linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Sudeep Holla <sudeep.holla@arm.com>
Cc: linux-acpi@vger.kernel.org,
	Vikas Sajjan <vikas.cha.sajjan@hpe.com>, Sunil <sunil.vl@hpe.com>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	PrashanthPrakash <pprakash@codeaurora.org>,
	Al Stone <al.stone@linaro.org>,
	Ashwin Chaugule <ashwin.chaugule@linaro.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v7 4/6] cpuidle: introduce HAVE_GENERIC_CPUIDLE_ENTER for ARM{32,64} platforms
Date: Thu, 07 Jul 2016 15:21:13 +0200	[thread overview]
Message-ID: <1675585.udvKUofiJK@vostro.rjw.lan> (raw)
In-Reply-To: <1467122152-5604-5-git-send-email-sudeep.holla@arm.com>

On Tuesday, June 28, 2016 02:55:50 PM Sudeep Holla wrote:
> The function arm_enter_idle_state is exactly the same in both generic
> ARM{32,64} CPUIdle driver and will be the same even on ARM64 backend
> for ACPI processor idle driver. So we can unify it and move it as
> generic_cpuidle_enter by introducing HAVE_GENERIC_CPUIDLE_ENTER and
> enabling the same on both ARM{32,64}.
> 
> This is in preparation of reuse of the generic cpuidle entry function
> for ACPI LPI support on ARM64.
> 
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>  arch/arm/Kconfig              |  1 +
>  arch/arm/kernel/cpuidle.c     |  4 ++--
>  arch/arm64/Kconfig            |  1 +
>  arch/arm64/kernel/cpuidle.c   |  6 +++---
>  drivers/cpuidle/Kconfig       |  3 +++
>  drivers/cpuidle/cpuidle-arm.c | 21 +--------------------
>  drivers/cpuidle/cpuidle.c     | 35 +++++++++++++++++++++++++++++++++++
>  include/linux/cpuidle.h       |  8 ++++++++
>  8 files changed, 54 insertions(+), 25 deletions(-)
> 
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index 90542db1220d..52b3dca0381c 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -54,6 +54,7 @@ config ARM
>  	select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL)
>  	select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL)
>  	select HAVE_FUNCTION_TRACER if (!XIP_KERNEL)
> +	select HAVE_GENERIC_CPUIDLE_ENTER

That "generic" part in the name concerns me a bit, because the thing is not
really generic.  It is "common on ARM" rather.

>  	select HAVE_GENERIC_DMA_COHERENT
>  	select HAVE_HW_BREAKPOINT if (PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7))
>  	select HAVE_IDE if PCI || ISA || PCMCIA
> diff --git a/arch/arm/kernel/cpuidle.c b/arch/arm/kernel/cpuidle.c
> index a44b268e12e1..49704e333bfc 100644
> --- a/arch/arm/kernel/cpuidle.c
> +++ b/arch/arm/kernel/cpuidle.c
> @@ -41,7 +41,7 @@ int arm_cpuidle_simple_enter(struct cpuidle_device *dev,
>  }
>  
>  /**
> - * arm_cpuidle_suspend() - function to enter low power idle states
> + * cpuidle_generic_enter() - function to enter low power idle states
>   * @index: an integer used as an identifier for the low level PM callbacks
>   *
>   * This function calls the underlying arch specific low level PM code as
> @@ -50,7 +50,7 @@ int arm_cpuidle_simple_enter(struct cpuidle_device *dev,
>   * Returns -EOPNOTSUPP if no suspend callback is defined, the result of the
>   * callback otherwise.
>   */
> -int arm_cpuidle_suspend(int index)
> +int cpuidle_generic_enter(int index)
>  {
>  	int ret = -EOPNOTSUPP;
>  	int cpu = smp_processor_id();
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 5a0a691d4220..0916b6e6c8ef 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -76,6 +76,7 @@ config ARM64
>  	select HAVE_FTRACE_MCOUNT_RECORD
>  	select HAVE_FUNCTION_TRACER
>  	select HAVE_FUNCTION_GRAPH_TRACER
> +	select HAVE_GENERIC_CPUIDLE_ENTER
>  	select HAVE_GENERIC_DMA_COHERENT
>  	select HAVE_HW_BREAKPOINT if PERF_EVENTS
>  	select HAVE_IRQ_TIME_ACCOUNTING
> diff --git a/arch/arm64/kernel/cpuidle.c b/arch/arm64/kernel/cpuidle.c
> index 06786fdaadeb..bade1b04ff12 100644
> --- a/arch/arm64/kernel/cpuidle.c
> +++ b/arch/arm64/kernel/cpuidle.c
> @@ -9,10 +9,10 @@
>   * published by the Free Software Foundation.
>   */
>  
> +#include <linux/cpuidle.h>
>  #include <linux/of.h>
>  #include <linux/of_device.h>
>  
> -#include <asm/cpuidle.h>
>  #include <asm/cpu_ops.h>
>  
>  int arm_cpuidle_init(unsigned int cpu)
> @@ -27,13 +27,13 @@ int arm_cpuidle_init(unsigned int cpu)
>  }
>  
>  /**
> - * cpu_suspend() - function to enter a low-power idle state
> + * cpuidle_generic_enter() - function to enter a low-power idle state
>   * @arg: argument to pass to CPU suspend operations
>   *
>   * Return: 0 on success, -EOPNOTSUPP if CPU suspend hook not initialized, CPU
>   * operations back-end error code otherwise.
>   */
> -int arm_cpuidle_suspend(int index)
> +int cpuidle_generic_enter(int index)
>  {
>  	int cpu = smp_processor_id();
>  
> diff --git a/drivers/cpuidle/Kconfig b/drivers/cpuidle/Kconfig
> index 7e48eb5bf0a7..e557289cff90 100644
> --- a/drivers/cpuidle/Kconfig
> +++ b/drivers/cpuidle/Kconfig
> @@ -45,4 +45,7 @@ endif
>  
>  config ARCH_NEEDS_CPU_IDLE_COUPLED
>  	def_bool n
> +
> +config HAVE_GENERIC_CPUIDLE_ENTER
> +	def_bool n
>  endmenu
> diff --git a/drivers/cpuidle/cpuidle-arm.c b/drivers/cpuidle/cpuidle-arm.c
> index e342565e8715..13012d8eba53 100644
> --- a/drivers/cpuidle/cpuidle-arm.c
> +++ b/drivers/cpuidle/cpuidle-arm.c
> @@ -36,26 +36,7 @@
>  static int arm_enter_idle_state(struct cpuidle_device *dev,
>  				struct cpuidle_driver *drv, int idx)
>  {
> -	int ret;
> -
> -	if (!idx) {
> -		cpu_do_idle();
> -		return idx;
> -	}
> -
> -	ret = cpu_pm_enter();
> -	if (!ret) {
> -		/*
> -		 * Pass idle state index to cpu_suspend which in turn will
> -		 * call the CPU ops suspend protocol with idle index as a
> -		 * parameter.
> -		 */
> -		ret = arm_cpuidle_suspend(idx);
> -
> -		cpu_pm_exit();
> -	}
> -
> -	return ret ? -1 : idx;
> +	return cpuidle_generic_enter_state(idx);
>  }
>  
>  static struct cpuidle_driver arm_idle_driver = {
> diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
> index a4d0059e232c..e490dea98b89 100644
> --- a/drivers/cpuidle/cpuidle.c
> +++ b/drivers/cpuidle/cpuidle.c
> @@ -16,6 +16,7 @@
>  #include <linux/pm_qos.h>
>  #include <linux/cpu.h>
>  #include <linux/cpuidle.h>
> +#include <linux/cpu_pm.h>
>  #include <linux/ktime.h>
>  #include <linux/hrtimer.h>
>  #include <linux/module.h>
> @@ -255,6 +256,40 @@ int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
>  }
>  
>  /**
> + * cpuidle_generic_enter_state - enter into the specified idle state using the
> + *				 generic callback if implemented
> + *
> + * @index: the index in the idle state table
> + *
> + * Returns the index in the idle state, -1 in case of error.
> + */
> +int cpuidle_generic_enter_state(int idx)
> +{
> +	int ret;
> +
> +	if (!idx) {
> +		cpu_do_idle();
> +		return idx;
> +	}
> +
> +	ret = cpu_pm_enter();

If you look at the users of cpu_pm_enter(), they are all ARM.  Nobody else uses
it, so at least please put cpuidle_generic_enter_state() under a #ifdef to avoid
building it in vain on non-ARM.

> +	if (!ret) {
> +		/*
> +		 * Pass idle state index to cpu_suspend which in turn will
> +		 * call the CPU ops suspend protocol with idle index as a
> +		 * parameter.
> +		 */
> +		ret = cpuidle_generic_enter(idx);
> +
> +		cpu_pm_exit();
> +	}
> +
> +	return ret ? -1 : idx;
> +}
> +
> +EXPORT_SYMBOL_GPL(cpuidle_generic_enter_state);
> +
> +/**
>   * cpuidle_enter - enter into the specified idle state
>   *
>   * @drv:   the cpuidle driver tied with the cpu
> diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
> index 07b83d32f66c..9fd3c10166fa 100644
> --- a/include/linux/cpuidle.h
> +++ b/include/linux/cpuidle.h
> @@ -154,6 +154,7 @@ extern int cpuidle_play_dead(void);
>  extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev);
>  static inline struct cpuidle_device *cpuidle_get_device(void)
>  {return __this_cpu_read(cpuidle_devices); }
> +extern int cpuidle_generic_enter_state(int idx);
>  #else
>  static inline void disable_cpuidle(void) { }
>  static inline bool cpuidle_not_available(struct cpuidle_driver *drv,
> @@ -190,6 +191,7 @@ static inline int cpuidle_play_dead(void) {return -ENODEV; }
>  static inline struct cpuidle_driver *cpuidle_get_cpu_driver(
>  	struct cpuidle_device *dev) {return NULL; }
>  static inline struct cpuidle_device *cpuidle_get_device(void) {return NULL; }
> +static inline int cpuidle_generic_enter_state(int idx) { return -1; }
>  #endif
>  
>  #if defined(CONFIG_CPU_IDLE) && defined(CONFIG_SUSPEND)
> @@ -246,6 +248,12 @@ static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
>  {return 0;}
>  #endif
>  
> +#ifdef CONFIG_HAVE_GENERIC_CPUIDLE_ENTER
> +extern int cpuidle_generic_enter(int idx);

And if you put it under the #ifdef here, its definition also should go under
the same #ifdef.

> +#else
> +static inline int cpuidle_generic_enter(int idx) { return -1; }
> +#endif
> +
>  #ifdef CONFIG_ARCH_HAS_CPU_RELAX
>  #define CPUIDLE_DRIVER_STATE_START	1
>  #else
> 

Thanks,
Rafael

  reply	other threads:[~2016-07-07 13:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-28 13:55 [PATCH v7 0/6] ACPI / processor_idle: Add ACPI v6.0 LPI support Sudeep Holla
2016-06-28 13:55 ` [PATCH v7 1/6] ACPI / processor_idle: introduce ACPI_PROCESSOR_CSTATE Sudeep Holla
2016-06-28 13:55 ` [PATCH v7 2/6] ACPI / processor_idle: Add support for Low Power Idle(LPI) states Sudeep Holla
2016-07-01 13:07   ` Daniel Lezcano
2016-07-04 13:00     ` Sudeep Holla
2016-07-04 13:17       ` Rafael J. Wysocki
2016-07-04 13:42         ` Sudeep Holla
2016-07-04 14:11           ` Rafael J. Wysocki
2016-06-28 13:55 ` [PATCH v7 3/6] arm64: cpuidle: drop __init section marker to arm_cpuidle_init Sudeep Holla
2016-06-28 13:55 ` [PATCH v7 4/6] cpuidle: introduce HAVE_GENERIC_CPUIDLE_ENTER for ARM{32,64} platforms Sudeep Holla
2016-07-07 13:21   ` Rafael J. Wysocki [this message]
2016-07-07 13:34     ` Sudeep Holla
2016-07-07 14:49       ` Rafael J. Wysocki
2016-07-07 15:48         ` Sudeep Holla
2016-06-28 13:55 ` [PATCH v7 5/6] arm64: add support for ACPI Low Power Idle(LPI) Sudeep Holla
2016-06-28 13:55 ` [PATCH v7 6/6] ACPI : enable ACPI_PROCESSOR_IDLE on ARM64 Sudeep Holla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1675585.udvKUofiJK@vostro.rjw.lan \
    --to=rjw@rjwysocki.net \
    --cc=al.stone@linaro.org \
    --cc=ashwin.chaugule@linaro.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=pprakash@codeaurora.org \
    --cc=sudeep.holla@arm.com \
    --cc=sunil.vl@hpe.com \
    --cc=vikas.cha.sajjan@hpe.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).