/* * timer_alarm - alarm system call. * * SIGALRM exception is sent to the caller task when specified * delay time is passed. If "msec" argument is 0, stop the * current running timer. */ int timer_alarm(u_long msec, u_long *remain) { struct timer *tmr; u_long left = 0; int s; s = splhigh(); tmr = &curtask->alarm; /* * If the timer is active, save the remaining time * before we update the timer setting. */ if (tmr->state == TM_ACTIVE) left = hztoms(time_remain(tmr->expire)); if (msec == 0) timer_stop(tmr); else timer_callout(tmr, msec, &alarm_expire, curtask); splx(s); if (remain != NULL) { if (copyout(&left, remain, sizeof(left))) return EFAULT; } return 0; }
/* * timer_delay - delay thread execution. * * The caller thread is blocked for the specified time. * Returns 0 on success, or the remaining time (msec) on * failure. */ u_long timer_delay(u_long msec) { struct timer *tmr; u_long remain = 0; int rc; rc = sched_tsleep(&delay_event, msec); if (rc != SLP_TIMEOUT) { tmr = &curthread->timeout; remain = hztoms(time_remain(tmr->expire)); } return remain; }
//[[Rcpp::export]] List gp_gdp(vec y, mat X, mat cand_S, vec init, vec priors, int B, int burn, bool printProg) { int n = y.size(); int num_params = cand_S.n_rows; mat In = eye<mat>(n,n); int acc_rate = 0; mat param = zeros<mat>(B+burn,num_params); double log_ratio; vec cand = zeros<vec>(num_params); vec curr = zeros<vec>(num_params); List ret; clock_t start_time = clock(); int freq = 50; param.row(0) = reshape(init,1,num_params); Rcout << endl; for (int b=1; b<B+burn; b++) { // Update s2, phi, tau: curr = vectorise(param.row(b-1)); cand = mvrnorm(curr, cand_S); // s2, phi, tau, d1,...,dp log_ratio = log_like_plus_log_prior(y,X,cand,In,priors) - log_like_plus_log_prior(y,X,curr,In,priors); if ( log_ratio > log(randu()) ) { param.row(b) = reshape(cand,1,num_params); if (b > burn) acc_rate++; } else { param.row(b) = param.row(b-1); } if (printProg) time_remain(start_time, b, B+burn-1, freq); if (b % freq == 0) start_time = clock(); } Rcout << endl; param.col(0) = exp(param.col(0)); param.col(1) = (priors[3]*exp(param.col(1))+priors[2]) / ( exp(param.col(1))+1 );// inverse logit param.col(2) = exp(param.col(2)); Rcout <<"Acceptance Rate: " << acc_rate * 1.0 / B << endl; Rcout <<"The parameters in $param are 's2,phi,tau'" << endl; ret["param"] = param.tail_rows(B); //s2, phi, tau ret["acc_rate"] = acc_rate * 1.0 / B; ret["y"] = y; ret["X"] = X; ret["cand_S"] = cand_S; return ret; }
/* * Handle clock interrupts. * * timer_handler() is called directly from the real time clock * interrupt. All interrupts are still disabled at the entry * of this routine. */ void timer_handler(void) { struct timer *tmr; u_long ticks; int wakeup = 0; /* * Bump time in ticks. * Note that it is allowed to wrap. */ lbolt++; if (curthread->priority == PRI_IDLE) idle_ticks++; while (!list_empty(&timer_list)) { /* * Check timer expiration. */ tmr = timer_next(&timer_list); if (time_before(lbolt, tmr->expire)) break; list_remove(&tmr->link); if (tmr->interval != 0) { /* * Periodic timer - reprogram timer again. */ ticks = time_remain(tmr->expire + tmr->interval); timer_add(tmr, ticks); sched_wakeup(&tmr->event); } else { /* * One-shot timer */ list_insert(&expire_list, &tmr->link); wakeup = 1; } } if (wakeup) sched_wakeup(&timer_event); sched_tick(); }