[v16,6/8] power: keep per-lcore state in lcore variable
Checks
Commit Message
Replace static array of cache-aligned structs with an lcore variable,
to slightly benefit code simplicity and performance.
Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
--
PATCH v6:
* Update FOREACH invocation to match new API.
RFC v3:
* Replace for loop with FOREACH macro.
---
lib/power/rte_power_pmd_mgmt.c | 35 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 18 deletions(-)
@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <rte_lcore.h>
+#include <rte_lcore_var.h>
#include <rte_cycles.h>
#include <rte_cpuflags.h>
#include <rte_malloc.h>
@@ -69,7 +70,7 @@ struct __rte_cache_aligned pmd_core_cfg {
uint64_t sleep_target;
/**< Prevent a queue from triggering sleep multiple times */
};
-static struct pmd_core_cfg lcore_cfgs[RTE_MAX_LCORE];
+static RTE_LCORE_VAR_HANDLE(struct pmd_core_cfg, lcore_cfgs);
static inline bool
queue_equal(const union queue *l, const union queue *r)
@@ -252,12 +253,11 @@ clb_multiwait(uint16_t port_id __rte_unused, uint16_t qidx __rte_unused,
struct rte_mbuf **pkts __rte_unused, uint16_t nb_rx,
uint16_t max_pkts __rte_unused, void *arg)
{
- const unsigned int lcore = rte_lcore_id();
struct queue_list_entry *queue_conf = arg;
struct pmd_core_cfg *lcore_conf;
const bool empty = nb_rx == 0;
- lcore_conf = &lcore_cfgs[lcore];
+ lcore_conf = RTE_LCORE_VAR(lcore_cfgs);
/* early exit */
if (likely(!empty))
@@ -317,13 +317,12 @@ clb_pause(uint16_t port_id __rte_unused, uint16_t qidx __rte_unused,
struct rte_mbuf **pkts __rte_unused, uint16_t nb_rx,
uint16_t max_pkts __rte_unused, void *arg)
{
- const unsigned int lcore = rte_lcore_id();
struct queue_list_entry *queue_conf = arg;
struct pmd_core_cfg *lcore_conf;
const bool empty = nb_rx == 0;
uint32_t pause_duration = rte_power_pmd_mgmt_get_pause_duration();
- lcore_conf = &lcore_cfgs[lcore];
+ lcore_conf = RTE_LCORE_VAR(lcore_cfgs);
if (likely(!empty))
/* early exit */
@@ -358,9 +357,8 @@ clb_scale_freq(uint16_t port_id __rte_unused, uint16_t qidx __rte_unused,
struct rte_mbuf **pkts __rte_unused, uint16_t nb_rx,
uint16_t max_pkts __rte_unused, void *arg)
{
- const unsigned int lcore = rte_lcore_id();
const bool empty = nb_rx == 0;
- struct pmd_core_cfg *lcore_conf = &lcore_cfgs[lcore];
+ struct pmd_core_cfg *lcore_conf = RTE_LCORE_VAR(lcore_cfgs);
struct queue_list_entry *queue_conf = arg;
if (likely(!empty)) {
@@ -519,7 +517,7 @@ rte_power_ethdev_pmgmt_queue_enable(unsigned int lcore_id, uint16_t port_id,
goto end;
}
- lcore_cfg = &lcore_cfgs[lcore_id];
+ lcore_cfg = RTE_LCORE_VAR_LCORE(lcore_id, lcore_cfgs);
/* check if other queues are stopped as well */
ret = cfg_queues_stopped(lcore_cfg);
@@ -620,7 +618,7 @@ rte_power_ethdev_pmgmt_queue_disable(unsigned int lcore_id,
}
/* no need to check queue id as wrong queue id would not be enabled */
- lcore_cfg = &lcore_cfgs[lcore_id];
+ lcore_cfg = RTE_LCORE_VAR_LCORE(lcore_id, lcore_cfgs);
/* check if other queues are stopped as well */
ret = cfg_queues_stopped(lcore_cfg);
@@ -770,21 +768,22 @@ rte_power_pmd_mgmt_get_scaling_freq_max(unsigned int lcore)
}
RTE_INIT(rte_power_ethdev_pmgmt_init) {
- size_t i;
- int j;
+ unsigned int lcore_id;
+ struct pmd_core_cfg *lcore_cfg;
+ int i;
+
+ RTE_LCORE_VAR_ALLOC(lcore_cfgs);
/* initialize all tailqs */
- for (i = 0; i < RTE_DIM(lcore_cfgs); i++) {
- struct pmd_core_cfg *cfg = &lcore_cfgs[i];
- TAILQ_INIT(&cfg->head);
- }
+ RTE_LCORE_VAR_FOREACH(lcore_id, lcore_cfg, lcore_cfgs)
+ TAILQ_INIT(&lcore_cfg->head);
/* initialize config defaults */
emptypoll_max = 512;
pause_duration = 1;
/* scaling defaults out of range to ensure not used unless set by user or app */
- for (j = 0; j < RTE_MAX_LCORE; j++) {
- scale_freq_min[j] = 0;
- scale_freq_max[j] = UINT32_MAX;
+ for (i = 0; i < RTE_MAX_LCORE; i++) {
+ scale_freq_min[i] = 0;
+ scale_freq_max[i] = UINT32_MAX;
}
}