OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:45 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Is hlt reduces CPU power consumption?
PostPosted: Tue Feb 09, 2016 9:23 am 
Offline
Member
Member
User avatar

Joined: Fri Apr 03, 2015 9:41 am
Posts: 492
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.


Top
 Profile  
 
 Post subject: Re: Is hlt reduces CPU power consumption?
PostPosted: Tue Feb 09, 2016 11:48 am 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject: Re: Is hlt reduces CPU power consumption?
PostPosted: Wed Feb 10, 2016 12:24 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 27, 2014 3:57 am
Posts: 568
Location: Moscow, Russia
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


Top
 Profile  
 
 Post subject: Re: Is hlt reduces CPU power consumption?
PostPosted: Sat Apr 15, 2017 11:28 am 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject: Re: Is hlt reduces CPU power consumption?
PostPosted: Sat Apr 15, 2017 11:52 am 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject: Re: Is hlt reduces CPU power consumption?
PostPosted: Sun Apr 16, 2017 3:42 am 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
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].


Top
 Profile  
 
 Post subject: Re: Is hlt reduces CPU power consumption?
PostPosted: Sun Apr 16, 2017 1:01 pm 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject: Re: Is hlt reduces CPU power consumption?
PostPosted: Sun Apr 16, 2017 1:30 pm 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject: Re: Is hlt reduces CPU power consumption?
PostPosted: Sun Apr 16, 2017 3:41 pm 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject: Re: Is hlt reduces CPU power consumption?
PostPosted: Sun Apr 16, 2017 7:06 pm 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 88 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group