// C Source File // Created 4/11/2007; 5:32:18 AM #undef OPTIMIZE_ROM_CALLS #define SAVE_SCREEN #include #include #include #include float calculateU(int numberOfTasks); void getparameters(); #define ARRAYSIZE 10 float carray[ARRAYSIZE]; float parray[ARRAYSIZE]; float barray[ARRAYSIZE]; float darray[ARRAYSIZE]; int uschedfailedtasks[ARRAYSIZE]; /* float *carray; float *parray; float *barray; float *darray; int *uschedfailedtasks; */ int ufailedcount; int tasks; int advancedmode; float contextswitch; // Main Function void _main(void) { int i, i2; char buffer[50]; advancedmode = 0; ufailedcount = 0; tasks = 0; contextswitch = 0.0F; /* if ((carray = (float *)malloc(tasks * sizeof(float)))==NULL) { DlgMessage("ERROR", "Out of memory", BT_OK, BT_NONE); return; } if ((parray = (float *)malloc(tasks * sizeof(float)))==NULL) { DlgMessage("ERROR", "Out of memory", BT_OK, BT_NONE); return; } if ((barray = (float *)malloc(tasks * sizeof(float)))==NULL) { DlgMessage("ERROR", "Out of memory", BT_OK, BT_NONE); return; } if ((darray = (float *)malloc(tasks * sizeof(float)))==NULL) { DlgMessage("ERROR", "Out of memory", BT_OK, BT_NONE); return; } if ((uschedfailedtasks = (int *)malloc(tasks * sizeof(int)))==NULL) { DlgMessage("ERROR", "Out of memory", BT_OK, BT_NONE); return; } */ clrscr(); while (1) { printf("Advanced Mode(Y/N)? "); getsn (buffer, 50); if (buffer[0]=='Y' || buffer[0]=='y') { advancedmode = 1; break; } else if (buffer[0]=='N' || buffer[0]=='n') { advancedmode = 0; break; } } // get context switch if (advancedmode) { while (1) { printf("\n"); printf("Context switch=? "); getsn (buffer, 50); if (!isdigit(buffer[0])) continue; contextswitch = atof(buffer); if (contextswitch>=0.0F) break; } } while (1) { getparameters(); // clears the screen clrscr(); printf("Confirm\n"); for (i=0;i ubound) { printf("U%d->%s=%f>U(%d)=%1.3f [check]\n", (i+1), buffer, utilization, (i+1), ubound); uschedfailedtasks[ufailedcount]=i; ufailedcount++; } else { printf("U%d->%s=%1.3f=0;i2--) { float numerator = 0.0F; // check if there is block and working on that particular task if (advancedmode && i2==task && barray[i2]!=0.0F) { numerator += barray[i2]; sprintf(buffer, "%s%.1f+", buffer, barray[i2]); } numerator += carray[i2]+2.0F*contextswitch; sprintf(buffer, "%s%.1f", buffer, (carray[i2]+2.0F*contextswitch)); if (i2!=0) strcat(buffer, "+"); currentr+=numerator; } previousr=currentr; printf("r(%d,0)->%s=%.1f\n", (task+1), buffer, currentr); // calculate each r > 0 float deadline=parray[task]; if (advancedmode) deadline=darray[task]; while (1) { // do previous task only currentr=carray[task]+2.0F*contextswitch; sprintf(buffer, "%.1f+", currentr); // check if there is blocking for current task if (advancedmode && barray[task]!=0.0F) { currentr += barray[task]; sprintf(buffer, "%s%.1f+", buffer, barray[task]); } for (i2=0;i2%s=%.1f\n", (task+1), iteration, buffer, currentr); if (currentr==previousr || currentr>=deadline) { break; } previousr = currentr; iteration++; } if (currentr>deadline) printf("task(%d) %.1f>%.1f is not scheduable\n", (task+1), currentr, deadline); else printf("task(%d) %.1f<=%.1f is scheduable\n", (task+1), currentr, deadline); if (i!=ufailedcount-1) { printf("\nPress any key to continue\n"); ngetchx(); clrscr(); } } /* free(carray); free(parray); free(array); free(darray); free(uschedfailedtasks); */ // wait for program to exit printf("\nDone\n"); ngetchx(); } float calculateU(int numberOfTasks) { return numberOfTasks*(pow(2, 1.0F/(float)numberOfTasks)-1); } void getparameters() { int i=0; char buffer[50]; // clears the screen clrscr(); printf("Enter number of tasks="); tasks = atoi (getsn (buffer, 50)); for (i=0;i