Question:
Context Switch and instruction time.?
Francesco Liciulli
2010-07-23 14:02:11 UTC
Hi guys,
I am not able to understand how the operative system can understand when to switch the execution from one process to an other. As far as I understood the cpu works on the instructions without knowing what it is executing.
How is the cpu able to switch from one process to the other? It has a timer? The operative system places a special system call after a specific number of instructions?

Furthermore I don-t understand one simple thing. The insctruction set of a calculator has plenty of instructions but I don-t believe that each instruction take the same amount of time to execute. So how does it work? Is it true that some instructions take more time to execute?

Thank you for the help! If you have any nice article for me to understand better the issue please suggest >D
Three answers:
zoot661
2010-07-25 11:05:27 UTC
The triggers for context switches will depend on the operating system in question.



They are no triggered by the CPU itself, but by a function call by the operating system ( or Kernel code)



This can be as the result of an event ( e.g. an interrupt from the system clock or a serial port ) or calling a system function (e.g. sleep() or write() )



The psuedo code for a system clock interrupt could be something like



incrementSystemTimers()

doContextSwitch()



and the psuedo code for the sleep system call could be something like



calcuateNextExecutionTime()

doContextSwitch()



doContextSwitch() is just another function that is something like



determineHighestPriorityProcess()

saveCurrentProcessContext()

LoadNewProcessContext()



The process context is effectively the state of the processor registers at the time the process is preempted.



The highest priority process that is ready to run is determined by an algorithm in the operating system and will depend on the type of operating system.



If there is no process ready to run then some form of idle process is selected.



The tick timer (or system clock) is programmed by the operating system vendor (e.g. microsoft)



As far as intruction timings are concerned, then normally a processor can only perform a fairly simple operation on each clock cycle (e.g. adding 2 registers together).



Multiplying two registers is normally a more complex operation where for each clock cycle one register is shifted and then added to the other register, thus a 16 bit multiply may take 16 clock cycles.



The multiply operation is controlled by 'microcode' on the processor that effectively runs a very small function



RISC processors had the design aim that they would only support simple operations, meaning that they could execute their instructions in 1 clock cycle, but complicated instructions have to be coded as any other functions would be.





Also, some processors(e.g. DSP's) have dedicated hardware, like barrel shifters than enable them to perform integer multiplications in single instructions
luebano
2016-09-29 04:15:03 UTC
no longer the coolest purchase interior the Bible is literal and historic. areas of it are, and parts of it are metaphorical. There are memories and fables and parables interior the Bible to illustrate it incredibly is efficacious message. Prophecies have been chanced on incredibly often in desires with magnificent visuals. i think one has to account for "clever format" in technological understand-how. That technological understand-how proves God exists with the help of potential of exhibiting how He makes the actual international. Einstein shown that factor isn't static besides the indisputable fact it rather is fluid. If God desires to delivery time around so he made manufacturing in a "week" then that's His option. what's time to God in spite of everything? pupils have been sorting out the Scriptures for 20 centuries and yet they even with the undeniable fact that stand. i'm a techniques from being a pupil, i'm purely a believer on my return and forth, as properly, it incredibly is commonplace as 'faith' for a reason.
anonymous
2010-07-23 15:01:35 UTC
It has a timer.



It's true. An nop takes a lot less time than a multiply.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...