junjie1475 / MacOS_CoreBinder

Kernel Extension allows to pin thread on a certain cpu core on Apple Silicon machines
The Unlicense
9 stars 0 forks source link

Try CoreBinder on M3 processor #2

Open wkxfudan opened 1 month ago

wkxfudan commented 1 month ago

Hello, I tried to apply mac os corebinder on Apple M3 platform, MacOS version is 14.5. I tried three compilation flags, -DT6000, -DT6020, -DT8112, none of which worked. Applying -DT6000 caused the OS to crash.

For the other two compilation flags, since the successful examples in the README are lost, I tried to use coremark load and check the binding phenomenon through htop. I found that coremark still switches between cores.

$ ./MacOS_CoreBinder/commandline_tool/pin -c 1 coremark/coremark.exe
core: 1
argv[0]: coremark/coremark.exe
ret: 0
2K performance run parameters for coremark.
CoreMark Size    : 666
Total ticks      : 26805
Total time (secs): 26.805000
Iterations/Sec   : 37306.472673
Iterations       : 1000000
Compiler version : Apple LLVM 15.0.0 (clang-1500.3.9.4)
Compiler flags   : -O2 -DPERFORMANCE_RUN=1  
Memory location  : Please put data memory location here
            (e.g. code in flash, data on heap etc)
seedcrc          : 0xe9f5
[0]crclist       : 0xe714
[0]crcmatrix     : 0x1fd7
[0]crcstate      : 0x8e3a
[0]crcfinal      : 0x988c
Correct operation validated. See README.md for run and reporting rules.
CoreMark 1.0 : 37306.472673 / Apple LLVM 15.0.0 (clang-1500.3.9.4) -O2 -DPERFORMANCE_RUN=1   / Heap

May I ask if there is any additional function to run on the M3 platform?

junjie1475 commented 1 month ago

Hi, can you try to embedde sysctlbyname("kern.pin_core", NULL, NULL, &core, sizeof(core)) directly into the code? Due to some wired issues it seems that the execve() doesn't inherit the bound_processor value in thread struct.

wkxfudan commented 1 month ago

Thanks for your reply!!!!!!! But embedding that system call in the code doesn't seem to work either.

I embedded the system call at the beginning of the main function.

main(int argc, char *argv[])
{
    int core = 6;
    sysctlbyname("kern.pin_core", NULL, NULL, &core, sizeof(core));
    ee_printf("sysctl pin to core:%d\n", core);
    ......
}

The execution results are as follows:

$ ./coremark.exe
sysctl pin to core:6
2K performance run parameters for coremark.
CoreMark Size    : 666
Total ticks      : 51684
Total time (secs): 51.684000
Iterations/Sec   : 38696.695302
Iterations       : 2000000
Compiler version : Apple LLVM 15.0.0 (clang-1500.3.9.4)
Compiler flags   : -O2 -DPERFORMANCE_RUN=1  
Memory location  : Please put data memory location here
                        (e.g. code in flash, data on heap etc)
seedcrc          : 0xe9f5
[0]crclist       : 0xe714
[0]crcmatrix     : 0x1fd7
[0]crcstate      : 0x8e3a
[0]crcfinal      : 0x382f
Correct operation validated. See README.md for run and reporting rules.
CoreMark 1.0 : 38696.695302 / Apple LLVM 15.0.0 (clang-1500.3.9.4) -O2 -DPERFORMANCE_RUN=1   / Heap

Observe through htop that coremark is still switching between different cores.

In addition, I have observed that if the binding is successful through corebinder, there will be some print information prompts. During my execution, the terminal does not have this print information, does it mean that the binding failed?