Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion config/device_mitigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,24 @@
"default": {
"items": ["DISABLE_DDR_TWEAK", "NO_PERFORMANCE_CPUGOV", "QCOM_NO_GPU_POWERSAVE"]
},
"device_rules": {}
"device_rules": {
"snapdragon_samsung_schedutil_bug": {
"name": "Snapdragon/Samsung Schedutil Mitigation",
"description": "Prevents 100% CPU usage deadlock on Prime Core by blacklisting schedutil on Samsung Snapdragon kernels.",
"filter_type": "all",
"items": [
"NO_SCHEDUTIL_CPUGOV"
],
"filter_condition": {
"soc": {
"operator": "regex",
"value": "(?i)(sm[0-9]+|qcom|qualcomm|snapdragon)"
},
"model": {
"operator": "regex",
"value": "(?i)(sm-|samsung)"
}
}
}
}
}
30 changes: 30 additions & 0 deletions jni/EncoreConfigStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <rapidjson/prettywriter.h>
#include <rapidjson/stringbuffer.h>

#include "DeviceMitigationStore.hpp"
#include "EncoreConfigStore.hpp"

bool EncoreConfigStore::load_config(const std::string &config_path) {
Expand Down Expand Up @@ -137,6 +138,21 @@ bool EncoreConfigStore::reload() {
return load_config(config_path_);
}

// Skip bypass on pre-GKI kernels where 'walt' doesn't exist and 'schedutil' is safe.
static bool is_governor_supported(const std::string &gov) {
std::ifstream file("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors");
if (!file.is_open()) {
return false;
}
std::string available_gov;
while (file >> available_gov) {
if (available_gov == gov) {
return true;
}
}
return false;
}

std::string EncoreConfigStore::read_default_cpu_governor() const {
// Fallback governor
std::string default_governor = "schedutil";
Expand All @@ -153,6 +169,14 @@ std::string EncoreConfigStore::read_default_cpu_governor() const {
}

file.close();

auto mitigations = device_mitigation_store.get_cached_mitigation_items(false);
if (mitigations.contains("NO_SCHEDUTIL_CPUGOV") && is_governor_supported("walt")) {
if (default_governor == "schedutil") {
default_governor = "walt";
}
}

return default_governor;
}

Expand Down Expand Up @@ -219,6 +243,12 @@ bool EncoreConfigStore::parse_config(const rapidjson::Document &doc) {
}
}

auto mitigations = device_mitigation_store.get_cached_mitigation_items(new_config.preferences.use_device_mitigation);
if (mitigations.contains("NO_SCHEDUTIL_CPUGOV") && is_governor_supported("walt")) {
if (new_config.cpu_governor.balance == "schedutil") new_config.cpu_governor.balance = "walt";
if (new_config.cpu_governor.powersave == "schedutil") new_config.cpu_governor.powersave = "walt";
}

{
std::lock_guard<std::mutex> lock(mutex_);
config_ = new_config;
Expand Down
11 changes: 11 additions & 0 deletions module/service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ rm -f "$MODULE_CONFIG/encore.log" "$MODULE_CONFIG/sysmon.log"
# Parse Governor to use
chmod 644 "$CPUFREQ/scaling_governor"
default_gov=$(cat "$CPUFREQ/scaling_governor")

# Add mitigation for Samsung Snapdragon Bug
SOC_ID=$(cat "$MODULE_CONFIG/soc_recognition" 2>/dev/null)
if [ "$SOC_ID" = "2" ] && getprop ro.product.brand | grep -iq "samsung"; then
if [ "$default_gov" = "schedutil" ]; then
if grep -q "walt" "$CPUFREQ/scaling_available_governors"; then
default_gov="walt"
fi
fi
fi

echo "$default_gov" >$MODULE_CONFIG/default_cpu_gov

# Create cleanup script
Expand Down