Пример #1
0
void core1_high() {
	printc("core %ld high prio thd %d running.\n", cos_cpuid(), cos_get_thd_id());

	create_thd(0, HIGH_PRIO);

	create_thd(1, LOW_PRIO);

	/* Brand operations removed. Add acap creation here. */
	int received_ipi = 0;

	int param[4];
	u64_t s, e;
	int iter = 0;
	while (1) {
		int ret = 0;
		/* printc("core %ld going to wait, thd %d\n", cos_cpuid(), cos_get_thd_id()); */

		/* if (-1 == (ret = cos_ainv_wait(...))) BUG(); */

		/* printc("core %ld, rec %d\n", cos_cpuid(), ++received_ipi); */
		param[0] = shared_mem[0];
		param[1] = shared_mem[1];
		param[2] = shared_mem[2];
		param[3] = shared_mem[3];
		assert(param[0] == 2);
		assert(param[1] == 4);
		assert(param[2] == 6);
		assert(param[3] == 8);

		/* rdtscll(e); */
		/* data[iter++] = e - c1_tsc; */

		int i;
		for (i = 0; i < n_wait; i++) {
			delay(20);
			/* printc("core %d triggering evt %d, i %d....\n", cos_cpuid(), evt, i); */
			shared_ret = 10;

			/* rdtscll(s); */

			evt_trigger(cos_spd_id(), evt);
 
			/* rdtscll(e); */
			/* data[iter++] = e - s; */

			/* printc("core %d triggerred evt %d, i %d....\n", cos_cpuid(), evt, i); */
		}
	}
}
Пример #2
0
void core0_high() {
	printc("core %ld high prio thd %d running.\n", cos_cpuid(), cos_get_thd_id());

	create_thd(0, LOW_PRIO); // creates low on core 0

	int i = 0;
	n_wait = 1;

	delay(20);

	evt = evt_create(cos_spd_id());
	printc("core %ld created evt %d....\n", cos_cpuid(), evt);
	
	int my_ret;
	u64_t s, e;
	while (i < ITER) {
		/* rdtscll(s); */

		shared_mem[0] = 2;
		shared_mem[1] = 4;
		shared_mem[2] = 6;
		shared_mem[3] = 8;
		/* add async inv here. */
		
		/* rdtscll(e); */
		/* data[i] = e - s; */

		/* printc("core %d ipi sent, going to evt_wait....\n", cos_cpuid()); */

		/* rdtscll(c0_high); */

		int ret = evt_wait_n(cos_spd_id(), evt, n_wait);
		my_ret = shared_ret;

		rdtscll(e);
		data[i] = e - c0_tsc;

		assert(my_ret == 10);
		/* printc("core %d up from evt_wait....\n", cos_cpuid()); */
		i++;
	}
	printc("core %ld test done, going to output...\n", cos_cpuid());
	output();
	printc("core %ld output done.\n", cos_cpuid());
}
Пример #3
0
void cos_init(void) {
	static int first = 1;

	printc("thd %d, core %ld in pong\n", cos_get_thd_id(), cos_cpuid());

	if (first) {
		first = 0;
		create_thd(1, HIGH_PRIO);
		printc("thd %d, core %ld done init in pong\n", cos_get_thd_id(), cos_cpuid());

		return;
	}

//core 1
	static int first_core1 = 1;
	if (cos_cpuid() == 1) {
		if (first_core1 == 1) {
			first_core1 = 0;
			core1_high();
		} else {
			core1_low();
		}
		return;
	}
	
//core 0
	static int first_core0 = 1;
	if (cos_cpuid() == 0) {
		if (first_core0 == 1) {
			first_core0 = 0;
			core0_high();
		} else {
			core0_low();
		}
		return;
	}
	
	return;
}
Пример #4
0
void cos_init(void *arg)
{

	int start_time_in_ticks = 0;
	int duration_time_in_ticks = 0;

	int local_period = 0;

	static int first = 0;

//	static int pre_run = 0;

	parse_initstr();

	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;

	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 */
			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()); */
			periodic_wake_wait(cos_spd_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;
}