Hoping somebody will find useful it.
Regards
Peppe
[PATCH] compiling realtime tests for SH.
This patch adds the atomi_add() define for __sh__;
ltp realtime tests seem to show that it works.
The patch also moves the tsc macros form the librttest.h
to another header file (named libtsc.h).
Without this I got the following error and no tests were built.
[snip]
In file included from librttest.c:43:
../include/librttest.h:127:2: error: #error
../include/librttest.h:169:2: error: #error
In file included from librttest.c:43:
../include/librttest.h: In function âatomic_addâ:
[snip]
The tsc macros header is only included in the following tests
(thus where necessary):
o async_handler_tsc.c
o preempt_timing.c
o rdtsc-latency.c
Note1: instead of touching the make process the patch allows to build
the tests above also for architecture that do not support tsc, yet.
These tests will fail at run-time with ENOTSUP. A warning will
appear while compiling as well.
hmm, I do know if it is the right solution but it's simple and
a good starting point for me.
Note2: I've just started running this part of the ltp on stlinux
targets so I cannot provide results and I don't know which
tests will fail.
Note3: realtime tests continues to build and apparently work on i386.
Signed-off-by: Giuseppe Cavallaro <[email protected]>
diff -urN ltp-full-20090731/testcases/realtime.orig/func/async_handler/async_handler_tsc.c ltp-full-20090731/testcases/realtime/func/async_handler/async_handler_tsc.c
--- ltp-full-20090731/testcases/realtime.orig/func/async_handler/async_handler_tsc.c 2009-11-04 15:55:58.000000000 +0100
+++ ltp-full-20090731/testcases/realtime/func/async_handler/async_handler_tsc.c 2009-11-04 15:39:21.000000000 +0100
@@ -45,6 +45,7 @@
#include <pthread.h>
#include <librttest.h>
#include <libstats.h>
+#include <libtsc.h>
#define HANDLER_PRIO 98
#define SIGNAL_PRIO 99
@@ -190,6 +191,11 @@
int main(int argc, char *argv[])
{
int signal_id, handler_id;
+
+#ifdef TSC_UNSUPPORTED
+ printf("Error: test cannot be executed on an arch wihout TSC.\n");
+ return ENOTSUP;
+#endif
setup();
rt_init("h", parse_args, argc, argv);
diff -urN ltp-full-20090731/testcases/realtime.orig/func/measurement/preempt_timing.c ltp-full-20090731/testcases/realtime/func/measurement/preempt_timing.c
--- ltp-full-20090731/testcases/realtime.orig/func/measurement/preempt_timing.c 2009-11-04 15:55:58.000000000 +0100
+++ ltp-full-20090731/testcases/realtime/func/measurement/preempt_timing.c 2009-11-04 15:39:26.000000000 +0100
@@ -52,7 +52,7 @@
#include <sys/mman.h>
#include <stdint.h>
#include <librttest.h>
-
+#include <libtsc.h>
#define ITERATIONS 1000000ULL
#define INTERVALS 10
@@ -86,6 +86,12 @@
struct sched_param param;
cpu_set_t mask;
int err;
+
+#ifdef TSC_UNSUPPORTED
+ printf("Error: test cannot be executed on an arch wihout TSC.\n");
+ return ENOTSUP;
+#endif
+
max = avg = 0;
min = -1;
setup();
diff -urN ltp-full-20090731/testcases/realtime.orig/func/measurement/rdtsc-latency.c ltp-full-20090731/testcases/realtime/func/measurement/rdtsc-latency.c
--- ltp-full-20090731/testcases/realtime.orig/func/measurement/rdtsc-latency.c 2009-11-04 15:55:58.000000000 +0100
+++ ltp-full-20090731/testcases/realtime/func/measurement/rdtsc-latency.c 2009-11-04 15:38:49.000000000 +0100
@@ -44,6 +44,7 @@
#include <errno.h>
#include <stdint.h>
#include <librttest.h>
+#include <libtsc.h>
#define ITERATIONS 1000000
@@ -101,6 +102,12 @@
unsigned long long deltas[ITERATIONS];
unsigned long long max, min, avg, tsc_a, tsc_b, tsc_period;
struct sched_param param;
+
+#ifdef TSC_UNSUPPORTED
+ printf("Error: test cannot be executed on an arch wihout TSC.\n");
+ return ENOTSUP;
+#endif
+
setup();
rt_init("h",parse_args,argc,argv);
diff -urN ltp-full-20090731/testcases/realtime.orig/include/librttest.h ltp-full-20090731/testcases/realtime/include/librttest.h
--- ltp-full-20090731/testcases/realtime.orig/include/librttest.h 2009-11-04 15:55:58.000000000 +0100
+++ ltp-full-20090731/testcases/realtime/include/librttest.h 2009-11-04 14:21:22.000000000 +0100
@@ -36,6 +36,7 @@
* 2006-May-09: improved command line argument handling
* 2007-Jul-12: Added latency tracing functions -- Josh Triplett
* 2007-Jul-26: Renamed to librttest.h -- Josh Triplett
+ * 2009-Nov-4: TSC macros within another header -- Giuseppe Cavallaro
*
*****************************************************************************/
@@ -96,36 +97,7 @@
#define thread_quit(T) (((T)->flags) & THREAD_QUIT)
#define PRINT_BUFFER_SIZE (1024*1024*4)
-
-/* TSC macros */
#define ULL_MAX 18446744073709551615ULL // (1 << 64) - 1
-#if defined(__i386__)
-#define rdtscll(val) __asm__ __volatile__("rdtsc" : "=A" (val))
-#elif defined(__x86_64__)
-#define rdtscll(val) \
- do { \
- uint32_t low, high; \
- __asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high)); \
- val = (uint64_t)high << 32 | low; \
- } while(0)
-#elif defined(__powerpc__)
-#if defined(__powerpc64__) /* 64bit version */
-#define rdtscll(val) \
- do { \
- __asm__ __volatile__ ("mfspr %0, 268" : "=r" (val)); \
- } while(0)
-#else /*__powerpc__ 32bit version */
-#define rdtscll(val) \
- do { \
- uint32_t tbhi, tblo ; \
- __asm__ __volatile__ ("mftbu %0" : "=r" (tbhi)); \
- __asm__ __volatile__ ("mftbl %0" : "=r" (tblo)); \
- val = 1000 * ((uint64_t) tbhi << 32) | tblo; \
- } while(0)
-#endif
-#else
-#error
-#endif
extern pthread_mutex_t _buffer_mutex;
extern char * _print_buffer;
@@ -135,7 +107,7 @@
/* function prototypes */
-/* atomic_add - add integer to atomic variable
+/* atomic_add - add integer to atomic variable and returns a value.
* i: integer value to add
* v: pointer of type atomic_t
*/
@@ -165,6 +137,20 @@
: "cc", "memory");
return t;
+#elif defined(__sh__)
+ unsigned long t;
+
+ __asm__ __volatile__ (
+"1: movli.l @%2, %0 ! atomic_add_return \n"
+" add %1, %0 \n"
+" movco.l %0, @%2 \n"
+" bf 1b \n"
+" synco \n"
+ : "=&z" (t)
+ : "r" (i), "r" (&v->counter)
+ : "t");
+
+ return t;
#else
#error
#endif
@@ -343,7 +329,6 @@
*/
int ts_to_nsec(struct timespec *ts, nsec_t *ns);
-/* return difference in microseconds */
unsigned long long tsc_minus(unsigned long long tsc_start, unsigned long long tsc_end);
/* rt_nanosleep: sleep for ns nanoseconds using clock_nanosleep
diff -urN ltp-full-20090731/testcases/realtime.orig/include/libtsc.h ltp-full-20090731/testcases/realtime/include/libtsc.h
--- ltp-full-20090731/testcases/realtime.orig/include/libtsc.h 1970-01-01 01:00:00.000000000 +0100
+++ ltp-full-20090731/testcases/realtime/include/libtsc.h 2009-11-04 15:41:03.000000000 +0100
@@ -0,0 +1,72 @@
+/******************************************************************************
+ *
+ * Copyright © International Business Machines Corp., 2006-2008
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * NAME
+ * libtsc.h
+ *
+ * DESCRIPTION
+ *
+ * USAGE:
+ * To be included in some testcases.
+ *
+ * AUTHOR
+ * Darren Hart <[email protected]>
+ * Giuseppe Cavallaro <peppe.cavallarost.com>
+ *
+ * HISTORY
+ * It directly comes from the librttest.h (see its HISTORY).
+ *
+ *****************************************************************************/
+
+#undef TSC_UNSUPPORTED
+
+/* TSC macros */
+#if defined(__i386__)
+#define rdtscll(val) __asm__ __volatile__("rdtsc" : "=A" (val))
+#elif defined(__x86_64__)
+#define rdtscll(val) \
+ do { \
+ uint32_t low, high; \
+ __asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high)); \
+ val = (uint64_t)high << 32 | low; \
+ } while (0)
+#elif defined(__powerpc__)
+#if defined(__powerpc64__) /* 64bit version */
+#define rdtscll(val) \
+ do { \
+ __asm__ __volatile__ ("mfspr %0, 268" : "=r" (val)); \
+ } while (0)
+#else /*__powerpc__ 32bit version */
+#define rdtscll(val) \
+ do { \
+ uint32_t tbhi, tblo ; \
+ __asm__ __volatile__ ("mftbu %0" : "=r" (tbhi)); \
+ __asm__ __volatile__ ("mftbl %0" : "=r" (tblo)); \
+ val = 1000 * ((uint64_t) tbhi << 32) | tblo; \
+ } while (0)
+#endif
+#else
+#warning TSC UNSUPPORTED
+/* All tests will be compiled also for the
+ * architecture without TSC support (e.g. SH).
+ * At run-time these will fail with ENOTSUP.
+ */
+#define rdtscll(val) do { } while (0)
+#define TSC_UNSUPPORTED
+#endif
+
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list