Ejemplo n.º 1
0
int main(void)
{
    tmr_t test_timer, test_timer_2, test_timer_3;

    printf("System abstraction test - POSIX implementation\n");

    system_init();

    tmr_init(&test_timer, true, test, NULL);
    tmr_start(test_timer, 100);
    tmr_init(&test_timer_2, true, test_2, NULL);
    tmr_start(test_timer_2, 275);
    tmr_init(&test_timer_3, false, test_3, NULL);
    tmr_start(test_timer_3, 1000);
    tmr_stop(test_timer);
    tmr_reset(test_timer);

    system_start();

    tmr_destroy(test_timer);
    tmr_destroy(test_timer_2);
    tmr_destroy(test_timer_3);

    return 0;
}
Ejemplo n.º 2
0
static void tcp_close_pending_connection (TCP_FD *pp)
{
	int	r;

	if (tmr_active (&pp->timer))
		tmr_stop (&pp->timer);

	ctrc_printd (TCPS_ID, TCPS_CLOSE_PEND, &pp->fd, sizeof (pp->fd));
	sock_fd_remove_socket (pp->fd);
	r = close (pp->fd);
	trace_server ("close", r, pp->fd);
	if (r)
		perror ("tcp_close_pending_connection: close()");
	pp->fd = 0;
	tcp_pending_free (pp);
}
Ejemplo n.º 3
0
void rfraginfo_delete (CCREF *refp)
{
    FragInfo_t	*fip;

    if ((fip = refp->fragments) == NULL)
        return;

    refp->fragments = NULL;
    rcl_access (fip);
    fip->nrefs--;
    rcl_done (fip);
    if (fip->nrefs > 0)
        return;

    db_free_data (fip->data);
    tmr_stop (&fip->timer);
    if (fip->key && fip->key != fip->hash.hash)
        xfree (fip->key);
    xfree (fip);
}
Ejemplo n.º 4
0
int main(void)
{
	RT_TASK *rtask;
	MBX *mbx;
	int maxisr = 0, maxsched = 0, ovrun = 0, semcnt;
	struct { int isr, sched; } latency;
	int timer_period, timer_freq, h_timer_freq;
	int count, perns, pervar, maxpervar = 0;
	RTIME tp, t;

	rt_allow_nonroot_hrt();
	pthread_create(&thread, NULL, endt, NULL);
	iopl(3);

	if (!(rtask = rt_task_init_schmod(nam2num("RTASK"), 0, 0, 0, SCHED_FIFO, ALLOWED_CPUS))) {
		printf("CANNOT CREATE REAL TIME TASK\n");
		return 1;
	}
	if (!(mbx = rt_named_mbx_init("LATMBX", 100*sizeof(latency)))) {
		printf("CANNOT CREATE MAILBOX\n");
		rt_task_delete(rtask);
		return 1;
	}

	rt_make_hard_real_time();
	timer_period = 1;
	timer_freq = 2;
	tmr_get_setup(timer, &timer_period, &timer_freq);
	h_timer_freq = timer_freq/2;
	perns = timer_period*1000000000LL/timer_freq;
 	tmr_start(timer);
#ifdef USE_EXT_WAIT
 	printf("Wait_on_timer returns timer count and cpu time.\n");
#else
 	printf("Wait_on_timer does just that.\n");
#endif
#ifdef DISABLE_INTR
 	printf("Wait_on_timer and times getting with interrupt disabled.\n");
#else
 	printf("Wait_on_timer and times getting with interrupt enabled.\n");
#endif
 	printf("Timer setup completed, running.\n\n");

	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();

	while (wait_on_timer(timer) > 0);
	tp = rt_get_cpu_time_ns();
	while (!end) {
		CLI();
		CHECK_FLAGS();
#ifdef USE_EXT_WAIT
		if ((semcnt = wait_on_timer_ext(timer, &count, &t)) > 0) {
			rt_printk("OVRN: %d, TOT: %d\n", semcnt, ++ovrun);
		}
#else
		if ((semcnt = wait_on_timer(timer)) > 0) {
			rt_printk("OVRN: %d, TOT: %d\n", semcnt, ++ovrun);
		}
		count = tmr_get_count(timer, &t);
#endif
		CHECK_FLAGS();
		STI();
		if ((latency.sched = ((timer_period - count)*1000000 + h_timer_freq)/timer_freq) > maxsched) {
			maxsched = latency.sched;
		}
		if ((latency.isr = ((timer_period - tmr_get_isr_count(timer))*1000000 + h_timer_freq)/timer_freq) > maxisr) {
			maxisr = latency.isr;
		}
		pervar = abs((int)(t - tp));
		tp = t;
		if (pervar > maxpervar) {
			maxpervar = pervar;
		}
		rt_mbx_send_if(mbx, &latency, sizeof(latency));
//		rt_printk("MXI %d, MXS %d\n", maxisr, maxsched);
	}
 	tmr_stop(timer);

	rt_make_soft_real_time();
	rt_task_delete(rtask);
	rt_mbx_delete(mbx);
	printf("*** MAX LATENCIES: ISR %d (us), SCHED %d (us) ***\n", maxisr, maxsched);
	printf("*** MAX PERIOD VARIATION %d (us) ***\n", (maxpervar - perns + 500)/1000);
	return 0;
}
Ejemplo n.º 5
0
static void tcp_pending_first_message (SOCKET fd, short revents, void *arg)
{
	TCP_FD		*pp = (TCP_FD *) arg;
	IP_CX		*cxp;
	TCP_DATA	*dp;
	int		err, r;
	socklen_t	sz;

	ctrc_begind (TCPS_ID, TCPS_PFMSG_EV, &fd, sizeof (fd));
	ctrc_contd (&revents, sizeof (revents));
	ctrc_endd ();

	trace_poll_events (fd, revents, arg);

	if ((revents & (POLLERR | POLLNVAL)) != 0) {
		sz = sizeof (err);
		r = getsockopt (pp->fd, SOL_SOCKET, SO_ERROR, &err, &sz);
		if ((r == -1) || err)  {
			log_printf (RTPS_ID, 0, "POLLERR | POLLNVAL [%d]: %d %s\r\n", pp->fd, err, strerror (err));
			tcp_close_pending_connection (pp);
			return;
		}
	}

	/* Check if connection unexpectedly closed. */
	if ((revents & POLLHUP) != 0) {
		log_printf (RTPS_ID, 0, "TCP(Sp): connection error!\r\n");
		tcp_close_pending_connection (pp);
		return;
	}

	if (!pp->sproto) {
		dp = xmalloc (sizeof (TCP_DATA));
		if (!dp) {
			log_printf (RTPS_ID, 0, "tcp_pending_first_message: out of memory for TCP context on [%d]\r\n", pp->fd);
			tcp_close_pending_connection (pp);
			return;
		}
		dp->recv_msg = xmalloc (sizeof (TCP_MSG));
		if (!dp->recv_msg) {
			xfree (dp);
			log_printf (RTPS_ID, 0, "tcp_pending_first_message: out of memory for TCP context on [%d]\r\n", pp->fd);
			tcp_close_pending_connection (pp);
			return;
		}
		dp->recv_msg->msg = NULL;
		dp->recv_msg->buffer = NULL;
		dp->recv_msg->size = dp->recv_msg->used = 0;
		dp->send_msg = NULL;
		pp->sproto = dp;
	}
	else
		dp = (TCP_DATA *) pp->sproto;

	if (tcp_receive_message_fragment (pp->fd, dp->recv_msg) == -1) {
		tcp_close_pending_connection (pp);
		return;
	}
	if (dp->recv_msg->used != dp->recv_msg->size)
		return; /* message (still) incomplete */

	ctrc_printd (TCPS_ID, TCPS_NEW_CX, &pp->fd, sizeof (pp->fd));

	cxp = pp->parent->stream_cb->on_new_connection (pp, dp->recv_msg->buffer, dp->recv_msg->size);
	xfree (dp->recv_msg->buffer);
	dp->recv_msg->buffer = NULL;
	dp->recv_msg->size = dp->recv_msg->used = 0;
	if (!cxp) {
		/* pending connection could not be 'promoted' to an IP_CX */
		tcp_close_pending_connection (pp);
		return;
	}

	/* Note: it is assumed that the returned cxp is usable for this layer, iow that required
	   callbacks are filled in. Failure to do so will result in crashes. */
	sock_fd_udata_socket (cxp->fd, cxp);
	sock_fd_fct_socket (cxp->fd,
			    tcp_socket_activity);

	/*	sock_fd_remove_socket (pp->fd);
	sock_fd_add_socket (cxp->fd,
			    POLLIN | POLLPRI | POLLHUP | POLLNVAL | POLLOUT,
			    tcp_socket_activity,
			    cxp,
			    "DDS.TCP");
	*/
	tmr_stop (&pp->timer);
	tcp_pending_free (pp);
}