xref: /dpdk/drivers/event/opdl/opdl_evdev_xstats.c (revision 1bdfe4d76e98fa3ba595f49606038f0a04181a6e)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4 
5 #include "opdl_evdev.h"
6 #include "opdl_log.h"
7 
8 static const char * const port_xstat_str[] = {
9 
10 	"claim_pkts_requested",
11 	"claim_pkts_granted",
12 	"claim_non_empty",
13 	"claim_empty",
14 	"total_cycles",
15 };
16 
17 
18 void
opdl_xstats_init(struct rte_eventdev * dev)19 opdl_xstats_init(struct rte_eventdev *dev)
20 {
21 	uint32_t i, j;
22 
23 	struct opdl_evdev *device = opdl_pmd_priv(dev);
24 
25 	if (!device->do_validation)
26 		return;
27 
28 	for (i = 0; i < device->max_port_nb; i++) {
29 		struct opdl_port *port = &device->ports[i];
30 
31 		for (j = 0; j < max_num_port_xstat; j++) {
32 			uint32_t index = (i * max_num_port_xstat) + j;
33 
34 			/* Name */
35 			snprintf(device->port_xstat[index].stat.name,
36 				sizeof(device->port_xstat[index].stat.name),
37 				"port_%02u_%s", i, port_xstat_str[j]);
38 
39 			/* ID */
40 			device->port_xstat[index].id = index;
41 
42 			/* Stats ptr */
43 			device->port_xstat[index].value = &port->port_stat[j];
44 		}
45 	}
46 }
47 
48 int
opdl_xstats_uninit(struct rte_eventdev * dev)49 opdl_xstats_uninit(struct rte_eventdev *dev)
50 {
51 	struct opdl_evdev *device = opdl_pmd_priv(dev);
52 
53 	if (!device->do_validation)
54 		return 0;
55 
56 	memset(device->port_xstat,
57 	       0,
58 	       sizeof(device->port_xstat));
59 
60 	return 0;
61 }
62 
63 int
opdl_xstats_get_names(const struct rte_eventdev * dev,enum rte_event_dev_xstats_mode mode,uint8_t queue_port_id,struct rte_event_dev_xstats_name * xstats_names,uint64_t * ids,unsigned int size)64 opdl_xstats_get_names(const struct rte_eventdev *dev,
65 		enum rte_event_dev_xstats_mode mode,
66 		uint8_t queue_port_id,
67 		struct rte_event_dev_xstats_name *xstats_names,
68 		uint64_t *ids, unsigned int size)
69 {
70 	struct opdl_evdev *device = opdl_pmd_priv(dev);
71 
72 	if (!device->do_validation)
73 		return -ENOTSUP;
74 
75 	if (mode == RTE_EVENT_DEV_XSTATS_DEVICE ||
76 			mode == RTE_EVENT_DEV_XSTATS_QUEUE)
77 		return -EINVAL;
78 
79 	if (queue_port_id >= device->max_port_nb)
80 		return -EINVAL;
81 
82 	if (size < max_num_port_xstat)
83 		return max_num_port_xstat;
84 
85 	uint32_t port_idx = queue_port_id * max_num_port_xstat;
86 
87 	uint32_t j;
88 	for (j = 0; j < max_num_port_xstat; j++) {
89 
90 		strcpy(xstats_names[j].name,
91 				device->port_xstat[j + port_idx].stat.name);
92 		ids[j] = device->port_xstat[j + port_idx].id;
93 	}
94 
95 	return max_num_port_xstat;
96 }
97 
98 int
opdl_xstats_get(const struct rte_eventdev * dev,enum rte_event_dev_xstats_mode mode,uint8_t queue_port_id,const uint64_t ids[],uint64_t values[],unsigned int n)99 opdl_xstats_get(const struct rte_eventdev *dev,
100 		enum rte_event_dev_xstats_mode mode,
101 		uint8_t queue_port_id,
102 		const uint64_t ids[],
103 		uint64_t values[], unsigned int n)
104 {
105 	struct opdl_evdev *device = opdl_pmd_priv(dev);
106 
107 	if (!device->do_validation)
108 		return -ENOTSUP;
109 
110 	if (mode == RTE_EVENT_DEV_XSTATS_DEVICE ||
111 			mode == RTE_EVENT_DEV_XSTATS_QUEUE)
112 		return -EINVAL;
113 
114 	if (queue_port_id >= device->max_port_nb)
115 		return -EINVAL;
116 
117 	if (n > max_num_port_xstat)
118 		return -EINVAL;
119 
120 	uint32_t p_start = queue_port_id * max_num_port_xstat;
121 	uint32_t p_finish = p_start + max_num_port_xstat;
122 
123 	uint32_t i;
124 	for (i = 0; i < n; i++) {
125 		if (ids[i] < p_start || ids[i] >= p_finish)
126 			return -EINVAL;
127 
128 		values[i] = *(device->port_xstat[ids[i]].value);
129 	}
130 
131 	return n;
132 }
133 
134 uint64_t
opdl_xstats_get_by_name(const struct rte_eventdev * dev,const char * name,uint64_t * id)135 opdl_xstats_get_by_name(const struct rte_eventdev *dev,
136 		const char *name, uint64_t *id)
137 {
138 	struct opdl_evdev *device = opdl_pmd_priv(dev);
139 
140 	if (!device->do_validation)
141 		return -ENOTSUP;
142 
143 	uint32_t max_index = device->max_port_nb * max_num_port_xstat;
144 
145 	uint32_t i;
146 	for (i = 0; i < max_index; i++) {
147 
148 		if (strncmp(name,
149 			   device->port_xstat[i].stat.name,
150 			   RTE_EVENT_DEV_XSTATS_NAME_SIZE) == 0) {
151 			if (id != NULL)
152 				*id = i;
153 			if (device->port_xstat[i].value)
154 				return *(device->port_xstat[i].value);
155 			break;
156 		}
157 	}
158 	return -EINVAL;
159 }
160 
161 int
opdl_xstats_reset(struct rte_eventdev * dev,enum rte_event_dev_xstats_mode mode,int16_t queue_port_id,const uint64_t ids[],uint32_t nb_ids)162 opdl_xstats_reset(struct rte_eventdev *dev,
163 		enum rte_event_dev_xstats_mode mode,
164 		int16_t queue_port_id, const uint64_t ids[],
165 		uint32_t nb_ids)
166 {
167 	struct opdl_evdev *device = opdl_pmd_priv(dev);
168 
169 	if (!device->do_validation)
170 		return -ENOTSUP;
171 
172 	RTE_SET_USED(dev);
173 	RTE_SET_USED(mode);
174 	RTE_SET_USED(queue_port_id);
175 	RTE_SET_USED(ids);
176 	RTE_SET_USED(nb_ids);
177 
178 	return -ENOTSUP;
179 }
180