diff options
Diffstat (limited to 'litmus/litmus_proc.c')
-rw-r--r-- | litmus/litmus_proc.c | 324 |
1 files changed, 324 insertions, 0 deletions
diff --git a/litmus/litmus_proc.c b/litmus/litmus_proc.c new file mode 100644 index 000000000000..ee0ad56d445c --- /dev/null +++ b/litmus/litmus_proc.c | |||
@@ -0,0 +1,324 @@ | |||
1 | /* | ||
2 | * litmus_proc.c -- Implementation of the /proc/litmus directory tree. | ||
3 | */ | ||
4 | |||
5 | #include <linux/uaccess.h> | ||
6 | |||
7 | #include <litmus/litmus_proc.h> | ||
8 | |||
9 | /* in litmus/litmus.c */ | ||
10 | extern atomic_t rt_task_count; | ||
11 | |||
12 | static struct proc_dir_entry *litmus_dir = NULL, | ||
13 | *curr_file = NULL, | ||
14 | *stat_file = NULL, | ||
15 | *plugs_dir = NULL, | ||
16 | *plugs_file = NULL, | ||
17 | #ifdef CONFIG_RELEASE_MASTER | ||
18 | *release_master_file = NULL, | ||
19 | #endif | ||
20 | *clus_cache_idx_file = NULL; | ||
21 | |||
22 | /* in litmus/sync.c */ | ||
23 | int count_tasks_waiting_for_release(void); | ||
24 | |||
25 | static int proc_read_stats(char *page, char **start, | ||
26 | off_t off, int count, | ||
27 | int *eof, void *data) | ||
28 | { | ||
29 | int len; | ||
30 | |||
31 | len = snprintf(page, PAGE_SIZE, | ||
32 | "real-time tasks = %d\n" | ||
33 | "ready for release = %d\n", | ||
34 | atomic_read(&rt_task_count), | ||
35 | count_tasks_waiting_for_release()); | ||
36 | return len; | ||
37 | } | ||
38 | |||
39 | static int proc_read_plugins(char *page, char **start, | ||
40 | off_t off, int count, | ||
41 | int *eof, void *data) | ||
42 | { | ||
43 | int len; | ||
44 | |||
45 | len = print_sched_plugins(page, PAGE_SIZE); | ||
46 | return len; | ||
47 | } | ||
48 | |||
49 | static int proc_read_curr(char *page, char **start, | ||
50 | off_t off, int count, | ||
51 | int *eof, void *data) | ||
52 | { | ||
53 | int len; | ||
54 | |||
55 | len = snprintf(page, PAGE_SIZE, "%s\n", litmus->plugin_name); | ||
56 | return len; | ||
57 | } | ||
58 | |||
59 | /* in litmus/litmus.c */ | ||
60 | int switch_sched_plugin(struct sched_plugin*); | ||
61 | |||
62 | static int proc_write_curr(struct file *file, | ||
63 | const char *buffer, | ||
64 | unsigned long count, | ||
65 | void *data) | ||
66 | { | ||
67 | int len, ret; | ||
68 | char name[65]; | ||
69 | struct sched_plugin* found; | ||
70 | |||
71 | if(count > 64) | ||
72 | len = 64; | ||
73 | else | ||
74 | len = count; | ||
75 | |||
76 | if(copy_from_user(name, buffer, len)) | ||
77 | return -EFAULT; | ||
78 | |||
79 | name[len] = '\0'; | ||
80 | /* chomp name */ | ||
81 | if (len > 1 && name[len - 1] == '\n') | ||
82 | name[len - 1] = '\0'; | ||
83 | |||
84 | found = find_sched_plugin(name); | ||
85 | |||
86 | if (found) { | ||
87 | ret = switch_sched_plugin(found); | ||
88 | if (ret != 0) | ||
89 | printk(KERN_INFO "Could not switch plugin: %d\n", ret); | ||
90 | } else | ||
91 | printk(KERN_INFO "Plugin '%s' is unknown.\n", name); | ||
92 | |||
93 | return len; | ||
94 | } | ||
95 | |||
96 | static int proc_read_cluster_size(char *page, char **start, | ||
97 | off_t off, int count, | ||
98 | int *eof, void *data) | ||
99 | { | ||
100 | int len; | ||
101 | if (cluster_cache_index == 2) | ||
102 | len = snprintf(page, PAGE_SIZE, "L2\n"); | ||
103 | else if (cluster_cache_index == 3) | ||
104 | len = snprintf(page, PAGE_SIZE, "L3\n"); | ||
105 | else if (cluster_cache_index == 1) | ||
106 | len = snprintf(page, PAGE_SIZE, "L1\n"); | ||
107 | else | ||
108 | len = snprintf(page, PAGE_SIZE, "ALL\n"); | ||
109 | |||
110 | return len; | ||
111 | } | ||
112 | |||
113 | static int proc_write_cluster_size(struct file *file, | ||
114 | const char *buffer, | ||
115 | unsigned long count, | ||
116 | void *data) | ||
117 | { | ||
118 | int len; | ||
119 | /* L2, L3 */ | ||
120 | char cache_name[33]; | ||
121 | |||
122 | if(count > 32) | ||
123 | len = 32; | ||
124 | else | ||
125 | len = count; | ||
126 | |||
127 | if(copy_from_user(cache_name, buffer, len)) | ||
128 | return -EFAULT; | ||
129 | |||
130 | cache_name[len] = '\0'; | ||
131 | /* chomp name */ | ||
132 | if (len > 1 && cache_name[len - 1] == '\n') | ||
133 | cache_name[len - 1] = '\0'; | ||
134 | |||
135 | /* do a quick and dirty comparison to find the cluster size */ | ||
136 | if (!strcmp(cache_name, "L2")) | ||
137 | cluster_cache_index = 2; | ||
138 | else if (!strcmp(cache_name, "L3")) | ||
139 | cluster_cache_index = 3; | ||
140 | else if (!strcmp(cache_name, "L1")) | ||
141 | cluster_cache_index = 1; | ||
142 | else if (!strcmp(cache_name, "ALL")) | ||
143 | cluster_cache_index = num_online_cpus(); | ||
144 | else | ||
145 | printk(KERN_INFO "Cluster '%s' is unknown.\n", cache_name); | ||
146 | |||
147 | return len; | ||
148 | } | ||
149 | |||
150 | #ifdef CONFIG_RELEASE_MASTER | ||
151 | static int proc_read_release_master(char *page, char **start, | ||
152 | off_t off, int count, | ||
153 | int *eof, void *data) | ||
154 | { | ||
155 | int len, master; | ||
156 | master = atomic_read(&release_master_cpu); | ||
157 | if (master == NO_CPU) | ||
158 | len = snprintf(page, PAGE_SIZE, "NO_CPU\n"); | ||
159 | else | ||
160 | len = snprintf(page, PAGE_SIZE, "%d\n", master); | ||
161 | return len; | ||
162 | } | ||
163 | |||
164 | static int proc_write_release_master(struct file *file, | ||
165 | const char *buffer, | ||
166 | unsigned long count, | ||
167 | void *data) | ||
168 | { | ||
169 | int cpu, err, online = 0; | ||
170 | char msg[64]; | ||
171 | |||
172 | if (count > 63) | ||
173 | return -EINVAL; | ||
174 | |||
175 | if (copy_from_user(msg, buffer, count)) | ||
176 | return -EFAULT; | ||
177 | |||
178 | /* terminate */ | ||
179 | msg[count] = '\0'; | ||
180 | /* chomp */ | ||
181 | if (count > 1 && msg[count - 1] == '\n') | ||
182 | msg[count - 1] = '\0'; | ||
183 | |||
184 | if (strcmp(msg, "NO_CPU") == 0) { | ||
185 | atomic_set(&release_master_cpu, NO_CPU); | ||
186 | return count; | ||
187 | } else { | ||
188 | err = sscanf(msg, "%d", &cpu); | ||
189 | if (err == 1 && cpu >= 0 && (online = cpu_online(cpu))) { | ||
190 | atomic_set(&release_master_cpu, cpu); | ||
191 | return count; | ||
192 | } else { | ||
193 | TRACE("invalid release master: '%s' " | ||
194 | "(err:%d cpu:%d online:%d)\n", | ||
195 | msg, err, cpu, online); | ||
196 | return -EINVAL; | ||
197 | } | ||
198 | } | ||
199 | } | ||
200 | #endif | ||
201 | |||
202 | int __init init_litmus_proc(void) | ||
203 | { | ||
204 | litmus_dir = proc_mkdir("litmus", NULL); | ||
205 | if (!litmus_dir) { | ||
206 | printk(KERN_ERR "Could not allocate LITMUS^RT procfs entry.\n"); | ||
207 | return -ENOMEM; | ||
208 | } | ||
209 | |||
210 | curr_file = create_proc_entry("active_plugin", | ||
211 | 0644, litmus_dir); | ||
212 | if (!curr_file) { | ||
213 | printk(KERN_ERR "Could not allocate active_plugin " | ||
214 | "procfs entry.\n"); | ||
215 | return -ENOMEM; | ||
216 | } | ||
217 | curr_file->read_proc = proc_read_curr; | ||
218 | curr_file->write_proc = proc_write_curr; | ||
219 | |||
220 | #ifdef CONFIG_RELEASE_MASTER | ||
221 | release_master_file = create_proc_entry("release_master", | ||
222 | 0644, litmus_dir); | ||
223 | if (!release_master_file) { | ||
224 | printk(KERN_ERR "Could not allocate release_master " | ||
225 | "procfs entry.\n"); | ||
226 | return -ENOMEM; | ||
227 | } | ||
228 | release_master_file->read_proc = proc_read_release_master; | ||
229 | release_master_file->write_proc = proc_write_release_master; | ||
230 | #endif | ||
231 | |||
232 | clus_cache_idx_file = create_proc_entry("cluster_cache", | ||
233 | 0644, litmus_dir); | ||
234 | if (!clus_cache_idx_file) { | ||
235 | printk(KERN_ERR "Could not allocate cluster_cache " | ||
236 | "procfs entry.\n"); | ||
237 | return -ENOMEM; | ||
238 | } | ||
239 | clus_cache_idx_file->read_proc = proc_read_cluster_size; | ||
240 | clus_cache_idx_file->write_proc = proc_write_cluster_size; | ||
241 | |||
242 | stat_file = create_proc_read_entry("stats", 0444, litmus_dir, | ||
243 | proc_read_stats, NULL); | ||
244 | |||
245 | plugs_dir = proc_mkdir("plugins", litmus_dir); | ||
246 | if (!plugs_dir){ | ||
247 | printk(KERN_ERR "Could not allocate plugins directory " | ||
248 | "procfs entry.\n"); | ||
249 | return -ENOMEM; | ||
250 | } | ||
251 | |||
252 | plugs_file = create_proc_read_entry("loaded", 0444, plugs_dir, | ||
253 | proc_read_plugins, NULL); | ||
254 | |||
255 | return 0; | ||
256 | } | ||
257 | |||
258 | void exit_litmus_proc(void) | ||
259 | { | ||
260 | if (plugs_file) | ||
261 | remove_proc_entry("loaded", plugs_dir); | ||
262 | if (plugs_dir) | ||
263 | remove_proc_entry("plugins", litmus_dir); | ||
264 | if (stat_file) | ||
265 | remove_proc_entry("stats", litmus_dir); | ||
266 | if (curr_file) | ||
267 | remove_proc_entry("active_plugin", litmus_dir); | ||
268 | if (clus_cache_idx_file) | ||
269 | remove_proc_entry("cluster_cache", litmus_dir); | ||
270 | #ifdef CONFIG_RELEASE_MASTER | ||
271 | if (release_master_file) | ||
272 | remove_proc_entry("release_master", litmus_dir); | ||
273 | #endif | ||
274 | if (litmus_dir) | ||
275 | remove_proc_entry("litmus", NULL); | ||
276 | } | ||
277 | |||
278 | long make_plugin_proc_dir(struct sched_plugin* plugin, | ||
279 | struct proc_dir_entry** pde_in) | ||
280 | { | ||
281 | struct proc_dir_entry *pde_new = NULL; | ||
282 | long rv; | ||
283 | |||
284 | if (!plugin || !plugin->plugin_name){ | ||
285 | printk(KERN_ERR "Invalid plugin struct passed to %s.\n", | ||
286 | __func__); | ||
287 | rv = -EINVAL; | ||
288 | goto out_no_pde; | ||
289 | } | ||
290 | |||
291 | if (!plugs_dir){ | ||
292 | printk(KERN_ERR "Could not make plugin sub-directory, because " | ||
293 | "/proc/litmus/plugins does not exist.\n"); | ||
294 | rv = -ENOENT; | ||
295 | goto out_no_pde; | ||
296 | } | ||
297 | |||
298 | pde_new = proc_mkdir(plugin->plugin_name, plugs_dir); | ||
299 | if (!pde_new){ | ||
300 | printk(KERN_ERR "Could not make plugin sub-directory: " | ||
301 | "out of memory?.\n"); | ||
302 | rv = -ENOMEM; | ||
303 | goto out_no_pde; | ||
304 | } | ||
305 | |||
306 | rv = 0; | ||
307 | *pde_in = pde_new; | ||
308 | goto out_ok; | ||
309 | |||
310 | out_no_pde: | ||
311 | *pde_in = NULL; | ||
312 | out_ok: | ||
313 | return rv; | ||
314 | } | ||
315 | |||
316 | void remove_plugin_proc_dir(struct sched_plugin* plugin) | ||
317 | { | ||
318 | if (!plugin || !plugin->plugin_name){ | ||
319 | printk(KERN_ERR "Invalid plugin struct passed to %s.\n", | ||
320 | __func__); | ||
321 | return; | ||
322 | } | ||
323 | remove_proc_entry(plugin->plugin_name, plugs_dir); | ||
324 | } | ||