target.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _PERF_TARGET_H
  3. #define _PERF_TARGET_H
  4. #include <stdbool.h>
  5. #include <sys/types.h>
  6. struct target {
  7. const char *pid;
  8. const char *tid;
  9. const char *cpu_list;
  10. const char *bpf_str;
  11. bool system_wide;
  12. bool uses_mmap;
  13. bool default_per_cpu;
  14. bool per_thread;
  15. bool use_bpf;
  16. bool inherit;
  17. int initial_delay;
  18. const char *attr_map;
  19. };
  20. enum target_errno {
  21. TARGET_ERRNO__SUCCESS = 0,
  22. /*
  23. * Choose an arbitrary negative big number not to clash with standard
  24. * errno since SUS requires the errno has distinct positive values.
  25. * See 'Issue 6' in the link below.
  26. *
  27. * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
  28. */
  29. __TARGET_ERRNO__START = -10000,
  30. /* for target__validate() */
  31. TARGET_ERRNO__PID_OVERRIDE_CPU = __TARGET_ERRNO__START,
  32. TARGET_ERRNO__PID_OVERRIDE_SYSTEM,
  33. TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD,
  34. TARGET_ERRNO__BPF_OVERRIDE_CPU,
  35. TARGET_ERRNO__BPF_OVERRIDE_PID,
  36. TARGET_ERRNO__BPF_OVERRIDE_THREAD,
  37. __TARGET_ERRNO__END,
  38. };
  39. enum target_errno target__validate(struct target *target);
  40. uid_t parse_uid(const char *str);
  41. int target__strerror(struct target *target, int errnum, char *buf, size_t buflen);
  42. static inline bool target__has_task(struct target *target)
  43. {
  44. return target->tid || target->pid;
  45. }
  46. static inline bool target__has_cpu(struct target *target)
  47. {
  48. return target->system_wide || target->cpu_list;
  49. }
  50. static inline bool target__none(struct target *target)
  51. {
  52. return !target__has_task(target) && !target__has_cpu(target);
  53. }
  54. static inline bool target__enable_on_exec(struct target *target)
  55. {
  56. /*
  57. * Normally enable_on_exec should be set if:
  58. * 1) The tracee process is forked (not attaching to existed task or cpu).
  59. * 2) And initial_delay is not configured.
  60. * Otherwise, we enable tracee events manually.
  61. */
  62. return target__none(target) && !target->initial_delay;
  63. }
  64. static inline bool target__has_per_thread(struct target *target)
  65. {
  66. return target->system_wide && target->per_thread;
  67. }
  68. static inline bool target__uses_dummy_map(struct target *target)
  69. {
  70. bool use_dummy = false;
  71. if (target->default_per_cpu)
  72. use_dummy = target->per_thread ? true : false;
  73. else if (target__has_task(target) ||
  74. (!target__has_cpu(target) && !target->uses_mmap))
  75. use_dummy = true;
  76. else if (target__has_per_thread(target))
  77. use_dummy = true;
  78. return use_dummy;
  79. }
  80. #endif /* _PERF_TARGET_H */