This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:multiasm:paarm:chapter_5_15 [2025/12/04 23:01] – [Conditional instructions] eriks.klavins | en:multiasm:paarm:chapter_5_15 [2025/12/04 23:12] (current) – [Power saving] eriks.klavins | ||
|---|---|---|---|
| Line 94: | Line 94: | ||
| Other conditional instructions can be used similarly: | Other conditional instructions can be used similarly: | ||
| + | {{: | ||
| These conditional instructions are helpful in branchless conditional checks. Taking into account that these instructions can also be executed speculatively, | These conditional instructions are helpful in branchless conditional checks. Taking into account that these instructions can also be executed speculatively, | ||
| ===== Power saving ===== | ===== Power saving ===== | ||
| + | |||
| + | Some special instructions are meant to put the processor into sleep modes and wait for an event to occur. The processor can be woken up by an interrupt or by an event. In these modes, the code may be explicitly created to initialise interrupts and events, and to handle them. After that, the processor may be put into sleep mode and remain asleep unless an event or interrupt occurs. The following code example can be used only in bare-metal mode – without an OS. | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | .global idle_loop | ||
| + | idle_loop: | ||
| + | 1: WFI @ Wait For Interrupt, core goes to low-power | ||
| + | B | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | The example only waits for interrupts to occur. To wait for events and interrupts, the ''< | ||
| + | |||
| + | On a Raspberry Pi 5 running Linux, it is not observable whether the CPU enters these modes, because the OS generates many events between CPU cores and also handles many interrupts from communication interfaces and other Raspberry Pi components. | ||
| + | Another way to save more energy while running the OS on the Raspberry Pi is to reduce the CPU clock frequency. There is a scheme called dynamic voltage and frequency scaling (DVFS), the same technique used in laptops, that reduces power consumption and thereby increases battery life. On the internet, there is a paper named “Cooling a Raspberry Pi Device ”. The paper includes one chapter explaining how to reduce the CPU clock frequency. The Linux OS exposes CPU frequency scaling through sysfs, e.g.: | ||
| + | * ”/ | ||
| + | * “/ | ||
| + | |||
| + | It is possible to use syscalls in assembler to open and write specific values into them. | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | .global _start | ||
| + | .section .text | ||
| + | _start: | ||
| + | @ openat(AT_FDCWD, | ||
| + | mov x0, #-100 @ AT_FDCWD | ||
| + | ldr x1, =gov_path | ||
| + | mov x2, #1 @ O_WRONLY | ||
| + | mov x3, #0 @ mode (unused) | ||
| + | mov x8, #56 @ sys_openat | ||
| + | svc #0 | ||
| + | mov x19, x0 @ save fd | ||
| + | |||
| + | @ write(fd, " | ||
| + | mov x0, x19 | ||
| + | ldr x1, =gov_value | ||
| + | mov x2, #10 @ length of " | ||
| + | mov x8, #64 @ sys_write | ||
| + | svc #0 | ||
| + | |||
| + | @ close(fd) | ||
| + | mov x0, x19 | ||
| + | mov x8, #57 @ sys_close | ||
| + | svc #0 | ||
| + | |||
| + | @ exit(0) | ||
| + | mov x0, #0 | ||
| + | mov x8, #93 @ sys_exit | ||
| + | svc #0 | ||
| + | |||
| + | .section .rodata | ||
| + | gov_path: | ||
| + | .asciz "/ | ||
| + | gov_value: | ||
| + | .asciz " | ||
| + | </ | ||
| + | </ | ||
| + | Similar things can be done with CPU frequencies, | ||
| + | |||