| .. | .. |
|---|
| 34 | 34 | TRACE_FUNC_OPT_STACK = 0x1, |
|---|
| 35 | 35 | }; |
|---|
| 36 | 36 | |
|---|
| 37 | | -static int allocate_ftrace_ops(struct trace_array *tr) |
|---|
| 37 | +int ftrace_allocate_ftrace_ops(struct trace_array *tr) |
|---|
| 38 | 38 | { |
|---|
| 39 | 39 | struct ftrace_ops *ops; |
|---|
| 40 | + |
|---|
| 41 | + /* The top level array uses the "global_ops" */ |
|---|
| 42 | + if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
|---|
| 43 | + return 0; |
|---|
| 40 | 44 | |
|---|
| 41 | 45 | ops = kzalloc(sizeof(*ops), GFP_KERNEL); |
|---|
| 42 | 46 | if (!ops) |
|---|
| 43 | 47 | return -ENOMEM; |
|---|
| 44 | 48 | |
|---|
| 45 | | - /* Currently only the non stack verision is supported */ |
|---|
| 49 | + /* Currently only the non stack version is supported */ |
|---|
| 46 | 50 | ops->func = function_trace_call; |
|---|
| 47 | 51 | ops->flags = FTRACE_OPS_FL_RECURSION_SAFE | FTRACE_OPS_FL_PID; |
|---|
| 48 | 52 | |
|---|
| 49 | 53 | tr->ops = ops; |
|---|
| 50 | 54 | ops->private = tr; |
|---|
| 55 | + |
|---|
| 51 | 56 | return 0; |
|---|
| 52 | 57 | } |
|---|
| 53 | 58 | |
|---|
| 59 | +void ftrace_free_ftrace_ops(struct trace_array *tr) |
|---|
| 60 | +{ |
|---|
| 61 | + kfree(tr->ops); |
|---|
| 62 | + tr->ops = NULL; |
|---|
| 63 | +} |
|---|
| 54 | 64 | |
|---|
| 55 | 65 | int ftrace_create_function_files(struct trace_array *tr, |
|---|
| 56 | 66 | struct dentry *parent) |
|---|
| 57 | 67 | { |
|---|
| 58 | | - int ret; |
|---|
| 59 | | - |
|---|
| 60 | 68 | /* |
|---|
| 61 | 69 | * The top level array uses the "global_ops", and the files are |
|---|
| 62 | 70 | * created on boot up. |
|---|
| .. | .. |
|---|
| 64 | 72 | if (tr->flags & TRACE_ARRAY_FL_GLOBAL) |
|---|
| 65 | 73 | return 0; |
|---|
| 66 | 74 | |
|---|
| 67 | | - ret = allocate_ftrace_ops(tr); |
|---|
| 68 | | - if (ret) |
|---|
| 69 | | - return ret; |
|---|
| 75 | + if (!tr->ops) |
|---|
| 76 | + return -EINVAL; |
|---|
| 70 | 77 | |
|---|
| 71 | 78 | ftrace_create_filter_files(tr->ops, parent); |
|---|
| 72 | 79 | |
|---|
| .. | .. |
|---|
| 76 | 83 | void ftrace_destroy_function_files(struct trace_array *tr) |
|---|
| 77 | 84 | { |
|---|
| 78 | 85 | ftrace_destroy_filter_files(tr->ops); |
|---|
| 79 | | - kfree(tr->ops); |
|---|
| 80 | | - tr->ops = NULL; |
|---|
| 86 | + ftrace_free_ftrace_ops(tr); |
|---|
| 81 | 87 | } |
|---|
| 82 | 88 | |
|---|
| 83 | 89 | static int function_trace_init(struct trace_array *tr) |
|---|
| .. | .. |
|---|
| 101 | 107 | |
|---|
| 102 | 108 | ftrace_init_array_ops(tr, func); |
|---|
| 103 | 109 | |
|---|
| 104 | | - tr->trace_buffer.cpu = get_cpu(); |
|---|
| 110 | + tr->array_buffer.cpu = get_cpu(); |
|---|
| 105 | 111 | put_cpu(); |
|---|
| 106 | 112 | |
|---|
| 107 | 113 | tracing_start_cmdline_record(); |
|---|
| .. | .. |
|---|
| 118 | 124 | |
|---|
| 119 | 125 | static void function_trace_start(struct trace_array *tr) |
|---|
| 120 | 126 | { |
|---|
| 121 | | - tracing_reset_online_cpus(&tr->trace_buffer); |
|---|
| 127 | + tracing_reset_online_cpus(&tr->array_buffer); |
|---|
| 122 | 128 | } |
|---|
| 123 | 129 | |
|---|
| 124 | 130 | static void |
|---|
| .. | .. |
|---|
| 127 | 133 | { |
|---|
| 128 | 134 | struct trace_array *tr = op->private; |
|---|
| 129 | 135 | struct trace_array_cpu *data; |
|---|
| 130 | | - unsigned long flags; |
|---|
| 136 | + unsigned int trace_ctx; |
|---|
| 131 | 137 | int bit; |
|---|
| 132 | 138 | int cpu; |
|---|
| 133 | | - int pc; |
|---|
| 134 | 139 | |
|---|
| 135 | 140 | if (unlikely(!tr->function_enabled)) |
|---|
| 136 | 141 | return; |
|---|
| 137 | 142 | |
|---|
| 138 | | - pc = preempt_count(); |
|---|
| 143 | + trace_ctx = tracing_gen_ctx(); |
|---|
| 139 | 144 | preempt_disable_notrace(); |
|---|
| 140 | 145 | |
|---|
| 141 | 146 | bit = trace_test_and_set_recursion(TRACE_FTRACE_START); |
|---|
| .. | .. |
|---|
| 143 | 148 | goto out; |
|---|
| 144 | 149 | |
|---|
| 145 | 150 | cpu = smp_processor_id(); |
|---|
| 146 | | - data = per_cpu_ptr(tr->trace_buffer.data, cpu); |
|---|
| 147 | | - if (!atomic_read(&data->disabled)) { |
|---|
| 148 | | - local_save_flags(flags); |
|---|
| 149 | | - trace_function(tr, ip, parent_ip, flags, pc); |
|---|
| 150 | | - } |
|---|
| 151 | + data = per_cpu_ptr(tr->array_buffer.data, cpu); |
|---|
| 152 | + if (!atomic_read(&data->disabled)) |
|---|
| 153 | + trace_function(tr, ip, parent_ip, trace_ctx); |
|---|
| 154 | + |
|---|
| 151 | 155 | trace_clear_recursion(bit); |
|---|
| 152 | 156 | |
|---|
| 153 | 157 | out: |
|---|
| .. | .. |
|---|
| 181 | 185 | unsigned long flags; |
|---|
| 182 | 186 | long disabled; |
|---|
| 183 | 187 | int cpu; |
|---|
| 184 | | - int pc; |
|---|
| 188 | + unsigned int trace_ctx; |
|---|
| 185 | 189 | |
|---|
| 186 | 190 | if (unlikely(!tr->function_enabled)) |
|---|
| 187 | 191 | return; |
|---|
| .. | .. |
|---|
| 192 | 196 | */ |
|---|
| 193 | 197 | local_irq_save(flags); |
|---|
| 194 | 198 | cpu = raw_smp_processor_id(); |
|---|
| 195 | | - data = per_cpu_ptr(tr->trace_buffer.data, cpu); |
|---|
| 199 | + data = per_cpu_ptr(tr->array_buffer.data, cpu); |
|---|
| 196 | 200 | disabled = atomic_inc_return(&data->disabled); |
|---|
| 197 | 201 | |
|---|
| 198 | 202 | if (likely(disabled == 1)) { |
|---|
| 199 | | - pc = preempt_count(); |
|---|
| 200 | | - trace_function(tr, ip, parent_ip, flags, pc); |
|---|
| 201 | | - __trace_stack(tr, flags, STACK_SKIP, pc); |
|---|
| 203 | + trace_ctx = tracing_gen_ctx_flags(flags); |
|---|
| 204 | + trace_function(tr, ip, parent_ip, trace_ctx); |
|---|
| 205 | + __trace_stack(tr, trace_ctx, STACK_SKIP); |
|---|
| 202 | 206 | } |
|---|
| 203 | 207 | |
|---|
| 204 | 208 | atomic_dec(&data->disabled); |
|---|
| .. | .. |
|---|
| 401 | 405 | |
|---|
| 402 | 406 | static __always_inline void trace_stack(struct trace_array *tr) |
|---|
| 403 | 407 | { |
|---|
| 404 | | - unsigned long flags; |
|---|
| 405 | | - int pc; |
|---|
| 408 | + unsigned int trace_ctx; |
|---|
| 406 | 409 | |
|---|
| 407 | | - local_save_flags(flags); |
|---|
| 408 | | - pc = preempt_count(); |
|---|
| 410 | + trace_ctx = tracing_gen_ctx(); |
|---|
| 409 | 411 | |
|---|
| 410 | | - __trace_stack(tr, flags, FTRACE_STACK_SKIP, pc); |
|---|
| 412 | + __trace_stack(tr, trace_ctx, FTRACE_STACK_SKIP); |
|---|
| 411 | 413 | } |
|---|
| 412 | 414 | |
|---|
| 413 | 415 | static void |
|---|