Re: [PATCH] Assorted counter/sched stuff (resend^2)

Neil Conway (nconway.list@ukaea.org.uk)
Tue, 22 Jun 1999 17:10:29 +0100


Here it is again folks...

Pretty simple stuff. However, since this is the third resend, I'm
getting a bit bored with it. If you don't like it please say so. If it
falls through the cracks this time then it's dead as far as I'm
concerned...

cheers
Neil

Neil Conway wrote:
>
> OK - another go. Perhaps everyone slept through this the last time, cos
> I can't see it being very contentious...
>
> Anyway - if it sucks, please tell me...
>
> Neil
> ps: this needs to go into 2.2 and 2.3 I guess.
>
> ------------------------------------------------------------------------
>
> Subject: [PATCH] Assorted counter/sched stuff] (resend)
> Date: Thu, 13 May 1999 12:19:26 +0100
> From: Neil Conway <nconway.list@ukaea.org.uk>
> Organization: Fusion
> To: "linux-kernel@vger.rutgers.edu" <linux-kernel@vger.rutgers.edu>,
> Linus Torvalds <torvalds@transmeta.com>
>
> This is a resend of a patch I made back in January. It was a bit
> premature then but since 2.3 has just forked I guess the world should be
> ready for it now ;-))
>
> *** NB: I'm off-list right now, so please CC me if you want me to notice
> a reply. ***
>
> I just checked it, and it applies cleanly to 2.2.8, even though it's a
> little grey and dusty by now...
>
> cheers
> Neil
>
> PS: As I see it, this will mean that nice +20 will actually cut things
> to 5% of CPU instead of 10%ish. I forgot to mention that first time
> around. If I'm being brain-dead please feel free to tell me though.
>
> ------------------------------------------------------------------------
>
> Subject: [PATCH] Assorted counter/sched stuff
> Date: Tue, 26 Jan 1999 23:09:22 +0000
> From: Neil Conway <nconway.list@ukaea.org.uk>
> Organization: Fusion
> To: Linus Torvalds <torvalds@transmeta.com>,
> "linux-kernel@vger.rutgers.edu" <linux-kernel@vger.rutgers.edu>
>
> (I didn't get this done before pre9 so I waited till now!)
>
> This is a collection of two types of fix: (a) drivers doing
> "current->counter =0;schedule()" with TASK_INTERRUPTIBLE set; (b) lots
> of architectures doing "if (current->counter <0)" when they should
> really have tested for "<= 0". (I don't know if it's safe to test "==
> 0" since I'm not certain that setting need_resched will ALWAYS prevent
> another timer-tick happening in the same context.)
>
> This also reverts the timeslice length comments to "200 ms" (calling it
> "210 ms" was incorrect on Alphas anyway due to HZ != 100).
>
> There are still loads of places (mostly in the fs code) where we do
> "current->counter =0;schedule()", but I don't know of any better way to
> do the waits in those cases. Perhaps they are conceptually optimal
> anyway.
>
> Neil
>
> ------------------------------------------------------------------------
> diff -ur linux-2.2.0/arch/alpha/kernel/smp.c linux-2.2.0.njc/arch/alpha/kernel/smp.c
> --- linux-2.2.0/arch/alpha/kernel/smp.c Sun Jan 17 01:02:50 1999
> +++ linux-2.2.0.njc/arch/alpha/kernel/smp.c Tue Jan 26 22:42:14 1999
> @@ -390,7 +390,7 @@
> if (current->pid) {
> update_one_process(current, 1, user, !user, cpu);
>
> - if (--current->counter < 0) {
> + if (--current->counter <= 0) {
> current->counter = 0;
> current->need_resched = 1;
> }
> diff -ur linux-2.2.0/arch/i386/kernel/smp.c linux-2.2.0.njc/arch/i386/kernel/smp.c
> --- linux-2.2.0/arch/i386/kernel/smp.c Tue Jan 26 18:09:10 1999
> +++ linux-2.2.0.njc/arch/i386/kernel/smp.c Tue Jan 26 22:49:43 1999
> @@ -1696,7 +1696,7 @@
> update_one_process(p, 1, user, system, cpu);
>
> p->counter -= 1;
> - if (p->counter < 0) {
> + if (p->counter <= 0) {
> p->counter = 0;
> p->need_resched = 1;
> }
> diff -ur linux-2.2.0/arch/ppc/kernel/smp.c linux-2.2.0.njc/arch/ppc/kernel/smp.c
> --- linux-2.2.0/arch/ppc/kernel/smp.c Wed Dec 30 18:55:07 1998
> +++ linux-2.2.0.njc/arch/ppc/kernel/smp.c Tue Jan 26 22:43:06 1999
> @@ -77,7 +77,7 @@
> update_one_process(p, 1, user, system, cpu);
>
> p->counter -= 1;
> - if (p->counter < 0) {
> + if (p->counter <= 0) {
> p->counter = 0;
> current->need_resched = 1;
> }
> diff -ur linux-2.2.0/arch/sparc/kernel/sun4d_smp.c linux-2.2.0.njc/arch/sparc/kernel/sun4d_smp.c
> --- linux-2.2.0/arch/sparc/kernel/sun4d_smp.c Mon Nov 16 18:37:28 1998
> +++ linux-2.2.0.njc/arch/sparc/kernel/sun4d_smp.c Tue Jan 26 22:42:37 1999
> @@ -471,7 +471,7 @@
> if(current->pid) {
> update_one_process(current, 1, user, !user, cpu);
>
> - if(--current->counter < 0) {
> + if(--current->counter <= 0) {
> current->counter = 0;
> current->need_resched = 1;
> }
> diff -ur linux-2.2.0/arch/sparc/kernel/sun4m_smp.c linux-2.2.0.njc/arch/sparc/kernel/sun4m_smp.c
> --- linux-2.2.0/arch/sparc/kernel/sun4m_smp.c Mon Nov 16 18:37:28 1998
> +++ linux-2.2.0.njc/arch/sparc/kernel/sun4m_smp.c Tue Jan 26 22:42:54 1999
> @@ -451,7 +451,7 @@
> if(current->pid) {
> update_one_process(current, 1, user, !user, cpu);
>
> - if(--current->counter < 0) {
> + if(--current->counter <= 0) {
> current->counter = 0;
> current->need_resched = 1;
> }
> diff -ur linux-2.2.0/arch/sparc64/kernel/smp.c linux-2.2.0.njc/arch/sparc64/kernel/smp.c
> --- linux-2.2.0/arch/sparc64/kernel/smp.c Tue Oct 27 17:52:20 1998
> +++ linux-2.2.0.njc/arch/sparc64/kernel/smp.c Tue Jan 26 22:43:37 1999
> @@ -578,7 +578,7 @@
> unsigned int *inc, *inc2;
>
> update_one_process(current, 1, user, !user, cpu);
> - if(--current->counter < 0) {
> + if(--current->counter <= 0) {
> current->counter = 0;
> current->need_resched = 1;
> }
> diff -ur linux-2.2.0/drivers/char/cyclades.c linux-2.2.0.njc/drivers/char/cyclades.c
> --- linux-2.2.0/drivers/char/cyclades.c Wed Jan 20 21:26:20 1999
> +++ linux-2.2.0.njc/drivers/char/cyclades.c Tue Jan 26 22:37:33 1999
> @@ -2597,7 +2597,6 @@
> printk("Not clean (jiff=%lu)...", jiffies);
> #endif
> current->state = TASK_INTERRUPTIBLE;
> - current->counter = 0; /* make us low-priority */
> schedule_timeout(char_time);
> if (signal_pending(current))
> break;
> @@ -2610,7 +2609,6 @@
> }
> /* Run one more char cycle */
> current->state = TASK_INTERRUPTIBLE;
> - current->counter = 0; /* make us low-priority */
> schedule_timeout(char_time * 5);
> current->state = TASK_RUNNING;
> #ifdef CY_DEBUG_WAIT_UNTIL_SENT
> diff -ur linux-2.2.0/drivers/char/esp.c linux-2.2.0.njc/drivers/char/esp.c
> --- linux-2.2.0/drivers/char/esp.c Sat Oct 31 19:06:21 1998
> +++ linux-2.2.0.njc/drivers/char/esp.c Tue Jan 26 22:38:03 1999
> @@ -2180,7 +2180,6 @@
> while ((serial_in(info, UART_ESI_STAT1) != 0x03) ||
> (serial_in(info, UART_ESI_STAT2) != 0xff)) {
> current->state = TASK_INTERRUPTIBLE;
> - current->counter = 0;
> schedule_timeout(char_time);
>
> if (signal_pending(current))
> diff -ur linux-2.2.0/drivers/char/rocket.c linux-2.2.0.njc/drivers/char/rocket.c
> --- linux-2.2.0/drivers/char/rocket.c Thu Nov 5 17:58:43 1998
> +++ linux-2.2.0.njc/drivers/char/rocket.c Tue Jan 26 22:38:25 1999
> @@ -1663,7 +1663,6 @@
> jiffies, check_time);
> #endif
> current->state = TASK_INTERRUPTIBLE;
> - current->counter = 0; /* make us low-priority */
> schedule_timeout(check_time);
> if (signal_pending(current))
> break;
> diff -ur linux-2.2.0/drivers/char/serial.c linux-2.2.0.njc/drivers/char/serial.c
> --- linux-2.2.0/drivers/char/serial.c Thu Jan 14 18:27:53 1999
> +++ linux-2.2.0.njc/drivers/char/serial.c Tue Jan 26 22:38:48 1999
> @@ -2376,7 +2376,6 @@
> printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
> #endif
> current->state = TASK_INTERRUPTIBLE;
> - current->counter = 0; /* make us low-priority */
> schedule_timeout(char_time);
> if (signal_pending(current))
> break;
> diff -ur linux-2.2.0/drivers/macintosh/macserial.c linux-2.2.0.njc/drivers/macintosh/macserial.c
> --- linux-2.2.0/drivers/macintosh/macserial.c Wed Dec 23 17:44:41 1998
> +++ linux-2.2.0.njc/drivers/macintosh/macserial.c Tue Jan 26 22:39:57 1999
> @@ -1324,7 +1324,6 @@
> char_time = MIN(char_time, timeout);
> while ((read_zsreg(info->zs_channel, 1) & ALL_SNT) == 0) {
> current->state = TASK_INTERRUPTIBLE;
> - current->counter = 0; /* make us low-priority */
> schedule_timeout(char_time);
> if (signal_pending(current))
> break;
> diff -ur linux-2.2.0/drivers/sbus/char/sab82532.c linux-2.2.0.njc/drivers/sbus/char/sab82532.c
> --- linux-2.2.0/drivers/sbus/char/sab82532.c Wed Dec 23 17:44:41 1998
> +++ linux-2.2.0.njc/drivers/sbus/char/sab82532.c Tue Jan 26 22:39:15 1999
> @@ -1672,7 +1672,6 @@
> #endif
> while (info->xmit_cnt || !info->all_sent) {
> current->state = TASK_INTERRUPTIBLE;
> - current->counter = 0;
> schedule_timeout(char_time);
> if (signal_pending(current))
> break;
> diff -ur linux-2.2.0/drivers/sbus/char/su.c linux-2.2.0.njc/drivers/sbus/char/su.c
> --- linux-2.2.0/drivers/sbus/char/su.c Wed Dec 23 17:44:41 1998
> +++ linux-2.2.0.njc/drivers/sbus/char/su.c Tue Jan 26 22:39:35 1999
> @@ -1814,7 +1814,6 @@
> printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
> #endif
> current->state = TASK_INTERRUPTIBLE;
> - current->counter = 0; /* make us low-priority */
> schedule_timeout(char_time);
> if (signal_pending(current))
> break;
> diff -ur linux-2.2.0/include/linux/sched.h linux-2.2.0.njc/include/linux/sched.h
> --- linux-2.2.0/include/linux/sched.h Tue Jan 26 00:06:22 1999
> +++ linux-2.2.0.njc/include/linux/sched.h Tue Jan 26 22:44:43 1999
> @@ -338,7 +338,7 @@
> */
> #define _STK_LIM (8*1024*1024)
>
> -#define DEF_PRIORITY (20*HZ/100) /* 210 ms time slices */
> +#define DEF_PRIORITY (20*HZ/100) /* 200 ms time slices */
>
> /*
> * INIT_TASK is used to set up the first task table, touch at
> diff -ur linux-2.2.0/kernel/sched.c linux-2.2.0.njc/kernel/sched.c
> --- linux-2.2.0/kernel/sched.c Tue Jan 19 18:19:58 1999
> +++ linux-2.2.0.njc/kernel/sched.c Tue Jan 26 22:52:31 1999
> @@ -1350,7 +1350,7 @@
> unsigned long user = ticks - system;
> if (p->pid) {
> p->counter -= ticks;
> - if (p->counter < 0) {
> + if (p->counter <= 0) {
> p->counter = 0;
> p->need_resched = 1;
> }
> @@ -1553,7 +1553,7 @@
> * do a "normalization" of the priority (traditionally
> * Unix nice values are -20 to 20; Linux doesn't really
> * use that kind of thing, but uses the length of the
> - * timeslice instead (default 210 ms). The rounding is
> + * timeslice instead (default 200 ms). The rounding is
> * why we want to avoid negative values.
> */
> newprio = (newprio * DEF_PRIORITY + 10) / 20;

-
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/