agora inbox for [email protected]  
help / color / mirror / Atom feed
From: Andres Freund <[email protected]>
Subject: [PATCH v7 3/4] instr_time: Add INSTR_TIME_SET_SECOND()
Date: Mon, 16 Jan 2023 11:06:36 -0800

Useful to calculate the end of a time-bound loop without having to convert
into time units (which is costly).

Author:
Reviewed-by:
Discussion: https://postgr.es/m/
Backpatch:
---
 src/include/portability/instr_time.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/include/portability/instr_time.h b/src/include/portability/instr_time.h
index 185be8d5cad..91492c62a39 100644
--- a/src/include/portability/instr_time.h
+++ b/src/include/portability/instr_time.h
@@ -22,6 +22,8 @@
  * INSTR_TIME_SET_CURRENT_LAZY(t)	set t to current time if t is zero,
  *									evaluates to whether t changed
  *
+ * INSTR_TIME_SET_SECOND(t, s)		set t to s seconds
+ *
  * INSTR_TIME_ADD(x, y)				x += y
  *
  * INSTR_TIME_SUBTRACT(x, y)		x -= y
@@ -114,6 +116,9 @@ pg_clock_gettime_ns(void)
 #define INSTR_TIME_SET_CURRENT(t) \
 	((t) = pg_clock_gettime_ns())
 
+#define INSTR_TIME_SET_SECONDS(t, s) \
+	((t) = NS_PER_S * (s))
+
 #define INSTR_TIME_GET_NANOSEC(t) \
 	((uint64) (t))
 
@@ -146,6 +151,9 @@ GetTimerFrequency(void)
 #define INSTR_TIME_SET_CURRENT(t) \
 	((t) = pg_query_performance_counter())
 
+#define INSTR_TIME_SET_SECONDS(t, s) \
+	((t) = s * GetTimerFrequency())
+
 #define INSTR_TIME_GET_NANOSEC(t) \
 	((uint64) (((t) * NS_PER_S) / GetTimerFrequency()))
 
-- 
2.38.0


--ftp5i6iirmkwy7na
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v7-0004-wip-report-nanoseconds-in-pg_test_timing.patch"



view thread (261+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [PATCH v7 3/4] instr_time: Add INSTR_TIME_SET_SECOND()
  In-Reply-To: <no-message-id-630838@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox