]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
hrtimer: create a "timer_slack" field in the task struct
authorArjan van de Ven <arjan@linux.intel.com>
Mon, 1 Sep 2008 22:52:40 +0000 (15:52 -0700)
committerArjan van de Ven <arjan@linux.intel.com>
Sat, 6 Sep 2008 04:35:30 +0000 (21:35 -0700)
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>
include/linux/init_task.h
include/linux/prctl.h
include/linux/sched.h
kernel/fork.c
kernel/sys.c

index 021d8e720c7941f17cd6a541a63b7a9275f68c9c..23fd8909b9e52c143faf401030e8d282c559baeb 100644 (file)
@@ -170,6 +170,7 @@ extern struct group_info init_groups;
        .cpu_timers     = INIT_CPU_TIMERS(tsk.cpu_timers),              \
        .fs_excl        = ATOMIC_INIT(0),                               \
        .pi_lock        = __SPIN_LOCK_UNLOCKED(tsk.pi_lock),            \
+       .timer_slack_ns = 50000, /* 50 usec default slack */            \
        .pids = {                                                       \
                [PIDTYPE_PID]  = INIT_PID_LINK(PIDTYPE_PID),            \
                [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID),           \
index 5ad79198d6f99809343dd063131b0ba48db8a063..48d887e3c6e737317a7b29d2a418f8383ae910cb 100644 (file)
 #define PR_GET_SECUREBITS 27
 #define PR_SET_SECUREBITS 28
 
+/*
+ * Get/set the timerslack as used by poll/select/nanosleep
+ * A value of 0 means "use default"
+ */
+#define PR_SET_TIMERSLACK 29
+#define PR_GET_TIMERSLACK 30
+
 #endif /* _LINUX_PRCTL_H */
index 3d9120c5ad1589a0da722e514c370c0a3f1c4fe4..dcc03fd5a7f3df86a005ac88b1dc2843c5c178b4 100644 (file)
@@ -1301,6 +1301,12 @@ struct task_struct {
        int latency_record_count;
        struct latency_record latency_record[LT_SAVECOUNT];
 #endif
+       /*
+        * time slack values; these are used to round up poll() and
+        * select() etc timeout values. These are in nanoseconds.
+        */
+       unsigned long timer_slack_ns;
+       unsigned long default_timer_slack_ns;
 };
 
 /*
index 7ce2ebe847964ecd0701c3c74c18994e3eebcf26..4308d75f0fa5bc67c36748d31bb0e2518ab58990 100644 (file)
@@ -987,6 +987,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
        p->prev_utime = cputime_zero;
        p->prev_stime = cputime_zero;
 
+       p->default_timer_slack_ns = current->timer_slack_ns;
+
 #ifdef CONFIG_DETECT_SOFTLOCKUP
        p->last_switch_count = 0;
        p->last_switch_timestamp = 0;
index 038a7bc0901d20f90f841c5e4326fc1f2f2b963f..1b96401a0576ab8b3d5b09641eabc3c53080b0e4 100644 (file)
@@ -1727,6 +1727,16 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
                case PR_SET_TSC:
                        error = SET_TSC_CTL(arg2);
                        break;
+               case PR_GET_TIMERSLACK:
+                       error = current->timer_slack_ns;
+                       break;
+               case PR_SET_TIMERSLACK:
+                       if (arg2 <= 0)
+                               current->timer_slack_ns =
+                                       current->default_timer_slack_ns;
+                       else
+                               current->timer_slack_ns = arg2;
+                       break;
                default:
                        error = -EINVAL;
                        break;