diff --git a/src/turbostat.c b/src/turbostat.c
index 5470e6e4d9c462458e6c9d41fef6f8782fcc34ef..42fed52a3e496b8e87036f20150023ce50a56ff2 100644 (file)
--- a/src/turbostat.c
+++ b/src/turbostat.c
CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set);
CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set);
if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) {
CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set);
CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set);
if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) {
- ERROR("Turbostat plugin: Could not migrate to CPU %d", cpu);
+ ERROR("turbostat plugin: Could not migrate to CPU %d", cpu);
return -1;
}
}
return -1;
}
}
ssnprintf(pathname, sizeof(pathname), "/dev/cpu/%d/msr", cpu);
fd = open(pathname, O_RDONLY);
if (fd < 0) {
ssnprintf(pathname, sizeof(pathname), "/dev/cpu/%d/msr", cpu);
fd = open(pathname, O_RDONLY);
if (fd < 0) {
- ERROR("Turbostat plugin: failed to open %s", pathname);
+ ERROR("turbostat plugin: failed to open %s", pathname);
return -1;
}
return fd;
return -1;
}
return fd;
retval = pread(fd, msr, sizeof *msr, offset);
if (retval != sizeof *msr) {
retval = pread(fd, msr, sizeof *msr, offset);
if (retval != sizeof *msr) {
- ERROR("Turbostat plugin: MSR offset 0x%llx read failed",
+ ERROR("turbostat plugin: MSR offset 0x%llx read failed",
(unsigned long long)offset);
return -1;
}
(unsigned long long)offset);
return -1;
}
#define READ_MSR(msr, dst) \
do { \
if (read_msr(msr_fd, msr, dst)) { \
#define READ_MSR(msr, dst) \
do { \
if (read_msr(msr_fd, msr, dst)) { \
- ERROR("Turbostat plugin: Unable to read " #msr); \
+ ERROR("turbostat plugin: Unable to read " #msr); \
retval = -1; \
goto out; \
} \
retval = -1; \
goto out; \
} \
@@ -463,7 +463,7 @@ delta_thread(struct thread_data *delta, const struct thread_data *new, const str
/* check for TSC < 1 Mcycles over interval */
if (delta->tsc < (1000 * 1000)) {
/* check for TSC < 1 Mcycles over interval */
if (delta->tsc < (1000 * 1000)) {
- WARNING("Turbostat plugin: Insanely slow TSC rate, TSC stops "
+ WARNING("turbostat plugin: Insanely slow TSC rate, TSC stops "
"in idle? You can disable all c-states by booting with"
" 'idle=poll' or just the deep ones with"
" 'processor.max_cstate=1'");
"in idle? You can disable all c-states by booting with"
" 'idle=poll' or just the deep ones with"
" 'processor.max_cstate=1'");
@@ -477,7 +477,7 @@ delta_thread(struct thread_data *delta, const struct thread_data *new, const str
delta->mperf = new->mperf - old->mperf;
} else {
if (!aperf_mperf_unstable) {
delta->mperf = new->mperf - old->mperf;
} else {
if (!aperf_mperf_unstable) {
- WARNING("Turbostat plugin: APERF or MPERF went "
+ WARNING("turbostat plugin: APERF or MPERF went "
"backwards. Frequency results do not cover "
"the entire interval. Fix this by running "
"Linux-2.6.30 or later.");
"backwards. Frequency results do not cover "
"the entire interval. Fix this by running "
"Linux-2.6.30 or later.");
@@ -500,7 +500,7 @@ delta_thread(struct thread_data *delta, const struct thread_data *new, const str
}
if (delta->mperf == 0) {
}
if (delta->mperf == 0) {
- WARNING("Turbostat plugin: cpu%d MPERF 0!", old->cpu_id);
+ WARNING("turbostat plugin: cpu%d MPERF 0!", old->cpu_id);
delta->mperf = 1; /* divide by 0 protection */
}
delta->mperf = 1; /* divide by 0 protection */
}
@@ -560,17 +560,17 @@ submit_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
if (!aperf_mperf_unstable)
turbostat_submit(name, "percent", "c1", 100.0 * t->c1/t->tsc);
if (!aperf_mperf_unstable)
turbostat_submit(name, "percent", "c1", 100.0 * t->c1/t->tsc);
- turbostat_submit("Average", "frequency", name, 1.0 / 1000000 * t->aperf / interval_float);
+ turbostat_submit(name, "frequency", "average", 1.0 / 1000000 * t->aperf / interval_float);
if ((!aperf_mperf_unstable) || (!(t->aperf > t->tsc || t->mperf > t->tsc)))
if ((!aperf_mperf_unstable) || (!(t->aperf > t->tsc || t->mperf > t->tsc)))
- turbostat_submit("Buzy", "frequency", name, 1.0 * t->tsc / 1000000 * t->aperf / t->mperf / interval_float);
+ turbostat_submit(name, "frequency", "busy", 1.0 * t->tsc / 1000000 * t->aperf / t->mperf / interval_float);
/* Sanity check (should stay stable) */
/* Sanity check (should stay stable) */
- turbostat_submit("TSC", "gauge", name, 1.0 * t->tsc / 1000000 / interval_float);
+ turbostat_submit(name, "gauge", "TSC", 1.0 * t->tsc / 1000000 / interval_float);
/* SMI */
if (do_smi)
/* SMI */
if (do_smi)
- turbostat_submit(NULL, "current", name, t->smi_count);
+ turbostat_submit(name, "count", NULL, t->smi_count);
/* submit per-core data only for 1st thread in core */
if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE))
/* submit per-core data only for 1st thread in core */
if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE))
turbostat_submit(name, "percent", "c7", 100.0 * c->c7/t->tsc);
if (do_dts)
turbostat_submit(name, "percent", "c7", 100.0 * c->c7/t->tsc);
if (do_dts)
- turbostat_submit(NULL, "temperature", name, c->core_temp_c);
+ turbostat_submit(name, "temperature", NULL, c->core_temp_c);
/* submit per-package data only for 1st core in package */
if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE))
/* submit per-package data only for 1st core in package */
if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE))
ssnprintf(name, sizeof(name), "pkg%02d", p->package_id);
if (do_ptm)
ssnprintf(name, sizeof(name), "pkg%02d", p->package_id);
if (do_ptm)
- turbostat_submit(NULL, "temperature", name, p->pkg_temp_c);
+ turbostat_submit(name, "temperature", NULL, p->pkg_temp_c);
if (do_pkg_cstate & (1 << 2))
turbostat_submit(name, "percent", "pc2", 100.0 * p->pc2/t->tsc);
if (do_pkg_cstate & (1 << 2))
turbostat_submit(name, "percent", "pc2", 100.0 * p->pc2/t->tsc);
@@ -614,13 +614,13 @@ submit_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
if (do_rapl) {
if (do_rapl & RAPL_PKG)
if (do_rapl) {
if (do_rapl & RAPL_PKG)
- turbostat_submit(name, "power", "Pkg_W", p->energy_pkg * rapl_energy_units / interval_float);
+ turbostat_submit(name, "power", "pkg", p->energy_pkg * rapl_energy_units / interval_float);
if (do_rapl & RAPL_CORES)
if (do_rapl & RAPL_CORES)
- turbostat_submit(name, "power", "Cor_W", p->energy_cores * rapl_energy_units / interval_float);
+ turbostat_submit(name, "power", "cores", p->energy_cores * rapl_energy_units / interval_float);
if (do_rapl & RAPL_GFX)
if (do_rapl & RAPL_GFX)
- turbostat_submit(name, "power", "GFX_W", p->energy_gfx * rapl_energy_units / interval_float);
+ turbostat_submit(name, "power", "GFX", p->energy_gfx * rapl_energy_units / interval_float);
if (do_rapl & RAPL_DRAM)
if (do_rapl & RAPL_DRAM)
- turbostat_submit(name, "power", "RAM_W", p->energy_dram * rapl_energy_units / interval_float);
+ turbostat_submit(name, "power", "DRAM", p->energy_dram * rapl_energy_units / interval_float);
}
done:
return 0;
}
done:
return 0;
@@ -794,7 +794,7 @@ set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_da
guess:
p->tcc_activation_temp = TJMAX_DEFAULT;
guess:
p->tcc_activation_temp = TJMAX_DEFAULT;
- WARNING("Turbostat plugin: cpu%d: Guessing tjMax %d C,"
+ WARNING("turbostat plugin: cpu%d: Guessing tjMax %d C,"
" Please use TCCActivationTemp to specify it.",
t->cpu_id, p->tcc_activation_temp);
" Please use TCCActivationTemp to specify it.",
t->cpu_id, p->tcc_activation_temp);
max_level = ebx = ecx = edx = 0;
__get_cpuid(0, &max_level, &ebx, &ecx, &edx);
if (ebx != 0x756e6547 && edx != 0x49656e69 && ecx != 0x6c65746e) {
max_level = ebx = ecx = edx = 0;
__get_cpuid(0, &max_level, &ebx, &ecx, &edx);
if (ebx != 0x756e6547 && edx != 0x49656e69 && ecx != 0x6c65746e) {
- ERROR("Turbostat plugin: Unsupported CPU (not Intel)");
+ ERROR("turbostat plugin: Unsupported CPU (not Intel)");
return -1;
}
return -1;
}
if (family == 6 || family == 0xf)
model += ((fms >> 16) & 0xf) << 4;
if (!(edx & (1 << 5))) {
if (family == 6 || family == 0xf)
model += ((fms >> 16) & 0xf) << 4;
if (!(edx & (1 << 5))) {
- ERROR("Turbostat plugin: Unsupported CPU (no MSR support)");
+ ERROR("turbostat plugin: Unsupported CPU (no MSR support)");
return -1;
}
return -1;
}
do_dts = eax & (1 << 0);
do_ptm = eax & (1 << 6);
if (!(ecx & (1 << 0))) {
do_dts = eax & (1 << 0);
do_ptm = eax & (1 << 6);
if (!(ecx & (1 << 0))) {
- ERROR("Turbostat plugin: Unsupported CPU (No APERF)");
+ ERROR("turbostat plugin: Unsupported CPU (No APERF)");
return -1;
}
return -1;
}
do_rapl = 0;
}
} else {
do_rapl = 0;
}
} else {
- ERROR("Turbostat plugin: Unsupported CPU (family: %#x, "
+ ERROR("turbostat plugin: Unsupported CPU (family: %#x, "
"model: %#x)", family, model);
return -1;
}
"model: %#x)", family, model);
return -1;
}
len = vsnprintf(path, sizeof(path), fmt, args);
va_end(args);
if (len < 0 || len >= PATH_MAX) {
len = vsnprintf(path, sizeof(path), fmt, args);
va_end(args);
if (len < 0 || len >= PATH_MAX) {
- ERROR("Turbostat plugin: path truncated: '%s'", path);
+ ERROR("turbostat plugin: path truncated: '%s'", path);
return -1;
}
filep = fopen(path, "r");
if (!filep) {
return -1;
}
filep = fopen(path, "r");
if (!filep) {
- ERROR("Turbostat plugin: Failed to open '%s'", path);
+ ERROR("turbostat plugin: Failed to open '%s'", path);
return -1;
}
if (fscanf(filep, "%d", &value) != 1) {
return -1;
}
if (fscanf(filep, "%d", &value) != 1) {
- ERROR("Turbostat plugin: Failed to parse number from '%s'", path);
+ ERROR("turbostat plugin: Failed to parse number from '%s'", path);
return -1;
}
fclose(filep);
return -1;
}
fclose(filep);
ssnprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu);
filep = fopen(path, "r");
if (!filep) {
ssnprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu);
filep = fopen(path, "r");
if (!filep) {
- ERROR("Turbostat plugin: Failed to open '%s'", path);
+ ERROR("turbostat plugin: Failed to open '%s'", path);
return -1;
}
/*
return -1;
}
/*
fp = fopen("/proc/stat", "r");
if (!fp) {
fp = fopen("/proc/stat", "r");
if (!fp) {
- ERROR("Turbostat plugin: Failed to open /proc/stat");
+ ERROR("turbostat plugin: Failed to open /proc/stat");
return -1;
}
retval = fscanf(fp, "cpu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n");
if (retval != 0) {
return -1;
}
retval = fscanf(fp, "cpu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n");
if (retval != 0) {
- ERROR("Turbostat plugin: Failed to parse /proc/stat");
+ ERROR("turbostat plugin: Failed to parse /proc/stat");
fclose(fp);
return -1;
}
fclose(fp);
return -1;
}
allocate_cpu_set(cpu_set_t ** set, size_t * size) {
*set = CPU_ALLOC(topology.max_cpu_id + 1);
if (*set == NULL) {
allocate_cpu_set(cpu_set_t ** set, size_t * size) {
*set = CPU_ALLOC(topology.max_cpu_id + 1);
if (*set == NULL) {
- ERROR("Turbostat plugin: Unable to allocate CPU state");
+ ERROR("turbostat plugin: Unable to allocate CPU state");
return -1;
}
*size = CPU_ALLOC_SIZE(topology.max_cpu_id + 1);
return -1;
}
*size = CPU_ALLOC_SIZE(topology.max_cpu_id + 1);
topology.cpus = calloc(1, (topology.max_cpu_id + 1) * sizeof(struct cpu_topology));
if (topology.cpus == NULL) {
topology.cpus = calloc(1, (topology.max_cpu_id + 1) * sizeof(struct cpu_topology));
if (topology.cpus == NULL) {
- ERROR("Turbostat plugin: Unable to allocate memory for CPU topology");
+ ERROR("turbostat plugin: Unable to allocate memory for CPU topology");
return -1;
}
return -1;
}
struct cpu_topology *cpu = &topology.cpus[i];
if (cpu_is_not_present(i)) {
struct cpu_topology *cpu = &topology.cpus[i];
if (cpu_is_not_present(i)) {
- WARNING("Turbostat plugin: cpu%d NOT PRESENT", i);
+ WARNING("turbostat plugin: cpu%d NOT PRESENT", i);
continue;
}
continue;
}
else if ((unsigned int) ret == i)
cpu->first_thread_in_core = 1;
else if ((unsigned int) ret == i)
cpu->first_thread_in_core = 1;
- DEBUG("Turbostat plugin: cpu %d pkg %d core %d\n",
+ DEBUG("turbostat plugin: cpu %d pkg %d core %d\n",
i, cpu->package_id, cpu->core_id);
}
/* Num is max + 1 (need to count 0) */
i, cpu->package_id, cpu->core_id);
}
/* Num is max + 1 (need to count 0) */
@@ -1253,10 +1253,22 @@ allocate_counters(struct thread_data **threads, struct core_data **cores, struct
unsigned int i;
unsigned int total_threads, total_cores;
unsigned int i;
unsigned int total_threads, total_cores;
+ if ((topology.num_threads == 0)
+ || (topology.num_cores == 0)
+ || (topology.num_packages == 0))
+ {
+ ERROR ("turbostat plugin: Invalid topology: %u threads, %u cores, %u packages",
+ topology.num_threads, topology.num_cores, topology.num_packages);
+ return -1;
+ }
+
total_threads = topology.num_threads * topology.num_cores * topology.num_packages;
*threads = calloc(total_threads, sizeof(struct thread_data));
if (*threads == NULL)
total_threads = topology.num_threads * topology.num_cores * topology.num_packages;
*threads = calloc(total_threads, sizeof(struct thread_data));
if (*threads == NULL)
- goto err;
+ {
+ ERROR ("turbostat plugin: calloc failed");
+ return -1;
+ }
for (i = 0; i < total_threads; ++i)
(*threads)[i].cpu_id = topology.max_cpu_id + 1;
for (i = 0; i < total_threads; ++i)
(*threads)[i].cpu_id = topology.max_cpu_id + 1;
@@ -1264,21 +1276,22 @@ allocate_counters(struct thread_data **threads, struct core_data **cores, struct
total_cores = topology.num_cores * topology.num_packages;
*cores = calloc(total_cores, sizeof(struct core_data));
if (*cores == NULL)
total_cores = topology.num_cores * topology.num_packages;
*cores = calloc(total_cores, sizeof(struct core_data));
if (*cores == NULL)
- goto err_clean_threads;
+ {
+ ERROR ("turbostat plugin: calloc failed");
+ sfree (threads);
+ return -1;
+ }
*packages = calloc(topology.num_packages, sizeof(struct pkg_data));
if (*packages == NULL)
*packages = calloc(topology.num_packages, sizeof(struct pkg_data));
if (*packages == NULL)
- goto err_clean_cores;
+ {
+ ERROR ("turbostat plugin: calloc failed");
+ sfree (cores);
+ sfree (threads);
+ return -1;
+ }
return 0;
return 0;
-
-err_clean_cores:
- free(*cores);
-err_clean_threads:
- free(*threads);
-err:
- ERROR("Turbostat plugin: Failled to allocate memory for counters");
- return -1;
}
static void
}
static void
if ((ret = setup_all_buffers()) < 0)
return ret;
if (for_all_proc_cpus(cpu_is_not_present)) {
if ((ret = setup_all_buffers()) < 0)
return ret;
if (for_all_proc_cpus(cpu_is_not_present)) {
- ERROR("Turbostat plugin: CPU appeared just after "
+ ERROR("turbostat plugin: CPU appeared just after "
"initialization");
return -1;
}
"initialization");
return -1;
}
/* Saving the scheduling affinity, as it will be modified by get_counters */
if (sched_getaffinity(0, cpu_saved_affinity_setsize, cpu_saved_affinity_set) != 0) {
/* Saving the scheduling affinity, as it will be modified by get_counters */
if (sched_getaffinity(0, cpu_saved_affinity_setsize, cpu_saved_affinity_set) != 0) {
- ERROR("Turbostat plugin: Unable to save the CPU affinity");
+ ERROR("turbostat plugin: Unable to save the CPU affinity");
return -1;
}
return -1;
}
return 0;
#ifndef HAVE_SYS_CAPABILITY_H
} else {
return 0;
#ifndef HAVE_SYS_CAPABILITY_H
} else {
- ERROR("Turbostat plugin: Initialization failed: this plugin "
+ ERROR("turbostat plugin: Initialization failed: this plugin "
"requires collectd to run as root");
return -1;
}
"requires collectd to run as root");
return -1;
}
cap_header->pid = getpid();
cap_header->version = _LINUX_CAPABILITY_VERSION;
if (capget(cap_header, cap_data) < 0) {
cap_header->pid = getpid();
cap_header->version = _LINUX_CAPABILITY_VERSION;
if (capget(cap_header, cap_data) < 0) {
- ERROR("Turbostat plugin: capget failed");
+ ERROR("turbostat plugin: capget failed");
return -1;
}
if ((cap_data->effective & (1 << CAP_SYS_RAWIO)) == 0) {
return -1;
}
if ((cap_data->effective & (1 << CAP_SYS_RAWIO)) == 0) {
- WARNING("Turbostat plugin: Collectd doesn't have the "
+ WARNING("turbostat plugin: Collectd doesn't have the "
"CAP_SYS_RAWIO capability. If you don't want to run "
"collectd as root, try running \"setcap "
"cap_sys_rawio=ep\" on collectd binary");
"CAP_SYS_RAWIO capability. If you don't want to run "
"collectd as root, try running \"setcap "
"cap_sys_rawio=ep\" on collectd binary");
}
if (euidaccess("/dev/cpu/0/msr", R_OK)) {
}
if (euidaccess("/dev/cpu/0/msr", R_OK)) {
- WARNING("Turbostat plugin: Collectd cannot open"
+ WARNING("turbostat plugin: Collectd cannot open"
"/dev/cpu/0/msr. If you don't want to run collectd as "
"root, you need to change the ownership (chown) and "
"permissions on /dev/cpu/*/msr to allow such access");
"/dev/cpu/0/msr. If you don't want to run collectd as "
"root, you need to change the ownership (chown) and "
"permissions on /dev/cpu/*/msr to allow such access");
}
if (ret != 0)
}
if (ret != 0)
- ERROR("Turbostat plugin: Initialization failed: this plugin "
+ ERROR("turbostat plugin: Initialization failed: this plugin "
"requires collectd to either to run as root or give "
"collectd a special capability (CAP_SYS_RAWIO) and read "
"access to /dev/cpu/*/msr (see previous warnings)");
"requires collectd to either to run as root or give "
"collectd a special capability (CAP_SYS_RAWIO) and read "
"access to /dev/cpu/*/msr (see previous warnings)");
int ret;
if (stat("/dev/cpu/0/msr", &sb)) {
int ret;
if (stat("/dev/cpu/0/msr", &sb)) {
- ERROR("Turbostat plugin: Initialization failed: /dev/cpu/0/msr"
+ ERROR("turbostat plugin: Initialization failed: /dev/cpu/0/msr"
" does not exist while the CPU supports MSR. You may be "
"missing the corresponding kernel module, please try '# "
"modprobe msr'");
" does not exist while the CPU supports MSR. You may be "
"missing the corresponding kernel module, please try '# "
"modprobe msr'");
if (strcasecmp("CoreCstates", key) == 0) {
tmp_val = strtoul(value, &end, 0);
if (*end != '\0' || tmp_val > UINT_MAX) {
if (strcasecmp("CoreCstates", key) == 0) {
tmp_val = strtoul(value, &end, 0);
if (*end != '\0' || tmp_val > UINT_MAX) {
- ERROR("Turbostat plugin: Invalid CoreCstates '%s'",
+ ERROR("turbostat plugin: Invalid CoreCstates '%s'",
value);
return -1;
}
value);
return -1;
}
} else if (strcasecmp("PackageCstates", key) == 0) {
tmp_val = strtoul(value, &end, 0);
if (*end != '\0' || tmp_val > UINT_MAX) {
} else if (strcasecmp("PackageCstates", key) == 0) {
tmp_val = strtoul(value, &end, 0);
if (*end != '\0' || tmp_val > UINT_MAX) {
- ERROR("Turbostat plugin: Invalid PackageCstates '%s'",
+ ERROR("turbostat plugin: Invalid PackageCstates '%s'",
value);
return -1;
}
value);
return -1;
}
} else if (strcasecmp("RunningAveragePowerLimit", key) == 0) {
tmp_val = strtoul(value, &end, 0);
if (*end != '\0' || tmp_val > UINT_MAX) {
} else if (strcasecmp("RunningAveragePowerLimit", key) == 0) {
tmp_val = strtoul(value, &end, 0);
if (*end != '\0' || tmp_val > UINT_MAX) {
- ERROR("Turbostat plugin: Invalid RunningAveragePowerLimit '%s'",
+ ERROR("turbostat plugin: Invalid RunningAveragePowerLimit '%s'",
value);
return -1;
}
value);
return -1;
}
} else if (strcasecmp("TCCActivationTemp", key) == 0) {
tmp_val = strtoul(value, &end, 0);
if (*end != '\0' || tmp_val > UINT_MAX) {
} else if (strcasecmp("TCCActivationTemp", key) == 0) {
tmp_val = strtoul(value, &end, 0);
if (*end != '\0' || tmp_val > UINT_MAX) {
- ERROR("Turbostat plugin: Invalid TCCActivationTemp '%s'",
+ ERROR("turbostat plugin: Invalid TCCActivationTemp '%s'",
value);
return -1;
}
tcc_activation_temp = (unsigned int) tmp_val;
} else {
value);
return -1;
}
tcc_activation_temp = (unsigned int) tmp_val;
} else {
- ERROR("Turbostat plugin: Invalid configuration option '%s'",
+ ERROR("turbostat plugin: Invalid configuration option '%s'",
key);
return -1;
}
key);
return -1;
}