- 在线时间
- 1630 小时
- 最后登录
- 2024-1-29
- 注册时间
- 2017-5-16
- 听众数
- 82
- 收听数
- 1
- 能力
- 120 分
- 体力
- 564703 点
- 威望
- 12 点
- 阅读权限
- 255
- 积分
- 174634
- 相册
- 1
- 日志
- 0
- 记录
- 0
- 帖子
- 5313
- 主题
- 5273
- 精华
- 3
- 分享
- 0
- 好友
- 163
TA的每日心情 | 开心 2021-8-11 17:59 |
|---|
签到天数: 17 天 [LV.4]偶尔看看III 网络挑战赛参赛者 网络挑战赛参赛者 - 自我介绍
- 本人女,毕业于内蒙古科技大学,担任文职专业,毕业专业英语。
 群组: 2018美赛大象算法课程 群组: 2018美赛护航培训课程 群组: 2019年 数学中国站长建 群组: 2019年数据分析师课程 群组: 2018年大象老师国赛优 |
) J! b' R: X+ J2 }9 K8 M" d经典任务调度算法的模拟程序
- Y* L$ X2 p# \$ J* e本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。# @) E% u `; _ G8 E
( q* J4 H! e+ ]3 s8 i编程平台:VC6.0+EasyX图形库环境。
* z4 X- O4 p4 O% N4 U" U
" |: O( O: c& K5 f以下截取部分程序运行图::
/ D+ |1 r8 k4 d7 [, L1 P6 g0 c! X! h$ j; @0 D
源代码:. H# _( g9 D5 h0 s
4 {% ^) e x* ~
#include<stdio.h>" {8 u* ^& C) j: f% d. D
#include<stdlib.h>6 _8 W4 J& M2 }$ [0 q
#include<easyx.h>4 ]; i8 B3 F& ~( C7 Y
#include<time.h>
7 F; z2 v" m5 q#include<conio.h>
+ c! W4 t1 Y# C( s9 u) q#include<graphics.h>
8 D6 }# f$ U* W* H' ~#define initProcessNum 10
8 m6 m/ n' t; X T. d+ J#define initProcessID 1000
, b1 _7 J& d2 x8 M8 A) U#define MAXProcessRunTime 10000+ W2 I: E# s* v' Y' w
#define MAX_MEMORY 4000' B; @% k" M' K, T0 v3 ?) j: z
#define exchange_IO_Compute 10
% E0 F! ]0 f" K2 ~9 Z6 G( |2 i; @: [#define exchange_process 253 P% ?- ^* N$ d% @- D) X. ?3 S. t
#define task_completed 1
( R% W4 m# K0 `; |#define task_not_completed 0
+ k5 o* h& n2 d7 W# P0 R9 a4 b#define initclocknum 100
- B. [4 u" u4 H* Z- c4 U$ L6 lenum condition( S% W4 m" q$ z% T
{! ^) K O1 F% `8 C# w0 e r
dead,computing,IO_waiting,ready+ }& O9 x+ K0 e4 W; b* o$ M* z
};+ @+ K* i4 {9 q! D
struct process
8 D1 [/ R( e2 ] p! w! D{. ~" T5 x2 [5 s+ g
int processID;0 E% J" M3 V1 \; W1 P; U- G, K
int comeingTime;
( ]1 m; m* Y# X. P+ O9 jint ioNum;
* B7 d+ r2 w0 Z, r0 m. T( ^int computeNum;$ x3 C3 ?1 [- F, X9 t
int * ioClock;: G; K6 E$ G/ R" h0 G
int * computeClock;2 P4 ^8 P# @0 O; T d: H6 U
int ioTime;' m% L% m8 D n4 `1 ~3 k$ P& r
int computeTime;3 m9 D. \: o) V$ ?6 F; ~
int askMemory;
+ ^: h2 {5 }- u5 _7 Fcondition flag;
6 }$ Q4 [5 i2 D- P. rint produceTime; //生成时间,以下三个数据成员用以计算相关性能; ]* X" y6 Z* P
int runningTime; //第一次占用CPU的时间
; n- ]" p2 x5 Q tint completedTime; //进程完成时的时间$ N- b; b/ E5 z) K
};
' a" @. G7 `$ W ctypedef struct processCmpletedInfo //保存完成一个作业的相关信息% K+ G6 T* [ @
{6 A" F2 Y6 \8 m* ^
int processID,comeingTime,askMemory;
( {+ q# P7 K$ H3 n7 Q# fint compute,waitio,exchange,completedTime,runningTime;2 [7 p9 {' J) a6 p* L
processCmpletedInfo * next;4 B3 `2 m- {$ |, ?! _
}PCI;
: `$ _" }. R8 G2 fstruct processPool. W0 b' {7 e" t9 C* O; m
{
8 T5 R% N2 t8 o# d/ R+ i& Yprocess * p;
, A# D- X% T% R# {( [int proNum;
% V4 _$ u) n5 q};! M4 S* J( G$ N
int MAX_COMING_TIME=0,ID_FIFO=0,systemClock=0,FLAG_FIFO=0,FLAG_TT=0,FLAG_PF=0,FLAG_SJF=0,FLAG_HR=0,FLAG_show=1;
9 |# s! ?# j- Q/ `! R6 w' `int InitPool(processPool * p);
, y+ J2 ], w% E# A' z$ B# O1 tint produce_one_task(processPool * p,int i,int id);4 I. P7 y) H8 ~5 G2 \/ `2 ]
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);: X' j' C* i9 p# o/ }, D0 Q
int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);' Q+ s3 J7 q6 V3 Y9 o
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);
( F( g- m1 k! V& P8 b; @, U3 {int FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);( E7 j/ D) |4 w' ?
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
. ]$ d* w; K& m/ p5 Tint SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
4 K" j# q: l; T$ f/ Lint PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
2 M$ q$ M# Y: x% pint Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
8 I' b+ x$ f) g) _# B; zint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);
1 P* f8 T/ a$ ~int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
8 T/ B( s" B5 I
v* K. B B3 z7 _- t* `* ]/ F, f: ^
( Y0 E9 t" E8 v* ^int sort_by_comingtime(processPool * p,int pos);& k5 S- I! k9 d
int showProcessInf(processPool p);& Y& t5 Z2 h; d0 P% a3 O2 j" M
int drawPerformance_FIFO(int x,int y,int memorry);
, e- R5 n. o/ Q' {8 S- Zint drawPerformance_HR(int x,int y,int memorry);' C1 |6 ]# P7 Z2 T4 w5 c4 ~8 n: J
int drawPerformance_PF(int x,int y,int memorry);
3 M2 ?& [6 V. ?) l# h: zint drawPerformance_TT(int x,int y,int memorry);/ M1 m& F }; [7 Q: ~
int drawPerformance_SJF(int x,int y,int memorry);
' l1 P& @: c* Qint MouseListening();: }; p0 ] d4 Q( Y w" n
int MouseListening2(int *flagShow,int * showTime);$ ^2 Y! H4 f7 x8 |+ V9 K, k
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);( a, ~* ?( p' L* x
/ O" o+ M6 k" p/ v" T! t
% s# j: \8 n% I w
void main()
, H/ j" ]- Q( M) m8 l{ [% B% O% u$ L" D
PCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,8 R% y: w. K# s+ r7 F4 d- E" U
*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;5 v) M6 K3 i6 R+ z" a2 _
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,7 y# y7 Q- q; _ \7 F4 y9 d
flagDraw=0,showTime=100000;2 p. }* p+ D6 w, g% q# p
processPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;# H: f9 V. h3 J7 `4 B- i; p0 l' D" t
FILE *fp=NULL;( j1 r3 a1 R% j3 G- B
//processPool HR_p,HR_mmy;
0 T2 _1 I; a X. ], @
+ R+ W& w% w2 @& E5 A4 C/ T' E6 N- b: X
srand((unsigned)time(0));# N: l5 [* h" ^2 Z7 X" z
systemClock=0;! U7 v( H5 u6 t" b$ h: ]7 f* j/ m' v
initgraph( 1200,650,SHOWCONSOLE );
+ c0 m6 L/ p0 s- d& jsettextcolor(GREEN);
; L. C" G6 d0 h# U) d- Dsetlinecolor(GREEN);, ?# i7 i- m2 W' ~. l7 M
setfillcolor(GREEN);) e0 V( p1 f3 U5 O
InitPool(&FIFO_p);3 E; D( y4 b2 L# ^' X1 O
sort_by_comingtime(&FIFO_p,-1);
8 U8 W0 j" Z1 ?' N; j4 `6 W3 YInitPool(&Timeturn_p);
3 K& M- Y5 p3 rInitPool(&SJF_p);
9 h! ]8 [% W6 m, g- _1 f: SInitPool(&Priority_p);
' M- F7 ?2 @: v1 B3 j0 |+ eInitPool(&HR_p);4 g% u- x! ]. \7 t2 O& b) s
//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
q% p; J% C9 R5 G2 ]1 i U//Sleep(10000);$ W7 k y. ?8 b" E! ]
7 v+ q! h# l0 k3 w4 B
1 o4 V7 l- n+ ?& K) o+ m; r
Timeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
2 J* [ `" y, ~" w: ^) o4 RSJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
# w! q7 N% P0 c1 X) i lPriority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
; L; i. T( h7 V5 _% c: F3 {4 k8 ?& PHR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
* g5 B! g( e" _; n$ Y7 Jfor(i=0; i<initProcessNum ;i++)
( n9 x! \, Q7 w) C- N, T+ y{
2 V$ n/ s5 B7 j1 ^Timeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
5 p- n$ i( S- d+ DTimeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));+ x; q. t# e) [6 k/ Z
SJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));1 @3 J9 d- @* _4 ^0 A) w
SJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
, {6 V& w: {2 P, r$ p8 A7 WPriority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
/ ]0 @, y7 b. h5 |+ o8 z/ TPriority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));, d* [- h- r! G$ f5 L/ T, @
HR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
2 Z5 [. v) p* _. Z1 WHR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
) i/ Y2 o" u i+ S$ U! V; z}8 X7 ^9 \% ^: U# [- G$ r- l, t
Timeturn_mmy.proNum = 0;
/ M0 Q1 B# R9 ^+ Q9 a/ aTimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);6 p0 @6 _) v/ I9 [4 b2 ?+ B1 s
SJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);) I" C- Q/ _( W" H. S. {
Priority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);# ?% s* v, O4 |) k3 T2 |
High_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);) l- N2 x5 z6 O( l# [
//showProcessInf(Timeturn_mmy);; x+ P4 U$ n# M1 ]5 H' J2 g
FIFO_pri = &FIFO_save_head;
2 v4 f7 B) q/ Q1 E1 T5 ~Timet_pri = &Timet_save_head;7 x9 I' h# H! ^! q+ \/ e2 k
SJF_pri = &SJF_save_head;
1 S- g& s2 D' ~0 V' ]5 D1 I0 @Priority_pri = &Priority_save_head;
5 h) I( {# d& ~5 F5 R. j* E- y$ @ HR_pri = &HR_save_head;/ ~( H3 F) D1 X3 |
setbkcolor(WHITE);& n/ `, u# ?, F! H" ?
while(1)5 G( M) }9 F& e. l( q u) v2 ^
{
* |% B3 x3 k( C" ]+ N/ d* Mif(MouseListening()==1)
' w5 V; p3 G/ Y5 r0 {5 i" g, J8 c& HflagDraw=1;
8 u' U, y& b$ k. Yif(count==100)
4 @0 a# q6 Z' A4 ?{( C+ O5 i4 j8 o/ T( A
if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)
& I3 m, _" |* T+ m% y! v{
3 M7 Q% Y+ y% \5 u/ UFIFO_pri = &((*FIFO_pri)->next);+ k2 W/ [: D* }/ \/ r& e
/ {! j: U6 u8 J6 s//printf("hello");! Q: [% K) ^5 @
}: D+ U! G d( d* S- R
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)
8 p8 b1 n' G* B9 r- W( ^) R4 N% F{
" ^( i; u9 }- c3 W) U: N' W Timet_pri = &((*Timet_pri)->next);
" }% _2 }4 c# N1 I7 M4 f7 Q" c' K//printf("hello");
$ F! a2 D) p0 }* R, @}# l. g3 I3 z, O9 U0 |7 ^, l9 [. X
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)
1 l" s/ I0 X, k+ A. o1 H& t{7 N, @% x! `8 r& ?1 F; ?
SJF_pri = &((*SJF_pri)->next);+ I9 M! a& Q6 D z0 T6 p! F9 `0 X* _
//printf("hello\n");' M* l9 g/ ^/ k6 f; I
}9 P0 k! _# ~% x5 w0 A1 A
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed)
3 i0 L, Y, B# l) {7 `$ F/ l{/ x4 C9 Z$ s7 v4 n/ ]
Priority_pri = &((*Priority_pri)->next);, n4 E& A8 R) i5 @3 s3 c
//printf("hello\n");( w, y7 q6 C' e; z( j& a
}. |) @+ @* y! _& Z+ V: w0 K4 _8 x
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)
3 Y+ ~5 @; V4 t6 j; z) O{
. a% W- C! s$ k+ b8 G3 f% i: NHR_pri = &((*HR_pri)->next);
5 x! {6 w. N9 \0 D T& _//printf("hello");
, Y" }/ `7 t, c}
% U, E7 E, O' B" M. I0 V& m/ lcount=0;6 A4 H4 d2 k+ ^; }; \7 V
}. r+ @5 k! h3 ?+ _ Y3 \
else7 { v4 Q. Y& d- h
{
9 x9 d& B& h' X+ Jif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)4 ^7 C/ e: s. R( F3 H" O# w
{
6 m, q) q3 Y$ F7 M5 Y! GFIFO_pri = &((*FIFO_pri)->next);
8 ^( V( a+ a4 Z* b6 j4 p; i// printf("hello");" }4 a" G5 e6 ?" Q# r+ F9 Z
}
3 p/ |1 T4 [; M% cif(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)3 }, \% l0 a8 V2 m# ~
{
3 H! I# m+ w4 G( i0 _, r' c- {Timet_pri = &((*Timet_pri)->next);9 U3 ~3 A$ D$ V# k5 U& |
// printf("hello");
0 L A. m. @% M) T}
/ a! w2 H' Z1 P' F% ~4 oif(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)6 P3 h% g: M( f2 A
{
( I1 ?: N1 P7 C, C0 w; p SJF_pri = &((*SJF_pri)->next);. m/ B ?" _' Y- ?2 w9 f+ Q- t
// printf("hello\n");/ b. `( C; t# C+ ?8 S8 M
}8 F ^, F: Q% e& E
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)5 i: U3 S" u% m+ o6 m. h- \" U B
{
7 N# t I- `& W* j7 o$ gPriority_pri = &((*Priority_pri)->next);9 V! y1 ]7 ` B6 ~: l% o, W) G2 L
//printf("hello\n");
( f; K8 }. u+ f& H8 L9 ]}
: u, G! S! m' b7 O( F" V$ F8 s/ Rif(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)0 ^% D+ ]% @9 l
{( X, r$ r5 f. M4 q( Y
HR_pri = &((*HR_pri)->next);5 \) x; k" d+ Y; g! n/ G" M
//printf("hello");
5 V3 g* O2 h) ~0 c//Sleep(1000);1 v1 ], ?6 c/ j3 P
}1 j9 V3 B0 M% q) Y4 h7 M" j
count++;, _2 ~$ k. u7 I8 [$ {5 ~
}7 s" ]5 K% Y8 M& ~
if(systemClock==showTime)
& J# D, W/ p1 ~4 D H! Q2 L3 h0 \3 V{: m) I5 j4 N' O5 i7 L
/*PCI * p=FIFO_save_head;
5 `+ T1 Z4 y) V- Y0 }int i=0;
, Z/ Z8 \; k2 a% A( v# t, _/ ]for( ;p!=NULL;p=p->next); `1 a, l5 @, f7 E& O
{
k6 X6 _( ]) k. S) Eprintf("Id %d\n",p->processID);
8 ?/ ^2 b1 P }2 l( k" c6 ]$ Vprintf("comeingtime %d\n",p->comeingTime);. w/ ~8 s( [+ M3 K% _
printf("runningtime %d\n",p->runningTime);
3 t+ C7 I2 v7 H3 Y0 e% o+ iprintf("asdmemory %d\n",p->askMemory);
+ p* k$ o# H5 W* k1 j7 p7 Rprintf("completedtime %d\n",p->completedTime);
5 h# Z% d# g) J5 F: eprintf("compute %d\n",p->compute);
( b. c! B: a! l/ fprintf("exchange %d\n",p->exchange);" M1 S8 q5 Y& u9 H! {" b
printf("waitio %d\n",p->waitio);
* D# V/ h/ `( V# e; Z: ci++;; x" l! D. A: O8 E+ h F
4 E' {+ I! V( x" b
& \; V# k0 Q( w- N/ w2 S. | T. ~}/ b4 K' s* M9 i0 o4 x) R C% c
printf("%d\n",i);*/8 l. R$ B+ x8 i. V
if( (fp = fopen( "data.txt", "a" )) == NULL )
* W( i9 i, q; u$ w{
3 M/ X+ ?# t0 {8 b7 ?, e+ H$ r4 h7 cprintf( "The file 'data.txt' was not opened\n" );
4 R( y: [& p& I- W//return 1;# B7 `; H8 {5 z. o. Z B0 [
}4 P( ?1 k; M+ y: d
else
: t) t" o1 y' H5 G) S, V{/ [7 F! N6 j$ f0 E: r+ b
fprintf(fp,"FCFS \n");; ~8 s4 L! B- w7 [. N9 D1 j Y
for(p=FIFO_save_head;p!=NULL;p=p->next)
" d' D. n5 f' yfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
B' C8 l% S5 C+ e/ _6 S6 J5 ~p->exchange,p->waitio,p->runningTime);9 y ?* v. @% [1 A9 c; @- j8 m
fprintf(fp,"\nTime turn \n");7 ], w- p* j! y# a
for(p=Timet_save_head;p!=NULL;p=p->next)
" M- m3 [& [" jfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute," ]% f, h! p8 ~8 K& M
p->exchange,p->waitio,p->runningTime);
' Y! u7 k0 A) s. v8 R9 S7 {fprintf(fp,"\nShort Job First \n");: D0 u S n$ n; i E1 \
for(p=SJF_save_head;p!=NULL;p=p->next)- l0 ~# S. p9 O7 \
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
9 | G) j1 r0 T. X; E( vp->exchange,p->waitio,p->runningTime);
4 Y1 l6 M6 _1 a$ `# ~fprintf(fp,"\nPriority \n");) F8 s5 o/ x) b( V4 J
for(p=Priority_save_head;p!=NULL;p=p->next)4 z5 L: C0 V- a: C+ y6 {: Y
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,: @/ j3 D4 X! Z$ Q
p->exchange,p->waitio,p->runningTime);# d& @2 G8 _" G' W
fprintf(fp,"\nHigh response \n");
& o) ~# K( _$ M1 n" J- o. mfor(p=HR_save_head;p!=NULL;p=p->next)/ w A4 L$ H, ?/ w+ \4 Q9 p
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,2 d; V: e/ ?) x' X
p->exchange,p->waitio,p->runningTime);6 p% c4 B* ]; x8 v
fclose(fp);0 k: I5 d* H8 S' S5 T
}: h2 r- s0 b3 U) m+ q
showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
8 C/ m6 I3 A5 _MouseListening2(&flagDraw,&showTime);
+ }, e3 r! A0 t( B+ ]6 F}7 A, t, M, V) o
systemClock++;
/ ?" ~8 r, t4 i; j& D, Bif(flagDraw==0)
3 g4 r, X; s+ W$ l Sleep(10);
6 F6 Z3 v8 t' `' p- y. e, \9 M}
0 Q3 e& M) h6 I) p' d
' |2 u5 V* [5 B- H$ T2 V: Y; [# T) J' q5 Z2 v. H
}
. D% D, ?* S% C) i. Z2 r, hint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)
' N5 B) N' N4 x/ Q{1 r3 V3 i1 K( D1 t0 j P0 }
PCI * p=NULL,* name[5];
' u2 O" I5 z7 i' oint count=0,i=0;
# ?$ A& o; ` Fchar ch[5][10]={"FCFS","timet","SJF","PR","HR"};
5 x2 q" b% M6 @: _double turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};9 U2 J9 G1 q9 N
struct info
" x9 B: |: M# |. Q! x- @: Y) w{6 [/ X8 W! ]- ?. K% n) P- V$ ^
char name[10];; c I _+ U9 W) R0 y
double throughput,turnover,wait,CPU_rate;
" X( a3 p# o3 q; w* ^8 G}inf[5];; R( T( T) j, A! s; |
name[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;0 B$ V) \8 Y: e+ V
printf("调度算法..........A\n");1 D, g/ [+ Y$ X$ m2 U4 T$ f
printf("吞吐量............B\n");1 Y: u3 b5 G% m9 k5 |& s* P* G
printf("平均周转时间......C\n");
, c9 h+ {) X; r# p( h+ Nprintf("等待时间..........D\n");6 E5 R+ b2 ], l! c6 S
printf("CPU利用率.........E\n");
0 l" e- N( o; f: e% x6 @+ [5 kprintf("A\tB\tC\t\tD\t\tE\n");. g# w. c: O2 H J( g7 j$ B
for(i=0;i<5;i++), y- T5 j/ }$ j) k; I& l. F
{6 j& P, W/ `* B8 J! B# e, A$ X
count=0,turnover=0,wait=0,c=0,w=0,change=0;
2 V$ l6 e+ {" S) nfor(p=name; p!=NULL; p=p->next)
, n3 q2 `6 n! ]5 p7 E{! ~3 ~5 t9 z; r. v3 A
count++;4 { I* l5 t2 m" ~
turnover += p->completedTime - p->comeingTime;
4 `% G1 E- J0 zwait += p->runningTime - p->comeingTime;( O. s9 x( N/ ^
c += p->compute;
1 Z. H; J& f ^$ qw += p->waitio;3 W8 K+ X6 |" e* ]- x
change += p->exchange;
$ E5 Z1 [# Y3 L( b5 ? W}" l+ K- l: ~/ {9 Q
turnover = turnover/count;
: j. ~9 L4 ?4 b5 E* Q0 y. Bprintf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));5 ?: c* E3 z% D" r K
strcpy(inf.name,ch);6 n) [+ i4 K5 g, F7 n$ ~7 H- f
inf.throughput=count;
8 o- c* S$ B! xinf.turnover=turnover;
5 s5 n6 B* V3 K% _inf.wait=wait;! i8 C8 X- ] }' [0 k
inf.CPU_rate=c/(c+w+change);
1 c9 r, O8 l6 O- `}
8 `+ Q; _- p5 v2 U//画图) \! F, A: s( j' y3 d$ d3 p
//cleardevice();! k& r/ ~0 y" k) e
line(0,600,1200,600);7 f- B8 Z+ P6 P( M7 ]) ]
line(10,600,10,200);2 d( ~ C1 E2 Z! U; J
line(10,200,5,205);' r1 i- ]2 w# m* ~
line(10,200,15,205);& m3 F& t% o+ [, |) U
line(310,600,310,200);
% x* Z1 d4 ^7 d+ A# x3 a7 S# n( lline(310,200,305,205);5 D' Y ]# i5 t' e3 q2 B) R
line(310,200,315,205);
4 M2 N% P( g. a* Vline(610,600,610,200);
+ n. P7 N- o' `0 `4 k' uline(610,200,605,205);) w, t5 @1 l4 @" l7 i- ~+ i1 f% w
line(610,200,615,205);* i4 G2 Y p; d& R7 o9 ?8 `
line(910,600,910,200);5 M! n8 Y1 D& H8 x8 R
line(910,200,905,205);
+ L P! |& D1 }. @line(910,200,915,205);//最高的长度400,宽度均为407 a- w1 ]( j8 ]- X Q
for(i=0;i<5;i++)( `5 u7 ]" H9 z( c
{ F' | ]1 K- c' q, |. Y
if(inf.throughput>pos[0])- u+ C% m' }: _8 T
pos[0]=inf.throughput; C+ _' F2 w/ v4 G% C
if(inf.turnover>pos[1])7 l5 x( t z$ {! d% H- w Y$ W
pos[1]=inf.turnover;* S7 K+ v4 _3 K; c7 g! `( h: z
if(inf.wait>pos[2]) h' T8 o% r8 u. j/ \; g$ s
pos[2]=inf.wait;$ @: K' j! y7 Q
if(inf.CPU_rate>pos[3])7 K) M1 E) ]2 y! O0 l
pos[3]=inf.CPU_rate;
5 r* G) U8 A9 @7 Q/ U}. e! g, V( V, t- A
settextstyle(30, 15, _T("楷体"));, D5 o+ z5 E% X7 e3 r9 s0 g
for(i=0;i<5;i++)
7 Q( B8 @& \ W{& M/ x5 |' ^. }# u7 @7 G! k
switch (i)
# }" l' y' O/ r$ u, X{: |% ~2 s: u6 Q* w- T. u( \. e
case 0:
e: M# e( D; p2 x- F4 Nsetfillcolor(BLUE);
' p& j) X* u! i& \5 B9 v. v5 ?fillrectangle(100,50,150,100);/ R0 _ D. v" r/ g4 }
outtextxy(160,50,"FCFS");
7 W9 S. s: R7 y3 z3 p' A8 Pbreak;2 v) W1 y9 B, f) V
case 1:! S: n- l) _6 b: Q! g
setfillcolor(RED);5 r/ J7 o$ w' X
fillrectangle(250,50,300,100);3 x) Z- K; {" a, H
outtextxy(310,50,"timeTurn");
$ @* X; q7 A% ^4 z3 ~break;
) }; o/ M4 t( K+ U% l T, B1 ccase 2:+ a8 |9 ~& h: [4 u1 U9 T5 m
setfillcolor(YELLOW);1 R1 I* @7 J; z: p& o! U4 X- a
fillrectangle(450,50,500,100);
5 i. E2 O6 U9 n* n0 u4 {outtextxy(510,50,"SJf");
0 P; E/ h( i" Q1 C- Xbreak;
1 g* n5 @! P" P) u! c% P3 Qcase 3:
1 U8 R4 s3 w& n/ E9 @. \setfillcolor(BROWN);
7 V; p$ f- y, `7 N+ q( L0 wfillrectangle(580,50,630,100);; r O' `' \5 @% c8 x2 d6 ^% n
outtextxy(640,50,"PR");
7 _( J' H$ H2 [% cbreak;
% R( T- W1 ], V; V0 d# \case 4:' N5 J. e; x/ ~
setfillcolor(GREEN);: G$ i8 x9 A u3 f+ `# n
fillrectangle(690,50,740,100);! z5 ^ {! u4 j1 ~& s
outtextxy(750,50,"HR");; Q! |! D: R; ^. @1 r9 Y: ^8 q
break;+ j4 j6 ^* k' e. k
}
6 r% c% x! H& f P5 Vfillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);
* z: N" s; G5 M# V, bfillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);
4 @) e. a' s$ w h, g. ifillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);
* C0 q; u0 V; T2 T+ C7 _0 sfillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);
5 e0 F: e5 S: w( u5 n& H( o& I. X1 f) A
0 a& v3 Q' x0 ~}
; r; I. @' h0 @ outtextxy(100,150,"吞吐量");8 v) n" I6 Y; `, V; I" ^
outtextxy(350,150,"平均周转时间");0 z' e# D. Q4 q
outtextxy(650,150,"平均等待时间");) R9 a, W. K# B+ x5 E
outtextxy(950,150,"CPU利用率");4 t \! e; ~$ b$ h5 @9 \; y8 i
return 0;
9 O) I/ x% G5 C# r/ ?1 i; j, V}
" J' J$ s" P( N* iint MouseListening()6 m V$ v. q& ^& T. a. F% m
{6 f& l6 k9 c/ d6 F* v& r8 W0 g
MOUSEMSG p;& V% W0 P8 k- D6 a6 i4 H5 ~9 A
if(MouseHit())
/ L4 G) ^! R% R U Z3 V U{& I6 i1 m5 e! w9 L+ G
p=GetMouseMsg();; V% ^8 _# @7 M9 m4 S0 J4 p8 H
if(p.mkLButton==true)' J" E: H9 f4 l# l7 m' X# B
{
$ f0 Q; B) e# S, i7 L/ @if(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
: T( p% H/ D( L! u( cFLAG_FIFO = 1;0 g! Y* i8 T; q$ z: e
else if(p.x>400 && p.y>0 && p.x<800 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
1 e' q& U& k. a) iFLAG_TT = 1;
' w3 S! U2 d f0 }6 w) celse if(p.x>800 && p.y>0 && p.x<1200 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)( G! r7 _1 D, U' y# |( M% G
FLAG_PF = 1;
. k- G1 U' a4 g; d% s2 gelse if(p.x>0 && p.y>325 && p.x<400 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
b/ v. k0 W" r1 C; s: ]FLAG_SJF = 1;- M5 p. H' R+ G" p& x
else if(p.x>400 && p.y>325 && p.x<800 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0), B# p$ [ r3 O7 d7 M- L0 V e. J
FLAG_HR=1;
u8 t l) q5 a+ u: U. jelse if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)
7 Y' G8 k" p& J% j$ a% S( t4 x{
% R ]. }( q8 Z5 y% R+ kFLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;
8 j o1 `5 f7 w' T$ lclearrectangle(800,325,1200,650);
E7 |$ V* C2 n9 ?}
& _1 }$ z+ g/ ?" Aelse if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )
3 j/ l( ]/ P; \6 O{! H5 [' {+ ` h* [2 @- ]/ c
FLAG_show=0;
$ w' ?# l6 ]7 H* acleardevice();
2 M* `7 {/ |2 E+ W t8 I6 l8 freturn 1;- m2 _& {7 P" X* u; w
}! L! Z- H* j4 m
}
6 J+ V# y" [: b; M% M: i2 s}
6 D Q! L& S- s8 i1 H# xreturn 0;9 _) Y/ k: V4 Z9 E; U
}2 c( f( |- V5 t- ?6 F4 ~/ ?
int MouseListening2(int *flagShow,int * showTime)
) u% v4 U2 H/ R0 @{+ f+ P3 A# E8 v
MOUSEMSG p;
3 A" ?7 G- l% t- M2 n8 Rrectangle(1150,0,1200,50);* U M1 S7 ?0 L
outtextxy(1160,10,"X");2 |% K5 M1 `- z3 U3 P/ |
while(1)
/ X$ z- G7 a2 m{
) \" \0 W+ f1 S5 dif(MouseHit()) R2 G0 |: B: A( n0 }
{
6 D( M4 z; L9 P& o% l2 _! c* t) Jp=GetMouseMsg();; E- ^5 f+ m# M) b( X
if(p.mkLButton==true)
* x/ }) g2 L& H) D3 W" a& E{
. p8 N3 n1 R% Z, G0 K9 u$ b/ nif(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 ): {5 c( v/ H9 ]0 N; Z# y
{- e1 V5 K! `, r k8 q2 T
(*flagShow) = 0;1 H# D7 m% x, L' E& `
(*showTime) += (*showTime);4 ` Z0 U8 ~0 U! I6 b
FLAG_show=1;
2 ]1 |* U8 h; F0 _break;
: O+ k" w0 g4 H5 O}
6 r2 @4 b8 C9 _& k" d6 G! N* c# b& L/ v Z
}
7 U& u8 Z$ U' w3 q4 G- G! e' q: o! s}
$ c, F d! m" V* o" V1 H2 CSleep(20);
% \* n* b/ e; _8 `9 g" @}# J0 h) E9 e( X/ w6 q
cleardevice();4 z$ r+ A+ \; J2 l) J5 h' `) p
return 0;
, x1 G8 w6 I% m0 o: u}: S1 e3 Z, F) c2 d
int drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)2 X5 s" ~2 b; q5 C: A; m
{3 Y3 R. O* R" ]
static int info[11][3],num=0; [' |, D7 ^2 a; x
int i=0,j=0,pos[10][3][2];) C1 ?7 r Z, L6 r9 _" P* i
float temp,t;
d. K2 r: s% S) c \//画按钮,不属于FIFO图的范围9 C t' ^+ X6 ~: r
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1)$ P! n. o/ r! _6 m
{
& v' [2 p! C6 O) a! t" A6 `; jsettextstyle(30, 15, _T("楷体"));: }& X+ y& O) c
rectangle(890,455,1110,510);
1 g6 A4 {- |; W+ C) d. Xrectangle(900,465,1100,500);9 O- l! I8 e) D& j2 O4 o
outtextxy(910,468,"查看运行结果");' t! B1 `0 c, P
}
- b# G' A7 }8 o) `3 D* f4 R) p//结束画按钮
: C" r! s& ~: ]2 ~: pinfo[num][0] = com;- I2 |" t5 ], O. f; c* L' \/ l
info[num][1] = wai;
! o' R! f( t [# L: \info[num++][2] = cha;
! y# R( H" |: C% c2 Mif(num>10) //存储10个点2 c) j( c0 ~" n) m
{
" K) x. I; w a |0 k$ d7 r1 ^for(i=0 ;i<10;i++)
' \! X* G+ H8 r{# p& ]( N ^7 J7 g2 ?: L6 Y' f( E
info[0] = info[i+1][0];
/ d5 H1 R& w% a9 T8 sinfo[1] = info[i+1][1];
4 q- q" N4 Z" ^0 k+ i! P! Tinfo[2] = info[i+1][2];0 f1 ~' C! ]- a5 ^) |
}5 W- V: U$ j% P! I6 L
num--;
4 F' r2 W9 V8 Q& r; Y+ N2 m6 Z}3 z& x% y$ R: q6 R: A. v
if(FLAG_show==0)
8 \7 t; N8 j" xreturn 0;2 a; J( `2 @* B7 f% G+ [
for(i=0; i<num; i++)+ t- u. q7 O9 Q4 j
{
5 K2 n2 M2 Q$ d: X( u0 yt = (float)info[0];/ Z; X. }: S, G8 f0 I, u9 W$ t
temp = (t/101)*90;1 }" P$ s0 Q0 M4 D3 X
pos[0][0] = (10-num+i)*25+x+100;
& |) v2 ~0 J" n% s/ Gpos[0][1] = y+110-(int)temp;
( P) x! ?" A2 ~t = (float)info[1];
5 A& J+ d# H* l' utemp = (t/101)*90;
% P& N2 n( y% N+ S$ Cpos[1][0] = (10-num+i)*25+x+100;
, N- G6 w. x1 r# n/ ~9 gpos[1][1] = y+210-(int)temp;: M7 f. d6 X3 m5 l
t = (float)info[2];/ i9 P- `7 c+ @" i$ B5 f
temp = (t/101)*90;
) c/ B& G4 n3 d' b5 I! ~- npos[2][0] = (10-num+i)*25+x+100;
& I1 s# F1 z+ }pos[2][1] = y+310-(int)temp;; [" f& z% a9 ]; A0 H a
}6 T% {4 U, V6 ]0 W
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
" w2 Y' H7 T/ N, S! q9 c: D{1 s3 K% {1 z( W- Q. D0 N2 B z
clearrectangle(x,y,x+400,y+315);
( _. |; f/ ^0 _4 _' {settextstyle(20, 10, _T("楷体"));
" ?! ]1 ~- d4 d1 Yrectangle(x,y,x+400,y+325);
4 z, W3 H4 a7 W8 D* {! N4 Douttextxy(x+40,y+10,"CPU"); //画柱状图
2 m* x1 _5 O' Wouttextxy(x+45,y+10+100,"IO");; l. ?- H+ j ^8 Y9 J9 U
outtextxy(x+40-15,y+10+200,"change");5 A8 R. ]2 O" K2 ]8 ~; |# f5 ]3 i
rectangle(x+35,y+30,x+75,y+110);' S& N0 b+ u+ D; @
rectangle(x+35,y+130,x+75,y+210);) J" E4 N1 E$ w) V
rectangle(x+35,y+230,x+75,y+310);; o3 C+ u1 j9 W
outtextxy(x+180,y+310,"FCFS");
1 [! H% [2 @; B# s) Q' N. T: wt = (float)com;' v- u i* v: j, \. \
temp=(t/101)*80;
( _" e" m5 G4 J# c; Afillrectangle(x+35,y+110-(int)temp,x+75,y+110);
& L/ t% I, ^3 i: a8 wt = (float)wai;
8 T$ Q) S5 N+ \ [5 p, Btemp=(t/101)*80;
& H6 q; Z2 \9 G4 F+ Ofillrectangle(x+35,y+210-(int)temp,x+75,y+210);
& C/ G+ ?& D% s6 @- \t = (float)cha;
+ o; g0 r7 o: w; ^' Q! utemp=(t/101)*80;4 M2 D- a) K& A1 y7 J4 Y5 N \
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
- r9 r2 D! i* P+ }- U( gfor(i=0; i<3; i++) //画坐标 high=90,length=2505 D7 H) J) ?4 O& ]
{
, t" Z+ f6 y# fline(x+100,y+110+100*i,x+350,y+110+100*i);
/ L9 Z- f( O M8 D6 B) Z2 }, Oline(x+350,y+110+100*i,x+350-5,y+110-5+100*i); p; \/ N8 |3 d: j% M, B6 r
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);! K7 s% g( Q5 ^& a
3 r' O+ {* |6 r8 M6 zline(x+100,y+110+100*i,x+100,y+20+100*i);( D G$ E2 J8 e' D" m
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
) ]5 V: [( j |9 q/ vline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
- w: A3 W8 S! w1 }7 _for(j=0;j<num-1;j++)0 P' I- @( z& c
{
4 T9 ^4 }4 P. ]line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
$ t/ t) p& F8 t' E; P u/ @3 Dline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
' w0 v( }/ \) @+ |+ f- L3 Qline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 7 ~7 \: H7 e2 |& J
}
) S# E; M @. H8 I}+ t7 X6 {5 t; C: j$ e/ g1 I6 j
}2 R# h( I1 X. \) `1 Z# S+ w
else if(FLAG_FIFO==1)8 o5 L. x9 E. P
{
* I$ E/ X5 `0 \ bx=0,y=0; W$ j% t8 f: z$ s* r, |1 L4 k: \
for(i=0; i<num; i++)0 B0 o# d+ `$ T8 ]1 j& b
{
: o2 v& a8 v$ b9 p! ^) m( Mt = (float)info[0];
+ }! g5 J3 r- B/ Etemp = (t/101)*180;
/ |( C8 z: P" n# n2 M- V- vpos[0][0] = (10-num+i)*50+x+650;7 V: S1 ~! |9 S9 p @
pos[0][1] = y+210-(int)temp;
& y5 L0 M+ z! l0 u$ a/ gt = (float)info[1];
# g) |3 V: B# Z+ j3 A! ytemp = (t/101)*180;
/ y/ |- c: K! J2 ]1 U% i+ G% _' ~pos[1][0] = (10-num+i)*50+x+650;
; \9 J/ L0 b) h1 l+ `4 |* qpos[1][1] = y+420-(int)temp;
% J3 a( G6 l" _4 ^7 D; Jt = (float)info[2];
; w$ }5 D6 h2 J' V: E' Ftemp = (float)(t/101)*180;9 E* n0 H. S2 E
pos[2][0] = (10-num+i)*50+x+650;
4 |- b/ n z* U! y1 e8 gpos[2][1] = y+630-(int)temp;+ H3 i; B7 }4 g& R" F2 t3 S
}
4 C5 j' `: V) B$ A/ U# zclearrectangle(x,y,x+1200,y+650);
8 d1 q/ S% w. r- d, d1 Ksettextstyle(40, 20, _T("楷体"));, O- @. H+ G( z0 \0 \9 t
outtextxy(x+50,y+50,"FCFS");/ ?) [& h6 Q# E, Z8 l; ?, t3 Y& x
outtextxy(x+280,y+20,"CPU"); //画柱状图
3 i% M- p; r+ bouttextxy(x+285,y+20+200,"IO");8 d4 E# d9 J# y$ [' ^7 Y
outtextxy(x+250,y+20+400,"change");
6 S: X4 O# g E& crectangle(x+270,y+65,x+330,y+215);
) L) V( A1 O0 N7 J6 prectangle(x+270,y+265,x+330,y+415);3 [- o G; V2 U# @. t% r9 _8 I
rectangle(x+270,y+465,x+330,y+615);
6 c& S7 L3 x# W9 x# J4 ~9 aouttextxy(x+290,y+620,"TT");. ]0 r0 d3 u( r- g" h4 x# y; U, c
t = (float)com;8 p0 X: k8 N* u2 Q$ p& B
temp=(t/101)*150;" t" l* T4 p& P# o+ B
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
% u# i4 s( W/ K$ Gt = (float)wai;0 |2 m d( l& j2 U9 x' s
temp=(t/101)*150;/ j- i* V2 }% ~. i
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
9 n5 q+ l& \# o% m/ k2 |+ xt = (float)cha;
' W7 W4 A) ^4 _; Y ]3 ]temp=(t/101)*150;
& t/ V( x2 o$ q+ X( I4 m1 k6 Xfillrectangle(x+270,y+615-(int)temp,x+330,y+615);
) p4 \6 v) h' O, M: W8 sfor(i=0; i<3; i++) //画坐标 high=90,length=2500 g5 j) y8 P) t% e! e- m* ?4 ?
{! ^! N. S7 f m' L
line(x+650,y+210+210*i,x+1150,y+210+210*i);5 e9 u& x. N! a( l9 z, {4 n
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
( f4 [) l; S; @% o/ Aline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);# X+ x9 a4 B; ^# ~$ ?8 v9 \
1 b% w/ R! Z/ `" _5 Z0 ]line(x+650,y+210+210*i,x+650,y+20+210*i);
: k1 g4 Q8 ?; o5 @8 x- `7 tline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
7 |$ c; _# S: w8 z' C7 y! mline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
, o% e, o/ f# ~9 K1 afor(j=0;j<num-1;j++)* _4 H/ w% n: e- I6 B; s
{
; T2 \, n6 o( h( G, S' k2 B: }line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);% O0 @7 _0 I; s; g, I' w
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);3 j& P( Q; z8 w; F, `3 K, o
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 2 x# q5 u+ W. X4 {8 O
}
& U0 k. @1 n/ c3 X7 i D; V1 M7 ~}8 r$ A N0 Y2 Z- B/ x5 k8 G
}( K" ^% r) W" o
+ j3 X! b4 q: U
- K! C3 F1 y: d+ ]5 A7 K! a4 p% t- w5 Vreturn 0;- G1 y# h9 z7 ?/ t
}1 Y" c# z: I+ L: L( u. s; [
int drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)
7 G: P/ g' L1 G- Y& f{% f2 X- a, y/ G7 H0 W
static int info[11][3],num=0;
% k B* W. t9 K) F6 vint i=0,j=0,pos[10][3][2];
; \5 t5 t. m8 i3 I6 F: w) z7 _5 S2 ]float temp,t;' x8 Y* O8 [% d) y' t
info[num][0] = com;' A; O- N/ r C* N: U5 `5 r
info[num][1] = wai;
5 X/ U8 A% ?$ c0 \# {! e" _5 t5 linfo[num++][2] = cha;
% R5 a8 a+ N5 W& _, ?% d1 T8 C: Cif(num>10) //存储10个点. i" K; g4 M: \
{: L" b0 [* d9 b0 |) l$ x& X9 A4 ]
for(i=0 ;i<10;i++)
: I. E3 u3 U- [4 a) a{
4 v/ C0 [; _$ K. A4 Minfo[0] = info[i+1][0];
% |4 N' a# G t @* H1 hinfo[1] = info[i+1][1];7 O& o8 k6 E% D2 I! E+ y( r
info[2] = info[i+1][2];# n$ f% j4 [! ^+ P4 P+ A
}
2 V& \% O4 [: B5 Wnum--;
2 r3 f$ k- x' g+ x* m+ c- Y4 ^- b}
, p# {/ t/ O1 Y: k" @/ V& z6 Xif(FLAG_show==0)4 j9 u# {" f" d' E7 J
return 0;
& Q: O$ a4 k4 c- |- Nfor(i=0; i<num; i++)5 D4 L; x+ t1 T" d5 t
{
7 E7 {: H$ x' V1 v( Ct = (float)info[0];+ ?8 Q& k/ |9 u7 \& q& U
temp = (t/101)*90;
0 v; a+ y5 V3 q8 E6 J* z* l8 i2 @pos[0][0] = (10-num+i)*25+x+100;
1 G8 M/ F+ Z4 u, t3 wpos[0][1] = y+110-(int)temp;
" ]% L# e( i3 j5 G7 z2 Ot = (float)info[1];
# ~0 V6 v! V" L& L6 w& u* ^% z7 Atemp = (t/101)*90;' U6 i" s& {2 [& v! }. U9 J
pos[1][0] = (10-num+i)*25+x+100;. e8 q4 R5 Q+ z( [# I
pos[1][1] = y+210-(int)temp;
' h; m k1 a4 v7 V. O/ P: ot = (float)info[2];1 Q9 ?3 A) A: _' l
temp = (float)(t/101)*90;
& C5 o: M( U9 [, Z' b Vpos[2][0] = (10-num+i)*25+x+100;
' V8 ]+ e9 y& d! ~2 Q epos[2][1] = y+310-(int)temp;
% H8 ?& o5 n2 J3 w4 C/ w}
8 H' F5 k+ T" F3 u9 Q# K/ Vif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
2 S6 d$ Y/ |! b7 a7 e k: k" _! J{2 h3 j0 V# n% K+ ~' T; [1 b5 H' [
clearrectangle(x,y,x+400,y+315);0 {0 | k) X$ F* W+ q- O
settextstyle(20, 10, _T("楷体"));
: i& R5 {, e1 _( v2 v0 k$ X) a- Q: zrectangle(x,y,x+400,y+325);
1 ] q7 o( r/ o; p7 h3 Douttextxy(x+40,y+10,"CPU"); //画柱状图3 q9 R, C" a" v L4 V) Z
outtextxy(x+45,y+10+100,"IO");
9 {/ H4 Q$ _" F% bouttextxy(x+40-15,y+10+200,"change");
0 [( Z1 Q2 P' t" ~' b! Y5 {. }rectangle(x+35,y+30,x+75,y+110);
, K& \. ^* h6 O) e8 F) Nrectangle(x+35,y+130,x+75,y+210);
5 e) O1 ]. Q0 ^rectangle(x+35,y+230,x+75,y+310);. z5 n' ^' a2 f7 o, P/ n
outtextxy(x+180,y+310,"HR");
$ d4 _; w, @( T7 b! Kt = (float)com;
, h4 ?1 o+ g3 g- f7 D6 Wtemp=(t/101)*80;
3 @9 l4 h& L1 l2 m2 M# t+ O% Xfillrectangle(x+35,y+110-(int)temp,x+75,y+110);
$ B; e w# `/ G) U( Q3 Zt = (float)wai;
0 E/ x. D, ~, R7 d4 n- ktemp=(t/101)*80;
- I" d' B. B2 H! Lfillrectangle(x+35,y+210-(int)temp,x+75,y+210);1 z+ `3 C, b1 V3 f* T
t = (float)cha;" v) F/ ?- k. v$ D
temp=(t/101)*80;- [3 `1 Y$ g, o! y
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);$ p) g6 c( w3 w- _" n! I4 z
for(i=0; i<3; i++) //画坐标 high=90,length=250
9 I8 R8 {" W l( k. t+ {' f: `( q{
: X/ w+ K* l8 Y7 Rline(x+100,y+110+100*i,x+350,y+110+100*i);3 i+ ^& g% f9 c( M$ H/ _" F
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
$ U. }. i& @. R; Dline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
' N$ m' B7 _& {( H
; q# [$ J j! n- Eline(x+100,y+110+100*i,x+100,y+20+100*i);
* l1 y( ]% L, W, Z+ V1 b' Uline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
: Z& M7 @2 l: I, Hline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
; k: P$ l8 s R( k. }* k# V% @/ Ufor(j=0;j<num-1;j++)& `# [ F, @2 \/ f# O" D& E
{
9 @) K7 m4 C$ r9 \; q" Gline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
' R4 Y! f' o9 ^line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);% Y, ]3 j, s& `2 T% n2 p
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
/ \( e' @9 ]. R}5 L% p, S! c; l" E& S* ~! L* e4 q
}9 M0 F) O! [5 ^ s( m
}
$ _4 `+ I, y: H8 _" m+ B! V' Felse if(FLAG_HR==1)
; o% |) }" A2 U; q4 a$ P{1 o5 s$ x/ t* w: s! m7 M+ L
x=0,y=0;1 x u3 d' d8 ]5 B. _
for(i=0; i<num; i++)
" l* D$ J$ q2 ^+ I- S8 U- @{! E9 ~# O4 q C3 [
t = (float)info[0]; x% i, Y$ i- g8 J/ n" `1 D7 R2 x7 [
temp = (t/101)*180;
7 t |- h9 {% n {! d/ Y9 Qpos[0][0] = (10-num+i)*50+x+650;
' V$ U7 b A0 p+ q6 Dpos[0][1] = y+210-(int)temp;
: F" G# d$ O+ w2 l! zt = (float)info[1];! b' n# N. u) k* V1 v: a% c
temp = (t/101)*180;' g2 i$ n! V# B6 o6 L+ @" a+ S: ^
pos[1][0] = (10-num+i)*50+x+650;
T3 e4 h8 H+ d" }- O( wpos[1][1] = y+420-(int)temp;5 q# B i) v$ Y0 l2 h) e8 o! b
t = (float)info[2];
* Z e) O" J( h' Z: o6 P4 x% s# wtemp = (float)(t/101)*180;
~ f, O( G/ R1 Spos[2][0] = (10-num+i)*50+x+650;
- E1 T+ t1 m; O" c1 E- G, |pos[2][1] = y+630-(int)temp;# I- x' a3 x5 l4 j
}
/ {; j8 d0 N4 s# \% i" oclearrectangle(x,y,x+1200,y+650);1 W& p( W7 c" v$ ]2 ?
settextstyle(40, 20, _T("楷体"));
5 s" P X; E( \; _3 {0 S. l/ I* A* aouttextxy(x+50,y+50,"HR");- L% \# U' a8 v; P6 o) N& l
outtextxy(x+280,y+20,"CPU"); //画柱状图
4 I: Y' h4 ~/ X) ^ t! louttextxy(x+285,y+20+200,"IO");# G v, W$ ^, W) o) q0 _1 _- U" |
outtextxy(x+250,y+20+400,"change");
/ U' O- z7 h) srectangle(x+270,y+65,x+330,y+215);4 m2 C4 B) m" F
rectangle(x+270,y+265,x+330,y+415);
3 |7 Q3 m" _3 a+ H. X; ^5 [rectangle(x+270,y+465,x+330,y+615);
5 {* ]- q$ v4 b7 T" A" G9 nouttextxy(x+290,y+620,"TT");
/ I2 E" K1 {/ _+ X. f$ rt = (float)com;
+ e8 c" n, g9 k% `temp=(t/101)*150;5 E0 ^( L! B/ l- R- _& K! W$ _
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);/ L+ Y/ d+ I, S9 s
t = (float)wai;& J: A' y: U( z- A% h& B5 s
temp=(t/101)*150;
, V' u. x- W, }) Z/ s8 ]fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
! a6 B$ t) X& g& k6 Nt = (float)cha;
/ a) ~' N7 ^0 ~8 `) w; Y) a; Jtemp=(t/101)*150;
: D! v8 E# }1 `+ t/ p% `; Q/ I; bfillrectangle(x+270,y+615-(int)temp,x+330,y+615);$ z) ]1 q5 B- _: X4 G
for(i=0; i<3; i++) //画坐标 high=90,length=250
, T2 ~8 S$ ] q) h* A+ ?{
, C0 ~: i$ }+ ` N* {line(x+650,y+210+210*i,x+1150,y+210+210*i);
" ]3 L. f' q) Oline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
& q' b/ T9 F) x: r) Bline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);9 n# X G+ q( c0 l/ ^ L3 s
* H# X2 l) x2 M6 e/ Cline(x+650,y+210+210*i,x+650,y+20+210*i);$ `5 y- S0 E; k9 b2 w- N; _2 K
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
: @& r: ?% f( B8 Bline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
. S2 i2 X! O: y$ w- d" kfor(j=0;j<num-1;j++)
" L. ?. t" G0 R( N0 V{0 [6 f; _5 ~; I9 R# c9 S2 E9 K
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
8 x$ r- o9 J% [0 O6 mline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);, \7 t1 O8 q( b' @
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); % K- d9 r% W2 M; ~
}+ ?% g6 V$ v4 [0 s) J8 P3 _& d
}$ ~6 j+ N& \( F# N; [
}
8 [+ ^7 V `& m3 o, X! q8 t) ?5 ` G* \' B2 B9 o) f' r
* a# T" r0 _# C Lreturn 0;/ c2 t' s. W0 [4 S y
}
0 b' {( j/ c7 i7 n; u, fint drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)
) K1 q( l, n3 g3 R: S! A# h8 m{ z( ?0 r( q/ g) ]
static int info[11][3],num=0;
# A9 x- I0 p! oint i=0,j=0,pos[10][3][2];3 y+ }0 |# ]2 \
float temp,t;
. {& S; j. S* S: T6 {+ X; yinfo[num][0] = com;
; r4 m# A0 \4 a1 I/ o1 t% _info[num][1] = wai;6 \1 w! x. n) r( ?* {" y
info[num++][2] = cha; x% z' J, [# ?7 L/ z$ I
if(num>10) //存储10个点0 y( H0 p; u0 u% X2 ]& J
{
( G* o( K8 o9 s$ ]# W% G' P8 M2 u; Afor(i=0 ;i<10;i++). _3 x* C( _7 d+ ?4 g, d
{/ v2 V* D, n/ J3 u/ V( A5 |
info[0] = info[i+1][0];2 D' S w) @8 o1 ]$ }: ?
info[1] = info[i+1][1];: _# w h% y' f! b# ?8 \
info[2] = info[i+1][2];6 a6 |8 Q: q4 G2 t
}9 `( x7 {5 h- W$ Q2 x3 U
num--;) p% \8 {9 Y6 E" t% j) D
}% L: T n5 @- Y; m1 e
if(FLAG_show==0)1 L7 a9 }- t" V
return 0;9 H2 k" e& Y1 k
for(i=0; i<num; i++)# A" N a9 X" R$ u' a* I) b
{
0 z; v6 G% _1 a, G2 F/ G: qt = (float)info[0];( D6 f! O& n( q' h+ V% z( f- v
temp = (t/101)*90;- A9 r8 |1 Q0 W9 ^- K( s
pos[0][0] = (10-num+i)*25+x+100;; ~+ w. \4 z% Q) ~1 u7 \
pos[0][1] = y+110-(int)temp;
& j; q. i4 P5 E) e9 E) @t = (float)info[1];
5 k4 b3 U* E: [& Ltemp = (t/101)*90;- r' ~! i1 {: j! c9 M+ t& x* M) N
pos[1][0] = (10-num+i)*25+x+100;3 A/ U! k; f9 t) Z3 P% I
pos[1][1] = y+210-(int)temp;
* y) j4 e* e$ S- q' o1 N- pt = (float)info[2];7 T2 ~ r9 S2 S+ ^/ D3 ~
temp = (float)(t/101)*90;. L) g3 D i/ [0 {* K b Z4 U' Z t
pos[2][0] = (10-num+i)*25+x+100;
( n* C, C* }& Fpos[2][1] = y+310-(int)temp;! X8 x. x2 I2 V8 s7 A, R
}
7 n& F8 ]3 O3 a/ t7 ~5 jif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
/ H$ I" ]5 J2 X1 F, ~; I" R{9 s' L/ _- |# y
clearrectangle(x,y,x+400,y+315);
1 [' n" L r+ E- ?settextstyle(20, 10, _T("楷体"));
5 c6 t. J! K/ l7 U3 ^9 [rectangle(x,y,x+400,y+325);) R( s, j+ w* B& Y
outtextxy(x+40,y+10,"CPU"); //画柱状图
& j% {! f& G* Xouttextxy(x+45,y+10+100,"IO");% x, G; E! K! a0 W+ [0 ^
outtextxy(x+40-15,y+10+200,"change");# p6 `, c2 H% H7 G& \
rectangle(x+35,y+30,x+75,y+110);
2 k+ \9 l4 k1 p- b, w9 l+ m; Qrectangle(x+35,y+130,x+75,y+210);
. q3 k0 H) s. D* W+ erectangle(x+35,y+230,x+75,y+310);
/ u, s6 ^( s/ \outtextxy(x+180,y+310,"TT");" k: p. y* J8 W$ G' [0 M/ ~
t = (float)com;
3 A* P/ g) x$ n$ G2 ftemp=(t/101)*80;6 D) K5 |8 u3 g0 V6 d
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
- O9 _# b7 }8 n" wt = (float)wai;
. y0 @+ ?% }6 `5 e9 j% s4 i) Y3 h, Atemp=(t/101)*80;5 `. d$ r8 E6 X) i8 G. G. h. w
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
; \# i# l7 A x8 y! ut = (float)cha;
. Z/ {/ t& l- r) a% P8 ~temp=(t/101)*80;, x6 h0 R6 G: h( B
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);7 d1 G% V1 J% T, F
for(i=0; i<3; i++) //画坐标 high=90,length=250
4 f9 Q5 P: r3 `* }{: Y( {, \) p# f! ?9 w$ {8 y
line(x+100,y+110+100*i,x+350,y+110+100*i);
0 N7 r- o5 B4 D/ x# J2 K3 _' mline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
$ d1 ^ `& o5 Sline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);) E7 j1 Z5 c. h; b7 |
$ |* \( Z- m0 h1 h0 Z+ Z( ?
line(x+100,y+110+100*i,x+100,y+20+100*i);- {: y9 p5 m/ L; L% P8 a
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
( }/ J$ R: N: K9 _& Nline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);1 n$ N, o8 ]: }: Z V
for(j=0;j<num-1;j++)% i+ f$ E4 P! F0 ]5 P
{- s( c3 v( M) H% v
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);& _. I+ v4 v0 G6 o+ m# j
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);; e9 |* _9 l* F3 I( ]# g! S
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
5 I4 s$ J' A$ P: F" P! A}
* [* j4 i6 w& `2 C; {. r}% R2 p4 N9 L/ t) y' b# v. [. b' F
}
# s' v& J$ K+ K, felse if(FLAG_TT==1)" F% o' @3 F% v0 D8 x8 k/ X
{
& H9 v/ |6 d8 j1 E7 C4 ?x=0,y=0;; `" L' a8 M# ~
for(i=0; i<num; i++)
! @9 x# `/ e/ J- a8 s, r5 {: w{/ f- j" T% m2 V9 ]# s/ d
t = (float)info[0];/ j8 B) c9 X! j3 Z
temp = (t/101)*180;
4 E) S5 z! [5 N; h2 _pos[0][0] = (10-num+i)*50+x+650;
5 ?" S! E. W6 s4 d3 u1 B qpos[0][1] = y+210-(int)temp;) i! f0 u8 z% }: M
t = (float)info[1];; C- \" v6 I& w% F1 B. A+ b9 B6 F
temp = (t/101)*180;+ H5 l5 l% a* z" O4 \
pos[1][0] = (10-num+i)*50+x+650;- ^* K* _& d: M9 b. \
pos[1][1] = y+420-(int)temp;
# L8 w& H/ C1 M, I! r+ vt = (float)info[2];
* X' p5 T1 p2 d! [$ Ytemp = (float)(t/101)*180;
- h, Q ^9 E5 O) t+ Apos[2][0] = (10-num+i)*50+x+650;
) j6 n/ c( t$ apos[2][1] = y+630-(int)temp;
" O; F/ u8 \" _! |, D2 p7 ~. i" f}
6 G4 @/ Y# k4 i5 u# A9 b) Kclearrectangle(x,y,x+1200,y+650);
& m- p8 K" B0 I5 Xsettextstyle(40, 20, _T("楷体"));4 g8 ?6 } [% Q, Z
outtextxy(x+50,y+50,"TT");
7 o9 N& d, W8 p9 F$ uouttextxy(x+280,y+20,"CPU"); //画柱状图* p3 p' M/ R f. k/ F5 d$ S
outtextxy(x+285,y+20+200,"IO");/ }$ y; s5 s- l2 |3 Q( C
outtextxy(x+250,y+20+400,"change");
, s q2 r, c7 o* q$ {) J: irectangle(x+270,y+65,x+330,y+215);
5 M: G; B3 k& y4 k/ Q/ }" p4 o1 f0 b+ Krectangle(x+270,y+265,x+330,y+415);
! B; h# m! B" Urectangle(x+270,y+465,x+330,y+615);
& h) _' H# p# W: U/ Y/ y i, \$ Souttextxy(x+290,y+620,"TT");
0 j1 P% Y0 ^- H/ i S" m" at = (float)com;
7 |; f; c! p5 r* L7 n4 S$ Htemp=(t/101)*150;; y9 }9 q8 P) o; @* N
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);+ `% R6 h! E9 K8 Z0 f. M; z1 g0 _
t = (float)wai;
- O r9 d3 X, v6 y% c6 x: ptemp=(t/101)*150;
1 u) c2 g. M3 _* _+ a' Wfillrectangle(x+270,y+415-(int)temp,x+330,y+415);
$ ^7 m7 [. p4 F) N% E0 `t = (float)cha;: B! I0 ^ Z! c& ?! ~8 L
temp=(t/101)*150;
; \! _8 g! \7 R$ e* l6 efillrectangle(x+270,y+615-(int)temp,x+330,y+615);
/ J0 k+ e$ D3 nfor(i=0; i<3; i++) //画坐标 high=90,length=2509 Q! X8 C1 V0 ?+ O V+ b
{
% G) e4 ]/ R; l3 Lline(x+650,y+210+210*i,x+1150,y+210+210*i);0 s7 y- g& l z; J" Z- z+ V8 N6 J
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
6 H* I9 N' }% F4 ]% O0 v+ [+ G8 rline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);9 Q# [% C% o' e0 m- _
+ l' N f8 C( _1 _" J, S5 z0 uline(x+650,y+210+210*i,x+650,y+20+210*i);+ e& K7 z+ R: n5 Q9 W4 q" D
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);0 r# H* T3 ]* K9 R$ `* I8 G! X- _- y
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
, _* N+ @8 l! k, p yfor(j=0;j<num-1;j++)
1 X: A% b; n/ S: O0 Y5 q4 x8 f{
3 I: _4 O7 h: Z- U8 u: ]+ rline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);$ q l1 W6 }, S/ N1 ~
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
$ A) G, H3 x) M/ W2 `line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
' J. ]( l( m2 m$ p}: v5 _$ t- n8 h
}0 I- }/ r" `2 X$ K
}, ` Q% E& D: g m2 v! p
9 c- g( Z4 Y% F5 b7 O& k' f- b( w; ^1 a, @ F/ S! z" }
return 0;
. `6 o; {* Z% [% V7 _5 F}
( t2 G8 H- j1 \4 lint drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)2 F0 @- v2 I! K S
{
/ h) T2 V8 n5 @( R* h k& G4 `4 Cstatic int info[11][3],num=0;
7 y2 I9 Y! i( T8 b. Q( c' b5 h5 B! Nint i=0,j=0,pos[10][3][2];
7 C3 u. b' f' @float temp,t;
9 X4 B) ~. h/ h t0 \4 hinfo[num][0] = com;
4 N3 s# ~/ i7 d& F* ?info[num][1] = wai;* p, |4 {, v6 A: a+ ]& M3 E
info[num++][2] = cha;5 G% y8 s7 t3 o" M
if(num>10) //存储10个点
0 ^- h, e( s9 F( L{6 S0 y7 N0 [& z" |
for(i=0 ;i<10;i++)7 J: j7 l6 p; I' w, V- I4 ]5 ?( u) Z
{* F# y9 `- o* f6 s; G7 g$ p, t
info[0] = info[i+1][0];
# q- A7 E2 r) P* M, Sinfo[1] = info[i+1][1];! L: k: w% A1 X
info[2] = info[i+1][2];
% {' R) M) r! H. t3 X}2 |# Y- Q6 B5 f9 R
num--;+ `" f- z, O2 d( Q; u, K
}
* k) \. N2 f) R$ K4 x8 V- rif(FLAG_show==0) i4 O! j' p W5 V9 j. P0 r- o
return 0;
0 z9 L8 w0 j. h! Q I9 o0 xfor(i=0; i<num; i++)
% ] b( d7 U9 V' G4 o6 h{
$ i! @: a" w& B0 t# ^3 gt = (float)info[0];
5 P4 V- a8 q2 q8 ~# U' S/ Dtemp = (t/101)*90;
: h J8 P# @( L+ cpos[0][0] = (10-num+i)*25+x+100;& i6 w" k; c# A; o) w5 r# V& b
pos[0][1] = y+110-(int)temp;3 V+ R' k/ \% c0 |! V
t = (float)info[1];; |* D: Q7 a; b
temp = (t/101)*90;0 }/ q# L$ u$ Q/ K* N
pos[1][0] = (10-num+i)*25+x+100;
k V" V6 ?, E, [5 \* Spos[1][1] = y+210-(int)temp;
$ m2 ~9 B3 P0 G o8 Nt = (float)info[2];$ J J w+ I( i; ]$ x
temp = (float)(t/101)*90;* |# {8 R3 O( v( ]! _6 N6 H K) c
pos[2][0] = (10-num+i)*25+x+100;
t3 A; H% b4 j4 j2 lpos[2][1] = y+310-(int)temp;
3 D9 e; g4 f/ {& e$ [}; U3 U- X2 f# S4 y* p( F" }
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
- C! y. g* \ |6 ~0 r4 o0 r$ W( ?{* N6 @* N3 U+ Y6 {
clearrectangle(x,y,x+400,y+315);# I1 N$ Z! a+ `
settextstyle(20, 10, _T("楷体"));
9 \4 {4 q: M4 {/ i3 Vrectangle(x,y,x+400,y+325);
5 N% n7 C/ T' Y. K5 y- Douttextxy(x+40,y+10,"CPU"); //画柱状图
9 I6 l- l, B% A9 \0 Louttextxy(x+45,y+10+100,"IO");. H3 c E# ^3 D8 Y* @
outtextxy(x+40-15,y+10+200,"change");2 X' N H' {8 P1 P9 G' A
rectangle(x+35,y+30,x+75,y+110);% e; D: w/ o: x
rectangle(x+35,y+130,x+75,y+210);1 ~6 d8 |6 ^2 x# j) m( d
rectangle(x+35,y+230,x+75,y+310);
9 ?0 g2 q; _# J( douttextxy(x+180,y+310,"PF");1 ^5 A; Y$ z E/ h4 R1 M3 T
t = (float)com;
$ g0 i1 X$ ?! n$ b/ p0 h: X9 I+ jtemp=(t/101)*80;6 d5 K! V9 h) Z/ F
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
- C: V* ~1 l8 k- @3 s1 Y( Ot = (float)wai;7 E1 W! j# A' r7 u
temp=(t/101)*80;
* u0 b. I* ^$ |6 \+ q- zfillrectangle(x+35,y+210-(int)temp,x+75,y+210);& |6 a5 |9 t X& H
t = (float)cha;$ [0 N Q4 S1 A" _9 Q
temp=(t/101)*80;7 w: |/ x5 I5 _. z E+ O. X
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
( d# q/ ^' {, ~' ?! d+ ^for(i=0; i<3; i++) //画坐标 high=90,length=250
8 S5 z |. g- t# M( S{0 I; h; r% ^$ m* w3 ^
line(x+100,y+110+100*i,x+350,y+110+100*i);
* g7 n- n/ P+ F( Zline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
$ S5 a/ z' M/ a5 k& l* `* @7 v! H% wline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
) Y5 M0 X5 R+ E8 ?8 |4 ]9 m
5 U- o$ k1 W/ pline(x+100,y+110+100*i,x+100,y+20+100*i);4 t" u( h4 h6 h
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);* Q7 k! V- k% L. l9 w
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);1 \5 x" d. O/ O
for(j=0;j<num-1;j++)9 b* H, P8 h% V" v4 j* L* a
{% i4 ?, r: B8 l2 J. d6 w$ z, m5 N
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);- Q, @1 ?/ e' d& S5 B, f/ S& K
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
' D' N5 v. y. i- H5 I" [! \line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
% F1 u" W* g& S& q}
9 |5 U8 \$ a# N8 `. Z}! j3 V! A7 W& D: [: Y2 j/ p
}# ?( b) K9 V( N. k9 d4 d; N
else if(FLAG_PF==1)8 b" c# P$ {6 N2 P. Y2 W
{
0 D$ g. C6 B, ex=0,y=0;
! w* w) Z! y. k* S9 g, sfor(i=0; i<num; i++): q3 i3 S5 N$ g9 w
{2 d. z' N0 e5 g
t = (float)info[0];4 f; B2 E% E9 J$ L5 e$ z/ t# g
temp = (t/101)*180;
* s3 R% ^+ y; ipos[0][0] = (10-num+i)*50+x+650;
7 E/ u5 e. M3 E( apos[0][1] = y+210-(int)temp;
$ j6 p$ \1 v1 j( _t = (float)info[1];
2 N6 y3 `0 h+ v* }temp = (t/101)*180;
( d5 c9 _7 v3 I/ k' z/ gpos[1][0] = (10-num+i)*50+x+650;& n7 x" K1 Q7 N
pos[1][1] = y+420-(int)temp;
7 Y; \7 O! ~8 Z( H4 It = (float)info[2];
0 V7 t/ T& Z- V* n+ jtemp = (float)(t/101)*180;$ b) Y: p. ]( b
pos[2][0] = (10-num+i)*50+x+650;
5 Z, s7 I( f* q, z/ r' d$ b9 Kpos[2][1] = y+630-(int)temp;) U; x/ g v3 {4 z/ s
}3 B+ H/ ^8 i5 s6 x& y
clearrectangle(x,y,x+1200,y+650);
3 x" p* Y6 X0 vsettextstyle(40, 20, _T("楷体"));
- ~2 d- V& z1 v3 a! d/ ]9 d1 Houttextxy(x+50,y+50,"PF");2 Y2 g2 j' D! o& \- P
outtextxy(x+280,y+20,"CPU"); //画柱状图
6 ?+ z- p$ Y6 @ ]% D% k7 B) U3 routtextxy(x+285,y+20+200,"IO");, {# `+ {: X" J+ D
outtextxy(x+250,y+20+400,"change");
; T# @; G9 N, I- \, irectangle(x+270,y+65,x+330,y+215);
# Q8 S' V! N8 vrectangle(x+270,y+265,x+330,y+415);; [; P; ~! X j
rectangle(x+270,y+465,x+330,y+615);
& u( P, M, D+ z# `7 Q+ M% Uouttextxy(x+290,y+620,"TT");3 A; [5 L8 O2 ?/ w" ~% Z1 \
t = (float)com;5 F. Z: ]0 e6 E
temp=(t/101)*150;3 |4 W0 i4 b2 S% B, q. ]; k
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);) D. z$ o% ]* A* h2 b1 k
t = (float)wai;
( }, T- E3 G r: _3 a q3 K5 Rtemp=(t/101)*150;! K! H* f: F" b! q
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);* C. H2 v6 S7 x' b- y
t = (float)cha;
) y9 |8 Z8 x6 l2 Ctemp=(t/101)*150;0 B# ` e+ k" l( ?, Y. [
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
) z; S. O: F9 {! u8 ?: {6 Lfor(i=0; i<3; i++) //画坐标 high=90,length=2501 a0 V5 [" l" o8 }
{
5 E7 _% ~, X; p3 [- z9 y) q3 Sline(x+650,y+210+210*i,x+1150,y+210+210*i);8 V# p$ E: d/ @# j" ]) a6 m$ L
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);. f" I. Z4 U+ b: c1 W0 O6 \8 \
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
% L. y! D( e& R6 b% m* e" O- f) K9 O4 [ g
line(x+650,y+210+210*i,x+650,y+20+210*i);2 |6 s# H; o# |) \4 O$ U# \: ^$ T
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);) S/ V/ k. l1 c3 [3 B# Z: ?
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);$ H1 \# X( t% a! X6 H4 _$ O: b/ E
for(j=0;j<num-1;j++)8 S" A- p0 L) r6 |
{
# `- j' K8 \" Q0 R, C aline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);$ R; m- Q5 p8 J; b' J
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
( \) C r0 G9 ]! lline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 8 F S) w+ C0 h
}
7 p5 H( f2 Z ?: T1 [$ u! ?" [}( u, X6 H! q3 ^, z3 }) @- D
}
1 Y% k7 w% o3 v& I$ H ereturn 0;: f/ V( [- T% b
}1 B6 [0 Z' d$ M- D6 N
int drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)$ O: ~$ p4 d" u" P1 |
{) W; {3 f/ c) O L% q; _ T
static int info[11][3],num=0;) z1 `& y0 a( F0 \. I
int i=0,j=0,pos[10][3][2];
- J, q0 @$ r! Ffloat temp,t;8 c& L1 ^5 l/ b, A; O, c
info[num][0] = com;
& E* D6 N: T4 `. x8 {$ e" P9 kinfo[num][1] = wai;
1 W; z+ M9 R. Tinfo[num++][2] = cha;7 g4 R& B, j: k) i
if(num>10) //存储10个点3 e$ h5 g; `4 X A2 L
{' b- N; E! k* m0 h0 v: t
for(i=0 ;i<10;i++), u* A9 v9 z( s, E
{; W; v2 A$ w4 h7 ?6 K& z6 J* ?
info[0] = info[i+1][0];: H* W( U% _% A1 @8 H8 u( o
info[1] = info[i+1][1];
* K. b" L0 R" W' c% Iinfo[2] = info[i+1][2];5 v& x( h- M! {7 ?1 y, V
}1 g7 i- l9 X1 }) ?+ } E- T
num--;
$ N) M+ ]+ e) B1 ?; L o}
* p: y; Q2 e: b7 c* uif(FLAG_show==0)
2 i1 X4 ^9 f- p% j' [2 x! B nreturn 0;6 c5 A5 u) D. N) o
for(i=0; i<num; i++): P- h9 d8 X5 K! f, u
{. g8 B: w3 T+ @# c/ z* M
t = (float)info[0];
4 j( ]) R( E& c r1 a( T' N5 @( Utemp = (t/101)*90;
$ W! h. F( Y7 V* W6 |4 S! r; l- l. }pos[0][0] = (10-num+i)*25+x+100;
7 V, b/ _) T) j8 J5 upos[0][1] = y+110-(int)temp;
7 \1 m& K @' Z+ R& Qt = (float)info[1];; W/ S2 \+ a4 W, _- U/ Y$ T E
temp = (t/101)*90;
( G8 q4 _- ?) O. H7 kpos[1][0] = (10-num+i)*25+x+100;
9 {, i! ^! a! N" zpos[1][1] = y+210-(int)temp;3 d& Q4 @: B8 c- L9 @
t = (float)info[2];
$ Y5 E. W$ g0 r3 ?4 r H7 ftemp = (float)(t/101)*90;
6 t) K. p3 E1 Ypos[2][0] = (10-num+i)*25+x+100;6 ?3 i) \2 h- j0 Y2 [+ N
pos[2][1] = y+310-(int)temp;1 s. q$ ^* P: h/ Y) L
}- m: v1 c, j; o# |
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)" w6 y; m' ~8 F) m4 c7 {* _" h
{
- h1 b) O, D+ i6 a% F4 Tclearrectangle(x,y,x+400,y+315);6 b- C3 P* I5 V/ D
settextstyle(20, 10, _T("楷体"));
( m4 @) p9 T' q! E5 |0 a6 H- O* `rectangle(x,y,x+400,y+325);* z1 V/ u9 p6 k( d! s6 K
outtextxy(x+40,y+10,"CPU"); //画柱状图
& c) ?$ k6 `( u+ [- Wouttextxy(x+45,y+10+100,"IO");. `; A- c$ K8 K# H& T
outtextxy(x+40-15,y+10+200,"change");. Z1 C% u5 s- k* `4 Z
rectangle(x+35,y+30,x+75,y+110);8 O) x# B" n5 x
rectangle(x+35,y+130,x+75,y+210);
' g8 t/ p( v3 ?% D1 i9 arectangle(x+35,y+230,x+75,y+310);
% K8 |3 y* ~. ]0 t& Youttextxy(x+180,y+310,"SJF");
: C2 R) r/ e/ M9 F: Vt = (float)com;& w7 S( |5 n9 l3 k- T+ o2 E) z
temp=(t/101)*80;
. s) Z" G) A% F6 S0 _# Jfillrectangle(x+35,y+110-(int)temp,x+75,y+110);
7 Q. g' c2 k7 c' B) Ft = (float)wai;: u. q' ]. ~1 k5 @6 x# d5 ^
temp=(t/101)*80;' P/ [2 ~1 ^- r! a+ E) K9 q
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
) w! u. Z6 ]) d% L$ J: J$ b/ wt = (float)cha;
2 J$ j& L6 U. O, Etemp=(t/101)*80;* q8 @5 y5 n& ~: b' k# H+ E
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);" \6 I7 u# J/ w. ?$ s8 b
for(i=0; i<3; i++) //画坐标 high=90,length=250
6 t, c+ q: p! p( F2 X3 t{$ s# p. q5 H# q8 v8 h0 h! V
line(x+100,y+110+100*i,x+350,y+110+100*i);. p1 \5 K1 v- l* Y
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
c4 X, M4 B4 S% iline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);1 {" `$ `; X+ _, C: u. R) e
5 q# R& ~: d4 Q. ]
line(x+100,y+110+100*i,x+100,y+20+100*i);
# ?. V; g7 P" g# K$ Z% fline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);$ V: @4 B0 l C R. ^" Z9 S$ b7 c
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);* A* @' R9 ~, _* C
for(j=0;j<num-1;j++)
: L3 R+ u& v4 h/ L{
4 v6 T8 n. r5 x" T9 J F, N1 c, f% ?4 Gline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
4 x! R. {, K l0 x1 }0 Nline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
8 l: C4 `' O f& u0 m2 Pline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 1 D; V) E" T) |
}
7 a8 Q2 E0 j, v6 _}. Z$ F7 I2 H3 s4 m r. ]6 `
}
; L% q2 s8 e9 t! r1 K% Celse if(FLAG_SJF==1)
( N5 |. m+ Q/ q, ?' |{
/ F8 }! H6 E% d. w2 Dx=0,y=0;* s' B$ f2 |- o" G
for(i=0; i<num; i++); o9 d; h6 |- e P
{9 @4 A" f& M& S5 r0 L
t = (float)info[0];, L) e: e# V# ~7 Z
temp = (t/101)*180;* A1 ~7 E, N: T+ F5 f
pos[0][0] = (10-num+i)*50+x+650;
9 m8 q- i8 W$ |. W6 f. X( zpos[0][1] = y+210-(int)temp;1 q# m0 L6 C* C. R
t = (float)info[1];
' ^) k) x* r$ d) d$ _2 P6 C3 wtemp = (t/101)*180;. R* K! [' O C( t- M5 V; P& w
pos[1][0] = (10-num+i)*50+x+650; Q# D! i* P7 n( g
pos[1][1] = y+420-(int)temp;9 n3 `" {: q' `* q. M z7 s
t = (float)info[2];7 Z2 J7 v& Q. D) {- ] A
temp = (float)(t/101)*180; i+ j G& \, |4 {
pos[2][0] = (10-num+i)*50+x+650;
' Y/ N) P- B- O8 W; N+ Hpos[2][1] = y+630-(int)temp;
) g o, U% A" Z0 s7 d}, d# v& f4 I; H1 @* O$ a- d
clearrectangle(x,y,x+1200,y+650);
! T" x: x* q( [$ M% R b- esettextstyle(40, 20, _T("楷体"));
( s7 o$ O& b8 bouttextxy(x+50,y+50,"SJF");
" ]! k1 j+ e' L& x2 douttextxy(x+280,y+20,"CPU"); //画柱状图( m( L8 a; W- b% Y, i2 I* H1 T5 [
outtextxy(x+285,y+20+200,"IO");" I3 g& h. H/ K+ Y3 V: ~
outtextxy(x+250,y+20+400,"change");; p/ G2 i( E0 K6 u( J# k( h
rectangle(x+270,y+65,x+330,y+215);
5 J8 h& i7 n8 H, f- H, |# u0 q# trectangle(x+270,y+265,x+330,y+415);
8 s6 e( U( c$ G6 T9 f, o- jrectangle(x+270,y+465,x+330,y+615);
, q9 K8 a8 @! H( A% V6 k" i" T& @* eouttextxy(x+290,y+620,"TT");
) v* f M D8 w+ g3 d2 zt = (float)com;' u# J$ `+ l1 F
temp=(t/101)*150;
) g3 f( L. f8 m5 ifillrectangle(x+270,y+215-(int)temp,x+330,y+215);
& t# O. k8 I7 dt = (float)wai;5 V3 a, K% y0 f' m* D
temp=(t/101)*150;
1 n9 v% `# C2 W1 [) O. Cfillrectangle(x+270,y+415-(int)temp,x+330,y+415);6 b4 v1 {' p% t* W. j4 G, j. j
t = (float)cha;
2 W. c1 F; D8 m, Atemp=(t/101)*150;
. `* D0 Z# |; T6 w8 i2 xfillrectangle(x+270,y+615-(int)temp,x+330,y+615);
7 x: u$ K* a& r$ m4 w" Kfor(i=0; i<3; i++) //画坐标 high=90,length=250
$ y' P; J9 z+ E6 E! _{
, J4 e$ i( q! U2 Tline(x+650,y+210+210*i,x+1150,y+210+210*i);
1 T" p0 l8 R; a6 a. g. Q4 }line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);" w& N# Y% p5 W2 J- f% c, K9 `& p
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
2 W! |, g6 `5 G4 t2 J: G# R" F
# p9 [2 v/ z- y; B* Xline(x+650,y+210+210*i,x+650,y+20+210*i);. k/ ^* `4 Y1 N9 Y- c, f% g
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
. {5 W, U* Z: P9 yline(x+650,y+20+210*i,x+650+10,y+20+10+210*i); A7 z3 ^7 l6 A* L
for(j=0;j<num-1;j++)
, n# D y$ C7 k" B# D4 p# p1 Z{, a$ N& L' e$ F$ d( Z7 s
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
' i0 w, m% }9 t2 R% dline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);, d4 q2 O( p0 d7 Y. W
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 7 a3 ^+ j- ?# ^7 y: g
}& Q. @1 q5 S/ L
}6 A7 @, [& U ?& t7 S
}% g% G" y. r& ?9 A: A3 j1 ]* ] y
return 0;: D* \$ K6 C* A* e
}! l. R( `# C' y2 L8 @& k- \
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
/ T: r7 B1 H4 b# N! o& e{
( N& \. h6 ~, P A9 T+ F$ Mstatic int compute=0,waitio=0,change=0;% \$ ]) c( e" E
static int computeLast=0,waitioLast=0,changeLast=0;+ ^- |- ]7 T+ _& z" t
int i=0;
5 S! ]1 V' n. z3 Qif(draw==1)
! m, U0 B! m' v3 s{
( x S% E7 Y! A//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);8 x, a1 M0 |) ^/ c) F$ t
drawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);3 m2 v) I {% ]
computeLast=compute;
/ h8 Z# N' a ~waitioLast=waitio;
( _( z' l2 A( c3 g4 ]1 SchangeLast=change;) `+ d h" H0 J7 V7 b, u5 D8 B8 m
}
3 f! T8 n- J0 r* f" Jif((* memory).p[0].flag==ready)& `9 q) b# {% V3 p
(* memory).p[0].flag=computing;7 F8 y$ B5 [6 `$ S$ g; P1 `$ B
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)% O! X( W: `9 } g) b
{
+ b o: U$ P q! G! U2 }i=(*memory).p[0].computeNum;
$ s% o- U6 ?% c! n+ \' vif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
+ w. c# {! L! q# \' {1 |# c{
1 b9 n, |* n) f1 l% x+ {2 @(*memory).p[0].flag=IO_waiting;6 k7 T+ C8 f4 e1 ^
(*memory).p[0].computeNum--;; b' B" u$ A" G' @6 w
change += exchange_IO_Compute;
$ V: f5 Z8 ]- s6 E3 wcompute++;
; \, X0 ~" O& Z: e! D}$ d! ]: X5 y. K" h
else
7 E5 U8 f- n. ?. T{
" F* S. g" Y" i- R) wcompute++;
: Z1 S- [8 q- a* b- N}; L# Y: t+ y8 J) f# A
}
$ q7 b. d9 k# q7 g( X) Z0 Z: welse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting), R" A. m# Q0 b' n& f; Q
{8 h p7 A+ Q2 A: u
2 j4 V2 z n, P
i=(*memory).p[0].ioNum;6 N2 X0 f) k* E6 E W
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed# Y! d( n; r) q. s6 V4 G
{
6 @' P- D+ j. e3 M/ [(*memory).p[0].flag=computing;1 m o% h2 [2 E+ e9 i A
(*memory).p[0].ioNum--;
& }9 Q2 B+ b: }5 Q, Kchange += exchange_IO_Compute;( m6 n* Q R! n. M' R \6 O# u
waitio++;
! k, T/ S' |; c" s}( o& Y, b+ I$ _" E3 w. K. b- I0 d
else
( D- r) d( {( ?8 M{
$ k+ W; L, q. Y+ Owaitio++;
" R( W3 g S/ z. j0 F0 M8 @& E; ~}9 t2 k a) I% w8 T+ O
}1 Z) i: r6 M# a3 G! ^3 q
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
) T* z3 z; b) n. Q; q6 k0 X{
! S5 T) }6 o; i5 a" I- }4 }- Q(* memory).p[0].flag=IO_waiting;
7 D) r- G1 K& {, j. V& f" _- ~change += exchange_IO_Compute;4 J+ v: o, b. t) G
}
- d$ t( q8 y# K3 q7 B) {else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)3 d' G6 m+ U A: [ B
{# L) e0 ` u5 z) f/ f+ X4 L
(* memory).p[0].flag=computing;( J6 j. L$ C( c4 m; a5 `
change += exchange_IO_Compute;( D1 X1 O5 j! h! [2 @
}- o3 R8 ^4 s! Q$ P
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成; y8 J( {+ b* t: Z' h% ~! s
{
6 K. e1 L4 C# f _+ ~0 ?: c: o(*save) = (PCI*)malloc(sizeof(PCI));$ j# t% Y1 f$ D9 m9 H
(*save)->next = NULL;
" ]& B8 E! N# y) P m9 e( c(*save)->processID = (*memory).p[0].processID;
/ k. @+ D2 \: y0 p7 p(*save)->comeingTime = (*memory).p[0].produceTime;1 m# V5 ^( o" y; @$ b
(*save)->askMemory = (*memory).p[0].askMemory;8 b0 u2 h) @/ M) \+ `$ P) n
(*save)->compute = compute;
( w$ k1 s5 w7 ?9 B! ~5 |(*save)->waitio = waitio;
: ]1 X# Z7 z2 I& g(*save)->exchange = change;
6 X1 z' Y8 d6 B5 H @(*save)->completedTime = systemClock;% Y0 e; ~6 J0 n0 x0 t
(*save)->runningTime = (*memory).p[0].runningTime;4 [; w; U0 f% X1 R
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;
, H8 R: Y6 u5 J2 ?) ncompute=waitio=change=0;
- _( I5 Y# M6 O1 RcomputeLast=waitioLast=changeLast=0;. k- R* @( c3 C; C9 |8 V- b8 g- }
High_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);
: ~ j. k8 C1 x! E! A" N' |6 `change += exchange_process;1 y1 W6 }8 h8 O% I5 Y# I5 `
return task_completed;9 T6 A6 L5 N6 I9 k! Z) T# F3 n( S I4 \; B
}3 \* @3 u) C' Z$ ^ X% F2 X; _
else. q2 g9 Y4 d: R. L
return task_not_completed;* T" @/ v5 Q4 a9 j- l6 d9 C
}
/ H6 Y! n- r6 q( @+ a2 N& o qint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)' A& W- h( y8 c) n
{1 `2 Q* a. V6 B5 `' O
static int waitTime[initProcessNum],i=0,j=0;
: @+ Z0 l0 {8 Z! Z. m8 i! d) `static double HR_ratio[initProcessNum];1 z- l. w2 _, [+ D
if(flag==0) //初始化数组
! D9 X+ n# y+ H' x2 O) s7 [8 Y{
4 f/ D: D7 u: V$ S# u. E% Y0 }for(i=0; i<initProcessNum; i++)8 q% `2 m) ]0 X! i7 q, `
{
) q, |* s, T# Y$ N* n+ q* Z2 c7 p7 pwaitTime=0;
" L- B p- n. t, j% FHR_ratio=1;- O! \- ^# J3 X! X
}% N* A( [" T6 ? U5 l
}9 z" R) q, F, K+ }9 \# N
for(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比
6 Y5 W" f; u* N{
5 p$ R- ^7 ~3 xwaitTime++;
0 |" `+ e: t1 rHR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);
' A2 [( L; U! b" w# O. Zif(HR_ratio > HR_ratio[j])
' {" z5 K5 g: w+ E, jj = i;
" y7 c( V5 S# G9 Z2 R}
: t- {+ Q. G8 B2 ? dif(dispatch==1) //需要调度一个进程到内存中执行/ S/ A' Q# f4 u
{
7 m( Z6 E# A7 C: K1 @if((*storage).p[j].askMemory < *spareMemory)
( Y# u- x# a7 {, [8 H{0 F( t. K& l7 w8 l* V6 c, O
(*memory).p[0].askMemory = (*storage).p[j].askMemory;
# H# ?9 A3 c' s(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
( E4 H( f ?$ }& `3 J: Y(*memory).p[0].computeNum = (*storage).p[j].computeNum;# _% y, n. g9 W- r3 D6 T5 r
(*memory).p[0].ioNum = (*storage).p[j].ioNum;9 L6 a7 x: U% ~7 U6 Q8 k
(*memory).p[0].processID = (*storage).p[j].processID;
! |# ~. P' ?# C: g/ _4 {(*memory).p[0].flag = (*storage).p[j].flag; ?: }, o$ ]! G' s" Z4 m
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
- t) ]! u- `- K' `2 A9 E: O, ~(*memory).p[0].computeTime = (*storage).p[j].computeTime;
4 g8 D/ Y8 Y2 {" ](*memory).p[0].runningTime = systemClock;
4 l# b+ z. G3 n3 C9 ~(*memory).p[0].produceTime = (*storage).p[j].produceTime;
5 b+ R8 J$ A- R/ Y4 ?( N+ Xfor(i=0; i<(*memory).p[0].ioNum; i++)4 D% R, V' m+ h# \. T s# a# i& }
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
1 {; f+ M5 l; W3 b& A8 Q6 Rfor(i=0; i<(*memory).p[0].computeNum; i++)
" V# G7 A9 x" R1 q- X. }& I, U. ^(*memory).p[0].computeClock = (*storage).p[j].computeClock;. F# A1 q: ~9 c0 D: ]
(*memory).proNum=1;
" v8 f$ l& B4 f2 _+ C7 ^+ S5 m*spareMemory = *spareMemory - (*memory).p[j].askMemory;/ Z1 U; |* j1 G g7 D6 j( t# U
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
/ e3 P9 \3 m. e5 j5 `( g- G* D(*storage).p[j].produceTime = systemClock;
+ _& t: k& [+ x( u q) g7 dMAX_COMING_TIME = (*storage).p[j].comeingTime;3 ^( B- Z% h( n7 t+ F3 `, M
waitTime[j] = 0;
/ M K/ G8 d0 B3 R* ~HR_ratio[j] = 1;
6 w; J/ S/ W/ @) h- c7 o}8 [# i% A% w0 G8 l
else
9 a- H; B: U' I/ B# v% L4 y! E2 X{, [( K0 Z* e: ~4 ]6 W+ c
printf("A process ask for a memory overed the system capacity\n ");4 Y3 T. O1 }! K4 |4 k6 z
exit(1);( O' T; k0 \$ }6 Z* a
}
4 w! G+ j9 n1 x. o}
& q; a. j+ S5 L5 P) o" ireturn 0;
2 Z6 C9 _ k# |2 y- p4 n}
( d' s& e4 q2 k( v9 A# b" S2 J5 Y$ e; @int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
# D9 @+ t) |$ \- Q0 Z* r{. r' N+ w) y( K* T: W
static int compute=0,waitio=0,change=0;
! G- U" j( P: v1 H9 p1 x7 {static int computeLast=0,waitioLast=0,changeLast=0;
/ A8 c( C F1 Wint i=0;
3 M0 V& J% _( c& O+ mif(draw==1)( U$ P( }, q) E' u- U
{9 g9 y# _6 r( X: @& |" L
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
% N0 D V& l2 `0 ddrawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);: h) M! B5 S* G ^! K1 N K6 w
j& x8 U" n! L7 v3 h( r" U
! K4 t( B4 N9 n* v# A# f
computeLast=compute;
) o! ?+ Q7 f L( N" ^" N/ u4 PwaitioLast=waitio;1 ~5 l5 v2 \! [
changeLast=change;1 D( K: {( z; M' A; K. g
}2 ?, n8 H2 c; o. L0 P
if((* memory).p[0].flag==ready)
0 a" y9 X9 |$ D, v& y(* memory).p[0].flag=computing;/ J" l& R4 D r3 q7 Y
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing): V! y+ V: W* p5 L+ n3 [* N
{2 S1 t1 f& @; y0 O, t
i=(*memory).p[0].computeNum;
/ s( H+ |9 \1 P! xif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed! V9 |5 D! { q
{
7 x9 \7 o+ s) e" c3 d" g(*memory).p[0].flag=IO_waiting;: s, v2 a7 A5 C2 P
(*memory).p[0].computeNum--;
! p4 v( ]2 U4 B. R" S* U" i( Nchange += exchange_IO_Compute;
5 _* E' o/ r+ l6 ^3 tcompute++;
" o# p; N2 I6 U3 Z2 D k5 ^- k' b}
! X( N, _ p# A* ?& u9 `# a2 x: Eelse
& T( _: x: p- m v1 g' C{1 d( O, ~7 f! _" n! y7 x
compute++;) N% c% i, r7 Z. w/ a
}6 T% v/ o8 `& R) h7 l# e, j
}
1 l( N0 y& B: [else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)) R% U8 L" \* t# \. e
{. x* ^% K) ?2 o: d! M) y
$ I" e# B8 u% r3 Y' a: z
i=(*memory).p[0].ioNum;1 d. ?$ I. L' W
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
( U+ n9 U+ i+ z2 S& Q; V{) W! n9 F& y9 i$ X' u* @5 R3 T) Q
(*memory).p[0].flag=computing;( c' z/ o! M7 W+ O5 ^# L8 P+ _
(*memory).p[0].ioNum--;. |/ f1 J8 j5 e# B3 z0 V
change += exchange_IO_Compute;
3 O# o. B1 a$ i4 f/ w# gwaitio++;( o' m M0 G& F0 F3 m
}% I( Q% k7 J' K; o. w4 O" r8 Y
else' l5 Q# a5 }6 M' S4 C- Z1 J
{
: n1 E8 O' i) } B7 l5 twaitio++;' l2 d" m5 g; h, A1 P& ]
}! h s* \5 r& T6 x8 R
}1 z# e. V/ J3 V8 w
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing) x. p8 d+ f9 v6 j
{
' _1 T1 u6 P/ A- `0 @(* memory).p[0].flag=IO_waiting;
- F$ S( \0 b0 Achange += exchange_IO_Compute;
0 ]3 _' ]( ]9 C" {0 D) v* Y}( o; x( a' O( H3 G N1 t
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
! [( I7 r8 j3 P- h$ ~9 O L{+ w' M/ D! h y4 Y3 l
(* memory).p[0].flag=computing;
3 ?3 @$ e" V- w$ t. c4 k1 F# h7 \; L5 Schange += exchange_IO_Compute;
) h: m: a9 ]4 Z. r}! l) f9 i7 t# s D
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成( ]1 t( t& |" [8 W9 y7 Q+ {- j
{
8 O0 I5 C' o, r(*save) = (PCI*)malloc(sizeof(PCI));$ p. l& B o* w# B u! I. z% E0 I
(*save)->next = NULL;: w4 t& n! Y; A# O0 ~! d5 U$ m
(*save)->processID = (*memory).p[0].processID;
7 J: O( M5 l5 b9 _(*save)->comeingTime = (*memory).p[0].produceTime;+ E4 I! f9 X" h6 O5 o
(*save)->askMemory = (*memory).p[0].askMemory;
" [9 ~+ m$ ~1 M- X# U5 g9 b! q(*save)->compute = compute;! k2 F: ~: U4 W6 j4 i$ F K
(*save)->waitio = waitio;' X8 l2 l5 A. |! ]8 }! o, [6 ?
(*save)->exchange = change;
+ h, k/ M: G" w0 s; A1 {: x(*save)->completedTime = systemClock; t4 s9 d/ S s+ W
(*save)->runningTime = (*memory).p[0].runningTime;7 m. G, L, {. O2 x! l
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;3 a6 X& ~& @6 v$ n' o2 z
compute=waitio=change=0;
6 m* f6 w4 x& @/ a1 Z/ f! BcomputeLast=waitioLast=changeLast=0;8 u$ m# y, P$ b2 w# t- ?
Priority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
- g( p& i; m9 Zchange += exchange_process;5 p0 Y6 N& P) I) U5 |: J: q
return task_completed;) x7 M- m v9 R$ i/ S, g* i/ M% i3 ?
}
: g. n0 N |$ A: Xelse
5 @5 t7 M' j! [9 ~7 Ereturn task_not_completed;
5 S! [/ V- }% h$ [ a. ~8 C}! B' S$ h$ A4 L2 g
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)/ p( j, |, H9 o- F9 A# Q& u9 q
{
/ h. C! K0 t+ Zint priorityNum[initProcessNum],i=0,j=0;
! d8 z4 J' }; \double temp=0;
9 d5 C# O. L, ^/ s8 E) B+ ]for(i=0; i<(*storage).proNum; i++) // setting priority to each process
Z5 C+ a; d9 y) |. Z{ \+ M! Q, z/ R8 m
temp = (*storage).p.computeTime/(*storage).p.ioTime;
9 S* v" X. A- X) M: d7 p# }if(temp > 0.8)2 b8 G& ~0 ^& Z8 c0 A' {% \/ {
priorityNum = 6;5 o1 Z* o5 [/ p8 q$ X5 @
else if(temp > 0.7)
7 `% T4 ^! w. L/ p ~priorityNum = 5;$ ^) ~) {( a1 ~' a3 o) `, |& z. a
else if(temp > 0.6)
7 R/ H N, B |. I7 ApriorityNum = 4;) J$ D! V0 c: L2 V* g5 s4 |! ~6 |
else if(temp > 0.5)
* L9 ^2 ^3 Q- ApriorityNum = 3;0 ~( T. q: g. l/ ^* [8 F" L% Y
else if(temp > 0.4)
& ^; O9 w6 F7 x4 g% s* vpriorityNum = 2;) V$ X4 D& `+ e) p0 p( C
else* U# I5 f0 m# i+ @
priorityNum = 1;1 E* c8 G' n2 Q
if(priorityNum[j] < priorityNum)2 c: n5 {5 v# d @: C! g5 e! i$ y
j = i;" t5 V) P8 J. n
}. Z/ v# m9 A) v) G9 P2 p9 B
if((*storage).p[j].askMemory < *spareMemory). |6 R" E$ h- R% v/ A* k
{+ {8 B; j0 Y' @6 Z Y' ]% N
(*memory).p[0].askMemory = (*storage).p[j].askMemory;/ C/ a0 b# P4 ?
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime; o# r' R# H; W/ b
(*memory).p[0].computeNum = (*storage).p[j].computeNum;
/ P: C8 q1 M& M- Z! d(*memory).p[0].ioNum = (*storage).p[j].ioNum;- h2 h' k& w0 W) ]( B
(*memory).p[0].processID = (*storage).p[j].processID;
7 M& Y% B4 y) e3 y3 g2 [3 u& b, |(*memory).p[0].flag = (*storage).p[j].flag;
& x; z$ J- x+ P5 z/ C6 ?0 e: M(*memory).p[0].ioTime = (*storage).p[j].ioTime;
, w d/ E: a0 L1 o8 n& F) z(*memory).p[0].computeTime = (*storage).p[j].computeTime;0 N6 _. ]6 ?8 w; X$ D5 ^/ n
(*memory).p[0].runningTime = systemClock;& a$ P: ]! F. c
(*memory).p[0].produceTime = (*storage).p[j].produceTime;
/ w; x$ a% y* D6 |4 q' l; N9 }9 Xfor(i=0; i<(*memory).p[0].ioNum; i++)6 G0 C: p4 U# I. W0 X) {* T- `
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
, v: J) g. D: Lfor(i=0; i<(*memory).p[0].computeNum; i++)
2 D1 G1 @6 Y- X/ q(*memory).p[0].computeClock = (*storage).p[j].computeClock;
5 I1 O @2 U2 |* s! z(*memory).proNum=1;& i* O1 a0 _' \/ m' ?
*spareMemory = *spareMemory - (*memory).p[j].askMemory;$ b' {# U/ K7 c2 t" T; L
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程8 ^6 V) s6 Z& I
MAX_COMING_TIME = (*storage).p[j].comeingTime;
1 [6 F1 q; E3 }; b& r$ j9 D}
" P, n( W) m/ }/ _1 Y$ }else
# Q- J1 P4 P7 U% E9 ]+ c: P9 Q{* V" h# i# d$ J4 a- r H5 q
printf("A process ask for a memory overed the system capacity\n ");
$ i, ?9 G$ V$ T. G2 _ pexit(1);: v0 }9 N5 a0 |- T
}
. g" o; ]' O4 r! S1 Greturn 0;
+ Z1 Q2 z# X9 {/ c2 w! _}
& ? }+ W- F/ Z9 J. Z5 ^7 r% hint ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)$ E2 _; N+ |& W2 x
{ n$ ?! J. \. A: g5 |
static int compute=0,waitio=0,change=0;
1 X0 j1 a' `! l |, |3 \ j+ mstatic int computeLast=0,waitioLast=0,changeLast=0;. W! f$ N* G* n; j9 U
int i=0;! ~' y& T. P+ p- K
if(draw==1)% } b+ q5 R& A3 F3 G5 q9 n
{
! H' Z8 W o2 M# F//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
. y, [3 T2 x8 t5 J6 vdrawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);' g: v$ M/ R, S5 {* D
* |4 q1 q0 F l0 q! ?) X( C
% v8 S& }0 Z3 _, G* `: g* L7 @computeLast=compute;: \" f# m* o+ r* q
waitioLast=waitio;
! u1 _2 K# G% }& `changeLast=change;4 i1 l: ^ ~' ] h' M
}
9 d/ }0 v$ U4 m% m! u/ m$ Lif((* memory).p[0].flag==ready)( r2 I. U& @7 m& j3 M$ K
(* memory).p[0].flag=computing;
x# J3 Q: D% `4 m& Tif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)4 C ]6 U0 E+ X$ h$ A! x, R
{/ E: o2 e r& z H0 k( U
i=(*memory).p[0].computeNum;
4 W9 X# J! p& C; K% |if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed) c" p5 s, H" c1 H9 @0 z. l
{
: Y6 m) D z# k, `3 Z4 Q& R(*memory).p[0].flag=IO_waiting;
, U3 d, x: q$ E(*memory).p[0].computeNum--;
, {; W) m- X/ o( qchange += exchange_IO_Compute;
M( m) Q7 v0 O& Hcompute++;
6 S% U ?1 X, }$ |}7 n. u; g5 k1 @% C6 y
else- f) m( U5 \4 u" P4 R- x* Y
{
" D/ Q) A! X7 Z4 |' F& Ucompute++;, p- z C$ @' [& K4 p" V
}' ^2 c f* ^9 b, m2 m
}) U" E* f" c# C/ ?
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)# O: ?3 A* v* Z( F
{
6 C/ t, B: X3 t& H
" j; y. \" z; A# o* e$ q- z8 ]i=(*memory).p[0].ioNum;& ^6 L# [/ E; C/ C! H
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
0 L2 [8 [, i H( Z4 X$ t{
" `4 Q% m7 l0 o: F; \(*memory).p[0].flag=computing;, r& K' K: K: V
(*memory).p[0].ioNum--;
' K; i1 C4 h9 k6 [7 D! }! _- ichange += exchange_IO_Compute;1 Z$ _, U/ _& T6 _* ~7 a
waitio++;7 t5 m( X. A2 w7 ~& U& H
}. [/ D. M) E% v4 q% [
else
( h: b" l n, w# q" |{1 y# o0 t d; O0 l
waitio++;
& @5 D: h1 A+ ]7 I6 W) |}
$ z9 |, i2 N" x; {- W* h* n- y2 M}
6 s$ v' U- G( Z* [else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)1 p) S, m, v" a4 G" U1 r
{+ [5 n& L) p1 L7 E& x+ a
(* memory).p[0].flag=IO_waiting;
5 [0 l2 _( J1 D) g) E4 {change += exchange_IO_Compute;
+ V3 n: o; d+ W3 V3 W}' Q! y6 O* R7 E% d) E
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)# V* y2 Q5 e# U1 Q2 I3 s5 y$ g
{
& o( S" r, y& B& Y6 V$ [(* memory).p[0].flag=computing;% b E2 j! u+ w5 l
change += exchange_IO_Compute;# l; s( k! @ p9 d6 r1 s0 ^
}; `5 u1 l# e6 G; i0 k
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成4 w/ ^) E' q# [. |
{
, B c/ H6 y0 L: i. d9 P+ I(*save) = (PCI*)malloc(sizeof(PCI));
5 R5 ?8 y0 h% v7 _ u(*save)->next = NULL;
0 @2 k2 q# p1 _/ M" [: ?$ o$ [(*save)->processID = (*memory).p[0].processID;8 m9 Q- P1 @7 L! i# W
(*save)->comeingTime = (*memory).p[0].produceTime;9 O1 O: M9 @' Y$ B3 w5 O" ?( a* V
(*save)->askMemory = (*memory).p[0].askMemory;
6 Q' T5 |& x K; y Y(*save)->compute = compute;# M* C6 Z9 n# b) A
(*save)->waitio = waitio;" o% w7 K8 h1 [
(*save)->exchange = change;8 g% y( \- T2 b
(*save)->completedTime = systemClock;) v# S8 o7 K# z) ]8 d: W
(*save)->runningTime = (*memory).p[0].runningTime; s% A: M' q0 |( X8 ]0 M
*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;
2 e" M9 h' s3 L4 \; N5 E) ycompute=waitio=change=0;
' j$ |$ S+ q" w: ?computeLast=waitioLast=changeLast=0;
! v! K6 s, U3 F w% D/ t+ P, @SJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));& i+ M' G+ T% S" J
change += exchange_process;
' n2 B) p! J2 K8 G( m- c0 E3 |return task_completed;
. W, g* W( D# n: D}
* [) i5 v. h" h! pelse7 S3 `; _5 u. I( E# l
return task_not_completed;
`0 s4 s) K3 C. _. k' i}
$ Z- {. X$ F" ^' B5 g% A2 \int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory); J3 Q; D9 ]4 \7 ^& T
{
2 C6 g, }" w: @! m+ r- t9 B' Z- b$ aint i=0,j=0;
& G. p$ A- M1 t4 e+ ^: Nfor(i=1; i<(*storage).proNum; i++)$ I4 X% r. o6 `0 ~' d2 I7 c- X
{
2 A7 B6 R- M+ x8 |8 Dif(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))
' d6 R" t$ j8 [5 a/ cj=i;
9 p- e% h5 _& f) o" I# K7 s0 P}. `! s1 p! I' v' V3 T, d) B
if((*storage).p[j].askMemory > *spareMemory)* J& U# p) T- I7 _! A
{
& O& t4 f4 s: R; [4 y# \printf("The memory asked is overflowed than the system memory.\n");
0 r: \5 M4 |3 f5 sexit(0);& w8 x: R7 n/ }* x0 f$ A
}
, w0 I8 i; n6 C0 D9 I( Lelse
& }8 f) u# |: d H$ B{
) V) J/ X4 R- d- l& |; c(*memory).p[0].askMemory = (*storage).p[j].askMemory;" y" A: |* v0 I0 `
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;. Y; q3 u3 M* a4 D
(*memory).p[0].computeNum = (*storage).p[j].computeNum;+ W# \" Y$ C! u9 r' @; b3 ?. c
(*memory).p[0].ioNum = (*storage).p[j].ioNum;2 c R* z0 h6 _( l) u) E
(*memory).p[0].processID = (*storage).p[j].processID;1 X2 w- s' y6 _$ o' E w
(*memory).p[0].flag = (*storage).p[j].flag;
( C; k, {0 t+ }) t7 D8 H! s7 L(*memory).p[0].ioTime = (*storage).p[j].ioTime;* K1 p2 j( a `$ A1 f& j4 A
(*memory).p[0].computeTime = (*storage).p[j].computeTime;
, ~: b; h: L- Y+ y/ o/ d2 H(*memory).p[0].runningTime = systemClock;
0 U$ P7 _+ W1 g1 y(*memory).p[0].produceTime = (*storage).p[j].produceTime;
* I5 D. }. ?# y4 T# Kfor(i=0; i<(*memory).p[0].ioNum; i++)7 ?4 e, i7 z# p8 x' n/ F0 }
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
7 d+ k$ P6 K& M2 x: Y2 N6 b6 Afor(i=0; i<(*memory).p[0].computeNum; i++)! Q5 S% P; n, ?9 j+ E6 N
(*memory).p[0].computeClock = (*storage).p[j].computeClock;$ u; F* Y) j) |- R( Y" X
(*memory).proNum=1;
% R% h; z$ |0 e, t5 p*spareMemory = *spareMemory - (*memory).p[j].askMemory;( I3 F. \( w: I* Q' x
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程 ]' T2 C9 P, r& }
MAX_COMING_TIME = (*storage).p[j].comeingTime;
$ h; d( A4 a% `/ ?4 p}
( x# \% m0 S) f" o3 Y0 ]" T1 Nreturn 0;
7 }# D( B) u& v" C1 Q, z# K( d}
5 y# U. P# V |7 T( b; i1 I" b$ jint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
$ D. c! ^' S. S4 S5 s' {{
, N1 ~, @; }0 Ystatic int compute=0,waitio=0,change=0,clockSegment=100,poi=0;. j6 C4 h8 F/ [0 g; Z9 k- D* H9 h
static int computeLast=0,waitioLast=0,changeLast=0;
% {1 F5 i4 ~4 |; p2 lint i=0,j=0,k=0;! h! V3 S3 s6 M: ]. _
if((*memory).proNum<=0)
, m1 B; h6 F4 s( jTimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);
' }) _7 m# Z8 ?" tif(draw==1)
/ A, x4 O$ w( l0 C% \4 ]{ v8 a" w% h. p, V1 _( C2 b, }
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);" `+ z6 X b5 j$ v0 z! ?1 N$ k2 h" O9 C
drawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);' O8 h3 e1 N+ e" _' e, h
0 b' W% p8 k! U
1 o2 O% S: k- R# _; N$ H2 F* `computeLast=compute;
. g8 _. S6 M8 U2 VwaitioLast=waitio;
5 }" q1 ^5 K& D1 B) DchangeLast=change;
/ m' p9 {5 V) S: e}5 g" M9 c/ B' Q0 k
if(poi>=(* memory).proNum)$ s2 Q% H& f% X% @! g- w; P0 w
poi = 0;
4 [! U1 j8 ^; l; n3 |; Hif((* memory).p[poi].flag==ready)# {8 ?. s5 ~. s+ J
(* memory).p[poi].flag=computing;$ p: z. g. ~/ \5 T6 M
if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)
B. |& F2 e" a8 N{$ t; H6 [5 W2 {
i=(*memory).p[poi].computeNum;( ]4 T% w! v) f
if(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed$ @8 A( D0 O# N' a' A
{/ T b/ U9 O$ w2 \5 e8 j8 U8 ]
(*memory).p[poi].flag=IO_waiting;& ?2 y( p/ a" Q4 d( [; o
(*memory).p[poi].computeNum--;
# O( f% b. H( Y( x; \; t* kchange += exchange_IO_Compute;9 `. D S( I: e5 u* c
compute++;
2 b1 ^- ~, }3 c, g. r0 I" @}
: ]; J5 w; E" F. R6 n. n7 celse
* O9 S& n: M" F' C{3 O( i' l+ U. @* Y$ h+ z. B
compute++;
+ N" d4 J& g+ x+ E o6 p}
% T: G0 a0 c. A, }: x}0 Y& [9 Y+ n+ D
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)
$ ?" I d3 E/ {+ H{2 R f& d0 n1 B4 P7 ~
, V4 R4 \) ]0 z+ H& i8 d9 d+ ei=(*memory).p[poi].ioNum;! k0 f" G; k: k2 x* l
if(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
5 o+ Y& R! l8 M) v( j a# q7 o{! Z+ x2 L2 l! l( S+ C' E
(*memory).p[poi].flag=computing;5 V5 A: l* o# [0 T3 x" G
(*memory).p[poi].ioNum--;
1 I. f+ a6 U# ]& P3 Y: \change += exchange_IO_Compute;
9 f- g% a1 m, u( i+ i- K2 N5 Pwaitio++;
' l! ?! ^% V7 L+ m1 B}
0 W8 I1 |& |2 pelse2 R# `5 R( j Y! Z/ c
{
* I$ f5 d' k, m+ i# bwaitio++;# o6 {# s3 H, ~- n; j9 }
}
* P1 J' x0 ~; s5 R! p4 n}1 Y. n' W0 ?, R! m4 p! K5 b' d& ~
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing); c1 K M k4 t8 b' \" ~) y+ E
{7 E* t# e, a8 D2 S0 l* u2 V9 i
(* memory).p[poi].flag=IO_waiting;
. x0 [% m$ O, p" a+ V9 C6 b1 ichange += exchange_IO_Compute;
B. Z8 U( x& w6 t}
: W3 p& w; j" Z6 R: Eelse if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)9 \( |* ^* D! b+ E, [ F
{
5 C$ b4 }* O4 N& G, I$ i(* memory).p[poi].flag=computing;
, s3 y1 x# O- r6 E* o. j5 k j% dchange += exchange_IO_Compute;
4 h H8 C) N8 ` N}
1 a& o& L& ^2 h1 ^for(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进
0 C7 [: v) f) d/ S{% Q9 e1 l' k6 x: E5 u3 k
if(i!=poi && (*memory).p.flag==IO_waiting): u& D% x3 [% e- e6 u% F6 u
{
! ?" [% W& i1 q2 d6 n. Xj=(*memory).p.ioNum;9 t/ X& n) O3 b" Y8 c
if(j>0)
! r$ \, M; u$ y. d7 e/ U{$ K+ E ]6 J* g, o) l
if(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed
0 T( @9 \& V$ u{
. o# Q4 i" a) V; Z4 K(*memory).p.flag=computing;
! Q2 F' B! C: y' Z9 `2 L(*memory).p.ioNum--;3 h+ E3 ]* Y e
change += exchange_IO_Compute;
# V/ _; ^3 G2 }9 ^}" F1 U! ?( o" h& w. D4 k' h/ X
}* W9 j5 c' w* ?
}9 b$ U8 P+ E! y
}
4 r5 i9 F ^! ^ ]- w2 @' tfor(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程
# W- ] b/ E" C: q{
8 A, c$ b& \9 mif((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed. s" ]/ p2 k* P; w( e" Z" w% o J
{
, O/ x# w* w4 e(*save) = (PCI*)malloc(sizeof(PCI));
9 b; o9 k ~. ~. a* S! x$ O2 ?(*save)->next = NULL;/ q* l# j- f% C$ w
(*save)->processID = (*memory).p.processID;9 U2 |. E' |8 e1 Y
(*save)->comeingTime = (*memory).p.produceTime;0 D7 A! Z6 j( n- i3 r
(*save)->askMemory = (*memory).p.askMemory;5 {$ r! s3 y O3 _, y; x
(*save)->compute = compute;
7 l" a+ T2 m# {% o(*save)->waitio = waitio;
! U+ b0 W' ]) x$ ]# _(*save)->exchange = change;2 b$ N2 r* q' `" e' g4 e
(*save)->completedTime = systemClock-(*save)->comeingTime;
, Y+ {9 ?/ t8 _+ x# p(*save)->runningTime = (*memory).p.runningTime;* g' t, W5 B! U! `+ C
(*save)->completedTime = systemClock;
; }3 I! t% g6 l ^; d( ]( M' R, v*spareMemory = *spareMemory + (*memory).p.askMemory;
* A2 E/ R! D0 c3 u# Ncompute=waitio=change=0;: `" ^3 s/ h$ D9 O5 ^) P( O
computeLast=waitioLast=changeLast=0;
" @$ B; _5 m$ e/ h+ j$ {2 m: J; Jif(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入! j' ?3 d, F+ R) w0 z
{
) X% l9 D' U5 A) E7 p9 Hif(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程
N! K% `# Z. l2 }{
' R0 N. _4 A' ^7 }poi++;
0 J& K; D! n2 I- [( T' e" } clockSegment=2000;, }4 j1 y4 K. ~1 W) ?# M1 g2 y, n3 B
}
' n: O! c- V o# B3 B2 w g}6 o' s* e" |- B! M3 U6 r: I
else //没有足够内存调入新进程) j, c b1 k! X1 O7 C' c$ |. f$ u/ l
{
) }/ S, B" G' _* C5 J; e) P |; Iif(i < (*memory).proNum-1)0 ]9 q+ R! o9 s# @$ Q, g( e
{1 _# A6 I- l; }0 f7 P! z" }1 j
for(j=i; j+1<(*memory).proNum; j++)
8 V+ j# [+ \" X: }6 V- ~{4 X5 ~6 }8 k. s1 w6 |+ P7 N
(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;
9 Y4 U8 w8 s B" J(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;' H" o8 {. R9 a; ]8 n
(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;
3 \7 D1 c: N' h" f) B) ~8 D N(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;
9 M. Y- S* a, R# ?(*memory).p[j].processID = (*memory).p[j+1].processID;! z7 B$ z' d, H( V
(*memory).p[j].flag = (*memory).p[j+1].flag; Y* O, _3 `3 K) R3 r
(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;
8 l8 w/ k7 ^! I) b1 ~(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;
$ w& M# V8 Z7 } m% @(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;% d( t) D6 N- f+ A1 }$ ?
(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;; C: M9 `& n+ S$ A( g
(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;
; Y% g5 h1 C7 p% e$ cfor(k=0; k<(*memory).p[j].computeNum; k++), ^- A( J+ B) O6 r. l& a' K$ {3 G- ]
(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];
* h2 G+ X2 W7 S4 M; E! Pfor(k=0; k<(*memory).p[j].ioNum; k++)# K1 G7 ~5 p. ^4 M
(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];) ~/ K1 i. i+ j& E1 C
}* R! `8 m' ?# m# \4 G
if(i<poi)
6 J2 w$ o7 m1 y0 mpoi--;
+ W9 y9 v; m+ S+ Melse if(i==poi)8 s; }* D+ J7 a; U
clockSegment=2000;
: g \' D$ B3 T+ a4 n}
, U: G6 O$ J+ ji--;4 B- i9 L" s. m
(*memory).proNum--;
: s' W7 D! @6 |}: G+ {, F4 h5 {# G# k- W0 L. u) W
return task_completed;
9 V! k$ \9 h; m5 S& n: f}
6 ~5 S; F& Q" }" j- _+ m}
" z) P& S( Y( {* h# v1 `3 y--clockSegment;- t7 j+ V' o% m& l5 R6 a* V
if(clockSegment<=0)
4 G0 \ c7 L* {{
( R+ i! P% w) C3 e* D1 Q5 h' Epoi=poi+1;! S; ^7 E( A. O6 m% X: v; f
if(poi>=(*memory).proNum)+ _, k- I1 R1 `' V$ F* ~: R7 N; g
poi=0;/ L$ g; T$ `; ]1 b
clockSegment=100;3 Z$ a9 ]: \, Z4 g8 ]! k7 E; E
}
5 s$ j) h! V/ {% E& lreturn task_not_completed;5 j- p" x! Y: D6 s s
}( s8 E" C! }7 l2 B! E% j
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)
3 b, M6 I( d0 M1 F+ g{
4 G- R/ o+ ~" D0 Zint i=0,j=0,k=0,flag=0,translation=0;
; A. F8 q, a J' D4 _for(i=0; i<(*storage).proNum; i++)
# x9 E' n( d7 M8 M; i+ [ [) K{/ K2 d0 x& s; Q+ F
if((*storage).p.comeingTime>MAX_COMING_TIME)
5 d7 y- m- S1 _: N9 ?" IMAX_COMING_TIME = (*storage).p.comeingTime;
4 F. [/ t! a( W}, M, v! c2 L& \: q0 z' n1 k% H
if(pos>=0)
" t L6 r. W- U+ _{$ Q5 p, Q; w5 o5 n I
for(i=0; i<(*storage).proNum; i++). @' W+ m& F% G+ f/ ]% l' H
{
) H, l! Q7 Y* yif((*storage).p.askMemory <= *spareMemory)
5 c+ p/ \9 Y) J* U5 P% w( k{
9 S4 U# m9 {0 Ej=pos;4 r! u) U4 U4 g8 A( c4 Z) n& M
(*memory).p[j].askMemory = (*storage).p.askMemory;3 Y1 P9 F. k8 T9 K4 _4 t
(*memory).p[j].comeingTime = (*storage).p.comeingTime;
- [/ ]& q3 T$ Z5 T! U- m5 P+ o- C$ ~" Q4 Z(*memory).p[j].computeNum = (*storage).p.computeNum;- M4 M3 S9 Q/ p2 o
(*memory).p[j].ioNum = (*storage).p.ioNum;6 S% p* i% K1 q& B
(*memory).p[j].processID = (*storage).p.processID;* r7 @# l. i4 J3 s+ O
(*memory).p[j].flag = (*storage).p.flag;- z) p, L0 ]0 Y
(*memory).p[j].ioTime = (*storage).p.ioTime;
1 K9 ^1 |# r: V(*memory).p[j].computeTime = (*storage).p.computeTime;3 s; r+ }% \; K, P" X* n5 g; t
(*memory).p[j].runningTime = systemClock;
) a9 n# H0 H- j1 I* D' v(*memory).p[j].produceTime = (*storage).p.produceTime;( c4 l; M4 o8 w; [+ Z# [- v% S
for(k=0; k<(*memory).p[j].ioNum; k++)
+ o/ A4 N$ N/ a5 }9 {(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];" W, b: ?+ S# E# Z9 X/ j
for(k=0; k<(*memory).p[j].computeNum; k++)% c; z8 [7 ]9 B6 L8 l
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
6 @( Q) L' A& D! J6 `: H4 v*spareMemory = *spareMemory - (*memory).p[j].askMemory;
! d2 x) x3 Q; Z6 k+ b9 }produce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
( l& _7 s9 `2 n, b5 YMAX_COMING_TIME = (*storage).p.comeingTime;- c4 w. O+ c, \
translation=1;
8 Y* \4 @5 l: a( G. \break;
' | s9 t8 ^9 m2 X) y}
* E, |1 {7 K! S+ K+ W5 M( s3 g' ~}$ Q2 F8 l7 m* {9 s6 @" g/ C
}
- i# d4 Q- L$ O- e, {else
$ s% u l: D$ w4 B{! N" Z, F7 F- y5 U2 f
while(1)
& f7 o) g, e9 S; s9 C+ R. A" F{# |- N/ T% f! T! e* J( V, D- e
flag=0;
* y, q. i1 E/ i8 Afor(i=0; i<(*storage).proNum; i++); X+ y( G) r) G% \$ {( e
{5 x: M8 E2 X! y
if((*storage).p.askMemory <= *spareMemory)
3 n3 c* v! W! k" Y/ y9 |{
, B% g4 l! q$ |: bj=(*memory).proNum;
% x5 t4 g' h, l, s& @+ R(*memory).p[j].askMemory = (*storage).p.askMemory;: w( P0 u! [- q; C4 p
(*memory).p[j].comeingTime = (*storage).p.comeingTime;
" ?8 @" C& {# s) [) N(*memory).p[j].computeNum = (*storage).p.computeNum;
' c% b! q6 t0 f8 ?$ P' q9 H+ n& d(*memory).p[j].ioNum = (*storage).p.ioNum;. J3 G. Q2 `2 I) C
(*memory).p[j].processID = (*storage).p.processID;
- }, y: G! I3 |# w' T(*memory).p[j].flag = (*storage).p.flag;* o( ?' g _) O$ y- E
(*memory).p[j].ioTime = (*storage).p.ioTime;) W7 S" S: t8 l# ]9 v
(*memory).p[j].computeTime = (*storage).p.computeTime;9 t% G% O: u8 s- [: _ x0 w9 n" {2 L' z
(*memory).p[j].runningTime = systemClock;
! X# X4 n w9 S6 L# e* P! V(*memory).p[j].produceTime = (*storage).p.produceTime;9 |* b8 p! a1 ?+ ?8 q7 j4 S
for(k=0; k<(*memory).p[j].ioNum; k++)& S: u! a( u) w; j; q9 l8 \
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
0 s& [* b( m* [3 V1 J* Kfor(k=0; k<(*memory).p[j].computeNum; k++)7 V$ S4 M) F: i$ V( `
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];3 m% x& u0 Z: K
(*memory).proNum++;
& J1 H" E+ {9 q. M*spareMemory = *spareMemory - (*memory).p[j].askMemory;/ G1 u @0 |1 v, Q
produce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
' H. e$ j. L0 nMAX_COMING_TIME = (*storage).p.comeingTime;- ?, I5 d$ ?! Q, t% W
flag=1;; P8 \; q/ V' V/ @
translation=1;0 |* ^ ~ S' c
}
) H- q2 E5 E8 h' n2 d}
9 S6 [/ Q6 `! H; s3 Nif(flag == 0)6 r. D$ [+ u) z! C: r: F* l {
break;+ Z" Q0 f3 r2 q2 M) O9 b$ n
}
9 q% V Y6 x2 p0 s5 w}! w$ e2 r; [. K [/ \* n6 D, B
return translation;3 M( @7 O6 @0 K7 b" N. x2 |" C
}: I1 n4 o; ?1 b9 W$ d
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)
3 `( V- U0 ?0 v B: n) f{
- V3 z8 t$ {6 F7 ?1 q7 V# @static int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;
0 p) r; [9 }4 U* g. xstatic int computeLast=0,waitioLast=0,changeLast=0;
, ?5 E" _8 q6 s4 G" q4 [( a, Gint i=0;- g! B4 c2 q! |
if(draw==1)
0 W) P$ p, h7 Q- s{3 m$ D" G4 q1 H" k7 J7 x* {
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);1 o5 G, n4 {) L* f) Y$ G4 U- z
drawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
3 R7 l3 ], O0 m$ B( y7 P8 f1 \: ?2 b0 F& b+ D O
4 f5 ~# c4 I$ ^( [- r0 C6 HcomputeLast=compute;
, G( a7 b6 o" v4 W. dwaitioLast=waitio;% M; e. V$ N1 E Q! ]
changeLast=change;
$ i* b( t$ M+ @( P2 l7 j3 U0 G9 K7 z}* m/ q, Q8 v% d
if(flag==1) $ k+ c: J6 C# j3 F; y& j8 I! |2 p
{% j2 v6 R) t' B. [
if((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed
0 E# t8 {+ J5 E+ o6 |0 U( n7 P{$ B1 D' {2 u: E0 s9 F9 ~
if(flagiocpt==0) // implement compute
' h0 V6 ~( `3 x5 a; X+ t' X2 [{
# H% m- S/ g' i& gi=(*memory).p[0].computeNum;" H& R" X* m& e
if(i>0 && (*memory).p[0].computeClock[i-1]>0)
6 l, M' S$ J$ ~* H" f! F% u6 H{
$ A# F4 E. f0 j7 N) z9 J3 K+ M4 Gif(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed
$ a! y) g0 K4 O4 I. ~. G1 c: }6 T7 t{$ c9 J9 x3 h, `' I
flagiocpt = 1;# K* I; |8 j/ n' m0 x
(*memory).p[0].computeNum--;
& a g: W+ d$ f) J6 q5 h9 G: {change += exchange_IO_Compute;* E- K E! Q4 { K9 u
compute++;
' [, K4 y2 b) e& H" g}
n3 ~9 s, s3 [. I# c+ melse
: S I' Y' Z5 {1 P2 S; Jcompute++;
. S% u! e( J$ _$ `; U& y
2 |! d1 O7 u$ L* r: g- I}1 G! f/ T5 Q) ?9 }) G
else
1 T4 f" {: f0 f s* z8 Zflagiocpt = 1;
5 B' d! B9 X3 T6 A6 [}; U3 z7 h6 q6 O+ G% L
else //wait io
* G. a( n3 P: m{
+ Q0 j$ O+ M; s% {' Li=(*memory).p[0].ioNum;
. C* R9 Q9 j, X) F8 cif(i>0 && (*memory).p[0].ioClock[i-1]>0)
; A) a+ v* _% O/ T" r" J{$ V# u- R6 S9 Z5 p; M( C
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
1 d- g. p# r/ L3 j{$ ]9 e7 [* t' `; m# n8 t9 a
flagiocpt = 0; R. }* H2 s: F
(*memory).p[0].ioNum--;
* R; Z0 G. C% Z8 q' T G- Q- dchange += exchange_IO_Compute;8 \" @% X+ @% O) S$ K5 @) o
waitio++;
4 C2 f; K5 T' V. L& y- e}
/ Z* A+ h {3 h& G4 yelse1 W! O, }2 z6 S9 f: G/ h* Q
waitio++;
6 H4 a$ U% }) `- m, @- [
% G9 `4 q7 J4 L( A3 i}
7 O% ^8 L7 B9 c! x8 F4 [ felse3 Y0 O; j7 u+ D3 M6 F! b4 V
flagiocpt = 0;
* I% @: U- s# k1 U0 q2 ~/ c9 T6 _}' f& X, ?; }) g
} h# j; V2 S5 ~2 K! t; d
else //task is completed
0 _( A- w: |9 k6 o{
) @) z+ S9 e. {7 B& n" I% H" {(*save) = (PCI*)malloc(sizeof(PCI));
, ?+ m- ^ X% ?' Q( m8 u2 h(*save)->next = NULL;
1 _6 S; P" h6 ]5 Q (*save)->processID = (*memory).p[0].processID;; s& q: k( T2 U* C$ m* A3 ?
(*save)->comeingTime = (*memory).p[0].produceTime;( E5 L1 `8 Z6 W0 @/ S
(*save)->askMemory = (*memory).p[0].askMemory;1 Q, P7 L+ W5 b. S6 w7 M
(*save)->compute = compute;
1 K; P( m9 J9 O; ?$ s$ T1 H+ Y(*save)->waitio = waitio;6 I# C. M! o3 J* h& J
(*save)->exchange = change;/ @7 }2 K6 s- T4 M; ^
(*save)->completedTime = systemClock-(*save)->comeingTime;4 Q& E& H% S R$ [$ r
(*save)->runningTime = (*memory).p[0].runningTime;$ G$ M' Q3 ~4 @0 k
(*save)->completedTime = systemClock;
( {3 g2 _. E, y7 N//*spareMemory = MAX_MEMORY;& e6 {' S1 ~ E. t. G5 c
free((*memory).p[0].ioClock);
" N. {4 s& g, {9 R2 sfree((*memory).p[0].computeClock);
8 b& [$ w) S& B: jfree((*memory).p);) ]; C3 D2 x5 R# A; q8 h
flag=0;
% r& ]. M8 }1 Bcompute=waitio=change=0;
- J0 R1 V3 G/ A9 ycomputeLast=waitioLast=changeLast=0;
6 M5 R3 y1 s: M7 I' r f+ e$ {3 V1 rreturn task_completed;9 R# Y$ P9 g3 R7 C
}
]0 g' l/ Y' e4 ^7 O}
8 o, W" P* g& n v6 h) y$ @& ]1 e4 oelse
N% a0 S) h/ E6 i- q; e8 N{; k, N! e1 b: c& U8 I
FIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));
% J e8 n1 d& Y* s N, R# Achange += exchange_process;
2 j8 L$ Z9 Q7 l8 ]) x: U% n5 C//*spareMemory -= (*memory).p[0].askMemory;
/ J& f2 W) K4 S% x+ q1 hflag=1;. h- S$ R! B8 S/ | q7 i9 Z+ o7 u
//showProcessInf(*memory);% @' }& _5 D- j+ K: _
return task_not_completed;
- x5 Q5 e! L4 F1 G% u: K& [}
) A& a! P0 Q; G( ?7 ?return task_not_completed;
& z) @2 [% W/ ^7 F1 A" _$ O2 j}
! O9 d3 u4 w Q$ x5 Z* t9 p+ U6 Iint FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)
) }& q9 O* }/ \0 Q{
+ ~% R* b7 D. T% x5 b' L2 T/ zint i=0,j=0,k=0;
$ c8 p! e; y! y' F% |0 n- ?! TMAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;$ m, T. Y' \. ^3 j7 H) P
(*memory).p = (process*)malloc(initProcessNum*sizeof(process));3 h6 {" ]+ q2 N4 F. T
memory->proNum = 1;, r2 y' \& I8 k$ m2 ^
for(i=0; i<initProcessNum; i++)8 K7 ` Q$ D. l& S
{
+ U5 \$ F1 k: Z% t$ o9 d( Qif((*storage).p.askMemory <= *spareMemory)7 ?0 C4 p$ ?7 r. A& Q. d5 i( f2 p
{. k+ ~. p6 F$ n$ _
(*memory).p[0].askMemory = (*storage).p.askMemory;( {3 h) J+ P' Q
(*memory).p[0].comeingTime = (*storage).p.comeingTime;, \$ L) z9 j, M4 M8 z
(*memory).p[0].computeNum = (*storage).p.computeNum;
# ^8 @; F" i4 k7 E3 A! z(*memory).p[0].ioNum = (*storage).p.ioNum; v) {# U! M5 y, S9 C
(*memory).p[0].processID = (*storage).p.processID;: N: A) r& P& `; R2 l/ i
(*memory).p[0].flag = (*storage).p.flag;! W5 T2 V9 u/ i- k" V) N, c5 w
(*memory).p[0].ioTime = (*storage).p.ioTime;
/ l) x* Y0 X1 z2 A" y; w(*memory).p[0].computeTime = (*storage).p.computeTime;
, S: M* e! q# z% \% \(*memory).p[0].produceTime = (*storage).p.produceTime;
9 l+ K* g6 ^3 m5 S; z6 }1 r(*memory).p[0].runningTime = systemClock;
( ^ V. q8 u2 X3 t+ `& }) A! E(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));5 S' B" r( X; s- G) Q8 t" m$ b: K
(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));. A! |/ m5 q& y3 ]: P9 A
for(k=0; k<(*memory).p[0].ioNum; k++)
2 P8 l4 z! X& C(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];; V3 E1 w6 Q& Q
for(k=0; k<(*memory).p[0].computeNum; k++)
, j# k& V: U7 ?; J; h+ V7 @* G* B(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];
- B. K7 O Y. g4 M: O$ I5 gbreak;, o% o3 A, _) ~- u3 p: Y5 k0 F
}
+ ?6 r. t: o# ~7 A}; c5 s* W5 ?6 p5 y! Z; g! N
if(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入
. l% H7 L% f& b; ?2 E' {: z{
2 i+ n" _! P$ j0 @produce_one_task(storage,i,ID_FIFO++);' n# z/ o: Q0 y+ v7 s! `
MAX_COMING_TIME = (*storage).p.comeingTime;
& ?; S, A" l, {' P( H$ }! ysort_by_comingtime(storage,i);& o; @: x: X4 L/ S' @) ~
}
4 \( i; z1 c4 k; F+ g, }return 0;
8 h ^ I# D5 u: e8 P. C, s' i}3 b) m, `) ?2 ~. V. i3 Y# s
int sort_by_comingtime(processPool * p,int pos)! @6 `5 F; I7 F% t0 p9 H C! `
{; [& O# Q( I1 t3 C4 M( Q
int i=0,j=0;. m$ C/ E. q/ t+ H' u8 g- t/ K* X
process temp;; h+ W& D2 e2 `) y2 l5 J
if(pos<0)+ _4 ?8 Y" p9 i$ W/ V( }8 R
{0 H4 y5 j% T4 n" x# U0 P( c2 G/ i
for(i=0; i<initProcessNum; i++)
9 `: [0 c4 Y+ H& M1 @4 U8 r. R8 hfor(j=0; j+1<initProcessNum-i; j++)
& t9 i4 d+ d" U( U0 Y{% [. i- b4 H% D/ B* z
if((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)6 [5 j; ?" W6 i( H( g' }; }
{
8 e* i$ y3 J! u8 J: Ntemp = (*p).p[j];
0 Y: h+ p# g+ |* W9 d; I( v(*p).p[j] = (*p).p[j+1];5 z1 }8 }* E9 t% L( G
(*p).p[j+1] = temp;
9 w5 T& D0 n% U ~}, `# U0 w3 Z ]) {
} c2 G5 n# ]1 V# r; s9 m
}# e& p/ y% T2 p' _
else if(pos<initProcessNum)1 k8 X, H, u) |2 k9 x: Q; {8 [, Q
{: _: h+ m9 b1 m4 f
for(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)
; z. O. @' L+ K# ~' v7 R{5 S9 z, H; j6 f3 X$ ~
temp = (*p).p;; [* h; n& G; I! a+ p7 R* o
(*p).p = (*p).p[i+1];# V8 o2 k+ }' G& ^
(*p).p[i+1] = temp;
, e X7 V" b$ z1 Y) N- x! w}
* w% S+ g0 p- s. y9 bfor(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)
: P" K, \5 O J" X+ i. J{
2 d2 a4 I! r( w. P. c9 Otemp = (*p).p[i-1];; t' c5 R6 b1 U
(*p).p[i-1] = (*p).p;
# v9 p. z2 }2 \: ^! ]8 R(*p).p = temp;
% i% u; Z" D4 a7 I) t( s; {}
7 Z; O' F {/ s Q5 {+ L" |}# c; F6 z; `( w; `' x4 N& M
else K. q6 M! i3 U8 |$ M ]
printf("position eror\n");
! f' h: X& h7 r# m/ f: ?return 0;
) T, B+ L5 `- i}
T$ x* \/ i; _6 a& Oint InitPool(processPool * p) t' o" J# _4 F) h3 g
{( v( G% K, C f
int i=0;
; O8 j; W# Q0 d8 I. F(*p).proNum = initProcessNum;
. P& C0 p- b E(*p).p = (process*)malloc(initProcessNum*sizeof(process));
& _1 T2 q5 T0 t6 \( [; z) mfor(i=0; i<initProcessNum; i++) //init process information7 l! v k4 W T1 H% F
{# \+ `' N5 Q+ t
(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));. o1 g2 K+ i: n/ u
(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));
3 e. u! j2 f2 A) C& _produce_one_task(&(*p),i,ID_FIFO++); X2 p) N8 V2 i$ h
}2 y" o. ]1 b, i" M4 S; B
return 0;
7 I- O/ H& z; c) C. M2 j' K" x}' r9 U3 U. o) q
int produce_one_task(processPool * p,int i,int id)( @$ k) U( j2 f$ m
{7 D/ R; B7 g3 B% v) z+ T
int time=MAX_COMING_TIME,j=0,totallTime=0;5 k9 A7 T0 f! |7 w' t, B% v7 T
(*p).p.processID = initProcessID+id;
4 w4 f) u) x5 }/ O8 f(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);
9 }* {% b4 f: H# H+ ~7 \7 e(*p).p.produceTime = systemClock;
* S& Z" I9 }* B(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;0 P# y- X9 K, K
(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6;
' R' U" ? K3 O) J, MtotallTime = (*p).p.computeNum + (*p).p.ioNum;
8 s( B- \9 K; K9 N1 Y; g" P(*p).p.computeTime=0;/ m) Y5 _2 _7 X6 n
for(j=0; j<(*p).p.computeNum; j++)
/ s- W9 j3 c8 [" @6 {, ?2 A{
8 q/ ?, i7 p) j4 M" z1 [7 ](*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;
2 @# v3 ]; k$ c( Q% y8 L(*p).p.computeTime += (*p).p.computeClock[j];/ [2 U9 W0 f& O5 J+ t: T6 m2 |
}# e2 |5 Z) f6 z4 L8 c7 D& F0 G# C
(*p).p.ioTime=0;% M' k/ g1 A- }) a3 |
for(j=0; j<(*p).p.ioNum; j++) |
|