Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5782157ioo; Wed, 1 Jun 2022 12:29:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvPgltLH9RsiU0EZacjlka/FH4oJw5T0oZnUZlP+v6sF0U0/b9ioJd0vE6hFUBkyGQDtjg X-Received: by 2002:a17:902:e74d:b0:163:783a:3473 with SMTP id p13-20020a170902e74d00b00163783a3473mr947087plf.17.1654111740215; Wed, 01 Jun 2022 12:29:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654111740; cv=none; d=google.com; s=arc-20160816; b=ubFUlZ3ajXk6qHx+cXjWvgWOzQdQZBuLhfsljbzl4LdxUfX5PMst5gmLSjUzmPTLkj uEVXgu17IsHQ7WIWSJ9zdV3LsLuHV8kBdXHuGiAWjpCCCYA8U8epE/NnMQsA4GrhH8Lj CdgTXAJmeUIYPQuXrzHcyU2v1TdqYKSzyX7B4BtOorey/k9gHtH4Tuskkqcjf0ADttR9 Dh1GZBD2b+ZCH0ih4VUzRJQmVke7/3w0BBjYBeYF1ojt9Ov17696shTDzelZXEd4lSTy /Oiym9n+MZG/de9+zCO20ozkFbe3Axaicxp5G5IalN7vG+cd7Y9mBkf6TGrXKa9ei7uT 1k0A== 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=sp61j0jOxh675zEwHGRAuiHfrRaXXimDo3bMjlhAKxY=; b=thte3kgpmbejhY/YtPe8eHG7Q+l4othkYjswiqSMLmuMEAYlVpsGr4j6xyfPJisd6H WVCgi7zN32Ybp8nXis4IjAogYk4UlhaiIM55lDTGJwZAMDSE/w7NXRT0xHVLRO+WH+s3 +joSHtwy+SQ4zpmWGuNzQeNTUFyS8mm/mWLram0xhNjL6t6BuQG5wextoKh/swoL2ZdP Yu6h/YiioyX5idiYyFrr4zTAY6fvFQqxGELbPJbXaUHi/6L72TOzPIsnKwqaHpiz3ye/ kCpLLTDH8TRcGSeTuzOzSl2RfcLJUc8eGGtwJ0rI1mNKXhJfMY3eUtkHc0l5WYb9dLBz pbig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OAW4Rqb8; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id z8-20020a170903018800b00153b2d16403si4052442plg.11.2022.06.01.12.28.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 12:29:00 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OAW4Rqb8; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E003F17EC3B; Wed, 1 Jun 2022 12:00:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229549AbiEaLvN (ORCPT + 99 others); Tue, 31 May 2022 07:51:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241631AbiEaLvL (ORCPT ); Tue, 31 May 2022 07:51:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 302B39969F for ; Tue, 31 May 2022 04:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653997869; 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=sp61j0jOxh675zEwHGRAuiHfrRaXXimDo3bMjlhAKxY=; b=OAW4Rqb8pQmdLVEdBh98uxYvXxygQrn7z6v1Nkd2b3XuiSuxaBVZuATbv0YqsYNlwmw04+ oxMiMWpYyDVHWzWJT9xxKZN2G/JjLazi/ae/avBCfxpe+1r4khIf6JS9nvIrdHjBOAXwyP fs75AukyUx/rYA1gjur3whLuPqFAeJY= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-497-1EHks0CWNJyMB8m5cGKi9Q-1; Tue, 31 May 2022 07:51:07 -0400 X-MC-Unique: 1EHks0CWNJyMB8m5cGKi9Q-1 Received: by mail-wr1-f71.google.com with SMTP id d6-20020adfe886000000b00210316ee45eso845139wrm.4 for ; Tue, 31 May 2022 04:51:07 -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=sp61j0jOxh675zEwHGRAuiHfrRaXXimDo3bMjlhAKxY=; b=DzLEPw0vnyJgbakfuDWl+QO/Dl82PMyloLoH2pwrR2zVcelpMYAglbyq+3Ov54wmQ0 1M/nIGf1+Gl3Xox+e9TzfYJXsJtDwhKPzv9GUeWX/FjbymLlLQLQC+pyVvaFdb350m7+ Vav54C7sZHPlHnJXFMsvddN38uB4RxyUKEUl+gj6PIwj89aKHnIRntaesSr7ifuu3eq8 4jdLMSXYjBkr4mVHGGKHoRPATeKor5tQZBPX78s3FDhjzl51G4BCIVKtwfiit4pemCoA xWyXW74OnYKIYeALUtGlGQOR/Fn08pVpSDrt8nDzQVhfIyii9i2Mds8Sd1yCNu8DqCPb cWFw== X-Gm-Message-State: AOAM533ssvwxm4CET/V0GdHbCV2FdfL8gUzYP17LPCXdxt1JESP/IkcU kZ9Bmu3Da346LQF0+aA11c0L2zNU4YciDVLUKiXoFsgDSge2yAEhsTdaaPetlpNol5cSVI4jPnA sjCtpQMVf3EracX/u5ptejuO6O1mrxfqIS9EJutVtXUYg6rskHhUr/luTXObb5nOJugpEL2aFsT 1a X-Received: by 2002:adf:ce03:0:b0:210:32ec:50fd with SMTP id p3-20020adfce03000000b0021032ec50fdmr8804148wrn.407.1653997866448; Tue, 31 May 2022 04:51:06 -0700 (PDT) X-Received: by 2002:adf:ce03:0:b0:210:32ec:50fd with SMTP id p3-20020adfce03000000b0021032ec50fdmr8804120wrn.407.1653997866117; Tue, 31 May 2022 04:51:06 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id g12-20020adfd1ec000000b0020c5253d8f2sm8381245wrd.62.2022.05.31.04.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 May 2022 04:51:05 -0700 (PDT) From: Valentin Schneider To: Tianchen Ding Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , 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: <1d0eb8f4-e474-86a9-751a-7c2e1788df85@linux.alibaba.com> References: <20220527090544.527411-1-dtcccc@linux.alibaba.com> <1d0eb8f4-e474-86a9-751a-7c2e1788df85@linux.alibaba.com> Date: Tue, 31 May 2022 12:50:49 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 31/05/22 15:20, Tianchen Ding wrote: > On 2022/5/31 00:24, Valentin Schneider wrote: >> >> 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(). > > Yes. This part is what we mainly want to affect. The above WF_ON_CPU is > not our point. > Right. >> >> 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; > > It's a little different. This may bring extra IPIs when nr_running == 1 > and the current task on wakee cpu is not the target wakeup task (i.e., > rq->curr == another_task && rq->curr != p). Then this another_task may > be disturbed by IPI which is not expected. So IMO the promise by > WF_ON_CPU is necessary. You're right, actually taking a second look at that WF_ON_CPU path, shouldn't the existing condition be: if ((wake_flags & WF_ON_CPU) && !cpu_rq(cpu)->nr_running) ? Per the p->on_rq and p->on_cpu ordering, if we have WF_ON_CPU here then we must have !p->on_rq, so the deactivate has happened, thus the task being alone on the rq implies nr_running==0. @Mel, do you remember why you went for <=1 here? I couldn't find any clues on the original posting.