[PATCH RFC 5/8] clock device: convert timer_create

From: Richard Cochran
Date: Thu Nov 04 2010 - 15:29:45 EST


This patch lets the timer_create system call use dynamic clock devices.

Signed-off-by: Richard Cochran <richard.cochran@xxxxxxxxxx>
---
include/linux/clockdevice.h | 5 +++++
kernel/posix-timers.c | 12 ++++++++++--
kernel/time/clockdevice.c | 17 +++++++++++++++++
3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/include/linux/clockdevice.h b/include/linux/clockdevice.h
index ae258ac..3201a28 100644
--- a/include/linux/clockdevice.h
+++ b/include/linux/clockdevice.h
@@ -103,4 +103,9 @@ void *clock_device_private(struct file *fp);
*/
struct clock_device *clockid_to_clock_device(clockid_t id);

+/*
+ * The following functions are only to be called from posix-timers.c
+ */
+int clock_device_timer_create(struct clock_device *clk, struct k_itimer *kit);
+
#endif
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index ef4e222..42efbe9 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -39,6 +39,7 @@
#include <asm/uaccess.h>
#include <linux/list.h>
#include <linux/init.h>
+#include <linux/clockdevice.h>
#include <linux/compiler.h>
#include <linux/idr.h>
#include <linux/posix-timers.h>
@@ -523,12 +524,15 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
struct sigevent __user *, timer_event_spec,
timer_t __user *, created_timer_id)
{
+ struct clock_device *clk_dev;
struct k_itimer *new_timer;
int error, new_timer_id;
sigevent_t event;
int it_id_set = IT_ID_NOT_SET;

- if (invalid_clockid(which_clock))
+ clk_dev = clockid_to_clock_device(which_clock);
+
+ if (!clk_dev && invalid_clockid(which_clock))
return -EINVAL;

new_timer = alloc_posix_timer();
@@ -591,7 +595,11 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
goto out;
}

- error = CLOCK_DISPATCH(which_clock, timer_create, (new_timer));
+ if (clk_dev)
+ error = clock_device_timer_create(clk_dev, new_timer);
+ else {
+ error = CLOCK_DISPATCH(which_clock, timer_create, (new_timer));
+ }
if (error)
goto out;

diff --git a/kernel/time/clockdevice.c b/kernel/time/clockdevice.c
index 3f2870d..166cc30 100644
--- a/kernel/time/clockdevice.c
+++ b/kernel/time/clockdevice.c
@@ -264,3 +264,20 @@ SYSCALL_DEFINE2(clock_settime,
mutex_unlock(&clk->mux);
return err;
}
+
+int clock_device_timer_create(struct clock_device *clk, struct k_itimer *kit)
+{
+ int err;
+
+ mutex_lock(&clk->mux);
+
+ if (clk->zombie)
+ err = -ENODEV;
+ else if (!clk->ops->timer_create)
+ err = -EOPNOTSUPP;
+ else
+ err = clk->ops->timer_create(clk->priv, kit);
+
+ mutex_unlock(&clk->mux);
+ return err;
+}
--
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/