Skip to contentSkip to conversation

syscalls: Add timer measurement library

PATCH Superseded Cyril Hrubis 2 participants 7 messages Jun 14, 2017 – Jun 20, 2017 Library code

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 syscalls: Add timer measurement library

This commit adds a timer measurement library, mostly based on changes done to the pselect01.c test and changes all tests that measure timer precision to use it.

The timer testcases that measure timeouts now just define sampling function and optional setup and cleanup. The rest of the functionality is implemented in the lib/tst_timer_test.c library. This change not only removes fair amount of duplicated code but also allows us to tune thresholds and define testcases in a single place for all testcases.

The timer measurement library also supports for passing sleep time and number of iterations as a command-line parameters, can print nifty frequency plot into the terminal, as well as save test measurements into a text file.

---

The changes from the v1:

* Fixed the outliners calculation not to overflow the sample array

* Moved the sample function to tst_test structure
- now the testcases define tst_test structure
- the tst_test structure is then passed to the timer test setup function and is modified there
- this seems to be the easiest solution I could come up with

* The timer test library now sets timeout in a case that that we request single test, the timeout is set to 110% of the requested runtime which fixes timeouts if the requested time multiplied by iterations yields more than default timeout value

FYI this conflicts with the saturated timer conversions patch, I will apply this one over the saturated one while dropping changes from tst_timer.h from this one.

 include/tst_test.h                                 |   7 +-
 include/tst_timer.h                                |  26 ++
 include/tst_timer_test.h                           |  57 +++
 lib/tst_test.c                                     |  40 +-
 lib/tst_timer_test.c                               | 450 +++++++++++++++++++++
 runtest/syscalls                                   |   1 +
 testcases/kernel/syscalls/.gitignore               |   1 +
 .../syscalls/clock_nanosleep/clock_nanosleep01.c   |  67 +--
 .../syscalls/clock_nanosleep/clock_nanosleep02.c   |  49 +++
 .../kernel/syscalls/epoll_wait/epoll_wait02.c      | 125 ++----
 testcases/kernel/syscalls/futex/futex_wait05.c     |  61 +--
 testcases/kernel/syscalls/nanosleep/nanosleep01.c  |  56 +--
 testcases/kernel/syscalls/poll/poll02.c            | 104 ++---
 testcases/kernel/syscalls/pselect/pselect01.c      | 159 ++------
 testcases/kernel/syscalls/select/select04.c        | 103 ++---
 15 files changed, 779 insertions(+), 527 deletions(-)
 create mode 100644 include/tst_timer_test.h
 create mode 100644 lib/tst_timer_test.c
 create mode 100644 testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep02.c
include/tst_test.h +5 -2
index 666109550..8a575fc0a 100644
@@ -145,6 +145,9 @@ struct tst_test {
 	void (*test)(unsigned int test_nr);
 	void (*test_all)(void);
 
+	/* Sampling function for timer measurement testcases */
+	int (*sample)(int clk_id, long long usec);
+
 	/* NULL terminated array of resource file names */
 	const char *const *resource_files;
 };
@@ -179,12 +182,12 @@ extern int TEST_ERRNO;
 const char *tst_strerrno(int err);
 const char *tst_strsig(int sig);
 
+void tst_set_timeout(unsigned int timeout);
+
 #ifndef TST_NO_DEFAULT_MAIN
 
 static struct tst_test test;
 
-void tst_set_timeout(unsigned int timeout);
-
 int main(int argc, char *argv[])
 {
 	tst_run_tcases(argc, argv, &test);
include/tst_timer.h +26 -0
index f0a10bd45..0448f4428 100644
@@ -77,6 +77,32 @@ static inline struct timeval tst_us_to_timeval(long long us)
 }
 
 /*
+ * Converts ms to struct timespec
+ */
+static inline struct timespec tst_ms_to_timespec(long long us)
+{
+	struct timespec ret;
+
+	ret.tv_sec = us / 1000;
+	ret.tv_nsec = (us % 1000) * 1000000;
+
+	return ret;
+}
+
+/*
+ * Converts us to struct timespec
+ */
+static inline struct timespec tst_us_to_timespec(long long us)
+{
+	struct timespec ret;
+
+	ret.tv_sec = us / 1000000;
+	ret.tv_nsec = (us % 1000000) * 1000;
+
+	return ret;
+}
+
+/*
  * Comparsions
  */
 static inline int tst_timespec_lt(struct timespec t1, struct timespec t2)
include/tst_timer_test.h new file +57 -0

57 lines not on this page · raw message

lib/tst_test.c +30 -10
index 794aa8555..16ea64fe9 100644
@@ -30,6 +30,7 @@
 #include "tst_device.h"
 #include "lapi/futex.h"
 #include "tst_ansi_color.h"
+#include "tst_timer_test.h"
 
 #include "old_resource.h"
 #include "old_device.h"
@@ -635,25 +636,44 @@ static const char *get_tid(char *argv[])
 static struct tst_device tdev;
 struct tst_device *tst_device;
 
-static void do_setup(int argc, char *argv[])
+static void assert_test_fn(void)
 {
-	if (!tst_test)
-		tst_brk(TBROK, "No tests to run");
+	int cnt = 0;
 
-	if (!tst_test->tid)
-		tst_test->tid = get_tid(argv);
+	if (tst_test->test)
+		cnt++;
 
-	if (!tst_test->test && !tst_test->test_all)
+	if (tst_test->test_all)
+		cnt++;
+
+	if (tst_test->sample)
+		cnt++;
+
+	if (!cnt)
 		tst_brk(TBROK, "No test function speficied");
 
-	if (tst_test->test && tst_test->test_all)
-		tst_brk(TBROK, "You can define either test() or test_all()");
+	if (cnt != 1)
+		tst_brk(TBROK, "You can define only one test function");
 
 	if (tst_test->test && !tst_test->tcnt)
 		tst_brk(TBROK, "Number of tests (tcnt) must not be > 0");
 
-	if (tst_test->test_all && tst_test->tcnt)
-		tst_brk(TBROK, "You can't define tcnt for test_all()");
+	if (!tst_test->test && tst_test->tcnt)
+		tst_brk(TBROK, "You can define tcnt only for test()");
+}
+
+static void do_setup(int argc, char *argv[])
+{
+	if (!tst_test)
+		tst_brk(TBROK, "No tests to run");
+
+	assert_test_fn();
+
+	if (tst_test->sample)
+		tst_test = tst_timer_test_setup(tst_test);
+
+	if (!tst_test->tid)
+		tst_test->tid = get_tid(argv);
 
 	if (tst_test->needs_root && geteuid() != 0)
 		tst_brk(TCONF, "Test needs to be run as root");
lib/tst_timer_test.c new file +450 -0

450 lines not on this page · raw message

runtest/syscalls +1 -0
index 32c65c60a..4bca483dd 100644
@@ -74,6 +74,7 @@ chroot04 chroot04
 
 clock_getres01 clock_getres01
 clock_nanosleep01 clock_nanosleep01
+clock_nanosleep02 clock_nanosleep02
 clock_nanosleep2_01 clock_nanosleep2_01
 
 clone01 clone01
testcases/kernel/syscalls/.gitignore +1 -0
index 03178db02..05c3dc503 100644
@@ -53,6 +53,7 @@
 /chroot/chroot04
 /clock_getres/clock_getres01
 /clock_nanosleep/clock_nanosleep01
+/clock_nanosleep/clock_nanosleep02
 /clock_nanosleep2/clock_nanosleep2_01
 /clone/clone01
 /clone/clone02
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +17 -50

107 lines not on this page · raw message

testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep02.c new file +49 -0

49 lines not on this page · raw message

testcases/kernel/syscalls/epoll_wait/epoll_wait02.c +32 -93

166 lines not on this page · raw message

testcases/kernel/syscalls/futex/futex_wait05.c +16 -45

85 lines not on this page · raw message

testcases/kernel/syscalls/nanosleep/nanosleep01.c +17 -39

80 lines not on this page · raw message

testcases/kernel/syscalls/poll/poll02.c +26 -78

136 lines not on this page · raw message

testcases/kernel/syscalls/pselect/pselect01.c +28 -131

180 lines not on this page · raw message

testcases/kernel/syscalls/select/select04.c +24 -79

133 lines not on this page · raw message

Signature · 1 line
2.13.0
#1 lore raw

PATCH v2 1/1 syscalls: Add timer measurement library

----- Original Message -----

Quoted 32 lines

This commit adds a timer measurement library, mostly based on changes done to the pselect01.c test and changes all tests that measure timer precision to use it.

The timer testcases that measure timeouts now just define sampling function and
optional setup and cleanup. The rest of the functionality is implemented in the
lib/tst_timer_test.c library. This change not only removes fair amount of duplicated code but also allows us to tune thresholds and define testcases in a
single place for all testcases.

The timer measurement library also supports for passing sleep time and number of iterations as a command-line parameters, can print nifty frequency plot into the terminal, as well as save test measurements into a text file.

---

The changes from the v1:

* Fixed the outliners calculation not to overflow the sample array

* Moved the sample function to tst_test structure
- now the testcases define tst_test structure
- the tst_test structure is then passed to the timer test setup function and is modified there
- this seems to be the easiest solution I could come up with

Quoted 5 lines

* The timer test library now sets timeout in a case that that we request single test, the timeout is set to 110% of the requested runtime which fixes timeouts if the requested time multiplied by iterations yields more than default timeout value

Hi,

as approach it looks OK to me. Couple notes below:

- error: ‘PR_GET_TIMERSLACK’ undeclared (first use in this function) Old ditros don't have this define.

- clock_getres/clock_gettime requires -rt for glibc < 2.17 On RHEL5/6 I had to modify these Makefiles:

#       modified:   include/mk/testcases.mk
#       modified:   lib/newlib_tests/Makefile
#       modified:   lib/tests/Makefile
#       modified:   testcases/kernel/containers/netns/Makefile
#       modified:   testcases/kernel/containers/share/Makefile

- threshold might be too low for some systems The data I sent in:
http://lists.linux.it/pipermail/ltp/2017-June/004705.html
was from a quite beefy system, and it sometimes went over 250us threshold.

Should we increase threshold? The formula is based on comment for select(), but we are applying this to other syscalls as well. We used to do 1%, now it's more strict with just 0.1%.

Should we use RT priority?
Should we set CPU affinity to only single CPU?

It fails easily on my laptop (i7-6820HQ CPU @ 2.70GHz) atm.:

tst_timer_test.c:269: INFO: pselect() sleeping for 25000us 50 iterations, threshold 301.29us tst_timer_test.c:312: INFO: min 25063us, max 25586us, median 25293us, trunc mean 25303.85us (discarded 2) tst_timer_test.c:315: FAIL: pselect() slept for too long

Time: us | Frequency
--------------------------------------------------------------------------------

    25063 | *******************-
    25091 | ************************-
    25119 | *****************************
    25147 |
    25175 | *********+
    25203 | **************+
    25231 | ****+
    25259 | **************+
    25287 | *********+
    25315 | *********+
    25343 | ****+
    25371 | *********+
    25399 |
    25427 |
    25455 | ****+
    25483 | ********************************************************************
    25511 | **************+
    25539 |
    25567 | ****+
--------------------------------------------------------------------------------
     28us | 1 sample = 4.85714 '*', 9.71429 '+', 19.42857 '-', non-zero '.'

Regards,
Jan

#2 lore raw

PATCH v2 1/1 syscalls: Add timer measurement library

Hi!

Quoted 2 lines

- error: ???PR_GET_TIMERSLACK??? undeclared (first use in this function) Old ditros don't have this define.

What about ifdefing it around as:

lib/tst_timer_test.c +5 -0
index 7566180c3..74157dbce 100644
@@ -333,6 +333,7 @@ static void timer_setup(void)
 
        monotonic_resolution = t.tv_nsec / 1000;
 
+#ifdef PR_GET_TIMERSLACK
        ret = prctl(PR_GET_TIMERSLACK);
        if (ret < 0) {
                tst_res(TINFO, "prctl(PR_GET_TIMERSLACK) = -1, using 50us");
@@ -341,6 +342,10 @@ static void timer_setup(void)
                timerslack = ret / 1000;
                tst_res(TINFO, "prctl(PR_GET_TIMERSLACK) = %ius", timerslack);
        }
+#else
+       tst_res(TINFO, "PR_GET_TIMERSLACK not defined, using 50us");
+       timerslack = 50;
+#endif /* PR_GET_TIMERSLACK */
 
 
Quoted 7 lines

- clock_getres/clock_gettime requires -rt for glibc < 2.17 On RHEL5/6 I had to modify these Makefiles:

#       modified:   include/mk/testcases.mk
#       modified:   lib/newlib_tests/Makefile
#       modified:   lib/tests/Makefile
#       modified:   testcases/kernel/containers/netns/Makefile
#       modified:   testcases/kernel/containers/share/Makefile

Ah right, will fix that in v3.

Quoted 5 lines

- threshold might be too low for some systems The data I sent in:
http://lists.linux.it/pipermail/ltp/2017-June/004705.html
was from a quite beefy system, and it sometimes went over 250us threshold.

That is something I left for discussion after we agree on the test API.

Quoted 3 lines

Should we increase threshold? The formula is based on comment for select(), but we are applying this to other syscalls as well. We used to do 1%, now it's more strict with just 0.1%.

Well, if you look at man prctl and the PR_SET_TIMERSLACK it explicitly states that the value is used for select, poll, epoll, nanosleep and futex.

The select and *poll family all use the same function with a formula we copy in the test library. The futex seems to use only the timerslack value, so we are less strict for that case and likely for the nanosleep calls, though I haven't checked that part of the kernel to make sure that the slack is used there. We may as well modify the threshold based on the scall name we get if you think that it's worth the additional complexity.

Quoted 2 lines

Should we use RT priority?
Should we set CPU affinity to only single CPU?

I would rather increase the thresholds a bit than change the test to test in a this kind of artificial scenario. Or even better we may try to run the test twice with a stricter threshold for RT thread pinned to a single CPU.

Quoted 21 lines

It fails easily on my laptop (i7-6820HQ CPU @ 2.70GHz) atm.:

tst_timer_test.c:269: INFO: pselect() sleeping for 25000us 50 iterations, threshold 301.29us tst_timer_test.c:312: INFO: min 25063us, max 25586us, median 25293us, trunc mean 25303.85us (discarded 2) tst_timer_test.c:315: FAIL: pselect() slept for too long

Time: us | Frequency
--------------------------------------------------------------------------------

    25063 | *******************-
    25091 | ************************-
    25119 | *****************************
    25147 |
    25175 | *********+
    25203 | **************+
    25231 | ****+
    25259 | **************+
    25287 | *********+
    25315 | *********+
    25343 | ****+
    25371 | *********+
    25399 |
Quoted 8 lines
    25427 |
    25455 | ****+
    25483 | ********************************************************************
    25511 | **************+
    25539 |
    25567 | ****+
--------------------------------------------------------------------------------
     28us | 1 sample = 4.85714 '*', 9.71429 '+', 19.42857 '-', non-zero '.'

Was that under a load or on an idle machine?

Anyway I'm OK with increasing the thresholds, the question is how much. For this particular case it's failing just by a tiny little bit. Do you see any failures if the static part of the treshold gets increased from 250 to 350 or do we need even more?

Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

PATCH v2 1/1 syscalls: Add timer measurement library

----- Original Message -----

Quoted 19 lines

Hi!

Quoted 2 lines

- error: ???PR_GET_TIMERSLACK??? undeclared (first use in this function) Old ditros don't have this define.

What about ifdefing it around as:

lib/tst_timer_test.c +1 -0
index 7566180c3..74157dbce 100644
@@ -333,6 +333,7 @@ static void timer_setup(void)
 
        monotonic_resolution = t.tv_nsec / 1000;
 
+#ifdef PR_GET_TIMERSLACK
        ret = prctl(PR_GET_TIMERSLACK);
        if (ret < 0) {
                tst_res(TINFO, "prctl(PR_GET_TIMERSLACK) = -1, using 50us");

lib/tst_timer_test.c static void timer_setup(void) · line 349

Quoted 8 lines
lib/tst_timer_test.c +4 -0
@@ -341,6 +342,10 @@ static void timer_setup(void)
                timerslack = ret / 1000;
                tst_res(TINFO, "prctl(PR_GET_TIMERSLACK) = %ius",
                timerslack);
        }
+#else
+       tst_res(TINFO, "PR_GET_TIMERSLACK not defined, using 50us");
+       timerslack = 50;
+#endif /* PR_GET_TIMERSLACK */

Fine by me.

Quoted 36 lines
Quoted 9 lines

- clock_getres/clock_gettime requires -rt for glibc < 2.17 On RHEL5/6 I had to modify these Makefiles:

#       modified:   include/mk/testcases.mk
#       modified:   lib/newlib_tests/Makefile
#       modified:   lib/tests/Makefile
#       modified:   testcases/kernel/containers/netns/Makefile
#       modified:   testcases/kernel/containers/share/Makefile

Ah right, will fix that in v3.

Quoted 5 lines

- threshold might be too low for some systems The data I sent in:
http://lists.linux.it/pipermail/ltp/2017-June/004705.html
was from a quite beefy system, and it sometimes went over 250us threshold.

That is something I left for discussion after we agree on the test API.

Quoted 3 lines

Should we increase threshold? The formula is based on comment for select(), but we are applying this to other syscalls as well. We used to do 1%, now it's more strict with just 0.1%.

Well, if you look at man prctl and the PR_SET_TIMERSLACK it explicitly states that the value is used for select, poll, epoll, nanosleep and futex.

The select and *poll family all use the same function with a formula we copy in
the test library. The futex seems to use only the timerslack value, so we are less strict for that case and likely for the nanosleep calls, though I haven't
checked that part of the kernel to make sure that the slack is used there. We may as well modify the threshold based on the scall name we get if you think that it's worth the additional complexity.

Quoted 6 lines
Quoted 2 lines

Should we use RT priority?
Should we set CPU affinity to only single CPU?

I would rather increase the thresholds a bit than change the test to test in a
this kind of artificial scenario.

OK.

Quoted 36 lines

Or even better we may try to run the test
twice with a stricter threshold for RT thread pinned to a single CPU.

Quoted 24 lines

It fails easily on my laptop (i7-6820HQ CPU @ 2.70GHz) atm.:

tst_timer_test.c:269: INFO: pselect() sleeping for 25000us 50 iterations, threshold 301.29us
tst_timer_test.c:312: INFO: min 25063us, max 25586us, median 25293us, trunc mean 25303.85us (discarded 2)
tst_timer_test.c:315: FAIL: pselect() slept for too long

Time: us | Frequency
--------------------------------------------------------------------------------

    25063 | *******************-
    25091 | ************************-
    25119 | *****************************
    25147 |
    25175 | *********+
    25203 | **************+
    25231 | ****+
    25259 | **************+
    25287 | *********+
    25315 | *********+
    25343 | ****+
    25371 | *********+
    25399 |
    25427 |
Quoted 8 lines
    25455 | ****+
    25483 |
    ********************************************************************
    25511 | **************+
    25539 |
    25567 | ****+
--------------------------------------------------------------------------------
     28us | 1 sample = 4.85714 '*', 9.71429 '+', 19.42857 '-', non-zero '.'
Quoted 1 line

Was that under a load or on an idle machine?

Idle, but not in performance mode.

Quoted 5 lines

Anyway I'm OK with increasing the thresholds, the question is how much. For this particular case it's failing just by a tiny little bit. Do you see any failures if the static part of the treshold gets increased from 250 to 350 or do we need even more?

I'd go with 400, I'm bit paranoid that with all HW available we still find some corner cases.

Regards,
Jan

#4 lore raw

PATCH v2 1/1 syscalls: Add timer measurement library

In reply to Jan Stancek

Hi!

Quoted 7 lines

- clock_getres/clock_gettime requires -rt for glibc < 2.17 On RHEL5/6 I had to modify these Makefiles:

#       modified:   include/mk/testcases.mk
#       modified:   lib/newlib_tests/Makefile
#       modified:   lib/tests/Makefile
#       modified:   testcases/kernel/containers/netns/Makefile
#       modified:   testcases/kernel/containers/share/Makefile

Hrm, looks like we have the very same problem as we had with the mq_open() either we link everything with -lrt or figure out how to separate the timer library and link it only with the timer testcases. The problem here is that we call a funcition from the timer library from the main library. And we cannot use weak stubs since we link statically.

Thinking of it using raw clock_* syscalls to avoid the dependency is not a good option either since these are VDSO. These could still be reached via syscall() it would be only slower and possibly broken since glibc defaults to VDSO...

Or do you have a better idea how to avoid linking whole LTP with -lrt?

Signature · 2 lines
Cyril Hrubis
[email protected]
#5 lore raw

PATCH v2 1/1 syscalls: Add timer measurement library

Hi!
What about this patch:

From 5cc450f19eb526cb19c33f4f13796e3c2a6f0bff Mon Sep 17 00:00:00 2001
From: Cyril Hrubis <[email protected]>
Date: Tue, 20 Jun 2017 14:33:59 +0200
Subject: [PATCH] Fix clock_gettime linking problems.

---
 include/tst_clocks.h |   29 +++++++++++++++++++++++++++++
 lib/tst_clocks.c     |   37 +++++++++++++++++++++++++++++++++++++
 lib/tst_timer.c      |   13 +++++++------
 lib/tst_timer_test.c |    3 ++-
 4 files changed, 75 insertions(+), 7 deletions(-)
 create mode 100644 include/tst_clocks.h
 create mode 100644 lib/tst_clocks.c
include/tst_clocks.h new file +29 -0
new file mode 100644
index 0000000..ee2f645
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017 Cyril Hrubis <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * clock_gettime() and clock_getres() functions
+ */
+
+#ifndef TST_CLOCKS__
+#define TST_CLOCKS__
+
+int tst_clock_getres(clockid_t clk_id, struct timespec *res);
+
+int tst_clock_gettime(clockid_t clk_id, struct timespec *ts);
+
+#endif /* TST_CLOCKS__ */
lib/tst_clocks.c new file +37 -0
new file mode 100644
index 0000000..87413a3
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2017 Cyril Hrubis <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * clock_gettime() and clock_getres() functions
+ */
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <time.h>
+#include <sys/syscall.h>
+
+#include "tst_clocks.h"
+
+int tst_clock_getres(clockid_t clk_id, struct timespec *res)
+{
+	return syscall(SYS_clock_getres, clk_id, res);
+}
+
+int tst_clock_gettime(clockid_t clk_id, struct timespec *ts)
+{
+	return syscall(SYS_clock_gettime, clk_id, ts);
+}
lib/tst_timer.c +7 -6
index bd3f277..afdb441 100644
@@ -25,6 +25,7 @@
 
 #include "test.h"
 #include "tst_timer.h"
+#include "tst_clocks.h"
 #include "lapi/posix_clocks.h"
 
 static struct timespec start_time, stop_time;
@@ -56,7 +57,7 @@ static const char *clock_name(clockid_t clk_id)
 
 void tst_timer_check(clockid_t clk_id)
 {
-	if (clock_gettime(clk_id, &start_time)) {
+	if (tst_clock_gettime(clk_id, &start_time)) {
 		if (errno == EINVAL) {
 			tst_brkm(TCONF, NULL,
 			         "Clock id %s(%u) not supported by kernel",
@@ -64,7 +65,7 @@ void tst_timer_check(clockid_t clk_id)
 			return;
 		}
 
-		tst_brkm(TBROK | TERRNO, NULL, "clock_gettime() failed");
+		tst_brkm(TBROK | TERRNO, NULL, "tst_clock_gettime() failed");
 	}
 }
 
@@ -72,14 +73,14 @@ void tst_timer_start(clockid_t clk_id)
 {
 	clock_id = clk_id;
 
-	if (clock_gettime(clock_id, &start_time))
-		tst_resm(TWARN | TERRNO, "clock_gettime() failed");
+	if (tst_clock_gettime(clock_id, &start_time))
+		tst_resm(TWARN | TERRNO, "tst_clock_gettime() failed");
 }
 
 void tst_timer_stop(void)
 {
-	if (clock_gettime(clock_id, &stop_time))
-		tst_resm(TWARN | TERRNO, "clock_gettime() failed");
+	if (tst_clock_gettime(clock_id, &stop_time))
+		tst_resm(TWARN | TERRNO, "tst_clock_gettime() failed");
 }
 
 struct timespec tst_timer_elapsed(void)
lib/tst_timer_test.c +2 -1
index 4627a4e..8921547 100644
@@ -23,6 +23,7 @@
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
 #include "tst_timer_test.h"
+#include "tst_clocks.h"
 
 #define MAX_SAMPLES 500
 
@@ -339,7 +340,7 @@ static void timer_setup(void)
 	struct timespec t;
 	int ret;
 
-	clock_getres(CLOCK_MONOTONIC, &t);
+	tst_clock_getres(CLOCK_MONOTONIC, &t);
 
 	tst_res(TINFO, "CLOCK_MONOTONIC resolution %lins", (long)t.tv_nsec);
 
Signature · 6 lines
1.7.10.4


-- 
Cyril Hrubis
[email protected]
#6 lore raw

PATCH v2 1/1 syscalls: Add timer measurement library

----- Original Message -----

Quoted 6 lines

From: "Cyril Hrubis" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: [email protected]
Sent: Tuesday, 20 June, 2017 2:33:58 PM
Subject: Re: [LTP] [PATCH v2] syscalls: Add timer measurement library

Quoted 8 lines

Hi!
What about this patch:

From 5cc450f19eb526cb19c33f4f13796e3c2a6f0bff Mon Sep 17 00:00:00 2001
From: Cyril Hrubis <[email protected]>
Date: Tue, 20 Jun 2017 14:33:59 +0200
Subject: [PATCH] Fix clock_gettime linking problems.

Works for me. Nothing else comes to my mind, either syscalls or linking everything with -rt.

Only potential issue I can think of is parameter padding needed in syscall() for some architectures with 32-bit userspace. With clockid_t defined as int, I think we should be fine.

Regards,
Jan