新石器Wiki

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

ユーザ用ツール

サイト用ツール


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


差分

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

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
programing:linux-programing:linux-cpu-core-shield [2022/10/20 17:23] – [スクリプトによる IRQ への CPU アフィニティーの自動割り当て] yokoprograming:linux-programing:linux-cpu-core-shield [2026/07/28 13:16] (現在) – 外部編集 127.0.0.1
行 1: 行 1:
-【Ubuntu/Linux】CPUコアのシールド分離 +====== 【Ubuntu/Linux】CPUコアのシールド分離 ======
-==============================+
 リアルタイム性が要求されるネットワーク通信を含むプログラムなど、さまざまなイベントに応答する際にレイテンシーを最小限に抑える必要がある。 リアルタイム性が要求されるネットワーク通信を含むプログラムなど、さまざまなイベントに応答する際にレイテンシーを最小限に抑える必要がある。
 これを行う為に、割り込み (IRQ) とさまざまな CPU 上のユーザープロセスを相互に分離する手法について備忘録を残す。 これを行う為に、割り込み (IRQ) とさまざまな CPU 上のユーザープロセスを相互に分離する手法について備忘録を残す。
行 9: 行 8:
  
  
-プロセスのCPUコア分離 +===== プロセスのCPUコア分離 =====
------------------+
 リアルタイム性が必要なユーザプログラム(プロセス)を実行するCPUコアを分離する。 リアルタイム性が必要なユーザプログラム(プロセス)を実行するCPUコアを分離する。
 ### コア除外の設定 ### コア除外の設定
行 54: 行 52:
 </code> </code>
  
-割り込みのCPUコア固定 +===== 割り込みのCPUコア固定 =====
------------------+
 上記でコア分離したプロセスが使用するNICカードの割り込みを、分離したコア側に割り当てる。 上記でコア分離したプロセスが使用するNICカードの割り込みを、分離したコア側に割り当てる。
  
行 73: 行 70:
 <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>
  
行 109: 行 112:
     if ($ARGV[1] eq "set") {     if ($ARGV[1] eq "set") {
  $mode = 1;  $mode = 1;
 +    }
 +    if ($ARGV[1] eq "debug") {
 + $mode = 2;
     }     }
 } }
行 115: 行 121:
  
 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: 行 144:
  
 <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>
  
  
-参考 +===== 参考 =====
-----+
  
-1. [[https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux_for_real_time/8/html/optimizing_rhel_8_for_real_time_for_low_latency_operation/assembly_binding-interrupts-and-processes_optimizing-rhel8-for-real-time-for-low-latency-operation#doc-wrapper|第12章 割り込みとユーザープロセスを分離してシステムレイテンシーを最小限に抑える]] +  - [[https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux_for_real_time/8/html/optimizing_rhel_8_for_real_time_for_low_latency_operation/assembly_binding-interrupts-and-processes_optimizing-rhel8-for-real-time-for-low-latency-operation#doc-wrapper|第12章 割り込みとユーザープロセスを分離してシステムレイテンシーを最小限に抑える]] 
-2. [[https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux_for_real_time/7/html/tuning_guide/interrupt_and_process_binding|2.4. 割り込みおよびプロセスバインディング]] +  [[https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux_for_real_time/7/html/tuning_guide/interrupt_and_process_binding|2.4. 割り込みおよびプロセスバインディング]] 
-3. [[https://docs.oracle.com/cd/E26853_01/coh.371/b71688/tune_perftune.htm|6 パフォーマンス・チューニング]] +  [[https://docs.oracle.com/cd/E26853_01/coh.371/b71688/tune_perftune.htm|6 パフォーマンス・チューニング]] 
-4. [[https://www.slideshare.net/syuu1228/interrupt-affinity|Interrupt Affinityについて]] +  [[https://www.slideshare.net/syuu1228/interrupt-affinity|Interrupt Affinityについて]] 
-5. [[https://web.mit.edu/rhel-doc/4/RH-DOCS/rhel-rg-ja-4/s1-proc-directories.html|5.3. /proc/配下のディレクトリ]] +  [[https://web.mit.edu/rhel-doc/4/RH-DOCS/rhel-rg-ja-4/s1-proc-directories.html|5.3. /proc/配下のディレクトリ]] 
-6. [[https://qiita.com/knakahara/items/825d2f052b07c0a2599e|irqbalance を NetBSD に移植してみる]] +  [[https://qiita.com/knakahara/items/825d2f052b07c0a2599e|irqbalance を NetBSD に移植してみる]] 
-7. [[https://rheb.hatenablog.com/entry/nfv_tuning|レッドハットが考えるNFV環境向けのチューニング]] +  [[https://rheb.hatenablog.com/entry/nfv_tuning|レッドハットが考えるNFV環境向けのチューニング]] 
-8. [[https://www.web-dev-qa-db-ja.com/ja/linux/isolcpusがアクティブ化されているかどうかを検出する方法/962607069/|isolcpusがアクティブ化されているかどうかを検出する方法]] +  [[https://www.web-dev-qa-db-ja.com/ja/linux/isolcpusがアクティブ化されているかどうかを検出する方法/962607069/|isolcpusがアクティブ化されているかどうかを検出する方法]] 
-9. [[https://qiita.com/nakat-t/items/4542e84c4b72b78740e8|プロセス・スレッドを特定のCPUコアでのみ動作させる方法]] +  [[https://qiita.com/nakat-t/items/4542e84c4b72b78740e8|プロセス・スレッドを特定のCPUコアでのみ動作させる方法]] 
-10. [[https://www.rcannings.com/systemd-core-isolation/|SYSTEMD CORE ISOLATION]] +  [[https://www.rcannings.com/systemd-core-isolation/|SYSTEMD CORE ISOLATION]] 
-11. [[https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/6/html/performance_tuning_guide/sect-red_hat_enterprise_linux-performance_tuning_guide-tool_reference-irqbalance|3.4. irqbalance]] +  [[https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/6/html/performance_tuning_guide/sect-red_hat_enterprise_linux-performance_tuning_guide-tool_reference-irqbalance|3.4. irqbalance]] 
-12. [[https://qiita.com/gyaneman/items/f77c2633a5ac92f05302|プロセス・スレッドにCPUアフィニティを設定する方法]] +  [[https://qiita.com/gyaneman/items/f77c2633a5ac92f05302|プロセス・スレッドにCPUアフィニティを設定する方法]] 
-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 ポリシーの設定]] +  [[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 の分離]] +  [[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}}+  - [[https://blog.amedama.jp/entry/stress-command|stress コマンドを使ってマシンに負荷をかける]] 
 +  - {{https://www.concurrent-rt.co.jp/external/TechSup/PDF/RedHawkLinux_UsersGuide8.2_Jpn.pdf}}
  
  
  
programing/linux-programing/linux-cpu-core-shield.1666254233.txt.gz · 最終更新: by yoko