Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1267016rdb; Wed, 24 Jan 2024 09:36:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfBOO/JWaCZmVZowN4ggr+/xCUNxh0kqJC18GifntXq8DQ0EDTodokybevJjCSM1B64P6X X-Received: by 2002:a05:6a21:78a4:b0:19c:711d:d0d7 with SMTP id bf36-20020a056a2178a400b0019c711dd0d7mr323776pzc.83.1706117790352; Wed, 24 Jan 2024 09:36:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706117790; cv=pass; d=google.com; s=arc-20160816; b=tCMdDuPWu8Ef9ApjggsflSJB+pnrZXN5X4KqZsf486/iyo7n8nGc4fgdJOapyDqAnd VFiPzW7ZxaPYo19YD1o1eXt1NAYklA7jqHBFimJqESAF2+GbiG76pwcrskKtQJOs07/l Ro8XBVcLod9L1+0j4FuFvyThmjfraRid/zQrj4acviU+BT+M3xwu+sv2x3Lc6mzmmmLh OZyqXv8ixKzKqAijM+UZTByzTLCaC7NQZoZuYP6M8GdoS/IEnWij0Y9a52KfzaYp6D0a 6Y3tF2/iqbMIAHozVR8rxglkqcWcYv7muZlm6bXTRZyCKozHXg9klNcFBe6RQ3RT9T4N auQQ== 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=T4oFFxrGJjvJMdipGRPgFDEw8qOVkPwwk5ZnkPIzNBU=; fh=4P8gqRLFmANjcHHSJu0T2ajtncG7F3hkmyD1v1G3zYE=; b=I8cHxaIYaM1SFX9oF8ZoHGfYScd+yV6rL3L4sLhRsxSDOLt4fxWDIDIZyupCZVQaFX bX1qGB6At3MwBAEkLOGTLV+IGjc3jWAEk7Y6AKysN1opk9MLskkDzo+4jqaj4RFXGXsz kpD3fhyUwmJ+oafG3YrGPRbi8RVz38KRO0AmZWnAJyvhvt6PCxwjg8fcguSUGZEMfUcD wohhfs4XZ32EZ2r6ln5rnfuVZaaUsvEOAvaJNoPUzZ4wwSinIx7lAmbG33R2imZhZ8uk wM+lNNiFOJxNew3H1qpVMqcgpHYa1hf5j7nDQrpBC4HM259hih3LHazbdFJypqbxZo1A yZAg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Xo3Ks91e; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-37381-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37381-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u22-20020a63ef16000000b00563de199314si12111920pgh.896.2024.01.24.09.36.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 09:36:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37381-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Xo3Ks91e; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-37381-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37381-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6C02CB296B3 for ; Wed, 24 Jan 2024 17:05:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 35606823BB; Wed, 24 Jan 2024 17:05:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Xo3Ks91e" 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 5738D81AD7 for ; Wed, 24 Jan 2024 17:05:15 +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=1706115915; cv=none; b=nkrKTWWXI54OZOH5poe2CxavT6tW90QW6iMzIvrtJydmOK7kpSFbEgXkxQukD6/UazkJ2kVpj08Bbv7E9f8nQaG55rUUx2Qp0RaFjVCSVUbZnukiXotXTW2k1Msk814y521+bTw8+vm3o5uFKFG6srfg62e+7m6m7uWb33yJJcs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706115915; c=relaxed/simple; bh=JNABFf9l7peDqU/Keofwd5fi4DbQISwry21UShiw/q4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MXPJ0cUVsDu3rGhQ8gfm85XXe4VoWdNOlOc/0gYOQECguK9Q+IF+1ShT5h56hPXtECMjNzy1F4R/pDtGV51+5+kHGIreeezvIs5IepVhlk/cMGrcVszK8e6uOzPAlD3zyzapFBB6008goEfbUwN1g19Boj80DaCj+l/07m8qhBM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xo3Ks91e; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA85AC43394; Wed, 24 Jan 2024 17:05:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706115914; bh=JNABFf9l7peDqU/Keofwd5fi4DbQISwry21UShiw/q4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xo3Ks91ecsh5kAWpzzWn/VCsbSUBy31Cy7IrMNMJ8qT4K4ItWhbuJHlVv9lp7S4ih SPxbLceATVw8ZhiElnQu9MvxclyW4/+BRhen36Z63F/IqaGKkG4zqZDEtKrvbZ/Y/i RkvCFOP5bF51av/xUGH7zAyTRS38bHy6pOE39CBoPSaSzwokrkcwGrfBo4LfjeMIj2 qlTcUeTwCRkUcHxdPURNW50i5cTlD1y58yHPQv/Q/BxlM0qG4ql9gnz2FD7J1NAUGL Oqmas3KSUEmuRhfewfJsuhluRYjR1adLecv8+QgJowfLfqVIJhvaq3WQCQvYKels1t T3YNgHklN1Dtg== From: Frederic Weisbecker To: LKML Cc: Peng Liu , Thomas Gleixner , Ingo Molnar , Anna-Maria Behnsen , Joel Fernandes , Frederic Weisbecker Subject: [PATCH 02/15] tick/nohz: Remove duplicate between lowres and highres handlers Date: Wed, 24 Jan 2024 18:04:46 +0100 Message-ID: <20240124170459.24850-3-frederic@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124170459.24850-1-frederic@kernel.org> References: <20240124170459.24850-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Signed-off-by: Peng Liu Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.c | 96 ++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 58 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index e90dbb7ae70a..6f69ae88e47e 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -255,6 +255,41 @@ 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_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; +} #endif #ifdef CONFIG_NO_HZ_FULL @@ -1392,30 +1427,17 @@ void tick_nohz_idle_exit(void) * 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. + * This low-resolution handler still reuse tick_nohz_highres_handler() since + * most of the work is independent from the clockevent level. */ 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_highres_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) @@ -1484,46 +1506,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; -} -#endif /* HIGH_RES_TIMERS */ - #if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS static int sched_skew_tick; @@ -1545,10 +1527,8 @@ void tick_setup_sched_timer(int mode) /* Emulate tick processing via per-CPU hrtimers: */ hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); -#ifdef CONFIG_HIGH_RES_TIMERS if (mode == NOHZ_MODE_HIGHRES) ts->sched_timer.function = tick_nohz_highres_handler; -#endif /* Get the next period (per-CPU) */ hrtimer_set_expires(&ts->sched_timer, tick_init_jiffy_update()); -- 2.43.0