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

[Xen-devel] [PATCH] use atomic_t type for system wide credit scheduler statistics



Current code is not SMP safe. Use atomic_t type instead.

Thanks,
xiaowei
diff -r 5b9f282679ae -r 7b843d53b3ea xen/common/sched_credit.c
--- a/xen/common/sched_credit.c Mon Mar 09 00:09:52 2009 +0800
+++ b/xen/common/sched_credit.c Mon Mar 09 01:26:09 2009 +0800
@@ -79,12 +79,17 @@
  */
 #ifdef CSCHED_STATS
 
-#define CSCHED_STAT(_X)         (csched_priv.stats._X)
-#define CSCHED_STAT_DEFINE(_X)  uint32_t _X;
+#define CSCHED_STAT(_X)         (atomic_read(&csched_priv.stats._X))
+#define CSCHED_STAT_DEFINE(_X)  atomic_t _X;
 #define CSCHED_STAT_PRINTK(_X)                                  \
     do                                                          \
     {                                                           \
-        printk("\t%-30s = %u\n", #_X, CSCHED_STAT(_X));  \
+        printk("\t%-30s = %i\n", #_X, CSCHED_STAT(_X));         \
+    } while ( 0 );
+#define CSCHED_STAT_RESET(_X)                                   \
+    do                                                          \
+    {                                                           \
+        atomic_set(&csched_priv.stats._X, 0);                   \
     } while ( 0 );
 
 /*
@@ -137,12 +142,6 @@
     CSCHED_STATS_EXPAND_CHECKS(_MACRO)      \
     CSCHED_STATS_EXPAND_SCHED(_MACRO)
 
-#define CSCHED_STATS_RESET()                                        \
-    do                                                              \
-    {                                                               \
-        memset(&csched_priv.stats, 0, sizeof(csched_priv.stats));   \
-    } while ( 0 )
-
 #define CSCHED_STATS_DEFINE()                   \
     struct                                      \
     {                                           \
@@ -156,7 +155,13 @@
         CSCHED_STATS_EXPAND(CSCHED_STAT_PRINTK) \
     } while ( 0 )
 
-#define CSCHED_STAT_CRANK(_X)               (CSCHED_STAT(_X)++)
+#define CSCHED_STATS_RESET()                    \
+    do                                          \
+    {                                           \
+        CSCHED_STATS_EXPAND(CSCHED_STAT_RESET)  \
+    } while ( 0 )
+
+#define CSCHED_STAT_CRANK(_X)               (atomic_inc(&csched_priv.stats._X))
 
 #define CSCHED_VCPU_STATS_RESET(_V)                     \
     do                                                  \
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.