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

[Xen-changelog] [xen-4.0-testing] xentrace: Clean up initialisation.



# HG changeset patch
# User Keir Fraser <keir@xxxxxxx>
# Date 1292530691 0
# Node ID eebc0881bdf7dc37e07102101d76c47892623b37
# Parent  4cf3919db1b5b8d04f43887b389dbf9d4191feee
xentrace: Clean up initialisation.

Allocate no memory and print no debug messages when disabled.

Signed-off-by: Keir Fraser <keir@xxxxxxx>
xen-unstable changeset:   22567:f5f3cf4e001f
xen-unstable date:        Thu Dec 16 20:07:03 2010 +0000
---
 xen/common/trace.c |  118 +++++++++++++++++++++++------------------------------
 1 files changed, 53 insertions(+), 65 deletions(-)

diff -r 4cf3919db1b5 -r eebc0881bdf7 xen/common/trace.c
--- a/xen/common/trace.c        Thu Dec 16 20:13:47 2010 +0000
+++ b/xen/common/trace.c        Thu Dec 16 20:18:11 2010 +0000
@@ -79,14 +79,8 @@ static u32 tb_event_mask = TRC_ALL;
 
 static void calc_tinfo_first_offset(void)
 {
-    int offset_in_bytes;
-    
-    offset_in_bytes = offsetof(struct t_info, mfn_offset[NR_CPUS]);
-
+    int offset_in_bytes = offsetof(struct t_info, mfn_offset[NR_CPUS]);
     t_info_first_offset = fit_to_type(uint32_t, offset_in_bytes);
-
-    gdprintk(XENLOG_INFO, "%s: NR_CPUs %d, offset_in_bytes %d, 
t_info_first_offset %u\n",
-           __func__, NR_CPUS, offset_in_bytes, (unsigned)t_info_first_offset);
 }
 
 /**
@@ -121,20 +115,36 @@ static int alloc_trace_bufs(void)
     int           i, cpu, order;
     unsigned long nr_pages;
     /* Start after a fixed-size array of NR_CPUS */
-    uint32_t *t_info_mfn_list = (uint32_t *)t_info;
-    int offset = t_info_first_offset;
-
-    BUG_ON(check_tbuf_size(opt_tbuf_size));
+    uint32_t *t_info_mfn_list;
+    int offset;
 
     if ( opt_tbuf_size == 0 )
         return -EINVAL;
 
-    if ( !t_info )
-    {
-        printk("%s: t_info not allocated, cannot allocate trace buffers!\n",
-               __func__);
+    if ( check_tbuf_size(opt_tbuf_size) )
+    {
+        printk("Xen trace buffers: tb size %d too large. "
+               "Tracing disabled.\n",
+               opt_tbuf_size);
         return -EINVAL;
     }
+
+    /* t_info size is fixed for now. Currently this works great, so there
+     * seems to be no need to make it dynamic. */
+    t_info = alloc_xenheap_pages(get_order_from_pages(T_INFO_PAGES), 0);
+    if ( t_info == NULL )
+    {
+        printk("Xen trace buffers: t_info allocation failed! "
+               "Tracing disabled.\n");
+        return -ENOMEM;
+    }
+
+    for ( i = 0; i < T_INFO_PAGES; i++ )
+        share_xen_page_with_privileged_guests(
+            virt_to_page(t_info) + i, XENSHARE_readonly);
+
+    t_info_mfn_list = (uint32_t *)t_info;
+    offset = t_info_first_offset;
 
     t_info->tbuf_size = opt_tbuf_size;
     printk(XENLOG_INFO "tbuf_size %d\n", t_info->tbuf_size);
@@ -241,7 +251,7 @@ static int tb_set_size(int size)
 
 
 
-    if ( (opt_tbuf_size != 0) )
+    if ( opt_tbuf_size != 0 )
     {
         if ( size != opt_tbuf_size )
             gdprintk(XENLOG_INFO, "tb_set_size from %d to %d not 
implemented\n",
@@ -252,20 +262,16 @@ static int tb_set_size(int size)
     if ( size <= 0 )
         return -EINVAL;
 
-    if ( check_tbuf_size(size) )
-    {
-        gdprintk(XENLOG_INFO, "tb size %d too large\n", size);
-        return -EINVAL;
-    }
-
     opt_tbuf_size = size;
 
-    if ( (ret = alloc_trace_bufs()) == 0 )
-        printk("Xen trace buffers: initialized\n");
-    else
+    if ( (ret = alloc_trace_bufs()) != 0 )
+    {
         opt_tbuf_size = 0;
-
-    return ret;
+        return ret;
+    }
+
+    printk("Xen trace buffers: initialized\n");
+    return 0;
 }
 
 int trace_will_trace_event(u32 event)
@@ -308,49 +314,31 @@ void __init init_trace_bufs(void)
     /* Calculate offset in u32 of first mfn */
     calc_tinfo_first_offset();
 
-    /* t_info size fixed at 2 pages for now.  That should be big enough / 
small enough
-     * until it's worth making it dynamic. */
-    t_info = alloc_xenheap_pages(1, 0);
-
-    if ( t_info == NULL )
-    {
-        printk("Xen trace buffers: t_info allocation failed!  Tracing 
disabled.\n");
-        return;
-    }
-
-    for(i = 0; i < NR_CPUS; i++)
+    /* Per-cpu t_lock initialisation. */
+    for ( i = 0; i < NR_CPUS; i++ )
         spin_lock_init(&per_cpu(t_lock, i));
 
-    for(i=0; i<T_INFO_PAGES; i++)
-        share_xen_page_with_privileged_guests(
-            virt_to_page(t_info) + i, XENSHARE_readonly);
-
     if ( opt_tbuf_size == 0 )
     {
         printk("Xen trace buffers: disabled\n");
-        return;
-    }
-    else if ( check_tbuf_size(opt_tbuf_size) )
-    {
-        gdprintk(XENLOG_INFO, "Xen trace buffers: "
-                 "tb size %d too large, disabling\n",
-                 opt_tbuf_size);
-        opt_tbuf_size = 0;
-    }
-
-    if ( alloc_trace_bufs() == 0 )
-    {
-        printk("Xen trace buffers: initialised\n");
-        wmb(); /* above must be visible before tb_init_done flag set */
-        tb_init_done = 1;
-    }
-    else
-    {
-        gdprintk(XENLOG_INFO, "Xen trace buffers: "
-                 "allocation size %d failed, disabling\n",
-                 opt_tbuf_size);
-        opt_tbuf_size = 0;
-    }
+        goto fail;
+    }
+
+    if ( alloc_trace_bufs() != 0 )
+    {
+        dprintk(XENLOG_INFO, "Xen trace buffers: "
+                "allocation size %d failed, disabling\n",
+                opt_tbuf_size);
+        goto fail;
+    }
+
+    printk("Xen trace buffers: initialised\n");
+    wmb(); /* above must be visible before tb_init_done flag set */
+    tb_init_done = 1;
+    return;
+
+ fail:
+    opt_tbuf_size = 0;
 }
 
 /**

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


 


Rackspace

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