static int do_priority_change(void) { if (g_args[1] && g_args[2]) { uint32_t pid = atoi(g_args[1]); uint32_t new_priority = atoi(g_args[2]); if (pid == 0) { print_strln("usage: priority <pid> <priority>"); } else { if (!change_priority(pid, new_priority)) { print_strln("Failed to change priority."); return 0; } return 1; } } else { print_strln("usage: priority <pid> <priority>"); } return 0; }
ER chg_pri(ID tskid, PRI tskpri) { TCB *p_tcb; uint_t newpri; ER ercd; LOG_CHG_PRI_ENTER(tskid, tskpri); CHECK_TSKCTX_UNL(); CHECK_TSKID_SELF(tskid); CHECK_TPRI_INI(tskpri); p_tcb = get_tcb_self(tskid); newpri = (tskpri == TPRI_INI) ? p_tcb->p_tinib->ipriority : INT_PRIORITY(tskpri); t_lock_cpu(); if (TSTAT_DORMANT(p_tcb->tstat)) { ercd = E_OBJ; } else { if (change_priority(p_tcb, newpri)) { dispatch(); } ercd = E_OK; } t_unlock_cpu(); error_exit: LOG_CHG_PRI_LEAVE(ercd); return(ercd); }
/* * 要素優先度が上がる(または増える)場合の現在優先度変更処理 */ Inline bool_t mutex_raise_priority(TCB *p_tcb, uint_t newpri) { if (newpri < p_tcb->priority) { return(change_priority(p_tcb, newpri, true)); } return(false); }
int sys_change_priority(void) { int priority; /*first value argptr saves the pointer variable to the second argument 4 bytes */ argptr(0,(char**)&priority,4); return change_priority(priority); }
void delete_priority(element del, int *n) { if (!inheap(del, *n)) { printf("The element you want to delete is not in the heap.\n"); return; } change_priority(del, heap[1], n); delete_max_heap(n); }
void mutex_acquire(TCB *p_tcb, MTXCB *p_mtxcb) { p_mtxcb->p_loctsk = p_tcb; p_mtxcb->p_prevmtx = p_tcb->p_lastmtx; p_tcb->p_lastmtx = p_mtxcb; if (MTX_CEILING(p_mtxcb) && p_mtxcb->p_mtxinib->ceilpri < p_tcb->priority) { change_priority(p_tcb, p_mtxcb->p_mtxinib->ceilpri, true); } }
void test_process_receive() { //pid == 4 //testing message recieve printf("attemping to receive from 1\n"); MessageEnvelope* env = receive_message(); printf("got:_%s_ from process id: %d\n", env->data, env->sender_pid); get_trace_buffer(env); printf("message trace:\n%s\n", env->data); change_priority(MIN_PRIORITY, 2); request_process_status(env); printf("process status:\n%s\n", env->data); release_message_envelope(env); while (1) release_processor(); }
void mutex_drop_priority(TCB *p_tcb, MTXCB *p_mtxcb) { uint_t newpri; if (MTX_CEILING(p_mtxcb) && p_mtxcb->p_mtxinib->ceilpri == p_tcb->priority) { newpri = mutex_calc_priority(p_tcb); if (newpri != p_tcb->priority) { change_priority(p_tcb, newpri, true); } } }
/* * 要素優先度が下がる(または減る)場合の現在優先度変更処理 */ Inline bool_t mutex_drop_priority(TCB *p_tcb, uint_t oldpri) { uint_t newpri; if (oldpri == p_tcb->priority) { newpri = mutex_calc_priority(p_tcb); if (newpri != p_tcb->priority) { return(change_priority(p_tcb, newpri, true)); } } return(false); }
ER chg_pri(ID tskid, PRI tskpri) { TCB *p_tcb; uint_t newbpri; ER ercd; LOG_CHG_PRI_ENTER(tskid, tskpri); CHECK_TSKCTX_UNL(); /*[NGKI1184][NGKI1185]*/ if (tskid == TSK_SELF) { p_tcb = p_runtsk; /*[NGKI1198]*/ } else { CHECK_ID(VALID_TSKID(tskid)); /*[NGKI1187]*/ p_tcb = get_tcb(tskid); } if (tskpri == TPRI_INI) { newbpri = p_tcb->p_tinib->ipriority; /*[NGKI1199]*/ } else { CHECK_PAR(VALID_TPRI(tskpri)); /*[NGKI1188]*/ newbpri = INT_PRIORITY(tskpri); } lock_cpu(); if (p_tcb->p_tinib->tskatr == TA_NOEXS) { ercd = E_NOEXS; /*[NGKI1189]*/ } else if (TSTAT_DORMANT(p_tcb->tstat)) { ercd = E_OBJ; /*[NGKI1191]*/ } else if ((p_tcb->p_lastmtx != NULL || TSTAT_WAIT_MTX(p_tcb->tstat)) && !((*mtxhook_check_ceilpri)(p_tcb, newbpri))) { ercd = E_ILUSE; /*[NGKI1201]*/ } else { p_tcb->bpriority = newbpri; /*[NGKI1192]*/ if (p_tcb->p_lastmtx == NULL || !((*mtxhook_scan_ceilmtx)(p_tcb))) { change_priority(p_tcb, newbpri, false); /*[NGKI1193]*/ if (p_runtsk != p_schedtsk) { dispatch(); } /*[NGKI1197]*/ } ercd = E_OK; } unlock_cpu(); error_exit: LOG_CHG_PRI_LEAVE(ercd); return(ercd); }
ER chg_pri(ID tskid, PRI tskpri) { TCB *p_tcb; uint_t newbpri; ER ercd; LOG_CHG_PRI_ENTER(tskid, tskpri); CHECK_TSKCTX_UNL(); CHECK_TSKID_SELF(tskid); CHECK_TPRI_INI(tskpri); p_tcb = get_tcb_self(tskid); t_lock_cpu(); if (p_tcb->p_tinib->tskatr == TA_NOEXS) { ercd = E_NOEXS; } else if (VIOLATE_ACPTN(p_tcb->p_tinib->acvct.acptn2)) { ercd = E_OACV; } else if (TSTAT_DORMANT(p_tcb->tstat)) { ercd = E_OBJ; } else { newbpri = (tskpri == TPRI_INI) ? p_tcb->p_tinib->ipriority : INT_PRIORITY(tskpri); if (!(newbpri >= p_runtsk->p_tinib->p_dominib->minpriority)) { ercd = E_ILUSE; } else if ((!queue_empty(&(p_tcb->mutex_queue)) || TSTAT_WAIT_MTX(p_tcb->tstat)) && !((*mtxhook_check_ceilpri)(p_tcb, newbpri))) { ercd = E_ILUSE; } else { p_tcb->bpriority = newbpri; if (queue_empty(&(p_tcb->mutex_queue)) || !((*mtxhook_scan_ceilmtx)(p_tcb))) { if (change_priority(p_tcb, newbpri, false)) { dispatch(); } } ercd = E_OK; } } t_unlock_cpu(); error_exit: LOG_CHG_PRI_LEAVE(ercd); return(ercd); }
int main(void) { // create a max heap first for (int j = 1; j < 11; j++) { element temp; temp.key = j; insert_max_heap(temp, &n); } traverse(); element origin = {3}; element newp = {33}; change_priority(origin, newp, &n); traverse(); return 0; }
SYSCALL ER chg_pri(ID tskid, PRI tskpri) { TCB *tcb; UINT newpri; UINT tstat; ER ercd; LOG_CHG_PRI_ENTER(tskid, tskpri); CHECK_TSKCTX_UNL(); CHECK_TSKID_SELF(tskid); CHECK_TPRI_INI(tskpri); tcb = get_tcb_self(tskid); newpri = (tskpri == TPRI_INI) ? tcb->tinib->ipriority : INT_PRIORITY(tskpri); t_lock_cpu(); if (TSTAT_DORMANT(tstat = tcb->tstat)) { ercd = E_OBJ; } else if (TSTAT_RUNNABLE(tstat)) { if (change_priority(tcb, newpri)) { dispatch(); } ercd = E_OK; } else { tcb->priority = newpri; if ((tstat & TS_WAIT_WOBJCB) != 0) { wobj_change_priority(((WINFO_WOBJ *)(tcb->winfo)) ->wobjcb, tcb); } ercd = E_OK; } t_unlock_cpu(); exit: LOG_CHG_PRI_LEAVE(ercd); return(ercd); }
int main(){ int i; int begin = getpid(); int pid = fork(); if(pid > 0){ for(i = 0; i < 10 && pid > 0; i++){ pid = fork(); if(pid == 0){ break; } if(pid < 0) printf(1,"errors occur!\n"); } if (pid == 0){ int j = 0; if(getpid() == begin + 5){ printf(1," pid = %d, get higher priority\n\n",getpid()); change_priority(33); } if(getpid() == begin + 8){ printf(1," pid = %d, get higher priority\n\n",getpid()); change_priority(33); } while(j++ < 30000000); exit(0); } }else if(pid == 0){ sleep(100); int j = 0; while(j++ < 30000000); exit(0); } int ki = 1; int status; while(ki >= 0){ ki = wait(&status); if(ki == begin+5) printf(1," [%d] I should be done first two\n",ki); else if(ki == begin+8) printf(1," [%d] I should be done first two\n",ki); else printf(1," [%d] done runing\n",ki); } exit(0); return 0; }
void cci_process() { CCI_DISPLAY_ENV = request_msg_env(); MsgEnv *cci_env = request_msg_env(); MsgEnv* a_env = request_msg_env(); // this wont be released as process A will release it later char formatted_msg[1000]; int retVal; while(1) { const int twait = 500000; cci_print("CCI: "); //cci_env = request_msg_env(); get_console_chars(cci_env); cci_env = receive_message(); while(cci_env->msg_type != CONSOLE_INPUT) { release_message_env(cci_env); cci_env = receive_message(); } //Obtained keyboard input char command [MAXCHAR]; int offset = sprintf(command, cci_env->data); // Check atleast 2 characters even if user entered 1. if (offset < 2) offset = 2; // Send a message to process A. This only happens once. If it has already been sent, then prompt user. if (strncasecmp(command, "s", offset) == 0) { if (a_env != NULL) { retVal = send_message(PROCA_ID, a_env); if (retVal != SUCCESS) cci_print("Failed to send message envlope and start A\n"); a_env = NULL; } else { cci_print("A has already started.\n"); } } else if(strncasecmp(command, "ps", offset ) == 0) { retVal = request_process_status(cci_env); if (retVal != SUCCESS) cci_print("Failed to request process status"); sprintf(formatted_msg, cci_env->data); cci_print(formatted_msg); } else if(strncasecmp(command, "cd", offset) == 0) { displayClock(1); } else if(strncasecmp(command, "ct", offset) == 0) { displayClock(0); } // Display Trace Buffers else if(strncasecmp(command, "b", offset) == 0) { retVal = get_trace_buffers(cci_env); if (retVal != SUCCESS) cci_print("Failed to get trace buffers"); sprintf(formatted_msg, "%s", cci_env->data); cci_print(formatted_msg); } else if(strncasecmp(command, "c", 2) == 0) { if(command[4] != ':' || command[7] != ':' || strlen(command) != 10) { sprintf(formatted_msg, "Invalid format for command %s. It should be: c <hh>:<mm>:<ss>\n", "c"); cci_print(formatted_msg); } else { const char * rawTimeString = command+2; char hourString [3] = { '0', '0', '\0'}; char minString [3] = { '0', '0', '\0'}; char secString [3] = { '0', '0', '\0'}; int i, hr, min, sec; for (i=0;i<2;i++) { hourString[i] =rawTimeString[i]; minString[i]=rawTimeString[3+i]; secString[i]=rawTimeString[6+i]; } hour = atoi(hourString); min = atoi(minString); sec = atoi(secString); if (hour>23 || min>59 || sec > 59) { sprintf(formatted_msg, "Invalid input." " Ensure hh not greater than 23, mm not greater than 59, ss not greater than 59.\n"); cci_print(formatted_msg); } else setClock(hour, min, sec); // offset the "c " (c-space) } } else if(strncasecmp(command, "n", 1) == 0) { int priority, pid; // extract priority and pid from the command if (sscanf(command, "%*s %i %i", &priority, &pid)!=2) { sprintf(formatted_msg, "Invalid format for command %s. It should be: n <priority> <process id>\n", "n"); cci_print(formatted_msg); } else { retVal = change_priority(priority, pid); sprintf(formatted_msg, "Priority: %i, Pid: %i\n", priority, pid); cci_print(formatted_msg); if (retVal == ILLEGAL_ARGUMENT) { sprintf(formatted_msg, "Invalid arguments. Ensure that the priority is between [0-3], and the process ID is a valid" "process ID other than the NULL process ID\n"); cci_print(formatted_msg); } else if (retVal != SUCCESS) { cci_print("Priority of specified process could not be changed\n"); } } } else if(strncasecmp(command, "t", offset) == 0) { // no need to release envelopes as terminate will free all memory from MSG_LIST terminate(); } // debugging function. find where all the envelopes are. else if(strncasecmp(command, "en", offset) == 0) { int offset = sprintf(formatted_msg, "\nEnvelope Num\tHeld By\n"); int i; for (i = 0; i < MSG_ENV_COUNT; ++i) { const char* pcb_name; switch(MSG_LIST[i]->dest_pid) { case(-1): pcb_name = "NONE\0"; break; default: pcb_name = PCB_LIST[MSG_LIST[i]->dest_pid]->name; } offset += sprintf(formatted_msg+offset, "%i\t\t%s\n", i+1, pcb_name); } cci_print(formatted_msg); } // debugging, check all queues else if(strncasecmp(command, "cq", offset) == 0) { int offset = 0; offset += sprintf(formatted_msg, "\nREADY QUEUE"); int rdy_queues = proc_pq_get_num_prorities(RDY_PROC_QUEUE); int i; for (i = 0; i < rdy_queues; ++i) { offset+= sprintf(formatted_msg+offset, "\nPriority %i: ", i); pcb* head = RDY_PROC_QUEUE->priority_queues[i]->head; while (head != NULL) { offset += sprintf(formatted_msg+offset, "%s->", head->name); head = head->next; } } offset += sprintf(formatted_msg+offset, "\n\nBLOCKED QUEUE: "); pcb* head = BLOCKED_QUEUE->head; while(head!=NULL) { offset += sprintf(formatted_msg+offset, "%s->", head->name); head = head->next; } offset += sprintf(formatted_msg + offset, "\n\n"); cci_print(formatted_msg); } // One space and enter results in CCI: being printed again else if(strncasecmp(command, " ", offset) == 0) { } // If enter is directly pressed, display a different error else if(strcmp(command, "") == 0) { cci_print("Enter a command!\n"); } // Default error message else { sprintf(formatted_msg, "The command %s is not supported\n", command); cci_print(formatted_msg); } //printf("releasing %p\n", cci_env); //release_message_env(cci_env); } fflush(stdout); printf("=====================WTH! CCI came out of while loop!"); fflush(stdout); terminate(); }
ER chg_pri(ID tskid, PRI tskpri) { TCB *p_tcb; uint_t newpri; ER ercd; bool_t dspreq = false; PCB *p_pcb; LOG_CHG_PRI_ENTER(tskid, tskpri); CHECK_TSKCTX_UNL(); CHECK_TSKID_SELF(tskid); CHECK_TPRI_INI(tskpri); t_lock_cpu(); p_tcb = get_tcb_self(tskid, get_my_p_pcb()); newpri = (tskpri == TPRI_INI) ? p_tcb->p_tinib->ipriority : INT_PRIORITY(tskpri); p_pcb = t_acquire_tsk_lock(p_tcb); if (TSTAT_DORMANT(p_tcb->tstat)) { ercd = E_OBJ; } else { #if TTYPE_KLOCK == G_KLOCK if (change_priority(p_tcb, newpri)) { dspreq = dispatch_request(p_pcb); } #else /* TTYPE_KLOCK != G_KLOCK */ if (!(TSTAT_WAITING(p_tcb->tstat) && TSTAT_WAIT_WOBJ(p_tcb->tstat))) { /* オブジェクト待ち以外の状態の場合 */ if (change_priority(p_tcb, newpri)) { dspreq = dispatch_request(p_pcb); } } else { /* * オブジェクト待ちの場合 * デッドロック回避のため,ロックを取得し直す */ WOBJCB *p_wobjcb = p_tcb->p_wobjcb; p_tcb->pend_chgpri = true; p_tcb->pend_newpri = newpri; release_tsk_lock(p_pcb); /* * あらためて * オブジェクトロック -> タスクロック * の順でロックを取得 */ TEST_G_LABEL("_test_chg_pri"); retry: t_acquire_obj_lock(&GET_OBJLOCK(p_wobjcb)); if ((p_pcb = t_acquire_nested_tsk_lock(p_tcb, &GET_OBJLOCK(p_wobjcb))) == NULL){ goto retry; } /* タスクの状態が変化していないかチェック */ if (!(p_tcb->pend_chgpri)) { /* 既に他の箇所で優先度変更処理がなされた */ release_nested_tsk_lock(p_pcb); release_obj_lock(&GET_OBJLOCK(p_wobjcb)); t_unlock_cpu(); ercd = E_OK; goto error_exit; } p_tcb->priority = p_tcb->pend_newpri; p_tcb->pend_chgpri = false; change_priority(p_tcb, newpri); release_obj_lock(&GET_OBJLOCK(p_wobjcb)); } #endif /* TTYPE_KLOCK != G_KLOCK */ ercd = E_OK; } release_tsk_lock(p_pcb); if (dspreq) { dispatch(); } t_unlock_cpu(); error_exit: LOG_CHG_PRI_LEAVE(ercd); return(ercd); }
int main(int argc, char *argv[]) { int c; if (strcmp(__progname, "swapon") == 0) return swapon_command(argc, argv); while ((c = getopt(argc, argv, "Aacdlkp:st:")) != -1) { switch (c) { case 'A': SET_COMMAND(CMD_A); break; case 'a': SET_COMMAND(CMD_a); break; case 'c': SET_COMMAND(CMD_c); break; case 'd': SET_COMMAND(CMD_d); break; case 'l': SET_COMMAND(CMD_l); break; case 'k': kflag = 1; break; case 'p': pflag = 1; /* XXX strtol() */ pri = atoi(optarg); break; case 's': SET_COMMAND(CMD_s); break; case 't': if (tflag != NULL) usage(); tflag = optarg; break; default: usage(); /* NOTREACHED */ } } argv += optind; argc -= optind; /* Did the user specify a command? */ if (command == 0) { if (argc == 0) SET_COMMAND(CMD_l); else usage(); } switch (argc) { case 0: if (command & REQUIRE_PATH) usage(); break; case 1: if (command & REQUIRE_NOPATH) usage(); break; default: usage(); } /* To change priority, you have to specify one. */ if ((command == CMD_c) && pflag == 0) usage(); /* Sanity-check -t */ if (tflag != NULL) { if (command != CMD_A) usage(); if (strcmp(tflag, "blk") != 0 && strcmp(tflag, "noblk") != 0) usage(); } /* Dispatch the command. */ switch (command) { case CMD_l: list_swap(pri, kflag, pflag, 1); break; case CMD_s: list_swap(pri, kflag, pflag, 0); break; case CMD_c: change_priority(argv[0]); break; case CMD_a: add_swap(argv[0]); break; case CMD_d: del_swap(argv[0]); break; case CMD_A: do_fstab(); break; } return (0); }
void CCI() { //printf("You're in the CCI\n"); int HH=0; int MM=0; int SS=0; int pri=0; int id=0; int U = 0; int dun = 0; msg_env* env = request_msg_env(); msg_env* first = request_msg_env(); while(1) { // send the welcome message /* if (first == NULL){ terminate(1); } strcpy(first->msg_text, "Enter input for the CCI [s, ps, c [##:##:##], cd, ct, b, n [new_prio] [pid], e... , t]:\0"); int F = 0; F = send_console_chars(first); if (F == 0){ terminate(1); } */ U = get_console_chars(env); //keyboard input //sleep(5); // only do this if there was input if (U==1) { env = receive_message(); while (env->msg_type != CONSOLE_INPUT) { env = receive_message(); //***STOPS HERE TO WAIT FOR INPUT } char* input_txt = env->msg_text; // send envelope to Process A if (strcmp(input_txt,"s")==0) { // printf("input was s\n"); //if the text in the field is "s" env = request_msg_env(); //request an envelope int Z =0; Z = send_message(3,env); // send message to Process A } // display process status of all processes else if (strcmp(input_txt,"ps")==0) { // printf("input was ps\n"); env = request_msg_env(); //request an envelope int J=request_process_status(env); if (J==0) printf("Error with getting Process Status\n"); } // allows time to be displayed on console and halts if getting ct else if (strcmp(input_txt,"cd")==0) { // printf("input was cd\n"); wallClockOut = 1; } else if (strcmp(input_txt,"ct")==0) { // printf("input was ct\n"); wallClockOut = 0; } // set clock to any valid 24hr time else if (strncmp(input_txt,"c", 1)==0) { // printf("input was c\n"); int HH = atoi(input_txt+2); int MM = atoi(input_txt+5); int SS = atoi(input_txt+8); int R = clock_set(wallclock, HH, MM, SS); if (R==0) printf("Error with setting clock in CCI\n"); } // b displays past instances of send and receive messages else if (strcmp(input_txt,"b")==0) { // printf("input was b\n"); env = request_msg_env(); //request an envelope int U=get_trace_buffers(env); if (U==0) printf("Error performing call on Trace Buffers\n"); } // terminates RTX else if (strcmp(input_txt,"t")==0) { terminate(0); } // changes priority else if (strncmp(input_txt,"n",1)==0) { // printf("input was n\n"); int new_pri = atoi(input_txt+2); int ID = atoi(input_txt+4); int R = change_priority(new_pri, ID); if (R==0) printf("Error with changing priority in CCI\n"); } // echo the input back else if (strncmp(input_txt,"e", 1)==0) { // printf("input was e\n"); env = request_msg_env(); //request an envelope input_txt[0] = ' '; strcat(input_txt, "\n\n"); strcpy(env->msg_text, "echo is: "); strcpy(env->msg_text, input_txt); int R = send_console_chars(env); if (R==0) printf("Error with echoing to screen\n"); } else { env = request_msg_env(); //request an envelope char* temp = (char*) malloc(sizeof(SIZE)); sprintf(temp, "'%s' is not valid CCI input. Please try again.\n\n", input_txt); strcpy(env->msg_text, temp); int R = send_console_chars(env); if (R==0) printf("Error with printing invalid input message\n"); // printf("'%s' is not valid CCI input. Please try again.\n\n", input_txt); } dun = release_msg_env(env); if (dun == 0) { env = request_msg_env(); //request an envelope strcpy(env->msg_text, "ERROR IN DEALLOCATING ENVELOPE AT END OF CCI\n"); int R = send_console_chars(env); if (R==0) printf("Error with printing error message\n"); } //else // printf("CCI finished, I think\n"); } env = request_msg_env(); // if there was no input release_processor(); } }