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 */
|
2013-06-01 06:26:45 +08:00
|
|
|
/*
|
|
|
|
* Percpu refcounts:
|
|
|
|
* (C) 2012 Google, Inc.
|
|
|
|
* Author: Kent Overstreet <koverstreet@google.com>
|
|
|
|
*
|
|
|
|
* This implements a refcount with similar semantics to atomic_t - atomic_inc(),
|
|
|
|
* atomic_dec_and_test() - but percpu.
|
|
|
|
*
|
|
|
|
* There's one important difference between percpu refs and normal atomic_t
|
|
|
|
* refcounts; you have to keep track of your initial refcount, and then when you
|
|
|
|
* start shutting down you call percpu_ref_kill() _before_ dropping the initial
|
|
|
|
* refcount.
|
|
|
|
*
|
|
|
|
* The refcount will have a range of 0 to ((1U << 31) - 1), i.e. one bit less
|
|
|
|
* than an atomic_t - this is because of the way shutdown works, see
|
2014-09-25 01:31:48 +08:00
|
|
|
* percpu_ref_kill()/PERCPU_COUNT_BIAS.
|
2013-06-01 06:26:45 +08:00
|
|
|
*
|
|
|
|
* Before you call percpu_ref_kill(), percpu_ref_put() does not check for the
|
|
|
|
* refcount hitting 0 - it can't, if it was in percpu mode. percpu_ref_kill()
|
|
|
|
* puts the ref back in single atomic_t mode, collecting the per cpu refs and
|
|
|
|
* issuing the appropriate barriers, and then marks the ref as shutting down so
|
|
|
|
* that percpu_ref_put() will check for the ref hitting 0. After it returns,
|
|
|
|
* it's safe to drop the initial ref.
|
|
|
|
*
|
|
|
|
* USAGE:
|
|
|
|
*
|
|
|
|
* See fs/aio.c for some example usage; it's used there for struct kioctx, which
|
|
|
|
* is created when userspaces calls io_setup(), and destroyed when userspace
|
|
|
|
* calls io_destroy() or the process exits.
|
|
|
|
*
|
|
|
|
* In the aio code, kill_ioctx() is called when we wish to destroy a kioctx; it
|
2018-03-15 03:45:12 +08:00
|
|
|
* removes the kioctx from the proccess's table of kioctxs and kills percpu_ref.
|
|
|
|
* After that, there can't be any new users of the kioctx (from lookup_ioctx())
|
|
|
|
* and it's then safe to drop the initial ref with percpu_ref_put().
|
|
|
|
*
|
|
|
|
* Note that the free path, free_ioctx(), needs to go through explicit call_rcu()
|
|
|
|
* to synchronize with RCU protected lookup_ioctx(). percpu_ref operations don't
|
|
|
|
* imply RCU grace periods of any kind and if a user wants to combine percpu_ref
|
|
|
|
* with RCU protection, it must be done explicitly.
|
2013-06-01 06:26:45 +08:00
|
|
|
*
|
|
|
|
* Code that does a two stage shutdown like this often needs some kind of
|
|
|
|
* explicit synchronization to ensure the initial refcount can only be dropped
|
|
|
|
* once - percpu_ref_kill() does this for you, it returns true once and false if
|
|
|
|
* someone else already called it. The aio code uses it this way, but it's not
|
|
|
|
* necessary if the code has some other mechanism to synchronize teardown.
|
|
|
|
* around.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_PERCPU_REFCOUNT_H
|
|
|
|
#define _LINUX_PERCPU_REFCOUNT_H
|
|
|
|
|
|
|
|
#include <linux/atomic.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/percpu.h>
|
|
|
|
#include <linux/rcupdate.h>
|
2014-09-08 08:51:30 +08:00
|
|
|
#include <linux/gfp.h>
|
2013-06-01 06:26:45 +08:00
|
|
|
|
|
|
|
struct percpu_ref;
|
2013-06-13 11:43:06 +08:00
|
|
|
typedef void (percpu_ref_func_t)(struct percpu_ref *);
|
2013-06-01 06:26:45 +08:00
|
|
|
|
2014-09-25 01:31:48 +08:00
|
|
|
/* flags set in the lower bits of percpu_ref->percpu_count_ptr */
|
|
|
|
enum {
|
|
|
|
__PERCPU_REF_ATOMIC = 1LU << 0, /* operating in atomic mode */
|
2014-09-25 01:31:49 +08:00
|
|
|
__PERCPU_REF_DEAD = 1LU << 1, /* (being) killed */
|
|
|
|
__PERCPU_REF_ATOMIC_DEAD = __PERCPU_REF_ATOMIC | __PERCPU_REF_DEAD,
|
|
|
|
|
|
|
|
__PERCPU_REF_FLAG_BITS = 2,
|
2014-09-25 01:31:48 +08:00
|
|
|
};
|
|
|
|
|
2014-09-25 01:31:50 +08:00
|
|
|
/* @flags for percpu_ref_init() */
|
|
|
|
enum {
|
|
|
|
/*
|
|
|
|
* Start w/ ref == 1 in atomic mode. Can be switched to percpu
|
2014-09-25 01:31:50 +08:00
|
|
|
* operation using percpu_ref_switch_to_percpu(). If initialized
|
|
|
|
* with this flag, the ref will stay in atomic mode until
|
|
|
|
* percpu_ref_switch_to_percpu() is invoked on it.
|
2019-05-08 01:01:47 +08:00
|
|
|
* Implies ALLOW_REINIT.
|
2014-09-25 01:31:50 +08:00
|
|
|
*/
|
|
|
|
PERCPU_REF_INIT_ATOMIC = 1 << 0,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start dead w/ ref == 0 in atomic mode. Must be revived with
|
2019-05-08 01:01:47 +08:00
|
|
|
* percpu_ref_reinit() before used. Implies INIT_ATOMIC and
|
|
|
|
* ALLOW_REINIT.
|
2014-09-25 01:31:50 +08:00
|
|
|
*/
|
|
|
|
PERCPU_REF_INIT_DEAD = 1 << 1,
|
2019-05-08 01:01:47 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow switching from atomic mode to percpu mode.
|
|
|
|
*/
|
|
|
|
PERCPU_REF_ALLOW_REINIT = 1 << 2,
|
2014-09-25 01:31:50 +08:00
|
|
|
};
|
|
|
|
|
2013-06-01 06:26:45 +08:00
|
|
|
struct percpu_ref {
|
2014-09-20 13:27:25 +08:00
|
|
|
atomic_long_t count;
|
2013-06-01 06:26:45 +08:00
|
|
|
/*
|
|
|
|
* The low bit of the pointer indicates whether the ref is in percpu
|
2014-06-28 20:10:14 +08:00
|
|
|
* mode; if set, then get/put will manipulate the atomic_t.
|
2013-06-01 06:26:45 +08:00
|
|
|
*/
|
2014-09-25 01:31:48 +08:00
|
|
|
unsigned long percpu_count_ptr;
|
2013-06-13 11:43:06 +08:00
|
|
|
percpu_ref_func_t *release;
|
2014-09-25 01:31:48 +08:00
|
|
|
percpu_ref_func_t *confirm_switch;
|
2014-09-25 01:31:50 +08:00
|
|
|
bool force_atomic:1;
|
2019-05-08 01:01:50 +08:00
|
|
|
bool allow_reinit:1;
|
2013-06-01 06:26:45 +08:00
|
|
|
struct rcu_head rcu;
|
|
|
|
};
|
|
|
|
|
2013-06-13 11:52:01 +08:00
|
|
|
int __must_check percpu_ref_init(struct percpu_ref *ref,
|
2014-09-25 01:31:50 +08:00
|
|
|
percpu_ref_func_t *release, unsigned int flags,
|
|
|
|
gfp_t gfp);
|
2014-06-28 20:10:14 +08:00
|
|
|
void percpu_ref_exit(struct percpu_ref *ref);
|
2014-09-25 01:31:49 +08:00
|
|
|
void percpu_ref_switch_to_atomic(struct percpu_ref *ref,
|
|
|
|
percpu_ref_func_t *confirm_switch);
|
2017-03-15 11:05:14 +08:00
|
|
|
void percpu_ref_switch_to_atomic_sync(struct percpu_ref *ref);
|
2014-09-25 01:31:49 +08:00
|
|
|
void percpu_ref_switch_to_percpu(struct percpu_ref *ref);
|
2013-06-14 10:23:53 +08:00
|
|
|
void percpu_ref_kill_and_confirm(struct percpu_ref *ref,
|
|
|
|
percpu_ref_func_t *confirm_kill);
|
2018-09-27 05:01:07 +08:00
|
|
|
void percpu_ref_resurrect(struct percpu_ref *ref);
|
2014-09-25 01:31:49 +08:00
|
|
|
void percpu_ref_reinit(struct percpu_ref *ref);
|
2013-06-14 10:23:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* percpu_ref_kill - drop the initial ref
|
|
|
|
* @ref: percpu_ref to kill
|
|
|
|
*
|
|
|
|
* Must be used to drop the initial ref on a percpu refcount; must be called
|
|
|
|
* precisely once before shutdown.
|
|
|
|
*
|
2018-03-15 03:45:12 +08:00
|
|
|
* Switches @ref into atomic mode before gathering up the percpu counters
|
|
|
|
* and dropping the initial ref.
|
|
|
|
*
|
|
|
|
* There are no implied RCU grace periods between kill and release.
|
2013-06-14 10:23:53 +08:00
|
|
|
*/
|
|
|
|
static inline void percpu_ref_kill(struct percpu_ref *ref)
|
|
|
|
{
|
2015-09-23 18:34:30 +08:00
|
|
|
percpu_ref_kill_and_confirm(ref, NULL);
|
2013-06-14 10:23:53 +08:00
|
|
|
}
|
2013-06-01 06:26:45 +08:00
|
|
|
|
2014-06-28 20:10:13 +08:00
|
|
|
/*
|
|
|
|
* Internal helper. Don't use outside percpu-refcount proper. The
|
|
|
|
* function doesn't return the pointer and let the caller test it for NULL
|
|
|
|
* because doing so forces the compiler to generate two conditional
|
2014-09-25 01:31:48 +08:00
|
|
|
* branches as it can't assume that @ref->percpu_count is not NULL.
|
2014-06-28 20:10:13 +08:00
|
|
|
*/
|
2014-09-25 01:31:48 +08:00
|
|
|
static inline bool __ref_is_percpu(struct percpu_ref *ref,
|
|
|
|
unsigned long __percpu **percpu_countp)
|
2014-06-28 20:10:13 +08:00
|
|
|
{
|
2015-01-06 23:26:10 +08:00
|
|
|
unsigned long percpu_ptr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The value of @ref->percpu_count_ptr is tested for
|
|
|
|
* !__PERCPU_REF_ATOMIC, which may be set asynchronously, and then
|
|
|
|
* used as a pointer. If the compiler generates a separate fetch
|
|
|
|
* when using it as a pointer, __PERCPU_REF_ATOMIC may be set in
|
|
|
|
* between contaminating the pointer value, meaning that
|
2016-05-26 04:11:57 +08:00
|
|
|
* READ_ONCE() is required when fetching it.
|
2017-10-10 01:20:44 +08:00
|
|
|
*
|
|
|
|
* The smp_read_barrier_depends() implied by READ_ONCE() pairs
|
|
|
|
* with smp_store_release() in __percpu_ref_switch_to_percpu().
|
2015-01-06 23:26:10 +08:00
|
|
|
*/
|
2016-05-26 04:11:57 +08:00
|
|
|
percpu_ptr = READ_ONCE(ref->percpu_count_ptr);
|
|
|
|
|
2014-11-22 22:22:42 +08:00
|
|
|
/*
|
|
|
|
* Theoretically, the following could test just ATOMIC; however,
|
|
|
|
* then we'd have to mask off DEAD separately as DEAD may be
|
|
|
|
* visible without ATOMIC if we race with percpu_ref_kill(). DEAD
|
|
|
|
* implies ATOMIC anyway. Test them together.
|
|
|
|
*/
|
|
|
|
if (unlikely(percpu_ptr & __PERCPU_REF_ATOMIC_DEAD))
|
2014-06-28 20:10:13 +08:00
|
|
|
return false;
|
|
|
|
|
2014-09-25 01:31:48 +08:00
|
|
|
*percpu_countp = (unsigned long __percpu *)percpu_ptr;
|
2014-06-28 20:10:13 +08:00
|
|
|
return true;
|
|
|
|
}
|
2013-06-01 06:26:45 +08:00
|
|
|
|
|
|
|
/**
|
2014-12-11 07:42:42 +08:00
|
|
|
* percpu_ref_get_many - increment a percpu refcount
|
2013-06-13 11:43:06 +08:00
|
|
|
* @ref: percpu_ref to get
|
2014-12-11 07:42:42 +08:00
|
|
|
* @nr: number of references to get
|
2013-06-01 06:26:45 +08:00
|
|
|
*
|
2014-12-11 07:42:42 +08:00
|
|
|
* Analogous to atomic_long_add().
|
2014-09-25 01:31:48 +08:00
|
|
|
*
|
|
|
|
* This function is safe to call as long as @ref is between init and exit.
|
|
|
|
*/
|
2014-12-11 07:42:42 +08:00
|
|
|
static inline void percpu_ref_get_many(struct percpu_ref *ref, unsigned long nr)
|
2013-06-01 06:26:45 +08:00
|
|
|
{
|
2014-09-25 01:31:48 +08:00
|
|
|
unsigned long __percpu *percpu_count;
|
2013-06-01 06:26:45 +08:00
|
|
|
|
2013-06-17 07:12:26 +08:00
|
|
|
rcu_read_lock_sched();
|
2013-06-01 06:26:45 +08:00
|
|
|
|
2014-09-25 01:31:48 +08:00
|
|
|
if (__ref_is_percpu(ref, &percpu_count))
|
2014-12-11 07:42:42 +08:00
|
|
|
this_cpu_add(*percpu_count, nr);
|
2013-06-01 06:26:45 +08:00
|
|
|
else
|
2014-12-11 07:42:42 +08:00
|
|
|
atomic_long_add(nr, &ref->count);
|
2013-06-01 06:26:45 +08:00
|
|
|
|
2013-06-17 07:12:26 +08:00
|
|
|
rcu_read_unlock_sched();
|
2013-06-01 06:26:45 +08:00
|
|
|
}
|
|
|
|
|
2014-12-11 07:42:42 +08:00
|
|
|
/**
|
|
|
|
* percpu_ref_get - increment a percpu refcount
|
|
|
|
* @ref: percpu_ref to get
|
|
|
|
*
|
|
|
|
* Analagous to atomic_long_inc().
|
|
|
|
*
|
|
|
|
* This function is safe to call as long as @ref is between init and exit.
|
|
|
|
*/
|
|
|
|
static inline void percpu_ref_get(struct percpu_ref *ref)
|
|
|
|
{
|
|
|
|
percpu_ref_get_many(ref, 1);
|
|
|
|
}
|
|
|
|
|
2014-05-10 03:11:53 +08:00
|
|
|
/**
|
|
|
|
* percpu_ref_tryget - try to increment a percpu refcount
|
|
|
|
* @ref: percpu_ref to try-get
|
|
|
|
*
|
|
|
|
* Increment a percpu refcount unless its count already reached zero.
|
|
|
|
* Returns %true on success; %false on failure.
|
|
|
|
*
|
2014-09-25 01:31:48 +08:00
|
|
|
* This function is safe to call as long as @ref is between init and exit.
|
2014-05-10 03:11:53 +08:00
|
|
|
*/
|
|
|
|
static inline bool percpu_ref_tryget(struct percpu_ref *ref)
|
|
|
|
{
|
2014-09-25 01:31:48 +08:00
|
|
|
unsigned long __percpu *percpu_count;
|
2017-01-28 20:42:20 +08:00
|
|
|
bool ret;
|
2014-05-10 03:11:53 +08:00
|
|
|
|
|
|
|
rcu_read_lock_sched();
|
|
|
|
|
2014-09-25 01:31:48 +08:00
|
|
|
if (__ref_is_percpu(ref, &percpu_count)) {
|
2014-09-25 01:31:48 +08:00
|
|
|
this_cpu_inc(*percpu_count);
|
2014-05-10 03:11:53 +08:00
|
|
|
ret = true;
|
|
|
|
} else {
|
2014-09-20 13:27:25 +08:00
|
|
|
ret = atomic_long_inc_not_zero(&ref->count);
|
2014-05-10 03:11:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rcu_read_unlock_sched();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-14 10:23:53 +08:00
|
|
|
/**
|
2014-05-10 03:11:53 +08:00
|
|
|
* percpu_ref_tryget_live - try to increment a live percpu refcount
|
2013-06-14 10:23:53 +08:00
|
|
|
* @ref: percpu_ref to try-get
|
|
|
|
*
|
|
|
|
* Increment a percpu refcount unless it has already been killed. Returns
|
|
|
|
* %true on success; %false on failure.
|
|
|
|
*
|
2014-09-25 01:31:48 +08:00
|
|
|
* Completion of percpu_ref_kill() in itself doesn't guarantee that this
|
|
|
|
* function will fail. For such guarantee, percpu_ref_kill_and_confirm()
|
|
|
|
* should be used. After the confirm_kill callback is invoked, it's
|
|
|
|
* guaranteed that no new reference will be given out by
|
|
|
|
* percpu_ref_tryget_live().
|
2014-05-10 03:11:53 +08:00
|
|
|
*
|
2014-09-25 01:31:48 +08:00
|
|
|
* This function is safe to call as long as @ref is between init and exit.
|
2013-06-14 10:23:53 +08:00
|
|
|
*/
|
2014-05-10 03:11:53 +08:00
|
|
|
static inline bool percpu_ref_tryget_live(struct percpu_ref *ref)
|
2013-06-14 10:23:53 +08:00
|
|
|
{
|
2014-09-25 01:31:48 +08:00
|
|
|
unsigned long __percpu *percpu_count;
|
2017-01-28 20:42:20 +08:00
|
|
|
bool ret = false;
|
2013-06-14 10:23:53 +08:00
|
|
|
|
2013-06-17 07:12:26 +08:00
|
|
|
rcu_read_lock_sched();
|
2013-06-14 10:23:53 +08:00
|
|
|
|
2014-09-25 01:31:48 +08:00
|
|
|
if (__ref_is_percpu(ref, &percpu_count)) {
|
2014-09-25 01:31:48 +08:00
|
|
|
this_cpu_inc(*percpu_count);
|
2013-06-14 10:23:53 +08:00
|
|
|
ret = true;
|
2015-01-06 23:26:10 +08:00
|
|
|
} else if (!(ref->percpu_count_ptr & __PERCPU_REF_DEAD)) {
|
2014-09-25 01:31:49 +08:00
|
|
|
ret = atomic_long_inc_not_zero(&ref->count);
|
2013-06-14 10:23:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-17 07:12:26 +08:00
|
|
|
rcu_read_unlock_sched();
|
2013-06-14 10:23:53 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-01 06:26:45 +08:00
|
|
|
/**
|
2014-12-11 07:42:42 +08:00
|
|
|
* percpu_ref_put_many - decrement a percpu refcount
|
2013-06-13 11:43:06 +08:00
|
|
|
* @ref: percpu_ref to put
|
2014-12-11 07:42:42 +08:00
|
|
|
* @nr: number of references to put
|
2013-06-01 06:26:45 +08:00
|
|
|
*
|
|
|
|
* Decrement the refcount, and if 0, call the release function (which was passed
|
|
|
|
* to percpu_ref_init())
|
2014-09-25 01:31:48 +08:00
|
|
|
*
|
|
|
|
* This function is safe to call as long as @ref is between init and exit.
|
2013-06-01 06:26:45 +08:00
|
|
|
*/
|
2014-12-11 07:42:42 +08:00
|
|
|
static inline void percpu_ref_put_many(struct percpu_ref *ref, unsigned long nr)
|
2013-06-01 06:26:45 +08:00
|
|
|
{
|
2014-09-25 01:31:48 +08:00
|
|
|
unsigned long __percpu *percpu_count;
|
2013-06-01 06:26:45 +08:00
|
|
|
|
2013-06-17 07:12:26 +08:00
|
|
|
rcu_read_lock_sched();
|
2013-06-01 06:26:45 +08:00
|
|
|
|
2014-09-25 01:31:48 +08:00
|
|
|
if (__ref_is_percpu(ref, &percpu_count))
|
2014-12-11 07:42:42 +08:00
|
|
|
this_cpu_sub(*percpu_count, nr);
|
|
|
|
else if (unlikely(atomic_long_sub_and_test(nr, &ref->count)))
|
2013-06-01 06:26:45 +08:00
|
|
|
ref->release(ref);
|
|
|
|
|
2013-06-17 07:12:26 +08:00
|
|
|
rcu_read_unlock_sched();
|
2013-06-01 06:26:45 +08:00
|
|
|
}
|
|
|
|
|
2014-12-11 07:42:42 +08:00
|
|
|
/**
|
|
|
|
* percpu_ref_put - decrement a percpu refcount
|
|
|
|
* @ref: percpu_ref to put
|
|
|
|
*
|
|
|
|
* Decrement the refcount, and if 0, call the release function (which was passed
|
|
|
|
* to percpu_ref_init())
|
|
|
|
*
|
|
|
|
* This function is safe to call as long as @ref is between init and exit.
|
|
|
|
*/
|
|
|
|
static inline void percpu_ref_put(struct percpu_ref *ref)
|
|
|
|
{
|
|
|
|
percpu_ref_put_many(ref, 1);
|
|
|
|
}
|
|
|
|
|
2015-01-06 23:26:10 +08:00
|
|
|
/**
|
|
|
|
* percpu_ref_is_dying - test whether a percpu refcount is dying or dead
|
|
|
|
* @ref: percpu_ref to test
|
|
|
|
*
|
|
|
|
* Returns %true if @ref is dying or dead.
|
|
|
|
*
|
|
|
|
* This function is safe to call as long as @ref is between init and exit
|
|
|
|
* and the caller is responsible for synchronizing against state changes.
|
|
|
|
*/
|
|
|
|
static inline bool percpu_ref_is_dying(struct percpu_ref *ref)
|
|
|
|
{
|
|
|
|
return ref->percpu_count_ptr & __PERCPU_REF_DEAD;
|
|
|
|
}
|
|
|
|
|
2014-06-28 20:10:14 +08:00
|
|
|
/**
|
|
|
|
* percpu_ref_is_zero - test whether a percpu refcount reached zero
|
|
|
|
* @ref: percpu_ref to test
|
|
|
|
*
|
|
|
|
* Returns %true if @ref reached zero.
|
2014-09-25 01:31:48 +08:00
|
|
|
*
|
|
|
|
* This function is safe to call as long as @ref is between init and exit.
|
2014-06-28 20:10:14 +08:00
|
|
|
*/
|
|
|
|
static inline bool percpu_ref_is_zero(struct percpu_ref *ref)
|
|
|
|
{
|
2014-09-25 01:31:48 +08:00
|
|
|
unsigned long __percpu *percpu_count;
|
2014-06-28 20:10:14 +08:00
|
|
|
|
2014-09-25 01:31:48 +08:00
|
|
|
if (__ref_is_percpu(ref, &percpu_count))
|
2014-06-28 20:10:14 +08:00
|
|
|
return false;
|
2014-09-20 13:27:25 +08:00
|
|
|
return !atomic_long_read(&ref->count);
|
2014-06-28 20:10:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-01 06:26:45 +08:00
|
|
|
#endif
|