Skip to contentSkip to conversation

Use C99 standard integer types

PATCH In review Bruce Cran 2 participants 4 messages Dec 15, 2010 Kbuild

lore
Share & tools
lore

Bruce Cran

author
#0 lore raw

PATCH 1/1 Use C99 standard integer types

Since most compilers now have a copy of the C99 inttypes.h header available, [u]intX_t types should be preferred over compiler-specific types such as __u32 etc. Using the standard types allows clang to build fio.

I've attached a patch which updates blktrace_api.h, blktrace.c and os/binject.h .

The patch also updates Makefile.FreeBSD to use the -pthread flag since it's preferred over -lpthread .

Signature · 1 line
Bruce Cran
Makefile.FreeBSD +1 -1
index 9378b19..005458d 100644
@@ -52,7 +52,7 @@ mandir = $(prefix)/man
 %.o: %.c
 	$(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $<
 fio: $(OBJS)
-	$(QUIET_CC)$(CC) $(CFLAGS) -o $@ $(filter %.o,$^) $(EXTLIBS) -lpthread -lm -lrt
+	$(QUIET_CC)$(CC) $(CFLAGS) -o $@ $(filter %.o,$^) $(EXTLIBS) -pthread -lm -lrt
 
 depend:
 	$(QUIET_DEP)$(CC) -MM $(ALL_CFLAGS) $(SOURCE) 1> .depend
blktrace.c +2 -1
index 297a8a9..822dbc7 100644
@@ -1,6 +1,7 @@
 /*
  * blktrace support code for fio
  */
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/stat.h>
@@ -176,7 +177,7 @@ static void trace_add_open_event(struct thread_data *td, int fileno)
 	flist_add_tail(&ipo->list, &td->io_log_list);
 }
 
-static void trace_add_file(struct thread_data *td, __u32 device)
+static void trace_add_file(struct thread_data *td, uint32_t device)
 {
 	static unsigned int last_maj, last_min;
 	unsigned int maj = FMAJOR(device);
blktrace_api.h +22 -22

68 lines not on this page · raw message

os/binject.h +9 -9
index 1d862c8..f31d910 100644
@@ -9,15 +9,15 @@
 #define BINJECT_VER_MASK	((1 << BINJECT_MAGIC_SHIFT) - 1)
 
 struct b_user_cmd {
-	__u16 magic;	/* INPUT */
-	__u16 type;	/* INPUT */
-	__u32 error;	/* OUTPUT */
-	__u32 flags;	/* INPUT */
-	__u32 len;	/* INPUT */
-	__u64 offset;	/* INPUT */
-	__u64 buf;	/* INPUT */
-	__u64 usr_ptr;	/* PASSED THROUGH */
-	__u64 nsec;	/* OUTPUT */
+	uint16_t magic;		/* INPUT */
+	uint16_t type;		/* INPUT */
+	uint32_t error;		/* OUTPUT */
+	uint32_t flags;		/* INPUT */
+	uint32_t len;		/* INPUT */
+	uint64_t offset;	/* INPUT */
+	uint64_t buf;		/* INPUT */
+	uint64_t usr_ptr;	/* PASSED THROUGH */
+	uint64_t nsec;		/* OUTPUT */
 };
 
 struct b_ioctl_cmd {
#1 lore raw
Quoted 7 lines · Bruce Cran

Since most compilers now have a copy of the C99 inttypes.h header available, [u]intX_t types should be preferred over compiler-specific types such as __u32 etc. Using the standard types allows clang to build fio.

I've attached a patch which updates blktrace_api.h, blktrace.c and os/binject.h .

Really blktrace_api.h should just go away, since it's an OS interface and should be exposed as such. We've traditionally always used __uxx types in those interfaces. You should not be picking that up on FreeBSD :-)

Quoted 2 lines

The patch also updates Makefile.FreeBSD to use the -pthread flag since it's preferred over -lpthread .

Thanks, I can make that change. In the future, it would be nice if you would separate different changes into different patches. Any time you need to write 'the patch also...' it's a hint that it should be split!

Signature · 1 line
Jens Axboe
author
#2 lore raw
Quoted 4 lines · On Wed, 15 Dec 2010 16:29:23 +0100 Jens Axboe <[email protected]> wrote:

Really blktrace_api.h should just go away, since it's an OS interface and should be exposed as such. We've traditionally always used __uxx types in those interfaces. You should not be picking that up on FreeBSD :-)

It looks like blktrace_api.h is being parsed through the depend rule in Makefile.[FreeBSD|NetBSD|mac] due to the headers being listed in $(SOURCE) - gcc just ignores missing <> headers while clang generates an error as it builds the dependency list. Since headers which are included within source files will be listed as a dependency anyway, I think they can be removed from $(SOURCE).

Signature · 1 line
Bruce Cran
Makefile.FreeBSD +1 -3
index 9378b19..02ff95d 100644
@@ -33,9 +33,7 @@ OBJS += engines/net.o
 SOURCE = eta.c filehash.c filesetup.c fio.c gettime.c init.c ioengines.c \
 	 io_u.c log.c memory.c mutex.c options.c parse.c rbtree.c smalloc.c \
 	 stat.c parse.c crc/*.c engines/cpu.c engines/mmap.c \
-	 engines/posixaio.c engines/sync.c engines/null.c engines/net.c \
-	 *.h arch/*.h compiler/*.h crc/*.h lib/*.h \
-	 os/indirect.h os/kcompat.h os/os-freebsd.h os/os.h os/syslet.h
+	 engines/posixaio.c engines/sync.c engines/null.c engines/net.c
 
 ifneq ($(findstring $(MAKEFLAGS),s),s)
 ifndef V
Makefile.NetBSD +1 -3
index 9378b19..02ff95d 100644
@@ -33,9 +33,7 @@ OBJS += engines/net.o
 SOURCE = eta.c filehash.c filesetup.c fio.c gettime.c init.c ioengines.c \
 	 io_u.c log.c memory.c mutex.c options.c parse.c rbtree.c smalloc.c \
 	 stat.c parse.c crc/*.c engines/cpu.c engines/mmap.c \
-	 engines/posixaio.c engines/sync.c engines/null.c engines/net.c \
-	 *.h arch/*.h compiler/*.h crc/*.h lib/*.h \
-	 os/indirect.h os/kcompat.h os/os-freebsd.h os/os.h os/syslet.h
+	 engines/posixaio.c engines/sync.c engines/null.c engines/net.c
 
 ifneq ($(findstring $(MAKEFLAGS),s),s)
 ifndef V
Makefile.mac +1 -2
index 25c7fde..3eb20be 100644
@@ -33,8 +33,7 @@ OBJS += engines/net.o
 SOURCE = eta.c filehash.c filesetup.c fio.c gettime.c init.c ioengines.c \
 	 io_u.c log.c memory.c mutex.c options.c parse.c rbtree.c smalloc.c \
 	 stat.c parse.c crc/*.c engines/cpu.c engines/mmap.c \
-	 engines/posixaio.c engines/sync.c engines/null.c engines/net.c \
-	 *.h */*.h
+	 engines/posixaio.c engines/sync.c engines/null.c engines/net.c
 
 ifneq ($(findstring $(MAKEFLAGS),s),s)
 ifndef V
#3 lore raw
Quoted 8 lines · Bruce Cran
Quoted 4 lines · On Wed, 15 Dec 2010 16:29:23 +0100 Jens Axboe <[email protected]> wrote:

Really blktrace_api.h should just go away, since it's an OS interface and should be exposed as such. We've traditionally always used __uxx types in those interfaces. You should not be picking that up on FreeBSD :-)

Quoted 6 lines

It looks like blktrace_api.h is being parsed through the depend rule in Makefile.[FreeBSD|NetBSD|mac] due to the headers being listed in $(SOURCE) - gcc just ignores missing <> headers while clang generates an error as it builds the dependency list. Since headers which are included within source files will be listed as a dependency anyway, I think they can be removed from $(SOURCE).

This looks good, thanks!

Signature · 1 line
Jens Axboe