summaryrefslogtreecommitdiffstats
path: root/cpukit/score
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2016-08-17 09:52:09 +0000
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-10-12 07:04:11 +0200
commit748871578c3dd0077e1f1de246993c80424ab63b (patch)
tree98652e605f20a21010ce262cb3b468b6f9c2b1a9 /cpukit/score
parenttimecounter: Merge FreeBSD change r303548 (diff)
downloadrtems-748871578c3dd0077e1f1de246993c80424ab63b.tar.bz2
timecounter: Merge FreeBSD change r304285
Implement userspace gettimeofday(2) with HPET timecounter. Right now, userspace (fast) gettimeofday(2) on x86 only works for RDTSC. For older machines, like Core2, where RDTSC is not C2/C3 invariant, and which fall to HPET hardware, this means that the call has both the penalty of the syscall and of the uncached hw behind the QPI or PCIe connection to the sought bridge. Nothing can me done against the access latency, but the syscall overhead can be removed. System already provides mappable /dev/hpetX devices, which gives straight access to the HPET registers page. Add yet another algorithm to the x86 'vdso' timehands. Libc is updated to handle both RDTSC and HPET. For HPET, the index of the hpet device to mmap is passed from kernel to userspace, index might be changed and libc invalidates its mapping as needed. Remove cpu_fill_vdso_timehands() KPI, instead require that timecounters which can be used from userspace, to provide tc_fill_vdso_timehands{,32}() methods. Merge i386 and amd64 libc/<arch>/sys/__vdso_gettc.c into one source file in the new libc/x86/sys location. __vdso_gettc() internal interface is changed to move timecounter algorithm detection into the MD code. Measurements show that RDTSC even with the syscall overhead is faster than userspace HPET access. But still, userspace HPET is three-four times faster than syscall HPET on several Core2 and SandyBridge machines. Tested by: Howard Su <howard0su@gmail.com> Sponsored by: The FreeBSD Foundation MFC after: 1 month Differential revision: https://reviews.freebsd.org/D7473 Update #3175.
Diffstat (limited to 'cpukit/score')
-rw-r--r--cpukit/score/include/sys/timetc.h14
-rw-r--r--cpukit/score/src/kern_tc.c19
2 files changed, 28 insertions, 5 deletions
diff --git a/cpukit/score/include/sys/timetc.h b/cpukit/score/include/sys/timetc.h
index 73e63f7333..361535c0c8 100644
--- a/cpukit/score/include/sys/timetc.h
+++ b/cpukit/score/include/sys/timetc.h
@@ -30,8 +30,18 @@
*/
struct timecounter;
+struct vdso_timehands;
+struct vdso_timehands32;
+#ifndef __rtems__
+typedef u_int timecounter_get_t(struct timecounter *);
+#else /* __rtems__ */
typedef uint32_t timecounter_get_t(struct timecounter *);
+#endif /* __rtems__ */
typedef void timecounter_pps_t(struct timecounter *);
+typedef uint32_t timecounter_fill_vdso_timehands_t(struct vdso_timehands *,
+ struct timecounter *);
+typedef uint32_t timecounter_fill_vdso_timehands32_t(struct vdso_timehands32 *,
+ struct timecounter *);
struct timecounter {
timecounter_get_t *tc_get_timecount;
@@ -70,6 +80,10 @@ struct timecounter {
/* Pointer to the timecounter's private parts. */
struct timecounter *tc_next;
/* Pointer to the next timecounter. */
+#ifndef __rtems__
+ timecounter_fill_vdso_timehands_t *tc_fill_vdso_timehands;
+ timecounter_fill_vdso_timehands32_t *tc_fill_vdso_timehands32;
+#endif /* __rtems__ */
};
extern struct timecounter *timecounter;
diff --git a/cpukit/score/src/kern_tc.c b/cpukit/score/src/kern_tc.c
index 78e1308188..272461d9b4 100644
--- a/cpukit/score/src/kern_tc.c
+++ b/cpukit/score/src/kern_tc.c
@@ -6,11 +6,14 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * Copyright (c) 2011 The FreeBSD Foundation
+ * Copyright (c) 2011, 2015, 2016 The FreeBSD Foundation
* All rights reserved.
*
* Portions of this software were developed by Julien Ridoux at the University
* of Melbourne under sponsorship from the FreeBSD Foundation.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
*/
#ifdef __rtems__
@@ -2388,13 +2391,16 @@ tc_fill_vdso_timehands(struct vdso_timehands *vdso_th)
uint32_t enabled;
th = timehands;
- vdso_th->th_algo = VDSO_TH_ALGO_1;
vdso_th->th_scale = th->th_scale;
vdso_th->th_offset_count = th->th_offset_count;
vdso_th->th_counter_mask = th->th_counter->tc_counter_mask;
vdso_th->th_offset = th->th_offset;
vdso_th->th_boottime = th->th_boottime;
- enabled = cpu_fill_vdso_timehands(vdso_th, th->th_counter);
+ if (th->th_counter->tc_fill_vdso_timehands != NULL) {
+ enabled = th->th_counter->tc_fill_vdso_timehands(vdso_th,
+ th->th_counter);
+ } else
+ enabled = 0;
if (!vdso_th_enable)
enabled = 0;
return (enabled);
@@ -2409,7 +2415,6 @@ tc_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32)
uint32_t enabled;
th = timehands;
- vdso_th32->th_algo = VDSO_TH_ALGO_1;
*(uint64_t *)&vdso_th32->th_scale[0] = th->th_scale;
vdso_th32->th_offset_count = th->th_offset_count;
vdso_th32->th_counter_mask = th->th_counter->tc_counter_mask;
@@ -2417,7 +2422,11 @@ tc_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32)
*(uint64_t *)&vdso_th32->th_offset.frac[0] = th->th_offset.frac;
vdso_th32->th_boottime.sec = th->th_boottime.sec;
*(uint64_t *)&vdso_th32->th_boottime.frac[0] = th->th_boottime.frac;
- enabled = cpu_fill_vdso_timehands32(vdso_th32, th->th_counter);
+ if (th->th_counter->tc_fill_vdso_timehands32 != NULL) {
+ enabled = th->th_counter->tc_fill_vdso_timehands32(vdso_th32,
+ th->th_counter);
+ } else
+ enabled = 0;
if (!vdso_th_enable)
enabled = 0;
return (enabled);