Is hlt reduces CPU power consumption?
Is hlt reduces CPU power consumption?
When hlt command is executed by CPI, is it reduces power consumption?
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
- BrightLight
- Member
- Posts: 901
- Joined: Sat Dec 27, 2014 9:11 am
- Location: Maadi, Cairo, Egypt
- Contact:
Re: Is hlt reduces CPU power consumption?
Yes. HLT opcode tells the CPU that it can "take a break" until an IRQ occurs. So, it cools down the CPU and reduces power consumption.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
Re: Is hlt reduces CPU power consumption?
You should also consider using PAUSE.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
Re: Is hlt reduces CPU power consumption?
sorry for digging this old thread.
but can i use PAUSE instead of HLT as similar ways, to reduce/disable power consumption of the cores? its irrelevant if its yielded at NOP on earlyer cpus, since those will eat the energy aniway, but on newer ones, the energy can be saved.
i want to disable the cores if they dont have jobs to do (SMP) and i dont want to mess with interrupts to awake from HLT.
or the PAUSE will only save very small amouts of electricity compared to HLT, and i must trick that somehow to work?
but can i use PAUSE instead of HLT as similar ways, to reduce/disable power consumption of the cores? its irrelevant if its yielded at NOP on earlyer cpus, since those will eat the energy aniway, but on newer ones, the energy can be saved.
i want to disable the cores if they dont have jobs to do (SMP) and i dont want to mess with interrupts to awake from HLT.
or the PAUSE will only save very small amouts of electricity compared to HLT, and i must trick that somehow to work?
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
http://users.atw.hu/gerigeri/DawnOS/download.html
Re: Is hlt reduces CPU power consumption?
Hi,
Cheers,
Brendan
In theory, PAUSE might make a tiny difference, but not much and it would depend a lot on a large number of things.Geri wrote:but can i use PAUSE instead of HLT as similar ways, to reduce/disable power consumption of the cores?
For this, you'd want to consider MONITOR and MWAIT - it's designed for things like "wait until some other CPU adds a job to the scheduler's queue".Geri wrote: its irrelevant if its yielded at NOP on earlyer cpus, since those will eat the energy aniway, but on newer ones, the energy can be saved.
i want to disable the cores if they dont have jobs to do (SMP) and i dont want to mess with interrupts to awake from HLT.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: Is hlt reduces CPU power consumption?
IIRC in practice the main thing that happens is that the hardware thread gets less dispatch cycles in a hyperthreading configuration.Brendan wrote:In theory, PAUSE might make a tiny difference, but not much and it would depend a lot on a large number of things.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
Re: Is hlt reduces CPU power consumption?
Hi,
Note that "CPU is free to ignore it" is something Intel considered important when they created it - it's the reason they recycled "rep nop" and made sure it "worked" (was correctly ignored) on all their older CPUs.
Cheers,
Brendan
I like to think of it as a kind of "speculative execution barrier" (to wait for a logical CPU's in-flight instructions to retire before starting more instructions from that logical CPU); but it's only a hint and a CPU is free to do whatever it wants (including ignoring it completely).Korona wrote:IIRC in practice the main thing that happens is that the hardware thread gets less dispatch cycles in a hyperthreading configuration.Brendan wrote:In theory, PAUSE might make a tiny difference, but not much and it would depend a lot on a large number of things.
Note that "CPU is free to ignore it" is something Intel considered important when they created it - it's the reason they recycled "rep nop" and made sure it "worked" (was correctly ignored) on all their older CPUs.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: Is hlt reduces CPU power consumption?
The only purpose of PAUSE is to prevent the other thread in a core from being starved of resources during a spinlock, isn't it? I doubt it yields any gains in terms of power consumption at all.
Re: Is hlt reduces CPU power consumption?
Hi,
For power consumption; the right tool for the job is MONITOR/MWAIT - it does put the CPU into a power saving state (similar to HLT), and it also avoids the problems of "many iterations of the loop in progress" (similar to PAUSE).
Cheers,
Brendan
PAUSE can also help to improve "spin loop exit" performance. For example, (without PAUSE) if you're spinning until a variable changes the CPU can have many iterations of the loop "in progress" (hurting performance for other CPUs sharing the core) and when the variable does change there's many iterations of the loop that need to be cleared out before the CPU can exit the loop properly (hurting "spin loop exit" performance).Sik wrote:The only purpose of PAUSE is to prevent the other thread in a core from being starved of resources during a spinlock, isn't it? I doubt it yields any gains in terms of power consumption at all.
For power consumption; the right tool for the job is MONITOR/MWAIT - it does put the CPU into a power saving state (similar to HLT), and it also avoids the problems of "many iterations of the loop in progress" (similar to PAUSE).
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: Is hlt reduces CPU power consumption?
yes, it seems one pause will not decrase the power consumption notably. i tested on a desktop athlon2 x4, and it didnt really made any difference. maybe adding more will do more consumption decrase, i will test that later.
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
http://users.atw.hu/gerigeri/DawnOS/download.html