mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Suthikulpanit, Suravee" <Suravee.Suthikulpanit@amd.com>
To: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@suse.de>,
	"Suthikulpanit, Suravee" <Suravee.Suthikulpanit@amd.com>
Cc: Ashok Raj <ashok.raj@intel.com>,
	Andi Kleen <andi.kleen@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	"Ravi V. Shankar" <ravi.v.shankar@intel.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Ricardo Neri <ricardo.neri@intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>, Tony Luck <tony.luck@intel.com>,
	Clemens Ladisch <clemens@ladisch.de>,
	Arnd Bergmann <arnd@arndb.de>,
	Philippe Ombredanne <pombredanne@nexb.com>,
	Kate Stewart <kstewart@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Mimi Zohar <zohar@linux.ibm.com>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Nayna Jain <nayna@linux.ibm.com>,
	"Lendacky, Thomas" <Thomas.Lendacky@amd.com>,
	"Grimm, Jon" <Jon.Grimm@amd.com>
Subject: Re: [RFC PATCH v2 11/14] x86/watchdog/hardlockup: Add an HPET-based hardlockup detector
Date: Fri, 5 Apr 2019 16:12:56 +0000	[thread overview]
Message-ID: <b6d0dd2d-4b56-0055-a7e0-51af5c45f959@amd.com> (raw)
In-Reply-To: <1551283518-18922-12-git-send-email-ricardo.neri-calderon@linux.intel.com>

Hi Neri,

While trying out this patch series, I found that it does not work when the HPET timer
is in periodic mode.

On 2/27/19 11:05 PM, Ricardo Neri wrote:
> ......
> diff --git a/arch/x86/kernel/watchdog_hld_hpet.c b/arch/x86/kernel/watchdog_hld_hpet.c
> new file mode 100644
> index 000000000000..cfa284da4bf6
> --- /dev/null
> +++ b/arch/x86/kernel/watchdog_hld_hpet.c
> @@ -0,0 +1,405 @@
> .....
> +
> +/**
> + * set_comparator() - Update the comparator in an HPET timer instance
> + * @hdata:	A data structure with the timer instance to update
> + * @cmp:	The value to write in the in the comparator registere
> + *
> + * Returns:
> + *
> + * None
> + */
> +static inline void set_comparator(struct hpet_hld_data *hdata,
> +				  unsigned long cmp)
> +{
> +	hpet_writeq(cmp, HPET_Tn_CMP(hdata->num));
> +}
> +
> +/**
> + * kick_timer() - Reprogram timer to expire in the future
> + * @hdata:	A data structure with the timer instance to update
> + * @force:	Force reprogram. Useful enabling or re-enabling detector.
> + *
> + * Reprogram the timer to expire within watchdog_thresh seconds in the future.
> + *
> + * Returns:
> + *
> + * None
> + */
> +static void kick_timer(struct hpet_hld_data *hdata, bool force)
> +{
> +	bool kick_needed = force || !(hdata->flags & HPET_DEV_PERI_CAP);
> +	unsigned long new_compare, count;
> +
> +	/*
> +	 * Update the comparator in increments of watch_thresh seconds relative
> +	 * to the current count. Since watch_thresh is given in seconds, we
> +	 * are able to update the comparator before the counter reaches such new
> +	 * value.
> +	 *
> +	 * Let it wrap around if needed.
> +	 */
> +
> +	if (kick_needed) {
> +		count = get_count();
> +
> +		new_compare = count + watchdog_thresh * hdata->ticks_per_second;
> +
> +		set_comparator(hdata, new_compare);
> +	}
> +}

It turns out that the set_comparator() does not seem to support periodic mode,
in which it should have been setting the accumulator/period via the comparator register.

Instead, what if we re-factor the code in the arch/x86/kernel/hpet.c:hpet_set_periodic()
to hpet_set_comparator(). Then we can also reuse it in the arch/x86/kernel/watchdog_hld_pet.c:
kick_timer() as shown below.

With these changes, I can test the series on AMD systems, and see all cores
in /proc/interrupts are receiving NMI interrupts.

Regards,
Suravee


diff --git a/arch/x86/include/asm/hpet.h b/arch/x86/include/asm/hpet.h
index 0976334..f30957f 100644
--- a/arch/x86/include/asm/hpet.h
+++ b/arch/x86/include/asm/hpet.h
@@ -115,6 +115,7 @@ extern int hpet_rtc_timer_init(void);
  extern irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id);
  extern int hpet_register_irq_handler(rtc_irq_handler handler);
  extern void hpet_unregister_irq_handler(rtc_irq_handler handler);
+extern void hpet_set_comparator(int num, unsigned int cmp, unsigned int period);

  #endif /* CONFIG_HPET_EMULATE_RTC */

diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index 03b05dae..f3b2351 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -328,6 +328,41 @@ static void hpet_legacy_clockevent_register(void)
  	printk(KERN_DEBUG "hpet clockevent registered\n");
  }

+/*
+ * hpet_set_comparator() - Helper function for setting comparator register
+ * @num:	The timer ID
+ * @cmp:	The value to be written to the comparator/accumulator
+ * @period:	The value to be written to the period (0 = oneshot mode)
+ *
+ * Helper function for updating comparator, accumulator and period values.
+ *
+ * In periodic mode, HPET needs HPET_TN_SETVAL to be set before writing
+ * to the Tn_CMP to update the accumulator. Then, HPET needs a second
+ * write (with HPET_TN_SETVAL cleared) to Tn_CMP to set the period.
+ * The HPET_TN_SETVAL bit is automatically cleared after the first write.
+ *
+ * For one-shot mode, HPET_TN_SETVAL does not need to be set.
+ *
+ * See the following documents:
+ *   - Intel IA-PC HPET (High Precision Event Timers) Specification
+ *   - AMD-8111 HyperTransport I/O Hub Data Sheet, Publication # 24674
+ */
+void hpet_set_comparator(int num, unsigned int cmp, unsigned int period)
+{
+	if (period) {
+		unsigned int v = hpet_readl(HPET_Tn_CFG(num));
+		hpet_writel(v | HPET_TN_SETVAL, HPET_Tn_CFG(num));
+	}
+
+	hpet_writel(cmp, HPET_Tn_CMP(num));
+	if (!period)
+		return;
+
+	udelay(1);
+	hpet_writel(period, HPET_Tn_CMP(num));
+}
+EXPORT_SYMBOL_GPL(hpet_set_comparator);
+
  static int hpet_set_periodic(struct clock_event_device *evt, int timer)
  {
  	unsigned int cfg, cmp, now;
@@ -339,19 +374,11 @@ static int hpet_set_periodic(struct clock_event_device *evt, int timer)
  	now = hpet_readl(HPET_COUNTER);
  	cmp = now + (unsigned int)delta;
  	cfg = hpet_readl(HPET_Tn_CFG(timer));
-	cfg |= HPET_TN_ENABLE | HPET_TN_PERIODIC | HPET_TN_SETVAL |
-	       HPET_TN_32BIT;
+	cfg |= HPET_TN_ENABLE | HPET_TN_PERIODIC | HPET_TN_32BIT;
  	hpet_writel(cfg, HPET_Tn_CFG(timer));
-	hpet_writel(cmp, HPET_Tn_CMP(timer));
-	udelay(1);
-	/*
-	 * HPET on AMD 81xx needs a second write (with HPET_TN_SETVAL
-	 * cleared) to T0_CMP to set the period. The HPET_TN_SETVAL
-	 * bit is automatically cleared after the first write.
-	 * (See AMD-8111 HyperTransport I/O Hub Data Sheet,
-	 * Publication # 24674)
-	 */
-	hpet_writel((unsigned int)delta, HPET_Tn_CMP(timer));
+
+	hpet_set_comparator(timer, cmp, (unsigned int)delta);
+
  	hpet_start_counter();
  	hpet_print_config();

diff --git a/arch/x86/kernel/watchdog_hld_hpet.c b/arch/x86/kernel/watchdog_hld_hpet.c
index 4402def..de33c50 100644
--- a/arch/x86/kernel/watchdog_hld_hpet.c
+++ b/arch/x86/kernel/watchdog_hld_hpet.c
@@ -35,21 +35,6 @@ static inline unsigned long get_count(void)
  }

  /**
- * set_comparator() - Update the comparator in an HPET timer instance
- * @hdata:	A data structure with the timer instance to update
- * @cmp:	The value to write in the in the comparator registere
- *
- * Returns:
- *
- * None
- */
-static inline void set_comparator(struct hpet_hld_data *hdata,
-				  unsigned long cmp)
-{
-	hpet_writeq(cmp, HPET_Tn_CMP(hdata->num));
-}
-
-/**
   * kick_timer() - Reprogram timer to expire in the future
   * @hdata:	A data structure with the timer instance to update
   * @force:	Force reprogram. Useful enabling or re-enabling detector.
@@ -68,7 +53,7 @@ static inline void set_comparator(struct hpet_hld_data *hdata,
  static void kick_timer(struct hpet_hld_data *hdata, bool force)
  {
  	bool kick_needed = force || !(hdata->flags & HPET_DEV_PERI_CAP);
-	unsigned long tsc_curr, tsc_delta, new_compare, count;
+	unsigned long tsc_curr, tsc_delta, new_compare, count, period = 0;

  	/* Start obtaining the current TSC and HPET counts. */
  	tsc_curr = rdtsc();
@@ -81,6 +66,9 @@ static void kick_timer(struct hpet_hld_data *hdata, bool force)
  	hdata->tsc_next = tsc_curr + tsc_delta;
  	hdata->tsc_next_error = tsc_delta >> 6;

+	if (!kick_needed)
+		return;
+
  	/*
  	 * Update the comparator in increments of watch_thresh seconds relative
  	 * to the current count. Since watch_thresh is given in seconds, we
@@ -89,12 +77,11 @@ static void kick_timer(struct hpet_hld_data *hdata, bool force)
  	 *
  	 * Let it wrap around if needed.
  	 */
+	if (hdata->flags & HPET_DEV_PERI_CAP)
+		period = watchdog_thresh * hdata->ticks_per_second;

-	if (kick_needed) {
-		new_compare = count + watchdog_thresh * hdata->ticks_per_second;
-
-		set_comparator(hdata, new_compare);
-	}
+	new_compare = count + period;
+	hpet_set_comparator(hdata->num, new_compare, period);
  }

  /**
-- 
2.7.4

  parent reply	other threads:[~2019-04-05 16:15 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-27 16:05 [RFC PATCH v2 00/14] Implement " Ricardo Neri
2019-02-27 16:05 ` [RFC PATCH v2 01/14] x86/msi: Add definition for NMI delivery mode Ricardo Neri
2019-02-27 16:05 ` [RFC PATCH v2 02/14] x86/hpet: Expose more functions to read and write registers Ricardo Neri
2019-03-26 21:00   ` Thomas Gleixner
2019-04-09  2:03     ` Ricardo Neri
2019-02-27 16:05 ` [RFC PATCH v2 03/14] x86/hpet: Calculate ticks-per-second in a separate function Ricardo Neri
2019-03-26 21:03   ` Thomas Gleixner
2019-04-09  2:04     ` Ricardo Neri
2019-02-27 16:05 ` [RFC PATCH v2 04/14] x86/hpet: Reserve timer for the HPET hardlockup detector Ricardo Neri
2019-02-27 16:05 ` [RFC PATCH v2 05/14] x86/hpet: Relocate flag definitions to a header file Ricardo Neri
2019-03-26 21:11   ` Thomas Gleixner
2019-04-09  2:04     ` Ricardo Neri
2019-02-27 16:05 ` [RFC PATCH v2 06/14] x86/hpet: Configure the timer used by the hardlockup detector Ricardo Neri
2019-03-26 21:13   ` Thomas Gleixner
2019-04-09  2:04     ` Ricardo Neri
2019-02-27 16:05 ` [RFC PATCH v2 07/14] watchdog/hardlockup: Define a generic function to detect hardlockups Ricardo Neri
2019-02-27 16:05 ` [RFC PATCH v2 08/14] watchdog/hardlockup: Decouple the hardlockup detector from perf Ricardo Neri
2019-03-26 21:18   ` Thomas Gleixner
2019-04-09  2:05     ` Ricardo Neri
2019-02-27 16:05 ` [RFC PATCH v2 09/14] watchdog/hardlockup: Make arch_touch_nmi_watchdog() to hpet-based implementation Ricardo Neri
2019-02-27 16:17   ` Paul E. McKenney
2019-03-01  1:17     ` Ricardo Neri
2019-03-26 21:20       ` Thomas Gleixner
2019-04-09  2:05         ` Ricardo Neri
2019-02-27 16:05 ` [RFC PATCH v2 10/14] kernel/watchdog: Add a function to obtain the watchdog_allowed_mask Ricardo Neri
2019-03-26 21:22   ` Thomas Gleixner
2019-04-09  2:05     ` Ricardo Neri
2019-04-09 11:34   ` Peter Zijlstra
2019-04-11  1:15     ` Ricardo Neri
2019-02-27 16:05 ` [RFC PATCH v2 11/14] x86/watchdog/hardlockup: Add an HPET-based hardlockup detector Ricardo Neri
2019-03-26 20:49   ` Thomas Gleixner
2019-04-09  2:02     ` Ricardo Neri
2019-04-09 10:59     ` Peter Zijlstra
2019-04-10  1:13       ` Ricardo Neri
2019-04-05 16:12   ` Suthikulpanit, Suravee [this message]
2019-04-09  2:14     ` Ricardo Neri
2019-04-09 11:03   ` Peter Zijlstra
2019-04-10  1:05     ` Ricardo Neri
2019-02-27 16:05 ` [RFC PATCH v2 12/14] x86/watchdog/hardlockup/hpet: Determine if HPET timer caused NMI Ricardo Neri
2019-03-26 20:55   ` Thomas Gleixner
2019-04-09  2:02     ` Ricardo Neri
2019-04-09 11:28   ` Peter Zijlstra
2019-04-10  1:19     ` Ricardo Neri
2019-04-10  7:01       ` Peter Zijlstra
2019-04-11  1:12         ` Ricardo Neri
2019-02-27 16:05 ` [RFC PATCH v2 13/14] watchdog/hardlockup/hpet: Only enable the HPET watchdog via a boot parameter Ricardo Neri
2019-03-26 21:29   ` Thomas Gleixner
2019-04-09  2:07     ` Ricardo Neri
2019-02-27 16:05 ` [RFC PATCH v2 14/14] x86/watchdog: Add a shim hardlockup detector 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=b6d0dd2d-4b56-0055-a7e0-51af5c45f959@amd.com \
    --to=suravee.suthikulpanit@amd.com \
    --cc=Jon.Grimm@amd.com \
    --cc=Thomas.Lendacky@amd.com \
    --cc=andi.kleen@intel.com \
    --cc=arnd@arndb.de \
    --cc=ashok.raj@intel.com \
    --cc=bp@suse.de \
    --cc=clemens@ladisch.de \
    --cc=hpa@zytor.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kstewart@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=nayna@linux.ibm.com \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=pombredanne@nexb.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=ravi.v.shankar@intel.com \
    --cc=ricardo.neri-calderon@linux.intel.com \
    --cc=ricardo.neri@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.org \
    --cc=yamada.masahiro@socionext.com \
    --cc=zohar@linux.ibm.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®