Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp312180pxf; Thu, 11 Mar 2021 04:39:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwON3e76mi/5r6RaZwC3O5eYIJFv+W5HtiWTdldwMJvvGqOBmavhL9hOrG0p3BrKWMx2tGH X-Received: by 2002:a17:906:398a:: with SMTP id h10mr2936404eje.155.1615466341659; Thu, 11 Mar 2021 04:39:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615466341; cv=none; d=google.com; s=arc-20160816; b=pieQiKm+cdX8OcxnmjmfmzCQknmxSdIgQahy4yNoCNccXb8JrfeSeHzYigkGS26M6s 7DIzc2EtGhAXiQC9b4+sG63Xxw8cTlZVAVbloEWwaq3ITvRTVK17BFUOJ1iCnoG5lqD5 VIO/5RdDilullKjlTd8UtVDKJrXw8j5RYIFCK4AXh7c7Yi8Cy8/oJjakAgCXgQJWBAB8 stDPHkcwiFVSUAZMwFwHXoeLOaftPkrDgjaWXnF+EksjNnTy0emA3Izdv/VkgfN7x3l7 /sTd7QlacFX3Xto2GeBxmDcYSOSLOkC4NKO+IlLdHG/+DESgtujRH2E8M0bGkOQCZnPR sgXA== 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=Nsr9Bnp9sw/tC4qqskZ3KXKLKlqeIwNwFFNBLxkyF8c=; b=BGLm+9IarvJy3gr6Y4vTN8pHxlVU/BIh/WkPkZO5dVZiJ2HFrUl5NiSi4C8Pf69F4h A/nvimOv457GV9YJSap53F64qUjVK3q73u8mcnDhoIa00XULDVwm27sua6/flIBvpbXO 3vENYI8/2Npcynq/FHAhcht3+Z46DpWHDMRxsN6hbi81Zj61CpbVtJBqbW8dBYL1DM+O NZr8hBRRoT5dhtrTXJHJsLgM1PyityB2trsv8v+uvpv6crioWMNIS8cyD2lIoK5pM2hS GXDnFUmlAV9tY9QC26iryok1YYH4C0C2VmeKXh5t8X4k5IVT7XrjL0fb3Yj09OzzabGE 6zdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OQiTBJxm; 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 ci1si1766507ejb.3.2021.03.11.04.38.39; Thu, 11 Mar 2021 04:39:01 -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=OQiTBJxm; 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 S233325AbhCKMhh (ORCPT + 99 others); Thu, 11 Mar 2021 07:37:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:59780 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233167AbhCKMhX (ORCPT ); Thu, 11 Mar 2021 07:37:23 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A41F864FE7; Thu, 11 Mar 2021 12:37:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615466243; bh=tWJG8XyIOuDvmB3DrOnKsLIOoV6EuxGTr/dpTqOJcm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OQiTBJxmJ8J8whPrtGyYb2wD1fdS3xLxSaCWC//ZxAK8Bckgu/ex8e/KjkJDFjL4F S+/ICE5SJHo80mCVN4BXiI2uFkbS/qGu77aFccXe3lPB97/7lJZX7/skT5VZO7FAbV +QdvNVBYd2WMg0CAUoqvw7eUfiIhqMcAyxLft9khHffFYbqFDSrJNFzhOe8QDOtADa TtWncVc6SZcVVzP0cZKlABchPJaggb7yF7Qpz+7t4MHEf5/CLzCUPTTuP5otRv52ze lJJ70X4ttubgRXpHFknmRJOFSEYo4LSIIENotBQe/aADhFr+ahQVqBD0ys1zcFF8pE XrEUqocDEmqvg== From: Frederic Weisbecker To: Peter Zijlstra , Thomas Gleixner Cc: LKML , Yunfeng Ye , "Rafael J . Wysocki" , Ti Zhou , Frederic Weisbecker , "Paul E . McKenney" , Marcelo Tosatti , Ingo Molnar Subject: [PATCH 03/10] tick/nohz: Conditionally restart tick on idle exit Date: Thu, 11 Mar 2021 13:37:01 +0100 Message-Id: <20210311123708.23501-4-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 From: Yunfeng Ye In nohz_full mode, switching from idle to a task will unconditionally issue a tick restart. If the task is alone in the runqueue or is the highest priority, the tick will fire once then eventually stop. But that alone is still undesired noise. Therefore, only restart the tick on idle exit when it's strictly necessary. Signed-off-by: Yunfeng Ye Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Marcelo Tosatti Cc: Rafael J. Wysocki Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.c | 50 ++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index af76cfa51b57..77dc8cd61dc8 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -922,26 +922,30 @@ static void tick_nohz_restart_sched_tick(struct tick_sched *ts, ktime_t now) tick_nohz_restart(ts, now); } -static void tick_nohz_full_update_tick(struct tick_sched *ts) +static void __tick_nohz_full_update_tick(struct tick_sched *ts, + ktime_t now) { #ifdef CONFIG_NO_HZ_FULL - int cpu; - - if (!tick_nohz_full_this_cpu()) - return; - - if (!ts->tick_stopped && ts->nohz_mode == NOHZ_MODE_INACTIVE) - return; - - cpu = smp_processor_id(); + int cpu = smp_processor_id(); if (can_stop_full_tick(cpu, ts)) tick_nohz_stop_sched_tick(ts, cpu); else if (ts->tick_stopped) - tick_nohz_restart_sched_tick(ts, ktime_get()); + tick_nohz_restart_sched_tick(ts, now); #endif } +static void tick_nohz_full_update_tick(struct tick_sched *ts) +{ + if (!tick_nohz_full_this_cpu()) + return; + + if (!ts->tick_stopped && ts->nohz_mode == NOHZ_MODE_INACTIVE) + return; + + __tick_nohz_full_update_tick(ts, ktime_get()); +} + static bool can_stop_idle_tick(int cpu, struct tick_sched *ts) { /* @@ -1209,18 +1213,24 @@ static void tick_nohz_account_idle_ticks(struct tick_sched *ts) #endif } -static void __tick_nohz_idle_restart_tick(struct tick_sched *ts, ktime_t now) -{ - tick_nohz_restart_sched_tick(ts, now); - tick_nohz_account_idle_ticks(ts); -} - void tick_nohz_idle_restart_tick(void) { struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); - if (ts->tick_stopped) - __tick_nohz_idle_restart_tick(ts, ktime_get()); + if (ts->tick_stopped) { + tick_nohz_restart_sched_tick(ts, ktime_get()); + tick_nohz_account_idle_ticks(ts); + } +} + +static void tick_nohz_idle_update_tick(struct tick_sched *ts, ktime_t now) +{ + if (tick_nohz_full_this_cpu()) + __tick_nohz_full_update_tick(ts, now); + else + tick_nohz_restart_sched_tick(ts, now); + + tick_nohz_account_idle_ticks(ts); } /** @@ -1252,7 +1262,7 @@ void tick_nohz_idle_exit(void) tick_nohz_stop_idle(ts, now); if (tick_stopped) - __tick_nohz_idle_restart_tick(ts, now); + tick_nohz_idle_update_tick(ts, now); local_irq_enable(); } -- 2.25.1