將進程綁定到特定的cpu - taskset命令

在測試鬥地主程序的時候,發現單核cpu的運行時間總比多核cpu運行時間塊,用taskset命令一看,果然是一個進程運行在兩個cpu上。

   Score of team 1 is : -1154
   Score of team 2 is : 148
   Score of team 3 is : 1006

   real 4m12.768s
   user 0m12.307s
   sys      0m2.703s

  [root@ying ~]# ps -aux | grep dou
  root     30958 18.0  0.4  15508  4112 pts/0    S+   09:14   0:00 ./doudizhu_platform
  root     30960  0.0  0.0   9028   660 pts/1    R+   09:14   0:00 grep --color=auto dou
  [root@ying ~]# taskset -p 30958
  pid 30958's current affinity mask: 1
 Score of team 1 is : -1100
 Score of team 2 is : 568
 Score of team 3 is : 532


  real      6m41.709s
  user  0m7.428s
  sys   0m2.776s

root@10.63.93.13:~# ps -aux | grep dou
root      2314  2.5  0.9 177940 161356 pts/1   S+   09:06   0:09 ./doudizhu_platform
root     26076  0.0  0.0  12180   704 pts/2    S+   09:13   0:00 grep --color=auto dou
root@10.63.93.13:~# taskset -p 2314
pid 2314's current affinity mask: ff
root@10.63.93.13:~# taskset -p 2314
pid 2314's current affinity mask: ff

最後在將一個進程固定到cpu上貌似沒啥效果,麼有找到原因。不知道和單核機器和多核機器的gcc版本有沒有關係


Score of team 1 is : -182   
Score of team 2 is : 97
Score of team 3 is : 85

real        6m44.039s
user    0m7.668s
sys     0m2.568s

root@10.63.93.13:~# ps -aux | grep dou
root     16842  2.3  0.0  19628  2988 pts/1    S+   09:29   0:00 ./doudizhu_platform
root     22093  0.0  0.0  12176   704 pts/2    S+   09:29   0:00 grep --color=auto dou
root@10.63.93.13:~# taskset -pc 0 16842
pid 16842's current affinity list: 0-7
pid 16842's new affinity list: 0
root@10.63.93.13:~# taskset -p 16842
pid 16842's current affinity mask: 1

但是嘗試了一個很有意思的,將一個進程直接全部放在CPU 1, 結果泥煤的爆炸了

cpu1快爆了,不過cpu0倒是降下來一點

這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章