From owner-freebsd-hackers@FreeBSD.ORG Mon May 12 03:09:38 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6D3401065682 for ; Mon, 12 May 2008 03:09:38 +0000 (UTC) (envelope-from elijah.buck@gmail.com) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.169]) by mx1.freebsd.org (Postfix) with ESMTP id F11118FC20 for ; Mon, 12 May 2008 03:09:37 +0000 (UTC) (envelope-from elijah.buck@gmail.com) Received: by ug-out-1314.google.com with SMTP id q2so617958uge.37 for ; Sun, 11 May 2008 20:09:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=bL5guok2zWY3pd49iJaWa62zQEjJlDT5PbjvOCroxyQ=; b=Uainsn7HkDEA8qkaA0s95nUIkMu9aCRYI6MEQ3v2tKvOmI/seXp+UNEPNRkgNBMSlXp/EQPwLfBqGOdlNVNV5Cpo1Zv87RL1fSmKKDyLL9JRnY6zQnDzCK7R3nrfebVzyUTVZh7JutiaCsTihzQTrEBN+v2RU3v0SirigJC6Mik= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=H07TkHuOvWaQrSKnUQOczx+oEo21siScC4CaKl0h3uwG6pon51cinWCd54zN9HACGirGkZSW1EZ27eCOzZxcnQpadxrYFNSYL1lrQLnZLTUX0PjSJwUErvaYaE4xoG4QXXQZYSoG/+jks5Y7KDxgrifJeoyrTODv4lwGs9wiD64= Received: by 10.66.223.2 with SMTP id v2mr4944014ugg.18.1210560222976; Sun, 11 May 2008 19:43:42 -0700 (PDT) Received: by 10.67.121.6 with HTTP; Sun, 11 May 2008 19:43:42 -0700 (PDT) Message-ID: <303eddcb0805111943t7c456c79l56f427c526d0b454@mail.gmail.com> Date: Sun, 11 May 2008 21:43:42 -0500 From: "Elijah Buck" To: freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: 4bsd fuzzy runq X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 May 2008 03:09:38 -0000 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