[sheepdog] [PATCH v3 5/5] work: improve namings and fix obsolete comments
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Wed Dec 18 05:30:24 CET 2013
From: Hitoshi Mitake <mitake.hitoshi at gmail.com>
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 392ce8e..8ac3f90 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,9 +62,9 @@ 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;
@@ -74,7 +74,7 @@ struct worker_info {
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;
@@ -96,7 +96,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;
@@ -116,9 +116,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;
@@ -132,9 +132,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();
@@ -143,7 +143,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;
@@ -168,7 +168,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) {
@@ -192,7 +192,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) {
@@ -222,9 +222,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 */
@@ -239,7 +239,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);
@@ -258,14 +258,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();
@@ -399,7 +399,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;
@@ -438,7 +438,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