新石器Wiki

近年はシリコン(石)から進化した便利なもので溢れる時代。そんな気になった事や試した事など記す。

ユーザ用ツール

サイト用ツール


programing:linux-programing:linux-cpu-core-shield


差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
programing:linux-programing:linux-cpu-core-shield [2022/10/20 17:20] – [スクリプトによる IRQ への CPU アフィニティーの自動割り当て] yokoprograming:linux-programing:linux-cpu-core-shield [2022/10/25 13:09] (現在) – [CPU Affinityの一覧表示] yoko
行 73: 行 73:
 <code bash> <code bash>
 $ cat /proc/interrupts $ cat /proc/interrupts
 +            CPU0       CPU1       CPU2       CPU3
 +   0:         17          0          0          0  IR-IO-APIC    2-edge      timer
 +   6:          0          0          0          1  IR-IO-APIC    6-edge      ttyS2
 +   8:          0          0          1          0  IR-IO-APIC    8-edge      rtc0
 +   9:          0          5          0          0  IR-IO-APIC    9-fasteoi   acpi
 + ...
 </code> </code>
  
行 100: 行 106:
  
 my $infile = "/proc/interrupts"; my $infile = "/proc/interrupts";
-my $nicname = "enp3s0";                 # NICインタフェース名(デフォルト)+my $nicname = "enp3s0";                 # 検索するNICインタフェース名
 my $mode = 0;                           # 動作モード my $mode = 0;                           # 動作モード
  
行 109: 行 115:
     if ($ARGV[1] eq "set") {     if ($ARGV[1] eq "set") {
  $mode = 1;  $mode = 1;
 +    }
 +    if ($ARGV[1] eq "debug") {
 + $mode = 2;
     }     }
 } }
行 115: 行 124:
  
 while ( <IN> ) { while ( <IN> ) {
-  if ( $_ =~ /\b$nicname/ ) { +    if ( $_ =~ /\b$nicname/ ) { 
-    my @a = split(); + my @a = split(); 
-    $a[0] =~ s/:$//;                # 先頭ワードの末尾':'文字を削除+ $a[0] =~ s/:$//;                # IRQ番号、先頭ワードの末尾':'文字を削除
  
-    if ($mode == 1) {               # set ? + if ($mode == 0) { 
-      system("echo c > /proc/irq/$a[0]/smp_affinity"); # コア2,3+     print; 
 +
 + else { 
 +     if ($mode == 1) {           # set ? 
 + system("echo c > /proc/irq/$a[0]/smp_affinity"); # コア2,3 
 +     } 
 +     print "echo c > /proc/irq/$a[0]/smp_affinity\n"; 
 + }
     }     }
-    print "echo c > /proc/irq/$a[0]/smp_affinity\n"; 
-  } 
 } }
  
行 133: 行 147:
  
 <code bash> <code bash>
-$ sudo ./irq_shield.pl enp3s0 set+$ sudo ./irq_shield.pl enp1s0 set 
 +</code> 
 + 
 + 
 +その他 
 +----- 
 + 
 +### CPUに負荷をかける 
 +stressコマンドで、CPUのコア#2に演算負荷をかける。 
 + 
 +<code bash> 
 +$ taskset -c 2 stress -c 1 
 +</code> 
 + 
 +### CPU負荷状況の確認 
 +下記コマンドでCPUの負荷状況を表示。 
 + 
 +<code bash> 
 +$ dstat -c -C 0,1,2,3 
 +-----cpu0-usage----------cpu1-usage----------cpu2-usage----------cpu3-usage---- 
 +usr sys idl wai stl:usr sys idl wai stl:usr sys idl wai stl:usr sys idl wai stl 
 +  5    91     0:  7    90     0: 17    83     0:  0   0 100     0 
 + 11    83     0:  9    91     0: 99         0:  1    98     0 
 + 11    85     0:  8    92     0: 98         0:  0    99     0 
 +  9    86     0:  5    95     0: 99         0:  1    98     0 
 +  9    84     0:  8    91     0: 99         0:  0    98     0 
 + 14    81     0:  7    93     0:100         0:  0    99     0 
 + 12    83     0:  8    92     0: 99         0:  0    99     0 
 +  9    86     0:  4    95     0: 99         0:  0    98     0 
 + 14    80     0:  5    95     0: 98         0:  2    98     0 
 + 10    85     0:  6    94     0:100         0:  0    99     0 
 + 10    83     0:  4    96     0:100         0:  0   0 100     0 
 +</code> 
 +### CPU Affinityの一覧表示 
 +全プロセスのCPU Affinityを一覧表示するPerlスクリプト。 
 + 
 +<code perl cpu_pslist.pl> 
 +#!/usr/bin/perl 
 +
 +# CPU affinityの一覧を表示する。 
 +
 + 
 +use strict; 
 +use warnings; 
 + 
 +my @result; 
 +my $mode = 0; 
 + 
 +if (@ARGV >= 1) { 
 +    if ($ARGV[0] eq "tree") { 
 + $mode = 1; 
 +    } 
 +
 + 
 +if ($mode == 0) { 
 +    @result = `ps aux`; 
 +
 +else { 
 +    @result = `ps auxf`; 
 +
 + 
 +foreach my $line(@result) 
 +
 +    my @a = split(/\s+/, $line); # 複数の空白や改行でで分割 
 + 
 +    if ($a[1] eq "PID") { 
 + print "AFFIN " . $line; 
 +    } 
 +    else { 
 + my $affi = `taskset -pc $a[1] 2>&1`; # エラー出力は標準へ 
 + if ($? == 0) { # コマンド実行のリターンコード 
 +     my @b = split(/\s+/, $affi); # 複数の空白や改行で分割 
 +     my $str = sprintf("%-6s", $b[$#b]); # CPU affinity 
 +     print $str . $line; 
 +
 +    } 
 +}
 </code> </code>
  
行 154: 行 244:
 13. [[https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/assembly_configuring-cpu-affinity-and-numa-policies-using-systemd_managing-monitoring-and-updating-the-kernel|第28章 systemd を使用した CPU のアフィニティーおよび NUMA ポリシーの設定]] 13. [[https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/assembly_configuring-cpu-affinity-and-numa-policies-using-systemd_managing-monitoring-and-updating-the-kernel|第28章 systemd を使用した CPU のアフィニティーおよび NUMA ポリシーの設定]]
 14. [[https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/performance_tuning_guide/sect-red_hat_enterprise_linux-performance_tuning_guide-tuning_scheduling_policy-isolating_cpus|6.3.6.2. CPU の分離]] 14. [[https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/performance_tuning_guide/sect-red_hat_enterprise_linux-performance_tuning_guide-tuning_scheduling_policy-isolating_cpus|6.3.6.2. CPU の分離]]
-15. {{https://www.concurrent-rt.co.jp/external/TechSup/PDF/RedHawkLinux_UsersGuide8.2_Jpn.pdf}}+15. [[https://blog.amedama.jp/entry/stress-command|stress コマンドを使ってマシンに負荷をかける]] 
 +16. {{https://www.concurrent-rt.co.jp/external/TechSup/PDF/RedHawkLinux_UsersGuide8.2_Jpn.pdf}}
  
  
  
programing/linux-programing/linux-cpu-core-shield.1666254021.txt.gz · 最終更新: 2022/10/20 17:20 by yoko