[patch] sched_yield in 2.2.x

2001-05-29 Thread Ivan Schreter

Hello,

I'm not subscribed, so eventual replies please CC: to me ([EMAIL PROTECTED]).

Here is a 2-line patch that fixes sched_yield() call to actually really yield
the processor in 2.2.x kernels. I am using 2.2.16 and so have tested it in
2.2.16 only, but I suppose it should work with other kernels as well (there
seem not to be so many changes).

Bug description: When a process called sched_yield() it was properly marked for
reschedule and bit SCHED_YIELD for reschedule was properly set in p->policy.
However, prev_goodness() cleared this bit returning goodness 0 (I changed it to
-1 just to be sure this process isn't accidentally picked when there is other
process to run - maybe I'm wrong here, but 2.4.5 gives it also goodness -1, so
it should be OK). This was not that bad, but successive calls to goodness()
while searching for next process to run included last process, which had
meanwhile YIELD bit cleared and thus it's goodness value was calculated as
better. And we come to second line of the fix - do not consider prev process in
searching for next process to run, as it is anyway already selected as next by
default when no better process is found.

I hope that it will work in SMP environment as well (it should, since
schedule() seems to be mostly independent of UP/SMP).

And why do I want to use sched_yield()? Well, to implement user-space
longer-duration locks which don't consume the whole timeslice when waiting, but
rather relinquish processor to other task so it finishes it's work in critical
region sooner.

It's funny nobody has fixed this by now, but as I've seen there were couple
of discussion about sched_yield() already... I come probably too late...

Ivan Schreter
[EMAIL PROTECTED]


--- kernel/sched.c.orig Wed May 30 01:17:24 2001
+++ kernel/sched.c  Wed May 30 01:41:34 2001
@@ -196,7 +196,7 @@
 {
if (p->policy & SCHED_YIELD) {
p->policy &= ~SCHED_YIELD;
-   return 0;
+   return -1;
}
return goodness(prev, p, this_cpu);
 }
@@ -729,7 +729,7 @@
  * list, so our list starting at "p" is essentially fixed.
  */
while (p != _task) {
-   if (can_schedule(p)) {
+   if (p != prev && can_schedule(p)) {
int weight = goodness(prev, p, this_cpu);
if (weight > c)
c = weight, next = p;



[patch] sched_yield in 2.2.x

2001-05-29 Thread Ivan Schreter

Hello,

I'm not subscribed, so eventual replies please CC: to me ([EMAIL PROTECTED]).

Here is a 2-line patch that fixes sched_yield() call to actually really yield
the processor in 2.2.x kernels. I am using 2.2.16 and so have tested it in
2.2.16 only, but I suppose it should work with other kernels as well (there
seem not to be so many changes).

Bug description: When a process called sched_yield() it was properly marked for
reschedule and bit SCHED_YIELD for reschedule was properly set in p-policy.
However, prev_goodness() cleared this bit returning goodness 0 (I changed it to
-1 just to be sure this process isn't accidentally picked when there is other
process to run - maybe I'm wrong here, but 2.4.5 gives it also goodness -1, so
it should be OK). This was not that bad, but successive calls to goodness()
while searching for next process to run included last process, which had
meanwhile YIELD bit cleared and thus it's goodness value was calculated as
better. And we come to second line of the fix - do not consider prev process in
searching for next process to run, as it is anyway already selected as next by
default when no better process is found.

I hope that it will work in SMP environment as well (it should, since
schedule() seems to be mostly independent of UP/SMP).

And why do I want to use sched_yield()? Well, to implement user-space
longer-duration locks which don't consume the whole timeslice when waiting, but
rather relinquish processor to other task so it finishes it's work in critical
region sooner.

It's funny nobody has fixed this by now, but as I've seen there were couple
of discussion about sched_yield() already... I come probably too late...

Ivan Schreter
[EMAIL PROTECTED]


--- kernel/sched.c.orig Wed May 30 01:17:24 2001
+++ kernel/sched.c  Wed May 30 01:41:34 2001
@@ -196,7 +196,7 @@
 {
if (p-policy  SCHED_YIELD) {
p-policy = ~SCHED_YIELD;
-   return 0;
+   return -1;
}
return goodness(prev, p, this_cpu);
 }
@@ -729,7 +729,7 @@
  * list, so our list starting at p is essentially fixed.
  */
while (p != init_task) {
-   if (can_schedule(p)) {
+   if (p != prev  can_schedule(p)) {
int weight = goodness(prev, p, this_cpu);
if (weight  c)
c = weight, next = p;