Linux-kernel mailing list archive 1999-20,: Re: schedule() "spaghetti" in 2.3.2 ..

# Re: schedule() "spaghetti" in 2.3.2 ..

Pavel Machek (pavel@bug.ucw.cz)
Tue, 18 May 1999 13:12:19 +0200

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Andrea Arcangeli: "Re: andrea buffer code (2.2.9-C.gz)"
- Previous message: CT@braehler.com: "eide-scsi module in 2.2"

Hi!

> > why not move code blocks in macros ( like that in mm module ) or better in
> > inline functions.
>
> That would not have the intended effect - to keep jumps out of the
> fast path.
>
> Normally gcc codes a normal if like that (pseudo, m68k like assembly)
>
> if (x < 0) {
> /* error */
> }
> /* rest of fast path */
>
> tst x
> bgr L1 /* jump taken in most cases */
> /* error */
> L1:
> /* rest of fast path */
>
> this means there is a jump in the fast path (on modern CPUs that can be
> quite costly because of the pipeline stall when the jump is mispredicted).
> It is usually faster to have code like this:

What about heuristic which says

if (...) {
...
return;
}

should be moved out of line?

Pavel
> I would prefer a cleaner way too, e.g.
>
> if (__builtin_predict(err < 0, 0)) {
> /* unlikely error code */
> }

maybe
#define unlikely __builtin_one_unlikely()

if (is_error() && unlikely) {
}

:-). Where unlikely is evaluated as 1, but gcc knows that unlikely is
not evaluated in common case. It would permit other nice tricks, like
(dreaming)

if (unlikely) {
...
}

which means code in brackets hardly ever executes, so optimize it for
size, instead ;-).

Pavel

    --
    I'm really pavel@ucw.cz. Look at http://195.113.31.123/~pavel.          Pavel
    Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!

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

- Next message: Andrea Arcangeli: "Re: andrea buffer code (2.2.9-C.gz)"
- Previous message: CT@braehler.com: "eide-scsi module in 2.2"