fault_injector_random.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "fault_injector_random.h"
  2. #include "rng.h"
  3. FaultInjectorRandom::FaultInjectorRandom(UInt32 core_id, MemComponent::component_t mem_component)
  4. : FaultInjector(core_id, mem_component)
  5. , m_rng(rng_seed(0))
  6. {
  7. if (mem_component == MemComponent::L1_DCACHE)
  8. m_active = true;
  9. else
  10. m_active = false;
  11. }
  12. void
  13. FaultInjectorRandom::preRead(IntPtr addr, IntPtr location, UInt32 data_size, Byte *fault, SubsecondTime time)
  14. {
  15. // Data at virtual address <addr> is about to be read with size <data_size>.
  16. // <location> corresponds to the physical location (cache line) where the data lives.
  17. // Update <fault> here according to errors that have accumulated in this memory location.
  18. // Dummy random fault injector
  19. if (m_active && (rng_next(m_rng) % 0xffff) == 0)
  20. {
  21. UInt32 bit_location = rng_next(m_rng) % data_size;
  22. printf("Inserting bit %d flip at address %" PRIxPTR " on read access by core %d to component %s\n",
  23. bit_location, addr, m_core_id, MemComponentString(m_mem_component));
  24. fault[bit_location / 8] |= 1 << (bit_location % 8);
  25. }
  26. }
  27. void
  28. FaultInjectorRandom::postWrite(IntPtr addr, IntPtr location, UInt32 data_size, Byte *fault, SubsecondTime time)
  29. {
  30. // Data at virtual address <addr> has just been written to.
  31. // Update <fault> here according to errors that occured during the writing of this memory location.
  32. }