+#if KERNEL_LINUX
+#define MAX_AVAIL_FREQS 20
+
+static int num_cpu;
+
+struct cpu_data_t {
+ value_to_rate_state_t time_state[MAX_AVAIL_FREQS];
+} * cpu_data;
+
+/* Flags denoting capability of reporting CPU frequency statistics. */
+static bool report_p_stats = false;
+
+static void cpufreq_stats_init(void) {
+ cpu_data = calloc(num_cpu, sizeof(*cpu_data));
+ if (cpu_data == NULL)
+ return;
+
+ report_p_stats = true;
+
+ /* Check for stats module and disable if not present. */
+ for (int i = 0; i < num_cpu; i++) {
+ char filename[PATH_MAX];
+
+ snprintf(filename, sizeof(filename),
+ "/sys/devices/system/cpu/cpu%d/cpufreq/stats/time_in_state", i);
+ if (access(filename, R_OK)) {
+ NOTICE("cpufreq plugin: File %s not exists or no access. P-State "
+ "statistics will not be reported. Check if `cpufreq-stats' kernel "
+ "module is loaded.",
+ filename);
+ report_p_stats = false;
+ break;
+ }
+
+ snprintf(filename, sizeof(filename),
+ "/sys/devices/system/cpu/cpu%d/cpufreq/stats/total_trans", i);
+ if (access(filename, R_OK)) {
+ NOTICE("cpufreq plugin: File %s not exists or no access. P-State "
+ "statistics will not be reported. Check if `cpufreq-stats' kernel "
+ "module is loaded.",
+ filename);
+ report_p_stats = false;
+ break;
+ }
+ }
+ return;
+}
+#endif /* KERNEL_LINUX */