Ejemplo n.º 1
0
static status_t
low_resource_manager(void*)
{
	bigtime_t timeout = kLowResourceInterval;
	while (true) {
		int32 state = low_resource_state_no_update(B_ALL_KERNEL_RESOURCES);
		if (state != B_LOW_RESOURCE_CRITICAL) {
			acquire_sem_etc(sLowResourceWaitSem, 1, B_RELATIVE_TIMEOUT,
				timeout);
		}

		RecursiveLocker _(&sLowResourceLock);

		compute_state();
		state = low_resource_state_no_update(B_ALL_KERNEL_RESOURCES);

		TRACE(("low_resource_manager: state = %ld, %ld free pages, %lld free "
			"memory, %lu free semaphores\n", state, vm_page_num_free_pages(),
			vm_available_not_needed_memory(),
			sem_max_sems() - sem_used_sems()));

		if (state < B_LOW_RESOURCE_NOTE)
			continue;

		call_handlers(sLowResources);

		if (state == B_LOW_RESOURCE_WARNING)
			timeout = kWarnResourceInterval;
		else
			timeout = kLowResourceInterval;

		sLowResourceWaiterCondition.NotifyAll();
	}
	return 0;
}
Ejemplo n.º 2
0
int32
low_resource_state(uint32 resources)
{
	recursive_lock_lock(&sLowResourceLock);

	if (system_time() - sLastMeasurement > 500000)
		compute_state();

	int32 state = low_resource_state_no_update(resources);

	recursive_lock_unlock(&sLowResourceLock);

	return state;
}
Ejemplo n.º 3
0
static void unlock_check_read_write_state(grpc_chttp2_transport *t) {
  grpc_chttp2_transport_global *transport_global = &t->global;
  grpc_chttp2_stream_global *stream_global;
  grpc_stream_state state;

  if (!t->parsing_active) {
    /* if a stream is in the stream map, and gets cancelled, we need to ensure
       we are not parsing before continuing the cancellation to keep things in
       a sane state */
    while (grpc_chttp2_list_pop_closed_waiting_for_parsing(transport_global,
                                                           &stream_global)) {
      GPR_ASSERT(stream_global->in_stream_map);
      GPR_ASSERT(stream_global->write_state != GRPC_WRITE_STATE_OPEN);
      GPR_ASSERT(stream_global->read_closed);
      remove_stream(t, stream_global->id);
      grpc_chttp2_list_add_read_write_state_changed(transport_global,
                                                    stream_global);
    }
  }

  while (grpc_chttp2_list_pop_read_write_state_changed(transport_global,
                                                       &stream_global)) {
    if (stream_global->cancelled) {
      stream_global->write_state = GRPC_WRITE_STATE_SENT_CLOSE;
      stream_global->read_closed = 1;
      if (!stream_global->published_cancelled) {
        char buffer[GPR_LTOA_MIN_BUFSIZE];
        gpr_ltoa(stream_global->cancelled_status, buffer);
        grpc_chttp2_incoming_metadata_buffer_add(&stream_global->incoming_metadata,
          grpc_mdelem_from_strings(t->metadata_context, "grpc-status", buffer));
        grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into(
          &stream_global->incoming_metadata,
          &stream_global->incoming_sopb);
        stream_global->published_cancelled = 1;
      }
    }
    if (stream_global->write_state == GRPC_WRITE_STATE_SENT_CLOSE &&
        stream_global->read_closed && stream_global->in_stream_map) {
      if (t->parsing_active) {
        grpc_chttp2_list_add_closed_waiting_for_parsing(transport_global,
                                                        stream_global);
      } else {
        remove_stream(t, stream_global->id);
      }
    }
    if (!stream_global->publish_sopb) {
      continue;
    }
    /* FIXME(ctiller): we include in_stream_map in our computation of
       whether the stream is write-closed. This is completely bogus,
       but has the effect of delaying stream-closed until the stream
       is indeed evicted from the stream map, making it safe to delete.
       To fix this will require having an edge after stream-closed
       indicating that the stream is closed AND safe to delete. */
    state = compute_state(
        stream_global->write_state == GRPC_WRITE_STATE_SENT_CLOSE &&
            !stream_global->in_stream_map,
        stream_global->read_closed);
    if (stream_global->incoming_sopb.nops == 0 &&
        state == stream_global->published_state) {
      continue;
    }
    grpc_chttp2_incoming_metadata_buffer_postprocess_sopb_and_begin_live_op(
        &stream_global->incoming_metadata, &stream_global->incoming_sopb,
        &stream_global->outstanding_metadata);
    grpc_sopb_swap(stream_global->publish_sopb, &stream_global->incoming_sopb);
    stream_global->published_state = *stream_global->publish_state = state;
    grpc_chttp2_schedule_closure(transport_global,
                                 stream_global->recv_done_closure, 1);
    stream_global->recv_done_closure = NULL;
    stream_global->publish_sopb = NULL;
    stream_global->publish_state = NULL;
  }
}
PROCESS_THREAD(markov_process, ev, data) {
    int new_state = b[0];
    int i,j;

    PROCESS_BEGIN();

    //etimer_set(&et, CLOCK_SECOND);
    //PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    // Initial configurations  on CC2420
    cc2420_set_txpower(MAX_POWER);
    cc2420_set_channel(INTERFERED_CHANNEL);
    watchdog_stop();

    printf("RAND_MAX %d INTMAX %d\n", RANDOM_RAND_MAX, INT_MAX);
    random_init(19);


    /* XXX should use formula */
    W[0]= 31;
    W[1]= 62;
    W[2]= 124;
    W[3]= 248;
    W[4]= 496;
    W[5]= 992;
    W[6]= 1023;
    W[7]= 1023;

    for(i=0; i<NRSTATES; i++) {
        b[i] = bSTATE_MIN+i;
        B[i] = BSTATE_MIN+i;
        bctr[i] = 0;
        Bctr[i] = 0;
        ALFA[i] = 2.0/((float)W[i]);
        BETA[i] = 2.0/((float)(W[i]-1));
    }

    printf("a %d, b %d, c %d d %d BETA1 %d\n",
           100*((1-P)*ALFA[0]),
           100*((1-P)*(1-ALFA[0])),
           100*(P*ALFA[1]),
           100*(P*(1-ALFA[1])),
           100*BETA[1]);


    /* this is the first "dry" run where we compute the state for
       the real run */
    new_state = b[0];
    for(i=0; i<SAVESTATES; i++) {
        sstate [i] = 0;
        visits[i] = 0;
    }
    while (cs<SAVESTATES) {
        new_state = compute_state(new_state);
    }
    new_state = b[0];

    /* now we start the real run */
    cur_state = 0;
    cur_visits = 0;

    CC2420_SPI_ENABLE();

#if 0
    while (cs<) {
        ctr++;
        if (ctr % 100 == 0) {
            int ctr_sum = 0;
            printf("time %f\n", time);
            float b = 0;
            for(i=bSTATE_MIN; i<bSTATE_MIN+NRSTATES; i++) {
                printf("counter[%d]: %d\n", i, bctr[i]);
                ctr_sum += bctr[i];
                b += timeb[i];
            }
            for(i= 0; i<NRSTATES; i++) {
                printf("counter[%d]: %d\n", i, Bctr[i]);
                ctr_sum += Bctr[i];
            }
            b = b / time;
            printf("counter %d percent in b: %f\n", ctr_sum, b);
        }
        if (ctr > MAX) {
            int ctr_sum = 0;
            float b = 0;
            for(i=bSTATE_MIN; i<bSTATE_MIN+NRSTATES; i++) {
                printf("counter[%d]: %d\n", i, bctr[i]);
                ctr_sum += bctr[i];
            }
            for(i= 0; i<NRSTATES; i++) {
                printf("counter[%d]: %d\n", i, Bctr[i]);
                ctr_sum += Bctr[i];
            }
            printf("counter %d percent in b: %f\n", ctr_sum, b);
            printf("ctrs: b0 %d B0 %d b1 %d B1 %d b5 %d B5 %d\n",
                   bctr[0], Bctr[0], bctr[1], Bctr[1], bctr[5], Bctr[5]);
            exit(1);
        }
        update_state();
    }
#endif
    printf("after modelling\n");
    j=0;
    for(i=0; i<SAVESTATES; i++) {
        //printf("state %d visits% d\n", sstate[i], visits[i]);
        j += visits[i];
    }
    printf("sum visits %d\n", j);
    /* correct very first state */
    if (visits[0] == 0)
        visits[0] = 1;

    ctr = 0;
    printf("--------- real run -------------\n");
    update_state();

    CC2420_SPI_DISABLE();
    PROCESS_END();
}
Ejemplo n.º 5
0
  void lcd_state ( int *nz, double *dt, double *volt, double *freq,
		   double *d, double *K, double *alpha, int *shear, 
		   double *epsilon, double *flexo, double *w, double *boundary_tilt,
		   double *wtw, double *boundary_twist,double *pgx, double *pgy,
		   int *nsp, double *rho0, double *mu, double *chi, double *charge, double *sigma0,
		   double *z, double *layer_depth, double *tilt, double *twist, 
		   double *volt_ac, double *volt_dc, double *flowx, double *flowy, double *rho, double *sigma,
		   int *newton_iter, double *newton_tol, double *min_timestep, 
		   double *time_tol, double *ftime,
		   double* residual, double* stepsize)
		   
  {
    
    // purpose: compute an lcd state given an lcd state as an initial estimate
    
    // accepts : nz - input - number of grid points to consider (including boundaries)
    //           dt - input - time difference between initial state and desired state
    //                        if dt == 0 a steady state is computed


    Geometry g(*nz,*d);
    Parameters p = init_parameters(d,K,alpha,epsilon,flexo, w, boundary_tilt, wtw, boundary_twist,
				   nsp, rho0, mu, chi, charge, sigma0, ftime);

    p.boundary_volt_ac[0] = *volt;
    p.pgx = *pgx;
    p.pgy = *pgy;


    // create the previous state
    State prev (*nz,&p,&g);
    
    for (size_t j = 0; j < (size_t)*nz; j++){
      prev.tilt[j] = tilt[j];
      prev.volt_ac[j] = volt_ac[j];
      prev.volt_dc[j] = volt_dc[j];
      prev.flowx[j] = flowx[j];
       
      for (size_t sp = 0; sp < (size_t)*nsp; sp++){
	size_t l = j + sp * (*nz);
	prev.rho[sp][j] = rho[l];
      }      
    }
    
    vector<Equation*> e;
    //TODO include more equations!
    e.push_back(new Volt_ACEquation());
    e.push_back(new TiltEquation());
    
    
    State *s = compute_state
      (e, &p, &g, &prev , *dt ,
       *newton_tol,  *newton_iter , *time_tol , *min_timestep);
    
    
    for (size_t j = 0; j < (size_t)*nz; j++){
      tilt[j] = s->tilt[j];
      volt_ac[j] = s->volt_ac[j];
      volt_dc[j] = s->volt_dc[j];
      flowx[j] = s->flowx[j];
      flowy[j] = s->flowy[j];
      for (size_t sp = 0; sp < (size_t)*nsp; sp++){
	size_t l = j + sp * (*nz);
	rho[l] = s->rho[sp][j];
      }      
    } 
    

    delete(s);

#define COPYR(x) if (x != 0) for (size_t i = 0; i < e.size(); i++) for (size_t j = 0; j < e.at(i)->x.size(); j++) x[i*(*newton_iter) + j] = e.at(i)->x[j];  

    //copy residuals 
    COPYR(residual);
    COPYR(stepsize);
      for (size_t i = 0; i < e.size(); i++){
	delete(e.at(i));
      }

  }