Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp405195pxy; Thu, 22 Apr 2021 05:03:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNOlHdowxEpT2NkWleZDiu5qrSp/rUeoOw4YwQkFWKhZJwTwSamGMqErVtlYhA6MHW53Zo X-Received: by 2002:aa7:c4c1:: with SMTP id p1mr3319976edr.133.1619093011625; Thu, 22 Apr 2021 05:03:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619093011; cv=none; d=google.com; s=arc-20160816; b=avgt5CLabpW810jgRyJZA3utm0dqZO34Rxvm9qmn/OSw8axm03j6cl0Ilc81/P79fi mhJTwYhrmgh37cpuN8uMLy2M3aPueUf9On1b6AQquDOySNRmLdisXi/Gr0iNP8FlLZsy UCXOtgBtDSrR4CmPZzIVg3o56xYfkPobOEPU0ZkV1ktRKV3InY5gnhFW4yb180zeLDH+ /fTF3VqsGTV6lWJtMSNJB3y8FQp7VM0dbMnKXpoLFAIOuhD8tCWA9MnyBWoujUuVbIV1 1nAxK/tUH3B/S5GqGvQg60zGqEXWNTHcU9ubOmdPaCeai4SYVXemMubhUAcxc6Sbu0K7 xIDA== 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=qTKjij5omKnFizVQQAYRyS3oyv4+rvYa2ia+MiL/ljg=; b=Y78Bs2wGPeiF4ZdWsM+rpFvmgokgbImI9NDLqidJXxlHvZrYmKFBYFzVb5/Yyy9JRj 2PT7UbB1CpB7ZmzVZ2oJsAGLiJ/YPgLrfMPcKD4qgHvpgBAWZ4ZLRYE0UocuUq7Ojx2g I7PES3Dp7uSO3ASRLBy/Q2a1kOIGkTd/66YJ7auf4V0zxi4rhc9RYvevy1QFac1vgqs1 /187yTXa+GyXlXZLCC+QQA9N03og67N1XtCdM7Tjocfd+ZHDHWa49mjkVr1pj64zWwII QjtbHPhiF5SfuzxOc+6zn4ZRni9n9aEzzX9mERemOzK/z4lpfjjLIOpSH8YdMIROVMzy 4YCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kGzbuVEU; 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 g3si1999643edu.276.2021.04.22.05.03.08; Thu, 22 Apr 2021 05:03:31 -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=@kernel.org header.s=k20201202 header.b=kGzbuVEU; 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 S236152AbhDVMCp (ORCPT + 99 others); Thu, 22 Apr 2021 08:02:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:56318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235957AbhDVMCo (ORCPT ); Thu, 22 Apr 2021 08:02:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 34FD96145C; Thu, 22 Apr 2021 12:02:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619092929; bh=OOGMUkUWgJMSjS0NeoPvri4si7it3X4PmC8L55Sni6A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kGzbuVEU8nk97Mu0M09dBBstKtfKTDLWaduM07JUJ5aXFiz49IMOcuVgDM7SeGEZh 2jdIVMvgKyuzbXsRmJJUacey32W8rcndY9FNSS5Svap5VwiyV0YpSYzmAwmKryVC/L rSnf2LJtkG23BLv+HH4ReaYnBwLp2IA8hWTcPY/MDRmnMauAfFwHcKnQ/gNiaOFfLY ksiqIVkqtbT6UHY311W37jAZi6lkpcRibzquEUZyNjIEPLylEO211j7LO7ROp5LvXT H3QObbrP0cCuNYG5xRUI7tzFuz3B2gnJDjXANku81NRLrjriH9Bp/A/F6riq1cLJNX WEUhzCwRZXolg== From: Frederic Weisbecker To: Peter Zijlstra , Thomas Gleixner Cc: LKML , Yunfeng Ye , "Rafael J . Wysocki" , Frederic Weisbecker , Marcelo Tosatti Subject: [PATCH 2/8] tick/nohz: Conditionally restart tick on idle exit Date: Thu, 22 Apr 2021 14:01:52 +0200 Message-Id: <20210422120158.33629-3-frederic@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210422120158.33629-1-frederic@kernel.org> References: <20210422120158.33629-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 | 46 +++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index e10a4af88737..c888445fb181 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -926,24 +926,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 = smp_processor_id(); - if (!tick_nohz_full_cpu(cpu)) - return; - - if (!ts->tick_stopped && ts->nohz_mode == NOHZ_MODE_INACTIVE) - return; - 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_cpu(smp_processor_id())) + 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) { /* @@ -1205,18 +1211,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_cpu(smp_processor_id())) + __tick_nohz_full_update_tick(ts, now); + else + tick_nohz_restart_sched_tick(ts, now); + + tick_nohz_account_idle_ticks(ts); } /** @@ -1248,7 +1260,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