Re: /proc/stat weirdness

Denis Vlasenko (vda@port.imtp.ilyichevsk.odessa.ua)
Mon, 22 Apr 2002 10:10:25 -0200


On 22 April 2002 04:18, Mark Hahn wrote:
> why not figure out if theres a code-based reason?
> just add some code in the kernel to check for the case,
> and dump some extra data.

Hehe. I caught it (imho, not tested).
jiffies is saved to local variable before user,nice,system is calculated,
what if delta(user+nice+system) was == delta(jiffies)
[i.e. no idle ticks since last readout by e.g. top]
and a jiffy just ended and got accounted into one of user,nice,system?
We'll get delta(user+nice+system) > delta(jiffies),
delta(idle)=delta(jiffies)-delta(user+nice+system) - negative!

File: proc_misc.c
....
static int kstat_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int i, len;
extern unsigned long total_forks;
unsigned long jif = jiffies; <*********** jiffies saved
unsigned int sum = 0, user = 0, nice = 0, system = 0;
int major, disk;

for (i = 0 ; i < smp_num_cpus; i++) {
int cpu = cpu_logical_map(i), j;

user += kstat.per_cpu_user[cpu]; <***
nice += kstat.per_cpu_nice[cpu]; <*** accounting
system += kstat.per_cpu_system[cpu]; <***
#if !defined(CONFIG_ARCH_S390)
for (j = 0 ; j < NR_IRQS ; j++)
sum += kstat.irqs[cpu][j];
#endif
}

len = sprintf(page, "cpu %u %u %u %lu\n", user, nice, system,
jif * smp_num_cpus - (user + nice + system));

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