如何减少linux c应用程序中的CPU使用(分离的多线程)?
我急切地想知道,在检查由我编写的要处理的顶级信息时,哪种情况会导致cpu使用率增加 下面是我的环境如何减少linux c应用程序中的CPU使用(分离的多线程)?,c,linux,cpu-usage,C,Linux,Cpu Usage,我急切地想知道,在检查由我编写的要处理的顶级信息时,哪种情况会导致cpu使用率增加 下面是我的环境 # cat /proc/cpuinfo system type : CN3010_EVB_HS5 (CN5010p1.1-500-SCP) processor : 0 cpu model : Cavium Octeon+ V0.1 BogoMIPS : 1000.00 wait inst
# cat /proc/cpuinfo
system type : CN3010_EVB_HS5 (CN5010p1.1-500-SCP)
processor : 0
cpu model : Cavium Octeon+ V0.1
BogoMIPS : 1000.00
wait instruction : yes
microsecond timers : yes
tlb_entries : 64
extra interrupt vector : yes
hardware watchpoint : yes, count: 2, address/irw mask: [0x0ffc, 0x0ffb]
ASEs implemented :
shadow register sets : 1
kscratch registers : 0
core : 0
VCED exceptions : not available
VCEI exceptions : not available
# cat /proc/softirqs
CPU0
HI: 0
TIMER: 37673
NET_TX: 1
NET_RX: 63481
BLOCK: 0
BLOCK_IOPOLL: 0
TASKLET: 241456
SCHED: 0
HRTIMER: 0
RCU: 45060
#
# cat /proc/stat
cpu 6890 0 7591 11217 324 691 17637 0 0
cpu0 6890 0 7591 11217 324 691 17637 0 0
intr 3872174 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3557213 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30852 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2530 0 6328 275165 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 88 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ctxt 7152106
btime 1387517330
processes 1956
procs_running 2
procs_blocked 0
softirq 454085 0 44350 1 74147 0 0 282595 0 0 52992
**Cpu(s): 20.6%us, 23.0%sy, 0.0%ni, 15.0%id, 0.0%wa, 2.2%hi, 39.3%si, 0.0%st**
Mem: 45220K used, 50560K free, 0K shrd, 0K buff, 17568K cached
Load average: 0.52 0.72 0.52
PID USER STATUS RSS PPID %CPU %MEM COMMAND
800 root S 5076 1 75.3 5.2 core
2104 root S 2448 848 0.0 2.5 sshd
....
-->核心是我的进程(使用多线程),它有大约22个线程来执行作业。
很快,一个线程收集无线数据包,一个线程使用netlink库更改wifi频率。我不确定,但我认为这会增加cpu使用率
我不知道如何控制这种情况,如何接近,
我要检查哪一部分
下面是我的线程样式
while(1) {
do jobs;
sleep(x);
}
-->切换到
while (1) {
sleep(x);
do jobs;
}
无法解决它。如何处理这个问题?我要检查哪一部分
请帮帮我。我不想升级CPU。您通常会使用探查器来确定应用程序在哪里花费时间
较新的Linux内核内置了一个开销非常低的分析器,它还可以跟踪内核空间的进出,名为
perf
。您可以perf record
您的应用程序,然后运行perf report
查看它的功能。您似乎正在使用OCTEON+CN5010 cpu。作为一项高级性能改进任务,您可以利用OCTEONsimple exec程序(在Linux上,或在单独的内核上)进一步提高性能
Paxym或
perf top-p
您应该更多地解释应用程序实际在做什么。你为什么有22根线?你为什么不想使用CPU?很快,我的任务收集无线帧并分析它们。我想知道哪种情况会增加cpu使用率。我认为如果不估计CPU的使用率,这是不可能的。随机CPU使用率接近峰值(100%),我想知道如何跟踪这种情况,以及是什么原因造成的。