cpu_rmap.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef __LINUX_CPU_RMAP_H
  2. #define __LINUX_CPU_RMAP_H
  3. /*
  4. * cpu_rmap.c: CPU affinity reverse-map support
  5. * Copyright 2011 Solarflare Communications Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published
  9. * by the Free Software Foundation, incorporated herein by reference.
  10. */
  11. #include <linux/cpumask.h>
  12. #include <linux/gfp.h>
  13. #include <linux/slab.h>
  14. #include <linux/kref.h>
  15. /**
  16. * struct cpu_rmap - CPU affinity reverse-map
  17. * @refcount: kref for object
  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 {
  25. struct kref refcount;
  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. extern struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags);
  35. extern int cpu_rmap_put(struct cpu_rmap *rmap);
  36. extern int cpu_rmap_add(struct cpu_rmap *rmap, void *obj);
  37. extern int cpu_rmap_update(struct cpu_rmap *rmap, u16 index,
  38. const struct cpumask *affinity);
  39. static inline u16 cpu_rmap_lookup_index(struct cpu_rmap *rmap, unsigned int cpu)
  40. {
  41. return rmap->near[cpu].index;
  42. }
  43. static inline void *cpu_rmap_lookup_obj(struct cpu_rmap *rmap, unsigned int cpu)
  44. {
  45. return rmap->obj[rmap->near[cpu].index];
  46. }
  47. /**
  48. * alloc_irq_cpu_rmap - allocate CPU affinity reverse-map for IRQs
  49. * @size: Number of objects to be mapped
  50. *
  51. * Must be called in process context.
  52. */
  53. static inline struct cpu_rmap *alloc_irq_cpu_rmap(unsigned int size)
  54. {
  55. return alloc_cpu_rmap(size, GFP_KERNEL);
  56. }
  57. extern void free_irq_cpu_rmap(struct cpu_rmap *rmap);
  58. extern int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq);
  59. #endif /* __LINUX_CPU_RMAP_H */