14
$\begingroup$

I can't seem to get a straight answer as to what a CPU clock is.

I know there are quartz crystal clocks that work by the bending of quartz that happens as an electrical current is passed through it. Do modern CPUs also use a crystal with the same property?

$\endgroup$
8
  • 2
    $\begingroup$ Too short for an answer, but this explains most that is to know, and has plenty of links: en.wikipedia.org/wiki/Clock_generator $\endgroup$
    – AnoE
    Aug 24, 2022 at 8:27
  • 18
    $\begingroup$ This seems like it would be more on-topic on electronics.stackexchange.com, since you're asking about circuit implementation details, like how it's generated outside the CPU itself. (Although typically a CPU only gets a clock input of 100MHz or so (base clock), and multiplies it internally.) $\endgroup$ Aug 24, 2022 at 11:04
  • 3
    $\begingroup$ I have to recommend Ben Eater's outstanding videos on the topic. Start here! $\endgroup$
    – Wyck
    Aug 24, 2022 at 14:36
  • 7
    $\begingroup$ I don't think this is in the realm of computer science. As everybody knows, computer science is neither about computers nor science. $\endgroup$ Aug 25, 2022 at 0:18
  • 2
    $\begingroup$ Traditionally, it has been quartz crystal oscillators. But there are many, many ways to create an oscillator. Atomic clocks are coming down in price and size. Smaller, cheaper systems use internal or external RC oscillators or ceramic oscillators (typically 0.5% frequency accuracy, but often 0.1% frequency accuracy for automotive applications). $\endgroup$ Aug 25, 2022 at 0:30

4 Answers 4

37
$\begingroup$

Modern clocks are originally generated by quartz crystal oscillators of about 20MHz or so, and then the frequency is multiplied by one or more phase-locked loops to generate the clock signals for different parts of the system. (such as 4GHz for a CPU core).

This is mostly a question of electronics design, though.

$\endgroup$
9
  • 1
    $\begingroup$ ah, okay. And so the crystal serves as a transformation between straight electricity and an oscillating voltage, which I assume gets multiplied and then gated somehow to produce an on/off cycle? $\endgroup$
    – Ryan Folks
    Aug 24, 2022 at 17:01
  • 1
    $\begingroup$ The principle is that if you know enough about electronics, you can use a 20 MHz quarts to produce a 4,000 MHz clock signal. How it works is beyond me, but that's 100% what they do. Higher frequency quartz chips seem to be available, but nowhere near the Gigahertz range. And I don't know how stable and reproducible the frequency is, and at what cost and size. $\endgroup$
    – gnasher729
    Aug 24, 2022 at 18:39
  • 5
    $\begingroup$ @RyanFolks: Almost. It would be better to say that the crystal serves two functions: (1) it mechanically resonates at a particular frequency (like the ringing of a bell), and (2) it couples that mechanical oscillation with an electrical voltage. Simply applying a DC voltage to the crystal does nothing. But when it's incorporated into an oscillator circuit, the crystal selectively filters and resonates only with electrical oscillations of a particular frequency. The oscillator uses feedback and amplification to reinforce that frequency and generate a usable clock signal. $\endgroup$
    – David
    Aug 24, 2022 at 23:37
  • 2
    $\begingroup$ How clock multiplication works is that the basic signal like 20 MHz is distorted, which creates harmonics to which a PLL can be locked to generate a wave at that frequency. You can then lock a higher frequency clocks to a harmonic. E.g. if we take the first harmonic, we can make a 40 Mhz clock out of it. Second harmonic would give us 60 and so on. I'm guessing this can be cascaded; instead of taking something like the 10th harmonic of a base signal, which seems difficult, use several frequency multiplying stages cascaded together. $\endgroup$
    – Kaz
    Aug 25, 2022 at 7:05
  • 3
    $\begingroup$ @Kaz Maybe that's one way a PLL can work, but in reality, they are trying to copy a clock frequency but with an adjustable divider in the feedback path, so they act as adjustable multipliers $\endgroup$
    – user253751
    Aug 25, 2022 at 13:04
7
$\begingroup$

A CPU clock is a signal which is used for two related purposes:

  1. Devices that are synchronous to a common clock agree that they will only look at signals from other such devices within a very short window after the clock changes.

  2. Devices which are synchronous to a common clock agree that within that window they will never change any signals that are of interest to other such devices.

A very important feature of such systems is that there is never any ambiguity over which of two things happens first. Instead, either one will happen on an earlier clock than the other, or they will happen on the same clock in which cases they are unambiguously tied.

If computers would always process all operations in a fixed sequence that is decided in advance, it could have the circuitry that performs each operation wait until all preceding operations are done, without any need for a clock. Some parts of systems are sometimes designed that way, but in many cases some resources will be required to perform several operations, and it may be desirable to allocate the resource immediately to whichever operation is ready to use it first, and then have any later operation that needs the resource wait until the first operation is done with it. In systems that don't use clocks, however, this will create a problem.

If two operations that would need a resource become ready simultaneously, it is necessary that the circuits that would perform the operations both agree on which one should go first, before either proceeds. If each tasks thinks it should go first, the tasks will grab the resource simultaneously (oops). If each task thinks it should defer to the other, the tasks will deadlock waiting for each other to complete.

There are ways of resolving such situations in asynchronous systems by having both tasks recognize a window in which the other task might have beaten them, and will back off for an amount of time based upon how far they think were from the edge of that window, and then see if that results or one side or the other winning unambiguously (backing off again if it doesn't). Unfortunately, while the probability of a tie lasting for more than t microseconds would decrease exponentially with t, it's often difficult to parameterize how fast that will occur.

Having devices operate synchronously fixes this, since it makes it possible to design two circuits so that X will take a resource as soon as it becomes ready unless Y had been ready for it during the previous observation window, and Y will take the resource as soon as it's ready unless either X was ready for it in the previous window, or has become ready in the current window. While the likelihood that X and Y become ready "simultaneously" would be much greater than in the asynchronous system, such occurrences wouldn't cause problems.

While there are a variety of ways that a computer can generate the clock signal which is used to coordinate communication among the many components, an understanding of the purpose of the clock is far more important, especially from a computer-science perspective, than knowledge of the particular means used to generate it, and the principles involved are very similar to those involving long-range networking.

$\endgroup$
6
  • 2
    $\begingroup$ The question asked for what the clock is physically, not logically. This answer is answering a completely different question very well. $\endgroup$ Aug 26, 2022 at 23:42
  • $\begingroup$ @AdamBarnes: A CPU clock is, physically, the signal that is used as described. The equipment that generates a clock would typically have been a quartz oscillator, but nowadays would more often be something else. I answered the question in the title, which I viewed as more interesting than question of how clocks are generated, since many people who encounter the question would do so based upon the title. $\endgroup$
    – supercat
    Aug 27, 2022 at 18:09
  • $\begingroup$ "Which I viewes as [a] more interesting question" Then go ask it Q&A style - this question is about what a clock is physically, as you can see from all of the other answers, including the accepted answer, if not from the question itself. $\endgroup$ Aug 28, 2022 at 2:46
  • $\begingroup$ @AdamBarnes: I answered the question in the title, which is what people who find the page are as likely to be interested in as the question of how clocks are generated, and answers are supposed to serve not only the original poster but also people who arrive at the page later. If I were to author a separate post which actually asked the question in the title of this post, it post would probably get closed as a duplicate referenced to this one, so what would be the point? $\endgroup$
    – supercat
    Aug 28, 2022 at 6:20
  • 1
    $\begingroup$ The question in the title is asking what the clock is physically, and there is no edit history on the post. $\endgroup$ Aug 28, 2022 at 8:33
6
$\begingroup$

This is a picture of a DIY quartz clock:

quartz clock

This is (part of) a picture of a mainboard:

mainboard

Note the component I have marked with an arrow. You can see they look identical.

Some caveats:

  • Quartz crystals come in different packages, I have chosen two examples that happen to use the exact same package.
  • They will have different frequencies: mainboards usually use 14.318 MHz (I think that's a relic of TV output in early PCs), quartz clocks usually use 32.768 kHz (this one uses 12 MHz probably because their microcontroller can't run on such a slow clock).
  • The CPU does not use the 14.318 MHz directly but it is multiplied by a PLL circuit, possibly in one of the black ICs on the right side of the image.
$\endgroup$
2
  • 1
    $\begingroup$ Indeed, 14.318MHz (actually 315/22 MHz) is the NTSC master oscillator frequency. $\endgroup$
    – TLW
    Aug 25, 2022 at 18:57
  • 1
    $\begingroup$ … and it was chosen because TV is a mass market application and thus TV components are cheap – especially in the late 1970s / early 1980s when the PC was designed and computers were not mass market (yet). $\endgroup$ Aug 26, 2022 at 6:51
-1
$\begingroup$

I beleive modern cpus require a click source signal which is usually generated by a capacitor circuitry rather then a crystal. I Beleive crystals and other ics are used more for arm mcu. For CPU’s an llc circuit is used to deliver the clock source.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.