percpu_ida.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef __PERCPU_IDA_H__
  2. #define __PERCPU_IDA_H__
  3. #include <linux/types.h>
  4. #include <linux/bitops.h>
  5. #include <linux/init.h>
  6. #include <linux/spinlock_types.h>
  7. #include <linux/wait.h>
  8. #include <linux/cpumask.h>
  9. struct percpu_ida_cpu;
  10. struct percpu_ida {
  11. /*
  12. * number of tags available to be allocated, as passed to
  13. * percpu_ida_init()
  14. */
  15. unsigned nr_tags;
  16. struct percpu_ida_cpu __percpu *tag_cpu;
  17. /*
  18. * Bitmap of cpus that (may) have tags on their percpu freelists:
  19. * steal_tags() uses this to decide when to steal tags, and which cpus
  20. * to try stealing from.
  21. *
  22. * It's ok for a freelist to be empty when its bit is set - steal_tags()
  23. * will just keep looking - but the bitmap _must_ be set whenever a
  24. * percpu freelist does have tags.
  25. */
  26. cpumask_t cpus_have_tags;
  27. struct {
  28. spinlock_t lock;
  29. /*
  30. * When we go to steal tags from another cpu (see steal_tags()),
  31. * we want to pick a cpu at random. Cycling through them every
  32. * time we steal is a bit easier and more or less equivalent:
  33. */
  34. unsigned cpu_last_stolen;
  35. /* For sleeping on allocation failure */
  36. wait_queue_head_t wait;
  37. /*
  38. * Global freelist - it's a stack where nr_free points to the
  39. * top
  40. */
  41. unsigned nr_free;
  42. unsigned *freelist;
  43. } ____cacheline_aligned_in_smp;
  44. };
  45. int percpu_ida_alloc(struct percpu_ida *pool, gfp_t gfp);
  46. void percpu_ida_free(struct percpu_ida *pool, unsigned tag);
  47. void percpu_ida_destroy(struct percpu_ida *pool);
  48. int percpu_ida_init(struct percpu_ida *pool, unsigned long nr_tags);
  49. #endif /* __PERCPU_IDA_H__ */