^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef _PERF_TARGET_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _PERF_TARGET_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <stdbool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) struct target {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) const char *pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) const char *tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) const char *cpu_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) const char *uid_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) uid_t uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) bool system_wide;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) bool uses_mmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) bool default_per_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) bool per_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) enum target_errno {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) TARGET_ERRNO__SUCCESS = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * Choose an arbitrary negative big number not to clash with standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * errno since SUS requires the errno has distinct positive values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * See 'Issue 6' in the link below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) __TARGET_ERRNO__START = -10000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* for target__validate() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) TARGET_ERRNO__PID_OVERRIDE_CPU = __TARGET_ERRNO__START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) TARGET_ERRNO__PID_OVERRIDE_UID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) TARGET_ERRNO__UID_OVERRIDE_CPU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) TARGET_ERRNO__PID_OVERRIDE_SYSTEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) TARGET_ERRNO__UID_OVERRIDE_SYSTEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* for target__parse_uid() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) TARGET_ERRNO__INVALID_UID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) TARGET_ERRNO__USER_NOT_FOUND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) __TARGET_ERRNO__END,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) enum target_errno target__validate(struct target *target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) enum target_errno target__parse_uid(struct target *target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int target__strerror(struct target *target, int errnum, char *buf, size_t buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static inline bool target__has_task(struct target *target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return target->tid || target->pid || target->uid_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static inline bool target__has_cpu(struct target *target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return target->system_wide || target->cpu_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static inline bool target__none(struct target *target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return !target__has_task(target) && !target__has_cpu(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static inline bool target__has_per_thread(struct target *target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return target->system_wide && target->per_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static inline bool target__uses_dummy_map(struct target *target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) bool use_dummy = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (target->default_per_cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) use_dummy = target->per_thread ? true : false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) else if (target__has_task(target) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) (!target__has_cpu(target) && !target->uses_mmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) use_dummy = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) else if (target__has_per_thread(target))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) use_dummy = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return use_dummy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #endif /* _PERF_TARGET_H */