[RFC][PATCH 1/4] clock_rtoffset: new syscall
From: Alexander Shishkin
Date: Wed Apr 27 2011 - 06:46:09 EST
In order to keep track of system time changes, we introduce a new
syscall which returns the offset of CLOCK_MONOTONIC clock against
CLOCK_REALTIME. The caller is to store this value and use it in
system calls (like clock_nanosleep or timerfd_settime) that will
compare it against the effective offset in order to ensure that
the caller's notion of the system time corresponds to the effective
system time at the moment of the action being carried out. If it
has changed, these system calls will return an error and the caller
will have to obtain this offset again.
Signed-off-by: Alexander Shishkin <virtuoso@xxxxxxxxx>
CC: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
CC: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
CC: John Stultz <johnstul@xxxxxxxxxx>
CC: Chris Friesen <chris.friesen@xxxxxxxxxxx>
CC: Kay Sievers <kay.sievers@xxxxxxxx>
CC: Kirill A. Shutemov <kirill@xxxxxxxxxxxxx>
CC: linux-kernel@xxxxxxxxxxxxxxx
---
include/asm-generic/unistd.h | 4 +++-
kernel/posix-timers.c | 14 ++++++++++++++
kernel/sys_ni.c | 3 +++
3 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/include/asm-generic/unistd.h b/include/asm-generic/unistd.h
index 07c40d5..89edfc8 100644
--- a/include/asm-generic/unistd.h
+++ b/include/asm-generic/unistd.h
@@ -654,9 +654,11 @@ __SYSCALL(__NR_open_by_handle_at, sys_open_by_handle_at)
__SYSCALL(__NR_clock_adjtime, sys_clock_adjtime)
#define __NR_syncfs 267
__SYSCALL(__NR_syncfs, sys_syncfs)
+#define __NR_clock_rtoffset 268
+__SYSCALL(__NR_clock_rtoffset, sys_clock_rtoffset)
#undef __NR_syscalls
-#define __NR_syscalls 268
+#define __NR_syscalls 269
/*
* All syscalls below here should go away really,
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index e5498d7..2512708 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -1019,6 +1019,20 @@ SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
}
/*
+ * Retrieve CLOCK_REALTIME's offset against CLOCK_MONOTONIC
+ */
+SYSCALL_DEFINE1(clock_rtoffset, struct timespec __user, *offset)
+{
+ struct timespec time, mono, sleep;
+ int ret;
+
+ get_xtime_and_monotonic_and_sleep_offset(&time, &mono, &sleep);
+ ret = copy_to_user(offset, &mono, sizeof(mono));
+
+ return ret ? -EFAULT : 0;
+}
+
+/*
* nanosleep for monotonic and realtime clocks
*/
static int common_nsleep(const clockid_t which_clock, int flags,
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index 25cc41c..47791cc 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -191,3 +191,6 @@ cond_syscall(sys_fanotify_mark);
cond_syscall(sys_name_to_handle_at);
cond_syscall(sys_open_by_handle_at);
cond_syscall(compat_sys_open_by_handle_at);
+
+/* monotonic vs realtime clock offset */
+cond_syscall(sys_clock_rtoffset);
--
1.7.4.1
--
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/