All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH RFC v3 1/3] lib: add tst_timer_find_clock()
@ 2018-08-28 14:40 Jan Stancek
  2018-08-28 14:40 ` [LTP] [PATCH RFC v3 2/3] lib: introduce tst_timeout_remaining() Jan Stancek
  2018-08-28 14:40 ` [LTP] [PATCH RFC v3 3/3] move_pages12: end early if runtime gets close to test time Jan Stancek
  0 siblings, 2 replies; 9+ messages in thread
From: Jan Stancek @ 2018-08-28 14:40 UTC (permalink / raw)
  To: ltp

Adds function that returns first available clock usable for measuring
elapsed test time.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 include/tst_timer.h |  5 +++++
 lib/tst_timer.c     | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/tst_timer.h b/include/tst_timer.h
index 0fd7ed6cfc03..b92d975d8edc 100644
--- a/include/tst_timer.h
+++ b/include/tst_timer.h
@@ -245,6 +245,11 @@ static inline long long tst_timespec_abs_diff_ms(struct timespec t1,
 void tst_timer_check(clockid_t clk_id);
 
 /*
+ * Returns usable clock id for measuring elapsed test time.
+ */
+clockid_t tst_timer_find_clock(void);
+
+/*
  * Marks a start time for given clock type.
  *
  * @clk_id: Posix clock to use.
diff --git a/lib/tst_timer.c b/lib/tst_timer.c
index dffaba0cbd5c..bbd460364b70 100644
--- a/lib/tst_timer.c
+++ b/lib/tst_timer.c
@@ -39,6 +39,22 @@ static const char *clock_name(clockid_t clk_id)
 	}
 }
 
+clockid_t tst_timer_find_clock(void)
+{
+	unsigned int i;
+	static struct timespec tmp;
+	clockid_t clocks[] = { CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC_COARSE,
+		CLOCK_BOOTTIME, CLOCK_REALTIME, CLOCK_REALTIME_COARSE };
+
+	for (i = 0; i < ARRAY_SIZE(clocks); i++) {
+		if (tst_clock_gettime(clocks[i], &tmp) == 0)
+			return clocks[i];
+	}
+
+	tst_brk(TCONF, "Failed to find usable clock");
+	return -1;
+}
+
 void tst_timer_check(clockid_t clk_id)
 {
 	if (tst_clock_gettime(clk_id, &start_time)) {
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-08-30  9:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-28 14:40 [LTP] [PATCH RFC v3 1/3] lib: add tst_timer_find_clock() Jan Stancek
2018-08-28 14:40 ` [LTP] [PATCH RFC v3 2/3] lib: introduce tst_timeout_remaining() Jan Stancek
2018-08-29 13:08   ` Cyril Hrubis
2018-08-29 13:33     ` Jan Stancek
2018-08-29 14:35       ` Cyril Hrubis
2018-08-30  9:46         ` Richard Palethorpe
2018-08-30  7:21   ` Li Wang
2018-08-28 14:40 ` [LTP] [PATCH RFC v3 3/3] move_pages12: end early if runtime gets close to test time Jan Stancek
2018-08-29 13:18   ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.