From nobody Mon Jun 15 10:45:16 2026 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.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 1B6E134753A for ; Thu, 9 Apr 2026 16:58:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775753888; cv=none; b=EauhB/YPzommf2PPO5NxPL4CrNikXseBotyJlPFxX/Cji6yKO7UAP9VmeuypxSndnsxmDBPRa7SEK0wAKUlmP+onrQpsfMqkbvd6j2KmPoG9muZzG6S6OY4nBVdKtzzhMqzCXlnb6NAzKNBJIg8XOol2+iG/gaDhUZZJYLO7TS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775753888; c=relaxed/simple; bh=737PKe1Z1dqWHfIiV98Y0bpL/Qhu9WE+6ejlzFcnf98=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=oYXS4OXiOdRfUygJylK5mfT9XGoDvt2iOi3R1EEWj0XTJs687q7z3SjEQPXSV2AA65WQMKHuMWbzp+0RtKnPmD5vzMRKULleR3NBnvvQQ+MNTqnH0jypKcx48q9T/JEtalDSwYgVdWjKVVGkcdg5z8TNlFPvDIak14g871e0eiY= 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=YtYeu1b7; arc=none smtp.client-ip=209.85.208.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="YtYeu1b7" Received: by mail-ed1-f73.google.com with SMTP id 4fb4d7f45d1cf-66bb7305ae7so1002551a12.2 for ; Thu, 09 Apr 2026 09:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775753884; x=1776358684; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=hTeITRTwBV8u77vwqAF9dL2LE0U+mcOwYTEg5q2jVd4=; b=YtYeu1b7u4LAiYEcFFXaXIWWqQ31zOUYXCtxpbAKeS5cW8ztvTQGn3mBxoB+oH1V2L BFqmyiUPVzhU0ees+OiyKcnOcU1Nkqm/VD41GMQMDxEDVY4sRSMWf/05qf0Npgwe6rbw xiWcD91CR7DVV90JYQ54imoHHTuwX3rWOpLA3iq3okl4lttPvjxv1t1yONGVrV3nMTyB oU613mK8ZVKWlCm4iPywmiCYC0VTiT72r6n0d6E3nIuD6qP355G1mHk6OKEQkwq9dAh4 3sRcKPQ3oDuS5qQTJQHeXRTFiUJrQau70okFDqtWRGQ2QHt8oqsT042n5BJgPsmj36lh k4+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775753884; x=1776358684; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=hTeITRTwBV8u77vwqAF9dL2LE0U+mcOwYTEg5q2jVd4=; b=nVFt4EdqxzQjCBDL15Wajs7Kw3wscilYolS3A/7v3eYCEa49+ETtTugmBF1q28pVu5 t0AoBn7Om7f0qOH9CTVCCWIpPU0IXhxtXSuyklVndR5+WCZbEIZ6np7B9ZWDsnKcek8L bVMSULGaqFuC8mi9nBMYWD7ykx+x+DSV+ULH1JATA/hUo1kXF2HPCE3Hf/Xt5WGIo5ZT A2Qt6GqsqUVwJMdtgTxitXgAj7br1bSOT9LJ/dWJjh2IQQAeXYEtO4sdbSx84xQL+MSq HRfCmyYuxtBHhsyBNafAdFJNmcbJaJXp338+VA+eVnE3dsORPP1KWk9/U6CXC8pWHqdB f7Dg== X-Gm-Message-State: AOJu0YyGkLQyBUZ72YKW86/doN1KAf+EKlVEw1ystvj0UWT6hyQ4B0gY x7mGCRCkKYWfW12ffhipEucODwkuVmfy7tf1CNxkTux8CXsgqyPhGXKHXF8RpMkXrn1/DCR1GhH R5/nNdfEJ5jkNrQ== X-Received: from edud13.prod.google.com ([2002:a05:6402:d:b0:66b:eb26:53d8]) (user=jpiecuch job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:46ca:b0:66f:76d7:56a4 with SMTP id 4fb4d7f45d1cf-66f76d75775mr4491020a12.26.1775753884259; Thu, 09 Apr 2026 09:58:04 -0700 (PDT) Date: Thu, 9 Apr 2026 16:57: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.53.0.1213.gd9a14994de-goog Message-ID: <20260409165744.1526489-1-jpiecuch@google.com> Subject: [PATCH v2 sched_ext/for-7.1] sched_ext: Documentation: improve accuracy of task lifecycle pseudo-code From: Kuba Piecuch To: Tejun Heo , Andrea Righi , Changwoo Min , David Vernet , Christian Loehle Cc: linux-kernel@vger.kernel.org, sched-ext@lists.linux.dev, Kuba Piecuch Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" * Add ops.quiescent() and ops.runnable() to the sched_change path. When a queued task has one of its scheduling properties changed (e.g. nice, affinity), it goes through dequeue() -> quiescent() -> (property change callback, e.g. ops.set_weight()) -> runnable() -> enqueue(). * Change && to || in ops.enqueue() condition. We want to enqueue tasks that have a non-zero slice and are not in any DSQ. * Call ops.dispatch() and ops.dequeue() only for tasks that have had ops.enqueue() called. This is to account for tasks direct-dispatched from ops.select_cpu(). * Add a note explaining that the pseudo-code provides a simplified view of the task lifecycle and list some examples of cases that the pseudo-code does not account for. Fixes: a4f61f0a1afd ("sched_ext: Documentation: Add ops.dequeue() to task l= ifecycle") Signed-off-by: Kuba Piecuch Reviewed-by: Andrea Righi $ --- Changes in v2: - Changed && to || in ops.enqueue() condition (Andrea) - Moved ops.dispatch() and ops.dequeue() inside the if statement (Andrea) - Added a note after the pseudo-code with examples of cases that the pseudo-code does not account for - Link to v1: https://lore.kernel.org/all/20260408091821.91063-1-jpiecuch@= google.com Documentation/scheduler/sched-ext.rst | 43 ++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/Documentation/scheduler/sched-ext.rst b/Documentation/schedule= r/sched-ext.rst index ec594ae8086de..2d77ab4816a63 100644 --- a/Documentation/scheduler/sched-ext.rst +++ b/Documentation/scheduler/sched-ext.rst @@ -408,8 +408,8 @@ for more information. Task Lifecycle -------------- =20 -The following pseudo-code summarizes the entire lifecycle of a task managed -by a sched_ext scheduler: +The following pseudo-code presents a rough overview the entire lifecycle +of a task managed by a sched_ext scheduler: =20 .. code-block:: c =20 @@ -423,20 +423,25 @@ by a sched_ext scheduler: ops.runnable(); /* Task becomes ready to run */ =20 while (task_is_runnable(task)) { - if (task is not in a DSQ && task->scx.slice =3D=3D 0) { + if (task is not in a DSQ || task->scx.slice =3D=3D 0) { ops.enqueue(); /* Task can be added to a DSQ */ =20 /* Task property change (i.e., affinity, nice, etc.)? */ if (sched_change(task)) { ops.dequeue(); /* Exiting BPF scheduler custody */ + ops.quiescent(); + + /* Property change callback, e.g. ops.set_weight() */ + + ops.runnable(); continue; } - } =20 - /* Any usable CPU becomes available */ + /* Any usable CPU becomes available */ =20 - ops.dispatch(); /* Task is moved to a local DSQ */ - ops.dequeue(); /* Exiting BPF scheduler custody */ + ops.dispatch(); /* Task is moved to a local DSQ */ + ops.dequeue(); /* Exiting BPF scheduler custody */ + } =20 ops.running(); /* Task starts running on its assigned CPU= */ =20 @@ -456,6 +461,30 @@ by a sched_ext scheduler: ops.disable(); /* Disable BPF scheduling for the task */ ops.exit_task(); /* Task is destroyed */ =20 +Note that the above pseudo-code does not cover all possible state transiti= ons +and edge cases, to name a few examples: + +* ``ops.dispatch()`` may fail to move the task to a local DSQ due to a rac= ing + property change on that task, in which case ``ops.dispatch()`` will be + retried. + +* The task may be direct-dispatched to a local DSQ from ``ops.enqueue()``, + in which case ``ops.dispatch()`` and ``ops.dequeue()`` are skipped and w= e go + straight to ``ops.running()``. + +* Property changes may occur at virtually any point during the task's life= cycle, + not just when the task is queued and waiting to be dispatched. For examp= le, + changing a property of a running task will lead to the callback sequence + ``ops.stopping()`` -> ``ops.quiescent()`` -> (property change callback) = -> + ``ops.runnable()`` -> ``ops.running()``. + +* A sched_ext task can be preempted by a task from a higher-priority sched= uling + class, in which it will exit the tick-dispatch loop even though it is ru= nnable + and has a non-zero slice. + +See the "Scheduling Cycle" section for a more detailed description of how +a freshly woken up task gets on a CPU. + Where to Look =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 --=20 2.53.0.1213.gd9a14994de-goog