- fp = fopen(proc_stat, "r");
- if (!fp) {
- ERROR("%s: open failed", 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);
- return -ERR_CANT_READ_PROC_STAT;
- }
-
- while (1) {
- retval = fscanf(fp, "cpu%u %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n", &cpu_num);
- if (retval != 1)
- break;
-
- retval = func(cpu_num);
- if (retval) {
- fclose(fp);
- return(retval);
- }
- }
- fclose(fp);
- return 0;
-}
-
-/*
- * count_cpus()
- * remember the last one seen, it will be the max
- */
-static int
-count_cpus(int cpu)
-{
- if (topo.max_cpu_num < cpu)
- topo.max_cpu_num = cpu;
-
- topo.num_cpus += 1;
- return 0;
-}
-static int
-mark_cpu_present(int cpu)
-{
- CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set);
- return 0;
-}
-
-
-static void
-turbostat_submit (const char *plugin_instance,
- const char *type, const char *type_instance,
- gauge_t value)
-{
- value_list_t vl = VALUE_LIST_INIT;
- value_t v;
-
- v.gauge = value;
- vl.values = &v;
- vl.values_len = 1;
- sstrncpy (vl.host, hostname_g, sizeof (vl.host));
- sstrncpy (vl.plugin, PLUGIN_NAME, sizeof (vl.plugin));
- if (plugin_instance != NULL)
- sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
- sstrncpy (vl.type, type, sizeof (vl.type));
- if (type_instance != NULL)
- sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
-
- plugin_dispatch_values (&vl);
-}
-
-/*
- * column formatting convention & formats
- * package: "pk" 2 columns %2d
- * core: "cor" 3 columns %3d
- * CPU: "CPU" 3 columns %3d
- * Pkg_W: %6.2
- * Cor_W: %6.2
- * GFX_W: %5.2
- * RAM_W: %5.2
- * GHz: "GHz" 3 columns %3.2
- * TSC: "TSC" 3 columns %3.2
- * SMI: "SMI" 4 columns %4d
- * percentage " %pc3" %6.2
- * Perf Status percentage: %5.2
- * "CTMP" 4 columns %4d
- */
-#define NAME_LEN 12
-static int
-submit_counters(struct thread_data *t, struct core_data *c,
- struct pkg_data *p)
-{
- char name[NAME_LEN];
- double interval_float;
-
- interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0;
-
- snprintf(name, NAME_LEN, "cpu%02d", t->cpu_id);
-
- if (!skip_c0)
- turbostat_submit(name, "percent", "c0", 100.0 * t->mperf/t->tsc);
- if (!skip_c1)
- turbostat_submit(name, "percent", "c1", 100.0 * t->c1/t->tsc);
-
- /* GHz */
- if ((!aperf_mperf_unstable) || (!(t->aperf > t->tsc || t->mperf > t->tsc)))
- turbostat_submit(NULL, "frequency", name, 1.0 * t->tsc / 1000000000 * t->aperf / t->mperf / interval_float);
-
- /* SMI */
- turbostat_submit(NULL, "current", name, t->smi_count);
-
- /* print per-core data only for 1st thread in core */
- if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE))
- goto done;
-
- snprintf(name, NAME_LEN, "core%02d", c->core_id);
-
- if (do_core_cstate & (1 << 3))
- turbostat_submit(name, "percent", "c3", 100.0 * c->c3/t->tsc);
- if (do_core_cstate & (1 << 6))
- turbostat_submit(name, "percent", "c6", 100.0 * c->c6/t->tsc);
- if (do_core_cstate & (1 << 7))
- turbostat_submit(name, "percent", "c7", 100.0 * c->c7/t->tsc);
-
- if (do_dts)
- turbostat_submit(NULL, "temperature", name, c->core_temp_c);
-
- /* print per-package data only for 1st core in package */
- if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE))
- goto done;