Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp396273imm; Thu, 6 Sep 2018 04:21:01 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaLSseKRDfJBbRVtdjVvklvfdoo/vUmUBb7AhPNX2cVMUgOtXIdNjKN/1Jr35E+FF9wUWdf X-Received: by 2002:a17:902:864b:: with SMTP id y11-v6mr2133425plt.335.1536232861355; Thu, 06 Sep 2018 04:21:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536232861; cv=none; d=google.com; s=arc-20160816; b=BuXuGJxgYUdDT0kMqUNhwoAEjIjEEeLGUSZ65NAPigOZ9FFqNjxMtdYCiyuM+lO2LQ Eje3MylaxcPs/F7Otkz82KY1BFwr0iKibRaXsOx3j5pcV1TTCOwJWQ1gFeZz9/wldAM4 q1nDPTHoEsIfkY3B2u5urKi5Q4yqZdeEZrr0CPDUtRvQ4hHwarM2NcLPNY58zSzx2291 oI+i0w3VNqfMvKQsGAweErrJJRBnMZ7m0rBykB5XsRWdwtyJ2XZzrkpZ/W2nLWfj/lKO N6YYXt5Sf1RxAlKlI8UzvNh48BAU3DkPH94JZRYFlzaIHe1ea9ykvkN2p/NLGoGYhjLg t/5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=U1e5YIeJBa4sgAdzR/Jll7WtDtd6p66drLq31Fr4xfM=; b=XU5wfxeURsEccPRSUzUlWOT7obtoPFFgyo9ukZ1MoDhdIVEFDlJSeUcJ2koi2boDTE QkdfvKIzeJyCCqJalADGcpfzmoT2ZVOpT0+J8qhmkcGyZmBD2CJD0nP81+vHrTrrWPZD twISt3+CE+Lb90G/hLowM5PwvVMn4B7F8DFKGwsKkowny/iBFHtQ9bKe7TpwIGF26iHe Y7k+PYXm14/OKy1+po5Uhj0rnGvZ++YXjCbLE1bC0UHfDCol5tXFfLK7UcNzPzm2O2z9 5+LgZ9wemCY7RjwH84BcAvc+h43yKWcFo3ENCzbrSOdJ3V1dr9eu52YK8SHPoukC+kZA mX6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k130-v6si5231887pfc.282.2018.09.06.04.20.45; Thu, 06 Sep 2018 04:21:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727729AbeIFPXT (ORCPT + 99 others); Thu, 6 Sep 2018 11:23:19 -0400 Received: from terminus.zytor.com ([198.137.202.136]:60779 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726349AbeIFPXS (ORCPT ); Thu, 6 Sep 2018 11:23:18 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w86Ak7qr264532 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 6 Sep 2018 03:46:07 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w86Ak58p264515; Thu, 6 Sep 2018 03:46:05 -0700 Date: Thu, 6 Sep 2018 03:46:05 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Peter Zijlstra Message-ID: Cc: mingo@kernel.org, frame@mailbox.org, peterz@infradead.org, linux-kernel@vger.kernel.org, kevin@shanahan.id.au, niklas.cassel@linaro.org, tglx@linutronix.de, hpa@zytor.com Reply-To: niklas.cassel@linaro.org, tglx@linutronix.de, hpa@zytor.com, mingo@kernel.org, frame@mailbox.org, peterz@infradead.org, linux-kernel@vger.kernel.org, kevin@shanahan.id.au In-Reply-To: <20180905084158.GR24124@hirez.programming.kicks-ass.net> References: <20180905084158.GR24124@hirez.programming.kicks-ass.net> To: linux-tip-commits@vger.kernel.org Subject: [tip:timers/urgent] clocksource: Revert "Remove kthread" Git-Commit-ID: 760902b24960679c2e8592de3a56359d2c205731 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 760902b24960679c2e8592de3a56359d2c205731 Gitweb: https://git.kernel.org/tip/760902b24960679c2e8592de3a56359d2c205731 Author: Peter Zijlstra AuthorDate: Wed, 5 Sep 2018 10:41:58 +0200 Committer: Thomas Gleixner CommitDate: Thu, 6 Sep 2018 12:42:28 +0200 clocksource: Revert "Remove kthread" I turns out that the silly spawn kthread from worker was actually needed. clocksource_watchdog_kthread() cannot be called directly from clocksource_watchdog_work(), because clocksource_select() calls timekeeping_notify() which uses stop_machine(). One cannot use stop_machine() from a workqueue() due lock inversions wrt CPU hotplug. Revert the patch but add a comment that explain why we jump through such apparently silly hoops. Fixes: 7197e77abcb6 ("clocksource: Remove kthread") Reported-by: Siegfried Metz Signed-off-by: Peter Zijlstra (Intel) Tested-by: Niklas Cassel Tested-by: Kevin Shanahan Tested-by: viktor_jaegerskuepper@freenet.de Tested-by: Siegfried Metz Cc: rafael.j.wysocki@intel.com Cc: len.brown@intel.com Cc: diego.viola@gmail.com Cc: rui.zhang@intel.com Cc: bjorn.andersson@linaro.org Link: https://lkml.kernel.org/r/20180905084158.GR24124@hirez.programming.kicks-ass.net --- kernel/time/clocksource.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index f74fb00d8064..0e6e97a01942 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -133,19 +133,40 @@ static void inline clocksource_watchdog_unlock(unsigned long *flags) spin_unlock_irqrestore(&watchdog_lock, *flags); } +static int clocksource_watchdog_kthread(void *data); +static void __clocksource_change_rating(struct clocksource *cs, int rating); + /* * Interval: 0.5sec Threshold: 0.0625s */ #define WATCHDOG_INTERVAL (HZ >> 1) #define WATCHDOG_THRESHOLD (NSEC_PER_SEC >> 4) +static void clocksource_watchdog_work(struct work_struct *work) +{ + /* + * We cannot directly run clocksource_watchdog_kthread() here, because + * clocksource_select() calls timekeeping_notify() which uses + * stop_machine(). One cannot use stop_machine() from a workqueue() due + * lock inversions wrt CPU hotplug. + * + * Also, we only ever run this work once or twice during the lifetime + * of the kernel, so there is no point in creating a more permanent + * kthread for this. + * + * If kthread_run fails the next watchdog scan over the + * watchdog_list will find the unstable clock again. + */ + kthread_run(clocksource_watchdog_kthread, NULL, "kwatchdog"); +} + static void __clocksource_unstable(struct clocksource *cs) { cs->flags &= ~(CLOCK_SOURCE_VALID_FOR_HRES | CLOCK_SOURCE_WATCHDOG); cs->flags |= CLOCK_SOURCE_UNSTABLE; /* - * If the clocksource is registered clocksource_watchdog_work() will + * If the clocksource is registered clocksource_watchdog_kthread() will * re-rate and re-select. */ if (list_empty(&cs->list)) { @@ -156,7 +177,7 @@ static void __clocksource_unstable(struct clocksource *cs) if (cs->mark_unstable) cs->mark_unstable(cs); - /* kick clocksource_watchdog_work() */ + /* kick clocksource_watchdog_kthread() */ if (finished_booting) schedule_work(&watchdog_work); } @@ -166,7 +187,7 @@ static void __clocksource_unstable(struct clocksource *cs) * @cs: clocksource to be marked unstable * * This function is called by the x86 TSC code to mark clocksources as unstable; - * it defers demotion and re-selection to a work. + * it defers demotion and re-selection to a kthread. */ void clocksource_mark_unstable(struct clocksource *cs) { @@ -391,9 +412,7 @@ static void clocksource_dequeue_watchdog(struct clocksource *cs) } } -static void __clocksource_change_rating(struct clocksource *cs, int rating); - -static int __clocksource_watchdog_work(void) +static int __clocksource_watchdog_kthread(void) { struct clocksource *cs, *tmp; unsigned long flags; @@ -418,12 +437,13 @@ static int __clocksource_watchdog_work(void) return select; } -static void clocksource_watchdog_work(struct work_struct *work) +static int clocksource_watchdog_kthread(void *data) { mutex_lock(&clocksource_mutex); - if (__clocksource_watchdog_work()) + if (__clocksource_watchdog_kthread()) clocksource_select(); mutex_unlock(&clocksource_mutex); + return 0; } static bool clocksource_is_watchdog(struct clocksource *cs) @@ -442,7 +462,7 @@ static void clocksource_enqueue_watchdog(struct clocksource *cs) static void clocksource_select_watchdog(bool fallback) { } static inline void clocksource_dequeue_watchdog(struct clocksource *cs) { } static inline void clocksource_resume_watchdog(void) { } -static inline int __clocksource_watchdog_work(void) { return 0; } +static inline int __clocksource_watchdog_kthread(void) { return 0; } static bool clocksource_is_watchdog(struct clocksource *cs) { return false; } void clocksource_mark_unstable(struct clocksource *cs) { } @@ -810,7 +830,7 @@ static int __init clocksource_done_booting(void) /* * Run the watchdog first to eliminate unstable clock sources */ - __clocksource_watchdog_work(); + __clocksource_watchdog_kthread(); clocksource_select(); mutex_unlock(&clocksource_mutex); return 0;