(Back)port some changes from beagle-lucene-1-9-lockfile-branch: allow ext: queries...
[beagle.git] / glue / ioprio-glue.c
blob384bd48524d5cd9b306b8a350d9678dc4dde9305
1 /*
2 * ioprio-glue.c - I/O priority wrappers for the big dog
4 * Robert Love <rml@novell.com>
6 * Copyright (C) 2005 Novell, Inc.
7 */
9 #include <sys/syscall.h>
10 #include <unistd.h>
12 #if defined(__i386__)
13 #define __NR_ioprio_set 289
14 #define __NR_ioprio_get 290
15 #elif defined(__powerpc__) || defined(__powerpc64__)
16 #define __NR_ioprio_set 273
17 #define __NR_ioprio_get 274
18 #elif defined(__x86_64__)
19 #define __NR_ioprio_set 251
20 #define __NR_ioprio_get 252
21 #elif defined(__ia64__)
22 #define __NR_ioprio_set 1274
23 #define __NR_ioprio_get 1275
24 #elif defined(__alpha__)
25 #define __NR_ioprio_set 442
26 #define __NR_ioprio_get 443
27 #elif defined(__s390x__) || defined(__s390__)
28 #define __NR_ioprio_set 282
29 #define __NR_ioprio_get 283
30 #elif defined(__SH4__)
31 #define __NR_ioprio_set 288
32 #define __NR_ioprio_get 289
33 #elif defined(__SH5__)
34 #define __NR_ioprio_set 316
35 #define __NR_ioprio_get 317
36 #elif defined(__sparc__) || defined(__sparc64__)
37 #define __NR_ioprio_set 196
38 #define __NR_ioprio_get 218
39 #elif defined(__arm__)
40 #define __NR_ioprio_set 314
41 #define __NR_ioprio_get 315
42 #else
43 #error "Unsupported architecture!"
44 #endif
46 static inline int ioprio_set (int which, int who, int ioprio)
48 return syscall (__NR_ioprio_set, which, who, ioprio);
51 static inline int ioprio_get (int which, int who)
53 return syscall (__NR_ioprio_get, which, who);
56 enum {
57 IOPRIO_CLASS_NONE,
58 IOPRIO_CLASS_RT,
59 IOPRIO_CLASS_BE,
60 IOPRIO_CLASS_IDLE,
63 enum {
64 IOPRIO_WHO_PROCESS = 1,
65 IOPRIO_WHO_PGRP,
66 IOPRIO_WHO_USER,
69 #define IOPRIO_CLASS_SHIFT 13
70 #define IOPRIO_PRIO_MASK 0xff
72 int set_io_priority_idle (void)
74 int ioprio, ioclass;
76 ioprio = 7; /* priority is ignored with idle class */
77 ioclass = IOPRIO_CLASS_IDLE << IOPRIO_CLASS_SHIFT;
79 return ioprio_set (IOPRIO_WHO_PROCESS, 0, ioprio | ioclass);
82 int set_io_priority_best_effort (int ioprio)
84 int ioclass;
86 ioclass = IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
88 return ioprio_set (IOPRIO_WHO_PROCESS, 0, ioprio | ioclass);