flat assembler
Message board for the users of flat assembler.

Index > Main > what instruction(s) is the cpu calling when it 'idle'

Author
Thread Post new topic Reply to topic
tthsqe



Joined: 20 May 2009
Posts: 724
tthsqe
tile asks its all
Post 06 Jan 2015, 04:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
HLT
Post 06 Jan 2015, 04:15
View user's profile Send private message Visit poster's website Reply with quote
neville



Joined: 13 Jul 2008
Posts: 507
Location: New Zealand
neville
The HLT instruction puts the X86 cpu into a HALT state in which no further instructions are executed until an interrupt or reset is received. This of course is not quite the same thing as, for example, the System Idle process in a multi-tasking OS. In a simple case this could be a tight loop of I/O polling instructions.

_________________
FAMOS - the first memory operating system
Post 06 Jan 2015, 10:44
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
neville wrote:
This of course is not quite the same thing as, for example, the System Idle process in a multi-tasking OS. In a simple case this could be a tight loop of I/O polling instructions.
I hope no mainstream OS out there is doing that. Very inefficient. What I/O device these days doesn't have an interrupt? And what I/O device would be useful only when the other tasks are sleeping? I can't imagine any good scenario where this is a viable method. Confused
Post 06 Jan 2015, 10:52
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Every normal OS system idle process must end with HLT, lowering the CPU load this way.
Post 06 Jan 2015, 11:09
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
I don't know any system which is really idle even if it seems to be idle. Cool

There is so much to do in a PC for example, USB requires action, system has to react at key presses, there are many background service tasks, you have to be present on LAN and WLAN actions. So when is a system really idle ? I would say when it is powered off. Razz

And the big question is - why should a system be idle at all ? To save power - okay this is done for microcontrollers or mobiles but the electronic is running anyway - so the devices in a system are powered and the only thing is to put a microprocessor maybe in a power reduced mode (make it slower) but not really idle or even entering a HALT command. And the processor even takes energy when it is in HALT state. Rolling Eyes
Post 06 Jan 2015, 16:53
View user's profile Send private message Send e-mail Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
shutdownall, at first for the modern processors working allways on 100% is really hard task. Most of them will overheat. The power consumed is more by times, not by percents.

Anyway, your mistake is in the time scale. 1..2ms is very small time for a human, but almost an eternity for the CPU. Let see some simple example. If the timer makes the interrupts on 10ms and the CPU is 5% loaded, it actually executes some code for 0.5ms and stays in HALT for 9.5ms waiting for an interrupt.
Post 06 Jan 2015, 18:10
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
neville



Joined: 13 Jul 2008
Posts: 507
Location: New Zealand
neville
I just thought that tthsqe's original question implied he was thinking of on-going instruction executions, whereas the HLT instruction, as suggested by revolution, isn't quite like that.

Of course, the cpu will rarely if ever stay in the HALT state for more than a millisecond after executing a HLT, but since a ms is a long time to the cpu its heat dissipation can be significantly lowered.

In the HALT state the CPU is at least still internally polling it's interrupt lines fed from the external PICs (or maybe that's all implemented as a dedicated hardware function), but I'm not sure if that's what tthsqe had in mind when referring to the cpu being "idle"?

What I was getting at is that we could all write a keyboard polling loop which would occupy the CPU 100% while it waits for us to press a key. We could call this a software "idle" loop (yes, very inefficient!), and maybe this is what tthsqe was getting at? Or maybe the question was always meant to be a bit vague Very Happy

Code:
WAIT4KEY: IN  AL,64H
          AND AL,1      
          JZ  WAIT4KEY
GOTKEY:   IN  AL,60H    ;get scancode...
          ...           ;process scancode
    


or using real mode BIOS:
Code:
WAIT4KEY: MOV AH,1      
          INT 16H
          JZ  WAIT4KEY
GOTKEY:   CMP AH,...    ;process scancode...
    

_________________
FAMOS - the first memory operating system
Post 07 Jan 2015, 09:24
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.