X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fintel_pmu.c;h=f04f8871e18e492074b43a9a1b761c1e4d81fa93;hb=e10ce37462d3002c296efe1b5b955a0a498d1f3b;hp=a7ed7bafac01e5c0ae48c78f052d22aa7e4cf2e9;hpb=bdcb53df8ca1e24732204d519aa87888b603c280;p=collectd.git diff --git a/src/intel_pmu.c b/src/intel_pmu.c index a7ed7baf..f04f8871 100644 --- a/src/intel_pmu.c +++ b/src/intel_pmu.c @@ -1,7 +1,7 @@ /** * collectd - src/intel_pmu.c * - * Copyright(c) 2017 Intel Corporation. All rights reserved. + * Copyright(c) 2017-2018 Intel Corporation. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,9 +27,9 @@ **/ #include "collectd.h" -#include "common.h" +#include "utils/common/common.h" -#include "utils_config_cores.h" +#include "utils/config_cores/config_cores.h" #include #include @@ -67,9 +67,9 @@ struct event_info { typedef struct event_info event_info_t; struct intel_pmu_ctx_s { - _Bool hw_cache_events; - _Bool kernel_pmu_events; - _Bool sw_events; + 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; @@ -196,7 +196,8 @@ static void pmu_dump_config(void) { DEBUG(PMU_PLUGIN ": software_events : %d", g_ctx.sw_events); 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]); + DEBUG(PMU_PLUGIN ": hardware_events[%" PRIsz "]: %s", i, + g_ctx.hw_events[i]); } } @@ -213,12 +214,16 @@ static void pmu_dump_cgroups(void) { return; } for (size_t j = 0; j < cgroup->num_cores; j++) - snprintf(cores + strlen(cores), cores_size - strlen(cores), " %d", - cgroup->cores[j]); + if (snprintf(cores + strlen(cores), cores_size - strlen(cores), " %d", + cgroup->cores[j]) < 0) { + DEBUG(PMU_PLUGIN ": Failed to write list of cores to string."); + sfree(cores); + return; + } - DEBUG(PMU_PLUGIN ": group[%zu]", i); + DEBUG(PMU_PLUGIN ": group[%" PRIsz "]", i); DEBUG(PMU_PLUGIN ": description: %s", cgroup->desc); - DEBUG(PMU_PLUGIN ": cores count: %zu", cgroup->num_cores); + DEBUG(PMU_PLUGIN ": cores count: %" PRIsz, cgroup->num_cores); DEBUG(PMU_PLUGIN ": cores :%s", cores); sfree(cores); } @@ -231,7 +236,7 @@ static int pmu_validate_cgroups(core_group_t *cgroups, size_t len, /* i - group index, j - core index */ for (size_t i = 0; i < len; i++) { for (size_t j = 0; j < cgroups[i].num_cores; j++) { - int core = (int) cgroups[i].cores[j]; + int core = (int)cgroups[i].cores[j]; /* Core index cannot exceed number of cores in system, note that max_cores include both online and offline CPUs. */ @@ -242,10 +247,10 @@ static int pmu_validate_cgroups(core_group_t *cgroups, size_t len, } } /* Check if cores are set in remaining groups */ - for (size_t k = i+1; k < len; k++) + for (size_t k = i + 1; k < len; k++) if (config_cores_cmp_cgroups(&cgroups[i], &cgroups[k]) != 0) { - ERROR(PMU_PLUGIN ": Same cores cannot be set in different groups."); - return -1; + ERROR(PMU_PLUGIN ": Same cores cannot be set in different groups."); + return -1; } } return 0; @@ -262,7 +267,7 @@ static int pmu_config_hw_events(oconfig_item_t *ci) { return -EINVAL; } - g_ctx.hw_events = calloc(ci->values_num, sizeof(char *)); + g_ctx.hw_events = calloc(ci->values_num, sizeof(*g_ctx.hw_events)); if (g_ctx.hw_events == NULL) { ERROR(PMU_PLUGIN ": Failed to allocate hw events."); return -ENOMEM; @@ -325,8 +330,8 @@ static int pmu_config(oconfig_item_t *ci) { return 0; } -static void pmu_submit_counter(char *cgroup, char *event, counter_t value, - meta_data_t *meta) { +static void pmu_submit_counter(const char *cgroup, const char *event, + counter_t value, meta_data_t *meta) { value_list_t vl = VALUE_LIST_INIT; vl.values = &(value_t){.counter = value}; @@ -375,7 +380,7 @@ static void pmu_dispatch_data(void) { meta_data_t *meta = NULL; for (size_t j = 0; j < cgroup->num_cores; j++) { - int core = (int) cgroup->cores[j]; + int core = (int)cgroup->cores[j]; if (e->efd[core].fd < 0) continue; @@ -415,7 +420,7 @@ static int pmu_read(__attribute__((unused)) user_data_t *ud) { for (size_t i = 0; i < g_ctx.cores.num_cgroups; i++) { core_group_t *cgroup = g_ctx.cores.cgroups + i; for (size_t j = 0; j < cgroup->num_cores; j++) { - int core = (int) cgroup->cores[j]; + int core = (int)cgroup->cores[j]; if (e->efd[core].fd < 0) continue; @@ -441,7 +446,7 @@ static int pmu_add_events(struct eventlist *el, uint32_t type, /* Allocate memory for event struct that contains array of efd structs for all cores */ struct event *e = - calloc(sizeof(struct event) + sizeof(struct efd) * el->num_cpus, 1); + calloc(1, sizeof(struct event) + sizeof(struct efd) * el->num_cpus); if (e == NULL) { ERROR(PMU_PLUGIN ": Failed to allocate event structure"); return -ENOMEM; @@ -471,13 +476,13 @@ static int pmu_add_hw_events(struct eventlist *el, char **e, size_t count) { if (!events) return -1; - char *s, *tmp; + char *s, *tmp = NULL; for (s = strtok_r(events, ",", &tmp); s; s = strtok_r(NULL, ",", &tmp)) { /* Allocate memory for event struct that contains array of efd structs for all cores */ struct event *e = - calloc(sizeof(struct event) + sizeof(struct efd) * el->num_cpus, 1); + calloc(1, sizeof(struct event) + sizeof(struct efd) * el->num_cpus); if (e == NULL) { free(events); return -ENOMEM; @@ -527,6 +532,7 @@ static void pmu_free_events(struct eventlist *el) { while (e) { struct event *next = e->next; + sfree(e->event); sfree(e); e = next; } @@ -544,7 +550,7 @@ static int pmu_setup_events(struct eventlist *el, bool measure_all, for (size_t i = 0; i < g_ctx.cores.num_cgroups; i++) { core_group_t *cgroup = g_ctx.cores.cgroups + i; for (size_t j = 0; j < cgroup->num_cores; j++) { - int core = (int) cgroup->cores[j]; + int core = (int)cgroup->cores[j]; if (setup_event(e, core, leader, measure_all, measure_pid) < 0) { WARNING(PMU_PLUGIN ": perf event '%s' is not available (cpu=%d).",