Channels ▼

Al Williams

Dr. Dobb's Bloggers

Processor Interruptus

October 23, 2011

Every so often I like to sit down and think about how to do things differently. What would a language based on tree structures look like? How could you do parallel computing in a general way with no effort? What would a CPU look like if you had no preconceptions?

That last one is a favorite of mine since I enjoy designing CPUs (yes, I need to get out more). One result of that kind of brainstorm was Oneder, my CPU that uses a single instruction.

I do tend to go down the same rat hole when I think about alternate CPU architectures, however. I start to think about how software has become event driven. Then I have the brilliant flash of insight that we could make an event-driven CPU. Then I realize that I am reinventing interrupts, again.

Interrupts are a great thing, of course, although they are notoriously difficult to get right. The Apollo Guidance Computer, for example, wound up having interrupt overruns during the first moon landing. But the idea is simple. The CPU gets some sort of stimulus, saves what it is doing, does something else to respond to the stimulus, and then keeps right on going where it left off. Modern operating systems like Windows or Linux would be hard to imagine without interrupts. Many embedded systems use interrupts for tasks ranging from dealing with time-critical input, generating periodic waveforms, or waking a processor up while it mostly sleeps.

But are interrupts necessary? I don't mean can we make a stripped down CPU that doesn't use interrupts. Of course you can do that. I mean, can we think of a generally applicable CPU architecture that doesn't need interrupts to get common jobs done?

I keep trying to think about that, but I don't have much success. However, my old friends at Parallax dreamed up a way around the interrupt problem. I'm not sure I'm totally sold on it, but I will admit it is novel and gets rid of the interrupts at the user program level.

The Parallax Propeller chip doesn't use interrupts. What's the alternative? The simple answer is polling. You don't need interrupts if you just sit and wait for your external stimulus to happen. Of course, that's not fair, right? The whole idea of interrupts is that you can do things while you are waiting for the stimulus to happen. Well, that's why the Propeller has 8 separate CPUs.

The idea is that instead of writing an interrupt handler and making the single CPU stop what it is doing when an interrupt stimulus arrives, a Propeller programmer just dedicates a whole CPU (a cog) to waiting for that event. The cog goes to sleep, and wakes up to service the event without impacting any of the other cogs.

That has several advantages. First, it is clean and simple. It is also highly deterministic. You can even service multiple events at once. What's the downside? Coordinating the cogs is a bit difficult. If you need to use shared resources, there is a round-robin scheme to allow each cog a turn at the common items.

The Parallax Spin language helps manage it all in a high-level language, although I'm not a fan of the Python-style space indentation, which Spin uses.

Here's a snippet of Spin example code from the Parallax documentation:

  routine1_cog := cognew(Parallel_Routine_1(6, 365, -1), @cogStack[0]) + 1  
  routine2_cog := cognew(Parallel_Routine_2, @cogStack[50]) + 1

This might look like starting two new tasks, but in fact, it is allocating two CPUs (cogs) to run some code independently.

I hear Parallax is working on a new version of the Propeller, and honestly I don't know how popular they are in commercial designs or even hobby designs. But that's not really my point. My point is that even though we all know that a CPU has to have interrupts, here's an example of a highly useful one that does not have interrupts. You have to wonder what other novel architectures we could find — maybe some far better than what we have today — if only we would think outside of the chip. Well. Outside of the box.

Are you using the Propeller? Or some other novel architecture? What would persuade you to adopt a radical new architecture? Leave a comment and share your thoughts.

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video