From patchwork Tue Mar 12 11:45:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanjay Singh Rawat X-Patchwork-Id: 15282 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 2798E23E48 for ; Tue, 12 Mar 2013 11:46:47 +0000 (UTC) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by fiordland.canonical.com (Postfix) with ESMTP id C834BA18307 for ; Tue, 12 Mar 2013 11:46:46 +0000 (UTC) Received: by mail-ve0-f174.google.com with SMTP id pb11so3344292veb.19 for ; Tue, 12 Mar 2013 04:46:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=DvxM2nvinyciJYcA38Nq6yFoyDaZcMUFEUUjmDmM3vE=; b=BKHWocKuS9WIk4lWlrdgme5fxBQbb9n+tlHW023DkQBsDaBbRe9K0H5xeyfG9D9JFj rbHSII2UWgL4ifShvCmiD46D4zWheoNGvPJrFL4dQpS5gqfj3WXY8UT1dT5tSvgKCTmb ItgA5hmT+4QZ1UfRrha2VkiUaH21R7oanOf7c4w07KEhLu1IfS0HQY7L2XzAUjnN6M27 8uJVfmImU6/dkrPUVpE9ef19laAAIMWdsnDjXNAZt7FHbSrYg3sLcRgKLGE2bZFj95/u pm6ZC/QLLQFEDdm9MTCT0iB0B66mXiUEMNaueaH4KEkIHnO69L88O600Ja8gYGnekw7q 4HEA== X-Received: by 10.58.205.179 with SMTP id lh19mr6503163vec.7.1363088806254; Tue, 12 Mar 2013 04:46:46 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp123501veb; Tue, 12 Mar 2013 04:46:45 -0700 (PDT) X-Received: by 10.68.197.70 with SMTP id is6mr36945254pbc.79.1363088804991; Tue, 12 Mar 2013 04:46:44 -0700 (PDT) Received: from mail-da0-x22e.google.com (mail-da0-x22e.google.com [2607:f8b0:400e:c00::22e]) by mx.google.com with ESMTPS id tp7si28995029pbc.51.2013.03.12.04.46.44 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 12 Mar 2013 04:46:44 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400e:c00::22e is neither permitted nor denied by best guess record for domain of sanjay.rawat@linaro.org) client-ip=2607:f8b0:400e:c00::22e; Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400e:c00::22e is neither permitted nor denied by best guess record for domain of sanjay.rawat@linaro.org) smtp.mail=sanjay.rawat@linaro.org Received: by mail-da0-f46.google.com with SMTP id z8so818365dad.33 for ; Tue, 12 Mar 2013 04:46:44 -0700 (PDT) X-Received: by 10.68.213.7 with SMTP id no7mr36150212pbc.48.1363088804227; Tue, 12 Mar 2013 04:46:44 -0700 (PDT) Received: from srawat-Latitude-E6420.LGE.NET ([203.247.149.152]) by mx.google.com with ESMTPS id rl3sm24700295pbb.28.2013.03.12.04.46.40 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 12 Mar 2013 04:46:43 -0700 (PDT) From: Sanjay Singh Rawat To: linaro-dev@lists.linaro.org Cc: Sanjay Singh Rawat Subject: [PATCH powertop] thermal: add window for thermal related infromation Date: Tue, 12 Mar 2013 17:15:20 +0530 Message-Id: <1363088720-25245-2-git-send-email-sanjay.rawat@linaro.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1363088720-25245-1-git-send-email-sanjay.rawat@linaro.com> References: <1363088720-25245-1-git-send-email-sanjay.rawat@linaro.com> X-Gm-Message-State: ALoCoQnuX9+3V7PT+CNQbwHuMCugIXUY8IojbztsevccmuwSeFjSF/f0oLba1RA3vSNX8KABUqct add a window to display the stats of thermal, cooling zones and also information given by the hwmon sensor. Signed-off-by: Sanjay Singh Rawat --- src/Makefile.am | 2 +- src/display.cpp | 1 + src/main.cpp | 3 +- src/measurement/thermal.cpp | 148 +++++++++++++++++++++++++++++++++++++++++++ src/measurement/thermal.h | 1 + 5 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 src/measurement/thermal.cpp create mode 100644 src/measurement/thermal.h diff --git a/src/Makefile.am b/src/Makefile.am index f60426a..335fb6c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,7 +34,7 @@ powertop_SOURCES = parameters/persistent.cpp parameters/learn.cpp parameters/par report/report-formatter-base.cpp report/report-formatter-base.h \ report/report-formatter-csv.cpp report/report-formatter-csv.h \ report/report-formatter-html.cpp report/report-formatter-html.h \ - main.cpp css.h powertop.css cpu/intel_gpu.cpp + main.cpp css.h powertop.css cpu/intel_gpu.cpp measurement/thermal.h measurement/thermal.cpp powertop_CXXFLAGS = -fno-omit-frame-pointer -fstack-protector -Wall -Wshadow -Wformat $(NCURSES_CFLAGS) $(PCIUTILS_CFLAGS) $(LIBNL_CFLAGS) $(GLIB2_CFLAGS) diff --git a/src/display.cpp b/src/display.cpp index c76ba27..adcf80d 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -71,6 +71,7 @@ void init_display(void) create_tab("Idle stats", _("Idle stats")); create_tab("Frequency stats", _("Frequency stats")); create_tab("Device stats", _("Device stats")); + create_tab("Thermal stats", _("Thermal stats")); display = 1; } diff --git a/src/main.cpp b/src/main.cpp index e6036ae..e649919 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,7 +51,7 @@ #include "parameters/parameters.h" #include "calibrate/calibrate.h" - +#include "measurement/thermal.h" #include "tuning/tuning.h" #include "display.h" @@ -214,6 +214,7 @@ void one_measurement(int seconds, char *workload) report_display_cpu_pstates(); report_process_update_display(); + thermal_update_display(); tuning_update_display(); end_process_data(); diff --git a/src/measurement/thermal.cpp b/src/measurement/thermal.cpp new file mode 100644 index 0000000..c2c4c11 --- /dev/null +++ b/src/measurement/thermal.cpp @@ -0,0 +1,148 @@ +/* + * This is part of PowerTOP + * + * This program file is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program in a file named COPYING; if not, write to the + * Free Software Foundation, Inc, + * 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * or just google for it. + * + * getopt code is taken from "The GNU C Library" reference manual, + * section 24.2 "Parsing program options using getopt" + * http://www.gnu.org/s/libc/manual/html_node/Getopt-Long-Option-Example.html + * Manual published under the terms of the Free Documentation License. + */ + +#include +#include +#include "../display.h" +#include "../lib.h" + +enum attr_length { + SHORTT, + LONGT +}; + +static int get_thermal_attr(WINDOW *win, char *zone, const char *attr, int wide) +{ + char buf[512]; + int val; + string line; + + if(!wide) + wprintw(win,"%17s : ",attr); + else + wprintw(win,"%s : ",attr); + for(val=0 ; val<255 ; val++) { + sprintf(buf,"%s%d/%s",zone,val,attr); + if (access(buf, R_OK) !=0) { + wprintw(win," *\n"); + return -1; + } + line = read_sysfs_string("%s", buf); + wprintw(win," %s -",line.c_str()); + } + wprintw(win,"\n"); + return 0; +} + +static int get_thermal_zone_info(WINDOW *win) +{ + char linebuf[1024]; + string line; + + sprintf(linebuf,"/sys/class/thermal/thermal_zone"); + + wprintw(win,"\n[Zone : Thermal]----------------------------------------------\n"); + get_thermal_attr(win, linebuf, "type",SHORTT); + get_thermal_attr(win, linebuf, "temp",SHORTT); + get_thermal_attr(win, linebuf, "mode",SHORTT); + get_thermal_attr(win, linebuf, "policy",SHORTT); + get_thermal_attr(win, linebuf, "passive",SHORTT); + //todo: currently assuming only 3 trip points + get_thermal_attr(win, linebuf, "trip_point_0_temp",LONGT); + get_thermal_attr(win, linebuf, "trip_point_0_type",LONGT); + get_thermal_attr(win, linebuf, "trip_point_1_temp",LONGT); + get_thermal_attr(win, linebuf, "trip_point_1_type",LONGT); + get_thermal_attr(win, linebuf, "trip_point_2_temp",LONGT); + get_thermal_attr(win, linebuf, "trip_point_2_type",LONGT); + + return 0; +} + +static int get_cooling_zone_info(WINDOW *win) +{ + char linebuf[1024]; + string line; + + sprintf(linebuf,"/sys/class/thermal/cooling_device"); + + wprintw(win,"\n[Zone : Cooling]----------------------------------------------\n"); + get_thermal_attr(win, linebuf, "type",SHORTT); + get_thermal_attr(win, linebuf, "cur_state",SHORTT); + get_thermal_attr(win, linebuf, "max_state",SHORTT); + + return 0; +} + +static int get_hwmon_info(WINDOW *win) +{ + char linebuf[1024]; + string line; + + sprintf(linebuf,"/sys/class/hwmon/hwmon"); + + wprintw(win,"\n[HWMON info]--------------------------------------------------\n"); + get_thermal_attr(win, linebuf, "name",SHORTT); + get_thermal_attr(win, linebuf, "temp1_input",SHORTT); + get_thermal_attr(win, linebuf, "temp1_crit",SHORTT); + get_thermal_attr(win, linebuf, "temp1_max",SHORTT); + get_thermal_attr(win, linebuf, "temp2_input",SHORTT); + get_thermal_attr(win, linebuf, "temp2_crit",SHORTT); + get_thermal_attr(win, linebuf, "temp2_max",SHORTT); + get_thermal_attr(win, linebuf, "temp3_input",SHORTT); + get_thermal_attr(win, linebuf, "temp3_crit",SHORTT); + get_thermal_attr(win, linebuf, "temp3_max",SHORTT); + get_thermal_attr(win, linebuf, "fan1_input",SHORTT); + get_thermal_attr(win, linebuf, "fan2_input",SHORTT); + get_thermal_attr(win, linebuf, "fan3_input",SHORTT); + //todo: add more hwmon info + + return 0; +} + +void thermal_update_display(void) +{ + WINDOW *win; + + win = get_ncurses_win("Thermal stats"); + if (!win) { + printf("error: Window Thermal stats not found\n"); + return; + } + wclear(win); + wmove(win, 1,0); + + wprintw(win," *** Thermal window ***\n\n"); + wprintw(win,"[Note: '*' means no-more/no parameters]\n\n"); + wprintw(win,"[Params : Per-Devices-Info(1->n)]\n"); + wprintw(win," | |\n"); + wprintw(win," | |\n"); + wprintw(win," V V"); + + get_cooling_zone_info(win); + get_thermal_zone_info(win); + get_hwmon_info(win); + + +} diff --git a/src/measurement/thermal.h b/src/measurement/thermal.h new file mode 100644 index 0000000..104e968 --- /dev/null +++ b/src/measurement/thermal.h @@ -0,0 +1 @@ +extern void thermal_update_display(void);