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
|
2017-04-18 02:23:08 +08:00
|
|
|
#include <inttypes.h>
|
2014-03-06 00:20:31 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "debug.h"
|
|
|
|
#include "tests.h"
|
|
|
|
#include "machine.h"
|
|
|
|
#include "thread_map.h"
|
|
|
|
#include "symbol.h"
|
|
|
|
#include "thread.h"
|
2017-04-18 22:33:48 +08:00
|
|
|
#include "util.h"
|
2014-03-06 00:20:31 +08:00
|
|
|
|
|
|
|
#define THREADS 4
|
|
|
|
|
|
|
|
static int go_away;
|
|
|
|
|
|
|
|
struct thread_data {
|
|
|
|
pthread_t pt;
|
|
|
|
pid_t tid;
|
|
|
|
void *map;
|
|
|
|
int ready[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct thread_data threads[THREADS];
|
|
|
|
|
|
|
|
static int thread_init(struct thread_data *td)
|
|
|
|
{
|
|
|
|
void *map;
|
|
|
|
|
|
|
|
map = mmap(NULL, page_size,
|
|
|
|
PROT_READ|PROT_WRITE|PROT_EXEC,
|
|
|
|
MAP_SHARED|MAP_ANONYMOUS, -1, 0);
|
|
|
|
|
|
|
|
if (map == MAP_FAILED) {
|
|
|
|
perror("mmap failed");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
td->map = map;
|
|
|
|
td->tid = syscall(SYS_gettid);
|
|
|
|
|
|
|
|
pr_debug("tid = %d, map = %p\n", td->tid, map);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *thread_fn(void *arg)
|
|
|
|
{
|
|
|
|
struct thread_data *td = arg;
|
|
|
|
ssize_t ret;
|
|
|
|
int go;
|
|
|
|
|
|
|
|
if (thread_init(td))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Signal thread_create thread is initialized. */
|
|
|
|
ret = write(td->ready[1], &go, sizeof(int));
|
|
|
|
if (ret != sizeof(int)) {
|
|
|
|
pr_err("failed to notify\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!go_away) {
|
|
|
|
/* Waiting for main thread to kill us. */
|
|
|
|
usleep(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
munmap(td->map, page_size);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int thread_create(int i)
|
|
|
|
{
|
|
|
|
struct thread_data *td = &threads[i];
|
|
|
|
int err, go;
|
|
|
|
|
|
|
|
if (pipe(td->ready))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
err = pthread_create(&td->pt, NULL, thread_fn, td);
|
|
|
|
if (!err) {
|
|
|
|
/* Wait for thread initialization. */
|
|
|
|
ssize_t ret = read(td->ready[0], &go, sizeof(int));
|
|
|
|
err = ret != sizeof(int);
|
|
|
|
}
|
|
|
|
|
|
|
|
close(td->ready[0]);
|
|
|
|
close(td->ready[1]);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int threads_create(void)
|
|
|
|
{
|
|
|
|
struct thread_data *td0 = &threads[0];
|
|
|
|
int i, err = 0;
|
|
|
|
|
|
|
|
go_away = 0;
|
|
|
|
|
|
|
|
/* 0 is main thread */
|
|
|
|
if (thread_init(td0))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 1; !err && i < THREADS; i++)
|
|
|
|
err = thread_create(i);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int threads_destroy(void)
|
|
|
|
{
|
|
|
|
struct thread_data *td0 = &threads[0];
|
|
|
|
int i, err = 0;
|
|
|
|
|
|
|
|
/* cleanup the main thread */
|
|
|
|
munmap(td0->map, page_size);
|
|
|
|
|
|
|
|
go_away = 1;
|
|
|
|
|
|
|
|
for (i = 1; !err && i < THREADS; i++)
|
|
|
|
err = pthread_join(threads[i].pt, NULL);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef int (*synth_cb)(struct machine *machine);
|
|
|
|
|
|
|
|
static int synth_all(struct machine *machine)
|
|
|
|
{
|
|
|
|
return perf_event__synthesize_threads(NULL,
|
|
|
|
perf_event__process,
|
perf top: Implement multithreading for perf_event__synthesize_threads
The proc files which is sorted with alphabetical order are evenly
assigned to several synthesize threads to be processed in parallel.
For 'perf top', the threads number hard code to online CPU number. The
following patch will introduce an option to set it.
For other perf tools, the thread number is 1. Because the process
function is not ready for multithreading, e.g.
process_synthesized_event.
This patch series only support event synthesize multithreading for 'perf
top'. For other tools, it can be done separately later.
With multithread applied, the total processing time can get up to 1.56x
speedup on Knights Mill for 'perf top'.
For specific single event processing, the processing time could increase
because of the lock contention. So proc_map_timeout may need to be
increased. Otherwise some proc maps will be truncated.
Based on my test, increasing the proc_map_timeout has small impact
on the total processing time. The total processing time still get 1.49x
speedup on Knights Mill after increasing the proc_map_timeout.
The patch itself doesn't increase the proc_map_timeout.
Doesn't need to implement multithreading for per task monitoring,
perf_event__synthesize_thread_map. It doesn't have performance issue.
Committer testing:
# getconf _NPROCESSORS_ONLN
4
# perf trace --no-inherit -e clone -o /tmp/output perf top
# tail -4 /tmp/bla
0.124 ( 0.041 ms): clone(flags: VM|FS|FILES|SIGHAND|THREAD|SYSVSEM|SETTLS|PARENT_SETTID|CHILD_CLEARTID, child_stack: 0x7fc3eb3a8f30, parent_tidptr: 0x7fc3eb3a99d0, child_tidptr: 0x7fc3eb3a99d0, tls: 0x7fc3eb3a9700) = 9548 (perf)
0.246 ( 0.023 ms): clone(flags: VM|FS|FILES|SIGHAND|THREAD|SYSVSEM|SETTLS|PARENT_SETTID|CHILD_CLEARTID, child_stack: 0x7fc3eaba7f30, parent_tidptr: 0x7fc3eaba89d0, child_tidptr: 0x7fc3eaba89d0, tls: 0x7fc3eaba8700) = 9549 (perf)
0.286 ( 0.019 ms): clone(flags: VM|FS|FILES|SIGHAND|THREAD|SYSVSEM|SETTLS|PARENT_SETTID|CHILD_CLEARTID, child_stack: 0x7fc3ea3a6f30, parent_tidptr: 0x7fc3ea3a79d0, child_tidptr: 0x7fc3ea3a79d0, tls: 0x7fc3ea3a7700) = 9550 (perf)
246.540 ( 0.047 ms): clone(flags: VM|FS|FILES|SIGHAND|THREAD|SYSVSEM|SETTLS|PARENT_SETTID|CHILD_CLEARTID, child_stack: 0x7fc3ea3a6f30, parent_tidptr: 0x7fc3ea3a79d0, child_tidptr: 0x7fc3ea3a79d0, tls: 0x7fc3ea3a7700) = 9551 (perf)
#
Signed-off-by: Kan Liang <kan.liang@intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Lukasz Odzioba <lukasz.odzioba@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1506696477-146932-4-git-send-email-kan.liang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-09-29 22:47:54 +08:00
|
|
|
machine, 0, 500, 1);
|
2014-03-06 00:20:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int synth_process(struct machine *machine)
|
|
|
|
{
|
|
|
|
struct thread_map *map;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
map = thread_map__new_by_pid(getpid());
|
|
|
|
|
|
|
|
err = perf_event__synthesize_thread_map(NULL, map,
|
|
|
|
perf_event__process,
|
2015-06-17 21:51:11 +08:00
|
|
|
machine, 0, 500);
|
2014-03-06 00:20:31 +08:00
|
|
|
|
2015-06-23 06:36:05 +08:00
|
|
|
thread_map__put(map);
|
2014-03-06 00:20:31 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmap_events(synth_cb synth)
|
|
|
|
{
|
|
|
|
struct machine *machine;
|
|
|
|
int err, i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The threads_create will not return before all threads
|
|
|
|
* are spawned and all created memory map.
|
|
|
|
*
|
|
|
|
* They will loop until threads_destroy is called, so we
|
|
|
|
* can safely run synthesizing function.
|
|
|
|
*/
|
|
|
|
TEST_ASSERT_VAL("failed to create threads", !threads_create());
|
|
|
|
|
2015-12-03 16:34:13 +08:00
|
|
|
machine = machine__new_host();
|
2014-03-06 00:20:31 +08:00
|
|
|
|
|
|
|
dump_trace = verbose > 1 ? 1 : 0;
|
|
|
|
|
|
|
|
err = synth(machine);
|
|
|
|
|
|
|
|
dump_trace = 0;
|
|
|
|
|
|
|
|
TEST_ASSERT_VAL("failed to destroy threads", !threads_destroy());
|
|
|
|
TEST_ASSERT_VAL("failed to synthesize maps", !err);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All data is synthesized, try to find map for each
|
|
|
|
* thread object.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < THREADS; i++) {
|
|
|
|
struct thread_data *td = &threads[i];
|
|
|
|
struct addr_location al;
|
|
|
|
struct thread *thread;
|
|
|
|
|
|
|
|
thread = machine__findnew_thread(machine, getpid(), td->tid);
|
|
|
|
|
|
|
|
pr_debug("looking for map %p\n", td->map);
|
|
|
|
|
2014-10-23 23:50:25 +08:00
|
|
|
thread__find_addr_map(thread,
|
2014-03-06 00:20:31 +08:00
|
|
|
PERF_RECORD_MISC_USER, MAP__FUNCTION,
|
|
|
|
(unsigned long) (td->map + 1), &al);
|
|
|
|
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-07 07:43:22 +08:00
|
|
|
thread__put(thread);
|
|
|
|
|
2014-03-06 00:20:31 +08:00
|
|
|
if (!al.map) {
|
|
|
|
pr_debug("failed, couldn't find map\n");
|
|
|
|
err = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_debug("map %p, addr %" PRIx64 "\n", al.map, al.map->start);
|
|
|
|
}
|
|
|
|
|
|
|
|
machine__delete_threads(machine);
|
2015-12-03 16:34:13 +08:00
|
|
|
machine__delete(machine);
|
2014-03-06 00:20:31 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This test creates 'THREADS' number of threads (including
|
|
|
|
* main thread) and each thread creates memory map.
|
|
|
|
*
|
|
|
|
* When threads are created, we synthesize them with both
|
|
|
|
* (separate tests):
|
|
|
|
* perf_event__synthesize_thread_map (process based)
|
|
|
|
* perf_event__synthesize_threads (global)
|
|
|
|
*
|
|
|
|
* We test we can find all memory maps via:
|
|
|
|
* thread__find_addr_map
|
|
|
|
*
|
|
|
|
* by using all thread objects.
|
|
|
|
*/
|
2017-08-04 02:16:31 +08:00
|
|
|
int test__mmap_thread_lookup(struct test *test __maybe_unused, int subtest __maybe_unused)
|
2014-03-06 00:20:31 +08:00
|
|
|
{
|
|
|
|
/* perf_event__synthesize_threads synthesize */
|
|
|
|
TEST_ASSERT_VAL("failed with sythesizing all",
|
|
|
|
!mmap_events(synth_all));
|
|
|
|
|
|
|
|
/* perf_event__synthesize_thread_map synthesize */
|
|
|
|
TEST_ASSERT_VAL("failed with sythesizing process",
|
|
|
|
!mmap_events(synth_process));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|