next up previous
Next: Embedding industrial applications. Up: Results Previous: Task decomposition

Controlling the use of CPU by rtlinux threads.


\begin{displaymath}
\mbox{
\epsfxsize =70mm
\epsffile{images/usage2.eps}}
\end{displaymath}

% latex2html id marker 1104
$\textstyle \parbox{7cm}{{\bf FIGURE \arabic{figcounter}:}\quad {\it Task CPU usage measure. } }$
void usage_PI_ctrl(long long usage,unsigned long ref, int ntasks,pthread_t threads[],hrtime_t t_usage[]){
                      .............  
  if (iter>15)
    {
  // calculate error.
  E=(double)((ref-usage)/100*1000);
  
  // PI.
  U=(double)(U_bef+ (double)(1.1*E) - (double)(0.99*E_bef));

  period=(long long)(((double)((6*100*1000)/U))*1000*1000);

  // Apply new periods.
  for (i=1;i<ntasks;i++)
    if (period>1*1000*1000) threads[i]->period= period;

  //finally actualize U_bef and E_bef.
  E_bef=E;
  U_bef=usage;
    }
  iter++;
}



Josep Vidal Canet 2003-04-24