blob: 0de03643e77ba4036b448004cfb160dcd007c19f [file] [log] [blame]
subrata_modak55d04e42009-10-26 11:25:55 +00001/*
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
subrata_modak55d04e42009-10-26 11:25:55 +000017 */
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
37void ffsb_sleep(unsigned secs);
38void *ffsb_malloc(size_t size);
39void *ffsb_realloc(void *ptr, size_t size);
40char *ffsb_strdup(const char *str);
41size_t ffsb_strnlen(const char *str, size_t maxlen);
42
43void ffsb_mkdir(char *dirname);
44void ffsb_getrusage(struct rusage *ru_self, struct rusage *ru_children);
45void ffsb_sync(void);
46void *ffsb_align_4k(void *ptr);
47char *ffsb_printsize(char *buf, double size, int bufsize);
48
49int ffsb_system(char *command);
50void ffsb_milli_sleep(unsigned time);
51void ffsb_micro_sleep(unsigned time);
52void ffsb_unbuffer_stdout(void);
53void ffsb_bench_gettimeofday(void);
54void ffsb_bench_getpid(void);
55
56uint64_t ffsb_get_filesize(char *name);
57
58typedef struct {
59 unsigned required_count;
60 unsigned current_count;
61 pthread_mutex_t plock;
62 pthread_cond_t pcond;
63} ffsb_barrier_t ;
64
65void ffsb_barrier_init(ffsb_barrier_t *fb, unsigned count);
66void ffsb_barrier_wait(ffsb_barrier_t *fb);
67
68double cpu_so_far(void);
69double time_so_far(void);
70double cpu_so_far_children(void);
71float getfsutil(char *dirname);
72uint64_t getfsutil_size(char *dirname);
73
74struct timeval tvsub(struct timeval t1, struct timeval t0);
75struct timeval tvadd(struct timeval t1, struct timeval t0);
76double 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_ */