mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
	 Daniel Lezcano <daniel.lezcano@kernel.org>,
	Zhang Rui <rui.zhang@intel.com>,
	 Lukasz Luba <lukasz.luba@arm.com>,
	 Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: linux-pm@vger.kernel.org, linux-api@vger.kernel.org,
	 linux-kernel@vger.kernel.org, ricardo.neri@intel.com,
	 Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Subject: [PATCH 08/13] thermal: intel: dpti: Factor the programming sequence out into a helper
Date: Mon, 09 Nov 2026 19:36:35 -0800	[thread overview]
Message-ID: <20261109-dpti-custom-cpu-v1-8-ead8e2d2067e@linux.intel.com> (raw)
In-Reply-To: <20261109-dpti-custom-cpu-v1-0-ead8e2d2067e@linux.intel.com>

The hardware programming sequence for the directed package-level thermal
interrupt (DPTI) is embedded in dpti_online(): clear the acknowledgment
status, enable the interrupt, wait for the hardware to acknowledge, and
roll back on failure. The syscore resume callback reuses it to
unconditionally restore the DPTI on CPU0.

The programming sequence will have to run on a selected owner CPU. CPU0
will no longer always be the boot package's owner. The syscore resume
callback then cannot reuse dpti_online().

Factor the sequence out into dpti_program_this_cpu() and call it from both
the online callback and syscore resume. Its unused argument gives it the
callback signature, so that it can run on a remote CPU via
smp_call_on_cpu(). The syscore callbacks now act only if CPU0 owns the
DPTI.

Add dpti_lookup_pkg_id() to check, at entry points, that a CPU's package
has per-package state, and dpti_pkg_of_cpu_nocheck() for code that runs
after that check. Owner selection and the sysfs interface will reuse them.

No locking is needed in the syscore path: interrupts are disabled and
only the boot CPU is online at this point.

A suspend and resume cycle leaves the same state as before: the DPTI
directed to CPU0, or broadcasting if the hardware does not acknowledge.

Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
---
 drivers/thermal/intel/therm_throt.c | 83 ++++++++++++++++++++++++++++++-------
 1 file changed, 68 insertions(+), 15 deletions(-)

diff --git a/drivers/thermal/intel/therm_throt.c b/drivers/thermal/intel/therm_throt.c
index 36cdbe0eb6c1..72dabffe3b2f 100644
--- a/drivers/thermal/intel/therm_throt.c
+++ b/drivers/thermal/intel/therm_throt.c
@@ -519,6 +519,25 @@ static void dpti_config_ipi(void *info)
 	dpti_config_this_cpu(*((bool *)info));
 }
 
+/* The unused argument matches the smp_call_on_cpu() callback signature. */
+static int dpti_program_this_cpu(void *unused)
+{
+	int ret;
+
+	thermal_clear_package_intr_status(PACKAGE_LEVEL,
+					  PACKAGE_THERM_STATUS_DPTI_ACK);
+
+	dpti_config_this_cpu(true);
+	ret = dpti_wait_for_ack();
+	if (!ret)
+		return 0;
+
+	/* Undo the enable on failure, leaving the package as it was before. */
+	dpti_config_this_cpu(false);
+
+	return ret;
+}
+
 /**
  * struct dpti_pkg - Per-package DPTI state
  * @owner:	CPU currently programmed to receive the package-level
@@ -560,6 +579,38 @@ static bool dpti_supported(void)
 	return true;
 }
 
+static int dpti_lookup_pkg_id(unsigned int cpu, u16 *pkg_id)
+{
+	u16 id;
+
+	if (!dpti_supported())
+		return -ENODEV;
+
+	id = topology_logical_package_id(cpu);
+	if (id >= topology_max_packages())
+		return -ENODEV;
+
+	*pkg_id = id;
+
+	return 0;
+}
+
+/* For callers already past dpti_lookup_pkg_id(). */
+static struct dpti_pkg *dpti_pkg_of_cpu_nocheck(unsigned int cpu)
+{
+	return &dpti_pkgs[topology_logical_package_id(cpu)];
+}
+
+static bool dpti_cpu_is_owner(unsigned int cpu)
+{
+	u16 pkg_id;
+
+	if (dpti_lookup_pkg_id(cpu, &pkg_id))
+		return false;
+
+	return dpti_pkgs[pkg_id].owner == cpu;
+}
+
 /*
  * Must be called with cpu_hotplug_lock held to prevent CPUs from going offline
  * while iterating through packages and interrupts must be enabled to avoid
@@ -590,6 +641,7 @@ static void dpti_clear_all(void)
 static int dpti_online(unsigned int cpu)
 {
 	u16 pkg_id;
+	int ret;
 
 	if (!dpti_supported())
 		return 0;
@@ -605,19 +657,13 @@ static int dpti_online(unsigned int cpu)
 	if (dpti_pkgs[pkg_id].owner != nr_cpu_ids)
 		return 0;
 
-	thermal_clear_package_intr_status(PACKAGE_LEVEL,
-					  PACKAGE_THERM_STATUS_DPTI_ACK);
-
-	dpti_config_this_cpu(true);
-	if (!dpti_wait_for_ack()) {
-		dpti_pkgs[pkg_id].owner = cpu;
-		return 0;
-	}
+	ret = dpti_program_this_cpu(NULL);
+	if (ret)
+		return ret;
 
-	/* Roll back on failure so the package reverts to broadcasting mode. */
-	dpti_config_this_cpu(false);
+	dpti_pkgs[pkg_id].owner = cpu;
 
-	return -ETIMEDOUT;
+	return 0;
 }
 
 static void dpti_offline(unsigned int cpu)
@@ -695,16 +741,23 @@ static void dpti_offline(unsigned int cpu)
  */
 static void dpti_syscore_resume(void *data)
 {
+	if (!dpti_cpu_is_owner(0))
+		return;
+
+	if (!dpti_program_this_cpu(NULL))
+		return;
+
 	/*
-	 * We can't do anything to handle errors. If direction fails for CPU0,
-	 * another CPU will take over during CPU hotplug.
+	 * Let another CPU take over via CPU hotplug. No lock is needed here:
+	 * only CPU0 is online and interrupts are disabled.
 	 */
-	dpti_online(0);
+	dpti_pkg_of_cpu_nocheck(0)->owner = nr_cpu_ids;
 }
 
 static int dpti_syscore_suspend(void *data)
 {
-	dpti_offline(0);
+	if (dpti_cpu_is_owner(0))
+		dpti_config_this_cpu(false);
 
 	return 0;
 }

-- 
2.43.0


  parent reply	other threads:[~2026-11-10  3:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10  3:36 [PATCH 00/13] thermal: intel: dpti: Direct the package thermal interrupt to a chosen CPU Ricardo Neri
2026-11-10  3:36 ` [PATCH 01/13] thermal: intel: Keep directed package interrupts off after syscore shutdown Ricardo Neri
2026-11-10  3:36 ` [PATCH 02/13] thermal: intel: Prefix log messages via pr_fmt() Ricardo Neri
2026-11-10  3:36 ` [PATCH 03/13] thermal: intel: Move the sysfs device helpers next to their callers Ricardo Neri
2026-11-10  3:36 ` [PATCH 04/13] thermal: intel: dpti: Adopt the dpti_ prefix and the owner terminology Ricardo Neri
2026-11-10  3:36 ` [PATCH 05/13] thermal: intel: dpti: Tear down DPTI only during boot Ricardo Neri
2026-11-10  3:36 ` [PATCH 06/13] thermal: intel: dpti: Introduce struct dpti_pkg for per-package state Ricardo Neri
2026-11-10  3:36 ` [PATCH 07/13] thermal: intel: dpti: Configure the local CPU by value Ricardo Neri
2026-11-10  3:36 ` Ricardo Neri [this message]
2026-11-10  3:36 ` [PATCH 09/13] thermal: intel: dpti: Program the directed interrupt on the target CPU Ricardo Neri
2026-11-10  3:36 ` [PATCH 10/13] thermal: intel: dpti: Add rank-based owner selection Ricardo Neri
2026-11-10  3:36 ` [PATCH 11/13] thermal: intel: dpti: Serialize updates to the directed interrupt state Ricardo Neri
2026-11-10  3:36 ` [PATCH 12/13] thermal: intel: dpti: Avoid nohz_full CPUs when possible Ricardo Neri
2026-11-10  3:36 ` [PATCH 13/13] thermal: intel: dpti: Add sysfs control of interrupt owner Ricardo Neri

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261109-dpti-custom-cpu-v1-8-ead8e2d2067e@linux.intel.com \
    --to=ricardo.neri-calderon@linux.intel.com \
    --cc=daniel.lezcano@kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=rafael@kernel.org \
    --cc=ricardo.neri@intel.com \
    --cc=rui.zhang@intel.com \
    --cc=srinivas.pandruvada@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®