From nobody Tue Dec 2 00:25:38 2025 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B15DE3195FB for ; Tue, 25 Nov 2025 11:27:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764070030; cv=none; b=UBu63t89pQhENCvAYh+UHxAHWgGFXZaKWC7rxlRyFAeuxdvHtKOYIZoU8luxHUrEV/CbkIzX3GYB6vFN3H9bSaiVV2gIiKT81OmEyEQowJPcr7RBFVMWIc23RB1+D4u/KT/ExABtT5zhKeWmOWALKtjwCiOWiM6RtGKcXgwzhiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764070030; c=relaxed/simple; bh=a/jMPuNL0LXh8mbOwFnvXiyONNtTPYp9ciUcBqd+xDc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tJtYOjeJssURFw1wSl4u04DBdrLosEcouzBTJ4X1QsWN5gtNIB9vUso+j4FvElkfuDOgpn0a4JaPxSkIFXWe6kGKfaY/QOa511RsK/QaVvdPT/IJe9VK3MMf0obcIM/ywyPsk+w9KoE6U8AAaQcxcXeJIm8qJFSREMlUVqYVV4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=da2a8GT8; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="da2a8GT8" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-37a2dcc52aeso51454961fa.0 for ; Tue, 25 Nov 2025 03:27:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1764070023; x=1764674823; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0SsQjAUBc4I4Ftomg4p9T07PlaUDAMfxP/280o2pMx8=; b=da2a8GT8Q/R45NwSk4mrwYahro3DCk5W3ATU8pvMb+HgD2OjPj0RUlSKSKTGPTqQZl JXRsha9MMwebxH4O6jRwLRyFm4Q/otynOJTV0hFpaO/aS+v+hWLoo/9icvx5/XsFrlX8 vwBMB1E4LNeDAj489Et+dB6tkpCo3lE+dBY8i+X8Y4YYtH68t2T9yRv9ckO7NSPi6uBa VwP4fjLwOeaMNixcXr7/cwLNL/N/KQ1MMoco+wGKnM/Uxrn3kimdzI8tujd8AvjIvZAZ KpZzU9MHgPzGinlOC/TYAmd1pUjhKxsI4aX+MLWp6z+BpnTLCxW+xHpdAm5p4pf9Qv3c VBeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764070023; x=1764674823; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0SsQjAUBc4I4Ftomg4p9T07PlaUDAMfxP/280o2pMx8=; b=s4skGP5t277WRhCSeWzfp1CN/OgWtLkmAFfxpQU8+e3yAbLviyDkdbKcQukkrjuT/4 N2Ivh/+a6ehXiFhTdkDA43sxYUbCUJP9KPduOOK76uFunuLsuIsa1tXeWyRefOlTa7Bm 8H+cUyWsy99QVjgp8SpUJlsfRpK9bz2WXMYx16vXwSsZH6QrHk4JoCUkvm+JBw/m7pnq fdw3sTAkPhYjBc2uf++YgDc7m166R7MHJbRNYxcBhrXG+hLlwELOtwGSOTWLhXaXjZwH XJwXVEZF6cTpqeCq1R/iCZ1cJIsarRhXqiPfEd9lzdae8rJiKzTfHdCiko+ZoXPsGTAc vEAA== X-Forwarded-Encrypted: i=1; AJvYcCXfks2G9qrsvTL9afAdIuse1INqCDlVRrWTSTsclUOGA35nhUm8GupBVGx6a6f6ugEC92WCZleMeosH0XU=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1w7VypkhPIsB8L0A1qtd1Mjoi17TRpURXSumoZVzd7YRP8Jh9 zht+0Dxmzw9Bl1WnMaBFx/efo73SJUA0fUfTkWox/Ps2Rdh7xkn0UPzAaKviXpniClk= X-Gm-Gg: ASbGncuNwl7lxItCDVfiCgwtCgSWFBgxI0iKC99vsSgvR4LNKz55rJJU+Tt3HpvJOsR vAJJI7vx9sH7SJrfT994NvYL55pHOA2RTrk8neKSSCPop+cSrogAf9Zw3qobsKFyQUVoGKoQZH0 z3E/kumjuezuts6Br08VgMvNkz/j+zLTSFdpHC/iiIeYmThJWNYAS+z90Hzz1ZSgKpnPiG6LUeX 2qjXxrMHqtlxyOHWM0WS3KMfawIW0KY/0CIVPGEbE0miHZFslTYlEf/R6s6X/66zhaZKogKmwig 6q3pHL+nVAshQb1x7bneShs6p7GhO9VjSD/s3xc8xqJKRzsN1JDRAqTc0aZXYkm0Ik37DrIRTX1 t02YJZv8h1GtkK6dKxIK/fgMg+1Oxv9Lm+n+pMlaipJTTo98RQAVn3LL576vANuxgAVClLH3NRZ 3DbyzP1T0My2r0E+gLvZa2r7vDqV7N2c7hcY312z8auwZZ5NfOkcURxlGp7gV4 X-Google-Smtp-Source: AGHT+IEFmutfa/ZxoF2Ngxs2HZf0XLR/CkiEIKyvnVme49BuzM4cktsh/YOqq0q7xYeTdoknxiJRAA== X-Received: by 2002:a05:6512:3d91:b0:594:2f72:2fa2 with SMTP id 2adb3069b0e04-596b4e4b868mr949083e87.5.1764070022707; Tue, 25 Nov 2025 03:27:02 -0800 (PST) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5969db7563fsm4993526e87.2.2025.11.25.03.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Nov 2025 03:27:01 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Vincent Guittot , Peter Zijlstra , Kevin Hilman , Pavel Machek , Len Brown , Daniel Lezcano , Maulik Shah , Prasad Sodagudi , Dhruva Gole , Deepti Jaggi , Ulf Hansson , linux-kernel@vger.kernel.org Subject: [PATCH v4 4/6] sched: idle: Respect the CPU system wakeup QoS limit for s2idle Date: Tue, 25 Nov 2025 12:26:45 +0100 Message-ID: <20251125112650.329269-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251125112650.329269-1-ulf.hansson@linaro.org> References: <20251125112650.329269-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A CPU system wakeup QoS limit may have been requested by user space. To avoid breaking this constraint when entering a low power state during s2idle, let's start to take into account the QoS limit. Acked-by: Peter Zijlstra (Intel) Reviewed-by: Dhruva Gole Reviewed-by: Kevin Hilman (TI) Tested-by: Kevin Hilman (TI) Signed-off-by: Ulf Hansson --- Changes in v4: - Added tags. Changes in v3: - Updated commit message and added ack from Peter. Changes in v2: - Rework the code to take into account the failure/error path, when we don't find a s2idle specific state. --- drivers/cpuidle/cpuidle.c | 12 +++++++----- include/linux/cpuidle.h | 6 ++++-- kernel/sched/idle.c | 12 +++++++----- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 56132e843c99..c7876e9e024f 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -184,20 +184,22 @@ static noinstr void enter_s2idle_proper(struct cpuidl= e_driver *drv, * cpuidle_enter_s2idle - Enter an idle state suitable for suspend-to-idle. * @drv: cpuidle driver for the given CPU. * @dev: cpuidle device for the given CPU. + * @latency_limit_ns: Idle state exit latency limit * * If there are states with the ->enter_s2idle callback, find the deepest = of * them and enter it with frozen tick. */ -int cpuidle_enter_s2idle(struct cpuidle_driver *drv, struct cpuidle_device= *dev) +int cpuidle_enter_s2idle(struct cpuidle_driver *drv, struct cpuidle_device= *dev, + u64 latency_limit_ns) { int index; =20 /* - * Find the deepest state with ->enter_s2idle present, which guarantees - * that interrupts won't be enabled when it exits and allows the tick to - * be frozen safely. + * Find the deepest state with ->enter_s2idle present that meets the + * specified latency limit, which guarantees that interrupts won't be + * enabled when it exits and allows the tick to be frozen safely. */ - index =3D find_deepest_state(drv, dev, U64_MAX, 0, true); + index =3D find_deepest_state(drv, dev, latency_limit_ns, 0, true); if (index > 0) { enter_s2idle_proper(drv, dev, index); local_irq_enable(); diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index a9ee4fe55dcf..4073690504a7 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -248,7 +248,8 @@ extern int cpuidle_find_deepest_state(struct cpuidle_dr= iver *drv, struct cpuidle_device *dev, u64 latency_limit_ns); extern int cpuidle_enter_s2idle(struct cpuidle_driver *drv, - struct cpuidle_device *dev); + struct cpuidle_device *dev, + u64 latency_limit_ns); extern void cpuidle_use_deepest_state(u64 latency_limit_ns); #else static inline int cpuidle_find_deepest_state(struct cpuidle_driver *drv, @@ -256,7 +257,8 @@ static inline int cpuidle_find_deepest_state(struct cpu= idle_driver *drv, u64 latency_limit_ns) {return -ENODEV; } static inline int cpuidle_enter_s2idle(struct cpuidle_driver *drv, - struct cpuidle_device *dev) + struct cpuidle_device *dev, + u64 latency_limit_ns) {return -ENODEV; } static inline void cpuidle_use_deepest_state(u64 latency_limit_ns) { diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index c39b089d4f09..c1c3d0166610 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -131,12 +131,13 @@ void __cpuidle default_idle_call(void) } =20 static int call_cpuidle_s2idle(struct cpuidle_driver *drv, - struct cpuidle_device *dev) + struct cpuidle_device *dev, + u64 max_latency_ns) { if (current_clr_polling_and_test()) return -EBUSY; =20 - return cpuidle_enter_s2idle(drv, dev); + return cpuidle_enter_s2idle(drv, dev, max_latency_ns); } =20 static int call_cpuidle(struct cpuidle_driver *drv, struct cpuidle_device = *dev, @@ -205,12 +206,13 @@ static void cpuidle_idle_call(void) u64 max_latency_ns; =20 if (idle_should_enter_s2idle()) { + max_latency_ns =3D cpu_wakeup_latency_qos_limit() * + NSEC_PER_USEC; =20 - entered_state =3D call_cpuidle_s2idle(drv, dev); + entered_state =3D call_cpuidle_s2idle(drv, dev, + max_latency_ns); if (entered_state > 0) goto exit_idle; - - max_latency_ns =3D U64_MAX; } else { max_latency_ns =3D dev->forced_idle_latency_limit_ns; } --=20 2.43.0