18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: LGPL-2.1 28c2ecf20Sopenharmony_ci#ifndef PERF_FLAG_FD_NO_GROUP 38c2ecf20Sopenharmony_ci# define PERF_FLAG_FD_NO_GROUP (1UL << 0) 48c2ecf20Sopenharmony_ci#endif 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef PERF_FLAG_FD_OUTPUT 78c2ecf20Sopenharmony_ci# define PERF_FLAG_FD_OUTPUT (1UL << 1) 88c2ecf20Sopenharmony_ci#endif 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef PERF_FLAG_PID_CGROUP 118c2ecf20Sopenharmony_ci# define PERF_FLAG_PID_CGROUP (1UL << 2) /* pid=cgroup id, per-cpu mode only */ 128c2ecf20Sopenharmony_ci#endif 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#ifndef PERF_FLAG_FD_CLOEXEC 158c2ecf20Sopenharmony_ci# define PERF_FLAG_FD_CLOEXEC (1UL << 3) /* O_CLOEXEC */ 168c2ecf20Sopenharmony_ci#endif 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistatic size_t syscall_arg__scnprintf_perf_flags(char *bf, size_t size, 198c2ecf20Sopenharmony_ci struct syscall_arg *arg) 208c2ecf20Sopenharmony_ci{ 218c2ecf20Sopenharmony_ci bool show_prefix = arg->show_string_prefix; 228c2ecf20Sopenharmony_ci const char *prefix = "PERF_"; 238c2ecf20Sopenharmony_ci int printed = 0, flags = arg->val; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci if (flags == 0) 268c2ecf20Sopenharmony_ci return 0; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#define P_FLAG(n) \ 298c2ecf20Sopenharmony_ci if (flags & PERF_FLAG_##n) { \ 308c2ecf20Sopenharmony_ci printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \ 318c2ecf20Sopenharmony_ci flags &= ~PERF_FLAG_##n; \ 328c2ecf20Sopenharmony_ci } 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci P_FLAG(FD_NO_GROUP); 358c2ecf20Sopenharmony_ci P_FLAG(FD_OUTPUT); 368c2ecf20Sopenharmony_ci P_FLAG(PID_CGROUP); 378c2ecf20Sopenharmony_ci P_FLAG(FD_CLOEXEC); 388c2ecf20Sopenharmony_ci#undef P_FLAG 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci if (flags) 418c2ecf20Sopenharmony_ci printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci return printed; 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define SCA_PERF_FLAGS syscall_arg__scnprintf_perf_flags 47