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);
}
/* 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. */
}
}
/* 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;
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;
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;
while (e) {
struct event *next = e->next;
+ sfree(e->event);
sfree(e);
e = next;
}
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).",
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;
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;
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;
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;
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++;
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;
/* if not all cores are the same */
return -1;
}
-
#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;
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));
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);
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);
}
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);