Turbostat: remove proc_stat global variable
[collectd.git] / src / turbostat.c
index ecc2375..1588e65 100644 (file)
 
 #define PLUGIN_NAME "turbostat"
 
-static const char *proc_stat = "/proc/stat";
-static unsigned int skip_c0;
-static unsigned int skip_c1;
+/*
+ * If set, aperf_mperf_unstable disables a/mperf based stats.
+ * This includes: C0 & C1 states, frequency
+ *
+ * This value is automatically set if mperf or aperf decreases
+ */
+static _Bool aperf_mperf_unstable;
+
 static unsigned int do_core_cstate;
 static unsigned int do_pkg_cstate;
-static unsigned int do_rapl;
-static unsigned int do_dts;
-static unsigned int do_ptm;
+static _Bool do_dts;
+static _Bool do_ptm;
 static unsigned int tcc_activation_temp;
+
+static unsigned int do_rapl;
 static double rapl_energy_units;
 
 #define RAPL_PKG               (1 << 0)
@@ -99,9 +105,6 @@ static double rapl_energy_units;
                                        /* 0x642 MSR_PP1_POLICY */
 #define        TJMAX_DEFAULT   100
 
-int aperf_mperf_unstable;
-int backwards_count;
-
 cpu_set_t *cpu_present_set, *cpu_affinity_set, *cpu_saved_affinity_set;
 size_t cpu_present_setsize, cpu_affinity_setsize, cpu_saved_affinity_setsize;
 
@@ -370,7 +373,6 @@ delta_thread(struct thread_data *new, struct thread_data *old,
                old->aperf = new->aperf - old->aperf;
                old->mperf = new->mperf - old->mperf;
        } else {
-
                if (!aperf_mperf_unstable) {
                        WARNING(" APERF or MPERF went backwards * ");
                        WARNING("* Frequency results do not cover entire interval *");
@@ -378,12 +380,6 @@ delta_thread(struct thread_data *new, struct thread_data *old,
 
                        aperf_mperf_unstable = 1;
                }
-               /*
-                * mperf delta is likely a huge "positive" number
-                * can not use it for calculating c0 time
-                */
-               skip_c0 = 1;
-               skip_c1 = 1;
        }
 
 
@@ -720,15 +716,15 @@ for_all_proc_cpus(int (func)(int))
        int cpu_num;
        int retval;
 
-       fp = fopen(proc_stat, "r");
+       fp = fopen("/proc/stat", "r");
         if (!fp) {
-                ERROR("%s: open failed", proc_stat);
+                ERROR("Failed to open /proc/stat");
                 return -ERR_CANT_OPEN_FILE;
         }
 
        retval = fscanf(fp, "cpu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n");
        if (retval != 0) {
-               ERROR("%s: failed to parse format", proc_stat);
+               ERROR("Failed to parse /proc/stat");
                return -ERR_CANT_READ_PROC_STAT;
        }
 
@@ -818,9 +814,9 @@ submit_counters(struct thread_data *t, struct core_data *c,
 
        ssnprintf(name, sizeof(name), "cpu%02d", t->cpu_id);
 
-       if (!skip_c0)
+       if (!aperf_mperf_unstable)
                turbostat_submit(name, "percent", "c0", 100.0 * t->mperf/t->tsc);
-       if (!skip_c1)
+       if (!aperf_mperf_unstable)
                turbostat_submit(name, "percent", "c1", 100.0 * t->c1/t->tsc);
 
        /* GHz */