diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-07-04 09:49:29 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-07-04 09:49:29 -0700 |
| commit | 77d35b527b509e41f4c9a24d5fd56de02d93a503 (patch) | |
| tree | 35ad528ba86acf739ac63cd60dc3d61257b65cd8 /src | |
| parent | d1a9c84a6b375cb25a8b7475957130e364b41753 (diff) | |
| download | nng-77d35b527b509e41f4c9a24d5fd56de02d93a503.tar.gz nng-77d35b527b509e41f4c9a24d5fd56de02d93a503.tar.bz2 nng-77d35b527b509e41f4c9a24d5fd56de02d93a503.zip | |
fixes #575 kqueue spins hard
This sets the kqueue events to autoclear, reducing CPU usage to normal
sane levels, and eliminating the hard spin.
Diffstat (limited to 'src')
| -rw-r--r-- | src/platform/posix/posix_pollq_kqueue.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/platform/posix/posix_pollq_kqueue.c b/src/platform/posix/posix_pollq_kqueue.c index c118d528..50874d14 100644 --- a/src/platform/posix/posix_pollq_kqueue.c +++ b/src/platform/posix/posix_pollq_kqueue.c @@ -58,7 +58,7 @@ nni_posix_pfd_init(nni_posix_pfd **pfdp, int fd) nni_posix_pfd * pf; nni_posix_pollq *pq; struct kevent ev[2]; - unsigned flags = EV_ADD | EV_DISABLE; + unsigned flags = EV_ADD | EV_DISABLE | EV_CLEAR; // Set this is as soon as possible (narrow the close-exec race as // much as we can; better options are system calls that suppress @@ -128,7 +128,8 @@ nni_posix_pfd_fini(nni_posix_pfd *pf) struct kevent ev; nni_mtx_lock(&pq->mtx); nni_list_append(&pq->reapq, pf); - EV_SET(&ev, 0, EVFILT_USER, EV_ENABLE, NOTE_TRIGGER, 0, NULL); + EV_SET(&ev, 0, EVFILT_USER, EV_ENABLE | EV_CLEAR, NOTE_TRIGGER, + 0, NULL); // If this fails, the cleanup will stall. That should // only occur in a memory pressure situation, and it @@ -167,7 +168,7 @@ nni_posix_pfd_arm(nni_posix_pfd *pf, int events) { struct kevent ev[2]; int nev = 0; - unsigned flags = EV_ENABLE | EV_DISPATCH; + unsigned flags = EV_ENABLE | EV_DISPATCH | EV_CLEAR; nni_posix_pollq *pq = pf->pq; nni_mtx_lock(&pf->mtx); @@ -291,7 +292,7 @@ nni_posix_pollq_add_wake_evt(nni_posix_pollq *pq) int rv; struct kevent ev; - EV_SET(&ev, 0, EVFILT_USER, EV_ADD, 0, 0, NULL); + EV_SET(&ev, 0, EVFILT_USER, EV_ADD | EV_CLEAR, 0, 0, NULL); while ((rv = kevent(pq->kq, &ev, 1, NULL, 0, NULL)) != 0) { if (errno == EINTR) { continue; |
