Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp646234pxj; Thu, 13 May 2021 13:27:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhcZD/sGn5YCZ1blcebb5NLN1l3lzqcUfsCq4eTmEf+jVdr8z/MZmjaoQm/lrd0XIlw1HS X-Received: by 2002:aa7:c4d0:: with SMTP id p16mr53975522edr.102.1620937667136; Thu, 13 May 2021 13:27:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620937667; cv=none; d=google.com; s=arc-20160816; b=05EZvRfZl+B/vDsFh4gUUB+D6SKzFkvZ5wity0pVs2xdZt0Lp0I83Khx1jsv6AgUAX gyLhLInIbcN+V4XvyZBPcITxupf1ypjJ7z/bDA/gm51v5Tausc0VAD8i3X0uhfehMe1I V9hAMWk1yD+iZxXpA6h0P1gXCrWcDjOfdKMrBXuhaOpMLq31VOdG8lIrPFmNuk5ThIgG rLrbrubO6lZ0TcLZBISIp6gLmY5hXOFJU0iP8QZ+yvQh686c0Elx4SVbFoDE0MkCsocB KuECukBqbKlsO05jYUH1orNdRx3jioei1X/aAAxMo9KmYMSWqr0lk2zEz17yX6J6HB0R 1IVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=th7WBRzSVnO3u6U4v2APFdBJksytfWHgV3mR2AbbeeU=; b=KxIvzvsFRZHfm4Eie36nvgn+ekrX4a3YaCECSY5amrhPXxR03PNV8w+aVcO1QFBWIy O1sMr+GHxs+HjeED1MgUMQR4JOPqFCoyw+CxMwNYzvI9QLZ7KrP2p5HMJvUTCAadu9ZW Wt/M0walT8VVlQeWy9BpcHdAce3sKJDNI1+2xzhfBZWycLwbJQxhc6HZX/YQjr5TpP5Q Ggw8bXsCyIwdleFrV1hFIa2N3q/qzjfNNyZAQKalqpr6ZPzmu2kGIPIumWNxQRYHg8TY d2tO120xdQubFGCOU/K1JcMVOqwkDjyyaXp6jhMEyQcI22gt7tNw0MdrUCNKnw++36LM 1B9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=k+wP4sqf; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m14si3455847edr.306.2021.05.13.13.27.20; Thu, 13 May 2021 13:27:47 -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=@linutronix.de header.s=2020 header.b=k+wP4sqf; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234006AbhEMNVC (ORCPT + 99 others); Thu, 13 May 2021 09:21:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233949AbhEMNTF (ORCPT ); Thu, 13 May 2021 09:19:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05EE5C061761; Thu, 13 May 2021 06:17:37 -0700 (PDT) Date: Thu, 13 May 2021 13:17:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1620911850; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=th7WBRzSVnO3u6U4v2APFdBJksytfWHgV3mR2AbbeeU=; b=k+wP4sqfv3EtVMGo6ept8EU7tNNrKaZV9mozVYk5a02I6qpwSDcYuXDwwe1kRV8L/5NfTh m7ijBluHe1EV8Exksp+G+EkDYzgk54UNImyuKXckH+0Ua6iXGduFtynmYD90tHj+kRU5dU +beVIDNm1Zuqc1tF1F6W0FzM4PoLUYDe9InDeAk6wRgy81b2YWPRgfzwqQsBH9FyzA3mh5 ovZSxYdJp1USSE86zodRJ7IaumyGcN3rECArCEd+OJSquafasW9GocqSOAGnVvI3d+jQrX kADvkwZYXIKjmm5H5NBT/2GE2TvkmbEoTnoTf0vHxP8nkH53BJU5tPBemDVCXw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1620911850; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=th7WBRzSVnO3u6U4v2APFdBJksytfWHgV3mR2AbbeeU=; b=plsAajJl5AftsnTTTL+/3kIE917bhPZtde0C/JxpNVkzZ42Ud96SRpPRzKvWwtajOBVXon Nhy0E/RuY9C8hsBw== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/nohz] tick/nohz: Evaluate the CPU expression after the static key Cc: Peter Zijlstra , Frederic Weisbecker , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210512232924.150322-2-frederic@kernel.org> References: <20210512232924.150322-2-frederic@kernel.org> MIME-Version: 1.0 Message-ID: <162091184985.29796.1926500160516806098.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the timers/nohz branch of tip: Commit-ID: f105dfec0a951cd0d5bfbfe9dc067ea69f71ad5c Gitweb: https://git.kernel.org/tip/f105dfec0a951cd0d5bfbfe9dc067ea69f71ad5c Author: Peter Zijlstra AuthorDate: Thu, 13 May 2021 01:29:15 +02:00 Committer: Ingo Molnar CommitterDate: Thu, 13 May 2021 14:21:20 +02:00 tick/nohz: Evaluate the CPU expression after the static key When tick_nohz_full_cpu() is called with smp_processor_id(), the latter is unconditionally evaluated whether the static key is on or off. It is not necessary in the off-case though, so make sure the cpu expression is executed at the last moment. Illustrate with the following test function: int tick_nohz_test(void) { return tick_nohz_full_cpu(smp_processor_id()); } The resulting code before was: mov %gs:0x7eea92d1(%rip),%eax # smp_processor_id() fetch nopl 0x0(%rax,%rax,1) xor %eax,%eax retq cmpb $0x0,0x29d393a(%rip) # je tick_nohz_test+0x29 # jump to below eax clear mov %eax,%eax bt %rax,0x29d3936(%rip) # setb %al movzbl %al,%eax retq xor %eax,%eax retq Now it becomes: nopl 0x0(%rax,%rax,1) xor %eax,%eax retq cmpb $0x0,0x29d3871(%rip) # je tick_nohz_test+0x29 # jump to below eax clear mov %gs:0x7eea91f0(%rip),%eax # smp_processor_id() fetch, after static key mov %eax,%eax bt %rax,0x29d3866(%rip) # setb %al movzbl %al,%eax retq xor %eax,%eax retq Signed-off-by: Peter Zijlstra Signed-off-by: Frederic Weisbecker Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20210512232924.150322-2-frederic@kernel.org --- include/linux/tick.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/include/linux/tick.h b/include/linux/tick.h index 7340613..2258984 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -185,13 +185,17 @@ static inline bool tick_nohz_full_enabled(void) return tick_nohz_full_running; } -static inline bool tick_nohz_full_cpu(int cpu) -{ - if (!tick_nohz_full_enabled()) - return false; - - return cpumask_test_cpu(cpu, tick_nohz_full_mask); -} +/* + * Check if a CPU is part of the nohz_full subset. Arrange for evaluating + * the cpu expression (typically smp_processor_id()) _after_ the static + * key. + */ +#define tick_nohz_full_cpu(_cpu) ({ \ + bool __ret = false; \ + if (tick_nohz_full_enabled()) \ + __ret = cpumask_test_cpu((_cpu), tick_nohz_full_mask); \ + __ret; \ +}) static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask) {