- 在线时间
- 1630 小时
- 最后登录
- 2024-1-29
- 注册时间
- 2017-5-16
- 听众数
- 82
- 收听数
- 1
- 能力
- 120 分
- 体力
- 565636 点
- 威望
- 12 点
- 阅读权限
- 255
- 积分
- 174914
- 相册
- 1
- 日志
- 0
- 记录
- 0
- 帖子
- 5313
- 主题
- 5273
- 精华
- 3
- 分享
- 0
- 好友
- 163
TA的每日心情 | 开心 2021-8-11 17:59 |
|---|
签到天数: 17 天 [LV.4]偶尔看看III 网络挑战赛参赛者 网络挑战赛参赛者 - 自我介绍
- 本人女,毕业于内蒙古科技大学,担任文职专业,毕业专业英语。
 群组: 2018美赛大象算法课程 群组: 2018美赛护航培训课程 群组: 2019年 数学中国站长建 群组: 2019年数据分析师课程 群组: 2018年大象老师国赛优 |
T/ ?; g) V8 M7 `: @; k, z
经典任务调度算法的模拟程序
6 v; h% b/ |- L* T本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。
6 \8 L2 ]6 n3 W, T$ J0 u/ ]$ A% R7 z& q, d# ?
编程平台:VC6.0+EasyX图形库环境。
& F# R; H8 i8 f* C1 `
& G3 S, K) \9 R$ Y! C; T; T以下截取部分程序运行图::& h5 e0 B2 F; V
7 G8 ^6 c5 t7 y3 g$ b* ^1 l/ P
源代码:
' J0 B1 v; e& q" ]! {' T
/ \. i; \: e& h( ?#include<stdio.h>7 K4 B5 @5 m' K+ _
#include<stdlib.h>
$ j5 G+ c# |6 V1 k4 Y( G2 W#include<easyx.h>
2 w+ {' @- e3 ~2 y#include<time.h>
, r9 A4 |' k9 ~2 w5 D' s; g5 b#include<conio.h>
6 f3 y% F+ W( U#include<graphics.h>, v! j: w6 y! D; ?0 z- E2 I* o5 N
#define initProcessNum 10
( F5 f7 b! m0 t1 `+ B#define initProcessID 1000
( e( ~, ]! \ x#define MAXProcessRunTime 100007 }# V4 Q' m7 Q5 o% P/ e
#define MAX_MEMORY 4000
/ ]! ^+ w8 I0 ?% _% K" V" [2 B#define exchange_IO_Compute 10
0 j" I' Q) I, p6 H( R1 ?#define exchange_process 25) N4 @: | Y1 { Z6 w3 ?" c9 I
#define task_completed 1
! I ?' D' c) H; J! d0 A#define task_not_completed 0
% V# _7 @: L* N#define initclocknum 100
1 C/ k" I- e Tenum condition4 H1 ]1 }- z$ R) v5 R# K
{2 U' _2 h- F2 ~
dead,computing,IO_waiting,ready6 w* J. O# {& x; T$ Y9 g$ \; m+ J
};. X/ r' V, p3 }6 e& n8 D. Z
struct process
$ A& |. g7 Z- O1 Y( a{
( C8 w+ O4 i( w8 C/ w" e$ yint processID;
3 q; ]; e/ G5 i6 |& W7 Zint comeingTime;! ?5 h; H9 V3 {# U6 x7 y
int ioNum;( U" z* p5 B* z2 Z
int computeNum;) S. g' M0 H. I/ C3 Q; n
int * ioClock;
: Z1 v8 A# l6 I! |int * computeClock;, G; M' X. e# r6 f! \
int ioTime;; E! s6 V8 w& S4 u0 g
int computeTime;
; |$ @: l" y* i0 w) eint askMemory;% P7 S1 |! T, F N2 f
condition flag;
/ k- f# b6 f: Tint produceTime; //生成时间,以下三个数据成员用以计算相关性能
3 N- A6 a- f1 T" B; fint runningTime; //第一次占用CPU的时间
7 q' V) T3 J" R5 vint completedTime; //进程完成时的时间
2 T- }; j) D: R$ f( p};
0 L) B- k9 ?, d" T) X9 o: k2 xtypedef struct processCmpletedInfo //保存完成一个作业的相关信息
/ |5 _0 @( K- D$ I5 J{
& @! z$ I' q5 X( T% Y" \% [7 fint processID,comeingTime,askMemory;
2 I3 Y" t6 W" ?0 H' sint compute,waitio,exchange,completedTime,runningTime;
& S7 q* r* E* V8 e0 GprocessCmpletedInfo * next;
+ {/ V$ ?2 m3 z0 {+ z2 [}PCI;
& R4 d, [& A' Y {" W$ p6 wstruct processPool
6 ^4 Z/ Q' j1 ?- w2 j2 O' a; ?{' w2 Q* E/ K, i( K
process * p;+ ^( P5 f6 J4 F8 u
int proNum;+ E3 u+ N5 [+ J8 m
};
7 C: J8 a! o9 t* Eint 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;
0 w* Y$ O5 Y8 ^, N8 B8 w5 D w: }6 Iint InitPool(processPool * p);
4 C, z1 P) v. @" q9 \int produce_one_task(processPool * p,int i,int id);
' O1 Y1 c [1 s; i. C7 Fint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);6 Y* h& K$ C6 ~' Q* z( h) Y
int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);* K- z" a: d F' j$ J
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);
( b) v' f. J: h# b: Dint FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
* x, l; U' ^0 O* k; O" T! _: wint ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);0 C; M7 v v- [9 j E/ q
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);8 W2 q. i# I3 `- x! \
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);1 [. @+ _+ B0 g% R" _0 Q
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);: b& u0 i/ S. }. J: b5 U
int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);
4 j/ m" L) t; P# tint High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);! I* u* ^0 p) A, ~
( c G. b; h( J2 [# U7 x0 R
% H9 U4 G$ L. \ m! {
int sort_by_comingtime(processPool * p,int pos);8 f/ Y% M# ]( }) I! a
int showProcessInf(processPool p);
' P4 C7 v: k6 j" m& G$ }# Y& s0 w/ yint drawPerformance_FIFO(int x,int y,int memorry);
2 N d- O) i2 E! U0 \int drawPerformance_HR(int x,int y,int memorry);% ^- w1 I! o# G* V
int drawPerformance_PF(int x,int y,int memorry);+ ?; H c6 h; w, x. f
int drawPerformance_TT(int x,int y,int memorry);, `& s( ~2 V1 t# m; n6 P( S! j
int drawPerformance_SJF(int x,int y,int memorry);
& |) P3 z, q, |+ a* Fint MouseListening();
+ [1 u Z) p# r( E' U0 |) Q( ~int MouseListening2(int *flagShow,int * showTime);
7 k+ _0 r9 y1 ]- Vint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);0 p. a- Q, r9 h1 j
" o( T8 Y1 C# ?8 u+ d, ^, x' h# _- s) K2 V
void main()
+ B0 J) W& d; [. q+ `" h* @{- T( P+ a6 Z# `7 M2 o' [$ r
PCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,
5 Q# Y4 t' f/ h- A*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;4 {- h! _4 H. N# N0 h5 v
int i=0,FIFO_memory=MAX_MEMORY,count=0,Timet_memory=MAX_MEMORY,SJF_memory=MAX_MEMORY,Priority_memory=MAX_MEMORY,HR_memory=MAX_MEMORY," k, X$ x; X( Y+ V+ O/ R
flagDraw=0,showTime=100000;
; I: S: c3 \4 u+ v+ jprocessPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;
* _3 {% U: l4 m% y! I% f& V; ]FILE *fp=NULL;
" ]( V% J( e1 Z) x _4 e//processPool HR_p,HR_mmy;
. ^" L9 h2 c. M9 N6 m6 L
- h$ V3 e/ h5 y+ u% M0 E/ x: q& n( ]6 b9 S5 @/ T4 D% y% E I
srand((unsigned)time(0));
% A4 S" z5 j/ ?7 ?( J4 \; FsystemClock=0;
9 h- D8 @/ e8 y" Xinitgraph( 1200,650,SHOWCONSOLE );, ^! N4 b7 z0 P E4 J9 w2 ^1 V
settextcolor(GREEN);
! @4 X8 J8 L" t+ r- I: h- q% J) @setlinecolor(GREEN);& u0 x, S! z, @; y
setfillcolor(GREEN);
* y; {3 o- p! W+ j. hInitPool(&FIFO_p);
; U+ r- E8 h7 W0 i6 s7 s0 h+ l+ psort_by_comingtime(&FIFO_p,-1);
2 H/ i2 N& C9 u' P* }InitPool(&Timeturn_p); E0 T$ Q$ c) u8 Q. \# `! ]1 a
InitPool(&SJF_p);
8 G& W2 }. w9 N; L/ |- L5 k( l( P* AInitPool(&Priority_p);7 n; M, f+ E1 J7 F ~9 R
InitPool(&HR_p); v% _; q7 }/ E( @0 k( i8 N
//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
- L0 c! M+ m" j- a! ~& X//Sleep(10000);+ Q' v2 ^9 v* W" B5 O8 q
5 F$ t9 v1 w( J8 S% D! @# W. X
+ S* d3 E6 I( w; wTimeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
/ g/ n1 C9 [1 c, @6 gSJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));4 H \! h, [& N* q
Priority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
6 e& e2 ^3 g! ?8 WHR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
2 M9 z) n* B( K) H& S- V# Zfor(i=0; i<initProcessNum ;i++)9 F4 w! _3 _) d: ^- t8 |! `+ [
{! o0 Q* ]& a5 t7 \5 d2 b5 A
Timeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
6 {* X. {8 p6 z7 r" m8 _Timeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));" Z) A6 D; {' u! c
SJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
% i! R' K: r r3 J1 w1 SSJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));4 y, {6 Z3 F0 m
Priority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int)); U& M6 q6 S' h9 P8 L/ ]
Priority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
6 L5 j ~0 m# g4 \HR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));1 W0 I/ ^' P, l+ v* h# H) o; o: c
HR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
3 R$ a3 q o1 a9 p0 E+ M}
+ _2 x3 r" `9 G/ HTimeturn_mmy.proNum = 0; O3 w" \# O) ^- b- w9 o
TimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);6 i+ t' K1 ^( C+ A7 e3 F2 g7 `$ e5 C8 m
SJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);4 t V! a( O4 G" Q1 W' X' p
Priority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);. ?& I. A6 M5 T0 g3 g8 Q
High_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);7 _" x% ?4 Y6 O& X
//showProcessInf(Timeturn_mmy);
* r5 Q/ f" L2 v* @ I8 g- hFIFO_pri = &FIFO_save_head;
6 e c: M9 @- R5 y& U9 KTimet_pri = &Timet_save_head;% G# Z4 J& }! q" |, R
SJF_pri = &SJF_save_head;
+ \( d l3 {6 a: r/ G3 G: UPriority_pri = &Priority_save_head;
% }* y) g: _' F# g3 K HR_pri = &HR_save_head;+ V& B! y1 E. F- x" ]) _( f
setbkcolor(WHITE);1 s9 T0 I7 b2 D& I: O/ o
while(1)
+ t! J; K! g8 F0 _4 A/ ?+ T{: R, W3 Z3 r0 r% O' i* ?
if(MouseListening()==1)2 E6 Q2 ~! v8 ^. a8 R5 u; j
flagDraw=1;8 |- K6 m7 y8 j7 y! {/ H( J
if(count==100)0 }: A8 q5 n4 u% i& {4 k9 Q/ f/ [
{6 D$ H1 \1 ~- X( p$ p4 k3 F+ N. Q
if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)
5 C; k% n' @$ w- I2 e! O# V{
1 m% }" [. }& L5 Y' [FIFO_pri = &((*FIFO_pri)->next);
4 T: w- v8 B# z5 u Q" K+ f# P, m; ?. X/ N3 ] n
//printf("hello");
/ m, I& L. T' V- f& k) @8 `! B' M}
& x* K8 t% \2 _0 Dif(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)
3 h% I3 z0 a/ |) w: l8 Q m{
& J" f' S% B( m3 N. s Timet_pri = &((*Timet_pri)->next);
$ n: _8 ~* B" V/ g//printf("hello");
, G. ?% ^7 y1 Y' C/ R}; p% d1 A$ z0 t9 s7 g
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)
3 U. V& _8 }- K; E: Z2 Y{
- h* C& `! x, OSJF_pri = &((*SJF_pri)->next);& A7 L% d8 g; y$ m$ o/ G( m
//printf("hello\n");6 l7 ]. U5 m$ D) b) F5 o* w- Y
}
* z+ ~2 I2 m/ {# i4 ^/ I% m, L( Qif(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed), [' ?$ P( k5 \7 }# j) T
{, @- K+ s& d; A; ^; Q3 \1 V8 q
Priority_pri = &((*Priority_pri)->next);, `$ d& k" T2 s
//printf("hello\n");
) m* ~& S! U2 K# M! @5 x8 h% v}, w1 m' R* q) @- u! X$ o @. k( G* ]
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)# x( P4 v( q0 Y
{! U$ |% u8 I' ]. }% F
HR_pri = &((*HR_pri)->next);! @& o/ `( F' m0 n8 {
//printf("hello");" ^' ?6 ~; r. W4 ~4 S5 f
}
7 S! R9 [; E/ k1 dcount=0;
; w" P; A3 P+ K$ v3 r$ K}
) c8 v, \4 k( x( y( I7 B6 Melse% y, R& m& ~+ I1 `, q3 P: d% I
{5 J5 d% ?2 }* X- O* | V# ^
if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)/ `! v- b% \# s4 h
{
5 W5 u. \: a: B5 a7 a$ E& [FIFO_pri = &((*FIFO_pri)->next);& @9 a9 t9 e9 ~: z
// printf("hello");7 P3 D$ F8 D% a, Z
}0 B3 j; b4 U: P% v. {
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)
2 t) b0 d+ [5 u5 I# u0 x+ u{4 f4 `( D7 W) s) x2 T M
Timet_pri = &((*Timet_pri)->next);
: y- @* Y" }, m' e7 a// printf("hello");; g) e/ W- }1 h, e/ Q& g7 a
}
6 e, _3 X0 O, f' |& f! N# F, }if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)
# @% q" N( j3 N. \, _{
* S X0 M2 Y# a; n SJF_pri = &((*SJF_pri)->next);
) C: d) b1 s2 G// printf("hello\n");
" j# e- c- g! H: ~, |5 d' C}
- {1 F) R: z& X; V- L0 zif(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)
7 m. O) m! g# ?. K( ^{! V+ f* k6 `9 r/ T8 G
Priority_pri = &((*Priority_pri)->next);$ ]. i$ Y+ @! n
//printf("hello\n");% Q( }* Z6 a8 ]2 J
}
' t2 E7 X% Z% d9 z, U" b3 kif(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)
6 T/ _9 \6 g: E4 X) ]{
) F/ h8 _2 [* |0 \* z; }HR_pri = &((*HR_pri)->next);# m" v9 U. X/ S: j- d
//printf("hello");
# y* N. g( C9 [4 ?3 X! }//Sleep(1000);
& Y% ]" v# \) y3 o& {}
; e2 e; O! B% q1 Acount++;! q! m' Y/ Q; H" l$ R
}
" r4 f* l- y5 A. i: @4 A2 I% Q) {if(systemClock==showTime)
8 j3 \! V3 ]7 F. K+ U [8 m{( j; m4 s+ h5 X, L9 x$ o2 p
/*PCI * p=FIFO_save_head;8 J7 p- e% W z" E- I# g
int i=0;
- Z0 |# ^, P. U# G/ m9 _for( ;p!=NULL;p=p->next)2 G) M& p2 ~& g. P! c5 S
{
* z) @' y/ D8 t) hprintf("Id %d\n",p->processID);
& J& e% d$ I! C0 {# Mprintf("comeingtime %d\n",p->comeingTime);8 \9 K" m8 @" g7 l' k) w1 ~% S
printf("runningtime %d\n",p->runningTime);: q0 I5 e1 @ T
printf("asdmemory %d\n",p->askMemory);: P D+ K" n6 @. u, u
printf("completedtime %d\n",p->completedTime);
* k# |, ^, m2 y a5 w/ ^. zprintf("compute %d\n",p->compute);
1 x+ S P% @9 E7 a- h+ u0 V+ P* Wprintf("exchange %d\n",p->exchange);
1 G* w: u0 \3 E0 i: k& j7 }- aprintf("waitio %d\n",p->waitio);; F. v' D; i2 r" ^' t- a4 V$ t
i++;
, z3 K5 i# m, R1 e2 H) P
! C, _( k6 U! V l7 T# h
2 `3 H, q0 ?: L5 C: G+ }}7 {' }# u2 G6 F3 r
printf("%d\n",i);*/7 V; v) U' n) ?% F1 G
if( (fp = fopen( "data.txt", "a" )) == NULL )6 z$ V) s9 J9 p$ b7 u. g
{
. ?* w8 S7 _3 B8 H& q8 Xprintf( "The file 'data.txt' was not opened\n" );
9 n- X0 l, N K4 H//return 1;1 v$ c" V- @0 Q- R) J4 @
}" u. j! T! ^( U& y0 P! E
else B) N, f6 ]1 }* y7 b
{/ k. n( n, V% G. m/ U! X
fprintf(fp,"FCFS \n");
/ w% W7 H0 h5 Y$ c# u- D; C$ o- ]2 A& sfor(p=FIFO_save_head;p!=NULL;p=p->next)
0 G) {9 r5 X0 O5 l3 k" D' jfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,$ T( B7 x. |3 Q5 F
p->exchange,p->waitio,p->runningTime);
4 K5 B0 n' Y- z0 C& zfprintf(fp,"\nTime turn \n");
w% [ P+ h8 X$ s/ o+ z: f7 Yfor(p=Timet_save_head;p!=NULL;p=p->next)
1 N- I* A! D% i* l* E* r/ vfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
: \/ m2 g, P. _$ Lp->exchange,p->waitio,p->runningTime);
V' g2 }! P! k2 jfprintf(fp,"\nShort Job First \n");$ l! x6 ^, d. U: K: P0 |: ?* Q) @2 v
for(p=SJF_save_head;p!=NULL;p=p->next)& c7 @$ r9 V, a. k1 `$ ^; Q
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
8 G' E( v1 Q1 s" O ?6 X, Up->exchange,p->waitio,p->runningTime);5 ^. \% r* L& I& v3 P
fprintf(fp,"\nPriority \n");
& ~# M- w$ _; S( n w7 Rfor(p=Priority_save_head;p!=NULL;p=p->next)( Z* }7 y4 x, ], h. N2 V
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,! {5 F/ c! n# U$ x h! ~
p->exchange,p->waitio,p->runningTime);. b+ R) N1 m1 j, @7 x9 K
fprintf(fp,"\nHigh response \n");
4 Q& l/ I& w. r% b! F8 l* Mfor(p=HR_save_head;p!=NULL;p=p->next)
# q8 w6 X2 p+ U+ |6 v! ?( g2 L+ Zfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,4 k/ W/ \ ]& H& `! z
p->exchange,p->waitio,p->runningTime);4 c3 F! c( \. a0 F" S
fclose(fp);
# Y2 |; [+ s' k+ n. _# w2 w}# U9 z8 S0 Y. k7 r( e
showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);3 n( E1 m! ~7 `# A j/ L
MouseListening2(&flagDraw,&showTime);
9 S/ z- h- D5 G! I- V7 O0 H}
6 E: G! z9 n( A/ y" F1 ]systemClock++;
$ G/ Z8 h5 ]1 G& Z' _8 V$ X. Kif(flagDraw==0)1 d6 ^! ?4 P3 z) x- q( H# z3 c( l
Sleep(10);- c1 ]: j p' x( j
}
. l: {) E+ j6 s
4 } g; H: h m6 n7 w# B n' g8 ?9 z; v2 @$ P( y) N2 O
}3 {7 ]* O; t- _
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)
1 V# ^; z5 h' i1 T4 e$ W* `" }& f{
7 w6 p/ N! R, \( fPCI * p=NULL,* name[5];
) ~8 ^* s$ V7 z2 {int count=0,i=0;3 h. B8 o7 b, I' W0 z
char ch[5][10]={"FCFS","timet","SJF","PR","HR"};
- L* I2 }* m$ k( ^9 odouble turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};
* ~' @% \) C2 F4 p6 `: Gstruct info }; _! Q* E! |' p% S! c7 u
{1 a* z. E2 M% }. [$ {
char name[10];$ x' b9 _ R, {' m
double throughput,turnover,wait,CPU_rate;
0 R. F3 W$ g/ O" ]}inf[5];3 |9 K9 ~5 w4 C% s! u
name[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;
) A( W7 Z0 |8 J! Y2 H2 {2 x# {printf("调度算法..........A\n");
1 J2 a# ^; Y Y! Kprintf("吞吐量............B\n");
* i% h0 M. T6 @$ |! Z8 C, Jprintf("平均周转时间......C\n");
, N- P+ ], ?4 [: |printf("等待时间..........D\n");
: h6 d2 V6 l' u& Jprintf("CPU利用率.........E\n");
7 ]$ k: z" M# X! t7 F+ p F. g4 ?printf("A\tB\tC\t\tD\t\tE\n");. Q" r0 J$ } t8 y* }$ S
for(i=0;i<5;i++)2 w9 [+ A% z5 H2 ~" }9 y" l1 y
{* ]) p5 y& w6 G! s+ m
count=0,turnover=0,wait=0,c=0,w=0,change=0;
+ G; U. ^' l+ i- l' W2 Ifor(p=name; p!=NULL; p=p->next)/ m3 s L4 P& v, t* q% E& ?& n8 O& ^
{
0 V; p2 N- B. ?5 }5 ^6 lcount++;
" S1 N# P5 l% `turnover += p->completedTime - p->comeingTime;
?9 n' Q0 g9 C8 p6 await += p->runningTime - p->comeingTime;
) L/ O/ S. u/ S$ ~: P9 [: O! ^c += p->compute;
1 L: h5 _* P9 L% Q q1 R6 ?w += p->waitio;& G6 K+ }7 z4 D) Y o
change += p->exchange;
6 ~) a' M3 }& h}* l2 Y& ?% `0 q z$ n7 K
turnover = turnover/count;
- _/ W2 `7 I* _# L% }# [ `$ V6 lprintf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));
) U( z' t8 L2 Q! ystrcpy(inf.name,ch);
7 M' p# a. \0 q7 `0 f4 d6 J5 a! r/ e% z- winf.throughput=count;
3 l+ V; W+ R$ Rinf.turnover=turnover;
$ K* e4 g0 Y7 h& G/ V! r5 \inf.wait=wait;$ ?5 Y S0 ~# R$ M, Y, f
inf.CPU_rate=c/(c+w+change);
G7 y* H9 A8 A% y}9 ^( _4 ^' `. y# B( k: c' W
//画图: C+ G- n5 a6 u( A% E, J$ Z
//cleardevice();6 O: I. C, R) \) `2 |8 r& X( u! y
line(0,600,1200,600);# B, _% R- ~$ k6 ?
line(10,600,10,200);( ?( }! b9 ` ]1 @( o
line(10,200,5,205);
9 F% c' z3 Q; eline(10,200,15,205);
# g* P+ w2 o* zline(310,600,310,200);
9 B# D6 v; |1 O1 b wline(310,200,305,205);
* r8 N' Z) r1 S! B+ x( lline(310,200,315,205);
" T% l& l; M* \2 o) O# p& Fline(610,600,610,200);# s: d+ Q/ u5 i% ? d" |
line(610,200,605,205);
2 \# d0 F( R% r9 ]- z: }( dline(610,200,615,205);
. R5 T% F3 J* }. U3 K3 c3 rline(910,600,910,200);
7 v; L' h, Q& I) V; j) }, F, x- Gline(910,200,905,205);
) X9 [/ Y* j; \7 Eline(910,200,915,205);//最高的长度400,宽度均为40
4 p0 u) f. ]; V( {& @for(i=0;i<5;i++)5 K# w: s& ^# `# G D
{
% T# Y. u x# T# G8 s5 h6 Mif(inf.throughput>pos[0])
/ K6 _% z& K$ T- Y6 ?* npos[0]=inf.throughput;
6 u: X% V0 d. l8 m$ i- fif(inf.turnover>pos[1])1 J% T9 W; a, m2 x( N
pos[1]=inf.turnover;
6 ?% W- T. C" G7 Bif(inf.wait>pos[2])
! P& a/ K. V' p8 N. }pos[2]=inf.wait;4 _9 g$ w! _# Y* ]. d+ i+ s
if(inf.CPU_rate>pos[3])- Q4 l k' ~3 r- z/ V% ]
pos[3]=inf.CPU_rate;1 i7 V3 Z6 Q2 }; A7 U9 K
}$ ]. }# `) v; `# B/ X
settextstyle(30, 15, _T("楷体"));
$ e3 g! B1 \6 ffor(i=0;i<5;i++)
( |# y2 d+ N* M2 W6 w{
, k; F; Y) s! S9 lswitch (i)7 S3 E; J( c# s: R. V
{
' k, Q( l" n4 N& m5 a0 \case 0:
- X9 M; S2 v' m2 |% s' z% [. P% Usetfillcolor(BLUE);
% d# m7 Y. H0 `# _fillrectangle(100,50,150,100);
; n: J6 J# S5 f5 T) g0 M) Couttextxy(160,50,"FCFS");) e4 N( [: m- e) J6 R9 i5 a
break;
: G2 S, i8 v) Xcase 1:( s3 M4 p) I6 o2 v" |; Q' a
setfillcolor(RED);
. ^6 n8 B) q3 wfillrectangle(250,50,300,100);
2 U- R) w5 @5 a5 x$ o* ]outtextxy(310,50,"timeTurn");# \3 Y1 u( C* t: Y
break;+ ?' J2 |- G4 l* _( k! H6 i
case 2:
$ e: j# |) K( C: t, x6 ~* m( ysetfillcolor(YELLOW);$ s3 Y! ?, l- G; u8 |
fillrectangle(450,50,500,100);. f9 C+ Y; w3 m9 T! ~) [
outtextxy(510,50,"SJf"); p; H- Q6 _% _, Y( I6 w
break;
/ a, V; z& ~7 {- D3 e a" R0 bcase 3:
, M, `& ^! h8 v* Y$ n8 o6 _% tsetfillcolor(BROWN);
|: Q4 M4 G. { [5 q& B. g' Ufillrectangle(580,50,630,100);
. _/ c, d, C4 C6 d3 |outtextxy(640,50,"PR");0 K: ?! l8 _1 }$ F, C( Q% Z
break;9 Q& ~* ]; d8 \) m- a7 [
case 4:+ K+ o% I4 O# T" O- B. _" z
setfillcolor(GREEN);
; h% [; q2 y$ hfillrectangle(690,50,740,100);+ T7 \% x( ?3 f7 U1 J3 e, C8 c3 ^
outtextxy(750,50,"HR");
* ~4 V( f/ U9 q& Q' [" mbreak;# b" L7 h8 R' L0 ^9 }- w o! L" H
}+ ~$ T6 w; U1 [; G0 N
fillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);
( n( D3 F+ G8 {1 `5 e% Mfillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);
' G( L( |& G" w8 D }. Nfillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);
% s* l7 U. H) _1 y: S H. _fillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);0 v3 k0 I9 b9 {& h o3 n% h6 y% U
% z9 a" h0 [" b% j2 N9 |
) R( ?- g" [! ~* {" N6 _}
1 J8 l, [$ d* e2 |2 ^ outtextxy(100,150,"吞吐量");; R! p ^4 C1 n
outtextxy(350,150,"平均周转时间");
% a, V( ~" o Wouttextxy(650,150,"平均等待时间");
+ D7 d& | W+ o/ \1 Gouttextxy(950,150,"CPU利用率");
# |$ A, k$ K# x2 M9 freturn 0;2 \- A' h# [$ M7 G9 v, J
}0 f& G$ q4 \( l# d9 X! ~
int MouseListening()8 N% F1 `+ k# O
{
4 P2 L+ b9 ?9 p% @; q! {' IMOUSEMSG p;& S0 ~) Y7 t' M9 w
if(MouseHit())
' z5 G. ~! f; h" S{
2 ^" \5 k4 D/ w6 f* [p=GetMouseMsg();$ [& v* m; u8 A
if(p.mkLButton==true)+ ?( q! h) {5 X- |6 S
{
7 k& }, l( w( gif(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
" P4 c7 x: g3 {" O* oFLAG_FIFO = 1;7 W9 L+ {1 y; J8 F% j* ~, ]0 y
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): s- d9 e' p! k# _0 }' P
FLAG_TT = 1;/ u; |# n; t' ^9 l: V
else if(p.x>800 && p.y>0 && p.x<1200 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
. Y# x2 m2 d7 \; t" T( ZFLAG_PF = 1;
+ I0 g. v) ?' b3 a9 f( }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)8 Z, V4 l/ X0 k7 O A+ F! o
FLAG_SJF = 1;
- {4 X( Q" a- `3 V! b( Felse if(p.x>400 && p.y>325 && p.x<800 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
* E; W( q. l9 S% e4 cFLAG_HR=1;
* \. y5 W7 ]6 q) Z) z; }* Y welse if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)1 H' p0 q" q! ]+ ]. B
{7 D3 _ g. p: S
FLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;4 }, ]0 ?/ g/ I8 l8 w8 @+ P
clearrectangle(800,325,1200,650);2 Q6 q+ {1 i4 T& P& J- Z
}" {- y5 L3 o- B5 G" ]" z5 T
else if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )# o* f6 f) L9 a% S0 b
{
3 c4 g2 t. }* U8 I: bFLAG_show=0;. ^; ]) l( ]9 Y, ~: M' U
cleardevice();
, w2 o. b8 {% l; ]/ y1 m# [2 \return 1;
% `+ Z2 u* y3 u}
1 C/ l" F3 t& r7 j}1 M# S* `* L6 P; B
}& n$ F8 ?' \$ Z( z [/ F
return 0;
2 p3 ~1 ^' ]( Z3 o}+ G K4 T& r0 V' t/ @. @# d$ f
int MouseListening2(int *flagShow,int * showTime)
9 T3 E; p" r1 R# f{
; w6 f& Q7 |* R+ O$ _+ eMOUSEMSG p;
6 F1 {% c+ [, P0 s/ L7 ~* Zrectangle(1150,0,1200,50);6 m" ?9 y$ ~! r# L) P, q! J' ?3 P
outtextxy(1160,10,"X");
" G& |* x, o; B2 c3 q3 Z ~$ Qwhile(1)
- v5 b9 I# h( d' F# U7 z{( e- Y& h6 d4 o; S& T
if(MouseHit())9 b B0 O( d; W0 V& p3 x
{
. j0 g! z# X! Fp=GetMouseMsg();& F5 G7 j8 b1 |: x+ O, C' O# l
if(p.mkLButton==true)- Q o# @$ t/ M7 F
{
0 x, p& a: ?1 H# H( p0 i* S, ?if(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 )
! c+ f p% N/ k# |; F{
& r6 x! M) _: V y# V( @(*flagShow) = 0;3 E4 }% `& i$ `/ i. R7 F6 n
(*showTime) += (*showTime);& {1 Z+ n% m% Z, D& e7 y% l
FLAG_show=1;
8 _+ \9 H& B* y4 _) S1 i0 Hbreak;5 f$ ?+ ^. Q {. h
}
! }) N7 C' c% D5 I$ R" l- F0 M$ A8 V( D: p [+ s* K
}3 K. K9 u5 ]9 g1 }4 J
}
5 W" ~# y6 Y# V- E( v# t% z: r! eSleep(20);
2 q6 n3 T" y+ X$ i}
, N% g c d2 J+ M) R d) |3 I Gcleardevice();( {9 d" T: l N0 P; a% e( _/ w
return 0;$ ]+ y2 E# r6 k8 d u
}7 G' R$ W, L5 q1 _* H5 I2 x
int drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)6 t1 Y' Y4 o( n6 [
{
8 w. p5 l; m1 T8 E6 B' a0 q2 Xstatic int info[11][3],num=0;( m* H- X# `1 L' j3 f6 ~
int i=0,j=0,pos[10][3][2];
( C" l% y% Z% ~/ M. c+ xfloat temp,t;
; G5 \2 @2 o+ o5 ~ g//画按钮,不属于FIFO图的范围
2 P1 k0 y" k0 v/ Q8 J* I& _if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1). D) p: ? d H, m/ }
{
3 z7 n# k) G! ^* m% d3 Msettextstyle(30, 15, _T("楷体"));: h1 q; r7 j D
rectangle(890,455,1110,510);
: {( J5 l" j) m# Q n5 brectangle(900,465,1100,500);
/ S1 N0 Y# G( l1 r- vouttextxy(910,468,"查看运行结果");# Z3 f7 K" `9 J# U' z9 a' U* t
}
% y! U6 F' s7 F l6 V5 I- g0 _//结束画按钮+ G" A1 F8 G$ ^
info[num][0] = com;" T0 e/ _, V' |" k% c! v; t
info[num][1] = wai;
& B! Q" l7 w# i; P) J/ T& ~8 g7 [info[num++][2] = cha;
' G# g$ X& }( sif(num>10) //存储10个点
t! d" o+ H6 J3 K2 h1 K9 M" z. W{
' F! Z1 \; T6 k0 j9 G* Rfor(i=0 ;i<10;i++)
4 J- M. V% f1 N. [{/ T( H! O8 Z' s" B
info[0] = info[i+1][0];
0 _- _" H3 @4 @" T, Einfo[1] = info[i+1][1];; m" A0 C" H3 V
info[2] = info[i+1][2];5 h) H$ T$ m3 D2 |8 W3 K% j! I
}* z! q0 Z1 @% a+ o( s
num--;$ u: `3 N3 F. L% O7 k5 S- t& P
}
3 |* n# h/ g. Zif(FLAG_show==0)
) R! f" s4 |5 q6 U3 P, v" nreturn 0;/ a5 z$ t9 b0 n8 _8 T
for(i=0; i<num; i++)
B9 Z: v! ~ l. m5 x! W{0 o3 j) Q2 R& S s e3 j3 E
t = (float)info[0];$ S+ Y5 k: e1 D7 E' z
temp = (t/101)*90;' h. F8 [ O; x- Y8 T# _
pos[0][0] = (10-num+i)*25+x+100;
7 B6 v' R( i7 h qpos[0][1] = y+110-(int)temp;: q- y; [3 P8 f: N
t = (float)info[1];
) s. p* f* g A" B/ X9 ztemp = (t/101)*90;
4 b' t, o0 J; d* b+ N& X& k' {, q& Hpos[1][0] = (10-num+i)*25+x+100;' d8 Q8 ?( L6 ^3 w9 c) H0 r
pos[1][1] = y+210-(int)temp;
& i2 v$ b3 v- Z a2 {t = (float)info[2];6 y9 x3 `0 f8 v' M( g3 K
temp = (t/101)*90;1 H1 f6 q. c9 A7 g
pos[2][0] = (10-num+i)*25+x+100;
( G9 P( j+ j; X4 Gpos[2][1] = y+310-(int)temp;. j: H0 V$ m, l' h
}! ] U$ q& n( J; e
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
; q$ D$ [9 V5 X9 X! `{8 v* Q2 N% Q% M: }' Z1 y( d) w
clearrectangle(x,y,x+400,y+315);. M; b7 q8 P. T
settextstyle(20, 10, _T("楷体"));# m% Y: q3 X! L, D
rectangle(x,y,x+400,y+325);
2 S; F' R6 q0 L& r; aouttextxy(x+40,y+10,"CPU"); //画柱状图
+ A. G7 |: w, i" w7 \& Bouttextxy(x+45,y+10+100,"IO"); u. h! J0 H; v* N5 ^
outtextxy(x+40-15,y+10+200,"change");/ O9 a2 q1 A/ c3 X4 S3 m( G
rectangle(x+35,y+30,x+75,y+110);
3 i8 J+ m; D/ V" Trectangle(x+35,y+130,x+75,y+210);+ N8 _' l# ]! F/ W
rectangle(x+35,y+230,x+75,y+310);
- k5 T7 Z) z3 ~+ i X/ Douttextxy(x+180,y+310,"FCFS");
% M1 R9 N( d$ o* I) { jt = (float)com;
( Z' b) W2 E9 M) r3 Stemp=(t/101)*80;% \3 A5 @/ A1 j" S, L$ V
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
. v% t: B" R4 u3 J2 z! Zt = (float)wai;
1 q o+ C7 Q, }5 t8 ftemp=(t/101)*80;& @# Z3 f5 A/ K
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);9 C$ }6 o7 u# m: f( R. ~8 P
t = (float)cha;
6 ?& h2 w0 a4 a5 Gtemp=(t/101)*80;3 m) _8 t+ E6 o; C. |* a: f/ i
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
8 l! K7 A( p! Bfor(i=0; i<3; i++) //画坐标 high=90,length=250
+ K6 ]/ |* v2 @, B{
- i1 B, l2 q) S2 ?& aline(x+100,y+110+100*i,x+350,y+110+100*i);
6 }9 b. I4 v7 pline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);3 T- v- B0 m" L% k
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
0 g5 E% g9 h6 i1 Z% C5 }- D2 f9 ]- ^+ g1 m; F( j- w
line(x+100,y+110+100*i,x+100,y+20+100*i);
# P; E$ I0 z' f( I' pline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);' L; Q( O, k4 k( V
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);" X ^+ q8 y) f' A9 l" s) j
for(j=0;j<num-1;j++)
% g; {4 k3 M$ |, M5 G, N9 d{1 g1 z9 ~1 w+ F' Z) F y2 U
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);- e: `- @. y) d: Q2 w6 w( r5 @
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);2 K! @7 g5 F, a9 B2 z1 _
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); , L/ t' }2 Z# l; q& N- h: G7 u9 H$ J- F
}: B% o9 R b& F" @ L, x% A
}
9 b' H2 l3 d, _. X- Z. S0 j, P4 q. J}
5 h. r9 ?0 U6 ~1 s6 v5 yelse if(FLAG_FIFO==1)
0 c x8 U7 y) c{; a- L% h/ [0 p, J6 B
x=0,y=0;
7 z p' ^7 d+ T: M9 m9 v7 Cfor(i=0; i<num; i++)
* \4 U3 o' n' j3 M p7 t{0 o3 U& H x8 D8 {
t = (float)info[0];
/ K# C5 s" P( O+ a' T( _temp = (t/101)*180;
- |: U" V$ \5 i( l% Q8 ~1 Jpos[0][0] = (10-num+i)*50+x+650;
7 K1 S; G- S$ W, Q4 J+ j- }* Npos[0][1] = y+210-(int)temp;
: ]5 V* F8 o# ~ r7 r& A+ ft = (float)info[1];* v0 R( s- y( H9 k8 i% h, k
temp = (t/101)*180;0 P" Y$ w& a* \! }+ s4 @) i9 m5 x
pos[1][0] = (10-num+i)*50+x+650;
+ k7 \( c3 F/ L+ F( epos[1][1] = y+420-(int)temp;
, }/ W7 E+ W+ R1 |t = (float)info[2];2 \. G* [6 ^9 p. ]
temp = (float)(t/101)*180;
7 _# k2 P& P7 o f& y5 d, T, Mpos[2][0] = (10-num+i)*50+x+650;9 t0 g$ }8 H6 Q
pos[2][1] = y+630-(int)temp;
, J0 E3 U2 I# c& t& g+ D* T}
& f$ F9 J- U, [" f, }; Y7 gclearrectangle(x,y,x+1200,y+650);
* t- T8 k" B' U- G% z1 G, tsettextstyle(40, 20, _T("楷体"));1 Q- P4 m2 a! e6 w h
outtextxy(x+50,y+50,"FCFS");
" R( |& o- a% X4 [7 l; L2 T7 Xouttextxy(x+280,y+20,"CPU"); //画柱状图
6 J* _. w' m% _. Aouttextxy(x+285,y+20+200,"IO");
& L2 D& o) K9 G% F+ p: Jouttextxy(x+250,y+20+400,"change");$ X D1 N3 {5 h2 T+ ^( ~, L! {# u
rectangle(x+270,y+65,x+330,y+215);, @4 d9 {/ e' v# s6 ^1 ~. w
rectangle(x+270,y+265,x+330,y+415);2 Y i+ F- ]" l9 z. E1 s& S5 }
rectangle(x+270,y+465,x+330,y+615);
`! S0 J- B! ?2 ?+ jouttextxy(x+290,y+620,"TT");
% ~( j- N2 t6 w9 X3 l$ Q( Pt = (float)com;+ C7 K! w) W) ]$ s; i& b. R' Y
temp=(t/101)*150;# L7 D0 @. T9 s
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
" E6 d% [( G3 Rt = (float)wai;1 f' j9 I9 G" l) ~7 ?8 `* p
temp=(t/101)*150;! y* ^" V# P1 }7 z
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
" w& p$ D' c# Y% n+ xt = (float)cha;
% b6 @# e7 u1 `5 l) @; m: wtemp=(t/101)*150;
, N' z2 o' C" Z5 i3 ^! l% R; Yfillrectangle(x+270,y+615-(int)temp,x+330,y+615);
8 t8 p: r/ J& A" M+ J5 Jfor(i=0; i<3; i++) //画坐标 high=90,length=250
9 J9 {9 i% d7 N7 ?6 @; E/ ~{
, u* h/ {7 l% c; F' \ lline(x+650,y+210+210*i,x+1150,y+210+210*i);0 T/ z' o4 s- c) a3 t6 M
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);) v3 I8 W5 a( B
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
: {) L A; i/ l0 H/ @
8 {+ o3 F/ m. |$ {: A5 u/ Z' w nline(x+650,y+210+210*i,x+650,y+20+210*i);, \. G/ a1 R9 u# s$ f
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);- m \& n! q( @: g6 @1 G2 i
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
7 W7 T% E# e( v( y6 v; B1 dfor(j=0;j<num-1;j++)7 J$ s8 F& `/ Y! L# g
{
: t( I o- R4 Sline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);3 d* R& R h7 S9 j7 O% i a
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]); Q1 ?' M5 C) E6 H$ K6 r
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); & E9 Z' {7 u: A2 D
}
1 V1 b6 @" M6 A7 r) R8 b}
0 O# t/ ?- u, b- i( ^+ |- g- H}0 q- z, y2 G( ^, G8 r: h4 r5 N/ q3 ^' B
/ ?& v$ {0 H3 n2 f3 R! w* j: b: z' Y% i+ s R
return 0;. C% O5 j: Y! p
}% S# W2 z* C) g f" y
int drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)
) B6 a3 G/ p q s6 A$ h{. o6 W2 z& K! p9 d/ r
static int info[11][3],num=0;
1 P: l8 }, W) Z* Zint i=0,j=0,pos[10][3][2];
1 b( \0 b1 v# a7 c% @2 ufloat temp,t;5 `& D6 K- p: R& U
info[num][0] = com;
! M+ `( Y' F" N. a1 S7 Pinfo[num][1] = wai;
+ k4 r9 m, }; N1 ]. B# {info[num++][2] = cha;/ T3 F' H# q7 l: G( n' o7 z
if(num>10) //存储10个点' Q, y( _/ o* J, U* r7 z
{5 a; F! }% Y0 ] r4 z- ?: b: \
for(i=0 ;i<10;i++)
0 Y5 G) h7 ~9 u: W1 j; p{
6 ~. A6 O' k/ i$ y$ winfo[0] = info[i+1][0];8 ~# u' w4 Y4 |! J; m
info[1] = info[i+1][1];* _; A' `1 h! y4 O
info[2] = info[i+1][2]; Q4 {& i2 _$ T7 g1 J
}
% L& ]9 `" x" r( q5 x6 E7 E, bnum--;) y. o! ~ {2 z9 i- g( K6 }* |- n4 j
}
( j' T+ {" J% g: g+ c9 ]; Kif(FLAG_show==0)
7 l$ Q5 C; z9 ureturn 0;+ s6 E+ W# Z0 L. t9 }! ?" O3 Y: f; `
for(i=0; i<num; i++)+ ?1 a: M6 F- o- J
{' U8 ^7 z1 ^* d- t% p% i- `( k
t = (float)info[0];7 N2 \9 r9 A! [1 N, [, ^( T! d
temp = (t/101)*90;
' l' X. {0 S# |% n/ S9 \pos[0][0] = (10-num+i)*25+x+100;4 c# v1 b4 P. n' n3 I
pos[0][1] = y+110-(int)temp;
7 J# Z2 E: D9 Q0 a9 s" h* nt = (float)info[1];) Z2 ~, I7 h9 D4 ^2 }; Y" h. ]+ E+ n! V
temp = (t/101)*90;6 B, Q9 u' s K/ G0 i. t* v7 H
pos[1][0] = (10-num+i)*25+x+100;
4 M) I+ v! H1 O3 Zpos[1][1] = y+210-(int)temp;' `8 m" R; y# x# ^
t = (float)info[2]; z! Y( u0 i `! Z5 H4 S
temp = (float)(t/101)*90;
- E' q7 N1 k7 ^5 U# L) l+ vpos[2][0] = (10-num+i)*25+x+100;6 {; _* f& G6 p8 e( b
pos[2][1] = y+310-(int)temp;8 d( g7 n4 }1 [
}+ }7 a6 M" E# ^" K$ \/ K, k
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)- D" O7 _4 P, T1 {* L
{. R6 B& M% e+ A) d' H$ _
clearrectangle(x,y,x+400,y+315);
+ H0 ]* \) i4 U& o8 P4 p6 n# usettextstyle(20, 10, _T("楷体"));
. S8 h* l8 w3 C( Grectangle(x,y,x+400,y+325);) I( n7 l- H" K" e* N6 ~
outtextxy(x+40,y+10,"CPU"); //画柱状图
6 M+ J+ A, |' J& kouttextxy(x+45,y+10+100,"IO");3 w( y7 z8 z1 ^2 X+ J7 ^
outtextxy(x+40-15,y+10+200,"change");
" @% |) C" o4 w7 D9 b0 B/ |rectangle(x+35,y+30,x+75,y+110);
" ^$ R: }" h( S8 a/ P) ^3 Frectangle(x+35,y+130,x+75,y+210);3 Y! F1 P. n) z$ Q
rectangle(x+35,y+230,x+75,y+310);" D, K' L+ e0 U
outtextxy(x+180,y+310,"HR");1 l- ?. s% u; T
t = (float)com;) N/ S, U( m _, i! }! c& @
temp=(t/101)*80;0 P; b: p2 ]. o: d) k" _
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);* p# f# Y, O( H9 E1 s
t = (float)wai;
8 G$ u9 o3 T! A5 U& C' Etemp=(t/101)*80;
4 @- h& r9 _" Nfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
6 T8 _5 G; L, b5 A) P D! Ut = (float)cha;
/ j3 T/ R6 Q2 D$ M. ~- @temp=(t/101)*80;& f6 @1 _2 v, V0 i: [# Z
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);+ |) r! f) u0 b6 I
for(i=0; i<3; i++) //画坐标 high=90,length=250
, F1 t9 p6 U% P3 v8 o{$ R! s7 ]& [2 ]) |, Z- Z
line(x+100,y+110+100*i,x+350,y+110+100*i);
) i3 _7 G6 U- b1 x' Dline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
( @9 l8 H+ A7 Sline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);7 \* V" `" G- m3 H
$ ^+ u+ N' ~" ^+ k7 `line(x+100,y+110+100*i,x+100,y+20+100*i);
3 L; f6 c6 @$ ?line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);4 M* d! d4 |) L/ i
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
( n2 s$ ~) R6 ~. c, w. a, Mfor(j=0;j<num-1;j++)
; x9 M7 W C3 Q: n# p9 ^* {{
/ L# {% I: H* h* Zline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);5 M% g z( h; Q$ K6 Q
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
& w2 t* q0 |8 y! H# |5 F9 p( Jline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
% h% Q% h2 q% i}
7 s( M$ @7 P6 G! @$ v; s. j}
+ G) Q2 b% Z4 z9 V, _/ ^}; p! d7 N3 a5 U
else if(FLAG_HR==1)" h( U* J0 ]5 p' G3 }
{
5 k! B( n+ ?6 r/ l; Q+ Zx=0,y=0;* i$ y+ J3 S9 L; a1 x# d8 R! E
for(i=0; i<num; i++)
. k, }) u* A3 V+ c2 T9 N{' s3 R. F8 R1 F
t = (float)info[0];
( e7 T: b8 o( stemp = (t/101)*180;
6 ~& p2 m, S. [! T2 Apos[0][0] = (10-num+i)*50+x+650;
: f$ v- P' ^% I5 a" o9 Ppos[0][1] = y+210-(int)temp;3 C$ _- N- Y9 ?1 H0 q
t = (float)info[1];% b+ R! o- {0 O9 N
temp = (t/101)*180;5 P( e! s0 O8 n6 g
pos[1][0] = (10-num+i)*50+x+650;. f7 l, T1 C- G1 ^* U3 I4 l7 @
pos[1][1] = y+420-(int)temp;: H; b# U/ M' O" K4 b
t = (float)info[2];
5 u0 S4 s4 u9 d# H* P% gtemp = (float)(t/101)*180;
$ i5 r% D4 j/ x: a: npos[2][0] = (10-num+i)*50+x+650;
: T B6 ^9 s1 a- F2 a1 Jpos[2][1] = y+630-(int)temp;! ?* g8 b( D r* d$ V/ c% @
}
- u( m% H/ ?. l$ t! Aclearrectangle(x,y,x+1200,y+650);) P4 [" b2 Y3 i; {# C3 c6 A! `
settextstyle(40, 20, _T("楷体"));
0 z4 j" I! n! aouttextxy(x+50,y+50,"HR");
9 b- e; ]7 {, jouttextxy(x+280,y+20,"CPU"); //画柱状图
" n B# z* Y2 u' routtextxy(x+285,y+20+200,"IO");! R- f; O3 l$ M
outtextxy(x+250,y+20+400,"change");
9 ] |4 V5 t+ }. \& M2 Hrectangle(x+270,y+65,x+330,y+215);
+ X0 y N1 R8 a9 Q, ^rectangle(x+270,y+265,x+330,y+415);
4 ?# v w1 ^, `0 G( Z3 L* {rectangle(x+270,y+465,x+330,y+615); z+ E7 \2 I4 C# H! @
outtextxy(x+290,y+620,"TT");% G. r& Y- ^! s, Y( T
t = (float)com;
# ^( J v. f0 T* |5 gtemp=(t/101)*150;( h) r3 G2 D) b1 |& ` O+ u
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);9 ?2 p' `: l7 q9 y" n1 @& j9 A
t = (float)wai;
: `7 A2 ?3 P% H: y( @0 K; jtemp=(t/101)*150;4 g$ r$ j* H9 z& L' Q
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);& J6 S9 p: @1 |9 ^/ h8 Z5 T
t = (float)cha;. X A; ^: ~3 N0 B3 R6 F$ l6 n
temp=(t/101)*150;
2 x/ V) u) X, @. `! j. mfillrectangle(x+270,y+615-(int)temp,x+330,y+615);
: k! ^' m" n) W! O9 P/ lfor(i=0; i<3; i++) //画坐标 high=90,length=250
R5 ^' @6 Y8 q6 Q{9 R9 ]/ O% v, [- `
line(x+650,y+210+210*i,x+1150,y+210+210*i);; w$ q4 w% F L$ _3 K. u4 l# e
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);7 Y$ C3 W: P" I( v4 U
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
# V4 f ~+ }% Z I1 s
( i. o4 f7 r2 p1 P0 a gline(x+650,y+210+210*i,x+650,y+20+210*i);
$ z0 T3 |3 v- U- w) l+ Tline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
8 v- F& f+ V; b" H1 W$ fline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
$ y5 n% V! o! p% F9 {1 k# Kfor(j=0;j<num-1;j++)+ E( h5 X9 o' \% |
{6 K; N/ a1 W( }+ j, S' P- j
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
( E' c: S0 K2 B3 N D( t7 m/ u* pline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);- B5 [) k* y* E# b3 @/ S4 c4 q, s5 T
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 0 w' r( b9 r( F3 l) ^3 G" ^
}4 J& k( s1 {0 s: a- I- {
}
. l: D% n! @6 m9 Q}
7 d' k) P$ L6 V0 {: k8 j7 T0 ~9 ?( y2 O
; Q8 j/ C7 l# E, Z) j
return 0;
0 T7 T2 V+ h% U$ q8 E+ w( K}
6 f2 G P g+ z7 jint drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)% t( F4 m+ X1 `! Z8 {, f
{3 v( S3 w4 c9 J* C Y+ n
static int info[11][3],num=0;
* l! X1 J/ S9 m5 I) K8 Mint i=0,j=0,pos[10][3][2];
2 C% s0 W* s& j( ?! `; V. J- _float temp,t;* e$ Y9 t4 f$ j3 g$ a7 S
info[num][0] = com;6 l, r) l1 t! _
info[num][1] = wai;' Z9 m$ h, a2 V; L3 w
info[num++][2] = cha;! r! Y. w, E( v9 n4 H* V3 Y9 n- C
if(num>10) //存储10个点. ~/ n j+ N$ M" f8 P' T K0 |6 ]
{
% x7 t) I3 J) Z. l. I7 R# Tfor(i=0 ;i<10;i++)/ n6 o: h0 \6 U8 W5 ]
{! l! j+ R2 b& A$ T
info[0] = info[i+1][0];
& ]1 N8 C, G5 M# }info[1] = info[i+1][1];
0 ^$ r3 @4 Q0 @2 W+ S% Y' Linfo[2] = info[i+1][2];" B) _/ L6 R$ |
}/ U: [, n4 |" C. g' [+ S d
num--;; j- K6 T+ K: F h
}; c6 o3 P2 [. h# ]6 `( m z8 m
if(FLAG_show==0), l9 a1 B) S% J+ w2 d
return 0;3 _& I0 I# m: p8 O
for(i=0; i<num; i++)1 {1 e1 {8 J- x# ?! n. } @( u
{2 Y; k* Q3 e9 E9 a) Z% z
t = (float)info[0];; R7 \, L2 n. B% K9 Y2 l
temp = (t/101)*90;
% X4 Q* E: ~) v. ?pos[0][0] = (10-num+i)*25+x+100;+ D$ f1 I) I1 _
pos[0][1] = y+110-(int)temp;
" W8 y7 I1 O# D, V: v5 a* L: K" Z( Qt = (float)info[1];
( P& H+ V# |1 e1 ?temp = (t/101)*90;
6 i( [% i% E! ~+ ?pos[1][0] = (10-num+i)*25+x+100;2 u) k) m, N0 U, G0 ^
pos[1][1] = y+210-(int)temp;" p) F, _( M' u
t = (float)info[2];
3 N n. k+ i/ Z4 `: u! ftemp = (float)(t/101)*90;
; o9 F) C+ f3 C0 E* U* f3 y8 hpos[2][0] = (10-num+i)*25+x+100;3 q1 W' ^, z! f; H9 H( _
pos[2][1] = y+310-(int)temp;2 H4 M+ [4 L- f# ~
}
9 x# n" W5 E& f2 g2 ^, G! ^2 ?5 nif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)' H9 c' h& e5 Z& _; I
{0 [9 p; G# X- g* \+ h
clearrectangle(x,y,x+400,y+315);
3 m# b& M3 V/ B8 E0 x s4 dsettextstyle(20, 10, _T("楷体"));5 _" z e8 l; a d2 T6 h
rectangle(x,y,x+400,y+325);
( r( m# S. X' M6 J- v: r% @outtextxy(x+40,y+10,"CPU"); //画柱状图
( C! ^' z0 N8 Y* _outtextxy(x+45,y+10+100,"IO");5 O/ s( f/ `5 }' a. n4 t; j* z4 [
outtextxy(x+40-15,y+10+200,"change");
; Y3 m2 U9 p6 xrectangle(x+35,y+30,x+75,y+110);
6 \* k1 q, }! h( |4 O" mrectangle(x+35,y+130,x+75,y+210);
" w* s/ Z5 u/ u$ prectangle(x+35,y+230,x+75,y+310);
, _% f8 ?& g, O. w% Uouttextxy(x+180,y+310,"TT");1 E4 b8 X* a9 W* n7 P6 K' \7 M$ G
t = (float)com;# p' I* D+ f, r6 F7 m( x; K
temp=(t/101)*80;
3 q4 J: n u: c6 c$ f% s8 Gfillrectangle(x+35,y+110-(int)temp,x+75,y+110);; d- n6 I4 H; X5 g- x5 l
t = (float)wai;
/ l: @/ o) X: O7 R g& S4 l% ]: Ttemp=(t/101)*80;
/ y& q E6 ]0 {- \0 L3 W2 u, Ofillrectangle(x+35,y+210-(int)temp,x+75,y+210);- ^) @* n" u1 a4 ^5 s7 r
t = (float)cha;, Z) E* p* @$ R5 w" P
temp=(t/101)*80;+ J4 k$ f5 \' R2 l- ~
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
6 N$ i F1 [+ {0 l4 Kfor(i=0; i<3; i++) //画坐标 high=90,length=2504 j( I& v( d ?" J6 O$ c
{, X6 E. ?2 a! y$ q# A
line(x+100,y+110+100*i,x+350,y+110+100*i);% Z: K5 ~# A4 d* t* J; n
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);; ?; ?3 b" `9 S* e1 G: ~/ y
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);, D" i4 D8 u) t( l1 _$ s7 f& e
8 T) v. T. G% `+ y0 }( t4 V4 c
line(x+100,y+110+100*i,x+100,y+20+100*i);
% X6 s/ h: U% U# V, ^; Vline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
2 R1 d2 Z3 P5 o' V' x8 y" qline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);9 F6 y" r2 H* r/ x5 y; \4 _* F( _/ u
for(j=0;j<num-1;j++)
$ d8 e2 R4 g8 A. p! {" [* e{
/ g7 R4 G6 x3 Lline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
$ S' L, ^' a; a& |, f5 W; F: yline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
K* S! ^! f& C5 t/ }5 F( uline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); % H4 T+ _2 A4 S7 I2 e, a1 n" f
}3 m- O) @ c' B+ N$ X
}
; ]! P- L" t# u& @4 a9 h# A}& ~; l3 f4 t& i: W9 g
else if(FLAG_TT==1)
7 ~0 R2 P) t8 G7 u{1 w g; o/ ^6 D5 o
x=0,y=0;
( n* n0 F, _' T. C- Mfor(i=0; i<num; i++)- \% f* N% M. [
{/ R( j3 `2 c2 l, E" \; R# ~4 C
t = (float)info[0];) V' D+ S# L" _" ~: a1 i) {$ v
temp = (t/101)*180;. o2 y6 O' H: ^2 c
pos[0][0] = (10-num+i)*50+x+650;. R' @2 x9 h! c" z, {) r
pos[0][1] = y+210-(int)temp;% z" V! b; M1 J# _4 ^
t = (float)info[1];) t4 T& x* ^- M
temp = (t/101)*180;
" h$ s1 r% L) Q* s: |2 U( `pos[1][0] = (10-num+i)*50+x+650;
- P4 n) v* f% ?) n' Gpos[1][1] = y+420-(int)temp;! _. K2 \& S# R6 M Y/ u h
t = (float)info[2];
) @! _. U2 [! d* W" h4 ltemp = (float)(t/101)*180;
* |' W! I& p9 X) F, b+ s) M0 Vpos[2][0] = (10-num+i)*50+x+650;
6 i3 r( E7 ~% r7 z$ X% e" Q' vpos[2][1] = y+630-(int)temp;
8 t1 O+ N2 u$ F) F* q) L}- Q% j$ C# p- h
clearrectangle(x,y,x+1200,y+650);
! m1 j& Q6 q! v0 M, C& Dsettextstyle(40, 20, _T("楷体"));1 T/ g* c5 V9 v% R( \% g" |
outtextxy(x+50,y+50,"TT");. h5 ^2 B) ~0 j& V
outtextxy(x+280,y+20,"CPU"); //画柱状图& ~5 V0 D: S' B# |. Y9 \
outtextxy(x+285,y+20+200,"IO");) q; _" C1 r7 C' k
outtextxy(x+250,y+20+400,"change");
) w1 ]& `; \$ X7 \6 `: m: prectangle(x+270,y+65,x+330,y+215);5 Z0 P- ^, E5 R/ g2 i6 B# ^$ J2 e
rectangle(x+270,y+265,x+330,y+415);
7 L2 r1 c0 t, o$ Frectangle(x+270,y+465,x+330,y+615);$ h" h9 A" f, i I: }
outtextxy(x+290,y+620,"TT");' L$ |' n$ J) z' N( F( T
t = (float)com;
3 e7 ]# L: H4 Z% Y. ^temp=(t/101)*150;
9 w9 e3 t- N N& e0 q2 Yfillrectangle(x+270,y+215-(int)temp,x+330,y+215);8 B5 G0 ]* t. a* w
t = (float)wai;4 @9 p/ `9 \4 _- {7 Y3 V
temp=(t/101)*150;; R$ f7 V1 U9 x7 ^, x* j
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);' N/ i; @; V: }, E9 p% ]$ g: ?
t = (float)cha;$ M0 [, C* X8 u- i
temp=(t/101)*150;5 l. G( S; k+ H8 m) r/ r
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
! _2 |: v5 P% n8 Ofor(i=0; i<3; i++) //画坐标 high=90,length=250
1 x1 h! ^/ z$ ` W$ {0 B4 C{
[" {6 D1 ^2 i: w2 Kline(x+650,y+210+210*i,x+1150,y+210+210*i);) |. c4 O" B, `4 `( ~5 y0 i" n
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);8 H8 A6 v2 r) I9 b6 g4 E: ?. n! O
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
& T9 m: d% q0 h: K0 _( `) t4 ?
, ~; b+ N- K( s4 d. A9 V& D6 Nline(x+650,y+210+210*i,x+650,y+20+210*i);
) b0 x. i9 T+ x, {' l3 {3 vline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);. h5 }2 ^) K' Z& F& p1 K
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
. [( R6 u0 W4 l/ _% e- ~$ L- \for(j=0;j<num-1;j++)
6 `* r# y( l. Z; i8 n% E{
9 ]+ X' x& V+ l D" yline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);' j5 m3 T, W7 \5 ?& s7 w
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);( W* X# y, [' E$ f) `
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
" f# ]4 ~+ k; F) O) h9 K}# B$ I/ D3 q$ g. N
}& n1 v. I- g$ X% R
}9 D3 I: e. }5 z9 |5 I
6 F1 O. \. J* E. j* j+ {% P) k! [% R+ O8 a, M$ T5 c3 I
return 0;
- z) r; ~$ x' @/ F( f/ _}
8 e: w( v& s H; g R; `+ [/ Gint drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)
$ c& {4 s9 j% ~! ?# a{; t$ G7 \7 X1 t K+ u
static int info[11][3],num=0;
4 i& w0 T5 `( I1 ~% ^2 S+ \int i=0,j=0,pos[10][3][2];0 F9 j0 l- C' W4 K, W; R
float temp,t;
2 P3 j3 ]& g4 L6 v- I& _/ d; linfo[num][0] = com;
! Y9 K" D R" E4 k8 j+ Sinfo[num][1] = wai;; Z. z+ P* H- A. j* |
info[num++][2] = cha;# A1 W- d9 N8 w" s
if(num>10) //存储10个点
# u0 k2 z! }4 [4 n+ I) |{9 |( R/ l% F; n, |2 e' W
for(i=0 ;i<10;i++)5 i& E5 c, ]9 z) _. h/ ~4 k3 a
{
4 o1 n! f( f" ` V1 l! E# Pinfo[0] = info[i+1][0];# b0 f* D6 F9 C* R3 r7 Q
info[1] = info[i+1][1];
7 p4 P( K5 P5 R, ~/ P: ~info[2] = info[i+1][2];
. d6 |" J! t1 d9 {/ @+ h6 L}$ U# F2 B2 I ^; O# D6 w0 `
num--;
: y* n2 w# \% G) [8 f) s}2 X% b! E( h+ D8 s# u
if(FLAG_show==0)0 _' X/ v2 ^3 w* i
return 0;
. q( }$ J# N0 yfor(i=0; i<num; i++)
* w7 ~: q" n! {1 T! }0 i5 _' F( z) L, |{5 j5 Y9 x( J4 i* C7 T
t = (float)info[0];
& q- j2 }1 Y4 _( a& @) ?3 Vtemp = (t/101)*90;$ u1 h+ h. L4 Y; i7 r6 }2 ~
pos[0][0] = (10-num+i)*25+x+100;* O# }+ Q: D' Z1 M6 O9 s
pos[0][1] = y+110-(int)temp;9 q$ w% G- J$ v) t( P) u! k0 Z+ ]1 Z
t = (float)info[1];
3 m/ j. a' s, @$ _3 H( ?temp = (t/101)*90;
& l B' H& N0 ?4 f% Mpos[1][0] = (10-num+i)*25+x+100;
4 J. X5 M* O4 g: s% g' Hpos[1][1] = y+210-(int)temp;
" y: R5 |; ~; l5 V/ A8 U B: _t = (float)info[2];
! G2 d! v1 N$ Qtemp = (float)(t/101)*90;* Z" h/ U+ S; Q; P
pos[2][0] = (10-num+i)*25+x+100;- a; l' t8 H6 J7 q& D
pos[2][1] = y+310-(int)temp;1 U, z; V6 f6 d I. `7 p
}6 k0 s4 T0 F0 q
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)5 B2 n! z8 ~% G" s& d' v) ?% m2 E
{) ^+ W7 S& F5 Q4 P8 q: ?
clearrectangle(x,y,x+400,y+315);
' u% `8 N) c: o' _. P6 _+ o5 h- ksettextstyle(20, 10, _T("楷体"));
' n) j* y" y7 ^2 o' C8 z* R, Z% grectangle(x,y,x+400,y+325);
1 k- U9 e: Y% m( j% E* ~outtextxy(x+40,y+10,"CPU"); //画柱状图4 f4 @# U- m. J+ c) Z$ m
outtextxy(x+45,y+10+100,"IO");
. l7 W6 W( l2 k" f4 }" b6 Jouttextxy(x+40-15,y+10+200,"change");& T6 a. n1 f+ |- v9 B
rectangle(x+35,y+30,x+75,y+110);
0 y1 w# ^& i# C( g% x( nrectangle(x+35,y+130,x+75,y+210);
0 `# o7 `' D7 d Jrectangle(x+35,y+230,x+75,y+310);8 s3 ~) R$ S' I5 f
outtextxy(x+180,y+310,"PF");3 x- a: H* ]6 o5 Y
t = (float)com;- ?6 _- I6 @! a
temp=(t/101)*80;
5 x0 @' N: ?/ }8 P3 g, D! p6 _& q# Hfillrectangle(x+35,y+110-(int)temp,x+75,y+110);
0 d. i9 m* D6 {: q! F- n, d8 gt = (float)wai;
% S/ k8 l' b2 D0 l8 z3 A: J) Rtemp=(t/101)*80;( j( ^- m2 b; V* w
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);: O" o" m6 y/ F3 q
t = (float)cha;! M7 E5 U( m* U' U1 L4 O
temp=(t/101)*80;
" i; J6 O+ E, B( Yfillrectangle(x+35,y+310-(int)temp,x+75,y+310);
3 M& m3 e4 T4 s" b y! [for(i=0; i<3; i++) //画坐标 high=90,length=2500 o/ \- O& h/ P+ p! j
{
, ]" d: k; M) Z/ Qline(x+100,y+110+100*i,x+350,y+110+100*i);% Q' m/ Y, |4 ^' V4 Y
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);; Y, T ]$ k8 w+ j) e
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
' u$ d1 G" }# z
- C& T) a! h* D* F+ U, R1 s6 [line(x+100,y+110+100*i,x+100,y+20+100*i);2 M9 m: G1 h+ ~3 X+ f1 J" [: h! m \/ i. g
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
$ X" `; i6 T% `+ c4 C# }line(x+100,y+20+100*i,x+100+5,y+20+5+100*i); r8 k p' `7 I" L+ o2 m
for(j=0;j<num-1;j++)5 `# N9 i; S; W5 o% S
{
- g7 W! @: y& |1 hline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
5 F$ j- v+ h$ r- W9 c2 `! Kline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);' g2 @2 T! X- f% ^) G9 S5 J
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
4 o5 o3 B7 c- o! z) a}
# M: Y6 S2 R. D2 X( a4 u}
4 d z; s8 B, X& ^ M- u7 _) C9 V}
9 E/ D# y+ F/ a# E. [else if(FLAG_PF==1)
( K8 p% T) R- ^2 x$ q# b# u7 \{( D0 Q$ x5 ~: l: T9 u3 L7 ?
x=0,y=0;
7 R) r9 h2 v/ U' p* o/ U8 Vfor(i=0; i<num; i++)1 l& T' F ~% x' g* d, C
{& f8 {6 {' Z8 ?. ^6 K/ ^# O
t = (float)info[0];
0 t9 A+ P, Z" b( l7 H% K0 Dtemp = (t/101)*180;7 e! r; H y. I! U. K" t
pos[0][0] = (10-num+i)*50+x+650;. Y9 ^6 V4 J; F0 {4 I2 t
pos[0][1] = y+210-(int)temp;
& W4 a, f5 p1 O+ ~" et = (float)info[1];
, i' w/ z1 f% ^temp = (t/101)*180;% M# ^' y* D3 @# w% H/ X6 v- K+ {" d1 c* q
pos[1][0] = (10-num+i)*50+x+650;" s7 ?3 M$ m+ R/ r* E4 j( d& V
pos[1][1] = y+420-(int)temp;" a+ C/ g0 P4 b/ e% R
t = (float)info[2];5 B& Z2 j! K4 x" z ~
temp = (float)(t/101)*180;
' r- H. u3 M& `, Mpos[2][0] = (10-num+i)*50+x+650;
( i/ v7 m4 y6 _# N1 o/ Tpos[2][1] = y+630-(int)temp;& \9 P# X9 d) ?# D
}4 `$ ?7 l& [/ c
clearrectangle(x,y,x+1200,y+650);
1 c/ h/ P6 ]. @) `' ~; Wsettextstyle(40, 20, _T("楷体"));+ V! x& Q0 e& l9 ~$ @& r, b3 Y
outtextxy(x+50,y+50,"PF");
" q- U$ [. ]3 l" Bouttextxy(x+280,y+20,"CPU"); //画柱状图6 m3 a8 `" A) f0 n
outtextxy(x+285,y+20+200,"IO");
# p5 u, M5 R8 |outtextxy(x+250,y+20+400,"change");
: d' a0 ^! l8 drectangle(x+270,y+65,x+330,y+215);4 F8 E( ~! B* [# t- P, M( l
rectangle(x+270,y+265,x+330,y+415);1 {3 |- p6 g+ H& w9 L! G: x7 j
rectangle(x+270,y+465,x+330,y+615);
. | _/ m2 b1 \/ Q6 Uouttextxy(x+290,y+620,"TT");6 u7 ^3 R) B" n. m- m
t = (float)com;
; L6 w8 l& O3 S3 U. S& C% ftemp=(t/101)*150;
6 r1 ?% j$ l! t; F/ F! |. ufillrectangle(x+270,y+215-(int)temp,x+330,y+215);
" n! A+ N7 e5 s0 Z6 }" b% at = (float)wai;
) M6 k. k S! x8 U4 L' Ttemp=(t/101)*150;
" X1 v" O# f/ @& z2 afillrectangle(x+270,y+415-(int)temp,x+330,y+415);
( m" o- y1 T2 y" a4 rt = (float)cha;$ b+ \ d: C- y# U! k" v
temp=(t/101)*150;8 Y+ F4 c. d9 G) b, j/ ^
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
) v( R$ l5 K. `4 Efor(i=0; i<3; i++) //画坐标 high=90,length=250, @: D( A' S X4 R, ^& u
{) o' A0 P. I! B" h) O( c$ \/ \
line(x+650,y+210+210*i,x+1150,y+210+210*i);0 q6 Q3 t# P; _7 X1 P
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);- J2 \( k( `( F
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);" R+ q# Z7 K! A
' D- l6 D8 M+ O8 vline(x+650,y+210+210*i,x+650,y+20+210*i);
" V$ m1 A [+ X% V' D; Iline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
$ M1 y1 o3 Y0 d* Eline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
7 n/ K, z3 @$ t% w9 C0 E' ?6 I/ @; Wfor(j=0;j<num-1;j++)
* Q. _2 q3 {* F{1 m8 A$ F0 T4 E8 M7 _1 ~( t- N
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
! G3 r1 c+ A; n$ X$ r T6 t+ v- _line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
5 u; _" m) d7 F, U; j6 }9 Lline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
& v) h1 h) v7 q( M2 z) H$ m& M* c}: v0 |) z: N( ?* l# K, `6 z* O; G
}1 L3 Z( l' g2 {5 g
}8 C+ Z8 m6 U) H7 c9 S, F
return 0;( B4 Q$ K( p1 E
}
( h" M7 z: ]) d7 K oint drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha); }& o5 {) H8 E5 O) u
{& z& E1 p: q% p( [' v
static int info[11][3],num=0;% I. s2 r; C1 q# C! F
int i=0,j=0,pos[10][3][2];
" b! h; h8 V: D% _ d2 {6 N; rfloat temp,t;
: g( D' K- m0 G# l/ H l- Hinfo[num][0] = com;% {! ^4 Z, m- k7 D6 n3 F
info[num][1] = wai;6 o/ o" S6 D" I" o$ t7 V& p
info[num++][2] = cha;
, b: t6 { S9 E; C& A$ H. Rif(num>10) //存储10个点4 Y' \' T4 X1 V. A; h( {+ {
{
I% a0 r4 p0 }$ }! `for(i=0 ;i<10;i++)
/ k0 F% R! j: i" ?8 m# u{5 A& a# p" C8 N! L# @# d$ n
info[0] = info[i+1][0];
) Z# N, v6 {/ R M9 P: J: Tinfo[1] = info[i+1][1];
" m& V% z$ M. ninfo[2] = info[i+1][2];
8 _) L6 j0 \3 }4 ?2 F}7 _6 o0 G5 `+ N6 h0 m
num--;
3 c) b" X5 j \' b2 ?! }- z} t2 v6 p! R% @- }% O0 n/ N
if(FLAG_show==0)* z, @ I2 Z9 _" s# z2 C
return 0;
7 s. ]1 C# }( {for(i=0; i<num; i++) d' K7 t0 h& @8 \' [9 H
{, Y( I' R5 [* G
t = (float)info[0];$ B2 y) S% D B) ^8 k4 k, P
temp = (t/101)*90;
8 ~/ B8 [0 E Dpos[0][0] = (10-num+i)*25+x+100;. m, s3 D% B8 k9 f$ o4 J
pos[0][1] = y+110-(int)temp;
! G, ~. ?; `6 t! n6 C: W5 bt = (float)info[1];
8 R6 j3 \+ p( |* Z! d+ |8 ftemp = (t/101)*90;, R( v3 b h2 e0 U
pos[1][0] = (10-num+i)*25+x+100;3 Q" J \! {9 G0 q1 X
pos[1][1] = y+210-(int)temp;
9 ~, q. l/ B O& g3 Q1 w- @* U2 Vt = (float)info[2];
5 [% q2 x4 P1 c( @+ ?6 }5 ktemp = (float)(t/101)*90;
* w( N$ i2 H7 T( D; {$ Bpos[2][0] = (10-num+i)*25+x+100;
$ \$ `0 N1 F7 Z& I, Kpos[2][1] = y+310-(int)temp;
/ l9 D3 k$ n' F c3 @}
: ?( h* s" b- i2 K; kif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)% I% q) [: I/ E' `+ P7 d' q% n
{ 9 u ]6 }5 I! R& k; w( k& Q
clearrectangle(x,y,x+400,y+315);
, F, N% s0 }8 \: rsettextstyle(20, 10, _T("楷体"));
: j) [' u J6 n" orectangle(x,y,x+400,y+325); l2 e; a. D$ o ]* v
outtextxy(x+40,y+10,"CPU"); //画柱状图
0 d- F# A4 r, g4 h; [outtextxy(x+45,y+10+100,"IO");
: r) Q1 S9 b: m$ _$ _outtextxy(x+40-15,y+10+200,"change");
" d, s4 j/ w1 C" qrectangle(x+35,y+30,x+75,y+110);
/ f9 L3 g1 D6 t0 J) S9 @4 f! mrectangle(x+35,y+130,x+75,y+210);
$ V, J) E( \' D0 Frectangle(x+35,y+230,x+75,y+310);
v1 Q% J% k: |outtextxy(x+180,y+310,"SJF");
4 q! J; h* z1 m5 Vt = (float)com;* n! N& ]: |0 }+ ~
temp=(t/101)*80;* O8 r6 d# a: F1 o/ w. L
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
6 s8 M M. Y5 {. i/ @' ]% Y0 @t = (float)wai;9 U3 e- O7 T: q a% c
temp=(t/101)*80;& q, N4 M- W' g9 x
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);" _7 R& C8 l0 B% o" |3 k
t = (float)cha;
4 Y8 G; y( E. P# V ~* M2 Dtemp=(t/101)*80;
# N! P+ J3 H5 q: t4 rfillrectangle(x+35,y+310-(int)temp,x+75,y+310);. N. K1 a) h1 d
for(i=0; i<3; i++) //画坐标 high=90,length=250
4 F( y% _7 W. L9 k{" m% j# b' S5 E: R' W; W
line(x+100,y+110+100*i,x+350,y+110+100*i);7 v9 b1 B5 q( h) v- f/ o e
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);) O j" `6 j& a6 e2 V5 C
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);( [! r2 I3 c+ v1 b. M
) p3 G D# J& D$ S, S( _line(x+100,y+110+100*i,x+100,y+20+100*i);
; k% F- m& M5 |. K" `1 Dline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
' t1 q+ F( ~4 m9 {0 @; w0 Sline(x+100,y+20+100*i,x+100+5,y+20+5+100*i); i& E4 D1 {3 E( s! `
for(j=0;j<num-1;j++)4 }8 S! {6 A0 t- Q+ m3 G4 d
{
: o' O, r6 C8 B. iline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);/ _: i5 d$ ?# m. {) _7 }
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
2 w. P& n; ^2 x! }line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
6 _' _4 } e* {- z}% Y- q0 i8 d& w% m6 R. f/ S
}
5 l4 z" C) @' o0 r: h3 U}% t" s) ]! r+ P) S4 z4 Z8 z
else if(FLAG_SJF==1)6 u" Z2 \- V; P: s7 Q v6 [* u& b
{
& g5 x& [0 l. [- W, ux=0,y=0;
a- i% p% g a5 U6 [9 v( Yfor(i=0; i<num; i++)2 n- V* b) g* K6 Y: p. n8 i
{
( L/ B$ z8 ?" d& }) l$ [: I( ?' ht = (float)info[0];( L6 P1 U: {! Z1 m) q
temp = (t/101)*180;
/ V" z2 y7 U- @" o) t! Opos[0][0] = (10-num+i)*50+x+650;
, T1 L6 @! M/ b9 vpos[0][1] = y+210-(int)temp;
Y; A/ n2 ]) ^- @0 L9 S n0 l, Y+ yt = (float)info[1];3 v7 S8 s9 f, {( A3 j( C& v
temp = (t/101)*180;
d9 L$ G Z6 D+ e; ?3 D* y) M! Mpos[1][0] = (10-num+i)*50+x+650;' T" r, G X" H/ e3 x# d
pos[1][1] = y+420-(int)temp;
& D4 }3 ?; Z; N/ I7 I# X ]' `3 at = (float)info[2];
0 c, e% n) |( U D I" T+ h. Xtemp = (float)(t/101)*180;
- |6 m8 T6 D- ^" Ipos[2][0] = (10-num+i)*50+x+650;
5 i9 W4 q* s: G6 E0 v0 ^pos[2][1] = y+630-(int)temp;0 {) ~9 V- \9 N5 ^2 k
}
4 [! y, ?; W+ e! s& Eclearrectangle(x,y,x+1200,y+650);9 c& R* W0 m6 V3 X' E; D4 k2 H
settextstyle(40, 20, _T("楷体"));
2 D* M/ o! _1 {( }4 e1 \+ zouttextxy(x+50,y+50,"SJF");8 \; P' B" D8 }# {
outtextxy(x+280,y+20,"CPU"); //画柱状图
: Z7 l2 F9 e) louttextxy(x+285,y+20+200,"IO");% G# y7 U6 _7 q, Y0 z
outtextxy(x+250,y+20+400,"change");
+ s) L( Y% I, }6 Vrectangle(x+270,y+65,x+330,y+215);
+ s8 L5 d! B: }( S) y9 Hrectangle(x+270,y+265,x+330,y+415);
( v; E: `! _% z0 d- wrectangle(x+270,y+465,x+330,y+615);
& q6 ]! ~5 |2 m+ C' Y& N3 routtextxy(x+290,y+620,"TT");
! e5 c R3 y& `! M$ Nt = (float)com;
d/ Q. F, j, | Y0 H \( B9 c2 Ytemp=(t/101)*150;3 G3 ]4 F) ^( @
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
! q1 Y( y+ ~) e6 Qt = (float)wai;
, I$ ~3 D& m. @; r- |: e; Jtemp=(t/101)*150;
* k2 b [' V' h) ]$ n2 z+ h7 H4 j0 |$ [: ofillrectangle(x+270,y+415-(int)temp,x+330,y+415);
" I% D. D7 g4 O7 ct = (float)cha;' q! ]4 P. {9 I4 |9 e
temp=(t/101)*150;1 p( o9 v' z; q2 X
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);& X: N }6 P6 M) X- u: b
for(i=0; i<3; i++) //画坐标 high=90,length=250. M& K6 ^, [! }- v$ n9 b
{
5 ?- ~$ C' a1 o! a# \( \* pline(x+650,y+210+210*i,x+1150,y+210+210*i);, T, ]7 I* G2 [. |, s+ v2 g
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
# H9 @3 i* u/ z; vline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);' v5 r3 C9 R2 D
0 t- t& ?" s) \& m, h3 |6 c# o
line(x+650,y+210+210*i,x+650,y+20+210*i);
7 v3 y; \: Z5 ]8 X" i9 Sline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
0 v, X) k/ n; m1 q$ [3 \. F( [line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);. @# y9 y- n0 {; F* k; c
for(j=0;j<num-1;j++)* i+ u( O/ Y" E0 o( \ D- Q
{
, h! P6 k# M: u& \! @( ~$ Aline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
; i7 {% w( r3 w0 t( lline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);6 J: g" v1 Y, I2 x' |
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
& }2 c$ d. C3 a: N}
: P0 B2 A3 X: o% K8 B}
$ o( H! e. Y) b: j( |" b}% F/ ?4 H, t, D/ r5 i. D6 y
return 0;
, @; @- I4 _0 h}1 J/ d, u( C' D4 M% i3 i! \% B# X2 j
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
2 z+ L4 }* B% E! ^( Y8 A2 K{
" k- R+ b$ V9 _2 S G9 Nstatic int compute=0,waitio=0,change=0;
h; _: i" R% S- m5 T# i/ ostatic int computeLast=0,waitioLast=0,changeLast=0;$ H( S( v% _0 v9 ~
int i=0;
U3 {% Y3 F1 R" R. q! mif(draw==1)6 I8 [; w+ W; X6 @" F9 i" A
{
9 p: g( ^0 |0 m//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
$ \9 f% f: } _; z# Z# |7 W& SdrawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
: t# U6 q, j7 I3 e! p' |computeLast=compute;1 N- W0 ?' c1 R D
waitioLast=waitio;
! f7 D# Z1 B ^- H/ }changeLast=change;% b3 I. u5 M0 x6 N7 R- r
}0 u0 h# }+ P @/ n: n1 P2 B+ E2 |3 s2 ~% a
if((* memory).p[0].flag==ready)! l5 u6 z$ ?' e: F. v
(* memory).p[0].flag=computing;
$ w0 I6 `% |2 r! ]3 ^ }if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
4 E& N; s8 o- N: S{. G$ h' ]+ [) q" D/ n& G
i=(*memory).p[0].computeNum;
/ e( Z1 ]/ U9 ?if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
( g$ u* y$ f& |. U) ^" q0 u, Y8 {{% t$ [3 B% n X5 u! C7 w& f
(*memory).p[0].flag=IO_waiting;9 Q0 W& W) x r' V- _/ ?
(*memory).p[0].computeNum--; d* B5 M# M" w9 B5 q- V# a5 n' a; x
change += exchange_IO_Compute;) C5 \) A! h# T3 j( D5 g; J% u- ~3 ~- {
compute++;( k- d3 A6 M3 g
}
* ~, @% M! ?! K0 F( g4 c6 Y telse
$ M8 r& R& Z. u! Q2 X{
3 [3 ]* N5 |8 _" R( W* p! Zcompute++;
6 d1 J; b. Z9 L9 `, l! z}
n, e6 S5 c( s7 \0 `: c}1 L$ V9 d* e/ [4 K6 _: G
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)3 b( Z( X8 z2 p' t0 t0 x
{; C5 _: w8 i/ H {% u
" { n& _1 h4 k$ w }i=(*memory).p[0].ioNum; I. d4 D6 Y# Z, a7 @) S
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
! Z) h5 H* X- O8 @4 K{
0 o7 b9 G) I1 m" `3 B9 L9 x. l(*memory).p[0].flag=computing;# w' ?5 y7 K4 R
(*memory).p[0].ioNum--;
. @% `' Q& }" Dchange += exchange_IO_Compute;
$ p" h1 _0 ~ d. g! Qwaitio++;; B$ h3 R8 d0 s- I: |
}6 ` p1 Z* ]( T9 c9 p+ w( x: v
else# v3 N* G/ Q* w1 |, @& ~9 B
{
& M8 L3 i' T( V7 D1 O' e; Gwaitio++;
: f# m* C n: n' x}; i) n: x# R7 n/ Y, c- X/ A, c
}7 s" f4 Y" \7 e f7 ^
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing), B5 m% j0 f. X3 G% J0 D. g. s
{
1 M Z6 e2 g( W4 }+ ?6 L8 |(* memory).p[0].flag=IO_waiting;1 M5 |& f5 w. l
change += exchange_IO_Compute;
' N4 R3 i7 z9 z- M8 z}2 R _% w X* Y# `4 t+ M
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
0 W$ E7 U5 x I$ X( ]9 s, u{
$ ~3 ?# m! ?6 T L2 F9 y9 A3 X/ d2 F(* memory).p[0].flag=computing;
7 t) t6 P) J! ^change += exchange_IO_Compute;( `1 Y& V$ v7 ~/ t B! q7 k0 d
}
5 t3 S: ?1 }' V) Aif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成, F l1 K; s6 f4 N9 _1 y {1 t: V
{
6 b3 Z- ` _6 i# M( S3 F, M(*save) = (PCI*)malloc(sizeof(PCI));& |2 a `! y" t ?
(*save)->next = NULL;
1 G# U6 @9 C+ @ u# K4 z3 i(*save)->processID = (*memory).p[0].processID;
& a' p8 Q0 u* w: A(*save)->comeingTime = (*memory).p[0].produceTime;
/ O( e8 T6 ]9 C h# I, H3 { ?& n(*save)->askMemory = (*memory).p[0].askMemory;# D; E4 [" w. m
(*save)->compute = compute;
: D5 N) Q- ?* X' N4 ^+ g(*save)->waitio = waitio;+ |, l. H% c8 Q
(*save)->exchange = change;
( Z9 a7 T7 l" G5 G(*save)->completedTime = systemClock;
& z) U5 Y2 z5 `9 b3 a(*save)->runningTime = (*memory).p[0].runningTime;
8 {7 T% Y& w1 Q4 B" M7 l*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;
3 h Q O' ?8 ncompute=waitio=change=0;
/ ]; n9 r$ @& hcomputeLast=waitioLast=changeLast=0; B5 A0 N8 U4 ?& f8 w+ \$ F& R# A) r
High_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1); J0 W$ L: ]5 a3 a
change += exchange_process;9 t8 x6 N1 [. y; ^. X
return task_completed;0 f9 ]7 Y1 T( L6 G5 o" A
}) g0 h. s8 m$ k" ?" h; }
else
! {- w( Y$ p9 ^9 S/ I8 v+ C4 hreturn task_not_completed;* u2 J C' P. R N+ I% ?
}
! S/ b; N8 H# r7 }4 Iint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)* F9 W A& u0 H
{( ?& k3 ?3 d3 o1 z* ?- A4 w/ s
static int waitTime[initProcessNum],i=0,j=0;
; Y! c3 d: M3 X3 n# Hstatic double HR_ratio[initProcessNum];, t+ [% Q1 G6 ?0 Y
if(flag==0) //初始化数组9 S0 j8 U9 v9 {% ]
{
; s, _2 w' G! K1 |. l4 _* Ofor(i=0; i<initProcessNum; i++)# h1 Y5 K4 i2 g
{- E$ b2 |; l1 r- T
waitTime=0;& O4 A+ L+ c" ~% I- ]
HR_ratio=1;
( Z) t7 a: a3 o2 C' J}
% E; a9 F4 N% Y8 G/ W4 o3 p}
, K) ?, t; ^# {. h; zfor(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比 H6 S( D# T2 g- R1 r3 w$ o4 p# Y
{ a) o) p( V' \/ j' U
waitTime++;
: b( c* `6 h) {$ e5 ^ BHR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);
" |& S! U# x5 r, {7 Xif(HR_ratio > HR_ratio[j])! y+ \; A. u' K1 ^
j = i;
5 O" \" p: w B' h' v}- G7 a" A8 }" Z& y: Y- c, ~
if(dispatch==1) //需要调度一个进程到内存中执行2 }8 D' j: T+ c$ C' S
{
, P s3 |5 Q0 Qif((*storage).p[j].askMemory < *spareMemory)$ K* R- J6 D- t/ p' y
{
6 V# ^ E& h2 X; h(*memory).p[0].askMemory = (*storage).p[j].askMemory;
- p2 w% J! v# x8 z) Z, r(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;( Z# K3 i8 y: A1 g$ H, Y9 G! W
(*memory).p[0].computeNum = (*storage).p[j].computeNum;
( M, }$ W6 D! o. f9 B8 c: o5 r(*memory).p[0].ioNum = (*storage).p[j].ioNum;
1 e1 Y) p% _" G4 W* e% C(*memory).p[0].processID = (*storage).p[j].processID;
" e' p( S3 t6 ~, j, f E% {(*memory).p[0].flag = (*storage).p[j].flag;% R$ C$ J$ O1 B" w" J" B1 B
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
: G2 K: D' t: A" H1 ^5 d( k(*memory).p[0].computeTime = (*storage).p[j].computeTime;
2 J8 Q& t2 g/ z(*memory).p[0].runningTime = systemClock;1 P+ o v) ?' X! R
(*memory).p[0].produceTime = (*storage).p[j].produceTime; x/ a0 V# [, [9 Z) l( P* {
for(i=0; i<(*memory).p[0].ioNum; i++)* `; d) ^. `7 S
(*memory).p[0].ioClock = (*storage).p[j].ioClock;2 C& V8 F/ k( e H& u3 a
for(i=0; i<(*memory).p[0].computeNum; i++)+ Z/ V" A) c8 r( r" q
(*memory).p[0].computeClock = (*storage).p[j].computeClock;
; @: `0 @6 f- ?1 \6 h) |(*memory).proNum=1;
' ~& ]. O& {* Y0 c- P*spareMemory = *spareMemory - (*memory).p[j].askMemory;; c7 T8 i+ ^8 ~* u4 ^$ n9 u0 D
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程( g: p3 X* [9 q* p. W
(*storage).p[j].produceTime = systemClock;
4 @6 V i+ I( i. ~* ]MAX_COMING_TIME = (*storage).p[j].comeingTime;* Y% U( y& t# R$ v
waitTime[j] = 0;4 _7 I# f9 q" e4 w; t- a/ S5 n( G
HR_ratio[j] = 1;
7 ?7 ~# P/ z8 r* N}
0 H" N9 n8 {& @6 f6 D2 |+ celse
+ H5 b. }2 _* B& D4 C6 k{
( g! q+ ?/ v2 n R7 O6 z& Jprintf("A process ask for a memory overed the system capacity\n ");
a; C. Q( z4 Z* eexit(1);
9 n5 V1 R5 y4 u}3 r6 K: ]: k: {
}" R/ h9 ]% l- {/ p) O- V
return 0;9 c* f; o6 p1 A8 O
}) a' L- A3 Y* ^! ?3 j6 }7 Z: C- N
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
4 i% G- h" ~8 m9 j{
/ Y' ^0 Q2 i( sstatic int compute=0,waitio=0,change=0;; W, V3 R3 [$ c# i' h3 r3 V
static int computeLast=0,waitioLast=0,changeLast=0;+ L' S5 c' Q+ u" j! f
int i=0;
. W a* k9 ~5 G' Q! D) ?) J, zif(draw==1)
9 D, D0 _, c- p4 e1 [- l{+ s4 L3 }. Y" A
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast); K+ Y8 a4 ?4 [$ t4 T
drawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
% ?/ N" a/ d" K( O Z+ m% y$ }# b4 L: {8 a1 c
8 |' `4 [0 T! y. j' p
computeLast=compute;% G* n ], V& I1 {! H% _
waitioLast=waitio;- b# L. @, D0 Q" A
changeLast=change;
8 x! [6 n8 u+ {# z}' M3 P8 ~# l- B8 K* N& }
if((* memory).p[0].flag==ready)
) L9 \/ x; G+ K5 y5 P3 W* H(* memory).p[0].flag=computing;$ `/ h- D: g6 D
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
! T I& u, |+ d$ e{( ]! f% X* B4 o* F$ d
i=(*memory).p[0].computeNum;
$ t- j5 m) \8 f1 g1 Fif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed- F/ i9 w# u- K
{
: y# k N) }5 L. W(*memory).p[0].flag=IO_waiting;
$ Q8 G$ R% M5 E0 h(*memory).p[0].computeNum--;: C6 s# `( C) n- l' T
change += exchange_IO_Compute;& O* D1 A. @6 v) x4 q. Y& ]
compute++;
3 q# Z( H9 [8 B5 C}
8 `! r' I) t% kelse
) H2 U0 T7 _5 P{% C3 n. \# K2 ]7 w. m
compute++;
6 b! m6 r8 a4 b0 r4 m}
0 q3 `$ L2 A+ K3 x}- Y8 K# i+ d* n/ Z! s8 \
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting): i- b2 \, r% |$ A8 D& c y
{
|. m; C' X% l( i7 @, O2 D5 |1 I* X. i, i
i=(*memory).p[0].ioNum;
6 O3 T- z; U! S; I' mif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
" k* X c# q8 ]) q% e" u u! q% t{
2 b! |- I$ f2 U/ _* d: S(*memory).p[0].flag=computing;
& ?0 Z: J/ X L4 B4 w(*memory).p[0].ioNum--;% R/ R S j+ q
change += exchange_IO_Compute;
3 E& u s9 ^ Q5 t0 w4 a% Z2 `waitio++;2 d: k' g/ z' e5 d+ O5 Z5 w
}, k$ J1 D$ q- v L1 }
else
3 T' p3 {7 E! z% V{+ U) L( [. y0 Q$ K6 H
waitio++;1 F" R. S& [: q ] P* n& H' k
}
% F7 S, O b/ s}
, ]/ _, m8 v3 f4 H2 B: |6 p3 P- g9 Celse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
& m) D- h: B0 A{
' ~0 G1 k9 y) m/ O5 ~/ n(* memory).p[0].flag=IO_waiting;
1 |5 |3 Y; V. s) W$ }1 b% e/ O" vchange += exchange_IO_Compute;5 L- G! H1 V7 R4 X* s/ v/ F5 N0 H4 P
}
! e5 {/ s: _- ?, k6 t) R3 z( Ielse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)6 S2 h3 V- B" a" W- w) u- J
{. }2 }# j: t) g# p, O, T
(* memory).p[0].flag=computing;
( h0 G1 C& c' l5 Schange += exchange_IO_Compute;% w9 k. \# o" P; y' F( e
} i' `) _( J6 x% b7 k: b4 c! C
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
7 f( H& z4 x: x* K0 x- U& y{+ {9 I! i' `* a1 O/ n( ?2 z
(*save) = (PCI*)malloc(sizeof(PCI));& Y4 T4 b S7 p6 K. v; q
(*save)->next = NULL;, W" U0 A( K Q) h7 M
(*save)->processID = (*memory).p[0].processID;' _+ D7 u6 o' T6 x
(*save)->comeingTime = (*memory).p[0].produceTime;
, |) `4 o: ~6 ~2 y Z( }(*save)->askMemory = (*memory).p[0].askMemory;
# U. W$ Q( A: S(*save)->compute = compute;
4 G4 z, Z5 F; `! X" s- Z) B(*save)->waitio = waitio;
; G, \) M$ U0 J# p3 F- c. U(*save)->exchange = change;1 |: d' m/ V' j) M1 f
(*save)->completedTime = systemClock;3 l( a7 P' _6 d( R
(*save)->runningTime = (*memory).p[0].runningTime;4 z4 w1 l/ z1 e8 h/ F
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;- C% N, Q* n z0 H. Z' @& Q- |! x
compute=waitio=change=0;
& |. I( W1 h; v9 U1 qcomputeLast=waitioLast=changeLast=0;/ N0 Z3 P9 u# _- N: |
Priority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
+ @+ e: E' n8 w. d' x" z7 wchange += exchange_process;5 e3 G! j1 Q# }- F! }
return task_completed;/ b. h, n% F `
}/ [" [; [$ s M% p# |
else
d: V$ z$ K D2 E& a' Ereturn task_not_completed;$ j& w/ `% y# K- Y! Z
}
) @4 p+ M ?% Y' zint Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
" F0 n2 l- D9 Y$ a4 ]{# B# F" L+ a8 Z! Q) k
int priorityNum[initProcessNum],i=0,j=0;( ]; s: l, v. T- r! b" I+ Y
double temp=0;
& W. V8 F! N9 x, }6 v. c( r, rfor(i=0; i<(*storage).proNum; i++) // setting priority to each process
: n& q% C0 i0 L- C" i{- w- j, f% Z0 C) T8 R
temp = (*storage).p.computeTime/(*storage).p.ioTime;% d* v R2 Q/ y- n* Z. o
if(temp > 0.8) z" ~) x/ K* V0 X
priorityNum = 6;9 A/ d+ {! T# m/ V6 u
else if(temp > 0.7)# i) K$ y1 X) H5 L' A$ ?5 K
priorityNum = 5;7 q: G6 y A! v+ M, h
else if(temp > 0.6)& l* b1 Z9 t2 V8 ]- C, S6 ]4 u, a
priorityNum = 4;
& `9 O: C5 t1 M0 i+ Z: Z2 K( Oelse if(temp > 0.5) u z* c% b, K' Z5 D: |. `
priorityNum = 3;3 q7 P2 c* ^/ m& G. e, y$ J V+ E9 N
else if(temp > 0.4). @' X V9 R/ H0 ?! `) r
priorityNum = 2;
* j4 Z" T% R6 y+ _6 T$ _ p" Yelse2 g$ K( }# F+ a0 k% d0 l1 x+ _
priorityNum = 1;6 k2 E5 X. ]3 L* l& ~$ ~2 b; r
if(priorityNum[j] < priorityNum); C/ d0 g6 l4 P; H- O- _
j = i;
* `/ E& L% Q2 T# ~! y}
& ?- Y1 w: c. o2 h' | t5 J1 Bif((*storage).p[j].askMemory < *spareMemory)
1 [5 p+ T/ Z! K6 b. `{! _ B: P+ \) p9 s$ [* S$ D& m* B% Q
(*memory).p[0].askMemory = (*storage).p[j].askMemory;: X9 A) U8 @) a# K, g% O
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
# _& j3 ~2 q( f/ j- b3 C* o(*memory).p[0].computeNum = (*storage).p[j].computeNum;# O# f: f; R# H8 {' |" C* q% E
(*memory).p[0].ioNum = (*storage).p[j].ioNum;
/ j" G9 m& W7 z# u7 X(*memory).p[0].processID = (*storage).p[j].processID;2 N. o8 c W/ H. V% r5 l3 J
(*memory).p[0].flag = (*storage).p[j].flag;$ C- |8 D# X& C0 W
(*memory).p[0].ioTime = (*storage).p[j].ioTime;( G. `/ n+ ?5 @( `# n4 Y5 f
(*memory).p[0].computeTime = (*storage).p[j].computeTime;) r4 C& A7 }8 H- k. k9 M! F
(*memory).p[0].runningTime = systemClock;
3 f, W, w' h, P4 N(*memory).p[0].produceTime = (*storage).p[j].produceTime;! i5 G+ i/ o0 R& n3 X
for(i=0; i<(*memory).p[0].ioNum; i++)
. d- b+ C6 \6 Y(*memory).p[0].ioClock = (*storage).p[j].ioClock;& F3 Q* R$ ?2 P, L& c
for(i=0; i<(*memory).p[0].computeNum; i++)! i! w, j+ f# I( h0 D7 J
(*memory).p[0].computeClock = (*storage).p[j].computeClock;3 ^; A4 h0 F9 g- t1 B
(*memory).proNum=1;/ z7 K9 T: v, C [& S, i
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
1 }* }0 G$ t* d7 d( W3 Aproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程% M% {1 J: E/ W4 f8 N2 S
MAX_COMING_TIME = (*storage).p[j].comeingTime;' {0 M2 p* R5 B2 ]# J! i0 n: R
}5 ]- S) l$ N' _9 I/ y( ?/ R4 Z! N# N
else
5 _2 J5 C, T0 g U: c{6 A6 S4 }2 q/ Q7 `8 [; i: V
printf("A process ask for a memory overed the system capacity\n ");, r b5 J6 h. S3 i S- [, V
exit(1);2 a$ h; r- | N. i; Y
}4 e+ m+ b$ m5 l; S
return 0;
* i. @) G! I4 M# V, R4 f' k: e}" V% S5 ~/ Q+ k5 a% S) b
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
: y0 C9 g' H, d0 L, l{
0 s; ]5 z9 g, V" G9 Qstatic int compute=0,waitio=0,change=0;
* G8 P; E5 ]1 z f. X% v6 ^- Astatic int computeLast=0,waitioLast=0,changeLast=0;
7 {5 p( S+ {) k* S2 l8 B, [7 hint i=0;) `& ~& ?. c" |: l
if(draw==1)! F! P( D4 u9 R% z. d) i$ r' F8 l
{" Y8 @ m' k3 _6 e7 Y
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
1 q5 G* V* r2 P, }1 Z* Q( YdrawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
7 R7 `& c6 y8 A2 |- O* Z! o- M3 x2 G2 b) {
) G/ T& p# w$ A
computeLast=compute;' A0 o1 [* y1 D, q0 m4 ], |" O: y
waitioLast=waitio;
) J4 \: L/ e+ I; k1 f2 JchangeLast=change;
6 l3 q' G* ?5 }' v+ v! K; ?}- s2 D, t* A7 D5 A
if((* memory).p[0].flag==ready): C) k% G5 Y# i+ }
(* memory).p[0].flag=computing;: }3 r) v0 P4 e: A2 {2 Z
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing). q5 E. N* J o2 \* h
{
$ b' {( r$ t) T, p% m9 i/ Ei=(*memory).p[0].computeNum;; ?4 G# v ]3 j [2 [# t, u
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
" i% Y% H( K2 W4 D- c{+ u M3 g: F; `' W! _
(*memory).p[0].flag=IO_waiting;, B+ s8 h4 j7 ^7 c
(*memory).p[0].computeNum--;% q x: E" P6 ?% Q
change += exchange_IO_Compute;. ^! P7 c# y* a- h7 b+ r
compute++;: U% T# s% f- o8 B) b& }1 _# U3 D7 l
}
5 W! X$ c+ K$ w9 A& {7 B; b6 `0 Pelse" w" K% a" N& _& [; O0 c# O
{% L7 c/ U7 ^* Z; J0 |
compute++;% h% U7 U9 E) K1 c* k! i8 R# }
}+ c L+ s8 A- ^9 v+ u: {. _9 p S8 |
}3 D1 H# M) E9 I u1 M+ T5 k8 E
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)! [8 |4 n* e6 N* z$ ^, y3 ]4 I! `
{+ {3 `) y' [# x$ f* H9 J/ C
5 ]+ n5 N% r/ H# N) ui=(*memory).p[0].ioNum;
. {+ T/ m3 r6 E# Mif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
/ {( P6 N r% k{
$ X7 A4 a& G; g7 I+ \3 v9 Q8 ?(*memory).p[0].flag=computing;6 F8 ?/ ]4 Y2 i% J+ S) Y- X
(*memory).p[0].ioNum--;9 [7 [ _2 [+ p& M+ N# @, `' ~3 b
change += exchange_IO_Compute;7 O* p# C1 o& b! q! r% |
waitio++;" R( `6 P S& E7 M/ E4 l
}1 h! T, v" I6 m/ T1 z; O
else
4 v. I) H; N1 @3 S+ W8 Z. \' R* {{% e- P# v! B {; e
waitio++;
& I/ u* I8 Z6 `+ t- R; \3 _! h}9 p' e# t1 B/ d1 O8 W& x- w
} ^( Z* r7 M3 \8 T* x
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
( A% X, w* B: Y+ a; j& f+ l{5 Z; v; M- u8 E2 c" Z0 Y3 m
(* memory).p[0].flag=IO_waiting;! |$ _! z& F$ `3 M. p0 u# S
change += exchange_IO_Compute;
/ n4 P4 x% l7 {3 ]2 A, r+ y/ X}
+ y1 `5 C/ U2 n! [ K$ m# @else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)3 L; U* L8 t* [$ |" d! L2 D
{
, z, p" e6 R, h(* memory).p[0].flag=computing;
Z0 b: Y+ S7 j7 H; nchange += exchange_IO_Compute;; v7 x( ]. `# l# i% X
}; o) L0 W) V0 H) P1 p# f
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
2 X9 i" m- s6 a9 c) ?. g' E{
3 |9 d! k% y: Q- R$ Z9 t0 m(*save) = (PCI*)malloc(sizeof(PCI));9 A2 s0 J' Z- d/ J3 c+ X
(*save)->next = NULL;8 g5 z$ H& J c \8 Y" `1 L
(*save)->processID = (*memory).p[0].processID;) w' g' \, B6 Q) M- [
(*save)->comeingTime = (*memory).p[0].produceTime;% `& j! j$ V- F" X; P
(*save)->askMemory = (*memory).p[0].askMemory;
2 e4 U' P) `5 {( N+ v(*save)->compute = compute;/ A( d) m$ D+ d3 h9 c
(*save)->waitio = waitio;4 s! w- w$ `, _% c
(*save)->exchange = change;: O& z- }% g$ m; b
(*save)->completedTime = systemClock;: @) i( f' q$ d% M
(*save)->runningTime = (*memory).p[0].runningTime;( p" D$ H3 R, D y- d, A" Z1 z3 T5 l6 ]
*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;
) v- o) }4 ?& Rcompute=waitio=change=0;" k8 p3 `: V- V) H8 ?7 A
computeLast=waitioLast=changeLast=0;
* R5 P. f3 M( _( fSJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
w/ s7 c4 R4 @; D; H+ L/ q% dchange += exchange_process;
7 { g6 m( y7 U- M( Y5 e$ ^! { dreturn task_completed; ^7 k1 g/ i. P- e8 V2 J
}
! h3 V% L* z' qelse9 y7 c* y! S3 t
return task_not_completed;# q. |/ T$ S$ U$ d( C4 [
}
. g* z" Y' y8 N# p, y5 v4 ~int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)4 \7 T/ R9 e' g2 \( k" ^: H5 D$ V
{
" O8 S) k; K% p/ _: O: @; {int i=0,j=0; A. s% A% {+ ~0 e
for(i=1; i<(*storage).proNum; i++)4 v8 G4 s6 W% K3 l6 I1 \$ Z/ b
{) ?/ S9 G3 {2 g6 S& T- m# b
if(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))
4 j/ Y9 n2 C' X) Mj=i;# a# _2 ]- R" v7 O2 O, x9 C5 p0 G4 y
}% c* m$ ~4 c: |+ ^$ ]. n. t
if((*storage).p[j].askMemory > *spareMemory)" h) s! b5 u0 Y& j& i3 Y" e
{
0 ?; W% V3 K6 @8 k1 U# pprintf("The memory asked is overflowed than the system memory.\n");6 p% ^4 N1 M7 F
exit(0);3 f* E4 W" a4 Q2 W7 \. d% S/ C; A/ z1 O
}# l; E6 \# s& q+ u* a
else
. V, m2 c5 n f, X* i{
1 x' a0 {9 V% M0 U9 B9 e(*memory).p[0].askMemory = (*storage).p[j].askMemory;
$ O' ~1 d+ _- b. B3 E(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;- \! [& S% l+ e5 U
(*memory).p[0].computeNum = (*storage).p[j].computeNum;
/ O! H. Y l! A9 {0 Q! D& `3 f$ r(*memory).p[0].ioNum = (*storage).p[j].ioNum;
& D$ B* L! u- M3 i0 v0 w(*memory).p[0].processID = (*storage).p[j].processID;
" r- B7 Z4 m9 o, ~5 ~2 F' U(*memory).p[0].flag = (*storage).p[j].flag;
, g: V+ F$ F2 Q3 j) V6 n4 |1 D(*memory).p[0].ioTime = (*storage).p[j].ioTime;2 x/ k/ p E; }, F
(*memory).p[0].computeTime = (*storage).p[j].computeTime;
; h# X" B2 T6 b; f6 V& V" S3 I(*memory).p[0].runningTime = systemClock;
1 y v) }( V! @1 G8 Y(*memory).p[0].produceTime = (*storage).p[j].produceTime; u3 K, q k0 E$ s
for(i=0; i<(*memory).p[0].ioNum; i++)2 N" S9 s" Z- o2 _' e6 v1 u
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
4 c8 m- N# d' V5 Sfor(i=0; i<(*memory).p[0].computeNum; i++)* p% ?/ }! J) \ T, z; X
(*memory).p[0].computeClock = (*storage).p[j].computeClock;
6 h2 w% D1 e6 h+ G& g5 ^0 }(*memory).proNum=1;
9 h8 R2 w+ A$ f8 [- g*spareMemory = *spareMemory - (*memory).p[j].askMemory;& D! v/ G/ m7 B/ W
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程( u/ G9 q" c( m6 O. G" m
MAX_COMING_TIME = (*storage).p[j].comeingTime;
" |% z8 ?) x1 l8 h}3 u0 `5 m+ j6 u" u/ o" d
return 0;
3 N# Y. l1 @/ e( g}
& ~8 S. C% U' o+ Cint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)6 i9 g% F! x5 k
{0 L% C0 \3 r1 R, ~
static int compute=0,waitio=0,change=0,clockSegment=100,poi=0;
+ a5 F8 H+ r. n, t" L6 i+ d+ b% A$ Jstatic int computeLast=0,waitioLast=0,changeLast=0;/ Z- I* H) g: j/ u4 q/ q
int i=0,j=0,k=0;3 M8 E, [3 `6 E1 J- u$ V0 h
if((*memory).proNum<=0)
, {* H7 c9 `- O" a* |TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);: r* X: h5 N0 D9 i
if(draw==1)% }7 H3 U$ D+ z, R7 y
{
: W' n3 T: v) B& r# Y6 x( k//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);, \2 v" x( n; X( }$ y! V# r7 L% Q
drawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
8 G- f6 I- t" S! A% @0 U7 w b( h+ U$ q2 P
' N1 D; k6 I5 Z0 IcomputeLast=compute;, {1 |( X2 ~- Z E
waitioLast=waitio;
4 Q8 U+ W$ e9 |4 H$ D4 w2 V2 hchangeLast=change;1 a, n# m1 l |% R) f
}
. D, t; E3 B6 T$ f: w. j1 a' o3 Vif(poi>=(* memory).proNum)& N$ z; N, U0 O) K' E5 z/ z6 E
poi = 0;
/ R+ u3 S, k. Nif((* memory).p[poi].flag==ready)* J, N- p, ]* C
(* memory).p[poi].flag=computing;/ [, o+ O. ?, {. c
if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)
6 m, _7 G8 ]9 z' b{. h& d9 Y. y3 Y8 s
i=(*memory).p[poi].computeNum;# A0 `7 n0 r' k0 b" t
if(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed6 g( L6 C/ m8 [3 W* A
{
* I$ P% Z$ ?# U2 J, W; n(*memory).p[poi].flag=IO_waiting;: k* [+ P. T& f- a p
(*memory).p[poi].computeNum--;
X D ^2 v' L6 ]change += exchange_IO_Compute;
* J. P3 ?6 v# E7 X0 L: W4 fcompute++;
. g1 I5 f) t1 }: O+ m7 |}% E2 M4 m' F: f
else
5 O* l2 F2 Q% E1 T e, Z, _3 V{
7 p2 w% P) X; u2 m" h1 L4 j- k0 F! Ocompute++;
3 A' g1 A8 d6 @5 P+ q; M2 }$ O}
6 {9 _- P! g+ G2 ? q0 I, O8 ~1 [2 A- h}
* G9 P2 x! F! p$ Oelse if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)' Z6 h6 m/ \5 g. x4 l: b
{ g) Y l" w( w/ a
8 T( @3 W5 r7 @3 L
i=(*memory).p[poi].ioNum;
3 T; Q3 c k5 Y; K' lif(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
! T/ s! i' g. G* @! ?- m7 w) P4 {{* J2 W& M% f& n7 i8 k4 N
(*memory).p[poi].flag=computing;0 r( Y) I5 w, U t1 x
(*memory).p[poi].ioNum--;5 x0 m- } q7 u
change += exchange_IO_Compute;/ t: r z$ b- p& {+ u: i
waitio++; r- a* b0 b! O& G3 d2 B/ L3 f
}0 H0 N& Q9 I" v
else) i' t3 l" D! X
{
( P/ O. X: c+ O' J4 x5 N' P& [waitio++;
' }3 R9 t- k4 H" P9 J}6 H/ n- ~, {& ^. A$ i
}
o$ Z4 v6 h7 S4 i) lelse if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing)5 [5 Y l0 p3 k2 F! ~
{
" C) i { l; e% n; i/ V' Z(* memory).p[poi].flag=IO_waiting;
8 E" R7 U8 @7 j; Jchange += exchange_IO_Compute;$ D- o6 i. q" M8 Q/ ^+ [* D
}6 ]- t$ R: |! z* l, H5 z
else if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)
8 f: T$ ?: A, D5 T{; H A% p- |' E0 V
(* memory).p[poi].flag=computing;2 S) V& C8 l) T* c' R. }" x
change += exchange_IO_Compute;' K: {5 B+ ^! K6 e( m, _( p' {
}
( @0 c ^: U* J3 Z! efor(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进! s5 a7 b' I% Q ~
{
" j4 h% V k& x# _if(i!=poi && (*memory).p.flag==IO_waiting)
3 C- V6 L' ^: L{
. O* `3 Q9 ?, q) j9 e+ I4 ]j=(*memory).p.ioNum;5 O% P% \! y& _. C5 i* R0 P+ P
if(j>0)
3 g9 b, D' f2 H0 ]- W% `2 M3 z{5 c5 h" {) \7 Q. _
if(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed! |" G" ] I& U
{
( q' v w, b, f# D+ u(*memory).p.flag=computing;! ]8 r3 e- V) t$ k& D: `2 f
(*memory).p.ioNum--;) P" @& z2 g+ a; ]
change += exchange_IO_Compute;* j' Q1 y& K! F- X8 o' g% ^
}
4 _6 w' ^) _9 F$ d}
& d l. w' Q8 N s}- b/ a/ ~5 R. ~! \! c5 U
}
9 b; S; `+ R$ }: a" X1 `& e8 N) qfor(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程1 w3 W% G4 b; u& [/ K
{
% n7 c" `. A# V1 f* E4 Zif((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed+ ]. q- X5 |; {5 T
{
( h& _) s& r3 k& g(*save) = (PCI*)malloc(sizeof(PCI));- S. p8 f3 g) j# R9 g, i1 k
(*save)->next = NULL;
5 c H! E/ ?% n4 k4 b (*save)->processID = (*memory).p.processID;
1 w# a& E, \/ U4 q9 B(*save)->comeingTime = (*memory).p.produceTime;0 P* \. t q* p0 f
(*save)->askMemory = (*memory).p.askMemory;
! ^# K* E% O! V. d' E3 K. {(*save)->compute = compute;
7 }) o; J' z0 E% S* u9 q. p6 `3 {6 j(*save)->waitio = waitio;, C4 v& @$ O- r- [2 [+ _0 r6 F
(*save)->exchange = change;4 R% w, q" T2 P/ }' R+ V
(*save)->completedTime = systemClock-(*save)->comeingTime;
0 A% A3 _. n- A( c: u; K(*save)->runningTime = (*memory).p.runningTime;
+ M* F0 J- n$ ]- M, q(*save)->completedTime = systemClock;2 o2 T3 z+ C3 O+ A7 ^
*spareMemory = *spareMemory + (*memory).p.askMemory;
' b9 ^5 ]8 w: o5 S/ Y# A9 fcompute=waitio=change=0;6 z( _4 E) [1 S. J
computeLast=waitioLast=changeLast=0;0 B; g% j' [2 t) K1 f
if(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入5 B5 n' u2 v3 R+ P( I0 t+ a E
{
( w1 t# j- U& a d: o# t8 Cif(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程
" U: P# g5 g7 X. O0 h; p, s{
# ]0 d# n3 u ?; e4 ? Ppoi++;
0 e! T' p u; m! Q9 z% m! }! f8 D clockSegment=2000;
# ~5 o0 ?9 ]9 ^, r: z}5 E* u% t# l7 p# |+ @ y3 Y0 n
}$ q5 G P0 K l9 ~0 I( J
else //没有足够内存调入新进程
% ~! ~& b, j& z; y5 u" Y8 [{" w; S5 y7 V- m
if(i < (*memory).proNum-1)1 k7 w- x/ k6 Q% F
{
5 R4 x( G0 M5 ]' _; |$ U) U4 m: R/ ?4 {for(j=i; j+1<(*memory).proNum; j++)
# b* z0 Y5 r/ I8 S9 p$ T( i- [* K( ~1 _{
/ ` T4 G7 n. j: V: ~0 g% G! A. I(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;$ f9 H' O" G2 e) o
(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;
. J% [; Z$ u' r" T7 `(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;" M/ t- G, g& y- U
(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;$ A3 C& d8 V8 {! P: t
(*memory).p[j].processID = (*memory).p[j+1].processID;
( Q. D( b: X0 G2 u5 y$ ]7 c7 @(*memory).p[j].flag = (*memory).p[j+1].flag;
$ p& F7 M# U, S# L0 ?# D3 \* h y2 t(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;
- j# w1 _% v: \; x(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;4 T8 V+ g5 @* D5 \' @3 X0 f
(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;" \, {; M2 l9 B2 ~) n1 f8 R! K
(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;
$ @7 H/ A, D! @% ^/ D(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;3 m; i/ u% d! J
for(k=0; k<(*memory).p[j].computeNum; k++)
% E; y2 ^4 [, l4 L(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];
: y! z# R$ w' T$ ]9 r9 efor(k=0; k<(*memory).p[j].ioNum; k++)( I W6 u- ?. L# R E2 h1 ?/ ^) q6 F
(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];
2 v5 H; G8 D$ g: O; @}
r- b! z; t. E9 c% M. Oif(i<poi)
+ r1 ^5 _" A7 c7 \poi--;' H9 q6 o _% z5 ] O; n5 W9 P/ X' `
else if(i==poi)
7 f% B W: y9 w5 }clockSegment=2000;
; R; r# \4 o+ _% s% t$ B}
8 ^7 c0 f7 {/ t3 Oi--;
7 ~ t" [! S$ q% B- _8 \(*memory).proNum--;
/ R+ R) q6 o* V' }% r5 _}
K6 S* z% T% w( C$ I) _return task_completed;
! @) }6 x; i. l% ^' g}
/ ` J' _; M% C7 D# {}9 X6 M; s8 Q* I4 B/ E6 L. U
--clockSegment;
! e4 F$ B: Z |) I$ A- b4 v j/ Wif(clockSegment<=0)
, a9 V. l+ [2 |. n{# @8 \8 X) q# f# |4 L: e7 t$ V
poi=poi+1;9 M' D P; H& H" J/ n0 J
if(poi>=(*memory).proNum)1 b) r2 C5 K) \
poi=0;
% x4 i9 Z2 ]/ E$ P& g& V2 jclockSegment=100;
d, U' y) o4 b: Y}
( l# R! g0 `" c- i$ K3 oreturn task_not_completed;
$ |. F! R5 z* K* W; Z}9 X/ X" J Q6 `$ j
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos), k4 J0 l" A. Z6 B
{3 G( l5 k" `5 d/ G3 y
int i=0,j=0,k=0,flag=0,translation=0;
p/ C6 Q* C4 z( dfor(i=0; i<(*storage).proNum; i++)2 e( ]/ {; O& N+ y2 m0 F
{
1 Q. Y) R4 D; k" y& V& ]% E: ^if((*storage).p.comeingTime>MAX_COMING_TIME)% ~' W' ~1 \8 g3 F9 X" U
MAX_COMING_TIME = (*storage).p.comeingTime;2 D7 @/ Q; s5 ^8 j. L
}
. C8 T! X% e* _3 S4 P' X) @if(pos>=0)
s9 ~/ n8 ~" q% U{" x# I z$ F* |; Y$ [* e$ ~$ x
for(i=0; i<(*storage).proNum; i++)
6 E* ^+ E! {! q2 b( n9 _( D{ u9 F1 Z* p* t; A
if((*storage).p.askMemory <= *spareMemory)
- L- Q& J4 R4 l2 R2 x( S# g{
1 ^8 _ K6 s' ~j=pos;
1 m( T. Z; N/ |! m(*memory).p[j].askMemory = (*storage).p.askMemory;
9 z7 R! ]7 F5 u/ m" R% \. A% p' F) _% d(*memory).p[j].comeingTime = (*storage).p.comeingTime;
6 D8 u/ C; _: f+ h. ^/ u- a(*memory).p[j].computeNum = (*storage).p.computeNum;
3 A6 T" Q4 G O& \/ l5 ?(*memory).p[j].ioNum = (*storage).p.ioNum;& [1 m9 L- O. O/ m+ y
(*memory).p[j].processID = (*storage).p.processID;
* M+ F" I2 F3 ^) S- ?- s(*memory).p[j].flag = (*storage).p.flag;
! R) s, p( I( k/ w" C(*memory).p[j].ioTime = (*storage).p.ioTime;
u7 K; d5 q2 ?6 h- u/ j(*memory).p[j].computeTime = (*storage).p.computeTime;
; l) o3 C" J+ `# ]) _" u' ^(*memory).p[j].runningTime = systemClock;% U H# }7 ?$ i+ u& y' u! ?
(*memory).p[j].produceTime = (*storage).p.produceTime;
) S# ?* f, ] g0 N' e+ }/ `# vfor(k=0; k<(*memory).p[j].ioNum; k++)
' [, G6 |. g, |6 G(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
, \9 r; I2 Z2 ifor(k=0; k<(*memory).p[j].computeNum; k++)
" F' c+ P7 d, \. h. k) J1 \(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
) @+ S7 c2 m! ?- [$ k*spareMemory = *spareMemory - (*memory).p[j].askMemory;- j9 n1 x+ B: y# _
produce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程& w0 p7 U: C% d$ |' x* {
MAX_COMING_TIME = (*storage).p.comeingTime;
! U$ S, I9 `( P5 jtranslation=1;
$ f3 n& D8 i, R+ xbreak;, N% n2 J& D3 m& u2 v. E* ]
}
$ G0 \) \# A7 v% G+ t% u% L+ J& n! f}
/ D0 x- B9 P- C, S: `/ n: ]}
' H L4 U$ p2 s: gelse+ O& u b9 V* B9 c+ y/ N
{. a6 O" s3 K3 d* Y6 Z+ L
while(1)3 O; O5 I! x; N1 x# j6 t
{! v; Q* H0 p4 f* F! M
flag=0;# f6 d! I9 z9 F' Z# J/ Z
for(i=0; i<(*storage).proNum; i++)( n& j" X) p7 e X. O* n
{
; G7 {" M% z6 t5 v8 z9 Z, C$ Xif((*storage).p.askMemory <= *spareMemory): `: S2 [/ t3 F
{
; q" m7 E: P/ j7 E; qj=(*memory).proNum;$ I' t r: j+ V; {$ D) F2 \
(*memory).p[j].askMemory = (*storage).p.askMemory;
3 e' h. u ]( @(*memory).p[j].comeingTime = (*storage).p.comeingTime;
2 S/ g1 J' E8 ?(*memory).p[j].computeNum = (*storage).p.computeNum;
. ^+ A! C6 M- }* f2 W+ ^) {(*memory).p[j].ioNum = (*storage).p.ioNum;
: |% P9 x4 s8 ` R(*memory).p[j].processID = (*storage).p.processID;( y. o* E% F! x& g( A: }
(*memory).p[j].flag = (*storage).p.flag;
) T2 `) R0 U( ]& _3 ]; H$ {(*memory).p[j].ioTime = (*storage).p.ioTime;
* m; b2 F2 q2 x6 r8 x2 ?(*memory).p[j].computeTime = (*storage).p.computeTime;; [+ l* l( U. h) s! n
(*memory).p[j].runningTime = systemClock;
' T/ u) w6 B8 `' a( M6 H9 c) l(*memory).p[j].produceTime = (*storage).p.produceTime;4 y& |$ b& D7 Y4 E% j
for(k=0; k<(*memory).p[j].ioNum; k++)
" J. R# A' H7 q(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
9 h L9 i# x+ t0 t; j* afor(k=0; k<(*memory).p[j].computeNum; k++)
3 S/ y: t7 S: Y6 l* C! q(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
4 ]" X5 s" `2 l+ \(*memory).proNum++;
6 E3 ~. [% `. \' E J% |" R" N1 T9 y* F# l*spareMemory = *spareMemory - (*memory).p[j].askMemory;! B' l3 V) k% V. ?& ]- U3 S/ \
produce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程2 M* N7 F% @. b; D7 o
MAX_COMING_TIME = (*storage).p.comeingTime;
x" p4 z) I' N7 d& S" F6 f0 P+ _% Q! @flag=1;
8 ~5 Q2 m2 Q5 k: K- ?! |# M# E9 A& Etranslation=1;
) ?$ W6 H3 Y" [7 J& d) E2 q}
4 W% i h" f1 a d/ f}
8 P7 e: Q6 N+ d* ~, X5 U! nif(flag == 0)9 p! K# L. I6 f; C4 {. P; I! o
break;
* D+ S+ e0 Z [}9 z+ h+ z1 z" x- N5 J
}
( d( w( X7 s/ O# J! greturn translation;! m& Z% H4 j6 P' g2 I
}
+ y/ L+ z& ^6 I( e, Mint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)6 d' M! O6 A: u% I- E/ D/ a2 O
{
2 y# {5 O/ r; Y2 P7 L2 G0 xstatic int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;$ a$ P1 j) r3 L5 |
static int computeLast=0,waitioLast=0,changeLast=0;
- B; O, R( s% ^8 }$ c8 |" o% Yint i=0;# J% |. n9 e' ~2 e5 s# J
if(draw==1)
# Q1 g }' }/ V2 S: T) q{# P- D# H. v( [9 G- y: ^
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
. O2 V' w" \5 | J+ ?$ ~drawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);- c. b" H# t1 |$ P4 B. r" e- d- [
: P+ U9 y' ?2 K/ s" g
2 _5 z Y$ Y2 C: h mcomputeLast=compute;
& f: u) I- P" @6 {+ j0 t2 EwaitioLast=waitio;
$ t3 G; `# a, p; @/ s0 j$ wchangeLast=change;
0 N7 v: V$ v/ V% }7 H}. K ~# b6 r1 x0 u, n8 D, _
if(flag==1) 8 V9 U( m7 `8 B Z
{
- C" B! B/ d/ p1 c L3 p$ wif((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed
. ?5 j2 |3 m! Y" i3 V& P S{
* G3 F5 }" @% j$ F1 g- p7 Cif(flagiocpt==0) // implement compute# _% G+ W2 c* t, F6 s* a2 X: j' B; I; N. L
{
% [3 T$ N; H. j* N6 M3 n6 R1 b8 ?i=(*memory).p[0].computeNum;$ Y6 n' P4 G* \/ x" ^
if(i>0 && (*memory).p[0].computeClock[i-1]>0)
, [: a; M3 D7 x& c8 Z0 m0 w/ e- P# H! H{
' a% k" C' ^. R; T# B- y8 mif(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed
" K$ C( x* Z4 r! t{
o' \2 I; J/ h& c* {; h2 jflagiocpt = 1;
1 f" I+ @* K2 ]5 u(*memory).p[0].computeNum--;8 p+ u1 D1 y. W, q1 E
change += exchange_IO_Compute;
+ M, E! z5 L& V xcompute++;
: h# }4 X/ }" l}
; Z: h4 i# b( f9 ]4 _else7 G+ H7 r, j; }7 Z5 y
compute++;; B2 T" s* y, K, D/ G1 B
# c0 l: g9 l4 ]$ N- m0 X}
; G7 { @- v' r7 f1 Q) ~- D3 telse5 A" D8 G4 v# P9 q" A) _& j
flagiocpt = 1;! Z7 ]1 c5 Q; v X
}6 [5 I. e0 r3 ^8 i; P
else //wait io/ T2 W5 D7 k+ R7 N+ @; v
{
! @9 a# `" M6 g9 t2 |i=(*memory).p[0].ioNum;$ {- Z: x& B n
if(i>0 && (*memory).p[0].ioClock[i-1]>0)
9 G- ^ e6 v% M" p) `{5 `: Z4 H; d ^
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed: K8 Z- P0 L8 l, y
{
& T/ U, u3 B5 X0 f6 r; ]# iflagiocpt = 0;1 m( h( c$ e4 l* L; D/ q3 m
(*memory).p[0].ioNum--;
$ ^& I9 {7 t9 E! H: v+ M, Nchange += exchange_IO_Compute;
, n) m' n* H3 ~2 A3 @% A- fwaitio++;
# z/ M0 o* e& M. L, A1 @}. X0 e7 V. F) k4 ~: G* B
else- _( }. ?0 s' _" \0 _
waitio++;2 c; h6 m' Z2 Q+ v* `1 c, w# R- n
! z! j4 o5 b( h. n/ M
}% X/ q; N, e7 I( {
else9 M$ s* H1 e$ T7 d- J
flagiocpt = 0;* d5 y! X4 Q+ q& L2 ?; x- ~3 d) g
}
: f9 i* t' S5 L1 w}
|7 Z; ]7 t# W7 \' Q; }: H4 Z7 ^else //task is completed4 i* V/ z* A9 F8 }* p; U8 S/ f
{
) N' e [5 u! O' F5 E' A5 W(*save) = (PCI*)malloc(sizeof(PCI));- D1 B; c2 e% c& Q
(*save)->next = NULL;# B. ?- r2 T; ~& H Q0 l
(*save)->processID = (*memory).p[0].processID;
7 ]- S X9 \" Q, m1 J(*save)->comeingTime = (*memory).p[0].produceTime;! P4 X3 @" L9 J8 Q1 c
(*save)->askMemory = (*memory).p[0].askMemory;( R, Z; U* t3 p6 Q
(*save)->compute = compute;8 \3 r) o. v8 r! \3 ] ~" l2 C
(*save)->waitio = waitio;: a8 N( L/ ^/ N- ?4 R
(*save)->exchange = change;
* t1 U6 n0 z! u9 ` v(*save)->completedTime = systemClock-(*save)->comeingTime;5 R; G! U) d! Z' q
(*save)->runningTime = (*memory).p[0].runningTime;
1 e# A# L0 [% W7 d6 x' p9 n; X7 d(*save)->completedTime = systemClock;
& O/ i4 n' j! g//*spareMemory = MAX_MEMORY;
2 N7 l8 l" \/ q5 u! s# O G3 ]8 qfree((*memory).p[0].ioClock);
0 a- W* E& J) Q% x" B5 Afree((*memory).p[0].computeClock);, D# o! v6 |( Y+ w3 x8 {! J+ ]
free((*memory).p);6 Q& \+ M2 X$ W/ v$ v4 H, W* T/ U
flag=0;1 |: M3 r5 c+ r5 q4 U/ N
compute=waitio=change=0;
; D' ` I B; m: ^& U5 {" ?& McomputeLast=waitioLast=changeLast=0;3 H2 p8 W* q& k2 x
return task_completed;4 [* {; L: p$ ^+ k. T
}
! N% {1 x, ^; _" k}& t! B* b7 _* w5 W; V1 ^: {8 k
else 8 y5 u3 ]# C* F, e, \: Y a' o. r5 D
{
" M/ ]& S' j6 m$ @: r: `FIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));2 ]: q" S: D; d$ R9 W0 k
change += exchange_process;
) E' F3 d$ h/ n$ M. R$ [$ Y//*spareMemory -= (*memory).p[0].askMemory;7 E# x8 c: |1 l$ ?( Y3 k5 O
flag=1;7 d, z+ \0 } X) [% @
//showProcessInf(*memory);* \$ O: h" k) G0 j1 W/ T l
return task_not_completed;
4 K6 U5 z) ]) b/ I. G( Z}/ p$ n' O% b, V5 F P
return task_not_completed;
$ f) ^/ s A' S# y- B3 C A0 v( u}1 h* P; Y8 E1 h. v: s3 R9 e
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)2 ^3 w0 `: M. P' K4 _2 R* r
{/ s) g- T8 `: X& _9 B5 A. m
int i=0,j=0,k=0;
3 o" J4 @5 J0 P9 e( y5 k6 g4 ~MAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;
3 \, D [; Z/ @- H& v(*memory).p = (process*)malloc(initProcessNum*sizeof(process));
3 f* b7 C6 @$ T1 m7 wmemory->proNum = 1;- u- p) q7 e& i0 d2 c B7 b
for(i=0; i<initProcessNum; i++)3 O, P/ k! l3 c$ I. [& @/ V
{2 O+ W4 ` J6 z3 n3 }! K
if((*storage).p.askMemory <= *spareMemory)! q. k# c7 @& q8 D
{! c! z! y1 c4 F$ L% ~
(*memory).p[0].askMemory = (*storage).p.askMemory;
! J* ^$ c& u" o ]0 }4 h* e(*memory).p[0].comeingTime = (*storage).p.comeingTime;) }8 s; y6 j7 d
(*memory).p[0].computeNum = (*storage).p.computeNum;" q* Y6 A0 ]: e4 d5 t$ M
(*memory).p[0].ioNum = (*storage).p.ioNum;
5 O( h0 r6 |# A" H4 J; l# S8 {: M0 i' Z(*memory).p[0].processID = (*storage).p.processID;
6 [, v; _ I3 j5 ~0 J(*memory).p[0].flag = (*storage).p.flag;
2 A7 R' b& M6 Z( m(*memory).p[0].ioTime = (*storage).p.ioTime;" G3 f7 Z- W" b
(*memory).p[0].computeTime = (*storage).p.computeTime;
! f$ M0 |! \3 f2 |; k4 p9 a: ^(*memory).p[0].produceTime = (*storage).p.produceTime;
. G) M0 t3 w1 ~(*memory).p[0].runningTime = systemClock;7 [ c n/ U6 x, U! f+ Y
(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));: X# B- H( L4 K% p* j" Q0 M1 D
(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));$ Y, s( N" V' `$ E* b
for(k=0; k<(*memory).p[0].ioNum; k++)5 Q% O! A3 ^( j- h
(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];
4 B; B9 I' }+ l* kfor(k=0; k<(*memory).p[0].computeNum; k++)" P7 k3 f- q% T1 Y! t9 X2 L$ \2 I. v
(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];
7 C0 q: W" T9 J/ ebreak;4 @6 `3 R& h# M" V$ R* Y
}
6 K/ s% |; r/ V; T2 i}1 S% r- y: n3 y
if(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入
* w# o5 w8 }% f8 ^! ?: m{2 @% Y h: o/ k% M
produce_one_task(storage,i,ID_FIFO++);- k/ u( X1 U) ?# R( R4 |8 H
MAX_COMING_TIME = (*storage).p.comeingTime;% g) U0 L2 x# w# I" W3 j
sort_by_comingtime(storage,i);
1 J: I( I* S$ z! I+ X}
- I* S/ c. ^6 I2 T8 Freturn 0;# Z8 u" c9 B6 P; B4 q J+ d% V% L
}' T4 A; i4 w$ g6 s
int sort_by_comingtime(processPool * p,int pos)& b" ~ O1 P" H0 I
{1 L; k `5 h! Q- q2 ?. \% k; L$ G
int i=0,j=0;5 x$ k0 ^( h* D/ Z' z
process temp;* k2 p; V1 o- S! ~! g
if(pos<0)2 [5 ?- `( U0 n3 ]
{7 _4 O' S V& P$ s" p4 [
for(i=0; i<initProcessNum; i++)
8 v0 e) N* A! w( b8 Qfor(j=0; j+1<initProcessNum-i; j++)- b( P8 H; C! l
{! f) z: R; J2 w7 A' E2 }1 t& P
if((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)" S) R* C1 a, K) |
{9 h) p) ]7 t( Q/ p2 Q
temp = (*p).p[j];
3 k+ g# @& M i; z(*p).p[j] = (*p).p[j+1];
2 }2 P, K0 x3 l4 a- h2 M. \ Q(*p).p[j+1] = temp;
; r* ~8 |% ~! e( ^. f) r}
1 x; l1 w: _" w* p$ ^: F/ N- k# @} X M. y4 h7 G: U [8 L
}6 j- _; I5 D7 J/ b/ o& o% E8 ?4 w
else if(pos<initProcessNum)
2 s( ]% I" E1 P$ B{
! k3 d% z# J+ a# c: Rfor(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)* p2 ?2 ?! g2 ~( W, i/ H* y" ~8 g. m
{
' O+ x$ T9 {! | q& }/ I% etemp = (*p).p;
z I; S3 ^* D. X N3 b& b(*p).p = (*p).p[i+1];$ d2 Q, d) X2 r. p. ~; }
(*p).p[i+1] = temp;5 ?1 r& y* R/ e3 z
}
& U2 F1 a7 ]+ m- B+ G5 F4 E5 sfor(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)
1 K7 U; R+ }" m# q. @/ o2 y- {/ x{
" H9 s9 t' ^; v0 u+ Xtemp = (*p).p[i-1];, N* |6 g9 d- W! h5 `1 P c
(*p).p[i-1] = (*p).p;
% d4 Y9 D9 ?+ L- r5 t0 Q(*p).p = temp;* G& l2 w$ n0 d/ c% U+ I6 m
}( H% `3 E7 _1 R4 V
}
) j" s& N; j( ]0 o2 Qelse: X% F. {4 e! @8 n" e; l
printf("position eror\n");
P4 p/ P+ o# a" r1 C9 A7 Creturn 0;( x) Z/ a ?. J m! C6 ~- s
}
+ c$ J/ {/ b, C0 c2 d5 jint InitPool(processPool * p)
+ P2 Q7 w/ P$ O. L& m{
8 q% p; l0 M$ _1 ], _) U: tint i=0;" m0 K$ d" b7 Z7 P8 r/ p
(*p).proNum = initProcessNum;$ w% ^& m2 m6 b a" l* b
(*p).p = (process*)malloc(initProcessNum*sizeof(process));+ e7 x0 x4 B" S/ B! `
for(i=0; i<initProcessNum; i++) //init process information) f4 q l ]+ f( b* Z
{
( a8 r4 A9 H" e, |, Y6 X, j2 F' m(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));! ~$ {5 l1 A$ h l2 V
(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));; Y4 w- ]& O2 a1 G
produce_one_task(&(*p),i,ID_FIFO++);
- m8 U! Z3 p: w; x}
0 u% t5 c4 ~) }return 0;
6 M+ J+ j, ?* {* F7 p}- s" M( S7 T7 r4 L! ]. i9 c9 G
int produce_one_task(processPool * p,int i,int id)
# Y6 B' l& z$ A% B- ~3 [{, V' c; M" W4 R
int time=MAX_COMING_TIME,j=0,totallTime=0;) E. x& b# e" I: H
(*p).p.processID = initProcessID+id;
. R# ]9 d X+ {' K; h( @6 M* t F7 L& M(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);! Z6 y% |8 v( m$ H* s$ I7 Q. L( q- a
(*p).p.produceTime = systemClock;
6 f% Y1 K! w& {) v0 W9 V(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;. K6 E9 I" b9 u, b
(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6;. \1 z% r j6 d* b, E
totallTime = (*p).p.computeNum + (*p).p.ioNum;4 L0 T4 Q, t% X0 o* j7 e6 C' B
(*p).p.computeTime=0;$ b, g& K0 Z( c( c8 e
for(j=0; j<(*p).p.computeNum; j++)
; G7 k4 p7 [' t) k; ]" P7 |{, @, b- N c/ h- a% v, Q y1 C' N
(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;
1 G! V$ R O: e1 R; Q$ [$ J(*p).p.computeTime += (*p).p.computeClock[j];
H# e- m: ]* q% h; p1 }$ O}, i& P: m: w) D% @9 M
(*p).p.ioTime=0;! J9 H* n# C4 F4 a0 e% r% a8 {
for(j=0; j<(*p).p.ioNum; j++) |
|