[Mesa-dev] [PATCH 1/2] RFC : Context aware user space Resource control

aravindan.muthukumar at intel.com aravindan.muthukumar at intel.com
Fri Jul 20 08:32:56 UTC 2018


From: "Muthukumar, Aravindan" <aravindan.muthukumar at intel.com>

 The Patch here is to give control to user/ application to really
 decide what's the max GPU load it would put. If that can be
 known in advance, rpcs can be programmed accordingly.

 Here, we pass gpu_load_type = {high, medium, low} from application
 while context is created. Default here is 'High' and applications
 roughly know if they are going to eat up entire GPU. The typical
 usecase of 'Low' is idle screen or minor mouse movements. Users can
 read meaning of high/medium/low for their platform & then program
 contexts accordingly. Here, gpu_load_type directly translates
 to number of shader cores/EUs a particular GPU has.

 Signed-off-by: Aravindan Muthukumar <aravindan.muthukumar at intel.com>
 Signed-off-by: Kedar J Karanje <kedar.j.karanje at intel.com>
 Signed-off-by: Praveen Diwakar <praveen.diwakar at intel.com>
 Signed-off-by: Yogesh Marathe  <yogesh.marathe at intel.com>
---
 include/EGL/eglext.h                   |  8 ++++++++
 include/GL/glxext.h                    |  9 +++++++++
 include/GL/internal/dri_interface.h    | 12 ++++++++++++
 src/egl/drivers/dri2/egl_dri2.c        | 16 ++++++++++++++++
 src/egl/generate/egl.xml               |  8 ++++++++
 src/egl/main/eglcontext.c              |  5 +++++
 src/egl/main/eglcontext.h              |  2 ++
 src/glx/dri2_glx.c                     |  7 ++++++-
 src/glx/dri3_glx.c                     | 10 ++++++++--
 src/glx/dri_common.c                   | 19 ++++++++++++++++++-
 src/glx/dri_common.h                   |  2 +-
 src/glx/drisw_glx.c                    |  9 ++++++++-
 src/mesa/drivers/dri/common/dri_util.c |  6 +++++-
 src/mesa/drivers/dri/common/dri_util.h |  5 ++++-
 14 files changed, 110 insertions(+), 8 deletions(-)

diff --git a/include/EGL/eglext.h b/include/EGL/eglext.h
index 2f990cc..a29eccc 100644
--- a/include/EGL/eglext.h
+++ b/include/EGL/eglext.h
@@ -918,6 +918,14 @@ EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurfaceHI (EGLDisplay dpy, EGLConfi
 #define EGL_CONTEXT_PRIORITY_LOW_IMG      0x3103
 #endif /* EGL_IMG_context_priority */
 
+#ifndef EGL_CONTEXT_load_type
+#define EGL_CONTEXT_load_type 1
+#define EGL_CONTEXT_LOAD_TYPE             0x31A0
+#define EGL_CONTEXT_LOAD_LOW              0x31A1
+#define EGL_CONTEXT_LOAD_MEDIUM           0x31A2
+#define EGL_CONTEXT_LOAD_HIGH             0x31A3
+#endif /* EGL_CONTEXT_load_type */
+
 #ifndef EGL_IMG_image_plane_attribs
 #define EGL_IMG_image_plane_attribs 1
 #define EGL_NATIVE_BUFFER_MULTIPLANE_SEPARATE_IMG 0x3105
diff --git a/include/GL/glxext.h b/include/GL/glxext.h
index 0f60a38..9d4c3d0 100644
--- a/include/GL/glxext.h
+++ b/include/GL/glxext.h
@@ -163,6 +163,15 @@ __GLXextFuncPtr glXGetProcAddress (const GLubyte *procName);
 #define GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098
 #endif /* GLX_ARB_context_flush_control */
 
+#ifndef GLX_CONTEXT_load_type
+#define GLX_CONTEXT_load_type 1
+#define GLX_CONTEXT_LOAD_TYPE 0x31A0
+#define GLX_CONTEXT_LOAD_LOW 0x31A1
+#define GLX_CONTEXT_LOAD_MEDIUM 0x31A2
+#define GLX_CONTEXT_LOAD_HIGH 0x31A3
+#endif
+
+
 #ifndef GLX_ARB_create_context
 #define GLX_ARB_create_context 1
 #define GLX_CONTEXT_DEBUG_BIT_ARB         0x00000001
diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index 4f4795c..0a8492a 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1140,6 +1140,18 @@ struct __DRIdri2LoaderExtensionRec {
 #define __DRI_CTX_RELEASE_BEHAVIOR_FLUSH        1
 /*@}*/
 
+
+/**
+ * \name Context Load Types.
+ */
+/*@{*/
+#define __DRI_CTX_ATTRIB_LOAD_TYPE              6
+
+#define __DRI_CTX_ATTRIB_LOAD_LOW               0
+#define __DRI_CTX_ATTRIB_LOAD_MEDIUM            1
+#define __DRI_CTX_ATTRIB_LOAD_HIGH              2
+/*@}*/
+
 /**
  * \name Reasons that __DRIdri2Extension::createContextAttribs might fail
  */
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 45d0c72..c0dc97a 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1212,6 +1212,22 @@ dri2_fill_context_attribs(struct dri2_egl_context *dri2_ctx,
       ctx_attribs[pos++] = __DRI_CTX_RELEASE_BEHAVIOR_NONE;
    }
 
+   if(dri2_ctx->base.LoadType != EGL_CONTEXT_LOAD_HIGH) {
+      ctx_attribs[pos++] = __DRI_CTX_ATTRIB_LOAD_TYPE;
+
+      switch(dri2_ctx->base.LoadType) {
+      case EGL_CONTEXT_LOAD_MEDIUM:
+         ctx_attribs[pos++] = __DRI_CTX_ATTRIB_LOAD_MEDIUM;
+         break;
+      case EGL_CONTEXT_LOAD_LOW:
+         ctx_attribs[pos++] = __DRI_CTX_ATTRIB_LOAD_LOW;
+         break;
+      default:
+	 _eglError(EGL_BAD_CONFIG, "eglCreateContext");
+         return false;
+      }
+   }
+
    *num_attribs = pos;
 
    return true;
diff --git a/src/egl/generate/egl.xml b/src/egl/generate/egl.xml
index 9250f93..52b0c9f 100644
--- a/src/egl/generate/egl.xml
+++ b/src/egl/generate/egl.xml
@@ -460,6 +460,14 @@
             <unused start="0x3107" end="0x310F"/>
     </enums>
 
+    <enums namespace="EGL" start="0x31A0" end="0x31A3" vendor="IMG" comment="Reserved for context aware load type">
+        <enum value="0x31A0" name="EGL_CONTEXT_LOAD_TYPE"/>
+        <enum value="0x31A1" name="EGL_CONTEXT_LOAD_LOW"/>
+        <enum value="0x31A2" name="EGL_CONTEXT_LOAD_MEDIUM"/>
+        <enum value="0x31A3" name="EGL_CONTEXT_LOAD_HIGH"/>
+            <unused start="0x31A0" end="0x31A3"/>
+    </enums>
+
     <enums namespace="EGL" start="0x3110" end="0x311F" vendor="ATX" comment="Reserved for Tim Renouf, Antix (Khronos bug 4949)">
         <enum value="0x3110" name="EGL_BITMAP_PIXEL_SIZE_KHR"/>
             <unused start="0x3111" end="0x311F"/>
diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c
index 3e5d8ad..215fcd5 100644
--- a/src/egl/main/eglcontext.c
+++ b/src/egl/main/eglcontext.c
@@ -395,6 +395,10 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *dpy,
          }
          break;
 
+      case EGL_CONTEXT_LOAD_TYPE:
+	 ctx->LoadType = val;
+         break;
+
       default:
          err = EGL_BAD_ATTRIBUTE;
          break;
@@ -597,6 +601,7 @@ _eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy, _EGLConfig *conf,
    ctx->ResetNotificationStrategy = EGL_NO_RESET_NOTIFICATION_KHR;
    ctx->ContextPriority = EGL_CONTEXT_PRIORITY_MEDIUM_IMG;
    ctx->ReleaseBehavior = EGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR;
+   ctx->LoadType        = EGL_CONTEXT_LOAD_HIGH;
 
    err = _eglParseContextAttribList(ctx, dpy, attrib_list);
    if (err == EGL_SUCCESS && ctx->Config) {
diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h
index 8d97ef9..0d8c77f 100644
--- a/src/egl/main/eglcontext.h
+++ b/src/egl/main/eglcontext.h
@@ -68,6 +68,8 @@ struct _egl_context
 
    /* The real render buffer when a window surface is bound */
    EGLint WindowRenderBuffer;
+
+   EGLint LoadType;
 };
 
 
diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index 91afc33..aa9268b 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -248,6 +248,7 @@ dri2_create_context_attribs(struct glx_screen *base,
    unsigned api;
    int reset;
    int release;
+   uint32_t load_type = __DRI_CTX_ATTRIB_LOAD_HIGH;
    uint32_t ctx_attribs[2 * 6];
    unsigned num_ctx_attribs = 0;
 
@@ -260,7 +261,7 @@ dri2_create_context_attribs(struct glx_screen *base,
     */
    if (!dri2_convert_glx_attribs(num_attribs, attribs,
                                  &major_ver, &minor_ver, &renderType, &flags,
-                                 &api, &reset, &release, error))
+                                 &api, &reset, &release, &load_type, error))
       goto error_exit;
 
    /* Check the renderType value */
@@ -308,6 +309,10 @@ dri2_create_context_attribs(struct glx_screen *base,
        */
       ctx_attribs[num_ctx_attribs++] = flags;
    }
+   if(load_type != __DRI_CTX_ATTRIB_LOAD_HIGH){
+      ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_LOAD_TYPE;
+      ctx_attribs[num_ctx_attribs++] = load_type;
+   }
 
    /* The renderType is retrieved from attribs, or set to default
     *  of GLX_RGBA_TYPE.
diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c
index ce60b95..d112404 100644
--- a/src/glx/dri3_glx.c
+++ b/src/glx/dri3_glx.c
@@ -245,18 +245,18 @@ dri3_create_context_attribs(struct glx_screen *base,
    uint32_t major_ver = 2;
    uint32_t flags = 0;
    unsigned api;
+   uint32_t load_type = __DRI_CTX_ATTRIB_LOAD_HIGH;
    int reset = __DRI_CTX_RESET_NO_NOTIFICATION;
    int release = __DRI_CTX_RELEASE_BEHAVIOR_FLUSH;
    uint32_t ctx_attribs[2 * 6];
    unsigned num_ctx_attribs = 0;
    uint32_t render_type;
-
    /* Remap the GLX tokens to DRI2 tokens.
     */
    if (!dri2_convert_glx_attribs(num_attribs, attribs,
                                  &major_ver, &minor_ver,
                                  &render_type, &flags, &api,
-                                 &reset, &release, error))
+                                 &reset, &release,  &load_type, error))
       goto error_exit;
 
    /* Check the renderType value */
@@ -305,6 +305,12 @@ dri3_create_context_attribs(struct glx_screen *base,
       ctx_attribs[num_ctx_attribs++] = flags;
    }
 
+   if(load_type != __DRI_CTX_ATTRIB_LOAD_HIGH) {
+      ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_LOAD_TYPE;
+
+      ctx_attribs[num_ctx_attribs++] = load_type;
+   }
+
    pcp->driContext =
       (*psc->image_driver->createContextAttribs) (psc->driScreen,
                                                   api,
diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c
index ab5d6c5..3e026f9 100644
--- a/src/glx/dri_common.c
+++ b/src/glx/dri_common.c
@@ -493,7 +493,7 @@ _X_HIDDEN bool
 dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
                          unsigned *major_ver, unsigned *minor_ver,
                          uint32_t *render_type, uint32_t *flags, unsigned *api,
-                         int *reset, int *release, unsigned *error)
+                         int *reset, int *release, uint32_t *load_type, unsigned *error)
 {
    unsigned i;
    bool got_profile = false;
@@ -562,6 +562,23 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
             return false;
          }
          break;
+      case GLX_CONTEXT_LOAD_TYPE:
+         uint32_t val = attribs[i * 2 + 1];
+         switch ( val ) {
+         case GLX_CONTEXT_LOAD_LOW:
+            *load_type = val;
+            break;
+	 case GLX_CONTEXT_LOAD_MEDIUM:
+	    *load_type = val;
+	    break;
+         case GLX_CONTEXT_LOAD_HIGH:
+            *load_type = val;
+	    break;
+         default:
+	    *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
+            return false;
+	 }
+	 break;
       default:
 	 /* If an unknown attribute is received, fail.
 	  */
diff --git a/src/glx/dri_common.h b/src/glx/dri_common.h
index 4d97ff8..179210e 100644
--- a/src/glx/dri_common.h
+++ b/src/glx/dri_common.h
@@ -78,6 +78,6 @@ extern bool
 dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
                          unsigned *major_ver, unsigned *minor_ver,
                          uint32_t *render_type, uint32_t *flags, unsigned *api,
-                         int *reset, int *release, unsigned *error);
+                         int *reset, int *release, uint32_t *load_type, unsigned *error);
 
 #endif /* _DRI_COMMON_H */
diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index df2467a..4f8f616 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -413,6 +413,7 @@ drisw_create_context_attribs(struct glx_screen *base,
    uint32_t major_ver;
    uint32_t renderType;
    uint32_t flags;
+   uint32_t load_type = __DRI_CTX_ATTRIB_LOAD_HIGH;
    unsigned api;
    int reset;
    int release;
@@ -429,7 +430,7 @@ drisw_create_context_attribs(struct glx_screen *base,
     */
    if (!dri2_convert_glx_attribs(num_attribs, attribs,
                                  &major_ver, &minor_ver, &renderType, &flags,
-                                 &api, &reset, &release, error))
+                                 &api, &reset, &release, &load_type, error))
       return NULL;
 
    /* Check the renderType value */
@@ -476,6 +477,12 @@ drisw_create_context_attribs(struct glx_screen *base,
       ctx_attribs[num_ctx_attribs++] = flags;
    }
 
+   if(load_type != __DRI_CTX_ATTRIB_LOAD_HIGH) {
+      ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_LOAD_TYPE;
+
+      ctx_attribs[num_ctx_attribs++] = load_type;
+   }
+
    pcp->base.renderType = renderType;
 
    pcp->driContext =
diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c
index 0b94d19..e2efd6c 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -307,6 +307,7 @@ driCreateContextAttribs(__DRIscreen *screen, int api,
     ctx_config.flags = 0;
     ctx_config.attribute_mask = 0;
     ctx_config.priority = __DRI_CTX_PRIORITY_MEDIUM;
+    ctx_config.load_type = __DRI_CTX_ATTRIB_LOAD_HIGH;
 
     assert((num_attribs == 0) || (attribs != NULL));
 
@@ -369,6 +370,10 @@ driCreateContextAttribs(__DRIscreen *screen, int api,
                     ~__DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR;
             }
             break;
+	case __DRI_CTX_ATTRIB_LOAD_TYPE:
+            ctx_config.attribute_mask |= __DRIVER_CONTEXT_ATTRIB_LOAD_TYPE;
+            ctx_config.load_type = attribs[i * 2 + 1];
+	    break;
 	default:
 	    /* We can't create a context that satisfies the requirements of an
 	     * attribute that we don't understand.  Return failure.
@@ -481,7 +486,6 @@ driCreateContextAttribs(__DRIscreen *screen, int api,
         free(context);
         return NULL;
     }
-
     *error = __DRI_CTX_ERROR_SUCCESS;
     return context;
 }
diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h
index 062c83f..5fd4678 100644
--- a/src/mesa/drivers/dri/common/dri_util.h
+++ b/src/mesa/drivers/dri/common/dri_util.h
@@ -101,12 +101,15 @@ struct __DriverContextConfig {
 
     /* Only valid if __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR is set */
     int release_behavior;
+
+    /* Only valid if __DRIVER_CONTEXT_LOAD_TYPE is set */
+    unsigned load_type;
 };
 
 #define __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY   (1 << 0)
 #define __DRIVER_CONTEXT_ATTRIB_PRIORITY         (1 << 1)
 #define __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR (1 << 2)
-
+#define __DRIVER_CONTEXT_ATTRIB_LOAD_TYPE        (1 << 3)
 /**
  * Driver callback functions.
  *
-- 
2.7.4



More information about the mesa-dev mailing list