debuggers.hg

changeset 22727:2dd233e88838

x86: Free per-cpu area for offline cpu via RCU.

This allows other CPUs to reference per-cpu areas with less strict
locking. In particular, timer.c access a per-cpu lock with reference
to a per-timer cpu field which it accesses with no synchronisation.

One subtlety is that this prevents us bringing a cpu back online until
the RCU work is completed. In this case we return EBUSY and the
tool stack can report the (unlikely) error, or retry, as it sees fit.

Signed-off-by: Keir Fraser <keir@xen.org>
author Keir Fraser <keir@xen.org>
date Sat Jan 08 09:14:23 2011 +0000 (2011-01-08)
parents 03718b569d97
children c7c1ab13d08e
files xen/arch/x86/percpu.c
line diff
     1.1 --- a/xen/arch/x86/percpu.c	Fri Jan 07 18:53:50 2011 +0000
     1.2 +++ b/xen/arch/x86/percpu.c	Sat Jan 08 09:14:23 2011 +0000
     1.3 @@ -3,6 +3,7 @@
     1.4  #include <xen/cpu.h>
     1.5  #include <xen/init.h>
     1.6  #include <xen/mm.h>
     1.7 +#include <xen/rcupdate.h>
     1.8  
     1.9  unsigned long __per_cpu_offset[NR_CPUS];
    1.10  #define INVALID_PERCPU_AREA (-(long)__per_cpu_start)
    1.11 @@ -19,7 +20,7 @@ static int init_percpu_area(unsigned int
    1.12  {
    1.13      char *p;
    1.14      if ( __per_cpu_offset[cpu] != INVALID_PERCPU_AREA )
    1.15 -        return 0;
    1.16 +        return -EBUSY;
    1.17      if ( (p = alloc_xenheap_pages(PERCPU_ORDER, 0)) == NULL )
    1.18          return -ENOMEM;
    1.19      memset(p, 0, __per_cpu_data_end - __per_cpu_start);
    1.20 @@ -27,13 +28,28 @@ static int init_percpu_area(unsigned int
    1.21      return 0;
    1.22  }
    1.23  
    1.24 -static void free_percpu_area(unsigned int cpu)
    1.25 +struct free_info {
    1.26 +    unsigned int cpu;
    1.27 +    struct rcu_head rcu;
    1.28 +};
    1.29 +static DEFINE_PER_CPU(struct free_info, free_info);
    1.30 +
    1.31 +static void _free_percpu_area(struct rcu_head *head)
    1.32  {
    1.33 +    struct free_info *info = container_of(head, struct free_info, rcu);
    1.34 +    unsigned int cpu = info->cpu;
    1.35      char *p = __per_cpu_start + __per_cpu_offset[cpu];
    1.36      free_xenheap_pages(p, PERCPU_ORDER);
    1.37      __per_cpu_offset[cpu] = INVALID_PERCPU_AREA;
    1.38  }
    1.39  
    1.40 +static void free_percpu_area(unsigned int cpu)
    1.41 +{
    1.42 +    struct free_info *info = &per_cpu(free_info, cpu);
    1.43 +    info->cpu = cpu;
    1.44 +    call_rcu(&info->rcu, _free_percpu_area);
    1.45 +}
    1.46 +
    1.47  static int cpu_percpu_callback(
    1.48      struct notifier_block *nfb, unsigned long action, void *hcpu)
    1.49  {