2019-06-04 11:11:33 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2012-07-19 02:33:50 +04:00
|
|
|
#ifndef __LINUX_CPU_RMAP_H
|
|
|
|
#define __LINUX_CPU_RMAP_H
|
|
|
|
|
2011-01-19 14:03:25 +03:00
|
|
|
/*
|
|
|
|
* cpu_rmap.c: CPU affinity reverse-map support
|
|
|
|
* Copyright 2011 Solarflare Communications Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/cpumask.h>
|
|
|
|
#include <linux/gfp.h>
|
|
|
|
#include <linux/slab.h>
|
2013-01-12 02:31:36 +04:00
|
|
|
#include <linux/kref.h>
|
2011-01-19 14:03:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct cpu_rmap - CPU affinity reverse-map
|
2013-01-12 02:31:36 +04:00
|
|
|
* @refcount: kref for object
|
2011-01-19 14:03:25 +03:00
|
|
|
* @size: Number of objects to be reverse-mapped
|
|
|
|
* @obj: Pointer to array of object pointers
|
|
|
|
* @near: For each CPU, the index and distance to the nearest object,
|
|
|
|
* based on affinity masks
|
|
|
|
*/
|
|
|
|
struct cpu_rmap {
|
2013-01-12 02:31:36 +04:00
|
|
|
struct kref refcount;
|
2023-02-14 10:29:46 +03:00
|
|
|
u16 size;
|
2011-01-19 14:03:25 +03:00
|
|
|
void **obj;
|
|
|
|
struct {
|
|
|
|
u16 index;
|
|
|
|
u16 dist;
|
2020-03-24 00:58:49 +03:00
|
|
|
} near[];
|
2011-01-19 14:03:25 +03:00
|
|
|
};
|
|
|
|
#define CPU_RMAP_DIST_INF 0xffff
|
|
|
|
|
|
|
|
extern struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags);
|
2013-01-12 02:31:36 +04:00
|
|
|
extern int cpu_rmap_put(struct cpu_rmap *rmap);
|
2011-01-19 14:03:25 +03:00
|
|
|
|
|
|
|
extern int cpu_rmap_add(struct cpu_rmap *rmap, void *obj);
|
|
|
|
extern int cpu_rmap_update(struct cpu_rmap *rmap, u16 index,
|
|
|
|
const struct cpumask *affinity);
|
|
|
|
|
|
|
|
static inline u16 cpu_rmap_lookup_index(struct cpu_rmap *rmap, unsigned int cpu)
|
|
|
|
{
|
|
|
|
return rmap->near[cpu].index;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *cpu_rmap_lookup_obj(struct cpu_rmap *rmap, unsigned int cpu)
|
|
|
|
{
|
|
|
|
return rmap->obj[rmap->near[cpu].index];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* alloc_irq_cpu_rmap - allocate CPU affinity reverse-map for IRQs
|
|
|
|
* @size: Number of objects to be mapped
|
|
|
|
*
|
|
|
|
* Must be called in process context.
|
|
|
|
*/
|
|
|
|
static inline struct cpu_rmap *alloc_irq_cpu_rmap(unsigned int size)
|
|
|
|
{
|
|
|
|
return alloc_cpu_rmap(size, GFP_KERNEL);
|
|
|
|
}
|
|
|
|
extern void free_irq_cpu_rmap(struct cpu_rmap *rmap);
|
|
|
|
|
2023-02-14 12:05:46 +03:00
|
|
|
int irq_cpu_rmap_remove(struct cpu_rmap *rmap, int irq);
|
2011-01-19 14:03:25 +03:00
|
|
|
extern int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq);
|
|
|
|
|
2012-07-19 02:33:50 +04:00
|
|
|
#endif /* __LINUX_CPU_RMAP_H */
|