Skip to contentSkip to conversation

Documentation: trace: histogram-design: fix bracket, improve wording

PATCH Superseded Manuel Ebner 3 participants 4 messages Sep 3

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Documentation: trace: histogram-design: fix bracket, improve wording

Add missing ')' and add note about the new way of triggering an event.

---
@ Steven, I added this line, because else the references wouldn't make sense.
References: $wakeup_lat, next_pid

+ ... (which
+could equivalently be written trace(wakeup_latency,$wakeup_lat,next_pid)
are implemented, the parameters specified to the trace handler must be variables. In this case, $wakeup_lat is obviously a variable, but next_pid isn't, since it's just naming a field in the sched_switch

---
 Documentation/trace/histogram-design.rst | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
Documentation/trace/histogram-design.rst +8 -1
index 41a726cd3..86c83b177 100644
@@ -25,7 +25,7 @@ tracing_map.c.
 
 If the kernel is compiled with CONFIG_HIST_TRIGGERS_DEBUG set, an
 event file named 'hist_debug' will appear in each event's
-subdirectory.  This file can be read at any time and will display some
+
 of the hist trigger internals described in this document. Specific
 examples and output will be described in test cases below.
 
@@ -916,6 +916,13 @@ means it will be automatically converted into a field variable::
           onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,next_pid)' >>
 	  /sys/kernel/tracing/events/sched/sched_switch/trigger
 
+Note that the above is the old way to trigger a synthetic event, whereas the
+newer way is preferred, which uses the trace() action handler::
+
+  # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0: \
+          onmatch(sched.sched_waking).trace(wakeup_latency,$wakeup_lat,next_pid)' >>
+	  /sys/kernel/tracing/events/sched/sched_switch/trigger
+
 The diagram for the sched_switch event is similar to previous examples
 but shows the additional field_vars[] array for hist_data and shows
 the linkages between the field_vars and the variables and references
Signature · 1 line
2.54.0
#1 lore raw

PATCH v2 1/1 Documentation: trace: histogram-design: fix bracket, improve wording

Add missing ')' and add note about the new way of triggering an event.

---
I sent the previous mail on accident, sorry.

@ Steven, I added this line to your suggestion because else the references wouldn't make sense. References: $wakeup_lat, next_pid
Let me know what you think.

+ ... (which
+could equivalently be written trace(wakeup_latency,$wakeup_lat,next_pid)
are implemented, the parameters specified to the trace handler must be variables. In this case, $wakeup_lat is obviously a variable, but next_pid isn't, since it's just naming a field in the sched_switch

---
 Documentation/trace/histogram-design.rst | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
Documentation/trace/histogram-design.rst +8 -1
index 41a726cd3..c0271463b 100644
@@ -877,7 +877,7 @@ variables specified in the wakeup_latency() trace action, and use
 them to generate a new wakeup_latency event into the trace stream.
 
 Note that the way the trace handlers such as wakeup_latency() (which
-could equivalently be written trace(wakeup_latency,$wakeup_lat,next_pid)
+could equivalently be written trace(wakeup_latency,$wakeup_lat,next_pid))
 are implemented, the parameters specified to the trace handler must be
 variables.  In this case, $wakeup_lat is obviously a variable, but
 next_pid isn't, since it's just naming a field in the sched_switch
@@ -916,6 +916,13 @@ means it will be automatically converted into a field variable::
           onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,next_pid)' >>
 	  /sys/kernel/tracing/events/sched/sched_switch/trigger
 
+Note that the above is the old way to trigger a synthetic event, whereas the
+newer way is preferred, which uses the trace() action handler::
+
+  # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0: \
+          onmatch(sched.sched_waking).trace(wakeup_latency,$wakeup_lat,next_pid)' >>
+	  /sys/kernel/tracing/events/sched/sched_switch/trigger
+
 The diagram for the sched_switch event is similar to previous examples
 but shows the additional field_vars[] array for hist_data and shows
 the linkages between the field_vars and the variables and references
Signature · 1 line
2.54.0
maintainer
#2 lore raw
Quoted 11 lines · On Thu, 3 Sep 2026 09:11:05 +0200 Manuel Ebner <[email protected]>…

Add missing ')' and add note about the new way of triggering an event.

---
I sent the previous mail on accident, sorry.

@ Steven, I added this line to your suggestion because else the references wouldn't make sense. References: $wakeup_lat, next_pid
Let me know what you think.

It still looks fine without it. Here's the statement in full without the line:

Note that the way the trace handlers such as wakeup_latency() are implemented, the parameters specified to the trace handler must be variables. In this case, $wakeup_lat is obviously a variable, but next_pid isn't, since it's just naming a field in the sched_switch trace event. Since this is something that almost every trace() and save() action does, a special shortcut is implemented to allow field names to be used directly in those cases. How it works is that under the covers, a temporary variable is created for the named field, and this variable is what is actually passed to the trace handler. In the code and documentation, this type of variable is called a 'field variable'.

Perhaps it may look better if we move the text around a bit:

The onmatch() action below basically says that whenever we have a sched_switch event, if we have a matching sched_waking event, in this case if we have a pid in the sched_waking histogram that matches the next_pid field on this sched_switch event, we retrieve the variables specified in the wakeup_latency() trace action, and use them to generate a new wakeup_latency event into the trace stream.

First, we define the wakeup_latency synthetic event::

    # echo 'wakeup_latency u64 lat; pid_t pid' >> synthetic_events

Next, the sched_waking hist trigger as before::

    # echo 'hist:keys=pid:ts0=common_timestamp.usecs' >>
            events/sched/sched_waking/trigger

Finally, we create a hist trigger on the sched_switch event that generates a wakeup_latency() trace event. In this case we pass next_pid into the wakeup_latency synthetic event invocation, which means it will be automatically converted into a field variable::

    # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0: \
            onmatch(sched.sched_waking).trace(wakeup_latency,$wakeup_lat,next_pid)' >>
	    /sys/kernel/tracing/events/sched/sched_switch/trigger

Note, the above can also be written where wakeup_latency() is the action handler instead of trace()::

    # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0: \
            onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,next_pid)' >>
            /sys/kernel/tracing/events/sched/sched_switch/trigger

The diagram above illustrates the new elements described in the context of the sched_switch histogram using the onmatch() handler and the trace() action.

Note that the way the trace handlers such as wakeup_latency() are implemented, the parameters specified to the trace handler must be variables. In this case, $wakeup_lat is obviously a variable, but next_pid isn't, since it's just naming a field in the sched_switch trace event. Since this is something that almost every trace() and save() action does, a special shortcut is implemented to allow field names to be used directly in those cases. How it works is that under the covers, a temporary variable is created for the named field, and this variable is what is actually passed to the trace handler. In the code and documentation, this type of variable is called a 'field variable'.

Fields on other trace event's histograms can be used as well. In that case we have to generate a new histogram and an unfortunately named 'synthetic_field' (the use of synthetic here has nothing to do with synthetic events) and use that special histogram field as a variable.

-- Steve

#3 lore raw
In reply to Manuel Ebner
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The patch fails to implement the missing parenthesis fix claimed in the commit message. - [Low]…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The patch fails to implement the missing parenthesis fix claimed in the commit message.
- [Low] An unrelated line of documentation was accidentally deleted, breaking a sentence structure. --

commit 708a883b89775bdba5b9179959e1d7aeeadf6600
Author: Manuel Ebner <[email protected]>

Documentation: trace: histogram-design: fix bracket, improve wording

This commit aims to add a missing parenthesis and include a note about the new way of triggering an event in the histogram-design documentation.

Quoted 10 lines

---
@ Steven, I added this line, because else the references wouldn't make sense.
References: $wakeup_lat, next_pid

+ ... (which
+could equivalently be written trace(wakeup_latency,$wakeup_lat,next_pid)
are implemented, the parameters specified to the trace handler must be variables. In this case, $wakeup_lat is obviously a variable, but next_pid isn't, since it's just naming a field in the sched_switch
---

[Severity: Medium]
It looks like the intended fix for the missing parenthesis was accidentally placed between the --- separators in the commit message. As a result, this hunk is treated as commentary by git and dropped during patch application, so the parenthesis fix is missing from the actual file. Should this hunk be moved into the diff proper?

Documentation/trace/histogram-design.rst tracing_map.c. · line 28

Quoted 10 lines
Documentation/trace/histogram-design.rst +1 -1
index 41a726cd35369..86c83b177e446 100644
@@ -25,7 +25,7 @@ tracing_map.c.
 
 If the kernel is compiled with CONFIG_HIST_TRIGGERS_DEBUG set, an
 event file named 'hist_debug' will appear in each event's
-subdirectory.  This file can be read at any time and will display some
+

[Severity: Low]
Was this deletion intentional? It appears an unrelated line of documentation was accidentally removed here, breaking the sentence structure of the paragraph.

Quoted 2 lines
Documentation/trace/histogram-design.rst +0 -0
 of the hist trigger internals described in this document. Specific
 examples and output will be described in test cases below.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1