power: remove unused poll counter
[dpdk.git] / lib / power / rte_power_empty_poll.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation
3  */
4
5 #ifndef _RTE_EMPTY_POLL_H
6 #define _RTE_EMPTY_POLL_H
7
8 /**
9  * @file
10  * RTE Power Management
11  */
12 #include <stdint.h>
13 #include <stdbool.h>
14
15 #include <rte_common.h>
16 #include <rte_byteorder.h>
17 #include <rte_log.h>
18 #include <rte_string_fns.h>
19 #include <rte_power.h>
20 #include <rte_timer.h>
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #define NUM_FREQS  RTE_MAX_LCORE_FREQS
27
28 #define BINS_AV 4 /* Has to be ^2 */
29
30 #define DROP (NUM_DIRECTIONS * NUM_DEVICES)
31
32 #define NUM_PRIORITIES          2
33
34 #define NUM_NODES         256  /* Max core number*/
35
36 /* Processor Power State */
37 enum freq_val {
38         LOW,
39         MED,
40         HGH,
41         NUM_FREQ = NUM_FREQS
42 };
43
44
45 /* Queue Polling State */
46 enum queue_state {
47         TRAINING, /* NO TRAFFIC */
48         MED_NORMAL,   /* MED */
49         HGH_BUSY,     /* HIGH */
50         LOW_PURGE,    /* LOW */
51 };
52
53 /* Queue Stats */
54 struct freq_threshold {
55
56         uint64_t base_edpi;
57         bool trained;
58         uint32_t threshold_percent;
59         uint32_t cur_train_iter;
60 };
61
62 /* Each Worker Thread Empty Poll Stats */
63 struct priority_worker {
64
65         /* Current dequeue and throughput counts */
66         /* These 2 are written to by the worker threads */
67         /* So keep them on their own cache line */
68         uint64_t empty_dequeues;
69         uint64_t num_dequeue_pkts;
70
71         enum queue_state queue_state;
72
73         uint64_t empty_dequeues_prev;
74
75         /* Used for training only */
76         struct freq_threshold thresh[NUM_FREQ];
77         enum freq_val cur_freq;
78
79         /* bucket arrays to calculate the averages */
80         /* edpi mean empty poll counter difference per interval */
81         uint64_t edpi_av[BINS_AV];
82         /* empty poll counter */
83         uint32_t ec;
84
85         uint32_t lcore_id;
86         uint32_t iter_counter;
87         uint32_t threshold_ctr;
88         uint32_t display_ctr;
89         uint8_t  dev_id;
90
91 } __rte_cache_aligned;
92
93
94 struct stats_data {
95
96         struct priority_worker wrk_stats[NUM_NODES];
97
98         /* flag to stop rx threads processing packets until training over */
99         bool start_rx;
100
101 };
102
103 /* Empty Poll Parameters */
104 struct ep_params {
105
106         /* Timer related stuff */
107         uint64_t interval_ticks;
108         uint32_t max_train_iter;
109
110         struct rte_timer timer0;
111         struct stats_data wrk_data;
112 };
113
114
115 /* Sample App Init information */
116 struct ep_policy {
117
118         uint64_t med_base_edpi;
119         uint64_t hgh_base_edpi;
120
121         enum queue_state state;
122 };
123
124
125
126 /**
127  * Initialize the power management system.
128  *
129  * @param eptr
130  *   the structure of empty poll configuration
131  * @param freq_tlb
132  *   the power state/frequency mapping table
133  * @param policy
134  *   the initialization policy from sample app
135  *
136  * @return
137  *  - 0 on success.
138  *  - Negative on error.
139  */
140 __rte_experimental
141 int
142 rte_power_empty_poll_stat_init(struct ep_params **eptr, uint8_t *freq_tlb,
143                 struct ep_policy *policy);
144
145 /**
146  * Free the resource hold by power management system.
147  */
148 __rte_experimental
149 void
150 rte_power_empty_poll_stat_free(void);
151
152 /**
153  * Update specific core empty poll counter
154  * It's not thread safe.
155  *
156  * @param lcore_id
157  *  lcore id
158  *
159  * @return
160  *  - 0 on success.
161  *  - Negative on error.
162  */
163 __rte_experimental
164 int
165 rte_power_empty_poll_stat_update(unsigned int lcore_id);
166
167 /**
168  * Update specific core valid poll counter, not thread safe.
169  *
170  * @param lcore_id
171  *  lcore id.
172  * @param nb_pkt
173  *  The packet number of one valid poll.
174  *
175  * @return
176  *  - 0 on success.
177  *  - Negative on error.
178  */
179 __rte_experimental
180 int
181 rte_power_poll_stat_update(unsigned int lcore_id, uint8_t nb_pkt);
182
183 /**
184  * Fetch specific core empty poll counter.
185  *
186  * @param lcore_id
187  *  lcore id
188  *
189  * @return
190  *  Current lcore empty poll counter value.
191  */
192 __rte_experimental
193 uint64_t
194 rte_power_empty_poll_stat_fetch(unsigned int lcore_id);
195
196 /**
197  * Fetch specific core valid poll counter.
198  *
199  * @param lcore_id
200  *  lcore id
201  *
202  * @return
203  *  Current lcore valid poll counter value.
204  */
205 __rte_experimental
206 uint64_t
207 rte_power_poll_stat_fetch(unsigned int lcore_id);
208
209 /**
210  * Empty poll  state change detection function
211  *
212  * @param  tim
213  *  The timer structure
214  * @param  arg
215  *  The customized parameter
216  */
217 __rte_experimental
218 void
219 rte_empty_poll_detection(struct rte_timer *tim, void *arg);
220
221 #ifdef __cplusplus
222 }
223 #endif
224
225 #endif