如何调试strace中显示的futex争用? [英] How to debug a futex contention shown in strace?

查看:2199
本文介绍了如何调试strace中显示的futex争用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试多线程linux进程中的问题,该进程中某个线程似乎在几秒钟内未执行.查看strace输出显示它正在等待futex,例如
1673109 14:36:28.600329 futex(0x44b8d20,FUTEX_WAIT_PRIVATE,
1673109 14:36:33.221850< ... futex resumed>)= 0< 4.621514>

I'm debugging an issue in a multi-threaded linux process, where a certain thread appears to not execute for few seconds. Looking at strace output revealed it waits for futex e.g.
1673109 14:36:28.600329 futex(0x44b8d20, FUTEX_WAIT_PRIVATE,
1673109 14:36:33.221850 <... futex resumed> ) = 0 <4.621514>

如何找出用户空间中futex(0x44b8d20)的含义,即如何将其映射到内部使用futex的锁定结构.

How can I find out out what this futex(0x44b8d20) refers to in user space, i.e. how to map this to a locking construct which is using futex internally.

推荐答案

我将使用一个简单的systemtap脚本,以帮助您快速找出竞争的futex锁的地址.我说的地址是指 futex()的第一个参数.系统调用.

I would use a simple systemtap script so that would help you to quickly find out addresses of contended futex locks. When I say address, I am referring to the first argument of futex() syscall.

  1. 您可以在此处下载简单的系统点击脚本,该脚本可找到有争议的用户空间锁:
    https://sourceware.org/systemtap/examples/process/futexes.stp

  1. You can download the simple system tap script that finds the contended user space locks here:
    https://sourceware.org/systemtap/examples/process/futexes.stp

如果您的系统上安装了systemtap,
只需启动以下系统点击脚本:stap futexes.stp

If you have systemtap installed on your system,
just start this system tap script: stap futexes.stp

像以前一样捕获strace输出.

如果仅通过执行Ctrl-C结束系统Tap脚本执行,
您将获得竞争futex的输出.

If you end the system tap script execution by simply doing Ctrl-C,
you will get the output of contended futexes.

最后在您的strace输出中,
搜索第二个参数(操作类型)为FUTEX_WAIT的futex调用. 例如:futex(0x7f58a31999d0, FUTEX_WAIT, 4508, NULL) = 0

Finally in your strace output,
search for futex calls in which the second argument (operation type) is FUTEX_WAIT.
For example : futex(0x7f58a31999d0, FUTEX_WAIT, 4508, NULL) = 0

然后,您可以在系统点击脚本输出中搜索第一个参数.
类似于:ome[4489] lock 0x7f58a31999d0 contended 1 times, 7807 avg us

Then you can search for the first argument in system tap script output.
Something like : ome[4489] lock 0x7f58a31999d0 contended 1 times, 7807 avg us

如果您查看此系统点击脚本,
它会很好地为您打印进程名称和进程/线程ID.
这样可以轻松找到所需的内容.

If you look at this system tap script,
it nicely prints the process name and process/thread id for you.
This makes it easy to find what you are looking for.

但是请注意,执行systemtap脚本实际上会在整个系统范围内挂起系统调用.

However one note is that executing the systemtap script will actually hook a syscall system wide.

这篇关于如何调试strace中显示的futex争用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆