Implement nice() for Windows
authorBruce Cran <bruce.cran@gmail.com>
Wed, 12 Oct 2016 02:22:47 +0000 (03:22 +0100)
committerJens Axboe <axboe@fb.com>
Wed, 12 Oct 2016 14:58:36 +0000 (08:58 -0600)
Map the following ranges for the "nice" option:

Less than -15:  High
-1 through -15: Above normal
0:              Normal
1 through 15:   Below normal
More than 15:   Low/Idle

Signed-off-by: Jens Axboe <axboe@fb.com>
HOWTO
os/windows/posix.c

diff --git a/HOWTO b/HOWTO
index 07419a12054ed43b991e3300db29a07ca4efbec5..cf1024cff4dbb2a7f8ee888cae6d21d511b5096d 100644 (file)
--- a/HOWTO
+++ b/HOWTO
@@ -1066,6 +1066,10 @@ random_generator=str     Fio supports the following engines for generating
 
 nice=int       Run the job with the given nice value. See man nice(2).
 
+     On Windows, values less than -15 set the process class to "High";
+     -1 through -15 set "Above Normal"; 1 through 15 "Below Normal";
+     and above 15 "Idle" priority class.
+
 prio=int       Set the io priority value of this job. Linux limits us to
                a positive value between 0 and 7, with 0 being the highest.
                See man ionice(1). Refer to an appropriate manpage for
index 3388127821acadc5d4053689f1246efd3be96af3..bbd93e979522e098d9a438e0ccfdc10da0b89ec0 100755 (executable)
@@ -647,10 +647,19 @@ int setgid(gid_t gid)
 
 int nice(int incr)
 {
-       if (incr != 0) {
-               errno = EINVAL;
-               return -1;
-       }
+       DWORD prioclass = NORMAL_PRIORITY_CLASS;
+       
+       if (incr < -15)
+               prioclass = HIGH_PRIORITY_CLASS;
+       else if (incr < 0)
+               prioclass = ABOVE_NORMAL_PRIORITY_CLASS;
+       else if (incr > 15)
+               prioclass = IDLE_PRIORITY_CLASS;
+       else if (incr > 0)
+               prioclass = BELOW_NORMAL_PRIORITY_CLASS;
+       
+       if (!SetPriorityClass(GetCurrentProcess(), prioclass))
+               log_err("fio: SetPriorityClass failed\n");
 
        return 0;
 }