From: Cyril H. <su...@li...> - 2013-02-21 16:56:32
|
The branch, master, has been updated via 07f4e5432dd3e7a60bc0235f13200640c82d8f89 (commit) from 116a8c03828be8324ff0b402c33b591603883f7c (commit) - Log ----------------------------------------------------------------- commit 07f4e5432dd3e7a60bc0235f13200640c82d8f89 Author: Cyril Hrubis <ch...@su...> Date: Thu Feb 21 17:23:57 2013 +0100 syscalls/getrusage04: Try guess timer granularity. This patch adds timer granularity detection for the testcase. The granularity of getrusage timers depends on CONFIG_HZ kernel parameter. There is unfortunately no API to get getrusage timers resolution but there are linux specific POSIX timers that have exactly same granularity. These are now used to detect the expected timers resolution. Signed-off-by: Cyril Hrubis <ch...@su...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/syscalls/getrusage/Makefile | 2 + testcases/kernel/syscalls/getrusage/getrusage04.c | 54 ++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletions(-) diff --git a/testcases/kernel/syscalls/getrusage/Makefile b/testcases/kernel/syscalls/getrusage/Makefile index bd617d8..6851383 100644 --- a/testcases/kernel/syscalls/getrusage/Makefile +++ b/testcases/kernel/syscalls/getrusage/Makefile @@ -20,4 +20,6 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk +LDFLAGS += -lrt + include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/getrusage/getrusage04.c b/testcases/kernel/syscalls/getrusage/getrusage04.c index ceda15f..95c701d 100644 --- a/testcases/kernel/syscalls/getrusage/getrusage04.c +++ b/testcases/kernel/syscalls/getrusage/getrusage04.c @@ -17,6 +17,8 @@ * this test won't be executed on those platforms. * * Copyright (C) 2011 Red Hat, Inc. + * Copyright (C) 2013 Cyril Hrubis <ch...@su...> + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. @@ -37,6 +39,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ + #define _GNU_SOURCE #include <sys/types.h> #include <sys/resource.h> @@ -44,6 +47,7 @@ #include <errno.h> #include <stdio.h> #include <stdlib.h> +#include <time.h> #include "test.h" #include "usctest.h" @@ -52,7 +56,6 @@ char *TCID = "getrusage04"; int TST_TOTAL = 1; -#define BIAS_MAX 1000 #define RECORD_MAX 20 #define FACTOR_MAX 10 @@ -60,6 +63,8 @@ int TST_TOTAL = 1; #define RUSAGE_THREAD 1 #endif +static long BIAS_MAX; + static int opt_factor; static char *factor_str; static long factor_nr = 1; @@ -136,6 +141,9 @@ int main(int argc, char *argv[]) busyloop(100000); } } + + tst_resm(TPASS, "Test Passed"); + cleanup(); tst_exit(); } @@ -151,10 +159,54 @@ static void busyloop(long wait) while (wait--) ; } +/* + * The resolution of getrusage timers currently depends on CONFIG_HZ settings, + * as they are measured in jiffies. + * + * The problem is that there is no reasonable API to get either getrusage + * timers resolution or duration of jiffie. + * + * Here we use clock_getres() with linux specific CLOCK_REALTIME_COARSE (added + * in 2.6.32) which is also based on jiffies. This timer has the same + * granularity as getrusage but it's not guaranteed and it may change in the + * future. + * + * The default value for resolution was choosen to be 4ms as it corresponds to + * CONFIG_HZ=250 which seems to be default value. + */ + +#ifndef CLOCK_REALTIME_COARSE +#define CLOCK_REALTIME_COARSE 5 +#endif + +static unsigned long guess_timer_resolution(void) +{ + struct timespec res; + + if (clock_getres(CLOCK_REALTIME_COARSE, &res)) { + tst_resm(TINFO, + "CLOCK_REALTIME_COARSE not supported, using 4000 us"); + return 4000; + } + + if (res.tv_nsec < 1000000 || res.tv_nsec > 10000000) { + tst_resm(TINFO, "Unexpected CLOCK_REALTIME_COARSE resolution," + " using 4000 us"); + return 4000; + } + + tst_resm(TINFO, "Expected timers granularity is %li us", + res.tv_nsec / 1000); + + return res.tv_nsec / 1000; +} + static void setup(void) { tst_sig(NOFORK, DEF_HANDLER, cleanup); + BIAS_MAX = guess_timer_resolution(); + TEST_PAUSE; } hooks/post-receive -- ltp |