Productivity and Context Switching

The way that computer scheduling works is that you have several tasks running at a time, in a queue for the processor. In multicore and multiple processor situations, you can think of it as being the same but with  multiple queues each with several tasks. So what happens is that the first task gets the attention of a cpu and its data is loaded into cpu cache and the cpu starts executing the instructions at lightning speed until one of three possible things happen:

  1. The cpu gets interrupted to do something urgent.
  2. The task interrupts itself by sending a call to a peripheral e.g. a request to read data from a disk.
  3. The task runs out of its allotted time.

The first of these situation is a regular event, because the cpu is responsible for the operating system and if something needs doing to manage the computer then that takes priority over any application. The second situation is also a regular event. Most programs do not spend much time on the processor before they need to call for something. There are programs that do. For example, you can calculate pi to 50,000 decimal places and that’s a cpu-only task. The third situation is how a task like calculating pi to 50,000 decimal places gets evicted from the cpu. It uses up its time.

When a task gets evicted from the cpu it’s called a “context switch”. The data held in cpu cache is unloaded and the program is saved in its current state so that when it gets back into action the cpu can continue from where it left off. New data is then loaded for another process and the program code for that process is loaded and the cpu begins to run it.

Now if you’re a chip expert, you’re probably thinking that the whole context change process in a modern chip is more complicated than that, and indeed it is, but that’s not what I’m interested in here. I’m interested in the fact that context switching is expensive in terms of computer time. When a context switch occurs the cpu doesn’t just point itself at another string of instructions and start to plough through them, it unloads one instruction stream and its associated data and loads up another one before it gets on with the work it is supposed to be doing. For that reason, operating system scheduling algorithms are based on trying to minimize context switching while still balancing the work done between various competing programs.

The Human Context Switch

As far as context switching is concerned there’s a direct parallel between the human being and the computer. People also becomes less productive if there is too much context switching. Context switches occur for three reasons:

  1. You get interrupted to do something urgent – like answer the telephone.
  2. The task you are engaged in has to be set aside while you wait on someone else to do something – or possibly you are forced to change roles. For example, you need to “stop for gas.”
  3. You run out of the allotted time – you have to “go to a meeting” or whatever.

If you focus in on how you use a computer, you seem the same thing going on you flit from one application to another often leaving things incomplete because of interruptions.

The Antidote to Your Context Switching

There are two things that can be done to improve the situation, whether we are thinking in terms of how you do your job or how you use a computer:

  • Minimize interruptions
  • Organize and schedule your activities

I’ll have more to say about both these things in follow-on postings.

Leave a Reply

Improve the web with Nofollow Reciprocity.

Bad Behavior has blocked 300 access attempts in the last 7 days.

SEO Powered by Platinum SEO from Techblissonline