SOURCES: ionice.c (NEW) - initial

arekm arekm at pld-linux.org
Sun Oct 2 17:24:54 CEST 2005


Author: arekm                        Date: Sun Oct  2 15:24:54 2005 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- initial

---- Files affected:
SOURCES:
   ionice.c (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/ionice.c
diff -u /dev/null SOURCES/ionice.c:1.1
--- /dev/null	Sun Oct  2 17:24:54 2005
+++ SOURCES/ionice.c	Sun Oct  2 17:24:48 2005
@@ -0,0 +1,94 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <getopt.h>
+#include <unistd.h>
+#include <sys/ptrace.h>
+#include <asm/unistd.h>
+
+extern int sys_ioprio_set(int);
+extern int sys_ioprio_get(void);
+
+#if defined(__i386__)
+#define __NR_ioprio_set		289
+#define __NR_ioprio_get		290
+#elif defined(__ppc__)
+#define __NR_ioprio_set		273
+#define __NR_ioprio_get		274
+#elif defined(__x86_64__)
+#define __NR_ioprio_set		251
+#define __NR_ioprio_get		252
+#elif defined(__ia64__)
+#define __NR_ioprio_set		1274
+#define __NR_ioprio_get		1275
+#else
+#error "Unsupported arch"
+#endif
+
+_syscall1(int, ioprio_set, int, ioprio);
+_syscall0(int, ioprio_get);
+
+enum {
+	IOPRIO_CLASS_NONE,
+	IOPRIO_CLASS_RT,
+	IOPRIO_CLASS_BE,
+	IOPRIO_CLASS_IDLE,
+};
+
+const char *to_prio[] = { "none", "realtime", "best-effort", "idle", };
+
+int main(int argc, char *argv[])
+{
+	int ioprio = 4, set = 0, ioprio_class = IOPRIO_CLASS_BE;
+	int c;
+
+	while ((c = getopt(argc, argv, "+n:c:")) != EOF) {
+		switch (c) {
+		case 'n':
+			ioprio = strtol(optarg, NULL, 10);
+			set = 1;
+			break;
+		case 'c':
+			ioprio_class = strtol(optarg, NULL, 10);
+			set = 1;
+			break;
+		}
+	}
+
+	switch (ioprio_class) {
+		case IOPRIO_CLASS_NONE:
+			ioprio_class = IOPRIO_CLASS_BE;
+			break;
+		case IOPRIO_CLASS_RT:
+		case IOPRIO_CLASS_BE:
+			break;
+		case IOPRIO_CLASS_IDLE:
+			ioprio = 7;
+			break;
+		default:
+			printf("bad prio class %d\n", ioprio_class);
+			return 1;
+	}
+
+	if (!set) {
+		ioprio = ioprio_get();
+
+		if (ioprio == -1)
+			perror("ioprio_get");
+		else {
+			ioprio_class = ioprio >> 24;
+			ioprio = ioprio & 0xff;
+			printf("%s: prio %d\n", to_prio[ioprio_class], ioprio);
+		}
+	} else if (argv[optind]) {
+		printf("%s: prio %d\n", to_prio[ioprio_class], ioprio);
+		if (ioprio_set(ioprio | ioprio_class << 24) == -1) {
+			perror("ioprio_set");
+			return 1;
+		}
+		execvp(argv[optind], &argv[optind]);
+	}
+
+	return 0;
+}
+
================================================================



More information about the pld-cvs-commit mailing list