kqueue: Use wakeup_one based on # of threads sleep on kqueue
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Wed, 2 Mar 2016 14:39:29 +0000 (22:39 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Wed, 2 Mar 2016 14:42:05 +0000 (22:42 +0800)
Get rid of the sysctl to set wakeup_one optimization.  This also
unbreaks the case when wakeup_one optimization is enabled, and
multiple threads share and sleep on one kqueue.

sys/kern/kern_event.c
sys/sys/eventvar.h

index 58d3624..3b9d4ae 100644 (file)
@@ -135,9 +135,6 @@ SYSCTL_INT(_kern, OID_AUTO, kq_calloutmax, CTLFLAG_RW,
 static int             kq_checkloop = 1000000;
 SYSCTL_INT(_kern, OID_AUTO, kq_checkloop, CTLFLAG_RW,
     &kq_checkloop, 0, "Maximum number of loops for kqueue scan");
-static int             kq_wakeup_one = 1;
-SYSCTL_INT(_kern, OID_AUTO, kq_wakeup_one, CTLFLAG_RW,
-    &kq_wakeup_one, 0, "Wakeup only one kqueue scanner");
 
 #define KNOTE_ACTIVATE(kn) do {                                        \
        kn->kn_status |= KN_ACTIVE;                                     \
@@ -831,7 +828,7 @@ kern_kevent(struct kqueue *kq, int nevents, int *res, void *uap,
 
                        lwkt_gettoken(tok);
                        if (kq->kq_count == 0) {
-                               kq->kq_state |= KQ_SLEEP;
+                               kq->kq_sleep_cnt++;
                                error = tsleep(kq, PCATCH, "kqread", timeout);
 
                                /* don't restart after signals... */
@@ -1371,12 +1368,12 @@ kqueue_close(struct file *fp)
 static void
 kqueue_wakeup(struct kqueue *kq)
 {
-       if (kq->kq_state & KQ_SLEEP) {
-               kq->kq_state &= ~KQ_SLEEP;
-               if (kq_wakeup_one)
+       if (kq->kq_sleep_cnt) {
+               if (kq->kq_sleep_cnt == 1)
                        wakeup_one(kq);
                else
                        wakeup(kq);
+               kq->kq_sleep_cnt = 0;
        }
        KNOTE(&kq->kq_kqinfo.ki_note, 0);
 }
index 50e7e9b..8d755cb 100644 (file)
@@ -63,11 +63,11 @@ struct kqueue {
        struct          kqinfo kq_kqinfo;       
        struct          filedesc *kq_fdp;
        int             kq_state;
+       u_int           kq_sleep_cnt;
        u_long          kq_knhashmask;          /* size of knhash */
        struct          klist *kq_knhash;       /* hash table for knotes */
 };
 
-#define KQ_SLEEP       0x02
 #define KQ_ASYNC       0x04
 
 #endif /* _KERNEL */