cpuevent.hh revision 2651
12689Sktlim@umich.edu/* 22689Sktlim@umich.edu * Copyright (c) 2006 The Regents of The University of Michigan 32689Sktlim@umich.edu * All rights reserved. 42689Sktlim@umich.edu * 52689Sktlim@umich.edu * Redistribution and use in source and binary forms, with or without 62689Sktlim@umich.edu * modification, are permitted provided that the following conditions are 72689Sktlim@umich.edu * met: redistributions of source code must retain the above copyright 82689Sktlim@umich.edu * notice, this list of conditions and the following disclaimer; 92689Sktlim@umich.edu * redistributions in binary form must reproduce the above copyright 102689Sktlim@umich.edu * notice, this list of conditions and the following disclaimer in the 112689Sktlim@umich.edu * documentation and/or other materials provided with the distribution; 122689Sktlim@umich.edu * neither the name of the copyright holders nor the names of its 132689Sktlim@umich.edu * contributors may be used to endorse or promote products derived from 142689Sktlim@umich.edu * this software without specific prior written permission. 152689Sktlim@umich.edu * 162689Sktlim@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172689Sktlim@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182689Sktlim@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192689Sktlim@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202689Sktlim@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212689Sktlim@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222689Sktlim@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232689Sktlim@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242689Sktlim@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252689Sktlim@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262689Sktlim@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272689Sktlim@umich.edu * 282689Sktlim@umich.edu * Authors: Ali Saidi 292689Sktlim@umich.edu */ 302326SN/A 312326SN/A#ifndef __CPU_CPUEVENT_HH__ 322326SN/A#define __CPU_CPUEVENT_HH__ 332326SN/A 342326SN/A#include <vector> 352326SN/A#include "sim/eventq.hh" 362348SN/A 372326SN/Aclass ExecContext; 382326SN/A 392326SN/A/** This class creates a global list of events than need a pointer to an 402326SN/A * execution context. When a switchover takes place the events can be migrated 412326SN/A * to the new execution context, otherwise you could have a wake timer interrupt 422326SN/A * go off on a switched out cpu or other unfortunate events. This object MUST be 432326SN/A * dynamically allocated to avoid it being deleted after a cpu switch happens. 442326SN/A * */ 452326SN/Aclass CpuEvent : public Event 462326SN/A{ 472326SN/A private: 482326SN/A /** type of global list of cpu events. */ 492326SN/A typedef std::vector<CpuEvent *> CpuEventList; 502326SN/A 512348SN/A /** Static list of cpu events that is searched every time a cpu switch 522348SN/A * happens. */ 532348SN/A static CpuEventList cpuEventList; 542348SN/A 552348SN/A /** The execution context that is switched to the new cpus. */ 562348SN/A ExecContext *xc; 572348SN/A 582348SN/A public: 592348SN/A CpuEvent(EventQueue *q, ExecContext *_xc, Priority p = Default_Pri) 602326SN/A : Event(q, p), xc(_xc) 612326SN/A { cpuEventList.push_back(this); } 622326SN/A 632326SN/A /** delete the cpu event from the global list. */ 642326SN/A ~CpuEvent(); 652326SN/A 662348SN/A /** Update all events switching old xc to new xc. 672326SN/A * @param oldXc the old exeuction context we are switching from 682326SN/A * @param newXc the new execution context we are switching to. 692326SN/A */ 702326SN/A static void replaceExecContext(ExecContext *oldXc, ExecContext *newXc); 712734Sktlim@umich.edu}; 722734Sktlim@umich.edu 732348SN/Atemplate <class T, void (T::* F)(ExecContext *xc)> 742326SN/Aclass CpuEventWrapper : public CpuEvent 752326SN/A{ 762348SN/A private: 772326SN/A T *object; 782326SN/A 792348SN/A public: 802326SN/A CpuEventWrapper(T *obj, ExecContext *_xc, EventQueue *q = &mainEventQueue, 812326SN/A Priority p = Default_Pri) 822348SN/A : CpuEvent(q, _xc, p), object(obj) 832326SN/A { } 842326SN/A void process() { (object->*F)(xc); } 852326SN/A}; 862348SN/A 872326SN/A#endif // __CPU_CPUEVENT_HH__ 882326SN/A 892326SN/A