aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArjan van de Ven <arjan@linux.intel.com>2008-09-01 18:52:40 -0400
committerArjan van de Ven <arjan@linux.intel.com>2008-09-06 00:35:30 -0400
commit6976675d94042fbd446231d1bd8b7de71a980ada (patch)
tree2d2acebb8078dd373115ecbdac5423f7d4fa7d72
parent654c8e0b1c623b156c5b92f28d914ab38c9c2c90 (diff)
hrtimer: create a "timer_slack" field in the task struct
We want to be able to control the default "rounding" that is used by select() and poll() and friends. This is a per process property (so that we can have a "nice" like program to start certain programs with a looser or stricter rounding) that can be set/get via a prctl(). For this purpose, a field called "timer_slack_ns" is added to the task struct. In addition, a field called "default_timer_slack"ns" is added so that tasks easily can temporarily to a more/less accurate slack and then back to the default. The default value of the slack is set to 50 usec; this is significantly less than 2.6.27's average select() and poll() timing error but still allows the kernel to group timers somewhat to preserve power behavior. Applications and admins can override this via the prctl() Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
-rw-r--r--include/linux/init_task.h1
-rw-r--r--include/linux/prctl.h7
-rw-r--r--include/linux/sched.h6
-rw-r--r--kernel/fork.c2
-rw-r--r--kernel/sys.c10
5 files changed, 26 insertions, 0 deletions
diff --git a/include/linux/init_task.h b/include/linux/init_task.h
index 021d8e720c79..23fd8909b9e5 100644
--- a/include/linux/init_task.h
+++ b/include/linux/init_task.h
@@ -170,6 +170,7 @@ extern struct group_info init_groups;
170 .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ 170 .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
171 .fs_excl = ATOMIC_INIT(0), \ 171 .fs_excl = ATOMIC_INIT(0), \
172 .pi_lock = __SPIN_LOCK_UNLOCKED(tsk.pi_lock), \ 172 .pi_lock = __SPIN_LOCK_UNLOCKED(tsk.pi_lock), \
173 .timer_slack_ns = 50000, /* 50 usec default slack */ \
173 .pids = { \ 174 .pids = { \
174 [PIDTYPE_PID] = INIT_PID_LINK(PIDTYPE_PID), \ 175 [PIDTYPE_PID] = INIT_PID_LINK(PIDTYPE_PID), \
175 [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID), \ 176 [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID), \
diff --git a/include/linux/prctl.h b/include/linux/prctl.h
index 5ad79198d6f9..48d887e3c6e7 100644
--- a/include/linux/prctl.h
+++ b/include/linux/prctl.h
@@ -78,4 +78,11 @@
78#define PR_GET_SECUREBITS 27 78#define PR_GET_SECUREBITS 27
79#define PR_SET_SECUREBITS 28 79#define PR_SET_SECUREBITS 28
80 80
81/*
82 * Get/set the timerslack as used by poll/select/nanosleep
83 * A value of 0 means "use default"
84 */
85#define PR_SET_TIMERSLACK 29
86#define PR_GET_TIMERSLACK 30
87
81#endif /* _LINUX_PRCTL_H */ 88#endif /* _LINUX_PRCTL_H */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 3d9120c5ad15..dcc03fd5a7f3 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1301,6 +1301,12 @@ struct task_struct {
1301 int latency_record_count; 1301 int latency_record_count;
1302 struct latency_record latency_record[LT_SAVECOUNT]; 1302 struct latency_record latency_record[LT_SAVECOUNT];
1303#endif 1303#endif
1304 /*
1305 * time slack values; these are used to round up poll() and
1306 * select() etc timeout values. These are in nanoseconds.
1307 */
1308 unsigned long timer_slack_ns;
1309 unsigned long default_timer_slack_ns;
1304}; 1310};
1305 1311
1306/* 1312/*
diff --git a/kernel/fork.c b/kernel/fork.c
index 7ce2ebe84796..4308d75f0fa5 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -987,6 +987,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
987 p->prev_utime = cputime_zero; 987 p->prev_utime = cputime_zero;
988 p->prev_stime = cputime_zero; 988 p->prev_stime = cputime_zero;
989 989
990 p->default_timer_slack_ns = current->timer_slack_ns;
991
990#ifdef CONFIG_DETECT_SOFTLOCKUP 992#ifdef CONFIG_DETECT_SOFTLOCKUP
991 p->last_switch_count = 0; 993 p->last_switch_count = 0;
992 p->last_switch_timestamp = 0; 994 p->last_switch_timestamp = 0;
diff --git a/kernel/sys.c b/kernel/sys.c
index 038a7bc0901d..1b96401a0576 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1727,6 +1727,16 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
1727 case PR_SET_TSC: 1727 case PR_SET_TSC:
1728 error = SET_TSC_CTL(arg2); 1728 error = SET_TSC_CTL(arg2);
1729 break; 1729 break;
1730 case PR_GET_TIMERSLACK:
1731 error = current->timer_slack_ns;
1732 break;
1733 case PR_SET_TIMERSLACK:
1734 if (arg2 <= 0)
1735 current->timer_slack_ns =
1736 current->default_timer_slack_ns;
1737 else
1738 current->timer_slack_ns = arg2;
1739 break;
1730 default: 1740 default:
1731 error = -EINVAL; 1741 error = -EINVAL;
1732 break; 1742 break;