Skip to contentSkip to conversation

LLVM coverage support for Xen

PATCH Superseded Roger Pau Monne 5 participants 24 messages Nov 9, 2017 – Jan 23, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover LLVM coverage support for Xen

Hello,

The following patch series enables LLVM coverage support for the Xen hypervisor. This first patches are a re-organization of the gcov support, in order to make the support generic for all coverage technologies. This is mostly a name change from gcov -> cov in several places and files, together with the addition of a Kconfig option in order to enable LLVM coverage.

Patch 7 introduces the actual LLVM coverage support code that allows fetching the coverage data from Xen. Finally patch 9 adds the documentation on how to use this feature.

A sample coverage report obtained after booting a PVHv2 Dom0 can be found at:

http://xenbits.xen.org/people/royger/xen_profile/

Thanks, Roger.

Roger Pau Monne (9):
kconfig/gcov: remove gcc version choice from kconfig
gcov: rename folder and header to coverage
gcov: rename sysctl and functions
gcov: introduce hooks for the sysctl
coverage: introduce generic file
kconfig/gcov: rename to coverage
coverage: introduce support for llvm profiling
xsm: add bodge when compiling with llvm coverage support
coverage: add documentation for LLVM coverage

 docs/misc/coverage.markdown               |  49 +++++++++-
 tools/misc/xencov.c                       |  28 +++---
 xen/Kconfig.debug                         |  53 +---------
 xen/Rules.mk                              |   6 +-
 xen/common/Makefile                       |   2 +-
 xen/common/coverage/Makefile              |  11 +++
 xen/common/coverage/coverage.c            |  73 ++++++++++++++
 xen/common/coverage/coverage.h            |  13 +++
 xen/common/{gcov => coverage}/gcc_3_4.c   |   0
 xen/common/{gcov => coverage}/gcc_4_7.c   |   0
 xen/common/{gcov => coverage}/gcc_4_9.c   |   0
 xen/common/{gcov => coverage}/gcc_5.c     |   0
 xen/common/{gcov => coverage}/gcc_7.c     |   0
 xen/common/{gcov => coverage}/gcov.c      |  42 ++------
 xen/common/{gcov => coverage}/gcov.h      |   0
 xen/common/{gcov => coverage}/gcov_base.c |   0
 xen/common/coverage/llvm.c                | 154 ++++++++++++++++++++++++++++++
 xen/common/gcov/Makefile                  |  11 ---
 xen/common/sysctl.c                       |   8 +-
 xen/include/public/sysctl.h               |  18 ++--
 xen/include/xen/coverage.h                |  14 +++
 xen/include/xen/gcov.h                    |   9 --
 xen/include/xsm/dummy.h                   |  14 +++
 23 files changed, 371 insertions(+), 134 deletions(-)
 create mode 100644 xen/common/coverage/Makefile
 create mode 100644 xen/common/coverage/coverage.c
 create mode 100644 xen/common/coverage/coverage.h
 rename xen/common/{gcov => coverage}/gcc_3_4.c (100%)
 rename xen/common/{gcov => coverage}/gcc_4_7.c (100%)
 rename xen/common/{gcov => coverage}/gcc_4_9.c (100%)
 rename xen/common/{gcov => coverage}/gcc_5.c (100%)
 rename xen/common/{gcov => coverage}/gcc_7.c (100%)
 rename xen/common/{gcov => coverage}/gcov.c (89%)
 rename xen/common/{gcov => coverage}/gcov.h (100%)
 rename xen/common/{gcov => coverage}/gcov_base.c (100%)
 create mode 100644 xen/common/coverage/llvm.c
 delete mode 100644 xen/common/gcov/Makefile
 create mode 100644 xen/include/xen/coverage.h
 delete mode 100644 xen/include/xen/gcov.h
Signature · 7 lines
2.13.6 (Apple Git-96)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH v2 1/9 kconfig/gcov: remove gcc version choice from kconfig

Use autodetect only.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- New in this version.

---
 xen/Kconfig.debug        | 46 ----------------------------------------------
 xen/common/gcov/Makefile | 15 +++++----------
 2 files changed, 5 insertions(+), 56 deletions(-)
xen/Kconfig.debug +0 -46
index 8d70f63743..7bb0465b5d 100644
@@ -37,52 +37,6 @@ config GCOV
 
 	  If unsure, say N here.
 
-choice
-	prompt "Specify Gcov format"
-	depends on GCOV
-	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_7
-	bool "GCC 7 format"
-	---help---
-	  Select this option to use the format specified in GCC 7.
-	  Works in gcc version range [7, ...).
-
-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, 7).
-
-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 -10
index f68d050eca..a7a48494ca 100644
@@ -1,11 +1,6 @@
 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
-obj-$(CONFIG_GCOV_FORMAT_7)   += gcc_7.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, $(call cc-ifversion,lt,0x070000, \
-						gcc_5.o, gcc_7.o))))
+obj-y += $(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, $(call cc-ifversion,lt,0x070000, \
+		gcc_5.o, gcc_7.o))))
Signature · 7 lines
2.13.6 (Apple Git-96)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#4 lore raw

PATCH v2 2/9 gcov: rename folder and header to coverage

In reply to Roger Pau Monne

Preparatory change before adding llvm profiling support. No functional change.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Rename guard in coverage.h header.

---
 xen/common/Makefile                       | 2 +-
 xen/common/{gcov => coverage}/Makefile    | 0
 xen/common/{gcov => coverage}/gcc_3_4.c   | 0
 xen/common/{gcov => coverage}/gcc_4_7.c   | 0
 xen/common/{gcov => coverage}/gcc_4_9.c   | 0
 xen/common/{gcov => coverage}/gcc_5.c     | 0
 xen/common/{gcov => coverage}/gcc_7.c     | 0
 xen/common/{gcov => coverage}/gcov.c      | 0
 xen/common/{gcov => coverage}/gcov.h      | 0
 xen/common/{gcov => coverage}/gcov_base.c | 0
 xen/common/sysctl.c                       | 2 +-
 xen/include/xen/{gcov.h => coverage.h}    | 4 ++--
 12 files changed, 4 insertions(+), 4 deletions(-)
 rename xen/common/{gcov => coverage}/Makefile (100%)
 rename xen/common/{gcov => coverage}/gcc_3_4.c (100%)
 rename xen/common/{gcov => coverage}/gcc_4_7.c (100%)
 rename xen/common/{gcov => coverage}/gcc_4_9.c (100%)
 rename xen/common/{gcov => coverage}/gcc_5.c (100%)
 rename xen/common/{gcov => coverage}/gcc_7.c (100%)
 rename xen/common/{gcov => coverage}/gcov.c (100%)
 rename xen/common/{gcov => coverage}/gcov.h (100%)
 rename xen/common/{gcov => coverage}/gcov_base.c (100%)
 rename xen/include/xen/{gcov.h => coverage.h} (76%)
xen/common/Makefile +1 -1
index 66cc2c8995..ad181636f6 100644
@@ -74,7 +74,7 @@ tmem-y := tmem.o tmem_xen.o tmem_control.o
 tmem-$(CONFIG_COMPAT) += compat/tmem_xen.o
 obj-$(CONFIG_TMEM) += $(tmem-y)
 
-subdir-$(CONFIG_GCOV) += gcov
+subdir-$(CONFIG_GCOV) += coverage
 subdir-$(CONFIG_UBSAN) += ubsan
 
 subdir-y += libelf
xen/common/coverage/Makefile renamed from xen/common/gcov/Makefile +0 -0
similarity index 100%
rename from xen/common/gcov/Makefile
rename to xen/common/coverage/Makefile
xen/common/coverage/gcc_3_4.c renamed from xen/common/gcov/gcc_3_4.c +0 -0
similarity index 100%
rename from xen/common/gcov/gcc_3_4.c
rename to xen/common/coverage/gcc_3_4.c
xen/common/coverage/gcc_4_7.c renamed from xen/common/gcov/gcc_4_7.c +0 -0
similarity index 100%
rename from xen/common/gcov/gcc_4_7.c
rename to xen/common/coverage/gcc_4_7.c
xen/common/coverage/gcc_4_9.c renamed from xen/common/gcov/gcc_4_9.c +0 -0
similarity index 100%
rename from xen/common/gcov/gcc_4_9.c
rename to xen/common/coverage/gcc_4_9.c
xen/common/coverage/gcc_5.c renamed from xen/common/gcov/gcc_5.c +0 -0
similarity index 100%
rename from xen/common/gcov/gcc_5.c
rename to xen/common/coverage/gcc_5.c
xen/common/coverage/gcc_7.c renamed from xen/common/gcov/gcc_7.c +0 -0
similarity index 100%
rename from xen/common/gcov/gcc_7.c
rename to xen/common/coverage/gcc_7.c
xen/common/coverage/gcov.c renamed from xen/common/gcov/gcov.c +0 -0
similarity index 100%
rename from xen/common/gcov/gcov.c
rename to xen/common/coverage/gcov.c
xen/common/coverage/gcov.h renamed from xen/common/gcov/gcov.h +0 -0
similarity index 100%
rename from xen/common/gcov/gcov.h
rename to xen/common/coverage/gcov.h
xen/common/coverage/gcov_base.c renamed from xen/common/gcov/gcov_base.c +0 -0
similarity index 100%
rename from xen/common/gcov/gcov_base.c
rename to xen/common/coverage/gcov_base.c
xen/common/sysctl.c +1 -1
index 08198b7150..56def766e6 100644
@@ -27,7 +27,7 @@
 #include <xsm/xsm.h>
 #include <xen/pmstat.h>
 #include <xen/livepatch.h>
-#include <xen/gcov.h>
+#include <xen/coverage.h>
 
 long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
 {
xen/include/xen/coverage.h renamed from xen/include/xen/gcov.h +2 -2
similarity index 76%
rename from xen/include/xen/gcov.h
rename to xen/include/xen/coverage.h
index ef22eafc1f..b34c304cba 100644
@@ -1,5 +1,5 @@
-#ifndef _XEN_GCOV_H
-#define _XEN_GCOV_H
+#ifndef _XEN_COV_H
+#define _XEN_COV_H
 
 #ifdef CONFIG_GCOV
 #include <public/sysctl.h>
Signature · 7 lines
2.13.6 (Apple Git-96)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v2 2/9
#5 lore raw

Re: [PATCH v2 for-next 2/9] gcov: rename folder and header to coverage

Quoted 10 lines · Roger Pau Monne

Preparatory change before adding llvm profiling support. No functional change.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw

PATCH v2 3/9 gcov: rename sysctl and functions

In reply to Roger Pau Monne

Change gcov to cov (for internal interfaces) or coverage (for the public ones).

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
---
Changes since v1:
- Use coverage instead of cov in the public interface.

---
 tools/misc/xencov.c         | 28 ++++++++++++++--------------
 xen/common/coverage/gcov.c  |  8 ++++----
 xen/common/sysctl.c         |  4 ++--
 xen/include/public/sysctl.h | 12 ++++++------
 xen/include/xen/coverage.h  |  2 +-
 5 files changed, 27 insertions(+), 27 deletions(-)
tools/misc/xencov.c +14 -14
index 4130f425dc..e5b40dba9c 100644
@@ -26,31 +26,31 @@
 
 static xc_interface *xch = NULL;
 
-int gcov_sysctl(int op, struct xen_sysctl *sysctl,
-                struct xc_hypercall_buffer *buf, uint32_t buf_size)
+int cov_sysctl(int op, struct xen_sysctl *sysctl,
+               struct xc_hypercall_buffer *buf, uint32_t buf_size)
 {
     DECLARE_HYPERCALL_BUFFER_ARGUMENT(buf);
 
     memset(sysctl, 0, sizeof(*sysctl));
-    sysctl->cmd = XEN_SYSCTL_gcov_op;
+    sysctl->cmd = XEN_SYSCTL_coverage_op;
 
-    sysctl->u.gcov_op.cmd = op;
-    sysctl->u.gcov_op.size = buf_size;
-    set_xen_guest_handle(sysctl->u.gcov_op.buffer, buf);
+    sysctl->u.coverage_op.cmd = op;
+    sysctl->u.coverage_op.size = buf_size;
+    set_xen_guest_handle(sysctl->u.coverage_op.buffer, buf);
 
     return xc_sysctl(xch, sysctl);
 }
 
-static void gcov_read(const char *fn)
+static void cov_read(const char *fn)
 {
     struct xen_sysctl sys;
     uint32_t total_len;
     DECLARE_HYPERCALL_BUFFER(uint8_t, p);
     FILE *f;
 
-    if (gcov_sysctl(XEN_SYSCTL_GCOV_get_size, &sys, NULL, 0) < 0)
+    if (cov_sysctl(XEN_SYSCTL_COVERAGE_get_size, &sys, NULL, 0) < 0)
         err(1, "getting total length");
-    total_len = sys.u.gcov_op.size;
+    total_len = sys.u.coverage_op.size;
 
     /* Shouldn't exceed a few hundred kilobytes */
     if (total_len > 8u * 1024u * 1024u)
@@ -61,7 +61,7 @@ static void gcov_read(const char *fn)
         err(1, "allocating buffer");
 
     memset(p, 0, total_len);
-    if (gcov_sysctl(XEN_SYSCTL_GCOV_read, &sys, HYPERCALL_BUFFER(p),
+    if (cov_sysctl(XEN_SYSCTL_COVERAGE_read, &sys, HYPERCALL_BUFFER(p),
                     total_len) < 0)
         err(1, "getting gcov data");
 
@@ -82,11 +82,11 @@ static void gcov_read(const char *fn)
     xc_hypercall_buffer_free(xch, p);
 }
 
-static void gcov_reset(void)
+static void cov_reset(void)
 {
     struct xen_sysctl sys;
 
-    if (gcov_sysctl(XEN_SYSCTL_GCOV_reset, &sys, NULL, 0) < 0)
+    if (cov_sysctl(XEN_SYSCTL_COVERAGE_reset, &sys, NULL, 0) < 0)
         err(1, "resetting gcov information");
 }
 
@@ -126,9 +126,9 @@ int main(int argc, char **argv)
         err(1, "opening xc interface");
 
     if (strcmp(argv[0], "reset") == 0)
-        gcov_reset();
+        cov_reset();
     else if (strcmp(argv[0], "read") == 0)
-        gcov_read(argc > 1 ? argv[1] : "-");
+        cov_read(argc > 1 ? argv[1] : "-");
     else
         usage(1);
 
xen/common/coverage/gcov.c +4 -4
index 283d2eec86..798032cbbb 100644
@@ -209,18 +209,18 @@ static int gcov_dump_all(XEN_GUEST_HANDLE_PARAM(char) buffer,
     return ret;
 }
 
-int sysctl_gcov_op(struct xen_sysctl_gcov_op *op)
+int sysctl_cov_op(struct xen_sysctl_coverage_op *op)
 {
     int ret;
 
     switch ( op->cmd )
     {
-    case XEN_SYSCTL_GCOV_get_size:
+    case XEN_SYSCTL_COVERAGE_get_size:
         op->size = gcov_get_size();
         ret = 0;
         break;
 
-    case XEN_SYSCTL_GCOV_read:
+    case XEN_SYSCTL_COVERAGE_read:
     {
         XEN_GUEST_HANDLE_PARAM(char) buf;
         uint32_t size = op->size;
@@ -233,7 +233,7 @@ int sysctl_gcov_op(struct xen_sysctl_gcov_op *op)
         break;
     }
 
-    case XEN_SYSCTL_GCOV_reset:
+    case XEN_SYSCTL_COVERAGE_reset:
         gcov_reset_all_counters();
         ret = 0;
         break;
xen/common/sysctl.c +2 -2
index 56def766e6..f2ae6295ff 100644
@@ -397,8 +397,8 @@ 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);
+    case XEN_SYSCTL_coverage_op:
+        ret = sysctl_cov_op(&op->u.coverage_op);
         copyback = 1;
         break;
 #endif
xen/include/public/sysctl.h +6 -6
index 6140f1a059..3566f2eb69 100644
@@ -646,11 +646,11 @@ struct xen_sysctl_scheduler_op {
 
 #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 */
+#define XEN_SYSCTL_COVERAGE_get_size 0 /* Get total size of output data */
+#define XEN_SYSCTL_COVERAGE_read     1 /* Read output data */
+#define XEN_SYSCTL_COVERAGE_reset    2 /* Reset all counters */
 
-struct xen_sysctl_gcov_op {
+struct xen_sysctl_coverage_op {
     uint32_t cmd;
     uint32_t size; /* IN/OUT: size of the buffer  */
     XEN_GUEST_HANDLE_64(char) buffer; /* OUT */
@@ -1065,7 +1065,7 @@ struct xen_sysctl {
 #define XEN_SYSCTL_numainfo                      17
 #define XEN_SYSCTL_cpupool_op                    18
 #define XEN_SYSCTL_scheduler_op                  19
-#define XEN_SYSCTL_gcov_op                       20
+#define XEN_SYSCTL_coverage_op                   20
 #define XEN_SYSCTL_psr_cmt_op                    21
 #define XEN_SYSCTL_pcitopoinfo                   22
 #define XEN_SYSCTL_psr_cat_op                    23
@@ -1095,7 +1095,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_coverage_op       coverage_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/coverage.h +1 -1
index b34c304cba..daddef37d3 100644
@@ -3,7 +3,7 @@
 
 #ifdef CONFIG_GCOV
 #include <public/sysctl.h>
-int sysctl_gcov_op(struct xen_sysctl_gcov_op *op);
+int sysctl_cov_op(struct xen_sysctl_coverage_op *op);
 #endif
 
 #endif	/* _XEN_GCOV_H */
Signature · 7 lines
2.13.6 (Apple Git-96)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v2 3/9
#7 lore raw

Re: [PATCH v2 for-next 3/9] gcov: rename sysctl and functions

Quoted 11 lines · Roger Pau Monne

Change gcov to cov (for internal interfaces) or coverage (for the public ones).

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#8 lore raw

Re: [PATCH v2 for-next 3/9] gcov: rename sysctl and functions

In reply to Roger Pau Monne
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 09.11.17 at 12:13, <[email protected]> wrote:

Change gcov to cov (for internal interfaces) or coverage (for the public ones).

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
---
Changes since v1:
- Use coverage instead of cov in the public interface.

Quoted 2 lines
---
 tools/misc/xencov.c         | 28 ++++++++++++++--------------

Btw., I still have this (and subsequent patches in the series) on my list of things wanting to be committed, but this needs a tools maintainer's ack before it can go in.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by
#9 lore raw

Re: [PATCH v2 for-next 3/9] gcov: rename sysctl and functions

Jan Beulich writes ("Re: [Xen-devel] [PATCH v2 for-next 3/9] gcov: rename sysctl and functions"):

Quoted 3 lines · On 09.11.17 at 12:13, <[email protected]> wrote:
Quoted 2 lines

Change gcov to cov (for internal interfaces) or coverage (for the public ones).

...

Quoted 3 lines

Btw., I still have this (and subsequent patches in the series) on my list of things wanting to be committed, but this needs a tools maintainer's ack before it can go in.

Thanks for the implied ping.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#10 lore raw

PATCH v2 4/9 gcov: introduce hooks for the sysctl

In reply to Roger Pau Monne

So that other implementations of the sysctl can be added.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Constify cov_ops.
- Introduce a local coverage.h provate header and place the definition of cov_sysctl_ops there.

---
 xen/common/coverage/coverage.h | 12 ++++++++++++
 xen/common/coverage/gcov.c     | 13 ++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)
 create mode 100644 xen/common/coverage/coverage.h
xen/common/coverage/coverage.h new file +12 -0
new file mode 100644
index 0000000000..4613d5e6c1
@@ -0,0 +1,12 @@
+#ifndef _XEN_COV_PRIV_H
+#define _XEN_COV_PRIV_H
+
+#include <xen/types.h>
+
+struct cov_sysctl_ops {
+    uint32_t (*get_size)(void);
+    void     (*reset_counters)(void);
+    int      (*dump)(XEN_GUEST_HANDLE_PARAM(char), uint32_t *);
+};
+
+#endif
xen/common/coverage/gcov.c +10 -3
index 798032cbbb..8627ef3355 100644
@@ -22,6 +22,7 @@
 
 #include <public/sysctl.h>
 
+#include "coverage.h"
 #include "gcov.h"
 
 /**
@@ -209,6 +210,12 @@ static int gcov_dump_all(XEN_GUEST_HANDLE_PARAM(char) buffer,
     return ret;
 }
 
+static const struct cov_sysctl_ops cov_ops = {
+    .get_size = gcov_get_size,
+    .reset_counters = gcov_reset_all_counters,
+    .dump = gcov_dump_all,
+};
+
 int sysctl_cov_op(struct xen_sysctl_coverage_op *op)
 {
     int ret;
@@ -216,7 +223,7 @@ int sysctl_cov_op(struct xen_sysctl_coverage_op *op)
     switch ( op->cmd )
     {
     case XEN_SYSCTL_COVERAGE_get_size:
-        op->size = gcov_get_size();
+        op->size = cov_ops.get_size();
         ret = 0;
         break;
 
@@ -227,14 +234,14 @@ int sysctl_cov_op(struct xen_sysctl_coverage_op *op)
 
         buf = guest_handle_cast(op->buffer, char);
 
-        ret = gcov_dump_all(buf, &size);
+        ret = cov_ops.dump(buf, &size);
         op->size = size;
 
         break;
     }
 
     case XEN_SYSCTL_COVERAGE_reset:
-        gcov_reset_all_counters();
+        cov_ops.reset_counters();
         ret = 0;
         break;
 
Signature · 7 lines
2.13.6 (Apple Git-96)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#11 lore raw

Re: [PATCH v2 for-next 4/9] gcov: introduce hooks for the sysctl

Quoted 31 lines · Roger Pau Monne

So that other implementations of the sysctl can be added.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Constify cov_ops.
- Introduce a local coverage.h provate header and place the definition of cov_sysctl_ops there.

---
 xen/common/coverage/coverage.h | 12 ++++++++++++
 xen/common/coverage/gcov.c     | 13 ++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)
 create mode 100644 xen/common/coverage/coverage.h
xen/common/coverage/coverage.h new file +2 -0
new file mode 100644
index 0000000000..4613d5e6c1
@@ -0,0 +1,12 @@
+#ifndef _XEN_COV_PRIV_H
+#define _XEN_COV_PRIV_H

xen/common/coverage/coverage.h line 12

Quoted 10 lines
xen/common/coverage/coverage.h new file +10 -0
+
+#include <xen/types.h>
+
+struct cov_sysctl_ops {
+    uint32_t (*get_size)(void);
+    void     (*reset_counters)(void);
+    int      (*dump)(XEN_GUEST_HANDLE_PARAM(char), uint32_t *);
+};
+
+#endif

Perhaps add the editor configuration block?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Acked-by on v2 4/9
#12 lore raw

Re: [PATCH v2 for-next 4/9] gcov: introduce hooks for the sysctl

In reply to Roger Pau Monne
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 09.11.17 at 12:13, <[email protected]> wrote:

So that other implementations of the sysctl can be added.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#13 lore raw

PATCH v2 5/9 coverage: introduce generic file

In reply to Roger Pau Monne

It will contain the generic implementation of sysctl_cov_op, which will be shared between all the coverage implementations.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Use private coverage.h header.
- Sort alphabetically the obj-y list.

---
 xen/common/coverage/Makefile   |  2 +-
 xen/common/coverage/coverage.c | 73 ++++++++++++++++++++++++++++++++++++++++++
 xen/common/coverage/coverage.h |  1 +
 xen/common/coverage/gcov.c     | 39 +---------------------
 4 files changed, 76 insertions(+), 39 deletions(-)
 create mode 100644 xen/common/coverage/coverage.c
xen/common/coverage/Makefile +1 -1
index a7a48494ca..5387bc6429 100644
@@ -1,4 +1,4 @@
-obj-y += gcov_base.o gcov.o
+obj-y += coverage.o gcov_base.o gcov.o
 obj-y += $(call cc-ifversion,lt,0x040700, \
 		gcc_3_4.o, $(call cc-ifversion,lt,0x040900, \
 		gcc_4_7.o, $(call cc-ifversion,lt,0x050000, \
xen/common/coverage/coverage.c new file +73 -0

73 lines not on this page · raw message

xen/common/coverage/coverage.h +1 -0
index 4613d5e6c1..003bb76950 100644
@@ -8,5 +8,6 @@ struct cov_sysctl_ops {
     void     (*reset_counters)(void);
     int      (*dump)(XEN_GUEST_HANDLE_PARAM(char), uint32_t *);
 };
+extern const struct cov_sysctl_ops cov_ops;
 
 #endif
xen/common/coverage/gcov.c +1 -38
index 8627ef3355..3cc98728bf 100644
@@ -210,49 +210,12 @@ static int gcov_dump_all(XEN_GUEST_HANDLE_PARAM(char) buffer,
     return ret;
 }
 
-static const struct cov_sysctl_ops cov_ops = {
+const struct cov_sysctl_ops cov_ops = {
     .get_size = gcov_get_size,
     .reset_counters = gcov_reset_all_counters,
     .dump = gcov_dump_all,
 };
 
-int sysctl_cov_op(struct xen_sysctl_coverage_op *op)
-{
-    int ret;
-
-    switch ( op->cmd )
-    {
-    case XEN_SYSCTL_COVERAGE_get_size:
-        op->size = cov_ops.get_size();
-        ret = 0;
-        break;
-
-    case XEN_SYSCTL_COVERAGE_read:
-    {
-        XEN_GUEST_HANDLE_PARAM(char) buf;
-        uint32_t size = op->size;
-
-        buf = guest_handle_cast(op->buffer, char);
-
-        ret = cov_ops.dump(buf, &size);
-        op->size = size;
-
-        break;
-    }
-
-    case XEN_SYSCTL_COVERAGE_reset:
-        cov_ops.reset_counters();
-        ret = 0;
-        break;
-
-    default:
-        ret = -EOPNOTSUPP;
-        break;
-    }
-
-    return ret;
-}
-
 /*
  * Local variables:
  * mode: C
Signature · 7 lines
2.13.6 (Apple Git-96)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v2 5/9
#14 lore raw

Re: [PATCH v2 for-next 5/9] coverage: introduce generic file

Quoted 10 lines · Roger Pau Monne

It will contain the generic implementation of sysctl_cov_op, which will be shared between all the coverage implementations.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>

Quoted 178 lines
Cc Stefano Stabellini <[email protected]>
Cc Tim Deegan <[email protected]>
Cc Wei Liu <[email protected]>

---
Changes since v1:
- Use private coverage.h header.
- Sort alphabetically the obj-y list.

---
 xen/common/coverage/Makefile   |  2 +-
 xen/common/coverage/coverage.c | 73 ++++++++++++++++++++++++++++++++++++++++++
 xen/common/coverage/coverage.h |  1 +
 xen/common/coverage/gcov.c     | 39 +---------------------
 4 files changed, 76 insertions(+), 39 deletions(-)
 create mode 100644 xen/common/coverage/coverage.c
xen/common/coverage/Makefile +1 -1
index a7a48494ca..5387bc6429 100644
@@ -1,4 +1,4 @@
-obj-y += gcov_base.o gcov.o
+obj-y += coverage.o gcov_base.o gcov.o
 obj-y += $(call cc-ifversion,lt,0x040700, \
 		gcc_3_4.o, $(call cc-ifversion,lt,0x040900, \
 		gcc_4_7.o, $(call cc-ifversion,lt,0x050000, \
xen/common/coverage/coverage.c new file +73 -0
new file mode 100644
index 0000000000..bd90f28663
@@ -0,0 +1,73 @@
+/*
+ * Generic functionality for coverage analysis.
+ *
+ * Copyright (C) 2017 Citrix Systems R&D
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms and conditions of the GNU General Public
+ * License, version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/errno.h>
+#include <xen/guest_access.h>
+#include <xen/types.h>
+#include <xen/coverage.h>
+
+#include <public/sysctl.h>
+
+#include "coverage.h"
+
+int sysctl_cov_op(struct xen_sysctl_coverage_op *op)
+{
+    int ret;
+
+    switch ( op->cmd )
+    {
+    case XEN_SYSCTL_COVERAGE_get_size:
+        op->size = cov_ops.get_size();
+        ret = 0;
+        break;
+
+    case XEN_SYSCTL_COVERAGE_read:
+    {
+        XEN_GUEST_HANDLE_PARAM(char) buf;
+        uint32_t size = op->size;
+
+        buf = guest_handle_cast(op->buffer, char);
+
+        ret = cov_ops.dump(buf, &size);
+        op->size = size;
+
+        break;
+    }
+
+    case XEN_SYSCTL_COVERAGE_reset:
+        cov_ops.reset_counters();
+        ret = 0;
+        break;
+
+    default:
+        ret = -EOPNOTSUPP;
+        break;
+    }
+
+    return ret;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/common/coverage/coverage.h +1 -0
index 4613d5e6c1..003bb76950 100644
@@ -8,5 +8,6 @@ struct cov_sysctl_ops {
     void     (*reset_counters)(void);
     int      (*dump)(XEN_GUEST_HANDLE_PARAM(char), uint32_t *);
 };
+extern const struct cov_sysctl_ops cov_ops;
 
 #endif
xen/common/coverage/gcov.c +1 -38
index 8627ef3355..3cc98728bf 100644
@@ -210,49 +210,12 @@ static int gcov_dump_all(XEN_GUEST_HANDLE_PARAM(char) buffer,
     return ret;
 }
 
-static const struct cov_sysctl_ops cov_ops = {
+const struct cov_sysctl_ops cov_ops = {
     .get_size = gcov_get_size,
     .reset_counters = gcov_reset_all_counters,
     .dump = gcov_dump_all,
 };
 
-int sysctl_cov_op(struct xen_sysctl_coverage_op *op)
-{
-    int ret;
-
-    switch ( op->cmd )
-    {
-    case XEN_SYSCTL_COVERAGE_get_size:
-        op->size = cov_ops.get_size();
-        ret = 0;
-        break;
-
-    case XEN_SYSCTL_COVERAGE_read:
-    {
-        XEN_GUEST_HANDLE_PARAM(char) buf;
-        uint32_t size = op->size;
-
-        buf = guest_handle_cast(op->buffer, char);
-
-        ret = cov_ops.dump(buf, &size);
-        op->size = size;
-
-        break;
-    }
-
-    case XEN_SYSCTL_COVERAGE_reset:
-        cov_ops.reset_counters();
-        ret = 0;
-        break;
-
-    default:
-        ret = -EOPNOTSUPP;
-        break;
-    }
-
-    return ret;
-}
-
 /*
  * Local variables:
  * mode: C
Signature · 7 lines
2.13.6 (Apple Git-96)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#15 lore raw

PATCH v2 6/9 kconfig/gcov: rename to coverage

In reply to Roger Pau Monne

So it can be used by both gcc and clang. Just add the Kconfig option and modify the makefiles so the llvm coverage specific code can be added in a follow up patch.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Use a choice in kconfig to select code coverage technology.
- Compile coverage.c regardless of selected code coverage technology.
- Introduce an unimplemented sysctl_cov_op function if CONFIG_COVERAGE is not set.

---
 docs/misc/coverage.markdown  | 2 +-
 xen/Kconfig.debug            | 7 +++----
 xen/Rules.mk                 | 6 +++++-
 xen/common/Makefile          | 2 +-
 xen/common/coverage/Makefile | 5 ++++-
 xen/common/sysctl.c          | 2 --
 xen/include/xen/coverage.h   | 7 ++++++-
 7 files changed, 20 insertions(+), 11 deletions(-)
docs/misc/coverage.markdown +1 -1
index b47aba2648..430cd27b2f 100644
@@ -10,7 +10,7 @@ down your hypervisor.
 
 ## Enable coverage
 
-Test coverage support can be turned on compiling Xen with the `CONFIG_GCOV`
+Test coverage support can be turned on compiling Xen with the `CONFIG_COVERAGE`
 option set to `y`.
 
 Change your `.config` or run `make -C xen menuconfig`.
xen/Kconfig.debug +3 -4
index 7bb0465b5d..153d68fed3 100644
@@ -28,12 +28,11 @@ config FRAME_POINTER
 	  maybe slower, but it gives very useful debugging information
 	  in case of any Xen bugs.
 
-config GCOV
-	bool "Gcov Support"
+config COVERAGE
+	bool "Code coverage support"
 	depends on !LIVEPATCH
-	select SUPPRESS_DUPLICATE_SYMBOL_WARNINGS
 	---help---
-	  Enable gcov (a test coverage program in GCC) support.
+	  Enable code coverage support.
 
 	  If unsure, say N here.
 
xen/Rules.mk +5 -1
index 2659f8a4d1..d1b72e24ab 100644
@@ -115,9 +115,13 @@ subdir-all := $(subdir-y) $(subdir-n)
 
 $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -DINIT_SECTIONS_ONLY
 
-ifeq ($(CONFIG_GCOV),y)
+ifeq ($(CONFIG_COVERAGE),y)
+ifeq ($(clang),y)
+$(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-instr-generate -fcoverage-mapping
+else
 $(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-arcs -ftest-coverage
 endif
+endif
 
 ifeq ($(CONFIG_UBSAN),y)
 $(filter-out %.init.o $(noubsan-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fsanitize=undefined
xen/common/Makefile +1 -1
index ad181636f6..3a349f478b 100644
@@ -74,7 +74,7 @@ tmem-y := tmem.o tmem_xen.o tmem_control.o
 tmem-$(CONFIG_COMPAT) += compat/tmem_xen.o
 obj-$(CONFIG_TMEM) += $(tmem-y)
 
-subdir-$(CONFIG_GCOV) += coverage
+subdir-$(CONFIG_COVERAGE) += coverage
 subdir-$(CONFIG_UBSAN) += ubsan
 
 subdir-y += libelf
xen/common/coverage/Makefile +4 -1
index 5387bc6429..1039a160c4 100644
@@ -1,6 +1,9 @@
-obj-y += coverage.o gcov_base.o gcov.o
+obj-y += coverage.o
+ifneq ($(clang),y)
+obj-y += gcov_base.o gcov.o
 obj-y += $(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, $(call cc-ifversion,lt,0x070000, \
 		gcc_5.o, gcc_7.o))))
+endif
xen/common/sysctl.c +0 -2
index f2ae6295ff..8e83c33a16 100644
@@ -396,12 +396,10 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
     }
     break;
 
-#ifdef CONFIG_GCOV
     case XEN_SYSCTL_coverage_op:
         ret = sysctl_cov_op(&op->u.coverage_op);
         copyback = 1;
         break;
-#endif
 
 #ifdef CONFIG_HAS_PCI
     case XEN_SYSCTL_pcitopoinfo:
xen/include/xen/coverage.h +6 -1
index daddef37d3..098f116760 100644
@@ -1,9 +1,14 @@
 #ifndef _XEN_COV_H
 #define _XEN_COV_H
 
-#ifdef CONFIG_GCOV
+#ifdef CONFIG_COVERAGE
 #include <public/sysctl.h>
 int sysctl_cov_op(struct xen_sysctl_coverage_op *op);
+#else
+static inline int sysctl_cov_op(void *unused)
+{
+    return -ENOSYS;
+}
 #endif
 
 #endif	/* _XEN_GCOV_H */
Signature · 7 lines
2.13.6 (Apple Git-96)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#16 lore raw

Re: [PATCH v2 for-next 6/9] kconfig/gcov: rename to coverage

Quoted 48 lines · Roger Pau Monne

So it can be used by both gcc and clang. Just add the Kconfig option and modify the makefiles so the llvm coverage specific code can be added in a follow up patch.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Use a choice in kconfig to select code coverage technology.
- Compile coverage.c regardless of selected code coverage technology.
- Introduce an unimplemented sysctl_cov_op function if CONFIG_COVERAGE is not set.

---
 docs/misc/coverage.markdown  | 2 +-
 xen/Kconfig.debug            | 7 +++----
 xen/Rules.mk                 | 6 +++++-
 xen/common/Makefile          | 2 +-
 xen/common/coverage/Makefile | 5 ++++-
 xen/common/sysctl.c          | 2 --
 xen/include/xen/coverage.h   | 7 ++++++-
 7 files changed, 20 insertions(+), 11 deletions(-)
docs/misc/coverage.markdown +1 -1
index b47aba2648..430cd27b2f 100644
@@ -10,7 +10,7 @@ down your hypervisor.
 
 ## Enable coverage
 
-Test coverage support can be turned on compiling Xen with the `CONFIG_GCOV`
+Test coverage support can be turned on compiling Xen with the `CONFIG_COVERAGE`
 option set to `y`.
 
 Change your `.config` or run `make -C xen menuconfig`.
xen/Kconfig.debug +0 -0
index 7bb0465b5d..153d68fed3 100644

xen/Kconfig.debug config FRAME_POINTER · line 34

Quoted 9 lines
xen/Kconfig.debug +2 -3
@@ -28,12 +28,11 @@ config FRAME_POINTER
 	  maybe slower, but it gives very useful debugging information
 	  in case of any Xen bugs.
 
-config GCOV
-	bool "Gcov Support"
+config COVERAGE
+	bool "Code coverage support"
 	depends on !LIVEPATCH
-	select SUPPRESS_DUPLICATE_SYMBOL_WARNINGS

Any particular reason this was removed?

Or is the idea that the coverage technology should have this select?

Quoted 76 lines
xen/Kconfig.debug +1 -1
 	---help---
-	  Enable gcov (a test coverage program in GCC) support.
+	  Enable code coverage support.
 
 	  If unsure, say N here.
 
xen/Rules.mk +5 -1
index 2659f8a4d1..d1b72e24ab 100644
@@ -115,9 +115,13 @@ subdir-all := $(subdir-y) $(subdir-n)
 
 $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -DINIT_SECTIONS_ONLY
 
-ifeq ($(CONFIG_GCOV),y)
+ifeq ($(CONFIG_COVERAGE),y)
+ifeq ($(clang),y)
+$(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-instr-generate -fcoverage-mapping
+else
 $(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-arcs -ftest-coverage
 endif
+endif
 
 ifeq ($(CONFIG_UBSAN),y)
 $(filter-out %.init.o $(noubsan-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fsanitize=undefined
xen/common/Makefile +1 -1
index ad181636f6..3a349f478b 100644
@@ -74,7 +74,7 @@ tmem-y := tmem.o tmem_xen.o tmem_control.o
 tmem-$(CONFIG_COMPAT) += compat/tmem_xen.o
 obj-$(CONFIG_TMEM) += $(tmem-y)
 
-subdir-$(CONFIG_GCOV) += coverage
+subdir-$(CONFIG_COVERAGE) += coverage
 subdir-$(CONFIG_UBSAN) += ubsan
 
 subdir-y += libelf
xen/common/coverage/Makefile +4 -1
index 5387bc6429..1039a160c4 100644
@@ -1,6 +1,9 @@
-obj-y += coverage.o gcov_base.o gcov.o
+obj-y += coverage.o
+ifneq ($(clang),y)
+obj-y += gcov_base.o gcov.o
 obj-y += $(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, $(call cc-ifversion,lt,0x070000, \
 		gcc_5.o, gcc_7.o))))
+endif
xen/common/sysctl.c +0 -2
index f2ae6295ff..8e83c33a16 100644
@@ -396,12 +396,10 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
     }
     break;
 
-#ifdef CONFIG_GCOV
     case XEN_SYSCTL_coverage_op:
         ret = sysctl_cov_op(&op->u.coverage_op);
         copyback = 1;
         break;
-#endif
 
 #ifdef CONFIG_HAS_PCI
     case XEN_SYSCTL_pcitopoinfo:
xen/include/xen/coverage.h +0 -0
index daddef37d3..098f116760 100644
@@ -1,9 +1,14 @@
 #ifndef _XEN_COV_H

xen/include/xen/coverage.h line 10

Quoted 10 lines
xen/include/xen/coverage.h +5 -1
 #define _XEN_COV_H
 
-#ifdef CONFIG_GCOV
+#ifdef CONFIG_COVERAGE
 #include <public/sysctl.h>
 int sysctl_cov_op(struct xen_sysctl_coverage_op *op);
+#else
+static inline int sysctl_cov_op(void *unused)
+{
+    return -ENOSYS;

Not -EOPNOTSUPP ?

Quoted 7 lines
xen/include/xen/coverage.h +1 -0
+}
 #endif
 
 #endif	/* _XEN_GCOV_H */
Signature · 1 line
2.13.6 (Apple Git-96)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#17 lore raw

Re: [PATCH v2 for-next 6/9] kconfig/gcov: rename to coverage

Quoted 18 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · Roger Pau Monne
xen/Kconfig.debug +0 -0
index 7bb0465b5d..153d68fed3 100644

xen/Kconfig.debug config FRAME_POINTER · line 34

Quoted 9 lines
xen/Kconfig.debug +2 -3
@@ -28,12 +28,11 @@ config FRAME_POINTER
 	  maybe slower, but it gives very useful debugging information
 	  in case of any Xen bugs.
 
-config GCOV
-	bool "Gcov Support"
+config COVERAGE
+	bool "Code coverage support"
 	depends on !LIVEPATCH
-	select SUPPRESS_DUPLICATE_SYMBOL_WARNINGS

Any particular reason this was removed?

Quoted 1 line

Or is the idea that the coverage technology should have this select?

That's my fault, I will add the select back.

Quoted 8 lines
Quoted 8 lines
xen/include/xen/coverage.h +0 -0
index daddef37d3..098f116760 100644
@@ -1,9 +1,14 @@
 #ifndef _XEN_COV_H
 #define _XEN_COV_H
 
Quoted 10 lines

xen/include/xen/coverage.h line 10

Quoted 8 lines
xen/include/xen/coverage.h +5 -1
-#ifdef CONFIG_GCOV
+#ifdef CONFIG_COVERAGE
 #include <public/sysctl.h>
 int sysctl_cov_op(struct xen_sysctl_coverage_op *op);
+#else
+static inline int sysctl_cov_op(void *unused)
+{
+    return -ENOSYS;

Not -EOPNOTSUPP ?

IIRC for non implemented top-level hypercalls Xen returns ENOSYS instead of EOPNOTSUPP, but I might be wrong.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#18 lore raw

Re: [PATCH v2 for-next 6/9] kconfig/gcov: rename to coverage

Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 27.11.17 at 12:27, <[email protected]> wrote:
Quoted 7 lines · Konrad Rzeszutek Wilk
Quoted 6 lines · Roger Pau Monne
xen/include/xen/coverage.h +0 -0
@@ -1,9 +1,14 @@
 #ifndef _XEN_COV_H
 #define _XEN_COV_H
 
Quoted 10 lines

xen/include/xen/coverage.h line 10

Quoted 8 lines
xen/include/xen/coverage.h +5 -1
-#ifdef CONFIG_GCOV
+#ifdef CONFIG_COVERAGE
 #include <public/sysctl.h>
 int sysctl_cov_op(struct xen_sysctl_coverage_op *op);
+#else
+static inline int sysctl_cov_op(void *unused)
+{
+    return -ENOSYS;

Not -EOPNOTSUPP ?

Quoted 2 lines

IIRC for non implemented top-level hypercalls Xen returns ENOSYS instead of EOPNOTSUPP, but I might be wrong.

But this is an individual sysctl, not HYPERVISOR_sysctl.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#19 lore raw

Re: [PATCH v2 for-next 6/9] kconfig/gcov: rename to coverage

In reply to Roger Pau Monne
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 09.11.17 at 12:13, <[email protected]> wrote:

xen/Rules.mk subdir-all := $(subdir-y) $(subdir-n) · line 122

Quoted 10 lines
xen/Rules.mk +4 -2
@@ -115,9 +115,13 @@ subdir-all := $(subdir-y) $(subdir-n)
 
 $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += 
-DINIT_SECTIONS_ONLY
 
-ifeq ($(CONFIG_GCOV),y)
+ifeq ($(CONFIG_COVERAGE),y)
+ifeq ($(clang),y)
+$(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-instr-generate -fcoverage-mapping
+else
 $(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-arcs -ftest-coverage

Could you please eliminate the redundancy here? Use a helper variable to hold the options to add, and then have just a single line with the $(filter-out ...):.

xen/common/coverage/Makefile line 9

Quoted 13 lines
xen/common/coverage/Makefile +4 -1
@@ -1,6 +1,9 @@
-obj-y += coverage.o gcov_base.o gcov.o
+obj-y += coverage.o
+ifneq ($(clang),y)
+obj-y += gcov_base.o gcov.o
 obj-y += $(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, $(call cc-ifversion,lt,0x070000, \
 		gcc_5.o, gcc_7.o))))
+endif

I guess the build with clang is broken before and after this patch when the Kconfig option is enabled, in which case the ordering within the series doesn't matter. Otherwise I would have said that this patch should come after the one adding the LLVM files.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#20 lore raw

PATCH v2 7/9 coverage: introduce support for llvm profiling

In reply to Roger Pau Monne

Introduce the functionality in order to fill the hooks of the cov_sysctl_ops struct. Note that the functionality is still not wired into the build system.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Note that the file that contains the helpers is under a BSD 2-clause license. This is done so it can be shared with other OSes that use the llvm/clang compiler.
---
Changes since v1:
- Include private coverage.h header.
- Define LLVM_PROFILE_MAGIC based on the bitness of the arch.
- Add a comment regarding __llvm_profile_runtime.
- Constify data/names extern symbols.
- Use defines instead of variables to store the addresses of the external symbols.
- Parenthesize size in APPEND_TO_BUFFER.
- Use >= for minor version check.
- Use sizeof(header).

---
 xen/common/coverage/Makefile |   2 +
 xen/common/coverage/llvm.c   | 154 +++++++++++++++++++++++++++++++++++++++++++
 xen/include/public/sysctl.h  |   6 ++
 3 files changed, 162 insertions(+)
 create mode 100644 xen/common/coverage/llvm.c
xen/common/coverage/Makefile +2 -0
index 1039a160c4..46c78d1086 100644
@@ -6,4 +6,6 @@ obj-y += $(call cc-ifversion,lt,0x040700, \
 		gcc_4_7.o, $(call cc-ifversion,lt,0x050000, \
 		gcc_4_9.o, $(call cc-ifversion,lt,0x070000, \
 		gcc_5.o, gcc_7.o))))
+else
+obj-y += llvm.o
 endif
xen/common/coverage/llvm.c new file +154 -0

154 lines not on this page · raw message

xen/include/public/sysctl.h +6 -0
index 3566f2eb69..8db22ac803 100644
@@ -646,6 +646,12 @@ struct xen_sysctl_scheduler_op {
 
 #define XEN_GCOV_FORMAT_MAGIC    0x58434f56 /* XCOV */
 
+/*
+ * Ouput format of LLVM coverage data is just a raw stream, as would be
+ * written by the compiler_rt run time library into a .profraw file. There
+ * are no special Xen tags or delimiters because none are needed.
+ */
+
 #define XEN_SYSCTL_COVERAGE_get_size 0 /* Get total size of output data */
 #define XEN_SYSCTL_COVERAGE_read     1 /* Read output data */
 #define XEN_SYSCTL_COVERAGE_reset    2 /* Reset all counters */
Signature · 7 lines
2.13.6 (Apple Git-96)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v2 7/9
#21 lore raw

Re: [PATCH v2 for-next 7/9] coverage: introduce support for llvm profiling

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 09.11.17 at 12:13, <[email protected]> wrote:

Introduce the functionality in order to fill the hooks of the cov_sysctl_ops struct. Note that the functionality is still not wired into the build system.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#22 lore raw

PATCH v2 8/9 xsm: add bodge when compiling with llvm coverage support

In reply to Roger Pau Monne

llvm coverage support seems to disable some of the optimizations needed in order to compile xsm, and the end result is that references to __xsm_action_mismatch_detected are left in the object files.

Since coverage support cannot be used in production, introduce __xsm_action_mismatch_detected for llvm coverage builds.

---
Cc: Daniel De Graaf <[email protected]>
---
Changes since v1:
- Add inline.
- Use CONIFG_COVERAGE and __clang__ to detect if the bodge is needed.

---
 xen/include/xsm/dummy.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
xen/include/xsm/dummy.h +14 -0
index b2cd56cdc5..2c39ae2e6b 100644
@@ -24,8 +24,22 @@
  * if references remain at link time.
  */
 #define LINKER_BUG_ON(x) do { if (x) __xsm_action_mismatch_detected(); } while (0)
+
+#if defined(CONFIG_COVERAGE) && defined(__clang__)
+/*
+ * LLVM coverage support seems to disable some of the optimizations needed in
+ * order for XSM to compile. Since coverage should not be used in production
+ * provide an implementation of __xsm_action_mismatch_detected to satisfy the
+ * linker.
+ */
+static inline void __xsm_action_mismatch_detected(void)
+{
+    ASSERT_UNREACHABLE();
+}
+#else
 /* DO NOT implement this function; it is supposed to trigger link errors */
 void __xsm_action_mismatch_detected(void);
+#endif
 
 #ifdef CONFIG_XSM
 
Signature · 7 lines
2.13.6 (Apple Git-96)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#23 lore raw

PATCH v2 9/9 coverage: add documentation for LLVM coverage

In reply to Roger Pau Monne

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- s/gmake/make/.
- Fix gcov section to mention CONFIG_COVERAGE instead of CONFIG_GCOV.

---
 docs/misc/coverage.markdown | 47 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
docs/misc/coverage.markdown +47 -0
index 430cd27b2f..3554659fe4 100644
@@ -8,6 +8,8 @@ information. Every basic block in the code will be instrumented by the compiler
 to compute these statistics. It should not be used in production as it slows
 down your hypervisor.
 
+# GCOV (GCC coverage)
+
 ## Enable coverage
 
 Test coverage support can be turned on compiling Xen with the `CONFIG_COVERAGE`
@@ -75,3 +77,48 @@ blob extracted from xencov!**
 * See output in a browser
 
         firefox cov/index.html
+
+# LLVM coverage
+
+## Enable coverage
+
+Coverage can be enabled using a Kconfig option, from the top-level directory
+use the following command to display the Kconfig menu:
+
+    make -C xen menuconfig clang=y
+
+The code coverage option can be found inside of the "Debugging Options"
+section. After enabling it just compile Xen as you would normally do:
+
+    make xen clang=y
+
+## Extract coverage data
+
+LLVM coverage can be extracted from the hypervisor using the `xencov` tool.
+The following actions are available:
+
+* `xencov read` extract data
+* `xencov reset` reset all coverage counters
+* `xencov read-reset` extract data and reset counters at the same time.
+
+## Possible use
+
+**This section is just an example on how to use these tools!**
+
+This example assumes you compiled Xen and copied the xen-syms file from
+xen/xen-syms into your current directory.
+
+* Extract the coverage data from Xen:
+
+    xencov read xen.profraw
+
+* Convert the data into a profile. Note that you can merge more than one
+  profraw file into a single profdata file.
+
+    llvm-profdata merge xen.profraw -o xen.profdata
+
+* Generate a HTML report of the code coverage:
+
+    llvm-cov show -format=html -output-dir=cov/ xen-syms -instr-profile=xen.profdata
+
+* Open cov/index.html with your browser in order to display the profile.
Signature · 7 lines
2.13.6 (Apple Git-96)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel