Fix fd leak in cache line checking
[fio.git] / os / os-linux.h
index a2a9b249305863e0ba45cd0b96d4f1d6cdd39085..b766cbf9503af73a144e5cddf1f542ed8e13e3b4 100644 (file)
@@ -6,6 +6,7 @@
 #include <sys/syscall.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <errno.h>
 #include <linux/unistd.h>
 #include <linux/raw.h>
 #include <linux/major.h>
@@ -29,6 +30,7 @@
 #define FIO_HAVE_FALLOCATE
 #define FIO_HAVE_POSIXAIO_FSYNC
 #define FIO_HAVE_PSHARED_MUTEX
+#define FIO_HAVE_CL_SIZE
 
 #define OS_MAP_ANON            MAP_ANONYMOUS
 
@@ -248,4 +250,26 @@ static inline int fio_lookup_raw(dev_t dev, int *majdev, int *mindev)
 #define FIO_O_NOATIME  0
 #endif
 
+#define CACHE_LINE_FILE        \
+       "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
+
+static inline int arch_cache_line_size(void)
+{
+       char size[32];
+       int fd, ret;
+
+       fd = open(CACHE_LINE_FILE, O_RDONLY);
+       if (fd < 0)
+               return -1;
+
+       ret = read(fd, size, sizeof(size));
+
+       close(fd);
+
+       if (ret <= 0)
+               return -1;
+       else
+               return atoi(size);
+}
+
 #endif