CheckTable.cc revision 11793
12086SN/A/*
22086SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
35268Sksewell@umich.edu * Copyright (c) 2009 Advanced Micro Devices, Inc.
42086SN/A * All rights reserved.
52086SN/A *
62086SN/A * Redistribution and use in source and binary forms, with or without
72086SN/A * modification, are permitted provided that the following conditions are
82086SN/A * met: redistributions of source code must retain the above copyright
92086SN/A * notice, this list of conditions and the following disclaimer;
102086SN/A * redistributions in binary form must reproduce the above copyright
112086SN/A * notice, this list of conditions and the following disclaimer in the
122086SN/A * documentation and/or other materials provided with the distribution;
132086SN/A * neither the name of the copyright holders nor the names of its
142086SN/A * contributors may be used to endorse or promote products derived from
152086SN/A * this software without specific prior written permission.
162086SN/A *
172086SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182086SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192086SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202086SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212086SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222086SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232086SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242086SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252086SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262086SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272086SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu */
292665Ssaidi@eecs.umich.edu
302665Ssaidi@eecs.umich.edu#include "cpu/testers/rubytest/CheckTable.hh"
312686Sksewell@umich.edu
322086SN/A#include "base/intmath.hh"
334202Sbinkertn@umich.edu#include "base/random.hh"
342086SN/A#include "cpu/testers/rubytest/Check.hh"
354202Sbinkertn@umich.edu#include "debug/RubyTest.hh"
364202Sbinkertn@umich.edu
376313Sgblack@eecs.umich.eduCheckTable::CheckTable(int _num_writers, int _num_readers, RubyTester* _tester)
384997Sgblack@eecs.umich.edu    : m_num_writers(_num_writers), m_num_readers(_num_readers),
395222Sksewell@umich.edu      m_tester_ptr(_tester)
404202Sbinkertn@umich.edu{
415222Sksewell@umich.edu    Addr physical = 0;
424997Sgblack@eecs.umich.edu
434997Sgblack@eecs.umich.edu    const int size1 = 32;
445192Ssaidi@eecs.umich.edu    const int size2 = 100;
455192Ssaidi@eecs.umich.edu
464202Sbinkertn@umich.edu    DPRINTF(RubyTest, "Adding false sharing checks\n");
475222Sksewell@umich.edu    // The first set is to get some false sharing
485647Sgblack@eecs.umich.edu    physical = 1000;
495222Sksewell@umich.edu    for (int i = 0; i < size1; i++) {
505222Sksewell@umich.edu        // Setup linear addresses
515222Sksewell@umich.edu        addCheck(physical);
525222Sksewell@umich.edu        physical += CHECK_SIZE;
535222Sksewell@umich.edu    }
545222Sksewell@umich.edu
555222Sksewell@umich.edu    DPRINTF(RubyTest, "Adding cache conflict checks\n");
565222Sksewell@umich.edu    // The next two sets are to get some limited false sharing and
574202Sbinkertn@umich.edu    // cache conflicts
584202Sbinkertn@umich.edu    physical = 1000;
594202Sbinkertn@umich.edu    for (int i = 0; i < size2; i++) {
604202Sbinkertn@umich.edu        // Setup linear addresses
612086SN/A        addCheck(physical);
624202Sbinkertn@umich.edu        physical += 256;
634202Sbinkertn@umich.edu    }
644202Sbinkertn@umich.edu
654202Sbinkertn@umich.edu    DPRINTF(RubyTest, "Adding cache conflict checks2\n");
664202Sbinkertn@umich.edu    physical = 1000 + CHECK_SIZE;
674202Sbinkertn@umich.edu    for (int i = 0; i < size2; i++) {
68        // Setup linear addresses
69        addCheck(physical);
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
81void
82CheckTable::addCheck(Addr address)
83{
84    if (floorLog2(CHECK_SIZE) != 0) {
85        if (bitSelect(address, 0, CHECK_SIZE_BITS - 1) != 0) {
86            panic("Check not aligned");
87        }
88    }
89
90    for (int i = 0; i < CHECK_SIZE; i++) {
91        if (m_lookup_map.count(address+i)) {
92            // A mapping for this byte already existed, discard the
93            // entire check
94            return;
95        }
96    }
97
98    DPRINTF(RubyTest, "Adding check for address: %s\n", address);
99
100    Check* check_ptr = new Check(address, 100 + m_check_vector.size(),
101                                 m_num_writers, m_num_readers, m_tester_ptr);
102    for (int i = 0; i < CHECK_SIZE; i++) {
103        // Insert it once per byte
104        m_lookup_map[address + i] = check_ptr;
105    }
106    m_check_vector.push_back(check_ptr);
107}
108
109Check*
110CheckTable::getRandomCheck()
111{
112    assert(m_check_vector.size() > 0);
113    return m_check_vector[random_mt.random<unsigned>(0, m_check_vector.size() - 1)];
114}
115
116Check*
117CheckTable::getCheck(const Addr address)
118{
119    DPRINTF(RubyTest, "Looking for check by address: %s\n", address);
120
121    auto i = m_lookup_map.find(address);
122
123    if (i == m_lookup_map.end())
124        return NULL;
125
126    Check* check = i->second;
127    assert(check != NULL);
128    return check;
129}
130
131void
132CheckTable::print(std::ostream& out) const
133{
134}
135