use detail::fs in detail/turbo

This commit is contained in:
Carl Pearson
2019-09-25 08:54:46 -05:00
parent 1682a05d08
commit 02e0c7c464
3 changed files with 7 additions and 19 deletions

View File

@@ -4,6 +4,7 @@
#include <fstream>
#include "perfect/result.hpp"
#include "perfect/detail/fs.hpp"
namespace perfect {
namespace detail {
@@ -15,19 +16,12 @@ bool has_intel_pstate_no_turbo() {
Result write_intel_pstate_no_turbo(const std::string &s) {
assert(has_intel_pstate_no_turbo());
std::string path("/sys/devices/system/cpu/intel_pstate/no_turbo");
std::ofstream ofs(path, std::ofstream::out);
ofs << s;
ofs.close();
if (ofs.fail()) {
return Result::NO_PERMISSION;
}
return Result::SUCCESS;
return write_str(path, s);
}
std::string read_intel_pstate_no_turbo() {
assert(has_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::string result;
std::getline(ifs, result);

View File

@@ -1,6 +1,7 @@
#pragma once
#include "perfect/result.hpp"
#include "perfect/detail/fs.hpp"
namespace perfect {
namespace detail {
@@ -9,16 +10,10 @@ bool has_acpi_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());
std::string path("/sys/devices/system/cpu/cpufreq/boost");
std::ofstream ofs(path, std::ofstream::out);
ofs << s;
ofs.close();
if (ofs.fail()) {
return 1;
}
return 0;
return write_str(path, s);
}
std::string read_acpi_cpufeq_boost() {
@@ -35,11 +30,11 @@ std::string read_acpi_cpufeq_boost() {
}
Result disable_cpu_turbo() {
write_acpi_cpufreq_boost("0");
return write_acpi_cpufreq_boost("0");
}
Result enable_cpu_turbo() {
write_acpi_cpufreq_boost("1");
return write_acpi_cpufreq_boost("1");
}
} // namespace detail

View File

@@ -6,7 +6,6 @@ using namespace perfect;
int main(void) {
Result ret;
CpuTurboState state;
perfect::init();