Skip to contentSkip to conversation

syscalls/ioprio_set01.c: Stop decreasing priority continuously in loops

PATCH New Xiao Yang 2 participants 3 messages Aug 20, 2019 – Oct 16, 2019

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH 1/2 syscalls/ioprio_set01.c: Stop decreasing priority continuously in loops

Running ioprio_set01 -i 5 gets the following error:
-------------------------------------------------
...
ioprio_set01.c:29: INFO: ioprio_get returned class BEST-EFFORT prio 1 ioprio.h:89: PASS: ioprio_set new class BEST-EFFORT, new prio 2 ioprio.h:89: PASS: ioprio_set new class BEST-EFFORT, new prio 0 ioprio_set01.c:29: INFO: ioprio_get returned class BEST-EFFORT prio 0 ioprio.h:89: PASS: ioprio_set new class BEST-EFFORT, new prio 1 ioprio_set01.c:49: FAIL: ioprio increase out of range (-1)
...
-------------------------------------------------

The I/O scheduling priority of process is decreased by 1 continuously in loops so that it is out of range(i.e. 0~7) finally. We fix the issue by setting priority to original value before running test.

Also fix a typo because second subtest actually decreases priority.

---
 .../kernel/syscalls/ioprio/ioprio_set01.c     | 33 +++++++++++--------
 1 file changed, 20 insertions(+), 13 deletions(-)
testcases/kernel/syscalls/ioprio/ioprio_set01.c +20 -13
index 24bf8a9ca..5b89ac81e 100644
@@ -14,20 +14,12 @@
 #include "lapi/syscalls.h"
 #include "ioprio.h"
 
+static int orig_class;
+static int orig_prio;
+
 static void run(void)
 {
-	int class, prio;
-
-	/* Get the I/O priority for the current process */
-	TEST(sys_ioprio_get(IOPRIO_WHO_PROCESS, 0));
-
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "ioprio_get failed");
-
-	class = IOPRIO_PRIO_CLASS(TST_RET);
-	prio = IOPRIO_PRIO_LEVEL(TST_RET);
-	tst_res(TINFO, "ioprio_get returned class %s prio %d",
-		to_class_str[class], prio);
+	int class = orig_class, prio = orig_prio;
 
 	/* Bump prio to what it was + 1 */
 	class = IOPRIO_CLASS_BE;
@@ -46,7 +38,7 @@ static void run(void)
 
 	/* Bump prio down two notches */
 	if (!prio_in_range(prio - 2)) {
-		tst_res(TFAIL, "ioprio increase out of range (%d)", prio - 2);
+		tst_res(TFAIL, "ioprio decrease out of range (%d)", prio - 2);
 		return;
 	}
 	prio = (prio - 2);
@@ -58,6 +50,21 @@ static void run(void)
 		ioprio_check_setting(class, prio, 1);
 }
 
+static void setup(void)
+{
+	/* Get the I/O priority for the current process */
+	TEST(sys_ioprio_get(IOPRIO_WHO_PROCESS, 0));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "ioprio_get failed");
+
+	orig_class = IOPRIO_PRIO_CLASS(TST_RET);
+	orig_prio = IOPRIO_PRIO_LEVEL(TST_RET);
+
+	tst_res(TINFO, "ioprio_get returned class %s prio %d",
+		to_class_str[orig_class], orig_prio);
+}
+
 static struct tst_test test = {
+	.setup = setup,
 	.test_all = run,
 };
Signature · 1 line
2.21.0
author
#1 lore raw

PATCH 2/2 syscalls/ioprio_set01.c: Improve process for priority overflow

1) If original priority is 0, We should report TCONF for priority overflow in second subtest.
e.g. running ionice -n 0 ./ioprio_set01:
----------------------------------------------------------
...
ioprio_set01.c:65: INFO: ioprio_get returned class BEST-EFFORT prio 0 ioprio.h:89: PASS: ioprio_set new class BEST-EFFORT, new prio 1 ioprio_set01.c:43: CONF: ioprio decrease out of range (-1)
...
----------------------------------------------------------

2) If original priority is 7, we should report TCONF for priority overflow in first subtest and continue to run second subtest.
e.g. running ionice -n 7 ./ioprio_set01:
----------------------------------------------------------
...
ioprio_set01.c:65: INFO: ioprio_get returned class BEST-EFFORT prio 7 ioprio_set01.c:28: CONF: ioprio increase out of range (8) ioprio.h:89: PASS: ioprio_set new class BEST-EFFORT, new prio 6
...
---------------------------------------------------------

---
 testcases/kernel/syscalls/ioprio/ioprio_set01.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
testcases/kernel/syscalls/ioprio/ioprio_set01.c +9 -7
index 5b89ac81e..19953ba36 100644
@@ -23,11 +23,11 @@ static void run(void)
 
 	/* Bump prio to what it was + 1 */
 	class = IOPRIO_CLASS_BE;
-	if (!prio_in_range(prio + 1)) {
-		tst_res(TFAIL, "ioprio increase out of range (%d)", prio + 1);
-		return;
+	prio = prio + 1;
+	if (!prio_in_range(prio)) {
+		tst_res(TCONF, "ioprio increase out of range (%d)", prio);
+		goto second;
 	}
-	prio = (prio + 1);
 
 	TEST(sys_ioprio_set(IOPRIO_WHO_PROCESS, 0,
 			    IOPRIO_PRIO_VALUE(class, prio)));
@@ -36,12 +36,14 @@ static void run(void)
 	else
 		ioprio_check_setting(class, prio, 1);
 
+second:
 	/* Bump prio down two notches */
-	if (!prio_in_range(prio - 2)) {
-		tst_res(TFAIL, "ioprio decrease out of range (%d)", prio - 2);
+	prio = prio - 2;
+	if (!prio_in_range(prio)) {
+		tst_res(TCONF, "ioprio decrease out of range (%d)", prio);
 		return;
 	}
-	prio = (prio - 2);
+
 	TEST(sys_ioprio_set(IOPRIO_WHO_PROCESS, 0,
 			    IOPRIO_PRIO_VALUE(class, prio)));
 	if (TST_RET == -1)
Signature · 1 line
2.21.0