mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
timerfd: new timerfd API
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]>
This commit is contained in:
parent
5e05ad7d4e
commit
4d672e7ac7
24 changed files with 210 additions and 118 deletions
32
fs/compat.c
32
fs/compat.c
|
|
@ -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 sys_timerfd(ufd, clockid, flags, ut);
|
||||
return error;
|
||||
}
|
||||
|
||||
asmlinkage long compat_sys_timerfd_gettime(int ufd,
|
||||
struct compat_itimerspec __user *otmr)
|
||||
{
|
||||
int error;
|
||||
struct itimerspec t;
|
||||
struct itimerspec __user *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…
Reference in a new issue