Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 May 2008 21:43:42 -0500
From:      "Elijah Buck" <elijah.buck@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   4bsd fuzzy runq
Message-ID:  <303eddcb0805111943t7c456c79l56f427c526d0b454@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hi,

I'm looking at the code for 4bsd fuzzy run queues in kern_switch.c

The relevant bit:

if (fuzz > 1) {
    int count = fuzz;
    int cpu = PCPU_GET(cpuid);
    struct thread *td2;
    td2 = td = TAILQ_FIRST(rqh);
    while (count-- && td2) {
        if (td->td_lastcpu == cpu) {
            td = td2;
            break;
        }
        td2 = TAILQ_NEXT(td2, td_runq);
    }
...return(td)
The purpose of this code appears to be to look through the runq to a depth
defined by fuzz for a thread that was last run on the current cpu.

Here are the cases I see:
1.) if (td_lastcpu == cpu) on the first iteration then TAILQ_FIRST(rqh) is
the selected thread (because of the break).
2.) if (td_lastcpu != cpu) on the first iteration then td is never set
again, and so (td_lastcpu != cpu) is always true. So, again,
TAILQ_FIRST(rqh) will be selected (because count will reach 0).

Which doesn't seem right (since that's what the else clause does). What am I
missing here?

Thanks,
Elijah



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?303eddcb0805111943t7c456c79l56f427c526d0b454>