|
25 | 25 |
|
26 | 26 | #include <unistd.h> |
27 | 27 |
|
| 28 | +/* |
| 29 | + * See kernel documentation for a description: |
| 30 | + * https://www.kernel.org/doc/html/latest/filesystems/proc.html |
| 31 | + * |
| 32 | + * user: normal processes executing in user mode |
| 33 | + * nice: niced processes executing in user mode |
| 34 | + * system: processes executing in kernel mode |
| 35 | + * idle: twiddling thumbs |
| 36 | + * iowait: In a word, iowait stands for waiting for I/O to complete. But there are several problems: |
| 37 | + * irq: servicing interrupts |
| 38 | + * softirq: servicing softirqs |
| 39 | + * steal: involuntary wait |
| 40 | + * guest: running a normal guest |
| 41 | + * guest_nice: running a niced guest |
| 42 | + * |
| 43 | + * Ensure to pick the correct version of the documentation, older versions here: |
| 44 | + * https://github.com/torvalds/linux/tree/master/Documentation |
| 45 | + */ |
28 | 46 | struct cpu_stat_info { |
29 | 47 | double user; |
30 | 48 | double nice; |
@@ -109,7 +127,7 @@ static int cpu_thermal_update(struct flb_ne *ctx, uint64_t ts) |
109 | 127 | continue; |
110 | 128 | } |
111 | 129 |
|
112 | | - /* Phisical ID */ |
| 130 | + /* Physical ID */ |
113 | 131 | ret = ne_utils_file_read_uint64(ctx->path_sysfs, |
114 | 132 | entry->str, |
115 | 133 | "topology", "physical_package_id", |
@@ -223,9 +241,15 @@ static int stat_line(char *line, struct cpu_stat_info *st) |
223 | 241 | &st->steal, |
224 | 242 | &st->guest, |
225 | 243 | &st->guest_nice); |
226 | | - if (ret != 10) { |
| 244 | + |
| 245 | + /* On some older kernels the 'guest_nice' value may be missing */ |
| 246 | + if (ret < 9) { |
227 | 247 | return -1; |
228 | 248 | } |
| 249 | + /* Ensure we zero initialise it */ |
| 250 | + if ( ret == 9 ) { |
| 251 | + st->guest_nice = 0; |
| 252 | + } |
229 | 253 |
|
230 | 254 | /* Convert to seconds based on USER_HZ kernel param */ |
231 | 255 | st->user /= user_hz; |
|
0 commit comments