From patchwork Tue Sep 22 11:33:44 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Bharadwaj X-Patchwork-Id: 34069 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 94160B7CA7 for ; Tue, 22 Sep 2009 21:34:00 +1000 (EST) Received: from e28smtp03.in.ibm.com (e28smtp03.in.ibm.com [59.145.155.3]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "e28smtp03.in.ibm.com", Issuer "Equifax" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id ACDC4B7BD8 for ; Tue, 22 Sep 2009 21:33:51 +1000 (EST) Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by e28smtp03.in.ibm.com (8.14.3/8.13.1) with ESMTP id n8MBXlbY029064 for ; Tue, 22 Sep 2009 17:03:47 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id n8MBXlVC1896692 for ; Tue, 22 Sep 2009 17:03:47 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id n8MBXkYJ030616 for ; Tue, 22 Sep 2009 17:03:47 +0530 Received: from linux.vnet.ibm.com (Crystal-Planet.in.ibm.com [9.124.35.26]) by d28av01.in.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id n8MBXiLB030569 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 22 Sep 2009 17:03:45 +0530 Date: Tue, 22 Sep 2009 17:03:44 +0530 From: Arun R Bharadwaj To: Peter Zijlstra , Joel Schopp , Benjamin Herrenschmidt , Paul Mackerras , Ingo Molnar , Vaidyanathan Srinivasan , Dipankar Sarma , Balbir Singh , Gautham R Shenoy , Shaohua Li , Venkatesh Pallipadi , Arun Bharadwaj Subject: [v6 PATCH 7/7]: pSeries: implement pSeries processor idle module. Message-ID: <20090922113344.GH7788@linux.vnet.ibm.com> References: <20090922112526.GA7788@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20090922112526.GA7788@linux.vnet.ibm.com> User-Agent: Mutt/1.5.18 (2008-05-17) Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: arun@linux.vnet.ibm.com List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org * Arun R Bharadwaj [2009-09-22 16:55:27]: This patch creates arch/powerpc/platforms/pseries/processor_idle.c, which implements the cpuidle infrastructure for pseries. It implements a pseries_cpuidle_loop() which would be the main idle loop called from cpu_idle(). It makes decision of entering either cede1 or cede2 for dedicated lpar and shared_cede for shared lpar processor based on the decision taken by the cpuidle governor. Signed-off-by: Arun R Bharadwaj --- arch/powerpc/platforms/pseries/Makefile | 1 arch/powerpc/platforms/pseries/processor_idle.c | 191 ++++++++++++++++++++++++ arch/powerpc/platforms/pseries/pseries.h | 9 + arch/powerpc/platforms/pseries/setup.c | 8 - 4 files changed, 207 insertions(+), 2 deletions(-) Index: linux.trees.git/arch/powerpc/platforms/pseries/Makefile =================================================================== --- linux.trees.git.orig/arch/powerpc/platforms/pseries/Makefile +++ linux.trees.git/arch/powerpc/platforms/pseries/Makefile @@ -26,3 +26,4 @@ obj-$(CONFIG_HCALL_STATS) += hvCall_inst obj-$(CONFIG_PHYP_DUMP) += phyp_dump.o obj-$(CONFIG_CMM) += cmm.o obj-$(CONFIG_DTL) += dtl.o +obj-$(CONFIG_PSERIES_PROCESSOR_IDLE) += processor_idle.o Index: linux.trees.git/arch/powerpc/platforms/pseries/pseries.h =================================================================== --- linux.trees.git.orig/arch/powerpc/platforms/pseries/pseries.h +++ linux.trees.git/arch/powerpc/platforms/pseries/pseries.h @@ -10,6 +10,8 @@ #ifndef _PSERIES_PSERIES_H #define _PSERIES_PSERIES_H +#include + extern void __init fw_feature_init(const char *hypertas, unsigned long len); struct pt_regs; @@ -40,4 +42,11 @@ extern unsigned long rtas_poweron_auto; extern void find_udbg_vterm(void); +DECLARE_PER_CPU(unsigned long, smt_snooze_delay); + +#ifdef CONFIG_PSERIES_PROCESSOR_IDLE +int pseries_processor_idle_init(void); +extern struct cpuidle_driver pseries_idle_driver; +#endif + #endif /* _PSERIES_PSERIES_H */ Index: linux.trees.git/arch/powerpc/platforms/pseries/processor_idle.c =================================================================== --- /dev/null +++ linux.trees.git/arch/powerpc/platforms/pseries/processor_idle.c @@ -0,0 +1,191 @@ +/* + * processor_idle - idle state cpuidle driver. + * Adapted from drivers/acpi/processor_idle.c + * + * Arun R Bharadwaj + * + * Copyright (C) 2009 IBM Corporation. + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "plpar_wrappers.h" +#include "pseries.h" + +MODULE_AUTHOR("Arun R Bharadwaj"); +MODULE_DESCRIPTION("pSeries Idle State Driver"); +MODULE_LICENSE("GPL"); + +struct cpuidle_driver pseries_idle_driver = { + .name = "pseries_idle", + .owner = THIS_MODULE, +}; + +DEFINE_PER_CPU(struct cpuidle_device, pseries_dev); + +#define IDLE_STATE_COUNT 2 + +static int pseries_idle_init(struct cpuidle_device *dev) +{ + return cpuidle_register_device(dev); +} + +static void shared_cede(void) +{ + get_lppaca()->idle = 1; + cede_processor(); + get_lppaca()->idle = 0; +} + +static void cede1(void) +{ + local_irq_enable(); + set_thread_flag(TIF_POLLING_NRFLAG); + while (!need_resched()) { + ppc64_runlatch_off(); + HMT_low(); + HMT_very_low(); + } + HMT_medium(); + clear_thread_flag(TIF_POLLING_NRFLAG); + smp_mb(); + local_irq_disable(); +} + +static void cede2(void) +{ + ppc64_runlatch_off(); + HMT_medium(); + cede_processor(); +} + +static int pseries_cpuidle_loop(struct cpuidle_device *dev, + struct cpuidle_state *st) +{ + ktime_t t1, t2; + s64 diff; + int ret; + unsigned long in_purr, out_purr; + + get_lppaca()->idle = 1; + get_lppaca()->donate_dedicated_cpu = 1; + in_purr = mfspr(SPRN_PURR); + + t1 = ktime_get(); + + if (strcmp(st->desc, "shared_cede") == 0) + shared_cede(); + else if (strcmp(st->desc, "cede1") == 0) + cede1(); + else + cede2(); + + t2 = ktime_get(); + diff = ktime_to_us(ktime_sub(t2, t1)); + if (diff > INT_MAX) + diff = INT_MAX; + + ret = (int) diff; + + out_purr = mfspr(SPRN_PURR); + get_lppaca()->wait_state_cycles += out_purr - in_purr; + get_lppaca()->donate_dedicated_cpu = 0; + get_lppaca()->idle = 0; + + return ret; +} + +static int pseries_setup_cpuidle(struct cpuidle_device *dev, int cpu) +{ + int i; + struct cpuidle_state *state; + + dev->cpu = cpu; + + if (get_lppaca()->shared_proc) { + state = &dev->states[0]; + snprintf(state->name, CPUIDLE_NAME_LEN, "IDLE"); + state->enter = pseries_cpuidle_loop; + strncpy(state->desc, "shared_cede", CPUIDLE_DESC_LEN); + state->exit_latency = 0; + state->target_residency = 0; + return 0; + } + + for (i = 0; i < IDLE_STATE_COUNT; i++) { + state = &dev->states[i]; + + snprintf(state->name, CPUIDLE_NAME_LEN, "IDLE%d", i); + state->enter = pseries_cpuidle_loop; + + switch (i) { + case 0: + strncpy(state->desc, "cede1", CPUIDLE_DESC_LEN); + state->exit_latency = 0; + state->target_residency = 0; + break; + + case 1: + strncpy(state->desc, "cede2", CPUIDLE_DESC_LEN); + state->exit_latency = 1; + state->target_residency = + __get_cpu_var(smt_snooze_delay); + break; + } + } + dev->state_count = IDLE_STATE_COUNT; + + return 0; +} + +int __init pseries_processor_idle_init(void) +{ + int cpu; + int result = cpuidle_register_driver(&pseries_idle_driver); + + if (result < 0) + return result; + + printk(KERN_DEBUG "pSeries idle driver registered\n"); + + if (!firmware_has_feature(FW_FEATURE_SPLPAR)) { + printk(KERN_DEBUG "Using default idle\n"); + return 0; + } + + for_each_online_cpu(cpu) { + pseries_setup_cpuidle(&per_cpu(pseries_dev, cpu), cpu); + pseries_idle_init(&per_cpu(pseries_dev, cpu)); + } + + printk(KERN_DEBUG "Using cpuidle idle loop\n"); + + return 0; +} Index: linux.trees.git/arch/powerpc/platforms/pseries/setup.c =================================================================== --- linux.trees.git.orig/arch/powerpc/platforms/pseries/setup.c +++ linux.trees.git/arch/powerpc/platforms/pseries/setup.c @@ -297,9 +297,13 @@ static void __init pSeries_setup_arch(vo pSeries_nvram_init(); - /* Choose an idle loop */ - if (firmware_has_feature(FW_FEATURE_SPLPAR)) + /* Register an idle loop with cpuidle */ + if (firmware_has_feature(FW_FEATURE_SPLPAR)) { vpa_init(boot_cpuid); +#ifdef CONFIG_PSERIES_PROCESSOR_IDLE + pseries_processor_idle_init(); +#endif + } if (firmware_has_feature(FW_FEATURE_LPAR)) ppc_md.enable_pmcs = pseries_lpar_enable_pmcs;