From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.53.71 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796367610; b=b17C7rc6VJvV/Pc5gKyfOPVKsq4rVVwCdfTYbJQfAQmcxpftlGFVK+kKJ98eshE0TZNK hFebXxIPZAef0iMWdMA9d0Hv2Xft6WkkPnweuusXKA8YzcRCY6K87lAxJkwAEMiOIMCnG d0+FveaV9MX+uy6CwjaEiLxcl5INxTuYlFlMNrvOsl/zNL5Iy8wlz8vQHbuFbM0RgWFgr OE53zlxGt8/BKt4wDi3JTdJ6zfE9OBxUWpnABGk6hz4wnbIVMzm2B7BwwxoHqaCdNOV0s vvraI9eV/Ad68lBVLOi+bOYWRVGCgxbBOPnkBJHsHAQH3sR2PtJ5s3496hzYMFmrobA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796367610; h=DMARC-Filter:DKIM-Signature:Received:Received:Date:From:To:Cc: Subject:Message-ID:References:Content-Type:Content-Disposition: In-Reply-To:X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=cr6qxkOeWZ8PnQy1do7MoLN5Q8Ys6X5+0eOihBEfHMQ=; b=gejy6PqcmrKewOl8TmbOI949VmIhu+CVCjcianDpQPEaLT/QrEjztK4Xq1tM+N++g6Uv HUcS0mNeyRe0HO9kn4cMDiMdIQIbCh3wu0KVPSl6Zu9qrnP7uN/oFmiyrWT3shNoj4wp+ BcI0+408/7diSCic3QVN1xGcM/I+KdeyAdzHZ8/aJcO33Bp3U8Z7MI4+npSZeMhMGtoy+ mKiqGs/RMuhBxKTxXFHjvijlN0XAX4dJz6Gzra7jJxzdnuDgaDLlCJqPBegHWLOL0P5vJ Km70Q6jsKQ4FHPCZDqFypIxhEziIe4FuGC7OxwSyDliXICNWg59vzu7JYRBwJbfQc9w== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=a8u8joR4; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.53.71 Received: from BL0PR03CU003.outbound.protection.outlook.com (mail-eastusazon11012071.outbound.protection.outlook.com [52.101.53.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85FAC606A330; Fri, 4 Dec 2026 07:00:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 85FAC606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=a8u8joR4 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=a29Vjfq8HaDYmosVHSs4hwHJxcq7JirptmoZ5j0H7C4L3fngfxOJq1qLkx9iQWLeDczOtlDVUR6Mdi9UXa89Vivq+9Px1AMcfGYw0IC8r+IneFZMt20bomDRzx8ce0YL+sW3+xu2BxXyaGiatw7QZTh+ndt1h/jAithvOeFYjXsF3la9Ff/5kZTpPtvnENZWNyx1OncjX6wCGmTeOSUyR9aoUTb+j52r3GjrVr6O0kBXvzmxk9PVPdmEXIcm7MH3TwcAYoDj8EebG7I/cFySeSiGWMnP61X2nLUaTYxggJJrrNrb5a27qwyGswFiPdgx0MdahRb6X8WtFINJfTajUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cr6qxkOeWZ8PnQy1do7MoLN5Q8Ys6X5+0eOihBEfHMQ=; b=YJHk15TrpiwZDCHAAUPCAeCRmkZy2AmfBybG/w/Jatl15GHPw/GlfhwNBApO19GbrsSs6NTTA5tnRPmKxY3EkBGAnx9HS96SaB02HU8J+zsSsDEMEYixVJlcCoYdF9L45G8Rwwt3pgu6aTrw189nGvG5Ls7qJUa9xZr3tdeLtZhiFEy8ovATvMdnI0Djtx0GHtLQu4FPGowxb6rcEhUCU76lnIF4+FptlP0QkL5YBwUlO4fL5zE2aDWNlv8N3fStYIMCpqsO05jSwHcVPCO9frcXaVI+un7MoBXSqPyKm09FFQgXt+IlCyXbA4ke7iNTutsG73GYHRCMui7tdzweaA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cr6qxkOeWZ8PnQy1do7MoLN5Q8Ys6X5+0eOihBEfHMQ=; b=a8u8joR4MnlSbJukGvZWloODGLtsgS5Rm2IfL0hsfg7zDXW6M7pFp9q23aKEexjgRGrOyF3YB8gQuph+XZTmWsrMELugJ08i0J5Do01VPZQi2fa4rr30CpShBD8p+iQu96VZwXE8pioc8BAsgKWUWNTmDW8fNVYSFCZE87ggvrmD4hE+7C0gMCHTmrtLKaT5zXFQlOaBHNr8+gfd4GAhzfnD1O9ei0107oQRpVZj7RneybwW7Bsec1blU+iPhsbXTT0R8H45xgCDyBu3MD+EcaL8vrmYEMjljarTP9nIZn39524kmo6LM6eYUM6GGLkpisDANUxcRfapXDclsdpbVw== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BL1PR12MB5174.namprd12.prod.outlook.com (2603:10b6:208:31c::19) by PH7PR12MB8780.namprd12.prod.outlook.com (2603:10b6:510:26b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Fri, 4 Dec 2026 06:59:58 +0000 Received: from BL1PR12MB5174.namprd12.prod.outlook.com ([fe80::58de:822b:868:96e9]) by BL1PR12MB5174.namprd12.prod.outlook.com ([fe80::58de:822b:868:96e9%5]) with mapi id 15.21.0688.010; Fri, 4 Dec 2026 06:59:57 +0000 Date: Fri, 4 Dec 2026 07:59:49 +0100 From: Andrea Righi To: Hang Zhengyang Cc: Tejun Heo , David Vernet , Changwoo Min , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Shuah Khan , Kuba Piecuch , Jonathan Bastari Thamrin , Hui Su , sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH sched_ext/for-7.5 1/2] sched_ext: idle: Don't stack a sync wakee behind a higher-class task Message-ID: References: <20261120-scx-fix75-v1-0-254f782ff9b0@gmail.com> <20261120-scx-fix75-v1-1-254f782ff9b0@gmail.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261120-scx-fix75-v1-1-254f782ff9b0@gmail.com> X-ClientProxiedBy: MI0P293CA0004.ITAP293.PROD.OUTLOOK.COM (2603:10a6:290:44::15) To BL1PR12MB5174.namprd12.prod.outlook.com (2603:10b6:208:31c::19) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL1PR12MB5174:EE_|PH7PR12MB8780:EE_ X-MS-Office365-Filtering-Correlation-Id: dc5ba55b-fe63-4a2f-2c77-08df51d4350a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|23010399003|366016|261028144727099003|261102123227099003|56012099006|10067099003|261026140227099003|11063799006|261022075727099003|261021121427099003|261022105027099003|261026121527099003|261009223027099003|22082099003|18002099003|4143699003; X-Microsoft-Antispam-Message-Info: KZGRwi4F72T91Vrf/NFXj/8FkmS4X6GLwdl0A0VgGuOF3BMG4oxShT5inyps4mjQ+xY3+UzP05bGFTVad2fdFUjDE2QXbU+wiAeAnXmvWxU/Ja3z8kbFlUCgKe4NcDcARW43hqlEop1c9DACW1NOBe7XRy5KAXeGGEBAVvda8eiZuUTHvllKl2lCtOagvR7rpo7ybAMQ82ohNPcHMQ+qrF6v6Mg6TjdBU8O/CXWoH4n7t/yniKy1YDVQ6NCsgJT3XvhT0pZSxSCHSFG9jRo7nvvgvelR+Sv8crsF3ksHdsPrF7ysCQPq5ZiCw+hLVkeE1rYGvgpJLV3iI6W4Mc8YLTvSti7/iNugfRH3noYLoKj3RmdkbQGaJ72Ext/06ykC81BxSzgia2rRUb8T6GQVu2/5tBaxrrZ7vm6SUijvBF6QjAI82s+06h16S7hFFhOSGsWT0amU1K0lsPol7EuSQ0yZcO0gPtdyOMeE8zUDZE/bsZyX971LXatCLgGvScSMQVWWtfrI9N16shFQcGRmGKtyv9T6Q0H955YtSBoexZPlBtxXKSd6ehwbzdjCk1V911d9h3/tXxXFjio/24OtV9d48UQI8S9PH3pzt/825GDOr1HRP+FWcpvKTRkzfdHJk1Ph++CtxHEXBfEEGNIgfzONzbXuXqq+R5ON3bD5Ntg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL1PR12MB5174.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(23010399003)(366016)(261028144727099003)(261102123227099003)(56012099006)(10067099003)(261026140227099003)(11063799006)(261022075727099003)(261021121427099003)(261022105027099003)(261026121527099003)(261009223027099003)(22082099003)(18002099003)(4143699003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?bJ9Ii9gfvU/YWum+SnP3NE3WNm6cZMA8fO6FG3FbU+XP7Zv/bwS03n3QBZSu?= =?us-ascii?Q?LFdwBU0IfU1oX0OkQyyBe5ET29IX3tnAEkp4Byuqqhg+Zmsr9haXPYE/WiW6?= =?us-ascii?Q?8DmEuwqmwUTlTI7XUwz2EkAmK2fdk9skOG69smYNNAbmBnQqvkNAU11jgSwc?= =?us-ascii?Q?3EgBG4MQpFWz07ryLo80YtLcoJPXv/nGUVmfflLkh4bA40Q/lYJEabOrKI2h?= =?us-ascii?Q?lk/nAoNhnXxiZBmE5aM6Ui/VsdNFj16NE16FLb6GtjkPm+/ttH7dcM6v4Ol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jtqp+5lfM8nfbNFuEf7F2L21R18EeFwQ?= =?us-ascii?Q?HPbJOzbl7KeudpQdfxHMvElbJxcVs0RTCssomG59l8ZlUuJs4OgZyecS9jSY?= =?us-ascii?Q?t/Gmh8dO80YN6YYmJLlvmYewhD10W7d74rWIx3QnHtpx9oWcxgiD35S9WdXY?= =?us-ascii?Q?x2irPPYp5aH0tli4gn6PVmQDqOykRyyn2csJBCCLqYep3vG+RTHFdBaVpNNd?= =?us-ascii?Q?041FdqmBq9+/rWuYFC5xgqM56mNqjTSxPLCGnaPeQqerJI6mXq4FsvVm4E0k?= =?us-ascii?Q?1WwpKE5wsxiZnPvDzAodE3N8vP9SZJ12Z8CYWHCC9623yuqKqGeFSCEPV70C?= =?us-ascii?Q?zkTRJ1Kk2NEun7Sdv2VYk3fN92f48yd4nVFz1rwCAK5yR1p4Kz8YyKET0Svc?= =?us-ascii?Q?qdxBhdOBgu/Dp2YB9GfuYFI4jYqtgGryb/NR+Wz2GQd5Jy+jzLk75qWU5Yoc?= =?us-ascii?Q?y7L4xlJleJ/zb41gE4E4/KqlraW8oeq/lyIt9hnLaS4JqCjX/2iWcOkP3UU/?= =?us-ascii?Q?sUR39/c9ii0mrTgDEWD4UjdG1YQclIl8Vv9A2KWAYbhu+/0orDQgf22r5pc5?= =?us-ascii?Q?wGoAbmZFTQ=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc5ba55b-fe63-4a2f-2c77-08df51d4350a X-MS-Exchange-CrossTenant-AuthSource: BL1PR12MB5174.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 06:59:57.9625 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5u9LMUyvr9c2fAT/9NHMinbhYHPaAxQc5Qlfp9evqA1J6qsQ3U7y+YhLvY8WNEsV+RMj49gvkOrcGVf8Mel5rA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8780 Hi Hang, On Fri, Nov 20, 2026 at 04:44:22PM +0800, Hang Zhengyang wrote: > On a sync wakeup, scx_select_cpu_dfl() can return the waker's CPU. It > does this when the waker's local DSQ is empty and some CPU is idle, > because the waker is expected to give up its CPU soon. > > This is wrong when the waker's CPU runs an RT or DL task, or a fair > task in partial mode. The BPF scheduler can't preempt such a task. The > wakee waits on the local DSQ until that task blocks, or until the ext > dl_server runs the wakee. Meanwhile, other CPUs are idle. > > The waker may not sleep at all. pipe_write() and sock_def_readable() > always set WF_SYNC, even if the writer keeps running. I don't think this is the right place to address that. WF_SYNC is just a hint, but it expresses an expectation that the waker will sleep soon. If that expectation is wrong, shouldn't we fix the caller? This would also disable the shortcut for RT/EXT handoffs where the waker promptly blocks, while adding another rq field load and class check whenever a sync wakeup reaches this shortcut. I'd prefer to address the incorrect hints at the source and preserve the shortcut for callers that use it properly. Thanks, -Andrea > > This affects every BPF scheduler that leaves CPU selection to the > kernel, or that passes SCX_WAKE_SYNC to scx_bpf_select_cpu_dfl() or > scx_bpf_select_cpu_and(). In an 8 vCPU guest with scx_simple, an RT > task on CPU 0 wrote to a pipe and kept spinning. In 16 of 16 wakeups, > the reader ran on CPU 0, 169 ms to 1.5 s later. With an eventfd write > instead, which is not a sync wakeup, the reader ran on an idle CPU > within 0.1 ms. > > SCX_OPS_ALWAYS_ENQ_IMMED doesn't fix this. It re-enqueues the wakee, > but in the same test the wakee still ran 16 to 483 ms late. The fair > class doesn't have this problem. wake_affine_idle() also picks the > waker's CPU, but select_idle_sibling() only uses it if it is idle. > > Skip the shortcut when a task of a higher class than EXT is running, > or about to run, on the waker's CPU. rq->next_class shows this, and > rq_is_open() uses the same check for SCX_ENQ_IMMED. The wakee then > goes to an idle CPU, as in any other wakeup. Sync wakeups between EXT > tasks don't change, unless a higher-class task is about to run on the > waker's CPU. > > Signed-off-by: Hang Zhengyang > --- > kernel/sched/ext/idle.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/kernel/sched/ext/idle.c b/kernel/sched/ext/idle.c > index 922fbc3065cc..bf4dd8cb4255 100644 > --- a/kernel/sched/ext/idle.c > +++ b/kernel/sched/ext/idle.c > @@ -534,6 +534,7 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, > * If WAKE_SYNC, try to migrate the wakee to the waker's CPU. > */ > if (wake_flags & SCX_WAKE_SYNC) { > + const struct sched_class *next_class; > int waker_node; > > /* > @@ -559,9 +560,19 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, > * insufficient as the local DSQ of the waker could have tasks > * piled up on it even if there is an idle core elsewhere on > * the system. > + * > + * Also don't put @p behind a task of a higher class (RT, DL, > + * or fair in partial mode). The BPF scheduler can't preempt > + * that task, and it may keep the CPU for a long time. @p would > + * wait on the local DSQ until that task stops, or until the > + * ext dl_server runs @p. ->next_class also shows a higher-class > + * task that is about to run here. Reading it without the rq > + * lock is fine, since this is only a hint. > */ > + next_class = READ_ONCE(cpu_rq(cpu)->next_class); > waker_node = scx_cpu_node_if_enabled(cpu); > if (!(current->flags & PF_EXITING) && > + !sched_class_above(next_class, &ext_sched_class) && > cpu_rq(cpu)->scx.local_dsq.nr == 0 && > (!(flags & SCX_PICK_IDLE_IN_NODE) || (waker_node == node)) && > !cpumask_empty(idle_cpumask(waker_node)->cpu)) { > > -- > 2.53.0 >