PhysicalMemory (macOS): improves performance on Apple Silicon

This commit is contained in:
李通洲
2025-12-27 15:57:20 +08:00
parent 7e557a06b3
commit 9c870a57f0
@@ -2,6 +2,7 @@
#include "common/processing.h"
#include "util/smbiosHelper.h"
#include "util/stringUtils.h"
#include "util/apple/cf_helpers.h"
#import <Foundation/Foundation.h>
@@ -64,7 +65,7 @@ static void appendDevice(
}
}
const char* ffDetectPhysicalMemory(FFlist* result)
static const char* detectFromSystemProfiler(FFlist* result)
{
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
if (ffProcessAppendStdOut(&buffer, (char* const[]) {
@@ -119,3 +120,43 @@ const char* ffDetectPhysicalMemory(FFlist* result)
return NULL;
}
FF_MAYBE_UNUSED static const char* detectFromIokit(FFlist* result)
{
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryDevice = IORegistryEntryFromPath(kIOMainPortDefault, "IODeviceTree:/chosen");
if (!entryDevice)
return "IORegistryEntryFromPath() failed";
FF_CFTYPE_AUTO_RELEASE CFTypeRef dramType = IORegistryEntryCreateCFProperty(entryDevice, CFSTR("dram-type"), kCFAllocatorDefault, 0);
FF_CFTYPE_AUTO_RELEASE CFTypeRef dramSize = IORegistryEntryCreateCFProperty(entryDevice, CFSTR("dram-size"), kCFAllocatorDefault, 0);
FF_CFTYPE_AUTO_RELEASE CFTypeRef dramVendor = IORegistryEntryCreateCFProperty(entryDevice, CFSTR("dram-vendor"), kCFAllocatorDefault, 0);
if (!dramType || !dramSize || !dramVendor)
return "IORegistryEntryCreateCFProperty() failed";
FFPhysicalMemoryResult* device = ffListAdd(result);
ffStrbufInit(&device->type);
ffStrbufInit(&device->formFactor);
ffStrbufInit(&device->locator);
ffStrbufInit(&device->vendor);
ffStrbufInit(&device->serial);
ffStrbufInit(&device->partNumber);
device->size = 0;
device->maxSpeed = 0;
device->runningSpeed = 0;
device->ecc = false;
ffCfStrGetString(dramType, &device->type);
ffCfStrGetString(dramVendor, &device->vendor);
ffCfNumGetInt64(dramSize, (int64_t*) &device->size);
return NULL;
}
const char* ffDetectPhysicalMemory(FFlist* result)
{
#if __aarch64__
if (detectFromIokit(result) == NULL)
return NULL;
#endif
return detectFromSystemProfiler(result);
}