Commit 8c60bcb4 authored by Steven Toth's avatar Steven Toth Committed by Brian Paul

gallium/hud: Add support for block I/O, network I/O and lmsensor stats

V8: Feedback based on peer review
    convert if block into a switch
    Constify some func args

V7: Increase precision when measuring lmsensors volts
    Flatten patch series.

V6: Feedback based on peer review
    Simplify sensor initialization (arg passing).
    Constify some func args

V5: Feedback based on peer review
    Convert sprintf to snprintf
    Convert char * to const char *
    int arg converted to bool
    Func changes to take a filename vs a larger struct.
    Omit the space between '*' and the param name.

V4: Merged with master as of 2016/9/27 6pm

V3: Flatten the entire patchset ready for the ML

V2: Additional seperate patches based on feedback
a) configure.ac: Add a comment related to libsensors

b) HUD: Disable Block/NIC I/O stats by default.
Implement configuration option --enable-gallium-extra-hud=yes
and enable both statistics when this option is enabled.

c) Configure.ac: Minor cleanup to user visible configuration settings

d) Configure.ac: HUD stats - build system improvements
Move the -lsensors out of a deeper Makefile, bring it into the configure.ac.
Also, rename a compiler directive to more closely follow the standard.

V1: Initial release to the ML
Three new features:
1. Disk/block I/O device read/write stats MB/ps.
2. Network Interface RX/TX transfer statistics as a percentage
   of the overall NIC speed.
3. lmsensor power, voltage and temperature sensors.

The lmsensor changes makes a dependency on libsensors so support
for the change is opt out by default.
Signed-off-by: 's avatarSteven Toth <stoth@kernellabs.com>
Reviewed-by: Brian Paul's avatarBrian Paul <brianp@vmware.com>
parent 29783c08
......@@ -91,6 +91,7 @@ XCBGLX_REQUIRED=1.8.1
XSHMFENCE_REQUIRED=1.1
XVMC_REQUIRED=1.0.6
PYTHON_MAKO_REQUIRED=0.8.0
LIBSENSORS_REQUIRED=4.0.0
dnl Check for progs
AC_PROG_CPP
......@@ -871,6 +872,32 @@ AC_ARG_ENABLE([dri],
[enable_dri="$enableval"],
[enable_dri=yes])
AC_ARG_ENABLE([gallium-extra-hud],
[AS_HELP_STRING([--enable-gallium-extra-hud],
[enable HUD block/NIC I/O HUD stats support @<:@default=disabled@:>@])],
[enable_gallium_extra_hud="$enableval"],
[enable_gallium_extra_hud=no])
AM_CONDITIONAL(HAVE_GALLIUM_EXTRA_HUD, test "x$enable_gallium_extra_hud" = xyes)
if test "x$enable_gallium_extra_hud" = xyes ; then
DEFINES="${DEFINES} -DHAVE_GALLIUM_EXTRA_HUD=1"
fi
#TODO: no pkgconfig .pc available for libsensors.
#PKG_CHECK_MODULES([LIBSENSORS], [libsensors >= $LIBSENSORS_REQUIRED], [enable_lmsensors=yes], [enable_lmsensors=no])
AC_ARG_ENABLE([lmsensors],
[AS_HELP_STRING([--enable-lmsensors],
[enable HUD lmsensor support @<:@default=disabled@:>@])],
[enable_lmsensors="$enableval"],
[enable_lmsensors=no])
AM_CONDITIONAL(HAVE_LIBSENSORS, test "x$enable_lmsensors" = xyes)
if test "x$enable_lmsensors" = xyes ; then
DEFINES="${DEFINES} -DHAVE_LIBSENSORS=1"
LIBSENSORS_LDFLAGS="-lsensors"
else
LIBSENSORS_LDFLAGS=""
fi
AC_SUBST(LIBSENSORS_LDFLAGS)
case "$host_os" in
linux*)
dri3_default=yes
......@@ -1124,6 +1151,8 @@ AM_CONDITIONAL(HAVE_DRISW_KMS, test "x$have_drisw_kms" = xyes )
AM_CONDITIONAL(HAVE_DRI2, test "x$enable_dri" = xyes -a "x$dri_platform" = xdrm -a "x$have_libdrm" = xyes )
AM_CONDITIONAL(HAVE_DRI3, test "x$enable_dri3" = xyes -a "x$dri_platform" = xdrm -a "x$have_libdrm" = xyes )
AM_CONDITIONAL(HAVE_APPLEDRI, test "x$enable_dri" = xyes -a "x$dri_platform" = xapple )
AM_CONDITIONAL(HAVE_LMSENSORS, test "x$enable_lmsensors" = xyes )
AM_CONDITIONAL(HAVE_GALLIUM_EXTRA_HUD, test "x$enable_gallium_extra_hud" = xyes )
AM_CONDITIONAL(HAVE_WINDOWSDRI, test "x$enable_dri" = xyes -a "x$dri_platform" = xwindows )
AC_ARG_ENABLE([shared-glapi],
......@@ -2891,6 +2920,19 @@ else
echo " Gallium: no"
fi
echo ""
if test "x$enable_gallium_extra_hud" != xyes; then
echo " HUD extra stats: no"
else
echo " HUD extra stats: yes"
fi
if test "x$enable_lmsensors" != xyes; then
echo " HUD lmsensors: no"
else
echo " HUD lmsensors: yes"
fi
dnl Shader cache
echo ""
echo " Shader cache: $enable_shader_cache"
......
......@@ -34,6 +34,8 @@ libgallium_la_SOURCES += \
endif
libgallium_la_LDFLAGS = $(LIBSENSORS_LDFLAGS)
MKDIR_GEN = $(AM_V_at)$(MKDIR_P) $(@D)
PYTHON_GEN = $(AM_V_GEN)$(PYTHON2) $(PYTHON_FLAGS)
......
......@@ -62,6 +62,9 @@ C_SOURCES := \
hud/hud_context.c \
hud/hud_context.h \
hud/hud_cpu.c \
hud/hud_nic.c \
hud/hud_diskstat.c \
hud/hud_sensors_temp.c \
hud/hud_driver_query.c \
hud/hud_fps.c \
hud/hud_private.h \
......
......@@ -257,6 +257,10 @@ number_to_human_readable(uint64_t num, uint64_t max_value,
static const char *hz_units[] =
{" Hz", " KHz", " MHz", " GHz"};
static const char *percent_units[] = {"%"};
static const char *dbm_units[] = {" (-dBm)"};
static const char *temperature_units[] = {" C"};
static const char *volt_units[] = {" mV", " V"};
static const char *amp_units[] = {" mA", " A"};
const char **units;
unsigned max_unit;
......@@ -269,6 +273,22 @@ number_to_human_readable(uint64_t num, uint64_t max_value,
max_unit = ARRAY_SIZE(time_units)-1;
units = time_units;
break;
case PIPE_DRIVER_QUERY_TYPE_VOLTS:
max_unit = ARRAY_SIZE(volt_units)-1;
units = volt_units;
break;
case PIPE_DRIVER_QUERY_TYPE_AMPS:
max_unit = ARRAY_SIZE(amp_units)-1;
units = amp_units;
break;
case PIPE_DRIVER_QUERY_TYPE_DBM:
max_unit = ARRAY_SIZE(dbm_units)-1;
units = dbm_units;
break;
case PIPE_DRIVER_QUERY_TYPE_TEMPERATURE:
max_unit = ARRAY_SIZE(temperature_units)-1;
units = temperature_units;
break;
case PIPE_DRIVER_QUERY_TYPE_PERCENTAGE:
max_unit = ARRAY_SIZE(percent_units)-1;
units = percent_units;
......@@ -993,6 +1013,9 @@ hud_parse_env_var(struct hud_context *hud, const char *env)
}
/* Add a graph. */
#if HAVE_GALLIUM_EXTRA_HUD || HAVE_LIBSENSORS
char arg_name[64];
#endif
/* IF YOU CHANGE THIS, UPDATE print_help! */
if (strcmp(name, "fps") == 0) {
hud_fps_graph_install(pane);
......@@ -1003,6 +1026,48 @@ hud_parse_env_var(struct hud_context *hud, const char *env)
else if (sscanf(name, "cpu%u%s", &i, s) == 1) {
hud_cpu_graph_install(pane, i);
}
#if HAVE_GALLIUM_EXTRA_HUD
else if (sscanf(name, "nic-rx-%s", arg_name) == 1) {
hud_nic_graph_install(pane, arg_name, NIC_DIRECTION_RX);
}
else if (sscanf(name, "nic-tx-%s", arg_name) == 1) {
hud_nic_graph_install(pane, arg_name, NIC_DIRECTION_TX);
}
else if (sscanf(name, "nic-rssi-%s", arg_name) == 1) {
hud_nic_graph_install(pane, arg_name, NIC_RSSI_DBM);
pane->type = PIPE_DRIVER_QUERY_TYPE_DBM;
}
else if (sscanf(name, "diskstat-rd-%s", arg_name) == 1) {
hud_diskstat_graph_install(pane, arg_name, DISKSTAT_RD);
pane->type = PIPE_DRIVER_QUERY_TYPE_BYTES;
}
else if (sscanf(name, "diskstat-wr-%s", arg_name) == 1) {
hud_diskstat_graph_install(pane, arg_name, DISKSTAT_WR);
pane->type = PIPE_DRIVER_QUERY_TYPE_BYTES;
}
#endif
#if HAVE_LIBSENSORS
else if (sscanf(name, "sensors_temp_cu-%s", arg_name) == 1) {
hud_sensors_temp_graph_install(pane, arg_name,
SENSORS_TEMP_CURRENT);
pane->type = PIPE_DRIVER_QUERY_TYPE_TEMPERATURE;
}
else if (sscanf(name, "sensors_temp_cr-%s", arg_name) == 1) {
hud_sensors_temp_graph_install(pane, arg_name,
SENSORS_TEMP_CRITICAL);
pane->type = PIPE_DRIVER_QUERY_TYPE_TEMPERATURE;
}
else if (sscanf(name, "sensors_volt_cu-%s", arg_name) == 1) {
hud_sensors_temp_graph_install(pane, arg_name,
SENSORS_VOLTAGE_CURRENT);
pane->type = PIPE_DRIVER_QUERY_TYPE_VOLTS;
}
else if (sscanf(name, "sensors_curr_cu-%s", arg_name) == 1) {
hud_sensors_temp_graph_install(pane, arg_name,
SENSORS_CURRENT_CURRENT);
pane->type = PIPE_DRIVER_QUERY_TYPE_AMPS;
}
#endif
else if (strcmp(name, "samples-passed") == 0 &&
has_occlusion_query(hud->pipe->screen)) {
hud_pipe_query_install(&hud->batch_query, pane, hud->pipe,
......@@ -1212,6 +1277,14 @@ print_help(struct pipe_screen *screen)
puts(" cs-invocations");
}
#if HAVE_GALLIUM_EXTRA_HUD
hud_get_num_disks(1);
hud_get_num_nics(1);
#endif
#if HAVE_LIBSENSORS
hud_get_num_sensors(1);
#endif
if (screen->get_driver_query_info){
boolean skipping = false;
struct pipe_driver_query_info info;
......
/**************************************************************************
*
* Copyright (C) 2016 Steven Toth <stoth@kernellabs.com>
* Copyright (C) 2016 Zodiac Inflight Innovations
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#if HAVE_GALLIUM_EXTRA_HUD
/* Purpose: Reading /sys/block/<*>/stat MB/s read/write throughput per second,
* displaying on the HUD.
*/
#include "hud/hud_private.h"
#include "util/list.h"
#include "os/os_time.h"
#include "util/u_memory.h"
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <stdlib.h>
#include <unistd.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#define LOCAL_DEBUG 0
struct stat_s
{
/* Read */
uint64_t r_ios;
uint64_t r_merges;
uint64_t r_sectors;
uint64_t r_ticks;
/* Write */
uint64_t w_ios;
uint64_t w_merges;
uint64_t w_sectors;
uint64_t w_ticks;
/* Misc */
uint64_t in_flight;
uint64_t io_ticks;
uint64_t time_in_queue;
};
struct diskstat_info
{
struct list_head list;
int mode; /* DISKSTAT_RD, DISKSTAT_WR */
char name[64]; /* EG. sda5 */
char sysfs_filename[128];
uint64_t last_time;
struct stat_s last_stat;
};
/* TODO: We don't handle dynamic block device / partition
* arrival or removal.
* Static globals specific to this HUD category.
*/
static int gdiskstat_count = 0;
static struct list_head gdiskstat_list;
static struct diskstat_info *
find_dsi_by_name(const char *n, int mode)
{
list_for_each_entry(struct diskstat_info, dsi, &gdiskstat_list, list) {
if (dsi->mode != mode)
continue;
if (strcasecmp(dsi->name, n) == 0)
return dsi;
}
return 0;
}
static int
get_file_values(const char *fn, struct stat_s *s)
{
int ret = 0;
FILE *fh = fopen(fn, "r");
if (!fh)
return -1;
ret = fscanf(fh,
"%" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64
" %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 "",
&s->r_ios, &s->r_merges, &s->r_sectors, &s->r_ticks, &s->w_ios,
&s->w_merges, &s->w_sectors, &s->w_ticks, &s->in_flight, &s->io_ticks,
&s->time_in_queue);
fclose(fh);
return ret;
}
static void
query_dsi_load(struct hud_graph *gr)
{
/* The framework calls us periodically, compensate for the
* calling interval accordingly when reporting per second.
*/
struct diskstat_info *dsi = gr->query_data;
uint64_t now = os_time_get();
if (dsi->last_time) {
if (dsi->last_time + gr->pane->period <= now) {
struct stat_s stat;
if (get_file_values(dsi->sysfs_filename, &stat) < 0)
return;
float val = 0;
switch (dsi->mode) {
case DISKSTAT_RD:
val =
((stat.r_sectors -
dsi->last_stat.r_sectors) * 512) /
(((float) gr->pane->period / 1000) / 1000);
break;
case DISKSTAT_WR:
val =
((stat.w_sectors -
dsi->last_stat.w_sectors) * 512) /
(((float) gr->pane->period / 1000) / 1000);
break;
}
hud_graph_add_value(gr, (uint64_t) val);
dsi->last_stat = stat;
dsi->last_time = now;
}
}
else {
/* initialize */
switch (dsi->mode) {
case DISKSTAT_RD:
case DISKSTAT_WR:
get_file_values(dsi->sysfs_filename, &dsi->last_stat);
break;
}
dsi->last_time = now;
}
}
static void
free_query_data(void *p)
{
struct diskstat_info *nic = (struct diskstat_info *) p;
list_del(&nic->list);
FREE(nic);
}
/**
* Create and initialize a new object for a specific block I/O device.
* \param pane parent context.
* \param dev_name logical block device name, EG. sda5.
* \param mode query read or write (DISKSTAT_RD/DISKSTAT_WR) statistics.
*/
void
hud_diskstat_graph_install(struct hud_pane *pane, const char *dev_name,
unsigned int mode)
{
struct hud_graph *gr;
struct diskstat_info *dsi;
int num_devs = hud_get_num_disks(0);
if (num_devs <= 0)
return;
#if LOCAL_DEBUG
printf("%s(%s, %s) - Creating HUD object\n", __func__, dev_name,
mode == DISKSTAT_RD ? "RD" :
mode == DISKSTAT_WR ? "WR" : "UNDEFINED");
#endif
dsi = find_dsi_by_name(dev_name, mode);
if (!dsi)
return;
gr = CALLOC_STRUCT(hud_graph);
if (!gr)
return;
dsi->mode = mode;
if (dsi->mode == DISKSTAT_RD) {
snprintf(gr->name, sizeof(gr->name), "%s-Read-MB/s", dsi->name);
}
else if (dsi->mode == DISKSTAT_WR) {
snprintf(gr->name, sizeof(gr->name), "%s-Write-MB/s", dsi->name);
}
else
return;
gr->query_data = dsi;
gr->query_new_value = query_dsi_load;
/* Don't use free() as our callback as that messes up Gallium's
* memory debugger. Use simple free_query_data() wrapper.
*/
gr->free_query_data = free_query_data;
hud_pane_add_graph(pane, gr);
hud_pane_set_max_value(pane, 100);
}
static void
add_object_part(const char *basename, const char *name, int objmode)
{
struct diskstat_info *dsi = CALLOC_STRUCT(diskstat_info);
strcpy(dsi->name, name);
snprintf(dsi->sysfs_filename, sizeof(dsi->sysfs_filename), "%s/%s/stat",
basename, name);
dsi->mode = objmode;
list_addtail(&dsi->list, &gdiskstat_list);
gdiskstat_count++;
}
static void
add_object(const char *basename, const char *name, int objmode)
{
struct diskstat_info *dsi = CALLOC_STRUCT(diskstat_info);
strcpy(dsi->name, name);
snprintf(dsi->sysfs_filename, sizeof(dsi->sysfs_filename), "%s/stat",
basename);
dsi->mode = objmode;
list_addtail(&dsi->list, &gdiskstat_list);
gdiskstat_count++;
}
/**
* Initialize internal object arrays and display block I/O HUD help.
* \param displayhelp true if the list of detected devices should be
displayed on the console.
* \return number of detected block I/O devices.
*/
int
hud_get_num_disks(bool displayhelp)
{
struct dirent *dp;
struct stat stat_buf;
char name[64];
/* Return the number of block devices and partitions. */
if (gdiskstat_count)
return gdiskstat_count;
/* Scan /sys/block, for every object type we support, create and
* persist an object to represent its different statistics.
*/
list_inithead(&gdiskstat_list);
DIR *dir = opendir("/sys/block/");
if (!dir)
return 0;
while ((dp = readdir(dir)) != NULL) {
/* Avoid 'lo' and '..' and '.' */
if (strlen(dp->d_name) <= 2)
continue;
char basename[256];
snprintf(basename, sizeof(basename), "/sys/block/%s", dp->d_name);
snprintf(name, sizeof(name), "%s/stat", basename);
if (stat(name, &stat_buf) < 0)
continue;
if (!S_ISREG(stat_buf.st_mode))
continue; /* Not a regular file */
/* Add a physical block device with R/W stats */
add_object(basename, dp->d_name, DISKSTAT_RD);
add_object(basename, dp->d_name, DISKSTAT_WR);
/* Add any partitions */
struct dirent *dpart;
DIR *pdir = opendir(basename);
if (!pdir)
return 0;
while ((dpart = readdir(pdir)) != NULL) {
/* Avoid 'lo' and '..' and '.' */
if (strlen(dpart->d_name) <= 2)
continue;
char p[64];
snprintf(p, sizeof(p), "%s/%s/stat", basename, dpart->d_name);
if (stat(p, &stat_buf) < 0)
continue;
if (!S_ISREG(stat_buf.st_mode))
continue; /* Not a regular file */
/* Add a partition with R/W stats */
add_object_part(basename, dpart->d_name, DISKSTAT_RD);
add_object_part(basename, dpart->d_name, DISKSTAT_WR);
}
}
if (displayhelp) {
list_for_each_entry(struct diskstat_info, dsi, &gdiskstat_list, list) {
char line[32];
snprintf(line, sizeof(line), " diskstat-%s-%s",
dsi->mode == DISKSTAT_RD ? "rd" :
dsi->mode == DISKSTAT_WR ? "wr" : "undefined", dsi->name);
puts(line);
}
}
return gdiskstat_count;
}
#endif /* HAVE_GALLIUM_EXTRA_HUD */
This diff is collapsed.
......@@ -103,4 +103,29 @@ boolean hud_driver_query_install(struct hud_batch_query_context **pbq,
void hud_batch_query_update(struct hud_batch_query_context *bq);
void hud_batch_query_cleanup(struct hud_batch_query_context **pbq);
#if HAVE_GALLIUM_EXTRA_HUD
int hud_get_num_nics(bool displayhelp);
#define NIC_DIRECTION_RX 1
#define NIC_DIRECTION_TX 2
#define NIC_RSSI_DBM 3
void hud_nic_graph_install(struct hud_pane *pane, const char *nic_index,
unsigned int mode);
int hud_get_num_disks(bool displayhelp);
#define DISKSTAT_RD 1
#define DISKSTAT_WR 2
void hud_diskstat_graph_install(struct hud_pane *pane, const char *dev_name,
unsigned int mode);
#endif
#if HAVE_LIBSENSORS
int hud_get_num_sensors(bool displayhelp);
#define SENSORS_TEMP_CURRENT 1
#define SENSORS_TEMP_CRITICAL 2
#define SENSORS_VOLTAGE_CURRENT 3
#define SENSORS_CURRENT_CURRENT 4
void hud_sensors_temp_graph_install(struct hud_pane *pane, const char *dev_name,
unsigned int mode);
#endif
#endif
This diff is collapsed.
......@@ -965,6 +965,10 @@ enum pipe_driver_query_type
PIPE_DRIVER_QUERY_TYPE_BYTES,
PIPE_DRIVER_QUERY_TYPE_MICROSECONDS,
PIPE_DRIVER_QUERY_TYPE_HZ,
PIPE_DRIVER_QUERY_TYPE_DBM,
PIPE_DRIVER_QUERY_TYPE_TEMPERATURE,
PIPE_DRIVER_QUERY_TYPE_VOLTS,
PIPE_DRIVER_QUERY_TYPE_AMPS,
};
/* Whether an average value per frame or a cumulative value should be
......
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