flat assembler
Message board for the users of flat assembler.

Index > OS Construction > SMP

Author
Thread Post new topic Reply to topic
sinsi



Joined: 10 Aug 2007
Posts: 708
Location: Adelaide
sinsi
Q1: is it *required* to send two SIPIs to an AP?
Q2: is CLI/HLT the way to suspend a CPU?
Q2a: if so, is INIT-SIPI the way to wake it up?

Lots more questions, but these are the basics.
Intel docs, you suck man.
Post 07 Oct 2009, 07:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17663
Location: In your JS exploiting you and your system
revolution
Perhaps the AMD docs can help a bit? I don't know if they can, just that sometimes there is some extra info the Intel forget to tell.
Post 07 Oct 2009, 07:49
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 708
Location: Adelaide
sinsi
Yeah, but the spec is intel (mp 1.4) from years ago, but I will give it a try.
Does your website have an instant link to the pdf's? Very Happy <edit
Post 07 Oct 2009, 07:58
View user's profile Send private message Reply with quote
Pirata Derek



Joined: 31 Oct 2008
Posts: 259
Location: Italy
Pirata Derek
If you use:
Code:
...
   cli
   hlt
   nop
   ret
...
    

The CPU will be "STONED", because HLT maintains it in a low operative state, but CLI doesn't let interrupts (like a mouse movement) to wake it up except for the RESET-PIN interrupt (it's the interrupt with the most priority to be executed)

I think you should find another way to let some hardware interrupts wake up CPU.
Post 07 Oct 2009, 08:59
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17663
Location: In your JS exploiting you and your system
revolution
Pirata Derek wrote:
If you use:
Code:
...
   cli
   hlt
   nop
   ret
...
    

The CPU will be "STONED", because HLT maintains it in a low operative state, but CLI doesn't let interrupts (like a mouse movement) to wake it up except for the RESET-PIN interrupt (it's the interrupt with the most priority to be executed)

I think you should find another way to let some hardware interrupts wake up CPU.
It has been awhile since I last looked at this but IIRC the HLT will restart upon any interrupt regardless of the CLI. The only change is that the CPU won't jump to the interrupt handler, it will continue on to the NOP with interrupts still disabled. Of course, NMI can still bring you out to the interrupt handler.
Code:
...
  @@:
   cli
   hlt
   jmp @b
...    
That might make things a bit more troublesome. Only RESET or NMI can break out. But even then still only if you are in ring 0.

[edit] I hope I am not confusing this with the ARM stuff. Anyhow, it should be easy to setup a test to confirm.
Post 07 Oct 2009, 09:33
View user's profile Send private message Visit poster's website Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
Pirata Derek wrote:
If you use:
Code:
...
   cli
   hlt
   nop
   ret
...
    

The CPU will be "STONED", because HLT maintains it in a low operative state, but CLI doesn't let interrupts

Yeah, because this is deliberately badly written code. Of course you shouldn't explicitly give it a "cli". hlt should *always* be called in a "sti" area.

And what's with the nop? Have I missed something somewhere in the docs? Is it for older machines (like when using in/out)?
Post 07 Oct 2009, 09:45
View user's profile Send private message Reply with quote
Pirata Derek



Joined: 31 Oct 2008
Posts: 259
Location: Italy
Pirata Derek
Yes, i know:
I inserted the CLI because it is in the second question of the first post. (check it)

The NOP is an optional that i use to be sure CPU won't perform any operation after returning to an interrupt (fired after the HLT)

Once, a driver without the NOP after the HLT crashed my system.
with the NOP, it didn't crash no more.

I don't know why, maybe the NT kernel sucks... Laughing
Post 07 Oct 2009, 12:21
View user's profile Send private message Send e-mail Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
with PIT set to 24 Hz and HLT in the main loop, you set the minimal looping frequency to 24 Hz.

Code:
|________________|________________|______________|_____
^
PIT interrupt, 24 times/sec. default 18,2 times/sec

all code executed between two PIT interrupt is ended by HLT.
then, to wake PC, you use PIT.

    


measure of time between HLT and PIT int will give you the spare computing power you have.
Post 08 Oct 2009, 11:53
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
I'm writing some 64-bit SMP protected-mode code right now and:
Q1: No, but I send them anyway - some CPUs *might* not wake up on the first one, but most (newer) do.
Q2: You suspend a CPU with HLT
HLT is 'woken' by an interrupt - so if you return from an interrupt, you continue to the next instrction.
IF you suspend a CPU with CLI/HLT the only way to wake it up is RESET and that's not what you usually want. I do a CLI/HLT only to debug with QEMU.

Q2a: If you use CLI/HLT then - YES!

Intel docs do suck, but everything is there Smile
Post 09 Oct 2009, 10:32
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17663
Location: In your JS exploiting you and your system
revolution
Madis731: Are you sure that NMI does not also wake up the CPU from a CLI/HLT?
Post 09 Oct 2009, 10:40
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
Manual says cli doesn't affect NMI and execution resumes after hlt on NMI or SMI.
Post 23 Oct 2009, 17:09
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 708
Location: Adelaide
sinsi
If I start an AP via INIT-SIPI-SIPI, then stone it with HLT, is sending it an NMI a good way to unstone it or is there a better way?
All the handler does is IRET and the code continues as I expect but is it good/bad/shrug?
Post 21 May 2010, 06:40
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
Yes, the APIC can send another IPI (type NMI) to wake up a target processor which behaves like a normal interrupt if you program the LVT/LINT of the LAPICs of all processors.

Intel Vol 3A and AMD Vol 2 should give you more details.
Post 21 May 2010, 08:53
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 708
Location: Adelaide
sinsi
It just seems strange to send NMI, since that was historically a catastrophic failure (ram parity error).
Post 21 May 2010, 09:06
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
Well you can still send a normal IPI if you don't use cli but I don't know how that affects interrupts across processors -- maybe someone here can enlighten us Smile
Post 21 May 2010, 10:23
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
Update: seems the IOAPIC directs all normal interrupts to core 0 so you can use this to stop APs with hlt and wake them with a normal (type fixed) IPI at a vector of your choice. I'm not in a position to test this with my OS atm but hope to soon.
Post 29 May 2010, 09:00
View user's profile Send private message 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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.