[Mesa-dev] [PATCH 4/5] intel: aubinator: generate a standalone binary

Jason Ekstrand jason at jlekstrand.net
Tue Oct 4 16:12:56 UTC 2016


On Tue, Oct 4, 2016 at 8:59 AM, Lionel Landwerlin <llandwerlin at gmail.com>
wrote:

> Embed the xml files into the binary, so aubinator can be used from any
> location.
>
> v2: Split generation packing into another patch (Jason)
>     Check for xxd (Jason)
>
> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
> Cc: Sirisha Gandikota <Sirisha.Gandikota at intel.com>
> ---
>  configure.ac                    |  1 +
>  src/intel/Makefile.am           |  1 +
>  src/intel/Makefile.aubinator.am | 36 ++++++++++++++++++
>  src/intel/Makefile.sources      |  7 ++++
>  src/intel/tools/.gitignore      |  5 +++
>  src/intel/tools/aubinator.c     | 39 ++++++++++----------
>  src/intel/tools/decoder.c       | 82 +++++++++++++++++++++++++-----
> -----------
>  src/intel/tools/decoder.h       |  4 +-
>  8 files changed, 122 insertions(+), 53 deletions(-)
>  create mode 100644 src/intel/Makefile.aubinator.am
>
> diff --git a/configure.ac b/configure.ac
> index 1bfac3b..7046349 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -110,6 +110,7 @@ LT_PREREQ([2.2])
>  LT_INIT([disable-static])
>
>  AC_CHECK_PROG(RM, rm, [rm -f])
> +AC_CHECK_PROG(XXD, xxd, [xxd])
>
>  AX_PROG_BISON([],
>                AS_IF([test ! -f "$srcdir/src/compiler/glsl/
> glcpp/glcpp-parse.c"],
> diff --git a/src/intel/Makefile.am b/src/intel/Makefile.am
> index 9186b5c..c3cb9fb 100644
> --- a/src/intel/Makefile.am
> +++ b/src/intel/Makefile.am
> @@ -52,6 +52,7 @@ BUILT_SOURCES =
>  CLEANFILES =
>  EXTRA_DIST =
>
> +include Makefile.aubinator.am
>  include Makefile.blorp.am
>  include Makefile.common.am
>  include Makefile.genxml.am
> diff --git a/src/intel/Makefile.aubinator.am b/src/intel/Makefile.
> aubinator.am
> new file mode 100644
> index 0000000..3d05d30
> --- /dev/null
> +++ b/src/intel/Makefile.aubinator.am
> @@ -0,0 +1,36 @@
> +# Copyright © 2016 Intel Corporation
> +#
> +# Permission is hereby granted, free of charge, to any person obtaining a
> +# copy of this software and associated documentation files (the
> "Software"),
> +# to deal in the Software without restriction, including without
> limitation
> +# the rights to use, copy, modify, merge, publish, distribute, sublicense,
> +# and/or sell copies of the Software, and to permit persons to whom the
> +# Software is furnished to do so, subject to the following conditions:
> +#
> +# The above copyright notice and this permission notice (including the
> next
> +# paragraph) shall be included in all copies or substantial portions of
> the
> +# Software.
> +#
> +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
> OR
> +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
> OTHER
> +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> DEALINGS
> +# IN THE SOFTWARE.
> +
> +BUILT_SOURCES += $(AUBINATOR_GENERATED_FILES)
> +
> +SUFFIXES = _aubinator_xml.h .xml
> +
> +tools/gen6_aubinator_xml.h: genxml/gen6.xml
> +tools/gen7_aubinator_xml.h: genxml/gen7.xml
> +tools/gen75_aubinator_xml.h: genxml/gen75.xml
> +tools/gen8_aubinator_xml.h: genxml/gen8.xml
> +tools/gen9_aubinator_xml.h: genxml/gen9.xml
> +
> +$(AUBINATOR_GENERATED_FILES): Makefile
> +
> +%_aubinator_xml.h:
> +       $(MKDIR_GEN)
> +       $(AM_V_GEN) $(XXD) -i $< > $@
> diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources
> index 94073d2..a5c2bf0 100644
> --- a/src/intel/Makefile.sources
> +++ b/src/intel/Makefile.sources
> @@ -1,3 +1,10 @@
> +AUBINATOR_GENERATED_FILES = \
> +       tools/gen6_aubinator_xml.h \
> +       tools/gen7_aubinator_xml.h \
> +       tools/gen75_aubinator_xml.h \
> +       tools/gen8_aubinator_xml.h \
> +       tools/gen9_aubinator_xml.h
> +
>  BLORP_FILES = \
>         blorp/blorp.c \
>         blorp/blorp.h \
> diff --git a/src/intel/tools/.gitignore b/src/intel/tools/.gitignore
> index 0c80a6f..c4eebde 100644
> --- a/src/intel/tools/.gitignore
> +++ b/src/intel/tools/.gitignore
> @@ -1 +1,6 @@
>  /aubinator
> +gen6_aubinator_xml.h
> +gen75_aubinator_xml.h
> +gen7_aubinator_xml.h
> +gen8_aubinator_xml.h
> +gen9_aubinator_xml.h
> diff --git a/src/intel/tools/aubinator.c b/src/intel/tools/aubinator.c
> index 459e3d4..3599867 100644
> --- a/src/intel/tools/aubinator.c
> +++ b/src/intel/tools/aubinator.c
> @@ -1065,22 +1065,21 @@ int main(int argc, char *argv[])
>     int i;
>     bool found_arg_gen = false, pager = true;
>     const char *value, *input_file = NULL;
> -   char gen_file[256], gen_val[24];
> +   char gen_val[24];
>     const struct {
>        const char *name;
>        int pci_id;
> -      int major;
> -      int minor;
>     } gens[] = {
> -      { "ivb", 0x0166, 7, 0 }, /* Intel(R) Ivybridge Mobile GT2 */
> -      { "hsw", 0x0416, 7, 5 }, /* Intel(R) Haswell Mobile GT2 */
> -      { "byt", 0x0155, 7, 5 }, /* Intel(R) Bay Trail */
> -      { "bdw", 0x1616, 8, 0 }, /* Intel(R) HD Graphics 5500 (Broadwell
> GT2) */
> -      { "chv", 0x22B3, 8, 0 }, /* Intel(R) HD Graphics (Cherryview) */
> -      { "skl", 0x1912, 9, 0 }, /* Intel(R) HD Graphics 530 (Skylake GT2)
> */
> -      { "kbl", 0x591D, 9, 0 }, /* Intel(R) Kabylake GT2 */
> -      { "bxt", 0x0A84, 9, 0 }  /* Intel(R) HD Graphics (Broxton) */
> +      { "ivb", 0x0166 }, /* Intel(R) Ivybridge Mobile GT2 */
> +      { "hsw", 0x0416 }, /* Intel(R) Haswell Mobile GT2 */
> +      { "byt", 0x0155 }, /* Intel(R) Bay Trail */
> +      { "bdw", 0x1616 }, /* Intel(R) HD Graphics 5500 (Broadwell GT2) */
> +      { "chv", 0x22B3 }, /* Intel(R) HD Graphics (Cherryview) */
> +      { "skl", 0x1912 }, /* Intel(R) HD Graphics 530 (Skylake GT2) */
> +      { "kbl", 0x591D }, /* Intel(R) Kabylake GT2 */
> +      { "bxt", 0x0A84 }  /* Intel(R) HD Graphics (Broxton) */
>     }, *gen = NULL;
> +   struct gen_device_info devinfo;
>
>     if (argc == 1) {
>        print_help(argv[0], stderr);
> @@ -1143,6 +1142,13 @@ int main(int argc, char *argv[])
>        exit(EXIT_FAILURE);
>     }
>
> +   if (!gen_get_device_info(gen->pci_id, &devinfo)) {
> +      fprintf(stderr, "can't find device information: pci_id=0x%x
> name=%s\n",
> +              gen->pci_id, gen->name);
> +      exit(EXIT_FAILURE);
> +   }
> +
> +
>     /* Do this before we redirect stdout to pager. */
>     if (option_color == COLOR_AUTO)
>        option_color = isatty(1) ? COLOR_ALWAYS : COLOR_NEVER;
> @@ -1150,17 +1156,10 @@ int main(int argc, char *argv[])
>     if (isatty(1) && pager)
>        setup_pager();
>
> -   if (gen->minor > 0) {
> -      snprintf(gen_file, sizeof(gen_file), "../genxml/gen%d%d.xml",
> -               gen->major, gen->minor);
> -   } else {
> -      snprintf(gen_file, sizeof(gen_file), "../genxml/gen%d.xml",
> gen->major);
> -   }
> -
> -   spec = gen_spec_load(gen_file);
> +   spec = gen_spec_load(&devinfo);
>     disasm = gen_disasm_create(gen->pci_id);
>
> -   if (argv[i] == NULL) {
> +   if (input_file == NULL) {
>

I think this hunk belongs in the next commit.


>         print_help(argv[0], stderr);
>         exit(EXIT_FAILURE);
>     } else {
> diff --git a/src/intel/tools/decoder.c b/src/intel/tools/decoder.c
> index 4cbaab2..2be26e9 100644
> --- a/src/intel/tools/decoder.c
> +++ b/src/intel/tools/decoder.c
> @@ -33,6 +33,12 @@
>
>  #include "decoder.h"
>
> +#include "gen6_aubinator_xml.h"
> +#include "gen7_aubinator_xml.h"
> +#include "gen75_aubinator_xml.h"
> +#include "gen8_aubinator_xml.h"
> +#include "gen9_aubinator_xml.h"
> +
>  #define XML_BUFFER_SIZE 4096
>
>  #define MAKE_GEN(major, minor) ( ((major) << 8) | (minor) )
> @@ -395,57 +401,69 @@ character_data(void *data, const XML_Char *s, int
> len)
>  {
>  }
>
> +static void *
> +devinfo_to_xml_data(const struct gen_device_info *devinfo,
> +                    uint32_t *data_length)
> +{
> +   switch (devinfo->gen) {
> +   case 6:
> +      *data_length = sizeof(genxml_gen6_xml);
> +      return genxml_gen6_xml;
> +   case 7:
> +      if (devinfo->is_haswell) {
> +         *data_length = sizeof(genxml_gen75_xml);
> +         return genxml_gen75_xml;
> +      }
> +      *data_length = sizeof(genxml_gen7_xml);
> +      return genxml_gen7_xml;
> +   case 8:
> +      *data_length = sizeof(genxml_gen8_xml);
> +      return genxml_gen8_xml;
> +   case 9:
> +      *data_length = sizeof(genxml_gen9_xml);
> +      return genxml_gen9_xml;
> +   default:
> +      return NULL;
> +   }
> +}
> +
>  struct gen_spec *
> -gen_spec_load(const char *filename)
> +gen_spec_load(const struct gen_device_info *devinfo)
>  {
>     struct parser_context ctx;
> -   void *buf;
> -   int len;
> -   FILE *input;
> -
> -   input = fopen(filename, "r");
> -   printf("xml filename = %s\n", filename);
> -   if (input == NULL) {
> -      fprintf(stderr, "failed to open xml description\n");
> -      exit(EXIT_FAILURE);
> -   }
> +   void *buf, *data;
> +   uint32_t data_length = 0;
>
>     memset(&ctx, 0, sizeof ctx);
>     ctx.parser = XML_ParserCreate(NULL);
>     XML_SetUserData(ctx.parser, &ctx);
>     if (ctx.parser == NULL) {
>        fprintf(stderr, "failed to create parser\n");
> -      fclose(input);
>        return NULL;
>     }
>
>     XML_SetElementHandler(ctx.parser, start_element, end_element);
>     XML_SetCharacterDataHandler(ctx.parser, character_data);
> -   ctx.loc.filename = filename;
>
>     ctx.spec = xzalloc(sizeof(*ctx.spec));
>
> -   do {
> -      buf = XML_GetBuffer(ctx.parser, XML_BUFFER_SIZE);
> -      len = fread(buf, 1, XML_BUFFER_SIZE, input);
> -      if (len < 0) {
> -         fprintf(stderr, "fread: %m\n");
> -         fclose(input);
> -         return NULL;
> -      }
> -      if (XML_ParseBuffer(ctx.parser, len, len == 0) == 0) {
> -         fprintf(stderr,
> -                 "Error parsing XML at line %ld col %ld: %s\n",
> -                 XML_GetCurrentLineNumber(ctx.parser),
> -                 XML_GetCurrentColumnNumber(ctx.parser),
> -                 XML_ErrorString(XML_GetErrorCode(ctx.parser)));
> -         fclose(input);
> -         return NULL;
> -      }
> -   } while (len > 0);
> +
> +   data = devinfo_to_xml_data(devinfo, &data_length);
> +   buf = XML_GetBuffer(ctx.parser, data_length);
> +
> +   memcpy(buf, data, data_length);
> +
> +   if (XML_ParseBuffer(ctx.parser, data_length, data_length == 0) == 0) {
> +      fprintf(stderr,
> +              "Error parsing XML at line %ld col %ld: %s\n",
> +              XML_GetCurrentLineNumber(ctx.parser),
> +              XML_GetCurrentColumnNumber(ctx.parser),
> +              XML_ErrorString(XML_GetErrorCode(ctx.parser)));
> +      XML_ParserFree(ctx.parser);
> +      return NULL;
> +   }
>
>     XML_ParserFree(ctx.parser);
> -   fclose(input);
>
>     return ctx.spec;
>  }
> diff --git a/src/intel/tools/decoder.h b/src/intel/tools/decoder.h
> index f688ba5..5bea9b9 100644
> --- a/src/intel/tools/decoder.h
> +++ b/src/intel/tools/decoder.h
> @@ -26,6 +26,8 @@
>  #include <stdint.h>
>  #include <stdbool.h>
>
> +#include "common/gen_device_info.h"
> +
>  struct gen_spec;
>  struct gen_group;
>  struct gen_field;
> @@ -36,7 +38,7 @@ static inline uint32_t gen_make_gen(uint32_t major,
> uint32_t minor)
>  }
>
>  struct gen_group *gen_spec_find_struct(struct gen_spec *spec, const char
> *name);
> -struct gen_spec *gen_spec_load(const char *filename);
> +struct gen_spec *gen_spec_load(const struct gen_device_info *devinfo);
>  uint32_t gen_spec_get_gen(struct gen_spec *spec);
>  struct gen_group *gen_spec_find_instruction(struct gen_spec *spec, const
> uint32_t *p);
>  struct gen_group *gen_spec_find_register(struct gen_spec *spec, uint32_t
> offset);
> --
> 2.9.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20161004/a4ffa348/attachment-0001.html>


More information about the mesa-dev mailing list