On the other hand, if /dev/epoll were flexible enough that it could
deliver AIO completion notifications, then /dev/sigtimedwait
would not be needed. For instance:
// extend bits/poll.h
#define POLLAIO 0x800 // aio completion event; pollfd.fd contains aiocb *
// open /dev/epoll and set up map as usual
kdpfd = open("/dev/epoll", O_RDWR);
char *map = mmap(NULL, mapsize, PROT_READ | PROT_WRITE, MAP_PRIVATE, kdpfd, 0);
// tell our /dev/epoll fd that we're interested in events on fd diskfd
struct pollfd pfd;
pfd.fd = diskfd;
pfd.events = AIOEVENT;
pfd.revents = 0;
write(kdpfd, &pfd, sizeof(pfd));
// set up an asynchronous read from 'diskfd'
struct aiocb *r = malloc(sizeof(*r));
r->aio_filedes = diskfd;
r->aio_... = ...
// when read is finished, have it notify the /dev/epoll device
// interested in diskfd rather than sending a signal
r->aio_sigevent.sigev_notify = SIGEV_NONE;
aio_read(r);
...
// Pick up events
for (;;) {
struct devpoll dvp;
dvp.dp_nfds = 1000;
dvp.dp_fds = NULL; // NULL means "use map instead of buffer"
dvp.dp_timeout = 1;
int nevents = ioctl(kdpfd, DS_SIGTIMEDWAIT, &dvp);
struct pollfd *result = map + dvp.result_offset;
// use 'em. Some might be aio completion notifications;
// some might be traditional poll notifications
// (and if this is AIX, some might be sysv message queue notifications!)
for (i=0; i<nevents; i++)
if (result[i].revents & POLLAIO)
handle_aio_completion((struct aiocb *)result[i].fd);
else
handle_readiness(&result[i]);
}
Davide, is that along the lines of what you were thinking of
for /dev/epoll and disk files? (Plain old polling of disk
files doesn't make much sense unless you're just interested in
them growing, I suppose; aio completion notification is what you
really want.)
- Dan
-- "I have seen the future, and it licks itself clean." -- Bucky Katt - 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/