Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libbpf-tools: add futexctn #4669

Merged
merged 1 commit into from
Nov 27, 2023
Merged

libbpf-tools: add futexctn #4669

merged 1 commit into from
Nov 27, 2023

Conversation

ethercflow
Copy link
Contributor

@ethercflow ethercflow commented Jul 10, 2023

Although systemtap already has a futexes.stp tool, it doesn't feel very easy to use. For example, there are only maximum, minimum and average values, but no delay distribution information. In addition, although the mutex address is behind, there is no call stack information, which is inconvenient to check when you cannot use gdb to attach the process.

This tool identifies lock contention information by filtering futex FUTEX_WAIT operations and retrieves the call stack information when entering lock contention. The lock contention counter is partitioned based on the call stack, enabling users to locate all path information involved in this lock contention using the printed lock address, which serves as the basis for optimization.

➜ ✗ sudo ./futexctn -p 381676 1 1 -mT

15:07:13


fmu[381694] lock 0x55bb40a44060 contended 61 times, 16 avg msecs [max: 21 msecs, min 16 msecs]
    -
    __lll_lock_wait_private
    bar
    foo
    thread_func
    pthread_condattr_setpshared
    -
     msecs               : count    distribution
         0 -> 1          : 0        |                                        |
         2 -> 3          : 0        |                                        |
         4 -> 7          : 0        |                                        |
         8 -> 15         : 0        |                                        |
        16 -> 31         : 61       |****************************************|


fmu[381689] lock 0x55bb40a44060 contended 61 times, 16 avg msecs [max: 21 msecs, min 16 msecs]
    -
    __lll_lock_wait_private
    bar
    foo
    thread_func
    pthread_condattr_setpshared
    -
     msecs               : count    distribution
         0 -> 1          : 0        |                                        |
         2 -> 3          : 0        |                                        |
         4 -> 7          : 0        |                                        |
         8 -> 15         : 0        |                                        |
        16 -> 31         : 61       |****************************************|

@chenhengqi
Copy link
Collaborator

Could you explain how does this tool work, especially the contended counter ?

@ethercflow
Copy link
Contributor Author

Could you explain how does this tool work, especially the contended counter ?

Done

@chenhengqi
Copy link
Collaborator

  • Since this tool is working on a single process basis, FUTEX_WAIT_PRIVATE should be used instead of FUTEX_WAIT.

When executing a futex operation that requests to block a thread,
the kernel will block only if the futex word has the value that
the calling thread supplied (as one of the arguments of the
futex() call) as the expected value of the futex word.

  • According to the manpage, I guess more work should be done to check whether there is a contention or not.

@ethercflow
Copy link
Contributor Author

Since this tool is working on a single process basis, FUTEX_WAIT_PRIVATE should be used instead of FUTEX_WAIT.

@chenhengqi Glibc (pthread) only use FUTEX_WAIT, so we need to add comments to notice this?

@ethercflow
Copy link
Contributor Author

Hi @chenhengqi @yonghong-song, do you have any other suggestions for modification?

@yonghong-song
Copy link
Collaborator

Similar to other tools, please guard your usage of blazesym with macro USE_BLAZESYM as it may not be available in all systems.

@ethercflow ethercflow force-pushed the futexctn branch 2 times, most recently from 30be7ea to 152e304 Compare August 25, 2023 08:25
@ethercflow
Copy link
Contributor Author

Similar to other tools, please guard your usage of blazesym with macro USE_BLAZESYM as it may not be available in all systems.

@yonghong-song Fixed, thanks!

@ethercflow
Copy link
Contributor Author

Hi @yonghong-song @chenhengqi , sorry to bother you. May I ask if this PR be merged? Is there anything else I need to do?

Signed-off-by: Wenbo Zhang <[email protected]>
@chenhengqi chenhengqi merged commit bc9b43a into iovisor:master Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants