mmap.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LIBPERF_INTERNAL_MMAP_H
  3. #define __LIBPERF_INTERNAL_MMAP_H
  4. #include <linux/compiler.h>
  5. #include <linux/refcount.h>
  6. #include <linux/types.h>
  7. #include <stdbool.h>
  8. #include <internal/cpumap.h>
  9. /* perf sample has 16 bits size limit */
  10. #define PERF_SAMPLE_MAX_SIZE (1 << 16)
  11. struct perf_mmap;
  12. struct perf_counts_values;
  13. typedef void (*libperf_unmap_cb_t)(struct perf_mmap *map);
  14. /**
  15. * struct perf_mmap - perf's ring buffer mmap details
  16. *
  17. * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
  18. */
  19. struct perf_mmap {
  20. void *base;
  21. int mask;
  22. int fd;
  23. struct perf_cpu cpu;
  24. refcount_t refcnt;
  25. u64 prev;
  26. u64 start;
  27. u64 end;
  28. bool overwrite;
  29. u64 flush;
  30. libperf_unmap_cb_t unmap_cb;
  31. void *event_copy;
  32. size_t event_copy_sz;
  33. struct perf_mmap *next;
  34. };
  35. struct perf_mmap_param {
  36. int prot;
  37. int mask;
  38. };
  39. size_t perf_mmap__mmap_len(struct perf_mmap *map);
  40. void perf_mmap__init(struct perf_mmap *map, struct perf_mmap *prev,
  41. bool overwrite, libperf_unmap_cb_t unmap_cb);
  42. int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
  43. int fd, struct perf_cpu cpu);
  44. void perf_mmap__munmap(struct perf_mmap *map);
  45. void perf_mmap__get(struct perf_mmap *map);
  46. void perf_mmap__put(struct perf_mmap *map);
  47. u64 perf_mmap__read_head(struct perf_mmap *map);
  48. int perf_mmap__read_self(struct perf_mmap *map, struct perf_counts_values *count);
  49. #endif /* __LIBPERF_INTERNAL_MMAP_H */