Unverified Commit ad5d1122 authored by Vincent Chen's avatar Vincent Chen Committed by Palmer Dabbelt
Browse files

riscv: use vDSO common flow to reduce the latency of the time-related functions



Even if RISC-V has supported the vDSO feature, the latency of the functions
for obtaining the system time is still expensive. It is because these
functions still trigger a corresponding system call in the process, which
slows down the response time. If we want to remove the system call to
reduce the latency, the kernel should have the ability to output the system
clock information to userspace. This patch introduces the vDSO common flow
to enable the kernel to achieve the above feature and uses "rdtime"
instruction to obtain the current time in the user space. Under this
condition, the latency cost by the ecall from U-mode to S-mode can be
eliminated. After applying this patch, the latency of gettimeofday()
measured on the HiFive unleashed board can be reduced by %61.

Signed-off-by: default avatarVincent Chen <vincent.chen@sifive.com>
Reviewed-by: default avatarAtish Patra <atish.patra@wdc.com>
Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
parent 05589dde
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ config 32BIT

config RISCV
	def_bool y
	select ARCH_CLOCKSOURCE_INIT
	select ARCH_HAS_BINFMT_FLAT
	select ARCH_HAS_DEBUG_VIRTUAL if MMU
	select ARCH_HAS_DEBUG_WX
@@ -31,6 +32,7 @@ config RISCV
	select GENERIC_ARCH_TOPOLOGY if SMP
	select GENERIC_ATOMIC64 if !64BIT
	select GENERIC_CLOCKEVENTS
	select GENERIC_GETTIMEOFDAY if HAVE_GENERIC_VDSO
	select GENERIC_IOREMAP
	select GENERIC_IRQ_MULTI_HANDLER
	select GENERIC_IRQ_SHOW
@@ -40,6 +42,7 @@ config RISCV
	select GENERIC_SMP_IDLE_THREAD
	select GENERIC_STRNCPY_FROM_USER if MMU
	select GENERIC_STRNLEN_USER if MMU
	select GENERIC_TIME_VSYSCALL if MMU && 64BIT
	select HANDLE_DOMAIN_IRQ
	select HAVE_ARCH_AUDITSYSCALL
	select HAVE_ARCH_KASAN if MMU && 64BIT
@@ -53,6 +56,7 @@ config RISCV
	select HAVE_DMA_CONTIGUOUS if MMU
	select HAVE_EBPF_JIT if MMU
	select HAVE_FUTEX_CMPXCHG if FUTEX
	select HAVE_GENERIC_VDSO if MMU && 64BIT
	select HAVE_PCI
	select HAVE_PERF_EVENTS
	select HAVE_PERF_REGS
+7 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_CLOCKSOURCE_H
#define _ASM_CLOCKSOURCE_H

#include <asm/vdso/clocksource.h>

#endif
+2 −10
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@

#include <linux/const.h>

#include <vdso/processor.h>

#include <asm/ptrace.h>

/*
@@ -58,16 +60,6 @@ static inline void release_thread(struct task_struct *dead_task)
extern unsigned long get_wchan(struct task_struct *p);


static inline void cpu_relax(void)
{
#ifdef __riscv_muldiv
	int dummy;
	/* In lieu of a halt instruction, induce a long-latency stall. */
	__asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy));
#endif
	barrier();
}

static inline void wait_for_interrupt(void)
{
	__asm__ __volatile__ ("wfi");
+2 −0
Original line number Diff line number Diff line
@@ -10,8 +10,10 @@

#include <linux/types.h>

#ifndef GENERIC_TIME_VSYSCALL
struct vdso_data {
};
#endif

/*
 * The VDSO symbols are mapped into Linux so we can just use regular symbol
+8 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __ASM_VDSOCLOCKSOURCE_H
#define __ASM_VDSOCLOCKSOURCE_H

#define VDSO_ARCH_CLOCKMODES	\
	VDSO_CLOCKMODE_ARCHTIMER

#endif
Loading