#include <asm/msr-index.h>
#include <cpuid.h>
+#ifdef HAVE_SYS_CAPABILITY_H
#include <sys/capability.h>
+#endif /* HAVE_SYS_CAPABILITY_H */
#define PLUGIN_NAME "turbostat"
{
unsigned int i;
int ret;
- unsigned int max_package_id, max_core_id, max_thread_id;
- max_package_id = max_core_id = max_thread_id = 0;
+ unsigned int max_package_id, max_core_id, max_threads;
+ max_package_id = max_core_id = max_threads = 0;
/* Clean topology */
free(topology.cpus);
goto err;
else
num_threads = (unsigned int) ret;
- if (num_threads > max_thread_id)
- max_thread_id = num_threads;
+ if (num_threads > max_threads)
+ max_threads = num_threads;
ret = parse_int_file("/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", i);
if (ret < 0)
goto err;
/* Num is max + 1 (need to count 0) */
topology.num_packages = max_package_id + 1;
topology.num_cores = max_core_id + 1;
- topology.num_threads = max_thread_id + 1;
+ topology.num_threads = max_threads;
return 0;
err:
if (*threads == NULL)
goto err;
+ for (i = 0; i < total_threads; ++i)
+ (*threads)[i].cpu_id = topology.max_cpu_id + 1;
+
total_cores = topology.num_cores * topology.num_packages;
*cores = calloc(total_cores, sizeof(struct core_data));
if (*cores == NULL)
if (*packages == NULL)
goto err_clean_cores;
- for (i = 0; i < topology.num_packages; i++)
- (*packages)[i].package_id = i;
-
return 0;
err_clean_cores:
static int
check_permissions(void)
{
+#ifdef HAVE_SYS_CAPABILITY_H
struct __user_cap_header_struct cap_header_data;
cap_user_header_t cap_header = &cap_header_data;
struct __user_cap_data_struct cap_data_data;
cap_user_data_t cap_data = &cap_data_data;
int ret = 0;
+#endif /* HAVE_SYS_CAPABILITY_H */
if (getuid() == 0) {
/* We have everything we need */
return 0;
+#ifndef HAVE_SYS_CAPABILITY_H
+ } else {
+ ERROR("Turbostat plugin: Initialization failed: this plugin "
+ "requires collectd to run as root");
+ return -1;
+ }
+#else /* HAVE_SYS_CAPABILITY_H */
}
/* check for CAP_SYS_RAWIO */
"collectd a special capability (CAP_SYS_RAWIO) and read "
"access to /dev/cpu/*/msr (see previous warnings)");
return ret;
+#endif /* HAVE_SYS_CAPABILITY_H */
}
static int