summaryrefslogtreecommitdiff
path: root/ioprio.c
diff options
context:
space:
mode:
Diffstat (limited to 'ioprio.c')
-rw-r--r--ioprio.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/ioprio.c b/ioprio.c
new file mode 100644
index 0000000..52c5a28
--- /dev/null
+++ b/ioprio.c
@@ -0,0 +1,86 @@
+#include "defs.h"
+
+enum {
+ IOPRIO_WHO_PROCESS = 1,
+ IOPRIO_WHO_PGRP,
+ IOPRIO_WHO_USER
+};
+
+static const struct xlat ioprio_who[] = {
+ XLAT(IOPRIO_WHO_PROCESS),
+ XLAT(IOPRIO_WHO_PGRP),
+ XLAT(IOPRIO_WHO_USER),
+ XLAT_END
+};
+
+enum {
+ IOPRIO_CLASS_NONE,
+ IOPRIO_CLASS_RT,
+ IOPRIO_CLASS_BE,
+ IOPRIO_CLASS_IDLE
+};
+
+static const struct xlat ioprio_class[] = {
+ XLAT(IOPRIO_CLASS_NONE),
+ XLAT(IOPRIO_CLASS_RT),
+ XLAT(IOPRIO_CLASS_BE),
+ XLAT(IOPRIO_CLASS_IDLE),
+ XLAT_END
+};
+
+#define IOPRIO_CLASS_SHIFT (13)
+#define IOPRIO_PRIO_MASK ((1ul << IOPRIO_CLASS_SHIFT) - 1)
+
+#define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT)
+#define IOPRIO_PRIO_DATA(mask) ((mask) & IOPRIO_PRIO_MASK)
+
+static const char *
+sprint_ioprio(int ioprio)
+{
+ static char outstr[256];
+ const char *str;
+ int class, data;
+
+ class = IOPRIO_PRIO_CLASS(ioprio);
+ data = IOPRIO_PRIO_DATA(ioprio);
+ str = xlookup(ioprio_class, class);
+ if (str)
+ sprintf(outstr, "IOPRIO_PRIO_VALUE(%s,%d)", str, data);
+ else
+ sprintf(outstr, "IOPRIO_PRIO_VALUE(%#x /* %s */,%d)",
+ class, "IOPRIO_CLASS_???", data);
+
+ return outstr;
+}
+
+int
+sys_ioprio_get(struct tcb *tcp)
+{
+ if (entering(tcp)) {
+ /* int which */
+ printxval(ioprio_who, tcp->u_arg[0], "IOPRIO_WHO_???");
+ /* int who */
+ tprintf(", %d", (int) tcp->u_arg[1]);
+ return 0;
+ } else {
+ if (syserror(tcp))
+ return 0;
+
+ tcp->auxstr = sprint_ioprio(tcp->u_rval);
+ return RVAL_STR;
+ }
+}
+
+int
+sys_ioprio_set(struct tcb *tcp)
+{
+ if (entering(tcp)) {
+ /* int which */
+ printxval(ioprio_who, tcp->u_arg[0], "IOPRIO_WHO_???");
+ /* int who */
+ tprintf(", %d, ", (int) tcp->u_arg[1]);
+ /* int ioprio */
+ tprints(sprint_ioprio(tcp->u_arg[2]));
+ }
+ return 0;
+}