Blame SOURCES/oprofile-0.9.7-xen.patch

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