git: ad1ed7742f0e - stable/13 - riscv: Print less CPU info

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Mon, 12 Jun 2023 13:50:23 UTC
The branch stable/13 has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=ad1ed7742f0e5a5059d5acac2901f74b3df7685e

commit ad1ed7742f0e5a5059d5acac2901f74b3df7685e
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2023-05-22 23:54:36 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2023-06-12 13:49:54 +0000

    riscv: Print less CPU info
    
    Change the reporting strategy to more closely follow what arm64
    implements:
     - Always print the one-line CPU summary when a core comes online
     - Only print the additional fields (e.g. ISA) when they differ from the
       CPU before it
    
    In the common case of identical CPUs this results in informative but
    non-repetitive output. For example, in QEMU:
    
      CPU 0  : Vendor=Unspecified Core=Unknown (Hart 0)
        marchid=0x80032, mimpid=0x80032
        MMU: 0x7<Sv39,Sv48,Sv57>
        ISA: 0x112d<Atomic,Compressed,Double,Float,Mult/Div>
      real memory  = 8589934592 (8192 MB)
      avail memory = 8332300288 (7946 MB)
      FreeBSD/SMP: Multiprocessor System Detected: 6 CPUs
      CPU 1  : Vendor=Unspecified Core=Unknown (Hart 1)
      CPU 2  : Vendor=Unspecified Core=Unknown (Hart 2)
      CPU 3  : Vendor=Unspecified Core=Unknown (Hart 3)
    
    Reviewed by:    markj
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D40024
    
    (cherry picked from commit 940e6d36de1ef010f731e290c9b2b08535fff424)
---
 sys/riscv/riscv/identcpu.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/sys/riscv/riscv/identcpu.c b/sys/riscv/riscv/identcpu.c
index e1a34983abf7..dafab6530024 100644
--- a/sys/riscv/riscv/identcpu.c
+++ b/sys/riscv/riscv/identcpu.c
@@ -449,18 +449,30 @@ printcpuinfo(u_int cpu)
 	KASSERT(desc->isa_extensions != 0,
 	    ("Empty extension set for CPU %u, did parsing fail?", cpu));
 
-	/* Print details for boot CPU or if we want verbose output */
-	if (cpu == 0 || bootverbose) {
-		/* Summary line. */
-		printf("CPU %-3u: Vendor=%s Core=%s (Hart %u)\n", cpu,
-		    desc->cpu_mvendor_name, desc->cpu_march_name, hart);
+	/*
+	 * Suppress the output of some fields in the common case of identical
+	 * CPU features.
+	 */
+#define	SHOULD_PRINT(_field)	\
+    (cpu == 0 || desc[0]._field != desc[-1]._field)
 
+	/* Always print summary line. */
+	printf("CPU %-3u: Vendor=%s Core=%s (Hart %u)\n", cpu,
+	    desc->cpu_mvendor_name, desc->cpu_march_name, hart);
+
+	/* These values are global. */
+	if (cpu == 0)
 		printf("  marchid=%#lx, mimpid=%#lx\n", marchid, mimpid);
+
+	if (SHOULD_PRINT(mmu_caps)) {
 		printf("  MMU: %#b\n", desc->mmu_caps,
 		    "\020"
 		    "\01Sv39"
 		    "\02Sv48"
 		    "\03Sv57");
+	}
+
+	if (SHOULD_PRINT(isa_extensions)) {
 		printf("  ISA: %#b\n", desc->isa_extensions,
 		    "\020"
 		    "\01Atomic"
@@ -469,4 +481,6 @@ printcpuinfo(u_int cpu)
 		    "\06Float"
 		    "\15Mult/Div");
 	}
+
+#undef SHOULD_PRINT
 }