Rework gcov support in Xen
PATCH v4 2/2 gcov: provide the capability to select gcov format automatically
In reply to Wei LiuAnd make it the default in Kconfig.
---
v4: dropped Jan's ack
--- xen/Kconfig.debug | 9 ++++++++- xen/common/gcov/Makefile | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-)
xen/Kconfig.debug +8 -1
@@ -39,10 +39,17 @@ config GCOV choice prompt "Specify Gcov format" depends on GCOV - default GCOV_FORMAT_5 + default GCOV_FORMAT_AUTODETECT ---help--- The gcov format is determined by gcc version. + If unsure, choose "Autodetect". + +config GCOV_FORMAT_AUTODETECT + bool "Autodetect" + ---help--- + Automatically select gcov format based on gcc version. + config GCOV_FORMAT_5 bool "GCC 5 format" ---help---
xen/common/gcov/Makefile +4 -0
@@ -3,3 +3,7 @@ obj-$(CONFIG_GCOV_FORMAT_3_4) += gcc_3_4.o obj-$(CONFIG_GCOV_FORMAT_4_7) += gcc_4_7.o obj-$(CONFIG_GCOV_FORMAT_4_9) += gcc_4_9.o obj-$(CONFIG_GCOV_FORMAT_5) += gcc_5.o +obj-$(CONFIG_GCOV_FORMAT_AUTODETECT) += $(call cc-ifversion,lt,0x040700, \ + gcc_3_4.o, $(call cc-ifversion,lt,0x040900, \ + gcc_4_7.o, $(call cc-ifversion,lt,0x050000, \ + gcc_4_9.o, gcc_5.o)))
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
v4 cover Rework gcov support in Xen
Only sending out two patches.
This series can be found at:
git://xenbits.xen.org/people/liuw/xen.git wip.rework-gcov-v$VERSION
Wei.
---
v2: see individual commits for changes.
Wei Liu (2):
gcov: add new interface and new formats support
gcov: provide the capability to select gcov format automatically
xen/Kconfig.debug | 46 +++++- xen/common/gcov/Makefile | 9 ++ xen/common/gcov/gcc_3_4.c | 367 ++++++++++++++++++++++++++++++++++++++++++++ xen/common/gcov/gcc_4_7.c | 204 ++++++++++++++++++++++++ xen/common/gcov/gcc_4_9.c | 35 +++++ xen/common/gcov/gcc_5.c | 35 +++++ xen/common/gcov/gcov.c | 257 +++++++++++++++++++++++++++++++ xen/common/gcov/gcov.h | 40 +++++ xen/common/gcov/gcov_base.c | 60 ++++++++ xen/common/sysctl.c | 8 + xen/include/public/sysctl.h | 39 ++++- xen/include/xen/gcov.h | 9 ++ 12 files changed, 1102 insertions(+), 7 deletions(-) create mode 100644 xen/common/gcov/gcc_3_4.c create mode 100644 xen/common/gcov/gcc_4_7.c create mode 100644 xen/common/gcov/gcc_4_9.c create mode 100644 xen/common/gcov/gcc_5.c create mode 100644 xen/common/gcov/gcov.c create mode 100644 xen/common/gcov/gcov.h create mode 100644 xen/common/gcov/gcov_base.c create mode 100644 xen/include/xen/gcov.h
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v4 1/2 gcov: add new interface and new formats support
A new sysctl interface for passing gcov data back to userspace. The new interface uses a customised record file format. The new sysctl reuses original sysctl number but renames the op to gcov_op.
Formats starting from gcc version 3.4 are supported. The code is rewritten so that a new format can be easily added in the future. Version specific code is grouped into different files. The format one needs to use can be picked via Kconfig. The default format is the newest one.
Userspace programs to handle extracted data will come in a later patch.
---
v4:
1. gcov conflicts with livepatch in Kconfig.
2. Finer grain formats
v3:
1. Check gcc version in gcc_*.c files.
2. Eliminate u32 / u64.
3. Mark __gcov_init as __init.
4. Fix a rebase error in v2.
5. Some other cosmetic fixes.
v2:
1. Use tab in Kconfig and indent help text properly.
2. Bump XEN_SYSCTL_INTERFACE_VERSION.
3. Fix cosmetic issues.
--- xen/Kconfig.debug | 39 ++++- xen/common/gcov/Makefile | 5 + xen/common/gcov/gcc_3_4.c | 367 ++++++++++++++++++++++++++++++++++++++++++++ xen/common/gcov/gcc_4_7.c | 204 ++++++++++++++++++++++++ xen/common/gcov/gcc_4_9.c | 35 +++++ xen/common/gcov/gcc_5.c | 35 +++++ xen/common/gcov/gcov.c | 257 +++++++++++++++++++++++++++++++ xen/common/gcov/gcov.h | 40 +++++ xen/common/gcov/gcov_base.c | 60 ++++++++ xen/common/sysctl.c | 8 + xen/include/public/sysctl.h | 39 ++++- xen/include/xen/gcov.h | 9 ++ 12 files changed, 1091 insertions(+), 7 deletions(-) create mode 100644 xen/common/gcov/gcc_3_4.c create mode 100644 xen/common/gcov/gcc_4_7.c create mode 100644 xen/common/gcov/gcc_4_9.c create mode 100644 xen/common/gcov/gcc_5.c create mode 100644 xen/common/gcov/gcov.c create mode 100644 xen/common/gcov/gcov.h create mode 100644 xen/common/gcov/gcov_base.c create mode 100644 xen/include/xen/gcov.h
xen/Kconfig.debug +34 -5
@@ -30,16 +30,45 @@ config FRAME_POINTER config GCOV bool "Gcov Support" - depends on BROKEN + depends on !LIVEPATCH ---help--- Enable gcov (a test coverage program in GCC) support. - Currently the data structure and hypercall interface are tied - to GCC 3.4 gcov format. You need to have a version of GCC - that is compatible with that format to make gcov work. - If unsure, say N here. +choice + prompt "Specify Gcov format" + depends on GCOV + default GCOV_FORMAT_5 + ---help--- + The gcov format is determined by gcc version. + +config GCOV_FORMAT_5 + bool "GCC 5 format" + ---help--- + Select this option to use the format specified in GCC 5. + Works in gcc version range [5, ...). + +config GCOV_FORMAT_4_9 + bool "GCC 4.9 format" + ---help--- + Select this option to use the format specified in GCC 4.9. + Works in gcc version range [4.9, 5). + +config GCOV_FORMAT_4_7 + bool "GCC 4.7 format" + ---help--- + Select this option to use the format specified in GCC 4.7. + Works in gcc version range [4.7, 4.9). + +config GCOV_FORMAT_3_4 + bool "GCC 3.4 format" + ---help--- + Select this option to use the format specified in GCC 3.4. + Works in gcc version range [3.4, 4.7). + +endchoice + config LOCK_PROFILE bool "Lock Profiling" ---help---
xen/common/gcov/Makefile +5 -0
@@ -0,0 +1,5 @@ +obj-y += gcov_base.o gcov.o +obj-$(CONFIG_GCOV_FORMAT_3_4) += gcc_3_4.o +obj-$(CONFIG_GCOV_FORMAT_4_7) += gcc_4_7.o +obj-$(CONFIG_GCOV_FORMAT_4_9) += gcc_4_9.o +obj-$(CONFIG_GCOV_FORMAT_5) += gcc_5.o
xen/common/gcov/gcc_3_4.c new file +367 -0
367 lines not on this page · raw message
xen/common/gcov/gcc_4_7.c new file +204 -0
204 lines not on this page · raw message
xen/common/gcov/gcc_4_9.c new file +35 -0
@@ -0,0 +1,35 @@ +/* +* This code provides functions to handle gcc's profiling data format +* introduced with gcc 4.7. +* +* This file is based heavily on gcc_3_4.c file. +* +* For a better understanding, refer to gcc source: +* gcc/gcov-io.h +* libgcc/libgcov.c +* +* Uses gcc-internal data definitions. +* +* Imported from Linux and modified for Xen by +* Wei Liu <[email protected]> +*/ + +#include "gcov.h" + +#if !(GCC_VERSION >=40900 &&GCC_VERSION <50100 ) +#error "Wrong version of GCC used to compile gcov" +#endif + +#define GCOV_COUNTERS 9 + +#include "gcc_4_7.c" + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/common/gcov/gcc_5.c new file +35 -0
@@ -0,0 +1,35 @@ +/* +* This code provides functions to handle gcc's profiling data format +* introduced with gcc 4.7. +* +* This file is based heavily on gcc_3_4.c file. +* +* For a better understanding, refer to gcc source: +* gcc/gcov-io.h +* libgcc/libgcov.c +* +* Uses gcc-internal data definitions. +* +* Imported from Linux and modified for Xen by +* Wei Liu <[email protected]> +*/ + +#include "gcov.h" + +#if GCC_VERSION <50000 +#error "Wrong version of GCC used to compile gcov" +#endif + +#define GCOV_COUNTERS 10 + +#include "gcc_4_7.c" + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/common/gcov/gcov.c new file +257 -0
257 lines not on this page · raw message
xen/common/gcov/gcov.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef _GCOV_H_ +#define _GCOV_H_ + +#include <xen/guest_access.h> +#include <xen/types.h> + +/* +* Profiling data types used for gcc 3.4 and above - these are defined by +* gcc and need to be kept as close to the original definition as possible to +* remain compatible. +*/ +#define GCOV_DATA_MAGIC ((unsigned int)0x67636461) +#define GCOV_TAG_FUNCTION ((unsigned int)0x01000000) +#define GCOV_TAG_COUNTER_BASE ((unsigned int)0x01a10000) +#define GCOV_TAG_FOR_COUNTER (count) \ + GCOV_TAG_COUNTER_BASE + ((unsigned int)(count) << 17) + +#define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + +#if BITS_PER_LONG >=64 +typedef long gcov_type ; +#else +typedef long long gcov_type ; +#endif + +/* Opaque gcov_info -- tied to specific gcc gcov formats */ +struct gcov_info ; + +void gcov_info_link (struct gcov_info *info); +struct gcov_info *gcov_info_next (const struct gcov_info *info); +void gcov_info_reset (struct gcov_info *info); +const char *gcov_info_filename (const struct gcov_info *info); +size_t gcov_info_to_gcda (char *buffer,const struct gcov_info *info); + +size_t gcov_store_uint32 (void *buffer,size_t off,uint32_t v); +size_t gcov_store_uint64 (void *buffer,size_t off,uint64_t v); + +#endif /* _GCOV_H_ */
xen/common/gcov/gcov_base.c new file +60 -0
60 lines not on this page · raw message
xen/common/sysctl.c +8 -0
@@ -28,6 +28,7 @@#include <xsm/xsm.h> #include <xen/pmstat.h> #include <xen/livepatch.h> +#include <xen/gcov.h> long do_sysctl (XEN_GUEST_HANDLE_PARAM (xen_sysctl_t) u_sysctl) {
@@ -395,6 +396,13 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) }break ; +#ifdef CONFIG_GCOV +case XEN_SYSCTL_gcov_op: + ret =sysctl_gcov_op (&op->u.gcov_op); + copyback =1 ; +break ; +#endif +#ifdef CONFIG_HAS_PCI case XEN_SYSCTL_pcitopoinfo: {
xen/include/public/sysctl.h +37 -2
@@ -36,7 +36,7 @@#include "physdev.h" #include "tmem.h" -#define XEN_SYSCTL_INTERFACE_VERSION 0x0000000E +#define XEN_SYSCTL_INTERFACE_VERSION 0x0000000F/* * Read console content from Xen buffer ring.
@@ -665,6 +665,40 @@ struct xen_sysctl_scheduler_op {typedef struct xen_sysctl_scheduler_op xen_sysctl_scheduler_op_t ;DEFINE_XEN_GUEST_HANDLE (xen_sysctl_scheduler_op_t); +/* +* Output format of gcov data: +* +* XEN_GCOV_FORMAT_MAGIC XEN_GCOV_RECORD ... XEN_GCOV_RECORD +* +* That is, one magic number followed by 0 or more record. +* +* The magic number is stored as an uint32_t field. +* +* The record is packed and variable in length. It has the form: +* +* filename: a NULL terminated path name extracted from gcov, used to +* create the name of gcda file. +* size: a uint32_t field indicating the size of the payload, the +* unit is byte. +* payload: the actual payload, length is `size' bytes. +* +* Userspace tool will split the record to different files. +*/ + +#define XEN_GCOV_FORMAT_MAGIC 0x58434f56/* XCOV */ + +#define XEN_SYSCTL_GCOV_get_size 0/* Get total size of output data */ +#define XEN_SYSCTL_GCOV_read 1/* Read output data */ +#define XEN_SYSCTL_GCOV_reset 2/* Reset all counters */ + +struct xen_sysctl_gcov_op { +uint32_t cmd; +uint32_t size;/* IN/OUT: size of the buffer */ +XEN_GUEST_HANDLE_64 (char ) buffer;/* OUT */ +}; +typedef struct xen_sysctl_gcov_op xen_sysctl_gcov_op_t ; +DEFINE_XEN_GUEST_HANDLE (xen_sysctl_gcov_op_t); +#define XEN_SYSCTL_PSR_CMT_get_total_rmid 0#define XEN_SYSCTL_PSR_CMT_get_l3_upscaling_factor 1/* The L3 cache size is returned in KB unit */
@@ -1073,7 +1107,7 @@ struct xen_sysctl {#define XEN_SYSCTL_numainfo 17#define XEN_SYSCTL_cpupool_op 18#define XEN_SYSCTL_scheduler_op 19 -/* #define XEN_SYSCTL_coverage_op 20 */ +#define XEN_SYSCTL_gcov_op 20#define XEN_SYSCTL_psr_cmt_op 21#define XEN_SYSCTL_pcitopoinfo 22#define XEN_SYSCTL_psr_cat_op 23
@@ -1102,6 +1136,7 @@ struct xen_sysctl {struct xen_sysctl_lockprof_op lockprof_op;struct xen_sysctl_cpupool_op cpupool_op;struct xen_sysctl_scheduler_op scheduler_op; +struct xen_sysctl_gcov_op gcov_op;struct xen_sysctl_psr_cmt_op psr_cmt_op;struct xen_sysctl_psr_cat_op psr_cat_op;struct xen_sysctl_tmem_op tmem_op;
xen/include/xen/gcov.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _XEN_GCOV_H +#define _XEN_GCOV_H + +#ifdef CONFIG_GCOV +#include <public/sysctl.h> +int sysctl_gcov_op (xen_sysctl_gcov_op_t *op); +#endif + +#endif /* _XEN_GCOV_H */
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v4 1/2] gcov: add new interface and new formats support
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 13.10.16 at 14:04, <[email protected]> wrote:
A new sysctl interface for passing gcov data back to userspace. The new interface uses a customised record file format. The new sysctl reuses original sysctl number but renames the op to
gcov_op.Formats starting from gcc version 3.4 are supported. The code is rewritten so that a new format can be easily added in the future. Version specific code is grouped into different files. The format one needs to use can be picked via
Kconfig. The default format is the newest one.
Quoted 3 lines
Userspace programs to handle extracted data will come in a later patch.
Signed-off-by Wei Liu <[email protected]>
with one suggestion and one further adjustment:
xen/common/gcov/gcc_4_9.c line 5
Quoted 8 lines
xen/common/gcov/gcc_4_9.c new file +5
-0@@ -0,0 +1,35 @@ +/* +* This code provides functions to handle gcc's profiling data format +* introduced with gcc 4.7. +* +* This file is based heavily on gcc_3_4.c file.
I think this is not really applicable here and in gcc_5.c.
Quoted 4 lines
xen/common/gcov/gcc_4_9.c new file +4
-0+* +* For a better understanding, refer to gcc source: +* gcc/gcov-io.h +* libgcc/libgcov.c
xen/common/gcov/gcc_4_9.c line 19
Quoted 10 lines
xen/common/gcov/gcc_4_9.c new file +10
-0+* +* Uses gcc-internal data definitions. +* +* Imported from Linux and modified for Xen by +* Wei Liu <[email protected]> +*/ + +#include "gcov.h" + +#if !(GCC_VERSION >=40900 &&GCC_VERSION <50100 )
This wants to be 50000 now on the right side, afaict.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v4 2/2] gcov: provide the capability to select gcov format automatically
In reply to Wei LiuQuoted 6 lines
Quoted 1 line
Quoted 1 line · On 13.10.16 at 14:04, <[email protected]> wrote:
And make it the default in
Kconfig.Signed-off-by Wei Liu <[email protected]>---
v4: dropped Jan's ack
Feel free to re-instate.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v4 1/2] gcov: add new interface and new formats support
In reply to Jan BeulichQuoted 18 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 13.10.16 at 14:04, <[email protected]> wrote:
A new sysctl interface for passing gcov data back to userspace. The new interface uses a customised record file format. The new sysctl reuses original sysctl number but renames the op to
gcov_op.Formats starting from gcc version 3.4 are supported. The code is rewritten so that a new format can be easily added in the future. Version specific code is grouped into different files. The format one needs to use can be picked via
Kconfig. The default format is the newest one.Quoted 3 lines
Userspace programs to handle extracted data will come in a later patch.
Signed-off-by Wei Liu <[email protected]>Acked-by Jan Beulich <[email protected]>with one suggestion and one further adjustment:
Quoted 10 lines
xen/common/gcov/gcc_4_9.c line 5
Quoted 8 lines
xen/common/gcov/gcc_4_9.c new file +5
-0@@ -0,0 +1,35 @@ +/* +* This code provides functions to handle gcc's profiling data format +* introduced with gcc 4.7. +* +* This file is based heavily on gcc_3_4.c file. I think this is not really applicable here and in
gcc_5.c.
OK. I will delete this.
Quoted 18 lines
Quoted 5 lines
xen/common/gcov/gcc_4_9.c new file +4
-0+* +* For a better understanding, refer to gcc source: +* gcc/gcov-io.h +* libgcc/libgcov.c xen/common/gcov/gcc_4_9.c line 19
Quoted 10 lines
xen/common/gcov/gcc_4_9.c new file +10
-0+* +* Uses gcc-internal data definitions. +* +* Imported from Linux and modified for Xen by +* Wei Liu <[email protected]> +*/ + +#include "gcov.h" + +#if !(GCC_VERSION >=40900 &&GCC_VERSION <50100 )This wants to be 50000 now on the right side, afaict.
Right. I missed this one place. I will fix it.
Thanks for your careful review.
Wei.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v4 1/2] gcov: add new interface and new formats support
In reply to Wei LiuQuoted 13 lines
xen/common/sysctl.c +1
-0@@ -28,6 +28,7 @@#include <xsm/xsm.h> #include <xen/pmstat.h> #include <xen/livepatch.h> +#include <xen/gcov.h> long do_sysctl (XEN_GUEST_HANDLE_PARAM (xen_sysctl_t) u_sysctl) {
xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 404
Quoted 9 lines
xen/common/sysctl.c +6
-0@@ -395,6 +396,13 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) }break ; +#ifdef CONFIG_GCOV +case XEN_SYSCTL_gcov_op: + ret =sysctl_gcov_op (&op->u.gcov_op); + copyback =1 ; +break ; +#endif
Should there be an XSM entry in flask_sysctl for this? And also in flask/policy/access_vectors
And in tools/flask/policy/policy.conf
Maybe that should be a seperate patch?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v4 1/2] gcov: add new interface and new formats support
Quoted 26 lines · Konrad Rzeszutek Wilk
Quoted 13 lines
xen/common/sysctl.c +1
-0@@ -28,6 +28,7 @@#include <xsm/xsm.h> #include <xen/pmstat.h> #include <xen/livepatch.h> +#include <xen/gcov.h> long do_sysctl (XEN_GUEST_HANDLE_PARAM (xen_sysctl_t) u_sysctl) {xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 404
Quoted 9 lines
xen/common/sysctl.c +6
-0@@ -395,6 +396,13 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) }break ; +#ifdef CONFIG_GCOV +case XEN_SYSCTL_gcov_op: + ret =sysctl_gcov_op (&op->u.gcov_op); + copyback =1 ; +break ; +#endif Should there be an XSM entry in
flask_sysctlfor this? And also in flask/policy/access_vectors
Quoted 3 lines
And in
tools/flask/policy/policy.confMaybe that should be a seperate patch?
Yes. That's planned. Didn't want to cram in too much stuff in one single patch.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel