All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] Use C99 standard integer types
@ 2010-12-15 15:09 Bruce Cran
  2010-12-15 15:29 ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Bruce Cran @ 2010-12-15 15:09 UTC (permalink / raw)
  To: fio

[-- Attachment #1: Type: text/plain, Size: 415 bytes --]

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 .

-- 
Bruce Cran

[-- Attachment #2: c99.diff --]
[-- Type: application/octet-stream, Size: 3970 bytes --]

diff --git a/Makefile.FreeBSD b/Makefile.FreeBSD
index 9378b19..005458d 100644
--- a/Makefile.FreeBSD
+++ b/Makefile.FreeBSD
@@ -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
diff --git a/blktrace.c b/blktrace.c
index 297a8a9..822dbc7 100644
--- a/blktrace.c
+++ b/blktrace.c
@@ -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);
diff --git a/blktrace_api.h b/blktrace_api.h
index 3df3347..78498bf 100644
--- a/blktrace_api.h
+++ b/blktrace_api.h
@@ -1,7 +1,7 @@
 #ifndef BLKTRACEAPI_H
 #define BLKTRACEAPI_H
 
-#include <asm/types.h>
+#include <inttypes.h>
 
 /*
  * Trace categories
@@ -92,39 +92,39 @@ enum blktrace_notify {
  * The trace itself
  */
 struct blk_io_trace {
-	__u32 magic;		/* MAGIC << 8 | version */
-	__u32 sequence;		/* event number */
-	__u64 time;		/* in nanoseconds */
-	__u64 sector;		/* disk offset */
-	__u32 bytes;		/* transfer length */
-	__u32 action;		/* what happened */
-	__u32 pid;		/* who did it */
-	__u32 device;		/* device identifier (dev_t) */
-	__u32 cpu;		/* on what cpu did it happen */
-	__u16 error;		/* completion error */
-	__u16 pdu_len;		/* length of data after this trace */
+	uint32_t magic;		/* MAGIC << 8 | version */
+	uint32_t sequence;	/* event number */
+	uint64_t time;		/* in nanoseconds */
+	uint64_t sector;	/* disk offset */
+	uint32_t bytes;		/* transfer length */
+	uint32_t action;	/* what happened */
+	uint32_t pid;		/* who did it */
+	uint32_t device;	/* device identifier (dev_t) */
+	uint32_t cpu;		/* on what cpu did it happen */
+	uint16_t error;		/* completion error */
+	uint16_t pdu_len;	/* length of data after this trace */
 };
 
 /*
  * The remap event
  */
 struct blk_io_trace_remap {
-	__u32 device;
-	__u32 device_from;
-	__u64 sector;
+	uint32_t device;
+	uint32_t device_from;
+	uint64_t sector;
 };
 
 /*
  * User setup structure passed with BLKSTARTTRACE
  */
 struct blk_user_trace_setup {
-	char name[32];			/* output */
-	__u16 act_mask;			/* input */
-	__u32 buf_size;			/* input */
-	__u32 buf_nr;			/* input */
-	__u64 start_lba;
-	__u64 end_lba;
-	__u32 pid;
+	char     name[32];		/* output */
+	uint16_t act_mask;		/* input */
+	uint32_t buf_size;		/* input */
+	uint32_t buf_nr;		/* input */
+	uint64_t start_lba;
+	uint64_t end_lba;
+	uint32_t pid;
 };
 
 #define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup)
diff --git a/os/binject.h b/os/binject.h
index 1d862c8..f31d910 100644
--- a/os/binject.h
+++ b/os/binject.h
@@ -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 {

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [patch] Use C99 standard integer types
  2010-12-15 15:09 [patch] Use C99 standard integer types Bruce Cran
@ 2010-12-15 15:29 ` Jens Axboe
  2010-12-15 16:37   ` Bruce Cran
  0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2010-12-15 15:29 UTC (permalink / raw)
  To: Bruce Cran; +Cc: fio

On 2010-12-15 16:09, Bruce Cran wrote:
> 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
:-)

> 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!

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] Use C99 standard integer types
  2010-12-15 15:29 ` Jens Axboe
@ 2010-12-15 16:37   ` Bruce Cran
  2010-12-15 18:30     ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Bruce Cran @ 2010-12-15 16:37 UTC (permalink / raw)
  To: Jens Axboe; +Cc: fio

[-- Attachment #1: Type: text/plain, Size: 717 bytes --]

On Wed, 15 Dec 2010 16:29:23 +0100
Jens Axboe <jaxboe@fusionio.com> 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).

-- 
Bruce Cran

[-- Attachment #2: Makefile.diff --]
[-- Type: application/octet-stream, Size: 1931 bytes --]

diff --git a/Makefile.FreeBSD b/Makefile.FreeBSD
index 9378b19..02ff95d 100644
--- a/Makefile.FreeBSD
+++ b/Makefile.FreeBSD
@@ -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
diff --git a/Makefile.NetBSD b/Makefile.NetBSD
index 9378b19..02ff95d 100644
--- a/Makefile.NetBSD
+++ b/Makefile.NetBSD
@@ -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
diff --git a/Makefile.mac b/Makefile.mac
index 25c7fde..3eb20be 100644
--- a/Makefile.mac
+++ b/Makefile.mac
@@ -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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [patch] Use C99 standard integer types
  2010-12-15 16:37   ` Bruce Cran
@ 2010-12-15 18:30     ` Jens Axboe
  0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2010-12-15 18:30 UTC (permalink / raw)
  To: Bruce Cran; +Cc: fio

On 2010-12-15 17:37, Bruce Cran wrote:
> On Wed, 15 Dec 2010 16:29:23 +0100
> Jens Axboe <jaxboe@fusionio.com> 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).

This looks good, thanks!

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-12-15 18:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-15 15:09 [patch] Use C99 standard integer types Bruce Cran
2010-12-15 15:29 ` Jens Axboe
2010-12-15 16:37   ` Bruce Cran
2010-12-15 18:30     ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.