[Mesa-dev] [PATCH 4/4] gallium/hud: add monitoring of API thread busy status

Nicolai Hähnle nhaehnle at gmail.com
Mon Feb 13 15:41:36 UTC 2017


On 11.02.2017 20:58, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>

Patches 1, 2, 4:

Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>

>
> ---
>  src/gallium/auxiliary/hud/hud_context.c |  3 ++
>  src/gallium/auxiliary/hud/hud_cpu.c     | 60 +++++++++++++++++++++++++++++++++
>  src/gallium/auxiliary/hud/hud_private.h |  1 +
>  3 files changed, 64 insertions(+)
>
> diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
> index a635797..5354db7 100644
> --- a/src/gallium/auxiliary/hud/hud_context.c
> +++ b/src/gallium/auxiliary/hud/hud_context.c
> @@ -1110,20 +1110,23 @@ hud_parse_env_var(struct hud_context *hud, const char *env)
>        /* IF YOU CHANGE THIS, UPDATE print_help! */
>        if (strcmp(name, "fps") == 0) {
>           hud_fps_graph_install(pane);
>        }
>        else if (strcmp(name, "cpu") == 0) {
>           hud_cpu_graph_install(pane, ALL_CPUS);
>        }
>        else if (sscanf(name, "cpu%u%s", &i, s) == 1) {
>           hud_cpu_graph_install(pane, i);
>        }
> +      else if (strcmp(name, "API-thread-busy") == 0) {
> +         hud_api_thread_busy_install(pane);
> +      }
>  #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;
> diff --git a/src/gallium/auxiliary/hud/hud_cpu.c b/src/gallium/auxiliary/hud/hud_cpu.c
> index c65444e..a8d97b8 100644
> --- a/src/gallium/auxiliary/hud/hud_cpu.c
> +++ b/src/gallium/auxiliary/hud/hud_cpu.c
> @@ -23,20 +23,21 @@
>   * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
>   * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
>   *
>   **************************************************************************/
>
>  /* This file contains code for reading CPU load for displaying on the HUD.
>   */
>
>  #include "hud/hud_private.h"
>  #include "os/os_time.h"
> +#include "os/os_thread.h"
>  #include "util/u_memory.h"
>  #include <stdio.h>
>  #include <inttypes.h>
>  #ifdef PIPE_OS_WINDOWS
>  #include <windows.h>
>  #endif
>
>
>  #ifdef PIPE_OS_WINDOWS
>
> @@ -223,10 +224,69 @@ int
>  hud_get_num_cpus(void)
>  {
>     uint64_t busy, total;
>     int i = 0;
>
>     while (get_cpu_stats(i, &busy, &total))
>        i++;
>
>     return i;
>  }
> +
> +struct thread_info {
> +   int64_t last_time;
> +   int64_t last_thread_time;
> +};
> +
> +static void
> +query_api_thread_busy_status(struct hud_graph *gr)
> +{
> +   struct thread_info *info = gr->query_data;
> +   int64_t now = os_time_get_nano();
> +
> +   if (info->last_time) {
> +      if (info->last_time + gr->pane->period*1000 <= now) {
> +         int64_t thread_now = pipe_current_thread_get_time_nano();
> +
> +         hud_graph_add_value(gr,
> +                             (thread_now - info->last_thread_time) * 100 /
> +                             (now - info->last_time));
> +
> +         info->last_thread_time = thread_now;
> +         info->last_time = now;
> +      }
> +   } else {
> +      /* initialize */
> +      info->last_time = now;
> +      info->last_thread_time = pipe_current_thread_get_time_nano();
> +   }
> +}
> +
> +void
> +hud_api_thread_busy_install(struct hud_pane *pane)
> +{
> +   struct hud_graph *gr;
> +
> +   gr = CALLOC_STRUCT(hud_graph);
> +   if (!gr)
> +      return;
> +
> +   strcpy(gr->name, "API-thread-busy");
> +
> +   gr->query_data = CALLOC_STRUCT(thread_info);
> +   if (!gr->query_data) {
> +      FREE(gr);
> +      return;
> +   }
> +
> +   gr->query_new_value = query_api_thread_busy_status;
> +
> +   /* 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_graph_set_dump_file(gr);
> +
> +   hud_pane_add_graph(pane, gr);
> +   hud_pane_set_max_value(pane, 100);
> +}
> diff --git a/src/gallium/auxiliary/hud/hud_private.h b/src/gallium/auxiliary/hud/hud_private.h
> index b23439e..1d06e03 100644
> --- a/src/gallium/auxiliary/hud/hud_private.h
> +++ b/src/gallium/auxiliary/hud/hud_private.h
> @@ -86,20 +86,21 @@ void hud_graph_add_value(struct hud_graph *gr, uint64_t value);
>
>  /* graphs/queries */
>  struct hud_batch_query_context;
>
>  #define ALL_CPUS ~0 /* optionally set as cpu_index */
>
>  int hud_get_num_cpus(void);
>
>  void hud_fps_graph_install(struct hud_pane *pane);
>  void hud_cpu_graph_install(struct hud_pane *pane, unsigned cpu_index);
> +void hud_api_thread_busy_install(struct hud_pane *pane);
>  void hud_pipe_query_install(struct hud_batch_query_context **pbq,
>                              struct hud_pane *pane, struct pipe_context *pipe,
>                              const char *name, unsigned query_type,
>                              unsigned result_index,
>                              uint64_t max_value,
>                              enum pipe_driver_query_type type,
>                              enum pipe_driver_query_result_type result_type,
>                              unsigned flags);
>  boolean hud_driver_query_install(struct hud_batch_query_context **pbq,
>                                   struct hud_pane *pane,
>



More information about the mesa-dev mailing list