/* * tor > 0 == event is "from" * tor < 0 == event is "to" */ static inline long evt_get(void) { long eid; if (!evt_all) evt_all = evt_split(cos_spd_id(), 0, 1); assert(evt_all); eid = (ncached == 0) ? evt_split(cos_spd_id(), evt_all, 0) : evt_cache[--ncached]; assert(eid > 0); return eid; }
void cos_init(void) { LOGD("BEGIN"); td_t t1, t2; long evt1; int ret; char *params1 = "unused"; char *sql = NULL; evt1 = evt_split(cos_spd_id(), 0, 0); assert(evt1 > 0); t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1); if (t1 < 0) { LOGD("Can't open database"); return; } trelease(cos_spd_id(), t1); LOGD("Opened database successfully!"); sql = "CREATE TABLE COMPANY(" \ "ID INT PRIMARY KEY NOT NULL," \ "NAME TEXT NOT NULL," \ "AGE INT NOT NULL," \ "ADDRESS CHAR(50)," \ "SALARY REAL );"; t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1); ret = twrite_pack(cos_spd_id(), t1, sql, 1024); LOGD("%s: Table created ", ret < 0 ? "unsuccessfully" : "successfully"); }
void cos_init(void) { ccv_disable_cache(); cbufp_t cbid; char *buf; int mat_size; long evt_tsplit; td_t td; ccv_dense_matrix_t *ccv_mat_input = NULL; ccv_dense_matrix_t *ccv_mat_output = NULL; ccv_read("photo.bmp", &ccv_mat_input, CCV_IO_ANY_FILE | CCV_IO_GRAY); assert(ccv_mat_input); evt_tsplit = evt_split(cos_spd_id(), 0, 0); td = ccv_fd_tsplit(cos_spd_id(), td_root, "face", strlen("face"), TOR_ALL, evt_tsplit); cbuf_matrix_t *cbuf_mat = ccv2cbufmat(ccv_mat_input); cbufp_send_deref(cbuf_mat->cbid); ccv_fd_twritep(cos_spd_id(), td, cbuf_mat->cbid, cbuf_mat->size); /* test of treapd, should same with the input*/ int off, len; cbid = ccv_fd_treadp(cos_spd_id(), td, &off, &len); buf = cbufp2buf(cbid, len); cbuf_mat = (cbuf_matrix_t *)buf; ccv_mat_output = cbuf2ccvmat(cbuf_mat); return; }
void cos_init(void) { LOGD("BEGIN"); td_t t1, t2; long evt1; int ret; char *params1 = "unused"; char *sql = NULL; evt1 = evt_split(cos_spd_id(), 0, 0); assert(evt1 > 0); t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1); if (t1 < 0) { LOGD("FAILED: split"); return; } trelease(cos_spd_id(), t1); LOGD("PASSED: split->release"); sql = "CREATE TABLE student(" \ "id INTEGER PRIMARY KEY AUTOINCREMENT," \ "name TEXT NOT NULL," \ "age INTEGER );" ; t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1); ret = twrite_pack(cos_spd_id(), t1, sql, 1024); LOGD("%s: Create table.", ret < 0 ? "FAILED" : "PASSED"); //trelease(cos_spd_id(), t1); }
/* * tor > 0 == event is "from" * tor < 0 == event is "to" */ static inline long evt_get_thdid(int thdid) { long eid; if (!evt_all[thdid]) evt_all[thdid] = evt_split(cos_spd_id(), 0, 1); assert(evt_all[thdid]); /* /\* if we do not cache, it is faster? (8000 reqs/sec) *\/ */ /* eid = evt_split(cos_spd_id(), evt_all[thdid], 0); */ eid = (ncached == 0) ? evt_split(cos_spd_id(), evt_all[thdid], 0) : evt_cache[--ncached]; assert(eid > 0); return eid; }
/*Send Query Response*/ int write_response() { td_t write_tor; long evt; unsigned int ret; printc("SQLITE: Begin querying db\n"); evt = evt_split(cos_spd_id(), 0, 0); write_tor = tsplit(cos_spd_id(), td_root, response, strlen(response), TOR_ALL, evt); if (write_tor < 1) { printc("SQLITE: split failed %d\n", write_tor); return 1; } ret = twrite_pack(cos_spd_id(), write_tor, response_buffer, strlen(response_buffer)); printc("SQLITE: WROTE %d (%s), ret %d\n", strlen(response_buffer), response_buffer, ret); trelease(cos_spd_id(), write_tor); return 0; }
void cos_init(void) { LOGD("BEGIN"); td_t t1, t2; long evt1; int ret; char *params1 = "unused"; char *sql = NULL; evt1 = evt_split(cos_spd_id(), 0, 0); assert(evt1 > 0); t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1); if (t1 < 0) { LOGD("Can't open database"); return; } trelease(cos_spd_id(), t1); LOGD("Opened database successfully!"); sql = "CREATE TABLE COMPANY(" \ "ID INT PRIMARY KEY NOT NULL," \ "NAME TEXT NOT NULL," \ "AGE INT NOT NULL," \ "ADDRESS CHAR(50)," \ "SALARY REAL ;" \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (1, 'Paul', 32, 'California', 20000.00 ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (2, 'Allen', 25, 'Texas', 15000.00 ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (3, 'Teddy', 23, 'Norway', 20000.00 );" \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );" \ "UPDATE COMPANY set SALARY = 25000.00 where ID=1; "; t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1); ret = twrite_pack(cos_spd_id(), t1, sql, 1024); LOGD("%s: Operation done ", ret < 0 ? "unsuccessfully" : "successfully"); }
void trans_recv_hi(void) { unsigned int amnt_hi = 1; long evt_hi; td_t td_hi; char *params_hi = "7"; printc("***HIGH PRIO RECV STARTING***\n"); evt_hi = evt_split(cos_spd_id(), 0, 0); assert(evt_hi > 0); td_hi = tsplit(cos_spd_id(), td_root, params_hi, strlen(params_hi), TOR_READ, evt_hi); printc("EVT_HI (%ld) TD_HI (%d)\n", evt_hi, td_hi); do { evt_wait(cos_spd_id(), evt_hi); // if((amnt_hi++ % 1000) == 0) printc("hi prio count (%u) spd(%d) tid(%d)\n", amnt_hi++, cos_spd_id(), cos_get_thd_id()); } while (1);//cur_itr++ < ITR); return; }
/*Read Query Response*/ int read_query() { td_t read_tor; long evt; unsigned int ret; printc("SQLITE: Begin Reading Query\n"); evt = evt_split(cos_spd_id(), 0, 0); read_tor = tsplit(cos_spd_id(), td_root, query, strlen(query), TOR_ALL, evt); if (read_tor < 1) { printc("SQLITE: split failed %d\n", read_tor); return 1; } ret = tread_pack(cos_spd_id(), read_tor, buffer, 1023); if (ret > 0) buffer[ret] = '\0'; printc("SQLITE: READ %d : %s\n", ret, buffer); strcpy(sql, buffer); buffer[0] = '\0'; trelease(cos_spd_id(), read_tor); return 0; }
//static volatile int cur_itr = 0; void trans_recv_lo(void) { unsigned int amnt_lo = 1; long evt_lo; td_t td_lo; char *params_lo = "8"; printc("***LOW PRIO RECV STARTING***\n"); evt_lo = evt_split(cos_spd_id(), 0, 0); assert(evt_lo > 0); td_lo = tsplit(cos_spd_id(), td_root, params_lo, strlen(params_lo), TOR_READ, evt_lo); printc("EVT_LO (%ld) TD_LO (%d)\n", evt_lo, td_lo); do { evt_wait(cos_spd_id(), evt_lo); // if((amnt_lo++ % 1000) == 0) printc("lo prio count (%u) spd(%d) tid(%d)\n", amnt_lo++, cos_spd_id(), cos_get_thd_id()); } while (1);//cur_itr++ < ITR); 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 run_sqlite() { sqlite3 *db; char *zErrMsg = 0; int rc; td_t t1, t2; long evt1, evt2; unsigned int ret1, ret2; int a = 0, b = 0, c = 0; c = treadp(cos_spd_id(), 0, &a, &b); printc("%d %d %d\n", a, b, c); evt1 = evt_split(cos_spd_id(), 0, 0); evt2 = evt_split(cos_spd_id(), 0, 0); assert(evt1 > 0 && evt2 > 0); /* Open database */ rc = sqlite3_open(":memory:", &db); if (rc) { printc("SQLITE: Can't open database: %s\n", sqlite3_errmsg(db)); return; } else { printc("SQLITE: Opened database successfully\n"); } /* Create Table */ sql = "CREATE TABLE PEOPLE(" \ "ID INT PRIMARY KEY NOT NULL," \ "NAME TEXT NOT NULL," \ "AGE INT NOT NULL," \ "ADDRESS CHAR(50));"; rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); if( rc != SQLITE_OK ){ printc("SQLITE: SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); }else{ printc("SQLITE: Table created successfully\n"); } /*Insert Table Data*/ printc("SQLITE: Insert 3 rows into the table (Joel, Kevin, Mike)\n"); sql = "INSERT INTO PEOPLE (ID,NAME,AGE,ADDRESS) " \ "VALUES (1, 'Joel', 21, 'Washington DC');" \ "INSERT INTO PEOPLE (ID,NAME,AGE,ADDRESS) " \ "VALUES (2, 'Kevin', 30, 'Rio');" \ "INSERT INTO PEOPLE (ID,NAME,AGE,ADDRESS)" \ "VALUES (3, 'Mike', 23, 'New York');"; rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); if( rc != SQLITE_OK ){ printc("SQLITE: SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); }else{ printc("SQLITE: Data inserted successfully\n"); } /*Read Query*/ rc = read_query(); if (rc > 0) { printc("SQLITE: Failed Reading Query Torrent\n"); return; } printc("%s\n", sql); rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); if( rc != SQLITE_OK ){ printc("SQLITE: SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); }else{ printc("SQLITE: Data Queried\n"); } write_response(); if (rc > 0) { printc("SQLITE: Error Writing to Response Torrent\n"); return; } sqlite3_close(db); return; }
void cos_init(void) { td_t t1, t2; long evt1, evt2; char *params1 = "bar"; char *params2 = "foo/"; char *params3 = "foo/bar"; char *data1 = "1234567890", *data2 = "asdf;lkj", *data3 = "asdf;lkj1234567890"; unsigned int ret1, ret2; int a = 0, b = 0, c = 0; c = treadp(cos_spd_id(), 0, &a, &b); printc("UNIT TEST Unit tests for torrents...\n"); printc("%d %d %d\n", a, b, c); evt1 = evt_split(cos_spd_id(), 0, 0); evt2 = evt_split(cos_spd_id(), 0, 0); assert(evt1 > 0 && evt2 > 0); t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1); if (t1 < 1) { printc("UNIT TEST FAILED: split failed %d\n", t1); return; } trelease(cos_spd_id(), t1); printc("UNIT TEST PASSED: split->release\n"); t1 = tsplit(cos_spd_id(), td_root, params2, strlen(params2), TOR_ALL, evt1); if (t1 < 1) { printc("UNIT TEST FAILED: split2 failed %d\n", t1); return; } t2 = tsplit(cos_spd_id(), t1, params1, strlen(params1), TOR_ALL, evt2); if (t2 < 1) { printc("UNIT TEST FAILED: split3 failed %d\n", t2); return; } ret1 = twrite_pack(cos_spd_id(), t1, data1, strlen(data1)); ret2 = twrite_pack(cos_spd_id(), t2, data2, strlen(data2)); printv("write %d & %d, ret %d & %d\n", strlen(data1), strlen(data2), ret1, ret2); trelease(cos_spd_id(), t1); trelease(cos_spd_id(), t2); printc("UNIT TEST PASSED: 2 split -> 2 write -> 2 release\n"); t1 = tsplit(cos_spd_id(), td_root, params2, strlen(params2), TOR_ALL, evt1); t2 = tsplit(cos_spd_id(), t1, params1, strlen(params1), TOR_ALL, evt2); if (t1 < 1 || t2 < 1) { printc("UNIT TEST FAILED: later splits failed\n"); return; } ret1 = tread_pack(cos_spd_id(), t1, buffer, 1023); if (ret1 > 0) buffer[ret1] = '\0'; printv("read %d (%d): %s (%s)\n", ret1, strlen(data1), buffer, data1); assert(!strcmp(buffer, data1)); assert(ret1 == strlen(data1)); buffer[0] = '\0'; ret1 = tread_pack(cos_spd_id(), t2, buffer, 1023); if (ret1 > 0) buffer[ret1] = '\0'; assert(!strcmp(buffer, data2)); assert(ret1 == strlen(data2)); printv("read %d: %s\n", ret1, buffer); buffer[0] = '\0'; trelease(cos_spd_id(), t1); trelease(cos_spd_id(), t2); printc("UNIT TEST PASSED: 2 split -> 2 read -> 2 release\n"); t1 = tsplit(cos_spd_id(), td_root, params3, strlen(params3), TOR_ALL, evt1); ret1 = tread_pack(cos_spd_id(), t1, buffer, 1023); if (ret1 > 0) buffer[ret1] = '\0'; printv("read %d: %s\n", ret1, buffer); assert(!strcmp(buffer, data2)); assert(ret1 == strlen(data2)); printc("UNIT TEST PASSED: split with absolute addressing -> read\n"); buffer[0] = '\0'; ret1 = twrite_pack(cos_spd_id(), t1, data1, strlen(data1)); printv("write %d, ret %d\n", strlen(data1), ret1); trelease(cos_spd_id(), t1); t1 = tsplit(cos_spd_id(), td_root, params3, strlen(params3), TOR_ALL, evt1); ret1 = tread_pack(cos_spd_id(), t1, buffer, 1023); if (ret1 > 0 && ret1 < 1024) buffer[ret1] = '\0'; printv("read %d: %s (%s)\n", ret1, buffer, data3); assert(ret1 == strlen(data2)+strlen(data1)); assert(!strcmp(buffer, data3)); buffer[0] = '\0'; printc("UNIT TEST PASSED: writing to an existing file\n"); printc("UNIT TEST ALL PASSED\n"); return; }
static void test0(void) { /* struct cbuf_alloc_desc *d; */ /* int i; */ /* d = &cbufp_alloc_freelists[0]; */ /* assert(EMPTY_LIST(d, next, prev)); */ /* for (i = 0 ; i < CBUFP_NUM ; i++) { */ /* buf[i] = cbufp_alloc(4096, &p[i]); */ /* cbufp_send(p[i]); */ /* assert(buf[i]); */ /* } */ /* for (i = 0 ; i < CBUFP_NUM ; i++) { */ /* cbufp_deref(p[i]); */ /* } */ td_t t1, t2, t3; long evt1, evt2, evt3; char *params1 = "bar"; char *params2 = "foo/"; char *params3 = "foo/bar"; char *data1 = "1234567890", *data2 = "asdf;lkj", *data3 = "asdf;lkj1234567890"; unsigned int ret1, ret2; evt1 = evt_split(cos_spd_id(), 0, 0); evt2 = evt_split(cos_spd_id(), 0, 0); /* evt3 = evt_create(cos_spd_id()); */ assert(evt1 > 0 && evt2 > 0); printc("\nRAMFS Testing Starting.....(thd %d)\n\n", cos_get_thd_id()); t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1); if (t1 < 1) { printc("UNIT TEST FAILED: split failed %d\n", t1); return; } trelease(cos_spd_id(), t1); t1 = tsplit(cos_spd_id(), td_root, params2, strlen(params2), TOR_ALL, evt1); if (t1 < 1) { printc("UNIT TEST FAILED: split2 failed %d\n", t1); return; } t2 = tsplit(cos_spd_id(), t1, params1, strlen(params1), TOR_ALL, evt2); if (t2 < 1) { printc("UNIT TEST FAILED: split3 failed %d\n", t2); return; } #ifdef TEST_RAMFS_C3 ret1 = twritep_pack(cos_spd_id(), t1, data1, strlen(data1)); ret2 = twritep_pack(cos_spd_id(), t2, data2, strlen(data2)); #else ret1 = twrite_pack(cos_spd_id(), t1, data1, strlen(data1)); ret2 = twrite_pack(cos_spd_id(), t2, data2, strlen(data2)); #endif printc("write %d & %d, ret %d & %d\n", strlen(data1), strlen(data2), ret1, ret2); /* This is important!!!! release in the opposite order */ trelease(cos_spd_id(), t2); trelease(cos_spd_id(), t1); int max_test; // need test for max number of allowed faults (ureboot) for (max_test = 0; max_test < 400; max_test++) { printc("\n>>>>>>ramfs test phase 3 start .... (iter %d)\n", max_test); t1 = tsplit(cos_spd_id(), td_root, params2, strlen(params2), TOR_ALL, evt1); /* printc("\n[[[[[[.... 2nd tsplit\n"); */ t2 = tsplit(cos_spd_id(), t1, params1, strlen(params1), TOR_ALL, evt2); if (t1 < 1 || t2 < 1) { printc("UNIT TEST FAILED: later splits failed\n"); return; } /* printc("\n[[[[[[.... 1st tread\n"); */ #ifdef TEST_RAMFS_C3 ret1 = treadp_pack(cos_spd_id(), t1, buffer, 1023); #else ret1 = tread_pack(cos_spd_id(), t1, buffer, 1023); #endif if (ret1 > 0) buffer[ret1] = '\0'; assert(!strcmp(buffer, data1)); // treadp does not return length, instead return cbid /* assert(ret1 == strlen(data1)); */ printc("read %d (%d): %s (%s)\n", ret1, strlen(data1), buffer, data1); buffer[0] = '\0'; #ifdef TEST_RAMFS_C3 ret1 = treadp_pack(cos_spd_id(), t2, buffer, 1023); #else ret1 = tread_pack(cos_spd_id(), t2, buffer, 1023); #endif if (ret1 > 0) buffer[ret1] = '\0'; assert(!strcmp(buffer, data2)); /* assert(ret1 == strlen(data2)); */ printc("read %d (%d): %s (%s)\n", ret1, strlen(data2), buffer, data2); buffer[0] = '\0'; trelease(cos_spd_id(), t2); trelease(cos_spd_id(), t1); } printc("\nRAMFS Testing Done.....\n\n"); return; }