Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp313466pxf; Thu, 11 Mar 2021 04:40:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJwZ12FLrLzOdZ+UnEjwukITNW7UU+OW0H6KCnhGWpPdLHVdOO85XBi0bfUhwmPtPCWiB7P4 X-Received: by 2002:a17:906:814b:: with SMTP id z11mr2898193ejw.290.1615466454352; Thu, 11 Mar 2021 04:40:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615466454; cv=none; d=google.com; s=arc-20160816; b=asIWA4k7l12MtWkPQqqEz6cnyz4pVQQeMZxAEdv1J58O6xTGv9G7LPIqV3PVk59yOs Z0XgTI9E4yXNMgtSC+UyjCoJnIbwOiuSjPTKZ3M2BUa9Wvg8z0DtvjC+fRfxXYh/ZN+b 9lA6a4Glo5qzwQDILAp+aXsEigqRm+UhreCT5/qCwOYxY9128xVuQWUVynJpjFq7SrXQ Okjmvf/FyP6OGqY1lkZGY4nYgK+Qy3STZJtLBSZ9bQTFUeIHs7KGNiGw72seNiAzsZy7 MUC27aZ3PTIrG4NwJVsFIYamne7iTPh/EYoUAKNCxf1FLMoAIJCvfx2crZQPOIgiXc5J o7kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1Hn+ROaZaF8Ri2Jqvuzpz5QSbwR/qiXN9j4fncwse0E=; b=luKFEbzkCOkkW8beLtQMJJZJ+5UPkxVZZQnY6ysTv2/LeZYhPLiqJfRWTbyZm/YTkE nKH1PaZH64WEynuYGW4iIPUu9QDvD4LCRCsqcnQOtZJ9gpuFkh/3S6fyjyiBsLE3Q3CQ OwiQGc26bbE+pT/wLvbCp6D5Z/40f23zKUDN4T0jmtZIUXxyEMKNXL2dHXqKxchWWHC5 7sAy5KxAClY1uAbfF+lQemIjZyYlRKgj6cm+X6D0rnfZ7bHZzwqMVe9wCTDWUkpkWnaz 2u5XbEPsq9lxWgLpbrLL0LXAo+keJEPvjd4iap2ZAu+QU6hB4+2ODzLM2zlZD3jAtkWM Zh+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c+xwuhAJ; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c10si1683853edv.12.2021.03.11.04.40.31; Thu, 11 Mar 2021 04:40:54 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=c+xwuhAJ; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233287AbhCKMhe (ORCPT + 99 others); Thu, 11 Mar 2021 07:37:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:59746 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233216AbhCKMhU (ORCPT ); Thu, 11 Mar 2021 07:37:20 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D886464FE2; Thu, 11 Mar 2021 12:37:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615466240; bh=ihrDgHPsOXbJ0Kv6xMjDIKxHBrnQYBX7f9H3CeZ7+Y4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c+xwuhAJouSIwNkq4pLlOxiqqBvcHt+bcl0oGaK3UaiAIWpZ1tBo5TtzrHopuLjU3 RQDE8fXmi0Xfd6pgs+rozhhCebHvWatzK1DVLo/sktls48RQd22lSmbi36o5GF021C 56bwFW+wMsi4hdYduuVQl/3MLYlSuafgWeYfrJwvUPRnLrvGb3XQnwNqj+65fipZF0 Jr+z8JA2QswLofn1q21MxQSnScxt1k6EpZCcrTHcPZtj+JZh8EI3OIcpz+i40gZO9R BLK8CQM2EKSHdlQqR8yQeNQO5HcvwypKVNK0MVBY+HCao/+VwCfNXsswK+lxzfJMIZ k4hHYTXPBCI3A== From: Frederic Weisbecker To: Peter Zijlstra , Thomas Gleixner Cc: LKML , Frederic Weisbecker , "Rafael J . Wysocki" , Ti Zhou , Yunfeng Ye , "Paul E . McKenney" , Marcelo Tosatti , Ingo Molnar Subject: [PATCH 02/10] tick/nohz: Add tick_nohz_full_this_cpu() Date: Thu, 11 Mar 2021 13:37:00 +0100 Message-Id: <20210311123708.23501-3-frederic@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210311123708.23501-1-frederic@kernel.org> References: <20210311123708.23501-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Optimize further the check for local full dynticks CPU. Testing directly tick_nohz_full_cpu(smp_processor_id()) is suboptimal because the compiler first fetches the CPU number and only then processes the static key. It's best to evaluate the static branch before anything. Provide with a function that handles that correctly and convert some users along. Signed-off-by: Frederic Weisbecker Cc: Yunfeng Ye Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Marcelo Tosatti Cc: Rafael J. Wysocki --- include/linux/tick.h | 11 ++++++++++- kernel/time/tick-sched.c | 12 +++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/linux/tick.h b/include/linux/tick.h index 7340613c7eff..bfc96cbe955c 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -193,6 +193,14 @@ static inline bool tick_nohz_full_cpu(int cpu) return cpumask_test_cpu(cpu, tick_nohz_full_mask); } +static inline bool tick_nohz_full_this_cpu(void) +{ + if (!tick_nohz_full_enabled()) + return false; + + return cpumask_test_cpu(smp_processor_id(), tick_nohz_full_mask); +} + static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask) { if (tick_nohz_full_enabled()) @@ -271,6 +279,7 @@ extern void __init tick_nohz_full_setup(cpumask_var_t cpumask); #else static inline bool tick_nohz_full_enabled(void) { return false; } static inline bool tick_nohz_full_cpu(int cpu) { return false; } +static inline bool tick_nohz_full_this_cpu(void) { return false; } static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask) { } static inline void tick_nohz_dep_set_cpu(int cpu, enum tick_dep_bits bit) { } @@ -296,7 +305,7 @@ static inline void tick_nohz_full_setup(cpumask_var_t cpumask) { } static inline void tick_nohz_task_switch(void) { - if (tick_nohz_full_enabled()) + if (tick_nohz_full_this_cpu()) __tick_nohz_task_switch(); } diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 22b6a46818cf..af76cfa51b57 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -304,7 +304,7 @@ static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) = */ static void tick_nohz_full_kick(void) { - if (!tick_nohz_full_cpu(smp_processor_id())) + if (!tick_nohz_full_this_cpu()) return; irq_work_queue(this_cpu_ptr(&nohz_full_kick_work)); @@ -452,9 +452,6 @@ void __tick_nohz_task_switch(void) local_irq_save(flags); - if (!tick_nohz_full_cpu(smp_processor_id())) - goto out; - ts = this_cpu_ptr(&tick_cpu_sched); if (ts->tick_stopped) { @@ -462,7 +459,6 @@ void __tick_nohz_task_switch(void) atomic_read(¤t->signal->tick_dep_mask)) tick_nohz_full_kick(); } -out: local_irq_restore(flags); } @@ -929,14 +925,16 @@ static void tick_nohz_restart_sched_tick(struct tick_sched *ts, ktime_t now) static void tick_nohz_full_update_tick(struct tick_sched *ts) { #ifdef CONFIG_NO_HZ_FULL - int cpu = smp_processor_id(); + int cpu; - if (!tick_nohz_full_cpu(cpu)) + if (!tick_nohz_full_this_cpu()) return; if (!ts->tick_stopped && ts->nohz_mode == NOHZ_MODE_INACTIVE) return; + cpu = smp_processor_id(); + if (can_stop_full_tick(cpu, ts)) tick_nohz_stop_sched_tick(ts, cpu); else if (ts->tick_stopped) -- 2.25.1