Skip to content

Commit

Permalink
MIPS: VDSO: Add implementation of gettimeofday() fallback
Browse files Browse the repository at this point in the history
This patch adds gettimeofday_fallback() function that wraps assembly
invocation of gettimeofday() syscall using __NR_gettimeofday.

This function is used if pure VDSO implementation gettimeofday()
does not succeed for any reason. Its imeplementation is enclosed in
"#ifdef CONFIG_MIPS_CLOCK_VSYSCALL" to be in sync with the similar
arrangement for __vdso_gettimeofday().

If syscall invocation via __NR_gettimeofday fails, register a3 will
be set. So, after the syscall, register a3 is tested and the return
valuem is negated if it's set.

Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Cc: Douglas Leung <douglas.leung@imgtec.com>
Cc: James Hogan <james.hogan@imgtec.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
Cc: Raghu Gandham <raghu.gandham@imgtec.com>
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/16640/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
  • Loading branch information
Goran Ferenc authored and Ralf Baechle committed Jun 29, 2017
1 parent 180902e commit 0b523a8
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion arch/mips/vdso/gettimeofday.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@
#include <asm/unistd.h>
#include <asm/vdso.h>

#ifdef CONFIG_MIPS_CLOCK_VSYSCALL

static __always_inline long gettimeofday_fallback(struct timeval *_tv,
struct timezone *_tz)
{
register struct timezone *tz asm("a1") = _tz;
register struct timeval *tv asm("a0") = _tv;
register long ret asm("v0");
register long nr asm("v0") = __NR_gettimeofday;
register long error asm("a3");

asm volatile(
" syscall\n"
: "=r" (ret), "=r" (error)
: "r" (tv), "r" (tz), "r" (nr)
: "memory");

return error ? -ret : ret;
}

#endif

static __always_inline long clock_gettime_fallback(clockid_t _clkid,
struct timespec *_ts)
{
Expand Down Expand Up @@ -205,7 +227,7 @@ int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)

ret = do_realtime(&ts, data);
if (ret)
return ret;
return gettimeofday_fallback(tv, tz);

if (tv) {
tv->tv_sec = ts.tv_sec;
Expand Down

0 comments on commit 0b523a8

Please sign in to comment.