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; }