Skip to contentSkip to conversation

O(1) scheduler, -D1, 2.5.2-pre9, 2.4.17

PATCH New Ingo Molnar 7 participants 12 messages Jan 7, 2002 – Jan 10, 2002 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 1 line · Linus Torvalds

Ingo, looks true. A quick -D2?

yep, Brian is right. I've uploaded -D2:

        http://redhat.com/~mingo/O(1)-scheduler/sched-O1-2.5.2-D2.patch

other changes:

- make rt_priority 99 map to p->prio 0, rt_priority 0 map to p->prio 99.

- display 'top' priorities correctly, 0-39 for normal processes, negative values for RT tasks. (it works just fine it appears.) We did not use to display the real priority of RT tasks, but now it's natural.

Quoted 2 lines

Oh, and please move console_init() back, other consoles (sparc?) may depend on having PCI layers initialized.

(doh, done too, fix is in -D2.)

Quoted 2 lines

Oh, and _I_ don't like "cpu()". What's wrong with the already existing "smp_processor_id()"?

nothing serious, my main problem with it is that it's often too long for my 80 chars wide consoles, and it's also too long to type and i use it quite often in SMP code.

IIRC we had a 'hard_smp_processor_id()' initially, partly to make it harder to use it. (it was very slow because it did an APIC read). But these days smp_processor_id() is just as fast (or even faster) as 'current'. So i wanted to use cpu() in new code to make it easier to read and to make it more compact. But if this is a problem i can remove it. I've verified that there is no obvious namespace collisions.

(i've done a quick UP sanity compile + boot of 2.5.2-pre9 + D2, it all works as expected.)

Ingo

#2 lore raw

Hi all

I'm joining the host of beta testers involved in that patch...

It's currently running on a production machine :
dual PII350 on ASUS P2B-DS
3 SCSI hard drives
512MB of RAM
3C905C
This is a network server running squid-cache www proxy with a medium load (700 clients on a T3), mysqld, apache, proftpd. kernel is stock 2.4.17 - and so far, so good.

Cheers,

François Cami

Quoted 53 lines · Ingo Molnar
Quoted 2 lines · Linus Torvalds

Ingo, looks true. A quick -D2?

yep, Brian is right. I've uploaded -D2:

        http://redhat.com/~mingo/O(1)-scheduler/sched-O1-2.5.2-D2.patch

other changes:

- make rt_priority 99 map to p->prio 0, rt_priority 0 map to p->prio 99.

- display 'top' priorities correctly, 0-39 for normal processes, negative values for RT tasks. (it works just fine it appears.) We did not use to display the real priority of RT tasks, but now it's natural.

Quoted 3 lines

Oh, and please move console_init() back, other consoles (sparc?) may depend on having PCI layers initialized.

(doh, done too, fix is in -D2.)

Quoted 3 lines

Oh, and _I_ don't like "cpu()". What's wrong with the already existing "smp_processor_id()"?

nothing serious, my main problem with it is that it's often too long for my 80 chars wide consoles, and it's also too long to type and i use it quite often in SMP code.

IIRC we had a 'hard_smp_processor_id()' initially, partly to make it harder to use it. (it was very slow because it did an APIC read). But these days smp_processor_id() is just as fast (or even faster) as 'current'. So i wanted to use cpu() in new code to make it easier to read and to make it more compact. But if this is a problem i can remove it. I've verified that there is no obvious namespace collisions.

(i've done a quick UP sanity compile + boot of 2.5.2-pre9 + D2, it all works as expected.)

Ingo

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#4 lore raw
In reply to a message not in the archive

Hi Ingo,

I tested 2.5.2-pre10 today. There is some bitop abuse that needs fixing for big endian machines to work :)

At the moment we have:

	#define BITMAP_SIZE ((MAX_PRIO+7)/8)
	char bitmap[BITMAP_SIZE];

Which is initialised using:

	memset(array->bitmap, 0xff, BITMAP_SIZE);
	clear_bit(MAX_PRIO, array->bitmap);

This results in the following in memory (in ascending memory order):

ffffffffffffffff ffffffffffffffff fffffeffff000000

The problem here is that when we search the high word, we do so from the right, therefore we get 128 all the time :)

The following patch fixes this. We need to define the bitmap to be in terms of unsigned long, in this case its only lucky we have the correct alignment. We also replace the memset of the bitmap with set_bit.

With the patch things look much better (and the kernel boots on my ppc64 machine :)

ffffffffffffffff ffffffffffffffff 000000ffffffffff

Anton

include/asm-i386/mmu_context.h +1 -1
diff -urN linuxppc_2_5/include/asm-i386/mmu_context.h linuxppc_2_5_work/include/asm-i386/mmu_context.h
@@ -16,7 +16,7 @@
 # error update this function.
 #endif
 
-static inline int sched_find_first_zero_bit(char *bitmap)
+static inline int sched_find_first_zero_bit(unsigned long *bitmap)
 {
 	unsigned int *b = (unsigned int *)bitmap;
 	unsigned int rt;
kernel/sched.c +5 -6
diff -urN linuxppc_2_5/kernel/sched.c linuxppc_2_5_work/kernel/sched.c
@@ -20,15 +20,13 @@
 #include <linux/interrupt.h>
 #include <asm/mmu_context.h>
 
-#define BITMAP_SIZE ((MAX_PRIO+7)/8)
-
 typedef struct runqueue runqueue_t;
 
 struct prio_array {
 	int nr_active;
 	spinlock_t *lock;
 	runqueue_t *rq;
-	char bitmap[BITMAP_SIZE];
+	unsigned long bitmap[3];
 	list_t queue[MAX_PRIO];
 };
 
@@ -1306,11 +1304,12 @@
 			array = rq->arrays + j;
 			array->rq = rq;
 			array->lock = &rq->lock;
-			for (k = 0; k < MAX_PRIO; k++)
+			for (k = 0; k < MAX_PRIO; k++) {
 				INIT_LIST_HEAD(array->queue + k);
-			memset(array->bitmap, 0xff, BITMAP_SIZE);
+				__set_bit(k, array->bitmap);
+			}
 			// zero delimiter for bitsearch
-			clear_bit(MAX_PRIO, array->bitmap);
+			__clear_bit(MAX_PRIO, array->bitmap);
 		}
 	}
 	/*
#6 lore raw
In reply to a message not in the archive

Review

Quoted 9 lines

struct prio_array {

(quoted diff) +1 -1
 	int nr_active;
 	spinlock_t *lock;
 	runqueue_t *rq;
-	char bitmap[BITMAP_SIZE];
+	unsigned long bitmap[3];
 	list_t queue[MAX_PRIO];
 };

Sorry, of course this is wrong if sizeof(unsigned long) < 64. But you get the idea :)

Anton

#5 lore raw

PATCH 1/1 O(1) scheduler, -E1, 2.5.2-pre10, 2.4.17

In reply to Anton Blanchard

this is the latest update of the O(1) scheduler:

	http://redhat.com/~mingo/O(1)-scheduler/sched-O1-2.5.2-pre10-E1.patch

        http://redhat.com/~mingo/O(1)-scheduler/sched-O1-2.4.17-E1.patch

now that Linus has put the -D2 patch into the 2.5.2-pre10 kernel, the 2.5.2-pre10-E1 patch has become quite small :-)

The patch compiles, boots & works just fine on my UP/SMP boxes.

Changes since -D2:

- make rq->bitmap big-endian safe. (Anton Blanchard)

- documented and cleaned up the load estimator bits, no functional changes apart from small speedups.

- do init_idle() before starting up the init thread, this removes a race where we'd run the init thread on CPU#0 before init_idle() has been called.

Ingo

#7 lore raw
In reply to Anton Blanchard
Quoted 6 lines · Anton Blanchard

Review

Quoted 3 lines
(quoted diff) +1 -1
-	char bitmap[BITMAP_SIZE];
+	unsigned long bitmap[3];
 	list_t queue[MAX_PRIO];

Sorry, of course this is wrong if sizeof(unsigned long) < 64. But you get the idea :)

thanks, i've put the generic fix into the -E1 patch.

Quoted 2 lines

With the patch things look much better (and the kernel boots on my ppc64 machine :)

hey it should not even compile, you forgot to send us the PPC definition of sched_find_first_zero_bit() ;-)

Ingo

#3 lore raw
In reply to Ingo Molnar

Excellent - I'm going to try this one on whatever machines I have available for testing, and if I am emboldened by success, I'll try it on some light duty production servers as well -

- keep us in the loop, please!

Regards,

jjs

Quoted 86 lines · FD Cami

Hi all

I'm joining the host of beta testers involved in that patch...

It's currently running on a production machine :
dual PII350 on ASUS P2B-DS
3 SCSI hard drives
512MB of RAM
3C905C
This is a network server running squid-cache www proxy with a medium load (700 clients on a T3), mysqld, apache, proftpd. kernel is stock 2.4.17 - and so far, so good.

Cheers,

François Cami

Quoted 47 lines · Ingo Molnar
Quoted 2 lines · Linus Torvalds

Ingo, looks true. A quick -D2?

yep, Brian is right. I've uploaded -D2:

        http://redhat.com/~mingo/O(1)-scheduler/sched-O1-2.5.2-D2.patch

other changes:

- make rt_priority 99 map to p->prio 0, rt_priority 0 map to p->prio
99.

- display 'top' priorities correctly, 0-39 for normal processes,
negative
values for RT tasks. (it works just fine it appears.) We did not
use to
display the real priority of RT tasks, but now it's natural.

Quoted 3 lines

Oh, and please move console_init() back, other consoles (sparc?) may depend on having PCI layers initialized.

(doh, done too, fix is in -D2.)

Quoted 3 lines

Oh, and _I_ don't like "cpu()". What's wrong with the already existing "smp_processor_id()"?

nothing serious, my main problem with it is that it's often too long for my 80 chars wide consoles, and it's also too long to type and i use it quite often in SMP code.

IIRC we had a 'hard_smp_processor_id()' initially, partly to make it harder to use it. (it was very slow because it did an APIC read). But these days smp_processor_id() is just as fast (or even faster) as 'current'. So i wanted to use cpu() in new code to make it easier to read and to make it more compact. But if this is a problem i can remove it. I've verified that there is no obvious namespace collisions.

(i've done a quick UP sanity compile + boot of 2.5.2-pre9 + D2, it all works as expected.)

Quoted 9 lines

Ingo

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#8 lore raw
In reply to Anton Blanchard
Quoted 6 lines
Quoted 3 lines

With the patch things look much better (and the kernel boots on my ppc64 machine :)

hey it should not even compile, you forgot to send us the PPC definition of sched_find_first_zero_bit() ;-)

Good point, but its ppc64 so the patch would include all of include/asm-ppc64 and arch/ppc64 :)

I expect most architectures have a reasonably fast find_first_zero_bit so they can simply do:

static inline int sched_find_first_zero_bit(unsigned long *bitmap)

{
	return find_first_zero_bit(bitmap, MAX_PRIO);
}
#9 lore raw
In reply to Anton Blanchard
Quoted 7 lines · Anton Blanchard

I expect most architectures have a reasonably fast find_first_zero_bit so they can simply do:

static inline int sched_find_first_zero_bit(unsigned long *bitmap)

{
	return find_first_zero_bit(bitmap, MAX_PRIO);
}

Careful. The following is really quite a bit better on Alpha:

static inline int
sched_find_first_zero_bit(unsigned long *bitmap)

{
        unsigned long b0 = bitmap[0];
        unsigned long b1 = bitmap[1];
        unsigned long b2 = bitmap[2];
        unsigned long ofs = MAX_RT_PRIO;

        if (unlikely(~(b0 & b1) != 0)) {
                b2 = (~b0 == 0 ? b0 : b1);
                ofs = (~b0 == 0 ? 0 : 64);
        }

        return ffz(b2) + ofs;
}

It compiles down to

        ldq $2,0($16)
        ldq $3,8($16)
        lda $5,128($31)
        ldq $0,16($16)
        and $2,$3,$1
        ornot $31,$2,$4
        ornot $31,$1,$1
        bne $1,$L8
$L2:
        ornot $31,$0,$0
        cttz $0,$0
        addl $0,$5,$0
        ret $31,($26),1
$L8:
        mov $2,$0
        cmpult $31,$4,$5
        cmovne $4,$3,$0
        sll $5,6,$5
        br $31,$L2

which is a fair bit better than find_first_zero_bit if for no other reason than we collect all the memory accesses right up at the beginning.

While we're on the subject of sched_find_first_zero_bit, I'd like to complain about Ingo's choice of header file. Why in the world did you choose mmu_context.h? Invent a new asm/sched.h if you must, but please don't choose headers at random.

r~

#10 lore raw
In reply to Anton Blanchard
Quoted 4 lines · Richard Henderson

Careful. The following is really quite a bit better on Alpha:

static inline int
sched_find_first_zero_bit(unsigned long *bitmap)

Quoted 13 lines
{
        unsigned long b0 = bitmap[0];
        unsigned long b1 = bitmap[1];
        unsigned long b2 = bitmap[2];
        unsigned long ofs = MAX_RT_PRIO;

        if (unlikely(~(b0 & b1) != 0)) {
                b2 = (~b0 == 0 ? b0 : b1);
                ofs = (~b0 == 0 ? 0 : 64);
        }

        return ffz(b2) + ofs;
}

True. Minor correction:
- b2 = (~b0 == 0 ? b0 : b1);
- ofs = (~b0 == 0 ? 0 : 64);
+ b2 = (~b0 ? b0 : b1);
+ ofs = (~b0 ? 0 : 64);

Note that comment for this function is a bit confusing:
* ... It's the fastest
* way of searching a 168-bit bitmap where the first 128 bits are
* unlikely to be set.

s/set/cleared/

Quoted 4 lines

While we're on the subject of sched_find_first_zero_bit, I'd like to complain about Ingo's choice of header file. Why in the world did you choose mmu_context.h? Invent a new asm/sched.h if you must, but please don't choose headers at random.

Agreed. Apparently asm/bitops.h?

Ivan.

#12 lore raw
In reply to Anton Blanchard
Quoted 26 lines · Ivan Kokshaysky
Quoted 4 lines · Richard Henderson

Careful. The following is really quite a bit better on Alpha:

static inline int
sched_find_first_zero_bit(unsigned long *bitmap)

Quoted 13 lines
{
        unsigned long b0 = bitmap[0];
        unsigned long b1 = bitmap[1];
        unsigned long b2 = bitmap[2];
        unsigned long ofs = MAX_RT_PRIO;

        if (unlikely(~(b0 & b1) != 0)) {
                b2 = (~b0 == 0 ? b0 : b1);
                ofs = (~b0 == 0 ? 0 : 64);
        }

        return ffz(b2) + ofs;
}

True. Minor correction:

(quoted diff) +2 -2
-               b2 = (~b0 == 0 ? b0 : b1);
-               ofs = (~b0 == 0 ? 0 : 64);
+               b2 = (~b0 ? b0 : b1);
+               ofs = (~b0 ? 0 : 64);
Quoted 4 lines

Note that comment for this function is a bit confusing:
* ... It's the fastest
* way of searching a 168-bit bitmap where the first 128 bits are
* unlikely to be set.

What if we want a 2048-bit bitmap???

Quoted 16 lines

s/set/cleared/

Quoted 4 lines

While we're on the subject of sched_find_first_zero_bit, I'd like to complain about Ingo's choice of header file. Why in the world did you choose mmu_context.h? Invent a new asm/sched.h if you must, but please don't choose headers at random.

Agreed. Apparently asm/bitops.h?

Ivan.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 3 lines
George           [email protected]
High-res-timers: http://sourceforge.net/projects/high-res-timers/
Real time sched: http://sourceforge.net/projects/rtsched/
#11 lore raw
In reply to Ivan Kokshaysky
Quoted 6 lines · Ivan Kokshaysky

Note that comment for this function is a bit confusing:
* ... It's the fastest
* way of searching a 168-bit bitmap where the first 128 bits are
* unlikely to be set.

s/set/cleared/

no, it's really 'cleared'. The bits are inverted right now.

Ingo