From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E844264619 for ; Thu, 23 Apr 2026 13:32:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776951144; cv=none; b=TCiBlUoBpY02f7Cqewo/VV5mlkU3WgugnsedZTETr4uZQWi50TpSoVSeCK6UUl1CsijT+aNdjyAWm7RJ1gz9rYoAq5v3gn2VzaKQI3PTpg3bBOpzjFKe7233ZHrdgOFSXHO0tgV4bfMglCvACTH42uVXqaJg6rRwhruWwiIi26A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776951144; c=relaxed/simple; bh=jsXtsggAeyiDql3NH+l5Ml75IjPlBUWMT0Ppryu4IOs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ui9NE8QV9Ivw6wSSca1biGVMZvse95ngAhub5DeAkilpYRyHckIUscB1p5vaDYuPu68fvOp5y4jbd9Mqon7KG/Gne2hZnYrzBSVCpoORXOT66XxqSJRWzc8R3eYfyxZv9WTsgdUUGMP6SwQzrpcTK7GC7Jd/E2nLh+8dj5Xh9Xk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jpiecuch.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Wet2L/cH; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jpiecuch.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Wet2L/cH" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-488ba2f4094so38275265e9.1 for ; Thu, 23 Apr 2026 06:32:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776951142; x=1777555942; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=a/7W0TaHNw+5a6v8mLmrLJrhufHg8u0tXJKdz0acvqg=; b=Wet2L/cHWUmeSSO8OgLPFOlNQWN7AB/cp0agzyXQOqnY9iIczHI8Oc9h6JfRSPMsjO sZrb6ItwKzXFoyVRjngcZC05bvkFov8mQUFOgXgVYqSoVYJl9k/LVJuTZDdXcUVogx18 GM4YaAdeUBfEuvHwA5Su7mdk4s4DgpSC/vErM1bsEu16siF5qWpDFqpkyi7J8+EHpQ+R FOYMSDAadZhtEUSyENsXh+Y0fanIY5sNVzyNBHM/QoiXQ32gVJ0+ymOh02EUSFUiLR3G WVY2a2LKmOHA1gRypiZGEo2d1ZYFhqEA2rjyPhPTJG2VzFo9Boezv+GV6bfN1SItusL2 EHnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776951142; x=1777555942; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=a/7W0TaHNw+5a6v8mLmrLJrhufHg8u0tXJKdz0acvqg=; b=Yzy705+PojwGY/fx/1a0H+9/yfjHSBVxs6ybyccTn5JJuAxQXz7/jz14in2/4Bfes8 vHMksIxS8HdbRQctYjguKkDvYsNxvy8abFk3zop//iaYI0J8EbyoQ1QnN5+juRRcj4Gf +6+D4eGNAw66tX1903ibPumUmUj7lIg0zhgHjh6l4/NoWCSYu89qqVamtLi1d+MG8m4A tmuWx0frv+9Q+jjgj5L7AnlQvZy+S+jrd2UI/gRA+Od0adLMSX7+/pFCL21f+lwz58Ze bEdHvcpUZovM177jBMTLRWlCxH/4NyxiAOtEUU63WISQrKY+BsCrifnY1jlNGtH1gag+ SuUQ== X-Forwarded-Encrypted: i=1; AFNElJ/QWZxiPXBt3DqjkBK1HkulWNBHD7UAEnOX/2GPLc5XuyPq4juVpyTogIOSQHJF8ATmzKQkJCg66g0kY6k=@vger.kernel.org X-Gm-Message-State: AOJu0YziqBrgfwUR1oVdO6O9Ge4p3jLn+4m6WNMAKr4v/Nv9x3k+R8Zp R1WPgcRy8gZiJKW1f03Mq4ctMkBR2EhGDpmJnzN8IaJlK88ap3BSR0t6ivPKYyPTqwj4FdSohue jocjx+S/8KK6sZA== X-Received: from wrub15.prod.google.com ([2002:a5d:4d8f:0:b0:43b:47ce:83d1]) (user=jpiecuch job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600d:14:b0:488:9e43:9690 with SMTP id 5b1f17b1804b1-488fb7451f1mr298196035e9.10.1776951141512; Thu, 23 Apr 2026 06:32:21 -0700 (PDT) Date: Thu, 23 Apr 2026 13:32:20 +0000 In-Reply-To: <20260422142633.G7180@cchengyang.duckdns.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260319083518.94673-1-arighi@nvidia.com> <20260422142633.G7180@cchengyang.duckdns.org> X-Mailer: aerc 0.21.0-0-g5549850facc2 Message-ID: Subject: Re: [PATCH v2 sched_ext/for-7.1] sched_ext: Invalidate dispatch decisions on CPU affinity changes From: Kuba Piecuch To: Cheng-Yang Chou , Tejun Heo Cc: Kuba Piecuch , Andrea Righi , David Vernet , Changwoo Min , Emil Tsalapatis , Christian Loehle , Daniel Hodges , , , Ching-Chun Huang , Chia-Ping Tsai Content-Type: text/plain; charset="UTF-8" Hi Cheng-Yang, On Wed Apr 22, 2026 at 6:33 AM UTC, Cheng-Yang Chou wrote: > Hi Tejun, Andrea, and Kuba > > On Mon, Mar 23, 2026 at 01:13:20PM -1000, Tejun Heo wrote: >> > The simple way to do this is to do scx_bpf_dsq_insert() at the very beginning, >> > once we know which task we would like to dispatch, and cancel the pending >> > dispatch via scx_bpf_dispatch_cancel() if any of the pre-dispatch checks fail >> > on the BPF side. This way, the "critical section" includes BPF-side checks, and >> > SCX will ignore the dispatch if there was a dequeue/enqueue racing with the >> > critical section. >> > >> > With this solution, we can throw an error if task_can_run_on_remote_rq() is >> > false, because we know that there was no racing cpumask change (if there was, >> > it would have been caught earlier, in finish_dispatch()). >> >> Yeah, I think this makes more sense. qseq is already there to provide >> protection against these events. It's just that the capturing of qseq is too >> late. If insert/cancel is too ugly, we can introduce another kfunc to >> capture the qseq - scx_bpf_dsq_insert_begin() or something like that - and >> stash it in a per-cpu variable. That way, qseq would be cover the "current" >> queued instance and the existing qseq mechanism would be able to reliably >> ignore the ones that lost race to dequeue. > > Since this has been stale for a while, I prepared a patch to implement > scx_bpf_dsq_insert_begin() as suggested. > > Is anyone else working on this? If not, I'm happy to send the formal > patch to fix this. Thanks for creating the patch. A couple of thoughts: 1. Do we have a use case that requires dsq_insert_begin() that isn't satisfied using the "insert and then cancel if needed" approach? 2. Do we want to restrict ourselves through the one qseq slot provided by dsq_insert_begin()? The most flexible approach IMO would be to simply allow BPF to read the qseq directly via a kfunc and then supply it to dsq_insert() later. With this, we can have multiple qseqs saved at the same time, and we can even pass them between CPUs, e.g. if one CPU dequeues a task for a sibling CPU, but we want the checks to be made inside the sibling's ops.dispatch() (I just made this use case it up, it may not be practical.) That said, exposing an internal thing like qseq to BPF may be a step too far. Let me know what you think. Thanks, Kuba