[ovs-dev] [PATCH] ofproto-dpif-upcall: reduce number of wakeup
Ben Pfaff
blp at nicira.com
Wed Oct 2 18:09:57 UTC 2013
On Wed, Sep 25, 2013 at 08:55:21AM -0700, Ben Pfaff wrote:
> On Wed, Sep 25, 2013 at 01:38:58PM +0900, YAMAMOTO Takashi wrote:
> > 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 <yamt at mwd.biglobe.ne.jp>
>
> Looks good, I'll apply this after Ethan's other changes to this file get
> in (presumably today).
I rebased this against current master and applied it as follows:
--8<--------------------------cut here-------------------------->8--
From: YAMAMOTO Takashi <yamt at mwd.biglobe.ne.jp>
Date: Wed, 2 Oct 2013 10:49:30 -0700
Subject: [PATCH] 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 <yamt at mwd.biglobe.ne.jp>
Signed-off-by: Ben Pfaff <blp at nicira.com>
---
ofproto/ofproto-dpif-upcall.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c
index 571d312..07c302f 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);
--
1.7.10.4
More information about the dev
mailing list