X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fintel_rdt.c;h=62848dbfe5e24046fae4a4f3ae76606720fb47b6;hp=422d05de3050ed8c71dac8b64364e8728c39f473;hb=54619dc85fd308b21ed09a0271e5c7383c7921b9;hpb=4d08ad76c9ad3fb84138d037ab4586db02c723d1 diff --git a/src/intel_rdt.c b/src/intel_rdt.c index 422d05de..62848dbf 100644 --- a/src/intel_rdt.c +++ b/src/intel_rdt.c @@ -105,7 +105,7 @@ static void rdt_submit_derive(const char *cgroup, const char *type, vl.values_len = 1; sstrncpy(vl.plugin, RDT_PLUGIN, sizeof(vl.plugin)); - snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s", cgroup); + ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s", cgroup); sstrncpy(vl.type, type, sizeof(vl.type)); if (type_instance) sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); @@ -121,7 +121,7 @@ static void rdt_submit_gauge(const char *cgroup, const char *type, vl.values_len = 1; sstrncpy(vl.plugin, RDT_PLUGIN, sizeof(vl.plugin)); - snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s", cgroup); + ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s", cgroup); sstrncpy(vl.type, type, sizeof(vl.type)); if (type_instance) sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); @@ -144,8 +144,8 @@ static void rdt_dump_cgroups(void) { memset(cores, 0, sizeof(cores)); for (size_t j = 0; j < cgroup->num_cores; j++) { - snprintf(cores + strlen(cores), sizeof(cores) - strlen(cores) - 1, " %d", - cgroup->cores[j]); + ssnprintf(cores + strlen(cores), sizeof(cores) - strlen(cores) - 1, " %d", + cgroup->cores[j]); } DEBUG(RDT_PLUGIN ": group[%zu]:", i); @@ -171,8 +171,8 @@ static void rdt_dump_ngroups(void) { for (size_t i = 0; i < g_rdt->num_ngroups; i++) { memset(names, 0, sizeof(names)); for (size_t j = 0; j < g_rdt->ngroups[i].num_names; j++) - snprintf(names + strlen(names), sizeof(names) - strlen(names) - 1, " %s", - g_rdt->ngroups[i].names[j]); + ssnprintf(names + strlen(names), sizeof(names) - strlen(names) - 1, " %s", + g_rdt->ngroups[i].names[j]); DEBUG(RDT_PLUGIN ": group[%d]:", (int)i); DEBUG(RDT_PLUGIN ": description: %s", g_rdt->ngroups[i].desc); @@ -249,8 +249,8 @@ static void rdt_dump_pids_data(void) { for (size_t j = 0; j < g_rdt->ngroups[i].num_names; ++j) { pids_list_t *list = g_rdt->ngroups[i].proc_pids[j]->curr; for (size_t k = 0; k < list->size; k++) - snprintf(pids + strlen(pids), sizeof(pids) - strlen(pids) - 1, " %u", - list->pids[k]); + ssnprintf(pids + strlen(pids), sizeof(pids) - strlen(pids) - 1, " %u", + list->pids[k]); } DEBUG(RDT_PLUGIN ": [%s] %s", g_rdt->ngroups[i].desc, pids); } @@ -325,8 +325,12 @@ static int strlisttoarray(char *str_list, char ***names, size_t *names_num) { continue; if ((isdupstr((const char **)*names, *names_num, token))) { - ERROR(RDT_PLUGIN ": Duplicated process name \'%s\' in group \'%s\'", - token, str_list); + if (str_list != NULL) + ERROR(RDT_PLUGIN ": Duplicated process name \'%s\' in group \'%s\'", + token, str_list); + else + ERROR(RDT_PLUGIN ": Duplicated process name \'%s\'", token); + return -EINVAL; } else { if (0 != strarray_add(names, names_num, token)) { @@ -475,6 +479,8 @@ static void rdt_free_ngroups(rdt_ctx_t *rdt) { } if (rdt->proc_pids) sfree(rdt->proc_pids); + + rdt->num_ngroups = 0; } /* @@ -849,9 +855,9 @@ static void rdt_init_pids_monitoring() { } /* update global proc_pids table */ - proc_pids_t **proc_pids = realloc(g_rdt->proc_pids, - (g_rdt->num_proc_pids + ng->num_names) * - sizeof(*g_rdt->proc_pids)); + proc_pids_t **proc_pids = + realloc(g_rdt->proc_pids, (g_rdt->num_proc_pids + ng->num_names) * + sizeof(*g_rdt->proc_pids)); if (NULL == proc_pids) { ERROR(RDT_PLUGIN ": Alloc error\n"); continue; @@ -882,7 +888,7 @@ static void rdt_init_pids_monitoring() { #endif /* LIBPQOS2 */ /* * NAME - * rdt_free_ngroups + * rdt_free_cgroups * * DESCRIPTION * Function to deallocate memory allocated for core groups. @@ -892,6 +898,7 @@ static void rdt_free_cgroups(void) { for (int i = 0; i < RDT_MAX_CORES; i++) { sfree(g_rdt->pcgroups[i]); } + g_rdt->cores.num_cgroups = 0; } static int rdt_default_cgroups(void) { @@ -919,7 +926,7 @@ static int rdt_default_cgroups(void) { cgroup->num_cores = 1; cgroup->cores[0] = i; - snprintf(desc, sizeof(desc), "%d", g_rdt->pqos_cpu->cores[i].lcore); + ssnprintf(desc, sizeof(desc), "%d", g_rdt->pqos_cpu->cores[i].lcore); cgroup->desc = strdup(desc); if (cgroup->desc == NULL) { ERROR(RDT_PLUGIN ": Error allocating core group description"); @@ -1101,21 +1108,27 @@ static int rdt_config(oconfig_item_t *ci) { reports a failure in configuration and aborts */ - return (0); + return 0; } for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strncasecmp("Cores", child->key, (size_t)strlen("Cores")) == 0) { - if (rdt_config_cgroups(child) != 0) { + if (g_rdt->cores.num_cgroups > 0) { + ERROR(RDT_PLUGIN + ": Configuration parameter \"%s\" can be used only once.", + child->key); + g_state = CONFIGURATION_ERROR; + } else if (rdt_config_cgroups(child) != 0) g_state = CONFIGURATION_ERROR; + + if (g_state == CONFIGURATION_ERROR) /* if we return -1 at this point collectd reports a failure in configuration and aborts */ - return (0); - } + return 0; #if COLLECT_DEBUG rdt_dump_cgroups(); @@ -1128,21 +1141,24 @@ static int rdt_config(oconfig_item_t *ci) { "Resctrl monitoring is needed for PIDs monitoring.", child->key); g_state = CONFIGURATION_ERROR; - /* if we return -1 at this point collectd - reports a failure in configuration and - aborts - */ - return 0; } - if (rdt_config_ngroups(g_rdt, child) != 0) { + else if (g_rdt->num_ngroups > 0) { + ERROR(RDT_PLUGIN + ": Configuration parameter \"%s\" can be used only once.", + child->key); g_state = CONFIGURATION_ERROR; + } + + else if (rdt_config_ngroups(g_rdt, child) != 0) + g_state = CONFIGURATION_ERROR; + + if (g_state == CONFIGURATION_ERROR) /* if we return -1 at this point collectd reports a failure in configuration and aborts */ return 0; - } #if COLLECT_DEBUG rdt_dump_ngroups(); @@ -1249,8 +1265,17 @@ static void rdt_init_cores_monitoring() { static int rdt_init(void) { - if (g_state == CONFIGURATION_ERROR) + if (g_state == CONFIGURATION_ERROR) { + if (g_rdt != NULL) { + if (g_rdt->cores.num_cgroups > 0) + rdt_free_cgroups(); +#ifdef LIBPQOS2 + if (g_rdt->num_ngroups > 0) + rdt_free_ngroups(g_rdt); +#endif + } return -1; + } int rdt_preinint_result = rdt_preinit(); if (rdt_preinint_result != 0)