Xenoprof passive domain support
PATCH 1/1 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.
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -77,6 +77,15 @@ } xenoprof_counter_t;DEFINE_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_GUEST_HANDLE (xenoprof_passive_t); +#endif /* __XEN_PUBLIC_XENOPROF_H__ */
xen/include/xen/xenoprof.h +1 -0
@@ -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
@@ -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 +7 -2
@@ -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,13 @@#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 DOMAIN_SWITCH_CODE 11 +#define LAST_CODE 12#endif /* OPD_INTERFACE_H */
daemon/opd_kernel.c +104 -0
138 lines not on this page · raw message
daemon/opd_kernel.h +7 -0
@@ -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 +38 -2
@@ -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 "opd_trans.h"
@@ -189,7 +192,7 @@ } -static void code_kernel_exit (struct transient * trans) +static void code_user_enter (struct transient * trans) {verbprintf (vmisc,"KERNEL_EXIT_SWITCH to user-space\n" ); trans->in_kernel =0 ;
@@ -218,6 +221,30 @@ trans->tracing =TRACING_OFF ; } +static void code_xen_enter (struct transient *trans) +{ +verbprintf (vmisc,"XEN_ENTER_SWITCH to xen\n" ); + trans->in_kernel =1 ; + trans->current =NULL ; +/* subtlety: we must keep trans->cookie cached, +* even though it's meaningless for Xen - +* we won't necessarily get a cookie switch on +* Xen exit. See comments in opd_sfile.c. +* It seems that we can get away with in_kernel = 1 as long as we +* supply the correct Xen image, and its address range in startup +* find_kernel_image is modified to look in the Xen image also +*/ +} + +long long other_domain =-1 ; + +static void code_domain_switch (struct transient *trans) +{ +/* We have to remember the old kernel value, so we do the safe thing: increment */ + trans->in_kernel++; + trans->current =NULL ; + other_domain =pop_buffer_value (trans); +}typedef void (*handler_t )(struct transient *);
@@ -227,12 +254,14 @@ &code_cpu_switch, &code_cookie_switch, &code_kernel_enter, - &code_kernel_exit, + &code_user_enter, &code_module_loaded,/* tgid handled differently */ &code_unknown, &code_trace_begin, &code_trace_end, + &code_xen_enter, + &code_domain_switch, };
@@ -266,6 +295,13 @@if (!is_escape_code (code)) {opd_put_sample (&trans, code); +if (other_domain !=-1 ) { +/* if last sample was for another domain, +restore trans fields */ + other_domain =-1 ; + trans.current =NULL ; + trans.in_kernel--; + }continue ; }
daemon/oprofiled.c +32 -0
@@ -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
@@ -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
Xiaowei,
Do you have a more recent patch for this? I'm having a hard time sorting out
the rejects, particularly the ones related to xenoprof-generic.patch. (I'm working against change set 10031.) Renato sent me something called xenoprof3.patch (could have been his name for this patch), but that could have just been his name for it.
Particularly confusing are the changes related to CPU_MODE_XEN inadd_kernel_ctx_swtich(). There's no case statement there at all anymore,
just an "if (in_kernel)" statement. And all I find in oprofile.h are #defines's for CPU_IS_KERNEL, CPU_TRACE_BEGIN...
Any help would be appreciated.
Which change set were your patches of 4/28 against?
Signature · 3 lines
Ray Bryant AMD Performance Labs Austin, Tx 512-602-0038 (o) 512-507-7807 (c)