From: Damien Le Moal <dlemoal@kernel.org>
To: ltp <ltp@lists.linux.it>, Linus Walleij <linus.walleij@linaro.org>
Cc: Niklas Cassel <niklas.cassel@wdc.com>
Subject: [LTP] [PATCH v2 1/2] ioprio: use ioprio.h kernel header if it exists
Date: Thu, 8 Jun 2023 09:53:14 +0900 [thread overview]
Message-ID: <20230608005315.3703446-2-dlemoal@kernel.org> (raw)
In-Reply-To: <20230608005315.3703446-1-dlemoal@kernel.org>
For the ioprio system call test cases, avoid blindly defining the
IOPRIO_XXX macro internally and instead use the kernel user API header
file if it exists. Given that the definitions in this header file have
changed over time, make sure to test for the existence of the macro
IOPRIO_PRIO_LEVEL macro and define it if it does not exist. Similarly,
use IOPRIO_NR_LEVELS to define IOPRIO_PRIO_NUM if that macro exists.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
---
configure.ac | 1 +
testcases/kernel/syscalls/ioprio/ioprio.h | 29 +++++++++++++++++------
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/configure.ac b/configure.ac
index 548288310..e4aa2cadf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -56,6 +56,7 @@ AC_CHECK_HEADERS_ONCE([ \
linux/if_ether.h \
linux/if_packet.h \
linux/io_uring.h \
+ linux/ioprio.h \
linux/keyctl.h \
linux/mempolicy.h \
linux/module.h \
diff --git a/testcases/kernel/syscalls/ioprio/ioprio.h b/testcases/kernel/syscalls/ioprio/ioprio.h
index c74380475..6ca134a54 100644
--- a/testcases/kernel/syscalls/ioprio/ioprio.h
+++ b/testcases/kernel/syscalls/ioprio/ioprio.h
@@ -6,6 +6,12 @@
#ifndef LTP_IOPRIO_H
#define LTP_IOPRIO_H
+#ifdef HAVE_LINUX_IOPRIO_H
+
+# include <linux/ioprio.h>
+
+#else
+
enum {
IOPRIO_CLASS_NONE = 0,
IOPRIO_CLASS_RT,
@@ -19,15 +25,24 @@ enum {
IOPRIO_WHO_USER,
};
-/* The I/O scheduler classes have 8 priorities 0..7 except for the IDLE class */
-#define IOPRIO_PRIO_NUM 8
+# define IOPRIO_CLASS_SHIFT (13)
+# define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1)
+
+# define IOPRIO_PRIO_CLASS(data) ((data) >> IOPRIO_CLASS_SHIFT)
+# define IOPRIO_PRIO_VALUE(class, data) (((class) << IOPRIO_CLASS_SHIFT) | data)
-#define IOPRIO_CLASS_SHIFT (13)
-#define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1)
+#endif
+
+/* The RT and BE I/O priority classes have 8 priority levels 0..7 */
+#ifdef IOPRIO_NR_LEVELS
+# define IOPRIO_PRIO_NUM IOPRIO_NR_LEVELS
+#else
+# define IOPRIO_PRIO_NUM 8
+#endif
-#define IOPRIO_PRIO_CLASS(data) ((data) >> IOPRIO_CLASS_SHIFT)
-#define IOPRIO_PRIO_LEVEL(data) ((data) & IOPRIO_PRIO_MASK)
-#define IOPRIO_PRIO_VALUE(class, data) (((class) << IOPRIO_CLASS_SHIFT) | data)
+#ifndef IOPRIO_PRIO_LEVEL
+# define IOPRIO_PRIO_LEVEL(data) ((data) & IOPRIO_PRIO_MASK)
+#endif
static const char * const to_class_str[] = {
[IOPRIO_CLASS_NONE] = "NONE",
--
2.40.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2023-06-08 0:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-08 0:53 [LTP] [PATCH v2 0/2] Improve ioprio tests Damien Le Moal
2023-06-08 0:53 ` Damien Le Moal [this message]
2023-06-20 10:14 ` [LTP] [PATCH v2 1/2] ioprio: use ioprio.h kernel header if it exists Petr Vorel
2023-06-20 13:01 ` Damien Le Moal
2023-06-20 18:52 ` Linus Walleij
2023-06-08 0:53 ` [LTP] [PATCH v2 2/2] ioprio: Use IOPRIO_PRIO_NUM to check prio range Damien Le Moal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230608005315.3703446-2-dlemoal@kernel.org \
--to=dlemoal@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=ltp@lists.linux.it \
--cc=niklas.cassel@wdc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox