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_string_fns.h>
17 #include <rte_timer.h>
23 #define NUM_FREQS RTE_MAX_LCORE_FREQS
25 #define BINS_AV 4 /* Has to be ^2 */
27 #define DROP (NUM_DIRECTIONS * NUM_DEVICES)
29 #define NUM_PRIORITIES 2
31 #define NUM_NODES 256 /* Max core number*/
33 /* Processor Power State */
42 /* Queue Polling State */
44 TRAINING, /* NO TRAFFIC */
51 struct freq_threshold {
55 uint32_t threshold_percent;
56 uint32_t cur_train_iter;
59 /* Each Worker Thread Empty Poll Stats */
60 struct priority_worker {
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;
68 enum queue_state queue_state;
70 uint64_t empty_dequeues_prev;
72 /* Used for training only */
73 struct freq_threshold thresh[NUM_FREQ];
74 enum freq_val cur_freq;
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 */
83 uint32_t iter_counter;
84 uint32_t threshold_ctr;
88 } __rte_cache_aligned;
93 struct priority_worker wrk_stats[NUM_NODES];
95 /* flag to stop rx threads processing packets until training over */
100 /* Empty Poll Parameters */
103 /* Timer related stuff */
104 uint64_t interval_ticks;
105 uint32_t max_train_iter;
107 struct rte_timer timer0;
108 struct stats_data wrk_data;
112 /* Sample App Init information */
115 uint64_t med_base_edpi;
116 uint64_t hgh_base_edpi;
118 enum queue_state state;
124 * Initialize the power management system.
127 * the structure of empty poll configuration
129 * the power state/frequency mapping table
131 * the initialization policy from sample app
135 * - Negative on error.
139 rte_power_empty_poll_stat_init(struct ep_params **eptr, uint8_t *freq_tlb,
140 struct ep_policy *policy);
143 * Free the resource hold by power management system.
147 rte_power_empty_poll_stat_free(void);
150 * Update specific core empty poll counter
151 * It's not thread safe.
158 * - Negative on error.
162 rte_power_empty_poll_stat_update(unsigned int lcore_id);
165 * Update specific core valid poll counter, not thread safe.
170 * The packet number of one valid poll.
174 * - Negative on error.
178 rte_power_poll_stat_update(unsigned int lcore_id, uint8_t nb_pkt);
181 * Fetch specific core empty poll counter.
187 * Current lcore empty poll counter value.
191 rte_power_empty_poll_stat_fetch(unsigned int lcore_id);
194 * Fetch specific core valid poll counter.
200 * Current lcore valid poll counter value.
204 rte_power_poll_stat_fetch(unsigned int lcore_id);
207 * Empty poll state change detection function
210 * The timer structure
212 * The customized parameter
216 rte_empty_poll_detection(struct rte_timer *tim, void *arg);