I have modified test_fsync to use modular C so there is less duplicate
code and it can be enhanced easier.  Applied patch attached, though the
diff is larger than the C file so you might want to just look at the C
file in git.

-- 
  Bruce Momjian  <br...@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +
diff --git a/src/tools/fsync/README b/src/tools/fsync/README
index a1c2ae4..5bf6f1f 100644
*** /tmp/pgdiff.20499/6PmS7d_README	Sat Jan 15 14:41:11 2011
--- src/tools/fsync/README	Sat Jan 15 14:20:47 2011
*************** test_fsync
*** 3,9 ****
  
  This program tests fsync.  The tests are described as part of the program output.
  
! 	Usage:	test_fsync [-f filename] [loops]
  	
  test_fsync is intended to give you a reasonable idea of what the fastest
  fsync_method is on your specific system, as well as supplying diagnostic
--- 3,9 ----
  
  This program tests fsync.  The tests are described as part of the program output.
  
! 	Usage:	test_fsync [-f filename] [ops_per_test]
  	
  test_fsync is intended to give you a reasonable idea of what the fastest
  fsync_method is on your specific system, as well as supplying diagnostic
*************** The output filename defaults to test_fsy
*** 16,20 ****
  test_fsync should be run in the same filesystem as your transaction log
  directory (pg_xlog).
  
! Loops default to 2000.  Increase this to get more accurate measurements.
  
--- 16,21 ----
  test_fsync should be run in the same filesystem as your transaction log
  directory (pg_xlog).
  
! Ops-per-test defaults to 2000.  Increase this to get more accurate
! measurements.
  
diff --git a/src/tools/fsync/test_fsync.c b/src/tools/fsync/test_fsync.c
index ebfd5fd..ce59afa 100644
*** /tmp/pgdiff.20499/aaqVod_test_fsync.c	Sat Jan 15 14:41:11 2011
--- src/tools/fsync/test_fsync.c	Sat Jan 15 14:36:45 2011
***************
*** 22,27 ****
--- 22,28 ----
  #include <unistd.h>
  #include <string.h>
  
+ 
  /* 
   * put the temp files in the local directory
   * unless the user specifies otherwise 
***************
*** 34,54 ****
  #define NA_FORMAT		LABEL_FORMAT "%18s"
  
  
! int			loops = 2000;
  
! void		die(char *str);
  void		print_elapse(struct timeval start_t, struct timeval stop_t);
  
  int
  main(int argc, char *argv[])
  {
! 	struct timeval start_t, stop_t;
! 	int			tmpfile, i;
! 	char	   *full_buf = (char *) malloc(XLOG_SEG_SIZE),
! 			   *buf, *filename = FSYNC_FILENAME;
  
  	/* 
! 	 * arguments: loops and filename (optional) 
  	 */
  	if (argc > 2 && strcmp(argv[1], "-f") == 0)
  	{
--- 35,93 ----
  #define NA_FORMAT		LABEL_FORMAT "%18s"
  
  
! int			ops_per_test = 2000;
! char	    full_buf[XLOG_SEG_SIZE], *buf, *filename = FSYNC_FILENAME;
! struct timeval start_t, stop_t;
  
! 
! void		handle_args(int argc, char *argv[]);
! void		prepare_buf(void);
! void		test_open(void);
! void		test_non_sync(void);
! void		test_sync(int writes_per_op);
! void		test_open_syncs(void);
! void		test_file_descriptor_sync(void);
  void		print_elapse(struct timeval start_t, struct timeval stop_t);
+ void		die(char *str);
+ 
  
  int
  main(int argc, char *argv[])
  {
! 	handle_args(argc, argv);
! 	
! 	prepare_buf();
! 
! 	test_open();
! 	
! 	test_non_sync();
! 	
! 	/* Test using 1 8k write */
! 	test_sync(1);
! 
! 	/* Test using 2 8k writes */
! 	test_sync(2);
! 	
! 	test_open_syncs();
! 
! 	test_file_descriptor_sync();
! 	
! 	unlink(filename);
! 
! 	return 0;
! }
  
+ void
+ handle_args(int argc, char *argv[])
+ {
+ 	if (argc > 1 && strcmp(argv[1], "-h") == 0)
+ 	{
+ 		fprintf(stderr, "test_fsync [-f filename] [ops-per-test]\n");
+ 		exit(1);
+ 	}
+ 	
  	/* 
! 	 * arguments: ops_per_test and filename (optional) 
  	 */
  	if (argc > 2 && strcmp(argv[1], "-f") == 0)
  	{
*************** main(int argc, char *argv[])
*** 58,67 ****
  	}
  
  	if (argc > 1) 
! 		loops = atoi(argv[1]);
  
! 	for (i = 0; i < XLOG_SEG_SIZE; i++)
! 		full_buf[i] = random();
  
  	/* 
  	 * test if we can open the target file 
--- 97,123 ----
  	}
  
  	if (argc > 1) 
! 		ops_per_test = atoi(argv[1]);
  
! 	printf("Ops-per-test = %d\n\n", ops_per_test);
! }
! 
! void
! prepare_buf(void)
! {
! 	int			ops;
! 
! 	/* write random data into buffer */
! 	for (ops = 0; ops < XLOG_SEG_SIZE; ops++)
! 		full_buf[ops] = random();
! 
! 	buf = (char *) TYPEALIGN(ALIGNOF_XLOG_BUFFER, full_buf);
! }
! 
! void
! test_open(void)
! {
! 	int			tmpfile;
  
  	/* 
  	 * test if we can open the target file 
*************** main(int argc, char *argv[])
*** 70,94 ****
  		die("Cannot open output file.");
  	if (write(tmpfile, full_buf, XLOG_SEG_SIZE) != XLOG_SEG_SIZE)
  		die("write failed");
! 	/*
! 	 * fsync now so that dirty buffers don't skew later tests
! 	 */
  	if (fsync(tmpfile) != 0)
  		die("fsync failed");
- 	close(tmpfile);
  
! 	buf = (char *) TYPEALIGN(ALIGNOF_XLOG_BUFFER, full_buf);
  
! 	printf("Loops = %d\n\n", loops);
  
  	/*
  	 * Test a simple write without fsync
  	 */
! 	printf("Simple write:\n");
  	printf(LABEL_FORMAT, "8k write");
  	fflush(stdout);
  	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
  	{
  		if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
  			die("Cannot open output file.");
--- 126,153 ----
  		die("Cannot open output file.");
  	if (write(tmpfile, full_buf, XLOG_SEG_SIZE) != XLOG_SEG_SIZE)
  		die("write failed");
! 
! 	/* fsync now so that dirty buffers don't skew later tests */
  	if (fsync(tmpfile) != 0)
  		die("fsync failed");
  
! 	close(tmpfile);
! }
  
! void
! test_non_sync(void)
! {
! 	int			tmpfile, ops;
  
  	/*
  	 * Test a simple write without fsync
  	 */
! 	printf("Simple non-sync'ed write:\n");
  	printf(LABEL_FORMAT, "8k write");
  	fflush(stdout);
+ 
  	gettimeofday(&start_t, NULL);
! 	for (ops = 0; ops < ops_per_test; ops++)
  	{
  		if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
  			die("Cannot open output file.");
*************** main(int argc, char *argv[])
*** 98,122 ****
  	}
  	gettimeofday(&stop_t, NULL);
  	print_elapse(start_t, stop_t);
  
! 	/*
! 	 * Test all fsync methods using single 8k writes
! 	 */
! 	printf("\nCompare file sync methods using one write:\n");
  
  	/*
  	 * Test open_datasync if available
  	 */
  #ifdef OPEN_DATASYNC_FLAG
! 	printf(LABEL_FORMAT, "open_datasync 8k write");
  	fflush(stdout);
  	if ((tmpfile = open(filename, O_RDWR | O_DSYNC, 0)) == -1)
  		die("Cannot open output file.");
  	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
  	{
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
  		if (lseek(tmpfile, 0, SEEK_SET) == -1)
  			die("seek failed");
  	}
--- 157,193 ----
  	}
  	gettimeofday(&stop_t, NULL);
  	print_elapse(start_t, stop_t);
+ }
  
! void
! test_sync(int writes_per_op)
! {
! 	int			tmpfile, ops, writes;
! 
! 	if (writes_per_op == 1)
! 		printf("\nCompare file sync methods using one write:\n");
! 	else
! 		printf("\nCompare file sync methods using two writes:\n");
! 	printf("(in wal_sync_method preference order)\n");
  
  	/*
  	 * Test open_datasync if available
  	 */
  #ifdef OPEN_DATASYNC_FLAG
! 	if (writes_per_op == 1)
! 		printf(LABEL_FORMAT, "open_datasync 8k write");
! 	else
! 	 	printf(LABEL_FORMAT, "2 open_datasync 8k writes");
  	fflush(stdout);
+ 
  	if ((tmpfile = open(filename, O_RDWR | O_DSYNC, 0)) == -1)
  		die("Cannot open output file.");
  	gettimeofday(&start_t, NULL);
! 	for (ops = 0; ops < ops_per_test; ops++)
  	{
! 		for (writes = 0; writes < writes_per_op; writes++)
! 			if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 				die("write failed");
  		if (lseek(tmpfile, 0, SEEK_SET) == -1)
  			die("seek failed");
  	}
*************** main(int argc, char *argv[])
*** 128,144 ****
  	 * If O_DIRECT is enabled, test that with open_datasync
  	 */
  #if PG_O_DIRECT != 0
- 	fflush(stdout);
  	if ((tmpfile = open(filename, O_RDWR | O_DSYNC | PG_O_DIRECT, 0)) == -1)
  		printf(NA_FORMAT, "o_direct", "n/a on this filesystem\n");
  	else
  	{
! 		printf(LABEL_FORMAT, "open_datasync 8k direct I/O write");
  		gettimeofday(&start_t, NULL);
! 		for (i = 0; i < loops; i++)
  		{
! 			if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 				die("write failed");
  			if (lseek(tmpfile, 0, SEEK_SET) == -1)
  				die("seek failed");
  		}
--- 199,220 ----
  	 * If O_DIRECT is enabled, test that with open_datasync
  	 */
  #if PG_O_DIRECT != 0
  	if ((tmpfile = open(filename, O_RDWR | O_DSYNC | PG_O_DIRECT, 0)) == -1)
  		printf(NA_FORMAT, "o_direct", "n/a on this filesystem\n");
  	else
  	{
! 		if (writes_per_op == 1)
! 			printf(LABEL_FORMAT, "open_datasync 8k direct I/O write");
! 		else
! 			printf(LABEL_FORMAT, "2 open_datasync 8k direct I/O writes");
! 		fflush(stdout);
! 
  		gettimeofday(&start_t, NULL);
! 		for (ops = 0; ops < ops_per_test; ops++)
  		{
! 			for (writes = 0; writes < writes_per_op; writes++)
! 				if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 					die("write failed");
  			if (lseek(tmpfile, 0, SEEK_SET) == -1)
  				die("seek failed");
  		}
*************** main(int argc, char *argv[])
*** 155,222 ****
  #endif
  
  /*
-  * Test open_sync if available
-  */
- #ifdef OPEN_SYNC_FLAG
- 	printf(LABEL_FORMAT, "open_sync 8k write");
- 	fflush(stdout);
- 	if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG, 0)) == -1)
- 		die("Cannot open output file.");
- 	gettimeofday(&start_t, NULL);
- 	for (i = 0; i < loops; i++)
- 	{
- 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
- 			die("write failed");
- 		if (lseek(tmpfile, 0, SEEK_SET) == -1)
- 			die("seek failed");
- 	}
- 	gettimeofday(&stop_t, NULL);
- 	close(tmpfile);
- 	print_elapse(start_t, stop_t);
- 
- 	/*
- 	 * If O_DIRECT is enabled, test that with open_sync
- 	 */
- #if PG_O_DIRECT != 0
- 	printf(LABEL_FORMAT, "open_sync 8k direct I/O write");
- 	fflush(stdout);
- 	if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG | PG_O_DIRECT, 0)) == -1)
- 		printf(NA_FORMAT, "o_direct", "n/a on this filesystem\n");
- 	else
- 	{
- 		gettimeofday(&start_t, NULL);
- 		for (i = 0; i < loops; i++)
- 		{
- 			if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
- 				die("write failed");
- 			if (lseek(tmpfile, 0, SEEK_SET) == -1)
- 				die("seek failed");
- 		}
- 		gettimeofday(&stop_t, NULL);
- 		close(tmpfile);
- 		print_elapse(start_t, stop_t);
- 	}
- #else
- 	printf(NA_FORMAT, "o_direct", "n/a\n");
- #endif
- 
- #else
- 	printf(NA_FORMAT, "open_sync", "n/a\n");
- #endif
- 
- /*
   * Test fdatasync if available
   */
  #ifdef HAVE_FDATASYNC
! 	printf(LABEL_FORMAT, "8k write, fdatasync");
  	fflush(stdout);
  	if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
  		die("Cannot open output file.");
  	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
  	{
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
  		fdatasync(tmpfile);
  		if (lseek(tmpfile, 0, SEEK_SET) == -1)
  			die("seek failed");
--- 231,253 ----
  #endif
  
  /*
   * Test fdatasync if available
   */
  #ifdef HAVE_FDATASYNC
! 	if (writes_per_op == 1)
! 		printf(LABEL_FORMAT, "8k write, fdatasync");
! 	else
! 		printf(LABEL_FORMAT, "8k write, 8k write, fdatasync");
  	fflush(stdout);
+ 
  	if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
  		die("Cannot open output file.");
  	gettimeofday(&start_t, NULL);
! 	for (ops = 0; ops < ops_per_test; ops++)
  	{
! 		for (writes = 0; writes < writes_per_op; writes++)
! 			if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 				die("write failed");
  		fdatasync(tmpfile);
  		if (lseek(tmpfile, 0, SEEK_SET) == -1)
  			die("seek failed");
*************** main(int argc, char *argv[])
*** 231,245 ****
  /*
   * Test fsync
   */
! 	printf(LABEL_FORMAT, "8k write, fsync");
  	fflush(stdout);
  	if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
  		die("Cannot open output file.");
  	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
  	{
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
  		if (fsync(tmpfile) != 0)
  			die("fsync failed");
  		if (lseek(tmpfile, 0, SEEK_SET) == -1)
--- 262,281 ----
  /*
   * Test fsync
   */
! 	if (writes_per_op == 1)
! 		printf(LABEL_FORMAT, "8k write, fsync");
! 	else
! 		printf(LABEL_FORMAT, "8k write, 8k write, fsync");
  	fflush(stdout);
+ 
  	if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
  		die("Cannot open output file.");
  	gettimeofday(&start_t, NULL);
! 	for (ops = 0; ops < ops_per_test; ops++)
  	{
! 		for (writes = 0; writes < writes_per_op; writes++)
! 			if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 				die("write failed");
  		if (fsync(tmpfile) != 0)
  			die("fsync failed");
  		if (lseek(tmpfile, 0, SEEK_SET) == -1)
*************** main(int argc, char *argv[])
*** 253,267 ****
   * If fsync_writethrough is available, test as well
   */	
  #ifdef HAVE_FSYNC_WRITETHROUGH
! 	printf(LABEL_FORMAT, "8k write, fsync_writethrough");
  	fflush(stdout);
  	if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
  		die("Cannot open output file.");
  	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
  	{
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
  		if (fcntl(tmpfile, F_FULLFSYNC ) != 0)
  			die("fsync failed");
  		if (lseek(tmpfile, 0, SEEK_SET) == -1)
--- 289,308 ----
   * If fsync_writethrough is available, test as well
   */	
  #ifdef HAVE_FSYNC_WRITETHROUGH
! 	if (writes_per_op == 1)
! 		printf(LABEL_FORMAT, "8k write, fsync_writethrough");
! 	else
! 		printf(LABEL_FORMAT, "8k write, 8k write, fsync_writethrough");
  	fflush(stdout);
+ 
  	if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
  		die("Cannot open output file.");
  	gettimeofday(&start_t, NULL);
! 	for (ops = 0; ops < ops_per_test; ops++)
  	{
! 		for (writes = 0; writes < writes_per_op; writes++)
! 			if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 				die("write failed");
  		if (fcntl(tmpfile, F_FULLFSYNC ) != 0)
  			die("fsync failed");
  		if (lseek(tmpfile, 0, SEEK_SET) == -1)
*************** main(int argc, char *argv[])
*** 274,373 ****
  	printf(NA_FORMAT, "fsync_writethrough", "n/a\n");
  #endif
  
- 	/*
- 	 * Compare some of the file sync methods with 
- 	 * two 8k writes to see if timing is different
- 	 */
- 	printf("\nCompare file sync methods using two writes:\n");
- 
  /*
!  * Test open_datasync with and without o_direct
!  */
! #ifdef OPEN_DATASYNC_FLAG
!  	printf(LABEL_FORMAT, "2 open_datasync 8k writes");
! 	fflush(stdout);
! 	if ((tmpfile = open(filename, O_RDWR | O_DSYNC, 0)) == -1)
! 		die("Cannot open output file.");
! 	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
! 	{
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
! 		if (lseek(tmpfile, 0, SEEK_SET) == -1)
! 			die("seek failed");
! 	}
! 	gettimeofday(&stop_t, NULL);
! 	close(tmpfile);
! 	print_elapse(start_t, stop_t);
! 	
! #if PG_O_DIRECT != 0
! 	printf(LABEL_FORMAT, "2 open_datasync direct I/O 8k writes");
! 	fflush(stdout);
! 	if ((tmpfile = open(filename, O_RDWR | O_DSYNC | PG_O_DIRECT, 0)) == -1)
! 		die("Cannot open output file.");
! 	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
! 	{
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
! 		if (lseek(tmpfile, 0, SEEK_SET) == -1)
! 			die("seek failed");
! 	}
! 	gettimeofday(&stop_t, NULL);
! 	close(tmpfile);
! 	print_elapse(start_t, stop_t);
! #else
! 		printf(NA_FORMAT, "o_direct" "n/a\n");
! #endif
! 
! #else
! 	printf(NA_FORMAT, "open_datasync", "n/a\n");
! #endif
! 
! /*
!  * Test open_sync with and without o_direct
   */
  #ifdef OPEN_SYNC_FLAG
! 	printf(LABEL_FORMAT, "2 open_sync 8k writes");
  	fflush(stdout);
  	if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG, 0)) == -1)
  		die("Cannot open output file.");
  	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
  	{
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
  		if (lseek(tmpfile, 0, SEEK_SET) == -1)
  			die("seek failed");
  	}
  	gettimeofday(&stop_t, NULL);
  	close(tmpfile);
  	print_elapse(start_t, stop_t);
! 	
  #if PG_O_DIRECT != 0
! 	printf(LABEL_FORMAT, "2 open_sync direct I/O 8k writes");
  	fflush(stdout);
  	if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG | PG_O_DIRECT, 0)) == -1)
! 		die("Cannot open output file.");
! 	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
  	{
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
! 		if (lseek(tmpfile, 0, SEEK_SET) == -1)
! 			die("seek failed");
  	}
- 	gettimeofday(&stop_t, NULL);
- 	close(tmpfile);
- 	print_elapse(start_t, stop_t);
  #else
  	printf(NA_FORMAT, "o_direct", "n/a\n");
  #endif
--- 315,372 ----
  	printf(NA_FORMAT, "fsync_writethrough", "n/a\n");
  #endif
  
  /*
!  * Test open_sync if available
   */
  #ifdef OPEN_SYNC_FLAG
! 	if (writes_per_op == 1)
! 		printf(LABEL_FORMAT, "open_sync 8k write");
! 	else
! 		printf(LABEL_FORMAT, "2 open_sync 8k writes");
  	fflush(stdout);
+ 
  	if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG, 0)) == -1)
  		die("Cannot open output file.");
  	gettimeofday(&start_t, NULL);
! 	for (ops = 0; ops < ops_per_test; ops++)
  	{
! 		for (writes = 0; writes < writes_per_op; writes++)
! 			if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 				die("write failed");
  		if (lseek(tmpfile, 0, SEEK_SET) == -1)
  			die("seek failed");
  	}
  	gettimeofday(&stop_t, NULL);
  	close(tmpfile);
  	print_elapse(start_t, stop_t);
! 
! 	/*
! 	 * If O_DIRECT is enabled, test that with open_sync
! 	 */
  #if PG_O_DIRECT != 0
! 	if (writes_per_op == 1)
! 		printf(LABEL_FORMAT, "open_sync 8k direct I/O write");
! 	else
! 		printf(LABEL_FORMAT, "2 open_sync 8k direct I/O writes");
  	fflush(stdout);
+ 
  	if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG | PG_O_DIRECT, 0)) == -1)
! 		printf(NA_FORMAT, "o_direct", "n/a on this filesystem\n");
! 	else
  	{
! 		gettimeofday(&start_t, NULL);
! 		for (ops = 0; ops < ops_per_test; ops++)
! 		{
! 			for (writes = 0; writes < writes_per_op; writes++)
! 				if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 					die("write failed");
! 			if (lseek(tmpfile, 0, SEEK_SET) == -1)
! 				die("seek failed");
! 		}
! 		gettimeofday(&stop_t, NULL);
! 		close(tmpfile);
! 		print_elapse(start_t, stop_t);
  	}
  #else
  	printf(NA_FORMAT, "o_direct", "n/a\n");
  #endif
*************** main(int argc, char *argv[])
*** 375,456 ****
  #else
  	printf(NA_FORMAT, "open_sync", "n/a\n");
  #endif
  
! /*
!  *	Test fdatasync
!  */
! #ifdef HAVE_FDATASYNC
! 	printf(LABEL_FORMAT, "8k write, 8k write, fdatasync");
! 	fflush(stdout);
! 	if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
! 		die("Cannot open output file.");
! 	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
! 	{
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
! 		fdatasync(tmpfile);
! 		if (lseek(tmpfile, 0, SEEK_SET) == -1)
! 			die("seek failed");
! 	}
! 	gettimeofday(&stop_t, NULL);
! 	close(tmpfile);
! 	print_elapse(start_t, stop_t);
! #else
! 	printf(NA_FORMAT, "fdatasync", "n/a\n");
! #endif
! 
! /*
!  * Test basic fsync
!  */
! 	printf(LABEL_FORMAT, "8k write, 8k write, fsync");
! 	fflush(stdout);
! 	if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
! 		die("Cannot open output file.");
! 	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
! 	{
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
! 		if (fsync(tmpfile) != 0)
! 			die("fsync failed");
! 		if (lseek(tmpfile, 0, SEEK_SET) == -1)
! 			die("seek failed");
! 	}
! 	gettimeofday(&stop_t, NULL);
! 	close(tmpfile);
! 	print_elapse(start_t, stop_t);
! 	
! /*
!  * Test fsync_writethrough if available
!  */	
! #ifdef HAVE_FSYNC_WRITETHROUGH
! 	printf(LABEL_FORMAT, "8k write, 8k write, fsync_writethrough");
! 	fflush(stdout);
! 	if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
! 		die("Cannot open output file.");
! 	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
! 	{
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
! 		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
! 			die("write failed");
! 		if (fcntl(tmpfile, F_FULLFSYNC) != 0)
! 			die("fsync failed");
! 		if (lseek(tmpfile, 0, SEEK_SET) == -1)
! 			die("seek failed");
! 	}
! 	gettimeofday(&stop_t, NULL);
! 	close(tmpfile);
! 	print_elapse(start_t, stop_t);
! #else
! 	printf(NA_FORMAT, "fsync_writethrough", "n/a\n");
! #endif
  
  	/*
  	 * Compare 1 to 2 writes
--- 374,385 ----
  #else
  	printf(NA_FORMAT, "open_sync", "n/a\n");
  #endif
+ }
  
! void
! test_open_syncs(void)
! {
! 	int			tmpfile, ops;
  
  	/*
  	 * Compare 1 to 2 writes
*************** main(int argc, char *argv[])
*** 465,474 ****
  #ifdef OPEN_SYNC_FLAG
  	printf(LABEL_FORMAT, "open_sync 16k write");
  	fflush(stdout);
  	if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG, 0)) == -1)
  		die("Cannot open output file.");
  	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
  	{
  		if (write(tmpfile, buf, WRITE_SIZE * 2) != WRITE_SIZE * 2)
  			die("write failed");
--- 394,404 ----
  #ifdef OPEN_SYNC_FLAG
  	printf(LABEL_FORMAT, "open_sync 16k write");
  	fflush(stdout);
+ 
  	if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG, 0)) == -1)
  		die("Cannot open output file.");
  	gettimeofday(&start_t, NULL);
! 	for (ops = 0; ops < ops_per_test; ops++)
  	{
  		if (write(tmpfile, buf, WRITE_SIZE * 2) != WRITE_SIZE * 2)
  			die("write failed");
*************** main(int argc, char *argv[])
*** 481,490 ****
  
  	printf(LABEL_FORMAT, "2 open_sync 8k writes");
  	fflush(stdout);
  	if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG, 0)) == -1)
  		die("Cannot open output file.");
  	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
  	{
  		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
  			die("write failed");
--- 411,421 ----
  
  	printf(LABEL_FORMAT, "2 open_sync 8k writes");
  	fflush(stdout);
+ 
  	if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG, 0)) == -1)
  		die("Cannot open output file.");
  	gettimeofday(&start_t, NULL);
! 	for (ops = 0; ops < ops_per_test; ops++)
  	{
  		if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
  			die("write failed");
*************** main(int argc, char *argv[])
*** 499,504 ****
--- 430,441 ----
  #else
  	printf(NA_FORMAT, "open_sync", "n/a\n");
  #endif
+ }
+ 
+ void
+ test_file_descriptor_sync(void)
+ {
+ 	int			tmpfile, ops;
  
  	/*
  	 * Test whether fsync can sync data written on a different
*************** main(int argc, char *argv[])
*** 517,524 ****
  	 */
  	printf(LABEL_FORMAT, "8k write, fsync, close");
  	fflush(stdout);
  	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
  	{
  		if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
  			die("Cannot open output file.");
--- 454,462 ----
  	 */
  	printf(LABEL_FORMAT, "8k write, fsync, close");
  	fflush(stdout);
+ 
  	gettimeofday(&start_t, NULL);
! 	for (ops = 0; ops < ops_per_test; ops++)
  	{
  		if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
  			die("Cannot open output file.");
*************** main(int argc, char *argv[])
*** 545,552 ****
  	 */
   	printf(LABEL_FORMAT, "8k write, close, fsync");
   	fflush(stdout);
  	gettimeofday(&start_t, NULL);
! 	for (i = 0; i < loops; i++)
  	{
  		if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
  			die("Cannot open output file.");
--- 483,491 ----
  	 */
   	printf(LABEL_FORMAT, "8k write, close, fsync");
   	fflush(stdout);
+ 
  	gettimeofday(&start_t, NULL);
! 	for (ops = 0; ops < ops_per_test; ops++)
  	{
  		if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
  			die("Cannot open output file.");
*************** main(int argc, char *argv[])
*** 563,575 ****
  	gettimeofday(&stop_t, NULL);
  	print_elapse(start_t, stop_t);
  
- 	/* 
- 	 * cleanup 
- 	 */
- 	free(full_buf);
- 	unlink(filename);
- 
- 	return 0;
  }
  
  /* 
--- 502,507 ----
*************** print_elapse(struct timeval start_t, str
*** 580,586 ****
  {
  	double		total_time = (stop_t.tv_sec - start_t.tv_sec) +
  	(stop_t.tv_usec - start_t.tv_usec) * 0.000001;
! 	double		per_second = loops / total_time;
  
  	printf("%9.3f ops/sec\n", per_second);
  }
--- 512,518 ----
  {
  	double		total_time = (stop_t.tv_sec - start_t.tv_sec) +
  	(stop_t.tv_usec - start_t.tv_usec) * 0.000001;
! 	double		per_second = ops_per_test / total_time;
  
  	printf("%9.3f ops/sec\n", per_second);
  }
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to