From patchwork Sat Jun 21 23:29:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 32308 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f69.google.com (mail-pb0-f69.google.com [209.85.160.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BFDCA203F4 for ; Sat, 21 Jun 2014 23:30:38 +0000 (UTC) Received: by mail-pb0-f69.google.com with SMTP id uo5sf19543724pbc.0 for ; Sat, 21 Jun 2014 16:30:38 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=FW8d7IpCdjlYppAgnzMJ5x/hm+vJgNfm6E+4dFAOU4s=; b=YK11H/VcTvKLd1QoxL1CUASb/29oVZubTW1nZ49GXEd+7Io/MJv/9fV6qOT4nsxIjl 6b57WaI0VClk/SYluAHkgqFqcfR//LukhjiGsQV6DBZltevfUZQdPBf7nD+taw83Eg/j 37wNWc841xWdj68uKm3Iw/TYSxRUmjB9d+MLpKRzLjnIuw0N5lrTnXg4KbPAICx37kK+ y3ve37hs+oh+OKYT+F/OS6zzQSaxzvXJeYSz4EBIBnSn9XDogbkFepKLcdXPp9pkWeGw uwAzfSbApUwZDGYtRslqTHEz33CrDmr+vcnvEAktUTyPPyCzYElf8l8tkQ5uiRMm1/+u WcOQ== X-Gm-Message-State: ALoCoQnlzSdNIpTaVklugpZ5s9wcPpowGiizYIhHWQbfp+BdgNssurXScfF4D1C0dFkFYazmyFkL X-Received: by 10.66.169.231 with SMTP id ah7mr5498905pac.40.1403393437915; Sat, 21 Jun 2014 16:30:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.95.6 with SMTP id h6ls1444745qge.45.gmail; Sat, 21 Jun 2014 16:30:37 -0700 (PDT) X-Received: by 10.52.244.138 with SMTP id xg10mr2188309vdc.40.1403393437811; Sat, 21 Jun 2014 16:30:37 -0700 (PDT) Received: from mail-ve0-x22c.google.com (mail-ve0-x22c.google.com [2607:f8b0:400c:c01::22c]) by mx.google.com with ESMTPS id ds1si6576700vec.32.2014.06.21.16.30.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 21 Jun 2014 16:30:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::22c as permitted sender) client-ip=2607:f8b0:400c:c01::22c; Received: by mail-ve0-f172.google.com with SMTP id jz11so4875414veb.3 for ; Sat, 21 Jun 2014 16:30:37 -0700 (PDT) X-Received: by 10.221.27.8 with SMTP id ro8mr3803631vcb.30.1403393437622; Sat, 21 Jun 2014 16:30:37 -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.221.37.5 with SMTP id tc5csp44340vcb; Sat, 21 Jun 2014 16:30:37 -0700 (PDT) X-Received: by 10.68.211.195 with SMTP id ne3mr16416446pbc.121.1403393436711; Sat, 21 Jun 2014 16:30:36 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ea5si15653498pad.63.2014.06.21.16.30.08; Sat, 21 Jun 2014 16:30:08 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752033AbaFUX3c (ORCPT + 13 others); Sat, 21 Jun 2014 19:29:32 -0400 Received: from mail-wg0-f49.google.com ([74.125.82.49]:35342 "EHLO mail-wg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751502AbaFUX3Z (ORCPT ); Sat, 21 Jun 2014 19:29:25 -0400 Received: by mail-wg0-f49.google.com with SMTP id y10so5081290wgg.8 for ; Sat, 21 Jun 2014 16:29:24 -0700 (PDT) X-Received: by 10.194.83.39 with SMTP id n7mr15453408wjy.58.1403393364684; Sat, 21 Jun 2014 16:29:24 -0700 (PDT) Received: from localhost.localdomain (8.20.196.77.rev.sfr.net. [77.196.20.8]) by mx.google.com with ESMTPSA id sg1sm41744wic.4.2014.06.21.16.29.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jun 2014 16:29:24 -0700 (PDT) From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Viresh Kumar , Frederic Weisbecker Subject: [PATCH 2/5] timer: Kick dynticks targets on mod_timer*() calls Date: Sun, 22 Jun 2014 01:29:14 +0200 Message-Id: <1403393357-2070-3-git-send-email-fweisbec@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1403393357-2070-1-git-send-email-fweisbec@gmail.com> References: <1403393357-2070-1-git-send-email-fweisbec@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: fweisbec@gmail.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::22c as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com 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: , From: Viresh Kumar When a timer is enqueued or modified on a dynticks target, that CPU must re-evaluate the next tick to service that timer. The tick re-evaluation is performed by an IPI kick on the target. Now while we correctly call wake_up_nohz_cpu() from add_timer_on(), the mod_timer*() API family doesn't support so well dynticks targets. The reason for this is likely that __mod_timer() isn't supposed to select an idle target for a timer, unless that target is the current CPU, in which case a dynticks idle kick isn't actually needed. But there is a small race window lurking behind that assumption: the elected target has all the time to turn dynticks idle between the call to get_nohz_timer_target() and the locking of its base. Hence a risk that we enqueue a timer on a dynticks idle destination without kicking it. As a result, the timer might be serviced too late in the future. Also a target elected by __mod_timer() can be in full dynticks mode and thus require to be kicked as well. And unlike idle dynticks, this concern both local and remote targets. To fix this whole issue, lets centralize the dynticks kick to internal_add_timer() so that it is well handled for all sort of timer enqueue. Even timer migration is concerned so that a full dynticks target is correctly kicked as needed when timers are migrating to it. Signed-off-by: Viresh Kumar Signed-off-by: Frederic Weisbecker --- kernel/timer.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/kernel/timer.c b/kernel/timer.c index 9e5f4f2..aca5dfe 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -410,6 +410,22 @@ static void internal_add_timer(struct tvec_base *base, struct timer_list *timer) base->next_timer = timer->expires; } base->all_timers++; + + /* + * Check whether the other CPU is in dynticks mode and needs + * to be triggered to reevaluate the timer wheel. + * We are protected against the other CPU fiddling + * with the timer by holding the timer base lock. This also + * makes sure that a CPU on the way to stop its tick can not + * evaluate the timer wheel. + * + * Spare the IPI for deferrable timers on idle targets though. + * The next busy ticks will take care of it. Except full dynticks + * require special care against races with idle_cpu(), lets deal + * with that later. + */ + if (!tbase_get_deferrable(base) || tick_nohz_full_cpu(base->cpu)) + wake_up_nohz_cpu(base->cpu); } #ifdef CONFIG_TIMER_STATS @@ -949,22 +965,6 @@ void add_timer_on(struct timer_list *timer, int cpu) timer_set_base(timer, base); debug_activate(timer, timer->expires); internal_add_timer(base, timer); - /* - * Check whether the other CPU is in dynticks mode and needs - * to be triggered to reevaluate the timer wheel. - * We are protected against the other CPU fiddling - * with the timer by holding the timer base lock. This also - * makes sure that a CPU on the way to stop its tick can not - * evaluate the timer wheel. - * - * Spare the IPI for deferrable timers on idle targets though. - * The next busy ticks will take care of it. Except full dynticks - * require special care against races with idle_cpu(), lets deal - * with that later. - */ - if (!tbase_get_deferrable(timer->base) || tick_nohz_full_cpu(cpu)) - wake_up_nohz_cpu(cpu); - spin_unlock_irqrestore(&base->lock, flags); } EXPORT_SYMBOL_GPL(add_timer_on);