Skip to content

Commit

Permalink
Merge pull request #509 from brauner/2021-12-13.fixes
Browse files Browse the repository at this point in the history
tree-wide: use PRIu64 to print uint64_t
  • Loading branch information
stgraber committed Dec 13, 2021
2 parents 80613fb + da8546f commit ac5989e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
9 changes: 5 additions & 4 deletions meson.build
Expand Up @@ -18,6 +18,11 @@ conf.set_quoted('PROJECT', meson.project_name())
conf.set_quoted('PROJECT_URL', 'https://linuxcontainers.org/lxcfs/introduction/')
conf.set_quoted('PROJECT_VERSION', meson.project_version(),
description : 'Numerical project version (used where a simple number is expected)')
conf.set_quoted('PACKAGE_VERSION', meson.project_version())
conf.set('_GNU_SOURCE', true)
conf.set('_FILE_OFFSET_BITS', 64)
conf.set('__STDC_FORMAT_MACROS', true)

project_source_root = meson.current_source_dir()
project_build_root = meson.current_build_dir()

Expand Down Expand Up @@ -133,10 +138,6 @@ foreach ident : [
conf.set10('HAVE_' + ident[0].to_upper(), have)
endforeach

conf.set('_GNU_SOURCE', true)
conf.set('_FILE_OFFSET_BITS', 64)
conf.set('__STDC_FORMAT_MACROS', true)

libfuse = dependency('fuse3', required : false)
if libfuse.found()
conf.set10('HAVE_FUSE3', true)
Expand Down
18 changes: 9 additions & 9 deletions src/proc_cpuview.c
Expand Up @@ -683,9 +683,9 @@ int cpuview_proc_stat(const char *cg, const char *cpuset,
}

if (user_surplus > 0)
lxcfs_debug("leftover user: %lu for %s\n", user_surplus, cg);
lxcfs_debug("leftover user: %" PRIu64 "for %s\n", user_surplus, cg);
if (system_surplus > 0)
lxcfs_debug("leftover system: %lu for %s\n", system_surplus, cg);
lxcfs_debug("leftover system: %" PRIu64 "for %s\n", system_surplus, cg);

for (curcpu = 0, i = -1; curcpu < nprocs; curcpu++) {
if (!stat_node->usage[curcpu].online)
Expand All @@ -712,9 +712,9 @@ int cpuview_proc_stat(const char *cg, const char *cpuset,
max_diff_idle_index = curcpu;
}

lxcfs_v("curcpu: %d, diff_user: %lu, diff_system: %lu, diff_idle: %lu\n", curcpu, diff[curcpu].user, diff[curcpu].system, diff[curcpu].idle);
lxcfs_v("curcpu: %d, diff_user: %" PRIu64 ", diff_system: %" PRIu64 ", diff_idle: %" PRIu64 "\n", curcpu, diff[curcpu].user, diff[curcpu].system, diff[curcpu].idle);
}
lxcfs_v("total. diff_user: %lu, diff_system: %lu, diff_idle: %lu\n", diff_user, diff_system, diff_idle);
lxcfs_v("total. diff_user: %" PRIu64 ", diff_system: %" PRIu64 ", diff_idle: %" PRIu64 "\n", diff_user, diff_system, diff_idle);

/* revise cpu usage view to support partial cpu case. */
exact_cpus = exact_cpu_count(cg);
Expand All @@ -724,21 +724,21 @@ int cpuview_proc_stat(const char *cg, const char *cpuset,
uint64_t delta = (uint64_t)((double)(diff_user + diff_system + diff_idle) * (1 - exact_cpus / (double)max_cpus));

lxcfs_v("revising cpu usage view to match the exact cpu count [%f]\n", exact_cpus);
lxcfs_v("delta: %lu\n", delta);
lxcfs_v("idle_sum before: %lu\n", idle_sum);
lxcfs_v("delta: %" PRIu64 "\n", delta);
lxcfs_v("idle_sum before: %" PRIu64 "\n", idle_sum);
if (idle_sum > delta)
idle_sum = idle_sum - delta;
else
idle_sum = 0;
lxcfs_v("idle_sum after: %lu\n", idle_sum);
lxcfs_v("idle_sum after: %l" PRIu64 "\n", idle_sum);

curcpu = max_diff_idle_index;
lxcfs_v("curcpu: %d, idle before: %lu\n", curcpu, stat_node->view[curcpu].idle);
lxcfs_v("curcpu: %d, idle before: %" PRIu64 "\n", curcpu, stat_node->view[curcpu].idle);
if (stat_node->view[curcpu].idle > delta)
stat_node->view[curcpu].idle = stat_node->view[curcpu].idle - delta;
else
stat_node->view[curcpu].idle = 0;
lxcfs_v("curcpu: %d, idle after: %lu\n", curcpu, stat_node->view[curcpu].idle);
lxcfs_v("curcpu: %d, idle after: %" PRIu64 "\n", curcpu, stat_node->view[curcpu].idle);
}
} else {
for (curcpu = 0; curcpu < nprocs; curcpu++) {
Expand Down
12 changes: 6 additions & 6 deletions src/proc_fuse.c
Expand Up @@ -308,7 +308,7 @@ static void get_swap_info(const char *cgroup, uint64_t memlimit,
uint64_t *swusage, uint64_t *memswpriority)
{
__do_free char *memswusage_str = NULL, *memswpriority_str = NULL;
size_t memswlimit = 0, memswusage = 0;
uint64_t memswlimit = 0, memswusage = 0;
int ret;

*swtotal = *swusage = 0;
Expand Down Expand Up @@ -461,13 +461,13 @@ static void get_blkio_io_value(char *str, unsigned major, unsigned minor,
len = strlen(key);
while (*str) {
if (startswith(str, key)) {
sscanf(str + len, "%lu", v);
sscanf(str + len, "%" PRIu64, v);
return;
}
eol = strchr(str, '\n');
if (!eol)
return;
str = eol+1;
str = eol + 1;
}
}

Expand Down Expand Up @@ -621,7 +621,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
stats.read_sectors || stats.write_sectors || stats.read_ticks ||
stats.write_ticks || stats.ios_pgr || stats.total_ticks || stats.rq_ticks ||
stats.discard_merged || stats.discard_sectors || stats.discard_ticks)
snprintf(lbuf, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
snprintf(lbuf, 256, "%u %u %s %" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "\n",
stats.major,
stats.minor,
stats.dev_name,
Expand Down Expand Up @@ -979,7 +979,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,

curcpu++;

ret = sscanf(line, "%*s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
ret = sscanf(line, "%*s %" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64,
&user,
&nice,
&system,
Expand Down Expand Up @@ -1056,7 +1056,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,

cache = d->buf;

int cpuall_len = snprintf(cpuall, CPUALL_MAX_SIZE, "cpu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
int cpuall_len = snprintf(cpuall, CPUALL_MAX_SIZE, "cpu %" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "%" PRIu64 "\n",
user_sum,
nice_sum,
system_sum,
Expand Down
18 changes: 9 additions & 9 deletions src/proc_loadavg.c
Expand Up @@ -49,13 +49,13 @@ static int loadavg = 0;
#define FLUSH_TIME 5 /*the flush rate */
#define DEPTH_DIR 3 /*the depth of per cgroup */
/* The function of calculate loadavg .*/
#define FSHIFT 11 /* nr of bits of precision */
#define FIXED_1 (1 << FSHIFT) /* 1.0 as fixed-point */
#define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */
#define EXP_5 2014 /* 1/exp(5sec/5min) */
#define EXP_15 2037 /* 1/exp(5sec/15min) */
#define FSHIFT (uint64_t)11 /* nr of bits of precision */
#define FIXED_1 ((uint64_t)1 << FSHIFT) /* 1.0 as fixed-point */
#define EXP_1 (uint64_t)1884 /* 1/exp(5sec/1min) as fixed-point */
#define EXP_5 (uint64_t)2014 /* 1/exp(5sec/5min) */
#define EXP_15 (uint64_t)2037 /* 1/exp(5sec/15min) */
#define LOAD_INT(x) ((x) >> FSHIFT)
#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * (uint64_t)100)
static volatile sig_atomic_t loadavg_stop = 0;

struct load_node {
Expand Down Expand Up @@ -225,9 +225,9 @@ int proc_loadavg_read(char *buf, size_t size, off_t offset,
b = n->avenrun[1] + (FIXED_1 / 200);
c = n->avenrun[2] + (FIXED_1 / 200);
total_len = snprintf(d->buf, d->buflen,
"%lu.%02lu "
"%lu.%02lu "
"%lu.%02lu "
"%" PRIu64 ".%02" PRIu64 " "
"%" PRIu64 ".%02lu "
"%" PRIu64 ".%02" PRIu64 " "
"%d/"
"%d "
"%d\n",
Expand Down

0 comments on commit ac5989e

Please sign in to comment.