Page 1 of 1

Is hlt reduces CPU power consumption?

Posted: Tue Feb 09, 2016 9:23 am
by osdever
When hlt command is executed by CPI, is it reduces power consumption?

Re: Is hlt reduces CPU power consumption?

Posted: Tue Feb 09, 2016 11:48 am
by BrightLight
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.

Re: Is hlt reduces CPU power consumption?

Posted: Wed Feb 10, 2016 12:24 am
by Roman
You should also consider using PAUSE.

Re: Is hlt reduces CPU power consumption?

Posted: Sat Apr 15, 2017 11:28 am
by Geri
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?

Re: Is hlt reduces CPU power consumption?

Posted: Sat Apr 15, 2017 11:52 am
by Brendan
Hi,
Geri wrote:but can i use PAUSE instead of HLT as similar ways, to reduce/disable power consumption of the cores?
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: 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.
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".


Cheers,

Brendan

Re: Is hlt reduces CPU power consumption?

Posted: Sun Apr 16, 2017 3:42 am
by Korona
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.
IIRC in practice the main thing that happens is that the hardware thread gets less dispatch cycles in a hyperthreading configuration.

Re: Is hlt reduces CPU power consumption?

Posted: Sun Apr 16, 2017 1:01 pm
by Brendan
Hi,
Korona wrote:
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.
IIRC in practice the main thing that happens is that the hardware thread gets less dispatch cycles in a hyperthreading configuration.
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).

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

Re: Is hlt reduces CPU power consumption?

Posted: Sun Apr 16, 2017 1:30 pm
by Sik
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?

Posted: Sun Apr 16, 2017 3:41 pm
by Brendan
Hi,
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.
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).

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

Re: Is hlt reduces CPU power consumption?

Posted: Sun Apr 16, 2017 7:06 pm
by Geri
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.