Commit 5912e264 authored by Zhang Rui's avatar Zhang Rui

Merge branch 'tmon-fixes' of .git into next

parents f1260791 986ffe03
...@@ -2,8 +2,8 @@ VERSION = 1.0 ...@@ -2,8 +2,8 @@ VERSION = 1.0
BINDIR=usr/bin BINDIR=usr/bin
WARNFLAGS=-Wall -Wshadow -W -Wformat -Wimplicit-function-declaration -Wimplicit-int WARNFLAGS=-Wall -Wshadow -W -Wformat -Wimplicit-function-declaration -Wimplicit-int
CFLAGS= -O1 ${WARNFLAGS} -fstack-protector CFLAGS+= -O1 ${WARNFLAGS} -fstack-protector
CC=gcc CC=$(CROSS_COMPILE)gcc
CFLAGS+=-D VERSION=\"$(VERSION)\" CFLAGS+=-D VERSION=\"$(VERSION)\"
LDFLAGS+= LDFLAGS+=
...@@ -16,12 +16,21 @@ INSTALL_CONFIGFILE=install -m 644 -p ...@@ -16,12 +16,21 @@ INSTALL_CONFIGFILE=install -m 644 -p
CONFIG_FILE= CONFIG_FILE=
CONFIG_PATH= CONFIG_PATH=
# Static builds might require -ltinfo, for instance
ifneq ($(findstring -static, $(LDFLAGS)),)
STATIC := --static
endif
TMON_LIBS=-lm -lpthread
TMON_LIBS += $(shell pkg-config --libs $(STATIC) panelw ncursesw 2> /dev/null || \
pkg-config --libs $(STATIC) panel ncurses 2> /dev/null || \
echo -lpanel -lncurses)
OBJS = tmon.o tui.o sysfs.o pid.o OBJS = tmon.o tui.o sysfs.o pid.o
OBJS += OBJS +=
tmon: $(OBJS) Makefile tmon.h tmon: $(OBJS) Makefile tmon.h
$(CC) ${CFLAGS} $(LDFLAGS) $(OBJS) -o $(TARGET) -lm -lpanel -lncursesw -ltinfo -lpthread $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $(TARGET) $(TMON_LIBS)
valgrind: tmon valgrind: tmon
sudo valgrind -v --track-origins=yes --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes ./$(TARGET) 1> /dev/null sudo valgrind -v --track-origins=yes --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes ./$(TARGET) 1> /dev/null
......
...@@ -55,6 +55,8 @@ The \fB-l --log\fP option write data to /var/tmp/tmon.log ...@@ -55,6 +55,8 @@ The \fB-l --log\fP option write data to /var/tmp/tmon.log
.PP .PP
The \fB-t --time-interval\fP option sets the polling interval in seconds The \fB-t --time-interval\fP option sets the polling interval in seconds
.PP .PP
The \fB-T --target-temp\fP option sets the initial target temperature
.PP
The \fB-v --version\fP option shows the version of \fBtmon \fP The \fB-v --version\fP option shows the version of \fBtmon \fP
.PP .PP
The \fB-z --zone\fP option sets the target therma zone instance to be controlled The \fB-z --zone\fP option sets the target therma zone instance to be controlled
......
...@@ -64,6 +64,7 @@ void usage() ...@@ -64,6 +64,7 @@ void usage()
printf(" -h, --help show this help message\n"); printf(" -h, --help show this help message\n");
printf(" -l, --log log data to /var/tmp/tmon.log\n"); printf(" -l, --log log data to /var/tmp/tmon.log\n");
printf(" -t, --time-interval sampling time interval, > 1 sec.\n"); printf(" -t, --time-interval sampling time interval, > 1 sec.\n");
printf(" -T, --target-temp initial target temperature\n");
printf(" -v, --version show version\n"); printf(" -v, --version show version\n");
printf(" -z, --zone target thermal zone id\n"); printf(" -z, --zone target thermal zone id\n");
...@@ -219,6 +220,7 @@ static struct option opts[] = { ...@@ -219,6 +220,7 @@ static struct option opts[] = {
{ "control", 1, NULL, 'c' }, { "control", 1, NULL, 'c' },
{ "daemon", 0, NULL, 'd' }, { "daemon", 0, NULL, 'd' },
{ "time-interval", 1, NULL, 't' }, { "time-interval", 1, NULL, 't' },
{ "target-temp", 1, NULL, 'T' },
{ "log", 0, NULL, 'l' }, { "log", 0, NULL, 'l' },
{ "help", 0, NULL, 'h' }, { "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' }, { "version", 0, NULL, 'v' },
...@@ -231,7 +233,7 @@ int main(int argc, char **argv) ...@@ -231,7 +233,7 @@ int main(int argc, char **argv)
{ {
int err = 0; int err = 0;
int id2 = 0, c; int id2 = 0, c;
double yk = 0.0; /* controller output */ double yk = 0.0, temp; /* controller output */
int target_tz_index; int target_tz_index;
if (geteuid() != 0) { if (geteuid() != 0) {
...@@ -239,7 +241,7 @@ int main(int argc, char **argv) ...@@ -239,7 +241,7 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
while ((c = getopt_long(argc, argv, "c:dlht:vgz:", opts, &id2)) != -1) { while ((c = getopt_long(argc, argv, "c:dlht:T:vgz:", opts, &id2)) != -1) {
switch (c) { switch (c) {
case 'c': case 'c':
no_control = 0; no_control = 0;
...@@ -254,6 +256,14 @@ int main(int argc, char **argv) ...@@ -254,6 +256,14 @@ int main(int argc, char **argv)
if (ticktime < 1) if (ticktime < 1)
ticktime = 1; ticktime = 1;
break; break;
case 'T':
temp = strtod(optarg, NULL);
if (temp < 0) {
fprintf(stderr, "error: temperature must be positive\n");
return 1;
}
target_temp_user = temp;
break;
case 'l': case 'l':
printf("Logging data to /var/tmp/tmon.log\n"); printf("Logging data to /var/tmp/tmon.log\n");
logging = 1; logging = 1;
......
...@@ -30,6 +30,18 @@ ...@@ -30,6 +30,18 @@
#include "tmon.h" #include "tmon.h"
#define min(x, y) ({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
#define max(x, y) ({ \
typeof(x) _max1 = (x); \
typeof(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })
static PANEL *data_panel; static PANEL *data_panel;
static PANEL *dialogue_panel; static PANEL *dialogue_panel;
static PANEL *top; static PANEL *top;
...@@ -98,6 +110,18 @@ void write_status_bar(int x, char *line) ...@@ -98,6 +110,18 @@ void write_status_bar(int x, char *line)
wrefresh(status_bar_window); wrefresh(status_bar_window);
} }
/* wrap at 5 */
#define DIAG_DEV_ROWS 5
/*
* list cooling devices + "set temp" entry; wraps after 5 rows, if they fit
*/
static int diag_dev_rows(void)
{
int entries = ptdata.nr_cooling_dev + 1;
int rows = max(DIAG_DEV_ROWS, (entries + 1) / 2);
return min(rows, entries);
}
void setup_windows(void) void setup_windows(void)
{ {
int y_begin = 1; int y_begin = 1;
...@@ -122,7 +146,7 @@ void setup_windows(void) ...@@ -122,7 +146,7 @@ void setup_windows(void)
* dialogue window is a pop-up, when needed it lays on top of cdev win * dialogue window is a pop-up, when needed it lays on top of cdev win
*/ */
dialogue_window = subwin(stdscr, ptdata.nr_cooling_dev+5, maxx-50, dialogue_window = subwin(stdscr, diag_dev_rows() + 5, maxx-50,
DIAG_Y, DIAG_X); DIAG_Y, DIAG_X);
thermal_data_window = subwin(stdscr, ptdata.nr_tz_sensor * thermal_data_window = subwin(stdscr, ptdata.nr_tz_sensor *
...@@ -258,21 +282,26 @@ void show_cooling_device(void) ...@@ -258,21 +282,26 @@ void show_cooling_device(void)
} }
const char DIAG_TITLE[] = "[ TUNABLES ]"; const char DIAG_TITLE[] = "[ TUNABLES ]";
#define DIAG_DEV_ROWS 5
void show_dialogue(void) void show_dialogue(void)
{ {
int j, x = 0, y = 0; int j, x = 0, y = 0;
int rows, cols;
WINDOW *w = dialogue_window; WINDOW *w = dialogue_window;
if (tui_disabled || !w) if (tui_disabled || !w)
return; return;
getmaxyx(w, rows, cols);
/* Silence compiler 'unused' warnings */
(void)cols;
werase(w); werase(w);
box(w, 0, 0); box(w, 0, 0);
mvwprintw(w, 0, maxx/4, DIAG_TITLE); mvwprintw(w, 0, maxx/4, DIAG_TITLE);
/* list all the available tunables */ /* list all the available tunables */
for (j = 0; j <= ptdata.nr_cooling_dev; j++) { for (j = 0; j <= ptdata.nr_cooling_dev; j++) {
y = j % DIAG_DEV_ROWS; y = j % diag_dev_rows();
if (y == 0 && j != 0) if (y == 0 && j != 0)
x += 20; x += 20;
if (j == ptdata.nr_cooling_dev) if (j == ptdata.nr_cooling_dev)
...@@ -283,12 +312,10 @@ void show_dialogue(void) ...@@ -283,12 +312,10 @@ void show_dialogue(void)
ptdata.cdi[j].type, ptdata.cdi[j].instance); ptdata.cdi[j].type, ptdata.cdi[j].instance);
} }
wattron(w, A_BOLD); wattron(w, A_BOLD);
mvwprintw(w, DIAG_DEV_ROWS+1, 1, "Enter Choice [A-Z]?"); mvwprintw(w, diag_dev_rows()+1, 1, "Enter Choice [A-Z]?");
wattroff(w, A_BOLD); wattroff(w, A_BOLD);
/* y size of dialogue win is nr cdev + 5, so print legend /* print legend at the bottom line */
* at the bottom line mvwprintw(w, rows - 2, 1,
*/
mvwprintw(w, ptdata.nr_cooling_dev+3, 1,
"Legend: A=Active, P=Passive, C=Critical"); "Legend: A=Active, P=Passive, C=Critical");
wrefresh(dialogue_window); wrefresh(dialogue_window);
...@@ -437,7 +464,7 @@ static void handle_input_choice(int ch) ...@@ -437,7 +464,7 @@ static void handle_input_choice(int ch)
snprintf(buf, sizeof(buf), "New Value for %.10s-%2d: ", snprintf(buf, sizeof(buf), "New Value for %.10s-%2d: ",
ptdata.cdi[cdev_id].type, ptdata.cdi[cdev_id].type,
ptdata.cdi[cdev_id].instance); ptdata.cdi[cdev_id].instance);
write_dialogue_win(buf, DIAG_DEV_ROWS+2, 2); write_dialogue_win(buf, diag_dev_rows() + 2, 2);
handle_input_val(cdev_id); handle_input_val(cdev_id);
} else { } else {
snprintf(buf, sizeof(buf), "Invalid selection %d", ch); snprintf(buf, sizeof(buf), "Invalid selection %d", ch);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment