[PATCH 4/5 gnumach] sched_prim.c: Lock thread when calling thread_setrun
--- kern/sched_prim.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kern/sched_prim.c b/kern/sched_prim.c index 5def77d4..bc7befe8 100644 --- a/kern/sched_prim.c +++ b/kern/sched_prim.c @@ -1793,7 +1793,9 @@ retry: */ if ((new_thread = (thread_t)*threadp)!= THREAD_NULL) { *threadp = (volatile thread_t) THREAD_NULL; + thread_lock(new_thread); thread_setrun(new_thread, FALSE); + thread_unlock(new_thread); } counter(c_idle_thread_block++); -- 2.40.1
[PATCH 5/5 gnumach] sched_prim.c: Check all run queues not just master processor
--- kern/sched_prim.c | 10 -- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kern/sched_prim.c b/kern/sched_prim.c index bc7befe8..ce458eb5 100644 --- a/kern/sched_prim.c +++ b/kern/sched_prim.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -1983,6 +1984,7 @@ void do_thread_scan(void) spl_t s; boolean_t restart_needed = 0; thread_tthread; + int i; #ifMACH_HOST processor_set_t pset; #endif /* MACH_HOST */ @@ -1998,8 +2000,12 @@ void do_thread_scan(void) #else /* MACH_HOST */ restart_needed = do_runq_scan(&default_pset.runq); #endif /* MACH_HOST */ - if (!restart_needed) - restart_needed = do_runq_scan(&master_processor->runq); + if (!restart_needed) { + for (i = 0; i < smp_get_numcpus(); i++) { + if ((restart_needed = do_runq_scan(&cpu_to_processor(i)->runq))) + break; + } + } /* * Ok, we now have a collection of candidates -- fix them. -- 2.40.1
[PATCH 3/5 gnumach] sched_prim.c: Add missing MACH_HOST pset conditionals
--- kern/sched_prim.c | 29 +++-- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/kern/sched_prim.c b/kern/sched_prim.c index 5ee0791b..5def77d4 100644 --- a/kern/sched_prim.c +++ b/kern/sched_prim.c @@ -510,6 +510,13 @@ static thread_t thread_select( processor_t myprocessor) { thread_t thread; + processor_set_t pset; + +#ifMACH_HOST + pset = myprocessor->processor_set; +#else /* MACH_HOST */ + pset = &default_pset; +#endif /* MACH_HOST */ myprocessor->first_quantum = TRUE; /* @@ -520,13 +527,6 @@ static thread_t thread_select( thread = choose_thread(myprocessor); } else { - processor_set_t pset; - -#ifMACH_HOST - pset = myprocessor->processor_set; -#else /* MACH_HOST */ - pset = &default_pset; -#endif /* MACH_HOST */ simple_lock(&pset->runq.lock); #ifDEBUG checkrq(&pset->runq, "thread_select"); @@ -1259,7 +1259,11 @@ void thread_setrun( /* * Not bound, any processor in the processor set is ok. */ +#ifMACH_HOST pset = th->processor_set; +#else + pset = &default_pset; +#endif /* MACH_HOST */ #ifHW_FOOTPRINT /* * But first check the last processor it ran on. @@ -1543,9 +1547,11 @@ thread_t choose_thread( /*NOTREACHED*/ } simple_unlock(&runq->lock); - +#ifMACH_HOST pset = myprocessor->processor_set; - +#else + pset = &default_pset; +#endif simple_lock(&pset->runq.lock); return choose_pset_thread(myprocessor,pset); } @@ -1752,8 +1758,11 @@ retry: } else if (state == PROCESSOR_IDLE) { processor_set_t pset; - +#ifMACH_HOST pset = myprocessor->processor_set; +#else + pset = &default_pset; +#endif /* MACH_HOST */ simple_lock(&pset->idle_lock); if (myprocessor->state != PROCESSOR_IDLE) { /* -- 2.40.1
[PATCH 1/5 gnumach] sched_prim.c: Split bound processor case into two
--- kern/sched_prim.c | 32 ++-- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/kern/sched_prim.c b/kern/sched_prim.c index be34e7dd..d69e4990 100644 --- a/kern/sched_prim.c +++ b/kern/sched_prim.c @@ -1325,12 +1325,33 @@ void thread_setrun( } else { /* -* Bound, can only run on bound processor. Have to lock -* processor here because it may not be the current one. +* Bound, can only run on bound processor. +* Check two cases, bound is current or not. */ - if (processor->state == PROCESSOR_IDLE) { +#ifMACH_HOST + pset = processor->processor_set; +#else + pset = &default_pset; +#endif /* MACH_HOST */ + if (processor == current_processor()) { + if (processor->state == PROCESSOR_IDLE) { + simple_lock(&pset->idle_lock); + if (processor->state == PROCESSOR_IDLE) { + queue_remove(&pset->idle_queue, processor, +processor_t, processor_queue); + pset->idle_count--; + processor->next_thread = th; + processor->state = PROCESSOR_DISPATCHING; + simple_unlock(&pset->idle_lock); + /* Interrupt self */ + cause_ast_check(processor); + return; + } + simple_unlock(&pset->idle_lock); + } + } + else { processor_lock(processor); - pset = processor->processor_set; simple_lock(&pset->idle_lock); if (processor->state == PROCESSOR_IDLE) { queue_remove(&pset->idle_queue, processor, @@ -1340,8 +1361,7 @@ void thread_setrun( processor->state = PROCESSOR_DISPATCHING; simple_unlock(&pset->idle_lock); processor_unlock(processor); - if (processor != current_processor()) - cause_ast_check(processor); + cause_ast_check(processor); return; } simple_unlock(&pset->idle_lock); -- 2.40.1
[PATCH 2/5 gnumach] sched_prim.c: Set quantum based on priority policy (not minimum)
--- kern/sched_prim.c | 21 ++--- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/kern/sched_prim.c b/kern/sched_prim.c index d69e4990..5ee0791b 100644 --- a/kern/sched_prim.c +++ b/kern/sched_prim.c @@ -518,7 +518,6 @@ static thread_t thread_select( */ if (myprocessor->runq.count > 0) { thread = choose_thread(myprocessor); - myprocessor->quantum = min_quantum; } else { processor_set_t pset; @@ -592,21 +591,21 @@ static thread_t thread_select( simple_unlock(&pset->runq.lock); } } + } #ifMACH_FIXPRI - if (thread->policy == POLICY_TIMESHARE) { + if (thread->policy == POLICY_TIMESHARE) { #endif /* MACH_FIXPRI */ - myprocessor->quantum = pset->set_quantum; + myprocessor->quantum = pset->set_quantum; #ifMACH_FIXPRI - } - else { - /* -* POLICY_FIXEDPRI -*/ - myprocessor->quantum = thread->sched_data; - } -#endif /* MACH_FIXPRI */ } + else { + /* +* POLICY_FIXEDPRI +*/ + myprocessor->quantum = thread->sched_data; + } +#endif /* MACH_FIXPRI */ return thread; } -- 2.40.1
[PATCH 0/5 gnumach] Scheduler fixes
Hi, This patchset does not seem to make much noticable difference to speed, but I think it's an improvement. The patches can probably be cherry-picked independently if you don't want all of them. Thanks, Damien
[PATCH v2 gnumach] apic: Use cpuid to read the apic id for speed
--- i386/i386/apic.c | 11 +-- i386/i386/cpu_number.h | 20 +++- i386/i386/mp_desc.c| 3 +-- x86_64/locore.S| 6 +++--- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/i386/i386/apic.c b/i386/i386/apic.c index 2bb8e3f1..3a51f506 100644 --- a/i386/i386/apic.c +++ b/i386/i386/apic.c @@ -185,7 +185,11 @@ apic_get_num_ioapics(void) int apic_get_current_cpu(void) { -return (lapic->apic_id.r >> 24) & 0xff; +unsigned int eax, ebx, ecx, edx; +eax = 1; +ecx = 0; +cpuid(eax, ebx, ecx, edx); +return (ebx >> 24); } @@ -295,11 +299,6 @@ lapic_enable(void) cpu_intr_save(&flags); apic_id = apic_get_current_cpu(); -if (apic_id < 0) - { -printf("apic_get_current_cpu() failed, assuming BSP\n"); -apic_id = 0; - } dummy = lapic->dest_format.r; lapic->dest_format.r = 0x; /* flat model */ diff --git a/i386/i386/cpu_number.h b/i386/i386/cpu_number.h index c00896e8..df086370 100644 --- a/i386/i386/cpu_number.h +++ b/i386/i386/cpu_number.h @@ -39,12 +39,30 @@ #defineCX(addr, reg) addr(,reg,8) #endif -#defineCPU_NUMBER(reg) \ +#defineCPU_NUMBER_NO_STACK(reg)\ movl%cs:lapic, reg ;\ movl%cs:APIC_ID(reg), reg ;\ shrl$24, reg;\ movl%cs:CX(cpu_id_lut, reg), reg;\ +/* Never call CPU_NUMBER(%esi) */ +#define CPU_NUMBER(reg)\ + pushl %esi;\ + pushl %eax;\ + pushl %ebx;\ + pushl %ecx;\ + pushl %edx;\ + movl$1, %eax;\ + cpuid ;\ + shrl$24, %ebx ;\ + movl%cs:CX(cpu_id_lut, %ebx), %esi ;\ + popl%edx;\ + popl%ecx;\ + popl%ebx;\ + popl%eax;\ + movl%esi, reg ;\ + popl%esi;\ + #ifndef __ASSEMBLER__ #include "kern/cpu_number.h" int cpu_number(void); diff --git a/i386/i386/mp_desc.c b/i386/i386/mp_desc.c index 88fbb50a..f1a1f989 100644 --- a/i386/i386/mp_desc.c +++ b/i386/i386/mp_desc.c @@ -275,8 +275,7 @@ cpu_setup(int cpu) void cpu_ap_main() { -unsigned apic_id = (((ApicLocalUnit*)phystokv(lapic_addr))->apic_id.r >> 24) & 0xff; -int cpu = apic_get_cpu_kernel_id(apic_id); +int cpu = cpu_number(); do { cpu_pause(); diff --git a/x86_64/locore.S b/x86_64/locore.S index a330d56b..c75feb23 100644 --- a/x86_64/locore.S +++ b/x86_64/locore.S @@ -1171,7 +1171,7 @@ syscall_entry_2: movq%rdx,R_CS(%rsp) /* fix cs */ movq%rbx,R_EFLAGS(%rsp) /* fix eflags */ - CPU_NUMBER(%edx) + CPU_NUMBER_NO_STACK(%edx) TIME_TRAP_SENTRY movqCX(EXT(kernel_stack),%rdx),%rbx @@ -1371,7 +1371,7 @@ ENTRY(syscall64) * save only the callee-preserved status according to the C ABI, * plus RIP and EFLAGS for sysret */ - CPU_NUMBER(%r11) + CPU_NUMBER_NO_STACK(%r11) movqCX(EXT(active_threads),%r11),%r11 /* point to current thread */ movqTH_PCB(%r11),%r11 /* point to pcb */ addq$ PCB_ISS,%r11 /* point to saved state */ @@ -1405,7 +1405,7 @@ ENTRY(syscall64) mov %r10,%rcx /* fix arg3 location according to C ABI */ /* switch to kernel stack, then we can enable interrupts */ - CPU_NUMBER(%r11) + CPU_NUMBER_NO_STACK(%r11) movqCX(EXT(kernel_stack),%r11),%rsp sti -- 2.40.1
Re: 64bit startup
Samuel Thibault, le sam. 12 août 2023 17:37:06 +0200, a ecrit: > BTW, git is now available and seems to be working fine, I could clone > the upstream glibc repository for instance. The testsuite runs quite fine. Of course most xfails on hurd-i386 are also xfails on hurd-amd64 :) I have put below the list of xfails for hurd-amd64, most of them are probably worth looking at, notably the default FPU config (to be fixed inside gnumach), the context support, and the backtrace support, which we will want anyway, and then the bug fixes, to be on part with hurd-i386 in terms of bugs :) Samuel # TODO: fix default FPU config test-xfail-test-fenv = yes test-xfail-test-float64x-acos = yes test-xfail-test-float64x-log10 = yes test-xfail-test-float64x-log2 = yes test-xfail-test-float64x-y0 = yes test-xfail-test-float64x-y1 = yes test-xfail-test-ldouble-acos = yes test-xfail-test-ldouble-log10 = yes test-xfail-test-ldouble-log2 = yes test-xfail-test-ldouble-y0 = yes test-xfail-test-ldouble-y1 = yes # TODO context support test-xfail-bug-getcontext = yes test-xfail-tst-setcontext2 = yes test-xfail-tst-setcontext4 = yes test-xfail-tst-setcontext5 = yes test-xfail-tst-setcontext6 = yes test-xfail-tst-setcontext7 = yes test-xfail-tst-setcontext8 = yes test-xfail-tst-setcontext9 = yes test-xfail-tst-swapcontext1 = yes test-xfail-tst-xbzero-opt = yes # Bus error test-xfail-test-bz22786 = yes # memory leak test-xfail-tst-vfprintf-width-prec-mem = yes test-xfail-tst-vfprintf-width-prec = yes # timeout test-xfail-tst-basic7 = yes # timeout test-xfail-tst-malloc-too-large = yes test-xfail-tst-malloc-too-large-malloc-check = yes test-xfail-tst-malloc-too-large-hugetlb1 = yes test-xfail-tst-malloc-too-large-hugetlb2 = yes # Bus error test-xfail-bug18240 = yes # cmsg bug test-xfail-tst-cmsghdr = yes # TODO support (for signals I guess) test-xfail-tst-backtrace4 = yes test-xfail-tst-backtrace5 = yes test-xfail-tst-backtrace6 = yes test-xfail-tst-dlopen-nodelete-reloc = yes test-xfail-tst-platform-1 = yes test-xfail-tst-audit4 = yes test-xfail-tst-audit5 = yes test-xfail-tst-audit6 = yes test-xfail-tst-audit7 = yes test-xfail-tst-audit10 = yes
Re: 64bit startup
For information, core dumping seems to be broken, so better disable it with rm -f /servers/crash ln -s crash-kill /servers/crash otherwise you get hangs or worse ;) Samuel
Re: 64bit startup
On August 15, 2023 4:11:08 PM GMT+02:00, jbra...@dismail.de wrote: >August 15, 2023 12:36 AM, "Guy-Fleury Iteriteka" wrote: > >> On August 14, 2023 10:48:57 PM GMT+02:00, Samuel Thibault >> wrote: >> >>> Samuel Thibault, le sam. 12 août 2023 17:37:06 +0200, a ecrit: >> >> Thats great,thanks. On irc you mention building python too cause many >> problems. Today i am going to >> search a good computer so that i learn programming in hurd >>> Samuel >> > >I've got the Hurd running pretty well on a T43. But that is only a 32-bit >single core machine. > >It also runs really well in qemu. Many Hurd developers run the Hurd in qemu. >:) I know that Yes. My current compter have an issue where some key are not working so it's not pratical for programming. >
Re: 64bit startup
August 15, 2023 12:36 AM, "Guy-Fleury Iteriteka" wrote: > On August 14, 2023 10:48:57 PM GMT+02:00, Samuel Thibault > wrote: > >> Samuel Thibault, le sam. 12 août 2023 17:37:06 +0200, a ecrit: > > Thats great,thanks. On irc you mention building python too cause many > problems. Today i am going to > search a good computer so that i learn programming in hurd >> Samuel > I've got the Hurd running pretty well on a T43. But that is only a 32-bit single core machine. It also runs really well in qemu. Many Hurd developers run the Hurd in qemu. :)