Skip to contentSkip to conversation

unit testing context switches.

RFC In review Gilles Chanteperdrix 5 participants 20 messages Jun 2, 2006 – Jun 8, 2006

lore
Share & tools
lore
#0 lore raw

RFC 1/1 unit testing context switches.

Now that the big context switches bugs have been solved, here is a patch that adds a unit test for context switches and FPU switches with various type of threads (kernel, user, user in secondary mode, not using FPU, using FPU, etc...). As is the case of the latency test there is a small RTDM driver in kernel-space, put in the benchmark class, even though this test is for unit testing, not for benchmarking.

The FPU switches need a small piece of code architecture dependent, put in <asm/xenomai/fptest.h>, currently only implemented for x86.

The kernel-space driver is called xeno_switchtest.ko, the user-space testing tool is called switchtest, because there is already a context switch benchmarking tool called "switch".

Signature · 1 line
					    Gilles Chanteperdrix.
rtdm/switchtest.h new file +43 -0
@@ -0,0 +1,43 @@
+#ifndef SWITCHTEST_H
+#define SWITCHTEST_H
+
+#include <rtdm/rtdm.h>
+#include <rtdm/rtbenchmark.h>
+
+#define RTSWITCH_FPU     0x1
+#define RTSWITCH_USE_FPU 0x2 /* Only for kernel-space tasks. */
+
+#define RTDM_SUBCLASS_SWITCH 1
+
+struct rtswitch_task {
+    unsigned index;
+    unsigned flags;
+};
+
+struct rtswitch {
+    unsigned from;
+    unsigned to;
+};
+
+#define RTSWITCH_RTIOC_TASKS_COUNT \
+    _IOW(RTIOC_TYPE_BENCHMARK, 0x30, unsigned long)
+
+#define RTSWITCH_RTIOC_SET_CPU \
+    _IOW(RTIOC_TYPE_BENCHMARK, 0x31, unsigned long)
+
+#define RTSWITCH_RTIOC_REGISTER_UTASK \
+    _IOW(RTIOC_TYPE_BENCHMARK, 0x32, struct rtswitch_task)
+
+#define RTSWITCH_RTIOC_CREATE_KTASK \
+    _IOWR(RTIOC_TYPE_BENCHMARK, 0x33, struct rtswitch_task)
+
+#define RTSWITCH_RTIOC_PEND \
+    _IOR(RTIOC_TYPE_BENCHMARK, 0x34, struct rtswitch_task)
+
+#define RTSWITCH_RTIOC_SWITCH_TO \
+    _IOR(RTIOC_TYPE_BENCHMARK, 0x35, struct rtswitch)
+
+#define RTSWITCH_RTIOC_GET_SWITCHES_COUNT \
+    _IOR(RTIOC_TYPE_BENCHMARK, 0x36, unsigned long)
+
+#endif /* SWITCHTEST_H */
asm-i386/fptest.h new file +38 -0
@@ -0,0 +1,38 @@
+#ifndef FPTEST_H
+#define FPTEST_H
+
+#ifdef __KERNEL__
+#include <linux/module.h>
+#else /* !__KERNEL__ */
+#include <stdio.h>
+#define printk printf
+#endif /* !__KERNEL__ */
+
+static inline void fp_regs_set(unsigned val)
+{
+    unsigned i;
+
+    for (i = 0; i < 8; i++)
+        __asm__ __volatile__ ("fildl %0" : /* no output */ : "m"(val));
+}
+
+static inline int fp_regs_check(unsigned val)
+{
+    unsigned i, failed = 0;
+    unsigned e[8];
+
+    for (i = 0; i < 8; i++)
+        __asm__ __volatile__ ("fistpl %0" : "=m"(e[7-i]));
+
+    for (i = 0; i < 8; i++)
+        if (e[i] != val) {
+            printk("r%d: %u != %u\n", i, e[i], val);
+            failed = 1;
+        }
+
+    return failed;
+}
+
+
+
+#endif /* FPTEST_H */
drivers/benchmark/switchtest.c new file +504 -0

504 lines not on this page · raw message

testsuite/switchtest/switchtest.c new file +752 -0

752 lines not on this page · raw message

configure.in +1 -0
Index: configure.in
===================================================================
@@ -564,6 +564,7 @@
        	src/testsuite/latency/Makefile \
        	src/testsuite/switch/Makefile \
        	src/testsuite/cyclic/Makefile \
+       	src/testsuite/switchtest/Makefile \
        	include/Makefile \
        	include/asm-generic/Makefile \
        	include/asm-blackfin/Makefile \
testsuite/switchtest/Makefile.am new file +27 -0
@@ -0,0 +1,27 @@
+testdir = $(prefix)/testsuite/switchtest
+
+test_PROGRAMS = switchtest
+
+switchtest_SOURCES = switchtest.c
+
+switchtest_CPPFLAGS = -I$(top_srcdir)/include/posix $(XENO_USER_CFLAGS) -g -I$(top_srcdir)/include
+
+switchtest_LDFLAGS = $(XENO_POSIX_WRAPPERS) $(XENO_USER_LDFLAGS)
+
+switchtest_LDADD = \
+	-lpthread -lrt \
+	../../skins/posix/.libs/libpthread_rt.a
+
+install-data-local:
+	$(mkinstalldirs) $(DESTDIR)$(testdir)
+	$(INSTALL_DATA) $(srcdir)/runinfo $(DESTDIR)$(testdir)/.runinfo
+	@echo "\$${DESTDIR}$(prefix)/bin/xeno-load \$$*" > $(DESTDIR)$(testdir)/run
+	@chmod +x $(DESTDIR)$(testdir)/run
+
+uninstall-local:
+	$(RM) $(DESTDIR)$(testdir)/.runinfo $(DESTDIR)$(testdir)/run
+
+run: all
+	@$(top_srcdir)/scripts/xeno-load --verbose
+
+EXTRA_DIST = runinfo
testsuite/switchtest/runinfo new file +1 -0
@@ -0,0 +1 @@
+cyclictest:posix+rtdm+switchtest:!./switchtest;popall:control_c
testsuite/Makefile.am +1 -1
Index: src/testsuite/Makefile.am
===================================================================
@@ -1 +1 @@
-SUBDIRS = latency switch cyclic
+SUBDIRS = latency switch cyclic switchtest
drivers/benchmark/Kconfig +8 -0
Index: ksrc/drivers/benchmark/Kconfig
===================================================================
@@ -5,3 +5,11 @@
 	help
 	Kernel-based benchmark driver for timer latency evaluation.
 	See testsuite/latency for a possible front-end.
+
+config XENO_DRIVERS_SWITCHTEST
+        depends on XENO_SKIN_RTDM
+        tristate "Context switch unit testing driver"
+        default n
+        help
+        Kernel-based driver for unit testing context switches and 
+        FPU switches.
drivers/benchmark/Config.in +2 -0
Index: ksrc/drivers/benchmark/Config.in
===================================================================
@@ -3,3 +3,5 @@
 #
 
 dep_tristate 'Timer benchmark driver' CONFIG_XENO_DRIVERS_TIMERBENCH $CONFIG_XENO_SKIN_RTDM
+
+dep_tristate 'Context switches test driver' CONFIG_XENO_DRIVERS_SWITCHTEST $CONFIG_XENO_SKIN_RTDM
drivers/benchmark/Makefile +12 -1
Index: ksrc/drivers/benchmark/Makefile
===================================================================
@@ -6,8 +6,12 @@
 
 obj-$(CONFIG_XENO_DRIVERS_TIMERBENCH) += xeno_timerbench.o
 
+obj-$(CONFIG_XENO_DRIVERS_SWITCHTEST) += xeno_switchtest.o
+
 xeno_timerbench-y := timerbench.o
 
+xeno_switchtest-y := switchtest.o
+
 EXTRA_CFLAGS += -Iinclude/xenomai
 
 else
@@ -18,12 +22,16 @@
 
 obj-$(CONFIG_XENO_DRIVERS_TIMERBENCH) := xeno_timerbench.o
 
+obj-$(CONFIG_XENO_DRIVERS_SWITCHTEST) := xeno_switchtest.o
+
 list-multi := xeno_timerbench.o
 
 xeno_timerbench-objs := timerbench.o
 
-export-objs := $(xeno_timerbench-objs)
+xeno_switchtest-objs := switchtest.o
 
+export-objs := $(xeno_timerbench-objs) $(xeno_switchtest-objs)
+
 EXTRA_CFLAGS += -I$(TOPDIR)/include/xenomai -I$(TOPDIR)/include/xenomai/compat
 
 include $(TOPDIR)/Rules.make
@@ -31,4 +39,7 @@
 xeno_timerbench.o: $(xeno_timerbench-objs)
 	$(LD) -r -o $@ $(xeno_timerbench-objs)
 
+xeno_switchtest.o: $(xeno_switchtest-objs)
+	$(LD) -r -o $@ $(xeno_switchtest-objs)
+
 endif
#1 lore raw
Quoted 7 lines · Gilles Chanteperdrix

Now that the big context switches bugs have been solved, here is a patch that adds a unit test for context switches and FPU switches with various type of threads (kernel, user, user in secondary mode, not using FPU, using FPU, etc...). As is the case of the latency test there is a small RTDM driver in kernel-space, put in the benchmark class, even though this test is for unit testing, not for benchmarking.

Quoted 8 lines

The FPU switches need a small piece of code architecture dependent, put in <asm/xenomai/fptest.h>, currently only implemented for x86.

The kernel-space driver is called xeno_switchtest.ko, the user-space testing tool is called switchtest, because there is already a context switch benchmarking tool called "switch".

does this maybe warrant a rename of both, to preclude the inevitable 'whats the difference between' Qs (sent or unsent) ?

#2 lore raw
In reply to Gilles Chanteperdrix

Gilles Chanteperdrix kirjoitti:

Quoted 6 lines

Now that the big context switches bugs have been solved, here is a patch that adds a unit test for context switches and FPU switches with various type of threads (kernel, user, user in secondary mode, not using FPU, using FPU, etc...). As is the case of the latency test there is a small RTDM driver in kernel-space, put in the benchmark class, even though this test is for unit testing, not for benchmarking.

Some months back when I was debugging an FPU bug on the ppc, I made similar test cases. Do you test the Linux side at all (does linux user/kernel task's fpu state get messed)? Though, I'm not sure if any driver uses FPU in linux kernel, but at least the PPC Altivec unit is used by RAID drivers. Btw. at least back then, Xenomai would have messed FPU state for a linux kernel task.

Quoted 6 lines

The FPU switches need a small piece of code architecture dependent, put in <asm/xenomai/fptest.h>, currently only implemented for x86.

The kernel-space driver is called xeno_switchtest.ko, the user-space testing tool is called switchtest, because there is already a context switch benchmarking tool called "switch".

-- hl

#10 lore raw
In reply to Gilles Chanteperdrix
Quoted 4 lines · Gilles Chanteperdrix

Now that the big context switches bugs have been solved, here is a patch that adds a unit test for context switches and FPU switches with various type of threads (kernel, user, user in secondary mode, not using FPU, using FPU, etc...).

Very good idea! Maybe it's a start to create more of such useful tests.

Quoted 3 lines

As is the case of the latency test
there is a small RTDM driver in kernel-space, put in the benchmark class, even though this test is for unit testing, not for benchmarking.

"Benchmark" is likely not the right term for such devices anymore. I guess no one will miss rtbenchmark.h, so what about this:

rttesting.h:
RTDM_CLASS_TESTING
|

 +-- RTDM_SUBCLASS_TIMER
 |
 +-- RTDM_SUBCLASS_SWITCH

In fact, you may even consider to add some performance tests to your driver one day. I would find it very interesting to have some numbers on average domain migration delays or on those various other switching variants - both from user and kernel contexts. This could then serve users to decide how to design critical parts of their system (and us to look for performance regressions).

Quoted 8 lines

The FPU switches need a small piece of code architecture dependent, put in <asm/xenomai/fptest.h>, currently only implemented for x86.

The kernel-space driver is called xeno_switchtest.ko, the user-space testing tool is called switchtest, because there is already a context switch benchmarking tool called "switch".

By combining both feature sets, the need for different names would disappear. :)

Jan

#3 lore raw
In reply to Heikki Lindholm
Quoted 11 lines · Heikki Lindholm

Gilles Chanteperdrix kirjoitti:

Quoted 6 lines

Now that the big context switches bugs have been solved, here is a patch that adds a unit test for context switches and FPU switches with various type of threads (kernel, user, user in secondary mode, not using FPU, using FPU, etc...). As is the case of the latency test there is a small RTDM driver in kernel-space, put in the benchmark class, even though this test is for unit testing, not for benchmarking.

Some months back when I was debugging an FPU bug on the ppc, I made similar test cases. Do you test the Linux side at all (does linux user/kernel task's fpu state get messed)?

No, currently the only Linux regular task, the idle task, does not use FPU, but it may be changed easily.

Quoted 4 lines

Though, I'm not sure if any
driver uses FPU in linux kernel, but at least the PPC Altivec unit is used by RAID drivers. Btw. at least back then, Xenomai would have messed FPU state for a linux kernel task.

x86 has the same issue: RAID driver use mmx, sse or sse2, and manually disable preemption, clear the ts bit, save the FPU registers contents before using mmx, sse or sse2, and restore the original state when done. If Xenomai ever preempts at that point, and the underlying task has not use its FPU, the contents of the FPU registers will be lost.

The only fix I see is to change the FPU switching code to only rely on the state of the FPU hardware FPU bits, and not on the status bits of the interrupted task.

Signature · 1 line
					    Gilles Chanteperdrix.
#4 lore raw
Quoted 28 lines · Gilles Chanteperdrix
Quoted 11 lines · Heikki Lindholm

Gilles Chanteperdrix kirjoitti:

Quoted 6 lines

Now that the big context switches bugs have been solved, here is a patch that adds a unit test for context switches and FPU switches with various type of threads (kernel, user, user in secondary mode, not using FPU, using FPU, etc...). As is the case of the latency test there is a small RTDM driver in kernel-space, put in the benchmark class, even though this test is for unit testing, not for benchmarking.

Some months back when I was debugging an FPU bug on the ppc, I made similar test cases. Do you test the Linux side at all (does linux user/kernel task's fpu state get messed)?

No, currently the only Linux regular task, the idle task, does not use FPU, but it may be changed easily.

Quoted 4 lines

Though, I'm not sure if any
driver uses FPU in linux kernel, but at least the PPC Altivec unit is used by RAID drivers. Btw. at least back then, Xenomai would have messed FPU state for a linux kernel task.

x86 has the same issue: RAID driver use mmx, sse or sse2, and manually disable preemption, clear the ts bit, save the FPU registers contents before using mmx, sse or sse2, and restore the original state when done. If Xenomai ever preempts at that point, and the underlying task has not use its FPU, the contents of the FPU registers will be lost.

Quoted 3 lines

The only fix I see is to change the FPU switching code to only rely on the state of the FPU hardware FPU bits, and not on the status bits of the interrupted task.

Actually, only the mmx code is problematic because mmx registers are aliased to the regular floating point registers. sse and sse2 use distinct registers, so as long as real-time code does not use SSE registers, there is no problem. Altivec seems to be in the same case as SSE, or am I missing something ?

Signature · 1 line
					    Gilles Chanteperdrix.
#5 lore raw

Gilles Chanteperdrix kirjoitti:

Quoted 29 lines
Quoted 28 lines · Gilles Chanteperdrix
Quoted 11 lines · Heikki Lindholm

Gilles Chanteperdrix kirjoitti:

Quoted 6 lines

Now that the big context switches bugs have been solved, here is a patch that adds a unit test for context switches and FPU switches with various type of threads (kernel, user, user in secondary mode, not using FPU, using FPU, etc...). As is the case of the latency test there is a small RTDM driver in kernel-space, put in the benchmark class, even though this test is for unit testing, not for benchmarking.

Some months back when I was debugging an FPU bug on the ppc, I made similar test cases. Do you test the Linux side at all (does linux user/kernel task's fpu state get messed)?

No, currently the only Linux regular task, the idle task, does not use FPU, but it may be changed easily.

Quoted 4 lines

Though, I'm not sure if any
driver uses FPU in linux kernel, but at least the PPC Altivec unit is used by RAID drivers. Btw. at least back then, Xenomai would have messed FPU state for a linux kernel task.

x86 has the same issue: RAID driver use mmx, sse or sse2, and manually disable preemption, clear the ts bit, save the FPU registers contents before using mmx, sse or sse2, and restore the original state when done. If Xenomai ever preempts at that point, and the underlying task has not use its FPU, the contents of the FPU registers will be lost.

Quoted 8 lines
Quoted 3 lines

The only fix I see is to change the FPU switching code to only rely on the state of the FPU hardware FPU bits, and not on the status bits of the interrupted task.

Actually, only the mmx code is problematic because mmx registers are
aliased to the regular floating point registers. sse and sse2 use
distinct registers, so as long as real-time code does not use SSE
registers, there is no problem. Altivec seems to be in the same case as SSE, or am I missing something ?

Yes, Altivec is separate from the FPU. Hopefully nobody uses FPU in the kernel - AFAIK currently not, but you never know about closed-source drivers and such. Whereas, Altivec, I think, is something that should, eventually, be supported by the real-time domain, too. Adding Altivec support is very similar to the existing fpu support, and being that it has to tackle the kernel-using-altivec issue anyway, it's probably nicer to add fpu kernel support as well. Only problem is that it will increase the context switch time. I'd remember that using the FPU bits (instead of task state) from the processor will pretty much cause saving state on every transition to xeno, because of the kernel's lazy usage model (on UP; SMP will do that anyway).

-- hl

#6 lore raw
Quoted 8 lines · Heikki Lindholm

Yes, Altivec is separate from the FPU. Hopefully nobody uses FPU in the kernel - AFAIK currently not, but you never know about closed-source drivers and such. Whereas, Altivec, I think, is something that should, eventually, be supported by the real-time domain, too. Adding Altivec support is very similar to the existing fpu support, and being that it has to tackle the kernel-using-altivec issue anyway, it's probably nicer to add fpu kernel support as well. Only problem is that it will increase the context switch time.

Maybe we could add an XNSIMD flag for Altivec and SSE, distinct from XNFPU, so that only the task that really use SIMD instructions would pay the price of the switch ?

Quoted 4 lines

I'd remember that using the FPU bits (instead
of task state) from the processor will pretty much cause saving state on every transition to xeno, because of the kernel's lazy usage model (on UP; SMP will do that anyway).

I do not understand what you mean: on x86 the state of the ts bit in cr0 is enough to know if the FPU was used either in kernel-space or in user-space. I know power pc is a bit different because the state of the FPU is saved by the user/kernel switches, but is not the state of the MSR_FP bit enough to know if FPU was used in kernel-space ?

Signature · 1 line
					    Gilles Chanteperdrix.
#7 lore raw

Gilles Chanteperdrix kirjoitti:

Quoted 10 lines
Quoted 8 lines · Heikki Lindholm

Yes, Altivec is separate from the FPU. Hopefully nobody uses FPU in the kernel - AFAIK currently not, but you never know about closed-source drivers and such. Whereas, Altivec, I think, is something that should, eventually, be supported by the real-time domain, too. Adding Altivec support is very similar to the existing fpu support, and being that it has to tackle the kernel-using-altivec issue anyway, it's probably nicer to add fpu kernel support as well. Only problem is that it will increase the context switch time.

Quoted 3 lines

Maybe we could add an XNSIMD flag for Altivec and SSE, distinct from XNFPU, so that only the task that really use SIMD instructions would pay the price of the switch ?

Sounds like a plan to me.

Quoted 10 lines
Quoted 4 lines

I'd remember that using the FPU bits (instead
of task state) from the processor will pretty much cause saving state on every transition to xeno, because of the kernel's lazy usage model (on UP; SMP will do that anyway).

I do not understand what you mean: on x86 the state of the ts bit in cr0 is enough to know if the FPU was used either in kernel-space or in user-space. I know power pc is a bit different because the state of the FPU is saved by the user/kernel switches, but is not the state of the MSR_FP bit enough to know if FPU was used in kernel-space ?

Yes, the MSR_FP bit is enough to know that FPU was/is being used, but as I recall, the problem is that it seldom is off after somebody has used FPU. More clearly put, if a task uses FPU, MSR_FP gets set. After that, if no other task shows interest in the FPU, its state doesn't get saved and MSR_FP stays on until some other task wants to use the FPU, at which point the FPU state is saved and MSR_FP reset. This is what I meant...

...But looking at xeno code again and thinking this over again, it doesn't seem so bad to guess FPU usage from MSR_FP, because it doesn't change the situation much, it just needs an extra (static) space for saved kernel FPU regs somewhere. I actually implemented this back when I was fixing the FPU bug, but didn't submit it then, because I thought it might not be so useful.

-- hl

#8 lore raw
Quoted 11 lines · Heikki Lindholm

Gilles Chanteperdrix kirjoitti:

Quoted 10 lines
Quoted 8 lines · Heikki Lindholm

Yes, Altivec is separate from the FPU. Hopefully nobody uses FPU in the kernel - AFAIK currently not, but you never know about closed-source drivers and such. Whereas, Altivec, I think, is something that should, eventually, be supported by the real-time domain, too. Adding Altivec support is very similar to the existing fpu support, and being that it has to tackle the kernel-using-altivec issue anyway, it's probably nicer to add fpu kernel support as well. Only problem is that it will increase the context switch time.

Quoted 5 lines
Quoted 3 lines

Maybe we could add an XNSIMD flag for Altivec and SSE, distinct from XNFPU, so that only the task that really use SIMD instructions would pay the price of the switch ?

Sounds like a plan to me.

Actually that is a bad idea on x86, because the fxsave instruction that saves the whole FP context, including SSE registers, is faster than the fsave instruction that only save the regular FP registers. We are discussing about operations that take around 500 ns on a 1GHz PIII with cold cache.

I would be curious to know how many cycles the FP and altivec registers save take on power pc.

Signature · 1 line
					    Gilles Chanteperdrix.
#9 lore raw

Gilles Chanteperdrix kirjoitti:

Quoted 16 lines
Quoted 15 lines · Heikki Lindholm

Gilles Chanteperdrix kirjoitti:

Quoted 13 lines
Quoted 8 lines · Heikki Lindholm

Yes, Altivec is separate from the FPU. Hopefully nobody uses FPU in the kernel - AFAIK currently not, but you never know about closed-source drivers and such. Whereas, Altivec, I think, is something that should, eventually, be supported by the real-time domain, too. Adding Altivec support is very similar to the existing fpu support, and being that it has to tackle the kernel-using-altivec issue anyway, it's probably nicer to add fpu kernel support as well. Only problem is that it will increase the context switch time.

Maybe we could add an XNSIMD flag for Altivec and SSE, distinct from XNFPU, so that only the task that really use SIMD instructions would pay the price of the switch ?

Quoted 7 lines
Quoted 1 line

Sounds like a plan to me.

Actually that is a bad idea on x86, because the fxsave instruction that saves the whole FP context, including SSE registers, is faster than the fsave instruction that only save the regular FP registers. We are discussing about operations that take around 500 ns on a 1GHz PIII with cold cache.

If the SSE saving instruction is faster and the hit basically goes to the rt-app that uses SSE, why is it a bad idea (other than being slow)? Who cares if there's an extraneous FPU save?

Quoted 2 lines

I would be curious to know how many cycles the FP and altivec registers save take on power pc.

Well, FPU is 32 64-bit registers and AltiVec is 32 128-bit registers. Each load/store needs a separate instruction, which is usually just one cycle, but compared to "normal" context switch, FPU is about 2x and AltiVec about 4x. So, with both enabled, context switch would total around 7 times the normal time. Some savings might be possible by enforcing usage of VRSAVE register (tells which regs are actually used), but Linux doesn't use that and I'm not sure if gcc supports that either.

-- hl

#11 lore raw
In reply to Gilles Chanteperdrix
Quoted 8 lines · Gilles Chanteperdrix

Now that the big context switches bugs have been solved, here is a patch that adds a unit test for context switches and FPU switches with various type of threads (kernel, user, user in secondary mode, not using FPU, using FPU, etc...). As is the case of the latency test there is a small RTDM driver in kernel-space, put in the benchmark class, even though this test is for unit testing, not for benchmarking.

Quoted 6 lines

The FPU switches need a small piece of code architecture dependent, put in <asm/xenomai/fptest.h>, currently only implemented for x86.

The kernel-space driver is called xeno_switchtest.ko, the user-space testing tool is called switchtest, because there is already a context switch benchmarking tool called "switch".

Here is an updated version, applying the remarks of Jim and Jan:
renamed rtbenchmark rttesting, and renamed the already existing context switch benchmark switchbench. The patch is large but contains mostly renames.

I would prefer to commit this version before implementing the other changes, namely allowing kernel-space non real-time tasks to use the FPU and merging the context switches benchmark test with this test.

Signature · 1 line
					    Gilles Chanteperdrix.
asm-i386/fptest.h new file +38 -0
@@ -0,0 +1,38 @@
+#ifndef FPTEST_H
+#define FPTEST_H
+
+#ifdef __KERNEL__
+#include <linux/module.h>
+#else /* !__KERNEL__ */
+#include <stdio.h>
+#define printk printf
+#endif /* !__KERNEL__ */
+
+static inline void fp_regs_set(unsigned val)
+{
+    unsigned i;
+
+    for (i = 0; i < 8; i++)
+        __asm__ __volatile__ ("fildl %0" : /* no output */ : "m"(val));
+}
+
+static inline int fp_regs_check(unsigned val)
+{
+    unsigned i, failed = 0;
+    unsigned e[8];
+
+    for (i = 0; i < 8; i++)
+        __asm__ __volatile__ ("fistpl %0" : "=m"(e[7-i]));
+
+    for (i = 0; i < 8; i++)
+        if (e[i] != val) {
+            printk("r%d: %u != %u\n", i, e[i], val);
+            failed = 1;
+        }
+
+    return failed;
+}
+
+
+
+#endif /* FPTEST_H */
drivers/testing/switchtest.c new file +504 -0

504 lines not on this page · raw message

testsuite/switchtest/switch.c new file +752 -0

752 lines not on this page · raw message

testsuite/switchtest/runinfo new file +1 -0
@@ -0,0 +1 @@
+switch:posix+rtdm+switchtest:!./switch;popall:control_c
testsuite/switchtest/Makefile.am new file +27 -0
@@ -0,0 +1,27 @@
+testdir = $(prefix)/testsuite/switchtest
+
+test_PROGRAMS = switch
+
+switch_SOURCES = switch.c
+
+switch_CPPFLAGS = -I$(top_srcdir)/include/posix $(XENO_USER_CFLAGS) -g -I$(top_srcdir)/include
+
+switch_LDFLAGS = $(XENO_POSIX_WRAPPERS) $(XENO_USER_LDFLAGS)
+
+switch_LDADD = \
+	-lpthread -lrt \
+	../../skins/posix/.libs/libpthread_rt.a
+
+install-data-local:
+	$(mkinstalldirs) $(DESTDIR)$(testdir)
+	$(INSTALL_DATA) $(srcdir)/runinfo $(DESTDIR)$(testdir)/.runinfo
+	@echo "\$${DESTDIR}$(prefix)/bin/xeno-load \$$*" > $(DESTDIR)$(testdir)/run
+	@chmod +x $(DESTDIR)$(testdir)/run
+
+uninstall-local:
+	$(RM) $(DESTDIR)$(testdir)/.runinfo $(DESTDIR)$(testdir)/run
+
+run: all
+	@$(top_srcdir)/scripts/xeno-load --verbose
+
+EXTRA_DIST = runinfo
rtdm/rtbenchmark.h +0 -144

144 lines not on this page · raw message

rtdm/Makefile.am +1 -1
Index: include/rtdm/Makefile.am
===================================================================
@@ -7,4 +7,4 @@
 	rtdm.h \
 	rtdm_driver.h \
 	rtserial.h \
-	rtbenchmark.h
+	rttesting.h
rtdm/rttesting.h new file +188 -0

188 lines not on this page · raw message

rtdm/rtdm.h +1 -1
Index: include/rtdm/rtdm.h
===================================================================
@@ -68,7 +68,7 @@
 #define RTDM_CLASS_CAN              3
 #define RTDM_CLASS_NETWORK          4
 #define RTDM_CLASS_RTMAC            5
-#define RTDM_CLASS_BENCHMARK        6
+#define RTDM_CLASS_TESTING          6
 /*
 #define RTDM_CLASS_USB              ?
 #define RTDM_CLASS_FIREWIRE         ?
configure.in +2 -1
Index: configure.in
===================================================================
@@ -562,8 +562,9 @@
 	src/include/Makefile \
        	src/testsuite/Makefile \
        	src/testsuite/latency/Makefile \
-       	src/testsuite/switch/Makefile \
+       	src/testsuite/switchbench/Makefile \
        	src/testsuite/cyclic/Makefile \
+       	src/testsuite/switchtest/Makefile \
        	include/Makefile \
        	include/asm-generic/Makefile \
        	include/asm-blackfin/Makefile \
testsuite/latency/latency.c +1 -1
Index: src/testsuite/latency/latency.c
===================================================================
@@ -11,7 +11,7 @@
 #include <native/task.h>
 #include <native/timer.h>
 #include <native/sem.h>
-#include <rtdm/rtbenchmark.h>
+#include <rtdm/rttesting.h>
 
 RT_TASK latency_task, display_task;
 
testsuite/switch/runinfo +0 -1
Index: src/testsuite/switch/runinfo
===================================================================
@@ -1 +0,0 @@
-switch:native:!./switch;popall:control_c
testsuite/switch/switch.c +0 -223

223 lines not on this page · raw message

testsuite/switch/Makefile.am +0 -29
Index: src/testsuite/switch/Makefile.am
===================================================================
@@ -1,29 +0,0 @@
-testdir = $(prefix)/testsuite/switch
-
-test_PROGRAMS = switch
-
-switch_SOURCES = switch.c
-
-switch_CPPFLAGS = \
-	@XENO_USER_CFLAGS@ \
-	-I$(top_srcdir)/include
-
-switch_LDFLAGS = @XENO_USER_LDFLAGS@
-
-switch_LDADD = \
-	../../skins/native/.libs/libnative.a \
-	-lpthread
-
-install-data-local:
-	$(mkinstalldirs) $(DESTDIR)$(testdir)
-	$(INSTALL_DATA) $(srcdir)/runinfo $(DESTDIR)$(testdir)/.runinfo
-	@echo "\$${DESTDIR}$(prefix)/bin/xeno-load \$$*" > $(DESTDIR)$(testdir)/run
-	@chmod +x $(DESTDIR)$(testdir)/run
-
-uninstall-local:
-	$(RM) $(DESTDIR)$(testdir)/.runinfo $(DESTDIR)$(testdir)/run
-
-run: all
-	@$(top_srcdir)/scripts/xeno-load --verbose
-
-EXTRA_DIST = runinfo
testsuite/switchbench/runinfo new file +1 -0
@@ -0,0 +1 @@
+switch:native:!./switch;popall:control_c
testsuite/switchbench/switch.c new file +223 -0

223 lines not on this page · raw message

testsuite/switchbench/Makefile.am new file +29 -0
@@ -0,0 +1,29 @@
+testdir = $(prefix)/testsuite/switchbench
+
+test_PROGRAMS = switch
+
+switch_SOURCES = switch.c
+
+switch_CPPFLAGS = \
+	@XENO_USER_CFLAGS@ \
+	-I$(top_srcdir)/include
+
+switch_LDFLAGS = @XENO_USER_LDFLAGS@
+
+switch_LDADD = \
+	../../skins/native/.libs/libnative.a \
+	-lpthread
+
+install-data-local:
+	$(mkinstalldirs) $(DESTDIR)$(testdir)
+	$(INSTALL_DATA) $(srcdir)/runinfo $(DESTDIR)$(testdir)/.runinfo
+	@echo "\$${DESTDIR}$(prefix)/bin/xeno-load \$$*" > $(DESTDIR)$(testdir)/run
+	@chmod +x $(DESTDIR)$(testdir)/run
+
+uninstall-local:
+	$(RM) $(DESTDIR)$(testdir)/.runinfo $(DESTDIR)$(testdir)/run
+
+run: all
+	@$(top_srcdir)/scripts/xeno-load --verbose
+
+EXTRA_DIST = runinfo
testsuite/cyclic/cyclictest.c +1 -1
Index: src/testsuite/cyclic/cyclictest.c
===================================================================
@@ -36,7 +36,7 @@
 #include <sys/mman.h>
 
 #if IPIPE_TRACE
-#include <rtdm/rtbenchmark.h>
+#include <rtdm/rttesting.h>
 #endif
 
 /* Ugly, but .... */
testsuite/Makefile.am +1 -1
Index: src/testsuite/Makefile.am
===================================================================
@@ -1 +1 @@
-SUBDIRS = latency switch cyclic
+SUBDIRS = latency switchbench cyclic switchtest
drivers/Kconfig +1 -1
Index: ksrc/drivers/Kconfig
===================================================================
@@ -1,2 +1,2 @@
 source "drivers/xenomai/16550A/Kconfig"
-source "drivers/xenomai/benchmark/Kconfig"
+source "drivers/xenomai/testing/Kconfig"
drivers/Makefile +4 -2
Index: ksrc/drivers/Makefile
===================================================================
@@ -2,7 +2,7 @@
 
 # Makefile frag for Linux v2.6
 
-obj-$(CONFIG_XENOMAI) += 16550A/ benchmark/
+obj-$(CONFIG_XENOMAI) += 16550A/ testing/
 
 else
 
@@ -10,8 +10,10 @@
 
 subdir-$(CONFIG_XENO_DRIVERS_16550A) += 16550A
 
-subdir-$(CONFIG_XENO_DRIVERS_TIMERBENCH) += benchmark
+subdir-$(CONFIG_XENO_DRIVERS_TIMERBENCH) += testing
 
+subdir-$(CONFIG_XENO_DRIVERS_SWITCHTEST) += testing
+
 include $(TOPDIR)/Rules.make
 
 endif
drivers/benchmark/Kconfig +0 -7
Index: ksrc/drivers/benchmark/Kconfig
===================================================================
@@ -1,7 +0,0 @@
-config XENO_DRIVERS_TIMERBENCH
-	depends on XENO_SKIN_RTDM
-	tristate "Timer benchmark driver"
-	default n
-	help
-	Kernel-based benchmark driver for timer latency evaluation.
-	See testsuite/latency for a possible front-end.
drivers/benchmark/timerbench.c +0 -575

575 lines not on this page · raw message

drivers/benchmark/Config.in +0 -5
Index: ksrc/drivers/benchmark/Config.in
===================================================================
@@ -1,5 +0,0 @@
-#
-# Xenomai configuration for Linux v2.4
-#
-
-dep_tristate 'Timer benchmark driver' CONFIG_XENO_DRIVERS_TIMERBENCH $CONFIG_XENO_SKIN_RTDM
drivers/benchmark/Makefile +0 -34
Index: ksrc/drivers/benchmark/Makefile
===================================================================
@@ -1,34 +0,0 @@
-ifeq ($(PATCHLEVEL),6)
-
-# Makefile frag for Linux v2.6
-
-EXTRA_CFLAGS += -Iinclude/xenomai
-
-obj-$(CONFIG_XENO_DRIVERS_TIMERBENCH) += xeno_timerbench.o
-
-xeno_timerbench-y := timerbench.o
-
-EXTRA_CFLAGS += -Iinclude/xenomai
-
-else
-
-# Makefile frag for Linux v2.4
-
-O_TARGET := built-in.o
-
-obj-$(CONFIG_XENO_DRIVERS_TIMERBENCH) := xeno_timerbench.o
-
-list-multi := xeno_timerbench.o
-
-xeno_timerbench-objs := timerbench.o
-
-export-objs := $(xeno_timerbench-objs)
-
-EXTRA_CFLAGS += -I$(TOPDIR)/include/xenomai -I$(TOPDIR)/include/xenomai/compat
-
-include $(TOPDIR)/Rules.make
-
-xeno_timerbench.o: $(xeno_timerbench-objs)
-	$(LD) -r -o $@ $(xeno_timerbench-objs)
-
-endif
drivers/testing/Kconfig new file +15 -0
@@ -0,0 +1,15 @@
+config XENO_DRIVERS_TIMERBENCH
+	depends on XENO_SKIN_RTDM
+	tristate "Timer benchmark driver"
+	default n
+	help
+	Kernel-based benchmark driver for timer latency evaluation.
+	See testsuite/latency for a possible front-end.
+
+config XENO_DRIVERS_SWITCHTEST
+        depends on XENO_SKIN_RTDM
+        tristate "Context switch unit testing driver"
+        default n
+        help
+        Kernel-based driver for unit testing context switches and 
+        FPU switches.
drivers/testing/timerbench.c new file +575 -0

141 lines not on this page · raw message

drivers/testing/Config.in new file +7 -0

Lines of this file are not shown. View the raw message.

drivers/testing/Makefile new file +45 -0

45 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#12 lore raw
Quoted 16 lines · Gilles Chanteperdrix
Quoted 8 lines · Gilles Chanteperdrix

Now that the big context switches bugs have been solved, here is a patch that adds a unit test for context switches and FPU switches with various type of threads (kernel, user, user in secondary mode, not using FPU, using FPU, etc...). As is the case of the latency test there is a small RTDM driver in kernel-space, put in the benchmark class, even though this test is for unit testing, not for benchmarking.

Quoted 6 lines

The FPU switches need a small piece of code architecture dependent, put in <asm/xenomai/fptest.h>, currently only implemented for x86.

The kernel-space driver is called xeno_switchtest.ko, the user-space testing tool is called switchtest, because there is already a context switch benchmarking tool called "switch".

Quoted 9 lines

Here is an updated version, applying the remarks of Jim and Jan:
renamed rtbenchmark rttesting, and renamed the already existing context switch benchmark switchbench. The patch is large but contains mostly renames.

I would prefer to commit this version before implementing the other changes, namely allowing kernel-space non real-time tasks to use the FPU and merging the context switches benchmark test with this test.

Ack, but please only use svn move for the renaming to keep the history.

Jan

#13 lore raw
In reply to Gilles Chanteperdrix
Quoted 32 lines · Gilles Chanteperdrix
Quoted 8 lines · Gilles Chanteperdrix

Now that the big context switches bugs have been solved, here is a patch that adds a unit test for context switches and FPU switches with various type of threads (kernel, user, user in secondary mode, not using FPU, using FPU, etc...). As is the case of the latency test there is a small RTDM driver in kernel-space, put in the benchmark class, even though this test is for unit testing, not for benchmarking.

Quoted 6 lines

The FPU switches need a small piece of code architecture dependent, put in <asm/xenomai/fptest.h>, currently only implemented for x86.

The kernel-space driver is called xeno_switchtest.ko, the user-space testing tool is called switchtest, because there is already a context switch benchmarking tool called "switch".

Here is an updated version, applying the remarks of Jim and Jan:
renamed rtbenchmark rttesting, and renamed the already existing context switch benchmark switchbench. The patch is large but contains mostly renames.

I would prefer to commit this version before implementing the other changes, namely allowing kernel-space non real-time tasks to use the FPU and merging the context switches benchmark test with this test.

testsuite/switchtest/switch.c new file +7 -0
+
+/* Thread type. */
+typedef enum {
+    IDLE = 0,
+    RTK  = 1,        /* kernel-space thread. */
+    RTUP = 2,        /* user-space real-time thread in primary mode. */
+    RTUS = 3,        /* user-space real-time thread in secondary mode. */

testsuite/switchtest/switch.c line 50

Quoted 10 lines
testsuite/switchtest/switch.c new file +10 -0
+    RTUO = 4,        /* user-space real-time thread oscillating
+                        between primary and secondary mode. */
+} threadtype;
+
+typedef enum {
+    FP   = 1,        /* arm the FPU task bit (only make sense for RTK) */
+    UFPP = 2,        /* use the FPU while in primary mode. */
+    UFPS = 4         /* use the FPU while in secondary mode. */
+} fpflags;
+

IDLE and FP at least look like a bit too generic, potentially subject to name clashes. Otherwise, that's fine with me.

Signature · 1 line
Philippe.
#14 lore raw
In reply to Gilles Chanteperdrix
Quoted 3 lines · Gilles Chanteperdrix
rtdm/rttesting.h new file +0 -0
@@ -0,0 +1,188 @@

...

rtdm/rttesting.h line 58

Quoted 6 lines

+ *
+ * @{
+ */

rtdm/rttesting.h new file +3 -0
+
+#ifndef _RTBENCHMARK_H
+#define _RTBENCHMARK_H

Hmm, there might be further renamings required. Could you double-check (e.g. grep -ri benchmark)?

Jan

#15 lore raw
Quoted 5 lines · Jan Kiszka
Quoted 3 lines · Gilles Chanteperdrix
rtdm/rttesting.h new file +0 -0
@@ -0,0 +1,188 @@

...

Quoted 9 lines

rtdm/rttesting.h line 58

Quoted 6 lines

+ *
+ * @{
+ */

rtdm/rttesting.h new file +3 -0
+
+#ifndef _RTBENCHMARK_H
+#define _RTBENCHMARK_H

Hmm, there might be further renamings required. Could you double-check (e.g. grep -ri benchmark)?

This particular define should be fixed in the version that I commited.

I also put dummy asm/fptest.h for all other architectures than x86, I would now need volunteers with other hardware than x86 to implement asm/fptest.h for their platform and run the test.

A little explanation of what work should be done: two functions fp_regs_set and fp_regs_check should be implemented. fp_regs_set should set all fp registers to the integer value passed as argument. fp_regs_check should check that all fp registers are set to the integer value passed as argument, print the incorrect registers if any and return 1 if some register value is incorrect.

These functions get called before and after each FPU switch to verify that the FPU switch actually saved and restored the FPU registers correctly. The registers are set to the unique index of the current task so that in case of failure, the value of the incorrect register should allow to know from which task it comes.

Signature · 1 line
					    Gilles Chanteperdrix.
#16 lore raw

Gilles Chanteperdrix kirjoitti:

Quoted 22 lines
Quoted 5 lines · Jan Kiszka
Quoted 3 lines · Gilles Chanteperdrix
rtdm/rttesting.h new file +0 -0
@@ -0,0 +1,188 @@

...

Quoted 9 lines

rtdm/rttesting.h line 58

Quoted 6 lines

+ *
+ * @{
+ */

rtdm/rttesting.h new file +3 -0
+
+#ifndef _RTBENCHMARK_H
+#define _RTBENCHMARK_H

Hmm, there might be further renamings required. Could you double-check (e.g. grep -ri benchmark)?

This particular define should be fixed in the version that I commited.

I also put dummy asm/fptest.h for all other architectures than x86, I would now need volunteers with other hardware than x86 to implement asm/fptest.h for their platform and run the test.

Quoted 6 lines

A little explanation of what work should be done: two functions fp_regs_set and fp_regs_check should be implemented. fp_regs_set should set all fp registers to the integer value passed as argument. fp_regs_check should check that all fp registers are set to the integer value passed as argument, print the incorrect registers if any and return 1 if some register value is incorrect.

IMO setting every reg to a different value would be better, or like I did, calculate some value using every reg and only check the final result. That would also make pointer (to the fpu save area) corruptions/miscalculations and interruptions to the fpu save/restore routines better visible.

-- hl

#17 lore raw
Quoted 30 lines · Heikki Lindholm

Gilles Chanteperdrix kirjoitti:

Quoted 22 lines
Quoted 5 lines · Jan Kiszka
Quoted 3 lines · Gilles Chanteperdrix
rtdm/rttesting.h new file +0 -0
@@ -0,0 +1,188 @@

...

Quoted 9 lines

rtdm/rttesting.h line 58

Quoted 6 lines

+ *
+ * @{
+ */

rtdm/rttesting.h new file +3 -0
+
+#ifndef _RTBENCHMARK_H
+#define _RTBENCHMARK_H

Hmm, there might be further renamings required. Could you double-check (e.g. grep -ri benchmark)?

This particular define should be fixed in the version that I commited.

I also put dummy asm/fptest.h for all other architectures than x86, I would now need volunteers with other hardware than x86 to implement asm/fptest.h for their platform and run the test.

Quoted 6 lines

A little explanation of what work should be done: two functions fp_regs_set and fp_regs_check should be implemented. fp_regs_set should set all fp registers to the integer value passed as argument. fp_regs_check should check that all fp registers are set to the integer value passed as argument, print the incorrect registers if any and return 1 if some register value is incorrect.

Quoted 5 lines

IMO setting every reg to a different value would be better, or like I did, calculate some value using every reg and only check the final result. That would also make pointer (to the fpu save area) corruptions/miscalculations and interruptions to the fpu save/restore routines better visible.

Every register is set to a different value by every task, so if something goes wrong, it will not get unnoticed. Checking only a final result will not tell you which context was badly switched, whereas the current approach will, and will also tell you where the erroneous register come from.

The implementor of fp_regs_set/fp_regs_check is also free to set every register to a different value depending on the integer value passed as argument but it is of limited interest.

Signature · 1 line
					    Gilles Chanteperdrix.
#18 lore raw

Gilles Chanteperdrix kirjoitti:

Quoted 37 lines
Quoted 30 lines · Heikki Lindholm

Gilles Chanteperdrix kirjoitti:

Quoted 22 lines
Quoted 5 lines · Jan Kiszka
Quoted 3 lines · Gilles Chanteperdrix
rtdm/rttesting.h new file +0 -0
@@ -0,0 +1,188 @@

...

Quoted 9 lines

rtdm/rttesting.h line 58

Quoted 6 lines

+ *
+ * @{
+ */

rtdm/rttesting.h new file +3 -0
+
+#ifndef _RTBENCHMARK_H
+#define _RTBENCHMARK_H

Hmm, there might be further renamings required. Could you double-check (e.g. grep -ri benchmark)?

This particular define should be fixed in the version that I commited.

I also put dummy asm/fptest.h for all other architectures than x86, I would now need volunteers with other hardware than x86 to implement asm/fptest.h for their platform and run the test.

Quoted 6 lines

A little explanation of what work should be done: two functions fp_regs_set and fp_regs_check should be implemented. fp_regs_set should set all fp registers to the integer value passed as argument. fp_regs_check should check that all fp registers are set to the integer value passed as argument, print the incorrect registers if any and return 1 if some register value is incorrect.

Quoted 5 lines

IMO setting every reg to a different value would be better, or like I did, calculate some value using every reg and only check the final result. That would also make pointer (to the fpu save area) corruptions/miscalculations and interruptions to the fpu save/restore routines better visible.

Quoted 3 lines

Every register is set to a different value by every task, so if something goes wrong, it will not get unnoticed. Checking only a final result will not tell you which context was badly switched, whereas the

Yes, and checking final result is more cumbersome, because the result might not be the same on all cpu implementations/modes - one would have to precalculate the correct answer once.

Quoted 2 lines

current approach will, and will also tell you where the erroneous register come from.

Good point.

One more thing though: Having always the same values doesn't tell if the task's state is overwritten with some "older generation" of its state or something odd like that. The state-saving will only need to work once and if it sucks rest of the time nobody knows. Or was that accounted for in the code? (Didn't read it all that carefully, lazy me)

-- hl

#19 lore raw
Quoted 5 lines · Heikki Lindholm

One more thing though: Having always the same values doesn't tell if the task's state is overwritten with some "older generation" of its state or something odd like that. The state-saving will only need to work once and if it sucks rest of the time nobody knows. Or was that accounted for in the code? (Didn't read it all that carefully, lazy me)

That is right, the new implementation compute a different value for each switch.

Signature · 1 line
					    Gilles Chanteperdrix.