ERR_CPU_ALLOC,
ERR_NOT_ROOT,
UNSUPPORTED_CPU,
+ ERR_PATH_TOO_LONG,
};
static int
submit_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
{
- char name[12];
+ char name[DATA_MAX_NAME_LEN];
double interval_float;
interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0;
va_list args;
char path[PATH_MAX];
FILE *filep;
- int value;
+ int len, value;
va_start(args, fmt);
- vsnprintf(path, sizeof(path), fmt, args);
+ len = vsnprintf(path, sizeof(path), fmt, args);
va_end(args);
+ if (len < 0 || len >= PATH_MAX) {
+ ERROR("Turbostat plugin: path truncated: '%s'", path);
+ return -ERR_PATH_TOO_LONG;
+ }
+
filep = fopen(path, "r");
if (!filep) {
ERROR("Turbostat plugin: Failed to open '%s'", path);
return -ERR_CALLOC;
}
-static int
+static void
init_counter(struct thread_data *thread_base, struct core_data *core_base,
struct pkg_data *pkg_base, int cpu_id)
{
c->core_id = cpu->core_id;
p->package_id = cpu->package_id;
-
- return 0;
}
-static int
+static void
initialize_counters(void)
{
- int ret;
int cpu_id;
for (cpu_id = 0; cpu_id <= topology.max_cpu_id; ++cpu_id) {
- if (cpu_is_not_present(cpu_id)) {
+ if (cpu_is_not_present(cpu_id))
continue;
- }
-
- ret = init_counter(EVEN_COUNTERS, cpu_id);
- if (ret < 0)
- return ret;
- ret = init_counter(ODD_COUNTERS, cpu_id);
- if (ret < 0)
- return ret;
- ret = init_counter(DELTA_COUNTERS, cpu_id);
- if (ret < 0)
- return ret;
+ init_counter(EVEN_COUNTERS, cpu_id);
+ init_counter(ODD_COUNTERS, cpu_id);
+ init_counter(DELTA_COUNTERS, cpu_id);
}
- return 0;
}
DO_OR_GOTO_ERR(allocate_counters(&thread_even, &core_even, &package_even));
DO_OR_GOTO_ERR(allocate_counters(&thread_odd, &core_odd, &package_odd));
DO_OR_GOTO_ERR(allocate_counters(&thread_delta, &core_delta, &package_delta));
- DO_OR_GOTO_ERR(initialize_counters());
+ initialize_counters();
DO_OR_GOTO_ERR(for_all_cpus(set_temperature_target, EVEN_COUNTERS));
DO_OR_GOTO_ERR(for_all_cpus(set_temperature_target, ODD_COUNTERS));