cpu_rmap.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  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. #include <linux/cpumask.h>
  10. #include <linux/gfp.h>
  11. #include <linux/slab.h>
  12. /**
  13. * struct cpu_rmap - CPU affinity reverse-map
  14. * @size: Number of objects to be reverse-mapped
  15. * @used: Number of objects added
  16. * @obj: Pointer to array of object pointers
  17. * @near: For each CPU, the index and distance to the nearest object,
  18. * based on affinity masks
  19. */
  20. struct cpu_rmap {
  21. u16 size, used;
  22. void **obj;
  23. struct {
  24. u16 index;
  25. u16 dist;
  26. } near[0];
  27. };
  28. #define CPU_RMAP_DIST_INF 0xffff
  29. extern struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags);
  30. /**
  31. * free_cpu_rmap - free CPU affinity reverse-map
  32. * @rmap: Reverse-map allocated with alloc_cpu_rmap(), or %NULL
  33. */
  34. static inline void free_cpu_rmap(struct cpu_rmap *rmap)
  35. {
  36. kfree(rmap);
  37. }
  38. extern int cpu_rmap_add(struct cpu_rmap *rmap, void *obj);
  39. extern int cpu_rmap_update(struct cpu_rmap *rmap, u16 index,
  40. const struct cpumask *affinity);
  41. static inline u16 cpu_rmap_lookup_index(struct cpu_rmap *rmap, unsigned int cpu)
  42. {
  43. return rmap->near[cpu].index;
  44. }
  45. static inline void *cpu_rmap_lookup_obj(struct cpu_rmap *rmap, unsigned int cpu)
  46. {
  47. return rmap->obj[rmap->near[cpu].index];
  48. }
  49. #ifdef CONFIG_GENERIC_HARDIRQS
  50. /**
  51. * alloc_irq_cpu_rmap - allocate CPU affinity reverse-map for IRQs
  52. * @size: Number of objects to be mapped
  53. *
  54. * Must be called in process context.
  55. */
  56. static inline struct cpu_rmap *alloc_irq_cpu_rmap(unsigned int size)
  57. {
  58. return alloc_cpu_rmap(size, GFP_KERNEL);
  59. }
  60. extern void free_irq_cpu_rmap(struct cpu_rmap *rmap);
  61. extern int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq);
  62. #endif