[PATCH i-g-t 3/9] lib/perf: Fix data types and general tidy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx>

Configuration and format are uint64_t in the perf API.

Tidy some other details as well.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx>
---
 lib/igt_perf.c | 40 +++++++++++++++++++---------------------
 lib/igt_perf.h |  4 ++--
 2 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/lib/igt_perf.c b/lib/igt_perf.c
index 961a858af9e3..208474302fcc 100644
--- a/lib/igt_perf.c
+++ b/lib/igt_perf.c
@@ -9,49 +9,47 @@
 
 uint64_t i915_type_id(void)
 {
-	char buf[1024];
-	int fd, n;
-
-	fd = open("/sys/bus/event_source/devices/i915/type", 0);
-	if (fd < 0) {
-		n = -1;
-	} else {
-		n = read(fd, buf, sizeof(buf)-1);
-		close(fd);
-	}
-	if (n < 0)
+	char buf[64];
+	ssize_t ret;
+	int fd;
+
+	fd = open("/sys/bus/event_source/devices/i915/type", O_RDONLY);
+	if (fd < 0)
+		return 0;
+
+	ret = read(fd, buf, sizeof(buf) - 1);
+	close(fd);
+	if (ret < 1)
 		return 0;
 
-	buf[n] = '\0';
-	return strtoull(buf, 0, 0);
+	buf[ret] = '\0';
+
+	return strtoull(buf, NULL, 0);
 }
 
-static int _perf_open(int config, int group, int format)
+static int _perf_open(uint64_t config, int group, uint64_t format)
 {
-	struct perf_event_attr attr;
-
-	memset(&attr, 0, sizeof (attr));
+	struct perf_event_attr attr = { };
 
 	attr.type = i915_type_id();
 	if (attr.type == 0)
 		return -ENOENT;
 
-	attr.config = config;
-
 	if (group >= 0)
 		format &= ~PERF_FORMAT_GROUP;
 
 	attr.read_format = format;
+	attr.config = config;
 
 	return perf_event_open(&attr, -1, 0, group, 0);
 }
 
-int perf_i915_open(int config)
+int perf_i915_open(uint64_t config)
 {
 	return _perf_open(config, -1, PERF_FORMAT_TOTAL_TIME_ENABLED);
 }
 
-int perf_i915_open_group(int config, int group)
+int perf_i915_open_group(uint64_t config, int group)
 {
 	return _perf_open(config, group,
 			  PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_GROUP);
diff --git a/lib/igt_perf.h b/lib/igt_perf.h
index 8e674c3a3755..cc10cb300aaf 100644
--- a/lib/igt_perf.h
+++ b/lib/igt_perf.h
@@ -62,7 +62,7 @@ perf_event_open(struct perf_event_attr *attr,
 }
 
 uint64_t i915_type_id(void);
-int perf_i915_open(int config);
-int perf_i915_open_group(int config, int group);
+int perf_i915_open(uint64_t config);
+int perf_i915_open_group(uint64_t config, int group);
 
 #endif /* I915_PERF_H */
-- 
2.9.5

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux