Browse Source

[core] tighter OS event poll loops (better asm)

slightly reorganize some code for better asm
master
Glenn Strauss 5 months ago
parent
commit
7b5ba32a12
  1. 11
      src/fdevent_freebsd_kqueue.c
  2. 7
      src/fdevent_linux_sysepoll.c
  3. 24
      src/fdevent_poll.c
  4. 11
      src/fdevent_solaris_devpoll.c

11
src/fdevent_freebsd_kqueue.c

@ -72,17 +72,16 @@ static int fdevent_freebsd_kqueue_event_set(fdevents *ev, fdnode *fdn, int event
static int fdevent_freebsd_kqueue_poll(fdevents * const ev, int timeout_ms) {
struct timespec ts;
int n;
ts.tv_sec = timeout_ms / 1000;
ts.tv_nsec = (timeout_ms % 1000) * 1000000;
n = kevent(ev->kq_fd, NULL, 0, ev->kq_results, ev->maxfds, &ts);
struct kevent * const restrict kq_results = ev->kq_results;
const int n = kevent(ev->kq_fd, NULL, 0, kq_results, ev->maxfds, &ts);
for (int i = 0; i < n; ++i) {
fdnode * const fdn = (fdnode *)ev->kq_results[i].udata;
int filt = ev->kq_results[i].filter;
int e = ev->kq_results[i].flags;
fdnode * const fdn = (fdnode *)kq_results[i].udata;
int filt = kq_results[i].filter;
int e = kq_results[i].flags;
if ((fdevent_handler)NULL != fdn->handler) {
int revents = (filt == EVFILT_READ) ? FDEVENT_IN : FDEVENT_OUT;
if (e & EV_EOF)

7
src/fdevent_linux_sysepoll.c

@ -35,10 +35,11 @@ static int fdevent_linux_sysepoll_event_set(fdevents *ev, fdnode *fdn, int event
}
static int fdevent_linux_sysepoll_poll(fdevents * const ev, int timeout_ms) {
int n = epoll_wait(ev->epoll_fd, ev->epoll_events, ev->maxfds, timeout_ms);
struct epoll_event * const restrict epoll_events = ev->epoll_events;
int n = epoll_wait(ev->epoll_fd, epoll_events, ev->maxfds, timeout_ms);
for (int i = 0; i < n; ++i) {
fdnode * const fdn = (fdnode *)ev->epoll_events[i].data.ptr;
int revents = ev->epoll_events[i].events;
fdnode * const fdn = (fdnode *)epoll_events[i].data.ptr;
int revents = epoll_events[i].events;
if ((fdevent_handler)NULL != fdn->handler) {
(*fdn->handler)(fdn->ctx, revents);
}

24
src/fdevent_poll.c

@ -77,22 +77,16 @@ static int fdevent_poll_event_set(fdevents *ev, fdnode *fdn, int events) {
return 0;
}
__attribute_pure__
static int fdevent_poll_next_ndx(const fdevents *ev, int ndx) {
for (uint32_t i = (uint32_t)(ndx+1); i < ev->used; ++i) {
if (ev->pollfds[i].revents) return i;
}
return -1;
}
static int fdevent_poll_poll(fdevents *ev, int timeout_ms) {
const int n = poll(ev->pollfds, ev->used, timeout_ms);
for (int ndx=-1,i=0; i<n && -1!=(ndx=fdevent_poll_next_ndx(ev,ndx)); ++i){
fdnode *fdn = ev->fdarray[ev->pollfds[ndx].fd];
int revents = ev->pollfds[ndx].revents;
if (0 == ((uintptr_t)fdn & 0x3)) {
(*fdn->handler)(fdn->ctx, revents);
}
struct pollfd * const restrict pfds = ev->pollfds;
fdnode ** const fdarray = ev->fdarray;
const int n = poll(pfds, ev->used, timeout_ms);
for (int i = 0, m = 0; m < n; ++i) {
if (0 == pfds[i].revents) continue;
fdnode *fdn = fdarray[pfds[i].fd];
if (0 == ((uintptr_t)fdn & 0x3))
(*fdn->handler)(fdn->ctx, pfds[i].revents);
++m;
}
return n;
}

11
src/fdevent_solaris_devpoll.c

@ -42,18 +42,19 @@ static int fdevent_solaris_devpoll_event_set(fdevents *ev, fdnode *fdn, int even
}
static int fdevent_solaris_devpoll_poll(fdevents *ev, int timeout_ms) {
int n;
fdnode ** const fdarray = ev->fdarray;
struct pollfd * const devpollfds = ev->devpollfds;
struct dvpoll dopoll;
dopoll.dp_timeout = timeout_ms;
dopoll.dp_nfds = ev->maxfds - 1;
dopoll.dp_fds = ev->devpollfds;
dopoll.dp_fds = devpollfds;
n = ioctl(ev->devpoll_fd, DP_POLL, &dopoll);
const int n = ioctl(ev->devpoll_fd, DP_POLL, &dopoll);
for (int i = 0; i < n; ++i) {
fdnode * const fdn = ev->fdarray[ev->devpollfds[i].fd];
int revents = ev->devpollfds[i].revents;
fdnode * const fdn = fdarray[devpollfds[i].fd];
int revents = devpollfds[i].revents;
if (0 == ((uintptr_t)fdn & 0x3)) {
(*fdn->handler)(fdn->ctx, revents);
}

Loading…
Cancel
Save