diff options
author | Arjan van de Ven <arjan@linux.intel.com> | 2008-09-07 13:47:46 -0400 |
---|---|---|
committer | Arjan van de Ven <arjan@linux.intel.com> | 2008-09-07 13:58:01 -0400 |
commit | da8f2e170ea94cc20f8ebbc8ee8d127edb8f12f1 (patch) | |
tree | 08d25027a7769cd250aca5b516a3d8c95e4385be | |
parent | 2ec02270c00f94b08fddfb68c37510a9fb47ac7c (diff) |
hrtimer: add a hrtimer_start_range() function
this patch adds a _range version of hrtimer_start() so that range timers
can be created; the hrtimer_start() function is just a wrapper around this.
In addition, hrtimer_start_expires() will now preserve existing ranges.
Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
-rw-r--r-- | include/linux/hrtimer.h | 9 | ||||
-rw-r--r-- | kernel/hrtimer.c | 26 |
2 files changed, 31 insertions, 4 deletions
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h index 4c1a834b9849..1c0473e8ecb4 100644 --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h | |||
@@ -350,13 +350,20 @@ static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { } | |||
350 | /* Basic timer operations: */ | 350 | /* Basic timer operations: */ |
351 | extern int hrtimer_start(struct hrtimer *timer, ktime_t tim, | 351 | extern int hrtimer_start(struct hrtimer *timer, ktime_t tim, |
352 | const enum hrtimer_mode mode); | 352 | const enum hrtimer_mode mode); |
353 | extern int hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim, | ||
354 | unsigned long range_ns, const enum hrtimer_mode mode); | ||
353 | extern int hrtimer_cancel(struct hrtimer *timer); | 355 | extern int hrtimer_cancel(struct hrtimer *timer); |
354 | extern int hrtimer_try_to_cancel(struct hrtimer *timer); | 356 | extern int hrtimer_try_to_cancel(struct hrtimer *timer); |
355 | 357 | ||
356 | static inline int hrtimer_start_expires(struct hrtimer *timer, | 358 | static inline int hrtimer_start_expires(struct hrtimer *timer, |
357 | enum hrtimer_mode mode) | 359 | enum hrtimer_mode mode) |
358 | { | 360 | { |
359 | return hrtimer_start(timer, hrtimer_get_expires(timer), mode); | 361 | unsigned long delta; |
362 | ktime_t soft, hard; | ||
363 | soft = hrtimer_get_softexpires(timer); | ||
364 | hard = hrtimer_get_expires(timer); | ||
365 | delta = ktime_to_ns(ktime_sub(hard, soft)); | ||
366 | return hrtimer_start_range_ns(timer, hrtimer_get_expires(timer), delta, mode); | ||
360 | } | 367 | } |
361 | 368 | ||
362 | static inline int hrtimer_restart(struct hrtimer *timer) | 369 | static inline int hrtimer_restart(struct hrtimer *timer) |
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index 01483004183d..a0222097c57e 100644 --- a/kernel/hrtimer.c +++ b/kernel/hrtimer.c | |||
@@ -945,9 +945,10 @@ remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base) | |||
945 | } | 945 | } |
946 | 946 | ||
947 | /** | 947 | /** |
948 | * hrtimer_start - (re)start an relative timer on the current CPU | 948 | * hrtimer_start_range_ns - (re)start an relative timer on the current CPU |
949 | * @timer: the timer to be added | 949 | * @timer: the timer to be added |
950 | * @tim: expiry time | 950 | * @tim: expiry time |
951 | * @delta_ns: "slack" range for the timer | ||
951 | * @mode: expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL) | 952 | * @mode: expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL) |
952 | * | 953 | * |
953 | * Returns: | 954 | * Returns: |
@@ -955,7 +956,8 @@ remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base) | |||
955 | * 1 when the timer was active | 956 | * 1 when the timer was active |
956 | */ | 957 | */ |
957 | int | 958 | int |
958 | hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode) | 959 | hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim, unsigned long delta_ns, |
960 | const enum hrtimer_mode mode) | ||
959 | { | 961 | { |
960 | struct hrtimer_clock_base *base, *new_base; | 962 | struct hrtimer_clock_base *base, *new_base; |
961 | unsigned long flags; | 963 | unsigned long flags; |
@@ -983,7 +985,7 @@ hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode) | |||
983 | #endif | 985 | #endif |
984 | } | 986 | } |
985 | 987 | ||
986 | hrtimer_set_expires(timer, tim); | 988 | hrtimer_set_expires_range_ns(timer, tim, delta_ns); |
987 | 989 | ||
988 | timer_stats_hrtimer_set_start_info(timer); | 990 | timer_stats_hrtimer_set_start_info(timer); |
989 | 991 | ||
@@ -1016,8 +1018,26 @@ hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode) | |||
1016 | 1018 | ||
1017 | return ret; | 1019 | return ret; |
1018 | } | 1020 | } |
1021 | EXPORT_SYMBOL_GPL(hrtimer_start_range_ns); | ||
1022 | |||
1023 | /** | ||
1024 | * hrtimer_start - (re)start an relative timer on the current CPU | ||
1025 | * @timer: the timer to be added | ||
1026 | * @tim: expiry time | ||
1027 | * @mode: expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL) | ||
1028 | * | ||
1029 | * Returns: | ||
1030 | * 0 on success | ||
1031 | * 1 when the timer was active | ||
1032 | */ | ||
1033 | int | ||
1034 | hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode) | ||
1035 | { | ||
1036 | return hrtimer_start_range_ns(timer, tim, 0, mode); | ||
1037 | } | ||
1019 | EXPORT_SYMBOL_GPL(hrtimer_start); | 1038 | EXPORT_SYMBOL_GPL(hrtimer_start); |
1020 | 1039 | ||
1040 | |||
1021 | /** | 1041 | /** |
1022 | * hrtimer_try_to_cancel - try to deactivate a timer | 1042 | * hrtimer_try_to_cancel - try to deactivate a timer |
1023 | * @timer: hrtimer to stop | 1043 | * @timer: hrtimer to stop |