From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 40700A00C2; Fri, 24 Apr 2020 17:30:01 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D53B71D177; Fri, 24 Apr 2020 17:29:59 +0200 (CEST) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by dpdk.org (Postfix) with ESMTP id 05C551D164 for ; Fri, 24 Apr 2020 17:29:57 +0200 (CEST) Received: by mail-pf1-f196.google.com with SMTP id x2so1244408pfx.7 for ; Fri, 24 Apr 2020 08:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/0p10XPHhLLZfWiI6+bg/WwShRKOgZAA8rLTs+K7Yfg=; b=zDo1IgGok/hqQ3qYTqYT1GvQkuO6gs0XMPWUbe5RjcfuiJr+YEgjg1+1tobcqDe8rR vwyTBAa6SBcUl1KxJ9ipqSb1xliiJiG5W1wjUn6OHZUUt3BJXspi4V8v9eVpqspxwLA9 Pqio9p50xAHjPDNIRNwcaqHuuwpKPOUpKZ0ddWaJgTUU9LJQSTIRJtYxMtEazFLA31Rn SyYrO/BTTjGCaiixOCzLASUV8PbnukbX8Sgahb4nbkQbEQWsB0IUrnjNBqd+wJRr3O/q ITJc1uKMqmJyIEwsveqB5shDSh3BUEqWTGmNmQM7J8Q6y3lB3aW8kJEd+MjY+fx0Nnma 5cvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/0p10XPHhLLZfWiI6+bg/WwShRKOgZAA8rLTs+K7Yfg=; b=AC25EvWnOhsLukC6CWikT1YUjw4OvQqRsaa67jqYxX0VSf0I+X8IMDLwTkLLe1Iets HYnHv+T6771qjxrc8zzPStjwGRx0bkgiOn7fsQQ4zW0o6Q9EhIVs+u+sIiqPfzCtRuvM Ofx6uWgI0sATZYtxgH+msZtISkdzqd1NktC51ipeUh0x0YcTfHokiXfZqHIKkG9CALmH 1tcptC08k/dChYq3invGG2gPkrEaNhrw8eISYgMKt0z5vnp1YtnmDofw2L2sht2pjYYY MKslSfm4DG4GUqu2gpj/gS8JEO72xiPAruDiv98kMfWzoZ7CNEJbuOJ+83yIhcSAGbcx O8gg== X-Gm-Message-State: AGi0PubEXepF2snHplDb78KzT7elI/j/JpjEkZCq0p2k2HO2w2FV3Kc0 90JyKS/tu6+eY84KkY1RoG1kzw== X-Google-Smtp-Source: APiQypLnSkb4yIfzidxtEM6naEwQH46gFLJnhDIGfgbacxh1sZHHbMiEbvyqwI5oaBfIj1pscyPxRw== X-Received: by 2002:a63:c34e:: with SMTP id e14mr10040071pgd.212.1587742196781; Fri, 24 Apr 2020 08:29:56 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id f21sm6160916pfn.71.2020.04.24.08.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 08:29:56 -0700 (PDT) Date: Fri, 24 Apr 2020 08:29:53 -0700 From: Stephen Hemminger To: Ciara Power Cc: dev@dpdk.org, kevin.laatz@intel.com, reshma.pattan@intel.com, jerinjacobk@gmail.com, david.marchand@redhat.com, keith.wiles@intel.com, mb@smartsharesystems.com, thomas@monjalon.net Message-ID: <20200424082953.4b52ab9e@hermes.lan> In-Reply-To: <20200424124159.45989-3-ciara.power@intel.com> References: <20200319171907.60891-1-ciara.power@intel.com> <20200424124159.45989-1-ciara.power@intel.com> <20200424124159.45989-3-ciara.power@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v4 02/18] telemetry: move code to metrics for later reuse X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Fri, 24 Apr 2020 13:41:43 +0100 Ciara Power wrote: > This commit moves some of the telemetry library code to a new file in > the metrics library. No modifications are made to the moved code, > except what is needed to allow it to compile and run. The additional > code in metrics is built only when the Jansson library is present. > Telemetry functions as normal, using the functions from the > metrics_telemetry file. This move will enable code be reused by the new > version of telemetry in a later commit, to support backward > compatibility with the existing telemetry usage. > > Signed-off-by: Ciara Power Minor comments, none of these are show stoppers. > diff --git a/lib/librte_metrics/rte_metrics.c b/lib/librte_metrics/rte_metrics.c > index df5e32c59f..9b38d7787c 100644 > --- a/lib/librte_metrics/rte_metrics.c > +++ b/lib/librte_metrics/rte_metrics.c > @@ -13,7 +13,6 @@ > #include > #include > > -#define RTE_METRICS_MAX_METRICS 256 > #define RTE_METRICS_MEMZONE_NAME "RTE_METRICS" > > /** > diff --git a/lib/librte_metrics/rte_metrics.h b/lib/librte_metrics/rte_metrics.h > index 77bffe08e4..466ca98c31 100644 > --- a/lib/librte_metrics/rte_metrics.h > +++ b/lib/librte_metrics/rte_metrics.h > @@ -32,6 +32,7 @@ extern "C" { > > /** Maximum length of metric name (including null-terminator) */ > #define RTE_METRICS_MAX_NAME_LEN 64 > +#define RTE_METRICS_MAX_METRICS 256 Exposing max metrics to API/ABI does limit you in the future. > diff --git a/lib/librte_metrics/rte_metrics_telemetry.c b/lib/librte_metrics/rte_metrics_telemetry.c > new file mode 100644 > index 0000000000..a6b2616714 > --- /dev/null > +++ b/lib/librte_metrics/rte_metrics_telemetry.c > @@ -0,0 +1,719 @@ ... > +static int32_t > +rte_metrics_tel_is_port_active(int port_id) portid should be uint16_t like rte_ethdev return bool rather than int > +{ > + int ret; > + > + ret = rte_eth_find_next(port_id); > + if (ret == port_id) > + return 1; > + > + METRICS_LOG_ERR("port_id: %d is invalid, not active", > + port_id); > + > + return 0; > +} > + > +static int32_t > +rte_metrics_tel_reg_port_ethdev_to_metrics(uint16_t port_id) > +{ > + int ret, num_xstats, ret_val, i; > + struct rte_eth_xstat *eth_xstats = NULL; > + struct rte_eth_xstat_name *eth_xstats_names = NULL; You don't need to initialize all variables, and it is actually bad practice with modern compilers since it breaks checking for using values before set. > + > + if (!rte_eth_dev_is_valid_port(port_id)) { > + METRICS_LOG_ERR("port_id: %d is invalid", port_id); > + return -EINVAL; > + } Validity of port_id is already checked by rte_eth_xstats_get > + num_xstats = rte_eth_xstats_get(port_id, NULL, 0); > + if (num_xstats < 0) { > + METRICS_LOG_ERR("rte_eth_xstats_get(%u) failed: %d", > + port_id, num_xstats); > + return -EPERM; > + } > + > + eth_xstats = malloc(sizeof(struct rte_eth_xstat) * num_xstats); > + if (eth_xstats == NULL) { > + METRICS_LOG_ERR("Failed to malloc memory for xstats"); > + return -ENOMEM; > + } > + > + ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats); > + const char *xstats_names[num_xstats]; Please don't put declarations in the middle of the code. You should malloc the names as well > + eth_xstats_names = malloc(sizeof(struct rte_eth_xstat_name) > + * num_xstats); > + if (ret < 0 || ret > num_xstats) { > + METRICS_LOG_ERR("rte_eth_xstats_get(%u) len%i failed: %d", > + port_id, num_xstats, ret); > + ret_val = -EPERM; > + goto free_xstats; > + } > + > + if (eth_xstats_names == NULL) { > + METRICS_LOG_ERR("Failed to malloc memory for xstats_names"); > + ret_val = -ENOMEM; > + goto free_xstats; > + } > + > + ret = rte_eth_xstats_get_names(port_id, eth_xstats_names, num_xstats); > + if (ret < 0 || ret > num_xstats) { > + METRICS_LOG_ERR("rte_eth_xstats_get_names(%u) len%i failed: %d", > + port_id, num_xstats, ret); > + ret_val = -EPERM; > + goto free_xstats; > + } > + > + for (i = 0; i < num_xstats; i++) > + xstats_names[i] = eth_xstats_names[eth_xstats[i].id].name; > + > + ret_val = rte_metrics_reg_names(xstats_names, num_xstats); > + if (ret_val < 0) { > + METRICS_LOG_ERR("rte_metrics_reg_names failed - metrics may already be registered"); > + ret_val = -1; > + goto free_xstats; > + } > + > + goto free_xstats; > + > +free_xstats: > + free(eth_xstats); > + free(eth_xstats_names); > + return ret_val; > +} > + > +int32_t > +rte_metrics_tel_reg_all_ethdev(int *metrics_register_done, int *reg_index_list) > +{ > + struct driver_index { > + const void *dev_ops; > + int reg_index; > + } drv_idx[RTE_MAX_ETHPORTS] = { {0} }; > + int nb_drv_idx = 0; > + uint16_t pid; > + int ret; > + > + RTE_ETH_FOREACH_DEV(pid) { > + int i; > + /* Different device types have different numbers of stats, so > + * first check if the stats for this type of device have > + * already been registered > + */ > + for (i = 0; i < nb_drv_idx; i++) { > + if (rte_eth_devices[pid].dev_ops == > + drv_idx[i].dev_ops) { > + reg_index_list[pid] = drv_idx[i].reg_index; > + break; > + } > + } > + if (i < nb_drv_idx) > + continue; /* we found a match, go to next port */ > + > + /* No match, register a new set of xstats for this port */ > + ret = rte_metrics_tel_reg_port_ethdev_to_metrics(pid); > + if (ret < 0) { > + METRICS_LOG_ERR("Failed to register ethdev metrics"); > + return -1; > + } > + reg_index_list[pid] = ret; > + drv_idx[nb_drv_idx].dev_ops = rte_eth_devices[pid].dev_ops; > + drv_idx[nb_drv_idx].reg_index = ret; > + nb_drv_idx++; > + } > + > + *metrics_register_done = 1; > + return 0; > +} > + > +static int32_t > +rte_metrics_tel_update_metrics_ethdev(uint16_t port_id, int reg_start_index) > +{ > + int ret, num_xstats, i; > + struct rte_eth_xstat *eth_xstats; > + > + if (!rte_eth_dev_is_valid_port(port_id)) { > + METRICS_LOG_ERR("port_id: %d is invalid", port_id); > + return -EINVAL; > + } > + > + ret = rte_metrics_tel_is_port_active(port_id); > + if (ret < 1) > + return -EINVAL; > + > + num_xstats = rte_eth_xstats_get(port_id, NULL, 0); > + if (num_xstats < 0) { > + METRICS_LOG_ERR("rte_eth_xstats_get(%u) failed: %d", port_id, > + num_xstats); > + return -EPERM; > + } The number of metrics on a port should not change (as long as it has not been hot plugged). So you could optimize by knowing number of stats from last query. > + eth_xstats = malloc(sizeof(struct rte_eth_xstat) * num_xstats); > + if (eth_xstats == NULL) { > + METRICS_LOG_ERR("Failed to malloc memory for xstats"); > + return -ENOMEM; > + } > + > + ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats); > + if (ret < 0 || ret > num_xstats) { > + free(eth_xstats); > + METRICS_LOG_ERR("rte_eth_xstats_get(%u) len%i failed: %d", > + port_id, num_xstats, ret); > + return -EPERM; > + } > + > + uint64_t xstats_values[num_xstats]; > + for (i = 0; i < num_xstats; i++) > + xstats_values[i] = eth_xstats[i].value; > + > + ret = rte_metrics_update_values(port_id, reg_start_index, xstats_values, > + num_xstats); > + if (ret < 0) { > + METRICS_LOG_ERR("Could not update metrics values"); > + free(eth_xstats); > + return -EPERM; > + } > + > + free(eth_xstats); > + return 0; > +} > + > +static int > +rte_metrics_tel_get_metrics(uint32_t port_id, struct rte_metric_value > + *metrics, struct rte_metric_name *names, int num_metrics) Don't break awkwardly in the function declaration. > +{ > + int ret, num_values; > + > + if (num_metrics < 0) { if you don't want negative, make it unsigned. > + METRICS_LOG_ERR("Invalid metrics count"); > + return -EINVAL; > + } else if (num_metrics == 0) { else after return non needed. > + METRICS_LOG_ERR("No metrics to display (none have been registered)"); > + return -EPERM; > + } > + > + if (metrics == NULL) { > + METRICS_LOG_ERR("Metrics must be initialised."); > + return -EINVAL; > + } > + > + if (names == NULL) { > + METRICS_LOG_ERR("Names must be initialised."); > + return -EINVAL; > + } > + > + ret = rte_metrics_get_names(names, num_metrics); > + if (ret < 0 || ret > num_metrics) { > + METRICS_LOG_ERR("Cannot get metrics names"); > + return -EPERM; > + } > + > + num_values = rte_metrics_get_values(port_id, NULL, 0); > + ret = rte_metrics_get_values(port_id, metrics, num_values); > + if (ret < 0 || ret > num_values) { > + METRICS_LOG_ERR("Cannot get metrics values"); > + return -EPERM; > + } > + > + return 0; > +}