cpuidle: add riscv cpuidle driver
Subsystems (2)
PATCH v2 1/1 cpuidle: add riscv cpuidle driver
This patch adds a simple cpuidle driver for RISC-V systems using the WFI state. Other states will be supported in the future.
---
Changes in v2:
- call "mb()" before run "WFI" in cpu_do_idle
- modify commit description
- place "select CPU_IDLE" in alphabetical order
- replace "__asm__ __volatile__ ("wfi")" with "wait_for_interrupt()"
- delete "cpuidle.c",move "cpu_do_idle()" to cpuidle.h
- modify "arch_cpu_idle", "cpu_do_idle" can be called by "arch_cpu_idle"
- fix space/tab issues
- modify riscv_low_level_suspend_enter to __weak mode
arch/riscv/Kconfig | 7 ++++++ arch/riscv/include/asm/cpuidle.h | 16 ++++++++++++ arch/riscv/kernel/process.c | 3 ++- drivers/cpuidle/Kconfig | 5 ++++ drivers/cpuidle/Kconfig.riscv | 11 ++++++++ drivers/cpuidle/Makefile | 4 +++ drivers/cpuidle/cpuidle-riscv.c | 54 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/include/asm/cpuidle.h create mode 100644 drivers/cpuidle/Kconfig.riscv create mode 100644 drivers/cpuidle/cpuidle-riscv.c
arch/riscv/Kconfig +7 -0
@@ -33,6 +33,7 @@ config RISCV select ARCH_WANT_HUGE_PMD_SHARE if 64BIT select CLONE_BACKWARDS select COMMON_CLK + select CPU_IDLE select EDAC_SUPPORT select GENERIC_ARCH_TOPOLOGY if SMP select GENERIC_ATOMIC64 if !64BIT
@@ -407,6 +408,12 @@ config BUILTIN_DTB depends on RISCV_M_MODE depends on OF +menu "CPU Power Management" + +source "drivers/cpuidle/Kconfig" + +endmenu + menu "Power management options" source "kernel/power/Kconfig"
arch/riscv/include/asm/cpuidle.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __RISCV_CPUIDLE_H +#define __RISCV_CPUIDLE_H + +static inline void cpu_do_idle (void ) +{ +/* +* Add mb() here to ensure that all +* IO/MEM access are completed prior +* to enter WFI. +*/ +mb (); +wait_for_interrupt (); +} + +#endif
arch/riscv/kernel/process.c +2 -1
@@ -21,6 +21,7 @@#include <asm/string.h> #include <asm/switch_to.h> #include <asm/thread_info.h> +#include <asm/cpuidle.h> registerunsigned long gp_in_global __asm__("gp" );
@@ -35,7 +36,7 @@ extern asmlinkage void ret_from_kernel_thread(void);void arch_cpu_idle (void ) { -wait_for_interrupt (); +cpu_do_idle ();local_irq_enable (); }
drivers/cpuidle/Kconfig +5 -0
@@ -62,6 +62,11 @@ depends on PPC source "drivers/cpuidle/Kconfig.powerpc" endmenu +menu "RISCV CPU Idle Drivers" +depends on RISCV +source "drivers/cpuidle/Kconfig.riscv" +endmenu + config HALTPOLL_CPUIDLE tristate "Halt poll cpuidle driver" depends on X86 && KVM_GUEST
drivers/cpuidle/Kconfig.riscv new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# RISCV CPU Idle drivers +# +config RISCV_CPUIDLE + bool "Generic RISCV CPU idle Driver" + select DT_IDLE_STATES + select CPU_IDLE_MULTIPLE_DRIVERS + help + Select this option to enable generic cpuidle driver for RISCV. + Now only support C0 State.
drivers/cpuidle/Makefile +4 -0
@@ -34,3 +34,7 @@ obj-$(CONFIG_MIPS_CPS_CPUIDLE) += cpuidle-cps.o # POWERPC drivers obj-$(CONFIG_PSERIES_CPUIDLE) += cpuidle-pseries.o obj-$(CONFIG_POWERNV_CPUIDLE) += cpuidle-powernv.o + +############################################################################### +# RISCV drivers +obj-$(CONFIG_RISCV_CPUIDLE) += cpuidle-riscv.o
drivers/cpuidle/cpuidle-riscv.c new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.7.4
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi liush,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on pm/linux-next]
[also build test WARNING on linus/master v5.9-rc6 next-20200921] [cannot apply to daniel.lezcano/clockevents/next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/liush/cpuidle-add-riscv-cpuidle-driver/20200921-161139 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next config: riscv-allyesconfig (attached as .config) compiler: riscv64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=riscv
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/cpuidle/cpuidle-riscv.c:22:12: warning: no previous prototype for 'riscv_low_level_suspend_enter' [-Wmissing-prototypes]
22 | int __weak riscv_low_level_suspend_enter(int state)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# https://github.com/0day-ci/linux/commit/30d1da9b67239e99038b0bad282b70454865be02
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review liush/cpuidle-add-riscv-cpuidle-driver/20200921-161139 git checkout 30d1da9b67239e99038b0bad282b70454865be02
vim +/riscv_low_level_suspend_enter +22 drivers/cpuidle/cpuidle-riscv.c
21
> 22 int __weak riscv_low_level_suspend_enter(int state)
23 {
24 return 0;
25 }
26 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org