Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 #ifndef __LINUX_CPU_RMAP_H
0003 #define __LINUX_CPU_RMAP_H
0004 
0005 /*
0006  * cpu_rmap.c: CPU affinity reverse-map support
0007  * Copyright 2011 Solarflare Communications Inc.
0008  */
0009 
0010 #include <linux/cpumask.h>
0011 #include <linux/gfp.h>
0012 #include <linux/slab.h>
0013 #include <linux/kref.h>
0014 
0015 /**
0016  * struct cpu_rmap - CPU affinity reverse-map
0017  * @refcount: kref for object
0018  * @size: Number of objects to be reverse-mapped
0019  * @used: Number of objects added
0020  * @obj: Pointer to array of object pointers
0021  * @near: For each CPU, the index and distance to the nearest object,
0022  *      based on affinity masks
0023  */
0024 struct cpu_rmap {
0025     struct kref refcount;
0026     u16     size, used;
0027     void        **obj;
0028     struct {
0029         u16 index;
0030         u16 dist;
0031     }       near[];
0032 };
0033 #define CPU_RMAP_DIST_INF 0xffff
0034 
0035 extern struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags);
0036 extern int cpu_rmap_put(struct cpu_rmap *rmap);
0037 
0038 extern int cpu_rmap_add(struct cpu_rmap *rmap, void *obj);
0039 extern int cpu_rmap_update(struct cpu_rmap *rmap, u16 index,
0040                const struct cpumask *affinity);
0041 
0042 static inline u16 cpu_rmap_lookup_index(struct cpu_rmap *rmap, unsigned int cpu)
0043 {
0044     return rmap->near[cpu].index;
0045 }
0046 
0047 static inline void *cpu_rmap_lookup_obj(struct cpu_rmap *rmap, unsigned int cpu)
0048 {
0049     return rmap->obj[rmap->near[cpu].index];
0050 }
0051 
0052 /**
0053  * alloc_irq_cpu_rmap - allocate CPU affinity reverse-map for IRQs
0054  * @size: Number of objects to be mapped
0055  *
0056  * Must be called in process context.
0057  */
0058 static inline struct cpu_rmap *alloc_irq_cpu_rmap(unsigned int size)
0059 {
0060     return alloc_cpu_rmap(size, GFP_KERNEL);
0061 }
0062 extern void free_irq_cpu_rmap(struct cpu_rmap *rmap);
0063 
0064 extern int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq);
0065 
0066 #endif /* __LINUX_CPU_RMAP_H */