[Unix] Comparing CPU features with the help of cut/tr/diff/grep commands

I always wanted to know what is the difference between AMD EPYC and AMD Ryzen. But ouch... how to compare (or diff) that 'flags' line?

$ cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 23
model           : 1
model name      : AMD EPYC 7601 32-Core Processor
stepping        : 2
...
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm rep_good nopl cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw perfctr_core ssbd ibpb vmmcall fsgsbase tsc_adjust bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 xsaves clzero xsaveerptr virt_ssbd arat arch_capabilities
...
$ cat /proc/cpuinfo
processor       : 11
vendor_id       : AuthenticAMD
cpu family      : 23
model           : 113
model name      : AMD Ryzen 5 3600 6-Core Processor
stepping        : 0
...
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sme sev sev_es
...

Take only flags for only first core:

$ cat /proc/cpuinfo | grep flags | head -n 1 | cut -d ':' -f 2
 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm rep_good nopl cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw perfctr_core ssbd ibpb vmmcall fsgsbase tsc_adjust bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 xsaves clzero xsaveerptr virt_ssbd arat arch_capabilities

How to diff that line with another? Using 'tr' we can convert the string to a (sorted) list. Basically, it replaces space with newline character.

$ cat /proc/cpuinfo | grep flags | head -n 1 | cut -d ':' -f 2 | tr ' ' '\n' | sort
...
sse
sse2
sse4_1
sse4_2
sse4a
ssse3
syscall
tsc
tsc_adjust
tsc_deadline_timer
...

Now I can diff that:

$ cat /proc/cpuinfo | grep flags | head -n 1 | cut -d ':' -f 2 | tr ' ' '\n' | sort > epyc
$ cat /proc/cpuinfo | grep flags | head -n 1 | cut -d ':' -f 2 | tr ' ' '\n' | sort > ryzen

AMD Ryzen has more flags:

$ diff -u epyc ryzen | grep "^\(+\|-\)"

--- epyc        2022-12-10 21:52:00.000000000 +0100
+++ ryzen       2022-12-10 22:52:57.750783798 +0100
+aperfmperf
-arch_capabilities
+avic
+bpext
+cat_l3
+cdp_l3
+clwb
+constant_tsc
+cpb
+cqm
+cqm_llc
+cqm_mbm_local
+cqm_mbm_total
+cqm_occup_llc
+decodeassists
+extapic
+flushbyasid
-hypervisor
+ht
+hw_pstate
+ibs
+irperf
+lbrv
+mba
+monitor
+mwaitx
+nonstop_tsc
+npt
+nrip_save
+overflow_recov
+pausefilter
+perfctr_llc
+perfctr_nb
+pfthreshold
+rapl
+rdpid
+rdpru
+rdt_a
+sev
+sev_es
+skinit
+smca
+sme
+stibp
+succor
+svm
+svm_lock
+tce
+topoext
-tsc_adjust
-tsc_deadline_timer
-tsc_known_freq
-virt_ssbd
+tsc_scale
+umip
+vgif
+vmcb_clean
-x2apic
+v_spec_ctrl
+v_vmsave_vmload
+wbnoinvd
+wdt

I use grep here to suppress unchanged lines (i.e., common flags for both CPUs).

I spent only couple minutes to find this information.


Comments at reddit.

(the post first published at 20221211.)


List of my other blog posts.

Subscribe to my news feed

Yes, I know about these lousy Disqus ads. Please use adblocker. I would consider to subscribe to 'pro' version of Disqus if the signal/noise ratio in comments would be good enough.