Message ID | 20250102150201.21639-3-frederic@kernel.org (mailing list archive) |
---|---|
State | Changes Requested, archived |
Headers | show |
Series | cpuidle: Handle TIF_NR_POLLING on behalf of polling idle states | expand |
On Thu, Jan 2, 2025 at 4:02 PM Frederic Weisbecker <frederic@kernel.org> wrote: > > From: Peter Zijlstra <peterz@infradead.org> > > Provide a way to tell the cpuidle core about states monitoring > TIF_NEED_RESCHED on the hardware level, monitor/mwait users being the > only examples in use. > > This will allow cpuidle core to manage TIF_NR_POLLING on behalf of all > kinds of TIF_NEED_RESCHED watching states while keeping a necessary > distinction for the governors between software loops polling on > TIF_NEED_RESCHED and hardware monitored writes to thread flags. > > [fweisbec: _ Initialize flag from acpi_processor_setup_cstates() instead > of acpi_processor_setup_lpi_states(), as the latter seem to > be about arm64... > _ Rename CPUIDLE_FLAG_NO_IPI to CPUIDLE_FLAG_MWAIT] > > Signed-off-by: Peter Zijlstra <peterz@infradead.org> > Signed-off-by: Frederic Weisbecker <frederic@kernel.org> > --- > drivers/acpi/processor_idle.c | 3 +++ > drivers/idle/intel_idle.c | 5 ++++- > include/linux/cpuidle.h | 1 + > 3 files changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c > index 698897b29de2..66cb5536d91e 100644 > --- a/drivers/acpi/processor_idle.c > +++ b/drivers/acpi/processor_idle.c > @@ -806,6 +806,9 @@ static int acpi_processor_setup_cstates(struct acpi_processor *pr) > if (cx->type == ACPI_STATE_C1 || cx->type == ACPI_STATE_C2) > drv->safe_state_index = count; > > + if (cx->entry_method == ACPI_CSTATE_FFH) > + state->flags |= CPUIDLE_FLAG_MWAIT; FFH need not mean MWAIT in principle. FFH in _CST means MWAIT in practice because _CST is used on x86 which implements FFH through MWAIT, but it would be good at least to put a comment here to explain that this code is only expected to run on x86. Or better still, add something like acpi_arch_idle_state_flags(u8 entry_method) that will return CPUIDLE_FLAG_MWAIT for ACPI_CSTATE_FFH and 0 otherwise and then do state->flags |= acpi_arch_idle_state_flags(cx->entry_method); > + > /* > * Halt-induced C1 is not good for ->enter_s2idle, because it > * re-enables interrupts on exit. Moreover, C1 is generally not > diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c > index ac4d8faa3886..d52723fbeb04 100644 > --- a/drivers/idle/intel_idle.c > +++ b/drivers/idle/intel_idle.c > @@ -1787,7 +1787,8 @@ static void __init intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) > if (cx->type > ACPI_STATE_C1) > state->target_residency *= 3; > > - state->flags = MWAIT2flg(cx->address); > + state->flags = MWAIT2flg(cx->address) | CPUIDLE_FLAG_MWAIT; > + > if (cx->type > ACPI_STATE_C2) > state->flags |= CPUIDLE_FLAG_TLB_FLUSHED; > > @@ -2072,6 +2073,8 @@ static bool __init intel_idle_verify_cstate(unsigned int mwait_hint) > > static void state_update_enter_method(struct cpuidle_state *state, int cstate) > { > + state->flags |= CPUIDLE_FLAG_MWAIT; > + > if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) { > /* > * Combining with XSTATE with IBRS or IRQ_ENABLE flags > diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h > index a9ee4fe55dcf..b8084617aa27 100644 > --- a/include/linux/cpuidle.h > +++ b/include/linux/cpuidle.h > @@ -85,6 +85,7 @@ struct cpuidle_state { > #define CPUIDLE_FLAG_OFF BIT(4) /* disable this state by default */ > #define CPUIDLE_FLAG_TLB_FLUSHED BIT(5) /* idle-state flushes TLBs */ > #define CPUIDLE_FLAG_RCU_IDLE BIT(6) /* idle-state takes care of RCU */ > +#define CPUIDLE_FLAG_MWAIT BIT(7) /* hardware need_resched() monitoring */ > > struct cpuidle_device_kobj; > struct cpuidle_state_kobj; > --
On Tue, Jan 14, 2025 at 03:01:26PM +0100, Rafael J. Wysocki wrote: > On Thu, Jan 2, 2025 at 4:02 PM Frederic Weisbecker <frederic@kernel.org> wrote: > > > > From: Peter Zijlstra <peterz@infradead.org> > > > > Provide a way to tell the cpuidle core about states monitoring > > TIF_NEED_RESCHED on the hardware level, monitor/mwait users being the > > only examples in use. > > > > This will allow cpuidle core to manage TIF_NR_POLLING on behalf of all > > kinds of TIF_NEED_RESCHED watching states while keeping a necessary > > distinction for the governors between software loops polling on > > TIF_NEED_RESCHED and hardware monitored writes to thread flags. > > > > [fweisbec: _ Initialize flag from acpi_processor_setup_cstates() instead > > of acpi_processor_setup_lpi_states(), as the latter seem to > > be about arm64... > > _ Rename CPUIDLE_FLAG_NO_IPI to CPUIDLE_FLAG_MWAIT] > > > > Signed-off-by: Peter Zijlstra <peterz@infradead.org> > > Signed-off-by: Frederic Weisbecker <frederic@kernel.org> > > --- > > drivers/acpi/processor_idle.c | 3 +++ > > drivers/idle/intel_idle.c | 5 ++++- > > include/linux/cpuidle.h | 1 + > > 3 files changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c > > index 698897b29de2..66cb5536d91e 100644 > > --- a/drivers/acpi/processor_idle.c > > +++ b/drivers/acpi/processor_idle.c > > @@ -806,6 +806,9 @@ static int acpi_processor_setup_cstates(struct acpi_processor *pr) > > if (cx->type == ACPI_STATE_C1 || cx->type == ACPI_STATE_C2) > > drv->safe_state_index = count; > > > > + if (cx->entry_method == ACPI_CSTATE_FFH) > > + state->flags |= CPUIDLE_FLAG_MWAIT; > > FFH need not mean MWAIT in principle. > > FFH in _CST means MWAIT in practice because _CST is used on x86 which > implements FFH through MWAIT, but it would be good at least to put a > comment here to explain that this code is only expected to run on x86. > > Or better still, add something like acpi_arch_idle_state_flags(u8 > entry_method) that will return CPUIDLE_FLAG_MWAIT for ACPI_CSTATE_FFH > and 0 otherwise and then do > > state->flags |= acpi_arch_idle_state_flags(cx->entry_method); > +1, was about to suggest the same. Though I am not aware of any Arm platforms using C-States(LPI was added to suit Arm requirements), it is better to keep the FFH definition arch specific.
On Tue, Jan 14, 2025 at 3:34 PM Sudeep Holla <sudeep.holla@arm.com> wrote: > > On Tue, Jan 14, 2025 at 03:01:26PM +0100, Rafael J. Wysocki wrote: > > On Thu, Jan 2, 2025 at 4:02 PM Frederic Weisbecker <frederic@kernel.org> wrote: > > > > > > From: Peter Zijlstra <peterz@infradead.org> > > > > > > Provide a way to tell the cpuidle core about states monitoring > > > TIF_NEED_RESCHED on the hardware level, monitor/mwait users being the > > > only examples in use. > > > > > > This will allow cpuidle core to manage TIF_NR_POLLING on behalf of all > > > kinds of TIF_NEED_RESCHED watching states while keeping a necessary > > > distinction for the governors between software loops polling on > > > TIF_NEED_RESCHED and hardware monitored writes to thread flags. > > > > > > [fweisbec: _ Initialize flag from acpi_processor_setup_cstates() instead > > > of acpi_processor_setup_lpi_states(), as the latter seem to > > > be about arm64... > > > _ Rename CPUIDLE_FLAG_NO_IPI to CPUIDLE_FLAG_MWAIT] > > > > > > Signed-off-by: Peter Zijlstra <peterz@infradead.org> > > > Signed-off-by: Frederic Weisbecker <frederic@kernel.org> > > > --- > > > drivers/acpi/processor_idle.c | 3 +++ > > > drivers/idle/intel_idle.c | 5 ++++- > > > include/linux/cpuidle.h | 1 + > > > 3 files changed, 8 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c > > > index 698897b29de2..66cb5536d91e 100644 > > > --- a/drivers/acpi/processor_idle.c > > > +++ b/drivers/acpi/processor_idle.c > > > @@ -806,6 +806,9 @@ static int acpi_processor_setup_cstates(struct acpi_processor *pr) > > > if (cx->type == ACPI_STATE_C1 || cx->type == ACPI_STATE_C2) > > > drv->safe_state_index = count; > > > > > > + if (cx->entry_method == ACPI_CSTATE_FFH) > > > + state->flags |= CPUIDLE_FLAG_MWAIT; > > > > FFH need not mean MWAIT in principle. > > > > FFH in _CST means MWAIT in practice because _CST is used on x86 which > > implements FFH through MWAIT, but it would be good at least to put a > > comment here to explain that this code is only expected to run on x86. > > > > Or better still, add something like acpi_arch_idle_state_flags(u8 > > entry_method) that will return CPUIDLE_FLAG_MWAIT for ACPI_CSTATE_FFH > > and 0 otherwise and then do > > > > state->flags |= acpi_arch_idle_state_flags(cx->entry_method); > > > > +1, was about to suggest the same. Though I am not aware of any Arm platforms > using C-States(LPI was added to suit Arm requirements), it is better to keep > the FFH definition arch specific. Which will be consistent with this patch among other things: https://lore.kernel.org/linux-pm/20250110115953.6058-3-patryk.wlazlyn@linux.intel.com/
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 698897b29de2..66cb5536d91e 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -806,6 +806,9 @@ static int acpi_processor_setup_cstates(struct acpi_processor *pr) if (cx->type == ACPI_STATE_C1 || cx->type == ACPI_STATE_C2) drv->safe_state_index = count; + if (cx->entry_method == ACPI_CSTATE_FFH) + state->flags |= CPUIDLE_FLAG_MWAIT; + /* * Halt-induced C1 is not good for ->enter_s2idle, because it * re-enables interrupts on exit. Moreover, C1 is generally not diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c index ac4d8faa3886..d52723fbeb04 100644 --- a/drivers/idle/intel_idle.c +++ b/drivers/idle/intel_idle.c @@ -1787,7 +1787,8 @@ static void __init intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) if (cx->type > ACPI_STATE_C1) state->target_residency *= 3; - state->flags = MWAIT2flg(cx->address); + state->flags = MWAIT2flg(cx->address) | CPUIDLE_FLAG_MWAIT; + if (cx->type > ACPI_STATE_C2) state->flags |= CPUIDLE_FLAG_TLB_FLUSHED; @@ -2072,6 +2073,8 @@ static bool __init intel_idle_verify_cstate(unsigned int mwait_hint) static void state_update_enter_method(struct cpuidle_state *state, int cstate) { + state->flags |= CPUIDLE_FLAG_MWAIT; + if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) { /* * Combining with XSTATE with IBRS or IRQ_ENABLE flags diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index a9ee4fe55dcf..b8084617aa27 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -85,6 +85,7 @@ struct cpuidle_state { #define CPUIDLE_FLAG_OFF BIT(4) /* disable this state by default */ #define CPUIDLE_FLAG_TLB_FLUSHED BIT(5) /* idle-state flushes TLBs */ #define CPUIDLE_FLAG_RCU_IDLE BIT(6) /* idle-state takes care of RCU */ +#define CPUIDLE_FLAG_MWAIT BIT(7) /* hardware need_resched() monitoring */ struct cpuidle_device_kobj; struct cpuidle_state_kobj;