From patchwork Sun Feb 25 22:54:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 206130 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1770252dyb; Sun, 25 Feb 2024 14:55:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUIblt0SPEJklu8fPlhCl9pnkN6u+2Tnr+314ReYtRqiVzxf18WzP/SN9UjdJvN+anxFX2byXWtHVbr1SaaCIHw49QjOw== X-Google-Smtp-Source: AGHT+IG4Msgzczo0yskZTlBGAETvxqnpBeeYlahoMaEzuYRgeAZJKT53fY9BzZICWDX7t1u4HZm+ X-Received: by 2002:a17:90a:e2c7:b0:299:35ea:cfb5 with SMTP id fr7-20020a17090ae2c700b0029935eacfb5mr3058885pjb.2.1708901754843; Sun, 25 Feb 2024 14:55:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708901754; cv=pass; d=google.com; s=arc-20160816; b=Obl3yWYPfiTZGZ0BDZejFLq3wxoa/0zY33XD/O5XCdOxG/W5NbrmU1oArG8JN1SBjo 8F3CX8kgBMlSQY2jPLyIjrw9eXX2wWYQiQVe7zPQk4gmvjNFx7+TPMtK6/rp14GeuaHb XHZGKQPebX0B5lAaVc28jNV62k1YHrRv90s2Wa9mwZ4KMke81i1CjvigRkAl+9akIM6K r1zOoD7ZGai7fkDWFUIx/jnBVRjfWasISpHXriOE7JtkDkDtofJfo5RWl2QB9dCnOb6F LE5ekMfrS0zUNG9iO1P8Bt9mJ9iqGfCn1o5O2lJYX73rKFnOzF6ovPEL8UfADHPkxdFM +eSw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=F2HMzsbSBya5PazJzoP4ezhwGTyyYr23HIP8ixzYQu0=; fh=4P8gqRLFmANjcHHSJu0T2ajtncG7F3hkmyD1v1G3zYE=; b=zUcQrkQ9oK36qAM6ctG8FWxL3XcOiP+RDjbwALcPANaWCdxvkC6ugFXxoDuAPghD+h tQmq+Xux+6TgsNUnKS/is8te9pINY1zjgbGTTqFVzSEE/gDQGoQ4waKx2cR1o4sg3xeO hLiV3xPSu+lmDNshBvSjxe7vW92+wU2Gd3I18qRJmd2Ra0IjlNL3QlijO+r9NZsGfq9p zQR6n2CxeiIOh+1YQw9N5XzNVEM2vnyS/eouK9Qxp3Qv0d+ZScd+4Itt65WNf9h6Nl0z o9IaoQH+at0pA/lbUjAV4HegmtoXRkhPmiEOalSozMvnUOU+9mmuBiw+3pe8wCU0gAMq n08g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dEq6qFQu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80329-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80329-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o4-20020a17090ac70400b0029a5eba078asi4541691pjt.142.2024.02.25.14.55.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 14:55:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80329-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dEq6qFQu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80329-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80329-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A798E282065 for ; Sun, 25 Feb 2024 22:55:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6303F1C6AF; Sun, 25 Feb 2024 22:55:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dEq6qFQu" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DFDC1BF32 for ; Sun, 25 Feb 2024 22:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901718; cv=none; b=g5GtRgW2QFBktW0/j3prbb8sYBVukfy1LjaERT5ACxHhW/Rcq4AeigaoDd3tGIrJpawowFLY+Cr5wKGZ0T8ShjW+kuRmRR3JSyaH/cUKDRFzjS9LEEzOkopdmPaNIXgXSYqJj+vxYyFYOzlJM2hxc41A+Gqm+Q+5BVJsJwW7BXc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708901718; c=relaxed/simple; bh=+VkDJHjdvXPixo+AoZLYaSFfxZZUAYxpQOjC47SAJvs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YhjspfS4luiDyP7OYQNBJ9fpTdG1OnueLBdlzqjg9/W6GP3gwfQOXxSovdzPyis+BFKgboQJnfA7yY1nowJBoRaa3yJCXXt3/auPhNrUl1/gEKv/okPj+SmJifSj0wp4bQYu2CncnLCq/l2+Zg0GPx5PkYVM8s0Dy5UnX7g3lCM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dEq6qFQu; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93B78C433C7; Sun, 25 Feb 2024 22:55:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708901718; bh=+VkDJHjdvXPixo+AoZLYaSFfxZZUAYxpQOjC47SAJvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dEq6qFQu6pU6EZ3Ejzac3rNBls6OXzOOCQ+HwqB3QGi+X0lUQFwqGVF9DrN9zlrUY DQDlNOHff0D4hFajnvSo3Zq92dTzGGeMc7mgKVAga5AXLxpDLWqs3p7Ilm1ucNMsq7 uSxkWQHyJMajQ1qROJqXky/AF+LhPEe4iPZXSm6VXYRk8vaI7JSxfmwxJDA1aAtBUV Lmbt8gnIle5ppJt9mryOoI3o0c/mMAPwQjxCmnmZB6K6EkVTBgJBxH5EsHFxe0znkh n8GvsM2LFoSNdxWasYTBxMBOn5BxAXjja6M3rTI/76AeEhzMi/fHpC5MNvC0+0xT5i QD2O6tsI2JhHQ== From: Frederic Weisbecker To: LKML Cc: Peng Liu , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Joel Fernandes , Frederic Weisbecker Subject: [PATCH 02/16] tick/nohz: Remove duplicate between lowres and highres handlers Date: Sun, 25 Feb 2024 23:54:54 +0100 Message-ID: <20240225225508.11587-3-frederic@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240225225508.11587-1-frederic@kernel.org> References: <20240225225508.11587-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791913366158391970 X-GMAIL-MSGID: 1791913366158391970 From: Peng Liu tick_nohz_lowres_handler() does the same work as tick_nohz_highres_handler() plus the clockevent device reprogramming, so make the former reuse the latter and rename it accordingly. Signed-off-by: Peng Liu Signed-off-by: Frederic Weisbecker Reviewed-by: Thomas Gleixner --- kernel/time/tick-sched.c | 96 +++++++++++++++------------------------- 1 file changed, 36 insertions(+), 60 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index d4901654148d..88c992f48126 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -255,6 +255,40 @@ static void tick_sched_handle(struct tick_sched *ts, struct pt_regs *regs) update_process_times(user_mode(regs)); profile_tick(CPU_PROFILING); } + +/* + * We rearm the timer until we get disabled by the idle code. + * Called with interrupts disabled. + */ +static enum hrtimer_restart tick_nohz_handler(struct hrtimer *timer) +{ + struct tick_sched *ts = container_of(timer, struct tick_sched, sched_timer); + struct pt_regs *regs = get_irq_regs(); + ktime_t now = ktime_get(); + + tick_sched_do_timer(ts, now); + + /* + * Do not call when we are not in IRQ context and have + * no valid 'regs' pointer + */ + if (regs) + tick_sched_handle(ts, regs); + else + ts->next_tick = 0; + + /* + * In dynticks mode, tick reprogram is deferred: + * - to the idle task if in dynticks-idle + * - to IRQ exit if in full-dynticks. + */ + if (unlikely(ts->tick_stopped)) + return HRTIMER_NORESTART; + + hrtimer_forward(timer, now, TICK_NSEC); + + return HRTIMER_RESTART; +} #endif #ifdef CONFIG_NO_HZ_FULL @@ -1429,31 +1463,15 @@ void tick_nohz_idle_exit(void) * at the clockevent level. hrtimer can't be used instead, because its * infrastructure actually relies on the tick itself as a backend in * low-resolution mode (see hrtimer_run_queues()). - * - * This low-resolution handler still makes use of some hrtimer APIs meanwhile - * for convenience with expiration calculation and forwarding. */ static void tick_nohz_lowres_handler(struct clock_event_device *dev) { struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); - struct pt_regs *regs = get_irq_regs(); - ktime_t now = ktime_get(); dev->next_event = KTIME_MAX; - tick_sched_do_timer(ts, now); - tick_sched_handle(ts, regs); - - /* - * In dynticks mode, tick reprogram is deferred: - * - to the idle task if in dynticks-idle - * - to IRQ exit if in full-dynticks. - */ - if (likely(!ts->tick_stopped)) { - hrtimer_forward(&ts->sched_timer, now, TICK_NSEC); + if (likely(tick_nohz_handler(&ts->sched_timer) == HRTIMER_RESTART)) tick_program_event(hrtimer_get_expires(&ts->sched_timer), 1); - } - } static inline void tick_nohz_activate(struct tick_sched *ts, int mode) @@ -1522,48 +1540,6 @@ void tick_irq_enter(void) tick_nohz_irq_enter(); } -/* - * High resolution timer specific code - */ -#ifdef CONFIG_HIGH_RES_TIMERS -/* - * We rearm the timer until we get disabled by the idle code. - * Called with interrupts disabled. - */ -static enum hrtimer_restart tick_nohz_highres_handler(struct hrtimer *timer) -{ - struct tick_sched *ts = - container_of(timer, struct tick_sched, sched_timer); - struct pt_regs *regs = get_irq_regs(); - ktime_t now = ktime_get(); - - tick_sched_do_timer(ts, now); - - /* - * Do not call when we are not in IRQ context and have - * no valid 'regs' pointer - */ - if (regs) - tick_sched_handle(ts, regs); - else - ts->next_tick = 0; - - /* - * In dynticks mode, tick reprogram is deferred: - * - to the idle task if in dynticks-idle - * - to IRQ exit if in full-dynticks. - */ - if (unlikely(ts->tick_stopped)) - return HRTIMER_NORESTART; - - hrtimer_forward(timer, now, TICK_NSEC); - - return HRTIMER_RESTART; -} -#else -#define tick_nohz_highres_handler NULL -#endif /* CONFIG_HIGH_RES_TIMERS */ - #if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS static int sched_skew_tick; @@ -1587,7 +1563,7 @@ void tick_setup_sched_timer(int mode) hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) && mode == NOHZ_MODE_HIGHRES) - ts->sched_timer.function = tick_nohz_highres_handler; + ts->sched_timer.function = tick_nohz_handler; /* Get the next period (per-CPU) */ hrtimer_set_expires(&ts->sched_timer, tick_init_jiffy_update());