Amir Vadai | 122733a | 2012-07-18 22:33:50 +0000 | [diff] [blame] | 1 | #ifndef __LINUX_CPU_RMAP_H |
| 2 | #define __LINUX_CPU_RMAP_H |
| 3 | |
Ben Hutchings | c39649c | 2011-01-19 11:03:25 +0000 | [diff] [blame] | 4 | /* |
| 5 | * cpu_rmap.c: CPU affinity reverse-map support |
| 6 | * Copyright 2011 Solarflare Communications Inc. |
| 7 | * |
| 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. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/cpumask.h> |
| 14 | #include <linux/gfp.h> |
| 15 | #include <linux/slab.h> |
David Decotigny | 896f97e | 2013-01-11 14:31:36 -0800 | [diff] [blame] | 16 | #include <linux/kref.h> |
Ben Hutchings | c39649c | 2011-01-19 11:03:25 +0000 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * struct cpu_rmap - CPU affinity reverse-map |
David Decotigny | 896f97e | 2013-01-11 14:31:36 -0800 | [diff] [blame] | 20 | * @refcount: kref for object |
Ben Hutchings | c39649c | 2011-01-19 11:03:25 +0000 | [diff] [blame] | 21 | * @size: Number of objects to be reverse-mapped |
| 22 | * @used: Number of objects added |
| 23 | * @obj: Pointer to array of object pointers |
| 24 | * @near: For each CPU, the index and distance to the nearest object, |
| 25 | * based on affinity masks |
| 26 | */ |
| 27 | struct cpu_rmap { |
David Decotigny | 896f97e | 2013-01-11 14:31:36 -0800 | [diff] [blame] | 28 | struct kref refcount; |
Ben Hutchings | c39649c | 2011-01-19 11:03:25 +0000 | [diff] [blame] | 29 | u16 size, used; |
| 30 | void **obj; |
| 31 | struct { |
| 32 | u16 index; |
| 33 | u16 dist; |
| 34 | } near[0]; |
| 35 | }; |
| 36 | #define CPU_RMAP_DIST_INF 0xffff |
| 37 | |
| 38 | extern struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags); |
David Decotigny | 896f97e | 2013-01-11 14:31:36 -0800 | [diff] [blame] | 39 | extern int cpu_rmap_put(struct cpu_rmap *rmap); |
Ben Hutchings | c39649c | 2011-01-19 11:03:25 +0000 | [diff] [blame] | 40 | |
| 41 | extern int cpu_rmap_add(struct cpu_rmap *rmap, void *obj); |
| 42 | extern int cpu_rmap_update(struct cpu_rmap *rmap, u16 index, |
| 43 | const struct cpumask *affinity); |
| 44 | |
| 45 | static inline u16 cpu_rmap_lookup_index(struct cpu_rmap *rmap, unsigned int cpu) |
| 46 | { |
| 47 | return rmap->near[cpu].index; |
| 48 | } |
| 49 | |
| 50 | static inline void *cpu_rmap_lookup_obj(struct cpu_rmap *rmap, unsigned int cpu) |
| 51 | { |
| 52 | return rmap->obj[rmap->near[cpu].index]; |
| 53 | } |
| 54 | |
Ben Hutchings | c39649c | 2011-01-19 11:03:25 +0000 | [diff] [blame] | 55 | /** |
| 56 | * alloc_irq_cpu_rmap - allocate CPU affinity reverse-map for IRQs |
| 57 | * @size: Number of objects to be mapped |
| 58 | * |
| 59 | * Must be called in process context. |
| 60 | */ |
| 61 | static inline struct cpu_rmap *alloc_irq_cpu_rmap(unsigned int size) |
| 62 | { |
| 63 | return alloc_cpu_rmap(size, GFP_KERNEL); |
| 64 | } |
| 65 | extern void free_irq_cpu_rmap(struct cpu_rmap *rmap); |
| 66 | |
| 67 | extern int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq); |
| 68 | |
Amir Vadai | 122733a | 2012-07-18 22:33:50 +0000 | [diff] [blame] | 69 | #endif /* __LINUX_CPU_RMAP_H */ |