自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

使用Trace-Event解決系統(tǒng)不能深度睡眠的問(wèn)題

運(yùn)維 系統(tǒng)運(yùn)維
最近遇到一個(gè)問(wèn)題,系統(tǒng)不能睡眠到c7s, 只能睡眠到c3. (c-state不能到c7s, cpu的c-state, c0是運(yùn)行態(tài),其它狀態(tài)都是idle態(tài),睡眠的越深,c-state的值越大)。

[[374918]]

本文轉(zhuǎn)載自微信公眾號(hào)「相遇Linux」,作者JeffXie。轉(zhuǎn)載本文請(qǐng)聯(lián)系相遇Linux公眾號(hào)。  

最近遇到一個(gè)問(wèn)題,系統(tǒng)不能睡眠到c7s, 只能睡眠到c3. (c-state不能到c7s, cpu的c-state, c0是運(yùn)行態(tài),其它狀態(tài)都是idle態(tài),睡眠的越深,c-state的值越大)

 

這時(shí)候第一感覺(jué)是不是系統(tǒng)很忙導(dǎo)致, 使用pert top看一下耗cpu的進(jìn)程和熱點(diǎn)函數(shù):

  1. perf top -E 100 --stdio > perf-top.txt 
  2.  
  3.     19.85%  perf                  [.] __symbols__insert 
  4.      7.68%  perf                  [.] rb_next 
  5.      4.60%  libc-2.26.so          [.] __strcmp_sse2_unaligned 
  6.      4.20%  libelf-0.168.so       [.] gelf_getsym 
  7.      3.92%  perf                  [.] dso__load_sym 
  8.      3.86%  libc-2.26.so          [.] _int_malloc 
  9.      3.60%  libc-2.26.so          [.] __libc_calloc 
  10.      3.30%  libc-2.26.so          [.] vfprintf 
  11.      2.95%  perf                  [.] rb_insert_color 
  12.      2.61%  [kernel]              [k] prepare_exit_to_usermode 
  13.      2.51%  perf                  [.] machine__map_x86_64_entry_trampolines 
  14.      2.31%  perf                  [.] symbol__new 
  15.      2.22%  [kernel]              [k] do_syscall_64 
  16.      2.11%  libc-2.26.so          [.] __strlen_avx2 

發(fā)現(xiàn)系統(tǒng)中只有perf工具本身比較耗cpu :(

然后就想到是不是系統(tǒng)中某個(gè)進(jìn)程搞的鬼,不讓cpu睡眠到c7s. 這時(shí)候使用trace event監(jiān)控一下系統(tǒng)中sched_switch事件. 使用trace-cmd工具監(jiān)控所有cpu上的sched_switch(進(jìn)程切換)事件30秒:

  1. #trace-cmd record -e sched:sched_switch -M -1 sleep 30 
  2.  
  3. CPU0 data recorded at offset=0x63e000 
  4.     102400 bytes in size 
  5. CPU1 data recorded at offset=0x657000 
  6.     8192 bytes in size 
  7. CPU2 data recorded at offset=0x659000 
  8.     20480 bytes in size 
  9. CPU3 data recorded at offset=0x65e000 
  10.     20480 bytes in size 

使用trace-cmd report 查看一下監(jiān)控結(jié)果,但是查看這樣的原始數(shù)據(jù)不夠直觀,沒(méi)有某個(gè)進(jìn)程被切換到的統(tǒng)計(jì)信息:

  1. #trace-cmd report 
  2.  
  3. cpus=4 
  4.        trace-cmd-19794 [001] 225127.464466: sched_switch:         trace-cmd:19794 [120] S ==> swapper/1:0 [120] 
  5.        trace-cmd-19795 [003] 225127.464601: sched_switch:         trace-cmd:19795 [120] S ==> swapper/3:0 [120] 
  6.            sleep-19796 [002] 225127.464792: sched_switch:         sleep:19796 [120] S ==> swapper/2:0 [120] 
  7.           <idle>-0     [003] 225127.471948: sched_switch:         swapper/3:0 [120] R ==> rcu_sched:11 [120] 
  8.        rcu_sched-11    [003] 225127.471950: sched_switch:         rcu_sched:11 [120] W ==> swapper/3:0 [120] 
  9.           <idle>-0     [003] 225127.479959: sched_switch:         swapper/3:0 [120] R ==> rcu_sched:11 [120] 
  10.        rcu_sched-11    [003] 225127.479960: sched_switch:         rcu_sched:11 [120] W ==> swapper/3:0 [120] 
  11.           <idle>-0     [003] 225127.487959: sched_switch:         swapper/3:0 [120] R ==> rcu_sched:11 [120] 
  12.        rcu_sched-11    [003] 225127.487961: sched_switch:         rcu_sched:11 [120] W ==> swapper/3:0 [120] 
  13.           <idle>-0     [002] 225127.491959: sched_switch:         swapper/2:0 [120] R ==> kworker/2:2:19735 [120] 
  14.      kworker/2:2-19735 [002] 225127.491972: sched_switch:         kworker/2:2:19735 [120] W ==> swapper/2:0 [120] 

trace-cmd report 的結(jié)果使用正則表達(dá)式過(guò)濾一下,然后排序統(tǒng)計(jì):

  1. trace-cmd report | grep -o '==> [^ ]\+:\?' | sort | uniq -c 
  2.       3 ==> irqbalance:1034 
  3.       3 ==> khugepaged:43 
  4.      20 ==> ksoftirqd/0:10 
  5.       1 ==> ksoftirqd/1:18 
  6.      18 ==> ksoftirqd/3:30 
  7.       1 ==> kthreadd:19798 
  8.       1 ==> kthreadd:2 
  9.       4 ==> kworker/0:0:19785 
  10.       1 ==> kworker/0:1:19736 
  11.       5 ==> kworker/0:1:19798 
  12.       5 ==> kworker/0:1H:364 
  13.      53 ==> kworker/0:2:19614 
  14.      19 ==> kworker/1:1:7665 
  15.      30 ==> tuned:19498 
  16.      ...           

發(fā)現(xiàn)可疑線程tuned,30秒內(nèi)被切換到運(yùn)行了30次,其它線程都是常規(guī)線程。

此時(shí)查看一下系統(tǒng)中是否開(kāi)啟了tuned服務(wù):

 

果真是系統(tǒng)開(kāi)啟了tuned服務(wù),然后拉起了名字為tuned的線程.

查看一下tuned服務(wù)的配置文件:

  1. localhost:/home/jeff # tuned-adm active  
  2. Current active profile: sap-hana 
  3. localhost:/home/jeff # cat /usr/lib/tuned/sap-hana/tuned.conf  
  4. [main] 
  5. summary=Optimize for SAP NetWeaver, SAP HANA and HANA based products 
  6. [cpu] 
  7. force_latency = 70 

發(fā)現(xiàn)關(guān)于cpu這一項(xiàng),設(shè)置強(qiáng)制延遲時(shí)間為70秒 force_latency = 70 ,這個(gè)是為了優(yōu)化HANA數(shù)據(jù)庫(kù)。

到底force_latency怎樣起作用,經(jīng)過(guò)一頓搜索,發(fā)現(xiàn)這個(gè)值是被設(shè)置進(jìn)了/dev/cpu_dma_latency

使用lsof /dev/cpu_dma_latency, 發(fā)現(xiàn)tuned線程確實(shí)是在操作這個(gè)文件

  1. #lsof /dev/cpu_dma_latency 
  2. COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF  NODE NAME 
  3. tuned   18734 root    9w   CHR  10,60      0t0 11400 /dev/cpu_dma_latency 

而且Linux內(nèi)核文檔也說(shuō)明了/dev/cpu_dma_latency文件,如果要對(duì)它進(jìn)行寫操作,要open之后寫數(shù)據(jù)之后不close,如果釋放掉了文件描述符它就又會(huì)恢復(fù)到默認(rèn)值,這也印證了上面lsof /dev/cpu_dma_latency是有輸出結(jié)果的.

  1. https://github.com/torvalds/linux/blob/v5.8/Documentation/trace/coresight/coresight-cpu-debug.rst 
  2. As specified in the PM QoS documentation the requested parameter  
  3. will stay in effect until the file descriptor is released. For example: 
  4. exec 3<> /dev/cpu_dma_latency; echo 0 >&3 
  5. ... 
  6. Do some work... 
  7. ... 
  8. exec 3<>- 

查看一下/dev/cpu_dma_latency文件的內(nèi)容,確實(shí)是70,也就是(force_latency = 70)

  1. localhost:/home/jeff # cat /dev/cpu_dma_latency | hexdump -Cv  
  2. 00000000  46 00 00 00                                       |F...| 
  3. localhost:/home/jeff # echo $((0x46)) 
  4. 70 

此時(shí)查看一下系統(tǒng)中cpu各個(gè)睡眠態(tài)的描述和延遲時(shí)間值:

  1. # cd /sys/devices/system/cpu/cpu0/cpuidle/ 
  2. for state in * ; do 
  3. echo -e \ 
  4. "STATE: $state\t\ 
  5. DESC: $(cat $state/desc)\t\ 
  6. NAME: $(cat $state/name)\t\ 
  7. LATENCY: $(cat $state/latency)\t\ 
  8. RESIDENCY: $(cat $state/residency)" 
  9. done 

發(fā)現(xiàn)C3態(tài)的延遲時(shí)間是33微秒,C4的延時(shí)時(shí)間是133微秒,所以(force_latency = 70) ,

系統(tǒng)就只能睡眠到C3了 .(延遲時(shí)間就是從此睡眠態(tài)喚醒到運(yùn)行態(tài)的時(shí)間)

  1. STATE: state0    DESC: CPUIDLE CORE POLL IDLE    NAME: POLL  LATENCY: 0  RESIDENCY: 0 
  2. STATE: state1    DESC: MWAIT 0x00    NAME: C1    LATENCY: 2  RESIDENCY: 2 
  3. STATE: state2    DESC: MWAIT 0x01    NAME: C1E   LATENCY: 10 RESIDENCY: 20 
  4. STATE: state3    DESC: MWAIT 0x10    NAME: C3    LATENCY: 33 RESIDENCY: 100 
  5. STATE: state4    DESC: MWAIT 0x20    NAME: C6    LATENCY: 133    RESIDENCY: 400 
  6. STATE: state5    DESC: MWAIT 0x32    NAME: C7s   LATENCY: 166    RESIDENCY: 500 

此時(shí)關(guān)閉tuned 服務(wù), 再查看一下 /dev/cpu_dma_latency的值,變成了默認(rèn)的2000秒

  1. localhost:/home/jeff # tuned-adm off 
  2. localhost:/home/jeff # cat /dev/cpu_dma_latency | hexdump -Cv  
  3. 00000000  00 94 35 77                                       |..5w| 
  4. localhost:/home/jeff # echo $((0x77359400)) 
  5. 2000000000 

然后驗(yàn)證一下,此時(shí)系統(tǒng)可以睡眠到C7s了,此問(wèn)題得到解決 :)

 

解決此問(wèn)題,主要用到了Linux內(nèi)核本身提供的trace-event.

所以任何一個(gè)功能都不能小看,內(nèi)核就是這樣,一般看上去很無(wú)聊的功能,被一些工程師用很認(rèn)真的態(tài)度打磨出來(lái)之后,潛力還是非常大的:)

 

責(zé)任編輯:武曉燕 來(lái)源: 相遇Linux
相關(guān)推薦

2022-03-13 08:48:12

inspectorNode.js開(kāi)發(fā)

2022-05-04 10:22:39

Nodejs異步模式

2010-04-30 11:10:32

Oracle Sql

2024-12-05 09:06:58

2011-08-22 14:42:40

iPhone網(wǎng)絡(luò)

2018-01-16 10:38:03

Plesk面板Nginx

2018-09-04 08:00:00

人工智能深度學(xué)習(xí)神經(jīng)網(wǎng)絡(luò)

2017-09-28 10:40:10

深度學(xué)習(xí)多體問(wèn)題多代理系統(tǒng)

2017-09-23 22:07:24

深度學(xué)習(xí)N 體問(wèn)題GAN

2009-07-29 14:12:45

ASP.NET tra

2010-01-06 10:56:36

cisco 2950交

2010-02-02 16:52:42

Linux chrom

2011-05-06 15:56:38

打印機(jī)故障

2012-10-15 18:01:39

打印機(jī)打印機(jī)不能打印

2024-12-26 09:20:51

2012-04-25 08:59:04

云計(jì)算

2009-06-12 09:00:15

Linux域名訪問(wèn)

2011-08-10 13:53:05

windows7睡眠休眠

2009-07-22 13:32:24

JDBC SQL

2017-02-06 14:12:57

機(jī)器停車使用
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)