linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Paul Menage <menage@google.com>, Li Zefan <lizf@cn.fujitsu.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: containers@lists.linux-foundation.org,
	jacob.jun.pan@linux.intel.com,
	Arjan van de Ven <arjan@linux.intel.com>,
	linux-kernel@vger.kernel.org, Matt Helsley <matthltc@us.ibm.com>,
	linux-api@vger.kernel.org, Kay Sievers <kay.sievers@vrfy.org>,
	lennart@poettering.net, harald@redhat.com, david@fubar.dk,
	greg@kroah.com, "Kirill A. Shutemov" <kirill@shutemov.name>
Subject: [PATCH, v10 1/3] hrtimer: introduce effective timer slack
Date: Tue, 11 Oct 2011 19:15:27 +0300	[thread overview]
Message-ID: <1318349729-3108-2-git-send-email-kirill@shutemov.name> (raw)
In-Reply-To: <1318349729-3108-1-git-send-email-kirill@shutemov.name>

From: "Kirill A. Shutemov" <kirill@shutemov.name>

task_get_effective_timer_slack() returns timer slack value to be used
to configure per-task timers. It can be equal or higher than task's
timer slack value.

For now task_get_effective_timer_slack() returns timer_slack_ns of the
task. Timer slack cgroup controller will implement a bit more
sophisticated logic.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
 fs/select.c           |    7 ++-----
 include/linux/sched.h |    6 ++++++
 kernel/fork.c         |    4 ++++
 kernel/futex.c        |    4 ++--
 kernel/hrtimer.c      |    2 +-
 5 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/fs/select.c b/fs/select.c
index b6765cf..c6eb8fa 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -69,7 +69,6 @@ static long __estimate_accuracy(struct timespec *tv)
 
 long select_estimate_accuracy(struct timespec *tv)
 {
-	unsigned long ret;
 	struct timespec now;
 
 	/*
@@ -81,10 +80,8 @@ long select_estimate_accuracy(struct timespec *tv)
 
 	ktime_get_ts(&now);
 	now = timespec_sub(*tv, now);
-	ret = __estimate_accuracy(&now);
-	if (ret < current->timer_slack_ns)
-		return current->timer_slack_ns;
-	return ret;
+	return min_t(long, __estimate_accuracy(&now),
+			task_get_effective_timer_slack(current));
 }
 
 
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 28edc96..d79e300 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2719,6 +2719,12 @@ static inline unsigned long rlimit_max(unsigned int limit)
 	return task_rlimit_max(current, limit);
 }
 
+static inline unsigned long task_get_effective_timer_slack(
+		struct task_struct *tsk)
+{
+	return tsk->timer_slack_ns;
+}
+
 #endif /* __KERNEL__ */
 
 #endif
diff --git a/kernel/fork.c b/kernel/fork.c
index 0675082..4a9fd53 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1180,6 +1180,10 @@ static struct task_struct *copy_process(unsigned long clone_flags,
 	memset(&p->rss_stat, 0, sizeof(p->rss_stat));
 #endif
 
+	/*
+	 * Save current task's (not effective) timer slack value as default
+	 * timer slack value for new task.
+	 */
 	p->default_timer_slack_ns = current->timer_slack_ns;
 
 	task_io_accounting_init(&p->ioac);
diff --git a/kernel/futex.c b/kernel/futex.c
index ea87f4d..14f04b9 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -1875,7 +1875,7 @@ static int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val,
 				      HRTIMER_MODE_ABS);
 		hrtimer_init_sleeper(to, current);
 		hrtimer_set_expires_range_ns(&to->timer, *abs_time,
-					     current->timer_slack_ns);
+				     task_get_effective_timer_slack(current));
 	}
 
 retry:
@@ -2269,7 +2269,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
 				      HRTIMER_MODE_ABS);
 		hrtimer_init_sleeper(to, current);
 		hrtimer_set_expires_range_ns(&to->timer, *abs_time,
-					     current->timer_slack_ns);
+				     task_get_effective_timer_slack(current));
 	}
 
 	/*
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
index 422e567..379460b 100644
--- a/kernel/hrtimer.c
+++ b/kernel/hrtimer.c
@@ -1562,7 +1562,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
 	int ret = 0;
 	unsigned long slack;
 
-	slack = current->timer_slack_ns;
+	slack = task_get_effective_timer_slack(current);
 	if (rt_task(current))
 		slack = 0;
 
-- 
1.7.6.3

  reply	other threads:[~2011-10-11 16:15 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-11 16:15 [PATCH, v10 0/3] Introduce timer slack controller Kirill A. Shutemov
2011-10-11 16:15 ` Kirill A. Shutemov [this message]
2011-10-11 16:15 ` [PATCH, v10 2/3] hrtimer: implement PR_GET_EFFECTIVE_TIMERSLACK Kirill A. Shutemov
2011-10-11 16:15 ` [PATCH, v10 3/3] cgroups: introduce timer slack controller Kirill A. Shutemov
     [not found]   ` <1318349729-3108-4-git-send-email-kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org>
2011-10-11 16:49     ` Kirill A. Shutemov
2011-10-14 22:43     ` Andrew Morton
     [not found]       ` <20111014154348.ae6267aa.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2011-10-14 23:34         ` Kirill A. Shutemov
2011-10-15 11:20       ` Lennart Poettering
2011-10-15 19:11         ` Peter Zijlstra
2011-10-17  1:39           ` Lennart Poettering
     [not found]             ` <20111017013921.GA30035-kS5D54t9nk0aINubkmmoJbNAH6kLmebB@public.gmane.org>
2011-10-17  3:22               ` Matthew Garrett
     [not found]                 ` <20111017032232.GA4816-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
2011-10-17  5:21                   ` Arjan van de Ven
     [not found]                     ` <4E9BBB6D.4050004-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2011-10-17  7:36                       ` Peter Zijlstra
2011-10-17  9:38                         ` Thomas Gleixner
2011-10-17 12:46                           ` Matthew Garrett
     [not found]                             ` <20111017124647.GA12838-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
2011-10-17 13:06                               ` Peter Zijlstra
2011-10-17 14:11                                 ` Matthew Garrett
     [not found]                                   ` <20111017141147.GA14581-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
2011-10-17 14:28                                     ` Peter Zijlstra
2011-10-17 14:35                                       ` Arjan van de Ven
     [not found]                                         ` <4E9C3D39.9020109-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2011-10-17 14:45                                           ` Peter Zijlstra
2011-10-17 14:40                                       ` Matthew Garrett
2011-10-17 14:49                                         ` Peter Zijlstra
2011-10-17 14:59                                           ` Matthew Garrett
2011-10-17 15:11                                             ` Peter Zijlstra
2011-10-17 15:19                                               ` Matthew Garrett
     [not found]                                                 ` <20111017151920.GA16664-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
2011-10-17 15:21                                                   ` Peter Zijlstra
2011-10-17 15:31                                                     ` Matthew Garrett
     [not found]                                                       ` <20111017153142.GA17047-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
2011-10-17 16:36                                                         ` Peter Zijlstra
2011-10-17 16:49                                                           ` Matthew Garrett
2011-10-17 15:48                                                     ` Alan Cox
     [not found]                                                       ` <20111017164839.3887ee3e-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2011-10-17 16:33                                                         ` Peter Zijlstra
2011-10-17 15:18                                             ` Peter Zijlstra
2011-10-17  7:34                 ` Peter Zijlstra
2011-10-17 13:55                   ` Lennart Poettering
2011-10-17  7:28               ` Peter Zijlstra
2011-10-17 19:46                 ` Valdis.Kletnieks-PjAqaU27lzQ

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=1318349729-3108-2-git-send-email-kirill@shutemov.name \
    --to=kirill@shutemov.name \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@linux.intel.com \
    --cc=containers@lists.linux-foundation.org \
    --cc=david@fubar.dk \
    --cc=greg@kroah.com \
    --cc=harald@redhat.com \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=kay.sievers@vrfy.org \
    --cc=lennart@poettering.net \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=matthltc@us.ibm.com \
    --cc=menage@google.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;
as well as URLs for NNTP newsgroup(s).