aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/scripts/python/futex-contention.py
blob: 7e884d46f92066fcfd29f5a3222f90bbdd0640e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# futex contention
# (c) 2010, Arnaldo Carvalho de Melo <acme@redhat.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Translation of:
#
# http://sourceware.org/systemtap/wiki/WSFutexContention
#
# to perf python scripting.
#
# Measures futex contention

from __future__ import print_function

import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] +
                '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from Util import *

process_names = {}
thread_thislock = {}
thread_blocktime = {}

lock_waits = {}  # long-lived stats on (tid,lock) blockage elapsed time
process_names = {}  # long-lived pid-to-execname mapping


def syscalls__sys_enter_futex(event, ctxt, cpu, s, ns, tid, comm, callchain,
                              nr, uaddr, op, val, utime, uaddr2, val3):
    cmd = op & FUTEX_CMD_MASK
    if cmd != FUTEX_WAIT:
        return  # we don't care about originators of WAKE events

    process_names[tid] = comm
    thread_thislock[tid] = uaddr
    thread_blocktime[tid] = nsecs(s, ns)


def syscalls__sys_exit_futex(event, ctxt, cpu, s, ns, tid, comm, callchain,
                             nr, ret):
    if tid in thread_blocktime:
        elapsed = nsecs(s, ns) - thread_blocktime[tid]
        add_stats(lock_waits, (tid, thread_thislock[tid]), elapsed)
        del thread_blocktime[tid]
        del thread_thislock[tid]


def trace_begin():
    print("Press control+C to stop and show the summary")


def trace_end():
    for (tid, lock) in lock_waits:
        min, max, avg, count = lock_waits[tid, lock]
        print("%s[%d] lock %x contended %d times, %d avg ns [max: %d ns, min %d ns]" %
              (process_names[tid], tid, lock, count, avg, max, min))
ock protection for irq {un}maskYoshihiro Shimoda2-0/+14 2023-09-14net: renesas: rswitch: Fix unmasking irq conditionYoshihiro Shimoda1-4/+4 2023-09-13igb: clean up in all error paths when enabling SR-IOVCorinna Vinschen1-1/+4 2023-09-13ixgbe: fix timestamp configuration codeVadim Fedorenko1-13/+15 2023-09-13i2c: cadence: Fix the kernel-doc warningsShubhrajyoti Datta1-0/+1 2023-09-13pmdomain: Rename the genpd subsystem to pmdomainUlf Hansson87-12/+12 2023-09-13i2c: aspeed: Reset the i2c controller when timeout occursTommy Huang1-2/+5 2023-09-13i2c: I2C_MLXCPLD on ARM64 should depend on ACPIGeert Uytterhoeven1-2/+2 2023-09-13i2c: Make I2C_ATR invisibleGeert Uytterhoeven1-1/+1 2023-09-13i2c: Drop legacy callback .probe_new()Uwe Kleine-König1-10/+1 2023-09-13w1: ds2482: Switch back to use struct i2c_driver's .probe()Uwe Kleine-König1-1/+1 2023-09-13selftest: tcp: Add v4-mapped-v6 cases in bind_wildcard.c.Kuniyuki Iwashima1-0/+46 2023-09-13selftest: tcp: Move expected_errno into each test case in bind_wildcard.c.Kuniyuki Iwashima1-10/+10 2023-09-13selftest: tcp: Fix address length in bind_wildcard.c.Kuniyuki Iwashima1-1/+1 2023-09-13tcp: Fix bind() regression for v4-mapped-v6 non-wildcard address.Kuniyuki Iwashima1-1/+6 2023-09-13tcp: Fix bind() regression for v4-mapped-v6 wildcard address.Kuniyuki Iwashima2-1/+7 2023-09-13tcp: Factorise sk_family-independent comparison in inet_bind2_bucket_match(_a...Kuniyuki Iwashima1-15/+13 2023-09-12drm/amdkfd: Insert missing TLB flush on GFX10 and laterHarish Kasiviswanathan1-2/+1 2023-09-12selinux: fix handling of empty opts in selinux_fs_context_submount()Ondrej Mosnacek1-2/+8 2023-09-12riscv: errata: fix T-Head dcache.cva encodingIcenowy Zheng1-2/+2 2023-09-12riscv: kexec: Align the kexeced kernel entrySong Shuai1-1/+7 2023-09-12tpm: Fix typo in tpmrm class definitionJustin M. Forbes1-1/+1 2023-09-12ipv6: fix ip6_sock_set_addr_preferences() typoEric Dumazet1-1/+1 2023-09-12nvme-pci: do not set the NUMA node of device if it has nonePratyush Yadav1-3/+0 2023-09-12linux/export: fix reference to exported functions for parisc64Masahiro Yamada2-0/+11 2023-09-12selftests: tracing: Fix to unmount tracefs for recovering environmentMasami Hiramatsu (Google)1-0/+8 2023-09-12veth: Update XDP feature set when bringing up deviceToke Høiland-Jørgensen1-0/+2 2023-09-12eventfs: Fix the NULL pointer dereference bug in eventfs_remove_rec()Jinjie Ruan1-4/+9 2023-09-12Revert "comedi: add HAS_IOPORT dependencies"Ian Abbott1-68/+35 2023-09-12NFSD: fix possible oops when nfsd/pool_stats is closed.NeilBrown1-2/+3 2023-09-12net: macb: fix sleep inside spinlockSascha Hauer1-2/+3 2023-09-12drm/i915: Only check eDP HPD when AUX CH is sharedVille Syrjälä3-1/+28 2023-09-12PM: hibernate: Fix the exclusive get block device in test_resume modeChen Yu1-6/+6 2023-09-12PM: hibernate: Rename function parameter from snapshot_test to exclusiveChen Yu2-8/+10 2023-09-12net/tls: do not free tls_rec on async operation in bpf_exec_tx_verdict()Liu Jian1-2/+2 2023-09-11tracefs/eventfs: Use list_for_each_srcu() in dcache_dir_open_wrapper()Steven Rostedt (Google)1-1/+2