Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4138271pxy; Mon, 26 Apr 2021 19:47:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzh8oheqfxLCKZ5Ve0DEjRk2224xfPmk83pvGpV7wCBpsJzIiasgA6Qt9RAP0i8xtVsdHsy X-Received: by 2002:a62:1b50:0:b029:257:da1e:837f with SMTP id b77-20020a621b500000b0290257da1e837fmr20660060pfb.57.1619491635539; Mon, 26 Apr 2021 19:47:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619491635; cv=none; d=google.com; s=arc-20160816; b=NmqDEhxqJN0hyRQfPGHtrO6u1mwL4yR1grh2nXw1zgEb0cD0AqFNIxJi8hc0JUVcOX 2qxvy4raPW5tbNTDtW5Fl5jGhTQKpa4zI3TH9BHwvIwjvaHI/MmNB2fKTPnfpE2cw2B7 CeSZVvlKDXk220y6etVpe8WybWfkIRnwwtHve1sC/pMda//HMrynPQyldR32tvVZevp2 Kg7OGaGla6Fb93iWlMgrJ1FQMRlTX4+/S37cgzYL0BbEVw+5HN4Tz9AfsgU/j/xCSoBA F6Agsvy03LYXAcbsC7WA+guwaGcBc5+usH6AFG7vbBYlhCwBZ8E6sJ48AGcPKhysHHa5 +iYA== 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 :message-id:date:subject:cc:to:from; bh=OyIjlD0fV9S+kxj19pAMKVeo3T7FqK9WvP82AnjtjqM=; b=VflOTMC0IjpU0zS9SHB3aAD6OnAWP6KtGY9Zep8MzNMlLxTAm0vL110jyKL6Pni1Xb yR6QOCSK8jYya3B9Nulp5DjHmIcJ6d4zT/Ieryt8t52p5DsPcReHvZ8V8A5e0RPjAZqQ bXFLNE4CykUFM0B0Ofu/LX3BJe++lVjvjTENun2h9nSROw89+g699R/TNTj9SCJVEXQs n2r4gKsiLrXhFq/b90Qjk6+Nh+nWof2PWasWWnZ45PpDHStsood62DdoSYigVXxElpk+ 1WPuRZgoJ/xKCOh2pO8bSRkp56WF7BmxzriZ6lZ4jEDemvMF5SAdEULY0TFoS5O0MtdT qPBw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=hisilicon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p3si8979715pli.143.2021.04.26.19.47.02; Mon, 26 Apr 2021 19:47:15 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=hisilicon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233387AbhD0CqE (ORCPT + 99 others); Mon, 26 Apr 2021 22:46:04 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:16160 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231363AbhD0CqD (ORCPT ); Mon, 26 Apr 2021 22:46:03 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FTmJ54s1Mzmdsx; Tue, 27 Apr 2021 10:42:13 +0800 (CST) Received: from SWX921481.china.huawei.com (10.126.201.183) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Tue, 27 Apr 2021 10:45:09 +0800 From: Barry Song To: , , , , , , CC: , , , , , , , , , , , , Barry Song , "Yongjia Xie" Subject: [PATCH] sched/fair: don't use waker's cpu if the waker of sync wake-up is interrupt Date: Tue, 27 Apr 2021 14:37:58 +1200 Message-ID: <20210427023758.4048-1-song.bao.hua@hisilicon.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.126.201.183] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org a severe qperf performance decrease was reported in the below use case: For a hardware with 2 NUMA nodes, node0 has cpu0-31, node1 has cpu32-63. Ethernet is located in node1. Run the below commands: $ taskset -c 32-63 stress -c 32 & $ qperf 192.168.50.166 tcp_lat tcp_lat: latency = 2.95ms. Normally the latency should be less than 20us. But in the above test, latency increased dramatically to 2.95ms. This is caused by ping-pong of qperf between node0 and node1. Since it is a sync wake-up and waker's nr_running == 1, WAKE_AFFINE will pull qperf to node1, but LB will soon migrate qperf back to node0. Not like a normal sync wake-up coming from a task, the waker in the above test is an interrupt and nr_running happens to be 1 since stress starts 32 threads on node1 with 32 cpus. Testing also shows the performance of qperf won't drop if the number of threads are increased to 64, 96 or larger values: $ taskset -c 32-63 stress -c 96 & $ qperf 192.168.50.166 tcp_lat tcp_lat: latency = 14.7us. Obviously "-c 96" makes "cpu_rq(this_cpu)->nr_running == 1" false in wake_affine_idle() so WAKE_AFFINE won't pull qperf to node1. To fix this issue, this patch checks the waker of sync wake-up is a task but not an interrupt. In this case, the waker will schedule out and give CPU to wakee. Reported-by: Yongjia Xie Signed-off-by: Barry Song --- kernel/sched/fair.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 6d73bdbb2d40..8ad2d732033d 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5829,7 +5829,12 @@ wake_affine_idle(int this_cpu, int prev_cpu, int sync) if (available_idle_cpu(this_cpu) && cpus_share_cache(this_cpu, prev_cpu)) return available_idle_cpu(prev_cpu) ? prev_cpu : this_cpu; - if (sync && cpu_rq(this_cpu)->nr_running == 1) + /* + * If this is a sync wake-up and the only running thread is just + * waker, thus, waker is not interrupt, we assume wakee will get + * the cpu of waker soon + */ + if (sync && cpu_rq(this_cpu)->nr_running == 1 && in_task()) return this_cpu; if (available_idle_cpu(prev_cpu)) -- 2.25.1