Linux性能事件:cpu-clock和task-clock-有什么区别 [英] Linux perf events: cpu-clock and task-clock - what is the difference

查看:1444
本文介绍了Linux性能事件:cpu-clock和task-clock-有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux perf工具(以前称为perf_events)具有多个内置的通用软件事件.其中两个最基本的是:task-clockcpu_clock(内部称为PERF_COUNT_SW_CPU_CLOCKPERF_COUNT_SW_TASK_CLOCK).但是它们的问题在于缺乏描述.

Linux perf tools (some time ago named perf_events) has several builtin universal software events. Two most basic of them are: task-clock and cpu_clock (internally called PERF_COUNT_SW_CPU_CLOCK and PERF_COUNT_SW_TASK_CLOCK). But what is wrong with them is lack of description.

ysdx 用户报告 man perf_event_open 的简短说明:

ysdx user reports that man perf_event_open has short description:

    PERF_COUNT_SW_CPU_CLOCK
          This reports the CPU clock, a high-resolution per-
          CPU timer.

    PERF_COUNT_SW_TASK_CLOCK
          This reports a clock count specific to the task
          that is running.

但是描述很难理解.

有人可以给出有关如何以及何时解释task-clockcpu-clock事件的权威性答案吗?它们与linux内核调度程序有何关系?

Can somebody give authoritative answer about how and when the task-clock and cpu-clock events are accounted? How does they relate to the linux kernel scheduler?

何时task-clockcpu-clock将给出不同的值?我应该使用哪一个?

When task-clock and cpu-clock will give different values? Which one should I use?

推荐答案

1)默认情况下,perf stat显示task-clock,而不显示cpu-clock.因此,我们可以判断出task-clock预期会更加有用.

1) By default, perf stat shows task-clock, and does not show cpu-clock. Therefore we can tell task-clock was expected to be much more useful.

2)cpu-clock被简单地破坏了,并且多年未修复.最好忽略它.

2) cpu-clock was simply broken, and has not been fixed for many years. It is best to ignore it.

预期 sleep 1中的cpu-clock将显示约1秒.相反,task-clock将显示接近零.使用cpu-clock读取挂钟时间会很有意义.然后,您可以查看cpu-clocktask-clock之间的比率.

It was intended that cpu-clock of sleep 1 would show about 1 second. In contrast, task-clock would show close to zero. It would have made sense to use cpu-clock to read wall clock time. You could then look at the ratio between cpu-clock and task-clock.

但是在当前实现中,cpu-clock等效于task-clock.甚至有可能修复"现有计数器可能会破坏某些用户空间程序.如果有这样的程序,Linux可能无法修复"此计数器. Linux可能需要定义一个新的计数器.

But in the current implementation, cpu-clock is equivalent to task-clock. It is even possible that "fixing" the existing counter might break some userspace program. If there is such a program, Linux might not be able to "fix" this counter. Linux might need to define a new counter instead.

异常:在对CPU进行性能分析时,从v4.7-rc1开始或CPU-与特定任务相反-例如perf stat -a. perf stat -a显示cpu-clock而不是task-clock.在这种特定情况下,预期这两个计数器是等效的.在这种情况下,cpu-clock的初衷更为合理.因此,对于perf stat -a,您可以忽略此差异,并将其解释为task-clock.

Exception: starting with v4.7-rc1, when profiling a CPU or CPUs - as opposed to a specific task - e.g. perf stat -a. perf stat -a shows cpu-clock instead of task-clock. In this specific case, the two counters were intended to be equivalent. The original intention for cpu-clock makes more sense in this case. So for perf stat -a, you could just ignore this difference, and interpret it as task-clock.

如果您编写自己的代码来配置一个或多个CPU(而不是特定任务),那么遵循perf stat -a的实现也许是最清晰的.但是您可以链接到这个问题,以解释您的代码在做什么:-).

If you write your own code which profiles a CPU or CPUs - as opposed to a specific task - perhaps it would be clearest to follow the implementation of perf stat -a. But you might link to this question, to explain what your code is doing :-).

主题:回复:perf:有关perf软件事件的一些问题
来自:Peter Zijlstra

Subject: Re: perf: some questions about perf software events
From: Peter Zijlstra

Frank Bui-Huu在2010年11月27日星期六14:28 +0100写道:

On Sat, 2010-11-27 at 14:28 +0100, Franck Bui-Huu wrote:

Peter Zijlstra写道:

Peter Zijlstra writes:

Franck Bui-Huu在2010年11月24日星期三12:35 +0100写道:

On Wed, 2010-11-24 at 12:35 +0100, Franck Bui-Huu wrote:

[...]

我目前还没有看到cpu-clock和 任务时钟事件.他们俩似乎都在计算 任务正在CPU上运行.我错了吗?

Also I'm currently not seeing any real differences between cpu-clock and task-clock events. They both seem to count the time elapsed when the task is running on a CPU. Am I wrong ?

不,弗朗西斯已经注意到了,当我添加 多pmu的东西,在我的待办事项清单上可以查看(弗朗西斯也递给了我 一点补丁),但我一直对其他东西不感兴趣:/

No, Francis already noticed that, I probably wrecked it when I added the multi-pmu stuff, its on my todo list to look at (Francis also handed me a little patchlet), but I keep getting distracted with other stuff :/

好.

调整两者的期限是否有意义?

Does it make sense to adjust the period for both of them ?

此外,在创建任务时钟事件时,将'pid = -1'传递给 sys_perf_event_open()确实没有意义,对吗?

Also, when creating a task clock event, passing 'pid=-1' to sys_perf_event_open() doesn't really make sense, does it ?

与cpu时钟和'pid = n'相同:无论值如何,事件度量 cpu墙上的时钟.

Same with cpu clock and 'pid=n': whatever value, the event measure the cpu wall time clock.

也许在API中仅提出一个时钟并将其内部绑定 时钟到CPU或任务时钟取决于pid或cpu参数 更好了吗?

Perhaps proposing only one clock in the API and internally bind this clock to the cpu or task clock depending on pid or cpu parameters would have been better ?

不,在任务上同时计算CPU和任务时钟实际上是有意义的 (CPU时钟基本上是墙上时间).

No, it actually makes sense to count both cpu and task clock on a task (cpu clock basically being wall-time).

从更表面上讲,cpu-clockperf stat输出可能与早于v4.7-rc1的perf中的task-clock输出略有不同.例如,它可能为task-clock打印已使用的CPU",而不为cpu-clock打印.

On a more superficial level, perf stat output for cpu-clock can be slightly different from that of task-clock in perf earlier than v4.7-rc1. For example, it may print "CPUs utilized" for task-clock but not for cpu-clock.

这篇关于Linux性能事件:cpu-clock和task-clock-有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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