sim: ScopedMigration does nothing if both eqs are the same

Added a check to avoid unlocking/locking the same event queue. Also,
added an optional parameter to enable the migration to be skipped. This
can be useful to disable the synchronization for certain runtime
conditions.

Change-Id: I4b03b3ffff4f9503153cd41dd8aa78705bf16cc4
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/5730
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
This commit is contained in:
Tiago Muck
2017-09-08 12:24:42 -05:00
committed by Andreas Sandberg
parent 9b4e797cdd
commit 1033838e11

View File

@@ -542,28 +542,36 @@ class EventQueue
* example, be useful when performing IO across thread event * example, be useful when performing IO across thread event
* queues when timing is not crucial (e.g., during fast * queues when timing is not crucial (e.g., during fast
* forwarding). * forwarding).
*
* ScopedMigration does nothing if both eqs are the same
*/ */
class ScopedMigration class ScopedMigration
{ {
public: public:
ScopedMigration(EventQueue *_new_eq) ScopedMigration(EventQueue *_new_eq, bool _doMigrate = true)
: new_eq(*_new_eq), old_eq(*curEventQueue()) :new_eq(*_new_eq), old_eq(*curEventQueue()),
doMigrate((&new_eq != &old_eq)&&_doMigrate)
{ {
old_eq.unlock(); if (doMigrate){
new_eq.lock(); old_eq.unlock();
curEventQueue(&new_eq); new_eq.lock();
curEventQueue(&new_eq);
}
} }
~ScopedMigration() ~ScopedMigration()
{ {
new_eq.unlock(); if (doMigrate){
old_eq.lock(); new_eq.unlock();
curEventQueue(&old_eq); old_eq.lock();
curEventQueue(&old_eq);
}
} }
private: private:
EventQueue &new_eq; EventQueue &new_eq;
EventQueue &old_eq; EventQueue &old_eq;
bool doMigrate;
}; };
/** /**