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)
BIOS interupts vs. ports
Re:BIOS interupts vs. ports
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.
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?).also, what is faster, printing to screen (txt mode) directly writing to vga ram or using ints? (i think the first one is)
Re:BIOS interupts vs. ports
Tim,
Thanks
_mark()
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?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?).
Thanks
_mark()
Re:BIOS interupts vs. ports
Thank you Tim! I'm comfortable with ports, but I just wondered if ints (where useable) are maybe faster than portsTim 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.
Re:BIOS interupts vs. ports
_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.
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.
Re:BIOS interupts vs. ports
Ports usage may be slow on nowadays CPU, but it's definitely faster than using thousands cycled ints !!
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:BIOS interupts vs. ports
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 ...pini wrote: Ports usage may be slow on nowadays CPU, but it's definitely faster than using thousands cycled ints !!
The use of the interrupt itself takes only 50ns ... i bet there isn't much hardware that can respond that fast ...
Re:BIOS interupts vs. ports
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
Re:BIOS interupts vs. ports
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).
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).