@@ -10,25 +10,45 @@
int __vdso_clock_gettime(clockid_t clock,
struct old_timespec32 *ts)
{
- return __cvdso_clock_gettime32(clock, ts);
+ int ret = __cvdso_clock_gettime32(clock, ts);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_gettime32_fallback(clock, &ts);
}
int __vdso_clock_gettime64(clockid_t clock,
struct __kernel_timespec *ts)
{
- return __cvdso_clock_gettime(clock, ts);
+ int ret = __cvdso_clock_gettime(clock, ts);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_gettime_fallback(clock, ts);
}
int __vdso_gettimeofday(struct __kernel_old_timeval *tv,
struct timezone *tz)
{
- return __cvdso_gettimeofday(tv, tz);
+ int ret = __cvdso_gettimeofday(tv, tz);
+
+ if (likely(!ret))
+ return ret;
+
+ return gettimeofday_fallback(tv, tz);
}
int __vdso_clock_getres(clockid_t clock_id,
struct old_timespec32 *res)
{
- return __cvdso_clock_getres_time32(clock_id, res);
+ int ret = __cvdso_clock_getres_time32(clock_id, res);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_getres32_fallback(clock, res);
}
/* Avoid unresolved references emitted by GCC */
@@ -11,17 +11,32 @@
int __kernel_clock_gettime(clockid_t clock,
struct __kernel_timespec *ts)
{
- return __cvdso_clock_gettime(clock, ts);
+ int ret = __cvdso_clock_gettime(clock, ts);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_gettime_fallback(clock, ts);
}
int __kernel_gettimeofday(struct __kernel_old_timeval *tv,
struct timezone *tz)
{
- return __cvdso_gettimeofday(tv, tz);
+ int ret = __cvdso_gettimeofday(tv, tz);
+
+ if (likely(!ret))
+ return ret;
+
+ return gettimeofday_fallback(tv, tz);
}
int __kernel_clock_getres(clockid_t clock_id,
struct __kernel_timespec *res)
{
- return __cvdso_clock_getres(clock_id, res);
+ int ret = __cvdso_clock_getres(clock_id, res);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_getres_fallback(clock, res);
}
@@ -11,37 +11,64 @@
int __vdso_clock_gettime(clockid_t clock,
struct old_timespec32 *ts)
{
+ int ret;
+
/* The checks below are required for ABI consistency with arm */
if ((u32)ts >= TASK_SIZE_32)
return -EFAULT;
- return __cvdso_clock_gettime32(clock, ts);
+ ret = __cvdso_clock_gettime32(clock, ts);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_gettime32_fallback(clock, &ts);
}
int __vdso_clock_gettime64(clockid_t clock,
struct __kernel_timespec *ts)
{
+ int ret;
+
/* The checks below are required for ABI consistency with arm */
if ((u32)ts >= TASK_SIZE_32)
return -EFAULT;
- return __cvdso_clock_gettime(clock, ts);
+ ret = __cvdso_clock_gettime(clock, ts);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_gettime_fallback(clock, ts);
}
int __vdso_gettimeofday(struct __kernel_old_timeval *tv,
struct timezone *tz)
{
- return __cvdso_gettimeofday(tv, tz);
+ int ret = __cvdso_gettimeofday(tv, tz);
+
+ if (likely(!ret))
+ return ret;
+
+ return gettimeofday_fallback(tv, tz);
}
int __vdso_clock_getres(clockid_t clock_id,
struct old_timespec32 *res)
{
+ int ret;
+ struct __kernel_timespec ts;
+
/* The checks below are required for ABI consistency with arm */
if ((u32)res >= TASK_SIZE_32)
return -EFAULT;
- return __cvdso_clock_getres_time32(clock_id, res);
+ ret = __cvdso_clock_getres_time32(clock_id, res);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_getres32_fallback(clock, res);
}
/* Avoid unresolved references emitted by GCC */
@@ -14,25 +14,45 @@
int __vdso_clock_gettime(clockid_t clock,
struct old_timespec32 *ts)
{
- return __cvdso_clock_gettime32(clock, ts);
+ int ret = __cvdso_clock_gettime32(clock, ts);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_gettime32_fallback(clock, ts);
}
int __vdso_gettimeofday(struct __kernel_old_timeval *tv,
struct timezone *tz)
{
- return __cvdso_gettimeofday(tv, tz);
+ int ret = __cvdso_gettimeofday(tv, tz);
+
+ if (likely(!ret))
+ return ret;
+
+ return gettimeofday_fallback(tv, tz);
}
int __vdso_clock_getres(clockid_t clock_id,
struct old_timespec32 *res)
{
- return __cvdso_clock_getres_time32(clock_id, res);
+ int ret = __cvdso_clock_getres_time32(clock_id, res);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_getres32_fallback(clock, res);
}
int __vdso_clock_gettime64(clockid_t clock,
struct __kernel_timespec *ts)
{
- return __cvdso_clock_gettime(clock, ts);
+ int ret = __cvdso_clock_gettime(clock, ts);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_gettime_fallback(clock, ts);
}
#else
@@ -40,19 +60,34 @@ int __vdso_clock_gettime64(clockid_t clock,
int __vdso_clock_gettime(clockid_t clock,
struct __kernel_timespec *ts)
{
- return __cvdso_clock_gettime(clock, ts);
+ int ret = __cvdso_clock_gettime(clock, ts);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_gettime_fallback(clock, ts);
}
int __vdso_gettimeofday(struct __kernel_old_timeval *tv,
struct timezone *tz)
{
- return __cvdso_gettimeofday(tv, tz);
+ int ret = __cvdso_gettimeofday(tv, tz);
+
+ if (likely(!ret))
+ return ret;
+
+ return gettimeofday_fallback(tv, tz);
}
int __vdso_clock_getres(clockid_t clock_id,
struct __kernel_timespec *res)
{
- return __cvdso_clock_getres(clock_id, res);
+ int ret = __cvdso_clock_getres(clock_id, res);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_getres_fallback(clock, res);
}
#endif
@@ -19,7 +19,12 @@ extern __kernel_old_time_t __vdso_time(__kernel_old_time_t *t);
int __vdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
{
- return __cvdso_gettimeofday(tv, tz);
+ int ret = __cvdso_gettimeofday(tv, tz);
+
+ if (likely(!ret))
+ return ret;
+
+ return gettimeofday_fallback(tv, tz);
}
int gettimeofday(struct __kernel_old_timeval *, struct timezone *)
@@ -40,7 +45,12 @@ extern int __vdso_clock_getres(clockid_t clock, struct __kernel_timespec *res);
int __vdso_clock_gettime(clockid_t clock, struct __kernel_timespec *ts)
{
- return __cvdso_clock_gettime(clock, ts);
+ int ret = __cvdso_clock_gettime(clock, ts);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_gettime_fallback(clock, ts);
}
int clock_gettime(clockid_t, struct __kernel_timespec *)
@@ -49,7 +59,12 @@ int clock_gettime(clockid_t, struct __kernel_timespec *)
int __vdso_clock_getres(clockid_t clock,
struct __kernel_timespec *res)
{
- return __cvdso_clock_getres(clock, res);
+ int ret = __cvdso_clock_getres(clock_id, res);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_getres_fallback(clock, res);
}
int clock_getres(clockid_t, struct __kernel_timespec *)
__attribute__((weak, alias("__vdso_clock_getres")));
@@ -61,7 +76,12 @@ extern int __vdso_clock_getres(clockid_t clock, struct old_timespec32 *res);
int __vdso_clock_gettime(clockid_t clock, struct old_timespec32 *ts)
{
- return __cvdso_clock_gettime32(clock, ts);
+ int ret = __cvdso_clock_gettime32(clock, ts);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_gettime32_fallback(clock, ts);
}
int clock_gettime(clockid_t, struct old_timespec32 *)
@@ -69,7 +89,12 @@ int clock_gettime(clockid_t, struct old_timespec32 *)
int __vdso_clock_gettime64(clockid_t clock, struct __kernel_timespec *ts)
{
- return __cvdso_clock_gettime(clock, ts);
+ int ret = __cvdso_clock_gettime(clock, ts);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_gettime_fallback(clock, ts);
}
int clock_gettime64(clockid_t, struct __kernel_timespec *)
@@ -77,7 +102,12 @@ int clock_gettime64(clockid_t, struct __kernel_timespec *)
int __vdso_clock_getres(clockid_t clock, struct old_timespec32 *res)
{
- return __cvdso_clock_getres_time32(clock, res);
+ int ret = __cvdso_clock_getres_time32(clock, res);
+
+ if (likely(!ret))
+ return ret;
+
+ return clock_getres32_fallback(clock, res);
}
int clock_getres(clockid_t, struct old_timespec32 *)
@@ -16,9 +16,6 @@
* - __arch_get_vdso_data(): to get the vdso datapage.
* - __arch_get_hw_counter(): to get the hw counter based on the
* clock_mode.
- * - gettimeofday_fallback(): fallback for gettimeofday.
- * - clock_gettime_fallback(): fallback for clock_gettime.
- * - clock_getres_fallback(): fallback for clock_getres.
*/
#ifdef ENABLE_COMPAT_VDSO
#include <asm/vdso/compat_gettimeofday.h>
@@ -110,23 +107,14 @@ __cvdso_clock_gettime_common(clockid_t clock, struct __kernel_timespec *ts)
static __maybe_unused int
__cvdso_clock_gettime(clockid_t clock, struct __kernel_timespec *ts)
{
- int ret = __cvdso_clock_gettime_common(clock, ts);
-
- if (unlikely(ret))
- return clock_gettime_fallback(clock, ts);
- return 0;
+ return __cvdso_clock_gettime_common(clock, ts);
}
static __maybe_unused int
__cvdso_clock_gettime32(clockid_t clock, struct old_timespec32 *res)
{
struct __kernel_timespec ts;
- int ret;
-
- ret = __cvdso_clock_gettime_common(clock, &ts);
-
- if (unlikely(ret))
- return clock_gettime32_fallback(clock, res);
+ int ret = __cvdso_clock_gettime_common(clock, &ts);
if (likely(!ret)) {
res->tv_sec = ts.tv_sec;
@@ -144,7 +132,7 @@ __cvdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
struct __kernel_timespec ts;
if (do_hres(&vd[CS_HRES_COARSE], CLOCK_REALTIME, &ts))
- return gettimeofday_fallback(tv, tz);
+ return -1;
tv->tv_sec = ts.tv_sec;
tv->tv_usec = (u32)ts.tv_nsec / NSEC_PER_USEC;
@@ -218,23 +206,14 @@ int __cvdso_clock_getres_common(clockid_t clock, struct __kernel_timespec *res)
int __cvdso_clock_getres(clockid_t clock, struct __kernel_timespec *res)
{
- int ret = __cvdso_clock_getres_common(clock, res);
-
- if (unlikely(ret))
- return clock_getres_fallback(clock, res);
- return 0;
+ return __cvdso_clock_getres_common(clock, res);
}
static __maybe_unused int
__cvdso_clock_getres_time32(clockid_t clock, struct old_timespec32 *res)
{
struct __kernel_timespec ts;
- int ret;
-
- ret = __cvdso_clock_getres_common(clock, &ts);
-
- if (unlikely(ret))
- return clock_getres32_fallback(clock, res);
+ int ret = __cvdso_clock_getres_common(clock, &ts);
if (likely(!ret && res)) {
res->tv_sec = ts.tv_sec;
On powerpc, VDSO functions and syscalls cannot be implemented in C because the Linux kernel ABI requires that CR[SO] bit is set in case of error and cleared when no error. As this cannot be done in C, C VDSO functions and syscall'based fallback need a trampoline in ASM. By moving the fallback calls out of the common code, arches like powerpc can implement both the call to C VDSO and the fallback call in a single trampoline function. The two advantages are: - No need play back and forth with CR[SO] and negative return value. - No stack frame is required in VDSO C functions for the fallbacks. The performance improvement is significant on powerpc. Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> --- arch/arm/vdso/vgettimeofday.c | 28 +++++++++++++++--- arch/arm64/kernel/vdso/vgettimeofday.c | 21 ++++++++++++-- arch/arm64/kernel/vdso32/vgettimeofday.c | 35 ++++++++++++++++++++--- arch/mips/vdso/vgettimeofday.c | 49 +++++++++++++++++++++++++++----- arch/x86/entry/vdso/vclock_gettime.c | 42 +++++++++++++++++++++++---- lib/vdso/gettimeofday.c | 31 ++++---------------- 6 files changed, 156 insertions(+), 50 deletions(-)