From patchwork Fri Mar 30 10:48:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 7531 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 1E9F823E0C for ; Fri, 30 Mar 2012 10:48:23 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id B39E1A180AE for ; Fri, 30 Mar 2012 10:48:22 +0000 (UTC) Received: by iage36 with SMTP id e36so1139719iag.11 for ; Fri, 30 Mar 2012 03:48:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :mime-version:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=/EsNosts9uP1yAqaEJauLSj0x8/olrp0DTfNsABAtUg=; b=YuBi18y79h9zfS9sKcQr2VkL16FSvvTAEdL49L53BNoh1fYNHxUn9DQDmXTTf+oDzN ZlNI3dDYZrLZ69khA0pYLr8H+7yMqlpQJvwnye4TWhsnUg773FSoQUX+BtkboURzNnFj FcK2Al43VJfCUM01fQ5LtbnR4iaetgdCZsEkWZbKqo39PbhsOVU0UluwmS4m+0NFytXe WJ5mMQ7aquGi1OR74o1rnozyuQKpUKOox+QWerEsIUYd5WdMOXRNeQszr2cPE3TFMjXB dz5jfj3S+5OQJzrMgQHQKXm9XFCRHUB+McinizjhSNJjqzXDLmGfrGXLicnqOY/WxmDT YCCw== Received: by 10.50.186.161 with SMTP id fl1mr966664igc.44.1333104502043; Fri, 30 Mar 2012 03:48:22 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.5.205 with SMTP id 13csp15972ibw; Fri, 30 Mar 2012 03:48:21 -0700 (PDT) Received: by 10.14.96.6 with SMTP id q6mr393913eef.64.1333104500304; Fri, 30 Mar 2012 03:48:20 -0700 (PDT) Received: from mail-wg0-f50.google.com (mail-wg0-f50.google.com [74.125.82.50]) by mx.google.com with ESMTPS id x8si9534850weq.7.2012.03.30.03.48.19 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 30 Mar 2012 03:48:20 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.50 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=74.125.82.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.50 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: by wgbds12 with SMTP id ds12so410047wgb.31 for ; Fri, 30 Mar 2012 03:48:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.180.107.162 with SMTP id hd2mr5256123wib.8.1333104499617; Fri, 30 Mar 2012 03:48:19 -0700 (PDT) Received: from localhost.localdomain (AToulouse-159-1-7-136.w90-60.abo.wanadoo.fr. [90.60.242.136]) by mx.google.com with ESMTPS id fz9sm5386873wib.3.2012.03.30.03.48.18 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 30 Mar 2012 03:48:18 -0700 (PDT) From: Daniel Lezcano To: lenb@kernel.org Cc: linux-pm@lists.linux-foundation.org, daniel.lezcano@linaro.org, patches@linaro.org, linaro-dev@lists.linaro.org Subject: [PATCH] cpuidle : use percpu cpuidle in the core code Date: Fri, 30 Mar 2012 12:48:19 +0200 Message-Id: <1333104499-8627-1-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.5.4 X-Gm-Message-State: ALoCoQluKA2PzPMswNUhUOc5snJoNjWo5WMGWZtqKF8IJickcKoXdiBEWhAMk0ChzKVtVEuB68DX The usual cpuidle initialization routines are to register the driver, then register a cpuidle device per cpu. With the device's state count default initialization with the driver's state count, the code initialization remains mostly the same in the different drivers. We can then add a new function 'cpuidle_register' where we register the driver and the devices. These devices can be defined in a global static variable in cpuidle.c. We will be able to factor out and remove a lot of duplicate lines of code. As we still have some drivers, with different initialization routines, we keep 'cpuidle_register_driver' and 'cpuidle_register_device' as low level initialization routines to do some specific operations on the cpuidle devices. Signed-off-by: Daniel Lezcano --- drivers/cpuidle/cpuidle.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/cpuidle.h | 3 +++ 2 files changed, 37 insertions(+), 0 deletions(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index b8a1faf..2a174e8 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -23,6 +23,7 @@ #include "cpuidle.h" DEFINE_PER_CPU(struct cpuidle_device *, cpuidle_devices); +DEFINE_PER_CPU(struct cpuidle_device, cpuidle_device); DEFINE_MUTEX(cpuidle_lock); LIST_HEAD(cpuidle_detected_devices); @@ -391,6 +392,39 @@ int cpuidle_register_device(struct cpuidle_device *dev) EXPORT_SYMBOL_GPL(cpuidle_register_device); +int cpuidle_register(struct cpuidle_driver *drv) +{ + int ret, cpu; + struct cpuidle_device *dev; + + ret = cpuidle_register_driver(drv); + if (ret) + return ret; + + for_each_online_cpu(cpu) { + dev = &per_cpu(cpuidle_device, cpu); + dev->cpu = cpu; + + ret = cpuidle_register_device(dev); + if (ret) + goto out_unregister; + } + +out: + return ret; + +out_unregister: + for_each_online_cpu(cpu) { + dev = &per_cpu(cpuidle_device, cpu); + cpuidle_unregister_device(dev); + } + + cpuidle_unregister_driver(drv); + + goto out; +} +EXPORT_SYMBOL_GPL(cpuidle_register); + /** * cpuidle_unregister_device - unregisters a CPU's idle PM feature * @dev: the cpu diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index f3ebbba..17e3d33 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -133,6 +133,7 @@ struct cpuidle_driver { #ifdef CONFIG_CPU_IDLE extern void disable_cpuidle(void); extern int cpuidle_idle_call(void); +extern int cpuidle_register(struct cpuidle_driver *drv); extern int cpuidle_register_driver(struct cpuidle_driver *drv); struct cpuidle_driver *cpuidle_get_driver(void); extern void cpuidle_unregister_driver(struct cpuidle_driver *drv); @@ -150,6 +151,8 @@ extern int cpuidle_wrap_enter(struct cpuidle_device *dev, #else static inline void disable_cpuidle(void) { } static inline int cpuidle_idle_call(void) { return -ENODEV; } +static inline int cpuidle_register(struct cpuidle_driver *drv) +{return -ENODEV; } static inline int cpuidle_register_driver(struct cpuidle_driver *drv) {return -ENODEV; } static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }