[sheepdog] [PATCH v2 4/4] work: improve namings and fix obsolete comments

Hitoshi Mitake mitake.hitoshi at gmail.com
Tue Dec 17 15:42:56 CET 2013


This patch removes confusing names in work.c:
1. before: wi->nr_workers, after: wi->nr_queued_work
2. before: struct worker_info, after: struct wq_info

Also fixes obsolete comments.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 lib/work.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/lib/work.c b/lib/work.c
index f261e2d..33db83f 100644
--- a/lib/work.c
+++ b/lib/work.c
@@ -53,7 +53,7 @@ static int ack_efd;
  */
 #define WQ_PROTECTION_PERIOD 1000 /* ms */
 
-struct worker_info {
+struct wq_info {
 	const char *name;
 
 	struct list_head finished_list;
@@ -62,16 +62,16 @@ struct worker_info {
 	pthread_mutex_t finished_lock;
 	pthread_mutex_t startup_lock;
 
-	/* wokers sleep on this and signaled by tgtd */
+	/* wokers sleep on this and signaled by work producer */
 	pthread_cond_t pending_cond;
-	/* locked by tgtd and workers */
+	/* locked by main thread and workers */
 	pthread_mutex_t pending_lock;
 	/* protected by pending_lock */
 	struct work_queue q;
 	size_t nr_threads;
 
 	/* protected by uatomic primitives */
-	size_t nr_workers;
+	size_t nr_queued_work;
 
 	/* we cannot shrink work queue till this time */
 	uint64_t tm_end_of_protection;
@@ -93,7 +93,7 @@ static uint64_t get_msec_time(void)
 	return tv.tv_sec * 1000 + tv.tv_usec / 1000;
 }
 
-static inline uint64_t wq_get_roof(struct worker_info *wi)
+static inline uint64_t wq_get_roof(struct wq_info *wi)
 {
 	uint64_t nr = 1;
 
@@ -113,9 +113,9 @@ static inline uint64_t wq_get_roof(struct worker_info *wi)
 	return nr;
 }
 
-static bool wq_need_grow(struct worker_info *wi)
+static bool wq_need_grow(struct wq_info *wi)
 {
-	if (wi->nr_threads < uatomic_read(&wi->nr_workers) &&
+	if (wi->nr_threads < uatomic_read(&wi->nr_queued_work) &&
 	    wi->nr_threads * 2 <= wq_get_roof(wi)) {
 		wi->tm_end_of_protection = get_msec_time() +
 			WQ_PROTECTION_PERIOD;
@@ -129,9 +129,9 @@ static bool wq_need_grow(struct worker_info *wi)
  * Return true if more than half of threads are not used more than
  * WQ_PROTECTION_PERIOD seconds
  */
-static bool wq_need_shrink(struct worker_info *wi)
+static bool wq_need_shrink(struct wq_info *wi)
 {
-	if (uatomic_read(&wi->nr_workers) < wi->nr_threads / 2)
+	if (uatomic_read(&wi->nr_queued_work) < wi->nr_threads / 2)
 		/* we cannot shrink work queue during protection period. */
 		return wi->tm_end_of_protection <= get_msec_time();
 
@@ -140,7 +140,7 @@ static bool wq_need_shrink(struct worker_info *wi)
 	return false;
 }
 
-static int create_worker_threads(struct worker_info *wi, size_t nr_threads)
+static int create_worker_threads(struct wq_info *wi, size_t nr_threads)
 {
 	pthread_t thread;
 	int ret;
@@ -165,7 +165,7 @@ static int create_worker_threads(struct worker_info *wi, size_t nr_threads)
 
 void suspend_worker_threads(void)
 {
-	struct worker_info *wi;
+	struct wq_info *wi;
 	int tid;
 
 	list_for_each_entry(wi, &worker_info_list, worker_info_siblings) {
@@ -189,7 +189,7 @@ void suspend_worker_threads(void)
 
 void resume_worker_threads(void)
 {
-	struct worker_info *wi;
+	struct wq_info *wi;
 	int nr_threads = 0, tid;
 
 	FOR_EACH_BIT(tid, tid_map, tid_max) {
@@ -219,9 +219,9 @@ static void suspend(int num)
 
 void queue_work(struct work_queue *q, struct work *work)
 {
-	struct worker_info *wi = container_of(q, struct worker_info, q);
+	struct wq_info *wi = container_of(q, struct wq_info, q);
 
-	uatomic_inc(&wi->nr_workers);
+	uatomic_inc(&wi->nr_queued_work);
 
 	if (wq_need_grow(wi))
 		/* double the thread pool size */
@@ -236,7 +236,7 @@ void queue_work(struct work_queue *q, struct work *work)
 
 static void worker_thread_request_done(int fd, int events, void *data)
 {
-	struct worker_info *wi;
+	struct wq_info *wi;
 	struct work *work;
 	LIST_HEAD(list);
 
@@ -255,14 +255,14 @@ static void worker_thread_request_done(int fd, int events, void *data)
 			list_del(&work->w_list);
 
 			work->done(work);
-			uatomic_dec(&wi->nr_workers);
+			uatomic_dec(&wi->nr_queued_work);
 		}
 	}
 }
 
 static void *worker_routine(void *arg)
 {
-	struct worker_info *wi = arg;
+	struct wq_info *wi = arg;
 	struct work *work;
 	int tid = gettid();
 
@@ -396,7 +396,7 @@ struct work_queue *create_work_queue(const char *name,
 				     enum wq_thread_control tc)
 {
 	int ret;
-	struct worker_info *wi;
+	struct wq_info *wi;
 
 	wi = xzalloc(sizeof(*wi));
 	wi->name = name;
@@ -435,7 +435,7 @@ struct work_queue *create_ordered_work_queue(const char *name)
 
 bool work_queue_empty(struct work_queue *q)
 {
-	struct worker_info *wi = container_of(q, struct worker_info, q);
+	struct wq_info *wi = container_of(q, struct wq_info, q);
 
-	return uatomic_read(&wi->nr_workers) == 0;
+	return uatomic_read(&wi->nr_queued_work) == 0;
 }
-- 
1.8.1.2




More information about the sheepdog mailing list