13 Oct, 2012

1 commit


24 Mar, 2012

1 commit

  • In some cases the poll() implementation in a driver has to do different
    things depending on the events the caller wants to poll for. An example
    is when a driver needs to start a DMA engine if the caller polls for
    POLLIN, but doesn't want to do that if POLLIN is not requested but instead
    only POLLOUT or POLLPRI is requested. This is something that can happen
    in the video4linux subsystem among others.

    Unfortunately, the current epoll/poll/select implementation doesn't
    provide that information reliably. The poll_table_struct does have it: it
    has a key field with the event mask. But once a poll() call matches one
    or more bits of that mask any following poll() calls are passed a NULL
    poll_table pointer.

    Also, the eventpoll implementation always left the key field at ~0 instead
    of using the requested events mask.

    This was changed in eventpoll.c so the key field now contains the actual
    events that should be polled for as set by the caller.

    The solution to the NULL poll_table pointer is to set the qproc field to
    NULL in poll_table once poll() matches the events, not the poll_table
    pointer itself. That way drivers can obtain the mask through a new
    poll_requested_events inline.

    The poll_table_struct can still be NULL since some kernel code calls it
    internally (netfs_state_poll() in ./drivers/staging/pohmelfs/netfs.h). In
    that case poll_requested_events() returns ~0 (i.e. all events).

    Very rarely drivers might want to know whether poll_wait will actually
    wait. If another earlier file descriptor in the set already matched the
    events the caller wanted to wait for, then the kernel will return from the
    select() call without waiting. This might be useful information in order
    to avoid doing expensive work.

    A new helper function poll_does_not_wait() is added that drivers can use
    to detect this situation. This is now used in sock_poll_wait() in
    include/net/sock.h. This was the only place in the kernel that needed
    this information.

    Drivers should no longer access any of the poll_table internals, but use
    the poll_requested_events() and poll_does_not_wait() access functions
    instead. In order to enforce that the poll_table fields are now prepended
    with an underscore and a comment was added warning against using them
    directly.

    This required a change in unix_dgram_poll() in unix/af_unix.c which used
    the key field to get the requested events. It's been replaced by a call
    to poll_requested_events().

    For qproc it was especially important to change its name since the
    behavior of that field changes with this patch since this function pointer
    can now be NULL when that wasn't possible in the past.

    Any driver accessing the qproc or key fields directly will now fail to compile.

    Some notes regarding the correctness of this patch: the driver's poll()
    function is called with a 'struct poll_table_struct *wait' argument. This
    pointer may or may not be NULL, drivers can never rely on it being one or
    the other as that depends on whether or not an earlier file descriptor in
    the select()'s fdset matched the requested events.

    There are only three things a driver can do with the wait argument:

    1) obtain the key field:

    events = wait ? wait->key : ~0;

    This will still work although it should be replaced with the new
    poll_requested_events() function (which does exactly the same).
    This will now even work better, since wait is no longer set to NULL
    unnecessarily.

    2) use the qproc callback. This could be deadly since qproc can now be
    NULL. Renaming qproc should prevent this from happening. There are no
    kernel drivers that actually access this callback directly, BTW.

    3) test whether wait == NULL to determine whether poll would return without
    waiting. This is no longer sufficient as the correct test is now
    wait == NULL || wait->_qproc == NULL.

    However, the worst that can happen here is a slight performance hit in
    the case where wait != NULL and wait->_qproc == NULL. In that case the
    driver will assume that poll_wait() will actually add the fd to the set
    of waiting file descriptors. Of course, poll_wait() will not do that
    since it tests for wait->_qproc. This will not break anything, though.

    There is only one place in the whole kernel where this happens
    (sock_poll_wait() in include/net/sock.h) and that code will be replaced
    by a call to poll_does_not_wait() in the next patch.

    Note that even if wait->_qproc != NULL drivers cannot rely on poll_wait()
    actually waiting. The next file descriptor from the set might match the
    event mask and thus any possible waits will never happen.

    Signed-off-by: Hans Verkuil
    Reviewed-by: Jonathan Corbet
    Reviewed-by: Al Viro
    Cc: Davide Libenzi
    Signed-off-by: Hans de Goede
    Cc: Mauro Carvalho Chehab
    Cc: David Miller
    Cc: Eric Dumazet
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Hans Verkuil
     

31 Mar, 2011

1 commit


10 Dec, 2010

1 commit

  • Convert duplicated sys_poll to select. As Kosaki suggests, sys_poll() and
    sys_select() are now hidden by SYSCALL_DEFINEx() macros so it would be
    better to use plain select/poll syscall name.

    Signed-off-by: Namhyung Kim
    Reviewed-by: KOSAKI Motohiro
    Signed-off-by: Jiri Kosina

    Namhyung Kim
     

28 Oct, 2010

1 commit

  • This make epoll use hrtimers for the timeout value which prevents
    epoll_wait() from timing out up to a millisecond early.

    This mirrors the behavior of select() and poll().

    Signed-off-by: Shawn Bohrer
    Cc: Al Viro
    Acked-by: Davide Libenzi
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Shawn Bohrer
     

13 Mar, 2010

1 commit

  • Extern declarations in sysctl.c should be moved to their own header file,
    and then include them in relavant .c files.

    Move epoll_table extern declaration to linux/poll.h

    Signed-off-by: Dave Young
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dave Young
     

05 Oct, 2009

1 commit


17 Jun, 2009

1 commit

  • After introduction of keyed wakeups Davide Libenzi did on epoll, we are
    able to avoid spurious wakeups in poll()/select() code too.

    For example, typical use of poll()/select() is to wait for incoming
    network frames on many sockets. But TX completion for UDP/TCP frames call
    sock_wfree() which in turn schedules thread.

    When scheduled, thread does a full scan of all polled fds and can sleep
    again, because nothing is really available. If number of fds is large,
    this cause significant load.

    This patch makes select()/poll() aware of keyed wakeups and useless
    wakeups are avoided. This reduces number of context switches by about 50%
    on some setups, and work performed by sofirq handlers.

    Signed-off-by: Eric Dumazet
    Acked-by: David S. Miller
    Acked-by: Andi Kleen
    Acked-by: Ingo Molnar
    Acked-by: Davide Libenzi
    Cc: Christoph Lameter
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eric Dumazet
     

07 Jan, 2009

1 commit

  • f_op->poll is the only vfs operation which is not allowed to sleep. It's
    because poll and select implementation used task state to synchronize
    against wake ups, which doesn't have to be the case anymore as wait/wake
    interface can now use custom wake up functions. The non-sleep restriction
    can be a bit tricky because ->poll is not called from an atomic context
    and the result of accidentally sleeping in ->poll only shows up as
    temporary busy looping when the timing is right or rather wrong.

    This patch converts poll/select to use custom wake up function and use
    separate triggered variable to synchronize against wake up events. The
    only added overhead is an extra function call during wake up and
    negligible.

    This patch removes the one non-sleep exception from vfs locking rules and
    is beneficial to userland filesystem implementations like FUSE, 9p or
    peculiar fs like spufs as it's very difficult for those to implement
    non-sleeping poll method.

    While at it, make the following cosmetic changes to make poll.h and
    select.c checkpatch friendly.

    * s/type * symbol/type *symbol/ : three places in poll.h
    * remove blank line before EXPORT_SYMBOL() : two places in select.c

    Oleg: spotted missing barrier in poll_schedule_timeout()
    Davide: spotted missing write barrier in pollwake()

    Signed-off-by: Tejun Heo
    Cc: Eric Van Hensbergen
    Cc: Ron Minnich
    Cc: Ingo Molnar
    Cc: Christoph Hellwig
    Signed-off-by: Miklos Szeredi
    Cc: Davide Libenzi
    Cc: Brad Boyer
    Cc: Al Viro
    Cc: Roland McGrath
    Cc: Mauro Carvalho Chehab
    Signed-off-by: Andrew Morton
    Cc: Davide Libenzi
    Cc: Oleg Nesterov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Tejun Heo
     

06 Sep, 2008

2 commits

  • With lots of help, input and cleanups from Thomas Gleixner

    This patch switches select() and poll() over to hrtimers.

    The core of the patch is replacing the "s64 timeout" with a
    "struct timespec end_time" in all the plumbing.

    But most of the diffstat comes from using the just introduced helpers:
    poll_select_set_timeout
    poll_select_copy_remaining
    timespec_add_safe
    which make manipulating the timespec easier and less error-prone.

    Signed-off-by: Arjan van de Ven
    Signed-off-by: Thomas Gleixner

    Arjan van de Ven
     
  • This patch adds 2 helpers that will be used for the hrtimer based select/poll:

    poll_select_set_timeout() is a helper that takes a timeout (as a second, nanosecond
    pair) and turns that into a "struct timespec" that represents the absolute end time.
    This is a common operation in the many select() and poll() variants and needs various,
    common, sanity checks.

    poll_select_copy_remaining() is a helper that takes care of copying the remaining
    time to userspace, as select(), pselect() and ppoll() do. This function comes in
    both a natural and a compat implementation (due to datastructure differences).

    Signed-off-by: Thomas Gleixner
    Signed-off-by: Arjan van de Ven

    Thomas Gleixner
     

02 May, 2008

1 commit


12 Sep, 2007

1 commit

  • Taneli Vähäkangas reported that commit
    786d7e1612f0b0adb6046f19b906609e4fe8b1ba aka "Fix rmmod/read/write races
    in /proc entries" broke SBCL + SLIME combo.

    The old code in do_select() used DEFAULT_POLLMASK, if couldn't find
    ->poll handler. The new code makes ->poll always there and returns 0 by
    default, which is not correct. Return DEFAULT_POLLMASK instead.

    Steps to reproduce:

    install emacs, SBCL, SLIME
    emacs
    M-x slime in *inferior-lisp* buffer
    [watch it doing "Connecting to Swank on port X.."]

    Please, apply before 2.6.23.

    P.S.: why SBCL can't just read(2) /proc/cpuinfo is a mystery.

    Signed-off-by: Alexey Dobriyan
    Cc: T Taneli Vahakangas
    Cc: Oleg Nesterov
    Cc: "Eric W. Biederman"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     

04 Dec, 2006

1 commit


29 Mar, 2006

1 commit

  • Optimize select and poll by a using stack space for small fd sets

    This brings back an old optimization from Linux 2.0. Using the stack is
    faster than kmalloc. On a Intel P4 system it speeds up a select of a
    single pty fd by about 13% (~4000 cycles -> ~3500)

    It also saves memory because a daemon hanging in select or poll will
    usually save one or two less pages. This can add up - e.g. if you have 10
    daemons blocking in poll/select you save 40KB of memory.

    I did a patch for this long ago, but it was never applied. This version is
    a reimplementation of the old patch that tries to be less intrusive. I
    only did the minimal changes needed for the stack allocation.

    The cut off point before external memory is allocated is currently at
    832bytes. The system calls always allocate this much memory on the stack.

    These 832 bytes are divided into 256 bytes frontend data (for the select
    bitmaps of the pollfds) and the rest of the space for the wait queues used
    by the low level drivers. There are some extreme cases where this won't
    work out for select and it falls back to allocating memory too early -
    especially with very sparse large select bitmaps - but the majority of
    processes who only have a small number of file descriptors should be ok.
    [TBD: 832/256 might not be the best split for select or poll]

    I suspect more optimizations might be possible, but they would be more
    complicated. One way would be to cache the select/poll context over
    multiple system calls because typically the input values should be similar.
    Problem is when to flush the file descriptors out though.

    Signed-off-by: Andi Kleen
    Cc: Eric Dumazet
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andi Kleen
     

19 Jan, 2006

1 commit

  • The following implementation of ppoll() and pselect() system calls
    depends on the architecture providing a TIF_RESTORE_SIGMASK flag in the
    thread_info.

    These system calls have to change the signal mask during their
    operation, and signal handlers must be invoked using the new, temporary
    signal mask. The old signal mask must be restored either upon successful
    exit from the system call, or upon returning from the invoked signal
    handler if the system call is interrupted. We can't simply restore the
    original signal mask and return to userspace, since the restored signal
    mask may actually block the signal which interrupted the system call.

    The TIF_RESTORE_SIGMASK flag deals with this by causing the syscall exit
    path to trap into do_signal() just as TIF_SIGPENDING does, and by
    causing do_signal() to use the saved signal mask instead of the current
    signal mask when setting up the stack frame for the signal handler -- or
    by causing do_signal() to simply restore the saved signal mask in the
    case where there is no handler to be invoked.

    The first patch implements the sys_pselect() and sys_ppoll() system
    calls, which are present only if TIF_RESTORE_SIGMASK is defined. That
    #ifdef should go away in time when all architectures have implemented
    it. The second patch implements TIF_RESTORE_SIGMASK for the PowerPC
    kernel (in the -mm tree), and the third patch then removes the
    arch-specific implementations of sys_rt_sigsuspend() and replaces them
    with generic versions using the same trick.

    The fourth and fifth patches, provided by David Howells, implement
    TIF_RESTORE_SIGMASK for FR-V and i386 respectively, and the sixth patch
    adds the syscalls to the i386 syscall table.

    This patch:

    Add the pselect() and ppoll() system calls, providing core routines usable by
    the original select() and poll() system calls and also the new calls (with
    their semantics w.r.t timeouts).

    Signed-off-by: David Woodhouse
    Cc: Michael Kerrisk
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    David Woodhouse
     

17 Apr, 2005

1 commit

  • Initial git repository build. I'm not bothering with the full history,
    even though we have it. We can create a separate "historical" git
    archive of that later if we want to, and in the meantime it's about
    3.2GB when imported into git - space that would just make the early
    git days unnecessarily complicated, when we don't have a lot of good
    infrastructure for it.

    Let it rip!

    Linus Torvalds