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
|
2010-09-28 03:45:08 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2010 ARM Ltd.
|
2012-02-24 00:07:06 +08:00
|
|
|
* Copyright 2012 Advanced Micro Devices, Inc., Robert Richter
|
2010-09-28 03:45:08 +08:00
|
|
|
*
|
|
|
|
* Perf-events backend for OProfile.
|
|
|
|
*/
|
|
|
|
#include <linux/perf_event.h>
|
2010-10-14 23:31:43 +08:00
|
|
|
#include <linux/platform_device.h>
|
2010-09-28 03:45:08 +08:00
|
|
|
#include <linux/oprofile.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Per performance monitor configuration as set via oprofilefs.
|
|
|
|
*/
|
|
|
|
struct op_counter_config {
|
|
|
|
unsigned long count;
|
|
|
|
unsigned long enabled;
|
|
|
|
unsigned long event;
|
|
|
|
unsigned long unit_mask;
|
|
|
|
unsigned long kernel;
|
|
|
|
unsigned long user;
|
|
|
|
struct perf_event_attr attr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int oprofile_perf_enabled;
|
|
|
|
static DEFINE_MUTEX(oprofile_perf_mutex);
|
|
|
|
|
|
|
|
static struct op_counter_config *counter_config;
|
2012-02-24 00:07:06 +08:00
|
|
|
static DEFINE_PER_CPU(struct perf_event **, perf_events);
|
2010-09-28 03:45:08 +08:00
|
|
|
static int num_counters;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Overflow callback for oprofile.
|
|
|
|
*/
|
2011-07-09 01:34:42 +08:00
|
|
|
static void op_overflow_handler(struct perf_event *event,
|
2010-09-28 03:45:08 +08:00
|
|
|
struct perf_sample_data *data, struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
u32 cpu = smp_processor_id();
|
|
|
|
|
|
|
|
for (id = 0; id < num_counters; ++id)
|
2012-02-24 00:07:06 +08:00
|
|
|
if (per_cpu(perf_events, cpu)[id] == event)
|
2010-09-28 03:45:08 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (id != num_counters)
|
|
|
|
oprofile_add_sample(regs, id);
|
|
|
|
else
|
|
|
|
pr_warning("oprofile: ignoring spurious overflow "
|
|
|
|
"on cpu %u\n", cpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by oprofile_perf_setup to create perf attributes to mirror the oprofile
|
|
|
|
* settings in counter_config. Attributes are created as `pinned' events and
|
|
|
|
* so are permanently scheduled on the PMU.
|
|
|
|
*/
|
|
|
|
static void op_perf_setup(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u32 size = sizeof(struct perf_event_attr);
|
|
|
|
struct perf_event_attr *attr;
|
|
|
|
|
|
|
|
for (i = 0; i < num_counters; ++i) {
|
|
|
|
attr = &counter_config[i].attr;
|
|
|
|
memset(attr, 0, size);
|
|
|
|
attr->type = PERF_TYPE_RAW;
|
|
|
|
attr->size = size;
|
|
|
|
attr->config = counter_config[i].event;
|
|
|
|
attr->sample_period = counter_config[i].count;
|
|
|
|
attr->pinned = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int op_create_counter(int cpu, int event)
|
|
|
|
{
|
|
|
|
struct perf_event *pevent;
|
|
|
|
|
2012-02-24 00:07:06 +08:00
|
|
|
if (!counter_config[event].enabled || per_cpu(perf_events, cpu)[event])
|
2010-09-29 20:43:29 +08:00
|
|
|
return 0;
|
2010-09-28 03:45:08 +08:00
|
|
|
|
|
|
|
pevent = perf_event_create_kernel_counter(&counter_config[event].attr,
|
2010-10-15 18:45:00 +08:00
|
|
|
cpu, NULL,
|
2011-06-29 23:42:35 +08:00
|
|
|
op_overflow_handler, NULL);
|
2010-09-28 03:45:08 +08:00
|
|
|
|
2010-09-29 20:43:29 +08:00
|
|
|
if (IS_ERR(pevent))
|
|
|
|
return PTR_ERR(pevent);
|
|
|
|
|
|
|
|
if (pevent->state != PERF_EVENT_STATE_ACTIVE) {
|
2010-09-29 22:52:25 +08:00
|
|
|
perf_event_release_kernel(pevent);
|
2010-09-28 03:45:08 +08:00
|
|
|
pr_warning("oprofile: failed to enable event %d "
|
|
|
|
"on CPU %d\n", event, cpu);
|
2010-09-29 20:43:29 +08:00
|
|
|
return -EBUSY;
|
2010-09-28 03:45:08 +08:00
|
|
|
}
|
|
|
|
|
2012-02-24 00:07:06 +08:00
|
|
|
per_cpu(perf_events, cpu)[event] = pevent;
|
2010-09-29 20:43:29 +08:00
|
|
|
|
|
|
|
return 0;
|
2010-09-28 03:45:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void op_destroy_counter(int cpu, int event)
|
|
|
|
{
|
2012-02-24 00:07:06 +08:00
|
|
|
struct perf_event *pevent = per_cpu(perf_events, cpu)[event];
|
2010-09-28 03:45:08 +08:00
|
|
|
|
|
|
|
if (pevent) {
|
|
|
|
perf_event_release_kernel(pevent);
|
2012-02-24 00:07:06 +08:00
|
|
|
per_cpu(perf_events, cpu)[event] = NULL;
|
2010-09-28 03:45:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by oprofile_perf_start to create active perf events based on the
|
|
|
|
* perviously configured attributes.
|
|
|
|
*/
|
|
|
|
static int op_perf_start(void)
|
|
|
|
{
|
|
|
|
int cpu, event, ret = 0;
|
|
|
|
|
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
for (event = 0; event < num_counters; ++event) {
|
|
|
|
ret = op_create_counter(cpu, event);
|
|
|
|
if (ret)
|
2010-08-27 20:32:41 +08:00
|
|
|
return ret;
|
2010-09-28 03:45:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by oprofile_perf_stop at the end of a profiling run.
|
|
|
|
*/
|
|
|
|
static void op_perf_stop(void)
|
|
|
|
{
|
|
|
|
int cpu, event;
|
|
|
|
|
|
|
|
for_each_online_cpu(cpu)
|
|
|
|
for (event = 0; event < num_counters; ++event)
|
|
|
|
op_destroy_counter(cpu, event);
|
|
|
|
}
|
|
|
|
|
2013-07-19 19:52:42 +08:00
|
|
|
static int oprofile_perf_create_files(struct dentry *root)
|
2010-09-28 03:45:08 +08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_counters; i++) {
|
|
|
|
struct dentry *dir;
|
|
|
|
char buf[4];
|
|
|
|
|
|
|
|
snprintf(buf, sizeof buf, "%d", i);
|
2013-07-19 19:58:27 +08:00
|
|
|
dir = oprofilefs_mkdir(root, buf);
|
2013-07-19 20:10:36 +08:00
|
|
|
oprofilefs_create_ulong(dir, "enabled", &counter_config[i].enabled);
|
|
|
|
oprofilefs_create_ulong(dir, "event", &counter_config[i].event);
|
|
|
|
oprofilefs_create_ulong(dir, "count", &counter_config[i].count);
|
|
|
|
oprofilefs_create_ulong(dir, "unit_mask", &counter_config[i].unit_mask);
|
|
|
|
oprofilefs_create_ulong(dir, "kernel", &counter_config[i].kernel);
|
|
|
|
oprofilefs_create_ulong(dir, "user", &counter_config[i].user);
|
2010-09-28 03:45:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int oprofile_perf_setup(void)
|
|
|
|
{
|
2009-07-25 22:18:34 +08:00
|
|
|
raw_spin_lock(&oprofilefs_lock);
|
2010-09-28 03:45:08 +08:00
|
|
|
op_perf_setup();
|
2009-07-25 22:18:34 +08:00
|
|
|
raw_spin_unlock(&oprofilefs_lock);
|
2010-09-28 03:45:08 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int oprofile_perf_start(void)
|
|
|
|
{
|
|
|
|
int ret = -EBUSY;
|
|
|
|
|
|
|
|
mutex_lock(&oprofile_perf_mutex);
|
|
|
|
if (!oprofile_perf_enabled) {
|
|
|
|
ret = 0;
|
|
|
|
op_perf_start();
|
|
|
|
oprofile_perf_enabled = 1;
|
|
|
|
}
|
|
|
|
mutex_unlock(&oprofile_perf_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void oprofile_perf_stop(void)
|
|
|
|
{
|
|
|
|
mutex_lock(&oprofile_perf_mutex);
|
|
|
|
if (oprofile_perf_enabled)
|
|
|
|
op_perf_stop();
|
|
|
|
oprofile_perf_enabled = 0;
|
|
|
|
mutex_unlock(&oprofile_perf_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
2010-10-15 17:28:07 +08:00
|
|
|
|
2010-09-28 03:45:08 +08:00
|
|
|
static int oprofile_perf_suspend(struct platform_device *dev, pm_message_t state)
|
|
|
|
{
|
|
|
|
mutex_lock(&oprofile_perf_mutex);
|
|
|
|
if (oprofile_perf_enabled)
|
|
|
|
op_perf_stop();
|
|
|
|
mutex_unlock(&oprofile_perf_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int oprofile_perf_resume(struct platform_device *dev)
|
|
|
|
{
|
|
|
|
mutex_lock(&oprofile_perf_mutex);
|
|
|
|
if (oprofile_perf_enabled && op_perf_start())
|
|
|
|
oprofile_perf_enabled = 0;
|
|
|
|
mutex_unlock(&oprofile_perf_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver oprofile_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "oprofile-perf",
|
|
|
|
},
|
|
|
|
.resume = oprofile_perf_resume,
|
|
|
|
.suspend = oprofile_perf_suspend,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_device *oprofile_pdev;
|
|
|
|
|
|
|
|
static int __init init_driverfs(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = platform_driver_register(&oprofile_driver);
|
|
|
|
if (ret)
|
2010-08-27 20:32:41 +08:00
|
|
|
return ret;
|
2010-09-28 03:45:08 +08:00
|
|
|
|
|
|
|
oprofile_pdev = platform_device_register_simple(
|
|
|
|
oprofile_driver.driver.name, 0, NULL, 0);
|
|
|
|
if (IS_ERR(oprofile_pdev)) {
|
|
|
|
ret = PTR_ERR(oprofile_pdev);
|
|
|
|
platform_driver_unregister(&oprofile_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-10-14 23:31:42 +08:00
|
|
|
static void exit_driverfs(void)
|
2010-09-28 03:45:08 +08:00
|
|
|
{
|
|
|
|
platform_device_unregister(oprofile_pdev);
|
|
|
|
platform_driver_unregister(&oprofile_driver);
|
|
|
|
}
|
2010-10-15 17:28:07 +08:00
|
|
|
|
2010-09-28 03:45:08 +08:00
|
|
|
#else
|
2010-10-15 17:28:07 +08:00
|
|
|
|
|
|
|
static inline int init_driverfs(void) { return 0; }
|
|
|
|
static inline void exit_driverfs(void) { }
|
|
|
|
|
2010-09-28 03:45:08 +08:00
|
|
|
#endif /* CONFIG_PM */
|
|
|
|
|
2010-09-29 21:42:30 +08:00
|
|
|
void oprofile_perf_exit(void)
|
|
|
|
{
|
|
|
|
int cpu, id;
|
|
|
|
struct perf_event *event;
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
|
for (id = 0; id < num_counters; ++id) {
|
2012-02-24 00:07:06 +08:00
|
|
|
event = per_cpu(perf_events, cpu)[id];
|
2010-09-29 21:42:30 +08:00
|
|
|
if (event)
|
|
|
|
perf_event_release_kernel(event);
|
|
|
|
}
|
|
|
|
|
2012-02-24 00:07:06 +08:00
|
|
|
kfree(per_cpu(perf_events, cpu));
|
2010-09-29 21:42:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
kfree(counter_config);
|
|
|
|
exit_driverfs();
|
|
|
|
}
|
|
|
|
|
2010-09-28 03:45:08 +08:00
|
|
|
int __init oprofile_perf_init(struct oprofile_operations *ops)
|
|
|
|
{
|
|
|
|
int cpu, ret = 0;
|
|
|
|
|
2010-09-29 21:42:30 +08:00
|
|
|
ret = init_driverfs();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2010-09-28 03:45:08 +08:00
|
|
|
num_counters = perf_num_counters();
|
|
|
|
if (num_counters <= 0) {
|
|
|
|
pr_info("oprofile: no performance counters\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
counter_config = kcalloc(num_counters,
|
|
|
|
sizeof(struct op_counter_config), GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!counter_config) {
|
|
|
|
pr_info("oprofile: failed to allocate %d "
|
|
|
|
"counters\n", num_counters);
|
|
|
|
ret = -ENOMEM;
|
2010-09-29 21:42:30 +08:00
|
|
|
num_counters = 0;
|
2010-09-28 03:45:08 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
2012-02-24 00:07:06 +08:00
|
|
|
per_cpu(perf_events, cpu) = kcalloc(num_counters,
|
2010-09-28 03:45:08 +08:00
|
|
|
sizeof(struct perf_event *), GFP_KERNEL);
|
2012-02-24 00:07:06 +08:00
|
|
|
if (!per_cpu(perf_events, cpu)) {
|
2010-09-28 03:45:08 +08:00
|
|
|
pr_info("oprofile: failed to allocate %d perf events "
|
|
|
|
"for cpu %d\n", num_counters, cpu);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ops->create_files = oprofile_perf_create_files;
|
|
|
|
ops->setup = oprofile_perf_setup;
|
|
|
|
ops->start = oprofile_perf_start;
|
|
|
|
ops->stop = oprofile_perf_stop;
|
|
|
|
ops->shutdown = oprofile_perf_stop;
|
|
|
|
ops->cpu_type = op_name_from_perf_id();
|
|
|
|
|
|
|
|
if (!ops->cpu_type)
|
|
|
|
ret = -ENODEV;
|
|
|
|
else
|
|
|
|
pr_info("oprofile: using %s\n", ops->cpu_type);
|
|
|
|
|
|
|
|
out:
|
2010-09-29 21:42:30 +08:00
|
|
|
if (ret)
|
|
|
|
oprofile_perf_exit();
|
2010-09-28 03:45:08 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|