Skip to content

Commit 0b523a8

Browse files
Goran Ferencralfbaechle
authored andcommitted
MIPS: VDSO: Add implementation of gettimeofday() fallback
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 <[email protected]> Signed-off-by: Miodrag Dinic <[email protected]> Signed-off-by: Aleksandar Markovic <[email protected]> Cc: Douglas Leung <[email protected]> Cc: James Hogan <[email protected]> Cc: Paul Burton <[email protected]> Cc: Petar Jovanovic <[email protected]> Cc: Raghu Gandham <[email protected]> Cc: [email protected] Cc: [email protected] Patchwork: https://patchwork.linux-mips.org/patch/16640/ Signed-off-by: Ralf Baechle <[email protected]>
1 parent 180902e commit 0b523a8

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

arch/mips/vdso/gettimeofday.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@
2020
#include <asm/unistd.h>
2121
#include <asm/vdso.h>
2222

23+
#ifdef CONFIG_MIPS_CLOCK_VSYSCALL
24+
25+
static __always_inline long gettimeofday_fallback(struct timeval *_tv,
26+
struct timezone *_tz)
27+
{
28+
register struct timezone *tz asm("a1") = _tz;
29+
register struct timeval *tv asm("a0") = _tv;
30+
register long ret asm("v0");
31+
register long nr asm("v0") = __NR_gettimeofday;
32+
register long error asm("a3");
33+
34+
asm volatile(
35+
" syscall\n"
36+
: "=r" (ret), "=r" (error)
37+
: "r" (tv), "r" (tz), "r" (nr)
38+
: "memory");
39+
40+
return error ? -ret : ret;
41+
}
42+
43+
#endif
44+
2345
static __always_inline long clock_gettime_fallback(clockid_t _clkid,
2446
struct timespec *_ts)
2547
{
@@ -205,7 +227,7 @@ int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
205227

206228
ret = do_realtime(&ts, data);
207229
if (ret)
208-
return ret;
230+
return gettimeofday_fallback(tv, tz);
209231

210232
if (tv) {
211233
tv->tv_sec = ts.tv_sec;

0 commit comments

Comments
 (0)