Merge remote-tracking branch 'origin/collectd-5.8'
[collectd.git] / src / turbostat.c
index 48ef1b2..85f7d87 100644 (file)
@@ -266,7 +266,7 @@ open_msr(unsigned int cpu, _Bool multiple_read) {
     }
   }
 
-  ssnprintf(pathname, sizeof(pathname), "/dev/cpu/%d/msr", cpu);
+  snprintf(pathname, sizeof(pathname), "/dev/cpu/%d/msr", cpu);
   fd = open(pathname, O_RDONLY);
   if (fd < 0) {
     ERROR("turbostat plugin: failed to open %s", pathname);
@@ -556,7 +556,7 @@ static int submit_counters(struct thread_data *t, struct core_data *c,
   DEBUG("turbostat plugin: submit stats for cpu: %d, core: %d, pkg: %d",
         t->cpu_id, c->core_id, p->package_id);
 
-  ssnprintf(name, sizeof(name), "cpu%02d", t->cpu_id);
+  snprintf(name, sizeof(name), "cpu%02d", t->cpu_id);
 
   if (!aperf_mperf_unstable)
     turbostat_submit(name, "percent", "c0", 100.0 * t->mperf / t->tsc);
@@ -567,9 +567,9 @@ static int submit_counters(struct thread_data *t, struct core_data *c,
                    1.0 / 1000000 * t->aperf / interval_float);
 
   if ((!aperf_mperf_unstable) || (!(t->aperf > t->tsc || t->mperf > t->tsc)))
-    turbostat_submit(name, "frequency", "busy", 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) */
   turbostat_submit(name, "gauge", "TSC",
@@ -585,7 +585,11 @@ static int submit_counters(struct thread_data *t, struct core_data *c,
 
   /* If not using logical core numbering, set core id */
   if (!config_lcn) {
-    ssnprintf(name, sizeof(name), "core%02d", c->core_id);
+    if (topology.num_packages > 1)
+      snprintf(name, sizeof(name), "pkg%02d-core%02d", p->package_id,
+               c->core_id);
+    else
+      snprintf(name, sizeof(name), "core%02d", c->core_id);
   }
 
   if (do_core_cstate & (1 << 3))
@@ -602,7 +606,7 @@ static int submit_counters(struct thread_data *t, struct core_data *c,
   if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE))
     goto done;
 
-  ssnprintf(name, sizeof(name), "pkg%02d", p->package_id);
+  snprintf(name, sizeof(name), "pkg%02d", p->package_id);
 
   if (do_ptm)
     turbostat_submit(name, "temperature", NULL, p->pkg_temp_c);
@@ -974,6 +978,7 @@ static int __attribute__((warn_unused_result)) probe_cpu(void) {
     case 0x45: /* HSW */
     case 0x46: /* HSW */
     case 0x3D: /* BDW */
+    case 0x5E: /* SKL */
       do_rapl = RAPL_PKG | RAPL_CORES | RAPL_GFX;
       break;
     case 0x3F: /* HSX */
@@ -1064,8 +1069,8 @@ static int get_threads_on_core(unsigned int cpu) {
   int matches;
   char character;
 
-  ssnprintf(path, sizeof(path),
-            "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu);
+  snprintf(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);
@@ -1118,7 +1123,7 @@ for_all_proc_cpus(int(func)(unsigned int)) {
     retval = func(cpu_num);
     if (retval) {
       fclose(fp);
-      return (retval);
+      return retval;
     }
   }
   fclose(fp);