Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp984168iob; Fri, 13 May 2022 18:34:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYDVi9WAdmyIDIQIU3m8cR+OiIYNYuTpwRURdfR1xrq9tfweLf/Kep23DbLodgdXucvSsa X-Received: by 2002:a5d:4e42:0:b0:20a:d87f:84ee with SMTP id r2-20020a5d4e42000000b0020ad87f84eemr6076646wrt.593.1652492080596; Fri, 13 May 2022 18:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652492080; cv=none; d=google.com; s=arc-20160816; b=HgLteTUmG73xcNrDbXonZYmo9WsyQNqCE4Dn3xnLA0yQjabJb7VqBXvoenx3h8nmRb WP4fayzY4kIAOrQ10Q44qVVEmgcM/PxJVDwezc1CsdEEaoXXVhnLrqSFYZI3RRL7ZXwX SpVg2Vl/XdR8ZibdZrFKo9S5fASoPk8LEfC7AqyUHJU297rybMpWu5FstPCdEnvIBivv ysjGbWKnAIMck7+Kgx3OQ2mcSQVb4bqVrYxKSSExsIl5mTGOCKBqWBxB5MI4sQasMaor S4ijmvLgU77qhdz9LC9PISHL0I0cWeQPrOIlm+QHtagCWyjO8QTjT0LoqeX82TxTwquX JC+Q== 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=NqMousWdRvAAZoXA09omWPc6kIOYbCOqZaFTtpsry3s=; b=GX3tgQUzVHbJROdF9/2tztZ8Ddrv7W2oBK+XAhjKt/Eg5G3jPwkxQqikrHmH8FqMle F4OWhGSoan79sTJmqQwgtBDBUngn/PSg6St5u0/ukPhek94xJYYifhJX5Lp6dNh6jHRP o2w79Q07UCt0clhcE+LLKW7nLI9LuXZEvwu79SA7s28MMMmMDTOXDQ0HT9nTIBe0Z7JY ha5exdEc7GUD9gSxvKn28Ly4ZEimhHH4dv8OuF/bD2khCyrED+65A7lnXq8lJpeBayUn u1HJBg/jLSdQfmAaq/TEPdVSwssvvVjYoUrtbNgKMzlRqvIA0t3GXCXgk+jVnC0gMV9p CB2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i2-20020a7bc942000000b00393e72759fcsi7069262wml.196.2022.05.13.18.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:34:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EDF5540A748; Fri, 13 May 2022 17:02:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377288AbiEMGYp (ORCPT + 99 others); Fri, 13 May 2022 02:24:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240920AbiEMGYl (ORCPT ); Fri, 13 May 2022 02:24:41 -0400 Received: from out30-54.freemail.mail.aliyun.com (out30-54.freemail.mail.aliyun.com [115.124.30.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AB50291E76 for ; Thu, 12 May 2022 23:24:38 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R291e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04357;MF=dtcccc@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0VD1tx8B_1652423067; Received: from localhost.localdomain(mailfrom:dtcccc@linux.alibaba.com fp:SMTPD_---0VD1tx8B_1652423067) by smtp.aliyun-inc.com(127.0.0.1); Fri, 13 May 2022 14:24:35 +0800 From: Tianchen Ding To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira Cc: linux-kernel@vger.kernel.org Subject: [RFC PATCH] sched: Queue task on wakelist in the same llc if the wakee cpu is idle Date: Fri, 13 May 2022 14:24:27 +0800 Message-Id: <20220513062427.2375743-1-dtcccc@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We notice the commit 518cd6234178 ("sched: Only queue remote wakeups when crossing cache boundaries") disabled queuing tasks on wakelist when the cpus share llc. This is because, at that time, the scheduler must send IPIs to do ttwu_queue_wakelist. Nowadays, ttwu_queue_wakelist also supports TIF_POLLING, so this is not a problem now when the wakee cpu is in idle polling. Benefits: Queuing the task on idle cpu can help improving performance on waker cpu and utilization on wakee cpu, and further improve locality because the wakee cpu can handle its own rq. This patch helps improving rt on our real java workloads where wakeup happens frequently. Does this patch bring IPI flooding? For archs with TIF_POLLING_NRFLAG (e.g., x86), there will be no difference if the wakee cpu is idle polling. If the wakee cpu is idle but not polling, the later check_preempt_curr() will send IPI too. For archs without TIF_POLLING_NRFLAG (e.g., arm64), the IPI is unavoidable, since the later check_preempt_curr() will send IPI when wakee cpu is idle. Benchmark: running schbench -m 2 -t 8 on 8269CY: without patch: Latency percentiles (usec) 50.0000th: 10 75.0000th: 14 90.0000th: 16 95.0000th: 16 *99.0000th: 17 99.5000th: 20 99.9000th: 23 min=0, max=28 with patch: Latency percentiles (usec) 50.0000th: 6 75.0000th: 8 90.0000th: 9 95.0000th: 9 *99.0000th: 10 99.5000th: 10 99.9000th: 14 min=0, max=16 We've also tested unixbench and see about 10% improvement on Pipe-based Context Switching, and no performance regression on other test cases. For arm64, we've tested schbench and unixbench on Kunpeng920, the results show that, the improvement is not as obvious as on x86, and there's no performance regression. Signed-off-by: Tianchen Ding --- kernel/sched/core.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 51efaabac3e4..cae5011a8b1f 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3820,6 +3820,9 @@ static inline bool ttwu_queue_cond(int cpu, int wake_flags) if (!cpu_active(cpu)) return false; + if (cpu == smp_processor_id()) + return false; + /* * If the CPU does not share cache, then queue the task on the * remote rqs wakelist to avoid accessing remote data. @@ -3827,6 +3830,12 @@ static inline bool ttwu_queue_cond(int cpu, int wake_flags) if (!cpus_share_cache(smp_processor_id(), cpu)) return true; + /* + * If the CPU is idle, let itself do activation to improve utilization. + */ + if (available_idle_cpu(cpu)) + return true; + /* * If the task is descheduling and the only running task on the * CPU then use the wakelist to offload the task activation to @@ -3842,9 +3851,6 @@ static inline bool ttwu_queue_cond(int cpu, int wake_flags) static bool ttwu_queue_wakelist(struct task_struct *p, int cpu, int wake_flags) { if (sched_feat(TTWU_QUEUE) && ttwu_queue_cond(cpu, wake_flags)) { - if (WARN_ON_ONCE(cpu == smp_processor_id())) - return false; - sched_clock_cpu(cpu); /* Sync clocks across CPUs */ __ttwu_queue_wakelist(p, cpu, wake_flags); return true; -- 2.27.0