Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * trace_export.c - export basic ftrace utilities to user space
0004  *
0005  * Copyright (C) 2009 Steven Rostedt <srostedt@redhat.com>
0006  */
0007 #include <linux/stringify.h>
0008 #include <linux/kallsyms.h>
0009 #include <linux/seq_file.h>
0010 #include <linux/uaccess.h>
0011 #include <linux/ftrace.h>
0012 #include <linux/module.h>
0013 #include <linux/init.h>
0014 
0015 #include "trace_output.h"
0016 
0017 /* Stub function for events with triggers */
0018 static int ftrace_event_register(struct trace_event_call *call,
0019                  enum trace_reg type, void *data)
0020 {
0021     return 0;
0022 }
0023 
0024 #undef TRACE_SYSTEM
0025 #define TRACE_SYSTEM    ftrace
0026 
0027 /*
0028  * The FTRACE_ENTRY_REG macro allows ftrace entry to define register
0029  * function and thus become accessible via perf.
0030  */
0031 #undef FTRACE_ENTRY_REG
0032 #define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print, regfn) \
0033     FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print))
0034 
0035 /* not needed for this file */
0036 #undef __field_struct
0037 #define __field_struct(type, item)
0038 
0039 #undef __field
0040 #define __field(type, item)             type item;
0041 
0042 #undef __field_fn
0043 #define __field_fn(type, item)              type item;
0044 
0045 #undef __field_desc
0046 #define __field_desc(type, container, item)     type item;
0047 
0048 #undef __field_packed
0049 #define __field_packed(type, container, item)       type item;
0050 
0051 #undef __array
0052 #define __array(type, item, size)           type item[size];
0053 
0054 #undef __array_desc
0055 #define __array_desc(type, container, item, size)   type item[size];
0056 
0057 #undef __dynamic_array
0058 #define __dynamic_array(type, item)         type item[];
0059 
0060 #undef F_STRUCT
0061 #define F_STRUCT(args...)               args
0062 
0063 #undef F_printk
0064 #define F_printk(fmt, args...) fmt, args
0065 
0066 #undef FTRACE_ENTRY
0067 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print)     \
0068 struct ____ftrace_##name {                      \
0069     tstruct                             \
0070 };                                  \
0071 static void __always_unused ____ftrace_check_##name(void)       \
0072 {                                   \
0073     struct ____ftrace_##name *__entry = NULL;           \
0074                                     \
0075     /* force compile-time check on F_printk() */            \
0076     printk(print);                          \
0077 }
0078 
0079 #undef FTRACE_ENTRY_DUP
0080 #define FTRACE_ENTRY_DUP(name, struct_name, id, tstruct, print)     \
0081     FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print))
0082 
0083 #include "trace_entries.h"
0084 
0085 #undef __field_ext
0086 #define __field_ext(_type, _item, _filter_type) {           \
0087     .type = #_type, .name = #_item,                 \
0088     .size = sizeof(_type), .align = __alignof__(_type),     \
0089     is_signed_type(_type), .filter_type = _filter_type },
0090 
0091 
0092 #undef __field_ext_packed
0093 #define __field_ext_packed(_type, _item, _filter_type) {    \
0094     .type = #_type, .name = #_item,             \
0095     .size = sizeof(_type), .align = 1,          \
0096     is_signed_type(_type), .filter_type = _filter_type },
0097 
0098 #undef __field
0099 #define __field(_type, _item) __field_ext(_type, _item, FILTER_OTHER)
0100 
0101 #undef __field_fn
0102 #define __field_fn(_type, _item) __field_ext(_type, _item, FILTER_TRACE_FN)
0103 
0104 #undef __field_desc
0105 #define __field_desc(_type, _container, _item) __field_ext(_type, _item, FILTER_OTHER)
0106 
0107 #undef __field_packed
0108 #define __field_packed(_type, _container, _item) __field_ext_packed(_type, _item, FILTER_OTHER)
0109 
0110 #undef __array
0111 #define __array(_type, _item, _len) {                   \
0112     .type = #_type"["__stringify(_len)"]", .name = #_item,      \
0113     .size = sizeof(_type[_len]), .align = __alignof__(_type),   \
0114     is_signed_type(_type), .filter_type = FILTER_OTHER },
0115 
0116 #undef __array_desc
0117 #define __array_desc(_type, _container, _item, _len) __array(_type, _item, _len)
0118 
0119 #undef __dynamic_array
0120 #define __dynamic_array(_type, _item) {                 \
0121     .type = #_type "[]", .name = #_item,                \
0122     .size = 0, .align = __alignof__(_type),             \
0123     is_signed_type(_type), .filter_type = FILTER_OTHER },
0124 
0125 #undef FTRACE_ENTRY
0126 #define FTRACE_ENTRY(name, struct_name, id, tstruct, print)     \
0127 static struct trace_event_fields ftrace_event_fields_##name[] = {   \
0128     tstruct                             \
0129     {} };
0130 
0131 #include "trace_entries.h"
0132 
0133 #undef __entry
0134 #define __entry REC
0135 
0136 #undef __field
0137 #define __field(type, item)
0138 
0139 #undef __field_fn
0140 #define __field_fn(type, item)
0141 
0142 #undef __field_desc
0143 #define __field_desc(type, container, item)
0144 
0145 #undef __field_packed
0146 #define __field_packed(type, container, item)
0147 
0148 #undef __array
0149 #define __array(type, item, len)
0150 
0151 #undef __array_desc
0152 #define __array_desc(type, container, item, len)
0153 
0154 #undef __dynamic_array
0155 #define __dynamic_array(type, item)
0156 
0157 #undef F_printk
0158 #define F_printk(fmt, args...) __stringify(fmt) ", "  __stringify(args)
0159 
0160 #undef FTRACE_ENTRY_REG
0161 #define FTRACE_ENTRY_REG(call, struct_name, etype, tstruct, print, regfn) \
0162 static struct trace_event_class __refdata event_class_ftrace_##call = { \
0163     .system         = __stringify(TRACE_SYSTEM),        \
0164     .fields_array       = ftrace_event_fields_##call,       \
0165     .fields         = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\
0166     .reg            = regfn,                \
0167 };                                  \
0168                                     \
0169 struct trace_event_call __used event_##call = {             \
0170     .class          = &event_class_ftrace_##call,       \
0171     {                               \
0172         .name           = #call,            \
0173     },                              \
0174     .event.type     = etype,                \
0175     .print_fmt      = print,                \
0176     .flags          = TRACE_EVENT_FL_IGNORE_ENABLE,     \
0177 };                                  \
0178 static struct trace_event_call __used                       \
0179 __section("_ftrace_events") *__event_##call = &event_##call;
0180 
0181 #undef FTRACE_ENTRY
0182 #define FTRACE_ENTRY(call, struct_name, etype, tstruct, print)      \
0183     FTRACE_ENTRY_REG(call, struct_name, etype,          \
0184              PARAMS(tstruct), PARAMS(print), NULL)
0185 
0186 bool ftrace_event_is_function(struct trace_event_call *call)
0187 {
0188     return call == &event_function;
0189 }
0190 
0191 #include "trace_entries.h"