From owner-freebsd-bugs@FreeBSD.ORG Wed Oct 13 23:10:29 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6E94A16A4CF for ; Wed, 13 Oct 2004 23:10:29 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 50C1D43D49 for ; Wed, 13 Oct 2004 23:10:29 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i9DNATxV076633 for ; Wed, 13 Oct 2004 23:10:29 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i9DNATW1076632; Wed, 13 Oct 2004 23:10:29 GMT (envelope-from gnats) Resent-Date: Wed, 13 Oct 2004 23:10:29 GMT Resent-Message-Id: <200410132310.i9DNATW1076632@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Antoine Brodin Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5E7B716A4CE for ; Wed, 13 Oct 2004 23:02:33 +0000 (GMT) Received: from massena-4-82-67-196-50.fbx.proxad.net (massena-4-82-67-196-50.fbx.proxad.net [82.67.196.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8133743D2D for ; Wed, 13 Oct 2004 23:02:32 +0000 (GMT) (envelope-from antoine@massena-4-82-67-196-50.fbx.proxad.net) Received: from massena-4-82-67-196-50.fbx.proxad.net (localhost.fbx.proxad.net [127.0.0.1])id i9DN2VbU001134 for ; Thu, 14 Oct 2004 01:02:31 +0200 (CEST) (envelope-from antoine@massena-4-82-67-196-50.fbx.proxad.net) Received: (from antoine@localhost)i9DN2P3S001133; Thu, 14 Oct 2004 01:02:25 +0200 (CEST) (envelope-from antoine) Message-Id: <200410132302.i9DN2P3S001133@massena-4-82-67-196-50.fbx.proxad.net> Date: Thu, 14 Oct 2004 01:02:25 +0200 (CEST) From: Antoine Brodin To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: kern/72659: [patch] little bug in sched_ule interractivty scorer X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Antoine Brodin List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Oct 2004 23:10:29 -0000 >Number: 72659 >Category: kern >Synopsis: [patch] little bug in sched_ule interractivty scorer >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Oct 13 23:10:28 GMT 2004 >Closed-Date: >Last-Modified: >Originator: Antoine Brodin >Release: FreeBSD 6.0-CURRENT i386 >Organization: none >Environment: System: FreeBSD massena-4-82-67-196-50.fbx.proxad.net 6.0-CURRENT FreeBSD 6.0-CURRENT #0: Wed Oct 13 00:03:44 CEST 2004 antoine@massena-4-82-67-196-50.fbx.proxad.net:/usr/obj/usr/src/sys/BARTON i386 >Description: There's a little bug in the interactivty scorer in sched_ule : when the sleeptime is equal to the runtime, it returns 0 instead of either SCHED_INTERACT_HALF or 0. The routine also uses max() with signed ints, they should be replaced by imax(). >How-To-Repeat: You can print sleeptime, runtime and interactivity in a file and then use gnuplot to show it in 3D. The problem when sleeptime is equal to runtime is obvious. Note : I can't reproduce the sleeptime is equal to runtime case easily, durring boot I have a thread that has sleeptime=runtime=30720 but the applications I use don't seem to be "half interractive". I can reproduce it by running during 2 or 3 minutes this ugly program on my box (and adding a printf in the scorer code) : #include #include int main(void) { int i, j; while (1) { for (i = 0; i < 100000000 - j; i++) ; usleep(250000 + j); j += 100; printf("%d\n", j); } } >Fix: Apply the attached patch --- sched_ule.patch begins here --- Index: sched_ule.c =================================================================== RCS file: /home/ncvs/src/sys/kern/sched_ule.c,v retrieving revision 1.134 diff -u -r1.134 sched_ule.c --- sched_ule.c 5 Oct 2004 22:14:02 -0000 1.134 +++ sched_ule.c 13 Oct 2004 20:09:53 -0000 @@ -1143,19 +1143,17 @@ int div; if (kg->kg_runtime > kg->kg_slptime) { - div = max(1, kg->kg_runtime / SCHED_INTERACT_HALF); + div = imax(1, kg->kg_runtime / SCHED_INTERACT_HALF); return (SCHED_INTERACT_HALF + (SCHED_INTERACT_HALF - (kg->kg_slptime / div))); - } if (kg->kg_slptime > kg->kg_runtime) { - div = max(1, kg->kg_slptime / SCHED_INTERACT_HALF); + } + if (kg->kg_slptime > kg->kg_runtime) { + div = imax(1, kg->kg_slptime / SCHED_INTERACT_HALF); return (kg->kg_runtime / div); } - - /* - * This can happen if slptime and runtime are 0. - */ + if (kg->kg_runtime > 0) + return (SCHED_INTERACT_HALF); return (0); - } /* --- sched_ule.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: