Skip to contentSkip to conversation

Use tsc for implementation of clock_gettime.

PATCH In review Gilles Chanteperdrix 2 participants 9 messages May 17, 2007 – May 18, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use tsc for implementation of clock_gettime.

Hi,

here comes, for review, a patch which reduces the overhead of clock_gettime by directly reading the tsc in user-space for architectures that support it.

Signature · 1 line
					    Gilles Chanteperdrix.
asm-ia64/Makefile.in +3 -1
Index: include/asm-ia64/Makefile.in
===================================================================
@@ -230,7 +230,9 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-ia64
-includesub_HEADERS = atomic.h calibration.h features.h hal.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
+
 SUBDIRS = bits
 all: all-recursive
 
asm-ia64/Makefile.am +2 -1
Index: include/asm-ia64/Makefile.am
===================================================================
@@ -1,5 +1,6 @@
 includesubdir = $(includedir)/asm-ia64
 
-includesub_HEADERS = atomic.h calibration.h features.h hal.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-ia64/arith.h +6 -0
Index: include/asm-ia64/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_IA64_ARITH_H
+#define _XENO_ASM_IA64_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_IA64_ARITH_H */

Property changes on: include/asm-ia64/arith.h
___________________________________________________________________
Name: svn:executable
+ *

asm-blackfin/Makefile.in +2 -2
Index: include/asm-blackfin/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-blackfin
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-blackfin/Makefile.am +2 -2
Index: include/asm-blackfin/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-blackfin
 
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-blackfin/arith.h +6 -0
Index: include/asm-blackfin/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_BLACKFIN_ARITH_H
+#define _XENO_ASM_BLACKFIN_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_BLACKFIN_ARITH_H */

Property changes on: include/asm-blackfin/arith.h
___________________________________________________________________
Name: svn:executable
+ *

asm-generic/syscall.h +0 -1
Index: include/asm-generic/syscall.h
===================================================================
@@ -55,7 +55,6 @@
 
     unsigned long long cpufreq;	/* CPU frequency */
     unsigned long tickval;	/* Tick duration (ns) */
-
 } xnsysinfo_t;
 
 #define SIGHARDEN  SIGWINCH
asm-generic/bits/bind.h +2 -2
Index: include/asm-generic/bits/bind.h
===================================================================
@@ -62,7 +62,7 @@
 	sa.sa_flags = 0;
 	sigaction(SIGXCPU, &sa, NULL);
 
-	return __xn_mux_shifted_id(muxid);
+	return muxid;
 }
 
 static inline int
@@ -105,7 +105,7 @@
 		exit(1);
 	}
 
-	return __xn_mux_shifted_id(muxid);
+	return muxid;
 }
 
 #endif /* _XENO_ASM_GENERIC_BITS_BIND_H */
asm-generic/Makefile.in +1 -1
Index: include/asm-generic/Makefile.in
===================================================================
@@ -230,7 +230,7 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-generic
-includesub_HEADERS = features.h hal.h syscall.h system.h wrappers.h
+includesub_HEADERS = arith.h features.h hal.h syscall.h system.h wrappers.h
 SUBDIRS = bits
 all: all-recursive
 
asm-generic/Makefile.am +1 -1
Index: include/asm-generic/Makefile.am
===================================================================
@@ -1,5 +1,5 @@
 includesubdir = $(includedir)/asm-generic
 
-includesub_HEADERS = features.h hal.h syscall.h system.h wrappers.h
+includesub_HEADERS = arith.h features.h hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-generic/hal.h +1 -116

130 lines not on this page · raw message

asm-generic/system.h +0 -12
Index: include/asm-generic/system.h
===================================================================
@@ -133,18 +133,6 @@
 #define xnarch_logerr(fmt,args...)   printk(KERN_ERR XNARCH_PROMPT fmt , ##args)
 #define xnarch_printf(fmt,args...)   printk(KERN_INFO XNARCH_PROMPT fmt , ##args)
 
-#define xnarch_ullmod(ull,uld,rem)   ({ xnarch_ulldiv(ull,uld,rem); (*rem); })
-#define xnarch_uldiv(ull, d)         rthal_uldivrem(ull, d, NULL)
-#define xnarch_ulmod(ull, d)         ({ u_long _rem;                    \
-                                        rthal_uldivrem(ull,d,&_rem); _rem; })
-
-#define xnarch_ullmul                rthal_ullmul
-#define xnarch_uldivrem              rthal_uldivrem
-#define xnarch_ulldiv                rthal_ulldiv
-#define xnarch_imuldiv               rthal_imuldiv
-#define xnarch_llimd                 rthal_llimd
-#define xnarch_get_cpu_tsc           rthal_rdtsc
-
 typedef cpumask_t xnarch_cpumask_t;
 
 #ifdef CONFIG_SMP
asm-generic/arith.h +173 -0

173 lines not on this page · raw message

Property changes on: include/asm-generic/arith.h
___________________________________________________________________
Name: svn:executable
+ *

asm-powerpc/Makefile.in +2 -2
Index: include/asm-powerpc/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-powerpc
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-powerpc/Makefile.am +2 -2
Index: include/asm-powerpc/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-powerpc
 
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-powerpc/arith.h +6 -0
Index: include/asm-powerpc/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_POWERPC_ARITH_H
+#define _XENO_ASM_POWERPC_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_POWERPC_ARITH_H */

Property changes on: include/asm-powerpc/arith.h
___________________________________________________________________
Name: svn:executable
+ *

asm-arm/Makefile.in +2 -2
Index: include/asm-arm/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-arm
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-arm/Makefile.am +2 -2
Index: include/asm-arm/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-arm
 
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-arm/arith.h +6 -0
Index: include/asm-arm/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_ARM_ARITH_H
+#define _XENO_ASM_ARM_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_ARM_ARITH_H */

Property changes on: include/asm-arm/arith.h
___________________________________________________________________
Name: svn:executable
+ *

posix/syscall.h +5 -0
Index: include/posix/syscall.h
===================================================================
@@ -100,6 +100,11 @@
 #define __pse51_condattr_setpshared   74
 #define __pse51_thread_getschedparam  75
 
+typedef struct pse51_sysinfo {
+	unsigned period;
+	unsigned long long wallclock_offset;
+} pse51_sysinfo_t;
+
 #ifdef __KERNEL__
 
 #ifdef __cplusplus
asm-i386/Makefile.in +2 -2
Index: include/asm-i386/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-i386
-includesub_HEADERS = atomic.h calibration.h features.h \
-		hal.h smi.h switch.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h smi.h switch.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-i386/Makefile.am +2 -2
Index: include/asm-i386/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-i386
 
-includesub_HEADERS = atomic.h calibration.h features.h \
-		hal.h smi.h switch.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h smi.h switch.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-i386/hal.h +0 -65

71 lines not on this page · raw message

asm-i386/arith.h +107 -0

107 lines not on this page · raw message

Property changes on: include/asm-i386/arith.h
___________________________________________________________________
Name: svn:executable
+ *

asm-x86_64/Makefile.in +2 -2
Index: include/asm-x86_64/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-x86_64
-includesub_HEADERS = atomic.h smi.h switch.h calibration.h features.h \
-		hal.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h smi.h switch.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-x86_64/Makefile.am +2 -2
Index: include/asm-x86_64/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-x86_64
 
-includesub_HEADERS = atomic.h smi.h switch.h calibration.h features.h \
-		hal.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h smi.h switch.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-x86_64/arith.h +6 -0
Index: include/asm-x86_64/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_X86_64_ARITH_H
+#define _XENO_ASM_X86_64_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_X86_64_ARITH_H */

Property changes on: include/asm-x86_64/arith.h
___________________________________________________________________
Name: svn:executable
+ *

nucleus/shadow.h +1 -0
Index: include/nucleus/shadow.h
===================================================================
@@ -31,6 +31,7 @@
 /* Events sent to the interface callback */
 #define XNSHADOW_CLIENT_ATTACH  0
 #define XNSHADOW_CLIENT_DETACH  1
+#define XNSHADOW_CLIENT_INFO    2
 
 #ifdef __cplusplus
 extern "C" {
skins/psos+/init.c +1 -0
Index: src/skins/psos+/init.c
===================================================================
@@ -27,6 +27,7 @@
 {
 	__psos_muxid =
 	    xeno_bind_skin(PSOS_SKIN_MAGIC, "psos", "xeno_psos");
+	__psos_muxid = __xn_mux_shifted_id(__psos_muxid);
 }
 
 void k_fatal(u_long err_code, u_long flags)
skins/rtai/init.c +1 -0
Index: src/skins/rtai/init.c
===================================================================
@@ -30,4 +30,5 @@
 {
 	__rtai_muxid =
 	    xeno_bind_skin(RTAI_SKIN_MAGIC, "RTAI", "xeno_rtai");
+	__rtai_muxid = __xn_mux_shifted_id(__rtai_muxid);
 }
skins/posix/init.c +8 -1
Index: src/skins/posix/init.c
===================================================================
@@ -35,6 +35,7 @@
 static int fork_handler_registered;
 
 int __wrap_pthread_setschedparam(pthread_t, int, const struct sched_param *);
+void pse51_clock_init(int);
 
 static __attribute__ ((constructor))
 void __init_posix_interface(void)
@@ -42,9 +43,15 @@
 	struct sched_param parm;
 	int muxid, err;
 
-	__pse51_muxid =
+	muxid =
 	    xeno_bind_skin(PSE51_SKIN_MAGIC, "POSIX", "xeno_posix");
 
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+	pse51_clock_init(muxid);
+#endif /* CONFIG_XENO_HW_DIRECT_TSC */
+	
+	__pse51_muxid = __xn_mux_shifted_id(muxid);
+
 	muxid = XENOMAI_SYSBIND(RTDM_SKIN_MAGIC,
 				XENOMAI_FEAT_DEP, XENOMAI_ABI_REV, NULL);
 	if (muxid > 0) {
skins/posix/clock.c +48 -4

68 lines not on this page · raw message

skins/vrtx/init.c +1 -0
Index: src/skins/vrtx/init.c
===================================================================
@@ -43,6 +43,7 @@
 
 	__vrtx_muxid =
 	    xeno_bind_skin(VRTX_SKIN_MAGIC, "vrtx", "xeno_vrtx");
+	__vrtx_muxid = __xn_mux_shifted_id(__vrtx_muxid);
 
 	/* Allocate a TSD key for indexing self task pointers. */
 
skins/vxworks/init.c +1 -0
Index: src/skins/vxworks/init.c
===================================================================
@@ -41,6 +41,7 @@
 {
 	__vxworks_muxid = xeno_bind_skin(VXWORKS_SKIN_MAGIC,
 					 "vxworks", "xeno_vxworks");
+	__vxworks_muxid = __xn_mux_shifted_id(__vxworks_muxid);
 
 	/* Allocate a TSD key for indexing self task pointers. */
 
skins/native/init.c +1 -0
Index: src/skins/native/init.c
===================================================================
@@ -42,6 +42,7 @@
 {
 	__native_muxid =
 	    xeno_bind_skin(XENO_SKIN_MAGIC, "native", "xeno_native");
+	__native_muxid = __xn_mux_shifted_id(__native_muxid);
 
 	/* Allocate a TSD key for indexing self task pointers. */
 
skins/rtdm/init.c +2 -0
Index: src/skins/rtdm/init.c
===================================================================
@@ -34,4 +34,6 @@
 
 	__rtdm_muxid =
 		xeno_bind_skin_opt(RTDM_SKIN_MAGIC, "rtdm", "xeno_rtdm");
+	__rtdm_muxid = __xn_mux_shifted_id(__rtdm_muxid);
+
 }
skins/posix/syscall.c +12 -1
Index: ksrc/skins/posix/syscall.c
===================================================================
@@ -2843,6 +2843,7 @@
 
 static void *pse51_eventcb(int event, void *data)
 {
+	pse51_sysinfo_t si;
 	pse51_queues_t *q;
 	
 	switch(event) {
@@ -2890,8 +2891,18 @@
 		xnarch_sysfree(q, sizeof(*q));
 
 		return NULL;
+
+	case XNSHADOW_CLIENT_INFO:
+		if (!__xn_access_ok(current, VERIFY_WRITE, data, sizeof(si)))
+			return ERR_PTR(-EFAULT);
+
+		si.period = xntbase_get_tickval(pse51_tbase);
+		si.wallclock_offset = pse51_tbase->wallclock_offset;
+
+		__xn_copy_to_user(current, data, &si, sizeof(si));
+
+		return 0;
 	}
-	
 	return ERR_PTR(-EINVAL);
 }
 
nucleus/shadow.c +12 -1
Index: ksrc/nucleus/shadow.c
===================================================================
@@ -1557,10 +1557,14 @@
 
 static int xnshadow_sys_info(struct task_struct *curr, struct pt_regs *regs)
 {
-	/* UNUSED int muxid = __xn_reg_arg1(regs); */
+	int muxid = __xn_reg_arg1(regs);
 	u_long infarg = __xn_reg_arg2(regs);
 	xnsysinfo_t info;
+	void *err;
 
+	if (muxid < 0 || muxid >= XENOMAI_MUX_NR)
+		return -EINVAL;
+
 	if (!__xn_access_ok(curr, VERIFY_WRITE, infarg, sizeof(info)))
 		return -EFAULT;
 
@@ -1568,6 +1572,13 @@
 	info.tickval = xntbase_get_tickval(&nktbase);
 	__xn_copy_to_user(curr, (void *)infarg, &info, sizeof(info));
 
+	if (muxtable[muxid].systab && muxtable[muxid].eventcb) {
+		err = muxtable[muxid].eventcb(XNSHADOW_CLIENT_INFO,
+					      (void *) __xn_reg_arg3(regs));
+		if (IS_ERR(err))
+			return PTR_ERR(err);
+	}
+
 	return 0;
 }
 
#1 lore raw
Quoted 5 lines · Gilles Chanteperdrix

Hi,

here comes, for review, a patch which reduces the overhead of clock_gettime by directly reading the tsc in user-space for architectures that support it.

Highly welcome. But I have one concern: How and when do you propagate wallclock_offset changes to user space?

I think we need some vsyscall-alike approach for this, some read-only page that is mapped into every RT process, containing things like a regularly updated offset (seqlock fashioned) or other read-only information (shadow mode? cpu id?).

Jan

#2 lore raw
Quoted 9 lines · Jan Kiszka
Quoted 5 lines · Gilles Chanteperdrix

Hi,

here comes, for review, a patch which reduces the overhead of clock_gettime by directly reading the tsc in user-space for architectures that support it.

Highly welcome. But I have one concern: How and when do you propagate wallclock_offset changes to user space?

Since clock_settime is not implemented, never, but if clock_settime was implemented, clock_settime would re-issue the __xn_sys_info syscall.

Quoted 5 lines

I think we need some vsyscall-alike approach for this, some read-only page that is mapped into every RT process, containing things like a regularly updated offset (seqlock fashioned) or other read-only information (shadow mode? cpu id?).

As I said yesterday, having a page mapped at a different address in kernel-space and user-space is not an option on ARM, because each mapping of this page would have a separated cache.

Signature · 1 line
					    Gilles Chanteperdrix.
#3 lore raw
Quoted 8 lines · Gilles Chanteperdrix
Quoted 7 lines · Jan Kiszka
Quoted 5 lines · Gilles Chanteperdrix

Hi,

here comes, for review, a patch which reduces the overhead of clock_gettime by directly reading the tsc in user-space for architectures that support it.

Quoted 5 lines
Quoted 2 lines

Highly welcome. But I have one concern: How and when do you propagate wallclock_offset changes to user space?

Since clock_settime is not implemented, never, but if clock_settime was implemented, clock_settime would re-issue the __xn_sys_info syscall.

This excludes automatic clock adjustment, something I'm convinced we will have to provide in the future.

Quoted 11 lines
Quoted 6 lines

I think we need some vsyscall-alike approach for this, some read-only page that is mapped into every RT process, containing things like a regularly updated offset (seqlock fashioned) or other read-only information (shadow mode? cpu id?).

As I said yesterday, having a page mapped at a different address in kernel-space and user-space is not an option on ARM, because each mapping of this page would have a separated cache.

Hmm, what about the kernel writing directly to the (current) user address? We then only need to keep track of the per-mm address and have not fixed kernel equivalent. At least on arm, other archs may handle this differently at compile time.

Jan

#4 lore raw
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Gilles Chanteperdrix
Quoted 7 lines · Jan Kiszka
Quoted 5 lines · Gilles Chanteperdrix

Hi,

here comes, for review, a patch which reduces the overhead of clock_gettime by directly reading the tsc in user-space for architectures that support it.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Highly welcome. But I have one concern: How and when do you propagate wallclock_offset changes to user space?

Since clock_settime is not implemented, never, but if clock_settime was implemented, clock_settime would re-issue the __xn_sys_info syscall.

This excludes automatic clock adjustment, something I'm convinced we will have to provide in the future.

When we provide automatic clock adjustment, we will have to devise something more subtle than just an offset, so we will have to redesign posix clocks support anyway. Maybe clock_gettime(CLOCK_REALTIME) will then always be a syscall. After all, rt_timer_read is a syscall. If you want the fast clock, use CLOCK_MONOTONIC or rt_timer_tsc.

Signature · 1 line
					    Gilles Chanteperdrix.
#5 lore raw
Quoted 13 lines · Gilles Chanteperdrix
Quoted 12 lines · Jan Kiszka
Quoted 11 lines · Gilles Chanteperdrix
Quoted 9 lines · Jan Kiszka
Quoted 5 lines · Gilles Chanteperdrix

Hi,

here comes, for review, a patch which reduces the overhead of clock_gettime by directly reading the tsc in user-space for architectures that support it.

Highly welcome. But I have one concern: How and when do you propagate wallclock_offset changes to user space?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Since clock_settime is not implemented, never, but if clock_settime was implemented, clock_settime would re-issue the __xn_sys_info syscall.

This excludes automatic clock adjustment, something I'm convinced we will have to provide in the future.

When we provide automatic clock adjustment, we will have to devise something more subtle than just an offset, so we will have to redesign

I think offset + scaling factor.

Quoted 3 lines

posix clocks support anyway. Maybe clock_gettime(CLOCK_REALTIME) will then always be a syscall. After all, rt_timer_read is a syscall. If you want the fast clock, use CLOCK_MONOTONIC or rt_timer_tsc.

Actually, the issue of the intermediate approach starts earlier: as soon as you have clock_settime. Then you need to sync the offset across applications in different processes.

Having clock_monotonic (and maybe also rt_timer_tsc2ns) as a fast variant already now is not bad. But beyond that, before introducing a new interface between kernel and user space, I would like to consider the effort to get it future-proof immediately. That doesn't mean that we already have to implement clock adjustment, but we may already prepare the prerequisites.

Jan

#6 lore raw
Quoted 33 lines · Jan Kiszka
Quoted 13 lines · Gilles Chanteperdrix
Quoted 12 lines · Jan Kiszka
Quoted 11 lines · Gilles Chanteperdrix
Quoted 9 lines · Jan Kiszka
Quoted 5 lines · Gilles Chanteperdrix

Hi,

here comes, for review, a patch which reduces the overhead of clock_gettime by directly reading the tsc in user-space for architectures that support it.

Highly welcome. But I have one concern: How and when do you propagate wallclock_offset changes to user space?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Since clock_settime is not implemented, never, but if clock_settime was implemented, clock_settime would re-issue the __xn_sys_info syscall.

This excludes automatic clock adjustment, something I'm convinced we will have to provide in the future.

When we provide automatic clock adjustment, we will have to devise something more subtle than just an offset, so we will have to redesign

I think offset + scaling factor.

Quoted 3 lines

posix clocks support anyway. Maybe clock_gettime(CLOCK_REALTIME) will then always be a syscall. After all, rt_timer_read is a syscall. If you want the fast clock, use CLOCK_MONOTONIC or rt_timer_tsc.

Actually, the issue of the intermediate approach starts earlier: as soon as you have clock_settime. Then you need to sync the offset across applications in different processes.

Quoted 6 lines

Having clock_monotonic (and maybe also rt_timer_tsc2ns) as a fast variant already now is not bad. But beyond that, before introducing a new interface between kernel and user space, I would like to consider the effort to get it future-proof immediately. That doesn't mean that we already have to implement clock adjustment, but we may already prepare the prerequisites.

Ok. Here is a new version that does not break the ABI, and where clock_gettime(CLOCK_REALTIME) remains a syscall.

Note that it also adds user-space conversions between tsc and ns to the native skin.

Signature · 1 line
					    Gilles Chanteperdrix.
asm-ia64/Makefile.in +3 -1
Index: include/asm-ia64/Makefile.in
===================================================================
@@ -230,7 +230,9 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-ia64
-includesub_HEADERS = atomic.h calibration.h features.h hal.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
+
 SUBDIRS = bits
 all: all-recursive
 
asm-ia64/Makefile.am +2 -1
Index: include/asm-ia64/Makefile.am
===================================================================
@@ -1,5 +1,6 @@
 includesubdir = $(includedir)/asm-ia64
 
-includesub_HEADERS = atomic.h calibration.h features.h hal.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-ia64/arith.h +6 -0
Index: include/asm-ia64/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_IA64_ARITH_H
+#define _XENO_ASM_IA64_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_IA64_ARITH_H */
asm-blackfin/Makefile.in +2 -2
Index: include/asm-blackfin/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-blackfin
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-blackfin/Makefile.am +2 -2
Index: include/asm-blackfin/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-blackfin
 
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-blackfin/arith.h +6 -0
Index: include/asm-blackfin/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_BLACKFIN_ARITH_H
+#define _XENO_ASM_BLACKFIN_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_BLACKFIN_ARITH_H */
asm-generic/syscall.h +0 -1
Index: include/asm-generic/syscall.h
===================================================================
@@ -55,7 +55,6 @@
 
     unsigned long long cpufreq;	/* CPU frequency */
     unsigned long tickval;	/* Tick duration (ns) */
-
 } xnsysinfo_t;
 
 #define SIGHARDEN  SIGWINCH
asm-generic/bits/bind.h +2 -2
Index: include/asm-generic/bits/bind.h
===================================================================
@@ -62,7 +62,7 @@
 	sa.sa_flags = 0;
 	sigaction(SIGXCPU, &sa, NULL);
 
-	return __xn_mux_shifted_id(muxid);
+	return muxid;
 }
 
 static inline int
@@ -105,7 +105,7 @@
 		exit(1);
 	}
 
-	return __xn_mux_shifted_id(muxid);
+	return muxid;
 }
 
 #endif /* _XENO_ASM_GENERIC_BITS_BIND_H */
asm-generic/Makefile.in +1 -1
Index: include/asm-generic/Makefile.in
===================================================================
@@ -230,7 +230,7 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-generic
-includesub_HEADERS = features.h hal.h syscall.h system.h wrappers.h
+includesub_HEADERS = arith.h features.h hal.h syscall.h system.h wrappers.h
 SUBDIRS = bits
 all: all-recursive
 
asm-generic/Makefile.am +1 -1
Index: include/asm-generic/Makefile.am
===================================================================
@@ -1,5 +1,5 @@
 includesubdir = $(includedir)/asm-generic
 
-includesub_HEADERS = features.h hal.h syscall.h system.h wrappers.h
+includesub_HEADERS = arith.h features.h hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-generic/hal.h +1 -116

130 lines not on this page · raw message

asm-generic/system.h +0 -12
Index: include/asm-generic/system.h
===================================================================
@@ -133,18 +133,6 @@
 #define xnarch_logerr(fmt,args...)   printk(KERN_ERR XNARCH_PROMPT fmt , ##args)
 #define xnarch_printf(fmt,args...)   printk(KERN_INFO XNARCH_PROMPT fmt , ##args)
 
-#define xnarch_ullmod(ull,uld,rem)   ({ xnarch_ulldiv(ull,uld,rem); (*rem); })
-#define xnarch_uldiv(ull, d)         rthal_uldivrem(ull, d, NULL)
-#define xnarch_ulmod(ull, d)         ({ u_long _rem;                    \
-                                        rthal_uldivrem(ull,d,&_rem); _rem; })
-
-#define xnarch_ullmul                rthal_ullmul
-#define xnarch_uldivrem              rthal_uldivrem
-#define xnarch_ulldiv                rthal_ulldiv
-#define xnarch_imuldiv               rthal_imuldiv
-#define xnarch_llimd                 rthal_llimd
-#define xnarch_get_cpu_tsc           rthal_rdtsc
-
 typedef cpumask_t xnarch_cpumask_t;
 
 #ifdef CONFIG_SMP
asm-generic/arith.h +173 -0

173 lines not on this page · raw message

asm-powerpc/Makefile.in +2 -2
Index: include/asm-powerpc/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-powerpc
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-powerpc/Makefile.am +2 -2
Index: include/asm-powerpc/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-powerpc
 
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-powerpc/arith.h +6 -0
Index: include/asm-powerpc/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_POWERPC_ARITH_H
+#define _XENO_ASM_POWERPC_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_POWERPC_ARITH_H */
asm-arm/Makefile.in +2 -2
Index: include/asm-arm/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-arm
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-arm/Makefile.am +2 -2
Index: include/asm-arm/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-arm
 
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-arm/arith.h +6 -0
Index: include/asm-arm/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_ARM_ARITH_H
+#define _XENO_ASM_ARM_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_ARM_ARITH_H */
posix/syscall.h +5 -0
Index: include/posix/syscall.h
===================================================================
@@ -100,6 +100,11 @@
 #define __pse51_condattr_setpshared   74
 #define __pse51_thread_getschedparam  75
 
+typedef struct pse51_sysinfo {
+	unsigned period;
+	unsigned long long wallclock_offset;
+} pse51_sysinfo_t;
+
 #ifdef __KERNEL__
 
 #ifdef __cplusplus
asm-i386/Makefile.in +2 -2
Index: include/asm-i386/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-i386
-includesub_HEADERS = atomic.h calibration.h features.h \
-		hal.h smi.h switch.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h smi.h switch.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-i386/Makefile.am +2 -2
Index: include/asm-i386/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-i386
 
-includesub_HEADERS = atomic.h calibration.h features.h \
-		hal.h smi.h switch.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h smi.h switch.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-i386/hal.h +0 -65

71 lines not on this page · raw message

asm-i386/arith.h +107 -0

107 lines not on this page · raw message

asm-x86_64/Makefile.in +2 -2
Index: include/asm-x86_64/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-x86_64
-includesub_HEADERS = atomic.h smi.h switch.h calibration.h features.h \
-		hal.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h smi.h switch.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-x86_64/Makefile.am +2 -2
Index: include/asm-x86_64/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-x86_64
 
-includesub_HEADERS = atomic.h smi.h switch.h calibration.h features.h \
-		hal.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h smi.h switch.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-x86_64/arith.h +6 -0
Index: include/asm-x86_64/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_X86_64_ARITH_H
+#define _XENO_ASM_X86_64_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_X86_64_ARITH_H */
skins/psos+/init.c +1 -0
Index: src/skins/psos+/init.c
===================================================================
@@ -27,6 +27,7 @@
 {
 	__psos_muxid =
 	    xeno_bind_skin(PSOS_SKIN_MAGIC, "psos", "xeno_psos");
+	__psos_muxid = __xn_mux_shifted_id(__psos_muxid);
 }
 
 void k_fatal(u_long err_code, u_long flags)
skins/rtai/init.c +1 -0
Index: src/skins/rtai/init.c
===================================================================
@@ -30,4 +30,5 @@
 {
 	__rtai_muxid =
 	    xeno_bind_skin(RTAI_SKIN_MAGIC, "RTAI", "xeno_rtai");
+	__rtai_muxid = __xn_mux_shifted_id(__rtai_muxid);
 }
skins/posix/init.c +8 -1
Index: src/skins/posix/init.c
===================================================================
@@ -35,6 +35,7 @@
 static int fork_handler_registered;
 
 int __wrap_pthread_setschedparam(pthread_t, int, const struct sched_param *);
+void pse51_clock_init(int);
 
 static __attribute__ ((constructor))
 void __init_posix_interface(void)
@@ -42,9 +43,15 @@
 	struct sched_param parm;
 	int muxid, err;
 
-	__pse51_muxid =
+	muxid =
 	    xeno_bind_skin(PSE51_SKIN_MAGIC, "POSIX", "xeno_posix");
 
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+	pse51_clock_init(muxid);
+#endif /* CONFIG_XENO_HW_DIRECT_TSC */
+	
+	__pse51_muxid = __xn_mux_shifted_id(muxid);
+
 	muxid = XENOMAI_SYSBIND(RTDM_SKIN_MAGIC,
 				XENOMAI_FEAT_DEP, XENOMAI_ABI_REV, NULL);
 	if (muxid > 0) {
skins/posix/clock.c +33 -4
Index: src/skins/posix/clock.c
===================================================================
@@ -20,9 +20,24 @@
 #include <pthread.h>		/* For pthread_setcanceltype. */
 #include <posix/syscall.h>
 #include <time.h>
+#include <asm/xenomai/arith.h>
 
 extern int __pse51_muxid;
 
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+static xnsysinfo_t sysinfo;
+
+void pse51_clock_init(int muxid)
+{
+	int err = -XENOMAI_SYSCALL3(__xn_sys_info, muxid, &sysinfo);
+	if (err) {
+		fprintf(stderr, "Xenomai Posix skin init: "
+			"sys_info: %s\n", strerror(err));
+		exit(EXIT_FAILURE);
+	}
+}
+#endif /* CONFIG_XENO_HW_DIRECT_TSC */
+
 int __wrap_clock_getres(clockid_t clock_id, struct timespec *tp)
 {
 	int err = -XENOMAI_SKINCALL2(__pse51_muxid,
@@ -39,11 +54,25 @@
 
 int __wrap_clock_gettime(clockid_t clock_id, struct timespec *tp)
 {
-	int err = -XENOMAI_SKINCALL2(__pse51_muxid,
-				     __pse51_clock_gettime,
-				     clock_id,
-				     tp);
+	int err;
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+	if (clock_id == CLOCK_MONOTONIC) {
+		unsigned long long tsc, ns;
+		unsigned long rem;
 
+		tsc = __xn_rdtsc();
+		ns = xnarch_llimd(tsc, 1000000000, sysinfo.cpufreq);
+		tp->tv_sec = xnarch_ulldiv(ns, 1000000000, &rem);
+		tp->tv_nsec = rem;
+		return 0;
+	}
+#endif /* CONFIG_XENO_HW_DIRECT_TSC */
+
+	err = -XENOMAI_SKINCALL2(__pse51_muxid,
+				 __pse51_clock_gettime,
+				 clock_id,
+				 tp);
+
 	if (!err)
 		return 0;
 
skins/vrtx/init.c +1 -0
Index: src/skins/vrtx/init.c
===================================================================
@@ -43,6 +43,7 @@
 
 	__vrtx_muxid =
 	    xeno_bind_skin(VRTX_SKIN_MAGIC, "vrtx", "xeno_vrtx");
+	__vrtx_muxid = __xn_mux_shifted_id(__vrtx_muxid);
 
 	/* Allocate a TSD key for indexing self task pointers. */
 
skins/vxworks/init.c +1 -0
Index: src/skins/vxworks/init.c
===================================================================
@@ -41,6 +41,7 @@
 {
 	__vxworks_muxid = xeno_bind_skin(VXWORKS_SKIN_MAGIC,
 					 "vxworks", "xeno_vxworks");
+	__vxworks_muxid = __xn_mux_shifted_id(__vxworks_muxid);
 
 	/* Allocate a TSD key for indexing self task pointers. */
 
skins/native/init.c +7 -0
Index: src/skins/native/init.c
===================================================================
@@ -30,6 +30,7 @@
 pthread_key_t __native_tskey;
 
 int __native_muxid = -1;
+void native_timer_init(int);
 
 static void __flush_tsd(void *tsd)
 {
@@ -43,6 +44,12 @@
 	__native_muxid =
 	    xeno_bind_skin(XENO_SKIN_MAGIC, "native", "xeno_native");
 
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+	native_timer_init(__native_muxid);
+#endif /* CONFIG_XENO_HW_DIRECT_TSC */
+	
+	__native_muxid = __xn_mux_shifted_id(__native_muxid);
+
 	/* Allocate a TSD key for indexing self task pointers. */
 
 	if (pthread_key_create(&__native_tskey, &__flush_tsd) != 0) {
skins/native/timer.c +22 -0
Index: src/skins/native/timer.c
===================================================================
@@ -21,6 +21,20 @@
 
 extern int __native_muxid;
 
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+static xnsysinfo_t sysinfo;
+
+void native_timer_init(int muxid)
+{
+	int err = XENOMAI_SYSCALL3(__xn_sys_info, muxid, &sysinfo);
+	if (err) {
+		fprintf(stderr, "Native skin init: "
+			"sys_info: %s\n", strerror(-err));
+		exit(EXIT_FAILURE);
+	}
+}
+#endif /* CONFIG_XENO_HW_DIRECT_TSC */
+
 int rt_timer_set_mode(RTIME tickval)
 {
 	return XENOMAI_SKINCALL1(__native_muxid, __native_timer_set_mode,
@@ -68,7 +82,11 @@
 {
 	RTIME ticks;
 
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+	ticks = xnarch_llimd(ns, sysinfo.cpufreq, 1000000000);
+#else /* !CONFIG_XENO_HW_DIRECT_TSC */
 	XENOMAI_SKINCALL2(__native_muxid, __native_timer_ns2tsc, &ticks, &ns);
+#endif /* !CONFIG_XENO_HW_DIRECT_TSC */
 	return ticks;
 }
 
@@ -76,7 +94,11 @@
 {
 	SRTIME ns;
 
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+	ticks = xnarch_llimd(ticks, 1000000000, sysinfo.cpufreq);
+#else /* !CONFIG_XENO_HW_DIRECT_TSC */
 	XENOMAI_SKINCALL2(__native_muxid, __native_timer_tsc2ns, &ns, &ticks);
+#endif /* !CONFIG_XENO_HW_DIRECT_TSC */
 	return ns;
 }
 
skins/rtdm/init.c +2 -0
Index: src/skins/rtdm/init.c
===================================================================
@@ -34,4 +34,6 @@
 
 	__rtdm_muxid =
 		xeno_bind_skin_opt(RTDM_SKIN_MAGIC, "rtdm", "xeno_rtdm");
+	__rtdm_muxid = __xn_mux_shifted_id(__rtdm_muxid);
+
 }
skins/posix/syscall.c +1 -1
Index: ksrc/skins/posix/syscall.c
===================================================================
@@ -2891,7 +2891,7 @@
 
 		return NULL;
 	}
-	
+
 	return ERR_PTR(-EINVAL);
 }
 
#7 lore raw
Quoted 41 lines · Gilles Chanteperdrix
Quoted 33 lines · Jan Kiszka
Quoted 13 lines · Gilles Chanteperdrix
Quoted 12 lines · Jan Kiszka
Quoted 11 lines · Gilles Chanteperdrix
Quoted 9 lines · Jan Kiszka
Quoted 5 lines · Gilles Chanteperdrix

Hi,

here comes, for review, a patch which reduces the overhead of clock_gettime by directly reading the tsc in user-space for architectures that support it.

Highly welcome. But I have one concern: How and when do you propagate wallclock_offset changes to user space?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Since clock_settime is not implemented, never, but if clock_settime was implemented, clock_settime would re-issue the __xn_sys_info syscall.

This excludes automatic clock adjustment, something I'm convinced we will have to provide in the future.

When we provide automatic clock adjustment, we will have to devise something more subtle than just an offset, so we will have to redesign

I think offset + scaling factor.

Quoted 3 lines

posix clocks support anyway. Maybe clock_gettime(CLOCK_REALTIME) will then always be a syscall. After all, rt_timer_read is a syscall. If you want the fast clock, use CLOCK_MONOTONIC or rt_timer_tsc.

Actually, the issue of the intermediate approach starts earlier: as soon as you have clock_settime. Then you need to sync the offset across applications in different processes.

Quoted 6 lines

Having clock_monotonic (and maybe also rt_timer_tsc2ns) as a fast variant already now is not bad. But beyond that, before introducing a new interface between kernel and user space, I would like to consider the effort to get it future-proof immediately. That doesn't mean that we already have to implement clock adjustment, but we may already prepare the prerequisites.

Quoted 5 lines

Ok. Here is a new version that does not break the ABI, and where clock_gettime(CLOCK_REALTIME) remains a syscall.

Note that it also adds user-space conversions between tsc and ns to the native skin.

This one is actually tested.

Signature · 1 line
					    Gilles Chanteperdrix.
asm-ia64/Makefile.in +3 -1
Index: include/asm-ia64/Makefile.in
===================================================================
@@ -230,7 +230,9 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-ia64
-includesub_HEADERS = atomic.h calibration.h features.h hal.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
+
 SUBDIRS = bits
 all: all-recursive
 
asm-ia64/Makefile.am +2 -1
Index: include/asm-ia64/Makefile.am
===================================================================
@@ -1,5 +1,6 @@
 includesubdir = $(includedir)/asm-ia64
 
-includesub_HEADERS = atomic.h calibration.h features.h hal.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-ia64/arith.h +6 -0
Index: include/asm-ia64/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_IA64_ARITH_H
+#define _XENO_ASM_IA64_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_IA64_ARITH_H */
asm-blackfin/Makefile.in +2 -2
Index: include/asm-blackfin/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-blackfin
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-blackfin/Makefile.am +2 -2
Index: include/asm-blackfin/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-blackfin
 
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-blackfin/arith.h +6 -0
Index: include/asm-blackfin/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_BLACKFIN_ARITH_H
+#define _XENO_ASM_BLACKFIN_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_BLACKFIN_ARITH_H */
asm-generic/syscall.h +0 -1
Index: include/asm-generic/syscall.h
===================================================================
@@ -55,7 +55,6 @@
 
     unsigned long long cpufreq;	/* CPU frequency */
     unsigned long tickval;	/* Tick duration (ns) */
-
 } xnsysinfo_t;
 
 #define SIGHARDEN  SIGWINCH
asm-generic/bits/bind.h +2 -2
Index: include/asm-generic/bits/bind.h
===================================================================
@@ -62,7 +62,7 @@
 	sa.sa_flags = 0;
 	sigaction(SIGXCPU, &sa, NULL);
 
-	return __xn_mux_shifted_id(muxid);
+	return muxid;
 }
 
 static inline int
@@ -105,7 +105,7 @@
 		exit(1);
 	}
 
-	return __xn_mux_shifted_id(muxid);
+	return muxid;
 }
 
 #endif /* _XENO_ASM_GENERIC_BITS_BIND_H */
asm-generic/Makefile.in +1 -1
Index: include/asm-generic/Makefile.in
===================================================================
@@ -230,7 +230,7 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-generic
-includesub_HEADERS = features.h hal.h syscall.h system.h wrappers.h
+includesub_HEADERS = arith.h features.h hal.h syscall.h system.h wrappers.h
 SUBDIRS = bits
 all: all-recursive
 
asm-generic/Makefile.am +1 -1
Index: include/asm-generic/Makefile.am
===================================================================
@@ -1,5 +1,5 @@
 includesubdir = $(includedir)/asm-generic
 
-includesub_HEADERS = features.h hal.h syscall.h system.h wrappers.h
+includesub_HEADERS = arith.h features.h hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-generic/hal.h +1 -116

130 lines not on this page · raw message

asm-generic/system.h +0 -12
Index: include/asm-generic/system.h
===================================================================
@@ -133,18 +133,6 @@
 #define xnarch_logerr(fmt,args...)   printk(KERN_ERR XNARCH_PROMPT fmt , ##args)
 #define xnarch_printf(fmt,args...)   printk(KERN_INFO XNARCH_PROMPT fmt , ##args)
 
-#define xnarch_ullmod(ull,uld,rem)   ({ xnarch_ulldiv(ull,uld,rem); (*rem); })
-#define xnarch_uldiv(ull, d)         rthal_uldivrem(ull, d, NULL)
-#define xnarch_ulmod(ull, d)         ({ u_long _rem;                    \
-                                        rthal_uldivrem(ull,d,&_rem); _rem; })
-
-#define xnarch_ullmul                rthal_ullmul
-#define xnarch_uldivrem              rthal_uldivrem
-#define xnarch_ulldiv                rthal_ulldiv
-#define xnarch_imuldiv               rthal_imuldiv
-#define xnarch_llimd                 rthal_llimd
-#define xnarch_get_cpu_tsc           rthal_rdtsc
-
 typedef cpumask_t xnarch_cpumask_t;
 
 #ifdef CONFIG_SMP
asm-generic/arith.h +172 -0

172 lines not on this page · raw message

asm-powerpc/Makefile.in +2 -2
Index: include/asm-powerpc/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-powerpc
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-powerpc/Makefile.am +2 -2
Index: include/asm-powerpc/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-powerpc
 
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-powerpc/arith.h +6 -0
Index: include/asm-powerpc/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_POWERPC_ARITH_H
+#define _XENO_ASM_POWERPC_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_POWERPC_ARITH_H */
asm-arm/Makefile.in +2 -2
Index: include/asm-arm/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-arm
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-arm/Makefile.am +2 -2
Index: include/asm-arm/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-arm
 
-includesub_HEADERS = atomic.h calibration.h features.h hal.h \
-		syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-arm/arith.h +6 -0
Index: include/asm-arm/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_ARM_ARITH_H
+#define _XENO_ASM_ARM_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_ARM_ARITH_H */
posix/syscall.h +5 -0
Index: include/posix/syscall.h
===================================================================
@@ -100,6 +100,11 @@
 #define __pse51_condattr_setpshared   74
 #define __pse51_thread_getschedparam  75
 
+typedef struct pse51_sysinfo {
+	unsigned period;
+	unsigned long long wallclock_offset;
+} pse51_sysinfo_t;
+
 #ifdef __KERNEL__
 
 #ifdef __cplusplus
asm-i386/Makefile.in +2 -2
Index: include/asm-i386/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-i386
-includesub_HEADERS = atomic.h calibration.h features.h \
-		hal.h smi.h switch.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h smi.h switch.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-i386/Makefile.am +2 -2
Index: include/asm-i386/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-i386
 
-includesub_HEADERS = atomic.h calibration.h features.h \
-		hal.h smi.h switch.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h smi.h switch.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-i386/hal.h +0 -65

71 lines not on this page · raw message

asm-i386/arith.h +107 -0

107 lines not on this page · raw message

asm-x86_64/Makefile.in +2 -2
Index: include/asm-x86_64/Makefile.in
===================================================================
@@ -230,8 +230,8 @@
 target_os = @target_os@
 target_vendor = @target_vendor@
 includesubdir = $(includedir)/asm-x86_64
-includesub_HEADERS = atomic.h smi.h switch.h calibration.h features.h \
-		hal.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h smi.h switch.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
 all: all-recursive
asm-x86_64/Makefile.am +2 -2
Index: include/asm-x86_64/Makefile.am
===================================================================
@@ -1,6 +1,6 @@
 includesubdir = $(includedir)/asm-x86_64
 
-includesub_HEADERS = atomic.h smi.h switch.h calibration.h features.h \
-		hal.h syscall.h system.h wrappers.h fptest.h
+includesub_HEADERS = arith.h atomic.h calibration.h features.h fptest.h \
+		hal.h smi.h switch.h syscall.h system.h wrappers.h
 
 SUBDIRS = bits
asm-x86_64/arith.h +6 -0
Index: include/asm-x86_64/arith.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef _XENO_ASM_X86_64_ARITH_H
+#define _XENO_ASM_X86_64_ARITH_H
+
+#include <asm-generic/xenomai/arith.h>
+
+#endif /* _XENO_ASM_X86_64_ARITH_H */
skins/psos+/init.c +1 -0
Index: src/skins/psos+/init.c
===================================================================
@@ -27,6 +27,7 @@
 {
 	__psos_muxid =
 	    xeno_bind_skin(PSOS_SKIN_MAGIC, "psos", "xeno_psos");
+	__psos_muxid = __xn_mux_shifted_id(__psos_muxid);
 }
 
 void k_fatal(u_long err_code, u_long flags)
skins/rtai/init.c +1 -0
Index: src/skins/rtai/init.c
===================================================================
@@ -30,4 +30,5 @@
 {
 	__rtai_muxid =
 	    xeno_bind_skin(RTAI_SKIN_MAGIC, "RTAI", "xeno_rtai");
+	__rtai_muxid = __xn_mux_shifted_id(__rtai_muxid);
 }
skins/posix/init.c +8 -1
Index: src/skins/posix/init.c
===================================================================
@@ -35,6 +35,7 @@
 static int fork_handler_registered;
 
 int __wrap_pthread_setschedparam(pthread_t, int, const struct sched_param *);
+void pse51_clock_init(int);
 
 static __attribute__ ((constructor))
 void __init_posix_interface(void)
@@ -42,9 +43,15 @@
 	struct sched_param parm;
 	int muxid, err;
 
-	__pse51_muxid =
+	muxid =
 	    xeno_bind_skin(PSE51_SKIN_MAGIC, "POSIX", "xeno_posix");
 
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+	pse51_clock_init(muxid);
+#endif /* CONFIG_XENO_HW_DIRECT_TSC */
+	
+	__pse51_muxid = __xn_mux_shifted_id(muxid);
+
 	muxid = XENOMAI_SYSBIND(RTDM_SKIN_MAGIC,
 				XENOMAI_FEAT_DEP, XENOMAI_ABI_REV, NULL);
 	if (muxid > 0) {
skins/posix/clock.c +33 -4
Index: src/skins/posix/clock.c
===================================================================
@@ -20,9 +20,24 @@
 #include <pthread.h>		/* For pthread_setcanceltype. */
 #include <posix/syscall.h>
 #include <time.h>
+#include <asm/xenomai/arith.h>
 
 extern int __pse51_muxid;
 
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+static xnsysinfo_t sysinfo;
+
+void pse51_clock_init(int muxid)
+{
+	int err = -XENOMAI_SYSCALL2(__xn_sys_info, muxid, &sysinfo);
+	if (err) {
+		fprintf(stderr, "Xenomai Posix skin init: "
+			"sys_info: %s\n", strerror(err));
+		exit(EXIT_FAILURE);
+	}
+}
+#endif /* CONFIG_XENO_HW_DIRECT_TSC */
+
 int __wrap_clock_getres(clockid_t clock_id, struct timespec *tp)
 {
 	int err = -XENOMAI_SKINCALL2(__pse51_muxid,
@@ -39,11 +54,25 @@
 
 int __wrap_clock_gettime(clockid_t clock_id, struct timespec *tp)
 {
-	int err = -XENOMAI_SKINCALL2(__pse51_muxid,
-				     __pse51_clock_gettime,
-				     clock_id,
-				     tp);
+	int err;
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+	if (clock_id == CLOCK_MONOTONIC) {
+		unsigned long long tsc, ns;
+		unsigned long rem;
 
+		tsc = __xn_rdtsc();
+		ns = xnarch_llimd(tsc, 1000000000, sysinfo.cpufreq);
+		tp->tv_sec = xnarch_ulldiv(ns, 1000000000, &rem);
+		tp->tv_nsec = rem;
+		return 0;
+	}
+#endif /* CONFIG_XENO_HW_DIRECT_TSC */
+
+	err = -XENOMAI_SKINCALL2(__pse51_muxid,
+				 __pse51_clock_gettime,
+				 clock_id,
+				 tp);
+
 	if (!err)
 		return 0;
 
skins/vrtx/init.c +1 -0
Index: src/skins/vrtx/init.c
===================================================================
@@ -43,6 +43,7 @@
 
 	__vrtx_muxid =
 	    xeno_bind_skin(VRTX_SKIN_MAGIC, "vrtx", "xeno_vrtx");
+	__vrtx_muxid = __xn_mux_shifted_id(__vrtx_muxid);
 
 	/* Allocate a TSD key for indexing self task pointers. */
 
skins/vxworks/init.c +1 -0
Index: src/skins/vxworks/init.c
===================================================================
@@ -41,6 +41,7 @@
 {
 	__vxworks_muxid = xeno_bind_skin(VXWORKS_SKIN_MAGIC,
 					 "vxworks", "xeno_vxworks");
+	__vxworks_muxid = __xn_mux_shifted_id(__vxworks_muxid);
 
 	/* Allocate a TSD key for indexing self task pointers. */
 
skins/native/init.c +7 -0
Index: src/skins/native/init.c
===================================================================
@@ -30,6 +30,7 @@
 pthread_key_t __native_tskey;
 
 int __native_muxid = -1;
+void native_timer_init(int);
 
 static void __flush_tsd(void *tsd)
 {
@@ -43,6 +44,12 @@
 	__native_muxid =
 	    xeno_bind_skin(XENO_SKIN_MAGIC, "native", "xeno_native");
 
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+	native_timer_init(__native_muxid);
+#endif /* CONFIG_XENO_HW_DIRECT_TSC */
+	
+	__native_muxid = __xn_mux_shifted_id(__native_muxid);
+
 	/* Allocate a TSD key for indexing self task pointers. */
 
 	if (pthread_key_create(&__native_tskey, &__flush_tsd) != 0) {
skins/native/timer.c +23 -0
Index: src/skins/native/timer.c
===================================================================
@@ -18,9 +18,24 @@
 
 #include <native/syscall.h>
 #include <native/timer.h>
+#include <asm/xenomai/arith.h>
 
 extern int __native_muxid;
 
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+static xnsysinfo_t sysinfo;
+
+void native_timer_init(int muxid)
+{
+	int err = XENOMAI_SYSCALL2(__xn_sys_info, muxid, &sysinfo);
+	if (err) {
+		fprintf(stderr, "Native skin init: "
+			"sys_info: %s\n", strerror(-err));
+		exit(EXIT_FAILURE);
+	}
+}
+#endif /* CONFIG_XENO_HW_DIRECT_TSC */
+
 int rt_timer_set_mode(RTIME tickval)
 {
 	return XENOMAI_SKINCALL1(__native_muxid, __native_timer_set_mode,
@@ -68,7 +83,11 @@
 {
 	RTIME ticks;
 
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+	ticks = xnarch_llimd(ns, sysinfo.cpufreq, 1000000000);
+#else /* !CONFIG_XENO_HW_DIRECT_TSC */
 	XENOMAI_SKINCALL2(__native_muxid, __native_timer_ns2tsc, &ticks, &ns);
+#endif /* !CONFIG_XENO_HW_DIRECT_TSC */
 	return ticks;
 }
 
@@ -76,7 +95,11 @@
 {
 	SRTIME ns;
 
+#ifdef CONFIG_XENO_HW_DIRECT_TSC
+	ns = xnarch_llimd(ticks, 1000000000, sysinfo.cpufreq);
+#else /* !CONFIG_XENO_HW_DIRECT_TSC */
 	XENOMAI_SKINCALL2(__native_muxid, __native_timer_tsc2ns, &ns, &ticks);
+#endif /* !CONFIG_XENO_HW_DIRECT_TSC */
 	return ns;
 }
 
skins/rtdm/init.c +2 -0
Index: src/skins/rtdm/init.c
===================================================================
@@ -34,4 +34,6 @@
 
 	__rtdm_muxid =
 		xeno_bind_skin_opt(RTDM_SKIN_MAGIC, "rtdm", "xeno_rtdm");
+	__rtdm_muxid = __xn_mux_shifted_id(__rtdm_muxid);
+
 }
skins/posix/syscall.c +1 -1
Index: ksrc/skins/posix/syscall.c
===================================================================
@@ -2891,7 +2891,7 @@
 
 		return NULL;
 	}
-	
+
 	return ERR_PTR(-EINVAL);
 }
 
#8 lore raw
Quoted 42 lines · Gilles Chanteperdrix
Quoted 41 lines · Gilles Chanteperdrix
Quoted 39 lines · Jan Kiszka
Quoted 13 lines · Gilles Chanteperdrix
Quoted 12 lines · Jan Kiszka
Quoted 11 lines · Gilles Chanteperdrix
Quoted 9 lines · Jan Kiszka
Quoted 5 lines · Gilles Chanteperdrix

Hi,

here comes, for review, a patch which reduces the overhead of clock_gettime by directly reading the tsc in user-space for architectures that support it.

Highly welcome. But I have one concern: How and when do you propagate wallclock_offset changes to user space?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Since clock_settime is not implemented, never, but if clock_settime was implemented, clock_settime would re-issue the __xn_sys_info syscall.

This excludes automatic clock adjustment, something I'm convinced we will have to provide in the future.

When we provide automatic clock adjustment, we will have to devise something more subtle than just an offset, so we will have to redesign

I think offset + scaling factor.

Quoted 3 lines

posix clocks support anyway. Maybe clock_gettime(CLOCK_REALTIME) will then always be a syscall. After all, rt_timer_read is a syscall. If you want the fast clock, use CLOCK_MONOTONIC or rt_timer_tsc.

Actually, the issue of the intermediate approach starts earlier: as soon as you have clock_settime. Then you need to sync the offset across applications in different processes.

Having clock_monotonic (and maybe also rt_timer_tsc2ns) as a fast variant already now is not bad. But beyond that, before introducing a new interface between kernel and user space, I would like to consider the effort to get it future-proof immediately. That doesn't mean that we already have to implement clock adjustment, but we may already prepare the prerequisites.

Quoted 8 lines
Quoted 5 lines

Ok. Here is a new version that does not break the ABI, and where clock_gettime(CLOCK_REALTIME) remains a syscall.

Note that it also adds user-space conversions between tsc and ns to the native skin.

This one is actually tested.

Looks good to me, builds and runs fine here.

Jan