void cos_init(void) { static int flag = 0; union sched_param sp; int i; if(flag == 0){ printc("<<< CONTEXT SWITCH MICRO BENCHMARK TEST >>>\n"); flag = 1; sp.c.type = SCHEDP_PRIO; sp.c.value = 10; sched_create_thd(cos_spd_id(), sp.v, 0, 0); sp.c.type = SCHEDP_PRIO; sp.c.value = 11; sched_create_thd(cos_spd_id(), sp.v, 0, 0); } else { for(i=0; i<ITER; i++){ call_cs(); } } printc("<<< CONTEXT SWITCH MICRO BENCHMARK TEST DONE >>>\n"); return; }
void cos_init(void *arg) { static volatile int first = 1, second = 1; if (first) { first = 0; union sched_param sp; sp.c.type = SCHEDP_PRIO; sp.c.value = 10; if (sched_create_thd(cos_spd_id(), sp.v, 0, 0) == 0) BUG(); return; } else if (second) { // high prio thd union sched_param sp; second = 0; init(); sp.c.type = SCHEDP_PRIO; sp.c.value = 20; if (sched_create_thd(cos_spd_id(), sp.v, 0, 0) == 0) BUG(); event_wait(); } else { // low prio thd. keep writing tsc while (1) rdtscll(t_0); } }
void cos_init(void *arg) { static volatile int first = 0; union sched_param sp; int tcp_thd = 0; if (cos_get_thd_id() == event_thd) cos_net_evt_loop(); #ifdef DEBUG_PERIOD if (cos_get_thd_id() == debug_thd) { if (periodic_wake_create(cos_spd_id(), 100)) BUG(); while(1) { periodic_wake_wait(cos_spd_id()); printc("tcp evt trigger: tcp_accept_cnt %ld tcp_recv_cnt %ld net_accetp_cnt %ld\n", tcp_accept_cnt, tcp_recv_cnt, net_accetp_cnt); printc("tcp_tread_cnt %ld tcp_twrite_cnt %ld\n", tcp_tread_cnt, tcp_twrite_cnt); tcp_accept_cnt = 0; tcp_recv_cnt = 0; net_accetp_cnt = 0; tcp_tread_cnt = 0; tcp_twrite_cnt = 0; } } #endif if (first == 0) { first = 1; sp.c.type = SCHEDP_PRIO; sp.c.value = 28; tcp_thd = sched_create_thd(cos_spd_id(), sp.v, 0, 0); printc("tcp creates a thread %d\n", tcp_thd); #ifdef DEBUG_PERIOD sp.c.type = SCHEDP_PRIO; sp.c.value = 10; debug_thd = sched_create_thd(cos_spd_id(), sp.v, 0, 0); #endif return; } else { printc("tcp: thread %d\n", cos_get_thd_id()); init(); BUG(); prints("net: not expecting more than one bootstrap."); } }
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 = 10; sched_create_thd(cos_spd_id(), sp.v, 0, 0); } else { for (i=0; i<PAGE_NUM; i++) s_addr[i] = 0; for (i=0; i<PAGE_NUM; i++) d_addr[i] = 0; /* 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(); */ /* alias_test(); */ /* revoke_test(); */ /* all_in_one(); */ printc("<<< MM RECOVERY TEST DONE!! >>> {%d}\n\n\n", i); /* periodic_wake_wait(cos_spd_id()); */ } } return; }
static void cos_net_create_netif_thd(void) { union sched_param sp; sp.c.type = SCHEDP_PRIO; sp.c.value = 2; if (0 > (event_thd = sched_create_thd(cos_spd_id(), sp.v, 0, 0))) BUG(); }
void create_thd(int core, int prio) { union sched_param sp, sp1; sp.c.type = SCHEDP_PRIO; sp.c.value = prio; sp1.c.type = SCHEDP_CORE_ID; sp1.c.value = core; if (sched_create_thd(cos_spd_id(), sp.v, sp1.v, 0) == 0) BUG(); }
void cos_init(void *arg) { int c, accept_fd, ret; long eid; char *init_str = cos_init_args(); char __create_str[128]; static volatile int first = 1, off = 0; int port; u64_t start, end; if (cos_get_thd_id() == pid_thd) { pid_process(); } union sched_param sp; if (first) { first = 0; sp.c.type = SCHEDP_PRIO; sp.c.value = 10; pid_thd = sched_create_thd(cos_spd_id(), sp.v, 0, 0); init(init_str); return; } printc("Thread %d, port %d\n", cos_get_thd_id(), __port+off); port = off++; port += __port; eid = evt_get(); if (snprintf(__create_str, 128, create_str, port) < 0) BUG(); ret = c = from_tsplit(cos_spd_id(), td_root, __create_str, strlen(__create_str), TOR_ALL, eid); if (ret <= td_root) BUG(); accept_fd = c; printc("accept_fd %d (eid %d)\n", accept_fd, eid); evt_add(c, eid); /* event loop... */ while (1) { int t; long evt; evt = evt_wait_all(); t = evt_torrent(evt); printc("an interrupt comes in (thd %d, evt %d t %d)\n", cos_get_thd_id(), evt, t); accept_new(accept_fd); break; } }
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; }
void cos_init(void *arg) { printc(" **BEGIN RECV TRANS**\n"); if(first) { first = 0; union sched_param sp; int prio = 11; while(prios++ < 2) { sp.c.type = SCHEDP_PRIO; sp.c.value = prio; if(sched_create_thd(cos_spd_id(), sp.v, 0, 0) == 0) BUG(); printc("*trans.c: thread started!\n"); } return; } if(first_hi && first_lo) { first_hi = 0; trans_recv_hi(); } if(!first_hi && first_lo) { first_lo = 0; trans_recv_lo(); } /* // union sched_param sp; if(first_hi) { first_hi = 0; sp.c.type = SCHEDP_PRIO; sp.c.value = 8; if(sched_create_thd(cos_spd_id(), sp.v, 0, 0) == 0) BUG(); return; } //trans_recv_lo(); if(!first_hi && first_lo) { first_lo = 0; sp.c.value = 7; if(sched_create_thd(cos_spd_id(), sp.v, 0, 0) == 0) BUG(); trans_recv_hi(); } if(!first_hi && !first_lo) trans_recv_lo(); */ printc(" **RECV TRANS DONE**\n"); return; }
void cos_init(void) { static volatile int first = 1, second = 1, spin = 0, count = 0, i = 0; int tid = 0; int ret = 0; printc("Prio: %d\n", sched_priority(cos_get_thd_id())); printc("TID: %d\n", cos_get_thd_id()); if (first) { first = 0; union sched_param sp; sp.c.type = SCHEDP_PRIO; sp.c.value = 15; if (sched_create_thd(cos_spd_id(), sp.v, 0, 0) == 0) BUG(); printc("!!!!!!!!!!!!Thread #%d\n", (int) cos_get_thd_id()); return; } else if (second) { second = 0; printc("Calling cntl_thd\n"); if (parent_sched_child_cntl_thd(cos_spd_id())) BUG(); if (cos_sched_cntl(COS_SCHED_EVT_REGION, 0, (long)PERCPU_GET(cos_sched_notifications))) BUG(); printc("Called cntl_thd\n"); if ((tid = parent_sched_child_thd_crt(cos_spd_id(), cos_spd_id())) == -1) BUG(); printc("THID = %d\n", tid); if (parent_sched_child_timer_int(cos_spd_id(), 0, 1) != 0) BUG(); if ((ret = cos_switch_thread(tid, 0))) printc("Switch: %d\n", ret); if (parent_sched_child_timer_int(cos_spd_id(), 0, 1) != 0) BUG(); if ((ret = cos_switch_thread(tid, 0))) printc("Switch: %d\n", ret); while (1) { i++; if (i % 100000000 == 0) { printc("Stutter\n"); } } return; } else { while (1) { spin++; if (spin % 100000000 == 0) { printc("f\n"); } } return; } printc("I finished\n"); }
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 = 11; high = sched_create_thd(cos_spd_id(), sp.v, 0, 0); } else { test0(); } 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) { static volatile int first = 1; union sched_param sp; pnums = avg = 0; inc1 = inc2 = 0; #ifdef DEBUG_PERIOD unsigned long cos_immediate_process_cnt_prev = 0; if (cos_get_thd_id() == debug_thd) { if (periodic_wake_create(cos_spd_id(), 100)) BUG(); while(1) { periodic_wake_wait(cos_spd_id()); printc("num interrupt_wait %ld interrupt_process %ld\n", interrupt_wait_cnt, interrupt_process_cnt); interrupt_wait_cnt = 0; interrupt_process_cnt = 0; if (cos_immediate_process_cnt > 0) { printc("num immediate interrupt_process %ld\n", cos_immediate_process_cnt - cos_immediate_process_cnt_prev); cos_immediate_process_cnt_prev = cos_immediate_process_cnt; } } } #endif if (first) { first = 0; #ifdef DEBUG_PERIOD sp.c.type = SCHEDP_PRIO; sp.c.value = 10; debug_thd = sched_create_thd(cos_spd_id(), sp.v, 0, 0); #endif init(); } else { prints("net: not expecting more than one bootstrap."); } }
/** * cos_init */ void cos_init(void *arg) { static int first = 1; if (first) { union sched_param sp; first = 0; LOCK_INIT(); sp.c.type = SCHEDP_PRIO; sp.c.value = 10; if (sched_create_thd(cos_spd_id(), sp.v, 0, 0) == 0) BUG(); return; } read_ltoc(); // memset(all_tmem_mgr, 0, sizeof(struct tmem_mgr *) * MAX_NUM_SPDS); return; }
static void init(char *init_str) { int nthds; cvect_init_static(&evts); cvect_init_static(&tor_from); cvect_init_static(&tor_to); lock_static_init(&sc_lock); sscanf(init_str, "%d:%d:%d", &nthds, &__prio, &__port); /* printc("nthds:%d, prio:%d, port %d\n", nthds, __prio, __port); */ create_str = strstr(init_str, "/"); assert(create_str); for (; nthds > 0 ; nthds--) { union sched_param sp; int thdid; sp.c.type = SCHEDP_PRIO; sp.c.value = __prio++; thdid = sched_create_thd(cos_spd_id(), sp.v, 0, 0); } }
void cos_init(void) { static int first = 0, flag = 0; union sched_param sp; if(first == 0){ first = 1; sp.c.type = SCHEDP_PRIO; sp.c.value = 8; high = sched_create_thd(cos_spd_id(), sp.v, 0, 0); } else { if (cos_get_thd_id() == high) { periodic_wake_create(cos_spd_id(), NOISE_PERIOD); while(1){ periodic_wake_wait(cos_spd_id()); /* printc("PERIODIC: noise....(thd %d in spd %ld)\n", */ /* cos_get_thd_id(), cos_spd_id()); */ sinusoid_spike(); } } } return; }
void cos_init(void *arg) { td_t t1, serv; long evt; char *params1 = "foo", *params2 = "", *d; int period, num, ret, sz, i, j; u64_t start = 0, end = 0, re_cbuf; cbuf_t cb1; union sched_param sp; static int first = 1; if (first) { first = 0; sp.c.type = SCHEDP_PRIO; sp.c.value = 9; if (sched_create_thd(cos_spd_id(), sp.v, 0, 0) == 0) BUG(); return ; } evt = evt_split(cos_spd_id(), 0, 0); assert(evt > 0); serv = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_RW, evt); if (serv < 1) { printc("UNIT TEST FAILED: split1 failed %d\n", serv); } evt_wait(cos_spd_id(), evt); printc("client split successfully\n"); sz = 4096; j = 1000*ITER; rdtscll(start); for (i=1; i<=j; i++) { if (i == j) rdtscll(end); d = cbuf_alloc(sz, &cb1); if (!d) goto done; cbuf_send(cb1); rdtscll(end); ((u64_t *)d)[0] = end; ret = twritep(cos_spd_id(), serv, cb1, sz); cbuf_free(cb1); } printc("Client snd %d times %llu\n", j-1, (end-start)/(j-1)); /* * insert evt_grp_wait(...) into the code below where it makes * sense to. Simulate if the code were executing in separate * threads. */ parse_args(&period, &num); periodic_wake_create(cos_spd_id(), period); re_cbuf = 0; for (i=1; i<=ITER; i++) { for (j=0; j<num; j++) { rdtscll(start); d = cbuf_alloc(i*sz, &cb1); if (!d) goto done; cbuf_send_free(cb1); rdtscll(end); re_cbuf = re_cbuf+(end-start); rdtscll(end); ((u64_t *)d)[0] = end; ret = twritep(cos_spd_id(), serv, cb1, i*sz); } periodic_wake_wait(cos_spd_id()); } printc("Client: Period %d Num %d Cbuf %llu\n", period, num, re_cbuf/(num*ITER)); done: trelease(cos_spd_id(), serv); printc("client UNIT TEST PASSED: split->release\n"); printc("client UNIT TEST ALL PASSED\n"); return; }
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; }
void cos_init(void *arg) { static int first = 1; if (first) { union sched_param sp; first = 0; INIT_LIST(&threads, next, prev); init_spds(); sp.c.type = SCHEDP_PRIO; sp.c.value = 5; if (sched_create_thd(cos_spd_id(), sp.v, 0, 0) == 0) BUG(); return; } DOUT("thd %d Tmem policy running.....\n", cos_get_thd_id()); #ifdef THD_POOL printc("<<<Thd Pool with total %d tmems, component size %d>>>\n", MAX_NUM_MEM, THD_POOL); if (THD_POOL != 1) thdpool_max_policy(); else thdpool_1_policy(); #else printc("<<<Now using Algorithm %d, total number of tmems:%d >>>\n", ALGORITHM, MAX_NUM_MEM); DOUT("Tmem policy: %d in spd %ld\n", cos_get_thd_id(), cos_spd_id()); init_policy(); #endif periodic_wake_create(cos_spd_id(), POLICY_PERIODICITY); /* Wait for all other threads to initialize */ int i = 0, waiting = 100 / POLICY_PERIODICITY, counter = 0, report_period = 100 / POLICY_PERIODICITY; do { periodic_wake_wait(cos_spd_id()); } while (i++ < waiting); init_thds(); //unsigned long long s,e; while (1) { counter++; if (counter % report_period == 0) { /* report tmems usage */ cbufmgr_buf_report(); stkmgr_stack_report(); } gather_data(counter % report_period); #ifdef THD_POOL if (counter % report_period == 0) { if (THD_POOL == 1) thdpool_1_policy(); else thdpool_max_policy(counter % report_period); } #else //rdtscll(s); DOUT("POLICY starts!\n"); policy(); DOUT("POLICY ends!\n"); //rdtscll(e); //printc("SP:%llu cycles\n",e-s); #endif periodic_wake_wait(cos_spd_id()); } return; }
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) { u64_t start, end, avg, tot = 0, dev = 0, sum = 0, sum2 = 0; int i, j, k, outlier; static int first = 1; if (first) { union sched_param sp; first = 0; init_cache(); sp.c.type = SCHEDP_PRIO; sp.c.value = 20; if (sched_create_thd(cos_spd_id(), sp.v, 0, 0) == 0) BUG(); return; } //#define MPD_ENABLE #ifdef MPD_ENABLE int c0[] = {10, 11, 0}, c1[] = {0}, c2[] = {0}, c3[] = {0}, c_last[] = {0}; int *ms[] = {c0, c1, c2, c3, c_last}; for (j = 0 ; ms[j][0] ; j++) { for (i = 1 ; ms[j][i] != 0 ; i++) { if (cos_mpd_cntl(COS_MPD_MERGE, ms[j][0], ms[j][i])) { printc("merge of %d and %d failed. %d\n", ms[j][0], ms[j][i], 0); } } } printc("mpd done.\n"); #endif call_server(0,99,99,99); /* get stack */ // printc("addr %d, %d\n", &cache[1], &cache[0]); printc("optimal\n"); for (i = 16; i <= ITER; i*= 2) { sum = sum2 = 0; outlier = 0; for (k = 0; k < ITER2; k++) { rdtscll(start); struct cache_line *node = cache; for (j = 0; j < i; j++) { node->data++; node = node->next; } rdtscll(end); cost[k] = (end - start); sum+= (end - start); //call_server(i, 0, 0, 0); } for (k = 0; k < ITER2; k++) { // clean cache.... struct cache_line *node = cache; for (j = 0; j < ITER; j++) { node->data++; node = node->next; } } avg = sum / ITER2; for (k = 0; k < ITER2; k++) { if (cost[k] <= 2*avg) { sum2 += cost[k]; } else outlier++; } printc("Core %d, calling side, cache working set size %d, avg execution time %llu w/o %d outliers\n", cos_cpuid(), i * 64, sum2 / (ITER2-outlier), outlier); } printc("\nsamecore\n"); for (i = 16; i <= ITER; i*= 2) { sum = sum2 = 0; outlier = 0; for (k = 0; k < ITER2; k++) { rdtscll(start); struct cache_line *node = cache; for (j = 0; j < i; j++) { node->data++; node = node->next; } rdtscll(end); cost[k] = (end - start); sum+= (end - start); call_server(i, 0, 0, 0); } for (k = 0; k < ITER2; k++) { // clean cache.... struct cache_line *node = cache; for (j = 0; j < ITER; j++) { node->data++; node = node->next; } } avg = sum / ITER2; for (k = 0; k < ITER2; k++) { if (cost[k] <= 2*avg) { sum2 += cost[k]; } else outlier++; } printc("Core %d, calling side, cache working set size %d, avg execution time %llu w/o %d outliers\n", cos_cpuid(), i * 64, sum2 / (ITER2-outlier), outlier); } printc("\nxcore\n"); for (i = 16; i <= ITER; i*= 2) { sum = sum2 = 0; outlier = 0; for (k = 0; k < ITER2; k++) { rdtscll(start); struct cache_line *node = cache; for (j = 0; j < i; j++) { node->data++; node = node->next; } rdtscll(end); cost[k] = (end - start); sum+= (end - start); call_server_x(i, 0, 0, 0); } for (k = 0; k < ITER2; k++) { // clean cache.... struct cache_line *node = cache; for (j = 0; j < ITER; j++) { node->data++; node = node->next; } } avg = sum / ITER2; for (k = 0; k < ITER2; k++) { if (cost[k] <= 2*avg) { sum2 += cost[k]; } else outlier++; } printc("Core %d, calling side, cache working set size %d, avg execution time %llu w/o %d outliers\n", cos_cpuid(), i * 64, sum2 / (ITER2-outlier), outlier); } printc("done.\n"); /* printc("Core %ld: starting Invocations.\n", cos_cpuid()); */ /* for (i = 0 ; i < ITER ; i++) { */ /* rdtscll(start); */ /* call_server(99,99,99,99); */ /* rdtscll(end); */ /* meas[i] = end-start; */ /* } */ /* for (i = 0 ; i < ITER ; i++) tot += meas[i]; */ /* avg = tot/ITER; */ /* printc("avg %lld\n", avg); */ /* for (tot = 0, i = 0, j = 0 ; i < ITER ; i++) { */ /* if (meas[i] < avg*2) { */ /* tot += meas[i]; */ /* j++; */ /* } */ /* } */ /* printc("avg w/o %d outliers %lld\n", ITER-j, tot/j); */ /* for (i = 0 ; i < ITER ; i++) { */ /* u64_t diff = (meas[i] > avg) ? */ /* meas[i] - avg : */ /* avg - meas[i]; */ /* dev += (diff*diff); */ /* } */ /* dev /= ITER; */ /* printc("deviation^2 = %lld\n", dev); */ // printc("%d invocations took %lld\n", ITER, end-start); 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; }