Exemplo n.º 1
0
    def __init__(self):
        self.core_msr_files = {}
        self.package_msr_files = {}
        for i in range(cpu_count()):
            curr_core_id = int(cat("/sys/devices/system/cpu/cpu" + str(i) +
                                   "/topology/core_id", binary=False))
            if curr_core_id not in self.core_msr_files:
                self.core_msr_files[curr_core_id] = "/dev/cpu/" + \
                                                    str(i) + "/msr"

            curr_package_id = int(cat("/sys/devices/system/cpu/cpu" + str(i) +
                                      "/topology/physical_package_id",
                                      binary=False))
            if curr_package_id not in self.package_msr_files:
                self.package_msr_files[curr_package_id] = "/dev/cpu/" + \
                                                          str(i) + "/msr"
Exemplo n.º 2
0
    def __init__(self):
        self.inputs = list(
            zip((cat(filename, binary=False) for filename in sorted(
                glob.glob(AMD_ENERGY_DIR_GLOB + 'energy*_label'))),
                sorted(glob.glob(AMD_ENERGY_DIR_GLOB + 'energy*_input'))))

        # How many socket does the system have?
        socket_number = sum(1 for label, _ in self.inputs if 'socket' in label)
        self.inputs.sort(
            key=lambda x: self.get_input_position(x[0], socket_number))
Exemplo n.º 3
0
    def read_power(self):
        """ Read power stats and return dictionary"""

        pjoin = os.path.join
        ret = list()
        for path in self.basenames:
            name = None
            try:
                name = cat(pjoin(path, 'name'), fallback=None, binary=False)
            except (IOError, OSError, ValueError) as err:
                logging.warning("ignoring %r for file %r",
                                (err, path), RuntimeWarning)
                continue
            if name:
                try:
                    current = cat(pjoin(path, 'energy_uj'))
                    max_reading = 0.0
                    ret.append(RaplStats(name, float(current), max_reading))
                except (IOError, OSError, ValueError) as err:
                    logging.warning("ignoring %r for file %r",
                                    (err, path), RuntimeWarning)
        return ret
Exemplo n.º 4
0
def rapl_read():
    """ Read power stats and return dictionary"""
    basenames = glob.glob('/sys/class/powercap/intel-rapl:*/')
    basenames = sorted(set({x for x in basenames}))

    pjoin = os.path.join
    ret = list()
    for path in basenames:
        name = None
        try:
            name = cat(pjoin(path, 'name'), fallback=None, binary=False)
        except (IOError, OSError, ValueError) as err:
            logging.warning("ignoring %r for file %r", (err, path),
                            RuntimeWarning)
            continue
        if name:
            try:
                current = cat(pjoin(path, 'energy_uj'))
                max_reading = 0.0
                ret.append(RaplStats(name, float(current), max_reading))
            except (IOError, OSError, ValueError) as err:
                logging.warning("ignoring %r for file %r", (err, path),
                                RuntimeWarning)
    return ret
Exemplo n.º 5
0
    def available():
        cpuinfo = cat("/proc/cpuinfo", binary=False)
        # The reader only supports family 17h CPUs
        m = re.search(r"vendor_id[\s]+: ([A-Za-z]+)", cpuinfo)
        if m[1] != "AuthenticAMD":
            return False

        m = re.search(r"cpu family[\s]+: ([0-9]+)", cpuinfo)
        if int(m[1]) != 0x17:
            return False

        # Check whether MSRs are available and we have permission to read them
        try:
            open("/dev/cpu/0/msr")
            return True
        except (FileNotFoundError, PermissionError):
            return False
Exemplo n.º 6
0
    def available():
        cpuinfo = cat("/proc/cpuinfo", binary=False)
        # The reader only supports family 17h CPUs
        m = re.search(r"vendor_id[\s]+: ([A-Za-z]+)", cpuinfo)

        if not m or m is None:
            return False

        if m.group(1) != "AuthenticAMD":
            return False

        m = re.search(r"cpu family[\s]+: ([0-9]+)", cpuinfo)
        if int(m[1]) != 0x17:
            return False

        # with open("/proc/cpuinfo", "rb") as cpuinfo:
        #     all_info = cpuinfo.readlines()
        #     for line in all_info:
        #         if b"vendor_id" in line:
        #             print("Verndor id", line)
        #             if b"AuthenticAMD" not in line:
        #                 return False

        #     for line in all_info:
        #         if b"cpu family" in line:
        #             print("cpu family", line)
        #             m = re.search("cpu family[\s]+: ([0-9]+)", cpuinfo)
        #             if int(m[1]) != 0x17:
        #                 return False

        # Check whether MSRs are available and we have permission to read them
        try:
            open("/dev/cpu/0/msr")
            return True
        except (FileNotFoundError, PermissionError):
            return False
Exemplo n.º 7
0
 def read_power(self):
     ret = []
     for label, inp in self.inputs:
         value = cat(inp)
         ret.append(RaplStats(label, float(value), 0.0))
     return ret