From: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@suse.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>, Ashok Raj <ashok.raj@intel.com>,
Andi Kleen <ak@linux.intel.com>, Tony Luck <tony.luck@intel.com>,
Nicholas Piggin <npiggin@gmail.com>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
Stephane Eranian <eranian@google.com>,
Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>,
"Ravi V. Shankar" <ravi.v.shankar@intel.com>,
Ricardo Neri <ricardo.neri@intel.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
Ricardo Neri <ricardo.neri-calderon@linux.intel.com>,
Andi Kleen <andi.kleen@intel.com>
Subject: [RFC PATCH v5 09/16] watchdog/hardlockup/hpet: Group packages receiving IPIs when needed
Date: Tue, 4 May 2021 12:05:19 -0700 [thread overview]
Message-ID: <20210504190526.22347-10-ricardo.neri-calderon@linux.intel.com> (raw)
In-Reply-To: <20210504190526.22347-1-ricardo.neri-calderon@linux.intel.com>
In order to keep the HPET interrupts of the hardlockup detector at a rate
of one per second or less frequent, the HPET timer only targets one of
the CPUs monitored by the detector. This is the handling CPU. The rest of
the CPUs are monitored via an IPI issued by the handling CPUs.
Furthermore, the monitored CPUs are partitioned into groups. Groups are
targeted by the HPET timer in a round-robin manner. A group is composed of
of all the CPUs in a physical package.
There may be situations in which it is not possible to keep the
aforementioned HPET interrupt rate. This may happen if, for instance,
watchdog_thresh is set to 1 second and there are more than one package in
the system. In such case, the HPET timer should expire 1/nr_packages
seconds.
It is possible to keep the HPET timer expiration at one second or less
frequent if the packages receiving the IPI are grouped together. Hence,
in the example above, all packages would be grouped together.
This approach has the drawback of having to issue IPIs across packages
However, these cases should be rare: only when there are more packages
than the value of watchdog_thresh in seconds.
Implement functionality to use the logic above: when the hardlockup
detector is enabled in a CPU, check if grouping is necessary based in the
value of watchdog_thresh. When updating target_cpumask, do it as many
times as packages in the group.
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ashok Raj <ashok.raj@intel.com>
Cc: Andi Kleen <andi.kleen@intel.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: "Ravi V. Shankar" <ravi.v.shankar@intel.com>
Cc: x86@kernel.org
Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
---
Changes since v4:
* Introduced this patch.
Changes since v3:
* N/A
Changes since v2:
* N/A
Changes since v1:
*N/A
---
arch/x86/include/asm/hpet.h | 6 +++
arch/x86/kernel/watchdog_hld_hpet.c | 75 ++++++++++++++++++++++++-----
2 files changed, 68 insertions(+), 13 deletions(-)
diff --git a/arch/x86/include/asm/hpet.h b/arch/x86/include/asm/hpet.h
index 8aea54f412e0..bb76f54effe4 100644
--- a/arch/x86/include/asm/hpet.h
+++ b/arch/x86/include/asm/hpet.h
@@ -104,6 +104,10 @@ extern void hpet_unregister_irq_handler(rtc_irq_handler handler);
* @ticks_per_second: Frequency of the HPET timer
* @irq: IRQ number assigned to the HPET channel
* @handling_cpu: CPU handling the HPET interrupt
+ * @pkgs_per_group: Number of physical packages in a group of CPUs
+ * receiving an IPI
+ * @nr_groups: Number of groups into which @monitored_cpumask
+ * is partitioned
* @msi_msg: MSI message to be written it the HPET registers
* @affinity_work: Used to update the affinity of the detector
* interrupts, both IPI and NMI.
@@ -121,6 +125,8 @@ struct hpet_hld_data {
u64 ticks_per_second;
int irq;
u32 handling_cpu;
+ u32 pkgs_per_group;
+ u32 nr_groups;
struct msi_msg msi_msg;
struct irq_work affinity_work;
cpumask_var_t monitored_cpumask;
diff --git a/arch/x86/kernel/watchdog_hld_hpet.c b/arch/x86/kernel/watchdog_hld_hpet.c
index a363f3cd45dd..04b354a35e68 100644
--- a/arch/x86/kernel/watchdog_hld_hpet.c
+++ b/arch/x86/kernel/watchdog_hld_hpet.c
@@ -235,26 +235,71 @@ static void update_ipi_target_cpumask(struct hpet_hld_data *hdata)
retry:
cpumask_clear(hdata->target_cpumask);
- next_cpu = get_first_cpu_in_next_pkg(next_cpu, hdata);
- if (next_cpu < 0 || next_cpu >= nr_cpu_ids) {
- /*
- * If a CPU in a next package was not identified,
- * fallback to the first monitored CPU instead of
- * bailing out.
- */
- next_cpu = cpumask_first(hdata->monitored_cpumask);
- goto retry;
+ for (i = 0 ; i < hdata->pkgs_per_group; i++) {
+ next_cpu = get_first_cpu_in_next_pkg(next_cpu, hdata);
+ if (next_cpu < 0 || next_cpu >= nr_cpu_ids) {
+ /*
+ * If a CPU in a next package was not identified,
+ * fallback to the first monitored CPU instead of
+ * bailing out.
+ */
+ next_cpu = cpumask_first(hdata->monitored_cpumask);
+ goto retry;
+ }
+
+ /* Select all the CPUs in the same package as @next_cpu */
+ cpumask_or(hdata->target_cpumask, hdata->target_cpumask,
+ topology_core_cpumask(next_cpu));
}
- /* Select all the CPUs in the same package as @next_cpu */
- cpumask_or(hdata->target_cpumask, hdata->target_cpumask,
- topology_core_cpumask(next_cpu));
-
/* Only select the CPUs that need to be monitored */
cpumask_and(hdata->target_cpumask, hdata->target_cpumask,
hdata->monitored_cpumask);
}
+/**
+ * count_monitored_packages() - Count the packages with monitored CPUs
+ * @hdata: A data structure with the monitored cpumask
+ *
+ * Return the number of packages with at least one CPU in the monitored_cpumask
+ * of @hdata
+ */
+static u32 count_monitored_packages(struct hpet_hld_data *hdata)
+{
+ int c = cpumask_first(hdata->monitored_cpumask);
+ u16 start_id, id;
+ u32 nr_pkgs = 0;
+
+ start_id = topology_physical_package_id(c);
+
+ do {
+ nr_pkgs++;
+ c = get_first_cpu_in_next_pkg(c, hdata);
+ id = topology_physical_package_id(c);
+ } while (start_id != id);
+
+ return nr_pkgs;
+}
+
+static void setup_cpu_groups(struct hpet_hld_data *hdata)
+{
+ u32 monitored_pkgs = count_monitored_packages(hdata);
+
+ hdata->pkgs_per_group = 0;
+ hdata->nr_groups = U32_MAX;
+
+ /*
+ * To keep the HPET timer to fire each 1 second or less frequently,
+ * the condition watchdog_thresh >= nr_groups nust be met. Thus,
+ * group together one or more packages until such condition is reached.
+ */
+ while (watchdog_thresh < hdata->nr_groups) {
+ hdata->pkgs_per_group++;
+ hdata->nr_groups = DIV_ROUND_UP(monitored_pkgs,
+ hdata->pkgs_per_group);
+ }
+}
+
static void update_timer_irq_affinity(struct irq_work *work)
{
struct hpet_hld_data *hdata = container_of(work, struct hpet_hld_data,
@@ -378,6 +423,8 @@ void hardlockup_detector_hpet_enable(unsigned int cpu)
{
cpumask_set_cpu(cpu, hld_data->monitored_cpumask);
+ setup_cpu_groups(hld_data);
+
update_ipi_target_cpumask(hld_data);
/*
@@ -421,6 +468,8 @@ void hardlockup_detector_hpet_disable(unsigned int cpu)
hld_data->handling_cpu = cpumask_first(hld_data->monitored_cpumask);
update_msi_destid(hld_data);
+ setup_cpu_groups(hld_data);
+
update_ipi_target_cpumask(hld_data);
enable_timer(hld_data);
--
2.17.1
next prev parent reply other threads:[~2021-05-04 19:07 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-04 19:05 [RFC PATCH v5 00/16] x86: Implement an HPET-based hardlockup detector Ricardo Neri
2021-05-04 19:05 ` [RFC PATCH v5 01/16] x86/hpet: Expose hpet_writel() in header Ricardo Neri
2021-05-04 19:05 ` [RFC PATCH v5 02/16] x86/hpet: Add helper function hpet_set_comparator_periodic() Ricardo Neri
2021-05-04 19:05 ` [RFC PATCH v5 03/16] x86/hpet: Reserve an HPET channel for the hardlockup detector Ricardo Neri
2021-05-04 19:05 ` [RFC PATCH v5 04/16] watchdog/hardlockup: Define a generic function to detect hardlockups Ricardo Neri
2021-05-04 19:05 ` [RFC PATCH v5 05/16] watchdog/hardlockup: Decouple the hardlockup detector from perf Ricardo Neri
2021-05-04 19:05 ` [RFC PATCH v5 06/16] x86/nmi: Add an NMI_WATCHDOG NMI handler category Ricardo Neri
2021-05-04 19:05 ` [RFC PATCH v5 07/16] x86/watchdog/hardlockup: Add an HPET-based hardlockup detector Ricardo Neri
2021-05-04 20:53 ` Thomas Gleixner
2021-05-04 19:05 ` [RFC PATCH v5 08/16] x86/watchdog/hardlockup/hpet: Introduce a target_cpumask Ricardo Neri
2021-05-04 19:05 ` Ricardo Neri [this message]
2021-05-04 19:05 ` [RFC PATCH v5 10/16] watchdog/hardlockup/hpet: Adjust timer expiration on the number of monitored groups Ricardo Neri
2021-05-04 19:05 ` [RFC PATCH v5 11/16] x86/watchdog/hardlockup/hpet: Determine if HPET timer caused NMI Ricardo Neri
2021-05-04 19:05 ` [RFC PATCH v5 12/16] watchdog/hardlockup: Use parse_option_str() to handle "nmi_watchdog" Ricardo Neri
2021-05-04 19:05 ` [RFC PATCH v5 13/16] watchdog/hardlockup/hpet: Only enable the HPET watchdog via a boot parameter Ricardo Neri
2021-05-04 19:05 ` [RFC PATCH v5 14/16] x86/watchdog: Add a shim hardlockup detector Ricardo Neri
2021-05-04 19:05 ` [RFC PATCH v5 15/16] watchdog: Expose lockup_detector_reconfigure() Ricardo Neri
2021-05-04 19:05 ` [RFC PATCH v5 16/16] x86/tsc: Switch to perf-based hardlockup detector if TSC become unstable 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=20210504190526.22347-10-ricardo.neri-calderon@linux.intel.com \
--to=ricardo.neri-calderon@linux.intel.com \
--cc=Suravee.Suthikulpanit@amd.com \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=andi.kleen@intel.com \
--cc=ashok.raj@intel.com \
--cc=bp@suse.de \
--cc=eranian@google.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=npiggin@gmail.com \
--cc=peterz@infradead.org \
--cc=ravi.v.shankar@intel.com \
--cc=ricardo.neri@intel.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
/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®