19356Snilay@cs.wisc.edu/* 29356Snilay@cs.wisc.edu * Copyright (c) 2012 The Regents of The University of Michigan 39983Sstever@gmail.com * Copyright (c) 2012-2013 Mark D. Hill and David A. Wood 49983Sstever@gmail.com * Copyright (c) 2013 Advanced Micro Devices, Inc. 59356Snilay@cs.wisc.edu * All rights reserved. 69356Snilay@cs.wisc.edu * 79356Snilay@cs.wisc.edu * Redistribution and use in source and binary forms, with or without 89356Snilay@cs.wisc.edu * modification, are permitted provided that the following conditions are 99356Snilay@cs.wisc.edu * met: redistributions of source code must retain the above copyright 109356Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer; 119356Snilay@cs.wisc.edu * redistributions in binary form must reproduce the above copyright 129356Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer in the 139356Snilay@cs.wisc.edu * documentation and/or other materials provided with the distribution; 149356Snilay@cs.wisc.edu * neither the name of the copyright holders nor the names of its 159356Snilay@cs.wisc.edu * contributors may be used to endorse or promote products derived from 169356Snilay@cs.wisc.edu * this software without specific prior written permission. 179356Snilay@cs.wisc.edu * 189356Snilay@cs.wisc.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 199356Snilay@cs.wisc.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 209356Snilay@cs.wisc.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 219356Snilay@cs.wisc.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 229356Snilay@cs.wisc.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 239356Snilay@cs.wisc.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 249356Snilay@cs.wisc.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 259356Snilay@cs.wisc.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 269356Snilay@cs.wisc.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 279356Snilay@cs.wisc.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 289356Snilay@cs.wisc.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 299356Snilay@cs.wisc.edu * 309356Snilay@cs.wisc.edu * Authors: Steve Reinhardt 319356Snilay@cs.wisc.edu * Nathan Binkert 329356Snilay@cs.wisc.edu * Nilay Vaish 339356Snilay@cs.wisc.edu */ 349356Snilay@cs.wisc.edu 359356Snilay@cs.wisc.edu#ifndef __SIM_EVENTQ_IMPL_HH__ 369356Snilay@cs.wisc.edu#define __SIM_EVENTQ_IMPL_HH__ 379356Snilay@cs.wisc.edu 389356Snilay@cs.wisc.edu#include "base/trace.hh" 399356Snilay@cs.wisc.edu#include "sim/eventq.hh" 409356Snilay@cs.wisc.edu 419356Snilay@cs.wisc.eduinline void 429983Sstever@gmail.comEventQueue::schedule(Event *event, Tick when, bool global) 439356Snilay@cs.wisc.edu{ 449356Snilay@cs.wisc.edu assert(when >= getCurTick()); 459356Snilay@cs.wisc.edu assert(!event->scheduled()); 469356Snilay@cs.wisc.edu assert(event->initialized()); 479356Snilay@cs.wisc.edu 489356Snilay@cs.wisc.edu event->setWhen(when, this); 499983Sstever@gmail.com 509983Sstever@gmail.com // The check below is to make sure of two things 519983Sstever@gmail.com // a. a thread schedules local events on other queues through the asyncq 529983Sstever@gmail.com // b. a thread schedules global events on the asyncq, whether or not 539983Sstever@gmail.com // this event belongs to this eventq. This is required to maintain 549983Sstever@gmail.com // a total order amongst the global events. See global_event.{cc,hh} 559983Sstever@gmail.com // for more explanation. 569983Sstever@gmail.com if (inParallelMode && (this != curEventQueue() || global)) { 579983Sstever@gmail.com asyncInsert(event); 589983Sstever@gmail.com } else { 599983Sstever@gmail.com insert(event); 609983Sstever@gmail.com } 619356Snilay@cs.wisc.edu event->flags.set(Event::Scheduled); 6212040Sandreas.sandberg@arm.com event->acquire(); 639356Snilay@cs.wisc.edu 649356Snilay@cs.wisc.edu if (DTRACE(Event)) 659356Snilay@cs.wisc.edu event->trace("scheduled"); 669356Snilay@cs.wisc.edu} 679356Snilay@cs.wisc.edu 689356Snilay@cs.wisc.eduinline void 699356Snilay@cs.wisc.eduEventQueue::deschedule(Event *event) 709356Snilay@cs.wisc.edu{ 719356Snilay@cs.wisc.edu assert(event->scheduled()); 729356Snilay@cs.wisc.edu assert(event->initialized()); 739983Sstever@gmail.com assert(!inParallelMode || this == curEventQueue()); 749356Snilay@cs.wisc.edu 759356Snilay@cs.wisc.edu remove(event); 769356Snilay@cs.wisc.edu 779356Snilay@cs.wisc.edu event->flags.clear(Event::Squashed); 789356Snilay@cs.wisc.edu event->flags.clear(Event::Scheduled); 799356Snilay@cs.wisc.edu 809356Snilay@cs.wisc.edu if (DTRACE(Event)) 819356Snilay@cs.wisc.edu event->trace("descheduled"); 829356Snilay@cs.wisc.edu 8312040Sandreas.sandberg@arm.com event->release(); 849356Snilay@cs.wisc.edu} 859356Snilay@cs.wisc.edu 869356Snilay@cs.wisc.eduinline void 879356Snilay@cs.wisc.eduEventQueue::reschedule(Event *event, Tick when, bool always) 889356Snilay@cs.wisc.edu{ 899356Snilay@cs.wisc.edu assert(when >= getCurTick()); 909356Snilay@cs.wisc.edu assert(always || event->scheduled()); 919356Snilay@cs.wisc.edu assert(event->initialized()); 929983Sstever@gmail.com assert(!inParallelMode || this == curEventQueue()); 939356Snilay@cs.wisc.edu 9412040Sandreas.sandberg@arm.com if (event->scheduled()) { 959356Snilay@cs.wisc.edu remove(event); 9612040Sandreas.sandberg@arm.com } else { 9712040Sandreas.sandberg@arm.com event->acquire(); 9812040Sandreas.sandberg@arm.com } 999356Snilay@cs.wisc.edu 1009356Snilay@cs.wisc.edu event->setWhen(when, this); 1019356Snilay@cs.wisc.edu insert(event); 1029356Snilay@cs.wisc.edu event->flags.clear(Event::Squashed); 1039356Snilay@cs.wisc.edu event->flags.set(Event::Scheduled); 1049356Snilay@cs.wisc.edu 1059356Snilay@cs.wisc.edu if (DTRACE(Event)) 1069356Snilay@cs.wisc.edu event->trace("rescheduled"); 1079356Snilay@cs.wisc.edu} 1089356Snilay@cs.wisc.edu 1099356Snilay@cs.wisc.edu#endif // __SIM_EVENTQ_IMPL_HH__ 110