NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/57816: Add sysctl support for physical cores



The following reply was made to PR kern/57816; it has been noted by GNATS.

From: mlelstv%serpens.de@localhost (Michael van Elst)
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: kern/57816: Add sysctl support for physical cores
Date: Thu, 4 Jan 2024 18:33:38 -0000 (UTC)

 martin%duskware.de@localhost (Martin Husemann) writes:
 
 > On Thu, Jan 04, 2024 at 04:05:01PM +0000, Michael van Elst wrote:
 > >  That information is currently available using the cpuctl identify command,
 > >  but it's machine specific and probably delivers the information directly
 > >  only for x86.
 > 
 > It also has serious downsides:
 >  - it requires the user to be root
 >  - it requires one "cpuctl identify N" process for each cpu
 
 That's one of the design flaws of cpuctl. All data should be
 collected and provided by the kernel, including the information
 that cannot be collected from MSRs. That should make 'identify'
 a wrapper around sysctl.
 
 
 > I'm also not sure it is all correct - I have a
 > "AMD Ryzen 5 1400 Quad-Core Processor" with cpu0 ... cpu7, and e.g.
 > 
 > cpu7: AMD Ryzen 5 1400 Quad-Core Processor           , id 0x800f11
 > cpu7: node 0, package 0, core 5, smt 1
 > 
 > (with cores 0, 1, 4 and 5 showing up)
 
 The numbers are extracted from the APIC id, and there
 are is some heuristic on how to interpret the different
 bits as package, core or smt (thread) number.
 
 But these are the numbers the kernel relies on and
 sparse ids are not a problem.
 
 
 > but "cpuctl identify 7" says:
 > 
 > cpu7: Initial APIC ID 11
 > cpu7: Cluster/Package ID 0
 > cpu7: Core ID 1
 > cpu7: SMT ID 1
 
 Even on x86 you cannot read all information from MSRs and
 the code in kernel and cpuctl have diverged for some time.
 
 Saying that, I don't see the difference here, but the
 calculation of the package id ("socket") is weird:
 
 Kernel:
         if (smt_bits + core_bits) {
                 if (smt_bits + core_bits < sizeof(apic_id) * NBBY)
                         package_id = apic_id >> (smt_bits + core_bits);
                 else
                         package_id = 0;
         }
 
 cpuctl:
         ci->ci_packageid = ci->ci_initapicid >> pkg_shift;
         ...
         if (smt_bits + core_bits) {
                 if (smt_bits + core_bits < 32)
                         ci->ci_packageid = 0;
         }
 
 "diverged"...
 


Home | Main Index | Thread Index | Old Index