configure: add SCHED_IDLE check

We can't consider it always available on Linux. It fails on
Debian 6.x, for instance.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/configure b/configure
index 583e3ab..995b5df 100755
--- a/configure
+++ b/configure
@@ -200,6 +200,7 @@
   output_sym "CONFIG_FDATASYNC"
   output_sym "CONFIG_GETTIMEOFDAY"
   output_sym "CONFIG_CLOCK_GETTIME"
+  output_sym "CONFIG_SCHED_IDLE"
   echo "CC=$CC" >> $config_host_mak
   echo "EXTFLAGS=$CFLAGS -include config-host.h -D_GNU_SOURCE" >> $config_host_mak
   exit 0
@@ -844,6 +845,22 @@
 fi
 echo "RUSAGE_THREAD                 $rusage_thread"
 
+##########################################
+# Check whether we have SCHED_IDLE
+sched_idle="no"
+cat > $TMPC << EOF
+#include <sched.h>
+int main(int argc, char **argv)
+{
+  struct sched_param p;
+  return sched_setscheduler(0, SCHED_IDLE, &p);
+}
+EOF
+if compile_prog "" "" "SCHED_IDLE"; then
+  sched_idle="yes"
+fi
+echo "SCHED_IDLE                    $sched_idle"
+
 #############################################################################
 
 echo "# Automatically generated by configure - do not modify" > $config_host_mak
@@ -947,6 +964,9 @@
 if test "$rusage_thread" = "yes" ; then
   output_sym "CONFIG_RUSAGE_THREAD"
 fi
+if test "$sched_idle" = "yes" ; then
+  output_sym "CONFIG_SCHED_IDLE"
+fi
 
 echo "LIBS+=$LIBS" >> $config_host_mak
 echo "CC=$cc" >> $config_host_mak
diff --git a/idletime.c b/idletime.c
index 6100134..fb6f9dd 100644
--- a/idletime.c
+++ b/idletime.c
@@ -74,7 +74,7 @@
 	ipt->cali_time = calibrate_unit(ipt->data);
 
 	/* delay to set IDLE class till now for better calibration accuracy */
-#if defined(FIO_HAVE_SCHED_IDLE)
+#if defined(CONFIG_SCHED_IDLE)
 	if ((retval = fio_set_sched_idle()))
 		log_err("fio: fio_set_sched_idle failed\n");
 #else
@@ -385,7 +385,7 @@
 		return -1;
 	}	
 
-#if defined(FIO_HAVE_CPU_AFFINITY) && defined(FIO_HAVE_SCHED_IDLE)
+#if defined(FIO_HAVE_CPU_AFFINITY) && defined(CONFIG_SCHED_IDLE)
 	if (strcmp("calibrate", args) == 0) {
 		ipc.opt = IDLE_PROF_OPT_CALI;
 		fio_idle_prof_init();
diff --git a/os/os-linux.h b/os/os-linux.h
index acc5a20..c45f071 100644
--- a/os/os-linux.h
+++ b/os/os-linux.h
@@ -35,7 +35,6 @@
 #define FIO_HAVE_TRIM
 #define FIO_HAVE_BINJECT
 #define FIO_HAVE_GETTID
-#define FIO_HAVE_SCHED_IDLE
 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
 
 #ifdef MAP_HUGETLB
@@ -247,10 +246,12 @@
 	return errno;
 }
 
+#ifdef CONFIG_SCHED_IDLE
 static inline int fio_set_sched_idle(void)
 {
 	struct sched_param p = { .sched_priority = 0, };
 	return sched_setscheduler(gettid(), SCHED_IDLE, &p);
 }
+#endif
 
 #endif
diff --git a/os/os-windows.h b/os/os-windows.h
index 2d57891..98f9030 100644
--- a/os/os-windows.h
+++ b/os/os-windows.h
@@ -21,7 +21,6 @@
 #define FIO_HAVE_CPU_AFFINITY
 #define FIO_HAVE_CHARDEV_SIZE
 #define FIO_HAVE_GETTID
-#define FIO_HAVE_SCHED_IDLE
 #define FIO_USE_GENERIC_RAND
 
 #define FIO_PREFERRED_ENGINE		"windowsaio"