It is currently April 27th, 2024, 7:03 pm

Calculating E-core count

Tips and Tricks from the Rainmeter Community
TGonZo
Posts: 68
Joined: April 25th, 2015, 8:19 pm
Location: Virginia

Calculating E-core count

Post by TGonZo »

Hi all. I've looked for this topic and anything relating to it, and did not find anything. So I hope I am not repeating anything here.

I've been wanting a way to figure out how many P-cores and E-cores there are on the newer Intel CPUs.
So I think I have it figured out. I put together a quick skin to test the idea, and show you.
Also, I am hoping you all can review the code and if there are better ways to get this answer, I am willing to hear it.

You can get to the numbers of Cores and number of Logical processors in Windows, but not the actual P-core of E-core count. Not without using 3rd party tools. I wanted to keep this native. So I am using the wmic windows command to get that. Is there a better way?
And then I use those 2 numbers to calculate the P-cores and E-cores.
As best I can tell, I think this should work on all CPUs. If you don't have E-cores, it will just be 0.

I'll post the code here and you can look it over. Or use it if you have a need for it.
Here are 2 examples. One with E-cores and one without.

i7-1370P
CPUtest_i7-1370P.jpg
i9-9900K
CPUtest_i9-9900K.jpg

Code: Select all

[Rainmeter]
Update=1000
BackgroundMargins=0,0,0,0
OnRefreshAction=[!CommandMeasure CpuCores "Run"][!CommandMeasure CpuLogical "Run"]

[Metadata]
Name=CPUtest
Author=TGonZo
Information=Calculate P-cores and E-cores
License=Creative Commons BY-NC-SA 3.0
Version=1.0.0

[Variables]
fontName=Trebuchet MS
textSize=12

;=========================================================

[meterBase]
Meter=Image
X=0
Y=0
W=160
H=140
SolidColor=47,47,47,240
UpdateDivider=-1

;-------------

[CpuCores]
Measure=Plugin
Plugin=RunCommand
Parameter=wmic cpu get NumberOfCores/Format:List
OutputType=ANSI
RegExpSubstitute=1
Substitute="(?siU)^.*NumberOfCores=([\d]{1,2})":"\1","#CRLF#":""
UpdateDivider=-1

[CpuLogical]
Measure=Plugin
Plugin=RunCommand
Parameter=wmic cpu get NumberOfLogicalProcessors/Format:List
OutputType=ANSI
RegExpSubstitute=1
Substitute="(?siU)^.*NumberOfLogicalProcessors=([\d]{1,2})":"\1","#CRLF#":""
UpdateDivider=-1


[CpuPcores]
Measure=Calc
Formula=([CpuLogical]-[CpuCores] = 0 ? [CpuCores] : [CpuLogical]-[CpuCores])
DynamicVariables=1

[CpuEcores]
Measure=Calc
Formula=[CpuCores]-CpuPcores
DynamicVariables=1

[CpuFirstEcore]
Measure=Calc
Formula=(CpuEcores = 0 ? 0 : [CpuLogical]-CpuEcores+1)
DynamicVariables=1

;-------------

[MeterCPUs]
Meter=String
MeasureName=CpuCores
MeasureName2=CpuLogical
MeasureName3=CpuPcores
MeasureName4=CpuEcores
MeasureName5=CpuFirstEcore
FontSize=13
FontColor=255,255,255,255
Padding=10,10,10,10
AntiAlias=1
Text=Cores = %1 #CRLF#Logicals = %2 #CRLF#-----------------#CRLF#P-cores = %3 #CRLF#E-cores = %4 #CRLF#1st E-core = %5
 
 
My thoughts were to highlight the E-cores differently or something in my skins.
Let me know what you think.
You do not have the required permissions to view the files attached to this post.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2613
Joined: March 23rd, 2015, 5:26 pm

Re: Calculating E-core count

Post by SilverAzide »

TGonZo wrote: January 6th, 2024, 9:38 pm Hi all. I've looked for this topic and anything relating to it, and did not find anything. So I hope I am not repeating anything here.

I've been wanting a way to figure out how many P-cores and E-cores there are on the newer Intel CPUs.
So I think I have it figured out. I put together a quick skin to test the idea, and show you.
Also, I am hoping you all can review the code and if there are better ways to get this answer, I am willing to hear it.

You can get to the numbers of Cores and number of Logical processors in Windows, but not the actual P-core of E-core count. Not without using 3rd party tools. I wanted to keep this native. So I am using the wmic windows command to get that. Is there a better way?
And then I use those 2 numbers to calculate the P-cores and E-cores.
As best I can tell, I think this should work on all CPUs. If you don't have E-cores, it will just be 0.

I'll post the code here and you can look it over. Or use it if you have a need for it.
Here are 2 examples. One with E-cores and one without.

[...]

My thoughts were to highlight the E-cores differently or something in my skins.
Let me know what you think.
Hello TGonZo!
This logic does work for 99.9% of cases. The .1% where it won't work is when you have more than 64 logical cores (i.e., Threadrippers and the like), or when running a processor in NUMA mode, or when running on machines with more than 1 socket (SMP). In all these edge cases you will get half (or a quarter, whatever) of the actual number, or some other weird problem. (This actually isn't a hybrid CPU issue, it's anything with more than 64 threads or more than 1 "processor group". Windows itself cannot "see" more than 64 logical processors per process, unless specifically written to do otherwise.)

Another part of the .1% where it won't work is in virtual machines (which use single threaded vCPUs) and in cases where hyperthreading is disabled. Your logic will assume your i7, for example, has 14 P-cores and 0 E-cores, and if you were to assume hyperthreading was actually on, you'd end up with a weird 7-core hyperthreaded CPU. Not many folks would turn off hyperthreading, other than certain *cough* "entities" *cough* hyper-concerned about security and who wouldn't be allowed to run Rainmeter anyway.

It's difficult (as far I as know) to tell the difference between a P-core and an E-core if all you can see is the difference in physical/logical core count. I suspect you'd have to look at the base clock of each core to figure it out, and I have not figured out a way to do that (Windows doesn't seem to know). I assume HWiNFO and the like know this because they have a library of CPUs to draw from.

If you want to cover the full 100% of CPU architectures instead of 99.9% then your options are limited. I note that your objective is to not use third-party tools. I'm not sure if this extends to Rainmeter plugins. If plugins are acceptable, the only option I know of is my ActiveNet plugin I use in my Gadgets suite. I call the Win32 library functions (GetLogicalProcessorInformation, et al., same as SysInternals CoreInfo). This will get you all sorts of low level info; it still can't tell between P-cores and E-cores, but it CAN tell you how many threads are being used by each physical core, which will get you really really close to the info you want for any CPU architecture.

Code: Select all

C:\> Coreinfo64 -c

Coreinfo v3.6 - Dump information on system CPU and memory topology
Copyright (C) 2008-2022 Mark Russinovich
Sysinternals - www.sysinternals.com


Logical to Physical Processor Map:
**----------------------  Physical Processor 0 (Hyperthreaded)
--**--------------------  Physical Processor 1 (Hyperthreaded)
----**------------------  Physical Processor 2 (Hyperthreaded)
------**----------------  Physical Processor 3 (Hyperthreaded)
--------**--------------  Physical Processor 4 (Hyperthreaded)
----------**------------  Physical Processor 5 (Hyperthreaded)
------------**----------  Physical Processor 6 (Hyperthreaded)
--------------**--------  Physical Processor 7 (Hyperthreaded)
----------------*-------  Physical Processor 8
-----------------*------  Physical Processor 9
------------------*-----  Physical Processor 10
-------------------*----  Physical Processor 11
--------------------*---  Physical Processor 12
---------------------*--  Physical Processor 13
----------------------*-  Physical Processor 14
-----------------------*  Physical Processor 15
Gadgets Wiki GitHub More Gadgets...
TGonZo
Posts: 68
Joined: April 25th, 2015, 8:19 pm
Location: Virginia

Re: Calculating E-core count

Post by TGonZo »

Hi SilverAzide,

Thank you so much for your insights. I figured there may be a few edge cases where the math does not work, and I think you got it.
I think I am okay with the 99.9% solution case. It would take a huge amount of effort to close the gap on the last 0.1%.
In my opinion, that is not worth the effort at this time.

Also, my plan is to provide another CPU variant with E-core detection in it, and assuming the user has a 1 socket MB and has not done anything weird like disabling Hyperthreading. So the user would only pick the variant if they thought they had an E-core CPU and wanted to see them detailed out in the skin.

I'm not sure exactly what I will do yet, but wanted to make sure the math was sound first.

If there is a better or cleaner way to get the two numbers from Windows (Cores and Logical processors) than using the wmic command, I would like to check it out. If not, then what I have will be my 99.9% solution with caveats.

Thanks again for your time.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2613
Joined: March 23rd, 2015, 5:26 pm

Re: Calculating E-core count

Post by SilverAzide »

TGonZo wrote: January 7th, 2024, 2:20 am If there is a better or cleaner way to get the two numbers from Windows (Cores and Logical processors) than using the wmic command, I would like to check it out. If not, then what I have will be my 99.9% solution with caveats.
There is not a better way, to my knowledge. My plugin uses these same WMI queries, but does it directly via the API instead of scraping the screen for command line output.

One thing to watch out for if you want to use the wmic command is that you might get multiple records returned if the PC has more than 1 socket or more than 1 CPU. Threadrippers (perhaps just the old ones) are weird in that the processor acts like 1, 2, or 4 CPUs welded together and jammed into a single socket, so they might report oddball things. Intel's roadmap for future CPUs indicate they plan do this "chiplet" architecture too. So, if you care to add some insurance for this weirdness, in your regexp just grab the first (or last) line of output and you should be good.
Gadgets Wiki GitHub More Gadgets...
User avatar
SilverAzide
Rainmeter Sage
Posts: 2613
Joined: March 23rd, 2015, 5:26 pm

Re: Calculating E-core count

Post by SilverAzide »

TGonZo wrote: January 7th, 2024, 2:20 am Also, my plan is to provide another CPU variant with E-core detection in it, and assuming the user has a 1 socket MB and has not done anything weird like disabling Hyperthreading. So the user would only pick the variant if they thought they had an E-core CPU and wanted to see them detailed out in the skin.
You might be able to detect this auto-magically.

Code: Select all

If (logical_cores = physical_cores) then
    You have a case where it is highly likely that the user has hyperthreading off
    or, less likely, is running an ancient single-threaded CPU (Core Duo, etc.); you can't know about hybrid-ness in this case
Else If (logical_cores = physical_cores * 2) then
    User has a CPU with hyperthreading on and it is definitely NOT a hybrid CPU
Else
    User definitely has a hybrid CPU.
Gadgets Wiki GitHub More Gadgets...
TGonZo
Posts: 68
Joined: April 25th, 2015, 8:19 pm
Location: Virginia

Re: Calculating E-core count

Post by TGonZo »

Thanks for the tips. I think I will keep it simple for now, and provide a variant with E-cores in it. You would only select that variant if you have it.
I will continue to look at ways to make it fully automatic so there will not need to be a variant, but for now a variant is an easier solution.
As for future proofing for Intel using chiplets and having a hybrid with E-cores, I'll wait to see how that will look before coding it in.

Thanks again for your advice. I think I will go with that I have for now.
Your time is much appreciated.