From patchwork Thu Jun 25 23:24:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 50334 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4F3FE228FC for ; Thu, 25 Jun 2015 23:24:52 +0000 (UTC) Received: by wiea6 with SMTP id a6sf908500wie.1 for ; Thu, 25 Jun 2015 16:24:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=Zv9kB6kIawppXYoXgSfXaR0w8wPatiaVJlN+RUVs6bo=; b=in7MSOVGS6rOx5zuZL2sROcqur5n7Mvy5A/8KSRVuf5MkrXtmU2daZUpIdjaPyPAHY CNajnpGOFd14PVhuSVxgGIIg9QIczH3JYeh6kjLq8JPaG9OLaSNmcgrhvSSkhPkrvami b7JrEftz7LVw+B3UCMqKY8UPwlY1M4w9frxHDwK//kubClVvz5wSbtw2KiRsFbJxY9QI GU1btv+x61B0PYfPsOiP1HTUENwjX5zQ584rfrlZhh6Odiuba4tukxjaRX20511UZ+aV f2x5J5Gnn/sMcQRbHqAnJ4OwV+tRX5Om9ItHp2J3L21LZWPvRASiLw9WFsY74uujntq1 QYGg== X-Gm-Message-State: ALoCoQmR5A1PKLi8yC8f8/uulCi2kf6/WemiUWdu4/H3h3g1XLhL4QUcif0AxmRgKkQRxy/mX4nU X-Received: by 10.152.27.130 with SMTP id t2mr41434393lag.2.1435274691359; Thu, 25 Jun 2015 16:24:51 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.65 with SMTP id r1ls440069lag.61.gmail; Thu, 25 Jun 2015 16:24:51 -0700 (PDT) X-Received: by 10.112.83.135 with SMTP id q7mr47423618lby.13.1435274691202; Thu, 25 Jun 2015 16:24:51 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id rd3si25816729lac.167.2015.06.25.16.24.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2015 16:24:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbnk3 with SMTP id k3so54638787lbn.1 for ; Thu, 25 Jun 2015 16:24:50 -0700 (PDT) X-Received: by 10.112.93.37 with SMTP id cr5mr47581239lbb.106.1435274690669; Thu, 25 Jun 2015 16:24:50 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp914377lbb; Thu, 25 Jun 2015 16:24:49 -0700 (PDT) X-Received: by 10.66.222.161 with SMTP id qn1mr97507243pac.66.1435274688824; Thu, 25 Jun 2015 16:24:48 -0700 (PDT) Received: from mail-pd0-f171.google.com (mail-pd0-f171.google.com. [209.85.192.171]) by mx.google.com with ESMTPS id mr5si47183220pbb.204.2015.06.25.16.24.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2015 16:24:48 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.192.171 as permitted sender) client-ip=209.85.192.171; Received: by pdbep18 with SMTP id ep18so40695365pdb.1 for ; Thu, 25 Jun 2015 16:24:48 -0700 (PDT) X-Received: by 10.70.88.43 with SMTP id bd11mr94792762pdb.7.1435274687909; Thu, 25 Jun 2015 16:24:47 -0700 (PDT) Received: from localhost.localdomain (c-76-115-103-22.hsd1.or.comcast.net. [76.115.103.22]) by mx.google.com with ESMTPSA id cp10sm31217092pdb.44.2015.06.25.16.24.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Jun 2015 16:24:47 -0700 (PDT) From: John Stultz To: lkml Cc: Ruchi Kandoi , Arjan van de Ven , Thomas Gleixner , Oren Laadan , Micha Kalfon , Rom Lemarchand , Android Kernel Team , John Stultz 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 Message-Id: <1435274682-9425-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Ruchi Kandoi 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 have been folded into this patch to make it easier to reivew. Cc: Arjan van de Ven Cc: Thomas Gleixner Cc: Oren Laadan Cc: Micha Kalfon Cc: Ruchi Kandoi Cc: Rom Lemarchand Cc: Android Kernel Team Signed-off-by: Ruchi Kandoi [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 --- 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 #include #include +#include +#include +#include #include #include @@ -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;