Example #1
0
/*
 * Set up the given timer. The value in pt->pt_time.it_value is taken
 * to be an absolute time for CLOCK_REALTIME/CLOCK_MONOTONIC timers and
 * a relative time for CLOCK_VIRTUAL/CLOCK_PROF timers.
 */
void
timer_settime(struct ptimer *pt)
{
	struct ptimer *ptn, *pptn;
	struct ptlist *ptl;

	KASSERT(mutex_owned(&timer_lock));

	if (!CLOCK_VIRTUAL_P(pt->pt_type)) {
		callout_halt(&pt->pt_ch, &timer_lock);
		if (timespecisset(&pt->pt_time.it_value)) {
			/*
			 * Don't need to check tshzto() return value, here.
			 * callout_reset() does it for us.
			 */
			callout_reset(&pt->pt_ch,
			    pt->pt_type == CLOCK_MONOTONIC ?
			    tshztoup(&pt->pt_time.it_value) :
			    tshzto(&pt->pt_time.it_value),
			    realtimerexpire, pt);
		}
	} else {
		if (pt->pt_active) {
			ptn = LIST_NEXT(pt, pt_list);
			LIST_REMOVE(pt, pt_list);
			for ( ; ptn; ptn = LIST_NEXT(ptn, pt_list))
				timespecadd(&pt->pt_time.it_value,
				    &ptn->pt_time.it_value,
				    &ptn->pt_time.it_value);
		}
		if (timespecisset(&pt->pt_time.it_value)) {
			if (pt->pt_type == CLOCK_VIRTUAL)
				ptl = &pt->pt_proc->p_timers->pts_virtual;
			else
				ptl = &pt->pt_proc->p_timers->pts_prof;

			for (ptn = LIST_FIRST(ptl), pptn = NULL;
			     ptn && timespeccmp(&pt->pt_time.it_value,
				 &ptn->pt_time.it_value, >);
			     pptn = ptn, ptn = LIST_NEXT(ptn, pt_list))
				timespecsub(&pt->pt_time.it_value,
				    &ptn->pt_time.it_value,
				    &pt->pt_time.it_value);

			if (pptn)
				LIST_INSERT_AFTER(pptn, pt, pt_list);
			else
				LIST_INSERT_HEAD(ptl, pt, pt_list);

			for ( ; ptn ; ptn = LIST_NEXT(ptn, pt_list))
				timespecsub(&ptn->pt_time.it_value,
				    &pt->pt_time.it_value,
				    &ptn->pt_time.it_value);

			pt->pt_active = 1;
		} else
			pt->pt_active = 0;
	}
Example #2
0
/*! \brief Contem analises e tarefas necessarias ao select: inicio de burst e
 * inicializacao dos descritores. Ha' determinacao de timeout do select, se
 * necessario. Caso contrario, timeout permanece NULL
 *
 * \param[out] r_server A estrutura do servidor
 * \param[out] timeout O timeout a ser aplicado ao select
 *
 * \return -1 Caso erro na extracao do tempo atual
 * \return 0 Caso ok
 */
int server_select_analysis(server *r_server, struct timespec **timeout,
                            struct timespec *burst_rem_time)
{
  int transmission_flag = 0;
  struct timespec burst_cur_time;

  if (0 > bucket_burst_init(&r_server->last_burst, &burst_cur_time))
    return -1;

  if (!timespecisset(&burst_cur_time))
  {
    client_node *cur_client;
    for(cur_client = r_server->l_clients.head; cur_client; 
        cur_client = cur_client->next)  
      bucket_fill(r_server->velocity, &cur_client->bucket);
  }

  transmission_flag = server_init_sets(r_server);   
  if (r_server->l_clients.size && !transmission_flag)
  {
    bucket_burst_remain_time(&burst_cur_time, burst_rem_time); 
    *timeout = burst_rem_time;
  }

  return 0;
}
Example #3
0
static int
acpi_cmbat_info_expired(struct timespec *lastupdated)
{
    struct timespec	curtime;

    ACPI_SERIAL_ASSERT(cmbat);

    if (lastupdated == NULL)
	return (TRUE);
    if (!timespecisset(lastupdated))
	return (TRUE);

    getnanotime(&curtime);
    timespecsub(&curtime, lastupdated);
    return (curtime.tv_sec < 0 ||
	    curtime.tv_sec > acpi_battery_get_info_expire());
}
Example #4
0
static __inline int
acpi_cmbat_info_expired(struct timespec *lastupdated)
{
	struct timespec	curtime;

	if (lastupdated == NULL) {
		return (1);
	}

	if (!timespecisset(lastupdated)) {
		return (1);
	}

	getnanotime(&curtime);
	timespecsub(&curtime, lastupdated);
	return ((curtime.tv_sec < 0 || curtime.tv_sec > acpi_battery_get_info_expire()));
}