sched: Fix wake_affine() vs RT tasks
[linux/fpc-iii.git] / kernel / irq / proc.c
blob692363dd591f0c447d26b36318889f43bbe20ac3
1 /*
2 * linux/kernel/irq/proc.c
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
6 * This file contains the /proc/irq/ handling code.
7 */
9 #include <linux/irq.h>
10 #include <linux/proc_fs.h>
11 #include <linux/seq_file.h>
12 #include <linux/interrupt.h>
14 #include "internals.h"
16 static struct proc_dir_entry *root_irq_dir;
18 #ifdef CONFIG_SMP
20 static int irq_affinity_proc_show(struct seq_file *m, void *v)
22 struct irq_desc *desc = irq_to_desc((long)m->private);
23 const struct cpumask *mask = desc->affinity;
25 #ifdef CONFIG_GENERIC_PENDING_IRQ
26 if (desc->status & IRQ_MOVE_PENDING)
27 mask = desc->pending_mask;
28 #endif
29 seq_cpumask(m, mask);
30 seq_putc(m, '\n');
31 return 0;
34 #ifndef is_affinity_mask_valid
35 #define is_affinity_mask_valid(val) 1
36 #endif
38 int no_irq_affinity;
39 static ssize_t irq_affinity_proc_write(struct file *file,
40 const char __user *buffer, size_t count, loff_t *pos)
42 unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data;
43 cpumask_var_t new_value;
44 int err;
46 if (!irq_to_desc(irq)->chip->set_affinity || no_irq_affinity ||
47 irq_balancing_disabled(irq))
48 return -EIO;
50 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
51 return -ENOMEM;
53 err = cpumask_parse_user(buffer, count, new_value);
54 if (err)
55 goto free_cpumask;
57 if (!is_affinity_mask_valid(new_value)) {
58 err = -EINVAL;
59 goto free_cpumask;
63 * Do not allow disabling IRQs completely - it's a too easy
64 * way to make the system unusable accidentally :-) At least
65 * one online CPU still has to be targeted.
67 if (!cpumask_intersects(new_value, cpu_online_mask)) {
68 /* Special case for empty set - allow the architecture
69 code to set default SMP affinity. */
70 err = irq_select_affinity_usr(irq) ? -EINVAL : count;
71 } else {
72 irq_set_affinity(irq, new_value);
73 err = count;
76 free_cpumask:
77 free_cpumask_var(new_value);
78 return err;
81 static int irq_affinity_proc_open(struct inode *inode, struct file *file)
83 return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
86 static const struct file_operations irq_affinity_proc_fops = {
87 .open = irq_affinity_proc_open,
88 .read = seq_read,
89 .llseek = seq_lseek,
90 .release = single_release,
91 .write = irq_affinity_proc_write,
94 static int default_affinity_show(struct seq_file *m, void *v)
96 seq_cpumask(m, irq_default_affinity);
97 seq_putc(m, '\n');
98 return 0;
101 static ssize_t default_affinity_write(struct file *file,
102 const char __user *buffer, size_t count, loff_t *ppos)
104 cpumask_var_t new_value;
105 int err;
107 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
108 return -ENOMEM;
110 err = cpumask_parse_user(buffer, count, new_value);
111 if (err)
112 goto out;
114 if (!is_affinity_mask_valid(new_value)) {
115 err = -EINVAL;
116 goto out;
120 * Do not allow disabling IRQs completely - it's a too easy
121 * way to make the system unusable accidentally :-) At least
122 * one online CPU still has to be targeted.
124 if (!cpumask_intersects(new_value, cpu_online_mask)) {
125 err = -EINVAL;
126 goto out;
129 cpumask_copy(irq_default_affinity, new_value);
130 err = count;
132 out:
133 free_cpumask_var(new_value);
134 return err;
137 static int default_affinity_open(struct inode *inode, struct file *file)
139 return single_open(file, default_affinity_show, NULL);
142 static const struct file_operations default_affinity_proc_fops = {
143 .open = default_affinity_open,
144 .read = seq_read,
145 .llseek = seq_lseek,
146 .release = single_release,
147 .write = default_affinity_write,
149 #endif
151 static int irq_spurious_read(char *page, char **start, off_t off,
152 int count, int *eof, void *data)
154 struct irq_desc *desc = irq_to_desc((long) data);
155 return sprintf(page, "count %u\n"
156 "unhandled %u\n"
157 "last_unhandled %u ms\n",
158 desc->irq_count,
159 desc->irqs_unhandled,
160 jiffies_to_msecs(desc->last_unhandled));
163 #define MAX_NAMELEN 128
165 static int name_unique(unsigned int irq, struct irqaction *new_action)
167 struct irq_desc *desc = irq_to_desc(irq);
168 struct irqaction *action;
169 unsigned long flags;
170 int ret = 1;
172 spin_lock_irqsave(&desc->lock, flags);
173 for (action = desc->action ; action; action = action->next) {
174 if ((action != new_action) && action->name &&
175 !strcmp(new_action->name, action->name)) {
176 ret = 0;
177 break;
180 spin_unlock_irqrestore(&desc->lock, flags);
181 return ret;
184 void register_handler_proc(unsigned int irq, struct irqaction *action)
186 char name [MAX_NAMELEN];
187 struct irq_desc *desc = irq_to_desc(irq);
189 if (!desc->dir || action->dir || !action->name ||
190 !name_unique(irq, action))
191 return;
193 memset(name, 0, MAX_NAMELEN);
194 snprintf(name, MAX_NAMELEN, "%s", action->name);
196 /* create /proc/irq/1234/handler/ */
197 action->dir = proc_mkdir(name, desc->dir);
200 #undef MAX_NAMELEN
202 #define MAX_NAMELEN 10
204 void register_irq_proc(unsigned int irq, struct irq_desc *desc)
206 char name [MAX_NAMELEN];
207 struct proc_dir_entry *entry;
209 if (!root_irq_dir || (desc->chip == &no_irq_chip) || desc->dir)
210 return;
212 memset(name, 0, MAX_NAMELEN);
213 sprintf(name, "%d", irq);
215 /* create /proc/irq/1234 */
216 desc->dir = proc_mkdir(name, root_irq_dir);
218 #ifdef CONFIG_SMP
219 /* create /proc/irq/<irq>/smp_affinity */
220 proc_create_data("smp_affinity", 0600, desc->dir,
221 &irq_affinity_proc_fops, (void *)(long)irq);
222 #endif
224 entry = create_proc_entry("spurious", 0444, desc->dir);
225 if (entry) {
226 entry->data = (void *)(long)irq;
227 entry->read_proc = irq_spurious_read;
231 #undef MAX_NAMELEN
233 void unregister_handler_proc(unsigned int irq, struct irqaction *action)
235 if (action->dir) {
236 struct irq_desc *desc = irq_to_desc(irq);
238 remove_proc_entry(action->dir->name, desc->dir);
242 static void register_default_affinity_proc(void)
244 #ifdef CONFIG_SMP
245 proc_create("irq/default_smp_affinity", 0600, NULL,
246 &default_affinity_proc_fops);
247 #endif
250 void init_irq_proc(void)
252 unsigned int irq;
253 struct irq_desc *desc;
255 /* create /proc/irq */
256 root_irq_dir = proc_mkdir("irq", NULL);
257 if (!root_irq_dir)
258 return;
260 register_default_affinity_proc();
263 * Create entries for all existing IRQs.
265 for_each_irq_desc(irq, desc) {
266 if (!desc)
267 continue;
269 register_irq_proc(irq, desc);