WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] lockprof: Fix x86_32 build and clean up c

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] lockprof: Fix x86_32 build and clean up coding style
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 15 Oct 2009 01:40:17 -0700
Delivery-date: Thu, 15 Oct 2009 01:41:13 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1255591773 -3600
# Node ID 9e24f7f9d7a8c59747c4d7cd75215958d231f0b9
# Parent  cc8044c5da4c99149bc8aca68de299db8aa56b45
lockprof: Fix x86_32 build and clean up coding style

Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
 tools/misc/xenlockprof.c   |   35 ++++++++-------
 xen/common/spinlock.c      |  103 ++++++++++++++++++++-------------------------
 xen/include/xen/spinlock.h |    8 +--
 3 files changed, 69 insertions(+), 77 deletions(-)

diff -r cc8044c5da4c -r 9e24f7f9d7a8 tools/misc/xenlockprof.c
--- a/tools/misc/xenlockprof.c  Thu Oct 15 08:16:42 2009 +0100
+++ b/tools/misc/xenlockprof.c  Thu Oct 15 08:29:33 2009 +0100
@@ -16,6 +16,7 @@
 #include <sys/mman.h>
 #include <errno.h>
 #include <string.h>
+#include <inttypes.h>
 
 static int lock_pages(void *addr, size_t len)
 {
@@ -42,7 +43,7 @@ int main(int argc, char *argv[])
     char               name[60];
     xc_lockprof_data_t *data;
 
-    if ((argc > 2) || ((argc == 2) && (strcmp(argv[1], "-r") != 0)))
+    if ( (argc > 2) || ((argc == 2) && (strcmp(argv[1], "-r") != 0)) )
     {
         printf("%s: [-r]\n", argv[0]);
         printf("no args: print lock profile data\n");
@@ -50,28 +51,28 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    if ((xc_handle = xc_interface_open()) == -1)
+    if ( (xc_handle = xc_interface_open()) == -1 )
     {
         fprintf(stderr, "Error opening xc interface: %d (%s)\n",
                 errno, strerror(errno));
         return 1;
     }
 
-    if (argc > 1)
+    if ( argc > 1 )
     {
-        if (xc_lockprof_control(xc_handle, XEN_SYSCTL_LOCKPROF_reset, NULL,
-                                NULL, NULL) != 0)
+        if ( xc_lockprof_control(xc_handle, XEN_SYSCTL_LOCKPROF_reset, NULL,
+                                 NULL, NULL) != 0 )
         {
             fprintf(stderr, "Error reseting profile data: %d (%s)\n",
                     errno, strerror(errno));
             return 1;
         }
-        return 1;
+        return 0;
     }
 
     n = 0;
-    if (xc_lockprof_control(xc_handle, XEN_SYSCTL_LOCKPROF_query, &n,
-                            NULL, NULL) != 0)
+    if ( xc_lockprof_control(xc_handle, XEN_SYSCTL_LOCKPROF_query, &n,
+                             NULL, NULL) != 0 )
     {
         fprintf(stderr, "Error getting number of profile records: %d (%s)\n",
                 errno, strerror(errno));
@@ -80,7 +81,7 @@ int main(int argc, char *argv[])
 
     n += 32;    /* just to be sure */
     data = malloc(sizeof(*data) * n);
-    if ((data == NULL) || (lock_pages(data, sizeof(*data) * n) != 0))
+    if ( (data == NULL) || (lock_pages(data, sizeof(*data) * n) != 0) )
     {
         fprintf(stderr, "Could not alloc or lock buffers: %d (%s)\n",
                 errno, strerror(errno));
@@ -89,7 +90,7 @@ int main(int argc, char *argv[])
 
     i = n;
     if ( xc_lockprof_control(xc_handle, XEN_SYSCTL_LOCKPROF_query, &i,
-                             &time, data) != 0)
+                             &time, data) != 0 )
     {
         fprintf(stderr, "Error getting profile records: %d (%s)\n",
                 errno, strerror(errno));
@@ -98,16 +99,17 @@ int main(int argc, char *argv[])
 
     unlock_pages(data, sizeof(*data) * n);
 
-    if (i > n)
+    if ( i > n )
     {
         printf("data incomplete, %d records are missing!\n\n", i - n);
         i = n;
     }
+
     sl = 0;
     sb = 0;
-    for (j = 0; j < i; j++)
+    for ( j = 0; j < i; j++ )
     {
-        switch (data[j].type)
+        switch ( data[j].type )
         {
         case LOCKPROF_TYPE_GLOBAL:
             sprintf(name, "global lock %s", data[j].name);
@@ -117,15 +119,16 @@ int main(int argc, char *argv[])
             break;
         default:
             sprintf(name, "unknown type(%d) %d lock %s", data[j].type,
-                data[j].idx, data[j].name);
+                    data[j].idx, data[j].name);
             break;
         }
         l = (double)(data[j].lock_time) / 1E+09;
         b = (double)(data[j].block_time) / 1E+09;
         sl += l;
         sb += b;
-        printf("%-50s: lock:%12ld(%20.9fs), block:%12ld(%20.9fs)\n",
-            name, data[j].lock_cnt, l, data[j].block_cnt, b);
+        printf("%-50s: lock:%12"PRId64"(%20.9fs), "
+               "block:%12"PRId64"(%20.9fs)\n",
+               name, data[j].lock_cnt, l, data[j].block_cnt, b);
     }
     l = (double)time / 1E+09;
     printf("total profiling time: %20.9fs\n", l);
diff -r cc8044c5da4c -r 9e24f7f9d7a8 xen/common/spinlock.c
--- a/xen/common/spinlock.c     Thu Oct 15 08:16:42 2009 +0100
+++ b/xen/common/spinlock.c     Thu Oct 15 08:29:33 2009 +0100
@@ -314,54 +314,48 @@ int _rw_is_write_locked(rwlock_t *lock)
 }
 
 #ifdef LOCK_PROFILE
+
 struct lock_profile_anc {
     struct lock_profile_qhead *head_q;   /* first head of this type */
     char                      *name;     /* descriptive string for print */
 };
 
-typedef void lock_profile_subfunc(struct lock_profile *, int32_t, int32_t,
-                                  void *);
+typedef void lock_profile_subfunc(
+    struct lock_profile *, int32_t, int32_t, void *);
 
 extern struct lock_profile *__lock_profile_start;
 extern struct lock_profile *__lock_profile_end;
 
-static s_time_t lock_profile_start = 0;
+static s_time_t lock_profile_start;
 static struct lock_profile_anc lock_profile_ancs[LOCKPROF_TYPE_N];
 static struct lock_profile_qhead lock_profile_glb_q;
 static spinlock_t lock_profile_lock = SPIN_LOCK_UNLOCKED;
 
 static void spinlock_profile_iterate(lock_profile_subfunc *sub, void *par)
 {
-    int  i;
+    int i;
     struct lock_profile_qhead *hq;
     struct lock_profile *eq;
 
     spin_lock(&lock_profile_lock);
-    for (i = 0; i < LOCKPROF_TYPE_N; i++)
-    {
-        for (hq = lock_profile_ancs[i].head_q; hq; hq = hq->head_q)
-        {
-            for (eq = hq->elem_q; eq; eq = eq->next)
-            {
+    for ( i = 0; i < LOCKPROF_TYPE_N; i++ )
+        for ( hq = lock_profile_ancs[i].head_q; hq; hq = hq->head_q )
+            for ( eq = hq->elem_q; eq; eq = eq->next )
                 sub(eq, i, hq->idx, par);
-            }
-        }
-    }
     spin_unlock(&lock_profile_lock);
-    return;
 }
 
 static void spinlock_profile_print_elem(struct lock_profile *data,
     int32_t type, int32_t idx, void *par)
 {
-    if (type == LOCKPROF_TYPE_GLOBAL)
+    if ( type == LOCKPROF_TYPE_GLOBAL )
         printk("%s %s:\n", lock_profile_ancs[idx].name, data->name);
     else
         printk("%s %d %s:\n", lock_profile_ancs[idx].name, idx, data->name);
-    printk("  lock:%12ld(%08X:%08X), block:%12ld(%08X:%08X)\n",
-        data->lock_cnt, (u32)(data->time_hold >> 32), (u32)data->time_hold,
-        data->block_cnt, (u32)(data->time_block >> 32), (u32)data->time_block);
-    return;
+    printk("  lock:%12"PRId64"(%08X:%08X), block:%12"PRId64"(%08X:%08X)\n",
+           data->lock_cnt, (u32)(data->time_hold >> 32), (u32)data->time_hold,
+           data->block_cnt, (u32)(data->time_block >> 32),
+           (u32)data->time_block);
 }
 
 void spinlock_profile_printall(unsigned char key)
@@ -374,7 +368,6 @@ void spinlock_profile_printall(unsigned 
         "total = %08X:%08X)\n", (u32)(now>>32), (u32)now,
         (u32)(diff>>32), (u32)diff);
     spinlock_profile_iterate(spinlock_profile_print_elem, NULL);
-    return;
 }
 
 static void spinlock_profile_reset_elem(struct lock_profile *data,
@@ -384,7 +377,6 @@ static void spinlock_profile_reset_elem(
     data->block_cnt = 0;
     data->time_hold = 0;
     data->time_block = 0;
-    return;
 }
 
 void spinlock_profile_reset(unsigned char key)
@@ -396,7 +388,6 @@ void spinlock_profile_reset(unsigned cha
             (u32)(now>>32), (u32)now);
     lock_profile_start = now;
     spinlock_profile_iterate(spinlock_profile_reset_elem, NULL);
-    return;
 }
 
 typedef struct {
@@ -407,14 +398,13 @@ static void spinlock_profile_ucopy_elem(
 static void spinlock_profile_ucopy_elem(struct lock_profile *data,
     int32_t type, int32_t idx, void *par)
 {
-    spinlock_profile_ucopy_t *p;
+    spinlock_profile_ucopy_t *p = par;
     xen_sysctl_lockprof_data_t elem;
 
-    p = (spinlock_profile_ucopy_t *)par;
-    if (p->rc)
+    if ( p->rc )
         return;
 
-    if (p->pc->nr_elem < p->pc->max_elem)
+    if ( p->pc->nr_elem < p->pc->max_elem )
     {
         safe_strcpy(elem.name, data->name);
         elem.type = type;
@@ -423,46 +413,43 @@ static void spinlock_profile_ucopy_elem(
         elem.block_cnt = data->block_cnt;
         elem.lock_time = data->time_hold;
         elem.block_time = data->time_block;
-        if (copy_to_guest_offset(p->pc->data, p->pc->nr_elem, &elem, 1))
-        {
+        if ( copy_to_guest_offset(p->pc->data, p->pc->nr_elem, &elem, 1) )
             p->rc = -EFAULT;
-            return;
-        }
-    }
-    p->pc->nr_elem++;
-    
-    return;
+    }
+
+    if ( !p->rc )
+        p->pc->nr_elem++;
 }
 
 /* Dom0 control of lock profiling */
 int spinlock_profile_control(xen_sysctl_lockprof_op_t *pc)
 {
-    int rc;
+    int rc = 0;
     spinlock_profile_ucopy_t par;
 
-    rc = 0;
-    switch (pc->cmd)
+    switch ( pc->cmd )
     {
     case XEN_SYSCTL_LOCKPROF_reset:
         spinlock_profile_reset('\0');
         break;
     case XEN_SYSCTL_LOCKPROF_query:
-       pc->nr_elem = 0;
-       par.rc = 0;
-       par.pc = pc;
+        pc->nr_elem = 0;
+        par.rc = 0;
+        par.pc = pc;
         spinlock_profile_iterate(spinlock_profile_ucopy_elem, &par);
         pc->time = NOW() - lock_profile_start;
-       rc = par.rc;
+        rc = par.rc;
         break;
     default:
         rc = -EINVAL;
         break;
     }
+
     return rc;
 }
 
-void _lock_profile_register_struct(int32_t type,
-    struct lock_profile_qhead *qhead, int32_t idx, char *name)
+void _lock_profile_register_struct(
+    int32_t type, struct lock_profile_qhead *qhead, int32_t idx, char *name)
 {
     qhead->idx = idx;
     spin_lock(&lock_profile_lock);
@@ -470,39 +457,41 @@ void _lock_profile_register_struct(int32
     lock_profile_ancs[type].head_q = qhead;
     lock_profile_ancs[type].name = name;
     spin_unlock(&lock_profile_lock);
-    return;
-}
-
-void _lock_profile_deregister_struct(int32_t type,
-    struct lock_profile_qhead *qhead)
+}
+
+void _lock_profile_deregister_struct(
+    int32_t type, struct lock_profile_qhead *qhead)
 {
     struct lock_profile_qhead **q;
 
     spin_lock(&lock_profile_lock);
-    for (q = &lock_profile_ancs[type].head_q; *q; q = &((*q)->head_q))
-    {
-        if (*q == qhead)
+    for ( q = &lock_profile_ancs[type].head_q; *q; q = &(*q)->head_q )
+    {
+        if ( *q == qhead )
         {
             *q = qhead->head_q;
             break;
         }
     }
     spin_unlock(&lock_profile_lock);
-    return;
 }
 
 static int __init lock_prof_init(void)
 {
     struct lock_profile **q;
 
-    for (q = &__lock_profile_start; q < &__lock_profile_end; q++)
+    for ( q = &__lock_profile_start; q < &__lock_profile_end; q++ )
     {
         (*q)->next = lock_profile_glb_q.elem_q;
-       lock_profile_glb_q.elem_q = *q;
-    }
-    _lock_profile_register_struct(LOCKPROF_TYPE_GLOBAL, &lock_profile_glb_q,
+        lock_profile_glb_q.elem_q = *q;
+    }
+
+    _lock_profile_register_struct(
+        LOCKPROF_TYPE_GLOBAL, &lock_profile_glb_q,
         0, "Global lock");
+
     return 0;
 }
 __initcall(lock_prof_init);
-#endif
+
+#endif /* LOCK_PROFILE */
diff -r cc8044c5da4c -r 9e24f7f9d7a8 xen/include/xen/spinlock.h
--- a/xen/include/xen/spinlock.h        Thu Oct 15 08:16:42 2009 +0100
+++ b/xen/include/xen/spinlock.h        Thu Oct 15 08:29:33 2009 +0100
@@ -85,12 +85,12 @@ struct lock_profile_qhead {
 #define spin_lock_init_prof(s, l)                                             \
     do {                                                                      \
         (s)->l = (spinlock_t)_SPIN_LOCK_UNLOCKED(_LOCK_PROFILE(#l));          \
-       (s)->l.profile.next = (s)->profile_head.elem_q;                       \
-       (s)->profile_head.elem_q = &((s)->l.profile);                         \
+        (s)->l.profile.next = (s)->profile_head.elem_q;                       \
+        (s)->profile_head.elem_q = &((s)->l.profile);                         \
     } while(0)
 
-void _lock_profile_register_struct(int32_t, struct lock_profile_qhead *,      \
-                                   int32_t, char *);
+void _lock_profile_register_struct(
+    int32_t, struct lock_profile_qhead *, int32_t, char *);
 void _lock_profile_deregister_struct(int32_t, struct lock_profile_qhead *);
 
 #define lock_profile_register_struct(type, ptr, idx, print)                   \

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] lockprof: Fix x86_32 build and clean up coding style, Xen patchbot-unstable <=