Exemple #1
0
void test_iploop()
{
	printc("set eip back testing....\n");
	assert(cos_thd_cntl(COS_THD_IP_LFT, med, 0, 0) != -1);
	timed_event_block(cos_spd_id(), 5);
	return;
}
void cos_init(void)
{
	static int first = 0;
	union sched_param sp;

	if(first == 0){
		first = 1;
		sp.c.type = SCHEDP_PRIO;
		sp.c.value = 4;
		high = sched_create_thd(cos_spd_id(), sp.v, 0, 0);
	} else {
		if (cos_get_thd_id() == high) {
			periodic_wake_create(cos_spd_id(), INJECTION_PERIOD);
			timed_event_block(cos_spd_id(), 1);
#ifdef SWIFI_ON
			// this is for each service fault coverage test
			while(1) {
				test++;
				while (test == 3) timed_event_block(cos_spd_id(), 100);
				recovery_upcall(cos_spd_id(), COS_UPCALL_SWIFI_BEFORE,
						SWIFI_SPD, 0);
				// in 1 tick, hope some thread is spinning in the target spd
				/* printc("swifi....call timed_event_block\n"); */
				timed_event_block(cos_spd_id(), 1);
				/* printc("swifi....return from timed_event_block\n"); */
				
				fault_inject(SWIFI_SPD);

				recovery_upcall(cos_spd_id(), COS_UPCALL_SWIFI_AFTER,
						SWIFI_SPD, 0);
				/* printc("swifi....call periodic_wake_wait\n"); */
				periodic_wake_wait(cos_spd_id());
				/* printc("swifi....return from periodic_wake_wait\n"); */
			}
#endif
#ifdef SWIFI_WEB
			// this is for web server fault injection only
			while(1) {
				fault_inject(target_spd[TARGET_SPD]);
				periodic_wake_wait(cos_spd_id());
			}
#endif
		}
	}
}
void cos_init(void *arg)
{
	cos_map_init_static(&conn_map);

	while (1) {
		timed_event_block(cos_spd_id(), HTTP_REPORT_FREQ);
		printc("HTTP conns %ld, reqs %ld\n", http_conn_cnt, http_req_cnt);
		http_conn_cnt = http_req_cnt = 0;
	}
	
	return;
}
Exemple #4
0
static int init(void) 
{
	int cnt = 0;
#ifdef LWIP_STATS
	int stats_cnt = 0;
#endif

	lock_static_init(&net_lock);
	/* printc("netlock id %d\n", net_lock.lock_id); */
	NET_LOCK_TAKE();

	torlib_init();
	net_conn_init();
	cos_net_create_netif_thd();
	init_lwip();

	NET_LOCK_RELEASE();
	/* Start the tcp timer */
	while (1) {
		/* Sleep for a quarter of seconds as prescribed by lwip */
		NET_LOCK_TAKE();

		if (++cnt == 4) {
#ifdef TEST_TIMING
			timing_output();
#endif
		}
#ifdef LWIP_STATS
		if (++stats_cnt == 20) {
			stats_cnt = 0;
			stats_display();
		}
#endif
		tcp_tmr();
		NET_LOCK_RELEASE();
		timed_event_block(cos_spd_id(), 25); /* expressed in ticks currently */
		/* printc("use timer to tcp debug thread here...\n"); */
		cos_mpd_update();
	}

	prints("net: Error -- returning from init!!!");
	BUG();
	return 0;
}
Exemple #5
0
void cos_init(void)
{
	static int first = 0;
	union sched_param sp;
	int i;
	
	if(first == 0){
		first = 1;

		sp.c.type = SCHEDP_PRIO;
		sp.c.value = 11;
		high = sched_create_thd(cos_spd_id(), sp.v, 0, 0);

		sp.c.type = SCHEDP_PRIO;
		sp.c.value = 12;
		low = sched_create_thd(cos_spd_id(), sp.v, 0, 0);
	} else {
		if (cos_get_thd_id() == high) {
#ifdef TEST_TE
			while(1) {
				rdtscll(start);
				timed_event_block(cos_spd_id(), 100);
				rdtscll(end);
				printc("(thd %d)time even blocked for %llu ticks\n", cos_get_thd_id(), (end-start));
			}
#endif
#ifdef TEST_PERIOD
			periodic_wake_create(cos_spd_id(), 100);
			while(1) {
				rdtscll(start);
				periodic_wake_wait(cos_spd_id());
				rdtscll(end);
				printc("time even blocked for %llu ticks\n", (end-start));
			}
#endif
		}
	}
	return;
}
Exemple #6
0
void 
cos_init(void)
{
	static int first = 0;
	union sched_param sp;
	int i;
	

	if(first == 0){
		first = 1;

		for (i=0; i<PAGE_NUM; i++) s_addr[i] = 0;
		for (i=0; i<PAGE_NUM; i++) d_addr[i] = 0;

		sp.c.type = SCHEDP_PRIO;
		sp.c.value = THREAD1;
		sched_create_thd(cos_spd_id(), sp.v, 0, 0);

	} else {
		timed_event_block(cos_spd_id(), 50);
		periodic_wake_create(cos_spd_id(), 1);
		i = 0;
		while(i++ < 80) { /* 80 x 10 x 4k  < 4M */
			printc("<<< MM RECOVERY TEST START (thd %d) >>>\n", cos_get_thd_id());
			get_test();
#ifdef BEST_TEST
			alias_test();
			revoke_test();
#endif

			/* all_in_one(); */

			printc("<<< MM RECOVERY TEST DONE!! >>> {%d}\n\n\n", i);
			periodic_wake_wait(cos_spd_id());
		}
	}
	
	return;
}
unsigned long ss_action(unsigned long exe_time_left, unsigned long const initial_exe_t)
{

	parse_initstr();

	/* printc(">> Now I thd %d am in ss spd %d\n",cos_get_thd_id(),cos_spd_id()); */

	if (AVG_INVC_CYCS > exe_time_left) return 0;
	exe_time_left -= AVG_INVC_CYCS;
	if (exe_time_left == 0) return 0;

	exe_time_left = do_something(exe_time_left, initial_exe_t);
	if (exe_time_left == 0) return 0;
		
	timed_event_block(cos_spd_id(), ss_time);  /* blocked for some ticks  */

	exe_time_left -= AVG_INVC_CYCS;
	if (exe_time_left == 0) return 0;

	exe_time_left = do_something(exe_time_left, initial_exe_t);

	return exe_time_left;
}
Exemple #8
0
void 
cos_init(void)
{
	static int first = 0;
	union sched_param sp;
	int i, j, k;
	
	if(first == 0){
		first = 1;

		sp.c.type = SCHEDP_PRIO;
		sp.c.value = 10;
		warm = sched_create_thd(cos_spd_id(), sp.v, 0, 0);

		sp.c.type = SCHEDP_PRIO;
		sp.c.value = 11;
		high = sched_create_thd(cos_spd_id(), sp.v, 0, 0);

		sp.c.type = SCHEDP_PRIO;
		sp.c.value = 15;
		med = sched_create_thd(cos_spd_id(), sp.v, 0, 0);

		sp.c.type = SCHEDP_PRIO;
		sp.c.value = 20;
		low = sched_create_thd(cos_spd_id(), sp.v, 0, 0);

	} else {
#ifdef EXAMINE_LOCK
		if (cos_get_thd_id() == high) {
			printc("<<<high thd %d>>>\n", cos_get_thd_id());
			timed_event_block(cos_spd_id(), 5);
			ec3_ser1_test();
		}

		if (cos_get_thd_id() == med) {
			printc("<<<med thd %d>>>\n", cos_get_thd_id());
			timed_event_block(cos_spd_id(), 2);
			ec3_ser1_test();
		}

		if (cos_get_thd_id() == low) {
			printc("<<<low thd %d>>>\n", cos_get_thd_id());
			ec3_ser1_test();
		}
#endif

#ifdef EXAMINE_EVT
		if (cos_get_thd_id() == high) {
			printc("<<<high thd %d>>>\n", cos_get_thd_id());
			ec3_ser1_test();
		}
		
		if (cos_get_thd_id() == med) {
			printc("<<<med thd %d>>>\n", cos_get_thd_id());
			ec3_ser1_test();
		}

		if (cos_get_thd_id() == warm) {
			printc("<<<warm thd %d>>>\n", cos_get_thd_id());
			ec3_ser2_test();
		}
		
		if (cos_get_thd_id() == low) {
			printc("<<<low thd %d>>>\n", cos_get_thd_id());
			ec3_ser2_test();
		}
#endif
	}

	return;
}
void cos_init(void *arg)
{

	int start_time_in_ticks = 0;
	int duration_time_in_ticks = 0;

	int local_period = 0;

	static int first = 1;

//	static int pre_run = 0;

	if (first) {
		union sched_param sp;
		int i;
		first = 0;
		parse_initstr();
		assert(priority);
		sp.c.type = SCHEDP_PRIO;
		sp.c.value = priority;

		if (sched_create_thd(cos_spd_id(), sp.v, 0, 0) == 0) BUG();
		if (priority == 30) { //best effort thds
			printc("thd num %d\n",thd_num);
				for (i=0; i<(thd_num-1); i++)
				sched_create_thd(cos_spd_id(), sp.v, 0, 0);
		}
		return;
	}

	local_period = period;

	unsigned long cyc_per_tick;
	cyc_per_tick = sched_cyc_per_tick();

	unsigned long exe_cycle;
	exe_cycle = cyc_per_tick/US_PER_TICK;
	exe_cycle = exe_cycle*exe_t;

	start_time_in_ticks = start_time*100;
	duration_time_in_ticks = duration_time*100;

	printc("In spd %ld Thd %d, period %d ticks, execution time %d us in %lu cycles\n", cos_spd_id(),cos_get_thd_id(), local_period, exe_t, exe_cycle);

	/* int event_thd = 0; */
	/* unsigned long pre_t_0 = 0; */
	if (local_period <= 0){/* Create all non-periodic tasks */

#ifdef BEST_EFF   // for best effort sys now
		int i;
		if (first == 0){
//			for (i= 0;i<5;i++) create_thd("r0");
			pre_t_0 = sched_timestamp();
			first = 1;
		}

		printc("<<<<1 thd %d in spd %ld\n",cos_get_thd_id(), cos_spd_id());
		event_thd = cos_get_thd_id();

		for (i = 0 ; i < 100; i++){
			left(200000,200000,0,0);
		}

		unsigned long pre_run_remained = 0;
		unsigned long numm = 10000*cyc_per_tick/US_PER_TICK;;
		while(1) {
			for (i = 0 ; i < 10; i++){
				pre_run_remained = numm;  /* refill */
				pre_run_remained = left(20000,20000,0,0);
				/* printc(" thd %d pre_t_0 %u pre_t %lu\n", cos_get_thd_id(), pre_t_0, pre_t); */
			}
			unsigned long pre_t = sched_timestamp();
			if ( pre_t > pre_t_0 + 1*100) break;
		}
		printc("BF thd %d finish pre_run\n", cos_get_thd_id());

#endif
		/* pub_duration_time_in_ticks = duration_time_in_ticks; */
		timed_event_block(cos_spd_id(), start_time_in_ticks);
		printc("<<<<2 thd %d in spd %ld\n",cos_get_thd_id(), cos_spd_id());
	}
	else {/* Create all periodic tasks */
		if (local_period == 0 || (exe_t > local_period*US_PER_TICK)) BUG();
		/* if (cos_get_thd_id() == 20) { */
		/* 	printc("pre allocating ...\n"); */
		/* 	int mm; */
		/* 	for (mm = 0 ; mm < 3000; mm++) */
		/* 		left(70000, 70000, 0, 0); */
		/* 	printc("done.\n"); */
		/* } */
		periodic_wake_create(cos_spd_id(), local_period);

		int i = 0;
		int waiting = 0;

		if(start_time_in_ticks <= 0)
			/* waiting = (50+100*10) / local_period;   /\* use 50 before. Now change to let BF threads run first 10 seconds before 0 second *\/ */
			waiting = (50) / local_period;   /* use 50 before. Now change to let BF threads run first 10 seconds before 0 second */
		else
			waiting = start_time_in_ticks / local_period;
		do {
			periodic_wake_wait(cos_spd_id());
		} while (i++ < waiting); /* wait 50 ticks */
	}

/* Let all tasks run */
	unsigned long exe_cyc_remained = 0;
//	unsigned long long t;
//	unsigned long val;
	int refill_number = 0;

	unsigned long exe_cyc_event_remained = 0;
//	printc("start...!!\n");
	while (1) {
		if(local_period <= 0){			/* used for transient non-periodic tasks only */
			exe_cyc_event_remained = exe_cycle;  /* refill */
			while(1) {
				exe_cyc_event_remained = exe_cycle;  /* refill */
				/* rdtscll(t); */
				/* val = (int)(t & (TOTAL_AMNT-1)); */
				/* if (val >= 64){ */
					exe_cyc_event_remained = left(exe_cyc_event_remained,exe_cycle,0,0);
				/* } */
				/* else{ */
				/* 	exe_cyc_event_remained = right(exe_cyc_event_remained,exe_cycle,0,0); */
				/* } */
				unsigned long t = sched_timestamp();
				/* if ( t > (unsigned long)(7*100 + start_time_in_ticks + duration_time_in_ticks)) { */
				/* 	printc("thd %d left!!!\n",cos_get_thd_id()); */
				if ( t > (unsigned long)( start_time_in_ticks + duration_time_in_ticks)) {
					/* printc("thd %d left>>>\n",cos_get_thd_id()); */

					timed_event_block(cos_spd_id(), 10000);
				}
			}
		}
		else{
			/* rdtscll(start); */
			/* used for transient periodic tasks only */
			if (start_time_in_ticks > 0 && (local_period*refill_number > duration_time_in_ticks)){
				for(;;) periodic_wake_wait(cos_spd_id());
			}
			exe_cyc_remained = exe_cycle;  /* refill */
			/* printc("thd %d in home comp, going to call\n",cos_get_thd_id()); */
			while(exe_cyc_remained) {
				exe_cyc_remained = left(exe_cyc_remained,exe_cycle,0,0);	  
			}
			
			/* rdtscll(end); */
			/* printc("%d, times : %d\n", cos_get_thd_id(), times); */
			/* printc("\n @@thd %ld is sleeping in spd %d\n", cos_get_thd_id(), cos_spd_id()); */
			/* printc("thd %d back in home comp, going to block\n",cos_get_thd_id()); */
			periodic_wake_wait(cos_spd_id());
			/* printc("thd %d woke up.\n",cos_get_thd_id()); */
			refill_number++;	  
			/* printc("\n @@thd %ld is waking in spd %d\n", cos_get_thd_id(), cos_spd_id()); */
			/* printc("\n thd %d refilled...%d\n", cos_get_thd_id(), refill_number); */
		}
	}
	return;
}
static unsigned long do_action(unsigned long exe_time_left, const unsigned long initial_exe_t, cbuf_t cbt_map, int len_map)
{

	unsigned long i, j, val;
	unsigned long long t;
	int mark = 0;
	int len = SZ;

	static int first = 1;

	unsigned long has_run;   /* thread has run cycles in this inv */
	
	u32_t id, idx;
	cbuf_t cbt[NCBUF];
	memset(cbt, 0 , NCBUF*sizeof(cbuf_t));

	void *mt[NCBUF] = {};
	int get[NCBUF];
	memset(get, 0 , NCBUF*sizeof(cbuf_t));

	parse_initstr();
	/* DOUTs("thd %d enter comp %ld!\n", cos_get_thd_id(), cos_spd_id()); */
	if (first) {
		unsigned long temp = 0;
		temp = measure_loop_costs(spin);
		first = 0;
		/*if (exe_time_left < temp) return 0;
		  exe_time_left -= temp;*/
	}
	if (AVG_INVC_CYCS > exe_time_left) return 0;
	exe_time_left -= AVG_INVC_CYCS;


#ifdef CBUF2BUF
	u64_t start,end;	
	char *b;
	if(cbt_map && len_map){
		rdtscll(start);
		b = cbuf2buf(cbt_map,len_map);
		rdtscll(end);
		DOUTs("---- cost Bf2Bf :: %llu in spd %ld\n", end-start, cos_spd_id());
		if (!b) {
			DOUTs("Can not map into this spd %ld\n", cos_spd_id());
			return cbuf_null();
		}
		memset(b, 's', len_map);
		/* DOUTs("after buf2buf write sth...\n"); */
	}
#endif
	for (j = 0 ; j < num_invs ; j++) {
		if (exe_time_left == 0) return 0;
		kkk = 0;

		unsigned long ss = initial_exe_t / (100 / PERCENT_EXE) / 15 * 2;
		for (i=0; i<ss; i++) kkk++;
		has_run = ss * 15 / 2;//loop_cost;//

		if (has_run > exe_time_left) {
			return 0;
		}
		exe_time_left -= has_run;

		rdtscll(t);
		val = (int)(t & (TOTAL_AMNT-1));
		if (ss_attached && (val < prop_call_ss)) {
			//exe_time_left = ss_action(exe_time_left, initial_exe_t);

			SYNTH_TAKE();
			for (i = 0; i < NCBUF ; i++){
				rdtscll(t);
				cbt[i] = cbuf_null();
				mt[i] = cbuf_alloc(len, &cbt[i]);
			}
			SYNTH_RELEASE();
			printc("I am suspended :(\n");
			timed_event_block(cos_spd_id(), 2);
			printc("I am back :)\n");
			for (i = 0; i < NCBUF ; i++){
				cbuf_free(mt[i]);
			}
		}
		if (exe_time_left == 0) return 0;
		

#ifdef ALLOC_CBUF
		SYNTH_TAKE();
		for (i = 0; i < NCBUF ; i++){
			rdtscll(t);
			val = (int)(t & (TOTAL_AMNT-1));

			if (val >= cbuf_l_to_r) {
				cbt[i] = cbuf_null();
				rdtscll(start);
				mt[i] = cbuf_alloc(len, &cbt[i]);
				rdtscll(end);
				cbuf_unpack(cbt[i], &id, &idx);
				memset(mt[i], 'a', len);
				get[i] = 1;
				mark = 1;
			}
		}
		SYNTH_RELEASE();
#endif

		rdtscll(t);
		val = (int)(t & (TOTAL_AMNT-1));

		if(mark == 1){
			if (val >= l_to_r) {
				exe_time_left = calll_left(exe_time_left, initial_exe_t , cbt[0], len);
				
			} else {
				exe_time_left = callr_right(exe_time_left, initial_exe_t, cbt[0], len);
			}
		}
		else{
			if (val >= l_to_r) {
				exe_time_left = calll_left(exe_time_left, initial_exe_t , 0, 0);
				
			} else {
				exe_time_left = callr_right(exe_time_left, initial_exe_t, 0, 0);
			}
		}	

#ifdef ALLOC_CBUF
		for (i = 0; i < NCBUF ; i++){
			if (get[i] == 1){
				get[i] = 0;
				rdtscll(start);
				cbuf_free(mt[i]);
				rdtscll(end);
			}
		}
#endif

	}

	return exe_time_left;
}
/* 
 * Dependencies here (thus priority inheritance) will NOT be used if
 * you specify a timeout value.
 */
int lock_component_take(spdid_t spd, unsigned long lock_id, unsigned short int thd_id, unsigned int microsec)
{
	struct meta_lock *ml;
	spdid_t spdid = cos_spd_id();
	unsigned short int curr = (unsigned short int)cos_get_thd_id();
	struct blocked_thds blocked_desc = {.thd_id = curr};
	int ret = 0;
	
//	print("thread %d from spd %d locking for %d micrseconds.", curr, spdid, microsec);

	ACT_RECORD(ACT_LOCK, spd, lock_id, cos_get_thd_id(), thd_id);
	TAKE(spdid);

	if (0 == microsec) {
		ret = TIMER_EXPIRED;
		goto error;
	}
	ml = lock_find(lock_id, spd);
	/* tried to access a lock not yet created */
	if (!ml) {
		ret = -1;
		//print("take wtf%d%d%d", 0,0,0);
		goto error;
	}
	if (lock_is_thd_blocked(ml, curr)) {
		prints("lock: lock_is_thd_blocked failed in lock_component_take\n");
		goto error;
	}

	/* The calling component needs to retry its user-level lock,
	 * some preemption has caused the generation count to get off,
	 * i.e. we don't have the most up-to-date view of the
	 * lock's state */
	if (ml->gen_num != generation) {
		ml->gen_num = generation;
		ret = 0;
		goto error;
	}
	generation++;

	/* Note that we are creating the list of blocked threads from
	 * memory allocated on the individual thread's stacks. */
	INIT_LIST(&blocked_desc, next, prev);
	ADD_LIST(&ml->b_thds, &blocked_desc, next, prev);
	blocked_desc.timed = (TIMER_EVENT_INF != microsec);
	//ml->owner = thd_id;

	RELEASE(spdid);

	/* Bypass calling the timed every component if there is an infinite wait */
//	assert(TIMER_EVENT_INF == microsec);
//	assert(!blocked_desc.timed);
	if (TIMER_EVENT_INF == microsec) {
		if (-1 == sched_block(spdid, thd_id)) BUG();
		if (!EMPTY_LIST(&blocked_desc, next, prev)) BUG();
		/* 
		 * OK, this seems ridiculous but here is the rational: Assume
		 * we are a middle-prio thread, and were just woken by a low
		 * priority thread. We will preempt that thread when woken,
		 * and will continue here.  If a high priority thread is also
		 * waiting on the lock, then we would preempt the low priority
		 * thread while it should wake the high prio thread. With the
		 * following crit sect will switch to the low prio thread that
		 * still holds the component lock.  See the comments in
		 * lock_component_release. 
		 */
		//TAKE(spdid);
		//RELEASE(spdid);

		ACT_RECORD(ACT_WAKEUP, spd, lock_id, cos_get_thd_id(), 0);
		ret = 0;
	} else {
		assert(0);
#ifdef NIL
		/* ret here will fall through.  We do NOT use the
		 * dependency here as I can't think through the
		 * repercussions */
		if (-1 == (ret = timed_event_block(spdid, microsec))) return ret;

		/* 
		 * We might have woken from a timeout, which means
		 * that we need to remove this thread from the waiting
		 * list for the lock.
		 */
		TAKE(spdid);
		ml = lock_find(lock_id, spd);
		if (!ml) {
			ret = -1;
			goto error;
		}
		REM_LIST(&blocked_desc, next, prev);
		RELEASE(spdid);

		ACT_RECORD(ACT_WAKEUP, spd, lock_id, cos_get_thd_id(), 0); 
		/* ret is set to the amnt of time we blocked */
#endif 
	}
	return ret;
error:
	RELEASE(spdid);
	return ret;
}
Exemple #12
0
void 
cos_init(void)
{
	static int first = 0;
	union sched_param sp;
	int i, j, k;
	
	if(first == 0){
		first = 1;

		sp.c.type = SCHEDP_PRIO;
		sp.c.value = 10;
		warm = sched_create_thd(cos_spd_id(), sp.v, 0, 0);

		sp.c.type = SCHEDP_PRIO;
		sp.c.value = 11;
		high = sched_create_thd(cos_spd_id(), sp.v, 0, 0);
		printc("<<<high thd %d>>>\n", high);

		sp.c.type = SCHEDP_PRIO;
		sp.c.value = 15;
		med = sched_create_thd(cos_spd_id(), sp.v, 0, 0);
		printc("<<<med thd %d>>>\n", med);

		sp.c.type = SCHEDP_PRIO;
		sp.c.value = 20;
		low = sched_create_thd(cos_spd_id(), sp.v, 0, 0);
		printc("<<<low thd %d>>>\n", low);

	} else {
/**************************************/
/**************************************/
/**************************************/
/********  PI Overrun Fault*********/
#if defined MON_PI_OVERRUN 
		if (cos_get_thd_id() == high) {
			printc("<<<high thd %d>>>\n", cos_get_thd_id());
			periodic_wake_create(cos_spd_id(), 5);
			timed_event_block(cos_spd_id(), 3);
			try_cs_hp();
		}
		/* if (cos_get_thd_id() == med) { */
		/* 	printc("<<<med thd %d>>>\n", cos_get_thd_id()); */
		/* 	periodic_wake_create(cos_spd_id(), 8); */
		/* 	timed_event_block(cos_spd_id(), 6); */
		/* 	try_cs_mp(); */
		/* } */

		if (cos_get_thd_id() == low) {
			printc("<<<low thd %d>>>\n", cos_get_thd_id());
			periodic_wake_create(cos_spd_id(), 13);
			try_cs_lp();
		}
/********  PI Scheduling Fault *********/
#elif defined MON_PI_SCHEDULING
		/* if (cos_get_thd_id() == warm) { */
		/* 	printc("<<<worm thd %d (highest prio)>>>\n", cos_get_thd_id()); */
		/* 	sched_block(cos_spd_id(), 0); */
		/* 	printc("<<<worm thd %d is back...>>>\n", cos_get_thd_id()); */
		/* 	while(1); */
		/* } */
		if (cos_get_thd_id() == high) {
			printc("<<<high thd %d>>>\n", cos_get_thd_id());
			periodic_wake_create(cos_spd_id(), 5);
			timed_event_block(cos_spd_id(), 10);
			try_cs_hp();
		}
		if (cos_get_thd_id() == med) {
			printc("<<<med thd %d>>>\n", cos_get_thd_id());
			periodic_wake_create(cos_spd_id(), 8);
			timed_event_block(cos_spd_id(), 6);
			try_cs_mp();
		}

		if (cos_get_thd_id() == low) {
			printc("<<<low thd %d>>>\n", cos_get_thd_id());
			periodic_wake_create(cos_spd_id(), 13);
			try_cs_lp();
		}
/********  Deadlock Fault*********/
#elif defined MON_DEADLOCK
		if (cos_get_thd_id() == high) {
			printc("<<<high thd %d>>>\n", cos_get_thd_id());
			printc("\n[[[[ MON_DEADLOCK Test....]]]]\n");
			periodic_wake_create(cos_spd_id(), 5);
			timed_event_block(cos_spd_id(), 3);
			try_cs_hp();
		}
		if (cos_get_thd_id() == med) {
			printc("<<<med thd %d>>>\n", cos_get_thd_id());
			periodic_wake_create(cos_spd_id(), 8);
			timed_event_block(cos_spd_id(), 1);
			try_cs_mp();
		}
		if (cos_get_thd_id() == low) {
			printc("<<<low thd %d>>>\n", cos_get_thd_id());
			periodic_wake_create(cos_spd_id(), 13);
			try_cs_lp();
		}
/********  Overrun in Scheduler *********/
#elif defined MON_SCHED  // 2 threads, bloc/wakeup N time, random delay in sched
		printc("thread %d is in MON_SCHED_DELAY\n", cos_get_thd_id());
		if (cos_get_thd_id() == high) {
			printc("<<<high thd %d>>>\n", cos_get_thd_id());
			periodic_wake_create(cos_spd_id(), 5);
			try_cs_hp();
		}
		if (cos_get_thd_id() == low) {
			printc("<<<low thd %d>>>\n", cos_get_thd_id());
			periodic_wake_create(cos_spd_id(), 13);
			try_cs_lp();
		}
/********  Overrun in MM *********/
#elif defined MON_MM  // 1 threads, do alloc/alias/revoke
		if (cos_get_thd_id() == high) {
			periodic_wake_create(cos_spd_id(), 5);
			printc("thread %d is in MON_MM\n", cos_get_thd_id());
			try_cs_hp();
		}
#elif defined MON_CAS_TEST
		printc("thread %d is in MON_CAS_TEST\n", cos_get_thd_id());
		if (cos_get_thd_id() == high) {
			timed_event_block(cos_spd_id(), 6);
			printc("<<<high thd %d>>>\n", cos_get_thd_id());
			test_iploop();
			return;
		}
#elif defined MON_PPONG
		if (cos_get_thd_id() == high) {
			printc("<<<high thd %d --- PPONG>>>\n", cos_get_thd_id());
			int i = 0;
			unsigned long long start_pp, end_pp;
			
			while(i++ < RUNITER) {
				rdtscll(start_pp);
				try_cs_hp();
				rdtscll(end_pp);
				printc("one invocation in cmon is %llu\n", end_pp-start_pp);
			}
		}
#elif defined MON_FPU
		if (cos_get_thd_id() == high) {
			printc("\n\n<<<high thd %d --- FPU>>>\n\n", cos_get_thd_id());
			try_cs_hp();
		}
#endif		
	}

	return;
}