From: Amir Goldstein <amir73il@gmail.com>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: ltp@lists.linux.it, Jan Stancek <jstancek@redhat.com>,
Miklos Szeredi <miklos@szeredi.hu>,
linux-unionfs@vger.kernel.org
Subject: [PATCH v4 4/6] syscalls/readahead02: Convert to tst_timer helpers
Date: Wed, 28 Nov 2018 18:46:43 +0200 [thread overview]
Message-ID: <20181128164645.783-5-amir73il@gmail.com> (raw)
In-Reply-To: <20181128164645.783-1-amir73il@gmail.com>
To avoid usinf wall clock and get rid of gettimeofday boiler plate code.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
.../kernel/syscalls/readahead/readahead02.c | 22 +++++++------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c
index 0acdad482..24f045900 100644
--- a/testcases/kernel/syscalls/readahead/readahead02.c
+++ b/testcases/kernel/syscalls/readahead/readahead02.c
@@ -16,7 +16,6 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <sys/time.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -25,6 +24,7 @@
#include <fcntl.h>
#include "config.h"
#include "tst_test.h"
+#include "tst_timer.h"
#include "lapi/syscalls.h"
static char testfile[PATH_MAX] = "testfile";
@@ -130,17 +130,15 @@ static void create_testfile(void)
* @cached: returns cached kB from /proc/meminfo
*/
static void read_testfile(int do_readahead, const char *fname, size_t fsize,
- unsigned long *read_bytes, long *usec,
+ unsigned long *read_bytes, long long *usec,
unsigned long *cached)
{
int fd;
size_t i = 0;
long read_bytes_start;
unsigned char *p, tmp;
- unsigned long time_start_usec, time_end_usec;
unsigned long cached_start, max_ra_estimate = 0;
off_t offset = 0;
- struct timeval now;
fd = SAFE_OPEN(fname, O_RDONLY);
@@ -180,9 +178,7 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,
tst_res(TFAIL, "offset has changed to: %lu", offset);
}
- if (gettimeofday(&now, NULL) == -1)
- tst_brk(TBROK | TERRNO, "gettimeofday failed");
- time_start_usec = now.tv_sec * 1000000 + now.tv_usec;
+ tst_timer_start(CLOCK_MONOTONIC);
read_bytes_start = get_bytes_read();
p = SAFE_MMAP(NULL, fsize, PROT_READ, MAP_SHARED | MAP_POPULATE, fd, 0);
@@ -201,10 +197,8 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,
SAFE_MUNMAP(p, fsize);
*read_bytes = get_bytes_read() - read_bytes_start;
- if (gettimeofday(&now, NULL) == -1)
- tst_brk(TBROK | TERRNO, "gettimeofday failed");
- time_end_usec = now.tv_sec * 1000000 + now.tv_usec;
- *usec = time_end_usec - time_start_usec;
+ tst_timer_stop();
+ *usec = tst_timer_elapsed_us();
SAFE_CLOSE(fd);
}
@@ -212,7 +206,7 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,
static void test_readahead(void)
{
unsigned long read_bytes, read_bytes_ra;
- long usec, usec_ra;
+ long long usec, usec_ra;
unsigned long cached_max, cached_low, cached, cached_ra;
char proc_io_fname[128];
sprintf(proc_io_fname, "/proc/%u/io", getpid());
@@ -253,8 +247,8 @@ static void test_readahead(void)
else
cached_ra = 0;
- tst_res(TINFO, "read_testfile(0) took: %ld usec", usec);
- tst_res(TINFO, "read_testfile(1) took: %ld usec", usec_ra);
+ tst_res(TINFO, "read_testfile(0) took: %lli usec", usec);
+ tst_res(TINFO, "read_testfile(1) took: %lli usec", usec_ra);
if (has_file(proc_io_fname, 0)) {
tst_res(TINFO, "read_testfile(0) read: %ld bytes", read_bytes);
tst_res(TINFO, "read_testfile(1) read: %ld bytes",
--
2.17.1
WARNING: multiple messages have this Message-ID (diff)
From: Amir Goldstein <amir73il@gmail.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 4/6] syscalls/readahead02: Convert to tst_timer helpers
Date: Wed, 28 Nov 2018 18:46:43 +0200 [thread overview]
Message-ID: <20181128164645.783-5-amir73il@gmail.com> (raw)
In-Reply-To: <20181128164645.783-1-amir73il@gmail.com>
To avoid usinf wall clock and get rid of gettimeofday boiler plate code.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
.../kernel/syscalls/readahead/readahead02.c | 22 +++++++------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c
index 0acdad482..24f045900 100644
--- a/testcases/kernel/syscalls/readahead/readahead02.c
+++ b/testcases/kernel/syscalls/readahead/readahead02.c
@@ -16,7 +16,6 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <sys/time.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -25,6 +24,7 @@
#include <fcntl.h>
#include "config.h"
#include "tst_test.h"
+#include "tst_timer.h"
#include "lapi/syscalls.h"
static char testfile[PATH_MAX] = "testfile";
@@ -130,17 +130,15 @@ static void create_testfile(void)
* @cached: returns cached kB from /proc/meminfo
*/
static void read_testfile(int do_readahead, const char *fname, size_t fsize,
- unsigned long *read_bytes, long *usec,
+ unsigned long *read_bytes, long long *usec,
unsigned long *cached)
{
int fd;
size_t i = 0;
long read_bytes_start;
unsigned char *p, tmp;
- unsigned long time_start_usec, time_end_usec;
unsigned long cached_start, max_ra_estimate = 0;
off_t offset = 0;
- struct timeval now;
fd = SAFE_OPEN(fname, O_RDONLY);
@@ -180,9 +178,7 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,
tst_res(TFAIL, "offset has changed to: %lu", offset);
}
- if (gettimeofday(&now, NULL) == -1)
- tst_brk(TBROK | TERRNO, "gettimeofday failed");
- time_start_usec = now.tv_sec * 1000000 + now.tv_usec;
+ tst_timer_start(CLOCK_MONOTONIC);
read_bytes_start = get_bytes_read();
p = SAFE_MMAP(NULL, fsize, PROT_READ, MAP_SHARED | MAP_POPULATE, fd, 0);
@@ -201,10 +197,8 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,
SAFE_MUNMAP(p, fsize);
*read_bytes = get_bytes_read() - read_bytes_start;
- if (gettimeofday(&now, NULL) == -1)
- tst_brk(TBROK | TERRNO, "gettimeofday failed");
- time_end_usec = now.tv_sec * 1000000 + now.tv_usec;
- *usec = time_end_usec - time_start_usec;
+ tst_timer_stop();
+ *usec = tst_timer_elapsed_us();
SAFE_CLOSE(fd);
}
@@ -212,7 +206,7 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,
static void test_readahead(void)
{
unsigned long read_bytes, read_bytes_ra;
- long usec, usec_ra;
+ long long usec, usec_ra;
unsigned long cached_max, cached_low, cached, cached_ra;
char proc_io_fname[128];
sprintf(proc_io_fname, "/proc/%u/io", getpid());
@@ -253,8 +247,8 @@ static void test_readahead(void)
else
cached_ra = 0;
- tst_res(TINFO, "read_testfile(0) took: %ld usec", usec);
- tst_res(TINFO, "read_testfile(1) took: %ld usec", usec_ra);
+ tst_res(TINFO, "read_testfile(0) took: %lli usec", usec);
+ tst_res(TINFO, "read_testfile(1) took: %lli usec", usec_ra);
if (has_file(proc_io_fname, 0)) {
tst_res(TINFO, "read_testfile(0) read: %ld bytes", read_bytes);
tst_res(TINFO, "read_testfile(1) read: %ld bytes",
--
2.17.1
next prev parent reply other threads:[~2018-11-29 3:49 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-28 16:46 [PATCH v4 0/6] Tests for readahead() and fadvise() on overlayfs Amir Goldstein
2018-11-28 16:46 ` [LTP] " Amir Goldstein
2018-11-28 16:46 ` [PATCH v4 1/6] syscalls/readahead02: Convert to newlib and cleanup Amir Goldstein
2018-11-28 16:46 ` [LTP] " Amir Goldstein
2018-12-03 14:39 ` Cyril Hrubis
2018-12-03 14:39 ` [LTP] " Cyril Hrubis
2018-12-03 14:59 ` Amir Goldstein
2018-12-03 14:59 ` [LTP] " Amir Goldstein
2018-11-28 16:46 ` [PATCH v4 2/6] syscalls/readahead02: abort test if readahead syscall fails Amir Goldstein
2018-11-28 16:46 ` [LTP] " Amir Goldstein
2018-12-03 14:27 ` Cyril Hrubis
2018-12-03 14:27 ` [LTP] " Cyril Hrubis
2018-12-03 14:52 ` Amir Goldstein
2018-12-03 14:52 ` [LTP] " Amir Goldstein
2018-11-28 16:46 ` [PATCH v4 3/6] syscalls/readahead02: fail test if readahead did not use any cache Amir Goldstein
2018-11-28 16:46 ` [LTP] " Amir Goldstein
2018-11-28 16:46 ` Amir Goldstein [this message]
2018-11-28 16:46 ` [LTP] [PATCH v4 4/6] syscalls/readahead02: Convert to tst_timer helpers Amir Goldstein
2018-11-28 16:46 ` [PATCH v4 5/6] syscalls/readahead02: test readahead() on an overlayfs file Amir Goldstein
2018-11-28 16:46 ` [LTP] " Amir Goldstein
2018-12-04 14:02 ` Cyril Hrubis
2018-12-04 14:02 ` [LTP] " Cyril Hrubis
2018-11-28 16:46 ` [PATCH v4 6/6] syscalls/readahead02: test readahead using posix_fadvise() Amir Goldstein
2018-11-28 16:46 ` [LTP] " Amir Goldstein
2018-12-04 14:10 ` Cyril Hrubis
2018-12-04 14:10 ` [LTP] " 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=20181128164645.783-5-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=chrubis@suse.cz \
--cc=jstancek@redhat.com \
--cc=linux-unionfs@vger.kernel.org \
--cc=ltp@lists.linux.it \
--cc=miklos@szeredi.hu \
/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.