mmap.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
  32. struct perf_mmap *next;
  33. };
  34. struct perf_mmap_param {
  35. int prot;
  36. int mask;
  37. };
  38. size_t perf_mmap__mmap_len(struct perf_mmap *map);
  39. void perf_mmap__init(struct perf_mmap *map, struct perf_mmap *prev,
  40. bool overwrite, libperf_unmap_cb_t unmap_cb);
  41. int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
  42. int fd, struct perf_cpu cpu);
  43. void perf_mmap__munmap(struct perf_mmap *map);
  44. void perf_mmap__get(struct perf_mmap *map);
  45. void perf_mmap__put(struct perf_mmap *map);
  46. u64 perf_mmap__read_head(struct perf_mmap *map);
  47. int perf_mmap__read_self(struct perf_mmap *map, struct perf_counts_values *count);
  48. #endif /* __LIBPERF_INTERNAL_MMAP_H */