From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755810Ab0GIXh2 (ORCPT ); Fri, 9 Jul 2010 19:37:28 -0400 Received: from smtp.polymtl.ca ([132.207.4.11]:59632 "EHLO smtp.polymtl.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755745Ab0GIXhY (ORCPT ); Fri, 9 Jul 2010 19:37:24 -0400 Message-Id: <20100709225815.636279765@efficios.com> User-Agent: quilt/0.48-1 Date: Fri, 09 Jul 2010 18:57:31 -0400 From: Mathieu Desnoyers To: Steven Rostedt , LKML Cc: Linus Torvalds , Andrew Morton , Peter Zijlstra , Ingo Molnar , Frederic Weisbecker , Thomas Gleixner , Christoph Hellwig , Mathieu Desnoyers , Li Zefan , Lai Jiangshan , Johannes Berg , Masami Hiramatsu , Arnaldo Carvalho de Melo , Tom Zanussi , KOSAKI Motohiro , Andi Kleen Subject: [patch 04/20] idle notifier standardization x86_32 References: <20100709225727.312232266@efficios.com> Content-Disposition: inline; filename=idle-notifier-x86_32.patch X-Poly-FromMTA: (test.casi.polymtl.ca [132.207.72.60]) at Fri, 9 Jul 2010 22:58:16 +0000 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add idle notifier callback to x86_32. Signed-off-by: Mathieu Desnoyers --- arch/x86/include/asm/idle.h | 5 ----- arch/x86/kernel/apm_32.c | 6 ++++++ arch/x86/kernel/process_32.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) Index: linux.trees.git/arch/x86/kernel/process_32.c =================================================================== --- linux.trees.git.orig/arch/x86/kernel/process_32.c 2010-06-19 16:09:48.000000000 -0400 +++ linux.trees.git/arch/x86/kernel/process_32.c 2010-06-19 16:16:53.000000000 -0400 @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include #include @@ -61,6 +63,30 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); +static DEFINE_PER_CPU(unsigned char, is_idle); + +void enter_idle(void) +{ + percpu_write(is_idle, 1); + notify_idle(IDLE_START); +} + +static void __exit_idle(void) +{ + if (x86_test_and_clear_bit_percpu(0, is_idle) == 0) + return; + notify_idle(IDLE_END); +} + +/* Called from interrupts to signify idle end */ +void exit_idle(void) +{ + /* idle loop has pid 0 */ + if (current->pid) + return; + __exit_idle(); +} + /* * Return saved PC of a blocked thread. */ @@ -109,10 +135,17 @@ void cpu_idle(void) play_dead(); local_irq_disable(); + enter_idle(); /* Don't trace irqs off for idle */ stop_critical_timings(); pm_idle(); start_critical_timings(); + /* + * In many cases the interrupt that ended idle + * has already called exit_idle. But some idle loops can + * be woken up without interrupt. + */ + __exit_idle(); trace_power_end(smp_processor_id()); } Index: linux.trees.git/arch/x86/include/asm/idle.h =================================================================== --- linux.trees.git.orig/arch/x86/include/asm/idle.h 2010-06-19 16:15:29.000000000 -0400 +++ linux.trees.git/arch/x86/include/asm/idle.h 2010-06-19 16:15:34.000000000 -0400 @@ -1,13 +1,8 @@ #ifndef _ASM_X86_IDLE_H #define _ASM_X86_IDLE_H -#ifdef CONFIG_X86_64 void enter_idle(void); void exit_idle(void); -#else /* !CONFIG_X86_64 */ -static inline void enter_idle(void) { } -static inline void exit_idle(void) { } -#endif /* CONFIG_X86_64 */ void c1e_remove_cpu(int cpu); Index: linux.trees.git/arch/x86/kernel/apm_32.c =================================================================== --- linux.trees.git.orig/arch/x86/kernel/apm_32.c 2010-06-19 16:08:32.000000000 -0400 +++ linux.trees.git/arch/x86/kernel/apm_32.c 2010-06-19 16:15:34.000000000 -0400 @@ -227,6 +227,7 @@ #include #include #include +#include #include #include @@ -947,10 +948,15 @@ recalc: break; } } + enter_idle(); if (original_pm_idle) original_pm_idle(); else default_idle(); + /* In many cases the interrupt that ended idle + has already called exit_idle. But some idle + loops can be woken up without interrupt. */ + __exit_idle(); local_irq_disable(); jiffies_since_last_check = jiffies - last_jiffies; if (jiffies_since_last_check > idle_period)