ia64/xen-unstable

changeset 10052:7f98c67636f4

Fix xentrace to initialise the trace buffers if they are not set up.
Signed-off-by: Atsushi SAKAI <sakaia@jp.fujitsu.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri May 12 15:19:37 2006 +0100 (2006-05-12)
parents 1b55b85f8cb2
children b4842d0f49da
files tools/xentrace/xentrace.c
line diff
     1.1 --- a/tools/xentrace/xentrace.c	Fri May 12 15:17:21 2006 +0100
     1.2 +++ b/tools/xentrace/xentrace.c	Fri May 12 15:19:37 2006 +0100
     1.3 @@ -28,6 +28,8 @@
     1.4  
     1.5  #include <xenctrl.h>
     1.6  
     1.7 +#include "xc_private.h"
     1.8 +
     1.9  #define PERROR(_m, _a...)                                       \
    1.10  do {                                                            \
    1.11      int __saved_errno = errno;                                  \
    1.12 @@ -46,7 +48,7 @@ extern FILE *stderr;
    1.13  /* sleep for this long (milliseconds) between checking the trace buffers */
    1.14  #define POLL_SLEEP_MILLIS 100
    1.15  
    1.16 -
    1.17 +#define DEFAULT_TBUF_SIZE 20
    1.18  /***** The code **************************************************************/
    1.19  
    1.20  typedef struct settings_st {
    1.21 @@ -101,6 +103,26 @@ void write_rec(unsigned int cpu, struct 
    1.22      }
    1.23  }
    1.24  
    1.25 +void enable_tracing_or_die(int xc_handle) 
    1.26 +{
    1.27 +  int enable = 1;
    1.28 +  int tbsize = DEFAULT_TBUF_SIZE;
    1.29 +  
    1.30 +  if (xc_tbuf_enable(xc_handle, enable) != 0) {
    1.31 +    if (xc_tbuf_set_size(xc_handle, tbsize) != 0) {
    1.32 +      perror("set_size Hypercall failure");
    1.33 +      exit(1);
    1.34 +    }
    1.35 +    printf("Set default trace buffer allocation (%d pages)\n", tbsize);
    1.36 +    if (xc_tbuf_enable(xc_handle, enable) != 0) {
    1.37 +      perror("Could not enable trace buffers\n");
    1.38 +      exit(1);
    1.39 +    }
    1.40 +  }
    1.41 +  else
    1.42 +    printf("Tracing enabled\n");
    1.43 +}
    1.44 +
    1.45  /**
    1.46   * get_tbufs - get pointer to and size of the trace buffers
    1.47   * @mfn:  location to store mfn of the trace buffers to
    1.48 @@ -111,22 +133,37 @@ void write_rec(unsigned int cpu, struct 
    1.49   */
    1.50  void get_tbufs(unsigned long *mfn, unsigned long *size)
    1.51  {
    1.52 -    uint32_t size32;
    1.53 +    int ret;
    1.54 +    dom0_op_t op;                        /* dom0 op we'll build             */
    1.55      int xc_handle = xc_interface_open(); /* for accessing control interface */
    1.56 +    unsigned int tbsize;
    1.57  
    1.58 -    if (xc_tbuf_get_size(xc_handle, &size32) != 0)
    1.59 -        goto fail;
    1.60 -    *size = size32;
    1.61 +    enable_tracing_or_die(xc_handle);
    1.62  
    1.63 -    if (xc_tbuf_get_mfn(xc_handle, mfn) != 0)
    1.64 -        goto fail;
    1.65 +    if (xc_tbuf_get_size(xc_handle, &tbsize) != 0) {
    1.66 +      perror("Failure to get tbuf info from Xen. Guess size is 0?");
    1.67 +      exit(1);
    1.68 +    }
    1.69 +    else
    1.70 +      printf("Current tbuf size: 0x%x\n", tbsize);
    1.71 +    
    1.72 +
    1.73 +    op.cmd = DOM0_TBUFCONTROL;
    1.74 +    op.interface_version = DOM0_INTERFACE_VERSION;
    1.75 +    op.u.tbufcontrol.op  = DOM0_TBUF_GET_INFO;
    1.76 +
    1.77 +    ret = do_dom0_op(xc_handle, &op);
    1.78  
    1.79      xc_interface_close(xc_handle);
    1.80 -    return;
    1.81  
    1.82 -fail:
    1.83 -    PERROR("Failure to get trace buffer pointer from Xen");
    1.84 -    exit(EXIT_FAILURE);
    1.85 +    if ( ret != 0 )
    1.86 +    {
    1.87 +        PERROR("Failure to get trace buffer pointer from Xen");
    1.88 +        exit(EXIT_FAILURE);
    1.89 +    }
    1.90 +
    1.91 +    *mfn  = op.u.tbufcontrol.buffer_mfn;
    1.92 +    *size = op.u.tbufcontrol.size;
    1.93  }
    1.94  
    1.95  /**