bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 3/3 gnumach] percpu active_thread using gs segment


From: Samuel Thibault
Subject: Re: [PATCH 3/3 gnumach] percpu active_thread using gs segment
Date: Sun, 24 Sep 2023 15:22:59 +0200
User-agent: NeoMutt/20170609 (1.8.3)

Applied, thanks!

Damien Zammit, le dim. 24 sept. 2023 05:29:06 +0000, a ecrit:
> TESTED: As per previous commit
> ---
>  i386/i386/cswitch.S   | 2 +-
>  i386/i386/i386asm.sym | 1 +
>  i386/i386/locore.S    | 2 +-
>  i386/i386/pcb.c       | 2 +-
>  i386/i386/percpu.h    | 2 +-
>  kern/ipc_sched.c      | 2 +-
>  kern/machine.c        | 2 +-
>  kern/sched_prim.c     | 2 +-
>  kern/startup.c        | 2 +-
>  kern/thread.c         | 3 +--
>  kern/thread.h         | 3 +--
>  kern/timer.c          | 4 ++--
>  12 files changed, 13 insertions(+), 14 deletions(-)
> 
> diff --git a/i386/i386/cswitch.S b/i386/i386/cswitch.S
> index d97093ff..598e32cf 100644
> --- a/i386/i386/cswitch.S
> +++ b/i386/i386/cswitch.S
> @@ -79,7 +79,7 @@ ENTRY(Switch_context)
>       lea     KERNEL_STACK_SIZE-IKS_SIZE-IEL_SIZE(%ecx),%ebx
>                                               /* point to stack top */
>  
> -     movl    %esi,CX(EXT(active_threads),%edx)       /* new thread is active 
> */
> +     movl    %esi,MY(ACTIVE_THREAD)          /* new thread is active */
>       movl    %ecx,CX(EXT(active_stacks),%edx)        /* set current stack */
>       movl    %ebx,CX(EXT(kernel_stack),%edx) /* set stack top */
>  
> diff --git a/i386/i386/i386asm.sym b/i386/i386/i386asm.sym
> index d96b8be8..d4b05fa8 100644
> --- a/i386/i386/i386asm.sym
> +++ b/i386/i386/i386asm.sym
> @@ -54,6 +54,7 @@ expr        CALL_PMAP_UPDATE
>  offset       ApicLocalUnit           lu      apic_id         APIC_ID
>  
>  offset       percpu                  pc      cpu_id          PERCPU_CPU_ID
> +offset       percpu                  pc      active_thread   
> PERCPU_ACTIVE_THREAD
>  
>  offset       pcb                     pcb     iss
>  
> diff --git a/i386/i386/locore.S b/i386/i386/locore.S
> index 870db785..0e3dc1b3 100644
> --- a/i386/i386/locore.S
> +++ b/i386/i386/locore.S
> @@ -1082,7 +1082,7 @@ syscall_entry_2:
>   * Check for MACH or emulated system call
>   */
>  syscall_entry_3:
> -     movl    CX(EXT(active_threads),%edx),%edx
> +     movl    MY(ACTIVE_THREAD),%edx
>                                       /* point to current thread */
>       movl    TH_TASK(%edx),%edx      /* point to task */
>       movl    TASK_EMUL(%edx),%edx    /* get emulation vector */
> diff --git a/i386/i386/pcb.c b/i386/i386/pcb.c
> index e0f4f57a..9576c147 100644
> --- a/i386/i386/pcb.c
> +++ b/i386/i386/pcb.c
> @@ -316,7 +316,7 @@ void stack_handoff(
>       stack = current_stack();
>       old->kernel_stack = 0;
>       new->kernel_stack = stack;
> -     active_threads[mycpu] = new;
> +     percpu_assign(active_thread, new);
>  
>       /*
>        *      Switch exception link to point to new
> diff --git a/i386/i386/percpu.h b/i386/i386/percpu.h
> index fb42f9fb..cf9b96bd 100644
> --- a/i386/i386/percpu.h
> +++ b/i386/i386/percpu.h
> @@ -63,10 +63,10 @@ struct percpu {
>      int                      apic_id;
>      int                      cpu_id;
>      struct processor processor;
> +    thread_t         active_thread;
>  /*
>      struct machine_slot      machine_slot;
>      struct mp_desc_table mp_desc_table;
> -    thread_t         active_thread;
>      vm_offset_t              active_stack;
>      vm_offset_t              int_stack_top;
>      vm_offset_t              int_stack_base;
> diff --git a/kern/ipc_sched.c b/kern/ipc_sched.c
> index be82971b..4519c654 100644
> --- a/kern/ipc_sched.c
> +++ b/kern/ipc_sched.c
> @@ -233,7 +233,7 @@ thread_handoff(
>       /*
>        *      stack_handoff is machine-dependent.  It does the
>        *      machine-dependent components of a context-switch, like
> -      *      changing address spaces.  It updates active_threads.
> +      *      changing address spaces.  It updates active_thread.
>        */
>  
>       stack_handoff(old, new);
> diff --git a/kern/machine.c b/kern/machine.c
> index 0aa0f3c6..87fbc4d1 100644
> --- a/kern/machine.c
> +++ b/kern/machine.c
> @@ -635,7 +635,7 @@ void processor_doshutdown(processor_t processor)
>        */
>       PMAP_DEACTIVATE_KERNEL(cpu);
>  #ifndef MIGRATING_THREADS
> -     active_threads[cpu] = THREAD_NULL;
> +     percpu_array[cpu].active_thread = THREAD_NULL;
>  #endif
>       cpu_down(cpu);
>       thread_wakeup((event_t)processor);
> diff --git a/kern/sched_prim.c b/kern/sched_prim.c
> index 6617db7c..5ee0521a 100644
> --- a/kern/sched_prim.c
> +++ b/kern/sched_prim.c
> @@ -806,7 +806,7 @@ boolean_t thread_invoke(
>       /*
>        *      switch_context is machine-dependent.  It does the
>        *      machine-dependent components of a context-switch, like
> -      *      changing address spaces.  It updates active_threads.
> +      *      changing address spaces.  It updates active_thread.
>        *      It returns only if a continuation is not supplied.
>        */
>       counter(c_thread_invoke_csw++);
> diff --git a/kern/startup.c b/kern/startup.c
> index 88608c7d..13acb850 100644
> --- a/kern/startup.c
> +++ b/kern/startup.c
> @@ -300,7 +300,7 @@ void cpu_launch_first_thread(thread_t th)
>  
>       PMAP_ACTIVATE_KERNEL(mycpu);
>  
> -     active_threads[mycpu] = th;
> +     percpu_assign(active_thread, th);
>       active_stacks[mycpu] = th->kernel_stack;
>       thread_lock(th);
>       th->state &= ~TH_UNINT;
> diff --git a/kern/thread.c b/kern/thread.c
> index 9bbe8342..c397de84 100644
> --- a/kern/thread.c
> +++ b/kern/thread.c
> @@ -69,7 +69,6 @@
>  #include <machine/pcb.h>
>  #include <machine/thread.h>          /* for MACHINE_STACK */
>  
> -thread_t active_threads[NCPUS];
>  vm_offset_t active_stacks[NCPUS];
>  
>  struct kmem_cache thread_cache;
> @@ -2572,7 +2571,7 @@ kern_return_t processor_set_stack_usage(
>                       stack = thread->kernel_stack;
>  
>                       for (cpu = 0; cpu < smp_get_numcpus(); cpu++)
> -                             if (active_threads[cpu] == thread) {
> +                             if (percpu_array[cpu].active_thread == thread) {
>                                       stack = active_stacks[cpu];
>                                       break;
>                               }
> diff --git a/kern/thread.h b/kern/thread.h
> index 8547464d..ff91fddb 100644
> --- a/kern/thread.h
> +++ b/kern/thread.h
> @@ -268,7 +268,6 @@ typedef   mach_port_t *thread_array_t;
>  #endif       /* _KERN_KERN_TYPES_H_ */
>  
>  
> -extern thread_t              active_threads[NCPUS];  /* active threads */
>  extern vm_offset_t   active_stacks[NCPUS];   /* active kernel stacks */
>  
>  #ifdef KERNEL
> @@ -414,7 +413,7 @@ extern void               thread_unfreeze(
>   *   designate this by defining CURRENT_THREAD.
>   */
>  #ifndef      CURRENT_THREAD
> -#define current_thread()     (active_threads[cpu_number()])
> +#define current_thread()     (percpu_get(thread_t, active_thread))
>  #endif       /* CURRENT_THREAD */
>  
>  #define      current_stack()         (active_stacks[cpu_number()])
> diff --git a/kern/timer.c b/kern/timer.c
> index 7d029b7c..13dfc207 100644
> --- a/kern/timer.c
> +++ b/kern/timer.c
> @@ -132,7 +132,7 @@ time_trap_uentry(unsigned ts)
>       /*
>        *      Record new timer.
>        */
> -     mytimer = &(active_threads[mycpu]->system_timer);
> +     mytimer = &(current_thread()->system_timer);
>       current_timer[mycpu] = mytimer;
>       mytimer->tstamp = ts;
>  }
> @@ -170,7 +170,7 @@ time_trap_uexit(int ts)
>               timer_normalize(mytimer);       /* SYSTEMMODE */
>       }
>  
> -     mytimer = &(active_threads[mycpu]->user_timer);
> +     mytimer = &(current_thread()->user_timer);
>  
>       /*
>        *      Record new timer.
> -- 
> 2.40.1
> 
> 
> 

-- 
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]