1. 26 Jul, 2007 1 commit
    • Davide Libenzi's avatar
      make timerfd return a u64 and fix the __put_user · 09828402
      Davide Libenzi authored
      Davi fixed a missing cast in the __put_user(), that was making timerfd
      return a single byte instead of the full value.
      
      Talking with Michael about the timerfd man page, we think it'd be better to
      use a u64 for the returned value, to align it with the eventfd
      implementation.
      
      This is an ABI change.  The timerfd code is new in 2.6.22 and if we merge this
      into 2.6.23 then we should also merge it into 2.6.22.x.  That will leave a few
      early 2.6.22 kernels out in the wild which might misbehave when a future
      timerfd-enabled glibc is run on them.
      
      mtk says: The difference would be that read() will only return 4 bytes, while
      the application will expect 8.  If the application is checking the size of
      returned value, as it should, then it will be able to detect the problem (it
      could even be sophisticated enough to know that if this is a 4-byte return,
      then it is running on an old 2.6.22 kernel).  If the application is not
      checking the return from read(), then its 8-byte buffer will not be filled --
      the contents of the last 4 bytes will be undefined, so the u64 value as a
      whole will be junk.
      Signed-off-by: default avatarDavide Libenzi <davidel@xmailserver.org>
      Cc: Michael Kerrisk <mtk-manpages@gmx.net>
      Cc: Davi Arnaut <davi@haxent.com.br>
      Cc: <stable@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      09828402
  2. 18 May, 2007 1 commit
  3. 11 May, 2007 1 commit
    • Davide Libenzi's avatar
      signal/timer/event: timerfd core · b215e283
      Davide Libenzi authored
      This patch introduces a new system call for timers events delivered though
      file descriptors.  This allows timer event to be used with standard POSIX
      poll(2), select(2) and read(2).  As a consequence of supporting the Linux
      f_op->poll subsystem, they can be used with epoll(2) too.
      
      The system call is defined as:
      
      int timerfd(int ufd, int clockid, int flags, const struct itimerspec *utmr);
      
      The "ufd" parameter allows for re-use (re-programming) of an existing timerfd
      w/out going through the close/open cycle (same as signalfd).  If "ufd" is -1,
      s new file descriptor will be created, otherwise the existing "ufd" will be
      re-programmed.
      
      The "clockid" parameter is either CLOCK_MONOTONIC or CLOCK_REALTIME.  The time
      specified in the "utmr->it_value" parameter is the expiry time for the timer.
      
      If the TFD_TIMER_ABSTIME flag is set in "flags", this is an absolute time,
      otherwise it's a relative time.
      
      If the time specified in the "utmr->it_interval" is not zero (.tv_sec == 0,
      tv_nsec == 0), this is the period at which the following ticks should be
      generated.
      
      The "utmr->it_interval" should be set to zero if only one tick is requested.
      Setting the "utmr->it_value" to zero will disable the timer, or will create a
      timerfd without the timer enabled.
      
      The function returns the new (or same, in case "ufd" is a valid timerfd
      descriptor) file, or -1 in case of error.
      
      As stated before, the timerfd file descriptor supports poll(2), select(2) and
      epoll(2).  When a timer event happened on the timerfd, a POLLIN mask will be
      returned.
      
      The read(2) call can be used, and it will return a u32 variable holding the
      number of "ticks" that happened on the interface since the last call to
      read(2).  The read(2) call supportes the O_NONBLOCK flag too, and EAGAIN will
      be returned if no ticks happened.
      
      A quick test program, shows timerfd working correctly on my amd64 box:
      
      http://www.xmailserver.org/timerfd-test.c
      
      [akpm@linux-foundation.org: add sys_timerfd to sys_ni.c]
      Signed-off-by: default avatarDavide Libenzi <davidel@xmailserver.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      b215e283