From b11e10e2c81c2b608176021364a36d84173358e3 Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Sun, 24 Sep 2023 10:35:10 +0000 Subject: percpu area using gs segment This speeds up smp again, by storing the struct processor in a percpu area and avoiding an expensive cpu_number every call of current_processor(), as well as getting the cpu_number by an offset into the percpu area. Untested on 64 bit and work remains to use other percpu arrays. TESTED: (NCPUS=8) -smp 1 boots to login shell ~2x slower than uniprocessor TESTED: (NCPUS=8) -smp 2 boots to INIT but hangs there TESTED: (NCPUS=8) -smp 4 gets stuck seemingly within rumpdisk and hangs TESTED: (NCPUS=1) uniprocessor is a bit faster than normal Message-Id: <20230924103428.455966-3-damien@zamaudio.com> --- x86_64/Makefrag.am | 2 ++ x86_64/locore.S | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'x86_64') diff --git a/x86_64/Makefrag.am b/x86_64/Makefrag.am index 008ac58f..0c67517c 100644 --- a/x86_64/Makefrag.am +++ b/x86_64/Makefrag.am @@ -103,6 +103,8 @@ libkernel_a_SOURCES += \ i386/i386/irq.c \ i386/i386/irq.h \ i386/i386/msr.h \ + i386/i386/percpu.h \ + i386/i386/percpu.c \ i386/i386/pit.c \ i386/i386/pit.h diff --git a/x86_64/locore.S b/x86_64/locore.S index fabbf2e7..d640ef73 100644 --- a/x86_64/locore.S +++ b/x86_64/locore.S @@ -140,6 +140,7 @@ mov %dx,%ds ;\ mov %dx,%es ;\ mov %dx,%fs ;\ + mov $(PERCPU_DS),%dx ;\ mov %dx,%gs #else #define SET_KERNEL_SEGMENTS @@ -350,7 +351,7 @@ timer_normalize: * Switch to a new timer. */ ENTRY(timer_switch) - CPU_NUMBER(%edx) /* get this CPU */ + CPU_NUMBER_NO_GS(%edx) /* get this CPU */ movl VA_ETC,%ecx /* get timer */ movl CX(EXT(current_tstamp),%rdx),%eax /* get old time stamp */ movl %ecx,CX(EXT(current_tstamp),%rdx) /* set new time stamp */ @@ -368,7 +369,7 @@ ENTRY(timer_switch) * Initialize the first timer for a CPU. */ ENTRY(start_timer) - CPU_NUMBER(%edx) /* get this CPU */ + CPU_NUMBER_NO_GS(%edx) /* get this CPU */ movl VA_ETC,%ecx /* get timer */ movl %ecx,CX(EXT(current_tstamp),%rdx) /* set initial time stamp */ movl S_ARG0,%ecx /* get timer */ @@ -1445,7 +1446,7 @@ _syscall64_call: _syscall64_check_for_ast: /* Check for ast. */ - CPU_NUMBER(%r11) + CPU_NUMBER_NO_GS(%r11) cmpl $0,CX(EXT(need_ast),%r11) jz _syscall64_restore_state -- cgit v1.2.3