Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'perf-core-for-mingo-4.12-20170424' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core

Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:

User visible changes:

- Fix display of data source snoop indication in 'perf mem' (Andi Kleen)

- Fix the code to strip command name from /proc/PID/stat (Jiri Olsa)

Infrastructure changes:

- Continue the disentanglement of headers, specially util.h (Arnaldo Carvalho de Melo)

- Synchronize some header files with the kernel (Arnaldo Carvalho de Melo)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>

+1328 -733
+2 -2
arch/um/include/shared/os.h
··· 302 302 extern void maybe_sigio_broken(int fd, int read); 303 303 extern void sigio_broken(int fd, int read); 304 304 305 - /* sys-x86_64/prctl.c */ 306 - extern int os_arch_prctl(int pid, int code, unsigned long *addr); 305 + /* prctl.c */ 306 + extern int os_arch_prctl(int pid, int option, unsigned long *arg2); 307 307 308 308 /* tty.c */ 309 309 extern int get_pty(void);
+1
arch/x86/entry/syscalls/syscall_32.tbl
··· 390 390 381 i386 pkey_alloc sys_pkey_alloc 391 391 382 i386 pkey_free sys_pkey_free 392 392 383 i386 statx sys_statx 393 + 384 i386 arch_prctl sys_arch_prctl compat_sys_arch_prctl
+1
arch/x86/include/asm/cpufeatures.h
··· 187 187 * Reuse free bits when adding new feature flags! 188 188 */ 189 189 #define X86_FEATURE_RING3MWAIT ( 7*32+ 0) /* Ring 3 MONITOR/MWAIT */ 190 + #define X86_FEATURE_CPUID_FAULT ( 7*32+ 1) /* Intel CPUID faulting */ 190 191 #define X86_FEATURE_CPB ( 7*32+ 2) /* AMD Core Performance Boost */ 191 192 #define X86_FEATURE_EPB ( 7*32+ 3) /* IA32_ENERGY_PERF_BIAS support */ 192 193 #define X86_FEATURE_CAT_L3 ( 7*32+ 4) /* Cache Allocation Technology L3 */
+8 -3
arch/x86/include/asm/msr-index.h
··· 45 45 #define MSR_IA32_PERFCTR1 0x000000c2 46 46 #define MSR_FSB_FREQ 0x000000cd 47 47 #define MSR_PLATFORM_INFO 0x000000ce 48 + #define MSR_PLATFORM_INFO_CPUID_FAULT_BIT 31 49 + #define MSR_PLATFORM_INFO_CPUID_FAULT BIT_ULL(MSR_PLATFORM_INFO_CPUID_FAULT_BIT) 48 50 49 51 #define MSR_PKG_CST_CONFIG_CONTROL 0x000000e2 50 52 #define NHM_C3_AUTO_DEMOTE (1UL << 25) ··· 129 127 130 128 /* DEBUGCTLMSR bits (others vary by model): */ 131 129 #define DEBUGCTLMSR_LBR (1UL << 0) /* last branch recording */ 130 + #define DEBUGCTLMSR_BTF_SHIFT 1 132 131 #define DEBUGCTLMSR_BTF (1UL << 1) /* single-step on branches */ 133 132 #define DEBUGCTLMSR_TR (1UL << 6) 134 133 #define DEBUGCTLMSR_BTS (1UL << 7) ··· 555 552 #define MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE_BIT 39 556 553 #define MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE (1ULL << MSR_IA32_MISC_ENABLE_IP_PREF_DISABLE_BIT) 557 554 558 - /* MISC_FEATURE_ENABLES non-architectural features */ 559 - #define MSR_MISC_FEATURE_ENABLES 0x00000140 555 + /* MISC_FEATURES_ENABLES non-architectural features */ 556 + #define MSR_MISC_FEATURES_ENABLES 0x00000140 560 557 561 - #define MSR_MISC_FEATURE_ENABLES_RING3MWAIT_BIT 1 558 + #define MSR_MISC_FEATURES_ENABLES_CPUID_FAULT_BIT 0 559 + #define MSR_MISC_FEATURES_ENABLES_CPUID_FAULT BIT_ULL(MSR_MISC_FEATURES_ENABLES_CPUID_FAULT_BIT) 560 + #define MSR_MISC_FEATURES_ENABLES_RING3MWAIT_BIT 1 562 561 563 562 #define MSR_IA32_TSC_DEADLINE 0x000006E0 564 563
+2
arch/x86/include/asm/processor.h
··· 884 884 extern int get_tsc_mode(unsigned long adr); 885 885 extern int set_tsc_mode(unsigned int val); 886 886 887 + DECLARE_PER_CPU(u64, msr_misc_features_shadow); 888 + 887 889 /* Register/unregister a process' MPX related resource */ 888 890 #define MPX_ENABLE_MANAGEMENT() mpx_enable_management() 889 891 #define MPX_DISABLE_MANAGEMENT() mpx_disable_management()
+3 -1
arch/x86/include/asm/proto.h
··· 9 9 10 10 #ifdef CONFIG_X86_64 11 11 void entry_SYSCALL_64(void); 12 + long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2); 12 13 #endif 13 14 14 15 #ifdef CONFIG_X86_32 ··· 31 30 32 31 extern int reboot_force; 33 32 34 - long do_arch_prctl(struct task_struct *task, int code, unsigned long addr); 33 + long do_arch_prctl_common(struct task_struct *task, int option, 34 + unsigned long cpuid_enabled); 35 35 36 36 #endif /* _ASM_X86_PROTO_H */
+5 -1
arch/x86/include/asm/thread_info.h
··· 87 87 #define TIF_SECCOMP 8 /* secure computing */ 88 88 #define TIF_USER_RETURN_NOTIFY 11 /* notify kernel of userspace return */ 89 89 #define TIF_UPROBE 12 /* breakpointed or singlestepping */ 90 + #define TIF_NOCPUID 15 /* CPUID is not accessible in userland */ 90 91 #define TIF_NOTSC 16 /* TSC is not accessible in userland */ 91 92 #define TIF_IA32 17 /* IA32 compatibility process */ 92 93 #define TIF_NOHZ 19 /* in adaptive nohz mode */ ··· 111 110 #define _TIF_SECCOMP (1 << TIF_SECCOMP) 112 111 #define _TIF_USER_RETURN_NOTIFY (1 << TIF_USER_RETURN_NOTIFY) 113 112 #define _TIF_UPROBE (1 << TIF_UPROBE) 113 + #define _TIF_NOCPUID (1 << TIF_NOCPUID) 114 114 #define _TIF_NOTSC (1 << TIF_NOTSC) 115 115 #define _TIF_IA32 (1 << TIF_IA32) 116 116 #define _TIF_NOHZ (1 << TIF_NOHZ) ··· 140 138 141 139 /* flags to check in __switch_to() */ 142 140 #define _TIF_WORK_CTXSW \ 143 - (_TIF_IO_BITMAP|_TIF_NOTSC|_TIF_BLOCKSTEP) 141 + (_TIF_IO_BITMAP|_TIF_NOCPUID|_TIF_NOTSC|_TIF_BLOCKSTEP) 144 142 145 143 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY) 146 144 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW) ··· 241 239 extern void arch_task_cache_init(void); 242 240 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src); 243 241 extern void arch_release_task_struct(struct task_struct *tsk); 242 + extern void arch_setup_new_exec(void); 243 + #define arch_setup_new_exec arch_setup_new_exec 244 244 #endif /* !__ASSEMBLY__ */ 245 245 246 246 #endif /* _ASM_X86_THREAD_INFO_H */
+10
arch/x86/include/asm/tlbflush.h
··· 110 110 } 111 111 } 112 112 113 + static inline void cr4_toggle_bits(unsigned long mask) 114 + { 115 + unsigned long cr4; 116 + 117 + cr4 = this_cpu_read(cpu_tlbstate.cr4); 118 + cr4 ^= mask; 119 + this_cpu_write(cpu_tlbstate.cr4, cr4); 120 + __write_cr4(cr4); 121 + } 122 + 113 123 /* Read the CR4 shadow. */ 114 124 static inline unsigned long cr4_read_shadow(void) 115 125 {
+7 -4
arch/x86/include/uapi/asm/prctl.h
··· 1 1 #ifndef _ASM_X86_PRCTL_H 2 2 #define _ASM_X86_PRCTL_H 3 3 4 - #define ARCH_SET_GS 0x1001 5 - #define ARCH_SET_FS 0x1002 6 - #define ARCH_GET_FS 0x1003 7 - #define ARCH_GET_GS 0x1004 4 + #define ARCH_SET_GS 0x1001 5 + #define ARCH_SET_FS 0x1002 6 + #define ARCH_GET_FS 0x1003 7 + #define ARCH_GET_GS 0x1004 8 + 9 + #define ARCH_GET_CPUID 0x1011 10 + #define ARCH_SET_CPUID 0x1012 8 11 9 12 #define ARCH_MAP_VDSO_X32 0x2001 10 13 #define ARCH_MAP_VDSO_32 0x2002
+32 -8
arch/x86/kernel/cpu/intel.c
··· 90 90 return; 91 91 } 92 92 93 - if (ring3mwait_disabled) { 94 - msr_clear_bit(MSR_MISC_FEATURE_ENABLES, 95 - MSR_MISC_FEATURE_ENABLES_RING3MWAIT_BIT); 93 + if (ring3mwait_disabled) 96 94 return; 97 - } 98 - 99 - msr_set_bit(MSR_MISC_FEATURE_ENABLES, 100 - MSR_MISC_FEATURE_ENABLES_RING3MWAIT_BIT); 101 95 102 96 set_cpu_cap(c, X86_FEATURE_RING3MWAIT); 97 + this_cpu_or(msr_misc_features_shadow, 98 + 1UL << MSR_MISC_FEATURES_ENABLES_RING3MWAIT_BIT); 103 99 104 100 if (c == &boot_cpu_data) 105 101 ELF_HWCAP2 |= HWCAP2_RING3MWAIT; ··· 484 488 init_intel_energy_perf(c); 485 489 } 486 490 491 + static void init_cpuid_fault(struct cpuinfo_x86 *c) 492 + { 493 + u64 msr; 494 + 495 + if (!rdmsrl_safe(MSR_PLATFORM_INFO, &msr)) { 496 + if (msr & MSR_PLATFORM_INFO_CPUID_FAULT) 497 + set_cpu_cap(c, X86_FEATURE_CPUID_FAULT); 498 + } 499 + } 500 + 501 + static void init_intel_misc_features(struct cpuinfo_x86 *c) 502 + { 503 + u64 msr; 504 + 505 + if (rdmsrl_safe(MSR_MISC_FEATURES_ENABLES, &msr)) 506 + return; 507 + 508 + /* Clear all MISC features */ 509 + this_cpu_write(msr_misc_features_shadow, 0); 510 + 511 + /* Check features and update capabilities and shadow control bits */ 512 + init_cpuid_fault(c); 513 + probe_xeon_phi_r3mwait(c); 514 + 515 + msr = this_cpu_read(msr_misc_features_shadow); 516 + wrmsrl(MSR_MISC_FEATURES_ENABLES, msr); 517 + } 518 + 487 519 static void init_intel(struct cpuinfo_x86 *c) 488 520 { 489 521 unsigned int l2 = 0; ··· 626 602 627 603 init_intel_energy_perf(c); 628 604 629 - probe_xeon_phi_r3mwait(c); 605 + init_intel_misc_features(c); 630 606 } 631 607 632 608 #ifdef CONFIG_X86_32
+115 -36
arch/x86/kernel/process.c
··· 37 37 #include <asm/vm86.h> 38 38 #include <asm/switch_to.h> 39 39 #include <asm/desc.h> 40 + #include <asm/prctl.h> 40 41 41 42 /* 42 43 * per-CPU TSS segments. Threads are completely 'soft' on Linux, ··· 125 124 fpu__clear(&tsk->thread.fpu); 126 125 } 127 126 128 - static void hard_disable_TSC(void) 129 - { 130 - cr4_set_bits(X86_CR4_TSD); 131 - } 132 - 133 127 void disable_TSC(void) 134 128 { 135 129 preempt_disable(); ··· 133 137 * Must flip the CPU state synchronously with 134 138 * TIF_NOTSC in the current running context. 135 139 */ 136 - hard_disable_TSC(); 140 + cr4_set_bits(X86_CR4_TSD); 137 141 preempt_enable(); 138 - } 139 - 140 - static void hard_enable_TSC(void) 141 - { 142 - cr4_clear_bits(X86_CR4_TSD); 143 142 } 144 143 145 144 static void enable_TSC(void) ··· 145 154 * Must flip the CPU state synchronously with 146 155 * TIF_NOTSC in the current running context. 147 156 */ 148 - hard_enable_TSC(); 157 + cr4_clear_bits(X86_CR4_TSD); 149 158 preempt_enable(); 150 159 } 151 160 ··· 173 182 return 0; 174 183 } 175 184 176 - void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p, 177 - struct tss_struct *tss) 185 + DEFINE_PER_CPU(u64, msr_misc_features_shadow); 186 + 187 + static void set_cpuid_faulting(bool on) 178 188 { 179 - struct thread_struct *prev, *next; 189 + u64 msrval; 180 190 181 - prev = &prev_p->thread; 182 - next = &next_p->thread; 191 + msrval = this_cpu_read(msr_misc_features_shadow); 192 + msrval &= ~MSR_MISC_FEATURES_ENABLES_CPUID_FAULT; 193 + msrval |= (on << MSR_MISC_FEATURES_ENABLES_CPUID_FAULT_BIT); 194 + this_cpu_write(msr_misc_features_shadow, msrval); 195 + wrmsrl(MSR_MISC_FEATURES_ENABLES, msrval); 196 + } 183 197 184 - if (test_tsk_thread_flag(prev_p, TIF_BLOCKSTEP) ^ 185 - test_tsk_thread_flag(next_p, TIF_BLOCKSTEP)) { 186 - unsigned long debugctl = get_debugctlmsr(); 187 - 188 - debugctl &= ~DEBUGCTLMSR_BTF; 189 - if (test_tsk_thread_flag(next_p, TIF_BLOCKSTEP)) 190 - debugctl |= DEBUGCTLMSR_BTF; 191 - 192 - update_debugctlmsr(debugctl); 198 + static void disable_cpuid(void) 199 + { 200 + preempt_disable(); 201 + if (!test_and_set_thread_flag(TIF_NOCPUID)) { 202 + /* 203 + * Must flip the CPU state synchronously with 204 + * TIF_NOCPUID in the current running context. 205 + */ 206 + set_cpuid_faulting(true); 193 207 } 208 + preempt_enable(); 209 + } 194 210 195 - if (test_tsk_thread_flag(prev_p, TIF_NOTSC) ^ 196 - test_tsk_thread_flag(next_p, TIF_NOTSC)) { 197 - /* prev and next are different */ 198 - if (test_tsk_thread_flag(next_p, TIF_NOTSC)) 199 - hard_disable_TSC(); 200 - else 201 - hard_enable_TSC(); 211 + static void enable_cpuid(void) 212 + { 213 + preempt_disable(); 214 + if (test_and_clear_thread_flag(TIF_NOCPUID)) { 215 + /* 216 + * Must flip the CPU state synchronously with 217 + * TIF_NOCPUID in the current running context. 218 + */ 219 + set_cpuid_faulting(false); 202 220 } 221 + preempt_enable(); 222 + } 203 223 204 - if (test_tsk_thread_flag(next_p, TIF_IO_BITMAP)) { 224 + static int get_cpuid_mode(void) 225 + { 226 + return !test_thread_flag(TIF_NOCPUID); 227 + } 228 + 229 + static int set_cpuid_mode(struct task_struct *task, unsigned long cpuid_enabled) 230 + { 231 + if (!static_cpu_has(X86_FEATURE_CPUID_FAULT)) 232 + return -ENODEV; 233 + 234 + if (cpuid_enabled) 235 + enable_cpuid(); 236 + else 237 + disable_cpuid(); 238 + 239 + return 0; 240 + } 241 + 242 + /* 243 + * Called immediately after a successful exec. 244 + */ 245 + void arch_setup_new_exec(void) 246 + { 247 + /* If cpuid was previously disabled for this task, re-enable it. */ 248 + if (test_thread_flag(TIF_NOCPUID)) 249 + enable_cpuid(); 250 + } 251 + 252 + static inline void switch_to_bitmap(struct tss_struct *tss, 253 + struct thread_struct *prev, 254 + struct thread_struct *next, 255 + unsigned long tifp, unsigned long tifn) 256 + { 257 + if (tifn & _TIF_IO_BITMAP) { 205 258 /* 206 259 * Copy the relevant range of the IO bitmap. 207 260 * Normally this is 128 bytes or less: 208 261 */ 209 262 memcpy(tss->io_bitmap, next->io_bitmap_ptr, 210 263 max(prev->io_bitmap_max, next->io_bitmap_max)); 211 - 212 264 /* 213 265 * Make sure that the TSS limit is correct for the CPU 214 266 * to notice the IO bitmap. 215 267 */ 216 268 refresh_tss_limit(); 217 - } else if (test_tsk_thread_flag(prev_p, TIF_IO_BITMAP)) { 269 + } else if (tifp & _TIF_IO_BITMAP) { 218 270 /* 219 271 * Clear any possible leftover bits: 220 272 */ 221 273 memset(tss->io_bitmap, 0xff, prev->io_bitmap_max); 222 274 } 275 + } 276 + 277 + void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p, 278 + struct tss_struct *tss) 279 + { 280 + struct thread_struct *prev, *next; 281 + unsigned long tifp, tifn; 282 + 283 + prev = &prev_p->thread; 284 + next = &next_p->thread; 285 + 286 + tifn = READ_ONCE(task_thread_info(next_p)->flags); 287 + tifp = READ_ONCE(task_thread_info(prev_p)->flags); 288 + switch_to_bitmap(tss, prev, next, tifp, tifn); 289 + 223 290 propagate_user_return_notify(prev_p, next_p); 291 + 292 + if ((tifp & _TIF_BLOCKSTEP || tifn & _TIF_BLOCKSTEP) && 293 + arch_has_block_step()) { 294 + unsigned long debugctl, msk; 295 + 296 + rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl); 297 + debugctl &= ~DEBUGCTLMSR_BTF; 298 + msk = tifn & _TIF_BLOCKSTEP; 299 + debugctl |= (msk >> TIF_BLOCKSTEP) << DEBUGCTLMSR_BTF_SHIFT; 300 + wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl); 301 + } 302 + 303 + if ((tifp ^ tifn) & _TIF_NOTSC) 304 + cr4_toggle_bits(X86_CR4_TSD); 305 + 306 + if ((tifp ^ tifn) & _TIF_NOCPUID) 307 + set_cpuid_faulting(!!(tifn & _TIF_NOCPUID)); 224 308 } 225 309 226 310 /* ··· 615 549 out: 616 550 put_task_stack(p); 617 551 return ret; 552 + } 553 + 554 + long do_arch_prctl_common(struct task_struct *task, int option, 555 + unsigned long cpuid_enabled) 556 + { 557 + switch (option) { 558 + case ARCH_GET_CPUID: 559 + return get_cpuid_mode(); 560 + case ARCH_SET_CPUID: 561 + return set_cpuid_mode(task, cpuid_enabled); 562 + } 563 + 564 + return -EINVAL; 618 565 }
+7
arch/x86/kernel/process_32.c
··· 37 37 #include <linux/uaccess.h> 38 38 #include <linux/io.h> 39 39 #include <linux/kdebug.h> 40 + #include <linux/syscalls.h> 40 41 41 42 #include <asm/pgtable.h> 42 43 #include <asm/ldt.h> ··· 57 56 #include <asm/switch_to.h> 58 57 #include <asm/vm86.h> 59 58 #include <asm/intel_rdt.h> 59 + #include <asm/proto.h> 60 60 61 61 void __show_regs(struct pt_regs *regs, int all) 62 62 { ··· 305 303 intel_rdt_sched_in(); 306 304 307 305 return prev_p; 306 + } 307 + 308 + SYSCALL_DEFINE2(arch_prctl, int, option, unsigned long, arg2) 309 + { 310 + return do_arch_prctl_common(current, option, arg2); 308 311 }
+32 -16
arch/x86/kernel/process_64.c
··· 37 37 #include <linux/uaccess.h> 38 38 #include <linux/io.h> 39 39 #include <linux/ftrace.h> 40 + #include <linux/syscalls.h> 40 41 41 42 #include <asm/pgtable.h> 42 43 #include <asm/processor.h> ··· 205 204 (struct user_desc __user *)tls, 0); 206 205 else 207 206 #endif 208 - err = do_arch_prctl(p, ARCH_SET_FS, tls); 207 + err = do_arch_prctl_64(p, ARCH_SET_FS, tls); 209 208 if (err) 210 209 goto out; 211 210 } ··· 548 547 } 549 548 #endif 550 549 551 - long do_arch_prctl(struct task_struct *task, int code, unsigned long addr) 550 + long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2) 552 551 { 553 552 int ret = 0; 554 553 int doit = task == current; 555 554 int cpu; 556 555 557 - switch (code) { 556 + switch (option) { 558 557 case ARCH_SET_GS: 559 - if (addr >= TASK_SIZE_MAX) 558 + if (arg2 >= TASK_SIZE_MAX) 560 559 return -EPERM; 561 560 cpu = get_cpu(); 562 561 task->thread.gsindex = 0; 563 - task->thread.gsbase = addr; 562 + task->thread.gsbase = arg2; 564 563 if (doit) { 565 564 load_gs_index(0); 566 - ret = wrmsrl_safe(MSR_KERNEL_GS_BASE, addr); 565 + ret = wrmsrl_safe(MSR_KERNEL_GS_BASE, arg2); 567 566 } 568 567 put_cpu(); 569 568 break; 570 569 case ARCH_SET_FS: 571 570 /* Not strictly needed for fs, but do it for symmetry 572 571 with gs */ 573 - if (addr >= TASK_SIZE_MAX) 572 + if (arg2 >= TASK_SIZE_MAX) 574 573 return -EPERM; 575 574 cpu = get_cpu(); 576 575 task->thread.fsindex = 0; 577 - task->thread.fsbase = addr; 576 + task->thread.fsbase = arg2; 578 577 if (doit) { 579 578 /* set the selector to 0 to not confuse __switch_to */ 580 579 loadsegment(fs, 0); 581 - ret = wrmsrl_safe(MSR_FS_BASE, addr); 580 + ret = wrmsrl_safe(MSR_FS_BASE, arg2); 582 581 } 583 582 put_cpu(); 584 583 break; 585 584 case ARCH_GET_FS: { 586 585 unsigned long base; 586 + 587 587 if (doit) 588 588 rdmsrl(MSR_FS_BASE, base); 589 589 else 590 590 base = task->thread.fsbase; 591 - ret = put_user(base, (unsigned long __user *)addr); 591 + ret = put_user(base, (unsigned long __user *)arg2); 592 592 break; 593 593 } 594 594 case ARCH_GET_GS: { 595 595 unsigned long base; 596 + 596 597 if (doit) 597 598 rdmsrl(MSR_KERNEL_GS_BASE, base); 598 599 else 599 600 base = task->thread.gsbase; 600 - ret = put_user(base, (unsigned long __user *)addr); 601 + ret = put_user(base, (unsigned long __user *)arg2); 601 602 break; 602 603 } 603 604 604 605 #ifdef CONFIG_CHECKPOINT_RESTORE 605 606 # ifdef CONFIG_X86_X32_ABI 606 607 case ARCH_MAP_VDSO_X32: 607 - return prctl_map_vdso(&vdso_image_x32, addr); 608 + return prctl_map_vdso(&vdso_image_x32, arg2); 608 609 # endif 609 610 # if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION 610 611 case ARCH_MAP_VDSO_32: 611 - return prctl_map_vdso(&vdso_image_32, addr); 612 + return prctl_map_vdso(&vdso_image_32, arg2); 612 613 # endif 613 614 case ARCH_MAP_VDSO_64: 614 - return prctl_map_vdso(&vdso_image_64, addr); 615 + return prctl_map_vdso(&vdso_image_64, arg2); 615 616 #endif 616 617 617 618 default: ··· 624 621 return ret; 625 622 } 626 623 627 - long sys_arch_prctl(int code, unsigned long addr) 624 + SYSCALL_DEFINE2(arch_prctl, int, option, unsigned long, arg2) 628 625 { 629 - return do_arch_prctl(current, code, addr); 626 + long ret; 627 + 628 + ret = do_arch_prctl_64(current, option, arg2); 629 + if (ret == -EINVAL) 630 + ret = do_arch_prctl_common(current, option, arg2); 631 + 632 + return ret; 630 633 } 634 + 635 + #ifdef CONFIG_IA32_EMULATION 636 + COMPAT_SYSCALL_DEFINE2(arch_prctl, int, option, unsigned long, arg2) 637 + { 638 + return do_arch_prctl_common(current, option, arg2); 639 + } 640 + #endif 631 641 632 642 unsigned long KSTK_ESP(struct task_struct *task) 633 643 {
+4 -4
arch/x86/kernel/ptrace.c
··· 396 396 if (value >= TASK_SIZE_MAX) 397 397 return -EIO; 398 398 /* 399 - * When changing the segment base, use do_arch_prctl 399 + * When changing the segment base, use do_arch_prctl_64 400 400 * to set either thread.fs or thread.fsindex and the 401 401 * corresponding GDT slot. 402 402 */ 403 403 if (child->thread.fsbase != value) 404 - return do_arch_prctl(child, ARCH_SET_FS, value); 404 + return do_arch_prctl_64(child, ARCH_SET_FS, value); 405 405 return 0; 406 406 case offsetof(struct user_regs_struct,gs_base): 407 407 /* ··· 410 410 if (value >= TASK_SIZE_MAX) 411 411 return -EIO; 412 412 if (child->thread.gsbase != value) 413 - return do_arch_prctl(child, ARCH_SET_GS, value); 413 + return do_arch_prctl_64(child, ARCH_SET_GS, value); 414 414 return 0; 415 415 #endif 416 416 } ··· 869 869 Works just like arch_prctl, except that the arguments 870 870 are reversed. */ 871 871 case PTRACE_ARCH_PRCTL: 872 - ret = do_arch_prctl(child, data, addr); 872 + ret = do_arch_prctl_64(child, data, addr); 873 873 break; 874 874 #endif 875 875
+1 -1
arch/x86/um/Makefile
··· 16 16 17 17 ifeq ($(CONFIG_X86_32),y) 18 18 19 - obj-y += checksum_32.o 19 + obj-y += checksum_32.o syscalls_32.o 20 20 obj-$(CONFIG_ELF_CORE) += elfcore.o 21 21 22 22 subarch-y = ../lib/string_32.o ../lib/atomic64_32.o ../lib/atomic64_cx8_32.o
+1 -1
arch/x86/um/asm/ptrace.h
··· 78 78 return -ENOSYS; 79 79 } 80 80 81 - extern long arch_prctl(struct task_struct *task, int code, 81 + extern long arch_prctl(struct task_struct *task, int option, 82 82 unsigned long __user *addr); 83 83 84 84 #endif
+2 -2
arch/x86/um/os-Linux/prctl.c
··· 6 6 #include <sys/ptrace.h> 7 7 #include <asm/ptrace.h> 8 8 9 - int os_arch_prctl(int pid, int code, unsigned long *addr) 9 + int os_arch_prctl(int pid, int option, unsigned long *arg2) 10 10 { 11 - return ptrace(PTRACE_ARCH_PRCTL, pid, (unsigned long) addr, code); 11 + return ptrace(PTRACE_ARCH_PRCTL, pid, (unsigned long) arg2, option); 12 12 }
+7
arch/x86/um/syscalls_32.c
··· 1 + #include <linux/syscalls.h> 2 + #include <os.h> 3 + 4 + SYSCALL_DEFINE2(arch_prctl, int, option, unsigned long, arg2) 5 + { 6 + return -EINVAL; 7 + }
+11 -9
arch/x86/um/syscalls_64.c
··· 7 7 8 8 #include <linux/sched.h> 9 9 #include <linux/sched/mm.h> 10 + #include <linux/syscalls.h> 10 11 #include <linux/uaccess.h> 11 12 #include <asm/prctl.h> /* XXX This should get the constants from libc */ 12 13 #include <os.h> 13 14 14 - long arch_prctl(struct task_struct *task, int code, unsigned long __user *addr) 15 + long arch_prctl(struct task_struct *task, int option) 16 + unsigned long __user *arg2) 15 17 { 16 - unsigned long *ptr = addr, tmp; 18 + unsigned long *ptr = arg2, tmp; 17 19 long ret; 18 20 int pid = task->mm->context.id.u.pid; 19 21 ··· 32 30 * arch_prctl is run on the host, then the registers are read 33 31 * back. 34 32 */ 35 - switch (code) { 33 + switch (option) { 36 34 case ARCH_SET_FS: 37 35 case ARCH_SET_GS: 38 36 ret = restore_registers(pid, &current->thread.regs.regs); ··· 52 50 ptr = &tmp; 53 51 } 54 52 55 - ret = os_arch_prctl(pid, code, ptr); 53 + ret = os_arch_prctl(pid, option, ptr); 56 54 if (ret) 57 55 return ret; 58 56 59 - switch (code) { 57 + switch (option) { 60 58 case ARCH_SET_FS: 61 59 current->thread.arch.fs = (unsigned long) ptr; 62 60 ret = save_registers(pid, &current->thread.regs.regs); ··· 65 63 ret = save_registers(pid, &current->thread.regs.regs); 66 64 break; 67 65 case ARCH_GET_FS: 68 - ret = put_user(tmp, addr); 66 + ret = put_user(tmp, arg2); 69 67 break; 70 68 case ARCH_GET_GS: 71 - ret = put_user(tmp, addr); 69 + ret = put_user(tmp, arg2); 72 70 break; 73 71 } 74 72 75 73 return ret; 76 74 } 77 75 78 - long sys_arch_prctl(int code, unsigned long addr) 76 + SYSCALL_DEFINE2(arch_prctl, int, option, unsigned long, arg2) 79 77 { 80 - return arch_prctl(current, code, (unsigned long __user *) addr); 78 + return arch_prctl(current, option, (unsigned long __user *) arg2); 81 79 } 82 80 83 81 void arch_switch_to(struct task_struct *to)
+1
fs/exec.c
··· 1320 1320 else 1321 1321 set_dumpable(current->mm, suid_dumpable); 1322 1322 1323 + arch_setup_new_exec(); 1323 1324 perf_event_exec(); 1324 1325 __set_task_comm(current, kbasename(bprm->filename), true); 1325 1326
+2
include/linux/compat.h
··· 723 723 asmlinkage long compat_sys_fanotify_mark(int, unsigned int, __u32, __u32, 724 724 int, const char __user *); 725 725 726 + asmlinkage long compat_sys_arch_prctl(int option, unsigned long arg2); 727 + 726 728 /* 727 729 * For most but not all architectures, "am I in a compat syscall?" and 728 730 * "am I a compat task?" are the same question. For architectures on which
+4
include/linux/thread_info.h
··· 101 101 { } 102 102 #endif /* CONFIG_HARDENED_USERCOPY */ 103 103 104 + #ifndef arch_setup_new_exec 105 + static inline void arch_setup_new_exec(void) { } 106 + #endif 107 + 104 108 #endif /* __KERNEL__ */ 105 109 106 110 #endif /* _LINUX_THREAD_INFO_H */
+1
tools/arch/x86/include/asm/cpufeatures.h
··· 187 187 * Reuse free bits when adding new feature flags! 188 188 */ 189 189 #define X86_FEATURE_RING3MWAIT ( 7*32+ 0) /* Ring 3 MONITOR/MWAIT */ 190 + #define X86_FEATURE_CPUID_FAULT ( 7*32+ 1) /* Intel CPUID faulting */ 190 191 #define X86_FEATURE_CPB ( 7*32+ 2) /* AMD Core Performance Boost */ 191 192 #define X86_FEATURE_EPB ( 7*32+ 3) /* IA32_ENERGY_PERF_BIAS support */ 192 193 #define X86_FEATURE_CAT_L3 ( 7*32+ 4) /* Cache Allocation Technology L3 */
+1 -1
tools/arch/x86/lib/memcpy_64.S
··· 286 286 _ASM_EXTABLE_FAULT(.L_copy_leading_bytes, .L_memcpy_mcsafe_fail) 287 287 _ASM_EXTABLE_FAULT(.L_cache_w0, .L_memcpy_mcsafe_fail) 288 288 _ASM_EXTABLE_FAULT(.L_cache_w1, .L_memcpy_mcsafe_fail) 289 - _ASM_EXTABLE_FAULT(.L_cache_w3, .L_memcpy_mcsafe_fail) 289 + _ASM_EXTABLE_FAULT(.L_cache_w2, .L_memcpy_mcsafe_fail) 290 290 _ASM_EXTABLE_FAULT(.L_cache_w3, .L_memcpy_mcsafe_fail) 291 291 _ASM_EXTABLE_FAULT(.L_cache_w4, .L_memcpy_mcsafe_fail) 292 292 _ASM_EXTABLE_FAULT(.L_cache_w5, .L_memcpy_mcsafe_fail)
+10
tools/include/linux/bug.h
··· 1 + #ifndef _TOOLS_PERF_LINUX_BUG_H 2 + #define _TOOLS_PERF_LINUX_BUG_H 3 + 4 + /* Force a compilation error if condition is true, but also produce a 5 + result (of value 0 and type size_t), so the expression can be used 6 + e.g. in a structure initializer (or where-ever else comma expressions 7 + aren't permitted). */ 8 + #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 9 + 10 + #endif /* _TOOLS_PERF_LINUX_BUG_H */
+3
tools/include/linux/compiler-gcc.h
··· 16 16 #if GCC_VERSION >= 40300 17 17 # define __compiletime_error(message) __attribute__((error(message))) 18 18 #endif /* GCC_VERSION >= 40300 */ 19 + 20 + /* &a[0] degrades to a pointer: a different type from an array */ 21 + #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
+5
tools/include/linux/compiler.h
··· 17 17 # define __always_inline inline __attribute__((always_inline)) 18 18 #endif 19 19 20 + /* Are two types/vars the same type (ignoring qualifiers)? */ 21 + #ifndef __same_type 22 + # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) 23 + #endif 24 + 20 25 #ifdef __ANDROID__ 21 26 /* 22 27 * FIXME: Big hammer to get rid of tons of:
-4
tools/include/linux/hashtable.h
··· 13 13 #include <linux/hash.h> 14 14 #include <linux/log2.h> 15 15 16 - #ifndef ARRAY_SIZE 17 - #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 18 - #endif 19 - 20 16 #define DEFINE_HASHTABLE(name, bits) \ 21 17 struct hlist_head name[1 << (bits)] = \ 22 18 { [0 ... ((1 << (bits)) - 1)] = HLIST_HEAD_INIT }
+3
tools/include/linux/kernel.h
··· 4 4 #include <stdarg.h> 5 5 #include <stddef.h> 6 6 #include <assert.h> 7 + #include <linux/compiler.h> 7 8 8 9 #ifndef UINT_MAX 9 10 #define UINT_MAX (~0U) ··· 76 75 77 76 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); 78 77 int scnprintf(char * buf, size_t size, const char * fmt, ...); 78 + 79 + #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) 79 80 80 81 /* 81 82 * This looks more complex than it should be. But we need to
+3
tools/include/linux/log2.h
··· 12 12 #ifndef _TOOLS_LINUX_LOG2_H 13 13 #define _TOOLS_LINUX_LOG2_H 14 14 15 + #include <linux/bitops.h> 16 + #include <linux/types.h> 17 + 15 18 /* 16 19 * non-constant log of base 2 calculators 17 20 * - the arch may override these in asm/bitops.h if they can be implemented
+3 -2
tools/include/uapi/linux/stat.h
··· 114 114 __u64 stx_ino; /* Inode number */ 115 115 __u64 stx_size; /* File size */ 116 116 __u64 stx_blocks; /* Number of 512-byte blocks allocated */ 117 - __u64 __spare1[1]; 117 + __u64 stx_attributes_mask; /* Mask to show what's supported in stx_attributes */ 118 118 /* 0x40 */ 119 119 struct statx_timestamp stx_atime; /* Last access time */ 120 120 struct statx_timestamp stx_btime; /* File creation time */ ··· 152 152 #define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */ 153 153 #define STATX_BTIME 0x00000800U /* Want/got stx_btime */ 154 154 #define STATX_ALL 0x00000fffU /* All currently supported flags */ 155 + #define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */ 155 156 156 157 /* 157 - * Attributes to be found in stx_attributes 158 + * Attributes to be found in stx_attributes and masked in stx_attributes_mask. 158 159 * 159 160 * These give information about the features or the state of a file that might 160 161 * be of use to ordinary userspace programs such as GUIs or ls rather than
+1
tools/lib/subcmd/help.h
··· 2 2 #define __SUBCMD_HELP_H 3 3 4 4 #include <sys/types.h> 5 + #include <stdio.h> 5 6 6 7 struct cmdnames { 7 8 size_t alloc;
+1
tools/lib/symbol/kallsyms.c
··· 1 + #include <ctype.h> 1 2 #include "symbol/kallsyms.h" 2 3 #include <stdio.h> 3 4 #include <stdlib.h>
+1 -2
tools/objtool/builtin-check.c
··· 36 36 #include "warn.h" 37 37 38 38 #include <linux/hashtable.h> 39 - 40 - #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 39 + #include <linux/kernel.h> 41 40 42 41 #define STATE_FP_SAVED 0x1 43 42 #define STATE_FP_SETUP 0x2
+1 -2
tools/objtool/objtool.c
··· 31 31 #include <stdlib.h> 32 32 #include <subcmd/exec-cmd.h> 33 33 #include <subcmd/pager.h> 34 + #include <linux/kernel.h> 34 35 35 36 #include "builtin.h" 36 - 37 - #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) 38 37 39 38 struct cmd_struct { 40 39 const char *name;
+1
tools/perf/MANIFEST
··· 64 64 tools/include/linux/compiler.h 65 65 tools/include/linux/compiler-gcc.h 66 66 tools/include/linux/coresight-pmu.h 67 + tools/include/linux/bug.h 67 68 tools/include/linux/filter.h 68 69 tools/include/linux/hash.h 69 70 tools/include/linux/kernel.h
+1
tools/perf/arch/arm/util/cs-etm.c
··· 33 33 #include "../../util/cs-etm.h" 34 34 35 35 #include <stdlib.h> 36 + #include <sys/stat.h> 36 37 37 38 #define ENABLE_SINK_MAX 128 38 39 #define CS_BUS_DEVICE_PATH "/bus/coresight/devices/"
+2 -2
tools/perf/arch/arm/util/dwarf-regs.c
··· 9 9 */ 10 10 11 11 #include <stddef.h> 12 + #include <linux/stringify.h> 12 13 #include <dwarf-regs.h> 13 14 14 15 struct pt_regs_dwarfnum { ··· 17 16 unsigned int dwarfnum; 18 17 }; 19 18 20 - #define STR(s) #s 21 19 #define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num} 22 20 #define GPR_DWARFNUM_NAME(num) \ 23 - {.name = STR(%r##num), .dwarfnum = num} 21 + {.name = __stringify(%r##num), .dwarfnum = num} 24 22 #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0} 25 23 26 24 /*
+1
tools/perf/arch/arm/util/unwind-libdw.c
··· 1 1 #include <elfutils/libdwfl.h> 2 2 #include "../../util/unwind-libdw.h" 3 3 #include "../../util/perf_regs.h" 4 + #include "../../util/event.h" 4 5 5 6 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg) 6 7 {
+4 -1
tools/perf/arch/arm64/util/dwarf-regs.c
··· 8 8 * published by the Free Software Foundation. 9 9 */ 10 10 11 + #include <errno.h> 11 12 #include <stddef.h> 13 + #include <string.h> 12 14 #include <dwarf-regs.h> 13 15 #include <linux/ptrace.h> /* for struct user_pt_regs */ 16 + #include <linux/stringify.h> 14 17 #include "util.h" 15 18 16 19 struct pt_regs_dwarfnum { ··· 23 20 24 21 #define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num} 25 22 #define GPR_DWARFNUM_NAME(num) \ 26 - {.name = STR(%x##num), .dwarfnum = num} 23 + {.name = __stringify(%x##num), .dwarfnum = num} 27 24 #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0} 28 25 #define DWARFNUM2OFFSET(index) \ 29 26 (index * sizeof((struct user_pt_regs *)0)->regs[0])
+1 -1
tools/perf/arch/arm64/util/unwind-libunwind.c
··· 1 + #include <errno.h> 1 2 2 3 #ifndef REMOTE_UNWIND_LIBUNWIND 3 - #include <errno.h> 4 4 #include <libunwind.h> 5 5 #include "perf_regs.h" 6 6 #include "../../util/unwind.h"
+2
tools/perf/arch/common.c
··· 4 4 #include "../util/util.h" 5 5 #include "../util/debug.h" 6 6 7 + #include "sane_ctype.h" 8 + 7 9 const char *const arm_triplets[] = { 8 10 "arm-eabi-", 9 11 "arm-linux-androideabi-",
+3 -2
tools/perf/arch/powerpc/util/dwarf-regs.c
··· 15 15 #include <dwarf-regs.h> 16 16 #include <linux/ptrace.h> 17 17 #include <linux/kernel.h> 18 + #include <linux/stringify.h> 18 19 #include "util.h" 19 20 20 21 struct pt_regs_dwarfnum { ··· 25 24 }; 26 25 27 26 #define REG_DWARFNUM_NAME(r, num) \ 28 - {.name = STR(%)STR(r), .dwarfnum = num, \ 27 + {.name = __stringify(%)__stringify(r), .dwarfnum = num, \ 29 28 .ptregs_offset = offsetof(struct pt_regs, r)} 30 29 #define GPR_DWARFNUM_NAME(num) \ 31 - {.name = STR(%gpr##num), .dwarfnum = num, \ 30 + {.name = __stringify(%gpr##num), .dwarfnum = num, \ 32 31 .ptregs_offset = offsetof(struct pt_regs, gpr[num])} 33 32 #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0, .ptregs_offset = 0} 34 33
+1
tools/perf/arch/powerpc/util/kvm-stat.c
··· 1 + #include <errno.h> 1 2 #include "util/kvm-stat.h" 2 3 #include "util/parse-events.h" 3 4 #include "util/debug.h"
+1
tools/perf/arch/powerpc/util/perf_regs.c
··· 1 + #include <errno.h> 1 2 #include <string.h> 2 3 #include <regex.h> 3 4
+1
tools/perf/arch/s390/util/kvm-stat.c
··· 9 9 * as published by the Free Software Foundation. 10 10 */ 11 11 12 + #include <errno.h> 12 13 #include "../../util/kvm-stat.h" 13 14 #include <asm/sie.h> 14 15
+3
tools/perf/arch/x86/tests/intel-cqm.c
··· 6 6 #include "evsel.h" 7 7 #include "arch-tests.h" 8 8 9 + #include <signal.h> 9 10 #include <sys/mman.h> 11 + #include <sys/wait.h> 12 + #include <errno.h> 10 13 #include <string.h> 11 14 12 15 static pid_t spawn(void)
+2
tools/perf/arch/x86/tests/perf-time-to-tsc.c
··· 1 + #include <errno.h> 2 + #include <inttypes.h> 1 3 #include <stdio.h> 2 4 #include <unistd.h> 3 5 #include <linux/types.h>
+1
tools/perf/arch/x86/util/auxtrace.c
··· 13 13 * 14 14 */ 15 15 16 + #include <errno.h> 16 17 #include <stdbool.h> 17 18 18 19 #include "../../util/header.h"
+1
tools/perf/arch/x86/util/intel-bts.c
··· 13 13 * 14 14 */ 15 15 16 + #include <errno.h> 16 17 #include <linux/kernel.h> 17 18 #include <linux/types.h> 18 19 #include <linux/bitops.h>
+1
tools/perf/arch/x86/util/intel-pt.c
··· 13 13 * 14 14 */ 15 15 16 + #include <errno.h> 16 17 #include <stdbool.h> 17 18 #include <linux/kernel.h> 18 19 #include <linux/types.h>
+1
tools/perf/arch/x86/util/kvm-stat.c
··· 1 + #include <errno.h> 1 2 #include "../../util/kvm-stat.h" 2 3 #include <asm/svm.h> 3 4 #include <asm/vmx.h>
+1
tools/perf/arch/x86/util/perf_regs.c
··· 1 + #include <errno.h> 1 2 #include <string.h> 2 3 #include <regex.h> 3 4
+1
tools/perf/arch/x86/util/unwind-libdw.c
··· 1 1 #include <elfutils/libdwfl.h> 2 2 #include "../../util/unwind-libdw.h" 3 3 #include "../../util/perf_regs.h" 4 + #include "../../util/event.h" 4 5 5 6 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg) 6 7 {
+1
tools/perf/bench/mem-functions.c
··· 12 12 #include <subcmd/parse-options.h> 13 13 #include "../util/header.h" 14 14 #include "../util/cloexec.h" 15 + #include "../util/string2.h" 15 16 #include "bench.h" 16 17 #include "mem-memcpy-arch.h" 17 18 #include "mem-memset-arch.h"
+2
tools/perf/bench/numa.c
··· 4 4 * numa: Simulate NUMA-sensitive workload and measure their NUMA performance 5 5 */ 6 6 7 + #include <inttypes.h> 7 8 /* For the CLR_() macros */ 8 9 #include <pthread.h> 9 10 ··· 31 30 #include <sys/wait.h> 32 31 #include <sys/prctl.h> 33 32 #include <sys/types.h> 33 + #include <linux/kernel.h> 34 34 #include <linux/time64.h> 35 35 36 36 #include <numa.h>
+1
tools/perf/builtin-annotate.c
··· 33 33 #include "util/block-range.h" 34 34 35 35 #include <dlfcn.h> 36 + #include <errno.h> 36 37 #include <linux/bitmap.h> 37 38 38 39 struct perf_annotate {
+2
tools/perf/builtin-buildid-cache.c
··· 10 10 #include <sys/time.h> 11 11 #include <time.h> 12 12 #include <dirent.h> 13 + #include <errno.h> 13 14 #include <unistd.h> 14 15 #include "builtin.h" 15 16 #include "perf.h" ··· 22 21 #include "util/build-id.h" 23 22 #include "util/session.h" 24 23 #include "util/symbol.h" 24 + #include "util/time-utils.h" 25 25 26 26 static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid) 27 27 {
+1
tools/perf/builtin-buildid-list.c
··· 16 16 #include "util/session.h" 17 17 #include "util/symbol.h" 18 18 #include "util/data.h" 19 + #include <errno.h> 19 20 20 21 static int sysfs__fprintf_build_id(FILE *fp) 21 22 {
+4
tools/perf/builtin-c2c.c
··· 9 9 * Dick Fowles <fowles@inreach.com> 10 10 * Joe Mario <jmario@redhat.com> 11 11 */ 12 + #include <errno.h> 13 + #include <inttypes.h> 12 14 #include <linux/compiler.h> 13 15 #include <linux/kernel.h> 14 16 #include <linux/stringify.h> 15 17 #include <asm/bug.h> 18 + #include <sys/param.h> 16 19 #include "util.h" 17 20 #include "debug.h" 18 21 #include "builtin.h" ··· 32 29 #include <asm/bug.h> 33 30 #include "ui/browsers/hists.h" 34 31 #include "evlist.h" 32 + #include "thread.h" 35 33 36 34 struct c2c_hists { 37 35 struct hists hists;
+2
tools/perf/builtin-diff.c
··· 19 19 #include "util/data.h" 20 20 #include "util/config.h" 21 21 22 + #include <errno.h> 23 + #include <inttypes.h> 22 24 #include <stdlib.h> 23 25 #include <math.h> 24 26
+3
tools/perf/builtin-ftrace.c
··· 9 9 #include "builtin.h" 10 10 #include "perf.h" 11 11 12 + #include <errno.h> 12 13 #include <unistd.h> 13 14 #include <signal.h> 14 15 #include <fcntl.h> 16 + #include <poll.h> 15 17 16 18 #include "debug.h" 17 19 #include <subcmd/parse-options.h> 20 + #include <api/fs/tracing_path.h> 18 21 #include "evlist.h" 19 22 #include "target.h" 20 23 #include "cpumap.h"
+8 -2
tools/perf/builtin-help.c
··· 12 12 #include <subcmd/run-command.h> 13 13 #include <subcmd/help.h> 14 14 #include "util/debug.h" 15 + #include <linux/kernel.h> 16 + #include <errno.h> 17 + #include <stdio.h> 18 + #include <sys/types.h> 19 + #include <sys/stat.h> 20 + #include <unistd.h> 15 21 16 22 static struct man_viewer_list { 17 23 struct man_viewer_list *next; 18 - char name[FLEX_ARRAY]; 24 + char name[0]; 19 25 } *man_viewer_list; 20 26 21 27 static struct man_viewer_info_list { 22 28 struct man_viewer_info_list *next; 23 29 const char *info; 24 - char name[FLEX_ARRAY]; 30 + char name[0]; 25 31 } *man_viewer_info_list; 26 32 27 33 enum help_format {
+3
tools/perf/builtin-inject.c
··· 18 18 #include "util/data.h" 19 19 #include "util/auxtrace.h" 20 20 #include "util/jit.h" 21 + #include "util/thread.h" 21 22 22 23 #include <subcmd/parse-options.h> 23 24 24 25 #include <linux/list.h> 26 + #include <errno.h> 27 + #include <signal.h> 25 28 26 29 struct perf_inject { 27 30 struct perf_tool tool;
+1
tools/perf/builtin-kallsyms.c
··· 7 7 * 8 8 * Released under the GPL v2. (and only v2, not any later version) 9 9 */ 10 + #include <inttypes.h> 10 11 #include "builtin.h" 11 12 #include <linux/compiler.h> 12 13 #include <subcmd/parse-options.h>
+5
tools/perf/builtin-kmem.c
··· 20 20 21 21 #include "util/debug.h" 22 22 23 + #include <linux/kernel.h> 23 24 #include <linux/rbtree.h> 24 25 #include <linux/string.h> 26 + #include <errno.h> 27 + #include <inttypes.h> 25 28 #include <locale.h> 26 29 #include <regex.h> 30 + 31 + #include "sane_ctype.h" 27 32 28 33 static int kmem_slab; 29 34 static int kmem_page;
+21
tools/perf/builtin-kvm.c
··· 3 3 4 4 #include "util/evsel.h" 5 5 #include "util/evlist.h" 6 + #include "util/term.h" 6 7 #include "util/util.h" 7 8 #include "util/cache.h" 8 9 #include "util/symbol.h" ··· 24 23 #ifdef HAVE_TIMERFD_SUPPORT 25 24 #include <sys/timerfd.h> 26 25 #endif 26 + #include <sys/time.h> 27 27 28 + #include <linux/kernel.h> 28 29 #include <linux/time64.h> 30 + #include <errno.h> 31 + #include <inttypes.h> 32 + #include <poll.h> 29 33 #include <termios.h> 30 34 #include <semaphore.h> 35 + #include <signal.h> 31 36 #include <pthread.h> 32 37 #include <math.h> 38 + 39 + static const char *get_filename_for_perf_kvm(void) 40 + { 41 + const char *filename; 42 + 43 + if (perf_host && !perf_guest) 44 + filename = strdup("perf.data.host"); 45 + else if (!perf_host && perf_guest) 46 + filename = strdup("perf.data.guest"); 47 + else 48 + filename = strdup("perf.data.kvm"); 49 + 50 + return filename; 51 + } 33 52 34 53 #ifdef HAVE_KVM_STAT_SUPPORT 35 54 #include "util/kvm-stat.h"
+3
tools/perf/builtin-lock.c
··· 1 + #include <errno.h> 2 + #include <inttypes.h> 1 3 #include "builtin.h" 2 4 #include "perf.h" 3 5 ··· 28 26 29 27 #include <linux/list.h> 30 28 #include <linux/hash.h> 29 + #include <linux/kernel.h> 31 30 32 31 static struct perf_session *session; 33 32
+5
tools/perf/builtin-mem.c
··· 1 + #include <inttypes.h> 2 + #include <sys/types.h> 3 + #include <sys/stat.h> 4 + #include <unistd.h> 1 5 #include "builtin.h" 2 6 #include "perf.h" 3 7 ··· 12 8 #include "util/data.h" 13 9 #include "util/mem-events.h" 14 10 #include "util/debug.h" 11 + #include "util/symbol.h" 15 12 16 13 #define MEM_OPERATION_LOAD 0x1 17 14 #define MEM_OPERATION_STORE 0x2
+7
tools/perf/builtin-record.c
··· 38 38 #include "util/bpf-loader.h" 39 39 #include "util/trigger.h" 40 40 #include "util/perf-hooks.h" 41 + #include "util/time-utils.h" 42 + #include "util/units.h" 41 43 #include "asm/bug.h" 42 44 45 + #include <errno.h> 46 + #include <inttypes.h> 47 + #include <poll.h> 43 48 #include <unistd.h> 44 49 #include <sched.h> 50 + #include <signal.h> 45 51 #include <sys/mman.h> 52 + #include <sys/wait.h> 46 53 #include <asm/bug.h> 47 54 #include <linux/time64.h> 48 55
+8 -1
tools/perf/builtin-report.c
··· 16 16 #include <linux/rbtree.h> 17 17 #include "util/symbol.h" 18 18 #include "util/callchain.h" 19 - #include "util/strlist.h" 20 19 #include "util/values.h" 21 20 22 21 #include "perf.h" ··· 37 38 #include "arch/common.h" 38 39 #include "util/time-utils.h" 39 40 #include "util/auxtrace.h" 41 + #include "util/units.h" 40 42 41 43 #include <dlfcn.h> 44 + #include <errno.h> 45 + #include <inttypes.h> 46 + #include <regex.h> 47 + #include <signal.h> 42 48 #include <linux/bitmap.h> 43 49 #include <linux/stringify.h> 50 + #include <sys/types.h> 51 + #include <sys/stat.h> 52 + #include <unistd.h> 44 53 45 54 struct report { 46 55 struct perf_tool tool;
+5
tools/perf/builtin-sched.c
··· 22 22 23 23 #include "util/debug.h" 24 24 25 + #include <linux/kernel.h> 25 26 #include <linux/log2.h> 26 27 #include <sys/prctl.h> 27 28 #include <sys/resource.h> 29 + #include <inttypes.h> 28 30 31 + #include <errno.h> 29 32 #include <semaphore.h> 30 33 #include <pthread.h> 31 34 #include <math.h> 32 35 #include <api/fs/fs.h> 33 36 #include <linux/time64.h> 37 + 38 + #include "sane_ctype.h" 34 39 35 40 #define PR_SET_NAME 15 /* Set process name */ 36 41 #define MAX_CPUS 4096
+13
tools/perf/builtin-script.c
··· 21 21 #include "util/cpumap.h" 22 22 #include "util/thread_map.h" 23 23 #include "util/stat.h" 24 + #include "util/string2.h" 24 25 #include "util/thread-stack.h" 25 26 #include "util/time-utils.h" 27 + #include "print_binary.h" 26 28 #include <linux/bitmap.h> 29 + #include <linux/kernel.h> 27 30 #include <linux/stringify.h> 28 31 #include <linux/time64.h> 29 32 #include "asm/bug.h" 30 33 #include "util/mem-events.h" 31 34 #include "util/dump-insn.h" 35 + #include <dirent.h> 36 + #include <errno.h> 37 + #include <inttypes.h> 38 + #include <signal.h> 39 + #include <sys/param.h> 40 + #include <sys/types.h> 41 + #include <sys/stat.h> 42 + #include <unistd.h> 43 + 44 + #include "sane_ctype.h" 32 45 33 46 static char const *script_name; 34 47 static char const *generate_script_lang;
+10
tools/perf/builtin-stat.c
··· 64 64 #include "util/session.h" 65 65 #include "util/tool.h" 66 66 #include "util/group.h" 67 + #include "util/string2.h" 67 68 #include "asm/bug.h" 68 69 69 70 #include <linux/time64.h> 70 71 #include <api/fs/fs.h> 72 + #include <errno.h> 73 + #include <signal.h> 71 74 #include <stdlib.h> 72 75 #include <sys/prctl.h> 76 + #include <inttypes.h> 73 77 #include <locale.h> 74 78 #include <math.h> 79 + #include <sys/types.h> 80 + #include <sys/stat.h> 81 + #include <sys/wait.h> 82 + #include <unistd.h> 83 + 84 + #include "sane_ctype.h" 75 85 76 86 #define DEFAULT_SEPARATOR " " 77 87 #define CNTR_NOT_SUPPORTED "<not supported>"
+4 -1
tools/perf/builtin-timechart.c
··· 12 12 * of the License. 13 13 */ 14 14 15 + #include <errno.h> 16 + #include <inttypes.h> 15 17 #include <traceevent/event-parse.h> 16 18 17 19 #include "builtin.h" ··· 25 23 #include "util/cache.h" 26 24 #include "util/evlist.h" 27 25 #include "util/evsel.h" 26 + #include <linux/kernel.h> 28 27 #include <linux/rbtree.h> 29 28 #include <linux/time64.h> 30 29 #include "util/symbol.h" 30 + #include "util/thread.h" 31 31 #include "util/callchain.h" 32 - #include "util/strlist.h" 33 32 34 33 #include "perf.h" 35 34 #include "util/header.h"
+4
tools/perf/builtin-top.c
··· 40 40 #include "util/cpumap.h" 41 41 #include "util/xyarray.h" 42 42 #include "util/sort.h" 43 + #include "util/term.h" 43 44 #include "util/intlist.h" 44 45 #include "util/parse-branch-options.h" 45 46 #include "arch/common.h" ··· 59 58 #include <errno.h> 60 59 #include <time.h> 61 60 #include <sched.h> 61 + #include <signal.h> 62 62 63 63 #include <sys/syscall.h> 64 64 #include <sys/ioctl.h> ··· 73 71 #include <linux/stringify.h> 74 72 #include <linux/time64.h> 75 73 #include <linux/types.h> 74 + 75 + #include "sane_ctype.h" 76 76 77 77 static volatile int done; 78 78
+10
tools/perf/builtin-trace.c
··· 24 24 #include "util/evlist.h" 25 25 #include <subcmd/exec-cmd.h> 26 26 #include "util/machine.h" 27 + #include "util/path.h" 27 28 #include "util/session.h" 28 29 #include "util/thread.h" 29 30 #include <subcmd/parse-options.h> ··· 37 36 #include "util/parse-events.h" 38 37 #include "util/bpf-loader.h" 39 38 #include "callchain.h" 39 + #include "print_binary.h" 40 + #include "string2.h" 40 41 #include "syscalltbl.h" 41 42 #include "rb_resort.h" 42 43 44 + #include <errno.h> 45 + #include <inttypes.h> 43 46 #include <libaudit.h> /* FIXME: Still needed for audit_errno_to_name */ 47 + #include <poll.h> 48 + #include <signal.h> 44 49 #include <stdlib.h> 45 50 #include <string.h> 46 51 #include <linux/err.h> 47 52 #include <linux/filter.h> 48 53 #include <linux/audit.h> 54 + #include <linux/kernel.h> 49 55 #include <linux/random.h> 50 56 #include <linux/stringify.h> 51 57 #include <linux/time64.h> 58 + 59 + #include "sane_ctype.h" 52 60 53 61 #ifndef O_CLOEXEC 54 62 # define O_CLOEXEC 02000000
+2 -1
tools/perf/builtin-version.c
··· 1 - #include "util/util.h" 2 1 #include "builtin.h" 3 2 #include "perf.h" 3 + #include <linux/compiler.h> 4 + #include <stdio.h> 4 5 5 6 int cmd_version(int argc __maybe_unused, const char **argv __maybe_unused) 6 7 {
-4
tools/perf/builtin.h
··· 2 2 #define BUILTIN_H 3 3 4 4 #include "util/util.h" 5 - #include "util/strbuf.h" 6 5 7 6 extern const char perf_usage_string[]; 8 7 extern const char perf_more_info_string[]; 9 8 10 9 void list_common_cmds_help(void); 11 10 const char *help_unknown_cmd(const char *cmd); 12 - void prune_packed_objects(int); 13 - int read_line_with_nul(char *buf, int size, FILE *file); 14 - int check_pager_config(const char *cmd); 15 11 16 12 int cmd_annotate(int argc, const char **argv); 17 13 int cmd_bench(int argc, const char **argv);
+7 -11
tools/perf/perf.c
··· 19 19 #include "util/debug.h" 20 20 #include <api/fs/fs.h> 21 21 #include <api/fs/tracing_path.h> 22 + #include <errno.h> 22 23 #include <pthread.h> 24 + #include <signal.h> 23 25 #include <stdlib.h> 24 26 #include <time.h> 27 + #include <sys/types.h> 28 + #include <sys/stat.h> 29 + #include <unistd.h> 30 + #include <linux/kernel.h> 25 31 26 32 const char perf_usage_string[] = 27 33 "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]"; ··· 94 88 } 95 89 96 90 /* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */ 97 - int check_pager_config(const char *cmd) 91 + static int check_pager_config(const char *cmd) 98 92 { 99 93 int err; 100 94 struct pager_config c; ··· 333 327 { 334 328 const char *cmd = argv[0]; 335 329 unsigned int i; 336 - static const char ext[] = STRIP_EXTENSION; 337 - 338 - if (sizeof(ext) > 1) { 339 - i = strlen(argv[0]) - strlen(ext); 340 - if (i > 0 && !strcmp(argv[0] + i, ext)) { 341 - char *argv0 = strdup(argv[0]); 342 - argv[0] = cmd = argv0; 343 - argv0[i] = '\0'; 344 - } 345 - } 346 330 347 331 /* Turn "perf cmd --help" into "perf help cmd" */ 348 332 if (argc > 1 && !strcmp(argv[1], "--help")) {
+6
tools/perf/tests/attr.c
··· 18 18 * permissions. All the event text files are stored there. 19 19 */ 20 20 21 + #include <errno.h> 22 + #include <inttypes.h> 21 23 #include <stdlib.h> 22 24 #include <stdio.h> 23 25 #include <linux/types.h> 24 26 #include <linux/kernel.h> 27 + #include <sys/param.h> 28 + #include <sys/types.h> 29 + #include <sys/stat.h> 30 + #include <unistd.h> 25 31 #include "../perf.h" 26 32 #include "util.h" 27 33 #include <subcmd/exec-cmd.h>
+1
tools/perf/tests/backward-ring-buffer.c
··· 8 8 #include <sys/prctl.h> 9 9 #include "tests.h" 10 10 #include "debug.h" 11 + #include <errno.h> 11 12 12 13 #define NR_ITERS 111 13 14
+4
tools/perf/tests/bpf.c
··· 1 + #include <errno.h> 1 2 #include <stdio.h> 2 3 #include <sys/epoll.h> 4 + #include <sys/types.h> 5 + #include <sys/stat.h> 3 6 #include <util/util.h> 4 7 #include <util/bpf-loader.h> 5 8 #include <util/evlist.h> 6 9 #include <linux/bpf.h> 7 10 #include <linux/filter.h> 11 + #include <linux/kernel.h> 8 12 #include <api/fs/fs.h> 9 13 #include <bpf/bpf.h> 10 14 #include "tests.h"
+3
tools/perf/tests/builtin-test.c
··· 3 3 * 4 4 * Builtin regression testing command: ever growing number of sanity tests 5 5 */ 6 + #include <errno.h> 6 7 #include <unistd.h> 7 8 #include <string.h> 9 + #include <sys/wait.h> 8 10 #include "builtin.h" 9 11 #include "hist.h" 10 12 #include "intlist.h" ··· 15 13 #include "color.h" 16 14 #include <subcmd/parse-options.h> 17 15 #include "symbol.h" 16 + #include <linux/kernel.h> 18 17 19 18 static bool dont_fork; 20 19
+1
tools/perf/tests/clang.c
··· 2 2 #include "debug.h" 3 3 #include "util.h" 4 4 #include "c++/clang-c.h" 5 + #include <linux/kernel.h> 5 6 6 7 static struct { 7 8 int (*func)(void);
+6 -1
tools/perf/tests/code-reading.c
··· 1 + #include <errno.h> 2 + #include <linux/kernel.h> 1 3 #include <linux/types.h> 4 + #include <inttypes.h> 2 5 #include <stdlib.h> 3 6 #include <unistd.h> 4 7 #include <stdio.h> 5 - #include <ctype.h> 6 8 #include <string.h> 9 + #include <sys/param.h> 7 10 8 11 #include "parse-events.h" 9 12 #include "evlist.h" ··· 18 15 #include "thread.h" 19 16 20 17 #include "tests.h" 18 + 19 + #include "sane_ctype.h" 21 20 22 21 #define BUFSZ 1024 23 22 #define READLEN 128
+2
tools/perf/tests/dso-data.c
··· 1 + #include <dirent.h> 1 2 #include <stdlib.h> 3 + #include <linux/kernel.h> 2 4 #include <linux/types.h> 3 5 #include <sys/stat.h> 4 6 #include <fcntl.h>
+1
tools/perf/tests/dwarf-unwind.c
··· 1 1 #include <linux/compiler.h> 2 2 #include <linux/types.h> 3 + #include <inttypes.h> 3 4 #include <unistd.h> 4 5 #include "tests.h" 5 6 #include "debug.h"
+3
tools/perf/tests/event-times.c
··· 1 1 #include <linux/compiler.h> 2 + #include <errno.h> 3 + #include <inttypes.h> 2 4 #include <string.h> 5 + #include <sys/wait.h> 3 6 #include "tests.h" 4 7 #include "evlist.h" 5 8 #include "evsel.h"
+2
tools/perf/tests/evsel-roundtrip-name.c
··· 3 3 #include "parse-events.h" 4 4 #include "tests.h" 5 5 #include "debug.h" 6 + #include <errno.h> 7 + #include <linux/kernel.h> 6 8 7 9 static int perf_evsel__roundtrip_cache_name_test(void) 8 10 {
+2
tools/perf/tests/hists_common.c
··· 1 + #include <inttypes.h> 1 2 #include "perf.h" 2 3 #include "util/debug.h" 3 4 #include "util/symbol.h" ··· 8 7 #include "util/machine.h" 9 8 #include "util/thread.h" 10 9 #include "tests/hists_common.h" 10 + #include <linux/kernel.h> 11 11 12 12 static struct { 13 13 u32 pid;
+1
tools/perf/tests/hists_cumulate.c
··· 9 9 #include "util/parse-events.h" 10 10 #include "tests/tests.h" 11 11 #include "tests/hists_common.h" 12 + #include <linux/kernel.h> 12 13 13 14 struct sample { 14 15 u32 pid;
+1
tools/perf/tests/hists_filter.c
··· 9 9 #include "util/parse-events.h" 10 10 #include "tests/tests.h" 11 11 #include "tests/hists_common.h" 12 + #include <linux/kernel.h> 12 13 13 14 struct sample { 14 15 u32 pid;
+2
tools/perf/tests/hists_link.c
··· 9 9 #include "thread.h" 10 10 #include "parse-events.h" 11 11 #include "hists_common.h" 12 + #include <errno.h> 13 + #include <linux/kernel.h> 12 14 13 15 struct sample { 14 16 u32 pid;
+1
tools/perf/tests/hists_output.c
··· 9 9 #include "util/parse-events.h" 10 10 #include "tests/tests.h" 11 11 #include "tests/hists_common.h" 12 + #include <linux/kernel.h> 12 13 13 14 struct sample { 14 15 u32 cpu;
+2 -1
tools/perf/tests/is_printable_array.c
··· 1 1 #include <linux/compiler.h> 2 + #include <linux/kernel.h> 2 3 #include "tests.h" 3 4 #include "debug.h" 4 - #include "util.h" 5 + #include "print_binary.h" 5 6 6 7 int test__is_printable_array(int subtest __maybe_unused) 7 8 {
+3
tools/perf/tests/mmap-basic.c
··· 1 + #include <errno.h> 2 + #include <inttypes.h> 1 3 /* For the CLR_() macros */ 2 4 #include <pthread.h> 3 5 ··· 9 7 #include "cpumap.h" 10 8 #include "tests.h" 11 9 #include <linux/err.h> 10 + #include <linux/kernel.h> 12 11 13 12 /* 14 13 * This test will generate random numbers of calls to some getpid syscalls,
+2
tools/perf/tests/mmap-thread-lookup.c
··· 1 + #include <inttypes.h> 1 2 #include <unistd.h> 2 3 #include <sys/syscall.h> 3 4 #include <sys/types.h> ··· 12 11 #include "thread_map.h" 13 12 #include "symbol.h" 14 13 #include "thread.h" 14 + #include "util.h" 15 15 16 16 #define THREADS 4 17 17
+6
tools/perf/tests/openat-syscall-all-cpus.c
··· 1 + #include <errno.h> 2 + #include <inttypes.h> 1 3 /* For the CPU_* macros */ 2 4 #include <pthread.h> 3 5 6 + #include <sys/types.h> 7 + #include <sys/stat.h> 8 + #include <fcntl.h> 4 9 #include <api/fs/fs.h> 5 10 #include <linux/err.h> 11 + #include <api/fs/tracing_path.h> 6 12 #include "evsel.h" 7 13 #include "tests.h" 8 14 #include "thread_map.h"
+1
tools/perf/tests/openat-syscall-tp-fields.c
··· 5 5 #include "thread_map.h" 6 6 #include "tests.h" 7 7 #include "debug.h" 8 + #include <errno.h> 8 9 9 10 #ifndef O_DIRECTORY 10 11 #define O_DIRECTORY 00200000
+5
tools/perf/tests/openat-syscall.c
··· 1 + #include <errno.h> 2 + #include <inttypes.h> 1 3 #include <api/fs/tracing_path.h> 2 4 #include <linux/err.h> 5 + #include <sys/types.h> 6 + #include <sys/stat.h> 7 + #include <fcntl.h> 3 8 #include "thread_map.h" 4 9 #include "evsel.h" 5 10 #include "debug.h"
+7 -1
tools/perf/tests/parse-events.c
··· 1 - 2 1 #include "parse-events.h" 3 2 #include "evsel.h" 4 3 #include "evlist.h" ··· 5 6 #include "tests.h" 6 7 #include "debug.h" 7 8 #include "util.h" 9 + #include <dirent.h> 10 + #include <errno.h> 11 + #include <sys/types.h> 12 + #include <sys/stat.h> 13 + #include <unistd.h> 14 + #include <linux/kernel.h> 8 15 #include <linux/hw_breakpoint.h> 9 16 #include <api/fs/fs.h> 17 + #include <api/fs/tracing_path.h> 10 18 11 19 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \ 12 20 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
+1
tools/perf/tests/parse-no-sample-id-all.c
··· 1 + #include <linux/kernel.h> 1 2 #include <linux/types.h> 2 3 #include <stddef.h> 3 4
+2
tools/perf/tests/perf-record.c
··· 1 + #include <errno.h> 2 + #include <inttypes.h> 1 3 /* For the CLR_() macros */ 2 4 #include <pthread.h> 3 5
+2
tools/perf/tests/pmu.c
··· 2 2 #include "pmu.h" 3 3 #include "util.h" 4 4 #include "tests.h" 5 + #include <errno.h> 6 + #include <linux/kernel.h> 5 7 6 8 /* Simulated format definitions. */ 7 9 static struct test_format {
+2
tools/perf/tests/sample-parsing.c
··· 1 1 #include <stdbool.h> 2 + #include <inttypes.h> 3 + #include <linux/kernel.h> 2 4 #include <linux/types.h> 3 5 4 6 #include "util.h"
+1
tools/perf/tests/sdt.c
··· 1 + #include <errno.h> 1 2 #include <stdio.h> 2 3 #include <sys/epoll.h> 3 4 #include <util/util.h>
+2
tools/perf/tests/sw-clock.c
··· 1 + #include <errno.h> 2 + #include <inttypes.h> 1 3 #include <unistd.h> 2 4 #include <stdlib.h> 3 5 #include <signal.h>
+1
tools/perf/tests/switch-tracking.c
··· 1 1 #include <sys/time.h> 2 2 #include <sys/prctl.h> 3 + #include <errno.h> 3 4 #include <time.h> 4 5 #include <stdlib.h> 5 6
+1
tools/perf/tests/task-exit.c
··· 4 4 #include "cpumap.h" 5 5 #include "tests.h" 6 6 7 + #include <errno.h> 7 8 #include <signal.h> 8 9 9 10 static int exited;
+2 -1
tools/perf/tests/unit_number__scnprintf.c
··· 1 + #include <inttypes.h> 1 2 #include <linux/compiler.h> 2 3 #include <linux/types.h> 3 4 #include "tests.h" 4 - #include "util.h" 5 + #include "units.h" 5 6 #include "debug.h" 6 7 7 8 int test__unit_number__scnprint(int subtest __maybe_unused)
+1
tools/perf/tests/vmlinux-kallsyms.c
··· 1 1 #include <linux/compiler.h> 2 2 #include <linux/rbtree.h> 3 + #include <inttypes.h> 3 4 #include <string.h> 4 5 #include "map.h" 5 6 #include "symbol.h"
+1
tools/perf/trace/beauty/signum.c
··· 1 + #include <signal.h> 1 2 2 3 static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscall_arg *arg) 3 4 {
+2
tools/perf/ui/browser.c
··· 1 1 #include "../util.h" 2 + #include "../string2.h" 2 3 #include "../config.h" 3 4 #include "../../perf.h" 4 5 #include "libslang.h" ··· 14 13 #include "helpline.h" 15 14 #include "keysyms.h" 16 15 #include "../color.h" 16 + #include "sane_ctype.h" 17 17 18 18 static int ui_browser__percent_color(struct ui_browser *browser, 19 19 double percent, bool current)
+3
tools/perf/ui/browsers/annotate.c
··· 9 9 #include "../../util/symbol.h" 10 10 #include "../../util/evsel.h" 11 11 #include "../../util/config.h" 12 + #include <inttypes.h> 12 13 #include <pthread.h> 14 + #include <linux/kernel.h> 15 + #include <sys/ttydefaults.h> 13 16 14 17 struct disasm_line_samples { 15 18 double percent;
+2
tools/perf/ui/browsers/header.c
··· 8 8 #include "util/header.h" 9 9 #include "util/session.h" 10 10 11 + #include <sys/ttydefaults.h> 12 + 11 13 static void ui_browser__argv_write(struct ui_browser *browser, 12 14 void *entry, int row) 13 15 {
+10
tools/perf/ui/browsers/hists.c
··· 1 + #include <dirent.h> 2 + #include <errno.h> 3 + #include <inttypes.h> 1 4 #include <stdio.h> 2 5 #include <stdlib.h> 3 6 #include <string.h> 4 7 #include <linux/rbtree.h> 8 + #include <sys/ttydefaults.h> 5 9 6 10 #include "../../util/evsel.h" 7 11 #include "../../util/evlist.h" ··· 14 10 #include "../../util/sort.h" 15 11 #include "../../util/util.h" 16 12 #include "../../util/top.h" 13 + #include "../../util/thread.h" 17 14 #include "../../arch/common.h" 18 15 19 16 #include "../browsers/hists.h" ··· 23 18 #include "../ui.h" 24 19 #include "map.h" 25 20 #include "annotate.h" 21 + #include "srcline.h" 22 + #include "string2.h" 23 + #include "units.h" 24 + 25 + #include "sane_ctype.h" 26 26 27 27 extern void hist_browser__init_hpp(void); 28 28
+2
tools/perf/ui/browsers/map.c
··· 11 11 #include "../keysyms.h" 12 12 #include "map.h" 13 13 14 + #include "sane_ctype.h" 15 + 14 16 struct map_browser { 15 17 struct ui_browser b; 16 18 struct map *map;
+2 -1
tools/perf/ui/gtk/annotate.c
··· 3 3 #include "util/annotate.h" 4 4 #include "util/evsel.h" 5 5 #include "ui/helpline.h" 6 - 6 + #include <inttypes.h> 7 + #include <signal.h> 7 8 8 9 enum { 9 10 ANN_COL__PERCENT,
+2
tools/perf/ui/gtk/hists.c
··· 4 4 #include "../sort.h" 5 5 #include "../hist.h" 6 6 #include "../helpline.h" 7 + #include "../string2.h" 7 8 #include "gtk.h" 9 + #include <signal.h> 8 10 9 11 #define MAX_COLUMNS 32 10 12
+1
tools/perf/ui/hist.c
··· 1 + #include <inttypes.h> 1 2 #include <math.h> 2 3 #include <linux/compiler.h> 3 4
+1
tools/perf/ui/setup.c
··· 4 4 #include "../util/cache.h" 5 5 #include "../util/debug.h" 6 6 #include "../util/hist.h" 7 + #include "../util/util.h" 7 8 8 9 pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER; 9 10 void *perf_gtk_handle;
+4 -1
tools/perf/ui/stdio/hist.c
··· 4 4 #include "../../util/hist.h" 5 5 #include "../../util/sort.h" 6 6 #include "../../util/evsel.h" 7 - 7 + #include "../../util/srcline.h" 8 + #include "../../util/string2.h" 9 + #include "../../util/thread.h" 10 + #include "../../util/sane_ctype.h" 8 11 9 12 static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) 10 13 {
+1
tools/perf/ui/tui/setup.c
··· 1 1 #include <errno.h> 2 2 #include <signal.h> 3 3 #include <stdbool.h> 4 + #include <linux/kernel.h> 4 5 #ifdef HAVE_BACKTRACE_SUPPORT 5 6 #include <execinfo.h> 6 7 #endif
+2
tools/perf/util/Build
··· 16 16 libperf-y += parse-events.o 17 17 libperf-y += perf_regs.o 18 18 libperf-y += path.o 19 + libperf-y += print_binary.o 19 20 libperf-y += rbtree.o 20 21 libperf-y += libstring.o 21 22 libperf-y += bitmap.o ··· 89 88 libperf-y += mem-events.o 90 89 libperf-y += vsprintf.o 91 90 libperf-y += drv_configs.o 91 + libperf-y += units.o 92 92 libperf-y += time-utils.o 93 93 libperf-y += expr-bison.o 94 94
+6
tools/perf/util/annotate.c
··· 7 7 * Released under the GPL v2. (and only v2, not any later version) 8 8 */ 9 9 10 + #include <errno.h> 11 + #include <inttypes.h> 10 12 #include "util.h" 11 13 #include "ui/ui.h" 12 14 #include "sort.h" ··· 20 18 #include "annotate.h" 21 19 #include "evsel.h" 22 20 #include "block-range.h" 21 + #include "string2.h" 23 22 #include "arch/common.h" 24 23 #include <regex.h> 25 24 #include <pthread.h> 26 25 #include <linux/bitops.h> 26 + #include <linux/kernel.h> 27 27 #include <sys/utsname.h> 28 + 29 + #include "sane_ctype.h" 28 30 29 31 const char *disassembler_style; 30 32 const char *objdump_path;
+4 -2
tools/perf/util/auxtrace.c
··· 13 13 * 14 14 */ 15 15 16 + #include <inttypes.h> 16 17 #include <sys/types.h> 17 18 #include <sys/mman.h> 18 19 #include <stdbool.h> 19 - #include <ctype.h> 20 20 #include <string.h> 21 21 #include <limits.h> 22 22 #include <errno.h> ··· 46 46 #include "cpumap.h" 47 47 #include "thread_map.h" 48 48 #include "asm/bug.h" 49 - #include "symbol/kallsyms.h" 50 49 #include "auxtrace.h" 51 50 52 51 #include <linux/hash.h> ··· 57 58 58 59 #include "intel-pt.h" 59 60 #include "intel-bts.h" 61 + 62 + #include "sane_ctype.h" 63 + #include "symbol/kallsyms.h" 60 64 61 65 int auxtrace_mmap__mmap(struct auxtrace_mmap *mm, 62 66 struct auxtrace_mmap_params *mp,
+1
tools/perf/util/auxtrace.h
··· 17 17 #define __PERF_AUXTRACE_H 18 18 19 19 #include <sys/types.h> 20 + #include <errno.h> 20 21 #include <stdbool.h> 21 22 #include <stddef.h> 22 23 #include <linux/list.h>
+3
tools/perf/util/bpf-loader.c
··· 9 9 #include <bpf/libbpf.h> 10 10 #include <bpf/bpf.h> 11 11 #include <linux/err.h> 12 + #include <linux/kernel.h> 12 13 #include <linux/string.h> 14 + #include <errno.h> 13 15 #include "perf.h" 14 16 #include "debug.h" 15 17 #include "bpf-loader.h" ··· 19 17 #include "probe-event.h" 20 18 #include "probe-finder.h" // for MAX_PROBES 21 19 #include "parse-events.h" 20 + #include "strfilter.h" 22 21 #include "llvm-utils.h" 23 22 #include "c++/clang-c.h" 24 23
+2
tools/perf/util/bpf-loader.h
··· 85 85 char *buf, size_t size); 86 86 87 87 #else 88 + #include <errno.h> 89 + 88 90 static inline struct bpf_object * 89 91 bpf__prepare_load(const char *filename __maybe_unused, 90 92 bool source __maybe_unused)
+1
tools/perf/util/bpf-prologue.c
··· 12 12 #include "bpf-loader.h" 13 13 #include "bpf-prologue.h" 14 14 #include "probe-finder.h" 15 + #include <errno.h> 15 16 #include <dwarf-regs.h> 16 17 #include <linux/filter.h> 17 18
+2
tools/perf/util/bpf-prologue.h
··· 18 18 struct bpf_insn *new_prog, size_t *new_cnt, 19 19 size_t cnt_space); 20 20 #else 21 + #include <errno.h> 22 + 21 23 static inline int 22 24 bpf__gen_prologue(struct probe_trace_arg *args __maybe_unused, 23 25 int nargs __maybe_unused,
+10 -2
tools/perf/util/build-id.c
··· 7 7 * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <acme@redhat.com> 8 8 */ 9 9 #include "util.h" 10 + #include <dirent.h> 11 + #include <errno.h> 10 12 #include <stdio.h> 13 + #include <sys/stat.h> 14 + #include <sys/types.h> 11 15 #include "build-id.h" 12 16 #include "event.h" 13 17 #include "symbol.h" 18 + #include "thread.h" 14 19 #include <linux/kernel.h> 15 20 #include "debug.h" 16 21 #include "session.h" 17 22 #include "tool.h" 18 23 #include "header.h" 19 24 #include "vdso.h" 25 + #include "path.h" 20 26 #include "probe-file.h" 27 + #include "strlist.h" 21 28 29 + #include "sane_ctype.h" 22 30 23 31 static bool no_buildid_cache; 24 32 ··· 455 447 } 456 448 457 449 static bool lsdir_bid_head_filter(const char *name __maybe_unused, 458 - struct dirent *d __maybe_unused) 450 + struct dirent *d) 459 451 { 460 452 return (strlen(d->d_name) == 2) && 461 453 isxdigit(d->d_name[0]) && isxdigit(d->d_name[1]); 462 454 } 463 455 464 456 static bool lsdir_bid_tail_filter(const char *name __maybe_unused, 465 - struct dirent *d __maybe_unused) 457 + struct dirent *d) 466 458 { 467 459 int i = 0; 468 460 while (isxdigit(d->d_name[i]) && i < SBUILD_ID_SIZE - 3)
+3 -1
tools/perf/util/build-id.h
··· 5 5 #define SBUILD_ID_SIZE (BUILD_ID_SIZE * 2 + 1) 6 6 7 7 #include "tool.h" 8 - #include "strlist.h" 9 8 #include <linux/types.h> 10 9 11 10 extern struct perf_tool build_id__mark_dso_hit_ops; ··· 33 34 char *build_id_cache__linkname(const char *sbuild_id, char *bf, size_t size); 34 35 char *build_id_cache__cachedir(const char *sbuild_id, const char *name, 35 36 bool is_kallsyms, bool is_vdso); 37 + 38 + struct strlist; 39 + 36 40 struct strlist *build_id_cache__list_all(bool validonly); 37 41 char *build_id_cache__complement(const char *incomplete_sbuild_id); 38 42 int build_id_cache__list_build_ids(const char *pathname,
+1
tools/perf/util/c++/clang-c.h
··· 20 20 size_t *p_obj_buf_sz); 21 21 #else 22 22 23 + #include <errno.h> 23 24 24 25 static inline void perf_clang__init(void) { } 25 26 static inline void perf_clang__cleanup(void) { }
+104
tools/perf/util/callchain.c
··· 9 9 * 10 10 */ 11 11 12 + #include <inttypes.h> 12 13 #include <stdlib.h> 13 14 #include <stdio.h> 14 15 #include <stdbool.h> ··· 23 22 #include "sort.h" 24 23 #include "machine.h" 25 24 #include "callchain.h" 25 + 26 + #define CALLCHAIN_PARAM_DEFAULT \ 27 + .mode = CHAIN_GRAPH_ABS, \ 28 + .min_percent = 0.5, \ 29 + .order = ORDER_CALLEE, \ 30 + .key = CCKEY_FUNCTION, \ 31 + .value = CCVAL_PERCENT, \ 32 + 33 + struct callchain_param callchain_param = { 34 + CALLCHAIN_PARAM_DEFAULT 35 + }; 36 + 37 + struct callchain_param callchain_param_default = { 38 + CALLCHAIN_PARAM_DEFAULT 39 + }; 26 40 27 41 __thread struct callchain_cursor callchain_cursor; 28 42 ··· 128 112 return -1; 129 113 } 130 114 115 + static int get_stack_size(const char *str, unsigned long *_size) 116 + { 117 + char *endptr; 118 + unsigned long size; 119 + unsigned long max_size = round_down(USHRT_MAX, sizeof(u64)); 120 + 121 + size = strtoul(str, &endptr, 0); 122 + 123 + do { 124 + if (*endptr) 125 + break; 126 + 127 + size = round_up(size, sizeof(u64)); 128 + if (!size || size > max_size) 129 + break; 130 + 131 + *_size = size; 132 + return 0; 133 + 134 + } while (0); 135 + 136 + pr_err("callchain: Incorrect stack dump size (max %ld): %s\n", 137 + max_size, str); 138 + return -1; 139 + } 140 + 131 141 static int 132 142 __parse_callchain_report_opt(const char *arg, bool allow_record_opt) 133 143 { ··· 235 193 int parse_callchain_top_opt(const char *arg) 236 194 { 237 195 return __parse_callchain_report_opt(arg, true); 196 + } 197 + 198 + int parse_callchain_record(const char *arg, struct callchain_param *param) 199 + { 200 + char *tok, *name, *saveptr = NULL; 201 + char *buf; 202 + int ret = -1; 203 + 204 + /* We need buffer that we know we can write to. */ 205 + buf = malloc(strlen(arg) + 1); 206 + if (!buf) 207 + return -ENOMEM; 208 + 209 + strcpy(buf, arg); 210 + 211 + tok = strtok_r((char *)buf, ",", &saveptr); 212 + name = tok ? : (char *)buf; 213 + 214 + do { 215 + /* Framepointer style */ 216 + if (!strncmp(name, "fp", sizeof("fp"))) { 217 + if (!strtok_r(NULL, ",", &saveptr)) { 218 + param->record_mode = CALLCHAIN_FP; 219 + ret = 0; 220 + } else 221 + pr_err("callchain: No more arguments " 222 + "needed for --call-graph fp\n"); 223 + break; 224 + 225 + /* Dwarf style */ 226 + } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) { 227 + const unsigned long default_stack_dump_size = 8192; 228 + 229 + ret = 0; 230 + param->record_mode = CALLCHAIN_DWARF; 231 + param->dump_size = default_stack_dump_size; 232 + 233 + tok = strtok_r(NULL, ",", &saveptr); 234 + if (tok) { 235 + unsigned long size = 0; 236 + 237 + ret = get_stack_size(tok, &size); 238 + param->dump_size = size; 239 + } 240 + } else if (!strncmp(name, "lbr", sizeof("lbr"))) { 241 + if (!strtok_r(NULL, ",", &saveptr)) { 242 + param->record_mode = CALLCHAIN_LBR; 243 + ret = 0; 244 + } else 245 + pr_err("callchain: No more arguments " 246 + "needed for --call-graph lbr\n"); 247 + break; 248 + } else { 249 + pr_err("callchain: Unknown --call-graph option " 250 + "value: %s\n", arg); 251 + break; 252 + } 253 + 254 + } while (0); 255 + 256 + free(buf); 257 + return ret; 238 258 } 239 259 240 260 int perf_callchain_config(const char *var, const char *value)
+3 -2
tools/perf/util/cgroup.c
··· 4 4 #include "evsel.h" 5 5 #include "cgroup.h" 6 6 #include "evlist.h" 7 + #include <linux/stringify.h> 7 8 8 9 int nr_cgroups; 9 10 ··· 28 27 path_v1[0] = '\0'; 29 28 path_v2[0] = '\0'; 30 29 31 - while (fscanf(fp, "%*s %"STR(PATH_MAX)"s %"STR(PATH_MAX)"s %" 32 - STR(PATH_MAX)"s %*d %*d\n", 30 + while (fscanf(fp, "%*s %"__stringify(PATH_MAX)"s %"__stringify(PATH_MAX)"s %" 31 + __stringify(PATH_MAX)"s %*d %*d\n", 33 32 mountpoint, type, tokens) == 3) { 34 33 35 34 if (!path_v1[0] && !strcmp(type, "cgroup")) {
+1
tools/perf/util/cloexec.c
··· 1 + #include <errno.h> 1 2 #include <sched.h> 2 3 #include "util.h" 3 4 #include "../perf.h"
+2
tools/perf/util/color.h
··· 1 1 #ifndef __PERF_COLOR_H 2 2 #define __PERF_COLOR_H 3 3 4 + #include <stdio.h> 5 + 4 6 /* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */ 5 7 #define COLOR_MAXLEN 24 6 8
+2
tools/perf/util/comm.c
··· 1 1 #include "comm.h" 2 2 #include "util.h" 3 + #include <errno.h> 3 4 #include <stdlib.h> 4 5 #include <stdio.h> 6 + #include <string.h> 5 7 #include <linux/refcount.h> 6 8 7 9 struct comm_str {
+12
tools/perf/util/compress.h
··· 1 + #ifndef PERF_COMPRESS_H 2 + #define PERF_COMPRESS_H 3 + 4 + #ifdef HAVE_ZLIB_SUPPORT 5 + int gzip_decompress_to_file(const char *input, int output_fd); 6 + #endif 7 + 8 + #ifdef HAVE_LZMA_SUPPORT 9 + int lzma_decompress_to_file(const char *input, int output_fd); 10 + #endif 11 + 12 + #endif /* PERF_COMPRESS_H */
+7
tools/perf/util/config.c
··· 8 8 * Copyright (C) Johannes Schindelin, 2005 9 9 * 10 10 */ 11 + #include <errno.h> 12 + #include <sys/param.h> 11 13 #include "util.h" 12 14 #include "cache.h" 13 15 #include <subcmd/exec-cmd.h> 14 16 #include "util/hist.h" /* perf_hist_config */ 15 17 #include "util/llvm-utils.h" /* perf_llvm_config */ 16 18 #include "config.h" 19 + #include <sys/types.h> 20 + #include <sys/stat.h> 21 + #include <unistd.h> 22 + 23 + #include "sane_ctype.h" 17 24 18 25 #define MAXNAME (256) 19 26
+2
tools/perf/util/counts.c
··· 1 + #include <errno.h> 1 2 #include <stdlib.h> 2 3 #include "evsel.h" 3 4 #include "counts.h" 5 + #include "util.h" 4 6 5 7 struct perf_counts *perf_counts__new(int ncpus, int nthreads) 6 8 {
+3
tools/perf/util/cpumap.c
··· 3 3 #include "../perf.h" 4 4 #include "cpumap.h" 5 5 #include <assert.h> 6 + #include <dirent.h> 6 7 #include <stdio.h> 7 8 #include <stdlib.h> 8 9 #include <linux/bitmap.h> 9 10 #include "asm/bug.h" 11 + 12 + #include "sane_ctype.h" 10 13 11 14 static int max_cpu_num; 12 15 static int max_present_cpu_num;
+1 -1
tools/perf/util/ctype.c
··· 3 3 * 4 4 * No surprises, and works with signed and unsigned chars. 5 5 */ 6 - #include "util.h" 6 + #include "sane_ctype.h" 7 7 8 8 enum { 9 9 S = GIT_SPACE,
+4
tools/perf/util/data-convert-bt.c
··· 7 7 * Released under the GPL v2. (and only v2, not any later version) 8 8 */ 9 9 10 + #include <errno.h> 11 + #include <inttypes.h> 10 12 #include <linux/compiler.h> 13 + #include <linux/kernel.h> 11 14 #include <babeltrace/ctf-writer/writer.h> 12 15 #include <babeltrace/ctf-writer/clock.h> 13 16 #include <babeltrace/ctf-writer/stream.h> ··· 30 27 #include "evsel.h" 31 28 #include "machine.h" 32 29 #include "config.h" 30 + #include "sane_ctype.h" 33 31 34 32 #define pr_N(n, fmt, ...) \ 35 33 eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__)
+1
tools/perf/util/data.c
··· 2 2 #include <linux/kernel.h> 3 3 #include <sys/types.h> 4 4 #include <sys/stat.h> 5 + #include <errno.h> 5 6 #include <unistd.h> 6 7 #include <string.h> 7 8
+36 -1
tools/perf/util/debug.c
··· 2 2 3 3 #include "../perf.h" 4 4 5 + #include <inttypes.h> 5 6 #include <string.h> 6 7 #include <stdarg.h> 7 8 #include <stdio.h> 9 + #include <sys/wait.h> 8 10 #include <api/debug.h> 9 11 #include <linux/time64.h> 10 - 12 + #ifdef HAVE_BACKTRACE_SUPPORT 13 + #include <execinfo.h> 14 + #endif 11 15 #include "cache.h" 12 16 #include "color.h" 13 17 #include "event.h" 14 18 #include "debug.h" 19 + #include "print_binary.h" 15 20 #include "util.h" 16 21 #include "target.h" 22 + 23 + #include "sane_ctype.h" 17 24 18 25 int verbose; 19 26 bool dump_trace = false, quiet = false; ··· 250 243 void perf_debug_setup(void) 251 244 { 252 245 libapi_set_print(pr_warning_wrapper, pr_warning_wrapper, pr_debug_wrapper); 246 + } 247 + 248 + /* Obtain a backtrace and print it to stdout. */ 249 + #ifdef HAVE_BACKTRACE_SUPPORT 250 + void dump_stack(void) 251 + { 252 + void *array[16]; 253 + size_t size = backtrace(array, ARRAY_SIZE(array)); 254 + char **strings = backtrace_symbols(array, size); 255 + size_t i; 256 + 257 + printf("Obtained %zd stack frames.\n", size); 258 + 259 + for (i = 0; i < size; i++) 260 + printf("%s\n", strings[i]); 261 + 262 + free(strings); 263 + } 264 + #else 265 + void dump_stack(void) {} 266 + #endif 267 + 268 + void sighandler_dump_stack(int sig) 269 + { 270 + psignal(sig, "perf"); 271 + dump_stack(); 272 + signal(sig, SIG_DFL); 273 + raise(sig); 253 274 }
+3
tools/perf/util/debug.h
··· 56 56 void perf_debug_setup(void); 57 57 int perf_quiet_option(void); 58 58 59 + void dump_stack(void); 60 + void sighandler_dump_stack(int sig); 61 + 59 62 #endif /* __PERF_DEBUG_H */
+2
tools/perf/util/demangle-java.c
··· 7 7 8 8 #include "demangle-java.h" 9 9 10 + #include "sane_ctype.h" 11 + 10 12 enum { 11 13 MODE_PREFIX = 0, 12 14 MODE_CLASS = 1,
+1
tools/perf/util/drv_configs.c
··· 17 17 #include "evlist.h" 18 18 #include "evsel.h" 19 19 #include "pmu.h" 20 + #include <errno.h> 20 21 21 22 static int 22 23 perf_evsel__apply_drv_configs(struct perf_evsel *evsel,
+8
tools/perf/util/dso.c
··· 1 1 #include <asm/bug.h> 2 + #include <linux/kernel.h> 2 3 #include <sys/time.h> 3 4 #include <sys/resource.h> 5 + #include <sys/types.h> 6 + #include <sys/stat.h> 7 + #include <unistd.h> 8 + #include <errno.h> 9 + #include "compress.h" 10 + #include "path.h" 4 11 #include "symbol.h" 5 12 #include "dso.h" 6 13 #include "machine.h" 7 14 #include "auxtrace.h" 8 15 #include "util.h" 9 16 #include "debug.h" 17 + #include "string2.h" 10 18 #include "vdso.h" 11 19 12 20 static const char * const debuglink_paths[] = {
+3
tools/perf/util/dwarf-aux.c
··· 17 17 * 18 18 */ 19 19 20 + #include <errno.h> 21 + #include <inttypes.h> 20 22 #include <stdbool.h> 21 23 #include "util.h" 22 24 #include "debug.h" 23 25 #include "dwarf-aux.h" 26 + #include "string2.h" 24 27 25 28 /** 26 29 * cu_find_realpath - Find the realpath of the target file
+1
tools/perf/util/dwarf-regs.c
··· 8 8 #include <debug.h> 9 9 #include <dwarf-regs.h> 10 10 #include <elf.h> 11 + #include <linux/kernel.h> 11 12 12 13 #ifndef EM_AARCH64 13 14 #define EM_AARCH64 183 /* ARM 64 bit */
+1
tools/perf/util/env.c
··· 1 1 #include "cpumap.h" 2 2 #include "env.h" 3 3 #include "util.h" 4 + #include <errno.h> 4 5 5 6 struct perf_env perf_env; 6 7
+17 -2
tools/perf/util/event.c
··· 1 + #include <dirent.h> 2 + #include <errno.h> 3 + #include <inttypes.h> 4 + #include <linux/kernel.h> 1 5 #include <linux/types.h> 6 + #include <sys/types.h> 7 + #include <sys/stat.h> 8 + #include <unistd.h> 2 9 #include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */ 3 10 #include <api/fs/fs.h> 4 11 #include "event.h" ··· 13 6 #include "hist.h" 14 7 #include "machine.h" 15 8 #include "sort.h" 16 - #include "string.h" 9 + #include "string2.h" 17 10 #include "strlist.h" 18 11 #include "thread.h" 19 12 #include "thread_map.h" 13 + #include "sane_ctype.h" 20 14 #include "symbol/kallsyms.h" 21 15 #include "asm/bug.h" 22 16 #include "stat.h" ··· 141 133 ppids = strstr(bf, "PPid:"); 142 134 143 135 if (name) { 136 + char *nl; 137 + 144 138 name += 5; /* strlen("Name:") */ 145 - name = rtrim(ltrim(name)); 139 + name = ltrim(name); 140 + 141 + nl = strchr(name, '\n'); 142 + if (nl) 143 + *nl = '\0'; 144 + 146 145 size = strlen(name); 147 146 if (size >= len) 148 147 size = len - 1;
+1 -1
tools/perf/util/event.h
··· 3 3 4 4 #include <limits.h> 5 5 #include <stdio.h> 6 + #include <linux/kernel.h> 6 7 7 8 #include "../perf.h" 8 - #include "map.h" 9 9 #include "build-id.h" 10 10 #include "perf_regs.h" 11 11
+5
tools/perf/util/evlist.c
··· 8 8 */ 9 9 #include "util.h" 10 10 #include <api/fs/fs.h> 11 + #include <errno.h> 12 + #include <inttypes.h> 11 13 #include <poll.h> 12 14 #include "cpumap.h" 13 15 #include "thread_map.h" ··· 17 15 #include "evlist.h" 18 16 #include "evsel.h" 19 17 #include "debug.h" 18 + #include "units.h" 20 19 #include "asm/bug.h" 20 + #include <signal.h> 21 21 #include <unistd.h> 22 22 23 23 #include "parse-events.h" 24 24 #include <subcmd/parse-options.h> 25 25 26 + #include <sys/ioctl.h> 26 27 #include <sys/mman.h> 27 28 28 29 #include <linux/bitops.h>
+2
tools/perf/util/evlist.h
··· 1 1 #ifndef __PERF_EVLIST_H 2 2 #define __PERF_EVLIST_H 1 3 3 4 + #include <linux/kernel.h> 4 5 #include <linux/refcount.h> 5 6 #include <linux/list.h> 6 7 #include <api/fd/array.h> ··· 11 10 #include "evsel.h" 12 11 #include "util.h" 13 12 #include "auxtrace.h" 13 + #include <signal.h> 14 14 #include <unistd.h> 15 15 16 16 struct pollfd;
+5
tools/perf/util/evsel.c
··· 8 8 */ 9 9 10 10 #include <byteswap.h> 11 + #include <errno.h> 12 + #include <inttypes.h> 11 13 #include <linux/bitops.h> 12 14 #include <api/fs/tracing_path.h> 13 15 #include <traceevent/event-parse.h> 14 16 #include <linux/hw_breakpoint.h> 15 17 #include <linux/perf_event.h> 16 18 #include <linux/err.h> 19 + #include <sys/ioctl.h> 17 20 #include <sys/resource.h> 18 21 #include "asm/bug.h" 19 22 #include "callchain.h" ··· 32 29 #include "trace-event.h" 33 30 #include "stat.h" 34 31 #include "util/parse-branch-options.h" 32 + 33 + #include "sane_ctype.h" 35 34 36 35 static struct { 37 36 bool sample_id_all;
+2
tools/perf/util/evsel_fprintf.c
··· 1 + #include <inttypes.h> 1 2 #include <stdio.h> 2 3 #include <stdbool.h> 3 4 #include <traceevent/event-parse.h> 4 5 #include "evsel.h" 5 6 #include "callchain.h" 6 7 #include "map.h" 8 + #include "strlist.h" 7 9 #include "symbol.h" 8 10 9 11 static int comma_fprintf(FILE *fp, bool *first, const char *fmt, ...)
+9
tools/perf/util/header.c
··· 1 + #include <errno.h> 2 + #include <inttypes.h> 1 3 #include "util.h" 4 + #include "string2.h" 5 + #include <sys/param.h> 2 6 #include <sys/types.h> 3 7 #include <byteswap.h> 4 8 #include <unistd.h> ··· 11 7 #include <linux/list.h> 12 8 #include <linux/kernel.h> 13 9 #include <linux/bitops.h> 10 + #include <sys/stat.h> 11 + #include <sys/types.h> 14 12 #include <sys/utsname.h> 13 + #include <unistd.h> 15 14 16 15 #include "evlist.h" 17 16 #include "evsel.h" ··· 32 25 #include "data.h" 33 26 #include <api/fs/fs.h> 34 27 #include "asm/bug.h" 28 + 29 + #include "sane_ctype.h" 35 30 36 31 /* 37 32 * magic2 = "PERFILE2"
+1
tools/perf/util/help-unknown-cmd.c
··· 1 1 #include "cache.h" 2 2 #include "config.h" 3 + #include <poll.h> 3 4 #include <stdio.h> 4 5 #include <subcmd/help.h> 5 6 #include "../builtin.h"
+4
tools/perf/util/hist.c
··· 8 8 #include "evlist.h" 9 9 #include "evsel.h" 10 10 #include "annotate.h" 11 + #include "srcline.h" 12 + #include "thread.h" 11 13 #include "ui/progress.h" 14 + #include <errno.h> 12 15 #include <math.h> 16 + #include <sys/param.h> 13 17 14 18 static bool hists__filter_entry_by_dso(struct hists *hists, 15 19 struct hist_entry *he);
+2
tools/perf/util/intel-bts.c
··· 14 14 */ 15 15 16 16 #include <endian.h> 17 + #include <errno.h> 17 18 #include <byteswap.h> 19 + #include <inttypes.h> 18 20 #include <linux/kernel.h> 19 21 #include <linux/types.h> 20 22 #include <linux/bitops.h>
+1
tools/perf/util/intel-pt.c
··· 13 13 * 14 14 */ 15 15 16 + #include <inttypes.h> 16 17 #include <stdio.h> 17 18 #include <stdbool.h> 18 19 #include <errno.h>
+5 -2
tools/perf/util/jitdump.c
··· 1 1 #include <sys/sysmacros.h> 2 2 #include <sys/types.h> 3 + #include <errno.h> 3 4 #include <stdio.h> 4 5 #include <stdlib.h> 5 6 #include <string.h> ··· 10 9 #include <byteswap.h> 11 10 #include <sys/stat.h> 12 11 #include <sys/mman.h> 12 + #include <linux/stringify.h> 13 13 14 14 #include "util.h" 15 15 #include "event.h" 16 16 #include "debug.h" 17 17 #include "evlist.h" 18 18 #include "symbol.h" 19 - #include "strlist.h" 20 19 #include <elf.h> 21 20 22 21 #include "tsc.h" ··· 25 24 #include "jitdump.h" 26 25 #include "genelf.h" 27 26 #include "../builtin.h" 27 + 28 + #include "sane_ctype.h" 28 29 29 30 struct jit_buf_desc { 30 31 struct perf_data_file *output; ··· 184 181 jd->use_arch_timestamp); 185 182 186 183 if (header.version > JITHEADER_VERSION) { 187 - pr_err("wrong jitdump version %u, expected " STR(JITHEADER_VERSION), 184 + pr_err("wrong jitdump version %u, expected " __stringify(JITHEADER_VERSION), 188 185 header.version); 189 186 goto error; 190 187 }
+1
tools/perf/util/llvm-utils.c
··· 12 12 #include "llvm-utils.h" 13 13 #include "config.h" 14 14 #include "util.h" 15 + #include <sys/wait.h> 15 16 16 17 #define CLANG_BPF_CMD_DEFAULT_TEMPLATE \ 17 18 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
+2
tools/perf/util/lzma.c
··· 1 + #include <errno.h> 1 2 #include <lzma.h> 2 3 #include <stdio.h> 3 4 #include <linux/compiler.h> 5 + #include "compress.h" 4 6 #include "util.h" 5 7 #include "debug.h" 6 8
+10 -1
tools/perf/util/machine.c
··· 1 + #include <dirent.h> 2 + #include <errno.h> 3 + #include <inttypes.h> 4 + #include <regex.h> 1 5 #include "callchain.h" 2 6 #include "debug.h" 3 7 #include "event.h" ··· 14 10 #include "thread.h" 15 11 #include "vdso.h" 16 12 #include <stdbool.h> 17 - #include <symbol/kallsyms.h> 13 + #include <sys/types.h> 14 + #include <sys/stat.h> 15 + #include <unistd.h> 18 16 #include "unwind.h" 19 17 #include "linux/hash.h" 20 18 #include "asm/bug.h" 19 + 20 + #include "sane_ctype.h" 21 + #include <symbol/kallsyms.h> 21 22 22 23 static void __machine__remove_thread(struct machine *machine, struct thread *th, bool lock); 23 24
+1 -1
tools/perf/util/map.c
··· 9 9 #include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */ 10 10 #include "map.h" 11 11 #include "thread.h" 12 - #include "strlist.h" 13 12 #include "vdso.h" 14 13 #include "build-id.h" 15 14 #include "util.h" 16 15 #include "debug.h" 17 16 #include "machine.h" 18 17 #include <linux/string.h> 18 + #include "srcline.h" 19 19 #include "unwind.h" 20 20 21 21 static void __maps__insert(struct maps *maps, struct map *map);
+2 -1
tools/perf/util/mem-events.c
··· 6 6 #include <sys/stat.h> 7 7 #include <unistd.h> 8 8 #include <api/fs/fs.h> 9 + #include <linux/kernel.h> 9 10 #include "mem-events.h" 10 11 #include "debug.h" 11 12 #include "symbol.h" ··· 206 205 static const char * const snoop_access[] = { 207 206 "N/A", 208 207 "None", 209 - "Miss", 210 208 "Hit", 209 + "Miss", 211 210 "HitM", 212 211 }; 213 212
+1
tools/perf/util/namespaces.c
··· 11 11 #include "event.h" 12 12 #include <stdlib.h> 13 13 #include <stdio.h> 14 + #include <string.h> 14 15 15 16 struct namespaces *namespaces__new(struct namespaces_event *event) 16 17 {
+2
tools/perf/util/ordered-events.c
··· 1 + #include <errno.h> 2 + #include <inttypes.h> 1 3 #include <linux/list.h> 2 4 #include <linux/compiler.h> 3 5 #include <linux/string.h>
+7 -2
tools/perf/util/parse-events.c
··· 1 1 #include <linux/hw_breakpoint.h> 2 2 #include <linux/err.h> 3 - #include "util.h" 3 + #include <dirent.h> 4 + #include <errno.h> 5 + #include <sys/ioctl.h> 6 + #include <sys/param.h> 7 + #include "term.h" 4 8 #include "../perf.h" 5 9 #include "evlist.h" 6 10 #include "evsel.h" 7 11 #include <subcmd/parse-options.h> 8 12 #include "parse-events.h" 9 13 #include <subcmd/exec-cmd.h> 10 - #include "string.h" 14 + #include "string2.h" 15 + #include "strlist.h" 11 16 #include "symbol.h" 12 17 #include "cache.h" 13 18 #include "header.h"
+27 -1
tools/perf/util/path.c
··· 11 11 * which is what it's designed for. 12 12 */ 13 13 #include "cache.h" 14 - #include "util.h" 14 + #include "path.h" 15 + #include <linux/kernel.h> 15 16 #include <limits.h> 17 + #include <stdio.h> 18 + #include <sys/types.h> 19 + #include <sys/stat.h> 20 + #include <unistd.h> 16 21 17 22 static char bad_path[] = "/bad-path/"; 18 23 /* ··· 54 49 if (len >= PATH_MAX) 55 50 return bad_path; 56 51 return cleanup_path(pathname); 52 + } 53 + 54 + int path__join(char *bf, size_t size, const char *path1, const char *path2) 55 + { 56 + return scnprintf(bf, size, "%s%s%s", path1, path1[0] ? "/" : "", path2); 57 + } 58 + 59 + int path__join3(char *bf, size_t size, const char *path1, const char *path2, const char *path3) 60 + { 61 + return scnprintf(bf, size, "%s%s%s%s%s", path1, path1[0] ? "/" : "", 62 + path2, path2[0] ? "/" : "", path3); 63 + } 64 + 65 + bool is_regular_file(const char *file) 66 + { 67 + struct stat st; 68 + 69 + if (stat(file, &st)) 70 + return false; 71 + 72 + return S_ISREG(st.st_mode); 57 73 }
+9
tools/perf/util/path.h
··· 1 + #ifndef _PERF_PATH_H 2 + #define _PERF_PATH_H 3 + 4 + int path__join(char *bf, size_t size, const char *path1, const char *path2); 5 + int path__join3(char *bf, size_t size, const char *path1, const char *path2, const char *path3); 6 + 7 + bool is_regular_file(const char *file); 8 + 9 + #endif /* _PERF_PATH_H */
+1
tools/perf/util/perf-hooks.c
··· 9 9 #include <stdlib.h> 10 10 #include <setjmp.h> 11 11 #include <linux/err.h> 12 + #include <linux/kernel.h> 12 13 #include "util/util.h" 13 14 #include "util/debug.h" 14 15 #include "util/perf-hooks.h"
+3
tools/perf/util/pmu.c
··· 1 1 #include <linux/list.h> 2 2 #include <linux/compiler.h> 3 3 #include <sys/types.h> 4 + #include <errno.h> 5 + #include <sys/stat.h> 4 6 #include <unistd.h> 5 7 #include <stdio.h> 6 8 #include <stdbool.h> ··· 17 15 #include "header.h" 18 16 #include "pmu-events/pmu-events.h" 19 17 #include "cache.h" 18 + #include "string2.h" 20 19 21 20 struct perf_pmu_format { 22 21 char *name;
+55
tools/perf/util/print_binary.c
··· 1 + #include "print_binary.h" 2 + #include <linux/log2.h> 3 + #include "sane_ctype.h" 4 + 5 + void print_binary(unsigned char *data, size_t len, 6 + size_t bytes_per_line, print_binary_t printer, 7 + void *extra) 8 + { 9 + size_t i, j, mask; 10 + 11 + if (!printer) 12 + return; 13 + 14 + bytes_per_line = roundup_pow_of_two(bytes_per_line); 15 + mask = bytes_per_line - 1; 16 + 17 + printer(BINARY_PRINT_DATA_BEGIN, 0, extra); 18 + for (i = 0; i < len; i++) { 19 + if ((i & mask) == 0) { 20 + printer(BINARY_PRINT_LINE_BEGIN, -1, extra); 21 + printer(BINARY_PRINT_ADDR, i, extra); 22 + } 23 + 24 + printer(BINARY_PRINT_NUM_DATA, data[i], extra); 25 + 26 + if (((i & mask) == mask) || i == len - 1) { 27 + for (j = 0; j < mask-(i & mask); j++) 28 + printer(BINARY_PRINT_NUM_PAD, -1, extra); 29 + 30 + printer(BINARY_PRINT_SEP, i, extra); 31 + for (j = i & ~mask; j <= i; j++) 32 + printer(BINARY_PRINT_CHAR_DATA, data[j], extra); 33 + for (j = 0; j < mask-(i & mask); j++) 34 + printer(BINARY_PRINT_CHAR_PAD, i, extra); 35 + printer(BINARY_PRINT_LINE_END, -1, extra); 36 + } 37 + } 38 + printer(BINARY_PRINT_DATA_END, -1, extra); 39 + } 40 + 41 + int is_printable_array(char *p, unsigned int len) 42 + { 43 + unsigned int i; 44 + 45 + if (!p || !len || p[len - 1] != 0) 46 + return 0; 47 + 48 + len--; 49 + 50 + for (i = 0; i < len; i++) { 51 + if (!isprint(p[i]) && !isspace(p[i])) 52 + return 0; 53 + } 54 + return 1; 55 + }
+28
tools/perf/util/print_binary.h
··· 1 + #ifndef PERF_PRINT_BINARY_H 2 + #define PERF_PRINT_BINARY_H 3 + 4 + #include <stddef.h> 5 + 6 + enum binary_printer_ops { 7 + BINARY_PRINT_DATA_BEGIN, 8 + BINARY_PRINT_LINE_BEGIN, 9 + BINARY_PRINT_ADDR, 10 + BINARY_PRINT_NUM_DATA, 11 + BINARY_PRINT_NUM_PAD, 12 + BINARY_PRINT_SEP, 13 + BINARY_PRINT_CHAR_DATA, 14 + BINARY_PRINT_CHAR_PAD, 15 + BINARY_PRINT_LINE_END, 16 + BINARY_PRINT_DATA_END, 17 + }; 18 + 19 + typedef void (*print_binary_t)(enum binary_printer_ops op, 20 + unsigned int val, void *extra); 21 + 22 + void print_binary(unsigned char *data, size_t len, 23 + size_t bytes_per_line, print_binary_t printer, 24 + void *extra); 25 + 26 + int is_printable_array(char *p, unsigned int len); 27 + 28 + #endif /* PERF_PRINT_BINARY_H */
+5
tools/perf/util/probe-event.c
··· 19 19 * 20 20 */ 21 21 22 + #include <inttypes.h> 22 23 #include <sys/utsname.h> 23 24 #include <sys/types.h> 24 25 #include <sys/stat.h> ··· 36 35 #include "util.h" 37 36 #include "event.h" 38 37 #include "strlist.h" 38 + #include "strfilter.h" 39 39 #include "debug.h" 40 40 #include "cache.h" 41 41 #include "color.h" ··· 48 46 #include "probe-finder.h" 49 47 #include "probe-file.h" 50 48 #include "session.h" 49 + #include "string2.h" 50 + 51 + #include "sane_ctype.h" 51 52 52 53 #define PERFPROBE_GROUP "probe" 53 54
+5 -2
tools/perf/util/probe-event.h
··· 3 3 4 4 #include <stdbool.h> 5 5 #include "intlist.h" 6 - #include "strlist.h" 7 - #include "strfilter.h" 8 6 9 7 /* Probe related configurations */ 10 8 struct probe_conf { ··· 105 107 struct intlist *line_list; /* Visible lines */ 106 108 }; 107 109 110 + struct strlist; 111 + 108 112 /* List of variables */ 109 113 struct variable_list { 110 114 struct probe_trace_point point; /* Actual probepoint */ ··· 153 153 int apply_perf_probe_events(struct perf_probe_event *pevs, int npevs); 154 154 int show_probe_trace_events(struct perf_probe_event *pevs, int npevs); 155 155 void cleanup_perf_probe_events(struct perf_probe_event *pevs, int npevs); 156 + 157 + struct strfilter; 158 + 156 159 int del_perf_probe_events(struct strfilter *filter); 157 160 158 161 int show_perf_probe_event(const char *group, const char *event,
+6
tools/perf/util/probe-file.c
··· 14 14 * GNU General Public License for more details. 15 15 * 16 16 */ 17 + #include <errno.h> 18 + #include <sys/stat.h> 19 + #include <sys/types.h> 17 20 #include <sys/uio.h> 21 + #include <unistd.h> 18 22 #include "util.h" 19 23 #include "event.h" 20 24 #include "strlist.h" 25 + #include "strfilter.h" 21 26 #include "debug.h" 22 27 #include "cache.h" 23 28 #include "color.h" ··· 33 28 #include "probe-file.h" 34 29 #include "session.h" 35 30 #include "perf_regs.h" 31 + #include "string2.h" 36 32 37 33 /* 4096 - 2 ('\n' + '\0') */ 38 34 #define MAX_CMDLEN 4094
+4 -2
tools/perf/util/probe-file.h
··· 1 1 #ifndef __PROBE_FILE_H 2 2 #define __PROBE_FILE_H 3 3 4 - #include "strlist.h" 5 - #include "strfilter.h" 6 4 #include "probe-event.h" 5 + 6 + struct strlist; 7 + struct strfilter; 7 8 8 9 /* Cache of probe definitions */ 9 10 struct probe_cache_entry { ··· 42 41 struct strlist *probe_file__get_namelist(int fd); 43 42 struct strlist *probe_file__get_rawlist(int fd); 44 43 int probe_file__add_event(int fd, struct probe_trace_event *tev); 44 + 45 45 int probe_file__del_events(int fd, struct strfilter *filter); 46 46 int probe_file__get_events(int fd, struct strfilter *filter, 47 47 struct strlist *plist);
+3
tools/perf/util/probe-finder.c
··· 19 19 * 20 20 */ 21 21 22 + #include <inttypes.h> 22 23 #include <sys/utsname.h> 23 24 #include <sys/types.h> 24 25 #include <sys/stat.h> ··· 38 37 #include "debug.h" 39 38 #include "intlist.h" 40 39 #include "util.h" 40 + #include "strlist.h" 41 41 #include "symbol.h" 42 42 #include "probe-finder.h" 43 43 #include "probe-file.h" 44 + #include "string2.h" 44 45 45 46 /* Kprobe tracer basic type is up to u64 */ 46 47 #define MAX_BASIC_TYPE_BITS 64
+1 -1
tools/perf/util/probe-finder.h
··· 2 2 #define _PROBE_FINDER_H 3 3 4 4 #include <stdbool.h> 5 - #include "util.h" 6 5 #include "intlist.h" 7 6 #include "probe-event.h" 7 + #include "sane_ctype.h" 8 8 9 9 #define MAX_PROBE_BUFFER 1024 10 10 #define MAX_PROBES 128
+2
tools/perf/util/python-ext-sources
··· 21 21 util/parse-branch-options.c 22 22 util/rblist.c 23 23 util/counts.c 24 + util/print_binary.c 24 25 util/strlist.c 25 26 util/trace-event.c 26 27 ../lib/rbtree.c 27 28 util/string.c 28 29 util/symbol_fprintf.c 30 + util/units.c
+14
tools/perf/util/python.c
··· 4 4 #include <poll.h> 5 5 #include <linux/err.h> 6 6 #include "evlist.h" 7 + #include "callchain.h" 7 8 #include "evsel.h" 8 9 #include "event.h" 9 10 #include "cpumap.h" 11 + #include "print_binary.h" 10 12 #include "thread_map.h" 13 + 14 + /* 15 + * Provide these two so that we don't have to link against callchain.c and 16 + * start dragging hist.c, etc. 17 + */ 18 + struct callchain_param callchain_param; 19 + 20 + int parse_callchain_record(const char *arg __maybe_unused, 21 + struct callchain_param *param __maybe_unused) 22 + { 23 + return 0; 24 + } 11 25 12 26 /* 13 27 * Support debug printing even though util/debug.c is not linked. That means
+1
tools/perf/util/quote.c
··· 1 + #include <errno.h> 1 2 #include <stdlib.h> 2 3 #include "strbuf.h" 3 4 #include "quote.h"
+1
tools/perf/util/record.c
··· 2 2 #include "evsel.h" 3 3 #include "cpumap.h" 4 4 #include "parse-events.h" 5 + #include <errno.h> 5 6 #include <api/fs/fs.h> 6 7 #include "util.h" 7 8 #include "cloexec.h"
+51
tools/perf/util/sane_ctype.h
··· 1 + #ifndef _PERF_SANE_CTYPE_H 2 + #define _PERF_SANE_CTYPE_H 3 + 4 + extern const char *graph_line; 5 + extern const char *graph_dotted_line; 6 + extern const char *spaces; 7 + extern const char *dots; 8 + 9 + /* Sane ctype - no locale, and works with signed chars */ 10 + #undef isascii 11 + #undef isspace 12 + #undef isdigit 13 + #undef isxdigit 14 + #undef isalpha 15 + #undef isprint 16 + #undef isalnum 17 + #undef islower 18 + #undef isupper 19 + #undef tolower 20 + #undef toupper 21 + 22 + extern unsigned char sane_ctype[256]; 23 + #define GIT_SPACE 0x01 24 + #define GIT_DIGIT 0x02 25 + #define GIT_ALPHA 0x04 26 + #define GIT_GLOB_SPECIAL 0x08 27 + #define GIT_REGEX_SPECIAL 0x10 28 + #define GIT_PRINT_EXTRA 0x20 29 + #define GIT_PRINT 0x3E 30 + #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0) 31 + #define isascii(x) (((x) & ~0x7f) == 0) 32 + #define isspace(x) sane_istest(x,GIT_SPACE) 33 + #define isdigit(x) sane_istest(x,GIT_DIGIT) 34 + #define isxdigit(x) \ 35 + (sane_istest(toupper(x), GIT_ALPHA | GIT_DIGIT) && toupper(x) < 'G') 36 + #define isalpha(x) sane_istest(x,GIT_ALPHA) 37 + #define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) 38 + #define isprint(x) sane_istest(x,GIT_PRINT) 39 + #define islower(x) (sane_istest(x,GIT_ALPHA) && (x & 0x20)) 40 + #define isupper(x) (sane_istest(x,GIT_ALPHA) && !(x & 0x20)) 41 + #define tolower(x) sane_case((unsigned char)(x), 0x20) 42 + #define toupper(x) sane_case((unsigned char)(x), 0) 43 + 44 + static inline int sane_case(int x, int high) 45 + { 46 + if (sane_istest(x, GIT_ALPHA)) 47 + x = (x & ~0x20) | high; 48 + return x; 49 + } 50 + 51 + #endif /* _PERF_SANE_CTYPE_H */
+1
tools/perf/util/scripting-engines/trace-event-perl.c
··· 19 19 * 20 20 */ 21 21 22 + #include <inttypes.h> 22 23 #include <stdio.h> 23 24 #include <stdlib.h> 24 25 #include <string.h>
+2
tools/perf/util/scripting-engines/trace-event-python.c
··· 21 21 22 22 #include <Python.h> 23 23 24 + #include <inttypes.h> 24 25 #include <stdio.h> 25 26 #include <stdlib.h> 26 27 #include <string.h> ··· 46 45 #include "../call-path.h" 47 46 #include "thread_map.h" 48 47 #include "cpumap.h" 48 + #include "print_binary.h" 49 49 #include "stat.h" 50 50 51 51 PyMODINIT_FUNC initperf_trace_context(void);
+3
tools/perf/util/session.c
··· 1 + #include <errno.h> 2 + #include <inttypes.h> 1 3 #include <linux/kernel.h> 2 4 #include <traceevent/event-parse.h> 3 5 #include <api/fs/fs.h> ··· 19 17 #include "perf_regs.h" 20 18 #include "asm/bug.h" 21 19 #include "auxtrace.h" 20 + #include "thread.h" 22 21 #include "thread-stack.h" 23 22 #include "stat.h" 24 23
+2 -2
tools/perf/util/session.h
··· 5 5 #include "event.h" 6 6 #include "header.h" 7 7 #include "machine.h" 8 - #include "symbol.h" 9 - #include "thread.h" 10 8 #include "data.h" 11 9 #include "ordered-events.h" 10 + #include <linux/kernel.h> 12 11 #include <linux/rbtree.h> 13 12 #include <linux/perf_event.h> 14 13 15 14 struct ip_callchain; 15 + struct symbol; 16 16 struct thread; 17 17 18 18 struct auxtrace;
+6
tools/perf/util/sort.c
··· 1 + #include <errno.h> 2 + #include <inttypes.h> 3 + #include <regex.h> 1 4 #include <sys/mman.h> 2 5 #include "sort.h" 3 6 #include "hist.h" 4 7 #include "comm.h" 5 8 #include "symbol.h" 9 + #include "thread.h" 6 10 #include "evsel.h" 7 11 #include "evlist.h" 12 + #include "strlist.h" 8 13 #include <traceevent/event-parse.h> 9 14 #include "mem-events.h" 15 + #include <linux/kernel.h> 10 16 11 17 regex_t parent_regex; 12 18 const char default_parent_pattern[] = "^sys_|^do_page_fault";
+4 -3
tools/perf/util/sort.h
··· 2 2 #define __PERF_SORT_H 3 3 #include "../builtin.h" 4 4 5 - #include "util.h" 5 + #include <regex.h> 6 6 7 7 #include "color.h" 8 8 #include <linux/list.h> ··· 11 11 #include "symbol.h" 12 12 #include "string.h" 13 13 #include "callchain.h" 14 - #include "strlist.h" 15 14 #include "values.h" 16 15 17 16 #include "../perf.h" ··· 20 21 #include <subcmd/parse-options.h> 21 22 #include "parse-events.h" 22 23 #include "hist.h" 23 - #include "thread.h" 24 + #include "srcline.h" 25 + 26 + struct thread; 24 27 25 28 extern regex_t parent_regex; 26 29 extern const char *sort_order;
+2
tools/perf/util/srcline.c
··· 1 + #include <inttypes.h> 1 2 #include <stdio.h> 2 3 #include <stdlib.h> 3 4 #include <string.h> ··· 9 8 #include "util/util.h" 10 9 #include "util/debug.h" 11 10 #include "util/callchain.h" 11 + #include "srcline.h" 12 12 13 13 #include "symbol.h" 14 14
+34
tools/perf/util/srcline.h
··· 1 + #ifndef PERF_SRCLINE_H 2 + #define PERF_SRCLINE_H 3 + 4 + #include <linux/list.h> 5 + #include <linux/types.h> 6 + 7 + struct dso; 8 + struct symbol; 9 + 10 + extern bool srcline_full_filename; 11 + char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym, 12 + bool show_sym, bool show_addr); 13 + char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym, 14 + bool show_sym, bool show_addr, bool unwind_inlines); 15 + void free_srcline(char *srcline); 16 + 17 + #define SRCLINE_UNKNOWN ((char *) "??:0") 18 + 19 + struct inline_list { 20 + char *filename; 21 + char *funcname; 22 + unsigned int line_nr; 23 + struct list_head list; 24 + }; 25 + 26 + struct inline_node { 27 + u64 addr; 28 + struct list_head val; 29 + }; 30 + 31 + struct inline_node *dso__parse_addr_inlines(struct dso *dso, u64 addr); 32 + void inline_node__delete(struct inline_node *node); 33 + 34 + #endif /* PERF_SRCLINE_H */
+2
tools/perf/util/stat.c
··· 1 + #include <errno.h> 2 + #include <inttypes.h> 1 3 #include <math.h> 2 4 #include "stat.h" 3 5 #include "evlist.h"
+1
tools/perf/util/strbuf.c
··· 1 1 #include "debug.h" 2 2 #include "util.h" 3 3 #include <linux/kernel.h> 4 + #include <errno.h> 4 5 5 6 int prefixcmp(const char *str, const char *prefix) 6 7 {
+4 -1
tools/perf/util/strfilter.c
··· 1 1 #include "util.h" 2 - #include "string.h" 2 + #include "string2.h" 3 3 #include "strfilter.h" 4 + 5 + #include <errno.h> 6 + #include "sane_ctype.h" 4 7 5 8 /* Operators */ 6 9 static const char *OP_and = "&"; /* Logical AND */
+12 -6
tools/perf/util/string.c
··· 1 - #include "util.h" 2 - #include "linux/string.h" 1 + #include "string2.h" 2 + #include <linux/kernel.h> 3 + #include <linux/string.h> 4 + #include <stdlib.h> 5 + 6 + #include "sane_ctype.h" 3 7 4 8 #define K 1024LL 5 9 /* ··· 103 99 void argv_free(char **argv) 104 100 { 105 101 char **p; 106 - for (p = argv; *p; p++) 107 - zfree(p); 102 + for (p = argv; *p; p++) { 103 + free(*p); 104 + *p = NULL; 105 + } 108 106 109 107 free(argv); 110 108 } ··· 126 120 char **argv_split(const char *str, int *argcp) 127 121 { 128 122 int argc = count_argc(str); 129 - char **argv = zalloc(sizeof(*argv) * (argc+1)); 123 + char **argv = calloc(argc + 1, sizeof(*argv)); 130 124 char **argvp; 131 125 132 126 if (argv == NULL) ··· 383 377 goto out_err_overflow; 384 378 385 379 if (i > 0) 386 - printed += snprintf(e + printed, size - printed, " %s ", or_and); 380 + printed += scnprintf(e + printed, size - printed, " %s ", or_and); 387 381 printed += scnprintf(e + printed, size - printed, 388 382 "%s %s %d", var, eq_neq, ints[i]); 389 383 }
+42
tools/perf/util/string2.h
··· 1 + #ifndef PERF_STRING_H 2 + #define PERF_STRING_H 3 + 4 + #include <linux/types.h> 5 + #include <stddef.h> 6 + #include <string.h> 7 + 8 + s64 perf_atoll(const char *str); 9 + char **argv_split(const char *str, int *argcp); 10 + void argv_free(char **argv); 11 + bool strglobmatch(const char *str, const char *pat); 12 + bool strglobmatch_nocase(const char *str, const char *pat); 13 + bool strlazymatch(const char *str, const char *pat); 14 + static inline bool strisglob(const char *str) 15 + { 16 + return strpbrk(str, "*?[") != NULL; 17 + } 18 + int strtailcmp(const char *s1, const char *s2); 19 + char *strxfrchar(char *s, char from, char to); 20 + 21 + char *ltrim(char *s); 22 + char *rtrim(char *s); 23 + 24 + static inline char *trim(char *s) 25 + { 26 + return ltrim(rtrim(s)); 27 + } 28 + 29 + char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints); 30 + 31 + static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints) 32 + { 33 + return asprintf_expr_inout_ints(var, true, nints, ints); 34 + } 35 + 36 + static inline char *asprintf_expr_not_in_ints(const char *var, size_t nints, int *ints) 37 + { 38 + return asprintf_expr_inout_ints(var, false, nints, ints); 39 + } 40 + 41 + 42 + #endif /* PERF_STRING_H */
+1
tools/perf/util/strlist.c
··· 10 10 #include <stdio.h> 11 11 #include <stdlib.h> 12 12 #include <string.h> 13 + #include <unistd.h> 13 14 14 15 static 15 16 struct rb_node *strlist__node_new(struct rblist *rblist, const void *entry)
+2 -1
tools/perf/util/symbol-elf.c
··· 10 10 #include "demangle-rust.h" 11 11 #include "machine.h" 12 12 #include "vdso.h" 13 - #include <symbol/kallsyms.h> 14 13 #include "debug.h" 14 + #include "sane_ctype.h" 15 + #include <symbol/kallsyms.h> 15 16 16 17 #ifndef EM_AARCH64 17 18 #define EM_AARCH64 183 /* ARM 64 bit */
+1
tools/perf/util/symbol-minimal.c
··· 1 1 #include "symbol.h" 2 2 #include "util.h" 3 3 4 + #include <errno.h> 4 5 #include <stdio.h> 5 6 #include <fcntl.h> 6 7 #include <string.h>
+3
tools/perf/util/symbol.c
··· 3 3 #include <stdlib.h> 4 4 #include <stdio.h> 5 5 #include <string.h> 6 + #include <linux/kernel.h> 6 7 #include <sys/types.h> 7 8 #include <sys/stat.h> 8 9 #include <sys/param.h> ··· 19 18 #include "strlist.h" 20 19 #include "intlist.h" 21 20 #include "header.h" 21 + #include "path.h" 22 + #include "sane_ctype.h" 22 23 23 24 #include <elf.h> 24 25 #include <limits.h>
+1 -1
tools/perf/util/symbol.h
··· 13 13 #include <libgen.h> 14 14 #include "build-id.h" 15 15 #include "event.h" 16 - #include "util.h" 16 + #include "path.h" 17 17 18 18 #ifdef HAVE_LIBELF_SUPPORT 19 19 #include <libelf.h>
+5 -1
tools/perf/util/term.c
··· 1 - #include "util.h" 1 + #include "term.h" 2 + #include <stdlib.h> 3 + #include <termios.h> 4 + #include <unistd.h> 5 + #include <sys/ioctl.h> 2 6 3 7 void get_term_dimensions(struct winsize *ws) 4 8 {
+1
tools/perf/util/thread-stack.c
··· 15 15 16 16 #include <linux/rbtree.h> 17 17 #include <linux/list.h> 18 + #include <errno.h> 18 19 #include "thread.h" 19 20 #include "event.h" 20 21 #include "machine.h"
+2
tools/perf/util/thread.c
··· 1 1 #include "../perf.h" 2 + #include <errno.h> 2 3 #include <stdlib.h> 3 4 #include <stdio.h> 4 5 #include <string.h> 6 + #include <linux/kernel.h> 5 7 #include "session.h" 6 8 #include "thread.h" 7 9 #include "thread-stack.h"
+2
tools/perf/util/thread_map.c
··· 1 1 #include <dirent.h> 2 + #include <errno.h> 2 3 #include <limits.h> 3 4 #include <stdbool.h> 4 5 #include <stdlib.h> ··· 7 6 #include <sys/types.h> 8 7 #include <sys/stat.h> 9 8 #include <unistd.h> 9 + #include "string2.h" 10 10 #include "strlist.h" 11 11 #include <string.h> 12 12 #include <api/fs/fs.h>
+25
tools/perf/util/time-utils.c
··· 117 117 118 118 return false; 119 119 } 120 + 121 + int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz) 122 + { 123 + u64 sec = timestamp / NSEC_PER_SEC; 124 + u64 usec = (timestamp % NSEC_PER_SEC) / NSEC_PER_USEC; 125 + 126 + return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec); 127 + } 128 + 129 + int fetch_current_timestamp(char *buf, size_t sz) 130 + { 131 + struct timeval tv; 132 + struct tm tm; 133 + char dt[32]; 134 + 135 + if (gettimeofday(&tv, NULL) || !localtime_r(&tv.tv_sec, &tm)) 136 + return -1; 137 + 138 + if (!strftime(dt, sizeof(dt), "%Y%m%d%H%M%S", &tm)) 139 + return -1; 140 + 141 + scnprintf(buf, sz, "%s%02u", dt, (unsigned)tv.tv_usec / 10000); 142 + 143 + return 0; 144 + }
+7
tools/perf/util/time-utils.h
··· 1 1 #ifndef _TIME_UTILS_H_ 2 2 #define _TIME_UTILS_H_ 3 3 4 + #include <stddef.h> 5 + #include <linux/types.h> 6 + 4 7 struct perf_time_interval { 5 8 u64 start, end; 6 9 }; ··· 13 10 int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr); 14 11 15 12 bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp); 13 + 14 + int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); 15 + 16 + int fetch_current_timestamp(char *buf, size_t sz); 16 17 17 18 #endif
+1 -1
tools/perf/util/top.h
··· 5 5 #include <linux/types.h> 6 6 #include <stddef.h> 7 7 #include <stdbool.h> 8 - #include <termios.h> 8 + #include <sys/ioctl.h> 9 9 10 10 struct perf_evlist; 11 11 struct perf_evsel;
+2 -1
tools/perf/util/trace-event-parse.c
··· 21 21 #include <stdio.h> 22 22 #include <stdlib.h> 23 23 #include <string.h> 24 - #include <ctype.h> 25 24 #include <errno.h> 26 25 27 26 #include "../perf.h" 28 27 #include "util.h" 29 28 #include "trace-event.h" 29 + 30 + #include "sane_ctype.h" 30 31 31 32 static int get_common_field(struct scripting_context *context, 32 33 int *offset, int *size, const char *type)
+39
tools/perf/util/units.c
··· 1 + #include "units.h" 2 + #include <inttypes.h> 3 + #include <linux/kernel.h> 4 + #include <linux/time64.h> 5 + 6 + unsigned long convert_unit(unsigned long value, char *unit) 7 + { 8 + *unit = ' '; 9 + 10 + if (value > 1000) { 11 + value /= 1000; 12 + *unit = 'K'; 13 + } 14 + 15 + if (value > 1000) { 16 + value /= 1000; 17 + *unit = 'M'; 18 + } 19 + 20 + if (value > 1000) { 21 + value /= 1000; 22 + *unit = 'G'; 23 + } 24 + 25 + return value; 26 + } 27 + 28 + int unit_number__scnprintf(char *buf, size_t size, u64 n) 29 + { 30 + char unit[4] = "BKMG"; 31 + int i = 0; 32 + 33 + while (((n / 1024) > 1) && (i < 3)) { 34 + n /= 1024; 35 + i++; 36 + } 37 + 38 + return scnprintf(buf, size, "%" PRIu64 "%c", n, unit[i]); 39 + }
+10
tools/perf/util/units.h
··· 1 + #ifndef PERF_UNIT_H 2 + #define PERF_UNIT_H 3 + 4 + #include <stddef.h> 5 + #include <linux/types.h> 6 + 7 + unsigned long convert_unit(unsigned long value, char *unit); 8 + int unit_number__scnprintf(char *buf, size_t size, u64 n); 9 + 10 + #endif /* PERF_UNIT_H */
+1
tools/perf/util/unwind-libdw.c
··· 12 12 #include "event.h" 13 13 #include "perf_regs.h" 14 14 #include "callchain.h" 15 + #include "util.h" 15 16 16 17 static char *debuginfo_path; 17 18
+4 -2
tools/perf/util/unwind-libdw.h
··· 2 2 #define __PERF_UNWIND_LIBDW_H 3 3 4 4 #include <elfutils/libdwfl.h> 5 - #include "event.h" 6 - #include "thread.h" 7 5 #include "unwind.h" 6 + 7 + struct machine; 8 + struct perf_sample; 9 + struct thread; 8 10 9 11 bool libdw__arch_set_initial_registers(Dwfl_Thread *thread, void *arg); 10 12
+2
tools/perf/util/unwind-libunwind-local.c
··· 16 16 */ 17 17 18 18 #include <elf.h> 19 + #include <errno.h> 19 20 #include <gelf.h> 20 21 #include <fcntl.h> 22 + #include <inttypes.h> 21 23 #include <string.h> 22 24 #include <unistd.h> 23 25 #include <sys/mman.h>
+6 -3
tools/perf/util/unwind.h
··· 1 1 #ifndef __UNWIND_H 2 2 #define __UNWIND_H 3 3 4 + #include <linux/compiler.h> 4 5 #include <linux/types.h> 5 - #include "event.h" 6 - #include "symbol.h" 7 - #include "thread.h" 6 + 7 + struct map; 8 + struct perf_sample; 9 + struct symbol; 10 + struct thread; 8 11 9 12 struct unwind_entry { 10 13 struct map *map;
+4 -271
tools/perf/util/util.c
··· 3 3 #include "debug.h" 4 4 #include <api/fs/fs.h> 5 5 #include <sys/mman.h> 6 + #include <sys/stat.h> 6 7 #include <sys/utsname.h> 7 - #ifdef HAVE_BACKTRACE_SUPPORT 8 - #include <execinfo.h> 9 - #endif 8 + #include <dirent.h> 9 + #include <inttypes.h> 10 + #include <signal.h> 10 11 #include <stdio.h> 11 12 #include <stdlib.h> 12 13 #include <string.h> ··· 18 17 #include <linux/log2.h> 19 18 #include <linux/time64.h> 20 19 #include <unistd.h> 21 - #include "callchain.h" 22 20 #include "strlist.h" 23 - 24 - #define CALLCHAIN_PARAM_DEFAULT \ 25 - .mode = CHAIN_GRAPH_ABS, \ 26 - .min_percent = 0.5, \ 27 - .order = ORDER_CALLEE, \ 28 - .key = CCKEY_FUNCTION, \ 29 - .value = CCVAL_PERCENT, \ 30 - 31 - struct callchain_param callchain_param = { 32 - CALLCHAIN_PARAM_DEFAULT 33 - }; 34 - 35 - struct callchain_param callchain_param_default = { 36 - CALLCHAIN_PARAM_DEFAULT 37 - }; 38 21 39 22 /* 40 23 * XXX We need to find a better place for these things... ··· 254 269 return copyfile_mode(from, to, 0755); 255 270 } 256 271 257 - unsigned long convert_unit(unsigned long value, char *unit) 258 - { 259 - *unit = ' '; 260 - 261 - if (value > 1000) { 262 - value /= 1000; 263 - *unit = 'K'; 264 - } 265 - 266 - if (value > 1000) { 267 - value /= 1000; 268 - *unit = 'M'; 269 - } 270 - 271 - if (value > 1000) { 272 - value /= 1000; 273 - *unit = 'G'; 274 - } 275 - 276 - return value; 277 - } 278 - 279 272 static ssize_t ion(bool is_read, int fd, void *buf, size_t n) 280 273 { 281 274 void *buf_start = buf; ··· 335 372 return p - ptr; 336 373 } 337 374 338 - /* Obtain a backtrace and print it to stdout. */ 339 - #ifdef HAVE_BACKTRACE_SUPPORT 340 - void dump_stack(void) 341 - { 342 - void *array[16]; 343 - size_t size = backtrace(array, ARRAY_SIZE(array)); 344 - char **strings = backtrace_symbols(array, size); 345 - size_t i; 346 - 347 - printf("Obtained %zd stack frames.\n", size); 348 - 349 - for (i = 0; i < size; i++) 350 - printf("%s\n", strings[i]); 351 - 352 - free(strings); 353 - } 354 - #else 355 - void dump_stack(void) {} 356 - #endif 357 - 358 - void sighandler_dump_stack(int sig) 359 - { 360 - psignal(sig, "perf"); 361 - dump_stack(); 362 - signal(sig, SIG_DFL); 363 - raise(sig); 364 - } 365 - 366 - int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz) 367 - { 368 - u64 sec = timestamp / NSEC_PER_SEC; 369 - u64 usec = (timestamp % NSEC_PER_SEC) / NSEC_PER_USEC; 370 - 371 - return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec); 372 - } 373 - 374 375 unsigned long parse_tag_value(const char *str, struct parse_tag *tags) 375 376 { 376 377 struct parse_tag *i = tags; ··· 360 433 } 361 434 362 435 return (unsigned long) -1; 363 - } 364 - 365 - int get_stack_size(const char *str, unsigned long *_size) 366 - { 367 - char *endptr; 368 - unsigned long size; 369 - unsigned long max_size = round_down(USHRT_MAX, sizeof(u64)); 370 - 371 - size = strtoul(str, &endptr, 0); 372 - 373 - do { 374 - if (*endptr) 375 - break; 376 - 377 - size = round_up(size, sizeof(u64)); 378 - if (!size || size > max_size) 379 - break; 380 - 381 - *_size = size; 382 - return 0; 383 - 384 - } while (0); 385 - 386 - pr_err("callchain: Incorrect stack dump size (max %ld): %s\n", 387 - max_size, str); 388 - return -1; 389 - } 390 - 391 - int parse_callchain_record(const char *arg, struct callchain_param *param) 392 - { 393 - char *tok, *name, *saveptr = NULL; 394 - char *buf; 395 - int ret = -1; 396 - 397 - /* We need buffer that we know we can write to. */ 398 - buf = malloc(strlen(arg) + 1); 399 - if (!buf) 400 - return -ENOMEM; 401 - 402 - strcpy(buf, arg); 403 - 404 - tok = strtok_r((char *)buf, ",", &saveptr); 405 - name = tok ? : (char *)buf; 406 - 407 - do { 408 - /* Framepointer style */ 409 - if (!strncmp(name, "fp", sizeof("fp"))) { 410 - if (!strtok_r(NULL, ",", &saveptr)) { 411 - param->record_mode = CALLCHAIN_FP; 412 - ret = 0; 413 - } else 414 - pr_err("callchain: No more arguments " 415 - "needed for --call-graph fp\n"); 416 - break; 417 - 418 - /* Dwarf style */ 419 - } else if (!strncmp(name, "dwarf", sizeof("dwarf"))) { 420 - const unsigned long default_stack_dump_size = 8192; 421 - 422 - ret = 0; 423 - param->record_mode = CALLCHAIN_DWARF; 424 - param->dump_size = default_stack_dump_size; 425 - 426 - tok = strtok_r(NULL, ",", &saveptr); 427 - if (tok) { 428 - unsigned long size = 0; 429 - 430 - ret = get_stack_size(tok, &size); 431 - param->dump_size = size; 432 - } 433 - } else if (!strncmp(name, "lbr", sizeof("lbr"))) { 434 - if (!strtok_r(NULL, ",", &saveptr)) { 435 - param->record_mode = CALLCHAIN_LBR; 436 - ret = 0; 437 - } else 438 - pr_err("callchain: No more arguments " 439 - "needed for --call-graph lbr\n"); 440 - break; 441 - } else { 442 - pr_err("callchain: Unknown --call-graph option " 443 - "value: %s\n", arg); 444 - break; 445 - } 446 - 447 - } while (0); 448 - 449 - free(buf); 450 - return ret; 451 - } 452 - 453 - const char *get_filename_for_perf_kvm(void) 454 - { 455 - const char *filename; 456 - 457 - if (perf_host && !perf_guest) 458 - filename = strdup("perf.data.host"); 459 - else if (!perf_host && perf_guest) 460 - filename = strdup("perf.data.guest"); 461 - else 462 - filename = strdup("perf.data.kvm"); 463 - 464 - return filename; 465 436 } 466 437 467 438 int perf_event_paranoid(void) ··· 535 710 strlist__delete(tips); 536 711 537 712 return tip; 538 - } 539 - 540 - bool is_regular_file(const char *file) 541 - { 542 - struct stat st; 543 - 544 - if (stat(file, &st)) 545 - return false; 546 - 547 - return S_ISREG(st.st_mode); 548 - } 549 - 550 - int fetch_current_timestamp(char *buf, size_t sz) 551 - { 552 - struct timeval tv; 553 - struct tm tm; 554 - char dt[32]; 555 - 556 - if (gettimeofday(&tv, NULL) || !localtime_r(&tv.tv_sec, &tm)) 557 - return -1; 558 - 559 - if (!strftime(dt, sizeof(dt), "%Y%m%d%H%M%S", &tm)) 560 - return -1; 561 - 562 - scnprintf(buf, sz, "%s%02u", dt, (unsigned)tv.tv_usec / 10000); 563 - 564 - return 0; 565 - } 566 - 567 - void print_binary(unsigned char *data, size_t len, 568 - size_t bytes_per_line, print_binary_t printer, 569 - void *extra) 570 - { 571 - size_t i, j, mask; 572 - 573 - if (!printer) 574 - return; 575 - 576 - bytes_per_line = roundup_pow_of_two(bytes_per_line); 577 - mask = bytes_per_line - 1; 578 - 579 - printer(BINARY_PRINT_DATA_BEGIN, 0, extra); 580 - for (i = 0; i < len; i++) { 581 - if ((i & mask) == 0) { 582 - printer(BINARY_PRINT_LINE_BEGIN, -1, extra); 583 - printer(BINARY_PRINT_ADDR, i, extra); 584 - } 585 - 586 - printer(BINARY_PRINT_NUM_DATA, data[i], extra); 587 - 588 - if (((i & mask) == mask) || i == len - 1) { 589 - for (j = 0; j < mask-(i & mask); j++) 590 - printer(BINARY_PRINT_NUM_PAD, -1, extra); 591 - 592 - printer(BINARY_PRINT_SEP, i, extra); 593 - for (j = i & ~mask; j <= i; j++) 594 - printer(BINARY_PRINT_CHAR_DATA, data[j], extra); 595 - for (j = 0; j < mask-(i & mask); j++) 596 - printer(BINARY_PRINT_CHAR_PAD, i, extra); 597 - printer(BINARY_PRINT_LINE_END, -1, extra); 598 - } 599 - } 600 - printer(BINARY_PRINT_DATA_END, -1, extra); 601 - } 602 - 603 - int is_printable_array(char *p, unsigned int len) 604 - { 605 - unsigned int i; 606 - 607 - if (!p || !len || p[len - 1] != 0) 608 - return 0; 609 - 610 - len--; 611 - 612 - for (i = 0; i < len; i++) { 613 - if (!isprint(p[i]) && !isspace(p[i])) 614 - return 0; 615 - } 616 - return 1; 617 - } 618 - 619 - int unit_number__scnprintf(char *buf, size_t size, u64 n) 620 - { 621 - char unit[4] = "BKMG"; 622 - int i = 0; 623 - 624 - while (((n / 1024) > 1) && (i < 3)) { 625 - n /= 1024; 626 - i++; 627 - } 628 - 629 - return scnprintf(buf, size, "%" PRIu64 "%c", n, unit[i]); 630 713 }
+2 -283
tools/perf/util/util.h
··· 1 1 #ifndef GIT_COMPAT_UTIL_H 2 2 #define GIT_COMPAT_UTIL_H 3 3 4 - #ifndef FLEX_ARRAY 5 - /* 6 - * See if our compiler is known to support flexible array members. 7 - */ 8 - #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) 9 - # define FLEX_ARRAY /* empty */ 10 - #elif defined(__GNUC__) 11 - # if (__GNUC__ >= 3) 12 - # define FLEX_ARRAY /* empty */ 13 - # else 14 - # define FLEX_ARRAY 0 /* older GNU extension */ 15 - # endif 16 - #endif 17 - 18 - /* 19 - * Otherwise, default to safer but a bit wasteful traditional style 20 - */ 21 - #ifndef FLEX_ARRAY 22 - # define FLEX_ARRAY 1 23 - #endif 24 - #endif 25 - 26 - #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) 27 - 28 - #ifdef __GNUC__ 29 - #define TYPEOF(x) (__typeof__(x)) 30 - #else 31 - #define TYPEOF(x) 32 - #endif 33 - 34 - #define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (sizeof(x) * 8 - (bits)))) 35 - #define HAS_MULTI_BITS(i) ((i) & ((i) - 1)) /* checks if an integer has more than 1 bit set */ 36 - 37 - /* Approximation of the length of the decimal representation of this type. */ 38 - #define decimal_length(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1) 39 - 40 4 #define _ALL_SOURCE 1 41 5 #define _BSD_SOURCE 1 42 6 /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */ 43 7 #define _DEFAULT_SOURCE 1 44 8 #define HAS_BOOL 45 9 46 - #include <unistd.h> 47 - #include <stdio.h> 48 - #include <sys/stat.h> 49 - #include <sys/statfs.h> 50 10 #include <fcntl.h> 51 11 #include <stdbool.h> 52 12 #include <stddef.h> 53 13 #include <stdlib.h> 54 14 #include <stdarg.h> 55 - #include <string.h> 56 - #include <term.h> 57 - #include <errno.h> 58 - #include <limits.h> 59 - #include <sys/param.h> 60 - #include <sys/types.h> 61 - #include <dirent.h> 62 - #include <sys/time.h> 63 - #include <time.h> 64 - #include <signal.h> 65 - #include <fnmatch.h> 66 - #include <assert.h> 67 - #include <regex.h> 68 - #include <utime.h> 69 - #include <sys/wait.h> 70 - #include <poll.h> 71 - #include <sys/socket.h> 72 - #include <sys/ioctl.h> 73 - #include <inttypes.h> 74 - #include <linux/kernel.h> 75 15 #include <linux/types.h> 76 - #include <sys/ttydefaults.h> 77 - #include <api/fs/tracing_path.h> 78 - #include <termios.h> 79 - #include <linux/bitops.h> 80 - #include <termios.h> 81 - #include "strlist.h" 82 16 83 - extern const char *graph_line; 84 - extern const char *graph_dotted_line; 85 - extern const char *spaces; 86 - extern const char *dots; 87 17 extern char buildid_dir[]; 88 - 89 - /* On most systems <limits.h> would have given us this, but 90 - * not on some systems (e.g. GNU/Hurd). 91 - */ 92 - #ifndef PATH_MAX 93 - #define PATH_MAX 4096 94 - #endif 95 - 96 - #ifndef PRIuMAX 97 - #define PRIuMAX "llu" 98 - #endif 99 - 100 - #ifndef PRIu32 101 - #define PRIu32 "u" 102 - #endif 103 - 104 - #ifndef PRIx32 105 - #define PRIx32 "x" 106 - #endif 107 - 108 - #ifndef PATH_SEP 109 - #define PATH_SEP ':' 110 - #endif 111 - 112 - #ifndef STRIP_EXTENSION 113 - #define STRIP_EXTENSION "" 114 - #endif 115 - 116 - #ifndef has_dos_drive_prefix 117 - #define has_dos_drive_prefix(path) 0 118 - #endif 119 - 120 - #ifndef is_dir_sep 121 - #define is_dir_sep(c) ((c) == '/') 122 - #endif 123 18 124 19 #ifdef __GNUC__ 125 20 #define NORETURN __attribute__((__noreturn__)) ··· 38 143 int prefixcmp(const char *str, const char *prefix); 39 144 void set_buildid_dir(const char *dir); 40 145 41 - #ifdef __GLIBC_PREREQ 42 - #if __GLIBC_PREREQ(2, 1) 43 - #define HAVE_STRCHRNUL 44 - #endif 45 - #endif 46 - 47 - #ifndef HAVE_STRCHRNUL 48 - #define strchrnul gitstrchrnul 49 - static inline char *gitstrchrnul(const char *s, int c) 50 - { 51 - while (*s && *s != c) 52 - s++; 53 - return (char *)s; 54 - } 55 - #endif 56 - 57 146 static inline void *zalloc(size_t size) 58 147 { 59 148 return calloc(1, size); ··· 45 166 46 167 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; }) 47 168 48 - /* Sane ctype - no locale, and works with signed chars */ 49 - #undef isascii 50 - #undef isspace 51 - #undef isdigit 52 - #undef isxdigit 53 - #undef isalpha 54 - #undef isprint 55 - #undef isalnum 56 - #undef islower 57 - #undef isupper 58 - #undef tolower 59 - #undef toupper 60 - 61 - extern unsigned char sane_ctype[256]; 62 - #define GIT_SPACE 0x01 63 - #define GIT_DIGIT 0x02 64 - #define GIT_ALPHA 0x04 65 - #define GIT_GLOB_SPECIAL 0x08 66 - #define GIT_REGEX_SPECIAL 0x10 67 - #define GIT_PRINT_EXTRA 0x20 68 - #define GIT_PRINT 0x3E 69 - #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0) 70 - #define isascii(x) (((x) & ~0x7f) == 0) 71 - #define isspace(x) sane_istest(x,GIT_SPACE) 72 - #define isdigit(x) sane_istest(x,GIT_DIGIT) 73 - #define isxdigit(x) \ 74 - (sane_istest(toupper(x), GIT_ALPHA | GIT_DIGIT) && toupper(x) < 'G') 75 - #define isalpha(x) sane_istest(x,GIT_ALPHA) 76 - #define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) 77 - #define isprint(x) sane_istest(x,GIT_PRINT) 78 - #define islower(x) (sane_istest(x,GIT_ALPHA) && (x & 0x20)) 79 - #define isupper(x) (sane_istest(x,GIT_ALPHA) && !(x & 0x20)) 80 - #define tolower(x) sane_case((unsigned char)(x), 0x20) 81 - #define toupper(x) sane_case((unsigned char)(x), 0) 82 - 83 - static inline int sane_case(int x, int high) 84 - { 85 - if (sane_istest(x, GIT_ALPHA)) 86 - x = (x & ~0x20) | high; 87 - return x; 88 - } 169 + struct dirent; 170 + struct strlist; 89 171 90 172 int mkdir_p(char *path, mode_t mode); 91 173 int rm_rf(const char *path); ··· 56 216 int copyfile_mode(const char *from, const char *to, mode_t mode); 57 217 int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size); 58 218 59 - s64 perf_atoll(const char *str); 60 - char **argv_split(const char *str, int *argcp); 61 - void argv_free(char **argv); 62 - bool strglobmatch(const char *str, const char *pat); 63 - bool strglobmatch_nocase(const char *str, const char *pat); 64 - bool strlazymatch(const char *str, const char *pat); 65 - static inline bool strisglob(const char *str) 66 - { 67 - return strpbrk(str, "*?[") != NULL; 68 - } 69 - int strtailcmp(const char *s1, const char *s2); 70 - char *strxfrchar(char *s, char from, char to); 71 - unsigned long convert_unit(unsigned long value, char *unit); 72 219 ssize_t readn(int fd, void *buf, size_t n); 73 220 ssize_t writen(int fd, void *buf, size_t n); 74 221 ··· 63 236 64 237 void event_attr_init(struct perf_event_attr *attr); 65 238 66 - #define _STR(x) #x 67 - #define STR(x) _STR(x) 68 - 69 239 size_t hex_width(u64 v); 70 240 int hex2u64(const char *ptr, u64 *val); 71 - 72 - char *ltrim(char *s); 73 - char *rtrim(char *s); 74 - 75 - static inline char *trim(char *s) 76 - { 77 - return ltrim(rtrim(s)); 78 - } 79 - 80 - void dump_stack(void); 81 - void sighandler_dump_stack(int sig); 82 241 83 242 extern unsigned int page_size; 84 243 extern int cacheline_size; ··· 78 265 79 266 unsigned long parse_tag_value(const char *str, struct parse_tag *tags); 80 267 81 - #define SRCLINE_UNKNOWN ((char *) "??:0") 82 - 83 - static inline int path__join(char *bf, size_t size, 84 - const char *path1, const char *path2) 85 - { 86 - return scnprintf(bf, size, "%s%s%s", path1, path1[0] ? "/" : "", path2); 87 - } 88 - 89 - static inline int path__join3(char *bf, size_t size, 90 - const char *path1, const char *path2, 91 - const char *path3) 92 - { 93 - return scnprintf(bf, size, "%s%s%s%s%s", 94 - path1, path1[0] ? "/" : "", 95 - path2, path2[0] ? "/" : "", path3); 96 - } 97 - 98 - struct dso; 99 - struct symbol; 100 - 101 - extern bool srcline_full_filename; 102 - char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym, 103 - bool show_sym, bool show_addr); 104 - char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym, 105 - bool show_sym, bool show_addr, bool unwind_inlines); 106 - void free_srcline(char *srcline); 107 - 108 268 int perf_event_paranoid(void); 109 269 110 270 void mem_bswap_64(void *src, int byte_size); 111 271 void mem_bswap_32(void *src, int byte_size); 112 272 113 - const char *get_filename_for_perf_kvm(void); 114 273 bool find_process(const char *name); 115 - 116 - #ifdef HAVE_ZLIB_SUPPORT 117 - int gzip_decompress_to_file(const char *input, int output_fd); 118 - #endif 119 - 120 - #ifdef HAVE_LZMA_SUPPORT 121 - int lzma_decompress_to_file(const char *input, int output_fd); 122 - #endif 123 - 124 - char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints); 125 - 126 - static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints) 127 - { 128 - return asprintf_expr_inout_ints(var, true, nints, ints); 129 - } 130 - 131 - static inline char *asprintf_expr_not_in_ints(const char *var, size_t nints, int *ints) 132 - { 133 - return asprintf_expr_inout_ints(var, false, nints, ints); 134 - } 135 - 136 - int get_stack_size(const char *str, unsigned long *_size); 137 274 138 275 int fetch_kernel_version(unsigned int *puint, 139 276 char *str, size_t str_sz); ··· 94 331 #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x) 95 332 96 333 const char *perf_tip(const char *dirpath); 97 - bool is_regular_file(const char *file); 98 - int fetch_current_timestamp(char *buf, size_t sz); 99 - 100 - enum binary_printer_ops { 101 - BINARY_PRINT_DATA_BEGIN, 102 - BINARY_PRINT_LINE_BEGIN, 103 - BINARY_PRINT_ADDR, 104 - BINARY_PRINT_NUM_DATA, 105 - BINARY_PRINT_NUM_PAD, 106 - BINARY_PRINT_SEP, 107 - BINARY_PRINT_CHAR_DATA, 108 - BINARY_PRINT_CHAR_PAD, 109 - BINARY_PRINT_LINE_END, 110 - BINARY_PRINT_DATA_END, 111 - }; 112 - 113 - typedef void (*print_binary_t)(enum binary_printer_ops, 114 - unsigned int val, 115 - void *extra); 116 - 117 - void print_binary(unsigned char *data, size_t len, 118 - size_t bytes_per_line, print_binary_t printer, 119 - void *extra); 120 334 121 335 #ifndef HAVE_SCHED_GETCPU_SUPPORT 122 336 int sched_getcpu(void); 123 337 #endif 124 - 125 - int is_printable_array(char *p, unsigned int len); 126 - 127 - int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); 128 - 129 - int unit_number__scnprintf(char *buf, size_t size, u64 n); 130 - 131 - struct inline_list { 132 - char *filename; 133 - char *funcname; 134 - unsigned int line_nr; 135 - struct list_head list; 136 - }; 137 - 138 - struct inline_node { 139 - u64 addr; 140 - struct list_head val; 141 - }; 142 - 143 - struct inline_node *dso__parse_addr_inlines(struct dso *dso, u64 addr); 144 - void inline_node__delete(struct inline_node *node); 145 338 146 339 #endif /* GIT_COMPAT_UTIL_H */
+1 -1
tools/perf/util/vdso.c
··· 1 - 1 + #include <errno.h> 2 2 #include <unistd.h> 3 3 #include <stdio.h> 4 4 #include <string.h>
+2
tools/perf/util/xyarray.c
··· 1 1 #include "xyarray.h" 2 2 #include "util.h" 3 + #include <stdlib.h> 4 + #include <string.h> 3 5 4 6 struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size) 5 7 {
+1
tools/perf/util/zlib.c
··· 4 4 #include <sys/mman.h> 5 5 #include <zlib.h> 6 6 7 + #include "util/compress.h" 7 8 #include "util/util.h" 8 9 #include "util/debug.h" 9 10