summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBin Qian <bin.qian@windriver.com>2018-10-12 08:34:36 -0400
committerBin Qian <bin.qian@windriver.com>2018-10-16 10:29:52 -0400
commita63f6ea6caca9a2ab5bab2f44f7bd1caba816315 (patch)
tree3c518fa90b1d4fb4d5856b8d0687264183bdd4d6
parent3afa59ea77ab7a120519382af65832add285e25e (diff)
Add idle time to worker thread2018.10.0r/2018.10
Adding 50ms idle time in worker thread loop. This is to fix sm taking 100% cpu for a busy loop. Closes-Bug 1797438 Change-Id: Ia41acfab86c0188ceb5c80822010376977c6fc74 Signed-off-by: Bin Qian <bin.qian@windriver.com>
Notes
Notes (review): Code-Review+2: Al Bailey <al.bailey@windriver.com> Workflow+1: Dariush Eslimi <Dariush.Eslimi@windriver.com> Code-Review+2: Dariush Eslimi <Dariush.Eslimi@windriver.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 16 Oct 2018 18:40:42 +0000 Reviewed-on: https://review.openstack.org/610998 Project: openstack/stx-ha Branch: refs/heads/r/2018.10
-rw-r--r--service-mgmt/sm-1.0.0/src/sm_worker_thread.cpp20
-rw-r--r--service-mgmt/sm-1.0.0/src/sm_worker_thread.h1
2 files changed, 17 insertions, 4 deletions
diff --git a/service-mgmt/sm-1.0.0/src/sm_worker_thread.cpp b/service-mgmt/sm-1.0.0/src/sm_worker_thread.cpp
index 8d5daeb..9382154 100644
--- a/service-mgmt/sm-1.0.0/src/sm_worker_thread.cpp
+++ b/service-mgmt/sm-1.0.0/src/sm_worker_thread.cpp
@@ -8,6 +8,7 @@
8#include <stdio.h> 8#include <stdio.h>
9#include <errno.h> 9#include <errno.h>
10#include <unistd.h> 10#include <unistd.h>
11#include <time.h>
11#include "sm_util_types.h" 12#include "sm_util_types.h"
12#include "sm_debug.h" 13#include "sm_debug.h"
13 14
@@ -84,7 +85,7 @@ SmErrorT SmWorkerThread::go()
84 } 85 }
85 86
86 this->_thread_created = true; 87 this->_thread_created = true;
87 if( 0 != sem_init(&this->_sem, 0, MAX_QUEUED_ACTIONS) ) 88 if( 0 != sem_init(&this->_sem, 0, 0) )
88 { 89 {
89 DPRINTFE("Cannot init semaphore"); 90 DPRINTFE("Cannot init semaphore");
90 return SM_FAILED; 91 return SM_FAILED;
@@ -147,9 +148,22 @@ void SmWorkerThread::add_priority_action(SmAction& action)
147// **************************************************************************** 148// ****************************************************************************
148void SmWorkerThread::thread_run() 149void SmWorkerThread::thread_run()
149{ 150{
151 int wait_interval_ns = 50*1000000; //50 ms
152 int ns_to_sec = 1000000000;
153 struct timespec wait_time;
154
150 while(this->_goon) 155 while(this->_goon)
151 { 156 {
152 if(0 == sem_trywait(&this->_sem)) 157 clock_gettime(CLOCK_REALTIME, &wait_time);
158
159 wait_time.tv_nsec += wait_interval_ns;
160 if(wait_time.tv_nsec > ns_to_sec -1)
161 {
162 wait_time.tv_nsec -= ns_to_sec;
163 wait_time.tv_sec ++;
164 }
165
166 if(0 == sem_timedwait(&this->_sem, &wait_time))
153 { 167 {
154 SmAction* action = NULL; 168 SmAction* action = NULL;
155 if(!this->_priority_queue.empty()) 169 if(!this->_priority_queue.empty())
@@ -165,7 +179,7 @@ void SmWorkerThread::thread_run()
165 { 179 {
166 action->action(); 180 action->action();
167 } 181 }
168 }else if(EAGAIN != errno) 182 }else if(ETIMEDOUT != errno)
169 { 183 {
170 DPRINTFE("Semaphore wait failed. Error %d", errno); 184 DPRINTFE("Semaphore wait failed. Error %d", errno);
171 } 185 }
diff --git a/service-mgmt/sm-1.0.0/src/sm_worker_thread.h b/service-mgmt/sm-1.0.0/src/sm_worker_thread.h
index 49ed254..06028a6 100644
--- a/service-mgmt/sm-1.0.0/src/sm_worker_thread.h
+++ b/service-mgmt/sm-1.0.0/src/sm_worker_thread.h
@@ -11,7 +11,6 @@
11#include <pthread.h> 11#include <pthread.h>
12#include <semaphore.h> 12#include <semaphore.h>
13 13
14#define MAX_QUEUED_ACTIONS 24
15// **************************************************************************** 14// ****************************************************************************
16// SmAction interface, action to process in a worker thread 15// SmAction interface, action to process in a worker thread
17// **************************************************************************** 16// ****************************************************************************