From patchwork Fri Apr 4 08:35:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 27789 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C5F1620490 for ; Fri, 4 Apr 2014 08:37:05 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lj1sf11462459pab.9 for ; Fri, 04 Apr 2014 01:37:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=W/ArlOK5Jq9lbPdH3OrkEliB7pb5nKCy3ab5U7Msg9I=; b=bzqqf979bJO2Y5ifzm5Tpujm1fLMi8hrcR8vtICNQHskUrXQLsg5pawqiklhR3Ol6u 8QKqpxi93TpkqsqKUn4D2YEdySDv+sEBqUT5kCyr3Z7z5uTzF5ZkMih+geuaoCJOwN9f eTvcNFlL3P7BDP23087cttTbEjvICv6g8MOOKsNaXt+K/hzDelPT0o98Qe1Y4mauPcav dlS5l5yaIm6h4fdyLEn2+Z9Q7PKWmWTGHDAfxRrV+zDcvTYaHClMlDVeADx1vUXSa9hl 2KHFfVMR7bfCEJTZv/0zGzE+qvqIprB0sBTeGsJzOA/dJl5CF0FAhUcYAgqLTG/FZ3d+ s1fA== X-Gm-Message-State: ALoCoQlyuWrLZY/Qs2NjOTW1mU7E7wlSRRzVtcN7k89C9Z2iqYE/Y3CEySQBV93zUGkUn6dbJeAx X-Received: by 10.66.221.137 with SMTP id qe9mr7440040pac.4.1396600624996; Fri, 04 Apr 2014 01:37:04 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.83.137 with SMTP id j9ls983053qgd.70.gmail; Fri, 04 Apr 2014 01:37:04 -0700 (PDT) X-Received: by 10.52.130.225 with SMTP id oh1mr10283281vdb.8.1396600624886; Fri, 04 Apr 2014 01:37:04 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id ya4si16918vec.109.2014.04.04.01.37.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 04 Apr 2014 01:37:04 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id im17so2892292vcb.37 for ; Fri, 04 Apr 2014 01:37:04 -0700 (PDT) X-Received: by 10.221.40.10 with SMTP id to10mr579535vcb.22.1396600624808; Fri, 04 Apr 2014 01:37:04 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp95591vcv; Fri, 4 Apr 2014 01:37:03 -0700 (PDT) X-Received: by 10.68.139.137 with SMTP id qy9mr13425985pbb.11.1396600621163; Fri, 04 Apr 2014 01:37:01 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id vn9si4317781pbc.131.2014.04.04.01.37.00; Fri, 04 Apr 2014 01:37:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752481AbaDDIgq (ORCPT + 27 others); Fri, 4 Apr 2014 04:36:46 -0400 Received: from mail-wi0-f182.google.com ([209.85.212.182]:57229 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751978AbaDDIgj (ORCPT ); Fri, 4 Apr 2014 04:36:39 -0400 Received: by mail-wi0-f182.google.com with SMTP id d1so760711wiv.3 for ; Fri, 04 Apr 2014 01:36:37 -0700 (PDT) X-Received: by 10.195.12.14 with SMTP id em14mr17815606wjd.15.1396600597360; Fri, 04 Apr 2014 01:36:37 -0700 (PDT) Received: from localhost ([213.122.173.131]) by mx.google.com with ESMTPSA id fs8sm3250594wib.8.2014.04.04.01.36.32 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 04 Apr 2014 01:36:36 -0700 (PDT) From: Viresh Kumar To: tglx@linutronix.de, fweisbec@gmail.com, peterz@infradead.org, mingo@kernel.org, tj@kernel.org, lizefan@huawei.com Cc: linaro-kernel@lists.linaro.org, linaro-networking@linaro.org, Arvind.Chauhan@arm.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Viresh Kumar Subject: [PATCH V2 6/8] hrtimer: create hrtimer_quiesce_cpu() to isolate CPU from hrtimers Date: Fri, 4 Apr 2014 14:05:33 +0530 Message-Id: <3d9c01fcc1b628ebc47c0ccdd17f9dc3e9e54614.1396599474.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , To isolate CPUs (isolate from hrtimers) from sysfs using cpusets, we need some support from the hrtimer core. i.e. A routine hrtimer_quiesce_cpu() which would migrate away all the unpinned hrtimers, but shouldn't touch the pinned ones. This patch creates this routine. Signed-off-by: Viresh Kumar --- include/linux/hrtimer.h | 3 +++ kernel/hrtimer.c | 47 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h index 9fdb67b..0718753 100644 --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h @@ -350,6 +350,9 @@ DECLARE_PER_CPU(struct tick_device, tick_cpu_device); /* Exported timer functions: */ +/* To be used from cpusets, only */ +extern void hrtimer_quiesce_cpu(void *cpup); + /* Initialize timers: */ extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, enum hrtimer_mode mode); diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index 853dd8c..e8cd1db 100644 --- a/kernel/hrtimer.c +++ b/kernel/hrtimer.c @@ -1633,17 +1633,21 @@ static void init_hrtimers_cpu(int cpu) hrtimer_init_hres(cpu_base); } -#ifdef CONFIG_HOTPLUG_CPU - +#if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_CPUSETS) static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base, - struct hrtimer_clock_base *new_base) + struct hrtimer_clock_base *new_base, + bool remove_pinned) { struct hrtimer *timer; struct timerqueue_node *node; + struct timerqueue_head pinned; int is_pinned; + timerqueue_init_head(&pinned); + while ((node = timerqueue_getnext(&old_base->active))) { timer = container_of(node, struct hrtimer, node); + BUG_ON(hrtimer_callback_running(timer)); debug_deactivate(timer); @@ -1655,6 +1659,10 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base, __remove_hrtimer(timer, HRTIMER_STATE_MIGRATE, 0); is_pinned = timer->state & HRTIMER_STATE_PINNED; + if (!remove_pinned && is_pinned) { + timerqueue_add(&pinned, &timer->node); + continue; + } /* Check if CPU still has pinned timers */ if (unlikely(WARN(is_pinned, @@ -1676,18 +1684,24 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base, /* Clear the migration state bit */ timer->state &= ~HRTIMER_STATE_MIGRATE; } + + /* Re-queue pinned timers for non-hotplug usecase */ + while ((node = timerqueue_getnext(&pinned))) { + timer = container_of(node, struct hrtimer, node); + + timerqueue_del(&pinned, &timer->node); + enqueue_hrtimer(timer); + timer->state &= ~HRTIMER_STATE_MIGRATE; + } } -static void migrate_hrtimers(int scpu) +static void __migrate_hrtimers(int scpu, bool remove_pinned) { struct hrtimer_cpu_base *old_base, *new_base; struct hrtimer_clock_base *clock_base; unsigned int active_bases; int i; - BUG_ON(cpu_online(scpu)); - tick_cancel_sched_timer(scpu); - local_irq_disable(); old_base = &per_cpu(hrtimer_bases, scpu); new_base = &__get_cpu_var(hrtimer_bases); @@ -1700,7 +1714,8 @@ static void migrate_hrtimers(int scpu) for_each_active_base(i, clock_base, old_base, active_bases) migrate_hrtimer_list(clock_base, - &new_base->clock_base[clock_base->index]); + &new_base->clock_base[clock_base->index], + remove_pinned); raw_spin_unlock(&old_base->lock); raw_spin_unlock(&new_base->lock); @@ -1709,9 +1724,25 @@ static void migrate_hrtimers(int scpu) __hrtimer_peek_ahead_timers(); local_irq_enable(); } +#endif /* CONFIG_HOTPLUG_CPU || CONFIG_CPUSETS */ +#ifdef CONFIG_HOTPLUG_CPU +static void migrate_hrtimers(int scpu) +{ + BUG_ON(cpu_online(scpu)); + tick_cancel_sched_timer(scpu); + + __migrate_hrtimers(scpu, true); +} #endif /* CONFIG_HOTPLUG_CPU */ +#ifdef CONFIG_CPUSETS +void hrtimer_quiesce_cpu(void *cpup) +{ + __migrate_hrtimers(*(int *)cpup, false); +} +#endif /* CONFIG_CPUSETS */ + static int hrtimer_cpu_notify(struct notifier_block *self, unsigned long action, void *hcpu) {