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 14:07:57 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-04-16 22:20:36 +00:00
|
|
|
#ifndef _LINUX_KTHREAD_H
|
|
|
|
#define _LINUX_KTHREAD_H
|
|
|
|
/* Simple interface for creating and stopping kernel threads without mess. */
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
|
2020-06-11 01:41:59 +00:00
|
|
|
struct mm_struct;
|
|
|
|
|
2011-11-01 00:11:33 +00:00
|
|
|
__printf(4, 5)
|
2011-03-22 23:30:44 +00:00
|
|
|
struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
|
|
|
|
void *data,
|
|
|
|
int node,
|
2011-11-01 00:11:33 +00:00
|
|
|
const char namefmt[], ...);
|
2011-03-22 23:30:44 +00:00
|
|
|
|
2016-10-11 20:55:53 +00:00
|
|
|
/**
|
|
|
|
* kthread_create - create a kthread on the current node
|
|
|
|
* @threadfn: the function to run in the thread
|
|
|
|
* @data: data pointer for @threadfn()
|
|
|
|
* @namefmt: printf-style format string for the thread name
|
2021-06-29 02:33:32 +00:00
|
|
|
* @arg: arguments for @namefmt.
|
2016-10-11 20:55:53 +00:00
|
|
|
*
|
|
|
|
* This macro will create a kthread on the current node, leaving it in
|
|
|
|
* the stopped state. This is just a helper for kthread_create_on_node();
|
|
|
|
* see the documentation there for more details.
|
|
|
|
*/
|
2011-03-22 23:30:44 +00:00
|
|
|
#define kthread_create(threadfn, data, namefmt, arg...) \
|
2015-09-04 22:42:42 +00:00
|
|
|
kthread_create_on_node(threadfn, data, NUMA_NO_NODE, namefmt, ##arg)
|
2011-03-22 23:30:44 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-07-16 10:42:36 +00:00
|
|
|
struct task_struct *kthread_create_on_cpu(int (*threadfn)(void *data),
|
|
|
|
void *data,
|
|
|
|
unsigned int cpu,
|
|
|
|
const char *namefmt);
|
|
|
|
|
kthread: dynamically allocate memory to store kthread's full name
When I was implementing a new per-cpu kthread cfs_migration, I found the
comm of it "cfs_migration/%u" is truncated due to the limitation of
TASK_COMM_LEN. For example, the comm of the percpu thread on CPU10~19
all have the same name "cfs_migration/1", which will confuse the user.
This issue is not critical, because we can get the corresponding CPU
from the task's Cpus_allowed. But for kthreads corresponding to other
hardware devices, it is not easy to get the detailed device info from
task comm, for example,
jbd2/nvme0n1p2-
xfs-reclaim/sdf
Currently there are so many truncated kthreads:
rcu_tasks_kthre
rcu_tasks_rude_
rcu_tasks_trace
poll_mpt3sas0_s
ext4-rsv-conver
xfs-reclaim/sd{a, b, c, ...}
xfs-blockgc/sd{a, b, c, ...}
xfs-inodegc/sd{a, b, c, ...}
audit_send_repl
ecryptfs-kthrea
vfio-irqfd-clea
jbd2/nvme0n1p2-
...
We can shorten these names to work around this problem, but it may be
not applied to all of the truncated kthreads. Take 'jbd2/nvme0n1p2-'
for example, it is a nice name, and it is not a good idea to shorten it.
One possible way to fix this issue is extending the task comm size, but
as task->comm is used in lots of places, that may cause some potential
buffer overflows. Another more conservative approach is introducing a
new pointer to store kthread's full name if it is truncated, which won't
introduce too much overhead as it is in the non-critical path. Finally
we make a dicision to use the second approach. See also the discussions
in this thread:
https://lore.kernel.org/lkml/20211101060419.4682-1-laoar.shao@gmail.com/
After this change, the full name of these truncated kthreads will be
displayed via /proc/[pid]/comm:
rcu_tasks_kthread
rcu_tasks_rude_kthread
rcu_tasks_trace_kthread
poll_mpt3sas0_statu
ext4-rsv-conversion
xfs-reclaim/sdf1
xfs-blockgc/sdf1
xfs-inodegc/sdf1
audit_send_reply
ecryptfs-kthread
vfio-irqfd-cleanup
jbd2/nvme0n1p2-8
Link: https://lkml.kernel.org/r/20211120112850.46047-1-laoar.shao@gmail.com
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Suggested-by: Petr Mladek <pmladek@suse.com>
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Michal Miroslaw <mirq-linux@rere.qmqm.pl>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-01-20 02:08:43 +00:00
|
|
|
void get_kthread_comm(char *buf, size_t buf_size, struct task_struct *tsk);
|
2021-12-02 15:56:14 +00:00
|
|
|
bool set_kthread_struct(struct task_struct *p);
|
2021-05-10 15:10:23 +00:00
|
|
|
|
2021-01-12 10:24:04 +00:00
|
|
|
void kthread_set_per_cpu(struct task_struct *k, int cpu);
|
|
|
|
bool kthread_is_per_cpu(struct task_struct *k);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/**
|
2006-06-25 12:49:19 +00:00
|
|
|
* kthread_run - create and wake a thread.
|
2005-04-16 22:20:36 +00:00
|
|
|
* @threadfn: the function to run until signal_pending(current).
|
|
|
|
* @data: data ptr for @threadfn.
|
|
|
|
* @namefmt: printf-style name for the thread.
|
|
|
|
*
|
|
|
|
* Description: Convenient wrapper for kthread_create() followed by
|
2006-06-25 12:49:19 +00:00
|
|
|
* wake_up_process(). Returns the kthread or ERR_PTR(-ENOMEM).
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
#define kthread_run(threadfn, data, namefmt, ...) \
|
|
|
|
({ \
|
|
|
|
struct task_struct *__k \
|
|
|
|
= kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \
|
|
|
|
if (!IS_ERR(__k)) \
|
|
|
|
wake_up_process(__k); \
|
|
|
|
__k; \
|
|
|
|
})
|
|
|
|
|
2022-01-14 22:02:52 +00:00
|
|
|
/**
|
|
|
|
* kthread_run_on_cpu - create and wake a cpu bound thread.
|
|
|
|
* @threadfn: the function to run until signal_pending(current).
|
|
|
|
* @data: data ptr for @threadfn.
|
|
|
|
* @cpu: The cpu on which the thread should be bound,
|
|
|
|
* @namefmt: printf-style name for the thread. Format is restricted
|
|
|
|
* to "name.*%u". Code fills in cpu number.
|
|
|
|
*
|
|
|
|
* Description: Convenient wrapper for kthread_create_on_cpu()
|
|
|
|
* followed by wake_up_process(). Returns the kthread or
|
|
|
|
* ERR_PTR(-ENOMEM).
|
|
|
|
*/
|
|
|
|
static inline struct task_struct *
|
|
|
|
kthread_run_on_cpu(int (*threadfn)(void *data), void *data,
|
|
|
|
unsigned int cpu, const char *namefmt)
|
|
|
|
{
|
|
|
|
struct task_struct *p;
|
|
|
|
|
|
|
|
p = kthread_create_on_cpu(threadfn, data, cpu, namefmt);
|
|
|
|
if (!IS_ERR(p))
|
|
|
|
wake_up_process(p);
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2016-11-29 17:50:57 +00:00
|
|
|
void free_kthread_struct(struct task_struct *k);
|
2005-04-16 22:20:36 +00:00
|
|
|
void kthread_bind(struct task_struct *k, unsigned int cpu);
|
2015-05-15 15:43:34 +00:00
|
|
|
void kthread_bind_mask(struct task_struct *k, const struct cpumask *mask);
|
2005-04-16 22:20:36 +00:00
|
|
|
int kthread_stop(struct task_struct *k);
|
2012-07-16 10:42:36 +00:00
|
|
|
bool kthread_should_stop(void);
|
|
|
|
bool kthread_should_park(void);
|
2023-06-02 21:23:46 +00:00
|
|
|
bool kthread_should_stop_or_park(void);
|
2011-11-21 20:32:23 +00:00
|
|
|
bool kthread_freezable_should_stop(bool *was_frozen);
|
2020-05-06 16:09:34 +00:00
|
|
|
void *kthread_func(struct task_struct *k);
|
2010-06-29 08:07:09 +00:00
|
|
|
void *kthread_data(struct task_struct *k);
|
2016-10-11 20:55:17 +00:00
|
|
|
void *kthread_probe_data(struct task_struct *k);
|
2012-07-16 10:42:36 +00:00
|
|
|
int kthread_park(struct task_struct *k);
|
|
|
|
void kthread_unpark(struct task_struct *k);
|
|
|
|
void kthread_parkme(void);
|
2021-11-22 16:27:36 +00:00
|
|
|
void kthread_exit(long result) __noreturn;
|
2021-11-22 17:15:19 +00:00
|
|
|
void kthread_complete_and_exit(struct completion *, long) __noreturn;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-05-09 09:34:32 +00:00
|
|
|
int kthreadd(void *unused);
|
|
|
|
extern struct task_struct *kthreadd_task;
|
2011-03-22 23:30:44 +00:00
|
|
|
extern int tsk_fork_get_node(struct task_struct *tsk);
|
2007-05-09 09:34:32 +00:00
|
|
|
|
2010-06-29 08:07:09 +00:00
|
|
|
/*
|
|
|
|
* Simple work processor based on kthread.
|
|
|
|
*
|
|
|
|
* This provides easier way to make use of kthreads. A kthread_work
|
2016-10-11 20:55:20 +00:00
|
|
|
* can be queued and flushed using queue/kthread_flush_work()
|
2010-06-29 08:07:09 +00:00
|
|
|
* respectively. Queued kthread_works are processed by a kthread
|
|
|
|
* running kthread_worker_fn().
|
|
|
|
*/
|
|
|
|
struct kthread_work;
|
|
|
|
typedef void (*kthread_work_func_t)(struct kthread_work *work);
|
2017-10-04 23:27:06 +00:00
|
|
|
void kthread_delayed_work_timer_fn(struct timer_list *t);
|
2010-06-29 08:07:09 +00:00
|
|
|
|
2016-10-11 20:55:50 +00:00
|
|
|
enum {
|
|
|
|
KTW_FREEZABLE = 1 << 0, /* freeze during suspend */
|
|
|
|
};
|
|
|
|
|
2010-06-29 08:07:09 +00:00
|
|
|
struct kthread_worker {
|
2016-10-11 20:55:50 +00:00
|
|
|
unsigned int flags;
|
2019-02-12 16:25:53 +00:00
|
|
|
raw_spinlock_t lock;
|
2010-06-29 08:07:09 +00:00
|
|
|
struct list_head work_list;
|
2016-10-11 20:55:40 +00:00
|
|
|
struct list_head delayed_work_list;
|
2010-06-29 08:07:09 +00:00
|
|
|
struct task_struct *task;
|
2012-07-19 20:52:53 +00:00
|
|
|
struct kthread_work *current_work;
|
2010-06-29 08:07:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct kthread_work {
|
|
|
|
struct list_head node;
|
|
|
|
kthread_work_func_t func;
|
2012-07-19 20:52:53 +00:00
|
|
|
struct kthread_worker *worker;
|
kthread: allow to cancel kthread work
We are going to use kthread workers more widely and sometimes we will need
to make sure that the work is neither pending nor running.
This patch implements cancel_*_sync() operations as inspired by
workqueues. Well, we are synchronized against the other operations via
the worker lock, we use del_timer_sync() and a counter to count parallel
cancel operations. Therefore the implementation might be easier.
First, we check if a worker is assigned. If not, the work has newer been
queued after it was initialized.
Second, we take the worker lock. It must be the right one. The work must
not be assigned to another worker unless it is initialized in between.
Third, we try to cancel the timer when it exists. The timer is deleted
synchronously to make sure that the timer call back is not running. We
need to temporary release the worker->lock to avoid a possible deadlock
with the callback. In the meantime, we set work->canceling counter to
avoid any queuing.
Fourth, we try to remove the work from a worker list. It might be
the list of either normal or delayed works.
Fifth, if the work is running, we call kthread_flush_work(). It might
take an arbitrary time. We need to release the worker-lock again. In the
meantime, we again block any queuing by the canceling counter.
As already mentioned, the check for a pending kthread work is done under a
lock. In compare with workqueues, we do not need to fight for a single
PENDING bit to block other operations. Therefore we do not suffer from
the thundering storm problem and all parallel canceling jobs might use
kthread_flush_work(). Any queuing is blocked until the counter gets zero.
Link: http://lkml.kernel.org/r/1470754545-17632-10-git-send-email-pmladek@suse.com
Signed-off-by: Petr Mladek <pmladek@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Borislav Petkov <bp@suse.de>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-10-11 20:55:43 +00:00
|
|
|
/* Number of canceling calls that are running at the moment. */
|
|
|
|
int canceling;
|
2010-06-29 08:07:09 +00:00
|
|
|
};
|
|
|
|
|
2016-10-11 20:55:40 +00:00
|
|
|
struct kthread_delayed_work {
|
|
|
|
struct kthread_work work;
|
|
|
|
struct timer_list timer;
|
|
|
|
};
|
|
|
|
|
2010-06-29 08:07:09 +00:00
|
|
|
#define KTHREAD_WORK_INIT(work, fn) { \
|
|
|
|
.node = LIST_HEAD_INIT((work).node), \
|
|
|
|
.func = (fn), \
|
|
|
|
}
|
|
|
|
|
2016-10-11 20:55:40 +00:00
|
|
|
#define KTHREAD_DELAYED_WORK_INIT(dwork, fn) { \
|
|
|
|
.work = KTHREAD_WORK_INIT((dwork).work, (fn)), \
|
2017-10-23 07:40:42 +00:00
|
|
|
.timer = __TIMER_INITIALIZER(kthread_delayed_work_timer_fn,\
|
2016-10-11 20:55:40 +00:00
|
|
|
TIMER_IRQSAFE), \
|
|
|
|
}
|
|
|
|
|
2010-06-29 08:07:09 +00:00
|
|
|
#define DEFINE_KTHREAD_WORK(work, fn) \
|
|
|
|
struct kthread_work work = KTHREAD_WORK_INIT(work, fn)
|
|
|
|
|
2016-10-11 20:55:40 +00:00
|
|
|
#define DEFINE_KTHREAD_DELAYED_WORK(dwork, fn) \
|
|
|
|
struct kthread_delayed_work dwork = \
|
|
|
|
KTHREAD_DELAYED_WORK_INIT(dwork, fn)
|
|
|
|
|
2016-10-11 20:55:20 +00:00
|
|
|
extern void __kthread_init_worker(struct kthread_worker *worker,
|
2010-12-22 09:27:53 +00:00
|
|
|
const char *name, struct lock_class_key *key);
|
|
|
|
|
2016-10-11 20:55:20 +00:00
|
|
|
#define kthread_init_worker(worker) \
|
2010-12-22 09:27:53 +00:00
|
|
|
do { \
|
|
|
|
static struct lock_class_key __key; \
|
2016-10-11 20:55:20 +00:00
|
|
|
__kthread_init_worker((worker), "("#worker")->lock", &__key); \
|
2010-12-22 09:27:53 +00:00
|
|
|
} while (0)
|
|
|
|
|
2016-10-11 20:55:20 +00:00
|
|
|
#define kthread_init_work(work, fn) \
|
2010-12-22 09:27:53 +00:00
|
|
|
do { \
|
|
|
|
memset((work), 0, sizeof(struct kthread_work)); \
|
|
|
|
INIT_LIST_HEAD(&(work)->node); \
|
|
|
|
(work)->func = (fn); \
|
|
|
|
} while (0)
|
2010-06-29 08:07:09 +00:00
|
|
|
|
2016-10-11 20:55:40 +00:00
|
|
|
#define kthread_init_delayed_work(dwork, fn) \
|
|
|
|
do { \
|
|
|
|
kthread_init_work(&(dwork)->work, (fn)); \
|
2019-02-12 16:25:54 +00:00
|
|
|
timer_setup(&(dwork)->timer, \
|
2020-04-02 04:02:28 +00:00
|
|
|
kthread_delayed_work_timer_fn, \
|
|
|
|
TIMER_IRQSAFE); \
|
2016-10-11 20:55:40 +00:00
|
|
|
} while (0)
|
|
|
|
|
2010-06-29 08:07:09 +00:00
|
|
|
int kthread_worker_fn(void *worker_ptr);
|
|
|
|
|
2016-10-11 20:55:50 +00:00
|
|
|
__printf(2, 3)
|
kthread: add kthread_create_worker*()
Kthread workers are currently created using the classic kthread API,
namely kthread_run(). kthread_worker_fn() is passed as the @threadfn
parameter.
This patch defines kthread_create_worker() and
kthread_create_worker_on_cpu() functions that hide implementation details.
They enforce using kthread_worker_fn() for the main thread. But I doubt
that there are any plans to create any alternative. In fact, I think that
we do not want any alternative main thread because it would be hard to
support consistency with the rest of the kthread worker API.
The naming and function of kthread_create_worker() is inspired by the
workqueues API like the rest of the kthread worker API.
The kthread_create_worker_on_cpu() variant is motivated by the original
kthread_create_on_cpu(). Note that we need to bind per-CPU kthread
workers already when they are created. It makes the life easier.
kthread_bind() could not be used later for an already running worker.
This patch does _not_ convert existing kthread workers. The kthread
worker API need more improvements first, e.g. a function to destroy the
worker.
IMPORTANT:
kthread_create_worker_on_cpu() allows to use any format of the worker
name, in compare with kthread_create_on_cpu(). The good thing is that it
is more generic. The bad thing is that most users will need to pass the
cpu number in two parameters, e.g. kthread_create_worker_on_cpu(cpu,
"helper/%d", cpu).
To be honest, the main motivation was to avoid the need for an empty
va_list. The only legal way was to create a helper function that would be
called with an empty list. Other attempts caused compilation warnings or
even errors on different architectures.
There were also other alternatives, for example, using #define or
splitting __kthread_create_worker(). The used solution looked like the
least ugly.
Link: http://lkml.kernel.org/r/1470754545-17632-6-git-send-email-pmladek@suse.com
Signed-off-by: Petr Mladek <pmladek@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Borislav Petkov <bp@suse.de>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-10-11 20:55:30 +00:00
|
|
|
struct kthread_worker *
|
2016-10-11 20:55:50 +00:00
|
|
|
kthread_create_worker(unsigned int flags, const char namefmt[], ...);
|
kthread: add kthread_create_worker*()
Kthread workers are currently created using the classic kthread API,
namely kthread_run(). kthread_worker_fn() is passed as the @threadfn
parameter.
This patch defines kthread_create_worker() and
kthread_create_worker_on_cpu() functions that hide implementation details.
They enforce using kthread_worker_fn() for the main thread. But I doubt
that there are any plans to create any alternative. In fact, I think that
we do not want any alternative main thread because it would be hard to
support consistency with the rest of the kthread worker API.
The naming and function of kthread_create_worker() is inspired by the
workqueues API like the rest of the kthread worker API.
The kthread_create_worker_on_cpu() variant is motivated by the original
kthread_create_on_cpu(). Note that we need to bind per-CPU kthread
workers already when they are created. It makes the life easier.
kthread_bind() could not be used later for an already running worker.
This patch does _not_ convert existing kthread workers. The kthread
worker API need more improvements first, e.g. a function to destroy the
worker.
IMPORTANT:
kthread_create_worker_on_cpu() allows to use any format of the worker
name, in compare with kthread_create_on_cpu(). The good thing is that it
is more generic. The bad thing is that most users will need to pass the
cpu number in two parameters, e.g. kthread_create_worker_on_cpu(cpu,
"helper/%d", cpu).
To be honest, the main motivation was to avoid the need for an empty
va_list. The only legal way was to create a helper function that would be
called with an empty list. Other attempts caused compilation warnings or
even errors on different architectures.
There were also other alternatives, for example, using #define or
splitting __kthread_create_worker(). The used solution looked like the
least ugly.
Link: http://lkml.kernel.org/r/1470754545-17632-6-git-send-email-pmladek@suse.com
Signed-off-by: Petr Mladek <pmladek@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Borislav Petkov <bp@suse.de>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-10-11 20:55:30 +00:00
|
|
|
|
2016-12-13 00:40:39 +00:00
|
|
|
__printf(3, 4) struct kthread_worker *
|
2016-10-11 20:55:50 +00:00
|
|
|
kthread_create_worker_on_cpu(int cpu, unsigned int flags,
|
|
|
|
const char namefmt[], ...);
|
kthread: add kthread_create_worker*()
Kthread workers are currently created using the classic kthread API,
namely kthread_run(). kthread_worker_fn() is passed as the @threadfn
parameter.
This patch defines kthread_create_worker() and
kthread_create_worker_on_cpu() functions that hide implementation details.
They enforce using kthread_worker_fn() for the main thread. But I doubt
that there are any plans to create any alternative. In fact, I think that
we do not want any alternative main thread because it would be hard to
support consistency with the rest of the kthread worker API.
The naming and function of kthread_create_worker() is inspired by the
workqueues API like the rest of the kthread worker API.
The kthread_create_worker_on_cpu() variant is motivated by the original
kthread_create_on_cpu(). Note that we need to bind per-CPU kthread
workers already when they are created. It makes the life easier.
kthread_bind() could not be used later for an already running worker.
This patch does _not_ convert existing kthread workers. The kthread
worker API need more improvements first, e.g. a function to destroy the
worker.
IMPORTANT:
kthread_create_worker_on_cpu() allows to use any format of the worker
name, in compare with kthread_create_on_cpu(). The good thing is that it
is more generic. The bad thing is that most users will need to pass the
cpu number in two parameters, e.g. kthread_create_worker_on_cpu(cpu,
"helper/%d", cpu).
To be honest, the main motivation was to avoid the need for an empty
va_list. The only legal way was to create a helper function that would be
called with an empty list. Other attempts caused compilation warnings or
even errors on different architectures.
There were also other alternatives, for example, using #define or
splitting __kthread_create_worker(). The used solution looked like the
least ugly.
Link: http://lkml.kernel.org/r/1470754545-17632-6-git-send-email-pmladek@suse.com
Signed-off-by: Petr Mladek <pmladek@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Borislav Petkov <bp@suse.de>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-10-11 20:55:30 +00:00
|
|
|
|
2016-10-11 20:55:20 +00:00
|
|
|
bool kthread_queue_work(struct kthread_worker *worker,
|
2010-06-29 08:07:09 +00:00
|
|
|
struct kthread_work *work);
|
2016-10-11 20:55:40 +00:00
|
|
|
|
|
|
|
bool kthread_queue_delayed_work(struct kthread_worker *worker,
|
|
|
|
struct kthread_delayed_work *dwork,
|
|
|
|
unsigned long delay);
|
|
|
|
|
2016-10-11 20:55:46 +00:00
|
|
|
bool kthread_mod_delayed_work(struct kthread_worker *worker,
|
|
|
|
struct kthread_delayed_work *dwork,
|
|
|
|
unsigned long delay);
|
|
|
|
|
2016-10-11 20:55:20 +00:00
|
|
|
void kthread_flush_work(struct kthread_work *work);
|
|
|
|
void kthread_flush_worker(struct kthread_worker *worker);
|
2010-06-29 08:07:09 +00:00
|
|
|
|
kthread: allow to cancel kthread work
We are going to use kthread workers more widely and sometimes we will need
to make sure that the work is neither pending nor running.
This patch implements cancel_*_sync() operations as inspired by
workqueues. Well, we are synchronized against the other operations via
the worker lock, we use del_timer_sync() and a counter to count parallel
cancel operations. Therefore the implementation might be easier.
First, we check if a worker is assigned. If not, the work has newer been
queued after it was initialized.
Second, we take the worker lock. It must be the right one. The work must
not be assigned to another worker unless it is initialized in between.
Third, we try to cancel the timer when it exists. The timer is deleted
synchronously to make sure that the timer call back is not running. We
need to temporary release the worker->lock to avoid a possible deadlock
with the callback. In the meantime, we set work->canceling counter to
avoid any queuing.
Fourth, we try to remove the work from a worker list. It might be
the list of either normal or delayed works.
Fifth, if the work is running, we call kthread_flush_work(). It might
take an arbitrary time. We need to release the worker-lock again. In the
meantime, we again block any queuing by the canceling counter.
As already mentioned, the check for a pending kthread work is done under a
lock. In compare with workqueues, we do not need to fight for a single
PENDING bit to block other operations. Therefore we do not suffer from
the thundering storm problem and all parallel canceling jobs might use
kthread_flush_work(). Any queuing is blocked until the counter gets zero.
Link: http://lkml.kernel.org/r/1470754545-17632-10-git-send-email-pmladek@suse.com
Signed-off-by: Petr Mladek <pmladek@suse.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Borislav Petkov <bp@suse.de>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-10-11 20:55:43 +00:00
|
|
|
bool kthread_cancel_work_sync(struct kthread_work *work);
|
|
|
|
bool kthread_cancel_delayed_work_sync(struct kthread_delayed_work *work);
|
|
|
|
|
2016-10-11 20:55:33 +00:00
|
|
|
void kthread_destroy_worker(struct kthread_worker *worker);
|
|
|
|
|
2020-06-11 01:42:06 +00:00
|
|
|
void kthread_use_mm(struct mm_struct *mm);
|
|
|
|
void kthread_unuse_mm(struct mm_struct *mm);
|
2020-06-11 01:41:59 +00:00
|
|
|
|
2019-05-14 22:41:12 +00:00
|
|
|
struct cgroup_subsys_state;
|
|
|
|
|
2017-09-26 18:02:12 +00:00
|
|
|
#ifdef CONFIG_BLK_CGROUP
|
2017-09-14 21:02:04 +00:00
|
|
|
void kthread_associate_blkcg(struct cgroup_subsys_state *css);
|
|
|
|
struct cgroup_subsys_state *kthread_blkcg(void);
|
|
|
|
#else
|
|
|
|
static inline void kthread_associate_blkcg(struct cgroup_subsys_state *css) { }
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* _LINUX_KTHREAD_H */
|