I am not sure if this is the best sub for my question... I hope though that the mods can help me move the thread to appropriate place if I misplace it.
I am currently in a operating system class, and I have a question related to thread switching and save the previous thread when switch. So the question is like this:
The use of Hardware Threads or Hyper-threading is becoming commonplace in the design of
new processors. For example, the Core i3 and i5 lines include hardware provisions to handle two
hardware threads per processor (core). This is done by duplicating those parts of the processor
that store the architectural state, namely, the control and general purpose registers, but not
duplicating the main execution resources (e.g., pipelining). In short, only one of the hardware
threads can be executing, but each one of the two hardware threads has its own set of registers.
Assume that your architecture has two cores (processors), each equipped with two hardware
threads. Assume you are running a process composed by 8 threads, each connecting to a
lightweight process (thus, visible to the kernel as kernel threads). Each of the threads repeats the
following cycle a large number of times:
CPU usage 10ms, I/O 10ms
Assume that the scheduler switches threads every 5 ms. Fill out a table like the following, indicating the
state of each of the threads at every interval. Also, indicate, by the symbols S, and NS whether the
switch caused the saving (or not) of the architectural state of the preempted thread. Assume that no
other process or thread is present in the system.
5ms 10ms 15ms 20ms 25ms 30ms 35ms 40ms 45ms 50ms 55ms 60ms
I know that because there is 2 Hardware threading in 1 processor, so the process could have 2 thread run concurrently... and when it switch from T1 and T2 to T3 and T4, T1 and T2 go to ready state. How do the saving of the thread happen? According to the solution my professor give, the saving of T1 and T2 only occur when T5 and T6 go to the running state, but not when T3 and T4 at the running state. My question is why it doenst save immediately when it switch to T3 and T4 threads?