Index | Thread | Search

From:
Mike Larkin <mlarkin@nested.page>
Subject:
Re: print intel core type info in dmesg
To:
David Gwynne <david@gwynne.id.au>
Cc:
tech@openbsd.org
Date:
Wed, 23 Jul 2025 03:01:27 -0700

Download raw body.

Thread
On Wed, Jul 23, 2025 at 05:47:21PM +1000, David Gwynne wrote:
> i sent an old version of this around a year or two ago, which devolved
> into a discussion around how annoying the repeated cpu info is in dmesg.
> that's since been addressed, so i'm trying this out again.
>
> if an intel cpu provides information about the type of cpu, this adds it
> to the topology line in dmesg output. this is particularly interesting
> on hybrid systems.
>
> there are MSRs on recent amd chips that can tell zen 4 vs 4c or 5 vs 5c
> cores apart, but i dont have one to test with.
>

do you have a diff for amd that someone can test? and/or where are these
documented?

-ml

> Index: amd64/identcpu.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/amd64/amd64/identcpu.c,v
> diff -u -p -r1.151 identcpu.c
> --- amd64/identcpu.c	26 Jun 2025 12:17:27 -0000	1.151
> +++ amd64/identcpu.c	23 Jul 2025 07:31:25 -0000
> @@ -831,6 +843,7 @@ cpu_topology(struct cpu_info *ci)
>  	u_int32_t apicid, max_apicid = 0, max_coreid = 0;
>  	u_int32_t smt_bits = 0, core_bits, pkg_bits = 0;
>  	u_int32_t smt_mask = 0, core_mask, pkg_mask = 0;
> +	const char *type = NULL;
>
>  	/* We need at least apicid at CPUID 1 */
>  	if (ci->ci_cpuid_level < 1)
> @@ -890,20 +903,35 @@ cpu_topology(struct cpu_info *ci)
>  		ci->ci_smt_id = apicid & smt_mask;
>  		ci->ci_core_id = (apicid & core_mask) >> smt_bits;
>  		ci->ci_pkg_id = (apicid & pkg_mask) >> pkg_bits;
> +
> +		if (cpuid_level >= 0x1a) {
> +			CPUID_LEAF(0x1a, 0, eax, ebx, ecx, edx);
> +			switch ((eax >> 24) & 0xff) {
> +			case 0x20:
> +				type = "efficiency";
> +				break;
> +			case 0x40:
> +				type = "performance";
> +				break;
> +			}
> +		}
>  	} else
>  		goto no_topology;
>  #ifdef DEBUG
>  	printf("cpu%d: smt %u, core %u, pkg %u "
>  		"(apicid 0x%x, max_apicid 0x%x, max_coreid 0x%x, smt_bits 0x%x, smt_mask 0x%x, "
> -		"core_bits 0x%x, core_mask 0x%x, pkg_bits 0x%x, pkg_mask 0x%x)\n",
> +		"core_bits 0x%x, core_mask 0x%x, pkg_bits 0x%x, pkg_mask 0x%x)",
>  		ci->ci_cpuid, ci->ci_smt_id, ci->ci_core_id, ci->ci_pkg_id,
>  		apicid, max_apicid, max_coreid, smt_bits, smt_mask, core_bits,
>  		core_mask, pkg_bits, pkg_mask);
>  #else
> -	printf("cpu%d: smt %u, core %u, package %u\n", ci->ci_cpuid,
> +	printf("cpu%d: smt %u, core %u, package %u", ci->ci_cpuid,
>  		ci->ci_smt_id, ci->ci_core_id, ci->ci_pkg_id);
>
>  #endif
> +	if (type != NULL)
> +		printf(", %s core", type);
> +	printf("\n");
>  	return;
>  	/* We can't map, so consider ci_core_id as ci_cpuid */
>  no_topology:
>