blob: 854f9bd578bf13b1d0e698c4cf5de62f7d8ca335 [file] [log] [blame]
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01001/*
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
14struct 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
24extern struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags);
25
26static inline void free_cpu_rmap(struct cpu_rmap *rmap)
27{
28 kfree(rmap);
29}
30
31extern int cpu_rmap_add(struct cpu_rmap *rmap, void *obj);
32extern int cpu_rmap_update(struct cpu_rmap *rmap, u16 index,
33 const struct cpumask *affinity);
34
35static inline u16 cpu_rmap_lookup_index(struct cpu_rmap *rmap, unsigned int cpu)
36{
37 return rmap->near[cpu].index;
38}
39
40static 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
47static inline struct cpu_rmap *alloc_irq_cpu_rmap(unsigned int size)
48{
49 return alloc_cpu_rmap(size, GFP_KERNEL);
50}
51extern void free_irq_cpu_rmap(struct cpu_rmap *rmap);
52
53extern int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq);
54
55#endif