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 AB160169C804; Fri, 26 Dec 2025 11:05:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AB160169C804 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1766736332; bh=u/3eMiGoI02ou3IYfWG7soBlkrAq30q3X52nGk31ObY=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=H1onlRWCN5W/3YUZM/ZwTf7+wPaMtu3L2UKn8XOZXb9K1SbVzkbNSqNjWzsKDiRfD U3gdt4K53mlmoIBzi256Q8UfkmuhQwxpHbNCf+/iDnsMesoXzqC/3FBhBl9PBII6s6 GdeHQoeR0OSfVUwG5E0XNZDjb5ni6Wyv9grOeWcc= Received: from send150.i.mail.ru (send150.i.mail.ru [89.221.237.245]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4D3DE169C832 for ; Fri, 26 Dec 2025 11:05:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4D3DE169C832 Received: by exim-smtp-7b4fb89df9-mqnbq with esmtpa (envelope-from ) id 1vZ2pG-00000000MI7-1UgS; Fri, 26 Dec 2025 11:05:30 +0300 Date: Fri, 26 Dec 2025 11:05:28 +0300 To: Sergey Bronnikov Cc: tarantool-patches@dev.tarantool.org Message-ID: References: <9c378a741df0ebcd8e56ec738436ff450c167d72.1761301736.git.skaplun@tarantool.org> <7696cc7b-12a5-4194-a28d-43f5810c93e3@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7696cc7b-12a5-4194-a28d-43f5810c93e3@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD979975AF0D777FEBD705C26DA7DFA1BE5FABF32B159CC9D93182A05F5380850407D0DE93FF45B32923DE06ABAFEAF6705CEF84A6C8B967F3D4F327FDBBEDA3D817E39F992C946ADCE X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7922D113DFDC6D5A3EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F88016AB904663428638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B25F475E1440540A862E070BE324C7D3C4D131AF71CF1E11E4F6B57BC7E64490618DEB871D839B73339E8FC8737B5C2249D082881546D93491CC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92176DF2183F8FC7C0D9442B0B5983000E8941B15DA834481F9449624AB7ADAF372E808ACE2090B5E14AD6D5ED66289B5259CC434672EE63711DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C37725542EFDE5E0D335872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A5A011AF289788606A5002B1117B3ED69633B034548DBBACE81E49B01306B5E3AD823CB91A9FED034534781492E4B8EEADB1D70E2111C441FFBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE1918E10F71CB4DF9F96AB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D6599E8EFB6378E559E0773C1CAE90583943FA5EDE35AE4D23BAC035ACCF50FF5DB43838B9BEDD80634AB8341EE9D5BE9A0A57388B28B865399E64A711DB06F94A1D8448454B5F47DB108CD93680B12512CF4C41F94D744909CECFA6C6B0C050A61A8CAF69B82BA93681CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVdtTL5f5BIXboKNEnbfovKg= X-DA7885C5: 0103E19FBDF3C8D9F255D290C0D534F9CBDCD36012BA4626A383AD9E630341A042B9A4097C1363DD5B1A4C17EAA7BC4BEF2421ABFA55128DAF83EF9164C44C7E X-Mailru-Sender: 689FA8AB762F7393DDD5FD59B456EAD2F1EB2E21B9E2E0E8B22212D158AC21DCAEC7F0E29806631CE49D44BB4BD9522A059A1ED8796F048DB274557F927329BE89D5A3BC2B10C37545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 luajit 02/41] perf: introduce clock module 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: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for the review! Please consider my answers below. On 11.11.25, Sergey Bronnikov wrote: > Hi, Sergey! > > thanks for the patch! Please see my comments. > > Sergey > > On 10/24/25 13:50, Sergey Kaplun wrote: > > This module contains 2 functions: > > - `realtime()` -- returns the time represented by the wall clock. > > - `process_cputime()` -- returns the time consumed by all threads of > > the process. > I would rephrase second bullet: "to measure CPU time instead of elapsed > time" Rephrased. > Also, I would add this description to the Lua module as well. It is mentioned in the corresponding comment. Or I don't get what you mean. > > > > Both functions are implemented via FFI call to the `clock_gettime()`. > > --- > > perf/utils/clock.lua | 35 +++++++++++++++++++++++++++++++++++ > > 1 file changed, 35 insertions(+) > > create mode 100644 perf/utils/clock.lua > > > > diff --git a/perf/utils/clock.lua b/perf/utils/clock.lua > > new file mode 100644 > > index 00000000..57385967 > > --- /dev/null > > +++ b/perf/utils/clock.lua > > @@ -0,0 +1,35 @@ > > +local ffi = require('ffi') > > + > > +ffi.cdef[[ > > +struct timespec { > > + long tv_sec; /* Seconds. */ > > + long tv_nsec; /* Nanoseconds. */ > > +}; > > + > > +int clock_gettime(int clockid, struct timespec *tp); > > +]] > > + > > +local C = ffi.C > > + > > +-- Wall clock. > > +local CLOCK_REALTIME = 0 > >  This clock is not a reliable source of the time. This clock can be > adjusted by > > NTP or manually or by timezones. It is better to use CLOCK_MONOTONIC or > > even CLOCK_MONOTONIC_RAW (not portable, Linux-specific), it is more reliable > > and does not depend on things listed above. I have no strict opinion on this. On the first hand, monotonic time may be more reliable. OTOH, Google Benchmark uses realtime. AFAIU, the main point of using "real-time" is to reflect overall execution duration and adjust it for the minimum benchmark duration. Do we need to compare results with MONOTONIC time? I suppose that there is no way that wall clock will be adjusted during benchmarks somehow. > > > +-- CPU time consumed by the process. > > +local CLOCK_PROCESS_CPUTIME_ID = 2 > > + > > +-- All functions below returns the corresponding `clock_gettime()` > s/`clock_gettime()`/elapsed time/ Fixed. See the iterative patch below: =================================================================== diff --git a/perf/utils/clock.lua b/perf/utils/clock.lua index 57385967..cf708194 100644 --- a/perf/utils/clock.lua +++ b/perf/utils/clock.lua @@ -16,8 +16,8 @@ local CLOCK_REALTIME = 0 -- CPU time consumed by the process. local CLOCK_PROCESS_CPUTIME_ID = 2 --- All functions below returns the corresponding `clock_gettime()` --- in seconds. +-- All functions below returns the corresponding elapsed time in +-- seconds. local M = {} local timespec = ffi.new('struct timespec[1]') =================================================================== > > +-- in seconds. > > +local M = {} > > + > > +local timespec = ffi.new('struct timespec[1]') > > + > > +function M.realtime() > > + C.clock_gettime(CLOCK_REALTIME, timespec) > > + return tonumber(timespec[0].tv_sec) + tonumber(timespec[0].tv_nsec) / 1e9 > > +end > > + > > may be it is better to make conversion only once? > > @@ -24,7 +24,7 @@ local timespec = ffi.new('struct timespec[1]') > >  function M.realtime() >    C.clock_gettime(CLOCK_REALTIME, timespec) > -  return tonumber(timespec[0].tv_sec) + tonumber(timespec[0].tv_nsec) / 1e9 > +  return tonumber(timespec[0].tv_sec + timespec[0].tv_nsec / 1e9) In that way we lose the precision of `tv_nsec`. Ignoring. | luajit -e 'print(400000LL / 1e9)' | 0LL >  end > > the same below > > > +function M.process_cputime() > > + C.clock_gettime(CLOCK_PROCESS_CPUTIME_ID, timespec) > > + return tonumber(timespec[0].tv_sec) + tonumber(timespec[0].tv_nsec) / 1e9 > > +end > > + > > +return M -- Best regards, Sergey Kaplun