1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
5 #ifndef _RTE_EMPTY_POLL_H
6 #define _RTE_EMPTY_POLL_H
10 * RTE Power Management
15 #include <rte_common.h>
16 #include <rte_byteorder.h>
18 #include <rte_string_fns.h>
19 #include <rte_power.h>
20 #include <rte_timer.h>
26 #define NUM_FREQS RTE_MAX_LCORE_FREQS
28 #define BINS_AV 4 /* Has to be ^2 */
30 #define DROP (NUM_DIRECTIONS * NUM_DEVICES)
32 #define NUM_PRIORITIES 2
34 #define NUM_NODES 256 /* Max core number*/
36 /* Processor Power State */
45 /* Queue Polling State */
47 TRAINING, /* NO TRAFFIC */
54 struct freq_threshold {
58 uint32_t threshold_percent;
59 uint32_t cur_train_iter;
62 /* Each Worker Thread Empty Poll Stats */
63 struct priority_worker {
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;
71 enum queue_state queue_state;
73 uint64_t empty_dequeues_prev;
75 /* Used for training only */
76 struct freq_threshold thresh[NUM_FREQ];
77 enum freq_val cur_freq;
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 */
86 uint32_t iter_counter;
87 uint32_t threshold_ctr;
91 } __rte_cache_aligned;
96 struct priority_worker wrk_stats[NUM_NODES];
98 /* flag to stop rx threads processing packets until training over */
103 /* Empty Poll Parameters */
106 /* Timer related stuff */
107 uint64_t interval_ticks;
108 uint32_t max_train_iter;
110 struct rte_timer timer0;
111 struct stats_data wrk_data;
115 /* Sample App Init information */
118 uint64_t med_base_edpi;
119 uint64_t hgh_base_edpi;
121 enum queue_state state;
127 * Initialize the power management system.
130 * the structure of empty poll configuration
132 * the power state/frequency mapping table
134 * the initialization policy from sample app
138 * - Negative on error.
142 rte_power_empty_poll_stat_init(struct ep_params **eptr, uint8_t *freq_tlb,
143 struct ep_policy *policy);
146 * Free the resource hold by power management system.
150 rte_power_empty_poll_stat_free(void);
153 * Update specific core empty poll counter
154 * It's not thread safe.
161 * - Negative on error.
165 rte_power_empty_poll_stat_update(unsigned int lcore_id);
168 * Update specific core valid poll counter, not thread safe.
173 * The packet number of one valid poll.
177 * - Negative on error.
181 rte_power_poll_stat_update(unsigned int lcore_id, uint8_t nb_pkt);
184 * Fetch specific core empty poll counter.
190 * Current lcore empty poll counter value.
194 rte_power_empty_poll_stat_fetch(unsigned int lcore_id);
197 * Fetch specific core valid poll counter.
203 * Current lcore valid poll counter value.
207 rte_power_poll_stat_fetch(unsigned int lcore_id);
210 * Empty poll state change detection function
213 * The timer structure
215 * The customized parameter
219 rte_empty_poll_detection(struct rte_timer *tim, void *arg);