0

I am reading Linux Kernel Development 3rd edition by Robert Love,

On Ordering & Barriers, I read that:

smp_rmb() Provides an rmb() on SMP, and on UP provides a barrier()

I do not understand why UP version only does a barrier() which just forbids rearranging on compile.

Does single core x86 processors not do Out-of-order execution?

hoholee12
  • 334
  • 3
  • 14
  • "Does single core x86 processors not do Out-of-order execution?" - A core uses out-of-order execution. But the core itself "**sees**" that execution **in-order**. Memory barrier helps **other** CPUs to properly observe that order. But since on UP you don't have other CPU, then you don't need a memory barrier. – Tsyvarev Jan 18 '21 at 09:30
  • @Tsyvarev "core itself sees that execution in-order" I am unable to understand what this exactly means? This is too abstract... – hoholee12 Jan 18 '21 at 10:42
  • @Tsyvarev The second paragraph on the second answer definitely seems like what I was looking for. Anyways thanks again! – hoholee12 Jan 18 '21 at 10:49
  • As for "core itself sees that execution in-order". Imagine you are the CPU core and you need to execute a program containing 4 instructions: 1. Store 10 into variable `A`. 2. Store 20 into variable `B`. 3. Load from `B`. 4. Load from `A`. Assume, you **reorder** instructions for execute into 2-3-4-1. As instruction 2 is executed before 3, the instruction 3 would return 20. Good. But when you execute instruction 4 ("Load from `A`") you **remember**: in the instruction 1 you should store 10 into `A`. So, despite you haven't executed instruction 1 yet, you return 10 as a result of instruction 4. – Tsyvarev Jan 18 '21 at 11:37

0 Answers0