updated on Mon Jan 16 20:00:43 UTC 2012
[aur-mirror.git] / selinux-procps / procps-3.2.7-top-remcpu.patch
blob88d14ef0ace36ebde928391307f7f280c9e842d0
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
3 @@ -912,6 +912,7 @@
4 static CPU_t *cpus_refresh (CPU_t *cpus)
6 static FILE *fp = NULL;
7 + static int cpu_max;
8 int i;
9 int num;
10 // enough for a /proc/stat CPU line (not the intr line)
11 @@ -926,24 +927,29 @@
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));
15 + cpu_max = Cpu_tot;
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));
21 rewind(fp);
22 fflush(fp);
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",
33 - &cpus[Cpu_tot].u,
34 - &cpus[Cpu_tot].n,
35 - &cpus[Cpu_tot].s,
36 - &cpus[Cpu_tot].i,
37 - &cpus[Cpu_tot].w,
38 - &cpus[Cpu_tot].x,
39 - &cpus[Cpu_tot].y,
40 - &cpus[Cpu_tot].z
41 + &cpus[cpu_max].u,
42 + &cpus[cpu_max].n,
43 + &cpus[cpu_max].s,
44 + &cpus[cpu_max].i,
45 + &cpus[cpu_max].w,
46 + &cpus[cpu_max].x,
47 + &cpus[cpu_max].y,
48 + &cpus[cpu_max].z
50 if (num < 4)
51 std_err("failed /proc/stat read");
52 @@ -955,7 +961,7 @@
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
61 @@ -964,9 +970,35 @@
62 &cpus[i].id,
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
65 - if (num < 4)
66 - std_err("failed /proc/stat read");
67 + if (num < 4) {
68 + Cpu_tot = i;
69 + break;
70 + }
71 + if (i == cpu_max - 1) {
72 + // Bump cpu_max and extend cpus
73 + cpu_max++;
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));
77 + }
78 + }
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...
84 + if (Cpu_tot == 1) {
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;
96 return cpus;