diff mbox

[RFC,03/10] core/test: make cpu.h usable in tests

Message ID 1482298544-8418-4-git-send-email-oohall@gmail.com
State RFC
Headers show

Commit Message

Oliver O'Halloran Dec. 21, 2016, 5:35 a.m. UTC
Adds an #ifdef around this_cpu() so that it can be used inside test
code and fakes out the inline assembly used for barrier instructions
and setting the SMT priorities.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 include/cpu.h       |  5 +++++
 include/processor.h | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+)
diff mbox

Patch

diff --git a/include/cpu.h b/include/cpu.h
index f649a13e6231..eb9551405742 100644
--- a/include/cpu.h
+++ b/include/cpu.h
@@ -189,7 +189,12 @@  extern u8 get_available_nr_cores_in_chip(u32 chip_id);
 		core = next_available_core_in_chip(core, chip_id))
 
 /* Return the caller CPU (only after init_cpu_threads) */
+#ifndef __TEST__
 register struct cpu_thread *__this_cpu asm("r13");
+#else
+static struct cpu_thread fake_cpu;
+static struct cpu_thread *__this_cpu = &fake_cpu;
+#endif
 static inline __nomcount struct cpu_thread *this_cpu(void)
 {
 	return __this_cpu;
diff --git a/include/processor.h b/include/processor.h
index 3942268a114a..5d20ffb56dbd 100644
--- a/include/processor.h
+++ b/include/processor.h
@@ -200,6 +200,8 @@ 
 
 #else /* __ASSEMBLY__ */
 
+#ifndef __TEST__
+
 #include <compiler.h>
 #include <stdint.h>
 
@@ -318,6 +320,23 @@  static inline void st_le32(uint32_t *addr, uint32_t val)
 	asm volatile("stwbrx %0,0,%1" : : "r"(val), "r"(addr), "m"(*addr));
 }
 
+#else  /* __TEST__ */
+
+#define smt_low()
+#define smt_medium()
+#define smt_high()
+#define smt_medium_high()
+#define smt_medium_low()
+#define smt_extra_high()
+#define smt_very_low()
+
+#define eieio()
+#define sync()
+#define lwsync()
+#define isync()
+
+#endif /* __TEST__ */
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __PROCESSOR_H */