~ubuntu-branches/ubuntu/wily/thermald/wily-proposed

« back to all changes in this revision

Viewing changes to .pc/0008-Improve-accuracy-of-unit_value-calculation.patch/src/thd_cdev_intel_pstate_driver.cpp

  • Committer: Package Import Robot
  • Author(s): Colin King
  • Date: 2015-05-11 09:53:11 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20150511095311-k9x5dcc7uue0kljz
Tags: 1.4-1
Sync up with version 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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.
5
 
 *
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.
9
 
 *
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.
14
 
 *
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
18
 
 * 02110-1301, USA.
19
 
 *
20
 
 *
21
 
 * Author Name <Srinivas.Pandruvada@linux.intel.com>
22
 
 *
23
 
 */
24
 
 
25
 
#include "thd_cdev_intel_pstate_driver.h"
26
 
 
27
 
/*
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
37
 
 */
38
 
 
39
 
void cthd_intel_p_state_cdev::set_curr_state(int state, int arg) {
40
 
        std::stringstream tc_state_dev;
41
 
        int new_state;
42
 
 
43
 
        tc_state_dev << "/max_perf_pct";
44
 
        if (cdev_sysfs.exists(tc_state_dev.str())) {
45
 
                std::stringstream state_str;
46
 
                if (state == 0)
47
 
                        new_state = 100;
48
 
                else {
49
 
                        new_state = 100 - (state + min_compensation) * unit_value;
50
 
                }
51
 
                state_str << new_state;
52
 
                thd_log_debug("set cdev state index %d state %d percent %d\n", index,
53
 
                                state, new_state);
54
 
                if (new_state <= turbo_disable_percent)
55
 
                        set_turbo_disable_status(true);
56
 
                else
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;
60
 
                else
61
 
                        curr_state = state;
62
 
        } else
63
 
                curr_state = (state == 0) ? 0 : max_state;
64
 
}
65
 
 
66
 
void cthd_intel_p_state_cdev::set_turbo_disable_status(bool enable) {
67
 
        std::stringstream tc_state_dev;
68
 
 
69
 
        if (enable == turbo_status) {
70
 
                return;
71
 
        }
72
 
        tc_state_dev << "/no_turbo";
73
 
        if (enable) {
74
 
                cdev_sysfs.write(tc_state_dev.str(), "1");
75
 
                thd_log_info("turbo disabled \n");
76
 
        } else {
77
 
                cdev_sysfs.write(tc_state_dev.str(), "0");
78
 
                thd_log_info("turbo enabled \n");
79
 
        }
80
 
        turbo_status = enable;
81
 
}
82
 
 
83
 
int cthd_intel_p_state_cdev::get_max_state() {
84
 
        return max_state;
85
 
}
86
 
 
87
 
int cthd_intel_p_state_cdev::update() {
88
 
        std::stringstream tc_state_dev;
89
 
 
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;
95
 
        } else {
96
 
                return THD_ERROR;
97
 
        }
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;
102
 
        curr_state = 0;
103
 
        thd_log_debug(
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,
106
 
                        type_str.c_str());
107
 
 
108
 
        return THD_SUCCESS;
109
 
}