/* {{{ void apm_error(int type, const char *format, ...) This function provides a hook for error */ void apm_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) { TSRMLS_FETCH(); char *msg; va_list args_copy; zend_module_entry tmp_mod_entry; /* A copy of args is needed to be used for the old_error_cb */ va_copy(args_copy, args); vspprintf(&msg, 0, format, args_copy); va_end(args_copy); if (APM_G(event_enabled)) { /* We need to see if we have an uncaught exception fatal error now */ if (type == E_ERROR && strncmp(msg, "Uncaught exception", 18) == 0) { } else { insert_event(type, (char *) error_filename, error_lineno, msg TSRMLS_CC); } } efree(msg); /* Calling saved callback function for error handling, unless xdebug is loaded */ if (zend_hash_find(&module_registry, "xdebug", 7, (void**) &tmp_mod_entry) != SUCCESS) { old_error_cb(type, error_filename, error_lineno, format, args); } }
void start_monitor(){ struct timeval *currenttime; exec_count = 0; currenttime = (struct timeval*)malloc(sizeof(struct timeval)); exec_events = (t_event*)calloc(NUM_EVENTS, sizeof(t_event)); /*Keep waiting for new X events for a given screen*/ while(1){ XNextEvent(dis, (XEvent*) &event); XRRNotifyEvent *ev = (XRRNotifyEvent*)&event; gettimeofday(currenttime, NULL); if(!check_event(ev, currenttime)){ logMessage(WARNING, "Event already executed within threshold parameters..skiping this round\n"); continue; } insert_event(ev, currenttime); execute_events(&event); } free(currenttime); free(exec_events); }
/* * FIXME: allow amnt to be specified in time units rather than ticks. */ int timed_event_block(spdid_t spdinv, unsigned int amnt) { spdid_t spdid = cos_spd_id(); struct thread_event *te; int block_time; event_time_t t; if (amnt == 0) return 0; /* * Convert from usec to ticks * * +2 here as we don't know how far through the current clock * tick we are _and_ we don't know how far into the clock tick * the wakeup time is. The sleep is supposed to be for _at * least_ amnt clock ticks, thus here we are conservative. */ //amnt = (amnt/(unsigned int)usec_per_tick) + 2; /* update: seems like +1 should be enough */ amnt++; TAKE(spdid); te = te_get(cos_get_thd_id()); if (NULL == te) BUG(); assert(EMPTY_LIST(te, next, prev)); te->thread_id = cos_get_thd_id(); te->flags &= ~TE_TIMED_OUT; te->flags |= TE_BLOCKED; ticks = sched_timestamp(); te->event_expiration = ticks + amnt; block_time = ticks; assert(te->event_expiration > ticks); t = next_event_time(); insert_event(te); assert(te->next && te->prev && !EMPTY_LIST(te, next, prev)); RELEASE(spdid); if (t != next_event_time()) sched_timeout(spdid, amnt); if (-1 == sched_block(spdid, 0)) { prints("fprr: sched block failed in timed_event_block."); } /* we better have been taking off the list! */ assert(EMPTY_LIST(te, next, prev)); if (te->flags & TE_TIMED_OUT) return TIMER_EXPIRED; /* * The event has already been removed from event list in * event_expiration by the timeout thread. * * Minus 1 here as we must report the amount of time we are * sure we waited for. As we don't know how far into the tick * we were when we slept, and how far the wakeup is into a * tick, we must account for this. */ return ((int)ticks - block_time - 1); //*usec_per_tick; /* expressed in ticks currently */ }
//++++++++++++++++++++++++++++++++++++++++++++++++ //create_remove_addr_event: creates event to remove address // ensures retransmission of REMOVE_ADDR //++++++++++++++++++++++++++++++++++++++++++++++++ void create_remove_addr_event(const uint32_t ipaddr) { //create remove_addr event data struct remove_addr_event_data *rmadd = malloc(sizeof(struct remove_addr_event_data)); rmadd->ipaddr = ipaddr; //create new tp_event and put packet on retransmit queue struct tp_event *evt = malloc( sizeof(struct tp_event) ); evt->type = REMOVE_ADDR; evt->data = (void*) rmadd; //insert event time_t dsec = REMOVE_ADDR_TIME_INTERVAL; insert_event(evt, dsec, 0); }
laundry init_laundry(laundry l){ int i; double t; event e; int n = l->n; for(i=0; i<n; i++){ /*Se generan los `n` tiempos iniciales de falla y se los agrega a la lista de eventos */ t = exponential(l->rg, 1./(l->tfail)); e = create_event(t, MACHINE_BROKEN); l->events_list = insert_event(l->events_list, e); } return l; }
void RtpSession::send_rtcp() { RtcpPacket *p; struct timeval tv; gettimeofday(&tv, NULL); ntp_t ntp = timeval_to_ntp( tv ); uint8_t type = m_event_queue->type; switch ( m_event_queue->type ) { case RTCP_SR: /* We want to send an RTCP Sender Report. */ p = new RtcpPacket( RTCP_SR ); p->set_count( 0 ); p->set_sr_ssrc( m_ssrc ); p->set_sr_ntp_sec( ntp.secs ); p->set_sr_ntp_frac( ntp.frac ); p->set_sr_rtp_ts( m_last_timestamp ); p->set_sr_psent( m_psent ); p->set_sr_osent( m_osent ); break; case RTCP_RR: p = new RtcpPacket( RTCP_RR ); p->set_count( 1 ); default: p = NULL; } if ( ! p ) return; send_rtcp_pkt( p ); /* Advance the queue */ event_t *next = (event_t *)m_event_queue->next; free( m_event_queue ); m_event_queue = next; /* Schedule a new RTCP packet */ event_t *e = (event_t*)malloc( sizeof( event_t ) ); e->type = type; e->time = tv2dbl( tv ) + compute_rtcp_interval(); e->next = NULL; insert_event( e ); }
/* Class 'release' methods */ release::release(status &state,int id_server,int id_demand) { double distance = state.Sol->distance(id_server,id_demand); server = id_server; demand_point = id_demand; travel_time = distance / state.Sol->get_server_speed(server); on_scene_st = exponential(state.Sol->get_non_travel_time()); follow_up_travel_time = + distance * state.Sol->get_server_rate(server) - travel_time; service_time = travel_time + on_scene_st + follow_up_travel_time; return_time = state.current_time + service_time; insert_event(*(state.events),*this); Log_Simulation << "\tCall hosted by server " << id_server << endl; /* data */ state.busy[server] = true; state.busy_time[server] += service_time; state.arrival_time += travel_time; state.service_time += service_time; }
static void next_tcp_replica_xmit (chunkput_omhucast_t *cp,tick_t time_now) // Schedule the next TCP transmit start after the previous tcp transmit for // the same object has completed { tcp_xmit_received_t txr; unsigned r; if (cp->cp.replicas_unacked) { txr.event.create_time = time_now; txr.event.tllist.time = time_now + config.cluster_trip_time*3 + TCP_CHUNK_SETUP_BYTES*8; txr.event.type = (event_type_t)OMHUCAST_XMIT_RECEIVED; txr.cp = (chunk_put_handle_t)cp; r = cp->repnum++; txr.target_num = cp->ch_targets[r]; insert_event(txr); } }
static void schedule_tcp_reception_complete (unsigned target_num, chunk_put_handle_t cp ) { omhucast_target_t *t = omhucast_tgt + target_num; tcp_reception_complete_t trc; ongoing_reception_t *ort; tick_t remaining_xfer; assert(t); ort = (ongoing_reception_t *)t->orhead.tllist.next; assert(ort && &ort->tllist != &t->orhead.tllist); trc.event.create_time = now; assert(derived.chunk_tcp_xmit_duration > ort->credit); remaining_xfer = derived.chunk_tcp_xmit_duration - ort->credit; assert(t->n_ongoing_receptions); trc.event.tllist.time = now + remaining_xfer*t->n_ongoing_receptions; trc.event.type = (event_type_t)OMHUCAST_RECEPTION_COMPLETE; trc.cp = cp; assert (target_num < derived.n_targets); trc.target_num = target_num; insert_event(trc); }
uint16_t RtpSession::receive_rtp_packet(void *buf ) { struct timeval start_time_tv; if ( ! m_preceived ) { /* This is the 1th packet that we receive- * Here we should send an RTCP SDES packet with all the * infos... */ gettimeofday(&start_time_tv, NULL); m_start_time = tv2dbl(start_time_tv); #if 0 /*! Build the SDES CNAME packet */ uint16_t s = 10 + strlen( m_cname ); /* Align to 32 bit boundary .. */ s = (uint16_t)ceil( (double)s /4 ) * 4; m_sdes_pkt = (rtcp_t *)calloc( s , 1 ); RtcpPacket *p = new RtcpPacket( m_sdes_pkt, s ); p->set_version( 2 ); p->set_padding( 0 ); p->set_count( 1 ); p->set_type( RTCP_SDES ); p->set_length( (uint16_t)s/4 - 1 ); m_sdes_pkt->r.sdes.src = htonl( m_ssrc ); m_sdes_pkt->r.sdes.item->type = RTCP_SDES_CNAME; m_sdes_pkt->r.sdes.item->length = strlen( m_cname ); memcpy( m_sdes_pkt->r.sdes.item[0].data, m_cname, strlen(m_cname) ); m_sdes_pkt_size = s; /*! Schedule an RTCP RR.. */ event_t *e = (event_t*)malloc( sizeof( event_t ) ); e->type = RTCP_RR; e->time = m_start_time + 5.0; e->next = NULL; insert_event( e ); send_rtcp(); #endif } int event = 0; int retval; double timeout, now; struct timeval timeout_tv, now_tv; fd_set sockets; /*! Here we check for events or things to do... */ while ( 1 ) { gettimeofday(&now_tv, NULL); now = tv2dbl(now_tv); if ( m_event_queue != NULL ) { event = 1; timeout = m_event_queue->time - now; } else { event = 0; timeout = 0.5; /* Arbitrary value.. to be trimmed.. */ } if ( timeout < 0 ) timeout = 0; timeout_tv = dbl2tv( timeout ); FD_ZERO( &sockets ); FD_SET( m_rtp_sock, &sockets ); FD_SET( m_rtcp_sock, &sockets ); int max_fd = ((m_rtp_sock > m_rtcp_sock) ? m_rtp_sock : m_rtcp_sock ) + 1; retval = select(max_fd, &sockets, NULL, NULL, &timeout_tv); if ( retval < 0 ) { perror("select"); return false; } else if ( retval > 0 ) { // There are some events... if (FD_ISSET(m_rtp_sock, &sockets)) { /* There's an RTP packet to be read... */ return receive_rtp( buf ); } if (FD_ISSET(m_rtcp_sock, &sockets)) { receive_rtcp(); } } else { /* retval == 0, select timed out */ if (event) { gettimeofday( &now_tv, NULL ); now = tv2dbl( now_tv ); while ( m_event_queue != NULL && m_event_queue->time <= now ) { /* There is a pending RTCP packet to send) */ send_rtcp(); } } } } }
bool RtpSession::send_rtp_packet(void *buf, uint16_t size, uint32_t ts_inc ) { uint32_t timestamp; struct timeval start_time_tv, now_tv; double play_time, now; timestamp = m_prev_timestamp + ts_inc; m_prev_timestamp = timestamp; if ( !buf || !size ) { printf("Cannot send packet.\n"); return false; } if ( ! m_psent ) { /* This is the 1th packet that we send. * Here we should send an RTCP SDES packet with all the * infos... */ gettimeofday(&start_time_tv, NULL); m_start_time = tv2dbl(start_time_tv); /*! Build the SDES CNAME packet */ uint16_t s = 10 + strlen( m_cname ); /* Align to 32 bit boundary .. */ s = (uint16_t)ceil( (double)s /4 ) * 4; m_sdes_pkt = (rtcp_t *)calloc( s , 1 ); RtcpPacket *p = new RtcpPacket( m_sdes_pkt, s ); p->set_version( 2 ); p->set_padding( 0 ); p->set_count( 1 ); p->set_type( RTCP_SDES ); p->set_length( (uint16_t)s/4 - 1 ); m_sdes_pkt->r.sdes.src = htonl( m_ssrc ); m_sdes_pkt->r.sdes.item->type = RTCP_SDES_CNAME; m_sdes_pkt->r.sdes.item->length = strlen( m_cname ); memcpy( m_sdes_pkt->r.sdes.item[0].data, m_cname, strlen(m_cname) ); m_sdes_pkt_size = s; /*! Schedule an RTCP for now.. */ event_t *e = (event_t*)malloc( sizeof( event_t ) ); e->type = RTCP_SR; e->time = 0.0; e->next = NULL; insert_event( e ); send_rtcp(); } /** OK, we build the real RTP packet... */ RtpPacket *pkt = new RtpPacket( (uint8_t*)buf, size ); pkt->set_ssrc( m_ssrc ); pkt->set_payload_type( m_payload_type ); pkt->set_sequence( m_seq++ ); pkt->set_timestamp( timestamp ); delete pkt; if ( ! send_pkt( buf, size ) ) { /* Problems sending packet.. probably the client closed * the connection.. */ return false; } /* *************************************************** */ /*! Here we check for events or things to do... */ /* Schedule the times to play packets as an absolute offset from * our start time, rather than a relative offset from the initial * packet. (We're less vulnerable to drifting clocks that way). * Alternative version based on timestamps and RTP clock.. */ play_time = m_start_time + ((double)(timestamp - m_base_timestamp)/ m_rtp_clock); // printf("play_time: %f - difference: %f sec.\n", play_time, // ((double)(timestamp - m_base_timestamp)/ m_rtp_clock)); while (gettimeofday(&now_tv, NULL), (now = tv2dbl(now_tv)) < play_time) { int event = 0; int retval; double timeout; struct timeval timeout_tv; fd_set sockets; if ( m_event_queue != NULL && m_event_queue->time < play_time ) { event = 1; timeout = m_event_queue->time - now; } else { event = 0; timeout = play_time - now; } if ( timeout < 0 ) timeout = 0; timeout_tv = dbl2tv( timeout ); FD_ZERO( &sockets ); FD_SET( m_rtp_sock, &sockets ); FD_SET( m_rtcp_sock, &sockets ); int max_fd = ((m_rtp_sock > m_rtcp_sock) ? m_rtp_sock : m_rtcp_sock ) + 1; retval = select(max_fd, &sockets, NULL, NULL, &timeout_tv); if ( retval < 0 ) { perror("select"); exit(1); } else if ( retval > 0 ) { // There are some events... if (FD_ISSET(m_rtp_sock, &sockets)) { /* There's an RTP packet to be read... * We should receive, validate and .. trash it.. */ receive_rtp( (void*)m_buf ); } if (FD_ISSET(m_rtcp_sock, &sockets)) { receive_rtcp(); } } else { /* retval == 0, select timed out */ if (event) { gettimeofday( &now_tv, NULL ); now = tv2dbl( now_tv ); while ( m_event_queue != NULL && m_event_queue->time <= now ) { /* There is a pending RTCP packet to send) */ send_rtcp(); } } else break; /* Time for the next packet */ } } /* **************************************************** */ return true; }
double run_laundry(laundry l){ event current, e; double t; /*Acumulador del tiempo en funcionamiento*/ double trunning=0; int broken = 0, waiting = 0; /*Se inicializa el sistema*/ l = init_laundry(l); while(broken <= (l->s)){ /*Mientras la cantidad de maquinas rotas sea menor o igual a la cantidad de repuestos, el sistema puede funcionar. */ current = next_event(l->events_list); trunning += get_time(current); if(get_type(current) == MACHINE_BROKEN){ /*El evento es una maquina rota, entonces se genera un nuevo tiempo de falla para uno los repuestos que entra en funcionamiento. */ t = exponential(l->rg, 1./(l->tfail)); e = create_event(t, MACHINE_BROKEN); l->events_list = insert_event(l->events_list, e); broken++; if(broken <= (l->o)){ /*Si hay un operario libre, entonces se genera un nuevo tiempo de reparacion para la maquina que entra al taller. */ t = exponential(l->rg, 1./(l->trepair)); e = create_event(t, MACHINE_REPAIRED); l->events_list = insert_event(l->events_list, e); } else{ /*Si todos los operarios estan ocupados, la maquina queda en espera. */ waiting++; } } else{ /*El evento es una maquina reparada, entonces hay una maquina rota menos. Ademas se acaba de liberar un operario, entonces si hay maquinas en espera de reparacion, se genera un nuevo tiempo de reparacion. */ broken--; if(waiting > 0){ waiting--; t = exponential(l->rg, 1./(l->trepair)); e = create_event(t, MACHINE_REPAIRED); l->events_list = insert_event(l->events_list, e); } } destroy_event(current); } return trunning; }
void handle_omhucast_reception_complete (const event_t *e) // handle the expected completion of a TCP chunk reception. // // while there is an ongoing reception queue (orhead) for the target // if the lead ongoing reception does not have enough credit yet // schedule the next tcp_reception_complete event // break // Make a Disk Write Completion event for the completed ongoing reception // consume the ongoing reception { const tcp_reception_complete_t *trc = (const tcp_reception_complete_t *)e; tcp_reception_ack_t tcp_ack; ongoing_reception_t *ort,*ort_next; disk_write_start_t dws; omhucast_target_t *t; tick_t write_start,write_completion; unsigned n; tick_t write_variance = derived.chunk_disk_write_duration/config.write_variance; tick_t write_duration = derived.chunk_disk_write_duration - write_variance/2 + (rand() % write_variance); assert (e); (void)e; t = omhucast_tgt + trc->target_num; tcp_ack.target_num = trc->target_num; dws.target_num = trc->target_num; assert(t->n_ongoing_receptions); credit_ongoing_receptions(t,t->n_ongoing_receptions); for (ort = (ongoing_reception_t *)t->orhead.tllist.next,n=0; &ort->tllist != &t->orhead.tllist; ort = ort_next,++n) { if (ort->credit < derived.chunk_tcp_xmit_duration) { schedule_tcp_reception_complete (trc->target_num,ort->cp); break; } tcp_ack.event.create_time = e->tllist.time; tcp_ack.event.tllist.time = e->tllist.time + config.cluster_trip_time; tcp_ack.event.type = (event_type_t)OMHUCAST_RECEPTION_ACK; tcp_ack.cp = ort->cp; tcp_ack.max_ongoing_rx = ort->max_ongoing_rx; insert_event(tcp_ack); dws.event.create_time = e->tllist.time; write_start = (t->last_disk_write_completion > e->tllist.time) ? t->last_disk_write_completion : e->tllist.time; write_completion = write_start + write_duration; dws.event.create_time = e->tllist.time; dws.event.tllist.time = write_start; t->last_disk_write_completion = write_completion; dws.expected_done = write_completion; dws.event.type = DISK_WRITE_START; dws.cp = ort->cp; assert(chunk_seq(ort->cp)); insert_event(dws); ort_next = (ongoing_reception_t *)ort->tllist.next; assert(ort_next); assert(&ort_next->tllist == &t->orhead.tllist || ort_next->cp != ort->cp); tllist_remove(&ort->tllist); memset(ort,0xFD,sizeof *ort); free(ort); --t->n_ongoing_receptions; } }