1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
10 * Metrics are statistics that are not generated by PMDs, and hence
11 * are better reported through a mechanism that is independent from
12 * the ethdev-based extended statistics. Providers will typically
13 * be other libraries and consumers will typically be applications.
15 * Metric information is populated using a push model, where producers
16 * update the values contained within the metric library by calling
17 * an update function on the relevant metrics. Consumers receive
18 * metric information by querying the central metric data, which is
19 * held in shared memory. Currently only bulk querying of metrics
20 * by consumers is supported.
23 #ifndef _RTE_METRICS_H_
24 #define _RTE_METRICS_H_
27 #include <rte_compat.h>
33 /** Maximum length of metric name (including null-terminator) */
34 #define RTE_METRICS_MAX_NAME_LEN 64
37 * Global metric special id.
39 * When used for the port_id parameter when calling
40 * rte_metrics_update_metric() or rte_metrics_update_metric(),
41 * the global metric, which are not associated with any specific
42 * port (i.e. device), are updated.
44 #define RTE_METRICS_GLOBAL -1
48 * A name-key lookup for metrics.
50 * An array of this structure is returned by rte_metrics_get_names().
51 * The struct rte_metric_value references these names via their array index.
53 struct rte_metric_name {
54 /** String describing metric */
55 char name[RTE_METRICS_MAX_NAME_LEN];
60 * Metric value structure.
62 * This structure is used by rte_metrics_get_values() to return metrics,
63 * which are statistics that are not generated by PMDs. It maps a name key,
64 * which corresponds to an index in the array returned by
65 * rte_metrics_get_names().
67 struct rte_metric_value {
68 /** Numeric identifier of metric. */
70 /** Value for metric */
76 * Initializes metric module. This function must be called from
77 * a primary process before metrics are used.
80 * Socket to use for shared memory allocation.
82 void rte_metrics_init(int socket_id);
86 * @b EXPERIMENTAL: this API may change without prior notice
88 * Deinitialize metric module. This function must be called from
89 * a primary process after all the metrics usage is over, to
90 * release the shared memory.
93 * -EINVAL - invalid parameter.
94 * -EIO: Error, unable to access metrics shared memory
95 * (rte_metrics_init() not called)
99 int rte_metrics_deinit(void);
102 * Register a metric, making it available as a reporting parameter.
104 * Registering a metric is the way producers declare a parameter
105 * that they wish to be reported. Once registered, the associated
106 * numeric key can be obtained via rte_metrics_get_names(), which
107 * is required for updating said metric's value.
110 * Metric name. If this exceeds RTE_METRICS_MAX_NAME_LEN (including
111 * the NULL terminator), it is truncated.
114 * - Zero or positive: Success (index key of new metric)
115 * - -EIO: Error, unable to access metrics shared memory
116 * (rte_metrics_init() not called)
117 * - -EINVAL: Error, invalid parameters
118 * - -ENOMEM: Error, maximum metrics reached
120 int rte_metrics_reg_name(const char *name);
123 * Register a set of metrics.
125 * This is a bulk version of rte_metrics_reg_names() and aside from
126 * handling multiple keys at once is functionally identical.
129 * List of metric names
132 * Number of metrics in set
135 * - Zero or positive: Success (index key of start of set)
136 * - -EIO: Error, unable to access metrics shared memory
137 * (rte_metrics_init() not called)
138 * - -EINVAL: Error, invalid parameters
139 * - -ENOMEM: Error, maximum metrics reached
141 int rte_metrics_reg_names(const char * const *names, uint16_t cnt_names);
144 * Get metric name-key lookup table.
147 * A struct rte_metric_name array of at least *capacity* in size to
148 * receive key names. If this is NULL, function returns the required
149 * number of elements for this array.
152 * Size (number of elements) of struct rte_metric_name array.
153 * Disregarded if names is NULL.
156 * - Positive value above capacity: error, *names* is too small.
157 * Return value is required size.
158 * - Positive value equal or less than capacity: Success. Return
159 * value is number of elements filled in.
160 * - Negative value: error.
162 int rte_metrics_get_names(
163 struct rte_metric_name *names,
167 * Get metric value table.
173 * A struct rte_metric_value array of at least *capacity* in size to
174 * receive metric ids and values. If this is NULL, function returns
175 * the required number of elements for this array.
178 * Size (number of elements) of struct rte_metric_value array.
179 * Disregarded if names is NULL.
182 * - Positive value above capacity: error, *values* is too small.
183 * Return value is required size.
184 * - Positive value equal or less than capacity: Success. Return
185 * value is number of elements filled in.
186 * - Negative value: error.
188 int rte_metrics_get_values(
190 struct rte_metric_value *values,
197 * Port to update metrics for
199 * Id of metric to update
204 * - -EIO if unable to access shared metrics memory
207 int rte_metrics_update_value(
210 const uint64_t value);
213 * Updates a metric set. Note that it is an error to try to
214 * update across a set boundary.
217 * Port to update metrics for
219 * Base id of metrics set to update
223 * Number of new values
226 * - -ERANGE if count exceeds metric set size
227 * - -EIO if unable to access shared metrics memory
230 int rte_metrics_update_values(
233 const uint64_t *values,