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 */
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifndef __LINUX_PREEMPT_H
|
|
|
|
#define __LINUX_PREEMPT_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* include/linux/preempt.h - macros for accessing and manipulating
|
|
|
|
* preempt_count (used for kernel preemption, interrupt count, etc.)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/linkage.h>
|
2007-07-26 19:40:43 +08:00
|
|
|
#include <linux/list.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related
symbols: preempt, softirq, hardirq, nmi, preempt active, need resched,
etc...
preempt.h defines the accessors and mutators of preempt_count.
But there is a messy dependency game around those two header files:
* preempt_mask.h includes preempt.h in order to access preempt_count()
* preempt_mask.h defines all preempt_count semantic and symbols
except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h
Thus we need to define it from preempt.h, right before including
asm/preempt.h, instead of defining it to preempt_mask.h with the
other preempt_count symbols. Therefore the preempt_count semantics
happen to be spread out.
* We plan to introduce preempt_active_[enter,exit]() to consolidate
preempt_schedule*() code. But we'll need to access both preempt_count
mutators (preempt_count_add()) and preempt_count symbols
(PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt
operations is in preempt.h but then we'll need symbols in
preempt_mask.h which already includes preempt.h. So we end up with
a ressource circle dependency.
Lets merge preempt_mask.h into preempt.h to solve these dependency issues.
This way we gather semantic symbols and operation definition of
preempt_count in a single file.
This is a dumb copy-paste merge. Further merge re-arrangments are
performed in a subsequent patch to ease review.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-12 22:41:46 +08:00
|
|
|
/*
|
|
|
|
* We put the hardirq and softirq counter into the preemption
|
|
|
|
* counter. The bitmask has the following meaning:
|
|
|
|
*
|
|
|
|
* - bits 0-7 are the preemption count (max preemption depth: 256)
|
|
|
|
* - bits 8-15 are the softirq count (max # of softirqs: 256)
|
|
|
|
*
|
|
|
|
* The hardirq count could in theory be the same as the number of
|
|
|
|
* interrupts in the system, but we run all interrupt handlers with
|
|
|
|
* interrupts disabled, so we cannot have nesting interrupts. Though
|
|
|
|
* there are a few palaeontologic drivers which reenable interrupts in
|
|
|
|
* the handler, so we need more than one bit here.
|
|
|
|
*
|
2015-05-12 22:41:47 +08:00
|
|
|
* PREEMPT_MASK: 0x000000ff
|
|
|
|
* SOFTIRQ_MASK: 0x0000ff00
|
|
|
|
* HARDIRQ_MASK: 0x000f0000
|
2020-02-19 16:46:47 +08:00
|
|
|
* NMI_MASK: 0x00f00000
|
2015-05-12 22:41:47 +08:00
|
|
|
* PREEMPT_NEED_RESCHED: 0x80000000
|
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related
symbols: preempt, softirq, hardirq, nmi, preempt active, need resched,
etc...
preempt.h defines the accessors and mutators of preempt_count.
But there is a messy dependency game around those two header files:
* preempt_mask.h includes preempt.h in order to access preempt_count()
* preempt_mask.h defines all preempt_count semantic and symbols
except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h
Thus we need to define it from preempt.h, right before including
asm/preempt.h, instead of defining it to preempt_mask.h with the
other preempt_count symbols. Therefore the preempt_count semantics
happen to be spread out.
* We plan to introduce preempt_active_[enter,exit]() to consolidate
preempt_schedule*() code. But we'll need to access both preempt_count
mutators (preempt_count_add()) and preempt_count symbols
(PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt
operations is in preempt.h but then we'll need symbols in
preempt_mask.h which already includes preempt.h. So we end up with
a ressource circle dependency.
Lets merge preempt_mask.h into preempt.h to solve these dependency issues.
This way we gather semantic symbols and operation definition of
preempt_count in a single file.
This is a dumb copy-paste merge. Further merge re-arrangments are
performed in a subsequent patch to ease review.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-12 22:41:46 +08:00
|
|
|
*/
|
|
|
|
#define PREEMPT_BITS 8
|
|
|
|
#define SOFTIRQ_BITS 8
|
|
|
|
#define HARDIRQ_BITS 4
|
2020-02-19 16:46:47 +08:00
|
|
|
#define NMI_BITS 4
|
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related
symbols: preempt, softirq, hardirq, nmi, preempt active, need resched,
etc...
preempt.h defines the accessors and mutators of preempt_count.
But there is a messy dependency game around those two header files:
* preempt_mask.h includes preempt.h in order to access preempt_count()
* preempt_mask.h defines all preempt_count semantic and symbols
except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h
Thus we need to define it from preempt.h, right before including
asm/preempt.h, instead of defining it to preempt_mask.h with the
other preempt_count symbols. Therefore the preempt_count semantics
happen to be spread out.
* We plan to introduce preempt_active_[enter,exit]() to consolidate
preempt_schedule*() code. But we'll need to access both preempt_count
mutators (preempt_count_add()) and preempt_count symbols
(PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt
operations is in preempt.h but then we'll need symbols in
preempt_mask.h which already includes preempt.h. So we end up with
a ressource circle dependency.
Lets merge preempt_mask.h into preempt.h to solve these dependency issues.
This way we gather semantic symbols and operation definition of
preempt_count in a single file.
This is a dumb copy-paste merge. Further merge re-arrangments are
performed in a subsequent patch to ease review.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-12 22:41:46 +08:00
|
|
|
|
|
|
|
#define PREEMPT_SHIFT 0
|
|
|
|
#define SOFTIRQ_SHIFT (PREEMPT_SHIFT + PREEMPT_BITS)
|
|
|
|
#define HARDIRQ_SHIFT (SOFTIRQ_SHIFT + SOFTIRQ_BITS)
|
|
|
|
#define NMI_SHIFT (HARDIRQ_SHIFT + HARDIRQ_BITS)
|
|
|
|
|
|
|
|
#define __IRQ_MASK(x) ((1UL << (x))-1)
|
|
|
|
|
|
|
|
#define PREEMPT_MASK (__IRQ_MASK(PREEMPT_BITS) << PREEMPT_SHIFT)
|
|
|
|
#define SOFTIRQ_MASK (__IRQ_MASK(SOFTIRQ_BITS) << SOFTIRQ_SHIFT)
|
|
|
|
#define HARDIRQ_MASK (__IRQ_MASK(HARDIRQ_BITS) << HARDIRQ_SHIFT)
|
|
|
|
#define NMI_MASK (__IRQ_MASK(NMI_BITS) << NMI_SHIFT)
|
|
|
|
|
|
|
|
#define PREEMPT_OFFSET (1UL << PREEMPT_SHIFT)
|
|
|
|
#define SOFTIRQ_OFFSET (1UL << SOFTIRQ_SHIFT)
|
|
|
|
#define HARDIRQ_OFFSET (1UL << HARDIRQ_SHIFT)
|
|
|
|
#define NMI_OFFSET (1UL << NMI_SHIFT)
|
|
|
|
|
|
|
|
#define SOFTIRQ_DISABLE_OFFSET (2 * SOFTIRQ_OFFSET)
|
|
|
|
|
2017-02-04 05:07:57 +08:00
|
|
|
#define PREEMPT_DISABLED (PREEMPT_DISABLE_OFFSET + PREEMPT_ENABLED)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable preemption until the scheduler is running -- use an unconditional
|
|
|
|
* value so that it also works on !PREEMPT_COUNT kernels.
|
|
|
|
*
|
|
|
|
* Reset by start_kernel()->sched_init()->init_idle()->init_idle_preempt_count().
|
|
|
|
*/
|
|
|
|
#define INIT_PREEMPT_COUNT PREEMPT_OFFSET
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initial preempt_count value; reflects the preempt_count schedule invariant
|
|
|
|
* which states that during context switches:
|
|
|
|
*
|
|
|
|
* preempt_count() == 2*PREEMPT_DISABLE_OFFSET
|
|
|
|
*
|
|
|
|
* Note: PREEMPT_DISABLE_OFFSET is 0 for !PREEMPT_COUNT kernels.
|
|
|
|
* Note: See finish_task_switch().
|
|
|
|
*/
|
|
|
|
#define FORK_PREEMPT_COUNT (2*PREEMPT_DISABLE_OFFSET + PREEMPT_ENABLED)
|
|
|
|
|
2015-05-12 22:41:47 +08:00
|
|
|
/* preempt_count() and related functions, depends on PREEMPT_NEED_RESCHED */
|
|
|
|
#include <asm/preempt.h>
|
|
|
|
|
2021-10-16 03:01:19 +08:00
|
|
|
/**
|
|
|
|
* interrupt_context_level - return interrupt context level
|
|
|
|
*
|
|
|
|
* Returns the current interrupt context level.
|
|
|
|
* 0 - normal context
|
|
|
|
* 1 - softirq context
|
|
|
|
* 2 - hardirq context
|
|
|
|
* 3 - NMI context
|
|
|
|
*/
|
|
|
|
static __always_inline unsigned char interrupt_context_level(void)
|
|
|
|
{
|
|
|
|
unsigned long pc = preempt_count();
|
|
|
|
unsigned char level = 0;
|
|
|
|
|
|
|
|
level += !!(pc & (NMI_MASK));
|
|
|
|
level += !!(pc & (NMI_MASK | HARDIRQ_MASK));
|
|
|
|
level += !!(pc & (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET));
|
|
|
|
|
|
|
|
return level;
|
|
|
|
}
|
|
|
|
|
2020-11-13 22:02:17 +08:00
|
|
|
#define nmi_count() (preempt_count() & NMI_MASK)
|
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related
symbols: preempt, softirq, hardirq, nmi, preempt active, need resched,
etc...
preempt.h defines the accessors and mutators of preempt_count.
But there is a messy dependency game around those two header files:
* preempt_mask.h includes preempt.h in order to access preempt_count()
* preempt_mask.h defines all preempt_count semantic and symbols
except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h
Thus we need to define it from preempt.h, right before including
asm/preempt.h, instead of defining it to preempt_mask.h with the
other preempt_count symbols. Therefore the preempt_count semantics
happen to be spread out.
* We plan to introduce preempt_active_[enter,exit]() to consolidate
preempt_schedule*() code. But we'll need to access both preempt_count
mutators (preempt_count_add()) and preempt_count symbols
(PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt
operations is in preempt.h but then we'll need symbols in
preempt_mask.h which already includes preempt.h. So we end up with
a ressource circle dependency.
Lets merge preempt_mask.h into preempt.h to solve these dependency issues.
This way we gather semantic symbols and operation definition of
preempt_count in a single file.
This is a dumb copy-paste merge. Further merge re-arrangments are
performed in a subsequent patch to ease review.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-12 22:41:46 +08:00
|
|
|
#define hardirq_count() (preempt_count() & HARDIRQ_MASK)
|
2021-03-09 16:55:53 +08:00
|
|
|
#ifdef CONFIG_PREEMPT_RT
|
|
|
|
# define softirq_count() (current->softirq_disable_cnt & SOFTIRQ_MASK)
|
|
|
|
#else
|
|
|
|
# define softirq_count() (preempt_count() & SOFTIRQ_MASK)
|
|
|
|
#endif
|
2020-11-13 22:02:17 +08:00
|
|
|
#define irq_count() (nmi_count() | hardirq_count() | softirq_count())
|
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related
symbols: preempt, softirq, hardirq, nmi, preempt active, need resched,
etc...
preempt.h defines the accessors and mutators of preempt_count.
But there is a messy dependency game around those two header files:
* preempt_mask.h includes preempt.h in order to access preempt_count()
* preempt_mask.h defines all preempt_count semantic and symbols
except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h
Thus we need to define it from preempt.h, right before including
asm/preempt.h, instead of defining it to preempt_mask.h with the
other preempt_count symbols. Therefore the preempt_count semantics
happen to be spread out.
* We plan to introduce preempt_active_[enter,exit]() to consolidate
preempt_schedule*() code. But we'll need to access both preempt_count
mutators (preempt_count_add()) and preempt_count symbols
(PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt
operations is in preempt.h but then we'll need symbols in
preempt_mask.h which already includes preempt.h. So we end up with
a ressource circle dependency.
Lets merge preempt_mask.h into preempt.h to solve these dependency issues.
This way we gather semantic symbols and operation definition of
preempt_count in a single file.
This is a dumb copy-paste merge. Further merge re-arrangments are
performed in a subsequent patch to ease review.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-12 22:41:46 +08:00
|
|
|
|
|
|
|
/*
|
2020-11-13 22:02:17 +08:00
|
|
|
* Macros to retrieve the current execution context:
|
2016-11-22 17:57:15 +08:00
|
|
|
*
|
2020-11-13 22:02:17 +08:00
|
|
|
* in_nmi() - We're in NMI context
|
|
|
|
* in_hardirq() - We're in hard IRQ context
|
|
|
|
* in_serving_softirq() - We're in softirq context
|
|
|
|
* in_task() - We're in task context
|
|
|
|
*/
|
|
|
|
#define in_nmi() (nmi_count())
|
|
|
|
#define in_hardirq() (hardirq_count())
|
|
|
|
#define in_serving_softirq() (softirq_count() & SOFTIRQ_OFFSET)
|
|
|
|
#define in_task() (!(in_nmi() | in_hardirq() | in_serving_softirq()))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following macros are deprecated and should not be used in new code:
|
|
|
|
* in_irq() - Obsolete version of in_hardirq()
|
2016-11-22 17:57:15 +08:00
|
|
|
* in_softirq() - We have BH disabled, or are processing softirqs
|
|
|
|
* in_interrupt() - We're in NMI,IRQ,SoftIRQ context or have BH disabled
|
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related
symbols: preempt, softirq, hardirq, nmi, preempt active, need resched,
etc...
preempt.h defines the accessors and mutators of preempt_count.
But there is a messy dependency game around those two header files:
* preempt_mask.h includes preempt.h in order to access preempt_count()
* preempt_mask.h defines all preempt_count semantic and symbols
except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h
Thus we need to define it from preempt.h, right before including
asm/preempt.h, instead of defining it to preempt_mask.h with the
other preempt_count symbols. Therefore the preempt_count semantics
happen to be spread out.
* We plan to introduce preempt_active_[enter,exit]() to consolidate
preempt_schedule*() code. But we'll need to access both preempt_count
mutators (preempt_count_add()) and preempt_count symbols
(PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt
operations is in preempt.h but then we'll need symbols in
preempt_mask.h which already includes preempt.h. So we end up with
a ressource circle dependency.
Lets merge preempt_mask.h into preempt.h to solve these dependency issues.
This way we gather semantic symbols and operation definition of
preempt_count in a single file.
This is a dumb copy-paste merge. Further merge re-arrangments are
performed in a subsequent patch to ease review.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-12 22:41:46 +08:00
|
|
|
*/
|
|
|
|
#define in_irq() (hardirq_count())
|
|
|
|
#define in_softirq() (softirq_count())
|
|
|
|
#define in_interrupt() (irq_count())
|
|
|
|
|
2015-07-15 17:52:04 +08:00
|
|
|
/*
|
|
|
|
* The preempt_count offset after preempt_disable();
|
|
|
|
*/
|
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related
symbols: preempt, softirq, hardirq, nmi, preempt active, need resched,
etc...
preempt.h defines the accessors and mutators of preempt_count.
But there is a messy dependency game around those two header files:
* preempt_mask.h includes preempt.h in order to access preempt_count()
* preempt_mask.h defines all preempt_count semantic and symbols
except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h
Thus we need to define it from preempt.h, right before including
asm/preempt.h, instead of defining it to preempt_mask.h with the
other preempt_count symbols. Therefore the preempt_count semantics
happen to be spread out.
* We plan to introduce preempt_active_[enter,exit]() to consolidate
preempt_schedule*() code. But we'll need to access both preempt_count
mutators (preempt_count_add()) and preempt_count symbols
(PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt
operations is in preempt.h but then we'll need symbols in
preempt_mask.h which already includes preempt.h. So we end up with
a ressource circle dependency.
Lets merge preempt_mask.h into preempt.h to solve these dependency issues.
This way we gather semantic symbols and operation definition of
preempt_count in a single file.
This is a dumb copy-paste merge. Further merge re-arrangments are
performed in a subsequent patch to ease review.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-12 22:41:46 +08:00
|
|
|
#if defined(CONFIG_PREEMPT_COUNT)
|
2015-07-15 17:52:04 +08:00
|
|
|
# define PREEMPT_DISABLE_OFFSET PREEMPT_OFFSET
|
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related
symbols: preempt, softirq, hardirq, nmi, preempt active, need resched,
etc...
preempt.h defines the accessors and mutators of preempt_count.
But there is a messy dependency game around those two header files:
* preempt_mask.h includes preempt.h in order to access preempt_count()
* preempt_mask.h defines all preempt_count semantic and symbols
except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h
Thus we need to define it from preempt.h, right before including
asm/preempt.h, instead of defining it to preempt_mask.h with the
other preempt_count symbols. Therefore the preempt_count semantics
happen to be spread out.
* We plan to introduce preempt_active_[enter,exit]() to consolidate
preempt_schedule*() code. But we'll need to access both preempt_count
mutators (preempt_count_add()) and preempt_count symbols
(PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt
operations is in preempt.h but then we'll need symbols in
preempt_mask.h which already includes preempt.h. So we end up with
a ressource circle dependency.
Lets merge preempt_mask.h into preempt.h to solve these dependency issues.
This way we gather semantic symbols and operation definition of
preempt_count in a single file.
This is a dumb copy-paste merge. Further merge re-arrangments are
performed in a subsequent patch to ease review.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-12 22:41:46 +08:00
|
|
|
#else
|
2015-07-15 17:52:04 +08:00
|
|
|
# define PREEMPT_DISABLE_OFFSET 0
|
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related
symbols: preempt, softirq, hardirq, nmi, preempt active, need resched,
etc...
preempt.h defines the accessors and mutators of preempt_count.
But there is a messy dependency game around those two header files:
* preempt_mask.h includes preempt.h in order to access preempt_count()
* preempt_mask.h defines all preempt_count semantic and symbols
except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h
Thus we need to define it from preempt.h, right before including
asm/preempt.h, instead of defining it to preempt_mask.h with the
other preempt_count symbols. Therefore the preempt_count semantics
happen to be spread out.
* We plan to introduce preempt_active_[enter,exit]() to consolidate
preempt_schedule*() code. But we'll need to access both preempt_count
mutators (preempt_count_add()) and preempt_count symbols
(PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt
operations is in preempt.h but then we'll need symbols in
preempt_mask.h which already includes preempt.h. So we end up with
a ressource circle dependency.
Lets merge preempt_mask.h into preempt.h to solve these dependency issues.
This way we gather semantic symbols and operation definition of
preempt_count in a single file.
This is a dumb copy-paste merge. Further merge re-arrangments are
performed in a subsequent patch to ease review.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-12 22:41:46 +08:00
|
|
|
#endif
|
|
|
|
|
2015-07-15 17:52:04 +08:00
|
|
|
/*
|
|
|
|
* The preempt_count offset after spin_lock()
|
|
|
|
*/
|
2021-08-16 05:29:22 +08:00
|
|
|
#if !defined(CONFIG_PREEMPT_RT)
|
2021-09-24 00:54:44 +08:00
|
|
|
#define PREEMPT_LOCK_OFFSET PREEMPT_DISABLE_OFFSET
|
2021-08-16 05:29:22 +08:00
|
|
|
#else
|
2021-09-24 00:54:44 +08:00
|
|
|
/* Locks on RT do not disable preemption */
|
|
|
|
#define PREEMPT_LOCK_OFFSET 0
|
2021-08-16 05:29:22 +08:00
|
|
|
#endif
|
2015-07-15 17:52:04 +08:00
|
|
|
|
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related
symbols: preempt, softirq, hardirq, nmi, preempt active, need resched,
etc...
preempt.h defines the accessors and mutators of preempt_count.
But there is a messy dependency game around those two header files:
* preempt_mask.h includes preempt.h in order to access preempt_count()
* preempt_mask.h defines all preempt_count semantic and symbols
except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h
Thus we need to define it from preempt.h, right before including
asm/preempt.h, instead of defining it to preempt_mask.h with the
other preempt_count symbols. Therefore the preempt_count semantics
happen to be spread out.
* We plan to introduce preempt_active_[enter,exit]() to consolidate
preempt_schedule*() code. But we'll need to access both preempt_count
mutators (preempt_count_add()) and preempt_count symbols
(PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt
operations is in preempt.h but then we'll need symbols in
preempt_mask.h which already includes preempt.h. So we end up with
a ressource circle dependency.
Lets merge preempt_mask.h into preempt.h to solve these dependency issues.
This way we gather semantic symbols and operation definition of
preempt_count in a single file.
This is a dumb copy-paste merge. Further merge re-arrangments are
performed in a subsequent patch to ease review.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-12 22:41:46 +08:00
|
|
|
/*
|
|
|
|
* The preempt_count offset needed for things like:
|
|
|
|
*
|
|
|
|
* spin_lock_bh()
|
|
|
|
*
|
|
|
|
* Which need to disable both preemption (CONFIG_PREEMPT_COUNT) and
|
|
|
|
* softirqs, such that unlock sequences of:
|
|
|
|
*
|
|
|
|
* spin_unlock();
|
|
|
|
* local_bh_enable();
|
|
|
|
*
|
|
|
|
* Work as expected.
|
|
|
|
*/
|
2015-07-15 17:52:04 +08:00
|
|
|
#define SOFTIRQ_LOCK_OFFSET (SOFTIRQ_DISABLE_OFFSET + PREEMPT_LOCK_OFFSET)
|
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related
symbols: preempt, softirq, hardirq, nmi, preempt active, need resched,
etc...
preempt.h defines the accessors and mutators of preempt_count.
But there is a messy dependency game around those two header files:
* preempt_mask.h includes preempt.h in order to access preempt_count()
* preempt_mask.h defines all preempt_count semantic and symbols
except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h
Thus we need to define it from preempt.h, right before including
asm/preempt.h, instead of defining it to preempt_mask.h with the
other preempt_count symbols. Therefore the preempt_count semantics
happen to be spread out.
* We plan to introduce preempt_active_[enter,exit]() to consolidate
preempt_schedule*() code. But we'll need to access both preempt_count
mutators (preempt_count_add()) and preempt_count symbols
(PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt
operations is in preempt.h but then we'll need symbols in
preempt_mask.h which already includes preempt.h. So we end up with
a ressource circle dependency.
Lets merge preempt_mask.h into preempt.h to solve these dependency issues.
This way we gather semantic symbols and operation definition of
preempt_count in a single file.
This is a dumb copy-paste merge. Further merge re-arrangments are
performed in a subsequent patch to ease review.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-12 22:41:46 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Are we running in atomic context? WARNING: this macro cannot
|
|
|
|
* always detect atomic context; in particular, it cannot know about
|
|
|
|
* held spinlocks in non-preemptible kernels. Thus it should not be
|
|
|
|
* used in the general case to determine whether sleeping is possible.
|
|
|
|
* Do not use in_atomic() in driver code.
|
|
|
|
*/
|
2015-05-12 22:41:51 +08:00
|
|
|
#define in_atomic() (preempt_count() != 0)
|
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related
symbols: preempt, softirq, hardirq, nmi, preempt active, need resched,
etc...
preempt.h defines the accessors and mutators of preempt_count.
But there is a messy dependency game around those two header files:
* preempt_mask.h includes preempt.h in order to access preempt_count()
* preempt_mask.h defines all preempt_count semantic and symbols
except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h
Thus we need to define it from preempt.h, right before including
asm/preempt.h, instead of defining it to preempt_mask.h with the
other preempt_count symbols. Therefore the preempt_count semantics
happen to be spread out.
* We plan to introduce preempt_active_[enter,exit]() to consolidate
preempt_schedule*() code. But we'll need to access both preempt_count
mutators (preempt_count_add()) and preempt_count symbols
(PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt
operations is in preempt.h but then we'll need symbols in
preempt_mask.h which already includes preempt.h. So we end up with
a ressource circle dependency.
Lets merge preempt_mask.h into preempt.h to solve these dependency issues.
This way we gather semantic symbols and operation definition of
preempt_count in a single file.
This is a dumb copy-paste merge. Further merge re-arrangments are
performed in a subsequent patch to ease review.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-12 22:41:46 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether we were atomic before we did preempt_disable():
|
2015-05-12 22:41:50 +08:00
|
|
|
* (used by the scheduler)
|
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related
symbols: preempt, softirq, hardirq, nmi, preempt active, need resched,
etc...
preempt.h defines the accessors and mutators of preempt_count.
But there is a messy dependency game around those two header files:
* preempt_mask.h includes preempt.h in order to access preempt_count()
* preempt_mask.h defines all preempt_count semantic and symbols
except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h
Thus we need to define it from preempt.h, right before including
asm/preempt.h, instead of defining it to preempt_mask.h with the
other preempt_count symbols. Therefore the preempt_count semantics
happen to be spread out.
* We plan to introduce preempt_active_[enter,exit]() to consolidate
preempt_schedule*() code. But we'll need to access both preempt_count
mutators (preempt_count_add()) and preempt_count symbols
(PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt
operations is in preempt.h but then we'll need symbols in
preempt_mask.h which already includes preempt.h. So we end up with
a ressource circle dependency.
Lets merge preempt_mask.h into preempt.h to solve these dependency issues.
This way we gather semantic symbols and operation definition of
preempt_count in a single file.
This is a dumb copy-paste merge. Further merge re-arrangments are
performed in a subsequent patch to ease review.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-12 22:41:46 +08:00
|
|
|
*/
|
2015-09-29 00:11:45 +08:00
|
|
|
#define in_atomic_preempt_off() (preempt_count() != PREEMPT_DISABLE_OFFSET)
|
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related
symbols: preempt, softirq, hardirq, nmi, preempt active, need resched,
etc...
preempt.h defines the accessors and mutators of preempt_count.
But there is a messy dependency game around those two header files:
* preempt_mask.h includes preempt.h in order to access preempt_count()
* preempt_mask.h defines all preempt_count semantic and symbols
except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h
Thus we need to define it from preempt.h, right before including
asm/preempt.h, instead of defining it to preempt_mask.h with the
other preempt_count symbols. Therefore the preempt_count semantics
happen to be spread out.
* We plan to introduce preempt_active_[enter,exit]() to consolidate
preempt_schedule*() code. But we'll need to access both preempt_count
mutators (preempt_count_add()) and preempt_count symbols
(PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt
operations is in preempt.h but then we'll need symbols in
preempt_mask.h which already includes preempt.h. So we end up with
a ressource circle dependency.
Lets merge preempt_mask.h into preempt.h to solve these dependency issues.
This way we gather semantic symbols and operation definition of
preempt_count in a single file.
This is a dumb copy-paste merge. Further merge re-arrangments are
performed in a subsequent patch to ease review.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-12 22:41:46 +08:00
|
|
|
|
2018-07-31 06:24:23 +08:00
|
|
|
#if defined(CONFIG_DEBUG_PREEMPT) || defined(CONFIG_TRACE_PREEMPT_TOGGLE)
|
2013-09-10 18:15:23 +08:00
|
|
|
extern void preempt_count_add(int val);
|
|
|
|
extern void preempt_count_sub(int val);
|
2015-07-15 17:52:04 +08:00
|
|
|
#define preempt_count_dec_and_test() \
|
|
|
|
({ preempt_count_sub(1); should_resched(0); })
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
2013-09-10 18:15:23 +08:00
|
|
|
#define preempt_count_add(val) __preempt_count_add(val)
|
|
|
|
#define preempt_count_sub(val) __preempt_count_sub(val)
|
|
|
|
#define preempt_count_dec_and_test() __preempt_count_dec_and_test()
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
2013-09-10 18:15:23 +08:00
|
|
|
#define __preempt_count_inc() __preempt_count_add(1)
|
|
|
|
#define __preempt_count_dec() __preempt_count_sub(1)
|
2011-06-08 07:13:27 +08:00
|
|
|
|
2013-09-10 18:15:23 +08:00
|
|
|
#define preempt_count_inc() preempt_count_add(1)
|
|
|
|
#define preempt_count_dec() preempt_count_sub(1)
|
2011-06-08 07:13:27 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_PREEMPT_COUNT
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define preempt_disable() \
|
|
|
|
do { \
|
2013-09-10 18:15:23 +08:00
|
|
|
preempt_count_inc(); \
|
2005-04-17 06:20:36 +08:00
|
|
|
barrier(); \
|
|
|
|
} while (0)
|
|
|
|
|
2011-03-21 20:32:17 +08:00
|
|
|
#define sched_preempt_enable_no_resched() \
|
2005-04-17 06:20:36 +08:00
|
|
|
do { \
|
|
|
|
barrier(); \
|
2013-09-10 18:15:23 +08:00
|
|
|
preempt_count_dec(); \
|
2005-04-17 06:20:36 +08:00
|
|
|
} while (0)
|
|
|
|
|
2013-09-10 18:15:23 +08:00
|
|
|
#define preempt_enable_no_resched() sched_preempt_enable_no_resched()
|
2011-03-21 20:32:17 +08:00
|
|
|
|
2015-05-12 22:41:47 +08:00
|
|
|
#define preemptible() (preempt_count() == 0 && !irqs_disabled())
|
|
|
|
|
2019-07-27 05:19:37 +08:00
|
|
|
#ifdef CONFIG_PREEMPTION
|
2005-04-17 06:20:36 +08:00
|
|
|
#define preempt_enable() \
|
|
|
|
do { \
|
2013-09-10 18:15:23 +08:00
|
|
|
barrier(); \
|
|
|
|
if (unlikely(preempt_count_dec_and_test())) \
|
2013-08-14 20:51:00 +08:00
|
|
|
__preempt_schedule(); \
|
2005-04-17 06:20:36 +08:00
|
|
|
} while (0)
|
|
|
|
|
2015-06-04 23:39:09 +08:00
|
|
|
#define preempt_enable_notrace() \
|
|
|
|
do { \
|
|
|
|
barrier(); \
|
|
|
|
if (unlikely(__preempt_count_dec_and_test())) \
|
|
|
|
__preempt_schedule_notrace(); \
|
|
|
|
} while (0)
|
|
|
|
|
2013-09-10 18:15:23 +08:00
|
|
|
#define preempt_check_resched() \
|
|
|
|
do { \
|
2015-07-15 17:52:04 +08:00
|
|
|
if (should_resched(0)) \
|
2013-08-14 20:51:00 +08:00
|
|
|
__preempt_schedule(); \
|
2013-09-10 18:15:23 +08:00
|
|
|
} while (0)
|
|
|
|
|
2019-07-27 05:19:37 +08:00
|
|
|
#else /* !CONFIG_PREEMPTION */
|
2013-11-20 23:52:19 +08:00
|
|
|
#define preempt_enable() \
|
|
|
|
do { \
|
|
|
|
barrier(); \
|
|
|
|
preempt_count_dec(); \
|
|
|
|
} while (0)
|
2008-05-13 03:20:41 +08:00
|
|
|
|
2015-06-04 23:39:09 +08:00
|
|
|
#define preempt_enable_notrace() \
|
2008-05-13 03:20:41 +08:00
|
|
|
do { \
|
|
|
|
barrier(); \
|
2013-09-10 18:15:23 +08:00
|
|
|
__preempt_count_dec(); \
|
2008-05-13 03:20:41 +08:00
|
|
|
} while (0)
|
|
|
|
|
2015-06-04 23:39:09 +08:00
|
|
|
#define preempt_check_resched() do { } while (0)
|
2019-07-27 05:19:37 +08:00
|
|
|
#endif /* CONFIG_PREEMPTION */
|
2013-09-10 18:15:23 +08:00
|
|
|
|
2015-06-04 23:39:09 +08:00
|
|
|
#define preempt_disable_notrace() \
|
2008-05-13 03:20:41 +08:00
|
|
|
do { \
|
2015-06-04 23:39:09 +08:00
|
|
|
__preempt_count_inc(); \
|
2013-09-10 18:15:23 +08:00
|
|
|
barrier(); \
|
2008-05-13 03:20:41 +08:00
|
|
|
} while (0)
|
2015-06-04 23:39:09 +08:00
|
|
|
|
|
|
|
#define preempt_enable_no_resched_notrace() \
|
2013-11-20 23:52:19 +08:00
|
|
|
do { \
|
|
|
|
barrier(); \
|
|
|
|
__preempt_count_dec(); \
|
|
|
|
} while (0)
|
2008-05-13 03:20:41 +08:00
|
|
|
|
2011-06-08 07:13:27 +08:00
|
|
|
#else /* !CONFIG_PREEMPT_COUNT */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
spinlocks and preemption points need to be at least compiler barriers
In UP and non-preempt respectively, the spinlocks and preemption
disable/enable points are stubbed out entirely, because there is no
regular code that can ever hit the kind of concurrency they are meant to
protect against.
However, while there is no regular code that can cause scheduling, we
_do_ end up having some exceptional (literally!) code that can do so,
and that we need to make sure does not ever get moved into the critical
region by the compiler.
In particular, get_user() and put_user() is generally implemented as
inline asm statements (even if the inline asm may then make a call
instruction to call out-of-line), and can obviously cause a page fault
and IO as a result. If that inline asm has been scheduled into the
middle of a preemption-safe (or spinlock-protected) code region, we
obviously lose.
Now, admittedly this is *very* unlikely to actually ever happen, and
we've not seen examples of actual bugs related to this. But partly
exactly because it's so hard to trigger and the resulting bug is so
subtle, we should be extra careful to get this right.
So make sure that even when preemption is disabled, and we don't have to
generate any actual *code* to explicitly tell the system that we are in
a preemption-disabled region, we need to at least tell the compiler not
to move things around the critical region.
This patch grew out of the same discussion that caused commits
79e5f05edcbf ("ARC: Add implicit compiler barrier to raw_local_irq*
functions") and 3e2e0d2c222b ("tile: comment assumption about
__insn_mtspr for <asm/irqflags.h>") to come about.
Note for stable: use discretion when/if applying this. As mentioned,
this bug may never have actually bitten anybody, and gcc may never have
done the required code motion for it to possibly ever trigger in
practice.
Cc: stable@vger.kernel.org
Cc: Steven Rostedt <srostedt@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-04-10 01:48:33 +08:00
|
|
|
/*
|
|
|
|
* Even if we don't have any preemption, we need preempt disable/enable
|
|
|
|
* to be barriers, so that we don't have things like get_user/put_user
|
|
|
|
* that can cause faults and scheduling migrate into our preempt-protected
|
|
|
|
* region.
|
|
|
|
*/
|
2013-09-10 18:15:23 +08:00
|
|
|
#define preempt_disable() barrier()
|
spinlocks and preemption points need to be at least compiler barriers
In UP and non-preempt respectively, the spinlocks and preemption
disable/enable points are stubbed out entirely, because there is no
regular code that can ever hit the kind of concurrency they are meant to
protect against.
However, while there is no regular code that can cause scheduling, we
_do_ end up having some exceptional (literally!) code that can do so,
and that we need to make sure does not ever get moved into the critical
region by the compiler.
In particular, get_user() and put_user() is generally implemented as
inline asm statements (even if the inline asm may then make a call
instruction to call out-of-line), and can obviously cause a page fault
and IO as a result. If that inline asm has been scheduled into the
middle of a preemption-safe (or spinlock-protected) code region, we
obviously lose.
Now, admittedly this is *very* unlikely to actually ever happen, and
we've not seen examples of actual bugs related to this. But partly
exactly because it's so hard to trigger and the resulting bug is so
subtle, we should be extra careful to get this right.
So make sure that even when preemption is disabled, and we don't have to
generate any actual *code* to explicitly tell the system that we are in
a preemption-disabled region, we need to at least tell the compiler not
to move things around the critical region.
This patch grew out of the same discussion that caused commits
79e5f05edcbf ("ARC: Add implicit compiler barrier to raw_local_irq*
functions") and 3e2e0d2c222b ("tile: comment assumption about
__insn_mtspr for <asm/irqflags.h>") to come about.
Note for stable: use discretion when/if applying this. As mentioned,
this bug may never have actually bitten anybody, and gcc may never have
done the required code motion for it to possibly ever trigger in
practice.
Cc: stable@vger.kernel.org
Cc: Steven Rostedt <srostedt@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-04-10 01:48:33 +08:00
|
|
|
#define sched_preempt_enable_no_resched() barrier()
|
2013-09-10 18:15:23 +08:00
|
|
|
#define preempt_enable_no_resched() barrier()
|
|
|
|
#define preempt_enable() barrier()
|
|
|
|
#define preempt_check_resched() do { } while (0)
|
spinlocks and preemption points need to be at least compiler barriers
In UP and non-preempt respectively, the spinlocks and preemption
disable/enable points are stubbed out entirely, because there is no
regular code that can ever hit the kind of concurrency they are meant to
protect against.
However, while there is no regular code that can cause scheduling, we
_do_ end up having some exceptional (literally!) code that can do so,
and that we need to make sure does not ever get moved into the critical
region by the compiler.
In particular, get_user() and put_user() is generally implemented as
inline asm statements (even if the inline asm may then make a call
instruction to call out-of-line), and can obviously cause a page fault
and IO as a result. If that inline asm has been scheduled into the
middle of a preemption-safe (or spinlock-protected) code region, we
obviously lose.
Now, admittedly this is *very* unlikely to actually ever happen, and
we've not seen examples of actual bugs related to this. But partly
exactly because it's so hard to trigger and the resulting bug is so
subtle, we should be extra careful to get this right.
So make sure that even when preemption is disabled, and we don't have to
generate any actual *code* to explicitly tell the system that we are in
a preemption-disabled region, we need to at least tell the compiler not
to move things around the critical region.
This patch grew out of the same discussion that caused commits
79e5f05edcbf ("ARC: Add implicit compiler barrier to raw_local_irq*
functions") and 3e2e0d2c222b ("tile: comment assumption about
__insn_mtspr for <asm/irqflags.h>") to come about.
Note for stable: use discretion when/if applying this. As mentioned,
this bug may never have actually bitten anybody, and gcc may never have
done the required code motion for it to possibly ever trigger in
practice.
Cc: stable@vger.kernel.org
Cc: Steven Rostedt <srostedt@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-04-10 01:48:33 +08:00
|
|
|
|
|
|
|
#define preempt_disable_notrace() barrier()
|
|
|
|
#define preempt_enable_no_resched_notrace() barrier()
|
|
|
|
#define preempt_enable_notrace() barrier()
|
2015-05-12 22:41:47 +08:00
|
|
|
#define preemptible() 0
|
2008-05-13 03:20:41 +08:00
|
|
|
|
2011-06-08 07:13:27 +08:00
|
|
|
#endif /* CONFIG_PREEMPT_COUNT */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-11-20 23:52:19 +08:00
|
|
|
#ifdef MODULE
|
|
|
|
/*
|
|
|
|
* Modules have no business playing preemption tricks.
|
|
|
|
*/
|
|
|
|
#undef sched_preempt_enable_no_resched
|
|
|
|
#undef preempt_enable_no_resched
|
|
|
|
#undef preempt_enable_no_resched_notrace
|
|
|
|
#undef preempt_check_resched
|
|
|
|
#endif
|
|
|
|
|
2013-11-20 19:22:37 +08:00
|
|
|
#define preempt_set_need_resched() \
|
|
|
|
do { \
|
|
|
|
set_preempt_need_resched(); \
|
|
|
|
} while (0)
|
|
|
|
#define preempt_fold_need_resched() \
|
|
|
|
do { \
|
|
|
|
if (tif_need_resched()) \
|
|
|
|
set_preempt_need_resched(); \
|
|
|
|
} while (0)
|
|
|
|
|
2007-07-26 19:40:43 +08:00
|
|
|
#ifdef CONFIG_PREEMPT_NOTIFIERS
|
|
|
|
|
|
|
|
struct preempt_notifier;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* preempt_ops - notifiers called when a task is preempted and rescheduled
|
|
|
|
* @sched_in: we're about to be rescheduled:
|
|
|
|
* notifier: struct preempt_notifier for the task being scheduled
|
|
|
|
* cpu: cpu we're scheduled on
|
|
|
|
* @sched_out: we've just been preempted
|
|
|
|
* notifier: struct preempt_notifier for the task being preempted
|
|
|
|
* next: the task that's kicking us out
|
2009-12-02 11:56:46 +08:00
|
|
|
*
|
|
|
|
* Please note that sched_in and out are called under different
|
|
|
|
* contexts. sched_out is called with rq lock held and irq disabled
|
|
|
|
* while sched_in is called without rq lock and irq enabled. This
|
|
|
|
* difference is intentional and depended upon by its users.
|
2007-07-26 19:40:43 +08:00
|
|
|
*/
|
|
|
|
struct preempt_ops {
|
|
|
|
void (*sched_in)(struct preempt_notifier *notifier, int cpu);
|
|
|
|
void (*sched_out)(struct preempt_notifier *notifier,
|
|
|
|
struct task_struct *next);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* preempt_notifier - key for installing preemption notifiers
|
|
|
|
* @link: internal use
|
|
|
|
* @ops: defines the notifier functions to be called
|
|
|
|
*
|
|
|
|
* Usually used in conjunction with container_of().
|
|
|
|
*/
|
|
|
|
struct preempt_notifier {
|
|
|
|
struct hlist_node link;
|
|
|
|
struct preempt_ops *ops;
|
|
|
|
};
|
|
|
|
|
2015-07-04 00:53:58 +08:00
|
|
|
void preempt_notifier_inc(void);
|
|
|
|
void preempt_notifier_dec(void);
|
2007-07-26 19:40:43 +08:00
|
|
|
void preempt_notifier_register(struct preempt_notifier *notifier);
|
|
|
|
void preempt_notifier_unregister(struct preempt_notifier *notifier);
|
|
|
|
|
|
|
|
static inline void preempt_notifier_init(struct preempt_notifier *notifier,
|
|
|
|
struct preempt_ops *ops)
|
|
|
|
{
|
|
|
|
INIT_HLIST_NODE(¬ifier->link);
|
|
|
|
notifier->ops = ops;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-11-19 03:48:42 +08:00
|
|
|
#ifdef CONFIG_SMP
|
2020-09-17 16:38:30 +08:00
|
|
|
|
|
|
|
/*
|
2020-09-28 23:06:07 +08:00
|
|
|
* Migrate-Disable and why it is undesired.
|
2020-09-17 16:38:30 +08:00
|
|
|
*
|
2020-09-28 23:06:07 +08:00
|
|
|
* When a preempted task becomes elegible to run under the ideal model (IOW it
|
|
|
|
* becomes one of the M highest priority tasks), it might still have to wait
|
|
|
|
* for the preemptee's migrate_disable() section to complete. Thereby suffering
|
|
|
|
* a reduction in bandwidth in the exact duration of the migrate_disable()
|
|
|
|
* section.
|
2020-09-17 16:38:30 +08:00
|
|
|
*
|
2020-09-28 23:06:07 +08:00
|
|
|
* Per this argument, the change from preempt_disable() to migrate_disable()
|
|
|
|
* gets us:
|
2020-09-17 16:38:30 +08:00
|
|
|
*
|
2020-09-28 23:06:07 +08:00
|
|
|
* - a higher priority tasks gains reduced wake-up latency; with preempt_disable()
|
|
|
|
* it would have had to wait for the lower priority task.
|
|
|
|
*
|
|
|
|
* - a lower priority tasks; which under preempt_disable() could've instantly
|
|
|
|
* migrated away when another CPU becomes available, is now constrained
|
|
|
|
* by the ability to push the higher priority task away, which might itself be
|
|
|
|
* in a migrate_disable() section, reducing it's available bandwidth.
|
|
|
|
*
|
|
|
|
* IOW it trades latency / moves the interference term, but it stays in the
|
|
|
|
* system, and as long as it remains unbounded, the system is not fully
|
|
|
|
* deterministic.
|
2020-09-17 16:38:30 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* The reason we have it anyway.
|
|
|
|
*
|
|
|
|
* PREEMPT_RT breaks a number of assumptions traditionally held. By forcing a
|
|
|
|
* number of primitives into becoming preemptible, they would also allow
|
|
|
|
* migration. This turns out to break a bunch of per-cpu usage. To this end,
|
|
|
|
* all these primitives employ migirate_disable() to restore this implicit
|
|
|
|
* assumption.
|
|
|
|
*
|
|
|
|
* This is a 'temporary' work-around at best. The correct solution is getting
|
|
|
|
* rid of the above assumptions and reworking the code to employ explicit
|
|
|
|
* per-cpu locking or short preempt-disable regions.
|
|
|
|
*
|
|
|
|
* The end goal must be to get rid of migrate_disable(), alternatively we need
|
|
|
|
* a schedulability theory that does not depend on abritrary migration.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Notes on the implementation.
|
|
|
|
*
|
|
|
|
* The implementation is particularly tricky since existing code patterns
|
|
|
|
* dictate neither migrate_disable() nor migrate_enable() is allowed to block.
|
|
|
|
* This means that it cannot use cpus_read_lock() to serialize against hotplug,
|
|
|
|
* nor can it easily migrate itself into a pending affinity mask change on
|
|
|
|
* migrate_enable().
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Note: even non-work-conserving schedulers like semi-partitioned depends on
|
|
|
|
* migration, so migrate_disable() is not only a problem for
|
|
|
|
* work-conserving schedulers.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
extern void migrate_disable(void);
|
|
|
|
extern void migrate_enable(void);
|
|
|
|
|
2020-11-19 03:48:42 +08:00
|
|
|
#else
|
2020-09-17 16:38:30 +08:00
|
|
|
|
|
|
|
static inline void migrate_disable(void) { }
|
|
|
|
static inline void migrate_enable(void) { }
|
|
|
|
|
2020-11-19 03:48:42 +08:00
|
|
|
#endif /* CONFIG_SMP */
|
2020-09-17 16:38:30 +08:00
|
|
|
|
2022-08-26 00:41:24 +08:00
|
|
|
/**
|
|
|
|
* preempt_disable_nested - Disable preemption inside a normally preempt disabled section
|
|
|
|
*
|
|
|
|
* Use for code which requires preemption protection inside a critical
|
|
|
|
* section which has preemption disabled implicitly on non-PREEMPT_RT
|
|
|
|
* enabled kernels, by e.g.:
|
|
|
|
* - holding a spinlock/rwlock
|
|
|
|
* - soft interrupt context
|
|
|
|
* - regular interrupt handlers
|
|
|
|
*
|
|
|
|
* On PREEMPT_RT enabled kernels spinlock/rwlock held sections, soft
|
|
|
|
* interrupt context and regular interrupt handlers are preemptible and
|
|
|
|
* only prevent migration. preempt_disable_nested() ensures that preemption
|
|
|
|
* is disabled for cases which require CPU local serialization even on
|
|
|
|
* PREEMPT_RT. For non-PREEMPT_RT kernels this is a NOP.
|
|
|
|
*
|
|
|
|
* The use cases are code sequences which are not serialized by a
|
|
|
|
* particular lock instance, e.g.:
|
|
|
|
* - seqcount write side critical sections where the seqcount is not
|
|
|
|
* associated to a particular lock and therefore the automatic
|
|
|
|
* protection mechanism does not work. This prevents a live lock
|
|
|
|
* against a preempting high priority reader.
|
|
|
|
* - RMW per CPU variable updates like vmstat.
|
|
|
|
*/
|
|
|
|
/* Macro to avoid header recursion hell vs. lockdep */
|
|
|
|
#define preempt_disable_nested() \
|
|
|
|
do { \
|
|
|
|
if (IS_ENABLED(CONFIG_PREEMPT_RT)) \
|
|
|
|
preempt_disable(); \
|
|
|
|
else \
|
|
|
|
lockdep_assert_preemption_disabled(); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* preempt_enable_nested - Undo the effect of preempt_disable_nested()
|
|
|
|
*/
|
|
|
|
static __always_inline void preempt_enable_nested(void)
|
|
|
|
{
|
|
|
|
if (IS_ENABLED(CONFIG_PREEMPT_RT))
|
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif /* __LINUX_PREEMPT_H */
|