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++; }