Re: [PATCH 0/3] Fix sysrq caused USB performance regressions andleak

From: Alan Cox
Date: Fri Jul 10 2009 - 05:33:25 EST


On Fri, 10 Jul 2009 11:07:53 +0200
Anders Larsen <al@xxxxxxxxxxx> wrote:

> On 2009-07-10 02:01:37, Alan Cox wrote:
> > > shouldn't it be
> > > + if (likely(!port->console || !port->sysrq))
> > > respectively
> > > + if (unlikely(port->console && port->sysrq)) {
> > >
> > > at least for clarity?
> >
> > It'll get predicted by the CPU just fine I suspect.
>
> I thought likely() / unlikely() were for the _compiler_ to arrange the
> blocks more efficiently?

Bit of both. Some systems have indicators for whether jumps are likely to
be taken, others you do things like conditionally jump forward to a jump
table which jumps back.

gcc itself says "programmers are notoriously bad at predicting how their
programs actually perform." 8)

Benchmarking I've not had any luck with unlikely() on a modern CPU
(the CPU is dynamically predicting anyway). The pentium iv does add
branch prediction hints (DS: and CS: overrides get reused) but they seem
to make things slower in the case where the CPU will get it right anyway.

So I'd like to see benchmarking evidence for an unlikely on such a hot
and predictible path.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/