Skip to content

Commit 9572f8c

Browse files
Shrikanth Hegdetyreld
Shrikanth Hegde
authored andcommitted
lparstat: Use CLOCK_BOOTTIME for get_time interface and Deprecate get_sys_upttime
"time" is used in lparstat.c to find the time elapsed either since boot or between two intervals. But it is using gettimeofday which returns the time elapsed since Epoch. This works for intervals calculations but it doesn't work for since boot reports. Instead use the CLOCK_BOOTTIME interface to get the elapsed time. This fixes physc, utilization based on purr being wrong since boot. Remove "uptime" interface since there are no users of it. One can get the system uptime by calling "time" itself. =============================== ::Test:: ========================== reboot stress-ng --cpu=$(nproc) -t 600 sleep 600 Results:: ==================== Shared LPAR ================================== System Configuration type=Shared mode=Uncapped smt=8 lcpu=12 mem=15573440 kB cpus=37 ent=12.00 lparstat -E <-- Observe utilization values ====== 6.9-rc1 and lparstat 1.3.10 ============= ---Actual--- -Normalized- %busy %idle Frequency %busy %idle ------ ------ ------------- ------ ------ 0.00 0.00 3.87GHz[106%] 0.00 0.00 ==== With this patch and patch 2/3 ============= ---Actual--- -Normalized- %busy %idle Frequency %busy %idle ------ ------ ------------- ------ ------ 38.72 0.11 3.87GHz[106%] 41.04 0.12 lparstat <-- Observe physc values ====== 6.9-rc1 and lparstat 1.3.10 =================================== %user %sys %wait %idle physc %entc lbusy app vcsw phint ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- 47.48 0.01 0.00 52.51 0.00 0.00 47.49 69099.72 541547 21 === With this patch and this patch ================================ === %user %sys %wait %idle physc %entc lbusy app vcsw phint ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- 47.48 0.01 0.00 52.51 5.73 47.75 47.49 31.21 541753 21 ==================== Dedicated LPAR ================================== System Configuration type=Dedicated mode=Capped smt=8 lcpu=12 mem=15573248 kB cpus=0 ent=12.00 ::lparstat -E:: <-- Observe utilization values. ======= 6.9-rc1 and lparstat 1.3.10 ============= ---Actual--- -Normalized- %busy %idle Frequency %busy %idle ------ ------ ------------- ------ ------ 0.00 0.00 3.87GHz[106%] 0.00 0.00 === With this patch and powerpc-utils patch to do the above equation === ---Actual--- -Normalized- %busy %idle Frequency %busy %idle ------ ------ ------------- ------ ------ 48.87 51.51 3.87GHz[106%] 51.81 54.60 ::lparstat:: <-- Observe physc values. ======= 6.9-rc1 and lparstat 1.3.10 ============= %user %sys %wait %idle physc %entc lbusy app vcsw phint ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- 48.38 0.01 0.00 51.61 0.03 0.25 48.39 0.00 344661 8 === With this patch and powerpc-utils patch to do the above equation === %user %sys %wait %idle physc %entc lbusy app vcsw phint ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- 48.38 0.01 0.00 51.61 12.05 100.42 48.39 0.00 344877 8 ============================================================================= Interval based lparstat values are same. With this patch the physc and busy purr/idle purr values show correctly for since boot reports. Note: this patch doesn't fix the idle purr being incorrect. That is currently being investigated. Signed-off-by: Shrikanth Hegde <[email protected]> Signed-off-by: Tyrel Datwyler <[email protected]>
1 parent 81c51b5 commit 9572f8c

File tree

2 files changed

+10
-53
lines changed

2 files changed

+10
-53
lines changed

src/lparstat.c

+10-47
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "lparstat.h"
3737
#include "pseries_platform.h"
3838
#include "cpu_info_helpers.h"
39+
#include <time.h>
3940

4041
#define LPARCFG_FILE "/proc/ppc64/lparcfg"
4142
#define SE_NOT_FOUND "???"
@@ -255,14 +256,17 @@ long long get_delta_value(char *se_name)
255256

256257
void get_time()
257258
{
258-
struct timeval t;
259259
struct sysentry *se;
260+
struct timespec ts;
261+
int err;
260262

261-
gettimeofday(&t, 0);
263+
err = clock_gettime(CLOCK_BOOTTIME, &ts);
264+
if (err)
265+
return;
262266

263267
se = get_sysentry("time");
264268
sprintf(se->value, "%lld",
265-
(long long)t.tv_sec * 1000000LL + (long long)t.tv_usec);
269+
(long long)ts.tv_sec);
266270
}
267271

268272
int get_time_base()
@@ -304,39 +308,13 @@ double get_scaled_tb(void)
304308
online_cores = atoi(se->value);
305309

306310
elapsed = get_delta_value("time");
307-
elapsed = elapsed / 1000000.0;
308311

309312
se = get_sysentry("timebase");
310313
timebase = atoi(se->value);
311314

312315
return (timebase * elapsed) * online_cores;
313316
}
314317

315-
void get_sys_uptime(struct sysentry *unused_se, char *uptime)
316-
{
317-
FILE *f;
318-
char buf[80];
319-
320-
f = fopen("/proc/uptime", "r");
321-
if (!f) {
322-
fprintf(stderr, "Could not open /proc/uptime\n");
323-
sprintf(uptime, SE_NOT_VALID);
324-
return;
325-
}
326-
327-
if ((fgets(buf, 80, f)) != NULL) {
328-
char *value;
329-
330-
value = strchr(buf, ' ');
331-
*value = '\0';
332-
sprintf(uptime, "%s", buf);
333-
} else {
334-
sprintf(uptime, SE_NOT_VALID);
335-
}
336-
337-
fclose(f);
338-
}
339-
340318
int get_nominal_frequency(void)
341319
{
342320
FILE *f;
@@ -403,13 +381,12 @@ void get_cpu_physc(struct sysentry *unused_se, char *buf)
403381
delta_purr = get_delta_value("purr");
404382

405383
se = get_sysentry("tbr");
406-
if (se->value[0] != '\0') {
384+
if (se->old_value[0] != '\0') {
407385
delta_tb = get_delta_value("tbr");
408386

409387
physc = delta_purr / delta_tb;
410388
} else {
411389
elapsed = get_delta_value("time");
412-
elapsed = elapsed / 1000000.0;
413390

414391
se = get_sysentry("timebase");
415392
timebase = atoi(se->value);
@@ -436,23 +413,9 @@ void get_cpu_app(struct sysentry *unused_se, char *buf)
436413
{
437414
struct sysentry *se;
438415
float timebase, app, elapsed_time;
439-
long long new_app, old_app, delta_time;
440-
char *descr, uptime[32];
416+
long long new_app, old_app;
441417

442-
se = get_sysentry("time");
443-
if (se->old_value[0] == '\0') {
444-
/* Single report since boot */
445-
get_sysdata("uptime", &descr, uptime);
446-
447-
if (!strcmp(uptime, SE_NOT_VALID)) {
448-
sprintf(buf, "-");
449-
return;
450-
}
451-
elapsed_time = atof(uptime);
452-
} else {
453-
delta_time = get_delta_value("time");
454-
elapsed_time = delta_time / 1000000.0;
455-
}
418+
elapsed_time = get_delta_value("time");
456419

457420
se = get_sysentry("timebase");
458421
timebase = atof(se->value);

src/lparstat.h

-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ extern void get_cpu_stat(struct sysentry *, char *);
6060
extern void get_cpu_physc(struct sysentry *, char *);
6161
extern void get_per_entc(struct sysentry *, char *);
6262
extern void get_cpu_app(struct sysentry *, char *);
63-
extern void get_sys_uptime(struct sysentry *, char *);
6463
extern void get_cpu_util_purr(struct sysentry *unused_se, char *buf);
6564
extern void get_cpu_idle_purr(struct sysentry *unused_se, char *buf);
6665
extern void get_cpu_util_spurr(struct sysentry *unused_se, char *buf);
@@ -272,11 +271,6 @@ struct sysentry system_data[] = {
272271
{.name = "phint",
273272
.descr = "Phantom Interrupts"},
274273

275-
/* /proc/uptime */
276-
{.name = "uptime",
277-
.descr = "System Uptime",
278-
.get = &get_sys_uptime},
279-
280274
/* /sys/devices/system/cpu/cpu<n>/ */
281275
/* Sum of per CPU SPURR registers */
282276
{.name = "spurr",

0 commit comments

Comments
 (0)