Skip to contentSkip to conversation

restartable sequences benchmarks

RFC PATCH In review Dave Watson 3 participants 8 messages Oct 22, 2015

Subsystems (11)
x86 VFS Kselftest MM core +7 more subsystems
lore
Share & tools
lore
#0 lore raw

cover restartable sequences benchmarks

We've been testing out restartable sequences + malloc changes for use at Facebook. Below are some test results, as well as some possible changes based on Paul Turner's original patches

https://lkml.org/lkml/2015/6/24/665

I ran one service with several permutations of various mallocs. The service is CPU-bound, and hits the allocator quite hard. Requests/s are held constant at the source, so we use cpu idle time and latency as an indicator of service quality. These are average numbers over several hours. Machines were dual E5-2660, total 16 cores + hyperthreading. This service has ~400 total threads, 70-90 of which are doing work at any particular time.

RSS CPUIDLE LATENCYMS

jemalloc 4.0.0                     31G   33%     390
jemalloc + this patch              25G   33%     390
jemalloc + this patch using lsl    25G   30%     420
jemalloc + PT's rseq patch         25G   32%     405
glibc malloc 2.20                  27G   30%     420
tcmalloc gperftools trunk (2.2)    21G   30%     480

jemalloc rseq patch used for testing:
https://github.com/djwatson/jemalloc

lsl test - using lsl segment limit to get cpu (i.e. inlined vdso getcpu on x86) instead of using the thread caching as in this patch. There has been some suggestions to add the thread-cached getcpu() feature separately. It does seem to move the needle in a real service by about ~3% to have a thread-cached getcpu vs. not. I don't think we can use restartable sequences in production without a faster getcpu.

GS-segment / migration only tests

There's been some interest in seeing if we can do this with only gs segment, here's some numbers for those. This doesn't have to be gs, it could just be a migration signal sent to userspace as well, the same approaches would apply.

GS patch: https://lkml.org/lkml/2014/9/13/59

RSS CPUIDLE LATENCYMS

jemalloc 4.0.0                     31G   33%     390
jemalloc + percpu locking          25G   25%     420
jemalloc + preempt lock / signal   25G   32%     415

* Percpu locking - just lock everything percpu all the time. If scheduled off during the critical section, other threads have to wait.

* 'Preempt lock' idea is that we grab a lock, but if we miss the lock, send a signal to the offending thread (tid is stored in the lock variable) to restart its critical section. Libunwind was used to fixup ips in the signal handler, walking all the frames. This is slower than the kernel preempt check, but happens less often - only if there was a preempt during the critical section. Critical sections were inlined using the same scheme as in this patch. There is more overhead than restartable sequences in the hot path (an extra unlocked cmpxchg, some accounting). Microbenchmarks showed it was 2x slower than rseq, but still faster than atomics.

Roughly like this: https://gist.github.com/djwatson/9c268681a0dfa797990c

* I also tried a percpu version of stm (software transactional memory), but could never write anything better than ~3x slower than atomics in a microbenchmark. I didn't test this in a real service.

Attached are two changes to the original patch:

1) Support more than one critical memory range in the kernel using binary search. This has several advantages:

* We don't need an extra register ABI to support multiplexing them in userspace. This also avoids some complexity knowing which registers/flags might be smashed by a restart.

* There are no collisions between shared libraries

* They can be inlined with gcc inline asm. With optimization on, gcc correctly inlines and registers many more regions. In a real service this does seem to improve latency a hair. A microbenchmark shows ~20% faster.

Downsides: Less control over how we search/jump to the regions, but I didn't notice any difference in testing a reasonable number of regions (less than 100). We could set a max limit?

2) Additional checks in ptrace to single step over critical sections. We also prevent setting breakpoints, as these also seem to confuse gdb sometimes.

Dave Watson (3):
restartable sequences: user-space per-cpu critical sections restartable sequences: x86 ABI
restartable sequences: basic user-space self-tests

 arch/Kconfig                                       |   7 +
 arch/x86/Kconfig                                   |   1 +
 arch/x86/entry/common.c                            |   3 +
 arch/x86/entry/syscalls/syscall_64.tbl             |   1 +
 arch/x86/include/asm/restartable_sequences.h       |  44 +++
 arch/x86/kernel/Makefile                           |   2 +
 arch/x86/kernel/ptrace.c                           |   6 +-
 arch/x86/kernel/restartable_sequences.c            |  47 +++
 arch/x86/kernel/signal.c                           |  12 +-
 fs/exec.c                                          |   3 +-
 include/linux/sched.h                              |  39 +++
 include/uapi/asm-generic/unistd.h                  |   4 +-
 init/Kconfig                                       |   9 +
 kernel/Makefile                                    |   2 +-
 kernel/fork.c                                      |   1 +
 kernel/ptrace.c                                    |  15 +-
 kernel/restartable_sequences.c                     | 255 ++++++++++++++++
 kernel/sched/core.c                                |   5 +
 kernel/sched/sched.h                               |   3 +
 kernel/sys_ni.c                                    |   3 +
 tools/testing/selftests/rseq/Makefile              |  14 +
 .../testing/selftests/rseq/basic_percpu_ops_test.c | 331 +++++++++++++++++++++
 tools/testing/selftests/rseq/rseq.c                |  48 +++
 tools/testing/selftests/rseq/rseq.h                |  17 ++
 24 files changed, 862 insertions(+), 10 deletions(-)
 create mode 100644 arch/x86/include/asm/restartable_sequences.h
 create mode 100644 arch/x86/kernel/restartable_sequences.c
 create mode 100644 kernel/restartable_sequences.c
 create mode 100644 tools/testing/selftests/rseq/Makefile
 create mode 100644 tools/testing/selftests/rseq/basic_percpu_ops_test.c
 create mode 100644 tools/testing/selftests/rseq/rseq.c
 create mode 100644 tools/testing/selftests/rseq/rseq.h
Signature · 1 line
2.4.6
#1 lore raw

RFC PATCH 1/3 restartable sequences: user-space per-cpu critical sections

Introduce the notion of 'restartable sequence'. This is a user-defined range within which we guarantee user-execution will occur serially with respect to scheduling events such as migration or competition with other threads.

Preemption, or other interruption within this region, results in control being transferred to a user-defined restart handler when rescheduled. This handler may arrange for the original operation to be retried, including potentially resynchronizing with dependent state that may have been updated in the interim.

This may be used in combination with an in-memory cpu-id to allow user programs to implement cpu-local data-structures and primitives, without the use/overhead of any atomics.

The kernel ABI generally consists of:
- A critical region, with start, end and restart addresses
- A (per-thread) memory location which will be kept current with its cpu

The definition of the above is performed via a new syscall,
SYSCALL_DEFINE5(restartable_sequences,
int, op, int, flags, long, val1, long, val2, long, val3)

There are currently 2 possible operations,
1) Configure the critical region(s)
2) Configure the per-thread cpu pointer

[ See kernel/restartable_sequences.c for full documentation ]

A thread that has not configured (2) will not be restarted when executing in (1).

This patch introduces the general framework for configuration, as well as exposing the syscall. We minimally expose x86 as having support (even though the actual ABI is added by a subsequent patch) so that this can be compile tested in isolation.

Ptrace is modified to avoid setting a breakpoint in the critical region, since doing so would always restart the critical section, and may not work correctly if the breakpoint is also the restart address.

---
 arch/Kconfig                      |   7 ++
 arch/x86/Kconfig                  |   1 +
 fs/exec.c                         |   3 +-
 include/linux/sched.h             |  39 ++++++
 include/uapi/asm-generic/unistd.h |   4 +-
 init/Kconfig                      |   9 ++
 kernel/Makefile                   |   2 +-
 kernel/fork.c                     |   1 +
 kernel/ptrace.c                   |  15 ++-
 kernel/restartable_sequences.c    | 250 ++++++++++++++++++++++++++++++++++++++
 kernel/sched/core.c               |   5 +
 kernel/sched/sched.h              |   3 +
 kernel/sys_ni.c                   |   3 +
 13 files changed, 335 insertions(+), 7 deletions(-)
 create mode 100644 kernel/restartable_sequences.c
arch/Kconfig +7 -0
index 4e949e5..93c18fa 100644
@@ -241,6 +241,13 @@ config HAVE_REGS_AND_STACK_ACCESS_API
 	  declared in asm/ptrace.h
 	  For example the kprobes-based event tracer needs this API.
 
+config HAVE_RESTARTABLE_SEQUENCE_SUPPORT
+	bool
+	depends on HAVE_REGS_AND_STACK_ACCESS_API
+	help
+	  This symbol should be selected by an architecture if it supports an
+	  implementation of restartable sequences.
+
 config HAVE_CLK
 	bool
 	help
arch/x86/Kconfig +1 -0
index 96d058a..865e795 100644
@@ -112,6 +112,7 @@ config X86
 	select HAVE_IOREMAP_PROT
 	select HAVE_IRQ_EXIT_ON_IRQ_STACK	if X86_64
 	select HAVE_IRQ_TIME_ACCOUNTING
+	select HAVE_RESTARTABLE_SEQUENCE_SUPPORT
 	select HAVE_KERNEL_BZIP2
 	select HAVE_KERNEL_GZIP
 	select HAVE_KERNEL_LZ4
fs/exec.c +2 -1
index b06623a..aa94834 100644
@@ -19,7 +19,7 @@
  * current->executable is only used by the procfs.  This allows a dispatch
  * table to check for several different types  of binary formats.  We keep
  * trying until we recognize the file or we run out of supported binary
- * formats. 
+ * formats.
  */
 
 #include <linux/slab.h>
@@ -1596,6 +1596,7 @@ static int do_execveat_common(int fd, struct filename *filename,
 	current->in_execve = 0;
 	acct_update_integrals(current);
 	task_numa_free(current);
+	rseq_clear_state_exec(current);
 	free_bprm(bprm);
 	kfree(pathbuf);
 	putname(filename);
include/linux/sched.h +39 -0
index b7b9501..a7b6e24 100644
@@ -1182,6 +1182,31 @@ struct mempolicy;
 struct pipe_inode_info;
 struct uts_namespace;
 
+#ifdef CONFIG_RESTARTABLE_SEQUENCES
+struct restartable_sequence_section {
+	/* Start and end of an address space's critical section. */
+	struct rb_node node;
+	void __user *crit_start, __user *crit_end, __user *crit_restart;
+};
+struct restartable_sequence_state {
+	struct rb_root sections;
+	/* Thread's current CPU, typically in TLS. */
+	int __user *cpu_pointer;
+	struct preempt_notifier notifier;
+};
+
+void rseq_clear_state_exec(struct task_struct *p);
+unsigned long rseq_lookup(struct task_struct *p, unsigned long ip);
+#else
+static inline void rseq_clear_state_exec(struct task_struct *p) {}
+static inline void rseq_fork(struct task_struct *p) {}
+static inline unsigned long
+rseq_lookup(struct task_struct *p, unsigned long ip)
+{
+	return 0;
+}
+#endif
+
 struct load_weight {
 	unsigned long weight;
 	u32 inv_weight;
@@ -1811,6 +1836,11 @@ struct task_struct {
 #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
 	unsigned long	task_state_change;
 #endif
+
+#ifdef CONFIG_RESTARTABLE_SEQUENCES
+	struct restartable_sequence_state rseq_state;
+#endif
+
 	int pagefault_disabled;
 /* CPU-specific state of this task */
 	struct thread_struct thread;
@@ -3180,4 +3210,13 @@ static inline unsigned long rlimit_max(unsigned int limit)
 	return task_rlimit_max(current, limit);
 }
 
+#ifdef CONFIG_RESTARTABLE_SEQUENCES
+static inline int rseq_active(struct task_struct *p)
+{
+	return p->rseq_state.cpu_pointer != NULL;
+}
+#else
+static inline int rseq_active(struct task_struct *p) { return 0; }
+#endif
+
 #endif
include/uapi/asm-generic/unistd.h +3 -1
index ee12400..9659f31 100644
@@ -713,9 +713,11 @@ __SC_COMP(__NR_execveat, sys_execveat, compat_sys_execveat)
 __SYSCALL(__NR_userfaultfd, sys_userfaultfd)
 #define __NR_membarrier 283
 __SYSCALL(__NR_membarrier, sys_membarrier)
+#define __NR_restartable_sequences 284
+__SYSCALL(__NR_restartable_sequences, sys_restartable_sequences)
 
 #undef __NR_syscalls
-#define __NR_syscalls 284
+#define __NR_syscalls 285
 
 /*
  * All syscalls below here should go away really,
init/Kconfig +9 -0
index c24b6f7..9b4a180 100644
@@ -2042,6 +2042,15 @@ source "block/Kconfig"
 config PREEMPT_NOTIFIERS
 	bool
 
+config RESTARTABLE_SEQUENCES
+	bool "Userspace Restartable Sequences (RSEQ)"
+	default n
+	depends on HAVE_RESTARTABLE_SEQUENCE_SUPPORT && PREEMPT_NOTIFIERS
+	help
+	  Allows binaries to define a region of user-text within which
+	  execution will be restarted in the event of signal delivery or
+	  preemption.
+
 config PADATA
 	depends on SMP
 	bool
kernel/Makefile +1 -1
index 53abf00..dbe6963 100644
@@ -101,8 +101,8 @@ obj-$(CONFIG_JUMP_LABEL) += jump_label.o
 obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o
 obj-$(CONFIG_TORTURE_TEST) += torture.o
 obj-$(CONFIG_MEMBARRIER) += membarrier.o
-
 obj-$(CONFIG_HAS_IOMEM) += memremap.o
+obj-$(CONFIG_RESTARTABLE_SEQUENCES) += restartable_sequences.o
 
 $(obj)/configs.o: $(obj)/config_data.h
 
kernel/fork.c +1 -0
index 2845623..aa3ba1e 100644
@@ -252,6 +252,7 @@ void __put_task_struct(struct task_struct *tsk)
 	WARN_ON(tsk == current);
 
 	task_numa_free(tsk);
+	rseq_clear_state_exec(tsk);
 	security_task_free(tsk);
 	exit_creds(tsk);
 	delayacct_tsk_free(tsk);
kernel/ptrace.c +11 -4
index 787320d..63935bc 100644
@@ -825,7 +825,10 @@ int ptrace_request(struct task_struct *child, long request,
 		return generic_ptrace_peekdata(child, addr, data);
 	case PTRACE_POKETEXT:
 	case PTRACE_POKEDATA:
-		return generic_ptrace_pokedata(child, addr, data);
+		/* Don't breakpoint restartable sequences */
+		if (!rseq_lookup(child, addr))
+			return generic_ptrace_pokedata(child, addr, data);
+		break;
 
 #ifdef PTRACE_OLDSETOPTIONS
 	case PTRACE_OLDSETOPTIONS:
@@ -1116,7 +1119,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
 	compat_ulong_t __user *datap = compat_ptr(data);
 	compat_ulong_t word;
 	siginfo_t siginfo;
-	int ret;
+	int ret = -EIO;
 
 	switch (request) {
 	case PTRACE_PEEKTEXT:
@@ -1130,8 +1133,12 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
 
 	case PTRACE_POKETEXT:
 	case PTRACE_POKEDATA:
-		ret = access_process_vm(child, addr, &data, sizeof(data), 1);
-		ret = (ret != sizeof(data) ? -EIO : 0);
+		/* Don't breakpoint restartable sequences */
+		if (!rseq_lookup(child, addr)) {
+			ret = access_process_vm(
+				child, addr, &data, sizeof(data), 1);
+			ret = (ret != sizeof(data) ? -EIO : 0);
+		}
 		break;
 
 	case PTRACE_GETEVENTMSG:
kernel/restartable_sequences.c new file +250 -0

250 lines not on this page · raw message

kernel/sched/core.c +5 -0
index 10a8faa..1e192f5 100644
@@ -2112,6 +2112,11 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
 
 	p->numa_group = NULL;
 #endif /* CONFIG_NUMA_BALANCING */
+
+#ifdef CONFIG_RESTARTABLE_SEQUENCES
+	memset(&p->rseq_state, 0, sizeof(p->rseq_state));
+	p->rseq_state.sections = RB_ROOT;
+#endif
 }
 
 #ifdef CONFIG_NUMA_BALANCING
kernel/sched/sched.h +3 -0
index 6d2a119..c7fb1a6 100644
@@ -953,6 +953,9 @@ static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
 {
 	set_task_rq(p, cpu);
 #ifdef CONFIG_SMP
+	if (rseq_active(p))
+		set_tsk_thread_flag(p, TIF_NOTIFY_RESUME);
+
 	/*
 	 * After ->cpu is set up to a new value, task_rq_lock(p, ...) can be
 	 * successfuly executed on another CPU. We must ensure that updates of
kernel/sys_ni.c +3 -0
index a02decf..d396884 100644
@@ -248,3 +248,6 @@ cond_syscall(sys_execveat);
 
 /* membarrier */
 cond_syscall(sys_membarrier);
+
+/* restartable sequences */
+cond_syscall(sys_restartable_sequences);
Signature · 1 line
2.4.6
#4 lore raw

RFC PATCH 2/3 restartable sequences: x86 ABI

In reply to Dave Watson

Implements the x86 (i386 & x86-64) ABIs for interrupting and restarting execution within restartable sequence sections.

Ptrace is modified to single step over the entire critical region.

---
 arch/x86/entry/common.c                      |  3 ++
 arch/x86/entry/syscalls/syscall_64.tbl       |  1 +
 arch/x86/include/asm/restartable_sequences.h | 44 ++++++++++++++++++++++++++
 arch/x86/kernel/Makefile                     |  2 ++
 arch/x86/kernel/ptrace.c                     |  6 ++--
 arch/x86/kernel/restartable_sequences.c      | 47 ++++++++++++++++++++++++++++
 arch/x86/kernel/signal.c                     | 12 ++++++-
 kernel/restartable_sequences.c               | 11 +++++--
 8 files changed, 120 insertions(+), 6 deletions(-)
 create mode 100644 arch/x86/include/asm/restartable_sequences.h
 create mode 100644 arch/x86/kernel/restartable_sequences.c
arch/x86/entry/common.c +3 -0
index 80dcc92..e817f04 100644
@@ -24,6 +24,7 @@
 
 #include <asm/desc.h>
 #include <asm/traps.h>
+#include <asm/restartable_sequences.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/syscalls.h>
@@ -253,6 +254,8 @@ __visible void prepare_exit_to_usermode(struct pt_regs *regs)
 		if (cached_flags & _TIF_NOTIFY_RESUME) {
 			clear_thread_flag(TIF_NOTIFY_RESUME);
 			tracehook_notify_resume(regs);
+			if (rseq_active(current))
+				arch_rseq_handle_notify_resume(regs);
 		}
 
 		if (cached_flags & _TIF_USER_RETURN_NOTIFY)
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
index 278842f..0fd4243 100644
@@ -331,6 +331,7 @@
 322	64	execveat		stub_execveat
 323	common	userfaultfd		sys_userfaultfd
 324	common	membarrier		sys_membarrier
+325	common	restartable_sequences	sys_restartable_sequences
 
 #
 # x32-specific system call numbers start at 512 to avoid cache impact
arch/x86/include/asm/restartable_sequences.h new file +44 -0

44 lines not on this page · raw message

arch/x86/kernel/Makefile +2 -0
index b1b78ff..ee98fb6 100644
@@ -110,6 +110,8 @@ obj-$(CONFIG_EFI)			+= sysfb_efi.o
 obj-$(CONFIG_PERF_EVENTS)		+= perf_regs.o
 obj-$(CONFIG_TRACING)			+= tracepoint.o
 
+obj-$(CONFIG_RESTARTABLE_SEQUENCES)	+= restartable_sequences.o
+
 ###
 # 64 bit specific files
 ifeq ($(CONFIG_X86_64),y)
arch/x86/kernel/ptrace.c +4 -2
index 558f50e..934aeaf 100644
@@ -1439,6 +1439,8 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
 	struct siginfo info;
 
 	fill_sigtrap_info(tsk, regs, error_code, si_code, &info);
-	/* Send us the fake SIGTRAP */
-	force_sig_info(SIGTRAP, &info, tsk);
+	/* Don't single step in to a restartable sequence */
+	if (!rseq_lookup(tsk, (unsigned long)regs->ip))
+		/* Send us the fake SIGTRAP */
+		force_sig_info(SIGTRAP, &info, tsk);
 }
arch/x86/kernel/restartable_sequences.c new file +47 -0

47 lines not on this page · raw message

arch/x86/kernel/signal.c +11 -1
index da52e6b..1516e5d 100644
@@ -30,6 +30,7 @@
 #include <asm/fpu/signal.h>
 #include <asm/vdso.h>
 #include <asm/mce.h>
+#include <asm/restartable_sequences.h>
 #include <asm/sighandling.h>
 #include <asm/vm86.h>
 
@@ -377,7 +378,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
 		 */
 		put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
 	} put_user_catch(err);
-	
+
 	err |= copy_siginfo_to_user(&frame->info, &ksig->info);
 	err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
 				regs, set->sig[0]);
@@ -613,6 +614,15 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
 	sigset_t *set = sigmask_to_save();
 	compat_sigset_t *cset = (compat_sigset_t *) set;
 
+	/*
+	 * If we are executing in the critical section of a restartable
+	 * sequence we need to fix up the user's stack saved ip at this point
+	 * so that signal handler return does not allow us to jump back into
+	 * the block across a context switch boundary.
+	 */
+	if (rseq_active(current))
+		arch_rseq_check_critical_section(current, regs);
+
 	/* Set up the stack frame */
 	if (is_ia32_frame()) {
 		if (ksig->ka.sa.sa_flags & SA_SIGINFO)
kernel/restartable_sequences.c +8 -3
index 72cfa9b..87e63e2 100644
@@ -20,18 +20,23 @@
 
 #ifdef CONFIG_RESTARTABLE_SEQUENCES
 
+#include <asm/restartable_sequences.h>
 #include <linux/uaccess.h>
 #include <linux/preempt.h>
 #include <linux/slab.h>
 #include <linux/syscalls.h>
 
 static void rseq_sched_in_nop(struct preempt_notifier *pn, int cpu) {}
-static void rseq_sched_out_nop(struct preempt_notifier *pn,
-			       struct task_struct *next) {}
+static void rseq_sched_out(struct preempt_notifier *pn,
+			   struct task_struct *next)
+{
+	if (arch_rseq_needs_notify_resume(current))
+		set_thread_flag(TIF_NOTIFY_RESUME);
+}
 
 static __read_mostly struct preempt_ops rseq_preempt_ops = {
 	.sched_in = rseq_sched_in_nop,
-	.sched_out = rseq_sched_out_nop,
+	.sched_out = rseq_sched_out,
 };
 
 unsigned long rseq_lookup(struct task_struct *p, unsigned long ip)
Signature · 1 line
2.4.6
#5 lore raw

RFC PATCH 3/3 restartable sequences: basic user-space self-tests

In reply to Dave Watson

Implements basic tests of RSEQ functionality.

"basic_percpu_ops_test" implements a few simple per-cpu operations and testing their correctness.

---
 tools/testing/selftests/rseq/Makefile              |  14 +
 .../testing/selftests/rseq/basic_percpu_ops_test.c | 331 +++++++++++++++++++++
 tools/testing/selftests/rseq/rseq.c                |  48 +++
 tools/testing/selftests/rseq/rseq.h                |  17 ++
 4 files changed, 410 insertions(+)
 create mode 100644 tools/testing/selftests/rseq/Makefile
 create mode 100644 tools/testing/selftests/rseq/basic_percpu_ops_test.c
 create mode 100644 tools/testing/selftests/rseq/rseq.c
 create mode 100644 tools/testing/selftests/rseq/rseq.h
tools/testing/selftests/rseq/Makefile new file +14 -0
new file mode 100644
index 0000000..3a9cb5c
@@ -0,0 +1,14 @@
+CFLAGS += -Wall
+LDFLAGS += -lpthread
+
+TESTS = basic_test basic_percpu_ops_test
+
+basic_percpu_ops_test: basic_percpu_ops_test.c
+
+
+all: $(TESTS)
+%: %.c
+	$(CC) $(CFLAGS) -o $@ $^ rseq.c $(LDFLAGS)
+
+clean:
+	$(RM) $(TESTS)
tools/testing/selftests/rseq/basic_percpu_ops_test.c new file +331 -0

331 lines not on this page · raw message

tools/testing/selftests/rseq/rseq.c new file +48 -0

48 lines not on this page · raw message

tools/testing/selftests/rseq/rseq.h new file +17 -0
new file mode 100644
index 0000000..e12db18
@@ -0,0 +1,17 @@
+#ifndef RSEQ_TEST_H
+#define RSEQ_TEST_H
+
+int sys_rseq(int op, int flags, void *val1, void *val2, void *val3);
+/* RSEQ provided thread-local current_cpu */
+
+void rseq_configure_cpu_pointer(void);
+
+void rseq_configure_region(void *rseq_text_start, void *rseq_text_end,
+	void *rseq_text_restart);
+
+extern __thread volatile const int __rseq_current_cpu;
+static inline int rseq_current_cpu(void) { return __rseq_current_cpu; }
+
+void run_tests(void);
+
+#endif
Signature · 1 line
2.4.6
#2 lore raw

Re: [RFC PATCH 1/3] restartable sequences: user-space per-cpu critical sections

In reply to Dave Watson
url: https://github.com/0day-ci/linux/commits/Dave-Watson/restartable-sequences-benchmarks/20151023-020939 reproduce:

Hi Dave,

[auto build test WARNING on v4.3-rc6 -- if it's inappropriate base, please suggest rules for selecting the more suitable base]

url: https://github.com/0day-ci/linux/commits/Dave-Watson/restartable-sequences-benchmarks/20151023-020939
reproduce:

        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF=-D__CHECK_ENDIAN__

sparse warnings: (new ones prefixed by >>)

include/linux/sched.h:1189:34: sparse: Expected ) in function declarator include/linux/sched.h:1189:34: sparse: got (

>> builtin:0:0: sparse: expected ; at end of declaration

include/linux/sched.h:1190:1: sparse: Expected ; at the end of type declaration include/linux/sched.h:1190:1: sparse: got }
include/linux/radix-tree.h:212:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces)
--
include/linux/sched.h:1189:34: sparse: Expected ) in function declarator include/linux/sched.h:1189:34: sparse: got (

>> builtin:0:0: sparse: expected ; at end of declaration

include/linux/sched.h:1190:1: sparse: Expected ; at the end of type declaration include/linux/sched.h:1190:1: sparse: got }
--
mm/page_alloc.c:6010:1: sparse: directive in argument list mm/page_alloc.c:6012:1: sparse: directive in argument list mm/page_alloc.c:6019:1: sparse: directive in argument list mm/page_alloc.c:6021:1: sparse: directive in argument list include/linux/sched.h:1189:34: sparse: Expected ) in function declarator include/linux/sched.h:1189:34: sparse: got (

>> builtin:0:0: sparse: expected ; at end of declaration

include/linux/sched.h:1190:1: sparse: Expected ; at the end of type declaration include/linux/sched.h:1190:1: sparse: got }
--
include/linux/sched.h:1189:34: sparse: Expected ) in function declarator include/linux/sched.h:1189:34: sparse: got (

>> builtin:0:0: sparse: expected ; at end of declaration

include/linux/sched.h:1190:1: sparse: Expected ; at the end of type declaration include/linux/sched.h:1190:1: sparse: got }
include/linux/radix-tree.h:212:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces)
--
mm/debug.c:176:1: sparse: directive in argument list
mm/debug.c:178:1: sparse: directive in argument list
mm/debug.c:187:1: sparse: directive in argument list
mm/debug.c:189:1: sparse: directive in argument list
mm/debug.c:190:1: sparse: directive in argument list
mm/debug.c:192:1: sparse: directive in argument list
mm/debug.c:194:1: sparse: directive in argument list
mm/debug.c:196:1: sparse: directive in argument list
mm/debug.c:197:1: sparse: directive in argument list
mm/debug.c:199:1: sparse: directive in argument list
mm/debug.c:200:1: sparse: directive in argument list
mm/debug.c:202:1: sparse: directive in argument list
mm/debug.c:206:1: sparse: directive in argument list
mm/debug.c:208:1: sparse: directive in argument list
mm/debug.c:221:1: sparse: directive in argument list
mm/debug.c:223:1: sparse: directive in argument list
mm/debug.c:224:1: sparse: directive in argument list
mm/debug.c:226:1: sparse: directive in argument list
mm/debug.c:228:1: sparse: directive in argument list
mm/debug.c:230:1: sparse: directive in argument list
mm/debug.c:231:1: sparse: directive in argument list
mm/debug.c:233:1: sparse: directive in argument list
mm/debug.c:234:1: sparse: directive in argument list
mm/debug.c:236:1: sparse: directive in argument list
include/linux/sched.h:1189:34: sparse: Expected ) in function declarator include/linux/sched.h:1189:34: sparse: got (

>> builtin:0:0: sparse: expected ; at end of declaration

include/linux/sched.h:1190:1: sparse: Expected ; at the end of type declaration include/linux/sched.h:1190:1: sparse: got }
--
include/linux/sched.h:1189:34: sparse: Expected ) in function declarator include/linux/sched.h:1189:34: sparse: got (

>> builtin:0:0: sparse: expected ; at end of declaration

include/linux/sched.h:1190:1: sparse: Expected ; at the end of type declaration include/linux/sched.h:1190:1: sparse: got }
include/linux/radix-tree.h:212:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:212:16: sparse: incompatible types in comparison expression (different address spaces)
--
include/linux/sched.h:1189:34: sparse: Expected ) in function declarator include/linux/sched.h:1189:34: sparse: got (

>> builtin:0:0: sparse: expected ; at end of declaration

include/linux/sched.h:1190:1: sparse: Expected ; at the end of type declaration include/linux/sched.h:1190:1: sparse: got }
mm/memcontrol.c:3289:21: sparse: incompatible types in comparison expression (different address spaces) mm/memcontrol.c:3291:21: sparse: incompatible types in comparison expression (different address spaces) mm/memcontrol.c:4861:23: sparse: incompatible types in comparison expression (different address spaces)

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#6 lore raw
In reply to Dave Watson
Quoted 3 lines · Dave Watson

We've been testing out restartable sequences + malloc changes for use at Facebook. Below are some test results, as well as some possible changes based on Paul Turner's original patches

Thanks! I'll stare at this some time between now and Kernel Summit.

Quoted 11 lines

https://lkml.org/lkml/2015/6/24/665

I ran one service with several permutations of various mallocs. The service is CPU-bound, and hits the allocator quite hard. Requests/s are held constant at the source, so we use cpu idle time and latency as an indicator of service quality. These are average numbers over several hours. Machines were dual E5-2660, total 16 cores + hyperthreading. This service has ~400 total threads, 70-90 of which are doing work at any particular time.

Quoted 7 lines

RSS CPUIDLE LATENCYMS

jemalloc 4.0.0                     31G   33%     390
jemalloc + this patch              25G   33%     390
jemalloc + this patch using lsl    25G   30%     420
jemalloc + PT's rseq patch         25G   32%     405
glibc malloc 2.20                  27G   30%     420
tcmalloc gperftools trunk (2.2)    21G   30%     480

Slightly confused. This is showing a space efficiency improvement but not a performance improvement? Is the idea that percpu free lists are more space efficient than per-thread free lists?

Quoted 10 lines

jemalloc rseq patch used for testing:
https://github.com/djwatson/jemalloc

lsl test - using lsl segment limit to get cpu (i.e. inlined vdso getcpu on x86) instead of using the thread caching as in this patch. There has been some suggestions to add the thread-cached getcpu() feature separately. It does seem to move the needle in a real service by about ~3% to have a thread-cached getcpu vs. not. I don't think we can use restartable sequences in production without a faster getcpu.

If nothing else, I'd like to replace the thread-cached getcpu thing with percpu gsbase, at least on x86. That doesn't necessarily have to be exclusive with restartable sequences.

Quoted 8 lines

GS-segment / migration only tests

There's been some interest in seeing if we can do this with only gs segment, here's some numbers for those. This doesn't have to be gs, it could just be a migration signal sent to userspace as well, the same approaches would apply.

Quoted 6 lines

GS patch: https://lkml.org/lkml/2014/9/13/59

RSS CPUIDLE LATENCYMS

jemalloc 4.0.0                     31G   33%     390
jemalloc + percpu locking          25G   25%     420
jemalloc + preempt lock / signal   25G   32%     415

Neat!

--Andy

#3 lore raw

Re: [RFC PATCH 1/3] restartable sequences: user-space per-cpu critical sections

In reply to Dave Watson
reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…

Hi Dave,

[auto build test ERROR on v4.3-rc6 -- if it's inappropriate base, please suggest rules for selecting the more suitable base]

url:    https://github.com/0day-ci/linux/commits/Dave-Watson/restartable-sequences-benchmarks/20151023-020939
config: openrisc-allmodconfig (attached as .config)

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=openrisc

All errors (new ones prefixed by >>):

In file included from include/asm-generic/unistd.h:1:0,
from arch/openrisc/include/uapi/asm/unistd.h:26, from arch/openrisc/kernel/sys_call_table.c:27:

>> include/uapi/asm-generic/unistd.h:717:1: error: 'sys_restartable_sequences' undeclared here (not in a function)

vim +/sys_restartable_sequences +717 include/uapi/asm-generic/unistd.h

711 __SC_COMP(__NR_execveat, sys_execveat, compat_sys_execveat)
712 #define __NR_userfaultfd 282
713 __SYSCALL(__NR_userfaultfd, sys_userfaultfd)
714 #define __NR_membarrier 283
715 __SYSCALL(__NR_membarrier, sys_membarrier)
716 #define __NR_restartable_sequences 284

 > 717	__SYSCALL(__NR_restartable_sequences, sys_restartable_sequences)

718
719 #undef __NR_syscalls
720 #define __NR_syscalls 285

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#7 lore raw
In reply to Andy Lutomirski
Quoted 10 lines · Andy Lutomirski
Quoted 8 lines · Dave Watson

RSS CPUIDLE LATENCYMS

jemalloc 4.0.0                     31G   33%     390
jemalloc + this patch              25G   33%     390
jemalloc + this patch using lsl    25G   30%     420
jemalloc + PT's rseq patch         25G   32%     405
glibc malloc 2.20                  27G   30%     420
tcmalloc gperftools trunk (2.2)    21G   30%     480
Quoted 5 lines

Slightly confused. This is showing a space efficiency improvement but not a performance improvement? Is the idea that percpu free lists are more space efficient than per-thread free lists?

--Andy

Correct - the service was already tuned such that most requests hit the (very large) thread free lists to avoided taking expensive locks talking to the central arena. There were more threads than cpus, so the memory win is just needing fewer free lists.