Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed detecting CPU core count on Intel CPU #6

Merged
merged 1 commit into from
Jan 19, 2022

Conversation

b00t0x
Copy link
Contributor

@b00t0x b00t0x commented Jan 17, 2022

Background

RestricEvents.kext counts cores by tracing x86_pkgs structure, but macOS doesn't seem to use x86_pkgs when setting the processor name in About This Mac. macOS may read other information like cpuid_info().

It's not normally a problem as each method returns the same core count, but it's a problem if x86_pkgs has been modified, for example my CpuTopologyRebuild.kext.

see also : b00t0x/CpuTopologyRebuild#2

Changes

This commit changes the logic to use cpuid_info()->core_count for getting core count. The original logic using the x86_pkgs seems to be written for AMD environment, and I don't know how this fix affects it, so I don't removed the logic and left it for AMD.

Samples

Before

maint@Z690M ~ % grep -A1 '<key>revcpuname' /Volumes/USB/EFI/OC/config.plist
				<key>revcpuname</key>
				<string>NAME NAME NAME</string>
maint@Z690M ~ % kextstat | grep RestrictEvents                             
Executing: /usr/bin/kmutil showloaded
No variant specified, falling back to release
   53    0 0                  0xf000     0xf000     as.vit9696.RestrictEvents (1.0.6) 429B25D1-F485-39A6-AA3C-C0B527FB944E <51 9 7 6 3 2 1>
maint@Z690M ~ % sysctl machdep.cpu | grep count                            
machdep.cpu.core_count: 24
machdep.cpu.thread_count: 24
maint@Z690M ~ % grep rev /var/log/Lilu_1.5.9_21.2.txt
RestrictEvents       rev: @ (DBG) restriction policy plugin loaded
RestrictEvents       rev: @ (DBG) revnopatch to disable 
RestrictEvents       rev: @ (DBG) read revcpu override from NVRAM - 1
RestrictEvents       rev: @ (DBG) read revcpuname from NVRAM
RestrictEvents       rev: @ (DBG) requested to patch CPU name to NAME NAME NAME
RestrictEvents       rev: @ (DBG) calculated 16 cores in pkg 0 amd 0
RestrictEvents       rev: @ (DBG) chosen 16-Core Intel Xeon W patch for 16 core CPU
RestrictEvents       rev: @ (DBG) init bsd policy on 21
RestrictEvents       rev: @ (DBG) patched 16-Core Intel Xeon W in AppleSystemInfo

Screen Shot 2022-01-18 at 0 57 40

After

maint@Z690M ~ % grep -A1 '<key>revcpuname' /Volumes/USB/EFI/OC/config.plist
				<key>revcpuname</key>
				<string>NAME NAME NAME</string>
maint@Z690M ~ % kextstat | grep RestrictEvents                             
Executing: /usr/bin/kmutil showloaded
No variant specified, falling back to release
   53    0 0                  0x14000    0x14000    as.vit9696.RestrictEvents (1.0.7) 1F40922B-BA76-3783-A69F-6B61FBE3C87D <51 9 7 6 3 2 1>
maint@Z690M ~ % sysctl machdep.cpu | grep count                            
machdep.cpu.core_count: 24
machdep.cpu.thread_count: 24
maint@Z690M ~ % grep rev /var/log/Lilu_1.5.9_21.2.txt
RestrictEvents       rev: @ (DBG) restriction policy plugin loaded
RestrictEvents       rev: @ (DBG) revnopatch to disable 
RestrictEvents       rev: @ (DBG) read revcpu override from NVRAM - 1
RestrictEvents       rev: @ (DBG) read revcpuname from NVRAM
RestrictEvents       rev: @ (DBG) requested to patch CPU name to NAME NAME NAME
RestrictEvents       rev: @ (DBG) calculated 24 cores from cpuid_info()
RestrictEvents       rev: @ (DBG) chosen 24-Core Intel Xeon W patch for 24 core CPU
RestrictEvents       rev: @ (DBG) init bsd policy on 21
RestrictEvents       rev: @ (DBG) patched 24-Core Intel Xeon W in AppleSystemInfo

Screen Shot 2022-01-18 at 1 02 18

uint32_t cc = 0, pp = 0;
if (!isAMD) {
cc = cpuid_info()->core_count;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cpuid_info() is com.apple.kpi.private, but I guess we cannot get there via any other way.

@vit9696 vit9696 merged commit af9924a into acidanthera:master Jan 19, 2022
@b00t0x b00t0x deleted the patch_core_count branch January 19, 2022 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants