ia64/xen-unstable

changeset 14059:af3281c66e73

Add find_domain_rcu_lock() and domain_rcu_unlock().

Signed-off-by: Jose Renato Santos <jsantos@hpl.hp.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Feb 21 16:33:34 2007 +0000 (2007-02-21)
parents 97826d77bd4d
children 335a8280ab1d
files xen/common/domain.c xen/include/xen/sched.h
line diff
     1.1 --- a/xen/common/domain.c	Wed Feb 21 16:13:49 2007 +0000
     1.2 +++ b/xen/common/domain.c	Wed Feb 21 16:33:34 2007 +0000
     1.3 @@ -217,8 +217,10 @@ struct domain *get_domain_by_id(domid_t 
     1.4      struct domain *d;
     1.5  
     1.6      rcu_read_lock(&domlist_read_lock);
     1.7 -    d = rcu_dereference(domain_hash[DOMAIN_HASH(dom)]);
     1.8 -    while ( d != NULL )
     1.9 +
    1.10 +    for ( d = rcu_dereference(domain_hash[DOMAIN_HASH(dom)]);
    1.11 +          d != NULL;
    1.12 +          d = rcu_dereference(d->next_in_hashbucket) )
    1.13      {
    1.14          if ( d->domain_id == dom )
    1.15          {
    1.16 @@ -226,14 +228,34 @@ struct domain *get_domain_by_id(domid_t 
    1.17                  d = NULL;
    1.18              break;
    1.19          }
    1.20 -        d = rcu_dereference(d->next_in_hashbucket);
    1.21      }
    1.22 +
    1.23      rcu_read_unlock(&domlist_read_lock);
    1.24  
    1.25      return d;
    1.26  }
    1.27  
    1.28  
    1.29 +struct domain *find_domain_rcu_lock(domid_t dom)
    1.30 +{
    1.31 +    struct domain *d;
    1.32 +
    1.33 +    rcu_read_lock(&domlist_read_lock);
    1.34 +
    1.35 +    for ( d = rcu_dereference(domain_hash[DOMAIN_HASH(dom)]);
    1.36 +          d != NULL;
    1.37 +          d = rcu_dereference(d->next_in_hashbucket) )
    1.38 +    {
    1.39 +        if ( d->domain_id == dom )
    1.40 +            return d;
    1.41 +    }
    1.42 +
    1.43 +    rcu_read_unlock(&domlist_read_lock);
    1.44 +
    1.45 +    return NULL;
    1.46 +}
    1.47 +
    1.48 +
    1.49  void domain_kill(struct domain *d)
    1.50  {
    1.51      domain_pause(d);
     2.1 --- a/xen/include/xen/sched.h	Wed Feb 21 16:13:49 2007 +0000
     2.2 +++ b/xen/include/xen/sched.h	Wed Feb 21 16:33:34 2007 +0000
     2.3 @@ -269,6 +269,21 @@ int construct_dom0(
     2.4      unsigned long initrd_start, unsigned long initrd_len,
     2.5      char *cmdline);
     2.6  
     2.7 +/*
     2.8 + * find_domain_rcu_lock() is more efficient than get_domain_by_id().
     2.9 + * This is the preferred function if the returned domain reference
    2.10 + * is short lived,  but it cannot be used if the domain reference needs 
    2.11 + * to be kept beyond the current scope (e.g., across a softirq).
    2.12 + * The returned domain reference must be discarded using domain_rcu_unlock().
    2.13 + */
    2.14 +struct domain *find_domain_rcu_lock(domid_t dom);
    2.15 +
    2.16 +/* Finish a RCU critical region started by find_domain_rcu_lock(). */
    2.17 +static inline void domain_rcu_unlock(struct domain *d)
    2.18 +{
    2.19 +    rcu_read_unlock(&domlist_read_lock);
    2.20 +}
    2.21 +
    2.22  struct domain *get_domain_by_id(domid_t dom);
    2.23  void domain_destroy(struct domain *d);
    2.24  void domain_kill(struct domain *d);