| Can you please explain how does RAM come into play when the computer runs and how the CLOCK comes into play while the computer runs? |
RAM is used to store data, just like a hard drive or a CD. The CPU itself also has memory in it that can be used to store data. The key performance difference is speed. The memory in the CPU is much much faster than RAM, which itself is much much faster than a mechanical hard drive. However, faster memory is expensive. Memory on the CPU is much much more expensive than RAM, which itself is much much more expensive than a mechanical hard drive.
For these reasons computers use many types of memory in a hierarchy. Data that is actively being used is stored in the CPU's memory, data that is likely to be used soon or has been used recently is stored in RAM, and data that is not likely to be used anytime soon is stored on the mechanical hard drive. This hierarchy allows lots of data to "share" very fast memory without having to pay for hundreds of gigabytes of very fast memory.
The computer frequently duplicates data between the different memory systems. Which data is duplicated depends on what programs you are currently executing.
RAM does not perform swapping or process management, these features are facilitated by special hardware in the processor, but are primarily implemented in the operating system software (which is stored in memory and uses the CPU).
Swapping occurs to free up extra RAM. It is most prominent when insufficient RAM exists to support all of the programs that are requesting to store data in RAM. Swapping works by copying sections of RAM to the mechanical hard drive. If that section of RAM is needed later by the executing program it is then necessary for the computer to copy the data back from the hard drive to RAM. (Doing this will often require some other section of RAM to be copied to to the hard drive to make room). This process is very slow due to the fact that the hard drive is so much slower than the RAM.
The computer's clock is used to synchronize operation of the processor. In modern CPUs it does not directly indicate how quickly the processor can carry out instructions. Modern CPUs are designed like an assembly line, there are many stations that perform a very small part of executing a single instruction. The clock speed describes how long the processor waits for each station to complete its job before the instruction is shifted to the next station. For example, in a 3Ghz CPU the instruction will shift to the next station every 0.334ns.
However, the "assembly line" is orders of magnitude more complex than an assembly line that you would find in a factory. Knowing the clock speed tells you very little about how quickly the processor can execute instructions because:
- different instruction types require different numbers of stations to complete
- the processor will have more than one instruction executing at the same time... but
- some instructions will cause all instructions that are currently executing to be cleared from the "assembly line" (any partial results are discarded)
- some stations are duplicated so more than one instruction can use them at the same time
- modern CPUs usually have multiple cores, so there are multiple independent assembly lines
- some instructions will cause the processor to stall (not move any instructions to the next station)
All of these factors are dependent on the design of the CPU architecture. The exact same instructions will be handled differently by different CPU architectures. Additionally, different architectures divide up the steps of executing an instruction (the "stations") differently.
For example, the Cedar Mill
revision of the Pentium 4 processor used up to 31 stations to execute a single instruction. The competing AMD processors had many fewer stages, and were able to execute instructions with fewer clock cycles. This is a significant contributing factor to why they were able to outperform the Pentium 4's even though the P4's were clocked at least 1Ghz higher.
This is why you can only compare clock speed between processors that use the same architecture.
** Note that the "assembly line" example is not standard terminology. The "assembly line" is called a pipeline, and the "stations" are usually called stages.