X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fintel_rdt.c;h=7328836694dee755dbdeaa38c51413286dfa6c52;hb=3d5b7121b097f54d50632488883cd9b943e3d1fa;hp=0863a72740b6f8d3a0b6e635e2705e02b84f04b3;hpb=141fd306b2f83d9bd7a4434348ef864c109cbaf1;p=collectd.git diff --git a/src/intel_rdt.c b/src/intel_rdt.c index 0863a727..73288366 100644 --- a/src/intel_rdt.c +++ b/src/intel_rdt.c @@ -3,15 +3,15 @@ * * Copyright(c) 2016 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 in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is furnished to do - * so, subject to the following conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, @@ -25,9 +25,10 @@ * Serhiy Pshyk **/ -#include - #include "common.h" +#include "collectd.h" + +#include #define RDT_PLUGIN "intel_rdt" @@ -35,6 +36,11 @@ #define RDT_MAX_SOCKET_CORES 64 #define RDT_MAX_CORES (RDT_MAX_SOCKET_CORES * RDT_MAX_SOCKETS) +typedef enum { + UNKNOWN = 0, + CONFIGURATION_ERROR, +} rdt_config_status; + struct rdt_core_group_s { char *desc; size_t num_cores; @@ -55,6 +61,8 @@ typedef struct rdt_ctx_s rdt_ctx_t; static rdt_ctx_t *g_rdt = NULL; +static rdt_config_status g_state = UNKNOWN; + static int isdup(const uint64_t *nums, size_t size, uint64_t val) { for (size_t i = 0; i < size; i++) if (nums[i] == val) @@ -264,7 +272,8 @@ static int oconfig_to_cgroups(oconfig_item_t *item, rdt_core_group_t *groups, uint64_t cores[RDT_MAX_CORES] = {0}; char value[DATA_MAX_NAME_LEN]; - if ((item->values[j].value.string == NULL) || (strlen(item->values[j].value.string) == 0)) + if ((item->values[j].value.string == NULL) || + (strlen(item->values[j].value.string) == 0)) continue; sstrncpy(value, item->values[j].value.string, sizeof(value)); @@ -398,15 +407,14 @@ static int rdt_config_cgroups(oconfig_item_t *item) { DEBUG(RDT_PLUGIN ": Core groups [%d]:", item->values_num); for (int j = 0; j < item->values_num; j++) { if (item->values[j].type != OCONFIG_TYPE_STRING) { - ERROR(RDT_PLUGIN ": given core group value is not a string [idx=%d]", - j); + ERROR(RDT_PLUGIN ": given core group value is not a string [idx=%d]", j); return (-EINVAL); } DEBUG(RDT_PLUGIN ": [%d]: %s", j, item->values[j].value.string); } n = oconfig_to_cgroups(item, g_rdt->cgroups, RDT_MAX_CORES, - g_rdt->pqos_cpu->num_cores-1); + g_rdt->pqos_cpu->num_cores - 1); if (n < 0) { rdt_free_cgroups(); ERROR(RDT_PLUGIN ": Error parsing core groups configuration."); @@ -418,8 +426,7 @@ static int rdt_config_cgroups(oconfig_item_t *item) { n = rdt_default_cgroups(); if (n < 0) { rdt_free_cgroups(); - ERROR(RDT_PLUGIN - ": Error creating default core groups configuration."); + ERROR(RDT_PLUGIN ": Error creating default core groups configuration."); return n; } INFO(RDT_PLUGIN @@ -494,8 +501,7 @@ static int rdt_preinit(void) { goto rdt_preinit_error2; } - ret = pqos_cap_get_type(g_rdt->pqos_cap, PQOS_CAP_TYPE_MON, - &g_rdt->cap_mon); + ret = pqos_cap_get_type(g_rdt->pqos_cap, PQOS_CAP_TYPE_MON, &g_rdt->cap_mon); if (ret == PQOS_RETVAL_PARAM) { ERROR(RDT_PLUGIN ": Error retrieving monitoring capabilities."); goto rdt_preinit_error2; @@ -524,8 +530,14 @@ static int rdt_config(oconfig_item_t *ci) { int ret = 0; ret = rdt_preinit(); - if (ret != 0) - return ret; + if (ret != 0) { + g_state = CONFIGURATION_ERROR; + /* if we return -1 at this point collectd + reports a failure in configuration and + aborts + */ + goto exit; + } for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -533,27 +545,33 @@ static int rdt_config(oconfig_item_t *ci) { if (strcasecmp("Cores", child->key) == 0) { ret = rdt_config_cgroups(child); - if (ret != 0) - return ret; + if (ret != 0) { + g_state = CONFIGURATION_ERROR; + /* if we return -1 at this point collectd + reports a failure in configuration and + aborts + */ + goto exit; + } #if COLLECT_DEBUG rdt_dump_cgroups(); #endif /* COLLECT_DEBUG */ } else { - ERROR(RDT_PLUGIN ": Unknown configuration parameter \"%s\".", - child->key); + ERROR(RDT_PLUGIN ": Unknown configuration parameter \"%s\".", child->key); } } +exit: return (0); } static void rdt_submit_derive(char *cgroup, char *type, char *type_instance, - derive_t value) { + derive_t value) { value_list_t vl = VALUE_LIST_INIT; - vl.values = &(value_t) { .derive = value }; + vl.values = &(value_t){.derive = value}; vl.values_len = 1; sstrncpy(vl.plugin, RDT_PLUGIN, sizeof(vl.plugin)); @@ -566,10 +584,10 @@ static void rdt_submit_derive(char *cgroup, char *type, char *type_instance, } static void rdt_submit_gauge(char *cgroup, char *type, char *type_instance, - gauge_t value) { + gauge_t value) { value_list_t vl = VALUE_LIST_INIT; - vl.values = &(value_t) { .gauge = value }; + vl.values = &(value_t){.gauge = value}; vl.values_len = 1; sstrncpy(vl.plugin, RDT_PLUGIN, sizeof(vl.plugin)); @@ -615,10 +633,10 @@ static int rdt_read(__attribute__((unused)) user_data_t *ud) { rdt_submit_gauge(g_rdt->cgroups[i].desc, "ipc", NULL, pv->ipc); if (g_rdt->cgroups[i].events & mbm_events) { - rdt_submit_derive(g_rdt->cgroups[i].desc, "memory_bandwidth", - "local", pv->mbm_local_delta); - rdt_submit_derive(g_rdt->cgroups[i].desc, "memory_bandwidth", - "remote", pv->mbm_remote_delta); + rdt_submit_derive(g_rdt->cgroups[i].desc, "memory_bandwidth", "local", + pv->mbm_local_delta); + rdt_submit_derive(g_rdt->cgroups[i].desc, "memory_bandwidth", "remote", + pv->mbm_remote_delta); } } @@ -628,6 +646,9 @@ static int rdt_read(__attribute__((unused)) user_data_t *ud) { static int rdt_init(void) { int ret; + if(g_state == CONFIGURATION_ERROR) + return (-1); + ret = rdt_preinit(); if (ret != 0) return ret;