[sheepdog] [PATCH] work: improve namings and comments

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Thu Dec 19 03:46:14 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 |   52 ++++++++++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/lib/work.c b/lib/work.c
index 50b57a5..2eeafe2 100644
--- a/lib/work.c
+++ b/lib/work.c
@@ -40,25 +40,25 @@
  */
 #define WQ_PROTECTION_PERIOD 1000 /* ms */
 
-struct worker_info {
+struct wq_info {
 	const char *name;
 
 	struct list_head finished_list;
-	struct list_node worker_info_siblings;
+	struct list_node wq_info_siblings;
 
 	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 work producer 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;
@@ -66,7 +66,7 @@ struct worker_info {
 };
 
 static int efd;
-static LIST_HEAD(worker_info_list);
+static LIST_HEAD(wq_info_list);
 static size_t nr_nodes = 1;
 static size_t (*wq_get_nr_nodes)(void);
 
@@ -85,10 +85,10 @@ static int ack_efd;
 
 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) {
+	list_for_each_entry(wi, &wq_info_list, wq_info_siblings) {
 		pthread_mutex_lock(&wi->pending_lock);
 	}
 
@@ -109,7 +109,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) {
@@ -120,7 +120,7 @@ void resume_worker_threads(void)
 	for (int i = 0; i < nr_threads; i++)
 		eventfd_xread(ack_efd);
 
-	list_for_each_entry(wi, &worker_info_list, worker_info_siblings) {
+	list_for_each_entry(wi, &wq_info_list, wq_info_siblings) {
 		pthread_mutex_unlock(&wi->pending_lock);
 	}
 }
@@ -195,7 +195,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;
 
@@ -215,9 +215,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;
@@ -231,9 +231,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();
 
@@ -242,7 +242,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;
@@ -265,9 +265,9 @@ static int create_worker_threads(struct worker_info *wi, size_t nr_threads)
 
 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);
 	pthread_mutex_lock(&wi->pending_lock);
 
 	if (wq_need_grow(wi))
@@ -282,7 +282,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);
 
@@ -291,7 +291,7 @@ static void worker_thread_request_done(int fd, int events, void *data)
 
 	eventfd_xread(fd);
 
-	list_for_each_entry(wi, &worker_info_list, worker_info_siblings) {
+	list_for_each_entry(wi, &wq_info_list, wq_info_siblings) {
 		pthread_mutex_lock(&wi->finished_lock);
 		list_splice_init(&wi->finished_list, &list);
 		pthread_mutex_unlock(&wi->finished_lock);
@@ -301,14 +301,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();
 
@@ -401,7 +401,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;
@@ -420,7 +420,7 @@ struct work_queue *create_work_queue(const char *name,
 	if (ret < 0)
 		goto destroy_threads;
 
-	list_add(&wi->worker_info_siblings, &worker_info_list);
+	list_add(&wi->wq_info_siblings, &wq_info_list);
 
 	return &wi->q;
 destroy_threads:
@@ -440,7 +440,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.7.10.4




More information about the sheepdog mailing list