Skip to content

Commit

Permalink
ACPI: add perf low power callback
Browse files Browse the repository at this point in the history
This patch add an optional callback needed by some PMU features, e.g., AMD
BRS, to give a chance to the perf_events code to change its state before
going to low power and after coming back.

The callback is void when the PERF_NEEDS_LOPWR_CB flag is not set.
This flag must be set in arch specific perf_event.h header whenever needed.
When not set, there is no impact of the ACPI code.

Signed-off-by: Stephane Eranian <eranian@google.com>
  • Loading branch information
Stephane Eranian authored and intel-lab-lkp committed Dec 1, 2021
1 parent 2f4b02d commit a31c16e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/acpi/acpi_pad.c
Expand Up @@ -164,6 +164,9 @@ static int power_saving_thread(void *data)
tsc_marked_unstable = 1;
}
local_irq_disable();

perf_lopwr_cb(true);

tick_broadcast_enable();
tick_broadcast_enter();
stop_critical_timings();
Expand All @@ -172,6 +175,9 @@ static int power_saving_thread(void *data)

start_critical_timings();
tick_broadcast_exit();

perf_lopwr_cb(false);

local_irq_enable();

if (time_before(expire_time, jiffies)) {
Expand Down
5 changes: 5 additions & 0 deletions drivers/acpi/processor_idle.c
Expand Up @@ -20,6 +20,7 @@
#include <linux/tick.h>
#include <linux/cpuidle.h>
#include <linux/cpu.h>
#include <linux/perf_event.h>
#include <acpi/processor.h>

/*
Expand Down Expand Up @@ -546,6 +547,8 @@ static void wait_for_freeze(void)
*/
static void __cpuidle acpi_idle_do_entry(struct acpi_processor_cx *cx)
{
perf_lopwr_cb(true);

if (cx->entry_method == ACPI_CSTATE_FFH) {
/* Call into architectural FFH based C-state */
acpi_processor_ffh_cstate_enter(cx);
Expand All @@ -556,6 +559,8 @@ static void __cpuidle acpi_idle_do_entry(struct acpi_processor_cx *cx)
inb(cx->address);
wait_for_freeze();
}

perf_lopwr_cb(false);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions include/linux/perf_event.h
Expand Up @@ -1674,4 +1674,10 @@ typedef int (perf_snapshot_branch_stack_t)(struct perf_branch_entry *entries,
unsigned int cnt);
DECLARE_STATIC_CALL(perf_snapshot_branch_stack, perf_snapshot_branch_stack_t);

#ifndef PERF_NEEDS_LOPWR_CB
static inline void perf_lopwr_cb(bool mode)
{
}
#endif

#endif /* _LINUX_PERF_EVENT_H */

0 comments on commit a31c16e

Please sign in to comment.