target.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 *uid_str;
  11. uid_t uid;
  12. bool system_wide;
  13. bool uses_mmap;
  14. bool default_per_cpu;
  15. bool per_thread;
  16. };
  17. enum target_errno {
  18. TARGET_ERRNO__SUCCESS = 0,
  19. /*
  20. * Choose an arbitrary negative big number not to clash with standard
  21. * errno since SUS requires the errno has distinct positive values.
  22. * See 'Issue 6' in the link below.
  23. *
  24. * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
  25. */
  26. __TARGET_ERRNO__START = -10000,
  27. /* for target__validate() */
  28. TARGET_ERRNO__PID_OVERRIDE_CPU = __TARGET_ERRNO__START,
  29. TARGET_ERRNO__PID_OVERRIDE_UID,
  30. TARGET_ERRNO__UID_OVERRIDE_CPU,
  31. TARGET_ERRNO__PID_OVERRIDE_SYSTEM,
  32. TARGET_ERRNO__UID_OVERRIDE_SYSTEM,
  33. TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD,
  34. /* for target__parse_uid() */
  35. TARGET_ERRNO__INVALID_UID,
  36. TARGET_ERRNO__USER_NOT_FOUND,
  37. __TARGET_ERRNO__END,
  38. };
  39. enum target_errno target__validate(struct target *target);
  40. enum target_errno target__parse_uid(struct target *target);
  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 || target->uid_str;
  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__has_per_thread(struct target *target)
  55. {
  56. return target->system_wide && target->per_thread;
  57. }
  58. static inline bool target__uses_dummy_map(struct target *target)
  59. {
  60. bool use_dummy = false;
  61. if (target->default_per_cpu)
  62. use_dummy = target->per_thread ? true : false;
  63. else if (target__has_task(target) ||
  64. (!target__has_cpu(target) && !target->uses_mmap))
  65. use_dummy = true;
  66. else if (target__has_per_thread(target))
  67. use_dummy = true;
  68. return use_dummy;
  69. }
  70. #endif /* _PERF_TARGET_H */