Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3931944ioo; Mon, 30 May 2022 13:16:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBJM1njjsyL35Vua76SKH1w758ZhLBv+mVmhE5+Qup5JxYtN4o0BGUSGwuqdqLbVWj2gvd X-Received: by 2002:a17:907:97d2:b0:6ff:288d:1bf2 with SMTP id js18-20020a17090797d200b006ff288d1bf2mr19288099ejc.664.1653941800162; Mon, 30 May 2022 13:16:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653941800; cv=none; d=google.com; s=arc-20160816; b=fT+USXImgG3BdfwW3J+VwNv9lv3lCbupz1sEEdSKKo+RmqqHlD3ESe1RBhlAdpytMZ K/crl4lDit9oAu79Rwc8b/uAVgI/zlPz5Y9x2en7rXDPeBpiZHTy/HpyNDQzyhf9MH54 mGEp6Hm9MoYHunrMB1qCU+14O+L6bIyvraY8luG6zlAaXQXHk2+gH+FSSliz1ClDSvOm 5aOa/3thaU8CRbR8qd+Z5vi3NHDcG9ZseTlg6ljyUhw/i80U94VsES/JwAOcy4h+m05S /aDVdi97ajp24rkSvn8A32kjImr3gdD0OY6bcK6cywrgGorhsNySfLuhRiqZyk3CyEwo NQdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=c51AIok/qwJiPHR0blC8qWUmAJd+ZhA5KSNEkPpkepM=; b=X55OIKYqyI5VphyoktCzVOEuLmS5y6u14jWNfUQJyPYOg4gCHMdBWCw2cufhL9KAqc RPKuqMgeX9rMb4HktiJSaiSAQPqA4troCAuRB6gDHzZlim0wkrnjmId2B07xhpPThdGu 1t+sOdqAEUQAxrlxaWbkzTUXSi7qlSOF8RDxRvvMoWaFiUCgZcW8Qk8ZxQoAEWxV/Xyf QYd0WbqSu5fswrKRF3UvtBX5Is/BUiLkA+m9i5Pef98LYnwOeu3cIhfQycJEuJ6hRnQ5 E/Cl+rouNHAVKYNJWawpS60piEBCTMf2IsYCXY50KwS7Hj5BYinwujf/LzJDyAo2pqwZ Uk3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RgrKCUzM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p11-20020a1709061b4b00b006df76385e1csi10839737ejg.700.2022.05.30.13.16.15; Mon, 30 May 2022 13:16:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RgrKCUzM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241522AbiE3QYN (ORCPT + 99 others); Mon, 30 May 2022 12:24:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241825AbiE3QYL (ORCPT ); Mon, 30 May 2022 12:24:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E521B980B4 for ; Mon, 30 May 2022 09:24:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653927850; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=c51AIok/qwJiPHR0blC8qWUmAJd+ZhA5KSNEkPpkepM=; b=RgrKCUzMqzpxY04NGvX1xx72WF7wePNbRG6y4SaFojc/FbRPHWO0rW812/5TAdVqohB41A jEmG/J+ulmTOROxXo95uEaCO7q9yuMBBUmi1s3EVQ/PJP9e1t1y/G6jxIt/qJto7riuRUC ba3GyW2FzNPTb3WIWwoIKZpRXydZPTM= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-486-7OdMNw05OSKfMIEncxA8ZA-1; Mon, 30 May 2022 12:24:08 -0400 X-MC-Unique: 7OdMNw05OSKfMIEncxA8ZA-1 Received: by mail-wr1-f69.google.com with SMTP id bv12-20020a0560001f0c00b0020e359b3852so1660088wrb.14 for ; Mon, 30 May 2022 09:24:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=c51AIok/qwJiPHR0blC8qWUmAJd+ZhA5KSNEkPpkepM=; b=ZQ6WkM/5ZPSCb8TNQPlWVDqkIIrRnROxQezFAKFGcdcDSpcM5vf9Jks/u8M4ln/zTN 7qXNh56Nxb9IwQ9Lt5QRsVOtP3axyQR4xzGuamQjqdPBLduvGOnHxvqBRdkwCBZd8BgS uXh25k2ZZ0dPW32AuIpUaYHI9x0zqN+1qkJANT1nnvLPKDFNh+yKO5Pw5+TkUD92fcet BTBv6eDNGfrZMAHkaIYYxCBc8bPOxaCTWKZH3yQL0pJxqQxB2tyM1gFlan3tlZ9c8tgz uwNEk+lIwW4LFiaL5m3yiZdgjoOJqSR0jjRiLswvo5UP3hCHNhDS1+gMVNRCVKdT5cIt z8aw== X-Gm-Message-State: AOAM53122MqmWdDr1uWq9hKGFXXrWNDJwLnzayX7/4DkgbndVU+orb5Z aRRnu8d//sgTLC96EVoTQh4rwhJxvrvxi8mOgVlWz0mGXYd2BcKr8DUFHbLWVIwStqpJsHEIqGB buuWjQuKn01qnzlUHE9p9kBn6b4gqYW+HBUSXFW6GPNP7UfuEnUDDVxjqWu31g5B5baoZdNuKa9 L1 X-Received: by 2002:a5d:6dd1:0:b0:210:7a1:cda0 with SMTP id d17-20020a5d6dd1000000b0021007a1cda0mr18680270wrz.570.1653927847397; Mon, 30 May 2022 09:24:07 -0700 (PDT) X-Received: by 2002:a5d:6dd1:0:b0:210:7a1:cda0 with SMTP id d17-20020a5d6dd1000000b0021007a1cda0mr18680245wrz.570.1653927847122; Mon, 30 May 2022 09:24:07 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id r4-20020a1c2b04000000b003973c4bb19bsm10694681wmr.16.2022.05.30.09.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 May 2022 09:24:06 -0700 (PDT) From: Valentin Schneider To: Tianchen Ding , 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: Re: [PATCH v2] sched: Queue task on wakelist in the same llc if the wakee cpu is idle In-Reply-To: <20220527090544.527411-1-dtcccc@linux.alibaba.com> References: <20220527090544.527411-1-dtcccc@linux.alibaba.com> Date: Mon, 30 May 2022 17:24:05 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On 27/05/22 17:05, Tianchen Ding wrote: > The main idea of wakelist is to avoid cache bouncing. However, > 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. [...] > Our patch has improvement on schbench, hackbench > and Pipe-based Context Switching of unixbench > when there exists idle cpus, > and no obvious regression on other tests of unixbench. > This can help improve rt in scenes where wakeup happens frequently. > > Signed-off-by: Tianchen Ding This feels a bit like a generalization of 2ebb17717550 ("sched/core: Offload wakee task activation if it the wakee is descheduling") Given rq->curr is updated before prev->on_cpu is cleared, the waker executing ttwu_queue_cond() can observe: p->on_rq=0 p->on_cpu=1 rq->curr=swapper/x (aka idle task) So your addition of available_idle_cpu() in ttwu_queue_cond() (sort of) matches that when invoked via: if (smp_load_acquire(&p->on_cpu) && ttwu_queue_wakelist(p, task_cpu(p), wake_flags | WF_ON_CPU)) goto unlock; but it also affects ttwu_queue(p, cpu, wake_flags); at the tail end of try_to_wake_up(). With all that in mind, I'm curious whether your patch is functionaly close to the below. --- diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 66c4e5922fe1..ffd43264722a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3836,7 +3836,7 @@ static inline bool ttwu_queue_cond(int cpu, int wake_flags) * the soon-to-be-idle CPU as the current CPU is likely busy. * nr_running is checked to avoid unnecessary task stacking. */ - if ((wake_flags & WF_ON_CPU) && cpu_rq(cpu)->nr_running <= 1) + if (cpu_rq(cpu)->nr_running <= 1) return true; return false;