Power State Model

 

We model a power state machine that transitions the system through a set of states in order to reduce the power consumption of the system. It consists of 4 states namely the Active, Idle, Sleep1 and Sleep2 as shown in Figure 1. The system is initiated in the Active state and remains in this state as long as it receives a task. If the system receives no task for a period of T1, it transitions to the Idle state and reset the timer. In the Idle state as soon as the system receives a task it transitions back to the Active state. If in this state, no task is received for a period of T2, the system moves out of the Idle state and transitions to the Sleep1 state. Finally, if the system does not receive a task in the Sleep1 state for a period of T3, it transitions to a deeper sleep state Sleep2 and remains in this state as long as it receives a task. In any of the power saving states if a task is received, it moves the system to the Active state.

 

Figure 1

 

 

 

 

Each state has a number of different FSM's embedded within it that interacts with each other. All the states except Sleep2 have a FSM timer embedded within them that keeps track of how long the system has been idle. Furthermore, all states have a sampler that checks for a task every T4. The Active state also has an FSM service provider within it that processes a task for a period of T5. A task received by the system is queued on a global bounded queue, therefore every state has access to this queue. Once the queue has reached its maximum size, the following tasks received by the system is lost. The service provider requests for a task from the queue and in turn the queue pops a task for the service provider. The transition diagrams for the different components with in a state are shown in Figure 2.

 

 

Figure 2

 

 

Implementation of the Power State Model

 

 

          using namespace std;

          using namespace Untimed;

 

          typedef signalstruct<int> signal;

          typedef signalstruct<signal> list;

          #define QueueSize 5

          #define IdleThreshold 5

          #define Sleep1Threshold 10

          #define Sleep2Threshold 20

          #define ServiceExpiry 2

          #define task 1

          #define no_task 0

          #define ACTIVE 0

          #define IDLE   1

          #define SLEEP1 2

          #define SLEEP2 3

 

          signal updateState(signal s, int v, int t)

          {

                   signal osig;

                   osig.insert(v);

                   osig.insert(t);

                   for(int i = 2; i < s.length(); i++)

                   osig.insert(s[i]);

 

                   return osig;

          }

 

          signal updateQueue(signal s)

          {

                   signal osig;

 

                   for(int i = 0;  i < 2;  i++)

                   osig.insert(s[i]);

                   osig.insert(0);

                   for(int j = 4; j < s.length(); j++)

                   osig.insert(s[j]);

 

                   return osig;

          }

 

          signal UpdateSP(signal s, int val)

          {

                   signal osig;

                   osig = take(s,2);

                   osig.insert(val);

                   osig = append(osig,drop(s,3));

 

                   return osig;

          }

 

          int getTimer(signal s) { return head(tail(s)); }

          int getState(signal s) { return head(s); }

          int getServiceProvider(signal s) { return head(drop(s,2)); }

          signal getQueue(signal s) { return drop(s,3); }

 

          class moore

          {

                   public:

                   signal w;

 

                   moore()

                   {

                             w.insert(ACTIVE); // Initialize the State - 0 is the Active State

                             w.insert(0);                           // Initialize the Timer

                             w.insert(0);                    // Initialize the Service Expiry Timer

                             }

                   ~moore() {}

                   signal outputfn (signal cstate)

                   {

                             signal osig;

                             osig.insert(getState(cstate));

                             return osig;

                   }

 

                   signal nextstatefn (signal cstate, signal input)

                   {

                             signal newstate;

 

                             int Tval  = 0;

                             int SPval = 0;

 

                             Tval  = getTimer(cstate);

                             SPval = getServiceProvider(cstate);

 

                             signal Q;

                             Q = getQueue(cstate);

 

                             if(head(input) == no_task) Tval = Tval + 1;

                             if(getState(cstate) == ACTIVE) SPval = SPval + 1;

 

                             if(getState(cstate) == ACTIVE) // In the Active State

                             {

                                      if(Tval > IdleThreshold && head(input) == no_task)

                                      {

                                                if(SPval <= ServiceExpiry)

                                                {

                                                          newstate = append(newstate, updateState(cstate,1,0));

                                                          newstate = UpdateSP(newstate,SPval);

                                                          return newstate;

                                                }

                                                else

                                                {

                                                          newstate = append(newstate, updateState(cstate,1,0));

                                                          newstate = updateQueue(newstate);

                                                          return newstate;

                                                }

                                      return cstate;

                                      }

                                      else if(Tval <= IdleThreshold && head(input) == no_task)

                                      {

                                                if(SPval <= ServiceExpiry)

                                                {

                                                          newstate = append(newstate, updateState(cstate,0,Tval));

                                                          newstate = UpdateSP(newstate,SPval);

                                                          return newstate;

                                                }

                                                else

                                                {

                                                          newstate = append(newstate, updateState(cstate,0,Tval));

                                                          newstate = updateQueue(newstate);

                                                          return newstate;

                                                }

                                      return cstate;

                                      }

                                      else if(head(input) == task)

                                      {

                                                if(SPval <= ServiceExpiry && Q.length() != QueueSize)

                                                {

                                                          newstate = UpdateSP(cstate,SPval);

                                                          newstate.insert(head(input));

                                                          return newstate;

                                                }

                                                else if(SPval > ServiceExpiry && Q.length() != QueueSize)

                                                {

                                                          newstate = updateQueue(cstate);

                                                          newstate.insert(head(input));

                                                          return newstate;

                                                }

                                                else if(SPval > ServiceExpiry && Q.length() == QueueSize)

                                                {

                                                          newstate = updateQueue(cstate);

                                                          newstate.insert(head(input));

                                                          return newstate;

                                                }

                                                else if(SPval <= ServiceExpiry && Q.length() == QueueSize)

                                                {

                                                          newstate = UpdateSP(cstate,SPval);

                                                          return newstate;

                                                }

                                      return cstate;

                                      }

                             return cstate;

                             }

 

                             else if(getState(cstate) == IDLE) // In the Idle State

                             {

                                      if(Tval > Sleep1Threshold && head(input) == no_task)

                                      {

                                                newstate = append(newstate, updateState(cstate,2,Tval));

                                                return newstate;

                                      }

 

                                      else if (Tval <= Sleep1Threshold && head(input) == no_task)

                                      {

                                                newstate = append(newstate, updateState(cstate,1,Tval));

                                                return newstate;

                                      }

                                      else if (head(input) == task && Q.length() != QueueSize)

                                      {

                                                newstate = append(newstate, updateState(cstate,0,0));

                                                newstate.insert(head(input));

                                                return newstate;

                                      }

                                      else if (head(input) == task && Q.length() == QueueSize)

                                      {

                                                newstate = append(newstate, updateState(cstate,0,0));

                                                return newstate;

                                      }

                             return cstate;

                             }

 

                             else if(getState(cstate) == SLEEP1) // In the Sleep 1 State

                             {

                                      if(Tval > Sleep2Threshold && head(input) == no_task)

                                      {

                                                newstate = append(newstate, updateState(cstate,3,Tval));

                                                return newstate;

                                      }

                                      else if(Tval <= Sleep2Threshold && head(input) == no_task)

                                      {

                                                newstate = append(newstate, updateState(cstate,2,Tval));

                                                return newstate;

                                      }

                                      else if(head(input) == task && Q.length() != QueueSize)

                                      {

                                                newstate = append(newstate, updateState(cstate,0,0));

                                                newstate.insert(head(input));

                                                return newstate;

                                      }

                                      else if(head(input) == task && Q.length() == QueueSize)

                                      {

                                                newstate = append(newstate, updateState(cstate,0,0));

                                                return newstate;

                                      }

                             return cstate;

                             }

 

                             else if(getState(cstate) == SLEEP2) // In the Sleep 2 State

                             {

                                      if(head(input) == task && Q.length() != QueueSize)

                                      {

                                                newstate = append(newstate, updateState(cstate,0,0));

                                                newstate.insert(head(input));

                                                return newstate;

                                      }

                                      else if(head(input) == task && Q.length() == QueueSize)

                                      {

                                                newstate = append(newstate, updateState(cstate,0,0));

                                                return newstate;

                                      }

                                      else if(head(input) == no_task)

                                      {

                                                newstate = append(newstate, updateState(cstate,3,Tval));

                                                return newstate;

                                      }

                             return cstate;

                             }

                   return cstate;

                   }

 

                   int partitionfn (signal s) { return 1; }

          };

 

          int main()

          {

                   moore mooreobj;

                   signal input;

                   /* ... Intialize the input signal ... */

                   signal output = mooreU(mooreobj,input);

                   return 0;

          }