{sys_,/dev/}epoll waiting timeout

From: Lennert Buytenhek (buytenh@math.leidenuniv.nl)
Date: Wed Jan 22 2003 - 01:55:02 EST


Both /dev/epoll EP_POLL and sys_epoll_wait, when converting the passed
timeout value in msec to jiffies, round down instead of up. This
occasionally causes these functions to return without any active fd's
before the given timeout period has passed.

This can cause fun situations like these:
        epoll_wait(epfd, events, maxevents, timeout_until_next_timer_expiry)
                [ returns too early ]

        gettimeofday(&now, NULL)
                [ notice that the first timer has not yet expired, do nothing ]

        epoll_wait(epfd, events, maxevents, random_small_value_less_than_jiffy)
                [ returns immediately ]

        gettimeofday(&now, NULL)
                [ notice that first timer still didn't expire yet, do nothing ]


Effectively causing busy-wait loops of on average half a jiffy.

nanosleep(2) always rounds timeout values up (I think it is required to do
so by some specification which says that this call should sleep _at_least_
the given amount of time), and this approach to me makes sense for
{sys_,/dev/}epoll also. See <linux/time.h>:timespec_to_jiffies and

Will you accept a patch to do this?

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

This archive was generated by hypermail 2b29 : Thu Jan 23 2003 - 22:00:28 EST