From nobody Mon Feb 9 08:55:46 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4449D367F26 for ; Thu, 22 Jan 2026 15:56:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769097395; cv=none; b=Hibl7Vbe1iWHn6EiTNPSrAljc8gzrtIjE0oGbyFQUBjLqbvp7EMPSbAiX2eUsZHd26OB5D0sCiKHZzAQtLO8NgkfTbNdZ2zMK59FTAjIcGc3JO/rMYPSduBzoYWnM32ZnpAOM0To2s3UPPAbib0nVdyrQEwvJjlRg2FjqxUpVsU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769097395; c=relaxed/simple; bh=RhPHfKDm0oGl1S2+0DrnK5IezrXtna+1V4LIOFyEyZ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=edTUZ95tKyTAlVxWIlHC9oZCf9q1VncBg/16I9sSEZCCUY2+T6LtefUpH5yocQJ7bn1VfokloIo4LGKpagX6CVxVsmZeFpoueSVpj0sI/oEN7st2b0mskB3cyH5YNlqc3LNkFkMPCoGI8EqYOK2wIRAAb3l9hmWEBQ5c+z7UDSU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XDzIbKs8; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XDzIbKs8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769097376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WLPd5+GnCQcV5/ZdDudxK6xPWoyTLOfgIflkpaGoDIg=; b=XDzIbKs8Xg/pUwdEiugr1oSBgvN7ZSBekI6JpXBKILEYRUMPCfuWv9gpOnOMJfb4V2XoYG IRZ6hKCyPg9Vb1ZMNIprZ//HMARMvTI9xYazgdZtLlujmTiXvF5pqWBsaWCW7hPAGVDRVS cA4rn+eZU03+tclyf2ssXlSe+WpzpMs= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-244-hvrdKgFWPYW0EaUuna6RBw-1; Thu, 22 Jan 2026 10:56:13 -0500 X-MC-Unique: hvrdKgFWPYW0EaUuna6RBw-1 X-Mimecast-MFC-AGG-ID: hvrdKgFWPYW0EaUuna6RBw_1769097371 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A5BF518005B0; Thu, 22 Jan 2026 15:56:11 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.rmtit.csb (unknown [10.45.224.47]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E49B8180049F; Thu, 22 Jan 2026 15:56:06 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, Steven Rostedt , Nam Cao , Juri Lelli , Gabriele Monaco , Jonathan Corbet , Masami Hiramatsu , linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Tomas Glozar , Clark Williams , John Kacur Subject: [PATCH v5 10/15] rv: Add enqueue/dequeue to snroc monitor Date: Thu, 22 Jan 2026 16:54:55 +0100 Message-ID: <20260122155500.362683-11-gmonaco@redhat.com> In-Reply-To: <20260122155500.362683-1-gmonaco@redhat.com> References: <20260122155500.362683-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Type: text/plain; charset="utf-8" The snroc monitor is a simple monitor that validates set_state occurs only when a task is running. This implicitly validates switch in and out follow one another. Add enqueue/dequeue to validate they also follow one another without duplicated events. Although they are not necessary to define the task context, adding the check here saves from adding another simple per-task monitor, which would require another slot in the task struct. Signed-off-by: Gabriele Monaco --- Documentation/trace/rv/monitor_sched.rst | 39 ++++++++++++------- kernel/trace/rv/monitors/snroc/snroc.c | 18 ++++++++- kernel/trace/rv/monitors/snroc/snroc.h | 46 ++++++++++++++++++++--- tools/verification/models/sched/snroc.dot | 30 ++++++++++----- 4 files changed, 101 insertions(+), 32 deletions(-) diff --git a/Documentation/trace/rv/monitor_sched.rst b/Documentation/trace= /rv/monitor_sched.rst index 0b96d6e147c6..d88ef856f89f 100644 --- a/Documentation/trace/rv/monitor_sched.rst +++ b/Documentation/trace/rv/monitor_sched.rst @@ -66,21 +66,32 @@ Monitor snroc =20 The set non runnable on its own context (snroc) monitor ensures changes in= a task state happens only in the respective task's context. This is a per-ta= sk -monitor:: +monitor. +The monitor also includes enqueue/dequeue events to validate they alternate +each other without duplication. Although they are not necessary to define = the +context, adding the check here saves from adding another simple per-task m= onitor:: + + | + | + v + #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D# + +------ H enqueued H= <--+ + | #=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D# | + | | ^ sched_set_state = | + | sched_switch_in sched_switch_out +--------------+ = | + | v | v | = | + | +-----------------------+ sched_dequeue +-------------------+= | + | | | -----------------> | |= | + | | own_context | | dequeued_running |= | + | | | <----------------- | |= | + | +-----------------------+ sched_enqueue +-------------------+= | + | ^ | | = | + | +---+ | sched_switch_out = | + | sched_set_state v = | + | +-------------------------------------+ = | + +--------------------> | dequeued | ----------= ----+ + sched_dequeue +-------------------------------------+ sched_enq= ueue =20 - | - | - v - +------------------+ - | other_context | <+ - +------------------+ | - | | - | sched_switch_in | sched_switch_out - v | - sched_set_state | - +------------------ | - | own_context | - +-----------------> -+ =20 Monitor scpd ~~~~~~~~~~~~ diff --git a/kernel/trace/rv/monitors/snroc/snroc.c b/kernel/trace/rv/monit= ors/snroc/snroc.c index f168b1a4b12c..87f87f479d18 100644 --- a/kernel/trace/rv/monitors/snroc/snroc.c +++ b/kernel/trace/rv/monitors/snroc/snroc.c @@ -17,6 +17,16 @@ #include "snroc.h" #include =20 +static void handle_sched_dequeue(void *data, struct task_struct *tsk, int = cpu) +{ + da_handle_event(tsk, sched_dequeue_snroc); +} + +static void handle_sched_enqueue(void *data, struct task_struct *tsk, int = cpu) +{ + da_handle_event(tsk, sched_enqueue_snroc); +} + static void handle_sched_set_state(void *data, struct task_struct *tsk, in= t state) { da_handle_event(tsk, sched_set_state_snroc); @@ -27,8 +37,8 @@ static void handle_sched_switch(void *data, bool preempt, struct task_struct *next, unsigned int prev_state) { - da_handle_start_event(prev, sched_switch_out_snroc); - da_handle_event(next, sched_switch_in_snroc); + da_handle_event(prev, sched_switch_out_snroc); + da_handle_start_run_event(next, sched_switch_in_snroc); } =20 static int enable_snroc(void) @@ -39,6 +49,8 @@ static int enable_snroc(void) if (retval) return retval; =20 + rv_attach_trace_probe("snroc", sched_dequeue_tp, handle_sched_dequeue); + rv_attach_trace_probe("snroc", sched_enqueue_tp, handle_sched_enqueue); rv_attach_trace_probe("snroc", sched_set_state_tp, handle_sched_set_state= ); rv_attach_trace_probe("snroc", sched_switch, handle_sched_switch); =20 @@ -49,6 +61,8 @@ static void disable_snroc(void) { rv_this.enabled =3D 0; =20 + rv_detach_trace_probe("snroc", sched_dequeue_tp, handle_sched_dequeue); + rv_detach_trace_probe("snroc", sched_enqueue_tp, handle_sched_enqueue); rv_detach_trace_probe("snroc", sched_set_state_tp, handle_sched_set_state= ); rv_detach_trace_probe("snroc", sched_switch, handle_sched_switch); =20 diff --git a/kernel/trace/rv/monitors/snroc/snroc.h b/kernel/trace/rv/monit= ors/snroc/snroc.h index 88b7328ad31a..b5b8c508cd11 100644 --- a/kernel/trace/rv/monitors/snroc/snroc.h +++ b/kernel/trace/rv/monitors/snroc/snroc.h @@ -8,7 +8,9 @@ #define MONITOR_NAME snroc =20 enum states_snroc { - other_context_snroc, + enqueued_snroc, + dequeued_snroc, + dequeued_running_snroc, own_context_snroc, state_max_snroc, }; @@ -16,6 +18,8 @@ enum states_snroc { #define INVALID_STATE state_max_snroc =20 enum events_snroc { + sched_dequeue_snroc, + sched_enqueue_snroc, sched_set_state_snroc, sched_switch_in_snroc, sched_switch_out_snroc, @@ -32,18 +36,48 @@ struct automaton_snroc { =20 static const struct automaton_snroc automaton_snroc =3D { .state_names =3D { - "other_context", + "enqueued", + "dequeued", + "dequeued_running", "own_context", }, .event_names =3D { + "sched_dequeue", + "sched_enqueue", "sched_set_state", "sched_switch_in", "sched_switch_out", }, .function =3D { - { INVALID_STATE, own_context_snroc, INVALID_STATE }, - { own_context_snroc, INVALID_STATE, other_context_snroc }, + { + dequeued_snroc, + INVALID_STATE, + INVALID_STATE, + own_context_snroc, + INVALID_STATE, + }, + { + INVALID_STATE, + enqueued_snroc, + INVALID_STATE, + INVALID_STATE, + INVALID_STATE, + }, + { + INVALID_STATE, + own_context_snroc, + dequeued_running_snroc, + INVALID_STATE, + dequeued_snroc, + }, + { + dequeued_running_snroc, + INVALID_STATE, + own_context_snroc, + INVALID_STATE, + enqueued_snroc, + }, }, - .initial_state =3D other_context_snroc, - .final_states =3D { 1, 0 }, + .initial_state =3D enqueued_snroc, + .final_states =3D { 1, 0, 0, 0 }, }; diff --git a/tools/verification/models/sched/snroc.dot b/tools/verification= /models/sched/snroc.dot index 8b71c32d4dca..b32e9adfb383 100644 --- a/tools/verification/models/sched/snroc.dot +++ b/tools/verification/models/sched/snroc.dot @@ -1,18 +1,28 @@ digraph state_automaton { center =3D true; size =3D "7,11"; - {node [shape =3D plaintext, style=3Dinvis, label=3D""] "__init_other_cont= ext"}; - {node [shape =3D ellipse] "other_context"}; - {node [shape =3D plaintext] "other_context"}; - {node [shape =3D plaintext] "own_context"}; - "__init_other_context" -> "other_context"; - "other_context" [label =3D "other_context", color =3D green3]; - "other_context" -> "own_context" [ label =3D "sched_switch_in" ]; + {node [shape =3D circle] "dequeued"}; + {node [shape =3D circle] "dequeued_running"}; + {node [shape =3D plaintext, style=3Dinvis, label=3D""] "__init_enqueued"}; + {node [shape =3D doublecircle] "enqueued"}; + {node [shape =3D circle] "enqueued"}; + {node [shape =3D circle] "own_context"}; + "__init_enqueued" -> "enqueued"; + "dequeued" [label =3D "dequeued"]; + "dequeued" -> "enqueued" [ label =3D "sched_enqueue" ]; + "dequeued_running" [label =3D "dequeued_running"]; + "dequeued_running" -> "dequeued" [ label =3D "sched_switch_out" ]; + "dequeued_running" -> "dequeued_running" [ label =3D "sched_set_state" ]; + "dequeued_running" -> "own_context" [ label =3D "sched_enqueue" ]; + "enqueued" [label =3D "enqueued", color =3D green3]; + "enqueued" -> "dequeued" [ label =3D "sched_dequeue" ]; + "enqueued" -> "own_context" [ label =3D "sched_switch_in" ]; "own_context" [label =3D "own_context"]; - "own_context" -> "other_context" [ label =3D "sched_switch_out" ]; + "own_context" -> "dequeued_running" [ label =3D "sched_dequeue" ]; + "own_context" -> "enqueued" [ label =3D "sched_switch_out" ]; "own_context" -> "own_context" [ label =3D "sched_set_state" ]; { rank =3D min ; - "__init_other_context"; - "other_context"; + "__init_enqueued"; + "enqueued"; } } --=20 2.52.0