数学建模社区-数学中国

标题: 经典任务调度算法的模拟程序 [打印本页]

作者: 杨利霞    时间: 2021-4-9 15:15
标题: 经典任务调度算法的模拟程序

1 A& \) ]4 U7 E+ m. c) o经典任务调度算法的模拟程序, _$ i& o" v' k- B: p
本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。4 {0 }0 @9 O7 ^

6 i; V  Y7 Q6 ~; D1 m编程平台:VC6.0+EasyX图形库环境。
" {- N4 f2 f/ W3 ^+ x1 d6 o  g
9 j1 R. h: H& ^* c- d% y以下截取部分程序运行图::- i6 _$ X$ q' ?" G; ?1 X, j
; ]* [0 C* H/ T8 r0 z- M6 d$ x
源代码:( ~6 v! Q8 z0 ^5 h6 ~4 E# V
  c. E* t- n3 W
#include<stdio.h>
( U5 b; K+ V$ v7 f% t#include<stdlib.h>$ t, e, s6 V* E6 z, E
#include<easyx.h>
0 P* B: G9 {9 ^& \#include<time.h>
/ p4 a2 ~, `8 {4 A  Y) @#include<conio.h># g& G+ _# E/ Z; J0 B( {8 X
#include<graphics.h>
9 u8 o+ r/ B! h; R, A, h/ t#define initProcessNum 10
& H: R3 S. K* D. d4 |7 c#define initProcessID 1000
- z6 H4 o# N/ j#define MAXProcessRunTime 10000
* _3 g: F, X1 U6 h! B/ @#define MAX_MEMORY  4000" O0 Y; }6 n$ ^7 i; k9 S( J
#define exchange_IO_Compute 10
- [8 S+ a2 s. r; D! @( f#define exchange_process 25) n& p2 M/ d6 Q: ^1 F
#define task_completed 1
. O8 L3 o# @) Z# I' v! z#define task_not_completed 0' ]7 l$ r: `% b/ O' f7 i
#define initclocknum 100
9 V+ O- b- l, u) ~) v* Uenum condition: \: U; B* ]9 ?
{. r" w5 s% [8 m
dead,computing,IO_waiting,ready
0 r- ~* I8 F$ ^% C- |* M+ k# W};1 e! O9 e' U$ K8 g$ D
struct process( Q: U8 \  @4 O  A7 ~7 `: Q0 j
{
8 ^8 E: z* _9 c2 Oint processID;
& r. v2 X% v8 Dint comeingTime;& F  q- L* N: ]! Q/ K
int ioNum;
9 w4 k5 _, T! m! zint computeNum;6 D- l; I6 R% M. a9 y
int * ioClock;
, I4 N+ D2 M' g, uint * computeClock;
8 {: l( Y2 E" V! K2 w" x+ l+ {2 Tint ioTime;
) A2 F4 V- }7 h7 U0 C+ `  [9 hint computeTime;$ P& q7 Z; W; D8 V, o2 d
int askMemory;; ]  q) Q  O( W3 z6 ]( ~8 X; [: X- |# h
condition flag;
7 T8 i( _: O! l! C# Y+ S( [/ {/ Mint produceTime;  //生成时间,以下三个数据成员用以计算相关性能5 Y9 k4 s/ [; l* i# z+ F) O* Y6 Z
int runningTime;  //第一次占用CPU的时间
  A: T, d$ N* x8 M+ @. y3 uint completedTime; //进程完成时的时间7 ~3 N& K, o- E* b5 i" K3 w
};
! r) l* i& x- o  ]* U# Btypedef struct processCmpletedInfo  //保存完成一个作业的相关信息
5 S' ?8 r. R2 P- M( g, N$ H{( X4 b% F& X' M& y! M/ S
int processID,comeingTime,askMemory;
9 D9 ?) f; U3 s  h5 ^int compute,waitio,exchange,completedTime,runningTime;! X" v/ p) b3 d
processCmpletedInfo * next;9 f" V: W0 n- k# K/ V6 F4 M
}PCI;
0 B5 A; j% b# @: v! j* W/ `struct processPool" ^1 c" M) e9 m
{
4 f$ E# w; x2 Aprocess * p;# S& E6 P4 v( \* @& @
int proNum;; A$ G" b( h2 @
};7 Z) S2 p5 s6 T' ^( `0 P, ^- s
int 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;1 v) X4 W5 c) u) |( T0 `
int InitPool(processPool * p);! V0 ~& z2 k6 ^) l. V# C
int produce_one_task(processPool * p,int i,int id);1 r8 M* m7 q: ?: P/ ^* {
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);
5 h3 y7 t3 E8 f8 G% dint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
- k( ~/ a' h7 Jint TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);
& A9 d% w' Z0 q) M! |int FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
6 O! C0 y+ P! j: P* \! kint ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
" O0 p! R$ Q2 `  ^9 y5 uint SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);$ p' ~7 L3 Y) M$ ~
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
+ [" [9 Q) ^3 m7 {( Gint Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
0 w/ v% z; P2 @: u5 B9 i8 q+ Mint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);8 ~3 \+ J4 t4 u; V" r2 t! q
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);" E7 W; v' g5 t+ A: v% L9 w' F) l

# s+ G$ S8 e# S: z! w
" O+ M  U3 [6 K+ qint sort_by_comingtime(processPool * p,int pos);
4 G( e- D& X9 P  h# X, [: L% g) Nint showProcessInf(processPool p);, {* B" Z" h& r, _8 V( Q- q
int drawPerformance_FIFO(int x,int y,int memorry);' Y3 f: f+ [) U3 B& E2 C5 ~
int drawPerformance_HR(int x,int y,int memorry);
# c5 q) `# t; y( Uint drawPerformance_PF(int x,int y,int memorry);* z0 i+ s# w* S% v
int drawPerformance_TT(int x,int y,int memorry);2 h1 s: I' e) a# E: u' d( a
int drawPerformance_SJF(int x,int y,int memorry);2 q" h: ]8 V, x/ e5 @' J7 ?7 s1 V  v
int MouseListening();# G8 e- h& _3 V9 Z
int MouseListening2(int *flagShow,int * showTime);7 G5 T) Z9 M0 p& r
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);
8 P2 U5 c; t6 l  C. ~! |' e' O" n" G% o3 }- Y3 A8 u& w/ p
2 f3 Z# J6 N4 x8 j) W, |6 o
void main()# Q  R! v( H1 @  v# n
{$ p) \0 `% K3 ]
PCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,- ]# S/ \3 [& j7 H( Z$ N
*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;
0 }* Q  B& V! K/ [3 H9 eint i=0,FIFO_memory=MAX_MEMORY,count=0,Timet_memory=MAX_MEMORY,SJF_memory=MAX_MEMORY,Priority_memory=MAX_MEMORY,HR_memory=MAX_MEMORY,/ i2 l2 A! N8 ~" B' Y
flagDraw=0,showTime=100000;$ Y0 p5 t3 m4 B$ o8 G$ J! }
processPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;
3 W" F- n. I6 b+ C# z. hFILE *fp=NULL;
) ^  j( Q0 _% s" O0 U+ \. F% g//processPool HR_p,HR_mmy;3 k5 w! Y3 L$ `2 \
/ W+ e9 i! w3 P; F
1 k6 T# R# q2 u7 G7 t6 }
srand((unsigned)time(0));
$ P. Y9 @" w, N$ x1 SsystemClock=0;
# q! O% P7 ?; b; sinitgraph( 1200,650,SHOWCONSOLE );* u/ u3 K! [* Y! n7 `" p
settextcolor(GREEN);
2 @0 S! y5 F. u% \9 B, L1 osetlinecolor(GREEN);
4 o7 l5 M' r/ a, W* \+ `: Vsetfillcolor(GREEN);
* t6 ~  O5 E* C: v& E: g% hInitPool(&FIFO_p);
, v2 {* p+ a+ ~0 zsort_by_comingtime(&FIFO_p,-1);
. y  l5 y5 b* ?& ^$ I  RInitPool(&Timeturn_p);1 B8 v2 a4 X( [, m
InitPool(&SJF_p);
/ c6 ?! A+ {4 z& i4 x3 m3 q' oInitPool(&Priority_p);; o9 V) z4 @" g2 G) ~6 I2 K$ B8 }4 _
InitPool(&HR_p);
- R. x$ k( ~: t$ H# v( [' E0 H//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);2 B! I( P( ~- d. T' _( T7 p
//Sleep(10000);
! J% _* E6 P  g/ H+ c/ |5 {8 X- L$ X

0 u& H1 g8 T7 y; ^/ yTimeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));) K4 ~# ?$ ?0 E5 g
SJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));0 T% D5 ]6 Y* H, M4 T
Priority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));5 Q+ u& s! m; X7 O7 G! k& F
HR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));1 r. r; Q( _9 V$ P9 S% g" N
for(i=0; i<initProcessNum ;i++)& W) g0 [  i) x* D" I
{$ c& H! x2 v. P
Timeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));+ a9 w6 o" D; V& ~: {1 j
Timeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));6 V& T, ?2 ~/ g' e) n
SJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
% b- \9 J0 K) |; VSJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));+ ~3 L+ q6 c  z! ^- x) a
Priority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));+ Z# v  U/ K; w: j& o  b  D! K( g
Priority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
- n* @$ i1 k5 AHR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
4 B- f% g. X2 {5 KHR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
/ K- e9 a" n0 y- ~5 j- S9 v}% D0 u8 |# ^; J, n0 R* m6 e& d
Timeturn_mmy.proNum = 0;
5 \' s2 n( u* t8 w  E& v: jTimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);
" `6 I  q5 X7 D  T3 N; l& }6 ISJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);
9 B" |6 s! ^& [" i( qPriority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);
' S  a7 p  F6 b$ G+ @( xHigh_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);+ k3 p! k% f. L" q# k6 F2 J
//showProcessInf(Timeturn_mmy);6 z* ^6 [1 N: w; F* }2 Z/ J$ g
FIFO_pri = &FIFO_save_head;
) `6 |6 ]7 m' qTimet_pri = &Timet_save_head;( n# \9 P& u* Y7 R0 M' r) v$ W# n
SJF_pri = &SJF_save_head;
  G* g: `+ p2 Y% x: j; R' R& b) PPriority_pri = &Priority_save_head;' f& w" K  l0 H& l, G% t: p( d: E
    HR_pri = &HR_save_head;
+ w1 ?. z; a' p7 s, v- ]0 K  Isetbkcolor(WHITE);& |) v$ {- \; }# h) D* _& G" ?
while(1)
4 b; F" ]# t" X" E7 C{
! T8 X$ ?2 J3 R* ?. E* g! }- h, Uif(MouseListening()==1)- K5 e5 X; O# \5 F) ^  l) b
flagDraw=1;: j9 J7 |/ D7 w+ h/ N& f0 j& L
if(count==100)
7 c1 t9 {* m  E0 r% R/ h  {{# m0 |- G' f: U$ V9 p# R: D. C& y
if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)
! G+ w: Z  d8 b  c0 I" v{
/ P+ d( [" I# v( a# ]5 }/ g, @5 wFIFO_pri = &((*FIFO_pri)->next);( T4 i/ N: V0 @% x1 P- o
7 I9 F0 B8 O) o0 c
//printf("hello");$ k, c$ E2 V- v! w% |
}
2 |" K8 `4 N  u5 N+ ?9 h; \6 Y, Vif(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)
6 X8 F6 T1 a+ J) F{
+ N& E' J  s8 `    Timet_pri = &((*Timet_pri)->next);5 s  P$ p5 W1 H9 K3 |) F, s
//printf("hello");( I" o; V8 P  e3 f) U
}0 h) b* h& i0 u& o) Y- W
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)( N1 P- }  h9 X9 ?% V5 H
{; W1 K: K, l) U0 A4 w- f
SJF_pri = &((*SJF_pri)->next);# O2 y$ L8 g) r0 X
//printf("hello\n");
  g5 k. L6 p8 N& }}
! [" _8 u* e* F1 e+ ^if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed); i$ F6 g2 D- V3 q+ v
{9 m  {* _; F  h* [% `
Priority_pri = &((*Priority_pri)->next);( R) f4 r/ m0 x0 F2 m
//printf("hello\n");. ^1 [! z/ L, k# [- c; U, g  X
}* f$ K% G& t# O1 v
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)0 ~; f* A% n+ k7 h
{9 m) g8 y- U, a3 L( U
HR_pri = &((*HR_pri)->next);
2 x* x  I( s6 `  i# x+ F" }8 a  [//printf("hello");& Y* o: ~/ y5 E5 g! I7 p  B
}% ^+ {8 r; N; O
count=0;
. U5 J8 B+ {4 `6 \/ l. T- [}
% \$ X$ K, `( l, ~/ c& g9 Delse
: s' m' c( _9 b6 K' y( P7 x3 A{
& t! p2 L, U! e0 o* }& F( qif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)9 v/ E6 I$ H+ A6 w
{
6 \" a! x- c9 }, I, yFIFO_pri = &((*FIFO_pri)->next);* I5 K, q4 |6 x# ?
// printf("hello");
3 `$ l6 c" {$ _, a}
+ h8 m7 u2 C, F% j6 N2 Gif(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)
' t: \7 |6 W( j" d: E- b) B: F{" z. g( I. @2 }6 o
Timet_pri = &((*Timet_pri)->next);! P$ [; S9 Y) b* }1 m4 K& I
// printf("hello");
0 C, z% B7 U: e) \" u7 E* O}4 o0 v# ^& L# C1 L$ f% [8 h
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)
4 O% o9 F# U0 L; S& t6 k) o{# U7 x+ Z8 w" m  h8 {9 {) x
   SJF_pri = &((*SJF_pri)->next);
7 C+ A) Z. g( N4 K% g// printf("hello\n");+ B% c4 l, n" R* J) t4 \9 l( O' p
}2 {! n! L# c6 C$ R0 M
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)1 D0 p0 H6 O8 ]/ W0 n3 T
{% I$ M7 D3 c! Y3 {' x$ O. R( l1 `
Priority_pri = &((*Priority_pri)->next);) o% u5 I, f6 A. ~' G& i
//printf("hello\n");8 b& S4 G4 j' f# O: ^7 z
}2 u+ A  L9 V" S) b
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)" K( n% T5 X2 h# s# d# O& o$ u  V# m
{
, Q# ]0 }' P1 V1 n( o9 ?HR_pri = &((*HR_pri)->next);
- ^: q% r& V; x) S) s' ]//printf("hello");7 ]1 Q+ X* h. v& M% ~  Y
//Sleep(1000);
& m% T2 R; K" r+ V( c1 ~}. i$ ^0 `% G9 `% f- _/ }
count++;
3 w: R- Q& N0 _}
2 h+ V: a, P* n/ r# Qif(systemClock==showTime)3 I8 W+ r2 N, L: |5 `) l1 U
{6 i4 k% k. M2 o/ t" k
/*PCI * p=FIFO_save_head;
; n* z' Z4 A2 A1 G. F' Y; Dint i=0;: r& L' q6 k& e1 P  o
for( ;p!=NULL;p=p->next)0 s1 K% V& l9 U3 A; k; G' [
{
2 f+ |' U; G# m" O( vprintf("Id %d\n",p->processID);
* @1 F0 r+ C' D6 M2 w0 u6 [printf("comeingtime %d\n",p->comeingTime);
. ~0 |$ `' W7 Q1 O/ zprintf("runningtime %d\n",p->runningTime);+ Q/ D- J  i; |" V% }" L  E
printf("asdmemory %d\n",p->askMemory);
1 k5 ~& @0 K1 q- e6 ?$ l0 t) t2 Mprintf("completedtime %d\n",p->completedTime);0 @* x% M, f; ?5 z7 I% w/ }$ `
printf("compute %d\n",p->compute);
; G4 P/ x/ T& u. q$ yprintf("exchange %d\n",p->exchange);) V5 S, J" `( D( |3 C
printf("waitio %d\n",p->waitio);
5 R/ c4 ~$ ?& w: _, F8 Q0 U2 xi++;' A+ l2 ~4 }$ [' u3 {4 b6 z
  W8 C5 u9 N- y+ A, M
, u9 J# e9 |) L( C2 u) t" r* X6 T
}) v/ n1 V$ Z8 x
printf("%d\n",i);*/) g9 i% x1 L9 Z, M% V
if( (fp  = fopen( "data.txt", "a" )) == NULL )
3 v! q% k1 J5 t" I/ [' R% h$ f$ ]4 D% m{& e% R6 K) u( D! c
printf( "The file 'data.txt' was not opened\n" );
8 v; n  z" Y& K//return 1;$ q$ j2 S8 Y* M1 q/ O7 x/ [8 E  a
}! ?$ t: S7 D+ ^) F% q; h& s
else
9 h; a! D3 P6 n+ X9 N) ?{
6 f$ v% ~# G5 x: i) t4 P; r- rfprintf(fp,"FCFS \n");
/ x' D8 P% p/ u: Pfor(p=FIFO_save_head;p!=NULL;p=p->next)
' d) s8 c  ^9 o2 Q' W* ~, i' ^. Dfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
4 q; ~# z1 \  Y# y* @" up->exchange,p->waitio,p->runningTime);8 [2 a7 r# g1 J* N
fprintf(fp,"\nTime turn \n");# _( H$ K0 n" I0 z$ N* |$ @7 _: r
for(p=Timet_save_head;p!=NULL;p=p->next)
. o3 E2 }+ e) s" W' ifprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
/ P4 d8 O; }& lp->exchange,p->waitio,p->runningTime);
: S9 j; A: g. G3 r# @fprintf(fp,"\nShort Job First \n");
6 c6 c, r+ K/ `$ M. Xfor(p=SJF_save_head;p!=NULL;p=p->next)/ H+ \3 K0 [& Y- @# n1 m
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,& Z* Z/ `0 t/ a4 t
p->exchange,p->waitio,p->runningTime);
( t- B- O6 \7 ], z9 `" ]/ l/ sfprintf(fp,"\nPriority  \n");" T! ], s) T5 O+ a1 b0 g
for(p=Priority_save_head;p!=NULL;p=p->next)
+ o& }! a! P) b* k. q6 F( }  vfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,$ s' x9 W) H- S. \! G4 ~9 M
p->exchange,p->waitio,p->runningTime);9 y: m0 w/ z; K- U  y. ?" G
fprintf(fp,"\nHigh response \n");4 M9 P5 m1 N% {/ x$ E  \; w9 R: v
for(p=HR_save_head;p!=NULL;p=p->next)( C$ ~* s+ m' `: p1 j" [
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,; D8 L3 d) [1 p7 U+ C3 Q) O
p->exchange,p->waitio,p->runningTime);( j( |: j2 y4 y- |* q2 t4 Y' k# J4 l
fclose(fp);1 z7 v, s5 V" d( i: L! U
}
3 t! [$ o# }- }0 ~2 oshowRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);# \, z7 n) H, ^7 @- _
MouseListening2(&flagDraw,&showTime);
2 U2 ^# `. I, [6 T$ b. G}
  _' N6 G& @$ w& B, \systemClock++;
, k: k, L3 j1 i! m. a* F" u* Yif(flagDraw==0)
/ W6 E9 y2 n* l' A. c  Sleep(10);+ _2 _% v% r* j% z/ a: r4 S
}5 c& ]/ |6 {+ Z9 V0 @2 S. \

2 k$ a: }" M# P$ d2 D- o+ s) Q7 y( V
}: B- a) H- N4 Y2 t, `! k
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)
! G0 T. z9 e" L; X{
) E7 ~* L; f- I, n/ mPCI * p=NULL,* name[5];
/ k" m; z4 K% R4 d# x8 I! J5 pint count=0,i=0;2 B+ L: |# C2 c
char ch[5][10]={"FCFS","timet","SJF","PR","HR"};
( O7 Z& _7 D0 ~& I+ l7 X1 {double turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};/ B* [- k  f& N2 C7 b' H) q
struct info+ h& ]( R+ Z' l3 [6 t0 w4 ~
{
' r! B8 F* ^& n, T+ q- rchar name[10];1 ?% u& s7 B0 B$ X4 P! n' m! W  N# W
double throughput,turnover,wait,CPU_rate;
& G( d# I/ R% O7 T* `9 V}inf[5];
) \4 k( B" L& B. a! cname[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;- {1 L5 W* D% D9 Q3 `
printf("调度算法..........A\n");
" ~5 E) }/ N- q* B0 t" ?* ~printf("吞吐量............B\n");% ?7 E* `) y8 D" O' R" z# c
printf("平均周转时间......C\n");
5 H$ d! ~" |. R  iprintf("等待时间..........D\n");
8 l* Q- ?3 M  Hprintf("CPU利用率.........E\n");3 B3 B. O" H8 \) C
printf("A\tB\tC\t\tD\t\tE\n");- ]# ^/ _+ b" h9 K
for(i=0;i<5;i++)
- I, D: O  T; T3 d7 D; ?( C& @{
# ^$ }, }- j: u8 k' A. P2 Fcount=0,turnover=0,wait=0,c=0,w=0,change=0;- u6 w: J, R" K/ T# D  A
for(p=name; p!=NULL; p=p->next)
6 V  E( O$ K1 }* l! k. ~{! V) F! G. n: Y
count++;0 [1 S6 E0 b5 g: y7 t
turnover += p->completedTime - p->comeingTime;
5 o6 z+ d  W& [9 j" V; Y% t  ]wait += p->runningTime - p->comeingTime;
! T) c4 T8 l1 A+ Q9 Cc += p->compute;
% B2 }8 n) C& \% D- kw += p->waitio;
. |5 A3 u: X0 g7 }5 F7 @& P& F5 R$ h( mchange += p->exchange;
, @% B4 L3 a, u}
4 M4 T4 u2 V  Sturnover = turnover/count;- }7 a7 M! [# p  i
printf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));
- r7 u/ e" j+ \9 ~" Gstrcpy(inf.name,ch);
( N" D5 d8 A9 D+ Iinf.throughput=count;) M* `& N$ n. y6 g. s
inf.turnover=turnover;
  H: X% o" |3 Y2 Binf.wait=wait;6 N5 D  a  A8 P* t. A, }! \
inf.CPU_rate=c/(c+w+change);
" T' L) X: k+ P( C! L}
6 A! R6 n( L9 ]//画图
& u8 r- k% e- Y& @. w4 k+ p//cleardevice();
# X' ^( u; g3 \6 ~0 a- m# Z) C! B2 [% nline(0,600,1200,600);% T7 Q! l  ^# `- z% ~$ p9 T
line(10,600,10,200);' J+ M3 ]" i/ f
line(10,200,5,205);8 V# g. w! o8 I
line(10,200,15,205);
( H; W9 Q# B3 F6 qline(310,600,310,200);0 i2 ^) a2 @' l: G, U$ [9 K
line(310,200,305,205);
3 \5 f/ p- y! {/ `8 nline(310,200,315,205);
! R; c$ z( z' D5 e+ Bline(610,600,610,200);
% A) o& n4 l! Pline(610,200,605,205);" _" O2 {8 y( t+ k) {& B
line(610,200,615,205);" G# H6 g- o! K0 [  P
line(910,600,910,200);
$ d( V- }$ E" i0 iline(910,200,905,205);) u) i' n3 q# }; Y$ k( L
line(910,200,915,205);//最高的长度400,宽度均为40
. N! U; I6 D" \9 k# [+ z3 dfor(i=0;i<5;i++)
# m; I: h/ g2 l6 @{4 k) e4 ]3 z. w' t4 ^. |
if(inf.throughput>pos[0])) ?2 i3 }3 a: h; K
pos[0]=inf.throughput;4 v3 ^2 a1 g( z& y- i. y
if(inf.turnover>pos[1])
* X0 _  C7 j- }. H9 spos[1]=inf.turnover;
; s" w' E9 ^( Oif(inf.wait>pos[2])3 L$ M8 R, X% F+ g8 S5 Z1 `
pos[2]=inf.wait;
/ X; y1 c6 l2 j  f  s0 t% b( q+ j7 Xif(inf.CPU_rate>pos[3])
# B- @+ U3 \( S8 B* S0 z- {9 b0 mpos[3]=inf.CPU_rate;5 k0 W" q6 i5 w* c. X) L3 x
}( b+ T0 ~) l: N3 x1 L4 t. x
settextstyle(30, 15, _T("楷体"));) }) v5 I1 Z! ?2 o. m
for(i=0;i<5;i++)
$ o6 @" E( X( N. g{2 e2 t0 ^8 u6 L, N; z
switch (i)
! W* b5 E! g7 U, Z( t{- \& C& I7 U* C, Z. {# M
case 0:
7 I8 U: o; Z& n- x5 E0 v+ Psetfillcolor(BLUE);5 I) }4 \3 n! {5 J: \( }1 f
fillrectangle(100,50,150,100);
: ]* V: b; I. P) l* m  Vouttextxy(160,50,"FCFS");- c. w" j& H/ ?1 }7 [
break;
/ _+ k9 Q1 R3 c  ~, Tcase 1:
' ^( N9 d3 d# b+ L* S# y% k. K" wsetfillcolor(RED);$ n% C! u* q* k) ^9 F' @) s1 I
fillrectangle(250,50,300,100);% @/ U# R, ^- L9 O' |
outtextxy(310,50,"timeTurn");
( ~6 S* q$ q2 C, c. tbreak;
! U7 I3 l  ?" R& Q" N* a( m- M9 y4 ecase 2:" Y7 e% n( S" }# H9 z
setfillcolor(YELLOW);  w- \) r! J& A9 V
fillrectangle(450,50,500,100);( F: i, M( O. q
outtextxy(510,50,"SJf");, W: ?1 i- d$ H# @% T% N
break;+ o, M1 [+ O  t% f+ ^, i% E- p
case 3:
) Z+ x  N% S. Z2 qsetfillcolor(BROWN);2 i% `: m6 S0 O1 H9 f5 Z/ r% m+ \
fillrectangle(580,50,630,100);
' v+ C3 {+ x- u0 a1 y" xouttextxy(640,50,"PR");1 }. V" d& x( C3 v5 j* V
break;
) K8 F+ E" m3 @case 4:! F8 e8 K+ L! R- y, n
setfillcolor(GREEN);
3 l3 n) i6 Q- X6 s) rfillrectangle(690,50,740,100);4 R1 V" I% K$ f
outtextxy(750,50,"HR");  R. ^1 J" c2 Q+ m! u5 Z8 k+ c
break;6 W9 w. G8 A  r  h6 f% s7 l' }9 `
}
: R" |( I5 A5 n. G0 t3 `: Ffillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);
  {* ^9 {, E" O) F  Gfillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);
* I/ t) d6 W; _, Zfillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);
+ D( R4 P$ B; `9 R4 h. C; V( pfillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);, _+ ^. k6 T4 R; f: ?
% j6 l1 N4 z# b$ V' a6 n3 G* I, r% E

6 A, J$ P. S$ m& Z4 w}
* S( q, E8 \* m- \3 W  [    outtextxy(100,150,"吞吐量");
! F& V& Y) d( b% T0 p7 Bouttextxy(350,150,"平均周转时间");4 C0 J0 u& W4 V5 B( Y5 E' ]4 V! z, V2 S
outtextxy(650,150,"平均等待时间");+ F0 x" m, ~' v
outtextxy(950,150,"CPU利用率");
' p0 _: L1 u# N& B7 Dreturn 0;' O+ _& g: [: R" O  @
}
) I8 w1 X6 K3 V. m" A5 ?4 M: t2 Zint MouseListening()
- W$ |5 ~; T6 s( R; ]{8 q1 w, j# ~% |
MOUSEMSG p;. I3 W9 _/ O: b% W5 M0 u0 _
if(MouseHit())' ~) Y1 |  |# w4 B
{
6 b% H, L8 R& M; X0 R4 kp=GetMouseMsg();
" J. v" s1 V+ x8 O: A) z% Kif(p.mkLButton==true)
- @& w2 X% V( C- L' a{
4 _3 i$ ^, Y7 |; N- K0 H/ m/ gif(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
; H9 m+ |" g+ o8 J& UFLAG_FIFO = 1;) S1 y$ S* B+ [' E  h
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)' L* I0 E# n* Y% c% e8 F. R* Y
FLAG_TT = 1;
& E) `7 e/ N# H7 Q! K1 b1 i1 L! Delse if(p.x>800 && p.y>0 && p.x<1200 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)% S& ~& a/ g* _0 s- ^; F7 e4 @6 @
FLAG_PF = 1;0 f# b5 `- i. B$ K4 ^  z
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)- J- g9 n2 z) P/ _2 g3 h0 |
FLAG_SJF = 1;
" _8 u% F$ p% a9 zelse if(p.x>400 && p.y>325 && p.x<800 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)8 A! c0 i$ T2 c( u% E: |' X; ~
FLAG_HR=1;
# \* J1 z8 K+ t0 x2 ~- Melse if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)) W+ t; \% i9 ~3 v- X* F8 a
{' m1 t* A  G# U1 P. l) e& N
FLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;
8 \& s, J+ O3 T# ^; bclearrectangle(800,325,1200,650);
4 i- y, O0 L9 ?% V- ^  t}
. D! V  h9 h6 delse if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )
5 ]0 j/ N- W8 n) v; Y) I{
+ J1 s1 a: s+ i' Z' E9 S% YFLAG_show=0;' A+ Y1 k. |% E, l5 `( f: [
cleardevice();
: T6 z& }7 L: m7 c1 v% Yreturn 1;
) Q4 I. S" I8 v6 T  G7 ~" R% P}$ L7 \+ ~5 Y8 _# i
}+ U4 D& M+ u5 b' E
}" E% e: l4 T& G: R( n6 z
return 0;
. I( [' ]7 m* \6 g5 R}% e. R" @) i* j2 F
int MouseListening2(int *flagShow,int * showTime)5 [" a2 u6 G5 E4 ]; `! N/ `
{
) i. X$ [! D; j6 \6 q9 N9 GMOUSEMSG p;
7 x. [1 n, |5 a, d0 j3 u' m$ Trectangle(1150,0,1200,50);
* K$ P6 ^+ S# i% |/ @outtextxy(1160,10,"X");% h# H1 I! U3 K, G6 @7 L
while(1)( }7 [  y3 b& |4 h; ?1 f( b, X1 Y
{
- `$ {# c2 i! K9 z% R9 Iif(MouseHit()); S3 v! x: Y& C5 L  a
{
- D9 K7 o+ }# e* ?! Ep=GetMouseMsg();$ o" r- I: A$ D* a
if(p.mkLButton==true): P  g+ m; a) X( ?! Z
{1 b* d" i+ |1 Q' o$ g! j
if(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 )
7 c& s8 [) v2 b% }: P0 m  P' a' X9 \{& _4 m* V8 @, l3 \) `5 x
(*flagShow) = 0;
( L0 [# G3 W! r1 J' t9 B(*showTime) += (*showTime);
4 n( w; t% C/ u. iFLAG_show=1;6 `) l9 N! d) N% A. I1 J; r8 n3 T
break;
* @, O5 x7 D- q: P2 ^}9 l7 B+ I) d! ]* B# y/ `

' c! t+ H! F+ P  f4 I}
$ h. c$ `! I, X- P. o4 p+ x9 ^1 O}2 W- y& f2 W* e) a; R
Sleep(20);, C, U: G0 r9 x% h. @, j: R: R
}+ J% S8 F8 X. ^
cleardevice();) @( B7 [  s9 G5 o1 s
return 0;4 u( R% w' \: g' v6 Y
}8 z) y& d6 f$ e1 J
int drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)
$ Z1 S' [* B7 k* H" B' z5 s{. q. y' y0 R4 a
static int info[11][3],num=0;
6 I+ A  Q: v- M1 d5 W; @+ h$ D* _" Oint i=0,j=0,pos[10][3][2];
& N/ ^7 ]1 G4 I3 |5 N, S  D7 Z1 e& ffloat temp,t;$ q0 e$ l) J7 a- N
//画按钮,不属于FIFO图的范围! w$ P' ~- U1 S
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1); `: X$ k, b' ^
{
  ]  M3 g/ Q  f% `settextstyle(30, 15, _T("楷体"));7 a1 m" Q7 [7 M- B6 T& U
rectangle(890,455,1110,510);& c% F  T1 K- A2 F) i
rectangle(900,465,1100,500);: A% ^) t1 x6 j* `. q7 i
outtextxy(910,468,"查看运行结果");  b$ H9 K, o' z# _+ z9 e* u
}
! B- Q7 c1 h* T. v$ J2 f//结束画按钮) c1 p% B3 \. u( ?. Z# G# y
info[num][0] = com;
8 b) O3 n0 u9 ?& E1 finfo[num][1] = wai;
" M) M8 b; b! P" Yinfo[num++][2] = cha;
( L6 i9 R& f; }: b/ P2 @if(num>10)  //存储10个点
- i& Y% t3 O2 r6 o# ~2 n1 L{
; }/ m7 f6 f2 O$ j1 h" Wfor(i=0 ;i<10;i++)
: k7 N# N) d8 G' K! R  D. N/ M{
: Y# D) H9 X6 b+ Finfo[0] = info[i+1][0];) y" W: l7 l3 g
info[1] = info[i+1][1];& S1 _4 t4 z3 k2 N* T5 C7 ]
info[2] = info[i+1][2];& [! ?: L0 N1 U) j1 K$ e1 U: d
}0 z( K0 k5 m6 Q* {) A+ l
num--;
* _9 g6 I! m, z3 i}
/ g' }( T/ l! W, Q; eif(FLAG_show==0)
' s: R5 d% b1 K% V1 ^return 0;
  c* p+ R0 Y7 ?for(i=0; i<num; i++); _' K: e! g% i1 W( D8 F
{; I! O8 O; c; g3 @) {3 l! l7 u
t = (float)info[0];
& L' p* P2 b- i: Z# s# v, }7 Stemp = (t/101)*90;1 M+ y. G: f  U: [
pos[0][0] = (10-num+i)*25+x+100;
# R, k+ _) b8 Y( m5 Fpos[0][1] = y+110-(int)temp;
  ~1 M2 _) S/ U+ K& j. E, B0 mt = (float)info[1];* x! a/ z: P# c9 T
temp = (t/101)*90;
6 {( A3 m) W8 [, \5 u! ipos[1][0] = (10-num+i)*25+x+100;
& @; v1 v$ S2 u" r% k9 `pos[1][1] = y+210-(int)temp;' N: }8 N  h; N6 a* m; S! w
t = (float)info[2];
. i$ W5 i( g6 r% p+ |2 Q, O: E& T: X& Ktemp = (t/101)*90;
0 J* l+ R5 Y2 q$ Q+ p1 j8 zpos[2][0] = (10-num+i)*25+x+100;; J# i2 D# O9 S
pos[2][1] = y+310-(int)temp;
9 @( i7 ]9 ?% B5 M  A}
8 F/ o8 S- G+ x4 @if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
% V- g4 Q- i* _. d6 L3 X% @. d- L{
9 \1 H- ^8 ~8 I/ j  R; Fclearrectangle(x,y,x+400,y+315);) V; ^3 p- b5 n7 Y6 a- |
settextstyle(20, 10, _T("楷体"));
' r, \& {# P! P0 M3 Z% ^9 hrectangle(x,y,x+400,y+325);6 ~4 P1 A0 C! C1 a9 ]! r8 R
outtextxy(x+40,y+10,"CPU");       //画柱状图
1 n8 _& k, Q! R  S+ }outtextxy(x+45,y+10+100,"IO");: K6 [8 @2 v: |2 E
outtextxy(x+40-15,y+10+200,"change");
) v/ t' i& L7 A3 f  ]4 ?% v* hrectangle(x+35,y+30,x+75,y+110);, l4 G" c6 g% S8 U. M
rectangle(x+35,y+130,x+75,y+210);( s0 b% U1 `, c1 b: E( ]
rectangle(x+35,y+230,x+75,y+310);% b9 T( ^0 E5 @& n" F, }0 H
outtextxy(x+180,y+310,"FCFS");1 N+ Y+ J. k: b  U  n, K
t = (float)com;! J/ \) o/ d7 g0 v, {7 Z
temp=(t/101)*80;
6 d1 e5 W1 `6 m8 ofillrectangle(x+35,y+110-(int)temp,x+75,y+110);  g2 o: U6 Q1 n( J  }
t = (float)wai;/ x6 g! Q7 b* l
temp=(t/101)*80;
! |0 V: p5 c" Rfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
5 O1 ^4 R. L" l# e& ?t = (float)cha;
8 @2 i* X. g6 |3 C+ Htemp=(t/101)*80;
/ D1 M) [- H5 i' Q$ qfillrectangle(x+35,y+310-(int)temp,x+75,y+310);
' I4 b/ X9 W- i7 l$ ufor(i=0; i<3; i++)   //画坐标   high=90,length=250
. J- a! Z: P5 @8 B1 ?) P{& M4 `8 J3 [+ W; B: P3 A- b
line(x+100,y+110+100*i,x+350,y+110+100*i);
+ G* B8 K( O" bline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);4 t. J- E& W; _" V6 S- i
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);0 M2 ]# N1 o9 L' ]9 q% S) N
7 e6 C# O/ I- J; n
line(x+100,y+110+100*i,x+100,y+20+100*i);; [5 A, q' N) ]& i- R
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
1 ?7 \2 p( t8 Cline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);: B+ T  a; u$ @
for(j=0;j<num-1;j++)
) ^1 N/ r" o" }# T. K2 W( f{+ u, ^3 F  M0 u" E2 x5 B
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);- Y& z2 H% J  c. j
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
9 F& f* c' x; ^. O8 |: d) d) Lline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
1 f. G' U* O" ^9 f}
/ k) o, U, h# C- T3 |}+ |5 L! H' Q! w( C
}
! e% z: ~& Q  o6 G, O- w/ belse if(FLAG_FIFO==1)6 O. ~" G2 \: w& g
{
  y/ {4 T7 j% a+ v8 [. sx=0,y=0;
! Y" P; k) p* d4 B2 s! V3 X0 k4 @for(i=0; i<num; i++)5 _8 N/ T- v2 s7 b8 k" W
{
; \8 s$ o" b3 r1 pt = (float)info[0];/ n5 n9 O3 P5 Z+ e& D
temp = (t/101)*180;2 a6 u8 {3 U% m& g2 ~2 A
pos[0][0] = (10-num+i)*50+x+650;% n. N4 [- s1 z' k. v
pos[0][1] = y+210-(int)temp;& l1 d% u. d$ c2 j+ k# ]
t = (float)info[1];
8 T5 L9 I1 u2 b; O: btemp = (t/101)*180;
# m2 B8 h  y: z: `5 f: D. F5 D3 |pos[1][0] = (10-num+i)*50+x+650;
( T! p/ X2 Z' [' @2 z* opos[1][1] = y+420-(int)temp;
; Y9 }3 r! H$ O; H5 {- Z$ @t = (float)info[2];
& z0 _/ `4 N6 j0 ^temp = (float)(t/101)*180;
6 P; \+ ^" T8 A+ Ppos[2][0] = (10-num+i)*50+x+650;% X/ q  ^4 @5 S7 r9 w* u3 v# Z
pos[2][1] = y+630-(int)temp;
# g- c7 h' j. F$ F9 C}; |7 O% o6 G& P' N5 F, p6 C/ e
clearrectangle(x,y,x+1200,y+650);2 i8 m/ q' M: p  e, |
settextstyle(40, 20, _T("楷体"));( K- z, b& }- u) ?/ P7 m3 m
outtextxy(x+50,y+50,"FCFS");
& v  ~8 k: k, r/ j, U/ D) routtextxy(x+280,y+20,"CPU");       //画柱状图3 ?. _  S$ G$ Q4 B  \+ V8 e2 k& o/ N
outtextxy(x+285,y+20+200,"IO");- U* u7 {7 P( a0 Q# ~4 N7 u/ J: E
outtextxy(x+250,y+20+400,"change");7 `$ ?* R) t3 S! ]
rectangle(x+270,y+65,x+330,y+215);/ A, p; i" [- Q( L8 `( u4 r
rectangle(x+270,y+265,x+330,y+415);
- P" ~4 n8 R1 d$ t5 l0 brectangle(x+270,y+465,x+330,y+615);9 l: y8 `! c. A- E
outtextxy(x+290,y+620,"TT");
: T' L1 n- o- f6 Yt = (float)com;
5 T2 t+ C. \/ W# O3 r' htemp=(t/101)*150;
  y9 c& u% E1 J* {7 O  C, Rfillrectangle(x+270,y+215-(int)temp,x+330,y+215);) R- ?* p9 _0 d3 v
t = (float)wai;9 a' v; W2 Z  x" N7 i
temp=(t/101)*150;0 @8 P" N  {9 z7 V; D
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
" x! d- @# [9 t" h$ p: At = (float)cha;3 E6 ^! L# @2 I" U2 u3 ~& f4 N
temp=(t/101)*150;
/ T  o# _$ D9 e1 [; z# X4 U" ~3 i, Q/ S& Xfillrectangle(x+270,y+615-(int)temp,x+330,y+615);1 m6 e3 `( h( E$ Q
for(i=0; i<3; i++)   //画坐标   high=90,length=2503 Q8 x7 R$ ]& T. T2 @- a
{: n& F/ P2 U& }
line(x+650,y+210+210*i,x+1150,y+210+210*i);2 C) a4 B: n" X2 u1 ^
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);* `2 I% ]8 [+ ^' G* ]9 i0 z  O
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
4 D- E( O; y( Y9 K. P3 D0 F) k, T6 P/ s) r3 f7 I7 g  Q
line(x+650,y+210+210*i,x+650,y+20+210*i);
1 j1 C2 s& }# \line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
# u; E. U) [5 P  c$ h. T3 f2 Gline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
" g; P% ~2 e* y1 cfor(j=0;j<num-1;j++)
$ A# s8 T0 H' X$ m* A% r1 j{
: I3 b: N1 {( w7 t. @$ U: Cline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
$ H! W. x2 Z& Z0 ~% rline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
/ y7 G# R. y. d* h; Q+ S) kline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
0 C- s) R* z* `( Z}' v! P9 V! u( q- j4 t4 C
}
/ N! i% E' d0 o( _4 K% G}) e. c7 P/ o# n: Y" K. y, F5 e6 E

7 p: F7 Q- _7 e9 q* l9 Q
2 L& _: \& N- Jreturn 0;4 b; F" w; k  i7 ]+ s1 a% e7 y
}
2 c* O* D  w/ F, mint drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)
$ \8 `4 x% C: ?3 x{5 O9 u2 F$ H1 z; n% W
static int info[11][3],num=0;
# r2 m0 [6 |6 @int i=0,j=0,pos[10][3][2];' p6 J; T- s4 W  y0 k
float temp,t;& n2 I- D# Y+ T$ s4 e) J8 P* D. V5 B
info[num][0] = com;$ M: x+ w* b/ `" h% ]- K
info[num][1] = wai;2 a% W7 M" Y$ U  V( H- D$ o4 l( T$ M
info[num++][2] = cha;( T/ L+ p6 M- g/ N( c2 B
if(num>10)  //存储10个点
' z) X3 {4 }8 y5 |' L& ?{& n! Y+ [) }: T& D5 i$ J7 M
for(i=0 ;i<10;i++)
5 M& m* |1 y2 R) r6 g3 A{
! c3 ~4 J) U! R5 Jinfo[0] = info[i+1][0];
- a/ @; S& [2 v. binfo[1] = info[i+1][1];3 c$ ^; E+ p. X) _4 S' F  U
info[2] = info[i+1][2];( a' \& m, I0 D7 }. ]- T
}, x2 d0 W7 M& R2 ^) S- G
num--;5 v# a  M2 t# H; l/ Y; \6 K- Z
}
6 w( K) E& Y1 v) Q  pif(FLAG_show==0)
3 l; m" g; L1 t  S* ]. ]return 0;
$ _* V! z7 L) e" ffor(i=0; i<num; i++)* r* c" Q7 \/ R- O4 v4 Q3 v" ^. w- {; o
{
* C) V- A# g9 h# x) }$ ~5 @t = (float)info[0];  u* i+ ]0 a9 m# N6 @
temp = (t/101)*90;
+ R7 ^9 [, O' ?5 T" S* q9 t' Dpos[0][0] = (10-num+i)*25+x+100;
( @9 [" z$ b. J! c* hpos[0][1] = y+110-(int)temp;
+ X' p) s& K8 z7 ]" rt = (float)info[1];
& L& j$ q% ^  V: W. Q" X# `; Ltemp = (t/101)*90;
$ H" z8 x* z6 R4 R6 ppos[1][0] = (10-num+i)*25+x+100;) ^9 v- g# d) ^$ j) ?
pos[1][1] = y+210-(int)temp;
8 k. R) z2 v" p- o) ]3 `# jt = (float)info[2];% c/ v$ g4 S) p) w
temp = (float)(t/101)*90;
$ ?! {' I) D7 a, }4 vpos[2][0] = (10-num+i)*25+x+100;7 @, N: s- ~! J! I, t% K7 d+ s
pos[2][1] = y+310-(int)temp;
6 [% r7 f  U% p8 E' p% t5 e/ h}
% b4 T/ d. L) X* Qif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)- [$ v" V) g$ o
{3 y6 |9 P% ?# B4 ~( U9 Y
clearrectangle(x,y,x+400,y+315);7 I% U7 }# Z/ e  A
settextstyle(20, 10, _T("楷体"));
5 I: }% x, o' u2 K# G0 ^2 y4 L7 _rectangle(x,y,x+400,y+325);
! Y/ k/ z. `1 o8 w5 r/ Houttextxy(x+40,y+10,"CPU");       //画柱状图% Y' F8 D. w$ X' g1 j& s' H
outtextxy(x+45,y+10+100,"IO");/ e) i9 a7 B) [' s* |
outtextxy(x+40-15,y+10+200,"change");* V& u' N& z: s" X3 ^+ y
rectangle(x+35,y+30,x+75,y+110);
5 H% C6 M! Y/ D, ^6 }. orectangle(x+35,y+130,x+75,y+210);: H  c) n/ s  O/ J9 j7 P
rectangle(x+35,y+230,x+75,y+310);+ k! c* |9 h* g9 c
outtextxy(x+180,y+310,"HR");
( |) p" d- j) ~* I5 p! S* }t = (float)com;
+ i/ w. }5 H* c. U$ N1 ytemp=(t/101)*80;
1 F5 I* y" a) |1 t, ^' ufillrectangle(x+35,y+110-(int)temp,x+75,y+110);
2 O- U  s/ e' r6 L$ Bt = (float)wai;
$ j$ J) K- y" O6 e# Xtemp=(t/101)*80;3 z2 a5 F' y/ w( F! R" X! \
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);3 u4 w1 S* j% ~7 J% m
t = (float)cha;
# n3 b) o# X7 e" `) A+ g$ J$ ?3 Qtemp=(t/101)*80;  _; o, Z) q5 _5 q
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
; F: A4 P1 J( S: I9 g8 Lfor(i=0; i<3; i++)   //画坐标   high=90,length=250
$ C3 y* S) t0 S5 e{
/ b8 v  j+ l7 a# w2 xline(x+100,y+110+100*i,x+350,y+110+100*i);. W1 r$ [7 \+ X+ U6 x9 [
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);. F' T. {3 t/ w7 C7 O
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
8 o3 G5 S1 N7 A; d1 Q7 U4 C* A+ ]" u0 l; D0 s0 n6 J8 q8 D! t8 j
line(x+100,y+110+100*i,x+100,y+20+100*i);) `+ @/ {' F# ^+ \* V
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);3 L3 D" u2 |; F5 Z7 V1 J
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);" m: ^1 G% A9 w  |( Z0 X) P
for(j=0;j<num-1;j++); c! J) [1 c( j# R
{& X$ A9 R, V" z' Z1 H, d
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);3 v5 j) z2 h( R/ c* s
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
! o' C; z. z  l) f0 Zline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ( A, m" M0 K* v( z
}
1 O  U/ K2 G6 M, E0 @2 z3 ]}
, z  B$ x9 h& ^: U8 b. [( G}
( ?0 J( q! ^* J6 s: H, n( {else if(FLAG_HR==1)# u- f/ W* w- Q4 W. F5 t% P
{
. {" Y7 H! k& @% [x=0,y=0;. j, q2 `# j& T  w- [6 T$ A- g
for(i=0; i<num; i++)
1 F. L4 @6 u( H# b7 N. w{6 i' {$ A5 b4 Q% w
t = (float)info[0];
8 Y+ s! ]# B3 ftemp = (t/101)*180;
$ P& t5 [1 W. y0 A/ ypos[0][0] = (10-num+i)*50+x+650;  P; B. @: Y! K0 f) o8 i; W2 A
pos[0][1] = y+210-(int)temp;
0 b, j8 R5 X1 z$ E4 x0 D4 ^1 jt = (float)info[1];% b. A( R" {* B/ J: h7 O& U7 r
temp = (t/101)*180;/ z- s% u: X+ H1 f
pos[1][0] = (10-num+i)*50+x+650;+ o* }4 }" ]. x2 M6 V  ~( B
pos[1][1] = y+420-(int)temp;
! u+ l2 D7 r) y! Nt = (float)info[2];% e9 `5 Z# i. c2 k+ y& ^
temp = (float)(t/101)*180;
! s, F% E: r, q1 H9 o/ Kpos[2][0] = (10-num+i)*50+x+650;5 ?+ F4 I4 M4 s& m( V6 t
pos[2][1] = y+630-(int)temp;
" I% ]& m7 S+ Q2 f}
% V# u( u+ k9 l" F+ Uclearrectangle(x,y,x+1200,y+650);
7 D) p: Z4 v. y# W# U9 ~$ x4 Rsettextstyle(40, 20, _T("楷体"));
. p' J. U0 Q! ?" e/ J$ _6 Xouttextxy(x+50,y+50,"HR");
8 V3 I* U+ u) fouttextxy(x+280,y+20,"CPU");       //画柱状图
" ]% ^4 P# S% a' V5 s5 P/ uouttextxy(x+285,y+20+200,"IO");
" e% {+ ?3 F  O$ jouttextxy(x+250,y+20+400,"change");6 M0 z! Q! L' \2 A% O
rectangle(x+270,y+65,x+330,y+215);
$ t9 F# r2 O/ o  Prectangle(x+270,y+265,x+330,y+415);
0 B& q$ _: m( D" }1 Irectangle(x+270,y+465,x+330,y+615);' @5 X7 u( t+ C+ f: }
outtextxy(x+290,y+620,"TT");
/ ~; x0 u- ?" m' ]4 _2 `$ At = (float)com;
/ I8 v# N9 @+ W  }5 G$ atemp=(t/101)*150;
) z: C  \; f5 W+ i8 Dfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
, T. D; L6 C, E, n% t! |5 f% Tt = (float)wai;
: h) [, [2 W0 t2 B" ]$ x$ C0 f8 _temp=(t/101)*150;
. u  b+ C  \! Kfillrectangle(x+270,y+415-(int)temp,x+330,y+415);
6 C" _# [* t& h% X! Qt = (float)cha;8 H0 t1 B% m$ c/ w2 P  j
temp=(t/101)*150;7 A0 R% A/ ^" W/ a# k) {
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
2 v- U! q2 R  i& `* t0 l+ Qfor(i=0; i<3; i++)   //画坐标   high=90,length=2500 l# @5 y9 |5 r  P4 w% v
{
- ?. b5 |) D2 v1 r- d* mline(x+650,y+210+210*i,x+1150,y+210+210*i);
; t$ W2 @/ o: i0 A; iline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);4 t1 g/ p- |$ @7 V
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
4 s# u" {1 D. j; {2 E  ~2 E. Y5 P/ D. r4 i4 |+ f* w
line(x+650,y+210+210*i,x+650,y+20+210*i);
8 R7 L6 w* o. H/ g% Dline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);: I! P' G. c0 V  z( u
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
1 u# ?, ~3 `" e- C. ~& ffor(j=0;j<num-1;j++)
/ S# L& L- @) K8 A1 X' N. V{$ W6 A# b+ n+ M! _! O% B+ m
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
8 M$ _$ U8 U- E, w) w+ [* Rline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);; w/ p+ @7 {4 N* `3 s% Y
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
+ N- S+ t3 D9 c3 b}
( m$ S, W/ \) j}4 v+ h+ H( a/ P
}9 x- i" }8 z! h4 {
+ _% t5 e/ M5 T2 ?, W. `

1 u* S$ G: L2 h6 V- X7 u1 Jreturn 0;) [& f  M# D- q
}, w- ]3 O. w. A0 H. V2 h; M
int drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)
  X7 l# x8 ]+ l0 l; p% L{
( \7 y7 C* G$ Astatic int info[11][3],num=0;! O) X. a" ]0 g0 E9 {" O( l+ U
int i=0,j=0,pos[10][3][2];- C7 \2 V( L( {2 g, k3 z9 X. g
float temp,t;. t1 e5 d( Z7 [4 y
info[num][0] = com;5 q# U8 C1 H! D
info[num][1] = wai;. Q: e1 A- }4 i0 {* g+ |# u
info[num++][2] = cha;
) |; i( o, L4 {1 j9 q7 Pif(num>10)  //存储10个点! X' e7 }; g) i4 h4 T" g
{5 O5 l- d/ r0 A* E! _9 }9 J3 V( L
for(i=0 ;i<10;i++)
) h) `) j9 b2 Y4 Q{
" g0 p, Z6 c2 G  W# jinfo[0] = info[i+1][0];
4 D- A8 M, t4 B, @/ _; ?info[1] = info[i+1][1];  Z9 w# F( ~/ i5 b5 x
info[2] = info[i+1][2];
4 `# L) X" f2 \9 ^- o8 f}& v7 d- J" R) u7 c  B4 ?
num--;
, b( _7 G' n- r' h}: q8 a. |) }3 y: Y
if(FLAG_show==0)- \1 c& R: F: H7 J3 G9 `
return 0;
% H+ Q  ~' e: Y0 n* }4 `& L. cfor(i=0; i<num; i++)
: f0 G/ M- M6 i{
: R: \; l2 n! W6 o( }% ~4 p% Z* Ut = (float)info[0];( Z' T( ~3 B9 J# B: O; U' b+ o
temp = (t/101)*90;- S$ B6 R5 `" e9 u- q# J
pos[0][0] = (10-num+i)*25+x+100;' L  ^- k' W7 A8 Q1 T( P- Y! s
pos[0][1] = y+110-(int)temp;
$ @$ b/ d! C9 I! L; v6 J% zt = (float)info[1];/ g4 P/ n! X: c3 A* k" C
temp = (t/101)*90;
7 G' ~& S: c" t$ `. u8 Gpos[1][0] = (10-num+i)*25+x+100;
+ C; e+ ?6 q. J1 O1 x5 w& O7 }! kpos[1][1] = y+210-(int)temp;3 k& l3 J5 k% S5 m2 |
t = (float)info[2];9 Y' s( e2 N# j% R% M
temp = (float)(t/101)*90;
, j, o- s- U) d9 Fpos[2][0] = (10-num+i)*25+x+100;; ^# c( S8 u0 S7 K2 M( s/ \' S  z
pos[2][1] = y+310-(int)temp;
  p# e! S( C! [9 }( t9 Q8 D* r" N5 H}
: ?) f: |* P8 |# O: P5 y, O4 s7 R$ sif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)" r( ?# n6 d  m4 A- i
{- J  A0 g' I3 }, f
clearrectangle(x,y,x+400,y+315);
9 N: F1 k, ]8 E" `) B8 Jsettextstyle(20, 10, _T("楷体"));+ U" O; J5 {; h3 X, U! B  n
rectangle(x,y,x+400,y+325);
" l! ~9 X! I+ u$ G+ Souttextxy(x+40,y+10,"CPU");       //画柱状图
  m9 l% M  Q4 p8 ]# j  Couttextxy(x+45,y+10+100,"IO");' C  A  H) L: k" j$ m6 a
outtextxy(x+40-15,y+10+200,"change");# s" d2 T6 Y$ C
rectangle(x+35,y+30,x+75,y+110);6 U6 j5 D9 N: Y! j( ?& G
rectangle(x+35,y+130,x+75,y+210);
1 C$ I& e% {. I1 o# Orectangle(x+35,y+230,x+75,y+310);/ S) ]7 C4 h2 e  J! N+ A
outtextxy(x+180,y+310,"TT");
5 z- n! H0 D* e1 ]: N0 st = (float)com;6 z; ~) u- z% p* m* P' k+ F
temp=(t/101)*80;0 U0 K. H9 `0 D$ V- z: j* |: Y; S  @
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);: j" [( F7 o$ B$ j4 x( b
t = (float)wai;: r: B: v) V. B3 _9 T
temp=(t/101)*80;
4 O" E/ F( B  O2 m, c8 ifillrectangle(x+35,y+210-(int)temp,x+75,y+210);
$ Q3 J3 J, A8 Rt = (float)cha;
1 O+ o5 S0 r  p9 }temp=(t/101)*80;0 j4 v, J9 v8 d/ x$ m  s0 F* ~+ q
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);4 x6 G7 L4 W; J. v2 X
for(i=0; i<3; i++)   //画坐标   high=90,length=250
# Q9 `3 {; v3 z' ^* c# U+ E{
: d% d0 J: [% [% g7 e9 Kline(x+100,y+110+100*i,x+350,y+110+100*i);5 a) j7 y" G# Z, q
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);: a# [; z2 X& ~' F3 b) {4 }6 Y
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
- I* K1 L! `3 I5 |& I3 _$ u5 t- v, @2 {( D1 [2 R" B' S% T
line(x+100,y+110+100*i,x+100,y+20+100*i);
* t- X6 c- U8 X$ e% ^line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
# V0 w! O& ^1 [5 {% N5 O1 Dline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
3 X0 ^! g+ {; z0 ~) P7 p9 T5 R) }for(j=0;j<num-1;j++)
/ ]" ~  V$ A) ]5 J* U6 p{
: f& L" {/ s3 }3 Q1 o% Mline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
! E! D3 i! G& Pline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
; Q8 g- H( D! K( Xline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
1 s& t( J; n, q+ n3 D}0 }4 p* i& Y' k& a! s
}
" q% R, {: Y* H}! a0 {* T8 h6 D. D
else if(FLAG_TT==1)
- m; U, `$ Y5 m8 ]' t/ _" x$ o- R{  d3 Z! o+ `0 p# i7 L( x  K
x=0,y=0;
9 f6 e- ]2 S4 ffor(i=0; i<num; i++)
# n; G* w- }/ |4 d8 z) {{
( f" c  q; N$ e3 c) O, Wt = (float)info[0];
- @7 d% \% F# Jtemp = (t/101)*180;. p" N3 r8 y1 I6 g$ o. T
pos[0][0] = (10-num+i)*50+x+650;/ N! ?( r$ `4 S1 x4 K0 f+ F6 U4 ^
pos[0][1] = y+210-(int)temp;
+ r# n4 ^1 w$ k* Vt = (float)info[1];
! D" J. t# L# U& mtemp = (t/101)*180;% i6 F0 A6 j% p& l
pos[1][0] = (10-num+i)*50+x+650;$ q" ]0 p8 V$ D3 Z: K+ @0 x# q( f
pos[1][1] = y+420-(int)temp;
+ H7 B7 W$ H% ct = (float)info[2];
1 B/ G2 S2 {& U! q( d; Jtemp = (float)(t/101)*180;. m) K, ~4 O$ `, M! k' A: T
pos[2][0] = (10-num+i)*50+x+650;
  u$ S/ |# H/ u# C" q& I! Epos[2][1] = y+630-(int)temp;
# Z' ]" b; W* o# N}/ _3 `. [  @$ S0 h# }3 B, c7 G) ^
clearrectangle(x,y,x+1200,y+650);' L7 Z- {  j+ R+ x
settextstyle(40, 20, _T("楷体"));
2 W- }7 w) Y& R2 P* Routtextxy(x+50,y+50,"TT");
( B- u  l& J$ z# L9 Y* W  mouttextxy(x+280,y+20,"CPU");       //画柱状图
# U3 B3 N0 [4 N" zouttextxy(x+285,y+20+200,"IO");) _7 S- A+ T9 B3 I. J
outtextxy(x+250,y+20+400,"change");  l: ?0 o( E3 F! u7 _' Q
rectangle(x+270,y+65,x+330,y+215);
$ ?/ L7 c$ I0 m. S; ~, d, ^9 qrectangle(x+270,y+265,x+330,y+415);
2 H1 X- {" e/ d5 T3 X! X6 l+ wrectangle(x+270,y+465,x+330,y+615);9 T5 G% M* C# [; o% x
outtextxy(x+290,y+620,"TT");
) V+ j( G2 ?" vt = (float)com;0 j9 ?  J0 X: n- u6 F3 H
temp=(t/101)*150;
$ w/ j' a. p6 n* C; X, A1 Mfillrectangle(x+270,y+215-(int)temp,x+330,y+215);, |, {5 p2 I; s
t = (float)wai;
2 w; @/ f1 W( m/ a% Ttemp=(t/101)*150;
' E" |- q* C' i: mfillrectangle(x+270,y+415-(int)temp,x+330,y+415);; b3 P8 R, x8 F! N0 ?+ X
t = (float)cha;" h4 E$ w. h  j% j  t
temp=(t/101)*150;
- W7 P) \1 }8 v) ^# ]fillrectangle(x+270,y+615-(int)temp,x+330,y+615);2 u5 Y- V/ g+ ], C
for(i=0; i<3; i++)   //画坐标   high=90,length=250
4 T. |0 z, @( O{
* d6 n1 O, S9 v5 {" ^, `line(x+650,y+210+210*i,x+1150,y+210+210*i);
9 p, @; E& ^) `  R" sline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);; R+ Z1 V/ T$ @7 U
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
$ H$ B! A: c9 C: {4 `; {* m; ~" P- e2 c+ g& s
line(x+650,y+210+210*i,x+650,y+20+210*i);
/ k/ f& r: t+ P5 q# y9 m# K# pline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);. Z# b0 S- e: z" I
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);3 ]- C" [* q0 O! \% c
for(j=0;j<num-1;j++): Q. J' t$ I5 v2 |: `" a2 z; {) R
{' M) k  ^$ Y7 n0 U" l- g
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
2 v$ Q) `/ D$ V7 Zline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
! L' t, d' p& H$ yline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
+ d- e" [) z% X" p7 D}
& l$ W8 o$ M. G( I4 ]}
" D2 @1 f; u7 J) V) \( ]}
% ]  K8 t6 R) b1 N- ~- Y+ p
6 k3 h& L+ L9 @8 f( h4 N5 x: R; i8 j# H& a7 [+ w  z
return 0;" \3 ~% i8 p8 w4 v4 I4 p
}
5 h1 N: S7 ?; I( d% {! Y- n' |int drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)
1 _  I8 P- d, h& C. x! R8 y{# f* |: U' j9 s/ ?
static int info[11][3],num=0;2 i( y0 O+ P8 t4 V
int i=0,j=0,pos[10][3][2];
' s$ i9 S: T* |+ Q8 z6 }" nfloat temp,t;
) [$ o" V9 @$ X+ a8 einfo[num][0] = com;
7 X0 b8 [  E  R1 uinfo[num][1] = wai;: I7 `1 ]% i! H: @% I
info[num++][2] = cha;
+ c& n' f, n" Tif(num>10)  //存储10个点1 ?7 d9 ^' W" g2 C5 r5 M
{
% k! K) Y- [; l/ E5 tfor(i=0 ;i<10;i++)
; r8 q" a7 m* Y* ^4 C) g: l{1 E9 l3 L1 x+ a8 ^1 w2 v
info[0] = info[i+1][0];1 R6 y6 d6 g3 s# q
info[1] = info[i+1][1];
/ F2 y+ x6 F& c9 m, ^+ ]info[2] = info[i+1][2];
1 S" o' ^4 y3 Y+ x7 U2 V/ J3 S}% X# k: R0 Y3 Z) M  N, n. \
num--;9 n* E8 P  c, E$ ]
}
+ \% A/ @0 G* a8 m! ^6 Jif(FLAG_show==0)
9 o9 ?5 L$ g% t2 v8 H( ]return 0;
  q: h0 b0 D; k7 m" ifor(i=0; i<num; i++): ?# ^) L  Y/ _" `
{: T$ ^! M2 |8 e, M" K5 V2 R& T! {
t = (float)info[0];$ [" f" J! [* Q$ ?
temp = (t/101)*90;, t+ ?" W/ i! w. g4 s' K6 o
pos[0][0] = (10-num+i)*25+x+100;6 L+ L8 b7 n, A' R2 R- D8 p9 y1 @. b
pos[0][1] = y+110-(int)temp;0 w/ O+ F6 f2 m3 U7 O$ L
t = (float)info[1];
, \. M5 d8 T5 Etemp = (t/101)*90;
8 s9 d, p4 N. g) ?/ e/ hpos[1][0] = (10-num+i)*25+x+100;
5 S9 G/ d  B; U; dpos[1][1] = y+210-(int)temp;4 s3 L* M9 j# t: P9 y) F
t = (float)info[2];) K! q9 e1 _$ S6 `0 _8 B4 [
temp = (float)(t/101)*90;) g9 f3 d# a" n; s& \8 g" T
pos[2][0] = (10-num+i)*25+x+100;! D( n4 F! v4 G8 S2 r( o2 E
pos[2][1] = y+310-(int)temp;8 Y- X" L/ g2 C9 I' l
}1 {* t+ r/ E: ]
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)' Q  Z2 ^3 c% `1 Q6 ~
{
0 _) G/ F/ W& N' ^  J+ [2 `clearrectangle(x,y,x+400,y+315);
! t( X2 v# V3 ]' K# `settextstyle(20, 10, _T("楷体"));# k% R  K# Y/ K. T# f# {
rectangle(x,y,x+400,y+325);
8 }) ]0 Y$ x( V/ Douttextxy(x+40,y+10,"CPU");       //画柱状图; f$ E+ ^% X; i& x2 N6 O) l
outtextxy(x+45,y+10+100,"IO");
' N! t& M% x4 X1 M; p# ?/ U- D  Iouttextxy(x+40-15,y+10+200,"change");6 W! r: w; I) h& i% w% Q, n. \
rectangle(x+35,y+30,x+75,y+110);
& h- }) F5 Y6 S. R& |rectangle(x+35,y+130,x+75,y+210);9 J1 Y4 M* Q: ^: K
rectangle(x+35,y+230,x+75,y+310);
5 b6 _, R' z4 Q5 Gouttextxy(x+180,y+310,"PF");
$ E$ u4 d. D' a+ k) s7 }* Nt = (float)com;
  c& Y. L* P; [- m, Ftemp=(t/101)*80;% n; u: Z7 u7 V
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
% \  ^: J( B' b$ h& P/ |t = (float)wai;) Q! t9 n" H) K$ H
temp=(t/101)*80;
- H; p4 q6 }( I4 G% B* d  B% Gfillrectangle(x+35,y+210-(int)temp,x+75,y+210);& Y1 X1 c/ B0 `
t = (float)cha;' t/ A' F- D+ s) q% p5 x4 ]( P8 H/ u
temp=(t/101)*80;
& F0 x' c  t& W; o" U0 \/ ~! y+ K, Rfillrectangle(x+35,y+310-(int)temp,x+75,y+310);5 w. ]9 {! n$ F( h5 p) b9 m" i
for(i=0; i<3; i++)   //画坐标   high=90,length=250
  C# J6 z1 f4 W: ]; F  l{
' ~+ a- k4 m5 g  r" uline(x+100,y+110+100*i,x+350,y+110+100*i);
0 h, w$ P7 T2 \7 a5 w5 qline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
" v; n" k% @; S; z) y& d. k. kline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);; h* h2 @) Y4 p  Q1 v
0 C3 L1 b8 r- f) N
line(x+100,y+110+100*i,x+100,y+20+100*i);
7 a# }; f6 Q2 p3 @- pline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
; X- j* [; o( x0 @+ aline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
! o" q# S7 [" [" D4 T- [6 z+ Wfor(j=0;j<num-1;j++)
7 y; e9 M8 L, v" M+ B$ M, |# t% w{4 P' ]. l4 }9 g4 m. u/ L
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
8 v4 X2 ]: R% Xline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
! t% C+ v" D. r! M" f# x$ {line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
" y0 v3 u. ]1 }) y0 U/ _3 v}- a, n" [. P  R; _. ^) g
}/ B3 s) n% h: D: z' Z3 r
}) ~9 s0 }! G& c: d# m; m
else if(FLAG_PF==1)' I9 f; V  Q, `- L
{* ]. O' c1 n4 r( Z
x=0,y=0;* v5 y: d" s8 p7 A, I0 m
for(i=0; i<num; i++)+ D. ?) s9 I) }0 g% V+ V" V( \
{
. D9 E- P' {' V' V8 k4 o/ I9 j+ dt = (float)info[0];# Y% E' |- h  e6 V" a+ V0 O
temp = (t/101)*180;6 Y3 x' }# I2 g$ T* n4 c
pos[0][0] = (10-num+i)*50+x+650;& w& J6 G# C: k+ G- C' q
pos[0][1] = y+210-(int)temp;
1 z% _" Q/ ?7 s( e' ^6 G" M% {t = (float)info[1];
4 o4 b/ h/ m+ P  s- Y% Htemp = (t/101)*180;; b% a" b' T& W8 a1 E2 r7 l
pos[1][0] = (10-num+i)*50+x+650;  ^3 r- P# ~; Y9 N! K; r/ K0 }! e% t
pos[1][1] = y+420-(int)temp;
, T4 Z- P$ [* e) n' I0 ]- yt = (float)info[2];- T1 v' `& O3 K- d: T4 J' U4 @- W
temp = (float)(t/101)*180;7 g! y/ q. e, q
pos[2][0] = (10-num+i)*50+x+650;
6 s. m# v; K. Q# s2 E3 H& e! {pos[2][1] = y+630-(int)temp;! b/ H$ [, m" s3 |) A9 y# r( v7 r
}- J; T+ p% U/ L7 M8 G4 a9 m
clearrectangle(x,y,x+1200,y+650);( x2 V% o: j+ C7 E
settextstyle(40, 20, _T("楷体"));
% k# q3 _/ z( s( q$ R' louttextxy(x+50,y+50,"PF");0 j, k4 y7 d' \" d' c2 [% g0 [
outtextxy(x+280,y+20,"CPU");       //画柱状图3 R" G& K' s' h7 x/ @2 x
outtextxy(x+285,y+20+200,"IO");* J. i8 {- C8 y) r$ v& x
outtextxy(x+250,y+20+400,"change");( E5 Z! T2 m$ H% M' |
rectangle(x+270,y+65,x+330,y+215);* v* E- G1 J4 h  n* q0 c
rectangle(x+270,y+265,x+330,y+415);$ o6 e% |* R* d1 u. }' s0 B9 K
rectangle(x+270,y+465,x+330,y+615);0 n1 O5 x. R" @- t
outtextxy(x+290,y+620,"TT");
7 Q# M8 x; U. i5 nt = (float)com;
' l6 Z' l/ I5 Utemp=(t/101)*150;4 Z$ x4 {6 V5 b) j7 d. |2 g" S
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);/ u7 P- P; H0 O+ p
t = (float)wai;5 D2 }3 n) C. n6 b( q6 M* a, p
temp=(t/101)*150;
0 {% L- P* {4 c  G9 i: z* m. \fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
" I7 t% A( h. `/ g; s' O- gt = (float)cha;
+ X( @2 t" x9 F6 P2 z2 Ftemp=(t/101)*150;
# g, Y5 F# h1 ^% ~& Afillrectangle(x+270,y+615-(int)temp,x+330,y+615);
1 V- t2 i# N6 Y% L2 Dfor(i=0; i<3; i++)   //画坐标   high=90,length=2509 L1 R; b+ n( M" X
{+ w5 G1 I3 W( L8 ]* Z1 {
line(x+650,y+210+210*i,x+1150,y+210+210*i);
6 \% T" g' X+ [, L1 u: Eline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
9 R  }: E9 m7 P9 [, ^' W+ Jline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
- L' S) F) M0 r# N3 F6 _! ?
% t2 i$ w& O3 M7 V8 M9 aline(x+650,y+210+210*i,x+650,y+20+210*i);) h, n8 |2 m: @; S, v* Z& c
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
2 c; J# s* W$ E/ |line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);/ ?9 E2 }" U0 E1 C0 |3 A7 ?
for(j=0;j<num-1;j++)7 e9 u* T; ^1 }- f
{, h2 w, p& n; g" t6 D
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
+ n4 t% K" }& y! Yline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);" t" j* o% W: @# j8 z. A5 ]! Q$ x" W
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
9 s1 n$ R. R, L# s}  M5 F5 s; d' L8 ?6 e
}" M- j1 i+ c5 K. z$ X
}
8 X" ^) k$ A8 ?0 m  e' `* O7 Breturn 0;5 b$ E  G, a% j: E5 P; w
}* ^- \# s' S+ r$ |5 ^" B! h; J3 o$ W8 R
int drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)! M$ f3 l$ U+ q; l( Z( X
{
- |7 t3 s- @0 s/ k6 e  Zstatic int info[11][3],num=0;) A; o( Q  a- x
int i=0,j=0,pos[10][3][2];
' W: [& ^. ~/ h* W, Z6 Qfloat temp,t;
/ O2 b% y. d! ^. i" T4 T6 ?: ninfo[num][0] = com;% k3 _* l; P# W: a$ \5 L) L
info[num][1] = wai;8 ?; A3 W; o' I: t# q* i# i
info[num++][2] = cha;. k$ y4 V1 F8 d+ F) ~3 Z  ]( o
if(num>10)  //存储10个点
/ e+ y  W: a* X{
. T. C& T6 J# Q  M- ^" Z& [for(i=0 ;i<10;i++)
6 A: e' v4 \6 i) S! O* |- Y8 w{
% o! \4 r- J. A1 O0 iinfo[0] = info[i+1][0];: ]+ N, q; E0 K3 ?& [) _
info[1] = info[i+1][1];
; \$ `! g; k1 R! o* J* xinfo[2] = info[i+1][2];
$ x- d2 J% k$ o4 W}
7 P; m. U; `+ w2 F0 [num--;! ]9 y) G. N6 v+ Q& P' C( C
}" R! K4 C* c, ^
if(FLAG_show==0)/ q1 s; |- i. B4 B( G
return 0;
6 U0 _% m2 v# g: {! s/ ~for(i=0; i<num; i++)
0 e; }9 i1 R- F, j: l{* `. V$ @1 z! A- t
t = (float)info[0];$ h% G+ J! d9 ~. B
temp = (t/101)*90;
$ J7 H: |# G0 b' Z/ [  D' f5 X( l$ opos[0][0] = (10-num+i)*25+x+100;# c; O6 }1 d4 j" o* f8 R
pos[0][1] = y+110-(int)temp;
% \2 S: d4 `" O4 |" M! ~t = (float)info[1];4 J# x% C: G* J# U; m, D3 v0 W; k$ T
temp = (t/101)*90;
* R: X5 b9 D0 C$ t: ~pos[1][0] = (10-num+i)*25+x+100;! B: A5 i5 D( B- k' h8 F
pos[1][1] = y+210-(int)temp;
2 u# o% S+ a0 H& M. L" Ot = (float)info[2];
" w; N9 ]. I7 W& t+ f: btemp = (float)(t/101)*90;! [! P$ O% G; @2 B
pos[2][0] = (10-num+i)*25+x+100;# G) E" y7 Z0 f/ b) C) \, w
pos[2][1] = y+310-(int)temp;
: R+ g, f! V; E  }6 i9 l: f2 g2 o}
8 h$ s2 I/ D& L! K# z8 M8 P/ zif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
9 N0 j. ]8 d0 Q4 f{ $ V/ A# x" x5 g8 h$ y
clearrectangle(x,y,x+400,y+315);
2 }5 x# f6 g$ N) l) rsettextstyle(20, 10, _T("楷体"));1 k' e5 S& f6 Z8 C( Y  _; \# X. ]
rectangle(x,y,x+400,y+325);: t& b/ [( D3 y! A& J7 o0 _& g
outtextxy(x+40,y+10,"CPU");       //画柱状图
& i2 R2 y7 E6 x4 m% C% ?outtextxy(x+45,y+10+100,"IO");
' C0 j. [; q  @outtextxy(x+40-15,y+10+200,"change");
" Y6 ]( {2 n$ c0 x# Mrectangle(x+35,y+30,x+75,y+110);+ A+ K# v  b6 R, C* f' ?
rectangle(x+35,y+130,x+75,y+210);  Y: r1 N( m5 L+ L8 B6 e; \, s
rectangle(x+35,y+230,x+75,y+310);
) p9 L) V2 V5 h4 Z5 B5 E1 zouttextxy(x+180,y+310,"SJF");
4 A$ N; |3 ?+ Z9 w) Et = (float)com;6 a, e, Q( E% `: a. P5 c, J
temp=(t/101)*80;
& i* m' b8 B0 G  kfillrectangle(x+35,y+110-(int)temp,x+75,y+110);
7 b$ @. P8 P: ]7 [2 C8 Ut = (float)wai;
7 `* O0 A4 C4 S; i4 h" U2 _temp=(t/101)*80;5 f' b+ w* z9 A& c/ S
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);3 L! S- n8 G/ I
t = (float)cha;3 A  B2 w; f7 s; y$ z
temp=(t/101)*80;+ C4 a8 U5 u+ z1 m& y
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);: [5 M4 Q* t9 e, t4 I& p8 ~5 e
for(i=0; i<3; i++)   //画坐标   high=90,length=250- u0 m5 {! S. ~6 C6 [$ Y
{! S( Y# e/ F; m, D; M" u
line(x+100,y+110+100*i,x+350,y+110+100*i);
1 }& M7 h  q' t- F$ ]- Y0 v! b4 iline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);: Y% u8 w9 t; x# ?" n8 |
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
8 |; ^# ^) I9 ]( S9 m4 V8 v0 P2 X7 [. E3 W8 @) A, ?& ?
line(x+100,y+110+100*i,x+100,y+20+100*i);
  M6 p7 b9 ~( j" D8 M+ H, S5 Lline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);6 ?9 |$ K+ R& [/ Y5 F) p3 c
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);% u, `! T7 R* c1 I2 B! K6 ^
for(j=0;j<num-1;j++)
2 u3 P: p( f  X' E, F{
8 O) A1 e# Z- w7 X2 yline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
3 v( d+ ^) Y) B3 `5 u; e+ S0 ?line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
5 |; W& x, Q3 `+ ^( sline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); % g2 Y! I: M6 x6 g7 v
}
2 L) H) _( j! c7 h7 q: `$ @9 I}
* S* K) c9 H+ I. S+ ^}  g, k8 }; ]1 A, B- \' g
else if(FLAG_SJF==1): j/ Z8 X  U7 H: s0 X) R( I
{( t9 r) q; b" J. z7 ~- Y' s8 D, L" A
x=0,y=0;
  l1 W" A& d- I, Q) t1 R9 }9 Pfor(i=0; i<num; i++)6 [! W  C( n- }: n6 }6 X+ e" Y" R$ v
{# L1 J$ P# y" D# \) L. L9 b! L9 m
t = (float)info[0];
9 ~/ M" U  S" u$ H  v3 ftemp = (t/101)*180;
4 J9 [! N' o. k) J- y+ ypos[0][0] = (10-num+i)*50+x+650;
6 f& s3 z) o7 h  l+ v0 spos[0][1] = y+210-(int)temp;
' r. U0 f5 ?5 D( lt = (float)info[1];) ^1 ?" S' G7 {. |5 r- M1 Y
temp = (t/101)*180;
0 p) U: B) |. `' z) t/ u& Wpos[1][0] = (10-num+i)*50+x+650;
/ n, p1 ]5 t2 f# w7 A. L! @0 Tpos[1][1] = y+420-(int)temp;
( }# F  i+ O' C- |t = (float)info[2];
) F- k& b/ w. s1 btemp = (float)(t/101)*180;
3 C7 T1 s/ q  W. Xpos[2][0] = (10-num+i)*50+x+650;. u& [# J! P  g4 Q
pos[2][1] = y+630-(int)temp;
1 J& q  G/ p0 {( `  @}
; y% |) f* B- x! s1 }clearrectangle(x,y,x+1200,y+650);
8 k7 s# ~! B% |9 ~settextstyle(40, 20, _T("楷体"));
$ P* n# _5 Q( Wouttextxy(x+50,y+50,"SJF");% Q) y) _% L+ {+ [- ?
outtextxy(x+280,y+20,"CPU");       //画柱状图
- ~; \- W, W  Y% A/ v: l4 routtextxy(x+285,y+20+200,"IO");/ A8 @& G4 z4 Z  \" b9 k* @/ @# \" p
outtextxy(x+250,y+20+400,"change");
/ p! a0 ?. \: v9 @rectangle(x+270,y+65,x+330,y+215);
0 |0 E$ F/ Z3 F7 hrectangle(x+270,y+265,x+330,y+415);
$ r% I% s; P3 ]5 x$ c( irectangle(x+270,y+465,x+330,y+615);
& H; ^0 I! [$ _) X% |outtextxy(x+290,y+620,"TT");& [3 r8 d- g, I# U! h) s, l1 t
t = (float)com;5 h$ Z0 @% a( u7 B" D
temp=(t/101)*150;
+ h2 [  L( C' j* Ufillrectangle(x+270,y+215-(int)temp,x+330,y+215);
3 L: u) P. Z: _; T6 r5 Ut = (float)wai;
' z/ V6 J3 h# Ttemp=(t/101)*150;
$ U* P8 _$ W3 b. g3 d6 x, efillrectangle(x+270,y+415-(int)temp,x+330,y+415);* V) P+ Y1 h, c" _) I8 O9 g
t = (float)cha;
- ?' s( @' e7 L8 a  ktemp=(t/101)*150;
* ]  G# ^% A6 C' }2 B2 ]  L) lfillrectangle(x+270,y+615-(int)temp,x+330,y+615);: @9 e& H: @7 U- A4 q
for(i=0; i<3; i++)   //画坐标   high=90,length=2500 u' h% N9 M  z" n
{& w( u. O/ Q, f# O4 o$ S+ p. U
line(x+650,y+210+210*i,x+1150,y+210+210*i);
: F4 Q, R5 A+ r3 Dline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);; P% R3 p" }7 \2 _
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
( |2 p- v5 R" O2 z
% ], k' J, j9 Gline(x+650,y+210+210*i,x+650,y+20+210*i);0 l$ P; V0 `9 w4 @9 A
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);/ R. r: u9 d3 ^& n" ^
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
/ `7 @6 P  q* h% B4 ufor(j=0;j<num-1;j++)6 c, I' c; u1 I2 M3 L. b* I
{6 {, T( [* K8 ~, \2 O7 l0 o6 n2 {
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);: n$ D% i$ n" h9 u% n
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
0 k% F" {" e9 F1 j9 l% g8 J4 }line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); % R! H+ \$ d" }6 ^6 `
}9 U  o. g. k) E( ~% Z: L/ W* ^8 `
}  M& `+ E# P* p
}
/ j9 Q* u' m* E* d& r  dreturn 0;8 Z1 C/ A" {! m9 W2 B, @
}" q5 s: e7 l! }: j! L0 Y" @
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
# G" q' c. c. R7 L{
9 N) m% ~' v! Fstatic int compute=0,waitio=0,change=0;
3 {2 p: d0 v* r; g" l7 rstatic int computeLast=0,waitioLast=0,changeLast=0;) q5 z+ J9 A; ^* y2 q
int i=0;
# p" @. i) A. w; hif(draw==1)2 p6 z6 o+ M4 F& B
{
/ L, u, H* \; @, c. t8 w! q2 Y//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);) g& d; B% Y9 X7 t. |8 C
drawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);0 T/ A8 U. Z0 j3 V
computeLast=compute;& R4 w& @6 {: `7 Y
waitioLast=waitio;* F5 K# S4 b" B
changeLast=change;
/ O! t! S/ Y$ J3 F6 C# c}1 p6 F  o* A' o: W
if((* memory).p[0].flag==ready)
. B( D, L- ?( T(* memory).p[0].flag=computing;
, `. u' ?8 T2 U& s# L# Cif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
, a( X; E+ W; [2 ]4 E{  h! ^; d3 F+ a7 H5 _& |
i=(*memory).p[0].computeNum;
3 k5 @' @9 a. B, t& {if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed/ ^9 ^: i1 {+ F" p( C
{
/ M$ T$ ^3 n2 x: @" u+ ](*memory).p[0].flag=IO_waiting;! Y% \! s, ]$ T% n8 v# M9 i9 G$ m
(*memory).p[0].computeNum--;5 e+ y. y/ O: x' u- k, ?
change += exchange_IO_Compute;% a( \7 a+ _1 q8 w* K3 A$ W6 a  b
compute++;" Q3 @3 q0 I; U/ U0 i( x4 I% O; x
}
. [9 q( ~" l) t( [3 w5 T( }else
0 \# `2 }; V7 _  p9 M{; ]$ P: e8 f' e! H6 H
compute++;
  F4 ?* d* t+ k- y2 }' T- F2 c! K}% Z! I8 Q1 A8 c1 R1 T! A5 H9 W
}
* l( u9 P! q- t1 F, X( Zelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
/ o% U6 C) L3 h; x6 u{
' `+ C: Y) H9 g+ h5 D2 Y
( L0 L+ U  Z8 V4 Q6 h6 ]i=(*memory).p[0].ioNum;* b. }% V) h# q" p7 s$ S
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
9 p& S, t' w- @/ \( z{
* ^6 |# ]9 t0 ], p/ O6 X. |(*memory).p[0].flag=computing;% j- ?6 J8 \# `& u$ F6 D
(*memory).p[0].ioNum--;# A% b4 p' {% I% l/ S2 T5 m4 J  e5 _
change += exchange_IO_Compute;
! w! Z* _5 I% Y' m4 P' Bwaitio++;7 X3 b- Y( B0 k; \, x: W) X8 \
}
7 u2 e7 Y$ W0 c" P% ~* lelse/ G2 h" d; U" i5 {3 E3 T
{/ H" |# I; N! U
waitio++;6 `: _* s% `; Y; i- D
}
) d& Z8 T: y( k7 i) ]}$ t, z0 A  p; o3 `( C
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing). k& b- C1 ?1 I" _( b# B8 r
{  @0 X- e' n% H9 T9 {
(* memory).p[0].flag=IO_waiting;: }9 x2 F% K; B' m$ k9 ]9 ]! L
change += exchange_IO_Compute;4 @4 i! {. {! W; ~& m3 n2 O$ e3 A
}' N, u+ h, |7 ]; O$ M2 Z
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
) ^; g. S3 i: P6 g' D{
) \: p6 j6 G+ `4 R, h6 \8 I3 G(* memory).p[0].flag=computing;
2 e/ C; m) v( \change += exchange_IO_Compute;7 F4 O6 C, C% S
}
9 P) k# d+ q, e, x! @+ hif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0)  //一个作业已经完成
7 B! h3 `0 N& P) w' b! _{
& `& v) G- m) i$ o% W/ q(*save) = (PCI*)malloc(sizeof(PCI));; E) M$ q" q/ O) t$ K' M
(*save)->next = NULL;4 W8 H7 l4 K: x( E% d7 g# r. W
(*save)->processID = (*memory).p[0].processID;% P# {- v6 q0 [( Q3 u0 v& |1 w
(*save)->comeingTime = (*memory).p[0].produceTime;
9 D! Z! @! C* V& z/ A(*save)->askMemory = (*memory).p[0].askMemory;
8 ?& N9 _* i: b0 S+ D(*save)->compute = compute;
( S9 _' l  Y, r6 _(*save)->waitio = waitio;% D" u" g" S3 t& m/ s
(*save)->exchange = change;& E; Q& W  q  @2 |& Q6 B
(*save)->completedTime = systemClock;+ o: [% ^9 {$ g
(*save)->runningTime = (*memory).p[0].runningTime;5 K( X5 t! M' V3 ]
*spareMemory = MAX_MEMORY;         //*spareMemory + (*memory).p[0].askMemory;7 ~( w1 n5 `4 H
compute=waitio=change=0;
1 A  h" X5 v. q9 T1 p5 NcomputeLast=waitioLast=changeLast=0;1 {3 {- Y- N9 N. V: v
High_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);
! i; E+ D: O$ bchange += exchange_process;
) h# e  ^9 Q: N& Rreturn task_completed;
3 q: k: ]5 t9 Z) M}
# [7 j; w, u  j% selse
: |* |5 s  |2 Sreturn task_not_completed;, ^$ }" g; a2 f
}
. i* r" r6 R! V2 {8 c, A. k3 [int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)/ d9 k. u+ ~- g: D8 i/ L: m, m
{
7 m) [. F) _7 \) [; B) W" Hstatic int waitTime[initProcessNum],i=0,j=0;+ O  H$ Y% P% K5 ~( ?2 k
static double HR_ratio[initProcessNum];/ l1 f; e( N2 i9 _& |/ q4 k3 Z
if(flag==0)                    //初始化数组3 P/ W$ V! Z! X8 O4 h3 j
{( ~" t. G! I$ g  c' r
for(i=0; i<initProcessNum; i++)7 ^0 h, `- b& U% P; w
{' u1 N: z1 L$ @  n
waitTime=0;# x- x4 J; P" {6 O& q  f% q5 G4 o1 z8 A6 l
HR_ratio=1;  Y: N1 A& t4 N4 {( G
}! e4 Q: f* z5 X& I7 G4 v
}0 r9 ?# z/ c; H; m+ ^+ S) J' y
for(i=0; i<(*storage).proNum; i++)  //等待时间增加,重置响应比5 p, |- Y! v: u& A
{" t4 t" f, Y& R+ l. F% D
waitTime++;; W/ v) f  s) ]; x$ d6 q
HR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);
& H, y+ E# H6 z- E1 ]if(HR_ratio > HR_ratio[j])5 \) h; b& Q" x. g
j = i;5 @, S: r$ `+ u- o
}
" {. ^) r/ s% Y. pif(dispatch==1)                    //需要调度一个进程到内存中执行
" D0 W3 C7 O# t& u{5 v1 R6 m! |" \! V& e
if((*storage).p[j].askMemory < *spareMemory)' P* w: w( [0 M* ~( `, o5 H
{
, O; ^! ~# V$ R2 o6 }) Y1 n(*memory).p[0].askMemory = (*storage).p[j].askMemory;; L# g- H+ P) h+ o0 u1 p
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;1 {8 w# i( `% [
(*memory).p[0].computeNum = (*storage).p[j].computeNum;
$ ?9 F8 L2 ^( M9 j(*memory).p[0].ioNum = (*storage).p[j].ioNum;5 x! @5 G, o, V6 [' h
(*memory).p[0].processID = (*storage).p[j].processID;$ \9 A) F* O/ Q/ y
(*memory).p[0].flag = (*storage).p[j].flag;% V( P$ F6 K/ Y, z. w2 z
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
: {" @) Y  R/ O: c  }) M0 E(*memory).p[0].computeTime = (*storage).p[j].computeTime;2 x9 B" Y# c& B+ I1 F. N7 |$ O
(*memory).p[0].runningTime = systemClock;# q: g7 D2 `0 K; b. E
(*memory).p[0].produceTime = (*storage).p[j].produceTime;
- N. v1 p0 t" ~2 L; V" Ffor(i=0; i<(*memory).p[0].ioNum; i++)
1 J7 K) G2 Z  q! n(*memory).p[0].ioClock = (*storage).p[j].ioClock;
# P, P" C- f5 \* R% X. b9 \for(i=0; i<(*memory).p[0].computeNum; i++)  S& f. S$ n5 Q5 }8 K* h
(*memory).p[0].computeClock = (*storage).p[j].computeClock;
. k, q1 J: M5 p3 }8 B, r* n4 K6 E(*memory).proNum=1;; |/ i6 N, o! ?% A7 @' Y! A  }
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
; e- J- o* G0 Y( f& v6 wproduce_one_task(&(*storage),j,ID_FIFO++);           //调入一个进程后,再在进程池中新生成一个进程6 _1 c6 }; O5 j1 A+ O
(*storage).p[j].produceTime = systemClock;
; |" {4 ~! e! A& R+ eMAX_COMING_TIME = (*storage).p[j].comeingTime;  D( k3 z3 _0 c, o: ^9 b7 q$ X
waitTime[j] = 0;2 t+ I; Q' x' g$ \$ R/ t
HR_ratio[j] = 1;
3 @# q. p1 q  k6 X& @3 E- N}
2 R5 b5 L8 X3 a! s6 I+ Q6 L& z: Telse; }. J& U$ {8 C
{& b# K" e" p; z, }
printf("A process ask for a memory overed the system capacity\n ");2 W% L( R4 N' ~/ ~. x3 R0 W! O) i- G
exit(1);
. L* V7 O. ]7 V+ N$ `# O( }}, n! Z7 c, \$ G% h0 Y8 u  l; t
}8 A% s7 i3 r( I' x' u0 d; M) m
return 0;, |* R6 O. g! u5 K' o
}8 j  y/ n4 V4 [/ K' c" n0 w, t, P
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)8 r8 f" h* q# E' D
{& q, l. W. b- @$ l
static int compute=0,waitio=0,change=0;9 w5 U! ~! J2 X7 a1 S. e7 i
static int computeLast=0,waitioLast=0,changeLast=0;
6 ]: c1 F' H. p5 E# Y" Hint i=0;
# ~% [( }' m3 w; Iif(draw==1)
+ R4 `) \, J2 k/ Y{
% U" a2 }$ ?6 ?( E+ ?//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);( P: h. Q) D/ K, q1 a. }4 e8 l7 ?
drawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
& L5 M* ?& M" X* w( G- o' A, t8 y: C3 _
, d7 e4 N' O1 ~* C  G4 w4 D4 e1 q
computeLast=compute;( V$ T6 O. E9 R: c" \1 U  G& t
waitioLast=waitio;
" |8 o1 A4 E0 v4 VchangeLast=change;8 `! f( x+ H, h1 m9 B# l+ }9 l
}
2 R' o; p+ N4 k) c5 x6 Dif((* memory).p[0].flag==ready)
% D7 [7 V9 R+ F- R, J1 N+ O(* memory).p[0].flag=computing;
" V# `- z4 H& v0 Hif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
" F  T. b' s6 N( b; H/ [{
0 P9 X: y0 f9 z- }& q  yi=(*memory).p[0].computeNum;  X7 h- o# \1 {7 g& a: S
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
" b6 `0 k) r) T: v! }{8 E8 l' Z0 w, g! v' \! x- W
(*memory).p[0].flag=IO_waiting;/ h& }3 v4 q/ x6 p* f" _; s
(*memory).p[0].computeNum--;6 A. w7 {( B" J7 t- G
change += exchange_IO_Compute;
1 g+ A) }8 Y" y/ Ocompute++;
8 ]- k$ x; m3 [" r  L* R}& T- q) e  l) M" C, N+ i! \
else8 q6 _- u( c& M: V
{* Z6 V% |/ s4 ~9 d- ?. ~$ I
compute++;4 G: E$ ?+ i2 W) A7 Z* {" q
}
2 Z+ N. P; Y0 V- ]2 s# G}/ ^; p& m1 R, \1 A
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting); z0 F8 r8 Z9 ]- z
{2 x7 K1 a6 h( w  I6 G/ I! v

. J: Y/ v5 D1 O$ C0 s; ci=(*memory).p[0].ioNum;) p+ U) V: ^4 C, O
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
5 v1 X" v9 S: [5 i) H( B1 M" o{
/ d0 [! z2 Z& @2 v  e(*memory).p[0].flag=computing;
; P6 K' ?" R: |(*memory).p[0].ioNum--;
( h4 |2 |. g) n8 `: E7 }6 Achange += exchange_IO_Compute;3 f% ~/ {5 u4 g5 B+ n5 Z& I
waitio++;6 w% w) b0 P' b7 k' d3 a: p
}
  D  q6 L* U5 uelse7 G! q7 x' f. ^. ~! R9 A( ?8 S$ j
{; T; R6 ~* P: U
waitio++;
( {2 n8 a! A9 S; O}
; P" j3 d2 @4 F. B}
! o; R. }( b) d# T( ?: u4 E/ relse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)$ c; W( x7 {/ c
{
, w' H% u; k! ](* memory).p[0].flag=IO_waiting;: k4 ~# X0 T, k
change += exchange_IO_Compute;/ D0 u) D9 I9 r1 v  F, |
}
9 o" E* ^& {, T; ~, |1 }  u" Relse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
2 L2 c5 }5 U  y& n3 X+ n! L" }{
& U0 C7 H9 {0 w: w  j(* memory).p[0].flag=computing;; [3 G- Z9 G/ }4 x; M" s/ [
change += exchange_IO_Compute;; K" i1 n" n6 k, C* c( `/ C8 W, j
}
: V: v) |; @) h+ ^: l- D' b. A  lif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0)  //一个作业已经完成
- r+ O& V- h* B3 A7 x7 i3 ^/ y{
: N* u: R7 S% Z9 n, ^(*save) = (PCI*)malloc(sizeof(PCI));
2 I6 J8 n2 v5 \3 n7 T- w(*save)->next = NULL;1 q% n. }8 z& k( r# A$ l: z, `
(*save)->processID = (*memory).p[0].processID;
; M9 I- y$ g1 N) f  U+ c(*save)->comeingTime = (*memory).p[0].produceTime;' g+ I7 X% C9 N! L5 z% N$ |( O
(*save)->askMemory = (*memory).p[0].askMemory;2 E1 F9 O! y6 r/ x  I/ `
(*save)->compute = compute;3 \9 o' S) ]0 n  T) \/ G
(*save)->waitio = waitio;
# d; ~3 p# E% Z! e3 q2 Q9 F$ _4 P* d7 ](*save)->exchange = change;
  c5 g/ x% e+ M  n  ]% Q(*save)->completedTime = systemClock;
+ w* n) }0 f2 ?3 c(*save)->runningTime = (*memory).p[0].runningTime;
4 m) i5 U  |+ O9 T# q3 J5 C*spareMemory = MAX_MEMORY;      //*spareMemory + (*memory).p[0].askMemory;
% r  [* {6 J. W' d! _% [compute=waitio=change=0;
  K- Q, _+ b3 s% C5 scomputeLast=waitioLast=changeLast=0;
. ?# q: ?1 R9 ?) F+ d( jPriority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));+ ?. M9 b5 F+ H( b4 k, j! ~5 y
change += exchange_process;) G) l% r9 F) P! i" g5 w
return task_completed;
. j* x3 F* V( v( F/ q}
  F, R+ ?: w7 q. y& lelse6 G" S) a7 u1 Z% m  V& `) ]
return task_not_completed;
  {1 a& v3 E5 V5 y5 d, Y) r9 U! E. ]}1 o5 g1 ^* z7 H
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)% P, U$ `4 K% g$ S
{$ \* w: j8 C8 o
int priorityNum[initProcessNum],i=0,j=0;
& P4 y" U; l- L* ?' i  Z, n- g+ ]double temp=0;0 I9 c4 B9 J8 E: D+ W$ p+ y" m1 F
for(i=0; i<(*storage).proNum; i++)    // setting priority to each process
" y: `+ I  h1 Q, J% m, G* }{0 ^1 l9 W7 [: G4 o) g8 o
temp = (*storage).p.computeTime/(*storage).p.ioTime;- A( U8 {! n# U2 e, t6 I: |
if(temp > 0.8)
, v! }. A3 g% `1 zpriorityNum = 6;7 D. h! t* q( V4 Z; f- M
else if(temp > 0.7)
; H' Q8 ]) u7 r" RpriorityNum = 5;% I2 j% k2 w9 _+ ~# I) @( W- y, A; `
else if(temp > 0.6)% e/ K4 y. ]- h* N3 U3 ], F9 R
priorityNum = 4;7 _/ ~5 j& ?5 ^. F5 F4 x* ]; v
else if(temp > 0.5)
  k7 L* `. A% O+ z, TpriorityNum = 3;
. [2 s  D2 U* X! ]else if(temp > 0.4)* ^+ t$ H5 }+ ]8 |' G0 }% m( u
priorityNum = 2;
- Y4 ^* [# N/ w8 velse
! L+ O% k0 s2 v- ^" S. W. PpriorityNum = 1;  V* Q1 Y! p9 i4 m* {! w: h
if(priorityNum[j] < priorityNum)4 V/ b6 E2 u- D7 G: q' V
j = i;1 }0 o$ }. G" H# E2 `5 k; ~" M
}
+ V; R" @' p4 ^) x! A7 Lif((*storage).p[j].askMemory < *spareMemory)
6 Y, p! G% s; K- Y% {1 S" P2 j0 s{$ g) x9 I  F4 r0 g1 s/ z" ~8 C
(*memory).p[0].askMemory = (*storage).p[j].askMemory;6 ^/ d' E, _3 Z: u" e
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
0 o8 X7 g4 ^7 f5 o* b(*memory).p[0].computeNum = (*storage).p[j].computeNum;" ^9 z4 P' e$ v. E& J& b1 k
(*memory).p[0].ioNum = (*storage).p[j].ioNum;/ h( b6 Y$ C2 N+ p! p3 `8 X1 ?
(*memory).p[0].processID = (*storage).p[j].processID;, b8 C/ n0 |; `9 n7 g( u
(*memory).p[0].flag = (*storage).p[j].flag;! w. }) Z. F, t& ?, M
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
3 {8 ~4 h( a% w; o(*memory).p[0].computeTime = (*storage).p[j].computeTime;
) S8 c( R$ V/ i# w/ o0 [8 I! W(*memory).p[0].runningTime = systemClock;0 J! w& Z; v0 f! ~* s
(*memory).p[0].produceTime = (*storage).p[j].produceTime;, H3 `- G; P. F8 D/ Y% V
for(i=0; i<(*memory).p[0].ioNum; i++)  P2 ~) }- K6 ^& s& K
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
" {/ x6 a" v3 s& X) y) u5 zfor(i=0; i<(*memory).p[0].computeNum; i++)
! }! K' N$ ~4 F# p(*memory).p[0].computeClock = (*storage).p[j].computeClock;0 \) U& e. d8 G6 Y+ ~+ I- |; P$ t
(*memory).proNum=1;; j! S- W" U" U! z+ w+ H4 q4 b+ w
*spareMemory = *spareMemory - (*memory).p[j].askMemory;3 [4 s' K6 p$ Q# M* G
produce_one_task(&(*storage),j,ID_FIFO++);           //调入一个进程后,再在进程池中新生成一个进程0 m7 H( M  j! D) G% v( Z+ F
MAX_COMING_TIME = (*storage).p[j].comeingTime;
3 B# l% H$ V8 B, ^6 L$ K}
0 c4 ?! ]% e5 ?2 J; W; Telse
) |4 l! C, i- x& `5 v4 u{- s6 [5 h9 l+ _* q, b) O
printf("A process ask for a memory overed the system capacity\n ");
. `8 m1 m( l; b5 k& r. |exit(1);( {" d) j/ C6 q+ S1 d
}7 h* S) K8 l+ ]
return 0;
' e- M, k" C' `: K}  p7 ~  _+ W# n
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)" g; F9 t; G" Q1 @0 U4 G
{
7 x9 Z5 G. z! q4 [3 j# L( Astatic int compute=0,waitio=0,change=0;) x% Y* G* \' I: ?
static int computeLast=0,waitioLast=0,changeLast=0;
3 R% d5 r9 p, w/ Lint i=0;- S- M, G- G- H+ [/ W
if(draw==1)
0 A4 ]4 ~/ W- x/ m{
/ M( |- i" h3 N//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);- j+ Q/ y6 Q& [+ O* Y+ P  w
drawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
& v  S+ L2 k  b/ h3 P( C4 F2 R. A: E

! U* s. ]4 ^: |4 ]  ~/ B9 I7 CcomputeLast=compute;
0 T/ Z% J1 M& c: Q2 twaitioLast=waitio;
9 l6 V) Z- F& P4 @; K' C6 [changeLast=change;  x' d1 W, @6 L6 F' }8 n$ R; `, X
}( L4 `, D6 m( n: M, a  `
if((* memory).p[0].flag==ready)
) h/ R" T. W* h$ e  G, S; D' U4 f(* memory).p[0].flag=computing;: r7 o4 Q1 S' @2 t/ Z7 z3 K0 ?
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
# o* l9 t' D$ W5 d{
# i6 S7 q+ m0 j* Ki=(*memory).p[0].computeNum;) j; O0 F: @8 L
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
/ N& C2 P) C& K{
9 J# z9 I8 l% G  b; h6 l(*memory).p[0].flag=IO_waiting;# W' x9 O8 |& X) Q. ?& q
(*memory).p[0].computeNum--;
% @6 J" o1 B/ F) Q2 schange += exchange_IO_Compute;" h7 [1 N( A0 o4 B, K
compute++;7 ?; F, k2 a$ ]; P2 @* Z  e- I
}
% [; Y) ?3 y3 Lelse! t% N& v8 |8 q' v: t
{0 c) E# G) R6 K0 E3 P; @5 T9 a
compute++;  A$ J  [, |9 K8 R
}
( U2 y$ m! v  b8 a% m+ w4 n}
- @- q5 ]. u1 {- k' p3 Yelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)3 q, e1 y* K7 v. M. Q
{0 O' z& X( V# m. m) ~) ]

1 q) Q6 g6 t# P/ y! _4 `- h9 }7 wi=(*memory).p[0].ioNum;6 f: K$ A; w4 G% Q
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed; g$ [# l; z: u: t- z7 @
{
4 l; n; R+ z! B) n" Z(*memory).p[0].flag=computing;& Q, H& i  ^* k* Y$ a! p; C& X% F
(*memory).p[0].ioNum--;
6 F% V6 a/ Z' G$ g' g( z& T  [change += exchange_IO_Compute;3 U# ^% g/ B2 T# j' \
waitio++;
* j/ i2 s1 [5 G8 }& }}
5 S6 g0 |$ E+ `3 W( u- M% }else. ^0 Z! x/ i+ q, p% m( {2 ]7 u
{- b% X/ E+ I0 D; O/ v+ h" o
waitio++;
! T$ [, f" |4 h' C}
. W7 F9 f; W& ?! d. q}& P0 ~# j1 T+ z6 b6 U0 t* ~$ Q
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)" o& ?8 n( K; k
{
# ~: z: B0 }- Y2 B: m" Z1 F$ [(* memory).p[0].flag=IO_waiting;5 W! q- l1 Q2 u
change += exchange_IO_Compute;4 O1 `/ i3 ~4 F
}
5 |4 }  |: p( I5 w! D3 l! delse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
1 ]5 ], X* d4 g2 J7 w3 h+ @; W{
* Q; ?2 ]6 }) R7 g$ T! T(* memory).p[0].flag=computing;) e* f$ U; J' a! f% X" |: Y
change += exchange_IO_Compute;$ E  l; Z& p' q
}2 ^. E4 \0 b# W
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0)  //一个作业已经完成& o8 w# Z, ?" I2 I9 y  P3 n
{
: v$ I2 C$ p, n5 u3 x% ?(*save) = (PCI*)malloc(sizeof(PCI));
& z) C2 ^" }2 J9 `. U; U(*save)->next = NULL;' x9 ], V$ X! \# e5 {2 W# V  x
(*save)->processID = (*memory).p[0].processID;' c+ q4 @- p; }" e" p/ ~1 m9 I
(*save)->comeingTime = (*memory).p[0].produceTime;
/ ]' ?8 I4 |# m. j4 _  \: ~(*save)->askMemory = (*memory).p[0].askMemory;
, l8 r. Z, }- w(*save)->compute = compute;3 J+ }7 P. E6 s+ S; o2 t
(*save)->waitio = waitio;
8 q1 ]' ?, I$ v8 ]  \(*save)->exchange = change;1 s7 l6 @) U+ x7 Z0 c
(*save)->completedTime = systemClock;$ w9 x& t2 C+ \  R: u
(*save)->runningTime = (*memory).p[0].runningTime;
0 d; \9 j) B) q+ T0 e9 [*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;
$ r6 e0 d  R6 n8 m- {3 kcompute=waitio=change=0;7 {) n4 y+ F  k5 i$ [
computeLast=waitioLast=changeLast=0;5 Z# K- m1 H3 s9 e
SJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
$ f/ }/ [! I; i& s0 {change += exchange_process;
9 O! [4 Z2 j( c6 Areturn task_completed;, Z$ C3 U' `+ R' c
}
/ K) H! _; {4 l  b: k' ~6 nelse8 B) ^% Y' t0 K7 v
return task_not_completed;! }# W8 m) S+ k$ T# _  o/ v
}
- o7 v% V0 d7 D' N+ Oint SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
" Z* ?$ s# e! b1 V9 X% v{
" R: R* r; A; O8 yint i=0,j=0;
/ a( S8 P0 A: X( H/ m" c2 j% ~for(i=1; i<(*storage).proNum; i++)% W  ?' R5 a" a" Z. t7 R! ~
{* e) y1 W. E6 ?+ F/ `& A
if(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))
; b% a$ E- W0 n" B( V( E) kj=i;
% }- v9 Z2 M9 f& s! S}
6 M; L: |) L6 F5 r7 sif((*storage).p[j].askMemory > *spareMemory)
! d$ b/ T+ a* [4 G5 Y0 x( Q{9 g; y' [7 E/ Q' ^" Q7 y4 Z
printf("The memory asked is overflowed than the system memory.\n");9 D; V% W4 P. f( C: Z' ~
exit(0);
  f5 `" e5 t, U5 Q}8 s" Z( u4 ]9 _7 w$ w$ p: D8 f
else
6 n0 t7 L* G' s8 y/ E3 Z{4 @8 c2 I; _- I& s/ N
(*memory).p[0].askMemory = (*storage).p[j].askMemory;
- t" u0 K9 }: `# E6 c3 w1 o(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;0 n4 @( n$ @$ C1 U  |' m8 j
(*memory).p[0].computeNum = (*storage).p[j].computeNum;
6 w) i( O, [. H1 v' Q- A6 {0 Y' k(*memory).p[0].ioNum = (*storage).p[j].ioNum;
8 k# y3 d+ }( Q- ?' I(*memory).p[0].processID = (*storage).p[j].processID;
: j8 Y( E) B& j6 n/ @9 O# x* @(*memory).p[0].flag = (*storage).p[j].flag;
: v# A3 n" ^" r- Y" L(*memory).p[0].ioTime = (*storage).p[j].ioTime;
- U: }5 q! v0 o, T8 K3 J/ b(*memory).p[0].computeTime = (*storage).p[j].computeTime;
2 Z% d* t6 B* _! R& H( n(*memory).p[0].runningTime = systemClock;
6 `- R8 c6 r& G+ u7 B(*memory).p[0].produceTime = (*storage).p[j].produceTime;1 F8 Q! |1 f$ U8 n& e
for(i=0; i<(*memory).p[0].ioNum; i++)
/ G# O$ D" O8 h(*memory).p[0].ioClock = (*storage).p[j].ioClock;
& d5 J* E4 d/ ^0 M& G. w3 S# F6 Dfor(i=0; i<(*memory).p[0].computeNum; i++)& K2 n+ q" k; S
(*memory).p[0].computeClock = (*storage).p[j].computeClock;7 x" O( t& V+ Y% c% M0 U7 o' J* {: |
(*memory).proNum=1;" B7 l: b, d! y  L0 y
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
6 N! v7 b( W$ c# u& nproduce_one_task(&(*storage),j,ID_FIFO++);           //调入一个进程后,再在进程池中新生成一个进程
6 M3 e4 [, k* i- S, I' NMAX_COMING_TIME = (*storage).p[j].comeingTime;) t' b4 e' C8 R* b6 z
}) u" d( t$ U% t: l
return 0;' G. f0 k4 c0 V$ z
}0 a! h$ F" N" F' l
int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)6 u  ^: j' H* i6 h/ L, ^
{& u+ p& j) P# O- r( W1 c
static int compute=0,waitio=0,change=0,clockSegment=100,poi=0;1 \  ?, P2 K$ @; y0 N
static int computeLast=0,waitioLast=0,changeLast=0;
# l$ w8 j. O, \& E; h9 Y  oint i=0,j=0,k=0;1 t8 u! H$ L) J3 Q
if((*memory).proNum<=0)
7 b4 X, d. `7 Y: qTimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);
2 Y1 n+ V6 F, W+ Vif(draw==1)$ M1 Q0 J9 w% E% M
{( z" [9 |2 O& o* J' n' N6 f
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
4 B& z" @1 D& f& [; ^$ |drawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);8 O0 T. L) d, n& W4 J3 F
7 A, p1 c# E2 X" K
" Z' ^6 D! g9 J5 A0 X* j
computeLast=compute;" H0 V3 B' W! L6 e2 j, d6 o8 Y
waitioLast=waitio;0 O3 N; D7 `8 k" s' A
changeLast=change;' n) Y- L; J% z9 u
}
  g- a7 B6 ?" b' T7 B5 hif(poi>=(* memory).proNum)
5 C7 a+ O& `% C/ ?poi = 0;) v5 s7 j' G& K7 h
if((* memory).p[poi].flag==ready)
( L7 X# g6 N* w$ M! C6 E8 `(* memory).p[poi].flag=computing;; C5 ]* f3 J% Y$ v1 |; b
if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)
/ Z5 C; h3 Z" A# W) w2 n{- L0 b: h0 E6 m1 l
i=(*memory).p[poi].computeNum;
$ C8 E6 K! Y  P) [9 k, s$ d+ bif(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed
2 G+ E7 A: H) |3 g4 u{4 M, F* W9 [, l' W* F% o; Z, k! {
(*memory).p[poi].flag=IO_waiting;
$ n" b, P7 N! Y. n" V, A(*memory).p[poi].computeNum--;& D! U/ _6 m8 y/ N2 G% \3 v! j$ w
change += exchange_IO_Compute;
. C+ K/ P/ X; {compute++;- G- K2 R7 @" b" I
}7 Y' Z& P2 J7 I. p  V
else9 i+ G/ W5 n: ~. i- N
{# [+ f2 I4 M/ L* s2 |' }2 D
compute++;/ L& c  V( f# T: A0 E! f
}2 g9 ]9 U/ {# v; j+ S, k
}
' M0 n" B0 G& R' ?# |1 p* Qelse if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)
0 |" [" D+ r0 f2 s, v5 B{
( I: M, v0 ?0 N9 O5 D( p+ \8 @5 x: P4 B
i=(*memory).p[poi].ioNum;
( [" i! q% r4 _9 l5 X& t: x# L: jif(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
1 i+ Y6 N* k  F7 s$ [. H{  h) M( D; r1 q& {7 X. k2 i
(*memory).p[poi].flag=computing;
' D9 v( t, t* R' U  n& G(*memory).p[poi].ioNum--;. \' |/ d9 j/ b# {" N
change += exchange_IO_Compute;- Y0 a3 s" O6 c/ L0 y+ B
waitio++;
7 L' q4 L( T, J5 h- k* e9 g}# {! q5 h% m0 l. n
else
6 j4 D2 U2 m9 d4 \: f' r% [{1 I1 W( s: a) W- U7 P9 K, `
waitio++;" k: ^# i* ~$ ], Z. D4 h, p
}
; q- [, b- A; O}. t5 H& t( s) j& A# q
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing)4 W3 z2 s  [9 G
{
* @* R* `$ V# @& v$ q! f(* memory).p[poi].flag=IO_waiting;9 T; \$ h6 s2 @, a' n" l7 h
change += exchange_IO_Compute;
9 f8 Z- E, k) x  P3 s2 W}
: g, m( i& I5 w2 W" D  i$ i4 l( Selse if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)
: A; Q3 t& n/ h. Z, p{
* x) d$ x+ H$ |' d$ }) S(* memory).p[poi].flag=computing;
, p9 i- O, |" P  a1 ochange += exchange_IO_Compute;6 G8 @5 J5 b) ~) b4 Q9 X
}& r. [9 g: r  n- f! Y
for(i=0; i<(*memory).proNum; i++)  //其他等待io的进程可以并行推进1 `; |# h8 n0 ?+ Q5 ^( C9 a1 f
{
. _1 z7 o$ _5 f* e' l6 H) ?: Mif(i!=poi && (*memory).p.flag==IO_waiting)$ U4 l: J' ], X4 v3 }( |
{! g- l2 e/ F& n5 W; }4 R# T
j=(*memory).p.ioNum;, f, u" c1 O& {
if(j>0)" o2 P0 |* [  e8 b# c, f
{
. D  u6 z/ V, D9 U, z, mif(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed2 @1 Y# @" h* }+ v
{
5 c+ P* w5 b9 q(*memory).p.flag=computing;
/ G$ |. _0 v$ o; f$ u(*memory).p.ioNum--;$ z& l( X. E" M( b( A0 @
change += exchange_IO_Compute;. U1 B0 v* B; ^5 E9 J" k6 B
}
0 ~. c0 N- b. _! ~" V}
0 y  x6 Z. q& C  S& K  _9 [5 X9 A, Q}
4 J. G! [1 g2 T& {0 ?+ a0 a% z+ i- V. b: J}
2 ^2 Q) L. A; bfor(i=0; i<(*memory).proNum; i++)  //处理已经运行完毕的进程
" `, c* h1 p3 M9 R{6 Q3 `  f/ V; n: R
if((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed  E/ N$ o9 l! e; s* i! c
{0 r4 Z. T' Z1 z1 K0 U5 Q" y) ]
(*save) = (PCI*)malloc(sizeof(PCI));
: K/ e" C8 d  p(*save)->next = NULL;
+ }+ C6 h2 S! o       (*save)->processID = (*memory).p.processID;
7 v, v+ r4 ?  O6 v5 J+ Z(*save)->comeingTime = (*memory).p.produceTime;
: f2 m3 y; U: n( Y(*save)->askMemory = (*memory).p.askMemory;
, M3 o* @9 U) I(*save)->compute = compute;
* a, ?$ i9 G" ~# C0 y(*save)->waitio = waitio;
4 j5 b. t0 f7 @(*save)->exchange = change;; R4 S. x# F! G( p8 G( `- y0 h! C* H# n. s/ u
(*save)->completedTime = systemClock-(*save)->comeingTime;( j# I+ ~& p$ t' _4 ^# Q: @$ Y
(*save)->runningTime = (*memory).p.runningTime;9 w$ n5 l, u, Q' S! F5 U. N4 p
(*save)->completedTime = systemClock;. w& u+ I+ k; V, j7 [( {
*spareMemory = *spareMemory + (*memory).p.askMemory;5 `% z" e$ e1 }
compute=waitio=change=0;. F% g; r; Q4 B0 p8 x3 T; r
computeLast=waitioLast=changeLast=0;
5 o' |3 J6 R! V) B/ ]if(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入" q7 Y$ v2 o. z& |& ?
{
, r4 I! [/ V; {# `* s: j( ~; Tif(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程
# z* a. }# _2 N; ~{
# |: q: [9 e" A7 U$ x! fpoi++;
4 r) Q2 L6 W  d' Z! f4 j   clockSegment=2000;
9 U  w+ i2 i9 V  C5 W1 k9 S}
0 ?+ v( V. X- c0 d  E7 H- e}
* Y7 @: f' H1 m3 w4 n+ n% m2 celse  //没有足够内存调入新进程& ]. r9 o! v/ w/ C$ K8 E
{2 `/ X" b7 H2 @2 B1 u3 _
if(i < (*memory).proNum-1). M: f" h6 X7 a, g9 n
{0 w) E! e! @: f: }3 J5 ]
for(j=i; j+1<(*memory).proNum; j++)5 I( C' Z: ^& j8 X5 j
{
4 {/ ^1 y( f4 M$ T; K+ O  b(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;! [$ t5 X7 e1 C( V3 u9 M
(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;
6 y6 Z- l+ d1 v. ~9 I4 p) z/ f% b(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;  r8 w# q+ C* g6 G- \0 n4 i
(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;5 ^8 j, q; h* ~7 o0 S% s  p2 X4 \
(*memory).p[j].processID = (*memory).p[j+1].processID;
% ^. I& B6 D8 |9 e# w9 N(*memory).p[j].flag = (*memory).p[j+1].flag;
! a' r2 a$ F7 t1 h, N4 |" A3 e(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;8 Z" B/ N6 z. M& s
(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;9 b( ^. |( A: u. `! T5 O+ w
(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;
" X; g# u% O2 n( n$ s( C' ~9 @(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;# i! J! c/ ^/ G$ k
(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;% }! G# i. d9 f' w$ V
for(k=0; k<(*memory).p[j].computeNum; k++)# w3 k7 A$ n, B1 g" L: A# G
(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];
7 [3 U3 X3 f0 |$ \, [0 W  `for(k=0; k<(*memory).p[j].ioNum; k++)1 h" R6 J( R8 U5 K& g+ D
(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];8 k* L) N: W6 u* i& M
}1 k6 {$ {- Z. S4 t7 B% I. H
if(i<poi)( U9 C/ @6 K5 b# s
poi--;7 R& A9 ]: y' s$ |+ Y* R
else if(i==poi)# Z+ C3 |: O: t' U
clockSegment=2000;
% M) s7 u- K- ]- G9 \}
5 W8 S0 z6 Q0 c& q# ?i--;
$ e' I, [9 f/ D" D9 ~(*memory).proNum--;1 L1 H( f; E+ B" D9 v- {* D
}
! D# p! Z5 V/ }8 f' Vreturn task_completed;
2 G3 C% b) f7 W  }* u}
7 ~* Y+ ~5 p/ H+ Z( b' s! v: ^}
& B3 n8 H. }1 b  y--clockSegment;
# _( d* p; l' M; ]- vif(clockSegment<=0)
& B$ I7 N/ g( M4 Q3 a{6 ~8 U+ }4 ~- K' D/ B
poi=poi+1;
6 E: V6 }( ~3 `4 j) J2 N, ?if(poi>=(*memory).proNum)
& w0 m$ v( C1 k( lpoi=0;0 [5 d. z1 H. @0 j: ?
clockSegment=100;
3 e7 U  l4 ]9 ]* J6 D$ ?}# t3 Q( K( h# N+ }7 r
return task_not_completed;
  ]- V% ?0 V% g8 C; ^. [$ ?}
5 E& ~+ n7 L, }' _int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos), D* W9 h: ~8 X/ |$ e/ \6 j+ C
{
. L: r4 W  U: E0 s4 G0 ^int i=0,j=0,k=0,flag=0,translation=0;
- y0 F( T! o# n6 d4 Ffor(i=0; i<(*storage).proNum; i++)
1 W. `# p# L' {0 J* ]( ^{
5 h; i4 u8 ]2 j0 I+ ^3 pif((*storage).p.comeingTime>MAX_COMING_TIME)
6 i9 T# s% {, R0 F0 J# V7 D0 jMAX_COMING_TIME = (*storage).p.comeingTime;
) [) e* k: ?! M7 f( U; m6 a/ m}& q7 m# g7 J5 p( _8 {2 R& j
if(pos>=0)6 e: V2 ]; }+ {  R, L9 ]
{
! y3 _2 y* `$ d, n  Lfor(i=0; i<(*storage).proNum; i++)3 h6 Q7 t/ N) p6 a- o# s, h3 Z
{
$ S8 {6 s, m/ L5 c5 W% G5 o- m+ Hif((*storage).p.askMemory <= *spareMemory)
9 ~& D. g. F+ ~( _# ?( ?7 J4 n{8 u$ z  K9 R2 P- m3 W
j=pos;; G) U! g  T% e9 P4 E' b4 `# @
(*memory).p[j].askMemory = (*storage).p.askMemory;
. d' t' U, T$ T  L( j" t(*memory).p[j].comeingTime = (*storage).p.comeingTime;2 A9 o. Y5 ]- t* `; b$ s
(*memory).p[j].computeNum = (*storage).p.computeNum;2 u- g$ B5 }+ Y- B- _. m0 ^9 F
(*memory).p[j].ioNum = (*storage).p.ioNum;! q2 v# \% t- U1 r) S
(*memory).p[j].processID = (*storage).p.processID;4 O9 t0 n1 \  y" }+ n% C* z7 w% f9 f
(*memory).p[j].flag = (*storage).p.flag;3 r7 P3 ]( {# {$ _, k  B$ w
(*memory).p[j].ioTime = (*storage).p.ioTime;- N3 u, n0 H. }/ a. {, Z% ~. n
(*memory).p[j].computeTime = (*storage).p.computeTime;; p  Z, |8 I# a, g) v
(*memory).p[j].runningTime = systemClock;9 Z! l" B0 Y6 h" k* d' Q
(*memory).p[j].produceTime = (*storage).p.produceTime;# y, {5 Q9 n. N& ]2 T' m; n
for(k=0; k<(*memory).p[j].ioNum; k++)
2 z1 r1 r3 x+ n% `1 K, N5 s(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
3 U/ T5 ]; Q+ v% F) ufor(k=0; k<(*memory).p[j].computeNum; k++)
! f* j: m3 Q1 h& N8 |# l6 `  y(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
6 L( h1 y9 H7 P" t' K. R*spareMemory = *spareMemory - (*memory).p[j].askMemory;
; s- E+ |0 g2 |8 dproduce_one_task(storage,i,ID_FIFO++);           //调入一个进程后,再在进程池中新生成一个进程
- n9 m! ^- T' r* l9 W/ Z# S8 CMAX_COMING_TIME = (*storage).p.comeingTime;, @) u: [- u3 f4 @# ~
translation=1;: l1 k: ]0 f! w; R4 _6 z# j
break;" z! I! h# }+ F$ X
}0 B5 C5 U( ]  K( R, a5 n) W
}. G/ W0 L6 x! Y
}
. F+ X2 @, H7 ?else
. ~; q- N# i9 ^" k6 c2 ]& ?{
: y+ c2 G6 J6 N% l$ \- pwhile(1)
1 G0 R) U  B3 V, G) O{7 R5 q/ `9 C. f' A1 c! a7 D6 _
flag=0;
3 Y2 {4 |3 q( n6 y. @  `for(i=0; i<(*storage).proNum; i++)5 A6 V3 P9 [/ ?) E# R: J( ?
{
2 _8 ?6 z9 ^* b0 i+ f. Qif((*storage).p.askMemory <= *spareMemory): O$ E9 j% {2 s# \" V. d) q. I
{" D  h$ q8 H2 s
j=(*memory).proNum;) c+ c( Z, t4 ^6 e1 c& `
(*memory).p[j].askMemory = (*storage).p.askMemory;
) Y2 X* Z0 z1 C% f(*memory).p[j].comeingTime = (*storage).p.comeingTime;
; |! `8 M: `: ~/ x(*memory).p[j].computeNum = (*storage).p.computeNum;
3 i9 [; N8 b% k+ h( G(*memory).p[j].ioNum = (*storage).p.ioNum;
0 k' R0 m7 m3 b4 T, U+ n(*memory).p[j].processID = (*storage).p.processID;
3 s6 S- N& D' W7 @; C( {' Q(*memory).p[j].flag = (*storage).p.flag;1 F8 |6 S& r9 B; v  G& s3 i$ a
(*memory).p[j].ioTime = (*storage).p.ioTime;
5 A3 F8 [& Y6 m" d( S/ A(*memory).p[j].computeTime = (*storage).p.computeTime;
( u7 z' T3 P8 C7 |(*memory).p[j].runningTime = systemClock;# z/ Q- q, u. M! `7 {2 T5 p. b
(*memory).p[j].produceTime = (*storage).p.produceTime;
- D& `5 x3 ~1 s0 ]for(k=0; k<(*memory).p[j].ioNum; k++). B4 c2 Q6 s0 i0 t
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
; U4 s2 A% T$ S, bfor(k=0; k<(*memory).p[j].computeNum; k++)
( e! x" F7 {# Y' \$ Z0 \(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
* U" a0 m2 G6 C" m- P) {(*memory).proNum++;
8 M  }2 G6 \+ v* C& A1 h*spareMemory = *spareMemory - (*memory).p[j].askMemory;
  D/ \2 m4 ?6 ~$ P/ H% Lproduce_one_task(&(*storage),i,ID_FIFO++);           //调入一个进程后,再在进程池中新生成一个进程
5 b; ?; j* \" lMAX_COMING_TIME = (*storage).p.comeingTime;
7 P0 p3 y  T; ]3 O2 A" E" Q+ bflag=1;
# P+ r3 d8 w5 B( `0 L' ctranslation=1;
3 Y5 p& F& Y6 y0 `) X}
. t2 G! l, a6 Y1 v! O8 G}( ?" i/ t; q( m* l
if(flag == 0)
& _, |3 @- S; @) d, q' e+ V' pbreak;
1 F$ {$ }" ]$ m1 m' w) f/ P; q  Y9 E}
, u; Y* B. M8 k' ~2 ]# @}3 _" L2 }5 u! L% z' }! [6 P
return translation;" p/ c" L( Z& d* h6 R' {
}' \4 g( m; M3 L1 `
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)
: {) P# `$ I3 |5 S{! @( S, ^; M1 d0 Q4 W# T' E
static int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;
4 v- {2 X# X5 `$ G: Zstatic int computeLast=0,waitioLast=0,changeLast=0;, ~$ \0 K, ^6 o! j
int i=0;
  @) d6 a6 \' ~* nif(draw==1)6 d$ A2 K% U9 O
{. |& ?3 [7 y1 P! d$ ~) o
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);. E3 T# J/ h( h: f
drawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);, Y+ W* a0 y) ^5 v- N- Q

, z4 S* Q; d/ p& S, o6 C' V
% j' X" r6 x$ M6 f$ Z; \' G" bcomputeLast=compute;/ R/ d1 s# i( a6 P' B5 b3 _  B
waitioLast=waitio;
! V9 V3 F! v" f% C% KchangeLast=change;
$ O2 G: ?0 \8 G+ b( M! \) {}) a7 y2 R1 D( j( N6 o
if(flag==1)  
2 z2 z' w" q: o! u# r{7 V& c) V1 D- p2 H
if((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0)  //task is not completed5 T8 j2 p' \& ~' A) k* \. k+ H
{
/ k+ Q9 h6 f. ^4 Nif(flagiocpt==0)   // implement compute' O: B$ f! c- u
{# y" C( p7 V2 S- w) q( Y7 V
i=(*memory).p[0].computeNum;
3 H$ r" h1 f# }4 L+ Sif(i>0 && (*memory).p[0].computeClock[i-1]>0)1 F4 g$ Z/ _: s3 n: n
{
; I& g) H* L% Y+ m6 f! Q7 Nif(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed
9 t4 T; f& D; m5 v5 d$ F) U) X& K{
% a4 X) Z) T8 b" Oflagiocpt = 1;
) W& j2 [- @3 b(*memory).p[0].computeNum--;4 K, a- ]: [3 u! U% k
change += exchange_IO_Compute;/ k6 x0 i9 g9 P7 e% z- Y
compute++;
9 k0 R1 x* a8 q' Z0 {' e: k}
0 T! E: F! z$ d& s( m' n/ D3 yelse
1 l5 Y3 v( T* r" s& Mcompute++;
4 i: r2 E4 d. {0 \2 k7 u
" C1 y/ N9 y/ T5 T) y( T! m}
) |5 s; y: z  [- J+ }% m9 ]' }( Q' I( Delse) `. h. G/ I! f& r3 X6 e
flagiocpt = 1;
: M- n9 ~! [7 `- J}* R( C$ Y; \3 _# q8 f& A& f
else  //wait io5 C  f( D: N" e/ i4 t, h' R" R5 w
{
( ?- X; _% {7 M- [7 _( X( Vi=(*memory).p[0].ioNum;0 f8 C) w9 C2 Y7 a
if(i>0 && (*memory).p[0].ioClock[i-1]>0)6 W# V6 P4 c& b% m
{
, @$ `' N# L5 C) P% y0 P) fif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed5 z& a/ w* ]7 d
{6 Q# q9 a* Q5 B8 X8 t  p9 {
flagiocpt = 0;5 |) L5 v; I8 ]" J
(*memory).p[0].ioNum--;; ?! c! a0 D4 t+ J6 {1 T' T5 N
change += exchange_IO_Compute;
6 M& _8 C7 o' p4 kwaitio++;
# e+ x1 b5 U0 `: H4 b- O}& V$ p1 c, i: y. E
else5 t' c7 \# j8 j# y0 H# y
waitio++;
& U' p4 I0 O$ M" B8 E; d( d% Y1 A# O+ r
: C6 k* C/ v$ t& q: a}3 A3 e: r; m. w% H$ j" L
else. f# T- a* b/ F" h# M$ x' h
flagiocpt = 0;
8 k. O9 E  U2 [" ]) _. v/ W}
' f% \2 e3 r  n}
; D( A0 z; m: uelse  //task is completed
) h: d4 m5 x) h/ M) D0 c{
1 u0 a( w/ M' f7 o  y2 }(*save) = (PCI*)malloc(sizeof(PCI));
6 \" ?4 Z7 b4 H. u$ j2 I+ Z2 D(*save)->next = NULL;
* o9 G! j: v# m1 P       (*save)->processID = (*memory).p[0].processID;
4 j2 i% t! n5 D5 c$ [  c(*save)->comeingTime = (*memory).p[0].produceTime;
& T5 h5 ]3 F! V1 ^5 {9 r(*save)->askMemory = (*memory).p[0].askMemory;
. w& @$ B/ Q- x0 j! H(*save)->compute = compute;! ^4 @4 o* ~( ~2 n5 w; B8 J
(*save)->waitio = waitio;$ ?& l5 Y" \5 |/ Y
(*save)->exchange = change;
& H; M& R; }# x+ |/ Z(*save)->completedTime = systemClock-(*save)->comeingTime;1 x  `8 r" w) `; N+ l" G# D! ^
(*save)->runningTime = (*memory).p[0].runningTime;
' I9 [/ M0 s2 g( {6 s9 P4 V6 f(*save)->completedTime = systemClock;' Y' o: ^3 I, D+ r& x3 `
//*spareMemory = MAX_MEMORY;
% g% d. D3 ^9 C8 {- W; [free((*memory).p[0].ioClock);
, U" q* b, X; g0 \  Yfree((*memory).p[0].computeClock);
8 _7 n" P% H9 Ffree((*memory).p);
. E- a- E; R3 E4 u6 w/ b8 j3 l7 kflag=0;
4 d1 C& p6 A! o" X! Fcompute=waitio=change=0;0 p# q# M1 s" ]$ O9 @
computeLast=waitioLast=changeLast=0;
. a6 ?9 O2 b# o8 dreturn task_completed;9 ^0 X. j9 p3 R
}8 X8 }! t7 n; t; C* j. P+ t
}4 K* ~/ c- p0 H/ T. `" T
else         . j) O( ?& _* \" J0 S! \; @
{
! ]- |# r# }: ?- R: N  ^  \, X2 o* FFIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));
. D% N# Q& D" N  T! Q1 f  a  O$ Gchange += exchange_process;  A$ \% @$ R$ ?/ I+ \% H3 ~0 H
//*spareMemory -= (*memory).p[0].askMemory;) Z# B" q  N& l1 p1 P
flag=1;% M; `, f9 H2 F; s" z- s& z
//showProcessInf(*memory);+ m7 W4 A$ Z, d6 @9 C9 _4 y% j
return task_not_completed;
6 M8 c2 a2 l* L4 D, [}6 h# P1 E7 q4 X7 Y& Z- i9 q
return task_not_completed;8 n! w8 [% t% I4 R5 ]* V9 K# K
}
4 p' d; }7 k9 Y# G# a3 vint FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)
* m. ~- _, z- e% T{* I% E9 D# F1 x
int i=0,j=0,k=0;) s0 m9 L. T. t- a' x) Y
MAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;2 }& z9 b5 H. m7 }: m
(*memory).p = (process*)malloc(initProcessNum*sizeof(process));
: Q" e# S. K2 w4 x) W6 kmemory->proNum = 1;# W9 s* f0 g2 k2 A4 |
for(i=0; i<initProcessNum; i++). u( L( S; Y* g9 ]4 A0 ^
{
9 M: y9 |, j( t% ^- y! P. tif((*storage).p.askMemory <= *spareMemory)
$ ^# o& ^- Y4 d7 J: V5 c4 \3 E{
# x6 G, r1 W- K, O- G- V  T(*memory).p[0].askMemory = (*storage).p.askMemory;
0 N/ ]+ e8 k3 q1 c2 J7 B(*memory).p[0].comeingTime = (*storage).p.comeingTime;8 {- C$ u5 P5 t1 _) p
(*memory).p[0].computeNum = (*storage).p.computeNum;: q/ U- u$ K' O0 S* ]
(*memory).p[0].ioNum = (*storage).p.ioNum;
6 C- G6 ^- ^' ]& J6 M6 ?1 J, Q# T; O(*memory).p[0].processID = (*storage).p.processID;; |2 x" F) r, O6 I& W0 ^
(*memory).p[0].flag = (*storage).p.flag;
5 O' e0 L  H+ _6 e  r; D, b(*memory).p[0].ioTime = (*storage).p.ioTime;. z4 b  G7 i4 [8 Z
(*memory).p[0].computeTime = (*storage).p.computeTime;
7 N: ~! c4 V/ x8 r8 C1 i(*memory).p[0].produceTime = (*storage).p.produceTime;9 ^2 \* G* c- P( q+ u
(*memory).p[0].runningTime = systemClock;
8 O: |8 c4 `2 q0 e: B(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));: }% v; g; D0 u' A5 T; E9 @( f/ b
(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));
) @4 F# e% y' Z" |, h- b* ufor(k=0; k<(*memory).p[0].ioNum; k++)+ S3 C1 O1 x' k4 {6 N
(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];
; f* m9 _/ w8 v+ F# z: B9 U' ?for(k=0; k<(*memory).p[0].computeNum; k++)
) ~1 U( a$ I2 V(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];& q8 ~1 T$ A$ Z% g
break;5 u- r3 w. S2 {$ O
}# q1 P# W* ?3 e
}
0 W. {3 G  W! d7 e% V' Z) c/ Q% cif(i<initProcessNum)  //调用一个作业进入内存后,并再生成一个作业等待调入0 Y; l/ k% i! D, Z
{
0 s+ E7 P# m, S) aproduce_one_task(storage,i,ID_FIFO++);
1 q* \  p! r' \9 h% ~% |6 UMAX_COMING_TIME = (*storage).p.comeingTime;
; a: {& K7 _6 G' e2 Vsort_by_comingtime(storage,i);1 s+ S# H+ F) x$ q6 H8 E& r# i
}
- x' R8 A+ {3 n' c: K5 s0 kreturn 0;
% @7 j. T  I6 O8 ^( P1 s}% W. L5 w6 m% D
int sort_by_comingtime(processPool * p,int pos)
, G; M  @7 d; E. L{
" P4 d9 P3 ~* tint i=0,j=0;6 y2 ~) n' [' G' J& \) u
process temp;, X- }" Y' M1 x2 C6 g- {( i* t
if(pos<0)/ s0 }5 q# d, a. }! b$ x
{2 v! B8 b2 ]5 h9 h
for(i=0; i<initProcessNum; i++)$ y9 k# R& P# t6 o3 v7 m0 y) b
for(j=0; j+1<initProcessNum-i; j++)
, Y5 O8 w3 ~0 b) E{
7 n4 L3 g9 E" @, J  l5 |  V; Uif((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)
1 F; U9 `6 h0 @! c3 }{* _) E' a4 \9 d
temp = (*p).p[j];/ N5 J) T& Z) Z: j9 b( o8 p% y+ O* R0 M
(*p).p[j] = (*p).p[j+1];0 R9 ~/ A6 e" U/ m5 P- R4 E4 f+ p
(*p).p[j+1] = temp;2 _: _/ i8 \2 K- b3 m0 m
}5 x! @* M: }( T* E1 i
}0 h+ [6 F8 V3 G3 g+ `5 A
}3 i* D3 b: z# ~4 \2 S8 A
else if(pos<initProcessNum)9 H. d$ S) J% }- a" w/ k+ m' V
{4 c- h8 |' z& {
for(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)' Q. X) q3 t1 E
{
2 v, d8 N- H: ^- A. Ptemp = (*p).p;$ k5 u! z9 z2 }  s+ r& ^
(*p).p = (*p).p[i+1];
2 J7 p  L% L+ P; a4 u& P0 n(*p).p[i+1] = temp;! C, \3 U* H2 h4 T
}9 z2 @0 K' D% f" n# J0 [! q9 s
for(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)9 ]: Z7 T; v/ ^, b0 _
{( [8 C1 {1 z" r
temp = (*p).p[i-1];$ f% D/ U" u0 I. V6 B7 o
(*p).p[i-1] = (*p).p;7 u0 E, }( K" G
(*p).p = temp;6 o9 V9 h, @# Z8 Y7 O
}
7 ^: V  \2 N/ J- w) ~. ~% @}
' e" X% D  y" ^! w$ G, A& K, i. Belse& y. b! t4 L4 f; M. ]& Q4 C- G5 b
printf("position eror\n");
, {+ _$ R; j, A- [# b& zreturn 0;& J: D% X; a# b9 a3 h
}
3 N+ h# H# E8 qint InitPool(processPool * p): {" d; p: ^0 I- H" W
{  a# F  k6 U; n, Y+ s, F
int i=0;  W/ f1 F! O3 {, `2 }$ d
(*p).proNum = initProcessNum;
% u+ {- ~5 E# ]* h* P" S3 Q2 ^' f(*p).p = (process*)malloc(initProcessNum*sizeof(process));+ V5 m$ Z: Y: o# t
for(i=0; i<initProcessNum; i++)                                        //init process information
; p& ]) _) ]+ ?) Z8 V{
+ @+ q# R! }" r4 C7 L(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));/ o9 d  e* g' v! U) l0 f
(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));" ^' f' `7 j0 u; W  `: v
produce_one_task(&(*p),i,ID_FIFO++);" N1 B6 z; p1 _4 m" a
}
, u( c4 W9 Y4 h& ?1 F) ~return 0;
" A8 O* K$ P9 f3 m; `}
$ m/ K* `# @( N4 Iint produce_one_task(processPool * p,int i,int id)3 }' e, p8 C0 @$ f+ k5 I, ~' ^
{3 t1 ]; F8 B9 |1 N
int time=MAX_COMING_TIME,j=0,totallTime=0;
; |' J8 o* R# f0 E(*p).p.processID = initProcessID+id;           3 C! _1 B/ T- c# `7 [1 Q2 ~
(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);( n9 u/ L5 n+ A1 F2 \5 G
(*p).p.produceTime = systemClock;  f/ a% y3 P; \* Y5 d, l- I" Y
(*p).p.ioNum = rand()%4+20;                                        //IO number setting to 2--5;
# O" j( R5 V$ ]) R(*p).p.computeNum = rand()%4+30;                                   //computNum setting to 3--6;( c7 R& ~1 Q$ }( q
totallTime = (*p).p.computeNum  + (*p).p.ioNum;
/ ^3 f  ~  e5 u3 R. v) T1 ](*p).p.computeTime=0;: Q2 f5 h* J+ Y; _  ?0 Y3 C! V6 o
for(j=0; j<(*p).p.computeNum; j++)4 e6 ?7 t. d* y% V! K; ~
{, B+ U1 K4 D3 u+ ~& @# @' s: r( T
(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;2 L( o" z' m! o/ a% ?' _
(*p).p.computeTime += (*p).p.computeClock[j];7 i7 k7 S5 U5 }% j/ |9 d
}0 e# s5 y2 T4 ]1 t
(*p).p.ioTime=0;
0 z$ Q+ s8 d* f( A3 ifor(j=0; j<(*p).p.ioNum; j++)
5 a/ I  c" n$ ]; M{
( B! R; u5 s% M0 d(*p).p.ioClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;
2 J6 S- F8 a& x5 {& N(*p).p.ioTime += (*p).p.ioClock[j];
0 o8 r2 v2 V- u  a* A}  w: B- ?7 {9 ]0 s
(*p).p.askMemory = rand()%(MAX_MEMORY/4);
! s2 I# S6 ^8 O* v6 _3 l(*p).p.flag = ready;0 H9 U; D& n  w6 J4 k* y' R! Q
return 0;
+ |8 O! `0 g; Z* n* q6 K) s}
9 Q5 p( ?1 s! t8 C+ zint showProcessInf(processPool p)
4 e$ r2 D7 s0 A% O" o{3 g4 f( w1 I" w7 |9 C
int i=0,j=0;
+ d- g$ q% ^3 D5 O$ Wfor(i=0;i<p.proNum;i++)
; p" ?- N, E6 C8 N{
! G: h  A# _; c8 F; k& W1 H3 o: pprintf("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
0 t+ G# B& l% i9 A,p.p.askMemory);# A9 \* D4 b) e
for(j=0;j<p.p.ioNum;j++)
  ]% y* |0 w. k7 Y# N$ e% k5 f{
! p$ B% }2 h1 O3 tprintf("%d ",p.p.ioClock[j]);2 L) ~7 d9 p: Q0 B8 L* ^' B
}
# c) T0 c" H. I/ Sprintf("\n");$ r: V3 W4 C, j& g
for( j=0;j<p.p.computeNum;j++)
/ r, G& Y0 u/ Y{! R3 X# W5 V! ^$ x
printf("%d ",p.p.computeClock[j]);
6 I. H) y' N" x) P# c}
" ^6 j  _+ E6 y1 o- [* `5 Jprintf("\n");
/ _  w5 O2 Q3 x  u  y) D) m; z}" W9 q1 u/ j5 V+ d- Q- A8 @
return 0;
/ k1 H* ^" H$ x' f4 @}2 }- d: g1 p3 D" H/ T  r
————————————————
& ^7 Q/ t4 o; Y( r$ v版权声明:本文为CSDN博主「wang_dong001」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
* z7 z  Z8 L" F# D# L& h/ i5 o' G3 m& C原文链接:https://blog.csdn.net/wang_dong001/article/details/478435191 z( \+ j0 x. e& _, E. t4 I
- w8 Z! T$ k: S: q3 X# }+ C% l

7 `0 V: k' y# S/ T/ W5 U3 O




欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5