* Does cli() need to be called before reading avenrun?
@ 2003-01-02 0:39 Peter Benie
2003-01-02 0:53 ` Robert Love
0 siblings, 1 reply; 3+ messages in thread
From: Peter Benie @ 2003-01-02 0:39 UTC (permalink / raw)
To: linux-kernel
In kernel 2.4, in sys_sysinfo(), the code reads:
cli();
val.uptime = jiffies / HZ;
val.loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
val.loads[1] = avenrun[1] << (SI_LOAD_SHIFT - FSHIFT);
val.loads[2] = avenrun[2] << (SI_LOAD_SHIFT - FSHIFT);
val.procs = nr_threads-1;
sti();
In loadavg_read_proc, the code is in essence the same, except that it
isn't wrapped in cli/sti.
Is there a reason for the cli?
Peter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Does cli() need to be called before reading avenrun?
2003-01-02 0:39 Does cli() need to be called before reading avenrun? Peter Benie
@ 2003-01-02 0:53 ` Robert Love
2003-01-02 10:38 ` Peter Benie
0 siblings, 1 reply; 3+ messages in thread
From: Robert Love @ 2003-01-02 0:53 UTC (permalink / raw)
To: Peter Benie; +Cc: linux-kernel
On Wed, 2003-01-01 at 19:39, Peter Benie wrote:
> In kernel 2.4, in sys_sysinfo(), the code reads:
>
> cli();
> val.uptime = jiffies / HZ;
>
> val.loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
> val.loads[1] = avenrun[1] << (SI_LOAD_SHIFT - FSHIFT);
> val.loads[2] = avenrun[2] << (SI_LOAD_SHIFT - FSHIFT);
>
> val.procs = nr_threads-1;
> sti();
>
> In loadavg_read_proc, the code is in essence the same, except that it
> isn't wrapped in cli/sti.
>
> Is there a reason for the cli?
Interrupts off protects the reading of avenrun[] - it is only written to
from the timer interrupt, so you can safely read it when interrupts are
disabled.
The reason we need some sort of protection is that there are the three
array entries, so we need to make sure we read all three atomically (not
that its a huge deal if we do not).
So I guess the proc code needs to disable interrupts, too. I am on my
laptop and only have a 2.5 tree - sure it is not disabled somewhere in
there?
Note in 2.5 we replaced the cli() with a read_lock() on xtime_lock.
Robert Love
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Does cli() need to be called before reading avenrun?
2003-01-02 0:53 ` Robert Love
@ 2003-01-02 10:38 ` Peter Benie
0 siblings, 0 replies; 3+ messages in thread
From: Peter Benie @ 2003-01-02 10:38 UTC (permalink / raw)
To: Robert Love; +Cc: linux-kernel
Robert Love writes ("Re: Does cli() need to be called before reading avenrun?"):
> On Wed, 2003-01-01 at 19:39, Peter Benie wrote:
> > In kernel 2.4, in sys_sysinfo(), the code reads:
> >
> > cli();
> > val.uptime = jiffies / HZ;
> >
> > val.loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
> > val.loads[1] = avenrun[1] << (SI_LOAD_SHIFT - FSHIFT);
> > val.loads[2] = avenrun[2] << (SI_LOAD_SHIFT - FSHIFT);
> >
> > val.procs = nr_threads-1;
> > sti();
> >
> > In loadavg_read_proc, the code is in essence the same, except that it
> > isn't wrapped in cli/sti.
> >
> > Is there a reason for the cli?
>
> The reason we need some sort of protection is that there are the three
> array entries, so we need to make sure we read all three atomically (not
> that its a huge deal if we do not).
This is exactly what I have my doubts about. These are three load
averages with different time constants - it isn't meaningful to
compare them so it doesn't matter if they are not sampled at exactly
the same time.
What caused me to look at this code is was a complaint in the exim
source about how long sysinfo() took compared with reading
/proc/loadavg - the difference is a factor of 100 which is large
enough to seriously affect exim's performance. This looks like a
possible cause.
Peter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-01-02 10:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-02 0:39 Does cli() need to be called before reading avenrun? Peter Benie
2003-01-02 0:53 ` Robert Love
2003-01-02 10:38 ` Peter Benie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox