Is hlt reduces CPU power consumption?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
osdever
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am
Contact:

Is hlt reduces CPU power consumption?

Post by osdever »

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.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Is hlt reduces CPU power consumption?

Post 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.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Is hlt reduces CPU power consumption?

Post by Roman »

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
User avatar
Geri
Member
Member
Posts: 442
Joined: Sun Jul 14, 2013 6:01 pm

Re: Is hlt reduces CPU power consumption?

Post 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?
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Is hlt reduces CPU power consumption?

Post 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
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.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Is hlt reduces CPU power consumption?

Post 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.
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].
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Is hlt reduces CPU power consumption?

Post 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
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.
User avatar
Sik
Member
Member
Posts: 251
Joined: Wed Aug 17, 2016 4:55 am

Re: Is hlt reduces CPU power consumption?

Post 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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Is hlt reduces CPU power consumption?

Post 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
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.
User avatar
Geri
Member
Member
Posts: 442
Joined: Sun Jul 14, 2013 6:01 pm

Re: Is hlt reduces CPU power consumption?

Post 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.
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
Post Reply