Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4588862pxy; Tue, 27 Apr 2021 08:18:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjKWTCpRSBmRAA1AUdI7QPYWIiK2boCMQbUO0GNt8ScF3xcZdWvmVxcaIY5IY8YRIiOeX6 X-Received: by 2002:aa7:d0c9:: with SMTP id u9mr3289143edo.43.1619536731724; Tue, 27 Apr 2021 08:18:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619536731; cv=none; d=google.com; s=arc-20160816; b=D0OSiQQwy/oPfLNuehGdy1RWAv/Wh221Zpr/1HPuKPYKiWZy8u99pvV/qtELoh5h/w uw+JPAYVMhjytNAcO2iMK89f3ffJt5lmaiV0crnkm53vJeS53ZdcUbj5veo1N0/ytEs1 4x5PR+OcEpsG/qop7RWFZZhbtf2BU7FB+67MOaec8ygcgZQaA3iMBdLq+dWGD7GO8IcL NL0DhPCcO3M4jtF8ZNMK3n8VFIlK37CUsDH9ugT/+/D3MwfwgP6/rxU8WUASRuGUMuLE jOBowxslsIJpeIadFKJp1U1KHk3oZbN0O4Fo3HnFbCu6qgLaJE3slXmuumHYOBSz5Ycf PuBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=kbCLDunCrFDW+UNrnx2AkD+SvvLwF4qVXw/73zjizkc=; b=wO4HgZk88j2YJgxdlRvF2tesSangTLyv5JMk7B9FTtMWrar+l8VRS6ghAJDwES0v+i LDsyuppTXspn+cHW9dOyVxCT1h+xTE0iYXF2NSh5JP7tM+EsuUtbpa9rbKzfo9Zn9tHx BYXeW7QY1VsVTlupNJYRd6XKCaBqJlVk4F4GmpTa79d5YGcInkUubp49tLAqUqGYqeAv E3wGpxyUlJdgxNHq5/OXf2GOwuRZBUMmDIWYSPNJbsk1Oz9kHz4RBMq+fLLezwqEQMIZ QRjLHCgSNrv00hkdfYOmQo3fbkji+OC1Y5IKpCMChX3qzICbxkSSvuH/YZoRtHUjaQzA jJRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ivqAP/6r"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l33si3106349ede.161.2021.04.27.08.18.27; Tue, 27 Apr 2021 08:18:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ivqAP/6r"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236144AbhD0PNP (ORCPT + 99 others); Tue, 27 Apr 2021 11:13:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42556 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235466AbhD0PNO (ORCPT ); Tue, 27 Apr 2021 11:13:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619536350; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kbCLDunCrFDW+UNrnx2AkD+SvvLwF4qVXw/73zjizkc=; b=ivqAP/6relT0enaTrTxy2dxhFtDAm9sZzK/XrDoCK7t26y4ta7TVid6YzXFVWot6FgW+9s 0ot7HxI99rMgpGPDTWp9SjoRC5Pta2lbH037oJs7slbJwyn0cTC+SnI/nEG1TmvcXPmTK9 ZojqIfj2Mt2OCmQm106sqR7FnX66V4U= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-48-PFUsQWzEOtWdtSSqfEywUQ-1; Tue, 27 Apr 2021 11:12:27 -0400 X-MC-Unique: PFUsQWzEOtWdtSSqfEywUQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AA9BA80DDF8; Tue, 27 Apr 2021 15:12:25 +0000 (UTC) Received: from fuller.cnet (ovpn-112-5.gru2.redhat.com [10.97.112.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B5F605C260; Tue, 27 Apr 2021 15:12:18 +0000 (UTC) Received: by fuller.cnet (Postfix, from userid 1000) id B490D416D899; Tue, 27 Apr 2021 12:11:25 -0300 (-03) Date: Tue, 27 Apr 2021 12:11:25 -0300 From: Marcelo Tosatti To: Thomas Gleixner Cc: LKML , Anna-Maria Behnsen , Peter Zijlstra , Frederic Weisbecker , Peter Xu , Nitesh Narayan Lal , Alex Belits , "Rafael J. Wysocki" , John Stultz Subject: Re: [patch 8/8] hrtimer: Avoid more SMP function calls in clock_was_set() Message-ID: <20210427151125.GA171315@fuller.cnet> References: <20210427082537.611978720@linutronix.de> <20210427083724.840364566@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210427083724.840364566@linutronix.de> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 27, 2021 at 10:25:45AM +0200, Thomas Gleixner wrote: > There are more indicators whether the SMP function calls on clock_was_set() > can be avoided: > > - When the remote CPU is currently handling hrtimer_interrupt(). In > that case the remote CPU will update offsets and reevaluate the timer > bases before reprogramming anyway, so nothing to do. > > By unconditionally updating the offsets the following checks are possible: > > - When the offset update already happened on the remote CPU then the > remote update attempt will yield the same seqeuence number and no > IPI is required. > > - After updating it can be checked whether the first expiring timer in > the affected clock bases moves before the first expiring (softirq) > timer of the CPU. If that's not the case then sending the IPI is not > required. > > Signed-off-by: Thomas Gleixner > --- > kernel/time/hrtimer.c | 66 +++++++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 57 insertions(+), 9 deletions(-) > > --- a/kernel/time/hrtimer.c > +++ b/kernel/time/hrtimer.c > @@ -880,6 +880,60 @@ static void hrtimer_reprogram(struct hrt > tick_program_event(expires, 1); > } > > +static bool update_needs_ipi(struct hrtimer_cpu_base *cpu_base, > + unsigned int active) > +{ > + struct hrtimer_clock_base *base; > + unsigned int seq; > + ktime_t expires; > + > + /* > + * If the remote CPU is currently handling an hrtimer interrupt, it > + * will update and reevaluate the first expiring timer of all clock > + * bases before reprogramming. Nothing to do here. > + */ > + if (cpu_base->in_hrtirq) > + return false; Thomas, The base offsets are updated at Cscope tag: hrtimer_update_base # line filename / context / line 1 736 kernel/time/hrtimer.c <> (IPI handler) hrtimer_update_base(base); 2 1617 kernel/time/hrtimer.c <> (softirq handler) now = hrtimer_update_base(cpu_base); 3 1645 kernel/time/hrtimer.c <> (hrtimer_interrupt entry) entry_time = now = hrtimer_update_base(cpu_base); 4 1695 kernel/time/hrtimer.c <> (after tick_program_event failure) now = hrtimer_update_base(cpu_base); 5 1768 kernel/time/hrtimer.c <> (sched_tick) now = hrtimer_update_base(cpu_base); Consider hrtimer_interrupt in_hrtirq = 1 __run_hrtimer raw_spin_unlock_irqrestore(&cpu_base->lock, flags) settimeofday clock_was_set lock cpu_base->lock update_needs_ipi returns false continue to process hrtimers with stale base->offset No?