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 20CBA37F8A1 for ; Fri, 24 Apr 2026 09:24:26 +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=1777022667; cv=none; b=Cv4g4OpADDITMY3ro8pSs1ZJIkrCnCWRKLobODEPdAlHNgTiHhDdmJQk9xN6yaUnvHI5HVW/FaiwcmA+DnIUSUosaSb97YvD53Ysglw7se+XmczkYLX0wpWPxk4ySJYVyZeRJI5km1KdbCjYWvFgE+RvbJUhCvGQEJDozjtg7jE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777022667; c=relaxed/simple; bh=m4wkbucZDqiwRQgCi3C5GP0+GvBJowo+E9lh5+Fard8=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=kCGcBE9owzB/X0Q0/lABqKnHFzFT37rH8yqwBobJcT3SdfHzeNRdyJ09P4BUADBLQRKKIIBw5tR8kBSLPDN/JuDfBCBEe2l5v8ci7bPRHtVY4+T6EgfPf6TUq3VAod8TnO8RL9/fFTIbL9z9G1RekEWbAP43oLtxPxSlISF7/Tw= 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=W4OAX8V2; 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="W4OAX8V2" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4837bfcfe0dso83107315e9.1 for ; Fri, 24 Apr 2026 02:24:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777022664; x=1777627464; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=yCnZUBbOFm+NpCPSvShrUcUmnxgANsGzshR4TjOR3Kk=; b=W4OAX8V2zsq/Znz4r/Yx/3iCVxh1OCH7cKjr0jT3MTutXPJVuOgnfFAKNYzCqRtu4+ IiW9kiy8nNdGTPgfh/3HHiOkRwLvokf0xHcCkhtmYP5lw6Kuaz4dQuFxB0ki2ETdg2OK CFLiX4mXeabd6a/uQ6qHs1r3iHRpoGXHpGwq4jeS0oxHKIdz3zMXPj0H8apXdjPF4KBp b4UYrvUEYakAgX/8Yp/WaGpA/QUqstmbOXwcWSmnbW2mZPX3g6elgTRK6yaeZg7mZfOK dPjPaTrU0zt1LsCrnOB+ROs5CoRAzs4SW0ehg9rrVWVkHpilJKJHkSV3kB9NrFeshv7B rRtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777022664; x=1777627464; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yCnZUBbOFm+NpCPSvShrUcUmnxgANsGzshR4TjOR3Kk=; b=DkqjXUvIOrXRoYEbduNZkzwzhkG9KlMnU+o5IioCmucZO0YVAZuqPKka8wwKD4b4mV +yEirrcJ9w0TGCImuqdKu5kY8IabP9TstzRlPTosPCMR2SutoKpKQhBsF59WVlll8W24 Lp7OhvYd2F2mb5InFO+8pB9x9+aX4Ef0Yjhphw6e1v/yHw7psAJN01xVMseh85XeJMn5 8todRh6HGT1zzdDc1KxAuIPZY9Gq1PjMVJl7gRP71/bA9DbKBkJQcacyysGRn1y5kiP5 P+QEAovProeG0AJyBUGTs0QhQf+vwSb2TLxmNXCxQzavpBlo1Kj2XLmmTPEv88WnmnRY sBNQ== X-Gm-Message-State: AOJu0Yy+9Uvi98Q249+cD6hyp87LitgUteAT9PgtDrA9gz08HXhALfRk DjxRs4TPgnVevKKcXqm+UD8WxlU50r9OLJiHJ5mu/IK0Z2p/Ar7LFgWlF0WFUv9cHZdFyTVAj/G CmZWlRYvzv0SCcQ== X-Received: from wmtm7.prod.google.com ([2002:a05:600c:c4b7:b0:488:a6d9:e91a]) (user=jpiecuch job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:797:b0:489:1a3a:9e45 with SMTP id 5b1f17b1804b1-4891a3a9f38mr194689215e9.26.1777022664577; Fri, 24 Apr 2026 02:24:24 -0700 (PDT) Date: Fri, 24 Apr 2026 09:22:44 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.54.0.rc2.544.gc7ae2d5bb8-goog Message-ID: <20260424092245.3212529-1-jpiecuch@google.com> Subject: [PATCH sched_ext/for-7.1-fixes] sched_ext: Call wakeup_preempt() in local_dsq_post_enq() From: Kuba Piecuch To: Tejun Heo , Andrea Righi , Changwoo Min , David Vernet Cc: linux-kernel@vger.kernel.org, sched-ext@lists.linux.dev, Peter Zijlstra , Kuba Piecuch Content-Type: text/plain; charset="UTF-8" There are several edge cases (see linked thread) where an IMMED task can be left lingering on a local DSQ if an RT task swoops in at the wrong time. All of these edge cases are due to rq->next_class being idle even after dispatching a task to rq's local DSQ. We should bump rq->next_class to &ext_sched_class as soon as we've inserted a task into the local DSQ. To optimize the common case of rq->next_class == &ext_sched_class, only call wakeup_preempt() if rq->next_class is below EXT. If next_class is EXT or above, wakeup_preempt() is a no-op anyway. Link: https://lore.kernel.org/all/DHZPHUFXB4N3.2RY28MUEWBNYK@google.com/ Signed-off-by: Kuba Piecuch --- kernel/sched/ext.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 1f670028bf19..034df77e3af1 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -1393,7 +1393,6 @@ static void local_dsq_post_enq(struct scx_sched *sch, struct scx_dispatch_q *dsq struct task_struct *p, u64 enq_flags) { struct rq *rq = container_of(dsq, struct rq, scx.local_dsq); - bool preempt = false; call_task_dequeue(sch, rq, p, 0); @@ -1408,11 +1407,19 @@ static void local_dsq_post_enq(struct scx_sched *sch, struct scx_dispatch_q *dsq if ((enq_flags & SCX_ENQ_PREEMPT) && p != rq->curr && rq->curr->sched_class == &ext_sched_class) { rq->curr->scx.slice = 0; - preempt = true; + resched_curr(rq); } - if (preempt || sched_class_above(&ext_sched_class, rq->curr->sched_class)) - resched_curr(rq); + /* + * If @rq->next_class is currently idle, we need to bump it + * to &ext_sched_class using wakeup_preempt(). Otherwise, if we drop + * the rq lock later in the pick and an RT task wakes up on @rq, + * wakeup_preempt_idle() will be called during RT task wakeup and + * SCX won't have an opportunity to re-enqueue IMMED tasks from @rq's + * local DSQ. + */ + if (sched_class_above(&ext_sched_class, rq->next_class)) + wakeup_preempt(rq, p, 0); } static void dispatch_enqueue(struct scx_sched *sch, struct rq *rq, -- 2.54.0.rc2.544.gc7ae2d5bb8-goog