问题描述
我想知道如何分析Pthread互斥,看看是否有我的code是任何锁定的争点。 (谁喜欢有争议的code,对不对?:)我知道该怎么做了code的更一般的分析,因为我提到的。但我想知道是否有可用的能够为配置文件互斥锁定,将提供指标/统计约互斥锁争用,看看我是否有任何问题领域任何工具或选项。
I would like to know how to profile a pthread mutex to see if there are any locking contention points in my code. (who likes contentious code, right? :) I know how to do a more general profiling of the code, as I mention here. But I would like to know if there are any tools or options available to be able to profile mutex locking that would provide metrics/stats about mutex locking contentions to see if I have any problem areas.
下面是一些背景和内容:
Here's some background and context:
最近我的工作使用了Cavium的Octeon CPU嵌入式C ++项目。 OCTEON对SDK实现使用自旋锁互斥风格同步。通过的Octeon文档看,我碰到一个方法来分析的螺旋锁,可以看到每一个自旋锁有多少次旋转,而等待锁变得可用。要使用此我不得不做一个条件编译,然后将每次自旋锁纺递增计数器,那么我可以查询微调等待值。所以,我所做的就是封装自旋锁,并添加到转储自旋锁微调等待值的所有系统中使用了自旋锁的能力。实际值剪掉多大的意义,但也有少数相比,其余的有非常高的值,我把重点放在减少争用的。
Recently I worked on an embedded C++ project using a Cavium Octeon CPU. The Octeon SDK implements mutex style synchronization using spinlocks. Looking through the Octeon documentation, I came across a way to profile the spinlocks to be able to see how many times each spinlock had to spin while waiting for the lock to become available. To use this I had to do a conditional compile and then it would increment a counter each time the spinlock spun, then I could query the spinner wait value. So, what I did was to encapsulate the spinlock and added the ability to dump the spinlock spinner wait value for all of the spinlocks used in the system. The actual value didnt mean much, but there were a few that had really high values compared to the rest, and I focused on reducing the contention for those.
我知道这可能是自旋锁很简单,因为它只是每旋转一个计数器,而是通过相关的pthread手册页和头文件我还没有发现任何类似的阅读,有没有一个适合Pthread互斥的东西吗?
I know this is probably quite easy for spinlocks, since its just a counter per spin, but reading through the related pthread man pages and header files I havent found anything similar, is there something available for pthread mutex?
我真的想避免做一些哈克喜欢拍照的时间之前,每个锁之后。
I would really like to avoid having to do something hacky like taking the time before and after each lock.
PS:什么是互斥的复数形式呢?互斥,muteces,mutexi,穆蒂?互斥从未响起我的权利。
PS: What's the plural of mutex? mutexes, muteces, mutexi, muti??? Mutexes never sounded right to me.
推荐答案
的的valgrind
工具的使您可以指定多久的锁应该报告错误之前,等待上的限制。
The valgrind
tool drd lets you specify a limit on how long a lock should be waited on before reporting an error.
这提到 DRD
,也提到自己自己的工具,名为 mutrace
它看起来像你后一种工具。它会告诉你:
This site mentions drd
and also mentions their own tool called mutrace
which looks like the kind of tool you're after. It tells you:
- 互斥了多少次锁定
- 互斥线程拥有多少次修改
- 互斥了多少次争(已被锁定,当锁定请求被做了)
- 在期限不同的统计互斥被锁定
例如
mutrace: 10 most contended mutexes:
Mutex # Locked Changed Cont. tot.Time[ms] avg.Time[ms] max.Time[ms] Type
35 368268 407 275 120,822 0,000 0,894 normal
5 234645 100 21 86,855 0,000 0,494 normal
26 177324 47 4 98,610 0,001 0,150 normal
19 55758 53 2 23,931 0,000 0,092 normal
53 106 73 1 0,769 0,007 0,160 normal
25 15156 70 1 6,633 0,000 0,019 normal
4 973 10 1 4,376 0,004 0,174 normal
75 68 62 0 0,038 0,001 0,004 normal
9 1663 52 0 1,068 0,001 0,412 normal
3 136553 41 0 61,408 0,000 0,281 normal
... ... ... ... ... ... ... ...
mutrace: Total runtime 9678,142 ms.
这篇关于如何来分析在Linux Pthread互斥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!