From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 379EDC04AB7 for ; Tue, 14 May 2019 14:03:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0ACA921537 for ; Tue, 14 May 2019 14:03:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726733AbfENODz (ORCPT ); Tue, 14 May 2019 10:03:55 -0400 Received: from mga05.intel.com ([192.55.52.43]:47289 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726342AbfENODA (ORCPT ); Tue, 14 May 2019 10:03:00 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 May 2019 07:02:59 -0700 X-ExtLoop1: 1 Received: from unknown (HELO luv-build.sc.intel.com) ([172.25.110.25]) by fmsmga005.fm.intel.com with ESMTP; 14 May 2019 07:02:59 -0700 From: Ricardo Neri To: Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Ashok Raj , Joerg Roedel , Andi Kleen , Peter Zijlstra , "Ravi V. Shankar" , x86@kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Ricardo Neri , Ricardo Neri , Tony Luck , Jacob Pan , "Rafael J. Wysocki" , Don Zickus , Nicholas Piggin , Michael Ellerman , Frederic Weisbecker , Alexei Starovoitov , Babu Moger , Mathieu Desnoyers , Masami Hiramatsu , Andrew Morton , Philippe Ombredanne , Colin Ian King , Byungchul Park , "Paul E. McKenney" , "Luis R. Rodriguez" , Waiman Long , Josh Poimboeuf , Randy Dunlap , Davidlohr Bueso , Marc Zyngier , Kai-Heng Feng , Konrad Rzeszutek Wilk , David Rientjes , Stephane Eranian , Suravee Suthikulpanit Subject: [RFC PATCH v3 12/21] watchdog/hardlockup/hpet: Adjust timer expiration on the number of monitored CPUs Date: Tue, 14 May 2019 07:02:05 -0700 Message-Id: <1557842534-4266-13-git-send-email-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1557842534-4266-1-git-send-email-ricardo.neri-calderon@linux.intel.com> References: <1557842534-4266-1-git-send-email-ricardo.neri-calderon@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Each CPU should be monitored for hardlockups every watchdog_thresh seconds. Since all the CPUs in the system are monitored by the same timer and the timer interrupt is rotated among the monitored CPUs, the timer must expire every watchdog_thresh/N seconds; where N is the number of monitored CPUs. Use the new member of struct hld_data, ticks_per_cpu, to store the aforementioned quantity. The ticks-per-CPU quantity is updated every time the number of monitored CPUs changes: when the watchdog is enabled or disabled for a specific CPU. If the timer is used in periodic mode, it needs to be adjusted to reflect the new expected expiration. Cc: Ashok Raj Cc: Andi Kleen Cc: Tony Luck Cc: Borislav Petkov Cc: Jacob Pan Cc: "Rafael J. Wysocki" Cc: Don Zickus Cc: Nicholas Piggin Cc: Michael Ellerman Cc: Frederic Weisbecker Cc: Alexei Starovoitov Cc: Babu Moger Cc: Mathieu Desnoyers Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Andrew Morton Cc: Philippe Ombredanne Cc: Colin Ian King Cc: Byungchul Park Cc: "Paul E. McKenney" Cc: "Luis R. Rodriguez" Cc: Waiman Long Cc: Josh Poimboeuf Cc: Randy Dunlap Cc: Davidlohr Bueso Cc: Marc Zyngier Cc: Kai-Heng Feng Cc: Konrad Rzeszutek Wilk Cc: David Rientjes Cc: Stephane Eranian Cc: Suravee Suthikulpanit Cc: "Ravi V. Shankar" Cc: x86@kernel.org Cc: iommu@lists.linux-foundation.org Signed-off-by: Ricardo Neri --- arch/x86/include/asm/hpet.h | 1 + arch/x86/kernel/watchdog_hld_hpet.c | 46 +++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/hpet.h b/arch/x86/include/asm/hpet.h index 31fc27508cf3..64acacce095d 100644 --- a/arch/x86/include/asm/hpet.h +++ b/arch/x86/include/asm/hpet.h @@ -114,6 +114,7 @@ struct hpet_hld_data { bool has_periodic; u32 num; u64 ticks_per_second; + u64 ticks_per_cpu; u32 handling_cpu; u32 enabled_cpus; struct msi_msg msi_msg; diff --git a/arch/x86/kernel/watchdog_hld_hpet.c b/arch/x86/kernel/watchdog_hld_hpet.c index c20b378b8c0c..9a3431a54616 100644 --- a/arch/x86/kernel/watchdog_hld_hpet.c +++ b/arch/x86/kernel/watchdog_hld_hpet.c @@ -44,6 +44,13 @@ static void kick_timer(struct hpet_hld_data *hdata, bool force) * are able to update the comparator before the counter reaches such new * value. * + * Each CPU must be monitored every watch_thresh seconds. Since the + * timer targets one CPU at a time, it must expire every + * + * ticks_per_cpu = watch_thresh * ticks_per_second /enabled_cpus + * + * as computed in update_ticks_per_cpu(). + * * Let it wrap around if needed. */ @@ -51,10 +58,10 @@ static void kick_timer(struct hpet_hld_data *hdata, bool force) return; if (hdata->has_periodic) - period = watchdog_thresh * hdata->ticks_per_second; + period = watchdog_thresh * hdata->ticks_per_cpu; count = hpet_readl(HPET_COUNTER); - new_compare = count + watchdog_thresh * hdata->ticks_per_second; + new_compare = count + watchdog_thresh * hdata->ticks_per_cpu; hpet_set_comparator(hdata->num, (u32)new_compare, (u32)period); } @@ -233,6 +240,27 @@ static int setup_hpet_irq(struct hpet_hld_data *hdata) return ret; } +/** + * update_ticks_per_cpu() - Update the number of HPET ticks per CPU + * @hdata: struct with the timer's the ticks-per-second and CPU mask + * + * From the overall ticks-per-second of the timer, compute the number of ticks + * after which the timer should expire to monitor each CPU every watch_thresh + * seconds. The ticks-per-cpu quantity is computed using the number of CPUs that + * the watchdog currently monitors. + */ +static void update_ticks_per_cpu(struct hpet_hld_data *hdata) +{ + u64 temp = hdata->ticks_per_second; + + /* Only update if there are monitored CPUs. */ + if (!hdata->enabled_cpus) + return; + + do_div(temp, hdata->enabled_cpus); + hdata->ticks_per_cpu = temp; +} + /** * hardlockup_detector_hpet_enable() - Enable the hardlockup detector * @cpu: CPU Index in which the watchdog will be enabled. @@ -245,13 +273,23 @@ void hardlockup_detector_hpet_enable(unsigned int cpu) { cpumask_set_cpu(cpu, to_cpumask(hld_data->cpu_monitored_mask)); - if (!hld_data->enabled_cpus++) { + hld_data->enabled_cpus++; + update_ticks_per_cpu(hld_data); + + if (hld_data->enabled_cpus == 1) { hld_data->handling_cpu = cpu; update_msi_destid(hld_data); /* Force timer kick when detector is just enabled */ kick_timer(hld_data, true); enable_timer(hld_data); } + + /* + * When in periodic mode, we only kick the timer here. Hence, + * as there are now more CPUs to monitor, we need to adjust the + * periodic expiration. + */ + kick_timer(hld_data, hld_data->has_periodic); } /** @@ -267,6 +305,8 @@ void hardlockup_detector_hpet_disable(unsigned int cpu) cpumask_clear_cpu(cpu, to_cpumask(hld_data->cpu_monitored_mask)); hld_data->enabled_cpus--; + update_ticks_per_cpu(hld_data); + if (hld_data->handling_cpu != cpu) return; -- 2.17.1