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