Exemple #1
0
static __inline__ mpqueue_head_t *
timer_call_entry_enqueue_deadline(
	timer_call_t		entry,
	mpqueue_head_t		*queue,
	uint64_t		deadline)
{
	mpqueue_head_t	*old_queue = MPQUEUE(CE(entry)->queue);

	if (!hw_lock_held((hw_lock_t)&entry->lock))
		panic("_call_entry_enqueue_deadline() "
			"entry %p is not locked\n", entry);
	/* XXX More lock pretense:  */
	if (!hw_lock_held((hw_lock_t)&queue->lock_data))
		panic("_call_entry_enqueue_deadline() "
			"queue %p is not locked\n", queue);
	if (old_queue != NULL && old_queue != queue)
		panic("_call_entry_enqueue_deadline() "
			"old_queue %p != queue", old_queue);

	call_entry_enqueue_deadline(CE(entry), QUEUE(queue), deadline);

/* For efficiency, track the earliest soft deadline on the queue, so that
 * fuzzy decisions can be made without lock acquisitions.
 */
	queue->earliest_soft_deadline = ((timer_call_t)queue_first(&queue->head))->soft_deadline;

	if (old_queue)
		old_queue->count--;
	queue->count++;

	return (old_queue);
}
Exemple #2
0
/*
 * run through all the timers, call the ones that needs it,
 * clear the ones that wants it, and calculate the next
 * potential cycle we could sleep for...
 */
avr_cycle_count_t
avr_cycle_timer_process(
		avr_t * avr)
{
	avr_cycle_timer_pool_t * pool = &avr->cycle_timers;

	if (pool->timer) do {
		avr_cycle_timer_slot_p t = pool->timer;
		avr_cycle_count_t when = t->when;

		if (when > avr->cycle)
			return avr_cycle_timer_return_sleep_run_cycles_limited(avr, when - avr->cycle);

		// detach from active timers
		pool->timer = t->next;
		t->next = NULL;
		do {
			avr_cycle_count_t w = t->timer(avr, when, t->param);
			// make sure the return value is either zero, or greater
			// than the last one to prevent infinite loop here
			when = w > when ? w : 0;
		} while (when && when <= avr->cycle);
		
		if (when) // reschedule then
			avr_cycle_timer_insert(avr, when - avr->cycle, t->timer, t->param);
		
		// requeue this one into the free ones
		QUEUE(pool->timer_free, t);
	} while (pool->timer);

	// original behavior was to return 1000 cycles when no timers were present...
	// run_cycles are bound to at least one cycle but no more than requested limit...
	//	value passed here is returned unbounded, thus preserving original behavior.
	return avr_cycle_timer_return_sleep_run_cycles_limited(avr, DEFAULT_SLEEP_CYCLES);
}
Exemple #3
0
static __inline__ void
timer_call_entry_enqueue_tail(
	timer_call_t			entry,
	mpqueue_head_t			*queue)
{
	call_entry_enqueue_tail(CE(entry), QUEUE(queue));
	queue->count++;
	return;
}
/*
 * Callback function for handling calculated data.
 *
 * @param [in]   Data_p   Pointer to the data buffer for calculation.
 * @param [in]   Length   Length of the data for calculation.
 * @param [out]  Hash_p   Pointer to buffer with calculated hash.
 * @param [in]   Param_p  Pointer to extra parameters.
 *
 * @return none.
 */
static void Protrom_Transport_OutHashCallback(const void *const Data_p, uint32 Length, const uint8 *const Hash_p, void *Param_p)
{
    Protrom_Packet_t *Packet_p = (Protrom_Packet_t *)Param_p;

    memcpy(&Packet_p->CRC, Hash_p, sizeof(uint16));
    memcpy((uint8 *)((Packet_p->Buffer_p) + PROTROM_HEADER_LENGTH + (Packet_p->Header.PayloadLength)), Hash_p, sizeof(uint16));
    Protrom_SerializeHeader(Packet_p->Buffer_p, &Packet_p->Header);
    (void)QUEUE(Packet_p->Communication_p, FifoEnqueue_Fn)(OBJECT_QUEUE(Packet_p->Communication_p), Packet_p->Communication_p->Outbound_p, Packet_p);
}
Exemple #5
0
static __inline__ mpqueue_head_t *
timer_call_entry_enqueue_deadline(
	timer_call_t			entry,
	mpqueue_head_t			*queue,
	uint64_t			deadline)
{
	return MPQUEUE(call_entry_enqueue_deadline(CE(entry),
						   QUEUE(queue), deadline));
}
/*
 * Initializes the PROTOROM network layer.
 *
 * @param [in]  Communication_p Communication module context.
 *
 * @retval  E_SUCCESS                   After successful execution.
 * @retval  E_FAILED_TO_INIT_COM_DEVICE Failed to initialize the communication
 *                                      device.
 */
ErrorCode_e Protrom_Network_Initialize(Communication_t *Communication_p)
{
    memset(PROTROM_NETWORK(Communication_p), 0, sizeof(Protrom_NetworkContext_t));
    PROTROM_NETWORK(Communication_p)->Outbound.TxCriticalSection = Do_CriticalSection_Create();

    /* Simulate a finished read to get the inbound state-machine going. */
    Protrom_Network_ReadCallback(NULL, 0, Communication_p->CommunicationDevice_p);
    (void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Outbound_p, QUEUE_NONEMPTY, Protrom_QueueCallback, Communication_p);

    return E_SUCCESS;
}
Exemple #7
0
void queue_add_html(char *s)
{
	if(!strncmp(s, "file://", 7)){
		char *p = s + 7;
#ifdef _WIN32
		p++;
#endif
		html_expand(p);
		if(!queue_has(file_queue, p))
			QUEUE(p);
	}else
		fprintf(stderr, "warning: can't add \"%s\" to queue\n", s);
}
/*
 * Shutdown the PROTROM network layer.
 *
 * @param [in]  Communication_p Communication module context.
 *
 * @retval  E_SUCCESS After successful execution.
 */
ErrorCode_e Protrom_Network_Shutdown(const Communication_t *const Communication_p)
{
    Protrom_Inbound_t *In_p = &(PROTROM_NETWORK(Communication_p)->Inbound);

    if (NULL != In_p->Packet_p) {
        if (NULL != In_p->Packet_p->Buffer_p) {
            free(In_p->Packet_p->Buffer_p);
        }

        free(In_p->Packet_p);
        In_p->Packet_p = NULL;
    }

    (void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Outbound_p, QUEUE_NONEMPTY, NULL, NULL);
    (void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Outbound_p, QUEUE_EMPTY, NULL, NULL);

    (void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p, QUEUE_NONEMPTY, NULL, NULL);
    (void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p, QUEUE_EMPTY, NULL, NULL);

    Do_CriticalSection_Destroy(&(PROTROM_NETWORK(Communication_p)->Outbound.TxCriticalSection));

    return E_SUCCESS;
}
Exemple #9
0
void
avr_cycle_timer_reset(
		struct avr_t * avr)
{
	avr_cycle_timer_pool_t * pool = &avr->cycle_timers;
	memset(pool, 0, sizeof(*pool));
	// queue all slots into the free queue
	for (int i = 0; i < MAX_CYCLE_TIMERS; i++) {
		avr_cycle_timer_slot_p t = &pool->timer_slots[i];
		QUEUE(pool->timer_free, t);
	}
	avr->run_cycle_count = 1;
	avr->run_cycle_limit = 1;
}
/*
 * Handles all registered TL processes for PROTROM protocol family.
 *
 * @param [in]  Communication_p Communication module context.
 *
 * @retval  E_SUCCESS After successful execution.
 */
ErrorCode_e Protrom_Transport_Poll(Communication_t *Communication_p)
{
    ErrorCode_e ReturnValue = E_SUCCESS;
    Protrom_Packet_t *Packet_p = NULL;

    Protrom_Network_ReceiverHandler(Communication_p);
    Packet_p = (Protrom_Packet_t *)QUEUE(Communication_p, FifoDequeue_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p);

    if (NULL == Packet_p) {
        return E_ALLOCATE_FAILED;
    }

    ReturnValue = Protrom_Process(Communication_p, Packet_p);

    return ReturnValue;
}
Exemple #11
0
static __inline__ mpqueue_head_t *
timer_call_entry_enqueue_deadline(
	timer_call_t			entry,
	mpqueue_head_t			*queue,
	uint64_t			deadline)
{
	mpqueue_head_t	*old_queue = MPQUEUE(CE(entry)->queue);

	call_entry_enqueue_deadline(CE(entry), QUEUE(queue), deadline);

	/* For efficiency, track the earliest soft deadline on the queue,
	 * so that fuzzy decisions can be made without lock acquisitions.
	 */
	queue->earliest_soft_deadline = ((timer_call_t)queue_first(&queue->head))->soft_deadline;

	if (old_queue)
		old_queue->count--;
	queue->count++;

	return old_queue;
}
Exemple #12
0
void
avr_cycle_timer_cancel(
		avr_t * avr,
		avr_cycle_timer_t timer,
		void * param)
{
	avr_cycle_timer_pool_t * pool = &avr->cycle_timers;

	// find its place in the list
	avr_cycle_timer_slot_p t = pool->timer, last = NULL;
	while (t) {
		if (t->timer == timer && t->param == param) {
			DETACH(pool->timer, last, t);
			QUEUE(pool->timer_free, t);
			break;
		}
		last = t;
		t = t->next;
	}
	avr_cycle_timer_reset_sleep_run_cycles_limited(avr);
}
Exemple #13
0
static __inline__ mpqueue_head_t *
timer_call_entry_enqueue_deadline(
	timer_call_t		entry,
	mpqueue_head_t		*queue,
	uint64_t		deadline)
{
	mpqueue_head_t	*old_queue = MPQUEUE(CE(entry)->queue);

	if (!hw_lock_held((hw_lock_t)&entry->lock))
		panic("_call_entry_enqueue_deadline() "
			"entry %p is not locked\n", entry);
	/* XXX More lock pretense:  */
	if (!hw_lock_held((hw_lock_t)&queue->lock_data))
		panic("_call_entry_enqueue_deadline() "
			"queue %p is not locked\n", queue);
	if (old_queue != NULL && old_queue != queue)
		panic("_call_entry_enqueue_deadline() "
			"old_queue %p != queue", old_queue);

	call_entry_enqueue_deadline(CE(entry), QUEUE(queue), deadline);

	return (old_queue);
}
Exemple #14
0
void
TkInOutEvents(
    XEvent *eventPtr,		/* A template X event. Must have all fields
				 * properly set except for type, window,
				 * subwindow, x, y, detail, and same_screen.
				 * (Not all of these fields are valid for
				 * FocusIn/FocusOut events; x_root and y_root
				 * must be valid for Enter/Leave events, even
				 * though x and y needn't be valid). */
    TkWindow *sourcePtr,	/* Window that used to have the pointer or
				 * focus (NULL means it was not in a window
				 * managed by this process). */
    TkWindow *destPtr,		/* Window that is to end up with the pointer
				 * or focus (NULL means it's not one managed
				 * by this process). */
    int leaveType,		/* Type of events to generate for windows
				 * being left (LeaveNotify or FocusOut). 0
				 * means don't generate leave events. */
    int enterType,		/* Type of events to generate for windows
				 * being entered (EnterNotify or FocusIn). 0
				 * means don't generate enter events. */
    Tcl_QueuePosition position)	/* Position at which events are added to the
				 * system event queue. */
{
    register TkWindow *winPtr;
    int upLevels, downLevels, i, j, focus;

    /*
     * There are four possible cases to deal with:
     *
     * 1. SourcePtr and destPtr are the same. There's nothing to do in this
     *    case.
     * 2. SourcePtr is an ancestor of destPtr in the same top-level window.
     *    Must generate events down the window tree from source to dest.
     * 3. DestPtr is an ancestor of sourcePtr in the same top-level window.
     *    Must generate events up the window tree from sourcePtr to destPtr.
     * 4. All other cases. Must first generate events up the window tree from
     *    sourcePtr to its top-level, then down from destPtr's top-level to
     *    destPtr. This form is called "non-linear."
     *
     * The call to FindCommonAncestor separates these four cases and decides
     * how many levels up and down events have to be generated for.
     */

    if (sourcePtr == destPtr) {
	return;
    }
    if ((leaveType == FocusOut) || (enterType == FocusIn)) {
	focus = 1;
    } else {
	focus = 0;
    }
    FindCommonAncestor(sourcePtr, destPtr, &upLevels, &downLevels);

    /*
     * Generate enter/leave events and add them to the grab event queue.
     */

#define QUEUE(w, t, d)					\
    if (w->window != None) {				\
	eventPtr->type = t;				\
	if (focus) {					\
	    eventPtr->xfocus.window = w->window;	\
	    eventPtr->xfocus.detail = d;		\
	} else {					\
	    eventPtr->xcrossing.detail = d;		\
	    TkChangeEventWindow(eventPtr, w);		\
	}						\
	Tk_QueueWindowEvent(eventPtr, position);	\
    }

    if (downLevels == 0) {
	/*
	 * SourcePtr is an inferior of destPtr.
	 */

	if (leaveType != 0) {
	    QUEUE(sourcePtr, leaveType, NotifyAncestor);
	    for (winPtr = sourcePtr->parentPtr, i = upLevels-1; i > 0;
		    winPtr = winPtr->parentPtr, i--) {
		QUEUE(winPtr, leaveType, NotifyVirtual);
	    }
	}
	if ((enterType != 0) && (destPtr != NULL)) {
	    QUEUE(destPtr, enterType, NotifyInferior);
	}
    } else if (upLevels == 0) {
	/*
	 * DestPtr is an inferior of sourcePtr.
	 */

	if ((leaveType != 0) && (sourcePtr != NULL)) {
	    QUEUE(sourcePtr, leaveType, NotifyInferior);
	}
	if (enterType != 0) {
	    for (i = downLevels-1; i > 0; i--) {
		for (winPtr = destPtr->parentPtr, j = 1; j < i;
			winPtr = winPtr->parentPtr, j++) {
		    /* empty */
		}
		QUEUE(winPtr, enterType, NotifyVirtual);
	    }
	    if (destPtr != NULL) {
		QUEUE(destPtr, enterType, NotifyAncestor);
	    }
	}
    } else {
	/*
	 * Non-linear: neither window is an inferior of the other.
	 */

	if (leaveType != 0) {
	    QUEUE(sourcePtr, leaveType, NotifyNonlinear);
	    for (winPtr = sourcePtr->parentPtr, i = upLevels-1; i > 0;
		    winPtr = winPtr->parentPtr, i--) {
		QUEUE(winPtr, leaveType, NotifyNonlinearVirtual);
	    }
	}
	if (enterType != 0) {
	    for (i = downLevels-1; i > 0; i--) {
		for (winPtr = destPtr->parentPtr, j = 1; j < i;
			winPtr = winPtr->parentPtr, j++) {
		}
		QUEUE(winPtr, enterType, NotifyNonlinearVirtual);
	    }
	    if (destPtr != NULL) {
		QUEUE(destPtr, enterType, NotifyNonlinear);
	    }
	}
    }
}
Exemple #15
0
void maos_isim(int isim){
    const PARMS_T *parms=global->parms;
    RECON_T *recon=global->recon;
    SIM_T   *simu =global->simu;
    int iseed=global->iseed;
    int simstart=parms->sim.start;
    int simend=parms->sim.end;
    if(isim==simstart+1){//skip slow first step.
	tk_atm=myclockd();
    }
    if(isim+2+parms->sim.dtrat_hi>=simend){
	draw_single=0;
    }
    double ck_0=myclockd();
    simu->isim=isim;
    simu->status->isim=isim;
    sim_update_etf(simu);
    if(parms->atm.frozenflow){
#if USE_CUDA
	if(parms->gpu.evl || parms->gpu.wfs){
	    /*may need to copy another part */
	    gpu_atm2gpu(simu->atm, simu->atmscale, parms, iseed, isim);
	}
#endif
    }else{
	//Do not put this one inside parallel 
	genatm(simu);
	/*re-seed the atmosphere in case atm is loaded from shm/file */
	seed_rand(simu->atm_rand, lrand(simu->init_rand));
    }
    OMPTASK_SINGLE{
	if(parms->sim.dmproj){
	    /* teporarily disable FR.M so that Mfun is used.*/
	    cell *FRM=recon->FR.M; recon->FR.M=NULL; 
	    muv_solve(&simu->dmproj, &recon->FL, &recon->FR, NULL);
	    recon->FR.M=FRM;/*set FR.M back*/
	    if(parms->save.dm){
		zfarr_dcell(simu->save->dmproj, simu->isim, simu->dmproj);
	    }
	    if(!parms->fit.square){
		/* Embed DM commands to a square array for fast ray tracing */
		for(int idm=0; idm<parms->ndm; idm++){
		    loc_embed(simu->dmprojsq->p[idm], recon->aloc->p[idm], simu->dmproj->p[idm]->p);
		}
	    }
#if USE_CUDA
	    if(parms->gpu.evl || parms->gpu.wfs){
		gpu_dmproj2gpu(simu->dmprojsq);
	    }
#endif
	}
	save_dmreal(simu);
	extern int NO_RECON, NO_WFS, NO_EVL;
	if(PARALLEL){
	    /*
	      We do the big loop in parallel to make better use the
	      CPUs. Notice that the reconstructor is working on grad from
	      last time step so that there is no confliction in data access.
	    */
	    /*when we want to apply idealngs correction, wfsgrad need to wait for perfevl. */
	    long group=0;
	    if(parms->gpu.evl && !NO_EVL){
		//Queue tasks on GPU, no stream sync is done
		QUEUE_THREAD(group, simu->perf_evl_pre, 0);
	    }
	    if(!parms->tomo.ahst_idealngs && parms->gpu.wfs && !NO_WFS){
		//task for each wfs
		QUEUE_THREAD(group, simu->wfs_grad_pre, 0);
	    }
	    if(!NO_RECON){
		//don't put this first. It has cpu overhead in computing gradol
		QUEUE(group, reconstruct, simu, 1, 0);
	    }
	    if(!NO_EVL){
		if(parms->gpu.evl){
		    //wait for GPU tasks to be queued before calling sync
		    WAIT(group);
		}
		QUEUE(group, perfevl, simu, 1, 0);
	    }
	    if(!NO_WFS){
		if(parms->tomo.ahst_idealngs || (parms->gpu.wfs && !parms->gpu.evl)){
		    //in ahst_idealngs mode, weight for perfevl to finish.
		    //otherwise, wait for GPU tasks to be queued before calling sync
		    WAIT(group);
		}
		QUEUE(group, wfsgrad, simu, 1, 0);
	    }
	    if(!NO_RECON){
		//wait for all tasks to finish before modifying dmreal
		WAIT(group);
		shift_grad(simu);/*before filter() */
		filter_dm(simu);/*updates dmreal, so has to be after prefevl/wfsgrad is done. */
	    }
	    WAIT(group);
	}else{/*do the big loop in serial mode. */
	    if(parms->sim.closeloop){
		if(!NO_EVL) perfevl(simu);/*before wfsgrad so we can apply ideal NGS modes */
		if(!NO_WFS) wfsgrad(simu);/*output grads to gradcl, gradol */
		if(!NO_RECON) {
		    reconstruct(simu);/*uses grads from gradlast cl, gradlast ol. */
		    shift_grad(simu);
		    filter_dm(simu);
		}
	    }else{/*in OL mode,  */
		if(!NO_WFS) wfsgrad(simu);
		if(!NO_RECON) {
		    shift_grad(simu);
		    reconstruct(simu);
		    filter_dm(simu);
		}
		if(!NO_EVL) perfevl(simu);
	    }
	}
    }
    double ck_end=myclockd();
    long steps_done=iseed*(simend-simstart)+(isim+1-simstart);
    long steps_rest=parms->sim.nseed*(simend-simstart)-steps_done;
    if(isim!=simstart){
	simu->status->rest=(long)((ck_end-tk_0-(tk_atm-tk_1)*(iseed+1))/steps_done*steps_rest
				  +(tk_atm-tk_1)*(parms->sim.nseed-iseed-1));
	simu->status->mean=(ck_end-tk_atm)/(double)(isim-simstart);
    }
    simu->status->laps=(long)(ck_end-tk_0);
    simu->status->tot  =ck_end-ck_0;
    simu->status->wfs  =simu->tk_wfs;
    simu->status->recon=simu->tk_recon;
    simu->status->other=simu->tk_cache;
    simu->status->eval =simu->tk_eval;
    simu->status->scale=1;
    if(simu->timing){
	simu->timing->p[isim*simu->timing->nx]=get_job_mem();
	simu->timing->p[isim*simu->timing->nx+1]=simu->status->tot;
	simu->timing->p[isim*simu->timing->nx+2]=simu->status->wfs;
	simu->timing->p[isim*simu->timing->nx+3]=simu->status->recon;
	simu->timing->p[isim*simu->timing->nx+4]=simu->status->eval;
    }
    double this_time=myclockd();
    if(this_time>simu->last_report_time+1 || isim+1==simend || parms->sim.pause){
	/*we don't print out or report too frequently. */
	simu->last_report_time=this_time;
#if defined(__linux__) || defined(__APPLE__)
	scheduler_report(simu->status);
#endif
	print_progress(simu);
    }
}
// Do not remove the include below
#include "MxBmesh.h"
#include <util/delay.h>

#define TIMER2TICKS 1 //this is timer period
byte  MXBMESH::retrysend=0;


byte MXBMESH::lastrbseq=0; //last rb seq ,seq start from 255
byte MXBMESH::lasthandledseq[NODECOUNT_MAX]; //last  seq

byte MXBMESH::sendpacketseq=255; //neigbour cast seq
QUEUE MXBMESH::rxqueue=QUEUE();
QUEUE MXBMESH::txqueue=QUEUE();
byte MXBMESH::broadcast_interval_passed=0;
uint16_t MXBMESH::dataupload_interval_passed=0;
uint16_t MXBMESH::timeout_interval_passed=0;
#if WITHSINKSOFT
byte MXBMESH::rxserialbuf[SINKMTU];
byte MXBMESH::rxserialbufindex=0;
HardwareSerial *MXBMESH::sinkSerial=NULL;
#endif
uint8_t MXBMESH::hasIntervalElapsedFunction=0;
void (*MXBMESH::IntervalElapsedFunction)();
uint8_t MXBMESH::hasDownloadDataFunction=0;
void (*MXBMESH::DownloadDataFunction)(uint8_t* payload,uint8_t len);
uint16_t MXBMESH::Timeout=0;
void (*MXBMESH::TimeoutFunction)();
uint8_t  MXBMESH::hasSerialHandlerFunction;
uint8_t (*MXBMESH::SerialHandlerFunction)(uint8_t  *buf,byte len);
uint8_t MXBMESH::hasGetdataHandlerFunction;