From 9ba789f26c2e377173ef6f6c12a3667592c5784a Mon Sep 17 00:00:00 2001 From: Hoang Hong Quan Date: Sun, 15 Dec 2024 15:16:38 +0700 Subject: [PATCH] Add TSC synchronization kexts: AmdTscSync, VoodooTSCSync and CpuTscSync --- OpCore-Simplify.py | 2 +- Scripts/datasets/kext_data.py | 64 +++++++++++++++++++++++++++-------- Scripts/kext_maestro.py | 25 ++++++++++++-- 3 files changed, 73 insertions(+), 18 deletions(-) diff --git a/OpCore-Simplify.py b/OpCore-Simplify.py index b54c559..7b226ee 100644 --- a/OpCore-Simplify.py +++ b/OpCore-Simplify.py @@ -174,7 +174,7 @@ class OCPE: print("3. Copy kexts and snapshot to config.plist...", end=" ") kexts_directory = os.path.join(self.result_dir, "EFI", "OC", "Kexts") self.k.install_kexts_to_efi(macos_version, kexts_directory) - config_data["Kernel"]["Add"] = self.k.load_kexts(macos_version, kexts_directory) + config_data["Kernel"]["Add"] = self.k.load_kexts(hardware_report, macos_version, kexts_directory) print("Done") print("4. Generate config.plist...", end=" ") self.co.genarate(hardware_report, unsupported_devices, smbios_model, macos_version, needs_oclp, self.k.kexts, config_data) diff --git a/Scripts/datasets/kext_data.py b/Scripts/datasets/kext_data.py index 4c6832d..a3cace1 100644 --- a/Scripts/datasets/kext_data.py +++ b/Scripts/datasets/kext_data.py @@ -556,6 +556,56 @@ kexts = [ "repo": "Sinetek-rtsx" } ), + KextInfo( + name = "AmdTscSync", + description = "A modified version of VoodooTSCSync for AMD CPUs", + category = "TSC Synchronization", + conflict_group_id = "TSC", + github_repo = { + "owner": "naveenkrdy", + "repo": "AmdTscSync" + } + ), + KextInfo( + name = "VoodooTSCSync", + description = "A kernel extension which will synchronize the TSC on Intel CPUs", + category = "TSC Synchronization", + conflict_group_id = "TSC", + github_repo = { + "owner": "RehabMan", + "repo": "VoodooTSCSync" + }, + download_info = { + "id": 823728912, + "url": "https://github.com/lzhoang2801/lzhoang2801.github.io/raw/refs/heads/main/public/extra-files/VoodooTSCSync-v1.1.zip" + } + ), + KextInfo( + name = "CpuTscSync", + description = "Lilu plugin for TSC sync and disabling xcpm_urgency on Intel CPUs", + category = "TSC Synchronization", + requires_kexts = ["Lilu"], + conflict_group_id = "TSC", + github_repo = { + "owner": "acidanthera", + "repo": "CpuTscSync" + } + ), + KextInfo( + name = "ForgedInvariant", + description = "The plug & play kext for syncing the TSC on AMD & Intel", + category = "TSC Synchronization", + requires_kexts = ["Lilu"], + conflict_group_id = "TSC", + github_repo = { + "owner": "ChefKissInc", + "repo": "ForgedInvariant" + }, + download_info = { + "id": "".join(random.choices('0123456789', k=9)), + "url": "https://nightly.link/ChefKissInc/ForgedInvariant/workflows/main/master/Artifacts.zip" + } + ), KextInfo( name = "AMFIPass", description = "A replacement for amfi=0x80 boot argument", @@ -667,20 +717,6 @@ kexts = [ "repo": "FeatureUnlock" } ), - KextInfo( - name = "ForgedInvariant", - description = "The plug & play kext for syncing the TSC on AMD & Intel", - category = "Extras", - requires_kexts = ["Lilu"], - github_repo = { - "owner": "ChefKissInc", - "repo": "ForgedInvariant" - }, - download_info = { - "id": "".join(random.choices('0123456789', k=9)), - "url": "https://nightly.link/ChefKissInc/ForgedInvariant/workflows/main/master/Artifacts.zip" - } - ), KextInfo( name = "HibernationFixup", description = "Fixes hibernation compatibility issues", diff --git a/Scripts/kext_maestro.py b/Scripts/kext_maestro.py index 9ffa1a1..4ffa4e3 100644 --- a/Scripts/kext_maestro.py +++ b/Scripts/kext_maestro.py @@ -142,10 +142,12 @@ class KextMaestro: else: selected_kexts.append("NootRX" if "Navi 2" in list(hardware_report.get("GPU").items())[0][-1].get("Codename") else "WhateverGreen") - if "Laptop" in hardware_report.get("Motherboard").get("Platform") and ("ASUS" in hardware_report.get("Motherboard").get("Name") or "NootedRed" in selected_kexts) or \ - self.is_intel_hedt_cpu(hardware_report.get("CPU").get("Codename")): + if "Laptop" in hardware_report.get("Motherboard").get("Platform") and ("ASUS" in hardware_report.get("Motherboard").get("Name") or "NootedRed" in selected_kexts): selected_kexts.append("ForgedInvariant") + if self.is_intel_hedt_cpu(hardware_report.get("CPU").get("Codename")): + selected_kexts.append("CpuTscSync") + if needs_oclp: selected_kexts.extend(("AMFIPass", "RestrictEvents")) @@ -317,8 +319,23 @@ class KextMaestro: for bundle_identifier, bundle_version in bundle_info.get("OSBundleLibraries", {}).items() } } + + def modify_kexts(self, plist_path, hardware_report, macos_version): + try: + bundle_info = self.utils.read_file(plist_path) + + if bundle_info.get("IOKitPersonalities").get("VoodooTSCSync"): + bundle_info["IOKitPersonalities"]["VoodooTSCSync"]["IOPropertyMatch"]["IOCPUNumber"] = 0 if self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("21.0.0") else int(hardware_report["CPU"]["Core Count"]) - 1 + elif bundle_info.get("IOKitPersonalities").get("AmdTscSync"): + bundle_info["IOKitPersonalities"]["AmdTscSync"]["IOPropertyMatch"]["IOCPUNumber"] = 0 if self.utils.parse_darwin_version(macos_version) >= self.utils.parse_darwin_version("21.0.0") else int(hardware_report["CPU"]["Core Count"]) - 1 + else: + return + + self.utils.write_file(plist_path, bundle_info) + except: + return - def load_kexts(self, macos_version, kexts_directory): + def load_kexts(self, hardware_report, macos_version, kexts_directory): kernel_add = [] unload_kext = [] @@ -343,6 +360,8 @@ class KextMaestro: bundle_info = self.process_kext(kexts_directory, kext_path) if bundle_info: + self.modify_kexts(os.path.join(kexts_directory, kext_path, bundle_info.get("PlistPath")), hardware_report, macos_version) + bundle_list.append(bundle_info) bundle_dict = {bundle["BundleIdentifier"]: bundle for bundle in bundle_list}