diff options
author | Zhang Rui <rui.zhang@intel.com> | 2015-02-28 01:07:03 -0500 |
---|---|---|
committer | Zhang Rui <rui.zhang@intel.com> | 2015-02-28 01:07:03 -0500 |
commit | 5912e264d9eec512598d8faf33440630a3aee989 (patch) | |
tree | 6f8c41d8335bfef7022e6caefb993777062667e4 | |
parent | f126079123f9d055c2304b8ab17bac11b0cd22fa (diff) | |
parent | 986ffe0384c38606b94947fad04e5deacb515408 (diff) |
Merge branch 'tmon-fixes' of .git into next
-rw-r--r-- | tools/thermal/tmon/.gitignore | 1 | ||||
-rw-r--r-- | tools/thermal/tmon/Makefile | 15 | ||||
-rw-r--r-- | tools/thermal/tmon/tmon.8 | 2 | ||||
-rw-r--r-- | tools/thermal/tmon/tmon.c | 14 | ||||
-rw-r--r-- | tools/thermal/tmon/tui.c | 45 |
5 files changed, 63 insertions, 14 deletions
diff --git a/tools/thermal/tmon/.gitignore b/tools/thermal/tmon/.gitignore new file mode 100644 index 000000000000..06e96be65276 --- /dev/null +++ b/tools/thermal/tmon/.gitignore | |||
@@ -0,0 +1 @@ | |||
/tmon | |||
diff --git a/tools/thermal/tmon/Makefile b/tools/thermal/tmon/Makefile index e775adcbd29f..0788621c8d76 100644 --- a/tools/thermal/tmon/Makefile +++ b/tools/thermal/tmon/Makefile | |||
@@ -2,8 +2,8 @@ VERSION = 1.0 | |||
2 | 2 | ||
3 | BINDIR=usr/bin | 3 | BINDIR=usr/bin |
4 | WARNFLAGS=-Wall -Wshadow -W -Wformat -Wimplicit-function-declaration -Wimplicit-int | 4 | WARNFLAGS=-Wall -Wshadow -W -Wformat -Wimplicit-function-declaration -Wimplicit-int |
5 | CFLAGS= -O1 ${WARNFLAGS} -fstack-protector | 5 | CFLAGS+= -O1 ${WARNFLAGS} -fstack-protector |
6 | CC=gcc | 6 | CC=$(CROSS_COMPILE)gcc |
7 | 7 | ||
8 | CFLAGS+=-D VERSION=\"$(VERSION)\" | 8 | CFLAGS+=-D VERSION=\"$(VERSION)\" |
9 | LDFLAGS+= | 9 | LDFLAGS+= |
@@ -16,12 +16,21 @@ INSTALL_CONFIGFILE=install -m 644 -p | |||
16 | CONFIG_FILE= | 16 | CONFIG_FILE= |
17 | CONFIG_PATH= | 17 | CONFIG_PATH= |
18 | 18 | ||
19 | # Static builds might require -ltinfo, for instance | ||
20 | ifneq ($(findstring -static, $(LDFLAGS)),) | ||
21 | STATIC := --static | ||
22 | endif | ||
23 | |||
24 | TMON_LIBS=-lm -lpthread | ||
25 | TMON_LIBS += $(shell pkg-config --libs $(STATIC) panelw ncursesw 2> /dev/null || \ | ||
26 | pkg-config --libs $(STATIC) panel ncurses 2> /dev/null || \ | ||
27 | echo -lpanel -lncurses) | ||
19 | 28 | ||
20 | OBJS = tmon.o tui.o sysfs.o pid.o | 29 | OBJS = tmon.o tui.o sysfs.o pid.o |
21 | OBJS += | 30 | OBJS += |
22 | 31 | ||
23 | tmon: $(OBJS) Makefile tmon.h | 32 | tmon: $(OBJS) Makefile tmon.h |
24 | $(CC) ${CFLAGS} $(LDFLAGS) $(OBJS) -o $(TARGET) -lm -lpanel -lncursesw -ltinfo -lpthread | 33 | $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $(TARGET) $(TMON_LIBS) |
25 | 34 | ||
26 | valgrind: tmon | 35 | valgrind: tmon |
27 | sudo valgrind -v --track-origins=yes --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes ./$(TARGET) 1> /dev/null | 36 | sudo valgrind -v --track-origins=yes --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes ./$(TARGET) 1> /dev/null |
diff --git a/tools/thermal/tmon/tmon.8 b/tools/thermal/tmon/tmon.8 index 0be727cb9892..02d5179803aa 100644 --- a/tools/thermal/tmon/tmon.8 +++ b/tools/thermal/tmon/tmon.8 | |||
@@ -55,6 +55,8 @@ The \fB-l --log\fP option write data to /var/tmp/tmon.log | |||
55 | .PP | 55 | .PP |
56 | The \fB-t --time-interval\fP option sets the polling interval in seconds | 56 | The \fB-t --time-interval\fP option sets the polling interval in seconds |
57 | .PP | 57 | .PP |
58 | The \fB-T --target-temp\fP option sets the initial target temperature | ||
59 | .PP | ||
58 | The \fB-v --version\fP option shows the version of \fBtmon \fP | 60 | The \fB-v --version\fP option shows the version of \fBtmon \fP |
59 | .PP | 61 | .PP |
60 | The \fB-z --zone\fP option sets the target therma zone instance to be controlled | 62 | The \fB-z --zone\fP option sets the target therma zone instance to be controlled |
diff --git a/tools/thermal/tmon/tmon.c b/tools/thermal/tmon/tmon.c index 09b7c3218334..9aa19652e8e8 100644 --- a/tools/thermal/tmon/tmon.c +++ b/tools/thermal/tmon/tmon.c | |||
@@ -64,6 +64,7 @@ void usage() | |||
64 | printf(" -h, --help show this help message\n"); | 64 | printf(" -h, --help show this help message\n"); |
65 | printf(" -l, --log log data to /var/tmp/tmon.log\n"); | 65 | printf(" -l, --log log data to /var/tmp/tmon.log\n"); |
66 | printf(" -t, --time-interval sampling time interval, > 1 sec.\n"); | 66 | printf(" -t, --time-interval sampling time interval, > 1 sec.\n"); |
67 | printf(" -T, --target-temp initial target temperature\n"); | ||
67 | printf(" -v, --version show version\n"); | 68 | printf(" -v, --version show version\n"); |
68 | printf(" -z, --zone target thermal zone id\n"); | 69 | printf(" -z, --zone target thermal zone id\n"); |
69 | 70 | ||
@@ -219,6 +220,7 @@ static struct option opts[] = { | |||
219 | { "control", 1, NULL, 'c' }, | 220 | { "control", 1, NULL, 'c' }, |
220 | { "daemon", 0, NULL, 'd' }, | 221 | { "daemon", 0, NULL, 'd' }, |
221 | { "time-interval", 1, NULL, 't' }, | 222 | { "time-interval", 1, NULL, 't' }, |
223 | { "target-temp", 1, NULL, 'T' }, | ||
222 | { "log", 0, NULL, 'l' }, | 224 | { "log", 0, NULL, 'l' }, |
223 | { "help", 0, NULL, 'h' }, | 225 | { "help", 0, NULL, 'h' }, |
224 | { "version", 0, NULL, 'v' }, | 226 | { "version", 0, NULL, 'v' }, |
@@ -231,7 +233,7 @@ int main(int argc, char **argv) | |||
231 | { | 233 | { |
232 | int err = 0; | 234 | int err = 0; |
233 | int id2 = 0, c; | 235 | int id2 = 0, c; |
234 | double yk = 0.0; /* controller output */ | 236 | double yk = 0.0, temp; /* controller output */ |
235 | int target_tz_index; | 237 | int target_tz_index; |
236 | 238 | ||
237 | if (geteuid() != 0) { | 239 | if (geteuid() != 0) { |
@@ -239,7 +241,7 @@ int main(int argc, char **argv) | |||
239 | exit(EXIT_FAILURE); | 241 | exit(EXIT_FAILURE); |
240 | } | 242 | } |
241 | 243 | ||
242 | while ((c = getopt_long(argc, argv, "c:dlht:vgz:", opts, &id2)) != -1) { | 244 | while ((c = getopt_long(argc, argv, "c:dlht:T:vgz:", opts, &id2)) != -1) { |
243 | switch (c) { | 245 | switch (c) { |
244 | case 'c': | 246 | case 'c': |
245 | no_control = 0; | 247 | no_control = 0; |
@@ -254,6 +256,14 @@ int main(int argc, char **argv) | |||
254 | if (ticktime < 1) | 256 | if (ticktime < 1) |
255 | ticktime = 1; | 257 | ticktime = 1; |
256 | break; | 258 | break; |
259 | case 'T': | ||
260 | temp = strtod(optarg, NULL); | ||
261 | if (temp < 0) { | ||
262 | fprintf(stderr, "error: temperature must be positive\n"); | ||
263 | return 1; | ||
264 | } | ||
265 | target_temp_user = temp; | ||
266 | break; | ||
257 | case 'l': | 267 | case 'l': |
258 | printf("Logging data to /var/tmp/tmon.log\n"); | 268 | printf("Logging data to /var/tmp/tmon.log\n"); |
259 | logging = 1; | 269 | logging = 1; |
diff --git a/tools/thermal/tmon/tui.c b/tools/thermal/tmon/tui.c index 89f8ef0e15c8..b5d1c6b22dd3 100644 --- a/tools/thermal/tmon/tui.c +++ b/tools/thermal/tmon/tui.c | |||
@@ -30,6 +30,18 @@ | |||
30 | 30 | ||
31 | #include "tmon.h" | 31 | #include "tmon.h" |
32 | 32 | ||
33 | #define min(x, y) ({ \ | ||
34 | typeof(x) _min1 = (x); \ | ||
35 | typeof(y) _min2 = (y); \ | ||
36 | (void) (&_min1 == &_min2); \ | ||
37 | _min1 < _min2 ? _min1 : _min2; }) | ||
38 | |||
39 | #define max(x, y) ({ \ | ||
40 | typeof(x) _max1 = (x); \ | ||
41 | typeof(y) _max2 = (y); \ | ||
42 | (void) (&_max1 == &_max2); \ | ||
43 | _max1 > _max2 ? _max1 : _max2; }) | ||
44 | |||
33 | static PANEL *data_panel; | 45 | static PANEL *data_panel; |
34 | static PANEL *dialogue_panel; | 46 | static PANEL *dialogue_panel; |
35 | static PANEL *top; | 47 | static PANEL *top; |
@@ -98,6 +110,18 @@ void write_status_bar(int x, char *line) | |||
98 | wrefresh(status_bar_window); | 110 | wrefresh(status_bar_window); |
99 | } | 111 | } |
100 | 112 | ||
113 | /* wrap at 5 */ | ||
114 | #define DIAG_DEV_ROWS 5 | ||
115 | /* | ||
116 | * list cooling devices + "set temp" entry; wraps after 5 rows, if they fit | ||
117 | */ | ||
118 | static int diag_dev_rows(void) | ||
119 | { | ||
120 | int entries = ptdata.nr_cooling_dev + 1; | ||
121 | int rows = max(DIAG_DEV_ROWS, (entries + 1) / 2); | ||
122 | return min(rows, entries); | ||
123 | } | ||
124 | |||
101 | void setup_windows(void) | 125 | void setup_windows(void) |
102 | { | 126 | { |
103 | int y_begin = 1; | 127 | int y_begin = 1; |
@@ -122,7 +146,7 @@ void setup_windows(void) | |||
122 | * dialogue window is a pop-up, when needed it lays on top of cdev win | 146 | * dialogue window is a pop-up, when needed it lays on top of cdev win |
123 | */ | 147 | */ |
124 | 148 | ||
125 | dialogue_window = subwin(stdscr, ptdata.nr_cooling_dev+5, maxx-50, | 149 | dialogue_window = subwin(stdscr, diag_dev_rows() + 5, maxx-50, |
126 | DIAG_Y, DIAG_X); | 150 | DIAG_Y, DIAG_X); |
127 | 151 | ||
128 | thermal_data_window = subwin(stdscr, ptdata.nr_tz_sensor * | 152 | thermal_data_window = subwin(stdscr, ptdata.nr_tz_sensor * |
@@ -258,21 +282,26 @@ void show_cooling_device(void) | |||
258 | } | 282 | } |
259 | 283 | ||
260 | const char DIAG_TITLE[] = "[ TUNABLES ]"; | 284 | const char DIAG_TITLE[] = "[ TUNABLES ]"; |
261 | #define DIAG_DEV_ROWS 5 | ||
262 | void show_dialogue(void) | 285 | void show_dialogue(void) |
263 | { | 286 | { |
264 | int j, x = 0, y = 0; | 287 | int j, x = 0, y = 0; |
288 | int rows, cols; | ||
265 | WINDOW *w = dialogue_window; | 289 | WINDOW *w = dialogue_window; |
266 | 290 | ||
267 | if (tui_disabled || !w) | 291 | if (tui_disabled || !w) |
268 | return; | 292 | return; |
269 | 293 | ||
294 | getmaxyx(w, rows, cols); | ||
295 | |||
296 | /* Silence compiler 'unused' warnings */ | ||
297 | (void)cols; | ||
298 | |||
270 | werase(w); | 299 | werase(w); |
271 | box(w, 0, 0); | 300 | box(w, 0, 0); |
272 | mvwprintw(w, 0, maxx/4, DIAG_TITLE); | 301 | mvwprintw(w, 0, maxx/4, DIAG_TITLE); |
273 | /* list all the available tunables */ | 302 | /* list all the available tunables */ |
274 | for (j = 0; j <= ptdata.nr_cooling_dev; j++) { | 303 | for (j = 0; j <= ptdata.nr_cooling_dev; j++) { |
275 | y = j % DIAG_DEV_ROWS; | 304 | y = j % diag_dev_rows(); |
276 | if (y == 0 && j != 0) | 305 | if (y == 0 && j != 0) |
277 | x += 20; | 306 | x += 20; |
278 | if (j == ptdata.nr_cooling_dev) | 307 | if (j == ptdata.nr_cooling_dev) |
@@ -283,12 +312,10 @@ void show_dialogue(void) | |||
283 | ptdata.cdi[j].type, ptdata.cdi[j].instance); | 312 | ptdata.cdi[j].type, ptdata.cdi[j].instance); |
284 | } | 313 | } |
285 | wattron(w, A_BOLD); | 314 | wattron(w, A_BOLD); |
286 | mvwprintw(w, DIAG_DEV_ROWS+1, 1, "Enter Choice [A-Z]?"); | 315 | mvwprintw(w, diag_dev_rows()+1, 1, "Enter Choice [A-Z]?"); |
287 | wattroff(w, A_BOLD); | 316 | wattroff(w, A_BOLD); |
288 | /* y size of dialogue win is nr cdev + 5, so print legend | 317 | /* print legend at the bottom line */ |
289 | * at the bottom line | 318 | mvwprintw(w, rows - 2, 1, |
290 | */ | ||
291 | mvwprintw(w, ptdata.nr_cooling_dev+3, 1, | ||
292 | "Legend: A=Active, P=Passive, C=Critical"); | 319 | "Legend: A=Active, P=Passive, C=Critical"); |
293 | 320 | ||
294 | wrefresh(dialogue_window); | 321 | wrefresh(dialogue_window); |
@@ -437,7 +464,7 @@ static void handle_input_choice(int ch) | |||
437 | snprintf(buf, sizeof(buf), "New Value for %.10s-%2d: ", | 464 | snprintf(buf, sizeof(buf), "New Value for %.10s-%2d: ", |
438 | ptdata.cdi[cdev_id].type, | 465 | ptdata.cdi[cdev_id].type, |
439 | ptdata.cdi[cdev_id].instance); | 466 | ptdata.cdi[cdev_id].instance); |
440 | write_dialogue_win(buf, DIAG_DEV_ROWS+2, 2); | 467 | write_dialogue_win(buf, diag_dev_rows() + 2, 2); |
441 | handle_input_val(cdev_id); | 468 | handle_input_val(cdev_id); |
442 | } else { | 469 | } else { |
443 | snprintf(buf, sizeof(buf), "Invalid selection %d", ch); | 470 | snprintf(buf, sizeof(buf), "Invalid selection %d", ch); |