BIOS interupts vs. ports

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.
Post Reply
nitroglycerin

BIOS interupts vs. ports

Post by nitroglycerin »

hi, me again ;D

what is faster? using BIOS ints or ports? eg. I can use kbd through bios ints and kbd ports 0x60 and 0x64. what is faster? (for a simple user-input)

also, what is faster, printing to screen (txt mode) directly writing to vga ram or using ints? (i think the first one is)
Tim

Re:BIOS interupts vs. ports

Post by Tim »

Ports are theoretically faster (you're using one IN or OUT instruction instead of going through the BIOS code). But port accesses are so slow compared to modern CPUs that there's hardly any difference. However, if you're going to write a protected mode OS, you will need to use ports.
also, what is faster, printing to screen (txt mode) directly writing to vga ram or using ints? (i think the first one is)
It's definitely faster to write directly to video RAM, especially if that region isn't cached write-through (is it cached write-through by default?).
_mark

Re:BIOS interupts vs. ports

Post by _mark »

Tim,
It's definitely faster to write directly to video RAM, especially if that region isn't cached write-through (is it cached write-through by default?).
Is that what that video rom shadow stuff is in the bios? And why would we want cached video anyway? I'm not sure I understand this one?

Thanks
_mark()
nitroglycerin

Re:BIOS interupts vs. ports

Post by nitroglycerin »

Tim Robinson wrote: Ports are theoretically faster (you're using one IN or OUT instruction instead of going through the BIOS code). But port accesses are so slow compared to modern CPUs that there's hardly any difference. However, if you're going to write a protected mode OS, you will need to use ports.
Thank you Tim! I'm comfortable with ports, but I just wondered if ints (where useable) are maybe faster than ports
Tim

Re:BIOS interupts vs. ports

Post by Tim »

_mark(): I was thinking of the B8000 region itself. Accessing the video memory itself is pretty slow compared to DRAM, and glacial compared to the CPU's cache (reading video RAM takes an eternity). If the CPU was caching that area, so that reads and writes went to the CPU's cache first, instead of straight to the video card, then it would be pretty fast. You probably wouldn't notice because the CPU would probably flush the cache before the next vertical refresh anyway.

nitroglycerin: as I said, direct port access uses fewer instruction than calling an interrupt. But the total time taken is almost the same either way, because the port access time (either done by yourself or done by the BIOS int -- somebody's got to do it) is so much greater than the interrupt overhead time.
pini

Re:BIOS interupts vs. ports

Post by pini »

Ports usage may be slow on nowadays CPU, but it's definitely faster than using thousands cycled ints !!
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:BIOS interupts vs. ports

Post by Pype.Clicker »

pini wrote: Ports usage may be slow on nowadays CPU, but it's definitely faster than using thousands cycled ints !!
note: on a 2GHz CPU, 1000 cycles (well, in fact, trapping to the kernel requires 99 cycles, according to some 80386 docs) only takes 500ns ...

The use of the interrupt itself takes only 50ns ... i bet there isn't much hardware that can respond that fast ...
pini

Re:BIOS interupts vs. ports

Post by pini »

Maybe the int call is only 50ns, but you have to deal with the opcodes of the int functions you're calling, and that makes a very different result
Tim

Re:BIOS interupts vs. ports

Post by Tim »

You might have missed my point.

At most, an x86 INT instruction takes a couple of hundred clock cycles. An IN or OUT instruction has to interact with both the bus and the hardware. Each one takes at least a couple of bus cycles, plus the time taken by the hardware. One bus cycle equals many CPU cycles (think of a 33MHz PCI bus coupled to a 1600MHz CPU), so even if the hardware device is instant, you've already got a slowdown of several hundred CPU cycles just from bus overhead.

Add to that the time taken by the device's circuitry, and you almost always find that (time for port) < (time for INT + time for port).
Post Reply