glthread: compile marshal_generated.c faster by breaking it up into 8 files
authorMarek Olšák <marek.olsak@amd.com>
Thu, 5 Mar 2020 23:08:58 +0000 (18:08 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 24 Mar 2020 20:28:30 +0000 (16:28 -0400)
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4270>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4270>

src/mapi/glapi/gen/gl_marshal.py
src/mapi/glapi/gen/meson.build
src/mesa/Android.gen.mk
src/mesa/Makefile.sources
src/mesa/SConscript
src/mesa/meson.build

index d2704e43db20f7027d37df80871ed68f8c7f03f9..0572458fd974938e0a3766b74280dd717da55ee5 100644 (file)
@@ -46,6 +46,8 @@ static inline int safe_mul(int a, int b)
 """
 
 
+file_index = 0
+file_count = 1
 current_indent = 0
 
 
@@ -324,18 +326,27 @@ class PrintCode(gl_XML.gl_print_base):
         out('')
 
     def printBody(self, api):
-        async_funcs = []
+        # The first file only contains the dispatch tables
+        if file_index == 0:
+            self.print_unmarshal_dispatch_cmd(api)
+            self.print_create_marshal_table(api)
+            return
+
+        # The remaining files contain the marshal and unmarshal functions
+        func_per_file = (len(api.functionIterateAll()) // (file_count - 1)) + 1
+        i = -1
         for func in api.functionIterateAll():
+            i += 1
+            if i // func_per_file != (file_index - 1):
+                continue
+
             flavor = func.marshal_flavor()
             if flavor in ('skip', 'custom'):
                 continue
             elif flavor == 'async':
                 self.print_async_body(func)
-                async_funcs.append(func)
             elif flavor == 'sync':
                 self.print_sync_body(func)
-        self.print_unmarshal_dispatch_cmd(api)
-        self.print_create_marshal_table(api)
 
 
 def show_usage():
@@ -347,14 +358,19 @@ if __name__ == '__main__':
     file_name = 'gl_API.xml'
 
     try:
-        (args, trail) = getopt.getopt(sys.argv[1:], 'm:f:')
+        (args, trail) = getopt.getopt(sys.argv[1:], 'm:f:i:n:')
     except Exception:
         show_usage()
 
     for (arg,val) in args:
         if arg == '-f':
             file_name = val
+        elif arg == '-i':
+            file_index = int(val)
+        elif arg == '-n':
+            file_count = int(val)
 
+    assert file_index < file_count
     printer = PrintCode()
 
     api = gl_XML.parse_GL_API(file_name, marshal_XML.marshal_item_factory())
index 007f0dc2346c1f631ce645feb95ea345a46c6011..d04ccf19ae4f1c58a7c82fcf91975dd305bd1c9c 100644 (file)
@@ -222,14 +222,17 @@ main_api_exec_c = custom_target(
   capture : true,
 )
 
-main_marshal_generated_c = custom_target(
-  'marshal_generated.c',
-  input : ['gl_marshal.py', 'gl_and_es_API.xml'],
-  output : 'marshal_generated.c',
-  command : [prog_python, '@INPUT0@', '-f', '@INPUT1@'],
-  depend_files : files('marshal_XML.py') + glapi_gen_depends,
-  capture : true,
-)
+main_marshal_generated_c = []
+foreach x : ['0', '1', '2', '3', '4', '5', '6', '7']
+  main_marshal_generated_c += custom_target(
+    'marshal_generated' + x + '.c',
+    input : ['gl_marshal.py', 'gl_and_es_API.xml'],
+    output : 'marshal_generated' + x + '.c',
+    command : [prog_python, '@INPUT0@', '-f', '@INPUT1@', '-i', x, '-n', '8'],
+    depend_files : files('marshal_XML.py') + glapi_gen_depends,
+    capture : true,
+  )
+endforeach
 
 glx_generated = []
 
index ff4f5e4e4d84867d4d2b0df83ba90cf7b5e3802e..7fbbaa9ddbb73647ed184c670940058d1d34c772 100644 (file)
@@ -87,10 +87,52 @@ $(intermediates)/main/api_exec.c: PRIVATE_XML := -f $(glapi)/gl_and_es_API.xml
 $(intermediates)/main/api_exec.c: $(dispatch_deps)
        $(call es-gen)
 
-$(intermediates)/main/marshal_generated.c: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(glapi)/gl_marshal.py
-$(intermediates)/main/marshal_generated.c: PRIVATE_XML := -f $(glapi)/gl_and_es_API.xml
+$(intermediates)/main/marshal_generated0.c: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(glapi)/gl_marshal.py
+$(intermediates)/main/marshal_generated0.c: PRIVATE_XML := -f $(glapi)/gl_and_es_API.xml -i 0 -n 8
 
-$(intermediates)/main/marshal_generated.c: $(dispatch_deps)
+$(intermediates)/main/marshal_generated0.c: $(dispatch_deps)
+       $(call es-gen)
+
+$(intermediates)/main/marshal_generated1.c: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(glapi)/gl_marshal.py
+$(intermediates)/main/marshal_generated1.c: PRIVATE_XML := -f $(glapi)/gl_and_es_API.xml -i 1 -n 8
+
+$(intermediates)/main/marshal_generated1.c: $(dispatch_deps)
+       $(call es-gen)
+
+$(intermediates)/main/marshal_generated2.c: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(glapi)/gl_marshal.py
+$(intermediates)/main/marshal_generated2.c: PRIVATE_XML := -f $(glapi)/gl_and_es_API.xml -i 2 -n 8
+
+$(intermediates)/main/marshal_generated2.c: $(dispatch_deps)
+       $(call es-gen)
+
+$(intermediates)/main/marshal_generated3.c: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(glapi)/gl_marshal.py
+$(intermediates)/main/marshal_generated3.c: PRIVATE_XML := -f $(glapi)/gl_and_es_API.xml -i 3 -n 8
+
+$(intermediates)/main/marshal_generated3.c: $(dispatch_deps)
+       $(call es-gen)
+
+$(intermediates)/main/marshal_generated4.c: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(glapi)/gl_marshal.py
+$(intermediates)/main/marshal_generated4.c: PRIVATE_XML := -f $(glapi)/gl_and_es_API.xml -i 4 -n 8
+
+$(intermediates)/main/marshal_generated4.c: $(dispatch_deps)
+       $(call es-gen)
+
+$(intermediates)/main/marshal_generated5.c: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(glapi)/gl_marshal.py
+$(intermediates)/main/marshal_generated5.c: PRIVATE_XML := -f $(glapi)/gl_and_es_API.xml -i 5 -n 8
+
+$(intermediates)/main/marshal_generated5.c: $(dispatch_deps)
+       $(call es-gen)
+
+$(intermediates)/main/marshal_generated6.c: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(glapi)/gl_marshal.py
+$(intermediates)/main/marshal_generated6.c: PRIVATE_XML := -f $(glapi)/gl_and_es_API.xml -i 6 -n 8
+
+$(intermediates)/main/marshal_generated6.c: $(dispatch_deps)
+       $(call es-gen)
+
+$(intermediates)/main/marshal_generated7.c: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(glapi)/gl_marshal.py
+$(intermediates)/main/marshal_generated7.c: PRIVATE_XML := -f $(glapi)/gl_and_es_API.xml -i 7 -n 8
+
+$(intermediates)/main/marshal_generated7.c: $(dispatch_deps)
        $(call es-gen)
 
 $(intermediates)/main/marshal_generated.h: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(glapi)/gl_marshal_h.py
index 6faf5d992b62e973729d73503e61b72a013c6cd2..cb4aab1d10aecd2458afa7d49232b891153642ba 100644 (file)
@@ -145,7 +145,14 @@ MAIN_FILES = \
        main/lines.c \
        main/lines.h \
        main/macros.h \
-       main/marshal_generated.c \
+       main/marshal_generated0.c \
+       main/marshal_generated1.c \
+       main/marshal_generated2.c \
+       main/marshal_generated3.c \
+       main/marshal_generated4.c \
+       main/marshal_generated5.c \
+       main/marshal_generated6.c \
+       main/marshal_generated7.c \
        main/marshal_generated.h \
        main/matrix.c \
        main/matrix.h \
index da003743f59efbcf0261e6cf94aaed12ffe1af48..dafe6c4bbbd441de3826f726a1ece9ada11e3d80 100644 (file)
@@ -104,12 +104,13 @@ if env['platform'] not in ('cygwin', 'darwin', 'windows', 'haiku'):
         pass
 
 # The marshal_generated.c file is generated from the GL/ES API.xml file
-env.CodeGenerate(
-    target = 'main/marshal_generated.c',
-    script = GLAPI + 'gen/gl_marshal.py',
-    source = [GLAPI + 'gen/gl_and_es_API.xml'] + env.Glob(GLAPI + 'gen/*.xml'),
-    command = python_cmd + ' $SCRIPT -f $SOURCE > $TARGET'
-    )
+for i in range(8):
+    env.CodeGenerate(
+        target = 'main/marshal_generated{0}.c'.format(i),
+        script = GLAPI + 'gen/gl_marshal.py',
+        source = [GLAPI + 'gen/gl_and_es_API.xml'] + env.Glob(GLAPI + 'gen/*.xml'),
+        command = python_cmd + ' $SCRIPT -f $SOURCE -i {0} -n 8 > $TARGET'.format(i)
+        )
 
 # The marshal_generated.h file is generated from the GL/ES API.xml file
 env.CodeGenerate(
index 5f9065675180f9e534007d99675bbb5691968bde..11c176686cc3696cdb0bf4e87ce1daf952c178cb 100644 (file)
@@ -692,13 +692,12 @@ files_libmesa_common += [
   main_enums_c,
   format_fallback_c,
   get_hash_h,
-  main_marshal_generated_c,
   main_marshal_generated_h,
   main_dispatch_h,
   ir_expression_operation_h,
   main_remap_helper_h,
   sha1_h,
-]
+] + main_marshal_generated_c
 files_libmesa_gallium += [
   ir_expression_operation_h,
   sha1_h,