Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp138395pxb; Tue, 17 Aug 2021 21:39:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNGkKMnq/GZfojMj9cKdYBUYw64IIYMPdNlIybVHss/+8csfKrJs1WAc210HhXAQ5NFm7F X-Received: by 2002:a17:906:a018:: with SMTP id p24mr7772427ejy.349.1629261536529; Tue, 17 Aug 2021 21:38:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629261536; cv=none; d=google.com; s=arc-20160816; b=gMr6QiYY6SUNHLo4p/yfq5SN/MiItm5y9jOIeT30DFX45T3REtB3IbPPDkmTtLYs5/ QODn5RJJYQ6oE+OzAv5WQhoMdf8qr2N8yj1ER5OFER1OIzjSwFybWI2pRYUCwQU4GU59 D5QEeHLOv+76UWSXd4ewn/lcn912QIm0evk6d3UTdw3eyMpZaRBxozPKLokcUJ1AYfuc 9Xz9SFbRpwzDEOJQ4Pyvx8gyChCNEFV0MfgC+Cl0+PI63eh7pWD3Emo7c21sKu/xQw0F A0+iq8OTj0Zhb/5/yMPssajyI+1pjxkVT7o0Afb/nX1Q3V+ooitv/DWAPJW93swmWY17 Wb0g== 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:dkim-signature:date; bh=+43KjJ461Wnnntp1BMXUkH0siaYFPWBA0DWao3uueIE=; b=T1FpdIQTVXSg2bOkP+siZ5vjz+DP22rmALtmhDTkJE+LkmAmheYF9C6kPV2bA1tLRc apTjdxNw8vLT64ZECA1Np+M9CEamWGid9wIyD25n05zqtrx9K5b9/OiGWsRjJyrQTKfQ 9B7bew6TE1ujRpx5x8aHH/odhD6UqoWQXKbD1wgevRk2EZt6w2GFTIEd1/EmNtwBkrAG sRu33GehtBcQCC5MBHrGZwR9BR8Emnl1ii0SOFPXsJRTlxSKQgpuGfeKuBNr6BS0NTZy e4S6L6rYlrfwifGjcx1urNQWtX6mtZHWWtX4sOEiTqyFKlXqhGHd9Fh6vnEF3j1AHfsF n5Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=SmMYcnEY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nc13si3809460ejc.649.2021.08.17.21.38.33; Tue, 17 Aug 2021 21:38:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=SmMYcnEY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237470AbhHREfC (ORCPT + 99 others); Wed, 18 Aug 2021 00:35:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231853AbhHREfB (ORCPT ); Wed, 18 Aug 2021 00:35:01 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47992C061764 for ; Tue, 17 Aug 2021 21:34:27 -0700 (PDT) Date: Wed, 18 Aug 2021 12:35:13 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1629261263; 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=+43KjJ461Wnnntp1BMXUkH0siaYFPWBA0DWao3uueIE=; b=SmMYcnEYRIJRa95jl6aydqNRHSJ0Rq/o9NRlLaZXUVLP8e2HsdUV1jcqfuJ68K7jB96KzS iwUJx36enCawS0fmuIImhCCgKpOmMZl56pazGVB5Nm1RPXtIZ2Fao0SRDx/RhO1TBB8E6C nBOBnKh2CgOtDpmFF81PiFPzM4GWwWo= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Tao Zhou To: Josh Don Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Joel Fernandes , Vineeth Pillai , linux-kernel@vger.kernel.org, tao.zhou@linux.dev Subject: Re: [PATCH] sched/core: fix pick_next_task 'max' tracking Message-ID: References: <20210818005615.138527-1-joshdon@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210818005615.138527-1-joshdon@google.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: tao.zhou@linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Josh, On Tue, Aug 17, 2021 at 05:56:15PM -0700, Josh Don wrote: > For core-sched, pick_next_task will update the 'max' task if there is a > cookie mismatch (since in this case the new task must be of higher > priority than the current max). However, we fail to update 'max' if > we've found a task with a matching cookie and higher priority than > 'max'. > > This can result in extra iterations on SMT-X machines, where X > 2. > > As an example, on a machine with SMT=3, on core 0, SMT-0 might pick > the following, in order: > > - SMT-0: p1, with cookie A, and priority 10 (max = p1) > - SMT-1: p2, with cookie A, and priority 30 (max not updated here) Thanks for your illustration. Good catch. The guilty is 'cookie_equals(class_pick, cookie))' condition in pick_task() > - SMT-2: p3, with cookie B, and priority 20 (max = p2) > > invalidate the other picks and retry > > Here, we should have instead updated 'max' when picking for SMT-1. Note > that this code would eventually have righted itself, since the retry > loop would re-pick p2, and update 'max' accordingly. However, this patch > avoids the extra round-trip. This is correct then may increase the chance to retry. That means it is more possible to filter the max first(not sure). > Signed-off-by: Josh Don > --- > kernel/sched/core.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 3431939699dc..110ea7582a33 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -5623,6 +5623,8 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) > occ = 1; > goto again; > } > + } else if (prio_less(max, p, fi_before)) { > + max = p; > } > } > } > -- > 2.33.0.rc1.237.g0d66db33f3-goog > Thanks, Tao