From: YAMAMOTO Takashi Date: Wed, 2 Oct 2013 17:49:30 +0000 (-0700) Subject: ofproto-dpif-upcall: reduce number of wakeup X-Git-Tag: sliver-openvswitch-2.0.90-1~11^2~11 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=9b32ece62481706b0a340f7a100fe79ad9caad9e;p=sliver-openvswitch.git ofproto-dpif-upcall: reduce number of wakeup If a queue length is long (ie. non-0), the consumer thread should already be busy working on the queue. there's no need to wake it up repeatedly. Signed-off-by: YAMAMOTO Takashi Signed-off-by: Ben Pfaff --- diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c index 571d31214..07c302fd5 100644 --- a/ofproto/ofproto-dpif-upcall.c +++ b/ofproto/ofproto-dpif-upcall.c @@ -59,6 +59,7 @@ struct handler { size_t n_upcalls OVS_GUARDED; size_t n_new_upcalls; /* Only changed by the dispatcher. */ + bool need_signal; /* Only changed by the dispatcher. */ pthread_cond_t wake_cond; /* Wakes 'thread' while holding 'mutex'. */ @@ -222,6 +223,7 @@ udpif_recv_set(struct udpif *udpif, size_t n_handlers, bool enable) handler->udpif = udpif; list_init(&handler->upcalls); + handler->need_signal = false; xpthread_cond_init(&handler->wake_cond, NULL); ovs_mutex_init(&handler->mutex); xpthread_create(&handler->thread, NULL, udpif_upcall_handler, @@ -530,9 +532,13 @@ recv_upcalls(struct udpif *udpif) ovs_mutex_lock(&handler->mutex); if (handler->n_upcalls < MAX_QUEUE_LENGTH) { list_push_back(&handler->upcalls, &upcall->list_node); - handler->n_new_upcalls = ++handler->n_upcalls; - - if (handler->n_new_upcalls >= FLOW_MISS_MAX_BATCH) { + if (handler->n_upcalls == 0) { + handler->need_signal = true; + } + handler->n_upcalls++; + if (handler->need_signal && + handler->n_upcalls >= FLOW_MISS_MAX_BATCH) { + handler->need_signal = false; xpthread_cond_signal(&handler->wake_cond); } ovs_mutex_unlock(&handler->mutex); @@ -555,8 +561,8 @@ recv_upcalls(struct udpif *udpif) for (n = 0; n < udpif->n_handlers; ++n) { struct handler *handler = &udpif->handlers[n]; - if (handler->n_new_upcalls) { - handler->n_new_upcalls = 0; + if (handler->need_signal) { + handler->need_signal = false; ovs_mutex_lock(&handler->mutex); xpthread_cond_signal(&handler->wake_cond); ovs_mutex_unlock(&handler->mutex);