Skip to contentSkip to conversation

Xenoprof passive domain support

PATCH Yang, Xiaowei 1 participant 1 message Apr 28, 2006

lore
Share & tools
lore
#0 lore raw

Resent the patch due to cset 9866 change (Rename *GUEST_HANDLE to *XEN_GUEST_HANDLE). Thanks,
xiaowei

Quoted 22 lines

-----Original Message-----
From: Yang, Xiaowei
Sent: 2006年4月28日 15:59
To: 'Santos, Jose Renato G'
Cc: '[email protected]'
Subject: [PATCH] Xenoprof passive domain support

Hi Renato,
This patch is to add Xenoprof passive domain support in SMP environment. Basically:
- It allocates per vcpu buffers for passive domain and maps them into primary domain's space.
- When primary domain gets sampled and triggers virq, its kernel module will handle passive domain' samples besides its owns. There is potential buffer overflow if passive is very busy while primary is idle. The simple workaround is to allocate a rather big buffer for passive. For now it works fine. A better way is to notify primary when passive buffer exceeds the threshold.
- When oprofile gets passive domain samples, it splits them in to 3 parts by PC ranges pre-definition: xen/kernel/application and maps the first two into functions. The oprofile version is a little old, for the patch was made last August.

Quoted 6 lines

The main usage is to use Xenoprof to profile HVM domain as passive domain, which provides enough information for low level performance tuning while no change in HVM is needed.

Thanks,
Xiaowei

Add Xenoprof passive domain support

linux-2.6-xen-sparse/arch/i386/oprofile/xenoprof.c +117 -12
diff -r e327fb66a8d9 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 passive_domid)
 {
 	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;
@@ -119,23 +122,61 @@
 
 	if (tail > head) {
 		while (tail < size) {
+			if (passive_domid)
+				oprofile_add_pc(~1UL, 0, passive_domid);
 			oprofile_add_pc(buf->event_log[tail].eip,
 					buf->event_log[tail].mode,
 					buf->event_log[tail].event);
-			oprofile_samples++;
+			if (!passive_domid)
+				oprofile_samples++;
+			else
+				p_oprofile_samples++;
 			tail++;
 		}
 		tail = 0;
 	}
 	while (tail < head) {
+		if (passive_domid)
+			oprofile_add_pc(~1UL, 0, passive_domid);
 		oprofile_add_pc(buf->event_log[tail].eip,
 				buf->event_log[tail].mode,
 				buf->event_log[tail].event);
-		oprofile_samples++;
+		if (!passive_domid)
+			oprofile_samples++;
+		else
+			p_oprofile_samples++;
 		tail++;
 	}
 
 	buf->event_tail = tail;
+}
+
+static void xenoprof_handle_passive(void)
+{
+	int i, j;
+	struct xenoprof_buf * buf;
+
+	for (i = 0; i < pdomains; i++)
+		for (j = 0; j < passive_domains[i].nbuf; j++) {
+			buf = p_xenoprof_buf[i][j];
+			xenoprof_add_pc(buf, passive_domains[i].domain_id);
+		}			
+}
+
+
+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)
+		xenoprof_handle_passive();
 
 	return IRQ_HANDLED;
 }
@@ -318,6 +359,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 +450,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 +525,8 @@
 
 void __exit oprofile_arch_exit(void)
 {
+	int i;
+
 	if (using_xenoprof)
 		exit_driverfs();
 
@@ -436,6 +534,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 +174 -37

347 lines not on this page · raw message

xen/arch/x86/domain.c +0 -1
diff -r e327fb66a8d9 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 e327fb66a8d9 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 e327fb66a8d9 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 e327fb66a8d9 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 e327fb66a8d9 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

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