• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Copyright (c) International Business Machines Corp., 2001-2006
3  *
4  *   This program is free software;  you can redistribute it and/or modify
5  *   it under the terms of the GNU General Public License as published by
6  *   the Free Software Foundation; either version 2 of the License, or
7  *   (at your option) any later version.
8  *
9  *   This program is distributed in the hope that it will be useful,
10  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
12  *   the GNU General Public License for more details.
13  *
14  *   You should have received a copy of the GNU General Public License
15  *   along with this program;  if not, write to the Free Software
16  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #ifndef _UTIL_H_
19 #define _UTIL_H_
20 
21 #include "config.h"
22 
23 #include <sys/time.h>
24 #include <sys/resource.h>
25 
26 #ifdef HAVE_SYS_VFS_H
27 #include <sys/vfs.h>
28 #endif
29 #include <sys/statvfs.h>
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include <assert.h>
33 #include <string.h>
34 #include <pthread.h>
35 
36 
37 void ffsb_sleep(unsigned secs);
38 void *ffsb_malloc(size_t size);
39 void *ffsb_realloc(void *ptr, size_t size);
40 char *ffsb_strdup(const char *str);
41 size_t ffsb_strnlen(const char *str, size_t maxlen);
42 
43 void ffsb_mkdir(char *dirname);
44 void ffsb_getrusage(struct rusage *ru_self, struct rusage *ru_children);
45 void ffsb_sync(void);
46 void *ffsb_align_4k(void *ptr);
47 char *ffsb_printsize(char *buf, double size, int bufsize);
48 
49 int ffsb_system(char *command);
50 void ffsb_milli_sleep(unsigned time);
51 void ffsb_micro_sleep(unsigned time);
52 void ffsb_unbuffer_stdout(void);
53 void ffsb_bench_gettimeofday(void);
54 void ffsb_bench_getpid(void);
55 
56 uint64_t ffsb_get_filesize(char *name);
57 
58 typedef struct {
59 	unsigned required_count;
60 	unsigned current_count;
61 	pthread_mutex_t plock;
62 	pthread_cond_t pcond;
63 } ffsb_barrier_t ;
64 
65 void ffsb_barrier_init(ffsb_barrier_t *fb, unsigned count);
66 void ffsb_barrier_wait(ffsb_barrier_t *fb);
67 
68 double cpu_so_far(void);
69 double time_so_far(void);
70 double cpu_so_far_children(void);
71 float getfsutil(char *dirname);
72 uint64_t getfsutil_size(char *dirname);
73 
74 struct timeval tvsub(struct timeval t1, struct timeval t0);
75 struct timeval tvadd(struct timeval t1, struct timeval t0);
76 double tvtodouble(struct timeval *t);
77 
78 
79 #define max(a, b) (((a) > (b)) ? (a) : (b))
80 
81 #ifndef timersub
82 #define timersub(a, b, result)                                          \
83 	do {           	                                                \
84 		(result)->tv_sec = (a)->tv_sec - (b)->tv_sec;		\
85 		(result)->tv_usec = (a)->tv_usec - (b)->tv_usec;	\
86 									\
87 		if ((result)->tv_usec < 0) {				\
88 			(result)->tv_sec--;				\
89 			(result)->tv_usec += 1000000;			\
90 		}							\
91 	} while (0)
92 #endif /* timersub */
93 
94 #endif /* _UTIL_H_ */
95