1 |
On Thu, 2007-02-08 at 16:10 +1100, Christian Marie wrote: |
2 |
> On Thu, Feb 08, 2007 at 10:23:09AM +0930, Iain Buchanan wrote: |
3 |
> > Hi all, |
4 |
> > |
5 |
> > I'm trying to use: |
6 |
> > |
7 |
> > _syscall3(int, ioprio_set, int, which, int, who, int, ioprio); |
8 |
> > _syscall2(int, ioprio_get, int, which, int, who); |
9 |
> > |
10 |
> > and supposedly I just |
11 |
> > |
12 |
> > #include <linux/unistd.h> |
13 |
> > |
14 |
> > but I'm getting these error from gcc: |
15 |
> > |
16 |
> > error: syntax error before "ioprio_set" |
17 |
> > warning: data definition has no type or storage class |
18 |
> > error: syntax error before "ioprio_get" |
19 |
> > warning: data definition has no type or storage class |
20 |
> |
21 |
> Hi, |
22 |
> |
23 |
> It would be helpful to provide us with the failing code as we have no |
24 |
> clue what you could be doing wrong. |
25 |
|
26 |
sure - my question was more "where has the define for _syscall2 gone?", |
27 |
but here is the code. It comes |
28 |
from /usr/src/linux/Documentation/block/ioprio.txt. I compile it with: |
29 |
$ gcc -o ionice ionice.c |
30 |
ionice.c:36: error: syntax error before "ioprio_set" |
31 |
ionice.c:36: warning: data definition has no type or storage class |
32 |
ionice.c:37: error: syntax error before "ioprio_get" |
33 |
ionice.c:37: warning: data definition has no type or storage class |
34 |
|
35 |
------begin ionice.c------ |
36 |
// |
37 |
// Sample ionice utility copied from |
38 |
// /usr/src/linux/Documentation/block/ioprio.txt from gentoo kernel version |
39 |
// 2.6.19-suspend2-r1. Probably (C) Jens Axboe <axboe@××××.de> and GPL'd? |
40 |
// |
41 |
|
42 |
#include <stdio.h> |
43 |
#include <stdlib.h> |
44 |
#include <errno.h> |
45 |
#include <getopt.h> |
46 |
#include <unistd.h> |
47 |
#include <sys/ptrace.h> |
48 |
|
49 |
extern int sys_ioprio_set(int, int, int); |
50 |
extern int sys_ioprio_get(int, int); |
51 |
|
52 |
#if defined(__i386__) |
53 |
#define __NR_ioprio_set 289 |
54 |
#define __NR_ioprio_get 290 |
55 |
#elif defined(__ppc__) |
56 |
#define __NR_ioprio_set 273 |
57 |
#define __NR_ioprio_get 274 |
58 |
#elif defined(__x86_64__) |
59 |
#define __NR_ioprio_set 251 |
60 |
#define __NR_ioprio_get 252 |
61 |
#elif defined(__ia64__) |
62 |
#define __NR_ioprio_set 1274 |
63 |
#define __NR_ioprio_get 1275 |
64 |
#else |
65 |
#error "Unsupported arch" |
66 |
#endif |
67 |
|
68 |
int ioprio_get(int which, int who); |
69 |
int ioprio_set(int which, int who, int ioprio); |
70 |
|
71 |
_syscall3(int, ioprio_set, int, which, int, who, int, ioprio); |
72 |
_syscall2(int, ioprio_get, int, which, int, who); |
73 |
|
74 |
enum { |
75 |
IOPRIO_CLASS_NONE, |
76 |
IOPRIO_CLASS_RT, |
77 |
IOPRIO_CLASS_BE, |
78 |
IOPRIO_CLASS_IDLE, |
79 |
}; |
80 |
|
81 |
enum { |
82 |
IOPRIO_WHO_PROCESS = 1, |
83 |
IOPRIO_WHO_PGRP, |
84 |
IOPRIO_WHO_USER, |
85 |
}; |
86 |
|
87 |
#define IOPRIO_CLASS_SHIFT 13 |
88 |
|
89 |
const char *to_prio[] = { "none", "realtime", "best-effort", "idle", }; |
90 |
|
91 |
int main(int argc, char *argv[]) |
92 |
{ |
93 |
int ioprio = 4, set = 0, ioprio_class = IOPRIO_CLASS_BE; |
94 |
int c, pid = 0; |
95 |
|
96 |
while ((c = getopt(argc, argv, "+n:c:p:")) != EOF) { |
97 |
switch (c) { |
98 |
case 'n': |
99 |
ioprio = strtol(optarg, NULL, 10); |
100 |
set = 1; |
101 |
break; |
102 |
case 'c': |
103 |
ioprio_class = strtol(optarg, NULL, 10); |
104 |
set = 1; |
105 |
break; |
106 |
case 'p': |
107 |
pid = strtol(optarg, NULL, 10); |
108 |
break; |
109 |
} |
110 |
} |
111 |
|
112 |
switch (ioprio_class) { |
113 |
case IOPRIO_CLASS_NONE: |
114 |
ioprio_class = IOPRIO_CLASS_BE; |
115 |
break; |
116 |
case IOPRIO_CLASS_RT: |
117 |
case IOPRIO_CLASS_BE: |
118 |
break; |
119 |
case IOPRIO_CLASS_IDLE: |
120 |
ioprio = 7; |
121 |
break; |
122 |
default: |
123 |
printf("bad prio class %d\n", ioprio_class); |
124 |
return 1; |
125 |
} |
126 |
|
127 |
if (!set) { |
128 |
if (!pid && argv[optind]) |
129 |
pid = strtol(argv[optind], NULL, 10); |
130 |
|
131 |
ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid); |
132 |
|
133 |
printf("pid=%d, %d\n", pid, ioprio); |
134 |
|
135 |
if (ioprio == -1) |
136 |
perror("ioprio_get"); |
137 |
else { |
138 |
ioprio_class = ioprio >> IOPRIO_CLASS_SHIFT; |
139 |
ioprio = ioprio & 0xff; |
140 |
printf("%s: prio %d\n", to_prio[ioprio_class], ioprio); |
141 |
} |
142 |
} else { |
143 |
if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class << IOPRIO_CLASS_SHIFT) == -1) { |
144 |
perror("ioprio_set"); |
145 |
return 1; |
146 |
} |
147 |
|
148 |
if (argv[optind]) |
149 |
execvp(argv[optind], &argv[optind]); |
150 |
} |
151 |
|
152 |
return 0; |
153 |
} |
154 |
|
155 |
------end ionice.c------ |
156 |
|
157 |
thanks, |
158 |
-- |
159 |
Iain Buchanan <iaindb at netspace dot net dot au> |
160 |
|
161 |
Progress might have been all right once, but it's gone on too long. |
162 |
-- Ogden Nash |
163 |
|
164 |
-- |
165 |
gentoo-user@g.o mailing list |