Mesa (master): svga: don't call os_get_time() when not needed by Gallium HUD

Brian Paul brianp at kemper.freedesktop.org
Tue Aug 16 14:29:09 UTC 2016


Module: Mesa
Branch: master
Commit: f934117bbb9d58f0f5d9cfb4397fec9c6371ed64
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f934117bbb9d58f0f5d9cfb4397fec9c6371ed64

Author: Brian Paul <brianp at vmware.com>
Date:   Tue Aug  2 14:27:33 2016 -0600

svga: don't call os_get_time() when not needed by Gallium HUD

The calls to os_get_time() were showing up higher than expected in
profiles.

Reviewed-by: Charmaine Lee <charmainel at vmware.com>

---

 src/gallium/drivers/svga/svga_context.c          |  5 ++---
 src/gallium/drivers/svga/svga_context.h          | 15 +++++++++++++++
 src/gallium/drivers/svga/svga_pipe_query.c       |  7 +++++--
 src/gallium/drivers/svga/svga_resource_buffer.c  |  5 ++---
 src/gallium/drivers/svga/svga_resource_texture.c |  5 ++---
 5 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/src/gallium/drivers/svga/svga_context.c b/src/gallium/drivers/svga/svga_context.c
index f623caf..52956fa 100644
--- a/src/gallium/drivers/svga/svga_context.c
+++ b/src/gallium/drivers/svga/svga_context.c
@@ -31,7 +31,6 @@
 #include "util/u_memory.h"
 #include "util/u_bitmask.h"
 #include "util/u_upload_mgr.h"
-#include "os/os_time.h"
 
 #include "svga_context.h"
 #include "svga_screen.h"
@@ -320,9 +319,9 @@ void svga_context_flush( struct svga_context *svga,
 
    /* Flush pending commands to hardware:
     */
-   t0 = os_time_get();
+   t0 = svga_get_time(svga);
    svga->swc->flush(svga->swc, &fence);
-   svga->hud.flush_time += (os_time_get() - t0);
+   svga->hud.flush_time += (svga_get_time(svga) - t0);
 
    svga->hud.num_flushes++;
 
diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h
index 4eb8a19..1e62e71 100644
--- a/src/gallium/drivers/svga/svga_context.h
+++ b/src/gallium/drivers/svga/svga_context.h
@@ -31,6 +31,8 @@
 #include "pipe/p_defines.h"
 #include "pipe/p_state.h"
 
+#include "os/os_time.h"
+
 #include "util/u_blitter.h"
 #include "util/list.h"
 
@@ -544,6 +546,8 @@ struct svga_context
       uint64_t num_surface_views;       /**< SVGA_QUERY_NUM_SURFACE_VIEWS */
       uint64_t num_bytes_uploaded;      /**< SVGA_QUERY_NUM_BYTES_UPLOADED */
       uint64_t num_generate_mipmap;     /**< SVGA_QUERY_NUM_GENERATE_MIPMAP */
+
+      boolean uses_time;                /**< os_time_get() calls needed? */
    } hud;
 
    /** The currently bound stream output targets */
@@ -703,4 +707,15 @@ svga_rects_equal(const SVGA3dRect *r1, const SVGA3dRect *r2)
    return memcmp(r1, r2, sizeof(*r1)) == 0;
 }
 
+/**
+ * If the Gallium HUD is enabled, this will return the current time.
+ * Otherwise, just return zero.
+ */
+static inline int64_t
+svga_get_time(struct svga_context *svga)
+{
+   return svga->hud.uses_time ? os_time_get() : 0;
+}
+
+
 #endif
diff --git a/src/gallium/drivers/svga/svga_pipe_query.c b/src/gallium/drivers/svga/svga_pipe_query.c
index 65e58fe..bf074b6 100644
--- a/src/gallium/drivers/svga/svga_pipe_query.c
+++ b/src/gallium/drivers/svga/svga_pipe_query.c
@@ -731,11 +731,9 @@ svga_create_query(struct pipe_context *pipe,
    case SVGA_QUERY_NUM_FALLBACKS:
    case SVGA_QUERY_NUM_FLUSHES:
    case SVGA_QUERY_NUM_VALIDATIONS:
-   case SVGA_QUERY_MAP_BUFFER_TIME:
    case SVGA_QUERY_NUM_RESOURCES_MAPPED:
    case SVGA_QUERY_NUM_BYTES_UPLOADED:
    case SVGA_QUERY_COMMAND_BUFFER_SIZE:
-   case SVGA_QUERY_FLUSH_TIME:
    case SVGA_QUERY_SURFACE_WRITE_FLUSHES:
    case SVGA_QUERY_MEMORY_USED:
    case SVGA_QUERY_NUM_SHADERS:
@@ -749,6 +747,11 @@ svga_create_query(struct pipe_context *pipe,
    case SVGA_QUERY_NUM_CONST_BUF_UPDATES:
    case SVGA_QUERY_NUM_CONST_UPDATES:
       break;
+   case SVGA_QUERY_FLUSH_TIME:
+   case SVGA_QUERY_MAP_BUFFER_TIME:
+      /* These queries need os_time_get() */
+      svga->hud.uses_time = TRUE;
+      break;
    default:
       assert(!"unexpected query type in svga_create_query()");
    }
diff --git a/src/gallium/drivers/svga/svga_resource_buffer.c b/src/gallium/drivers/svga/svga_resource_buffer.c
index 68ce103..c126ff9 100644
--- a/src/gallium/drivers/svga/svga_resource_buffer.c
+++ b/src/gallium/drivers/svga/svga_resource_buffer.c
@@ -29,7 +29,6 @@
 #include "pipe/p_defines.h"
 #include "util/u_inlines.h"
 #include "os/os_thread.h"
-#include "os/os_time.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "util/u_resource.h"
@@ -78,7 +77,7 @@ svga_buffer_transfer_map(struct pipe_context *pipe,
    struct svga_buffer *sbuf = svga_buffer(resource);
    struct pipe_transfer *transfer;
    uint8_t *map;
-   int64_t begin = os_time_get();
+   int64_t begin = svga_get_time(svga);
 
    assert(box->y == 0);
    assert(box->z == 0);
@@ -264,7 +263,7 @@ svga_buffer_transfer_map(struct pipe_context *pipe,
       FREE(transfer);
    }
 
-   svga->hud.map_buffer_time += (os_time_get() - begin);
+   svga->hud.map_buffer_time += (svga_get_time(svga) - begin);
 
    return map;
 }
diff --git a/src/gallium/drivers/svga/svga_resource_texture.c b/src/gallium/drivers/svga/svga_resource_texture.c
index 230221a..30dc4d9 100644
--- a/src/gallium/drivers/svga/svga_resource_texture.c
+++ b/src/gallium/drivers/svga/svga_resource_texture.c
@@ -29,7 +29,6 @@
 #include "pipe/p_state.h"
 #include "pipe/p_defines.h"
 #include "os/os_thread.h"
-#include "os/os_time.h"
 #include "util/u_format.h"
 #include "util/u_inlines.h"
 #include "util/u_math.h"
@@ -336,7 +335,7 @@ svga_texture_transfer_map(struct pipe_context *pipe,
       !svga_have_gb_dma(svga);
    unsigned d;
    void *returnVal;
-   int64_t begin = os_time_get();
+   int64_t begin = svga_get_time(svga);
 
    /* We can't map texture storage directly unless we have GB objects */
    if (usage & PIPE_TRANSFER_MAP_DIRECTLY) {
@@ -579,7 +578,7 @@ svga_texture_transfer_map(struct pipe_context *pipe,
       returnVal = (void *) (map + offset);
    }
 
-   svga->hud.map_buffer_time += (os_time_get() - begin);
+   svga->hud.map_buffer_time += (svga_get_time(svga) - begin);
    svga->hud.num_resources_mapped++;
 
    return returnVal;




More information about the mesa-commit mailing list