Re: [PATCH 0/4] perf lock contention: Improve lock symbol display (v1)
From: Namhyung Kim
Date: Tue Mar 14 2023 - 13:55:32 EST
Hi Arnaldo,
On Tue, Mar 14, 2023 at 5:23 AM Arnaldo Carvalho de Melo
<acme@xxxxxxxxxx> wrote:
>
> Em Mon, Mar 13, 2023 at 06:45:53PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Mon, Mar 13, 2023 at 01:48:21PM -0700, Namhyung Kim escreveu:
> > > Hello,
> > >
> > > This patchset improves the symbolization of locks for -l/--lock-addr mode.
> > > As of now it only shows global lock symbols present in the kallsyms. But
> > > we can add some more lock symbols by traversing pointers in the BPF program.
> > >
> > > For example, mmap_lock can be reached from the mm_struct of the current task
> > > (task_struct->mm->mmap_lock) and we can compare the address of the give lock
> > > with it. Similarly I've added 'siglock' for current->sighand->siglock.
>
> Hey, we can go a bit further by using something like pahole's
> --expand_types and --expand_pointers and play iterating a type members
> and looking for locks, like:
>
> ⬢[acme@toolbox pahole]$ pahole task_struct | grep spinlock_t
> spinlock_t alloc_lock; /* 3280 4 */
> raw_spinlock_t pi_lock; /* 3284 4 */
> seqcount_spinlock_t mems_allowed_seq; /* 3616 4 */
> ⬢[acme@toolbox pahole]$
>
> Expand points will find mmap_lock:
>
> ⬢[acme@toolbox pahole]$ pahole --expand_pointers -C task_struct | grep -B10 mmap_lock
> } *pgd;
> atomic_t membarrier_state;
> atomic_t mm_users;
> atomic_t mm_count;
>
> /* XXX 4 bytes hole, try to pack */
>
> atomic_long_t pgtables_bytes;
> int map_count;
> spinlock_t page_table_lock;
> struct rw_semaphore mmap_lock;
> ^C
> ⬢[acme@toolbox pahole]$
>
>
> ITs just too much expansion to see task_struct->mm, but it is there, of
> course:
>
> ⬢[acme@toolbox pahole]$ pahole mm_struct | grep mmap_lock
> struct rw_semaphore mmap_lock; /* 120 40 */
> ⬢[acme@toolbox pahole]$
>
> Also:
>
> ⬢[acme@toolbox pahole]$ pahole --contains rw_semaphore
> address_space
> signal_struct
> key
> inode
> super_block
> quota_info
> user_namespace
> blocking_notifier_head
> backing_dev_info
> anon_vma
> tty_struct
> cpufreq_policy
> tcf_block
> ipc_ids
> autogroup
> kvm_arch
> posix_clock
> listener_list
> uprobe
> kernfs_root
> configfs_fragment
> ext4_inode_info
> ext4_group_info
> btrfs_fs_info
> extent_buffer
> btrfs_dev_replace
> btrfs_space_info
> btrfs_inode
> btrfs_block_group
> tpm_chip
> ib_device
> ib_xrcd
> blk_crypto_profile
> controller
> led_classdev
> cppc_pcc_data
> dm_snapshot
> ⬢[acme@toolbox pahole]$
>
> And:
>
> ⬢[acme@toolbox pahole]$ pahole --find_pointers_to mm_struct
> task_struct: mm
> task_struct: active_mm
> vm_area_struct: vm_mm
> flush_tlb_info: mm
> signal_struct: oom_mm
> tlb_state: loaded_mm
> linux_binprm: mm
> mmu_gather: mm
> trace_event_raw_xen_mmu_ptep_modify_prot: mm
> trace_event_raw_xen_mmu_alloc_ptpage: mm
> trace_event_raw_xen_mmu_pgd: mm
> trace_event_raw_xen_mmu_flush_tlb_multi: mm
> trace_event_raw_hyperv_mmu_flush_tlb_multi: mm
> mmu_notifier: mm
> mmu_notifier_range: mm
> sgx_encl_mm: mm
> rq: prev_mm
> kvm: mm
> cpuset_migrate_mm_work: mm
> mmap_unlock_irq_work: mm
> delayed_uprobe: mm
> map_info: mm
> trace_event_raw_mmap_lock: mm
> trace_event_raw_mmap_lock_acquire_returned: mm
> mm_walk: mm
> make_exclusive_args: mm
> mmu_interval_notifier: mm
> mm_slot: mm
> rmap_item: mm
> trace_event_raw_mm_khugepaged_scan_pmd: mm
> trace_event_raw_mm_collapse_huge_page: mm
> trace_event_raw_mm_collapse_huge_page_swapin: mm
> mm_slot: mm
> move_charge_struct: mm
> userfaultfd_ctx: mm
> proc_maps_private: mm
> remap_pfn: mm
> intel_svm: mm
> binder_alloc: vma_vm_mm
> ⬢[acme@toolbox pahole]$
This looks really cool! especially.
I'm especially interested in adding super_block and kernfs_root.
Let me see how I can add them.
Thanks,
Namhyung