News for hackers. Stuff that matters.
Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by Animats on Friday May 03, 2019 @01:40PM (#19820489)
Mainframe designers had this problem under control by 1970. Mainframes had, and have, "channels". A channel is part of the processor architecture. It takes commands, sends them to a peripheral, and manages the data transfer in both directions. Channels have some privileged functions through which the OS tells them where the data is supposed to go in memory. The architecture of channels is well defined, and peripherals are built to talk to channels. The CPU has I/O instructions to control channels in a well defined way.

The peripheral never has access to main memory. There is no peripheral-controlled "direct memory access" (DMA). So it's possible to give control of a channel to a userland program without a memory security risk.

Minicomputers of the 1970s had low transistor counts and slow CPUs. So peripherals were usually put directly on the memory bus, with full access to memory. I/O operations were performed by storing into memory addresses, which caused bus transactions detected by the peripheral device. There were no CPU I/O instructions.

Microprocessors copied the minicomputer model. IBM's people knew this was a bad idea, and in the IBM PS/2, they introduced the "microchannel". Peripheral vendors, facing a new architecture that required more transistors, screamed. IBM backed down and went back to bus-oriented peripherals.

That model persists today, even though the few thousand transistors required for a channel controller are nothing today. Even though most modern CPUs have I/O channel like machinery, it's exposed to the program as registers the program stores into and memory accesses by the peripheral device.

So there's no standardization on how to talk to devices at the hardware level. Some CPUs have protection systems, an "I/O MMU", and there have been various channel-like interfaces, especially from Intel, but they have never caught on.

Instead, we mostly have heavy kernel mediation between the hardware and the user program. And way too many "drivers". This has become a problem with "solid state disk", which is really a random access memory device that doesn't write very fast. Mostly, it's used to emulate rotating disks.

Samsung makes a key/value store device which uses SSD-type memory devices but manages the key/value store itself. But you need a kernel between the device and the user program. You can't just open a channel to it and let the user program access it.

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by dbcurtis on Friday May 03, 2019 @02:47PM (#19821146)
That is an IBM- and Univac-centric view of I/O. Control Data Corp had the "peripheral processor", or PP. PP's only ran OS code, usually called "driver overlays".

It was actually very elegant. There were 10 copies of PP state (20 in the 7600) and only 1 actual execution unit (2 in 7600). Hardware multi-threading in 1959! So there were 10 PP's executing PP overlay code (drivers) at 1/10 the instruction rate of the main CPU. Each PP had 4K of 12-bit words, which served for both PP code and I/O buffer space. The main memory was 60 bits wide (12*5) and the addresses were 18 bits, so the PP's had 18 bit accumulators for computing addresses.

Since PP's ran only trusted code, they were allowed to scribble anywhere in main memory that they wanted to. At the end of the I/O operation, the PP computed an address for the main CPU and that directly became the interrupt vector address. This meant that the CPU never had to deal with low level interrupts, only the much less frequent I/O operation completion interrupt at the end of a long operation.

(In a past life, I did system software at CDC, and CPU logic design at Sperry-Univac and Amdahl.)

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by timzentu on Friday May 03, 2019 @06:50PM (#19822965)
Oh man, CDS/CDC (Control Data Systems/ Control Data Corporation) is where my Dad worked. Don't know if you knew him (Ed), but he was one of the last 2-4 employees for the company. He was working up in Michigan until 1996. I still remember we took a vacation to DC and in the Smithsonian they had 2 of the machines he worked on. [Him swearing at some hardware while in a museum because it had cut him is one of my best memories. Asked him how he could tell and it had a screwdriver ding from shutting it).
Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by watersb on Saturday May 04, 2019 @04:38PM (#19829230)
Friend of mine ran the CDC 6600 at the University of Texas in Austin.

Now I need to ask him about DMA architecture...

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by kabdib on Friday May 03, 2019 @03:18PM (#19821393)
IIRC the IBM Microchannel stuff was perceived as a ploy to recover control of the PC industry by licensing a new bus. The licensing terms were pretty bad (it could be that "free" was the expected bar at the time, though) and the implementation was expensive, too. Unfortunately for IBM the industry was pretty happy using the existing buses, and when more performance was needed the industry was equally happy to invent new buses that didn't involve paying royalties to IBM.

So regardless of MC's attractiveness from a systems standpoint, it was a nonstarter in an industry that was headed towards an ecology of clones and racing to the bottom in manufacturing costs. Many PC manufacturers ditched parity memory, too.

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by kazinator on Friday May 03, 2019 @02:27PM (#19820960)
> Channels have some privileged functions through which the OS tells them where the data is supposed to go in memory.

So the channel controller system has DMA; just not the peripheral.

> Minicomputers of the 1970s had low transistor counts and slow CPUs. So peripherals were usually put directly on the memory bus, with full access to memory.

That's "bus mastering" DMA. There is such a thing as "third party" DMA, which uses generic DMA controller, which is programmed to push data back and forth between memory and relatively dumb peripherals.

That approximates the channel concept.

PC's have had DMA controllers since 1980 something. The IBM PC had it in the form of the Intel 8237 chip. This is documented as having four "channels", wouldn't you know it.

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by Animats on Friday May 03, 2019 @03:00PM (#19821256)
Those are more like add-on features a driver can use if present. They don't push peripheral interfaces into a standard channel-like format. Nor are they close to one that can be exposed to application programs.
Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by kazinator on Friday May 03, 2019 @04:49PM (#19822140)
We can't expose a DMA controller directly to programs, but an API could be devised for it. Such a thing is needed even just from the mere portability point of view: making different DMA controllers on different systems look the same.

Applications will typically specify transfers using virtual addresses, but DMA controllers will understand physical memory (usually, but maybe there are virtually mapped ones out there). Plus there are other issues like restricted ranges: DMA that cannot acces all physical memory but just a certain range. The API will have to convert ranges of virtual addresses to one or more physical ranges, which are then queued as one or more DMA operations and somehow deal with the problem that not just any old memory allocation in the application is DMA-able.

Applications talking to channel hardware directly using dedicated CPU instructions is only possible in some vendor-locked IBM mainframe world. It's not otherwise feasible simply for business/market/economic reasons having nothing to do with technical feasibility.

An operating system API is basically a set of extensions to the instruction set available in the application's virtual machine; it's no different from some dedicated I/O instructions, just perhaps less efficient (which may or may not matter).

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by Unklejoe on Friday May 03, 2019 @08:22PM (#19823416)
> but DMA controllers will understand physical memory

Yup, this is what I’ve found on many embedded SoCs. It’s unfortunate. The fact that they need physical addresses makes them not worth using in many cases (mainly when trying to move user buffers around).

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by hyc_symas on Saturday May 04, 2019 @01:58PM (#19828054)
Sun supported DMA to virtual addresses in SunOS / Solaris. Made some aspects of drivers easier.
Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by CamperBob2 on Friday May 03, 2019 @06:29PM (#19822822)
They don't push peripheral interfaces into a standard channel-like format.

How does this not describe a PCIe bus master?

Frankly I don't understand any of this. High-performance I/O works by accessing main memory directly, just like it always has. The CPU then has to wait on main memory, just like it always has. Saying that the CPU is somehow the bottleneck seems to fall into the "not even wrong" area. There is no danger of I/O bandwidth approaching L1 or even L2 speeds anytime soon.

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by ncmncm on Friday May 03, 2019 @08:29PM (#19823443)
400 Gbps is 50 GBps, or 50 bytes per ns. A 100-byte packet comes every 2ns. The bottleneck is not cache bandwidth, it is the number of instructions you have time to execute per unit of I/O: in 6 cycles you will not get to run 24 instructions, especially if you have to wait 3 cycles for your L1 cache.
Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by CamperBob2 on Friday May 03, 2019 @09:36PM (#19823722)
But you aren't waiting on L1, except in the sense that you're waiting on line fills from main memory. If the problem is that you don't have enough time to do something with the data you're getting, how is that solvable by architectural changes external to the CPU?

In the real world, if you need to deal with 400 Gb/s, you aren't going to send it to a single general-purpose CPU using any type of bus or channel. The CPU won't see it until another ASIC (or FPGA, I suppose) crunches it first.

Yes, that may impose a limit on the speed of an external network that a CPU can deal with, but that's the way it goes. MCA was never going to save us at this end of the Moore's Law curve.

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by ncmncm on Friday May 03, 2019 @10:33PM (#19823981)
It is only solvable by architectural changes external to the CPU. Even at 40Gbps, which we live with now, that's 20 ns per packet, or 80 ns at a pokey 10Gbps, certainly not enough time to do a system call per packet.

So you need the hardware to divvy traffic up to multiple queues -- rings, really -- and a core for each ring. The packets just show up in memory, and the cores had just better keep up. If that looks to you like the same old POSIX architecture, I don't know what to say.

It was around 2010 that the network pipes got faster than the SAN file servers, and suddenly file output capacity had to be incorporated into network flow control.

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by dkersten on Friday May 03, 2019 @04:17PM (#19821876)
So would it be correct to say that functionally, it’s similar to DMA, but the API is different because “channels” expose a consistent interface while DMA doesn’t?
Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by kazinator on Friday May 03, 2019 @04:50PM (#19822153)
Channels only expose a consistent interface as long as there is no other mainframe other than an IBM one, or compatible.

Once you have two, and you want portable applications, using channel I/O instructions directly inline goes out the window; you need an API.

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by marshray on Friday May 03, 2019 @05:10PM (#19822310)
One could say this about any library or OS feature. Berkeley Sockets, for example.

Porting code is easier when there are portable APIs. But that doesn't diminish from the quality of the abstraction.

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by transpute on Friday May 03, 2019 @04:55PM (#19822186)
> So there's no standardization on how to talk to devices at the hardware level. Some CPUs have protection systems, an "I/O MMU", and there have been various channel-like interfaces, especially from Intel, but they have never caught on.

From the paper:

> NVMe SSDs perform I/O faster than the OS can accept new I/O requests and notify their completion. Furthermore, the current POSIX AIO implementations in Linux are ugly and adhoc, and they have limited support from file systems. This has lead to new AIO interfaces that eliminate system calls and leverage polling. However, polling for completion is not suitable for large I/O transfers.

AWS Nitro SR-IOV I/O virtualization [1] uses Intel VT-d Posted Interrupts [2] to avoid polling, but this CPU feature is price-segmented to Xeon E5 and higher. For other CPUs, polling [3] is necessary to achieve high IOPS with NVME. Intel and AMD should consider making this feature available on all CPUs, to support NVME and NVDIMM.

[1] SR-IOV: https://www.snia.org/sites/default/files/RonEmerick_PCI_Expr... & https://www.twosixlabs.com/running-thousands-of-kvm-guests-o...

[2] IOMMU: https://www.linux-kvm.org/images/7/70/2012-forum-nakajima_ap...

[3] Polling: https://events.static.linuxfound.org/sites/events/files/slid... & https://www.snia.org/sites/default/files/SDC/2018/presentati...

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by _msw_ on Saturday May 04, 2019 @01:26AM (#19824635)
Disclosure: I work at AWS and played a part in building the Nitro system

The Nitro system does use SR-IOV, and it can take advantage of hardware virtualization features like VT-d posted interrupts to lower interrupt virtualization overhead. But VT-d posted interrupts isn't a factor in avoiding polling. I'd go further to say that the Two Six Labs blog post has some inaccuracies, so I wouldn't depend on the information it contains much.

Polling is often more efficient, and lower latency, than interrupt driven operation. If a CPU is mostly doing IO, polling for work can be a much better approach. Jens Axboe has been working on adding polling to the I/O stack for a while [1], and has recently added a new API for submitting I/O that is very promising [2] (25-33% performance improvements on I/O heavy workloads).

[1] https://lwn.net/Articles/705315/

[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by _msw_ on Tuesday May 07, 2019 @05:29PM (#19853621)
Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by stcredzero on Friday May 03, 2019 @09:01PM (#19823582)
Mainframes had, and have, "channels". A channel is part of the processor architecture. It takes commands, sends them to a peripheral, and manages the data transfer in both directions. Channels have some privileged functions through which the OS tells them where the data is supposed to go in memory. The architecture of channels is well defined, and peripherals are built to talk to channels. The CPU has I/O instructions to control channels in a well defined way.

I need these! Not for communication between the program and peripherals. I'd like to have these for communication between processes, threads, and software Actors. I'd like to be able to map such hardware channels to channels in Golang. What we have today are software channels implemented with, "heavy kernel mediation between the hardware and the user program," which means that one may be required to think a bit too much about how processes communicate with each other, and the performance implications and how these mechanisms can break down.

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by michaelmu on Friday May 03, 2019 @01:48PM (#19820572)
Thanks for this explanation. Super interesting!
Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by temac on Friday May 03, 2019 @04:15PM (#19821863)
The PS/2 was not successful not because of technicalities but because IBM did not want it to be cloned. Third parties decided what the PC should be (mostly continue to be, there was less differences between cloners and the original PC than with the PS/2), and IBM followed. In insight, the PS/2 could not win in this context, because IBM did not matter anymore very early on for the history of the PC, regardless of peripheral vendors. This market was never driven by peripherals anyway, especially not internal extension boards.

You can use VFIO, yes it needs an IOMMU but that basically what you ask for: hardware support - and yeah, I would like IOMMU to be generalized, also because it is dangerous to have some external ports without one, nowadays (even without thinking about efficient access from userspace). And because of that you can not delegate the core of the thing to "peripheral" anymore, basically you need IOMMU and once you have it, well what else do you need?

On the storage level, you can mmap on Optane on DDR4 without intermediate software copy I think. But that's merely an implementation detail anyway. When you think about the complexities of modern controllers and the diversity of options to implement them - and at the same time the most important latencies; well the only thing that matter is the end result, and obviously it can be better to not burn some CPU cycles in some cases (for some very specific workloads), but it is not trivial what to put in HW or SW to achieve that: RAM is already crazy slow, and the faster SSD is still even slower: so you will need to be smart in SW anyway to not be bitten by latencies. So in a sense; no! modern CPU are certainly not slow!

I also think you misrepresent the common modern interfaces availables for (even interoperable) SSDs; they are certainly not "emulat[ing] rotating disks".

I'd like that you give the following some thought to finish: 1/ HW backward compat is not a prime requirement anymore (because a/ smartphone dev model b/ even PC model has shifted enough so that it actually does not support complete backward compat anymore, mostly due to SoC integration). 2/ There is "sufficient" competition, where sufficient can be defined as effective to drive innovations because they can bring market advantages, and there are a non trivial number of competitors on the market (I'll mix a little but this is still relevant to what we are talking about: Intel, AMD, Arm, nVidia, Apple, Samsung, etc.) 3/ The designers working on those chips and systems are not stupid. What we have now is of course affected by technical history, but what we have now is already immensely different from what we had during the PS/2 era. Some of the historical impacts are possibly confined in less than a square millimeter on chips, and not only your PCI was not your ISA but your modern PCIe is also already quite different from your PCI... So the impact of peripheral vendors in the PS/2 era today for all of that: absolutely null, without a doubt.

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by tux1968 on Friday May 03, 2019 @05:46PM (#19822581)
> basically you need IOMMU and once you have it, well what else do you need?

Not sure where this exploit[1] stands now, but you may need a clean slate implementation that doesn't have to boot up with IOMMU disabled for legacy reasons.

[1] https://journal-bcs.springeropen.com/articles/10.1186/s13173...

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by bogomipz on Friday May 03, 2019 @07:17PM (#19823107)
>"Mainframe designers had this problem under control by 1970. Mainframes had, and have, "channels". A channel is part of the processor architecture."

What are some examples of these processors?

I would be interested in reading more about these mainframe processors architecture. Might you or anyone else have some links?

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by neop1x on Saturday May 04, 2019 @02:07PM (#19828126)
It is always surprising for me to see how mainframes have always been one step further. I don't have any experience with them but I've learned that there have been for example live VM migrations between hosts for a long time already. And that there was a cool system called IBM AS/400 introduced in 1988 with integrated database and "everything is an object" design and peripherals with processors and which is still being used for some critical applications today. Our x86 clouds with Kubernetes may sometimes feel like a bunch of cheap toys in a way. :P
Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by minipci1321 on Saturday May 04, 2019 @07:43AM (#19825851)
Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by p_l on Saturday May 04, 2019 @10:02AM (#19826495)
MCA was normal DMA bus, including extensions to use it as memory bus (which added few pins to help recognize a memory card and manage it, with plain MCA transfers for access)

Closest to complex "IO Channel Program" on PCs was I2O which largely tanked despite leaving huge mark on SCSI controller design.

Re:I/O Is Faster Than CPU – Let’s Partition Resources and El... by dooglius on Friday May 03, 2019 @02:50PM (#19821173)
This sounds pretty similar to what goes on now, except that the channel processor sits on the other side of the (e.g.) PCIe connector.