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

IOConnectCallStructMethod calling failed #839

Open
liyuankunbix opened this issue Oct 5, 2024 · 10 comments
Open

IOConnectCallStructMethod calling failed #839

liyuankunbix opened this issue Oct 5, 2024 · 10 comments

Comments

@liyuankunbix
Copy link

Below is the output of pcm.

 Intel(r) Performance Counter Monitor ($Format:%ci ID=%h$)


=====  Processor information  =====
Hybrid processor         : no
IBRS and IBPB supported  : yes
STIBP supported          : yes
Spec arch caps supported : yes
Max CPUID level          : 22
CPU family               : 6
CPU model number         : 166
IOServiceOpen returned 0xe00002c7
Unable to build CPU topology
WARNING: Core 0 IA32_PERFEVTSEL0_ADDR is not zeroed 18446744073709551615
Access to Intel(r) Performance Counter Monitor has denied (Performance Monitoring Unit is occupied by other application). Try to stop the application that uses PMU.
Alternatively you can try running PCM with option -r to reset PMU.
Cleaning up
 Zeroed PMU registers
 Zeroed uncore PMU registers

I tried to debug the code, below is the call stack.

libPcmMsr.dylib!MSRAccessor::read(unsigned int, unsigned long long, unsigned long long*) (/Users/bixian/pcm/src/MacMSRDriver/MSRAccessor.cpp:37)
pcm!pcm::MsrHandle::read(unsigned long long, unsigned long long*) (/Users/bixian/pcm/src/msr.cpp:140)
pcm!pcm::SafeMsrHandle::read(unsigned long long, unsigned long long*) (/Users/bixian/pcm/src/msr.h:76)
pcm!pcm::PCM::PMUinUse() (/Users/bixian/pcm/src/cpucounters.cpp:4720)
pcm!pcm::PCM::program(pcm::PCM::ProgramMode, void const*, bool, int) (/Users/bixian/pcm/src/cpucounters.cpp:3467)
pcm!mainThrows(int, char**) (/Users/bixian/pcm/src/pcm.cpp:1557)
pcm!main (/Users/bixian/pcm/src/pcm.cpp:1343)
libdyld.dylib!start (Unknown Source:0)
libdyld.dylib!start (Unknown Source:0)

And when the debugger step over kern_return_t ret = IOConnectCallStructMethod(connect, kReadMSR, &idatas, struct_size, &odatas, &struct_size);, the returned value is 268435459 rather than 0.
Below is the code snippet and corresponding arguments passed into IOConnectCallStructMethod

int32_t MSRAccessor::read(uint32_t core_num, uint64_t msr_num, uint64_t * value)
{
    pcm_msr_data_t idatas, odatas;

    size_t struct_size = sizeof(pcm_msr_data_t);
    idatas.msr_num = (uint32_t)msr_num;
    idatas.cpu_num = core_num;

    kern_return_t ret = IOConnectCallStructMethod(connect, kReadMSR,
                                                  &idatas, struct_size,
                                                  &odatas, &struct_size);

    if(ret == KERN_SUCCESS)
    {
        *value = odatas.value;
        return sizeof(uint64_t);
    } else {
        return -1;
    }
}
idatas={
    value=0;
    cpu_num=0;
    mar_num=914;
}
struct_size=16
connect=0
kReadMSR=2

I did some research about IOConnectCallStructMethod. It seems IOConnectCallStructMethod is trying to send a struct to a kext and get the output struct, correct? And I double checked that SIP is disabled and com.intel.driver.PcmMsr is loaded.

I cannot diagnose anymore.

@opcm
Copy link
Contributor

opcm commented Oct 5, 2024

could you run pcm with the -r option?

pcm -r

Does it work?

@liyuankunbix
Copy link
Author

could you run pcm with the -r option?

pcm -r

Does it work?

I don't think -r option makes any difference.

 Intel(r) Performance Counter Monitor ($Format:%ci ID=%h$)
3

=====  Processor information  =====
Hybrid processor         : no
IBRS and IBPB supported  : yes
STIBP supported          : yes
Spec arch caps supported : yes
Max CPUID level          : 22
CPU family               : 6
CPU model number         : 166
IOServiceOpen returned 0xe00002c7
Unable to build CPU topology

 Resetting PMU configuration
Execute debugger commands using "-exec <command>", for example "-exec info registers" will list registers in use (when GDB is the debugger)
 Zeroed PMU registers
WARNING: Core 0 IA32_PERFEVTSEL0_ADDR is not zeroed 18446744073709551615
Access to Intel(r) Performance Counter Monitor has denied (Performance Monitoring Unit is occupied by other application). Try to stop the application that uses PMU.
Alternatively you can try running PCM with option -r to reset PMU.
Cleaning up
 Zeroed PMU registers
 Zeroed uncore PMU registers
The program '/Users/bixian/pcm/build/bin/pcm' has exited with code 0 (0x00000000).

@opcm
Copy link
Contributor

opcm commented Oct 6, 2024

this seems to the the same issue: #608 (comment)

Did you try the manual install procedure: https://github.com/intel/pcm/blob/master/doc/MAC_HOWTO.txt
Could you share the output of kextstat ?

@liyuankunbix
Copy link
Author

this seems to the the same issue: #608 (comment)

Did you try the manual install procedure: https://github.com/intel/pcm/blob/master/doc/MAC_HOWTO.txt Could you share the output of kextstat ?

I basically follow the instructions in https://github.com/intel/pcm/blob/master/doc/MAC_HOWTO.txt, except I use several cmake options, "-DPCM_NO_ASAN=1", "-DNO_SSL=1", "-DCMAKE_BUILD_TYPE=Debug".

The reason why I use "-DPCM_NO_ASAN=1" is the kext fails to be loaded without this option and give me a error message could not find a kext which exports this symbol ___asan_unregister_image_globals.

The reason why I use "-DNO_SSL=1" is I have no openssl installed.

The reason for Debug cmake type is I want to do some debugging.

Index Refs Address            Size       Wired      Name (Version) UUID <Linked Against>
161    0 0xffffff7fa23c7000 0x3000     0x3000     com.intel.driver.PcmMsr (1) 10C068DB-3E2F-39D4-80ED-275885FCFDC6 <8 6 5 3 1>

Here's part of the output of kextstat. Do you need a full version?

@opcm
Copy link
Contributor

opcm commented Oct 6, 2024

thank you. Please share the full output from kextstat and also MacOS/OSX version.

@liyuankunbix
Copy link
Author

thank you. Please share the full output from kextstat and also MacOS/OSX version.

Index Refs Address            Size       Wired      Name (Version) UUID <Linked Against>
    1  130 0                  0          0          com.apple.kpi.bsd (20.3.0) C86236B2-4976-3542-80CA-74A6B8B4BA03 <>
    2   20 0                  0          0          com.apple.kpi.dsep (20.3.0) C86236B2-4976-3542-80CA-74A6B8B4BA03 <>
    3  159 0                  0          0          com.apple.kpi.iokit (20.3.0) C86236B2-4976-3542-80CA-74A6B8B4BA03 <>
    4    0 0                  0          0          com.apple.kpi.kasan (20.3.0) C86236B2-4976-3542-80CA-74A6B8B4BA03 <>
    5  165 0                  0          0          com.apple.kpi.libkern (20.3.0) C86236B2-4976-3542-80CA-74A6B8B4BA03 <>
    6  145 0                  0          0          com.apple.kpi.mach (20.3.0) C86236B2-4976-3542-80CA-74A6B8B4BA03 <>
    7   87 0                  0          0          com.apple.kpi.private (20.3.0) C86236B2-4976-3542-80CA-74A6B8B4BA03 <>
    8  102 0                  0          0          com.apple.kpi.unsupported (20.3.0) C86236B2-4976-3542-80CA-74A6B8B4BA03 <>
    9    2 0xffffff80031e8000 0xe000     0xe000     com.apple.kec.Libm (1) 75E2671F-F050-3765-96B8-BD03232E1A62 <5>
   10   11 0xffffff8003406000 0x91000    0x91000    com.apple.kec.corecrypto (11.1) E009770B-BAFB-3BF9-B176-D6B4CC96DF5F <8 7 6 5 3 1>
   11    0 0xffffff80034a1000 0x8000     0x8000     com.apple.kec.pthread (1) 1E922D2A-9975-3AFB-A009-73EC3EF87A86 <8 7 6 5 3 1>
   12    1 0xffffff8003563000 0x2000     0x2000     com.apple.driver.watchdog (1) 2C1307C5-FD71-3802-8D68-A67DB24BCB4A <8 7 6 5 3 1>
   13   36 0xffffff80026d8000 0x2000     0x2000     com.apple.iokit.IOACPIFamily (1.4) B41AA072-8BB9-3493-9796-6FF849CDABB8 <8 7 5 3>
   14   33 0xffffff8002c1f000 0x28000    0x28000    com.apple.iokit.IOPCIFamily (2.9) BF2C5E86-1E8F-3FD4-9874-7738178FA73B <8 7 6 5 3>
   15   11 0xffffff8001895000 0x19000    0x19000    com.apple.driver.AppleSMC (3.1.9) 1E48B8EB-7BF3-3366-8520-2C4B31A7D3F8 <14 13 12 8 7 6 5 3 1>
   16    2 0xffffff8001292000 0x77000    0x77000    com.apple.driver.AppleACPIPlatform (6.1) 2F2AA264-6BD5-3E4F-829C-8952B3ABB2D5 <15 14 13 8 7 6 5 3 1>
   17    5 0xffffff8002d37000 0x2000     0x2000     com.apple.driver.IOSlaveProcessor (1) FC8BCD16-0792-35FD-B23E-A0720BC40E1A <5 3>
   18    3 0xffffff800187b000 0x10000    0x10000    com.apple.driver.AppleSEPManager (1.0.1) 4FC2AB67-A77F-3028-BFF6-7BE23EEE6773 <17 14 10 8 7 6 5 3 1>
   19    1 0xffffff800158c000 0x4000     0x4000     com.apple.driver.AppleBusPowerController (1.0) 499DB0FD-1FE4-31FC-B0E0-ECE24BF29417 <15 13 7 6 5 3>
   20    9 0xffffff80019e2000 0x4000     0x4000     com.apple.driver.usb.AppleUSBCommon (1.0) 62FE0E66-DCCA-3443-B01E-0F0FAB0A820D <6 5 3 1>
   21    1 0xffffff800304d000 0x1000     0x1000     com.apple.driver.AppleUSBHostMergeProperties (1.2) 90FEE882-3237-3822-91F1-6AD62C8E46AD <5 3 1>
   22   24 0xffffff8002f52000 0x8d000    0x8d000    com.apple.iokit.IOUSBHostFamily (1.2) A84D73D5-4F62-32E2-A1DB-9F021795AE81 <21 20 19 15 13 8 7 6 5 3 1>
   23    3 0xffffff80031d2000 0xf000     0xf000     com.apple.driver.KernelRelayHost (1) 6E0EDF05-F095-3009-AC2B-BE4CEFFF6583 <22 6 5 3>
   24    1 0xffffff8001600000 0x50000    0x50000    com.apple.driver.AppleCredentialManager (1.0) 56AFE766-6003-3409-B493-402505841C1C <23 18 17 10 8 7 6 5 3 1>
   25    2 0xffffff800166d000 0x6000     0x6000     com.apple.driver.AppleEffaceableStorage (1.0) CE527E76-F27F-33BD-933A-ED837F559A6D <8 6 5 3 1>
   26    0 0xffffff8001677000 0x6000     0x6000     com.apple.driver.AppleFDEKeyStore (28.30) FDFE34C9-00DA-3C05-AC10-14CF0EB24902 <25 10 8 7 6 5 3 1>
   27    2 0xffffff8001b7e000 0x7000     0x7000     com.apple.kext.CoreTrust (1) 36944A7C-F451-35A4-82A1-3B6BF8CBAC71 <10 5>
   28    8 0xffffff8001801000 0x15000    0x15000    com.apple.driver.AppleMobileFileIntegrity (1.0.5) 2A454117-CDAA-301F-B609-BA396742C91A <27 10 8 7 6 5 3 2 1>
   29    3 0xffffff8002c5a000 0x14000    0x14000    com.apple.iokit.IOSCSIArchitectureModelFamily (436.40.6) E5CB0567-FBD1-39AE-8847-C559B51918B1 <7 6 5 3 1>
   30    8 0xffffff8002d3f000 0x12000    0x12000    com.apple.iokit.IOStorageFamily (2.1) B5300908-BF34-3D47-8776-FB154A6DEE4C <8 7 6 5 3 1>
   31    1 0xffffff8002c7f000 0xe000     0xe000     com.apple.iokit.IOSCSIBlockCommandsDevice (436.40.6) 17662AB7-6B15-3342-9F23-AB161202B652 <30 29 7 6 5 3 1>
   32    1 0xffffff80031ae000 0x1a000    0x1a000    com.apple.iokit.IOUSBMassStorageDriver (184.40.6) AB4AC255-99A6-38E2-B5FE-22B97EEC79AA <30 29 22 14 7 6 5 3 1>
   33    1 0xffffff80018ef000 0x8000     0x8000     com.apple.driver.AppleUSBTDM (511.60.2) E381525B-81E2-3E87-B197-6355B228751B <32 31 30 29 28 22 8 7 6 5 3 1>
   34    0 0xffffff800175c000 0x80000    0x80000    com.apple.driver.AppleKeyStore (2) EAF92490-F231-30E8-A019-2C01F28E4315 <33 28 27 24 23 18 17 10 8 7 6 5 3 1>
   35    0 0xffffff80018b6000 0x7000     0x7000     com.apple.driver.AppleSSE (1.0) 59F98016-B7A6-3538-8C5E-ABF400FA3EE6 <23 18 17 8 6 5 3 1>
   36    2 0xffffff8001aa9000 0x7000     0x7000     com.apple.iokit.CoreAnalyticsFamily (1) CB8BC944-2B59-355C-A5D6-05FE908EBF67 <8 7 6 5 3 1>
   37    2 0xffffff80017fd000 0x3000     0x3000     com.apple.kext.AppleMatch (1.0.0d1) 82D16ED7-54AB-3562-9ABF-05E96C622BF6 <5 1>
   38    3 0xffffff800321a000 0x44000    0x44000    com.apple.security.sandbox (300.0) 2BC91DC8-F0AF-3762-B99A-53A1CF504978 <37 30 28 8 7 6 5 3 2 1>
   39    2 0xffffff8003211000 0x8000     0x8000     com.apple.security.quarantine (4) 1C99CAC8-F001-3CEE-92E1-BB2CFC5A4D8F <38 37 8 7 6 5 3 2 1>
   40    0 0xffffff8001b86000 0x4c000    0x4c000    com.apple.iokit.EndpointSecurity (1) 77BEC648-BF3B-3BC3-B2D9-27CA8967CC51 <39 28 8 7 6 5 3 2 1>
   41    1 0xffffff8002858000 0x6000     0x6000     com.apple.iokit.IOBluetoothPacketLogger (8.0.3d9) 097BD1D7-B43F-3B74-B331-C40C51F32A46 <7 6 5 3 1>
   42   10 0xffffff8002c55000 0x3000     0x3000     com.apple.iokit.IOReportFamily (47) D3C4FAA4-8F06-3C5C-AB36-4BE632CCE051 <6 5 3>
   43    5 0xffffff800276a000 0x9e000    0x9e000    com.apple.iokit.IOBluetoothFamily (8.0.3d9) EF7A0345-A992-34DD-A26F-C853D623D78B <42 41 22 13 8 7 6 5 3 1>
   44    0 0xffffff8002895000 0xc000     0xc000     com.apple.driver.DiskImages (493.0.0) 11E51AF9-6467-39AC-89A2-A62CE763F298 <30 8 7 6 5 3 1>
   45    0 0xffffff8002962000 0x1000     0x1000     com.apple.iokit.IOKitRegistryCompatibility (1) 2D92E372-8280-3FC3-B646-9FB3667B8D3D <5 3>
   46   10 0xffffff8002996000 0x17000    0x17000    com.apple.iokit.IONetworkingFamily (3.4) CEA28E53-3048-362D-B58E-3A02FFC20EA9 <8 7 6 5 3 1>
   47    2 0xffffff8002e87000 0x1b000    0x1b000    com.apple.iokit.IOTimeSyncFamily (900.11) E181C003-3A97-339B-BD7D-26FECFDA8CF2 <46 6 5 3 1>
   48   12 0                  0x8a000    0x8a000    as.vit9696.Lilu (1.6.7) 039F3B4B-9F80-33EE-9A16-F67DCE917B54 <8 6 5 3 2 1>
   49    0 0                  0xbd000    0xbd000    as.vit9696.WhateverGreen (1.6.6) DAD00AEB-D725-3AE3-9413-58EF7FF544D7 <48 14 8 6 5 3 2 1>
   50    2 0xffffff80034b7000 0xab000    0xab000    com.apple.vecLib.kext (1.2.0) 528BC21D-5AEB-365D-98CD-E3489B4C37DA <9 8 7 6 5 3>
   51    5 0xffffff800273b000 0x1e000    0x1e000    com.apple.iokit.IOAudioFamily (300.6.1) 8CBD98F6-7011-35DA-B0A7-47EF6636B572 <50 6 5 3 1>
   52    0 0                  0x18000    0x18000    org.tw.CodecCommander (2.7.1) 114866EA-9E10-3A75-8084-CEEE9D344D9F <51 14 13 5 3 1>
   53    0 0                  0x1cc000   0x1cc000   as.vit9696.AppleALC (1.8.6) 18A7C47A-6E1D-3BC4-8064-7E38F09B2336 <48 14 8 6 5 3 1>
   54    1 0                  0xb000     0xb000     com.alexandred.VoodooI2CServices (1) DBFA5EBE-2783-30ED-8E39-5829C42D6832 <5 3>
   55    0 0                  0x17000    0x17000    org.acidanthera.NVMeFix (1.1.1) 5DC6B2B2-6835-31AF-8A05-89B60EF52FB6 <48 8 6 5 3 2 1>
   56    0 0                  0xf000     0xf000     com.zxystd.IntelBTPatcher (2.4.0) 06D53ACB-3381-3B25-BBA8-403841B1AE25 <48 22 8 6 5 3 2 1>
   57   14 0xffffff80028d2000 0x5d000    0x5d000    com.apple.iokit.IOHIDFamily (2.0.0) 4A62A5E5-1CB2-3B05-8BBD-5044EF737AC0 <42 8 7 6 5 3 2 1>
   58    0 0                  0xc000     0xc000     as.acidanthera.BrightnessKeys (1.0.3) A6BF7D8A-0A1D-341F-B3CD-3C21A1E4E414 <57 48 13 8 6 5 3 1>
   59    0 0                  0xf000     0xf000     com.1Revenger1.ECEnabler (1.0.4) FAC43E50-D32E-394E-894D-6A408D8E5DF6 <48 8 6 5 3 2 1>
   60    4 0                  0x29000    0x29000    as.vit9696.VirtualSMC (1.3.2) 71035DEB-98F5-3B4E-BBF0-ED7E662A498A <48 13 8 6 5 3 1>
   61    4 0xffffff8002cd8000 0x1000     0x1000     com.apple.iokit.IOSMBusFamily (1.1) 1B91C74F-E16F-30B0-93C2-B16EA181DC59 <6 5 3>
   62    0 0                  0x1a000    0x1a000    ru.usrsse2.SMCBatteryManager (1.3.2) 0AE79B59-2E84-3B5F-A6B8-187E71D990CA <61 60 48 13 8 6 5 3 1>
   63    0 0                  0x16000    0x16000    as.lvs1974.SMCDellSensors (1.3.2) EE6171BE-FCD9-3C83-B7C4-7AA2891BB6C0 <60 48 8 6 5 3 2 1>
   64    0 0                  0xb000     0xb000     ru.usrsse2.SMCLightSensor (1.3.2) 6E4EDA3A-BE36-377E-8DF0-AF19868A014F <60 48 13 8 6 5 3 2 1>
   65    0 0                  0xb000     0xb000     org.vanilla.driver.CPUFriend (1.2.4) A6C993B8-8837-37CD-BDEF-CE3A0A8E098D <48 13 8 6 5 3 2 1>
   66    0 0                  0x12000    0x12000    com.sicreative.VoltageShift (1.24) 312963A2-7405-3406-9C5B-83B9887406A8 <5 3>
   67    0 0xffffff8001288000 0x9000     0x9000     com.apple.nke.applicationfirewall (310) D31A7A1B-3D95-3727-BC98-719DD7756B8D <8 7 6 5 3 1>
   68    1 0xffffff80016cf000 0x10000    0x10000    com.apple.security.AppleImage4 (3.0.0) 5D746F35-15A8-3406-8725-8867038D656D <10 8 7 5 3 1>
   69    0 0xffffff800190b000 0xe000     0xe000     com.apple.AppleSystemPolicy (2.0.0) 6756BBFE-4F94-3A32-AF9A-377AE3136B0E <39 38 28 8 7 6 5 3 2 1>
   70    0 0xffffff800132f000 0x2000     0x2000     com.apple.driver.AppleAPIC (1.7) A598BD53-CDC1-3CDB-B9A3-5D504B859FA9 <14 5 3>
   71    0 0xffffff8001891000 0x3000     0x3000     com.apple.driver.AppleSMBIOS (2.1) 6AD3FBAC-858E-3372-8DAF-69F54979BF82 <8 5 3>
   72    0 0xffffff80016a2000 0x2000     0x2000     com.apple.driver.AppleHPET (1.8) F676213C-6F1A-3B99-9B14-2F97DAFB8162 <13 8 6 5 3>
   73    0 0xffffff8001317000 0x2000     0x2000     com.apple.driver.AppleACPIButtons (6.1) 0CFFA69C-CBF7-3998-9677-9937E377E15D <57 42 16 13 8 7 6 5 3 1>
   74    1 0                  0x27000    0x27000    org.coolstar.VoodooGPIO (1.1) 7ED39A4D-2EFD-35AE-9BC6-6215C17D93F1 <13 6 5 3>
   75    1 0                  0x19000    0x19000    as.acidanthera.voodoo.driver.PS2Controller (2.3.5) 1D4D74E8-0696-3777-8F2A-17EF560A50AA <13 8 6 5 3 1>
   76    0 0xffffff8001861000 0x6000     0x6000     com.apple.driver.AppleRTC (2.0) 975447E5-D440-3234-954F-2EEDC204910A <13 8 6 5 3 1>
   77    0 0xffffff800131c000 0x5000     0x5000     com.apple.driver.AppleACPIEC (6.1) 0912BC2E-5CBA-3EA6-9B82-59C837DC754B <61 57 42 16 13 8 7 6 5 3 1>
   78    1 0xffffff8001657000 0x2000     0x2000     com.apple.driver.AppleEFIRuntime (2.1) DFD17EE5-E4FE-319E-9191-EFEEA53690DA <8 7 6 5 3>
   79    3 0xffffff800165a000 0xa000     0xa000     com.apple.driver.AppleEFINVRAM (2.1) D6C13E44-3657-3F40-99E4-355DAA82202E <78 8 7 6 5 3 1>
   80    1 0xffffff80030f0000 0x4f000    0x4f000    com.apple.driver.usb.AppleUSBXHCI (1.2) D623BBDD-59E1-3494-BE57-0F4AFD1CF853 <22 20 13 8 7 6 5 3 1>
   81    0 0xffffff8003148000 0x28000    0x28000    com.apple.driver.usb.AppleUSBXHCIPCI (1.2) 279DC1E0-EDF4-3931-83DC-CF11DC249E98 <80 22 20 14 13 8 7 6 5 3 1>
   82    1 0                  0x2a000    0x2a000    com.alexandred.VoodooI2C (2.8) 32040AEF-5627-3CBB-B1B1-7F91309B82F7 <74 57 54 14 13 6 5 3 1>
   83    0 0                  0x46000    0x46000    ru.joedm.SMCSuperIO (1.3.2) 3C126AAE-6C46-3A48-A7BA-441448384DAF <60 48 13 8 6 5 3 2 1>
   84    0 0                  0x34000    0x34000    com.alexandred.VoodooI2CHID (1) 1E31C431-D53C-3632-A18B-64F58F53D280 <82 57 13 6 5 3>
   85    0 0xffffff8002964000 0x2a000    0x2a000    com.apple.iokit.IONVMeFamily (2.1.0) D5DFC80E-EF7A-3660-BE57-473E67626B44 <79 42 30 28 14 8 7 6 5 3 1>
   86    1 0xffffff80033e4000 0x17000    0x17000    com.apple.driver.corecapture (1.0.4) DDCF23B4-962A-3A18-B089-CD07BDAD9A35 <8 7 6 5 3 1>
   87    1 0xffffff8002c19000 0x5000     0x5000     com.apple.driver.mDNSOffloadUserClient (1.0.1b8) 35ABC470-4743-30AC-9BA8-4A62CFA2296D <46 5 3 1>
   88    2 0xffffff8002ce9000 0x3e000    0x3e000    com.apple.iokit.IOSkywalkFamily (1) 882D8199-A1D6-3A53-9A83-1D11A15DECFA <87 46 8 7 6 5 3 1>
   89    1 0xffffff8001c40000 0x13a000   0x13a000   com.apple.iokit.IO80211Family (1200.12.2b1) 27EDE1C0-32A1-3BC9-A93A-49B4E7AD2167 <88 86 46 28 10 8 7 6 5 3 1>
   90    0 0                  0xf9b000   0xf9b000   com.zxystd.AirportItlwm (2.3.0) 7A97F4EB-76DB-3EDA-8326-920D801E23DE <89 46 14 6 5 3 1>
   91    1 0xffffff8002d87000 0xd9000    0xd9000    com.apple.iokit.IOThunderboltFamily (9.3.2) 73A0BDC8-85DE-3B44-99A7-A864CA44D289 <15 6 5 3 1>
   92    0 0xffffff8001964000 0x30000    0x30000    com.apple.driver.AppleThunderboltNHI (7.2.8) CD53D1A8-1CA7-3041-BC61-EF4A58B0758B <91 14 13 7 6 5 3 1>
   94    1 0xffffff8003276000 0x163000   0x163000   com.apple.filesystems.apfs (1677.81.1) DB8F6842-2D8F-3535-8352-54EBDD26900F <79 68 36 30 25 10 8 7 6 5 3 2 1>
   95    0 0                  0x1b000    0x1b000    me.kishorprins.VoodooInput (1.1.4) 00E6EEA3-7FF2-3367-A2E9-1C5109A3E8E2 <57 6 5 3>
   96    1 0xffffff8002863000 0xf000     0xf000     com.apple.driver.IOBluetoothHIDDriver (8.0.3d9) 5AE6FD64-33E9-33E9-8001-B2B1289535B2 <57 43 6 5 3>
   97    1 0xffffff80019c8000 0x6000     0x6000     com.apple.driver.AppleHSBluetoothDriver (4030.5) C816C61B-E933-354F-B844-521080A4FD59 <96 57 43 7 6 5 3 1>
   98    2 0xffffff80016e4000 0xd000     0xd000     com.apple.driver.AppleInputDeviceSupport (4400.35) E537E671-F2B3-3A8D-A70F-17BE6143FC92 <36 17 6 5 3 1>
   99    2 0xffffff8001825000 0x14000    0x14000    com.apple.driver.AppleMultitouchDriver (4400.28) D6F49AEB-08D3-3701-B74F-B243243A253F <98 57 42 8 6 5 3 1>
  100    0 0xffffff80019d1000 0x7000     0x7000     com.apple.driver.AppleTopCaseHIDEventDriver (4030.5) 76F0CBD7-F1A6-3FE5-9BC9-F82A111B11AC <99 97 57 7 6 5 3 1>
  101    0 0xffffff8001332000 0x7000     0x7000     com.apple.driver.AppleActuatorDriver (4400.28) BEB8D1A8-32D6-313D-B13A-17594045D021 <99 98 57 42 8 6 5 3 1>
  102    0 0                  0xf000     0xf000     as.acidanthera.voodoo.driver.PS2Keyboard (2.3.5) 5D8E3386-829F-38F9-B971-B25FBA437C3C <75 57 8 6 5 3 1>
  103    0 0xffffff80031e5000 0x1000     0x1000     com.apple.private.KextAudit (1.0) F8D19031-5AF3-30AC-982F-D51A7A941DBD <15 8 7 6 5 3>
  104    0 0xffffff8002eaf000 0x63000    0x63000    com.apple.iokit.IOUSBFamily (900.4.2) F474B853-D7A0-3C87-BAD8-8C16049A08F8 <22 20 14 8 6 5 3 1>
  105    0 0xffffff800304f000 0x2000     0x2000     com.apple.driver.usb.AppleUSBHostPacketFilter (1.0) 6D208E1B-AE2C-3DE4-80DE-2B1D0F5C46C2 <22 20 8 7 6 5 3 1>
  106    0 0xffffff80018bf000 0x11000    0x11000    com.apple.driver.AppleSmartBatteryManager (161.0.0) 81E73A5A-759D-3F2D-923D-0803C9F7AB6A <61 15 13 6 5 3 1>
  107    0 0xffffff800167f000 0x2000     0x2000     com.apple.AppleFSCompression.AppleFSCompressionTypeDataless (1.0.0d1) 1C6A2FF2-53DF-3274-AF90-1C4D432519F5 <8 7 5 3 2 1>
  108    0 0xffffff8001682000 0x9000     0x9000     com.apple.AppleFSCompression.AppleFSCompressionTypeZlib (1.0.0) F986F845-36B3-34A6-86E8-32870C739DDC <7 5 3 2 1>
  109    0 0xffffff8001a9b000 0xc000     0xc000     com.apple.BootCache (40) 5FF5DE96-C153-37AE-96BA-057BB841EFD9 <8 7 6 5 3 1>
  110    1 0xffffff8001c3d000 0x2000     0x2000     com.apple.filesystems.hfs.encodings.kext (1) 99860746-6E6D-383E-BBAD-9EA92F3C189F <8 7 6 5 3 1>
  111    1 0xffffff8001bd8000 0x63000    0x63000    com.apple.filesystems.hfs.kext (556.60.1) CA235EAE-E294-3F07-B75B-36CF5D5287E4 <110 8 7 6 5 3 1>
  112    2 0xffffff8002d66000 0x1c000    0x1c000    com.apple.iokit.IOSurface (289.3) 22DEF369-CE8F-3ACF-BD1E-4CE16AAB209A <8 7 6 5 3 1>
  113    0 0xffffff8001567000 0x1000     0x1000     com.apple.driver.AppleBSDKextStarter (3) F512DB7A-E949-364B-893A-B155C919EF2F <5 3>
  114    0 0xffffff80034aa000 0xc000     0xc000     com.apple.filesystems.tmpfs (1) 33EBC2A2-A8BD-33B8-B821-0FB4F5B2EC77 <8 7 6 5 1>
  116    0 0                  0xafd000   0xafd000   com.zxystd.IntelBluetoothFirmware (2.4.0) F9DD55B4-27C6-39D5-AAFC-C599DB3DEBCA <22 6 5 3>
  117    2 0xffffff8002833000 0x5000     0x5000     com.apple.iokit.IOBluetoothHostControllerTransport (8.0.3d9) A5E9BD21-89A1-30A6-85C2-E09108461821 <43 22 14 13 8 7 6 5 3 1>
  118    1 0xffffff800283e000 0x18000    0x18000    com.apple.iokit.IOBluetoothHostControllerUSBTransport (8.0.3d9) FE41F4A9-D10B-343C-BB26-9CB317F752F1 <117 43 22 14 13 8 7 6 5 3 1>
  119    0 0xffffff8002821000 0x7000     0x7000     com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport (8.0.3d9) 30678A52-91FE-37AB-9E35-A3F637F3FFB3 <118 117 43 22 14 13 8 7 6 5 3>
  120    3 0xffffff8003048000 0x3000     0x3000     com.apple.driver.usb.AppleUSBHostCompositeDevice (1.2) E262EB63-C5DE-39E7-81A8-7D392721EF73 <22 20 7 6 5 3 1>
  121    3 0xffffff8001a2a000 0x2000     0x2000     com.apple.driver.usb.networking (5.0.0) 9B5DD9DF-9A0D-31C5-80E0-670D6AFD6EF5 <22 7 6 5 3 1>
  122    2 0xffffff80019de000 0x2000     0x2000     com.apple.driver.usb.cdc (5.0.0) B246DA0A-7913-37F2-AB4E-38CD5B154A19 <121 120 22 6 5 3 1>
  124    0 0xffffff8003052000 0x2b000    0x2b000    com.apple.driver.usb.AppleUSBHub (1.2) 7699C6C9-BEF3-358D-817A-C2F1C8D0DEDD <22 20 13 6 5 3 1>
  125    0 0xffffff8003045000 0x2000     0x2000     com.apple.driver.usb.AppleUSBHostBillboardDevice (1.0) 83258EC3-7FF2-36E4-8979-A68499E7BE0B <22 20 6 5 3 1>
  126    0 0xffffff8001a2d000 0x3000     0x3000     com.apple.driver.usb.realtek8153patcher (5.0.0) 0C58685F-3662-3A4D-AF8C-8B0AA87D046D <22 6 5 3 1>
  129    0 0xffffff8001a21000 0x7000     0x7000     com.apple.driver.usb.cdc.ncm (5.0.0) CD9A1845-EEE9-39FF-A333-D36D98037AEB <122 121 120 46 42 22 7 6 5 3 1>
  130    3 0xffffff7fa0ab3000 0x4000     0x4000     com.apple.driver.IOPlatformPluginFamily (6.0.0d8) 781FB738-E551-3048-A081-CDA1E2092212 <13 8 7 6 5 3>
  131    1 0xffffff7fa0ada000 0x14000    0x14000    com.apple.driver.X86PlatformPlugin (1.0.0) 0A781B73-564E-3AA8-AFF9-718BCF2B9712 <130 22 15 13 8 7 6 5 3 1>
  134    2 0xffffff8002c05000 0x2000     0x2000     com.apple.iokit.IOEthernetAVBController (1.1.0) CE70C64A-A310-3F71-B061-88A5887A8941 <46 6 5 3 1>
  135    1 0xffffff7fa0b0e000 0x68000    0x68000    com.apple.plugin.IOgPTPPlugin (900.11) F295D470-2D07-3050-873C-0F7948844A95 <134 88 57 47 46 9 7 6 5 3 1>
  139   15 0xffffff7fa0a63000 0x2f000    0x2f000    com.apple.iokit.IOGraphicsFamily (585) EF8876FC-C6D6-3D53-9915-762EF4F12870 <14 8 6 5 3 1>
  140    5 0xffffff7f9f1b7000 0x4000     0x4000     com.apple.AppleGraphicsDeviceControl (6.2.2) 867CDCFC-72A3-390B-B252-5F0F9390C1AF <139 14 8 7 6 5 3 1>
  141    2 0xffffff7fa090b000 0x6a000    0x6a000    com.apple.iokit.IOAcceleratorFamily2 (439.52) 7B467C8D-2528-3663-8024-B09E1DCED75A <139 112 42 28 14 8 7 6 5 3 1>
  142    0 0xffffff7f9f653000 0xbf000    0xbf000    com.apple.driver.AppleIntelCFLGraphicsFramebuffer (16.0.1) 9E24E6AB-A78F-3DF2-B7FA-2645B4B85BC1 <141 140 139 42 14 13 8 7 6 5 3 1>
  143    2 0xffffff7f9f405000 0x4000     0x4000     com.apple.iokit.IOHDAFamily (283.15) CFE5D674-E1F8-3EFC-8DEB-50FFF11C8D57 <6 5 3 1>
  144    1 0xffffff7f9f2e5000 0x13000    0x13000    com.apple.driver.AppleHDAController (283.15) 2180888A-8340-3930-9534-C3693D9599EA <143 139 51 14 8 7 6 5 3 1>
  148    4 0xffffff7fa0aa8000 0x9000     0x9000     com.apple.iokit.IONDRVSupport (585) 40BEBEA2-BBB5-3B09-B6AE-B4B372775FBD <139 14 8 6 5 3>
  149    1 0xffffff7fa0684000 0x7000     0x7000     com.apple.driver.AppleSMBusController (1.0.18d1) D69C0758-0371-369E-88ED-E11402B91008 <61 14 13 6 5 3>
  150    0 0xffffff7fa0634000 0xb000     0xb000     com.apple.driver.AppleMCCSControl (1.14) 4D16F699-71E8-3335-A706-A534F1D2B993 <149 139 15 14 13 8 6 5 3 1>
  152    0 0xffffff7f9ffc2000 0xb8000    0xb8000    com.apple.driver.AppleIntelKBLGraphics (16.0.1) 9F686C76-339E-3B4C-91F9-B9A742F8B1CB <141 139 112 14 8 7 6 5 3 1>
  153    3 0xffffff8002cda000 0x6000     0x6000     com.apple.iokit.IOSerialFamily (11) BFD092AF-19A4-37DD-AD69-6C36365D8044 <8 7 6 5 3 1>
  154    1 0xffffff7fa0774000 0x3000     0x3000     com.apple.driver.usb.serial (6.0.0) 4527DAE7-D093-35A0-B72D-2F452FA9137F <153 22 6 5 3 1>
  155    0 0xffffff7fa070d000 0x2000     0x2000     com.apple.driver.usb.cdc.acm (5.0.0) 92526887-9BEE-3E17-A85D-3DFA1B862C74 <154 153 122 121 120 22 6 5 3 1>
  156    1 0xffffff7f9efe8000 0x2000     0x2000     com.apple.driver.AppleBacklightExpert (1.1.0) 29E038A5-5B0C-37EA-A92C-52C8744FF59F <148 139 15 14 6 5 3>
  157    0 0xffffff7f9efe3000 0x3000     0x3000     com.apple.driver.AppleBacklight (180.3) 13F78CBD-7588-3F9A-893A-50DE0B154B96 <156 148 139 14 6 5 3>
  159    1 0xffffff8002d3c000 0x2000     0x2000     com.apple.iokit.IOSlowAdaptiveClockingFamily (1.0.0) A0FE30D2-102E-334B-A1CD-660522D4F14E <8 7 6 5 3 1>
  160    0 0xffffff7fa062f000 0x1000     0x1000     com.apple.driver.AppleIntelSlowAdaptiveClocking (4.0.0) E418234E-462F-3CC8-A573-17078E40C0DE <159 5 3>
  161    0 0xffffff7fa23c7000 0x3000     0x3000     com.intel.driver.PcmMsr (1) 10C068DB-3E2F-39D4-80ED-275885FCFDC6 <8 6 5 3 1>
  162    0 0xffffff7f9f1ad000 0x7000     0x7000     com.apple.AppleGPUWrangler (6.2.2) 6F5CDA38-68B4-301D-B459-CEC6F7186D0F <140 139 14 8 7 6 5 3 1>
  163    0 0xffffff7fa077a000 0x3000     0x3000     com.apple.driver.AppleUpstreamUserClient (3.6.8) 1F766D0B-7CF1-3D05-AF80-2A7D62003F7B <139 14 13 8 6 5 3 1>
  164    1 0xffffff7fa11fd000 0xf000     0xf000     com.apple.kext.OSvKernDSPLib (529) 8F4BD574-40D0-339E-8F82-17109DD9E7E4 <6 5>
  165    1 0xffffff7f9f312000 0xe3000    0xe3000    com.apple.driver.DspFuncLib (283.15) 7F9AFBE5-C181-38BB-A6E3-C75B1D6CD8D9 <164 79 51 50 7 6 5 3 1>
  166    0 0xffffff7f9f230000 0x90000    0x90000    com.apple.driver.AppleHDA (283.15) 89B2DAFE-09C2-38F5-8218-51EAEC799425 <165 148 144 143 139 51 7 6 5 3 1>
  167    0 0xffffff7f9f0a2000 0xc000     0xc000     com.apple.driver.AppleDiskImages2 (1) E6E4351B-D4E8-3F24-AE7D-45B665E4C4E5 <30 6 5 3 1>
  168    0 0xffffff7f9f40d000 0xa000     0xa000     com.apple.driver.AppleHV (1) E718C011-691A-35C1-B0A7-AEC1025E19CA <38 8 7 6 5 3 1>
  169    0 0xffffff7fa07a3000 0x3000     0x3000     com.apple.Dont_Steal_Mac_OS_X (7.0.0) C23783B5-21C5-3084-B67A-BB994F502C6A <15 10 8 5 3 1>
  170    0 0xffffff7fa08a6000 0x13000    0x13000    com.apple.iokit.IOAVBFamily (930.1) 6C5052C9-A983-3626-863C-171013064822 <135 134 47 46 7 6 5 3 1>
  171    0 0xffffff7fa0994000 0x7000     0x7000     com.apple.iokit.IOBluetoothSerialManager (8.0.3d9) B780E5DD-B4DD-3355-A631-9CFEAF0CFC59 <153 8 6 5 3 1>
  172    0 0xffffff7fa0b9f000 0x19000    0x19000    com.apple.driver.usb.AppleUSBUserHCI (1) 6FE7E24C-5793-3AFF-AAFF-9DB4F82066BA <22 20 6 5 3 1>
  173    0 0xffffff7fa0bbe000 0x3000     0x3000     com.apple.iokit.IOUserEthernet (1.0.1) D95650D2-397D-3A31-A8E5-5B74994EAAC6 <46 7 6 5 3 1>
  174    0 0xffffff7fa0bd8000 0x3000     0x3000     com.apple.driver.LuaHardwareAccess (1.0.16) DDAC3137-602E-3520-A3E1-C1ACAF357044 <8 7 6 5 3 1>
  175    0 0xffffff7fa144b000 0x8000     0x8000     com.apple.driver.pmtelemetry (1) 1B9A3B60-046F-3858-9A8E-EFFD697C01C0 <8 7 6 5 3 1>
  176    0 0xffffff7f9f1aa000 0x2000     0x2000     com.apple.AGDCPluginDisplayMetrics (6.2.2) 60FC04B2-C96B-37B3-8046-31A09912C52C <140 8 7 6 5 3 1>
  177    1 0xffffff7f9f1a3000 0x1000     0x1000     com.apple.driver.AppleGraphicsControl (6.2.2) B1CF4471-53CC-316E-BFB2-1C94052E6ED0 <8 6 5 3 1>
  178    0 0xffffff7f9f1bf000 0x9000     0x9000     com.apple.driver.AppleGraphicsDevicePolicy (6.2.2) D05F43EC-C765-339C-97F3-2E1633C9E630 <177 140 139 14 13 8 7 6 5 3 1>
  180    3 0xffffff7fa13ed000 0x5d000    0x5d000    com.apple.filesystems.ntfs (3.14.3) EFE3E119-6AD2-3DFC-8133-32EDB79BCE42 <8 7 6 5 1>
  181    2 0xffffff7fa14d4000 0x3000     0x3000     com.apple.kext.triggers (1.0) D4AC084E-97BE-37BC-BEB5-BE9A4BD1705D <8 7 6 5 3 1>
  182    0 0xffffff7fa13ab000 0x8000     0x8000     com.apple.filesystems.autofs (3.0) 6BADA3B0-3B9B-3385-9465-3902DD9AB114 <181 8 7 6 5 3 2 1>
  183    0 0xffffff7f9f110000 0x17000    0x17000    com.apple.fileutil (20.036.15) 4A53F82C-2C04-3148-A67B-9DFC24C5312C <6 5 3 2 1>
  184    0 0xffffff7fa0785000 0x3000     0x3000     com.apple.driver.AudioAUUC (1.70) 2DB3C567-43FA-309A-8388-B6756C05D67F <139 51 14 13 8 6 5 3 1>
  185    1 0xffffff7fa0aef000 0x6000     0x6000     com.apple.driver.X86PlatformShim (1.0.0) E2E5D882-7FAF-3E79-ABD9-CEE57429403D <131 130 15 8 5 3>
  186    0 0xffffff7f9f20f000 0x1d000    0x1d000    com.apple.driver.AGPM (119) 5728C057-EAAC-341C-87D9-81FC917CDCF9 <148 140 139 130 14 7 6 5 3 1>
  187    0 0xffffff7fa0680000 0x2000     0x2000     com.apple.driver.ApplePlatformEnabler (2.7.0d0) A21C2B68-5CCE-3036-80CC-B232460CA1E1 <8 6 5 3>
  188    0 0xffffff8001692000 0x4000     0x4000     com.apple.driver.AppleHIDKeyboard (223) DB52914E-103E-3DA3-B378-03F6CED02A89 <57 7 6 5 3>
  189    0 0xffffff7fa1466000 0x6a000    0x6a000    com.apple.filesystems.smbfs (3.4.1) 25B4D36D-9E80-3737-A383-5C00EC04C221 <181 10 8 7 6 5 3 1>

macos version 11.2.3 (20D91)
XCode Version 12.5.1 (12E507)
Apple clang version 12.0.5 (clang-1205.0.22.11)

@opcm
Copy link
Contributor

opcm commented Oct 6, 2024

Below is the output of pcm.

 Intel(r) Performance Counter Monitor ($Format:%ci ID=%h$)


=====  Processor information  =====
Hybrid processor         : no
IBRS and IBPB supported  : yes
STIBP supported          : yes
Spec arch caps supported : yes
Max CPUID level          : 22
CPU family               : 6
CPU model number         : 166
IOServiceOpen returned 0xe00002c7
Unable to build CPU topology
WARNING: Core 0 IA32_PERFEVTSEL0_ADDR is not zeroed 18446744073709551615
Access to Intel(r) Performance Counter Monitor has denied (Performance Monitoring Unit is occupied by other application). Try to stop the application that uses PMU.
Alternatively you can try running PCM with option -r to reset PMU.
Cleaning up
 Zeroed PMU registers
 Zeroed uncore PMU registers

I tried to debug the code, below is the call stack.

libPcmMsr.dylib!MSRAccessor::read(unsigned int, unsigned long long, unsigned long long*) (/Users/bixian/pcm/src/MacMSRDriver/MSRAccessor.cpp:37)
pcm!pcm::MsrHandle::read(unsigned long long, unsigned long long*) (/Users/bixian/pcm/src/msr.cpp:140)
pcm!pcm::SafeMsrHandle::read(unsigned long long, unsigned long long*) (/Users/bixian/pcm/src/msr.h:76)
pcm!pcm::PCM::PMUinUse() (/Users/bixian/pcm/src/cpucounters.cpp:4720)
pcm!pcm::PCM::program(pcm::PCM::ProgramMode, void const*, bool, int) (/Users/bixian/pcm/src/cpucounters.cpp:3467)
pcm!mainThrows(int, char**) (/Users/bixian/pcm/src/pcm.cpp:1557)
pcm!main (/Users/bixian/pcm/src/pcm.cpp:1343)
libdyld.dylib!start (Unknown Source:0)
libdyld.dylib!start (Unknown Source:0)

And when the debugger step over kern_return_t ret = IOConnectCallStructMethod(connect, kReadMSR, &idatas, struct_size, &odatas, &struct_size);, the returned value is 268435459 rather than 0. Below is the code snippet and corresponding arguments passed into IOConnectCallStructMethod

int32_t MSRAccessor::read(uint32_t core_num, uint64_t msr_num, uint64_t * value)
{
    pcm_msr_data_t idatas, odatas;

    size_t struct_size = sizeof(pcm_msr_data_t);
    idatas.msr_num = (uint32_t)msr_num;
    idatas.cpu_num = core_num;

    kern_return_t ret = IOConnectCallStructMethod(connect, kReadMSR,
                                                  &idatas, struct_size,
                                                  &odatas, &struct_size);

    if(ret == KERN_SUCCESS)
    {
        *value = odatas.value;
        return sizeof(uint64_t);
    } else {
        return -1;
    }
}
idatas={
    value=0;
    cpu_num=0;
    mar_num=914;
}
struct_size=16
connect=0
kReadMSR=2

I did some research about IOConnectCallStructMethod. It seems IOConnectCallStructMethod is trying to send a struct to a kext and get the output struct, correct? And I double checked that SIP is disabled and com.intel.driver.PcmMsr is loaded.

I cannot diagnose anymore.

It fails already here (from your log):

IOServiceOpen returned 0xe00002c7
Unable to build CPU topology

cerr << "IOServiceOpen returned 0x" << hex << setw(8) << kernResult << dec << endl;

Code 0xE00002C7 means kIOReturnUnsupported

Not sure why it is not supported. In PCM we don't use kIOReturnUnsupported at all.

@opcm
Copy link
Contributor

opcm commented Oct 6, 2024

Could you try this from the howto:

Logging/Debugging

Sometimes you will get errors while running utilities that may come from the kernel, and you can use something like this DTrace script to correlate it with user-land behavior:

sudo dtrace -n 'fbt:mach_kernel:_ZN*IOUser*:return /execname == "pcm"/ { @hgram[probefunc, arg1, ustack(20)] = count(); }' -c ./pcm

Various commands that can help diagnose errors:

kmutil log stream
kmutil inspect -b com.intel.driver.PcmMsr

@liyuankunbix
Copy link
Author

Could you try this from the howto:

Logging/Debugging

Sometimes you will get errors while running utilities that may come from the kernel, and you can use something like this DTrace script to correlate it with user-land behavior:

sudo dtrace -n 'fbt:mach_kernel:_ZN*IOUser*:return /execname == "pcm"/ { @hgram[probefunc, arg1, ustack(20)] = count(); }' -c ./pcm

Various commands that can help diagnose errors:

kmutil log stream
kmutil inspect -b com.intel.driver.PcmMsr

It seems that I finally got pcm working. I disable SIP totally instead of disabling partially(only disabling Kext Signing and Filesystem Protections) and run pcm with option -r(sudo pcm -r). I believe that the terminal printing below is the output we expected. Correct?

 Intel(r) Performance Counter Monitor ($Format:%ci ID=%h$)



=====  Processor information  =====
Hybrid processor         : no
IBRS and IBPB supported  : yes
STIBP supported          : yes
Spec arch caps supported : yes
Max CPUID level          : 22
CPU family               : 6
CPU model number         : 166
Number of physical cores: 6
Number of logical cores: 12
Number of online logical cores: 12
Threads (logical cores) per physical core: 2
Num sockets: 1
Physical cores per socket: 6
Last level cache slices per socket: 6
Core PMU (perfmon) version: 4
Number of core PMU generic (programmable) counters: 4
Width of generic (programmable) counters: 48 bits
Number of core PMU fixed counters: 3
Width of fixed counters: 48 bits
Nominal core frequency: 1600000000 Hz
IBRS enabled in the kernel   : no
STIBP enabled in the kernel  : no
The processor is not susceptible to Rogue Data Cache Load: yes
The processor supports enhanced IBRS                     : yes
Package thermal spec power: 15 Watt; Package minimum power: 0 Watt; Package maximum power: 0 Watt;

Socket 0: 0 PCU units detected. 0 IIO units detected. 0 IRP units detected. 0 CHA/CBO units detected. 0 MDF units detected. 0 UBOX units detected. 0 CXL units detected. 0 PCIE_GEN5x16 units detected. 0 PCIE_GEN5x8 units detected.


 Resetting PMU configuration
 Zeroed PMU registers

Detected Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz "Intel(r) microarchitecture codename Comet Lake" stepping 0

 UTIL  : utlization (same as core C0 state active state residency, the value is in 0..1) 
 IPC   : instructions per CPU cycle
 CFREQ : core frequency in Ghz
 L3MISS: L3 (read) cache misses 
 L2MISS: L2 (read) cache misses (including other core's L2 cache *hits*) 
 L3HIT : L3 (read) cache hit ratio (0.00-1.00)
 L2HIT : L2 cache hit ratio (0.00-1.00)
 L3MPI : number of L3 (read) cache misses per instruction
 L2MPI : number of L2 (read) cache misses per instruction
 READ  : bytes read from main memory controller (in GBytes)
 WRITE : bytes written to main memory controller (in GBytes)
 IO    : bytes read/written due to IO requests to memory controller (in GBytes); this may be an over estimate due to same-cache-line partial requests
 IA    : bytes read/written due to IA requests to memory controller (in GBytes); this may be an over estimate due to same-cache-line partial requests
 GT    : bytes read/written due to GT requests to memory controller (in GBytes); this may be an over estimate due to same-cache-line partial requests
 TEMP  : Temperature reading in 1 degree Celsius relative to the TjMax temperature (thermal headroom): 0 corresponds to the max temperature
 energy: Energy in Joules


 Core (SKT) | UTIL | IPC  | CFREQ | L3MISS | L2MISS | L3HIT | L2HIT | L3MPI | L2MPI |  TEMP

   0    0     0.33   0.42    0.94     241 K    986 K    0.73    0.39  0.0018  0.0075     52
   1    0     0.02   0.27    0.97    1267       17 K    0.90    0.35  0.0003  0.0041     52
   2    0     0.22   0.57    0.99     162 K    754 K    0.75    0.41  0.0013  0.0061     51
   3    0     0.01   0.31    0.99    1178       15 K    0.88    0.36  0.0003  0.0035     51
   4    0     0.16   0.77    1.06     144 K    664 K    0.76    0.42  0.0011  0.0051     52
   5    0     0.01   0.36    1.01    1235       12 K    0.85    0.30  0.0003  0.0033     52
   6    0     0.11   0.88    1.02      68 K    290 K    0.72    0.38  0.0007  0.0029     50
   7    0     0.01   0.42    0.98     609     6273      0.86    0.35  0.0002  0.0019     50
   8    0     0.04   0.41    0.99      24 K    109 K    0.73    0.37  0.0016  0.0072     51
   9    0     0.01   0.51    0.97     437     5296      0.87    0.31  0.0001  0.0016     51
  10    0     0.02   1.33    1.24    6775       39 K    0.79    0.36  0.0002  0.0011     53
  11    0     0.00   0.63    0.95     347     3446      0.86    0.34  0.0001  0.0012     53
---------------------------------------------------------------------------------------------------------------
 SKT    0     0.08   0.60    0.99     654 K   2904 K    0.74    0.40  0.0012  0.0052     50
---------------------------------------------------------------------------------------------------------------
 TOTAL  *     0.08   0.60    0.99     654 K   2904 K    0.74    0.40  0.0012  0.0052     N/A

 Instructions retired:  561 M ; Active cycles:  939 M ; Time (TSC): 1613 Mticks ; C0 (active,non-halted) core residency: 7.83 %

 C1 core residency: 11.45 %; C3 core residency: 0.09 %; C6 core residency: 0.00 %; C7 core residency: 80.63 %;
 C0 package residency: 57.13 %; C2 package residency: 18.34 %; C3 package residency: 24.53 %; C6 package residency: 0.00 %; C7 package residency: 0.00 %; C8 package residency: 0.00 %; C9 package residency: 0.00 %; C10 package residency: 0.00 %;
                             ┌────────────────────────────────────────────────────────────────────────────────┐
 Core    C-state distribution│00000011111111177777777777777777777777777777777777777777777777777777777777777777│
                             └────────────────────────────────────────────────────────────────────────────────┘
                             ┌─────────────────────────────────────────────────────────────────────────────────┐
 Package C-state distribution│000000000000000000000000000000000000000000000022222222222222233333333333333333333│
                             └─────────────────────────────────────────────────────────────────────────────────┘
---------------------------------------------------------------------------------------------------------------

MEM (GB)->|  READ |  WRITE |   IO   |   IA   |   GT   | CPU energy | PP0 energy | PP1 energy |
---------------------------------------------------------------------------------------------------------------
 SKT   0     2.66     0.49     1.78     0.84     0.46       3.79       0.74       0.03
---------------------------------------------------------------------------------------------------------------

For now, my only question is, according to your opinion, which of SIP items are required to make pcm works? You may just provide some suggestions or give me some hints and I will keep trying and testing.

  1. Apple Internal
  2. Kext Signing
  3. Filesystem Protections
  4. Debugging Restrictions
  5. DTrace Restrictions
  6. NVRAM Protections
  7. BaseSystem Verification

@opcm
Copy link
Contributor

opcm commented Oct 6, 2024

yes, this is expected output. Unfortunately I don't have access to MacOS system right now. Your help is much appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants