Blob Blame History Raw
From f338f8513ec9ffbe26ba9fe4de000331dc2c2789 Mon Sep 17 00:00:00 2001
From: Krishnan Parthasarathi <kparthas@redhat.com>
Date: Thu, 13 Aug 2015 14:39:58 +0530
Subject: [PATCH 314/320] event-epoll: Use pollers[] to check if event_pool_dispatch was called

        Backport of http://review.gluster.org/12004

This patch allows event_pool to change the no. of worker threads handling
events independent of event_dispatch() being called.

NB This patch is not a straight backport of the above patch. It
telescopes the following patches upstream,

	[1] http://review.gluster.com/11911
        [2] http://review.gluster.com/12004

[1] - uses an extra flag to change behaviour of reconfiguring the no. of
worker threads. This wasn't complete.

[2] - makes event_reconfigure_threads() implementation of epoll-based
eventing independent of when event_dispatch() is called , without the
extra flag introduced in [1].

BUG: 1241336
Change-Id: Ia8df3c958545324472262c555ed84b71797f002e
Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/56626
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Atin Mukherjee <amukherj@redhat.com>
---
 libglusterfs/src/event-epoll.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/libglusterfs/src/event-epoll.c b/libglusterfs/src/event-epoll.c
index 9403217..fc3099d 100644
--- a/libglusterfs/src/event-epoll.c
+++ b/libglusterfs/src/event-epoll.c
@@ -770,6 +770,23 @@ event_dispatch_epoll (struct event_pool *event_pool)
 	return ret;
 }
 
+/**
+ * @param event_pool  event_pool on which fds of interest are registered for
+ *                     events.
+ *
+ * @return  1 if at least one epoll worker thread is spawned, 0 otherwise
+ *
+ * NB This function SHOULD be called under event_pool->mutex.
+ */
+
+static int
+event_pool_dispatched_unlocked (struct event_pool *event_pool)
+{
+        return (event_pool->pollers[0] != 0);
+
+}
+
+
 int
 event_reconfigure_threads_epoll (struct event_pool *event_pool, int value)
 {
@@ -796,7 +813,12 @@ event_reconfigure_threads_epoll (struct event_pool *event_pool, int value)
 
                 oldthreadcount = event_pool->eventthreadcount;
 
-                if (oldthreadcount < value) {
+                /* Start 'worker' threads as necessary only if event_dispatch()
+                 * was called before. If event_dispatch() was not called, there
+                 * will be no epoll 'worker' threads running yet. */
+
+                if (event_pool_dispatched_unlocked(event_pool)
+                    && (oldthreadcount < value)) {
                         /* create more poll threads */
                         for (i = oldthreadcount; i < value; i++) {
                                 /* Start a thread if the index at this location
-- 
1.7.1