Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp449886ybl; Wed, 29 Jan 2020 03:35:36 -0800 (PST) X-Google-Smtp-Source: APXvYqzpYd5LANtjwSvxl3bTU+LHamBPQQqZgl3sWueR1IAPxjSqmOZjOGOX7mlZiY3n6KarnXY5 X-Received: by 2002:aca:db56:: with SMTP id s83mr6091586oig.171.1580297736187; Wed, 29 Jan 2020 03:35:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580297736; cv=none; d=google.com; s=arc-20160816; b=hD1+3ZCQclDSFzyqX9mh10lNFuj+PliXWK05ins0c79OLKR7yFt8jv6VpTXj/GE1gy NAd7C3l/qMLEYJLTMrcjyft46faAAY0l2ebxtYNrZfuN/TjS9t7jH1nQnp1rutV5cwdx stdPqaDO5r1z8uEbV4N28GGtm8013BJyhmAyIDxAw4EYC4kbBkm1ujGwuEI9l6BhtSAn qkE6sBeYOqKLXsvOs6b1W/gR+vWOyfpq4gTBooSVBRzK7lLEFDsiXoedsuZIzT2NIFDF DZ8zqj7QpfA/ddKN9aJx+xjEBJV1LjsKpDsQwSBIHpyiz9qIQ8UXdOojD8aGyCLZVPI4 u+ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=FTwma60+jjkki8PAi1WMZh0pnzxy9Uly5ln4eoDxIeo=; b=vZSkXoZvIQmC/kOjDo78CjtVoX0koOcSDIe/XgZsKADxYMpGDCbwy2VC/ZK3fX/5+N 2mcreph+BL3BA9DWYNC+v20eusFV1+jEBli8wymUj/P9Nufa1uEuxH4cgr71Kjyc1oA0 zv8YWHtCW6iq8dgH1J6RhHbqujoG06c7h0qoDQ+h2HS13tQPoY0FOWrGK951zkQXrY0f r6pErvxLE2IvN+bqWFh3LocWr8/BH2Ouk1nd88iUWAe5+8js9VtA1c8AL5WqtltfWPfd 52H93dTuLoQtSNIv/DVwifj9KQDV8ul1Fwc46x82G5gtNiFg4SrRtkyGFib5p9WwmvY2 jp8Q== 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 f60si935952otf.119.2020.01.29.03.35.24; Wed, 29 Jan 2020 03:35:36 -0800 (PST) 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 S1726871AbgA2LdV (ORCPT + 99 others); Wed, 29 Jan 2020 06:33:21 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:51125 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726794AbgA2LdQ (ORCPT ); Wed, 29 Jan 2020 06:33:16 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iwlae-0007mI-Tt; Wed, 29 Jan 2020 12:33:00 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 4762C1C1C1B; Wed, 29 Jan 2020 12:32:59 +0100 (CET) Date: Wed, 29 Jan 2020 11:32:59 -0000 From: "tip-bot2 for Wanpeng Li" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/nohz: Optimize get_nohz_timer_target() Cc: Wanpeng Li , "Peter Zijlstra (Intel)" , Ingo Molnar , Frederic Weisbecker , x86 , LKML In-Reply-To: <1578876627-11938-1-git-send-email-wanpengli@tencent.com> References: <1578876627-11938-1-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Message-ID: <158029757906.396.16628642864164316826.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: 1.5 X-Linutronix-Spam-Level: + X-Linutronix-Spam-Status: No , 1.5 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001,URIBL_DBL_ABUSE_MALW=2.5 Sender: linux-kernel-owner@vger.kernel.org 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: e938b9c94164e4d981039f1cf6007d7453883e5a Gitweb: https://git.kernel.org/tip/e938b9c94164e4d981039f1cf6007d7453883e5a Author: Wanpeng Li AuthorDate: Mon, 13 Jan 2020 08:50:27 +08:00 Committer: Ingo Molnar CommitterDate: Tue, 28 Jan 2020 21:36:57 +01:00 sched/nohz: Optimize get_nohz_timer_target() On a machine, CPU 0 is used for housekeeping, the other 39 CPUs in the same socket are in nohz_full mode. We can observe huge time burn in the loop for seaching nearest busy housekeeper cpu by ftrace. 2) | get_nohz_timer_target() { 2) 0.240 us | housekeeping_test_cpu(); 2) 0.458 us | housekeeping_test_cpu(); ... 2) 0.292 us | housekeeping_test_cpu(); 2) 0.240 us | housekeeping_test_cpu(); 2) 0.227 us | housekeeping_any_cpu(); 2) + 43.460 us | } This patch optimizes the searching logic by finding a nearest housekeeper CPU in the housekeeping cpumask, it can minimize the worst searching time from ~44us to < 10us in my testing. In addition, the last iterated busy housekeeper can become a random candidate while current CPU is a better fallback if it is a housekeeper. Signed-off-by: Wanpeng Li Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Reviewed-by: Frederic Weisbecker Link: https://lkml.kernel.org/r/1578876627-11938-1-git-send-email-wanpengli@tencent.com --- kernel/sched/core.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 55b9a9c..a8a5d5b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -552,27 +552,32 @@ void resched_cpu(int cpu) */ int get_nohz_timer_target(void) { - int i, cpu = smp_processor_id(); + int i, cpu = smp_processor_id(), default_cpu = -1; struct sched_domain *sd; - if (!idle_cpu(cpu) && housekeeping_cpu(cpu, HK_FLAG_TIMER)) - return cpu; + if (housekeeping_cpu(cpu, HK_FLAG_TIMER)) { + if (!idle_cpu(cpu)) + return cpu; + default_cpu = cpu; + } rcu_read_lock(); for_each_domain(cpu, sd) { - for_each_cpu(i, sched_domain_span(sd)) { + for_each_cpu_and(i, sched_domain_span(sd), + housekeeping_cpumask(HK_FLAG_TIMER)) { if (cpu == i) continue; - if (!idle_cpu(i) && housekeeping_cpu(i, HK_FLAG_TIMER)) { + if (!idle_cpu(i)) { cpu = i; goto unlock; } } } - if (!housekeeping_cpu(cpu, HK_FLAG_TIMER)) - cpu = housekeeping_any_cpu(HK_FLAG_TIMER); + if (default_cpu == -1) + default_cpu = housekeeping_any_cpu(HK_FLAG_TIMER); + cpu = default_cpu; unlock: rcu_read_unlock(); return cpu;