Skip to content

Commit

Permalink
Improved performance with Lilu 1.4.3 APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Mar 28, 2020
1 parent a75f1b0 commit bd58d87
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 38 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
VirtualSMC Changelog
====================
#### v1.1.2
- Improved performance with Lilu 1.4.3 APIs

#### v1.1.1
- Fixed SMCSuperIO crashes with unsupported chips
- SMCSuperIO detected chip name to ioreg
Expand Down
59 changes: 31 additions & 28 deletions Sensors/SMCProcessor/SMCProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <VirtualSMCSDK/kern_vsmcapi.hpp>
#include <Headers/kern_time.hpp>
#include <Headers/kern_devinfo.hpp>
#include <IOKit/IODeviceTreeSupport.h>
#include <IOKit/IOTimerEventSource.h>

Expand Down Expand Up @@ -267,7 +268,11 @@ bool SMCProcessor::start(IOService *provider) {
return false;
}

cpuGeneration = CPUInfo::getGeneration(&cpuFamily, &cpuModel, &cpuStepping);
auto &bdi = BaseDeviceInfo::get();
cpuGeneration = bdi.cpuGeneration;
cpuFamily = bdi.cpuFamily;
cpuModel = bdi.cpuModel;
cpuStepping = bdi.cpuStepping;
if (cpuGeneration == CPUInfo::CpuGeneration::Unknown ||
cpuGeneration < CPUInfo::CpuGeneration::Penryn) {
SYSLOG("scpu", "failed to find a compatible processor");
Expand Down Expand Up @@ -331,36 +336,34 @@ bool SMCProcessor::start(IOService *provider) {

// Some laptop models start core sensors not with 0, but actually with 1.
size_t coreOffset = 0;
char model[80];
if (WIOKit::getComputerInfo(model, sizeof(model), nullptr, 0)) {
if (!strncmp(model, "MacBook", strlen("MacBook"))) {
auto rmodel = model + strlen("MacBook");
auto isdigit = [](auto l) { return l >= '0' && l <= '9'; };

if (!strncmp(rmodel, "Air", strlen("Air"))) {
// MacBookAir6,1 and above
const char *suffix = rmodel + strlen("Air");
if (isdigit(suffix[0]) && (isdigit(suffix[1]) || suffix[0] >= '6'))
coreOffset = 1;
} else if (!strncmp(model, "Pro", strlen("Pro"))) {
const char *suffix = rmodel + strlen("Pro");
if (isdigit(suffix[0]) && isdigit(suffix[1]) && ((suffix[0] == '1' && suffix[1] >= '3') || suffix[0] > '1')) {
// MacBookPro13,1 and above
coreOffset = 1;
} else {
// Select MacBookPro models of previous generations (excluding: 10,2; 11,1; 12,x)
const char *matches[] { "8,", "9,", "10,1", "11,2", "11,3", "11,4", "11,5" };
for (auto &match : matches) {
if (!strncmp(suffix, match, strlen(match))) {
coreOffset = 1;
break;
}
auto model = BaseDeviceInfo::get().modelIdentifier;
if (!strncmp(model, "MacBook", strlen("MacBook"))) {
auto rmodel = model + strlen("MacBook");
auto isdigit = [](auto l) { return l >= '0' && l <= '9'; };

if (!strncmp(rmodel, "Air", strlen("Air"))) {
// MacBookAir6,1 and above
const char *suffix = rmodel + strlen("Air");
if (isdigit(suffix[0]) && (isdigit(suffix[1]) || suffix[0] >= '6'))
coreOffset = 1;
} else if (!strncmp(model, "Pro", strlen("Pro"))) {
const char *suffix = rmodel + strlen("Pro");
if (isdigit(suffix[0]) && isdigit(suffix[1]) && ((suffix[0] == '1' && suffix[1] >= '3') || suffix[0] > '1')) {
// MacBookPro13,1 and above
coreOffset = 1;
} else {
// Select MacBookPro models of previous generations (excluding: 10,2; 11,1; 12,x)
const char *matches[] { "8,", "9,", "10,1", "11,2", "11,3", "11,4", "11,5" };
for (auto &match : matches) {
if (!strncmp(suffix, match, strlen(match))) {
coreOffset = 1;
break;
}
}
} else if (isdigit(rmodel[0]) && (isdigit(rmodel[1]) || rmodel[0] >= '8')) {
// MacBook8,1 and above
coreOffset = 1;
}
} else if (isdigit(rmodel[0]) && (isdigit(rmodel[1]) || rmodel[0] >= '8')) {
// MacBook8,1 and above
coreOffset = 1;
}
} else {
SYSLOG("scpu", "failed to get system model");
Expand Down
8 changes: 4 additions & 4 deletions VirtualSMC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1010;
LastUpgradeCheck = 1130;
LastUpgradeCheck = 1140;
ORGANIZATIONNAME = vit9696;
TargetAttributes = {
1C748C261C21952C0024EED2 = {
Expand Down Expand Up @@ -1461,7 +1461,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.8;
MODULE_VERSION = 1.1.1;
MODULE_VERSION = 1.1.2;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
VALID_ARCHS = x86_64;
Expand Down Expand Up @@ -1509,7 +1509,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.8;
MODULE_VERSION = 1.1.1;
MODULE_VERSION = 1.1.2;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
VALID_ARCHS = x86_64;
Expand Down Expand Up @@ -2128,7 +2128,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.8;
MODULE_VERSION = 1.1.1;
MODULE_VERSION = 1.1.2;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
VALID_ARCHS = x86_64;
Expand Down
3 changes: 2 additions & 1 deletion VirtualSMC/kern_keystore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <libkern/OSByteOrder.h>
#include <Headers/kern_atomic.hpp>
#include <Headers/kern_devinfo.hpp>
#include <Headers/kern_iokit.hpp>
#include <Headers/kern_util.hpp>
#include <Headers/kern_time.hpp>
Expand Down Expand Up @@ -348,7 +349,7 @@ bool VirtualSMCKeystore::mergePredefined(const char *board, int model) {
if (!addKey(KeyNum, valueNum))
return false;

SMC_DATA dataBEMB[] {WIOKit::getComputerModel() == WIOKit::ComputerModel::ComputerLaptop};
SMC_DATA dataBEMB[] {BaseDeviceInfo::get().modelType == WIOKit::ComputerModel::ComputerLaptop};
if (!addKey(KeyBEMB, VirtualSMCValueVariable::withData(
dataBEMB, sizeof(dataBEMB), SmcKeyTypeFlag, SMC_KEY_ATTRIBUTE_READ)))
return false;
Expand Down
8 changes: 3 additions & 5 deletions VirtualSMC/kern_vsmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <Library/LegacyIOService.h>
#include <Headers/kern_efi.hpp>
#include <Headers/kern_devinfo.hpp>
#include <Headers/kern_iokit.hpp>
#include <Headers/kern_crypto.hpp>
#include <Headers/plugin_start.hpp>
Expand Down Expand Up @@ -70,16 +71,13 @@ bool VirtualSMC::start(IOService *provider) {
SYSLOG("vsmc", "watchdog loop allocation failure");
}

int computerModel = WIOKit::getComputerModel();
int computerModel = BaseDeviceInfo::get().modelType;
if (computerModel == WIOKit::ComputerModel::ComputerAny) {
DBGLOG("vsmc", "failed to determine laptop or desktop model");
computerModel = WIOKit::ComputerModel::ComputerInvalid;
}

char boardIdentifier[64];
if (!WIOKit::getComputerInfo(nullptr, 0, boardIdentifier, sizeof(boardIdentifier))) {
DBGLOG("vsmc", "failed to obtain board-id");
}
auto boardIdentifier = BaseDeviceInfo::get().boardIdentifier;

SMCInfo deviceInfo {};

Expand Down

0 comments on commit bd58d87

Please sign in to comment.