ia64/xen-unstable

changeset 10064:18fceb2f6b2d

Use common code for enabling tracing via xenmon and xentrace, also fixing
the last two remaining xc_private.h users outside of libxc.

Signed-off-by: John Levon <john.levon@sun.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue May 16 09:18:25 2006 +0100 (2006-05-16)
parents 6a285d7d7b39
children c5551469f00e
files tools/libxc/xc_tbuf.c tools/libxc/xenctrl.h tools/xenmon/xenbaked.c tools/xentrace/xentrace.c
line diff
     1.1 --- a/tools/libxc/xc_tbuf.c	Tue May 16 09:15:19 2006 +0100
     1.2 +++ b/tools/libxc/xc_tbuf.c	Tue May 16 09:18:25 2006 +0100
     1.3 @@ -16,7 +16,7 @@
     1.4  
     1.5  #include "xc_private.h"
     1.6  
     1.7 -int xc_tbuf_enable(int xc_handle, int enable)
     1.8 +static int tbuf_enable(int xc_handle, int enable)
     1.9  {
    1.10    DECLARE_DOM0_OP;
    1.11  
    1.12 @@ -30,7 +30,7 @@ int xc_tbuf_enable(int xc_handle, int en
    1.13    return xc_dom0_op(xc_handle, &op);
    1.14  }
    1.15  
    1.16 -int xc_tbuf_set_size(int xc_handle, uint32_t size)
    1.17 +int xc_tbuf_set_size(int xc_handle, unsigned long size)
    1.18  {
    1.19    DECLARE_DOM0_OP;
    1.20  
    1.21 @@ -42,7 +42,7 @@ int xc_tbuf_set_size(int xc_handle, uint
    1.22    return xc_dom0_op(xc_handle, &op);
    1.23  }
    1.24  
    1.25 -int xc_tbuf_get_size(int xc_handle, uint32_t *size)
    1.26 +int xc_tbuf_get_size(int xc_handle, unsigned long *size)
    1.27  {
    1.28    int rc;
    1.29    DECLARE_DOM0_OP;
    1.30 @@ -57,10 +57,17 @@ int xc_tbuf_get_size(int xc_handle, uint
    1.31    return rc;
    1.32  }
    1.33  
    1.34 -int xc_tbuf_get_mfn(int xc_handle, unsigned long *mfn)
    1.35 +int xc_tbuf_enable(int xc_handle, size_t cnt, unsigned long *mfn,
    1.36 +    unsigned long *size)
    1.37  {
    1.38 +    DECLARE_DOM0_OP;
    1.39      int rc;
    1.40 -    DECLARE_DOM0_OP;
    1.41 +
    1.42 +    if ( xc_tbuf_set_size(xc_handle, cnt) != 0 )
    1.43 +        return -1;
    1.44 +
    1.45 +    if ( tbuf_enable(xc_handle, 1) != 0 )
    1.46 +        return -1;
    1.47  
    1.48      op.cmd = DOM0_TBUFCONTROL;
    1.49      op.interface_version = DOM0_INTERFACE_VERSION;
    1.50 @@ -68,8 +75,17 @@ int xc_tbuf_get_mfn(int xc_handle, unsig
    1.51  
    1.52      rc = xc_dom0_op(xc_handle, &op);
    1.53      if ( rc == 0 )
    1.54 -      *mfn = op.u.tbufcontrol.buffer_mfn;
    1.55 -    return rc;
    1.56 +    {
    1.57 +        *size = op.u.tbufcontrol.size;
    1.58 +        *mfn = op.u.tbufcontrol.buffer_mfn;
    1.59 +    }
    1.60 +
    1.61 +    return 0;
    1.62 +}
    1.63 +
    1.64 +int xc_tbuf_disable(int xc_handle)
    1.65 +{
    1.66 +    return tbuf_enable(xc_handle, 0);
    1.67  }
    1.68  
    1.69  int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask)
    1.70 @@ -95,3 +111,4 @@ int xc_tbuf_set_evt_mask(int xc_handle, 
    1.71  
    1.72      return do_dom0_op(xc_handle, &op);
    1.73  }
    1.74 +
     2.1 --- a/tools/libxc/xenctrl.h	Tue May 16 09:15:19 2006 +0100
     2.2 +++ b/tools/libxc/xenctrl.h	Tue May 16 09:18:25 2006 +0100
     2.3 @@ -529,15 +529,23 @@ long xc_get_tot_pages(int xc_handle, uin
     2.4   */
     2.5  
     2.6  /**
     2.7 - * This function enables or disables tracing. Trace buffer memory must
     2.8 - * be already allocated by setting the size to a non-zero value, otherwise
     2.9 - * tracing cannot be enabled.
    2.10 + * xc_tbuf_enable - enable tracing buffers
    2.11   *
    2.12   * @parm xc_handle a handle to an open hypervisor interface
    2.13 - * @parm enable the desired action, 1 for enable, 0 for disable
    2.14 - * @return 0 on success, -1 on failure.
    2.15 + * @parm cnt size of tracing buffers to create (in pages)
    2.16 + * @parm mfn location to store mfn of the trace buffers to
    2.17 + * @parm size location to store the size (in bytes) of a trace buffer to
    2.18 + *
    2.19 + * Gets the machine address of the trace pointer area and the size of the
    2.20 + * per CPU buffers.
    2.21   */
    2.22 -int xc_tbuf_enable(int xc_handle, int enable);
    2.23 +int xc_tbuf_enable(int xc_handle, size_t cnt, unsigned long *mfn,
    2.24 +    unsigned long *size);
    2.25 +
    2.26 +/*
    2.27 + * Disable tracing buffers.
    2.28 + */
    2.29 +int xc_tbuf_disable(int xc_handle);
    2.30  
    2.31  /**
    2.32   * This function sets the size of the trace buffers. Setting the size
    2.33 @@ -549,7 +557,7 @@ int xc_tbuf_enable(int xc_handle, int en
    2.34   * @parm size the size in pages per cpu for the trace buffers
    2.35   * @return 0 on success, -1 on failure.
    2.36   */
    2.37 -int xc_tbuf_set_size(int xc_handle, uint32_t size);
    2.38 +int xc_tbuf_set_size(int xc_handle, unsigned long size);
    2.39  
    2.40  /**
    2.41   * This function retrieves the current size of the trace buffers.
    2.42 @@ -559,16 +567,7 @@ int xc_tbuf_set_size(int xc_handle, uint
    2.43   * @parm size will contain the size in bytes for the trace buffers
    2.44   * @return 0 on success, -1 on failure.
    2.45   */
    2.46 -int xc_tbuf_get_size(int xc_handle, uint32_t *size);
    2.47 -
    2.48 -/**
    2.49 - * This function retrieves the machine frame of the trace buffer.
    2.50 -
    2.51 - * @parm xc_handle a handle to an open hypervisor interface
    2.52 - * @parm mfn will contain the machine frame of the buffer.
    2.53 - * @return 0 on success, -1 on failure.
    2.54 - */
    2.55 -int xc_tbuf_get_mfn(int xc_handle, unsigned long *mfn);
    2.56 +int xc_tbuf_get_size(int xc_handle, unsigned long *size);
    2.57  
    2.58  int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask);
    2.59  
     3.1 --- a/tools/xenmon/xenbaked.c	Tue May 16 09:15:19 2006 +0100
     3.2 +++ b/tools/xenmon/xenbaked.c	Tue May 16 09:18:25 2006 +0100
     3.3 @@ -35,6 +35,7 @@
     3.4  #include <sys/mman.h>
     3.5  #include <sys/stat.h>
     3.6  #include <sys/types.h>
     3.7 +#include <sys/ioctl.h>
     3.8  #include <fcntl.h>
     3.9  #include <unistd.h>
    3.10  #include <errno.h>
    3.11 @@ -46,7 +47,14 @@
    3.12  #include <sys/select.h>
    3.13  #include <xen/linux/evtchn.h>
    3.14  
    3.15 -#include "xc_private.h"
    3.16 +#define PERROR(_m, _a...)                                       \
    3.17 +do {                                                            \
    3.18 +    int __saved_errno = errno;                                  \
    3.19 +    fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a ,       \
    3.20 +            __saved_errno, strerror(__saved_errno));            \
    3.21 +    errno = __saved_errno;                                      \
    3.22 +} while (0)
    3.23 +
    3.24  typedef struct { int counter; } atomic_t;
    3.25  #define _atomic_read(v)		((v).counter)
    3.26  
    3.27 @@ -326,79 +334,34 @@ void wait_for_event(void)
    3.28    }
    3.29  }
    3.30  
    3.31 -void enable_tracing_or_die(int xc_handle) 
    3.32 +static void get_tbufs(unsigned long *mfn, unsigned long *size)
    3.33  {
    3.34 -  int enable = 1;
    3.35 -  int tbsize = DEFAULT_TBUF_SIZE;
    3.36 -  
    3.37 -  if (xc_tbuf_enable(xc_handle, enable) != 0) {
    3.38 -    if (xc_tbuf_set_size(xc_handle, tbsize) != 0) {
    3.39 -      perror("set_size Hypercall failure");
    3.40 -      exit(1);
    3.41 +    int xc_handle = xc_interface_open();
    3.42 +    int ret;
    3.43 +
    3.44 +    if ( xc_handle < 0 ) 
    3.45 +    {
    3.46 +        exit(EXIT_FAILURE);
    3.47      }
    3.48 -    printf("Set default trace buffer allocation (%d pages)\n", tbsize);
    3.49 -    if (xc_tbuf_enable(xc_handle, enable) != 0) {
    3.50 -      perror("Could not enable trace buffers\n");
    3.51 -      exit(1);
    3.52 +
    3.53 +    ret = xc_tbuf_enable(xc_handle, DEFAULT_TBUF_SIZE, mfn, size);
    3.54 +
    3.55 +    if ( ret != 0 )
    3.56 +    {
    3.57 +        perror("Couldn't enable trace buffers");
    3.58 +        exit(1);
    3.59      }
    3.60 -  }
    3.61 -  else
    3.62 -    printf("Tracing enabled\n");
    3.63 +
    3.64 +    xc_interface_close(xc_handle);
    3.65  }
    3.66  
    3.67  void disable_tracing(void)
    3.68  {
    3.69 -  int enable = 0;
    3.70    int xc_handle = xc_interface_open();
    3.71 -    
    3.72 -  xc_tbuf_enable(xc_handle, enable);
    3.73 +  xc_tbuf_disable(xc_handle);  
    3.74    xc_interface_close(xc_handle);
    3.75  }
    3.76  
    3.77 -
    3.78 -/**
    3.79 - * get_tbufs - get pointer to and size of the trace buffers
    3.80 - * @mfn:  location to store mfn of the trace buffers to
    3.81 - * @size: location to store the size of a trace buffer to
    3.82 - *
    3.83 - * Gets the machine address of the trace pointer area and the size of the
    3.84 - * per CPU buffers.
    3.85 - */
    3.86 -void get_tbufs(unsigned long *mfn, unsigned long *size)
    3.87 -{
    3.88 -    int ret;
    3.89 -    dom0_op_t op;                        /* dom0 op we'll build             */
    3.90 -    int xc_handle = xc_interface_open(); /* for accessing control interface */
    3.91 -    unsigned int tbsize;
    3.92 -
    3.93 -    enable_tracing_or_die(xc_handle);
    3.94 -
    3.95 -    if (xc_tbuf_get_size(xc_handle, &tbsize) != 0) {
    3.96 -      perror("Failure to get tbuf info from Xen. Guess size is 0?");
    3.97 -      exit(1);
    3.98 -    }
    3.99 -    else
   3.100 -      printf("Current tbuf size: 0x%x\n", tbsize);
   3.101 -    
   3.102 -
   3.103 -    op.cmd = DOM0_TBUFCONTROL;
   3.104 -    op.interface_version = DOM0_INTERFACE_VERSION;
   3.105 -    op.u.tbufcontrol.op  = DOM0_TBUF_GET_INFO;
   3.106 -
   3.107 -    ret = do_dom0_op(xc_handle, &op);
   3.108 -
   3.109 -    xc_interface_close(xc_handle);
   3.110 -
   3.111 -    if ( ret != 0 )
   3.112 -    {
   3.113 -        PERROR("Failure to get trace buffer pointer from Xen");
   3.114 -        exit(EXIT_FAILURE);
   3.115 -    }
   3.116 -
   3.117 -    *mfn  = op.u.tbufcontrol.buffer_mfn;
   3.118 -    *size = op.u.tbufcontrol.size;
   3.119 -}
   3.120 -
   3.121  /**
   3.122   * map_tbufs - memory map Xen trace buffers into user space
   3.123   * @tbufs_mfn: mfn of the trace buffers
     4.1 --- a/tools/xentrace/xentrace.c	Tue May 16 09:15:19 2006 +0100
     4.2 +++ b/tools/xentrace/xentrace.c	Tue May 16 09:18:25 2006 +0100
     4.3 @@ -28,8 +28,6 @@
     4.4  
     4.5  #include <xenctrl.h>
     4.6  
     4.7 -#include "xc_private.h"
     4.8 -
     4.9  #define PERROR(_m, _a...)                                       \
    4.10  do {                                                            \
    4.11      int __saved_errno = errno;                                  \
    4.12 @@ -103,67 +101,25 @@ void write_rec(unsigned int cpu, struct 
    4.13      }
    4.14  }
    4.15  
    4.16 -void enable_tracing_or_die(int xc_handle) 
    4.17 +static void get_tbufs(unsigned long *mfn, unsigned long *size)
    4.18  {
    4.19 -  int enable = 1;
    4.20 -  int tbsize = DEFAULT_TBUF_SIZE;
    4.21 -  
    4.22 -  if (xc_tbuf_enable(xc_handle, enable) != 0) {
    4.23 -    if (xc_tbuf_set_size(xc_handle, tbsize) != 0) {
    4.24 -      perror("set_size Hypercall failure");
    4.25 -      exit(1);
    4.26 -    }
    4.27 -    printf("Set default trace buffer allocation (%d pages)\n", tbsize);
    4.28 -    if (xc_tbuf_enable(xc_handle, enable) != 0) {
    4.29 -      perror("Could not enable trace buffers\n");
    4.30 -      exit(1);
    4.31 -    }
    4.32 -  }
    4.33 -  else
    4.34 -    printf("Tracing enabled\n");
    4.35 -}
    4.36 +    int xc_handle = xc_interface_open();
    4.37 +    int ret;
    4.38  
    4.39 -/**
    4.40 - * get_tbufs - get pointer to and size of the trace buffers
    4.41 - * @mfn:  location to store mfn of the trace buffers to
    4.42 - * @size: location to store the size of a trace buffer to
    4.43 - *
    4.44 - * Gets the machine address of the trace pointer area and the size of the
    4.45 - * per CPU buffers.
    4.46 - */
    4.47 -void get_tbufs(unsigned long *mfn, unsigned long *size)
    4.48 -{
    4.49 -    int ret;
    4.50 -    dom0_op_t op;                        /* dom0 op we'll build             */
    4.51 -    int xc_handle = xc_interface_open(); /* for accessing control interface */
    4.52 -    unsigned int tbsize;
    4.53 +    if ( xc_handle < 0 ) 
    4.54 +    {
    4.55 +        exit(EXIT_FAILURE);
    4.56 +    }
    4.57  
    4.58 -    enable_tracing_or_die(xc_handle);
    4.59 -
    4.60 -    if (xc_tbuf_get_size(xc_handle, &tbsize) != 0) {
    4.61 -      perror("Failure to get tbuf info from Xen. Guess size is 0?");
    4.62 -      exit(1);
    4.63 -    }
    4.64 -    else
    4.65 -      printf("Current tbuf size: 0x%x\n", tbsize);
    4.66 -    
    4.67 -
    4.68 -    op.cmd = DOM0_TBUFCONTROL;
    4.69 -    op.interface_version = DOM0_INTERFACE_VERSION;
    4.70 -    op.u.tbufcontrol.op  = DOM0_TBUF_GET_INFO;
    4.71 -
    4.72 -    ret = do_dom0_op(xc_handle, &op);
    4.73 -
    4.74 -    xc_interface_close(xc_handle);
    4.75 +    ret = xc_tbuf_enable(xc_handle, DEFAULT_TBUF_SIZE, mfn, size);
    4.76  
    4.77      if ( ret != 0 )
    4.78      {
    4.79 -        PERROR("Failure to get trace buffer pointer from Xen");
    4.80 -        exit(EXIT_FAILURE);
    4.81 +        perror("Couldn't enable trace buffers");
    4.82 +        exit(1);
    4.83      }
    4.84  
    4.85 -    *mfn  = op.u.tbufcontrol.buffer_mfn;
    4.86 -    *size = op.u.tbufcontrol.size;
    4.87 +    xc_interface_close(xc_handle);
    4.88  }
    4.89  
    4.90  /**