[libvirt] [PATCH] Make use of PERF_COUNT_HW_REF_CPU_CYCLES conditional

The PERF_COUNT_HW_REF_CPU_CYCLES constant is not available on all Linux distros libvirt targets, so its use must be made conditional. Other constant have existed long enough that we can assume they exist, as we don't support very old distros like RHEL-5 any more. Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/util/virperf.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/util/virperf.c b/src/util/virperf.c index 49ec258..f64692b 100644 --- a/src/util/virperf.c +++ b/src/util/virperf.c @@ -104,8 +104,14 @@ static struct virPerfEventAttr attrs[] = { .attrType = PERF_TYPE_HARDWARE, .attrConfig = PERF_COUNT_HW_STALLED_CYCLES_BACKEND}, {.type = VIR_PERF_EVENT_REF_CPU_CYCLES, +# ifdef PERF_COUNT_HW_REF_CPU_CYCLES .attrType = PERF_TYPE_HARDWARE, - .attrConfig = PERF_COUNT_HW_REF_CPU_CYCLES}, + .attrConfig = PERF_COUNT_HW_REF_CPU_CYCLES +# else + .attrType = 0, + .attrConfig = 0, +# endif + }, }; typedef struct virPerfEventAttr *virPerfEventAttrPtr; -- 2.9.3

On Fri, Dec 16, 2016 at 10:47:22AM +0000, Daniel P. Berrange wrote:
The PERF_COUNT_HW_REF_CPU_CYCLES constant is not available on all Linux distros libvirt targets, so its use must be made conditional. Other constant have existed long enough that we can assume they exist, as we don't support very old distros like RHEL-5 any more.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/util/virperf.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Opps, forgot to annotate that I pushed this as a build breaker fix for Debian
diff --git a/src/util/virperf.c b/src/util/virperf.c index 49ec258..f64692b 100644 --- a/src/util/virperf.c +++ b/src/util/virperf.c @@ -104,8 +104,14 @@ static struct virPerfEventAttr attrs[] = { .attrType = PERF_TYPE_HARDWARE, .attrConfig = PERF_COUNT_HW_STALLED_CYCLES_BACKEND}, {.type = VIR_PERF_EVENT_REF_CPU_CYCLES, +# ifdef PERF_COUNT_HW_REF_CPU_CYCLES .attrType = PERF_TYPE_HARDWARE, - .attrConfig = PERF_COUNT_HW_REF_CPU_CYCLES}, + .attrConfig = PERF_COUNT_HW_REF_CPU_CYCLES +# else + .attrType = 0, + .attrConfig = 0, +# endif + }, }; typedef struct virPerfEventAttr *virPerfEventAttrPtr;
Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :|

On Fri, Dec 16, Daniel P. Berrange wrote:
The PERF_COUNT_HW_REF_CPU_CYCLES constant is not available on all Linux distros libvirt targets, so its use must be made conditional. Other constant have existed long enough that we can assume they exist, as we don't support very old distros like RHEL-5 any more.
+# ifdef PERF_COUNT_HW_REF_CPU_CYCLES
How can this fix the error? This and PERF_COUNT_HW_STALLED_CYCLES_FRONTEND/BACKEND are part of an 'enum', which is ordinary code for cpp. Unfortunately this is correct because the code is written in C, not CPP. I will deal with the compile errors like that: Index: libvirt-20170308T173307.d7dcea6/src/util/virperf.c =================================================================== --- libvirt-20170308T173307.d7dcea6.orig/src/util/virperf.c +++ libvirt-20170308T173307.d7dcea6/src/util/virperf.c @@ -76,6 +76,12 @@ struct virPerfEventAttr { unsigned long long attrConfig; }; +#ifndef PERF_ATTR_SIZE_VER2 +#define PERF_COUNT_HW_STALLED_CYCLES_FRONTEND 7 +#define PERF_COUNT_HW_STALLED_CYCLES_BACKEND 8 +#define PERF_COUNT_HW_REF_CPU_CYCLES 9 +#endif + static struct virPerfEventAttr attrs[] = { {.type = VIR_PERF_EVENT_CMT, .attrType = 0, .attrConfig = 1}, {.type = VIR_PERF_EVENT_MBMT, .attrType = 0, .attrConfig = 2}, Olaf
participants (2)
-
Daniel P. Berrange
-
Olaf Hering