From c0f6e19a1a154f31ce085d0010c164cdef5fbe18 Mon Sep 17 00:00:00 2001 From: Kamil Wiatrowski Date: Fri, 2 Feb 2018 14:25:56 +0000 Subject: [PATCH] intel_pmu,intel_rdt plugins: apply formatting rules Run script contrib/format.sh to format the code. Replace zu with new collectd macro PRIsz. Change-Id: I167b1065461e924d7ab260a35f85f5ab162c4165 Signed-off-by: Kamil Wiatrowski --- src/intel_pmu.c | 19 +++++++++--------- src/intel_rdt.c | 4 ++-- src/utils_config_cores.c | 19 +++++++++--------- src/utils_config_cores.h | 1 - src/utils_config_cores_test.c | 46 +++++++++++++++++-------------------------- 5 files changed, 40 insertions(+), 49 deletions(-) diff --git a/src/intel_pmu.c b/src/intel_pmu.c index a7ed7baf..6f8c79df 100644 --- a/src/intel_pmu.c +++ b/src/intel_pmu.c @@ -216,9 +216,9 @@ static void pmu_dump_cgroups(void) { snprintf(cores + strlen(cores), cores_size - strlen(cores), " %d", cgroup->cores[j]); - 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 +231,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 +242,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; @@ -375,7 +375,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 +415,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; @@ -527,6 +527,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 +545,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).", diff --git a/src/intel_rdt.c b/src/intel_rdt.c index b254ba78..6613ab8f 100644 --- a/src/intel_rdt.c +++ b/src/intel_rdt.c @@ -183,7 +183,7 @@ static int rdt_config_cgroups(oconfig_item_t *item) { for (size_t group_idx = 0; group_idx < n; group_idx++) { core_group_t *cgroup = g_rdt->cores.cgroups + group_idx; for (size_t core_idx = 0; core_idx < cgroup->num_cores; core_idx++) { - if (!rdt_is_core_id_valid((int) cgroup->cores[core_idx])) { + if (!rdt_is_core_id_valid((int)cgroup->cores[core_idx])) { ERROR(RDT_PLUGIN ": Core group '%s' contains invalid core id '%d'", cgroup->desc, (int)cgroup->cores[core_idx]); rdt_free_cgroups(); @@ -200,7 +200,7 @@ static int rdt_config_cgroups(oconfig_item_t *item) { ERROR(RDT_PLUGIN ": Error creating default core groups configuration."); return ret; } - n = (size_t) ret; + n = (size_t)ret; INFO(RDT_PLUGIN ": No core groups configured. Default core groups created."); } diff --git a/src/utils_config_cores.c b/src/utils_config_cores.c index 1daa76db..f280f05a 100644 --- a/src/utils_config_cores.c +++ b/src/utils_config_cores.c @@ -49,7 +49,7 @@ static int str_to_uint(const char *s, unsigned *n) { return -EINVAL; char *endptr = NULL; - *n = (unsigned) strtoul(s, &endptr, 0); + *n = (unsigned)strtoul(s, &endptr, 0); if (*s == '\0' || *endptr != '\0') { ERROR(UTIL_NAME ": Failed to parse '%s' into unsigned number", s); return -EINVAL; @@ -84,7 +84,7 @@ static size_t str_list_to_nums(char *s, unsigned *nums, size_t nums_len) { char *token; size_t idx = 0; - while((token = strtok_r(s, ",", &saveptr))) { + while ((token = strtok_r(s, ",", &saveptr))) { char *pos; unsigned start, end = 0; s = NULL; @@ -119,7 +119,8 @@ static size_t str_list_to_nums(char *s, unsigned *nums, size_t nums_len) { if (is_in_list(i, nums, idx)) continue; if (idx >= nums_len) { - WARNING(UTIL_NAME ": exceeded the cores number limit: %zu", nums_len); + WARNING(UTIL_NAME ": exceeded the cores number limit: %" PRIsz, + nums_len); return idx; } nums[idx] = i; @@ -202,7 +203,8 @@ int config_cores_parse(const oconfig_item_t *ci, core_groups_list_t *cgl) { unsigned cores[MAX_CORES] = {0}; if (cg_idx >= STATIC_ARRAY_SIZE(cgroups)) { - ERROR(UTIL_NAME ": Configuration exceeds maximum number of cores: %zu", + ERROR(UTIL_NAME + ": Configuration exceeds maximum number of cores: %" PRIsz, STATIC_ARRAY_SIZE(cgroups)); ret = -EINVAL; goto parse_error; @@ -290,7 +292,7 @@ int config_cores_parse(const oconfig_item_t *ci, core_groups_list_t *cgl) { parse_error: cg_idx = 0; - while(cg_idx < STATIC_ARRAY_SIZE(cgroups) && cgroups[cg_idx].desc != NULL) { + while (cg_idx < STATIC_ARRAY_SIZE(cgroups) && cgroups[cg_idx].desc != NULL) { sfree(cgroups[cg_idx].desc); sfree(cgroups[cg_idx].cores); cg_idx++; @@ -324,9 +326,9 @@ int config_cores_default(int num_cores, core_groups_list_t *cgl) { cgl->cgroups[i].desc = strdup(desc); if (cgl->cgroups[i].desc == NULL) { - ERROR(UTIL_NAME ": Failed to allocate description for cgroup %d.", i); - config_cores_cleanup(cgl); - return -ENOMEM; + ERROR(UTIL_NAME ": Failed to allocate description for cgroup %d.", i); + config_cores_cleanup(cgl); + return -ENOMEM; } } return 0; @@ -368,4 +370,3 @@ int config_cores_cmp_cgroups(const core_group_t *cg_a, /* if not all cores are the same */ return -1; } - diff --git a/src/utils_config_cores.h b/src/utils_config_cores.h index de79dde2..c1b92d0a 100644 --- a/src/utils_config_cores.h +++ b/src/utils_config_cores.h @@ -128,4 +128,3 @@ int config_cores_cmp_cgroups(const core_group_t *cg_a, const core_group_t *cg_b); #endif /* UTILS_CONFIG_CORES_H */ - diff --git a/src/utils_config_cores_test.c b/src/utils_config_cores_test.c index 8dc4d531..96451a50 100644 --- a/src/utils_config_cores_test.c +++ b/src/utils_config_cores_test.c @@ -28,34 +28,24 @@ #include "testing.h" #include "utils_config_cores.c" /* sic */ -oconfig_value_t test_cfg_values[] = { - { {"0"}, OCONFIG_TYPE_STRING }, - { {"1-2"}, OCONFIG_TYPE_STRING }, - { {"[3-4]"}, OCONFIG_TYPE_STRING }}; +oconfig_value_t test_cfg_values[] = {{{"0"}, OCONFIG_TYPE_STRING}, + {{"1-2"}, OCONFIG_TYPE_STRING}, + {{"[3-4]"}, OCONFIG_TYPE_STRING}}; oconfig_item_t test_cfg = { - "Cores", - test_cfg_values, - STATIC_ARRAY_SIZE(test_cfg_values), - NULL, - NULL, - 0 }; + "Cores", test_cfg_values, STATIC_ARRAY_SIZE(test_cfg_values), NULL, NULL, + 0}; static int compare_with_test_config(core_groups_list_t *cgl) { - if (cgl->num_cgroups == 4 && - cgl->cgroups[0].num_cores == 1 && - strcmp("0", cgl->cgroups[0].desc) == 0 && - cgl->cgroups[0].cores[0] == 0 && + if (cgl->num_cgroups == 4 && cgl->cgroups[0].num_cores == 1 && + strcmp("0", cgl->cgroups[0].desc) == 0 && cgl->cgroups[0].cores[0] == 0 && cgl->cgroups[1].num_cores == 2 && strcmp("1-2", cgl->cgroups[1].desc) == 0 && - cgl->cgroups[1].cores[0] == 1 && - cgl->cgroups[1].cores[1] == 2 && + cgl->cgroups[1].cores[0] == 1 && cgl->cgroups[1].cores[1] == 2 && cgl->cgroups[2].num_cores == 1 && - strcmp("3", cgl->cgroups[2].desc) == 0 && - cgl->cgroups[2].cores[0] == 3 && + strcmp("3", cgl->cgroups[2].desc) == 0 && cgl->cgroups[2].cores[0] == 3 && cgl->cgroups[3].num_cores == 1 && - strcmp("4", cgl->cgroups[3].desc) == 0 && - cgl->cgroups[3].cores[0] == 4) + strcmp("4", cgl->cgroups[3].desc) == 0 && cgl->cgroups[3].cores[0] == 4) return 0; return -1; @@ -112,7 +102,7 @@ DEF_TEST(cores_list_to_numbers) { n = str_list_to_nums(str, nums, STATIC_ARRAY_SIZE(nums)); EXPECT_EQ_INT(MAX_CORES, n); EXPECT_EQ_INT(0, nums[0]); - EXPECT_EQ_INT(MAX_CORES-1, nums[MAX_CORES-1]); + EXPECT_EQ_INT(MAX_CORES - 1, nums[MAX_CORES - 1]); /* Should return 0 for incorrect syntax. */ strncpy(str, "5g", STATIC_ARRAY_SIZE(str)); @@ -157,8 +147,8 @@ DEF_TEST(cores_option_parse_fail) { int ret = 0; core_groups_list_t cgl = {0}; /* Wrong value, missing closing bracket ] */ - oconfig_value_t values = { {"[0-15"}, OCONFIG_TYPE_STRING }; - oconfig_item_t cfg = { "Cores", &values, 1, NULL, NULL, 0 }; + oconfig_value_t values = {{"[0-15"}, OCONFIG_TYPE_STRING}; + oconfig_item_t cfg = {"Cores", &values, 1, NULL, NULL, 0}; ret = config_cores_parse(&cfg, &cgl); EXPECT_EQ_INT(-EINVAL, ret); @@ -198,7 +188,7 @@ DEF_TEST(cores_default_list_fail) { ret = config_cores_default(-1, &cgl); OK(ret < 0); - ret = config_cores_default(MAX_CORES+1, &cgl); + ret = config_cores_default(MAX_CORES + 1, &cgl); OK(ret < 0); ret = config_cores_default(1, NULL); OK(ret < 0); @@ -223,10 +213,10 @@ DEF_TEST(cores_group_cleanup) { } DEF_TEST(cores_group_cmp) { - unsigned cores_mock[] = {0,1,2}; - core_group_t group_mock = { "0,1,2", cores_mock, 3 }; - unsigned cores_mock_2[] = {2,3}; - core_group_t group_mock_2 = { "2,3", cores_mock_2, 2 }; + unsigned cores_mock[] = {0, 1, 2}; + core_group_t group_mock = {"0,1,2", cores_mock, 3}; + unsigned cores_mock_2[] = {2, 3}; + core_group_t group_mock_2 = {"2,3", cores_mock_2, 2}; int ret = config_cores_cmp_cgroups(&group_mock, &group_mock); EXPECT_EQ_INT(1, ret); -- 2.11.0