spin_loop_detector.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef __SPIN_LOOP_DETECTOR_H
  2. #define __SPIN_LOOP_DETECTOR_H
  3. #include "fixed_types.h"
  4. #include "thread.h"
  5. #include <unordered_map>
  6. #include <deque>
  7. class SpinLoopDetector
  8. {
  9. private:
  10. static const size_t SDT_MAX_SIZE = 16;
  11. typedef uint16_t reg_t; // Pin's REG enum
  12. typedef std::pair<uint64_t, uint16_t> RubEntry;
  13. typedef std::unordered_map<reg_t, RubEntry> Rub;
  14. struct SdtEntry
  15. {
  16. SdtEntry(uint64_t _eip, uint8_t _id, uint64_t _icount, SubsecondTime _tcount) : eip(_eip), id(_id), icount(_icount), tcount(_tcount) {}
  17. uint64_t eip;
  18. uint8_t id;
  19. uint64_t icount;
  20. SubsecondTime tcount;
  21. };
  22. typedef std::deque<SdtEntry> Sdt;
  23. const Thread *m_thread;
  24. Rub m_rub; // Register Update Buffer
  25. Sdt m_sdt; // Spin Detection Table
  26. uint16_t m_sdt_bitmask; // Bitmask of all valid SDT entries
  27. uint8_t m_sdt_nextid;
  28. public:
  29. SpinLoopDetector(Thread *thread) : m_thread(thread), m_rub(), m_sdt(), m_sdt_bitmask(0), m_sdt_nextid(0) {}
  30. void commitBCT(uint64_t eip);
  31. void commitNonSilentStore();
  32. void commitRegisterWrite(reg_t reg, uint64_t old_value, uint64_t value);
  33. bool inCandidateSpin() { return !m_sdt.empty(); }
  34. };
  35. #endif // __SPIN_LOOP_DETECTOR_H