Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2591041rwi; Tue, 1 Nov 2022 09:22:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7y04xbE8OMTdiid5j4/ta97kvEJjQ9Lshw8ORxLylG6j1b54ANrp9Kd2pS82KEnaFHQs9v X-Received: by 2002:a17:907:9627:b0:78d:a7d8:9407 with SMTP id gb39-20020a170907962700b0078da7d89407mr18604483ejc.675.1667319763743; Tue, 01 Nov 2022 09:22:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667319763; cv=none; d=google.com; s=arc-20160816; b=X2L06SKL+npUNYGAQZJKbZUHVN3AqsekRDvkWWUmcuwhhj5nGloucde5WM0qxi6ugA sMNetKZKjZjFPBBdsdaWVLo+sN9gVy7q8Orvg5U1u49xshox/lYxTOUrE01LCztl1veO C8LxWmtr6ocKVY0jtnhdwwfm8PN7+M+dG21Vg+0Yi0Pi40B3LYLtCL/n2MsEdO+8y4SR SBnS7Zp/d+ykf/U28KGR4MKyOMBKU06wjWnSbIXj/H5N2CFJ9kXlv77bOMeGFlcce/WY vhngmKGDKUOEaSkF8zisk9wLEWfs6TNQEjk0KoTxYyKng+1P5/uD0j8fMWK/5fd/nupR bBFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=b1Cj0chaw9JLH2gXk2AZTiOd2rXLa7xopFMjGx4myaM=; b=cerY71hYmfV1vnnt3NQUIse9sjC02VMmt8htdwX7KCB9eUk2yo4NZqeGTmrAtkZZvs fRDWT+WLvh9YuyaZ463HoE5VvVdX1/co84afdpGJ0d0QTi5V+8Y3Yz4wDvE5udmR7CI4 7ff0+KCuVZxRN8/pdCRPm1onKHc5ngrfFNeLL+GK4+RLv11NtTvGOF/BNJg2wbtWik6F ViEPxYCXejdwQQQTcLn4ACcQftyrKyTNeVzpJNYhrkpMy92hF+qFfM/Vb1avQWKo1y8y 7tqUwCayVH2krqrTudXZ22WofunrN9Oj8Y4HFeyfCbqCqg48KWrn0KvNjX7wzI1bM8WH O5MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=GO1A5SoU; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be7-20020a1709070a4700b007a46fa50b26si13500347ejc.517.2022.11.01.09.22.19; Tue, 01 Nov 2022 09:22:43 -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=@infradead.org header.s=desiato.20200630 header.b=GO1A5SoU; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230520AbiKAPGh (ORCPT + 96 others); Tue, 1 Nov 2022 11:06:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231414AbiKAPGW (ORCPT ); Tue, 1 Nov 2022 11:06:22 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A91A31DDD6 for ; Tue, 1 Nov 2022 08:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=b1Cj0chaw9JLH2gXk2AZTiOd2rXLa7xopFMjGx4myaM=; b=GO1A5SoU2ykqlSazqqbbpt53fS tiPQJnRVbFOm4yp/siJ3m95ByA6Vzgd2nY6Yx1ltR03u2mMJnyvXpkMA66wFNhMItJ51CiPe/SoR4 iXMPvBma0/0omCz/pcySWoREN/csO0FsQhnyr7rOMI8qWxgsnt072XL8oSyYXaC+6QV2SHPpdIzIC 1CAzkIsUuO8fvTiv2WMV/ytqcZxLiEkNmry8XF5m1yZE42WbLKO59pG1rUNBjyKqQwSONyXdBaKQe 5RZZ4ez7pigqnNg7G3tkFAi65EeTSfIqAUkIebjm4AblEJ4mmflkio/LguqB6iR9rAPOo1sNXLuyb 89Y0gCxA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1opsje-0089Qb-GU; Tue, 01 Nov 2022 14:59:26 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7C6C130007E; Tue, 1 Nov 2022 15:59:25 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3925D28576692; Tue, 1 Nov 2022 15:59:25 +0100 (CET) Date: Tue, 1 Nov 2022 15:59:25 +0100 From: Peter Zijlstra To: Chen Yu Cc: Tianchen Ding , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org Subject: Re: [PATCH] sched: Clear ttwu_pending after enqueue_task Message-ID: References: <20221101073630.2797-1-dtcccc@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 Tue, Nov 01, 2022 at 09:51:25PM +0800, Chen Yu wrote: > > Could you try the below instead? Also note the comment; since you did > > the work to figure out why -- best record that for posterity. > > > > @@ -3737,6 +3730,13 @@ void sched_ttwu_pending(void *arg) > > set_task_cpu(p, cpu_of(rq)); > > > > ttwu_do_activate(rq, p, p->sched_remote_wakeup ? WF_MIGRATED : 0, &rf); > > + /* > > + * Must be after enqueueing at least once task such that > > + * idle_cpu() does not observe a false-negative -- if it does, > > + * it is possible for select_idle_siblings() to stack a number > > + * of tasks on this CPU during that window. > > + */ > > + WRITE_ONCE(rq->ttwu_pending, 0); > Just curious why do we put above code inside llist_for_each_entry_safe loop? > My understanding is that once 1 task is queued, select_idle_cpu() would not > treat this rq as idle anymore because nr_running is not 0. But would this bring > overhead to write the rq->ttwu_pending multiple times, do I miss something? So the consideration is that by clearing it late, you might also clear a next set; consider something like: cpu0 cpu1 cpu2 ttwu_queue() ->ttwu_pending = 1; llist_add() sched_ttwu_pending() llist_del_all() ... long ... ttwu_queue() ->ttwu_pending = 1 llist_add() ... time ... ->ttwu_pending = 0 Which leaves you with a non-empty list but with ttwu_pending == 0. But I suppose that's not actually better with my variant, since it keeps writing 0s. We can make it more complicated again, but perhaps it doesn't matter and your version is good enough. But please update with a comment on why it needs to be after ttwu_do_activate().