use detail::fs in detail/turbo
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "perfect/result.hpp"
|
#include "perfect/result.hpp"
|
||||||
|
#include "perfect/detail/fs.hpp"
|
||||||
|
|
||||||
namespace perfect {
|
namespace perfect {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
@@ -15,19 +16,12 @@ bool has_intel_pstate_no_turbo() {
|
|||||||
Result write_intel_pstate_no_turbo(const std::string &s) {
|
Result write_intel_pstate_no_turbo(const std::string &s) {
|
||||||
assert(has_intel_pstate_no_turbo());
|
assert(has_intel_pstate_no_turbo());
|
||||||
std::string path("/sys/devices/system/cpu/intel_pstate/no_turbo");
|
std::string path("/sys/devices/system/cpu/intel_pstate/no_turbo");
|
||||||
std::ofstream ofs(path, std::ofstream::out);
|
return write_str(path, s);
|
||||||
ofs << s;
|
|
||||||
ofs.close();
|
|
||||||
if (ofs.fail()) {
|
|
||||||
return Result::NO_PERMISSION;
|
|
||||||
}
|
|
||||||
return Result::SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string read_intel_pstate_no_turbo() {
|
std::string read_intel_pstate_no_turbo() {
|
||||||
assert(has_intel_pstate_no_turbo());
|
assert(has_intel_pstate_no_turbo());
|
||||||
std::string path("/sys/devices/system/cpu/intel_pstate/no_turbo");
|
std::string path("/sys/devices/system/cpu/intel_pstate/no_turbo");
|
||||||
// SPDLOG_LOGGER_TRACE(logger::console(), "reading {}", path);
|
|
||||||
std::ifstream ifs(path, std::ifstream::in);
|
std::ifstream ifs(path, std::ifstream::in);
|
||||||
std::string result;
|
std::string result;
|
||||||
std::getline(ifs, result);
|
std::getline(ifs, result);
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "perfect/result.hpp"
|
#include "perfect/result.hpp"
|
||||||
|
#include "perfect/detail/fs.hpp"
|
||||||
|
|
||||||
namespace perfect {
|
namespace perfect {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
@@ -9,16 +10,10 @@ bool has_acpi_cpufreq_boost() {
|
|||||||
return bool(std::ifstream("/sys/devices/system/cpu/cpufreq/boost"));
|
return bool(std::ifstream("/sys/devices/system/cpu/cpufreq/boost"));
|
||||||
}
|
}
|
||||||
|
|
||||||
int write_acpi_cpufreq_boost(const std::string &s) {
|
Result write_acpi_cpufreq_boost(const std::string &s) {
|
||||||
assert(has_acpi_cpufreq_boost());
|
assert(has_acpi_cpufreq_boost());
|
||||||
std::string path("/sys/devices/system/cpu/cpufreq/boost");
|
std::string path("/sys/devices/system/cpu/cpufreq/boost");
|
||||||
std::ofstream ofs(path, std::ofstream::out);
|
return write_str(path, s);
|
||||||
ofs << s;
|
|
||||||
ofs.close();
|
|
||||||
if (ofs.fail()) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string read_acpi_cpufeq_boost() {
|
std::string read_acpi_cpufeq_boost() {
|
||||||
@@ -35,11 +30,11 @@ std::string read_acpi_cpufeq_boost() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result disable_cpu_turbo() {
|
Result disable_cpu_turbo() {
|
||||||
write_acpi_cpufreq_boost("0");
|
return write_acpi_cpufreq_boost("0");
|
||||||
}
|
}
|
||||||
|
|
||||||
Result enable_cpu_turbo() {
|
Result enable_cpu_turbo() {
|
||||||
write_acpi_cpufreq_boost("1");
|
return write_acpi_cpufreq_boost("1");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
@@ -6,7 +6,6 @@ using namespace perfect;
|
|||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
Result ret;
|
|
||||||
CpuTurboState state;
|
CpuTurboState state;
|
||||||
|
|
||||||
perfect::init();
|
perfect::init();
|
||||||
|
Reference in New Issue
Block a user