Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame^] | 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 | struct cpu_rmap { |
| 15 | u16 size, used; |
| 16 | void **obj; |
| 17 | struct { |
| 18 | u16 index; |
| 19 | u16 dist; |
| 20 | } near[0]; |
| 21 | }; |
| 22 | #define CPU_RMAP_DIST_INF 0xffff |
| 23 | |
| 24 | extern struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags); |
| 25 | |
| 26 | static inline void free_cpu_rmap(struct cpu_rmap *rmap) |
| 27 | { |
| 28 | kfree(rmap); |
| 29 | } |
| 30 | |
| 31 | extern int cpu_rmap_add(struct cpu_rmap *rmap, void *obj); |
| 32 | extern int cpu_rmap_update(struct cpu_rmap *rmap, u16 index, |
| 33 | const struct cpumask *affinity); |
| 34 | |
| 35 | static inline u16 cpu_rmap_lookup_index(struct cpu_rmap *rmap, unsigned int cpu) |
| 36 | { |
| 37 | return rmap->near[cpu].index; |
| 38 | } |
| 39 | |
| 40 | static inline void *cpu_rmap_lookup_obj(struct cpu_rmap *rmap, unsigned int cpu) |
| 41 | { |
| 42 | return rmap->obj[rmap->near[cpu].index]; |
| 43 | } |
| 44 | |
| 45 | #ifdef CONFIG_GENERIC_HARDIRQS |
| 46 | |
| 47 | static inline struct cpu_rmap *alloc_irq_cpu_rmap(unsigned int size) |
| 48 | { |
| 49 | return alloc_cpu_rmap(size, GFP_KERNEL); |
| 50 | } |
| 51 | extern void free_irq_cpu_rmap(struct cpu_rmap *rmap); |
| 52 | |
| 53 | extern int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq); |
| 54 | |
| 55 | #endif |