1 #ifndef __LINUX_CPU_RMAP_H
2 #define __LINUX_CPU_RMAP_H
5 * cpu_rmap.c: CPU affinity reverse-map support
6 * Copyright 2011 Solarflare Communications Inc.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation, incorporated herein by reference.
13 #include <linux/cpumask.h>
14 #include <linux/gfp.h>
15 #include <linux/slab.h>
18 * struct cpu_rmap - CPU affinity reverse-map
19 * @size: Number of objects to be reverse-mapped
20 * @used: Number of objects added
21 * @obj: Pointer to array of object pointers
22 * @near: For each CPU, the index and distance to the nearest object,
23 * based on affinity masks
33 #define CPU_RMAP_DIST_INF 0xffff
35 extern struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags);
38 * free_cpu_rmap - free CPU affinity reverse-map
39 * @rmap: Reverse-map allocated with alloc_cpu_rmap(), or %NULL
41 static inline void free_cpu_rmap(struct cpu_rmap *rmap)
46 extern int cpu_rmap_add(struct cpu_rmap *rmap, void *obj);
47 extern int cpu_rmap_update(struct cpu_rmap *rmap, u16 index,
48 const struct cpumask *affinity);
50 static inline u16 cpu_rmap_lookup_index(struct cpu_rmap *rmap, unsigned int cpu)
52 return rmap->near[cpu].index;
55 static inline void *cpu_rmap_lookup_obj(struct cpu_rmap *rmap, unsigned int cpu)
57 return rmap->obj[rmap->near[cpu].index];
60 #ifdef CONFIG_GENERIC_HARDIRQS
63 * alloc_irq_cpu_rmap - allocate CPU affinity reverse-map for IRQs
64 * @size: Number of objects to be mapped
66 * Must be called in process context.
68 static inline struct cpu_rmap *alloc_irq_cpu_rmap(unsigned int size)
70 return alloc_cpu_rmap(size, GFP_KERNEL);
72 extern void free_irq_cpu_rmap(struct cpu_rmap *rmap);
74 extern int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq);
77 #endif /* __LINUX_CPU_RMAP_H */