From: "Jan Beulich" Subject: [PATCH] oprofile: don't pass around redundant, easily derived arguments Date: Tue, 06 Mar 2012 15:47:42 +0000 Message-ID: <4F563FAE0200007800076B45@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartCEE0DA8E.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartCEE0DA8E.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Passing both a struct vcpu pointer and the corresponding struct domain one is simply pointless, especially when intermediate functions just forward it without themselves making use of the already obtained value. Also constify a few function parameters. Signed-off-by: Jan Beulich --- a/xen/arch/ia64/xen/oprofile/xenoprof.c +++ b/xen/arch/ia64/xen/oprofile/xenoprof.c @@ -27,7 +27,7 @@ #include /* for vmx_user_mode() */ =20 int -xenoprofile_get_mode(struct vcpu *v, struct cpu_user_regs * const regs) +xenoprofile_get_mode(const struct vcpu *v, const struct cpu_user_regs = *regs) { int mode; =20 --- a/xen/arch/x86/oprofile/backtrace.c +++ b/xen/arch/x86/oprofile/backtrace.c @@ -32,10 +32,10 @@ DEFINE_COMPAT_HANDLE(frame_head32_t); #endif =20 static struct frame_head * -dump_hypervisor_backtrace(struct domain *d, struct vcpu *vcpu,=20 - struct frame_head * head, int mode) +dump_hypervisor_backtrace(struct vcpu *vcpu, const struct frame_head = *head, + int mode) { - if (!xenoprof_add_trace(d, vcpu, head->ret, mode)) + if (!xenoprof_add_trace(vcpu, head->ret, mode)) return 0; =20 /* frame pointers should strictly progress back up the stack @@ -57,8 +57,8 @@ static inline int is_32bit_vcpu(struct v #endif =20 static struct frame_head * -dump_guest_backtrace(struct domain *d, struct vcpu *vcpu,=20 - const struct frame_head *head, int mode) +dump_guest_backtrace(struct vcpu *vcpu, const struct frame_head *head, + int mode) { frame_head_t bufhead; =20 @@ -90,7 +90,7 @@ dump_guest_backtrace(struct domain *d, s return 0; } =20 - if (!xenoprof_add_trace(d, vcpu, bufhead.ret, mode)) + if (!xenoprof_add_trace(vcpu, bufhead.ret, mode)) return 0; =20 /* frame pointers should strictly progress back up the stack @@ -132,8 +132,8 @@ dump_guest_backtrace(struct domain *d, s * in the kernel mode. */ #if defined(CONFIG_FRAME_POINTER) -static int valid_hypervisor_stack(struct frame_head * head,=20 - struct cpu_user_regs * regs) +static int valid_hypervisor_stack(const struct frame_head *head, + const struct cpu_user_regs *regs) { unsigned long headaddr =3D (unsigned long)head; #ifdef CONFIG_X86_64 @@ -147,27 +147,24 @@ static int valid_hypervisor_stack(struct } #else /* without fp, it's just junk */ -static int valid_hypervisor_stack(struct frame_head * head,=20 - struct cpu_user_regs * regs) +static int valid_hypervisor_stack(const struct frame_head *head, + const struct cpu_user_regs *regs) { return 0; } #endif =20 -void xenoprof_backtrace(struct domain *d, struct vcpu *vcpu,=20 - struct cpu_user_regs * const regs, +void xenoprof_backtrace(struct vcpu *vcpu, const struct cpu_user_regs = *regs, unsigned long depth, int mode) { - struct frame_head *head; - - head =3D (struct frame_head *)regs->ebp; + const struct frame_head *head =3D (void *)regs->ebp; =20 if (mode > 1) { while (depth-- && valid_hypervisor_stack(head, regs)) - head =3D dump_hypervisor_backtrace(d, vcpu, head, mode); + head =3D dump_hypervisor_backtrace(vcpu, head, mode); return; } =20 while (depth-- && head) - head =3D dump_guest_backtrace(d, vcpu, head, mode); + head =3D dump_guest_backtrace(vcpu, head, mode); } --- a/xen/arch/x86/oprofile/xenoprof.c +++ b/xen/arch/x86/oprofile/xenoprof.c @@ -10,6 +10,7 @@ =20 #include #include +#include #include #ifdef CONFIG_COMPAT #include @@ -77,7 +78,8 @@ int compat_oprof_arch_counter(XEN_GUEST_ } #endif =20 -int xenoprofile_get_mode(struct vcpu *v, struct cpu_user_regs * const = regs) +int xenoprofile_get_mode(const struct vcpu *v, + const struct cpu_user_regs *regs) { if ( !guest_mode(regs) ) return 2; --- a/xen/common/xenoprof.c +++ b/xen/common/xenoprof.c @@ -511,24 +511,23 @@ static int xenoprof_add_sample(struct do return 1; } =20 -int xenoprof_add_trace(struct domain *d, struct vcpu *vcpu, - uint64_t eip, int mode) +int xenoprof_add_trace(struct vcpu *vcpu, uint64_t pc, int mode) { + struct domain *d =3D vcpu->domain; xenoprof_buf_t *buf =3D d->xenoprof->vcpu[vcpu->vcpu_id].buffer; =20 /* Do not accidentally write an escape code due to a broken frame. */ - if ( eip =3D=3D XENOPROF_ESCAPE_CODE ) + if ( pc =3D=3D XENOPROF_ESCAPE_CODE ) { invalid_buffer_samples++; return 0; } =20 - return xenoprof_add_sample(d, buf, eip, mode, 0); + return xenoprof_add_sample(d, buf, pc, mode, 0); } =20 -void xenoprof_log_event(struct vcpu *vcpu,=20 - struct cpu_user_regs * regs, uint64_t eip,=20 - int mode, int event) +void xenoprof_log_event(struct vcpu *vcpu, const struct cpu_user_regs = *regs, + uint64_t pc, int mode, int event) { struct domain *d =3D vcpu->domain; struct xenoprof_vcpu *v; @@ -565,7 +564,7 @@ void xenoprof_log_event(struct vcpu *vcp } } =20 - if ( xenoprof_add_sample(d, buf, eip, mode, event) ) + if ( xenoprof_add_sample(d, buf, pc, mode, event) ) { if ( is_active(vcpu->domain) ) active_samples++; @@ -581,7 +580,7 @@ void xenoprof_log_event(struct vcpu *vcp } =20 if ( backtrace_depth > 0 ) - xenoprof_backtrace(d, vcpu, regs, backtrace_depth, mode); + xenoprof_backtrace(vcpu, regs, backtrace_depth, mode); } =20 =20 --- a/xen/include/asm-ia64/xenoprof.h +++ b/xen/include/asm-ia64/xenoprof.h @@ -45,14 +45,13 @@ static inline int xenoprof_arch_ibs_coun =20 struct vcpu; struct cpu_user_regs; -int xenoprofile_get_mode(struct vcpu *v, struct cpu_user_regs * const = regs); +int xenoprofile_get_mode(const struct vcpu *, const struct cpu_user_regs = *); static inline int xenoprof_backtrace_supported(void) { return 0; } -static inline void xenoprof_backtrace( - struct domain *d, struct vcpu *vcpu,=20 - struct pt_regs *const regs, unsigned long depth, int mode) +static inline void xenoprof_backtrace(struct vcpu *vcpu, + const struct pt_regs *regs, unsigned long depth, int mode) { /* To be implemented */ return; --- a/xen/include/asm-x86/xenoprof.h +++ b/xen/include/asm-x86/xenoprof.h @@ -56,16 +56,15 @@ static inline void ibs_init(void) {} #define ibs_caps 0 #endif =20 -int xenoprofile_get_mode(struct vcpu *v, struct cpu_user_regs * const = regs); +int xenoprofile_get_mode(const struct vcpu *, const struct cpu_user_regs = *); =20 static inline int xenoprof_backtrace_supported(void) { return 1; } =20 -void xenoprof_backtrace( - struct domain *d, struct vcpu *vcpu,=20 - struct cpu_user_regs *const regs, unsigned long depth, int mode); +void xenoprof_backtrace(struct vcpu *, const struct cpu_user_regs *, + unsigned long depth, int mode); =20 #define xenoprof_shared_gmfn(d, gmaddr, maddr) \ do { \ --- a/xen/include/xen/xenoprof.h +++ b/xen/include/xen/xenoprof.h @@ -68,8 +68,7 @@ int is_active(struct domain *d); int is_passive(struct domain *d); void free_xenoprof_pages(struct domain *d); =20 -int xenoprof_add_trace(struct domain *d, struct vcpu *v,=20 - uint64_t eip, int mode); +int xenoprof_add_trace(struct vcpu *, uint64_t pc, int mode); =20 #define PMU_OWNER_NONE 0 #define PMU_OWNER_XENOPROF 1 @@ -77,8 +76,7 @@ int xenoprof_add_trace(struct domain *d, int acquire_pmu_ownship(int pmu_ownership); void release_pmu_ownship(int pmu_ownership); =20 -void xenoprof_log_event(struct vcpu *vcpu, - struct cpu_user_regs * regs, uint64_t eip, - int mode, int event); +void xenoprof_log_event(struct vcpu *, const struct cpu_user_regs *, + uint64_t pc, int mode, int event); =20 #endif /* __XEN__XENOPROF_H__ */ --=__PartCEE0DA8E.0__= Content-Type: text/plain; name="oprof-add-trace-no-domain.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="oprof-add-trace-no-domain.patch" oprofile: don't pass around redundant, easily derived arguments=0A=0APassin= g both a struct vcpu pointer and the corresponding struct domain=0Aone is = simply pointless, especially when intermediate functions just=0Aforward it = without themselves making use of the already obtained value.=0A=0AAlso = constify a few function parameters.=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/arch/ia64/xen/oprofile/xenoprof.c=0A+++ = b/xen/arch/ia64/xen/oprofile/xenoprof.c=0A@@ -27,7 +27,7 @@=0A #include = /* for vmx_user_mode() */=0A =0A int=0A-xenoprofile_get_mode= (struct vcpu *v, struct cpu_user_regs * const regs)=0A+xenoprofile_get_mode= (const struct vcpu *v, const struct cpu_user_regs *regs)=0A {=0A int = mode;=0A =0A--- a/xen/arch/x86/oprofile/backtrace.c=0A+++ b/xen/arch/x86/op= rofile/backtrace.c=0A@@ -32,10 +32,10 @@ DEFINE_COMPAT_HANDLE(frame_head32_= t);=0A #endif=0A =0A static struct frame_head *=0A-dump_hypervisor_backtrac= e(struct domain *d, struct vcpu *vcpu, =0A- struct = frame_head * head, int mode)=0A+dump_hypervisor_backtrace(struct vcpu = *vcpu, const struct frame_head *head,=0A+ int = mode)=0A {=0A- if (!xenoprof_add_trace(d, vcpu, head->ret, mode))=0A+ = if (!xenoprof_add_trace(vcpu, head->ret, mode))=0A return 0;=0A = =0A /* frame pointers should strictly progress back up the stack=0A@@= -57,8 +57,8 @@ static inline int is_32bit_vcpu(struct v=0A #endif=0A =0A = static struct frame_head *=0A-dump_guest_backtrace(struct domain *d, = struct vcpu *vcpu, =0A- const struct frame_head *head, int = mode)=0A+dump_guest_backtrace(struct vcpu *vcpu, const struct frame_head = *head,=0A+ int mode)=0A {=0A frame_head_t = bufhead;=0A =0A@@ -90,7 +90,7 @@ dump_guest_backtrace(struct domain *d, = s=0A return 0;=0A }=0A =0A- if (!xenoprof_add_trace(= d, vcpu, bufhead.ret, mode))=0A+ if (!xenoprof_add_trace(vcpu, = bufhead.ret, mode))=0A return 0;=0A =0A /* frame pointers = should strictly progress back up the stack=0A@@ -132,8 +132,8 @@ dump_guest= _backtrace(struct domain *d, s=0A * in the kernel mode.=0A */=0A #if = defined(CONFIG_FRAME_POINTER)=0A-static int valid_hypervisor_stack(struct = frame_head * head, =0A- struct cpu_user_regs * = regs)=0A+static int valid_hypervisor_stack(const struct frame_head = *head,=0A+ const struct cpu_user_regs = *regs)=0A {=0A unsigned long headaddr =3D (unsigned long)head;=0A = #ifdef CONFIG_X86_64=0A@@ -147,27 +147,24 @@ static int valid_hypervisor_st= ack(struct=0A }=0A #else=0A /* without fp, it's just junk */=0A-static int = valid_hypervisor_stack(struct frame_head * head, =0A- = struct cpu_user_regs * regs)=0A+static int valid_hypervisor_stack(const = struct frame_head *head,=0A+ const struct = cpu_user_regs *regs)=0A {=0A return 0;=0A }=0A #endif=0A =0A-void = xenoprof_backtrace(struct domain *d, struct vcpu *vcpu, =0A- = struct cpu_user_regs * const regs,=0A+void xenoprof_backtrace(struct vcpu = *vcpu, const struct cpu_user_regs *regs,=0A unsigned = long depth, int mode)=0A {=0A- struct frame_head *head;=0A-=0A- head = =3D (struct frame_head *)regs->ebp;=0A+ const struct frame_head *head = =3D (void *)regs->ebp;=0A =0A if (mode > 1) {=0A while = (depth-- && valid_hypervisor_stack(head, regs))=0A- head =3D = dump_hypervisor_backtrace(d, vcpu, head, mode);=0A+ head =3D = dump_hypervisor_backtrace(vcpu, head, mode);=0A return;=0A = }=0A =0A while (depth-- && head)=0A- head =3D dump_guest_backtra= ce(d, vcpu, head, mode);=0A+ head =3D dump_guest_backtrace(vcpu, = head, mode);=0A }=0A--- a/xen/arch/x86/oprofile/xenoprof.c=0A+++ b/xen/arch= /x86/oprofile/xenoprof.c=0A@@ -10,6 +10,7 @@=0A =0A #include =0A #include =0A+#include =0A #include = =0A #ifdef CONFIG_COMPAT=0A #include = =0A@@ -77,7 +78,8 @@ int compat_oprof_arch_counter(XEN_GUEST_=0A }=0A = #endif=0A =0A-int xenoprofile_get_mode(struct vcpu *v, struct cpu_user_regs= * const regs)=0A+int xenoprofile_get_mode(const struct vcpu *v,=0A+ = const struct cpu_user_regs *regs)=0A {=0A if ( = !guest_mode(regs) )=0A return 2;=0A--- a/xen/common/xenoprof.c=0A++= + b/xen/common/xenoprof.c=0A@@ -511,24 +511,23 @@ static int xenoprof_add_s= ample(struct do=0A return 1;=0A }=0A =0A-int xenoprof_add_trace(struct = domain *d, struct vcpu *vcpu,=0A- uint64_t eip, int = mode)=0A+int xenoprof_add_trace(struct vcpu *vcpu, uint64_t pc, int = mode)=0A {=0A+ struct domain *d =3D vcpu->domain;=0A xenoprof_buf_t = *buf =3D d->xenoprof->vcpu[vcpu->vcpu_id].buffer;=0A =0A /* Do not = accidentally write an escape code due to a broken frame. */=0A- if ( = eip =3D=3D XENOPROF_ESCAPE_CODE )=0A+ if ( pc =3D=3D XENOPROF_ESCAPE_COD= E )=0A {=0A invalid_buffer_samples++;=0A return 0;=0A = }=0A =0A- return xenoprof_add_sample(d, buf, eip, mode, 0);=0A+ = return xenoprof_add_sample(d, buf, pc, mode, 0);=0A }=0A =0A-void = xenoprof_log_event(struct vcpu *vcpu, =0A- struct = cpu_user_regs * regs, uint64_t eip, =0A- int mode, = int event)=0A+void xenoprof_log_event(struct vcpu *vcpu, const struct = cpu_user_regs *regs,=0A+ uint64_t pc, int mode, int = event)=0A {=0A struct domain *d =3D vcpu->domain;=0A struct = xenoprof_vcpu *v;=0A@@ -565,7 +564,7 @@ void xenoprof_log_event(struct = vcpu *vcp=0A }=0A }=0A =0A- if ( xenoprof_add_sample(d, = buf, eip, mode, event) )=0A+ if ( xenoprof_add_sample(d, buf, pc, mode, = event) )=0A {=0A if ( is_active(vcpu->domain) )=0A = active_samples++;=0A@@ -581,7 +580,7 @@ void xenoprof_log_event(struct = vcpu *vcp=0A }=0A =0A if ( backtrace_depth > 0 )=0A- = xenoprof_backtrace(d, vcpu, regs, backtrace_depth, mode);=0A+ = xenoprof_backtrace(vcpu, regs, backtrace_depth, mode);=0A }=0A =0A =0A--- = a/xen/include/asm-ia64/xenoprof.h=0A+++ b/xen/include/asm-ia64/xenoprof.h= =0A@@ -45,14 +45,13 @@ static inline int xenoprof_arch_ibs_coun=0A =0A = struct vcpu;=0A struct cpu_user_regs;=0A-int xenoprofile_get_mode(struct = vcpu *v, struct cpu_user_regs * const regs);=0A+int xenoprofile_get_mode(co= nst struct vcpu *, const struct cpu_user_regs *);=0A static inline int = xenoprof_backtrace_supported(void)=0A {=0A return 0;=0A }=0A-static = inline void xenoprof_backtrace(=0A- struct domain *d, struct vcpu = *vcpu, =0A- struct pt_regs *const regs, unsigned long depth, int = mode)=0A+static inline void xenoprof_backtrace(struct vcpu *vcpu,=0A+ = const struct pt_regs *regs, unsigned long depth, int mode)=0A {=0A /* = To be implemented */=0A return;=0A--- a/xen/include/asm-x86/xenoprof.h= =0A+++ b/xen/include/asm-x86/xenoprof.h=0A@@ -56,16 +56,15 @@ static = inline void ibs_init(void) {}=0A #define ibs_caps 0=0A #endif=0A =0A-int = xenoprofile_get_mode(struct vcpu *v, struct cpu_user_regs * const = regs);=0A+int xenoprofile_get_mode(const struct vcpu *, const struct = cpu_user_regs *);=0A =0A static inline int xenoprof_backtrace_supported(voi= d)=0A {=0A return 1;=0A }=0A =0A-void xenoprof_backtrace(=0A- = struct domain *d, struct vcpu *vcpu, =0A- struct cpu_user_regs *const = regs, unsigned long depth, int mode);=0A+void xenoprof_backtrace(struct = vcpu *, const struct cpu_user_regs *,=0A+ unsigned = long depth, int mode);=0A =0A #define xenoprof_shared_gmfn(d, gmaddr, = maddr) \=0A do { = \=0A--- a/xen/include/xen/xenoprof.h=0A+++ = b/xen/include/xen/xenoprof.h=0A@@ -68,8 +68,7 @@ int is_active(struct = domain *d);=0A int is_passive(struct domain *d);=0A void free_xenoprof_page= s(struct domain *d);=0A =0A-int xenoprof_add_trace(struct domain *d, = struct vcpu *v, =0A- uint64_t eip, int mode);=0A+int = xenoprof_add_trace(struct vcpu *, uint64_t pc, int mode);=0A =0A #define = PMU_OWNER_NONE 0=0A #define PMU_OWNER_XENOPROF 1=0A@@ -77,8 = +76,7 @@ int xenoprof_add_trace(struct domain *d,=0A int acquire_pmu_ownshi= p(int pmu_ownership);=0A void release_pmu_ownship(int pmu_ownership);=0A = =0A-void xenoprof_log_event(struct vcpu *vcpu,=0A- = struct cpu_user_regs * regs, uint64_t eip,=0A- int = mode, int event);=0A+void xenoprof_log_event(struct vcpu *, const struct = cpu_user_regs *,=0A+ uint64_t pc, int mode, int = event);=0A =0A #endif /* __XEN__XENOPROF_H__ */=0A --=__PartCEE0DA8E.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartCEE0DA8E.0__=--