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