From patchwork Wed Sep 11 04:27:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983622 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SGt586Fz1y21 for ; Wed, 11 Sep 2024 14:27:49 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExA-0003o9-1w; Wed, 11 Sep 2024 04:27:40 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soEx7-0003nc-0P for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:27:37 +0000 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (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 smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id A2BAA3F32F for ; Wed, 11 Sep 2024 04:27:36 +0000 (UTC) Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-7db02e69823so1238762a12.0 for ; Tue, 10 Sep 2024 21:27:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028855; x=1726633655; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZypwcOT1P34XEIc5DlUw59zbm036I5KIKKvM2uqtPXM=; b=OW7RetF3InpIKMst0Z3d5uCryM2VdGYa7YfdPgZpDTrKTXLLdS3RueDidvQovnxcPJ GlGNZp4SKcejhUqtA5Oolk6YDK4/miuAsvrfZmZjMGCVI0+OpdG3LM1lukl05YIAkbu/ TmqW/wYZBgk7QQqxpQS+iO/hutHhP/VPY58S5QZ8uUwqfWAOR0hw/qHeRzw6MW1dpupf 8QFLDDVIWze1i5g9gkGNS3hcnNABQpw1dGtitf9k+Tqf4Ng9jhCVE6+TL97f1wkYhs0H JHh3O70PUuAxswtnLlyBfL/1tSyTUNrbQGIDEIC04jDU6YHFIhPifGEsoqYXqy2e/nPC OOmw== X-Gm-Message-State: AOJu0YyX3qJwJcjCQ79IywAs18JFIYZv0WNTGI6SIIABRmLVxbvuWqVr laU8Uor8F13N+8VjSwRxT7V50STD6uYM7/VcdOiSYSl5O1jjcTckTE/ySon/F0UxmAVM8x855Ic deo5GQFjE9VXNzPMJZUwWehDn3YFFqLiQBrLJ9yH+/t9cdW25Gbrkaml0rfrL958kdDvVdFQbmC Fo4AQYzcAh X-Received: by 2002:a17:902:cec5:b0:205:8a1a:53df with SMTP id d9443c01a7336-2074c5d3a7emr42626315ad.20.1726028854856; Tue, 10 Sep 2024 21:27:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpWdYsOxPfb44hsaBZZok2hdOcUpEz7YmXLMfYOL4bujE/vp328dE3d6hbcAyxtCabx8lK1g== X-Received: by 2002:a17:902:cec5:b0:205:8a1a:53df with SMTP id d9443c01a7336-2074c5d3a7emr42625875ad.20.1726028854108; Tue, 10 Sep 2024 21:27:34 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20710f1d4b0sm55438985ad.189.2024.09.10.21.27.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:27:33 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 01/17] cpuidle: Consolidate disabled state checks Date: Wed, 11 Sep 2024 01:27:10 -0300 Message-Id: <20240911042726.959018-2-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/2080324 There are two reasons why CPU idle states may be disabled: either because the driver has disabled them or because they have been disabled by user space via sysfs. In the former case, the state's "disabled" flag is set once during the initialization of the driver and it is never cleared later (it is read-only effectively). In the latter case, the "disable" field of the given state's cpuidle_state_usage struct is set and it may be changed via sysfs. Thus checking whether or not an idle state has been disabled involves reading these two flags every time. In order to avoid the additional check of the state's "disabled" flag (which is effectively read-only anyway), use the value of it at the init time to set a (new) flag in the "disable" field of that state's cpuidle_state_usage structure and use the sysfs interface to manipulate another (new) flag in it. This way the state is disabled whenever the "disable" field of its cpuidle_state_usage structure is nonzero, whatever the reason, and it is the only place to look into to check whether or not the state has been disabled. Signed-off-by: Rafael J. Wysocki Acked-by: Daniel Lezcano Acked-by: Peter Zijlstra (Intel) (cherry picked from commit 99e98d3fb1008ef7416e16a1fd355cb73a253502) Signed-off-by: Marcelo Henrique Cerri --- drivers/cpuidle/cpuidle-powernv.c | 7 ++-- drivers/cpuidle/cpuidle.c | 24 +++++++------- drivers/cpuidle/governors/ladder.c | 4 +-- drivers/cpuidle/governors/menu.c | 8 ++--- drivers/cpuidle/governors/teo.c | 5 ++- drivers/cpuidle/sysfs.c | 51 ++++++++++++++++++------------ include/linux/cpuidle.h | 3 ++ 7 files changed, 54 insertions(+), 48 deletions(-) diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c index 84b1ebe212b3..1b299e801f74 100644 --- a/drivers/cpuidle/cpuidle-powernv.c +++ b/drivers/cpuidle/cpuidle-powernv.c @@ -56,13 +56,10 @@ static u64 get_snooze_timeout(struct cpuidle_device *dev, return default_snooze_timeout; for (i = index + 1; i < drv->state_count; i++) { - struct cpuidle_state *s = &drv->states[i]; - struct cpuidle_state_usage *su = &dev->states_usage[i]; - - if (s->disabled || su->disable) + if (dev->states_usage[i].disable) continue; - return s->target_residency * tb_ticks_per_usec; + return drv->states[i].target_residency * tb_ticks_per_usec; } return default_snooze_timeout; diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 73f08cda21e0..11e08ed7f4b3 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -84,12 +84,12 @@ static int find_deepest_state(struct cpuidle_driver *drv, for (i = 1; i < drv->state_count; i++) { struct cpuidle_state *s = &drv->states[i]; - struct cpuidle_state_usage *su = &dev->states_usage[i]; - if (s->disabled || su->disable || s->exit_latency <= latency_req - || s->exit_latency > max_latency - || (s->flags & forbidden_flags) - || (s2idle && !s->enter_s2idle)) + if (dev->states_usage[i].disable || + s->exit_latency <= latency_req || + s->exit_latency > max_latency || + (s->flags & forbidden_flags) || + (s2idle && !s->enter_s2idle)) continue; latency_req = s->exit_latency; @@ -266,8 +266,7 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, if (diff < drv->states[entered_state].target_residency) { for (i = entered_state - 1; i >= 0; i--) { - if (drv->states[i].disabled || - dev->states_usage[i].disable) + if (dev->states_usage[i].disable) continue; /* Shallower states are enabled, so update. */ @@ -276,8 +275,7 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, } } else if (diff > delay) { for (i = entered_state + 1; i < drv->state_count; i++) { - if (drv->states[i].disabled || - dev->states_usage[i].disable) + if (dev->states_usage[i].disable) continue; /* @@ -381,7 +379,7 @@ u64 cpuidle_poll_time(struct cpuidle_driver *drv, limit_ns = TICK_NSEC; for (i = 1; i < drv->state_count; i++) { - if (drv->states[i].disabled || dev->states_usage[i].disable) + if (dev->states_usage[i].disable) continue; limit_ns = (u64)drv->states[i].target_residency * NSEC_PER_USEC; @@ -569,12 +567,16 @@ static void __cpuidle_device_init(struct cpuidle_device *dev) */ static int __cpuidle_register_device(struct cpuidle_device *dev) { - int ret; struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); + int i, ret; if (!try_module_get(drv->owner)) return -EINVAL; + for (i = 0; i < drv->state_count; i++) + if (drv->states[i].disabled) + dev->states_usage[i].disable |= CPUIDLE_STATE_DISABLED_BY_DRIVER; + per_cpu(cpuidle_devices, dev->cpu) = dev; list_add(&dev->device_list, &cpuidle_detected_devices); diff --git a/drivers/cpuidle/governors/ladder.c b/drivers/cpuidle/governors/ladder.c index 428eeb832fe7..b0126b8c32fe 100644 --- a/drivers/cpuidle/governors/ladder.c +++ b/drivers/cpuidle/governors/ladder.c @@ -84,7 +84,6 @@ static int ladder_select_state(struct cpuidle_driver *drv, /* consider promotion */ if (last_idx < drv->state_count - 1 && - !drv->states[last_idx + 1].disabled && !dev->states_usage[last_idx + 1].disable && last_residency > last_state->threshold.promotion_time && drv->states[last_idx + 1].exit_latency <= latency_req) { @@ -98,8 +97,7 @@ static int ladder_select_state(struct cpuidle_driver *drv, /* consider demotion */ if (last_idx > first_idx && - (drv->states[last_idx].disabled || - dev->states_usage[last_idx].disable || + (dev->states_usage[last_idx].disable || drv->states[last_idx].exit_latency > latency_req)) { int i; diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index e5a5d0c8d66b..38b2b72102a8 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -298,7 +298,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, if (unlikely(drv->state_count <= 1 || latency_req == 0) || ((data->next_timer_us < drv->states[1].target_residency || latency_req < drv->states[1].exit_latency) && - !drv->states[0].disabled && !dev->states_usage[0].disable)) { + !dev->states_usage[0].disable)) { /* * In this case state[0] will be used no matter what, so return * it right away and keep the tick running if state[0] is a @@ -349,9 +349,8 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, idx = -1; for (i = 0; i < drv->state_count; i++) { struct cpuidle_state *s = &drv->states[i]; - struct cpuidle_state_usage *su = &dev->states_usage[i]; - if (s->disabled || su->disable) + if (dev->states_usage[i].disable) continue; if (idx == -1) @@ -422,8 +421,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, * tick, so try to correct that. */ for (i = idx - 1; i >= 0; i--) { - if (drv->states[i].disabled || - dev->states_usage[i].disable) + if (dev->states_usage[i].disable) continue; idx = i; diff --git a/drivers/cpuidle/governors/teo.c b/drivers/cpuidle/governors/teo.c index c71773c88890..e726bb1c6ba6 100644 --- a/drivers/cpuidle/governors/teo.c +++ b/drivers/cpuidle/governors/teo.c @@ -212,7 +212,7 @@ static int teo_find_shallower_state(struct cpuidle_driver *drv, int i; for (i = state_idx - 1; i >= 0; i--) { - if (drv->states[i].disabled || dev->states_usage[i].disable) + if (dev->states_usage[i].disable) continue; state_idx = i; @@ -257,9 +257,8 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, for (i = 0; i < drv->state_count; i++) { struct cpuidle_state *s = &drv->states[i]; - struct cpuidle_state_usage *su = &dev->states_usage[i]; - if (s->disabled || su->disable) { + if (dev->states_usage[i].disable) { /* * Ignore disabled states with target residencies beyond * the anticipated idle duration. diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c index e591f56f98c0..280ab31c1e59 100644 --- a/drivers/cpuidle/sysfs.c +++ b/drivers/cpuidle/sysfs.c @@ -255,25 +255,6 @@ static ssize_t show_state_##_name(struct cpuidle_state *state, \ return sprintf(buf, "%u\n", state->_name);\ } -#define define_store_state_ull_function(_name) \ -static ssize_t store_state_##_name(struct cpuidle_state *state, \ - struct cpuidle_state_usage *state_usage, \ - const char *buf, size_t size) \ -{ \ - unsigned long long value; \ - int err; \ - if (!capable(CAP_SYS_ADMIN)) \ - return -EPERM; \ - err = kstrtoull(buf, 0, &value); \ - if (err) \ - return err; \ - if (value) \ - state_usage->_name = 1; \ - else \ - state_usage->_name = 0; \ - return size; \ -} - #define define_show_state_ull_function(_name) \ static ssize_t show_state_##_name(struct cpuidle_state *state, \ struct cpuidle_state_usage *state_usage, \ @@ -299,11 +280,39 @@ define_show_state_ull_function(usage) define_show_state_ull_function(time) define_show_state_str_function(name) define_show_state_str_function(desc) -define_show_state_ull_function(disable) -define_store_state_ull_function(disable) define_show_state_ull_function(above) define_show_state_ull_function(below) +static ssize_t show_state_disable(struct cpuidle_state *state, + struct cpuidle_state_usage *state_usage, + char *buf) +{ + return sprintf(buf, "%llu\n", + state_usage->disable & CPUIDLE_STATE_DISABLED_BY_USER); +} + +static ssize_t store_state_disable(struct cpuidle_state *state, + struct cpuidle_state_usage *state_usage, + const char *buf, size_t size) +{ + unsigned int value; + int err; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + err = kstrtouint(buf, 0, &value); + if (err) + return err; + + if (value) + state_usage->disable |= CPUIDLE_STATE_DISABLED_BY_USER; + else + state_usage->disable &= ~CPUIDLE_STATE_DISABLED_BY_USER; + + return size; +} + define_one_state_ro(name, show_state_name); define_one_state_ro(desc, show_state_desc); define_one_state_ro(latency, show_state_exit_latency); diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index 4b6b5bea8f79..d23a3b1ddcf6 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -29,6 +29,9 @@ struct cpuidle_driver; * CPUIDLE DEVICE INTERFACE * ****************************/ +#define CPUIDLE_STATE_DISABLED_BY_USER BIT(0) +#define CPUIDLE_STATE_DISABLED_BY_DRIVER BIT(1) + struct cpuidle_state_usage { unsigned long long disable; unsigned long long usage; From patchwork Wed Sep 11 04:27:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983620 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SGt5T56z1y23 for ; Wed, 11 Sep 2024 14:27:50 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExC-0003ot-9M; Wed, 11 Sep 2024 04:27:42 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExA-0003ny-2c for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:27:40 +0000 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) (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 smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id B90783F17F for ; Wed, 11 Sep 2024 04:27:39 +0000 (UTC) Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-718e2da2e33so4832012b3a.1 for ; Tue, 10 Sep 2024 21:27:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028858; x=1726633658; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OJMc5P+ps/MIK/mTUgFY/O32cTs2FV/ZzQOrJfCExZI=; b=e+D6a6cCTE1QABGd72HvuqvPnjzmARoBgj8udMy2xWRZk3FR7hr07y9180Omo/DVjU U0drUqRvjkz7wOYp4GPbUK9lQKem8QBge479i+OHeJUle8n2dVGUnqNXFA9H4Qy84dBF NVOBBZo0mCLMuZpDBS20b8SpZ2WvtnvlrslU9K5Mn6k3iVZuHy5hv5O4NolIHoQX/8Bf nqMfepKY2nFioNrZi0duj0Yk8/XsiJ7wNHirapdBUZdsfgJHLSob+tQq6nxxrpLsrjpb ukEHlhWMrwBxDk2DPkPqwD0sEuqeXSzFBCDviVGRNTHnhi/04aD5GpXE3cfaSFOgYtEy ptmA== X-Gm-Message-State: AOJu0YyxP25YIJWJgARN1Whqjk3evYLDeJpFMvscyptlCyDXg9/weRRw LodXk0BwUtHSQQTWt7+S1pCDD/DaFGkq9ep2RUp2YhVLAC8Yq/lCCLPURzfJvNhEQ97uvVtqf92 27SHSX7oWmdhT3nnbYyjEx2knA0X811VrE6iozyGR9wSKQmO4Q7szVB0QWJeq/xedgJ3rCJGwS1 XStcpmgq++ X-Received: by 2002:aa7:8883:0:b0:714:2069:d917 with SMTP id d2e1a72fcca58-718d5f0fcccmr20666053b3a.25.1726028857968; Tue, 10 Sep 2024 21:27:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAlIMvcOVZ9oaoymO8aMkRxVORXdK5ik5AIIYgz/9YMt/aeVQCNaRzcUmkDFXPwv1w69JGXQ== X-Received: by 2002:aa7:8883:0:b0:714:2069:d917 with SMTP id d2e1a72fcca58-718d5f0fcccmr20666030b3a.25.1726028857461; Tue, 10 Sep 2024 21:27:37 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-719090c1b2dsm2122047b3a.185.2024.09.10.21.27.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:27:37 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 02/17] cpuidle: Introduce cpuidle_driver_state_disabled() for driver quirks Date: Wed, 11 Sep 2024 01:27:11 -0300 Message-Id: <20240911042726.959018-3-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/2080324 Commit 99e98d3fb100 ("cpuidle: Consolidate disabled state checks") overlooked the fact that the imx6q and tegra20 cpuidle drivers use the "disabled" field in struct cpuidle_state for quirks which trigger after the initialization of cpuidle, so reading the initial value of that field is not sufficient for those drivers. In order to allow them to implement the quirks without using the "disabled" field in struct cpuidle_state, introduce a new helper function and modify them to use it. Fixes: 99e98d3fb100 ("cpuidle: Consolidate disabled state checks") Reported-by: Len Brown Signed-off-by: Rafael J. Wysocki (cherry picked from commit cbda56d5fefcebc01448982a55836c88a825b34c) Signed-off-by: Marcelo Henrique Cerri --- arch/arm/mach-imx/cpuidle-imx6q.c | 4 ++-- arch/arm/mach-tegra/cpuidle-tegra20.c | 2 +- drivers/cpuidle/driver.c | 28 +++++++++++++++++++++++++++ include/linux/cpuidle.h | 4 ++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/arch/arm/mach-imx/cpuidle-imx6q.c b/arch/arm/mach-imx/cpuidle-imx6q.c index 39a7d9393641..24dd5bbe60e4 100644 --- a/arch/arm/mach-imx/cpuidle-imx6q.c +++ b/arch/arm/mach-imx/cpuidle-imx6q.c @@ -62,13 +62,13 @@ static struct cpuidle_driver imx6q_cpuidle_driver = { */ void imx6q_cpuidle_fec_irqs_used(void) { - imx6q_cpuidle_driver.states[1].disabled = true; + cpuidle_driver_state_disabled(&imx6q_cpuidle_driver, 1, true); } EXPORT_SYMBOL_GPL(imx6q_cpuidle_fec_irqs_used); void imx6q_cpuidle_fec_irqs_unused(void) { - imx6q_cpuidle_driver.states[1].disabled = false; + cpuidle_driver_state_disabled(&imx6q_cpuidle_driver, 1, false); } EXPORT_SYMBOL_GPL(imx6q_cpuidle_fec_irqs_unused); diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c index 2447427cb4a8..69f3fa270fbe 100644 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c @@ -203,7 +203,7 @@ void tegra20_cpuidle_pcie_irqs_in_use(void) { pr_info_once( "Disabling cpuidle LP2 state, since PCIe IRQs are in use\n"); - tegra_idle_driver.states[1].disabled = true; + cpuidle_driver_state_disabled(&tegra_idle_driver, 1, true); } int __init tegra20_cpuidle_init(void) diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c index 9db154224999..fb904ff05256 100644 --- a/drivers/cpuidle/driver.c +++ b/drivers/cpuidle/driver.c @@ -378,3 +378,31 @@ void cpuidle_driver_unref(void) spin_unlock(&cpuidle_driver_lock); } + +/** + * cpuidle_driver_state_disabled - Disable or enable an idle state + * @drv: cpuidle driver owning the state + * @idx: State index + * @disable: Whether or not to disable the state + */ +void cpuidle_driver_state_disabled(struct cpuidle_driver *drv, int idx, + bool disable) +{ + unsigned int cpu; + + mutex_lock(&cpuidle_lock); + + for_each_cpu(cpu, drv->cpumask) { + struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu); + + if (!dev) + continue; + + if (disable) + dev->states_usage[idx].disable |= CPUIDLE_STATE_DISABLED_BY_DRIVER; + else + dev->states_usage[idx].disable &= ~CPUIDLE_STATE_DISABLED_BY_DRIVER; + } + + mutex_unlock(&cpuidle_lock); +} diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index d23a3b1ddcf6..4450f64e6ddf 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -147,6 +147,8 @@ extern int cpuidle_register_driver(struct cpuidle_driver *drv); extern struct cpuidle_driver *cpuidle_get_driver(void); extern struct cpuidle_driver *cpuidle_driver_ref(void); extern void cpuidle_driver_unref(void); +extern void cpuidle_driver_state_disabled(struct cpuidle_driver *drv, int idx, + bool disable); extern void cpuidle_unregister_driver(struct cpuidle_driver *drv); extern int cpuidle_register_device(struct cpuidle_device *dev); extern void cpuidle_unregister_device(struct cpuidle_device *dev); @@ -184,6 +186,8 @@ static inline int cpuidle_register_driver(struct cpuidle_driver *drv) static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; } static inline struct cpuidle_driver *cpuidle_driver_ref(void) {return NULL; } static inline void cpuidle_driver_unref(void) {} +static inline void cpuidle_driver_state_disabled(struct cpuidle_driver *drv, + int idx, bool disable) { } static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { } static inline int cpuidle_register_device(struct cpuidle_device *dev) {return -ENODEV; } From patchwork Wed Sep 11 04:27:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983623 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SGy1FsKz1y1C for ; Wed, 11 Sep 2024 14:27:54 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExF-0003rz-N7; Wed, 11 Sep 2024 04:27:45 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExE-0003qF-0H for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:27:44 +0000 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (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 smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id C7FFD3F12E for ; Wed, 11 Sep 2024 04:27:43 +0000 (UTC) Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-71791a81824so6095828b3a.0 for ; Tue, 10 Sep 2024 21:27:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028862; x=1726633662; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PJHxKKThlKMlnXC+oiJ2rmUb7RbTGDzvc+pzp/vEeXg=; b=Oy5Xt0Gmc4XrOlNOb8PN9cfcTwgVhzyTRzc0969UksiH6CFv8Nl0/Me+sTPs8z5Eli 4dgJHach/aq3CVqcVE5EfLwGkqfmfy/zu1I+p1KjITMV+36zEAxHcZ7Kw6Mgo1TOBKhq 4F8FWpqM4dCxOBjFGdKhvfKvjP+3M3s2O9xqudvQlvFYNOKRznYA2rB1G+WGd9qrxLpx sdUOx0JU2/4gHxDMfX+2WJmd1wcCL1jWLwFfkPZZU1qYsawPgKJYXNYCMkX3dqYAieNm hbzUYB1VdHdNc2XUDH4GDDeDk1RhBf6cM0doHUk6MnRTeuRrfWN1NxAcc37I+d0UrWcv ojJg== X-Gm-Message-State: AOJu0YyXUS5PD84KxAuXrIu4oxdBBJbr92tSG1au1dYOvi6RimTpPcE6 dD7GwsMWoFapLFJ7pKfTA1TG6oCAF+JA2B1B3wOFQ1Bziv0M3+KR6qrB3wuKRMgTehgAIaJf5nS MpxBTY3P1mWk4XhOxugnXMONIr8IZIPtcpivSx2YBZ7OcQf3VHmn7CbOb5EzUfuJCfU8ItC4ubG mgbCmxr0JK X-Received: by 2002:a05:6a00:139d:b0:714:43d2:920f with SMTP id d2e1a72fcca58-718d5f072cbmr18732738b3a.25.1726028862075; Tue, 10 Sep 2024 21:27:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNzycHGqcWdKmsxpxr7BdpTe2IlNE85mcThwsxLgGokKY22jw+021/hbs2eotgy+g+huw4qw== X-Received: by 2002:a05:6a00:139d:b0:714:43d2:920f with SMTP id d2e1a72fcca58-718d5f072cbmr18732716b3a.25.1726028861534; Tue, 10 Sep 2024 21:27:41 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-719090ad428sm2191307b3a.142.2024.09.10.21.27.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:27:41 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 03/17] cpuidle: Drop disabled field from struct cpuidle_state Date: Wed, 11 Sep 2024 01:27:12 -0300 Message-Id: <20240911042726.959018-4-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/2080324 After recent cpuidle updates the "disabled" field in struct cpuidle_state is only used by two drivers (intel_idle and shmobile cpuidle) for marking unusable idle states, but that may as well be achieved with the help of a state flag, so define an "unusable" idle state flag, CPUIDLE_FLAG_UNUSABLE, make the drivers in question use it instead of the "disabled" field and make the core set CPUIDLE_STATE_DISABLED_BY_DRIVER for the idle states with that flag set. After the above changes, the "disabled" field in struct cpuidle_state is not used any more, so drop it. No intentional functional impact. Signed-off-by: Rafael J. Wysocki (cherry picked from commit ba1e78a1dc0ca3e92f0be82279e6ba24177af7d6) Signed-off-by: Marcelo Henrique Cerri --- arch/sh/kernel/cpu/shmobile/cpuidle.c | 8 ++++---- drivers/cpuidle/cpuidle.c | 2 +- drivers/cpuidle/poll_state.c | 1 - drivers/idle/intel_idle.c | 6 +++--- include/linux/cpuidle.h | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/arch/sh/kernel/cpu/shmobile/cpuidle.c b/arch/sh/kernel/cpu/shmobile/cpuidle.c index dbd2cdec2ddb..b0f9c8f8fd14 100644 --- a/arch/sh/kernel/cpu/shmobile/cpuidle.c +++ b/arch/sh/kernel/cpu/shmobile/cpuidle.c @@ -67,7 +67,7 @@ static struct cpuidle_driver cpuidle_driver = { .enter = cpuidle_sleep_enter, .name = "C2", .desc = "SuperH Sleep Mode [SF]", - .disabled = true, + .flags = CPUIDLE_FLAG_UNUSABLE, }, { .exit_latency = 2300, @@ -76,7 +76,7 @@ static struct cpuidle_driver cpuidle_driver = { .enter = cpuidle_sleep_enter, .name = "C3", .desc = "SuperH Mobile Standby Mode [SF]", - .disabled = true, + .flags = CPUIDLE_FLAG_UNUSABLE, }, }, .safe_state_index = 0, @@ -86,10 +86,10 @@ static struct cpuidle_driver cpuidle_driver = { int __init sh_mobile_setup_cpuidle(void) { if (sh_mobile_sleep_supported & SUSP_SH_SF) - cpuidle_driver.states[1].disabled = false; + cpuidle_driver.states[1].flags = CPUIDLE_FLAG_NONE; if (sh_mobile_sleep_supported & SUSP_SH_STANDBY) - cpuidle_driver.states[2].disabled = false; + cpuidle_driver.states[2].flags = CPUIDLE_FLAG_NONE; return cpuidle_register(&cpuidle_driver, NULL); } diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 11e08ed7f4b3..f0559c0e46c9 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -574,7 +574,7 @@ static int __cpuidle_register_device(struct cpuidle_device *dev) return -EINVAL; for (i = 0; i < drv->state_count; i++) - if (drv->states[i].disabled) + if (drv->states[i].flags & CPUIDLE_FLAG_UNUSABLE) dev->states_usage[i].disable |= CPUIDLE_STATE_DISABLED_BY_DRIVER; per_cpu(cpuidle_devices, dev->cpu) = dev; diff --git a/drivers/cpuidle/poll_state.c b/drivers/cpuidle/poll_state.c index c8fa5f41dfc4..642cbdfe9874 100644 --- a/drivers/cpuidle/poll_state.c +++ b/drivers/cpuidle/poll_state.c @@ -51,7 +51,6 @@ void cpuidle_poll_state_init(struct cpuidle_driver *drv) state->target_residency = 0; state->power_usage = -1; state->enter = poll_idle; - state->disabled = false; state->flags = CPUIDLE_FLAG_POLLING; } EXPORT_SYMBOL_GPL(cpuidle_poll_state_init); diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c index 63b221226261..945afa633345 100644 --- a/drivers/idle/intel_idle.c +++ b/drivers/idle/intel_idle.c @@ -1317,8 +1317,8 @@ static void sklh_idle_state_table_update(void) return; } - skl_cstates[5].disabled = 1; /* C8-SKL */ - skl_cstates[6].disabled = 1; /* C9-SKL */ + skl_cstates[5].flags |= CPUIDLE_FLAG_UNUSABLE; /* C8-SKL */ + skl_cstates[6].flags |= CPUIDLE_FLAG_UNUSABLE; /* C9-SKL */ } /* * intel_idle_state_table_update() @@ -1381,7 +1381,7 @@ static void __init intel_idle_cpuidle_driver_init(void) continue; /* if state marked as disabled, skip it */ - if (cpuidle_state_table[cstate].disabled != 0) { + if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_UNUSABLE) { pr_debug("state %s is disabled\n", cpuidle_state_table[cstate].name); continue; diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index 4450f64e6ddf..68eeb0a308cc 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -52,7 +52,6 @@ struct cpuidle_state { unsigned int exit_latency; /* in US */ int power_usage; /* in mW */ unsigned int target_residency; /* in US */ - bool disabled; /* disabled on all CPUs */ int (*enter) (struct cpuidle_device *dev, struct cpuidle_driver *drv, @@ -75,6 +74,7 @@ struct cpuidle_state { #define CPUIDLE_FLAG_POLLING BIT(0) /* polling state */ #define CPUIDLE_FLAG_COUPLED BIT(1) /* state applies to multiple cpus */ #define CPUIDLE_FLAG_TIMER_STOP BIT(2) /* timer is stopped on this state */ +#define CPUIDLE_FLAG_UNUSABLE BIT(3) /* avoid using this state */ struct cpuidle_device_kobj; struct cpuidle_state_kobj; From patchwork Wed Sep 11 04:27:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983624 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SH04jHpz1y1C for ; Wed, 11 Sep 2024 14:27:56 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExI-0003vx-Um; Wed, 11 Sep 2024 04:27:48 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExH-0003tw-Im for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:27:47 +0000 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 2FE393F12E for ; Wed, 11 Sep 2024 04:27:47 +0000 (UTC) Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-7db1762d70fso31409a12.2 for ; Tue, 10 Sep 2024 21:27:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028865; x=1726633665; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CunWbNwDUWaGJJPWVl6dpJfT+aHH9sr1VrwpfRJXNU0=; b=cd2mNP5ts4iIlywGf2YeVU68vqQTqW1LGSX0jNcszOO1/NPbHJmiUdwoFnZpBB3jze SPXKe4b8h72ILD5Efovo/c1vdHL1kd4oyN63C/1JOHZBPUVexQT6tFe42xZEl9SWV0+/ 1n7GokEofzT4mR4AN6ACZtLTcsUOKg15BrKT0Ux0IdKDRSstKBSkySAMrqgIpdWlmd1i HUTMBOOzccOaheYu9cOtXxF8P8Di7ggJrVeaTxWhdD9F9FC0q0iPfeimB+vfiJbhxoND rDcI/ryKqZPrZJ0UiJbAybcVDp4Q+TqxBhjy8diQ6GjgLPc8rLWEtCo+YevNwA1zy7LB zfQg== X-Gm-Message-State: AOJu0YxgiREUnH8N9FkQIcauZ4hRdgX9hROSPARM9IQU0y8zyLC4M7A9 grFCHije6CndMVah57TzD/eqEhTKwvwsib/LK2+VAAYlwSHKWhB9xl+ypIdIODFz4y1VzldMEXv SNLyL4IUNr3LnjdEyR5FDOgyANVNGk466CKMnfkUPhH1BlUhQSppjZ0tbO9ES1iZxi1N8yK4PYv OQ0GV0ZmLX X-Received: by 2002:a05:6300:404c:b0:1cf:460d:8b75 with SMTP id adf61e73a8af0-1cf5e041762mr5165024637.7.1726028865464; Tue, 10 Sep 2024 21:27:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWvvuDENHM1LtXrUQxszRaplYYoFitJ0wvBTOzoCHrf56FbKAHSOnJai+Gt+T12YsvP3dJiQ== X-Received: by 2002:a05:6300:404c:b0:1cf:460d:8b75 with SMTP id adf61e73a8af0-1cf5e041762mr5164992637.7.1726028865031; Tue, 10 Sep 2024 21:27:45 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-719090af969sm2118959b3a.183.2024.09.10.21.27.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:27:44 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 04/17] ACPI: processor: Export function to claim _CST control Date: Wed, 11 Sep 2024 01:27:13 -0300 Message-Id: <20240911042726.959018-5-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/2080324 The intel_idle driver will be modified to use ACPI _CST subsequently and it will need to notify the platform firmware of that if acpi_gbl_FADT.cst_control is set, so add a routine for this purpose, acpi_processor_claim_cst_control(), to acpi_processor.c (so that it is always present which is required by intel_idle) and export it to allow the ACPI processor driver (which is modular) to call it. No intentional functional impact. Signed-off-by: Rafael J. Wysocki (cherry picked from commit bc94638886ab21f8247d3f7f39573d3feb7d8284) Signed-off-by: Marcelo Henrique Cerri --- drivers/acpi/acpi_processor.c | 25 +++++++++++++++++++++++++ drivers/acpi/processor_idle.c | 12 ++++-------- include/linux/acpi.h | 6 ++++++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c index 2c4dda0787e8..8a53f3c5b70e 100644 --- a/drivers/acpi/acpi_processor.c +++ b/drivers/acpi/acpi_processor.c @@ -705,3 +705,28 @@ void __init acpi_processor_init(void) acpi_scan_add_handler_with_hotplug(&processor_handler, "processor"); acpi_scan_add_handler(&processor_container_handler); } + +#ifdef CONFIG_ACPI_PROCESSOR_CSTATE +/** + * acpi_processor_claim_cst_control - Request _CST control from the platform. + */ +bool acpi_processor_claim_cst_control(void) +{ + static bool cst_control_claimed; + acpi_status status; + + if (!acpi_gbl_FADT.cst_control || cst_control_claimed) + return true; + + status = acpi_os_write_port(acpi_gbl_FADT.smi_command, + acpi_gbl_FADT.cst_control, 8); + if (ACPI_FAILURE(status)) { + pr_warn("ACPI: Failed to claim processor _CST control\n"); + return false; + } + + cst_control_claimed = true; + return true; +} +EXPORT_SYMBOL_GPL(acpi_processor_claim_cst_control); +#endif /* CONFIG_ACPI_PROCESSOR_CSTATE */ diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index ab21643e0685..34cc23abd038 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -966,7 +966,6 @@ static int acpi_processor_setup_cstates(struct acpi_processor *pr) static inline void acpi_processor_cstate_first_run_checks(void) { - acpi_status status; static int first_run; if (first_run) @@ -978,13 +977,10 @@ static inline void acpi_processor_cstate_first_run_checks(void) max_cstate); first_run++; - if (acpi_gbl_FADT.cst_control && !nocst) { - status = acpi_os_write_port(acpi_gbl_FADT.smi_command, - acpi_gbl_FADT.cst_control, 8); - if (ACPI_FAILURE(status)) - ACPI_EXCEPTION((AE_INFO, status, - "Notifying BIOS of _CST ability failed")); - } + if (nocst) + return; + + acpi_processor_claim_cst_control(); } #else diff --git a/include/linux/acpi.h b/include/linux/acpi.h index c708fd831565..f80bd32daa29 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -283,6 +283,12 @@ static inline bool invalid_phys_cpuid(phys_cpuid_t phys_id) /* Validate the processor object's proc_id */ bool acpi_duplicate_processor_id(int proc_id); +/* Processor _CTS control */ +#ifdef CONFIG_ACPI_PROCESSOR_CSTATE +bool acpi_processor_claim_cst_control(void); +#else +static inline bool acpi_processor_claim_cst_control(void) { return false; } +#endif #ifdef CONFIG_ACPI_HOTPLUG_CPU /* Arch dependent functions for cpu hotplug support */ From patchwork Wed Sep 11 04:27:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983625 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SH504lkz1y1C for ; Wed, 11 Sep 2024 14:28:00 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExN-00041G-4n; Wed, 11 Sep 2024 04:27:53 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExK-0003yM-Nb for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:27:50 +0000 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) (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 smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 8D8253F12E for ; Wed, 11 Sep 2024 04:27:50 +0000 (UTC) Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-718f329aefdso3999920b3a.1 for ; Tue, 10 Sep 2024 21:27:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028868; x=1726633668; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KLnO/AgdF4K3ycVsmI8AGMphNpSZtBrCUK8XrB4ALkg=; b=kdh1wL0COak0kbrfBUwniOYOkgJFGDTFDyPTUcOcbsDglFCYjuiuSIIhqMMNJwoF2A 84fCPNuZDivAQX/5yN/kbMxEmojySIm7Xb5oj6sncwvxq33zINh0AyXAjWHDndPqugf6 iaCeFCPQOAY4V8/DE6uG8GK/MtVeJ3JPzGQRvWHiXgTvtoyjXjtU6ntIKxU33WJD+06C QqslZZXg1SKjfvigun72uyJE4HLKYsWIdB+6l3lCZTcgjgtdKFNl4/94dGfbdjw87jKA EEMU16Ha+z4Gjo3zY4v+sX8n6i6Vv0gREs0J6Cc9AKAspVquBqh3B+Bqi9QG1Wl4uGoG 9Ypw== X-Gm-Message-State: AOJu0YzOE4xy61/fVEV2elM6PYbpt8NKrvYdGE1RkaAiQ4sbxjpXYfFs jdBnWY7C2SS4LO2585rVS2TmSRbWcBf4rjRZev5U4h78JmOt0aLfKlLSnOBkBsm8hcR09+HEEWT BkgLJeI5Kw70WpEbhHP5wnoWxX7U+cZxPS5qrSyLwWWx14smMDVST6tvkU+urEj5cG1IE2e9x2H qDl/XWqLWn X-Received: by 2002:a05:6a21:4a4c:b0:1cc:dd02:f8f3 with SMTP id adf61e73a8af0-1cf5e106e2emr4571034637.28.1726028868569; Tue, 10 Sep 2024 21:27:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHi12OwpNa8+9SSk21SRDV8OT70HugmnVOa4pWfLLFqHfgNNxOqiUzayaJxcrE0n2t46JuV4g== X-Received: by 2002:a05:6a21:4a4c:b0:1cc:dd02:f8f3 with SMTP id adf61e73a8af0-1cf5e106e2emr4571005637.28.1726028868160; Tue, 10 Sep 2024 21:27:48 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d823cf3a6asm6421320a12.26.2024.09.10.21.27.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:27:47 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 05/17] ACPI: processor: Introduce acpi_processor_evaluate_cst() Date: Wed, 11 Sep 2024 01:27:14 -0300 Message-Id: <20240911042726.959018-6-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/2080324 In order to separate the ACPI _CST evaluation from checks specific to the ACPI processor driver, move the majority of the acpi_processor_get_power_info_cst() function body to a new function, acpi_processor_evaluate_cst(), that will extract the C-states information from _CST output, and redefine acpi_processor_get_power_info_cst() as a wrapper around it. No intentional functional impact. Signed-off-by: Rafael J. Wysocki (cherry picked from commit 987c785319b99e32602f7f86cfae3cf9b81e402b) Signed-off-by: Marcelo Henrique Cerri --- drivers/acpi/processor_idle.c | 52 +++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 34cc23abd038..aca7c306f2cb 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -298,21 +298,17 @@ static int acpi_processor_get_power_info_default(struct acpi_processor *pr) return 0; } -static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) +static int acpi_processor_evaluate_cst(acpi_handle handle, u32 cpu, + struct acpi_processor_power *info) { + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *cst; acpi_status status; u64 count; - int current_count; + int current_count = 0; int i, ret = 0; - struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; - union acpi_object *cst; - - if (nocst) - return -ENODEV; - current_count = 0; - - status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer); + status = acpi_evaluate_object(handle, "_CST", NULL, &buffer); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No _CST, giving up\n")); return -ENODEV; @@ -336,9 +332,6 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) goto end; } - /* Tell driver that at least _CST is supported. */ - pr->flags.has_cst = 1; - for (i = 1; i <= count; i++) { union acpi_object *element; union acpi_object *obj; @@ -384,7 +377,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) cx.entry_method = ACPI_CSTATE_SYSTEMIO; if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) { if (acpi_processor_ffh_cstate_probe - (pr->id, &cx, reg) == 0) { + (cpu, &cx, reg) == 0) { cx.entry_method = ACPI_CSTATE_FFH; } else if (cx.type == ACPI_STATE_C1) { /* @@ -433,7 +426,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) continue; current_count++; - memcpy(&(pr->power.states[current_count]), &cx, sizeof(cx)); + memcpy(&info->states[current_count], &cx, sizeof(cx)); /* * We support total ACPI_PROCESSOR_MAX_POWER - 1 @@ -447,12 +440,9 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) } } - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d power states\n", - current_count)); + acpi_handle_info(handle, "Found %d idle states\n", current_count); - /* Validate number of power states discovered */ - if (current_count < 2) - ret = -EFAULT; + info->count = current_count; end: kfree(buffer.pointer); @@ -460,6 +450,28 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) return ret; } +static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) +{ + int ret; + + if (nocst) + return -ENODEV; + + ret = acpi_processor_evaluate_cst(pr->handle, pr->id, &pr->power); + if (ret) + return ret; + + /* + * It is expected that there will be at least 2 states, C1 and + * something else (C2 or C3), so fail if that is not the case. + */ + if (pr->power.count < 2) + return -EFAULT; + + pr->flags.has_cst = 1; + return 0; +} + static void acpi_processor_power_verify_c3(struct acpi_processor *pr, struct acpi_processor_cx *cx) { From patchwork Wed Sep 11 04:27:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983626 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SH85NJ5z1y1C for ; Wed, 11 Sep 2024 14:28:04 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExQ-00049F-LZ; Wed, 11 Sep 2024 04:27:56 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExP-000444-1K for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:27:55 +0000 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (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 smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 7348D3F17F for ; Wed, 11 Sep 2024 04:27:54 +0000 (UTC) Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-2d889fde2aaso7631716a91.0 for ; Tue, 10 Sep 2024 21:27:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028872; x=1726633672; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GsIvOqpK4hbw71uVaHxz0J+GjAQ+gYgSxyf9e8OQErE=; b=F4jAaFS25o1rWdHlYjbE8FmiBkndu2EkJq2/lr9GT5r23W+zs3Zb8hq0jY6cakZTkG qve+/RE06sUvJ8AnSJPe4/qqFbo79KGc3ABFTCTKL4k7LGki9qCmgX4/IZdEVzbcCHL5 etEVDM+Um47OOB88dWAxwgz4oVCfsWcK4h/+LodbeXMv/zt3ibBaNMSbKgaPFrv8/C5i oFjagLopN+EcggCjzLf5SOb4HjpH2RERMYcRF95y2IbEURzPLRzyj0hM2dd/tnVI+coN hOGpK6gMrnSp4WBEWprAWKZHRu7vheBiZZANkoYfmo3AVBmPUBjIvoMKwjmUowChfMfa euRA== X-Gm-Message-State: AOJu0YwkFd+MS3mlyfC6Af49H9C/DrxgzDN36NHMuaAuwKdLqTk350PN sZd+6gkHv/or8R4lpTL40M1OgElExmO5vZ79aF/CjwlHEwMSojSm37C0FGOyAxWuf9qL2/CAWMf vmMV7Ost1I3heEOzwXjcflC7O7CJOoZdc6O9ksZBLKkzN0jKCY0Z6Mgd7SLOdepersqHX4FvF5o XBoTQv0VUd X-Received: by 2002:a17:902:f693:b0:202:1bb6:1897 with SMTP id d9443c01a7336-2074c4ce577mr43374935ad.14.1726028872505; Tue, 10 Sep 2024 21:27:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTK+6iJWSQqf1N9h1j+9X1UpLoZE+sJI9KqwebllUseGzgH0tGi440Stnc5hFdjYL3jPVHdQ== X-Received: by 2002:a17:902:f693:b0:202:1bb6:1897 with SMTP id d9443c01a7336-2074c4ce577mr43374595ad.14.1726028871859; Tue, 10 Sep 2024 21:27:51 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20710e3368bsm55771195ad.95.2024.09.10.21.27.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:27:51 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 06/17] ACPI: processor: Clean up acpi_processor_evaluate_cst() Date: Wed, 11 Sep 2024 01:27:15 -0300 Message-Id: <20240911042726.959018-7-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/2080324 Clean up acpi_processor_evaluate_cst() in multiple ways: * Rename current_count to last_index which matches the purpose of the variable better. * Consistently use acpi_handle_*() for printing messages and make the messages cleaner. * Drop redundant parens and braces. * Rewrite and clarify comments. * Rearrange checks and drop the redundant ones. No intentional functional impact. Signed-off-by: Rafael J. Wysocki (cherry picked from commit aa659a3fca79abd9a3ca3ddc535db631b01c9a02) Signed-off-by: Marcelo Henrique Cerri --- drivers/acpi/processor_idle.c | 114 ++++++++++++++++------------------ 1 file changed, 52 insertions(+), 62 deletions(-) diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index aca7c306f2cb..90ee04177c0d 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -305,29 +305,29 @@ static int acpi_processor_evaluate_cst(acpi_handle handle, u32 cpu, union acpi_object *cst; acpi_status status; u64 count; - int current_count = 0; + int last_index = 0; int i, ret = 0; status = acpi_evaluate_object(handle, "_CST", NULL, &buffer); if (ACPI_FAILURE(status)) { - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No _CST, giving up\n")); + acpi_handle_debug(handle, "No _CST\n"); return -ENODEV; } cst = buffer.pointer; - /* There must be at least 2 elements */ - if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) { - pr_err("not enough elements in _CST\n"); + /* There must be at least 2 elements. */ + if (!cst || cst->type != ACPI_TYPE_PACKAGE || cst->package.count < 2) { + acpi_handle_warn(handle, "Invalid _CST output\n"); ret = -EFAULT; goto end; } count = cst->package.elements[0].integer.value; - /* Validate number of power states. */ + /* Validate the number of C-states. */ if (count < 1 || count != cst->package.count - 1) { - pr_err("count given by _CST is not valid\n"); + acpi_handle_warn(handle, "Inconsistent _CST data\n"); ret = -EFAULT; goto end; } @@ -338,111 +338,101 @@ static int acpi_processor_evaluate_cst(acpi_handle handle, u32 cpu, struct acpi_power_register *reg; struct acpi_processor_cx cx; + /* + * If there is not enough space for all C-states, skip the + * excess ones and log a warning. + */ + if (last_index >= ACPI_PROCESSOR_MAX_POWER - 1) { + acpi_handle_warn(handle, + "No room for more idle states (limit: %d)\n", + ACPI_PROCESSOR_MAX_POWER - 1); + break; + } + memset(&cx, 0, sizeof(cx)); - element = &(cst->package.elements[i]); + element = &cst->package.elements[i]; if (element->type != ACPI_TYPE_PACKAGE) continue; if (element->package.count != 4) continue; - obj = &(element->package.elements[0]); + obj = &element->package.elements[0]; if (obj->type != ACPI_TYPE_BUFFER) continue; reg = (struct acpi_power_register *)obj->buffer.pointer; - if (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO && - (reg->space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) - continue; - - /* There should be an easy way to extract an integer... */ - obj = &(element->package.elements[1]); + obj = &element->package.elements[1]; if (obj->type != ACPI_TYPE_INTEGER) continue; cx.type = obj->integer.value; /* - * Some buggy BIOSes won't list C1 in _CST - - * Let acpi_processor_get_power_info_default() handle them later + * There are known cases in which the _CST output does not + * contain C1, so if the type of the first state found is not + * C1, leave an empty slot for C1 to be filled in later. */ if (i == 1 && cx.type != ACPI_STATE_C1) - current_count++; + last_index = 1; cx.address = reg->address; - cx.index = current_count + 1; + cx.index = last_index + 1; - cx.entry_method = ACPI_CSTATE_SYSTEMIO; if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) { - if (acpi_processor_ffh_cstate_probe - (cpu, &cx, reg) == 0) { - cx.entry_method = ACPI_CSTATE_FFH; + if (!acpi_processor_ffh_cstate_probe(cpu, &cx, reg)) { + /* + * In the majority of cases _CST describes C1 as + * a FIXED_HARDWARE C-state, but if the command + * line forbids using MWAIT, use CSTATE_HALT for + * C1 regardless. + */ + if (cx.type == ACPI_STATE_C1 && + boot_option_idle_override == IDLE_NOMWAIT) { + cx.entry_method = ACPI_CSTATE_HALT; + snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); + } else { + cx.entry_method = ACPI_CSTATE_FFH; + } } else if (cx.type == ACPI_STATE_C1) { /* - * C1 is a special case where FIXED_HARDWARE - * can be handled in non-MWAIT way as well. - * In that case, save this _CST entry info. - * Otherwise, ignore this info and continue. + * In the special case of C1, FIXED_HARDWARE can + * be handled by executing the HLT instruction. */ cx.entry_method = ACPI_CSTATE_HALT; snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); } else { continue; } - if (cx.type == ACPI_STATE_C1 && - (boot_option_idle_override == IDLE_NOMWAIT)) { - /* - * In most cases the C1 space_id obtained from - * _CST object is FIXED_HARDWARE access mode. - * But when the option of idle=halt is added, - * the entry_method type should be changed from - * CSTATE_FFH to CSTATE_HALT. - * When the option of idle=nomwait is added, - * the C1 entry_method type should be - * CSTATE_HALT. - */ - cx.entry_method = ACPI_CSTATE_HALT; - snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); - } - } else { + } else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) { + cx.entry_method = ACPI_CSTATE_SYSTEMIO; snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI IOPORT 0x%x", cx.address); + } else { + continue; } - if (cx.type == ACPI_STATE_C1) { + if (cx.type == ACPI_STATE_C1) cx.valid = 1; - } - obj = &(element->package.elements[2]); + obj = &element->package.elements[2]; if (obj->type != ACPI_TYPE_INTEGER) continue; cx.latency = obj->integer.value; - obj = &(element->package.elements[3]); + obj = &element->package.elements[3]; if (obj->type != ACPI_TYPE_INTEGER) continue; - current_count++; - memcpy(&info->states[current_count], &cx, sizeof(cx)); - - /* - * We support total ACPI_PROCESSOR_MAX_POWER - 1 - * (From 1 through ACPI_PROCESSOR_MAX_POWER - 1) - */ - if (current_count >= (ACPI_PROCESSOR_MAX_POWER - 1)) { - pr_warn("Limiting number of power states to max (%d)\n", - ACPI_PROCESSOR_MAX_POWER); - pr_warn("Please increase ACPI_PROCESSOR_MAX_POWER if needed.\n"); - break; - } + memcpy(&info->states[++last_index], &cx, sizeof(cx)); } - acpi_handle_info(handle, "Found %d idle states\n", current_count); + acpi_handle_info(handle, "Found %d idle states\n", last_index); - info->count = current_count; + info->count = last_index; end: kfree(buffer.pointer); From patchwork Wed Sep 11 04:27:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983627 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SHB3gyKz1y1C for ; Wed, 11 Sep 2024 14:28:06 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExS-0004Cr-RQ; Wed, 11 Sep 2024 04:27:58 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExR-0004A4-2Q for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:27:57 +0000 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (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 smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 998DD3F17F for ; Wed, 11 Sep 2024 04:27:56 +0000 (UTC) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-207464a9b59so19481375ad.3 for ; Tue, 10 Sep 2024 21:27:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028875; x=1726633675; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yXjn4HqecvnxNVEa/otiintc6QPjlGVtNBcjDiEfkkM=; b=p9XGL2RvWfutQj7qkiV3JQxhr9JYOoKCH2z0ojWVWy3hEZ+LIhl536pVJJSN1/6TYc qTkVED6FK6zX3nUTVRl/UWMqyvy5ffgJ9RJyDY/XllSsl3D2HHVrOsBp+iBsIa+cTlhg ty5ka+tzEWBPravvAzWdpArRPRixzuRVHPX0xgghIwvOHQhSFK1Dj0a2rzLgbtaNfldm /M5Pg9rqPZ9aBv3d2MOzP/xhebJgbBXTzSktwheNqZmQ3TkPrZDKHTL5bzBbqeMXqsk8 IZTAOG3M/jWF0MKDM4Txw35UKhoYvszgDDP8Gx1B36sI/kXJvczk1d/58L3XEWIrDylN 7lRw== X-Gm-Message-State: AOJu0YwBlC50RK2VzXXxNCL2k4I+/BfJjKQohr3rv369Q2pVpqJMvgDL V3xjyyRXWyohQEft4H1TukLcm1hU22sQ+CRdwxps5oTPjKpsB7IDufiIMNKXIyR4rWv51Enx9ce mN3rKKPUYD84zfHmiw9lvihnC0hmfF4VGDjHruxwiJJcFLvM8QQohbVcOYaYV9DwMXzvcwKbnPv jOsQ+3AaOK X-Received: by 2002:a17:903:11c6:b0:207:14a8:4e9e with SMTP id d9443c01a7336-2074c60d7f0mr38958655ad.29.1726028875043; Tue, 10 Sep 2024 21:27:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDmhYr5qDcVQKo7qXNsvli2y89ssSiVv8QeW/Tsg4Hu1cwiOBm750xjIzQHyiH/lTYXP6oHQ== X-Received: by 2002:a17:903:11c6:b0:207:14a8:4e9e with SMTP id d9443c01a7336-2074c60d7f0mr38958555ad.29.1726028874708; Tue, 10 Sep 2024 21:27:54 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2071684aaa9sm53101245ad.8.2024.09.10.21.27.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:27:54 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 07/17] ACPI: processor: Make ACPI_PROCESSOR_CSTATE depend on ACPI_PROCESSOR Date: Wed, 11 Sep 2024 01:27:16 -0300 Message-Id: <20240911042726.959018-8-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/2080324 To avoid build errors when CONFIG_ACPI_PROCESSOR_CSTATE is set and CONFIG_ACPI_PROCESSOR is not (that may appear in randconfig builds), make the former depend on the latter. Acked-by: Len Brown Signed-off-by: Rafael J. Wysocki (cherry picked from commit 239ed06d0eefc4ee351af69bd64742ada56c4bdb) Signed-off-by: Marcelo Henrique Cerri --- drivers/acpi/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index ebe1e9e5fd81..5559ef264060 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -241,6 +241,7 @@ config ACPI_CPU_FREQ_PSS config ACPI_PROCESSOR_CSTATE def_bool y + depends on ACPI_PROCESSOR depends on IA64 || X86 config ACPI_PROCESSOR_IDLE From patchwork Wed Sep 11 04:27:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983628 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SHH27Vrz1y1C for ; Wed, 11 Sep 2024 14:28:11 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExX-0004L6-6o; Wed, 11 Sep 2024 04:28:03 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExU-0004GT-Qc for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:28:00 +0000 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (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 smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 38EE53F17F for ; Wed, 11 Sep 2024 04:28:00 +0000 (UTC) Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-205529c3402so82844725ad.0 for ; Tue, 10 Sep 2024 21:28:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028878; x=1726633678; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6mgn9A0AxCswtaIjZpdaOXuX3k+h9pCGoTs/ggQX1/s=; b=hgbENLP366r07fOIYFiX2L/v8FFGWVn0BEgT/Qtgs2VNb22ABiT/d/H2DEoMyTmOoT DVN5McKF7A23wzlSwST0Lmm5lw5jf3Sh1oLSINKRh8mOK+yJSKz40fzdoIu/2kSmZG2L 9yQH2807+gieoT9TZ6ffMo6J3ZCBO6nzjHulVRi2sqMMe4FX54jt1dAIxQGgS5rsUzmB fRoiLV9i5rAFnYbMJ1cRQ5hPJIVyjshHAN/OF2NfCbKOv/kZ7B9hGkwGm3gHoqvqWIC7 KDiE/1XGFGJ6Rb49a3Yh9ABV8ZVVn+fWwORoBXSOy913CDvvMCLeBP2OjcfOIYIR2wlc xVtw== X-Gm-Message-State: AOJu0YzqJYijzEzvTDbWXtU+XdljhcumApWxQeiztlISLJDIULHVoL8N U83zYUgZzKzQ/2j12AN8x33f42PWwoKDgbXRoIW+BCGKFTMY7sJopND0mRnpVKD/qVlaul3+V9u ImGXWurDeunI7pzw31QpU0Vx343xsGga+qwDY9l0z4wY7OvgLjevSU1Vq8RFvgA+zp/xqMzpjAE SeDpJfQSY0 X-Received: by 2002:a17:902:db01:b0:205:937f:3ac6 with SMTP id d9443c01a7336-2074c4c560bmr37145765ad.1.1726028878495; Tue, 10 Sep 2024 21:27:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IESEMU9Ae7KyeDfhDFoB8JJW7WN02g2ZXp5DfZsZ0rFwTwYYIzu7um+J9VGa65lfVrvHKQ34Q== X-Received: by 2002:a17:902:db01:b0:205:937f:3ac6 with SMTP id d9443c01a7336-2074c4c560bmr37145595ad.1.1726028877884; Tue, 10 Sep 2024 21:27:57 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20710f5274csm55546515ad.304.2024.09.10.21.27.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:27:57 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 08/17] ACPI: processor: Export acpi_processor_evaluate_cst() Date: Wed, 11 Sep 2024 01:27:17 -0300 Message-Id: <20240911042726.959018-9-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/2080324 The intel_idle driver will be modified to use ACPI _CST subsequently and it will need to call acpi_processor_evaluate_cst(), so move that function to acpi_processor.c so that it is always present (which is required by intel_idle) and export it to modules to allow the ACPI processor driver (which is modular) to call it. No intentional functional impact. Signed-off-by: Rafael J. Wysocki (cherry picked from commit 77fb4e0a559a960eb36d0b2c50c781c5492577eb) Signed-off-by: Marcelo Henrique Cerri --- drivers/acpi/acpi_processor.c | 157 ++++++++++++++++++++++++++++++++++ drivers/acpi/processor_idle.c | 142 ------------------------------ include/linux/acpi.h | 9 ++ 3 files changed, 166 insertions(+), 142 deletions(-) diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c index 8a53f3c5b70e..5379bc3f275d 100644 --- a/drivers/acpi/acpi_processor.c +++ b/drivers/acpi/acpi_processor.c @@ -729,4 +729,161 @@ bool acpi_processor_claim_cst_control(void) return true; } EXPORT_SYMBOL_GPL(acpi_processor_claim_cst_control); + +/** + * acpi_processor_evaluate_cst - Evaluate the processor _CST control method. + * @handle: ACPI handle of the processor object containing the _CST. + * @cpu: The numeric ID of the target CPU. + * @info: Object write the C-states information into. + * + * Extract the C-state information for the given CPU from the output of the _CST + * control method under the corresponding ACPI processor object (or processor + * device object) and populate @info with it. + * + * If any ACPI_ADR_SPACE_FIXED_HARDWARE C-states are found, invoke + * acpi_processor_ffh_cstate_probe() to verify them and update the + * cpu_cstate_entry data for @cpu. + */ +int acpi_processor_evaluate_cst(acpi_handle handle, u32 cpu, + struct acpi_processor_power *info) +{ + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *cst; + acpi_status status; + u64 count; + int last_index = 0; + int i, ret = 0; + + status = acpi_evaluate_object(handle, "_CST", NULL, &buffer); + if (ACPI_FAILURE(status)) { + acpi_handle_debug(handle, "No _CST\n"); + return -ENODEV; + } + + cst = buffer.pointer; + + /* There must be at least 2 elements. */ + if (!cst || cst->type != ACPI_TYPE_PACKAGE || cst->package.count < 2) { + acpi_handle_warn(handle, "Invalid _CST output\n"); + ret = -EFAULT; + goto end; + } + + count = cst->package.elements[0].integer.value; + + /* Validate the number of C-states. */ + if (count < 1 || count != cst->package.count - 1) { + acpi_handle_warn(handle, "Inconsistent _CST data\n"); + ret = -EFAULT; + goto end; + } + + for (i = 1; i <= count; i++) { + union acpi_object *element; + union acpi_object *obj; + struct acpi_power_register *reg; + struct acpi_processor_cx cx; + + /* + * If there is not enough space for all C-states, skip the + * excess ones and log a warning. + */ + if (last_index >= ACPI_PROCESSOR_MAX_POWER - 1) { + acpi_handle_warn(handle, + "No room for more idle states (limit: %d)\n", + ACPI_PROCESSOR_MAX_POWER - 1); + break; + } + + memset(&cx, 0, sizeof(cx)); + + element = &cst->package.elements[i]; + if (element->type != ACPI_TYPE_PACKAGE) + continue; + + if (element->package.count != 4) + continue; + + obj = &element->package.elements[0]; + + if (obj->type != ACPI_TYPE_BUFFER) + continue; + + reg = (struct acpi_power_register *)obj->buffer.pointer; + + obj = &element->package.elements[1]; + if (obj->type != ACPI_TYPE_INTEGER) + continue; + + cx.type = obj->integer.value; + /* + * There are known cases in which the _CST output does not + * contain C1, so if the type of the first state found is not + * C1, leave an empty slot for C1 to be filled in later. + */ + if (i == 1 && cx.type != ACPI_STATE_C1) + last_index = 1; + + cx.address = reg->address; + cx.index = last_index + 1; + + if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) { + if (!acpi_processor_ffh_cstate_probe(cpu, &cx, reg)) { + /* + * In the majority of cases _CST describes C1 as + * a FIXED_HARDWARE C-state, but if the command + * line forbids using MWAIT, use CSTATE_HALT for + * C1 regardless. + */ + if (cx.type == ACPI_STATE_C1 && + boot_option_idle_override == IDLE_NOMWAIT) { + cx.entry_method = ACPI_CSTATE_HALT; + snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); + } else { + cx.entry_method = ACPI_CSTATE_FFH; + } + } else if (cx.type == ACPI_STATE_C1) { + /* + * In the special case of C1, FIXED_HARDWARE can + * be handled by executing the HLT instruction. + */ + cx.entry_method = ACPI_CSTATE_HALT; + snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); + } else { + continue; + } + } else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) { + cx.entry_method = ACPI_CSTATE_SYSTEMIO; + snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI IOPORT 0x%x", + cx.address); + } else { + continue; + } + + if (cx.type == ACPI_STATE_C1) + cx.valid = 1; + + obj = &element->package.elements[2]; + if (obj->type != ACPI_TYPE_INTEGER) + continue; + + cx.latency = obj->integer.value; + + obj = &element->package.elements[3]; + if (obj->type != ACPI_TYPE_INTEGER) + continue; + + memcpy(&info->states[++last_index], &cx, sizeof(cx)); + } + + acpi_handle_info(handle, "Found %d idle states\n", last_index); + + info->count = last_index; + + end: + kfree(buffer.pointer); + + return ret; +} +EXPORT_SYMBOL_GPL(acpi_processor_evaluate_cst); #endif /* CONFIG_ACPI_PROCESSOR_CSTATE */ diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 90ee04177c0d..1cf0e5a1536d 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -298,148 +298,6 @@ static int acpi_processor_get_power_info_default(struct acpi_processor *pr) return 0; } -static int acpi_processor_evaluate_cst(acpi_handle handle, u32 cpu, - struct acpi_processor_power *info) -{ - struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; - union acpi_object *cst; - acpi_status status; - u64 count; - int last_index = 0; - int i, ret = 0; - - status = acpi_evaluate_object(handle, "_CST", NULL, &buffer); - if (ACPI_FAILURE(status)) { - acpi_handle_debug(handle, "No _CST\n"); - return -ENODEV; - } - - cst = buffer.pointer; - - /* There must be at least 2 elements. */ - if (!cst || cst->type != ACPI_TYPE_PACKAGE || cst->package.count < 2) { - acpi_handle_warn(handle, "Invalid _CST output\n"); - ret = -EFAULT; - goto end; - } - - count = cst->package.elements[0].integer.value; - - /* Validate the number of C-states. */ - if (count < 1 || count != cst->package.count - 1) { - acpi_handle_warn(handle, "Inconsistent _CST data\n"); - ret = -EFAULT; - goto end; - } - - for (i = 1; i <= count; i++) { - union acpi_object *element; - union acpi_object *obj; - struct acpi_power_register *reg; - struct acpi_processor_cx cx; - - /* - * If there is not enough space for all C-states, skip the - * excess ones and log a warning. - */ - if (last_index >= ACPI_PROCESSOR_MAX_POWER - 1) { - acpi_handle_warn(handle, - "No room for more idle states (limit: %d)\n", - ACPI_PROCESSOR_MAX_POWER - 1); - break; - } - - memset(&cx, 0, sizeof(cx)); - - element = &cst->package.elements[i]; - if (element->type != ACPI_TYPE_PACKAGE) - continue; - - if (element->package.count != 4) - continue; - - obj = &element->package.elements[0]; - - if (obj->type != ACPI_TYPE_BUFFER) - continue; - - reg = (struct acpi_power_register *)obj->buffer.pointer; - - obj = &element->package.elements[1]; - if (obj->type != ACPI_TYPE_INTEGER) - continue; - - cx.type = obj->integer.value; - /* - * There are known cases in which the _CST output does not - * contain C1, so if the type of the first state found is not - * C1, leave an empty slot for C1 to be filled in later. - */ - if (i == 1 && cx.type != ACPI_STATE_C1) - last_index = 1; - - cx.address = reg->address; - cx.index = last_index + 1; - - if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) { - if (!acpi_processor_ffh_cstate_probe(cpu, &cx, reg)) { - /* - * In the majority of cases _CST describes C1 as - * a FIXED_HARDWARE C-state, but if the command - * line forbids using MWAIT, use CSTATE_HALT for - * C1 regardless. - */ - if (cx.type == ACPI_STATE_C1 && - boot_option_idle_override == IDLE_NOMWAIT) { - cx.entry_method = ACPI_CSTATE_HALT; - snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); - } else { - cx.entry_method = ACPI_CSTATE_FFH; - } - } else if (cx.type == ACPI_STATE_C1) { - /* - * In the special case of C1, FIXED_HARDWARE can - * be handled by executing the HLT instruction. - */ - cx.entry_method = ACPI_CSTATE_HALT; - snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); - } else { - continue; - } - } else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) { - cx.entry_method = ACPI_CSTATE_SYSTEMIO; - snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI IOPORT 0x%x", - cx.address); - } else { - continue; - } - - if (cx.type == ACPI_STATE_C1) - cx.valid = 1; - - obj = &element->package.elements[2]; - if (obj->type != ACPI_TYPE_INTEGER) - continue; - - cx.latency = obj->integer.value; - - obj = &element->package.elements[3]; - if (obj->type != ACPI_TYPE_INTEGER) - continue; - - memcpy(&info->states[++last_index], &cx, sizeof(cx)); - } - - acpi_handle_info(handle, "Found %d idle states\n", last_index); - - info->count = last_index; - - end: - kfree(buffer.pointer); - - return ret; -} - static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) { int ret; diff --git a/include/linux/acpi.h b/include/linux/acpi.h index f80bd32daa29..ed68f45c09f7 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -284,10 +284,19 @@ static inline bool invalid_phys_cpuid(phys_cpuid_t phys_id) /* Validate the processor object's proc_id */ bool acpi_duplicate_processor_id(int proc_id); /* Processor _CTS control */ +struct acpi_processor_power; + #ifdef CONFIG_ACPI_PROCESSOR_CSTATE bool acpi_processor_claim_cst_control(void); +int acpi_processor_evaluate_cst(acpi_handle handle, u32 cpu, + struct acpi_processor_power *info); #else static inline bool acpi_processor_claim_cst_control(void) { return false; } +static inline int acpi_processor_evaluate_cst(acpi_handle handle, u32 cpu, + struct acpi_processor_power *info) +{ + return -ENODEV; +} #endif #ifdef CONFIG_ACPI_HOTPLUG_CPU From patchwork Wed Sep 11 04:27:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983629 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SHL398Xz1y1C for ; Wed, 11 Sep 2024 14:28:14 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExa-0004R8-Lg; Wed, 11 Sep 2024 04:28:06 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExY-0004NT-DH for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:28:04 +0000 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (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 smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 9AC363F17F for ; Wed, 11 Sep 2024 04:28:03 +0000 (UTC) Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-71797acf5c2so6112707b3a.3 for ; Tue, 10 Sep 2024 21:28:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028882; x=1726633682; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ykmEyaU+NEBo4iyalFMroe3tNdGojZ4kv+0FvqdykDs=; b=vgvLu6pTvGeUGzX6GuKkLQZ0dPiyDoY5o/QLyDZVAX4UXiXi4dawEcfvGkQRbHz8ZG Zg8XP0/eDP07MSDOjQwAWHvUSrAwD+xUzsiOb6vAbKlphNALWMGqZHswO7sChOqJVl3G 8naePy2TnEwgTddOJZvr+DlOo0NuqsFGek1WacjCjB+vQWtIWQhb63/VtlCrJV/b5cgf gY9lux2LJL0SB94UogRPztxW+Kb9TuAWotI6xfkA3ago+TgRtICmcU1oVVwmCthH/rTJ Mzj6I3WiHYuIg939J6lcTlUBYpY4gOmAQJ7emuhwU00wHEX+xYimXQ1kZw4MSc0anm7Z TUmg== X-Gm-Message-State: AOJu0Ywzsysxl5Bdb37FYW3nfGXxEIcKLTVt0TmuRuCza6JAC4dl55pb aeMa6uTeP4wsvT3KJ/G/mUOHqC0JoeHZ37a3hcV3YmI6jr6kDGxivi4h3mqDyiv3r7qqOz3TQNH lrhN+pccGnC4rqlbPG1Mxa/3im12bAtKDV9VuEMtW0YUu+6l0tlMDa6yD+odqBf038yOm/Tg47s nXKgFaS13u X-Received: by 2002:a05:6a00:139d:b0:710:50c8:ddcb with SMTP id d2e1a72fcca58-718d5dede6fmr24849779b3a.5.1726028881776; Tue, 10 Sep 2024 21:28:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5Lar/bG3Vnux9+dNi/rmuiWEfBHeCUY5L1pWHW1FAyZcGKJY4cMmaAP0sSPVEXUx/4XMcDw== X-Received: by 2002:a05:6a00:139d:b0:710:50c8:ddcb with SMTP id d2e1a72fcca58-718d5dede6fmr24849745b3a.5.1726028881247; Tue, 10 Sep 2024 21:28:01 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d860a4d202sm5325667a12.85.2024.09.10.21.28.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:28:00 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 09/17] intel_idle: Refactor intel_idle_cpuidle_driver_init() Date: Wed, 11 Sep 2024 01:27:18 -0300 Message-Id: <20240911042726.959018-10-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/2080324 Move the C-state verification and checks from intel_idle_cpuidle_driver_init() to a separate function, intel_idle_verify_cstate(), and make the former call it after checking the CPUIDLE_FLAG_UNUSABLE state flag. Also combine the drv->states[] updates with the incrementation of drv->state_count. No intentional functional impact. Signed-off-by: Rafael J. Wysocki (back ported from commit 9f3d6daf61e5156139cd05643f7f1c2a9b7b49b0) [marcelo.cerri: Updated context to keep current IBRS fix] Signed-off-by: Marcelo Henrique Cerri --- drivers/idle/intel_idle.c | 49 ++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c index 945afa633345..6148ec3290c2 100644 --- a/drivers/idle/intel_idle.c +++ b/drivers/idle/intel_idle.c @@ -970,6 +970,22 @@ static void intel_idle_s2idle(struct cpuidle_device *dev, mwait_idle_with_hints(eax, ecx); } +static bool intel_idle_verify_cstate(unsigned int mwait_hint) +{ + unsigned int mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint) + 1; + unsigned int num_substates = (mwait_substates >> mwait_cstate * 4) & + MWAIT_SUBSTATE_MASK; + + /* Ignore the C-state if there are NO sub-states in CPUID for it. */ + if (num_substates == 0) + return false; + + if (mwait_cstate > 2 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC)) + mark_tsc_unstable("TSC halts in idle states deeper than C2"); + + return true; +} + static void __setup_broadcast_timer(bool on) { if (on) @@ -1358,10 +1374,10 @@ static void __init intel_idle_cpuidle_driver_init(void) drv->state_count = 1; for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) { - int num_substates, mwait_hint, mwait_cstate; + unsigned int mwait_hint; - if ((cpuidle_state_table[cstate].enter == NULL) && - (cpuidle_state_table[cstate].enter_s2idle == NULL)) + if (!cpuidle_state_table[cstate].enter && + !cpuidle_state_table[cstate].enter_s2idle) break; if (cstate + 1 > max_cstate) { @@ -1369,39 +1385,24 @@ static void __init intel_idle_cpuidle_driver_init(void) break; } - mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags); - mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint); - - /* number of sub-states for this state in CPUID.MWAIT */ - num_substates = (mwait_substates >> ((mwait_cstate + 1) * 4)) - & MWAIT_SUBSTATE_MASK; - - /* if NO sub-states for this state in CPUID, skip it */ - if (num_substates == 0) - continue; - - /* if state marked as disabled, skip it */ + /* If marked as unusable, skip this state. */ if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_UNUSABLE) { pr_debug("state %s is disabled\n", cpuidle_state_table[cstate].name); continue; } - - if (((mwait_cstate + 1) > 2) && - !boot_cpu_has(X86_FEATURE_NONSTOP_TSC)) - mark_tsc_unstable("TSC halts in idle" - " states deeper than C2"); - - drv->states[drv->state_count] = /* structure copy */ - cpuidle_state_table[cstate]; + mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags); + if (!intel_idle_verify_cstate(mwait_hint)) + continue; if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) && cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_IBRS) { drv->states[drv->state_count].enter = intel_idle_ibrs; } - drv->state_count += 1; + /* Structure copy. */ + drv->states[drv->state_count++] = cpuidle_state_table[cstate]; } if (icpu->byt_auto_demotion_disable_flag) { From patchwork Wed Sep 11 04:27:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983630 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SHN4m4gz1y1C for ; Wed, 11 Sep 2024 14:28:16 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExc-0004VE-Qo; Wed, 11 Sep 2024 04:28:08 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExb-0004Rz-1T for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:28:07 +0000 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (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 smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id C08843F12E for ; Wed, 11 Sep 2024 04:28:06 +0000 (UTC) Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-2d88641e9a8so6453058a91.0 for ; Tue, 10 Sep 2024 21:28:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028885; x=1726633685; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3lie7kpKrCziEINXVcL8lUf7Mbyh3iEgVVGbKqWkYSo=; b=XKyUDbGcFImNhQ+4Ds5vm/8Pk0rbA28xug9WU3oFimnINf2H/IZfVbhMuAWR2vx+ea 733cRyd7/kvivZgj0BF+FxrM/D78t6G9sfaSL4C9uoQMbASPZ+hZsl7FPhYmlo2Bxj+4 0MqYK8jLlXug9BBS7SDMoJOWAu3LwQNtRIiT9yyHAUmd/H2vFluwG0sX0Or5MUKs7rCY XS37KC8SUNZS3aRzhAa/Lf0DPiDLAafWUiV/376Mz0GAvT+yJqP8ODwY7xin0TnM9GZU Pq1op/aXkF4cvocy/gWMdgbZIqNDSVLDicp+lor/tdDekzzlngZshpikWsRrlhljaw1Y yFhw== X-Gm-Message-State: AOJu0YwuWHoZ0OyIbm3hLWCepuiAnBCE7WT5d26UThDVCXj0zfOFysLz II6PZxp/je7EZWplc88R1s6Myg1bqH51DtnIfL1pwNaa/GXTSJy1k9hDXlaDB2sgpotYeeygPuf Bdb5H4ja/IbC7iiQcWgULxyAZRZHSYAlkla50F0q1IuZ+qqqUBkrICVoRo1vbdd2/A8JgUnpDaR IpxZRTiTMN X-Received: by 2002:a17:90a:304a:b0:2d8:82a2:b093 with SMTP id 98e67ed59e1d1-2dad50d297cmr17486690a91.13.1726028884960; Tue, 10 Sep 2024 21:28:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpXdVx9N78qpaq5JqX5Kb3CdHMEaWVSiENyEq18upYTqGbGjBftG0WgCvW5tATXcl55iLT6Q== X-Received: by 2002:a17:90a:304a:b0:2d8:82a2:b093 with SMTP id 98e67ed59e1d1-2dad50d297cmr17486668a91.13.1726028884479; Tue, 10 Sep 2024 21:28:04 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2dadc0213a7sm9495809a91.18.2024.09.10.21.28.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:28:04 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 10/17] intel_idle: Use ACPI _CST for processor models without C-state tables Date: Wed, 11 Sep 2024 01:27:19 -0300 Message-Id: <20240911042726.959018-11-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/2080324 Modify the intel_idle driver to get the C-states information from ACPI _CST if the processor model is not recognized by it. The processor is still required to support MWAIT and the information from ACPI _CST will only be used if all of the C-states listed by _CST are of the ACPI_CSTATE_FFH type (which means that they are expected to be entered via MWAIT). Moreover, the driver assumes that the _CST information is the same for all CPUs in the system, so it is sufficient to evaluate _CST for one of them and extract the common list of C-states from there. Also _CST is evaluated once at the system initialization time and the driver does not respond to _CST change notifications (that can be changed in the future). The main functional difference between intel_idle with this change and the ACPI processor driver is that the former sets the target residency to be equal to the exit latency (provided by _CST) for C1-type C-states and to 3 times the exit latency value for the other C-state types, whereas the latter obtains the target residency by multiplying the exit latency by the same number (2 by default) for all C-state types. Therefore it is expected that in general using the former instead of the latter on the same system will lead to improved energy-efficiency. Signed-off-by: Rafael J. Wysocki (cherry picked from commit 18734958e9bfbc055805d110a38dc76307eba742) Signed-off-by: Marcelo Henrique Cerri --- drivers/idle/intel_idle.c | 190 ++++++++++++++++++++++++++++++++------ 1 file changed, 162 insertions(+), 28 deletions(-) diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c index 6148ec3290c2..e812a4056fcd 100644 --- a/drivers/idle/intel_idle.c +++ b/drivers/idle/intel_idle.c @@ -41,6 +41,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -1137,6 +1138,129 @@ static const struct x86_cpu_id intel_idle_ids[] __initconst = { {} }; +#define INTEL_CPU_FAM6_MWAIT \ + { X86_VENDOR_INTEL, 6, X86_MODEL_ANY, X86_FEATURE_MWAIT, 0 } + +static const struct x86_cpu_id intel_mwait_ids[] __initconst = { + INTEL_CPU_FAM6_MWAIT, + {} +}; + +static bool intel_idle_max_cstate_reached(int cstate) +{ + if (cstate + 1 > max_cstate) { + pr_info("max_cstate %d reached\n", max_cstate); + return true; + } + return false; +} + +#ifdef CONFIG_ACPI_PROCESSOR_CSTATE +#include + +static struct acpi_processor_power acpi_state_table; + +/** + * intel_idle_cst_usable - Check if the _CST information can be used. + * + * Check if all of the C-states listed by _CST in the max_cstate range are + * ACPI_CSTATE_FFH, which means that they should be entered via MWAIT. + */ +static bool intel_idle_cst_usable(void) +{ + int cstate, limit; + + limit = min_t(int, min_t(int, CPUIDLE_STATE_MAX, max_cstate + 1), + acpi_state_table.count); + + for (cstate = 1; cstate < limit; cstate++) { + struct acpi_processor_cx *cx = &acpi_state_table.states[cstate]; + + if (cx->entry_method != ACPI_CSTATE_FFH) + return false; + } + + return true; +} + +static bool intel_idle_acpi_cst_extract(void) +{ + unsigned int cpu; + + for_each_possible_cpu(cpu) { + struct acpi_processor *pr = per_cpu(processors, cpu); + + if (!pr) + continue; + + if (acpi_processor_evaluate_cst(pr->handle, cpu, &acpi_state_table)) + continue; + + acpi_state_table.count++; + + if (!intel_idle_cst_usable()) + continue; + + if (!acpi_processor_claim_cst_control()) { + acpi_state_table.count = 0; + return false; + } + + return true; + } + + pr_debug("ACPI _CST not found or not usable\n"); + return false; +} + +static void intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) +{ + int cstate, limit = min_t(int, CPUIDLE_STATE_MAX, acpi_state_table.count); + + /* + * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of + * the interesting states are ACPI_CSTATE_FFH. + */ + for (cstate = 1; cstate < limit; cstate++) { + struct acpi_processor_cx *cx; + struct cpuidle_state *state; + + if (intel_idle_max_cstate_reached(cstate)) + break; + + cx = &acpi_state_table.states[cstate]; + + state = &drv->states[drv->state_count++]; + + snprintf(state->name, CPUIDLE_NAME_LEN, "C%d_ACPI", cstate); + strlcpy(state->desc, cx->desc, CPUIDLE_DESC_LEN); + state->exit_latency = cx->latency; + /* + * For C1-type C-states use the same number for both the exit + * latency and target residency, because that is the case for + * C1 in the majority of the static C-states tables above. + * For the other types of C-states, however, set the target + * residency to 3 times the exit latency which should lead to + * a reasonable balance between energy-efficiency and + * performance in the majority of interesting cases. + */ + state->target_residency = cx->latency; + if (cx->type > ACPI_STATE_C1) + state->target_residency *= 3; + + state->flags = MWAIT2flg(cx->address); + if (cx->type > ACPI_STATE_C2) + state->flags |= CPUIDLE_FLAG_TLB_FLUSHED; + + state->enter = intel_idle; + state->enter_s2idle = intel_idle_s2idle; + } +} +#else /* !CONFIG_ACPI_PROCESSOR_CSTATE */ +static inline bool intel_idle_acpi_cst_extract(void) { return false; } +static inline void intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) { } +#endif /* !CONFIG_ACPI_PROCESSOR_CSTATE */ + /* * intel_idle_probe() */ @@ -1151,17 +1275,15 @@ static int __init intel_idle_probe(void) } id = x86_match_cpu(intel_idle_ids); - if (!id) { - if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && - boot_cpu_data.x86 == 6) - pr_debug("does not run on family %d model %d\n", - boot_cpu_data.x86, boot_cpu_data.x86_model); - return -ENODEV; - } - - if (!boot_cpu_has(X86_FEATURE_MWAIT)) { - pr_debug("Please enable MWAIT in BIOS SETUP\n"); - return -ENODEV; + if (id) { + if (!boot_cpu_has(X86_FEATURE_MWAIT)) { + pr_debug("Please enable MWAIT in BIOS SETUP\n"); + return -ENODEV; + } + } else { + id = x86_match_cpu(intel_mwait_ids); + if (!id) + return -ENODEV; } if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF) @@ -1177,7 +1299,10 @@ static int __init intel_idle_probe(void) pr_debug("MWAIT substates: 0x%x\n", mwait_substates); icpu = (const struct idle_cpu *)id->driver_data; - cpuidle_state_table = icpu->state_table; + if (icpu) + cpuidle_state_table = icpu->state_table; + else if (!intel_idle_acpi_cst_extract()) + return -ENODEV; pr_debug("v" INTEL_IDLE_VERSION " model 0x%X\n", boot_cpu_data.x86_model); @@ -1359,31 +1484,19 @@ static void intel_idle_state_table_update(void) } } -/* - * intel_idle_cpuidle_driver_init() - * allocate, initialize cpuidle_states - */ -static void __init intel_idle_cpuidle_driver_init(void) +static void intel_idle_init_cstates_icpu(struct cpuidle_driver *drv) { int cstate; - struct cpuidle_driver *drv = &intel_idle_driver; - - intel_idle_state_table_update(); - - cpuidle_poll_state_init(drv); - drv->state_count = 1; for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) { unsigned int mwait_hint; - if (!cpuidle_state_table[cstate].enter && - !cpuidle_state_table[cstate].enter_s2idle) + if (intel_idle_max_cstate_reached(cstate)) break; - if (cstate + 1 > max_cstate) { - pr_info("max_cstate %d reached\n", max_cstate); + if (!cpuidle_state_table[cstate].enter && + !cpuidle_state_table[cstate].enter_s2idle) break; - } /* If marked as unusable, skip this state. */ if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_UNUSABLE) { @@ -1411,6 +1524,24 @@ static void __init intel_idle_cpuidle_driver_init(void) } } +/* + * intel_idle_cpuidle_driver_init() + * allocate, initialize cpuidle_states + */ +static void __init intel_idle_cpuidle_driver_init(void) +{ + struct cpuidle_driver *drv = &intel_idle_driver; + + intel_idle_state_table_update(); + + cpuidle_poll_state_init(drv); + drv->state_count = 1; + + if (icpu) + intel_idle_init_cstates_icpu(drv); + else + intel_idle_init_cstates_acpi(drv); +} /* * intel_idle_cpu_init() @@ -1429,6 +1560,9 @@ static int intel_idle_cpu_init(unsigned int cpu) return -EIO; } + if (!icpu) + return 0; + if (icpu->auto_demotion_disable_flags) auto_demotion_disable(); From patchwork Wed Sep 11 04:27:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983631 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SHR5Ccjz1y1C for ; Wed, 11 Sep 2024 14:28:19 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExg-0004c6-9i; Wed, 11 Sep 2024 04:28:12 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExe-0004Ya-9b for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:28:10 +0000 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (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 smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id AD09B3F17F for ; Wed, 11 Sep 2024 04:28:09 +0000 (UTC) Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-2d89dacf002so7613635a91.3 for ; Tue, 10 Sep 2024 21:28:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028888; x=1726633688; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E4B+Daf/YzWUi5Yt+ZKA37eDoLaqWqltg6XY8EM68bo=; b=durtX0noRoqd1jTg/0dKkXuxbZWITRkqR8xpztGZfo0fjHPHBTd96HQ0ZYBRY1BXdR mgaycBC+LSMgOK+47KamLtm131PH8oesL5mV1rVCIztFi2H3yRs9M/5+U/rizrAR9GE8 Y7cJDABnzS969x5UStezhjrsHJ3l4d7WWLJ+Bl43glgW/7M5Ah5mUvp9LjbRfDBiE3TE eEfbEMOE8Dp0skaUN3vxS2Hu9+OKRhLdMJ2eGNXaNTit/huBJNlBmHvLitLek+zLnqis ShLP3LTdDauUtmLjgd3fZMqMYO3ymgzpGw3zN3lY9nlMfXd+e0eLYpbAD9TpSxbDiLEH qpMA== X-Gm-Message-State: AOJu0Yw6hK61qfuGYK3agKGkOG2t706USvrYWh6Z4Nf1q/1aib4kOL70 V6X74m3SD3uoJSiidUB1EE62AFfi8lp5II37DFqUXI4WkAUJgEF0RUUaxjX9iXE4Pd5dA1vd5SH b9faWGXE0gZB5VWwGGwlmRbSWtLimrxVL8D6Fozc/yc9p1ZKs4FnLhrIQIjKcygSrhL7ShfdF2N qme1iDuJrf X-Received: by 2002:a17:90a:e150:b0:2d4:bf3:428e with SMTP id 98e67ed59e1d1-2dad50f3f3cmr22588172a91.37.1726028887856; Tue, 10 Sep 2024 21:28:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3W4Mq8DUZK7lZyXy9iuJub1YwzHy5ZdXya7xjcnYF5hpmUn6DwfYv9YaOgdGPVPSAWO2eKQ== X-Received: by 2002:a17:90a:e150:b0:2d4:bf3:428e with SMTP id 98e67ed59e1d1-2dad50f3f3cmr22588146a91.37.1726028887327; Tue, 10 Sep 2024 21:28:07 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2dadc03700dsm9417168a91.21.2024.09.10.21.28.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:28:07 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 11/17] cpuidle: Allow idle states to be disabled by default Date: Wed, 11 Sep 2024 01:27:20 -0300 Message-Id: <20240911042726.959018-12-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/2080324 In certain situations it may be useful to prevent some idle states from being used by default while allowing user space to enable them later on. For this purpose, introduce a new state flag, CPUIDLE_FLAG_OFF, to mark idle states that should be disabled by default, make the core set CPUIDLE_STATE_DISABLED_BY_USER for those states at the initialization time and add a new state attribute in sysfs, "default_status", to inform user space of the initial status of the given idle state ("disabled" if CPUIDLE_FLAG_OFF is set for it, "enabled" otherwise). Signed-off-by: Rafael J. Wysocki (cherry picked from commit 75a80267410e38ab76c4ceb39753f96d72113781) Signed-off-by: Marcelo Henrique Cerri --- Documentation/ABI/testing/sysfs-devices-system-cpu | 6 ++++++ Documentation/admin-guide/pm/cpuidle.rst | 3 +++ drivers/cpuidle/cpuidle.c | 6 +++++- drivers/cpuidle/sysfs.c | 10 ++++++++++ include/linux/cpuidle.h | 1 + 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu index 08e153614e09..58850f15d957 100644 --- a/Documentation/ABI/testing/sysfs-devices-system-cpu +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu @@ -196,6 +196,12 @@ Description: does not reflect it. Likewise, if one enables a deep state but a lighter state still is disabled, then this has no effect. +What: /sys/devices/system/cpu/cpuX/cpuidle/stateN/default_status +Date: December 2019 +KernelVersion: v5.6 +Contact: Linux power management list +Description: + (RO) The default status of this state, "enabled" or "disabled". What: /sys/devices/system/cpu/cpuX/cpuidle/stateN/residency Date: March 2014 diff --git a/Documentation/admin-guide/pm/cpuidle.rst b/Documentation/admin-guide/pm/cpuidle.rst index 80cf2ef2a506..c4d129234bc4 100644 --- a/Documentation/admin-guide/pm/cpuidle.rst +++ b/Documentation/admin-guide/pm/cpuidle.rst @@ -506,6 +506,9 @@ object corresponding to it, as follows: ``disable`` Whether or not this idle state is disabled. +``default_status`` + The default status of this state, "enabled" or "disabled". + ``latency`` Exit latency of the idle state in microseconds. diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index f0559c0e46c9..24edf2214db6 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -573,10 +573,14 @@ static int __cpuidle_register_device(struct cpuidle_device *dev) if (!try_module_get(drv->owner)) return -EINVAL; - for (i = 0; i < drv->state_count; i++) + for (i = 0; i < drv->state_count; i++) { if (drv->states[i].flags & CPUIDLE_FLAG_UNUSABLE) dev->states_usage[i].disable |= CPUIDLE_STATE_DISABLED_BY_DRIVER; + if (drv->states[i].flags & CPUIDLE_FLAG_OFF) + dev->states_usage[i].disable |= CPUIDLE_STATE_DISABLED_BY_USER; + } + per_cpu(cpuidle_devices, dev->cpu) = dev; list_add(&dev->device_list, &cpuidle_detected_devices); diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c index 280ab31c1e59..f518ac2b09a0 100644 --- a/drivers/cpuidle/sysfs.c +++ b/drivers/cpuidle/sysfs.c @@ -313,6 +313,14 @@ static ssize_t store_state_disable(struct cpuidle_state *state, return size; } +static ssize_t show_state_default_status(struct cpuidle_state *state, + struct cpuidle_state_usage *state_usage, + char *buf) +{ + return sprintf(buf, "%s\n", + state->flags & CPUIDLE_FLAG_OFF ? "disabled" : "enabled"); +} + define_one_state_ro(name, show_state_name); define_one_state_ro(desc, show_state_desc); define_one_state_ro(latency, show_state_exit_latency); @@ -323,6 +331,7 @@ define_one_state_ro(time, show_state_time); define_one_state_rw(disable, show_state_disable, store_state_disable); define_one_state_ro(above, show_state_above); define_one_state_ro(below, show_state_below); +define_one_state_ro(default_status, show_state_default_status); static struct attribute *cpuidle_state_default_attrs[] = { &attr_name.attr, @@ -335,6 +344,7 @@ static struct attribute *cpuidle_state_default_attrs[] = { &attr_disable.attr, &attr_above.attr, &attr_below.attr, + &attr_default_status.attr, NULL }; diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index 68eeb0a308cc..f45ea5993827 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -75,6 +75,7 @@ struct cpuidle_state { #define CPUIDLE_FLAG_COUPLED BIT(1) /* state applies to multiple cpus */ #define CPUIDLE_FLAG_TIMER_STOP BIT(2) /* timer is stopped on this state */ #define CPUIDLE_FLAG_UNUSABLE BIT(3) /* avoid using this state */ +#define CPUIDLE_FLAG_OFF BIT(4) /* disable this state by default */ struct cpuidle_device_kobj; struct cpuidle_state_kobj; From patchwork Wed Sep 11 04:27:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983632 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SHT6wlvz1y1C for ; Wed, 11 Sep 2024 14:28:21 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExi-0004h6-Gf; Wed, 11 Sep 2024 04:28:14 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExh-0004dr-5F for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:28:13 +0000 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (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 smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 8BA5D3F17F for ; Wed, 11 Sep 2024 04:28:12 +0000 (UTC) Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-2d8e59fcd4bso1786700a91.1 for ; Tue, 10 Sep 2024 21:28:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028891; x=1726633691; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D9xfz/gtVCd2/mt5g4moqJYuSkM3J38vXJ0zYR9wwoA=; b=aC/YXHU8d0pxai3waNAoMfS5l51LU0p7NmrPKJVLqvXpccl7Hp7FM7QaZnA2EBAHp5 FImaBkZ2yp6g9EYvColFwMgIp1DcPRIKZPmlEh0oiXtBis4wGtR8zKUwL/AcdBdGphpP 8gmuhIRRNO675BMvYw0Tdi6aNhjg3onxD9GiuwUgZWYFymNgFlLGoVLg/EKIi+asM0oZ 4SENHbbrmtZBAU/BNaav9p32r6E4/yL4yV0LX2VqVNo4lhVUcyLL2QntLvfkl1YZv71b qs4T9ob30164POrgCvwghB5HdTDtRujZ4E0YY5WmfGZAWCGCylExwxq36YiM8pW66dcf zn9g== X-Gm-Message-State: AOJu0YzOZa/8M2Lv9vZ2dFMkt4pzFpMobPKyfz8ollw0KBIA36A6JfUn 8we0fC0LHThbfgvQHdPrWLe6AAraYMH2TrBuZM2UIeXmgwUc40b8lCvCw3J2kicfuh9ZukOHgOP CDWepWCK3WEl/2O9Y4VuQB7G7J2Gc+T2/PsF5/vzgxp3NnB0B38zPvv6m0lI/pX2DdJVpsCGpBa 3nlCMBmElb X-Received: by 2002:a17:90b:1c01:b0:2da:5d71:fbc with SMTP id 98e67ed59e1d1-2db82fb6df0mr2111138a91.16.1726028890923; Tue, 10 Sep 2024 21:28:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKJbG8eVL2yrUsBGLmRW1mExEdmMLvBxmdin9nQCXls63RwRBHPfn+yIMFvuZ8EPm3B+QKXQ== X-Received: by 2002:a17:90b:1c01:b0:2da:5d71:fbc with SMTP id 98e67ed59e1d1-2db82fb6df0mr2111119a91.16.1726028890415; Tue, 10 Sep 2024 21:28:10 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2dadc04041csm9401173a91.27.2024.09.10.21.28.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:28:10 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 12/17] intel_idle: Allow ACPI _CST to be used for selected known processors Date: Wed, 11 Sep 2024 01:27:21 -0300 Message-Id: <20240911042726.959018-13-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Rafael J. Wysocki" BugLink: https://bugs.launchpad.net/bugs/2080324 Update the intel_idle driver to get the C-states information from ACPI _CST in some cases in which the processor is known to the driver, as long as that information is available and the new use_acpi flag is set in the profile of the processor in question. In the cases when there is a specific table of C-states for the given processor in the driver, that table is used as the primary source of information on the available C-states, but if ACPI _CST is present, the C-states that are not listed by it will not be enabled by default (they still can be enabled later by user space via sysfs, though). The new CPUIDLE_FLAG_ALWAYS_ENABLE flag can be used for marking C-states that should be enabled by default even if they are not listed by ACPI _CST. Signed-off-by: Rafael J. Wysocki (cherry picked from commit bff8e60a86f4960133f90ad9add9adeb082b8154) Signed-off-by: Marcelo Henrique Cerri --- drivers/idle/intel_idle.c | 45 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c index e812a4056fcd..9eb131434af3 100644 --- a/drivers/idle/intel_idle.c +++ b/drivers/idle/intel_idle.c @@ -82,6 +82,7 @@ struct idle_cpu { unsigned long auto_demotion_disable_flags; bool byt_auto_demotion_disable_flag; bool disable_promotion_to_c1e; + bool use_acpi; }; static const struct idle_cpu *icpu; @@ -92,6 +93,11 @@ static void intel_idle_s2idle(struct cpuidle_device *dev, struct cpuidle_driver *drv, int index); static struct cpuidle_state *cpuidle_state_table; +/* + * Enable this state by default even if the ACPI _CST does not list it. + */ +#define CPUIDLE_FLAG_ALWAYS_ENABLE BIT(15) + /* * Set this flag for states where the HW flushes the TLB for us * and so we don't need cross-calls to keep it consistent. @@ -1256,9 +1262,33 @@ static void intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) state->enter_s2idle = intel_idle_s2idle; } } + +static bool intel_idle_off_by_default(u32 mwait_hint) +{ + int cstate, limit; + + /* + * If there are no _CST C-states, do not disable any C-states by + * default. + */ + if (!acpi_state_table.count) + return false; + + limit = min_t(int, CPUIDLE_STATE_MAX, acpi_state_table.count); + /* + * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of + * the interesting states are ACPI_CSTATE_FFH. + */ + for (cstate = 1; cstate < limit; cstate++) { + if (acpi_state_table.states[cstate].address == mwait_hint) + return false; + } + return true; +} #else /* !CONFIG_ACPI_PROCESSOR_CSTATE */ static inline bool intel_idle_acpi_cst_extract(void) { return false; } static inline void intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) { } +static inline bool intel_idle_off_by_default(u32 mwait_hint) { return false; } #endif /* !CONFIG_ACPI_PROCESSOR_CSTATE */ /* @@ -1299,10 +1329,13 @@ static int __init intel_idle_probe(void) pr_debug("MWAIT substates: 0x%x\n", mwait_substates); icpu = (const struct idle_cpu *)id->driver_data; - if (icpu) + if (icpu) { cpuidle_state_table = icpu->state_table; - else if (!intel_idle_acpi_cst_extract()) + if (icpu->use_acpi) + intel_idle_acpi_cst_extract(); + } else if (!intel_idle_acpi_cst_extract()) { return -ENODEV; + } pr_debug("v" INTEL_IDLE_VERSION " model 0x%X\n", boot_cpu_data.x86_model); @@ -1515,7 +1548,13 @@ static void intel_idle_init_cstates_icpu(struct cpuidle_driver *drv) } /* Structure copy. */ - drv->states[drv->state_count++] = cpuidle_state_table[cstate]; + drv->states[drv->state_count] = cpuidle_state_table[cstate]; + + if (icpu->use_acpi && intel_idle_off_by_default(mwait_hint) && + !(cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_ALWAYS_ENABLE)) + drv->states[drv->state_count].flags |= CPUIDLE_FLAG_OFF; + + drv->state_count++; } if (icpu->byt_auto_demotion_disable_flag) { From patchwork Wed Sep 11 04:27:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983633 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SHZ1jnNz1y1C for ; Wed, 11 Sep 2024 14:28:26 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExl-0004tV-R1; Wed, 11 Sep 2024 04:28:17 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExk-0004nu-Bz for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:28:16 +0000 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (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 smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 0F4A73F17F for ; Wed, 11 Sep 2024 04:28:16 +0000 (UTC) Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-718816b5109so1552745b3a.1 for ; Tue, 10 Sep 2024 21:28:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028894; x=1726633694; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sM7gGejR1/OiPdxw5ntCYZFQnbhhL339uG3KZiEO30M=; b=CPMfmZbg0gXXqayz9OYk6uYoICgKZacsRNV/sarS8XxJkq2ziCCVZ39KB1+aioB58G JkpQEhLWE7VFahpKq2FyzNaqvlrQ5QSR83aoLTDcBynipKeG1ngQsWIJfpWiFa4NazKm jhvCdiIw0N+eeWVdCp0Ks5CWj9QElrp7QCDJ/rvHDJtOLyOH8y+PWnFfKX/N+Up2xUrS k8LXQQT0gxC2b8wQ6rcabz1xYg6LhR660JirElhxZO/NK4oeZHSHakwxLHLqo6HTzCzc HYohlbtwesStYSXJiIe0mYJL1Yhgsatp3Op3rGGbGOJh1ilIfGVz93WrNNNdEgcxNr/S wTOw== X-Gm-Message-State: AOJu0YwRb1rPWxp3Qp0RXPxLKst94OdypUka71evUIIGT70G8X+4T8ub GNOAKuynWRngGvc+aK4zx/4+julC2FjOf3w7P9iZ7IKXcWh/u9Q6C6eaYOfq2DopgfTzj1S/chY qR+6fyY7ije4Z9dEFuXQWJWFO09b+JvWxPXkrlYt6kHjlgd+kFE7FzwXhAXcIK9HAX4mtoT9Kr+ oVoIwevOXi X-Received: by 2002:a05:6a00:2304:b0:714:241d:a323 with SMTP id d2e1a72fcca58-7191712263dmr2181245b3a.17.1726028894321; Tue, 10 Sep 2024 21:28:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYNN0cCkLV7hlhVh18HAcyR4h4T1GG9jE+6CQORrilb0Lfb5eZbh1Xhil5Q3M36fy9EeWDgA== X-Received: by 2002:a05:6a00:2304:b0:714:241d:a323 with SMTP id d2e1a72fcca58-7191712263dmr2181217b3a.17.1726028893821; Tue, 10 Sep 2024 21:28:13 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-719090b281fsm2193412b3a.171.2024.09.10.21.28.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:28:13 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 13/17] x86/cpu: Add Sapphire Rapids CPU model number Date: Wed, 11 Sep 2024 01:27:22 -0300 Message-Id: <20240911042726.959018-14-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Tony Luck BugLink: https://bugs.launchpad.net/bugs/2080324 Latest edition (039) of "Intel Architecture Instruction Set Extensions and Future Features Programming Reference" includes three new CPU model numbers. Linux already has the two Ice Lake server ones. Add the new model number for Sapphire Rapids. Signed-off-by: Tony Luck Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/20200603173352.15506-1-tony.luck@intel.com (back ported from commit be25d1b5ea6a3a3ecbb5474e2ae8e32d2ba055ea) [marcelo.cerri: adjusted context. intel-family.h had several refactors. Sapphire rapids was still add as INTEL_FAM6_, so this adjustment is just a matter of ordering the defines.] Signed-off-by: Marcelo Henrique Cerri --- arch/x86/include/asm/intel-family.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/include/asm/intel-family.h b/arch/x86/include/asm/intel-family.h index 6fdd863198ec..28a74f22e49a 100644 --- a/arch/x86/include/asm/intel-family.h +++ b/arch/x86/include/asm/intel-family.h @@ -102,6 +102,8 @@ #define INTEL_FAM6_RAPTORLAKE_P 0xBA #define INTEL_FAM6_RAPTORLAKE_S 0xBF +#define INTEL_FAM6_SAPPHIRERAPIDS_X 0x8F + /* "Small Core" Processors (Atom) */ #define INTEL_FAM6_ATOM_BONNELL 0x1C /* Diamondville, Pineview */ From patchwork Wed Sep 11 04:27:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983634 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SHf2QTrz1y1C for ; Wed, 11 Sep 2024 14:28:30 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExq-00058H-0K; Wed, 11 Sep 2024 04:28:22 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExn-00051v-SH for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:28:19 +0000 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (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 smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 8D7A93F5B8 for ; Wed, 11 Sep 2024 04:28:19 +0000 (UTC) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-1fd9a0efe4eso79493105ad.0 for ; Tue, 10 Sep 2024 21:28:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028898; x=1726633698; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Fcekwy/mnKBkv/DhlkKLBUVGC1GySKj2rTkvQl++/Q=; b=C7g65KOAKsXV6dh19kPUQVHWAx2mWO4BK7RASQYhik/4mAyTTRzP8q2+0Yk16ZBW9X AlLgUgE1r8xE4vJRvfZnCSoDj0u/0s4VLBhyy4gHYkWVk0gbqSfJmNh+t0j9qqiGAfWj a3s17Co0pSWvo/hvsM7NfTPeXLE+i4RKgwRECLHCTexgVJUad3v/PoGTlf337+ttKV9Q 936D4U+sAzg1Y2ckbcX45/NDz6tZoN2od6x8HBZW9/hkVJ1Kl1Ntnhe6pJCHWx4/P20q TqnXeDpBLIsGwSWh8Uq1tLm4ojkO9JAouky3MO0MOCoYqok7U7+NG7d7/+dhjdJ5a8XQ GfUQ== X-Gm-Message-State: AOJu0Yw4uOnG/wlLsgdIFoYMGrCOGge2zClJMveD8ZL8LvT0sl56j1Of 1lDpvKUsmlfa3LjKFryQgdSn6WQeyyuz5u2wbykVji6/N8I14WzXJvhfAU9zI4xfZ/P66C5Wnby Ueb0X9/0KaWQVxVqhCB0sm1WzdpSzAkzqQdv35sCPLD1y7CgIxdG8/fJWOQbsnsIyqyW0gm2p17 KNHtRA2r3z X-Received: by 2002:a17:902:e846:b0:206:c8dc:e334 with SMTP id d9443c01a7336-2074c69b72emr42719245ad.39.1726028897641; Tue, 10 Sep 2024 21:28:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGf+TC19MZODlV7h7mfagItW6mP5lN4A5z/1QoVnb1CFbK9I4rXpmhUtKJdO3bTOjOCeJcmsQ== X-Received: by 2002:a17:902:e846:b0:206:c8dc:e334 with SMTP id d9443c01a7336-2074c69b72emr42718985ad.39.1726028897188; Tue, 10 Sep 2024 21:28:17 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20710e1a684sm55530155ad.10.2024.09.10.21.28.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:28:16 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 14/17] intel_idle: Fix max_cstate for processor models without C-state tables Date: Wed, 11 Sep 2024 01:27:23 -0300 Message-Id: <20240911042726.959018-15-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Chen Yu BugLink: https://bugs.launchpad.net/bugs/2080324 Currently intel_idle driver gets the c-state information from ACPI _CST if the processor model is not recognized by it. However the c-state in _CST starts with index 1 which is different from the index in intel_idle driver's internal c-state table. While intel_idle_max_cstate_reached() was previously introduced to deal with intel_idle driver's internal c-state table, re-using this function directly on _CST is incorrect. Fix this by subtracting 1 from the index when checking max_cstate in the _CST case. For example, append intel_idle.max_cstate=1 in boot command line, Before the patch: grep . /sys/devices/system/cpu/cpu0/cpuidle/state*/name POLL After the patch: grep . /sys/devices/system/cpu/cpu0/cpuidle/state*/name /sys/devices/system/cpu/cpu0/cpuidle/state0/name:POLL /sys/devices/system/cpu/cpu0/cpuidle/state1/name:C1_ACPI Fixes: 18734958e9bf ("intel_idle: Use ACPI _CST for processor models without C-state tables") Reported-by: Pengfei Xu Cc: 5.6+ # 5.6+ Signed-off-by: Chen Yu [ rjw: Changelog edits ] Signed-off-by: Rafael J. Wysocki (cherry picked from commit 4e0ba5577dba686f96c1c10ef4166380667fdec7) Signed-off-by: Marcelo Henrique Cerri --- drivers/idle/intel_idle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c index 9eb131434af3..4abbae526a3f 100644 --- a/drivers/idle/intel_idle.c +++ b/drivers/idle/intel_idle.c @@ -1231,7 +1231,7 @@ static void intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) struct acpi_processor_cx *cx; struct cpuidle_state *state; - if (intel_idle_max_cstate_reached(cstate)) + if (intel_idle_max_cstate_reached(cstate - 1)) break; cx = &acpi_state_table.states[cstate]; From patchwork Wed Sep 11 04:27:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983635 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SHj439sz1y1C for ; Wed, 11 Sep 2024 14:28:33 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExt-0005K2-Gq; Wed, 11 Sep 2024 04:28:25 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExr-0005Fa-JY for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:28:23 +0000 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (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 smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 1C7593F17F for ; Wed, 11 Sep 2024 04:28:23 +0000 (UTC) Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2053f4938c7so78788805ad.2 for ; Tue, 10 Sep 2024 21:28:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028901; x=1726633701; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pKqLb7niH9XLhO/z9afUIrClAI0LstuEVxkl+E/+vAg=; b=jm+yQgd0Vf+92QhZRDRBzVAxPuu7vUYXnCIFmr3/85SvAAujVJlQ312VortTatQ0Nr rij2EJgFdlXbiGnuSxaRus07J/wICw/mg+TDDsdm3adQquFyTHxjQjxUA7Mjr8Sv5n01 itBRnQ//WRQQPlFemfS7QOOs2mHNy+0sgAkUl6O4fp1xmvtBchGD8qnU5UZpHa2brsh9 hUAKJQAL5pToiUNqoNlX5BLnlUrGZOJ0Z/Im2gmuodaPg1lQy9oxuhCKC1tOtOG60HqK O68o0QVZc54tHAjsU4bGRten7pJ4Hs7Sw5Axbv7YpaP87pUvPT5o7Qv95S7aNsWPo7j2 m71Q== X-Gm-Message-State: AOJu0YzK8TC/UKUzXyGJVs2psOqz4wm9EoO77IZ1Sbfe1x9NnLmS30HM h2H4BgGVCUIOkDrzcY3J3NRxfYFBsnscJjDfuxnAXjrYmsy0hT4IxwWVpiUip4WwRBbCw4cAd27 lwN0beK2Uzs1mYxHQFru1sx7AqtLnYd9Q4IB9R2rJ28ucCWR771wL+wj8BKyFubMmjCsc1DltB6 ngxJWc5guU X-Received: by 2002:a17:902:e74e:b0:205:40a6:115a with SMTP id d9443c01a7336-2074c6aecf8mr44406855ad.48.1726028901457; Tue, 10 Sep 2024 21:28:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHRRdo4yKhCxjuRVtNzkiuXYbBmHBYE5XXhsfaJJ/KLWALc1+yZeLsE/sG9CPZ6Vf84Ac6RtA== X-Received: by 2002:a17:902:e74e:b0:205:40a6:115a with SMTP id d9443c01a7336-2074c6aecf8mr44406615ad.48.1726028900977; Tue, 10 Sep 2024 21:28:20 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20710f32611sm55171705ad.270.2024.09.10.21.28.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:28:20 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 15/17] intel_idle: add SPR support Date: Wed, 11 Sep 2024 01:27:24 -0300 Message-Id: <20240911042726.959018-16-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Artem Bityutskiy BugLink: https://bugs.launchpad.net/bugs/2080324 Add Sapphire Rapids Xeon support. Up until very recently, the C1 and C1E C-states were independent, but this has changed in some new chips, including Sapphire Rapids Xeon (SPR). In these chips the C1 and C1E states cannot be enabled at the same time. The "C1E promotion" bit in 'MSR_IA32_POWER_CTL' also has its semantics changed a bit. Here are the C1, C1E, and "C1E promotion" bit rules on Xeons before SPR. 1. If C1E promotion bit is disabled. a. C1 requests end up with C1 C-state. b. C1E requests end up with C1E C-state. 2. If C1E promotion bit is enabled. a. C1 requests end up with C1E C-state. b. C1E requests end up with C1E C-state. Here are the C1, C1E, and "C1E promotion" bit rules on Sapphire Rapids Xeon. 1. If C1E promotion bit is disabled. a. C1 requests end up with C1 C-state. b. C1E requests end up with C1 C-state. 2. If C1E promotion bit is enabled. a. C1 requests end up with C1E C-state. b. C1E requests end up with C1E C-state. Before SPR Xeon, the 'intel_idle' driver was disabling C1E promotion and was exposing C1 and C1E as independent C-states. But on SPR, C1 and C1E cannot be enabled at the same time. This patch adds both C1 and C1E states. However, C1E is marked as with the "CPUIDLE_FLAG_UNUSABLE" flag, which means that in won't be registered by default. The C1E promotion bit will be cleared, which means that by default only C1 and C6 will be registered on SPR. The next patch will add an option for enabling C1E and disabling C1 on SPR. Signed-off-by: Artem Bityutskiy Signed-off-by: Rafael J. Wysocki (back ported from commit 9edf3c0ffef0ec1bed8300315852b5c6a0997130) [marcelo.cerri: Fix context in several places and replaced X86_MATCH_INTEL_FAM6_MODEL() with INTEL_CPU_FAM6()] Signed-off-by: Marcelo Henrique Cerri --- drivers/idle/intel_idle.c | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c index 4abbae526a3f..8d6aa90acf35 100644 --- a/drivers/idle/intel_idle.c +++ b/drivers/idle/intel_idle.c @@ -708,6 +708,46 @@ static struct cpuidle_state skx_cstates[] = { .enter = NULL } }; +/* + * On Sapphire Rapids Xeon C1 has to be disabled if C1E is enabled, and vice + * versa. On SPR C1E is enabled only if "C1E promotion" bit is set in + * MSR_IA32_POWER_CTL. But in this case there effectively no C1, because C1 + * requests are promoted to C1E. If the "C1E promotion" bit is cleared, then + * both C1 and C1E requests end up with C1, so there is effectively no C1E. + * + * By default we enable C1 and disable C1E by marking it with + * 'CPUIDLE_FLAG_UNUSABLE'. + */ +static struct cpuidle_state spr_cstates[] __initdata = { + { + .name = "C1", + .desc = "MWAIT 0x00", + .flags = MWAIT2flg(0x00), + .exit_latency = 1, + .target_residency = 1, + .enter = &intel_idle, + .enter_s2idle = intel_idle_s2idle, }, + { + .name = "C1E", + .desc = "MWAIT 0x01", + .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE | \ + CPUIDLE_FLAG_UNUSABLE, + .exit_latency = 2, + .target_residency = 4, + .enter = &intel_idle, + .enter_s2idle = intel_idle_s2idle, }, + { + .name = "C6", + .desc = "MWAIT 0x20", + .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED, + .exit_latency = 290, + .target_residency = 800, + .enter = &intel_idle, + .enter_s2idle = intel_idle_s2idle, }, + { + .enter = NULL } +}; + static struct cpuidle_state atom_cstates[] = { { .name = "C1E", @@ -744,6 +784,7 @@ static struct cpuidle_state atom_cstates[] = { { .enter = NULL } }; + static struct cpuidle_state tangier_cstates[] = { { .name = "C1", @@ -1089,6 +1130,12 @@ static const struct idle_cpu idle_cpu_avn = { .disable_promotion_to_c1e = true, }; +static const struct idle_cpu idle_cpu_spr __initconst = { + .state_table = spr_cstates, + .disable_promotion_to_c1e = true, + .use_acpi = true, +}; + static const struct idle_cpu idle_cpu_knl = { .state_table = knl_cstates, }; @@ -1135,6 +1182,7 @@ static const struct x86_cpu_id intel_idle_ids[] __initconst = { INTEL_CPU_FAM6(KABYLAKE_L, idle_cpu_skl), INTEL_CPU_FAM6(KABYLAKE, idle_cpu_skl), INTEL_CPU_FAM6(SKYLAKE_X, idle_cpu_skx), + INTEL_CPU_FAM6(SAPPHIRERAPIDS_X, idle_cpu_spr), INTEL_CPU_FAM6(XEON_PHI_KNL, idle_cpu_knl), INTEL_CPU_FAM6(XEON_PHI_KNM, idle_cpu_knl), INTEL_CPU_FAM6(ATOM_GOLDMONT, idle_cpu_bxt), From patchwork Wed Sep 11 04:27:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983636 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SHm4BMyz1y1C for ; Wed, 11 Sep 2024 14:28:36 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExw-0005WN-Br; Wed, 11 Sep 2024 04:28:28 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExv-0005QX-BD for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:28:27 +0000 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (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 smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 1106B3F17F for ; Wed, 11 Sep 2024 04:28:27 +0000 (UTC) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2053f49d0c9so4731065ad.1 for ; Tue, 10 Sep 2024 21:28:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028905; x=1726633705; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W96lZ23O9XHZWqwQo/bubosV6E+Z0P/2cuelyN4WnGI=; b=Mb1TnH8ROG/osEqUeLWVH7+epi+eXeOCXKWkfPXN86wQpi4DiFPu5I/Ctqe71EJVOd zHq3V1UIGGGYSMD28u0YZdNMFPwRiT1yMAgdQPxCzm7dxURCeQtZfoBT9KyHohE+nAcQ zDnHO8ONy7kIAu9afQ+FaSXdf2dCzKBBicVrst3fKWBBTCSX0BI5QXfk8fxTn2dnhcRZ 8t0EziajG2D90nJMKtds18MQ4PQ9Uru2rS/ldwo14d80WE5PIy6FLHZcosmEnDDKBrhu O3MDqIdZuQ7VBVDuTygzgCnXLj+BGKgGULb+8ROqa2Da8/jgve4Fwl+QKcvQ26Fwb3Ta fjuw== X-Gm-Message-State: AOJu0YxXKdZr0uF19UTseRCr13maSSSNxQvlI8T0pE5606Ge3pfAdRGC YlvSo9mrVAjx8wXC1QH2Rrpmp2OfHAJReI9DhVanfddZgz0c/PGqTNpnjS6/dgJurR6aO53d3sL JmjTc9z4whYPoN0uzFpwY00e88XCwk/sv7xcodxNq7C/96+TS2gWAIcVFnt/LbE1y+hqnzj8UTL PTxb5IZBma X-Received: by 2002:a17:902:f785:b0:206:8d6e:d003 with SMTP id d9443c01a7336-2074cb33ff3mr41272935ad.4.1726028905446; Tue, 10 Sep 2024 21:28:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUBB/ASZKj5OwrQKhiM9T4xG/ilvWUAATVrQ53mAMHQ/rgcPEBGqxbe9qSRV+z1/drl7HI/A== X-Received: by 2002:a17:902:f785:b0:206:8d6e:d003 with SMTP id d9443c01a7336-2074cb33ff3mr41272725ad.4.1726028905062; Tue, 10 Sep 2024 21:28:25 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20710ee1edasm55858435ad.167.2024.09.10.21.28.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:28:24 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 16/17] UBUNTU: SAUCE: x86/cpu: Add Emerald Rapids CPU model number Date: Wed, 11 Sep 2024 01:27:25 -0300 Message-Id: <20240911042726.959018-17-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/2080324 Based on upstream commit id 7beade0dd41d ("x86/cpu: Add several Intel server CPU model numbers"), but bring only the model number for emerald rapids. Signed-off-by: Marcelo Henrique Cerri --- arch/x86/include/asm/intel-family.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/include/asm/intel-family.h b/arch/x86/include/asm/intel-family.h index 28a74f22e49a..b959620ded6d 100644 --- a/arch/x86/include/asm/intel-family.h +++ b/arch/x86/include/asm/intel-family.h @@ -104,6 +104,8 @@ #define INTEL_FAM6_SAPPHIRERAPIDS_X 0x8F +#define INTEL_FAM6_EMERALDRAPIDS_X 0xCF + /* "Small Core" Processors (Atom) */ #define INTEL_FAM6_ATOM_BONNELL 0x1C /* Diamondville, Pineview */ From patchwork Wed Sep 11 04:27:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1983637 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3SHq66rLz1y1C for ; Wed, 11 Sep 2024 14:28:39 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1soExz-0005hW-Mc; Wed, 11 Sep 2024 04:28:31 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soExy-0005ay-6T for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 04:28:30 +0000 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (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 smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 08EB83F12E for ; Wed, 11 Sep 2024 04:28:30 +0000 (UTC) Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-20537e42b7aso90065485ad.2 for ; Tue, 10 Sep 2024 21:28:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726028908; x=1726633708; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1hBi5MVJ5Qv67eR1cAb4awAM5WqxjtareYJ7N8XN+UE=; b=vPANAi/d2ktv6Z2g0hIP4GuXqme3oVIBeXAg3Y3uLS8eQPBZ9hyg1ZsdqCDIuhLhp+ 84U1vR2Rv7MTvoSZMR4Eu59Drw/95FXD8gO71BCKjMPSkZR/2GJGQOrNnQ0smvy0QTOL tXFY4JvRGQY254U2cqS+IRt4KC6bv5fWFdelPNT/lEbGzlh82Ce273ceJ+rOwYerDriM 6h1MjgffgLFUkDHQstfFiN1P8Jb2uQG1hbsh2k3PB4/9K6P8BZ70UU2Z4IJsc6kZDAzs Sf1T8QCicLRIsZVBAWsDcWmnhYhGZcQ8xEXt7cM/6JHu34FjxwjBdY/MulxOonDA8MOg +0SA== X-Gm-Message-State: AOJu0YydQeoddoS+OE370rbeWatAprfUWJYteO+QcNZYtihEzUdmCL8c OGLzu0NLQ+GQHVC/ZlLwXrVhz5u+Nm2xXRZjXoPQ0M74ZO9ziMbGfGZOai2UJihwJ/Ztvf2t3GB WSRsThR6g/Od2V+ayUkoZTRA0vi9Z9qrB5Wamp68OsUgyzB/qnZTZW40igDj0RL4gUN05IO8EFA zf0nQjzP8S X-Received: by 2002:a17:902:d4c2:b0:205:489d:628 with SMTP id d9443c01a7336-2074c4d3504mr44572795ad.16.1726028908432; Tue, 10 Sep 2024 21:28:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPKpEaQQBLPlpftYbrfaUbQ0Mc5O44DDhrQ5j8np+iv4hOg9951ZpZ79XfhWNoaDFXyo4iXg== X-Received: by 2002:a17:902:d4c2:b0:205:489d:628 with SMTP id d9443c01a7336-2074c4d3504mr44572655ad.16.1726028908070; Tue, 10 Sep 2024 21:28:28 -0700 (PDT) Received: from canonical.com ([189.78.78.86]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20710eead48sm55301495ad.131.2024.09.10.21.28.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 21:28:27 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [SRU][focal:linux-gcp][PATCH 17/17] intel_idle: add Emerald Rapids Xeon support Date: Wed, 11 Sep 2024 01:27:26 -0300 Message-Id: <20240911042726.959018-18-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911042726.959018-1-marcelo.cerri@canonical.com> References: <20240911042726.959018-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Artem Bityutskiy BugLink: https://bugs.launchpad.net/bugs/2080324 Emerald Rapids (EMR) is the next Intel Xeon processor after Sapphire Rapids (SPR). EMR C-states are the same as SPR C-states, and we expect that EMR C-state characteristics (latency and target residency) will be the same as in SPR. Therefore, add EMR support by using SPR C-states table. Signed-off-by: Artem Bityutskiy Signed-off-by: Rafael J. Wysocki (back ported from commit 74528edfbc664f9d2c927c4e5a44f1285598ed0f) [marcelo.cerri: Fix context in several places and replaced X86_MATCH_INTEL_FAM6_MODEL() with INTEL_CPU_FAM6() and drop support for preferred_cstates from upstream commit id da0e58c038e6 ("intel_idle: add 'preferred_cstates' module argument").] Signed-off-by: Marcelo Henrique Cerri --- drivers/idle/intel_idle.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c index 8d6aa90acf35..768d622646db 100644 --- a/drivers/idle/intel_idle.c +++ b/drivers/idle/intel_idle.c @@ -1183,6 +1183,7 @@ static const struct x86_cpu_id intel_idle_ids[] __initconst = { INTEL_CPU_FAM6(KABYLAKE, idle_cpu_skl), INTEL_CPU_FAM6(SKYLAKE_X, idle_cpu_skx), INTEL_CPU_FAM6(SAPPHIRERAPIDS_X, idle_cpu_spr), + INTEL_CPU_FAM6(EMERALDRAPIDS_X, idle_cpu_spr), INTEL_CPU_FAM6(XEON_PHI_KNL, idle_cpu_knl), INTEL_CPU_FAM6(XEON_PHI_KNM, idle_cpu_knl), INTEL_CPU_FAM6(ATOM_GOLDMONT, idle_cpu_bxt),