Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3541748imm; Wed, 5 Sep 2018 01:44:20 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZKz+K3ANmV8m15REKXvLmJHvyyBf8bWSWqfxXGhMYHqm2Xnjq2tXeH7houWnC6QcAhHezv X-Received: by 2002:a62:9894:: with SMTP id d20-v6mr39240693pfk.186.1536137059982; Wed, 05 Sep 2018 01:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536137059; cv=none; d=google.com; s=arc-20160816; b=dwOQMZoNyiSEdDgdb9GgZMrKXAj5GIEOzzs4GjoAvtToe+ExcqZivZAkxZckEtuQIa +e3pedlB8w/kvG3d/9yhy5BFn+clt+qzKCHSyvuzBQ3fqjd48nhMzCDnxIBWMA7nKjAK PmgRCTnsbfNxxBIVWGfU6IuU0etiLsDQd4Bqaa4II98TpNURYF0gnLb2nZCpvPTh/kNl /tf9+LMR4CzrTrDQXKI3ephK4y8U3DnLWzX/uxyi5UItu/AAVrhj66Pup+KvCFoOqmGZ uMOmUC+EosD+GjGOFgBB+3YovAT+B3wylue1WBA9wjELQ+t2/jolFmWYSkB6YikNoiU9 Fcpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=EV5mjUDfDqZzsNbmaiaPxT8o+PyQBvvsBSCq0GJQao8=; b=XUpwcXTzTvxs/E1UUnZiKfRwvLxyva2LMeZkaaR7PGDYqdWEKsD0N2TyBtpgaKo3XI aYLSbq8/MN+U9sdk5Xxoiul6Jkx6/AP+bPUDQ5dbhq4ZgZtOSF3ptpzjDJYsg9nmicP0 UBbIPHLaZYmnA7V8Gb7VtiBI2MIgr4QrL5H15XPp0T2q8+/URtS4qoV4lFY0KNtiXCtY NoUddIlQgA+cWGVCQwFjfGvbszvfXQgV+QIF9++pxoMYykaxtDvI+t5ae/nZ/FCOWXEO Rzt6CIbDrEw9hOwmWzOryWnOrAzENOihpqJ5T2bbYMLQcWqzulG0kDEr/q/fHQ2fKDRb 3Slw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b="t/7KFJ7n"; 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 d30-v6si1403829pld.452.2018.09.05.01.44.04; Wed, 05 Sep 2018 01:44:19 -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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b="t/7KFJ7n"; 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 S1727851AbeIENLd (ORCPT + 99 others); Wed, 5 Sep 2018 09:11:33 -0400 Received: from merlin.infradead.org ([205.233.59.134]:58300 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726401AbeIENLd (ORCPT ); Wed, 5 Sep 2018 09:11:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=EV5mjUDfDqZzsNbmaiaPxT8o+PyQBvvsBSCq0GJQao8=; b=t/7KFJ7nGMeYnleKhtJ+C4UFi FfFibzkaUGdbHfeuhq3FlKwk0Rlsg8PA4dU0xvKNKht5KQ1dNplvV3UEt/Ygysj2wOiUBu+YP8jpn 50a1f9qz91Hfzgbx26LyO+s+xZwYZ5rzM++mwXxQNYnErIwLv/976WKqNFxgeiG5MYcKqPaWqSv+g hulKivgi7dPui6IxQ8BCU7P2tB2tZRZb/d0RcvltavteBTyyX8PX8g4FNwvrG6RVE8TUO481+EACZ q63BGR9XXWRynJW2qm4Jh5Kaq+dODEOdb0lc+oeB6O6AK+bG4nq1OK2oufWJ8MsZSGhMelg+oMZke pQ2EJ7T7g==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fxTNw-0003z9-Cx; Wed, 05 Sep 2018 08:42:00 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id BF31C20191BFD; Wed, 5 Sep 2018 10:41:58 +0200 (CEST) Date: Wed, 5 Sep 2018 10:41:58 +0200 From: Peter Zijlstra To: Niklas Cassel Cc: Thomas Gleixner , Kevin Shanahan , Siegfried Metz , linux-kernel@vger.kernel.org, rafael.j.wysocki@intel.com, len.brown@intel.com, rjw@rjwysocki.net, diego.viola@gmail.com, rui.zhang@intel.com, viktor_jaegerskuepper@freenet.de, niklas.cassel@linaro.org, bjorn.andersson@linaro.org Subject: [PATCH] clocksource: Revert "Remove kthread" Message-ID: <20180905084158.GR24124@hirez.programming.kicks-ass.net> References: <74c5abc8-7430-5bc9-2f8a-a2205608bee7@mailbox.org> <20180830130439.GM24082@hirez.programming.kicks-ass.net> <20180901022125.GO4941@tuon.disenchant.local> <20180903072506.GS24124@hirez.programming.kicks-ass.net> <20180903085423.GU24124@hirez.programming.kicks-ass.net> <20180903093305.GC24142@hirez.programming.kicks-ass.net> <20180904134450.GA10572@centauri.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180904134450.GA10572@centauri.lan> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 04, 2018 at 03:44:50PM +0200, Niklas Cassel wrote: > watchdog_worker is only defined if CONFIG_CLOCKSOURCE_WATCHDOG is set, > so you might want to wrap it with an ifdef to avoid build errors. Yes, so I wrote a version that only spawned the kthread_worker when a MUST_VERIFY clocksource was registered -- which turned out to be a lot harder than it sounds, because clocksource registration happens _waaay_ before kthreadd gets spawned. But after I finished that I realized that this work only ever runs once or twice during the lifetime of the kernel. So spawning a permanent thread is quite pointless. So lets just revert the patch and add a wee comment there explaining why we spawn the kthread. --- Subject: clocksource: Revert "Remove kthread" It turns out that the silly spawn kthread from worker was actually needed, revert the patch but add a comment that explain why we jump through such apparently silly hoops. Fixes: 7197e77abcb6 ("clocksource: Remove kthread") Signed-off-by: Peter Zijlstra (Intel) --- 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;