]> git.proxmox.com Git - mirror_ovs.git/blobdiff - lib/perf-counter.c
dpctl: Add the option 'pmd' for dump-flows.
[mirror_ovs.git] / lib / perf-counter.c
index b700e492bcc8be82b1dd5f8f435be7d4b4d109b3..402fabe1775b22d832cd9e94f20cbaee09c431d5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Nicira, Inc.
+ * Copyright (c) 2015, 2016, 2019 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,7 +15,9 @@
  */
 
 /* This implementation only applies to the Linux platform.  */
-#ifdef __linux__
+
+#include <config.h>
+#if defined(__linux__) && defined(HAVE_LINUX_PERF_EVENT_H) && !__CHECKER__
 
 #include <stddef.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #include <linux/perf_event.h>
 #include <asm/unistd.h>
-#include <config.h>
-#include "dynamic-string.h"
-#include "openvswitch/vlog.h"
+#include "openvswitch/dynamic-string.h"
 #include "perf-counter.h"
-#include "shash.h"
+#include "openvswitch/shash.h"
 #include "util.h"
 
-VLOG_DEFINE_THIS_MODULE(perf_counter);
-
-static struct shash perf_counters;
+static struct shash perf_counters = SHASH_INITIALIZER(&perf_counters);
 static int fd__ = 0;
 
 uint64_t
 perf_counter_read(uint64_t *counter)
 {
-    size_t size = sizeof *counter;
+    int size = sizeof *counter;
 
     if (fd__ <= 0 || read(fd__, counter, size) < size) {
         *counter = 0;
@@ -75,9 +73,7 @@ perf_event_setup(void)
     pe.exclude_hv = 1;
 
     fd__ = perf_event_open(&pe, 0, -1, -1, 0);
-    if (fd__ == -1) {
-        VLOG_INFO("Peformance counter is not available on this platform.");
-    } else {
+    if (fd__ > 0) {
         ioctl(fd__, PERF_EVENT_IOC_RESET, 0);
         ioctl(fd__, PERF_EVENT_IOC_ENABLE, 0);
     }
@@ -150,7 +146,7 @@ perf_counters_to_ds(struct ds *ds)
  * Caller is responsible for free memory.
  */
 char *
-perf_counters_to_string()
+perf_counters_to_string(void)
 {
     struct ds ds;
 
@@ -180,7 +176,7 @@ perf_counters_clear(void)
 }
 
 void
-perf_counters_destroy()
+perf_counters_destroy(void)
 {
     struct shash_node *node, *next;