12a457
From 4303daad1fb1dfc2689440cb0767c9beb45dbdd5 Mon Sep 17 00:00:00 2001
12a457
From: Krishnan Parthasarathi <kparthas@redhat.com>
12a457
Date: Thu, 13 Aug 2015 14:39:58 +0530
12a457
Subject: [PATCH 12/26] event-epoll: Use pollers[] to check if event_pool_dispatch was called
12a457
12a457
        Backport of http://review.gluster.org/12004
12a457
12a457
This patch allows event_pool to change the no. of worker threads handling
12a457
events independent of event_dispatch() being called.
12a457
12a457
NB This patch is not a straight backport of the above patch. It
12a457
telescopes the following patches upstream,
12a457
12a457
	[1] http://review.gluster.com/11911
12a457
        [2] http://review.gluster.com/12004
12a457
12a457
[1] - uses an extra flag to change behaviour of reconfiguring the no. of
12a457
worker threads. This wasn't complete.
12a457
12a457
[2] - makes event_reconfigure_threads() implementation of epoll-based
12a457
eventing independent of when event_dispatch() is called , without the
12a457
extra flag introduced in [1].
12a457
12a457
Label: DOWNSTREAM ONLY
12a457
12a457
BUG: 1319710
12a457
Change-Id: I6c91803ff12546d9a94369ad74b46506c016c426
12a457
Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com>
12a457
Signed-off-by: Gaurav Kumar Garg <ggarg@redhat.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/59409
12a457
Reviewed-by: Dan Lambright <dlambrig@redhat.com>
12a457
Tested-by: Dan Lambright <dlambrig@redhat.com>
12a457
(cherry picked from commit da5f555adf66e1e1000cd8af9a45d537514ccc42)
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/70340
12a457
Reviewed-by: Shyam Ranganathan <srangana@redhat.com>
12a457
Tested-by: Atin Mukherjee <amukherj@redhat.com>
12a457
---
12a457
 libglusterfs/src/event-epoll.c |   24 +++++++++++++++++++++++-
12a457
 1 files changed, 23 insertions(+), 1 deletions(-)
12a457
12a457
diff --git a/libglusterfs/src/event-epoll.c b/libglusterfs/src/event-epoll.c
12a457
index 9403217..fc3099d 100644
12a457
--- a/libglusterfs/src/event-epoll.c
12a457
+++ b/libglusterfs/src/event-epoll.c
12a457
@@ -770,6 +770,23 @@ event_dispatch_epoll (struct event_pool *event_pool)
12a457
 	return ret;
12a457
 }
12a457
 
12a457
+/**
12a457
+ * @param event_pool  event_pool on which fds of interest are registered for
12a457
+ *                     events.
12a457
+ *
12a457
+ * @return  1 if at least one epoll worker thread is spawned, 0 otherwise
12a457
+ *
12a457
+ * NB This function SHOULD be called under event_pool->mutex.
12a457
+ */
12a457
+
12a457
+static int
12a457
+event_pool_dispatched_unlocked (struct event_pool *event_pool)
12a457
+{
12a457
+        return (event_pool->pollers[0] != 0);
12a457
+
12a457
+}
12a457
+
12a457
+
12a457
 int
12a457
 event_reconfigure_threads_epoll (struct event_pool *event_pool, int value)
12a457
 {
12a457
@@ -796,7 +813,12 @@ event_reconfigure_threads_epoll (struct event_pool *event_pool, int value)
12a457
 
12a457
                 oldthreadcount = event_pool->eventthreadcount;
12a457
 
12a457
-                if (oldthreadcount < value) {
12a457
+                /* Start 'worker' threads as necessary only if event_dispatch()
12a457
+                 * was called before. If event_dispatch() was not called, there
12a457
+                 * will be no epoll 'worker' threads running yet. */
12a457
+
12a457
+                if (event_pool_dispatched_unlocked(event_pool)
12a457
+                    && (oldthreadcount < value)) {
12a457
                         /* create more poll threads */
12a457
                         for (i = oldthreadcount; i < value; i++) {
12a457
                                 /* Start a thread if the index at this location
12a457
-- 
12a457
1.7.1
12a457