Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp180358pxb; Wed, 11 Nov 2020 00:27:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZ7RHdcahK9Yw+lTzdocKdt5vYhmO+UPcpQXHKJhi9c63VuOwpqn7a06bBICq4E5QNDGCC X-Received: by 2002:a17:906:2895:: with SMTP id o21mr25247245ejd.332.1605083261431; Wed, 11 Nov 2020 00:27:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605083261; cv=none; d=google.com; s=arc-20160816; b=XKFfBYm0k4Z8eyrd+m9LFsgHxYjr4MGuIKDUr1DJZosSdSkScZVAN1xXQI4HFfxGsV GbG4hUfWrO6SdaixgsFc8Z/bVDsU98vPjQ8RrSG4Z4Qtvyd6yjf6VPDS2zA+mQmn+tpc wJYyZR0cQAuQ6JoQHgvSRSPobQ7bCN0vMwwEzt3Y6YMu1ChV1OGG6dCdHum0IDKjp9WX 9Fw5YhRlSYROtOSF8vsbZAcfdFCNtCSAwY0VUr+uKLUioX9szTx+oa5PfaXpEDLL2k0L vnXlp2kYuE+v62BgrenQaekbarF0wXgb20pzK8g9LG9oDjDG0/26QAjgX/vWgA/Z0WOc mv6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=WxmguMigCVYdvg/XX4NfDLNdO82BjrGincvzoSF6y1s=; b=lfApA4MDxhiGi8DIGPQ2056bo2Vftbd3cWndRNnb5NMAPoMYVWO3qUAJ+nf3T6Q2nz ERKdOLA7rrq3c0vQvjgmgJ3hUMLa9RxQx/6NFcBckW6xO/ZmHXHWFZSNsnbcrYqFpMMW DjCxuapsPAjBHVjA9nX+RyJFIAmHmeYeBOd3U3VjyW1UVcTG/QzlQn/GO3zTbKCQGNPt SODx3YPtnnL/61YGk9srLwkWi1wndfG6No3U7CRssyFlLyw/dLZk12SOvU/N9RWpEZch gGy8nRwxJOUoPDSQ2cXwUow+FbQeoD+qJvZ0KLrEpodywMliuc8VKqLzRU3W90s3HL1j lWGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=4QmQoj5g; dkim=neutral (no key) header.i=@linutronix.de header.b=RLaBsVgm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n3si977924edo.468.2020.11.11.00.27.14; Wed, 11 Nov 2020 00:27:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=4QmQoj5g; dkim=neutral (no key) header.i=@linutronix.de header.b=RLaBsVgm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726635AbgKKIYp (ORCPT + 99 others); Wed, 11 Nov 2020 03:24:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726298AbgKKIXV (ORCPT ); Wed, 11 Nov 2020 03:23:21 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35430C0613D1; Wed, 11 Nov 2020 00:23:21 -0800 (PST) Date: Wed, 11 Nov 2020 08:23:18 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1605082999; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WxmguMigCVYdvg/XX4NfDLNdO82BjrGincvzoSF6y1s=; b=4QmQoj5gY2Ps1BWCGFkVH0NLRJ5TDGvKjFXz+9A1X1iT2t76QIkEuqDuyepTetYRqHluJI 5N6PrO18l0JT+HAIQOF/Uc7geYKpEk4il1JRSI4OJVbwEJ1cVO0/xORJLpZrU3fbeGaKe5 g1GKmcrHnIfo/bDq9cwkGenvfD3llVAKqNMhZMRVprQ7QyILZLS8l1H7FKCoc+j7hwS3Xa 4AJ+uHF1FZbBhRyeKo2rSMFloCnL+NW5oTlA0BDqJFxDUV1HFbhFTh3q4olDpIC0VGHnXv xycE2DSyCEO4AVLCaLiKUtH9EtQlrPV/bISIkvhLXSY16/zU64SHGnOpvWXGfw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1605082999; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WxmguMigCVYdvg/XX4NfDLNdO82BjrGincvzoSF6y1s=; b=RLaBsVgmkefSJENQmBhjnEqKQS0MTHGCfGbHFVikzGwHPnMyJbydFjBHtpBN28NWCOqDVP Eyv2cpo7USJri8Dg== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/core: Make migrate disable and CPU hotplug cooperative Cc: Thomas Gleixner , "Peter Zijlstra (Intel)" , Valentin Schneider , Daniel Bristot de Oliveira , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20201023102347.067278757@infradead.org> References: <20201023102347.067278757@infradead.org> MIME-Version: 1.0 Message-ID: <160508299865.11244.8558054743131362689.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: 3015ef4b98f53fe7eba4f5f82f562c0e074d213c Gitweb: https://git.kernel.org/tip/3015ef4b98f53fe7eba4f5f82f562c0e074d213c Author: Thomas Gleixner AuthorDate: Wed, 26 Aug 2020 14:08:10 +02:00 Committer: Peter Zijlstra CommitterDate: Tue, 10 Nov 2020 18:39:00 +01:00 sched/core: Make migrate disable and CPU hotplug cooperative On CPU unplug tasks which are in a migrate disabled region cannot be pushed to a different CPU until they returned to migrateable state. Account the number of tasks on a runqueue which are in a migrate disabled section and make the hotplug wait mechanism respect that. Signed-off-by: Thomas Gleixner Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Valentin Schneider Reviewed-by: Daniel Bristot de Oliveira Link: https://lkml.kernel.org/r/20201023102347.067278757@infradead.org --- kernel/sched/core.c | 36 ++++++++++++++++++++++++++++++------ kernel/sched/sched.h | 4 ++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 0efc1e4..6ea593c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1721,10 +1721,17 @@ static void migrate_disable_switch(struct rq *rq, struct task_struct *p) void migrate_disable(void) { - if (current->migration_disabled++) + struct task_struct *p = current; + + if (p->migration_disabled) { + p->migration_disabled++; return; + } - barrier(); + preempt_disable(); + this_rq()->nr_pinned++; + p->migration_disabled = 1; + preempt_enable(); } EXPORT_SYMBOL_GPL(migrate_disable); @@ -1751,6 +1758,7 @@ void migrate_enable(void) */ barrier(); p->migration_disabled = 0; + this_rq()->nr_pinned--; preempt_enable(); } EXPORT_SYMBOL_GPL(migrate_enable); @@ -1760,6 +1768,11 @@ static inline bool is_migration_disabled(struct task_struct *p) return p->migration_disabled; } +static inline bool rq_has_pinned_tasks(struct rq *rq) +{ + return rq->nr_pinned; +} + #endif /* @@ -2693,6 +2706,11 @@ static inline bool is_migration_disabled(struct task_struct *p) return false; } +static inline bool rq_has_pinned_tasks(struct rq *rq) +{ + return false; +} + #endif static void @@ -7066,15 +7084,20 @@ static void balance_push(struct rq *rq) * Both the cpu-hotplug and stop task are in this case and are * required to complete the hotplug process. */ - if (is_per_cpu_kthread(push_task)) { + if (is_per_cpu_kthread(push_task) || is_migration_disabled(push_task)) { /* * If this is the idle task on the outgoing CPU try to wake * up the hotplug control thread which might wait for the * last task to vanish. The rcuwait_active() check is * accurate here because the waiter is pinned on this CPU * and can't obviously be running in parallel. + * + * On RT kernels this also has to check whether there are + * pinned and scheduled out tasks on the runqueue. They + * need to leave the migrate disabled section first. */ - if (!rq->nr_running && rcuwait_active(&rq->hotplug_wait)) { + if (!rq->nr_running && !rq_has_pinned_tasks(rq) && + rcuwait_active(&rq->hotplug_wait)) { raw_spin_unlock(&rq->lock); rcuwait_wake_up(&rq->hotplug_wait); raw_spin_lock(&rq->lock); @@ -7121,7 +7144,8 @@ static void balance_hotplug_wait(void) { struct rq *rq = this_rq(); - rcuwait_wait_event(&rq->hotplug_wait, rq->nr_running == 1, + rcuwait_wait_event(&rq->hotplug_wait, + rq->nr_running == 1 && !rq_has_pinned_tasks(rq), TASK_UNINTERRUPTIBLE); } @@ -7366,7 +7390,7 @@ int sched_cpu_dying(unsigned int cpu) sched_tick_stop(cpu); rq_lock_irqsave(rq, &rf); - BUG_ON(rq->nr_running != 1); + BUG_ON(rq->nr_running != 1 || rq_has_pinned_tasks(rq)); rq_unlock_irqrestore(rq, &rf); calc_load_migrate(rq); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 72d8e47..42de140 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1053,6 +1053,10 @@ struct rq { /* Must be inspected within a rcu lock section */ struct cpuidle_state *idle_state; #endif + +#if defined(CONFIG_PREEMPT_RT) && defined(CONFIG_SMP) + unsigned int nr_pinned; +#endif }; #ifdef CONFIG_FAIR_GROUP_SCHED