Blame SOURCES/oprofile-0.9.7-xen.patch

d5df0a
diff -up oprofile-0.9.7/daemon/init.c.xen oprofile-0.9.7/daemon/init.c
d5df0a
--- oprofile-0.9.7/daemon/init.c.xen	2011-07-04 22:25:04.000000000 -0400
d5df0a
+++ oprofile-0.9.7/daemon/init.c	2011-11-28 16:25:07.577000010 -0500
d5df0a
@@ -312,6 +312,8 @@ static void opd_26_init(void)
d5df0a
 
d5df0a
 	opd_create_vmlinux(vmlinux, kernel_range);
d5df0a
 	opd_create_xen(xenimage, xen_range);
d5df0a
+	if (xen_passive_setup)
d5df0a
+		opd_create_passive(xen_passive_setup);
d5df0a
 
d5df0a
 	opd_buf_size = opd_read_fs_int("/dev/oprofile/", "buffer_size", 1);
d5df0a
 	kernel_pointer_size = opd_read_fs_int("/dev/oprofile/", "pointer_size", 1);
d5df0a
diff -up oprofile-0.9.7/daemon/opd_kernel.c.xen oprofile-0.9.7/daemon/opd_kernel.c
d5df0a
--- oprofile-0.9.7/daemon/opd_kernel.c.xen	2011-07-04 22:25:04.000000000 -0400
d5df0a
+++ oprofile-0.9.7/daemon/opd_kernel.c	2011-11-28 16:25:07.579000010 -0500
d5df0a
@@ -34,11 +34,22 @@ static struct kernel_image vmlinux_image
d5df0a
 
d5df0a
 static struct kernel_image xen_image;
d5df0a
 
d5df0a
+static struct kernel_image xen_image_anon;
d5df0a
+static struct kernel_image vmlinux_image_anon;
d5df0a
+
d5df0a
+static LIST_HEAD(passive_vmlinux);
d5df0a
+static LIST_HEAD(passive_xen);
d5df0a
+static LIST_HEAD(passive_apps);
d5df0a
+static LIST_HEAD(passive_modules);
d5df0a
+static LIST_HEAD(passive_xen_anon);
d5df0a
+
d5df0a
 void opd_create_vmlinux(char const * name, char const * arg)
d5df0a
 {
d5df0a
 	/* vmlinux is *not* on the list of modules */
d5df0a
 	list_init(&vmlinux_image.list);
d5df0a
 
d5df0a
+	list_init(&vmlinux_image_anon.list);
d5df0a
+
d5df0a
 	/* for no vmlinux */
d5df0a
 	if (no_vmlinux) {
d5df0a
 		vmlinux_image.name = "no-vmlinux";
d5df0a
@@ -57,13 +68,22 @@ void opd_create_vmlinux(char const * nam
d5df0a
 		        vmlinux_image.start, vmlinux_image.end);
d5df0a
 		exit(EXIT_FAILURE);
d5df0a
 	}
d5df0a
+
d5df0a
+	vmlinux_image_anon.name  = "vmlinux-unknown";
d5df0a
+	vmlinux_image_anon.start = vmlinux_image.start;
d5df0a
+	vmlinux_image_anon.end   = vmlinux_image.end;
d5df0a
+
d5df0a
 }
d5df0a
 
d5df0a
 void opd_create_xen(char const * name, char const * arg)
d5df0a
 {
d5df0a
+	int stat;
d5df0a
+
d5df0a
 	/* xen is *not* on the list of modules */
d5df0a
 	list_init(&xen_image.list);
d5df0a
 
d5df0a
+	list_init(&xen_image_anon.list);
d5df0a
+
d5df0a
 	/* for no xen */
d5df0a
 	if (no_xen) {
d5df0a
 		xen_image.name = "no-xen";
d5df0a
@@ -72,18 +92,106 @@ void opd_create_xen(char const * name, c
d5df0a
 
d5df0a
 	xen_image.name = xstrdup(name);
d5df0a
 
d5df0a
-	sscanf(arg, "%llx,%llx", &xen_image.start, &xen_image.end);
d5df0a
+	stat = sscanf(arg, "%llx,%llx", &xen_image.start, &xen_image.end);
d5df0a
+
d5df0a
+	xen_image_anon.name  = "xen-unknown";
d5df0a
+	xen_image_anon.start = xen_image.start;
d5df0a
+	xen_image_anon.end   = xen_image.end;
d5df0a
 
d5df0a
 	verbprintf(vmisc, "xen_start = %llx, xen_end = %llx\n",
d5df0a
 	           xen_image.start, xen_image.end);
d5df0a
 
d5df0a
-	if (!xen_image.start && !xen_image.end) {
d5df0a
+	if ( stat != 2 ) {
d5df0a
 		fprintf(stderr, "error: mis-parsed xen range: %llx-%llx\n",
d5df0a
 		        xen_image.start, xen_image.end);
d5df0a
 		exit(EXIT_FAILURE);
d5df0a
 	}
d5df0a
+
d5df0a
 }
d5df0a
 
d5df0a
+void opd_create_passive_domain(int id, char const * image_kernel, 
d5df0a
+			       char const * range, char const * image_xen)
d5df0a
+{
d5df0a
+	char file[64];
d5df0a
+	struct kernel_image * image;
d5df0a
+	int stat;
d5df0a
+
d5df0a
+	image = xmalloc(sizeof(struct kernel_image));
d5df0a
+	image->name = xstrdup(image_kernel);
d5df0a
+	image->start = image->end = 0; 
d5df0a
+	stat = sscanf(range, "%llx,%llx", &image->start, &image->end);
d5df0a
+	image->id = id;
d5df0a
+	list_add(&image->list, &passive_vmlinux);
d5df0a
+	
d5df0a
+	if ( stat != 2 ) {
d5df0a
+		fprintf(stderr, "error: mis-parsed passive domain range for "
d5df0a
+			"domain %d: %llx-%llx\n", id, image->start, image->end);
d5df0a
+		exit(EXIT_FAILURE);
d5df0a
+	}
d5df0a
+
d5df0a
+	image = xmalloc(sizeof(struct kernel_image));
d5df0a
+	image->name = xstrdup(image_xen);
d5df0a
+	image->start = xen_image.start;
d5df0a
+	image->end = xen_image.end;
d5df0a
+	image->id = id;
d5df0a
+	list_add(&image->list, &passive_xen);
d5df0a
+
d5df0a
+	sprintf(file, "domain%d-apps", id);
d5df0a
+	image = xmalloc(sizeof(struct kernel_image));
d5df0a
+	image->name = xstrdup(file);
d5df0a
+	image->start = 0; 
d5df0a
+	image->end = 0;
d5df0a
+	image->id = id;
d5df0a
+	list_add(&image->list, &passive_apps);
d5df0a
+
d5df0a
+	sprintf(file, "domain%d-modules", id);
d5df0a
+	image = xmalloc(sizeof(struct kernel_image));
d5df0a
+	image->name = xstrdup(file);
d5df0a
+	image->start = 0; 
d5df0a
+	image->end = 0;
d5df0a
+	stat = sscanf(range, "%llx,%llx", &image->start, &image->end);
d5df0a
+	image->id = id;
d5df0a
+	list_add(&image->list, &passive_modules);
d5df0a
+
d5df0a
+	sprintf(file, "domain%d-xen-unknown", id);
d5df0a
+	image = xmalloc(sizeof(struct kernel_image));
d5df0a
+	image->name = xstrdup(file);
d5df0a
+	image->start = xen_image.start; 
d5df0a
+	image->end = xen_image.end;
d5df0a
+	image->id = id;
d5df0a
+	list_add(&image->list, &passive_xen_anon);
d5df0a
+
d5df0a
+}
d5df0a
+
d5df0a
+void opd_create_passive(char const *setup_file)
d5df0a
+{
d5df0a
+	FILE *fp;
d5df0a
+	int id=0;
d5df0a
+	char image_kernel[128+1];
d5df0a
+	char range[128+1];
d5df0a
+	char image_xen[128+1];
d5df0a
+	int stat;
d5df0a
+
d5df0a
+	image_kernel[0] = range[0] = image_xen[0] = 0;
d5df0a
+
d5df0a
+	fp = fopen(setup_file, "r");
d5df0a
+
d5df0a
+	if (!fp) {
d5df0a
+		fprintf(stderr, "error: Could not open Xen passive domain "
d5df0a
+			"setup file %s\n", setup_file);
d5df0a
+		exit(EXIT_FAILURE);
d5df0a
+	}
d5df0a
+
d5df0a
+	while (1) {
d5df0a
+		stat = fscanf(fp, "%d %128s %128s %128s", &id, image_kernel, range, 
d5df0a
+			image_xen);
d5df0a
+		if ( stat != 4 )
d5df0a
+			return;
d5df0a
+		opd_create_passive_domain(id, image_kernel, range, image_xen);
d5df0a
+	}
d5df0a
+
d5df0a
+	fclose(fp);
d5df0a
+}
d5df0a
 
d5df0a
 /**
d5df0a
  * Allocate and initialise a kernel image description
d5df0a
@@ -210,6 +318,75 @@ struct kernel_image * find_kernel_image(
d5df0a
 	struct list_head * pos;
d5df0a
 	struct kernel_image * image = &vmlinux_image;
d5df0a
 
d5df0a
+	if (current_domain != COORDINATOR_DOMAIN) {
d5df0a
+		/* we rely on cpu_mode value (i.e. trans->in_kernel)
d5df0a
+		 * to search the right image type: xen, kernel or user
d5df0a
+		 * We cannot use address ranges since hypervisor does not
d5df0a
+		 * share the same address space with fully virtualized guests,
d5df0a
+		 * and thus address ranges can overlap  */
d5df0a
+		switch ( trans->in_kernel ) {
d5df0a
+
d5df0a
+		/* user mode */
d5df0a
+		case 1:
d5df0a
+			list_for_each(pos, &passive_apps) {
d5df0a
+				image = list_entry(pos, struct kernel_image, list);
d5df0a
+				if (image->id == current_domain) 
d5df0a
+					return image;
d5df0a
+			}
d5df0a
+			return NULL;
d5df0a
+
d5df0a
+		/* kernel mode */
d5df0a
+		case 2:
d5df0a
+			list_for_each(pos, &passive_vmlinux) {
d5df0a
+				image = list_entry(pos, struct kernel_image, list);
d5df0a
+				if ( (image->id == current_domain)
d5df0a
+				     && ( (image->start == 0 && image->end == 0)
d5df0a
+					  || (image->start <= trans->pc 
d5df0a
+					      && image->end > trans->pc) ) )
d5df0a
+						return image;
d5df0a
+			}
d5df0a
+			/* if not in kernel image range then it should be a module */ 
d5df0a
+			list_for_each(pos, &passive_modules) {
d5df0a
+				image = list_entry(pos, struct kernel_image, list);
d5df0a
+				if (image->id == current_domain) 
d5df0a
+					return image;
d5df0a
+			}
d5df0a
+			/* This should not happen if the kernel and user level 
d5df0a
+                           oprofile code are sane and in sync */
d5df0a
+			return NULL;
d5df0a
+
d5df0a
+		/* hypervisor mode */
d5df0a
+		case 3:
d5df0a
+			list_for_each(pos, &passive_xen) {
d5df0a
+				image = list_entry(pos, struct kernel_image, list);
d5df0a
+				if (image->id == current_domain
d5df0a
+				    && image->start <= trans->pc 
d5df0a
+				    && image->end > trans->pc) 
d5df0a
+					return image;
d5df0a
+			}
d5df0a
+			list_for_each(pos, &passive_xen_anon) {
d5df0a
+				image = list_entry(pos, struct kernel_image, list);
d5df0a
+				if (image->id == current_domain)
d5df0a
+					return image;
d5df0a
+			}
d5df0a
+			return NULL;
d5df0a
+
d5df0a
+		default:
d5df0a
+			printf("Unexpected error on passive mode: CPU mode is "
d5df0a
+			       "%d for domain %d\n", trans->in_kernel, current_domain);
d5df0a
+			return NULL;
d5df0a
+		}
d5df0a
+		
d5df0a
+		
d5df0a
+	}
d5df0a
+
d5df0a
+	if (xen_image.start <= trans->pc && xen_image.end > trans->pc)
d5df0a
+		return &xen_image;
d5df0a
+ 
d5df0a
+	if (trans->in_kernel == 2) {
d5df0a
+		return &xen_image_anon;
d5df0a
+	}
d5df0a
+
d5df0a
 	if (no_vmlinux)
d5df0a
 		return image;
d5df0a
 
d5df0a
@@ -222,8 +399,5 @@ struct kernel_image * find_kernel_image(
d5df0a
 			return image;
d5df0a
 	}
d5df0a
 
d5df0a
-	if (xen_image.start <= trans->pc && xen_image.end > trans->pc)
d5df0a
-		return &xen_image;
d5df0a
-
d5df0a
-	return NULL;
d5df0a
+	return &vmlinux_image_anon;
d5df0a
 }
d5df0a
diff -up oprofile-0.9.7/daemon/opd_kernel.h.xen oprofile-0.9.7/daemon/opd_kernel.h
d5df0a
--- oprofile-0.9.7/daemon/opd_kernel.h.xen	2011-07-04 22:25:04.000000000 -0400
d5df0a
+++ oprofile-0.9.7/daemon/opd_kernel.h	2011-11-28 16:25:07.580000010 -0500
d5df0a
@@ -23,8 +23,12 @@ struct transient;
d5df0a
 /** create the kernel image */
d5df0a
 void opd_create_vmlinux(char const * name, char const * arg);
d5df0a
 
d5df0a
+/** create Xen image */
d5df0a
 void opd_create_xen(char const * name, char const * arg);
d5df0a
 
d5df0a
+/** create Xen passive domain images */
d5df0a
+void opd_create_passive(char const *setup_file);
d5df0a
+
d5df0a
 /** opd_reread_module_info - parse /proc/modules for kernel modules */
d5df0a
 void opd_reread_module_info(void);
d5df0a
 
d5df0a
@@ -33,6 +37,7 @@ struct kernel_image {
d5df0a
 	char * name;
d5df0a
 	vma_t start;
d5df0a
 	vma_t end;
d5df0a
+	int id;
d5df0a
 	struct list_head list;
d5df0a
 };
d5df0a
 
d5df0a
diff -up oprofile-0.9.7/daemon/opd_sfile.c.xen oprofile-0.9.7/daemon/opd_sfile.c
d5df0a
--- oprofile-0.9.7/daemon/opd_sfile.c.xen	2011-07-04 22:25:04.000000000 -0400
d5df0a
+++ oprofile-0.9.7/daemon/opd_sfile.c	2011-11-28 16:25:07.582000010 -0500
d5df0a
@@ -240,7 +240,7 @@ struct sfile * sfile_find(struct transie
d5df0a
 	}
d5df0a
 
d5df0a
 	/* we might need a kernel image start/end to hash on */
d5df0a
-	if (trans->in_kernel) {
d5df0a
+	else if (trans->in_kernel) {
d5df0a
 		ki = find_kernel_image(trans);
d5df0a
 		if (!ki) {
d5df0a
 			verbprintf(vsamples, "Lost kernel sample %llx\n", trans->pc);
d5df0a
diff -up oprofile-0.9.7/daemon/opd_trans.c.xen oprofile-0.9.7/daemon/opd_trans.c
d5df0a
--- oprofile-0.9.7/daemon/opd_trans.c.xen	2011-07-04 22:25:04.000000000 -0400
d5df0a
+++ oprofile-0.9.7/daemon/opd_trans.c	2011-11-28 16:25:07.584000010 -0500
d5df0a
@@ -31,6 +31,8 @@
d5df0a
 #include <stdio.h>
d5df0a
 #include <errno.h>
d5df0a
 
d5df0a
+int32_t current_domain = COORDINATOR_DOMAIN;
d5df0a
+
d5df0a
 extern size_t kernel_pointer_size;
d5df0a
 
d5df0a
 
d5df0a
@@ -203,6 +205,9 @@ static void code_kernel_enter(struct tra
d5df0a
 {
d5df0a
 	verbprintf(vmisc, "KERNEL_ENTER_SWITCH to kernel\n");
d5df0a
 	trans->in_kernel = 1;
d5df0a
+	/* if in passive domain mode cpu mode should be incremented */
d5df0a
+	if (current_domain != COORDINATOR_DOMAIN)
d5df0a
+		trans->in_kernel++;
d5df0a
 	clear_trans_current(trans);
d5df0a
 	/* subtlety: we must keep trans->cookie cached,
d5df0a
 	 * even though it's meaningless for the kernel -
d5df0a
@@ -216,6 +221,9 @@ static void code_user_enter(struct trans
d5df0a
 {
d5df0a
 	verbprintf(vmisc, "USER_ENTER_SWITCH to user-space\n");
d5df0a
 	trans->in_kernel = 0;
d5df0a
+	/* if in passive domain mode cpu mode should be incremented */
d5df0a
+	if (current_domain != COORDINATOR_DOMAIN)
d5df0a
+		trans->in_kernel++;
d5df0a
 	clear_trans_current(trans);
d5df0a
 	clear_trans_last(trans);
d5df0a
 }
d5df0a
@@ -244,17 +252,34 @@ static void code_trace_begin(struct tran
d5df0a
 static void code_xen_enter(struct transient * trans)
d5df0a
 {
d5df0a
 	verbprintf(vmisc, "XEN_ENTER_SWITCH to xen\n");
d5df0a
-	trans->in_kernel = 1;
d5df0a
+	trans->in_kernel = 2;
d5df0a
+	/* if in passive domain mode cpu mode should be incremented */
d5df0a
+	if (current_domain != COORDINATOR_DOMAIN)
d5df0a
+		trans->in_kernel++;
d5df0a
 	trans->current = NULL;
d5df0a
 	/* subtlety: we must keep trans->cookie cached, even though it's
d5df0a
-	 * meaningless for Xen - we won't necessarily get a cookie switch
d5df0a
-	 * on Xen exit. See comments in opd_sfile.c. It seems that we can
d5df0a
-	 * get away with in_kernel = 1 as long as we supply the correct
d5df0a
-	 * Xen image, and its address range in startup find_kernel_image
d5df0a
-	 * is modified to look in the Xen image also
d5df0a
-	 */
d5df0a
+	 * meaningless for Xen - same reason as for kernel */
d5df0a
 }
d5df0a
 
d5df0a
+static void code_domain_switch(struct transient *trans)
d5df0a
+{
d5df0a
+	/* While processing passive domain samples we ensure (in_kernel!=0)
d5df0a
+	 * We do this in order to ignore cookies for passive domain samples 
d5df0a
+	 * But, we have to remember the kernel value for coordinator domain, 
d5df0a
+	 * so we do the safe thing: increment when leaving the coordinator
d5df0a
+	 * domain and decrement when returning to it 
d5df0a
+ 	 */
d5df0a
+	if (current_domain == COORDINATOR_DOMAIN)
d5df0a
+		trans->in_kernel++;
d5df0a
+
d5df0a
+	trans->current = NULL;
d5df0a
+	current_domain = (int32_t) pop_buffer_value(trans);
d5df0a
+
d5df0a
+	/* If returning to coordinator domain restore the kernel value */
d5df0a
+	if (current_domain == COORDINATOR_DOMAIN)
d5df0a
+		trans->in_kernel--;
d5df0a
+}
d5df0a
+ 
d5df0a
 extern void code_spu_profiling(struct transient * trans);
d5df0a
 extern void code_spu_ctx_switch(struct transient * trans);
d5df0a
 
d5df0a
@@ -278,7 +303,7 @@ handler_t handlers[LAST_CODE + 1] = {
d5df0a
 	&code_spu_profiling,
d5df0a
 	&code_spu_ctx_switch,
d5df0a
 #else
d5df0a
-	&code_unknown,
d5df0a
+ 	&code_domain_switch,
d5df0a
 	&code_unknown,
d5df0a
 #endif
d5df0a
 	&code_ibs_fetch_sample,
d5df0a
diff -up oprofile-0.9.7/daemon/opd_trans.h.xen oprofile-0.9.7/daemon/opd_trans.h
d5df0a
--- oprofile-0.9.7/daemon/opd_trans.h.xen	2011-07-04 22:25:04.000000000 -0400
d5df0a
+++ oprofile-0.9.7/daemon/opd_trans.h	2011-11-28 16:25:07.585000010 -0500
d5df0a
@@ -21,6 +21,10 @@
d5df0a
 
d5df0a
 #include <stdint.h>
d5df0a
 
d5df0a
+#define COORDINATOR_DOMAIN -1
d5df0a
+
d5df0a
+extern int32_t current_domain;
d5df0a
+
d5df0a
 struct sfile;
d5df0a
 struct anon_mapping;
d5df0a
 
d5df0a
diff -up oprofile-0.9.7/daemon/oprofiled.c.xen oprofile-0.9.7/daemon/oprofiled.c
d5df0a
--- oprofile-0.9.7/daemon/oprofiled.c.xen	2011-07-04 22:25:04.000000000 -0400
d5df0a
+++ oprofile-0.9.7/daemon/oprofiled.c	2011-11-28 16:25:07.587000010 -0500
d5df0a
@@ -71,6 +71,7 @@ char * session_dir;
d5df0a
 int no_xen;
d5df0a
 char * xenimage;
d5df0a
 char * xen_range;
d5df0a
+char * xen_passive_setup;
d5df0a
 static char * verbose;
d5df0a
 static char * binary_name_filter;
d5df0a
 static char * events;
d5df0a
@@ -91,6 +92,7 @@ static struct poptOption options[] = {
d5df0a
 	{ "xen-range", 0, POPT_ARG_STRING, &xen_range, 0, "Xen VMA range", "start-end", },
d5df0a
 	{ "xen-image", 0, POPT_ARG_STRING, &xenimage, 0, "Xen image", "file", },
d5df0a
 	{ "image", 0, POPT_ARG_STRING, &binary_name_filter, 0, "image name filter", "profile these comma separated image" },
d5df0a
+	{ "xen-passive-setup", 0, POPT_ARG_STRING, &xen_passive_setup, 0, "Xen passive domain setup file", "filename", },
d5df0a
 	{ "separate-lib", 0, POPT_ARG_INT, &separate_lib, 0, "separate library samples for each distinct application", "[0|1]", },
d5df0a
 	{ "separate-kernel", 0, POPT_ARG_INT, &separate_kernel, 0, "separate kernel samples for each distinct application", "[0|1]", },
d5df0a
 	{ "separate-thread", 0, POPT_ARG_INT, &separate_thread, 0, "thread-profiling mode", "[0|1]" },
d5df0a
diff -up oprofile-0.9.7/daemon/oprofiled.h.xen oprofile-0.9.7/daemon/oprofiled.h
d5df0a
--- oprofile-0.9.7/daemon/oprofiled.h.xen	2011-07-04 22:25:04.000000000 -0400
d5df0a
+++ oprofile-0.9.7/daemon/oprofiled.h	2011-11-28 16:25:07.588000010 -0500
d5df0a
@@ -65,5 +65,6 @@ extern char * kernel_range;
d5df0a
 extern int no_xen;
d5df0a
 extern char * xenimage;
d5df0a
 extern char * xen_range;
d5df0a
+extern char * xen_passive_setup;
d5df0a
 
d5df0a
 #endif /* OPROFILED_H */
d5df0a
diff -up oprofile-0.9.7/doc/opcontrol.1.in.xen oprofile-0.9.7/doc/opcontrol.1.in
d5df0a
--- oprofile-0.9.7/doc/opcontrol.1.in.xen	2011-07-04 22:25:04.000000000 -0400
d5df0a
+++ oprofile-0.9.7/doc/opcontrol.1.in	2011-11-28 16:25:07.590000010 -0500
d5df0a
@@ -158,12 +158,41 @@ Xen image
d5df0a
 .br
d5df0a
 .TP
d5df0a
 .BI "--active-domains="<list>
d5df0a
-List of domain ids participating in a multi-domain profiling session. If 
d5df0a
+List of domain ids participating in a multi-domain profiling session. 
d5df0a
+Each of the specified domains must run an instance of oprofile. The 
d5df0a
+sequence of opcontrol commands in each domain must follow a given 
d5df0a
+order which is specified in the oprofile user manual. If 
d5df0a
 more than one domain is specified in <list> they should be separated using 
d5df0a
 commas. This option can only be used in domain 0 which is the only domain 
d5df0a
 that can coordinate a multi-domain profiling session. Including domain 0 in 
d5df0a
 the list of active domains is optional. (e.g. --active-domains=2,5,6 and 
d5df0a
---active-domains=0,2,5,6 are equivalent)
d5df0a
+--active-domains=0,2,5,6 are equivalent).
d5df0a
+This option can only be specified
d5df0a
+if --start-daemon is also specified and it is only 
d5df0a
+valid for the current run of the oprofile daemon; e.g. the list 
d5df0a
+of active domains is not persistent.
d5df0a
+.br
d5df0a
+.TP
d5df0a
+.BI "--passive-domains="<list> or "--domains="<list>
d5df0a
+List of domain ids to be profiled, separated by commas. 
d5df0a
+As opposed to the --active-domains option, the domains specified with this
d5df0a
+option do not need to run oprofile. This makes 
d5df0a
+profiling multiple domains easier. However, with the passive-domains option, 
d5df0a
+samples in user level processes and kernel modules cannot be 
d5df0a
+mapped to specific symbols and are aggregated
d5df0a
+under a generic class. Both --active-domains and --passive-domains 
d5df0a
+options can be specified in the same command, but the same domain cannot be
d5df0a
+specified in both options. This option can only be specified if either --start
d5df0a
+or --start-daemon is specified on the same command and it is only valid for 
d5df0a
+the current run of the oprofile daemon; e.g. the list of passive domains is 
d5df0a
+not persistent.
d5df0a
+.br
d5df0a
+.TP
d5df0a
+.BI "--passive-images="<list> or "--domains-images="<list>
d5df0a
+List of kernel images associated with the domains specified in the
d5df0a
+--passive-domains option, also separated by commas. The association
d5df0a
+between the images and domains is based on the order they are
d5df0a
+specified in both options.
d5df0a
 .br
d5df0a
 .SH OPTIONS (specific to System z)
d5df0a
 .TP
d5df0a
diff -up oprofile-0.9.7/libpp/format_output.cpp.xen oprofile-0.9.7/libpp/format_output.cpp
d5df0a
--- oprofile-0.9.7/libpp/format_output.cpp.xen	2011-07-04 22:25:04.000000000 -0400
d5df0a
+++ oprofile-0.9.7/libpp/format_output.cpp	2011-11-28 16:25:07.592000010 -0500
d5df0a
@@ -287,8 +287,8 @@ string formatter::format_app_name(field_
d5df0a
 {
d5df0a
 	return get_image_name(f.symbol.app_name,
d5df0a
 		long_filenames 
d5df0a
-			? image_name_storage::int_real_filename
d5df0a
-			: image_name_storage::int_real_basename,
d5df0a
+			? image_name_storage::int_filename
d5df0a
+			: image_name_storage::int_basename,
d5df0a
 		extra_found_images);
d5df0a
 }
d5df0a
 
d5df0a
diff -up oprofile-0.9.7/utils/opcontrol.xen oprofile-0.9.7/utils/opcontrol
d5df0a
--- oprofile-0.9.7/utils/opcontrol.xen	2011-07-20 15:36:48.000000000 -0400
d5df0a
+++ oprofile-0.9.7/utils/opcontrol	2011-11-28 16:28:56.431000248 -0500
d5df0a
@@ -236,9 +236,16 @@ opcontrol: usage:
d5df0a
                                  buffer-size.
d5df0a
    --cpu-buffer-size=num         per-cpu buffer size in units (2.6 kernel)
d5df0a
                                  Same rules as defined for buffer-size.
d5df0a
-   --xen                         Xen image (for Xen only)
d5df0a
-   --active-domains=<list>       List of domains in profiling session (for Xen)
d5df0a
-                                 (list contains domain ids separated by commas)
d5df0a
+   --xen=file                    Xen image (for Xen only)
d5df0a
+   --active-domains=id[,ids]     list of domains in multiple domain profiling session (Xen)
d5df0a
+                                 (detailed profiling of user level and kernel modules code)
d5df0a
+                                 (requires running oprofile on these domains)
d5df0a
+   --passive-domains=id[,ids]    list of domains to be profiled (Xen).
d5df0a
+     or --domains=id[,ids]       (coarse profiling of user level and kernel modules code)
d5df0a
+                                 (no need to run oprofile on these domains)
d5df0a
+   --passive-images=file[,files] list of kernel images associated with each passive domain
d5df0a
+     or 
d5df0a
+   --domain-images=file[,files]
d5df0a
 
d5df0a
   System z specific options
d5df0a
 
d5df0a
@@ -388,6 +395,9 @@ do_init()
d5df0a
 	SETUP_FILE="$SETUP_DIR/daemonrc"
d5df0a
 	SEC_SETUP_FILE="$SETUP_DIR/daemonrc_new"
d5df0a
 
d5df0a
+	# location for passing info about passive domains to daemon
d5df0a
+	PASSIVE_SETUP_FILE="$SETUP_DIR/xendomain.setup"
d5df0a
+
d5df0a
 	# initialize daemon vars
d5df0a
 	decide_oprofile_device_mount
d5df0a
 	CPUTYPE=`cat $MOUNT/cpu_type`
d5df0a
@@ -539,7 +549,7 @@ do_load_setup()
d5df0a
 }
d5df0a
 
d5df0a
 
d5df0a
-check_valid_args()
d5df0a
+check_valid_vmlinux()
d5df0a
 {
d5df0a
 	if test -z "$VMLINUX"; then
d5df0a
 		echo "No vmlinux file specified. You must specify the correct vmlinux file, e.g." >&2
d5df0a
@@ -560,8 +570,12 @@ check_valid_args()
d5df0a
 
d5df0a
 	echo "The specified vmlinux file \"$VMLINUX\" doesn't exist." >&2
d5df0a
 	exit 1
d5df0a
+}
d5df0a
+
d5df0a
 
d5df0a
 # similar check for Xen image
d5df0a
+check_valid_xen()
d5df0a
+{
d5df0a
 	if test -f "$XENIMAGE"; then
d5df0a
 		return
d5df0a
 	fi
d5df0a
@@ -622,6 +636,77 @@ get_image_range()
d5df0a
 }
d5df0a
 
d5df0a
 
d5df0a
+set_passive_domain()
d5df0a
+{
d5df0a
+	DOMAIN_ID=$1
d5df0a
+	FILE_IMAGE=$2
d5df0a
+	XEN_IMAGE=$3
d5df0a
+
d5df0a
+	if test "$FILE_IMAGE" = "none"; then
d5df0a
+		RANGE="0,0"
d5df0a
+		FILE_IMAGE="domain$DOMAIN_ID-kernel"
d5df0a
+	else
d5df0a
+		# Find VMA range for passive domain kernel image 
d5df0a
+		range_info=`objdump -h $FILE_IMAGE 2>/dev/null | grep " .text "`
d5df0a
+		tmp1=`echo $range_info | awk '{print $4}'`	
d5df0a
+		tmp_length=`echo $range_info | awk  '{print $3}'`
d5df0a
+		tmp2=`objdump -h $FILE_IMAGE --adjust-vma=0x$tmp_length 2>/dev/null | grep " .text " | awk  '{print $4}'`
d5df0a
+
d5df0a
+		if test -z "$tmp1" -o -z "$tmp2"; then
d5df0a
+			echo "The specified file $FILE_IMAGE does not seem to be valid" >&2
d5df0a
+			echo "Make sure you are using the non-compressed image file (e.g. vmlinux not vmlinuz)" >&2
d5df0a
+			vecho "found start as \"$tmp1\", end as \"$tmp2\"" >&2
d5df0a
+			exit 1
d5df0a
+		fi
d5df0a
+		RANGE="`echo $tmp1`,`echo $tmp2`"
d5df0a
+	fi
d5df0a
+	echo " $DOMAIN_ID $FILE_IMAGE $RANGE $XEN_IMAGE" >> $PASSIVE_SETUP_FILE
d5df0a
+}
d5df0a
+
d5df0a
+
d5df0a
+set_passive_domain_config()
d5df0a
+{
d5df0a
+
d5df0a
+	create_dir "$SETUP_DIR"
d5df0a
+
d5df0a
+	touch $PASSIVE_SETUP_FILE
d5df0a
+	chmod 644 $PASSIVE_SETUP_FILE
d5df0a
+	>$PASSIVE_SETUP_FILE
d5df0a
+
d5df0a
+	NDOMAINS=`echo "$PASSIVE_DOMAINS" | awk -F',' '{print NF}'`
d5df0a
+
d5df0a
+	if test -n "$PASSIVE_IMAGES"; then
d5df0a
+		NIMAGES=`echo "$PASSIVE_IMAGES" | awk -F',' '{print NF}'`
d5df0a
+		if [ $NDOMAINS != $NIMAGES ]; then
d5df0a
+			echo "# of passive domains and # of passive images doesn't match." >&2
d5df0a
+			do_help
d5df0a
+			exit 1
d5df0a
+		fi
d5df0a
+
d5df0a
+		for (( i=1; i<=$NDOMAINS; i++ )); do
d5df0a
+			ID=`echo "$PASSIVE_DOMAINS" | awk -F"," '{print $'$i'}'`
d5df0a
+			FILE=`echo "$PASSIVE_IMAGES" | awk -F',' '{print $'$i'}'`
d5df0a
+			if test ! -f "$FILE"; then
d5df0a
+				echo "Image $FILE for passive domain $ID not found." >&2
d5df0a
+				return 1
d5df0a
+			fi
d5df0a
+			LNK_KERNEL=/boot/domain$ID-kernel
d5df0a
+			ln -sf $FILE $LNK_KERNEL
d5df0a
+			LNK_XEN=/boot/domain$ID-xen
d5df0a
+			ln -sf $XENIMAGE $LNK_XEN
d5df0a
+			set_passive_domain $ID $LNK_KERNEL $LNK_XEN 
d5df0a
+		done
d5df0a
+	else
d5df0a
+			for (( i=1; i<=$NDOMAINS; i++ )); do
d5df0a
+				ID=`echo "$PASSIVE_DOMAINS" | awk -F"," '{print $'$i'}'`
d5df0a
+				LNK_XEN=/boot/domain$ID-xen
d5df0a
+				set_passive_domain $ID none $LNK_XEN
d5df0a
+		done 
d5df0a
+
d5df0a
+	fi
d5df0a
+}
d5df0a
+
d5df0a
+  
d5df0a
 # validate --separate= parameters. This function is called with IFS=,
d5df0a
 # so on each argument is splitted
d5df0a
 validate_separate_args()
d5df0a
@@ -932,10 +1017,20 @@ do_options()
d5df0a
 				DO_SETUP=yes
d5df0a
 				;;
d5df0a
 			--active-domains)
d5df0a
-				error_if_invalid_arg $arg $val
d5df0a
+				error_if_invalid_arg "$arg" "$val"
d5df0a
 				ACTIVE_DOMAINS=$val
d5df0a
 				DO_SETUP=yes
d5df0a
 				;;
d5df0a
+			--passive-domains|--domains)
d5df0a
+				error_if_invalid_arg "$arg" "$val"
d5df0a
+				PASSIVE_DOMAINS=$val
d5df0a
+				DO_SETUP=yes
d5df0a
+				;;
d5df0a
+			--passive-images|--domain-images)
d5df0a
+				error_if_invalid_arg "$arg" "$val"
d5df0a
+				PASSIVE_IMAGES=$val
d5df0a
+				DO_SETUP=yes
d5df0a
+				;;
d5df0a
 			-i|--image)
d5df0a
 				error_if_invalid_arg "$arg" "$val"
d5df0a
 				if test "$val" = "all"; then
d5df0a
@@ -1366,6 +1461,16 @@ check_event_mapping_data()
d5df0a
 			exit 1
d5df0a
 		fi
d5df0a
 	fi
d5df0a
+
d5df0a
+	if test -n "$ACTIVE_DOMAINS" -a "$START_DAEMON" != "yes"; then
d5df0a
+		echo "Option \"--active-domains\" can only be used with option \"-start-daemon\"." >&2
d5df0a
+		exit 1
d5df0a
+	fi
d5df0a
+
d5df0a
+	if test -n "$PASSIVE_DOMAINS" -a "$START_DAEMON" != "yes" -a "$START" != "yes"; then
d5df0a
+		echo "Option \"--passive-domains\" or "--domains" can only be used with option \"--start-daemon\" or \"--start\"." >&2
d5df0a
+		exit 1
d5df0a
+	fi
d5df0a
 }
d5df0a
 
d5df0a
 
d5df0a
@@ -1404,6 +1509,15 @@ do_param_setup()
d5df0a
 		fi
d5df0a
 	fi
d5df0a
 
d5df0a
+	if test -n "$PASSIVE_DOMAINS"; then
d5df0a
+		if test "$KERNEL_SUPPORT" = "yes"; then
d5df0a
+			echo $PASSIVE_DOMAINS >$MOUNT/passive_domains
d5df0a
+			set_passive_domain_config
d5df0a
+		else
d5df0a
+			echo "passive-domains not supported - ignored" >&2
d5df0a
+		fi
d5df0a
+	fi
d5df0a
+	
d5df0a
 	if test $NOTE_SIZE != 0; then
d5df0a
 		set_param notesize $NOTE_SIZE
d5df0a
 	fi
d5df0a
@@ -1566,7 +1680,8 @@ do_start_daemon()
d5df0a
 	fi
d5df0a
 
d5df0a
 	do_setup
d5df0a
-	check_valid_args
d5df0a
+ 	check_valid_vmlinux
d5df0a
+ 	check_valid_xen
d5df0a
 	get_image_range "linux"
d5df0a
 	get_image_range "xen"
d5df0a
 	do_param_setup
d5df0a
@@ -1600,6 +1715,10 @@ do_start_daemon()
d5df0a
 		OPD_ARGS="$OPD_ARGS --image=$IMAGE_FILTER"
d5df0a
 	fi
d5df0a
 
d5df0a
+	if ! test -z "$PASSIVE_DOMAINS"; then
d5df0a
+		OPD_ARGS="$OPD_ARGS --xen-passive-setup=$PASSIVE_SETUP_FILE"
d5df0a
+	fi
d5df0a
+
d5df0a
 	if test -n "$VERBOSE"; then
d5df0a
 		OPD_ARGS="$OPD_ARGS --verbose=$VERBOSE"
d5df0a
 	fi
d5df0a
@@ -1805,6 +1924,8 @@ do_save_session()
d5df0a
 	fi
d5df0a
 
d5df0a
 	hup_daemon
d5df0a
+
d5df0a
+	rm -f /boot/domain-*-kernel /boot/domain-*-xen
d5df0a
 }
d5df0a
 
d5df0a
 
d5df0a
@@ -1855,7 +1976,8 @@ do_operations()
d5df0a
 	fi
d5df0a
 
d5df0a
 	if test "$SETUP" = "yes"; then
d5df0a
-		check_valid_args
d5df0a
+		check_valid_vmlinux
d5df0a
+		check_valid_xen
d5df0a
 		do_save_setup
d5df0a
 	fi
d5df0a