From patchwork Wed Mar 27 10:22:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 15690 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 6748723E66 for ; Wed, 27 Mar 2013 10:22:22 +0000 (UTC) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by fiordland.canonical.com (Postfix) with ESMTP id 06400A18172 for ; Wed, 27 Mar 2013 10:22:21 +0000 (UTC) Received: by mail-ve0-f176.google.com with SMTP id ox1so2031401veb.7 for ; Wed, 27 Mar 2013 03:22:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=Y57mXy5QDLqRVBTCGwzsx699veuS15pBxS7X6AlTKAc=; b=N1i5g3nfVip1+MLne2jKsu8p9ixGmCCUzCH8Hqe8ihNeZdqikUR14pVfTQhuuPodLP 9YSHcvsJQKDeaycvSt6QEdVjVLcljpTO9k9ETClonTwXQJkMbBDGcF0g1LFPR7g/eKrm H7L8Tm7MFea7zi18EVCZp+L1xfVINK/kIkmhdxGELSeVqmtdC/mnV5xyC71xa2GgmVlf 3cCmXfxV9hpcRpwlP19DyIk1o/o+pOI5KPY52wTjpElB8iK9bNC7O9CCDk7G4Cc/JkjK sV9FBnGC2GbagvDbGRzK3H+03KOvocHM3OQYI8RJhP8Rqulpc3J/r3YHogLgP+MNXeT5 QokA== X-Received: by 10.58.253.33 with SMTP id zx1mr8833827vec.35.1364379741557; Wed, 27 Mar 2013 03:22:21 -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.59.4.204 with SMTP id cg12csp109285ved; Wed, 27 Mar 2013 03:22:20 -0700 (PDT) X-Received: by 10.194.235.196 with SMTP id uo4mr30183159wjc.30.1364379740573; Wed, 27 Mar 2013 03:22:20 -0700 (PDT) Received: from mail-we0-x231.google.com ([2a00:1450:400c:c03::231]) by mx.google.com with ESMTPS id un4si8036153wjc.76.2013.03.27.03.22.20 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 27 Mar 2013 03:22:20 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c03::231 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=2a00:1450:400c:c03::231; Authentication-Results: mx.google.com; spf=neutral (google.com: 2a00:1450:400c:c03::231 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: by mail-we0-f177.google.com with SMTP id o45so2321656wer.22 for ; Wed, 27 Mar 2013 03:22:20 -0700 (PDT) X-Received: by 10.180.79.227 with SMTP id m3mr8605653wix.12.1364379740106; Wed, 27 Mar 2013 03:22:20 -0700 (PDT) Received: from mai.home (AToulouse-654-1-426-131.w2-6.abo.wanadoo.fr. [2.6.209.131]) by mx.google.com with ESMTPS id dp5sm7754760wib.1.2013.03.27.03.22.17 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 27 Mar 2013 03:22:18 -0700 (PDT) From: Daniel Lezcano To: rjw@sisk.pl Cc: tglx@linutronix.de, linus.walleij@linaro.org, kernel@pengutronix.de, santosh.shilimkar@ti.com, linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, patches@linaro.org Subject: [PATCH 2/5] cpuidle: initialize the broadcast timer framework Date: Wed, 27 Mar 2013 11:22:10 +0100 Message-Id: <1364379733-23725-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1364379733-23725-1-git-send-email-daniel.lezcano@linaro.org> References: <1364379733-23725-1-git-send-email-daniel.lezcano@linaro.org> X-Gm-Message-State: ALoCoQkHr3hhpvzv5VyshjMoHw2gyt6DTuYtttoLkV86FjBlly9OT0c1KxzaEItT89Hfr8ZYT7rt The commit 89878baa73f0f1c679355006bd8632e5d78f96c2 introduced the CPUIDLE_FLAG_TIMER_STOP flag where we specify a specific idle state stops the local timer. Now use this flag to check at init time if one state will need the broadcast timer and, in this case, setup the broadcast timer framework. That prevents multiple code duplication in the drivers. Signed-off-by: Daniel Lezcano --- drivers/cpuidle/driver.c | 31 +++++++++++++++++++++++++++++-- include/linux/cpuidle.h | 2 ++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c index 422c7b6..8dfaaae 100644 --- a/drivers/cpuidle/driver.c +++ b/drivers/cpuidle/driver.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include "cpuidle.h" @@ -19,9 +21,28 @@ DEFINE_SPINLOCK(cpuidle_driver_lock); static void __cpuidle_set_cpu_driver(struct cpuidle_driver *drv, int cpu); static struct cpuidle_driver * __cpuidle_get_cpu_driver(int cpu); -static void __cpuidle_driver_init(struct cpuidle_driver *drv) +static void cpuidle_setup_broadcast_timer(void *arg) { + int cpu = smp_processor_id(); + clockevents_notify((long)(arg), &cpu); +} + +static void __cpuidle_driver_init(struct cpuidle_driver *drv, int cpu) +{ + int i; + drv->refcnt = 0; + + for (i = drv->state_count - 1; i >= 0 ; i--) { + + if (!(drv->states[i].flags & CPUIDLE_FLAG_TIMER_STOP)) + continue; + + drv->bctimer = 1; + on_each_cpu_mask(get_cpu_mask(cpu), cpuidle_setup_broadcast_timer, + (void *)CLOCK_EVT_NOTIFY_BROADCAST_ON, 1); + break; + } } static int __cpuidle_register_driver(struct cpuidle_driver *drv, int cpu) @@ -35,7 +56,7 @@ static int __cpuidle_register_driver(struct cpuidle_driver *drv, int cpu) if (__cpuidle_get_cpu_driver(cpu)) return -EBUSY; - __cpuidle_driver_init(drv); + __cpuidle_driver_init(drv, cpu); __cpuidle_set_cpu_driver(drv, cpu); @@ -49,6 +70,12 @@ static void __cpuidle_unregister_driver(struct cpuidle_driver *drv, int cpu) if (!WARN_ON(drv->refcnt > 0)) __cpuidle_set_cpu_driver(NULL, cpu); + + if (drv->bctimer) { + drv->bctimer = 0; + on_each_cpu_mask(get_cpu_mask(cpu), cpuidle_setup_broadcast_timer, + (void *)CLOCK_EVT_NOTIFY_BROADCAST_OFF, 1); + } } #ifdef CONFIG_CPU_IDLE_MULTIPLE_DRIVERS diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index a837b33..fc3e580 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -107,6 +107,8 @@ struct cpuidle_driver { /* set to 1 to use the core cpuidle time keeping (for all states). */ unsigned int en_core_tk_irqen:1; + /* used by the cpuidle framework to setup the broadcast timer */ + unsigned int bctimer:1; /* states array must be ordered in decreasing power consumption */ struct cpuidle_state states[CPUIDLE_STATE_MAX]; int state_count;