cpu_rmap.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #ifndef __LINUX_CPU_RMAP_H
  3. #define __LINUX_CPU_RMAP_H
  4. /*
  5. * cpu_rmap.c: CPU affinity reverse-map support
  6. * Copyright 2011 Solarflare Communications Inc.
  7. */
  8. #include <linux/cpumask.h>
  9. #include <linux/gfp.h>
  10. #include <linux/slab.h>
  11. #include <linux/kref.h>
  12. /**
  13. * struct cpu_rmap - CPU affinity reverse-map
  14. * @refcount: kref for object
  15. * @size: Number of objects to be reverse-mapped
  16. * @used: Number of objects added
  17. * @obj: Pointer to array of object pointers
  18. * @near: For each CPU, the index and distance to the nearest object,
  19. * based on affinity masks
  20. */
  21. struct cpu_rmap {
  22. struct kref refcount;
  23. u16 size, used;
  24. void **obj;
  25. struct {
  26. u16 index;
  27. u16 dist;
  28. } near[];
  29. };
  30. #define CPU_RMAP_DIST_INF 0xffff
  31. extern struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags);
  32. extern int cpu_rmap_put(struct cpu_rmap *rmap);
  33. extern int cpu_rmap_add(struct cpu_rmap *rmap, void *obj);
  34. extern int cpu_rmap_update(struct cpu_rmap *rmap, u16 index,
  35. const struct cpumask *affinity);
  36. static inline u16 cpu_rmap_lookup_index(struct cpu_rmap *rmap, unsigned int cpu)
  37. {
  38. return rmap->near[cpu].index;
  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. * alloc_irq_cpu_rmap - allocate CPU affinity reverse-map for IRQs
  46. * @size: Number of objects to be mapped
  47. *
  48. * Must be called in process context.
  49. */
  50. static inline struct cpu_rmap *alloc_irq_cpu_rmap(unsigned int size)
  51. {
  52. return alloc_cpu_rmap(size, GFP_KERNEL);
  53. }
  54. extern void free_irq_cpu_rmap(struct cpu_rmap *rmap);
  55. extern int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq);
  56. #endif /* __LINUX_CPU_RMAP_H */