CheckTable.cc revision 6899
1
2/*
3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4 * Copyright (c) 2009 Advanced Micro Devices, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met: redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer;
11 * redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution;
14 * neither the name of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31
32#include "cpu/rubytest/CheckTable.hh"
33#include "cpu/rubytest/CheckTable.hh"
34#include "cpu/rubytest/Check.hh"
35#include "mem/gems_common/Map.hh"
36
37CheckTable::CheckTable(int _num_cpu_sequencers, RubyTester* _tester)
38  : m_num_cpu_sequencers(_num_cpu_sequencers), m_tester_ptr(_tester)
39{
40  m_lookup_map_ptr = new Map<Address, Check*>;
41  physical_address_t physical = 0;
42  Address address;
43
44  const int size1 = 32;
45  const int size2 = 100;
46
47  // The first set is to get some false sharing
48  physical = 1000;
49  for (int i=0; i<size1; i++) {
50    // Setup linear addresses
51    address.setAddress(physical);
52    addCheck(address);
53    physical += CHECK_SIZE;
54  }
55
56  // The next two sets are to get some limited false sharing and cache conflicts
57  physical = 1000;
58  for (int i=0; i<size2; i++) {
59    // Setup linear addresses
60    address.setAddress(physical);
61    addCheck(address);
62    physical += 256;
63  }
64
65  physical = 1000 + CHECK_SIZE;
66  for (int i=0; i<size2; i++) {
67    // Setup linear addresses
68    address.setAddress(physical);
69    addCheck(address);
70    physical += 256;
71  }
72}
73
74CheckTable::~CheckTable()
75{
76  int size = m_check_vector.size();
77  for (int i=0; i<size; i++) {
78    delete m_check_vector[i];
79  }
80  delete m_lookup_map_ptr;
81}
82
83void CheckTable::addCheck(const Address& address)
84{
85  if (log_int(CHECK_SIZE) != 0) {
86    if (address.bitSelect(0,CHECK_SIZE_BITS-1) != 0) {
87      ERROR_MSG("Check not aligned");
88    }
89  }
90
91  for (int i=0; i<CHECK_SIZE; i++) {
92    if (m_lookup_map_ptr->exist(Address(address.getAddress()+i))) {
93      // A mapping for this byte already existed, discard the entire check
94      return;
95    }
96  }
97
98  Check* check_ptr = new Check(address,
99                               Address(100+m_check_vector.size()),
100                               m_num_cpu_sequencers,
101                               m_tester_ptr);
102  for (int i=0; i<CHECK_SIZE; i++) {
103    // Insert it once per byte
104    m_lookup_map_ptr->add(Address(address.getAddress()+i), check_ptr);
105  }
106  m_check_vector.insertAtBottom(check_ptr);
107}
108
109Check* CheckTable::getRandomCheck()
110{
111  return m_check_vector[random() % m_check_vector.size()];
112}
113
114Check* CheckTable::getCheck(const Address& address)
115{
116  DEBUG_MSG(TESTER_COMP, MedPrio, "Looking for check by address");
117  DEBUG_EXPR(TESTER_COMP, MedPrio, address);
118
119  if (m_lookup_map_ptr->exist(address)) {
120    Check* check = m_lookup_map_ptr->lookup(address);
121    assert(check != NULL);
122    return check;
123  } else {
124    return NULL;
125  }
126}
127
128void CheckTable::print(ostream& out) const
129{
130}
131