2
* thd_sysfs_intel_pstate_driver.cpp: thermal cooling class implementation
3
* using Intel p state driver
4
* Copyright (C) 2012 Intel Corporation. All rights reserved.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License version
8
* 2 or later as published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
* Author Name <Srinivas.Pandruvada@linux.intel.com>
25
#include "thd_cdev_intel_pstate_driver.h"
28
* This implementation allows to control get max state and
29
* set current state of using Intel P state driver
30
* P state drives uses a percent count. 100% means full
31
* performance, setting anything lower limits performance.
32
* Each lower state reduces performance by unit value.
33
* unit value is calculated using number of possible p states
34
* . Each step reduces bye one p state.
35
* Contents of "/sys/devices/system/cpu/intel_pstate/"
36
max_perf_pct, min_perf_pct, no_turbo
39
void cthd_intel_p_state_cdev::set_curr_state(int state, int arg) {
40
std::stringstream tc_state_dev;
43
tc_state_dev << "/max_perf_pct";
44
if (cdev_sysfs.exists(tc_state_dev.str())) {
45
std::stringstream state_str;
49
new_state = 100 - (state + min_compensation) * unit_value;
51
state_str << new_state;
52
thd_log_debug("set cdev state index %d state %d percent %d\n", index,
54
if (new_state <= turbo_disable_percent)
55
set_turbo_disable_status(true);
57
set_turbo_disable_status(false);
58
if (cdev_sysfs.write(tc_state_dev.str(), state_str.str()) < 0)
59
curr_state = (state == 0) ? 0 : max_state;
63
curr_state = (state == 0) ? 0 : max_state;
66
void cthd_intel_p_state_cdev::set_turbo_disable_status(bool enable) {
67
std::stringstream tc_state_dev;
69
if (enable == turbo_status) {
72
tc_state_dev << "/no_turbo";
74
cdev_sysfs.write(tc_state_dev.str(), "1");
75
thd_log_info("turbo disabled \n");
77
cdev_sysfs.write(tc_state_dev.str(), "0");
78
thd_log_info("turbo enabled \n");
80
turbo_status = enable;
83
int cthd_intel_p_state_cdev::get_max_state() {
87
int cthd_intel_p_state_cdev::update() {
88
std::stringstream tc_state_dev;
90
tc_state_dev << "/max_perf_pct";
91
if (cdev_sysfs.exists(tc_state_dev.str())) {
92
std::string state_str;
93
cdev_sysfs.read(tc_state_dev.str(), state_str);
94
std::istringstream(state_str) >> curr_state;
98
thd_log_info("Use Default pstate drv settings\n");
99
max_state = default_max_state;
100
min_compensation = 0;
101
unit_value = 100 / max_state;
104
"cooling dev index:%d, curr_state:%d, max_state:%d, unit:%f, min_com:%d, type:%s\n",
105
index, curr_state, max_state, unit_value, min_compensation,