What does the processor do when I copy things from one USB disk to another?

21

1

Is all data that I copy going through it or is there another more direct way?

Felix Dombek

Posted 2011-02-04T12:04:19.993

Reputation: 1 729

The processor is active and in control with USB, but not with firewire (as that card has its own cpu) – tobylane – 2011-02-04T20:58:49.187

Answers

31

Tricky one! Data doesn't really go through the CPU per se.

Data and the critical 1's and 0's go through the chipset, or dedicated I/O chips and memory, however, when you are copying files, the command to do the copy gets run by the processor.

Imagine having an object in front of you (the data), your arms (Chipset/I/O chip), and your brain (the CPU). You do not actually use your brain to move the object, your brain runs the "command" to your arms to move the object.

William Hilsum

Posted 2011-02-04T12:04:19.993

Reputation: 111 572

The problem with this explanation is that it only applies to DMA. On Intel and most other chipsets, in any case that DMA is not being used, the CPU will do the work. In this case the OP description is actually more accurate. This will apply to older systems (as in classic at this point), micro controllers, faulty disk controllers or setups that are otherwise incompatible with DMA. – krowe – 2018-07-05T03:51:46.443

1Nice metaphor, @Wil. – Shinrai – 2011-02-04T16:19:48.863

4@Shinrai - although, it doesn't stand up if they are psychic! I would love to move the object with my brain! – William Hilsum – 2011-02-04T16:24:32.893

Didn't DMA or something bypass the CPU? – o0'. – 2011-02-04T16:30:54.930

2DMA helps by giving the CPU an interrupt whenever an IO command to a block device, such as a USB stick, has completed. The CPU then continues executing the copying. In fact, what the CPU is doing is running kernel-ioctl code that interfaces with the device drivers to copy chunks (the actual name) over DMA. The CPU also handles asynchronous IO and sync IO slightly different from a kernel-code-executing-perspective. – Henrik – 2011-02-04T16:39:17.653

The second paragraph isn't very clear. – tshepang – 2011-02-04T19:32:26.687

@Tshepang which is why I wrote the metaphor. – William Hilsum – 2011-02-04T20:01:49.400

I mean there's a grammatical error... a missing comma or period? – tshepang – 2011-02-04T20:08:09.013

+1 good explanation. @Tshepang: I'm guessing that it sounds a little weird because you wouldn't usually say "Imagine having your arms" or "Imagine having your brain" – Justin – 2011-02-04T20:26:32.610

@jus You are talking about the 3rd par and I'm talking about the second. – tshepang – 2011-02-04T20:29:41.927

@Tshepang - I didn't really see a problem, but is it better now? – William Hilsum – 2011-02-04T20:47:27.063

Definitely better. One more quibble: Please split it in two sentence. That is, put a period between "memory" and "however". Once that is the case, you'll be a rockstar (which you already are.... look at all the rep). – tshepang – 2011-02-04T20:59:12.957

1I don't do it for the rep, just love this site and helping people! I don't really think it is better as two sentences, but hopefully it is better now.... if you don't like it, I think there is a new thing for lower members, try editing it yourself! – William Hilsum – 2011-02-04T21:11:58.347

Nice answer! I'm going to use this going forward when describing data transfer to users. – Supercereal – 2011-02-04T21:18:43.530

@Henrick The CPU does not get involved in any form of copying during a DMA operation. When a DMA request is programmed into a DMA controller, the controller is given a memory source address, a destination address and a memory count. As soon as a DMA Request is then issued, the DMA controller instructs the CPU to float off the data and address buses and then directly controls the memory read/write and address lines to force data to transfer rapidly from one location to another in cycles much smaller than the CPU's own. When the DMA request has completed, the CPU returns to the buses. – Linker3000 – 2011-02-04T21:27:01.943

One further way to extend the metaphor that I've used before - hard drives are the shelves where you keep all your files or tools, and the RAM is the workbench or desktop you actually do your tasks on. – Shinrai – 2011-02-04T22:04:02.850

5

The CPU has to run the program that reads the source file and then writes the destination file.

The data that's read will (usually) be read into main memory in chunks, but doesn't actually go through the CPU.

ChrisF

Posted 2011-02-04T12:04:19.993

Reputation: 39 650

4

On a mainframe with intelligent channels, the cpu would just tell the channels to do the copy. Very efficient and allows for fast large backups with little CPU overhead.

Unfortunately, we don't have intelligent channels so the CPU ends up in a loop similar to:

for each file(dev1); do 
   createfile(dev2);
   copyfilecontent(dev1, dev2);
end;

The CPU overhead is not that high unless there are lots of small files, especially lots of files in the same directory. The create file operation usually has the highest overhead. Disk to disk copy just treat each disk as a pre-existing file.

BillThor

Posted 2011-02-04T12:04:19.993

Reputation: 9 384

What are intelligent channels? Could you show a pseudo-code snippet for that? – Henrik – 2011-02-04T16:41:17.120

Intelligent channels are hardware devices which handle I/O on mainframes. I expect they are limited functionality microcomputers in their own right. No idea what their code looks like. They were very important when mainframes handled 100's of online users in 8MB of memory. I believe Commodore computers used to have a second CPU in their disk systems. They may have had similar functionality. – BillThor – 2011-02-04T17:00:18.453