All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Stancek <jstancek@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH RFC v3 1/3] lib: add tst_timer_find_clock()
Date: Tue, 28 Aug 2018 16:40:05 +0200	[thread overview]
Message-ID: <920f7a911d8b32c3c2e673a9c608ded2526a616d.1535466715.git.jstancek@redhat.com> (raw)

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


             reply	other threads:[~2018-08-28 14:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-28 14:40 Jan Stancek [this message]
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

Reply instructions:

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

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

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=920f7a911d8b32c3c2e673a9c608ded2526a616d.1535466715.git.jstancek@redhat.com \
    --to=jstancek@redhat.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.