(original) (raw)
--- pipetest.c.orig Sun Oct 27 15:11:57 2002 +++ pipetest.c Sun Oct 27 15:12:00 2002 @@ -27,7 +27,23 @@ #define PAGE_SIZE 4096 #include +#include #include "eventpoll.h" +#define __NR_sys_epoll_create 254 +#define __NR_sys_epoll_ctl 255 +#define __NR_sys_epoll_wait 256 + + +#define __sys_epoll_create(maxfds) _syscall1(int, sys_epoll_create, int, maxfds) +#define __sys_epoll_ctl(epfd, op, fd, events) _syscall4(int, sys_epoll_ctl, \ + int, epfd, int, op, int, fd, unsigned int, events) +#define __sys_epoll_wait(epfd, events, timeout) _syscall3(int, sys_epoll_wait, \ + int, epfd, struct pollfd **, events, int, timeout) + +__sys_epoll_create(maxfds) +__sys_epoll_ctl(epfd, op, fd, events) +__sys_epoll_wait(epfd, events, timeout) + #if !defined(DEBUG) #define dprintf(x...) do {} while(0) @@ -40,6 +56,7 @@ enum { MODE_POLL, MODE_EPOLL, + MODE_SYS_EPOLL, MODE_AIO_POLL, MODE_AIO_READ, } mode = MODE_POLL; @@ -47,6 +64,7 @@ const char *modes[] = { "poll", "epoll", + "sys-epoll", "aio-poll", "aio-read", }; @@ -62,7 +80,7 @@ int done; #define FD_SLOP 10 -#define MAX_FDS 20010 +#define MAX_FDS 64*1024 #define READ 0 #define WRITE 1 @@ -321,6 +339,9 @@ if (mode == MODE_EPOLL) epoll_add_fd(fds[READ], POLLIN); + if (mode == MODE_SYS_EPOLL) + sys_epoll_ctl(epoll_fd, EP_CTL_ADD, fds[READ], POLLIN); + inf = &fdinfo[fds[WRITE]]; assert(inf->active == 0); inf->active = 1; @@ -416,6 +437,37 @@ } } +void sys_epoll_setup(void) +{ + unsigned long size; + + epoll_fd = sys_epoll_create(MAX_FDS); + if (-1 == epoll_fd) + pexit("epoll_create"); +} +/* This function is stolen from dphttpd.c */ +void sys_epoll_main_loop(void) +{ + int ii, nfds; + struct pollfd *pfds; + struct evpoll evp; + + while (!done) { + send_pending_tokes(); + + evp.ep_timeout = 100 /*STD_SCHED_TIMEOUT*/; + evp.ep_resoff = 0; + + nfds = sys_epoll_wait(epoll_fd, &pfds, 100); + if (nfds < 0) + pexit("epoll_wait"); + for (ii = 0; ii < nfds; ii++, pfds++) { + if (pfds->revents & POLLIN) + read_and_process_token(pfds->fd); + } + } +} + struct aio_ring { unsigned id; /* kernel internal index number */ unsigned nr; /* number of io_events */ @@ -494,7 +546,7 @@ submit_iocbs(); send_pending_tokes(); - res = io_getevents(ctx, 1/*MAX_FDS*/, &event, NULL); + res = io_getevents(ctx, 1, MAX_FDS, &event, NULL); if (res <= 0) { printf("io_getevents: %d (%s)", res, strerror(-res)); exit(1); @@ -537,6 +589,10 @@ mode = MODE_AIO_POLL; } else if (0 == strcmp(argv[1], "--epoll")) { mode = MODE_EPOLL; + } else if (0 == strcmp(argv[1], "--poll")) { + mode = MODE_POLL; + } else if (0 == strcmp(argv[1], "--sys-epoll")) { + mode = MODE_SYS_EPOLL; } else if (0 == strcmp(argv[1], "--aio-read")) { mode = MODE_AIO_READ; } else if (0 == strcmp(argv[1], "--aio-mmap")) { @@ -553,7 +609,7 @@ } if (argc != 4) { - fprintf(stderr, "usage: aio-poll-pipe \n"); + fprintf(stderr, "usage: pipetest [--aio-poll | --epoll] [--bufsize] \n"); return 2; } @@ -585,6 +641,9 @@ if (mode == MODE_EPOLL) epoll_setup(); + if (mode == MODE_SYS_EPOLL) + sys_epoll_setup(); + makepipes(nr); /* epoll and poll both have their startup overhead in @@ -607,6 +666,9 @@ if (mode == MODE_EPOLL) epoll_main_loop(); + if (mode == MODE_SYS_EPOLL) + sys_epoll_main_loop(); + if (mode == MODE_AIO_POLL || mode == MODE_AIO_READ) { if (MODE_AIO_MMAP) mmap_aio_main_loop();