Add lib/getrusage.c

Abstract out the SELF/THREAD complication.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/configure b/configure
index f730dfd..59899db 100755
--- a/configure
+++ b/configure
@@ -26,6 +26,9 @@
 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
@@ -480,7 +483,6 @@
 linux_2arg_affinity="no"
 linux_3arg_affinity="no"
 cat > $TMPC << EOF
-#define _GNU_SOURCE
 #include <sched.h>
 int main(int argc, char **argv)
 {
@@ -492,7 +494,6 @@
   linux_3arg_affinity="yes"
 else
   cat > $TMPC << EOF
-#define _GNU_SOURCE
 #include <sched.h>
 int main(int argc, char **argv)
 {
@@ -601,7 +602,6 @@
 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)
@@ -642,7 +642,6 @@
 # splice probe
 linux_splice="no"
 cat > $TMPC << EOF
-#define _GNU_SOURCE
 #include <stdio.h>
 #include <fcntl.h>
 int main(int argc, char **argv)
@@ -789,6 +788,24 @@
 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
@@ -889,6 +906,10 @@
 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