~ubuntu-branches/ubuntu/utopic/thermald/utopic

« back to all changes in this revision

Viewing changes to .pc/0001-Buggy-thermal-zone-trip-index.patch/src/thd_zone_therm_sys_fs.cpp

  • Committer: Package Import Robot
  • Author(s): Colin King
  • Date: 2014-05-19 12:41:22 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140519124122-zan11arvjxtbqcq5
Tags: 1.2-1
* Adjust for coretemp path change
* Deny non root users to send system bus dbus messages
* Remove compile warning
* Remove rpmlint warning for manual page
* Remove old patches that are now included into version 1.2
* Sync up with version 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * thd_zone_therm_sys_fs.cpp: thermal zone class implementation
3
 
 *      for thermal sysfs
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_zone_therm_sys_fs.h"
26
 
#include "thd_engine.h"
27
 
#include <stdlib.h>
28
 
 
29
 
cthd_sysfs_zone::cthd_sysfs_zone(int count, std::string path) :
30
 
                cthd_zone(count, path), trip_point_cnt(0), zone(NULL) {
31
 
 
32
 
        std::stringstream tc_type_dev;
33
 
        tc_type_dev << index << "/type";
34
 
 
35
 
        thd_log_debug("Thermal Zone look for %s\n", tc_type_dev.str().c_str());
36
 
 
37
 
        if (zone_sysfs.exists(tc_type_dev.str())) {
38
 
                zone_sysfs.read(tc_type_dev.str(), type_str);
39
 
        }
40
 
 
41
 
        thd_log_debug("Thermal Zone %d:%s\n", index, type_str.c_str());
42
 
}
43
 
 
44
 
int cthd_sysfs_zone::zone_bind_sensors() {
45
 
        cthd_sensor *sensor;
46
 
 
47
 
        sensor = thd_engine->search_sensor(type_str);
48
 
        if (sensor) {
49
 
                bind_sensor(sensor);
50
 
        } else
51
 
                return THD_ERROR;
52
 
 
53
 
        return THD_SUCCESS;
54
 
}
55
 
 
56
 
int cthd_sysfs_zone::read_trip_points() {
57
 
 
58
 
        // Gather all trip points
59
 
        std::stringstream trip_sysfs;
60
 
        trip_sysfs << index << "/" << "trip_point_";
61
 
        for (int i = 0; i < max_trip_points; ++i) {
62
 
                std::stringstream type_stream;
63
 
                std::stringstream temp_stream;
64
 
                std::stringstream hist_stream;
65
 
                std::string _type_str;
66
 
                std::string _temp_str;
67
 
                std::string _hist_str;
68
 
                trip_point_type_t trip_type;
69
 
                unsigned int temp = 0, hyst = 1;
70
 
 
71
 
                type_stream << trip_sysfs.str() << i << "_type";
72
 
                if (zone_sysfs.exists(type_stream.str())) {
73
 
                        zone_sysfs.read(type_stream.str(), _type_str);
74
 
                        thd_log_debug("read_trip_points %s:%s \n",
75
 
                                        type_stream.str().c_str(), _type_str.c_str());
76
 
                }
77
 
                temp_stream << trip_sysfs.str() << i << "_temp";
78
 
                if (zone_sysfs.exists(temp_stream.str())) {
79
 
                        zone_sysfs.read(temp_stream.str(), _temp_str);
80
 
                        std::istringstream(_temp_str) >> temp;
81
 
                        thd_log_debug("read_trip_points %s:%s \n",
82
 
                                        temp_stream.str().c_str(), _temp_str.c_str());
83
 
                }
84
 
 
85
 
                hist_stream << trip_sysfs.str() << i << "_hyst";
86
 
                if (zone_sysfs.exists(hist_stream.str())) {
87
 
                        zone_sysfs.read(hist_stream.str(), _hist_str);
88
 
                        std::istringstream(_hist_str) >> hyst;
89
 
                        thd_log_debug("read_trip_points %s:%s \n",
90
 
                                        hist_stream.str().c_str(), _hist_str.c_str());
91
 
                }
92
 
 
93
 
                if (_type_str == "critical")
94
 
                        trip_type = CRITICAL;
95
 
                else if (_type_str == "hot")
96
 
                        trip_type = MAX;
97
 
                else if (_type_str == "active")
98
 
                        trip_type = ACTIVE;
99
 
                else if (_type_str == "passive")
100
 
                        trip_type = PASSIVE;
101
 
                else
102
 
                        trip_type = INVALID_TRIP_TYPE;
103
 
                if (temp > 0 && trip_type != INVALID_TRIP_TYPE) {
104
 
                        cthd_sensor *sensor;
105
 
 
106
 
                        sensor = thd_engine->search_sensor(type_str);
107
 
                        if (sensor) {
108
 
                                cthd_trip_point trip_pt(trip_point_cnt, trip_type, temp, hyst,
109
 
                                                index, sensor->get_index());
110
 
                                trip_points.push_back(trip_pt);
111
 
                                ++trip_point_cnt;
112
 
                        }
113
 
                }
114
 
        }
115
 
        thd_log_debug("read_trip_points Added %d trips \n", trip_point_cnt);
116
 
        if (trip_point_cnt == 0)
117
 
                return THD_ERROR;
118
 
        else
119
 
                return THD_SUCCESS;
120
 
}
121
 
 
122
 
int cthd_sysfs_zone::read_cdev_trip_points() {
123
 
        thd_log_debug(" >> read_cdev_trip_points for \n");
124
 
 
125
 
        // Gather all Cdevs
126
 
        // Gather all trip points
127
 
        std::stringstream cdev_sysfs;
128
 
        cdev_sysfs << index << "/" << "cdev";
129
 
        for (int i = 0; i < max_cool_devs; ++i) {
130
 
                std::stringstream trip_pt_stream, cdev_stream;
131
 
                std::string trip_pt_str;
132
 
                int trip_cnt = -1;
133
 
                char buf[50], *ptr;
134
 
                trip_pt_stream << cdev_sysfs.str() << i << "_trip_point";
135
 
 
136
 
                if (zone_sysfs.exists(trip_pt_stream.str())) {
137
 
                        zone_sysfs.read(trip_pt_stream.str(), trip_pt_str);
138
 
                        std::istringstream(trip_pt_str) >> trip_cnt;
139
 
                } else
140
 
                        continue;
141
 
                thd_log_debug("cdev trip point: %s contains %d\n", trip_pt_str.c_str(),
142
 
                                trip_cnt);
143
 
                cdev_stream << cdev_sysfs.str() << i;
144
 
                if (zone_sysfs.exists(cdev_stream.str())) {
145
 
                        thd_log_debug("cdev%d present\n", i);
146
 
                        int ret = zone_sysfs.read_symbolic_link_value(cdev_stream.str(),
147
 
                                        buf, 50);
148
 
                        if (ret == 0) {
149
 
                                ptr = strstr(buf, "cooling_device");
150
 
                                if (ptr) {
151
 
                                        ptr += strlen("cooling_device");
152
 
                                        thd_log_debug("symbolic name %s:%s\n", buf, ptr);
153
 
                                        if (trip_cnt >= 0) {
154
 
                                                trip_points[trip_cnt].thd_trip_point_add_cdev_index(
155
 
                                                                atoi(ptr), cthd_trip_point::default_influence);
156
 
                                                zone_cdev_binded_status = true;
157
 
                                        }
158
 
                                }
159
 
                        }
160
 
                }
161
 
        }
162
 
        thd_log_debug(
163
 
                        "cthd_sysfs_zone::read_cdev_trip_points: ZONE bound to CDEV status %d \n",
164
 
                        zone_cdev_binded_status);
165
 
 
166
 
        return THD_SUCCESS;
167
 
}