eventq.cc revision 221
12SN/A/*
21762SN/A * Copyright (c) 2003 The Regents of The University of Michigan
32SN/A * All rights reserved.
42SN/A *
52SN/A * Redistribution and use in source and binary forms, with or without
62SN/A * modification, are permitted provided that the following conditions are
72SN/A * met: redistributions of source code must retain the above copyright
82SN/A * notice, this list of conditions and the following disclaimer;
92SN/A * redistributions in binary form must reproduce the above copyright
102SN/A * notice, this list of conditions and the following disclaimer in the
112SN/A * documentation and/or other materials provided with the distribution;
122SN/A * neither the name of the copyright holders nor the names of its
132SN/A * contributors may be used to endorse or promote products derived from
142SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu */
282665Ssaidi@eecs.umich.edu
292665Ssaidi@eecs.umich.edu#include <assert.h>
302665Ssaidi@eecs.umich.edu
312665Ssaidi@eecs.umich.edu#include <iostream>
322SN/A#include <string>
332SN/A#include <sstream>
342SN/A#include <vector>
352SN/A
362SN/A#include "cpu/full_cpu/smt.hh"
372973Sgblack@eecs.umich.edu#include "base/misc.hh"
3856SN/A
391717SN/A#include "sim/eventq.hh"
402518SN/A#include "base/trace.hh"
4156SN/A#include "sim/universe.hh"
422518SN/A
432518SN/Ausing namespace std;
442SN/A
452SN/Aconst string Event::defaultName("event");
462973Sgblack@eecs.umich.edu
472SN/A//
482SN/A// Main Event Queue
492SN/A//
502SN/A// Events on this queue are processed at the *beginning* of each
512SN/A// cycle, before the pipeline simulation is performed.
522SN/A//
532SN/AEventQueue mainEventQueue("MainEventQueue");
542SN/A
552SN/Avoid
562SN/AEventQueue::insert(Event *event)
573059Sgblack@eecs.umich.edu{
583059Sgblack@eecs.umich.edu    if (head == NULL || event->when() < head->when() ||
593059Sgblack@eecs.umich.edu        (event->when() == head->when() &&
603059Sgblack@eecs.umich.edu         event->priority() <= head->priority())) {
613059Sgblack@eecs.umich.edu        event->next = head;
623059Sgblack@eecs.umich.edu        head = event;
633059Sgblack@eecs.umich.edu    } else {
643059Sgblack@eecs.umich.edu        Event *prev = head;
653059Sgblack@eecs.umich.edu        Event *curr = head->next;
663059Sgblack@eecs.umich.edu
672973Sgblack@eecs.umich.edu        while (curr) {
682973Sgblack@eecs.umich.edu            if (event->when() <= curr->when() &&
693059Sgblack@eecs.umich.edu                (event->when() < curr->when() ||
703064Sgblack@eecs.umich.edu                 event->priority() <= curr->priority()))
713059Sgblack@eecs.umich.edu                break;
723064Sgblack@eecs.umich.edu
733059Sgblack@eecs.umich.edu            prev = curr;
743064Sgblack@eecs.umich.edu            curr = curr->next;
753059Sgblack@eecs.umich.edu        }
763059Sgblack@eecs.umich.edu
773059Sgblack@eecs.umich.edu        event->next = curr;
783059Sgblack@eecs.umich.edu        prev->next = event;
793059Sgblack@eecs.umich.edu    }
803059Sgblack@eecs.umich.edu}
813064Sgblack@eecs.umich.edu
823059Sgblack@eecs.umich.eduvoid
833059Sgblack@eecs.umich.eduEventQueue::remove(Event *event)
843059Sgblack@eecs.umich.edu{
853059Sgblack@eecs.umich.edu    if (head == NULL)
863059Sgblack@eecs.umich.edu        return;
873059Sgblack@eecs.umich.edu
883059Sgblack@eecs.umich.edu    if (head == event){
893059Sgblack@eecs.umich.edu        head = event->next;
903059Sgblack@eecs.umich.edu        return;
913059Sgblack@eecs.umich.edu    }
923059Sgblack@eecs.umich.edu
933064Sgblack@eecs.umich.edu    Event *prev = head;
943059Sgblack@eecs.umich.edu    Event *curr = head->next;
953059Sgblack@eecs.umich.edu    while (curr && curr != event) {
963059Sgblack@eecs.umich.edu        prev = curr;
973059Sgblack@eecs.umich.edu        curr = curr->next;
983059Sgblack@eecs.umich.edu    }
993059Sgblack@eecs.umich.edu
1003059Sgblack@eecs.umich.edu    if (curr == event)
1013059Sgblack@eecs.umich.edu        prev->next = curr->next;
1023059Sgblack@eecs.umich.edu}
1033059Sgblack@eecs.umich.edu
1043064Sgblack@eecs.umich.eduvoid
1053059Sgblack@eecs.umich.eduEventQueue::serviceOne()
1063059Sgblack@eecs.umich.edu{
1073059Sgblack@eecs.umich.edu    Event *event = head;
1083059Sgblack@eecs.umich.edu    event->clearFlags(Event::Scheduled);
1093059Sgblack@eecs.umich.edu    head = event->next;
1103059Sgblack@eecs.umich.edu
1113059Sgblack@eecs.umich.edu    // handle action
1123059Sgblack@eecs.umich.edu    if (!event->squashed())
1132973Sgblack@eecs.umich.edu        event->process();
1142973Sgblack@eecs.umich.edu    else
1151968SN/A        event->clearFlags(Event::Squashed);
1163064Sgblack@eecs.umich.edu
1171968SN/A    if (event->getFlags(Event::AutoDelete))
1181968SN/A        delete event;
1191968SN/A}
1201968SN/A
1211967SN/Avoid
1221967SN/AEventQueue::nameChildren()
1231967SN/A{
1241967SN/A#if 0
1251967SN/A    int j = 0;
1261967SN/A
1271967SN/A    Event *event = head;
1281967SN/A    while (event) {
1291967SN/A        stringstream stream;
1301967SN/A        ccprintf(stream, "%s.event%d", name(), j++);
1311904SN/A        event->setName(stream.str());
1321904SN/A
1331904SN/A        event = event->next;
1341904SN/A    }
135452SN/A#endif
1363064Sgblack@eecs.umich.edu}
1372SN/A
1381904SN/Avoid
1391904SN/AEventQueue::serialize(ostream &os)
1402SN/A{
1411904SN/A#if 0
1423064Sgblack@eecs.umich.edu    string objects = "";
1432SN/A
1442SN/A    Event *event = head;
1451904SN/A    while (event) {
1461904SN/A        objects += event->name();
1471904SN/A        objects += " ";
1482299SN/A        event->serialize(os);
1492299SN/A
1501904SN/A        event = event->next;
1511904SN/A    }
1521904SN/A    nameOut(os, "Serialized");
1531904SN/A    SERIALIZE_MEMBER(objects);
1541904SN/A#endif
1551904SN/A}
1561904SN/A
157452SN/Avoid
1581904SN/AEventQueue::dump()
1591904SN/A{
1601904SN/A    cprintf("============================================================\n");
1612SN/A    cprintf("EventQueue Dump  (cycle %d)\n", curTick);
1622SN/A    cprintf("------------------------------------------------------------\n");
1631904SN/A
1641904SN/A    if (empty())
1651904SN/A        cprintf("<No Events>\n");
1661904SN/A    else {
1671904SN/A        Event *event = head;
1681904SN/A        while (event) {
1692SN/A            event->dump();
1701904SN/A            event = event->next;
1712SN/A        }
1722SN/A    }
1731904SN/A
1742SN/A    cprintf("============================================================\n");
1751904SN/A}
1761904SN/A
1771904SN/A
1781904SN/Aconst char *
1791904SN/AEvent::description()
1801904SN/A{
1811904SN/A    return "generic";
1821904SN/A}
1831904SN/A
1841904SN/A#if TRACING_ON
1851904SN/Avoid
1861904SN/AEvent::trace(const char *action)
1871904SN/A{
1881904SN/A    // This DPRINTF is unconditional because calls to this function
1891904SN/A    // are protected by an 'if (DTRACE(Event))' in the inlined Event
1901904SN/A    // methods.
1911904SN/A    //
1921904SN/A    // This is just a default implementation for derived classes where
1931904SN/A    // it's not worth doing anything special.  If you want to put a
1941904SN/A    // more informative message in the trace, override this method on
1952525SN/A    // the particular subclass where you have the information that
1961904SN/A    // needs to be printed.
1972525SN/A    DPRINTFN("%s event %s @ %d\n", description(), action, when());
1982525SN/A}
1992525SN/A#endif
2001904SN/A
2011904SN/Avoid
2021904SN/AEvent::dump()
2031904SN/A{
2041904SN/A#if TRACING_ON
2051904SN/A    cprintf("   Created: %d\n", when_created);
2061904SN/A#endif
2071904SN/A    if (scheduled()) {
2081967SN/A#if TRACING_ON
2091967SN/A        cprintf("   Scheduled at  %d\n", when_scheduled);
2101967SN/A#endif
2111967SN/A        cprintf("   Scheduled for %d\n", when());
2121967SN/A    }
2132SN/A    else {
2142SN/A        cprintf("   Not Scheduled\n");
2152SN/A    }
2162SN/A}
2172SN/A