Skip to contentSkip to conversation

Xenoprof passive domain support

PATCH Yang, Xiaowei 2 participants 2 messages Apr 29, 2006 – May 2, 2006

lore
Share & tools
lore
#0 lore raw

Renato,
I remade the patch. It has several improvements.
1) Add a lock for preventing more than one LPs of dom0 from accessing to passive domain concurrently.
2) Add escape code only at the beginning and end of a bunch of passive domain samples, which dom0 handles one time. Originally we added escape code in front of every passive domain sample. That's inefficient.
3) Reuse "normal ESCAPE_CODE" of oprofile to add passive domain switch event into the CPU buffer.

Thanks,
-Xiaowei

Quoted 60 lines

-----Original Message-----
From: Santos, Jose Renato G [mailto:[email protected]]
Sent: 2006年4月29日 9:43
To: Yang, Xiaowei
Cc: [email protected]; John Levon; Yoshio Turner; G John Janakiraman
Subject: RE: [PATCH] Xenoprof passive domain support

Xiaowei,

Thanks for the patch.
I took a first look in the patch and have a few comments.

First, I think there is a concurrency problem that needs to fixed. If dom0 has more than one VCPU, then 2 VCPUs can access the same passive buffer at the same time. This should not be allowed, since the buffer is not protected by any lock. We should make sure that any passive domain buffer is accessed by one and only one dom0 VCPU. A simple approach would be to have only VCPU 0 (in dom0) to handle all the passive domain samples. However, this may cause an
imbalance on the speed that oprofile CPU buffers are filled. Probably the cpu buffer for VCPU 0 would fill much earlier and cause more frequent flushes to the event buffer, increasing the overhead.
I would prefer if we could distribute the passive buffers to all VCPUs in dom0. I will think more about this during the weekend and make additional comments, earlier next week.

Second, I see that you reused most of the code that was used in Xen 2.0, when passive domains was supported for non SMP guests.
John Levon (cc'ed on this message) has made some comments on that code which I think we should address right now. More specifically, he suggested that we change the way domain switches are represented in the CPU buffer. Please look at his comment below.

I suggest that we address these 2 issues first and then I can look more carefully at the rest of the code. Please CC John Levon, on you next messages

Thanks

Renato

Old comments by John Levon on passive domain code:
=============================================================
I'm uncomfortable with the chosen domain switching encoding. It's pretty confusing to follow all the escaping done already, and you're making it more complicated. Why can't you use a normal ESCAPE_CODE? I.e. the buffer would have

EIP Event
---------------------------------
0. ESCAPE_CODE DOMAIN_SWITCH
1. domain ID
2. EIP Event

Quoted 7 lines

Sure, you lose an entry (1) in size but it means simpler code, and less i-cache hurt.

Why is the state not persistent until the next escape code? i.e. it's only for one sample.

======================================================================

Add Xenoprof passive domain support

linux-2.6-xen-sparse/arch/i386/oprofile/xenoprof.c +119 -12
diff -r e0d986fc0978 linux-2.6-xen-sparse/arch/i386/oprofile/xenoprof.c
@@ -50,6 +50,11 @@
 /* cpu model type string - copied from Xen memory space on XENOPROF_init command */
 char cpu_type[XENOPROF_CPU_TYPE_SIZE];
 
+/* Passive sample buffers shared with Xen */
+xenoprof_buf_t *p_xenoprof_buf[MAX_OPROF_DOMAINS][MAX_VIRT_CPUS];
+/* Passive shared buffer area */
+char *p_shared_buffer[MAX_OPROF_DOMAINS];
+
 #ifdef CONFIG_PM
 
 static int xenoprof_suspend(struct sys_device * dev, pm_message_t state)
@@ -102,16 +107,14 @@
 #endif /* CONFIG_PM */
 
 unsigned long long oprofile_samples = 0;
-
-static irqreturn_t 
-xenoprof_ovf_interrupt(int irq, void * dev_id, struct pt_regs * regs)
+unsigned long long p_oprofile_samples = 0;
+
+extern unsigned int pdomains;
+extern struct xenoprof_passive passive_domains[MAX_OPROF_DOMAINS];
+
+static void xenoprof_add_pc(xenoprof_buf_t *buf, int is_passive)
 {
 	int head, tail, size;
-	struct xenoprof_buf * buf;
-	int cpu;
-
-	cpu = smp_processor_id();
-	buf = xenoprof_buf[cpu];
 
 	head = buf->event_head;
 	tail = buf->event_tail;
@@ -122,7 +125,10 @@
 			oprofile_add_pc(buf->event_log[tail].eip,
 					buf->event_log[tail].mode,
 					buf->event_log[tail].event);
-			oprofile_samples++;
+			if (!is_passive)
+				oprofile_samples++;
+			else
+				p_oprofile_samples++;
 			tail++;
 		}
 		tail = 0;
@@ -131,11 +137,48 @@
 		oprofile_add_pc(buf->event_log[tail].eip,
 				buf->event_log[tail].mode,
 				buf->event_log[tail].event);
-		oprofile_samples++;
+		if (!is_passive)
+			oprofile_samples++;
+		else
+			p_oprofile_samples++;
 		tail++;
 	}
 
 	buf->event_tail = tail;
+}
+
+static void xenoprof_handle_passive(void)
+{
+	int i, j;
+
+	for (i = 0; i < pdomains; i++)
+		for (j = 0; j < passive_domains[i].nbuf; j++) {
+			xenoprof_buf_t *buf = p_xenoprof_buf[i][j];
+			if (buf->event_head == buf->event_tail)
+				continue;
+                        oprofile_add_pc(0, 3, passive_domains[i].domain_id);
+			xenoprof_add_pc(buf, 1);
+                        oprofile_add_pc(0, 4, passive_domains[i].domain_id);
+		}			
+}
+
+DECLARE_MUTEX(xenoprof_sem);
+
+static irqreturn_t 
+xenoprof_ovf_interrupt(int irq, void * dev_id, struct pt_regs * regs)
+{
+	struct xenoprof_buf * buf;
+	int cpu;
+
+	cpu = smp_processor_id();
+	buf = xenoprof_buf[cpu];
+
+	xenoprof_add_pc(buf, 0);
+
+	if (is_primary && !down_trylock(&xenoprof_sem)) {
+		xenoprof_handle_passive();
+		up(&xenoprof_sem);
+	}
 
 	return IRQ_HANDLED;
 }
@@ -318,6 +361,60 @@
 	}
 	
 	active_defined = 1;
+	return ret;
+}
+
+static int xenoprof_set_passive(struct xenoprof_passive *passive_domains,
+                                unsigned int pdomains)
+{
+	int ret;
+	int i, j;
+	int vm_size;
+	int npages;
+	struct xenoprof_buf *buf;
+	pgprot_t prot = __pgprot(_KERNPG_TABLE);
+
+	if (!is_primary)
+        	return 0;
+
+	if (pdomains > MAX_OPROF_DOMAINS)
+		return -E2BIG;
+
+	ret = HYPERVISOR_xenoprof_op(XENOPROF_reset_passive_list, NULL);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < pdomains; i++) {
+		ret = HYPERVISOR_xenoprof_op(XENOPROF_set_passive, &passive_domains[i]);
+		if (ret)
+			return ret;
+
+		npages = (passive_domains[i].bufsize * passive_domains[i].nbuf - 1) / PAGE_SIZE + 1;
+		vm_size = npages * PAGE_SIZE;
+
+		p_shared_buffer[i] = (char *)vm_map_xen_pages(passive_domains[i].buf_maddr,
+							      vm_size, prot);
+		if (!p_shared_buffer[i]) {
+			ret = -ENOMEM;
+			goto out;
+		}
+
+		for (j = 0; j < passive_domains[i].nbuf; j++) {
+			buf = (struct xenoprof_buf *)
+				&p_shared_buffer[i][j * passive_domains[i].bufsize];
+			BUG_ON(buf->vcpu_id >= MAX_VIRT_CPUS);
+			p_xenoprof_buf[i][buf->vcpu_id] = buf;
+		}
+
+	}
+	return 0;
+
+out:
+	for (j = 0; j < i; j++) {
+		vunmap(p_shared_buffer[j]);
+		p_shared_buffer[j] = NULL;
+	}
+
 	return ret;
 }
 
@@ -355,6 +452,7 @@
 struct oprofile_operations xenoprof_ops = {
 	.create_files 	= xenoprof_create_files,
 	.set_active	= xenoprof_set_active,
+	.set_passive    = xenoprof_set_passive,
 	.setup 		= xenoprof_setup,
 	.shutdown	= xenoprof_shutdown,
 	.start		= xenoprof_start,
@@ -429,6 +527,8 @@
 
 void __exit oprofile_arch_exit(void)
 {
+	int i;
+
 	if (using_xenoprof)
 		exit_driverfs();
 
@@ -436,6 +536,13 @@
 		vunmap(shared_buffer);
 		shared_buffer = NULL;
 	}
-	if (is_primary)
+	if (is_primary) {
+		for (i = 0; i < pdomains; i++)
+			if (p_shared_buffer[i]) {
+		                vunmap(p_shared_buffer[i]);
+                		p_shared_buffer[i] = NULL;
+			}
 		HYPERVISOR_xenoprof_op(XENOPROF_shutdown, NULL);
-}
+        }
+
+}
patches/linux-2.6.16/xenoprof-generic.patch +160 -66

352 lines not on this page · raw message

xen/arch/x86/domain.c +0 -1
diff -r e0d986fc0978 xen/arch/x86/domain.c
@@ -956,7 +956,6 @@
 
     /* Free page used by xen oprofile buffer */
     free_xenoprof_pages(d);
-
 }
 
 void arch_dump_domain_info(struct domain *d)
xen/arch/x86/hvm/vmx/vmx.c +1 -0
diff -r e0d986fc0978 xen/arch/x86/hvm/vmx/vmx.c
@@ -2069,6 +2069,7 @@
     }
 
     __vmread(GUEST_RIP, &eip);
+    regs.eip = eip;
     TRACE_VMEXIT(0,exit_reason);
 
     switch (exit_reason) {
xen/arch/x86/oprofile/nmi_int.c +1 -1
diff -r e0d986fc0978 xen/arch/x86/oprofile/nmi_int.c
@@ -269,7 +269,7 @@
 { 
 	__u8 cpu_model = current_cpu_data.x86_model;
 
-	if (cpu_model > 4)
+	if (cpu_model > 7)
 		return 0;
 
 #ifndef CONFIG_SMP
xen/arch/x86/oprofile/xenoprof.c +92 -6

192 lines not on this page · raw message

xen/include/public/xenoprof.h +9 -0
diff -r e0d986fc0978 xen/include/public/xenoprof.h
@@ -77,6 +77,15 @@
 } xenoprof_counter_t;
 DEFINE_XEN_GUEST_HANDLE(xenoprof_counter_t);
 
+typedef struct xenoprof_passive {
+    uint16_t domain_id;
+    int32_t  max_samples;
+    int32_t  nbuf;
+    int32_t  bufsize;
+    uint64_t buf_maddr;
+} xenoprof_passive_t;
+DEFINE_XEN_GUEST_HANDLE(xenoprof_passive_t);
+
 
 #endif /* __XEN_PUBLIC_XENOPROF_H__ */
 
xen/include/xen/xenoprof.h +1 -0
diff -r e0d986fc0978 xen/include/xen/xenoprof.h
@@ -14,6 +14,7 @@
 
 #define XENOPROF_DOMAIN_IGNORED    0
 #define XENOPROF_DOMAIN_ACTIVE     1
+#define XENOPROF_DOMAIN_PASSIVE    2
 
 #define XENOPROF_IDLE              0
 #define XENOPROF_COUNTERS_RESERVED 1
daemon/init.c +6 -0
diff -ru --exclude='*.html' --exclude=configure oprofile-0.8.1/daemon/init.c oprofile-0.8.1.xenoprof/daemon/init.c
@@ -7,6 +7,9 @@
  *
  * @author John Levon
  * @author Philippe Elie
+ * Modified by Aravind Menon for Xen
+ * These modifications are:
+ * Copyright (C) 2005 Hewlett-Packard Co.
  */
 
 #include "config.h"
@@ -221,6 +224,9 @@
 	size_t opd_buf_size;
 
 	opd_create_vmlinux(vmlinux, kernel_range);
+	opd_create_xen(xenimage, xen_range);
+	if (passive_ids)
+		opd_create_passive(passive_ids);
 
 	opd_buf_size = opd_read_fs_int("/dev/oprofile/", "buffer_size", 1);
 	kernel_pointer_size = opd_read_fs_int("/dev/oprofile/", "pointer_size", 1);
daemon/opd_interface.h +8 -2
diff -ru --exclude='*.html' --exclude=configure oprofile-0.8.1/daemon/opd_interface.h oprofile-0.8.1.xenoprof/daemon/opd_interface.h
@@ -8,6 +8,9 @@
  *
  * @author John Levon
  * @author Philippe Elie
+ * Modified by Aravind Menon for Xen
+ * These modifications are:
+ * Copyright (C) 2005 Hewlett-Packard Co.
  */
 
 #ifndef OPD_INTERFACE_H
@@ -17,11 +20,14 @@
 #define CPU_SWITCH_CODE			2
 #define COOKIE_SWITCH_CODE		3
 #define KERNEL_ENTER_SWITCH_CODE	4
-#define KERNEL_EXIT_SWITCH_CODE		5
+#define USER_ENTER_SWITCH_CODE		5
 #define MODULE_LOADED_CODE              6
 #define CTX_TGID_CODE			7
 #define TRACE_BEGIN_CODE		8
 #define TRACE_END_CODE			9
-#define LAST_CODE			10
+#define XEN_ENTER_SWITCH_CODE		10
+#define PASSIVE_START_CODE		11
+#define PASSIVE_STOP_CODE		12
+#define LAST_CODE			13
  
 #endif /* OPD_INTERFACE_H */
daemon/opd_kernel.c +104 -0

138 lines not on this page · raw message

daemon/opd_kernel.h +7 -0
diff -ru --exclude='*.html' --exclude=configure oprofile-0.8.1/daemon/opd_kernel.h oprofile-0.8.1.xenoprof/daemon/opd_kernel.h
@@ -7,6 +7,9 @@
  *
  * @author John Levon
  * @author Philippe Elie
+ * Modified by Aravind Menon for Xen
+ * These modifications are:
+ * Copyright (C) 2005 Hewlett-Packard Co.
  */
 
 #ifndef OPD_KERNEL_H
@@ -20,6 +23,9 @@
 /** create the kernel image */
 void opd_create_vmlinux(char const * name, char const * arg);
 
+void opd_create_xen(char const * name, char const * arg);
+void opd_create_passive(char const * name);
+
 /** opd_reread_module_info - parse /proc/modules for kernel modules */
 void opd_reread_module_info(void);
 
@@ -28,6 +34,7 @@
 	char * name;
 	vma_t start;
 	vma_t end;
+	int id;
 	struct list_head list;
 };
 
daemon/opd_trans.c +43 -2

74 lines not on this page · raw message

daemon/oprofiled.c +32 -0
diff -ru --exclude='*.html' --exclude=configure oprofile-0.8.1/daemon/oprofiled.c oprofile-0.8.1.xenoprof/daemon/oprofiled.c
@@ -7,6 +7,9 @@
  *
  * @author John Levon
  * @author Philippe Elie
+ * Modified by Aravind Menon for Xen
+ * These modifications are:
+ * Copyright (C) 2005 Hewlett-Packard Co.
  */
 
 #include "config.h"
@@ -60,6 +63,10 @@
 int no_vmlinux;
 char * vmlinux;
 char * kernel_range;
+int no_xen;
+char * xenimage;
+char * xen_range;
+char * passive_ids;
 static char * verbose;
 static char * binary_name_filter;
 static char * events;
@@ -75,7 +82,11 @@
 	{ "kernel-range", 'r', POPT_ARG_STRING, &kernel_range, 0, "Kernel VMA range", "start-end", },
 	{ "vmlinux", 'k', POPT_ARG_STRING, &vmlinux, 0, "vmlinux kernel image", "file", },
 	{ "no-vmlinux", 0, POPT_ARG_NONE, &no_vmlinux, 0, "vmlinux kernel image file not available", NULL, },
+	{ "xen-range", 0, POPT_ARG_STRING, &xen_range, 0, "Xen VMA range", "start-end", },
+	{ "xen-image", 0, POPT_ARG_STRING, &xenimage, 0, "Xen image", "file", },
+	{ "no-xen", 0, POPT_ARG_NONE, &no_xen, 0, "xen image not available", NULL, },
 	{ "image", 0, POPT_ARG_STRING, &binary_name_filter, 0, "image name filter", "profile these comma separated image" },
+	{ "passive-domains", 0, POPT_ARG_STRING, &passive_ids, 0, "Passive domains list", "list", },
 	{ "separate-lib", 0, POPT_ARG_INT, &separate_lib, 0, "separate library samples for each distinct application", "[0|1]", },
 	{ "separate-kernel", 0, POPT_ARG_INT, &separate_kernel, 0, "separate kernel samples for each distinct application", "[0|1]", },
 	{ "separate-thread", 0, POPT_ARG_INT, &separate_thread, 0, "thread-profiling mode", "[0|1]" },
@@ -402,6 +413,27 @@
 		}
 	}
 
+	if (!no_xen) {
+		if (!xenimage || !strcmp("", xenimage)) {
+			fprintf(stderr, "oprofiled: no xen image specified.\n");
+			poptPrintHelp(optcon, stderr, 0);
+			exit(EXIT_FAILURE);
+		}
+
+		/* canonicalise xen image filename. fix #637805 */
+		tmp = xmalloc(PATH_MAX);
+		if (realpath(xenimage, tmp))
+			xenimage = tmp;
+		else
+			free(tmp);
+
+		if (!xen_range || !strcmp("", xen_range)) {
+			fprintf(stderr, "oprofiled: no Xen VMA range specified.\n");
+			poptPrintHelp(optcon, stderr, 0);
+			exit(EXIT_FAILURE);
+		}
+	}
+
 	opd_parse_events(events);
 
 	opd_parse_image_filter();
daemon/oprofiled.h +7 -0
diff -ru --exclude='*.html' --exclude=configure oprofile-0.8.1/daemon/oprofiled.h oprofile-0.8.1.xenoprof/daemon/oprofiled.h
@@ -7,6 +7,9 @@
  *
  * @author John Levon
  * @author Philippe Elie
+ * Modified by Aravind Menon for Xen
+ * These modifications are:
+ * Copyright (C) 2005 Hewlett-Packard Co.
  */
 
 #ifndef OPROFILED_H
@@ -68,5 +71,9 @@
 extern int no_vmlinux;
 extern char * vmlinux;
 extern char * kernel_range;
+extern int no_xen;
+extern char * xenimage;
+extern char * xen_range;
+extern char * passive_ids;
 
 #endif /* OPROFILED_H */
utils/opcontrol +135 -5

228 lines not on this page · raw message

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

#1 lore raw

"Yang, Xiaowei" <[email protected]> wrote on 04/29/2006 05:46:27 AM:

Quoted 7 lines

Renato,
I remade the patch. It has several improvements.
1) Add a lock for preventing more than one LPs of dom0 from accessing to passive domain concurrently.
2) Add escape code only at the beginning and end of a bunch of passive domain samples, which dom0 handles one time. Originally we added escape code in front of every passive domain sample. That's

inefficient.

Quoted 5 lines

3) Reuse "normal ESCAPE_CODE" of oprofile to add passive domain switch event into the CPU buffer.

Thanks,
-Xiaowei

I tried the patch. The build of a xen0 kernel fails with:
arch/i386/oprofile/../../../drivers/oprofile/oprof.c:41: error:
?MAX_OPROF_DOMAINS? undeclared here (not in a function) arch/i386/oprofile/../../../drivers/oprofile/oprof.c: In function ?oprofile_set_active?:
arch/i386/oprofile/../../../drivers/oprofile/oprof.c:45: error: ?struct oprofile_operations? has no member named ?set_active? arch/i386/oprofile/../../../drivers/oprofile/oprof.c:46: error: ?struct oprofile_operations? has no member named ?set_active? arch/i386/oprofile/../../../drivers/oprofile/oprof.c: In function ?oprofile_set_passive?:
arch/i386/oprofile/../../../drivers/oprofile/oprof.c:56: error: ?struct oprofile_operations? has no member named ?set_passive? arch/i386/oprofile/../../../drivers/oprofile/oprof.c:57: error: ?struct oprofile_operations? has no member named ?set_passive?
make[1]: *** [arch/i386/oprofile/../../../drivers/oprofile/oprof.o] Error 1
make: *** [arch/i386/oprofile] Error 2

It appears that the patch to patches/linux-2.6.16/xenoprof-generic.patch is not correct. For example:

-diff -pruN ../pristine-linux-2.6.16/include/linux/oprofile.h ./include/linux/oprofile.h
---- ../pristine-linux-2.6.16/include/linux/oprofile.h 2006-03-20 05:53:29.000000000 +0000
-+++ ./include/linux/oprofile.h 2006-04-03 15:53:05.000000000 +0100 -@@ -16,6 +16,8 @@
- #include <linux/types.h>
- #include <linux/spinlock.h>
- #include <asm/atomic.h>
-+
-+#include <xen/interface/xenoprof.h>
-
- struct super_block;
- struct dentry;
-@@ -27,6 +29,8 @@ struct oprofile_operations {
- /* create any necessary configuration files in the oprofile fs.
- * Optional. */

-       int (*create_files)(struct super_block * sb, struct dentry * root);
-+      /* setup active domains with Xen */
-+      int (*set_active)(int *active_domains, unsigned int adomains);
-       /* Do any necessary interrupt setup. Optional. */
-       int (*setup)(void);
-       /* Do any necessary interrupt shutdown. Optional. */

removes the xenoprof support from include/linux/oprofile.h rather than adding the filed for set_passive to struct oprofile_operations.

The initial patch released on 2006/04/28 had it correct:

diff -pruN ../pristine-linux-2.6.16/include/linux/oprofile.h
./include/linux/oprofile.h
---- ../pristine-linux-2.6.16/include/linux/oprofile.h 2006-03-20 05:53:29.000000000 +0000
-+++ ./include/linux/oprofile.h 2006-04-03 15:53:05.000000000 +0100 +--- ../pristine-linux-2.6.16/include/linux/oprofile.h 2006-04-27 16:22:31.000000000 +0800
++++ ./include/linux/oprofile.h 2006-04-25 17:20:36.000000000 +0800
@@ -16,6 +16,8 @@
#include <linux/types.h>
#include <linux/spinlock.h>
@@ -373,12 +508,14 @@

struct super_block;
struct dentry;
-@@ -27,6 +29,8 @@ struct oprofile_operations {

+@@ -27,6 +29,10 @@ struct oprofile_operations {
        /* create any necessary configuration files in the oprofile fs.
         * Optional. */
        int (*create_files)(struct super_block * sb, struct dentry * root);
 +      /* setup active domains with Xen */
 +      int (*set_active)(int *active_domains, unsigned int adomains);
++      /* setup passive domains with Xen */
++      int (*set_passive)(struct xenoprof_passive *passive_domains,
unsigned int pdomains);
        /* Do any necessary interrupt setup. Optional. */
        int (*setup)(void);
        /* Do any necessary interrupt shutdown. Optional. */

I'll hack my copy of the patch for now. You may want to revisit how the patch is created.

Steve D.