Skip to contentSkip to conversation

gcov: return ENOSYS for unimplemented gcov domctl

PATCH In review Roger Pau Monne 8 participants 43 messages Oct 26, 2017 – Nov 9, 2017 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/9 gcov: return ENOSYS for unimplemented gcov domctl

---
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]>

---
 xen/common/gcov/gcov.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/gcov/gcov.c +1 -1
index 2f18f6d176..35653fd8d8 100644
@@ -239,7 +239,7 @@ int sysctl_gcov_op(struct xen_sysctl_gcov_op *op)
         break;
 
     default:
-        ret = -EINVAL;
+        ret = -ENOSYS;
         break;
     }
 
Signature · 7 lines
2.13.5 (Apple Git-94)


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

Roger Pau Monne writes ("[PATCH for-next 1/9] gcov: return ENOSYS for unimplemented gcov domctl"):

Quoted 1 line

...

xen/common/gcov/gcov.c int sysctl_gcov_op(struct xen_sysctl_gcov_op *op) · line 244

Quoted 5 lines

default:

xen/common/gcov/gcov.c +1 -1
-        ret = -EINVAL;
+        ret = -ENOSYS;
         break;
     }

I think this is a bugfix which should go into 4.10. Julien ? (Subject line changed by me.)

Ian.

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

#3 lore raw

Hi,

Quoted 9 lines · Ian Jackson

Roger Pau Monne writes ("[PATCH for-next 1/9] gcov: return ENOSYS for unimplemented gcov domctl"):

Quoted 1 line

...

xen/common/gcov/gcov.c int sysctl_gcov_op(struct xen_sysctl_gcov_op *op) · line 244

Quoted 5 lines

default:

xen/common/gcov/gcov.c +1 -1
-        ret = -EINVAL;
+        ret = -ENOSYS;
          break;
      }
Quoted 4 lines

I think this is a bugfix which should go into 4.10. Julien ? (Subject line changed by me.)

Yes I agree.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#4 lore raw
In reply to Roger Pau Monne

xen/common/gcov/gcov.c int sysctl_gcov_op(struct xen_sysctl_gcov_op *op) · line 244

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 26.10.17 at 11:19, <[email protected]> wrote:
xen/common/gcov/gcov.c +1 -1
@@ -239,7 +239,7 @@ int sysctl_gcov_op(struct xen_sysctl_gcov_op *op)
         break;
 
     default:
-        ret = -EINVAL;
+        ret = -ENOSYS;
         break;
     }

Very certainly ENOSYS is not in any way better. Despite the many misuses of it, we've started enforcing that this wouldn't be spread. -EOPNOTSUPP may be fine here, but -EINVAL is suitable as well. -ENOSYS exclusively means that a _top level_ hypercall is unimplemented (i.e. with very few exceptions there should be exactly one place where it gets returned, which is in the main hypercall dispatch code).

Jan

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

#5 lore raw

Jan Beulich writes ("Re: [PATCH for-next 1/9] gcov: return ENOSYS for unimplemented gcov domctl"):

Quoted 16 lines · On 26.10.17 at 11:19, <[email protected]> wrote:

xen/common/gcov/gcov.c int sysctl_gcov_op(struct xen_sysctl_gcov_op *op) · line 244

Quoted 10 lines
xen/common/gcov/gcov.c +1 -1
@@ -239,7 +239,7 @@ int sysctl_gcov_op(struct xen_sysctl_gcov_op *op)
         break;
 
     default:
-        ret = -EINVAL;
+        ret = -ENOSYS;
         break;
     }

Very certainly ENOSYS is not in any way better. Despite the many misuses of it, we've started enforcing that this wouldn't be spread.

(quoted diff) +0 -2
-EOPNOTSUPP may be fine here, but -EINVAL is suitable as well.
-ENOSYS exclusively means that a _top level_ hypercall is
Quoted 3 lines

unimplemented (i.e. with very few exceptions there should be exactly one place where it gets returned, which is in the main hypercall dispatch code).

The distinction between unimplemented status of a top-level hypercall and unimplemented status of a sub-op is rarely useful to the caller.

Conversely, the distinction between an unimplemented facility, and a facility which is exists but is being used improperly, is vitally important to anyone who is trying to write compatibility code.

I don't mind if you want to insist on the former distinction, reserving ENOSYS for top-level hypercalls and EOPNOTSUPP for other functions.

But I absolutely do mind the use of EINVAL for "unsupported function". I appreciate that much of the hypervisor has historically used EINVAL this way, but this is (a) a pain for callers (b) evil, bad, and wrong
(c) unnecessary since EOPNOTSUPP is available. We should at least not perpetrate any more of this. In an unreleased API we should change it before release.

Thanks for your attention.

Ian.

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

#6 lore raw
Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 06.11.17 at 12:16, <[email protected]> wrote:

Jan Beulich writes ("Re: [PATCH for-next 1/9] gcov: return ENOSYS for unimplemented gcov domctl"):

Quoted 16 lines · On 26.10.17 at 11:19, <[email protected]> wrote:

xen/common/gcov/gcov.c int sysctl_gcov_op(struct xen_sysctl_gcov_op *op) · line 244

Quoted 10 lines
xen/common/gcov/gcov.c +1 -1
@@ -239,7 +239,7 @@ int sysctl_gcov_op(struct xen_sysctl_gcov_op *op)
         break;
 
     default:
-        ret = -EINVAL;
+        ret = -ENOSYS;
         break;
     }

Very certainly ENOSYS is not in any way better. Despite the many misuses of it, we've started enforcing that this wouldn't be spread.

(quoted diff) +0 -2
-EOPNOTSUPP may be fine here, but -EINVAL is suitable as well.
-ENOSYS exclusively means that a _top level_ hypercall is
Quoted 3 lines

unimplemented (i.e. with very few exceptions there should be exactly one place where it gets returned, which is in the main hypercall dispatch code).

The distinction between unimplemented status of a top-level hypercall and unimplemented status of a sub-op is rarely useful to the caller.

Conversely, the distinction between an unimplemented facility, and a facility which is exists but is being used improperly, is vitally important to anyone who is trying to write compatibility code.

I don't mind if you want to insist on the former distinction, reserving ENOSYS for top-level hypercalls and EOPNOTSUPP for other functions.

Quoted 6 lines

But I absolutely do mind the use of EINVAL for "unsupported function". I appreciate that much of the hypervisor has historically used EINVAL this way, but this is (a) a pain for callers (b) evil, bad, and wrong
(c) unnecessary since EOPNOTSUPP is available. We should at least not perpetrate any more of this. In an unreleased API we should change it before release.

Okay, so EOPNOTSUPP is it then, which is also my preference (due to there being so many uses of EINVAL elsewhere). I've merely mentioned that EINVAL would be suitable since, technically speaking, the value in a "sub-operation" field being invalid is no different from this being the case for the value in any other field.

Jan

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

#7 lore raw
Quoted 34 lines · Jan Beulich
Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 06.11.17 at 12:16, <[email protected]> wrote:

Jan Beulich writes ("Re: [PATCH for-next 1/9] gcov: return ENOSYS for unimplemented gcov domctl"):

Quoted 16 lines · On 26.10.17 at 11:19, <[email protected]> wrote:

xen/common/gcov/gcov.c int sysctl_gcov_op(struct xen_sysctl_gcov_op *op) · line 244

Quoted 10 lines
xen/common/gcov/gcov.c +1 -1
@@ -239,7 +239,7 @@ int sysctl_gcov_op(struct xen_sysctl_gcov_op *op)
         break;
 
     default:
-        ret = -EINVAL;
+        ret = -ENOSYS;
         break;
     }

Very certainly ENOSYS is not in any way better. Despite the many misuses of it, we've started enforcing that this wouldn't be spread.

(quoted diff) +0 -2
-EOPNOTSUPP may be fine here, but -EINVAL is suitable as well.
-ENOSYS exclusively means that a _top level_ hypercall is
Quoted 3 lines

unimplemented (i.e. with very few exceptions there should be exactly one place where it gets returned, which is in the main hypercall dispatch code).

The distinction between unimplemented status of a top-level hypercall and unimplemented status of a sub-op is rarely useful to the caller.

Conversely, the distinction between an unimplemented facility, and a facility which is exists but is being used improperly, is vitally important to anyone who is trying to write compatibility code.

I don't mind if you want to insist on the former distinction, reserving ENOSYS for top-level hypercalls and EOPNOTSUPP for other functions.

Quoted 6 lines
Quoted 6 lines

But I absolutely do mind the use of EINVAL for "unsupported function". I appreciate that much of the hypervisor has historically used EINVAL this way, but this is (a) a pain for callers (b) evil, bad, and wrong
(c) unnecessary since EOPNOTSUPP is available. We should at least not perpetrate any more of this. In an unreleased API we should change it before release.

This API has actually been released since ~2013 IIRC, when it was added to Xen.

Quoted 6 lines

Okay, so EOPNOTSUPP is it then, which is also my preference (due to there being so many uses of EINVAL elsewhere). I've merely mentioned that EINVAL would be suitable since, technically speaking, the value in a "sub-operation" field being invalid is no different from this being the case for the value in any other field.

If I don't get any more comments I will re-send this patch separately using EOPNOTSUPP instead of ENOSYS. I will also keep the Acks gathered so far unless anyone objects.

Thanks, Roger.

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

#8 lore raw
Quoted 11 lines · Roger Pau Monné
Quoted 6 lines

Okay, so EOPNOTSUPP is it then, which is also my preference (due to there being so many uses of EINVAL elsewhere). I've merely mentioned that EINVAL would be suitable since, technically speaking, the value in a "sub-operation" field being invalid is no different from this being the case for the value in any other field.

If I don't get any more comments I will re-send this patch separately using EOPNOTSUPP instead of ENOSYS. I will also keep the Acks gathered so far unless anyone objects.

Please send a new patch. I believe this one is already applied.

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

#9 lore raw

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

In reply to a message not in the archive

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]>

---
 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}    | 0
 12 files changed, 2 insertions(+), 2 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} (100%)
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 +0 -0
similarity index 100%
rename from xen/include/xen/gcov.h
rename to xen/include/xen/coverage.h
Signature · 7 lines
2.13.5 (Apple Git-94)


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

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

xen/include/xen/coverage.h

Quoted 4 lines
xen/include/xen/coverage.h renamed from xen/include/xen/gcov.h +0 -0
similarity index 100%
rename from xen/include/xen/gcov.h
rename to xen/include/xen/coverage.h

Please also rename the define guard in this file.

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

#11 lore raw

PATCH 3/9 gcov: rename sysctl and functions

In reply to a message not in the archive

Change gcov to cov.

---
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]>

---
 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..5db00c37db 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_cov_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.cov_op.cmd = op;
+    sysctl->u.cov_op.size = buf_size;
+    set_xen_guest_handle(sysctl->u.cov_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_COV_get_size, &sys, NULL, 0) < 0)
         err(1, "getting total length");
-    total_len = sys.u.gcov_op.size;
+    total_len = sys.u.cov_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_COV_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_COV_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 35653fd8d8..b1735693be 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_cov_op *op)
 {
     int ret;
 
     switch ( op->cmd )
     {
-    case XEN_SYSCTL_GCOV_get_size:
+    case XEN_SYSCTL_COV_get_size:
         op->size = gcov_get_size();
         ret = 0;
         break;
 
-    case XEN_SYSCTL_GCOV_read:
+    case XEN_SYSCTL_COV_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_COV_reset:
         gcov_reset_all_counters();
         ret = 0;
         break;
xen/common/sysctl.c +2 -2
index 56def766e6..da3e1246b1 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_cov_op:
+        ret = sysctl_cov_op(&op->u.cov_op);
         copyback = 1;
         break;
 #endif
xen/include/public/sysctl.h +6 -6
index 6140f1a059..654b37cdce 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_COV_get_size 0 /* Get total size of output data */
+#define XEN_SYSCTL_COV_read     1 /* Read output data */
+#define XEN_SYSCTL_COV_reset    2 /* Reset all counters */
 
-struct xen_sysctl_gcov_op {
+struct xen_sysctl_cov_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_cov_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_cov_op            cov_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 ef22eafc1f..bdfd29d3bb 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_cov_op *op);
 #endif
 
 #endif	/* _XEN_GCOV_H */
Signature · 7 lines
2.13.5 (Apple Git-94)


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

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

In reply to Roger Pau Monne
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 26.10.17 at 11:19, <[email protected]> wrote:
xen/include/public/sysctl.h +5 -5
@@ -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_COV_get_size 0 /* Get total size of output data */
+#define XEN_SYSCTL_COV_read     1 /* Read output data */
+#define XEN_SYSCTL_COV_reset    2 /* Reset all counters */
 
-struct xen_sysctl_gcov_op {
+struct xen_sysctl_cov_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_cov_op                        20
 #define XEN_SYSCTL_psr_cmt_op                    21
 #define XEN_SYSCTL_pcitopoinfo                   22
 #define XEN_SYSCTL_psr_cat_op                    23

xen/include/public/sysctl.h struct xen_sysctl { · line 1101

Quoted 8 lines
xen/include/public/sysctl.h +1 -1
@@ -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_cov_op            cov_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;

While for internal things "cov" is probably fine for now, for the public interface I think I would prefer it to be a little longer, perhaps even fully spelled out "coverage".

Jan

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

#14 lore raw

PATCH 4/9 gcov: introduce hooks for the sysctl

In reply to a message not in the archive

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]>

---
 xen/common/coverage/gcov.c | 13 ++++++++++---
 xen/include/xen/coverage.h |  7 +++++++
 2 files changed, 17 insertions(+), 3 deletions(-)
xen/common/coverage/gcov.c +10 -3
index b1735693be..66c4075f8a 100644
@@ -19,6 +19,7 @@
 #include <xen/errno.h>
 #include <xen/guest_access.h>
 #include <xen/types.h>
+#include <xen/coverage.h>
 
 #include <public/sysctl.h>
 
@@ -209,6 +210,12 @@ static int gcov_dump_all(XEN_GUEST_HANDLE_PARAM(char) buffer,
     return ret;
 }
 
+static 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_cov_op *op)
 {
     int ret;
@@ -216,7 +223,7 @@ int sysctl_cov_op(struct xen_sysctl_cov_op *op)
     switch ( op->cmd )
     {
     case XEN_SYSCTL_COV_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_cov_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_COV_reset:
-        gcov_reset_all_counters();
+        cov_ops.reset_counters();
         ret = 0;
         break;
 
xen/include/xen/coverage.h +7 -0
index bdfd29d3bb..9078330109 100644
@@ -3,6 +3,13 @@
 
 #ifdef CONFIG_GCOV
 #include <public/sysctl.h>
+
+struct cov_sysctl_ops {
+    uint32_t (*get_size)(void);
+    void     (*reset_counters)(void);
+    int      (*dump)(XEN_GUEST_HANDLE_PARAM(char), uint32_t *);
+};
+
 int sysctl_cov_op(struct xen_sysctl_cov_op *op);
 #endif
 
Signature · 7 lines
2.13.5 (Apple Git-94)


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

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

xen/common/coverage/gcov.c static int gcov_dump_all(XEN_GUEST_HANDLE_PARAM(char) buffer, · line 213

Quoted 5 lines · Roger Pau Monne
xen/common/coverage/gcov.c +1 -0
@@ -209,6 +210,12 @@ static int gcov_dump_all(XEN_GUEST_HANDLE_PARAM(char) buffer,
     return ret;
 }
 
+static struct cov_sysctl_ops cov_ops = {

static const.

~Andrew

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

#16 lore raw

PATCH 5/9 coverage: introduce generic file

In reply to a message not in the archive

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]>

---
 xen/common/coverage/Makefile   |  2 +-
 xen/common/coverage/coverage.c | 71 ++++++++++++++++++++++++++++++++++++++++++
 xen/common/coverage/gcov.c     | 41 +-----------------------
 xen/include/xen/coverage.h     |  1 +
 4 files changed, 74 insertions(+), 41 deletions(-)
 create mode 100644 xen/common/coverage/coverage.c
xen/common/coverage/Makefile +1 -1
index f68d050eca..0e0510679e 100644
@@ -1,4 +1,4 @@
-obj-y += gcov_base.o gcov.o
+obj-y += gcov_base.o gcov.o coverage.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
xen/common/coverage/coverage.c new file +71 -0

71 lines not on this page · raw message

xen/common/coverage/gcov.c +1 -40

58 lines not on this page · raw message

xen/include/xen/coverage.h +1 -0
index 9078330109..de400620bf 100644
@@ -9,6 +9,7 @@ struct cov_sysctl_ops {
     void     (*reset_counters)(void);
     int      (*dump)(XEN_GUEST_HANDLE_PARAM(char), uint32_t *);
 };
+extern struct cov_sysctl_ops cov_ops;
 
 int sysctl_cov_op(struct xen_sysctl_cov_op *op);
 #endif
Signature · 7 lines
2.13.5 (Apple Git-94)


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

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

Quoted 29 lines · Roger Pau Monne
xen/common/coverage/Makefile +1 -1
index f68d050eca..0e0510679e 100644
@@ -1,4 +1,4 @@
-obj-y += gcov_base.o gcov.o
+obj-y += gcov_base.o gcov.o coverage.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
xen/common/coverage/coverage.c new file +12 -0
new file mode 100644
index 0000000000..1dec6944be
@@ -0,0 +1,71 @@
+/*
+ * 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

xen/common/coverage/coverage.c line 22

Quoted 10 lines
xen/common/coverage/coverage.c new file +10 -0
+ * 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>

Please sort this.

The rest appears to be pure code motion to me. It looks fine.

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

#18 lore raw

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

Quoted 34 lines · Wei Liu
Quoted 33 lines · Roger Pau Monne
xen/common/coverage/Makefile +1 -1
index f68d050eca..0e0510679e 100644
@@ -1,4 +1,4 @@
-obj-y += gcov_base.o gcov.o
+obj-y += gcov_base.o gcov.o coverage.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
xen/common/coverage/coverage.c new file +16 -0
new file mode 100644
index 0000000000..1dec6944be
@@ -0,0 +1,71 @@
+/*
+ * 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/>.
Quoted 8 lines

xen/common/coverage/coverage.c line 22

Quoted 6 lines
xen/common/coverage/coverage.c new file +6 -0
+ */
+
+#include <xen/errno.h>
+#include <xen/guest_access.h>
+#include <xen/types.h>
+#include <xen/coverage.h>

Please sort this.

OK, I will have to include type.h in coverage.h then.

Thanks, Roger.

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

#19 lore raw

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

Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 30.10.17 at 17:57, <[email protected]> wrote:
Quoted 20 lines · Wei Liu
Quoted 19 lines · Roger Pau Monne
xen/common/coverage/coverage.c new file +16 -0
@@ -0,0 +1,71 @@
+/*
+ * 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/>.
Quoted 8 lines

xen/common/coverage/coverage.c line 22

Quoted 6 lines
xen/common/coverage/coverage.c new file +6 -0
+ */
+
+#include <xen/errno.h>
+#include <xen/guest_access.h>
+#include <xen/types.h>
+#include <xen/coverage.h>

Please sort this.

Quoted 1 line

OK, I will have to include type.h in coverage.h then.

But that's not something depending on the ordering request: No matter that we have many examples to the contrary, headers (at least non-private ones) shouldn't really rely on other things to have been included up front.

Jan

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

#20 lore raw

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

In reply to Roger Pau Monne

xen/common/coverage/Makefile line 1

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 26.10.17 at 11:19, <[email protected]> wrote:
xen/common/coverage/Makefile +1 -1
@@ -1,4 +1,4 @@
-obj-y += gcov_base.o gcov.o
+obj-y += gcov_base.o gcov.o coverage.o

These would better be sorted, too.

xen/include/xen/coverage.h struct cov_sysctl_ops { · line 12

Quoted 7 lines
xen/include/xen/coverage.h +1 -0
@@ -9,6 +9,7 @@ struct cov_sysctl_ops {
     void     (*reset_counters)(void);
     int      (*dump)(XEN_GUEST_HANDLE_PARAM(char), uint32_t *);
 };
+extern struct cov_sysctl_ops cov_ops;

I don't think this is the right place to put this declaration (and perhaps also the struct one) - it's not part of the outside visible interface of the coverage code, but an internal aspect. Such should live in a private header, unless they need to be exposed to e.g. arch specific code (which doesn't appear to be the case here).

Jan

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

#21 lore raw

PATCH 6/9 kconfig: add llvm coverage option

In reply to a message not in the archive

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]>

---
 xen/Kconfig.debug            | 16 ++++++++++++++++
 xen/Rules.mk                 |  4 ++++
 xen/common/Makefile          |  2 +-
 xen/common/coverage/Makefile |  4 ++++
 xen/common/sysctl.c          |  2 +-
 xen/include/xen/coverage.h   |  2 +-
 6 files changed, 27 insertions(+), 3 deletions(-)
xen/Kconfig.debug +16 -0
index 8d70f63743..46c72ea8bb 100644
@@ -28,10 +28,17 @@ config FRAME_POINTER
 	  maybe slower, but it gives very useful debugging information
 	  in case of any Xen bugs.
 
+# Hidden option enabled when either GCOV or LLVM coverage support is enabled.
+# This allows to enable the shared coverage bits in Xen without having to
+# check for each possible coverage implementation.
+config COVERAGE
+	bool
+
 config GCOV
 	bool "Gcov Support"
 	depends on !LIVEPATCH
 	select SUPPRESS_DUPLICATE_SYMBOL_WARNINGS
+	select COVERAGE
 	---help---
 	  Enable gcov (a test coverage program in GCC) support.
 
@@ -83,6 +90,15 @@ config GCOV_FORMAT_3_4
 
 endchoice
 
+config LLVM_COVERAGE
+	bool "LLVM coverage support"
+	depends on !LIVEPATCH && !GCOV
+	select COVERAGE
+	---help---
+	  Enable LLVM coverage support.
+
+	  If unsure, say N here.
+
 config LOCK_PROFILE
 	bool "Lock Profiling"
 	---help---
xen/Rules.mk +4 -0
index 2659f8a4d1..076ba93185 100644
@@ -119,6 +119,10 @@ ifeq ($(CONFIG_GCOV),y)
 $(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-arcs -ftest-coverage
 endif
 
+ifeq ($(CONFIG_LLVM_COVERAGE),y)
+$(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-instr-generate -fcoverage-mapping
+endif
+
 ifeq ($(CONFIG_UBSAN),y)
 $(filter-out %.init.o $(noubsan-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fsanitize=undefined
 endif
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 -0
index 0e0510679e..e4541a1233 100644
@@ -1,3 +1,4 @@
+ifeq ($(CONFIG_GCOV),y)
 obj-y += gcov_base.o gcov.o coverage.o
 obj-$(CONFIG_GCOV_FORMAT_3_4) += gcc_3_4.o
 obj-$(CONFIG_GCOV_FORMAT_4_7) += gcc_4_7.o
@@ -9,3 +10,6 @@ obj-$(CONFIG_GCOV_FORMAT_AUTODETECT) += $(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 += coverage.o
+endif
xen/common/sysctl.c +1 -1
index da3e1246b1..e989b2711d 100644
@@ -396,7 +396,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
     }
     break;
 
-#ifdef CONFIG_GCOV
+#ifdef CONFIG_COVERAGE
     case XEN_SYSCTL_cov_op:
         ret = sysctl_cov_op(&op->u.cov_op);
         copyback = 1;
xen/include/xen/coverage.h +1 -1
index de400620bf..666bf624f9 100644
@@ -1,7 +1,7 @@
 #ifndef _XEN_GCOV_H
 #define _XEN_GCOV_H
 
-#ifdef CONFIG_GCOV
+#ifdef CONFIG_COVERAGE
 #include <public/sysctl.h>
 
 struct cov_sysctl_ops {
Signature · 7 lines
2.13.5 (Apple Git-94)


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

Re: [PATCH for-next 6/9] kconfig: add llvm coverage option

xen/Kconfig.debug config FRAME_POINTER · line 39

Quoted 3 lines · Roger Pau Monne

config GCOV

xen/Kconfig.debug +0 -0
 	bool "Gcov Support"
 	depends on !LIVEPATCH

&& !LLVM_COVERAGE

(will review in detail later)

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

#23 lore raw

Re: [PATCH for-next 6/9] kconfig: add llvm coverage option

Quoted 6 lines · Wei Liu

xen/Kconfig.debug config FRAME_POINTER · line 39

Quoted 3 lines · Roger Pau Monne

config GCOV

xen/Kconfig.debug +0 -0
 	bool "Gcov Support"
 	depends on !LIVEPATCH

&& !LLVM_COVERAGE

That was my idea, but sadly that's not possible because you generate a circular dependency. The best solution that I found is to only mark one as exclusive (ie: have depends !GCOV in the LLVM_COVERAGE option below).

Thanks, Roger.

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

#24 lore raw

Re: [PATCH for-next 6/9] kconfig: add llvm coverage option

Quoted 6 lines · Roger Pau Monné
Quoted 5 lines · Wei Liu
Quoted 3 lines · Roger Pau Monne

config GCOV

xen/Kconfig.debug +0 -0
 	bool "Gcov Support"
 	depends on !LIVEPATCH
Quoted 7 lines
Quoted 1 line

&& !LLVM_COVERAGE

That was my idea, but sadly that's not possible because you generate a circular dependency. The best solution that I found is to only mark one as exclusive (ie: have depends !GCOV in the LLVM_COVERAGE option below).

In that case, why not just use "choice" to let user pick the implementation?

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

#25 lore raw

Re: [PATCH for-next 6/9] kconfig: add llvm coverage option

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 26.10.17 at 12:10, <[email protected]> wrote:
Quoted 8 lines · Roger Pau Monné
Quoted 6 lines · Wei Liu

xen/Kconfig.debug config FRAME_POINTER · line 39

Quoted 3 lines · Roger Pau Monne

config GCOV

xen/Kconfig.debug +0 -0
 	bool "Gcov Support"
 	depends on !LIVEPATCH

&& !LLVM_COVERAGE

Quoted 7 lines
Quoted 4 lines

That was my idea, but sadly that's not possible because you generate a circular dependency. The best solution that I found is to only mark one as exclusive (ie: have depends !GCOV in the LLVM_COVERAGE option below).

In that case, why not just use "choice" to let user pick the implementation?

Plus then this choice should probably have an auto-detect option just like gcov's gcc version one - at least I assume that it should be pretty straightforward to tell at build time which variant to use. In fact - what would happen if one enabled the wrong option for the compiler in use? IOW I wonder whether auto-detection (and then also for the gcc version) should be the only valid mode).

Jan

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

#26 lore raw

Re: [PATCH for-next 6/9] kconfig: add llvm coverage option

Quoted 18 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 26.10.17 at 12:10, <[email protected]> wrote:
Quoted 8 lines · Roger Pau Monné
Quoted 6 lines · Wei Liu

xen/Kconfig.debug config FRAME_POINTER · line 39

Quoted 3 lines · Roger Pau Monne

config GCOV

xen/Kconfig.debug +0 -0
 	bool "Gcov Support"
 	depends on !LIVEPATCH

&& !LLVM_COVERAGE

Quoted 7 lines
Quoted 4 lines

That was my idea, but sadly that's not possible because you generate a circular dependency. The best solution that I found is to only mark one as exclusive (ie: have depends !GCOV in the LLVM_COVERAGE option below).

In that case, why not just use "choice" to let user pick the implementation?

Quoted 6 lines

Plus then this choice should probably have an auto-detect option just like gcov's gcc version one - at least I assume that it should be pretty straightforward to tell at build time which variant to use. In fact - what would happen if one enabled the wrong option for the compiler in use? IOW I wonder whether auto-detection (and then also for the gcc version) should be the only valid mode).

I don't plan to introduce llvm/clang version choices here, I think autodetection should be fine.

I can remove the gcc ones also, leaving this as a boolean choice (ie:
enable code coverage support), but I would like to have some confirmation from the gcc side.

Thanks, Roger.

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

#27 lore raw

Re: [PATCH for-next 6/9] kconfig: add llvm coverage option

Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 08.11.17 at 09:49, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 26.10.17 at 12:10, <[email protected]> wrote:
Quoted 8 lines · Roger Pau Monné
Quoted 6 lines · Wei Liu

xen/Kconfig.debug config FRAME_POINTER · line 39

Quoted 3 lines · Roger Pau Monne

config GCOV

xen/Kconfig.debug +0 -0
 	bool "Gcov Support"
 	depends on !LIVEPATCH

&& !LLVM_COVERAGE

Quoted 7 lines
Quoted 4 lines

That was my idea, but sadly that's not possible because you generate a circular dependency. The best solution that I found is to only mark one as exclusive (ie: have depends !GCOV in the LLVM_COVERAGE option below).

In that case, why not just use "choice" to let user pick the implementation?

Quoted 6 lines

Plus then this choice should probably have an auto-detect option just like gcov's gcc version one - at least I assume that it should be pretty straightforward to tell at build time which variant to use. In fact - what would happen if one enabled the wrong option for the compiler in use? IOW I wonder whether auto-detection (and then also for the gcc version) should be the only valid mode).

Quoted 2 lines

I don't plan to introduce llvm/clang version choices here, I think autodetection should be fine.

And I didn't think about version choices for clang here anyway - the point really was just about gcc vs clang.

Quoted 3 lines

I can remove the gcc ones also, leaving this as a boolean choice (ie:
enable code coverage support), but I would like to have some confirmation from the gcc side.

So let's ask Wei: What was the reason for the Kconfig level version choice here in the first place? After all, if the wrong one is being selected, the build will fail afaict due to the #error directives in the version specific files.

Jan

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

#28 lore raw

Re: [PATCH for-next 6/9] kconfig: add llvm coverage option

Quoted 33 lines · Jan Beulich
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 08.11.17 at 09:49, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 26.10.17 at 12:10, <[email protected]> wrote:
Quoted 8 lines · Roger Pau Monné
Quoted 6 lines · Wei Liu

Review

Quoted 3 lines · Roger Pau Monne

config GCOV

(quoted diff) +0 -0
 	bool "Gcov Support"
 	depends on !LIVEPATCH

&& !LLVM_COVERAGE

Quoted 7 lines
Quoted 4 lines

That was my idea, but sadly that's not possible because you generate a circular dependency. The best solution that I found is to only mark one as exclusive (ie: have depends !GCOV in the LLVM_COVERAGE option below).

In that case, why not just use "choice" to let user pick the implementation?

Quoted 6 lines

Plus then this choice should probably have an auto-detect option just like gcov's gcc version one - at least I assume that it should be pretty straightforward to tell at build time which variant to use. In fact - what would happen if one enabled the wrong option for the compiler in use? IOW I wonder whether auto-detection (and then also for the gcc version) should be the only valid mode).

Quoted 2 lines

I don't plan to introduce llvm/clang version choices here, I think autodetection should be fine.

And I didn't think about version choices for clang here anyway - the point really was just about gcc vs clang.

Quoted 9 lines
Quoted 3 lines

I can remove the gcc ones also, leaving this as a boolean choice (ie:
enable code coverage support), but I would like to have some confirmation from the gcc side.

So let's ask Wei: What was the reason for the Kconfig level version choice here in the first place? After all, if the wrong one is being selected, the build will fail afaict due to the #error directives in the version specific files.

The #error on versions was added in later iterations IIRC. Looking back I think it would make sense to just have autodetect.

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

#29 lore raw

Re: [PATCH for-next 6/9] kconfig: add llvm coverage option

In reply to Roger Pau Monne
Quoted 10 lines · Roger Pau Monne
xen/common/coverage/Makefile +1 -0
index 0e0510679e..e4541a1233 100644
@@ -1,3 +1,4 @@
+ifeq ($(CONFIG_GCOV),y)
 obj-y += gcov_base.o gcov.o coverage.o
 obj-$(CONFIG_GCOV_FORMAT_3_4) += gcc_3_4.o
 obj-$(CONFIG_GCOV_FORMAT_4_7) += gcc_4_7.o

xen/common/coverage/Makefile obj-$(CONFIG_GCOV_FORMAT_AUTODETECT) += $(call cc-ifversion,lt,0x040700, \ · line 15

Quoted 6 lines
xen/common/coverage/Makefile +3 -0
@@ -9,3 +10,6 @@ obj-$(CONFIG_GCOV_FORMAT_AUTODETECT) += $(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 += coverage.o
+endif

How about

obj-y += coverage.o

ifeq ($(CONFIG_GCOV),y)
...
endif

seeing as coverage.o is common now?

~Andrew

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

#30 lore raw

Re: [PATCH for-next 6/9] kconfig: add llvm coverage option

Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 26.10.17 at 12:24, <[email protected]> wrote:

xen/common/coverage/Makefile obj-$(CONFIG_GCOV_FORMAT_AUTODETECT) += $(call

Quoted 10 lines · Roger Pau Monne
xen/common/coverage/Makefile +1 -0
index 0e0510679e..e4541a1233 100644
@@ -1,3 +1,4 @@
+ifeq ($(CONFIG_GCOV),y)
 obj-y += gcov_base.o gcov.o coverage.o
 obj-$(CONFIG_GCOV_FORMAT_3_4) += gcc_3_4.o
 obj-$(CONFIG_GCOV_FORMAT_4_7) += gcc_4_7.o
@@ -9,3 +10,6 @@ obj-$(CONFIG_GCOV_FORMAT_AUTODETECT) += $(call 

cc-ifversion,lt,0x040700, \

xen/common/coverage/Makefile obj-$(CONFIG_GCOV_FORMAT_AUTODETECT) += $(call cc-ifversion,lt,0x040700, \ · line 15

Quoted 6 lines
xen/common/coverage/Makefile +3 -0
 						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 += coverage.o
+endif

How about

Quoted 5 lines

obj-y += coverage.o

ifeq ($(CONFIG_GCOV),y)
...
endif

Except please obj-$(CONFIG_GCOV) instead of ifeq.

Jan

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

#31 lore raw

Re: [PATCH for-next 6/9] kconfig: add llvm coverage option

In reply to Roger Pau Monne

xen/Kconfig.debug config FRAME_POINTER · line 35

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 26.10.17 at 11:19, <[email protected]> wrote:
xen/Kconfig.debug +5 -0
@@ -28,10 +28,17 @@ config FRAME_POINTER
 	  maybe slower, but it gives very useful debugging information
 	  in case of any Xen bugs.
 
+# Hidden option enabled when either GCOV or LLVM coverage support is enabled.
+# This allows to enable the shared coverage bits in Xen without having to
+# check for each possible coverage implementation.
+config COVERAGE
+	bool

In case this is still needed after the conversion to "choice", the comment should be dropped - it is the very purpose of prompt-less options that is being described there.

xen/Rules.mk ifeq ($(CONFIG_GCOV),y) · line 124

Quoted 9 lines
xen/Rules.mk +3 -0
@@ -119,6 +119,10 @@ ifeq ($(CONFIG_GCOV),y)
 $(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-arcs -ftest-coverage
 endif
 
+ifeq ($(CONFIG_LLVM_COVERAGE),y)
+$(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-instr-generate -fcoverage-mapping
+endif

The use of nogcov-y here suggests that the earlier patch abstracting away the "g" should be extended to remove that letter here, too.

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 402

Quoted 11 lines
xen/common/sysctl.c +1 -1
@@ -396,7 +396,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
     }
     break;
 
-#ifdef CONFIG_GCOV
+#ifdef CONFIG_COVERAGE
     case XEN_SYSCTL_cov_op:
         ret = sysctl_cov_op(&op->u.cov_op);
         copyback = 1;

Couldn't you better do away with the #ifdef altogether, by introducing a suitable inline function for the coverage-disabled case (returning -EOPNOTSUPP)?

Jan

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

#32 lore raw

PATCH 7/9 coverage: introduce support for llvm profiling

In reply to a message not in the archive

Introduce the functionality in order to fill the hooks of the cov_sysctl_ops struct.

---
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]>
Cc: [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.

---
 xen/common/coverage/Makefile |   2 +-
 xen/common/coverage/llvm.c   | 148 +++++++++++++++++++++++++++++++++++++++++++
 xen/include/public/sysctl.h  |   6 ++
 3 files changed, 155 insertions(+), 1 deletion(-)
 create mode 100644 xen/common/coverage/llvm.c
xen/common/coverage/Makefile +1 -1
index e4541a1233..f2ffb2b8de 100644
@@ -11,5 +11,5 @@ obj-$(CONFIG_GCOV_FORMAT_AUTODETECT) += $(call cc-ifversion,lt,0x040700, \
 						gcc_4_9.o, $(call cc-ifversion,lt,0x070000, \
 						gcc_5.o, gcc_7.o))))
 else
-obj-y += coverage.o
+obj-y += llvm.o coverage.o
 endif
xen/common/coverage/llvm.c new file +148 -0

148 lines not on this page · raw message

xen/include/public/sysctl.h +6 -0
index 654b37cdce..62824b18f2 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_COV_get_size 0 /* Get total size of output data */
 #define XEN_SYSCTL_COV_read     1 /* Read output data */
 #define XEN_SYSCTL_COV_reset    2 /* Reset all counters */
Signature · 7 lines
2.13.5 (Apple Git-94)


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

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

In reply to a message not in the archive

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]>

---
 xen/include/xsm/dummy.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
xen/include/xsm/dummy.h +14 -0
index b2cd56cdc5..674dc8ea1b 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)
+
+#ifdef CONFIG_LLVM_COVERAGE
+/*
+ * 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 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.5 (Apple Git-94)


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

Re: [PATCH for-next 8/9] xsm: add bodge when compiling with llvm coverage support

Quoted 8 lines · 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.

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

#35 lore raw

Re: [PATCH for-next 8/9] xsm: add bodge when compiling with llvm coverage support

In reply to Roger Pau Monne
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 26.10.17 at 11:19, <[email protected]> wrote:
xen/include/xsm/dummy.h +2 -0
@@ -24,8 +24,22 @@
  * if references remain at link time.
  */
 #define LINKER_BUG_ON(x) do { if (x) __xsm_action_mismatch_detected(); } while (0)
+
+#ifdef CONFIG_LLVM_COVERAGE

xen/include/xsm/dummy.h line 38

Quoted 10 lines
xen/include/xsm/dummy.h +10 -0
+/*
+ * 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 void __xsm_action_mismatch_detected(void)
+{
+    ASSERT_UNREACHABLE();
+}

I'm pretty sure this wants to be "inline".

Jan

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

#36 lore raw

PATCH 9/9 coverage: add documentation for LLVM coverage

In reply to a message not in the archive

---
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]>

---
 docs/misc/coverage.markdown | 47 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
docs/misc/coverage.markdown +47 -0
index 0a32c48f4b..565644631a 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 `coverage` option set
@@ -87,3 +89,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:
+
+    gmake -C xen menuconfig clang=y
+
+The LLVM coverage option can be found inside of the "Debugging Options"
+section. After enabling it just compile Xen as you would normally do:
+
+   gmake 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.5 (Apple Git-94)


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

Re: [PATCH for-next 9/9] coverage: add documentation for LLVM coverage

Quoted 36 lines · 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]>

---
 docs/misc/coverage.markdown | 47 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
docs/misc/coverage.markdown +7 -0
index 0a32c48f4b..565644631a 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 `coverage` option set
@@ -87,3 +89,48 @@ blob extracted from xencov!**
 * See output in a browser
 
         firefox cov/index.html
+
+# LLVM coverage
+
+## Enable coverage
+

docs/misc/coverage.markdown blob extracted from xencov!** · line 106

Quoted 10 lines
docs/misc/coverage.markdown +10 -0
+Coverage can be enabled using a Kconfig option, from the top-level directory
+use the following command to display the Kconfig menu:
+
+    gmake -C xen menuconfig clang=y
+
+The LLVM coverage option can be found inside of the "Debugging Options"
+section. After enabling it just compile Xen as you would normally do:
+
+   gmake xen clang=y
+

It can be a bit confusing when make and gmake appear in the same document. I suggest you use make all over and add a footnote saying it should be gmake on FreeBSD.

This footnote should apply to both gcov and llvm-cov -- I believe you should be able to build gcov support on FreeBSD, too.

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

#38 lore raw

Re: [PATCH for-next 9/9] coverage: add documentation for LLVM coverage

Quoted 43 lines · Wei Liu
Quoted 42 lines · 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]>

---
 docs/misc/coverage.markdown | 47 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
docs/misc/coverage.markdown +13 -0
index 0a32c48f4b..565644631a 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 `coverage` option set
@@ -87,3 +89,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:
+
+    gmake -C xen menuconfig clang=y
+
+The LLVM coverage option can be found inside of the "Debugging Options"
Quoted 8 lines

docs/misc/coverage.markdown blob extracted from xencov!** · line 106

Quoted 4 lines
docs/misc/coverage.markdown +4 -0
+section. After enabling it just compile Xen as you would normally do:
+
+   gmake xen clang=y
+

It can be a bit confusing when make and gmake appear in the same document. I suggest you use make all over and add a footnote saying it should be gmake on FreeBSD.

This is my fault from copying the runes from my command line. I'm not sure a footnote is even needed, everything on BSDs should use gmake instead of make, and I don't plan to edit all the documentation files.

Thanks, Roger.

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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#40 lore raw

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

Quoted 4 lines · Roger Pau Monne

Introduce the functionality in order to fill the hooks of the cov_sysctl_ops struct.

Quoted 14 lines

---
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]>
Cc: [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.

It would be helpful if you can put a reference to the original code somewhere, either in commit message or in the comment section of the file.

Quoted 23 lines
---
 xen/common/coverage/Makefile |   2 +-
 xen/common/coverage/llvm.c   | 148 +++++++++++++++++++++++++++++++++++++++++++
 xen/include/public/sysctl.h  |   6 ++
 3 files changed, 155 insertions(+), 1 deletion(-)
 create mode 100644 xen/common/coverage/llvm.c
xen/common/coverage/Makefile +1 -1
index e4541a1233..f2ffb2b8de 100644
@@ -11,5 +11,5 @@ obj-$(CONFIG_GCOV_FORMAT_AUTODETECT) += $(call cc-ifversion,lt,0x040700, \
 						gcc_4_9.o, $(call cc-ifversion,lt,0x070000, \
 						gcc_5.o, gcc_7.o))))
 else
-obj-y += coverage.o
+obj-y += llvm.o coverage.o
 endif
xen/common/coverage/llvm.c new file +0 -0
new file mode 100644
index 0000000000..c8905070a3

xen/common/coverage/llvm.c

Quoted 5 lines
xen/common/coverage/llvm.c new file +5 -0
+#include <xen/errno.h>
+#include <xen/guest_access.h>
+#include <xen/types.h>
+#include <xen/coverage.h>
+

Order.

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

#41 lore raw

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

In reply to a message not in the archive
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 26.10.17 at 11:19, <[email protected]> wrote:
xen/common/coverage/llvm.c new file +31 -0
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2017 Citrix Systems R&D
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <xen/errno.h>
+#include <xen/guest_access.h>
+#include <xen/types.h>
+#include <xen/coverage.h>
+

xen/common/coverage/llvm.c line 41

Quoted 10 lines
xen/common/coverage/llvm.c new file +10 -0
+#ifndef __clang__
+#error "LLVM coverage selected without clang compiler"
+#endif
+
+#define LLVM_PROFILE_MAGIC_64 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
+       (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 |  \
+        (uint64_t)'f' << 16 | (uint64_t)'r' << 8 | (uint64_t)129
+#define LLVM_PROFILE_MAGIC_32 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
+       (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 |  \
+        (uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129

Judging by the file having Xen style, I imply this isn't intended to very closely match some other original. With that, parentheses should be added around all the shift operations above.

xen/common/coverage/llvm.c line 42

Quoted 1 line
xen/common/coverage/llvm.c new file +1 -0
+#if __clang_major__ >= 4 || (__clang_major__ == 3 && __clang_minor__ == 9)

Is it certain that there's never going to be a 3.10? Otherwise

Quoted 3 lines

= might be more suitable for the minor version check.

+int __llvm_profile_runtime;

This isn't used anywhere - please add a brief comment explaining the need for it (the more that its type being plain int is also suspicious).

xen/common/coverage/llvm.c

Quoted 6 lines
xen/common/coverage/llvm.c new file +6 -0
+extern struct llvm_profile_data __start___llvm_prf_data;
+extern struct llvm_profile_data __stop___llvm_prf_data;
+extern uint64_t __start___llvm_prf_cnts;
+extern uint64_t __stop___llvm_prf_cnts;
+extern char __start___llvm_prf_names;
+extern char __stop___llvm_prf_names;

I guess all of these really want to have [] added, making ...

xen/common/coverage/llvm.c

Quoted 6 lines
xen/common/coverage/llvm.c new file +6 -0
+static void *start_data = &__start___llvm_prf_data;
+static void *end_data = &__stop___llvm_prf_data;
+static void *start_counters = &__start___llvm_prf_cnts;
+static void *end_counters = &__stop___llvm_prf_cnts;
+static void *start_names = &__start___llvm_prf_names;
+static void *end_names = &__stop___llvm_prf_names;

... the &s here unnecessary. But then - do these really need to be statics (rather than #define-s)?

I would also guess that at least the names ones could be const.

xen/common/coverage/llvm.c

Quoted 8 lines
xen/common/coverage/llvm.c new file +8 -0
+static int dump(XEN_GUEST_HANDLE_PARAM(char) buffer, uint32_t *buf_size)
+{
+    struct llvm_profile_header header = {
+#if BITS_PER_LONG == 64
+        .magic = LLVM_PROFILE_MAGIC_64,
+#else
+        .magic = LLVM_PROFILE_MAGIC_32,
+#endif

I think this should just be LLVM_PROFILE_MAGIC, with the #ifdef moved to the #define-s.

xen/common/coverage/llvm.c

Quoted 13 lines
xen/common/coverage/llvm.c new file +13 -0
+        .version = LLVM_PROFILE_VERSION,
+        .data_size = (end_data - start_data) / sizeof(struct llvm_profile_data),
+        .counters_size = (end_counters - start_counters) / sizeof(uint64_t),
+        .names_size = end_names - start_names,
+        .counters_delta = (uintptr_t)start_counters,
+        .names_delta = (uintptr_t)start_names,
+        .value_kind_last = LLVM_PROFILE_NUM_KINDS - 1,
+    };
+    unsigned int off = 0;
+
+#define APPEND_TO_BUFFER(src, size)                     \
+({                                                      \
+    if ( off + size > *buf_size )                       \

(size)

xen/common/coverage/llvm.c

Quoted 3 lines
xen/common/coverage/llvm.c new file +3 -0
+        return -ENOMEM;                                 \
+    copy_to_guest_offset(buffer, off, src, size);       \
+    off += size;                                        \

Ideally here too, albeit only the comma operator has lower precedence, and that would require parenthesizing in the macro invocation already (which is also why the arguments to copy_to_guest_offset() explicitly do not need extra parentheses added).

xen/common/coverage/llvm.c

Quoted 2 lines
xen/common/coverage/llvm.c new file +2 -0
+})
+    APPEND_TO_BUFFER((char *)&header, sizeof(struct llvm_profile_header));

sizeof(header)

xen/common/coverage/llvm.c

Quoted 3 lines
xen/common/coverage/llvm.c new file +3 -0
+    APPEND_TO_BUFFER((char *)start_data, end_data - start_data);
+    APPEND_TO_BUFFER((char *)start_counters, end_counters - start_counters);
+    APPEND_TO_BUFFER((char *)start_names, end_names - start_names);

The casts should all be to const char*, and perhaps that would better be done inside the macro anyway.

xen/common/coverage/llvm.c

Quoted 8 lines
xen/common/coverage/llvm.c new file +8 -0
+#undef APPEND_TO_BUFFER
+
+    clear_guest_offset(buffer, off, *buf_size - off);
+
+    return 0;
+}
+
+struct cov_sysctl_ops cov_ops = {

const

xen/include/public/sysctl.h struct xen_sysctl_scheduler_op { · line 647

Quoted 5 lines
xen/include/public/sysctl.h +0 -0
@@ -646,6 +646,12 @@ struct xen_sysctl_scheduler_op {
 
 #define XEN_GCOV_FORMAT_MAGIC    0x58434f56 /* XCOV */

Hmm, shouldn't the private magic #define-s actually be put here (in which case you'd indeed need to retain both 32- and 64-bit variants)?

Jan

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

#42 lore raw

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

Quoted 14 lines · Jan Beulich

xen/common/coverage/llvm.c

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 26.10.17 at 11:19, <[email protected]> wrote:
xen/common/coverage/llvm.c new file +6 -0
+#define LLVM_PROFILE_MAGIC_64 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
+       (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 |  \
+        (uint64_t)'f' << 16 | (uint64_t)'r' << 8 | (uint64_t)129
+#define LLVM_PROFILE_MAGIC_32 (uint64_t)255 << 56 | (uint64_t)'l' << 48 | \
+       (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 |  \
+        (uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129

Judging by the file having Xen style, I imply this isn't intended to very closely match some other original. With that, parentheses should be added around all the shift operations above.

Quoted 4 lines
Quoted 1 line

+#if __clang_major__ >= 4 || (__clang_major__ == 3 && __clang_minor__ == 9)

Is it certain that there's never going to be a 3.10? Otherwise

Quoted 1 line

= might be more suitable for the minor version check.

No, there's not going to be a clang 3.10.

Quoted 5 lines
Quoted 1 line

+int __llvm_profile_runtime;

This isn't used anywhere - please add a brief comment explaining the need for it (the more that its type being plain int is also suspicious).

This is an internal symbol that must be present because Xen is not linked against the run-time coverage library. It's described as an int here:

https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#using-the-profiling-runtime-without-static-initializers

Without this symbol linkage fails.

Quoted 19 lines

xen/common/coverage/llvm.c

Quoted 6 lines
xen/common/coverage/llvm.c new file +6 -0
+extern struct llvm_profile_data __start___llvm_prf_data;
+extern struct llvm_profile_data __stop___llvm_prf_data;
+extern uint64_t __start___llvm_prf_cnts;
+extern uint64_t __stop___llvm_prf_cnts;
+extern char __start___llvm_prf_names;
+extern char __stop___llvm_prf_names;

I guess all of these really want to have [] added, making ...

xen/common/coverage/llvm.c

Quoted 6 lines
xen/common/coverage/llvm.c new file +6 -0
+static void *start_data = &__start___llvm_prf_data;
+static void *end_data = &__stop___llvm_prf_data;
+static void *start_counters = &__start___llvm_prf_cnts;
+static void *end_counters = &__stop___llvm_prf_cnts;
+static void *start_names = &__start___llvm_prf_names;
+static void *end_names = &__stop___llvm_prf_names;

... the &s here unnecessary. But then - do these really need to be statics (rather than #define-s)?

Quoted 1 line

I would also guess that at least the names ones could be const.

Could make them defines indeed.

Quoted 6 lines

xen/common/coverage/llvm.c

Quoted 3 lines
xen/common/coverage/llvm.c new file +3 -0
+    APPEND_TO_BUFFER((char *)start_data, end_data - start_data);
+    APPEND_TO_BUFFER((char *)start_counters, end_counters - start_counters);
+    APPEND_TO_BUFFER((char *)start_names, end_names - start_names);

The casts should all be to const char*, and perhaps that would better be done inside the macro anyway.

Seems better indeed.

Quoted 9 lines

xen/include/public/sysctl.h struct xen_sysctl_scheduler_op { · line 647

Quoted 5 lines
xen/include/public/sysctl.h +0 -0
@@ -646,6 +646,12 @@ struct xen_sysctl_scheduler_op {
 
 #define XEN_GCOV_FORMAT_MAGIC    0x58434f56 /* XCOV */

Hmm, shouldn't the private magic #define-s actually be put here (in which case you'd indeed need to retain both 32- and 64-bit variants)?

I don't think so, here XEN_GCOV_FORMAT_MAGIC is a Xen specific gcov magic number.

OTOH LLVM_PROFILE_MAGIC_{64/32} is an llvm defined magic number, that's not under our control. Hence I don't think it should be exported in Xen public headers.

Roger.

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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#44 lore raw

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

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 08.11.17 at 09:56, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich

xen/include/public/sysctl.h struct xen_sysctl_scheduler_op { · line 647

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 26.10.17 at 11:19, <[email protected]> wrote:
xen/include/public/sysctl.h +0 -0
@@ -646,6 +646,12 @@ struct xen_sysctl_scheduler_op {
 
 #define XEN_GCOV_FORMAT_MAGIC    0x58434f56 /* XCOV */

Hmm, shouldn't the private magic #define-s actually be put here (in which case you'd indeed need to retain both 32- and 64-bit variants)?

Quoted 6 lines

I don't think so, here XEN_GCOV_FORMAT_MAGIC is a Xen specific gcov magic number.

OTOH LLVM_PROFILE_MAGIC_{64/32} is an llvm defined magic number, that's not under our control. Hence I don't think it should be exported in Xen public headers.

Okay.

Jan

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

#45 lore raw

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

- llvm-dev, since the code review can continue without that audience.

vedant

Quoted 22 lines · Jan Beulich via llvm-dev
Quoted 14 lines
Quoted 2 lines
Quoted 2 lines · On 08.11.17 at 09:56, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich

xen/include/public/sysctl.h struct xen_sysctl_scheduler_op { · line 647

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 26.10.17 at 11:19, <[email protected]> wrote:
xen/include/public/sysctl.h +0 -0
@@ -646,6 +646,12 @@ struct xen_sysctl_scheduler_op {
 
 #define XEN_GCOV_FORMAT_MAGIC    0x58434f56 /* XCOV */

Hmm, shouldn't the private magic #define-s actually be put here (in which case you'd indeed need to retain both 32- and 64-bit variants)?

Quoted 6 lines

I don't think so, here XEN_GCOV_FORMAT_MAGIC is a Xen specific gcov magic number.

OTOH LLVM_PROFILE_MAGIC_{64/32} is an llvm defined magic number, that's not under our control. Hence I don't think it should be exported in Xen public headers.

Quoted 8 lines

Okay.

Jan

_______________________________________________
LLVM Developers mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

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