cpu_rmap.h 2.0 KB

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