<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">hi hitoshi,</div>I’m so sorry that this patch introduce a bug in the dog command.<div class="">recently I read the source code of dog , it seems that <br class=""><div class="">dog uses `init_work_queue` as well as sheep! </div><div class="">so extract `wq_trace_init` from `init_work_queue` causes </div><div class="">dog’s new thread enter into loop, because `tid_max` is not initialized.</div><div class=""><br class=""></div><div class="">all in all, the main problem is the code below will enter into loop when `tid_max` is 0.</div><div class="">---</div><div class=""><p style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><span class="Apple-tab-span" style="white-space:pre"> </span>/* enlarge bitmap size */</p>
<p style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> while (tid > tid_max)</p>
<p style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> tid_max *= 2;</p><div class="">—</div></div><div class="">and we need to init `tid_max` before journal init.</div><div class="">and we need to make sure both sheep and dog will not enter into loop.</div><div class=""><br class=""></div><div class=""><div class="">maybe the solution is:</div><div class="">1. revert the patch & assign tid_max to 1 in its declaration </div><div class="">or</div><div class="">2. call `wq_trace_init` in the dog’s main() function before `init_work_queue`</div><div class="">or</div><div class="">3. make sure `tid_max` is not 0 in `trace_set_tid_map`</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">what do you think</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Thanks</div><div class="">Jinzhi Chen</div><div class=""><br class=""></div><div class=""><div class=""><div><blockquote type="cite" class=""><div class="">On Nov 13, 2014, at 10:07 AM, Hitoshi Mitake <<a href="mailto:mitake.hitoshi@lab.ntt.co.jp" class="">mitake.hitoshi@lab.ntt.co.jp</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">At Wed, 12 Nov 2014 14:21:22 +0800,</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Jinzhi Chen wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="">when journal thread init before the initialization of trace,<br class="">it enter into loop (using uninitailized `tid_max`)with<br class="">--debug-enable configured. we need to initialize trace before<br class="">journal thread init.<br class="">this patch extrace `wq_trace_init` from `init_work_queue` and<br class="">call it in the main() function just before the initialization<br class="">of journal file.<br class=""><br class="">Signed-off-by: Jinzhi Chen <<a href="mailto:nxtjinzhi@gmail.com" class="">nxtjinzhi@gmail.com</a>><br class="">---<br class="">include/work.h | 1 +<br class="">lib/work.c | 8 ++------<br class="">sheep/sheep.c | 7 +++++++<br class="">3 files changed, 10 insertions(+), 6 deletions(-)<br class=""><br class="">diff --git a/include/work.h b/include/work.h<br class="">index b2fa0cf..c2008ba 100644<br class="">--- a/include/work.h<br class="">+++ b/include/work.h<br class="">@@ -63,6 +63,7 @@ struct work_queue *create_work_queue(const char *name, enum wq_thread_control);<br class="">struct work_queue *create_ordered_work_queue(const char *name);<br class="">void queue_work(struct work_queue *q, struct work *work);<br class="">bool work_queue_empty(struct work_queue *q);<br class="">+int wq_trace_init(void);<br class=""><br class="">#ifdef HAVE_TRACE<br class="">void suspend_worker_threads(void);<br class="">diff --git a/lib/work.c b/lib/work.c<br class="">index 7e2cd79..95953e4 100644<br class="">--- a/lib/work.c<br class="">+++ b/lib/work.c<br class="">@@ -134,7 +134,7 @@ static void suspend(int num)<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>eventfd_xwrite(ack_efd, 1); /* ack of resume */<br class="">}<br class=""><br class="">-static int wq_trace_init(void)<br class="">+int wq_trace_init(void)<br class="">{<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>tid_max = TID_MAX_DEFAULT;<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>tid_map = alloc_bitmap(NULL, 0, tid_max);<br class="">@@ -180,7 +180,7 @@ static void trace_clear_tid_map(int tid)<br class=""><br class="">#else<br class=""><br class="">-static inline int wq_trace_init(void) { return 0; }<br class="">+inline int wq_trace_init(void) { return 0; }<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Applied, thanks. But I removed the above inline because it is not</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">required.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Thanks,</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Hitoshi</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">static inline void trace_set_tid_map(int tid) {}<br class="">static inline void trace_clear_tid_map(int tid) {}<br class=""><br class="">@@ -364,10 +364,6 @@ int init_work_queue(size_t (*get_nr_nodes)(void))<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>return -1;<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>}<br class=""><br class="">-<span class="Apple-tab-span" style="white-space: pre;"> </span>ret = wq_trace_init();<br class="">-<span class="Apple-tab-span" style="white-space: pre;"> </span>if (ret < 0)<br class="">-<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>return ret;<br class="">-<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>ret = register_event(efd, worker_thread_request_done, NULL);<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>if (ret) {<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>sd_err("failed to register event fd %m");<br class="">diff --git a/sheep/sheep.c b/sheep/sheep.c<br class="">index 2e91d0f..ef45a33 100644<br class="">--- a/sheep/sheep.c<br class="">+++ b/sheep/sheep.c<br class="">@@ -885,6 +885,13 @@ int main(int argc, char **argv)<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>goto cleanup_log;<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>}<br class=""><br class="">+<span class="Apple-tab-span" style="white-space: pre;"> </span>/* We should init trace for work queue before journal init */<br class="">+<span class="Apple-tab-span" style="white-space: pre;"> </span>ret = wq_trace_init();<br class="">+<span class="Apple-tab-span" style="white-space: pre;"> </span>if (ret) {<br class="">+<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>sd_err("failed to init trace for work queue");<br class="">+<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>goto cleanup_log;<br class="">+<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br class="">+<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>/* We should init journal file before backend init */<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>if (uatomic_is_true(&sys->use_journal)) {<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>if (!strlen(jpath))<br class="">--<span class="Apple-converted-space"> </span><br class="">1.9.3 (Apple Git-50)<br class=""><br class="">--<span class="Apple-converted-space"> </span><br class="">sheepdog mailing list<br class=""><a href="mailto:sheepdog@lists.wpkg.org" class="">sheepdog@lists.wpkg.org</a><br class=""><a href="http://lists.wpkg.org/mailman/listinfo/sheepdog" class="">http://lists.wpkg.org/mailman/listinfo/sheepdog</a></blockquote></div></blockquote></div><br class=""></div></div></div></body></html>