Page 1 of 2

bootloader - the loops - warm processor

Posted: Sun Jan 31, 2010 1:56 pm
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?

Re: bootloader - the loops - warm processor

Posted: Sun Jan 31, 2010 2:02 pm
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 :)

Re: bootloader - the loops - warm processor

Posted: Sun Jan 31, 2010 2:10 pm
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 =)

Re: bootloader - the loops - warm processor

Posted: Sun Jan 31, 2010 2:15 pm
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.

Re: bootloader - the loops - warm processor

Posted: Sun Jan 31, 2010 9:35 pm
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?

Re: bootloader - the loops - warm processor

Posted: Mon Feb 01, 2010 5:17 am
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.

Re: bootloader - the loops - warm processor

Posted: Mon Feb 01, 2010 2:01 pm
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?

Re: bootloader - the loops - warm processor

Posted: Mon Feb 01, 2010 2:41 pm
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

Re: bootloader - the loops - warm processor

Posted: Wed Feb 03, 2010 7:52 am
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!

Re: bootloader - the loops - warm processor

Posted: Sun Feb 21, 2010 8:49 pm
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?

Re: bootloader - the loops - warm processor

Posted: Sun Feb 21, 2010 9:46 pm
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

Re: bootloader - the loops - warm processor

Posted: Sun Feb 21, 2010 9:52 pm
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.

Re: bootloader - the loops - warm processor

Posted: Sun Feb 21, 2010 11:08 pm
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?

Re: bootloader - the loops - warm processor

Posted: Mon Feb 22, 2010 3:42 am
by Combuster
At least Yasm will not assemble that and throws back a syntax error

Re: bootloader - the loops - warm processor

Posted: Mon Feb 22, 2010 5:31 am
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