Merge branch 'collectd-5.7'
[collectd.git] / src / intel_pmu.c
index e332c37..ea7c83f 100644 (file)
@@ -67,6 +67,7 @@ struct intel_pmu_ctx_s {
   _Bool hw_cache_events;
   _Bool kernel_pmu_events;
   _Bool sw_events;
+  char  event_list_fn[PATH_MAX];
   char **hw_events;
   size_t hw_events_count;
   struct eventlist *event_list;
@@ -181,8 +182,6 @@ static void pmu_dump_events() {
     DEBUG(PMU_PLUGIN ":     config    : %#x", (unsigned)e->attr.config);
     DEBUG(PMU_PLUGIN ":     size      : %d", e->attr.size);
   }
-
-  return;
 }
 
 static void pmu_dump_config(void) {
@@ -195,8 +194,6 @@ static void pmu_dump_config(void) {
   for (size_t i = 0; i < g_ctx.hw_events_count; i++) {
     DEBUG(PMU_PLUGIN ":   hardware_events[%zu]: %s", i, g_ctx.hw_events[i]);
   }
-
-  return;
 }
 
 #endif /* COLLECT_DEBUG */
@@ -232,24 +229,27 @@ static int pmu_config_hw_events(oconfig_item_t *ci) {
 }
 
 static int pmu_config(oconfig_item_t *ci) {
-  int ret = 0;
 
   DEBUG(PMU_PLUGIN ": %s:%d", __FUNCTION__, __LINE__);
 
   for (int i = 0; i < ci->children_num; i++) {
+    int ret = 0;
     oconfig_item_t *child = ci->children + i;
 
     if (strcasecmp("ReportHardwareCacheEvents", child->key) == 0) {
       ret = cf_util_get_boolean(child, &g_ctx.hw_cache_events);
     } else if (strcasecmp("ReportKernelPMUEvents", child->key) == 0) {
       ret = cf_util_get_boolean(child, &g_ctx.kernel_pmu_events);
+    } else if (strcasecmp("EventList", child->key) == 0) {
+      ret = cf_util_get_string_buffer(child, g_ctx.event_list_fn,
+                                      sizeof(g_ctx.event_list_fn));
     } else if (strcasecmp("HardwareEvents", child->key) == 0) {
       ret = pmu_config_hw_events(child);
     } else if (strcasecmp("ReportSoftwareEvents", child->key) == 0) {
       ret = cf_util_get_boolean(child, &g_ctx.sw_events);
     } else {
       ERROR(PMU_PLUGIN ": Unknown configuration parameter \"%s\".", child->key);
-      ret = (-1);
+      ret = -1;
     }
 
     if (ret != 0) {
@@ -283,7 +283,7 @@ static void pmu_submit_counter(int cpu, char *event, counter_t value) {
   plugin_dispatch_values(&vl);
 }
 
-static int pmu_dispatch_data(void) {
+static void pmu_dispatch_data(void) {
 
   struct event *e;
 
@@ -310,8 +310,6 @@ static int pmu_dispatch_data(void) {
       pmu_submit_counter(-1, e->event, all_value);
     }
   }
-
-  return 0;
 }
 
 static int pmu_read(__attribute__((unused)) user_data_t *ud) {
@@ -322,22 +320,18 @@ static int pmu_read(__attribute__((unused)) user_data_t *ud) {
   ret = read_all_events(g_ctx.event_list);
   if (ret != 0) {
     ERROR(PMU_PLUGIN ": Failed to read values of all events.");
-    return 0;
+    return ret;
   }
 
-  ret = pmu_dispatch_data();
-  if (ret != 0) {
-    ERROR(PMU_PLUGIN ": Failed to dispatch event values.");
-    return 0;
-  }
+  pmu_dispatch_data();
 
   return 0;
 }
 
 static int pmu_add_events(struct eventlist *el, uint32_t type,
-                          event_info_t *events, int count) {
+                          event_info_t *events, size_t count) {
 
-  for (int i = 0; i < count; i++) {
+  for (size_t i = 0; i < count; i++) {
     /* Allocate memory for event struct that contains array of efd structs
        for all cores */
     struct event *e =
@@ -350,7 +344,6 @@ static int pmu_add_events(struct eventlist *el, uint32_t type,
     e->attr.type = type;
     e->attr.config = events[i].config;
     e->attr.size = PERF_ATTR_SIZE_VER0;
-    e->next = NULL;
     if (!el->eventlist)
       el->eventlist = e;
     if (el->eventlist_last)
@@ -493,6 +486,14 @@ static int pmu_init(void) {
 
   /* parse events names if config option is present and is not empty */
   if (g_ctx.hw_events_count) {
+
+    ret = read_events(g_ctx.event_list_fn);
+    if (ret != 0) {
+      ERROR(PMU_PLUGIN ": Failed to read event list file '%s'.",
+            g_ctx.event_list_fn);
+      return ret;
+    }
+
     ret = pmu_add_hw_events(g_ctx.event_list, g_ctx.hw_events,
                             g_ctx.hw_events_count);
     if (ret != 0) {