lib: Fix clock_gettime linking problems.
PATCH 1/2 lib: Fix clock_gettime linking problems.
Until glibc 2.17 clock_* calls needed explicit -lrt and hence linking with -lltp fails on older distributions.
Since we do not want to link whole LTP with -lrt this commit adds simple internal functions for clock_gettime() and clock_getres() calls to be used internally in the test library.
--- include/tst_clocks.h | 29 +++++++++++++++++++++++++++++ lib/tst_clocks.c | 37 +++++++++++++++++++++++++++++++++++++ lib/tst_timer.c | 13 +++++++------ 3 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 include/tst_clocks.h create mode 100644 lib/tst_clocks.c
include/tst_clocks.h new file +29 -0
@@ -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
@@ -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
@@ -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 )
Signature · 1 line
2.13.0
PATCH 2/2 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.
--- 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 | 461 +++++++++++++++++++++ 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, 790 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
@@ -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
@@ -93,6 +93,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
@@ -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 +461 -0
461 lines not on this page · raw message
runtest/syscalls +1 -0
@@ -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
@@ -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
PATCH 2/2 syscalls: Add timer measurement library
----- Original Message -----
Quoted 18 lines
From: "Cyril Hrubis" <[email protected]>
To: [email protected]
Sent: Tuesday, 20 June, 2017 3:42:18 PM
Subject: [LTP] [PATCH 2/2] syscalls: Add timer measurement libraryThis commit adds a timer measurement library, mostly based on changes done to the
pselect01.ctest 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 thelib/tst_timer_test.clibrary. 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.
Quoted 5 lines
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.
Hi,
looks good to me.
It compiled fine across RHEL 5/6/7 x86_64. No failures when I run it on my laptop.
I plan to also run it across multiple arches/distros on randomly picked systems from lab.
Regards,
Jan
PATCH 2/2 syscalls: Add timer measurement library
----- Original Message -----
Quoted 30 lines
----- Original Message -----
Quoted 19 lines
From: "Cyril Hrubis" <[email protected]>
To: [email protected]
Sent: Tuesday, 20 June, 2017 3:42:18 PM
Subject: [LTP] [PATCH 2/2] syscalls: Add timer measurement libraryThis commit adds a timer measurement library, mostly based on changes done to the
pselect01.ctest 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 thelib/tst_timer_test.clibrary. 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.Quoted 5 lines
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.
Hi,
Quoted 7 lines
looks good to me.
It compiled fine across RHEL 5/6/7
x86_64. No failures when I run it on my laptop.I plan to also run it across multiple arches/distros on randomly picked systems from lab.
Results from ~35 random RHEL6/7 systems look OK. I've hit one failure in RHEL6, but that looks like bug in older kernel, because the delays are huge:
tst_test.c:870: INFO: Timeout per run is 0h 05m 00s
tst_timer_test.c:345: INFO: CLOCK_MONOTONIC resolution 1ns
tst_timer_test.c:357: INFO: prctl(PR_GET_TIMERSLACK) = 50us
tst_timer_test.c:275: INFO: nanosleep() sleeping for 1000us 500 iterations, threshold 450.01us tst_timer_test.c:296: INFO: Found 488 outliners in [500430,12493] range tst_timer_test.c:318: INFO: min 1056us, max 500430us, median 500198us, trunc mean 466362.70us (discarded 25) tst_timer_test.c:321: FAIL: nanosleep() slept for too long
Time: us | Frequency
--------------------------------------------------------------------------------
1056 | **+
27339 | -
53622 | -
79905 | .
106188 | -
132471 | .
158754 | .
185037 | -
211320 | .
237603 | -
263886 | .
290169 | -
316452 | .
342735 | -
369018 | -
395301 | .
421584 | -
447867 | -
474150 | ********************************************************************--------------------------------------------------------------------------------
26283us | 1 sample = 0.15044 '*', 0.30088 '+', 0.60177 '-', non-zero '.'
Not reproducible when I try to run it by hand.
Regards,
Jan
PATCH 2/2 syscalls: Add timer measurement library
Hi!
Quoted 3 lines
Quoted 3 lines
Hi,
looks good to me.
Pushed with your ack.
Quoted 39 lines
Quoted 5 lines
It compiled fine across RHEL 5/6/7
x86_64. No failures when I run it on my laptop.I plan to also run it across multiple arches/distros on randomly picked systems from lab.
Results from ~35 random RHEL6/7 systems look OK. I've hit one failure in RHEL6, but that looks like bug in older kernel, because the delays are huge:
tst_test.c:870: INFO: Timeout per run is 0h 05m 00s
tst_timer_test.c:345: INFO:CLOCK_MONOTONICresolution 1ns
tst_timer_test.c:357: INFO:prctl(PR_GET_TIMERSLACK)= 50us
tst_timer_test.c:275: INFO:nanosleep()sleeping for 1000us 500 iterations, threshold 450.01us tst_timer_test.c:296: INFO: Found 488 outliners in [500430,12493] range tst_timer_test.c:318: INFO: min 1056us, max 500430us, median 500198us, trunc mean 466362.70us (discarded 25) tst_timer_test.c:321: FAIL:nanosleep()slept for too longTime: us | Frequency
--------------------------------------------------------------------------------1056 | **+ 27339 | - 53622 | - 79905 | . 106188 | - 132471 | . 158754 | . 185037 | - 211320 | . 237603 | - 263886 | . 290169 | - 316452 | . 342735 | - 369018 | - 395301 | . 421584 | - 447867 | - 474150 | ********************************************************************
Quoted 4 lines
--------------------------------------------------------------------------------
26283us | 1 sample = 0.15044 '*', 0.30088 '+', 0.60177 '-', non-zero '.'Not reproducible when I try to run it by hand.
That indeed looks like a kernel bug, isn't there something in dmesg?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/2 syscalls: Add timer measurement library
----- Original Message -----
Quoted 36 lines
Quoted 36 lines
tst_test.c:870: INFO: Timeout per run is 0h 05m 00s tst_timer_test.c:345: INFO:
CLOCK_MONOTONICresolution 1ns tst_timer_test.c:357: INFO:prctl(PR_GET_TIMERSLACK)= 50us tst_timer_test.c:275: INFO:nanosleep()sleeping for 1000us 500 iterations, threshold 450.01us
tst_timer_test.c:296: INFO: Found 488 outliners in [500430,12493] range tst_timer_test.c:318: INFO: min 1056us, max 500430us, median 500198us, trunc mean 466362.70us (discarded 25)
tst_timer_test.c:321: FAIL:nanosleep()slept for too longTime: us | Frequency
--------------------------------------------------------------------------------1056 | **+ 27339 | - 53622 | - 79905 | . 106188 | - 132471 | . 158754 | . 185037 | - 211320 | . 237603 | - 263886 | . 290169 | - 316452 | . 342735 | - 369018 | - 395301 | . 421584 | - 447867 | - 474150 |********************************************************************
--------------------------------------------------------------------------------
26283us | 1 sample = 0.15044 '*', 0.30088 '+', 0.60177 '-', non-zero '.'
Quoted 3 lines
Quoted 1 line
Not reproducible when I try to run it by hand.
That indeed looks like a kernel bug, isn't there something in dmesg?
No, nothing at the time nanosleep01 was running.
We carry patch below in our tests, so it's easier to link some dmesg output with testcases.
pan/ltp-pan.c +6 -0
@@ -1360,6 +1360,12 @@ static void write_test_start(struct tag_pgrp *running) running->cmd->cmdline, "", "exit", "<<<test_output>>>"); }fflush (stdout); + +FILE *f =fopen ("/dev/kmsg" ,"w" ); +if (f) { +fprintf (f,"ltptest %s start\n" , running->cmd->name); +fclose (f); + } }
Regards,
Jan
PATCH 2/2 syscalls: Add timer measurement library
Hi!
Quoted 10 lines
No, nothing at the time nanosleep01 was running.
We carry patch below in our tests, so it's easier to link some dmesg output with testcases.
pan/ltp-pan.c +0
-0
pan/ltp-pan.c static void write_test_start(struct tag_pgrp *running) · line 1369
Quoted 10 lines
pan/ltp-pan.c +6
-0@@ -1360,6 +1360,12 @@ static void write_test_start(struct tag_pgrp *running) running->cmd->cmdline, "", "exit", "<<<test_output>>>"); }fflush (stdout); + +FILE *f =fopen ("/dev/kmsg" ,"w" ); +if (f) { +fprintf (f,"ltptest %s start\n" , running->cmd->name); +fclose (f); + } }
That sounds reasonable. Maybe we can add an option to ltp-pan and runltp to enable this.
Signature · 2 lines
Cyril Hrubis [email protected]