From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp53.i.mail.ru (smtp53.i.mail.ru [94.100.177.113]) (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 DD40A440F3C for ; Mon, 18 Nov 2019 19:05:33 +0300 (MSK) From: Serge Petrenko Date: Mon, 18 Nov 2019 19:05:04 +0300 Message-Id: <802b779b0e38614c502b513f6e8204c2aee98094.1574091776.git.sergepetrenko@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v3 2/3] fiber.top(): alter exponential moving average calculation List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org When fiber EMA is 0 and first non-zero observation is added to it, we assumed that EMA should be equal to this observation (i.e. average value should be the same as the observed one). This breaks the following invariant: sum of clock EMAs of all fibers equals clock EMA of the thread. If one of the fibers is just spawned and has a big clock delta, it will assign this delta to its EMA, while the thread will calculate the new EMA as 15 * EMA / 16 + delta / 16, which may lead to a situation when fiber EMA is greater than cord EMA. This caused occasional test failures: ``` [001] Test failed! Result content mismatch: [001] --- app/fiber.result Mon Nov 18 17:00:48 2019 [001] +++ app/fiber.reject Mon Nov 18 17:33:10 2019 [001] @@ -1511,7 +1511,7 @@ [001] -- not exact due to accumulated integer division errors [001] sum_avg > 99 and sum_avg < 101 or sum_avg [001] --- [001] -- true [001] +- 187.59585601717 [001] ... [001] tbl = nil [001] --- ``` Follow-up #2694 --- src/lib/core/fiber.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/lib/core/fiber.c b/src/lib/core/fiber.c index 1e08d0ec9..232c29911 100644 --- a/src/lib/core/fiber.c +++ b/src/lib/core/fiber.c @@ -1098,11 +1098,7 @@ loop_on_iteration_start(ev_loop *loop, ev_check *watcher, int revents) static inline uint64_t clock_diff_accumulate(uint64_t acc, uint64_t delta) { - if (acc > 0) { - return delta / 16 + 15 * acc / 16; - } else { - return delta; - } + return delta / 16 + 15 * acc / 16; } inline void -- 2.21.0 (Apple Git-122)