116b585feSTom Zanussi.. SPDX-License-Identifier: GPL-2.0 216b585feSTom Zanussi 316b585feSTom Zanussi====================== 416b585feSTom ZanussiHistogram Design Notes 516b585feSTom Zanussi====================== 616b585feSTom Zanussi 716b585feSTom Zanussi:Author: Tom Zanussi <zanussi@kernel.org> 816b585feSTom Zanussi 916b585feSTom ZanussiThis document attempts to provide a description of how the ftrace 1016b585feSTom Zanussihistograms work and how the individual pieces map to the data 1116b585feSTom Zanussistructures used to implement them in trace_events_hist.c and 1216b585feSTom Zanussitracing_map.c. 1316b585feSTom Zanussi 1416b585feSTom ZanussiNote: All the ftrace histogram command examples assume the working 1516b585feSTom Zanussi directory is the ftrace /tracing directory. For example:: 1616b585feSTom Zanussi 17*2abfcd29SRoss Zwisler # cd /sys/kernel/tracing 1816b585feSTom Zanussi 1916b585feSTom ZanussiAlso, the histogram output displayed for those commands will be 2016b585feSTom Zanussigenerally be truncated - only enough to make the point is displayed. 2116b585feSTom Zanussi 2216b585feSTom Zanussi'hist_debug' trace event files 2316b585feSTom Zanussi============================== 2416b585feSTom Zanussi 2516b585feSTom ZanussiIf the kernel is compiled with CONFIG_HIST_TRIGGERS_DEBUG set, an 2616b585feSTom Zanussievent file named 'hist_debug' will appear in each event's 2716b585feSTom Zanussisubdirectory. This file can be read at any time and will display some 2816b585feSTom Zanussiof the hist trigger internals described in this document. Specific 2916b585feSTom Zanussiexamples and output will be described in test cases below. 3016b585feSTom Zanussi 3116b585feSTom ZanussiBasic histograms 3216b585feSTom Zanussi================ 3316b585feSTom Zanussi 3416b585feSTom ZanussiFirst, basic histograms. Below is pretty much the simplest thing you 3516b585feSTom Zanussican do with histograms - create one with a single key on a single 3616b585feSTom Zanussievent and cat the output:: 3716b585feSTom Zanussi 3816b585feSTom Zanussi # echo 'hist:keys=pid' >> events/sched/sched_waking/trigger 3916b585feSTom Zanussi 4016b585feSTom Zanussi # cat events/sched/sched_waking/hist 4116b585feSTom Zanussi 4216b585feSTom Zanussi { pid: 18249 } hitcount: 1 4316b585feSTom Zanussi { pid: 13399 } hitcount: 1 4416b585feSTom Zanussi { pid: 17973 } hitcount: 1 4516b585feSTom Zanussi { pid: 12572 } hitcount: 1 4616b585feSTom Zanussi ... 4716b585feSTom Zanussi { pid: 10 } hitcount: 921 4816b585feSTom Zanussi { pid: 18255 } hitcount: 1444 4916b585feSTom Zanussi { pid: 25526 } hitcount: 2055 5016b585feSTom Zanussi { pid: 5257 } hitcount: 2055 5116b585feSTom Zanussi { pid: 27367 } hitcount: 2055 5216b585feSTom Zanussi { pid: 1728 } hitcount: 2161 5316b585feSTom Zanussi 5416b585feSTom Zanussi Totals: 5516b585feSTom Zanussi Hits: 21305 5616b585feSTom Zanussi Entries: 183 5716b585feSTom Zanussi Dropped: 0 5816b585feSTom Zanussi 5916b585feSTom ZanussiWhat this does is create a histogram on the sched_waking event using 6016b585feSTom Zanussipid as a key and with a single value, hitcount, which even if not 6116b585feSTom Zanussiexplicitly specified, exists for every histogram regardless. 6216b585feSTom Zanussi 6316b585feSTom ZanussiThe hitcount value is a per-bucket value that's automatically 6416b585feSTom Zanussiincremented on every hit for the given key, which in this case is the 6516b585feSTom Zanussipid. 6616b585feSTom Zanussi 6716b585feSTom ZanussiSo in this histogram, there's a separate bucket for each pid, and each 6816b585feSTom Zanussibucket contains a value for that bucket, counting the number of times 6916b585feSTom Zanussisched_waking was called for that pid. 7016b585feSTom Zanussi 7116b585feSTom ZanussiEach histogram is represented by a hist_data struct. 7216b585feSTom Zanussi 7316b585feSTom ZanussiTo keep track of each key and value field in the histogram, hist_data 7416b585feSTom Zanussikeeps an array of these fields named fields[]. The fields[] array is 7516b585feSTom Zanussian array containing struct hist_field representations of each 7616b585feSTom Zanussihistogram val and key in the histogram (variables are also included 7716b585feSTom Zanussihere, but are discussed later). So for the above histogram we have one 7816b585feSTom Zanussikey and one value; in this case the one value is the hitcount value, 7916b585feSTom Zanussiwhich all histograms have, regardless of whether they define that 8016b585feSTom Zanussivalue or not, which the above histogram does not. 8116b585feSTom Zanussi 8216b585feSTom ZanussiEach struct hist_field contains a pointer to the ftrace_event_field 8316b585feSTom Zanussifrom the event's trace_event_file along with various bits related to 8416b585feSTom Zanussithat such as the size, offset, type, and a hist_field_fn_t function, 8516b585feSTom Zanussiwhich is used to grab the field's data from the ftrace event buffer 8616b585feSTom Zanussi(in most cases - some hist_fields such as hitcount don't directly map 8716b585feSTom Zanussito an event field in the trace buffer - in these cases the function 8816b585feSTom Zanussiimplementation gets its value from somewhere else). The flags field 8916b585feSTom Zanussiindicates which type of field it is - key, value, variable, variable 9016b585feSTom Zanussireference, etc., with value being the default. 9116b585feSTom Zanussi 9216b585feSTom ZanussiThe other important hist_data data structure in addition to the 9316b585feSTom Zanussifields[] array is the tracing_map instance created for the histogram, 9416b585feSTom Zanussiwhich is held in the .map member. The tracing_map implements the 9516b585feSTom Zanussilock-free hash table used to implement histograms (see 9616b585feSTom Zanussikernel/trace/tracing_map.h for much more discussion about the 9716b585feSTom Zanussilow-level data structures implementing the tracing_map). For the 9816b585feSTom Zanussipurposes of this discussion, the tracing_map contains a number of 9916b585feSTom Zanussibuckets, each bucket corresponding to a particular tracing_map_elt 10016b585feSTom Zanussiobject hashed by a given histogram key. 10116b585feSTom Zanussi 10216b585feSTom ZanussiBelow is a diagram the first part of which describes the hist_data and 10316b585feSTom Zanussiassociated key and value fields for the histogram described above. As 10416b585feSTom Zanussiyou can see, there are two fields in the fields array, one val field 10516b585feSTom Zanussifor the hitcount and one key field for the pid key. 10616b585feSTom Zanussi 10716b585feSTom ZanussiBelow that is a diagram of a run-time snapshot of what the tracing_map 10816b585feSTom Zanussimight look like for a given run. It attempts to show the 10916b585feSTom Zanussirelationships between the hist_data fields and the tracing_map 110daceabf1STom Zanussielements for a couple hypothetical keys and values.:: 11116b585feSTom Zanussi 11216b585feSTom Zanussi +------------------+ 11316b585feSTom Zanussi | hist_data | 11416b585feSTom Zanussi +------------------+ +----------------+ 11516b585feSTom Zanussi | .fields[] |---->| val = hitcount |----------------------------+ 11616b585feSTom Zanussi +----------------+ +----------------+ | 11716b585feSTom Zanussi | .map | | .size | | 11816b585feSTom Zanussi +----------------+ +--------------+ | 11916b585feSTom Zanussi | .offset | | 12016b585feSTom Zanussi +--------------+ | 12116b585feSTom Zanussi | .fn() | | 12216b585feSTom Zanussi +--------------+ | 12316b585feSTom Zanussi . | 12416b585feSTom Zanussi . | 12516b585feSTom Zanussi . | 12616b585feSTom Zanussi +----------------+ <--- n_vals | 12716b585feSTom Zanussi | key = pid |----------------------------|--+ 12816b585feSTom Zanussi +----------------+ | | 12916b585feSTom Zanussi | .size | | | 13016b585feSTom Zanussi +--------------+ | | 13116b585feSTom Zanussi | .offset | | | 13216b585feSTom Zanussi +--------------+ | | 13316b585feSTom Zanussi | .fn() | | | 13416b585feSTom Zanussi +----------------+ <--- n_fields | | 13516b585feSTom Zanussi | unused | | | 13616b585feSTom Zanussi +----------------+ | | 13716b585feSTom Zanussi | | | | 13816b585feSTom Zanussi +--------------+ | | 13916b585feSTom Zanussi | | | | 14016b585feSTom Zanussi +--------------+ | | 14116b585feSTom Zanussi | | | | 14216b585feSTom Zanussi +--------------+ | | 14316b585feSTom Zanussi n_keys = n_fields - n_vals | | 144daceabf1STom Zanussi 14516b585feSTom ZanussiThe hist_data n_vals and n_fields delineate the extent of the fields[] | | 14616b585feSTom Zanussiarray and separate keys from values for the rest of the code. | | 147daceabf1STom Zanussi 14816b585feSTom ZanussiBelow is a run-time representation of the tracing_map part of the | | 14916b585feSTom Zanussihistogram, with pointers from various parts of the fields[] array | | 15016b585feSTom Zanussito corresponding parts of the tracing_map. | | 151daceabf1STom Zanussi 15216b585feSTom ZanussiThe tracing_map consists of an array of tracing_map_entrys and a set | | 15316b585feSTom Zanussiof preallocated tracing_map_elts (abbreviated below as map_entry and | | 15416b585feSTom Zanussimap_elt). The total number of map_entrys in the hist_data.map array = | | 15516b585feSTom Zanussimap->max_elts (actually map->map_size but only max_elts of those are | | 15616b585feSTom Zanussiused. This is a property required by the map_insert() algorithm). | | 157daceabf1STom Zanussi 15816b585feSTom ZanussiIf a map_entry is unused, meaning no key has yet hashed into it, its | | 15916b585feSTom Zanussi.key value is 0 and its .val pointer is NULL. Once a map_entry has | | 16016b585feSTom Zanussibeen claimed, the .key value contains the key's hash value and the | | 16116b585feSTom Zanussi.val member points to a map_elt containing the full key and an entry | | 16216b585feSTom Zanussifor each key or value in the map_elt.fields[] array. There is an | | 16316b585feSTom Zanussientry in the map_elt.fields[] array corresponding to each hist_field | | 16416b585feSTom Zanussiin the histogram, and this is where the continually aggregated sums | | 16516b585feSTom Zanussicorresponding to each histogram value are kept. | | 166daceabf1STom Zanussi 16716b585feSTom ZanussiThe diagram attempts to show the relationship between the | | 16816b585feSTom Zanussihist_data.fields[] and the map_elt.fields[] with the links drawn | | 169daceabf1STom Zanussibetween diagrams:: 170daceabf1STom Zanussi 17116b585feSTom Zanussi +-----------+ | | 17216b585feSTom Zanussi | hist_data | | | 17316b585feSTom Zanussi +-----------+ | | 17416b585feSTom Zanussi | .fields | | | 17516b585feSTom Zanussi +---------+ +-----------+ | | 17616b585feSTom Zanussi | .map |---->| map_entry | | | 17716b585feSTom Zanussi +---------+ +-----------+ | | 17816b585feSTom Zanussi | .key |---> 0 | | 17916b585feSTom Zanussi +---------+ | | 18016b585feSTom Zanussi | .val |---> NULL | | 18116b585feSTom Zanussi +-----------+ | | 18216b585feSTom Zanussi | map_entry | | | 18316b585feSTom Zanussi +-----------+ | | 18416b585feSTom Zanussi | .key |---> pid = 999 | | 18516b585feSTom Zanussi +---------+ +-----------+ | | 18616b585feSTom Zanussi | .val |--->| map_elt | | | 18716b585feSTom Zanussi +---------+ +-----------+ | | 18816b585feSTom Zanussi . | .key |---> full key * | | 18916b585feSTom Zanussi . +---------+ +---------------+ | | 19016b585feSTom Zanussi . | .fields |--->| .sum (val) |<-+ | 19116b585feSTom Zanussi +-----------+ +---------+ | 2345 | | | 19216b585feSTom Zanussi | map_entry | +---------------+ | | 19316b585feSTom Zanussi +-----------+ | .offset (key) |<----+ 19416b585feSTom Zanussi | .key |---> 0 | 0 | | | 19516b585feSTom Zanussi +---------+ +---------------+ | | 19616b585feSTom Zanussi | .val |---> NULL . | | 19716b585feSTom Zanussi +-----------+ . | | 19816b585feSTom Zanussi | map_entry | . | | 19916b585feSTom Zanussi +-----------+ +---------------+ | | 20016b585feSTom Zanussi | .key | | .sum (val) or | | | 20116b585feSTom Zanussi +---------+ +---------+ | .offset (key) | | | 20216b585feSTom Zanussi | .val |--->| map_elt | +---------------+ | | 20316b585feSTom Zanussi +-----------+ +---------+ | .sum (val) or | | | 20416b585feSTom Zanussi | map_entry | | .offset (key) | | | 20516b585feSTom Zanussi +-----------+ +---------------+ | | 20616b585feSTom Zanussi | .key |---> pid = 4444 | | 20716b585feSTom Zanussi +---------+ +-----------+ | | 20816b585feSTom Zanussi | .val | | map_elt | | | 20916b585feSTom Zanussi +---------+ +-----------+ | | 21016b585feSTom Zanussi | .key |---> full key * | | 21116b585feSTom Zanussi +---------+ +---------------+ | | 21216b585feSTom Zanussi | .fields |--->| .sum (val) |<-+ | 21316b585feSTom Zanussi +---------+ | 65523 | | 21416b585feSTom Zanussi +---------------+ | 21516b585feSTom Zanussi | .offset (key) |<----+ 21616b585feSTom Zanussi | 0 | 21716b585feSTom Zanussi +---------------+ 21816b585feSTom Zanussi . 21916b585feSTom Zanussi . 22016b585feSTom Zanussi . 22116b585feSTom Zanussi +---------------+ 22216b585feSTom Zanussi | .sum (val) or | 22316b585feSTom Zanussi | .offset (key) | 22416b585feSTom Zanussi +---------------+ 22516b585feSTom Zanussi | .sum (val) or | 22616b585feSTom Zanussi | .offset (key) | 22716b585feSTom Zanussi +---------------+ 22816b585feSTom Zanussi 22916b585feSTom ZanussiAbbreviations used in the diagrams:: 23016b585feSTom Zanussi 23116b585feSTom Zanussi hist_data = struct hist_trigger_data 23216b585feSTom Zanussi hist_data.fields = struct hist_field 23316b585feSTom Zanussi fn = hist_field_fn_t 23416b585feSTom Zanussi map_entry = struct tracing_map_entry 23516b585feSTom Zanussi map_elt = struct tracing_map_elt 23616b585feSTom Zanussi map_elt.fields = struct tracing_map_field 23716b585feSTom Zanussi 23816b585feSTom ZanussiWhenever a new event occurs and it has a hist trigger associated with 23916b585feSTom Zanussiit, event_hist_trigger() is called. event_hist_trigger() first deals 24016b585feSTom Zanussiwith the key: for each subkey in the key (in the above example, there 24116b585feSTom Zanussiis just one subkey corresponding to pid), the hist_field that 24216b585feSTom Zanussirepresents that subkey is retrieved from hist_data.fields[] and the 24316b585feSTom Zanussihist_field_fn_t fn() associated with that field, along with the 24416b585feSTom Zanussifield's size and offset, is used to grab that subkey's data from the 24516b585feSTom Zanussicurrent trace record. 24616b585feSTom Zanussi 24716b585feSTom ZanussiOnce the complete key has been retrieved, it's used to look that key 24816b585feSTom Zanussiup in the tracing_map. If there's no tracing_map_elt associated with 24916b585feSTom Zanussithat key, an empty one is claimed and inserted in the map for the new 25016b585feSTom Zanussikey. In either case, the tracing_map_elt associated with that key is 25116b585feSTom Zanussireturned. 25216b585feSTom Zanussi 25316b585feSTom ZanussiOnce a tracing_map_elt available, hist_trigger_elt_update() is called. 25416b585feSTom ZanussiAs the name implies, this updates the element, which basically means 25516b585feSTom Zanussiupdating the element's fields. There's a tracing_map_field associated 25616b585feSTom Zanussiwith each key and value in the histogram, and each of these correspond 25716b585feSTom Zanussito the key and value hist_fields created when the histogram was 25816b585feSTom Zanussicreated. hist_trigger_elt_update() goes through each value hist_field 25916b585feSTom Zanussiand, as for the keys, uses the hist_field's fn() and size and offset 26016b585feSTom Zanussito grab the field's value from the current trace record. Once it has 26116b585feSTom Zanussithat value, it simply adds that value to that field's 26216b585feSTom Zanussicontinually-updated tracing_map_field.sum member. Some hist_field 26316b585feSTom Zanussifn()s, such as for the hitcount, don't actually grab anything from the 26416b585feSTom Zanussitrace record (the hitcount fn() just increments the counter sum by 1), 26516b585feSTom Zanussibut the idea is the same. 26616b585feSTom Zanussi 26716b585feSTom ZanussiOnce all the values have been updated, hist_trigger_elt_update() is 26816b585feSTom Zanussidone and returns. Note that there are also tracing_map_fields for 26916b585feSTom Zanussieach subkey in the key, but hist_trigger_elt_update() doesn't look at 27016b585feSTom Zanussithem or update anything - those exist only for sorting, which can 27116b585feSTom Zanussihappen later. 27216b585feSTom Zanussi 27316b585feSTom ZanussiBasic histogram test 27416b585feSTom Zanussi-------------------- 27516b585feSTom Zanussi 27616b585feSTom ZanussiThis is a good example to try. It produces 3 value fields and 2 key 27716b585feSTom Zanussifields in the output:: 27816b585feSTom Zanussi 27916b585feSTom Zanussi # echo 'hist:keys=common_pid,call_site.sym:values=bytes_req,bytes_alloc,hitcount' >> events/kmem/kmalloc/trigger 28016b585feSTom Zanussi 28116b585feSTom ZanussiTo see the debug data, cat the kmem/kmalloc's 'hist_debug' file. It 28216b585feSTom Zanussiwill show the trigger info of the histogram it corresponds to, along 28316b585feSTom Zanussiwith the address of the hist_data associated with the histogram, which 28416b585feSTom Zanussiwill become useful in later examples. It then displays the number of 28516b585feSTom Zanussitotal hist_fields associated with the histogram along with a count of 28616b585feSTom Zanussihow many of those correspond to keys and how many correspond to values. 28716b585feSTom Zanussi 28816b585feSTom ZanussiIt then goes on to display details for each field, including the 28916b585feSTom Zanussifield's flags and the position of each field in the hist_data's 29016b585feSTom Zanussifields[] array, which is useful information for verifying that things 29116b585feSTom Zanussiinternally appear correct or not, and which again will become even 29216b585feSTom Zanussimore useful in further examples:: 29316b585feSTom Zanussi 29416b585feSTom Zanussi # cat events/kmem/kmalloc/hist_debug 29516b585feSTom Zanussi 29616b585feSTom Zanussi # event histogram 29716b585feSTom Zanussi # 29816b585feSTom Zanussi # trigger info: hist:keys=common_pid,call_site.sym:vals=hitcount,bytes_req,bytes_alloc:sort=hitcount:size=2048 [active] 29916b585feSTom Zanussi # 30016b585feSTom Zanussi 30116b585feSTom Zanussi hist_data: 000000005e48c9a5 30216b585feSTom Zanussi 30316b585feSTom Zanussi n_vals: 3 30416b585feSTom Zanussi n_keys: 2 30516b585feSTom Zanussi n_fields: 5 30616b585feSTom Zanussi 30716b585feSTom Zanussi val fields: 30816b585feSTom Zanussi 30916b585feSTom Zanussi hist_data->fields[0]: 31016b585feSTom Zanussi flags: 31116b585feSTom Zanussi VAL: HIST_FIELD_FL_HITCOUNT 31216b585feSTom Zanussi type: u64 31316b585feSTom Zanussi size: 8 31416b585feSTom Zanussi is_signed: 0 31516b585feSTom Zanussi 31616b585feSTom Zanussi hist_data->fields[1]: 31716b585feSTom Zanussi flags: 31816b585feSTom Zanussi VAL: normal u64 value 31916b585feSTom Zanussi ftrace_event_field name: bytes_req 32016b585feSTom Zanussi type: size_t 32116b585feSTom Zanussi size: 8 32216b585feSTom Zanussi is_signed: 0 32316b585feSTom Zanussi 32416b585feSTom Zanussi hist_data->fields[2]: 32516b585feSTom Zanussi flags: 32616b585feSTom Zanussi VAL: normal u64 value 32716b585feSTom Zanussi ftrace_event_field name: bytes_alloc 32816b585feSTom Zanussi type: size_t 32916b585feSTom Zanussi size: 8 33016b585feSTom Zanussi is_signed: 0 33116b585feSTom Zanussi 33216b585feSTom Zanussi key fields: 33316b585feSTom Zanussi 33416b585feSTom Zanussi hist_data->fields[3]: 33516b585feSTom Zanussi flags: 33616b585feSTom Zanussi HIST_FIELD_FL_KEY 33716b585feSTom Zanussi ftrace_event_field name: common_pid 33816b585feSTom Zanussi type: int 33916b585feSTom Zanussi size: 8 34016b585feSTom Zanussi is_signed: 1 34116b585feSTom Zanussi 34216b585feSTom Zanussi hist_data->fields[4]: 34316b585feSTom Zanussi flags: 34416b585feSTom Zanussi HIST_FIELD_FL_KEY 34516b585feSTom Zanussi ftrace_event_field name: call_site 34616b585feSTom Zanussi type: unsigned long 34716b585feSTom Zanussi size: 8 34816b585feSTom Zanussi is_signed: 0 34916b585feSTom Zanussi 35016b585feSTom ZanussiThe commands below can be used to clean things up for the next test:: 35116b585feSTom Zanussi 35216b585feSTom Zanussi # echo '!hist:keys=common_pid,call_site.sym:values=bytes_req,bytes_alloc,hitcount' >> events/kmem/kmalloc/trigger 35316b585feSTom Zanussi 35416b585feSTom ZanussiVariables 35516b585feSTom Zanussi========= 35616b585feSTom Zanussi 35716b585feSTom ZanussiVariables allow data from one hist trigger to be saved by one hist 35816b585feSTom Zanussitrigger and retrieved by another hist trigger. For example, a trigger 35916b585feSTom Zanussion the sched_waking event can capture a timestamp for a particular 36016b585feSTom Zanussipid, and later a sched_switch event that switches to that pid event 36116b585feSTom Zanussican grab the timestamp and use it to calculate a time delta between 36216b585feSTom Zanussithe two events:: 36316b585feSTom Zanussi 36416b585feSTom Zanussi # echo 'hist:keys=pid:ts0=common_timestamp.usecs' >> 36516b585feSTom Zanussi events/sched/sched_waking/trigger 36616b585feSTom Zanussi 36716b585feSTom Zanussi # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0' >> 36816b585feSTom Zanussi events/sched/sched_switch/trigger 36916b585feSTom Zanussi 37016b585feSTom ZanussiIn terms of the histogram data structures, variables are implemented 37116b585feSTom Zanussias another type of hist_field and for a given hist trigger are added 37216b585feSTom Zanussito the hist_data.fields[] array just after all the val fields. To 37316b585feSTom Zanussidistinguish them from the existing key and val fields, they're given a 37416b585feSTom Zanussinew flag type, HIST_FIELD_FL_VAR (abbreviated FL_VAR) and they also 37516b585feSTom Zanussimake use of a new .var.idx field member in struct hist_field, which 37616b585feSTom Zanussimaps them to an index in a new map_elt.vars[] array added to the 37716b585feSTom Zanussimap_elt specifically designed to store and retrieve variable values. 37816b585feSTom ZanussiThe diagram below shows those new elements and adds a new variable 37916b585feSTom Zanussientry, ts0, corresponding to the ts0 variable in the sched_waking 38016b585feSTom Zanussitrigger above. 38116b585feSTom Zanussi 38216b585feSTom Zanussisched_waking histogram 383daceabf1STom Zanussi----------------------:: 38416b585feSTom Zanussi 38516b585feSTom Zanussi +------------------+ 38616b585feSTom Zanussi | hist_data |<-------------------------------------------------------+ 38716b585feSTom Zanussi +------------------+ +-------------------+ | 38816b585feSTom Zanussi | .fields[] |-->| val = hitcount | | 38916b585feSTom Zanussi +----------------+ +-------------------+ | 39016b585feSTom Zanussi | .map | | .size | | 39116b585feSTom Zanussi +----------------+ +-----------------+ | 39216b585feSTom Zanussi | .offset | | 39316b585feSTom Zanussi +-----------------+ | 39416b585feSTom Zanussi | .fn() | | 39516b585feSTom Zanussi +-----------------+ | 39616b585feSTom Zanussi | .flags | | 39716b585feSTom Zanussi +-----------------+ | 39816b585feSTom Zanussi | .var.idx | | 39916b585feSTom Zanussi +-------------------+ | 40016b585feSTom Zanussi | var = ts0 | | 40116b585feSTom Zanussi +-------------------+ | 40216b585feSTom Zanussi | .size | | 40316b585feSTom Zanussi +-----------------+ | 40416b585feSTom Zanussi | .offset | | 40516b585feSTom Zanussi +-----------------+ | 40616b585feSTom Zanussi | .fn() | | 40716b585feSTom Zanussi +-----------------+ | 40816b585feSTom Zanussi | .flags & FL_VAR | | 40916b585feSTom Zanussi +-----------------+ | 41016b585feSTom Zanussi | .var.idx |----------------------------+-+ | 41116b585feSTom Zanussi +-----------------+ | | | 41216b585feSTom Zanussi . | | | 41316b585feSTom Zanussi . | | | 41416b585feSTom Zanussi . | | | 41516b585feSTom Zanussi +-------------------+ <--- n_vals | | | 41616b585feSTom Zanussi | key = pid | | | | 41716b585feSTom Zanussi +-------------------+ | | | 41816b585feSTom Zanussi | .size | | | | 41916b585feSTom Zanussi +-----------------+ | | | 42016b585feSTom Zanussi | .offset | | | | 42116b585feSTom Zanussi +-----------------+ | | | 42216b585feSTom Zanussi | .fn() | | | | 42316b585feSTom Zanussi +-----------------+ | | | 42416b585feSTom Zanussi | .flags & FL_KEY | | | | 42516b585feSTom Zanussi +-----------------+ | | | 42616b585feSTom Zanussi | .var.idx | | | | 42716b585feSTom Zanussi +-------------------+ <--- n_fields | | | 42816b585feSTom Zanussi | unused | | | | 42916b585feSTom Zanussi +-------------------+ | | | 43016b585feSTom Zanussi | | | | | 43116b585feSTom Zanussi +-----------------+ | | | 43216b585feSTom Zanussi | | | | | 43316b585feSTom Zanussi +-----------------+ | | | 43416b585feSTom Zanussi | | | | | 43516b585feSTom Zanussi +-----------------+ | | | 43616b585feSTom Zanussi | | | | | 43716b585feSTom Zanussi +-----------------+ | | | 43816b585feSTom Zanussi | | | | | 43916b585feSTom Zanussi +-----------------+ | | | 44016b585feSTom Zanussi n_keys = n_fields - n_vals | | | 44116b585feSTom Zanussi | | | 442daceabf1STom Zanussi 44316b585feSTom ZanussiThis is very similar to the basic case. In the above diagram, we can | | | 44416b585feSTom Zanussisee a new .flags member has been added to the struct hist_field | | | 44516b585feSTom Zanussistruct, and a new entry added to hist_data.fields representing the ts0 | | | 44616b585feSTom Zanussivariable. For a normal val hist_field, .flags is just 0 (modulo | | | 44716b585feSTom Zanussimodifier flags), but if the value is defined as a variable, the .flags | | | 44816b585feSTom Zanussicontains a set FL_VAR bit. | | | 449daceabf1STom Zanussi 45016b585feSTom ZanussiAs you can see, the ts0 entry's .var.idx member contains the index | | | 45116b585feSTom Zanussiinto the tracing_map_elts' .vars[] array containing variable values. | | | 45216b585feSTom ZanussiThis idx is used whenever the value of the variable is set or read. | | | 45316b585feSTom ZanussiThe map_elt.vars idx assigned to the given variable is assigned and | | | 45416b585feSTom Zanussisaved in .var.idx by create_tracing_map_fields() after it calls | | | 45516b585feSTom Zanussitracing_map_add_var(). | | | 456daceabf1STom Zanussi 45716b585feSTom ZanussiBelow is a representation of the histogram at run-time, which | | | 45816b585feSTom Zanussipopulates the map, along with correspondence to the above hist_data and | | | 45916b585feSTom Zanussihist_field data structures. | | | 460daceabf1STom Zanussi 46116b585feSTom ZanussiThe diagram attempts to show the relationship between the | | | 46216b585feSTom Zanussihist_data.fields[] and the map_elt.fields[] and map_elt.vars[] with | | | 46316b585feSTom Zanussithe links drawn between diagrams. For each of the map_elts, you can | | | 46416b585feSTom Zanussisee that the .fields[] members point to the .sum or .offset of a key | | | 46516b585feSTom Zanussior val and the .vars[] members point to the value of a variable. The | | | 46616b585feSTom Zanussiarrows between the two diagrams show the linkages between those | | | 46716b585feSTom Zanussitracing_map members and the field definitions in the corresponding | | | 468daceabf1STom Zanussihist_data fields[] members.:: 469daceabf1STom Zanussi 47016b585feSTom Zanussi +-----------+ | | | 47116b585feSTom Zanussi | hist_data | | | | 47216b585feSTom Zanussi +-----------+ | | | 47316b585feSTom Zanussi | .fields | | | | 47416b585feSTom Zanussi +---------+ +-----------+ | | | 47516b585feSTom Zanussi | .map |---->| map_entry | | | | 47616b585feSTom Zanussi +---------+ +-----------+ | | | 47716b585feSTom Zanussi | .key |---> 0 | | | 47816b585feSTom Zanussi +---------+ | | | 47916b585feSTom Zanussi | .val |---> NULL | | | 48016b585feSTom Zanussi +-----------+ | | | 48116b585feSTom Zanussi | map_entry | | | | 48216b585feSTom Zanussi +-----------+ | | | 48316b585feSTom Zanussi | .key |---> pid = 999 | | | 48416b585feSTom Zanussi +---------+ +-----------+ | | | 48516b585feSTom Zanussi | .val |--->| map_elt | | | | 48616b585feSTom Zanussi +---------+ +-----------+ | | | 48716b585feSTom Zanussi . | .key |---> full key * | | | 48816b585feSTom Zanussi . +---------+ +---------------+ | | | 48916b585feSTom Zanussi . | .fields |--->| .sum (val) | | | | 49016b585feSTom Zanussi . +---------+ | 2345 | | | | 49116b585feSTom Zanussi . +--| .vars | +---------------+ | | | 49216b585feSTom Zanussi . | +---------+ | .offset (key) | | | | 49316b585feSTom Zanussi . | | 0 | | | | 49416b585feSTom Zanussi . | +---------------+ | | | 49516b585feSTom Zanussi . | . | | | 49616b585feSTom Zanussi . | . | | | 49716b585feSTom Zanussi . | . | | | 49816b585feSTom Zanussi . | +---------------+ | | | 49916b585feSTom Zanussi . | | .sum (val) or | | | | 50016b585feSTom Zanussi . | | .offset (key) | | | | 50116b585feSTom Zanussi . | +---------------+ | | | 50216b585feSTom Zanussi . | | .sum (val) or | | | | 50316b585feSTom Zanussi . | | .offset (key) | | | | 50416b585feSTom Zanussi . | +---------------+ | | | 50516b585feSTom Zanussi . | | | | 50616b585feSTom Zanussi . +---------------->+---------------+ | | | 50716b585feSTom Zanussi . | ts0 |<--+ | | 50816b585feSTom Zanussi . | 113345679876 | | | | 50916b585feSTom Zanussi . +---------------+ | | | 51016b585feSTom Zanussi . | unused | | | | 51116b585feSTom Zanussi . | | | | | 51216b585feSTom Zanussi . +---------------+ | | | 51316b585feSTom Zanussi . . | | | 51416b585feSTom Zanussi . . | | | 51516b585feSTom Zanussi . . | | | 51616b585feSTom Zanussi . +---------------+ | | | 51716b585feSTom Zanussi . | unused | | | | 51816b585feSTom Zanussi . | | | | | 51916b585feSTom Zanussi . +---------------+ | | | 52016b585feSTom Zanussi . | unused | | | | 52116b585feSTom Zanussi . | | | | | 52216b585feSTom Zanussi . +---------------+ | | | 52316b585feSTom Zanussi . | | | 52416b585feSTom Zanussi +-----------+ | | | 52516b585feSTom Zanussi | map_entry | | | | 52616b585feSTom Zanussi +-----------+ | | | 52716b585feSTom Zanussi | .key |---> pid = 4444 | | | 52816b585feSTom Zanussi +---------+ +-----------+ | | | 52916b585feSTom Zanussi | .val |--->| map_elt | | | | 53016b585feSTom Zanussi +---------+ +-----------+ | | | 53116b585feSTom Zanussi . | .key |---> full key * | | | 53216b585feSTom Zanussi . +---------+ +---------------+ | | | 53316b585feSTom Zanussi . | .fields |--->| .sum (val) | | | | 53416b585feSTom Zanussi +---------+ | 2345 | | | | 53516b585feSTom Zanussi +--| .vars | +---------------+ | | | 53616b585feSTom Zanussi | +---------+ | .offset (key) | | | | 53716b585feSTom Zanussi | | 0 | | | | 53816b585feSTom Zanussi | +---------------+ | | | 53916b585feSTom Zanussi | . | | | 54016b585feSTom Zanussi | . | | | 54116b585feSTom Zanussi | . | | | 54216b585feSTom Zanussi | +---------------+ | | | 54316b585feSTom Zanussi | | .sum (val) or | | | | 54416b585feSTom Zanussi | | .offset (key) | | | | 54516b585feSTom Zanussi | +---------------+ | | | 54616b585feSTom Zanussi | | .sum (val) or | | | | 54716b585feSTom Zanussi | | .offset (key) | | | | 54816b585feSTom Zanussi | +---------------+ | | | 54916b585feSTom Zanussi | | | | 55016b585feSTom Zanussi | +---------------+ | | | 55116b585feSTom Zanussi +---------------->| ts0 |<--+ | | 55216b585feSTom Zanussi | 213499240729 | | | 55316b585feSTom Zanussi +---------------+ | | 55416b585feSTom Zanussi | unused | | | 55516b585feSTom Zanussi | | | | 55616b585feSTom Zanussi +---------------+ | | 55716b585feSTom Zanussi . | | 55816b585feSTom Zanussi . | | 55916b585feSTom Zanussi . | | 56016b585feSTom Zanussi +---------------+ | | 56116b585feSTom Zanussi | unused | | | 56216b585feSTom Zanussi | | | | 56316b585feSTom Zanussi +---------------+ | | 56416b585feSTom Zanussi | unused | | | 56516b585feSTom Zanussi | | | | 56616b585feSTom Zanussi +---------------+ | | 567daceabf1STom Zanussi 56816b585feSTom ZanussiFor each used map entry, there's a map_elt pointing to an array of | | 56916b585feSTom Zanussi.vars containing the current value of the variables associated with | | 57016b585feSTom Zanussithat histogram entry. So in the above, the timestamp associated with | | 57116b585feSTom Zanussipid 999 is 113345679876, and the timestamp variable in the same | | 57216b585feSTom Zanussi.var.idx for pid 4444 is 213499240729. | | 573daceabf1STom Zanussi 57416b585feSTom Zanussisched_switch histogram | | 57516b585feSTom Zanussi---------------------- | | 576daceabf1STom Zanussi 57716b585feSTom ZanussiThe sched_switch histogram paired with the above sched_waking | | 57816b585feSTom Zanussihistogram is shown below. The most important aspect of the | | 57916b585feSTom Zanussisched_switch histogram is that it references a variable on the | | 58016b585feSTom Zanussisched_waking histogram above. | | 581daceabf1STom Zanussi 58216b585feSTom ZanussiThe histogram diagram is very similar to the others so far displayed, | | 58316b585feSTom Zanussibut it adds variable references. You can see the normal hitcount and | | 58416b585feSTom Zanussikey fields along with a new wakeup_lat variable implemented in the | | 58516b585feSTom Zanussisame way as the sched_waking ts0 variable, but in addition there's an | | 58616b585feSTom Zanussientry with the new FL_VAR_REF (short for HIST_FIELD_FL_VAR_REF) flag. | | 587daceabf1STom Zanussi 58816b585feSTom ZanussiAssociated with the new var ref field are a couple of new hist_field | | 58916b585feSTom Zanussimembers, var.hist_data and var_ref_idx. For a variable reference, the | | 59016b585feSTom Zanussivar.hist_data goes with the var.idx, which together uniquely identify | | 59116b585feSTom Zanussia particular variable on a particular histogram. The var_ref_idx is | | 59216b585feSTom Zanussijust the index into the var_ref_vals[] array that caches the values of | | 59316b585feSTom Zanussieach variable whenever a hist trigger is updated. Those resulting | | 59416b585feSTom Zanussivalues are then finally accessed by other code such as trace action | | 59516b585feSTom Zanussicode that uses the var_ref_idx values to assign param values. | | 596daceabf1STom Zanussi 59716b585feSTom ZanussiThe diagram below describes the situation for the sched_switch | | 598daceabf1STom Zanussihistogram referred to before:: 599daceabf1STom Zanussi 60016b585feSTom Zanussi # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0' >> | | 60116b585feSTom Zanussi events/sched/sched_switch/trigger | | 60216b585feSTom Zanussi | | 60316b585feSTom Zanussi +------------------+ | | 60416b585feSTom Zanussi | hist_data | | | 60516b585feSTom Zanussi +------------------+ +-----------------------+ | | 60616b585feSTom Zanussi | .fields[] |-->| val = hitcount | | | 60716b585feSTom Zanussi +----------------+ +-----------------------+ | | 60816b585feSTom Zanussi | .map | | .size | | | 60916b585feSTom Zanussi +----------------+ +---------------------+ | | 61016b585feSTom Zanussi +--| .var_refs[] | | .offset | | | 61116b585feSTom Zanussi | +----------------+ +---------------------+ | | 61216b585feSTom Zanussi | | .fn() | | | 61316b585feSTom Zanussi | var_ref_vals[] +---------------------+ | | 61416b585feSTom Zanussi | +-------------+ | .flags | | | 61516b585feSTom Zanussi | | $ts0 |<---+ +---------------------+ | | 61616b585feSTom Zanussi | +-------------+ | | .var.idx | | | 61716b585feSTom Zanussi | | | | +---------------------+ | | 61816b585feSTom Zanussi | +-------------+ | | .var.hist_data | | | 61916b585feSTom Zanussi | | | | +---------------------+ | | 62016b585feSTom Zanussi | +-------------+ | | .var_ref_idx | | | 62116b585feSTom Zanussi | | | | +-----------------------+ | | 62216b585feSTom Zanussi | +-------------+ | | var = wakeup_lat | | | 62316b585feSTom Zanussi | . | +-----------------------+ | | 62416b585feSTom Zanussi | . | | .size | | | 62516b585feSTom Zanussi | . | +---------------------+ | | 62616b585feSTom Zanussi | +-------------+ | | .offset | | | 62716b585feSTom Zanussi | | | | +---------------------+ | | 62816b585feSTom Zanussi | +-------------+ | | .fn() | | | 62916b585feSTom Zanussi | | | | +---------------------+ | | 63016b585feSTom Zanussi | +-------------+ | | .flags & FL_VAR | | | 63116b585feSTom Zanussi | | +---------------------+ | | 63216b585feSTom Zanussi | | | .var.idx | | | 63316b585feSTom Zanussi | | +---------------------+ | | 63416b585feSTom Zanussi | | | .var.hist_data | | | 63516b585feSTom Zanussi | | +---------------------+ | | 63616b585feSTom Zanussi | | | .var_ref_idx | | | 63716b585feSTom Zanussi | | +---------------------+ | | 63816b585feSTom Zanussi | | . | | 63916b585feSTom Zanussi | | . | | 64016b585feSTom Zanussi | | . | | 64116b585feSTom Zanussi | | +-----------------------+ <--- n_vals | | 64216b585feSTom Zanussi | | | key = pid | | | 64316b585feSTom Zanussi | | +-----------------------+ | | 64416b585feSTom Zanussi | | | .size | | | 64516b585feSTom Zanussi | | +---------------------+ | | 64616b585feSTom Zanussi | | | .offset | | | 64716b585feSTom Zanussi | | +---------------------+ | | 64816b585feSTom Zanussi | | | .fn() | | | 64916b585feSTom Zanussi | | +---------------------+ | | 65016b585feSTom Zanussi | | | .flags | | | 65116b585feSTom Zanussi | | +---------------------+ | | 65216b585feSTom Zanussi | | | .var.idx | | | 65316b585feSTom Zanussi | | +-----------------------+ <--- n_fields | | 65416b585feSTom Zanussi | | | unused | | | 65516b585feSTom Zanussi | | +-----------------------+ | | 65616b585feSTom Zanussi | | | | | | 65716b585feSTom Zanussi | | +---------------------+ | | 65816b585feSTom Zanussi | | | | | | 65916b585feSTom Zanussi | | +---------------------+ | | 66016b585feSTom Zanussi | | | | | | 66116b585feSTom Zanussi | | +---------------------+ | | 66216b585feSTom Zanussi | | | | | | 66316b585feSTom Zanussi | | +---------------------+ | | 66416b585feSTom Zanussi | | | | | | 66516b585feSTom Zanussi | | +---------------------+ | | 66616b585feSTom Zanussi | | n_keys = n_fields - n_vals | | 66716b585feSTom Zanussi | | | | 66816b585feSTom Zanussi | | | | 66916b585feSTom Zanussi | | +-----------------------+ | | 67016b585feSTom Zanussi +---------------------->| var_ref = $ts0 | | | 67116b585feSTom Zanussi | +-----------------------+ | | 67216b585feSTom Zanussi | | .size | | | 67316b585feSTom Zanussi | +---------------------+ | | 67416b585feSTom Zanussi | | .offset | | | 67516b585feSTom Zanussi | +---------------------+ | | 67616b585feSTom Zanussi | | .fn() | | | 67716b585feSTom Zanussi | +---------------------+ | | 67816b585feSTom Zanussi | | .flags & FL_VAR_REF | | | 67916b585feSTom Zanussi | +---------------------+ | | 68016b585feSTom Zanussi | | .var.idx |--------------------------+ | 68116b585feSTom Zanussi | +---------------------+ | 68216b585feSTom Zanussi | | .var.hist_data |----------------------------+ 68316b585feSTom Zanussi | +---------------------+ 68416b585feSTom Zanussi +---| .var_ref_idx | 68516b585feSTom Zanussi +---------------------+ 68616b585feSTom Zanussi 68716b585feSTom ZanussiAbbreviations used in the diagrams:: 68816b585feSTom Zanussi 68916b585feSTom Zanussi hist_data = struct hist_trigger_data 69016b585feSTom Zanussi hist_data.fields = struct hist_field 69116b585feSTom Zanussi fn = hist_field_fn_t 69216b585feSTom Zanussi FL_KEY = HIST_FIELD_FL_KEY 69316b585feSTom Zanussi FL_VAR = HIST_FIELD_FL_VAR 69416b585feSTom Zanussi FL_VAR_REF = HIST_FIELD_FL_VAR_REF 69516b585feSTom Zanussi 69616b585feSTom ZanussiWhen a hist trigger makes use of a variable, a new hist_field is 69716b585feSTom Zanussicreated with flag HIST_FIELD_FL_VAR_REF. For a VAR_REF field, the 69816b585feSTom Zanussivar.idx and var.hist_data take the same values as the referenced 69916b585feSTom Zanussivariable, as well as the referenced variable's size, type, and 70016b585feSTom Zanussiis_signed values. The VAR_REF field's .name is set to the name of the 70116b585feSTom Zanussivariable it references. If a variable reference was created using the 70216b585feSTom Zanussiexplicit system.event.$var_ref notation, the hist_field's system and 70309068445SSteven Rostedt (VMware)event_name variables are also set. 70416b585feSTom Zanussi 70516b585feSTom ZanussiSo, in order to handle an event for the sched_switch histogram, 70616b585feSTom Zanussibecause we have a reference to a variable on another histogram, we 70716b585feSTom Zanussineed to resolve all variable references first. This is done via the 70816b585feSTom Zanussiresolve_var_refs() calls made from event_hist_trigger(). What this 70916b585feSTom Zanussidoes is grabs the var_refs[] array from the hist_data representing the 71016b585feSTom Zanussisched_switch histogram. For each one of those, the referenced 71116b585feSTom Zanussivariable's var.hist_data along with the current key is used to look up 71216b585feSTom Zanussithe corresponding tracing_map_elt in that histogram. Once found, the 71316b585feSTom Zanussireferenced variable's var.idx is used to look up the variable's value 71416b585feSTom Zanussiusing tracing_map_read_var(elt, var.idx), which yields the value of 71516b585feSTom Zanussithe variable for that element, ts0 in the case above. Note that both 71616b585feSTom Zanussithe hist_fields representing both the variable and the variable 71716b585feSTom Zanussireference have the same var.idx, so this is straightforward. 71816b585feSTom Zanussi 71916b585feSTom ZanussiVariable and variable reference test 72016b585feSTom Zanussi------------------------------------ 72116b585feSTom Zanussi 72216b585feSTom ZanussiThis example creates a variable on the sched_waking event, ts0, and 72316b585feSTom Zanussiuses it in the sched_switch trigger. The sched_switch trigger also 72416b585feSTom Zanussicreates its own variable, wakeup_lat, but nothing yet uses it:: 72516b585feSTom Zanussi 72616b585feSTom Zanussi # echo 'hist:keys=pid:ts0=common_timestamp.usecs' >> events/sched/sched_waking/trigger 72716b585feSTom Zanussi 72816b585feSTom Zanussi # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0' >> events/sched/sched_switch/trigger 72916b585feSTom Zanussi 73016b585feSTom ZanussiLooking at the sched_waking 'hist_debug' output, in addition to the 73116b585feSTom Zanussinormal key and value hist_fields, in the val fields section we see a 73216b585feSTom Zanussifield with the HIST_FIELD_FL_VAR flag, which indicates that that field 73316b585feSTom Zanussirepresents a variable. Note that in addition to the variable name, 73416b585feSTom Zanussicontained in the var.name field, it includes the var.idx, which is the 73516b585feSTom Zanussiindex into the tracing_map_elt.vars[] array of the actual variable 73616b585feSTom Zanussilocation. Note also that the output shows that variables live in the 73716b585feSTom Zanussisame part of the hist_data->fields[] array as normal values:: 73816b585feSTom Zanussi 73916b585feSTom Zanussi # cat events/sched/sched_waking/hist_debug 74016b585feSTom Zanussi 74116b585feSTom Zanussi # event histogram 74216b585feSTom Zanussi # 74316b585feSTom Zanussi # trigger info: hist:keys=pid:vals=hitcount:ts0=common_timestamp.usecs:sort=hitcount:size=2048:clock=global [active] 74416b585feSTom Zanussi # 74516b585feSTom Zanussi 74616b585feSTom Zanussi hist_data: 000000009536f554 74716b585feSTom Zanussi 74816b585feSTom Zanussi n_vals: 2 74916b585feSTom Zanussi n_keys: 1 75016b585feSTom Zanussi n_fields: 3 75116b585feSTom Zanussi 75216b585feSTom Zanussi val fields: 75316b585feSTom Zanussi 75416b585feSTom Zanussi hist_data->fields[0]: 75516b585feSTom Zanussi flags: 75616b585feSTom Zanussi VAL: HIST_FIELD_FL_HITCOUNT 75716b585feSTom Zanussi type: u64 75816b585feSTom Zanussi size: 8 75916b585feSTom Zanussi is_signed: 0 76016b585feSTom Zanussi 76116b585feSTom Zanussi hist_data->fields[1]: 76216b585feSTom Zanussi flags: 76316b585feSTom Zanussi HIST_FIELD_FL_VAR 76416b585feSTom Zanussi var.name: ts0 76516b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 76616b585feSTom Zanussi type: u64 76716b585feSTom Zanussi size: 8 76816b585feSTom Zanussi is_signed: 0 76916b585feSTom Zanussi 77016b585feSTom Zanussi key fields: 77116b585feSTom Zanussi 77216b585feSTom Zanussi hist_data->fields[2]: 77316b585feSTom Zanussi flags: 77416b585feSTom Zanussi HIST_FIELD_FL_KEY 77516b585feSTom Zanussi ftrace_event_field name: pid 77616b585feSTom Zanussi type: pid_t 77716b585feSTom Zanussi size: 8 77816b585feSTom Zanussi is_signed: 1 77916b585feSTom Zanussi 78016b585feSTom ZanussiMoving on to the sched_switch trigger hist_debug output, in addition 78116b585feSTom Zanussito the unused wakeup_lat variable, we see a new section displaying 78216b585feSTom Zanussivariable references. Variable references are displayed in a separate 7832e171403SRandy Dunlapsection because in addition to being logically separate from 78416b585feSTom Zanussivariables and values, they actually live in a separate hist_data 78516b585feSTom Zanussiarray, var_refs[]. 78616b585feSTom Zanussi 78716b585feSTom ZanussiIn this example, the sched_switch trigger has a reference to a 78816b585feSTom Zanussivariable on the sched_waking trigger, $ts0. Looking at the details, 78916b585feSTom Zanussiwe can see that the var.hist_data value of the referenced variable 79016b585feSTom Zanussimatches the previously displayed sched_waking trigger, and the var.idx 79116b585feSTom Zanussivalue matches the previously displayed var.idx value for that 79216b585feSTom Zanussivariable. Also displayed is the var_ref_idx value for that variable 79316b585feSTom Zanussireference, which is where the value for that variable is cached for 79416b585feSTom Zanussiuse when the trigger is invoked:: 79516b585feSTom Zanussi 79616b585feSTom Zanussi # cat events/sched/sched_switch/hist_debug 79716b585feSTom Zanussi 79816b585feSTom Zanussi # event histogram 79916b585feSTom Zanussi # 80016b585feSTom Zanussi # trigger info: hist:keys=next_pid:vals=hitcount:wakeup_lat=common_timestamp.usecs-$ts0:sort=hitcount:size=2048:clock=global [active] 80116b585feSTom Zanussi # 80216b585feSTom Zanussi 80316b585feSTom Zanussi hist_data: 00000000f4ee8006 80416b585feSTom Zanussi 80516b585feSTom Zanussi n_vals: 2 80616b585feSTom Zanussi n_keys: 1 80716b585feSTom Zanussi n_fields: 3 80816b585feSTom Zanussi 80916b585feSTom Zanussi val fields: 81016b585feSTom Zanussi 81116b585feSTom Zanussi hist_data->fields[0]: 81216b585feSTom Zanussi flags: 81316b585feSTom Zanussi VAL: HIST_FIELD_FL_HITCOUNT 81416b585feSTom Zanussi type: u64 81516b585feSTom Zanussi size: 8 81616b585feSTom Zanussi is_signed: 0 81716b585feSTom Zanussi 81816b585feSTom Zanussi hist_data->fields[1]: 81916b585feSTom Zanussi flags: 82016b585feSTom Zanussi HIST_FIELD_FL_VAR 82116b585feSTom Zanussi var.name: wakeup_lat 82216b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 82316b585feSTom Zanussi type: u64 82416b585feSTom Zanussi size: 0 82516b585feSTom Zanussi is_signed: 0 82616b585feSTom Zanussi 82716b585feSTom Zanussi key fields: 82816b585feSTom Zanussi 82916b585feSTom Zanussi hist_data->fields[2]: 83016b585feSTom Zanussi flags: 83116b585feSTom Zanussi HIST_FIELD_FL_KEY 83216b585feSTom Zanussi ftrace_event_field name: next_pid 83316b585feSTom Zanussi type: pid_t 83416b585feSTom Zanussi size: 8 83516b585feSTom Zanussi is_signed: 1 83616b585feSTom Zanussi 83716b585feSTom Zanussi variable reference fields: 83816b585feSTom Zanussi 83916b585feSTom Zanussi hist_data->var_refs[0]: 84016b585feSTom Zanussi flags: 84116b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 84216b585feSTom Zanussi name: ts0 84316b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 84416b585feSTom Zanussi var.hist_data: 000000009536f554 84516b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 0 84616b585feSTom Zanussi type: u64 84716b585feSTom Zanussi size: 8 84816b585feSTom Zanussi is_signed: 0 84916b585feSTom Zanussi 85016b585feSTom ZanussiThe commands below can be used to clean things up for the next test:: 85116b585feSTom Zanussi 85216b585feSTom Zanussi # echo '!hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0' >> events/sched/sched_switch/trigger 85316b585feSTom Zanussi 85416b585feSTom Zanussi # echo '!hist:keys=pid:ts0=common_timestamp.usecs' >> events/sched/sched_waking/trigger 85516b585feSTom Zanussi 85616b585feSTom ZanussiActions and Handlers 85716b585feSTom Zanussi==================== 85816b585feSTom Zanussi 85916b585feSTom ZanussiAdding onto the previous example, we will now do something with that 86016b585feSTom Zanussiwakeup_lat variable, namely send it and another field as a synthetic 86116b585feSTom Zanussievent. 86216b585feSTom Zanussi 86316b585feSTom ZanussiThe onmatch() action below basically says that whenever we have a 86416b585feSTom Zanussisched_switch event, if we have a matching sched_waking event, in this 86516b585feSTom Zanussicase if we have a pid in the sched_waking histogram that matches the 8662e171403SRandy Dunlapnext_pid field on this sched_switch event, we retrieve the 86716b585feSTom Zanussivariables specified in the wakeup_latency() trace action, and use 86816b585feSTom Zanussithem to generate a new wakeup_latency event into the trace stream. 86916b585feSTom Zanussi 87016b585feSTom ZanussiNote that the way the trace handlers such as wakeup_latency() (which 87116b585feSTom Zanussicould equivalently be written trace(wakeup_latency,$wakeup_lat,next_pid) 87216b585feSTom Zanussiare implemented, the parameters specified to the trace handler must be 87316b585feSTom Zanussivariables. In this case, $wakeup_lat is obviously a variable, but 87416b585feSTom Zanussinext_pid isn't, since it's just naming a field in the sched_switch 87516b585feSTom Zanussitrace event. Since this is something that almost every trace() and 87616b585feSTom Zanussisave() action does, a special shortcut is implemented to allow field 87716b585feSTom Zanussinames to be used directly in those cases. How it works is that under 87816b585feSTom Zanussithe covers, a temporary variable is created for the named field, and 87916b585feSTom Zanussithis variable is what is actually passed to the trace handler. In the 88016b585feSTom Zanussicode and documentation, this type of variable is called a 'field 88116b585feSTom Zanussivariable'. 88216b585feSTom Zanussi 88316b585feSTom ZanussiFields on other trace event's histograms can be used as well. In that 88416b585feSTom Zanussicase we have to generate a new histogram and an unfortunately named 88516b585feSTom Zanussi'synthetic_field' (the use of synthetic here has nothing to do with 88616b585feSTom Zanussisynthetic events) and use that special histogram field as a variable. 88716b585feSTom Zanussi 88816b585feSTom ZanussiThe diagram below illustrates the new elements described above in the 88916b585feSTom Zanussicontext of the sched_switch histogram using the onmatch() handler and 89016b585feSTom Zanussithe trace() action. 89116b585feSTom Zanussi 89216b585feSTom ZanussiFirst, we define the wakeup_latency synthetic event:: 89316b585feSTom Zanussi 89416b585feSTom Zanussi # echo 'wakeup_latency u64 lat; pid_t pid' >> synthetic_events 89516b585feSTom Zanussi 89616b585feSTom ZanussiNext, the sched_waking hist trigger as before:: 89716b585feSTom Zanussi 89816b585feSTom Zanussi # echo 'hist:keys=pid:ts0=common_timestamp.usecs' >> 89916b585feSTom Zanussi events/sched/sched_waking/trigger 90016b585feSTom Zanussi 90116b585feSTom ZanussiFinally, we create a hist trigger on the sched_switch event that 90216b585feSTom Zanussigenerates a wakeup_latency() trace event. In this case we pass 90316b585feSTom Zanussinext_pid into the wakeup_latency synthetic event invocation, which 90416b585feSTom Zanussimeans it will be automatically converted into a field variable:: 90516b585feSTom Zanussi 90616b585feSTom Zanussi # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0: \ 90716b585feSTom Zanussi onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,next_pid)' >> 908*2abfcd29SRoss Zwisler /sys/kernel/tracing/events/sched/sched_switch/trigger 90916b585feSTom Zanussi 91016b585feSTom ZanussiThe diagram for the sched_switch event is similar to previous examples 91116b585feSTom Zanussibut shows the additional field_vars[] array for hist_data and shows 91216b585feSTom Zanussithe linkages between the field_vars and the variables and references 91316b585feSTom Zanussicreated to implement the field variables. The details are discussed 91416b585feSTom Zanussibelow:: 91516b585feSTom Zanussi 91616b585feSTom Zanussi +------------------+ 91716b585feSTom Zanussi | hist_data | 91816b585feSTom Zanussi +------------------+ +-----------------------+ 91916b585feSTom Zanussi | .fields[] |-->| val = hitcount | 92016b585feSTom Zanussi +----------------+ +-----------------------+ 92116b585feSTom Zanussi | .map | | .size | 92216b585feSTom Zanussi +----------------+ +---------------------+ 92316b585feSTom Zanussi +---| .field_vars[] | | .offset | 92416b585feSTom Zanussi | +----------------+ +---------------------+ 92516b585feSTom Zanussi |+--| .var_refs[] | | .offset | 92616b585feSTom Zanussi || +----------------+ +---------------------+ 92716b585feSTom Zanussi || | .fn() | 92816b585feSTom Zanussi || var_ref_vals[] +---------------------+ 92916b585feSTom Zanussi || +-------------+ | .flags | 93016b585feSTom Zanussi || | $ts0 |<---+ +---------------------+ 93116b585feSTom Zanussi || +-------------+ | | .var.idx | 93216b585feSTom Zanussi || | $next_pid |<-+ | +---------------------+ 93316b585feSTom Zanussi || +-------------+ | | | .var.hist_data | 93416b585feSTom Zanussi ||+>| $wakeup_lat | | | +---------------------+ 93516b585feSTom Zanussi ||| +-------------+ | | | .var_ref_idx | 93616b585feSTom Zanussi ||| | | | | +-----------------------+ 93716b585feSTom Zanussi ||| +-------------+ | | | var = wakeup_lat | 93816b585feSTom Zanussi ||| . | | +-----------------------+ 93916b585feSTom Zanussi ||| . | | | .size | 94016b585feSTom Zanussi ||| . | | +---------------------+ 94116b585feSTom Zanussi ||| +-------------+ | | | .offset | 94216b585feSTom Zanussi ||| | | | | +---------------------+ 94316b585feSTom Zanussi ||| +-------------+ | | | .fn() | 94416b585feSTom Zanussi ||| | | | | +---------------------+ 94516b585feSTom Zanussi ||| +-------------+ | | | .flags & FL_VAR | 94616b585feSTom Zanussi ||| | | +---------------------+ 94716b585feSTom Zanussi ||| | | | .var.idx | 94816b585feSTom Zanussi ||| | | +---------------------+ 94916b585feSTom Zanussi ||| | | | .var.hist_data | 95016b585feSTom Zanussi ||| | | +---------------------+ 95116b585feSTom Zanussi ||| | | | .var_ref_idx | 95216b585feSTom Zanussi ||| | | +---------------------+ 95316b585feSTom Zanussi ||| | | . 95416b585feSTom Zanussi ||| | | . 95516b585feSTom Zanussi ||| | | . 95616b585feSTom Zanussi ||| | | . 95716b585feSTom Zanussi ||| +--------------+ | | . 95816b585feSTom Zanussi +-->| field_var | | | . 95916b585feSTom Zanussi || +--------------+ | | . 96016b585feSTom Zanussi || | var | | | . 96116b585feSTom Zanussi || +------------+ | | . 96216b585feSTom Zanussi || | val | | | . 96316b585feSTom Zanussi || +--------------+ | | . 96416b585feSTom Zanussi || | field_var | | | . 96516b585feSTom Zanussi || +--------------+ | | . 96616b585feSTom Zanussi || | var | | | . 96716b585feSTom Zanussi || +------------+ | | . 96816b585feSTom Zanussi || | val | | | . 96916b585feSTom Zanussi || +------------+ | | . 97016b585feSTom Zanussi || . | | . 97116b585feSTom Zanussi || . | | . 97216b585feSTom Zanussi || . | | +-----------------------+ <--- n_vals 97316b585feSTom Zanussi || +--------------+ | | | key = pid | 97416b585feSTom Zanussi || | field_var | | | +-----------------------+ 97516b585feSTom Zanussi || +--------------+ | | | .size | 97616b585feSTom Zanussi || | var |--+| +---------------------+ 97716b585feSTom Zanussi || +------------+ ||| | .offset | 97816b585feSTom Zanussi || | val |-+|| +---------------------+ 97916b585feSTom Zanussi || +------------+ ||| | .fn() | 98016b585feSTom Zanussi || ||| +---------------------+ 98116b585feSTom Zanussi || ||| | .flags | 98216b585feSTom Zanussi || ||| +---------------------+ 98316b585feSTom Zanussi || ||| | .var.idx | 98416b585feSTom Zanussi || ||| +---------------------+ <--- n_fields 98516b585feSTom Zanussi || ||| 98616b585feSTom Zanussi || ||| n_keys = n_fields - n_vals 98716b585feSTom Zanussi || ||| +-----------------------+ 98816b585feSTom Zanussi || |+->| var = next_pid | 98916b585feSTom Zanussi || | | +-----------------------+ 99016b585feSTom Zanussi || | | | .size | 99116b585feSTom Zanussi || | | +---------------------+ 99216b585feSTom Zanussi || | | | .offset | 99316b585feSTom Zanussi || | | +---------------------+ 99416b585feSTom Zanussi || | | | .flags & FL_VAR | 99516b585feSTom Zanussi || | | +---------------------+ 99616b585feSTom Zanussi || | | | .var.idx | 99716b585feSTom Zanussi || | | +---------------------+ 99816b585feSTom Zanussi || | | | .var.hist_data | 99916b585feSTom Zanussi || | | +-----------------------+ 100016b585feSTom Zanussi || +-->| val for next_pid | 100116b585feSTom Zanussi || | | +-----------------------+ 100216b585feSTom Zanussi || | | | .size | 100316b585feSTom Zanussi || | | +---------------------+ 100416b585feSTom Zanussi || | | | .offset | 100516b585feSTom Zanussi || | | +---------------------+ 100616b585feSTom Zanussi || | | | .fn() | 100716b585feSTom Zanussi || | | +---------------------+ 100816b585feSTom Zanussi || | | | .flags | 100916b585feSTom Zanussi || | | +---------------------+ 101016b585feSTom Zanussi || | | | | 101116b585feSTom Zanussi || | | +---------------------+ 101216b585feSTom Zanussi || | | 101316b585feSTom Zanussi || | | 101416b585feSTom Zanussi || | | +-----------------------+ 101516b585feSTom Zanussi +|------------------|-|>| var_ref = $ts0 | 101616b585feSTom Zanussi | | | +-----------------------+ 101716b585feSTom Zanussi | | | | .size | 101816b585feSTom Zanussi | | | +---------------------+ 101916b585feSTom Zanussi | | | | .offset | 102016b585feSTom Zanussi | | | +---------------------+ 102116b585feSTom Zanussi | | | | .fn() | 102216b585feSTom Zanussi | | | +---------------------+ 102316b585feSTom Zanussi | | | | .flags & FL_VAR_REF | 102416b585feSTom Zanussi | | | +---------------------+ 102516b585feSTom Zanussi | | +---| .var_ref_idx | 102616b585feSTom Zanussi | | +-----------------------+ 102716b585feSTom Zanussi | | | var_ref = $next_pid | 102816b585feSTom Zanussi | | +-----------------------+ 102916b585feSTom Zanussi | | | .size | 103016b585feSTom Zanussi | | +---------------------+ 103116b585feSTom Zanussi | | | .offset | 103216b585feSTom Zanussi | | +---------------------+ 103316b585feSTom Zanussi | | | .fn() | 103416b585feSTom Zanussi | | +---------------------+ 103516b585feSTom Zanussi | | | .flags & FL_VAR_REF | 103616b585feSTom Zanussi | | +---------------------+ 103716b585feSTom Zanussi | +-----| .var_ref_idx | 103816b585feSTom Zanussi | +-----------------------+ 103916b585feSTom Zanussi | | var_ref = $wakeup_lat | 104016b585feSTom Zanussi | +-----------------------+ 104116b585feSTom Zanussi | | .size | 104216b585feSTom Zanussi | +---------------------+ 104316b585feSTom Zanussi | | .offset | 104416b585feSTom Zanussi | +---------------------+ 104516b585feSTom Zanussi | | .fn() | 104616b585feSTom Zanussi | +---------------------+ 104716b585feSTom Zanussi | | .flags & FL_VAR_REF | 104816b585feSTom Zanussi | +---------------------+ 104916b585feSTom Zanussi +------------------------| .var_ref_idx | 105016b585feSTom Zanussi +---------------------+ 105116b585feSTom Zanussi 105216b585feSTom ZanussiAs you can see, for a field variable, two hist_fields are created: one 105316b585feSTom Zanussirepresenting the variable, in this case next_pid, and one to actually 105416b585feSTom Zanussiget the value of the field from the trace stream, like a normal val 105516b585feSTom Zanussifield does. These are created separately from normal variable 105616b585feSTom Zanussicreation and are saved in the hist_data->field_vars[] array. See 105716b585feSTom Zanussibelow for how these are used. In addition, a reference hist_field is 105816b585feSTom Zanussialso created, which is needed to reference the field variables such as 105916b585feSTom Zanussi$next_pid variable in the trace() action. 106016b585feSTom Zanussi 106116b585feSTom ZanussiNote that $wakeup_lat is also a variable reference, referencing the 106216b585feSTom Zanussivalue of the expression common_timestamp-$ts0, and so also needs to 106316b585feSTom Zanussihave a hist field entry representing that reference created. 106416b585feSTom Zanussi 106516b585feSTom ZanussiWhen hist_trigger_elt_update() is called to get the normal key and 106616b585feSTom Zanussivalue fields, it also calls update_field_vars(), which goes through 106716b585feSTom Zanussieach field_var created for the histogram, and available from 106816b585feSTom Zanussihist_data->field_vars and calls val->fn() to get the data from the 106916b585feSTom Zanussicurrent trace record, and then uses the var's var.idx to set the 107016b585feSTom Zanussivariable at the var.idx offset in the appropriate tracing_map_elt's 107116b585feSTom Zanussivariable at elt->vars[var.idx]. 107216b585feSTom Zanussi 107316b585feSTom ZanussiOnce all the variables have been updated, resolve_var_refs() can be 107416b585feSTom Zanussicalled from event_hist_trigger(), and not only can our $ts0 and 107516b585feSTom Zanussi$next_pid references be resolved but the $wakeup_lat reference as 107616b585feSTom Zanussiwell. At this point, the trace() action can simply access the values 107716b585feSTom Zanussiassembled in the var_ref_vals[] array and generate the trace event. 107816b585feSTom Zanussi 107916b585feSTom ZanussiThe same process occurs for the field variables associated with the 108016b585feSTom Zanussisave() action. 108116b585feSTom Zanussi 108216b585feSTom ZanussiAbbreviations used in the diagram:: 108316b585feSTom Zanussi 108416b585feSTom Zanussi hist_data = struct hist_trigger_data 108516b585feSTom Zanussi hist_data.fields = struct hist_field 108616b585feSTom Zanussi field_var = struct field_var 108716b585feSTom Zanussi fn = hist_field_fn_t 108816b585feSTom Zanussi FL_KEY = HIST_FIELD_FL_KEY 108916b585feSTom Zanussi FL_VAR = HIST_FIELD_FL_VAR 109016b585feSTom Zanussi FL_VAR_REF = HIST_FIELD_FL_VAR_REF 109116b585feSTom Zanussi 109216b585feSTom Zanussitrace() action field variable test 109316b585feSTom Zanussi---------------------------------- 109416b585feSTom Zanussi 109516b585feSTom ZanussiThis example adds to the previous test example by finally making use 109616b585feSTom Zanussiof the wakeup_lat variable, but in addition also creates a couple of 109716b585feSTom Zanussifield variables that then are all passed to the wakeup_latency() trace 109816b585feSTom Zanussiaction via the onmatch() handler. 109916b585feSTom Zanussi 110016b585feSTom ZanussiFirst, we create the wakeup_latency synthetic event:: 110116b585feSTom Zanussi 110216b585feSTom Zanussi # echo 'wakeup_latency u64 lat; pid_t pid; char comm[16]' >> synthetic_events 110316b585feSTom Zanussi 110416b585feSTom ZanussiNext, the sched_waking trigger from previous examples:: 110516b585feSTom Zanussi 110616b585feSTom Zanussi # echo 'hist:keys=pid:ts0=common_timestamp.usecs' >> events/sched/sched_waking/trigger 110716b585feSTom Zanussi 110816b585feSTom ZanussiFinally, as in the previous test example, we calculate and assign the 110916b585feSTom Zanussiwakeup latency using the $ts0 reference from the sched_waking trigger 111016b585feSTom Zanussito the wakeup_lat variable, and finally use it along with a couple 111116b585feSTom Zanussisched_switch event fields, next_pid and next_comm, to generate a 111216b585feSTom Zanussiwakeup_latency trace event. The next_pid and next_comm event fields 111316b585feSTom Zanussiare automatically converted into field variables for this purpose:: 111416b585feSTom Zanussi 1115*2abfcd29SRoss Zwisler # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,next_pid,next_comm)' >> /sys/kernel/tracing/events/sched/sched_switch/trigger 111616b585feSTom Zanussi 111716b585feSTom ZanussiThe sched_waking hist_debug output shows the same data as in the 111816b585feSTom Zanussiprevious test example:: 111916b585feSTom Zanussi 112016b585feSTom Zanussi # cat events/sched/sched_waking/hist_debug 112116b585feSTom Zanussi 112216b585feSTom Zanussi # event histogram 112316b585feSTom Zanussi # 112416b585feSTom Zanussi # trigger info: hist:keys=pid:vals=hitcount:ts0=common_timestamp.usecs:sort=hitcount:size=2048:clock=global [active] 112516b585feSTom Zanussi # 112616b585feSTom Zanussi 112716b585feSTom Zanussi hist_data: 00000000d60ff61f 112816b585feSTom Zanussi 112916b585feSTom Zanussi n_vals: 2 113016b585feSTom Zanussi n_keys: 1 113116b585feSTom Zanussi n_fields: 3 113216b585feSTom Zanussi 113316b585feSTom Zanussi val fields: 113416b585feSTom Zanussi 113516b585feSTom Zanussi hist_data->fields[0]: 113616b585feSTom Zanussi flags: 113716b585feSTom Zanussi VAL: HIST_FIELD_FL_HITCOUNT 113816b585feSTom Zanussi type: u64 113916b585feSTom Zanussi size: 8 114016b585feSTom Zanussi is_signed: 0 114116b585feSTom Zanussi 114216b585feSTom Zanussi hist_data->fields[1]: 114316b585feSTom Zanussi flags: 114416b585feSTom Zanussi HIST_FIELD_FL_VAR 114516b585feSTom Zanussi var.name: ts0 114616b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 114716b585feSTom Zanussi type: u64 114816b585feSTom Zanussi size: 8 114916b585feSTom Zanussi is_signed: 0 115016b585feSTom Zanussi 115116b585feSTom Zanussi key fields: 115216b585feSTom Zanussi 115316b585feSTom Zanussi hist_data->fields[2]: 115416b585feSTom Zanussi flags: 115516b585feSTom Zanussi HIST_FIELD_FL_KEY 115616b585feSTom Zanussi ftrace_event_field name: pid 115716b585feSTom Zanussi type: pid_t 115816b585feSTom Zanussi size: 8 115916b585feSTom Zanussi is_signed: 1 116016b585feSTom Zanussi 116116b585feSTom ZanussiThe sched_switch hist_debug output shows the same key and value fields 116216b585feSTom Zanussias in the previous test example - note that wakeup_lat is still in the 116316b585feSTom Zanussival fields section, but that the new field variables are not there - 116416b585feSTom Zanussialthough the field variables are variables, they're held separately in 116516b585feSTom Zanussithe hist_data's field_vars[] array. Although the field variables and 116616b585feSTom Zanussithe normal variables are located in separate places, you can see that 116716b585feSTom Zanussithe actual variable locations for those variables in the 116816b585feSTom Zanussitracing_map_elt.vars[] do have increasing indices as expected: 116916b585feSTom Zanussiwakeup_lat takes the var.idx = 0 slot, while the field variables for 117016b585feSTom Zanussinext_pid and next_comm have values var.idx = 1, and var.idx = 2. Note 117116b585feSTom Zanussialso that those are the same values displayed for the variable 117216b585feSTom Zanussireferences corresponding to those variables in the variable reference 117316b585feSTom Zanussifields section. Since there are two triggers and thus two hist_data 117416b585feSTom Zanussiaddresses, those addresses also need to be accounted for when doing 117516b585feSTom Zanussithe matching - you can see that the first variable refers to the 0 117616b585feSTom Zanussivar.idx on the previous hist trigger (see the hist_data address 117716b585feSTom Zanussiassociated with that trigger), while the second variable refers to the 117816b585feSTom Zanussi0 var.idx on the sched_switch hist trigger, as do all the remaining 117916b585feSTom Zanussivariable references. 118016b585feSTom Zanussi 118116b585feSTom ZanussiFinally, the action tracking variables section just shows the system 118216b585feSTom Zanussiand event name for the onmatch() handler:: 118316b585feSTom Zanussi 118416b585feSTom Zanussi # cat events/sched/sched_switch/hist_debug 118516b585feSTom Zanussi 118616b585feSTom Zanussi # event histogram 118716b585feSTom Zanussi # 118816b585feSTom Zanussi # trigger info: hist:keys=next_pid:vals=hitcount:wakeup_lat=common_timestamp.usecs-$ts0:sort=hitcount:size=2048:clock=global:onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,next_pid,next_comm) [active] 118916b585feSTom Zanussi # 119016b585feSTom Zanussi 119116b585feSTom Zanussi hist_data: 0000000008f551b7 119216b585feSTom Zanussi 119316b585feSTom Zanussi n_vals: 2 119416b585feSTom Zanussi n_keys: 1 119516b585feSTom Zanussi n_fields: 3 119616b585feSTom Zanussi 119716b585feSTom Zanussi val fields: 119816b585feSTom Zanussi 119916b585feSTom Zanussi hist_data->fields[0]: 120016b585feSTom Zanussi flags: 120116b585feSTom Zanussi VAL: HIST_FIELD_FL_HITCOUNT 120216b585feSTom Zanussi type: u64 120316b585feSTom Zanussi size: 8 120416b585feSTom Zanussi is_signed: 0 120516b585feSTom Zanussi 120616b585feSTom Zanussi hist_data->fields[1]: 120716b585feSTom Zanussi flags: 120816b585feSTom Zanussi HIST_FIELD_FL_VAR 120916b585feSTom Zanussi var.name: wakeup_lat 121016b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 121116b585feSTom Zanussi type: u64 121216b585feSTom Zanussi size: 0 121316b585feSTom Zanussi is_signed: 0 121416b585feSTom Zanussi 121516b585feSTom Zanussi key fields: 121616b585feSTom Zanussi 121716b585feSTom Zanussi hist_data->fields[2]: 121816b585feSTom Zanussi flags: 121916b585feSTom Zanussi HIST_FIELD_FL_KEY 122016b585feSTom Zanussi ftrace_event_field name: next_pid 122116b585feSTom Zanussi type: pid_t 122216b585feSTom Zanussi size: 8 122316b585feSTom Zanussi is_signed: 1 122416b585feSTom Zanussi 122516b585feSTom Zanussi variable reference fields: 122616b585feSTom Zanussi 122716b585feSTom Zanussi hist_data->var_refs[0]: 122816b585feSTom Zanussi flags: 122916b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 123016b585feSTom Zanussi name: ts0 123116b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 123216b585feSTom Zanussi var.hist_data: 00000000d60ff61f 123316b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 0 123416b585feSTom Zanussi type: u64 123516b585feSTom Zanussi size: 8 123616b585feSTom Zanussi is_signed: 0 123716b585feSTom Zanussi 123816b585feSTom Zanussi hist_data->var_refs[1]: 123916b585feSTom Zanussi flags: 124016b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 124116b585feSTom Zanussi name: wakeup_lat 124216b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 124316b585feSTom Zanussi var.hist_data: 0000000008f551b7 124416b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 1 124516b585feSTom Zanussi type: u64 124616b585feSTom Zanussi size: 0 124716b585feSTom Zanussi is_signed: 0 124816b585feSTom Zanussi 124916b585feSTom Zanussi hist_data->var_refs[2]: 125016b585feSTom Zanussi flags: 125116b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 125216b585feSTom Zanussi name: next_pid 125316b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 1 125416b585feSTom Zanussi var.hist_data: 0000000008f551b7 125516b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 2 125616b585feSTom Zanussi type: pid_t 125716b585feSTom Zanussi size: 4 125816b585feSTom Zanussi is_signed: 0 125916b585feSTom Zanussi 126016b585feSTom Zanussi hist_data->var_refs[3]: 126116b585feSTom Zanussi flags: 126216b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 126316b585feSTom Zanussi name: next_comm 126416b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 2 126516b585feSTom Zanussi var.hist_data: 0000000008f551b7 126616b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 3 126716b585feSTom Zanussi type: char[16] 126816b585feSTom Zanussi size: 256 126916b585feSTom Zanussi is_signed: 0 127016b585feSTom Zanussi 127116b585feSTom Zanussi field variables: 127216b585feSTom Zanussi 127316b585feSTom Zanussi hist_data->field_vars[0]: 127416b585feSTom Zanussi 127516b585feSTom Zanussi field_vars[0].var: 127616b585feSTom Zanussi flags: 127716b585feSTom Zanussi HIST_FIELD_FL_VAR 127816b585feSTom Zanussi var.name: next_pid 127916b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 1 128016b585feSTom Zanussi 128116b585feSTom Zanussi field_vars[0].val: 128216b585feSTom Zanussi ftrace_event_field name: next_pid 128316b585feSTom Zanussi type: pid_t 128416b585feSTom Zanussi size: 4 128516b585feSTom Zanussi is_signed: 1 128616b585feSTom Zanussi 128716b585feSTom Zanussi hist_data->field_vars[1]: 128816b585feSTom Zanussi 128916b585feSTom Zanussi field_vars[1].var: 129016b585feSTom Zanussi flags: 129116b585feSTom Zanussi HIST_FIELD_FL_VAR 129216b585feSTom Zanussi var.name: next_comm 129316b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 2 129416b585feSTom Zanussi 129516b585feSTom Zanussi field_vars[1].val: 129616b585feSTom Zanussi ftrace_event_field name: next_comm 129716b585feSTom Zanussi type: char[16] 129816b585feSTom Zanussi size: 256 129916b585feSTom Zanussi is_signed: 0 130016b585feSTom Zanussi 130116b585feSTom Zanussi action tracking variables (for onmax()/onchange()/onmatch()): 130216b585feSTom Zanussi 130316b585feSTom Zanussi hist_data->actions[0].match_data.event_system: sched 130416b585feSTom Zanussi hist_data->actions[0].match_data.event: sched_waking 130516b585feSTom Zanussi 130616b585feSTom ZanussiThe commands below can be used to clean things up for the next test:: 130716b585feSTom Zanussi 1308*2abfcd29SRoss Zwisler # echo '!hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,next_pid,next_comm)' >> /sys/kernel/tracing/events/sched/sched_switch/trigger 130916b585feSTom Zanussi 131016b585feSTom Zanussi # echo '!hist:keys=pid:ts0=common_timestamp.usecs' >> events/sched/sched_waking/trigger 131116b585feSTom Zanussi 131216b585feSTom Zanussi # echo '!wakeup_latency u64 lat; pid_t pid; char comm[16]' >> synthetic_events 131316b585feSTom Zanussi 131416b585feSTom Zanussiaction_data and the trace() action 131516b585feSTom Zanussi---------------------------------- 131616b585feSTom Zanussi 131716b585feSTom ZanussiAs mentioned above, when the trace() action generates a synthetic 131816b585feSTom Zanussievent, all the parameters to the synthetic event either already are 131916b585feSTom Zanussivariables or are converted into variables (via field variables), and 132016b585feSTom Zanussifinally all those variable values are collected via references to them 132116b585feSTom Zanussiinto a var_ref_vals[] array. 132216b585feSTom Zanussi 132316b585feSTom ZanussiThe values in the var_ref_vals[] array, however, don't necessarily 132416b585feSTom Zanussifollow the same ordering as the synthetic event params. To address 132516b585feSTom Zanussithat, struct action_data contains another array, var_ref_idx[] that 132616b585feSTom Zanussimaps the trace action params to the var_ref_vals[] values. Below is a 132716b585feSTom Zanussidiagram illustrating that for the wakeup_latency() synthetic event:: 132816b585feSTom Zanussi 132916b585feSTom Zanussi +------------------+ wakeup_latency() 133016b585feSTom Zanussi | action_data | event params var_ref_vals[] 133116b585feSTom Zanussi +------------------+ +-----------------+ +-----------------+ 133216b585feSTom Zanussi | .var_ref_idx[] |--->| $wakeup_lat idx |---+ | | 133316b585feSTom Zanussi +----------------+ +-----------------+ | +-----------------+ 133416b585feSTom Zanussi | .synth_event | | $next_pid idx |---|-+ | $wakeup_lat val | 133516b585feSTom Zanussi +----------------+ +-----------------+ | | +-----------------+ 133616b585feSTom Zanussi . | +->| $next_pid val | 133716b585feSTom Zanussi . | +-----------------+ 133816b585feSTom Zanussi . | . 133916b585feSTom Zanussi +-----------------+ | . 134016b585feSTom Zanussi | | | . 134116b585feSTom Zanussi +-----------------+ | +-----------------+ 134216b585feSTom Zanussi +--->| $wakeup_lat val | 134316b585feSTom Zanussi +-----------------+ 134416b585feSTom Zanussi 134516b585feSTom ZanussiBasically, how this ends up getting used in the synthetic event probe 134616b585feSTom Zanussifunction, trace_event_raw_event_synth(), is as follows:: 134716b585feSTom Zanussi 134816b585feSTom Zanussi for each field i in .synth_event 134916b585feSTom Zanussi val_idx = .var_ref_idx[i] 135016b585feSTom Zanussi val = var_ref_vals[val_idx] 135116b585feSTom Zanussi 135216b585feSTom Zanussiaction_data and the onXXX() handlers 135316b585feSTom Zanussi------------------------------------ 135416b585feSTom Zanussi 135516b585feSTom ZanussiThe hist trigger onXXX() actions other than onmatch(), such as onmax() 135616b585feSTom Zanussiand onchange(), also make use of and internally create hidden 135716b585feSTom Zanussivariables. This information is contained in the 135816b585feSTom Zanussiaction_data.track_data struct, and is also visible in the hist_debug 135916b585feSTom Zanussioutput as will be described in the example below. 136016b585feSTom Zanussi 136116b585feSTom ZanussiTypically, the onmax() or onchange() handlers are used in conjunction 136216b585feSTom Zanussiwith the save() and snapshot() actions. For example:: 136316b585feSTom Zanussi 136416b585feSTom Zanussi # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0: \ 136516b585feSTom Zanussi onmax($wakeup_lat).save(next_comm,prev_pid,prev_prio,prev_comm)' >> 1366*2abfcd29SRoss Zwisler /sys/kernel/tracing/events/sched/sched_switch/trigger 136716b585feSTom Zanussi 136816b585feSTom Zanussior:: 136916b585feSTom Zanussi 137016b585feSTom Zanussi # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0: \ 137116b585feSTom Zanussi onmax($wakeup_lat).snapshot()' >> 1372*2abfcd29SRoss Zwisler /sys/kernel/tracing/events/sched/sched_switch/trigger 137316b585feSTom Zanussi 137416b585feSTom Zanussisave() action field variable test 137516b585feSTom Zanussi--------------------------------- 137616b585feSTom Zanussi 137716b585feSTom ZanussiFor this example, instead of generating a synthetic event, the save() 137816b585feSTom Zanussiaction is used to save field values whenever an onmax() handler 137916b585feSTom Zanussidetects that a new max latency has been hit. As in the previous 138016b585feSTom Zanussiexample, the values being saved are also field values, but in this 138116b585feSTom Zanussicase, are kept in a separate hist_data array named save_vars[]. 138216b585feSTom Zanussi 138316b585feSTom ZanussiAs in previous test examples, we set up the sched_waking trigger:: 138416b585feSTom Zanussi 138516b585feSTom Zanussi # echo 'hist:keys=pid:ts0=common_timestamp.usecs' >> events/sched/sched_waking/trigger 138616b585feSTom Zanussi 138716b585feSTom ZanussiIn this case, however, we set up the sched_switch trigger to save some 138816b585feSTom Zanussisched_switch field values whenever we hit a new maximum latency. For 138916b585feSTom Zanussiboth the onmax() handler and save() action, variables will be created, 139016b585feSTom Zanussiwhich we can use the hist_debug files to examine:: 139116b585feSTom Zanussi 139216b585feSTom Zanussi # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0:onmax($wakeup_lat).save(next_comm,prev_pid,prev_prio,prev_comm)' >> events/sched/sched_switch/trigger 139316b585feSTom Zanussi 139416b585feSTom ZanussiThe sched_waking hist_debug output shows the same data as in the 139516b585feSTom Zanussiprevious test examples:: 139616b585feSTom Zanussi 139716b585feSTom Zanussi # cat events/sched/sched_waking/hist_debug 139816b585feSTom Zanussi 139916b585feSTom Zanussi # 140016b585feSTom Zanussi # trigger info: hist:keys=pid:vals=hitcount:ts0=common_timestamp.usecs:sort=hitcount:size=2048:clock=global [active] 140116b585feSTom Zanussi # 140216b585feSTom Zanussi 140316b585feSTom Zanussi hist_data: 00000000e6290f48 140416b585feSTom Zanussi 140516b585feSTom Zanussi n_vals: 2 140616b585feSTom Zanussi n_keys: 1 140716b585feSTom Zanussi n_fields: 3 140816b585feSTom Zanussi 140916b585feSTom Zanussi val fields: 141016b585feSTom Zanussi 141116b585feSTom Zanussi hist_data->fields[0]: 141216b585feSTom Zanussi flags: 141316b585feSTom Zanussi VAL: HIST_FIELD_FL_HITCOUNT 141416b585feSTom Zanussi type: u64 141516b585feSTom Zanussi size: 8 141616b585feSTom Zanussi is_signed: 0 141716b585feSTom Zanussi 141816b585feSTom Zanussi hist_data->fields[1]: 141916b585feSTom Zanussi flags: 142016b585feSTom Zanussi HIST_FIELD_FL_VAR 142116b585feSTom Zanussi var.name: ts0 142216b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 142316b585feSTom Zanussi type: u64 142416b585feSTom Zanussi size: 8 142516b585feSTom Zanussi is_signed: 0 142616b585feSTom Zanussi 142716b585feSTom Zanussi key fields: 142816b585feSTom Zanussi 142916b585feSTom Zanussi hist_data->fields[2]: 143016b585feSTom Zanussi flags: 143116b585feSTom Zanussi HIST_FIELD_FL_KEY 143216b585feSTom Zanussi ftrace_event_field name: pid 143316b585feSTom Zanussi type: pid_t 143416b585feSTom Zanussi size: 8 143516b585feSTom Zanussi is_signed: 1 143616b585feSTom Zanussi 143716b585feSTom ZanussiThe output of the sched_switch trigger shows the same val and key 143816b585feSTom Zanussivalues as before, but also shows a couple new sections. 143916b585feSTom Zanussi 144016b585feSTom ZanussiFirst, the action tracking variables section now shows the 144116b585feSTom Zanussiactions[].track_data information describing the special tracking 144216b585feSTom Zanussivariables and references used to track, in this case, the running 144316b585feSTom Zanussimaximum value. The actions[].track_data.var_ref member contains the 144416b585feSTom Zanussireference to the variable being tracked, in this case the $wakeup_lat 144516b585feSTom Zanussivariable. In order to perform the onmax() handler function, there 144616b585feSTom Zanussialso needs to be a variable that tracks the current maximum by getting 144716b585feSTom Zanussiupdated whenever a new maximum is hit. In this case, we can see that 144809068445SSteven Rostedt (VMware)an auto-generated variable named ' __max' has been created and is 144916b585feSTom Zanussivisible in the actions[].track_data.track_var variable. 145016b585feSTom Zanussi 145116b585feSTom ZanussiFinally, in the new 'save action variables' section, we can see that 145216b585feSTom Zanussithe 4 params to the save() function have resulted in 4 field variables 145316b585feSTom Zanussibeing created for the purposes of saving the values of the named 145416b585feSTom Zanussifields when the max is hit. These variables are kept in a separate 145516b585feSTom Zanussisave_vars[] array off of hist_data, so are displayed in a separate 145616b585feSTom Zanussisection:: 145716b585feSTom Zanussi 145816b585feSTom Zanussi # cat events/sched/sched_switch/hist_debug 145916b585feSTom Zanussi 146016b585feSTom Zanussi # event histogram 146116b585feSTom Zanussi # 146216b585feSTom Zanussi # trigger info: hist:keys=next_pid:vals=hitcount:wakeup_lat=common_timestamp.usecs-$ts0:sort=hitcount:size=2048:clock=global:onmax($wakeup_lat).save(next_comm,prev_pid,prev_prio,prev_comm) [active] 146316b585feSTom Zanussi # 146416b585feSTom Zanussi 146516b585feSTom Zanussi hist_data: 0000000057bcd28d 146616b585feSTom Zanussi 146716b585feSTom Zanussi n_vals: 2 146816b585feSTom Zanussi n_keys: 1 146916b585feSTom Zanussi n_fields: 3 147016b585feSTom Zanussi 147116b585feSTom Zanussi val fields: 147216b585feSTom Zanussi 147316b585feSTom Zanussi hist_data->fields[0]: 147416b585feSTom Zanussi flags: 147516b585feSTom Zanussi VAL: HIST_FIELD_FL_HITCOUNT 147616b585feSTom Zanussi type: u64 147716b585feSTom Zanussi size: 8 147816b585feSTom Zanussi is_signed: 0 147916b585feSTom Zanussi 148016b585feSTom Zanussi hist_data->fields[1]: 148116b585feSTom Zanussi flags: 148216b585feSTom Zanussi HIST_FIELD_FL_VAR 148316b585feSTom Zanussi var.name: wakeup_lat 148416b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 148516b585feSTom Zanussi type: u64 148616b585feSTom Zanussi size: 0 148716b585feSTom Zanussi is_signed: 0 148816b585feSTom Zanussi 148916b585feSTom Zanussi key fields: 149016b585feSTom Zanussi 149116b585feSTom Zanussi hist_data->fields[2]: 149216b585feSTom Zanussi flags: 149316b585feSTom Zanussi HIST_FIELD_FL_KEY 149416b585feSTom Zanussi ftrace_event_field name: next_pid 149516b585feSTom Zanussi type: pid_t 149616b585feSTom Zanussi size: 8 149716b585feSTom Zanussi is_signed: 1 149816b585feSTom Zanussi 149916b585feSTom Zanussi variable reference fields: 150016b585feSTom Zanussi 150116b585feSTom Zanussi hist_data->var_refs[0]: 150216b585feSTom Zanussi flags: 150316b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 150416b585feSTom Zanussi name: ts0 150516b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 150616b585feSTom Zanussi var.hist_data: 00000000e6290f48 150716b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 0 150816b585feSTom Zanussi type: u64 150916b585feSTom Zanussi size: 8 151016b585feSTom Zanussi is_signed: 0 151116b585feSTom Zanussi 151216b585feSTom Zanussi hist_data->var_refs[1]: 151316b585feSTom Zanussi flags: 151416b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 151516b585feSTom Zanussi name: wakeup_lat 151616b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 151716b585feSTom Zanussi var.hist_data: 0000000057bcd28d 151816b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 1 151916b585feSTom Zanussi type: u64 152016b585feSTom Zanussi size: 0 152116b585feSTom Zanussi is_signed: 0 152216b585feSTom Zanussi 152316b585feSTom Zanussi action tracking variables (for onmax()/onchange()/onmatch()): 152416b585feSTom Zanussi 152516b585feSTom Zanussi hist_data->actions[0].track_data.var_ref: 152616b585feSTom Zanussi flags: 152716b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 152816b585feSTom Zanussi name: wakeup_lat 152916b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 153016b585feSTom Zanussi var.hist_data: 0000000057bcd28d 153116b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 1 153216b585feSTom Zanussi type: u64 153316b585feSTom Zanussi size: 0 153416b585feSTom Zanussi is_signed: 0 153516b585feSTom Zanussi 153616b585feSTom Zanussi hist_data->actions[0].track_data.track_var: 153716b585feSTom Zanussi flags: 153816b585feSTom Zanussi HIST_FIELD_FL_VAR 153916b585feSTom Zanussi var.name: __max 154016b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 1 154116b585feSTom Zanussi type: u64 154216b585feSTom Zanussi size: 8 154316b585feSTom Zanussi is_signed: 0 154416b585feSTom Zanussi 154516b585feSTom Zanussi save action variables (save() params): 154616b585feSTom Zanussi 154716b585feSTom Zanussi hist_data->save_vars[0]: 154816b585feSTom Zanussi 154916b585feSTom Zanussi save_vars[0].var: 155016b585feSTom Zanussi flags: 155116b585feSTom Zanussi HIST_FIELD_FL_VAR 155216b585feSTom Zanussi var.name: next_comm 155316b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 2 155416b585feSTom Zanussi 155516b585feSTom Zanussi save_vars[0].val: 155616b585feSTom Zanussi ftrace_event_field name: next_comm 155716b585feSTom Zanussi type: char[16] 155816b585feSTom Zanussi size: 256 155916b585feSTom Zanussi is_signed: 0 156016b585feSTom Zanussi 156116b585feSTom Zanussi hist_data->save_vars[1]: 156216b585feSTom Zanussi 156316b585feSTom Zanussi save_vars[1].var: 156416b585feSTom Zanussi flags: 156516b585feSTom Zanussi HIST_FIELD_FL_VAR 156616b585feSTom Zanussi var.name: prev_pid 156716b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 3 156816b585feSTom Zanussi 156916b585feSTom Zanussi save_vars[1].val: 157016b585feSTom Zanussi ftrace_event_field name: prev_pid 157116b585feSTom Zanussi type: pid_t 157216b585feSTom Zanussi size: 4 157316b585feSTom Zanussi is_signed: 1 157416b585feSTom Zanussi 157516b585feSTom Zanussi hist_data->save_vars[2]: 157616b585feSTom Zanussi 157716b585feSTom Zanussi save_vars[2].var: 157816b585feSTom Zanussi flags: 157916b585feSTom Zanussi HIST_FIELD_FL_VAR 158016b585feSTom Zanussi var.name: prev_prio 158116b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 4 158216b585feSTom Zanussi 158316b585feSTom Zanussi save_vars[2].val: 158416b585feSTom Zanussi ftrace_event_field name: prev_prio 158516b585feSTom Zanussi type: int 158616b585feSTom Zanussi size: 4 158716b585feSTom Zanussi is_signed: 1 158816b585feSTom Zanussi 158916b585feSTom Zanussi hist_data->save_vars[3]: 159016b585feSTom Zanussi 159116b585feSTom Zanussi save_vars[3].var: 159216b585feSTom Zanussi flags: 159316b585feSTom Zanussi HIST_FIELD_FL_VAR 159416b585feSTom Zanussi var.name: prev_comm 159516b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 5 159616b585feSTom Zanussi 159716b585feSTom Zanussi save_vars[3].val: 159816b585feSTom Zanussi ftrace_event_field name: prev_comm 159916b585feSTom Zanussi type: char[16] 160016b585feSTom Zanussi size: 256 160116b585feSTom Zanussi is_signed: 0 160216b585feSTom Zanussi 160316b585feSTom ZanussiThe commands below can be used to clean things up for the next test:: 160416b585feSTom Zanussi 160516b585feSTom Zanussi # echo '!hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0:onmax($wakeup_lat).save(next_comm,prev_pid,prev_prio,prev_comm)' >> events/sched/sched_switch/trigger 160616b585feSTom Zanussi 160716b585feSTom Zanussi # echo '!hist:keys=pid:ts0=common_timestamp.usecs' >> events/sched/sched_waking/trigger 160816b585feSTom Zanussi 160916b585feSTom ZanussiA couple special cases 161016b585feSTom Zanussi====================== 161116b585feSTom Zanussi 161216b585feSTom ZanussiWhile the above covers the basics of the histogram internals, there 161316b585feSTom Zanussiare a couple of special cases that should be discussed, since they 161409068445SSteven Rostedt (VMware)tend to create even more confusion. Those are field variables on other 161516b585feSTom Zanussihistograms, and aliases, both described below through example tests 161616b585feSTom Zanussiusing the hist_debug files. 161716b585feSTom Zanussi 161816b585feSTom ZanussiTest of field variables on other histograms 161916b585feSTom Zanussi------------------------------------------- 162016b585feSTom Zanussi 162116b585feSTom ZanussiThis example is similar to the previous examples, but in this case, 162216b585feSTom Zanussithe sched_switch trigger references a hist trigger field on another 162316b585feSTom Zanussievent, namely the sched_waking event. In order to accomplish this, a 162416b585feSTom Zanussifield variable is created for the other event, but since an existing 162516b585feSTom Zanussihistogram can't be used, as existing histograms are immutable, a new 162616b585feSTom Zanussihistogram with a matching variable is created and used, and we'll see 162716b585feSTom Zanussithat reflected in the hist_debug output shown below. 162816b585feSTom Zanussi 162916b585feSTom ZanussiFirst, we create the wakeup_latency synthetic event. Note the 163016b585feSTom Zanussiaddition of the prio field:: 163116b585feSTom Zanussi 163216b585feSTom Zanussi # echo 'wakeup_latency u64 lat; pid_t pid; int prio' >> synthetic_events 163316b585feSTom Zanussi 163416b585feSTom ZanussiAs in previous test examples, we set up the sched_waking trigger:: 163516b585feSTom Zanussi 163616b585feSTom Zanussi # echo 'hist:keys=pid:ts0=common_timestamp.usecs' >> events/sched/sched_waking/trigger 163716b585feSTom Zanussi 163816b585feSTom ZanussiHere we set up a hist trigger on sched_switch to send a wakeup_latency 163916b585feSTom Zanussievent using an onmatch handler naming the sched_waking event. Note 164016b585feSTom Zanussithat the third param being passed to the wakeup_latency() is prio, 164116b585feSTom Zanussiwhich is a field name that needs to have a field variable created for 164216b585feSTom Zanussiit. There isn't however any prio field on the sched_switch event so 164316b585feSTom Zanussiit would seem that it wouldn't be possible to create a field variable 164416b585feSTom Zanussifor it. The matching sched_waking event does have a prio field, so it 164516b585feSTom Zanussishould be possible to make use of it for this purpose. The problem 164616b585feSTom Zanussiwith that is that it's not currently possible to define a new variable 164716b585feSTom Zanussion an existing histogram, so it's not possible to add a new prio field 164816b585feSTom Zanussivariable to the existing sched_waking histogram. It is however 164916b585feSTom Zanussipossible to create an additional new 'matching' sched_waking histogram 165016b585feSTom Zanussifor the same event, meaning that it uses the same key and filters, and 165116b585feSTom Zanussidefine the new prio field variable on that. 165216b585feSTom Zanussi 165316b585feSTom ZanussiHere's the sched_switch trigger:: 165416b585feSTom Zanussi 165516b585feSTom Zanussi # echo 'hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,next_pid,prio)' >> events/sched/sched_switch/trigger 165616b585feSTom Zanussi 165716b585feSTom ZanussiAnd here's the output of the hist_debug information for the 165816b585feSTom Zanussisched_waking hist trigger. Note that there are two histograms 165916b585feSTom Zanussidisplayed in the output: the first is the normal sched_waking 166016b585feSTom Zanussihistogram we've seen in the previous examples, and the second is the 166116b585feSTom Zanussispecial histogram we created to provide the prio field variable. 166216b585feSTom Zanussi 166316b585feSTom ZanussiLooking at the second histogram below, we see a variable with the name 166416b585feSTom Zanussisynthetic_prio. This is the field variable created for the prio field 166516b585feSTom Zanussion that sched_waking histogram:: 166616b585feSTom Zanussi 166716b585feSTom Zanussi # cat events/sched/sched_waking/hist_debug 166816b585feSTom Zanussi 166916b585feSTom Zanussi # event histogram 167016b585feSTom Zanussi # 167116b585feSTom Zanussi # trigger info: hist:keys=pid:vals=hitcount:ts0=common_timestamp.usecs:sort=hitcount:size=2048:clock=global [active] 167216b585feSTom Zanussi # 167316b585feSTom Zanussi 167416b585feSTom Zanussi hist_data: 00000000349570e4 167516b585feSTom Zanussi 167616b585feSTom Zanussi n_vals: 2 167716b585feSTom Zanussi n_keys: 1 167816b585feSTom Zanussi n_fields: 3 167916b585feSTom Zanussi 168016b585feSTom Zanussi val fields: 168116b585feSTom Zanussi 168216b585feSTom Zanussi hist_data->fields[0]: 168316b585feSTom Zanussi flags: 168416b585feSTom Zanussi VAL: HIST_FIELD_FL_HITCOUNT 168516b585feSTom Zanussi type: u64 168616b585feSTom Zanussi size: 8 168716b585feSTom Zanussi is_signed: 0 168816b585feSTom Zanussi 168916b585feSTom Zanussi hist_data->fields[1]: 169016b585feSTom Zanussi flags: 169116b585feSTom Zanussi HIST_FIELD_FL_VAR 169216b585feSTom Zanussi var.name: ts0 169316b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 169416b585feSTom Zanussi type: u64 169516b585feSTom Zanussi size: 8 169616b585feSTom Zanussi is_signed: 0 169716b585feSTom Zanussi 169816b585feSTom Zanussi key fields: 169916b585feSTom Zanussi 170016b585feSTom Zanussi hist_data->fields[2]: 170116b585feSTom Zanussi flags: 170216b585feSTom Zanussi HIST_FIELD_FL_KEY 170316b585feSTom Zanussi ftrace_event_field name: pid 170416b585feSTom Zanussi type: pid_t 170516b585feSTom Zanussi size: 8 170616b585feSTom Zanussi is_signed: 1 170716b585feSTom Zanussi 170816b585feSTom Zanussi 170916b585feSTom Zanussi # event histogram 171016b585feSTom Zanussi # 171116b585feSTom Zanussi # trigger info: hist:keys=pid:vals=hitcount:synthetic_prio=prio:sort=hitcount:size=2048 [active] 171216b585feSTom Zanussi # 171316b585feSTom Zanussi 171416b585feSTom Zanussi hist_data: 000000006920cf38 171516b585feSTom Zanussi 171616b585feSTom Zanussi n_vals: 2 171716b585feSTom Zanussi n_keys: 1 171816b585feSTom Zanussi n_fields: 3 171916b585feSTom Zanussi 172016b585feSTom Zanussi val fields: 172116b585feSTom Zanussi 172216b585feSTom Zanussi hist_data->fields[0]: 172316b585feSTom Zanussi flags: 172416b585feSTom Zanussi VAL: HIST_FIELD_FL_HITCOUNT 172516b585feSTom Zanussi type: u64 172616b585feSTom Zanussi size: 8 172716b585feSTom Zanussi is_signed: 0 172816b585feSTom Zanussi 172916b585feSTom Zanussi hist_data->fields[1]: 173016b585feSTom Zanussi flags: 173116b585feSTom Zanussi HIST_FIELD_FL_VAR 173216b585feSTom Zanussi ftrace_event_field name: prio 173316b585feSTom Zanussi var.name: synthetic_prio 173416b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 173516b585feSTom Zanussi type: int 173616b585feSTom Zanussi size: 4 173716b585feSTom Zanussi is_signed: 1 173816b585feSTom Zanussi 173916b585feSTom Zanussi key fields: 174016b585feSTom Zanussi 174116b585feSTom Zanussi hist_data->fields[2]: 174216b585feSTom Zanussi flags: 174316b585feSTom Zanussi HIST_FIELD_FL_KEY 174416b585feSTom Zanussi ftrace_event_field name: pid 174516b585feSTom Zanussi type: pid_t 174616b585feSTom Zanussi size: 8 174716b585feSTom Zanussi is_signed: 1 174816b585feSTom Zanussi 174916b585feSTom ZanussiLooking at the sched_switch histogram below, we can see a reference to 175016b585feSTom Zanussithe synthetic_prio variable on sched_waking, and looking at the 175116b585feSTom Zanussiassociated hist_data address we see that it is indeed associated with 175216b585feSTom Zanussithe new histogram. Note also that the other references are to a 175316b585feSTom Zanussinormal variable, wakeup_lat, and to a normal field variable, next_pid, 175416b585feSTom Zanussithe details of which are in the field variables section:: 175516b585feSTom Zanussi 175616b585feSTom Zanussi # cat events/sched/sched_switch/hist_debug 175716b585feSTom Zanussi 175816b585feSTom Zanussi # event histogram 175916b585feSTom Zanussi # 176016b585feSTom Zanussi # trigger info: hist:keys=next_pid:vals=hitcount:wakeup_lat=common_timestamp.usecs-$ts0:sort=hitcount:size=2048:clock=global:onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,next_pid,prio) [active] 176116b585feSTom Zanussi # 176216b585feSTom Zanussi 176316b585feSTom Zanussi hist_data: 00000000a73b67df 176416b585feSTom Zanussi 176516b585feSTom Zanussi n_vals: 2 176616b585feSTom Zanussi n_keys: 1 176716b585feSTom Zanussi n_fields: 3 176816b585feSTom Zanussi 176916b585feSTom Zanussi val fields: 177016b585feSTom Zanussi 177116b585feSTom Zanussi hist_data->fields[0]: 177216b585feSTom Zanussi flags: 177316b585feSTom Zanussi VAL: HIST_FIELD_FL_HITCOUNT 177416b585feSTom Zanussi type: u64 177516b585feSTom Zanussi size: 8 177616b585feSTom Zanussi is_signed: 0 177716b585feSTom Zanussi 177816b585feSTom Zanussi hist_data->fields[1]: 177916b585feSTom Zanussi flags: 178016b585feSTom Zanussi HIST_FIELD_FL_VAR 178116b585feSTom Zanussi var.name: wakeup_lat 178216b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 178316b585feSTom Zanussi type: u64 178416b585feSTom Zanussi size: 0 178516b585feSTom Zanussi is_signed: 0 178616b585feSTom Zanussi 178716b585feSTom Zanussi key fields: 178816b585feSTom Zanussi 178916b585feSTom Zanussi hist_data->fields[2]: 179016b585feSTom Zanussi flags: 179116b585feSTom Zanussi HIST_FIELD_FL_KEY 179216b585feSTom Zanussi ftrace_event_field name: next_pid 179316b585feSTom Zanussi type: pid_t 179416b585feSTom Zanussi size: 8 179516b585feSTom Zanussi is_signed: 1 179616b585feSTom Zanussi 179716b585feSTom Zanussi variable reference fields: 179816b585feSTom Zanussi 179916b585feSTom Zanussi hist_data->var_refs[0]: 180016b585feSTom Zanussi flags: 180116b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 180216b585feSTom Zanussi name: ts0 180316b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 180416b585feSTom Zanussi var.hist_data: 00000000349570e4 180516b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 0 180616b585feSTom Zanussi type: u64 180716b585feSTom Zanussi size: 8 180816b585feSTom Zanussi is_signed: 0 180916b585feSTom Zanussi 181016b585feSTom Zanussi hist_data->var_refs[1]: 181116b585feSTom Zanussi flags: 181216b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 181316b585feSTom Zanussi name: wakeup_lat 181416b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 181516b585feSTom Zanussi var.hist_data: 00000000a73b67df 181616b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 1 181716b585feSTom Zanussi type: u64 181816b585feSTom Zanussi size: 0 181916b585feSTom Zanussi is_signed: 0 182016b585feSTom Zanussi 182116b585feSTom Zanussi hist_data->var_refs[2]: 182216b585feSTom Zanussi flags: 182316b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 182416b585feSTom Zanussi name: next_pid 182516b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 1 182616b585feSTom Zanussi var.hist_data: 00000000a73b67df 182716b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 2 182816b585feSTom Zanussi type: pid_t 182916b585feSTom Zanussi size: 4 183016b585feSTom Zanussi is_signed: 0 183116b585feSTom Zanussi 183216b585feSTom Zanussi hist_data->var_refs[3]: 183316b585feSTom Zanussi flags: 183416b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 183516b585feSTom Zanussi name: synthetic_prio 183616b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 183716b585feSTom Zanussi var.hist_data: 000000006920cf38 183816b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 3 183916b585feSTom Zanussi type: int 184016b585feSTom Zanussi size: 4 184116b585feSTom Zanussi is_signed: 1 184216b585feSTom Zanussi 184316b585feSTom Zanussi field variables: 184416b585feSTom Zanussi 184516b585feSTom Zanussi hist_data->field_vars[0]: 184616b585feSTom Zanussi 184716b585feSTom Zanussi field_vars[0].var: 184816b585feSTom Zanussi flags: 184916b585feSTom Zanussi HIST_FIELD_FL_VAR 185016b585feSTom Zanussi var.name: next_pid 185116b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 1 185216b585feSTom Zanussi 185316b585feSTom Zanussi field_vars[0].val: 185416b585feSTom Zanussi ftrace_event_field name: next_pid 185516b585feSTom Zanussi type: pid_t 185616b585feSTom Zanussi size: 4 185716b585feSTom Zanussi is_signed: 1 185816b585feSTom Zanussi 185916b585feSTom Zanussi action tracking variables (for onmax()/onchange()/onmatch()): 186016b585feSTom Zanussi 186116b585feSTom Zanussi hist_data->actions[0].match_data.event_system: sched 186216b585feSTom Zanussi hist_data->actions[0].match_data.event: sched_waking 186316b585feSTom Zanussi 186416b585feSTom ZanussiThe commands below can be used to clean things up for the next test:: 186516b585feSTom Zanussi 186616b585feSTom Zanussi # echo '!hist:keys=next_pid:wakeup_lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,next_pid,prio)' >> events/sched/sched_switch/trigger 186716b585feSTom Zanussi 186816b585feSTom Zanussi # echo '!hist:keys=pid:ts0=common_timestamp.usecs' >> events/sched/sched_waking/trigger 186916b585feSTom Zanussi 187016b585feSTom Zanussi # echo '!wakeup_latency u64 lat; pid_t pid; int prio' >> synthetic_events 187116b585feSTom Zanussi 187216b585feSTom ZanussiAlias test 187316b585feSTom Zanussi---------- 187416b585feSTom Zanussi 187516b585feSTom ZanussiThis example is very similar to previous examples, but demonstrates 187616b585feSTom Zanussithe alias flag. 187716b585feSTom Zanussi 187816b585feSTom ZanussiFirst, we create the wakeup_latency synthetic event:: 187916b585feSTom Zanussi 188016b585feSTom Zanussi # echo 'wakeup_latency u64 lat; pid_t pid; char comm[16]' >> synthetic_events 188116b585feSTom Zanussi 188216b585feSTom ZanussiNext, we create a sched_waking trigger similar to previous examples, 188316b585feSTom Zanussibut in this case we save the pid in the waking_pid variable:: 188416b585feSTom Zanussi 188516b585feSTom Zanussi # echo 'hist:keys=pid:waking_pid=pid:ts0=common_timestamp.usecs' >> events/sched/sched_waking/trigger 188616b585feSTom Zanussi 188716b585feSTom ZanussiFor the sched_switch trigger, instead of using $waking_pid directly in 188816b585feSTom Zanussithe wakeup_latency synthetic event invocation, we create an alias of 188916b585feSTom Zanussi$waking_pid named $woken_pid, and use that in the synthetic event 189016b585feSTom Zanussiinvocation instead:: 189116b585feSTom Zanussi 189216b585feSTom Zanussi # echo 'hist:keys=next_pid:woken_pid=$waking_pid:wakeup_lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,$woken_pid,next_comm)' >> events/sched/sched_switch/trigger 189316b585feSTom Zanussi 189416b585feSTom ZanussiLooking at the sched_waking hist_debug output, in addition to the 189516b585feSTom Zanussinormal fields, we can see the waking_pid variable:: 189616b585feSTom Zanussi 189716b585feSTom Zanussi # cat events/sched/sched_waking/hist_debug 189816b585feSTom Zanussi 189916b585feSTom Zanussi # event histogram 190016b585feSTom Zanussi # 190116b585feSTom Zanussi # trigger info: hist:keys=pid:vals=hitcount:waking_pid=pid,ts0=common_timestamp.usecs:sort=hitcount:size=2048:clock=global [active] 190216b585feSTom Zanussi # 190316b585feSTom Zanussi 190416b585feSTom Zanussi hist_data: 00000000a250528c 190516b585feSTom Zanussi 190616b585feSTom Zanussi n_vals: 3 190716b585feSTom Zanussi n_keys: 1 190816b585feSTom Zanussi n_fields: 4 190916b585feSTom Zanussi 191016b585feSTom Zanussi val fields: 191116b585feSTom Zanussi 191216b585feSTom Zanussi hist_data->fields[0]: 191316b585feSTom Zanussi flags: 191416b585feSTom Zanussi VAL: HIST_FIELD_FL_HITCOUNT 191516b585feSTom Zanussi type: u64 191616b585feSTom Zanussi size: 8 191716b585feSTom Zanussi is_signed: 0 191816b585feSTom Zanussi 191916b585feSTom Zanussi hist_data->fields[1]: 192016b585feSTom Zanussi flags: 192116b585feSTom Zanussi HIST_FIELD_FL_VAR 192216b585feSTom Zanussi ftrace_event_field name: pid 192316b585feSTom Zanussi var.name: waking_pid 192416b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 192516b585feSTom Zanussi type: pid_t 192616b585feSTom Zanussi size: 4 192716b585feSTom Zanussi is_signed: 1 192816b585feSTom Zanussi 192916b585feSTom Zanussi hist_data->fields[2]: 193016b585feSTom Zanussi flags: 193116b585feSTom Zanussi HIST_FIELD_FL_VAR 193216b585feSTom Zanussi var.name: ts0 193316b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 1 193416b585feSTom Zanussi type: u64 193516b585feSTom Zanussi size: 8 193616b585feSTom Zanussi is_signed: 0 193716b585feSTom Zanussi 193816b585feSTom Zanussi key fields: 193916b585feSTom Zanussi 194016b585feSTom Zanussi hist_data->fields[3]: 194116b585feSTom Zanussi flags: 194216b585feSTom Zanussi HIST_FIELD_FL_KEY 194316b585feSTom Zanussi ftrace_event_field name: pid 194416b585feSTom Zanussi type: pid_t 194516b585feSTom Zanussi size: 8 194616b585feSTom Zanussi is_signed: 1 194716b585feSTom Zanussi 194816b585feSTom ZanussiThe sched_switch hist_debug output shows that a variable named 194916b585feSTom Zanussiwoken_pid has been created but that it also has the 195016b585feSTom ZanussiHIST_FIELD_FL_ALIAS flag set. It also has the HIST_FIELD_FL_VAR flag 195116b585feSTom Zanussiset, which is why it appears in the val field section. 195216b585feSTom Zanussi 195316b585feSTom ZanussiDespite that implementation detail, an alias variable is actually more 195416b585feSTom Zanussilike a variable reference; in fact it can be thought of as a reference 195516b585feSTom Zanussito a reference. The implementation copies the var_ref->fn() from the 195616b585feSTom Zanussivariable reference being referenced, in this case, the waking_pid 195716b585feSTom Zanussifn(), which is hist_field_var_ref() and makes that the fn() of the 195816b585feSTom Zanussialias. The hist_field_var_ref() fn() requires the var_ref_idx of the 195916b585feSTom Zanussivariable reference it's using, so waking_pid's var_ref_idx is also 196016b585feSTom Zanussicopied to the alias. The end result is that when the value of alias 196116b585feSTom Zanussiis retrieved, in the end it just does the same thing the original 196216b585feSTom Zanussireference would have done and retrieves the same value from the 196316b585feSTom Zanussivar_ref_vals[] array. You can verify this in the output by noting 196416b585feSTom Zanussithat the var_ref_idx of the alias, in this case woken_pid, is the same 196516b585feSTom Zanussias the var_ref_idx of the reference, waking_pid, in the variable 196616b585feSTom Zanussireference fields section. 196716b585feSTom Zanussi 196816b585feSTom ZanussiAdditionally, once it gets that value, since it is also a variable, it 196916b585feSTom Zanussithen saves that value into its var.idx. So the var.idx of the 197016b585feSTom Zanussiwoken_pid alias is 0, which it fills with the value from var_ref_idx 0 197116b585feSTom Zanussiwhen its fn() is called to update itself. You'll also notice that 197216b585feSTom Zanussithere's a woken_pid var_ref in the variable refs section. That is the 197316b585feSTom Zanussireference to the woken_pid alias variable, and you can see that it 197416b585feSTom Zanussiretrieves the value from the same var.idx as the woken_pid alias, 0, 197516b585feSTom Zanussiand then in turn saves that value in its own var_ref_idx slot, 3, and 197616b585feSTom Zanussithe value at this position is finally what gets assigned to the 197716b585feSTom Zanussi$woken_pid slot in the trace event invocation:: 197816b585feSTom Zanussi 197916b585feSTom Zanussi # cat events/sched/sched_switch/hist_debug 198016b585feSTom Zanussi 198116b585feSTom Zanussi # event histogram 198216b585feSTom Zanussi # 198316b585feSTom Zanussi # trigger info: hist:keys=next_pid:vals=hitcount:woken_pid=$waking_pid,wakeup_lat=common_timestamp.usecs-$ts0:sort=hitcount:size=2048:clock=global:onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,$woken_pid,next_comm) [active] 198416b585feSTom Zanussi # 198516b585feSTom Zanussi 198616b585feSTom Zanussi hist_data: 0000000055d65ed0 198716b585feSTom Zanussi 198816b585feSTom Zanussi n_vals: 3 198916b585feSTom Zanussi n_keys: 1 199016b585feSTom Zanussi n_fields: 4 199116b585feSTom Zanussi 199216b585feSTom Zanussi val fields: 199316b585feSTom Zanussi 199416b585feSTom Zanussi hist_data->fields[0]: 199516b585feSTom Zanussi flags: 199616b585feSTom Zanussi VAL: HIST_FIELD_FL_HITCOUNT 199716b585feSTom Zanussi type: u64 199816b585feSTom Zanussi size: 8 199916b585feSTom Zanussi is_signed: 0 200016b585feSTom Zanussi 200116b585feSTom Zanussi hist_data->fields[1]: 200216b585feSTom Zanussi flags: 200316b585feSTom Zanussi HIST_FIELD_FL_VAR 200416b585feSTom Zanussi HIST_FIELD_FL_ALIAS 200516b585feSTom Zanussi var.name: woken_pid 200616b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 200716b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 0 200816b585feSTom Zanussi type: pid_t 200916b585feSTom Zanussi size: 4 201016b585feSTom Zanussi is_signed: 1 201116b585feSTom Zanussi 201216b585feSTom Zanussi hist_data->fields[2]: 201316b585feSTom Zanussi flags: 201416b585feSTom Zanussi HIST_FIELD_FL_VAR 201516b585feSTom Zanussi var.name: wakeup_lat 201616b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 1 201716b585feSTom Zanussi type: u64 201816b585feSTom Zanussi size: 0 201916b585feSTom Zanussi is_signed: 0 202016b585feSTom Zanussi 202116b585feSTom Zanussi key fields: 202216b585feSTom Zanussi 202316b585feSTom Zanussi hist_data->fields[3]: 202416b585feSTom Zanussi flags: 202516b585feSTom Zanussi HIST_FIELD_FL_KEY 202616b585feSTom Zanussi ftrace_event_field name: next_pid 202716b585feSTom Zanussi type: pid_t 202816b585feSTom Zanussi size: 8 202916b585feSTom Zanussi is_signed: 1 203016b585feSTom Zanussi 203116b585feSTom Zanussi variable reference fields: 203216b585feSTom Zanussi 203316b585feSTom Zanussi hist_data->var_refs[0]: 203416b585feSTom Zanussi flags: 203516b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 203616b585feSTom Zanussi name: waking_pid 203716b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 203816b585feSTom Zanussi var.hist_data: 00000000a250528c 203916b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 0 204016b585feSTom Zanussi type: pid_t 204116b585feSTom Zanussi size: 4 204216b585feSTom Zanussi is_signed: 1 204316b585feSTom Zanussi 204416b585feSTom Zanussi hist_data->var_refs[1]: 204516b585feSTom Zanussi flags: 204616b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 204716b585feSTom Zanussi name: ts0 204816b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 1 204916b585feSTom Zanussi var.hist_data: 00000000a250528c 205016b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 1 205116b585feSTom Zanussi type: u64 205216b585feSTom Zanussi size: 8 205316b585feSTom Zanussi is_signed: 0 205416b585feSTom Zanussi 205516b585feSTom Zanussi hist_data->var_refs[2]: 205616b585feSTom Zanussi flags: 205716b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 205816b585feSTom Zanussi name: wakeup_lat 205916b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 1 206016b585feSTom Zanussi var.hist_data: 0000000055d65ed0 206116b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 2 206216b585feSTom Zanussi type: u64 206316b585feSTom Zanussi size: 0 206416b585feSTom Zanussi is_signed: 0 206516b585feSTom Zanussi 206616b585feSTom Zanussi hist_data->var_refs[3]: 206716b585feSTom Zanussi flags: 206816b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 206916b585feSTom Zanussi name: woken_pid 207016b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 0 207116b585feSTom Zanussi var.hist_data: 0000000055d65ed0 207216b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 3 207316b585feSTom Zanussi type: pid_t 207416b585feSTom Zanussi size: 4 207516b585feSTom Zanussi is_signed: 1 207616b585feSTom Zanussi 207716b585feSTom Zanussi hist_data->var_refs[4]: 207816b585feSTom Zanussi flags: 207916b585feSTom Zanussi HIST_FIELD_FL_VAR_REF 208016b585feSTom Zanussi name: next_comm 208116b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 2 208216b585feSTom Zanussi var.hist_data: 0000000055d65ed0 208316b585feSTom Zanussi var_ref_idx (into hist_data->var_refs[]): 4 208416b585feSTom Zanussi type: char[16] 208516b585feSTom Zanussi size: 256 208616b585feSTom Zanussi is_signed: 0 208716b585feSTom Zanussi 208816b585feSTom Zanussi field variables: 208916b585feSTom Zanussi 209016b585feSTom Zanussi hist_data->field_vars[0]: 209116b585feSTom Zanussi 209216b585feSTom Zanussi field_vars[0].var: 209316b585feSTom Zanussi flags: 209416b585feSTom Zanussi HIST_FIELD_FL_VAR 209516b585feSTom Zanussi var.name: next_comm 209616b585feSTom Zanussi var.idx (into tracing_map_elt.vars[]): 2 209716b585feSTom Zanussi 209816b585feSTom Zanussi field_vars[0].val: 209916b585feSTom Zanussi ftrace_event_field name: next_comm 210016b585feSTom Zanussi type: char[16] 210116b585feSTom Zanussi size: 256 210216b585feSTom Zanussi is_signed: 0 210316b585feSTom Zanussi 210416b585feSTom Zanussi action tracking variables (for onmax()/onchange()/onmatch()): 210516b585feSTom Zanussi 210616b585feSTom Zanussi hist_data->actions[0].match_data.event_system: sched 210716b585feSTom Zanussi hist_data->actions[0].match_data.event: sched_waking 210816b585feSTom Zanussi 210916b585feSTom ZanussiThe commands below can be used to clean things up for the next test:: 211016b585feSTom Zanussi 211116b585feSTom Zanussi # echo '!hist:keys=next_pid:woken_pid=$waking_pid:wakeup_lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,$woken_pid,next_comm)' >> events/sched/sched_switch/trigger 211216b585feSTom Zanussi 211316b585feSTom Zanussi # echo '!hist:keys=pid:ts0=common_timestamp.usecs' >> events/sched/sched_waking/trigger 211416b585feSTom Zanussi 211516b585feSTom Zanussi # echo '!wakeup_latency u64 lat; pid_t pid; char comm[16]' >> synthetic_events 2116