* Ported to collectd by Vincent Brillault <git@lerya.net>
*/
+/*
+ * _GNU_SOURCE is required because of the following functions:
+ * - CPU_ISSET_S
+ * - CPU_ZERO_S
+ * - CPU_SET_S
+ * - CPU_FREE
+ * - CPU_ALLOC
+ * - CPU_ALLOC_SIZE
+ */
#define _GNU_SOURCE
+
#include <asm/msr-index.h>
#include <stdarg.h>
#include <stdio.h>
#define PLUGIN_NAME "turbostat"
static const char *proc_stat = "/proc/stat";
-static unsigned int interval_sec = 5; /* set with -i interval_sec */
static unsigned int skip_c0;
static unsigned int skip_c1;
static unsigned int do_nhm_cstates;
static unsigned int do_slm_cstates;
static unsigned int has_aperf;
static unsigned int has_epb;
-static unsigned int units = 1000000000; /* Ghz etc */
static unsigned int genuine_intel;
static unsigned int has_invariant_tsc;
static unsigned int do_nehalem_platform_info;
static int do_smi;
-static unsigned int show_pkg;
-static unsigned int show_core;
-static unsigned int show_cpu;
static unsigned int do_rapl;
static unsigned int do_dts;
static unsigned int do_ptm;
char pathname[32];
int fd;
- sprintf(pathname, "/dev/cpu/%d/msr", cpu);
+ ssnprintf(pathname, 32, "/dev/cpu/%d/msr", cpu);
fd = open(pathname, O_RDONLY);
if (fd < 0)
return -1;
/*
* Parse a file containing a single int.
*/
-static int
+static int __attribute__ ((format(printf,1,2)))
parse_int_file(const char *fmt, ...)
{
va_list args;
int matches;
char character;
- sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu);
+ ssnprintf(path, 80, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu);
filep = fopen(path, "r");
if (!filep) {
ERROR("%s: open failed", path);
/* GHz */
if (has_aperf && ((!aperf_mperf_unstable) || (!(t->aperf > t->tsc || t->mperf > t->tsc))))
- turbostat_submit(NULL, "frequency", name, 1.0 * t->tsc / units * t->aperf / t->mperf / interval_float);
+ turbostat_submit(NULL, "frequency", name, 1.0 * t->tsc / 1000000000 * t->aperf / t->mperf / interval_float);
/* SMI */
if (do_smi)
ret = for_all_proc_cpus(count_cpus);
if (ret < 0)
return ret;
- if (topo.num_cpus > 1)
- show_cpu = 1;
DEBUG("num_cpus %d max_cpu_num %d\n", topo.num_cpus, topo.max_cpu_num);
topo.num_cores_per_pkg = max_core_id + 1;
DEBUG("max_core_id %d, sizing for %d cores per package\n",
max_core_id, topo.num_cores_per_pkg);
- if (topo.num_cores_per_pkg > 1)
- show_core = 1;
topo.num_packages = max_package_id + 1;
DEBUG("max_package_id %d, sizing for %d packages\n",
max_package_id, topo.num_packages);
- if (topo.num_packages > 1)
- show_pkg = 1;
topo.num_threads_per_core = max_siblings;
DEBUG("max_siblings %d\n", max_siblings);
turbostat_init(void)
{
int ret;
- struct timespec ts;
DO_OR_GOTO_ERR(check_cpuid());
DO_OR_GOTO_ERR(check_dev_msr());
DO_OR_GOTO_ERR(setup_all_buffers());
DO_OR_GOTO_ERR(for_all_cpus(set_temperature_target, EVEN_COUNTERS));
- ts.tv_sec = interval_sec;
- ts.tv_nsec = 0;
-
- plugin_register_complex_read(NULL, PLUGIN_NAME, turbostat_read, &ts, NULL);
+ plugin_register_complex_read(NULL, PLUGIN_NAME, turbostat_read, NULL, NULL);
return 0;
err:
return ret;
}
-static const char *config_keys[] =
-{
- "Interval",
-};
-static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
-
-static int
-turbostat_config(const char *key, const char *value)
-{
- if (strcasecmp("Interval", key) == 0)
- interval_sec = atoi(value);
- else
- return -1;
- return 0;
-}
-
void module_register(void);
void module_register(void)
{
plugin_register_init(PLUGIN_NAME, turbostat_init);
- plugin_register_config(PLUGIN_NAME, turbostat_config, config_keys, config_keys_num);
}