• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2015 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import os
6import perf_measurement
7import numpy
8
9from autotest_lib.client.bin import test
10from autotest_lib.client.bin import utils
11from autotest_lib.client.common_lib import error
12
13# This event counts cycles when the page miss handler is servicing page walks
14# caused by ITLB misses. Raw event codes for x86 microarchitectures can be
15# found at Intel Open Source technology center website:
16# https://download.01.org/perfmon
17RAW_PAGE_WALK_EVENT_CODES = {
18    'Broadwell': 'r1085',
19    'Haswell': 'r1085',
20    'IvyBridge': 'r0485',
21    'SandyBridge': 'r0485',
22    'Silvermont': 'r0305',
23}
24
25class hardware_TLBMissCost(test.test):
26    """Calculates cost of one iTLB miss in
27    terms of cycles spent on page walking.
28    """
29
30    version = 1
31    preserve_srcdir = True
32
33    def initialize(self, events=('cycles', 'iTLB-misses')):
34        self.job.require_gcc()
35        self.events = events
36
37    def setup(self):
38        chost = os.getenv('CHOST', '')
39        if chost == 'x86_64-cros-linux-gnu':
40            os.chdir(self.srcdir)
41            utils.make('clean')
42            utils.make()
43
44    def warmup(self):
45        uarch = utils.get_intel_cpu_uarch()
46        if uarch not in RAW_PAGE_WALK_EVENT_CODES:
47            raise error.TestNAError('Unsupported microarchitecture.')
48        self.pw_event = RAW_PAGE_WALK_EVENT_CODES.get(uarch)
49
50    def run_once(self, program):
51        program = os.path.join(self.srcdir, program)
52        self.events = self.events + (self.pw_event,)
53        self.facts = perf_measurement.GatherPerfStats(program,
54                ','.join(self.events))
55
56    def postprocess_iteration(self):
57        results = {}
58        if ('iTLB-misses' in self.events):
59            pw_cycles_per_miss = [x[self.pw_event] * 1.0 / x['iTLB-misses']
60                                  for x in self.facts]
61            results['pw-cycles-per-miss'] = numpy.average(pw_cycles_per_miss)
62        if ('cycles' in self.events):
63            pw_cycle_percent = [x[self.pw_event] * 100.0 / x['cycles']
64                                for x in self.facts]
65            results['pw-cycle-percent'] = numpy.average(pw_cycle_percent)
66        self.write_perf_keyval(results)
67