Skip to content

Commit

Permalink
timerfd: new timerfd API
Browse files Browse the repository at this point in the history
This is the new timerfd API as it is implemented by the following patch:

int timerfd_create(int clockid, int flags);
int timerfd_settime(int ufd, int flags,
		    const struct itimerspec *utmr,
		    struct itimerspec *otmr);
int timerfd_gettime(int ufd, struct itimerspec *otmr);

The timerfd_create() API creates an un-programmed timerfd fd.  The "clockid"
parameter can be either CLOCK_MONOTONIC or CLOCK_REALTIME.

The timerfd_settime() API give new settings by the timerfd fd, by optionally
retrieving the previous expiration time (in case the "otmr" parameter is not
NULL).

The time value specified in "utmr" is absolute, if the TFD_TIMER_ABSTIME bit
is set in the "flags" parameter.  Otherwise it's a relative time.

The timerfd_gettime() API returns the next expiration time of the timer, or
{0, 0} if the timerfd has not been set yet.

Like the previous timerfd API implementation, read(2) and poll(2) are
supported (with the same interface).  Here's a simple test program I used to
exercise the new timerfd APIs:

http://www.xmailserver.org/timerfd-test2.c

[[email protected]: coding-style cleanups]
[[email protected]: fix ia64 build]
[[email protected]: fix m68k build]
[[email protected]: fix mips build]
[[email protected]: fix alpha, arm, blackfin, cris, m68k, s390, sparc and sparc64 builds]
[[email protected]: fix s390]
[[email protected]: fix powerpc build]
[[email protected]: fix sparc64 more]
Signed-off-by: Davide Libenzi <[email protected]>
Cc: Michael Kerrisk <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Davide Libenzi <[email protected]>
Cc: Michael Kerrisk <[email protected]>
Cc: Martin Schwidefsky <[email protected]>
Signed-off-by: Heiko Carstens <[email protected]>
Cc: Michael Kerrisk <[email protected]>
Cc: Davide Libenzi <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
davidel authored and Linus Torvalds committed Feb 5, 2008
1 parent 5e05ad7 commit 4d672e7
Show file tree
Hide file tree
Showing 24 changed files with 210 additions and 118 deletions.
2 changes: 1 addition & 1 deletion arch/alpha/kernel/systbls.S
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ sys_call_table:
.quad sys_epoll_pwait
.quad sys_utimensat /* 475 */
.quad sys_signalfd
.quad sys_timerfd
.quad sys_ni_syscall
.quad sys_eventfd

.size sys_call_table, . - sys_call_table
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/kernel/calls.S
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@
CALL(sys_kexec_load)
CALL(sys_utimensat)
CALL(sys_signalfd)
/* 350 */ CALL(sys_timerfd)
/* 350 */ CALL(sys_ni_syscall)
CALL(sys_eventfd)
CALL(sys_fallocate)
#ifndef syscalls_counted
Expand Down
2 changes: 1 addition & 1 deletion arch/blackfin/mach-common/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@ ENTRY(_sys_call_table)
.long _sys_epoll_pwait
.long _sys_utimensat
.long _sys_signalfd
.long _sys_timerfd
.long _sys_ni_syscall
.long _sys_eventfd /* 350 */
.long _sys_pread64
.long _sys_pwrite64
Expand Down
2 changes: 1 addition & 1 deletion arch/cris/arch-v10/kernel/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ sys_call_table:
.long sys_epoll_pwait
.long sys_utimensat /* 320 */
.long sys_signalfd
.long sys_timerfd
.long sys_ni_syscall
.long sys_eventfd
.long sys_fallocate

Expand Down
2 changes: 1 addition & 1 deletion arch/ia64/kernel/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ sys_call_table:
data8 sys_epoll_pwait // 1305
data8 sys_utimensat
data8 sys_signalfd
data8 sys_timerfd
data8 sys_ni_syscall
data8 sys_eventfd

.org sys_call_table + 8*NR_syscalls // guard against failures to increase NR_syscalls
2 changes: 1 addition & 1 deletion arch/m68k/kernel/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ sys_call_table:
.long sys_epoll_pwait /* 315 */
.long sys_utimensat
.long sys_signalfd
.long sys_timerfd
.long sys_ni_syscall
.long sys_eventfd
.long sys_fallocate /* 320 */

2 changes: 1 addition & 1 deletion arch/m68knommu/kernel/syscalltable.S
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ ENTRY(sys_call_table)
.long sys_epoll_pwait /* 315 */
.long sys_utimensat
.long sys_signalfd
.long sys_timerfd
.long sys_ni_syscall
.long sys_eventfd
.long sys_fallocate /* 320 */

Expand Down
2 changes: 1 addition & 1 deletion arch/mips/kernel/scall32-o32.S
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ einval: li v0, -EINVAL
sys sys_ioprio_get 2 /* 4315 */
sys sys_utimensat 4
sys sys_signalfd 3
sys sys_timerfd 4
sys sys_ni_syscall 0
sys sys_eventfd 1
sys sys_fallocate 6 /* 4320 */
.endm
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/kernel/scall64-64.S
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ sys_call_table:
PTR sys_ioprio_get
PTR sys_utimensat /* 5275 */
PTR sys_signalfd
PTR sys_timerfd
PTR sys_ni_syscall
PTR sys_eventfd
PTR sys_fallocate
.size sys_call_table,.-sys_call_table
2 changes: 1 addition & 1 deletion arch/mips/kernel/scall64-n32.S
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ EXPORT(sysn32_call_table)
PTR sys_ioprio_get
PTR compat_sys_utimensat
PTR compat_sys_signalfd /* 5280 */
PTR compat_sys_timerfd
PTR sys_ni_syscall
PTR sys_eventfd
PTR sys_fallocate
.size sysn32_call_table,.-sysn32_call_table
2 changes: 1 addition & 1 deletion arch/mips/kernel/scall64-o32.S
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ sys_call_table:
PTR sys_ioprio_get /* 4315 */
PTR compat_sys_utimensat
PTR compat_sys_signalfd
PTR compat_sys_timerfd
PTR sys_ni_syscall
PTR sys_eventfd
PTR sys32_fallocate /* 4320 */
.size sys_call_table,.-sys_call_table
8 changes: 0 additions & 8 deletions arch/s390/kernel/compat_wrapper.S
Original file line number Diff line number Diff line change
Expand Up @@ -1698,14 +1698,6 @@ compat_sys_signalfd_wrapper:
llgfr %r4,%r4 # compat_size_t
jg compat_sys_signalfd

.globl compat_sys_timerfd_wrapper
compat_sys_timerfd_wrapper:
lgfr %r2,%r2 # int
lgfr %r3,%r3 # int
lgfr %r4,%r4 # int
llgtr %r5,%r5 # struct compat_itimerspec *
jg compat_sys_timerfd

.globl sys_eventfd_wrapper
sys_eventfd_wrapper:
llgfr %r2,%r2 # unsigned int
Expand Down
2 changes: 1 addition & 1 deletion arch/s390/kernel/syscalls.S
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,5 @@ SYSCALL(sys_utimes,sys_utimes,compat_sys_utimes_wrapper)
SYSCALL(s390_fallocate,sys_fallocate,sys_fallocate_wrapper)
SYSCALL(sys_utimensat,sys_utimensat,compat_sys_utimensat_wrapper) /* 315 */
SYSCALL(sys_signalfd,sys_signalfd,compat_sys_signalfd_wrapper)
SYSCALL(sys_timerfd,sys_timerfd,compat_sys_timerfd_wrapper)
NI_SYSCALL /* 317 old sys_timer_fd */
SYSCALL(sys_eventfd,sys_eventfd,sys_eventfd_wrapper)
2 changes: 1 addition & 1 deletion arch/sparc/kernel/systbls.S
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ sys_call_table:
/*295*/ .long sys_fchmodat, sys_faccessat, sys_pselect6, sys_ppoll, sys_unshare
/*300*/ .long sys_set_robust_list, sys_get_robust_list, sys_migrate_pages, sys_mbind, sys_get_mempolicy
/*305*/ .long sys_set_mempolicy, sys_kexec_load, sys_move_pages, sys_getcpu, sys_epoll_pwait
/*310*/ .long sys_utimensat, sys_signalfd, sys_timerfd, sys_eventfd, sys_fallocate
/*310*/ .long sys_utimensat, sys_signalfd, sys_ni_syscall, sys_eventfd, sys_fallocate

#ifdef CONFIG_SUNOS_EMUL
/* Now the SunOS syscall table. */
Expand Down
4 changes: 2 additions & 2 deletions arch/sparc64/kernel/systbls.S
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ sys_call_table32:
.word sys_fchmodat, sys_faccessat, compat_sys_pselect6, compat_sys_ppoll, sys_unshare
/*300*/ .word compat_sys_set_robust_list, compat_sys_get_robust_list, compat_sys_migrate_pages, compat_sys_mbind, compat_sys_get_mempolicy
.word compat_sys_set_mempolicy, compat_sys_kexec_load, compat_sys_move_pages, sys_getcpu, compat_sys_epoll_pwait
/*310*/ .word compat_sys_utimensat, compat_sys_signalfd, compat_sys_timerfd, sys_eventfd, compat_sys_fallocate
/*310*/ .word compat_sys_utimensat, compat_sys_signalfd, sys_ni_syscall, sys_eventfd, compat_sys_fallocate

#endif /* CONFIG_COMPAT */

Expand Down Expand Up @@ -152,7 +152,7 @@ sys_call_table:
.word sys_fchmodat, sys_faccessat, sys_pselect6, sys_ppoll, sys_unshare
/*300*/ .word sys_set_robust_list, sys_get_robust_list, sys_migrate_pages, sys_mbind, sys_get_mempolicy
.word sys_set_mempolicy, sys_kexec_load, sys_move_pages, sys_getcpu, sys_epoll_pwait
/*310*/ .word sys_utimensat, sys_signalfd, sys_timerfd, sys_eventfd, sys_fallocate
/*310*/ .word sys_utimensat, sys_signalfd, sys_ni_syscall, sys_eventfd, sys_fallocate

#if defined(CONFIG_SUNOS_EMUL) || defined(CONFIG_SOLARIS_EMUL) || \
defined(CONFIG_SOLARIS_EMUL_MODULE)
Expand Down
32 changes: 27 additions & 5 deletions fs/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2206,19 +2206,41 @@ asmlinkage long compat_sys_signalfd(int ufd,

#ifdef CONFIG_TIMERFD

asmlinkage long compat_sys_timerfd(int ufd, int clockid, int flags,
const struct compat_itimerspec __user *utmr)
asmlinkage long compat_sys_timerfd_settime(int ufd, int flags,
const struct compat_itimerspec __user *utmr,
struct compat_itimerspec __user *otmr)
{
int error;
struct itimerspec t;
struct itimerspec __user *ut;

if (get_compat_itimerspec(&t, utmr))
return -EFAULT;
ut = compat_alloc_user_space(sizeof(*ut));
if (copy_to_user(ut, &t, sizeof(t)))
ut = compat_alloc_user_space(2 * sizeof(struct itimerspec));
if (copy_to_user(&ut[0], &t, sizeof(t)))
return -EFAULT;
error = sys_timerfd_settime(ufd, flags, &ut[0], &ut[1]);
if (!error && otmr)
error = (copy_from_user(&t, &ut[1], sizeof(struct itimerspec)) ||
put_compat_itimerspec(otmr, &t)) ? -EFAULT: 0;

return error;
}

asmlinkage long compat_sys_timerfd_gettime(int ufd,
struct compat_itimerspec __user *otmr)
{
int error;
struct itimerspec t;
struct itimerspec __user *ut;

return sys_timerfd(ufd, clockid, flags, ut);
ut = compat_alloc_user_space(sizeof(struct itimerspec));
error = sys_timerfd_gettime(ufd, ut);
if (!error)
error = (copy_from_user(&t, ut, sizeof(struct itimerspec)) ||
put_compat_itimerspec(otmr, &t)) ? -EFAULT: 0;

return error;
}

#endif /* CONFIG_TIMERFD */
Loading

0 comments on commit 4d672e7

Please sign in to comment.