Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2102084rwi; Tue, 1 Nov 2022 04:01:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4IEQtsn/nlPZQKIbJ3BySgHJeJDZjxKd1CBukQpXPGAvGK2hHA8knTPkdvIgKRKx657+Yf X-Received: by 2002:a17:90a:6347:b0:212:fe4a:c363 with SMTP id v7-20020a17090a634700b00212fe4ac363mr19278022pjs.176.1667300485851; Tue, 01 Nov 2022 04:01:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667300485; cv=none; d=google.com; s=arc-20160816; b=qoHAi99ckhFcs8AG5zuZ6Qvd9voASMQEO/HkrQx8jSU96cZn3RUXV4p4XWBvMsHZN8 lcuw2qBs4YSqx44sC+G4fU3bNHYGV0BEEGI2I0FRiLwAZId8g4e+cZnaYWMxo+Rm/j9f eHxd7PPyvZnTMRAJ/zBD1dsAxzriqMDX0NhK6kQs29/SXPGpmeFhqsitmqUW+hLlnOgM j2pi5YY++YL8khHTCl2Miv0hI5uySn14tw7ck67YqMAFOVYKM943fxh04jENwj1JEt0m VKZa8CsOcX8k6l3SHhczGeP5gWR7ZjH72e2rjaim4lbtiJDeKUGEl8JwCNl8z0yI4dtC OYdQ== 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=iPJVYSSrsREKVV6e45Jc8Aee33Xv4Zmq2z7M+AlUKm0=; b=ZBGevbj8NC9M+E2MNq9MyMun9+EhzKI24ElqnXlGnTbYSxil334d4eWKlBkR0R0DFi GdByTnhsufiD3AxUgjvg0kkCEpp2mN9gRkvOoP+qboR7kjfSNfaJ5dhc2xBGhvbNN4um 94HxIQ1v5EZiu3x191k8lLfQc+56OeuvfkjVQZUEBQHYpvdpOhNwr+8UdgLnrbvQDKyo Dvq1IrTwIiM29Ta5UKu6btw0tSmitne/yRfE5z2LKNDS60xb+Z5r+VaR77xl1Aip/Ww7 p6u14Ma0Zc6ukbl8SFgkAHHejxuvq4Vq88D//KLkog72ZYgL5Z+QX1JcfyE+oP/lsaO1 umMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=RTOJ96Lh; 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 t7-20020a170902a5c700b0018731d9aabbsi3453817plq.497.2022.11.01.04.01.11; Tue, 01 Nov 2022 04:01:25 -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=casper.20170209 header.b=RTOJ96Lh; 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 S229742AbiKAKe0 (ORCPT + 97 others); Tue, 1 Nov 2022 06:34:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229923AbiKAKeW (ORCPT ); Tue, 1 Nov 2022 06:34:22 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACC8CDF74 for ; Tue, 1 Nov 2022 03:34:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=iPJVYSSrsREKVV6e45Jc8Aee33Xv4Zmq2z7M+AlUKm0=; b=RTOJ96LhsvSb1Uo7OUXKbzo9iO O46VvMwhBpVyrLI+H7CDgGVI6/9fsMZjYZaNlGIyw2MaCWC5rpT0PTJaZZcKRFmmJQ88cBz8CcQKC VqQci6zdQEROI9KpM08YjlNwpL4jJbZs0Numnnyg02vphRprLwNNM0HUyO7ij36L2SOwZbEWAaKCK XW4pGTdEpbGTrCFe/bsuE5+eKAMMy+9WQhjpUcL0pNQm9hMgAPEbhLOChsNQJ8RJKKn4lleXSqhUl AM14J/Pnt0AvdzcnH7aEZWNbOTi8I73kHOGHaw5bVN8wMCIym9FhelL0QG7TsS54WU6qZD/957e8k CAjmMqaQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1opoax-004Wil-3Z; Tue, 01 Nov 2022 10:34:11 +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 E83DF30020B; Tue, 1 Nov 2022 11:34:04 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 8BE182BB7C856; Tue, 1 Nov 2022 11:34:04 +0100 (CET) Date: Tue, 1 Nov 2022 11:34:04 +0100 From: Peter Zijlstra To: Tianchen Ding Cc: 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: <20221101073630.2797-1-dtcccc@linux.alibaba.com> 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 03:36:30PM +0800, Tianchen Ding wrote: > We found a long tail latency in schbench whem m*t is close to nr_cpus. > (e.g., "schbench -m 2 -t 16" on a machine with 32 cpus.) > > This is because when the wakee cpu is idle, rq->ttwu_pending is cleared > too early, and idle_cpu() will return true until the wakee task enqueued. > This will mislead the waker when selecting idle cpu, and wake multiple > worker threads on the same wakee cpu. This situation is enlarged by > commit f3dd3f674555 ("sched: Remove the limitation of WF_ON_CPU on > wakelist if wakee cpu is idle") because it tends to use wakelist. > > Here is the result of "schbench -m 2 -t 16" on a VM with 32vcpu > (Intel(R) Xeon(R) Platinum 8369B). > > Latency percentiles (usec): > base base+revert_f3dd3f674555 base+this_patch > 50.0000th: 9 13 9 > 75.0000th: 12 19 12 > 90.0000th: 15 22 15 > 95.0000th: 18 24 17 > *99.0000th: 27 31 24 > 99.5000th: 3364 33 27 > 99.9000th: 12560 36 30 Nice; but have you also ran other benchmarks and confirmed it doesn't negatively affect those? If so; mentioning that is very helpful. If not; best go do so :-) > Signed-off-by: Tianchen Ding > --- > kernel/sched/core.c | 8 +------- > 1 file changed, 1 insertion(+), 7 deletions(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 87c9cdf37a26..b07de1753be5 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -3739,13 +3739,6 @@ void sched_ttwu_pending(void *arg) > if (!llist) > return; > > - /* > - * rq::ttwu_pending racy indication of out-standing wakeups. > - * Races such that false-negatives are possible, since they > - * are shorter lived that false-positives would be. > - */ > - WRITE_ONCE(rq->ttwu_pending, 0); > - > rq_lock_irqsave(rq, &rf); > update_rq_clock(rq); > 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); } rq_unlock_irqrestore(rq, &rf);