License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-05-13 03:20:44 +08:00
|
|
|
/* Include in trace.c */
|
|
|
|
|
2017-02-02 01:07:51 +08:00
|
|
|
#include <uapi/linux/sched/types.h>
|
2009-03-10 04:00:22 +08:00
|
|
|
#include <linux/stringify.h>
|
2008-05-13 03:20:44 +08:00
|
|
|
#include <linux/kthread.h>
|
2008-05-13 03:20:45 +08:00
|
|
|
#include <linux/delay.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2008-05-13 03:20:44 +08:00
|
|
|
|
2008-05-13 03:20:51 +08:00
|
|
|
static inline int trace_valid_entry(struct trace_entry *entry)
|
2008-05-13 03:20:44 +08:00
|
|
|
{
|
|
|
|
switch (entry->type) {
|
|
|
|
case TRACE_FN:
|
|
|
|
case TRACE_CTX:
|
2008-05-13 03:20:51 +08:00
|
|
|
case TRACE_WAKE:
|
2008-05-13 03:20:54 +08:00
|
|
|
case TRACE_STACK:
|
2008-08-02 00:26:41 +08:00
|
|
|
case TRACE_PRINT:
|
2008-11-13 04:24:24 +08:00
|
|
|
case TRACE_BRANCH:
|
2009-02-08 04:33:57 +08:00
|
|
|
case TRACE_GRAPH_ENT:
|
|
|
|
case TRACE_GRAPH_RET:
|
2008-05-13 03:20:44 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-10 07:53:48 +08:00
|
|
|
static int trace_test_buffer_cpu(struct array_buffer *buf, int cpu)
|
2008-05-13 03:20:44 +08:00
|
|
|
{
|
2008-09-30 11:02:41 +08:00
|
|
|
struct ring_buffer_event *event;
|
|
|
|
struct trace_entry *entry;
|
2009-02-19 11:50:01 +08:00
|
|
|
unsigned int loops = 0;
|
2008-05-13 03:20:44 +08:00
|
|
|
|
tracing: Consolidate max_tr into main trace_array structure
Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.
The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.
This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.
The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-05 22:24:35 +08:00
|
|
|
while ((event = ring_buffer_consume(buf->buffer, cpu, NULL, NULL))) {
|
2008-09-30 11:02:41 +08:00
|
|
|
entry = ring_buffer_event_data(event);
|
2008-05-13 03:20:44 +08:00
|
|
|
|
2009-02-19 11:50:01 +08:00
|
|
|
/*
|
|
|
|
* The ring buffer is a size of trace_buf_size, if
|
|
|
|
* we loop more than the size, there's something wrong
|
|
|
|
* with the ring buffer.
|
|
|
|
*/
|
|
|
|
if (loops++ > trace_buf_size) {
|
|
|
|
printk(KERN_CONT ".. bad ring buffer ");
|
|
|
|
goto failed;
|
|
|
|
}
|
2008-09-30 11:02:41 +08:00
|
|
|
if (!trace_valid_entry(entry)) {
|
2008-05-13 03:20:45 +08:00
|
|
|
printk(KERN_CONT ".. invalid entry %d ",
|
2008-09-30 11:02:41 +08:00
|
|
|
entry->type);
|
2008-05-13 03:20:44 +08:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed:
|
2008-05-13 03:20:45 +08:00
|
|
|
/* disable tracing */
|
|
|
|
tracing_disabled = 1;
|
2008-05-13 03:20:44 +08:00
|
|
|
printk(KERN_CONT ".. corrupted trace buffer .. ");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test the trace buffer to see if all the elements
|
|
|
|
* are still sane.
|
|
|
|
*/
|
2020-01-10 07:53:48 +08:00
|
|
|
static int __maybe_unused trace_test_buffer(struct array_buffer *buf, unsigned long *count)
|
2008-05-13 03:20:44 +08:00
|
|
|
{
|
2008-05-13 03:20:56 +08:00
|
|
|
unsigned long flags, cnt = 0;
|
|
|
|
int cpu, ret = 0;
|
2008-05-13 03:20:44 +08:00
|
|
|
|
2008-05-13 03:20:56 +08:00
|
|
|
/* Don't allow flipping of max traces now */
|
2008-11-16 04:48:29 +08:00
|
|
|
local_irq_save(flags);
|
2014-01-14 23:04:59 +08:00
|
|
|
arch_spin_lock(&buf->tr->max_lock);
|
2008-05-13 03:20:44 +08:00
|
|
|
|
tracing: Consolidate max_tr into main trace_array structure
Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.
The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.
This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.
The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-05 22:24:35 +08:00
|
|
|
cnt = ring_buffer_entries(buf->buffer);
|
2008-05-13 03:20:44 +08:00
|
|
|
|
2009-02-19 07:33:57 +08:00
|
|
|
/*
|
|
|
|
* The trace_test_buffer_cpu runs a while loop to consume all data.
|
|
|
|
* If the calling tracer is broken, and is constantly filling
|
|
|
|
* the buffer, this will run forever, and hard lock the box.
|
|
|
|
* We disable the ring buffer while we do this test to prevent
|
|
|
|
* a hard lock up.
|
|
|
|
*/
|
|
|
|
tracing_off();
|
2008-09-30 11:02:41 +08:00
|
|
|
for_each_possible_cpu(cpu) {
|
tracing: Consolidate max_tr into main trace_array structure
Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.
The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.
This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.
The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-05 22:24:35 +08:00
|
|
|
ret = trace_test_buffer_cpu(buf, cpu);
|
2008-05-13 03:20:44 +08:00
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
2009-02-19 07:33:57 +08:00
|
|
|
tracing_on();
|
2014-01-14 23:04:59 +08:00
|
|
|
arch_spin_unlock(&buf->tr->max_lock);
|
2008-11-16 04:48:29 +08:00
|
|
|
local_irq_restore(flags);
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
if (count)
|
|
|
|
*count = cnt;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-16 12:57:26 +08:00
|
|
|
static inline void warn_failed_init_tracer(struct tracer *trace, int init_ret)
|
|
|
|
{
|
|
|
|
printk(KERN_WARNING "Failed to init %s tracer, init returned %d\n",
|
|
|
|
trace->name, init_ret);
|
|
|
|
}
|
2008-10-07 07:06:12 +08:00
|
|
|
#ifdef CONFIG_FUNCTION_TRACER
|
2008-05-13 03:20:45 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE
|
|
|
|
|
2011-05-06 12:08:51 +08:00
|
|
|
static int trace_selftest_test_probe1_cnt;
|
|
|
|
static void trace_selftest_test_probe1_func(unsigned long ip,
|
2011-08-09 04:57:47 +08:00
|
|
|
unsigned long pip,
|
2011-08-10 00:50:46 +08:00
|
|
|
struct ftrace_ops *op,
|
2020-10-29 05:42:17 +08:00
|
|
|
struct ftrace_regs *fregs)
|
2011-05-06 12:08:51 +08:00
|
|
|
{
|
|
|
|
trace_selftest_test_probe1_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int trace_selftest_test_probe2_cnt;
|
|
|
|
static void trace_selftest_test_probe2_func(unsigned long ip,
|
2011-08-09 04:57:47 +08:00
|
|
|
unsigned long pip,
|
2011-08-10 00:50:46 +08:00
|
|
|
struct ftrace_ops *op,
|
2020-10-29 05:42:17 +08:00
|
|
|
struct ftrace_regs *fregs)
|
2011-05-06 12:08:51 +08:00
|
|
|
{
|
|
|
|
trace_selftest_test_probe2_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int trace_selftest_test_probe3_cnt;
|
|
|
|
static void trace_selftest_test_probe3_func(unsigned long ip,
|
2011-08-09 04:57:47 +08:00
|
|
|
unsigned long pip,
|
2011-08-10 00:50:46 +08:00
|
|
|
struct ftrace_ops *op,
|
2020-10-29 05:42:17 +08:00
|
|
|
struct ftrace_regs *fregs)
|
2011-05-06 12:08:51 +08:00
|
|
|
{
|
|
|
|
trace_selftest_test_probe3_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int trace_selftest_test_global_cnt;
|
|
|
|
static void trace_selftest_test_global_func(unsigned long ip,
|
2011-08-09 04:57:47 +08:00
|
|
|
unsigned long pip,
|
2011-08-10 00:50:46 +08:00
|
|
|
struct ftrace_ops *op,
|
2020-10-29 05:42:17 +08:00
|
|
|
struct ftrace_regs *fregs)
|
2011-05-06 12:08:51 +08:00
|
|
|
{
|
|
|
|
trace_selftest_test_global_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int trace_selftest_test_dyn_cnt;
|
|
|
|
static void trace_selftest_test_dyn_func(unsigned long ip,
|
2011-08-09 04:57:47 +08:00
|
|
|
unsigned long pip,
|
2011-08-10 00:50:46 +08:00
|
|
|
struct ftrace_ops *op,
|
2020-10-29 05:42:17 +08:00
|
|
|
struct ftrace_regs *fregs)
|
2011-05-06 12:08:51 +08:00
|
|
|
{
|
|
|
|
trace_selftest_test_dyn_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ftrace_ops test_probe1 = {
|
|
|
|
.func = trace_selftest_test_probe1_func,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct ftrace_ops test_probe2 = {
|
|
|
|
.func = trace_selftest_test_probe2_func,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct ftrace_ops test_probe3 = {
|
|
|
|
.func = trace_selftest_test_probe3_func,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void print_counts(void)
|
|
|
|
{
|
|
|
|
printk("(%d %d %d %d %d) ",
|
|
|
|
trace_selftest_test_probe1_cnt,
|
|
|
|
trace_selftest_test_probe2_cnt,
|
|
|
|
trace_selftest_test_probe3_cnt,
|
|
|
|
trace_selftest_test_global_cnt,
|
|
|
|
trace_selftest_test_dyn_cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reset_counts(void)
|
|
|
|
{
|
|
|
|
trace_selftest_test_probe1_cnt = 0;
|
|
|
|
trace_selftest_test_probe2_cnt = 0;
|
|
|
|
trace_selftest_test_probe3_cnt = 0;
|
|
|
|
trace_selftest_test_global_cnt = 0;
|
|
|
|
trace_selftest_test_dyn_cnt = 0;
|
|
|
|
}
|
|
|
|
|
2014-01-11 06:01:58 +08:00
|
|
|
static int trace_selftest_ops(struct trace_array *tr, int cnt)
|
2011-05-06 12:08:51 +08:00
|
|
|
{
|
|
|
|
int save_ftrace_enabled = ftrace_enabled;
|
|
|
|
struct ftrace_ops *dyn_ops;
|
|
|
|
char *func1_name;
|
|
|
|
char *func2_name;
|
|
|
|
int len1;
|
|
|
|
int len2;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
printk(KERN_CONT "PASSED\n");
|
|
|
|
pr_info("Testing dynamic ftrace ops #%d: ", cnt);
|
|
|
|
|
|
|
|
ftrace_enabled = 1;
|
|
|
|
reset_counts();
|
|
|
|
|
|
|
|
/* Handle PPC64 '.' name */
|
|
|
|
func1_name = "*" __stringify(DYN_FTRACE_TEST_NAME);
|
|
|
|
func2_name = "*" __stringify(DYN_FTRACE_TEST_NAME2);
|
|
|
|
len1 = strlen(func1_name);
|
|
|
|
len2 = strlen(func2_name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe 1 will trace function 1.
|
|
|
|
* Probe 2 will trace function 2.
|
|
|
|
* Probe 3 will trace functions 1 and 2.
|
|
|
|
*/
|
|
|
|
ftrace_set_filter(&test_probe1, func1_name, len1, 1);
|
|
|
|
ftrace_set_filter(&test_probe2, func2_name, len2, 1);
|
|
|
|
ftrace_set_filter(&test_probe3, func1_name, len1, 1);
|
|
|
|
ftrace_set_filter(&test_probe3, func2_name, len2, 0);
|
|
|
|
|
|
|
|
register_ftrace_function(&test_probe1);
|
|
|
|
register_ftrace_function(&test_probe2);
|
|
|
|
register_ftrace_function(&test_probe3);
|
2014-01-11 06:01:58 +08:00
|
|
|
/* First time we are running with main function */
|
|
|
|
if (cnt > 1) {
|
|
|
|
ftrace_init_array_ops(tr, trace_selftest_test_global_func);
|
|
|
|
register_ftrace_function(tr->ops);
|
|
|
|
}
|
2011-05-06 12:08:51 +08:00
|
|
|
|
|
|
|
DYN_FTRACE_TEST_NAME();
|
|
|
|
|
|
|
|
print_counts();
|
|
|
|
|
|
|
|
if (trace_selftest_test_probe1_cnt != 1)
|
|
|
|
goto out;
|
|
|
|
if (trace_selftest_test_probe2_cnt != 0)
|
|
|
|
goto out;
|
|
|
|
if (trace_selftest_test_probe3_cnt != 1)
|
|
|
|
goto out;
|
2014-01-11 06:01:58 +08:00
|
|
|
if (cnt > 1) {
|
|
|
|
if (trace_selftest_test_global_cnt == 0)
|
|
|
|
goto out;
|
|
|
|
}
|
2011-05-06 12:08:51 +08:00
|
|
|
|
|
|
|
DYN_FTRACE_TEST_NAME2();
|
|
|
|
|
|
|
|
print_counts();
|
|
|
|
|
|
|
|
if (trace_selftest_test_probe1_cnt != 1)
|
|
|
|
goto out;
|
|
|
|
if (trace_selftest_test_probe2_cnt != 1)
|
|
|
|
goto out;
|
|
|
|
if (trace_selftest_test_probe3_cnt != 2)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Add a dynamic probe */
|
|
|
|
dyn_ops = kzalloc(sizeof(*dyn_ops), GFP_KERNEL);
|
|
|
|
if (!dyn_ops) {
|
|
|
|
printk("MEMORY ERROR ");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
dyn_ops->func = trace_selftest_test_dyn_func;
|
|
|
|
|
|
|
|
register_ftrace_function(dyn_ops);
|
|
|
|
|
|
|
|
trace_selftest_test_global_cnt = 0;
|
|
|
|
|
|
|
|
DYN_FTRACE_TEST_NAME();
|
|
|
|
|
|
|
|
print_counts();
|
|
|
|
|
|
|
|
if (trace_selftest_test_probe1_cnt != 2)
|
|
|
|
goto out_free;
|
|
|
|
if (trace_selftest_test_probe2_cnt != 1)
|
|
|
|
goto out_free;
|
|
|
|
if (trace_selftest_test_probe3_cnt != 3)
|
|
|
|
goto out_free;
|
2014-01-11 06:01:58 +08:00
|
|
|
if (cnt > 1) {
|
|
|
|
if (trace_selftest_test_global_cnt == 0)
|
2017-09-02 00:04:09 +08:00
|
|
|
goto out_free;
|
2014-01-11 06:01:58 +08:00
|
|
|
}
|
2011-05-06 12:08:51 +08:00
|
|
|
if (trace_selftest_test_dyn_cnt == 0)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
DYN_FTRACE_TEST_NAME2();
|
|
|
|
|
|
|
|
print_counts();
|
|
|
|
|
|
|
|
if (trace_selftest_test_probe1_cnt != 2)
|
|
|
|
goto out_free;
|
|
|
|
if (trace_selftest_test_probe2_cnt != 2)
|
|
|
|
goto out_free;
|
|
|
|
if (trace_selftest_test_probe3_cnt != 4)
|
|
|
|
goto out_free;
|
|
|
|
|
2021-09-18 23:30:43 +08:00
|
|
|
/* Remove trace function from probe 3 */
|
|
|
|
func1_name = "!" __stringify(DYN_FTRACE_TEST_NAME);
|
|
|
|
len1 = strlen(func1_name);
|
|
|
|
|
|
|
|
ftrace_set_filter(&test_probe3, func1_name, len1, 0);
|
|
|
|
|
|
|
|
DYN_FTRACE_TEST_NAME();
|
|
|
|
|
|
|
|
print_counts();
|
|
|
|
|
|
|
|
if (trace_selftest_test_probe1_cnt != 3)
|
|
|
|
goto out_free;
|
|
|
|
if (trace_selftest_test_probe2_cnt != 2)
|
|
|
|
goto out_free;
|
|
|
|
if (trace_selftest_test_probe3_cnt != 4)
|
|
|
|
goto out_free;
|
|
|
|
if (cnt > 1) {
|
|
|
|
if (trace_selftest_test_global_cnt == 0)
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (trace_selftest_test_dyn_cnt == 0)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
DYN_FTRACE_TEST_NAME2();
|
|
|
|
|
|
|
|
print_counts();
|
|
|
|
|
|
|
|
if (trace_selftest_test_probe1_cnt != 3)
|
|
|
|
goto out_free;
|
|
|
|
if (trace_selftest_test_probe2_cnt != 3)
|
|
|
|
goto out_free;
|
|
|
|
if (trace_selftest_test_probe3_cnt != 5)
|
|
|
|
goto out_free;
|
|
|
|
|
2011-05-06 12:08:51 +08:00
|
|
|
ret = 0;
|
|
|
|
out_free:
|
|
|
|
unregister_ftrace_function(dyn_ops);
|
|
|
|
kfree(dyn_ops);
|
|
|
|
|
|
|
|
out:
|
|
|
|
/* Purposely unregister in the same order */
|
|
|
|
unregister_ftrace_function(&test_probe1);
|
|
|
|
unregister_ftrace_function(&test_probe2);
|
|
|
|
unregister_ftrace_function(&test_probe3);
|
2014-01-11 06:01:58 +08:00
|
|
|
if (cnt > 1)
|
|
|
|
unregister_ftrace_function(tr->ops);
|
|
|
|
ftrace_reset_array_ops(tr);
|
2011-05-06 12:08:51 +08:00
|
|
|
|
|
|
|
/* Make sure everything is off */
|
|
|
|
reset_counts();
|
|
|
|
DYN_FTRACE_TEST_NAME();
|
|
|
|
DYN_FTRACE_TEST_NAME();
|
|
|
|
|
|
|
|
if (trace_selftest_test_probe1_cnt ||
|
|
|
|
trace_selftest_test_probe2_cnt ||
|
|
|
|
trace_selftest_test_probe3_cnt ||
|
|
|
|
trace_selftest_test_global_cnt ||
|
|
|
|
trace_selftest_test_dyn_cnt)
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
ftrace_enabled = save_ftrace_enabled;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-05-13 03:20:45 +08:00
|
|
|
/* Test dynamic code modification and ftrace filters */
|
2014-04-18 03:44:42 +08:00
|
|
|
static int trace_selftest_startup_dynamic_tracing(struct tracer *trace,
|
|
|
|
struct trace_array *tr,
|
|
|
|
int (*func)(void))
|
2008-05-13 03:20:45 +08:00
|
|
|
{
|
|
|
|
int save_ftrace_enabled = ftrace_enabled;
|
2008-08-02 00:26:41 +08:00
|
|
|
unsigned long count;
|
2008-05-15 11:49:44 +08:00
|
|
|
char *func_name;
|
2008-08-02 00:26:41 +08:00
|
|
|
int ret;
|
2008-05-13 03:20:45 +08:00
|
|
|
|
|
|
|
/* The ftrace test PASSED */
|
|
|
|
printk(KERN_CONT "PASSED\n");
|
|
|
|
pr_info("Testing dynamic ftrace: ");
|
|
|
|
|
|
|
|
/* enable tracing, and record the filter function */
|
|
|
|
ftrace_enabled = 1;
|
|
|
|
|
|
|
|
/* passed in by parameter to fool gcc from optimizing */
|
|
|
|
func();
|
|
|
|
|
2008-05-15 11:49:44 +08:00
|
|
|
/*
|
2009-02-17 14:10:02 +08:00
|
|
|
* Some archs *cough*PowerPC*cough* add characters to the
|
2008-05-15 11:49:44 +08:00
|
|
|
* start of the function names. We simply put a '*' to
|
2009-02-17 14:10:02 +08:00
|
|
|
* accommodate them.
|
2008-05-15 11:49:44 +08:00
|
|
|
*/
|
2009-03-10 04:00:22 +08:00
|
|
|
func_name = "*" __stringify(DYN_FTRACE_TEST_NAME);
|
2008-05-15 11:49:44 +08:00
|
|
|
|
2008-05-13 03:20:45 +08:00
|
|
|
/* filter only on our function */
|
2011-05-06 10:54:01 +08:00
|
|
|
ftrace_set_global_filter(func_name, strlen(func_name), 1);
|
2008-05-13 03:20:45 +08:00
|
|
|
|
|
|
|
/* enable tracing */
|
2009-02-06 04:02:00 +08:00
|
|
|
ret = tracer_init(trace, tr);
|
2008-11-16 12:57:26 +08:00
|
|
|
if (ret) {
|
|
|
|
warn_failed_init_tracer(trace, ret);
|
|
|
|
goto out;
|
|
|
|
}
|
2008-08-02 00:26:41 +08:00
|
|
|
|
2008-05-13 03:20:45 +08:00
|
|
|
/* Sleep for a 1/10 of a second */
|
|
|
|
msleep(100);
|
|
|
|
|
|
|
|
/* we should have nothing in the buffer */
|
2020-01-10 07:53:48 +08:00
|
|
|
ret = trace_test_buffer(&tr->array_buffer, &count);
|
2008-05-13 03:20:45 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
ret = -1;
|
|
|
|
printk(KERN_CONT ".. filter did not filter .. ");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* call our function again */
|
|
|
|
func();
|
|
|
|
|
|
|
|
/* sleep again */
|
|
|
|
msleep(100);
|
|
|
|
|
|
|
|
/* stop the tracing. */
|
2008-11-08 11:36:02 +08:00
|
|
|
tracing_stop();
|
2008-05-13 03:20:45 +08:00
|
|
|
ftrace_enabled = 0;
|
|
|
|
|
|
|
|
/* check the trace buffer */
|
2020-01-10 07:53:48 +08:00
|
|
|
ret = trace_test_buffer(&tr->array_buffer, &count);
|
2014-09-13 02:26:51 +08:00
|
|
|
|
|
|
|
ftrace_enabled = 1;
|
2008-11-08 11:36:02 +08:00
|
|
|
tracing_start();
|
2008-05-13 03:20:45 +08:00
|
|
|
|
|
|
|
/* we should only have one item */
|
|
|
|
if (!ret && count != 1) {
|
2011-05-06 12:08:51 +08:00
|
|
|
trace->reset(tr);
|
2008-05-13 03:20:54 +08:00
|
|
|
printk(KERN_CONT ".. filter failed count=%ld ..", count);
|
2008-05-13 03:20:45 +08:00
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
2008-11-08 11:36:02 +08:00
|
|
|
|
2011-05-06 12:08:51 +08:00
|
|
|
/* Test the ops with global tracing running */
|
2014-01-11 06:01:58 +08:00
|
|
|
ret = trace_selftest_ops(tr, 1);
|
2011-05-06 12:08:51 +08:00
|
|
|
trace->reset(tr);
|
|
|
|
|
2008-05-13 03:20:45 +08:00
|
|
|
out:
|
|
|
|
ftrace_enabled = save_ftrace_enabled;
|
|
|
|
|
|
|
|
/* Enable tracing on all functions again */
|
2011-05-06 10:54:01 +08:00
|
|
|
ftrace_set_global_filter(NULL, 0, 1);
|
2008-05-13 03:20:45 +08:00
|
|
|
|
2011-05-06 12:08:51 +08:00
|
|
|
/* Test the ops with global tracing off */
|
|
|
|
if (!ret)
|
2014-01-11 06:01:58 +08:00
|
|
|
ret = trace_selftest_ops(tr, 2);
|
2011-05-06 12:08:51 +08:00
|
|
|
|
2008-05-13 03:20:45 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2012-07-21 01:08:05 +08:00
|
|
|
|
|
|
|
static int trace_selftest_recursion_cnt;
|
|
|
|
static void trace_selftest_test_recursion_func(unsigned long ip,
|
|
|
|
unsigned long pip,
|
|
|
|
struct ftrace_ops *op,
|
2020-10-29 05:42:17 +08:00
|
|
|
struct ftrace_regs *fregs)
|
2012-07-21 01:08:05 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This function is registered without the recursion safe flag.
|
|
|
|
* The ftrace infrastructure should provide the recursion
|
|
|
|
* protection. If not, this will crash the kernel!
|
|
|
|
*/
|
2012-11-03 05:01:20 +08:00
|
|
|
if (trace_selftest_recursion_cnt++ > 10)
|
|
|
|
return;
|
2012-07-21 01:08:05 +08:00
|
|
|
DYN_FTRACE_TEST_NAME();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void trace_selftest_test_recursion_safe_func(unsigned long ip,
|
|
|
|
unsigned long pip,
|
|
|
|
struct ftrace_ops *op,
|
2020-10-29 05:42:17 +08:00
|
|
|
struct ftrace_regs *fregs)
|
2012-07-21 01:08:05 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We said we would provide our own recursion. By calling
|
|
|
|
* this function again, we should recurse back into this function
|
|
|
|
* and count again. But this only happens if the arch supports
|
|
|
|
* all of ftrace features and nothing else is using the function
|
|
|
|
* tracing utility.
|
|
|
|
*/
|
|
|
|
if (trace_selftest_recursion_cnt++)
|
|
|
|
return;
|
|
|
|
DYN_FTRACE_TEST_NAME();
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ftrace_ops test_rec_probe = {
|
|
|
|
.func = trace_selftest_test_recursion_func,
|
2020-11-06 10:32:45 +08:00
|
|
|
.flags = FTRACE_OPS_FL_RECURSION,
|
2012-07-21 01:08:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct ftrace_ops test_recsafe_probe = {
|
|
|
|
.func = trace_selftest_test_recursion_safe_func,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
trace_selftest_function_recursion(void)
|
|
|
|
{
|
|
|
|
int save_ftrace_enabled = ftrace_enabled;
|
|
|
|
char *func_name;
|
|
|
|
int len;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* The previous test PASSED */
|
|
|
|
pr_cont("PASSED\n");
|
|
|
|
pr_info("Testing ftrace recursion: ");
|
|
|
|
|
|
|
|
|
|
|
|
/* enable tracing, and record the filter function */
|
|
|
|
ftrace_enabled = 1;
|
|
|
|
|
|
|
|
/* Handle PPC64 '.' name */
|
|
|
|
func_name = "*" __stringify(DYN_FTRACE_TEST_NAME);
|
|
|
|
len = strlen(func_name);
|
|
|
|
|
|
|
|
ret = ftrace_set_filter(&test_rec_probe, func_name, len, 1);
|
|
|
|
if (ret) {
|
|
|
|
pr_cont("*Could not set filter* ");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = register_ftrace_function(&test_rec_probe);
|
|
|
|
if (ret) {
|
|
|
|
pr_cont("*could not register callback* ");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
DYN_FTRACE_TEST_NAME();
|
|
|
|
|
|
|
|
unregister_ftrace_function(&test_rec_probe);
|
|
|
|
|
|
|
|
ret = -1;
|
2020-10-30 07:35:08 +08:00
|
|
|
/*
|
|
|
|
* Recursion allows for transitions between context,
|
|
|
|
* and may call the callback twice.
|
|
|
|
*/
|
|
|
|
if (trace_selftest_recursion_cnt != 1 &&
|
|
|
|
trace_selftest_recursion_cnt != 2) {
|
|
|
|
pr_cont("*callback not called once (or twice) (%d)* ",
|
2012-07-21 01:08:05 +08:00
|
|
|
trace_selftest_recursion_cnt);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_selftest_recursion_cnt = 1;
|
|
|
|
|
|
|
|
pr_cont("PASSED\n");
|
|
|
|
pr_info("Testing ftrace recursion safe: ");
|
|
|
|
|
|
|
|
ret = ftrace_set_filter(&test_recsafe_probe, func_name, len, 1);
|
|
|
|
if (ret) {
|
|
|
|
pr_cont("*Could not set filter* ");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = register_ftrace_function(&test_recsafe_probe);
|
|
|
|
if (ret) {
|
|
|
|
pr_cont("*could not register callback* ");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
DYN_FTRACE_TEST_NAME();
|
|
|
|
|
|
|
|
unregister_ftrace_function(&test_recsafe_probe);
|
|
|
|
|
|
|
|
ret = -1;
|
2013-01-23 12:35:11 +08:00
|
|
|
if (trace_selftest_recursion_cnt != 2) {
|
|
|
|
pr_cont("*callback not called expected 2 times (%d)* ",
|
|
|
|
trace_selftest_recursion_cnt);
|
2012-07-21 01:08:05 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
ftrace_enabled = save_ftrace_enabled;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2008-05-13 03:20:45 +08:00
|
|
|
#else
|
|
|
|
# define trace_selftest_startup_dynamic_tracing(trace, tr, func) ({ 0; })
|
2012-07-21 01:08:05 +08:00
|
|
|
# define trace_selftest_function_recursion() ({ 0; })
|
2008-05-13 03:20:45 +08:00
|
|
|
#endif /* CONFIG_DYNAMIC_FTRACE */
|
2009-03-13 18:54:40 +08:00
|
|
|
|
2012-07-21 01:45:59 +08:00
|
|
|
static enum {
|
|
|
|
TRACE_SELFTEST_REGS_START,
|
|
|
|
TRACE_SELFTEST_REGS_FOUND,
|
|
|
|
TRACE_SELFTEST_REGS_NOT_FOUND,
|
|
|
|
} trace_selftest_regs_stat;
|
|
|
|
|
|
|
|
static void trace_selftest_test_regs_func(unsigned long ip,
|
|
|
|
unsigned long pip,
|
|
|
|
struct ftrace_ops *op,
|
2020-10-29 05:42:17 +08:00
|
|
|
struct ftrace_regs *fregs)
|
2012-07-21 01:45:59 +08:00
|
|
|
{
|
2020-10-29 05:42:17 +08:00
|
|
|
struct pt_regs *regs = ftrace_get_regs(fregs);
|
|
|
|
|
|
|
|
if (regs)
|
2012-07-21 01:45:59 +08:00
|
|
|
trace_selftest_regs_stat = TRACE_SELFTEST_REGS_FOUND;
|
|
|
|
else
|
|
|
|
trace_selftest_regs_stat = TRACE_SELFTEST_REGS_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ftrace_ops test_regs_probe = {
|
|
|
|
.func = trace_selftest_test_regs_func,
|
2020-11-06 10:32:45 +08:00
|
|
|
.flags = FTRACE_OPS_FL_SAVE_REGS,
|
2012-07-21 01:45:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
trace_selftest_function_regs(void)
|
|
|
|
{
|
|
|
|
int save_ftrace_enabled = ftrace_enabled;
|
|
|
|
char *func_name;
|
|
|
|
int len;
|
|
|
|
int ret;
|
|
|
|
int supported = 0;
|
|
|
|
|
2012-09-28 16:15:17 +08:00
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
|
2012-07-21 01:45:59 +08:00
|
|
|
supported = 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The previous test PASSED */
|
|
|
|
pr_cont("PASSED\n");
|
|
|
|
pr_info("Testing ftrace regs%s: ",
|
|
|
|
!supported ? "(no arch support)" : "");
|
|
|
|
|
|
|
|
/* enable tracing, and record the filter function */
|
|
|
|
ftrace_enabled = 1;
|
|
|
|
|
|
|
|
/* Handle PPC64 '.' name */
|
|
|
|
func_name = "*" __stringify(DYN_FTRACE_TEST_NAME);
|
|
|
|
len = strlen(func_name);
|
|
|
|
|
|
|
|
ret = ftrace_set_filter(&test_regs_probe, func_name, len, 1);
|
|
|
|
/*
|
|
|
|
* If DYNAMIC_FTRACE is not set, then we just trace all functions.
|
|
|
|
* This test really doesn't care.
|
|
|
|
*/
|
|
|
|
if (ret && ret != -ENODEV) {
|
|
|
|
pr_cont("*Could not set filter* ");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = register_ftrace_function(&test_regs_probe);
|
|
|
|
/*
|
|
|
|
* Now if the arch does not support passing regs, then this should
|
|
|
|
* have failed.
|
|
|
|
*/
|
|
|
|
if (!supported) {
|
|
|
|
if (!ret) {
|
|
|
|
pr_cont("*registered save-regs without arch support* ");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
test_regs_probe.flags |= FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED;
|
|
|
|
ret = register_ftrace_function(&test_regs_probe);
|
|
|
|
}
|
|
|
|
if (ret) {
|
|
|
|
pr_cont("*could not register callback* ");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DYN_FTRACE_TEST_NAME();
|
|
|
|
|
|
|
|
unregister_ftrace_function(&test_regs_probe);
|
|
|
|
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
switch (trace_selftest_regs_stat) {
|
|
|
|
case TRACE_SELFTEST_REGS_START:
|
|
|
|
pr_cont("*callback never called* ");
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
case TRACE_SELFTEST_REGS_FOUND:
|
|
|
|
if (supported)
|
|
|
|
break;
|
|
|
|
pr_cont("*callback received regs without arch support* ");
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
case TRACE_SELFTEST_REGS_NOT_FOUND:
|
|
|
|
if (!supported)
|
|
|
|
break;
|
|
|
|
pr_cont("*callback received NULL regs* ");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
ftrace_enabled = save_ftrace_enabled;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
/*
|
|
|
|
* Simple verification test of ftrace function tracer.
|
|
|
|
* Enable ftrace, sleep 1/10 second, and then read the trace
|
|
|
|
* buffer to see if all is in order.
|
|
|
|
*/
|
2013-06-28 10:18:06 +08:00
|
|
|
__init int
|
2008-05-13 03:20:44 +08:00
|
|
|
trace_selftest_startup_function(struct tracer *trace, struct trace_array *tr)
|
|
|
|
{
|
2008-05-13 03:20:45 +08:00
|
|
|
int save_ftrace_enabled = ftrace_enabled;
|
2008-08-02 00:26:41 +08:00
|
|
|
unsigned long count;
|
|
|
|
int ret;
|
2008-05-13 03:20:44 +08:00
|
|
|
|
2013-06-28 10:18:06 +08:00
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE
|
|
|
|
if (ftrace_filter_param) {
|
|
|
|
printk(KERN_CONT " ... kernel command line filter set: force PASS ... ");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-05-13 03:20:45 +08:00
|
|
|
/* make sure msleep has been recorded */
|
|
|
|
msleep(1);
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
/* start the tracing */
|
2008-05-13 03:20:45 +08:00
|
|
|
ftrace_enabled = 1;
|
|
|
|
|
2009-02-06 04:02:00 +08:00
|
|
|
ret = tracer_init(trace, tr);
|
2008-11-16 12:57:26 +08:00
|
|
|
if (ret) {
|
|
|
|
warn_failed_init_tracer(trace, ret);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
/* Sleep for a 1/10 of a second */
|
|
|
|
msleep(100);
|
|
|
|
/* stop the tracing. */
|
2008-11-08 11:36:02 +08:00
|
|
|
tracing_stop();
|
2008-05-13 03:20:45 +08:00
|
|
|
ftrace_enabled = 0;
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
/* check the trace buffer */
|
2020-01-10 07:53:48 +08:00
|
|
|
ret = trace_test_buffer(&tr->array_buffer, &count);
|
2014-09-13 02:26:51 +08:00
|
|
|
|
|
|
|
ftrace_enabled = 1;
|
2008-05-13 03:20:44 +08:00
|
|
|
trace->reset(tr);
|
2008-11-08 11:36:02 +08:00
|
|
|
tracing_start();
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
if (!ret && !count) {
|
|
|
|
printk(KERN_CONT ".. no entries found ..");
|
|
|
|
ret = -1;
|
2008-05-13 03:20:45 +08:00
|
|
|
goto out;
|
2008-05-13 03:20:44 +08:00
|
|
|
}
|
|
|
|
|
2008-05-13 03:20:45 +08:00
|
|
|
ret = trace_selftest_startup_dynamic_tracing(trace, tr,
|
|
|
|
DYN_FTRACE_TEST_NAME);
|
2012-07-21 01:08:05 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
2008-05-13 03:20:45 +08:00
|
|
|
|
2012-07-21 01:08:05 +08:00
|
|
|
ret = trace_selftest_function_recursion();
|
2012-07-21 01:45:59 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = trace_selftest_function_regs();
|
2008-05-13 03:20:45 +08:00
|
|
|
out:
|
|
|
|
ftrace_enabled = save_ftrace_enabled;
|
|
|
|
|
2008-05-13 03:20:48 +08:00
|
|
|
/* kill ftrace totally if we failed */
|
|
|
|
if (ret)
|
|
|
|
ftrace_kill();
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2008-10-07 07:06:12 +08:00
|
|
|
#endif /* CONFIG_FUNCTION_TRACER */
|
2008-05-13 03:20:44 +08:00
|
|
|
|
2009-02-08 04:33:57 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
|
2009-03-22 12:04:35 +08:00
|
|
|
|
|
|
|
/* Maximum number of functions to trace before diagnosing a hang */
|
|
|
|
#define GRAPH_MAX_FUNC_TEST 100000000
|
|
|
|
|
|
|
|
static unsigned int graph_hang_thresh;
|
|
|
|
|
|
|
|
/* Wrap the real function entry probe to avoid possible hanging */
|
|
|
|
static int trace_graph_entry_watchdog(struct ftrace_graph_ent *trace)
|
|
|
|
{
|
|
|
|
/* This is harmlessly racy, we want to approximately detect a hang */
|
|
|
|
if (unlikely(++graph_hang_thresh > GRAPH_MAX_FUNC_TEST)) {
|
|
|
|
ftrace_graph_stop();
|
|
|
|
printk(KERN_WARNING "BUG: Function graph tracer hang!\n");
|
tracing: Fix ftrace_dump()
ftrace_dump() had a lot of issues. What ftrace_dump() does, is when
ftrace_dump_on_oops is set (via a kernel parameter or sysctl), it
will dump out the ftrace buffers to the console when either a oops,
panic, or a sysrq-z occurs.
This was written a long time ago when ftrace was fragile to recursion.
But it wasn't written well even for that.
There's a possible deadlock that can occur if a ftrace_dump() is happening
and an NMI triggers another dump. This is because it grabs a lock
before checking if the dump ran.
It also totally disables ftrace, and tracing for no good reasons.
As the ring_buffer now checks if it is read via a oops or NMI, where
there's a chance that the buffer gets corrupted, it will disable
itself. No need to have ftrace_dump() do the same.
ftrace_dump() is now cleaned up where it uses an atomic counter to
make sure only one dump happens at a time. A simple atomic_inc_return()
is enough that is needed for both other CPUs and NMIs. No need for
a spinlock, as if one CPU is running the dump, no other CPU needs
to do it too.
The tracing_on variable is turned off and not turned on. The original
code did this, but it wasn't pretty. By just disabling this variable
we get the result of not seeing traces that happen between crashes.
For sysrq-z, it doesn't get turned on, but the user can always write
a '1' to the tracing_on file. If they are using sysrq-z, then they should
know about tracing_on.
The new code is much easier to read and less error prone. No more
deadlock possibility when an NMI triggers here.
Reported-by: zhangwei(Jovi) <jovi.zhangwei@huawei.com>
Cc: stable@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-16 01:10:35 +08:00
|
|
|
if (ftrace_dump_on_oops) {
|
|
|
|
ftrace_dump(DUMP_ALL);
|
|
|
|
/* ftrace_dump() disables tracing */
|
|
|
|
tracing_on();
|
|
|
|
}
|
2009-03-22 12:04:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return trace_graph_entry(trace);
|
|
|
|
}
|
|
|
|
|
2018-11-16 03:06:47 +08:00
|
|
|
static struct fgraph_ops fgraph_ops __initdata = {
|
|
|
|
.entryfunc = &trace_graph_entry_watchdog,
|
|
|
|
.retfunc = &trace_graph_return,
|
|
|
|
};
|
|
|
|
|
2021-12-21 00:38:06 +08:00
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
|
2021-10-08 17:13:32 +08:00
|
|
|
noinline __noclone static void trace_direct_tramp(void) { }
|
2021-10-22 01:43:57 +08:00
|
|
|
#endif
|
2021-10-08 17:13:32 +08:00
|
|
|
|
2009-02-08 04:33:57 +08:00
|
|
|
/*
|
|
|
|
* Pretty much the same than for the function tracer from which the selftest
|
|
|
|
* has been borrowed.
|
|
|
|
*/
|
2013-06-28 10:18:06 +08:00
|
|
|
__init int
|
2009-02-08 04:33:57 +08:00
|
|
|
trace_selftest_startup_function_graph(struct tracer *trace,
|
|
|
|
struct trace_array *tr)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned long count;
|
2021-10-08 17:13:32 +08:00
|
|
|
char *func_name __maybe_unused;
|
2009-02-08 04:33:57 +08:00
|
|
|
|
2013-06-28 10:18:06 +08:00
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE
|
|
|
|
if (ftrace_filter_param) {
|
|
|
|
printk(KERN_CONT " ... kernel command line filter set: force PASS ... ");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-03-22 12:04:35 +08:00
|
|
|
/*
|
|
|
|
* Simulate the init() callback but we attach a watchdog callback
|
|
|
|
* to detect and recover from possible hangs
|
|
|
|
*/
|
2020-01-10 07:53:48 +08:00
|
|
|
tracing_reset_online_cpus(&tr->array_buffer);
|
2009-07-30 00:59:58 +08:00
|
|
|
set_graph_array(tr);
|
2018-11-16 03:06:47 +08:00
|
|
|
ret = register_ftrace_graph(&fgraph_ops);
|
2009-02-08 04:33:57 +08:00
|
|
|
if (ret) {
|
|
|
|
warn_failed_init_tracer(trace, ret);
|
|
|
|
goto out;
|
|
|
|
}
|
2009-03-22 12:04:35 +08:00
|
|
|
tracing_start_cmdline_record();
|
2009-02-08 04:33:57 +08:00
|
|
|
|
|
|
|
/* Sleep for a 1/10 of a second */
|
|
|
|
msleep(100);
|
|
|
|
|
2009-03-22 12:04:35 +08:00
|
|
|
/* Have we just recovered from a hang? */
|
|
|
|
if (graph_hang_thresh > GRAPH_MAX_FUNC_TEST) {
|
2020-12-08 16:54:09 +08:00
|
|
|
disable_tracing_selftest("recovering from a hang");
|
2009-03-22 12:04:35 +08:00
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-02-08 04:33:57 +08:00
|
|
|
tracing_stop();
|
|
|
|
|
|
|
|
/* check the trace buffer */
|
2020-01-10 07:53:48 +08:00
|
|
|
ret = trace_test_buffer(&tr->array_buffer, &count);
|
2009-02-08 04:33:57 +08:00
|
|
|
|
2019-04-22 07:40:44 +08:00
|
|
|
/* Need to also simulate the tr->reset to remove this fgraph_ops */
|
|
|
|
tracing_stop_cmdline_record();
|
|
|
|
unregister_ftrace_graph(&fgraph_ops);
|
|
|
|
|
2009-02-08 04:33:57 +08:00
|
|
|
tracing_start();
|
|
|
|
|
|
|
|
if (!ret && !count) {
|
|
|
|
printk(KERN_CONT ".. no entries found ..");
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2021-12-21 00:38:06 +08:00
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
|
2021-10-08 17:13:32 +08:00
|
|
|
tracing_reset_online_cpus(&tr->array_buffer);
|
|
|
|
set_graph_array(tr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some archs *cough*PowerPC*cough* add characters to the
|
|
|
|
* start of the function names. We simply put a '*' to
|
|
|
|
* accommodate them.
|
|
|
|
*/
|
|
|
|
func_name = "*" __stringify(DYN_FTRACE_TEST_NAME);
|
|
|
|
ftrace_set_global_filter(func_name, strlen(func_name), 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register direct function together with graph tracer
|
|
|
|
* and make sure we get graph trace.
|
|
|
|
*/
|
|
|
|
ret = register_ftrace_direct((unsigned long) DYN_FTRACE_TEST_NAME,
|
|
|
|
(unsigned long) trace_direct_tramp);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = register_ftrace_graph(&fgraph_ops);
|
|
|
|
if (ret) {
|
|
|
|
warn_failed_init_tracer(trace, ret);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
DYN_FTRACE_TEST_NAME();
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
tracing_stop();
|
|
|
|
/* check the trace buffer */
|
|
|
|
ret = trace_test_buffer(&tr->array_buffer, &count);
|
|
|
|
|
|
|
|
unregister_ftrace_graph(&fgraph_ops);
|
|
|
|
|
|
|
|
ret = unregister_ftrace_direct((unsigned long) DYN_FTRACE_TEST_NAME,
|
|
|
|
(unsigned long) trace_direct_tramp);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
tracing_start();
|
2009-02-08 04:33:57 +08:00
|
|
|
|
2021-10-08 17:13:32 +08:00
|
|
|
if (!ret && !count) {
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Don't test dynamic tracing, the function tracer already did */
|
2009-02-08 04:33:57 +08:00
|
|
|
out:
|
|
|
|
/* Stop it if we failed */
|
|
|
|
if (ret)
|
|
|
|
ftrace_graph_stop();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
|
|
|
|
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
#ifdef CONFIG_IRQSOFF_TRACER
|
|
|
|
int
|
|
|
|
trace_selftest_startup_irqsoff(struct tracer *trace, struct trace_array *tr)
|
|
|
|
{
|
2014-01-15 00:28:38 +08:00
|
|
|
unsigned long save_max = tr->max_latency;
|
2008-05-13 03:20:44 +08:00
|
|
|
unsigned long count;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* start the tracing */
|
2009-02-06 04:02:00 +08:00
|
|
|
ret = tracer_init(trace, tr);
|
2008-11-16 12:57:26 +08:00
|
|
|
if (ret) {
|
|
|
|
warn_failed_init_tracer(trace, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
/* reset the max latency */
|
2014-01-15 00:28:38 +08:00
|
|
|
tr->max_latency = 0;
|
2008-05-13 03:20:44 +08:00
|
|
|
/* disable interrupts for a bit */
|
|
|
|
local_irq_disable();
|
|
|
|
udelay(100);
|
|
|
|
local_irq_enable();
|
2009-03-18 05:38:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the tracer to avoid a warning subsequent
|
|
|
|
* to buffer flipping failure because tracing_stop()
|
|
|
|
* disables the tr and max buffers, making flipping impossible
|
|
|
|
* in case of parallels max irqs off latencies.
|
|
|
|
*/
|
|
|
|
trace->stop(tr);
|
2008-05-13 03:20:44 +08:00
|
|
|
/* stop the tracing. */
|
2008-11-08 11:36:02 +08:00
|
|
|
tracing_stop();
|
2008-05-13 03:20:44 +08:00
|
|
|
/* check both trace buffers */
|
2020-01-10 07:53:48 +08:00
|
|
|
ret = trace_test_buffer(&tr->array_buffer, NULL);
|
2008-05-13 03:20:44 +08:00
|
|
|
if (!ret)
|
tracing: Consolidate max_tr into main trace_array structure
Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.
The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.
This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.
The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-05 22:24:35 +08:00
|
|
|
ret = trace_test_buffer(&tr->max_buffer, &count);
|
2008-05-13 03:20:44 +08:00
|
|
|
trace->reset(tr);
|
2008-11-08 11:36:02 +08:00
|
|
|
tracing_start();
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
if (!ret && !count) {
|
|
|
|
printk(KERN_CONT ".. no entries found ..");
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
2014-01-15 00:28:38 +08:00
|
|
|
tr->max_latency = save_max;
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IRQSOFF_TRACER */
|
|
|
|
|
|
|
|
#ifdef CONFIG_PREEMPT_TRACER
|
|
|
|
int
|
|
|
|
trace_selftest_startup_preemptoff(struct tracer *trace, struct trace_array *tr)
|
|
|
|
{
|
2014-01-15 00:28:38 +08:00
|
|
|
unsigned long save_max = tr->max_latency;
|
2008-05-13 03:20:44 +08:00
|
|
|
unsigned long count;
|
|
|
|
int ret;
|
|
|
|
|
2008-11-08 11:36:02 +08:00
|
|
|
/*
|
2021-03-24 01:49:35 +08:00
|
|
|
* Now that the big kernel lock is no longer preemptible,
|
2008-11-08 11:36:02 +08:00
|
|
|
* and this is called with the BKL held, it will always
|
|
|
|
* fail. If preemption is already disabled, simply
|
|
|
|
* pass the test. When the BKL is removed, or becomes
|
|
|
|
* preemptible again, we will once again test this,
|
|
|
|
* so keep it in.
|
|
|
|
*/
|
|
|
|
if (preempt_count()) {
|
|
|
|
printk(KERN_CONT "can not test ... force ");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
/* start the tracing */
|
2009-02-06 04:02:00 +08:00
|
|
|
ret = tracer_init(trace, tr);
|
2008-11-16 12:57:26 +08:00
|
|
|
if (ret) {
|
|
|
|
warn_failed_init_tracer(trace, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
/* reset the max latency */
|
2014-01-15 00:28:38 +08:00
|
|
|
tr->max_latency = 0;
|
2008-05-13 03:20:44 +08:00
|
|
|
/* disable preemption for a bit */
|
|
|
|
preempt_disable();
|
|
|
|
udelay(100);
|
|
|
|
preempt_enable();
|
2009-03-18 05:38:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the tracer to avoid a warning subsequent
|
|
|
|
* to buffer flipping failure because tracing_stop()
|
|
|
|
* disables the tr and max buffers, making flipping impossible
|
|
|
|
* in case of parallels max preempt off latencies.
|
|
|
|
*/
|
|
|
|
trace->stop(tr);
|
2008-05-13 03:20:44 +08:00
|
|
|
/* stop the tracing. */
|
2008-11-08 11:36:02 +08:00
|
|
|
tracing_stop();
|
2008-05-13 03:20:44 +08:00
|
|
|
/* check both trace buffers */
|
2020-01-10 07:53:48 +08:00
|
|
|
ret = trace_test_buffer(&tr->array_buffer, NULL);
|
2008-05-13 03:20:44 +08:00
|
|
|
if (!ret)
|
tracing: Consolidate max_tr into main trace_array structure
Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.
The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.
This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.
The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-05 22:24:35 +08:00
|
|
|
ret = trace_test_buffer(&tr->max_buffer, &count);
|
2008-05-13 03:20:44 +08:00
|
|
|
trace->reset(tr);
|
2008-11-08 11:36:02 +08:00
|
|
|
tracing_start();
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
if (!ret && !count) {
|
|
|
|
printk(KERN_CONT ".. no entries found ..");
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
2014-01-15 00:28:38 +08:00
|
|
|
tr->max_latency = save_max;
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_PREEMPT_TRACER */
|
|
|
|
|
|
|
|
#if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
|
|
|
|
int
|
|
|
|
trace_selftest_startup_preemptirqsoff(struct tracer *trace, struct trace_array *tr)
|
|
|
|
{
|
2014-01-15 00:28:38 +08:00
|
|
|
unsigned long save_max = tr->max_latency;
|
2008-05-13 03:20:44 +08:00
|
|
|
unsigned long count;
|
|
|
|
int ret;
|
|
|
|
|
2008-11-08 11:36:02 +08:00
|
|
|
/*
|
2021-03-24 01:49:35 +08:00
|
|
|
* Now that the big kernel lock is no longer preemptible,
|
2008-11-08 11:36:02 +08:00
|
|
|
* and this is called with the BKL held, it will always
|
|
|
|
* fail. If preemption is already disabled, simply
|
|
|
|
* pass the test. When the BKL is removed, or becomes
|
|
|
|
* preemptible again, we will once again test this,
|
|
|
|
* so keep it in.
|
|
|
|
*/
|
|
|
|
if (preempt_count()) {
|
|
|
|
printk(KERN_CONT "can not test ... force ");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
/* start the tracing */
|
2009-02-06 04:02:00 +08:00
|
|
|
ret = tracer_init(trace, tr);
|
2008-11-16 12:57:26 +08:00
|
|
|
if (ret) {
|
|
|
|
warn_failed_init_tracer(trace, ret);
|
2009-03-16 07:32:41 +08:00
|
|
|
goto out_no_start;
|
2008-11-16 12:57:26 +08:00
|
|
|
}
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
/* reset the max latency */
|
2014-01-15 00:28:38 +08:00
|
|
|
tr->max_latency = 0;
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
/* disable preemption and interrupts for a bit */
|
|
|
|
preempt_disable();
|
|
|
|
local_irq_disable();
|
|
|
|
udelay(100);
|
|
|
|
preempt_enable();
|
|
|
|
/* reverse the order of preempt vs irqs */
|
|
|
|
local_irq_enable();
|
|
|
|
|
2009-03-18 05:38:58 +08:00
|
|
|
/*
|
|
|
|
* Stop the tracer to avoid a warning subsequent
|
|
|
|
* to buffer flipping failure because tracing_stop()
|
|
|
|
* disables the tr and max buffers, making flipping impossible
|
|
|
|
* in case of parallels max irqs/preempt off latencies.
|
|
|
|
*/
|
|
|
|
trace->stop(tr);
|
2008-05-13 03:20:44 +08:00
|
|
|
/* stop the tracing. */
|
2008-11-08 11:36:02 +08:00
|
|
|
tracing_stop();
|
2008-05-13 03:20:44 +08:00
|
|
|
/* check both trace buffers */
|
2020-01-10 07:53:48 +08:00
|
|
|
ret = trace_test_buffer(&tr->array_buffer, NULL);
|
2009-03-16 07:32:41 +08:00
|
|
|
if (ret)
|
2008-05-13 03:20:44 +08:00
|
|
|
goto out;
|
|
|
|
|
tracing: Consolidate max_tr into main trace_array structure
Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.
The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.
This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.
The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-05 22:24:35 +08:00
|
|
|
ret = trace_test_buffer(&tr->max_buffer, &count);
|
2009-03-16 07:32:41 +08:00
|
|
|
if (ret)
|
2008-05-13 03:20:44 +08:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!ret && !count) {
|
|
|
|
printk(KERN_CONT ".. no entries found ..");
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do the test by disabling interrupts first this time */
|
2014-01-15 00:28:38 +08:00
|
|
|
tr->max_latency = 0;
|
2008-11-08 11:36:02 +08:00
|
|
|
tracing_start();
|
2009-03-18 05:38:58 +08:00
|
|
|
trace->start(tr);
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
preempt_disable();
|
|
|
|
local_irq_disable();
|
|
|
|
udelay(100);
|
|
|
|
preempt_enable();
|
|
|
|
/* reverse the order of preempt vs irqs */
|
|
|
|
local_irq_enable();
|
|
|
|
|
2009-03-18 05:38:58 +08:00
|
|
|
trace->stop(tr);
|
2008-05-13 03:20:44 +08:00
|
|
|
/* stop the tracing. */
|
2008-11-08 11:36:02 +08:00
|
|
|
tracing_stop();
|
2008-05-13 03:20:44 +08:00
|
|
|
/* check both trace buffers */
|
2020-01-10 07:53:48 +08:00
|
|
|
ret = trace_test_buffer(&tr->array_buffer, NULL);
|
2008-05-13 03:20:44 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
tracing: Consolidate max_tr into main trace_array structure
Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.
The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.
This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.
The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-05 22:24:35 +08:00
|
|
|
ret = trace_test_buffer(&tr->max_buffer, &count);
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
if (!ret && !count) {
|
|
|
|
printk(KERN_CONT ".. no entries found ..");
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-03-16 07:32:41 +08:00
|
|
|
out:
|
2008-11-08 11:36:02 +08:00
|
|
|
tracing_start();
|
2009-03-16 07:32:41 +08:00
|
|
|
out_no_start:
|
|
|
|
trace->reset(tr);
|
2014-01-15 00:28:38 +08:00
|
|
|
tr->max_latency = save_max;
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IRQSOFF_TRACER && CONFIG_PREEMPT_TRACER */
|
|
|
|
|
2008-09-19 18:06:43 +08:00
|
|
|
#ifdef CONFIG_NOP_TRACER
|
|
|
|
int
|
|
|
|
trace_selftest_startup_nop(struct tracer *trace, struct trace_array *tr)
|
|
|
|
{
|
|
|
|
/* What could possibly go wrong? */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
#ifdef CONFIG_SCHED_TRACER
|
2014-10-09 01:52:16 +08:00
|
|
|
|
|
|
|
struct wakeup_test_data {
|
|
|
|
struct completion is_ready;
|
|
|
|
int go;
|
|
|
|
};
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
static int trace_wakeup_test_thread(void *data)
|
|
|
|
{
|
2013-11-07 21:43:42 +08:00
|
|
|
/* Make this a -deadline thread */
|
|
|
|
static const struct sched_attr attr = {
|
|
|
|
.sched_policy = SCHED_DEADLINE,
|
|
|
|
.sched_runtime = 100000ULL,
|
|
|
|
.sched_deadline = 10000000ULL,
|
|
|
|
.sched_period = 10000000ULL
|
|
|
|
};
|
2014-10-09 01:52:16 +08:00
|
|
|
struct wakeup_test_data *x = data;
|
2008-05-13 03:20:44 +08:00
|
|
|
|
2013-11-07 21:43:42 +08:00
|
|
|
sched_setattr(current, &attr);
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
/* Make it know we have a new prio */
|
2014-10-09 01:52:16 +08:00
|
|
|
complete(&x->is_ready);
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
/* now go to sleep and let the test wake us up */
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2014-10-09 01:52:16 +08:00
|
|
|
while (!x->go) {
|
|
|
|
schedule();
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
}
|
2008-05-13 03:20:44 +08:00
|
|
|
|
2014-10-09 01:52:16 +08:00
|
|
|
complete(&x->is_ready);
|
|
|
|
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2012-07-31 22:23:37 +08:00
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
/* we are awake, now wait to disappear */
|
|
|
|
while (!kthread_should_stop()) {
|
2014-10-09 01:52:16 +08:00
|
|
|
schedule();
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2008-05-13 03:20:44 +08:00
|
|
|
}
|
|
|
|
|
2014-10-09 01:52:16 +08:00
|
|
|
__set_current_state(TASK_RUNNING);
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int
|
|
|
|
trace_selftest_startup_wakeup(struct tracer *trace, struct trace_array *tr)
|
|
|
|
{
|
2014-01-15 00:28:38 +08:00
|
|
|
unsigned long save_max = tr->max_latency;
|
2008-05-13 03:20:44 +08:00
|
|
|
struct task_struct *p;
|
2014-10-09 01:52:16 +08:00
|
|
|
struct wakeup_test_data data;
|
2008-05-13 03:20:44 +08:00
|
|
|
unsigned long count;
|
|
|
|
int ret;
|
|
|
|
|
2014-10-09 01:52:16 +08:00
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
|
|
|
|
init_completion(&data.is_ready);
|
2008-05-13 03:20:44 +08:00
|
|
|
|
2013-11-07 21:43:42 +08:00
|
|
|
/* create a -deadline thread */
|
2014-10-09 01:52:16 +08:00
|
|
|
p = kthread_run(trace_wakeup_test_thread, &data, "ftrace-test");
|
2008-05-13 03:20:45 +08:00
|
|
|
if (IS_ERR(p)) {
|
2008-05-13 03:20:44 +08:00
|
|
|
printk(KERN_CONT "Failed to create ftrace wakeup test thread ");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-07 21:43:42 +08:00
|
|
|
/* make sure the thread is running at -deadline policy */
|
2014-10-09 01:52:16 +08:00
|
|
|
wait_for_completion(&data.is_ready);
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
/* start the tracing */
|
2009-02-06 04:02:00 +08:00
|
|
|
ret = tracer_init(trace, tr);
|
2008-11-16 12:57:26 +08:00
|
|
|
if (ret) {
|
|
|
|
warn_failed_init_tracer(trace, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
/* reset the max latency */
|
2014-01-15 00:28:38 +08:00
|
|
|
tr->max_latency = 0;
|
2008-05-13 03:20:44 +08:00
|
|
|
|
2012-07-31 22:23:37 +08:00
|
|
|
while (p->on_rq) {
|
|
|
|
/*
|
2013-11-07 21:43:42 +08:00
|
|
|
* Sleep to make sure the -deadline thread is asleep too.
|
2012-07-31 22:23:37 +08:00
|
|
|
* On virtual machines we can't rely on timings,
|
|
|
|
* but we want to make sure this test still works.
|
|
|
|
*/
|
|
|
|
msleep(100);
|
|
|
|
}
|
2008-05-13 03:20:44 +08:00
|
|
|
|
2014-10-09 01:52:16 +08:00
|
|
|
init_completion(&data.is_ready);
|
|
|
|
|
|
|
|
data.go = 1;
|
|
|
|
/* memory barrier is in the wake_up_process() */
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
wake_up_process(p);
|
|
|
|
|
2012-07-31 22:23:37 +08:00
|
|
|
/* Wait for the task to wake up */
|
2014-10-09 01:52:16 +08:00
|
|
|
wait_for_completion(&data.is_ready);
|
2008-09-30 11:02:37 +08:00
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
/* stop the tracing. */
|
2008-11-08 11:36:02 +08:00
|
|
|
tracing_stop();
|
2008-05-13 03:20:44 +08:00
|
|
|
/* check both trace buffers */
|
2020-01-10 07:53:48 +08:00
|
|
|
ret = trace_test_buffer(&tr->array_buffer, NULL);
|
2008-05-13 03:20:44 +08:00
|
|
|
if (!ret)
|
tracing: Consolidate max_tr into main trace_array structure
Currently, the way the latency tracers and snapshot feature works
is to have a separate trace_array called "max_tr" that holds the
snapshot buffer. For latency tracers, this snapshot buffer is used
to swap the running buffer with this buffer to save the current max
latency.
The only items needed for the max_tr is really just a copy of the buffer
itself, the per_cpu data pointers, the time_start timestamp that states
when the max latency was triggered, and the cpu that the max latency
was triggered on. All other fields in trace_array are unused by the
max_tr, making the max_tr mostly bloat.
This change removes the max_tr completely, and adds a new structure
called trace_buffer, that holds the buffer pointer, the per_cpu data
pointers, the time_start timestamp, and the cpu where the latency occurred.
The trace_array, now has two trace_buffers, one for the normal trace and
one for the max trace or snapshot. By doing this, not only do we remove
the bloat from the max_trace but the instances of traces can now use
their own snapshot feature and not have just the top level global_trace have
the snapshot feature and latency tracers for itself.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-03-05 22:24:35 +08:00
|
|
|
ret = trace_test_buffer(&tr->max_buffer, &count);
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
trace->reset(tr);
|
2008-11-08 11:36:02 +08:00
|
|
|
tracing_start();
|
2008-05-13 03:20:44 +08:00
|
|
|
|
2014-01-15 00:28:38 +08:00
|
|
|
tr->max_latency = save_max;
|
2008-05-13 03:20:44 +08:00
|
|
|
|
|
|
|
/* kill the thread */
|
|
|
|
kthread_stop(p);
|
|
|
|
|
|
|
|
if (!ret && !count) {
|
|
|
|
printk(KERN_CONT ".. no entries found ..");
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SCHED_TRACER */
|
|
|
|
|
2008-11-13 04:24:24 +08:00
|
|
|
#ifdef CONFIG_BRANCH_TRACER
|
|
|
|
int
|
|
|
|
trace_selftest_startup_branch(struct tracer *trace, struct trace_array *tr)
|
|
|
|
{
|
|
|
|
unsigned long count;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* start the tracing */
|
2009-02-06 04:02:00 +08:00
|
|
|
ret = tracer_init(trace, tr);
|
2008-11-16 12:57:26 +08:00
|
|
|
if (ret) {
|
|
|
|
warn_failed_init_tracer(trace, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:24:24 +08:00
|
|
|
/* Sleep for a 1/10 of a second */
|
|
|
|
msleep(100);
|
|
|
|
/* stop the tracing. */
|
|
|
|
tracing_stop();
|
|
|
|
/* check the trace buffer */
|
2020-01-10 07:53:48 +08:00
|
|
|
ret = trace_test_buffer(&tr->array_buffer, &count);
|
2008-11-13 04:24:24 +08:00
|
|
|
trace->reset(tr);
|
|
|
|
tracing_start();
|
|
|
|
|
2009-02-17 14:09:47 +08:00
|
|
|
if (!ret && !count) {
|
|
|
|
printk(KERN_CONT ".. no entries found ..");
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:24:24 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_BRANCH_TRACER */
|
2009-03-13 17:50:27 +08:00
|
|
|
|