Skip to contentSkip to conversation

Avoid panic when adjusting sedf parameters

PATCH In review Juergen Gross 3 participants 9 messages Nov 17, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Avoid panic when adjusting sedf parameters

When using sedf scheduler in a cpupool the system might panic when setting sedf scheduling parameters for a domain.
Introduces for_each_domain_in_cpupool macro as it is usable 4 times now.

Signed-off-by [email protected]
4 files changed, 12 insertions(+), 11 deletions(-)
xen/common/cpupool.c    |    4 +---
xen/common/sched_sedf.c |    8 ++++----
xen/common/schedule.c   |    5 +----
xen/include/xen/sched.h |    6 ++++++

# HG changeset patch
# User Juergen Gross <[email protected]> # Date 1321534918 -3600
# Node ID 8eea2b53adb207b8ab92148c8248b60831639e52 # Parent dbdc840f8f62db58321b5009e5e0f7833066386f Avoid panic when adjusting sedf parameters

When using sedf scheduler in a cpupool the system might panic when setting sedf scheduling parameters for a domain.
Introduces for_each_domain_in_cpupool macro as it is usable 4 times now.

Signed-off-by [email protected]
xen/common/cpupool.c +1 -3
diff -r dbdc840f8f62 -r 8eea2b53adb2 xen/common/cpupool.c
@@ -309,10 +309,8 @@ int cpupool_unassign_cpu(struct cpupool 
     if ( (c->n_dom > 0) && (cpumask_weight(c->cpu_valid) == 1) &&
          (cpu != cpupool_moving_cpu) )
     {
-        for_each_domain(d)
+        for_each_domain_in_cpupool(d, c)
         {
-            if ( d->cpupool != c )
-                continue;
             if ( !d->is_dying )
             {
                 ret = -EBUSY;
xen/common/sched_sedf.c +4 -4
diff -r dbdc840f8f62 -r 8eea2b53adb2 xen/common/sched_sedf.c
@@ -1304,6 +1304,8 @@ static void sedf_dump_cpu_state(const st
     rcu_read_lock(&domlist_read_lock);
     for_each_domain ( d )
     {
+        if ( (d->cpupool ? d->cpupool->sched : &sched_sedf_def) != ops )
+            continue;
         for_each_vcpu(d, ed)
         {
             if ( !__task_on_queue(ed) && (ed->processor == i) )
@@ -1335,10 +1337,8 @@ static int sedf_adjust_weights(struct cp
 
     /* Sum across all weights. */
     rcu_read_lock(&domlist_read_lock);
-    for_each_domain( d )
+    for_each_domain_in_cpupool( d, c )
     {
-        if ( c != d->cpupool )
-            continue;
         for_each_vcpu( d, p )
         {
             if ( (cpu = p->processor) >= nr_cpus )
@@ -1367,7 +1367,7 @@ static int sedf_adjust_weights(struct cp
 
     /* Adjust all slices (and periods) to the new weight. */
     rcu_read_lock(&domlist_read_lock);
-    for_each_domain( d )
+    for_each_domain_in_cpupool( d, c )
     {
         for_each_vcpu ( d, p )
         {
xen/common/schedule.c +1 -4
diff -r dbdc840f8f62 -r 8eea2b53adb2 xen/common/schedule.c
@@ -538,11 +538,8 @@ int cpu_disable_scheduler(unsigned int c
     if ( c == NULL )
         return ret;
 
-    for_each_domain ( d )
+    for_each_domain_in_cpupool ( d, c )
     {
-        if ( d->cpupool != c )
-            continue;
-
         affinity_broken = 0;
 
         for_each_vcpu ( d, v )
xen/include/xen/sched.h +6 -0
diff -r dbdc840f8f62 -r 8eea2b53adb2 xen/include/xen/sched.h
@@ -569,6 +569,12 @@ extern struct domain *domain_list;
        (_d) != NULL;                            \
        (_d) = rcu_dereference((_d)->next_in_list )) \
 
+#define for_each_domain_in_cpupool(_d,_c)       \
+ for ( (_d) = rcu_dereference(domain_list);     \
+       (_d) != NULL;                            \
+       (_d) = rcu_dereference((_d)->next_in_list )) \
+       if ((_d)->cpupool == (_c))
+
 #define for_each_vcpu(_d,_v)                    \
  for ( (_v) = (_d)->vcpu ? (_d)->vcpu[0] : NULL; \
        (_v) != NULL;                            \

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

xen/include/xen/sched.h extern struct domain *domain_list; · line 575

Quoted 11 lines
Quoted 1 line
Quoted 1 line · Juergen Gross
xen/include/xen/sched.h +4 -0
@@ -569,6 +569,12 @@ extern struct domain *domain_list;
       (_d) != NULL;                            \
       (_d) = rcu_dereference((_d)->next_in_list )) \
 
+#define for_each_domain_in_cpupool(_d,_c)       \
+ for ( (_d) = rcu_dereference(domain_list);     \
+       (_d) != NULL;                            \
+       (_d) = rcu_dereference((_d)->next_in_list )) \

Wouldn't this, up to here, simply be for_each_domain()?

xen/include/xen/sched.h extern struct domain *domain_list; · line 576

Quoted 1 line
xen/include/xen/sched.h +1 -0
+       if ((_d)->cpupool == (_c))

This is dangerous - consider code like

    if ( x )
        for_each_domain_in_cpupool ()
            function();
    else
        other_stuff;

which would now associate the else with the wrong (inner) if. One possible solution that comes to mind would be

#define for_each_domain_in_cpupool(_d,_c) \
    for_each_domain_in_cpupool (_d) \
        if ((_d)->cpupool != (_c)) \
            continue; \
        else

but I think I had seen a more clever solution to this problem, but cannot remember/locate it right now.

Jan

Quoted 4 lines
xen/include/xen/sched.h +1 -0
+
 #define for_each_vcpu(_d,_v)                    \
 for ( (_v) = (_d)->vcpu ? (_d)->vcpu[0] : NULL; \
       (_v) != NULL;                            \
#2 lore raw
Quoted 10 lines · Jan Beulich

xen/include/xen/sched.h extern struct domain *domain_list; · line 575

Quoted 4 lines
xen/include/xen/sched.h +4 -0
+#define for_each_domain_in_cpupool(_d,_c)       \
+ for ( (_d) = rcu_dereference(domain_list);     \
+       (_d) != NULL;                            \
+       (_d) = rcu_dereference((_d)->next_in_list )) \

Wouldn't this, up to here, simply be for_each_domain()?

Quoted 1 line

+ if ((_d)->cpupool == (_c))

This is dangerous - consider code like

I also wonder (and this is true for the existing open-coded versions too) whether we have sufficient locking around use of d->cpupool? Do these loops hold enough locks to ensure that d->cpupool doesn't change under their feet?

-- Keir

#3 lore raw
Quoted 6 lines · Keir Fraser
Quoted 4 lines · Jan Beulich
Quoted 4 lines
xen/include/xen/sched.h +4 -0
+#define for_each_domain_in_cpupool(_d,_c)       \
+ for ( (_d) = rcu_dereference(domain_list);     \
+       (_d) != NULL;                            \
+       (_d) = rcu_dereference((_d)->next_in_list )) \
Quoted 7 lines
Quoted 4 lines

Wouldn't this, up to here, simply be for_each_domain()?

Quoted 1 line

+ if ((_d)->cpupool == (_c))

This is dangerous - consider code like

I also wonder (and this is true for the existing open-coded versions too) whether we have sufficient locking around use of d->cpupool? Do these loops hold enough locks to ensure that d->cpupool doesn't change under their feet?

d->cpupool is changed in three functions:

I was just preparing a patch for cpupool_unassign_cpu() which is lacking rcu_lock_domain().
cpupool_add_domain() is called only for domains not yet in the domain list. sched_move_domain() is only called with domain lock held.

Juergen

Signature · 5 lines
Juergen Gross                 Principal Developer Operating Systems
PDG ES&S SWE OS6                       Telephone: +49 (0) 89 3222 2967
Fujitsu Technology Solutions              e-mail: [email protected]
Domagkstr. 28                           Internet: ts.fujitsu.com
D-80807 Muenchen                 Company details: ts.fujitsu.com/imprint.html
#4 lore raw
In reply to Jan Beulich
Quoted 11 lines · Jan Beulich

which would now associate the else with the wrong (inner) if. One possible solution that comes to mind would be

#define for_each_domain_in_cpupool(_d,_c) \
    for_each_domain_in_cpupool (_d) \
        if ((_d)->cpupool != (_c)) \
            continue; \
        else

but I think I had seen a more clever solution to this problem, but cannot remember/locate it right now.

Given the gcc ({}) construction, you could do a double-loop:

 for ( (_d) = rcu_dereference(domain_list);     \
       (_d) != NULL;                            \
       ({ while ((_d) = rcu_dereference((_d)->next_in_list != NULL)
             if ((_d)->cpupool == (_c)) break;
          (_d); }) )

A bit ugly. ;-) And I still worry about cpupool locking...

-- Keir

#5 lore raw
Quoted 13 lines · Keir Fraser
Quoted 11 lines · Jan Beulich

which would now associate the else with the wrong (inner) if. One possible solution that comes to mind would be

#define for_each_domain_in_cpupool(_d,_c) \
     for_each_domain_in_cpupool (_d) \
         if ((_d)->cpupool != (_c)) \
             continue; \
         else

but I think I had seen a more clever solution to this problem, but cannot remember/locate it right now.

Quoted 8 lines

Given the gcc ({}) construction, you could do a double-loop:

  for ( (_d) = rcu_dereference(domain_list);     \
        (_d) != NULL;                            \
        ({ while ((_d) = rcu_dereference((_d)->next_in_list != NULL)
              if ((_d)->cpupool == (_c)) break;
           (_d); }) )

A bit ugly. ;-) And I still worry about cpupool locking...

What about:

static inline struct domain *next_domain_in_cpupool(
struct domain *d, struct cpupool *c)

{
    for (d = rcu_dereference(d->next_in_list); d && d->cpupool != c;
         d = rcu_dereference(d->next_in_list));
    return d;
}
#define for_each_domain_in_cpupool(_d,_c)       \
 for ( (_d) = rcu_dereference(domain_list);     \
       (_d) != NULL;                            \
       (_d) = next_domain_in_cpupool((_d), (_c)))

Juergen

Signature · 5 lines
Juergen Gross                 Principal Developer Operating Systems
PDG ES&S SWE OS6                       Telephone: +49 (0) 89 3222 2967
Fujitsu Technology Solutions              e-mail: [email protected]
Domagkstr. 28                           Internet: ts.fujitsu.com
D-80807 Muenchen                 Company details: ts.fujitsu.com/imprint.html
#6 lore raw
Quoted 34 lines
Quoted 1 line
Quoted 1 line · Juergen Gross
Quoted 13 lines · Keir Fraser
Quoted 11 lines · Jan Beulich

which would now associate the else with the wrong (inner) if. One possible solution that comes to mind would be

#define for_each_domain_in_cpupool(_d,_c) \
     for_each_domain_in_cpupool (_d) \
         if ((_d)->cpupool != (_c)) \
             continue; \
         else

but I think I had seen a more clever solution to this problem, but cannot remember/locate it right now.

Quoted 8 lines

Given the gcc ({}) construction, you could do a double-loop:

  for ( (_d) = rcu_dereference(domain_list);     \
        (_d) != NULL;                            \
        ({ while ((_d) = rcu_dereference((_d)->next_in_list != NULL)
              if ((_d)->cpupool == (_c)) break;
           (_d); }) )

A bit ugly. ;-) And I still worry about cpupool locking...

What about:

static inline struct domain *next_domain_in_cpupool(
struct domain *d, struct cpupool *c)

{
     for (d = rcu_dereference(d->next_in_list); d && d->cpupool != c;
          d = rcu_dereference(d->next_in_list));
     return d;
}
Quoted 4 lines

#define for_each_domain_in_cpupool(_d,_c) \

  for ( (_d) = rcu_dereference(domain_list);     \
        (_d) != NULL;                            \
        (_d) = next_domain_in_cpupool((_d), (_c)))

Same problem as with Keir's variant - you'd enter the loop body for the first domain on the list regardless of its cpupool. But with a first_domain_in_cpupool() counterpart this might be usable. Or, as said in the other reply, putting a more complex construct in the middle clause.

Jan

#7 lore raw
Quoted 37 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · Juergen Gross
Quoted 13 lines · Keir Fraser
Quoted 11 lines · Jan Beulich

which would now associate the else with the wrong (inner) if. One possible solution that comes to mind would be

#define for_each_domain_in_cpupool(_d,_c) \
      for_each_domain_in_cpupool (_d) \
          if ((_d)->cpupool != (_c)) \
              continue; \
          else

but I think I had seen a more clever solution to this problem, but cannot remember/locate it right now.

Quoted 8 lines

Given the gcc ({}) construction, you could do a double-loop:

   for ( (_d) = rcu_dereference(domain_list);     \
         (_d) != NULL;                            \
         ({ while ((_d) = rcu_dereference((_d)->next_in_list != NULL)
               if ((_d)->cpupool == (_c)) break;
            (_d); }) )

A bit ugly. ;-) And I still worry about cpupool locking...

What about:

static inline struct domain *next_domain_in_cpupool(
struct domain *d, struct cpupool *c)

{
      for (d = rcu_dereference(d->next_in_list); d&&  d->cpupool != c;
           d = rcu_dereference(d->next_in_list));
      return d;
}
Quoted 4 lines
#define for_each_domain_in_cpupool(_d,_c)       \
   for ( (_d) = rcu_dereference(domain_list);     \
         (_d) != NULL;                            \
         (_d) = next_domain_in_cpupool((_d), (_c)))
Quoted 5 lines

Same problem as with Keir's variant - you'd enter the loop body for the first domain on the list regardless of its cpupool. But with a first_domain_in_cpupool() counterpart this might be usable. Or, as said in the other reply, putting a more complex construct in the middle clause.

I think adding first_domain_in_cpupool() is a good way to go. Sending out adjusted patch with appropriate locking added in cpupool_unassign_cpu() soon.

Juergen

Signature · 5 lines
Juergen Gross                 Principal Developer Operating Systems
PDG ES&S SWE OS6                       Telephone: +49 (0) 89 3222 2967
Fujitsu Technology Solutions              e-mail: [email protected]
Domagkstr. 28                           Internet: ts.fujitsu.com
D-80807 Muenchen                 Company details: ts.fujitsu.com/imprint.html
#8 lore raw
In reply to Keir Fraser
Quoted 15 lines
Quoted 1 line
Quoted 1 line · Keir Fraser
Quoted 11 lines · Jan Beulich

which would now associate the else with the wrong (inner) if. One possible solution that comes to mind would be

#define for_each_domain_in_cpupool(_d,_c) \
    for_each_domain_in_cpupool (_d) \
        if ((_d)->cpupool != (_c)) \
            continue; \
        else

but I think I had seen a more clever solution to this problem, but cannot remember/locate it right now.

Quoted 8 lines

Given the gcc ({}) construction, you could do a double-loop:

 for ( (_d) = rcu_dereference(domain_list);     \
       (_d) != NULL;                            \
       ({ while ((_d) = rcu_dereference((_d)->next_in_list != NULL)
             if ((_d)->cpupool == (_c)) break;
          (_d); }) )

A bit ugly. ;-) And I still worry about cpupool locking...

No - the very first domain would make into the body of the loop without its pool being checked. The (adjusted) construct would need to go into the checking (middle) portion of the for.

Jan