1bb730b58SSteven Rostedt (VMware) // SPDX-License-Identifier: GPL-2.0 20a1c49dbSSteven Rostedt /* 30a1c49dbSSteven Rostedt * This file defines the trace event structures that go into the ring 40a1c49dbSSteven Rostedt * buffer directly. They are created via macros so that changes for them 50a1c49dbSSteven Rostedt * appear in the format file. Using macros will automate this process. 60a1c49dbSSteven Rostedt * 70a1c49dbSSteven Rostedt * The macro used to create a ftrace data structure is: 80a1c49dbSSteven Rostedt * 90a1c49dbSSteven Rostedt * FTRACE_ENTRY( name, struct_name, id, structure, print ) 100a1c49dbSSteven Rostedt * 110a1c49dbSSteven Rostedt * @name: the name used the event name, as well as the name of 120a1c49dbSSteven Rostedt * the directory that holds the format file. 130a1c49dbSSteven Rostedt * 140a1c49dbSSteven Rostedt * @struct_name: the name of the structure that is created. 150a1c49dbSSteven Rostedt * 160a1c49dbSSteven Rostedt * @id: The event identifier that is used to detect what event 170a1c49dbSSteven Rostedt * this is from the ring buffer. 180a1c49dbSSteven Rostedt * 190a1c49dbSSteven Rostedt * @structure: the structure layout 200a1c49dbSSteven Rostedt * 210a1c49dbSSteven Rostedt * - __field( type, item ) 220a1c49dbSSteven Rostedt * This is equivalent to declaring 230a1c49dbSSteven Rostedt * type item; 240a1c49dbSSteven Rostedt * in the structure. 250a1c49dbSSteven Rostedt * - __array( type, item, size ) 260a1c49dbSSteven Rostedt * This is equivalent to declaring 270a1c49dbSSteven Rostedt * type item[size]; 280a1c49dbSSteven Rostedt * in the structure. 290a1c49dbSSteven Rostedt * 30d7315094SSteven Rostedt * * for structures within structures, the format of the internal 3125985edcSLucas De Marchi * structure is laid out. This allows the internal structure 32d7315094SSteven Rostedt * to be deciphered for the format file. Although these macros 33d7315094SSteven Rostedt * may become out of sync with the internal structure, they 34d7315094SSteven Rostedt * will create a compile error if it happens. Since the 35d7315094SSteven Rostedt * internel structures are just tracing helpers, this is not 36d7315094SSteven Rostedt * an issue. 37d7315094SSteven Rostedt * 38d7315094SSteven Rostedt * When an internal structure is used, it should use: 39d7315094SSteven Rostedt * 40d7315094SSteven Rostedt * __field_struct( type, item ) 41d7315094SSteven Rostedt * 42d7315094SSteven Rostedt * instead of __field. This will prevent it from being shown in 43d7315094SSteven Rostedt * the output file. The fields in the structure should use. 44d7315094SSteven Rostedt * 45d7315094SSteven Rostedt * __field_desc( type, container, item ) 46d7315094SSteven Rostedt * __array_desc( type, container, item, len ) 47d7315094SSteven Rostedt * 48d7315094SSteven Rostedt * type, item and len are the same as __field and __array, but 49d7315094SSteven Rostedt * container is added. This is the name of the item in 50d7315094SSteven Rostedt * __field_struct that this is describing. 51d7315094SSteven Rostedt * 52d7315094SSteven Rostedt * 530a1c49dbSSteven Rostedt * @print: the print format shown to users in the format file. 540a1c49dbSSteven Rostedt */ 550a1c49dbSSteven Rostedt 560a1c49dbSSteven Rostedt /* 57b595076aSUwe Kleine-König * Function trace entry - function address and parent function address: 580a1c49dbSSteven Rostedt */ 59ced39002SJiri Olsa FTRACE_ENTRY_REG(function, ftrace_entry, 600a1c49dbSSteven Rostedt 610a1c49dbSSteven Rostedt TRACE_FN, 620a1c49dbSSteven Rostedt 630a1c49dbSSteven Rostedt F_STRUCT( 6404ae87a5SPeter Zijlstra __field_fn( unsigned long, ip ) 6504ae87a5SPeter Zijlstra __field_fn( unsigned long, parent_ip ) 660a1c49dbSSteven Rostedt ), 670a1c49dbSSteven Rostedt 6885acbb21SChangbin Du F_printk(" %ps <-- %ps", 6985acbb21SChangbin Du (void *)__entry->ip, (void *)__entry->parent_ip), 70ced39002SJiri Olsa 71ced39002SJiri Olsa perf_ftrace_event_register 720a1c49dbSSteven Rostedt ); 730a1c49dbSSteven Rostedt 740a1c49dbSSteven Rostedt /* Function call entry */ 75a4a551b8SNamhyung Kim FTRACE_ENTRY_PACKED(funcgraph_entry, ftrace_graph_ent_entry, 760a1c49dbSSteven Rostedt 770a1c49dbSSteven Rostedt TRACE_GRAPH_ENT, 780a1c49dbSSteven Rostedt 790a1c49dbSSteven Rostedt F_STRUCT( 80d7315094SSteven Rostedt __field_struct( struct ftrace_graph_ent, graph_ent ) 81d7315094SSteven Rostedt __field_desc( unsigned long, graph_ent, func ) 82d7315094SSteven Rostedt __field_desc( int, graph_ent, depth ) 830a1c49dbSSteven Rostedt ), 840a1c49dbSSteven Rostedt 8504ae87a5SPeter Zijlstra F_printk("--> %ps (%d)", (void *)__entry->func, __entry->depth) 860a1c49dbSSteven Rostedt ); 870a1c49dbSSteven Rostedt 880a1c49dbSSteven Rostedt /* Function return entry */ 89a4a551b8SNamhyung Kim FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry, 900a1c49dbSSteven Rostedt 910a1c49dbSSteven Rostedt TRACE_GRAPH_RET, 920a1c49dbSSteven Rostedt 930a1c49dbSSteven Rostedt F_STRUCT( 94d7315094SSteven Rostedt __field_struct( struct ftrace_graph_ret, ret ) 95d7315094SSteven Rostedt __field_desc( unsigned long, ret, func ) 9604ae87a5SPeter Zijlstra __field_desc( unsigned long, ret, overrun ) 97d7315094SSteven Rostedt __field_desc( unsigned long long, ret, calltime) 98d7315094SSteven Rostedt __field_desc( unsigned long long, ret, rettime ) 99d7315094SSteven Rostedt __field_desc( int, ret, depth ) 1000a1c49dbSSteven Rostedt ), 1010a1c49dbSSteven Rostedt 10285acbb21SChangbin Du F_printk("<-- %ps (%d) (start: %llx end: %llx) over: %d", 10385acbb21SChangbin Du (void *)__entry->func, __entry->depth, 104c16de8fdSLi Zefan __entry->calltime, __entry->rettime, 10504ae87a5SPeter Zijlstra __entry->depth) 1060a1c49dbSSteven Rostedt ); 1070a1c49dbSSteven Rostedt 1080a1c49dbSSteven Rostedt /* 1090a1c49dbSSteven Rostedt * Context switch trace entry - which task (and prio) we switched from/to: 1100a1c49dbSSteven Rostedt * 1110a1c49dbSSteven Rostedt * This is used for both wakeup and context switches. We only want 1120a1c49dbSSteven Rostedt * to create one structure, but we need two outputs for it. 1130a1c49dbSSteven Rostedt */ 1140a1c49dbSSteven Rostedt #define FTRACE_CTX_FIELDS \ 1150a1c49dbSSteven Rostedt __field( unsigned int, prev_pid ) \ 116140e4f2dSDavid Sharp __field( unsigned int, next_pid ) \ 117140e4f2dSDavid Sharp __field( unsigned int, next_cpu ) \ 1180a1c49dbSSteven Rostedt __field( unsigned char, prev_prio ) \ 1190a1c49dbSSteven Rostedt __field( unsigned char, prev_state ) \ 1200a1c49dbSSteven Rostedt __field( unsigned char, next_prio ) \ 121140e4f2dSDavid Sharp __field( unsigned char, next_state ) 1220a1c49dbSSteven Rostedt 1230a1c49dbSSteven Rostedt FTRACE_ENTRY(context_switch, ctx_switch_entry, 1240a1c49dbSSteven Rostedt 1250a1c49dbSSteven Rostedt TRACE_CTX, 1260a1c49dbSSteven Rostedt 1270a1c49dbSSteven Rostedt F_STRUCT( 1280a1c49dbSSteven Rostedt FTRACE_CTX_FIELDS 1290a1c49dbSSteven Rostedt ), 1300a1c49dbSSteven Rostedt 131c16de8fdSLi Zefan F_printk("%u:%u:%u ==> %u:%u:%u [%03u]", 1320a1c49dbSSteven Rostedt __entry->prev_pid, __entry->prev_prio, __entry->prev_state, 1330a1c49dbSSteven Rostedt __entry->next_pid, __entry->next_prio, __entry->next_state, 13404ae87a5SPeter Zijlstra __entry->next_cpu) 1350a1c49dbSSteven Rostedt ); 1360a1c49dbSSteven Rostedt 1370a1c49dbSSteven Rostedt /* 1380a1c49dbSSteven Rostedt * FTRACE_ENTRY_DUP only creates the format file, it will not 1390a1c49dbSSteven Rostedt * create another structure. 1400a1c49dbSSteven Rostedt */ 1410a1c49dbSSteven Rostedt FTRACE_ENTRY_DUP(wakeup, ctx_switch_entry, 1420a1c49dbSSteven Rostedt 1430a1c49dbSSteven Rostedt TRACE_WAKE, 1440a1c49dbSSteven Rostedt 1450a1c49dbSSteven Rostedt F_STRUCT( 1460a1c49dbSSteven Rostedt FTRACE_CTX_FIELDS 1470a1c49dbSSteven Rostedt ), 1480a1c49dbSSteven Rostedt 1490a1c49dbSSteven Rostedt F_printk("%u:%u:%u ==+ %u:%u:%u [%03u]", 1500a1c49dbSSteven Rostedt __entry->prev_pid, __entry->prev_prio, __entry->prev_state, 1510a1c49dbSSteven Rostedt __entry->next_pid, __entry->next_prio, __entry->next_state, 15204ae87a5SPeter Zijlstra __entry->next_cpu) 1530a1c49dbSSteven Rostedt ); 1540a1c49dbSSteven Rostedt 1550a1c49dbSSteven Rostedt /* 1560a1c49dbSSteven Rostedt * Stack-trace entry: 1570a1c49dbSSteven Rostedt */ 1580a1c49dbSSteven Rostedt 1590a1c49dbSSteven Rostedt #define FTRACE_STACK_ENTRIES 8 1600a1c49dbSSteven Rostedt 1610a1c49dbSSteven Rostedt FTRACE_ENTRY(kernel_stack, stack_entry, 1620a1c49dbSSteven Rostedt 1630a1c49dbSSteven Rostedt TRACE_STACK, 1640a1c49dbSSteven Rostedt 1650a1c49dbSSteven Rostedt F_STRUCT( 1664a9bd3f1SSteven Rostedt __field( int, size ) 167cbc3b92cSJosef Bacik __array( unsigned long, caller, FTRACE_STACK_ENTRIES ) 1680a1c49dbSSteven Rostedt ), 1690a1c49dbSSteven Rostedt 17085acbb21SChangbin Du F_printk("\t=> %ps\n\t=> %ps\n\t=> %ps\n" 17185acbb21SChangbin Du "\t=> %ps\n\t=> %ps\n\t=> %ps\n" 17285acbb21SChangbin Du "\t=> %ps\n\t=> %ps\n", 17385acbb21SChangbin Du (void *)__entry->caller[0], (void *)__entry->caller[1], 17485acbb21SChangbin Du (void *)__entry->caller[2], (void *)__entry->caller[3], 17585acbb21SChangbin Du (void *)__entry->caller[4], (void *)__entry->caller[5], 17604ae87a5SPeter Zijlstra (void *)__entry->caller[6], (void *)__entry->caller[7]) 1770a1c49dbSSteven Rostedt ); 1780a1c49dbSSteven Rostedt 1790a1c49dbSSteven Rostedt FTRACE_ENTRY(user_stack, userstack_entry, 1800a1c49dbSSteven Rostedt 1810a1c49dbSSteven Rostedt TRACE_USER_STACK, 1820a1c49dbSSteven Rostedt 1830a1c49dbSSteven Rostedt F_STRUCT( 1840a1c49dbSSteven Rostedt __field( unsigned int, tgid ) 1850a1c49dbSSteven Rostedt __array( unsigned long, caller, FTRACE_STACK_ENTRIES ) 1860a1c49dbSSteven Rostedt ), 1870a1c49dbSSteven Rostedt 18885acbb21SChangbin Du F_printk("\t=> %ps\n\t=> %ps\n\t=> %ps\n" 18985acbb21SChangbin Du "\t=> %ps\n\t=> %ps\n\t=> %ps\n" 19085acbb21SChangbin Du "\t=> %ps\n\t=> %ps\n", 19185acbb21SChangbin Du (void *)__entry->caller[0], (void *)__entry->caller[1], 19285acbb21SChangbin Du (void *)__entry->caller[2], (void *)__entry->caller[3], 19385acbb21SChangbin Du (void *)__entry->caller[4], (void *)__entry->caller[5], 19404ae87a5SPeter Zijlstra (void *)__entry->caller[6], (void *)__entry->caller[7]) 1950a1c49dbSSteven Rostedt ); 1960a1c49dbSSteven Rostedt 1970a1c49dbSSteven Rostedt /* 1980a1c49dbSSteven Rostedt * trace_printk entry: 1990a1c49dbSSteven Rostedt */ 2000a1c49dbSSteven Rostedt FTRACE_ENTRY(bprint, bprint_entry, 2010a1c49dbSSteven Rostedt 2020a1c49dbSSteven Rostedt TRACE_BPRINT, 2030a1c49dbSSteven Rostedt 2040a1c49dbSSteven Rostedt F_STRUCT( 2050a1c49dbSSteven Rostedt __field( unsigned long, ip ) 2060a1c49dbSSteven Rostedt __field( const char *, fmt ) 2070a1c49dbSSteven Rostedt __dynamic_array( u32, buf ) 2080a1c49dbSSteven Rostedt ), 2090a1c49dbSSteven Rostedt 210bbedb179SScott Wood F_printk("%ps: %s", 21104ae87a5SPeter Zijlstra (void *)__entry->ip, __entry->fmt) 2120a1c49dbSSteven Rostedt ); 2130a1c49dbSSteven Rostedt 2143dd80953SSteven Rostedt (VMware) FTRACE_ENTRY_REG(print, print_entry, 2150a1c49dbSSteven Rostedt 2160a1c49dbSSteven Rostedt TRACE_PRINT, 2170a1c49dbSSteven Rostedt 2180a1c49dbSSteven Rostedt F_STRUCT( 2190a1c49dbSSteven Rostedt __field( unsigned long, ip ) 2200a1c49dbSSteven Rostedt __dynamic_array( char, buf ) 2210a1c49dbSSteven Rostedt ), 2220a1c49dbSSteven Rostedt 223bbedb179SScott Wood F_printk("%ps: %s", 22409ae7234SSteven Rostedt (Red Hat) (void *)__entry->ip, __entry->buf), 22509ae7234SSteven Rostedt (Red Hat) 2263dd80953SSteven Rostedt (VMware) ftrace_event_register 22709ae7234SSteven Rostedt (Red Hat) ); 22809ae7234SSteven Rostedt (Red Hat) 229fa32e855SSteven Rostedt FTRACE_ENTRY(raw_data, raw_data_entry, 230fa32e855SSteven Rostedt 231fa32e855SSteven Rostedt TRACE_RAW_DATA, 232fa32e855SSteven Rostedt 233fa32e855SSteven Rostedt F_STRUCT( 234fa32e855SSteven Rostedt __field( unsigned int, id ) 235fa32e855SSteven Rostedt __dynamic_array( char, buf ) 236fa32e855SSteven Rostedt ), 237fa32e855SSteven Rostedt 238fa32e855SSteven Rostedt F_printk("id:%04x %08x", 23904ae87a5SPeter Zijlstra __entry->id, (int)__entry->buf[0]) 240fa32e855SSteven Rostedt ); 241fa32e855SSteven Rostedt 24209ae7234SSteven Rostedt (Red Hat) FTRACE_ENTRY(bputs, bputs_entry, 24309ae7234SSteven Rostedt (Red Hat) 24409ae7234SSteven Rostedt (Red Hat) TRACE_BPUTS, 24509ae7234SSteven Rostedt (Red Hat) 24609ae7234SSteven Rostedt (Red Hat) F_STRUCT( 24709ae7234SSteven Rostedt (Red Hat) __field( unsigned long, ip ) 24809ae7234SSteven Rostedt (Red Hat) __field( const char *, str ) 24909ae7234SSteven Rostedt (Red Hat) ), 25009ae7234SSteven Rostedt (Red Hat) 251bbedb179SScott Wood F_printk("%ps: %s", 25204ae87a5SPeter Zijlstra (void *)__entry->ip, __entry->str) 2530a1c49dbSSteven Rostedt ); 2540a1c49dbSSteven Rostedt 2550a1c49dbSSteven Rostedt FTRACE_ENTRY(mmiotrace_rw, trace_mmiotrace_rw, 2560a1c49dbSSteven Rostedt 2570a1c49dbSSteven Rostedt TRACE_MMIO_RW, 2580a1c49dbSSteven Rostedt 2590a1c49dbSSteven Rostedt F_STRUCT( 260d7315094SSteven Rostedt __field_struct( struct mmiotrace_rw, rw ) 261d7315094SSteven Rostedt __field_desc( resource_size_t, rw, phys ) 262d7315094SSteven Rostedt __field_desc( unsigned long, rw, value ) 263d7315094SSteven Rostedt __field_desc( unsigned long, rw, pc ) 264d7315094SSteven Rostedt __field_desc( int, rw, map_id ) 265d7315094SSteven Rostedt __field_desc( unsigned char, rw, opcode ) 266d7315094SSteven Rostedt __field_desc( unsigned char, rw, width ) 2670a1c49dbSSteven Rostedt ), 2680a1c49dbSSteven Rostedt 269c16de8fdSLi Zefan F_printk("%lx %lx %lx %d %x %x", 270c16de8fdSLi Zefan (unsigned long)__entry->phys, __entry->value, __entry->pc, 27104ae87a5SPeter Zijlstra __entry->map_id, __entry->opcode, __entry->width) 2720a1c49dbSSteven Rostedt ); 2730a1c49dbSSteven Rostedt 2740a1c49dbSSteven Rostedt FTRACE_ENTRY(mmiotrace_map, trace_mmiotrace_map, 2750a1c49dbSSteven Rostedt 2760a1c49dbSSteven Rostedt TRACE_MMIO_MAP, 2770a1c49dbSSteven Rostedt 2780a1c49dbSSteven Rostedt F_STRUCT( 279d7315094SSteven Rostedt __field_struct( struct mmiotrace_map, map ) 280d7315094SSteven Rostedt __field_desc( resource_size_t, map, phys ) 281d7315094SSteven Rostedt __field_desc( unsigned long, map, virt ) 282d7315094SSteven Rostedt __field_desc( unsigned long, map, len ) 283d7315094SSteven Rostedt __field_desc( int, map, map_id ) 284d7315094SSteven Rostedt __field_desc( unsigned char, map, opcode ) 2850a1c49dbSSteven Rostedt ), 2860a1c49dbSSteven Rostedt 287c16de8fdSLi Zefan F_printk("%lx %lx %lx %d %x", 288c16de8fdSLi Zefan (unsigned long)__entry->phys, __entry->virt, __entry->len, 28904ae87a5SPeter Zijlstra __entry->map_id, __entry->opcode) 2900a1c49dbSSteven Rostedt ); 2910a1c49dbSSteven Rostedt 2920a1c49dbSSteven Rostedt 2930a1c49dbSSteven Rostedt #define TRACE_FUNC_SIZE 30 2940a1c49dbSSteven Rostedt #define TRACE_FILE_SIZE 20 2950a1c49dbSSteven Rostedt 2960a1c49dbSSteven Rostedt FTRACE_ENTRY(branch, trace_branch, 2970a1c49dbSSteven Rostedt 2980a1c49dbSSteven Rostedt TRACE_BRANCH, 2990a1c49dbSSteven Rostedt 3000a1c49dbSSteven Rostedt F_STRUCT( 3010a1c49dbSSteven Rostedt __field( unsigned int, line ) 3020a1c49dbSSteven Rostedt __array( char, func, TRACE_FUNC_SIZE+1 ) 3030a1c49dbSSteven Rostedt __array( char, file, TRACE_FILE_SIZE+1 ) 3040a1c49dbSSteven Rostedt __field( char, correct ) 305068f530bSSteven Rostedt (VMware) __field( char, constant ) 3060a1c49dbSSteven Rostedt ), 3070a1c49dbSSteven Rostedt 308068f530bSSteven Rostedt (VMware) F_printk("%u:%s:%s (%u)%s", 3090a1c49dbSSteven Rostedt __entry->line, 310068f530bSSteven Rostedt (VMware) __entry->func, __entry->file, __entry->correct, 31104ae87a5SPeter Zijlstra __entry->constant ? " CONSTANT" : "") 3120a1c49dbSSteven Rostedt ); 3130a1c49dbSSteven Rostedt 314e7c15cd8SSteven Rostedt (Red Hat) 315e7c15cd8SSteven Rostedt (Red Hat) FTRACE_ENTRY(hwlat, hwlat_entry, 316e7c15cd8SSteven Rostedt (Red Hat) 317e7c15cd8SSteven Rostedt (Red Hat) TRACE_HWLAT, 318e7c15cd8SSteven Rostedt (Red Hat) 319e7c15cd8SSteven Rostedt (Red Hat) F_STRUCT( 320e7c15cd8SSteven Rostedt (Red Hat) __field( u64, duration ) 321e7c15cd8SSteven Rostedt (Red Hat) __field( u64, outer_duration ) 3227b2c8625SSteven Rostedt (Red Hat) __field( u64, nmi_total_ts ) 32351aad0aeSDeepa Dinamani __field_struct( struct timespec64, timestamp ) 32451aad0aeSDeepa Dinamani __field_desc( s64, timestamp, tv_sec ) 325e7c15cd8SSteven Rostedt (Red Hat) __field_desc( long, timestamp, tv_nsec ) 3267b2c8625SSteven Rostedt (Red Hat) __field( unsigned int, nmi_count ) 327e7c15cd8SSteven Rostedt (Red Hat) __field( unsigned int, seqnum ) 328*b396bfdeSSteven Rostedt (VMware) __field( unsigned int, count ) 329e7c15cd8SSteven Rostedt (Red Hat) ), 330e7c15cd8SSteven Rostedt (Red Hat) 331*b396bfdeSSteven Rostedt (VMware) F_printk("cnt:%u\tts:%010llu.%010lu\tinner:%llu\touter:%llu\tcount:%d\tnmi-ts:%llu\tnmi-count:%u\n", 332e7c15cd8SSteven Rostedt (Red Hat) __entry->seqnum, 333e7c15cd8SSteven Rostedt (Red Hat) __entry->tv_sec, 334e7c15cd8SSteven Rostedt (Red Hat) __entry->tv_nsec, 335e7c15cd8SSteven Rostedt (Red Hat) __entry->duration, 3367b2c8625SSteven Rostedt (Red Hat) __entry->outer_duration, 337*b396bfdeSSteven Rostedt (VMware) __entry->count, 3387b2c8625SSteven Rostedt (Red Hat) __entry->nmi_total_ts, 33904ae87a5SPeter Zijlstra __entry->nmi_count) 340e7c15cd8SSteven Rostedt (Red Hat) ); 341