]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame_incremental - kernel/irq/proc.c
genirq: Add CPU mask affinity hint
[mirror_ubuntu-jammy-kernel.git] / kernel / irq / proc.c
... / ...
CommitLineData
1/*
2 * linux/kernel/irq/proc.c
3 *
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
5 *
6 * This file contains the /proc/irq/ handling code.
7 */
8
9#include <linux/irq.h>
10#include <linux/gfp.h>
11#include <linux/proc_fs.h>
12#include <linux/seq_file.h>
13#include <linux/interrupt.h>
14
15#include "internals.h"
16
17static struct proc_dir_entry *root_irq_dir;
18
19#ifdef CONFIG_SMP
20
21static int irq_affinity_proc_show(struct seq_file *m, void *v)
22{
23 struct irq_desc *desc = irq_to_desc((long)m->private);
24 const struct cpumask *mask = desc->affinity;
25
26#ifdef CONFIG_GENERIC_PENDING_IRQ
27 if (desc->status & IRQ_MOVE_PENDING)
28 mask = desc->pending_mask;
29#endif
30 seq_cpumask(m, mask);
31 seq_putc(m, '\n');
32 return 0;
33}
34
35static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)
36{
37 struct irq_desc *desc = irq_to_desc((long)m->private);
38 unsigned long flags;
39 cpumask_var_t mask;
40
41 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
42 return -ENOMEM;
43
44 raw_spin_lock_irqsave(&desc->lock, flags);
45 if (desc->affinity_hint)
46 cpumask_copy(mask, desc->affinity_hint);
47 else
48 cpumask_setall(mask);
49 raw_spin_unlock_irqrestore(&desc->lock, flags);
50
51 seq_cpumask(m, mask);
52 seq_putc(m, '\n');
53 free_cpumask_var(mask);
54
55 return 0;
56}
57
58#ifndef is_affinity_mask_valid
59#define is_affinity_mask_valid(val) 1
60#endif
61
62int no_irq_affinity;
63static ssize_t irq_affinity_proc_write(struct file *file,
64 const char __user *buffer, size_t count, loff_t *pos)
65{
66 unsigned int irq = (int)(long)PDE(file->f_path.dentry->d_inode)->data;
67 cpumask_var_t new_value;
68 int err;
69
70 if (!irq_to_desc(irq)->chip->set_affinity || no_irq_affinity ||
71 irq_balancing_disabled(irq))
72 return -EIO;
73
74 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
75 return -ENOMEM;
76
77 err = cpumask_parse_user(buffer, count, new_value);
78 if (err)
79 goto free_cpumask;
80
81 if (!is_affinity_mask_valid(new_value)) {
82 err = -EINVAL;
83 goto free_cpumask;
84 }
85
86 /*
87 * Do not allow disabling IRQs completely - it's a too easy
88 * way to make the system unusable accidentally :-) At least
89 * one online CPU still has to be targeted.
90 */
91 if (!cpumask_intersects(new_value, cpu_online_mask)) {
92 /* Special case for empty set - allow the architecture
93 code to set default SMP affinity. */
94 err = irq_select_affinity_usr(irq) ? -EINVAL : count;
95 } else {
96 irq_set_affinity(irq, new_value);
97 err = count;
98 }
99
100free_cpumask:
101 free_cpumask_var(new_value);
102 return err;
103}
104
105static int irq_affinity_proc_open(struct inode *inode, struct file *file)
106{
107 return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
108}
109
110static int irq_affinity_hint_proc_open(struct inode *inode, struct file *file)
111{
112 return single_open(file, irq_affinity_hint_proc_show, PDE(inode)->data);
113}
114
115static const struct file_operations irq_affinity_proc_fops = {
116 .open = irq_affinity_proc_open,
117 .read = seq_read,
118 .llseek = seq_lseek,
119 .release = single_release,
120 .write = irq_affinity_proc_write,
121};
122
123static const struct file_operations irq_affinity_hint_proc_fops = {
124 .open = irq_affinity_hint_proc_open,
125 .read = seq_read,
126 .llseek = seq_lseek,
127 .release = single_release,
128};
129
130static int default_affinity_show(struct seq_file *m, void *v)
131{
132 seq_cpumask(m, irq_default_affinity);
133 seq_putc(m, '\n');
134 return 0;
135}
136
137static ssize_t default_affinity_write(struct file *file,
138 const char __user *buffer, size_t count, loff_t *ppos)
139{
140 cpumask_var_t new_value;
141 int err;
142
143 if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
144 return -ENOMEM;
145
146 err = cpumask_parse_user(buffer, count, new_value);
147 if (err)
148 goto out;
149
150 if (!is_affinity_mask_valid(new_value)) {
151 err = -EINVAL;
152 goto out;
153 }
154
155 /*
156 * Do not allow disabling IRQs completely - it's a too easy
157 * way to make the system unusable accidentally :-) At least
158 * one online CPU still has to be targeted.
159 */
160 if (!cpumask_intersects(new_value, cpu_online_mask)) {
161 err = -EINVAL;
162 goto out;
163 }
164
165 cpumask_copy(irq_default_affinity, new_value);
166 err = count;
167
168out:
169 free_cpumask_var(new_value);
170 return err;
171}
172
173static int default_affinity_open(struct inode *inode, struct file *file)
174{
175 return single_open(file, default_affinity_show, PDE(inode)->data);
176}
177
178static const struct file_operations default_affinity_proc_fops = {
179 .open = default_affinity_open,
180 .read = seq_read,
181 .llseek = seq_lseek,
182 .release = single_release,
183 .write = default_affinity_write,
184};
185
186static int irq_node_proc_show(struct seq_file *m, void *v)
187{
188 struct irq_desc *desc = irq_to_desc((long) m->private);
189
190 seq_printf(m, "%d\n", desc->node);
191 return 0;
192}
193
194static int irq_node_proc_open(struct inode *inode, struct file *file)
195{
196 return single_open(file, irq_node_proc_show, PDE(inode)->data);
197}
198
199static const struct file_operations irq_node_proc_fops = {
200 .open = irq_node_proc_open,
201 .read = seq_read,
202 .llseek = seq_lseek,
203 .release = single_release,
204};
205#endif
206
207static int irq_spurious_proc_show(struct seq_file *m, void *v)
208{
209 struct irq_desc *desc = irq_to_desc((long) m->private);
210
211 seq_printf(m, "count %u\n" "unhandled %u\n" "last_unhandled %u ms\n",
212 desc->irq_count, desc->irqs_unhandled,
213 jiffies_to_msecs(desc->last_unhandled));
214 return 0;
215}
216
217static int irq_spurious_proc_open(struct inode *inode, struct file *file)
218{
219 return single_open(file, irq_spurious_proc_show, NULL);
220}
221
222static const struct file_operations irq_spurious_proc_fops = {
223 .open = irq_spurious_proc_open,
224 .read = seq_read,
225 .llseek = seq_lseek,
226 .release = single_release,
227};
228
229#define MAX_NAMELEN 128
230
231static int name_unique(unsigned int irq, struct irqaction *new_action)
232{
233 struct irq_desc *desc = irq_to_desc(irq);
234 struct irqaction *action;
235 unsigned long flags;
236 int ret = 1;
237
238 raw_spin_lock_irqsave(&desc->lock, flags);
239 for (action = desc->action ; action; action = action->next) {
240 if ((action != new_action) && action->name &&
241 !strcmp(new_action->name, action->name)) {
242 ret = 0;
243 break;
244 }
245 }
246 raw_spin_unlock_irqrestore(&desc->lock, flags);
247 return ret;
248}
249
250void register_handler_proc(unsigned int irq, struct irqaction *action)
251{
252 char name [MAX_NAMELEN];
253 struct irq_desc *desc = irq_to_desc(irq);
254
255 if (!desc->dir || action->dir || !action->name ||
256 !name_unique(irq, action))
257 return;
258
259 memset(name, 0, MAX_NAMELEN);
260 snprintf(name, MAX_NAMELEN, "%s", action->name);
261
262 /* create /proc/irq/1234/handler/ */
263 action->dir = proc_mkdir(name, desc->dir);
264}
265
266#undef MAX_NAMELEN
267
268#define MAX_NAMELEN 10
269
270void register_irq_proc(unsigned int irq, struct irq_desc *desc)
271{
272 char name [MAX_NAMELEN];
273
274 if (!root_irq_dir || (desc->chip == &no_irq_chip) || desc->dir)
275 return;
276
277 memset(name, 0, MAX_NAMELEN);
278 sprintf(name, "%d", irq);
279
280 /* create /proc/irq/1234 */
281 desc->dir = proc_mkdir(name, root_irq_dir);
282 if (!desc->dir)
283 return;
284
285#ifdef CONFIG_SMP
286 /* create /proc/irq/<irq>/smp_affinity */
287 proc_create_data("smp_affinity", 0600, desc->dir,
288 &irq_affinity_proc_fops, (void *)(long)irq);
289
290 /* create /proc/irq/<irq>/affinity_hint */
291 proc_create_data("affinity_hint", 0400, desc->dir,
292 &irq_affinity_hint_proc_fops, (void *)(long)irq);
293
294 proc_create_data("node", 0444, desc->dir,
295 &irq_node_proc_fops, (void *)(long)irq);
296#endif
297
298 proc_create_data("spurious", 0444, desc->dir,
299 &irq_spurious_proc_fops, (void *)(long)irq);
300}
301
302#undef MAX_NAMELEN
303
304void unregister_handler_proc(unsigned int irq, struct irqaction *action)
305{
306 if (action->dir) {
307 struct irq_desc *desc = irq_to_desc(irq);
308
309 remove_proc_entry(action->dir->name, desc->dir);
310 }
311}
312
313static void register_default_affinity_proc(void)
314{
315#ifdef CONFIG_SMP
316 proc_create("irq/default_smp_affinity", 0600, NULL,
317 &default_affinity_proc_fops);
318#endif
319}
320
321void init_irq_proc(void)
322{
323 unsigned int irq;
324 struct irq_desc *desc;
325
326 /* create /proc/irq */
327 root_irq_dir = proc_mkdir("irq", NULL);
328 if (!root_irq_dir)
329 return;
330
331 register_default_affinity_proc();
332
333 /*
334 * Create entries for all existing IRQs.
335 */
336 for_each_irq_desc(irq, desc) {
337 if (!desc)
338 continue;
339
340 register_irq_proc(irq, desc);
341 }
342}
343