| | 40 | */ |
|---|
| | 41 | |
|---|
| | 42 | /** @note |
|---|
| | 43 | * |
|---|
| | 44 | * Some remarks about __volatile__: Without this keyword gcc is allowed to reorder |
|---|
| | 45 | * or even optimize assembler instructions away. For instance, in the following code |
|---|
| | 46 | * the second rdmsr instruction is optimized away because gcc treats that instruction |
|---|
| | 47 | * as deterministic: |
|---|
| | 48 | * |
|---|
| | 49 | * @code |
|---|
| | 50 | * static inline uint64_t rdmsr_low(idx) |
|---|
| | 51 | * { |
|---|
| | 52 | * uint32_t low; |
|---|
| | 53 | * __asm__ ("rdmsr" : "=a"(low) : "c"(idx) : "edx"); |
|---|
| | 54 | * } |
|---|
| | 55 | * ... |
|---|
| | 56 | * uint32_t msr1 = rdmsr(1); |
|---|
| | 57 | * foo(msr1); |
|---|
| | 58 | * msr1 = rdmsr(1); |
|---|
| | 59 | * bar(msr1); |
|---|
| | 60 | * @endcode |
|---|
| | 61 | * |
|---|
| | 62 | * The input parameter of rdmsr_low is the same for both calls and therefore gcc will |
|---|
| | 63 | * use the result of the first call as input parameter for bar() as well. For rdmsr this |
|---|
| | 64 | * is not acceptable as this instruction is _not_ deterministic. This applies to reading |
|---|
| | 65 | * machine status information in general. |
|---|