Linux で特定の CPU 機能が利用可能かどうかを確認する方法

LinuxLinuxBeginner
今すぐ練習

💡 このチュートリアルは英語版からAIによって翻訳されています。原文を確認するには、 ここをクリックしてください

はじめに

この実験では、Linux システムで利用可能な特定の CPU 機能を確認する方法を学びます。最初に基本的な cat /proc/cpuinfo コマンドを使って詳細な CPU 仕様とフラグを表示し、CPU 情報を調べるさまざまな方法を探索します。

最初の調査の後、lscpu コマンドを使用して、CPU アーキテクチャと機能のより体系的な概要を把握します。最後に、dmidecode を使用してハードウェアの詳細を調べ、CPU 情報を含むシステムのコンポーネントについてさらに深く理解します。


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/UserandGroupManagementGroup(["User and Group Management"]) linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/UserandGroupManagementGroup -.-> linux/sudo("Privilege Granting") subgraph Lab Skills linux/cat -.-> lab-558803{{"Linux で特定の CPU 機能が利用可能かどうかを確認する方法"}} linux/sudo -.-> lab-558803{{"Linux で特定の CPU 機能が利用可能かどうかを確認する方法"}} end

cat /proc/cpuinfo で CPU 機能を一覧表示する

このステップでは、cat コマンドと /proc/cpuinfo ファイルを使用して、Linux システムの CPU 情報を調べる方法を学びます。

/proc ファイルシステムは、Linux の仮想ファイルシステムで、プロセスに関する情報やその他のシステム情報を提供します。/proc/cpuinfo ファイルには、システムにインストールされている CPU の詳細が含まれています。

cat コマンドは、ファイルの内容を表示するために使用される基本的な Linux ユーティリティです。

ターミナルが開いていない場合は、開きます。デスクトップの左側にある Xfce Terminal アイコンをクリックすることで、これを行うことができます。

次に、以下のコマンドを入力して、/proc/cpuinfo ファイルの内容を表示します。

cat /proc/cpuinfo

Enter キーを押します。

大量の出力が表示され、CPU のさまざまな側面が詳細に示されます。出力は次のようになります(出力の一部は簡潔さと汎用性のために省略されています)。

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 158
model name      : Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
stepping        : 9
microcode       : 0x...
cpu MHz         : ...
cache size      : ... KB
physical id     : 0
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : ...
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase bmi1 hle avx2 smep bmi2 erms rtm invpcid mpx rdseed adx smap clflushopt xsaves xsaveopt pcpe bts md_clear flush_l1d arch_capabilities
bugs            : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds mmio_stale_data retbleed
bogomips        : ...
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
...

このファイルは、各 CPU コアに関する詳細情報を提供します。これには、ベンダー、モデル名、速度、キャッシュサイズ、およびサポートされている機能(flags の下にリストされています)が含まれます。

/proc/cpuinfo の出力を理解することは、トラブルシューティングやシステムのハードウェアの機能を理解するのに役立ちます。

Continue をクリックして次のステップに進みます。

lscpu で機能を確認する

前のステップでは、cat /proc/cpuinfo を使用して詳細な CPU 情報を表示しました。/proc/cpuinfo は情報が充実していますが、出力が非常に長く、時には迅速に解析するのが難しい場合があります。

CPU アーキテクチャ情報の概要を取得するための、より使いやすいコマンドは lscpu です。lscpu コマンドは /proc/cpuinfo から CPU アーキテクチャ情報を収集し、整形された人間が読みやすい形式で表示します。

lscpu コマンドを使用して、CPU の概要を取得しましょう。

ターミナルに以下のコマンドを入力します。

lscpu

Enter キーを押します。

CPU のアーキテクチャの簡潔な概要が表示されます。出力は次のようになります。

Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         39 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  1
  On-line CPU(s) list:   0
Vendor ID:               GenuineIntel
  Model name:            Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase bmi1 hle avx2 smep bmi2 erms rtm invpcid mpx rdseed adx smap clflushopt xsaves xsaveopt pcpe bts md_clear flush_l1d arch_capabilities
L1d cache:               32K
L1i cache:               32K
L2 cache:                256K
L3 cache:                6M
NUMA node(s):            1
  NUMA node0 CPU(s):     0
Vulnerability Itlb multihit:  KVM: Mitigation: VMX disabled
Vulnerability L1tf:      Mitigation: PTE Inversion; VMX conditional cache flushes, SMT disabled
Vulnerability Mds:       Mitigation: Clear CPU buffers; SMT disabled
Vulnerability Meltdown:  Mitigation: PTI
Vulnerability Mmio stale data: Mitigation: Clear CPU buffers; SMT disabled
Vulnerability Retbleed:  Mitigation: IBPB conditional, IBRS_FW, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Spec store bypass: Mitigation: Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:  Mitigation: Invalidate IBPB conditional, INDIR branch predictor by IBPB_FW, STIBP disabled
Vulnerability Spectre v2:  Mitigation: IBPB conditional, IBRS_FW, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:     Mitigation: Microcode
Vulnerability Tsx async abort: Not affected

lscpu が情報を構造化された形式で表示していることに注目してください。これにより、アーキテクチャ、CPU オペレーションモード、ベンダー ID、モデル名、およびフラグ(CPU 機能)の概要などの特定の詳細を見つけやすくなります。

cat /proc/cpuinfo は生データを提供しますが、lscpu は解析されて整理されたビューを提供します。これは、迅速な概要を把握するのに便利です。

Continue をクリックして次のステップに進みます。

dmidecode でハードウェアを調べる

前のステップでは、cat /proc/cpuinfolscpu を使用して CPU 情報を調べました。今度は、システムのハードウェアを調べるためのより汎用的なツールである dmidecode を見てみましょう。

dmidecode は、コンピュータの DMI(Desktop Management Interface)または SMBIOS(System Management BIOS)テーブルを読み取るツールです。このテーブルには、マザーボード、BIOS、メモリなど、システムのハードウェアコンポーネントに関する情報が含まれています。

dmidecode は低レベルのシステム情報にアクセスするため、root 権限が必要です。sudo コマンドを使用して、これらの権限で dmidecode を実行することができます。この環境では、labex ユーザーはパスワードを必要とせずに sudo アクセスができることを忘れないでください。

ターミナルに以下のコマンドを入力して、完全な DMI 情報を表示します。

sudo dmidecode

Enter キーを押します。

大量の出力が表示され、さまざまなハードウェアコンポーネントの詳細が示されます。出力は異なる「ハンドル」またはセクションに構造化されており、それぞれがシステムの特定の部分(例:BIOS 情報、システム情報、ベースボード情報、メモリデバイス)を説明しています。

以下は、表示される内容の一部です(出力は仮想マシンの構成によって異なります)。

## dmidecode 3.3
Getting SMBIOS data from sysfs.
SMBIOS 3.3.0 present.

Handle 0x0000, DMI type 0, 26 bytes
BIOS Information
        Vendor: Google
        Version: Google
        Release Date: 01/01/2011
        Address: 0xE8000
        Runtime Size: 96 kB
        ROM Size: 128 kB
        Characteristics:
                PCI is supported
                BIOS is upgradeable
                BIOS shadowing is allowed
                Boot from CD is supported
                Selectable boot is supported
                BIOS ROM is socketed
                EDD is supported
                5.25" / 1.2MB floppy services are supported (int 13h)
                3.5" / 720kB floppy services are supported (int 13h)
                3.5" / 2.88MB floppy services are supported (int 13h)
                Print screen service is supported (int 5h)
                8042 keyboard services are supported (int 9h)
                Serial services are supported (int 14h)
                Printer services are supported (int 17h)
                CGA/mono video services are supported (int 10h)
                NEC PC-98
                ACPI is supported
                USB legacy is supported
                BIOS boot specification is supported
                Targeted content distribution is supported
                UEFI is supported
        BIOS Revision: 0.0

Handle 0x0001, DMI type 1, 27 bytes
System Information
        Manufacturer: Google
        Product Name: Google Compute Engine
        Version: pc-i440fx-xenial
        Serial Number: ...
        UUID: ...
        Wake-up Type: Power Switch
        SKU Number: ...
        Family: Virtual Machine

Handle 0x0002, DMI type 2, 10 bytes
Baseboard Information
        Manufacturer: Google
        Product Name: Google Compute Engine
        Version: pc-i440fx-xenial
        Serial Number: ...
        Asset Tag: No Asset Tag
        Features:
                Board is a hosting board
                Board is replaceable
        Location In Chassis: Not Specified
        Chassis Handle: 0x0003
        Type: Motherboard
        Contained Object Handles: 0

... (more output)

-t オプションを使用して、表示したい情報の種類を指定することもできます。たとえば、メモリ情報のみを表示するには、次のようにします。

sudo dmidecode -t memory

Enter キーを押します。

これにより、出力がフィルタリングされ、システムのメモリデバイスに関連する詳細のみが表示されます。

dmidecode は、コンピュータを開かずに詳細なハードウェア仕様を収集するための強力なツールです。ハードウェアの在庫管理やハードウェア関連の問題のトラブルシューティングに特に役立ちます。

Continue をクリックして、この実験を完了します。

まとめ

この実験では、Linux で特定の CPU 機能を確認する方法を学びました。最初に cat コマンドを使用して、/proc/cpuinfo という仮想ファイルに含まれる詳細な CPU 情報を表示しました。このファイルには、CPU の特性とサポートされているフラグの包括的なリストが提供されています。この最初のステップで、/proc ファイルシステムを通じてシステム情報にアクセスする方法を学びました。