SeriesRequestGenerator.cc revision 11320
16145SN/A/*
26386SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
37553SN/A * Copyright (c) 2009-2010 Advanced Micro Devices, Inc.
46386SN/A * All rights reserved.
56386SN/A *
66386SN/A * Redistribution and use in source and binary forms, with or without
76386SN/A * modification, are permitted provided that the following conditions are
86386SN/A * met: redistributions of source code must retain the above copyright
96386SN/A * notice, this list of conditions and the following disclaimer;
106386SN/A * redistributions in binary form must reproduce the above copyright
116386SN/A * notice, this list of conditions and the following disclaimer in the
126386SN/A * documentation and/or other materials provided with the distribution;
136386SN/A * neither the name of the copyright holders nor the names of its
146386SN/A * contributors may be used to endorse or promote products derived from
156386SN/A * this software without specific prior written permission.
166386SN/A *
176386SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186386SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196386SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206386SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216386SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226386SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236386SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246386SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256386SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266386SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276386SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286386SN/A */
296145SN/A
3010348Sandreas.hansson@arm.com#include "base/random.hh"
317632SBrad.Beckmann@amd.com#include "cpu/testers/directedtest/DirectedGenerator.hh"
327632SBrad.Beckmann@amd.com#include "cpu/testers/directedtest/RubyDirectedTester.hh"
337632SBrad.Beckmann@amd.com#include "cpu/testers/directedtest/SeriesRequestGenerator.hh"
348232Snate@binkert.org#include "debug/DirectedTest.hh"
356145SN/A
367553SN/ASeriesRequestGenerator::SeriesRequestGenerator(const Params *p)
379365Snilay@cs.wisc.edu    : DirectedGenerator(p),
389365Snilay@cs.wisc.edu      m_addr_increment_size(p->addr_increment_size),
399365Snilay@cs.wisc.edu      m_percent_writes(p->percent_writes)
406145SN/A{
417553SN/A    m_status = SeriesRequestGeneratorStatus_Thinking;
427553SN/A    m_active_node = 0;
437553SN/A    m_address = 0x0;
446145SN/A}
456145SN/A
467553SN/ASeriesRequestGenerator::~SeriesRequestGenerator()
476145SN/A{
486145SN/A}
496145SN/A
507553SN/Abool
517553SN/ASeriesRequestGenerator::initiate()
526145SN/A{
537553SN/A    DPRINTF(DirectedTest, "initiating request\n");
547553SN/A    assert(m_status == SeriesRequestGeneratorStatus_Thinking);
556145SN/A
568950Sandreas.hansson@arm.com    MasterPort* port = m_directed_tester->getCpuPort(m_active_node);
577553SN/A
587553SN/A    Request::Flags flags;
597553SN/A
607553SN/A    // For simplicity, requests are assumed to be 1 byte-sized
618832SAli.Saidi@ARM.com    Request *req = new Request(m_address, 1, flags, masterId);
627553SN/A
637553SN/A    Packet::Command cmd;
6410348Sandreas.hansson@arm.com    bool do_write = (random_mt.random(0, 100) < m_percent_writes);
659365Snilay@cs.wisc.edu    if (do_write) {
667553SN/A        cmd = MemCmd::WriteReq;
677553SN/A    } else {
687553SN/A        cmd = MemCmd::ReadReq;
696145SN/A    }
709365Snilay@cs.wisc.edu
718949Sandreas.hansson@arm.com    PacketPtr pkt = new Packet(req, cmd);
7210566Sandreas.hansson@arm.com    pkt->allocate();
736145SN/A
748975Sandreas.hansson@arm.com    if (port->sendTimingReq(pkt)) {
757553SN/A        DPRINTF(DirectedTest, "initiating request - successful\n");
767553SN/A        m_status = SeriesRequestGeneratorStatus_Request_Pending;
777553SN/A        return true;
787553SN/A    } else {
797553SN/A        // If the packet did not issue, must delete
807553SN/A        // Note: No need to delete the data, the packet destructor
817553SN/A        // will delete it
827553SN/A        delete pkt->req;
837553SN/A        delete pkt;
847553SN/A
857553SN/A        DPRINTF(DirectedTest, "failed to initiate request - sequencer not ready\n");
867553SN/A        return false;
877553SN/A    }
886145SN/A}
896145SN/A
9011320Ssteve.reinhardt@amd.comvoid
918655Sandreas.hansson@arm.comSeriesRequestGenerator::performCallback(uint32_t proc, Addr address)
926145SN/A{
937553SN/A    assert(m_active_node == proc);
9411320Ssteve.reinhardt@amd.com    assert(m_address == address);
957553SN/A    assert(m_status == SeriesRequestGeneratorStatus_Request_Pending);
966145SN/A
977553SN/A    m_status = SeriesRequestGeneratorStatus_Thinking;
987553SN/A    m_active_node++;
997553SN/A    if (m_active_node == m_num_cpus) {
1007553SN/A        //
1017553SN/A        // Cycle of requests completed, increment cycle completions and restart
1027553SN/A        // at cpu zero
1037553SN/A        //
1047553SN/A        m_directed_tester->incrementCycleCompletions();
1057553SN/A        m_address += m_addr_increment_size;
1067553SN/A        m_active_node = 0;
1077553SN/A    }
1086145SN/A}
1096145SN/A
1107553SN/ASeriesRequestGenerator *
1117553SN/ASeriesRequestGeneratorParams::create()
1126145SN/A{
1137553SN/A    return new SeriesRequestGenerator(this);
1146145SN/A}
115