[Mesa-dev] [PATCH] gallium/hud: Add power sensor support

Brian Paul brianp at vmware.com
Thu Sep 29 23:52:03 UTC 2016


Reviewed-by: Brian Paul <brianp at vmware.com>

and pushed to master.  Thanks.

-Brian

On 09/29/2016 08:11 AM, Steven Toth wrote:
> Implement support for power based sensors, reporting units in
> milli-watts and watts.
>
> Also, minor cleanup - change the related if block to a switch.
>
> Tested with two different power sensors, including the nouveau
> 'power1' sensors on a GTX950 card.
>
> Signed-off-by: Steven Toth <stoth at kernellabs.com>
> ---
>   src/gallium/auxiliary/hud/hud_context.c      | 10 ++++++++
>   src/gallium/auxiliary/hud/hud_private.h      |  1 +
>   src/gallium/auxiliary/hud/hud_sensors_temp.c | 38 ++++++++++++++++++++++++----
>   src/gallium/include/pipe/p_defines.h         |  1 +
>   4 files changed, 45 insertions(+), 5 deletions(-)
>
> diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
> index a82cdf2..3445488 100644
> --- a/src/gallium/auxiliary/hud/hud_context.c
> +++ b/src/gallium/auxiliary/hud/hud_context.c
> @@ -261,6 +261,7 @@ number_to_human_readable(uint64_t num, uint64_t max_value,
>      static const char *temperature_units[] = {" C"};
>      static const char *volt_units[] = {" mV", " V"};
>      static const char *amp_units[] = {" mA", " A"};
> +   static const char *watt_units[] = {" mW", " W"};
>
>      const char **units;
>      unsigned max_unit;
> @@ -301,6 +302,10 @@ number_to_human_readable(uint64_t num, uint64_t max_value,
>         max_unit = ARRAY_SIZE(hz_units)-1;
>         units = hz_units;
>         break;
> +   case PIPE_DRIVER_QUERY_TYPE_WATTS:
> +      max_unit = ARRAY_SIZE(watt_units)-1;
> +      units = watt_units;
> +      break;
>      default:
>         if (max_value == 100) {
>            max_unit = ARRAY_SIZE(percent_units)-1;
> @@ -1067,6 +1072,11 @@ hud_parse_env_var(struct hud_context *hud, const char *env)
>                                           SENSORS_CURRENT_CURRENT);
>            pane->type = PIPE_DRIVER_QUERY_TYPE_AMPS;
>         }
> +      else if (sscanf(name, "sensors_pow_cu-%s", arg_name) == 1) {
> +         hud_sensors_temp_graph_install(pane, arg_name,
> +                                        SENSORS_POWER_CURRENT);
> +         pane->type = PIPE_DRIVER_QUERY_TYPE_WATTS;
> +      }
>   #endif
>         else if (strcmp(name, "samples-passed") == 0 &&
>                  has_occlusion_query(hud->pipe->screen)) {
> diff --git a/src/gallium/auxiliary/hud/hud_private.h b/src/gallium/auxiliary/hud/hud_private.h
> index c825512..51049af 100644
> --- a/src/gallium/auxiliary/hud/hud_private.h
> +++ b/src/gallium/auxiliary/hud/hud_private.h
> @@ -124,6 +124,7 @@ int hud_get_num_sensors(bool displayhelp);
>   #define SENSORS_TEMP_CRITICAL    2
>   #define SENSORS_VOLTAGE_CURRENT  3
>   #define SENSORS_CURRENT_CURRENT  4
> +#define SENSORS_POWER_CURRENT    5
>   void hud_sensors_temp_graph_install(struct hud_pane *pane, const char *dev_name,
>                                       unsigned int mode);
>   #endif
> diff --git a/src/gallium/auxiliary/hud/hud_sensors_temp.c b/src/gallium/auxiliary/hud/hud_sensors_temp.c
> index bceffc4..7d1398a 100644
> --- a/src/gallium/auxiliary/hud/hud_sensors_temp.c
> +++ b/src/gallium/auxiliary/hud/hud_sensors_temp.c
> @@ -119,6 +119,15 @@ get_sensor_values(struct sensors_temp_info *sti)
>         if (sf)
>            sti->critical = get_value(sti->chip, sf);
>         break;
> +   case SENSORS_POWER_CURRENT:
> +      sf = sensors_get_subfeature(sti->chip, sti->feature,
> +                                  SENSORS_SUBFEATURE_POWER_INPUT);
> +      if (sf) {
> +         /* Sensors API returns in WATTs, even though driver is reporting mW,
> +          * convert back to mW */
> +         sti->current = get_value(sti->chip, sf) * 1000;
> +      }
> +      break;
>      }
>
>      sf = sensors_get_subfeature(sti->chip, sti->feature,
> @@ -173,6 +182,9 @@ query_sti_load(struct hud_graph *gr)
>            case SENSORS_CURRENT_CURRENT:
>               hud_graph_add_value(gr, (uint64_t) sti->current);
>               break;
> +         case SENSORS_POWER_CURRENT:
> +            hud_graph_add_value(gr, (uint64_t) sti->current);
> +            break;
>            }
>
>            sti->last_time = now;
> @@ -217,6 +229,7 @@ hud_sensors_temp_graph_install(struct hud_pane *pane, const char *dev_name,
>             mode == SENSORS_VOLTAGE_CURRENT ? "VOLTS" :
>             mode == SENSORS_CURRENT_CURRENT ? "AMPS" :
>             mode == SENSORS_TEMP_CURRENT ? "CU" :
> +          mode == SENSORS_POWER_CURRENT ? "POWER" :
>             mode == SENSORS_TEMP_CRITICAL ? "CR" : "UNDEFINED");
>   #endif
>
> @@ -234,6 +247,7 @@ hud_sensors_temp_graph_install(struct hud_pane *pane, const char *dev_name,
>              sti->mode == SENSORS_VOLTAGE_CURRENT ? "Volts" :
>              sti->mode == SENSORS_CURRENT_CURRENT ? "Amps" :
>              sti->mode == SENSORS_TEMP_CURRENT ? "Curr" :
> +           sti->mode == SENSORS_POWER_CURRENT ? "Pow" :
>              sti->mode == SENSORS_TEMP_CRITICAL ? "Crit" : "Unkn");
>
>      gr->query_data = sti;
> @@ -256,6 +270,9 @@ hud_sensors_temp_graph_install(struct hud_pane *pane, const char *dev_name,
>      case SENSORS_CURRENT_CURRENT:
>         hud_pane_set_max_value(pane, 5000);
>         break;
> +   case SENSORS_POWER_CURRENT:
> +      hud_pane_set_max_value(pane, 5000 /* mW */);
> +      break;
>      }
>   }
>
> @@ -303,19 +320,27 @@ build_sensor_list(void)
>            /* Create a 'current' and 'critical' object pair.
>             * Ignore sensor if its not temperature based.
>             */
> -         if (feature->type == SENSORS_FEATURE_TEMP) {
> +         switch(feature->type) {
> +         case SENSORS_FEATURE_TEMP:
>               create_object(name, featurename, chip, feature,
>                             SENSORS_TEMP_CURRENT);
>               create_object(name, featurename, chip, feature,
>                             SENSORS_TEMP_CRITICAL);
> -         }
> -         if (feature->type == SENSORS_FEATURE_IN) {
> +            break;
> +         case SENSORS_FEATURE_IN:
>               create_object(name, featurename, chip, feature,
>                             SENSORS_VOLTAGE_CURRENT);
> -         }
> -         if (feature->type == SENSORS_FEATURE_CURR) {
> +            break;
> +         case SENSORS_FEATURE_CURR:
>               create_object(name, featurename, chip, feature,
>                             SENSORS_CURRENT_CURRENT);
> +            break;
> +         case SENSORS_FEATURE_POWER:
> +            create_object(name, featurename, chip, feature,
> +                          SENSORS_POWER_CURRENT);
> +            break;
> +         default:
> +            break;
>            }
>            free(featurename);
>         }
> @@ -362,6 +387,9 @@ hud_get_num_sensors(bool displayhelp)
>            case SENSORS_CURRENT_CURRENT:
>               snprintf(line, sizeof(line), "    sensors_curr_cu-%s", sti->name);
>               break;
> +         case SENSORS_POWER_CURRENT:
> +            snprintf(line, sizeof(line), "    sensors_pow_cu-%s", sti->name);
> +            break;
>            }
>
>            puts(line);
> diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
> index 317a7c3..12d9b1a 100644
> --- a/src/gallium/include/pipe/p_defines.h
> +++ b/src/gallium/include/pipe/p_defines.h
> @@ -969,6 +969,7 @@ enum pipe_driver_query_type
>      PIPE_DRIVER_QUERY_TYPE_TEMPERATURE,
>      PIPE_DRIVER_QUERY_TYPE_VOLTS,
>      PIPE_DRIVER_QUERY_TYPE_AMPS,
> +   PIPE_DRIVER_QUERY_TYPE_WATTS,
>   };
>
>   /* Whether an average value per frame or a cumulative value should be
>



More information about the mesa-dev mailing list