From 60555e371d56a1e410d9fb6fc68f4e953f8f4109 Mon Sep 17 00:00:00 2001 From: "len.brown@intel.com" Date: Mon, 19 Nov 2007 22:22:37 -0500 Subject: ACPI: CONFIG_CPU_IDLE=ACPI by default In Linux-2.6.24, CPU_IDLE went upstream, default =n. For Linux-2.6.25, enable it by default on ACPI systems. For Linux-2.6.26, we plan to enable it always on ACPI systems. Signed-off-by: Len Brown --- drivers/cpuidle/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/cpuidle/Kconfig b/drivers/cpuidle/Kconfig index 3bed4127d4ad..7dbc4a83c45c 100644 --- a/drivers/cpuidle/Kconfig +++ b/drivers/cpuidle/Kconfig @@ -1,13 +1,13 @@ config CPU_IDLE bool "CPU idle PM support" + default ACPI help CPU idle is a generic framework for supporting software-controlled idle processor power management. It includes modular cross-platform governors that can be swapped during runtime. - If you're using a mobile platform that supports CPU idle PM (e.g. - an ACPI-capable notebook), you should say Y here. + If you're using an ACPI-enabled platform, you should say Y here. config CPU_IDLE_GOV_LADDER bool -- cgit v1.2.3-59-g8ed1b From 4963f62045b64f93c45fbcb6f8f0baf1e3e7a127 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Thu, 13 Dec 2007 23:50:45 -0500 Subject: cpuidle: create processor.latency_factor tunable Start with default value of 6, so by default, there is no functional change in this patch. Signed-off-by: Len Brown --- drivers/acpi/processor_idle.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index f996d0e37689..26ade1f3f5cd 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -94,6 +94,9 @@ module_param(bm_history, uint, 0644); static int acpi_processor_set_power_policy(struct acpi_processor *pr); +#else /* CONFIG_CPU_IDLE */ +static unsigned int latency_factor __read_mostly = 6; +module_param(latency_factor, uint, 0644); #endif /* @@ -1576,7 +1579,7 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i); state->exit_latency = cx->latency; - state->target_residency = cx->latency * 6; + state->target_residency = cx->latency * latency_factor; state->power_usage = cx->power; state->flags = 0; -- cgit v1.2.3-59-g8ed1b From 25de5718356e264820625600a9edca1df5ff26f8 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Fri, 14 Dec 2007 00:24:15 -0500 Subject: cpuidle: default processor.latency_factor=2 More aggressively request deep C-states. Note that the job of the OS is to minimize latency impact to expected break events such as interrupts. It is not the job of the OS to try to calculate if the C-state will reach energy break-even. The platform doesn't give the OS enough information for it to make that calculation. Thus, it is up to the platform to decide if it is worth it to go as deep as the OS requested it to, or if it should internally demote to a more shallow C-state. But the converse is not true. The platform can not promote into a deeper C-state than the OS requested else it may violate latency constraints. So it is important that the OS be aggressive in giving the platform permission to enter deep C-states. Signed-off-by: Len Brown --- drivers/acpi/processor_idle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 26ade1f3f5cd..bc99b7b9094f 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -95,7 +95,7 @@ module_param(bm_history, uint, 0644); static int acpi_processor_set_power_policy(struct acpi_processor *pr); #else /* CONFIG_CPU_IDLE */ -static unsigned int latency_factor __read_mostly = 6; +static unsigned int latency_factor __read_mostly = 2; module_param(latency_factor, uint, 0644); #endif -- cgit v1.2.3-59-g8ed1b From f757397097d0713c949af76dccabb65a2785782e Mon Sep 17 00:00:00 2001 From: Kevin Hilman Date: Thu, 31 Jan 2008 17:28:18 -0800 Subject: cpuidle: build fix for non-x86 Convert cpu_idle_wait() to cpuidle_kick_cpus() macro which is SMP-only, and gives error on non supported CPU. Signed-off-by: Kevin Hilman Acked-by: Venkatesh Pallipadi Acked-by: Rafael J. Wysocki Signed-off-by: Len Brown --- arch/x86/Kconfig | 3 +++ drivers/cpuidle/cpuidle.c | 2 +- include/linux/cpuidle.h | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 368864dfe6eb..37d1297e6787 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -105,6 +105,9 @@ config ARCH_HAS_ILOG2_U32 config ARCH_HAS_ILOG2_U64 def_bool n +config ARCH_HAS_CPU_IDLE_WAIT + def_bool y + config GENERIC_CALIBRATE_DELAY def_bool y diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index d2fabe7863a9..794962d9f48b 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -82,7 +82,7 @@ void cpuidle_uninstall_idle_handler(void) { if (enabled_devices && (pm_idle != pm_idle_old)) { pm_idle = pm_idle_old; - cpu_idle_wait(); + cpuidle_kick_cpus(); } } diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index 16a51546db44..cb95f5a9075a 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -72,6 +72,19 @@ cpuidle_set_statedata(struct cpuidle_state *state, void *data) state->driver_data = data; } +#ifdef CONFIG_SMP +#ifdef CONFIG_ARCH_HAS_CPU_IDLE_WAIT +static inline void cpuidle_kick_cpus(void) +{ + cpu_idle_wait(); +} +#else /* !CONFIG_ARCH_HAS_CPU_IDLE_WAIT */ +#error "Arch needs cpu_idle_wait() equivalent here" +#endif /* !CONFIG_ARCH_HAS_CPU_IDLE_WAIT */ +#else /* !CONFIG_SMP */ +static inline void cpuidle_kick_cpus(void) {} +#endif /* !CONFIG_SMP */ + struct cpuidle_state_kobj { struct cpuidle_state *state; struct completion kobj_unregister; -- cgit v1.2.3-59-g8ed1b From 2e906655baf1c6f6fccd212fc9e6499dc6928b80 Mon Sep 17 00:00:00 2001 From: "venkatesh.pallipadi@intel.com" Date: Thu, 31 Jan 2008 17:35:03 -0800 Subject: ACPI: idle: Fix acpi_safe_halt usages and interrupt enabling/disabling acpi_safe_halt() needs interrupts to be disabled for atomic need_resched check and safe halt. Otherwise we may miss an interrupt and go into halt. acpi_safe_halt() also does not enable interrupts on all return paths. So the callers should handle enable and disable interrupts around it. Signed-off-by: Venkatesh Pallipadi Signed-off-by: Len Brown --- drivers/acpi/processor_idle.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'drivers') diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 199ea2146153..106a22948aa9 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -201,6 +201,10 @@ static inline u32 ticks_elapsed_in_us(u32 t1, u32 t2) return PM_TIMER_TICKS_TO_US((0xFFFFFFFF - t1) + t2); } +/* + * Callers should disable interrupts before the call and enable + * interrupts after return. + */ static void acpi_safe_halt(void) { current_thread_info()->status &= ~TS_POLLING; @@ -413,6 +417,8 @@ static void acpi_processor_idle(void) pm_idle_save(); else acpi_safe_halt(); + + local_irq_enable(); return; } @@ -521,6 +527,7 @@ static void acpi_processor_idle(void) * skew otherwise. */ sleep_ticks = 0xFFFFFFFF; + local_irq_enable(); break; case ACPI_STATE_C2: @@ -1403,11 +1410,13 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev, if (unlikely(!pr)) return 0; + local_irq_disable(); if (pr->flags.bm_check) acpi_idle_update_bm_rld(pr, cx); acpi_safe_halt(); + local_irq_enable(); cx->usage++; return 0; @@ -1517,7 +1526,9 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev, if (dev->safe_state) { return dev->safe_state->enter(dev, dev->safe_state); } else { + local_irq_disable(); acpi_safe_halt(); + local_irq_enable(); return 0; } } -- cgit v1.2.3-59-g8ed1b From bc71bec91f9875ef825d12104acf3bf4ca215fa4 Mon Sep 17 00:00:00 2001 From: "venkatesh.pallipadi@intel.com" Date: Thu, 31 Jan 2008 17:35:04 -0800 Subject: ACPI: enable MWAIT for C1 idle Add MWAIT idle for C1 state instead of halt, on platforms that support C1 state with MWAIT. Renames cx->space_id to something more appropriate. Signed-off-by: Venkatesh Pallipadi Signed-off-by: Len Brown --- drivers/acpi/processor_idle.c | 20 ++++++++++++-------- include/acpi/processor.h | 3 ++- 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 106a22948aa9..4ba3a9a473dd 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -265,7 +265,7 @@ static atomic_t c3_cpu_count; /* Common C-state entry for C2, C3, .. */ static void acpi_cstate_enter(struct acpi_processor_cx *cstate) { - if (cstate->space_id == ACPI_CSTATE_FFH) { + if (cstate->entry_method == ACPI_CSTATE_FFH) { /* Call into architectural FFH based C-state */ acpi_processor_ffh_cstate_enter(cstate); } else { @@ -929,20 +929,20 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) cx.address = reg->address; cx.index = current_count + 1; - cx.space_id = ACPI_CSTATE_SYSTEMIO; + cx.entry_method = ACPI_CSTATE_SYSTEMIO; if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) { if (acpi_processor_ffh_cstate_probe (pr->id, &cx, reg) == 0) { - cx.space_id = ACPI_CSTATE_FFH; - } else if (cx.type != ACPI_STATE_C1) { + cx.entry_method = ACPI_CSTATE_FFH; + } else if (cx.type == ACPI_STATE_C1) { /* * C1 is a special case where FIXED_HARDWARE * can be handled in non-MWAIT way as well. * In that case, save this _CST entry info. - * That is, we retain space_id of SYSTEM_IO for - * halt based C1. * Otherwise, ignore this info and continue. */ + cx.entry_method = ACPI_CSTATE_HALT; + } else { continue; } } @@ -1376,12 +1376,16 @@ static inline void acpi_idle_update_bm_rld(struct acpi_processor *pr, /** * acpi_idle_do_entry - a helper function that does C2 and C3 type entry * @cx: cstate data + * + * Caller disables interrupt before call and enables interrupt after return. */ static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx) { - if (cx->space_id == ACPI_CSTATE_FFH) { + if (cx->entry_method == ACPI_CSTATE_FFH) { /* Call into architectural FFH based C-state */ acpi_processor_ffh_cstate_enter(cx); + } else if (cx->entry_method == ACPI_CSTATE_HALT) { + acpi_safe_halt(); } else { int unused; /* IO port based C-state */ @@ -1414,7 +1418,7 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev, if (pr->flags.bm_check) acpi_idle_update_bm_rld(pr, cx); - acpi_safe_halt(); + acpi_idle_do_entry(cx); local_irq_enable(); cx->usage++; diff --git a/include/acpi/processor.h b/include/acpi/processor.h index 6e253b5b0f3b..f6d7c508917c 100644 --- a/include/acpi/processor.h +++ b/include/acpi/processor.h @@ -34,6 +34,7 @@ #define ACPI_CSTATE_SYSTEMIO (0) #define ACPI_CSTATE_FFH (1) +#define ACPI_CSTATE_HALT (2) /* Power Management */ @@ -64,7 +65,7 @@ struct acpi_processor_cx { u8 valid; u8 type; u32 address; - u8 space_id; + u8 entry_method; u8 index; u32 latency; u32 latency_ticks; -- cgit v1.2.3-59-g8ed1b From 9b12e18cdc1553de62d931e73443c806347cd974 Mon Sep 17 00:00:00 2001 From: "venkatesh.pallipadi@intel.com" Date: Thu, 31 Jan 2008 17:35:05 -0800 Subject: ACPI: cpuidle: Support C1 idle time accounting Show C1 idle time in /sysfs cpuidle interface. C1 idle time may not be entirely accurate in all cases. It includes the time spent in the interrupt handler after wakeup with "hlt" based C1. But, it will be accurate with "mwait" based C1. Signed-off-by: Venkatesh Pallipadi Signed-off-by: Len Brown --- drivers/acpi/processor_idle.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 4ba3a9a473dd..fea71597b40a 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -1407,8 +1407,10 @@ static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx) static int acpi_idle_enter_c1(struct cpuidle_device *dev, struct cpuidle_state *state) { + u32 t1, t2; struct acpi_processor *pr; struct acpi_processor_cx *cx = cpuidle_get_statedata(state); + pr = processors[smp_processor_id()]; if (unlikely(!pr)) @@ -1418,12 +1420,14 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev, if (pr->flags.bm_check) acpi_idle_update_bm_rld(pr, cx); + t1 = inl(acpi_gbl_FADT.xpm_timer_block.address); acpi_idle_do_entry(cx); + t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); local_irq_enable(); cx->usage++; - return 0; + return ticks_elapsed_in_us(t1, t2); } /** @@ -1660,6 +1664,7 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) switch (cx->type) { case ACPI_STATE_C1: state->flags |= CPUIDLE_FLAG_SHALLOW; + state->flags |= CPUIDLE_FLAG_TIME_VALID; state->enter = acpi_idle_enter_c1; dev->safe_state = state; break; -- cgit v1.2.3-59-g8ed1b From 9a0b841586c3c6c846effdbe75885c2ebc0031b0 Mon Sep 17 00:00:00 2001 From: "venkatesh.pallipadi@intel.com" Date: Thu, 31 Jan 2008 17:35:06 -0800 Subject: cpuidle: Add a poll_idle method Add a default poll idle state with 0 latency. Provides an option to users to use poll_idle by using 0 as the latency requirement. Signed-off-by: Venkatesh Pallipadi Signed-off-by: Len Brown --- arch/x86/Kconfig | 3 +++ drivers/acpi/processor_idle.c | 4 +++- drivers/cpuidle/cpuidle.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/cpuidle.h | 13 ++++++++++--- 4 files changed, 57 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index e6728bd61cc1..fd4265007053 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -105,6 +105,9 @@ config GENERIC_TIME_VSYSCALL bool default X86_64 +config ARCH_HAS_CPU_RELAX + def_bool y + config HAVE_SETUP_PER_CPU_AREA def_bool X86_64 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index fea71597b40a..32488e6f76ab 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -1628,7 +1628,7 @@ struct cpuidle_driver acpi_idle_driver = { */ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) { - int i, count = 0; + int i, count = CPUIDLE_DRIVER_STATE_START; struct acpi_processor_cx *cx; struct cpuidle_state *state; struct cpuidle_device *dev = &pr->power.dev; @@ -1687,6 +1687,8 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) } count++; + if (count == CPUIDLE_STATE_MAX) + break; } dev->state_count = count; diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 2a98d99cbd46..2c4b2d47973e 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "cpuidle.h" @@ -180,6 +181,44 @@ void cpuidle_disable_device(struct cpuidle_device *dev) EXPORT_SYMBOL_GPL(cpuidle_disable_device); +#ifdef CONFIG_ARCH_HAS_CPU_RELAX +static int poll_idle(struct cpuidle_device *dev, struct cpuidle_state *st) +{ + ktime_t t1, t2; + s64 diff; + int ret; + + t1 = ktime_get(); + local_irq_enable(); + while (!need_resched()) + cpu_relax(); + + t2 = ktime_get(); + diff = ktime_to_us(ktime_sub(t2, t1)); + if (diff > INT_MAX) + diff = INT_MAX; + + ret = (int) diff; + return ret; +} + +static void poll_idle_init(struct cpuidle_device *dev) +{ + struct cpuidle_state *state = &dev->states[0]; + + cpuidle_set_statedata(state, NULL); + + snprintf(state->name, CPUIDLE_NAME_LEN, "C0 (poll idle)"); + state->exit_latency = 0; + state->target_residency = 0; + state->power_usage = -1; + state->flags = CPUIDLE_FLAG_POLL | CPUIDLE_FLAG_TIME_VALID; + state->enter = poll_idle; +} +#else +static void poll_idle_init(struct cpuidle_device *dev) {} +#endif /* CONFIG_ARCH_HAS_CPU_RELAX */ + /** * cpuidle_register_device - registers a CPU's idle PM feature * @dev: the cpu @@ -198,6 +237,8 @@ int cpuidle_register_device(struct cpuidle_device *dev) mutex_lock(&cpuidle_lock); + poll_idle_init(dev); + per_cpu(cpuidle_devices, dev->cpu) = dev; list_add(&dev->device_list, &cpuidle_detected_devices); if ((ret = cpuidle_add_sysfs(sys_dev))) { diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index b0fd85ab9efb..385d45b616db 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -46,9 +46,10 @@ struct cpuidle_state { /* Idle State Flags */ #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */ #define CPUIDLE_FLAG_CHECK_BM (0x02) /* BM activity will exit state */ -#define CPUIDLE_FLAG_SHALLOW (0x10) /* low latency, minimal savings */ -#define CPUIDLE_FLAG_BALANCED (0x20) /* medium latency, moderate savings */ -#define CPUIDLE_FLAG_DEEP (0x40) /* high latency, large savings */ +#define CPUIDLE_FLAG_POLL (0x10) /* no latency, no savings */ +#define CPUIDLE_FLAG_SHALLOW (0x20) /* low latency, minimal savings */ +#define CPUIDLE_FLAG_BALANCED (0x40) /* medium latency, moderate savings */ +#define CPUIDLE_FLAG_DEEP (0x80) /* high latency, large savings */ #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000) @@ -178,4 +179,10 @@ static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { } #endif +#ifdef CONFIG_ARCH_HAS_CPU_RELAX +#define CPUIDLE_DRIVER_STATE_START 1 +#else +#define CPUIDLE_DRIVER_STATE_START 0 +#endif + #endif /* _LINUX_CPUIDLE_H */ -- cgit v1.2.3-59-g8ed1b