#include <rte_common.h>
#include <rte_malloc.h>
#include <rte_errno.h>
+#ifdef RTE_LIBRTE_TELEMETRY
+#include <rte_telemetry.h>
+#endif
#include "rte_rawdev.h"
#include "rte_rawdev_pmd.h"
return 0;
}
+#ifdef RTE_LIBRTE_TELEMETRY
+static int
+handle_dev_list(const char *cmd __rte_unused,
+ const char *params __rte_unused,
+ struct rte_tel_data *d)
+{
+ int i;
+
+ rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
+ for (i = 0; i < rawdev_globals.nb_devs; i++)
+ if (rte_rawdevices[i].attached == RTE_RAWDEV_ATTACHED)
+ rte_tel_data_add_array_int(d, i);
+ return 0;
+}
+
+static int
+handle_dev_xstats(const char *cmd __rte_unused,
+ const char *params,
+ struct rte_tel_data *d)
+{
+ uint64_t *rawdev_xstats;
+ struct rte_rawdev_xstats_name *xstat_names;
+ int dev_id, num_xstats, i, ret;
+ unsigned int *ids;
+
+ if (params == NULL || strlen(params) == 0 || !isdigit(*params))
+ return -1;
+
+ dev_id = atoi(params);
+ if (!rte_rawdev_pmd_is_valid_dev(dev_id))
+ return -1;
+
+ num_xstats = xstats_get_count(dev_id);
+ if (num_xstats < 0)
+ return -1;
+
+ /* use one malloc for names, stats and ids */
+ rawdev_xstats = malloc((sizeof(uint64_t) +
+ sizeof(struct rte_rawdev_xstats_name) +
+ sizeof(unsigned int)) * num_xstats);
+ if (rawdev_xstats == NULL)
+ return -1;
+ xstat_names = (void *)&rawdev_xstats[num_xstats];
+ ids = (void *)&xstat_names[num_xstats];
+
+ ret = rte_rawdev_xstats_names_get(dev_id, xstat_names, num_xstats);
+ if (ret < 0 || ret > num_xstats) {
+ free(rawdev_xstats);
+ return -1;
+ }
+
+ for (i = 0; i < num_xstats; i++)
+ ids[i] = i;
+
+ ret = rte_rawdev_xstats_get(dev_id, ids, rawdev_xstats, num_xstats);
+ if (ret < 0 || ret > num_xstats) {
+ free(rawdev_xstats);
+ return -1;
+ }
+
+ rte_tel_data_start_dict(d);
+ for (i = 0; i < num_xstats; i++)
+ rte_tel_data_add_dict_u64(d, xstat_names[i].name,
+ rawdev_xstats[i]);
+
+ free(rawdev_xstats);
+ return 0;
+}
+#endif
+
RTE_INIT(librawdev_init_log)
{
librawdev_logtype = rte_log_register("lib.rawdev");
if (librawdev_logtype >= 0)
rte_log_set_level(librawdev_logtype, RTE_LOG_INFO);
+#ifdef RTE_LIBRTE_TELEMETRY
+ rte_telemetry_register_cmd("/rawdev/list", handle_dev_list,
+ "Returns list of available rawdev ports. Takes no parameters");
+ rte_telemetry_register_cmd("/rawdev/xstats", handle_dev_xstats,
+ "Returns the xstats for a rawdev port. Parameters: int port_id");
+#endif
}