Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1266575lqb; Thu, 30 May 2024 05:43:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUYY9xbSmxw7hlzyU6/CDHOho3rJGsCFfM3OPF/DtRP9DNSxjDHmIGxHD9fW2K4noHgXg2AtUMqlrzONbZDLK0hvcRYBOrh3rm7SMUo6Q== X-Google-Smtp-Source: AGHT+IH9WMHFUgJ9vu3Y6BtNUrJnKg8nXQJkLAtZjp75ua0LvoGlly+DEFXDvrjN0OdHRyq6Ye6F X-Received: by 2002:a05:6358:c9b:b0:199:2807:7f92 with SMTP id e5c5f4694b2df-199b94c7036mr217853355d.10.1717073033536; Thu, 30 May 2024 05:43:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717073033; cv=pass; d=google.com; s=arc-20160816; b=oc354XN23mpucCTnTAmft4eQ+CWPH+v0tM3u4IFB6ygDGa0IqEgpkhewbBKOQQE3Ru sZ7umFBQ349mUJcCp3OxwTazBf+iw6vsD5N7q03EGjiOhO2O9/6T+J520N5efVPOuaub YNwRcm4PT+1o5xR3zUaVCfz2/o5Gy3XctP2rrW56BPvLlfwAfDTF4RfB+pAHNP6UliZb PXpC23ELclfWYy14bCRFX8BG7nD3j9lOdaPTwuEdzAfmao6hUSJowNIW97isonKTemK+ dKNabdCidPXqqX3lxt1gwqlCePfODFNhO/OGpSXn4rbRguJl/FSdNTW3VYUIs/1igf+g vG2g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:subject:cc:to:from :date:dkim-signature; bh=uekMYU9dsE6UOZKdasq/PXY2idUK8eOtyfiH2Ns6Eq4=; fh=ZY6XUMjfT1Qzf0IznVU6MTPL2sNKjz4jmbjorW+MssE=; b=CiA9CEifc/YsZjXuOv7FdsaXpqYNtMixzUlMS0bg5yMsqx4K5udFBnIMIW/RECht+i m4RPm7l+Z6hkUCQtMRp0Ir1rxJaPbeR7w1TBvCG5UZeaQKgJ7zvgBUIOmeeXhX2K0/L5 BCOSt+DDEoKklvQcJShhdWTXzDC/oidbafCFyfQTerTu4t0sQsuJ9133zouK1yVddE27 Z9UHWCWr3taNFB2S+Jf/DZFkPzbEMRpngMsDQ6WJO6DIhRkLMhXl4Z4i7AOSCCn6KNw8 QAyT/WzbEAIm7NQJ++KavCGioT26re4/qoX7zx+pV4yF33m1+vUA+Mrpgzfudq7nOxAd vfpQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=frX3mc7N; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-195377-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195377-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6bfca4c919bsi1379180a12.366.2024.05.30.05.43.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 05:43:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195377-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=@redhat.com header.s=mimecast20190719 header.b=frX3mc7N; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-195377-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195377-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 57232B21C1B for ; Thu, 30 May 2024 12:43:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 34DA2132128; Thu, 30 May 2024 12:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="frX3mc7N" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 BDE2018309F for ; Thu, 30 May 2024 12:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717073020; cv=none; b=P5MBR/OjCkDNhsc7zLN0kcnuJ9xvshGd6MyWpRK21gCQ7NMjnARTHEcu+bPjidym0HwK95j/sI5reYCo9FNeZRGUpmfUrOCCQ33mwqInk4m+rgWzlm7Gg8N9kkXnLhjpr/khaH+x9SowymPhpeeJohmcD/C3zeYC7DnjahSDFHw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717073020; c=relaxed/simple; bh=lkMzy8caYhbIm4cIkAEbOIgxXgPW2TRXMPGpe3P/zqs=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=KNXffl0IH8hj4fu+RGKZeIEzPt4w+IJiF+ClWNkG1+e3tEw2yfiEPf+TtNRf5vDO3g+rClkiEdm/m3WJAKfQBZgdZf79wwVDHgA5kW9hnWNcINFe9V8xrxhS8YVOddmIJyH6DcQOvJodO2otPpCR08d5+sei0Jpyq/fvwfYFqcY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=frX3mc7N; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717073017; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=uekMYU9dsE6UOZKdasq/PXY2idUK8eOtyfiH2Ns6Eq4=; b=frX3mc7NHpB/DUV3p2VDP/xSLJvc2Ka+uCUUiVPlxRMsdaSw9R+gCmz9D2p1cVq2eJe4N/ tlcLbx0ptF63WkPboanVXUYCnFtu+506VOaEEchHmbsrFpF3o4hAvIwYEnIqD7c1XDkYnm kZGwniQnZLTTkAV623ROlrIalVxZMQo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-524-dYmdLYK3OKq6HMHrD5f5RQ-1; Thu, 30 May 2024 08:43:34 -0400 X-MC-Unique: dYmdLYK3OKq6HMHrD5f5RQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D3F09812296; Thu, 30 May 2024 12:43:33 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.232]) by smtp.corp.redhat.com (Postfix) with SMTP id 663D22870; Thu, 30 May 2024 12:43:32 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 30 May 2024 14:42:05 +0200 (CEST) Date: Thu, 30 May 2024 14:42:03 +0200 From: Oleg Nesterov To: Thomas Gleixner Cc: Anna-Maria Behnsen , Frederic Weisbecker , Ingo Molnar , linux-kernel@vger.kernel.org Subject: [PATCH] tick: shift tick_nohz_switch_to_nohz() from tick_check_oneshot_change() to hrtimer_run_queues() Message-ID: <20240530124203.GA26990@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 hrtimer_run_queues() calls tick_check_oneshot_change() to check if we can switch to highres or nohz mode, but the current code looks very confusing to me. In the highres=n or CONFIG_HIGH_RES_TIMERS=n cases tick_check_oneshot_change() itself calls tick_nohz_switch_to_nohz() and returns zero; that is why it needs the "allow_nohz" argument, which imo also adds confusion. This patch turns tick_check_oneshot_change() into a "pure" function without arguments. hrtimer_run_queues() calls hrtimer_switch_to_hres() or tick_nohz_switch_to_nohz() depending on hrtimer_is_hres_enabled(). Signed-off-by: Oleg Nesterov --- kernel/time/hrtimer.c | 7 +++++-- kernel/time/tick-internal.h | 6 ++++-- kernel/time/tick-sched.c | 15 ++++----------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 492c14aac642..806f352b095d 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1891,8 +1891,11 @@ void hrtimer_run_queues(void) * there only sets the check bit in the tick_oneshot code, * otherwise we might deadlock vs. xtime_lock. */ - if (tick_check_oneshot_change(!hrtimer_is_hres_enabled())) { - hrtimer_switch_to_hres(); + if (tick_check_oneshot_change()) { + if (hrtimer_is_hres_enabled()) + hrtimer_switch_to_hres(); + else + tick_nohz_switch_to_nohz(); return; } diff --git a/kernel/time/tick-internal.h b/kernel/time/tick-internal.h index 5f2105e637bd..6764fbd18afd 100644 --- a/kernel/time/tick-internal.h +++ b/kernel/time/tick-internal.h @@ -111,7 +111,8 @@ extern void tick_resume_oneshot(void); static inline bool tick_oneshot_possible(void) { return true; } extern int tick_oneshot_mode_active(void); extern void tick_clock_notify(void); -extern int tick_check_oneshot_change(int allow_nohz); +extern int tick_check_oneshot_change(void); +extern void tick_nohz_switch_to_nohz(void); extern int tick_init_highres(void); #else /* !CONFIG_TICK_ONESHOT: */ static inline @@ -124,7 +125,8 @@ static inline void tick_oneshot_notify(void) { } static inline bool tick_oneshot_possible(void) { return false; } static inline int tick_oneshot_mode_active(void) { return 0; } static inline void tick_clock_notify(void) { } -static inline int tick_check_oneshot_change(int allow_nohz) { return 0; } +static inline int tick_check_oneshot_change(void) { return 0; } +static inline void tick_nohz_switch_to_nohz(void) { } #endif /* !CONFIG_TICK_ONESHOT */ /* Functions related to oneshot broadcasting */ diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 71a792cd8936..4fd70be50b7f 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1514,7 +1514,7 @@ static inline void tick_nohz_activate(struct tick_sched *ts) /** * tick_nohz_switch_to_nohz - switch to NOHZ mode */ -static void tick_nohz_switch_to_nohz(void) +void tick_nohz_switch_to_nohz(void) { if (!tick_nohz_enabled) return; @@ -1552,7 +1552,6 @@ static inline void tick_nohz_irq_enter(void) #else -static inline void tick_nohz_switch_to_nohz(void) { } static inline void tick_nohz_irq_enter(void) { } static inline void tick_nohz_activate(struct tick_sched *ts) { } @@ -1670,11 +1669,9 @@ void tick_oneshot_notify(void) * Check if a change happened, which makes oneshot possible. * * Called cyclically from the hrtimer softirq (driven by the timer - * softirq). 'allow_nohz' signals that we can switch into low-res NOHZ - * mode, because high resolution timers are disabled (either compile - * or runtime). Called with interrupts disabled. + * softirq). Called with interrupts disabled. */ -int tick_check_oneshot_change(int allow_nohz) +int tick_check_oneshot_change(void) { struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); @@ -1687,9 +1684,5 @@ int tick_check_oneshot_change(int allow_nohz) if (!timekeeping_valid_for_hres() || !tick_is_oneshot_available()) return 0; - if (!allow_nohz) - return 1; - - tick_nohz_switch_to_nohz(); - return 0; + return 1; } -- 2.25.1.362.g51ebf55