<div dir="ltr"><div><div>Steven,<br><br></div>Can you enclose all the unix-specific parts in #ifdef PIPE_OS_UNIX to allow this to build for Windows?<br><br></div>-Brian<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 12, 2016 at 1:22 PM, Karol Herbst <span dir="ltr"><<a href="mailto:karolherbst@gmail.com" target="_blank">karolherbst@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hey,<br>
<br>
nice work regarding the lmsensor bits. But I think it makes sense to<br>
also wire the power things in, cause we actually expose them within<br>
nouveau. Others might want or actually do the same as well.<br>
<br>
Many thanks<br>
<br>
2016-09-12 20:33 GMT+02:00 Steven Toth <<a href="mailto:stoth@kernellabs.com">stoth@kernellabs.com</a>>:<br>
> Three new features:<br>
> 1. Disk/block I/O device read/write stats MB/ps.<br>
> 2. Network Interface RX/TX transfer statistics as a percentage<br>
> of the overall NIC speed.<br>
> 3. lmsensor power, voltage and temperature sensors.<br>
><br>
> The lmsensor changes makes a dependency on libsensors so support<br>
> so the change is opt out by default.<br>
><br>
> Signed-off-by: Steven Toth <<a href="mailto:stoth@kernellabs.com">stoth@kernellabs.com</a>><br>
> ---<br>
> <a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> | 20 ++<br>
> src/gallium/auxiliary/<wbr>Makefile.am | 4 +<br>
> src/gallium/auxiliary/<wbr>Makefile.sources | 3 +<br>
> src/gallium/auxiliary/hud/hud_<wbr>context.c | 67 ++++<br>
> src/gallium/auxiliary/hud/hud_<wbr>diskstat.c | 331 ++++++++++++++++++++<br>
> src/gallium/auxiliary/hud/hud_<wbr>nic.c | 437 +++++++++++++++++++++++++++<br>
> src/gallium/auxiliary/hud/hud_<wbr>private.h | 23 ++<br>
> src/gallium/auxiliary/hud/hud_<wbr>sensors_temp.c | 374 +++++++++++++++++++++++<br>
> src/gallium/include/pipe/p_<wbr>defines.h | 4 +<br>
> 9 files changed, 1263 insertions(+)<br>
> create mode 100644 src/gallium/auxiliary/hud/hud_<wbr>diskstat.c<br>
> create mode 100644 src/gallium/auxiliary/hud/hud_<wbr>nic.c<br>
> create mode 100644 src/gallium/auxiliary/hud/hud_<wbr>sensors_temp.c<br>
><br>
> diff --git a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> index a413a3a..ef4671a 100644<br>
> --- a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> +++ b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> @@ -91,6 +91,7 @@ XCBGLX_REQUIRED=1.8.1<br>
> XSHMFENCE_REQUIRED=1.1<br>
> XVMC_REQUIRED=1.0.6<br>
> PYTHON_MAKO_REQUIRED=0.8.0<br>
> +LIBSENSORS_REQUIRED=4.0.0<br>
><br>
> dnl Check for progs<br>
> AC_PROG_CPP<br>
> @@ -871,6 +872,17 @@ AC_ARG_ENABLE([dri],<br>
> [enable_dri="$enableval"],<br>
> [enable_dri=yes])<br>
><br>
> +#PKG_CHECK_MODULES([<wbr>LIBSENSORS], [libsensors >= $LIBSENSORS_REQUIRED], [enable_lmsensors=yes], [enable_lmsensors=no])<br>
> +AC_ARG_ENABLE([lmsensors],<br>
> + [AS_HELP_STRING([--enable-<wbr>lmsensors],<br>
> + [enable HUD lmsensor support @<:@default=disabled@:>@])],<br>
> + [enable_lmsensors="$enableval"<wbr>],<br>
> + [enable_lmsensors=no])<br>
> +AM_CONDITIONAL(HAVE_<wbr>LMSENSORS, test "x$enable_lmsensors" = xyes)<br>
> +if test "x$enable_lmsensors" = xyes ; then<br>
> + DEFINES="${DEFINES} -DHAVE_LMSENSORS=1"<br>
> +fi<br>
> +<br>
> case "$host_os" in<br>
> linux*)<br>
> dri3_default=yes<br>
> @@ -1122,6 +1134,7 @@ AM_CONDITIONAL(HAVE_DRISW_KMS, test "x$have_drisw_kms" = xyes )<br>
> AM_CONDITIONAL(HAVE_DRI2, test "x$enable_dri" = xyes -a "x$dri_platform" = xdrm -a "x$have_libdrm" = xyes )<br>
> AM_CONDITIONAL(HAVE_DRI3, test "x$enable_dri3" = xyes -a "x$dri_platform" = xdrm -a "x$have_libdrm" = xyes )<br>
> AM_CONDITIONAL(HAVE_APPLEDRI, test "x$enable_dri" = xyes -a "x$dri_platform" = xapple )<br>
> +AM_CONDITIONAL(HAVE_<wbr>LMSENSORS, test "x$enable_lmsensors" = xyes )<br>
><br>
> AC_ARG_ENABLE([shared-glapi],<br>
> [AS_HELP_STRING([--enable-<wbr>shared-glapi],<br>
> @@ -2876,6 +2889,13 @@ else<br>
> echo " Gallium: no"<br>
> fi<br>
><br>
> +echo ""<br>
> +if test "x$enable_lmsensors" != xyes; then<br>
> + echo " lmsensors: no"<br>
> +else<br>
> + echo " lmsensors: yes"<br>
> +fi<br>
> +<br>
> dnl Shader cache<br>
> echo ""<br>
> echo " Shader cache: $enable_shader_cache"<br>
> diff --git a/src/gallium/auxiliary/<wbr>Makefile.am b/src/gallium/auxiliary/<wbr>Makefile.am<br>
> index d971a2b..4e77c9d 100644<br>
> --- a/src/gallium/auxiliary/<wbr>Makefile.am<br>
> +++ b/src/gallium/auxiliary/<wbr>Makefile.am<br>
> @@ -34,6 +34,10 @@ libgallium_la_SOURCES += \<br>
><br>
> endif<br>
><br>
> +if HAVE_LMSENSORS<br>
> +libgallium_la_LDFLAGS = -lsensors<br>
> +endif<br>
> +<br>
> MKDIR_GEN = $(AM_V_at)$(MKDIR_P) $(@D)<br>
> PYTHON_GEN = $(AM_V_GEN)$(PYTHON2) $(PYTHON_FLAGS)<br>
><br>
> diff --git a/src/gallium/auxiliary/<wbr>Makefile.sources b/src/gallium/auxiliary/<wbr>Makefile.sources<br>
> index f8954c9..650a403 100644<br>
> --- a/src/gallium/auxiliary/<wbr>Makefile.sources<br>
> +++ b/src/gallium/auxiliary/<wbr>Makefile.sources<br>
> @@ -62,6 +62,9 @@ C_SOURCES := \<br>
> hud/hud_context.c \<br>
> hud/hud_context.h \<br>
> hud/hud_cpu.c \<br>
> + hud/hud_nic.c \<br>
> + hud/hud_diskstat.c \<br>
> + hud/hud_sensors_temp.c \<br>
> hud/hud_driver_query.c \<br>
> hud/hud_fps.c \<br>
> hud/hud_private.h \<br>
> diff --git a/src/gallium/auxiliary/hud/<wbr>hud_context.c b/src/gallium/auxiliary/hud/<wbr>hud_context.c<br>
> index f1a1cee..a90103b 100644<br>
> --- a/src/gallium/auxiliary/hud/<wbr>hud_context.c<br>
> +++ b/src/gallium/auxiliary/hud/<wbr>hud_context.c<br>
> @@ -257,6 +257,10 @@ number_to_human_readable(<wbr>uint64_t num, uint64_t max_value,<br>
> static const char *hz_units[] =<br>
> {" Hz", " KHz", " MHz", " GHz"};<br>
> static const char *percent_units[] = {"%"};<br>
> + static const char *dbm_units[] = {" (-dBm)"};<br>
> + static const char *temperature_units[] = {" C"};<br>
> + static const char *volt_units[] = {" V"};<br>
> + static const char *amp_units[] = {" mA", " A"};<br>
><br>
> const char **units;<br>
> unsigned max_unit;<br>
> @@ -269,6 +273,22 @@ number_to_human_readable(<wbr>uint64_t num, uint64_t max_value,<br>
> max_unit = ARRAY_SIZE(time_units)-1;<br>
> units = time_units;<br>
> break;<br>
> + case PIPE_DRIVER_QUERY_TYPE_VOLTS:<br>
> + max_unit = ARRAY_SIZE(volt_units)-1;<br>
> + units = volt_units;<br>
> + break;<br>
> + case PIPE_DRIVER_QUERY_TYPE_AMPS:<br>
> + max_unit = ARRAY_SIZE(amp_units)-1;<br>
> + units = amp_units;<br>
> + break;<br>
> + case PIPE_DRIVER_QUERY_TYPE_DBM:<br>
> + max_unit = ARRAY_SIZE(dbm_units)-1;<br>
> + units = dbm_units;<br>
> + break;<br>
> + case PIPE_DRIVER_QUERY_TYPE_<wbr>TEMPERATURE:<br>
> + max_unit = ARRAY_SIZE(temperature_units)-<wbr>1;<br>
> + units = temperature_units;<br>
> + break;<br>
> case PIPE_DRIVER_QUERY_TYPE_<wbr>PERCENTAGE:<br>
> max_unit = ARRAY_SIZE(percent_units)-1;<br>
> units = percent_units;<br>
> @@ -993,6 +1013,7 @@ hud_parse_env_var(struct hud_context *hud, const char *env)<br>
> }<br>
><br>
> /* Add a graph. */<br>
> + char arg_name[64];<br>
> /* IF YOU CHANGE THIS, UPDATE print_help! */<br>
> if (strcmp(name, "fps") == 0) {<br>
> hud_fps_graph_install(pane);<br>
> @@ -1003,6 +1024,46 @@ hud_parse_env_var(struct hud_context *hud, const char *env)<br>
> else if (sscanf(name, "cpu%u%s", &i, s) == 1) {<br>
> hud_cpu_graph_install(pane, i);<br>
> }<br>
> + else if (sscanf(name, "nic-rx-%s", arg_name) == 1) {<br>
> + hud_nic_graph_install(pane, arg_name, NIC_DIRECTION_RX);<br>
> + }<br>
> + else if (sscanf(name, "nic-tx-%s", arg_name) == 1) {<br>
> + hud_nic_graph_install(pane, arg_name, NIC_DIRECTION_TX);<br>
> + }<br>
> + else if (sscanf(name, "nic-rssi-%s", arg_name) == 1) {<br>
> + hud_nic_graph_install(pane, arg_name, NIC_RSSI_DBM);<br>
> + pane->type = PIPE_DRIVER_QUERY_TYPE_DBM;<br>
> + }<br>
> + else if (sscanf(name, "diskstat-rd-%s", arg_name) == 1) {<br>
> + hud_diskstat_graph_install(<wbr>pane, arg_name, DISKSTAT_RD);<br>
> + pane->type = PIPE_DRIVER_QUERY_TYPE_BYTES;<br>
> + }<br>
> + else if (sscanf(name, "diskstat-wr-%s", arg_name) == 1) {<br>
> + hud_diskstat_graph_install(<wbr>pane, arg_name, DISKSTAT_WR);<br>
> + pane->type = PIPE_DRIVER_QUERY_TYPE_BYTES;<br>
> + }<br>
> +#if HAVE_LMSENSORS<br>
> + else if (sscanf(name, "sensors_temp_cu-%s", arg_name) == 1) {<br>
> + hud_sensors_temp_graph_<wbr>install(pane, &name[16],<br>
> + SENSORS_TEMP_CURRENT);<br>
> + pane->type = PIPE_DRIVER_QUERY_TYPE_<wbr>TEMPERATURE;<br>
> + }<br>
> + else if (sscanf(name, "sensors_temp_cr-%s", arg_name) == 1) {<br>
> + hud_sensors_temp_graph_<wbr>install(pane, &name[16],<br>
> + SENSORS_TEMP_CRITICAL);<br>
> + pane->type = PIPE_DRIVER_QUERY_TYPE_<wbr>TEMPERATURE;<br>
> + }<br>
> + else if (sscanf(name, "sensors_volt_cu-%s", arg_name) == 1) {<br>
> + hud_sensors_temp_graph_<wbr>install(pane, &name[16],<br>
> + SENSORS_VOLTAGE_CURRENT);<br>
> + pane->type = PIPE_DRIVER_QUERY_TYPE_VOLTS;<br>
> + }<br>
> + else if (sscanf(name, "sensors_curr_cu-%s", arg_name) == 1) {<br>
> + hud_sensors_temp_graph_<wbr>install(pane, &name[16],<br>
> + SENSORS_CURRENT_CURRENT);<br>
> + pane->type = PIPE_DRIVER_QUERY_TYPE_AMPS;<br>
> + }<br>
> +#endif<br>
> else if (strcmp(name, "samples-passed") == 0 &&<br>
> has_occlusion_query(hud->pipe-<wbr>>screen)) {<br>
> hud_pipe_query_install(&hud-><wbr>batch_query, pane, hud->pipe,<br>
> @@ -1212,6 +1273,12 @@ print_help(struct pipe_screen *screen)<br>
> puts(" cs-invocations");<br>
> }<br>
><br>
> + hud_get_num_disks(1);<br>
> + hud_get_num_nics(1);<br>
> +#if HAVE_LMSENSORS<br>
> + hud_get_num_sensors(1);<br>
> +#endif<br>
> +<br>
> if (screen->get_driver_query_<wbr>info){<br>
> boolean skipping = false;<br>
> struct pipe_driver_query_info info;<br>
> diff --git a/src/gallium/auxiliary/hud/<wbr>hud_diskstat.c b/src/gallium/auxiliary/hud/<wbr>hud_diskstat.c<br>
> new file mode 100644<br>
> index 0000000..aee4964<br>
> --- /dev/null<br>
> +++ b/src/gallium/auxiliary/hud/<wbr>hud_diskstat.c<br>
> @@ -0,0 +1,331 @@<br>
> +/****************************<wbr>******************************<wbr>****************<br>
> + *<br>
> + * Copyright (C) 2016 Steven Toth <<a href="mailto:stoth@kernellabs.com">stoth@kernellabs.com</a>><br>
> + * Copyright (C) 2016 Zodiac Inflight Innovations<br>
> + * All Rights Reserved.<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the<br>
> + * "Software"), to deal in the Software without restriction, including<br>
> + * without limitation the rights to use, copy, modify, merge, publish,<br>
> + * distribute, sub license, and/or sell copies of the Software, and to<br>
> + * permit persons to whom the Software is furnished to do so, subject to<br>
> + * the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice (including the<br>
> + * next paragraph) shall be included in all copies or substantial portions<br>
> + * of the Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS<br>
> + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.<br>
> + * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR<br>
> + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,<br>
> + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE<br>
> + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.<br>
> + *<br>
> + ******************************<wbr>******************************<wbr>**************/<br>
> +<br>
> +/* Purpose: Reading /sys/block/<*>/stat MB/s read/write throughput per second,<br>
> + * displaying on the HUD.<br>
> + */<br>
> +<br>
> +#include "hud/hud_private.h"<br>
> +#include "util/list.h"<br>
> +#include "os/os_time.h"<br>
> +#include "util/u_memory.h"<br>
> +#include <stdio.h><br>
> +#include <unistd.h><br>
> +#include <dirent.h><br>
> +#include <stdlib.h><br>
> +#include <unistd.h><br>
> +#include <inttypes.h><br>
> +#include <sys/types.h><br>
> +#include <sys/stat.h><br>
> +#include <unistd.h><br>
> +<br>
> +#define LOCAL_DEBUG 0<br>
> +<br>
> +struct stat_s<br>
> +{<br>
> + /* Read */<br>
> + uint64_t r_ios;<br>
> + uint64_t r_merges;<br>
> + uint64_t r_sectors;<br>
> + uint64_t r_ticks;<br>
> + /* Write */<br>
> + uint64_t w_ios;<br>
> + uint64_t w_merges;<br>
> + uint64_t w_sectors;<br>
> + uint64_t w_ticks;<br>
> + /* Misc */<br>
> + uint64_t in_flight;<br>
> + uint64_t io_ticks;<br>
> + uint64_t time_in_queue;<br>
> +};<br>
> +<br>
> +struct diskstat_info<br>
> +{<br>
> + struct list_head list;<br>
> + int mode; /* DISKSTAT_RD, DISKSTAT_WR */<br>
> + char name[64]; /* EG. sda5 */<br>
> +<br>
> + char sysfs_filename[128];<br>
> + uint64_t last_time;<br>
> + struct stat_s last_stat;<br>
> +};<br>
> +<br>
> +/* TODO: We don't handle dynamic block device / partition<br>
> + * arrival or removal.<br>
> + * Static globals specific to this HUD category.<br>
> + */<br>
> +static int gdiskstat_count = 0;<br>
> +static struct list_head gdiskstat_list;<br>
> +<br>
> +static struct diskstat_info *<br>
> +find_dsi_by_name(char *n, int mode)<br>
> +{<br>
> + list_for_each_entry(struct diskstat_info, dsi, &gdiskstat_list, list) {<br>
> + if (dsi->mode != mode)<br>
> + continue;<br>
> + if (strcasecmp(dsi->name, n) == 0)<br>
> + return dsi;<br>
> + }<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int<br>
> +get_file_values(struct diskstat_info *dsi, struct stat_s *s)<br>
> +{<br>
> + int ret = 0;<br>
> + FILE *fh = fopen(dsi->sysfs_filename, "r");<br>
> + if (!fh)<br>
> + return -1;<br>
> +<br>
> + ret = fscanf(fh,<br>
> + "%" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64<br>
> + " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 "",<br>
> + &s->r_ios, &s->r_merges, &s->r_sectors, &s->r_ticks, &s->w_ios,<br>
> + &s->w_merges, &s->w_sectors, &s->w_ticks, &s->in_flight, &s->io_ticks,<br>
> + &s->time_in_queue);<br>
> +<br>
> + fclose(fh);<br>
> +<br>
> + return ret;<br>
> +}<br>
> +<br>
> +static void<br>
> +query_dsi_load(struct hud_graph *gr)<br>
> +{<br>
> + /* The framework calls us periodically, compensate for the<br>
> + * calling interval accordingly when reporting per second.<br>
> + */<br>
> + struct diskstat_info *dsi = gr->query_data;<br>
> + uint64_t now = os_time_get();<br>
> +<br>
> + if (dsi->last_time) {<br>
> + if (dsi->last_time + gr->pane->period <= now) {<br>
> + struct stat_s stat;<br>
> + if (get_file_values(dsi, &stat) < 0)<br>
> + return;<br>
> + float val = 0;<br>
> +<br>
> + switch (dsi->mode) {<br>
> + case DISKSTAT_RD:<br>
> + val =<br>
> + ((stat.r_sectors -<br>
> + dsi->last_stat.r_sectors) * 512) /<br>
> + (((float) gr->pane->period / 1000) / 1000);<br>
> + break;<br>
> + case DISKSTAT_WR:<br>
> + val =<br>
> + ((stat.w_sectors -<br>
> + dsi->last_stat.w_sectors) * 512) /<br>
> + (((float) gr->pane->period / 1000) / 1000);<br>
> + break;<br>
> + }<br>
> +<br>
> + hud_graph_add_value(gr, (uint64_t) val);<br>
> + dsi->last_stat = stat;<br>
> + dsi->last_time = now;<br>
> + }<br>
> + }<br>
> + else {<br>
> + /* initialize */<br>
> + switch (dsi->mode) {<br>
> + case DISKSTAT_RD:<br>
> + case DISKSTAT_WR:<br>
> + get_file_values(dsi, &dsi->last_stat);<br>
> + break;<br>
> + }<br>
> + dsi->last_time = now;<br>
> + }<br>
> +}<br>
> +<br>
> +static void<br>
> +free_query_data(void *p)<br>
> +{<br>
> + struct diskstat_info *nic = (struct diskstat_info *) p;<br>
> + list_del(&nic->list);<br>
> + FREE(nic);<br>
> +}<br>
> +<br>
> +/**<br>
> + * Create and initialize a new object for a specific block I/O device.<br>
> + * \param pane parent context.<br>
> + * \param dev_name logical block device name, EG. sda5.<br>
> + * \param mode query read or write (DISKSTAT_RD/DISKSTAT_WR) statistics.<br>
> + */<br>
> +void<br>
> +hud_diskstat_graph_install(<wbr>struct hud_pane *pane, char *dev_name,<br>
> + unsigned int mode)<br>
> +{<br>
> + struct hud_graph *gr;<br>
> + struct diskstat_info *dsi;<br>
> +<br>
> + int num_devs = hud_get_num_disks(0);<br>
> + if (num_devs <= 0)<br>
> + return;<br>
> +<br>
> +#if LOCAL_DEBUG<br>
> + printf("%s(%s, %s) - Creating HUD object\n", __func__, dev_name,<br>
> + mode == DISKSTAT_RD ? "RD" :<br>
> + mode == DISKSTAT_WR ? "WR" : "UNDEFINED");<br>
> +#endif<br>
> +<br>
> + dsi = find_dsi_by_name(dev_name, mode);<br>
> + if (!dsi)<br>
> + return;<br>
> +<br>
> + gr = CALLOC_STRUCT(hud_graph);<br>
> + if (!gr)<br>
> + return;<br>
> +<br>
> + dsi->mode = mode;<br>
> + if (dsi->mode == DISKSTAT_RD) {<br>
> + sprintf(gr->name, "%s-Read-MB/s", dsi->name);<br>
> + }<br>
> + else if (dsi->mode == DISKSTAT_WR) {<br>
> + sprintf(gr->name, "%s-Write-MB/s", dsi->name);<br>
> + }<br>
> + else<br>
> + return;<br>
> +<br>
> + gr->query_data = dsi;<br>
> + gr->query_new_value = query_dsi_load;<br>
> +<br>
> + /* Don't use free() as our callback as that messes up Gallium's<br>
> + * memory debugger. Use simple free_query_data() wrapper.<br>
> + */<br>
> + gr->free_query_data = free_query_data;<br>
> +<br>
> + hud_pane_add_graph(pane, gr);<br>
> + hud_pane_set_max_value(pane, 100);<br>
> +}<br>
> +<br>
> +static void<br>
> +add_object_part(char *basename, char *name, int objmode)<br>
> +{<br>
> + struct diskstat_info *dsi = CALLOC_STRUCT(diskstat_info);<br>
> +<br>
> + strcpy(dsi->name, name);<br>
> + sprintf(dsi->sysfs_filename, "%s/%s/stat", basename, name);<br>
> + dsi->mode = objmode;<br>
> + list_addtail(&dsi->list, &gdiskstat_list);<br>
> + gdiskstat_count++;<br>
> +}<br>
> +<br>
> +static void<br>
> +add_object(char *basename, char *name, int objmode)<br>
> +{<br>
> + struct diskstat_info *dsi = CALLOC_STRUCT(diskstat_info);<br>
> +<br>
> + strcpy(dsi->name, name);<br>
> + sprintf(dsi->sysfs_filename, "%s/stat", basename);<br>
> + dsi->mode = objmode;<br>
> + list_addtail(&dsi->list, &gdiskstat_list);<br>
> + gdiskstat_count++;<br>
> +}<br>
> +<br>
> +/**<br>
> + * Initialize internal object arrays and display block I/O HUD help.<br>
> + * \param displayhelp true if the list of detected devices should be<br>
> + displayed on the console.<br>
> + * \return number of detected block I/O devices.<br>
> + */<br>
> +int<br>
> +hud_get_num_disks(int displayhelp)<br>
> +{<br>
> + struct dirent *dp;<br>
> + struct stat stat_buf;<br>
> + char name[64];<br>
> +<br>
> + /* Return the number of block devices and partitions. */<br>
> + if (gdiskstat_count)<br>
> + return gdiskstat_count;<br>
> +<br>
> + /* Scan /sys/block, for every object type we support, create and<br>
> + * persist an object to represent its different statistics.<br>
> + */<br>
> + list_inithead(&gdiskstat_list)<wbr>;<br>
> + DIR *dir = opendir("/sys/block/");<br>
> + if (!dir)<br>
> + return 0;<br>
> +<br>
> + while ((dp = readdir(dir)) != NULL) {<br>
> +<br>
> + /* Avoid 'lo' and '..' and '.' */<br>
> + if (strlen(dp->d_name) <= 2)<br>
> + continue;<br>
> +<br>
> + char basename[256];<br>
> + sprintf(basename, "/sys/block/%s", dp->d_name);<br>
> + sprintf(name, "%s/stat", basename);<br>
> + if (stat(name, &stat_buf) < 0)<br>
> + continue;<br>
> +<br>
> + if (!S_ISREG(stat_buf.st_mode))<br>
> + continue; /* Not a regular file */<br>
> +<br>
> + /* Add a physical block device with R/W stats */<br>
> + add_object(basename, dp->d_name, DISKSTAT_RD);<br>
> + add_object(basename, dp->d_name, DISKSTAT_WR);<br>
> +<br>
> + /* Add any partitions */<br>
> + struct dirent *dpart;<br>
> + DIR *pdir = opendir(basename);<br>
> + if (!pdir)<br>
> + return 0;<br>
> +<br>
> + while ((dpart = readdir(pdir)) != NULL) {<br>
> + /* Avoid 'lo' and '..' and '.' */<br>
> + if (strlen(dpart->d_name) <= 2)<br>
> + continue;<br>
> +<br>
> + char p[64];<br>
> + sprintf(p, "%s/%s/stat", basename, dpart->d_name);<br>
> + if (stat(p, &stat_buf) < 0)<br>
> + continue;<br>
> +<br>
> + if (!S_ISREG(stat_buf.st_mode))<br>
> + continue; /* Not a regular file */<br>
> +<br>
> + /* Add a partition with R/W stats */<br>
> + add_object_part(basename, dpart->d_name, DISKSTAT_RD);<br>
> + add_object_part(basename, dpart->d_name, DISKSTAT_WR);<br>
> + }<br>
> + }<br>
> +<br>
> + if (displayhelp) {<br>
> + list_for_each_entry(struct diskstat_info, dsi, &gdiskstat_list, list) {<br>
> + char line[32];<br>
> + sprintf(line, " diskstat-%s-%s",<br>
> + dsi->mode == DISKSTAT_RD ? "rd" :<br>
> + dsi->mode == DISKSTAT_WR ? "wr" : "undefined", dsi->name);<br>
> +<br>
> + puts(line);<br>
> + }<br>
> + }<br>
> +<br>
> + return gdiskstat_count;<br>
> +}<br>
> diff --git a/src/gallium/auxiliary/hud/<wbr>hud_nic.c b/src/gallium/auxiliary/hud/<wbr>hud_nic.c<br>
> new file mode 100644<br>
> index 0000000..d31f797<br>
> --- /dev/null<br>
> +++ b/src/gallium/auxiliary/hud/<wbr>hud_nic.c<br>
> @@ -0,0 +1,437 @@<br>
> +/****************************<wbr>******************************<wbr>****************<br>
> + *<br>
> + * Copyright (C) 2016 Steven Toth <<a href="mailto:stoth@kernellabs.com">stoth@kernellabs.com</a>><br>
> + * Copyright (C) 2016 Zodiac Inflight Innovations<br>
> + * All Rights Reserved.<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the<br>
> + * "Software"), to deal in the Software without restriction, including<br>
> + * without limitation the rights to use, copy, modify, merge, publish,<br>
> + * distribute, sub license, and/or sell copies of the Software, and to<br>
> + * permit persons to whom the Software is furnished to do so, subject to<br>
> + * the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice (including the<br>
> + * next paragraph) shall be included in all copies or substantial portions<br>
> + * of the Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS<br>
> + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.<br>
> + * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR<br>
> + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,<br>
> + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE<br>
> + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.<br>
> + *<br>
> + ******************************<wbr>******************************<wbr>**************/<br>
> +<br>
> +/* Purpose: Reading network interface RX/TX throughput per second,<br>
> + * displaying on the HUD.<br>
> + */<br>
> +<br>
> +#include "hud/hud_private.h"<br>
> +#include "util/list.h"<br>
> +#include "os/os_time.h"<br>
> +#include "util/u_memory.h"<br>
> +#include <stdio.h><br>
> +#include <unistd.h><br>
> +#include <dirent.h><br>
> +#include <stdlib.h><br>
> +#include <unistd.h><br>
> +#include <inttypes.h><br>
> +#include <sys/types.h><br>
> +#include <sys/stat.h><br>
> +#include <sys/socket.h><br>
> +#include <sys/ioctl.h><br>
> +#include <linux/wireless.h><br>
> +<br>
> +#define LOCAL_DEBUG 0<br>
> +<br>
> +struct nic_info<br>
> +{<br>
> + struct list_head list;<br>
> + int mode;<br>
> + char name[64];<br>
> + uint64_t speedMbps;<br>
> + int is_wireless;<br>
> +<br>
> + char throughput_filename[128];<br>
> + uint64_t last_time;<br>
> + uint64_t last_nic_bytes;<br>
> +};<br>
> +<br>
> +/* TODO: We don't handle dynamic NIC arrival or removal.<br>
> + * Static globals specific to this HUD category.<br>
> + */<br>
> +static int gnic_count = 0;<br>
> +static struct list_head gnic_list;<br>
> +<br>
> +static struct nic_info *<br>
> +find_nic_by_name(char *n, int mode)<br>
> +{<br>
> + list_for_each_entry(struct nic_info, nic, &gnic_list, list) {<br>
> + if (nic->mode != mode)<br>
> + continue;<br>
> +<br>
> + if (strcasecmp(nic->name, n) == 0)<br>
> + return nic;<br>
> + }<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static int<br>
> +get_file_value(char *fname, uint64_t * value)<br>
> +{<br>
> + FILE *fh = fopen(fname, "r");<br>
> + if (!fh)<br>
> + return -1;<br>
> + if (fscanf(fh, "%" PRIu64 "", value) != 0) {<br>
> + /* Error */<br>
> + }<br>
> + fclose(fh);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static boolean<br>
> +get_nic_bytes(struct nic_info *nic, uint64_t * bytes)<br>
> +{<br>
> + if (get_file_value(nic-><wbr>throughput_filename, bytes) < 0)<br>
> + return FALSE;<br>
> +<br>
> + return TRUE;<br>
> +}<br>
> +<br>
> +static void<br>
> +query_wifi_bitrate(struct nic_info *nic, uint64_t * bitrate)<br>
> +{<br>
> + int sockfd;<br>
> + struct iw_statistics stats;<br>
> + struct iwreq req;<br>
> +<br>
> + memset(&stats, 0, sizeof(stats));<br>
> + memset(&req, 0, sizeof(req));<br>
> +<br>
> + strcpy(req.ifr_name, nic->name);<br>
> + req.u.data.pointer = &stats;<br>
> + req.u.data.flags = 1;<br>
> + req.u.data.length = sizeof(struct iw_statistics);<br>
> +<br>
> + /* Any old socket will do, and a datagram socket is pretty cheap */<br>
> + if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {<br>
> + fprintf(stderr, "Unable to create socket for %s\n", nic->name);<br>
> + return;<br>
> + }<br>
> +<br>
> + if (ioctl(sockfd, SIOCGIWRATE, &req) == -1) {<br>
> + fprintf(stderr, "Error performing SIOCGIWSTATS on %s\n", nic->name);<br>
> + close(sockfd);<br>
> + return;<br>
> + }<br>
> + *bitrate = req.u.bitrate.value;<br>
> +<br>
> + close(sockfd);<br>
> +}<br>
> +<br>
> +static void<br>
> +query_nic_rssi(struct nic_info *nic, uint64_t * leveldBm)<br>
> +{<br>
> + int sockfd;<br>
> + struct iw_statistics stats;<br>
> + struct iwreq req;<br>
> +<br>
> + memset(&stats, 0, sizeof(stats));<br>
> + memset(&req, 0, sizeof(req));<br>
> +<br>
> + strcpy(req.ifr_name, nic->name);<br>
> + req.u.data.pointer = &stats;<br>
> + req.u.data.flags = 1;<br>
> + req.u.data.length = sizeof(struct iw_statistics);<br>
> +<br>
> + if (nic->mode != NIC_RSSI_DBM)<br>
> + return;<br>
> +<br>
> + /* Any old socket will do, and a datagram socket is pretty cheap */<br>
> + if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {<br>
> + fprintf(stderr, "Unable to create socket for %s\n", nic->name);<br>
> + return;<br>
> + }<br>
> +<br>
> + /* Perform the ioctl */<br>
> + if (ioctl(sockfd, SIOCGIWSTATS, &req) == -1) {<br>
> + fprintf(stderr, "Error performing SIOCGIWSTATS on %s\n", nic->name);<br>
> + close(sockfd);<br>
> + return;<br>
> + }<br>
> + *leveldBm = ((char) stats.qual.level * -1);<br>
> +<br>
> + close(sockfd);<br>
> +<br>
> +#if LOCAL_DEBUG<br>
> + printf("NIC signal level%s is %d%s.\n",<br>
> + (stats.qual.updated & IW_QUAL_DBM ? " (in dBm)" : ""),<br>
> + (char) stats.qual.level,<br>
> + (stats.qual.updated & IW_QUAL_LEVEL_UPDATED ? " (updated)" : ""));<br>
> +#endif<br>
> +}<br>
> +<br>
> +static void<br>
> +query_nic_load(struct hud_graph *gr)<br>
> +{<br>
> + /* The framework calls us at a regular but indefined period,<br>
> + * not once per second, compensate the statistics accordingly.<br>
> + */<br>
> +<br>
> + struct nic_info *nic = gr->query_data;<br>
> + uint64_t now = os_time_get();<br>
> +<br>
> + if (nic->last_time) {<br>
> + if (nic->last_time + gr->pane->period <= now) {<br>
> + switch (nic->mode) {<br>
> + case NIC_DIRECTION_RX:<br>
> + case NIC_DIRECTION_TX:<br>
> + {<br>
> + uint64_t bytes;<br>
> + get_nic_bytes(nic, &bytes);<br>
> + uint64_t nic_mbps =<br>
> + ((bytes - nic->last_nic_bytes) / 1000000) * 8;<br>
> +<br>
> + float speedMbps = nic->speedMbps;<br>
> + float periodMs = gr->pane->period / 1000;<br>
> + float bits = nic_mbps;<br>
> + float period_factor = periodMs / 1000;<br>
> + float period_speed = speedMbps * period_factor;<br>
> + float pct = (bits / period_speed) * 100;<br>
> +<br>
> + /* Scaling bps with a narrow time period into a second,<br>
> + * potentially suffers from routing errors at higher<br>
> + * periods. Eg 104%. Compensate.<br>
> + */<br>
> + if (pct > 100)<br>
> + pct = 100;<br>
> + hud_graph_add_value(gr, (uint64_t) pct);<br>
> +<br>
> + nic->last_nic_bytes = bytes;<br>
> + }<br>
> + break;<br>
> + case NIC_RSSI_DBM:<br>
> + {<br>
> + uint64_t leveldBm = 0;<br>
> + query_nic_rssi(nic, &leveldBm);<br>
> + hud_graph_add_value(gr, leveldBm);<br>
> + }<br>
> + break;<br>
> + }<br>
> +<br>
> + nic->last_time = now;<br>
> + }<br>
> + }<br>
> + else {<br>
> + /* initialize */<br>
> + switch (nic->mode) {<br>
> + case NIC_DIRECTION_RX:<br>
> + case NIC_DIRECTION_TX:<br>
> + get_nic_bytes(nic, &nic->last_nic_bytes);<br>
> + break;<br>
> + case NIC_RSSI_DBM:<br>
> + break;<br>
> + }<br>
> +<br>
> + nic->last_time = now;<br>
> + }<br>
> +}<br>
> +<br>
> +static void<br>
> +free_query_data(void *p)<br>
> +{<br>
> + struct nic_info *nic = (struct nic_info *) p;<br>
> + list_del(&nic->list);<br>
> + FREE(nic);<br>
> +}<br>
> +<br>
> +/**<br>
> + * Create and initialize a new object for a specific network interface dev.<br>
> + * \param pane parent context.<br>
> + * \param nic_name logical block device name, EG. eth0.<br>
> + * \param mode query type (NIC_DIRECTION_RX/WR/RSSI) statistics.<br>
> + */<br>
> +void<br>
> +hud_nic_graph_install(struct hud_pane *pane, char *nic_name,<br>
> + unsigned int mode)<br>
> +{<br>
> + struct hud_graph *gr;<br>
> + struct nic_info *nic;<br>
> +<br>
> + int num_nics = hud_get_num_nics(0);<br>
> + if (num_nics <= 0)<br>
> + return;<br>
> +<br>
> +#if LOCAL_DEBUG<br>
> + printf("%s(%s, %s) - Creating HUD object\n", __func__, nic_name,<br>
> + mode == NIC_DIRECTION_RX ? "RX" :<br>
> + mode == NIC_DIRECTION_TX ? "TX" :<br>
> + mode == NIC_RSSI_DBM ? "RSSI" : "UNDEFINED");<br>
> +#endif<br>
> +<br>
> + nic = find_nic_by_name(nic_name, mode);<br>
> + if (!nic)<br>
> + return;<br>
> +<br>
> + gr = CALLOC_STRUCT(hud_graph);<br>
> + if (!gr)<br>
> + return;<br>
> +<br>
> + nic->mode = mode;<br>
> + if (nic->mode == NIC_DIRECTION_RX) {<br>
> + sprintf(gr->name, "%s-rx-%lldMbps", nic->name, nic->speedMbps);<br>
> + }<br>
> + else if (nic->mode == NIC_DIRECTION_TX) {<br>
> + sprintf(gr->name, "%s-tx-%lldMbps", nic->name, nic->speedMbps);<br>
> + }<br>
> + else if (nic->mode == NIC_RSSI_DBM)<br>
> + sprintf(gr->name, "%s-rssi", nic->name);<br>
> + else<br>
> + return;<br>
> +<br>
> + gr->query_data = nic;<br>
> + gr->query_new_value = query_nic_load;<br>
> +<br>
> + /* Don't use free() as our callback as that messes up Gallium's<br>
> + * memory debugger. Use simple free_query_data() wrapper.<br>
> + */<br>
> + gr->free_query_data = free_query_data;<br>
> +<br>
> + hud_pane_add_graph(pane, gr);<br>
> + hud_pane_set_max_value(pane, 100);<br>
> +}<br>
> +<br>
> +static int<br>
> +is_wireless_nic(char *dirbase)<br>
> +{<br>
> + struct stat stat_buf;<br>
> +<br>
> + /* Check if its a wireless card */<br>
> + char fn[256];<br>
> + sprintf(fn, "%s/wireless", dirbase);<br>
> + if (stat(fn, &stat_buf) == 0)<br>
> + return 1;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void<br>
> +query_nic_bitrate(struct nic_info *nic, char *dirbase)<br>
> +{<br>
> + struct stat stat_buf;<br>
> +<br>
> + /* Check if its a wireless card */<br>
> + char fn[256];<br>
> + sprintf(fn, "%s/wireless", dirbase);<br>
> + if (stat(fn, &stat_buf) == 0) {<br>
> + /* we're a wireless nic */<br>
> + query_wifi_bitrate(nic, &nic->speedMbps);<br>
> + nic->speedMbps /= 1000000;<br>
> + }<br>
> + else {<br>
> + /* Must be a wired nic */<br>
> + sprintf(fn, "%s/speed", dirbase);<br>
> + get_file_value(fn, &nic->speedMbps);<br>
> + }<br>
> +}<br>
> +<br>
> +/**<br>
> + * Initialize internal object arrays and display NIC HUD help.<br>
> + * \param displayhelp true if the list of detected devices should be<br>
> + displayed on the console.<br>
> + * \return number of detected network interface devices.<br>
> + */<br>
> +int<br>
> +hud_get_num_nics(int displayhelp)<br>
> +{<br>
> + struct dirent *dp;<br>
> + struct stat stat_buf;<br>
> + struct nic_info *nic;<br>
> + char name[64];<br>
> +<br>
> + /* Return the number if network interfaces. */<br>
> + if (gnic_count)<br>
> + return gnic_count;<br>
> +<br>
> + /* Scan /sys/block, for every object type we support, create and<br>
> + * persist an object to represent its different statistics.<br>
> + */<br>
> + list_inithead(&gnic_list);<br>
> + DIR *dir = opendir("/sys/class/net/");<br>
> + if (!dir)<br>
> + return 0;<br>
> +<br>
> + while ((dp = readdir(dir)) != NULL) {<br>
> +<br>
> + /* Avoid 'lo' and '..' and '.' */<br>
> + if (strlen(dp->d_name) <= 2)<br>
> + continue;<br>
> +<br>
> + char basename[256];<br>
> + sprintf(basename, "/sys/class/net/%s", dp->d_name);<br>
> + sprintf(name, "%s/statistics/rx_bytes", basename);<br>
> + if (stat(name, &stat_buf) < 0)<br>
> + continue;<br>
> +<br>
> + if (!S_ISREG(stat_buf.st_mode))<br>
> + continue; /* Not a regular file */<br>
> +<br>
> + int is_wireless = is_wireless_nic(basename);<br>
> +<br>
> + /* Add the RX object */<br>
> + nic = CALLOC_STRUCT(nic_info);<br>
> + strcpy(nic->name, dp->d_name);<br>
> + sprintf(nic->throughput_<wbr>filename, "%s/statistics/rx_bytes", basename);<br>
> + nic->mode = NIC_DIRECTION_RX;<br>
> + nic->is_wireless = is_wireless;<br>
> + query_nic_bitrate(nic, basename);<br>
> +<br>
> + list_addtail(&nic->list, &gnic_list);<br>
> + gnic_count++;<br>
> +<br>
> + /* Add the TX object */<br>
> + nic = CALLOC_STRUCT(nic_info);<br>
> + strcpy(nic->name, dp->d_name);<br>
> + sprintf(nic->throughput_<wbr>filename,<br>
> + "/sys/class/net/%s/statistics/<wbr>tx_bytes", dp->d_name);<br>
> + nic->mode = NIC_DIRECTION_TX;<br>
> + nic->is_wireless = is_wireless;<br>
> +<br>
> + query_nic_bitrate(nic, basename);<br>
> +<br>
> + list_addtail(&nic->list, &gnic_list);<br>
> + gnic_count++;<br>
> +<br>
> + if (nic->is_wireless) {<br>
> + /* RSSI Support */<br>
> + nic = CALLOC_STRUCT(nic_info);<br>
> + strcpy(nic->name, dp->d_name);<br>
> + sprintf(nic->throughput_<wbr>filename,<br>
> + "/sys/class/net/%s/statistics/<wbr>tx_bytes", dp->d_name);<br>
> + nic->mode = NIC_RSSI_DBM;<br>
> +<br>
> + query_nic_bitrate(nic, basename);<br>
> +<br>
> + list_addtail(&nic->list, &gnic_list);<br>
> + gnic_count++;<br>
> + }<br>
> +<br>
> + }<br>
> +<br>
> + list_for_each_entry(struct nic_info, nic, &gnic_list, list) {<br>
> + char line[64];<br>
> + sprintf(line, " nic-%s-%s",<br>
> + nic->mode == NIC_DIRECTION_RX ? "rx" :<br>
> + nic->mode == NIC_DIRECTION_TX ? "tx" :<br>
> + nic->mode == NIC_RSSI_DBM ? "rssi" : "undefined", nic->name);<br>
> +<br>
> + puts(line);<br>
> +<br>
> + }<br>
> +<br>
> + return gnic_count;<br>
> +}<br>
> diff --git a/src/gallium/auxiliary/hud/<wbr>hud_private.h b/src/gallium/auxiliary/hud/<wbr>hud_private.h<br>
> index 2104c27..5e9da0c 100644<br>
> --- a/src/gallium/auxiliary/hud/<wbr>hud_private.h<br>
> +++ b/src/gallium/auxiliary/hud/<wbr>hud_private.h<br>
> @@ -103,4 +103,27 @@ boolean hud_driver_query_install(<wbr>struct hud_batch_query_context **pbq,<br>
> void hud_batch_query_update(struct hud_batch_query_context *bq);<br>
> void hud_batch_query_cleanup(struct hud_batch_query_context **pbq);<br>
><br>
> +int hud_get_num_nics(int displayhelp);<br>
> +#define NIC_DIRECTION_RX 1<br>
> +#define NIC_DIRECTION_TX 2<br>
> +#define NIC_RSSI_DBM 3<br>
> +void hud_nic_graph_install(struct hud_pane *pane, char *nic_index,<br>
> + unsigned int mode);<br>
> +<br>
> +int hud_get_num_disks(int displayhelp);<br>
> +#define DISKSTAT_RD 1<br>
> +#define DISKSTAT_WR 2<br>
> +void hud_diskstat_graph_install(<wbr>struct hud_pane *pane, char *dev_name,<br>
> + unsigned int mode);<br>
> +<br>
> +#if HAVE_LMSENSORS<br>
> +int hud_get_num_sensors(int displayhelp);<br>
> +#define SENSORS_TEMP_CURRENT 1<br>
> +#define SENSORS_TEMP_CRITICAL 2<br>
> +#define SENSORS_VOLTAGE_CURRENT 3<br>
> +#define SENSORS_CURRENT_CURRENT 4<br>
> +void hud_sensors_temp_graph_<wbr>install(struct hud_pane *pane, char *dev_name,<br>
> + unsigned int mode);<br>
> +#endif<br>
> +<br>
> #endif<br>
> diff --git a/src/gallium/auxiliary/hud/<wbr>hud_sensors_temp.c b/src/gallium/auxiliary/hud/<wbr>hud_sensors_temp.c<br>
> new file mode 100644<br>
> index 0000000..1a06079<br>
> --- /dev/null<br>
> +++ b/src/gallium/auxiliary/hud/<wbr>hud_sensors_temp.c<br>
> @@ -0,0 +1,374 @@<br>
> +/****************************<wbr>******************************<wbr>****************<br>
> + *<br>
> + * Copyright (C) 2016 Steven Toth <<a href="mailto:stoth@kernellabs.com">stoth@kernellabs.com</a>><br>
> + * Copyright (C) 2016 Zodiac Inflight Innovations<br>
> + * All Rights Reserved.<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the<br>
> + * "Software"), to deal in the Software without restriction, including<br>
> + * without limitation the rights to use, copy, modify, merge, publish,<br>
> + * distribute, sub license, and/or sell copies of the Software, and to<br>
> + * permit persons to whom the Software is furnished to do so, subject to<br>
> + * the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice (including the<br>
> + * next paragraph) shall be included in all copies or substantial portions<br>
> + * of the Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS<br>
> + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.<br>
> + * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR<br>
> + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,<br>
> + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE<br>
> + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.<br>
> + *<br>
> + ******************************<wbr>******************************<wbr>**************/<br>
> +<br>
> +#if HAVE_LMSENSORS<br>
> +/* Purpose: Extract lm-sensors data, expose temperature, power, voltage. */<br>
> +<br>
> +#include "hud/hud_private.h"<br>
> +#include "util/list.h"<br>
> +#include "os/os_time.h"<br>
> +#include "util/u_memory.h"<br>
> +#include <stdio.h><br>
> +#include <unistd.h><br>
> +#include <dirent.h><br>
> +#include <stdlib.h><br>
> +#include <unistd.h><br>
> +#include <inttypes.h><br>
> +#include <sys/types.h><br>
> +#include <sys/stat.h><br>
> +#include <unistd.h><br>
> +#include <sensors/sensors.h><br>
> +<br>
> +#define LOCAL_DEBUG 0<br>
> +<br>
> +/* TODO: We don't handle dynamic sensor discovery / arrival or removal.<br>
> + * Static globals specific to this HUD category.<br>
> + */<br>
> +static int gsensors_temp_count = 0;<br>
> +static struct list_head gsensors_temp_list;<br>
> +<br>
> +struct sensors_temp_info<br>
> +{<br>
> + struct list_head list;<br>
> +<br>
> + /* Combined chip and feature name, human readable. */<br>
> + char name[64];<br>
> +<br>
> + /* The type of measurement, critical or current. */<br>
> + unsigned int mode;<br>
> +<br>
> + uint64_t last_time;<br>
> +<br>
> + char chipname[64];<br>
> + char featurename[128];<br>
> +<br>
> + sensors_chip_name *chip;<br>
> + const sensors_feature *feature;<br>
> + double current, min, max, critical;<br>
> +};<br>
> +<br>
> +static double<br>
> +get_value(const sensors_chip_name * name, const sensors_subfeature * sub)<br>
> +{<br>
> + double val;<br>
> + int err;<br>
> +<br>
> + err = sensors_get_value(name, sub->number, &val);<br>
> + if (err) {<br>
> + fprintf(stderr, "ERROR: Can't get value of subfeature %s\n", sub->name);<br>
> + val = 0;<br>
> + }<br>
> + return val;<br>
> +}<br>
> +<br>
> +static void<br>
> +get_sensor_values(struct sensors_temp_info *sti)<br>
> +{<br>
> + const sensors_subfeature *sf;<br>
> +<br>
> + if (sti->mode == SENSORS_VOLTAGE_CURRENT) {<br>
> + sf = sensors_get_subfeature(sti-><wbr>chip, sti->feature,<br>
> + SENSORS_SUBFEATURE_IN_INPUT);<br>
> + if (sf)<br>
> + sti->current = get_value(sti->chip, sf);<br>
> + }<br>
> +<br>
> + if (sti->mode == SENSORS_CURRENT_CURRENT) {<br>
> + sf = sensors_get_subfeature(sti-><wbr>chip, sti->feature,<br>
> + SENSORS_SUBFEATURE_CURR_INPUT)<wbr>;<br>
> + if (sf) {<br>
> + /* Sensors API returns in AMPs, even though driver is reporting mA,<br>
> + * convert back to mA */<br>
> + sti->current = get_value(sti->chip, sf) * 1000;<br>
> + }<br>
> + }<br>
> +<br>
> + if (sti->mode == SENSORS_TEMP_CURRENT) {<br>
> + sf = sensors_get_subfeature(sti-><wbr>chip, sti->feature,<br>
> + SENSORS_SUBFEATURE_TEMP_INPUT)<wbr>;<br>
> + if (sf)<br>
> + sti->current = get_value(sti->chip, sf);<br>
> + }<br>
> +<br>
> + if (sti->mode == SENSORS_TEMP_CRITICAL) {<br>
> + sf = sensors_get_subfeature(sti-><wbr>chip, sti->feature,<br>
> + SENSORS_SUBFEATURE_TEMP_CRIT);<br>
> + if (sf)<br>
> + sti->critical = get_value(sti->chip, sf);<br>
> + }<br>
> +<br>
> + sf = sensors_get_subfeature(sti-><wbr>chip, sti->feature,<br>
> + SENSORS_SUBFEATURE_TEMP_MIN);<br>
> + if (sf)<br>
> + sti->min = get_value(sti->chip, sf);<br>
> +<br>
> + sf = sensors_get_subfeature(sti-><wbr>chip, sti->feature,<br>
> + SENSORS_SUBFEATURE_TEMP_MAX);<br>
> + if (sf)<br>
> + sti->max = get_value(sti->chip, sf);<br>
> +#if LOCAL_DEBUG<br>
> + printf("%s.%s.current = %.1f\n", sti->chipname, sti->featurename,<br>
> + sti->current);<br>
> + printf("%s.%s.critical = %.1f\n", sti->chipname, sti->featurename,<br>
> + sti->critical);<br>
> +#endif<br>
> +}<br>
> +<br>
> +static struct sensors_temp_info *<br>
> +find_sti_by_name(char *n, unsigned int mode)<br>
> +{<br>
> + list_for_each_entry(struct sensors_temp_info, sti, &gsensors_temp_list, list) {<br>
> + if (sti->mode != mode)<br>
> + continue;<br>
> + if (strcasecmp(sti->name, n) == 0)<br>
> + return sti;<br>
> + }<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void<br>
> +query_sti_load(struct hud_graph *gr)<br>
> +{<br>
> + struct sensors_temp_info *sti = gr->query_data;<br>
> + uint64_t now = os_time_get();<br>
> +<br>
> + if (sti->last_time) {<br>
> + if (sti->last_time + gr->pane->period <= now) {<br>
> + get_sensor_values(sti);<br>
> +<br>
> + switch (sti->mode) {<br>
> + case SENSORS_TEMP_CURRENT:<br>
> + hud_graph_add_value(gr, (uint64_t) sti->current);<br>
> + break;<br>
> + case SENSORS_TEMP_CRITICAL:<br>
> + hud_graph_add_value(gr, (uint64_t) sti->critical);<br>
> + break;<br>
> + case SENSORS_VOLTAGE_CURRENT:<br>
> + hud_graph_add_value(gr, (uint64_t) sti->current);<br>
> + break;<br>
> + case SENSORS_CURRENT_CURRENT:<br>
> + hud_graph_add_value(gr, (uint64_t) sti->current);<br>
> + break;<br>
> + }<br>
> +<br>
> + sti->last_time = now;<br>
> + }<br>
> + }<br>
> + else {<br>
> + /* initialize */<br>
> + get_sensor_values(sti);<br>
> + sti->last_time = now;<br>
> + }<br>
> +}<br>
> +<br>
> +static void<br>
> +free_query_data(void *p)<br>
> +{<br>
> + struct sensors_temp_info *sti = (struct sensors_temp_info *) p;<br>
> + list_del(&sti->list);<br>
> + if (sti->chip)<br>
> + sensors_free_chip_name(sti-><wbr>chip);<br>
> + FREE(sti);<br>
> + sensors_cleanup();<br>
> +}<br>
> +<br>
> +/**<br>
> + * Create and initialize a new object for a specific sensor interface dev.<br>
> + * \param pane parent context.<br>
> + * \param dev_name device name, EG. 'coretemp-isa-0000.Core 1'<br>
> + * \param mode query type (NIC_DIRECTION_RX/WR/RSSI) statistics.<br>
> + */<br>
> +void<br>
> +hud_sensors_temp_graph_<wbr>install(struct hud_pane *pane, char *dev_name,<br>
> + unsigned int mode)<br>
> +{<br>
> + struct hud_graph *gr;<br>
> + struct sensors_temp_info *sti;<br>
> +<br>
> + int num_devs = hud_get_num_sensors(0);<br>
> + if (num_devs <= 0)<br>
> + return;<br>
> +#if LOCAL_DEBUG<br>
> + printf("%s(%s, %s) - Creating HUD object\n", __func__, dev_name,<br>
> + mode == SENSORS_VOLTAGE_CURRENT ? "VOLTS" :<br>
> + mode == SENSORS_CURRENT_CURRENT ? "AMPS" :<br>
> + mode == SENSORS_TEMP_CURRENT ? "CU" :<br>
> + mode == SENSORS_TEMP_CRITICAL ? "CR" : "UNDEFINED");<br>
> +#endif<br>
> +<br>
> + sti = find_sti_by_name(dev_name, mode);<br>
> + if (!sti)<br>
> + return;<br>
> +<br>
> + gr = CALLOC_STRUCT(hud_graph);<br>
> + if (!gr)<br>
> + return;<br>
> +<br>
> + sprintf(gr->name, "%.6s..%s (%s)",<br>
> + sti->chipname,<br>
> + sti->featurename,<br>
> + sti->mode == SENSORS_VOLTAGE_CURRENT ? "Volts" :<br>
> + sti->mode == SENSORS_CURRENT_CURRENT ? "Amps" :<br>
> + sti->mode == SENSORS_TEMP_CURRENT ? "Curr" :<br>
> + sti->mode == SENSORS_TEMP_CRITICAL ? "Crit" : "Unkn");<br>
> +<br>
> + gr->query_data = sti;<br>
> + gr->query_new_value = query_sti_load;<br>
> +<br>
> + /* Don't use free() as our callback as that messes up Gallium's<br>
> + * memory debugger. Use simple free_query_data() wrapper.<br>
> + */<br>
> + gr->free_query_data = free_query_data;<br>
> +<br>
> + hud_pane_add_graph(pane, gr);<br>
> + switch (sti->mode) {<br>
> + case SENSORS_TEMP_CURRENT:<br>
> + case SENSORS_TEMP_CRITICAL:<br>
> + hud_pane_set_max_value(pane, 120);<br>
> + break;<br>
> + case SENSORS_VOLTAGE_CURRENT:<br>
> + hud_pane_set_max_value(pane, 12);<br>
> + break;<br>
> + case SENSORS_CURRENT_CURRENT:<br>
> + hud_pane_set_max_value(pane, 5000);<br>
> + break;<br>
> + }<br>
> +}<br>
> +<br>
> +static void<br>
> +create_object(char *chipname, char *featurename,<br>
> + const sensors_chip_name * chip, const sensors_feature * feature,<br>
> + int mode)<br>
> +{<br>
> +#if LOCAL_DEBUG<br>
> + printf("%03d: %s.%s\n", gsensors_temp_count, chipname, featurename);<br>
> +#endif<br>
> + struct sensors_temp_info *sti = CALLOC_STRUCT(sensors_temp_<wbr>info);<br>
> +<br>
> + sti->mode = mode;<br>
> + sti->chip = (sensors_chip_name *) chip;<br>
> + sti->feature = feature;<br>
> + strcpy(sti->chipname, chipname);<br>
> + strcpy(sti->featurename, featurename);<br>
> + sprintf(sti->name, "%s.%s", sti->chipname, sti->featurename);<br>
> +<br>
> + list_addtail(&sti->list, &gsensors_temp_list);<br>
> + gsensors_temp_count++;<br>
> +}<br>
> +<br>
> +static void<br>
> +build_sensor_list(void)<br>
> +{<br>
> + const sensors_chip_name *chip;<br>
> + const sensors_chip_name *match = 0;<br>
> + const sensors_feature *feature;<br>
> + int chip_nr = 0;<br>
> +<br>
> + char name[256];<br>
> + while ((chip = sensors_get_detected_chips(<wbr>match, &chip_nr))) {<br>
> + sensors_snprintf_chip_name(<wbr>name, sizeof(name), chip);<br>
> +<br>
> + /* Get all features and filter accordingly. */<br>
> + int fnr = 0;<br>
> + while ((feature = sensors_get_features(chip, &fnr))) {<br>
> + char *featurename = sensors_get_label(chip, feature);<br>
> + if (!featurename)<br>
> + continue;<br>
> +<br>
> + /* Create a 'current' and 'critical' object pair.<br>
> + * Ignore sensor if its not temperature based.<br>
> + */<br>
> + if (feature->type == SENSORS_FEATURE_TEMP) {<br>
> + create_object(name, featurename, chip, feature,<br>
> + SENSORS_TEMP_CURRENT);<br>
> + create_object(name, featurename, chip, feature,<br>
> + SENSORS_TEMP_CRITICAL);<br>
> + }<br>
> + if (feature->type == SENSORS_FEATURE_IN) {<br>
> + create_object(name, featurename, chip, feature,<br>
> + SENSORS_VOLTAGE_CURRENT);<br>
> + }<br>
> + if (feature->type == SENSORS_FEATURE_CURR) {<br>
> + create_object(name, featurename, chip, feature,<br>
> + SENSORS_CURRENT_CURRENT);<br>
> + }<br>
> + free(featurename);<br>
> + }<br>
> + }<br>
> +}<br>
> +<br>
> +/**<br>
> + * Initialize internal object arrays and display lmsensors HUD help.<br>
> + * \param displayhelp true if the list of detected devices should be<br>
> + displayed on the console.<br>
> + * \return number of detected lmsensor devices.<br>
> + */<br>
> +int<br>
> +hud_get_num_sensors(int displayhelp)<br>
> +{<br>
> + /* Return the number of sensors detected. */<br>
> + if (gsensors_temp_count)<br>
> + return gsensors_temp_count;<br>
> +<br>
> + int ret = sensors_init(NULL);<br>
> + if (ret)<br>
> + return 0;<br>
> +<br>
> + list_inithead(&gsensors_temp_<wbr>list);<br>
> +<br>
> + /* Scan /sys/block, for every object type we support, create and<br>
> + * persist an object to represent its different statistics.<br>
> + */<br>
> + build_sensor_list();<br>
> +<br>
> + if (displayhelp) {<br>
> + list_for_each_entry(struct sensors_temp_info, sti, &gsensors_temp_list, list) {<br>
> + char line[64];<br>
> + switch (sti->mode) {<br>
> + case SENSORS_TEMP_CURRENT:<br>
> + sprintf(line, " sensors_temp_cu-%s", sti->name);<br>
> + break;<br>
> + case SENSORS_TEMP_CRITICAL:<br>
> + sprintf(line, " sensors_temp_cr-%s", sti->name);<br>
> + break;<br>
> + case SENSORS_VOLTAGE_CURRENT:<br>
> + sprintf(line, " sensors_volt_cu-%s", sti->name);<br>
> + break;<br>
> + case SENSORS_CURRENT_CURRENT:<br>
> + sprintf(line, " sensors_curr_cu-%s", sti->name);<br>
> + break;<br>
> + }<br>
> +<br>
> + puts(line);<br>
> + }<br>
> + }<br>
> +<br>
> + return gsensors_temp_count;<br>
> +}<br>
> +<br>
> +#endif /* HAVE_LMSENSORS */<br>
> diff --git a/src/gallium/include/pipe/p_<wbr>defines.h b/src/gallium/include/pipe/p_<wbr>defines.h<br>
> index 88aa050..317a7c3 100644<br>
> --- a/src/gallium/include/pipe/p_<wbr>defines.h<br>
> +++ b/src/gallium/include/pipe/p_<wbr>defines.h<br>
> @@ -965,6 +965,10 @@ enum pipe_driver_query_type<br>
> PIPE_DRIVER_QUERY_TYPE_BYTES,<br>
> PIPE_DRIVER_QUERY_TYPE_<wbr>MICROSECONDS,<br>
> PIPE_DRIVER_QUERY_TYPE_HZ,<br>
> + PIPE_DRIVER_QUERY_TYPE_DBM,<br>
> + PIPE_DRIVER_QUERY_TYPE_<wbr>TEMPERATURE,<br>
> + PIPE_DRIVER_QUERY_TYPE_VOLTS,<br>
> + PIPE_DRIVER_QUERY_TYPE_AMPS,<br>
> };<br>
><br>
> /* Whether an average value per frame or a cumulative value should be<br>
> --<br>
> 2.7.4<br>
><br>
> ______________________________<wbr>_________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</blockquote></div><br></div>