Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * This file defines the trace event structures that go into the ring
0004  * buffer directly. They are created via macros so that changes for them
0005  * appear in the format file. Using macros will automate this process.
0006  *
0007  * The macro used to create a ftrace data structure is:
0008  *
0009  * FTRACE_ENTRY( name, struct_name, id, structure, print )
0010  *
0011  * @name: the name used the event name, as well as the name of
0012  *   the directory that holds the format file.
0013  *
0014  * @struct_name: the name of the structure that is created.
0015  *
0016  * @id: The event identifier that is used to detect what event
0017  *    this is from the ring buffer.
0018  *
0019  * @structure: the structure layout
0020  *
0021  *  - __field(  type,   item    )
0022  *    This is equivalent to declaring
0023  *      type    item;
0024  *    in the structure.
0025  *  - __array(  type,   item,   size    )
0026  *    This is equivalent to declaring
0027  *      type    item[size];
0028  *    in the structure.
0029  *
0030  *   * for structures within structures, the format of the internal
0031  *  structure is laid out. This allows the internal structure
0032  *  to be deciphered for the format file. Although these macros
0033  *  may become out of sync with the internal structure, they
0034  *  will create a compile error if it happens. Since the
0035  *  internal structures are just tracing helpers, this is not
0036  *  an issue.
0037  *
0038  *  When an internal structure is used, it should use:
0039  *
0040  *  __field_struct( type,   item    )
0041  *
0042  *  instead of __field. This will prevent it from being shown in
0043  *  the output file. The fields in the structure should use.
0044  *
0045  *  __field_desc(   type,   container,  item        )
0046  *  __array_desc(   type,   container,  item,   len )
0047  *
0048  *  type, item and len are the same as __field and __array, but
0049  *  container is added. This is the name of the item in
0050  *  __field_struct that this is describing.
0051  *
0052  *
0053  * @print: the print format shown to users in the format file.
0054  */
0055 
0056 /*
0057  * Function trace entry - function address and parent function address:
0058  */
0059 FTRACE_ENTRY_REG(function, ftrace_entry,
0060 
0061     TRACE_FN,
0062 
0063     F_STRUCT(
0064         __field_fn( unsigned long,  ip      )
0065         __field_fn( unsigned long,  parent_ip   )
0066     ),
0067 
0068     F_printk(" %ps <-- %ps",
0069          (void *)__entry->ip, (void *)__entry->parent_ip),
0070 
0071     perf_ftrace_event_register
0072 );
0073 
0074 /* Function call entry */
0075 FTRACE_ENTRY_PACKED(funcgraph_entry, ftrace_graph_ent_entry,
0076 
0077     TRACE_GRAPH_ENT,
0078 
0079     F_STRUCT(
0080         __field_struct( struct ftrace_graph_ent,    graph_ent   )
0081         __field_packed( unsigned long,  graph_ent,  func        )
0082         __field_packed( int,        graph_ent,  depth       )
0083     ),
0084 
0085     F_printk("--> %ps (%d)", (void *)__entry->func, __entry->depth)
0086 );
0087 
0088 /* Function return entry */
0089 FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry,
0090 
0091     TRACE_GRAPH_RET,
0092 
0093     F_STRUCT(
0094         __field_struct( struct ftrace_graph_ret,    ret )
0095         __field_packed( unsigned long,  ret,        func    )
0096         __field_packed( int,        ret,        depth   )
0097         __field_packed( unsigned int,   ret,        overrun )
0098         __field_packed( unsigned long long, ret,    calltime)
0099         __field_packed( unsigned long long, ret,    rettime )
0100     ),
0101 
0102     F_printk("<-- %ps (%d) (start: %llx  end: %llx) over: %d",
0103          (void *)__entry->func, __entry->depth,
0104          __entry->calltime, __entry->rettime,
0105          __entry->depth)
0106 );
0107 
0108 /*
0109  * Context switch trace entry - which task (and prio) we switched from/to:
0110  *
0111  * This is used for both wakeup and context switches. We only want
0112  * to create one structure, but we need two outputs for it.
0113  */
0114 #define FTRACE_CTX_FIELDS                   \
0115     __field(    unsigned int,   prev_pid    )   \
0116     __field(    unsigned int,   next_pid    )   \
0117     __field(    unsigned int,   next_cpu    )       \
0118     __field(    unsigned char,  prev_prio   )   \
0119     __field(    unsigned char,  prev_state  )   \
0120     __field(    unsigned char,  next_prio   )   \
0121     __field(    unsigned char,  next_state  )
0122 
0123 FTRACE_ENTRY(context_switch, ctx_switch_entry,
0124 
0125     TRACE_CTX,
0126 
0127     F_STRUCT(
0128         FTRACE_CTX_FIELDS
0129     ),
0130 
0131     F_printk("%u:%u:%u  ==> %u:%u:%u [%03u]",
0132          __entry->prev_pid, __entry->prev_prio, __entry->prev_state,
0133          __entry->next_pid, __entry->next_prio, __entry->next_state,
0134          __entry->next_cpu)
0135 );
0136 
0137 /*
0138  * FTRACE_ENTRY_DUP only creates the format file, it will not
0139  *  create another structure.
0140  */
0141 FTRACE_ENTRY_DUP(wakeup, ctx_switch_entry,
0142 
0143     TRACE_WAKE,
0144 
0145     F_STRUCT(
0146         FTRACE_CTX_FIELDS
0147     ),
0148 
0149     F_printk("%u:%u:%u  ==+ %u:%u:%u [%03u]",
0150          __entry->prev_pid, __entry->prev_prio, __entry->prev_state,
0151          __entry->next_pid, __entry->next_prio, __entry->next_state,
0152          __entry->next_cpu)
0153 );
0154 
0155 /*
0156  * Stack-trace entry:
0157  */
0158 
0159 #define FTRACE_STACK_ENTRIES    8
0160 
0161 FTRACE_ENTRY(kernel_stack, stack_entry,
0162 
0163     TRACE_STACK,
0164 
0165     F_STRUCT(
0166         __field(    int,        size    )
0167         __array(    unsigned long,  caller, FTRACE_STACK_ENTRIES    )
0168     ),
0169 
0170     F_printk("\t=> %ps\n\t=> %ps\n\t=> %ps\n"
0171          "\t=> %ps\n\t=> %ps\n\t=> %ps\n"
0172          "\t=> %ps\n\t=> %ps\n",
0173          (void *)__entry->caller[0], (void *)__entry->caller[1],
0174          (void *)__entry->caller[2], (void *)__entry->caller[3],
0175          (void *)__entry->caller[4], (void *)__entry->caller[5],
0176          (void *)__entry->caller[6], (void *)__entry->caller[7])
0177 );
0178 
0179 FTRACE_ENTRY(user_stack, userstack_entry,
0180 
0181     TRACE_USER_STACK,
0182 
0183     F_STRUCT(
0184         __field(    unsigned int,   tgid    )
0185         __array(    unsigned long,  caller, FTRACE_STACK_ENTRIES    )
0186     ),
0187 
0188     F_printk("\t=> %ps\n\t=> %ps\n\t=> %ps\n"
0189          "\t=> %ps\n\t=> %ps\n\t=> %ps\n"
0190          "\t=> %ps\n\t=> %ps\n",
0191          (void *)__entry->caller[0], (void *)__entry->caller[1],
0192          (void *)__entry->caller[2], (void *)__entry->caller[3],
0193          (void *)__entry->caller[4], (void *)__entry->caller[5],
0194          (void *)__entry->caller[6], (void *)__entry->caller[7])
0195 );
0196 
0197 /*
0198  * trace_printk entry:
0199  */
0200 FTRACE_ENTRY(bprint, bprint_entry,
0201 
0202     TRACE_BPRINT,
0203 
0204     F_STRUCT(
0205         __field(    unsigned long,  ip  )
0206         __field(    const char *,   fmt )
0207         __dynamic_array(    u32,    buf )
0208     ),
0209 
0210     F_printk("%ps: %s",
0211          (void *)__entry->ip, __entry->fmt)
0212 );
0213 
0214 FTRACE_ENTRY_REG(print, print_entry,
0215 
0216     TRACE_PRINT,
0217 
0218     F_STRUCT(
0219         __field(    unsigned long,  ip  )
0220         __dynamic_array(    char,   buf )
0221     ),
0222 
0223     F_printk("%ps: %s",
0224          (void *)__entry->ip, __entry->buf),
0225 
0226     ftrace_event_register
0227 );
0228 
0229 FTRACE_ENTRY(raw_data, raw_data_entry,
0230 
0231     TRACE_RAW_DATA,
0232 
0233     F_STRUCT(
0234         __field(    unsigned int,   id  )
0235         __dynamic_array(    char,   buf )
0236     ),
0237 
0238     F_printk("id:%04x %08x",
0239          __entry->id, (int)__entry->buf[0])
0240 );
0241 
0242 FTRACE_ENTRY(bputs, bputs_entry,
0243 
0244     TRACE_BPUTS,
0245 
0246     F_STRUCT(
0247         __field(    unsigned long,  ip  )
0248         __field(    const char *,   str )
0249     ),
0250 
0251     F_printk("%ps: %s",
0252          (void *)__entry->ip, __entry->str)
0253 );
0254 
0255 FTRACE_ENTRY(mmiotrace_rw, trace_mmiotrace_rw,
0256 
0257     TRACE_MMIO_RW,
0258 
0259     F_STRUCT(
0260         __field_struct( struct mmiotrace_rw,    rw  )
0261         __field_desc(   resource_size_t, rw,    phys    )
0262         __field_desc(   unsigned long,  rw, value   )
0263         __field_desc(   unsigned long,  rw, pc  )
0264         __field_desc(   int,        rw, map_id  )
0265         __field_desc(   unsigned char,  rw, opcode  )
0266         __field_desc(   unsigned char,  rw, width   )
0267     ),
0268 
0269     F_printk("%lx %lx %lx %d %x %x",
0270          (unsigned long)__entry->phys, __entry->value, __entry->pc,
0271          __entry->map_id, __entry->opcode, __entry->width)
0272 );
0273 
0274 FTRACE_ENTRY(mmiotrace_map, trace_mmiotrace_map,
0275 
0276     TRACE_MMIO_MAP,
0277 
0278     F_STRUCT(
0279         __field_struct( struct mmiotrace_map,   map )
0280         __field_desc(   resource_size_t, map,   phys    )
0281         __field_desc(   unsigned long,  map,    virt    )
0282         __field_desc(   unsigned long,  map,    len )
0283         __field_desc(   int,        map,    map_id  )
0284         __field_desc(   unsigned char,  map,    opcode  )
0285     ),
0286 
0287     F_printk("%lx %lx %lx %d %x",
0288          (unsigned long)__entry->phys, __entry->virt, __entry->len,
0289          __entry->map_id, __entry->opcode)
0290 );
0291 
0292 
0293 #define TRACE_FUNC_SIZE 30
0294 #define TRACE_FILE_SIZE 20
0295 
0296 FTRACE_ENTRY(branch, trace_branch,
0297 
0298     TRACE_BRANCH,
0299 
0300     F_STRUCT(
0301         __field(    unsigned int,   line                )
0302         __array(    char,       func,   TRACE_FUNC_SIZE+1   )
0303         __array(    char,       file,   TRACE_FILE_SIZE+1   )
0304         __field(    char,       correct             )
0305         __field(    char,       constant            )
0306     ),
0307 
0308     F_printk("%u:%s:%s (%u)%s",
0309          __entry->line,
0310          __entry->func, __entry->file, __entry->correct,
0311          __entry->constant ? " CONSTANT" : "")
0312 );
0313 
0314 
0315 FTRACE_ENTRY(hwlat, hwlat_entry,
0316 
0317     TRACE_HWLAT,
0318 
0319     F_STRUCT(
0320         __field(    u64,            duration    )
0321         __field(    u64,            outer_duration  )
0322         __field(    u64,            nmi_total_ts    )
0323         __field_struct( struct timespec64,  timestamp   )
0324         __field_desc(   s64,    timestamp,  tv_sec      )
0325         __field_desc(   long,   timestamp,  tv_nsec     )
0326         __field(    unsigned int,       nmi_count   )
0327         __field(    unsigned int,       seqnum      )
0328         __field(    unsigned int,       count       )
0329     ),
0330 
0331     F_printk("cnt:%u\tts:%010llu.%010lu\tinner:%llu\touter:%llu\tcount:%d\tnmi-ts:%llu\tnmi-count:%u\n",
0332          __entry->seqnum,
0333          __entry->tv_sec,
0334          __entry->tv_nsec,
0335          __entry->duration,
0336          __entry->outer_duration,
0337          __entry->count,
0338          __entry->nmi_total_ts,
0339          __entry->nmi_count)
0340 );
0341 
0342 #define FUNC_REPEATS_GET_DELTA_TS(entry)                \
0343     (((u64)(entry)->top_delta_ts << 32) | (entry)->bottom_delta_ts) \
0344 
0345 FTRACE_ENTRY(func_repeats, func_repeats_entry,
0346 
0347     TRACE_FUNC_REPEATS,
0348 
0349     F_STRUCT(
0350         __field(    unsigned long,  ip      )
0351         __field(    unsigned long,  parent_ip   )
0352         __field(    u16 ,   count       )
0353         __field(    u16 ,   top_delta_ts    )
0354         __field(    u32 ,   bottom_delta_ts )
0355     ),
0356 
0357     F_printk(" %ps <-%ps\t(repeats:%u  delta: -%llu)",
0358          (void *)__entry->ip,
0359          (void *)__entry->parent_ip,
0360          __entry->count,
0361          FUNC_REPEATS_GET_DELTA_TS(__entry))
0362 );
0363 
0364 FTRACE_ENTRY(osnoise, osnoise_entry,
0365 
0366     TRACE_OSNOISE,
0367 
0368     F_STRUCT(
0369         __field(    u64,            noise       )
0370         __field(    u64,            runtime     )
0371         __field(    u64,            max_sample  )
0372         __field(    unsigned int,       hw_count    )
0373         __field(    unsigned int,       nmi_count   )
0374         __field(    unsigned int,       irq_count   )
0375         __field(    unsigned int,       softirq_count   )
0376         __field(    unsigned int,       thread_count    )
0377     ),
0378 
0379     F_printk("noise:%llu\tmax_sample:%llu\thw:%u\tnmi:%u\tirq:%u\tsoftirq:%u\tthread:%u\n",
0380          __entry->noise,
0381          __entry->max_sample,
0382          __entry->hw_count,
0383          __entry->nmi_count,
0384          __entry->irq_count,
0385          __entry->softirq_count,
0386          __entry->thread_count)
0387 );
0388 
0389 FTRACE_ENTRY(timerlat, timerlat_entry,
0390 
0391     TRACE_TIMERLAT,
0392 
0393     F_STRUCT(
0394         __field(    unsigned int,       seqnum      )
0395         __field(    int,            context     )
0396         __field(    u64,            timer_latency   )
0397     ),
0398 
0399     F_printk("seq:%u\tcontext:%d\ttimer_latency:%llu\n",
0400          __entry->seqnum,
0401          __entry->context,
0402          __entry->timer_latency)
0403 );