Memory mapped IO vs Port IO

Memory mapped IO vs Port IO

Post by Matthew Wi » Sat, 13 Sep 2003 01:10:16



There's a lot of drivers in the tree that allow you to access the device
either via IO port space or IO mem space. Here's some examples:

config SCSI_SYM53C8XX_IOMAPPED
bool "use normal IO"
depends on SCSI_SYM53C8XX_2
help
If you say Y here, the driver will preferently use normal IO
rather than memory mapped IO.

config 8139TOO_PIO
bool "Use PIO instead of MMIO"
depends on 8139TOO
help
This instructs the driver to use programmed I/O ports (PIO) instead
of PCI shared memory (MMIO). This can possibly solve some problems
in case your mainboard has memory consistency issues. If unsure,
say N.

config TULIP_MMIO
bool "Use PCI shared mem for NIC registers"
depends on TULIP
help
Use PCI shared memory for the NIC registers, rather than going through
the Tulip's PIO (programmed I/O ports). Faster, but could produce
obscure bugs if your mainboard has memory controller timing issues.
If in doubt, say N.

As you can see, everybody asks the question differently, and sometimes
you should answer Y and sometimes N to get MMIO. There are other drivers
which don't ask the question at all and you have to edit the .c file to
turn it on or off. I'll also note the acronym `PIO' is ambiguous --
sometimes it refers to Port IO and sometimes to Programmed IO (which
can be a memory access).

Personally, when I'm configuring a new kernel for a machine, I don't
want to learn about the suboptions for each device -- I've got dozens of
other things to configure right. My favourite solution to this problem
wuld be to ask the question once only and have it apply to all devices:

config MMIO
bool "Prefer Memory-mapped I/O accesses over Port I/O"
help
Many devices are accessible via both memory mapped I/O and
port I/O. Say Y here to access them via the slightly faster
memory mapped I/O method. If you experience problems, you may
wish to say N here.

If that's not acceptable, can I suggest that we at least ask a standard
question?

config WWWW_MMIO
bool "Use Memory mapped I/O in preference to Port I/O"
depends on WWWW
help
This device's registers can be accessed by either memory
mapped I/O or port I/O. Memory mapped I/O is faster, so you
are advised to say Y here.

(yes, we could wordsmith these questions into the ground; the key point
of this mail is whether we ask one question at the start of configuration
or whether we ask one question per device.)

--
"It's not Hollywood. War is real, war is primarily not about defeat or
victory, it is about death. I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

Memory mapped IO vs Port IO

Post by Andi Klee » Sat, 13 Sep 2003 01:20:12

Matthew Wilcox < XXXX@XXXXX.COM > writes:


My gut feeling is to just fix the drivers to make this runtime switchable
and get rid of the compile time options.

This would help distributions (who normally want to build conservative
by default, but still allow the users easy tuning without recompilation)
For that it would be nice if a standard module parameter or maybe
sysfs option existed.

The overhead of checking for PIO vs mmio at runtime in the drivers
should be completely in the noise on any non ancient CPU (both MMIO
and PIO typically take hundreds or thousands of CPU cycles for the bus
access, having an dynamic function call or an if before that is makes
no difference at all)

-Andi
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/

 
 
 

Memory mapped IO vs Port IO

Post by Matthew Wi » Sat, 13 Sep 2003 01:30:26


That's not true for MMIO writes which are posted. They should take
no longer than a memory write. For MMIO reads and PIO reads & writes,
you are, of course, correct.

--
"It's not Hollywood. War is real, war is primarily not about defeat or
victory, it is about death. I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

Memory mapped IO vs Port IO

Post by Andi Klee » Sat, 13 Sep 2003 01:40:13

On Thu, 11 Sep 2003 17:25:04 +0100




Even a memory write is tens to hundres of cycles.

-Andi

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

Memory mapped IO vs Port IO

Post by Matthew Wi » Sat, 13 Sep 2003 01:50:14


So are mispredicted branches.

--
"It's not Hollywood. War is real, war is primarily not about defeat or
victory, it is about death. I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

Memory mapped IO vs Port IO

Post by Jamie Loki » Sat, 13 Sep 2003 02:20:16


Another way to help distributions is to compile those drivers twice,
once for each access type. There aren't all that many drivers that
need it.


Ah, but what about the ancient CPUs?

-- Jamie
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

Memory mapped IO vs Port IO

Post by Andi Klee » Sat, 13 Sep 2003 02:40:29

On Thu, 11 Sep 2003 18:12:05 +0100




Only when there are more instructions to execute. But device
driver code often does a following read e.g. to check if it can submit
another request to the hardware.

My claim is basically:

Change everybody who currently does

#ifdef CONFIG_MMIO
writel(... )
readl(...)
#else
outl( ... )
inl ( ...)
#endif

to
if (dev->mmio) {
writel();
real();
} else {
outl();
inl();
}

and you will have a hard time to benchmark the difference on any non ancient system
in actual driver operation.

-Andi

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

Memory mapped IO vs Port IO

Post by Jamie Loki » Sun, 14 Sep 2003 01:30:17


I think it would be faster to hide the "if (mmio)" part into an
inline function which calls one or the other, given a resource cookie.

Branch prediction will remove most of the cost of a conditional test,
which is always the same in these drivers after all, but I don't think
it's quite so good at predicting indirect function calls.

-- Jamie
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

Memory mapped IO vs Port IO

Post by jbarne » Sun, 14 Sep 2003 01:30:25


I'd rather not see any more pointer dereferences or even branches than
absolutely necessary. Right now, readX/writeX and inX/outX are usually
inlines, and outX and writeX can be very fast. So I'd prefer either a
global CONFIG_MMIO option or consistent driver specific options that
explain what the difference between MMIO and port I/O actually is.

Jesse
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

Memory mapped IO vs Port IO

Post by jbarne » Sun, 14 Sep 2003 03:00:13

Ok, Andi asked for benchmarks, so I ran some. Let this should be a
lesson on why you shouldn't use port I/O :) I ran these on an SGI Altix
w/900 MHz McKinley processors.

Just straight calls to the routines (all of these are based on the
average of 100 iterations):
writeq(val, reg) time: 64 cycles
outl(val, reg) time: 2126 cycles

A simple branch:
if (use_mmio)
writeq(val, reg) time: 132 cycles
else
outl(val, reg) time: 1990 cycles

Using a wrapper to point to one of the routines:
wrapper->write(val, reg) time: 215 cycles
wrapper->out(val, reg) time: 3931 cycles

Thanks,
Jesse
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

Memory mapped IO vs Port IO

Post by Andi Klee » Sun, 14 Sep 2003 03:10:17


XXXX@XXXXX.COM (Jesse Barnes) writes:

^^^^^
^^^^^
Something seems to be wrong in your numbers.

Surely the outl in the if () cannot be faster than the pure outl() ?

-Andi

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

Memory mapped IO vs Port IO

Post by Andi Klee » Sun, 14 Sep 2003 03:20:14

On Fri, 12 Sep 2003 11:04:29 -0700




True. Ok for PIO it doesn't matter. I'm surprised the hit is that big
for MMIO. What code does the IA64 compiler generate for this?
If it was a branch it should have been predicted.

I guess we could use dynamic patching like the alternative() code on
i386 does for prefetches etc., but that may be a bit of overkill...
Or fix the makefiles that they can easily compile two versions of
the driver.

-Andi
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/
 
 
 

Memory mapped IO vs Port IO

Post by Tim Hocki » Sun, 14 Sep 2003 03:40:21


Also - a perhaps more useful test is a write followed by a read.

--
Notice that as computers are becoming easier and easier to use,
suddenly there's a big market for "Dummies" books. Cause and effect,
or merely an ironic juxtaposition of unrelated facts?

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/