数学建模社区-数学中国
标题: 经典任务调度算法的模拟程序 [打印本页]
作者: 杨利霞 时间: 2021-4-9 15:15
标题: 经典任务调度算法的模拟程序
& C: N# ?5 ]4 i经典任务调度算法的模拟程序# h5 Y( M! R1 ?% x9 A
本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。
. Y! X0 `. Q& m: Q. H& I1 H$ S0 j9 q5 ^
编程平台:VC6.0+EasyX图形库环境。
! H+ f/ q) `9 [" i- W+ \9 N
+ p' W& a# Q+ p1 l( S以下截取部分程序运行图::
& x: G, F/ Y2 K: {
2 ~0 D ?4 W- e* D源代码:1 m0 H: s& V* {! d, G+ A! T
0 K+ e o8 M5 L, }* S; Z
#include<stdio.h>
; a& k- ]) D: t% C# n/ Y! j0 x+ x3 i#include<stdlib.h>/ b4 x& k8 e1 D& p4 Q
#include<easyx.h>' C( X+ t1 v. |% U5 e
#include<time.h>5 }4 I# I- { n% J% G: T
#include<conio.h>
: k2 y. h( f3 u) R; Y& ?7 a#include<graphics.h>, O V: w P7 ]
#define initProcessNum 10
' X$ \. K7 |) W% A#define initProcessID 1000
; w% i) [9 b1 {# C& Q8 q- Y) S#define MAXProcessRunTime 10000
, [+ G7 ? T7 b. C. B#define MAX_MEMORY 4000
; j/ U4 N9 y. p8 G#define exchange_IO_Compute 10
' r5 z1 e0 s; m- P#define exchange_process 25' q0 b" i; W E; a$ C' r
#define task_completed 1
7 ^6 \9 n4 Q8 G5 R3 ?#define task_not_completed 00 O6 [) d( j! f4 W! Q
#define initclocknum 100
% V( s# w2 g9 i- l+ y. E; ~enum condition6 v8 R9 n! i: j7 h7 a* m3 {) c6 d, X
{! {, Z y+ Q$ Y
dead,computing,IO_waiting,ready
8 a: J4 H, M; Z! P' B: f. `7 A};
* k* l1 }7 J4 G" i( I. E; Mstruct process6 C9 X8 X' R g9 t8 f6 B
{
$ M6 }3 H9 k5 R' \int processID;
& a5 Y8 g# G1 Z6 |" ?0 _4 u5 z& oint comeingTime;
; s+ c& U+ F# @% C0 vint ioNum;
) @" _$ y' W" [5 \3 Eint computeNum;/ T; m; z. s1 c. U
int * ioClock;2 `# [. j1 y: o( ^1 o0 V; Y+ H; k
int * computeClock;
H0 z) h6 t7 B' O- Uint ioTime;* S4 _- V4 R, g, I
int computeTime;
0 o; s1 K% |+ Y. k4 }7 H5 Aint askMemory;
" a1 l; A9 ?3 v) ncondition flag;
( b6 L/ O: \/ A3 U1 e9 nint produceTime; //生成时间,以下三个数据成员用以计算相关性能
( i% M, Z. X8 z2 zint runningTime; //第一次占用CPU的时间* {, g3 M1 s3 `4 n# |
int completedTime; //进程完成时的时间7 `, m7 P+ s2 F% p- p& Q
};
7 D% @+ v# G, S; e$ Gtypedef struct processCmpletedInfo //保存完成一个作业的相关信息
' F& C# I, m0 F6 w; E3 B7 I{ H+ p2 Z) }' \
int processID,comeingTime,askMemory;
2 r9 i# P: K. `' Yint compute,waitio,exchange,completedTime,runningTime;
, A$ j& {4 p4 {4 q7 y d* ~7 ?processCmpletedInfo * next;
* g7 u( b! }& c}PCI;
. ]$ n. [6 X! t) ]- @. r1 Pstruct processPool
9 D5 h* l6 a: C# D6 j! h{: S- t# ? J1 r
process * p;
/ D( A! L, H2 J, m0 f! kint proNum;9 p* {2 e6 W- E
};
; G8 K1 P) O9 B0 j( xint MAX_COMING_TIME=0,ID_FIFO=0,systemClock=0,FLAG_FIFO=0,FLAG_TT=0,FLAG_PF=0,FLAG_SJF=0,FLAG_HR=0,FLAG_show=1;
: y% f6 m. p2 l( xint InitPool(processPool * p);
2 G& {1 c3 ^$ W5 Z' ?, Kint produce_one_task(processPool * p,int i,int id);( X$ ?7 L. m! Y
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);6 d+ k% d0 t; V; C& F5 I
int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
' _. E: _+ S) r7 Mint TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);1 c5 z# Q- a. ^5 d% }
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
" [$ h j/ w5 I9 E8 Jint ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
: T! `' X& F+ N/ m/ s1 w0 tint SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);9 m- [, H! r- g
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
6 t3 B; w& o5 ^+ r* L! o4 Kint Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);& ?9 H3 {! y- y$ b
int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);& {- J5 s. \( Q+ u! v8 @4 |
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);/ G* l1 B4 y/ X( X
3 P' Y- d7 d$ p1 ~* |& H* W
' n3 ]5 [8 F. v' |- m) hint sort_by_comingtime(processPool * p,int pos);
7 w$ w3 T% n" p) R9 }# D; S1 F$ Kint showProcessInf(processPool p);
3 r( A( |5 c" u- ?8 D1 cint drawPerformance_FIFO(int x,int y,int memorry);/ F+ R4 `. J m, j' j* K' A
int drawPerformance_HR(int x,int y,int memorry);& G0 A4 t2 [3 p* ~2 A! ~5 C4 z9 w
int drawPerformance_PF(int x,int y,int memorry);
7 s/ V) ~& W4 c/ v3 Uint drawPerformance_TT(int x,int y,int memorry);' a# B; M( W$ v& X, F6 v) Z
int drawPerformance_SJF(int x,int y,int memorry);
# p5 J. P4 A8 V* H: v% I$ Oint MouseListening();! u4 S6 j9 Y1 S+ L' x
int MouseListening2(int *flagShow,int * showTime);
% P7 M. E7 ^/ |3 X' Z( x0 l% dint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);: `4 @" |7 {0 a' B& Y5 }: I
5 `1 [1 c0 b0 F5 _
V: ?$ f/ i2 V* V$ zvoid main()4 ~2 ]) |: Q" {6 ~
{
+ ?) F5 S) [( x7 W1 _; APCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,- y# r9 ^$ v7 E0 V
*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;3 W2 W4 |+ s2 v, z: K
int i=0,FIFO_memory=MAX_MEMORY,count=0,Timet_memory=MAX_MEMORY,SJF_memory=MAX_MEMORY,Priority_memory=MAX_MEMORY,HR_memory=MAX_MEMORY,
# V9 y3 y! y- d/ I! @' `/ }6 iflagDraw=0,showTime=100000;
9 @0 r' u- H0 ?, I3 _# hprocessPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;
7 Z; k9 v4 ?: j# `FILE *fp=NULL;
/ N8 f9 t/ {' e6 X//processPool HR_p,HR_mmy;9 w% W: T, k9 Q1 X
3 |3 k) T& S s
, J' _! ?) e. B: {6 Tsrand((unsigned)time(0));
. ~$ E3 }; A& BsystemClock=0;
1 d5 L2 a, `) v4 `initgraph( 1200,650,SHOWCONSOLE );
0 P+ [0 I5 M7 r) ?2 wsettextcolor(GREEN);6 K8 j7 I* w" @; k" K+ x6 K) J
setlinecolor(GREEN);
. ?9 Z3 _ b# V+ Y) Z* \setfillcolor(GREEN);
E4 [7 w1 k0 r2 |# t: [InitPool(&FIFO_p);
C+ |9 v, U) psort_by_comingtime(&FIFO_p,-1);
, _$ p! K6 r# }$ l- v. gInitPool(&Timeturn_p);) L4 [* t! F6 `, L/ q
InitPool(&SJF_p); m0 s6 }; @( s# j$ m6 I7 k: m
InitPool(&Priority_p);5 _" x% O% C% z( V* y2 C
InitPool(&HR_p);/ o1 ~; ]% F* h9 n' S; Z n3 g
//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);8 Y5 n0 I' d0 Y( V+ e" I9 K
//Sleep(10000);
K J) }* H( _
- _% E4 q: s" k, R: U' ~" u
5 f" O0 G; p+ D) x8 l9 G qTimeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
0 P& w, v Y) m$ y% tSJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
8 q. g! ^4 N/ G' EPriority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
2 n* _; W3 m, `8 CHR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));# c! m: z9 {* A1 @
for(i=0; i<initProcessNum ;i++)
7 b G; H6 R; j& F" q' |$ ^{0 u b9 _: V/ U: w) i8 j4 h
Timeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));3 M% K2 T/ L7 L6 t
Timeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
* e8 s0 r7 j0 G/ l D4 ESJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));9 |0 ?6 Y& E' x& @$ ?# C
SJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
( H7 F. a$ o9 ]! qPriority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));; m! O( O4 l6 q# j
Priority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int)); S# r- L2 v5 U
HR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));( C0 h8 {, z: Q8 U$ ^8 a h1 y
HR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));0 V7 y/ J' J+ v7 r! b
}
: p* P) l5 J% X+ }/ ?5 u2 jTimeturn_mmy.proNum = 0;1 p( r+ T7 V. Q0 Z* P* g% R
TimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);# O7 [0 u0 P3 B" `* g
SJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);3 `% @; P) F& E" N& Z6 r
Priority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);
: |5 C" b2 j; ~) Z9 Z8 N* EHigh_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);+ ~* d/ x, J& h: e
//showProcessInf(Timeturn_mmy);
* r0 C5 I7 G( S+ O' A1 [4 M1 gFIFO_pri = &FIFO_save_head;, u% g& k( r8 [. l
Timet_pri = &Timet_save_head;: m# O1 O' t9 B8 \$ k: I, X6 x
SJF_pri = &SJF_save_head;
, v1 b7 A9 ^/ e/ D; j8 {Priority_pri = &Priority_save_head; P9 F3 \ }( z* d* F- y
HR_pri = &HR_save_head;
# d/ s6 R3 v) B) U$ U7 H( v4 i4 usetbkcolor(WHITE);8 U7 \1 j) o% u) h+ P
while(1)
, o8 ]% V3 p, b D! s{; l5 o( ^% ?; V \" a6 \
if(MouseListening()==1)
; U& Z" E! j: p G2 SflagDraw=1;6 t+ p. I5 D0 S' D
if(count==100)8 ^6 h/ A5 X; |' G# @
{
! q. \2 g! X0 [0 Z1 B0 x6 Mif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)5 d/ o: N9 E/ l% g4 ~8 t8 b# ]
{
( F# k( a* W1 k+ o0 @$ lFIFO_pri = &((*FIFO_pri)->next);9 J0 Z+ W" z+ Z$ N9 u
9 D+ i9 z6 ?- @7 O; f, t: i//printf("hello");
0 d+ z7 e6 J# n; V) u}
5 j- T7 V0 T& A3 t# j, I4 Y! m7 gif(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)
: ?. v% _0 E% Z" ^" @% [{
0 e1 u& F8 m0 u" k) T Timet_pri = &((*Timet_pri)->next);
, v! T( i [9 o' n5 b, C//printf("hello");, j& ^5 \* X ~% K A9 @
}
( R/ s; L9 ^# z7 Q3 Dif(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)- n* M" |5 m# ~ C
{
) v( z4 M3 \9 A& C5 cSJF_pri = &((*SJF_pri)->next);& T) A/ l) i7 ?3 V" f: b I: s
//printf("hello\n");: I. G5 i3 m0 A0 n
}
, W5 N, q" w7 I7 }" Kif(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed)
4 J4 Y" Z& k" Z2 H# ^( K( R# a{# P( Q! P, y" C
Priority_pri = &((*Priority_pri)->next);
1 R' `5 s2 o% Y }//printf("hello\n");
+ g. x* a9 J3 {5 r4 b( w t}7 z) d L% b) U& z
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)+ |# x! L1 X+ ]
{! j: |2 y! D m
HR_pri = &((*HR_pri)->next);! x: c3 ]% o- {
//printf("hello");
9 g7 E q% o" ~4 z% e: O! ]} | o8 a; f* h6 M& v3 ` r5 Y
count=0;: e8 Z: d. Q1 T1 H0 i( U7 G
}
( r: ?/ Y7 Q+ s: ^else. I e1 [" W7 z7 o5 [
{
5 e! ]3 |7 s, {" J: T8 b2 K! bif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)
0 P4 x V0 z3 I( H; u* N{* v7 u" l: r, ]1 f0 D
FIFO_pri = &((*FIFO_pri)->next);
6 d) B+ B8 {9 y9 O( B// printf("hello");% ~, r9 U1 K! F8 _% O% h/ K' T
}+ E8 P1 C% O( S+ |2 w) S9 z
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)0 g; c, t6 Q$ B7 {- P/ s) h4 {
{
( Z7 x! P' K; ]* C4 V% w+ f0 cTimet_pri = &((*Timet_pri)->next);
% l& \2 Z& {# D( H0 `2 w// printf("hello");9 G& `9 K% I T4 S2 u% h b' M
}. w; w% s G- j; o, ^1 f& X
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)6 F/ L7 I% A3 v# C3 {' @: I$ R( Y7 X. i
{0 r9 l& ]1 B f- ?8 v
SJF_pri = &((*SJF_pri)->next);
! ]5 g1 w+ @, [4 z3 Y# [+ I3 Y// printf("hello\n");! F! i/ Q2 L# }' b' | a( H0 o% |
}
9 V) N4 H R) xif(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)
1 A' D1 W. z' k! U* E{
: u3 R8 b/ l& `; `& _8 X6 oPriority_pri = &((*Priority_pri)->next);
! S' T) k$ x6 R//printf("hello\n"); \" g, ]" L+ Z) A
}7 a6 z. y! W* Y. x) t
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)0 g# M; e( q( K+ ^0 @
{
9 U+ K1 m7 H5 L6 }1 sHR_pri = &((*HR_pri)->next);; a9 z3 H8 F( n. g5 \2 r; Z4 x
//printf("hello");
, }7 d* l# p; U0 K P* U//Sleep(1000);# j+ w& J: l- Q) Q
}
& A7 |+ P$ H+ d# wcount++;
: U& \9 N. R! W' H4 ?9 I}
: X1 m, M4 u4 l, @2 b# G& n' ~5 Z/ Uif(systemClock==showTime)
6 Q( ?# z' m6 p0 o) n! u{+ s, I% f+ V# U" w, i- m
/*PCI * p=FIFO_save_head;0 `& X: M3 p G2 h) ^2 v6 r
int i=0;% x% E: V/ R! n# T9 [
for( ;p!=NULL;p=p->next)! p7 ]$ @6 u& J; T7 q1 g
{
0 q A9 T5 T7 Wprintf("Id %d\n",p->processID);
/ F" l9 A1 z Kprintf("comeingtime %d\n",p->comeingTime);
2 \! C7 L7 ^$ S. b( Nprintf("runningtime %d\n",p->runningTime); T( e4 k% W8 i
printf("asdmemory %d\n",p->askMemory);0 t# O: u% n8 V
printf("completedtime %d\n",p->completedTime);
5 C8 [5 B. R2 i# f9 V5 Gprintf("compute %d\n",p->compute);+ O+ Z3 h7 p$ e; G
printf("exchange %d\n",p->exchange);
7 E3 D0 R3 V+ s$ rprintf("waitio %d\n",p->waitio);- D" {& P2 t+ {$ ~1 b$ n/ l8 q
i++;
! U1 S/ d; j, q& l( R3 y* ?! J& w- f5 n7 y" L5 D
* D: @; y* V7 P _7 g5 ^}- ?0 i; I+ B* m& s6 v5 E& q
printf("%d\n",i);*/! e' z) r9 |0 Z# e, ^
if( (fp = fopen( "data.txt", "a" )) == NULL )
7 J7 W: m$ D/ E a$ r{: L( w3 ]1 V; n) n! _! i
printf( "The file 'data.txt' was not opened\n" );, C/ i! ]3 o: R0 J
//return 1;
- \( ~1 \5 B, i& v% I) G}
( F& h- I, z: f delse
2 j( V* D- m7 F4 |, G/ u{
2 H- D9 H4 H1 I8 pfprintf(fp,"FCFS \n");
- }! L1 i4 W7 B4 t6 o3 N9 P6 Wfor(p=FIFO_save_head;p!=NULL;p=p->next)
# ]: h2 v7 N# ]* @" afprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
' J8 ?$ f5 q, i0 ]" fp->exchange,p->waitio,p->runningTime);
; V' E2 R9 ~ H% ]1 [- Ifprintf(fp,"\nTime turn \n");
7 d8 G% o( p1 k6 d) D$ L( }0 Dfor(p=Timet_save_head;p!=NULL;p=p->next)
+ h" ?5 i8 G2 D* u# j: @fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,5 h m. \/ n V! B
p->exchange,p->waitio,p->runningTime);
4 u9 a1 }# y- j' L, R! y5 L% p4 mfprintf(fp,"\nShort Job First \n");
3 D( x% s1 B2 d2 |+ Qfor(p=SJF_save_head;p!=NULL;p=p->next)
c; H5 ~ U0 }1 }fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,5 Z5 C* ]; P; e7 [& g) w
p->exchange,p->waitio,p->runningTime);
/ v2 `+ |2 n3 x4 l& Xfprintf(fp,"\nPriority \n");
0 U( t( A( @/ _* `" N: hfor(p=Priority_save_head;p!=NULL;p=p->next)6 S x" J7 {/ ?2 P! x
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
9 u" \7 M4 E& f0 [ K, c0 Vp->exchange,p->waitio,p->runningTime);
5 T, \9 y& O1 x. D. [4 yfprintf(fp,"\nHigh response \n"); n% L" O/ l4 p( t- D; w0 H1 b
for(p=HR_save_head;p!=NULL;p=p->next)5 l* z: K1 v+ C5 e! p( z
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,, h3 F- r3 U# r+ @; j% P% O- ^
p->exchange,p->waitio,p->runningTime);
, N8 V+ p7 f) J7 l. O7 ^* e2 \fclose(fp);
+ f" h j( D, ~* E}+ I- U3 g L k: Q
showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);9 _" ]# n- f4 O; c% o! Q& `
MouseListening2(&flagDraw,&showTime);! k7 J$ F$ G! m0 [# Q6 E0 ?. _+ Z
}0 {# Y+ `5 m- B
systemClock++;
" q: v, {& v! [" c4 D1 W- K* Tif(flagDraw==0)
# A% n+ r. E- ` d7 s- S6 x Sleep(10);
& r( A3 u; ?5 T0 B}8 h& }' C; y0 t- A
' n$ @8 ^% L' J8 l: B! X+ Z
& i* O- I' l/ }+ z$ n0 \* S}
7 q& w$ O4 s+ U; l6 }( J, Oint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)6 \ L3 y% G0 ]6 L* G. L
{9 S, y a0 F W( R1 p* f# a3 k9 r
PCI * p=NULL,* name[5];8 e! S6 g6 G5 E/ [& ^
int count=0,i=0;
; }0 G2 m, s. _char ch[5][10]={"FCFS","timet","SJF","PR","HR"};- W0 R: H8 I1 _$ z% _9 @
double turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};
, @$ z, Z' e' Estruct info7 L" T( X B! e6 u
{0 Q) d+ ^" V* L
char name[10];" L0 b6 \0 x, @- X; e
double throughput,turnover,wait,CPU_rate;
7 C2 K' ~; m" L( a8 ~4 {2 ]6 ]}inf[5];2 S0 s5 Y; T6 C, d6 Q9 A
name[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;9 s* m* o. b5 Z3 D m+ c" c
printf("调度算法..........A\n");1 `; t* F9 A- y
printf("吞吐量............B\n");
. B9 f; ~- c, S1 S( {7 C0 u! B. Oprintf("平均周转时间......C\n");
+ c6 m5 p3 Y4 i0 S$ z1 g; Rprintf("等待时间..........D\n");
. c+ e; N U, w- E8 V1 X& y' jprintf("CPU利用率.........E\n");
% j5 L x: K; Cprintf("A\tB\tC\t\tD\t\tE\n");
1 `) R0 @% R6 s; @# R9 _* Afor(i=0;i<5;i++)( X Q) J3 e0 u( p
{
" o9 H b2 P0 |- ~count=0,turnover=0,wait=0,c=0,w=0,change=0;/ ?" d. D$ {; [, n, ^4 Z
for(p=name; p!=NULL; p=p->next)( B: G1 d& F. ?% Q4 m
{
! O; ~! ^$ C6 ^* ~1 P% B9 ccount++;/ X, T% T; |& D! \9 m% H
turnover += p->completedTime - p->comeingTime;4 q. `% ?8 D' P9 I" y6 L5 p+ p
wait += p->runningTime - p->comeingTime;, v- F' o9 x2 i7 f* c d8 g
c += p->compute;
1 W G" R+ j( yw += p->waitio;
! Q6 N4 p8 k- O1 g) Ochange += p->exchange;
, `, S2 D1 ]+ G, n6 k}' J6 Q: \! b9 J+ E m
turnover = turnover/count;
5 f9 V8 r' r$ j$ E! y$ P0 \printf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));
( J' E6 k% P. o% fstrcpy(inf.name,ch);+ O! }$ m% v- z1 t/ U! _: L
inf.throughput=count;
/ y0 U6 w9 \% Linf.turnover=turnover;
0 u2 R) R U& K4 ^ R/ Y5 Binf.wait=wait;* j6 |2 K$ ^' J( k
inf.CPU_rate=c/(c+w+change);6 l5 }4 C# d) X5 K j# ]% O3 ]
}
6 S Y$ S5 H4 H3 \. k. Z//画图- L& W% f$ Y% j/ d. ]
//cleardevice();$ j. {# v0 ?. E6 O
line(0,600,1200,600);, E9 e* G0 ]8 e
line(10,600,10,200);- J9 T; H* R" l
line(10,200,5,205);6 b% _. s5 C7 Y8 ]
line(10,200,15,205);9 U1 a8 T! I# n' e7 v' q' a
line(310,600,310,200);9 T+ w( m9 ?7 _* S' t
line(310,200,305,205);, d; |; \; u% `
line(310,200,315,205);
" |3 w" W! a- V2 e! ]+ \! o0 V# wline(610,600,610,200);5 v8 r( G4 }! q/ ]
line(610,200,605,205);6 \' O0 P, y7 `4 r! M( {1 e1 v! T
line(610,200,615,205);0 G- y1 n( G7 J2 ~- f. y
line(910,600,910,200);! w q7 C( d2 b s
line(910,200,905,205);
) n& L0 d, \! K9 pline(910,200,915,205);//最高的长度400,宽度均为40
2 k H t8 i. `3 W$ A3 Gfor(i=0;i<5;i++)$ |- o/ q- M P. K8 ^
{9 z* r; f. o" m
if(inf.throughput>pos[0])9 ?" w$ b1 q5 Y% e; }2 z' L1 X
pos[0]=inf.throughput;/ ]. w7 v L# g) x* P) h
if(inf.turnover>pos[1])
g2 N, V2 g% I0 p- W/ l6 v2 Q6 Bpos[1]=inf.turnover;
+ {: G1 }( t$ F& `$ Kif(inf.wait>pos[2])9 ]6 c& z" w4 Z0 o) V+ s) p
pos[2]=inf.wait;
- r: f) v! M- G8 p+ k) `6 zif(inf.CPU_rate>pos[3])3 u3 Y3 d, Y/ R
pos[3]=inf.CPU_rate;) H3 e. T8 c0 F3 l8 Y0 x) ` X
}
! y" t( M! G. ]1 e$ \2 Jsettextstyle(30, 15, _T("楷体"));
* k7 s2 ~+ W. g/ ]3 c2 i M& P( h: Vfor(i=0;i<5;i++)! B! n+ H: |1 t6 a Z. \/ O1 M
{
5 O. p0 T, r9 @9 pswitch (i)
( z! U- ~9 }0 L2 q+ v- ^{4 c- s' a1 F& G9 h, s' J
case 0:
+ K8 ^2 z2 ?" ~& W- Q3 b5 G1 rsetfillcolor(BLUE); B3 x. `& c5 B9 R
fillrectangle(100,50,150,100);1 o, [8 \( l7 H0 ^+ X, G, _
outtextxy(160,50,"FCFS");
' `) e6 K, y5 D& t: z# x# ubreak;
$ k6 O; N' Y% K2 _9 Ccase 1:
+ W% o' _+ \' H: V! fsetfillcolor(RED);
- y! H+ P! W/ J( Cfillrectangle(250,50,300,100);
0 O# ~" `) D* V$ n( }& E t6 b- zouttextxy(310,50,"timeTurn");
; c- w1 p, u- M& H" U5 S$ _* j9 abreak;
7 d9 s4 f) G' ~0 s7 c! Q/ t, Icase 2:. M a5 j5 [# p. w2 I, s
setfillcolor(YELLOW);
' A7 B( y2 X" ^fillrectangle(450,50,500,100);
C6 }, g( @% A+ H6 eouttextxy(510,50,"SJf");- O" D p6 m' Z7 [; U! R9 f9 D8 q# V0 B
break;
( x9 X% t. A7 X$ s/ o0 t( \case 3:4 ~! n2 s: ]" F5 }: Z% v
setfillcolor(BROWN);
" `" K" H L2 K$ U- efillrectangle(580,50,630,100);
$ M/ p& T3 v% ~' T( houttextxy(640,50,"PR");
& n; H- Q% K& p, d/ o7 j9 ~break;
6 u! K7 a" Z1 L& g% L% Dcase 4:4 M6 Y4 D" H& @) L1 ~
setfillcolor(GREEN);8 a' o- F# U# ^
fillrectangle(690,50,740,100);
! Q6 B8 J e1 U) G" Youttextxy(750,50,"HR");# ] g& d# l( L, E
break;
0 _! v' ?1 H; j; p' i# A; o% ?3 J}
0 ^; |' B* _7 ]8 Cfillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);
. @- [5 H0 L, \0 n4 u) Wfillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);
3 y. U) e d) Sfillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);5 c* t* ^' a, `7 c& [: c
fillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);/ J- J( s; Y! W+ W* |
6 C) n% q& D% A$ V+ h3 v* ]
, U6 l* E& X0 Q" w2 d}; z$ p: W0 [+ l% S7 R- S! l7 P
outtextxy(100,150,"吞吐量");9 f9 D3 N1 M m8 J* i6 |3 [4 G
outtextxy(350,150,"平均周转时间");
# g3 a+ }3 b) ?& R( J0 I# gouttextxy(650,150,"平均等待时间");3 ~* a* \4 U$ l
outtextxy(950,150,"CPU利用率");
2 ^+ v5 @) ?5 E, [5 U) |return 0;
1 c0 \) \3 }) k" H8 k4 k+ ]1 {}
5 R' {% E2 {' D# y; Vint MouseListening()& \, E. k Y& ^
{
6 y' R: F! R8 f4 U) A: h$ }MOUSEMSG p;
8 |# Q( T) H F# S+ f! kif(MouseHit())
2 b/ W7 b, ~4 s9 j0 Q4 s{
- Z' f% Y. v% U5 D) u2 d% u b! j/ z- E' dp=GetMouseMsg();
c9 Z& I$ t( E8 Q$ \7 s/ @/ {if(p.mkLButton==true)
. B4 i# e# ^9 h# [{# g" N* f7 i5 L$ S# r Y; R
if(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)$ t7 G. k+ Q% G2 K
FLAG_FIFO = 1;, v& h ?& j- E$ `
else if(p.x>400 && p.y>0 && p.x<800 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
W0 I2 ?6 f/ F! v0 y6 r4 @8 bFLAG_TT = 1;
) `$ O& Y) s2 }% _, }8 _* f* s4 Gelse if(p.x>800 && p.y>0 && p.x<1200 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)# q4 |1 V8 \' T& C" r
FLAG_PF = 1;3 v5 w- {9 a" z2 |0 H c
else if(p.x>0 && p.y>325 && p.x<400 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
- n( Q; e0 C1 k" \# ~FLAG_SJF = 1;
6 a8 ?, t# ^$ ]) Helse if(p.x>400 && p.y>325 && p.x<800 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)5 o o! {% D% I& K v; i
FLAG_HR=1;
1 l, |- F- u3 ]- w& z3 R* Uelse if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)
6 T: @! c4 }5 n( D{
, ?0 T8 u, A3 d0 }* n {FLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;
( v w6 M+ k% j) k" _) Qclearrectangle(800,325,1200,650);( |2 e2 U7 s4 t" a6 ~/ z
}
3 l: l3 i( i" `, Ielse if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )
) e/ g' ~- y3 O$ Y$ m{
1 @9 S& V- w2 E* Y! `FLAG_show=0;
9 q4 K, z H( P2 s. O( ecleardevice();
: ^+ h7 p, T4 c+ S: ^2 }return 1;
0 |$ d7 \5 K F9 H2 H}# D% P0 u- q0 { Z% P4 X- {
}: r R l& R' I Y- X* i
}" z; `7 G0 n/ |2 ?; d
return 0;- j% b: p3 I+ a* V# k% h
}
6 H+ l+ t9 D' D4 [- ]2 y' H, nint MouseListening2(int *flagShow,int * showTime)" w% p9 {% ]5 S- y1 F) K- K; [7 f
{; e" G, J: X; y( e) b" |
MOUSEMSG p;
8 S: {' t6 i+ y7 Hrectangle(1150,0,1200,50);
( b% r3 l) I: P8 xouttextxy(1160,10,"X");
3 I5 i" ?$ k' @7 nwhile(1)
r& `4 @% _! M! w& T: B{ k% o1 S' s7 L5 B& I. Y
if(MouseHit())- `* w( z/ t5 ]7 `7 ^0 N
{
) {- H( f5 T2 U6 f4 H) q, P5 np=GetMouseMsg();( R9 Z( D# h, U
if(p.mkLButton==true)( j2 k2 c- @* P
{2 N3 ^6 t' ^; v5 A9 E1 n" M& @
if(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 )/ Q' ~- }+ T* w O
{
, F! Z6 X" I+ Z! @7 \& J9 B4 F(*flagShow) = 0;
; z" a. g4 I( H8 y" j(*showTime) += (*showTime);/ u( F+ ~/ a; q: T' R+ A3 X
FLAG_show=1;8 A( ?+ a3 ^% M# j# j2 }+ O4 w7 T
break;
6 T2 C0 L6 n" u}
$ J2 R# a# b2 S- F/ S2 v
6 n5 s- w5 u3 m4 P/ b5 i}
" F x% B6 l, y0 r1 a. p}
5 D1 ]- X. e X: ~! |5 ASleep(20);9 e5 r* P; [ `
}) L [* Y4 L! T2 z, Z3 V. Z
cleardevice();/ L! \+ u$ s# F4 W' T' W2 O2 E* q
return 0;/ E @( X, n+ I1 F. Y
}
* L: \8 D, a- t7 s$ t$ X6 pint drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)" [% C- u. M* e* f u ^
{
: x' a: U! d' R* T" jstatic int info[11][3],num=0;# {+ R' d8 e7 E6 I; G4 C
int i=0,j=0,pos[10][3][2];
5 E; X$ R+ E2 A& Y( J3 n/ j0 qfloat temp,t;
2 k7 w5 E: {8 O4 o//画按钮,不属于FIFO图的范围* _+ K/ `8 Y/ S7 ^
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1)- H2 O; ~# x6 f! U1 D. L! U$ y
{
: o; X8 F+ x3 N) l0 ~8 E1 M% _, ^settextstyle(30, 15, _T("楷体"));, _; c- N: C2 |7 f( t, S
rectangle(890,455,1110,510);
' p& |1 D3 G+ f. l7 g" ^* H9 hrectangle(900,465,1100,500);
# y2 W6 k# |0 A2 {outtextxy(910,468,"查看运行结果");7 F0 F! W" s2 G0 I6 m& |$ N
}5 Q: Z7 |% \% a% a( A! Z$ X. ?
//结束画按钮
# f D- l0 z1 S E4 Binfo[num][0] = com;6 W) |4 B( U+ {# b* A2 m/ p0 H& n
info[num][1] = wai;) ~; }! [! s/ D8 \4 K" D8 e8 x
info[num++][2] = cha;
l: l/ ~# K0 ?% M; Rif(num>10) //存储10个点% g7 L6 p$ _7 D6 [' j) Q& Q* U
{
6 {# @( `' v4 g! rfor(i=0 ;i<10;i++)" m5 A7 ~- R- Z
{2 N- j/ f# x6 o) n. ~# u- D
info[0] = info[i+1][0]; _# k, k( r0 j; [" x& T5 L3 G
info[1] = info[i+1][1];
% z6 Y" M& _5 Sinfo[2] = info[i+1][2];
; u' E, H5 g2 R; B. v}0 v! I/ ^7 @2 C; D# C% }3 E
num--;
6 J/ [2 A& V& r/ e! l}* G) w8 P0 f% r, n2 W, ]
if(FLAG_show==0)
5 A4 S9 e% b! o, }( W1 s) {, @return 0;
% |0 z8 C* S! [0 X: Kfor(i=0; i<num; i++)6 c+ q* S5 I2 N' O
{
0 l5 z( L5 Q" D3 {t = (float)info[0];
5 K9 q, O% A- H# Ptemp = (t/101)*90;0 B5 ~" I, }0 L" M F- I/ @1 J
pos[0][0] = (10-num+i)*25+x+100;
0 s; x8 E4 H/ P+ {pos[0][1] = y+110-(int)temp;
+ z/ H% G& X$ ~t = (float)info[1];, u* @# J5 A# v4 u. x3 |9 B
temp = (t/101)*90;4 w$ P* y& j% f2 `2 q% d2 ?0 d, z
pos[1][0] = (10-num+i)*25+x+100;: ~' V3 N O) X. P8 l% i! f3 O
pos[1][1] = y+210-(int)temp;+ a; X' T, v# G, i; i& h2 ^; c
t = (float)info[2];& g8 U- w* N* @3 }
temp = (t/101)*90;
2 g( z7 k5 {) K Xpos[2][0] = (10-num+i)*25+x+100;
( R2 m/ i% b! h9 v4 g- r0 w5 J% lpos[2][1] = y+310-(int)temp;
, t8 P8 [! l5 |. K7 d# Q- P}9 L. K0 z6 P- V& F7 j8 I* [. E
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
3 O4 G4 p) W# m. g# Y{- u* q. L2 o1 R% O
clearrectangle(x,y,x+400,y+315);
0 h# w8 |* y- T/ ~( E! z+ t5 zsettextstyle(20, 10, _T("楷体"));
( Z3 |) ?/ Q6 I9 H4 w* Brectangle(x,y,x+400,y+325);. r ^+ M! I3 W# T2 z
outtextxy(x+40,y+10,"CPU"); //画柱状图
" w! L/ W" g& E: q" i4 a4 Z5 eouttextxy(x+45,y+10+100,"IO");
" h. p V2 C, k% k# r/ kouttextxy(x+40-15,y+10+200,"change");
1 Q# _% o) X3 r( l* Z' x: p8 y+ xrectangle(x+35,y+30,x+75,y+110);
4 ^0 q1 P) Y5 g% hrectangle(x+35,y+130,x+75,y+210);
; W M. R. k) \/ T, U3 s4 F" |- qrectangle(x+35,y+230,x+75,y+310);
) [& u. A1 X3 c; N* U& Mouttextxy(x+180,y+310,"FCFS");
0 m2 U0 R" `, A( it = (float)com;$ g+ k% g3 M; h# a' V
temp=(t/101)*80;
/ M( _# _* S/ X( I1 y% [. M- pfillrectangle(x+35,y+110-(int)temp,x+75,y+110);' \ i! Y2 O: h! D
t = (float)wai;7 B3 B* k; ^7 Z8 V7 {
temp=(t/101)*80;1 f" P; b/ s$ k
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);4 N+ k, a' D, C
t = (float)cha;. v8 X, G* \, o
temp=(t/101)*80;7 h6 p9 K7 E; e& \) m3 o6 j
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);: u8 W: r- P% T b8 ~- X% l
for(i=0; i<3; i++) //画坐标 high=90,length=250
. @. R5 F* e1 ^4 x{
n$ t4 p& N& s: Z( iline(x+100,y+110+100*i,x+350,y+110+100*i);
% g& y# l) w- g9 D* X1 gline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
' u1 y, U+ `. B7 d% a; X* w* }line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
4 ~& [3 U3 P9 q3 y; j6 j5 {7 e7 Z4 `
line(x+100,y+110+100*i,x+100,y+20+100*i);: `$ n! S8 K3 L" |" j
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);! n1 J" p* v/ D8 h6 x' N: h( F$ z
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
8 T1 k! K; a" m' bfor(j=0;j<num-1;j++)% P# Y5 U p- T1 q* R0 X
{
0 w* ~# T |" z' T: }& Tline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);2 r: b9 S& p. U) d9 _5 H
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);9 r" M/ ^6 B# l' H T2 M! ^5 a2 L0 Y
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
2 \0 W5 e2 [% K! I}
% v5 @1 M& X$ E}
) W9 I' v$ g$ s& a" R g* K}
$ J9 Y' P# N' Z3 q Melse if(FLAG_FIFO==1)- P% } K' d" e/ F
{: z& c8 m$ b: t5 p& j
x=0,y=0;4 z- o( c5 A% l6 n6 d% q5 F. p
for(i=0; i<num; i++)
3 N+ j3 Q" H3 ]. r1 C% ?( U2 i{' p. q V/ n3 Z# j, l, x1 Z
t = (float)info[0];3 G7 z) U8 x& _% ?4 i* |+ L
temp = (t/101)*180;
2 H( a# b* o+ R" A K, Fpos[0][0] = (10-num+i)*50+x+650;
/ C) ^. c; V& K3 B( M! xpos[0][1] = y+210-(int)temp;3 X* @, T0 ~2 I) g" v* _
t = (float)info[1];
/ r/ P- _; Y, Z0 ~& s; v0 @ X9 @temp = (t/101)*180;$ {. v$ y# R9 X* L0 w6 t
pos[1][0] = (10-num+i)*50+x+650;7 H% J1 |6 n/ n1 ~ G, b
pos[1][1] = y+420-(int)temp;1 z( i7 Y9 ]1 ` l
t = (float)info[2];" i$ X* n, q4 S) t5 ^4 O" s
temp = (float)(t/101)*180;; S% S: s( \/ q+ V) [# U
pos[2][0] = (10-num+i)*50+x+650;
/ Z! ?8 u6 k3 epos[2][1] = y+630-(int)temp;
3 k& q/ X8 ]# _& P! P$ X}
* n. E* I; A4 Z, `clearrectangle(x,y,x+1200,y+650);
# Q9 X* V( b# z4 G. D$ Bsettextstyle(40, 20, _T("楷体"));% v; k% `) P/ o8 o. n1 n
outtextxy(x+50,y+50,"FCFS");6 G& `/ O8 J2 R& j L* B
outtextxy(x+280,y+20,"CPU"); //画柱状图3 U1 I4 M) Z5 q
outtextxy(x+285,y+20+200,"IO");; I( w; t0 E1 }$ i
outtextxy(x+250,y+20+400,"change");
0 U$ U8 |3 v* M7 h/ b- trectangle(x+270,y+65,x+330,y+215);% q* L* ]3 p3 [1 O- D$ ]5 V# A) C
rectangle(x+270,y+265,x+330,y+415);( P) ?! f3 s$ G+ {1 l
rectangle(x+270,y+465,x+330,y+615);1 Q% R9 d2 g, p' U0 c2 o) G
outtextxy(x+290,y+620,"TT"); |0 B# O; G. E0 R
t = (float)com;9 h ]: l/ n# `- q
temp=(t/101)*150;
' H3 h p; c& M' N3 `fillrectangle(x+270,y+215-(int)temp,x+330,y+215);8 W3 Z' p1 O- [6 r* L
t = (float)wai;
4 E! C/ @+ y- }& otemp=(t/101)*150;
/ Q7 Y; Z4 ^+ a% e% C& Dfillrectangle(x+270,y+415-(int)temp,x+330,y+415);
$ @1 Z$ [4 @& M! H* l& M0 Jt = (float)cha;
# O! j+ V4 k2 a! ~: qtemp=(t/101)*150;* K$ h# G- v# I. B( N
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
5 n4 S6 o% g- ]2 yfor(i=0; i<3; i++) //画坐标 high=90,length=250* |: F, _) D6 `- W
{
- ?4 g' w) k3 Oline(x+650,y+210+210*i,x+1150,y+210+210*i);
& ?! A1 P1 b( G; gline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
3 l4 ^3 B+ _& Q% `" V& Sline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
v. J+ M( B# V6 |+ Z& j. P; {/ Z$ b& q0 c* V
line(x+650,y+210+210*i,x+650,y+20+210*i);+ \. Y3 z* a3 g+ H3 s
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
/ E- d$ U* i) U! _* b5 N! I5 L% qline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);- p# F; p3 N0 w: x8 X
for(j=0;j<num-1;j++)& e6 D" h" h k4 l7 [
{
4 B* _4 g8 Y7 V$ E3 u* X+ f$ M2 k' F( Vline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
: O; U/ G1 ~7 l5 Rline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);0 P9 \; m+ b7 ]8 X; [
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
' F- f) Z: C e) D; T p! l}
0 Y2 N. C4 d+ M9 ]7 ^ k$ j}
5 c- e A' v4 K}( K' S" B; K$ J- c# t' g8 `' s
2 M. D( e; U. |* d5 R
9 p# c' S5 z; i7 u' F7 D3 G1 c5 Zreturn 0;3 e" n) V! B. p5 Q/ \: m
}
) }8 J( f8 i- e% P; \int drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)
9 @- E% e% G2 {2 {{
, r0 v% ~: b ^: L3 z+ d) j: nstatic int info[11][3],num=0;
8 w* x, c9 Q* ~4 S9 N; ?- tint i=0,j=0,pos[10][3][2];8 U" c8 {6 M( B
float temp,t;% d* x C9 ^9 @: o4 n5 A; W
info[num][0] = com;0 m! ?. V1 S n* _7 Y
info[num][1] = wai;
+ L$ G! M0 k! e0 b0 r% @; cinfo[num++][2] = cha;9 }' f7 m7 p3 Q# D0 J: l
if(num>10) //存储10个点
2 e! w: M$ \9 v, x{
* F4 k) _+ E& I3 W2 G! ufor(i=0 ;i<10;i++)! H- F' o! v& W( A( d: l4 M/ T# m
{/ e6 l& q2 D' y( a
info[0] = info[i+1][0];
' D U2 j0 | O! C' F5 Linfo[1] = info[i+1][1];
5 C$ B$ r3 g% {3 U5 Z" Minfo[2] = info[i+1][2];
, m! q# C E Y2 {! ^1 T}
7 e3 U! V$ A: F9 w- S cnum--;
1 e3 l, `- v/ ?}, S- l; ?( Q, z3 W* z' _* Y6 |
if(FLAG_show==0)* [2 l* H% X/ I5 L4 ^0 V
return 0;
, t) d) T% J* }for(i=0; i<num; i++): [2 C# X1 [$ _8 b( N" y- B3 x( V/ x' H
{
# Y a3 Z. P; n- it = (float)info[0];
, t4 D, ?5 }. n+ p0 [2 K; ttemp = (t/101)*90;
. L2 x$ x3 K8 J' C2 Fpos[0][0] = (10-num+i)*25+x+100;
# F, A& _5 e! \' f' {pos[0][1] = y+110-(int)temp; r! U& F/ t" X+ }/ X9 D
t = (float)info[1];
( R' O. q1 p% k+ k. stemp = (t/101)*90;5 h, k ^5 v& z8 s
pos[1][0] = (10-num+i)*25+x+100;
m$ u0 S6 r# Q( M( L# g5 r- kpos[1][1] = y+210-(int)temp;
, j: l4 `" @( o' qt = (float)info[2];
- s. c$ H( h: W0 c) c/ r) Xtemp = (float)(t/101)*90;
' x6 P8 p W4 ?+ `, a0 e2 Z) Qpos[2][0] = (10-num+i)*25+x+100;
& j+ s+ T/ q Q/ k) u; T0 Rpos[2][1] = y+310-(int)temp;& P( a) o" z1 e, x5 j
}
* I( q/ ?# F e% q" dif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)' E4 S! f+ B/ `2 D) b1 f3 D2 L1 H0 ^7 u
{$ j, P' b+ P, q+ x0 k
clearrectangle(x,y,x+400,y+315);
1 x+ W6 }! e0 l, Y, F8 ~# Asettextstyle(20, 10, _T("楷体"));0 F! n- d1 w O; z" Q# K0 g
rectangle(x,y,x+400,y+325);, I" d. ]9 W5 ^, P D/ k. i
outtextxy(x+40,y+10,"CPU"); //画柱状图; H; Y+ V3 Q+ D: w7 f
outtextxy(x+45,y+10+100,"IO");3 ]) I5 |5 ~7 h0 T) V/ |2 w1 b
outtextxy(x+40-15,y+10+200,"change");
+ ~' h/ x3 Z) o$ }% grectangle(x+35,y+30,x+75,y+110);& M7 u, x& @8 c* z: S3 Y
rectangle(x+35,y+130,x+75,y+210);, M( f* ^5 X2 L7 r
rectangle(x+35,y+230,x+75,y+310);) m8 ?5 w" g) P
outtextxy(x+180,y+310,"HR");, \) r" W7 N6 F! H6 p& w: F
t = (float)com;1 _- K& a$ G: O/ S( H) I0 b
temp=(t/101)*80;
. ], |; p% s! @& R( efillrectangle(x+35,y+110-(int)temp,x+75,y+110);8 P/ I5 @! L* z$ Z5 A: |7 {' {
t = (float)wai;1 ?6 Q. d3 R$ {2 k5 H$ q
temp=(t/101)*80;4 L& J; k0 C- M- Q
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);: b! f* H+ Y- }: A2 o
t = (float)cha;
+ \% J5 k2 A' C, V7 V* z% jtemp=(t/101)*80;
# U; B, H& h/ v' P& o+ v) Pfillrectangle(x+35,y+310-(int)temp,x+75,y+310);
( V5 ^& h [* k- x5 vfor(i=0; i<3; i++) //画坐标 high=90,length=250
8 I' o- R5 z6 w A' j! \{
1 w. ~3 D; ?- _& r. L, G" dline(x+100,y+110+100*i,x+350,y+110+100*i);
; J. E* J6 L% b5 J9 I& U/ _line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);) q5 z1 N( W; ^9 }0 S7 e
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
4 m6 G* E2 e2 f: L( @
8 b/ k" h+ q+ B% K9 Dline(x+100,y+110+100*i,x+100,y+20+100*i);
" t! U7 @( P8 d, @, ^, ^# F) Rline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
2 N% A5 G0 L' w8 W: U* Q# R1 Dline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
* d* l% h0 A" }+ @for(j=0;j<num-1;j++)% w7 V X5 ^ w0 N$ j
{: U3 L4 S' p4 H9 P' T
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
4 M# I+ X) }5 @line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
& h7 K1 E- O& _ `6 nline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
2 g3 [7 r6 |# @) m. O! v}, L) H) V1 W4 v( e# Z7 t( p- J
}
0 G& d$ s4 q% S% z6 ]0 z& B. X}2 ]: S% `0 F7 K5 T0 g% ~
else if(FLAG_HR==1)" H% |3 ?- m& O5 x
{) v# d) Z) x6 s3 v2 k
x=0,y=0;
4 h' |4 D0 z! }4 W& P" H, [/ @5 Bfor(i=0; i<num; i++) {. m w( c8 w. T- }& |
{, O- r$ e' A3 w* _1 U* ^3 T
t = (float)info[0];8 x; f$ `0 f, J/ q* r8 k
temp = (t/101)*180;- x4 q* X5 F2 |8 A
pos[0][0] = (10-num+i)*50+x+650;) L- V/ M9 u3 B1 P- D% P+ x0 q
pos[0][1] = y+210-(int)temp;0 Y0 x6 t2 n; s; A5 G% e" a/ z
t = (float)info[1];; R4 I. y% Y# ?! d
temp = (t/101)*180;
' x8 d1 N- f! B/ I5 ^: lpos[1][0] = (10-num+i)*50+x+650;5 \4 F* ~- V$ h6 e7 y
pos[1][1] = y+420-(int)temp;% W ?+ v, v, V% ?; l
t = (float)info[2];
( N# {# o1 f: c9 Ftemp = (float)(t/101)*180;
: W- J# D, h+ I6 spos[2][0] = (10-num+i)*50+x+650;8 E) f0 x* w6 v% ]
pos[2][1] = y+630-(int)temp;& ~& ]! S8 ^, \- [: l
}9 ~# E# K' f. D& E
clearrectangle(x,y,x+1200,y+650);6 v8 K7 s+ @3 J: w0 }
settextstyle(40, 20, _T("楷体"));5 j- h$ x1 C- [% ^7 B( i
outtextxy(x+50,y+50,"HR");
+ w3 Z1 i1 n+ o, bouttextxy(x+280,y+20,"CPU"); //画柱状图: p- x. z3 s [8 v* r, Z6 z
outtextxy(x+285,y+20+200,"IO");
j+ _3 x6 C1 x( v6 T/ nouttextxy(x+250,y+20+400,"change");
6 E2 N; z1 v4 h) l1 T5 frectangle(x+270,y+65,x+330,y+215);
9 d2 Y+ G, ^! b6 _9 Brectangle(x+270,y+265,x+330,y+415);
; ~6 Y( A! t. d6 U# _3 c5 P1 T- krectangle(x+270,y+465,x+330,y+615);3 c" t; m8 @4 A. f9 p
outtextxy(x+290,y+620,"TT");5 |) i9 i- ]& ?4 T" v0 p
t = (float)com;3 ~+ `0 r5 ^+ X, y& r: ]. m* M. f
temp=(t/101)*150;* \, a. ~4 S4 z+ M4 Q
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);. q7 V9 b& M. `2 m% l
t = (float)wai;& |5 k. T/ ]( ~6 Z* y: N* a) f
temp=(t/101)*150;
7 R# _2 v; x4 bfillrectangle(x+270,y+415-(int)temp,x+330,y+415);% ^* _3 Q) m8 U9 `$ w' A6 |
t = (float)cha;
( W* e' e) Q G% t7 d9 [$ Q8 ]temp=(t/101)*150;, _5 W9 m9 p, J6 I$ }4 H
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
* K: E8 U; o* i# Efor(i=0; i<3; i++) //画坐标 high=90,length=250) X- {7 o3 m- Q
{- U! d5 Q1 k3 n: ~, L6 ]- d
line(x+650,y+210+210*i,x+1150,y+210+210*i);
1 m1 [6 I3 g. fline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
/ g* n- V; G$ ^0 I9 [ p- iline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);% f5 M/ j# p% P( V2 i
7 |6 U8 E4 [6 B9 v! O1 E& T) f1 E3 Xline(x+650,y+210+210*i,x+650,y+20+210*i);* C8 ]# {' g) z+ j& }* P C* s
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
5 @0 h3 C+ Y2 {7 @1 }2 m1 _" |' mline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
& V C" Q* G4 G, e2 c# ]( k: Pfor(j=0;j<num-1;j++)! ?7 c. _- c P2 F0 n
{
# r9 i- h( N. E7 nline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
- ]9 N7 Z' M# |, |8 Iline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);$ y6 U+ u8 G: Q& A
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); % z/ N+ `5 J- D& P4 u
}
, A* x4 n; J. \: X$ R5 k% U}% }) n/ @7 T6 h" [5 ]* m2 y3 N
}
- J2 ~5 W% u( H5 ]2 ~7 I5 E: {
5 P0 X; ]5 |6 [2 j5 K* D4 B; k: y9 F: b
return 0;
( a# @# I! D: G; L) V$ C* [}! Q' D3 V; F4 H3 ^% ^+ O$ P
int drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)
4 l* K- ?! J# w6 R: ~( P; U{
3 X' c0 e1 z7 D9 w6 _ E/ Dstatic int info[11][3],num=0;, @1 S* X* }, @6 P7 _) Q# J
int i=0,j=0,pos[10][3][2];
$ V0 S0 G3 c$ J6 ifloat temp,t;% A3 d+ w7 B! x& k' t9 v- U
info[num][0] = com;" K. H! ]8 n* V. w
info[num][1] = wai;
- p4 x# N! o* ]2 Uinfo[num++][2] = cha;
! b7 j- C9 C7 nif(num>10) //存储10个点" ]$ T( u* T l0 J3 T' _# ^
{
4 c2 M" X( m6 A: Z+ `for(i=0 ;i<10;i++)
* s4 r( R; P8 g% B{+ P9 u! c' w4 }4 P$ K
info[0] = info[i+1][0];' W) A# b& d. G5 S, \( z
info[1] = info[i+1][1];; O( r8 A' z8 B. }
info[2] = info[i+1][2];! b. A1 ~8 y {/ f
}0 V; A* |2 k+ b6 ]3 {% g
num--;
0 W+ b# f, s$ r$ @}
% I [: w8 I z. n8 Y3 Hif(FLAG_show==0); N. m2 y' J0 q9 e# I; p# h
return 0;
) h# b: _2 F/ k P- n4 e3 \for(i=0; i<num; i++)( K* R; ] B; S* \
{
. l' }) R; @5 P3 D% N, ~5 q1 St = (float)info[0];
% V% K% S2 {: e9 ntemp = (t/101)*90;! w6 E8 C, `9 i
pos[0][0] = (10-num+i)*25+x+100;
5 \4 o* I$ K" x. I9 D! qpos[0][1] = y+110-(int)temp;) V# N; V* Z v; Y
t = (float)info[1]; |, h, J( R2 s- @2 x
temp = (t/101)*90;
( H4 p% v5 H1 q- u& Ypos[1][0] = (10-num+i)*25+x+100;; V% F! o7 r0 B, t# j
pos[1][1] = y+210-(int)temp;- A1 l8 E' u0 Q: G
t = (float)info[2];
/ [- M) `+ b: E( @. m8 Xtemp = (float)(t/101)*90;) j7 Z5 M: _! w( E; h& N" |
pos[2][0] = (10-num+i)*25+x+100;
& ~5 o! m( v1 ^% D( X1 Dpos[2][1] = y+310-(int)temp;' r+ f9 @' X- p+ q6 h9 f4 U
}0 L5 c1 f2 m9 @+ ~/ R
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)+ `. s3 r. y& S1 B6 A. m
{
) N1 \- ]) b6 q ~( jclearrectangle(x,y,x+400,y+315);
2 J$ b+ H1 Z1 J0 W+ b! zsettextstyle(20, 10, _T("楷体"));
g i% S6 d7 m s& a6 }+ nrectangle(x,y,x+400,y+325);
/ \ w* t; o4 ^, i% M; Zouttextxy(x+40,y+10,"CPU"); //画柱状图
$ G, Y! W0 P0 Y2 j1 v- x7 louttextxy(x+45,y+10+100,"IO");
& a" g W2 `2 T: L" houttextxy(x+40-15,y+10+200,"change");
! E1 ?, V) d' R& Z: Arectangle(x+35,y+30,x+75,y+110);
0 W7 Q* n: r5 o ?4 K0 Krectangle(x+35,y+130,x+75,y+210);
& Q$ {, o9 L( f1 ^rectangle(x+35,y+230,x+75,y+310);
$ g7 o) i" O2 u* v L" r! R7 houttextxy(x+180,y+310,"TT");
: k" R. o7 o( Q. Nt = (float)com;
5 x- }0 v' H, ttemp=(t/101)*80;& Y3 [+ @" Y; s& h
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
: p$ ]3 ?8 i5 wt = (float)wai;8 f5 Z9 z$ ~$ i/ E8 d. t5 G- b
temp=(t/101)*80;
?/ S- u; x& B5 P* P: J8 @8 H( zfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
( [0 g" ?; `4 G8 It = (float)cha;
7 Y' c5 j: w9 otemp=(t/101)*80;# [# }6 i2 g; m# J @5 m
fillrectangle(x+35,y+310-(int)temp,x+75,y+310); v( |1 H- |5 H% ]
for(i=0; i<3; i++) //画坐标 high=90,length=250
+ P) c0 F- |+ v: y+ h+ m{
2 c) {+ [; q1 W, lline(x+100,y+110+100*i,x+350,y+110+100*i);
* L" E+ |4 }8 \5 qline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
" n7 B" B% \0 p1 Xline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
7 Z% k) L3 L- o0 |$ A
! c( _; @# J) L+ Hline(x+100,y+110+100*i,x+100,y+20+100*i);
/ y k- h% Y2 s N: w9 Pline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);3 k0 `" h( K: M7 ] O0 c
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
1 W" S9 u) ~4 W/ u8 e" v1 ofor(j=0;j<num-1;j++)% z- Z0 m: X* R+ }
{8 N' J, s6 J3 @) P7 w1 h. `
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
, r& b4 |* R7 T2 {0 }3 G ^0 Z* Qline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);- |, z9 @" [ R k
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
& T8 w' G8 c4 a) R! o. N2 Y}5 e1 g. I0 j% M" |% k) W7 [- G" N
}
! X8 o* e4 [. ?) @) L+ ~}% `6 C' h7 U; P4 } {
else if(FLAG_TT==1)( P( m4 ~( h5 H5 m7 W& ]
{
, }& ?3 ?. c9 @ [1 j8 ^8 bx=0,y=0;. d2 L4 j0 Y/ B: K9 b) E
for(i=0; i<num; i++)! B7 U% f! M$ _
{
9 M" o4 }8 @: w7 ]- \# mt = (float)info[0];
$ s) N2 a; |4 `& a4 C7 {% } ktemp = (t/101)*180;
* a$ I4 D& {% cpos[0][0] = (10-num+i)*50+x+650;
" ^5 T5 O* T$ [- X: Jpos[0][1] = y+210-(int)temp; C; T( e/ A+ e* D
t = (float)info[1];
7 A% D- w4 H& e- Htemp = (t/101)*180;
. w7 A" S/ Q/ k( s# V, rpos[1][0] = (10-num+i)*50+x+650;1 T- `2 N2 Z8 h
pos[1][1] = y+420-(int)temp;* A- p5 w5 J9 \+ Q8 t4 D( m
t = (float)info[2];
& Q5 g$ {1 }$ I# V6 `& `temp = (float)(t/101)*180;* [* p( r& j; H& R
pos[2][0] = (10-num+i)*50+x+650;
0 G; D5 e, D# @ s+ Bpos[2][1] = y+630-(int)temp;
$ u2 `9 h" V# ]) H* Y! r5 F$ O$ i}# I" ^1 u1 K& v
clearrectangle(x,y,x+1200,y+650);# i W& w, I- H) F. y" n
settextstyle(40, 20, _T("楷体"));1 ]) k# A+ y J- P) f
outtextxy(x+50,y+50,"TT");
& f- h3 W: B$ \+ {4 l# b/ x; Pouttextxy(x+280,y+20,"CPU"); //画柱状图) n% I# T% ]% F, g( Q: F/ R
outtextxy(x+285,y+20+200,"IO");
. z2 W. n+ j# F. x( o" couttextxy(x+250,y+20+400,"change");" `7 \( ~4 g# i" E$ c
rectangle(x+270,y+65,x+330,y+215);
5 x m z, |: H0 ~+ t8 n8 \7 z- |rectangle(x+270,y+265,x+330,y+415);' C% {( N8 B9 J9 g9 z
rectangle(x+270,y+465,x+330,y+615);
8 {8 r) ?5 g6 P% A/ Vouttextxy(x+290,y+620,"TT");
5 F* Z- X4 j$ q" ^" _% X# B3 zt = (float)com;6 ~) \4 V4 I8 s: c$ V0 H
temp=(t/101)*150;
" M, M+ H0 R( F2 F* Lfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
l3 a$ i$ k6 [t = (float)wai;
1 i6 X/ P$ t4 }" u Htemp=(t/101)*150;
5 R! i5 a+ w) k. @ Q8 Sfillrectangle(x+270,y+415-(int)temp,x+330,y+415);& J8 O* W: e9 p! k3 {9 J
t = (float)cha;# J4 z9 E K4 x% b* c7 L* }; }
temp=(t/101)*150;8 ]" i# @, z! M: P% |$ o
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
8 Y% a" o* j N! X6 ifor(i=0; i<3; i++) //画坐标 high=90,length=250
0 M% ]7 q( O2 t$ x! [" x{/ c8 \/ L0 d4 R
line(x+650,y+210+210*i,x+1150,y+210+210*i);
U' `% w/ y( J6 f" x2 Eline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);/ P2 s8 N. F& Q& @: c. p7 L6 \* q D
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
8 s% l% p; E! j% H7 w! W4 ]$ y. T- e% h
line(x+650,y+210+210*i,x+650,y+20+210*i);+ t! u3 \2 u* s) [' T% O
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
) ]- b7 ] S/ g- L5 ^. k: jline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
# k! ` M. J _for(j=0;j<num-1;j++)
( O2 s" n1 S( ^- ] R9 L/ Z{
( }& Q7 J1 C1 J& K* Rline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);7 ?. A2 g8 A1 T9 D3 U( W" A
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]); J: ]4 C) r, F. g
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 6 M- F9 g! n, f5 u
}
3 J& B5 O/ j$ H% t! t. U1 ?}5 r( O+ U a& d% g- R, v" I
}& N# `( m1 S4 f/ l7 k8 |; I
) @+ g9 d0 |3 M, H& Q q0 }
. \. w2 \) @5 z6 Q7 C/ oreturn 0;
# K4 i2 U# ]1 i( l8 W5 n}
! l- x" q O# a, u$ G9 vint drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)1 M! y* y4 i7 G& l
{& N5 a9 J0 h* L% u* Z3 s( A
static int info[11][3],num=0;* U5 ^) R: `7 y7 G/ r* ~
int i=0,j=0,pos[10][3][2];
: b5 F, H6 s- i% j) H- k- ~float temp,t;
( {1 v& w0 b5 S1 dinfo[num][0] = com;
. o& e8 S2 Q4 V4 E. Pinfo[num][1] = wai;
- o9 _# h0 P* e6 _8 c; r" T/ w9 Minfo[num++][2] = cha;- r; w6 g- n) ~7 X
if(num>10) //存储10个点; R( ~4 r6 j# R3 J* c- e
{
* X& R& J ~* K* t! D8 \8 f- H$ _for(i=0 ;i<10;i++) r' U6 U4 M# v# Y* s: P
{
`$ M; A& V/ A" H" v9 Minfo[0] = info[i+1][0];+ }3 {* {! z4 U& x3 J- q \1 d
info[1] = info[i+1][1];
4 |/ P/ o- h% uinfo[2] = info[i+1][2];( X3 n# g' |: y' m* `
}3 G) s" d+ [8 f) l7 X% f s
num--;! e& ]# ~4 W, t9 k
}, z7 N0 \1 J% j$ |
if(FLAG_show==0)
$ G& F$ D* U2 d9 lreturn 0;8 }& q6 w" n" h9 ? K) Z
for(i=0; i<num; i++), [! d# C' V3 @: S& _# N1 {
{. \- J' p) k( Z) H( [3 E r" o
t = (float)info[0];& b" w+ G; B1 i/ C3 M8 X, v0 ]% C
temp = (t/101)*90;
4 C ^+ d. t, W4 q: P) gpos[0][0] = (10-num+i)*25+x+100;) ^8 ~9 k" N6 M4 Z
pos[0][1] = y+110-(int)temp;( E! A& q/ b- D! q
t = (float)info[1];
* Z' b ]2 v0 @/ mtemp = (t/101)*90;/ P1 }; g/ r( G' t
pos[1][0] = (10-num+i)*25+x+100;6 B+ s. u8 w% L. o0 d
pos[1][1] = y+210-(int)temp;1 j/ S: X5 L, D" D% ]! x& X$ C
t = (float)info[2];
& D# G7 T! J' ztemp = (float)(t/101)*90;
! M2 c6 R8 r( |: B$ g" g8 Qpos[2][0] = (10-num+i)*25+x+100;
, [1 k2 b+ a' y$ Ipos[2][1] = y+310-(int)temp;% J+ r% p% n) c/ N
} K# z0 \7 }$ `( e c
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
; u) P1 g* X+ k. f{
, Z0 G) \3 e2 J8 t9 K5 eclearrectangle(x,y,x+400,y+315);
! s! i7 B" p8 w C" U, D0 jsettextstyle(20, 10, _T("楷体"));
# ^, x# O( g) Q( y( [9 Yrectangle(x,y,x+400,y+325);! p" i5 H9 v j, c& f
outtextxy(x+40,y+10,"CPU"); //画柱状图
z% |) i! }/ i. s) touttextxy(x+45,y+10+100,"IO");, n* M+ r! ~5 D( o% I: ]
outtextxy(x+40-15,y+10+200,"change");
: \9 V$ Z5 r9 J& v0 |rectangle(x+35,y+30,x+75,y+110);3 m6 v8 y2 X* Q* X4 X
rectangle(x+35,y+130,x+75,y+210);
6 e% Z9 K3 S' ^- grectangle(x+35,y+230,x+75,y+310);( X( y6 g& I1 {- t
outtextxy(x+180,y+310,"PF");
3 y! R/ Q" v/ Tt = (float)com;
% `+ C/ U; m: m ?9 Rtemp=(t/101)*80;
, w# f0 B0 G- U& F4 ?fillrectangle(x+35,y+110-(int)temp,x+75,y+110);+ A$ Q$ U! O; o; E
t = (float)wai;. z: Q% \4 ^$ o
temp=(t/101)*80;
: x) P& E% \: I( \fillrectangle(x+35,y+210-(int)temp,x+75,y+210);7 b- c" t. D1 V P3 m
t = (float)cha;, v6 g( k7 r9 @ B# x. P
temp=(t/101)*80;" M# D" Z( `1 b0 n& b6 A- ]0 A
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);: o$ K# Y1 ]* Q7 w
for(i=0; i<3; i++) //画坐标 high=90,length=250
" V1 r- i$ J8 c{
) _- S9 z. E0 N. b4 M# Lline(x+100,y+110+100*i,x+350,y+110+100*i);! a! ` V& X& Y5 X' }
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);1 O) K4 z* ] N" i: W8 x( f& S3 X
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);; A: n7 ?$ Z5 W6 n, C# ], h
4 {9 K( d" {0 |0 g* u- wline(x+100,y+110+100*i,x+100,y+20+100*i);
u) |6 y2 k8 _2 X& `line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
5 n8 b" Q; k) Z( x* x1 r, Jline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
1 [: E4 h8 W Z6 o/ B/ Q, efor(j=0;j<num-1;j++)% n2 @( v( D1 `8 q6 Y3 t' _$ b
{
$ Z1 X6 K$ y( a _$ j. L. d+ {line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
7 a$ A8 z3 E* O- G4 t; U, ]line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);5 C2 Y$ b% L5 H
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
- ^( V1 o% `5 @) [1 y6 q}
+ }2 e. }: p& U# G- H}1 {8 u- @$ ]; z- G; ?
}! v" e2 I: _) ]1 n
else if(FLAG_PF==1)* F; u% X* h: t0 p7 d
{6 x+ z) o) e+ I% ]
x=0,y=0;
1 F+ [% C# t1 ?& j# Rfor(i=0; i<num; i++)0 F5 u, _) j" U5 M/ A8 H7 a0 W# X
{
& j9 j1 m5 c8 Bt = (float)info[0];
% E% y+ K: G5 a: Rtemp = (t/101)*180;
" i: W1 L7 u) b6 ]' I' v6 kpos[0][0] = (10-num+i)*50+x+650;
z" Q0 v% v' b. {pos[0][1] = y+210-(int)temp;
- j/ p- C; r2 N6 pt = (float)info[1];) Q, m2 d, `7 K- ]$ V: ?2 H: g
temp = (t/101)*180;- E3 I' u ~, l9 ^- U1 L
pos[1][0] = (10-num+i)*50+x+650;6 u$ u0 l+ w" O' Z: C% z
pos[1][1] = y+420-(int)temp;0 C! ^6 x' p6 T8 v) G |3 V9 L
t = (float)info[2];
5 e [' n c; V/ Y) C: ptemp = (float)(t/101)*180;
% Y3 S6 d6 v: Q) K/ C" Jpos[2][0] = (10-num+i)*50+x+650;1 @7 H$ r: E6 T1 t- @
pos[2][1] = y+630-(int)temp;6 }# r! _* x, R: N. U- n; Z
}4 O9 B" |! |+ Q D* t7 c$ }+ A
clearrectangle(x,y,x+1200,y+650); Z% E" H4 ]) |2 m2 j1 x
settextstyle(40, 20, _T("楷体"));
, S# s9 S! x9 g* m* x- \+ Kouttextxy(x+50,y+50,"PF");. ^" _( D" B1 i; {% a7 Z
outtextxy(x+280,y+20,"CPU"); //画柱状图$ p2 z) g& B& }' ^8 e( Y
outtextxy(x+285,y+20+200,"IO");
# h" g# O/ m) B) X. Q' q8 g. W, i" vouttextxy(x+250,y+20+400,"change");
. r+ O+ v6 o6 D0 z2 T6 grectangle(x+270,y+65,x+330,y+215); b1 L, L4 }8 z" X; F+ M
rectangle(x+270,y+265,x+330,y+415);2 v7 u x2 \; P
rectangle(x+270,y+465,x+330,y+615);
5 }. W5 Y, Z$ ]- ~outtextxy(x+290,y+620,"TT");
7 X8 l7 h H6 P% ht = (float)com;
- c9 u# f7 H1 ^" u' \) _temp=(t/101)*150;9 n! i) C9 {- z0 z
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
L+ P; { g- Rt = (float)wai;
# `; |7 O4 J4 q2 ^3 C- {temp=(t/101)*150;
/ e, N' C, m0 [/ xfillrectangle(x+270,y+415-(int)temp,x+330,y+415);
- M$ B# N; m1 a6 Mt = (float)cha;- E8 L# A9 N' s8 v/ B) D
temp=(t/101)*150;" q0 n L7 m1 x% f2 W
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
+ d& a; s7 ]/ s( vfor(i=0; i<3; i++) //画坐标 high=90,length=250
/ B, T& `0 p9 d/ [" C7 o{
9 J# v; m6 g: Z5 z5 R7 Aline(x+650,y+210+210*i,x+1150,y+210+210*i);$ W6 e) m- ~: r0 N
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
% N6 C; D6 M0 d+ a% P5 Oline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
- j, ^& i% M6 z, k
4 E+ J" h7 t0 M8 w2 F: L" W- K: Uline(x+650,y+210+210*i,x+650,y+20+210*i);
& @1 ^; t! ~4 z( r% dline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);: t* c( u( T# C- L5 c
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);- _/ S7 W6 k. E
for(j=0;j<num-1;j++)
" v' Z; b) ]5 b/ w/ h) g0 f: U7 O{
( |. `3 x4 M3 N. aline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
+ S3 h3 s$ O1 F3 P0 d4 P4 |5 nline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
# o) D/ o3 O7 r, W" u, E4 Hline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ; J {; ?. G: R8 f. Z7 w2 l) ]! e' f
}6 I" e; @ M: c$ g
}" q3 ~! {0 [: ~ y
}
* V3 u6 Y* d, ]. c' {return 0;
: F8 ^9 A! L$ w& z3 N0 K% |}- u" j3 J. X) n; ]
int drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)
' M6 y# S5 D) z6 Q* ^& I; _+ Y( C{8 O8 D1 u( W- _3 I: C- g$ |
static int info[11][3],num=0;/ i: H& W4 N7 t
int i=0,j=0,pos[10][3][2];
% R- \# l5 Q s V- q3 Y1 Nfloat temp,t;0 i6 Z3 l9 M5 ?* U
info[num][0] = com;, R0 W0 K, ]1 y, }
info[num][1] = wai;
8 [( J$ v) w! ~) [8 p$ _& Kinfo[num++][2] = cha;
. [4 k" t1 u/ R# a& eif(num>10) //存储10个点, G5 h$ E5 ~6 }! N& c5 b+ r8 O
{
% Y' p/ o6 {3 U, Efor(i=0 ;i<10;i++)
0 ^6 E/ \/ K5 B5 r) W2 K& `* G{
2 |' O1 `- j# G' T0 L4 w7 V0 T# t' vinfo[0] = info[i+1][0];7 S. u# O, I) e L) X, Q- z, f ~, O
info[1] = info[i+1][1];
' R8 O- s$ f3 `( A; H7 T4 d* ?info[2] = info[i+1][2];
4 i; a0 i) C7 D9 V}
& ]/ T7 ~5 {0 L/ X0 c; anum--;
' i9 Z3 a7 [9 a4 b- p/ u& n}7 m- K q1 i" v( [" C% J. e
if(FLAG_show==0)4 z) _4 D7 L# l* @' v r* I
return 0;& \! b# G) T2 ?9 d9 j( ~
for(i=0; i<num; i++)
: ?% ? M2 I! @. ?& O{
0 n3 S( }3 B. R- m5 G6 O0 S. n3 }t = (float)info[0];& M$ s8 X' \- A+ o! h# ^) e
temp = (t/101)*90;
T4 r1 }5 n7 v; @1 Q2 E" ~& q6 Tpos[0][0] = (10-num+i)*25+x+100;
& r7 q- w9 S9 b; G6 ^2 x% opos[0][1] = y+110-(int)temp;0 g6 ^6 j# z: s, S9 N) u" k6 u5 g) ]
t = (float)info[1];/ d* i( I9 ~& K0 I
temp = (t/101)*90;
0 |. u+ B' e; }/ m' X* k9 d' e$ m) w( Jpos[1][0] = (10-num+i)*25+x+100;( s# T1 J3 ^# A
pos[1][1] = y+210-(int)temp;, W% B& O' ?: |: o
t = (float)info[2];
% Q$ `2 I( n5 ` }' B3 g/ wtemp = (float)(t/101)*90;, r* [) n9 V! C
pos[2][0] = (10-num+i)*25+x+100;4 q& b; b1 R+ @1 A
pos[2][1] = y+310-(int)temp;9 Q! T4 B% g) s/ n6 o Y* `
}
/ ?3 A. g2 _4 d* Q# h( X z% [; bif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
7 a7 G% L4 s% w& d$ `9 o! x/ o{ ( t& x6 {+ X% v0 }# V* x: K6 h
clearrectangle(x,y,x+400,y+315);
3 S& h# k h- a! p; U) wsettextstyle(20, 10, _T("楷体"));4 u; m. `2 T! \0 l
rectangle(x,y,x+400,y+325);
) r) I) ]3 n$ g- K/ @ @- Mouttextxy(x+40,y+10,"CPU"); //画柱状图6 Z. _; Z& L2 B4 N O
outtextxy(x+45,y+10+100,"IO");
, F. `- K' W# d/ D3 W7 Oouttextxy(x+40-15,y+10+200,"change");
K$ n8 {" g5 j% B: P, nrectangle(x+35,y+30,x+75,y+110);' q* r- H4 D* @. ~( e( F' _- }
rectangle(x+35,y+130,x+75,y+210);: \. |( D; ]) t: }
rectangle(x+35,y+230,x+75,y+310);
( d6 o$ ]8 N- W# Pouttextxy(x+180,y+310,"SJF");, ^8 i9 L2 T0 C
t = (float)com;+ t% N0 @/ {6 I% @1 r! @. z
temp=(t/101)*80;% _1 L/ R( u x4 i9 a! K/ y; Y' |
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
! G d$ n& `- }0 d' b" mt = (float)wai;
: @# U/ _& R3 ^# }/ t8 V" Xtemp=(t/101)*80;+ \. r" g: p! w: ?
fillrectangle(x+35,y+210-(int)temp,x+75,y+210); x5 h, b* A" A; u% H& f: T
t = (float)cha;
3 ^3 \; B2 R# q4 ]$ xtemp=(t/101)*80;- t/ n* e' Y" D( V
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
: G S( {9 `# qfor(i=0; i<3; i++) //画坐标 high=90,length=2500 _" N; ]( p$ u' T2 q
{
5 q( ~4 X" ?5 t+ wline(x+100,y+110+100*i,x+350,y+110+100*i);
9 C* @$ S! d* xline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
% ^# z1 _0 W1 w7 mline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
6 `: U" z3 t$ ~5 g) |
3 H, k' c# {6 C% R: I: aline(x+100,y+110+100*i,x+100,y+20+100*i);. V0 d1 z6 q* D. C
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
7 T* Q& U/ [) ~line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);6 \" @; P# _5 {$ \( G! N! [
for(j=0;j<num-1;j++)6 s3 d$ M1 t7 B+ p0 o5 p7 h
{
! ]+ O. J ]! D# u8 N jline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);' E3 y5 T. n. ~! L0 p% \6 E
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);- [+ g; c" ]& x4 e8 H
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 0 B, w5 k9 f* ^8 U7 }% ~ v
}
- b& q" b7 H8 ]# f2 w& }/ P}: V& q% N5 ^ e e6 r
}
! y; C0 h3 D3 t9 U# S8 ? i' t% u! Q( aelse if(FLAG_SJF==1); N: J4 p- a. _4 `0 \
{( H1 Z9 \0 V5 k$ C0 a) r, v6 k
x=0,y=0;- {' v; L' E' g: f# f. r k2 d
for(i=0; i<num; i++)
0 W9 Q( R* B7 f8 N( k5 ?{+ K+ P2 J5 p+ J: k) P0 |
t = (float)info[0];
* O3 I6 D: U2 K# o; mtemp = (t/101)*180;- t/ Z' n' X, z( k8 v
pos[0][0] = (10-num+i)*50+x+650;! ~8 P9 |2 d( ]. j# W
pos[0][1] = y+210-(int)temp;
8 y& k- u+ c% m. E% Dt = (float)info[1];( X: k2 b% a; _/ I: s! t' A2 Y: F# i! ~
temp = (t/101)*180;
0 X) h! j; H/ ~* S- L5 S+ R# ]pos[1][0] = (10-num+i)*50+x+650;5 [4 Q7 r# e% e# ]8 \" ]
pos[1][1] = y+420-(int)temp;1 b0 s/ x' d/ A) G( x0 c1 k. ?
t = (float)info[2];
; D8 b7 m: M+ Ftemp = (float)(t/101)*180;- |6 H3 u+ E9 e- P2 p# j3 |( l
pos[2][0] = (10-num+i)*50+x+650;
% K! v2 d( l6 `" R$ `pos[2][1] = y+630-(int)temp;) p3 W4 }" i; z1 [. u0 h8 f6 U
}
$ f+ @; w5 y( z& m0 l! k8 Cclearrectangle(x,y,x+1200,y+650);
2 }( T5 Q; Z4 E% m5 tsettextstyle(40, 20, _T("楷体"));. [: D1 B) Y2 G
outtextxy(x+50,y+50,"SJF");
- Y/ b" T- s6 n+ W& G& pouttextxy(x+280,y+20,"CPU"); //画柱状图9 [, E; \- B9 N: a$ y3 v) o
outtextxy(x+285,y+20+200,"IO");8 j4 K0 a% H: {. a8 D' K& ^+ @3 U Z
outtextxy(x+250,y+20+400,"change");7 D8 G: T1 T* I/ u0 {* Z' j
rectangle(x+270,y+65,x+330,y+215);
0 o. J6 j5 |4 E4 d) |rectangle(x+270,y+265,x+330,y+415);
* b" P4 n' T+ drectangle(x+270,y+465,x+330,y+615);- i* o- X/ @ Z9 D
outtextxy(x+290,y+620,"TT");9 F/ M& y9 k& U9 T
t = (float)com;
! Q: b3 P* s# Q( {3 otemp=(t/101)*150;
% `) V4 w7 E" \fillrectangle(x+270,y+215-(int)temp,x+330,y+215);& J6 k3 U7 A3 G5 r/ b% P& S+ |. H, F
t = (float)wai;
& s: h6 m C+ b8 }temp=(t/101)*150;
: x; D3 J+ O1 U, d, \5 t9 Sfillrectangle(x+270,y+415-(int)temp,x+330,y+415);
) r1 V7 ]. E# u( S0 p2 jt = (float)cha;( Q, h; h. C5 i$ u8 E
temp=(t/101)*150;: P3 V. p' Q1 c' h. @3 r
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);& I* I i& B: P/ X l+ E) y
for(i=0; i<3; i++) //画坐标 high=90,length=250" c, x# `$ d3 N2 Z: x
{3 D9 m" U; @, ], p/ i) ?
line(x+650,y+210+210*i,x+1150,y+210+210*i);- ~7 `2 g! [) o2 Q
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);* R- @2 {9 o4 \6 z: [3 L0 y3 f
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
- q) G4 X! d# a( {
' V/ E6 U% J# X p# m5 aline(x+650,y+210+210*i,x+650,y+20+210*i);; Y. ?9 E7 M: v M0 \+ w) _
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
$ N: r8 P" I7 Dline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
: G; z& ?1 g& F* kfor(j=0;j<num-1;j++)
. Y& U9 O8 ]7 D0 ? `" P1 F# e{
$ V, g2 R* p: x0 [& q8 _( {line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
4 Z W R) | _& ~. C, \line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
! |* h4 l8 Y. B- X2 S' K9 n8 Xline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 2 K$ Z2 j4 A3 d* Z
}
4 n7 l/ R6 @! ^8 N4 N}
: l7 @8 @* C, s; j+ B}1 B' p, D; b, Z9 o& ~7 l
return 0;2 T+ `. r1 t% Y6 A
}% ~/ k% \, A/ L5 K7 R
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
6 p( f. C4 z7 X5 N1 E' T7 S6 {1 y! d{
6 t: O! J4 i6 r( B) R" Ystatic int compute=0,waitio=0,change=0;# {6 r7 m d. e0 z7 p4 b( j/ `# ?
static int computeLast=0,waitioLast=0,changeLast=0;
0 X# N4 I# Z& s/ V$ X f/ tint i=0;# g& y; ^* G) s6 `
if(draw==1), O/ V7 x) U# u
{5 Y z( o C# V8 P Y; J* j
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);5 @% q# _9 y; `% V* _: i
drawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);3 {+ `5 U4 T* s. Z9 i! v
computeLast=compute;
O7 @1 g7 n$ \+ x' ^5 t; Y- u. G& }waitioLast=waitio;( ]! g ?0 n2 l: F
changeLast=change;. e6 e* s9 y) d6 ?9 p$ }5 c
}
: [2 p! E4 _. ~6 I% C; cif((* memory).p[0].flag==ready)
7 ]4 h0 U; I5 Y! o4 G! f(* memory).p[0].flag=computing;
- x9 R+ r% n. R9 @$ r' A1 fif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
8 g2 ?5 o. q# D2 u* v{
4 d; \1 g$ u& S! D; m$ gi=(*memory).p[0].computeNum;( B" p ~( J% j) T3 b' A
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed! g. B4 I# y; j6 L7 _4 |( ?: ~
{; |- U, l7 p- I# z9 T
(*memory).p[0].flag=IO_waiting;
, ^. |5 c8 a. A, O% E; o(*memory).p[0].computeNum--;
+ K5 `/ d" y5 D' x; ^) @change += exchange_IO_Compute;6 w" ^0 _1 s8 B/ z4 H$ E3 t0 y
compute++;
( t B d. V, w) d}; r8 r o. \6 W* T
else
7 Y7 {/ V$ P, k2 ^; H+ ?{( y E7 G `: D5 D0 h
compute++;# |2 r+ Q d, \$ r
}
4 g' Q4 p; Q( Y. |/ ?}% b( `+ R& n. Z2 o# E
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting) G X7 {1 @2 X1 j, @+ U
{0 j z7 f% V k* U
, w1 } ?$ c- |1 S6 y8 oi=(*memory).p[0].ioNum;) k1 F* M- w+ F3 A1 p. ^
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
/ C+ K+ U. z5 k( N3 _& h{
0 n* l0 |; x% _/ e5 m( E B$ H(*memory).p[0].flag=computing;% `, J+ V8 @ j5 S9 |1 O1 z
(*memory).p[0].ioNum--;
7 @8 M$ p3 F9 Ochange += exchange_IO_Compute;
( \( T8 l) Q: v. Hwaitio++;. Z/ C* B- r3 Y
} G5 k" N3 T. X$ E9 ]1 Y, c0 z
else8 r; i# K* x5 N% O
{
9 ]6 [! D9 E8 y, pwaitio++;2 c, K F* I. C
}' k9 C4 Z, e( o: S% ]/ Z/ l& j* K
}
5 Q' k1 h0 q6 K8 ]- t5 T. oelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)* s- H" G+ V# f7 s. B
{
7 Z; [ m- v9 p! Q. [8 r2 v/ \(* memory).p[0].flag=IO_waiting;8 z9 x- w) U9 a" }
change += exchange_IO_Compute;
8 a# ]6 }) ~: P- l}
- r3 o2 U i9 M( O$ ielse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)! c0 I; I& Q4 p5 X' H, ?
{, F' A6 v+ x6 a- m9 T" x
(* memory).p[0].flag=computing;7 s, b! c' t' T% T6 E! O% s
change += exchange_IO_Compute;3 u5 k6 p3 @' T
}, h$ p h) g# O9 H
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成, `1 X+ A8 k3 e& j# k5 W
{" K# [* }! j8 t6 K) a
(*save) = (PCI*)malloc(sizeof(PCI));* d- N& G& s: W7 i+ Z: Q
(*save)->next = NULL;/ M3 ~. ?' o3 E) A
(*save)->processID = (*memory).p[0].processID;
- ^1 y9 X. r% @3 p+ m/ R- d- h k& T- A(*save)->comeingTime = (*memory).p[0].produceTime;4 ~8 Q" P4 {; X; j* n9 s
(*save)->askMemory = (*memory).p[0].askMemory;" T1 _! b7 x8 v% a3 \* t" J; R
(*save)->compute = compute;
8 _. N0 t3 o7 ^4 d- f- O; T(*save)->waitio = waitio;( b* k8 j4 `1 G
(*save)->exchange = change;
8 x# i2 W/ O1 W& s(*save)->completedTime = systemClock;
0 z, ]6 W9 d5 Y4 `& ?6 \: D7 X" v- H(*save)->runningTime = (*memory).p[0].runningTime;6 B5 H% w4 Q- l
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;0 j. | P' _3 K6 C% j7 D
compute=waitio=change=0;6 k) a) m) k6 `8 E
computeLast=waitioLast=changeLast=0;' @0 |" T- d( z. d( q; X
High_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);) R- W z0 a, _. P
change += exchange_process;% W8 k/ s- l8 D, x% K1 s6 j
return task_completed;
/ c- R" c% G( r1 X# f4 E}
* ]! } ], m) U% z7 r" ~2 lelse
! ?: Y* b! r" Q& z i1 D5 p6 mreturn task_not_completed;) D% V* T. w/ _% N% t9 s" {4 c
}
, L1 v) D, s1 B, A+ P5 tint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)
# E% Z1 h* z4 c/ Q% c; Z) d{
. B+ f2 _. o; C3 } astatic int waitTime[initProcessNum],i=0,j=0;
! C# |: }4 V7 Q" q1 _' w. Istatic double HR_ratio[initProcessNum];2 y* f6 S, M8 O5 s' K/ h
if(flag==0) //初始化数组3 v, W( ]4 x4 m2 ?/ @
{2 Y% y6 V2 K$ C0 m; \) v' H
for(i=0; i<initProcessNum; i++)9 [3 y% m1 |. a/ Z6 T' I3 x% X
{$ u6 u5 n( c" g) J7 M4 J
waitTime=0;/ X8 k y1 l9 \
HR_ratio=1;8 Y; d- c3 k( d. V3 ]3 ^
}" b. E- ]. J- C: w7 ]- {+ P5 e. N
}
5 y5 y' P$ D- P! u; ^for(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比
- D4 M- X; ^1 Q) b S{
1 Y( y5 C/ v8 ?: |# kwaitTime++;$ G( @! S0 q5 u7 O- q
HR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);$ `$ I$ f; B0 e4 k4 z
if(HR_ratio > HR_ratio[j])
& P8 }) x9 T' Y# G0 k& P% f8 `j = i;
+ R/ L' X0 O4 {# I+ W/ p$ K}
0 `. b0 O | `if(dispatch==1) //需要调度一个进程到内存中执行
; ?3 b9 G$ ]6 E4 p' ^{
. d$ K2 p0 V4 D# iif((*storage).p[j].askMemory < *spareMemory)
+ A# o' M/ }: v/ M, y R{
& f5 ?6 K) _2 p) [! G& [+ x(*memory).p[0].askMemory = (*storage).p[j].askMemory;
( z/ P# X* t5 b( [(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;. v4 B1 j9 S! D0 N* \3 }. W
(*memory).p[0].computeNum = (*storage).p[j].computeNum;9 D# N! i% A' i5 \- ~2 N- T0 ^* [
(*memory).p[0].ioNum = (*storage).p[j].ioNum;
3 p8 x! f4 J& `5 p5 i& m(*memory).p[0].processID = (*storage).p[j].processID;/ [& j% A# o- ~0 m
(*memory).p[0].flag = (*storage).p[j].flag;8 a* r* ^' k# ?6 Y& \( l* z2 F/ y
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
: A- _* g+ a% ?# J0 N i+ Y' J8 ?& t(*memory).p[0].computeTime = (*storage).p[j].computeTime;
9 S6 z, M: \" f0 r& J3 N0 R1 `(*memory).p[0].runningTime = systemClock; [% G4 L3 C" R+ d
(*memory).p[0].produceTime = (*storage).p[j].produceTime;
5 U; k2 h8 @, p/ i/ p9 s0 Sfor(i=0; i<(*memory).p[0].ioNum; i++)& S z1 x; A( I9 k' ]
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
: y# U7 @" K8 S: _for(i=0; i<(*memory).p[0].computeNum; i++)
& T7 ] A7 O& ](*memory).p[0].computeClock = (*storage).p[j].computeClock;) R. N/ p& i5 G5 W5 Z7 j7 r( Y
(*memory).proNum=1;: y! W$ L* o0 F7 d a6 e$ n( Z
*spareMemory = *spareMemory - (*memory).p[j].askMemory;0 p0 Y9 G2 z8 f
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
( {# Y% w4 M. i8 g(*storage).p[j].produceTime = systemClock;8 A% v! g) C. |( Y& M! b. Y
MAX_COMING_TIME = (*storage).p[j].comeingTime;
; D- _3 h. p+ x F8 H3 g$ X. BwaitTime[j] = 0;, k. m/ n" q5 N R* o
HR_ratio[j] = 1;
- j* m5 L2 u3 N, M' `" ^# {}
& C5 |" a0 h* m1 ~else
; x3 `/ M. q5 J: j, ]0 l" i& O{0 w" b% W( o9 p8 k* Q. F" x
printf("A process ask for a memory overed the system capacity\n ");0 b' E& z Q+ j* v' v5 m) _+ Y" J
exit(1);
o' b2 N4 a4 x}4 M# b b. j# A0 [& D* f" `) i
}
5 ?) f0 X; x F' }return 0;1 v1 P/ w% l2 j$ w- T' F
}3 f, w1 O! t; E9 t) s
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw). y! Y2 a; ]# A+ r8 u
{
8 p6 q8 P, v2 y7 D0 B1 X( z$ M+ ^( G% lstatic int compute=0,waitio=0,change=0;
Y0 a: ~4 Z: \, [static int computeLast=0,waitioLast=0,changeLast=0;8 V j8 r7 b5 M+ W% l; d$ l
int i=0;
' E8 S% Z1 A1 V$ b" R ^if(draw==1)
* a+ j0 f& B4 Q& X, V{4 Q9 T; {" E( s
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
( J8 P7 z; p$ G& B) BdrawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
# W$ N! V! |4 C
- z! d. B* Z; R4 |5 I9 Y" R" w7 f4 Z
computeLast=compute;
5 N8 [) m8 M5 J( x! V1 a9 uwaitioLast=waitio;# K5 {* C* y. \( D+ Z) w
changeLast=change;9 h. f8 W. Z7 L2 L F0 g
}
5 w x/ U% Y6 a+ @" Sif((* memory).p[0].flag==ready): q$ \' Y W+ `- d0 v X1 m
(* memory).p[0].flag=computing;
, D: z" r4 b7 E9 y, vif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)$ C5 o {/ v# ]1 x! A3 v
{
) c v* B; p, j P$ Wi=(*memory).p[0].computeNum;
. c0 ?/ r s* Y& aif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed/ `; Q6 _) \9 x: [- | V
{5 h4 t2 @' F4 G: ^* V
(*memory).p[0].flag=IO_waiting;
3 P2 V2 d( _$ t+ w( a(*memory).p[0].computeNum--;3 A" X6 M6 F3 V6 v' n
change += exchange_IO_Compute;
7 ?0 a2 S4 `( Y/ G2 O! S8 ^compute++;' o! [4 G; f7 c% D& A, M% U
}/ {# T8 G: I% q* j' G$ {
else$ u& W o8 j1 |; D/ O" |# J) ]$ V
{5 ^! }, q5 ?+ e
compute++;
2 ]/ C9 @# M% k; _$ ^}- H8 `& U, y# f/ |2 M6 N
}# G$ d, a: u I( \ V, c+ g
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)- u, P; z) u5 g) M$ ^7 S
{
0 i+ `9 L& W! ?& _6 ?; V
L, U% e! E# Y' Q+ K9 `+ b! g6 y8 Ji=(*memory).p[0].ioNum;
& k* t& J% P, {if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed5 {& T0 w. U7 A/ l
{' j! t* ?/ j3 B
(*memory).p[0].flag=computing;
# K( D- `& x3 d. z6 t* I(*memory).p[0].ioNum--;
% Q; t3 \5 s9 S* Q. ]! ]$ ochange += exchange_IO_Compute;
/ q/ _- Q- {" |. ]waitio++;
4 p" W- ^+ J u9 @, I( E} \) U( P* i+ I
else
' \; h5 m0 l& O: B% ]; ^{
( g! R" G3 X* r, l! Iwaitio++;
. A; P2 }6 d5 z2 y0 K}2 @+ K# a; R- }9 _! S+ T
}
( h2 e! T' h- w5 d" G9 x# x: U4 q4 delse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)3 e1 s: y' y5 c9 G
{$ u& J6 B s. b$ c% ~$ Z
(* memory).p[0].flag=IO_waiting;
4 [( n0 }. ]/ |: t7 H4 b- [change += exchange_IO_Compute;
! D) Z: P# C6 ^$ G) ^) x, C; _}
! y, b5 |6 U# U+ f# U+ P2 k' Jelse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
) P+ @6 A: T% A; v# j' _ Q{
, |3 s5 s. q2 C(* memory).p[0].flag=computing;; K% X6 M2 o5 v$ p( U0 s* V
change += exchange_IO_Compute; g2 p: n# O6 |* e
}
, e2 @8 O# I& _+ k9 G" o, Uif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成" N9 @4 U% `" I7 l9 {
{
; ~# c+ X' | \, b: w- i" D7 z(*save) = (PCI*)malloc(sizeof(PCI));
: d0 `9 f+ \) _$ f) T/ u(*save)->next = NULL;; m; l g2 X5 f& Y `
(*save)->processID = (*memory).p[0].processID;) x1 F. ~, V5 E5 ?" F
(*save)->comeingTime = (*memory).p[0].produceTime;
% ^8 U* `4 ]: i0 J$ U; m8 M; N6 m( V(*save)->askMemory = (*memory).p[0].askMemory;
* m- f7 q" f1 o( u(*save)->compute = compute;! ~" ~: h0 a+ W) h" m& j3 k2 o& o
(*save)->waitio = waitio;1 P, g. S. G& E- v: k
(*save)->exchange = change;
$ h( L7 ~8 z, ]/ w i) V(*save)->completedTime = systemClock;
# ?" Y2 D* C) Z* v, m( y& L(*save)->runningTime = (*memory).p[0].runningTime;
6 C- I- E+ M5 r6 g*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;
6 a" z% [& f1 C, J1 Gcompute=waitio=change=0;
6 L4 B4 P2 u' Q0 EcomputeLast=waitioLast=changeLast=0;7 j. x( E9 H" J. Y3 E
Priority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
! u9 l( D' C+ N8 e' tchange += exchange_process;
) M" ?$ u+ M3 Q: lreturn task_completed;8 Z$ Q2 b) d3 s+ h# v. x" [7 k
}
' @0 G" @1 ]+ [ N& `3 lelse
! n. z' P( t7 E1 m2 u' p- q. qreturn task_not_completed;
! a1 b! O' x' x S. y} w+ A& y P- Q7 A7 f& M
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory): I$ j% ], H/ b
{
; h) e8 O' W/ E# Sint priorityNum[initProcessNum],i=0,j=0;
% ?0 u0 [% c; T$ O5 a. o; Xdouble temp=0;
7 L6 w4 [$ [5 B5 _- |for(i=0; i<(*storage).proNum; i++) // setting priority to each process4 M1 L/ E: l1 m( |
{8 x0 |. k: D# R) e% A
temp = (*storage).p.computeTime/(*storage).p.ioTime;- L' W' t' c3 Y( g& Z
if(temp > 0.8)
; G' H" N- L ppriorityNum = 6;( b5 _# s# \. k# p: p: p: {
else if(temp > 0.7)' t4 H- v! n. s1 c( i, m- V
priorityNum = 5;9 Y! e6 V: N% y6 \
else if(temp > 0.6)
N) T4 |' r4 Q/ y: KpriorityNum = 4;) i1 @3 J- ?5 i0 h: Y+ E* p p
else if(temp > 0.5)
$ B1 I6 m1 g1 l$ ypriorityNum = 3;
' S; W! }" p2 }* h, g: Oelse if(temp > 0.4)% J4 q& w V0 r3 t- g: e0 [
priorityNum = 2;
+ g2 E4 u' w, F% J8 C7 v' X D/ B5 relse
( Q4 F3 l, i* kpriorityNum = 1;+ b! T7 C) A' g( z5 Z
if(priorityNum[j] < priorityNum)
5 q( ~3 V8 a& }, h% j% a+ u1 Lj = i;: o, I u t( g9 T) T
}
0 \% ?) \; d' j% |1 Bif((*storage).p[j].askMemory < *spareMemory)
1 x. r% x. Z; B2 l8 j7 B{
0 H$ O5 S. ]1 n3 P- A(*memory).p[0].askMemory = (*storage).p[j].askMemory;
: h4 _1 F, v1 A/ E3 }) {(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
3 m; O; V8 C+ H9 `! i& x7 f(*memory).p[0].computeNum = (*storage).p[j].computeNum;
6 |# ]5 m# Q6 |8 Q4 T% I ~# P& \' s) E7 w(*memory).p[0].ioNum = (*storage).p[j].ioNum;
- F. \6 H6 }( `; t3 a2 c(*memory).p[0].processID = (*storage).p[j].processID;$ s& Y" `0 m0 N6 P. s; t% U" k
(*memory).p[0].flag = (*storage).p[j].flag;
* b' g0 c+ ~' X* p6 a: p, G, B; F# p(*memory).p[0].ioTime = (*storage).p[j].ioTime;1 R% c6 m4 V0 P+ s. y3 W
(*memory).p[0].computeTime = (*storage).p[j].computeTime;
$ K+ _% m2 T; ^(*memory).p[0].runningTime = systemClock;' [. J# A7 W; k* v+ _- ^3 B
(*memory).p[0].produceTime = (*storage).p[j].produceTime;
( I- f) } X: r" T2 [6 ^4 a7 ifor(i=0; i<(*memory).p[0].ioNum; i++)
8 a$ Q7 D: C7 b(*memory).p[0].ioClock = (*storage).p[j].ioClock;' Y0 a# v, U- i/ \
for(i=0; i<(*memory).p[0].computeNum; i++)" K+ e1 j% x J
(*memory).p[0].computeClock = (*storage).p[j].computeClock;8 b( Z; c, ?4 g. A; J
(*memory).proNum=1;, ^! o, b5 t6 F6 K
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
* a v" ~3 P# sproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程( t4 \. }" L5 ~9 e" |& v4 m
MAX_COMING_TIME = (*storage).p[j].comeingTime;2 Z! N7 Q( V' U; Z
}
3 T b! f& X, H- \! h. S+ Selse
# S# K' B; L, n4 c; T7 @8 s{
8 y! c) }7 M! R/ Hprintf("A process ask for a memory overed the system capacity\n ");% m @, U. u Q1 y4 [4 W. k
exit(1);& H0 v @1 R+ V, F7 o$ ]2 J
}# Q5 X5 O; q% m! e* O) p' e& e
return 0;
5 {" Z+ Y! N' y3 [* h}
* ] x8 e6 B4 r% q2 p& b) Bint ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw). \5 D7 T$ b0 n1 [
{% Y7 u9 U& Z R* C# t! ^
static int compute=0,waitio=0,change=0;
' S; ]) L; ~) W7 x7 \! s! Fstatic int computeLast=0,waitioLast=0,changeLast=0;# t; V* O, v: E4 W, B) m9 h: r
int i=0;* d l3 r/ p6 \& G
if(draw==1)3 M1 a, o, o' O ?' b/ _
{7 u% N _- g2 D J# q1 {3 y+ G
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
4 R, l7 C8 z5 z9 w; q- u2 U$ ?drawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);5 @5 _% _3 Q6 d7 ]! y
/ ?. V: l \2 M9 {' T
, A& J2 U+ x- o
computeLast=compute;
/ Q% P- _- l# `waitioLast=waitio;' R h# d# `0 u
changeLast=change;
( l1 ?( Z0 v6 q7 T2 X/ I% g}! m0 L5 `9 m* W, H/ V
if((* memory).p[0].flag==ready)& J: y+ g8 Q i S" i1 Q
(* memory).p[0].flag=computing;, N8 P0 e" }: ]. M8 s: k% a M
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
) e5 J0 l* w( |9 [6 v{. D) a- _; D) m, i/ B
i=(*memory).p[0].computeNum;* N5 {: G+ y! s
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
6 R9 h+ F! G4 g{& i7 H$ c4 H) p$ \8 A z; M5 \: E6 u
(*memory).p[0].flag=IO_waiting;& }3 }; o% D1 w2 {
(*memory).p[0].computeNum--;( W6 }" Q3 `0 l- S0 j, L6 n
change += exchange_IO_Compute;
I- I" g+ a( y% g) y8 I3 Z. a# Pcompute++;; c+ q- U& P2 k/ a# D
}
1 f Z/ `. A y) Pelse' n! `* k& I5 ~4 C
{
$ Y! N. ]& r: u, s3 Scompute++;$ k; \2 M# B$ o! a' z- G* L
}
! k; t6 J7 l1 X8 [% r}
! B/ W$ w- f. v& q melse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
6 F5 h2 F. k2 H! ], o" s F& h3 w" ~ ?{2 L' n7 j! M M+ Q7 }
1 p: @4 O2 E6 U+ T6 si=(*memory).p[0].ioNum;5 f% Z4 r! g; W& U& o
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
' K) X2 V- l8 B& g+ X1 M& O! D7 a{
- g. G; j" L* X, q: c+ D* j(*memory).p[0].flag=computing;
L; U( E+ t3 e X P( F) l(*memory).p[0].ioNum--;
' v" {# @. p' @' S+ g9 i6 u8 I5 Zchange += exchange_IO_Compute;
6 ^4 Q' V1 H- x* e# a6 p( mwaitio++; |, A/ M9 z% g3 G% D1 T" }
}3 t* K( M1 |4 P) L- r
else# e. {% L2 x7 p& K+ x: U
{
% R. @7 d, G+ C0 T' A' pwaitio++;
1 l ^- l s* d3 o# a! d4 H9 J}
* }$ b& }3 Q( R( @4 p, M}5 [% n! q! Q9 R- u5 {5 ?2 Y
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing): L# Y9 a O$ V# ^4 ~( i6 z1 x7 R
{4 X6 n% ]; v$ W( E
(* memory).p[0].flag=IO_waiting;/ u6 w& b0 Y: A- q6 d
change += exchange_IO_Compute;
+ c+ I( q% J1 b+ [- G) Q5 z}6 z. X3 w/ M; m" T7 F$ ~8 U
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
" _: ]+ M/ Z C1 U{
" e+ @+ n, u! |! d(* memory).p[0].flag=computing;( h! _) k3 h/ b; W7 W
change += exchange_IO_Compute;/ V/ g6 m7 \# }9 O
}
+ V, w1 K" W# ?5 ]8 q6 l0 Gif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
9 q6 ?: [" y7 b& U9 T7 H{
7 p: v- A9 C, ]: M3 s0 ]& W(*save) = (PCI*)malloc(sizeof(PCI));
7 H" k/ ]7 m Q! D(*save)->next = NULL;7 x2 Y$ S' v4 E! Z8 o: m) ~
(*save)->processID = (*memory).p[0].processID;
# ~- R7 u6 s. \# d7 b" ~" A: ]! ~(*save)->comeingTime = (*memory).p[0].produceTime;/ A* B" X0 }( b# g/ X* ~6 n$ s
(*save)->askMemory = (*memory).p[0].askMemory;$ L/ J6 a% U. ^" A3 K* s* h
(*save)->compute = compute;
2 t/ K5 U, o; i2 h7 P w(*save)->waitio = waitio;
+ f9 z/ k/ e7 b* H9 v7 r% P8 T(*save)->exchange = change;
0 B& b @; A# s9 `: p) P(*save)->completedTime = systemClock; d' v$ ]% F$ L* X5 n# x
(*save)->runningTime = (*memory).p[0].runningTime;* Y- E. F4 t4 C+ c! ^
*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;
/ e, \# |# T9 c& g& t5 Icompute=waitio=change=0;
. R0 p# c9 v2 t) J# EcomputeLast=waitioLast=changeLast=0;
) \. V6 z+ m8 YSJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));* W! z# {+ K" d5 A2 o
change += exchange_process;
9 c7 U% E4 H+ t, Q* jreturn task_completed;
. f# Q( ~3 U4 f$ | G" N# X; M$ D+ |}5 h7 Y- s' S. t% x0 V5 s$ d
else
* N) U! F+ ^0 O; \$ z& ~return task_not_completed;
: M8 ~; ]0 o) M& y3 e4 s3 P6 O}) o# f( ~! `0 \5 Q7 H* j
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)0 N+ s& Q" X( Y- d
{/ B3 J9 l) G4 O& c* b
int i=0,j=0;
% n4 ~( K- v* C/ cfor(i=1; i<(*storage).proNum; i++)
+ }9 e6 j1 S x- B{
3 y* B- i# B5 O% w9 rif(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))
( E T" o$ O' |* u ]2 ej=i;
9 P' T8 X' H9 J}
k4 }; K$ b1 u; u, D7 gif((*storage).p[j].askMemory > *spareMemory)3 y8 ~' i \* S2 T6 }( K7 S
{( {2 @" R& `0 Q# x5 |
printf("The memory asked is overflowed than the system memory.\n");
- D; J$ t) b: ]& E8 U0 z |exit(0);+ m' d+ w/ Q8 Q' ~+ {; |
}
: V. x8 c" }( {2 Velse
) s% _- w7 [4 Z# H{
# e1 N4 i8 K' k& o8 Z(*memory).p[0].askMemory = (*storage).p[j].askMemory;
$ {3 f: c( @5 y+ H; D% K/ U" d(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
2 p$ H `$ o9 n+ w8 G0 M/ J9 d, Z(*memory).p[0].computeNum = (*storage).p[j].computeNum;
4 x* B9 [; M8 o6 ~6 R6 c; k) _, o(*memory).p[0].ioNum = (*storage).p[j].ioNum;1 j, O9 E2 U6 A( g. M
(*memory).p[0].processID = (*storage).p[j].processID;" j. S, y9 f$ Y' {7 b8 {
(*memory).p[0].flag = (*storage).p[j].flag;
) t z+ g3 d" U4 z! c(*memory).p[0].ioTime = (*storage).p[j].ioTime;. w _7 J' y3 R3 C9 F- b& F
(*memory).p[0].computeTime = (*storage).p[j].computeTime;2 v2 d% H( j ~
(*memory).p[0].runningTime = systemClock;% H7 @' E1 s) m( @1 A1 Z
(*memory).p[0].produceTime = (*storage).p[j].produceTime; [( N+ `: F; P" A
for(i=0; i<(*memory).p[0].ioNum; i++)
5 v/ i B* s$ Y) T9 x& l(*memory).p[0].ioClock = (*storage).p[j].ioClock;/ \% ^8 \8 l" v6 \, m9 j! T
for(i=0; i<(*memory).p[0].computeNum; i++). i4 B* s: V! W) s9 a. B1 f
(*memory).p[0].computeClock = (*storage).p[j].computeClock;
7 T o2 L4 T8 v: f2 `9 ?- h(*memory).proNum=1;" j# L* H# @) H" r4 Q! ? t4 j
*spareMemory = *spareMemory - (*memory).p[j].askMemory;0 i9 ?* _6 Z. m, N* ?
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程- M0 }$ V! Q& }
MAX_COMING_TIME = (*storage).p[j].comeingTime;; u1 {: e$ e" A. P% \/ P# I# |
}
! a7 s0 |- k3 j0 qreturn 0;" b! D% K: y+ E2 F8 m/ T. D
}
0 L; y u7 Q) A' R9 N0 Oint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
1 p7 Q8 g; ~4 ]: m; b) A9 C{
! k8 k3 o$ H2 g' R1 @static int compute=0,waitio=0,change=0,clockSegment=100,poi=0;
0 o( Z' o9 z- T" `static int computeLast=0,waitioLast=0,changeLast=0;
/ I3 R# {, W4 R" [int i=0,j=0,k=0;
+ _. ^9 y2 j. v3 h; Wif((*memory).proNum<=0)
& L7 u8 v1 A! R# |# K5 T( WTimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);& ~( z) d3 g; z$ C0 N$ x9 f1 v6 H9 d
if(draw==1)
7 _0 H+ ?4 j3 e4 x{
+ p# H5 \1 C T//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);2 ?( T! B( X) S
drawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
, C; b$ B- h+ U: o
) [ U1 t. Q, Z# ?. j
8 u1 u3 }7 w9 K% h( c/ c& ]computeLast=compute;$ K, K* d+ |; A {
waitioLast=waitio;3 }- e2 m l' _: W
changeLast=change;8 O# W4 @+ H4 c: M5 D- p
}! C4 o! S3 `7 t" z7 k* {' ?
if(poi>=(* memory).proNum)/ f1 i3 A6 m6 [; Q/ `2 d
poi = 0;
; P6 n/ f2 C5 [ _ ?# `" V4 c( ?if((* memory).p[poi].flag==ready)
2 S6 u* Y3 k. Y; L* G(* memory).p[poi].flag=computing;7 x7 c0 x# A6 w5 q" m7 @
if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)
4 C! _+ s% Q4 S. e0 m7 N{
* ?; ~2 Z) c' G' s9 F& Si=(*memory).p[poi].computeNum;
, X8 F3 T' C& `" k2 H; Tif(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed
; ]9 L+ Z) U# l{
5 y" Z: K0 O, h k(*memory).p[poi].flag=IO_waiting;' ^ I7 G; B/ M6 y! G
(*memory).p[poi].computeNum--;- I9 F2 c2 y; j6 f% |4 g
change += exchange_IO_Compute;
- X' e, u7 ?8 z9 ]3 pcompute++;( \$ a4 K, G% q* h2 \
}
8 H( h, g8 d1 I* K7 @; M7 _& r6 Qelse0 d9 I* g, x+ y8 ?
{) K3 L% U0 M) J' p6 z7 n# f% ?
compute++;( X J/ d: |! q8 G6 M8 f. t
}# a7 E4 f0 Q( Q& W
}
+ r( s. r1 V6 \) M2 Melse if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)6 h' m# M+ i9 v4 Q! [. Z, `2 x, I
{
( h6 Y! y- ~* Q& U5 F: ]$ ]1 H/ o( y9 P" T, C& c) e
i=(*memory).p[poi].ioNum;" O2 k0 H% ^% a" s0 p& i
if(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed: c; g+ T: z# m U
{3 o+ F" H" v, Q5 A. k6 D
(*memory).p[poi].flag=computing;
0 h% E& i& L1 C; W I; k% N(*memory).p[poi].ioNum--;
4 ~' x- n. g2 D ?+ k* ` l' B/ nchange += exchange_IO_Compute;' U5 p: P. y% o. E1 ? }
waitio++; Q# J, C0 L5 P
}9 }# G4 [2 T( F
else
+ n: d# D a+ l: m" R1 _' C{) g% c4 S$ b6 e! n
waitio++;
? b( e7 i+ X! C}( n/ Y: p8 F2 X; j% ~
}5 D+ o5 q' \% ]
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing)/ U; ~% M1 n( }- I
{" {) j. N# u) {2 o8 `
(* memory).p[poi].flag=IO_waiting;
( \/ R5 B" I" c) }. E+ H0 g3 j/ R0 ychange += exchange_IO_Compute;
8 K( q! k; \& v9 M7 y}
2 a: R$ F$ O. ^& |; {' Velse if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)
7 J. i; i! F+ m9 e8 I7 x1 T Q{1 P2 k3 O" n0 R2 G$ L7 v
(* memory).p[poi].flag=computing;
[& Z' R. \% M8 schange += exchange_IO_Compute;, s7 Z% R9 r- L7 I
}7 G6 l6 Z. g; U3 E; d
for(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进
. C3 {# ~; k- T$ o2 X{
8 q2 ~! B4 _* X6 qif(i!=poi && (*memory).p.flag==IO_waiting)5 ~" i* ?6 J3 k
{
9 y( e! h0 s3 _4 {j=(*memory).p.ioNum;) G+ M: @, R; B9 d9 Z7 R
if(j>0)
+ W( i1 q j$ P% m' Z/ w$ W{
! G5 d; I- ~) W% H" h- Pif(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed' q" m* \! ~6 v% m N
{
; }9 W/ g+ \4 h/ o( U1 q L l(*memory).p.flag=computing;
" a1 J% ` j' n9 \2 }4 v(*memory).p.ioNum--;! ] f1 k6 R' i* z2 Q
change += exchange_IO_Compute;
/ y) e# D9 O! Y3 N/ U0 P+ E7 x}! u% l" U5 |& u& a0 s3 o2 ?
}6 [/ \( {0 ^# \. k! p& t7 i
}, y" a2 A+ K" l0 }! _* _
}
4 g# s1 ]2 B- \% T6 Ofor(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程' U U" L# L& r( G
{ V- i7 ~' ?1 J$ X
if((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed% [, _+ h% o0 U! _) t) L
{
" @0 b/ k" Q1 S; m% j6 Y' V(*save) = (PCI*)malloc(sizeof(PCI));
0 Q$ {8 b+ j: S# S% O X(*save)->next = NULL;& b' i: t/ l: {( f( _
(*save)->processID = (*memory).p.processID;
& c* [: b9 N$ ^& N9 v(*save)->comeingTime = (*memory).p.produceTime;# R2 z: v/ ^: g
(*save)->askMemory = (*memory).p.askMemory;
$ z ]+ r) G. X+ e* x' E* [(*save)->compute = compute;; A4 p% k4 j; }! S! T+ a
(*save)->waitio = waitio;# g: K% B# M, N* V. R- z( H
(*save)->exchange = change;
# f9 f9 J' }; \- Y3 G" }# l* w(*save)->completedTime = systemClock-(*save)->comeingTime;; _8 } U# N' L0 D2 o
(*save)->runningTime = (*memory).p.runningTime;
3 R" H2 [" |. D* T. f$ q3 m- O(*save)->completedTime = systemClock;
9 ]# m, Z& d N- \*spareMemory = *spareMemory + (*memory).p.askMemory;
% m2 Q S5 O' A( Zcompute=waitio=change=0;$ Y0 {) I+ |/ b0 k! w
computeLast=waitioLast=changeLast=0;& {) n( U# P0 a/ ?: d& I
if(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入6 M+ m8 K# ~% D W/ y1 z$ G+ x
{, g' X1 M: E2 I" G1 ]
if(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程
) u1 o5 x- s" O{/ A' W; W7 N1 l/ P3 C# O0 J3 J- D
poi++;: r3 l! n) r" X
clockSegment=2000;0 T9 ]* \; s. t* x# N: H
}# e& N6 V. a% S4 k1 J2 l
}% B; Z# [' y4 E' q4 Y# {: ^
else //没有足够内存调入新进程) {" {4 H+ D+ Q1 g
{' Y1 X+ a0 I3 Y7 L, {
if(i < (*memory).proNum-1)
7 K% ?4 H7 b; x+ t{1 W* S% v ^. {" A2 ^/ ?1 n
for(j=i; j+1<(*memory).proNum; j++)
; D9 h* o& _& r& j{
: X4 h5 O( u% e7 V/ H, J(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;3 `0 e/ m! y5 q4 U1 O. t9 _3 V
(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;9 S E, J F2 x% B
(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;
9 }9 s- V. ~, q- R3 j$ o(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;
2 ]# y, K7 A1 ^4 b0 O(*memory).p[j].processID = (*memory).p[j+1].processID;
5 P) n6 Y, m! H/ H(*memory).p[j].flag = (*memory).p[j+1].flag;
' t6 }* |& P0 K1 ?* h(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;
8 w$ j9 J0 s! f9 O# m- X(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;
; e0 R2 P- b& ]: e3 u( g(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;
& A5 n8 U# v1 a4 w. S) p. I(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;
# ] N' p' W- E/ ]( ~; |(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;
, A3 h$ r* A! Z# t1 y# d% Z: F$ p pfor(k=0; k<(*memory).p[j].computeNum; k++)0 E% W( v1 d8 E4 M7 y+ J1 E t! n
(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];
, O( N: b' U- H. p, o- Wfor(k=0; k<(*memory).p[j].ioNum; k++)
7 c4 D0 G* s( D( w. G2 o+ A: o(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];' m! C1 q$ M" H+ r& J
}. T% Z$ O8 \! M
if(i<poi)) I6 M8 a; E% `: I U- Q
poi--;0 x- f# x" P4 l/ I6 p$ M
else if(i==poi)
: \" p C. d/ _1 H# i- L- m2 r) lclockSegment=2000;8 g3 w) a9 M" p a
}
' Y' Z3 K9 i; n; bi--;
' i9 m; z( \& \% X, d(*memory).proNum--;
4 b& F" O9 ]( q" k" F}/ Q8 Y0 M. i; ]$ a5 v* s, P
return task_completed;
( m- f* a2 L" k; O6 K' T' X: g$ o}
- T+ l+ x- M- b}
/ W$ K# D7 Q1 k5 a4 t--clockSegment;6 Z1 |9 b( T9 ^. w Q
if(clockSegment<=0). j) F7 U2 h( l2 h4 k/ V; c: }( \
{- @) j' d+ r8 l* [* L& {3 D
poi=poi+1;8 h6 V9 o7 }: ]1 ~, }
if(poi>=(*memory).proNum)
. L/ Z3 ~' K: z) Zpoi=0;& W2 f# w. V! C4 g
clockSegment=100;
6 g8 t" `/ {. g* M}! T. x! \. M6 [/ q
return task_not_completed;+ z3 W+ x3 I- d' n/ E4 O" V
}/ P5 p+ i, A7 E" @9 |
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)
8 n) T2 d; I& [* C" o( T, ~{
0 N6 f4 P7 @# j; f, y! k0 @# aint i=0,j=0,k=0,flag=0,translation=0;
2 }$ v# |8 c7 Q( p1 K& p& zfor(i=0; i<(*storage).proNum; i++)
; T( i6 X8 i' _" \, ?' d{* h8 |% c9 X* r. H8 g% D
if((*storage).p.comeingTime>MAX_COMING_TIME)
! H! X3 {9 F: xMAX_COMING_TIME = (*storage).p.comeingTime;
, a- M' C+ Y( g7 g5 Q# @}4 M! e3 }1 L. | U3 q" S
if(pos>=0)) `, e3 u: `6 c8 V, z# w' b
{/ [1 R8 o2 w3 _7 _3 m
for(i=0; i<(*storage).proNum; i++)
3 m! D6 U/ @$ ]1 x{/ R' s1 c& o$ j+ Y
if((*storage).p.askMemory <= *spareMemory)
" e: I8 D* e3 G9 M{: @6 d9 x Z) \, |/ |8 q6 ]/ G A# W
j=pos;
; A) V- `! f% j& Q(*memory).p[j].askMemory = (*storage).p.askMemory;
# U) Z1 U6 g8 A" Y4 v9 S+ G(*memory).p[j].comeingTime = (*storage).p.comeingTime;
( ^3 S; ^4 d3 d, y5 a2 @6 G; Q$ _5 g. M(*memory).p[j].computeNum = (*storage).p.computeNum;
$ }) H6 U5 Q' b7 ]+ b9 J, `5 }(*memory).p[j].ioNum = (*storage).p.ioNum;' \( P7 o9 |4 q: {) X# O: J
(*memory).p[j].processID = (*storage).p.processID;
& m) n( v: c/ K8 o& y* l(*memory).p[j].flag = (*storage).p.flag;
3 f+ |9 q/ v8 m5 H* f0 R- m, i(*memory).p[j].ioTime = (*storage).p.ioTime;
2 w% r) V" U4 y9 K# Y(*memory).p[j].computeTime = (*storage).p.computeTime;
5 Q' f0 I: ^0 ^* ]- H(*memory).p[j].runningTime = systemClock;
4 @! u& L, \4 K" c1 f(*memory).p[j].produceTime = (*storage).p.produceTime;
& N$ E# F. P0 ?! i0 W$ ~for(k=0; k<(*memory).p[j].ioNum; k++)
' F7 T, d, @2 k0 L6 K. ]* t, v(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];1 k a- X6 m' ?& O, W9 V: o0 e" u( {
for(k=0; k<(*memory).p[j].computeNum; k++), Q7 q" E" l4 i, s0 F4 N- a, Q4 ~0 K" A
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
$ Z$ O* w% M# D0 G' A5 s! J*spareMemory = *spareMemory - (*memory).p[j].askMemory;
/ U7 g6 F$ N; Eproduce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程2 U! B; k. _) z$ @8 C* J* E2 }& f- [
MAX_COMING_TIME = (*storage).p.comeingTime;
! R8 g0 D* r. V* ?8 E" v4 qtranslation=1;2 {% g, e1 {- b [9 N
break;
t7 _6 K, O$ `4 ~}- h% _' T! n; v. N9 M
}# @4 F" B3 J5 b5 a
}, a" ~9 {! Y: R$ M1 r2 `
else
: W' ~4 [* p$ J9 C$ z{7 D: ]( O* m* m- i+ U3 T
while(1)" x d' L7 i4 @, b# P8 R Z
{
# }) Q4 o; |' j& uflag=0;( [" j& \% x5 L# q
for(i=0; i<(*storage).proNum; i++)+ i: K& l% i+ M6 {% [
{
8 L0 u8 q0 t% S/ [) Mif((*storage).p.askMemory <= *spareMemory)
7 I9 s4 s/ _: Z+ Z& d& j{
( T6 H; @' {5 ]; H' o9 s( Vj=(*memory).proNum;
3 s1 a+ x4 X- J6 C0 x8 t(*memory).p[j].askMemory = (*storage).p.askMemory;) v9 z3 a6 d' N( x1 t" X6 W
(*memory).p[j].comeingTime = (*storage).p.comeingTime;
0 k8 {4 q' ^) z% J$ a5 O' F(*memory).p[j].computeNum = (*storage).p.computeNum;
( ?. K8 @2 Q) x U$ r7 S) x(*memory).p[j].ioNum = (*storage).p.ioNum;
1 Y( q$ i6 x% f0 C: x(*memory).p[j].processID = (*storage).p.processID;
: |: ^ d; S1 r+ J, s' P(*memory).p[j].flag = (*storage).p.flag;
; V8 n( o9 e ^& S9 n- W(*memory).p[j].ioTime = (*storage).p.ioTime;5 a- O; S9 ]* w. \; _$ {
(*memory).p[j].computeTime = (*storage).p.computeTime;
$ q2 m8 v% m% ](*memory).p[j].runningTime = systemClock;. g4 d& M& b: v4 ?
(*memory).p[j].produceTime = (*storage).p.produceTime;
4 f T9 {9 z9 _" ?( r$ Afor(k=0; k<(*memory).p[j].ioNum; k++)
0 M1 W+ J& g+ ]* C! O(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
/ ~+ z( ]3 V! c7 Zfor(k=0; k<(*memory).p[j].computeNum; k++)
( T! T" F* z; \0 u7 R Q1 F8 O(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];, F* X: O& t* q7 h8 k) ]1 W: H/ K
(*memory).proNum++;5 [# P2 T4 \# I( c
*spareMemory = *spareMemory - (*memory).p[j].askMemory;& G9 c m$ p% Z' Q. {
produce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程2 F/ }, W- T8 v. a0 ^
MAX_COMING_TIME = (*storage).p.comeingTime;
: s. Z/ k# d! t$ x- |flag=1;2 i( \' C0 o. a5 y. ?
translation=1;1 H3 X+ [9 G |0 h, u
}
0 L w8 E' k' k. [ w: A}
# _ z N, c/ _8 n' O2 {0 F1 @- kif(flag == 0): J' M1 s0 _, Q) e
break;
0 |/ w# u" O' k7 p+ Z) |}
0 U! g( N3 v5 U/ e( \, X1 V}
- L/ a+ a' E' z, W# O9 a4 O* k$ Xreturn translation;
3 h6 `# ]7 E2 I% q* B. ]& M1 W5 P}
$ d4 B7 {! x5 lint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)
+ T: I% b7 U( Q% o L{* ^; ?; @: [$ H: d6 G$ H b
static int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;$ z5 }- |1 _8 C, \$ k
static int computeLast=0,waitioLast=0,changeLast=0;
9 k4 g; P1 }5 F( L- rint i=0;
. @& Y2 v% M3 |! A% nif(draw==1)
Q1 O. G" F; U; C& j{
: r) ~; O* m7 j. m. ]& m( H+ u' F% `//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
1 ?( j4 i {% udrawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);, A. v: e0 E0 R7 A6 E8 k# u
! D3 P2 t" D+ B4 a% h9 X% _! T1 [ a% ?) D( ^/ V$ Y
computeLast=compute;
, A8 ]6 c. }, KwaitioLast=waitio;0 B2 k+ U& ?/ x2 q
changeLast=change;
3 k, d* ^- r' ^3 |5 d' b* ?. C}
. P% Q G! ?; `, W6 cif(flag==1)
: c2 E" {* U* t$ i{
$ |8 ?; G' C% s. h7 w: rif((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed
7 Z0 v0 N! D' R/ E0 X{' e/ m+ p* X& f% \# I% K. p
if(flagiocpt==0) // implement compute) o6 w& H3 ~& W% x! V
{2 k$ p2 m9 t# f6 Z# ^6 D
i=(*memory).p[0].computeNum;9 k7 I' ?; H' P0 M
if(i>0 && (*memory).p[0].computeClock[i-1]>0)
& r! H2 n& }! n{
k) {; @- u2 z' Z& G1 Fif(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed. {* s5 r" ?4 v% w
{
w3 p# l S* o% B' Q8 }. ?flagiocpt = 1;
- o) U1 i+ U# @(*memory).p[0].computeNum--;
# s3 I9 B; j/ ~6 ]3 L1 z' Bchange += exchange_IO_Compute;
8 q+ W1 m, y9 d6 ^# I3 E) V! ccompute++;
% p6 q% E9 z' `3 s}3 J5 p8 h" E4 S" |3 r m" z$ _4 L
else& j# g$ F. V- [2 n$ g
compute++;
" G }# v ?8 s$ b, ^3 H+ j
7 h7 Z4 [, _2 i' ?1 m}$ B% l; D" G! [1 S) X. A. P$ x& _
else3 ]$ A; h5 B. \6 l
flagiocpt = 1;4 ?; @6 w+ I: \1 I
}2 p, ^" \1 K/ _; T2 m9 ?- O
else //wait io
4 a- ?0 g% S6 W( U" L: S{
/ d8 J3 X7 r- _* h$ Ii=(*memory).p[0].ioNum;
+ X1 y2 p5 J8 I h8 h) `) Fif(i>0 && (*memory).p[0].ioClock[i-1]>0)& S% m* x7 o" X) M7 r
{
# ~2 d# e: I0 B! z; |' C" Y5 pif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
^ B) |2 Z% Y% W5 S{1 ~1 @/ C& w% s1 M; h) Z2 n/ q$ j7 n
flagiocpt = 0;4 u$ D- G# Z. ~; |
(*memory).p[0].ioNum--;
0 ]6 J. I5 S# d' c4 c0 rchange += exchange_IO_Compute;
* k) @; E8 D6 h# J3 e: ?5 ^waitio++;
* r$ n( B1 t/ _3 x( B}0 x5 N ]- R1 u# Y C' ]$ R ^" s
else0 s+ o3 P, T2 {$ I z$ i
waitio++;
/ }. Z+ `$ G- Q
; G+ G' F0 i- h7 ]}; l" p/ x7 I- q+ T4 D, {
else. i4 t4 u% P# y5 @! d9 s# }
flagiocpt = 0;5 f4 K; Z) p0 X b6 O4 s
}3 y- O% _! G- e2 ?6 W8 _5 a/ C0 u- A
}
$ w& n7 ?" d5 _; q9 aelse //task is completed; f) e) k7 S3 ^5 J
{
+ a7 a- V9 l* z1 ?- S(*save) = (PCI*)malloc(sizeof(PCI));
% ?8 K1 q6 ?) j3 I9 l(*save)->next = NULL;
/ k% U, I. U* e ]* o0 P7 \1 A/ a* V (*save)->processID = (*memory).p[0].processID;
2 _3 V) @" f! y3 N5 q(*save)->comeingTime = (*memory).p[0].produceTime;
/ c4 ~5 b8 u( r2 k(*save)->askMemory = (*memory).p[0].askMemory;
) a# o" |, a# b/ A) E! Z(*save)->compute = compute;
' m( L6 j0 f9 ]/ P(*save)->waitio = waitio;# s: g+ n7 D# q- W- C. h+ `/ \
(*save)->exchange = change;5 ^+ l% Z$ Z, Z, C& r5 s( ]
(*save)->completedTime = systemClock-(*save)->comeingTime;% C, W+ ?8 c7 D0 e( F4 P/ l
(*save)->runningTime = (*memory).p[0].runningTime;
( V, ]9 S6 ]2 H- O(*save)->completedTime = systemClock;, V* x# ?6 A E* h; y _
//*spareMemory = MAX_MEMORY;
+ C0 m3 X/ N, i. T- j$ I# zfree((*memory).p[0].ioClock);
% P$ q9 E: k! W( Xfree((*memory).p[0].computeClock);
1 F0 f+ j# f- `* |2 {. b. m' x8 e* Dfree((*memory).p);
3 t9 C# }% j) J& T8 Qflag=0;- c% f- l* X+ G' I; B7 R
compute=waitio=change=0;
5 s3 z% w2 e( G$ o' dcomputeLast=waitioLast=changeLast=0;
! y9 P0 B+ U' ireturn task_completed;% t7 f4 ~% Q @" ]# y1 M
}/ v# K( w' U2 E$ o2 I' e
}. N" [! t9 a$ L* L1 P
else 2 I1 S t" M7 q2 F; ^
{
, t9 P7 V$ _- t' D7 nFIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));, A% L+ s% i% }0 S/ Z
change += exchange_process;) F9 N3 }3 t, H' M9 x
//*spareMemory -= (*memory).p[0].askMemory;7 B; A$ Q+ G6 P5 f
flag=1;
" R, y7 B' z# M7 p* B//showProcessInf(*memory);
' I. [ K, g: H! L1 ~. Preturn task_not_completed;
$ e! ?. Y1 T7 J g9 }}
1 H5 B( E* X' f8 n7 jreturn task_not_completed;2 M. H& i0 R: o# A: Z+ k, G
} f/ O# C" c% R ^; U9 J
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)" {+ `" Y0 r8 O% x3 t( f
{( {1 {3 X, q# y# I9 H# s m
int i=0,j=0,k=0;* l/ O0 h# S _
MAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;
, R5 S# @. [0 G7 t$ Y' ~+ k(*memory).p = (process*)malloc(initProcessNum*sizeof(process));
) H" X* `; |1 W6 Omemory->proNum = 1;9 {% h3 k* e/ M4 s2 q2 T
for(i=0; i<initProcessNum; i++)! o6 ?) Y: e1 t5 n4 n* i
{9 I# Q, g& _( E
if((*storage).p.askMemory <= *spareMemory)! Q2 { d- R x6 S2 N
{/ x9 q8 R! @/ f$ t7 d& n
(*memory).p[0].askMemory = (*storage).p.askMemory;. g/ b7 H( z# F' t
(*memory).p[0].comeingTime = (*storage).p.comeingTime;
! H& A; N/ t4 `4 z6 a, j, g(*memory).p[0].computeNum = (*storage).p.computeNum;* M% S8 y {7 W1 k
(*memory).p[0].ioNum = (*storage).p.ioNum;' I6 ~" Z4 J5 Y. o! b
(*memory).p[0].processID = (*storage).p.processID; p, {1 ?2 G. b$ g& E
(*memory).p[0].flag = (*storage).p.flag;
+ c6 Q) ?) f) ^* y3 I/ O(*memory).p[0].ioTime = (*storage).p.ioTime;2 a0 R/ {6 w% ^& c. l
(*memory).p[0].computeTime = (*storage).p.computeTime;; J& {& d* T# B3 Z( f
(*memory).p[0].produceTime = (*storage).p.produceTime;
1 u. X; `* O' k# n, a/ D7 s, r(*memory).p[0].runningTime = systemClock;3 \3 ?8 n# c0 G' T7 l7 q
(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));
% m; E: J3 Y" n+ B/ |- b: P(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));% G0 b" _! W( c; ]- m( e2 f
for(k=0; k<(*memory).p[0].ioNum; k++). J- i, u! W/ F' s6 \
(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];
n+ P- Q: k4 V* }4 f: \& q; afor(k=0; k<(*memory).p[0].computeNum; k++)2 d1 V* [9 U2 T5 a
(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];
, F8 e. F2 ~% e, Z/ U% d' T. p& L6 Dbreak;
9 i2 w- S- x" D, B v8 s( |}
4 n. K K9 k+ \. s1 r}6 Q! [6 [" C' ]" E! V+ y
if(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入
K$ l; F k+ \( Z4 \- u$ x& L{& d R8 c5 E3 `; @
produce_one_task(storage,i,ID_FIFO++);% y+ [/ u- _& K- F/ m
MAX_COMING_TIME = (*storage).p.comeingTime;
! V" E0 x6 [6 zsort_by_comingtime(storage,i);
9 r2 @2 b1 `3 P! i" ]}
3 R9 g! I ` a+ {return 0;
, M K+ y: W7 E6 M; N$ t}3 S8 H& ?0 r! N9 i2 f- o2 c
int sort_by_comingtime(processPool * p,int pos)
7 z* S+ r: ]9 W" K. z{
/ v1 R% [* n% u; \' Lint i=0,j=0;
# b& Z2 [& l5 q& Sprocess temp;4 B/ Y# K; g3 G( ^/ X
if(pos<0)
$ ]9 G( I7 L6 G6 N{# O6 k7 [( M7 ^* W1 [
for(i=0; i<initProcessNum; i++)5 [. b4 j) ], X9 P9 f0 d% ?
for(j=0; j+1<initProcessNum-i; j++)' \, ~' f' d! q6 ^! \0 o
{
" Z1 l+ e! {. q! H2 y! }# |# {if((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)
. m4 y1 ~/ Z u. j$ M$ a: W0 ]{# [0 P& y+ j7 U* ^$ `2 b' Y2 Q% l4 B
temp = (*p).p[j];
4 _, o# u4 j9 z! k1 v(*p).p[j] = (*p).p[j+1];
/ R3 F# b+ j( C9 q4 f' E(*p).p[j+1] = temp;
+ w# n$ b2 `0 `}
0 o. m; [! _2 n# r) B9 ~}) b2 i8 O; ^( V4 n6 e
}* `9 v( ~( W5 S# K
else if(pos<initProcessNum)! l5 R$ Y% v( h9 z: ^# `9 F
{4 K: J- l1 g% Z% [! a" I
for(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)
- q) a$ C, Z; h4 U3 P+ j- q2 M/ h{
0 l7 @8 M. W' |& G2 w( w& Atemp = (*p).p;
. X) i# s' D6 ~6 _* M( I(*p).p = (*p).p[i+1];) T, W7 q2 x* _' |1 x% y* b' K4 a
(*p).p[i+1] = temp;; m7 K% ^& a; @) X% [9 |. X& p, Y
}
% E( Q4 s! i" ^: n# v% wfor(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)
8 ?5 K4 V4 n0 h& Y{! q ?5 E* R2 A" p7 G3 F
temp = (*p).p[i-1];4 j l4 A' _4 r% Y& e
(*p).p[i-1] = (*p).p;
6 O5 _. b/ c) p(*p).p = temp;
$ X6 p8 J ]' T2 b$ p' N$ t}
: w$ g! l* H, d! N- ?( v1 F' y}* U! p0 ?: X2 R9 |/ C0 S5 V
else
' ?% A2 r$ I8 w; J. Qprintf("position eror\n");
4 m; k% h9 I" E) ]return 0;7 u g/ U2 I4 E
}
! Z/ W$ ^+ E+ R5 V& D5 [! @+ s0 d& \7 Nint InitPool(processPool * p)/ |9 {: i+ J8 o9 h
{# l1 j k+ Q% |, C4 A3 y: D
int i=0;9 L, H( q2 _( }
(*p).proNum = initProcessNum;
# v# P/ [2 i7 e! @' \(*p).p = (process*)malloc(initProcessNum*sizeof(process));' L% [. J$ e) p1 y- r& t6 L
for(i=0; i<initProcessNum; i++) //init process information
3 d/ u; Q* u O& b- i3 a{
3 n7 q2 |; ]% p( e# v2 ]+ a(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));# ~/ H/ `6 Y! C6 I* I' p
(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));
& i2 C$ {+ j8 }; rproduce_one_task(&(*p),i,ID_FIFO++);
7 T$ S" l# I; p& ?}
7 \7 d# n; K! O9 k$ Rreturn 0;
1 b5 V) y0 K& a1 c# O}
5 S+ ` r) y% G) _1 R5 K1 t3 @int produce_one_task(processPool * p,int i,int id)' b- k* [- g+ ^5 R* {* q
{. U: g: d( ~& n$ X, E/ p! f
int time=MAX_COMING_TIME,j=0,totallTime=0;
/ o* \7 b ?8 c: T$ s0 f(*p).p.processID = initProcessID+id; & U; Q6 E0 u% h
(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);: q0 w6 s9 ?2 ~4 \; W8 V+ G
(*p).p.produceTime = systemClock;
4 S* A3 }$ W: o$ M* u(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;7 }# a! G6 _) v; T; z
(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6;0 _( X6 v' B" ~- s( i
totallTime = (*p).p.computeNum + (*p).p.ioNum;! G& j6 i0 N7 R3 Q- S5 m4 S+ Z
(*p).p.computeTime=0;
2 @6 a! p5 n* G7 l6 ]5 y. kfor(j=0; j<(*p).p.computeNum; j++)4 L" ~4 N( ]4 o2 _! v
{! `4 f- ]9 E+ u: Y; ?( C0 u
(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;
) W; b* `, G1 W9 m/ i. k(*p).p.computeTime += (*p).p.computeClock[j];
# n/ l7 |" h) }" a}
" y2 h) \, t7 D9 p; m# ~(*p).p.ioTime=0;7 b8 d5 j6 c1 Q+ W( [; V( @( U
for(j=0; j<(*p).p.ioNum; j++)
3 Z# ~2 Y" b; E" z{
8 q5 p! B; b/ M0 _* H(*p).p.ioClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;
8 `$ b; D& S! i+ Q! }% d6 P(*p).p.ioTime += (*p).p.ioClock[j];
: Y3 i9 q) \$ R1 E}
1 V8 I! q0 Q/ S(*p).p.askMemory = rand()%(MAX_MEMORY/4);, y! w6 X' z Z9 `
(*p).p.flag = ready;
4 I' ^7 X+ {6 u: j/ _* h/ preturn 0;5 R7 b9 e1 Z* U8 K& y# l
}8 @, _7 K6 v: f( f& v
int showProcessInf(processPool p)! f9 E- U) U7 P! `- a5 b
{/ a3 g, O' H7 z( }) A9 [
int i=0,j=0;9 \: M/ S3 `- D$ D8 I, i
for(i=0;i<p.proNum;i++)
8 A, l" k8 M2 `2 s# ]{4 G5 k3 P! k; u/ i8 t* i) [: m" |
printf("ID:%d,%d,%d,%d,%d,%d,%d\n",p.p.processID,p.p.comeingTime,p.p.ioNum,p.p.computeNum,p.p.ioTime,p.p.computeTime" P" N, k: F. ?( \
,p.p.askMemory);
/ A: u2 L2 q! n1 e. Afor(j=0;j<p.p.ioNum;j++)
( ]0 d( S7 j) \5 @( ^ s{' y; G3 N" H7 a
printf("%d ",p.p.ioClock[j]);