Abstract out the SELF/THREAD complication.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
DEBUGFLAGS = -D_FORTIFY_SOURCE=2 -DFIO_INC_DEBUG
-CPPFLAGS= -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 \
- $(DEBUGFLAGS)
+CPPFLAGS= -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 $(DEBUGFLAGS)
OPTFLAGS= -O3 -g -ffast-math $(EXTFLAGS)
CFLAGS = -std=gnu99 -Wwrite-strings -Wall $(OPTFLAGS)
LIBS = -lm $(EXTLIBS)
engines/mmap.c engines/sync.c engines/null.c engines/net.c \
memalign.c server.c client.c iolog.c backend.c libfio.c flow.c \
json.c lib/zipf.c lib/axmap.c lib/lfsr.c gettime-thread.c \
- helpers.c lib/flist_sort.c lib/hweight.c
+ helpers.c lib/flist_sort.c lib/hweight.c lib/getrusage.c
ifdef CONFIG_64BIT_LLP64
CFLAGS += -DBITS_PER_LONG=32
ifdef CONFIG_LINUX_FALLOCATE
CFLAGS += -DCONFIG_LINUX_FALLOCATE
endif
+ifdef CONFIG_RUSAGE_THREAD
+ CFLAGS += -DCONFIG_RUSAGE_THREAD
+endif
ifeq ($(UNAME), Linux)
SOURCE += diskutil.c fifo.c blktrace.c cgroup.c trim.c engines/sg.c \
#include "lib/rand.h"
#include "memalign.h"
#include "server.h"
+#include "lib/getrusage.h"
static pthread_t disk_util_thread;
static struct fio_mutex *disk_thread_mutex;
}
fio_gettime(&td->epoch, NULL);
-#ifdef RUSAGE_THREAD
- getrusage(RUSAGE_THREAD, &td->ru_start);
-#else
- getrusage(RUSAGE_SELF, &td->ru_start);
-#endif
+ fio_getrusage(&td->ru_start);
clear_state = 0;
while (keep_running(td)) {
uint64_t verify_bytes;
config_host_mak="config-host.mak"
config_host_ld="config-host.ld"
+# Default CFLAGS
+CFLAGS="-D_GNU_SOURCE"
+
# Print a helpful header at the top of config.log
echo "# FIO configure log $(date)" >> config.log
printf "# Configured with:" >> config.log
linux_2arg_affinity="no"
linux_3arg_affinity="no"
cat > $TMPC << EOF
-#define _GNU_SOURCE
#include <sched.h>
int main(int argc, char **argv)
{
linux_3arg_affinity="yes"
else
cat > $TMPC << EOF
-#define _GNU_SOURCE
#include <sched.h>
int main(int argc, char **argv)
{
cat > $TMPC << EOF
#include <stdio.h>
#include <unistd.h>
-#define _GNU_SOURCE
#include <fcntl.h>
#include <linux/fs.h>
int main(int argc, char **argv)
# splice probe
linux_splice="no"
cat > $TMPC << EOF
-#define _GNU_SOURCE
#include <stdio.h>
#include <fcntl.h>
int main(int argc, char **argv)
fi
echo "__thread $tls_thread"
+##########################################
+# Check whether we have getrusage(RUSAGE_THREAD)
+rusage_thread="no"
+cat > $TMPC << EOF
+#include <sys/time.h>
+#include <sys/resource.h>
+int main(int argc, char **argv)
+{
+ struct rusage ru;
+ getrusage(RUSAGE_THREAD, &ru);
+ return 0;
+}
+EOF
+if compile_prog "" "" "RUSAGE_THREAD"; then
+ rusage_thread="yes"
+fi
+echo "RUSAGE_THREAD $rusage_thread"
+
#############################################################################
echo "# Automatically generated by configure - do not modify" > $config_host_mak
if test "$tls_thread" = "yes" ; then
echo "CONFIG_TLS_THREAD=y" >> $config_host_mak
fi
+if test "$rusage_thread" = "yes" ; then
+ echo "CONFIG_RUSAGE_THREAD=y" >> $config_host_mak
+fi
echo "LIBS+=$LIBS" >> $config_host_mak
echo "CC=$cc" >> $config_host_mak
+echo "CFLAGS=$CFLAGS" >> $config_host_mak
--- /dev/null
+#include <errno.h>
+#include "getrusage.h"
+
+int fio_getrusage(struct rusage *ru)
+{
+#ifdef CONFIG_RUSAGE_THREAD
+ if (!getrusage(RUSAGE_THREAD, ru))
+ return 0;
+ if (errno != EINVAL)
+ return -1;
+ /* Fall through to RUSAGE_SELF */
+#endif
+ return getrusage(RUSAGE_SELF, ru);
+}
--- /dev/null
+#ifndef FIO_GETRUSAGE_H
+#define FIO_GETRUSAGE_H
+
+#include <sys/time.h>
+#include <sys/resource.h>
+
+extern int fio_getrusage(struct rusage *ru);
+
+#endif
#include "diskutil.h"
#include "lib/ieee754.h"
#include "json.h"
+#include "lib/getrusage.h"
void update_rusage_stat(struct thread_data *td)
{
struct thread_stat *ts = &td->ts;
-#ifdef RUSAGE_THREAD
- getrusage(RUSAGE_THREAD, &td->ru_end);
-#else
- getrusage(RUSAGE_SELF, &td->ru_end);
-#endif
-
+ fio_getrusage(&td->ru_end);
ts->usr_time += mtime_since(&td->ru_start.ru_utime,
&td->ru_end.ru_utime);
ts->sys_time += mtime_since(&td->ru_start.ru_stime,