From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 4CF9E6EC41; Thu, 1 Jul 2021 18:56:42 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4CF9E6EC41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1625155002; bh=rjRBC6k1xWD11+sZvNZu/hSoayNdkQ9MuGl0tSW2lHk=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=K346h/GPN2+6qAsIGbpsKvtdS42SBesEYPkzwV+NLA5Y3+6gIL9x3CBa2fPkNDPR9 aV81+XLHLbgF7sE/K8UldxVMXe4hidm2i2gQqY1KRdUKMkkZN+4daKRdlGRwh6XjmB KrpNpFs5/2GN71YQ8jqsKZQKevbNDxD7+TBAL4VQ= Received: from smtp31.i.mail.ru (smtp31.i.mail.ru [94.100.177.91]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id C3CCA6EC41 for ; Thu, 1 Jul 2021 18:55:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C3CCA6EC41 Received: by smtp31.i.mail.ru with esmtpa (envelope-from ) id 1lyz24-0006YJ-R0; Thu, 01 Jul 2021 18:55:17 +0300 To: tarantool-patches@dev.tarantool.org Date: Thu, 1 Jul 2021 18:54:46 +0300 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD954DFF1DC42D673FB8EEAA58EF109ED2DCA3B880632F394B8182A05F538085040D302524A47952634ABE7F265EBBFD3A29940A79568F77F2B3A72F1F253978984 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE789066434B85BF7C7EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063786D6A7D810B9582D8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8CBF060CC0E7D8C04BDEDF224CCF488AC117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC5FC25ED3FCEC3375A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18BDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEC24E1E72F37C03A04D0DA9BD313A0613D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE365B78C30F681404D6136E347CC761E07C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F79006375C79DA22B1A023C3EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C97831C3A611387EFBEF399987FE5AEBDF0A48 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CA007D7800FCDDA27A7B911B6A0837021DE7EA230D15221AA9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFCCE3E035A672CDEE699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3483E1FCD56FEA62E6BF022D888EEF49501DCCD7C7AFDEE7FA4553A1A3708A94FE26441FF4F163E5091D7E09C32AA3244C1DC30F8FD2B5F83741938F1AABF0FBE3B038C9161EF167A183B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXgzbH4gLt0SRiw/vXLleB2D X-Mailru-Sender: EFA0F3A8419EF2166B053C73E674FFD5E7134DB305D9778B3D552647ED47DED5E2527C969975515C67F54F2D6EFFC80BC77752E0C033A69E17841C44D9B5D58765F2F89A5AFDB6F16C18EFA0BB12DBB0 X-Mras: Ok Subject: [Tarantool-patches] [PATCH 3/7] fiber: apply fix patch X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Egor Elchinov via Tarantool-patches Reply-To: eelchinov@tarantool.org Cc: gorcunov@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Egor Elchinov Some mistakes fixed. More consistent naming provided. Based on review and patch from Cyrill Gorcunov Needed for: #4002 --- src/lib/core/backtrace.cc | 47 +++++++++++++++++++++------------------ src/lib/core/backtrace.h | 8 ++++--- src/lib/core/fiber.c | 2 +- src/lib/core/fiber.h | 2 +- src/lua/fiber.c | 5 +++-- 5 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/lib/core/backtrace.cc b/src/lib/core/backtrace.cc index a1727374c..f97c4c0a9 100644 --- a/src/lib/core/backtrace.cc +++ b/src/lib/core/backtrace.cc @@ -443,8 +443,8 @@ out: * Must be by far faster than usual backtrace according to the * libunwind doc for unw_backtrace(). */ -void -fast_trace_collect(void **ip_buf, int limit) +void NOINLINE +backtrace_collect_ip(void **ip_buf, int limit) { memset(ip_buf, 0, limit * sizeof(*ip_buf)); #ifndef TARGET_OS_DARWIN @@ -466,54 +466,57 @@ fast_trace_collect(void **ip_buf, int limit) * TODO: to add cache and demangling support */ void -fast_trace_foreach(backtrace_cb cb, void **ip_buf, int limit, void *cb_ctx) +backtrace_foreach_ip(backtrace_cb cb, void **ip_buf, int limit, + void *cb_ctx) { #ifndef TARGET_OS_DARWIN - static __thread char proc_name[BACKTRACE_NAME_MAX]; - char* proc = NULL; - int frame_no = 0, ret = 0; + char proc_name[BACKTRACE_NAME_MAX]; unw_word_t ip = 0, offset = 0; unw_proc_info_t pi; - - unw_accessors_t* acc = unw_get_accessors(unw_local_addr_space); - assert(acc); - - for (frame_no = 0; frame_no < limit && ip_buf[frame_no] != NULL; - ++frame_no) { + int frame_no, ret = 0; + char *proc = NULL; + + unw_accessors_t *acc = unw_get_accessors(unw_local_addr_space); + + /* + * RIPs collecting comes from inside a helper routine + * so we skip the collector function address itself thus + * start fetching functions with frame number = 1. + */ + for (frame_no = 1; frame_no < limit && ip_buf[frame_no] != NULL; + frame_no++) { ip = (unw_word_t)ip_buf[frame_no]; + if (acc->get_proc_name == NULL) { ret = unw_get_proc_info_by_ip(unw_local_addr_space, ip, &pi, NULL); offset = ip - pi.start_ip; } else { ret = acc->get_proc_name(unw_local_addr_space, ip, - proc_name, sizeof(proc_name), - &offset, NULL); + proc_name, sizeof(proc_name), + &offset, NULL); proc = proc_name; } - - if (ret != 0 || (frame_no > 0 && - cb(frame_no - 1, (void *)ip, proc, - (size_t)offset, cb_ctx) != 0)) + if (ret != 0 || cb(frame_no - 1, (void *)ip, proc, + (size_t)offset, cb_ctx) != 0) break; } if (ret != 0) say_debug("unwinding error: %s", unw_strerror(ret)); #else - int frame_no = 0, ret = 1; + int frame_no, ret = 1; void *ip = NULL; size_t offset = 0; Dl_info dli; - for (frame_no = 0; frame_no < limit && ip_buf[frame_no] != NULL; + for (frame_no = 1; frame_no < limit && ip_buf[frame_no] != NULL; ++frame_no) { ip = ip_buf[frame_no]; ret = dladdr(ip, &dli); offset = (char *)ip - (char *)dli.dli_saddr; - if (frame_no > 0 && - cb(frame_no - 1, ip, dli.dli_sname, offset, cb_ctx) != 0) + if (cb(frame_no - 1, ip, dli.dli_sname, offset, cb_ctx) != 0) break; } diff --git a/src/lib/core/backtrace.h b/src/lib/core/backtrace.h index 8bb668366..4552c14e1 100644 --- a/src/lib/core/backtrace.h +++ b/src/lib/core/backtrace.h @@ -31,6 +31,7 @@ * SUCH DAMAGE. */ #include "trivia/config.h" +#include "trivia/util.h" #include #if defined(__cplusplus) @@ -55,11 +56,12 @@ backtrace_foreach(backtrace_cb cb, coro_context *coro_ctx, void *cb_ctx); void backtrace_proc_cache_clear(void); -void -fast_trace_collect(void **ip_buf, int limit); +void NOINLINE +backtrace_collect_ip(void **ip_buf, int limit); void -fast_trace_foreach(backtrace_cb cb, void **ip_buf, int limit, void *cb_ctx); +backtrace_foreach_ip(backtrace_cb cb, void **ip_buf, int limit, + void *cb_ctx); #endif /* ENABLE_BACKTRACE */ diff --git a/src/lib/core/fiber.c b/src/lib/core/fiber.c index 73500e043..924ff3c82 100644 --- a/src/lib/core/fiber.c +++ b/src/lib/core/fiber.c @@ -1265,7 +1265,7 @@ fiber_new_ex(const char *name, const struct fiber_attr *fiber_attr, fiber->fid = cord->next_fid; fiber_set_name(fiber, name); #if ENABLE_BACKTRACE - fast_trace_collect(fiber->parent_bt_ip_buf, FIBER_PARENT_BT_MAX); + backtrace_collect_ip(fiber->parent_bt_ip_buf, FIBER_PARENT_BT_MAX); #endif /* ENABLE_BACKTRACE */ register_fid(fiber); fiber->csw = 0; diff --git a/src/lib/core/fiber.h b/src/lib/core/fiber.h index 6a155c0fe..beed58866 100644 --- a/src/lib/core/fiber.h +++ b/src/lib/core/fiber.h @@ -654,7 +654,7 @@ struct fiber { char inline_name[FIBER_NAME_INLINE]; #if ENABLE_BACKTRACE /** Fiber creation backtrace chunk. */ - void* parent_bt_ip_buf[FIBER_PARENT_BT_MAX]; + void *parent_bt_ip_buf[FIBER_PARENT_BT_MAX]; #endif /* ENABLE_BACKTRACE */ }; diff --git a/src/lua/fiber.c b/src/lua/fiber.c index dc7051edd..7b21361d4 100644 --- a/src/lua/fiber.c +++ b/src/lua/fiber.c @@ -314,8 +314,9 @@ lbox_fiber_statof_map(struct fiber *f, void *cb_ctx, bool backtrace) tb_ctx.R = NULL; lua_pushstring(L, "backtrace_parent"); lua_newtable(L); - fast_trace_foreach(fiber_backtrace_cb, f->parent_bt_ip_buf, - FIBER_PARENT_BT_MAX, &tb_ctx); + backtrace_foreach_ip(fiber_backtrace_cb, + f->parent_bt_ip_buf, + FIBER_PARENT_BT_MAX, &tb_ctx); lua_settable(L, -3); #endif /* ENABLE_BACKTRACE */ } -- 2.31.1