void cbuf_call(char c)
{

	printc("\n****** MID: thread %d in spd %ld ******\n",cos_get_thd_id(), cos_spd_id());

	/* cbuf_t cb = cbuf_null(); */
	u32_t id, idx;
	/* u64_t start, end; */
	int i;

	cbuf_t cbt[iter];
	void *mt[iter];
	for (i = 0; i < iter ; i++){
		cbt[i] = cbuf_null();
		mt[i] = cbuf_alloc(SZ, &cbt[i]);
		cbuf_unpack(cbt[i], &id, &idx);
		printc("thread %d Now @ %p, memid %x, idx %x\n", cos_get_thd_id(), mt[i], id, idx);
		assert(mt[i]);
		memset(mt[i], c, SZ);
	}

	
	delay(DELAY);
	delay(DELAY);

	for (i = 0; i < iter ; i++){
		f(cbt[i],SZ);
	}


	/* delay(DELAY); */
	/* delay(DELAY); */

	printc("\n****** MID free: thread %d in spd %ld ******\n",cos_get_thd_id(), cos_spd_id());

	for (i = 0; i < iter ; i++){
		cbuf_free(mt[i]);
	}

	delay(DELAY);

	/* check_val(); */
	/* check_val1(); */

	/* m = cbuf_alloc(SZ, &cb); */
	/* cbuf_unpack(cb, &id, &idx); */
	/* printc("....Now @ %p, memid %x, idx %x\n", m, id, idx); */
	/* /\* printc("cb is %d\n",cb); *\/ */
	/* memset(m, c, SZ); */
	/* rdtscll(start); */
	/* for (i = 0 ; i < ITER ; i++) { */
	/* 	f(cb, SZ); */
	/* } */
	/* rdtscll(end); */
	/* printc("AVG: %lld\n", (end-start)/ITER); */
	/* printc("initial %c, after %c\n", c, ((char *)m)[0]); */
	/* cbuf_free(m); */

	return;
}
Example #2
0
cbuf_t 
f(cbuf_t cb, int len)
{
	char *b;

	b = cbuf2buf(cb, len);
	if (!b) {
		printc("WTF\n");
		return cbuf_null();
	}

//	memset(b, 'b', len);
	
	return cb;
}
Example #3
0
cbuf_t 
f(cbuf_t cb, int len)
{
	char *b;

	printc("\n****** BOT: thread %d in spd %ld ******\n",cos_get_thd_id(), cos_spd_id());
	b = cbuf2buf(cb, len);

	if (!b) {
		printc("WTF\n");
		return cbuf_null();
	}
	/* check_val(); */

	memset(b, 'b', len);

	return cb;
}
Example #4
0
int call_buf2buf(u32_t cb, int len) 
{
	u64_t start = 0, end = 0;
	char *b;
	
	rdtscll(start);
	b = cbuf2buf(cb,len);
	rdtscll(end);

        printc("cbuf2buf %llu cycs\n", end-start);
	
	if (!b) {
		printc("Can not map into this spd %ld\n", cos_spd_id());
		return cbuf_null();
	}
	memset(b, 's', len);
	
	return 0;
}
Example #5
0
int __attribute__((format(printf,1,2))) printc(char *fmt, ...)
{
    static td_t tor = 0;
    char *s;
    va_list arg_ptr;
    int ret;
    cbuf_t cb = cbuf_null();

    if (!tor) tor = printt_init();

    s = cbuf_alloc_ext(4096, &cb, CBUF_TMEM);
    assert(s);
    va_start(arg_ptr, fmt);
    ret = vsnprintf(s, 4096, fmt, arg_ptr);
    va_end(arg_ptr);
    print_twrite(cos_spd_id(), tor, cb, ret);
    cbuf_free(cb);

    return ret;
}
Example #6
0
void cos_init(void)
{
	u64_t start, end, start_tmp, end_tmp;
	int i, k, prev_sz = 1;

	cbuf_t cbt[NCBUF];
	memset(cbt, 0 , NCBUF*sizeof(cbuf_t));
	void *mt[NCBUF];
	unsigned int sz[NCBUF];

	for (i = 0; i < NCBUF ; i++){
		cbt[i] = cbuf_null();
		sz[i] = 0;
	}

	printc("\nMICRO BENCHMARK TEST (PINGPONG WITH CBUF)\n");

        /* RDTSCLL */
	printc("\n<<< RDTSCLL MICRO-BENCHMARK TEST >>>\n");
	rdtscll(start_tmp);
	for (i = 0 ; i < ITER ; i++) {
		rdtscll(start);
	}
	rdtscll(end_tmp);
	printc("%d rdtscll avg %lld cycs\n", ITER, (end_tmp-start_tmp)/ITER);
	
        /* PINGPONG */
	printc("\n<<< PINGPONG MICRO-BENCHMARK TEST >>>\n");
	call();
	for (k = 0; k <10 ;k++){
		
		rdtscll(start);
		for (i = 0 ; i < ITER ; i++) {
			call();
		}
		rdtscll(end);
		printc("%d invs avg %lld cycs\n", ITER, (end-start)/ITER);
	}
	printc("<<< PINGPONG BENCHMARK TEST DONE >>>\n");

        /* CACHING */
	printc("\n<<< WARM UP CBUF CACHE.......");
	for (i = 0; i < NCBUF ; i++){
		prev_sz += 4;
		prev_sz &= PAGE_SIZE-1;
		sz[i] = prev_sz;		
		mt[i] = cbuf_alloc(sz[i], &cbt[i]);
	}

	for (i = 0; i < NCBUF ; i++){
		simple_call_buf2buf(cbt[i], sz[i]);
	}

	for (i = 0; i < NCBUF ; i++){
		cbuf_free(mt[i]);
	}
	printc(" Done! >>>\n");

        /* CBUF_ALLOC  */
	printc("\n<<< CBUF_ALLOC MICRO-BENCHMARK TEST >>>\n");
	rdtscll(start);
	for (i = 0; i < NCBUF ; i++){
		prev_sz += 4;
		prev_sz &= PAGE_SIZE-1;
		sz[i] = prev_sz;
		mt[i] = cbuf_alloc(sz[i], &cbt[i]); 
	}
	rdtscll(end);
	printc("%d alloc_cbuf %llu cycs\n", NCBUF, (end-start)/NCBUF);
	printc("<<< CBUF_ALLOC MICRO-BENCHMARK TEST DONE >>>\n");

        /* CBUF2BUF  */
	printc("\n<<< CBUF2BUF MICRO-BENCHMARK TEST >>>\n");
	for (i = 0; i < NCBUF ; i++){
		call_buf2buf(cbt[i], sz[i]);
	}
	printc("<<< CBUF2BUF MICRO-BENCHMARK TEST DONE >>>\n");

        /* CBUF_FREE  */
	printc("\n<<< CBUF_FREE MICRO-BENCHMARK TEST >>>\n");
	rdtscll(start);
	for (i = 0; i < NCBUF ; i++){
		cbuf_free(mt[i]);                
	}
	rdtscll(end);
	printc("%d free_cbuf %llu cycs avg\n", NCBUF, (end-start)/NCBUF);
	printc("<<< CBUF_FREE MICRO-BENCHMARK TEST DONE >>>\n");

        /* CBUF_ALLOC-CBUF2BUF-CBUF_FREE */
	printc("\n<<< CBUF_ALLOC-CBUF2BUF-CBUF_FREE MICRO-BENCHMARK TEST >>>\n");
	prev_sz += 4;
	prev_sz &= PAGE_SIZE-1;
	sz[0] = prev_sz;
	rdtscll(start);
	for (i = 0; i < ITER ; i++){
		mt[0] = cbuf_alloc(sz[0], &cbt[0]);
		simple_call_buf2buf(cbt[0], sz[0]);
		cbuf_free(mt[0]);
	}
	rdtscll(end);
	printc("%d alloc-cbuf2buf-free %llu cycles avg\n", ITER, (end-start)/ITER);

	printc("<<< CBUF_ALLOC-CBUF2BUF-CBUF_FREE MICRO-BENCHMARK TEST DONE >>>\n");

	printc("\nMICRO BENCHMARK TEST (PINGPONG WITH CBUF) DONE!\n\n");
	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;
}