RubyDirectedTester.cc revision 13784
112609Sjason@lowepower.com/*
212609Sjason@lowepower.com * Copyright (c) 2012 ARM Limited
312609Sjason@lowepower.com * All rights reserved
412609Sjason@lowepower.com *
512609Sjason@lowepower.com * The license below extends only to copyright in the software and shall
612609Sjason@lowepower.com * not be construed as granting a license to any other intellectual
712609Sjason@lowepower.com * property including but not limited to intellectual property relating
812609Sjason@lowepower.com * to a hardware implementation of the functionality of the software
912609Sjason@lowepower.com * licensed hereunder.  You may use the software subject to the license
1012609Sjason@lowepower.com * terms below provided that you ensure that this notice is replicated
1112609Sjason@lowepower.com * unmodified and in its entirety in all distributions of the software,
1212609Sjason@lowepower.com * modified or unmodified, in source code or in binary form.
1312609Sjason@lowepower.com *
1412609Sjason@lowepower.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
1512609Sjason@lowepower.com * Copyright (c) 2009-2010 Advanced Micro Devices, Inc.
1612609Sjason@lowepower.com * All rights reserved.
1712609Sjason@lowepower.com *
1812609Sjason@lowepower.com * Redistribution and use in source and binary forms, with or without
1912609Sjason@lowepower.com * modification, are permitted provided that the following conditions are
2012609Sjason@lowepower.com * met: redistributions of source code must retain the above copyright
2112609Sjason@lowepower.com * notice, this list of conditions and the following disclaimer;
2212609Sjason@lowepower.com * redistributions in binary form must reproduce the above copyright
2312609Sjason@lowepower.com * notice, this list of conditions and the following disclaimer in the
2412609Sjason@lowepower.com * documentation and/or other materials provided with the distribution;
2512609Sjason@lowepower.com * neither the name of the copyright holders nor the names of its
2612609Sjason@lowepower.com * contributors may be used to endorse or promote products derived from
2712609Sjason@lowepower.com * this software without specific prior written permission.
2812609Sjason@lowepower.com *
2912609Sjason@lowepower.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3012609Sjason@lowepower.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3112609Sjason@lowepower.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3212609Sjason@lowepower.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3312609Sjason@lowepower.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3412609Sjason@lowepower.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3512609Sjason@lowepower.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3612609Sjason@lowepower.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3712609Sjason@lowepower.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3812609Sjason@lowepower.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3913774Sandreas.sandberg@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4013774Sandreas.sandberg@arm.com */
4113774Sandreas.sandberg@arm.com
4212609Sjason@lowepower.com#include "cpu/testers/directedtest/RubyDirectedTester.hh"
4312609Sjason@lowepower.com
4412609Sjason@lowepower.com#include "base/trace.hh"
4512609Sjason@lowepower.com#include "cpu/testers/directedtest/DirectedGenerator.hh"
4612609Sjason@lowepower.com#include "debug/DirectedTest.hh"
4712609Sjason@lowepower.com#include "sim/sim_exit.hh"
4812609Sjason@lowepower.com
4912609Sjason@lowepower.comRubyDirectedTester::RubyDirectedTester(const Params *p)
5012609Sjason@lowepower.com  : MemObject(p),
5112609Sjason@lowepower.com    directedStartEvent([this]{ wakeup(); }, "Directed tick",
5212609Sjason@lowepower.com                       false, Event::CPU_Tick_Pri),
5312609Sjason@lowepower.com    m_requests_to_complete(p->requests_to_complete),
5412609Sjason@lowepower.com    generator(p->generator)
5512609Sjason@lowepower.com{
5612609Sjason@lowepower.com    m_requests_completed = 0;
5712609Sjason@lowepower.com
5812609Sjason@lowepower.com    // create the ports
5912609Sjason@lowepower.com    for (int i = 0; i < p->port_cpuPort_connection_count; ++i) {
6012609Sjason@lowepower.com        ports.push_back(new CpuPort(csprintf("%s-port%d", name(), i),
6112609Sjason@lowepower.com                                    this, i));
6212609Sjason@lowepower.com    }
6312609Sjason@lowepower.com
6412609Sjason@lowepower.com    // add the check start event to the event queue
6512609Sjason@lowepower.com    schedule(directedStartEvent, 1);
6612609Sjason@lowepower.com}
6712609Sjason@lowepower.com
6812609Sjason@lowepower.comRubyDirectedTester::~RubyDirectedTester()
6912609Sjason@lowepower.com{
7012609Sjason@lowepower.com    for (int i = 0; i < ports.size(); i++)
7112609Sjason@lowepower.com        delete ports[i];
7212609Sjason@lowepower.com}
7312609Sjason@lowepower.com
7412609Sjason@lowepower.comvoid
7512609Sjason@lowepower.comRubyDirectedTester::init()
7612609Sjason@lowepower.com{
7712609Sjason@lowepower.com    assert(ports.size() > 0);
7812609Sjason@lowepower.com    generator->setDirectedTester(this);
7912609Sjason@lowepower.com}
8012609Sjason@lowepower.com
8112609Sjason@lowepower.comPort &
8212609Sjason@lowepower.comRubyDirectedTester::getPort(const std::string &if_name, PortID idx)
8312609Sjason@lowepower.com{
8412609Sjason@lowepower.com    if (if_name != "cpuPort") {
8512609Sjason@lowepower.com        // pass it along to our super class
8612609Sjason@lowepower.com        return MemObject::getPort(if_name, idx);
8712609Sjason@lowepower.com    } else {
8812609Sjason@lowepower.com        if (idx >= static_cast<int>(ports.size())) {
8912609Sjason@lowepower.com            panic("RubyDirectedTester::getPort: unknown index %d\n", idx);
9012609Sjason@lowepower.com        }
9112609Sjason@lowepower.com
9212609Sjason@lowepower.com        return *ports[idx];
9312609Sjason@lowepower.com    }
9412609Sjason@lowepower.com}
9512609Sjason@lowepower.com
9612609Sjason@lowepower.combool
9712609Sjason@lowepower.comRubyDirectedTester::CpuPort::recvTimingResp(PacketPtr pkt)
9812609Sjason@lowepower.com{
9912609Sjason@lowepower.com    tester->hitCallback(id, pkt->getAddr());
10012609Sjason@lowepower.com
10112609Sjason@lowepower.com    //
10212609Sjason@lowepower.com    // Now that the tester has completed, delete the packet, then return
10312609Sjason@lowepower.com    //
10412609Sjason@lowepower.com    delete pkt;
10512609Sjason@lowepower.com    return true;
10612609Sjason@lowepower.com}
10712609Sjason@lowepower.com
10812609Sjason@lowepower.comMasterPort*
10912609Sjason@lowepower.comRubyDirectedTester::getCpuPort(int idx)
11012609Sjason@lowepower.com{
11112609Sjason@lowepower.com    assert(idx >= 0 && idx < ports.size());
11212609Sjason@lowepower.com
11312609Sjason@lowepower.com    return ports[idx];
11412609Sjason@lowepower.com}
11512609Sjason@lowepower.com
11612609Sjason@lowepower.comvoid
11712609Sjason@lowepower.comRubyDirectedTester::hitCallback(NodeID proc, Addr addr)
11812609Sjason@lowepower.com{
11912609Sjason@lowepower.com    DPRINTF(DirectedTest,
12012609Sjason@lowepower.com            "completed request for proc: %d addr: 0x%x\n",
12112609Sjason@lowepower.com            proc,
12212609Sjason@lowepower.com            addr);
12312609Sjason@lowepower.com
12412609Sjason@lowepower.com    generator->performCallback(proc, addr);
12512609Sjason@lowepower.com    schedule(directedStartEvent, curTick());
12612609Sjason@lowepower.com}
12712609Sjason@lowepower.com
12812609Sjason@lowepower.comvoid
12912609Sjason@lowepower.comRubyDirectedTester::wakeup()
13012609Sjason@lowepower.com{
13112609Sjason@lowepower.com    if (m_requests_completed < m_requests_to_complete) {
13212609Sjason@lowepower.com        if (!generator->initiate()) {
13312609Sjason@lowepower.com            schedule(directedStartEvent, curTick() + 1);
13412609Sjason@lowepower.com        }
13512609Sjason@lowepower.com    } else {
13612609Sjason@lowepower.com        exitSimLoop("Ruby DirectedTester completed");
13712609Sjason@lowepower.com    }
13812609Sjason@lowepower.com}
13912609Sjason@lowepower.com
14012609Sjason@lowepower.comRubyDirectedTester *
14112609Sjason@lowepower.comRubyDirectedTesterParams::create()
14212609Sjason@lowepower.com{
14312609Sjason@lowepower.com    return new RubyDirectedTester(this);
14412609Sjason@lowepower.com}
14512609Sjason@lowepower.com