bitkeeper revision 1.911.1.1 (40abd5b2mqoey54uZKqDJrA-dD05Xw)
authoriap10@tetris.cl.cam.ac.uk <iap10@tetris.cl.cam.ac.uk>
Wed, 19 May 2004 21:46:26 +0000 (21:46 +0000)
committeriap10@tetris.cl.cam.ac.uk <iap10@tetris.cl.cam.ac.uk>
Wed, 19 May 2004 21:46:26 +0000 (21:46 +0000)
bandaid for xentrace. Really needs a Xen-visible trace buffer consumer
index, and a way of kicking the trace deamon...

tools/xentrace/Makefile
tools/xentrace/formats
tools/xentrace/xentrace.c
tools/xentrace/xentrace_format
xen/common/dom0_ops.c
xen/common/trace.c
xen/include/hypervisor-ifs/trace.h
xen/include/xen/trace.h

index 4a63ae2b3e092dbe8662403a6ce276c39c363fe6..d64d2a5a367fbf635febd0f56f9ffdb81ec9ed21 100644 (file)
@@ -1,6 +1,6 @@
 
 CC       = gcc
-CFLAGS   = -Wall -O3 
+CFLAGS   = -Wall -O3 -Werror
 CFLAGS  += -I../../xen/include/hypervisor-ifs
 CFLAGS  += -I../../xenolinux-sparse/include
 CFLAGS  += -I../xend/lib
index 726c199bd923f3bcaded4a1aa99608775de229f2..9a5b157f47a4102725a1904101d8aec17ccb86f7 100644 (file)
@@ -1,14 +1,35 @@
-0x00010000     CPU%(cpu)d 0x%(tsc)x sched_add_domain(0x%(3)08x)            [ dom id = 0x%(1)x%(2)08x   ]
-0x00010001     CPU%(cpu)d 0x%(tsc)x sched_rem_domain(0x%08(3)x)            [ dom id = 0x%(1)x%(2)08x   ]
-0x00010002     CPU%(cpu)d 0x%(tsc)x __wake_up(0x%(3)08x)                   [ dom id = 0x%(1)x%(2)08x   ]
-0x00010003     CPU%(cpu)d 0x%(tsc)x do_block()                             [ current = 0x%(2)08x         ]
-0x00010004     CPU%(cpu)d 0x%(tsc)x do_yield()                             [ current = %(2)08x         ]
-0x00010005     CPU%(cpu)d 0x%(tsc)x do_set_timer_op(0x%(4)08x, 0x%(5)08x)  [ current = 0x%(3)08x ]
-0x00010006     CPU%(cpu)d 0x%(tsc)x sched_ctl(0x%(1)08x)
-0x00010007     CPU%(cpu)d 0x%(tsc)x sched_adjdom(params)                   [ dom id = 0x%(1)x%(2)08x   ]
-0x00010008     CPU%(cpu)d 0x%(tsc)x __reschedule(0x%(3)08x)                [ dom id = 0x%(1)x%(2)08x   ]
-0x00010009     CPU%(cpu)d 0x%(tsc)x switching to task_struct 0x%(1)08x     [ dom id = 0x%(1)x     ]
-0x0001000A     CPU%(cpu)d 0x%(tsc)x s_timer_fn(unused)
-0x0001000B     CPU%(cpu)d 0x%(tsc)x t_timer_fn(unused)
-0x0001000C     CPU%(cpu)d 0x%(tsc)x dom_timer_fn(data)
-0x0001000D     CPU%(cpu)d 0x%(tsc)x fallback_timer_fn(unused)
+#0x00010000    CPU%(cpu)d %(tsc).6f sched_add_domain(0x%(3)08x)            [ dom id = 0x%(1)x%(2)08x   ]
+#0x00010001    CPU%(cpu)d %(tsc).6f sched_rem_domain(0x%08(3)x)            [ dom id = 0x%(1)x%(2)08x   ]
+#0x00010002    CPU%(cpu)d %(tsc).6f __wake_up(0x%(3)08x)                   [ dom id = 0x%(1)x%(2)08x   ]
+#0x00010003    CPU%(cpu)d %(tsc).6f do_block()                             [ current = 0x%(2)08x         ]
+#0x00010004    CPU%(cpu)d %(tsc).6f do_yield()                             [ current = %(2)08x         ]
+#0x00010005    CPU%(cpu)d %(tsc).6f do_set_timer_op(0x%(4)08x, 0x%(5)08x)  [ current = 0x%(3)08x ]
+#0x00010006    CPU%(cpu)d %(tsc).6f sched_ctl(0x%(1)08x)
+#0x00010007    CPU%(cpu)d %(tsc).6f sched_adjdom(params)                   [ dom id = 0x%(1)x%(2)08x   ]
+#0x00010008    CPU%(cpu)d %(tsc).6f __reschedule(0x%(3)08x)                [ dom id = 0x%(1)x%(2)08x   ]
+#0x00010009    CPU%(cpu)d %(tsc).6f switching to task_struct 0x%(1)08x     [ dom id = 0x%(1)x     ]
+#0x0001000A    CPU%(cpu)d %(tsc).6f s_timer_fn(unused)
+#0x0001000B    CPU%(cpu)d %(tsc).6f t_timer_fn(unused)
+#0x0001000C    CPU%(cpu)d %(tsc).6f dom_timer_fn(data)
+#0x0001000D    CPU%(cpu)d %(tsc).6f fallback_timer_fn(unused)
+
+
+0x00020008     CPU%(cpu)d %(tsc).6f enter: dom0_create_dom ( )
+0x00030008     CPU%(cpu)d %(tsc).6f leave: dom0_create_dom ( )
+
+0x00020009     CPU%(cpu)d %(tsc).6f enter: dom0_destroy_dom ( dom=0x%(2)x )
+0x00030009     CPU%(cpu)d %(tsc).6f leave: dom0_destroy_dom ( dom=0x%(2)x ) = %(1)d
+
+0x0002000A     CPU%(cpu)d %(tsc).6f enter: dom0_start_dom ( dom=0x%(2)x )
+0x0003000A     CPU%(cpu)d %(tsc).6f leave: dom0_start_dom ( dom=0x%(2)x ) = %(1)d
+0x0002000B     CPU%(cpu)d %(tsc).6f enter: dom0_stop_dom ( dom=0x%(2)x )
+0x0003000B     CPU%(cpu)d %(tsc).6f leave: dom0_stop_dom ( dom=0x%(2)x ) = %(1)d
+0x0002000C     CPU%(cpu)d %(tsc).6f enter: dom0_getinfo ( dom=0x%(2)x )
+0x0003000C     CPU%(cpu)d %(tsc).6f leave: dom0_getinfo ( dom=0x%(2)x ) = %(1)d
+0x0002000D     CPU%(cpu)d %(tsc).6f enter: dom0_build ( dom=0x%(2)x )
+0x0003000D     CPU%(cpu)d %(tsc).6f leave: dom0_build ( dom=0x%(2)x ) = %(1)d
+
+0x00020019     CPU%(cpu)d %(tsc).6f enter: dom0_shadow_op ( dom=0x%(2)x, %(3)d )
+0x00030019     CPU%(cpu)d %(tsc).6f leave: dom0_shadow_op ( dom=0x%(2)x, %(3)d  ) = %(1)d
+
+#0x0           CPU%(cpu)d %(tsc).6f %(event)x
index 157435baa06f5510096c02a75a2b130454a77d0f..dae9b67d801b85af9395fdd4453672f1c66483cf 100644 (file)
@@ -227,10 +227,10 @@ struct t_rec **init_rec_ptrs(unsigned long tbufs_phys,
  * trace buffer.  Each entry in this table corresponds to the tail index for a
  * particular trace buffer.
  */
-int *init_tail_idxs(struct t_buf **bufs, unsigned int num)
+unsigned long *init_tail_idxs(struct t_buf **bufs, unsigned int num)
 {
     int i;
-    int *tails = calloc(num, sizeof(unsigned int));
+    unsigned long *tails = calloc(num, sizeof(unsigned int));
  
     if ( tails == NULL )
     {
@@ -276,16 +276,19 @@ unsigned int get_num_cpus()
  */
 int monitor_tbufs(FILE *logfile)
 {
-    int i, j;
+    int i;
+
     void *tbufs_mapped;          /* pointer to where the tbufs are mapped    */
     struct t_buf **meta;         /* pointers to the trace buffer metadata    */
     struct t_rec **data;         /* pointers to the trace buffer data areas
                                   * where they are mapped into user space.   */
-    int *tails;                  /* store tail indexes for the trace buffers */
+    unsigned long *cons;         /* store tail indexes for the trace buffers */
     unsigned long tbufs_phys;    /* physical address of the tbufs            */
     unsigned int  num;           /* number of trace buffers / logical CPUS   */
     unsigned long size;          /* size of a single trace buffer            */
 
+    int size_in_recs;
+
     /* get number of logical CPUs (and therefore number of trace buffers) */
     num = get_num_cpus();
 
@@ -293,39 +296,32 @@ int monitor_tbufs(FILE *logfile)
     get_tbufs(&tbufs_phys, &size);
     tbufs_mapped = map_tbufs(tbufs_phys, num, size);
 
+    size_in_recs = (size / sizeof(struct t_rec) )-1;
+
     /* build arrays of convenience ptrs */
     meta  = init_bufs_ptrs (tbufs_mapped, num, size);
     data  = init_rec_ptrs  (tbufs_phys, tbufs_mapped, meta, num);
-    tails = init_tail_idxs (meta, num);
+    cons  = init_tail_idxs (meta, num);
 
     /* now, scan buffers for events */
     while ( !interrupted )
     {
         for ( i = 0; ( i < num ) && !interrupted; i++ )
-        {
-            signed long newdata = meta[i]->head - tails[i];
-            signed long prewrap = newdata;
-
-           /* correct newdata and prewrap in case of a pointer wrap */
-            if ( newdata < 0 )
-            {
-                newdata += meta[i]->size;
-                prewrap  = meta[i]->size - tails[i];
-            }
-
-            if ( newdata >= opts.new_data_thresh )
-            {
-                /* output pre-wrap data */
-                for(j = 0; j < prewrap; j++)
-                    write_rec(i, data[i] + tails[i] + j, logfile);
-                
-                /* output post-wrap data, if any */                    
-                for(j = 0; j < (newdata - prewrap); j++)
-                    write_rec(i, data[i] + j, logfile);  
-                
-                tails[i] += newdata;
-                if(tails[i] >= meta[i]->size) tails[i] = 0;
-            }
+        {          
+/*         printf("XX%d: cons=%ld head=%ld  %p\n", i,
+                  cons[i], meta[i]->head, data[i] + (cons[i] % size_in_recs) );
+                  */
+           while( cons[i] < meta[i]->head )
+           {
+/*
+               if( (cons[i] % 6  ) == 0 )
+                   printf("%d: cons=%ld head=%ld  %p\n", i,
+                      cons[i], meta[i]->head, data[i] + (cons[i] % size_in_recs) );
+                      */
+               write_rec(i, data[i] + (cons[i] % size_in_recs), logfile);
+               cons[i]++;
+           }
+
         }
         nanosleep(&opts.poll_sleep, NULL);
     }
@@ -333,7 +329,7 @@ int monitor_tbufs(FILE *logfile)
     /* cleanup */
     free(meta);
     free(data);
-    free(tails);
+    free(cons);
     /* don't need to munmap - cleanup is automatic */
     fclose(logfile);
 
index 4014811249932a0f0fe0a6afea6970d80893a769..d2e51265d498327f064d97a085d6cc778e8dc789 100644 (file)
@@ -4,7 +4,7 @@
 
 # Program for reformatting trace buffer output according to user-supplied rules
 
-import re, sys, string, signal, struct
+import re, sys, string, signal, struct, os, getopt
 
 def usage():
     print >> sys.stderr, \
@@ -43,6 +43,9 @@ def read_defs(defs_file):
         line = fd.readline()
         if not line:
             break
+       
+       if line[0] == '#' or line[0] == '\n':
+           continue
         
         m = reg.match(line)
 
@@ -58,29 +61,61 @@ def sighand(x,y):
 
 ##### Main code
 
+mhz = 0
+
 if len(sys.argv) < 2:
     usage()
 
+try:
+    opts, arg = getopt.getopt(sys.argv[1:], "c:" )
+
+    for opt in opts:
+       if opt[0] == '-c' : mhz = int(opt[1])
+
+except getopt.GetoptError:
+    usage()
+
+print mhz
+
 signal.signal(signal.SIGTERM, sighand)
 signal.signal(signal.SIGHUP,  sighand)
 signal.signal(signal.SIGINT,  sighand)
 
 interrupted = 0
 
-defs = read_defs(sys.argv[1])
+defs = read_defs(arg[0])
+
+print defs
 
 # structure of trace record + prepended CPU id (as output by xentrace):
 # CPU(I) TSC(Q) EVENT(L) D1(L) D2(L) D3(L) D4(L) D5(L)
 TRCREC = "IQLLLLLL"
 
+last_tsc = [0,0,0,0,0,0,0,0]
+
+i=0
+
 while not interrupted:
     try:
+       i=i+1
         line = sys.stdin.read(struct.calcsize(TRCREC))
         if not line:
             break
 
         (cpu, tsc, event, d1, d2, d3, d4, d5) = struct.unpack(TRCREC, line)
 
+       #tsc = (tscH<<32) | tscL
+
+       #print i, tsc
+
+       if tsc < last_tsc[cpu]:
+           print "TSC stepped backward cpu %d !  %d %d" % (cpu,tsc,last_tsc[cpu])
+
+       last_tsc[cpu] = tsc
+
+       if mhz:
+           tsc = tsc / (mhz*1000000.0)
+
         args = {'cpu'   : cpu,
                 'tsc'   : tsc,
                 'event' : event,
@@ -90,8 +125,15 @@ while not interrupted:
                 '4'     : d4,
                 '5'     : d5    }
 
-        if defs.has_key(str(event)): print defs[str(event)] % args
-        # silently skip lines we don't have a format for - a 'complain' option
-        # should be added if needed
+       try:
+
+           if defs.has_key(str(event)): 
+               print defs[str(event)] % args
+           else: 
+               if defs.has_key(str(0)): print defs[str(0)] % args
+       except TypeError:
+           print defs[str(event)]
+           print args
+           
 
     except IOError, struct.error: sys.exit()
index 32fa532c9a536b58fff3e02f373da5b3d8d8f175..3b413a1faaac22f0f8c34fd73843da56c2111dae 100644 (file)
@@ -22,8 +22,8 @@
 #include <hypervisor-ifs/sched_ctl.h>
 
 
-#define TRC_DOM0OP_START_BASE   0x00020000
-#define TRC_DOM0OP_FINISH_BASE  0x00030000
+#define TRC_DOM0OP_ENTER_BASE  0x00020000
+#define TRC_DOM0OP_LEAVE_BASE  0x00030000
 
 
 extern unsigned int alloc_new_dom_mem(struct task_struct *, unsigned int);
@@ -64,7 +64,7 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
         return -EACCES;
     }
 
-    TRACE_5D( TRC_DOM0OP_START_BASE + op->cmd, 
+    TRACE_5D( TRC_DOM0OP_ENTER_BASE + op->cmd, 
         0, op->u.dummy[0], op->u.dummy[1], op->u.dummy[2], op->u.dummy[3] );
 
     switch ( op->cmd )
@@ -668,7 +668,7 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
 
     }
 
-    TRACE_5D( TRC_DOM0OP_FINISH_BASE + op->cmd, ret,
+    TRACE_5D( TRC_DOM0OP_LEAVE_BASE + op->cmd, ret,
         op->u.dummy[0], op->u.dummy[1], op->u.dummy[2], op->u.dummy[3]  );
 
 
index 0140e7444a6605fc340e1972b34b78b77ee4e6f9..e79c97ee541e7395d798463c9699c944428da0ee 100644 (file)
@@ -27,7 +27,6 @@
 #include <xen/sched.h>
 #include <xen/slab.h>
 #include <xen/smp.h>
-#include <xen/spinlock.h>
 #include <xen/trace.h>
 #include <xen/errno.h>
 #include <asm/atomic.h>
@@ -86,7 +85,6 @@ void init_trace_bufs(void)
         /* For use in Xen. */
         buf->vdata    = (struct t_rec *)(buf+1);
         buf->head_ptr = buf->vdata;
-        spin_lock_init(&buf->lock);
         
         /* For use in user space. */
         buf->data = (struct t_rec *)__pa(buf->vdata);
index 4d267ba101728e23f27a309344fb1ff364a2fe41..d201eceb88b4e1bb6ed18e191a1e9c25e79d0585 100644 (file)
@@ -20,13 +20,12 @@ struct t_buf {
     struct t_rec *data;     /* pointer to data area.  physical address
                              * for convenience in user space code            */
 
-    unsigned int size;      /* size of the data area, in t_recs              */
-    unsigned int head;      /* array index of the most recent record         */
+    unsigned long size;      /* size of the data area, in t_recs              */
+    unsigned long head;      /* array index of the most recent record         */
 
 #ifdef __KERNEL__
     struct t_rec *head_ptr; /* pointer to the head record                    */
     struct t_rec *vdata;    /* virtual address pointer to data               */
-    spinlock_t lock;        /* ensure mutually exlusive access (for inserts) */
 #endif
 
     /* never add anything here - the kernel stuff must be the last elements */
index 00b18b02111da674c77914ec93ce0cd55c220871..782023f76ee8f0e453240576736b48333d9f7fb9 100644 (file)
@@ -61,10 +61,12 @@ static inline int trace(u32 event, u32 d1, u32 d2, u32 d3, u32 d4, u32 d5)
     if ( !tb_init_done )
         return -1;
 
+
     buf = t_bufs[smp_processor_id()];
-    rec = buf->head_ptr;
 
-    spin_lock_irqsave(&buf->lock, flags);
+    local_irq_save(flags);
+
+    rec = buf->head_ptr;
 
     rdtscll(rec->cycles);
     rec->event = event;
@@ -76,18 +78,12 @@ static inline int trace(u32 event, u32 d1, u32 d2, u32 d3, u32 d4, u32 d5)
 
     wmb(); /* above must be visible before reader sees index updated */
 
-    if ( likely(buf->head_ptr < (buf->vdata + buf->size - 1)) )
-    {
-        buf->head_ptr++;
-        buf->head++;
-    }
-    else
-    {
-        buf->head = 0;
+    buf->head_ptr++;
+    buf->head++;
+    if ( buf->head_ptr == (buf->vdata + (buf->size-1)) )
         buf->head_ptr = buf->vdata;
-    }
 
-    spin_unlock_irqrestore(&buf->lock, flags);
+    local_irq_restore(flags);
     
     return 0;
 }