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 21:07:57 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
/*
|
|
|
|
* kernel/power/wakelock.c
|
|
|
|
*
|
|
|
|
* User space wakeup sources support.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Rafael J. Wysocki <rjw@sisk.pl>
|
|
|
|
*
|
|
|
|
* This code is based on the analogous interface allowing user space to
|
|
|
|
* manipulate wakelocks on Android.
|
|
|
|
*/
|
|
|
|
|
2012-07-19 05:00:58 +07:00
|
|
|
#include <linux/capability.h>
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/hrtimer.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/rbtree.h>
|
|
|
|
#include <linux/slab.h>
|
2015-07-03 13:57:20 +07:00
|
|
|
#include <linux/workqueue.h>
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
|
2014-02-27 18:45:54 +07:00
|
|
|
#include "power.h"
|
|
|
|
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
static DEFINE_MUTEX(wakelocks_lock);
|
|
|
|
|
|
|
|
struct wakelock {
|
|
|
|
char *name;
|
|
|
|
struct rb_node node;
|
2019-08-07 08:48:45 +07:00
|
|
|
struct wakeup_source *ws;
|
2012-05-06 02:57:28 +07:00
|
|
|
#ifdef CONFIG_PM_WAKELOCKS_GC
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
struct list_head lru;
|
2012-05-06 02:57:28 +07:00
|
|
|
#endif
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct rb_root wakelocks_tree = RB_ROOT;
|
|
|
|
|
|
|
|
ssize_t pm_show_wakelocks(char *buf, bool show_active)
|
|
|
|
{
|
|
|
|
struct rb_node *node;
|
|
|
|
struct wakelock *wl;
|
|
|
|
char *str = buf;
|
|
|
|
char *end = buf + PAGE_SIZE;
|
|
|
|
|
|
|
|
mutex_lock(&wakelocks_lock);
|
|
|
|
|
|
|
|
for (node = rb_first(&wakelocks_tree); node; node = rb_next(node)) {
|
|
|
|
wl = rb_entry(node, struct wakelock, node);
|
2019-08-07 08:48:45 +07:00
|
|
|
if (wl->ws->active == show_active)
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
str += scnprintf(str, end - str, "%s ", wl->name);
|
|
|
|
}
|
|
|
|
if (str > buf)
|
|
|
|
str--;
|
|
|
|
|
|
|
|
str += scnprintf(str, end - str, "\n");
|
|
|
|
|
|
|
|
mutex_unlock(&wakelocks_lock);
|
|
|
|
return (str - buf);
|
|
|
|
}
|
|
|
|
|
2012-05-06 02:57:20 +07:00
|
|
|
#if CONFIG_PM_WAKELOCKS_LIMIT > 0
|
|
|
|
static unsigned int number_of_wakelocks;
|
|
|
|
|
|
|
|
static inline bool wakelocks_limit_exceeded(void)
|
|
|
|
{
|
|
|
|
return number_of_wakelocks > CONFIG_PM_WAKELOCKS_LIMIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void increment_wakelocks_number(void)
|
|
|
|
{
|
|
|
|
number_of_wakelocks++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void decrement_wakelocks_number(void)
|
|
|
|
{
|
|
|
|
number_of_wakelocks--;
|
|
|
|
}
|
|
|
|
#else /* CONFIG_PM_WAKELOCKS_LIMIT = 0 */
|
|
|
|
static inline bool wakelocks_limit_exceeded(void) { return false; }
|
|
|
|
static inline void increment_wakelocks_number(void) {}
|
|
|
|
static inline void decrement_wakelocks_number(void) {}
|
|
|
|
#endif /* CONFIG_PM_WAKELOCKS_LIMIT */
|
|
|
|
|
2012-05-06 02:57:28 +07:00
|
|
|
#ifdef CONFIG_PM_WAKELOCKS_GC
|
|
|
|
#define WL_GC_COUNT_MAX 100
|
|
|
|
#define WL_GC_TIME_SEC 300
|
|
|
|
|
2015-07-03 13:57:20 +07:00
|
|
|
static void __wakelocks_gc(struct work_struct *work);
|
2012-05-06 02:57:28 +07:00
|
|
|
static LIST_HEAD(wakelocks_lru_list);
|
2015-07-03 13:57:20 +07:00
|
|
|
static DECLARE_WORK(wakelock_work, __wakelocks_gc);
|
2012-05-06 02:57:28 +07:00
|
|
|
static unsigned int wakelocks_gc_count;
|
|
|
|
|
|
|
|
static inline void wakelocks_lru_add(struct wakelock *wl)
|
|
|
|
{
|
|
|
|
list_add(&wl->lru, &wakelocks_lru_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void wakelocks_lru_most_recent(struct wakelock *wl)
|
|
|
|
{
|
|
|
|
list_move(&wl->lru, &wakelocks_lru_list);
|
|
|
|
}
|
|
|
|
|
2015-07-03 13:57:20 +07:00
|
|
|
static void __wakelocks_gc(struct work_struct *work)
|
2012-05-06 02:57:28 +07:00
|
|
|
{
|
|
|
|
struct wakelock *wl, *aux;
|
|
|
|
ktime_t now;
|
|
|
|
|
2015-07-03 13:57:20 +07:00
|
|
|
mutex_lock(&wakelocks_lock);
|
2012-05-06 02:57:28 +07:00
|
|
|
|
|
|
|
now = ktime_get();
|
|
|
|
list_for_each_entry_safe_reverse(wl, aux, &wakelocks_lru_list, lru) {
|
|
|
|
u64 idle_time_ns;
|
|
|
|
bool active;
|
|
|
|
|
2019-08-07 08:48:45 +07:00
|
|
|
spin_lock_irq(&wl->ws->lock);
|
|
|
|
idle_time_ns = ktime_to_ns(ktime_sub(now, wl->ws->last_time));
|
|
|
|
active = wl->ws->active;
|
|
|
|
spin_unlock_irq(&wl->ws->lock);
|
2012-05-06 02:57:28 +07:00
|
|
|
|
|
|
|
if (idle_time_ns < ((u64)WL_GC_TIME_SEC * NSEC_PER_SEC))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!active) {
|
2019-08-07 08:48:45 +07:00
|
|
|
wakeup_source_unregister(wl->ws);
|
2012-05-06 02:57:28 +07:00
|
|
|
rb_erase(&wl->node, &wakelocks_tree);
|
|
|
|
list_del(&wl->lru);
|
|
|
|
kfree(wl->name);
|
|
|
|
kfree(wl);
|
|
|
|
decrement_wakelocks_number();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wakelocks_gc_count = 0;
|
2015-07-03 13:57:20 +07:00
|
|
|
|
|
|
|
mutex_unlock(&wakelocks_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wakelocks_gc(void)
|
|
|
|
{
|
|
|
|
if (++wakelocks_gc_count <= WL_GC_COUNT_MAX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
schedule_work(&wakelock_work);
|
2012-05-06 02:57:28 +07:00
|
|
|
}
|
|
|
|
#else /* !CONFIG_PM_WAKELOCKS_GC */
|
|
|
|
static inline void wakelocks_lru_add(struct wakelock *wl) {}
|
|
|
|
static inline void wakelocks_lru_most_recent(struct wakelock *wl) {}
|
|
|
|
static inline void wakelocks_gc(void) {}
|
|
|
|
#endif /* !CONFIG_PM_WAKELOCKS_GC */
|
|
|
|
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
static struct wakelock *wakelock_lookup_add(const char *name, size_t len,
|
|
|
|
bool add_if_not_found)
|
|
|
|
{
|
|
|
|
struct rb_node **node = &wakelocks_tree.rb_node;
|
|
|
|
struct rb_node *parent = *node;
|
|
|
|
struct wakelock *wl;
|
|
|
|
|
|
|
|
while (*node) {
|
|
|
|
int diff;
|
|
|
|
|
|
|
|
parent = *node;
|
|
|
|
wl = rb_entry(*node, struct wakelock, node);
|
|
|
|
diff = strncmp(name, wl->name, len);
|
|
|
|
if (diff == 0) {
|
|
|
|
if (wl->name[len])
|
|
|
|
diff = -1;
|
|
|
|
else
|
|
|
|
return wl;
|
|
|
|
}
|
|
|
|
if (diff < 0)
|
|
|
|
node = &(*node)->rb_left;
|
|
|
|
else
|
|
|
|
node = &(*node)->rb_right;
|
|
|
|
}
|
|
|
|
if (!add_if_not_found)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
2012-05-06 02:57:20 +07:00
|
|
|
if (wakelocks_limit_exceeded())
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
return ERR_PTR(-ENOSPC);
|
|
|
|
|
|
|
|
/* Not found, we have to add a new one. */
|
|
|
|
wl = kzalloc(sizeof(*wl), GFP_KERNEL);
|
|
|
|
if (!wl)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
wl->name = kstrndup(name, len, GFP_KERNEL);
|
|
|
|
if (!wl->name) {
|
|
|
|
kfree(wl);
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
}
|
2019-08-07 08:48:45 +07:00
|
|
|
|
2019-08-07 08:48:46 +07:00
|
|
|
wl->ws = wakeup_source_register(NULL, wl->name);
|
2019-08-07 08:48:45 +07:00
|
|
|
if (!wl->ws) {
|
|
|
|
kfree(wl->name);
|
|
|
|
kfree(wl);
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
}
|
|
|
|
wl->ws->last_time = ktime_get();
|
|
|
|
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
rb_link_node(&wl->node, parent, node);
|
|
|
|
rb_insert_color(&wl->node, &wakelocks_tree);
|
2012-05-06 02:57:28 +07:00
|
|
|
wakelocks_lru_add(wl);
|
2012-05-06 02:57:20 +07:00
|
|
|
increment_wakelocks_number();
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
return wl;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pm_wake_lock(const char *buf)
|
|
|
|
{
|
|
|
|
const char *str = buf;
|
|
|
|
struct wakelock *wl;
|
|
|
|
u64 timeout_ns = 0;
|
|
|
|
size_t len;
|
|
|
|
int ret = 0;
|
|
|
|
|
2012-07-19 05:00:58 +07:00
|
|
|
if (!capable(CAP_BLOCK_SUSPEND))
|
|
|
|
return -EPERM;
|
|
|
|
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
while (*str && !isspace(*str))
|
|
|
|
str++;
|
|
|
|
|
|
|
|
len = str - buf;
|
|
|
|
if (!len)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (*str && *str != '\n') {
|
|
|
|
/* Find out if there's a valid timeout string appended. */
|
|
|
|
ret = kstrtou64(skip_spaces(str), 10, &timeout_ns);
|
|
|
|
if (ret)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_lock(&wakelocks_lock);
|
|
|
|
|
|
|
|
wl = wakelock_lookup_add(buf, len, true);
|
|
|
|
if (IS_ERR(wl)) {
|
|
|
|
ret = PTR_ERR(wl);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (timeout_ns) {
|
|
|
|
u64 timeout_ms = timeout_ns + NSEC_PER_MSEC - 1;
|
|
|
|
|
|
|
|
do_div(timeout_ms, NSEC_PER_MSEC);
|
2019-08-07 08:48:45 +07:00
|
|
|
__pm_wakeup_event(wl->ws, timeout_ms);
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
} else {
|
2019-08-07 08:48:45 +07:00
|
|
|
__pm_stay_awake(wl->ws);
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
}
|
|
|
|
|
2012-05-06 02:57:28 +07:00
|
|
|
wakelocks_lru_most_recent(wl);
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&wakelocks_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pm_wake_unlock(const char *buf)
|
|
|
|
{
|
|
|
|
struct wakelock *wl;
|
|
|
|
size_t len;
|
|
|
|
int ret = 0;
|
|
|
|
|
2012-07-19 05:00:58 +07:00
|
|
|
if (!capable(CAP_BLOCK_SUSPEND))
|
|
|
|
return -EPERM;
|
|
|
|
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
len = strlen(buf);
|
|
|
|
if (!len)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (buf[len-1] == '\n')
|
|
|
|
len--;
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
mutex_lock(&wakelocks_lock);
|
|
|
|
|
|
|
|
wl = wakelock_lookup_add(buf, len, false);
|
|
|
|
if (IS_ERR(wl)) {
|
|
|
|
ret = PTR_ERR(wl);
|
|
|
|
goto out;
|
|
|
|
}
|
2019-08-07 08:48:45 +07:00
|
|
|
__pm_relax(wl->ws);
|
2012-05-06 02:57:28 +07:00
|
|
|
|
|
|
|
wakelocks_lru_most_recent(wl);
|
|
|
|
wakelocks_gc();
|
PM / Sleep: Add user space interface for manipulating wakeup sources, v3
Android allows user space to manipulate wakelocks using two
sysfs file located in /sys/power/, wake_lock and wake_unlock.
Writing a wakelock name and optionally a timeout to the wake_lock
file causes the wakelock whose name was written to be acquired (it
is created before is necessary), optionally with the given timeout.
Writing the name of a wakelock to wake_unlock causes that wakelock
to be released.
Implement an analogous interface for user space using wakeup sources.
Add the /sys/power/wake_lock and /sys/power/wake_unlock files
allowing user space to create, activate and deactivate wakeup
sources, such that writing a name and optionally a timeout to
wake_lock causes the wakeup source of that name to be activated,
optionally with the given timeout. If that wakeup source doesn't
exist, it will be created and then activated. Writing a name to
wake_unlock causes the wakeup source of that name, if there is one,
to be deactivated. Wakeup sources created with the help of
wake_lock that haven't been used for more than 5 minutes are garbage
collected and destroyed. Moreover, there can be only WL_NUMBER_LIMIT
wakeup sources created with the help of wake_lock present at a time.
The data type used to track wakeup sources created by user space is
called "struct wakelock" to indicate the origins of this feature.
This version of the patch includes an rbtree manipulation fix from John Stultz.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: NeilBrown <neilb@suse.de>
2012-04-30 03:53:42 +07:00
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&wakelocks_lock);
|
|
|
|
return ret;
|
|
|
|
}
|