static INT_PTR CALLBACK DlgProcMirOTROptsContacts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { HWND lv = GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS); switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); { SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR) new ContactPolicyMap()); HWND cmb = GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_DEFAULT)); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_ALWAYS)); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_OPP)); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_MANUAL)); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_NEVER)); EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY), FALSE); SendDlgItemMessage(hwndDlg, IDC_LV_CONT_CONTACTS, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);// | LVS_EX_CHECKBOXES); // add list columns LVCOLUMN lvc; // Initialize the LVCOLUMN structure. // The mask specifies that the format, width, text, and // subitem members of the structure are valid. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; lvc.fmt = LVCFMT_LEFT; lvc.iSubItem = 0; lvc.pszText = TranslateT(LANG_CONTACT); lvc.cx = 150; // width of column in pixels ListView_InsertColumn(lv, 0, &lvc); lvc.iSubItem = 1; lvc.pszText = TranslateT(LANG_PROTO); lvc.cx = 100; // width of column in pixels ListView_InsertColumn(lv, 1, &lvc); lvc.iSubItem = 2; lvc.pszText = TranslateT(LANG_POLICY); lvc.cx = 90; // width of column in pixels ListView_InsertColumn(lv, 2, &lvc); lvc.iSubItem = 3; lvc.pszText = TranslateT(LANG_HTMLCONV); lvc.cx = 80; // width of column in pixels ListView_InsertColumn(lv, 3, &lvc); } SendMessage(hwndDlg, WMU_REFRESHLIST, 0, 0); return TRUE; case WMU_REFRESHLIST: ListView_DeleteAllItems(lv); { LVITEM lvI = { 0 }; // Some code to create the list-view control. // Initialize LVITEM members that are common to all // items. lvI.mask = LVIF_TEXT | LVIF_PARAM;// | LVIF_NORECOMPUTE;// | LVIF_IMAGE; for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { const char *proto = GetContactProto(hContact); if (proto && db_get_b(hContact, proto, "ChatRoom", 0) == 0 && Proto_IsProtoOnContact(hContact, MODULENAME) // ignore chatrooms && mir_strcmp(proto, META_PROTO) != 0) // and MetaContacts { lvI.iItem = 0; lvI.iSubItem = 0; lvI.lParam = hContact; lvI.pszText = (TCHAR*)contact_get_nameT(hContact); lvI.iItem = ListView_InsertItem(lv, &lvI); PROTOACCOUNT *pa = Proto_GetAccount(proto); ListView_SetItemText(lv, lvI.iItem, 1, pa->tszAccountName); ListView_SetItemText(lv, lvI.iItem, 2, (TCHAR*)policy_to_string((OtrlPolicy)db_get_dw(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY))); ListView_SetItemText(lv, lvI.iItem, 3, (db_get_b(hContact, MODULENAME, "HTMLConv", 0)) ? TranslateT(LANG_YES) : TranslateT(LANG_NO)); } } } return TRUE; case WM_COMMAND: switch (HIWORD(wParam)) { case CBN_SELCHANGE: switch (LOWORD(wParam)) { case IDC_CMB_CONT_POLICY: int iUser = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS)); if (iUser == -1) break; int sel = SendDlgItemMessage(hwndDlg, IDC_CMB_CONT_POLICY, CB_GETCURSEL, 0, 0); if (sel == CB_ERR) break; int len = SendDlgItemMessage(hwndDlg, IDC_CMB_CONT_POLICY, CB_GETLBTEXTLEN, sel, 0); if (len < 0) break; TCHAR *text = new TCHAR[len + 1]; SendDlgItemMessage(hwndDlg, IDC_CMB_CONT_POLICY, CB_GETLBTEXT, sel, (LPARAM)text); ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS), iUser, 2, text); OtrlPolicy policy = policy_from_string(text); delete[] text; LVITEM lvi = { 0 }; lvi.mask = LVIF_PARAM; lvi.iItem = iUser; lvi.iSubItem = 0; ListView_GetItem(GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS), &lvi); ContactPolicyMap* cpm = (ContactPolicyMap*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); MCONTACT hContact = (MCONTACT)lvi.lParam; (*cpm)[hContact].policy = policy; SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; } break; } break; case WM_NOTIFY: if (((LPNMHDR)lParam)->code == PSN_APPLY) { // handle apply ContactPolicyMap *cpm = (ContactPolicyMap*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); // Iterate over the map and print out all key/value pairs. // Using a const_iterator since we are not going to change the values. for (ContactPolicyMap::const_iterator it = cpm->begin(); it != cpm->end(); ++it) { if (!it->first) continue; db_set_dw(it->first, MODULENAME, "Policy", (DWORD)it->second.policy); db_set_b(it->first, MODULENAME, "HTMLConv", it->second.htmlconv); } return TRUE; } if (((LPNMHDR)lParam)->hwndFrom == lv) { LPNMLISTVIEW notif = (LPNMLISTVIEW)lParam; if (((LPNMHDR)lParam)->code == LVN_ITEMCHANGED && (notif->uNewState & LVIS_SELECTED)) { if (notif->iItem == -1) { SendDlgItemMessage(hwndDlg, IDC_CMB_CONT_POLICY, CB_SETCURSEL, (LPARAM)-1, 0); EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY), FALSE); } else { EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_CONT_POLICY), TRUE); TCHAR buff[50]; ListView_GetItemText(((LPNMHDR)lParam)->hwndFrom, notif->iItem, 2, buff, _countof(buff)); SendDlgItemMessage(hwndDlg, IDC_CMB_CONT_POLICY, CB_SELECTSTRING, (LPARAM)-1, (WPARAM)buff); } } else if (((LPNMHDR)lParam)->code == NM_CLICK) { if (notif->iSubItem == 3) { LVITEM lvi; lvi.mask = LVIF_PARAM; lvi.iItem = notif->iItem; if (lvi.iItem < 0) return FALSE; lvi.iSubItem = 0; SendDlgItemMessage(hwndDlg, IDC_LV_CONT_CONTACTS, LVM_GETITEM, 0, (LPARAM)&lvi); MCONTACT hContact = (MCONTACT)lvi.lParam; ContactPolicyMap *cp = (ContactPolicyMap *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); TCHAR buff[50]; ListView_GetItemText(((LPNMHDR)lParam)->hwndFrom, lvi.iItem, 3, buff, _countof(buff)); if (_tcsncmp(buff, TranslateT(LANG_YES), 50) == 0) { (*cp)[hContact].htmlconv = HTMLCONV_DISABLE; ListView_SetItemText(((LPNMHDR)lParam)->hwndFrom, lvi.iItem, 3, TranslateT(LANG_NO)); } else { (*cp)[hContact].htmlconv = HTMLCONV_ENABLE; ListView_SetItemText(((LPNMHDR)lParam)->hwndFrom, lvi.iItem, 3, TranslateT(LANG_YES)); } SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } } } break; case WM_DESTROY: ContactPolicyMap *cpm = (ContactPolicyMap*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); cpm->clear(); delete cpm; break; } return FALSE; }
static INT_PTR CALLBACK DlgProcMirOTROptsProto(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { HWND lv = GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS); int sel; switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); { HWND cmb = GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_DEFAULT)); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_ALWAYS)); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_OPP)); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_MANUAL)); SendMessage(cmb, CB_ADDSTRING, 0, (WPARAM)TranslateT(LANG_POLICY_NEVER)); SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_SETCURSEL, (LPARAM)-1, 0); EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_NEWKEY), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_FORGET), FALSE); } SendMessage(lv, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);// | LVS_EX_CHECKBOXES); { // add list columns LVCOLUMN lvc; // Initialize the LVCOLUMN structure. // The mask specifies that the format, width, text, and // subitem members of the structure are valid. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; lvc.fmt = LVCFMT_LEFT; lvc.iSubItem = 0; lvc.pszText = TranslateT(LANG_PROTO); lvc.cx = 85; // width of column in pixels ListView_InsertColumn(lv, 0, &lvc); lvc.iSubItem = 1; lvc.pszText = TranslateT(LANG_POLICY); lvc.cx = 80; // width of column in pixels ListView_InsertColumn(lv, 1, &lvc); lvc.iSubItem = 2; lvc.pszText = TranslateT(LANG_FINGERPRINT); lvc.cx = 275; // width of column in pixels ListView_InsertColumn(lv, 2, &lvc); } PostMessage(hwndDlg, WMU_REFRESHPROTOLIST, 0, 0); return TRUE; case WMU_REFRESHPROTOLIST: ListView_DeleteAllItems(lv); { LV_ITEM item = { 0 }; int num_protocols; PROTOACCOUNT **pppDesc; Proto_EnumAccounts(&num_protocols, &pppDesc); for (int i = 0; i < num_protocols; i++) { if (!mir_strcmp(pppDesc[i]->szModuleName, META_PROTO)) continue; if ((CallProtoService(pppDesc[i]->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM) == 0) continue; item.mask = LVIF_TEXT | LVIF_PARAM; item.pszText = pppDesc[i]->tszAccountName; item.lParam = (LPARAM)pppDesc[i]->szModuleName; int ilvItem = ListView_InsertItem(lv, &item); ListView_SetItemText(lv, ilvItem, 1, (TCHAR*)policy_to_string(db_get_dw(0, MODULENAME"_ProtoPol", pppDesc[i]->szModuleName, CONTACT_DEFAULT_POLICY))); char fprint[45]; if (otrl_privkey_fingerprint(otr_user_state, fprint, pppDesc[i]->szModuleName, pppDesc[i]->szModuleName)) { TCHAR *temp = mir_a2t(fprint); ListView_SetItemText(lv, ilvItem, 2, temp); mir_free(temp); } } } return TRUE; case WM_COMMAND: switch (HIWORD(wParam)) { case BN_CLICKED: switch (LOWORD(wParam)) { case IDC_BTN_PROTO_NEWKEY: sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS)); if (sel != -1) { PROTOREGENKEYOPTIONS *opts = new PROTOREGENKEYOPTIONS(); opts->refresh = hwndDlg; ListView_GetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 0, opts->proto, _countof(opts->proto)); CloseHandle((HANDLE)_beginthreadex(0, 0, regen_key_thread, opts, 0, 0)); } break; case IDC_BTN_PROTO_FORGET: sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS)); if (sel != -1) { TCHAR buff_proto[128]; ListView_GetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 0, buff_proto, _countof(buff_proto)); TCHAR buff[512]; mir_sntprintf(buff, TranslateT(LANG_OTR_ASK_REMOVEKEY), buff_proto); if (IDYES == MessageBox(hwndDlg, buff, TranslateT(LANG_OTR_INFO), MB_ICONQUESTION | MB_YESNO)) { char *proto = GetProtoName(lv, sel); if (proto == NULL) break; OtrlPrivKey *key = otrl_privkey_find(otr_user_state, proto, proto); if (key) { otrl_privkey_forget(key); otrl_privkey_write(otr_user_state, _T2A(g_private_key_filename)); ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), sel, 2, _T("")); } } } } break; case CBN_SELCHANGE: switch (LOWORD(wParam)) { case IDC_CMB_PROTO_POLICY: int proto = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS)); if (proto == -1) break; int sel = SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_GETCURSEL, 0, 0); if (sel == CB_ERR) break; int len = SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_GETLBTEXTLEN, sel, 0); if (len < 0) break; TCHAR *text = new TCHAR[len + 1]; SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_GETLBTEXT, sel, (LPARAM)text); ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_PROTO_PROTOS), proto, 1, text); delete[] text; SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } break; } break; case WM_NOTIFY: if (((LPNMHDR)lParam)->code == LVN_ITEMCHANGED && ((LPNMHDR)lParam)->hwndFrom == lv) { LPNMLISTVIEW notif = (LPNMLISTVIEW)lParam; if ((notif->uNewState & LVIS_SELECTED) == 0) break; if (notif->iItem == -1) { SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_SETCURSEL, (LPARAM)-1, 0); EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_NEWKEY), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_FORGET), FALSE); } else { EnableWindow(GetDlgItem(hwndDlg, IDC_CMB_PROTO_POLICY), TRUE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_NEWKEY), TRUE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_PROTO_FORGET), TRUE); TCHAR buff[50]; ListView_GetItemText(((LPNMHDR)lParam)->hwndFrom, notif->iItem, 1, buff, _countof(buff)); SendDlgItemMessage(hwndDlg, IDC_CMB_PROTO_POLICY, CB_SELECTSTRING, (LPARAM)-1, (WPARAM)buff); } } else if (((LPNMHDR)lParam)->code == PSN_APPLY) { int cnt = ListView_GetItemCount(lv); TCHAR policy[64]; for (int i = 0; i < cnt; ++i) { char *proto = GetProtoName(lv, i); if (proto == NULL) continue; ListView_GetItemText(lv, i, 1, policy, _countof(policy)); db_set_dw(0, MODULENAME"_ProtoPol", proto, policy_from_string(policy)); } // handle apply return TRUE; } break; } return FALSE; }
int main(int argc, char** argv){ deadline_miss_flag = (int *)malloc(100*sizeof(int)); // int cpu_no; // for (cpu_no=0; cpu_no<100; cpu_no++){ // deadline_miss_flag[cpu_no] = cpu_no; // } srand(time(NULL)); int i,j; int thread_ret; char tmp_str[200], tmp_str_a[200]; // options int node_ids[4] = {0, 1, 2, 3}; // int node_ids[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; int num_nodes = 4; int node_socks[num_nodes]; int host_id = 200; int num_samples = 1*1e6*1e-3; // samples in subframe = (samples/sec)*1ms int duration = 50; //secs int priority = 10; int sched = SCHED_FIFO; sprintf(exp_str, "offload"); mcs = 20; int lmax = 1500; int deadline = 1500; num_bss = 4; num_ants = 1; // antennas per radio N_P = 8; char c; while ((c = getopt (argc, argv, "h::M:A:L:s:d:p:S:e:D:Z:m:")) != -1) { switch (c) { case 'M': num_bss = atoi(optarg); break; case 'A': num_ants = atoi(optarg); break; case 's': num_samples = atoi(optarg); break; case 'd': duration = atoi(optarg); break; case 'p': priority = atoi(optarg); if (priority > 99){ log_error("Unsupported priority!\n"); exit(-1); } break; case 'Z': N_P = atoi(optarg); break; case 'S': switch((char)*optarg){ case 'R': sched = SCHED_RR; break; case 'F': sched = SCHED_FIFO; break; case 'O': sched = SCHED_OTHER; break; default: log_error("Unsupported scheduler!\n"); exit(-1); break; } break; case 'e': switch((char)*optarg){ case 'P': sprintf(exp_str, "plain"); break; case 'O': sprintf(exp_str, "offload"); break; default: log_error("Unsupported exp!\n"); exit(-1); break; } break; case 'D': debug_trans = atoi(optarg); break; case 'm': mcs = atoi(optarg); break; case 'L': lmax = atoi(optarg); break; case 'h': default: printf("%s -h(elp) -M num_bss -A num_ants -L lmax -s num_samples -d duration(s) -p priority(1-99) -S sched (R/F/O) -e experiment ('P'plain /'O' offload) -D transport debug(0 or 1) -m MCS\n\nExample usage: sudo ./gd_lte -M 4 -A 1 -L 2000 -s 1000 -d 10 -p 10 -S F -e P -D 1 -m 20\n", argv[0]); exit(1); break; } } num_nodes = num_bss*num_ants; // calculate the number of cores to support the given radios num_cores_bs = ceil((double)lmax/1000); // each bs proc_nthreads = num_cores_bs*num_bss; // total assert(num_cores_bs == 1 || num_cores_bs == 2 || num_cores_bs == 3); log_notice("Scheduler will run with %d cores for each of %d BSs. Total cores = %d\n",num_cores_bs, num_bss, proc_nthreads) /**************************************************************************/ iqr = (short*) malloc(1*2*30720*sizeof(short)); //1=no_of_frame/1000, 2=BW/5MHz iqi = (short*) malloc(1*2*30720*sizeof(short)); // configure the baseband configure(0, NULL, 0, iqr, iqi, mcs, num_ants); /**************************************************************************/ double my_complex *buffer = (double my_complex*) malloc(num_samples*sizeof(double my_complex)); policy_to_string(sched, tmp_str_a); trans_nthreads = num_nodes; /**************************************************************************/ trans_threads = malloc(trans_nthreads*sizeof(pthread_t)); gd_thread_data_t *trans_tdata, *timer_tdata; trans_tdata = malloc(trans_nthreads*sizeof(gd_thread_data_t)); timer_tdata = malloc(1*sizeof(gd_thread_data_t)); proc_threads = malloc(proc_nthreads*sizeof(pthread_t)); gd_thread_data_t *proc_tdata; proc_tdata = malloc(proc_nthreads*sizeof(gd_thread_data_t)); subframe_mutex = (pthread_mutex_t*)malloc(proc_nthreads*sizeof(pthread_mutex_t)); state_mutex = (pthread_mutex_t*)malloc(proc_nthreads*sizeof(pthread_mutex_t)); subframe_cond = (pthread_cond_t*)malloc(proc_nthreads*sizeof(pthread_cond_t)); common_time = (struct timespec*)malloc((num_cores_bs)*sizeof(struct timespec)); subframe_avail = (int *)malloc(proc_nthreads*sizeof(int)); state = (long *)malloc(proc_nthreads*sizeof(long)); migrate_avail = (migrate *)malloc(proc_nthreads*sizeof(migrate)); migrate_to = (int *)malloc(proc_nthreads*sizeof(int)); for (i=0; i<proc_nthreads; i++){ subframe_avail[i] = 0; pthread_mutex_init(&subframe_mutex[i], NULL); pthread_mutex_init(&state_mutex[i], NULL); pthread_cond_init(&subframe_cond[i], NULL); migrate_avail[i].count = 0; migrate_avail[i].cur_start_id = 0; } /* install a signal handler for proper shutdown */ signal(SIGQUIT, gd_shutdown); signal(SIGTERM, gd_shutdown); signal(SIGHUP, gd_shutdown); signal(SIGINT, gd_shutdown); running = 1; gd_trans_initialize(node_socks, num_nodes); gd_trans_trigger(); timer_tdata->duration = duration; timer_tdata->sched_policy = sched; timer_tdata->sched_prio = priority; timer_tdata->deadline = usec_to_timespec(500); timer_tdata->period = usec_to_timespec(1000); timer_tdata->cpuset = malloc(sizeof(cpu_set_t)); CPU_SET( 2, timer_tdata->cpuset); for(i= 0; i < trans_nthreads; i++){ trans_tdata[i].ind = i; trans_tdata[i].duration = duration; trans_tdata[i].sched_policy = sched; trans_tdata[i].deadline = usec_to_timespec(500); trans_tdata[i].period = usec_to_timespec(1000); sprintf(tmp_str, "../log_static/exp%s_samp%d_trans%d_prior%d_sched%s_nbss%d_nants%d_ncores%d_Lmax%d_mcs%d.log", exp_str, num_samples, i, priority, tmp_str_a, num_bss, num_ants, num_cores_bs, lmax, mcs); trans_tdata[i].log_handler = fopen(tmp_str, "w"); trans_tdata[i].sched_prio = priority; trans_tdata[i].cpuset = malloc(sizeof(cpu_set_t)); CPU_SET( 22 +i, trans_tdata[i].cpuset); trans_tdata[i].conn_desc.node_id = i; trans_tdata[i].conn_desc.node_sock = node_socks[i]; trans_tdata[i].conn_desc.host_id = host_id; trans_tdata[i].conn_desc.num_samples = num_samples; trans_tdata[i].conn_desc.start_sample = 0; trans_tdata[i].conn_desc.buffer = buffer; trans_tdata[i].conn_desc.buffer_id = 1; } for(i= 0; i < proc_nthreads; i++){ proc_tdata[i].ind = i; proc_tdata[i].duration = duration; proc_tdata[i].sched_policy = sched; proc_tdata[i].deadline = usec_to_timespec(deadline); proc_tdata[i].period = usec_to_timespec(num_cores_bs*1000); sprintf(tmp_str, "../log_static/exp%s_samp%d_proc%d_prior%d_sched%s_nbss%d_nants%d_ncores%d_Lmax%d_mcs%d.log", exp_str, num_samples, i, priority,tmp_str_a, num_bss, num_ants, num_cores_bs, lmax, mcs); proc_tdata[i].log_handler = fopen(tmp_str, "w"); proc_tdata[i].sched_prio = priority; proc_tdata[i].cpuset = malloc(sizeof(cpu_set_t)); CPU_SET( 8+i, proc_tdata[i].cpuset); } struct timespec t_start; // starting time clock_gettime(CLOCK_MONOTONIC, &t_start); timer_tdata->main_start = t_start; thread_ret = pthread_create(&timer_thread, NULL, timer_main, timer_tdata); log_notice("Starting trans threads"); // start threads for(i = 0; i < trans_nthreads; i++){ trans_tdata[i].main_start = t_start; thread_ret = pthread_create(&trans_threads[i], NULL, trans_main, &trans_tdata[i]); if (thread_ret){ log_error("Cannot start thread"); exit(-1); } } log_notice("Starting proc threads"); for(i= 0; i < proc_nthreads; i++){ proc_tdata[i].main_start = t_start; thread_ret = pthread_create(&proc_threads[i], NULL, proc_main, &proc_tdata[i]); if (thread_ret){ log_error("Cannot start thread"); exit(-1); } } pthread_join(timer_thread, NULL); for (i = 0; i < trans_nthreads; i++) { pthread_join(trans_threads[i], NULL); } for (i = 0; i < proc_nthreads; i++) { pthread_join(proc_threads[i], NULL); } return 0; }
void parse_thread_args(char *arg, int idx, thread_data_t *tdata, policy_t def_policy) { char *str = strdup(arg); char *token; long period, exec, dline; char tmp[256]; int i = 0; int cpu; dline = 0; token = strtok(str, ":"); tdata->name = malloc(sizeof(char) * 5); tdata->ind = idx; /* default name for command line threads */ snprintf(tdata->name, 1, "t%d", tdata->ind); tdata->sched_prio = DEFAULT_THREAD_PRIORITY; tdata->sched_policy = def_policy; tdata->cpuset = NULL; tdata->cpuset_str = NULL; while ( token != NULL) { switch(i) { case 0: period = strtol(token, NULL, 10); if (period <= 0 ) usage("Cannot set negative period.", EXIT_INV_COMMANDLINE); tdata->period = usec_to_timespec(period); i++; break; case 1: exec = strtol(token,NULL, 10); //TODO: add support for max_et somehow if (exec > period) usage("Exec time cannot be greater than" " period.", EXIT_INV_COMMANDLINE); if (exec <= 0 ) usage("Cannot set negative exec time", EXIT_INV_COMMANDLINE); tdata->min_et = usec_to_timespec(exec); tdata->max_et = usec_to_timespec(exec); i++; break; case 2: #ifdef AQUOSA if (strcmp(token,"q") == 0) tdata->sched_policy = aquosa; else #endif #ifdef DLSCHED if (strcmp(token,"d") == 0) tdata->sched_policy = deadline; else #endif if (strcmp(token,"f") == 0) tdata->sched_policy = fifo; else if (strcmp(token,"r") == 0) tdata->sched_policy = rr ; else if (strcmp(token,"o") == 0) tdata->sched_policy = other; else { snprintf(tmp, 256, "Invalid scheduling policy %s in %s", token, arg); usage(tmp, EXIT_INV_COMMANDLINE); } policy_to_string(tdata->sched_policy, tdata->sched_policy_descr); i++; break; case 3: if (strcmp(token, "-") == 0) tdata->cpuset = NULL; else { tdata->cpuset = malloc (sizeof(cpu_set_t)); tdata->cpuset_str = strdup(token); } i++; break; case 4: tdata->sched_prio = strtol(token, NULL, 10); // do not check, will fail in pthread_setschedparam i++; break; case 5: dline = strtol(token, NULL, 10); if (dline < exec) usage("Deadline cannot be less than " "execution time", EXIT_INV_COMMANDLINE); if (dline > period) usage("Deadline cannot be greater than " "period", EXIT_INV_COMMANDLINE); if (dline <= 0 ) usage("Cannot set negative deadline", EXIT_INV_COMMANDLINE); tdata->deadline = usec_to_timespec(dline); i++; break; } token = strtok(NULL, ":"); } if ( i < 2 ) { printf("Period and exec time are mandatory\n"); exit(EXIT_INV_COMMANDLINE); } if (dline == 0) tdata->deadline = tdata->period; /* set cpu affinity mask */ if (tdata->cpuset_str) { snprintf(tmp, 256, "%s", tdata->cpuset_str); token = strtok(tmp, ","); while (token != NULL && i < 1000) { cpu = strtol(token, NULL, 10); CPU_SET(cpu, tdata->cpuset); strtok(NULL, ","); i++; } } else tdata->cpuset_str = strdup("-"); free(str); }
static void parse_thread_data(char *name, struct json_object *obj, int idx, thread_data_t *data, const rtapp_options_t *opts) { long exec, period, dline; char *policy; char def_policy[RTAPP_POLICY_DESCR_LENGTH]; struct array_list *cpuset; struct json_object *cpuset_obj, *cpu, *resources, *locks; int i, cpu_idx; log_info(PFX "Parsing thread %s [%d]", name, idx); /* common and defaults */ data->ind = idx; data->name = strdup(name); data->lock_pages = opts->lock_pages; data->sched_prio = DEFAULT_THREAD_PRIORITY; data->cpuset = NULL; data->cpuset_str = NULL; /* loop */ data->loop = get_int_value_from(obj, "loop", TRUE, -1); /* period */ period = get_int_value_from(obj, "period", FALSE, 0); if (period <= 0) { log_critical(PIN2 "Cannot set negative period"); exit(EXIT_INV_CONFIG); } data->period = usec_to_timespec(period); /* exec time */ exec = get_int_value_from(obj, "exec", FALSE, 0); if (exec > period) { log_critical(PIN2 "Exec must be greather than period"); exit(EXIT_INV_CONFIG); } if (exec < 0) { log_critical(PIN2 "Cannot set negative exec time"); exit(EXIT_INV_CONFIG); } data->min_et = usec_to_timespec(exec); data->max_et = usec_to_timespec(exec); /* deadline */ dline = get_int_value_from(obj, "deadline", TRUE, period); if (dline < exec) { log_critical(PIN2 "Deadline cannot be less than exec time"); exit(EXIT_INV_CONFIG); } if (dline > period) { log_critical(PIN2 "Deadline cannot be greater than period"); exit(EXIT_INV_CONFIG); } data->deadline = usec_to_timespec(dline); /* policy */ policy_to_string(opts->policy, def_policy); policy = get_string_value_from(obj, "policy", TRUE, def_policy); if (policy) { if (string_to_policy(policy, &data->sched_policy) != 0) { log_critical(PIN2 "Invalid policy %s", policy); exit(EXIT_INV_CONFIG); } } policy_to_string(data->sched_policy, data->sched_policy_descr); /* priority */ data->sched_prio = get_int_value_from(obj, "priority", TRUE, DEFAULT_THREAD_PRIORITY); /* cpu set */ cpuset_obj = get_in_object(obj, "cpus", TRUE); if (cpuset_obj) { assure_type_is(cpuset_obj, obj, "cpus", json_type_array); data->cpuset_str = strdup(json_object_to_json_string(cpuset_obj)); data->cpuset = malloc(sizeof(cpu_set_t)); cpuset = json_object_get_array(cpuset_obj); CPU_ZERO(data->cpuset); for (i=0; i < json_object_array_length(cpuset_obj); i++) { cpu = json_object_array_get_idx(cpuset_obj, i); cpu_idx = json_object_get_int(cpu); CPU_SET(cpu_idx, data->cpuset); } } else { data->cpuset_str = strdup("-"); data->cpuset = NULL; } log_info(PIN "key: cpus %s", data->cpuset_str); /* resources */ resources = get_in_object(obj, "resources", TRUE); locks = get_in_object(obj, "lock_order", TRUE); if (locks) { assure_type_is(locks, obj, "lock_order", json_type_array); log_info(PIN "key: lock_order %s", json_object_to_json_string(locks)); if (resources) { assure_type_is(resources, obj, "resources", json_type_object); log_info(PIN "key: resources %s", json_object_to_json_string(resources)); } parse_thread_resources(opts, locks, resources, data); } }