Skip to content

Commit ddde02d

Browse files
x86/inst: add explanation for nop
minor fix for mm. Signed-off-by: Leon <[email protected]>
1 parent bad51f5 commit ddde02d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

arch/intel/instruction.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# NOP
2+
* 清除由上一个算术逻辑指令设置的 flag 位
3+
* 1 字节 `nop` 指令是 `XCHG (E)AX, (E)AX` 的别名助记词
4+
* 2~9 字节的 `nop` 指令见 SDM Vol.2
5+
* 从软件上来说,`nop` 的两种应用场景
6+
* 制造错误
7+
* 辅助编程
8+
* 硬件上来看,用 `nop` 的目的主要是 *占位**对齐*
9+
* 占位是为了方便软件编写
10+
* 对齐是为了提升译码效率(部分 CPU)
11+
* 但是 `nop` 本身也需要被执行,因此会降低 CPU 的有效执行效率
12+
* 设计上, `nop` 作为一条有效的指令是需要完成整个 CPU 流水线过程的。它需要 Decode,Dispatch,Execution,Retire。执行它的单元一般是 ALU, 但是它不改变任何 ARF 的值. 所以 `nop` 的出现会影响 CPU 效率
13+
* 但是现代 CPU 已经有良好的乱序处理能力,并不需要人为使用 `nop` 来打断流水线
14+
15+
# References
16+
- [NOP指令会打断CPU流水线吗?](https://www.zhihu.com/question/21122634/answer/22763700)

kernel/mm/mm.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ Process context, cannot sleep | Use `GFP_ATOMIC`, or perform your allocations wi
332332
Interrupt handler | Use `GFP_ATOMIC`.
333333
Softirq | Use `GFP_ATOMIC`.
334334
Tasklet | Use `GFP_ATOMIC`.
335-
Need DMA-able memory, can sleep | Use `(GFP_DMA | GFP_KERNEL)`.
336-
Need DMA-able memory, cannot sleep | Use `(GFP_DMA | GFP_ATOMIC)`, or perform your allocation at an earlier point when you can sleep.
335+
Need DMA-able memory, can sleep | Use `(GFP_DMA \| GFP_KERNEL)`.
336+
Need DMA-able memory, cannot sleep | Use `(GFP_DMA \| GFP_ATOMIC)`, or perform your allocation at an earlier point when you can sleep.
337337

338338
## kfree()
339339
* `kfree()`释放`kmalloc()`分配出来的内存块

0 commit comments

Comments
 (0)