Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp312685pxf; Thu, 11 Mar 2021 04:39:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMP26Vd2sgRJL/gxT4036DNIsHhaoV5itcH2sEK0zXiGUxOrpvUqcjgVM86w+oURJP9l3u X-Received: by 2002:aa7:ccd7:: with SMTP id y23mr8368564edt.190.1615466385174; Thu, 11 Mar 2021 04:39:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615466385; cv=none; d=google.com; s=arc-20160816; b=KvFY4gVnIukreFawXLUwQUdYCPRYtBO7bop0qQQo1s87GyxKw+oA3L7P3nc3Pb22Id TDI17oybeIE/+sYZqwsc66bh5wRZre9C9YOFX5z8zA6CLpWTi8v0ZNUJCzJ0lSHvz2ER lbe2ohGwntoLRBm/h56ZPccpVcpbJxMNUlrxKaesncnupxlvVIog1lDr/b7tf+qX17F2 2ZjT6915/6SAeWk8XuTpxiRB1hKS1VJ87DAYw9a7ECeiyvz/JN/tPovBhy5hknjTA6hy Tpc3WodOgPp2TiH8WtyJZyAqdpYLyG7LGAlU8W3V6qYMTLWCoOtyqnllvSeXqFFoi+HL I9ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EdG7z7A7f38r+jF8afWaLD3dXjtHnX4h152Q5wanwMA=; b=USoIi6eB6Agr22oRymHlwH15aih2JGiuHH+OSRshCqD/qsFvwcgbVA1nEIDNRVGiKh BxgjrlNseWs1o7ObEow3/8sHHRELaTn/ac2PN30mq1uDnNkg7bqJM90eZ6QEDSK/wyb5 tuIGOTqB1hAiIsJkxQGuqVMkPK6dkhry7tNvLxW6rkw5YCSfOixfhIrv1AMU8d/puiuA xB3eKOFoTKRKp/+ik/6vac3PSTnXzB90XMBNyCyNn+4VVgfp6YcVIhhNdyXXCVx38QYH /nVLgn8uOMB8IaH1+dsWbzKM13s6trM9nPZGgez6txZ3+//GtihAmXXHvfr1UOE9/VA4 dP/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=md+vB5Zr; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id de11si1723805edb.15.2021.03.11.04.39.22; Thu, 11 Mar 2021 04:39:45 -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=@kernel.org header.s=k20201202 header.b=md+vB5Zr; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233389AbhCKMiH (ORCPT + 99 others); Thu, 11 Mar 2021 07:38:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:59950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233322AbhCKMhh (ORCPT ); Thu, 11 Mar 2021 07:37:37 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 87FC064FDF; Thu, 11 Mar 2021 12:37:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615466256; bh=pUXWyeYEYLRmfuK2ady5lC11LmUClYtDOY2m/bDc0SQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=md+vB5ZrZnyVtpghmoTnkEaPOBpErk7LS3KoNkrGv90DT6TOdNBOXOrzbYwXMmhr4 7UGQyUxh2cx5UPgW+tVLISGHWRGg01dILrncbUrKkvIoz9Xmj2xWMIVodyPG7pJ+u9 Z0WL49olnDZjPEbSGKF0zjN/CcIRsfmrW3MYBe/b+/zFstKFm2inDna5eZgf9RJer3 OBLqpxXmZVaryLDMR/S9ThR5xf+ytizf/eWRnhSkqMKlho6VbJ7UxvRzZCAHdly+jP /qxdnr0NafrJOKyES9Q52aec/o1oVNGE+sgYuLr3O7IY2xOwPJCqz8Ium/D1afPPtQ 5eoPrXTdIfscQ== From: Frederic Weisbecker To: Peter Zijlstra , Thomas Gleixner Cc: LKML , Frederic Weisbecker , "Rafael J . Wysocki" , Ti Zhou , Yunfeng Ye , "Paul E . McKenney" , Marcelo Tosatti , Ingo Molnar Subject: [PATCH 08/10] tick/nohz: Only wakeup a single target cpu when kicking a task Date: Thu, 11 Mar 2021 13:37:06 +0100 Message-Id: <20210311123708.23501-9-frederic@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210311123708.23501-1-frederic@kernel.org> References: <20210311123708.23501-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When adding a tick dependency to a task, its necessary to wakeup the CPU where the task resides to reevaluate tick dependencies on that CPU. However the current code wakes up all nohz_full CPUs, which is unnecessary. Switch to waking up a single CPU, by using ordering of writes to task->cpu and task->tick_dep_mask. Suggested-by: Peter Zijlstra Signed-off-by: Frederic Weisbecker Cc: Yunfeng Ye Cc: Thomas Gleixner Cc: Rafael J. Wysocki Signed-off-by: Marcelo Tosatti --- kernel/time/tick-sched.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 2a041d0dc3eb..8457f15a5073 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -322,6 +322,31 @@ void tick_nohz_full_kick_cpu(int cpu) irq_work_queue_on(&per_cpu(nohz_full_kick_work, cpu), cpu); } +static void tick_nohz_kick_task(struct task_struct *tsk) +{ + int cpu = task_cpu(tsk); + + /* + * If the task concurrently migrates to another cpu, + * we guarantee it sees the new tick dependency upon + * schedule. + * + * + * set_task_cpu(p, cpu); + * STORE p->cpu = @cpu + * __schedule() (switch to task 'p') + * LOCK rq->lock + * smp_mb__after_spin_lock() STORE p->tick_dep_mask + * tick_nohz_task_switch() smp_mb() (atomic_fetch_or()) + * LOAD p->tick_dep_mask LOAD p->cpu + */ + + preempt_disable(); + if (cpu_online(cpu)) + tick_nohz_full_kick_cpu(cpu); + preempt_enable(); +} + /* * Kick all full dynticks CPUs in order to force these to re-evaluate * their dependency on the tick and restart it if necessary. @@ -404,19 +429,8 @@ EXPORT_SYMBOL_GPL(tick_nohz_dep_clear_cpu); */ void tick_nohz_dep_set_task(struct task_struct *tsk, enum tick_dep_bits bit) { - if (!atomic_fetch_or(BIT(bit), &tsk->tick_dep_mask)) { - if (tsk == current) { - preempt_disable(); - tick_nohz_full_kick(); - preempt_enable(); - } else { - /* - * Some future tick_nohz_full_kick_task() - * should optimize this. - */ - tick_nohz_full_kick_all(); - } - } + if (!atomic_fetch_or(BIT(bit), &tsk->tick_dep_mask)) + tick_nohz_kick_task(tsk); } EXPORT_SYMBOL_GPL(tick_nohz_dep_set_task); -- 2.25.1