aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/cpu_rmap.h
diff options
context:
space:
mode:
authorBen Hutchings <bhutchings@solarflare.com>2011-01-19 06:03:25 -0500
committerDavid S. Miller <davem@davemloft.net>2011-01-24 17:51:56 -0500
commitc39649c331c70952700f99832b03f87e9d7f5b4b (patch)
tree19ba9cea5102595e42bcd043aa53eb666ea834fa /include/linux/cpu_rmap.h
parentc2df88cbb43c25db27fbbf94e92318bdad018f3e (diff)
lib: cpu_rmap: CPU affinity reverse-mapping
When initiating I/O on a multiqueue and multi-IRQ device, we may want to select a queue for which the response will be handled on the same or a nearby CPU. This requires a reverse-map of IRQ affinity. Add library functions to support a generic reverse-mapping from CPUs to objects with affinity and the specific case where the objects are IRQs. Signed-off-by: Ben Hutchings <bhutchings@solarflare.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/cpu_rmap.h')
-rw-r--r--include/linux/cpu_rmap.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/include/linux/cpu_rmap.h b/include/linux/cpu_rmap.h
new file mode 100644
index 000000000000..473771a528c0
--- /dev/null
+++ b/include/linux/cpu_rmap.h
@@ -0,0 +1,73 @@
1/*
2 * cpu_rmap.c: CPU affinity reverse-map support
3 * Copyright 2011 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10#include <linux/cpumask.h>
11#include <linux/gfp.h>
12#include <linux/slab.h>
13
14/**
15 * struct cpu_rmap - CPU affinity reverse-map
16 * @size: Number of objects to be reverse-mapped
17 * @used: Number of objects added
18 * @obj: Pointer to array of object pointers
19 * @near: For each CPU, the index and distance to the nearest object,
20 * based on affinity masks
21 */
22struct cpu_rmap {
23 u16 size, used;
24 void **obj;
25 struct {
26 u16 index;
27 u16 dist;
28 } near[0];
29};
30#define CPU_RMAP_DIST_INF 0xffff
31
32extern struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags);
33
34/**
35 * free_cpu_rmap - free CPU affinity reverse-map
36 * @rmap: Reverse-map allocated with alloc_cpu_rmap(), or %NULL
37 */
38static inline void free_cpu_rmap(struct cpu_rmap *rmap)
39{
40 kfree(rmap);
41}
42
43extern int cpu_rmap_add(struct cpu_rmap *rmap, void *obj);
44extern int cpu_rmap_update(struct cpu_rmap *rmap, u16 index,
45 const struct cpumask *affinity);
46
47static inline u16 cpu_rmap_lookup_index(struct cpu_rmap *rmap, unsigned int cpu)
48{
49 return rmap->near[cpu].index;
50}
51
52static inline void *cpu_rmap_lookup_obj(struct cpu_rmap *rmap, unsigned int cpu)
53{
54 return rmap->obj[rmap->near[cpu].index];
55}
56
57#ifdef CONFIG_GENERIC_HARDIRQS
58
59/**
60 * alloc_irq_cpu_rmap - allocate CPU affinity reverse-map for IRQs
61 * @size: Number of objects to be mapped
62 *
63 * Must be called in process context.
64 */
65static inline struct cpu_rmap *alloc_irq_cpu_rmap(unsigned int size)
66{
67 return alloc_cpu_rmap(size, GFP_KERNEL);
68}
69extern void free_irq_cpu_rmap(struct cpu_rmap *rmap);
70
71extern int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq);
72
73#endif