Skip to content

File retire_reporter.h

File List > common > retire_reporter.h

Go to the documentation of this file

#pragma once

#include <simtix/clocked.h>

#include <vector>

#include "sm/instr_ptr.h"

namespace simtix {

namespace trace {

// Class: trace::KonataRetireReporter
//   This class accepts the information of retired (or flushed) instructions and
//   output the corresponding Konata log in the next cycle.
class KonataRetireReporter : public sim::Clocked {
 public:
  struct InstrRetire {
    uint64_t unique_id;
    uint64_t retire_id;
    bool flushed;
  };

  // Cannot be copied.
  KonataRetireReporter(const KonataRetireReporter &) = delete;
  KonataRetireReporter &operator=(const KonataRetireReporter &) = delete;

  // Function: Flush
  //   A unified entry to flush the Konata log of retired instructions right
  //   away.
  static void Flush() { GetInstance().flush_(); }

 private:
  KonataRetireReporter()
      : Clocked("KonataRetireReporter", sim::kTraceTickPri) {}

  ~KonataRetireReporter() = default;

  void Tick() override { flush_(); }

  bool HasPendingTasks() override { return !retire_list_.empty(); }

  void flush_();

  static void Push(uint64_t unique_id, uint64_t retire_id, bool flushed);

  static KonataRetireReporter &GetInstance() {
    static KonataRetireReporter reporter;
    return reporter;
  }

  std::vector<InstrRetire> retire_list_;

  // Make InstrPtr as friend so that it can access the private Push function.
  friend class simtix::InstrPtr;
};

}  // namespace trace

}  // namespace simtix