File: oa_guid_registry.py

package info (click to toggle)
intel-gpu-tools 2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 62,024 kB
  • sloc: xml: 769,439; ansic: 348,692; python: 8,307; yacc: 2,781; perl: 1,196; sh: 1,178; lex: 487; asm: 227; makefile: 27; lisp: 11
file content (120 lines) | stat: -rw-r--r-- 3,945 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import copy
import hashlib
import re

import xml.etree.ElementTree as et


class Registry:

    # Tries to avoid fragility from et.tostring() by normalizing into CSV string first
    @staticmethod
    def hw_config_hash(metric_set):
        """Hashes the given metric set's HW register configs.

        Args:
            metric_set -- is an ElementTree element for a 'set'

        Note this doesn't accept an MDAPI based metric set description
        """

        registers_str = ""
        for config in metric_set.findall(".//register_config"):
            if config.get('id') == None:
                config_id = '0'
            else:
                config_id = config.get('id')
            if config.get('priority') == None:
                config_priority = '0'
            else:
                config_priority = config.get('priority')
            if config.get('availability') == None:
                config_availability = ""
            else:
                config_availability = config.get('availability')
            for reg in config.findall("register"):
                addr = int(reg.get('address'), 16)
                value = int(reg.get('value'), 16)
                registers_str = registers_str + config_id + ',' + config_priority + ',' + config_availability + ',' + str(addr) + ',' + str(value) + '\n'

        return hashlib.md5(registers_str.encode('utf-8')).hexdigest()


    @staticmethod
    def mdapi_hw_config_hash(mdapi_metric_set):
        """Hashes the HW register configuration of a metric set from VPG's MDAPI XML files.

        Args:
            mdapi_metric_set -- is an ElementTree element for a 'MetricSet'

        Note: being a simplistic hash of all RegConfigStart element contents
        this will change for minor comment changes in VPG's files. Without
        any promisies of stability within these files then it can't help to
        err on the side of caution here, so we know when to investigate
        changes that might affect our useages.
        """

        def reorder_attributes(root):
            for el in root.iter():
                attrib = el.attrib
                if len(attrib) > 1:
                    # adjust attribute order, e.g. by sorting
                    attribs = sorted(attrib.items())
                    attrib.clear()
                    attrib.update(attribs)

        config = et.Element('config')
        for registers in mdapi_metric_set.findall(".//RegConfigStart"):
            config.append(copy.deepcopy(registers))
        reorder_attributes(config)
        registers_str = et.tostring(config)

        return hashlib.md5(registers_str).hexdigest()

    @staticmethod
    def chipset_derive_hash(chipset, set_name, hash):
        """Derive a HW config hash for a given chipset & set name.

        This helps us avoiding collisions with identical config across
        different Gen or GT.
        """

        return "%s-%s-%s" % (chipset, set_name, hash)


    @staticmethod
    def chipset_name(name):
        known_chipsets = ( 'HSW',
                           'BDW',
                           'CHV',
                           'SKL',
                           'BXT',
                           'KBL',
                           'GLK',
                           'CFL',
                           'CNL',
                           'ICL',
                           'EHL',
                           'TGL',
                           'RKL',
                           'DG1',
                           'ACM',
                           'PVC',
                           'MTL',
                           'LNL',
                           'BMG',
                          )
        if name in known_chipsets:
            return name

        # Unknown HW
        assert 0


    @staticmethod
    def gt_name(name):
        return re.sub(' ', '', name)

    @staticmethod
    def sanitize_symbol_name(text):
        return text.replace('#', "_")