Skip to contentSkip to conversation

Non-polling trace record access

PATCH In review Rob Gardner 2 participants 2 messages Mar 31, 2006 – Apr 6, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Non-polling trace record access

This is the kernel side code to implement a virtual irq that gets sent when the xen trace buffers become half-full. This allows userland tools such as xentrace and xenmon to avoid polling for new trace records. A future patch will include support for this in XenMon, along with various other enhancements and bug fixes.

This patch has been tested on x86, x86-64, and x86 SMP machines.

Rob Gardner

# HG changeset patch
# User [email protected]
# Node ID 8e3d7bce3b29841a323056defacdb1181c252282 # Parent f0e14b4e535c7d99c56c286384b0d512c5220884

Added trace buffer virtual irq to implement non-polling trace record access

xen/common/trace.c Fri Mar 31 17:33:04 2006 renamed from xen/common/trace.c Thu Mar 30 13:37:22 2006 +0 -0
diff -r f0e14b4e535c -r 8e3d7bce3b29 xen/common/trace.c
@@ -27,6 +27,8 @@

#include <xen/smp.h>
#include <xen/trace.h>
#include <xen/errno.h>
+#include <xen/event.h>
+#include <xen/softirq.h>
#include <xen/init.h>
#include <asm/atomic.h>
#include <public/dom0_ops.h>
@@ -40,6 +42,10 @@
static struct t_rec *t_recs[NR_CPUS];
static int nr_recs;

+/* High water mark for trace buffers; */
+/* Send virtual interrupt when buffer level reaches this point */ +static int t_buf_highwater;
+
/* a flag recording whether initialization has been done */ /* or more properly, if the tbuf subsystem is enabled right now */ int tb_init_done;
@@ -49,6 +55,13 @@

/* which tracing events are enabled */
static u32 tb_event_mask = TRC_ALL;
+
+
+static void trace_notify_guest(void)
+{
+ send_guest_virq(dom0->vcpu[0], VIRQ_TBUF);
+}
+

/**
* alloc_trace_bufs - performs initialization of the per-cpu trace buffers. @@ -93,6 +106,8 @@

       t_recs[i] = (struct t_rec *)(buf + 1);

}

+ t_buf_highwater = nr_recs >> 1; /* 50% high water */
+ open_softirq(TRACE_SOFTIRQ, trace_notify_guest);
return 0;
}

@@ -228,6 +243,7 @@
struct t_buf *buf;
struct t_rec *rec;
unsigned long flags;
+ static uint32_t last_virq_sent = 0;

   BUG_ON(!tb_init_done);

@@ -272,6 +288,18 @@
buf->prod++;

local_irq_restore(flags);
+
+ /*

+     * Notify trace buffer consumer that we've reached the high water
+     * point. We don't want to repeatedly send virq's, so remember
+     * when we sent the last one.
+     *
+     */

+ if ( ((buf->prod - buf->cons) >= t_buf_highwater)
+ && (buf->cons > last_virq_sent)) {
+ last_virq_sent = buf->cons;
+ raise_softirq(TRACE_SOFTIRQ);
+ }
}

/*

xen/include/public/xen.h Fri Mar 31 17:33:04 2006 renamed from xen/include/public/xen.h Thu Mar 30 13:37:22 2006 +0 -0
diff -r f0e14b4e535c -r 8e3d7bce3b29 xen/include/public/xen.h
@@ -71,6 +71,7 @@
#define VIRQ_CONSOLE    2  /* (DOM0) Bytes received on emergency console. */
#define VIRQ_DOM_EXC    3  /* (DOM0) Exceptional event for some domain.   */
#define VIRQ_DEBUGGER   6  /* (DOM0) A domain has paused for debugging.   */

+#define VIRQ_TBUF 7 /* (DOM0) Trace buffer has records available */
#define NR_VIRQS 8

/*

xen/include/xen/softirq.h Fri Mar 31 17:33:04 2006 renamed from xen/include/xen/softirq.h Thu Mar 30 13:37:22 2006 +0 -0
diff -r f0e14b4e535c -r 8e3d7bce3b29 xen/include/xen/softirq.h
@@ -9,7 +9,8 @@
#define NMI_SOFTIRQ                       4
#define PAGE_SCRUB_SOFTIRQ                5
#define DOMAIN_SHUTDOWN_FINALISE_SOFTIRQ  6
-#define NR_SOFTIRQS                       7
+#define TRACE_SOFTIRQ                     7
+#define NR_SOFTIRQS                       8

#ifndef __ASSEMBLY__

# HG changeset patch
# User [email protected]
# Node ID 8e3d7bce3b29841a323056defacdb1181c252282 # Parent f0e14b4e535c7d99c56c286384b0d512c5220884

Added trace buffer virtual irq to implement non-polling trace record access

xen/common/trace.c +28 -0
diff -r f0e14b4e535c -r 8e3d7bce3b29 xen/common/trace.c
@@ -27,6 +27,8 @@
 #include <xen/smp.h>
 #include <xen/trace.h>
 #include <xen/errno.h>
+#include <xen/event.h>
+#include <xen/softirq.h>
 #include <xen/init.h>
 #include <asm/atomic.h>
 #include <public/dom0_ops.h>
@@ -40,6 +42,10 @@
 static struct t_rec *t_recs[NR_CPUS];
 static int nr_recs;
 
+/* High water mark for trace buffers; */
+/* Send virtual interrupt when buffer level reaches this point */
+static int t_buf_highwater;
+
 /* a flag recording whether initialization has been done */
 /* or more properly, if the tbuf subsystem is enabled right now */
 int tb_init_done;
@@ -49,6 +55,13 @@
 
 /* which tracing events are enabled */
 static u32 tb_event_mask = TRC_ALL;
+
+
+static void trace_notify_guest(void)
+{
+    send_guest_virq(dom0->vcpu[0], VIRQ_TBUF);
+}
+
 
 /**
  * alloc_trace_bufs - performs initialization of the per-cpu trace buffers.
@@ -93,6 +106,8 @@
         t_recs[i] = (struct t_rec *)(buf + 1);
     }
 
+    t_buf_highwater = nr_recs >> 1; /* 50% high water */
+    open_softirq(TRACE_SOFTIRQ, trace_notify_guest);
     return 0;
 }
 
@@ -228,6 +243,7 @@
     struct t_buf *buf;
     struct t_rec *rec;
     unsigned long flags;
+    static uint32_t last_virq_sent = 0;
 
     BUG_ON(!tb_init_done);
 
@@ -272,6 +288,18 @@
     buf->prod++;
 
     local_irq_restore(flags);
+
+    /*
+     * Notify trace buffer consumer that we've reached the high water
+     * point. We don't want to repeatedly send virq's, so remember
+     * when we sent the last one.
+     * 
+     */
+    if ( ((buf->prod - buf->cons) >= t_buf_highwater)
+         && (buf->cons > last_virq_sent)) {
+          last_virq_sent = buf->cons;
+          raise_softirq(TRACE_SOFTIRQ);
+    }
 }
 
 /*
xen/include/public/xen.h +1 -0
diff -r f0e14b4e535c -r 8e3d7bce3b29 xen/include/public/xen.h
@@ -71,6 +71,7 @@
 #define VIRQ_CONSOLE    2  /* (DOM0) Bytes received on emergency console. */
 #define VIRQ_DOM_EXC    3  /* (DOM0) Exceptional event for some domain.   */
 #define VIRQ_DEBUGGER   6  /* (DOM0) A domain has paused for debugging.   */
+#define VIRQ_TBUF       7  /* (DOM0) Trace buffer has records available   */
 #define NR_VIRQS        8
 
 /*
xen/include/xen/softirq.h +2 -1
diff -r f0e14b4e535c -r 8e3d7bce3b29 xen/include/xen/softirq.h
@@ -9,7 +9,8 @@
 #define NMI_SOFTIRQ                       4
 #define PAGE_SCRUB_SOFTIRQ                5
 #define DOMAIN_SHUTDOWN_FINALISE_SOFTIRQ  6
-#define NR_SOFTIRQS                       7
+#define TRACE_SOFTIRQ                     7
+#define NR_SOFTIRQS                       8
 
 #ifndef __ASSEMBLY__
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 3 lines · Rob Gardner

This is the kernel side code to implement a virtual irq that gets sent when the xen trace buffers become half-full. This allows userland tools such as xentrace and xenmon to avoid polling for new trace records. A future patch will include support for this in XenMon, along with various other enhancements and bug fixes.

This patch has been tested on x86, x86-64, and x86 SMP machines.

Please re-sync the patch with current tip, and also I think your interrupt holdoff logic is unnecessary. I think you can get rid of last_virq_sent and test '(buf->prod - buf->cons) == t_buf_highwater'. No need for '>=' because the producer is incremented by one each time trace() is called so you are bound to equal t_bug_highwater before you become greater than it.

-- Keir