From: John Stultz <john.stultz@linaro.org>
To: lkml <linux-kernel@vger.kernel.org>
Cc: Ruchi Kandoi <kandoiruchi@google.com>,
Arjan van de Ven <arjan@linux.intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Oren Laadan <orenl@cellrox.com>, Micha Kalfon <micha@cellrox.com>,
Rom Lemarchand <romlem@android.com>,
Android Kernel Team <kernel-team@android.com>,
John Stultz <john.stultz@linaro.org>
Subject: [RFC][PATCH] prctl: Add PR_SET_TIMERSLACK_PID for setting timer slack of an arbitrary thread.
Date: Thu, 25 Jun 2015 16:24:42 -0700 [thread overview]
Message-ID: <1435274682-9425-1-git-send-email-john.stultz@linaro.org> (raw)
From: Ruchi Kandoi <kandoiruchi@google.com>
This patch has been in the Android tree for ahwile, and I've not
seen it posted for review. Unfortunately the PR_SET_TIMERSLACK_PID
value has collided many times w/ upstream (first w/
PR_SET_THP_DISABLE, and again w/ PR_MPX_ENABLE_MANAGEMENT).
So to try to avoid further ABI trouble, I wanted to send this out
for initial review to see if there were any major objections,
or ideas for alternative approaches.
Thoughts and feedback would be appreciated.
thanks
-john
This patch allows power/performance management software to set
timer slack for other threads according to its policy for the
thread (such as when the thread is designated foreground vs.
background activity)
Second argument is similar to PR_SET_TIMERSLACK, if non-zero
then the slack is set to that value otherwise sets it to the
default for the thread.
Takes PID of the thread as the third argument.
This interface checks check for CAP_SYS_NICE to make sure that
arbitrary apps do not change the timer slack for other apps.
Additional fixes from Ruchi and Micha Kalfon <micha@cellrox.com>
have been folded into this patch to make it easier to reivew.
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Oren Laadan <orenl@cellrox.com>
Cc: Micha Kalfon <micha@cellrox.com>
Cc: Ruchi Kandoi <kandoiruchi@google.com>
Cc: Rom Lemarchand <romlem@android.com>
Cc: Android Kernel Team <kernel-team@android.com>
Signed-off-by: Ruchi Kandoi <kandoiruchi@google.com>
[jstultz:
* Folded in CAP_SYS_NICE check from Ruchi.
* Folded in fix misplaced PR_SET_TIMERSLACK_PID case fix from
Micha.
* Folded in make PR_SET_TIMERSLACK_PID pid namespace aware fix
from Micha.
* Changed PR_SET_TIMERSLACK_PID so it didn't collide with
already upstream prctrl values.
* Reworked commit message.]
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
include/uapi/linux/prctl.h | 7 +++++++
kernel/sys.c | 24 ++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h
index 31891d9..7086be4 100644
--- a/include/uapi/linux/prctl.h
+++ b/include/uapi/linux/prctl.h
@@ -187,6 +187,13 @@ struct prctl_mm_map {
#define PR_SET_FP_MODE 45
#define PR_GET_FP_MODE 46
+
+/* Sets the timerslack for arbitrary threads
+ * arg2 slack value, 0 means "use default"
+ * arg3 pid of the thread whose timer slack needs to be set
+ */
+#define PR_SET_TIMERSLACK_PID 47
+
# define PR_FP_MODE_FR (1 << 0) /* 64b FP registers */
# define PR_FP_MODE_FRE (1 << 1) /* 32b compatibility */
diff --git a/kernel/sys.c b/kernel/sys.c
index 8571296..75b32f0 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -41,6 +41,9 @@
#include <linux/syscore_ops.h>
#include <linux/version.h>
#include <linux/ctype.h>
+#include <linux/mm.h>
+#include <linux/mempolicy.h>
+#include <linux/sched.h>
#include <linux/compat.h>
#include <linux/syscalls.h>
@@ -2053,6 +2056,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
unsigned long, arg4, unsigned long, arg5)
{
struct task_struct *me = current;
+ struct task_struct *tsk;
unsigned char comm[sizeof(me->comm)];
long error;
@@ -2195,6 +2199,26 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
case PR_GET_TID_ADDRESS:
error = prctl_get_tid_address(me, (int __user **)arg2);
break;
+ case PR_SET_TIMERSLACK_PID:
+ if (task_pid_vnr(current) != (pid_t)arg3 &&
+ !capable(CAP_SYS_NICE))
+ return -EPERM;
+ rcu_read_lock();
+ tsk = find_task_by_vpid((pid_t)arg3);
+ if (tsk == NULL) {
+ rcu_read_unlock();
+ return -EINVAL;
+ }
+ get_task_struct(tsk);
+ rcu_read_unlock();
+ if (arg2 <= 0)
+ tsk->timer_slack_ns =
+ tsk->default_timer_slack_ns;
+ else
+ tsk->timer_slack_ns = arg2;
+ put_task_struct(tsk);
+ error = 0;
+ break;
case PR_SET_CHILD_SUBREAPER:
me->signal->is_child_subreaper = !!arg2;
break;
--
1.9.1
next reply other threads:[~2015-06-25 23:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-25 23:24 John Stultz [this message]
2015-06-26 1:21 ` Arjan van de Ven
2015-06-26 21:36 ` John Stultz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1435274682-9425-1-git-send-email-john.stultz@linaro.org \
--to=john.stultz@linaro.org \
--cc=arjan@linux.intel.com \
--cc=kandoiruchi@google.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=micha@cellrox.com \
--cc=orenl@cellrox.com \
--cc=romlem@android.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome