Ali Saidi | c0cf76c | 2006-05-29 18:24:27 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006 The Regents of The University of Michigan |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are |
| 7 | * met: redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer; |
| 9 | * redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution; |
| 12 | * neither the name of the copyright holders nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived from |
| 14 | * this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | * |
| 28 | * Authors: Ali Saidi |
| 29 | */ |
| 30 | |
| 31 | #ifndef __CPU_CPUEVENT_HH__ |
| 32 | #define __CPU_CPUEVENT_HH__ |
| 33 | |
| 34 | #include <vector> |
Nathan Binkert | 39a0556 | 2011-04-15 10:44:06 -0700 | [diff] [blame] | 35 | |
Ali Saidi | c0cf76c | 2006-05-29 18:24:27 -0400 | [diff] [blame] | 36 | #include "sim/eventq.hh" |
| 37 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 38 | class ThreadContext; |
Ali Saidi | c0cf76c | 2006-05-29 18:24:27 -0400 | [diff] [blame] | 39 | |
Nathan Binkert | e9a395c | 2007-01-03 10:13:45 -0800 | [diff] [blame] | 40 | /** |
| 41 | * This class creates a global list of events that need a pointer to a |
| 42 | * thread context. When a switchover takes place the events can be |
| 43 | * migrated to the new thread context, otherwise you could have a wake |
| 44 | * timer interrupt go off on a switched out cpu or other unfortunate |
| 45 | * events. This object MUST be dynamically allocated to avoid it being |
| 46 | * deleted after a cpu switch happens. |
| 47 | */ |
Ali Saidi | c0cf76c | 2006-05-29 18:24:27 -0400 | [diff] [blame] | 48 | class CpuEvent : public Event |
| 49 | { |
Gabe Black | 4a5cb3f | 2006-11-03 11:05:56 -0500 | [diff] [blame] | 50 | protected: |
Ali Saidi | c0cf76c | 2006-05-29 18:24:27 -0400 | [diff] [blame] | 51 | /** type of global list of cpu events. */ |
| 52 | typedef std::vector<CpuEvent *> CpuEventList; |
| 53 | |
| 54 | /** Static list of cpu events that is searched every time a cpu switch |
| 55 | * happens. */ |
| 56 | static CpuEventList cpuEventList; |
| 57 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 58 | /** The thread context that is switched to the new cpus. */ |
| 59 | ThreadContext *tc; |
Ali Saidi | c0cf76c | 2006-05-29 18:24:27 -0400 | [diff] [blame] | 60 | |
| 61 | public: |
Nathan Binkert | e063210 | 2008-10-09 04:58:24 -0700 | [diff] [blame] | 62 | CpuEvent(ThreadContext *_tc, Priority p = Default_Pri) |
| 63 | : Event(p), tc(_tc) |
Ali Saidi | c0cf76c | 2006-05-29 18:24:27 -0400 | [diff] [blame] | 64 | { cpuEventList.push_back(this); } |
| 65 | |
| 66 | /** delete the cpu event from the global list. */ |
| 67 | ~CpuEvent(); |
| 68 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 69 | /** Update all events switching old tc to new tc. |
| 70 | * @param oldTc the old thread context we are switching from |
| 71 | * @param newTc the new thread context we are switching to. |
Ali Saidi | c0cf76c | 2006-05-29 18:24:27 -0400 | [diff] [blame] | 72 | */ |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 73 | static void replaceThreadContext(ThreadContext *oldTc, |
| 74 | ThreadContext *newTc); |
Ali Saidi | fc79ace | 2007-01-30 18:25:39 -0500 | [diff] [blame] | 75 | ThreadContext* getTC() { return tc; } |
Ali Saidi | c0cf76c | 2006-05-29 18:24:27 -0400 | [diff] [blame] | 76 | }; |
| 77 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 78 | template <class T, void (T::* F)(ThreadContext *tc)> |
Ali Saidi | c0cf76c | 2006-05-29 18:24:27 -0400 | [diff] [blame] | 79 | class CpuEventWrapper : public CpuEvent |
| 80 | { |
| 81 | private: |
| 82 | T *object; |
| 83 | |
| 84 | public: |
Nathan Binkert | e063210 | 2008-10-09 04:58:24 -0700 | [diff] [blame] | 85 | CpuEventWrapper(T *obj, ThreadContext *_tc, Priority p = Default_Pri) |
| 86 | : CpuEvent(_tc, p), object(obj) |
Ali Saidi | c0cf76c | 2006-05-29 18:24:27 -0400 | [diff] [blame] | 87 | { } |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 88 | void process() { (object->*F)(tc); } |
Ali Saidi | c0cf76c | 2006-05-29 18:24:27 -0400 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | #endif // __CPU_CPUEVENT_HH__ |
| 92 | |