From 4303daad1fb1dfc2689440cb0767c9beb45dbdd5 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Thu, 13 Aug 2015 14:39:58 +0530 Subject: [PATCH 12/26] 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]. Label: DOWNSTREAM ONLY BUG: 1319710 Change-Id: I6c91803ff12546d9a94369ad74b46506c016c426 Signed-off-by: Krishnan Parthasarathi Signed-off-by: Gaurav Kumar Garg Reviewed-on: https://code.engineering.redhat.com/gerrit/59409 Reviewed-by: Dan Lambright Tested-by: Dan Lambright (cherry picked from commit da5f555adf66e1e1000cd8af9a45d537514ccc42) Reviewed-on: https://code.engineering.redhat.com/gerrit/70340 Reviewed-by: Shyam Ranganathan Tested-by: Atin Mukherjee --- 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