- 在线时间
- 1630 小时
- 最后登录
- 2024-1-29
- 注册时间
- 2017-5-16
- 听众数
- 82
- 收听数
- 1
- 能力
- 120 分
- 体力
- 564650 点
- 威望
- 12 点
- 阅读权限
- 255
- 积分
- 174618
- 相册
- 1
- 日志
- 0
- 记录
- 0
- 帖子
- 5313
- 主题
- 5273
- 精华
- 3
- 分享
- 0
- 好友
- 163
TA的每日心情 | 开心 2021-8-11 17:59 |
|---|
签到天数: 17 天 [LV.4]偶尔看看III 网络挑战赛参赛者 网络挑战赛参赛者 - 自我介绍
- 本人女,毕业于内蒙古科技大学,担任文职专业,毕业专业英语。
 群组: 2018美赛大象算法课程 群组: 2018美赛护航培训课程 群组: 2019年 数学中国站长建 群组: 2019年数据分析师课程 群组: 2018年大象老师国赛优 |
: s: e) \) I, H* `9 P% f' Y `* V
经典任务调度算法的模拟程序
5 p, M" X. Q$ v# C本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。2 P$ u+ [$ Y% {. ?* ]/ y
6 q: D# m7 i5 ~' ~$ B编程平台:VC6.0+EasyX图形库环境。" g$ A! K( T& {% p0 q
& n; t* Q% S( |: u* z8 p. q4 \
以下截取部分程序运行图::
1 |8 N$ \: S2 ^6 ~( x1 D) v
@/ x2 v: w, ~& k$ p源代码:! v+ y' @( s* D" F2 [: W& V
( \) O1 \' u& f j+ i$ o1 R- E% ]#include<stdio.h>4 m* s# q! W3 \
#include<stdlib.h>
6 G I8 R, s$ ?#include<easyx.h>
2 ]. k, A) A) a. I8 F* B; J#include<time.h>9 S, ~1 G3 Q, m" j
#include<conio.h>- p1 e5 f8 D, i1 k4 ^) z
#include<graphics.h>0 m ^+ m% k. W8 w1 @: C
#define initProcessNum 10
5 y- s! B' l& J- W, q#define initProcessID 10008 L" _5 t! [0 O! L" D
#define MAXProcessRunTime 10000; @0 Q% Z& [0 O d" l# ~; O4 |
#define MAX_MEMORY 4000
! k4 `5 k' f' L7 W#define exchange_IO_Compute 10
+ E% Y9 i7 r* y' |#define exchange_process 25: B2 ?: S) Y7 p5 A
#define task_completed 1
1 r" g) o4 Y$ N0 _9 N' a#define task_not_completed 02 q( W, w! w6 n# Q& x
#define initclocknum 100+ V: ?. M8 @) g! h- l9 ]9 i
enum condition
' z7 N+ r+ Y# ~( }; n{5 ]4 T- u* L% y% Z
dead,computing,IO_waiting,ready! l1 R" X( V, [( ?8 H: W+ {/ O
};
; D0 o$ V% D1 s, q$ G8 _6 V9 F ostruct process/ r0 F1 @/ g- p) \8 K4 Z8 `5 I) h) r
{4 n/ Q) K5 t* \! ]# O" h
int processID;
; E& r3 p& e! T& z1 [, S* nint comeingTime;
+ T1 j& |) x, ]; ?4 z# C6 @6 `int ioNum;6 N+ ?3 J% ?- h
int computeNum;
% ~% F, M9 p3 E3 Q7 P; K: Eint * ioClock; L5 L$ {9 p! W% v
int * computeClock;
+ \% }4 s8 n* U) `6 cint ioTime;
- w9 I3 Y' L5 O8 W# lint computeTime;; u; ?- c" d# V! s+ V- }
int askMemory;$ A, X" Z q6 }) t7 p. Q9 J
condition flag;
% u& r2 p# e$ h/ K) x( p0 {int produceTime; //生成时间,以下三个数据成员用以计算相关性能
! D; [! _2 n+ ^* D% h: `/ Wint runningTime; //第一次占用CPU的时间6 z8 b6 e' f0 G0 U9 h7 K, o
int completedTime; //进程完成时的时间: T1 f. z8 n$ ^$ h/ m
};5 `8 I4 s! L3 J- f+ i- T! f D
typedef struct processCmpletedInfo //保存完成一个作业的相关信息
+ P- [5 h( T" ^{9 Z I0 o; z5 u p0 ~9 l: v! X# u5 W
int processID,comeingTime,askMemory;
/ M$ V- h8 H \' {6 Y& mint compute,waitio,exchange,completedTime,runningTime;7 N( T; B9 S" o5 _$ r v
processCmpletedInfo * next;& |1 [, d9 y7 z8 v0 v
}PCI;' k, d. P6 c4 o4 R
struct processPool$ t, e% z+ g0 s+ y; K! ]: W( f
{
6 |! g0 Q+ C2 z! N1 Q# hprocess * p;/ h7 i2 `1 {; ]% t' H
int proNum;
# @. R4 y* l( d4 Z1 ?% m) e};
1 S0 R+ w$ y& h- c5 dint 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;
- C# j( R" P: |1 Z: \+ s& c' Eint InitPool(processPool * p);! f& u1 s3 o2 ]( L7 ?5 C( o
int produce_one_task(processPool * p,int i,int id);
8 x& L; \: P. D* a% bint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);
( ~& S( c9 J0 J% C9 tint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
3 }) A" b& T: M5 K0 J" Qint TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);4 T4 g0 `$ V' D% l) J8 n
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);- k' Q W& ^4 h" Y9 L
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
( G+ f3 R2 w2 l* ^+ `$ [' m$ Oint SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
& ^3 @, Q& e" i) _- q1 xint PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);0 g5 D {/ A/ ~9 S* B
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
* `9 F$ z: h% T) iint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);
$ {; b8 U1 ^8 Q% i1 y Mint High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
* B" u0 y! J+ N! D6 S/ f$ R5 g! [9 J+ H2 o, e# J6 }6 s" s0 @
3 d( b5 V7 Q i9 d7 S4 S; \int sort_by_comingtime(processPool * p,int pos);* q& b; h9 x7 p5 l: X
int showProcessInf(processPool p);
1 z, N6 x4 j0 T9 h+ Eint drawPerformance_FIFO(int x,int y,int memorry);0 @' H3 Q3 C0 R. V3 x: i! ]& r
int drawPerformance_HR(int x,int y,int memorry);4 l' I. r1 [/ M$ B, s1 B! t
int drawPerformance_PF(int x,int y,int memorry); G/ }1 E7 `8 n4 y; ?$ H
int drawPerformance_TT(int x,int y,int memorry);' j$ \4 [$ U5 \0 O+ j) y
int drawPerformance_SJF(int x,int y,int memorry);+ c& _# a r* n \" Y
int MouseListening();% c9 d, y: A- W8 d" T
int MouseListening2(int *flagShow,int * showTime);
E9 ?* D0 n5 T* iint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);
( w+ i+ F3 l s1 p& |
1 S- K! f/ P1 q: Q* j# S$ p# j+ h, Z
void main()
) a4 a( c1 E- ?+ B{
8 V5 X) c5 ~* n' l/ d7 rPCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,) w. i- w8 [9 a
*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;
0 b, O. F* w" z* o) T3 Pint i=0,FIFO_memory=MAX_MEMORY,count=0,Timet_memory=MAX_MEMORY,SJF_memory=MAX_MEMORY,Priority_memory=MAX_MEMORY,HR_memory=MAX_MEMORY,
( y/ |8 M! t; U) a. v2 a/ P: eflagDraw=0,showTime=100000;+ w8 _& M; S/ T m3 u/ g
processPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;+ Z ]% R+ G, N' Z" R8 M$ Y
FILE *fp=NULL;2 w; F0 A v4 B8 Z6 K7 S/ @
//processPool HR_p,HR_mmy;, F3 x$ U) V( z" m
4 f3 A0 v P% k& J
! X) A2 Z/ o2 w( R& J" t: ~srand((unsigned)time(0));
t) [3 ?: ^2 S8 |3 vsystemClock=0;
9 ?, o* u$ B) N( cinitgraph( 1200,650,SHOWCONSOLE );5 `0 C0 R1 ]- ^% K% K+ ~* Z: D, _6 ?1 M
settextcolor(GREEN);8 E2 c+ q% A4 K$ ]- F! P
setlinecolor(GREEN);6 q v/ f* H. E% U% K Z! Q# }
setfillcolor(GREEN);. c5 H4 k4 ]* W
InitPool(&FIFO_p);
# {& @; [" t$ {$ D0 w2 Nsort_by_comingtime(&FIFO_p,-1);* {2 `$ D i2 [/ P8 l ], R
InitPool(&Timeturn_p);2 ]; X6 D3 T8 W5 J# J9 T
InitPool(&SJF_p);
' J6 ^9 [. ~+ o# qInitPool(&Priority_p);" b1 \% w4 }, b5 T$ |4 ]' W
InitPool(&HR_p);
4 {. z$ W- d* s- U//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);& w% X8 ^2 k Z# n0 U5 b5 F
//Sleep(10000);, D+ n; v$ S# g7 T6 }; B4 q
1 k+ u# P: W7 E
* j7 X6 U1 Q. q- f: N
Timeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));6 f N3 L" x, L# H
SJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));& n. K# Y1 i0 y/ J
Priority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));1 C! m* Y) d' v1 L! `' w2 D
HR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));( q7 D6 L- }' K0 G! o
for(i=0; i<initProcessNum ;i++)' v: ]% D4 G- q* C
{
' }- p) R+ c* B) \- NTimeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));4 d: j6 J* M$ {) X
Timeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));7 m \" w a7 E2 m, A
SJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
c* a7 B2 ~* M/ z+ ]4 XSJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
' q4 J+ K. B, o: d6 l9 SPriority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));2 M0 [5 G9 P: M1 G! e1 m
Priority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
% N$ @3 p/ y e" h$ K* c* nHR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));; K4 l, b* q/ z6 H* x5 o
HR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
( r7 V- B: L* [. ?}
! _5 a: l9 y! h" I$ KTimeturn_mmy.proNum = 0;: ^, ~9 f$ @7 C) m
TimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);6 E4 e6 J; T( ]4 N
SJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);; o2 r- h" c; V" ]. k# W- t) F
Priority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory); v2 m! i! Z+ L3 g
High_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);& C9 W f, |8 P" }8 o. y
//showProcessInf(Timeturn_mmy);
6 h2 e( m2 z5 zFIFO_pri = &FIFO_save_head;
+ ^( [9 V. f% G: m! g# y+ w- S4 @Timet_pri = &Timet_save_head;# v; u2 a# i3 ~7 p6 C
SJF_pri = &SJF_save_head;7 Y* h7 r4 I7 G% m
Priority_pri = &Priority_save_head;; x( Q$ _3 K# g% b
HR_pri = &HR_save_head;
o9 ?4 d* {( c" C6 }, \' N. i" Psetbkcolor(WHITE);8 m3 \3 @, v9 k! F
while(1)
/ {7 h( F0 s9 ~ R{
8 _# c) F( g& }/ @: Zif(MouseListening()==1)
( G& Y5 P, ^3 S% l, nflagDraw=1;0 I& S* o7 W- B
if(count==100)
$ [9 L7 h9 q4 Q E8 N- \! D3 [{+ Q) o5 ?- Z" z/ G8 ^- X
if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)% z' U" m. n5 C5 @9 E
{, Y+ B: N0 N+ }! o3 q
FIFO_pri = &((*FIFO_pri)->next);
0 m2 x3 E. `9 J+ c8 j' c( `; \& X9 L4 B0 G
//printf("hello");3 A* {* c4 }9 v1 t5 E& s" i- _' |/ G
}$ |! E6 O! l3 v) A5 H7 {: ^' N
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)6 F2 \& w4 B9 k
{4 [# e5 P+ h1 j) K: C3 b. Y* Q. p) D) e
Timet_pri = &((*Timet_pri)->next);6 s2 O0 h' A9 \' E
//printf("hello");
0 t) M: |4 P |; E6 p3 e( U}
) W8 {! G. ^& G: Fif(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)
& E. _: m- U: [1 B+ p/ c& h1 Q{6 n1 o/ N) A+ X1 Z. o1 m
SJF_pri = &((*SJF_pri)->next);
D x5 l6 p0 C3 `//printf("hello\n");
# q5 N: F: _: a% a9 `! f) ?}
9 N% Q" _$ c7 J5 j" D: Z2 R- aif(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed)
1 R+ ~6 G$ k7 ^6 ]* P) p{
; [! a% K' g- A1 l5 }3 H6 W7 qPriority_pri = &((*Priority_pri)->next);
2 i; K m, h) X/ c//printf("hello\n");
* M* @8 p' F+ E}
$ g! o7 I& Q3 aif(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)
7 F9 g. f& M* B8 C0 D{
8 q2 @, Z, ^: h$ @5 NHR_pri = &((*HR_pri)->next);! e6 A$ a9 j1 o
//printf("hello");
6 S! P5 _# s7 q3 Q5 u}
0 i4 A: `9 Q9 |( `! Y( U* |/ Lcount=0;7 _9 c5 K" i$ v: H, t
}# L. A0 q1 \- a2 L5 d @
else) p; m1 O+ l+ n& Y) ?3 z
{2 W/ L. E: L/ m% s
if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)
* E$ A$ p% j9 _) Z! V{$ R, \! r+ q# V4 C3 o2 n; A: t
FIFO_pri = &((*FIFO_pri)->next);
# t8 B7 r' V' |9 [// printf("hello");* u# H# O0 z! F" S0 `* ^ z
}* c9 X0 R/ h' V2 u1 x0 ^
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)/ l; p1 \# g* @5 t
{
0 O* {- @. d* \! GTimet_pri = &((*Timet_pri)->next);
$ ?4 F" e8 L7 _9 j, w// printf("hello");
/ P) }' v# M% y+ H) J}8 q6 Z; G+ P+ D9 I" L
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)
) H3 [$ I) I2 n0 ]! f{) P6 l j/ P) _) y1 S9 x
SJF_pri = &((*SJF_pri)->next);
( K2 \, ^7 D4 f ^+ z0 W! ~9 R// printf("hello\n");+ H/ u- k7 Z! ~& F
}4 K8 S; |# u5 t# h5 h! P2 P0 n
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)
* r+ p: T! t6 {/ a x7 N" L{
5 o9 `* x9 t3 |& GPriority_pri = &((*Priority_pri)->next);
# T2 @( s6 n: Z5 O; }* j2 n//printf("hello\n");
) s' X4 I6 T$ ^$ C7 X4 q}. b5 B/ v* F7 w9 f! O! x
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)$ j- A7 W' [8 O
{9 [5 G. z: f3 t- R# D* r
HR_pri = &((*HR_pri)->next);7 X, ^$ h# K2 v
//printf("hello");/ \& R) P; y' f7 Y$ i" J3 O& E' b2 V
//Sleep(1000);$ j) a+ t" a& J3 j6 b" @% \
}% v; E2 S3 n% |/ f% J
count++;# a8 W: ]+ n0 z+ v0 S/ |( w
}
; Z5 G- C% q2 qif(systemClock==showTime)
* i3 A3 \# c* C{
' o; v9 E' r; s9 x- p/ B, P0 T/*PCI * p=FIFO_save_head;
: s' I0 D1 ~9 n; mint i=0;+ ?. X& s h; E
for( ;p!=NULL;p=p->next)
7 V* n' `. `* I) |{
/ k3 a; t8 D( d! L! z- Mprintf("Id %d\n",p->processID);
8 c5 U u% {$ k$ G7 ^: j( Dprintf("comeingtime %d\n",p->comeingTime);
. R# v* [4 y6 t q; A6 K& }printf("runningtime %d\n",p->runningTime);
6 e* g3 }8 n0 T- I2 U; ~6 c5 Lprintf("asdmemory %d\n",p->askMemory);
1 p9 W8 Z1 y) M& L0 o8 ^printf("completedtime %d\n",p->completedTime);
( @% ~- }7 l/ ^9 j2 Eprintf("compute %d\n",p->compute);+ |4 A: t) |" a) \2 Y
printf("exchange %d\n",p->exchange);1 J( e7 m2 M4 Q$ u! ?; C
printf("waitio %d\n",p->waitio);5 `( e0 }6 g5 M# T
i++;5 ^7 |3 {3 j* A! A
- _7 T. Y7 z4 k: G" E8 B" t
, j% K. W: _1 z& l: \6 b
}" j: M* h& P( ~9 q% L3 R" y
printf("%d\n",i);*/
( v9 t1 I! v$ @2 u7 l9 |) Dif( (fp = fopen( "data.txt", "a" )) == NULL )7 V u0 b# P: Q7 r
{& q, x# b' D+ a! Z8 F* b
printf( "The file 'data.txt' was not opened\n" );
2 D8 [9 j: w9 u) v6 F//return 1;
( N7 D8 m5 f& @0 F/ q}% X2 G, u% \7 Y; p2 H: e- D
else g( l6 Z9 a6 J2 q
{
. c* k# o* e) ]fprintf(fp,"FCFS \n");
2 y$ O6 Q% R/ u1 ]4 r' Mfor(p=FIFO_save_head;p!=NULL;p=p->next)
+ F2 p6 R( m3 N7 ^4 @fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
. ?. i. ~1 N) cp->exchange,p->waitio,p->runningTime);
+ [) o: J L* U% f; {fprintf(fp,"\nTime turn \n");
" X* t5 f. l y' q. L# t# |5 ^for(p=Timet_save_head;p!=NULL;p=p->next)% ^. ]3 `4 V2 N u
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
4 g; U! w, K' l4 R. A/ W: @, `( hp->exchange,p->waitio,p->runningTime);
6 E6 K) }/ X: @8 p, Y. k' k/ k% Gfprintf(fp,"\nShort Job First \n");$ u: U% e! g+ o1 G7 Q! W
for(p=SJF_save_head;p!=NULL;p=p->next)# y! ]6 S2 r% B: o
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,8 X; w7 d+ R+ e9 D v# A7 u$ k; ^
p->exchange,p->waitio,p->runningTime);
" b% j) g9 {, o0 G* {8 U; O* ~fprintf(fp,"\nPriority \n");1 y0 U1 p0 ~5 K' ~4 t' e
for(p=Priority_save_head;p!=NULL;p=p->next)
7 O0 h3 X# {, |7 lfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
0 Z: ^; d! J6 U) m1 h, Z9 ]9 }/ bp->exchange,p->waitio,p->runningTime);
/ x' D3 v4 V9 @( e( efprintf(fp,"\nHigh response \n");
/ w7 ]+ U' e# J$ D1 _for(p=HR_save_head;p!=NULL;p=p->next)
% v& ^/ u$ B. P7 U7 sfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,2 f! q& @) l: B
p->exchange,p->waitio,p->runningTime);
" y# [7 f/ J7 q2 Z2 cfclose(fp);( }) a9 C" ]& {6 P' P
}
^0 C) g6 p, @# w L4 }* GshowRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head); O3 a+ B1 T/ E9 c) {0 N
MouseListening2(&flagDraw,&showTime);
8 }! Z8 B; h. U}
! a+ y' X1 V; jsystemClock++;
+ I- P5 y$ w4 W; ]1 b/ i2 P4 ~if(flagDraw==0)
7 K1 A. u' Q) a- t* r3 \2 | Sleep(10);9 M$ z6 X# J5 N* d# P( O! y) U
}
& J% W8 }# R, S! x
% T( V! e: s. l( a3 F( [9 n8 B: C2 `+ P
}0 n9 k8 g5 r* W5 k z
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)5 E/ r+ \% w% v, C' E! T
{
1 M: J! a H( v: [" R$ FPCI * p=NULL,* name[5];* `, _1 K2 m0 ^4 b. n
int count=0,i=0;
) A# ~0 W4 W! K+ ichar ch[5][10]={"FCFS","timet","SJF","PR","HR"};
" c- q7 {, y; r% _* F% Ddouble turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};; v6 E& n6 B# f! S: d1 P
struct info
4 Y9 K' Q3 d0 v{
7 `0 U) r) e' G. K p5 Jchar name[10];
! r) a# u5 X% a+ }double throughput,turnover,wait,CPU_rate;
% [: s1 A% D" L4 x/ }/ W}inf[5];6 e3 O3 e) h& Y* H" y3 g
name[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;
O+ H& T5 f# o' eprintf("调度算法..........A\n");/ b3 `! F. q+ U2 J' v2 S
printf("吞吐量............B\n");
7 \7 O6 C8 R; T0 q+ m2 Aprintf("平均周转时间......C\n");; F2 P" b1 x9 ~8 x2 \
printf("等待时间..........D\n");7 I- m: d% R3 E3 v2 I0 l9 V5 m
printf("CPU利用率.........E\n");
5 Z) M9 Q! x' m) Wprintf("A\tB\tC\t\tD\t\tE\n");
4 P: e; T( ?$ x# Y, t6 qfor(i=0;i<5;i++)0 r" p3 i c) O
{, d4 C i1 r2 u. A' P: H
count=0,turnover=0,wait=0,c=0,w=0,change=0; V# G( ^6 Q1 G$ N: K: N& G0 g0 h
for(p=name; p!=NULL; p=p->next)
9 N( I$ M: r& y" @{
% w. L* \( [1 ?7 _3 ~! w1 V5 Ocount++;, q; f# V* e& S" G
turnover += p->completedTime - p->comeingTime;
& ?0 L/ M$ W: Gwait += p->runningTime - p->comeingTime;
* p" w+ Q: I2 {8 a: b- y& Jc += p->compute;0 v4 B/ y& y* W) Z. `9 v
w += p->waitio;
! S% m- n7 ]% n( s% G) n2 P+ P3 \change += p->exchange;
0 J' s3 @1 {7 h2 e3 j7 `}
5 V+ a8 Z% J+ _) ~turnover = turnover/count;$ c: p$ k5 r$ o4 X! u
printf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));2 m2 l& `6 H- q
strcpy(inf.name,ch);
1 T f4 S9 H4 {% i3 zinf.throughput=count;
& d8 L; W q& s/ |inf.turnover=turnover;
0 j5 g( n* p9 T3 Tinf.wait=wait;
& p. L# J, l8 B+ m: o. a6 rinf.CPU_rate=c/(c+w+change);
8 O! S4 U0 p6 r% b# Q a. O}4 G& A6 I7 E: h1 k+ c$ ~
//画图
' v& b, ~ C- z//cleardevice();0 _& H" X, G' N
line(0,600,1200,600);
0 g/ X4 L W+ P% C I2 ~; Aline(10,600,10,200);$ J/ P/ a& F! J
line(10,200,5,205);
% q& a3 s V9 v) u& Zline(10,200,15,205);( m4 p J+ `( J- i, z8 |2 X
line(310,600,310,200);
6 d3 f/ \. c# e' N5 w: @$ ?line(310,200,305,205);, k' f$ g3 K8 z' I# P% O2 U+ m
line(310,200,315,205);, T1 B/ [ m- [. ?3 ?
line(610,600,610,200);5 k1 O% Y: I5 }) r( M
line(610,200,605,205);
, `& @% W1 N" Zline(610,200,615,205);
+ X# N/ M/ o/ S8 a6 c" T; L0 l" ?line(910,600,910,200);8 b4 B X1 [* [; ^0 `
line(910,200,905,205);8 W" y8 {& X0 k/ Q2 L: m
line(910,200,915,205);//最高的长度400,宽度均为40
9 M8 w7 w5 r' q# p Nfor(i=0;i<5;i++)
: r) F- e6 S! {/ E- j# P+ g6 E{
! G- J$ }, r! S9 J4 v0 _/ ^if(inf.throughput>pos[0])4 U7 g' F5 u. x- w
pos[0]=inf.throughput;
+ k$ m2 l K4 N- A2 A6 x7 ~if(inf.turnover>pos[1])' P0 |% o. B' y5 n7 S& W9 B
pos[1]=inf.turnover;
8 \. h2 t% Z2 k1 w1 Aif(inf.wait>pos[2])' e. X' n% `" f
pos[2]=inf.wait;
: r/ W6 a( }0 S1 |. B$ nif(inf.CPU_rate>pos[3])3 t0 o [% b$ E- h
pos[3]=inf.CPU_rate;" [5 l( y( w; Y) \+ ^, R
}
9 k1 ?4 B8 |% P5 @) i$ I# tsettextstyle(30, 15, _T("楷体"));
7 R4 E' |% r0 hfor(i=0;i<5;i++)
6 J3 j4 D: J8 N+ M{
! Z+ E# `* t5 }. Z) A+ {switch (i)
2 g3 o4 O" E5 o% d5 E{% z. D( m' E \, Q, a" m. N
case 0:
5 f E3 u3 ^4 B% k4 bsetfillcolor(BLUE);# B1 ^& ~* k5 i# Y1 ^- P2 r2 ]" M% a
fillrectangle(100,50,150,100);$ F% O+ u6 R; P9 h5 \2 B6 k
outtextxy(160,50,"FCFS");
; y4 C( o, l6 P' Mbreak;. Q+ _) Y: b. v
case 1:
' R2 r) b" W. t1 U7 vsetfillcolor(RED);
8 ^* @: w3 i4 w% m* K$ O" hfillrectangle(250,50,300,100);
: I$ T8 C9 s9 }0 eouttextxy(310,50,"timeTurn");
" k- C7 C* K. P) P6 u' c. jbreak;# _! L' v" f8 Q
case 2:
. a( P) L- s: C+ Dsetfillcolor(YELLOW);0 t" s$ _. d% B+ d4 p+ W7 p7 |
fillrectangle(450,50,500,100);
: v! l' D v8 W! D2 Bouttextxy(510,50,"SJf");
. p0 s6 Z; g) R; u) I0 F- f6 ^$ Rbreak;# S, I$ }3 p0 ?* K
case 3:
( B4 I; L: ^/ w5 p, _! {7 Usetfillcolor(BROWN);
& P. Y5 G" T& ]! b$ L- G$ F1 a( afillrectangle(580,50,630,100);2 c7 b4 g9 K8 o! d; q7 Y- p
outtextxy(640,50,"PR");
9 I K4 h' o( Y* D4 wbreak;1 X/ T3 B$ g6 _& s
case 4:
, v7 T- F" B1 I6 z# Ysetfillcolor(GREEN);5 b2 S4 g: [8 k% X" `/ d
fillrectangle(690,50,740,100);
3 p) |6 C) X; ~; J) F0 t- F* I% r* L8 {outtextxy(750,50,"HR");
; P& N7 I+ b9 k2 w; j6 u! jbreak;
# h P& B. C2 z/ O3 M2 W}/ H* r! j2 M3 a! \1 l, z
fillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);' ?2 t) I( w1 H0 m5 Q; ^
fillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);+ c2 S2 e8 ~, `, ?9 ?8 d& y
fillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);; f2 D/ o0 N7 m
fillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);4 l* l `, m# z7 D
4 L3 P4 T; o" J1 M9 G5 m
( L5 x. Y) l9 H6 a" G}
2 I8 B$ ]4 z- W2 q: l( ? outtextxy(100,150,"吞吐量");
0 @8 ?. Z5 H% Y& H2 Qouttextxy(350,150,"平均周转时间");
0 I G4 K. p8 k# Wouttextxy(650,150,"平均等待时间");, s" k7 V+ a; W" ~ K4 s
outtextxy(950,150,"CPU利用率");
6 D8 F8 T+ \% H& Y0 p6 A0 r5 g0 Greturn 0;% z& m# Q% z" y" j
}/ k f% @, A+ z7 n) K
int MouseListening()
' n( | N( y8 w9 h# L+ x{
3 [/ i+ V& e* `0 g6 KMOUSEMSG p;
C: ~3 X, v+ v2 s4 k3 kif(MouseHit())
! v) e( k& I {4 y: L% {{1 {% C2 g% B: F) @$ m
p=GetMouseMsg();# c+ g# _5 N& f" H- D
if(p.mkLButton==true)
7 n" I- f8 S" Y& ~$ B- t{
7 Z9 H: b) t8 s- n, }if(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)4 P, E9 t, S, B4 i8 o
FLAG_FIFO = 1;5 } \4 Z8 V; v, {' i' r
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)" A4 S4 {/ S6 z) x
FLAG_TT = 1;
r( O, M3 A+ N& Jelse if(p.x>800 && p.y>0 && p.x<1200 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
; I% z( r U, @- Z2 q: c# ^7 nFLAG_PF = 1;
, W ~- X/ Y, B5 y. felse if(p.x>0 && p.y>325 && p.x<400 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
& N5 K1 K* ?3 G& I! x) lFLAG_SJF = 1;
! b" \, A- C0 g0 m0 o' M+ F. celse if(p.x>400 && p.y>325 && p.x<800 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)0 Y) F( B2 ^$ q( {- [8 ~4 y
FLAG_HR=1;" b$ q0 V" ]. B2 \
else if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0) z3 ]" L! |/ S! u$ c
{
9 I8 [' [% u6 ]% |+ n4 ~FLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;
+ f" [$ y3 S* Nclearrectangle(800,325,1200,650);0 J) G$ Q! j+ M3 O: e7 F @" z
}7 \1 o! b( X/ D8 H
else if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )5 c" v1 u5 I# ]( @) x/ H5 P. j$ E
{7 @& e/ P8 R1 ]2 N3 p
FLAG_show=0;
, A- v% b, H7 [+ }- L0 X$ Kcleardevice();7 u: q6 `6 H2 A3 A
return 1;
3 E- F, r: f6 X9 @% i; c |+ k3 L& m2 R}( g5 h' e8 |; }0 z8 ^( c5 F
}
6 {# O$ V, ^9 E$ w7 v( s4 p}
* C, c- p# A4 O8 H/ `- t1 d8 creturn 0;
! h2 D8 y" R9 t4 D8 {# \1 a4 T}
L. a, g4 }0 _, T4 kint MouseListening2(int *flagShow,int * showTime)1 ?' T) E1 f9 o! n
{
2 W* q. j: q3 ^8 Q* PMOUSEMSG p;. i+ r+ s* W) Y/ S# \) B
rectangle(1150,0,1200,50);
6 ]7 H9 Z8 ~. i, t5 Pouttextxy(1160,10,"X");, M( h+ r7 F4 t
while(1)! x2 }, n/ F1 t# B+ ~
{
* W1 i! a& Z1 u: tif(MouseHit())
) R, ^# J4 @, j3 N; J3 t4 m{
& s3 E0 {2 o1 @# m0 T7 p2 h/ e, gp=GetMouseMsg();! C: b2 d. _/ X* f7 Y8 a
if(p.mkLButton==true)3 S `$ q5 o( y6 ^
{
. n* \- t0 r' S0 s8 h0 s' Dif(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 )
3 q0 Y! L. y: Z$ J9 F d* r{* I. B5 ?5 \5 _9 r) `
(*flagShow) = 0;
& _: |* l' z' [2 P(*showTime) += (*showTime);) R4 V: i" e! @( N* ~7 ]8 v7 u1 u
FLAG_show=1;
* |* W. r& l) N. Z0 ]8 W6 n! hbreak;" X# k+ E9 O; G1 j% s2 T) f
}! y7 Z9 \8 `3 y& O+ m2 S
/ E9 j5 ^2 l6 H, [9 E$ {
}/ I# \6 R9 h) W% A5 t* g' S# T {# g+ G0 q
}; @& n+ R0 X, H c1 I
Sleep(20);
& D# r" U f% C}9 ~$ c/ Z$ \# T1 j4 b
cleardevice();6 u8 N% n! L ]8 n6 p5 P
return 0;7 m3 o7 q( P n$ h! d8 K& I
}
% {6 l1 k k# e9 {* e2 eint drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)
& H( w, ~7 U0 [& ~$ v$ r) v{& s" e- q3 R3 P; [8 } G
static int info[11][3],num=0;7 u4 k, I/ ?( W4 L* q% A. `
int i=0,j=0,pos[10][3][2]; W( T* a; t8 L
float temp,t;
0 I0 Q, _! X" _* W3 Q; L5 a//画按钮,不属于FIFO图的范围 ]/ H6 l) s% x, U
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1)
) K) \" O9 \1 n, {0 W{! D( B6 B3 i/ Z
settextstyle(30, 15, _T("楷体"));% I2 @/ c' w" A- S& f, H
rectangle(890,455,1110,510);
$ Q- r" r6 Q% x3 l9 j0 mrectangle(900,465,1100,500);" p! v9 W# R" c
outtextxy(910,468,"查看运行结果");+ U# _% P N6 _2 x1 z6 k8 v
}
5 b) H% V9 L- o% q$ C$ e' l. ^//结束画按钮
( d' K/ B$ A9 @5 V; v! W' Einfo[num][0] = com;
; w$ O% _3 k' I) \/ _2 q( winfo[num][1] = wai;% m7 I: _1 s/ Z7 C
info[num++][2] = cha;
' l2 b _" \; I6 [+ o3 Vif(num>10) //存储10个点
3 b8 C1 P7 R: \7 a( q" }{8 A6 T+ z' Q; @+ w
for(i=0 ;i<10;i++)% o( i5 `. _8 T" O' N" C1 a- F
{7 |5 v; H4 K7 v: n
info[0] = info[i+1][0];
* |6 O- J/ J6 e$ ^4 I$ P$ b) Cinfo[1] = info[i+1][1];6 a$ u& J# x" ]3 G% h# A
info[2] = info[i+1][2];
; W# V" u) t7 n' E; F' n}
+ l$ R) x+ Z3 {num--;6 Z% u6 {! x" y
}
) A# y& t/ t8 x- o% s3 X; Hif(FLAG_show==0)- M# J( K4 v I3 _" B! |! R
return 0;
8 o6 T L b$ Y4 g. Z& jfor(i=0; i<num; i++)- u. g0 t5 j: t/ r- {$ {5 j
{
4 c, U& h: x X9 |- T6 r" Qt = (float)info[0];
% ?5 L8 _! j" E+ W0 I0 L, ltemp = (t/101)*90;" w# o) a* e f
pos[0][0] = (10-num+i)*25+x+100;; |2 \9 D: e+ t4 Y
pos[0][1] = y+110-(int)temp;
% e* h" A* D3 e7 I( H& e5 Ht = (float)info[1];8 |1 y; a* O V7 R. a* h- m
temp = (t/101)*90;) Y' N {3 P' L- t) ]( X
pos[1][0] = (10-num+i)*25+x+100;% T9 R5 H. q% F6 w* g( R, }, O
pos[1][1] = y+210-(int)temp;
4 _+ ?: |( z5 S* Y- K7 \t = (float)info[2];4 w0 p+ @0 O, V) y* u) s4 Q
temp = (t/101)*90;1 C! c2 p9 W5 p' j# I X! W
pos[2][0] = (10-num+i)*25+x+100;: g1 L# I3 q/ `7 y3 f' {
pos[2][1] = y+310-(int)temp;
& H4 v% h2 m# m3 u# K}
5 ^, K% m: H; z, W, j- u- o8 Mif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)1 [+ G0 ~, n6 h% S
{
l4 u( N# k6 b/ G6 [clearrectangle(x,y,x+400,y+315);% S0 D9 ^4 x& ^5 h6 I. N# e
settextstyle(20, 10, _T("楷体"));
% T, m- }$ [3 s/ w5 trectangle(x,y,x+400,y+325);
: c9 T+ s1 [7 t( S! Uouttextxy(x+40,y+10,"CPU"); //画柱状图
7 f) G/ m2 M _. Z3 C' }: i& Louttextxy(x+45,y+10+100,"IO");: _) G4 J [# z( T7 P; U/ g
outtextxy(x+40-15,y+10+200,"change");8 L8 \0 t/ m. V, m: \
rectangle(x+35,y+30,x+75,y+110);6 N) O0 Z6 Q0 q7 h+ P: R n1 z
rectangle(x+35,y+130,x+75,y+210);; |' z- T3 V* u. y& N
rectangle(x+35,y+230,x+75,y+310);
3 ^$ i0 Z! Q6 j& s; f3 }/ Z Pouttextxy(x+180,y+310,"FCFS");
( H3 ], X8 R8 S$ m" ]t = (float)com;
+ @4 l k p1 w$ z) a* ftemp=(t/101)*80;
: k# L t1 F, o# gfillrectangle(x+35,y+110-(int)temp,x+75,y+110);3 ^5 x+ x' s8 y! B
t = (float)wai;4 P; b( z$ l6 D
temp=(t/101)*80;
0 X" n' e5 s a% j/ g) g) H8 |; Dfillrectangle(x+35,y+210-(int)temp,x+75,y+210);+ a6 y" o9 t+ P) Q8 _
t = (float)cha;
% g7 b; M3 N, U; R" s# htemp=(t/101)*80;) B: _. M4 D' v
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);3 u, u: w* B) t" b
for(i=0; i<3; i++) //画坐标 high=90,length=250# i* L6 d( h3 _. U% d
{- J3 S. y# y& H3 I! v' o
line(x+100,y+110+100*i,x+350,y+110+100*i);! e9 h1 ~% }3 E ?% y* C, h
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);9 s2 m& M* R2 T* B. G
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
* S; {2 D, ~5 N+ H( p5 W# c8 |
6 ~5 _! S- T% @0 uline(x+100,y+110+100*i,x+100,y+20+100*i);
1 q" Q6 c% \) rline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);% U6 f/ T! `$ A
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);2 \9 s7 S9 f! Z) K
for(j=0;j<num-1;j++)4 G# a0 d0 D* ]9 ^5 O. v
{5 Z2 l. _- U% D& j# V1 `
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
) ]) h0 k9 a4 q* Yline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
' R* t9 [! S& k. v! x( m' oline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
6 e7 z1 |# Q6 \' N" t}4 Y: r% u+ h5 c% ]3 P9 J- L
}8 C/ y6 ~6 l2 A4 w
}- S' M# ^. @$ k/ w' z3 o
else if(FLAG_FIFO==1)
7 }) e& [8 W: r6 X! L{0 e8 n& l' E/ W& d' d2 b/ D
x=0,y=0;
1 {; c) D- n3 H( ? rfor(i=0; i<num; i++)+ ^; V9 A1 y" Z/ `. M
{
; _ ~7 R2 D6 N8 o1 t r# Vt = (float)info[0];
! b$ M8 _, n6 a) h3 y2 N8 Atemp = (t/101)*180;& \3 n$ _ X7 y+ h
pos[0][0] = (10-num+i)*50+x+650;! @ N; }' F, S8 @) F9 q# q6 P
pos[0][1] = y+210-(int)temp;* h8 U* f3 r. h! Q W e. ?6 K
t = (float)info[1];4 o6 V2 `# M2 k2 \6 n0 v
temp = (t/101)*180;
. d C% h) p( ?pos[1][0] = (10-num+i)*50+x+650;
& F1 k# y& r/ A. R* P2 P$ t \$ Lpos[1][1] = y+420-(int)temp;
+ c$ V' {9 v" It = (float)info[2];; r" d' P0 u9 A0 B
temp = (float)(t/101)*180;
7 ^* {0 \% h- m; Y6 j3 U Rpos[2][0] = (10-num+i)*50+x+650;
l% s1 e- v5 {pos[2][1] = y+630-(int)temp;' Y+ ^6 |: q5 @0 R" t) F
}
! p0 |* _$ W/ X$ A ?2 q/ S$ _clearrectangle(x,y,x+1200,y+650);9 @) D0 f5 R9 H5 L' C; M
settextstyle(40, 20, _T("楷体"));
6 p7 y' ~1 ]6 kouttextxy(x+50,y+50,"FCFS");
, E9 X2 `4 N& |outtextxy(x+280,y+20,"CPU"); //画柱状图* a* h0 [! b( u
outtextxy(x+285,y+20+200,"IO");
! G& ^" W+ V# n2 k* [/ Gouttextxy(x+250,y+20+400,"change");
1 \' s4 |0 E- {+ Nrectangle(x+270,y+65,x+330,y+215);
9 w$ O: S% @# Crectangle(x+270,y+265,x+330,y+415);
5 K! s! q2 P# ^# @' i0 U) h0 P5 L4 drectangle(x+270,y+465,x+330,y+615);- j2 L- F0 f/ |
outtextxy(x+290,y+620,"TT");' { v1 R, M6 A0 M' a
t = (float)com;2 j# B# z. N0 O
temp=(t/101)*150;4 T" u* `: c, U
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);* R- k9 p: z; S
t = (float)wai;6 \, s- H% d. F
temp=(t/101)*150;# @0 J" M, |' V( `5 M
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
/ k5 {! q2 \5 O& X) c. Ut = (float)cha;8 W* l+ f% n, Z' ?6 c
temp=(t/101)*150;
' a" \ R; ^2 L; k8 R' S: G) hfillrectangle(x+270,y+615-(int)temp,x+330,y+615);0 I+ c4 P% w9 H. e
for(i=0; i<3; i++) //画坐标 high=90,length=250: h0 V" E% G' g, R2 o+ g! Z" V
{
1 P1 b# U8 A8 Q3 nline(x+650,y+210+210*i,x+1150,y+210+210*i);
* e' N9 r: l/ D7 E6 a+ Q" ~line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);8 }7 L# D2 H9 i1 V
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
, U/ s9 }. h# f- F3 E: y" u9 ^7 A, z: F+ e+ {
line(x+650,y+210+210*i,x+650,y+20+210*i);* R! E2 y) Z. G& T: G
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
0 L/ K3 }. m( s; Q- s4 {line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);" I6 q: S3 g2 A2 K+ O1 p
for(j=0;j<num-1;j++)4 g7 R2 B2 t3 A2 E
{4 P+ p4 @/ R W' T: X' J V/ R+ a
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);) f. A0 T1 D, i4 U
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);9 ]! a. w2 r% `8 |
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ! t+ Y" C/ ~5 b- [, B) `9 ~
} {. [4 d9 v4 D8 [) l6 G$ h! U
}
; ?3 a) S( |# j. }# {) I1 d$ Q}
! ?9 z% `" F) l; Z9 A) B) N+ j, U$ ~* j/ h) T
' k2 {9 L. k B/ n$ ~2 Creturn 0;1 z. n( r3 \1 d$ k: I1 k
}
1 `% t g& P3 n& Fint drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)$ m6 z: A9 }+ m2 \. I9 e @# o2 J
{* Z) E; c8 F s4 F& b: Q
static int info[11][3],num=0;$ o3 q# s- Y; U; h" Q0 N
int i=0,j=0,pos[10][3][2];
G- t0 z; }* M# d4 ?float temp,t;# g7 f2 f8 p) X l6 _7 V" n
info[num][0] = com;9 V* d4 X$ J5 i& K* F. X' ^ _# q
info[num][1] = wai;+ I- O) U# X8 M/ J4 S E6 x6 l' M
info[num++][2] = cha;' @2 B& o3 ]$ A4 \- B0 S- t) m
if(num>10) //存储10个点% { o/ a e# Y7 A
{! K1 h: B: ^) I0 t2 u( v# `" z
for(i=0 ;i<10;i++)3 ]1 u' F9 T. Q& B
{
7 R5 a: H# V: B8 v O" t: ^info[0] = info[i+1][0];9 b8 V2 t# g' ~ y5 |
info[1] = info[i+1][1];$ Z) j& t$ E; l' I
info[2] = info[i+1][2];5 O, P2 l4 R1 a5 u0 |9 s
}
7 x0 ~% B3 g, I2 l5 R! Xnum--;
) C/ y# ~) t: L+ i}
$ ?8 ]1 p* M7 V* @6 L9 m Y5 tif(FLAG_show==0)* ~0 q+ A6 r6 H( S
return 0;
! c, t" T7 H* p7 O8 s- F1 Gfor(i=0; i<num; i++)# N8 a g6 A5 U+ [
{
& A! z$ M+ U& B Yt = (float)info[0];
8 h" T* `1 R, w3 n2 ^0 [6 v: ntemp = (t/101)*90;4 A% Z8 P" X# m/ k
pos[0][0] = (10-num+i)*25+x+100;
% ]% ]( _. d0 C0 Qpos[0][1] = y+110-(int)temp;- m" G; p+ G# j4 W& |
t = (float)info[1];! b0 O( ]: X: q9 I6 z
temp = (t/101)*90;2 u; o# v- F; w4 Z) [3 {7 Q
pos[1][0] = (10-num+i)*25+x+100;! n- X0 \0 p) q) a, X7 O
pos[1][1] = y+210-(int)temp;3 S; O- |4 N3 e% p
t = (float)info[2];
, ?, @. p9 L+ |& z* N) _temp = (float)(t/101)*90;0 X J& \; B7 A: q6 |- _6 U. o
pos[2][0] = (10-num+i)*25+x+100;* c& I2 o) D% B: J: ?: R0 J
pos[2][1] = y+310-(int)temp;
$ p; A. v, b8 H6 a p- U}
' F- H$ D2 @: u* g# Z- R- Q" @ dif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)% j" H5 m! R# ?0 d
{. B4 Y! }5 H7 p$ Y5 r$ U/ c' O
clearrectangle(x,y,x+400,y+315);3 ^8 Q" x" J P! ~
settextstyle(20, 10, _T("楷体"));5 u, [9 f2 _( Y" X2 m7 s+ u
rectangle(x,y,x+400,y+325);
9 v8 I3 U4 ?; z( \8 N/ Z5 R" ?1 Touttextxy(x+40,y+10,"CPU"); //画柱状图
, w( J! J8 L/ f/ aouttextxy(x+45,y+10+100,"IO");
2 S+ z0 d" M N$ }$ Houttextxy(x+40-15,y+10+200,"change");
3 B7 s( t* x0 u6 R/ a9 Erectangle(x+35,y+30,x+75,y+110);6 u8 C& C0 k- i. }
rectangle(x+35,y+130,x+75,y+210);
( N+ p( l; G- F" ]8 Y: f0 q" hrectangle(x+35,y+230,x+75,y+310);6 h) ~3 W- s3 K, ~+ l
outtextxy(x+180,y+310,"HR");" E# w$ U& S! l2 D+ R8 A( L
t = (float)com;% m4 N+ V9 j4 N* b7 t, Y$ O- g
temp=(t/101)*80; y+ p* L# a% T* _" T( @0 }! o& M/ p5 S
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
/ u& C8 a2 w; z4 h, N, Ct = (float)wai;6 s: n1 t) g! P" J, j
temp=(t/101)*80;
% L) \ Y% ~# \' t& t: _fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
/ p) H/ V/ P/ `3 N5 |t = (float)cha;
" I5 c) Y/ a/ ^* Y/ U1 atemp=(t/101)*80;# r% v1 U1 s( U- ^8 o
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);9 P7 g7 N( Q. a
for(i=0; i<3; i++) //画坐标 high=90,length=2506 O. Z- w' w7 t D0 S- T( G
{
. M0 g. B0 }) {5 Iline(x+100,y+110+100*i,x+350,y+110+100*i);+ g+ \1 C u; s- c/ A7 F, `
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
: c: _: n* @3 k& uline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);1 o) x8 F$ a( {, K. {+ G( ~
: h6 M, x' i' `3 Z8 _6 [ P5 q
line(x+100,y+110+100*i,x+100,y+20+100*i); m6 K; [$ p- w+ ~* A
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
) ]9 [7 k6 H* }1 O; t, Wline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
" Z7 p/ A2 j6 z* G" m nfor(j=0;j<num-1;j++)
! ], T+ _8 o, V5 B{
' j/ L1 X6 _# F$ Bline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);6 {. w( o: U! h: U, E F
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);/ g9 a: \/ q" D4 n
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
4 \. |, L9 w/ [: J" L8 W3 c}- P! v: U- A* G4 S
}
# Z3 Y" D4 U1 k$ P}
d; K/ G$ u# G) {0 _- belse if(FLAG_HR==1)
! f% I4 p' M4 S! ]" N{" c+ x6 K p/ h7 U7 i4 ?9 q1 Z/ w
x=0,y=0;% F% x6 G/ \. Z4 T5 i4 v
for(i=0; i<num; i++); ^" t6 a c c
{
! [/ f c: q8 Q# i! h: K( _t = (float)info[0];& {6 ?* X# Y. U4 n# ~
temp = (t/101)*180;5 r1 X8 {) V' N3 g( ]4 H: _- D( T
pos[0][0] = (10-num+i)*50+x+650;
2 M; O& \7 T' t+ {pos[0][1] = y+210-(int)temp;+ y/ r8 }! i' y; U- D4 J5 _
t = (float)info[1];& E. Y. q# { v: F3 s! { e
temp = (t/101)*180;
" ?0 s( W7 D9 L. U0 h. ] Bpos[1][0] = (10-num+i)*50+x+650;
8 J* n3 J, F5 }: \pos[1][1] = y+420-(int)temp;; g) o* T/ V) l# O0 a l7 |. [# ^7 m. L
t = (float)info[2];
0 \' k3 V1 j9 ^% I5 E% G9 U5 vtemp = (float)(t/101)*180;" X' V( e K: y+ T" @8 _9 H1 Q
pos[2][0] = (10-num+i)*50+x+650;
- x* M ^2 a7 p3 z8 d" ypos[2][1] = y+630-(int)temp;
; h& j) q. L, ]}0 \ X; Q$ L& j3 C8 F& X- N
clearrectangle(x,y,x+1200,y+650);
; G1 S1 N( v% wsettextstyle(40, 20, _T("楷体"));4 v( Z! o6 K) N+ v
outtextxy(x+50,y+50,"HR");
8 t& g) c" T# p$ ~# y& }* f" @outtextxy(x+280,y+20,"CPU"); //画柱状图
5 n6 m% x7 [7 `/ d& V. W8 Iouttextxy(x+285,y+20+200,"IO");
( r1 \. \7 o& t2 Y$ Youttextxy(x+250,y+20+400,"change");$ U0 |' u/ X: |, D# f) N
rectangle(x+270,y+65,x+330,y+215);$ W' W. a' _9 p$ b, K
rectangle(x+270,y+265,x+330,y+415);4 N# q5 x3 C* R/ F* C
rectangle(x+270,y+465,x+330,y+615);
. c# T0 v8 P! E6 couttextxy(x+290,y+620,"TT");+ k* s; V9 E1 G# X I# O; Y; [% V
t = (float)com;
s5 _7 H3 e' Ltemp=(t/101)*150;
, ]/ d6 G; F, J2 [+ L. Sfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
6 G% w: W' ^5 n: @' s6 vt = (float)wai;% J( a" c0 C) I R5 [7 N
temp=(t/101)*150;
- i" a' Y, ^3 F% ~fillrectangle(x+270,y+415-(int)temp,x+330,y+415);4 {% j( j& X5 u, ?) N2 O
t = (float)cha;, t$ q! |* F# o5 f: [3 C5 v3 f6 |) R
temp=(t/101)*150;
7 _: d9 O W+ afillrectangle(x+270,y+615-(int)temp,x+330,y+615);
, {: L8 T+ i/ ?5 D }6 efor(i=0; i<3; i++) //画坐标 high=90,length=250
7 g' ?* N* j( K: j- V{ u3 b9 C3 U/ M' ~9 x4 Q
line(x+650,y+210+210*i,x+1150,y+210+210*i);5 ~# F# R& u. ^$ E: F
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);0 L3 d) i; b7 |6 V5 U
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
3 h1 [- H( U) V# M* E% O6 `8 X
. ^. Z# Y6 P8 \% B4 j( ~6 Bline(x+650,y+210+210*i,x+650,y+20+210*i);; |0 [) s8 ?$ J
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);0 I. u. T# `( q/ E9 E' S7 x
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
" y. ] C, v4 Z. U3 Afor(j=0;j<num-1;j++)
0 a# U% E! s' E; f/ d{
$ N$ S; G* b) |6 \+ Y) _- i7 `+ @line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
" U8 H6 }2 [: A5 Q7 {% ^line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);2 @. A( @& R) V" Q: c4 w9 g, B' a
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
& ^; z3 c0 Z* L. E2 e. ~}6 d9 e9 y$ R7 _1 Y6 p5 j- r
}
* Z& H. l4 }! B6 G8 ?2 z}
/ q. i5 Y; { J# B/ r0 M( e7 l: s+ X
0 X- Z- `. a7 z% f3 A" k4 C* {
* t# J% e% q7 _& L+ sreturn 0;3 n8 P z; ~. N4 U# |% E9 I
}
5 n1 ^( `5 ~. R( s2 M7 j5 Lint drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)
" ] m3 V! l6 a" K! s D! W{3 M: Q; j. T0 g6 A; w
static int info[11][3],num=0;
5 m- L, d+ C/ X& `int i=0,j=0,pos[10][3][2];
9 ?" e% x0 E4 i" P" i) Xfloat temp,t;, x, L b) c0 ]& r- ]
info[num][0] = com;$ ^3 f- Q/ M% f
info[num][1] = wai;
4 Y# H- o9 f* B: k: jinfo[num++][2] = cha;4 ?* o2 U# J( M# L! ^2 U
if(num>10) //存储10个点9 F6 A0 v5 C( ~+ A0 p7 H3 N1 r
{* @6 F+ f, K( X
for(i=0 ;i<10;i++)3 }$ D9 B z7 q+ G3 m; U( Z2 w
{
* [4 s/ h, k7 P$ minfo[0] = info[i+1][0];) g4 Y9 ?9 q9 [; v
info[1] = info[i+1][1];
1 V! t0 E1 J, C3 ginfo[2] = info[i+1][2];% F4 T7 E: X7 m% s* }
}' o+ _3 m4 T9 }4 g
num--;* c& P5 h$ @$ b2 n8 d" ?5 g; N) Z
}) Q2 x" H& |, i$ ?( S) ~5 p
if(FLAG_show==0)
0 _ J, T- C/ Y3 \1 l* }return 0;7 C+ |( l( R1 e- W4 h" ]9 u
for(i=0; i<num; i++)- G4 p& }' U8 _. ~$ a1 G' A
{
5 G7 U$ U( ]& j7 m& J$ s, g5 pt = (float)info[0];
) r3 S6 O6 O2 Z+ F Otemp = (t/101)*90;
& Z9 h7 W/ o! l3 z- b: o1 Npos[0][0] = (10-num+i)*25+x+100;
4 m% u% C: S' ^1 ]pos[0][1] = y+110-(int)temp; H1 @& ~4 w* d3 c7 a
t = (float)info[1];" k9 @3 U" i3 o; P |
temp = (t/101)*90;
. T0 J/ x( P& s% v2 Fpos[1][0] = (10-num+i)*25+x+100;
+ l- D' o/ R" Z8 H" D* ?pos[1][1] = y+210-(int)temp;
5 M0 P+ H. O4 ]+ Lt = (float)info[2];
7 T3 s3 ]8 ^8 r: p& h, htemp = (float)(t/101)*90;# C1 p5 x" s1 p+ H% q8 t( C. a9 J, [& ^- ^
pos[2][0] = (10-num+i)*25+x+100;# x$ e2 @5 X7 m9 u, X# h$ n
pos[2][1] = y+310-(int)temp;0 H" L- G4 d+ I7 ~
}
' z: t/ Z9 I/ |. lif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
G$ I0 X- f' Z$ B7 n2 P6 ?3 q{
+ E Y( `8 w3 R$ ~ r. Fclearrectangle(x,y,x+400,y+315);3 I7 f. ^2 R4 p" q: |/ o
settextstyle(20, 10, _T("楷体"));
, x+ }& X' Z: F! t) v) Z& ]rectangle(x,y,x+400,y+325); O# T$ v' s& u. ~5 t# l
outtextxy(x+40,y+10,"CPU"); //画柱状图
: s0 `6 k, Q2 x- {: B! qouttextxy(x+45,y+10+100,"IO");
$ g* k3 j# e7 j7 Z: f* x! pouttextxy(x+40-15,y+10+200,"change");
# ?+ o$ e, U$ V3 {5 F1 Erectangle(x+35,y+30,x+75,y+110);
( v; L% j) g/ I, h& trectangle(x+35,y+130,x+75,y+210);
9 c1 `* T5 ^ X0 z9 h4 w' L: Z# h) irectangle(x+35,y+230,x+75,y+310);6 i) R* y, R! P) z
outtextxy(x+180,y+310,"TT");+ g8 l' q1 i1 X( @
t = (float)com;
6 c* a. e8 O1 v$ R Ltemp=(t/101)*80;: q; z2 ~" p- [3 |3 N1 y
fillrectangle(x+35,y+110-(int)temp,x+75,y+110); r- j2 k3 y4 [! U
t = (float)wai;6 D4 W1 X$ a+ A/ I
temp=(t/101)*80;
/ j q/ u1 o) j% W/ m$ K. {" Hfillrectangle(x+35,y+210-(int)temp,x+75,y+210);6 h/ V) `! H. F) p
t = (float)cha;
5 b) c4 }4 b) d; M% y+ Utemp=(t/101)*80;" [: c+ R5 ~3 K
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);2 E: N# y$ L* _, ^
for(i=0; i<3; i++) //画坐标 high=90,length=2505 h& Q" T8 U I' f/ `
{
" V4 Z3 o& |0 g* B; f3 Eline(x+100,y+110+100*i,x+350,y+110+100*i);/ b2 F1 C& P3 p4 o5 |) J$ J
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
+ ^2 E# }, T2 _, P8 m2 @+ oline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
- t1 o; o% z4 V: f, m' _; d
! O5 j7 u* t3 y+ {) vline(x+100,y+110+100*i,x+100,y+20+100*i);
$ O8 {% y0 R) r' V, z# B& ]# X: nline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
4 ]. W' b9 _- E- G3 wline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);" J6 |% T$ r& `1 g6 R& y2 r7 j; q
for(j=0;j<num-1;j++)7 ^1 _( L6 E$ Y; O0 F% h7 d) t, c. B
{
1 x3 S: J) R6 x9 e$ ^& hline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);" p4 }& J% s) j1 E, K- _( R0 Z/ S+ Y
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
F9 z F6 \, N7 `line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
( I$ J* x9 T: m7 V L* ?}
) w X- d1 I& d, r' n" h: f+ C}
! ?" z( j+ k* I: s! R& \}$ }3 ]8 w" q$ g$ x) E" n
else if(FLAG_TT==1): m- L# d8 F+ z* i# Z) w
{# O# E3 w& I; {$ R8 o
x=0,y=0;
, R9 l. ~9 `: }" o7 lfor(i=0; i<num; i++)+ w# o* x0 h2 e! s
{
" |2 [/ n, C, ]: f/ P* Jt = (float)info[0];
1 L& _) D- R2 ^1 b0 B ctemp = (t/101)*180;
4 N' r. O( G: f8 q. A4 cpos[0][0] = (10-num+i)*50+x+650;
# b; F/ [" @: ]6 E. rpos[0][1] = y+210-(int)temp;
6 i$ w f1 @5 z1 ^t = (float)info[1];
7 ~' `! t4 Z- Ttemp = (t/101)*180;
+ P0 U/ R2 U$ a6 Vpos[1][0] = (10-num+i)*50+x+650;
8 ~+ D& I& S8 m5 xpos[1][1] = y+420-(int)temp; C+ T4 v4 Y' l" R. h
t = (float)info[2];- C" {9 x' P+ Y% q1 F
temp = (float)(t/101)*180;
3 S i+ N5 i0 j, Ypos[2][0] = (10-num+i)*50+x+650;
( _ A4 p2 D6 ]# `7 q- M) h) q2 w9 lpos[2][1] = y+630-(int)temp;
0 x/ w! [) `$ {6 o, B}$ _- s% }, L. Q6 u* [) J
clearrectangle(x,y,x+1200,y+650);/ n% t; s% _6 g: h) }& y/ b
settextstyle(40, 20, _T("楷体"));# [' x! Q3 P0 A( A* G6 w
outtextxy(x+50,y+50,"TT");
5 E2 o7 ]: H5 @6 Y1 _* h- wouttextxy(x+280,y+20,"CPU"); //画柱状图
% U: m; ^ V$ n% K# X: \; @outtextxy(x+285,y+20+200,"IO");
- H! N5 t5 i$ a9 \$ q# Fouttextxy(x+250,y+20+400,"change");
. O5 X' o# ?) D) _% p M# K' frectangle(x+270,y+65,x+330,y+215);7 H$ _$ }& Z3 n5 E
rectangle(x+270,y+265,x+330,y+415);
5 f- w5 W! G; M' u0 U7 u; Grectangle(x+270,y+465,x+330,y+615);! z& c2 C0 @+ Q; P' Q3 ]
outtextxy(x+290,y+620,"TT");
$ U; N8 ?! k" f! S0 nt = (float)com;
/ g( v+ P% z5 z7 f4 ntemp=(t/101)*150;
& v; M: ?& d, c! G0 C5 u' `fillrectangle(x+270,y+215-(int)temp,x+330,y+215);: z& v& h; w/ I$ ^/ s
t = (float)wai;
6 X! _! X2 \: b ^: l2 Otemp=(t/101)*150;# \0 R+ p, h f& }
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);; r. S3 x1 _: T# L
t = (float)cha;9 _4 i/ `7 i: J$ g# f
temp=(t/101)*150;
# W4 E v6 i% T! efillrectangle(x+270,y+615-(int)temp,x+330,y+615);1 m0 z- j4 L. I; u9 p
for(i=0; i<3; i++) //画坐标 high=90,length=250# i% X! G" r2 m
{8 L' r$ }7 l! _3 w7 s& P, Y
line(x+650,y+210+210*i,x+1150,y+210+210*i);3 m& V8 m. U4 R8 W n l. i8 o2 S
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);( ~, C$ w5 N( V6 A5 F G& ]: H
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
5 M* H* n/ r0 ^ X/ A
! G8 p1 K" z4 ]/ ?line(x+650,y+210+210*i,x+650,y+20+210*i);. d) K1 e/ v/ |: ~! V
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);% y: ], m( _5 i3 V( u$ y1 V
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);8 J4 c! { Q8 @' P( o
for(j=0;j<num-1;j++)5 g( Y* y) @* H" Z
{" { Z+ J# h" C9 [5 Q4 d
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);; l9 P! ?" y( v0 B! C' k3 m" F0 y
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);$ l+ N# f: c9 X, F: V4 l
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
2 L1 P7 v# A. x$ ]8 P* }} x" i+ i, r. ]# G2 A, b0 u2 _
}- l0 o0 c4 a9 ] B' Z5 |9 O
}( F: N6 N( D1 ^
# ~/ @% y! y, J. V
! Q) l; v0 W! b! }! v
return 0;2 l3 B8 E+ Q6 l& O6 j
}; G9 c P$ f6 k) L5 F( E
int drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha): M+ b" N6 m% U8 V1 P7 M
{
1 d9 Q8 \* Q2 E0 W7 bstatic int info[11][3],num=0;
" h ?) B1 ^$ Pint i=0,j=0,pos[10][3][2];
) z" q1 P' M# M0 E& F% lfloat temp,t;- T U" o: J6 S( R: A+ `8 J
info[num][0] = com;
0 `0 p: G g. h7 t0 R* E: I; K6 binfo[num][1] = wai;: l! f! r& u _6 V/ l' B- |
info[num++][2] = cha;0 Q0 t G/ G" @
if(num>10) //存储10个点
9 _- B4 ]1 p9 G( N, r- E{, x- f2 N- n: m5 k; ~
for(i=0 ;i<10;i++)
( h* l3 V# S: U* n8 X{% {/ q7 T+ P' R G$ V g- V$ |0 o4 l
info[0] = info[i+1][0];* ` [; H5 s/ F H8 s
info[1] = info[i+1][1];, O) b q' i6 X3 `! ~) X8 h3 M
info[2] = info[i+1][2];; R% ^/ l) y, m% w) E
}
- _6 c0 [& w6 M5 \num--;
P. X6 N9 @4 `4 Z$ z8 r6 X}; O! b: m3 m% L* J5 I5 W$ x- Z6 E
if(FLAG_show==0) y+ H2 w% [% A# U% ^* B0 U0 a
return 0;
; i9 L6 n# ~! {) C: ]) L. _0 ^for(i=0; i<num; i++)5 \! O- d% P/ S# U0 k. ]' X
{
: w! j; a5 d5 \: Z s4 b& K: W) pt = (float)info[0];
& B$ e/ W( H- Y% wtemp = (t/101)*90;. ~* G7 Y8 d0 ~. l5 x; u t J/ |9 @9 |
pos[0][0] = (10-num+i)*25+x+100;+ c0 P n# {4 G6 j. p
pos[0][1] = y+110-(int)temp;; |* \: n' ]7 Z. k# u
t = (float)info[1];2 D. A5 F5 a& `8 ~- i4 c5 ^
temp = (t/101)*90;- \2 e/ P! w8 Y5 ~0 Y: m
pos[1][0] = (10-num+i)*25+x+100;4 R, H# n4 N# ` N5 u+ N
pos[1][1] = y+210-(int)temp;
: V; n7 K, c$ ?, K) Bt = (float)info[2];6 K: o& z' W' D$ A, X$ l1 z
temp = (float)(t/101)*90;9 ^1 t# s3 ], d8 K. p6 t
pos[2][0] = (10-num+i)*25+x+100;
% I* @ |1 A. i( [* h( n, [pos[2][1] = y+310-(int)temp;
0 ^$ K; b! A9 R9 m, \) L% ^* S3 Z}
. h& A& u. H* C1 ^6 M2 aif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
1 P* B3 {' P/ a% {$ f4 ]7 q% A{( M" @% y/ ~1 B3 v$ G0 V: j; S, _) o
clearrectangle(x,y,x+400,y+315);: k) D. C8 ~7 O% D I
settextstyle(20, 10, _T("楷体"));
: r3 O! [/ [# D+ o2 zrectangle(x,y,x+400,y+325);
6 g1 l: v* Y: f3 _- ^; d8 Eouttextxy(x+40,y+10,"CPU"); //画柱状图
7 _2 L. ?* g9 t9 m0 qouttextxy(x+45,y+10+100,"IO");
, N0 ?1 {9 l5 r/ a5 U% Couttextxy(x+40-15,y+10+200,"change");: [7 f* K8 D2 N3 v$ f
rectangle(x+35,y+30,x+75,y+110);
6 Z( m7 D# J# I3 ]# K9 crectangle(x+35,y+130,x+75,y+210);
5 ^# S7 |6 w; ^0 v$ f: ^* grectangle(x+35,y+230,x+75,y+310);
+ d$ e. D" n) X" i3 L( i& Z# f6 U Jouttextxy(x+180,y+310,"PF");8 [; Y+ s* f3 E; }+ d
t = (float)com;, W: V0 I9 l6 k$ `9 E
temp=(t/101)*80;# f: e; G( i; ^- F8 u
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
' F: r: `) O5 n M5 `' ?t = (float)wai;
6 X* Q+ ?2 h+ I/ r2 p- X7 stemp=(t/101)*80;
8 D8 m( N$ \" E1 ?fillrectangle(x+35,y+210-(int)temp,x+75,y+210);5 Y) A- d$ E' @" ?) z) c
t = (float)cha;; j% K# S, g% F1 ~! _9 d& m+ a
temp=(t/101)*80;4 ?8 b! u+ W ^* l7 ]7 x
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);) _6 V) D; y% g* R8 `* v0 c
for(i=0; i<3; i++) //画坐标 high=90,length=250
3 S7 b# [+ Q8 \{7 |- F6 ?( _6 r+ A3 Z' B3 I
line(x+100,y+110+100*i,x+350,y+110+100*i);( e0 B- r- r6 ^2 c/ ]/ W. K' m
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);6 K4 Z: U. ` r3 B1 E U) E
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);8 `* z- }( x* V0 q
( q; G! F+ b/ Y3 a6 }4 h$ X, |- a$ T/ |
line(x+100,y+110+100*i,x+100,y+20+100*i);6 I& y _ y0 }, @
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
' q9 Z8 e& B. L) n3 A& Eline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);9 \3 \/ ~! e* t4 Q* K7 }
for(j=0;j<num-1;j++)0 i+ J; @. z( [+ _% V
{) v' i3 [8 ~4 u0 l6 C$ V
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
3 v: ?8 c+ R1 h) a, vline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
: y* Y+ E" z3 v7 f" p [line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
~$ ], ]" Z0 R6 f5 N}; V$ Q y* E+ X: D; s' `# y" d% L1 q
}
; o2 y5 B2 g: \7 E' ?$ [: Q}/ v5 @ n/ Y4 ~3 B$ R4 I& G X* P
else if(FLAG_PF==1)8 \. t v6 e6 K5 Z, y* ^, R
{$ ~0 x+ l/ {& R5 o
x=0,y=0;5 I$ \3 t2 K6 m6 \/ E% z
for(i=0; i<num; i++)
. N9 q3 y; z! P{2 H9 J* g+ y8 P8 b
t = (float)info[0];
/ c, s, r) L9 t2 I+ _+ K+ x0 g; H3 Jtemp = (t/101)*180;
5 r8 A: [: Y8 l2 F7 Y" l' D, mpos[0][0] = (10-num+i)*50+x+650;
7 o. z5 j6 V' T, [pos[0][1] = y+210-(int)temp;
# n. a) h( b2 u! C% T2 }% [. x% T: b" Pt = (float)info[1];
& a# a5 p( Z- e! ~6 f6 ?temp = (t/101)*180;
. [* w0 z* \1 D9 k, Spos[1][0] = (10-num+i)*50+x+650;
3 j) S: G7 N: Z3 epos[1][1] = y+420-(int)temp;$ i7 L% {2 |- J4 P. z; G
t = (float)info[2];2 Z' p8 e/ h- O' U' n9 \8 b) {5 u% H
temp = (float)(t/101)*180;2 A) s3 l$ l* z+ W# ]" l
pos[2][0] = (10-num+i)*50+x+650;6 f; a& M0 y/ c; u
pos[2][1] = y+630-(int)temp;
+ G3 k5 }! f# v+ i) W4 x! {# @( L}
0 @2 y2 V9 q2 L/ I/ v% Q0 Q2 Fclearrectangle(x,y,x+1200,y+650);! Q; h2 G% @9 `9 Y+ y% R
settextstyle(40, 20, _T("楷体"));
2 r# R* O7 m( k/ J) ^: Z; A& bouttextxy(x+50,y+50,"PF");/ k# ~) H! O6 Y1 l5 P# x
outtextxy(x+280,y+20,"CPU"); //画柱状图* y7 t l) D0 |" m
outtextxy(x+285,y+20+200,"IO");
8 W' k" @# g% r5 Couttextxy(x+250,y+20+400,"change");& B+ E, G9 [9 h! p; X( U) g& Y
rectangle(x+270,y+65,x+330,y+215);# L9 p p% t& A9 V+ _6 ^
rectangle(x+270,y+265,x+330,y+415);$ S5 M- c$ |. j0 D2 A8 s4 Q
rectangle(x+270,y+465,x+330,y+615);
8 c5 s0 R) G- N; N2 z$ T% jouttextxy(x+290,y+620,"TT");8 {; T& M% \% Y5 O1 Z( A; V! w' o
t = (float)com;5 u# T' ~. t, C; `! ]9 i6 t
temp=(t/101)*150;
- j: e$ ~) E9 }8 w2 q9 R' z$ Lfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
; P# b3 J; C: D/ B% a2 ~t = (float)wai; h. ^' B" z- }# K: n2 a Q
temp=(t/101)*150;
! |0 n9 \3 f. } m) r tfillrectangle(x+270,y+415-(int)temp,x+330,y+415);
S+ d2 o: G3 B6 ^t = (float)cha;
; B L: R/ M0 A( H, E- Dtemp=(t/101)*150;
{2 _- z1 o5 T" k& _0 Z* `8 _3 sfillrectangle(x+270,y+615-(int)temp,x+330,y+615);& r# a5 x7 Z; w/ J
for(i=0; i<3; i++) //画坐标 high=90,length=2503 S3 A. |" `" H3 Z, f- y
{1 J3 i5 G9 C7 o, B
line(x+650,y+210+210*i,x+1150,y+210+210*i);1 Y9 T' w# V5 O- p
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);; a0 L- x* |2 c9 h
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);' `' n% |! Q+ z( |- x5 H/ {/ l
. T( a2 L# [! Z0 u( T- O! Kline(x+650,y+210+210*i,x+650,y+20+210*i);
! A% s: Z/ J# P- `line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);# Y: \( a/ t. J
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);* B9 \7 E" @+ r) A' e& j/ Q- }
for(j=0;j<num-1;j++)7 @+ t9 \6 \+ N/ w( _7 Z
{
' P' o! V8 G: \% A' M2 oline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);+ ~) Z: }2 i8 I4 l' ^1 O
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
' ^. h$ U# ~1 z' o6 u, [line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ) H5 c' ^8 t+ F$ J0 c
}8 t+ f% i" V+ R$ |( k
}
- H( e6 g2 ~! ]+ `# C7 m& Y}8 w2 {3 _2 ^* I$ ~' x$ o3 F, i
return 0;
* p s* H0 v' j}; Y- p% g: b. u
int drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)/ w1 Y5 A. _" I0 ]+ p
{
5 H' Y6 f! E; F1 L3 m# r+ \ ustatic int info[11][3],num=0;/ [ q2 j; @( R* x8 c+ y w
int i=0,j=0,pos[10][3][2];! r2 |" H: b4 H2 A' [- O1 W
float temp,t;. H7 H/ r0 @% s
info[num][0] = com; k5 C6 ~& O8 q4 j) g; v
info[num][1] = wai;: e% b+ T& q! ^5 M2 f
info[num++][2] = cha;, {9 N# c3 S& g4 O! b. l
if(num>10) //存储10个点4 s; N3 G! K! f$ f& S' f
{7 o# a: U+ }* g' g6 J( b
for(i=0 ;i<10;i++)' T+ [! P$ F6 c1 o& o9 p5 C
{
1 G2 B' |6 b1 K8 V/ kinfo[0] = info[i+1][0];4 e$ D, G0 l; U) E {- B
info[1] = info[i+1][1];
8 W2 c6 k; h2 O1 D6 j9 N" {info[2] = info[i+1][2];/ K1 f! C% G6 D% M( g
}' t1 t- D% C5 f6 ?+ y( F1 J
num--;3 v2 z9 }, P" N
}5 M+ t0 v+ t( d8 P
if(FLAG_show==0)# e$ o* w7 V) i$ d. H
return 0;* T( Q! e; E6 v7 p8 D
for(i=0; i<num; i++)* I3 Z' t* v' Q/ H6 X2 \4 o# T
{- z; A" K- X! L6 W% k
t = (float)info[0];
# v$ l% v" N0 L5 wtemp = (t/101)*90;
7 j- j+ t6 N- S, {. m% R5 s9 K( Q$ {pos[0][0] = (10-num+i)*25+x+100;
9 w( l1 n0 M- l* B0 Lpos[0][1] = y+110-(int)temp;& T a2 L+ r& u1 P5 F" U; ?
t = (float)info[1];
4 _8 _ w3 B# [temp = (t/101)*90;
( k* F2 j6 W+ x3 U2 g/ G! Rpos[1][0] = (10-num+i)*25+x+100;1 N) m. o% ~) n2 l4 ?% b0 v
pos[1][1] = y+210-(int)temp;
) Y* |# I' i" y& G; {7 q( h+ \5 Nt = (float)info[2];
( I, g! ^! `0 h# Ttemp = (float)(t/101)*90;5 ?+ C; I2 ?6 u2 c I" I
pos[2][0] = (10-num+i)*25+x+100;
3 x' D. y4 D }9 epos[2][1] = y+310-(int)temp;
. ~) Y" M m8 f% K}& U' H3 p& ^' n# B$ Y( _% n* ^4 j: J$ u
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)# v$ ~" c; d: k' r
{
( _* D5 P4 P5 v g( e) jclearrectangle(x,y,x+400,y+315);
/ x% {! s& ?) Q. v% isettextstyle(20, 10, _T("楷体"));% L, v9 Q8 |4 w5 S, ]' j8 i5 `$ b
rectangle(x,y,x+400,y+325);
( A5 d* }$ l" e$ b8 t7 zouttextxy(x+40,y+10,"CPU"); //画柱状图
( G2 f$ B+ d2 Aouttextxy(x+45,y+10+100,"IO");
]2 a. l/ v- @( E: C' m" ?0 }outtextxy(x+40-15,y+10+200,"change");; j7 u' C/ ?/ k( l+ g
rectangle(x+35,y+30,x+75,y+110);% P' w8 s! }9 ^7 L) y q( p
rectangle(x+35,y+130,x+75,y+210);
) ~. _! z0 r1 D# Frectangle(x+35,y+230,x+75,y+310);/ H' A/ c. P4 z( y
outtextxy(x+180,y+310,"SJF");
2 L( ?! r8 A5 K: S& Nt = (float)com;6 ^* M; X: ?+ e; I& Y( O
temp=(t/101)*80;/ W: [; k0 B f f5 [
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);7 t! o" ]' s- g0 B8 h
t = (float)wai;
y/ b6 G4 T1 U$ l' Ztemp=(t/101)*80;
5 m8 G: `' d2 i3 E; Yfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
: A }. b2 W$ ft = (float)cha;
6 E$ D6 {+ @. _( L. s Vtemp=(t/101)*80;; r) d- R" O* T [
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);' a" d: O) e$ y0 f
for(i=0; i<3; i++) //画坐标 high=90,length=2502 w8 e+ R# U1 L7 I
{
3 j5 C/ c& J) h1 B" J- wline(x+100,y+110+100*i,x+350,y+110+100*i);' w. I# ^/ G" |* t
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);6 H3 h0 H9 g0 [0 h
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
7 J' v$ G* v* M$ I) ~ o! m- Y$ f! m& j
line(x+100,y+110+100*i,x+100,y+20+100*i);
: P' o8 h( b/ d% zline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
; c3 f9 _* G% k% S; S; ? f7 oline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);7 O" i1 W& \3 d) I
for(j=0;j<num-1;j++)# f. f# f5 ]* R5 j& ~8 j3 T
{
6 f/ `3 T3 c: E, K, Tline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
. I: N& |4 R, L5 t, Iline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);( ]: ]4 Z: j- C& p
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); : s( {. `+ }/ F; W1 R
}6 m5 [, N; O6 R, ^) |
}
% @, K6 w$ Q! R; X- U! O7 U}
8 v' @7 c y9 j. Eelse if(FLAG_SJF==1)
) b: B2 [, ~3 K1 N7 j{
. Q8 T8 O: _, }/ ?" O) l: ~/ zx=0,y=0;
6 g0 T- w% X4 O9 Z8 L- X4 Afor(i=0; i<num; i++)3 Y8 q- @9 P+ T
{
0 E x8 L) t& d& a; k# d0 Pt = (float)info[0];
5 r2 p+ l) E( Z/ z+ ytemp = (t/101)*180;' q$ Z$ e+ d7 G6 }) C
pos[0][0] = (10-num+i)*50+x+650;3 F% r1 _ p6 b7 i. |8 E
pos[0][1] = y+210-(int)temp;" |5 }. H9 j7 O0 z: u" J
t = (float)info[1];
" @$ E5 Y+ F, K, y; L R' Otemp = (t/101)*180;
1 p, g' _, w( F( S1 Hpos[1][0] = (10-num+i)*50+x+650;
7 {9 T) [; q& o- H' ~3 }1 Vpos[1][1] = y+420-(int)temp;
6 e& r7 Q3 t! W3 p: ^" Pt = (float)info[2];' L% H# X6 k8 k* R+ [5 _ }) y
temp = (float)(t/101)*180;
% h7 F4 \" y& L7 Dpos[2][0] = (10-num+i)*50+x+650;" [; O5 U9 p6 R3 H" a0 {- `# p3 S
pos[2][1] = y+630-(int)temp;# S6 R" t- ~) \
}5 e! o5 B1 {) [4 h% p3 F
clearrectangle(x,y,x+1200,y+650);
0 n5 L2 R+ K8 | F6 o; Ysettextstyle(40, 20, _T("楷体"));
$ e4 q8 O/ j* D; _; z4 ?$ Qouttextxy(x+50,y+50,"SJF");6 f' s/ y0 d% j1 d5 K7 x1 M
outtextxy(x+280,y+20,"CPU"); //画柱状图+ L2 s3 S* T: I4 G6 C& ?4 z; Y+ Y( Q
outtextxy(x+285,y+20+200,"IO");
" g' n; z5 @4 iouttextxy(x+250,y+20+400,"change");" `5 _' h; Q$ B' v5 O9 G, |% b
rectangle(x+270,y+65,x+330,y+215);; D9 \) v% ~+ V! a7 E
rectangle(x+270,y+265,x+330,y+415);3 t) b% C* o9 {; ^5 m
rectangle(x+270,y+465,x+330,y+615);! v3 g+ \' ]" E# `% v7 i
outtextxy(x+290,y+620,"TT");
& P. q T# e, E: o+ Ot = (float)com;) |8 ?0 U1 Z- u4 q
temp=(t/101)*150;& B/ y ^8 k) E7 |" J; L, v
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
5 j6 T9 O9 E' i) r1 a- F/ dt = (float)wai;
# T5 G# s( B- P2 A! |+ z# m+ P, I: Btemp=(t/101)*150;
& k! S9 {1 r/ t. O" a7 Jfillrectangle(x+270,y+415-(int)temp,x+330,y+415);
% I1 e% L9 u% r: t6 tt = (float)cha;
" C' R3 v4 T) j2 K+ {, P Otemp=(t/101)*150;0 b9 L$ H# _ E: d. L' o& `
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
/ y) I) U6 q& m) Zfor(i=0; i<3; i++) //画坐标 high=90,length=250
; U/ O. K; v! M g{
! r! e# m6 m1 A& _line(x+650,y+210+210*i,x+1150,y+210+210*i);$ X& n' g _" L2 X! q; u7 x* j9 @
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);3 c' E ?* `/ L3 ~6 z) g& Z3 L4 f
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
+ x9 x; {) o- J$ G6 n- M0 c7 ]- _7 y% y$ n$ G' Y" N% {
line(x+650,y+210+210*i,x+650,y+20+210*i);. A* v# y1 W& ]6 d% o7 U
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
1 [) i* U$ z0 D- nline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
) L' s/ Y6 H* @" s- Jfor(j=0;j<num-1;j++)9 E6 Z/ y% j$ R+ M j. F8 @
{4 i2 c: N% p; `: [6 Z* z- [
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
. F0 o' [ l0 [line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
2 C% o: z% q1 i7 X" q2 `5 X+ I( B/ B6 Qline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
! o& Q% } C& }. C" a# T6 P}" q2 {- B' R, I, j* f! [% [# K
}
8 x! L8 Y- S) f# ]0 w}
o+ b2 ^ P% m1 q6 C+ j0 Nreturn 0;
" B- d: ?; O8 G5 N}2 M. `6 P: ?) |/ F& d0 f* Y) b
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
* b0 U) D( H5 S{* ^5 h" ^: c/ Z1 c7 n1 |
static int compute=0,waitio=0,change=0;
; ]% A# Z. v- e+ U$ x, X3 z9 ostatic int computeLast=0,waitioLast=0,changeLast=0;
" p9 R/ R P+ v. {% M2 @1 n$ a+ \( Hint i=0;
$ Z) P5 L* s3 E7 r1 \, M! hif(draw==1)$ ~% C$ B2 D7 R7 F
{
- L: E( O! S `: v//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
9 x% k4 a5 h4 wdrawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
' L& I, i" b7 |, n1 G* ]2 ^computeLast=compute;0 D y- [) n. b' Z8 k
waitioLast=waitio;
2 N2 a% `9 G& T% ]% ] { XchangeLast=change;* W# \6 o' h; @1 U$ \
}0 K, b4 X# E4 t* F# D
if((* memory).p[0].flag==ready)
6 K: _% I& r2 r5 s" ](* memory).p[0].flag=computing;3 Q- S3 T3 }. m6 D
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)' ?! a: a) P, w k- R9 h, }
{
& _9 I0 _. l7 ci=(*memory).p[0].computeNum;) i a( |$ a/ b8 y- j
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
9 x( ?+ \7 z/ c. w2 e/ @7 @5 ~{9 H; v2 e9 k% x% Q- E0 x/ ~
(*memory).p[0].flag=IO_waiting;
}" u0 x- c$ I, `% [(*memory).p[0].computeNum--;
- U- B% B P$ t( jchange += exchange_IO_Compute;& L2 ^# k2 z E5 r6 |8 S" d
compute++;
9 J5 a7 p. M" n" P R, r}; `. p8 w N4 k' C
else
# B4 w; d# {" E; H% o" ]2 f: X{' ^3 F; @- S# T" b5 Y$ d
compute++;
/ |5 N0 B! U5 R}
) C8 u9 g$ ?. t}6 q1 E: }% E( e' O5 z2 X; A
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)( B0 V* _: P+ Q& e- a
{) B4 y- v2 Q, ~" y; T; U0 T
* ~* N) x# A: I; U2 i: D
i=(*memory).p[0].ioNum; Q$ d, f4 @# E% m# F m: T
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
8 C" @) A/ S3 R4 P{
+ u: [5 L. @2 t8 I(*memory).p[0].flag=computing;7 H4 M1 L0 `8 U1 A# v) @; K
(*memory).p[0].ioNum--;
% l1 y# T: V, p+ T5 o- M# M2 N: \change += exchange_IO_Compute;
( E: m+ W% F: O% n4 ` m# d" H& Dwaitio++;0 R. b% R1 j2 o' i: u; L/ _, ]
}( g0 J, i3 v; G( a$ T0 P: ^* j. U
else: r1 w" r: N4 x# }7 p9 r
{* G: w: a6 y6 I9 G! i' L! }
waitio++;2 W1 C q$ G% _- U- t1 ?! c
}
# |6 S: o C; s. Q9 a7 E6 v}$ t' ?& B2 C$ L) h7 q$ g! B
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
, @; D7 D0 ?* j4 V) r0 Y{
. f, d# ?; s8 X" M5 W) Y% J(* memory).p[0].flag=IO_waiting;
0 w. B( f8 T- \4 Bchange += exchange_IO_Compute;) k) U! s w% R7 i
}3 n* X3 s8 W5 I t! ?6 I5 E4 \
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)/ Z+ a. M% w" r
{: f# X0 ?! Z" A+ h$ l8 \, J' L# }
(* memory).p[0].flag=computing;
# r1 N1 X3 {; R! Mchange += exchange_IO_Compute;4 \% S7 b' o! w# b* c
}- z1 p# m7 C8 C. h, P: B" a4 M- T
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
6 q' S1 z% P! [9 m0 }3 S) Y9 _$ d{! }; T1 A0 T% e# g+ q
(*save) = (PCI*)malloc(sizeof(PCI));
. ?2 K+ Y0 ?& A5 ]+ Z0 H(*save)->next = NULL;' L" |* G4 y& e0 U& e" X: n( `
(*save)->processID = (*memory).p[0].processID;5 r) q5 |8 S) P2 d: y
(*save)->comeingTime = (*memory).p[0].produceTime;! p; h4 l! C+ m$ N
(*save)->askMemory = (*memory).p[0].askMemory;/ K& ^% y* @0 D, q+ E; F
(*save)->compute = compute;3 h, A$ S7 j. }; u; }/ Y# l' g
(*save)->waitio = waitio;# d% P: ]9 L" C
(*save)->exchange = change;
* B$ b0 ]& R' `& S. J(*save)->completedTime = systemClock;
9 e0 m$ T# L6 Y* L. t6 r(*save)->runningTime = (*memory).p[0].runningTime;
1 u [/ l2 m4 ~. G* l) o*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;
1 |+ r* r+ h) xcompute=waitio=change=0;
( [5 h6 r V; ^computeLast=waitioLast=changeLast=0;
( t: j/ R. J0 b: HHigh_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);
6 _$ M" u) s- E* w; {6 n# vchange += exchange_process;' z b/ X$ ]' w
return task_completed;$ h6 p. o. H: w
}
+ D8 E5 ` A/ F. D' w7 ?$ celse Y# y" u5 y; g
return task_not_completed;
2 Q9 K3 q3 L6 ?1 U9 R}
3 x8 x. u d6 G/ lint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)
2 h' I5 t% m+ a' H7 t- J- x$ M{
5 c% z0 U5 j6 \static int waitTime[initProcessNum],i=0,j=0;
6 g" S" N/ p* qstatic double HR_ratio[initProcessNum];
5 ]2 |" @: h2 H8 {# T4 Uif(flag==0) //初始化数组1 a) ~% ?: p3 I) S" w' ~7 l. J
{
& H9 _ K1 j& P$ ]4 U9 ?% o' Rfor(i=0; i<initProcessNum; i++)% W6 S; ^9 U. `0 Y2 O: I# C2 U
{# a, w+ A$ ^8 _: _5 M
waitTime=0;7 j2 j" J: Q/ k2 O( `
HR_ratio=1;1 K" H' v! h9 k' W
}
' [+ C$ [# Q5 Y: ]% n" j* b" v- w6 W) `}; F& y+ Z1 c: D" r# D
for(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比
0 V! r& |, }2 W, V{
; X* u" i& U. ?) Y- ~$ N" KwaitTime++;9 |$ G! H) S; A* z8 X" _
HR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);
; ^" ?/ C" @- V# Y9 V' }. P) s$ Mif(HR_ratio > HR_ratio[j])! M! i4 Z+ e2 @1 O; p# b
j = i;9 S- x/ B" v# y/ c# N" l
}" C% d8 B3 t! @
if(dispatch==1) //需要调度一个进程到内存中执行0 J# s7 {* R8 t3 Z
{
0 E8 _! X& W4 U' e& Jif((*storage).p[j].askMemory < *spareMemory)8 n8 y9 Z8 _$ | o3 W% a/ W2 v
{" [" g* V/ F* |6 P3 t- i
(*memory).p[0].askMemory = (*storage).p[j].askMemory;
9 E) ]! J/ S" B9 Y$ q(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;) \" I% D" ~; r- B4 f! B( J
(*memory).p[0].computeNum = (*storage).p[j].computeNum;, l( W! r; @8 l$ ^. d. ~, X
(*memory).p[0].ioNum = (*storage).p[j].ioNum;( X, g4 r9 [, H1 M3 g
(*memory).p[0].processID = (*storage).p[j].processID;3 q% D3 P+ J6 W5 T1 s' a7 [
(*memory).p[0].flag = (*storage).p[j].flag;
) e0 _/ Y' j. X: ^. A. J(*memory).p[0].ioTime = (*storage).p[j].ioTime;
1 p) H2 h9 `$ k7 C8 \(*memory).p[0].computeTime = (*storage).p[j].computeTime;1 X5 h4 T1 x3 s5 e4 C2 Y. x
(*memory).p[0].runningTime = systemClock;& L' C$ M; S% W1 v6 K J* l
(*memory).p[0].produceTime = (*storage).p[j].produceTime;7 ~4 o+ G/ @1 i* B9 B3 L
for(i=0; i<(*memory).p[0].ioNum; i++)- {2 E: T0 B5 ]6 w( ?
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
& I4 [2 B6 j4 e; y& V) i5 h5 cfor(i=0; i<(*memory).p[0].computeNum; i++)
, G( |$ n# w% S$ o% k. ^(*memory).p[0].computeClock = (*storage).p[j].computeClock;
6 q" e% \3 X# \" y(*memory).proNum=1;
. G: h7 i% K7 d8 `5 U/ ^5 R*spareMemory = *spareMemory - (*memory).p[j].askMemory;- K8 m# q) W8 Q; v8 N/ A$ N" q
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程( m" w, v: `5 g$ q8 }2 Q# s* I
(*storage).p[j].produceTime = systemClock;
4 S# Y* V( l- l2 r' p! LMAX_COMING_TIME = (*storage).p[j].comeingTime;/ K5 ~6 [$ {1 Q# s( z
waitTime[j] = 0;
" A' t$ d) p- h* B& h6 G, lHR_ratio[j] = 1;
/ I5 e. ^ N3 d1 R* W; m1 o1 t}
8 k/ A V" X2 i: ?2 l; ^, Pelse" p9 M1 k1 l" N" K) p! ^
{
$ U5 H% L+ r; E' t* @2 Iprintf("A process ask for a memory overed the system capacity\n ");
5 T' w1 [: M+ `; |$ x2 b" ~exit(1);9 Z% W" w: s& n" R) A$ B
}- q( x# X! A/ f+ c7 W0 G7 z7 f
}
" h4 g9 U/ q$ H# H8 N( ~+ wreturn 0;2 V, H- P2 E2 v! |4 h
}: C4 s5 c3 h: \8 h2 A5 Z! o+ m) m, ^
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
; m9 c' Q9 t* i{
7 J D% N* @' m3 Rstatic int compute=0,waitio=0,change=0;
' j7 |, H" q! s4 \: r' @8 Estatic int computeLast=0,waitioLast=0,changeLast=0;+ c0 t( _( E6 n' ^5 k
int i=0;
: U" t! {5 `4 qif(draw==1)6 c/ s4 c: G$ |; y5 r; H0 O* d
{
# H i: f, S( U//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
- \' Y8 r3 S2 d# \# ~( sdrawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
1 o( k$ W7 l8 }) E: N* @% l- A8 J( u( F: d9 E, j
" U& K+ d/ v9 H. T ScomputeLast=compute;2 S# o! W5 M- o! k6 q
waitioLast=waitio;
9 F# L/ d" B# {( EchangeLast=change;
- J2 h) r6 y2 _; J2 s0 V/ Q}
; e/ }8 j; Z* @4 Rif((* memory).p[0].flag==ready)
4 @2 H5 n" {' J; b B% s(* memory).p[0].flag=computing;
- g) ~* U! w9 z. p5 n4 {if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
6 _! T8 V1 j; B( ?# e{( R/ @0 G) r% o1 \( ~1 @" j: e2 O; V
i=(*memory).p[0].computeNum;" Y4 p, Y/ j; t# _6 m+ Z
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed7 j/ q& p. Y- i3 D
{( P4 e) J p, D# F9 m
(*memory).p[0].flag=IO_waiting; Q! W' o" {7 y- }1 q
(*memory).p[0].computeNum--;( `: e# B% @/ C$ d5 ~% s; M
change += exchange_IO_Compute;! C" y; o8 M- _6 B. u5 d8 V% ^
compute++;
2 ^4 M5 ?# _/ [4 O: H/ s}
; y; V! t! C; @! Eelse
/ Z7 x2 g: F( m5 k. b6 o9 Z{
1 l% d; `7 [! o1 @compute++;6 R* B& a" E6 `4 z! Z
}
+ h0 d" R# `3 `; s' M}2 e# H2 v3 m$ |0 Q& M2 X y
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)3 A9 V9 i1 J8 }3 \" f" K
{/ E5 `) a# x' R, m! f3 I8 W
; n: v/ w2 y' X7 k8 E
i=(*memory).p[0].ioNum;* z/ B; b/ p; e
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed2 }' ]7 x( E8 P- @+ X
{$ {5 `) j7 ]8 T t" R! M- M
(*memory).p[0].flag=computing;
' R: L+ L' }2 C2 T(*memory).p[0].ioNum--;
7 |# ]3 ]% K3 U- S( Wchange += exchange_IO_Compute;9 U/ F) f' W, T5 | _
waitio++;
6 L! @& Y# }/ u T1 H2 a% Y% ]9 v}+ y! f5 D" b' Z+ x' y) A% l: C C( B# D
else
1 L+ x) q; ~3 ?# t3 o{
! p& R0 b1 n. i1 y% a: xwaitio++; R" w. m* G( ^+ E" s/ z
}
5 r" \ q6 V1 p}' j0 h) v4 O( l/ A3 E8 a; j
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
, m! p! w0 l# k2 N2 T% s) j; a6 u7 z{
5 P- I& M( K0 k4 C7 I! H(* memory).p[0].flag=IO_waiting;- R7 D4 Y4 x+ K! H, N: y8 H! d
change += exchange_IO_Compute;4 k' t) f0 r$ N; n: E
}
! e0 Y! W/ X& B) Velse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
. l; O# h! B5 I{
+ G p. J0 L* v! t+ ] I q8 Z6 b(* memory).p[0].flag=computing;4 r: c& O/ P0 q3 O+ @
change += exchange_IO_Compute;2 L2 a5 z( a# O$ E# L
}
" {! H" T2 U# d) H# k8 |; N2 tif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
/ H" B) ]4 e! y [# I- x{
1 G% X( w% g( I( S+ \(*save) = (PCI*)malloc(sizeof(PCI));7 q1 u% U$ C, l# U
(*save)->next = NULL;
4 K1 Z. s6 U" G, e# Q$ d(*save)->processID = (*memory).p[0].processID;
]! w7 v3 f% _- T- A$ Q(*save)->comeingTime = (*memory).p[0].produceTime;& w- r+ n S4 _4 M; a( V `& A* c J
(*save)->askMemory = (*memory).p[0].askMemory;
$ _, J! w: L, [: Z7 I: e(*save)->compute = compute;9 ]2 ^" N3 z! P2 i
(*save)->waitio = waitio;4 v V: Z1 W$ P
(*save)->exchange = change;0 C3 m8 {; W! D% _. y/ f6 z& y
(*save)->completedTime = systemClock;
! W1 |3 ~: T' J(*save)->runningTime = (*memory).p[0].runningTime;
1 i9 z, y: B1 @ x9 V$ Q*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;
7 Y! t" X8 a) [8 W) j) Fcompute=waitio=change=0;: \5 @& Y% z2 B
computeLast=waitioLast=changeLast=0;
7 d1 i! C* K; f# A1 mPriority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
7 J: o1 K! Y. ]4 wchange += exchange_process;. g: {2 C9 z c2 P
return task_completed;
/ ? B3 u' l3 l1 C4 o}6 @1 m" ?( V6 d m' M' } C
else
: t/ ~, K! \9 u. f& T- \return task_not_completed;
1 l( }$ v. b2 G$ |3 _* l( p; E1 F}
. R1 _, _; e4 Y$ K$ P, ?7 N) Oint Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)- z( U/ c% I7 _! t) E. {+ B# |6 C- l
{
) ]' p; D' h1 A5 mint priorityNum[initProcessNum],i=0,j=0;8 R1 n% T" I: Z5 H8 u2 u
double temp=0;
3 n# q6 b- N% I; Efor(i=0; i<(*storage).proNum; i++) // setting priority to each process
7 c8 t+ F5 Y- L5 P{
# _5 I$ ?1 S- {. c5 j# gtemp = (*storage).p.computeTime/(*storage).p.ioTime;( K! c- s* }' M" o' w, u
if(temp > 0.8)
* m/ y; A, m y+ E- ^7 `priorityNum = 6;
9 {" v. v1 w& F$ y1 z3 n$ ~8 g/ B3 yelse if(temp > 0.7)
# g# X9 j$ K7 Z: P3 G8 O7 ypriorityNum = 5;! T+ X7 |$ W1 L3 Z; y
else if(temp > 0.6)/ W# s% [9 T* q1 N- a4 |) L$ b- _/ M
priorityNum = 4;
3 t9 x. B% O" s$ T" @- L7 jelse if(temp > 0.5)% J6 B# Z+ G" L; k, l+ J
priorityNum = 3;
9 D9 \. j) Q7 ^) J& @: }# T0 [6 }else if(temp > 0.4)0 t& j, ~6 O7 ?4 M
priorityNum = 2;( p3 D' u! c k3 D6 {! K
else
4 Y! @; O5 ?; |+ @! `$ x( f% TpriorityNum = 1;+ ?0 e) n y" d( @ R
if(priorityNum[j] < priorityNum)
, {, O1 q( j4 y- u# J' e/ F8 ?j = i;
7 Y& G, C8 I) i}3 [) v- G9 w/ s! p; c( @' D% B
if((*storage).p[j].askMemory < *spareMemory)* C {, w: ^5 W8 a$ U( U8 q
{, R& V: V" c, L
(*memory).p[0].askMemory = (*storage).p[j].askMemory;3 J: [4 h2 ^* f. W' h! m
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;+ N6 P, j5 l& @9 d _3 _' N
(*memory).p[0].computeNum = (*storage).p[j].computeNum;" I2 z7 T& M* H2 ]" [) g
(*memory).p[0].ioNum = (*storage).p[j].ioNum;* c5 X) c! B: h2 e
(*memory).p[0].processID = (*storage).p[j].processID;
& o- [% r+ N5 R8 e+ J; g(*memory).p[0].flag = (*storage).p[j].flag;
% }5 s2 ^$ J, W(*memory).p[0].ioTime = (*storage).p[j].ioTime;
7 ] [9 O+ ^1 ?& M* i4 I" |(*memory).p[0].computeTime = (*storage).p[j].computeTime;& \! v1 ~& Q; i3 o% {% ^/ q4 P
(*memory).p[0].runningTime = systemClock;
- W2 X% {1 K% S. |(*memory).p[0].produceTime = (*storage).p[j].produceTime;
' d0 ]. v0 s5 Dfor(i=0; i<(*memory).p[0].ioNum; i++)
# \) r* S0 q9 C6 N" z0 u(*memory).p[0].ioClock = (*storage).p[j].ioClock;
8 ?0 N5 f: O2 ?- p8 i5 E3 w# s; wfor(i=0; i<(*memory).p[0].computeNum; i++)
5 W, D4 P8 J; a* K/ _- Y(*memory).p[0].computeClock = (*storage).p[j].computeClock;1 s- h8 k! g! u% |3 L& o# u
(*memory).proNum=1;* {. A3 r! ]7 H; K
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
+ o' b% M. l1 |3 R. r- N8 j. _: U9 w5 Zproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
# [2 S( i9 e R, ?' q+ [% i* d. GMAX_COMING_TIME = (*storage).p[j].comeingTime;$ l3 f- q" k4 D
}
; \. j: m" g5 \6 k# w* H$ Zelse& l. O2 j4 {6 r# H% |0 U
{
% u- _3 a, P+ Jprintf("A process ask for a memory overed the system capacity\n ");
& q& U3 M, K7 ~* @+ o0 V! g' _exit(1);! f) n9 ]8 ^ N6 {, D# j
}
/ F% H" e& a5 }/ M! P5 V1 _: _return 0;; c: s( `6 g$ O9 y+ x4 o3 j
}4 X1 G2 r, D7 W# }& V
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)8 L b* ?# O, ~% N; p; C i4 f
{: U) e5 P- _" B& x0 Q" s4 a" V
static int compute=0,waitio=0,change=0;
' J' w1 v% b9 o" d& A Ustatic int computeLast=0,waitioLast=0,changeLast=0;1 s5 O0 r5 G+ J) @& \" o
int i=0;
9 A' e) E3 S; T; c) |if(draw==1)
: N4 F) D) E5 n$ v5 \{
( @; V7 T( _9 ?* o: P7 _//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);$ Y4 x) N4 B- c! u9 @1 f+ s. R
drawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);. J8 Q d+ n% ]! k, }
N/ h2 |, w" }* E; b
5 x" X8 s) R) Z% L) A1 N- u
computeLast=compute;
/ z6 B3 T c% LwaitioLast=waitio;" n, v/ I' b; |/ D! E i, b# p
changeLast=change;' r1 ^) _) D' y2 \
}
3 w. {3 R: x# O0 K+ Qif((* memory).p[0].flag==ready)
. t6 H. B+ j1 b+ j' ~( G; t(* memory).p[0].flag=computing;# O0 A4 M5 i2 P/ O5 s+ | d
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing). |, R3 Z' e' A% ]
{5 z! K5 j# f, A2 v, j
i=(*memory).p[0].computeNum;
% o" P# V- @/ g. Sif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed4 G/ B( ~) x& A) r2 r
{
N' c* L. L( q( D; _6 _1 B(*memory).p[0].flag=IO_waiting;1 p1 B" b: K! j" r
(*memory).p[0].computeNum--;
4 \9 Y: l7 L7 c V( a$ k; Bchange += exchange_IO_Compute;
3 z9 w) U6 X/ y1 u3 A- [) Acompute++;
9 R/ U K: F# `; U, h}* e4 _, f9 \3 O$ ?# t; ^8 W1 A
else
- i! W- E: I/ n7 y{
3 h( S# @" h4 Y% f5 z/ n' e F2 B% ^compute++;% V" k, j. G: @) f& y- P/ H
}+ l8 Q$ q5 T0 Y+ a4 @6 G/ d5 J
}
, c' }! [! m: M- h& p. y) k9 Ielse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
+ u6 g/ k2 M+ d! y' S{' y2 V' P. a+ v; c4 m8 R& x
& q( \ I# f6 I% V6 K- _& I+ z
i=(*memory).p[0].ioNum;
+ b4 ~) b' U# ]' |& m' i5 \* jif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
1 e; H+ x# P/ v6 E- F' X$ n{
: e0 C$ Y) \5 c5 j* h% \(*memory).p[0].flag=computing;, |( O' x% z6 Z5 m5 @9 t% S
(*memory).p[0].ioNum--;
$ _2 j4 n/ c; ichange += exchange_IO_Compute;
; \5 n, S+ t4 W0 r% [4 Uwaitio++;* X% k( p" X: g; q( t4 o
}
) ?$ v+ J5 ?5 _& a) ?( Ielse
, H4 s' z0 G" T( E' w{
! @' \& J4 D! I% e% ~* ?waitio++;
! X2 d: r1 M, {9 X( `0 f}
1 ]. W5 _9 ]0 z% z0 p% e$ i}# u, G# o" ?+ Q" s8 v) j
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
- d: t3 C) A) p* T" i9 o{8 x& H* s$ @( m) s2 Q* Q0 r
(* memory).p[0].flag=IO_waiting;
3 x/ {' F! a8 o: r8 ^change += exchange_IO_Compute;/ ~2 k' O# U6 x( r! B5 j7 n
}1 f. I9 @$ y, V# H' N# x7 N
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
0 L6 R; \3 X, P& s{
6 }) ?% }+ p8 V4 n! J(* memory).p[0].flag=computing;: J. b! X0 t ?
change += exchange_IO_Compute;+ L* `' v$ x# b9 W& D8 n D' L
}) ]+ P% X9 F! ^: S \
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成- l* p- ~# N7 F6 K
{
9 d! i( f( [* I; S& t(*save) = (PCI*)malloc(sizeof(PCI));
+ X, t. L: H9 R0 L0 Q! L(*save)->next = NULL;5 o6 ^. G) J) B; R4 A+ D
(*save)->processID = (*memory).p[0].processID;
) v5 z2 C0 R9 Z7 b(*save)->comeingTime = (*memory).p[0].produceTime;) }. h( P; J* G- S7 A8 k
(*save)->askMemory = (*memory).p[0].askMemory;
% ?2 Y6 z( l+ C( J% a(*save)->compute = compute;
# r$ x$ `' x9 f( Q h9 x, Z$ K4 {(*save)->waitio = waitio;4 d/ X! m3 j% _( b- N2 w, O
(*save)->exchange = change;. r- T% Z m2 V7 g# O+ [: a1 H
(*save)->completedTime = systemClock;9 R4 |5 ?9 \: s/ ?, d4 C
(*save)->runningTime = (*memory).p[0].runningTime;1 k8 ^6 ]' M" M2 }1 N- l+ i
*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;! \- \* S. o/ M+ b
compute=waitio=change=0;6 X1 K* @1 x1 h7 E" r- Z
computeLast=waitioLast=changeLast=0;$ w- m b, j; c; i6 F6 K3 ]
SJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));& R$ T$ i/ d* l0 M' J ?6 i/ E
change += exchange_process;% G. V! _( |$ `
return task_completed;
- F. m* |6 v+ K4 @2 l. e}8 h% e7 m4 a$ P0 b! p
else" I/ K6 e) e& F; N
return task_not_completed;
9 y/ Q O1 b/ K) i, W! B* p) S}
% \0 [" I6 o, g% q2 eint SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)6 e- q3 W7 t9 e: H+ ~
{
8 ?$ M. G1 x8 Z; [+ K3 s# {! oint i=0,j=0;1 R4 l$ y8 ]3 h V6 s3 s
for(i=1; i<(*storage).proNum; i++)
1 k! \* q3 o" x1 c7 ~7 X{8 a1 Y, W; @/ y
if(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))( a7 d% o3 |* {. j* h* Y9 e. [ ?% s6 Y
j=i;
" Q6 ^' U$ d9 }; S) A- e}5 Z5 l* k. e `2 y* ]" F
if((*storage).p[j].askMemory > *spareMemory). W% T% G7 ?5 a/ h2 b9 C, M
{1 K9 Q4 |4 d. O: ~4 C S3 A! V7 u
printf("The memory asked is overflowed than the system memory.\n");
) z; {" p* D" l4 S3 rexit(0);
* @# t0 @/ n: a8 H( D8 i" M% L}
4 W6 |* s6 ~; v% Welse
7 t0 y2 b$ }5 v. E2 ^{
2 P; S: d( {7 f! L1 u% b$ M) e(*memory).p[0].askMemory = (*storage).p[j].askMemory;( g/ X/ M+ N8 y; r- y4 `
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;. B5 ^9 ^7 h! ~! G; F8 K
(*memory).p[0].computeNum = (*storage).p[j].computeNum;
' t8 o1 L8 z% a# ~; F8 b% m(*memory).p[0].ioNum = (*storage).p[j].ioNum;& W( v& s) W8 j1 L& _ v
(*memory).p[0].processID = (*storage).p[j].processID;7 v2 G. D/ x- w1 R! Y
(*memory).p[0].flag = (*storage).p[j].flag;9 I) O5 d% z) m/ N! R# Q1 ]
(*memory).p[0].ioTime = (*storage).p[j].ioTime;; d e; z! X/ W9 ~
(*memory).p[0].computeTime = (*storage).p[j].computeTime;
$ o" i5 q; M; Y. V9 j(*memory).p[0].runningTime = systemClock;* b% I. D4 D7 V/ M9 q; ?( T6 p* |# r
(*memory).p[0].produceTime = (*storage).p[j].produceTime;
3 b! T5 w' z4 d1 r6 y+ W3 [& i0 ofor(i=0; i<(*memory).p[0].ioNum; i++)
; I. e! s/ K5 t+ t& V- K$ Q5 P0 K(*memory).p[0].ioClock = (*storage).p[j].ioClock;8 H+ Z3 e8 ]! E
for(i=0; i<(*memory).p[0].computeNum; i++)
/ B; y d2 }6 t) l(*memory).p[0].computeClock = (*storage).p[j].computeClock;
2 b% K" {; @( I2 Q8 d(*memory).proNum=1;. Y9 s! _5 Q' F. w/ ?5 z8 m L, [
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
& K4 Q# u y/ Y) Oproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
( i2 U( t3 ~( AMAX_COMING_TIME = (*storage).p[j].comeingTime;
0 q: [ |- L$ o+ k5 s# _4 ^}
/ E9 c" d/ A' kreturn 0;, C' W2 S; d& |
}
. g+ q* d( ?& X) w9 G9 vint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)& c* i* A, L* Q- c
{6 _" }" z' B, P% ?! Y3 B
static int compute=0,waitio=0,change=0,clockSegment=100,poi=0;5 {: H Y, |- x( m
static int computeLast=0,waitioLast=0,changeLast=0;
) a- L: e R: f7 z3 ]) Oint i=0,j=0,k=0;
4 O+ m$ S% w& I0 l* Oif((*memory).proNum<=0)- {" g2 y$ }8 j0 J# e
TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);
k0 Z. |( \& ]' o0 i2 Qif(draw==1)
) \! d; s6 h: Q4 t, _* _{
8 u% i1 E( \* e- G1 Z! T//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);+ B) M) G5 J- c; N9 |
drawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);! M7 W5 k% a5 O: ~( w
; a7 K7 `% X2 m/ L( ~4 w
c3 c( _: t: j) W+ u. scomputeLast=compute;; ^! x! p, T# X- W T$ s& ^
waitioLast=waitio;: `0 q# g" @ q5 _: R* M" h$ h3 c
changeLast=change;& b/ K3 }( v3 i9 X {
}
" f# D" H$ h) X2 V# h3 _$ X, ?5 P; C. \if(poi>=(* memory).proNum)) }5 L' B, w' w# K1 |. g' a5 W
poi = 0;3 e" }' h' a; o) H4 }
if((* memory).p[poi].flag==ready)
0 s4 Z4 T. D. u; ^' c6 X" }(* memory).p[poi].flag=computing;
+ B! @ }: r* Q! h# Lif((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)
7 H' @7 }6 _# \1 U: H6 t8 i# L{
$ {. \# ]# ~" `- ~! e8 c7 Vi=(*memory).p[poi].computeNum;! W1 Z0 S7 H4 h8 o$ p
if(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed
_0 J% i1 K$ h! z{
, e7 ^7 o- e1 s% K& D(*memory).p[poi].flag=IO_waiting;( \) F& [9 r" d- A2 o
(*memory).p[poi].computeNum--;
3 E- E: ^& E; L5 b7 G) ?8 {% G& M+ Ichange += exchange_IO_Compute;% k7 U4 f7 S. K- l
compute++;; L+ y+ ^& R2 d: O t$ s
}/ t+ V6 G' ~# E) ?7 l. C, Y
else. S( ?+ m& B" p" e( q6 e& L
{
|! l/ o5 ]8 I4 I" _; l9 X% Y" {compute++;: r; A! K# x, A w
}; ~, Q# d1 j6 i& M3 g+ X
}. a9 O/ x/ K. r
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)" D6 l8 r" V/ T& z3 W) d5 _
{6 W3 K2 N& T( N# o: ?
5 Y% p8 m' R- d/ @: P# x/ [
i=(*memory).p[poi].ioNum;* X* J) x% m+ ]- E8 q: y7 v
if(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
- a- F; N5 w3 Q \7 ~( y( ]{, e9 E. D8 J% J" y* v' [
(*memory).p[poi].flag=computing;
2 T& Z. `) {+ w# v$ F; z2 j1 [(*memory).p[poi].ioNum--;7 k/ h2 I4 i1 |' M; z
change += exchange_IO_Compute;8 a3 J' \; \9 [6 E- u
waitio++;
/ l2 {" F; d( X" ^3 C}! t, S7 `- G M8 r' t* d4 M
else7 `+ _/ i2 _: K: u
{% l. M4 ^. f# M9 F" {
waitio++;& H5 b- j& P7 C! a9 I
}3 W; X% @; c) f7 ?( k$ i2 Z
}- {* M/ R; S+ x( ?4 V6 z9 M
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing)1 r o2 T/ o# N$ D4 i1 J0 w
{6 c: C5 L! v$ A( G9 H7 \
(* memory).p[poi].flag=IO_waiting;( j! e6 m% d9 K
change += exchange_IO_Compute;
7 }4 K2 Q. w4 C% `( l w5 h}
. F6 `1 j, g9 Yelse if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)
: b) l: o; W" \9 J9 _5 q{* x& e9 a- N8 a$ L# f
(* memory).p[poi].flag=computing;
3 |6 \4 k# z* F. r# Nchange += exchange_IO_Compute;
9 D0 Y0 F4 z' f @, M}
1 I! ^; o! l+ D' P7 L. Kfor(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进+ X+ p- M$ B4 O/ m5 `
{; u* o1 _$ X* @1 F
if(i!=poi && (*memory).p.flag==IO_waiting), x1 f' q- _6 p( S ]! I
{- ~9 g N$ L9 i$ C8 B- w; f
j=(*memory).p.ioNum;2 b: W5 r' C$ t. s- \9 b; j- e
if(j>0)
4 p* M: J4 f: ^{0 x# B; Q! j1 `( k' O5 P
if(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed) x' \: Y8 F3 N" C- D
{
& L; O3 T( d' r ^' Z: R(*memory).p.flag=computing;0 ]$ L) n; U/ \
(*memory).p.ioNum--;! h2 R* ]5 F6 f6 X+ W( a4 p2 e- s( w
change += exchange_IO_Compute;! n, F, b" m2 x0 T2 ~
}
4 h1 L: d3 C% r" a5 Z% Y% @5 c}
7 M7 [0 c, g6 o9 ?% t3 K}& k7 Z3 j' y _* b
}$ ?5 q; n5 R8 \. p
for(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程* k. h9 n2 c1 n! b& `3 P) B. H0 u
{
* v/ X8 ? _' r" V U* Vif((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed7 M% L w7 ]1 t( V4 d
{# @1 e) H& y4 J- F' D
(*save) = (PCI*)malloc(sizeof(PCI));# @; W9 |' L9 B5 p
(*save)->next = NULL;: D" @" a' ]6 u
(*save)->processID = (*memory).p.processID;
/ z0 g0 ^" J, q+ n(*save)->comeingTime = (*memory).p.produceTime;
; g( W% ~6 |! A3 G4 j(*save)->askMemory = (*memory).p.askMemory;
" g- Y% m! c0 p(*save)->compute = compute;
" R- Q- e! o- V4 x0 W$ ^(*save)->waitio = waitio;
1 O& F( n4 ?9 T2 r2 Y" U, q( J7 x(*save)->exchange = change;9 |8 n; R3 z- ?4 P/ K
(*save)->completedTime = systemClock-(*save)->comeingTime;
" i" w; z! G# c0 Y4 X(*save)->runningTime = (*memory).p.runningTime;
, g& d2 s4 y" D: R: ^' x(*save)->completedTime = systemClock; P' v( Q" a) G, w( F; F0 y
*spareMemory = *spareMemory + (*memory).p.askMemory;' i4 Y. [9 J! \4 ^( e
compute=waitio=change=0;" Z2 \' }& H: ?$ |$ ~; p8 v* P2 A
computeLast=waitioLast=changeLast=0;
8 Y6 @! y6 P( p, E& [if(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入' f6 j% n3 D( A, a3 l% E
{! \# n* p5 J4 B# {# h1 @1 e; s
if(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程
# h0 }7 f6 o& T, d( E{
; l8 r5 d5 L2 l3 |poi++;
F8 I8 d" R4 w3 q0 Z clockSegment=2000;* V+ g7 p4 _- N8 ~1 Z
}4 j4 ?, a' e' }
}
$ C5 v' Q- c1 s9 w' X7 E- `2 g. j' pelse //没有足够内存调入新进程( `! s2 i( X5 V. W. I, K: m2 O
{% _& G% _5 _$ b; V
if(i < (*memory).proNum-1)
2 U: z5 y1 ]% h# k0 w) ^{
$ p3 o0 Q0 K6 {7 |$ g6 |for(j=i; j+1<(*memory).proNum; j++)% n1 h9 l; Z$ g% O: V
{
{1 o5 ~1 L; U7 M(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;# {) e1 g1 i B* ]7 B
(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;
2 n0 }. A5 j& n. h: e" m& h& p(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;2 G: n, @9 e& ?) z% E
(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;
) ~& X; _1 g' [(*memory).p[j].processID = (*memory).p[j+1].processID;6 j6 Z) V* _6 W5 s
(*memory).p[j].flag = (*memory).p[j+1].flag;
# m' {, m/ | f. }* K(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;
* N( L. y0 [' d) n(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;; J0 \4 r" l- Z3 h7 s
(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;0 }3 i! p; _; v5 ] A( `
(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;
3 y {- a1 {& j- [(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;
7 V M# M$ t pfor(k=0; k<(*memory).p[j].computeNum; k++)
0 H: ^1 l) f. {+ w(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];% y) e& Z- h, ?+ f+ J' C
for(k=0; k<(*memory).p[j].ioNum; k++)1 d n( v/ P9 Y& O% N( f
(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];
. K t: m' K5 ^! \0 z}% G, j4 \' G6 E% p) M# E
if(i<poi)0 y6 y) X9 z: s1 I3 m
poi--;
# h; r u O. d. x/ Aelse if(i==poi)1 E! ^7 s! g$ u0 v; M) j! W( P$ i n/ ^
clockSegment=2000;
$ `* e, Q. @- k* S% Z* [' P4 m}
4 A+ f* |' G8 M- @- Ui--;
+ p" A' x; J( t- i+ r j(*memory).proNum--;
) E# P& e, W% ~$ F4 I: }}
" R' I7 u( j: u2 W. dreturn task_completed;
& H! r: z8 `) t5 J: C}
$ z" e( p2 A" [# m/ S}
: b: @. o* W0 f. Y--clockSegment;$ r7 X5 b; h g. s2 l
if(clockSegment<=0)
& t- U; ^* s; p{/ Y- [/ S# C4 z9 ?% [9 H
poi=poi+1;" C, p* G o: r+ H6 j1 Y" M
if(poi>=(*memory).proNum)
6 Z7 N, V4 a3 m: v' B% vpoi=0;! [& u- ~. _+ w7 ]. @0 ~5 b9 a, Z) a
clockSegment=100;3 B* y, }5 o% q; ^& A) j
}
" C% j8 j0 b* B1 M+ }6 i5 Sreturn task_not_completed;" x0 t1 n: z+ x
}- n1 ^& I, a( u3 K) F. t$ z: v! k
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)
1 R0 n Y# U( T8 V! K& O- J{' I+ ^; Y8 e+ B. o/ C/ b
int i=0,j=0,k=0,flag=0,translation=0;
! ?1 W( \$ p6 e% S$ O8 }. ifor(i=0; i<(*storage).proNum; i++)
9 z4 E4 x' z9 Z# g2 k) V{
, }1 i: K0 w. K0 p# P# Z* f! Zif((*storage).p.comeingTime>MAX_COMING_TIME)2 p! t3 w' g/ C. k! ?4 \( h
MAX_COMING_TIME = (*storage).p.comeingTime;
- Y$ c, y/ w9 I8 s R& D}
2 o7 q# e% S8 W5 v, Uif(pos>=0)" K0 a" V' i& p7 V; [4 L
{
/ ~% O8 o: Y5 Z8 E" H- Tfor(i=0; i<(*storage).proNum; i++)
' O) A7 A! F/ i6 A{
% d5 M. r9 ~7 gif((*storage).p.askMemory <= *spareMemory)
# W; a% a' a! N K7 v* n) D0 W- \8 E{" B4 i$ o2 ?3 l0 X% p9 N) ^
j=pos;6 j& ]7 a1 N2 c6 F8 T# ^$ O6 t
(*memory).p[j].askMemory = (*storage).p.askMemory;# Z& k& t- y+ \4 ^' v& r
(*memory).p[j].comeingTime = (*storage).p.comeingTime;3 F" |1 k7 L: X
(*memory).p[j].computeNum = (*storage).p.computeNum;
* D+ _. i* k" Z4 l* o a(*memory).p[j].ioNum = (*storage).p.ioNum; m9 r- F0 H4 A
(*memory).p[j].processID = (*storage).p.processID;# _2 `' U# b. D2 f
(*memory).p[j].flag = (*storage).p.flag;
) M" R4 \( v3 b, c% H. C& e, {(*memory).p[j].ioTime = (*storage).p.ioTime;
8 L0 U0 P6 B/ Y( s; _(*memory).p[j].computeTime = (*storage).p.computeTime;: }4 A+ E" S0 o; j8 n
(*memory).p[j].runningTime = systemClock;
6 m( w% N# i7 P) R3 i' g9 v(*memory).p[j].produceTime = (*storage).p.produceTime;
/ E, Z, ^5 j+ M( J7 Gfor(k=0; k<(*memory).p[j].ioNum; k++): I. {$ {: O: Z5 _& w6 c+ @
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
3 L% u5 {6 C Q9 p! m0 `for(k=0; k<(*memory).p[j].computeNum; k++)
0 G) M0 m1 B7 z: N- W; {(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];6 j7 I% u' e6 Q$ V( G3 U* ~1 l
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
' X4 P$ f. D4 s0 m4 b7 @+ I8 tproduce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程5 v% Z, U: {7 F2 N; [. T; J
MAX_COMING_TIME = (*storage).p.comeingTime;
9 [) b: \: y: d3 Ptranslation=1;
2 {8 D+ C; [8 Y. E* obreak;
9 ^7 Z+ n4 I \5 F9 c8 v}
7 G( x4 \8 R) l- G) x, P2 A}
4 T0 |9 ?: s+ \, U. F6 K}3 S. A; `& W( t6 o& b3 m# M; N
else
; j* T3 i! s( H& S0 J1 }{
+ ~( r8 c& L2 V/ y% F, ^while(1)& E+ j! Q, l& W
{; R4 N( {6 J+ d
flag=0;
" ]/ H; e) z% T+ @& n$ \" Kfor(i=0; i<(*storage).proNum; i++)
4 Y2 W C4 M+ C, V{# i3 u, j# T" y+ U4 m) O) _
if((*storage).p.askMemory <= *spareMemory)
/ C! [) q/ w' J' K2 f# T{
! {8 k6 A9 x$ B- a! g) q# K8 Nj=(*memory).proNum;
- i8 U; C. @% X1 {(*memory).p[j].askMemory = (*storage).p.askMemory;
3 T, s9 e9 N# M(*memory).p[j].comeingTime = (*storage).p.comeingTime;
" P9 F v# ~3 m; ](*memory).p[j].computeNum = (*storage).p.computeNum;7 w# N Q0 C: L9 [1 h" S
(*memory).p[j].ioNum = (*storage).p.ioNum;
' A5 Y: j U3 F! l. N(*memory).p[j].processID = (*storage).p.processID; Q& ^3 M. D8 A, Q9 E7 n
(*memory).p[j].flag = (*storage).p.flag;
. d. F9 ~/ W4 f, x- `. O(*memory).p[j].ioTime = (*storage).p.ioTime;& _- z& @ W. w$ b6 V2 H2 l
(*memory).p[j].computeTime = (*storage).p.computeTime;1 s6 P3 G+ V) [7 A
(*memory).p[j].runningTime = systemClock;+ W. l; h) `% i8 J2 }3 S
(*memory).p[j].produceTime = (*storage).p.produceTime;7 e! W; I9 X; L
for(k=0; k<(*memory).p[j].ioNum; k++)
. i9 x3 b% r2 @# ^8 I: G# F(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
! ^9 ^& J3 ^ \9 b5 Z* \for(k=0; k<(*memory).p[j].computeNum; k++)
3 ?2 a4 K7 d& }' V* A/ u# z( f(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
; Z- C$ @1 r, |$ l6 z1 ?(*memory).proNum++;$ Q) I2 \" h) j1 R; y, W
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
8 x* Q$ W' X; `+ }produce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
* ~% m; m1 C6 ]MAX_COMING_TIME = (*storage).p.comeingTime;
/ v! ]9 O8 S4 C dflag=1;
5 q: A; c# c f/ [3 I2 |; Vtranslation=1;
$ `2 H0 t* c5 d4 C6 q8 {) K! }7 B+ d}
, f2 O% A* b p* v, B k}7 Q& Y; ]# n! T
if(flag == 0)* A) Z) O! T; I+ X! B$ m7 x
break;
! Z8 z! r' k0 O7 R; g7 W0 Z1 d}
7 q L* `4 Q: R2 L R' K. w( J}2 q0 \# T) i2 K* X
return translation;
& z% h7 b" ~; O}' _5 c' g1 `. f, X" _& s( y! F. @
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)
+ @8 {2 e! C( ^/ x$ Q9 W{/ q6 P7 q0 L3 `
static int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;- s4 Y8 Q( t# ^4 w8 G
static int computeLast=0,waitioLast=0,changeLast=0;
5 v5 b5 G1 ~. |( o* ^+ t8 Aint i=0;
5 ~" w: C2 l$ ?- S8 Rif(draw==1): v* N7 R0 F$ p$ \: S1 J
{
1 U' T3 u. s+ ]' [//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
- p$ I# c" Z' O/ g" U" h3 f8 ddrawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);1 W( _ I4 b* L' H8 @ N
+ _ c& f G! J1 ~( y( P5 N4 a- r
0 T4 N2 Z! r$ k1 L# ^computeLast=compute;
7 a5 z0 m8 l5 X9 U- E) {waitioLast=waitio;
+ o9 c. d3 L3 ]; Z: ]changeLast=change;! Y, @! r5 d. L9 d
}
# W9 H" H$ ]% a8 _5 s4 }: Bif(flag==1) # q+ y3 ^3 f3 ]( O& H2 c
{
6 `. ?# K2 l' {( ~if((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed
9 l/ P R j2 ^- B1 t0 W2 Q{
; v! A U! F' K7 I1 Eif(flagiocpt==0) // implement compute/ u% e/ f( C' \ n+ \/ q
{
( b* o( g: w1 d$ n6 mi=(*memory).p[0].computeNum;
7 I% e9 M; _* D" _- e; Aif(i>0 && (*memory).p[0].computeClock[i-1]>0)* ]# X0 [/ |' T2 ^ U
{$ r9 v O8 C k' V
if(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed, G2 m4 [; R* i, P% M1 v+ d. w
{
; Y; A: Y4 G- D' @, [flagiocpt = 1;
2 T2 m9 }" S( @! k(*memory).p[0].computeNum--;$ p: ^4 [$ | e* A4 k
change += exchange_IO_Compute;' ^. D. o( s' x K
compute++;$ f* N8 N: [: I( N& C! Y
}
U1 c. F% s* K# `else
; v5 S) E/ l$ q' Q) u. J( b; Tcompute++;
* @* o+ k* x' w& t
7 C, S7 f. K0 h8 A; ?}
2 I8 ?; P4 i1 F, Felse
4 D% q% m2 [7 kflagiocpt = 1;% }" W3 ?6 l3 l% p1 r
}7 S' Z* z' D- L0 u6 y
else //wait io
0 e7 y0 _3 K. X3 N{
3 a& T9 k) M% u$ l; F. N+ Oi=(*memory).p[0].ioNum;1 P+ h5 J+ |& L- m" |8 z v$ w
if(i>0 && (*memory).p[0].ioClock[i-1]>0)
) l+ u, I. }! ~" j2 x' H& A( ]{1 W! B, q) O: x) O
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
$ G+ S6 R+ b d; Y5 ~5 @{; A" Q- g' i0 g; b
flagiocpt = 0;6 y( Z" \: h q; Y8 J8 Y2 H9 w
(*memory).p[0].ioNum--;* X" ^* H! p0 z( n2 K3 y
change += exchange_IO_Compute;
2 G! D" V8 T& dwaitio++;- y! W- \3 L( C2 `7 Q
}
9 e9 n W& d8 ~. }else
! w: m c P% Z# x: ?waitio++;6 y- `! d( ~/ d( z; m# o5 R
) c9 h1 G I# S6 v4 z
}
1 w& r. y( z1 K5 melse' y& ]. H* ?% B# F1 U
flagiocpt = 0;
6 E* B% c2 M+ K0 f, G( R# A7 z! D}
' k/ b" P' u. o0 v n+ `) X}
0 ]; p. \0 }4 `1 J* I. `else //task is completed" k6 c9 z6 o* U6 Z8 I* T0 [- Y' |. `" x
{
( n% b; i6 @/ L2 e& o; U5 O(*save) = (PCI*)malloc(sizeof(PCI));: k! h# ?# M( }0 J
(*save)->next = NULL;
! R2 n+ V. b: y) L; b$ u (*save)->processID = (*memory).p[0].processID;
# B" T9 ]4 K1 z4 T* J: _- I(*save)->comeingTime = (*memory).p[0].produceTime;
$ D: L4 E' G+ \! v$ X' n# p$ c(*save)->askMemory = (*memory).p[0].askMemory;& m$ {- C, J7 G' s, F
(*save)->compute = compute;
7 k/ e/ n" l0 h5 S(*save)->waitio = waitio;
9 \' ]: @6 v; w" z( t# H(*save)->exchange = change;
( P. l) V ~: ~9 A! g0 S9 Z2 @(*save)->completedTime = systemClock-(*save)->comeingTime;
. R& a* Z3 U, I: V8 ]1 O(*save)->runningTime = (*memory).p[0].runningTime;
! ^' h9 s; _7 J(*save)->completedTime = systemClock;
( j. S; D' J+ s$ t//*spareMemory = MAX_MEMORY;0 D- `, S* |) s( u
free((*memory).p[0].ioClock);
" d( X# Z4 v. l' U) ^free((*memory).p[0].computeClock);5 M& Y3 U. j- Q' y
free((*memory).p); G. r$ k% W9 o- K' x+ O2 G. _
flag=0;1 {8 B1 _. e, \2 ]2 f5 @: |! y
compute=waitio=change=0;
/ ?) V% b4 G4 u/ i' jcomputeLast=waitioLast=changeLast=0;: M; s: g) B$ n. T, I
return task_completed;; k: p! V4 T1 i5 l) f) v. F% z
}
* K! L: P/ }8 C$ x}1 e! v# }, x2 C, `$ _, c
else
, _1 u" W8 N0 t5 w7 |- F; {- _{$ i/ _6 S; N' v0 V# E3 ]
FIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));( J! m( v4 V# m" D
change += exchange_process;1 }( v3 E8 H$ l7 J
//*spareMemory -= (*memory).p[0].askMemory;+ U" j7 u! `! H; |. P
flag=1;7 i& w9 K: x X: Z. H$ ]
//showProcessInf(*memory);3 P, H5 T5 Q" I4 V- [ ?; u$ t
return task_not_completed;* T& q- I1 d) l9 v/ [
}
" w/ v4 y* r1 Q9 ^" sreturn task_not_completed;, _8 l5 C- Q. a' w0 H- [9 f. V
}$ E: P- S4 p; m- c$ e
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)$ F: Z' c& ~' D' R7 u# s7 z2 V
{
4 R1 ?+ s: C3 z! Z/ mint i=0,j=0,k=0;
7 l; V5 Y) Y4 n! AMAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;) o* W" t: {3 r2 I- I5 G$ x1 e" T
(*memory).p = (process*)malloc(initProcessNum*sizeof(process));
2 c3 i% U* L/ B x: Amemory->proNum = 1;; E: [3 p; l( @7 h ~! j
for(i=0; i<initProcessNum; i++)% [0 v$ y6 f, R- P/ `
{
4 i3 ~" h; u& C$ iif((*storage).p.askMemory <= *spareMemory)! ]1 ~2 a X& m6 U3 a- H' f. f& q
{: q ~' k" [# }& S. Y* t' T
(*memory).p[0].askMemory = (*storage).p.askMemory;8 R1 Z. v. s. B
(*memory).p[0].comeingTime = (*storage).p.comeingTime;
: \ T2 y1 n) P% z2 @(*memory).p[0].computeNum = (*storage).p.computeNum;( X5 Y: i& n* ?5 g: @# r; v
(*memory).p[0].ioNum = (*storage).p.ioNum;4 f, [- O1 s2 A& J% q/ r3 Y
(*memory).p[0].processID = (*storage).p.processID;" Q% }* |+ a1 x* N# D. e9 Y9 G5 P6 P0 W
(*memory).p[0].flag = (*storage).p.flag;' ~/ }* i: A1 b
(*memory).p[0].ioTime = (*storage).p.ioTime;
; R2 u7 j# S% j4 v5 G( d(*memory).p[0].computeTime = (*storage).p.computeTime;
3 p1 b7 o2 M( v- f( M(*memory).p[0].produceTime = (*storage).p.produceTime;
; R) Y1 R& N: x4 ~# h(*memory).p[0].runningTime = systemClock;
2 z/ D) p! i2 g. {' g(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));% M5 M7 \* C9 S+ Z1 e3 P
(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));, E6 Q/ H+ ~) p# C; c
for(k=0; k<(*memory).p[0].ioNum; k++)2 N/ Z6 l V* `, `
(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];: V5 W6 o) `5 O) e4 G
for(k=0; k<(*memory).p[0].computeNum; k++)3 X' x9 T1 O* f- ] P7 f- F. {
(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];) k- w( R1 u2 s' C6 A( ]$ t
break;$ S0 a3 i/ h6 h; ~
}1 E" @* Q$ o" u# _( _, ~8 t
}" t5 x: q8 Y* G+ A
if(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入
, X S) k, m" n{+ o( T9 h* \2 T
produce_one_task(storage,i,ID_FIFO++);9 U* C; A% f: @0 q+ s7 ?$ J# e4 h2 T( q
MAX_COMING_TIME = (*storage).p.comeingTime;
- w: R) @% ]( J+ U; gsort_by_comingtime(storage,i);, u! v) U3 A# U
}
# P% M: P7 ^7 s3 f) j& o* @return 0;
& c' F8 z. h5 m. L- f. J}
5 q" @& e2 x+ F' v# W6 Q+ X" R* W; bint sort_by_comingtime(processPool * p,int pos)" T7 \" J/ j6 `% T0 A! r8 y
{
8 S8 g8 f) `0 W- X2 g8 L v& Sint i=0,j=0;
/ P( r' y0 p& G( |: aprocess temp;2 q! r; a' z2 J6 r& Y
if(pos<0)
1 R& I+ \' k& n) B& }0 t: ^{* } |5 q2 @1 I$ Y! S
for(i=0; i<initProcessNum; i++)
: I v" R7 L0 D$ T. @for(j=0; j+1<initProcessNum-i; j++)
$ e3 M( S8 X4 b; k% O5 x9 U" _{, x& K a* p/ o
if((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)
' D3 |2 M" T* A; G& c{8 a8 ~- y. m* U. O
temp = (*p).p[j];, L9 w9 z% E- F" s9 j
(*p).p[j] = (*p).p[j+1];% T. G3 O* `! F$ R1 m j
(*p).p[j+1] = temp; _# K- `9 d) ^9 I* \, e
}
% y- H/ o+ D; P- K) ?/ g5 E}
H2 O* t, ]) Y! y3 _9 d4 F9 ~}
& l& [4 R F! [8 felse if(pos<initProcessNum)
0 y1 s \. x% _9 e& V{
0 J: w& z1 Q; I; X8 K! z( I, L0 Vfor(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)
2 F# x3 ~" B4 q% k! T2 e! }{
* v0 _8 z I$ G" @1 U" gtemp = (*p).p;
. y& l6 N/ l W5 B" _(*p).p = (*p).p[i+1];
; H1 r& t3 g# \5 W0 v(*p).p[i+1] = temp;* o1 ?4 _2 `" I% c+ V9 ~! t
}# I3 `5 {" l% U' y
for(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++), O. @* Q% l+ c( y9 x) b& e9 ?( N, Z
{6 D6 K8 R; x8 s! D- M3 t1 E, P& n
temp = (*p).p[i-1];6 d ]! \, r) n; c
(*p).p[i-1] = (*p).p;
$ C: |5 z8 C: g(*p).p = temp;5 ~0 ^# C) d \* u& p8 D. O7 i
}
! A3 Z% L8 {8 L- m' F}
7 Y! J) J# t1 Y, Y: Eelse
/ m! R' w( ]+ x, p* X- j. sprintf("position eror\n");
9 s0 x6 J M4 hreturn 0;
+ H5 T& }* Z. Z2 D2 \, u}; s* }" y1 F9 }7 l% Q0 D
int InitPool(processPool * p); }/ m- y' q+ ?: P
{4 `7 E4 h r6 {3 [
int i=0;
B2 u0 A1 @ _* d V5 a(*p).proNum = initProcessNum;
2 d7 F/ G! g/ ^. m(*p).p = (process*)malloc(initProcessNum*sizeof(process));9 E& c: f9 V: b
for(i=0; i<initProcessNum; i++) //init process information
/ x& k' m' {+ ` [# r( w$ Y% S{
8 s7 C$ e; H9 ~( [(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));
% ~+ i) O: @- z) N: a/ h(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));( `$ T7 J4 M" H7 ?9 |
produce_one_task(&(*p),i,ID_FIFO++);
0 w5 x, @" G) Z' j& a}( h1 G' E$ ~) ^+ x) x7 j# i
return 0;# N9 B& o! d; W
}
+ ~) A* a7 f1 c3 u% a& O# bint produce_one_task(processPool * p,int i,int id)2 @0 N. X' ]# u5 f
{+ M: q8 |9 O# m7 m
int time=MAX_COMING_TIME,j=0,totallTime=0;
. y* R6 {, W2 z0 ]" B8 c4 R(*p).p.processID = initProcessID+id; 1 T d7 G4 O3 [% Z* ?7 ]
(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);4 ?% s5 f2 s E/ R5 n- r
(*p).p.produceTime = systemClock;4 _" U u& I# X
(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;
5 w4 a, c3 | G(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6;; Z4 M/ Q; ]9 Y9 d8 c" j
totallTime = (*p).p.computeNum + (*p).p.ioNum;: s0 Y4 W0 F4 ]; i3 n" r& d# r+ M
(*p).p.computeTime=0;9 ^ A9 T K6 n* L8 @5 B, h7 o7 G6 b
for(j=0; j<(*p).p.computeNum; j++)/ a5 h3 V6 W$ ^8 X }" H9 ?
{, m+ B) F) M& a8 p% O* o3 @
(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;4 i! e5 t3 L' Y- ^
(*p).p.computeTime += (*p).p.computeClock[j];7 g" i2 g) Y+ N. t
}/ [/ x2 l* w% s0 I* w8 F5 ]) a
(*p).p.ioTime=0;
' @) c. c6 S# [- s: Nfor(j=0; j<(*p).p.ioNum; j++) |
|