public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Bug in sys_sched_yield
@ 2001-04-11 19:31 Hubertus Franke
  2001-04-11 20:12 ` Andrea Arcangeli
  2001-04-12 16:08 ` [Lse-tech] " george anzinger
  0 siblings, 2 replies; 6+ messages in thread
From: Hubertus Franke @ 2001-04-11 19:31 UTC (permalink / raw)
  To: mingo; +Cc: Linux Kernel List, lse-tech



In the recent optimizations to sys_sched_yield a bug was introduced.
In the current implementation of sys_sched_yield()
the aligned_data and idle_tasks are indexed by logical cpu-#.

They should however be indexed by physical cpu-#.
Since logical==physical on the x86 platform, it doesn't matter there,
for other platforms where this is not true it will matter.
Below is the fix.


diff -uwrbBN linux-2.4.3/kernel/sched.c linux-2.4.3-fix/kernel/sched.c
--- linux-2.4.3/kernel/sched.c     Thu Mar 22 12:20:45 2001
+++ linux-2.4.3-fix/kernel/sched.c Wed Apr 11 11:27:16 2001
@@ -1024,9 +1024,11 @@
     int i;

     // Substract non-idle processes running on other CPUs.
-    for (i = 0; i < smp_num_cpus; i++)
-         if (aligned_data[i].schedule_data.curr != idle_task(i))
+    for (i = 0; i < smp_num_cpus; i++) {
+         int cpu = cpu_logical_map(i);
+         if (aligned_data[cpu].schedule_data.curr != idle_task(cpu))
               nr_pending--;
+    }
 #else
     // on UP this process is on the runqueue as well
     nr_pending--;

Hubertus Franke
Enterprise Linux Group (Mgr),  Linux Technology Center (Member Scalability)

email: frankeh@us.ibm.com
(w) 914-945-2003    (fax) 914-945-4425   TL: 862-2003





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug in sys_sched_yield
  2001-04-11 19:31 Bug in sys_sched_yield Hubertus Franke
@ 2001-04-11 20:12 ` Andrea Arcangeli
  2001-04-12 16:08 ` [Lse-tech] " george anzinger
  1 sibling, 0 replies; 6+ messages in thread
From: Andrea Arcangeli @ 2001-04-11 20:12 UTC (permalink / raw)
  To: Hubertus Franke; +Cc: mingo, Linux Kernel List, lse-tech

On Wed, Apr 11, 2001 at 03:31:37PM -0400, Hubertus Franke wrote:
> Below is the fix.

correct. Could you also use cpu_curr(cpu) instead of the longer expression?
(for the mainline it's only a beauty issue of course)

Andrea

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Lse-tech] Bug in sys_sched_yield
  2001-04-11 19:31 Bug in sys_sched_yield Hubertus Franke
  2001-04-11 20:12 ` Andrea Arcangeli
@ 2001-04-12 16:08 ` george anzinger
  2001-04-12 16:49   ` Walt Drummond
  1 sibling, 1 reply; 6+ messages in thread
From: george anzinger @ 2001-04-12 16:08 UTC (permalink / raw)
  To: Hubertus Franke; +Cc: mingo, Linux Kernel List, lse-tech

Hubertus Franke wrote:
> 
> In the recent optimizations to sys_sched_yield a bug was introduced.
> In the current implementation of sys_sched_yield()
> the aligned_data and idle_tasks are indexed by logical cpu-#.
> 
> They should however be indexed by physical cpu-#.
> Since logical==physical on the x86 platform, it doesn't matter there,
> for other platforms where this is not true it will matter.
> Below is the fix.
> 
Uh...  I do know about this map, but I wonder if it is at all needed. 
What is the real difference between a logical cpu and the physical one. 
Or is this only interesting if the machine is not Smp, i.e. all the cpus
are not the same?  It just seems to me that introducing an additional
mapping just slows things down and, if all the cpus are the same, does
not really do anything.  Of course, I am assuming that ALL usage would
be to the logical :)

George

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Lse-tech] Bug in sys_sched_yield
  2001-04-12 16:08 ` [Lse-tech] " george anzinger
@ 2001-04-12 16:49   ` Walt Drummond
  2001-04-12 17:31     ` george anzinger
  0 siblings, 1 reply; 6+ messages in thread
From: Walt Drummond @ 2001-04-12 16:49 UTC (permalink / raw)
  To: george anzinger; +Cc: Hubertus Franke, mingo, Linux Kernel List, lse-tech

george anzinger writes:
> Uh...  I do know about this map, but I wonder if it is at all needed. 
> What is the real difference between a logical cpu and the physical one. 
> Or is this only interesting if the machine is not Smp, i.e. all the cpus
> are not the same?  It just seems to me that introducing an additional
> mapping just slows things down and, if all the cpus are the same, does
> not really do anything.  Of course, I am assuming that ALL usage would
> be to the logical :)

Right.  That is not always the case.  IA32 is somewhat special. ;) The
logical mapping allows you to, among other things, easily enumerate
over the set of active processors without having to check if a
processor exists at the current processor address.

The difference is apparent when the physical CPU ID is, say, an
address on a processor bus, or worse, an address on a set of processor
busses.  Take a look at the IA-64's smp.h.  The IA64 physical
processor ID is a 64-bit structure that has to 8-bit ID's; an EID for
what amounts to a "processor bus" ID and an ID that corresponds to a
specific processor on a processor bus.  Together, they're a system
global ID for a specific processor.  But there is no guarantee that
the set of global ID's will be contiguous.

It's possible to have disjoint (non-contiguous) physical processor
ID's if a processor bus is not completely populated, or there is an
empty processor slot or odd processor numbering in firmware, or
whatever.

--Walt


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Lse-tech] Bug in sys_sched_yield
  2001-04-12 16:49   ` Walt Drummond
@ 2001-04-12 17:31     ` george anzinger
  2001-04-16 16:03       ` Walt Drummond
  0 siblings, 1 reply; 6+ messages in thread
From: george anzinger @ 2001-04-12 17:31 UTC (permalink / raw)
  To: drummond; +Cc: Hubertus Franke, mingo, Linux Kernel List, lse-tech

Walt Drummond wrote:
> 
> george anzinger writes:
> > Uh...  I do know about this map, but I wonder if it is at all needed.
> > What is the real difference between a logical cpu and the physical one.
> > Or is this only interesting if the machine is not Smp, i.e. all the cpus
> > are not the same?  It just seems to me that introducing an additional
> > mapping just slows things down and, if all the cpus are the same, does
> > not really do anything.  Of course, I am assuming that ALL usage would
> > be to the logical :)
> 
> Right.  That is not always the case.  IA32 is somewhat special. ;) The
> logical mapping allows you to, among other things, easily enumerate
> over the set of active processors without having to check if a
> processor exists at the current processor address.
> 
> The difference is apparent when the physical CPU ID is, say, an
> address on a processor bus, or worse, an address on a set of processor
> busses.  Take a look at the IA-64's smp.h.  The IA64 physical
> processor ID is a 64-bit structure that has to 8-bit ID's; an EID for
> what amounts to a "processor bus" ID and an ID that corresponds to a
> specific processor on a processor bus.  Together, they're a system
> global ID for a specific processor.  But there is no guarantee that
> the set of global ID's will be contiguous.
> 
> It's possible to have disjoint (non-contiguous) physical processor
> ID's if a processor bus is not completely populated, or there is an
> empty processor slot or odd processor numbering in firmware, or
> whatever.
> 
All that is cool.  Still, most places we don't really address the
processor, so the logical cpu number is all we need.  Places like
sched_yield, for example, should be using this, not the actual number,
which IMO should only be used when, for some reason, we NEED the hard
address of the cpu.  I don't think this ever has to leak out to the
common kernel code, or am i missing something here.

George

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Lse-tech] Bug in sys_sched_yield
  2001-04-12 17:31     ` george anzinger
@ 2001-04-16 16:03       ` Walt Drummond
  0 siblings, 0 replies; 6+ messages in thread
From: Walt Drummond @ 2001-04-16 16:03 UTC (permalink / raw)
  To: george anzinger
  Cc: drummond, Hubertus Franke, mingo, Linux Kernel List, lse-tech

george anzinger writes:
> All that is cool.  Still, most places we don't really address the
> processor, so the logical cpu number is all we need.  Places like
> sched_yield, for example, should be using this, not the actual number,
> which IMO should only be used when, for some reason, we NEED the hard
> address of the cpu.  I don't think this ever has to leak out to the
> common kernel code, or am i missing something here.

No your not, I was.  I completely misinterpreted your question.
Sorry about that.

Hubertus and Kanoj have provided the answer I should have given.

--Walt

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-04-16 16:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-04-11 19:31 Bug in sys_sched_yield Hubertus Franke
2001-04-11 20:12 ` Andrea Arcangeli
2001-04-12 16:08 ` [Lse-tech] " george anzinger
2001-04-12 16:49   ` Walt Drummond
2001-04-12 17:31     ` george anzinger
2001-04-16 16:03       ` Walt Drummond

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox