From nobody Tue Oct 7 00:32:46 2025 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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 3BE9B2F49FD for ; Wed, 16 Jul 2025 12:33:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752669229; cv=none; b=KHggvbfrbdyubA+nylJ+zT3q/EJPQQbjyK+J1G9Ysc/rJ9xGMN5W8RXzx1tmQIiHpAr+JWWPmcso7VpooVTlgOG4enbXZ2ljX+JuMSBppiHCs9rMkTT1laTi+Mabx9ogfhRoiYsmetNPtG5V+D4r8ouH2vAkc+af6Y04UXtgyZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752669229; c=relaxed/simple; bh=eAEoFvEDTvqGKJe3E3TphilXxDtGezqIPzxZRf+E1m4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o9Bo12NrdIhWS+kCrckbQ08jWtN/AZ+RdeovZSWNOej7tkDLTq+FM2P40RkWYgSQMqZU0ywt4AhRjWu+EAgzyf79tddymfO0hpR4gW06dZyW+/TfzhmSjDPWuC5UoNuNDH2BUaplAeb4zI1x3uAZ7XWS+BckIT0zUvd3oLdVIAI= 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=jBs68Z56; arc=none smtp.client-ip=209.85.208.175 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="jBs68Z56" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-32b2f5d91c8so49572771fa.0 for ; Wed, 16 Jul 2025 05:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752669225; x=1753274025; 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=OkDwg9Z86buzPjpSBkyXeXCd7fLEh0X0HNEXKRkal4k=; b=jBs68Z561BG62iY3C8TnykuSarqyjszuMarj8O/SuKAwElr6D69q7KFGCsZZAicWZP iiq0NSJMvOsc+cjng7ox78yY/nbtdCAG2A2eWkA5AEd06b8qNzNqYWejxRogJCDDx/Ud 5TPXuD+q1qnlECD4aMmjJl9md3gW2R+6SpSFR/YXNHTyib3l/TIz8nIXYM67FlvVPQgU +xiyAMuzkj6gzxe4Q4vVuaAoben3Nu1lxlH41uAfFEBQIGqAyUt58pbdJT1O0alRRCW7 syz0wNrObHMV3InbSlJQzPif6ndbVFzh4nwF8OS56R2pxpwstbWMm5kDgu99rm+u+lTh xMaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752669225; x=1753274025; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OkDwg9Z86buzPjpSBkyXeXCd7fLEh0X0HNEXKRkal4k=; b=ATMbI9/AQYbmMGMB3F7jJtB+jPr2P3HkyDdIycYjZoUN9KFi7Rni6E1yu7iXW/vtKA 1iuPvwOs54p6gM7zsYaKQBzvu7ICBAexpvTbVTsAYc/7gXMRVdbgyXm645ZYyjQy9eUn ZcyPRjkFI2hi32rCxUl6AFJoIQWrXkptSZdlG+uvzDjKXVilGY4SHxMf6u/UnPgaFk3a 0Aj0VTQQcAQkgsqMpzsFKXqCnrZjuq0F1KK6yofES2fw/y6+dDvY/bL2nmE7JbsOwh9j V8VxcUHwXGzRib1SaaS9sZ7eGLpG6NW2ci4Li3vg2+1f3vAWnn2S5hhhOAIAmExhUSHW hswA== X-Forwarded-Encrypted: i=1; AJvYcCW0gY8WZUqlwLZ4WQzwHB6/Od7OvwFhwcG1QDqCpIbyUNyfR0eP9HupOYWZ1ZAJEEfkeuyiZSSeCny9MpE=@vger.kernel.org X-Gm-Message-State: AOJu0YyDPPkx12ngujYSql2NUsG/6N8P6/6bOqMQsiWiWbv6iB1knij4 NT0edx4co4tBStfH+onwvvW12yLLkAfQ390XREpL2k5e94aKR6XEnHJQ0IGPZoA2kkA= X-Gm-Gg: ASbGnctKyhdJqeG1Vkm6Dg5cVJ+/RAP5uwqC/9NExHm32UGeqx2VPa8+tHhdkanOWJZ ZZRKT3kVDXgtMUyXNbQ8ntRN+Zrat9tMcYisSKNVRaGwyktF9hoQiOUY4Y7ud1HwfQhgFy/Pxvx hejuifd/9FLMRUrjtSZOe8AtPMEVXcDxvFqrac3OQ770bQiIiXy2yfw4/mYH7leVgMsaVH64Pbe HYWMSeakJ/g1Q42Z44dLfs4LCJzcM3ncvMiyXcVQTR4D60n00lIrHZQXkVR3RySshfTsOMUYU2g 0mxtCoRs4MdhafyjKDnixN/wqiePXkAqKHfFU1KAMpSrGZ0brMy+KDcf4My/btuLxQEBx19/S8r 8kHMmiDetvJVIiKATml5UgH5JpINyX7lw4UeoCbrAjWC+DmyHAKv28UsBhIR67TO3EvHRUsVt X-Google-Smtp-Source: AGHT+IHG98mZtuvNkqZvzA4vLTR1noVqA1xBF65Lev95RChrA7kTMsUpnxtT4HT7cd/pUSOzNKtHRQ== X-Received: by 2002:a2e:a7c1:0:b0:32c:a771:9899 with SMTP id 38308e7fff4ca-3308f4b79afmr8286091fa.9.1752669225074; Wed, 16 Jul 2025 05:33:45 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-32fa29134d4sm21136211fa.22.2025.07.16.05.33.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jul 2025 05:33:44 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Kevin Hilman , Pavel Machek , Len Brown , Daniel Lezcano , Saravana Kannan , Maulik Shah , Prasad Sodagudi , Ulf Hansson , linux-kernel@vger.kernel.org Subject: [RFC/PATCH 1/3] PM: QoS: Introduce a system-wakeup QoS limit Date: Wed, 16 Jul 2025 14:33:17 +0200 Message-ID: <20250716123323.65441-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250716123323.65441-1-ulf.hansson@linaro.org> References: <20250716123323.65441-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" Some platforms and devices supports multiple low-power-states than can be used for system-wide suspend. Today these states are selected on per subsystem basis and in most cases it's the deepest possible state that becomes selected. For some use-cases this is a problem as it isn't suitable or even breaks the system-wakeup latency constraint, when we decide to enter these deeper states during system-wide suspend. Therefore, let's introduce an interface for user-space, allowing us to specify the system-wakeup QoS limit. Subsequent changes will start taking into account the QoS limit. Signed-off-by: Ulf Hansson --- include/linux/pm_qos.h | 9 ++++ kernel/power/qos.c | 114 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/include/linux/pm_qos.h b/include/linux/pm_qos.h index 4a69d4af3ff8..5f84084f19c8 100644 --- a/include/linux/pm_qos.h +++ b/include/linux/pm_qos.h @@ -143,6 +143,15 @@ bool pm_qos_update_flags(struct pm_qos_flags *pqf, struct pm_qos_flags_request *req, enum pm_qos_req_action action, s32 val); =20 +#ifdef CONFIG_PM_SLEEP +s32 system_wakeup_latency_qos_limit(void); +#else +static inline s32 system_wakeup_latency_qos_limit(void) +{ + return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; +} +#endif + #ifdef CONFIG_CPU_IDLE s32 cpu_latency_qos_limit(void); bool cpu_latency_qos_request_active(struct pm_qos_request *req); diff --git a/kernel/power/qos.c b/kernel/power/qos.c index 4244b069442e..fb496c220ffe 100644 --- a/kernel/power/qos.c +++ b/kernel/power/qos.c @@ -209,6 +209,120 @@ bool pm_qos_update_flags(struct pm_qos_flags *pqf, return prev_value !=3D curr_value; } =20 +#ifdef CONFIG_PM_SLEEP +static struct pm_qos_constraints system_wakeup_latency_constraints =3D { + .list =3D PLIST_HEAD_INIT(system_wakeup_latency_constraints.list), + .target_value =3D PM_QOS_RESUME_LATENCY_NO_CONSTRAINT, + .default_value =3D PM_QOS_RESUME_LATENCY_NO_CONSTRAINT, + .no_constraint_value =3D PM_QOS_RESUME_LATENCY_NO_CONSTRAINT, + .type =3D PM_QOS_MIN, +}; + +/** + * system_wakeup_latency_qos_limit - Current system wakeup latency QoS lim= it. + * + * Returns the current system wakeup latency QoS limit that may have been + * requested by user-space. + */ +s32 system_wakeup_latency_qos_limit(void) +{ + return pm_qos_read_value(&system_wakeup_latency_constraints); +} + +static int system_wakeup_latency_qos_open(struct inode *inode, + struct file *filp) +{ + struct pm_qos_request *req; + + req =3D kzalloc(sizeof(*req), GFP_KERNEL); + if (!req) + return -ENOMEM; + + req->qos =3D &system_wakeup_latency_constraints; + pm_qos_update_target(req->qos, &req->node, PM_QOS_ADD_REQ, + PM_QOS_RESUME_LATENCY_NO_CONSTRAINT); + filp->private_data =3D req; + + return 0; +} + +static int system_wakeup_latency_qos_release(struct inode *inode, + struct file *filp) +{ + struct pm_qos_request *req =3D filp->private_data; + + filp->private_data =3D NULL; + pm_qos_update_target(req->qos, &req->node, PM_QOS_REMOVE_REQ, + PM_QOS_RESUME_LATENCY_NO_CONSTRAINT); + kfree(req); + + return 0; +} + +static ssize_t system_wakeup_latency_qos_read(struct file *filp, + char __user *buf, + size_t count, + loff_t *f_pos) +{ + s32 value =3D pm_qos_read_value(&system_wakeup_latency_constraints); + + return simple_read_from_buffer(buf, count, f_pos, &value, sizeof(s32)); +} + +static ssize_t system_wakeup_latency_qos_write(struct file *filp, + const char __user *buf, + size_t count, loff_t *f_pos) +{ + struct pm_qos_request *req =3D filp->private_data; + s32 value; + + if (count =3D=3D sizeof(s32)) { + if (copy_from_user(&value, buf, sizeof(s32))) + return -EFAULT; + } else { + int ret; + + ret =3D kstrtos32_from_user(buf, count, 16, &value); + if (ret) + return ret; + } + + if (value < 0) + return -EINVAL; + + pm_qos_update_target(req->qos, &req->node, PM_QOS_UPDATE_REQ, value); + + return count; +} + +static const struct file_operations system_wakeup_latency_qos_fops =3D { + .open =3D system_wakeup_latency_qos_open, + .release =3D system_wakeup_latency_qos_release, + .read =3D system_wakeup_latency_qos_read, + .write =3D system_wakeup_latency_qos_write, + .llseek =3D noop_llseek, +}; + +static struct miscdevice system_wakeup_latency_qos_miscdev =3D { + .minor =3D MISC_DYNAMIC_MINOR, + .name =3D "system_wakeup_latency", + .fops =3D &system_wakeup_latency_qos_fops, +}; + +static int __init system_wakeup_latency_qos_init(void) +{ + int ret; + + ret =3D misc_register(&system_wakeup_latency_qos_miscdev); + if (ret < 0) + pr_err("%s: %s setup failed\n", __func__, + system_wakeup_latency_qos_miscdev.name); + + return ret; +} +late_initcall(system_wakeup_latency_qos_init); +#endif /* CONFIG_PM_SLEEP */ + #ifdef CONFIG_CPU_IDLE /* Definitions related to the CPU latency QoS. */ =20 --=20 2.43.0 From nobody Tue Oct 7 00:32:46 2025 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 409692F5C35 for ; Wed, 16 Jul 2025 12:33:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752669229; cv=none; b=lv5GlbmRpSjX+ELkUI90Vveug2J8qmeQ2fjqj7e7li5JIHjLa//C365Vig0FiusfExBAixZTgwTS4cBszmnlu1AKelsYBTRZM1DQYMowhLExsouvog/AtWNTSskazLVyrZ8EZbVRaDEhQeIx0RLxAToQGY/TJyxMWDSx6a+NvAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752669229; c=relaxed/simple; bh=uMr5ewtwM88NHPIIUr3b4SgNh8FJpgI1igYb+ESENyY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GyctMayDkvIReCcXf2EOqD0RQ4IVPzdA3SVrIKEYlAGBf481QeWIN4+onlegrU3MUtWX+0KAMbxini9fdVMALbGqVNe7HPhP4UsgKTJsaxXHJIb1UPSguVvQYoHoqoAfz9ua6lYWo7MAdBEBIn/Xfgx+63vtxxLa1dHROONhQns= 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=qAd9aiKD; arc=none smtp.client-ip=209.85.167.54 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="qAd9aiKD" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-558facbc19cso5256889e87.3 for ; Wed, 16 Jul 2025 05:33:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752669226; x=1753274026; 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=ZPBtNDYnm76liocICYdzU8O0GnhwSM9tVX+/thS9jJw=; b=qAd9aiKDUr21frYvaXdCRHpf3IvsucysRiSt0c2AQsDGFWUyODW7BuWJXCQG3iT/iR zxjw2xvtyAiRhu58B8y1y4/l1RXTk12T/C1gg2SsAS5RCNMZbKl85saXutiJA7XA0NZC wI39jIs3+6D+qekQD0KOaETERt91hUzz8R/iNza4J1E+KB5WFWpd1IYsejurjeDnKV2q Cv5EZvJWkumMBeg8ZWfQx/UTr3MAsZA34OyJ8D9Tkv2vV4hrLboCh4UFHFhBzQjztmbX aqiDAa1XMFk3T5+bA6NCYYm2rhgs5zfP0tjxbtrCJj3Lii/2n3eXVxEnSLXzJjeeDeUS HqgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752669226; x=1753274026; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZPBtNDYnm76liocICYdzU8O0GnhwSM9tVX+/thS9jJw=; b=rhnQJlBJJ4cE8+x+hnEDcD2CPqHY18HsNzt+d/aOJrKiZtBJrb48Cw5LbpItHFdknR dKgjE3t/xgMIbWd7MtVpNpy3SQJPiuKUDETesTZPBMhk793bLB5IpQsLfPz7yzEZq1a+ aKEdAAKRuRcXQUU7GoyT0V3KAs66v4ud/2+iOVwJtGyb+zrMJGGY6V2aD3f8mFsnT3CY UgdXPmtrPk0Ln8at7qujvMcmt5jFEs+UALgHmc17xsst82yFIxnugQRxDjEEeInNnzEn LsCW2UjrSLWAPWQDJHytYIXKJ6rXjyeSqVghDFS2pls0a6+/Vq5HoJIt5Crw0/zPHteR 0g9A== X-Forwarded-Encrypted: i=1; AJvYcCWnPq2pilhqkkGRPjzXZUORIaD37TamM8XEe3a97RWktLSHMjn0Hv4/oOqQE3iRXjNbvxsKvBqxEuNNlBU=@vger.kernel.org X-Gm-Message-State: AOJu0YwM/zYJFEgG7u5+ZJf0V7Vs5kqhLTkXtPrqEg8pLYAAedTHv/+a jwYLRimflOFqEMzu7zYg8HymqecblKcddee1Rssxa72qllbk1WYysD+vlFpzSIlxrVg= X-Gm-Gg: ASbGncsIq9mHvE9wtcWVKeXPavxrRdxLM8pfrSnSNhGeiN3Xb79uzkwh4ccQcDdTWVr EAV54Xwi7tOVsrX5MkQmNjhDCHXat5LBxvFD0FUo8y8m+OH1Q/rrGxjnHn9iaih4Mxe8amNnM4S ZOJs1RwB+UqMvt0QHGNpz/5dGySIQNFii/iZh/DhmoYBbxCJ2IdnVv/No6a7GTNSYu+huXi0GxT h0gAZYUfofhJHPvUmLxOWM+sG6IOVrlzQ3QYxaEc/1b25z41be4Q7dVFVyEzp8ItmgkNJE9NALn ra1J7r7oBbsCBbF4xVSXy7/+vMkLDgKHAfay0JVCCkuxM1CGZCGJz1+9SOKHeuTD4CGTfuGJVqv ownScE1SwKcr7ceHArCweR/1BYuPEK5XcbplwnptqziOocT80oMhP71vwopqEeoj4CFl637le X-Google-Smtp-Source: AGHT+IGRhItw3Rx9uduPizZnNMfo3XdSdJYBSLoV85/Au8cZvRZ7HllLBaEgOBko+rtbJAjBxkRJaw== X-Received: by 2002:a05:6512:1041:b0:553:2f72:9ce0 with SMTP id 2adb3069b0e04-55a23f964afmr762602e87.52.1752669226288; Wed, 16 Jul 2025 05:33:46 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-32fa29134d4sm21136211fa.22.2025.07.16.05.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jul 2025 05:33:45 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Kevin Hilman , Pavel Machek , Len Brown , Daniel Lezcano , Saravana Kannan , Maulik Shah , Prasad Sodagudi , Ulf Hansson , linux-kernel@vger.kernel.org Subject: [RFC/PATCH 2/3] pmdomain: Respect the system-wakeup QoS limit at system-wide suspend Date: Wed, 16 Jul 2025 14:33:18 +0200 Message-ID: <20250716123323.65441-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250716123323.65441-1-ulf.hansson@linaro.org> References: <20250716123323.65441-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 system-wakeup QoS limit may have been requested by user-space. To avoid entering a too deep state for PM domains that are managed my genpd, let's start to take into account the QoS limit when selecting the low-power-state. If it turns out that none of the states in the list of domain-idlestates are suitable to use, let's leave the PM domain powered-on. Signed-off-by: Ulf Hansson --- drivers/pmdomain/core.c | 10 ++++++++-- drivers/pmdomain/governor.c | 23 +++++++++++++++++++++++ include/linux/pm_domain.h | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c index a86aeda1c955..5cbe7473c2b9 100644 --- a/drivers/pmdomain/core.c +++ b/drivers/pmdomain/core.c @@ -1396,8 +1396,14 @@ static void genpd_sync_power_off(struct generic_pm_d= omain *genpd, bool use_lock, return; } =20 - /* Choose the deepest state when suspending */ - genpd->state_idx =3D genpd->state_count - 1; + if (genpd->gov && genpd->gov->system_power_down_ok) { + if (!genpd->gov->system_power_down_ok(&genpd->domain)) + return; + } else { + /* Default to the deepest state. */ + genpd->state_idx =3D genpd->state_count - 1; + } + if (_genpd_power_off(genpd, false)) { genpd->states[genpd->state_idx].rejected++; return; diff --git a/drivers/pmdomain/governor.c b/drivers/pmdomain/governor.c index 39359811a930..2630ba6f28ef 100644 --- a/drivers/pmdomain/governor.c +++ b/drivers/pmdomain/governor.c @@ -343,6 +343,27 @@ static bool default_power_down_ok(struct dev_pm_domain= *pd) return _default_power_down_ok(pd, ktime_get()); } =20 +static bool default_system_power_down_ok(struct dev_pm_domain *pd) +{ + s64 constraint_ns =3D system_wakeup_latency_qos_limit() * NSEC_PER_USEC; + struct generic_pm_domain *genpd =3D pd_to_genpd(pd); + int state_idx =3D genpd->state_count - 1; + + /* Find the deepest state for the latency constraint. */ + while (state_idx >=3D 0) { + s64 latency_ns =3D genpd->states[state_idx].power_off_latency_ns + + genpd->states[state_idx].power_on_latency_ns; + + if (latency_ns <=3D constraint_ns) { + genpd->state_idx =3D state_idx; + return true; + } + state_idx--; + } + + return false; +} + #ifdef CONFIG_CPU_IDLE static bool cpu_power_down_ok(struct dev_pm_domain *pd) { @@ -418,12 +439,14 @@ static bool cpu_power_down_ok(struct dev_pm_domain *p= d) struct dev_power_governor pm_domain_cpu_gov =3D { .suspend_ok =3D default_suspend_ok, .power_down_ok =3D cpu_power_down_ok, + .system_power_down_ok =3D default_system_power_down_ok, }; #endif =20 struct dev_power_governor simple_qos_governor =3D { .suspend_ok =3D default_suspend_ok, .power_down_ok =3D default_power_down_ok, + .system_power_down_ok =3D default_system_power_down_ok, }; =20 /* diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 99556589f45e..0ad14cc4ad7f 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -140,6 +140,7 @@ enum genpd_sync_state { }; =20 struct dev_power_governor { + bool (*system_power_down_ok)(struct dev_pm_domain *domain); bool (*power_down_ok)(struct dev_pm_domain *domain); bool (*suspend_ok)(struct device *dev); }; --=20 2.43.0 From nobody Tue Oct 7 00:32:46 2025 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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 5CAC02F5C40 for ; Wed, 16 Jul 2025 12:33:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752669231; cv=none; b=m4xmjxJ5CxnYKvxS/3EH9A7BzdDheqTnPjyM8MAGvpr3+BlaHrqyY2QY3DGoZ9w/Z21TSu+gLfE7TKMZqQn+oDhdNFx3VlTeS+uQlRmNiWBUfczydLpgxEUTzOqaDz3bO+g23dcsaqfsTNmBNiXwonloSF/6QReMEJNxJuw015A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752669231; c=relaxed/simple; bh=l66YMhhyoUq/kOfTDxnT5FpNrTVvUcvvqXdHjhPBswk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HQ/64DRVRPUumhsr2YDqXH5ZB9MOPEgkLQlcq3x9enbOR3TR0WH4KXTOPgQT1WQ+e6GKhFdfcETmPlvnjfljReAHxIWXCPNaITHizwJ0cn24nVAQ0cOLJiyIqMT2/1LXfC8mOmiMUr/XmCVT0OHuDxxuyJSXwxxds9sMDDLsCMI= 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=aFUkxBhg; arc=none smtp.client-ip=209.85.208.175 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="aFUkxBhg" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-32b8134ef6aso58551171fa.0 for ; Wed, 16 Jul 2025 05:33:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1752669227; x=1753274027; 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=ORFGIaRZiQ2r3h2UbbHLjv8bRy43CZUiObx53cFsM7M=; b=aFUkxBhgTyF/UQHnbpmfylEUNpw02hm8LMViJ5VkKE6YZQMU6IYkJc/8l4MM00W2sv I7eVY1GehR9QwVAEmlgTTtWam1bhjuTSIPt6qxtO3wcEEF7bm1LhQJoXxY3lIbRD2Pke ogXd6mJWED68dK0X2OMorVo21WH+J8+lBf2a+WRNhO1Vg6gNBFFkJWjjjmIBcT/lXI58 k8Cb+od2DMnbW2cQCyVhJRZz3CvUN1GCWWt71zUXKtDtTTsg3IT6Oey5S9PbVuotuZSt hXzDwY3EUudpXw/Dt74oQ0BefwtJH8vqH1kZidJvsSHkwbKGafjjX8NXaLoVdQ5o2cMC j4qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752669227; x=1753274027; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ORFGIaRZiQ2r3h2UbbHLjv8bRy43CZUiObx53cFsM7M=; b=hbpsKHQ/IvSzkaLnCme372E3t9nlIgHwUlGV71REeYQ1NF6QAwq8vE44HacDE8cRlT 88A1My8/Uchct+kEa8AE+HPgrZ3Yl40hYcdemTb2OK0PWwnb71qF4PkziiKVCILVGXoF lfsTN9hLvrtXKBTiEwC8LuHcy9rBDN4HlHszfb7IAyBZXamUV4/jtGcbmsNBhG5u0u+9 eqJKGgGudCFZRCoshXcYUvWdEybPOqZYRx7128DE3Z0VCZZu4p5p3BeHNLHIKskzrqYP +cCFT4Z2cJimVqI5n0PdlI+9SXm9pwY0JlE40kbj2UVQb9nXYY2d8EDazmWBkKwFAHCe R6dQ== X-Forwarded-Encrypted: i=1; AJvYcCVubPnPW2utgU5IDTebLwcDzJRH/d7HKAb4+tMurT3abzQwCMEo1cA7R7mk0y8IImyVbNI16HtZxS7GcU4=@vger.kernel.org X-Gm-Message-State: AOJu0Yy65BZqly9FfeGbMARTWILLgwpaG5Ah2taxa6xlbNp6EQADLrcW NFhP2o2fdx/dIAR84Nyl93E3PXChKfDd8IDjleFD5a93Ue9yzL9UxxqsCohGwJyTa9g= X-Gm-Gg: ASbGncu8VLbN+CwueKeaMuhjJn25abXtyiLWK41LOfMJC7Aa+/PLrOapyrR7PqhHmOM BWABeW8wrigdFWDv/w76LqfmYjb0GCkK6F/B0TCR2nASQN95IQcLPsl5l4aCrGhQgBaVOa/Wkc1 tcPG7n8xs7MOABUqIsj84vJWXN1aWIdmE/vyVEu2kRDJSEkYRYkeuSGIS3M0zuGlEUEIReqIYzC F3/MnD04JDtyNc5kV39dqggQiPfGLpdSKe2Lg4oxyrFiDiHOS4JOEfFHvJxu2t/Zz7AGkFW+2t5 F7lolzv4B5d7zba4amvyT8S/02YQyCC3vhZdTbLQwqItxeagg13GKcXsYu3O0ALTAsG+wTJ1zXh NWcI6hJ7cCrolCugwgxJBe1xIwq0yZi8Ib0VdpAaZCxnzKz9OONc0czLWEVahjPLU8+KK38fP X-Google-Smtp-Source: AGHT+IHApt9dKWWo4VZfdfPAEXf4QKxQRQ/nikIwYXMJa5THXkanpElGwpOalL+3xkUK7ywi2MDTCw== X-Received: by 2002:a05:651c:1a0a:b0:32a:8297:54c9 with SMTP id 38308e7fff4ca-3308e34fc82mr10139451fa.8.1752669227417; Wed, 16 Jul 2025 05:33:47 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-32fa29134d4sm21136211fa.22.2025.07.16.05.33.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jul 2025 05:33:46 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Kevin Hilman , Pavel Machek , Len Brown , Daniel Lezcano , Saravana Kannan , Maulik Shah , Prasad Sodagudi , Ulf Hansson , linux-kernel@vger.kernel.org Subject: [RFC/PATCH 3/3] cpuidle: Respect the system-wakeup QoS limit for s2idle Date: Wed, 16 Jul 2025 14:33:19 +0200 Message-ID: <20250716123323.65441-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250716123323.65441-1-ulf.hansson@linaro.org> References: <20250716123323.65441-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 system-wakeup QoS limit may have been requested by user-space. To avoid entering a too deep state during s2idle, let's start to take into account the QoS limit when selecting a suitable low-power-state. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 0835da449db8..5f6dacb5b134 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -190,14 +190,15 @@ static noinstr void enter_s2idle_proper(struct cpuidl= e_driver *drv, */ int cpuidle_enter_s2idle(struct cpuidle_driver *drv, struct cpuidle_device= *dev) { + u64 constraint_ns =3D system_wakeup_latency_qos_limit() * NSEC_PER_USEC; 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 + * system-wakeup QoS 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, constraint_ns, 0, true); if (index > 0) { enter_s2idle_proper(drv, dev, index); local_irq_enable(); --=20 2.43.0