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 39A513C2760 for ; Thu, 19 Mar 2026 10:31:33 +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=1773916294; cv=none; b=tVIxz2szhQjBBzDPzdKmzvI1cz5THGnc5Ylx6ztuRGx0utayNmvVndrb3gQxoLAfcSwvdwHkqarxBaOgDwPW9UPaSi3tEHZwY+deMfrKgDNqzKkJ58GtjrtUPFCwPa+807apYH0r0ZUZgk1CkuhBb7Q5cnj2U2Sz4G1NKzFJMYc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773916294; c=relaxed/simple; bh=fdDW+cyULHtF9068HKpKB1+dQ6QqBdJldhZl7Oek9Ro=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=t61aJJbdyS1bBRLOBQ5xG2uUN5rqaiV9lkku24ZFL8tDPHBHkiFbLcODFdcBD/mD1vhYZ2qHn1iCIsEIXSeO1Qufo4IMFeeUcVnFdYWtY9YhP2cjaIGKZeAD6Gj8ivqX9XE2qZ/7UxoQocJhl1Jbw50vdtlk7KMW4VEHej/cnoc= 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=ayuiKjPB; 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="ayuiKjPB" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-483786a09b1so7438625e9.3 for ; Thu, 19 Mar 2026 03:31:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773916291; x=1774521091; 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=5QAJwDvz3p/lKamkB5t02atWMJOrYh8w3uDwHSA2+9E=; b=ayuiKjPBxrExTDpdy/fe3cU6Ttx8QCq/2u6D3VIrquhm/hxkZo1r3T9qgA14zAsJR8 Z747GzISdcmnLlP2I2VxJd3YofvyDeDDHsslszUxxfguDRNhWUvll/nN+0FoxBi08/nW 11MJWFE/SInt/KnX4e8e3j5X7pkdkBF2gXeoZLr4Ty43EASuf8yIyYGasoCDmzc68fWZ BjhxE3XCg0fJ5/06TuN6Bh8HR2NbhyKpDis9+hYB3sMPfpmWacIXazRHSmy36/7QVkZ3 UlJDPjJzpFazIuYZoMoVlch9LyCM0Pm7T578NPM79wZXUABAd3nwRIWGv1GvgSXB+9pJ CmSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773916291; x=1774521091; 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=5QAJwDvz3p/lKamkB5t02atWMJOrYh8w3uDwHSA2+9E=; b=D8XoTEr6PVuEOx6DonOCB5KCIDnucm+9Bb8yr0LAdtaS6Q/sm6iFZBWKFRkXtOqiKf pvmfUS6yx9FFynv9VEox3R6suqFMpzlPunfJ4kdX2igqRLwcNbS4YCStCg6kr5BeWM/N Qa1N1XtapILJAH6r52ryCT8ota6A5Kd+WqkEk9uDf19yOq/JVw4q/aIU5bkbtDD1SBY2 SNCJ6jfKEGk8rOxnexCcyhi7AFlSYU8+6FlR5We/louJNyY8GgtLfRL5PMAkvZpjF3+k sDu2px1/x+1PHKyDwU8hqBRkvwmmb/gQh4WsOd2Qgp17QNCIhqwixhZrKLwNtfMDrQ2+ c6Mw== X-Forwarded-Encrypted: i=1; AJvYcCVpWWL1O/OsuU58eXx5BW0EHLerwm6Q+5WWzwLauinFAokUq+2kiATTVZQ9ykQKtNYuYKOyJYkTucGYmOg=@vger.kernel.org X-Gm-Message-State: AOJu0Yzmikic/mmHVN/YvvkvlbrGLXiWfuOgIPzDvfLWvqDfweXLhBqa pDE23xsDY1pzx2J3bUCH2m21HszHzPD1b79ka5mEQX8CxLFS/0mNMcTcWEnmFi1AeGdvjTNklcs /L+oRQqmpDQ7uCg== X-Received: from wmil1.prod.google.com ([2002:a7b:c441:0:b0:485:40d2:1ebf]) (user=jpiecuch job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1f13:b0:485:3c05:24dc with SMTP id 5b1f17b1804b1-486f4465ec5mr110316055e9.33.1773916291431; Thu, 19 Mar 2026 03:31:31 -0700 (PDT) Date: Thu, 19 Mar 2026 10:31:30 +0000 In-Reply-To: <20260319083518.94673-1-arighi@nvidia.com> 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> 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: Andrea Righi , Tejun Heo , David Vernet , Changwoo Min Cc: Kuba Piecuch , Emil Tsalapatis , Christian Loehle , Daniel Hodges , , Content-Type: text/plain; charset="UTF-8" Hi Andrea, On Thu Mar 19, 2026 at 8:35 AM UTC, Andrea Righi wrote: > @@ -2043,6 +2041,13 @@ static void ops_dequeue(struct rq *rq, struct task_struct *p, u64 deq_flags) > */ > BUG(); > case SCX_OPSS_QUEUED: > + /* > + * Invalidate any in-flight dispatches for this task. The > + * task is leaving the runqueue, so any dispatch decision > + * made while it was queued is stale. > + */ > + rq->scx.ops_qseq++; I'm not sure why this is necessary. Isn't setting the ops_state to SCX_OPSS_NONE enough to invalidate in-flight dispatches? Could you describe a scenario where incrementing qseq on dequeue is necessary? > @@ -2537,9 +2546,26 @@ static void dispatch_to_local_dsq(struct scx_sched *sch, struct rq *rq, > } > > if (src_rq != dst_rq && > - unlikely(!task_can_run_on_remote_rq(sch, p, dst_rq, true))) { > - dispatch_enqueue(sch, rq, find_global_dsq(sch, task_cpu(p)), p, > - enq_flags | SCX_ENQ_CLEAR_OPSS | SCX_ENQ_GDSQ_FALLBACK); > + unlikely(!task_can_run_on_remote_rq(sch, p, dst_rq, false))) { > + /* > + * Affinity changed after dispatch decision and the task > + * can't run anymore on the destination rq. More of a nitpick, but this doesn't necessarily mean that the affinity changed. The scheduler could have also issued an invalid dispatch to a CPU outside of the task's cpumask (e.g. due to a bug), in which case the task won't be re-enqueued if we simply drop the dispatch, correct? > + * > + * Drop the dispatch, the task will be re-enqueued. Set the Just to clarify, is this referring to the enqueue that happens in do_set_cpus_allowed(), immediately after the actual cpumask change? > + * task back to QUEUED so dequeue (if waiting) can proceed > + * using current qseq from the task's rq. > + */ > + if (src_rq != rq) { > + raw_spin_rq_unlock(rq); > + raw_spin_rq_lock(src_rq); > + } > + atomic_long_set_release(&p->scx.ops_state, > + SCX_OPSS_QUEUED | > + (src_rq->scx.ops_qseq << SCX_OPSS_QSEQ_SHIFT)); > + if (src_rq != rq) { > + raw_spin_rq_unlock(src_rq); > + raw_spin_rq_lock(rq); > + } > return; > } My understanding is that task_can_run_on_remote_rq() can run without src_rq locked, so it's possible that @p's cpumask changes after the check, isn't it? In that case, I think it's still possible to move the task to the local DSQ of a CPU that is outside of its cpumask, triggering a warning in move_remote_task_to_local_dsq(). Thanks, Kuba