Skip to content

Commit

Permalink
eal/power: rework lcore init for x86
Browse files Browse the repository at this point in the history
Avoid allocating lcore variables for binaries only linking DPDK and
never using it.
Move power intrinsics init into an explicit helper called from
rte_eal_init().

Signed-off-by: David Marchand <[email protected]>
  • Loading branch information
david-marchand committed Nov 26, 2024
1 parent 5744e91 commit 8f51be4
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/eal/arm/rte_power_intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
#include "rte_cpuflags.h"
#include "rte_power_intrinsics.h"

#include "eal_private.h"

/**
* Set wfet_en if WFET is supported
*/
#ifdef RTE_ARCH_64
static uint8_t wfet_en;
#endif /* RTE_ARCH_64 */

RTE_INIT(rte_power_intrinsics_init)
void
eal_power_intrinsics_arch_init(void)
{
#ifdef RTE_ARCH_64
if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_WFXT))
Expand Down
3 changes: 3 additions & 0 deletions lib/eal/common/eal_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,9 @@ eal_get_internal_configuration(void);
rte_usage_hook_t
eal_get_application_usage_hook(void);

void
eal_power_intrinsics_arch_init(void);

/**
* Instruct primary process that a secondary process wants to attach.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/eal/freebsd/eal.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ rte_eal_init(int argc, char **argv)
return -1;
}

eal_power_intrinsics_arch_init();

eal_check_mem_on_local_socket();

if (rte_thread_set_affinity_by_id(rte_thread_self(),
Expand Down
2 changes: 2 additions & 0 deletions lib/eal/linux/eal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,8 @@ rte_eal_init(int argc, char **argv)
return -1;
}

eal_power_intrinsics_arch_init();

eal_check_mem_on_local_socket();

if (rte_thread_set_affinity_by_id(rte_thread_self(),
Expand Down
7 changes: 7 additions & 0 deletions lib/eal/loongarch/rte_power_intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

#include "rte_power_intrinsics.h"

#include "eal_private.h"

void
eal_power_intrinsics_arch_init(void)
{
}

/**
* This function is not supported on LOONGARCH.
*/
Expand Down
7 changes: 7 additions & 0 deletions lib/eal/ppc/rte_power_intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

#include "rte_power_intrinsics.h"

#include "eal_private.h"

void
eal_power_intrinsics_arch_init(void)
{
}

/**
* This function is not supported on PPC64.
*/
Expand Down
7 changes: 7 additions & 0 deletions lib/eal/riscv/rte_power_intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

#include "rte_power_intrinsics.h"

#include "eal_private.h"

void
eal_power_intrinsics_arch_init(void)
{
}

/**
* This function is not supported on RISC-V 64
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/eal/windows/eal.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ rte_eal_init(int argc, char **argv)
return -1;
}

eal_power_intrinsics_arch_init();

if (rte_thread_set_affinity_by_id(rte_thread_self(),
&lcore_config[config->main_lcore].cpuset) != 0) {
rte_eal_init_alert("Cannot set affinity");
Expand Down
14 changes: 10 additions & 4 deletions lib/eal/x86/rte_power_intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "rte_power_intrinsics.h"

#include "eal_private.h"

/*
* Per-lcore structure holding current status of C0.2 sleeps.
*/
Expand All @@ -22,8 +24,6 @@ struct power_wait_status {

RTE_LCORE_VAR_HANDLE(struct power_wait_status, wait_status);

RTE_LCORE_VAR_INIT(wait_status);

/*
* This function uses UMONITOR/UMWAIT instructions and will enter C0.2 state.
* For more information about usage of these instructions, please refer to
Expand Down Expand Up @@ -235,7 +235,9 @@ rte_power_pause(const uint64_t tsc_timestamp)
return 0;
}

RTE_INIT(rte_power_intrinsics_init) {
void
eal_power_intrinsics_arch_init(void)
{
struct rte_cpu_intrinsics i;

rte_cpu_get_intrinsics_support(&i);
Expand All @@ -247,6 +249,8 @@ RTE_INIT(rte_power_intrinsics_init) {
if (i.power_monitor)
monitor_supported = 1;

RTE_LCORE_VAR_ALLOC(wait_status);

if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_MONITORX)) {
power_monitor_ops.mmonitor = &amd_monitorx;
power_monitor_ops.mwait = &amd_mwaitx;
Expand Down Expand Up @@ -308,7 +312,7 @@ int
rte_power_monitor_multi(const struct rte_power_monitor_cond pmc[],
const uint32_t num, const uint64_t tsc_timestamp)
{
struct power_wait_status *s = RTE_LCORE_VAR(wait_status);
struct power_wait_status *s;
uint32_t i, rc;

/* check if supported */
Expand All @@ -329,6 +333,8 @@ rte_power_monitor_multi(const struct rte_power_monitor_cond pmc[],
if (rc != RTE_XBEGIN_STARTED)
return 0;

s = RTE_LCORE_VAR(wait_status);

/*
* the mere act of reading the lock status here adds the lock to
* the read set. This means that when we trigger a wakeup from another
Expand Down

0 comments on commit 8f51be4

Please sign in to comment.