+/**********************************
+ * Submitting the results (1 CPU) *
+ **********************************/
+
+/*
+ * Submit one gauge value
+ */
+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);
+}
+
+/*
+ * Submit every data for a single CPU
+ *
+ * Core data is shared for all threads in one core: submitted only for the first thread
+ * Package data is shared for all core in one package: submitted only for the first thread of the first core
+ */
+static int
+submit_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
+{
+ char name[12];
+ double interval_float;
+
+ interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0;
+
+ ssnprintf(name, sizeof(name), "cpu%02d", t->cpu_id);
+
+ if (!aperf_mperf_unstable)
+ turbostat_submit(name, "percent", "c0", 100.0 * t->mperf/t->tsc);
+ if (!aperf_mperf_unstable)
+ 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);
+
+ /* submit per-core data only for 1st thread in core */
+ if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE))
+ goto done;
+
+ ssnprintf(name, sizeof(name), "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);
+
+ /* submit per-package data only for 1st core in package */
+ if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE))
+ goto done;
+
+ ssnprintf(name, sizeof(name), "pkg%02d", p->package_id);
+
+ if (do_ptm)
+ turbostat_submit(NULL, "temperature", name, p->pkg_temp_c);
+
+ if (do_pkg_cstate & (1 << 2))
+ turbostat_submit(name, "percent", "pc2", 100.0 * p->pc2/t->tsc);
+ if (do_pkg_cstate & (1 << 3))
+ turbostat_submit(name, "percent", "pc3", 100.0 * p->pc3/t->tsc);
+ if (do_pkg_cstate & (1 << 6))
+ turbostat_submit(name, "percent", "pc6", 100.0 * p->pc6/t->tsc);
+ if (do_pkg_cstate & (1 << 7))
+ turbostat_submit(name, "percent", "pc7", 100.0 * p->pc7/t->tsc);
+ if (do_pkg_cstate & (1 << 8))
+ turbostat_submit(name, "percent", "pc8", 100.0 * p->pc8/t->tsc);
+ if (do_pkg_cstate & (1 << 9))
+ turbostat_submit(name, "percent", "pc9", 100.0 * p->pc9/t->tsc);
+ if (do_pkg_cstate & (1 << 10))
+ turbostat_submit(name, "percent", "pc10", 100.0 * p->pc10/t->tsc);
+
+ if (do_rapl) {
+ if (do_rapl & RAPL_PKG)
+ turbostat_submit(name, "power", "Pkg_W", p->energy_pkg * rapl_energy_units / interval_float);
+ if (do_rapl & RAPL_CORES)
+ turbostat_submit(name, "power", "Cor_W", p->energy_cores * rapl_energy_units / interval_float);
+ if (do_rapl & RAPL_GFX)
+ turbostat_submit(name, "power", "GFX_W", p->energy_gfx * rapl_energy_units / interval_float);
+ if (do_rapl & RAPL_DRAM)
+ turbostat_submit(name, "power", "RAM_W", p->energy_dram * rapl_energy_units / interval_float);
+ }
+done:
+ return 0;
+}
+
+/**********************************
+ * Looping function over all CPUs *
+ **********************************/
+