Chinese translated version of Documentation/accounting/delay-accounting.txt
If you have any comment or update to the content, please contact the
original document maintainer directly. However, if you have a problem
communicating in English you can also ask the Chinese maintainer for
help. Contact the Chinese maintainer if this translation is outdated
or if there is a problem with the translation.
Chinese maintainer: 林天智 <lintianzhi1992@gmail.com>
---------------------------------------------------------------------
Documentation/accounting/delay-accounting.txt的中文翻译
如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
译存在问题,请联系中文版维护者。
中文版维护者: 林天智 <lintianzhi1992@gmail.com>
以下为正文
---------------------------------------------------------------------
Delay accounting
----------------
延迟统计
=======
Tasks encounter delays in execution when they wait
for some kernel resource to become available e.g. a
runnable task may wait for a free CPU to run on.
当任务在执行的时候因为等待一些内核资源而有延迟的时候。比如,一个可运行的任务可能会等待CPU的空闲
The per-task delay accounting functionality measures
the delays experienced by a task while
当发生以下的情况的时候,平均任务等待时间被描述地很好:
a) waiting for a CPU (while being runnable)
b) completion of synchronous block I/O initiated by the task
c) swapping in pages
d) memory reclaim
a) 等CPU(当可运行的时候)
b) 等待I/O的完成
c) 交换页面
d) 重新分配内存
and makes these statistics available to userspace through
the taskstats interface.
并且让用户空间通过任务状态接口可以访问这些统计信息
Such delays provide feedback for setting a task's cpu priority,
io priority and rss limit values appropriately. Long delays for
important tasks could be a trigger for raising its corresponding priority.
这些延迟为设置一个任务的cpu优先级提供了反馈,io 优先和rss适当地限制了值。一些重要任务的长延迟可能会为提升它对应的权限作为一个触发器。
The functionality, through its use of the taskstats interface, also provides
delay statistics aggregated for all tasks (or threads) belonging to a
thread group (corresponding to a traditional Unix process). This is a commonly
needed aggregation that is more efficiently done by the kernel.
虽然函数用了任务状态接口,它也为所有任务(或线程)提供了属于它的线程组的聚合统计信息(对应于传统的Unix线程)。这是一个由内核来做会非常有效的一般性聚合需求。
Userspace utilities, particularly resource management applications, can also
aggregate delay statistics into arbitrary groups. To enable this, delay
statistics of a task are available both during its lifetime as well as on its
exit, ensuring continuous and complete monitoring can be done.
用户空间特性,特别是资源管理应用,可以聚合延迟统计信息到任意组。为了激活这个功能,一个任务的延迟统计在它的生命周期以及退出的时候必须是可用的,保证持续,完整的监控可以被完成。
接口
------
Delay accounting uses the taskstats interface which is described
in detail in a separate document in this directory. Taskstats returns a
generic data structure to userspace corresponding to per-pid and per-tgid
statistics. The delay accounting functionality populates specific fields of
this structure. See
include/linux/taskstats.h
延迟统计使用了任务状态接口(在这个目录下不同的文档已经详细描述)。任务状态给用户空间每个pid,每个tgid返回一个通用的统计信息的数据结构。延迟统计函数定义在这个文件:
include/linux/taskstats.h
for a description of the fields pertaining to delay accounting.
It will generally be in the form of counters returning the cumulative
delay seen for cpu, sync block I/O, swapin, memory reclaim etc.
这个数据结构会在累计cpu,I/O同步阻塞,数据换入,重新分配内存等延迟信息时使用到。
Taking the difference of two successive readings of a given
counter (say cpu_delay_total) for a task will give the delay
experienced by the task waiting for the corresponding resource
in that interval.
为了一个任务连续读两个给定的计数器,会给出在那个间隙内那个任务等待对于资源的延迟。
When a task exits, records containing the per-task statistics
are sent to userspace without requiring a command. If it is the last exiting
task of a thread group, the per-tgid statistics are also sent. More details
are given in the taskstats interface description.
当一个任务退出时,记录了包括每个任务的统计信息会发送到用户空间而不需要任何命令。如果这是在这个线程组中最后一个退出的任务,per-tgid统计信息也会被送出。更多的细节在任务状态接口中描述。
The getdelays.c userspace utility in this directory allows simple commands to
be run and the corresponding delay statistics to be displayed. It also serves
as an example of using the taskstats interface.
在这个目录下,getdelay.c 的用户空间功能允许执行简单的命令,对应的延迟统计会被列出来,同样可以作为使用任务状态接口的例子。
使用
-----
Compile the kernel with
CONFIG_TASK_DELAY_ACCT=y
CONFIG_TASKSTATS=y
用一下参数编译内核:
CONFIG_TASK_DELAY_ACCT=y
CONFIG_TASKSTATS=y
Delay accounting is enabled by default at boot up.
To disable, add
nodelayacct
to the kernel boot options. The rest of the instructions
below assume this has not been done.
延迟统计在启动的时候会默认开启
要禁止的话,增加
nodelayacct
作为内核启动选项,剩下的介绍假设这个参数并没有被加入。
After the system has booted up, use a utility
similar to getdelays.c to access the delays
seen by a given task or a task group (tgid).
The utility also allows a given command to be
executed and the corresponding delays to be
seen.
在内核启动之后,给定一个任务或者任务组,使用一个和getdeay.c相似的功能去访问延迟。对应的功能同样允许执行命令然后显示对应的延迟信息
General format of the getdelays command
getdelays命令的通用格式
getdelays [-t tgid] [-p pid] [-c cmd...]
Get delays, since system boot, for pid 10
# ./getdelays -p 10
(output similar to next case)
当系统启动时获取pid为10的延迟信息
# ./getdelays -p 10
(输出和下一个例子相似)
Get sum of delays, since system boot, for all pids with tgid 5
当系统启动时获取所有tgid为5的合计延迟,
# ./getdelays -t 5
CPU count real total virtual total delay total
7876 92005750 100000000 24001500
IO count delay total
0 0
SWAP count delay total
0 0
RECLAIM count delay total
0 0
Get delays seen in executing a given simple command
执行一个命令,并且获取它的延迟信息
# ./getdelays -c ls /
bin data1 data3 data5 dev home media opt root srv sys usr
boot data2 data4 data6 etc lib mnt proc sbin subdomain tmp var
CPU count real total virtual total delay total
6 4000250 4000000 0
IO count delay total
0 0
SWAP count delay total
0 0
RECLAIM count delay total
0 0