From patchwork Thu Jun 1 17:34:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9760715 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1F95960363 for ; Thu, 1 Jun 2017 17:36:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B39127F17 for ; Thu, 1 Jun 2017 17:36:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3C612851A; Thu, 1 Jun 2017 17:36:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2E5C027F17 for ; Thu, 1 Jun 2017 17:36:39 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dGTzC-0008VI-9G; Thu, 01 Jun 2017 17:34:14 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dGTzB-0008Us-Nu for xen-devel@lists.xenproject.org; Thu, 01 Jun 2017 17:34:13 +0000 Received: from [193.109.254.147] by server-8.bemta-6.messagelabs.com id 1C/16-03696-51050395; Thu, 01 Jun 2017 17:34:13 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrMIsWRWlGSWpSXmKPExsXiVRvkpCsSYBB psH+dqMX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmrFr+w/mgs8OFaufH2BvYFxm2MXIxSEkMINR Yu3zhSwgDovAGlaJk+fnM4I4EgKXWCXau9uAMpxATpzEhKUz2CHsUonFy1cwgthCAioSN7evY oKwvzNKPL6qAGILC+hJHDn6gx3C9paY9eEZmM0mYCDxZsdeVhBbREBJ4t6qyUwgy5gF3jFJXD +9EWwoi4CqxMZrz8GG8gI1X33+HszmFPCVmHTqDNRiH4lvvyaAxUUF5CRWXm5hhagXlDg58wn Q0RxAQzUl1u/SBwkzC8hLbH87h3kCo8gsJFWzEKpmIalawMi8ilGjOLWoLLVI19BQL6koMz2j JDcxM0fX0MBMLze1uDgxPTUnMalYLzk/dxMjMAIYgGAH46dlAYcYJTmYlER5F8gbRArxJeWnV GYkFmfEF5XmpBYfYpTh4FCS4L3gB5QTLEpNT61Iy8wBxiJMWoKDR0mENwUkzVtckJhbnJkOkT rFqMsx6cD2L0xCLHn5ealS4rxLQYoEQIoySvPgRsDSwiVGWSlhXkago4R4ClKLcjNLUOVfMYp zMCoJ8xqCTOHJzCuB2/QK6AgmoCNebNMHOaIkESEl1cCYVhpg6O9weodndoFiml3OsUmvVxcp XN+vt6DH7dDxG28+hnvK32Xec38O36fksN75omyNfgbO+s/kL31x2ePZwflXT5VV8dYN23Tuu 4uaXipGKR33c/pdefnK7tO/pHW8tG7t/3ykLcnWrG+qwOGZgtkmknxpQRulN6yMKG86Lv1t9Y kVwVOVWIozEg21mIuKEwGg2r3oBgMAAA== X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-6.tower-27.messagelabs.com!1496338452!105822893!1 X-Originating-IP: [74.125.82.66] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 29826 invoked from network); 1 Jun 2017 17:34:12 -0000 Received: from mail-wm0-f66.google.com (HELO mail-wm0-f66.google.com) (74.125.82.66) by server-6.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 1 Jun 2017 17:34:12 -0000 Received: by mail-wm0-f66.google.com with SMTP id k15so13061630wmh.3 for ; Thu, 01 Jun 2017 10:34:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=YYKKnlQOAspVyYOFVG4LFQ9UOQauFxdMbjdXsu71578=; b=NZFMxXRvF5cFW+Cssh2r+YF/UnTofJxvsVCPy6q55H5EAqR/lOzCvJHjnxNLgFjciJ b73ifOPPEOMadQB1X7ikon9Gga2w+cxiXLxcNto2s7IaxGxucVgYENy9mvAib4KaAfEw vNI53iaHrAqKb+LZuTbrF0fD74wgiUWfdgBmaj2ekMepPtdbT39lLXlIwOJ3Ezp0nVge UC8Ci7hcfObgm6HQbxyGyYpFgO2WBl/8wXoTZ1Tj3x0H+inodT/7evYHBLuVsQ3Ozbjk A1P5888pG1wq9CqKPu7DWIE0wwEV583IeDF4ycAjXacoaodN2VD5WldqPwmHvTeFfwGR YdqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=YYKKnlQOAspVyYOFVG4LFQ9UOQauFxdMbjdXsu71578=; b=iIo1xFqUO9qVFxUWsJZiegLQKqfwSnExhjGEWpElGhh4tLs1q1xd179Ah6xy1c8k23 yJfcQ0CG944kypbYMvypXFTTQO5qcJ8crWQNO3U0rZdjNOF2Mu8rsW+Yr+auYjRII78L cmlJav/WKz7YVjqXcHYh2zZ54qQ4QiJU1BjH+tbENrFnFwzWSc1LnfjKZlBk9/BFqpjX Q5AXd6o9w7cYKgA8XWNrapo4LySjF8mz7HWwbpHzrFvdppgD+xyOWUOP2ZlcGOgb9G+u SkJq8LBlhiZuukoDMAm69ecw9U45QK3l3xuLsNQ2nMQKjBA6vUhXfa0KMso1u+p+/59Y S3pQ== X-Gm-Message-State: AODbwcBEchWRF1RBTYSFhcU+URB8Hs51FKd2I+mnrUbi8Zd3mdATHuoJ lyUf1vQvBH8OmQ== X-Received: by 10.28.211.5 with SMTP id k5mr227643wmg.11.1496338451902; Thu, 01 Jun 2017 10:34:11 -0700 (PDT) Received: from Solace.fritz.box ([80.66.223.25]) by smtp.gmail.com with ESMTPSA id m141sm16716wma.7.2017.06.01.10.34.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 10:34:11 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Thu, 01 Jun 2017 19:34:09 +0200 Message-ID: <149633844944.12814.3257610267149025065.stgit@Solace.fritz.box> In-Reply-To: <149633614204.12814.14390287626133023934.stgit@Solace.fritz.box> References: <149633614204.12814.14390287626133023934.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , Julien Grall , Jan Beulich , Doug Goldstein Subject: [Xen-devel] [PATCH 05/15] xen: make it possible to disable tracing in Kconfig. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP And compile it out of the hypervisor entirely. Code and other sections' sizes change as follows. Output of `size`: vanilla patched-Y patched-N text 1929007 1929007 1902783 data 337784 337784 337688 bss 1310464 1310464 1310336 Output of `size -A`: vanilla patched-Y patched-N .text 1372602 1372602 1348026 .rodata 312152 312152 310680 .init.text 244209 244209 244033 .init.data 224576 224576 224576 .data 57472 57472 57376 .bss 1310464 1310464 1310336 Total 23026516 23027008 22858069 No functional change intended. Signed-off-by: Dario Faggioli --- Cc: George Dunlap Cc: Andrew Cooper Cc: Jan Beulich Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Julien Grall Cc: Ian Jackson Cc: Wei Liu Cc: Doug Goldstein --- xen/Kconfig.debug | 8 ++++++++ xen/arch/x86/hvm/svm/entry.S | 2 ++ xen/arch/x86/trace.c | 23 +++++++++++++++++++++++ xen/common/trace.c | 39 +++++++++++++++++++++++++++++++++++---- xen/drivers/cpufreq/utility.c | 7 +++++-- xen/include/xen/trace.h | 30 +++++++++++++++++++++++++++++- 6 files changed, 102 insertions(+), 7 deletions(-) diff --git a/xen/Kconfig.debug b/xen/Kconfig.debug index 689f297..374c1c0 100644 --- a/xen/Kconfig.debug +++ b/xen/Kconfig.debug @@ -98,6 +98,14 @@ config PERF_ARRAYS ---help--- Enables software performance counter array histograms. +config TRACING + bool "Tracing" + default y + ---help--- + Enables collecting traces of events occurring in the hypervisor + in per-CPU ring buffers. The 'xentrace' tool can be used to read + the buffers and dump the content on the disk. + config VERBOSE_DEBUG bool "Verbose debug messages" diff --git a/xen/arch/x86/hvm/svm/entry.S b/xen/arch/x86/hvm/svm/entry.S index a4ab40a..ea4a106 100644 --- a/xen/arch/x86/hvm/svm/entry.S +++ b/xen/arch/x86/hvm/svm/entry.S @@ -61,10 +61,12 @@ __UNLIKELY_END(nsvm_hap) call svm_asid_handle_vmrun +#ifdef CONFIG_TRACING cmpb $0,tb_init_done(%rip) UNLIKELY_START(nz, svm_trace) call svm_trace_vmentry UNLIKELY_END(svm_trace) +#endif mov VCPU_svm_vmcb(%rbx),%rcx mov UREGS_rax(%rsp),%rax diff --git a/xen/arch/x86/trace.c b/xen/arch/x86/trace.c index 4a953c5..411f798 100644 --- a/xen/arch/x86/trace.c +++ b/xen/arch/x86/trace.c @@ -1,3 +1,4 @@ +#ifdef CONFIG_TRACING #include #include #include @@ -157,3 +158,25 @@ void __trace_ptwr_emulation(unsigned long addr, l1_pgentry_t npte) __trace_var(event, 1/*tsc*/, sizeof(d), &d); } } +#else /* !CONFIG_TRACING */ +#include +#include + +void __trace_pv_trap(int trapnr, unsigned long eip, + int use_error_code, unsigned error_code) +{ +} +void __trace_pv_page_fault(unsigned long addr, unsigned error_code) +{ +} +void __trace_trap_one_addr(unsigned event, unsigned long va) +{ +} +void __trace_trap_two_addr(unsigned event, unsigned long va1, + unsigned long va2) +{ +} +void __trace_ptwr_emulation(unsigned long addr, l1_pgentry_t npte) +{ +} +#endif /* CONFIG_TRACING */ diff --git a/xen/common/trace.c b/xen/common/trace.c index f29cd4c..2c18462 100644 --- a/xen/common/trace.c +++ b/xen/common/trace.c @@ -48,6 +48,11 @@ static unsigned int opt_tevt_mask; integer_param("tbuf_size", opt_tbuf_size); integer_param("tevt_mask", opt_tevt_mask); +#ifdef CONFIG_TRACING +/* a flag recording whether initialization has been done */ +/* or more properly, if the tbuf subsystem is enabled right now */ +int tb_init_done __read_mostly; + /* Pointers to the meta-data objects for all system trace buffers */ static struct t_info *t_info; static unsigned int t_info_pages; @@ -64,10 +69,6 @@ static u32 t_buf_highwater; static DEFINE_PER_CPU(unsigned long, lost_records); static DEFINE_PER_CPU(unsigned long, lost_records_first_tsc); -/* a flag recording whether initialization has been done */ -/* or more properly, if the tbuf subsystem is enabled right now */ -int tb_init_done __read_mostly; - /* which CPUs tracing is enabled on */ static cpumask_t tb_cpu_mask; @@ -868,6 +869,36 @@ void __trace_hypercall(uint32_t event, unsigned long op, __trace_var(event, 1, sizeof(uint32_t) * (1 + (a - d.args)), &d); } +#else /* !CONFIG_TRACING */ +void __init init_trace_bufs(void) +{ + opt_tbuf_size = 0; +} + +int tb_control(xen_sysctl_tbuf_op_t *tbc) +{ + static DEFINE_SPINLOCK(lock); + int rc = 0; + + spin_lock(&lock); + + switch ( tbc->cmd ) + { + case XEN_SYSCTL_TBUFOP_get_info: + tbc->evt_mask = 0; + tbc->buffer_mfn = 0; + tbc->size = 0; + break; + default: + rc = -ENOSYS; + break; + } + + spin_unlock(&lock); + + return rc; +} +#endif /* CONFIG_TRACING */ /* * Local variables: diff --git a/xen/drivers/cpufreq/utility.c b/xen/drivers/cpufreq/utility.c index 53879fe..b686a9d 100644 --- a/xen/drivers/cpufreq/utility.c +++ b/xen/drivers/cpufreq/utility.c @@ -362,11 +362,14 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, if (cpu_online(policy->cpu) && cpufreq_driver->target) { - unsigned int prev_freq = policy->cur; + uint32_t d[2] = { policy->cur, 0 }; retval = cpufreq_driver->target(policy, target_freq, relation); if ( retval == 0 ) - TRACE_2D(TRC_PM_FREQ_CHANGE, prev_freq/1000, policy->cur/1000); + { + d[1] = policy->cur/1000; + trace_var(TRC_PM_FREQ_CHANGE, 1, sizeof(d), d); + } } return retval; diff --git a/xen/include/xen/trace.h b/xen/include/xen/trace.h index 12966ea..d1b6c70 100644 --- a/xen/include/xen/trace.h +++ b/xen/include/xen/trace.h @@ -21,7 +21,11 @@ #ifndef __XEN_TRACE_H__ #define __XEN_TRACE_H__ +#ifdef CONFIG_TRACING extern int tb_init_done; +#else +#define tb_init_done 0 +#endif #include #include @@ -33,6 +37,7 @@ void init_trace_bufs(void); /* used to retrieve the physical address of the trace buffers */ int tb_control(struct xen_sysctl_tbuf_op *tbc); +#ifdef CONFIG_TRACING int trace_will_trace_event(u32 event); void __trace_var(u32 event, bool_t cycles, unsigned int extra, const void *); @@ -113,7 +118,7 @@ void __trace_hypercall(uint32_t event, unsigned long op, } \ } while ( 0 ) -#define TRACE_6D(_e,d1,d2,d3,d4,d5,d6) \ +#define TRACE_6D(_e,d1,d2,d3,d4,d5,d6) \ do { \ if ( unlikely(tb_init_done) ) \ { \ @@ -127,5 +132,28 @@ void __trace_hypercall(uint32_t event, unsigned long op, __trace_var(_e, 1, sizeof(_d), _d); \ } \ } while ( 0 ) +#else /* !CONFIG_TRACING */ +#define trace_will_trace_event(u) (0) +static inline void __trace_var(u32 event, bool_t cycles, unsigned int extra, + const void *extra_data) +{ +} +static inline void trace_var(u32 event, int cycles, int extra, + const void *extra_data) +{ +} +static inline void __trace_hypercall(uint32_t event, unsigned long op, + const xen_ulong_t *args) +{ +} + +#define TRACE_0D(e) do {} while ( 0 ) +#define TRACE_1D(e,d1) do {} while ( 0 ) +#define TRACE_2D(e,d1,d2) do {} while ( 0 ) +#define TRACE_3D(e,d1,d2,d3) do {} while ( 0 ) +#define TRACE_4D(e,d1,d2,d3,d4) do {} while ( 0 ) +#define TRACE_5D(e,d1,d2,d3,d4,d5) do {} while ( 0 ) +#define TRACE_6D(e,d1,d2,d3,d4,d5,d6) do {} while ( 0 ) +#endif /* CONFIG_TRACING */ #endif /* __XEN_TRACE_H__ */