bootloader - the loops - warm processor

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.
Merdini
Member
Member
Posts: 34
Joined: Fri May 04, 2007 10:11 pm
Location: Sweden, Gothenburg

bootloader - the loops - warm processor

Post by Merdini »

When running w2k3 server for a while, my p3 500mhz is cool without a fan.
Strange part is, when im running my bootloader it gets hot as hell.

Could this be because of the loop?

Any ideas?

Here is a a simple bootloader which makes my processor get really hot:

Code: Select all

[BITS 16]
[ORG 0x7C00]
jmp $
times 510-($-$$) db 0
dw 0xAA55
What can i do instead?
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: bootloader - the loops - warm processor

Post by ru2aqare »

Kurdistan wrote:Could this be because of the loop?

Any ideas?
Insert an instruction to halt the processor (to reduce heat emission). Halt or something to that effect - reduce clock speed, etc.

Code: Select all

boot    segment para public use16 'CODE'
        org 7C00h
entry:
        sti     ; enable interrupts anyway (if disabled, the processor will lock up)
loop:
        hlt     ; halt processor
        jmp     short loop

        org 7CFEh
        dw      0AA55h
boot    ends
        end entry
I think you already know that running a processor that has a high heat dissipation factor without a proper cooling device will eventually damage it. You shouldn't be using it to... cook eggs on it, for example :)
Merdini
Member
Member
Posts: 34
Joined: Fri May 04, 2007 10:11 pm
Location: Sweden, Gothenburg

Re: bootloader - the loops - warm processor

Post by Merdini »

Thanks for the help, i'll try it out.

This processor doesn't need a fan, it has a pretty big heat sink.
Have used this computer as a webserver for a few years without any problems =)
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: bootloader - the loops - warm processor

Post by Gigasoft »

Use the HLT instruction when you're not doing anything to keep the CPU cold. When actively polling, using strings of PAUSE instructions or OUT 0edh, AL (a delay port implemented on many computers) might work.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: bootloader - the loops - warm processor

Post by Love4Boobies »

Gigasoft wrote:OUT 0edh, AL (a delay port implemented on many computers) might work.
I've never heard about this delay port before. What's supposed to be in AL? I'm intrigued, can you point to a reference?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Merdini
Member
Member
Posts: 34
Joined: Fri May 04, 2007 10:11 pm
Location: Sweden, Gothenburg

Re: bootloader - the loops - warm processor

Post by Merdini »

Only thing i found about out 0edh, al is "non existing port for delay".
It didn't work though, on vpc, my bootloader/kernel is still eating up the cpu.
halting didn't work ether, nether did PAUSE, the SSE2 instruction.
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: bootloader - the loops - warm processor

Post by Gigasoft »

I haven't found any documentation for this delay port, but many BIOSes use it, and Linux also seems to use it. The byte written to it doesn't matter. Perhaps it's just a reserved port that doesn't get responded too, causing a standard I/O delay.

If HLT doesn't even work, then it's a mystery. You're sure you're executing it in a loop?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: bootloader - the loops - warm processor

Post by Brendan »

Hi,
Kurdistan wrote:Only thing i found about out 0edh, al is "non existing port for delay".
It didn't work though, on vpc, my bootloader/kernel is still eating up the cpu.
halting didn't work ether, nether did PAUSE, the SSE2 instruction.
If you mean that none of these made a significant difference to CPU temperature, then that's probably what you should expect...

Most CPUs have several different power saving modes; and usually the modes that save the most power/heat have the highest latency (e.g. take longer to enter the power saving mode, and take longer to leave the power saving mode). HLT has low latency (which is important to avoid effecting IRQ latency too much) which means that most of the CPU is still running (and not much power is saved).

It's possible (likely) that the CPU supports much more aggressive power saving modes (including things like flushing all caches and turning them off, reducing the core's voltage and frequency, etc); and it's also likely that Windows uses one or more of these more aggressive power saving modes.

PAUSE isn't intended to reduce power usage at all - it's intended for improving performance with hyper-threading (where a core's resources are shared by logical CPUs). Basically it stops a tight loop running on one logical CPU from filling up the core's pipeline (and making the other logical CPU run slower).

OUT is similar - it does create a delay, but doesn't turn any of the CPU off and doesn't reduce power usage.

For all of these, HLT should save the most power (but still nowhere near the amount of power that deeper power management states, etc would save; and probably not enough to cause the CPU fan to slow down much).

To use the deeper power management states you need to mess with (chipset specific) I/O ports and/or (CPU model specific) MSRs and/or APM and/or ACPI.


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.
Merdini
Member
Member
Posts: 34
Joined: Fri May 04, 2007 10:11 pm
Location: Sweden, Gothenburg

Re: bootloader - the loops - warm processor

Post by Merdini »

Thanks for all the help!

The loop never got executed,
loop: hlt
jmp loop

But it worked now when i moved all the variable declaration to the end!
Merdini
Member
Member
Posts: 34
Joined: Fri May 04, 2007 10:11 pm
Location: Sweden, Gothenburg

Re: bootloader - the loops - warm processor

Post by Merdini »

I got to protected mode now, so hlt doesn't work due to the privileges.

My code is using 100% of the cpu, when Im in real mode and use hlt (without cli) it stays below 2% when idle. Now it's 100% when idle.

What can i use or do instead so that my code doesn't use 100% of the cpu when idle?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: bootloader - the loops - warm processor

Post by Brendan »

Hi,
Kurdistan wrote:I got to protected mode now, so hlt doesn't work due to the privileges.

My code is using 100% of the cpu, when Im in real mode and use hlt (without cli) it stays below 2% when idle. Now it's 100% when idle.

What can i use or do instead so that my code doesn't use 100% of the cpu when idle?
If HLT doesn't work due to privileges, then your code should call the kernel (or something that can use HLT) and tell it that it has nothing else to do. For most OS's the kernel would switch to another task (if there's any other tasks that could run) or if that's not possible it'd HLT until something changes (and if nothing changes for a while, it might try deeper sleep states).


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.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: bootloader - the loops - warm processor

Post by pcmattman »

I got to protected mode now, so hlt doesn't work due to the privileges.
You can still run hlt in protected mode, just not outside of ring0.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: bootloader - the loops - warm processor

Post by Love4Boobies »

Kurdistan wrote:The loop never got executed,
loop: hlt
jmp loop

But it worked now when i moved all the variable declaration to the end!
Is NASM so stupid as to let you use opcode names for labels or the code didn't assemble because you weren't unaware you did this?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: bootloader - the loops - warm processor

Post by Combuster »

At least Yasm will not assemble that and throws back a syntax error
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Merdini
Member
Member
Posts: 34
Joined: Fri May 04, 2007 10:11 pm
Location: Sweden, Gothenburg

Re: bootloader - the loops - warm processor

Post by Merdini »

Thanks Brendan, i'll try that.

No, i used "loop" just for an example. NASM didn't alert a errormessage when i tried loop now. But that mistake was corrected.

And i thought i was in ring 0?
I just wrote:

Code: Select all

cli
xor ax, ax
mov ds, ax
lgdt [gdt]
mov eax, cr0
or eax, 1
mov cr0, eax
and then jump to a 32 bit area, with:

Code: Select all

mov ax, 16
mov ds, ax
mov ss, ax
mov esp, 090000h
Post Reply