From patchwork Thu Jun 12 19:34:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 31862 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f197.google.com (mail-qc0-f197.google.com [209.85.216.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 698462100A for ; Thu, 12 Jun 2014 19:34:36 +0000 (UTC) Received: by mail-qc0-f197.google.com with SMTP id i8sf6077814qcq.0 for ; Thu, 12 Jun 2014 12:34:36 -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=OJ4rd9aM+kRC36psWqLP+QeQKj2V/6uXRS7Dj3mumJYp/+d14MhHxeBOT+WMg69eKs yqGTX5EnVFzaGtVPA5xWdjmJtToo3k5emM7voGOaT8YFINa13X9ojdCQjQZ6vQht5blY o7ErFXq8/hXtVjDhAT7F3EL8tjx9xvzavFMfvoq7FuGOOIwO32DiAbgtPO91C8htTrYS o3stDo24Jp/YLewbCAf8O8djG4bCTDKkCvY1ij2lNam6KTQDcrYGL1c3yIB81ZVY+qOw BC6SC+guHEbPlaIORotRZ2t8mGvhTJ7TjhGNd02blRa3TBnW11YQaWERa1dRX+e86oNr eRKw== X-Gm-Message-State: ALoCoQnWuS4+i1O1dSOaRpUv3BGAV8gSzXOyPKsLSPxXgBqJSgbU4LI27MD4clY63BQjxjG39ItK X-Received: by 10.236.101.148 with SMTP id b20mr507245yhg.46.1402601676300; Thu, 12 Jun 2014 12:34:36 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.46.53 with SMTP id j50ls3169090qga.67.gmail; Thu, 12 Jun 2014 12:34:36 -0700 (PDT) X-Received: by 10.52.12.129 with SMTP id y1mr1367182vdb.59.1402601676195; Thu, 12 Jun 2014 12:34:36 -0700 (PDT) Received: from mail-vc0-x22f.google.com (mail-vc0-x22f.google.com [2607:f8b0:400c:c03::22f]) by mx.google.com with ESMTPS id sy10si627507veb.103.2014.06.12.12.34.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Jun 2014 12:34:36 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22f as permitted sender) client-ip=2607:f8b0:400c:c03::22f; Received: by mail-vc0-f175.google.com with SMTP id hy4so1291340vcb.20 for ; Thu, 12 Jun 2014 12:34:36 -0700 (PDT) X-Received: by 10.58.196.231 with SMTP id ip7mr1735477vec.47.1402601676094; Thu, 12 Jun 2014 12:34:36 -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.54.6 with SMTP id vs6csp428007vcb; Thu, 12 Jun 2014 12:34:35 -0700 (PDT) X-Received: by 10.66.182.69 with SMTP id ec5mr23142596pac.125.1402601675165; Thu, 12 Jun 2014 12:34:35 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fy1si42585367pbb.65.2014.06.12.12.34.34; Thu, 12 Jun 2014 12:34:34 -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 S1752122AbaFLTeb (ORCPT + 27 others); Thu, 12 Jun 2014 15:34:31 -0400 Received: from mail-wi0-f182.google.com ([209.85.212.182]:36657 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751495AbaFLTeI (ORCPT ); Thu, 12 Jun 2014 15:34:08 -0400 Received: by mail-wi0-f182.google.com with SMTP id bs8so3553137wib.3 for ; Thu, 12 Jun 2014 12:34:07 -0700 (PDT) X-Received: by 10.194.60.35 with SMTP id e3mr23372886wjr.12.1402601647662; Thu, 12 Jun 2014 12:34:07 -0700 (PDT) Received: from localhost.localdomain (80.20.196.77.rev.sfr.net. [77.196.20.80]) by mx.google.com with ESMTPSA id ja9sm32029397wic.8.2014.06.12.12.34.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jun 2014 12:34:07 -0700 (PDT) From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Viresh Kumar , Frederic Weisbecker Subject: [PATCH 2/2] timer: Kick dynticks targets on mod_timer*() calls Date: Thu, 12 Jun 2014 21:34:01 +0200 Message-Id: <1402601641-28462-3-git-send-email-fweisbec@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1402601641-28462-1-git-send-email-fweisbec@gmail.com> References: <1402601641-28462-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:c03::22f 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);