1 --- procps-3.2.7/top.c.remcpu 2006-07-10 10:41:11.000000000 +0200
2 +++ procps-3.2.7/top.c 2006-07-10 10:41:35.000000000 +0200
4 static CPU_t *cpus_refresh (CPU_t *cpus)
6 static FILE *fp = NULL;
10 // enough for a /proc/stat CPU line (not the intr line)
12 can hold tics representing the /proc/stat cpu summary (the first
13 line read) -- that slot supports our View_CPUSUM toggle */
14 cpus = alloc_c((1 + Cpu_tot) * sizeof(CPU_t));
17 + else if (cpu_max > Cpu_tot)
18 + /* move saved CUPs summary to cpu_max possition */
19 + memcpy(&cpus[cpu_max], &cpus[Cpu_tot], sizeof(CPU_t));
24 // first value the last slot with the cpu summary line
25 if (!fgets(buf, sizeof(buf), fp)) std_err("failed /proc/stat read");
26 - cpus[Cpu_tot].x = 0; // FIXME: can't tell by kernel version number
27 - cpus[Cpu_tot].y = 0; // FIXME: can't tell by kernel version number
28 - cpus[Cpu_tot].z = 0; // FIXME: can't tell by kernel version number
29 + cpus[cpu_max].x = 0; // FIXME: can't tell by kernel version number
30 + cpus[cpu_max].y = 0; // FIXME: can't tell by kernel version number
31 + cpus[cpu_max].z = 0; // FIXME: can't tell by kernel version number
32 num = sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu",
51 std_err("failed /proc/stat read");
55 // now value each separate cpu's tics
56 - for (i = 0; 1 < Cpu_tot && i < Cpu_tot; i++) {
57 + for (i = 0; ; i++) {
58 if (!fgets(buf, sizeof(buf), fp)) std_err("failed /proc/stat read");
59 cpus[i].x = 0; // FIXME: can't tell by kernel version number
60 cpus[i].y = 0; // FIXME: can't tell by kernel version number
63 &cpus[i].u, &cpus[i].n, &cpus[i].s, &cpus[i].i, &cpus[i].w, &cpus[i].x, &cpus[i].y, &cpus[i].z
66 - std_err("failed /proc/stat read");
71 + if (i == cpu_max - 1) {
72 + // Bump cpu_max and extend cpus
74 + cpus = realloc(cpus, (1 + cpu_max) * sizeof(CPU_t));
75 + if (!cpus) std_err("realloc failed");
76 + memcpy(&cpus[cpu_max], &cpus[cpu_max-1], sizeof(CPU_t));
80 + if (cpu_max > Cpu_tot)
81 + memcpy(&cpus[Cpu_tot], &cpus[cpu_max], sizeof(CPU_t));
83 + // and just in case we're 2.2.xx compiled without SMP support...
85 + cpus[0].id = cpus[1].id = 0;
86 + cpus[0].u = cpus[1].u;
87 + cpus[0].n = cpus[1].n;
88 + cpus[0].s = cpus[1].s;
89 + cpus[0].i = cpus[1].i;
90 + cpus[0].w = cpus[1].w;
91 + cpus[0].x = cpus[1].x;
92 + cpus[0].y = cpus[1].y;
93 + cpus[0].z = cpus[1].z;