- 在线时间
- 1630 小时
- 最后登录
- 2024-1-29
- 注册时间
- 2017-5-16
- 听众数
- 82
- 收听数
- 1
- 能力
- 120 分
- 体力
- 563403 点
- 威望
- 12 点
- 阅读权限
- 255
- 积分
- 174244
- 相册
- 1
- 日志
- 0
- 记录
- 0
- 帖子
- 5313
- 主题
- 5273
- 精华
- 3
- 分享
- 0
- 好友
- 163
TA的每日心情 | 开心 2021-8-11 17:59 |
|---|
签到天数: 17 天 [LV.4]偶尔看看III 网络挑战赛参赛者 网络挑战赛参赛者 - 自我介绍
- 本人女,毕业于内蒙古科技大学,担任文职专业,毕业专业英语。
 群组: 2018美赛大象算法课程 群组: 2018美赛护航培训课程 群组: 2019年 数学中国站长建 群组: 2019年数据分析师课程 群组: 2018年大象老师国赛优 |
3 o: m0 l% ^) N4 v' V经典任务调度算法的模拟程序
+ n" |2 i# s# C( G2 E b本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。
5 ^! a7 u4 ]! J
# L& X/ d8 m- @+ v M, N- s6 C编程平台:VC6.0+EasyX图形库环境。, T4 Z0 r) T$ J% n
$ @7 l0 [1 B5 [8 u以下截取部分程序运行图::
1 r' p, }% f( p8 {& q& F/ m+ E) V1 ]% y
源代码:$ T; p- v2 ~ ]! g% M# N
3 H( ~; J/ F! P. _7 u
#include<stdio.h>3 i, v$ @1 H1 L+ O
#include<stdlib.h>0 A, B% E( f! ^0 N6 _' R
#include<easyx.h>
, I+ C4 c4 n" m4 J' j( K#include<time.h>6 ~& X% q" B# j, w
#include<conio.h>
; S1 a; u- m" y6 x( a7 |#include<graphics.h>
& v* _* X% U" Q" A: y. j# P D#define initProcessNum 101 ^8 f! z. ?% p, ]
#define initProcessID 1000
u% z& F( l- y+ W2 c4 y#define MAXProcessRunTime 10000: w ]9 K- G/ |% r5 M5 [
#define MAX_MEMORY 4000
" `! f% V# \5 j' x. O' ^#define exchange_IO_Compute 10
- I( G& z( ~, F#define exchange_process 253 [) g! N( e; u: ~
#define task_completed 1
! k1 @! s* N4 {, _1 h% \#define task_not_completed 00 F$ S% f0 f: x5 ~
#define initclocknum 1008 O; k& T* y$ K5 D. Y2 B# y
enum condition# E6 {2 n/ n( \# g* c
{2 h r2 S( ^8 @6 d' ~
dead,computing,IO_waiting,ready# r* b+ Y1 t* @+ O Q U
};. L, m4 k' h. x0 s1 L
struct process! |) h$ U% R! E5 ~+ c
{
9 l4 e+ _9 W/ u& pint processID;$ |/ ]( U9 X7 A3 N5 v
int comeingTime;
& N1 t; W6 {! ]# Z& rint ioNum;' e+ `$ M) L; d
int computeNum;
: L% W" B2 `# {1 \+ A3 C5 L- s: Pint * ioClock;: V$ j3 W* @# t) C
int * computeClock;
0 O6 f1 w: }5 L) _$ ~6 aint ioTime;
9 S0 f* _2 _; s2 h( t7 oint computeTime;; _) n! G4 T5 t0 W- G3 [
int askMemory;2 Z# U, L: f% s% B' u3 W' r) l
condition flag;
+ h& c1 d% E% X" I: bint produceTime; //生成时间,以下三个数据成员用以计算相关性能
. s: ^8 }# K- N3 `; p9 eint runningTime; //第一次占用CPU的时间3 s/ q! W* @$ o. z
int completedTime; //进程完成时的时间
6 T2 s6 ~. u3 h9 B5 A5 F};4 ]6 ~0 c8 _4 F* a+ u: Z
typedef struct processCmpletedInfo //保存完成一个作业的相关信息* i! S" ?) [6 l
{
, q& R! ?$ f F- Y4 Bint processID,comeingTime,askMemory;3 A/ y9 j* n' N& v( ?7 K
int compute,waitio,exchange,completedTime,runningTime;1 I) H8 F, R% ~6 y5 o6 ?* _
processCmpletedInfo * next;
% X. k/ g, U, `* Y! U5 Y$ @}PCI;4 [1 }) s) z- |
struct processPool. l" G' o3 x- l/ M! `+ F& P, s
{
3 x% {$ [5 O q& p+ p" y" V xprocess * p;
) j2 H, d Q& q8 wint proNum;! u; M- C, N p" m- g, e: T
};/ T% d; W+ }7 {1 E9 K! q# b _
int MAX_COMING_TIME=0,ID_FIFO=0,systemClock=0,FLAG_FIFO=0,FLAG_TT=0,FLAG_PF=0,FLAG_SJF=0,FLAG_HR=0,FLAG_show=1;
' u3 D& `! w) R: a! \% P% ?int InitPool(processPool * p);- z. }1 w5 _/ Y N7 X
int produce_one_task(processPool * p,int i,int id);
( Q4 B0 U& e- ]int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);# e# L$ d1 l+ p1 g
int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
* l/ T% u4 Y( h* F3 Yint TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);) t9 \6 b: ^6 p" Q5 l! B d! @6 P
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
_# n3 Q, R! b; U2 vint ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
1 Y; p- W6 ^1 F$ j$ \2 j& nint SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);% x( s1 _4 d: c) s$ q; A2 ^
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);2 {$ N0 F, q- p5 _, o% I7 L
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);! k9 s8 C' ?6 r2 @& z9 @
int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);
( o, u2 c. E7 c: x' n9 ?int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);; s2 _/ N5 d7 r+ |( d- N; y5 H
( V0 s, I& b0 C2 |( H6 ]: {0 \' v$ K& }
int sort_by_comingtime(processPool * p,int pos);
" O3 k! \) D6 N+ jint showProcessInf(processPool p);
1 |& L5 H# h$ e' {! T" s& Q( Dint drawPerformance_FIFO(int x,int y,int memorry);
0 E, ~. L$ U, t9 Y; b. c0 n9 R0 r. xint drawPerformance_HR(int x,int y,int memorry);
t$ c' F, E. s$ Mint drawPerformance_PF(int x,int y,int memorry);
( R$ c5 U, X i! j& N6 Mint drawPerformance_TT(int x,int y,int memorry);: c" h* t2 B7 L1 i
int drawPerformance_SJF(int x,int y,int memorry);
6 ~# k: o+ I9 S, a2 j) T" Sint MouseListening();
, ~5 [$ u% O8 j* a" U. |8 Oint MouseListening2(int *flagShow,int * showTime);/ p/ V2 z2 S# ^" k" g& \ _5 K; T6 }
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);; {$ ^. M) m Y* X0 o5 J
3 c2 N# q) g( l2 p' ~/ u
, v5 H7 x/ Z7 P+ o. Fvoid main()
' w, v0 N) ^9 X0 J6 V{4 B2 I$ b ~* H) B2 Q8 X
PCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,
. y i' T. a8 l. y0 |+ a- @+ z, M, [*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;% u4 p/ Z2 `8 U% h8 [) U: A
int i=0,FIFO_memory=MAX_MEMORY,count=0,Timet_memory=MAX_MEMORY,SJF_memory=MAX_MEMORY,Priority_memory=MAX_MEMORY,HR_memory=MAX_MEMORY,' ]! F: N2 j8 E
flagDraw=0,showTime=100000;
4 C) d: j( m" q. L! C2 ZprocessPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;
6 S3 }( e8 o! Z1 \6 V* n2 kFILE *fp=NULL;+ Z! R$ n5 j% B1 |4 U' p) ]0 K
//processPool HR_p,HR_mmy;
$ }+ H2 I c* _5 k& [4 E9 O7 G! V+ f) |
3 q2 d0 E3 U& j$ M* o2 a( j& e( M
srand((unsigned)time(0));
! F- [; s* ]; A' T) K' R; m0 UsystemClock=0;9 p; S+ j& L& C5 K0 v+ S0 E
initgraph( 1200,650,SHOWCONSOLE );, P; s4 T' A) L
settextcolor(GREEN);% d# B$ `4 t7 _0 l
setlinecolor(GREEN); D* D' n* E0 T7 N7 F7 z
setfillcolor(GREEN);9 z4 h4 p/ [ h' h2 [/ f
InitPool(&FIFO_p);
: _0 l' ?" V/ asort_by_comingtime(&FIFO_p,-1);
' K% n k( h4 h: qInitPool(&Timeturn_p); T7 Z# n7 F& T9 I; m) Y
InitPool(&SJF_p);
7 e0 M$ \ Q+ E1 x+ ` e+ I& DInitPool(&Priority_p);9 p9 |5 a( p( K( n1 @ Y; @2 T; G" A
InitPool(&HR_p);
v# U- _( r( Q7 U [( @//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);9 j, r6 {5 @1 _
//Sleep(10000);
* F6 B# L* h. t% B' m+ \5 f1 u- J9 F! S+ g; X: h- X1 m! i8 u* p9 K% G
$ p6 A' n% @* W8 A h
Timeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
" p% ~ o# D. s8 S0 o6 d9 SSJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
( r6 ]" x" {# L, H2 sPriority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
% z4 m3 ]2 `3 Z t; aHR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
7 K7 p2 Q! k9 A2 n# e4 n% nfor(i=0; i<initProcessNum ;i++)) L! i* I) M8 I6 z( _
{
0 h. b9 G: e, _Timeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));3 q0 [. E1 I$ i8 {: w: W
Timeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));) {! |- c8 A% Y: b/ l
SJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
\) _' m- Q! y! X9 [/ f6 _0 JSJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));6 W7 G1 i" s, ]5 z
Priority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
/ g/ V; T4 |& f" C$ }Priority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));$ w. W2 t! O# C' v+ d+ r7 b
HR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
: T# F) x, O4 W$ R3 b2 w) GHR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));5 J# A a( c* b% ~. f* n/ g; ?2 ?
}
& N6 h R* j7 M5 W6 I% p' JTimeturn_mmy.proNum = 0;
: L8 T+ `! @; g$ WTimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);
5 u; e. y' a+ ?* A; t b1 a) ESJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);
+ n9 o9 r2 F5 @3 N4 z& oPriority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);
; L8 b. o. i* a7 t" e2 |5 }, U( OHigh_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);
9 J5 _2 c9 B& D- M* n( B6 G. P//showProcessInf(Timeturn_mmy);" m6 H2 G# r0 l6 j' {2 i
FIFO_pri = &FIFO_save_head;
1 q. H, ]3 }2 x& CTimet_pri = &Timet_save_head;# D3 v0 n! {8 C# f( |$ R7 A( x; J6 r
SJF_pri = &SJF_save_head;
3 t/ J2 l$ a% @2 ^4 YPriority_pri = &Priority_save_head;
4 l$ E* y; z' v, k HR_pri = &HR_save_head;
) x' m* M1 |% O8 t* [+ b! N) k8 Bsetbkcolor(WHITE);
% M, ^% q- d5 o# P- G4 \0 }while(1)8 r; s% l% x0 @8 J) z
{! g0 K4 v$ D1 C( _4 V; e
if(MouseListening()==1)
5 s& n6 |" D: ?6 v5 Q/ {flagDraw=1;8 U# }7 I, n) a4 r1 J: n0 X
if(count==100); S& I: }. e" T
{
: H0 d, Y9 r" ~- r, I5 bif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)5 V) U$ l, ?7 f. X1 s( e8 S8 \
{! b% G9 B8 w% t3 C, k
FIFO_pri = &((*FIFO_pri)->next);
$ K8 n# X9 q5 }# j. D3 \4 m; E/ Z! y( j( N) d
//printf("hello");) d+ c9 F8 e3 n) ]
}. _/ D% ~! m/ P* S2 e) m& w
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)( z# K: Y, N1 ^) ?& Z' O' g) V
{: T2 c+ j. u, p6 [
Timet_pri = &((*Timet_pri)->next);
8 [" v* Z; |( v0 y2 w//printf("hello");! B: R+ t8 i! P! G6 c4 I2 v
}* R6 @! H; L0 c! B7 c
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)' A' l. U4 t/ I) b" E
{) z. B$ U" K. Z6 [0 Z- _ O. O
SJF_pri = &((*SJF_pri)->next);
6 o! A- @5 L$ ]8 [- m# X% |//printf("hello\n");4 E: p: `$ u& s% }
}
3 L) L$ x Y5 d8 D! Cif(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed)
$ b3 E# a1 d8 k{' v- U3 M5 z( `, a' p
Priority_pri = &((*Priority_pri)->next);
! ~, }; x8 e5 y: K1 |, ?$ ]7 q//printf("hello\n");4 E) n# N3 L; T: S
}: A% k8 o; e L& Z9 D$ O; G
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)2 k5 H% @. o* F
{
; ]5 [# |8 P1 A5 QHR_pri = &((*HR_pri)->next);. w7 ~ H" p& |( h2 y, H
//printf("hello");7 s+ _- _) v7 F% e
}4 {; R: G8 f" u# v; z2 `
count=0;
, m4 Q0 k/ }( H/ V7 }}
- p" j$ R1 `6 r$ \" j: V5 selse
8 G/ F7 U0 {/ Q; [{
! X3 I6 V D, e: F6 t' Eif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)7 Z) M) |+ l. j. ~& g+ @6 q
{: \$ i5 a ]) b& k6 m, k6 _4 B6 X5 h Y
FIFO_pri = &((*FIFO_pri)->next);3 e' i# D- Z9 o j" I M
// printf("hello");1 R; F7 h2 s( D4 V
}
% c/ e ?9 G0 {$ Dif(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)
, Z* W; P" n5 g, Z+ Q$ P6 \{! @9 T" V( a" }7 P% t0 |& r, f% i
Timet_pri = &((*Timet_pri)->next);' s; g6 |9 u) \1 S9 G
// printf("hello");
6 ?4 \; L" R9 Q8 r5 }, s}
; W0 T! b* C7 C+ T( I7 k% Rif(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)
7 x" b5 L$ c8 x* R0 i8 I{& t+ L( Q' i) y) X9 V* i( S
SJF_pri = &((*SJF_pri)->next); N% T5 T) g" U0 C, i
// printf("hello\n");* }6 }' f9 E& I3 f6 l5 T
}- w% V+ z3 C- W# F
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)+ [, K4 E% G& {8 l( R4 t
{0 G4 h6 [' _9 F$ ^4 X. a* A
Priority_pri = &((*Priority_pri)->next);
# t6 A; u9 v# I0 s& B//printf("hello\n");) U% `' R6 [' O( F% x* b1 n
}
: u7 g t3 t \0 Y6 M& Gif(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)
/ N) D# L/ ~( E9 U4 A{
% f+ V( i% B5 [HR_pri = &((*HR_pri)->next);
( N- i+ a9 j/ [3 z$ @, ?//printf("hello");
+ _' ]# [8 H- o% ~9 S7 X//Sleep(1000);! o( U$ o9 C/ q* k7 {
}
+ ]3 p0 R3 N0 M4 `: W3 _count++;1 K% ^2 Z) m! }# L
}
4 Z$ s: Z% Y* T3 {" ]& O0 hif(systemClock==showTime) G. _! r8 Z; J6 p2 A$ a
{
* P2 t+ Q Z6 z3 r) h! F/*PCI * p=FIFO_save_head;2 _/ G2 N- ~& \5 q" B" R5 h/ Z7 K. f
int i=0;
1 K# T& [6 b- r' Ifor( ;p!=NULL;p=p->next)0 Z( |1 k- J; Z; L' o( U' _
{7 V: D+ l. d# P) Q1 w( P
printf("Id %d\n",p->processID);* D0 l" p* n' w" C- k. l' g3 G- j
printf("comeingtime %d\n",p->comeingTime);" S% O2 S* ?* D
printf("runningtime %d\n",p->runningTime);
2 L# e/ U& q$ Qprintf("asdmemory %d\n",p->askMemory);' K8 }* L: s; U* w7 Y* [+ E/ u
printf("completedtime %d\n",p->completedTime);9 p7 \: J% R# H* Z4 Z
printf("compute %d\n",p->compute);, ]% A2 T) W3 e
printf("exchange %d\n",p->exchange); Z- B3 [5 I+ `& B" w% u1 E1 m
printf("waitio %d\n",p->waitio);
2 l" R' V" r; |, N& c2 Gi++;2 M, [+ R% `6 z
0 n$ _* D" e! D' _* g, D' ?9 R- n+ u# e/ R2 Z6 [
}
- e8 @ c% P8 l) n# x- rprintf("%d\n",i);*/
* G9 I. u6 O. j! E" W R* Qif( (fp = fopen( "data.txt", "a" )) == NULL ): t) @' l4 c& g9 l( ?
{6 G( C2 c( {! F! g- j8 v/ Q" z
printf( "The file 'data.txt' was not opened\n" );
5 ~' s) y& J4 v. _ X, v; C//return 1;
; N! P4 b1 O- u( u}+ t/ I+ y/ E ~
else
& |% {) o7 O9 W2 {9 I0 L{- P8 B$ j l6 T% d5 D( Z) O
fprintf(fp,"FCFS \n");7 P e4 s: u. }& f8 p8 b$ d* W
for(p=FIFO_save_head;p!=NULL;p=p->next)
9 h( I0 G- x) \fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
, X+ z* N* U- E( n- \/ ^p->exchange,p->waitio,p->runningTime);3 j; z% R( j8 b( ?2 ?' ?* l% u& o
fprintf(fp,"\nTime turn \n");
& U/ w8 Z6 T* t1 bfor(p=Timet_save_head;p!=NULL;p=p->next)- G' y3 G7 ~& i- @! U
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,0 L0 Y/ e3 k5 e( A7 d9 G
p->exchange,p->waitio,p->runningTime);
! u" v* J }* E4 B( I) j& gfprintf(fp,"\nShort Job First \n");
: @$ n7 _! {& m/ u& H, x1 Zfor(p=SJF_save_head;p!=NULL;p=p->next)
; q9 ^; _; q$ M7 ?8 ^fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,+ n- b. s6 }/ S. J4 i
p->exchange,p->waitio,p->runningTime);8 x6 t5 M# B( D, f: s, w6 k' R2 i
fprintf(fp,"\nPriority \n");0 y# X; K* {; A0 | Q# S' |
for(p=Priority_save_head;p!=NULL;p=p->next)# o5 L/ u/ X4 e8 R
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,! t7 ~0 R. o3 Q) U8 R- E
p->exchange,p->waitio,p->runningTime);
, h4 P5 h" [% i ?$ x) W9 a1 }fprintf(fp,"\nHigh response \n"); p( ^2 L' J, V- ]; m
for(p=HR_save_head;p!=NULL;p=p->next)
# T) Z* N; B+ \$ qfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,# z9 f5 L3 \5 G+ T! u3 L5 W
p->exchange,p->waitio,p->runningTime);* h- M/ U Q/ @# x" s# Z! X
fclose(fp);7 M# F4 i: X* Z/ x5 Y2 h* D
}
# B. Q$ x) R \: ^/ N7 |showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);' ^" ? K! C0 D, K* `8 G6 j
MouseListening2(&flagDraw,&showTime);9 u) ~% c' a$ y4 h. d" k) c: G
}
# B) c# |+ z, q8 o: }systemClock++;
7 d; h1 z; h z/ c1 V" yif(flagDraw==0)
( q7 t$ t4 [) s: B' O/ r: I5 J Sleep(10);
, a1 w6 E1 {+ x* R5 O}
* I, ~* u# w( A9 Y6 W- J5 v( g
) x6 q T7 [1 Q3 q7 a, N; y' V3 T5 r/ U6 k- z
}
2 F7 g" j# I$ i4 ^2 `int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)0 H0 p: X2 k- U3 `& H; f, J
{
, ~: A; A+ ?8 }0 ZPCI * p=NULL,* name[5];
, u5 u- t3 z; xint count=0,i=0;
; T% G! o4 v! d: s. |9 w$ P* _$ fchar ch[5][10]={"FCFS","timet","SJF","PR","HR"};" ?- h0 G. Q: a
double turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};& b$ Q6 f7 `: K- m; X$ g/ ]$ O/ O
struct info
+ h, V/ x8 ?: Q6 p{
6 Y0 n; D% B2 I( U" ichar name[10];: E# H: ^6 b, L! U l3 ~- g- }! b% \
double throughput,turnover,wait,CPU_rate;9 L2 T% ~% s g% ^+ v
}inf[5];; `* `, p7 N! w7 H* O7 ]" F& Q
name[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;' w! S1 r4 [, _1 f5 _) M& ]
printf("调度算法..........A\n");
$ q$ z8 r% Y, |1 U- gprintf("吞吐量............B\n");4 e6 U" r- v" H( S6 `7 j) v! M4 N% u) u
printf("平均周转时间......C\n");
: v/ E. d( r H C" r7 Uprintf("等待时间..........D\n");
, Z) d! o" ]/ i: G% jprintf("CPU利用率.........E\n");: O# r: ~9 h0 E9 z, Y6 z% R. b) q. c! P
printf("A\tB\tC\t\tD\t\tE\n");9 n: z7 m# W2 y* } l7 z) u
for(i=0;i<5;i++)
" P( J/ E9 W5 z{
' l3 z3 {6 t. K" ~count=0,turnover=0,wait=0,c=0,w=0,change=0; H" n D. J! c8 p+ n
for(p=name; p!=NULL; p=p->next)1 B/ P" H K! O/ w6 [/ r
{
5 S5 B, i/ H, Y) ?count++;. B$ e( N M- ?! c, _* o
turnover += p->completedTime - p->comeingTime;: P$ ]1 }( p, s. S1 t0 o& N7 k
wait += p->runningTime - p->comeingTime;
7 n1 C+ p- ?) ~, p Y cc += p->compute;2 r5 `* c I7 p! B* w) N
w += p->waitio;
4 f. C! h4 _( T0 }# tchange += p->exchange;# U S7 j! s0 d2 g; [
}
5 R: ]7 u7 N5 nturnover = turnover/count;
9 J5 m2 r3 {* ?' ]' c. a* bprintf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));! {5 q9 R8 B/ Z) M" [% n. D
strcpy(inf.name,ch);
0 }/ y# g1 P6 @5 l+ T# i" y6 @inf.throughput=count;
2 {1 Z( J3 q- H% X' zinf.turnover=turnover;
' ~6 H7 n/ [8 j/ S# O) a" winf.wait=wait;9 y& c0 f2 c. f0 M, Z F" p
inf.CPU_rate=c/(c+w+change);
$ f" R; B" O2 [# a* |) p}% x" A5 o4 y) e; J. \- `, h+ |
//画图
; ~; j8 \9 h ^2 q( k& l//cleardevice();) ?9 G; O( i* N# X& X. ^
line(0,600,1200,600);
7 H$ }& B# } V* `; ~line(10,600,10,200);
3 m4 q' D% _5 }$ e; mline(10,200,5,205);
) p" t- r" E* E z9 m6 _. M' aline(10,200,15,205);+ j) b% k6 j- K! P# ?0 I& C
line(310,600,310,200);
) Q8 \5 c7 E. V, `; Yline(310,200,305,205);
, N; E, e3 g) D7 E, _line(310,200,315,205);
7 o7 G' i! @5 bline(610,600,610,200);* x: `3 ^2 X) ?! r' `: N
line(610,200,605,205);
3 a! R1 W/ [0 T5 }+ Jline(610,200,615,205);
' r- B, l \0 ?0 x! U6 P. L' Zline(910,600,910,200);
6 N6 E7 W- a: b; P" w: @line(910,200,905,205);$ ^: V6 w5 l8 y- n7 s
line(910,200,915,205);//最高的长度400,宽度均为407 }& n4 z& u7 g* C( c
for(i=0;i<5;i++), `! u4 h% Y: H: V+ c* u
{" c4 `! X v' L) @9 c& K- m" B1 I
if(inf.throughput>pos[0]); ^- W+ Y% k6 f! L/ [3 s% o
pos[0]=inf.throughput;) o, a& T' T; m; B
if(inf.turnover>pos[1])' W" W7 T" c8 I4 O0 j/ b1 D) a
pos[1]=inf.turnover;
G7 P4 u# t* v9 k, g6 mif(inf.wait>pos[2])3 ?/ o& E. `" F q8 i& X; {( L3 f
pos[2]=inf.wait;
+ Q2 G' ?. {7 b4 cif(inf.CPU_rate>pos[3])
9 L3 h3 Z! t1 `* R2 C/ `* Bpos[3]=inf.CPU_rate;
3 b5 E _1 T- M% \* x}' ]& f( z: K0 R; m
settextstyle(30, 15, _T("楷体"));
( N1 ~( _* e5 S- Vfor(i=0;i<5;i++)9 X! U- W$ a+ _
{
6 B5 v5 ]1 A4 {/ `; kswitch (i)" e5 Y7 o; g' l* \2 k7 V& B/ n+ o
{
( |% `8 r @: ^& a6 F1 c6 g Scase 0:& [; s* } t+ M8 K
setfillcolor(BLUE);7 f3 p; a; _, X) V: H! Y9 n0 V% c8 ^, ?
fillrectangle(100,50,150,100);. B8 s) ^* l2 M/ o( \2 R* u
outtextxy(160,50,"FCFS");
* z" [1 l9 P& Q$ Q) u' Tbreak;; A/ z% g4 S" u0 N' R! ?2 Q6 X
case 1:
! k, i7 |0 P8 l7 n! h* G# N' ^0 Usetfillcolor(RED);/ g. _7 f5 [: w( Y
fillrectangle(250,50,300,100);- E5 {& ?% c/ c
outtextxy(310,50,"timeTurn");5 f* D8 J, v+ ^" }$ I( D
break;; e- u* E r# b/ h9 n: z4 r
case 2:
3 q/ P: r4 ~" M9 Z" `) M' R9 msetfillcolor(YELLOW);2 a9 {1 p% P0 e$ C7 @6 P0 S
fillrectangle(450,50,500,100);
' a, C/ v! t4 J" ]# O, h* {- `outtextxy(510,50,"SJf");$ c7 q! m* e9 f+ g
break;
: q {* l- j2 M$ }5 icase 3:
9 t4 v/ N; S( w1 w$ x7 l- nsetfillcolor(BROWN);
+ L. e/ P5 Z) Lfillrectangle(580,50,630,100);
" M) @" c& U: m; }6 h S Oouttextxy(640,50,"PR");
. b8 c; q, V/ z# Fbreak;+ |+ `$ n/ D3 [
case 4:: ^' k% E8 }/ q/ y7 C! ~
setfillcolor(GREEN);
! a5 u- e7 q4 T. W/ @3 F) lfillrectangle(690,50,740,100);
- T$ ?; V8 D5 o, b7 fouttextxy(750,50,"HR");( n5 H/ C% |* p* Y/ D- T% h! C
break;
7 _; m9 }' r0 ]" _( U U}
7 W1 T2 ~' W; B0 n2 S0 zfillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);
' ]' {2 k, h" E i: ]fillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600); b. _. v! a3 N2 n: R0 _
fillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);
6 h4 o1 v' i7 F2 Cfillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);
- x, a3 v/ n# D. Y; |' }( d4 K
L& ?8 X+ `. Q' b: W+ S0 ?$ {# f: h0 d* H7 S* G
}9 q8 k2 C' b5 l8 Q+ z( c
outtextxy(100,150,"吞吐量");
4 }) e& h* |: ?( l6 c, ?! p( e4 F* \: ]outtextxy(350,150,"平均周转时间");3 o3 W4 T! U, |# l" w
outtextxy(650,150,"平均等待时间");# M1 ]5 x( G+ ?$ k# P
outtextxy(950,150,"CPU利用率");
. f1 H* v; X2 T& Sreturn 0;, l7 b; a1 {& q! t; J5 u: ~3 w; J
}$ r2 x+ y1 H* H1 ^
int MouseListening()7 i( d) [1 }* d: G
{, w# F% d8 K4 { W' Z
MOUSEMSG p;
. o2 p& |# X! G4 A6 `, B4 Kif(MouseHit())
, Z" L: P7 j3 f/ D d9 K{0 j9 J/ b6 n4 Z" L2 ]
p=GetMouseMsg();, I0 H' \# l# T* w: J8 |! Q
if(p.mkLButton==true)
1 A# r l! H1 q' f q0 ~" l, r! ~{( Y5 e& \6 q- D* v" z6 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)1 V$ [3 q) v. i5 U( a* J
FLAG_FIFO = 1;9 @1 w g# p" |( l6 B( t# f; H
else if(p.x>400 && p.y>0 && p.x<800 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0). X. h: c/ r& e: E- Y
FLAG_TT = 1;6 ^' a6 h* h4 ^0 h" h5 U
else if(p.x>800 && p.y>0 && p.x<1200 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
+ Z/ m0 _) u. d. xFLAG_PF = 1;
5 T1 R! s# Z/ N" B0 Ielse if(p.x>0 && p.y>325 && p.x<400 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
( `, S! n" N, G# mFLAG_SJF = 1;
; C7 g' x Z9 Relse if(p.x>400 && p.y>325 && p.x<800 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)4 d6 A8 ^' K2 a1 [0 x7 ]
FLAG_HR=1;0 i% |* P6 e9 q8 V1 C% g, V
else if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)1 @: D8 ^; H- n: H
{
" n4 o3 X+ f, [- E* z, Z7 I; |FLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;
5 {5 M: k* j$ u0 P7 O ^( N# gclearrectangle(800,325,1200,650);
! a) `+ G% o) P P. C}. Y8 U1 g. I2 y3 p
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 )
% U" x2 u# I: m. U" V3 W7 b" i{
( J( R& p/ Q& T) F# g, K3 GFLAG_show=0;
/ o5 | Q% M6 m* c# |cleardevice();
7 `" C) _8 n" preturn 1;* g% [& ?: j5 J
}
7 f! N. S9 m; q+ R}
8 h, O' g* Q8 T+ i! p1 j}
) E5 o; @! T" {. K3 a6 B" P5 o! ireturn 0;4 E4 ]& k& `+ X! D
}
; z! |- G# I5 Q4 mint MouseListening2(int *flagShow,int * showTime)
% B' y3 g# w2 [3 t' V [0 \( e: \{
4 [& v9 ]4 S6 r4 }MOUSEMSG p;4 |4 B2 p5 A9 \0 r ], I
rectangle(1150,0,1200,50);9 n* [, W2 c W5 r
outtextxy(1160,10,"X");, T5 T1 F& {& A, b4 L% r" n
while(1)3 M" \/ M0 ~8 h$ y. i& k/ R+ F9 W& a
{
( g( }- n& }% {$ W. M. @) f6 f# Xif(MouseHit())
$ W0 q! s* Q) s+ d+ Q- g l{3 s2 C1 r- D; y2 B8 Y2 y
p=GetMouseMsg();
k! ^" L8 q+ D6 G4 ?: L Xif(p.mkLButton==true)* P5 Y4 t6 v& u& H- C6 e) ]& u3 `+ D
{
# ^& E: \9 J$ m$ T" dif(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 ): V1 Z4 q8 x8 W. w1 g% s1 K4 m
{* [8 l; }2 c1 P4 m
(*flagShow) = 0;. I8 U2 A d1 o+ O
(*showTime) += (*showTime);
9 W' R" f! N' ]: Z! GFLAG_show=1;3 g9 D& P5 ^) G1 Z6 y
break;6 T' q7 F4 E# h8 Z( f' l' A6 H5 C7 [
}
+ ?) _- o3 i8 N& G' H9 h8 G5 P5 s. D" t
4 N0 ?6 b9 S. Y) X* _ \}
: C" z3 r/ c; a/ b* y6 k}
1 U! J0 K+ S' b9 OSleep(20);9 Y9 L% m. b1 d) d
}7 g# K% M% D$ _
cleardevice();
0 s& f1 N9 w0 w) `0 oreturn 0;: Y {3 u3 ?1 F
}. `8 X9 @6 H/ O2 e% _2 F4 G, b
int drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)
+ X3 a( L x' C: {) z{
2 m! Y4 S! h9 ?+ n; z, J5 xstatic int info[11][3],num=0;
, W7 N) H3 O5 H/ v( A- f/ ]int i=0,j=0,pos[10][3][2];
& i) J/ z4 Q; X7 B& F0 S3 mfloat temp,t;
" P2 z9 M* C' }- d//画按钮,不属于FIFO图的范围4 P4 `" R. G1 e+ q' Z, \8 q
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1): m% k* L+ j" ?
{
+ P7 z8 V4 O4 G, n! usettextstyle(30, 15, _T("楷体"));
- P' P( g/ z0 G4 vrectangle(890,455,1110,510);
2 t; U( z! `8 g, \* D1 v6 lrectangle(900,465,1100,500);' u* U2 ~# ?2 D$ S" r4 t
outtextxy(910,468,"查看运行结果");0 ^ u" S! r& Y$ s% \+ r
}
9 Z3 _. n/ d' D$ u9 D" A+ O% \* P. G" e//结束画按钮
6 c/ K8 g" H. Jinfo[num][0] = com;4 h% `' \2 m' p. P& c# a
info[num][1] = wai;
0 s$ J9 D$ J- G0 h/ @) E% ]info[num++][2] = cha;4 ?) X! I( c2 `, A9 M+ x4 {2 D
if(num>10) //存储10个点- V. ]1 W! M5 f% d
{" J, n- H5 }: S; g1 S( B
for(i=0 ;i<10;i++)
3 ~" F4 h+ m- B6 F1 o9 S{
6 o( I* L$ {; d" H) Vinfo[0] = info[i+1][0];
6 t5 T1 l. c; W2 J) cinfo[1] = info[i+1][1];
0 ~( V+ H. l- Q) h0 G+ \6 a; Q3 F$ ginfo[2] = info[i+1][2];$ j6 W! h) U: c6 ]- L
}
$ e& X) c9 c& Pnum--;# z! [( p0 ?* p y
}
. l: G2 J U+ p2 E Yif(FLAG_show==0)/ b( y* P! a8 }$ _; ]2 h
return 0;
2 ?& x/ s8 k5 W$ Y7 R I* M% Cfor(i=0; i<num; i++)
+ m" W5 D8 g, \$ K u( a{5 o, v) a8 D2 S; q4 n# o. a
t = (float)info[0];4 I8 g/ a3 J6 V$ F" i1 E
temp = (t/101)*90; h0 {* e8 f4 z2 g1 ^1 i7 i2 A
pos[0][0] = (10-num+i)*25+x+100;
4 H0 I/ [1 M/ U! bpos[0][1] = y+110-(int)temp;/ h& l9 M" W: |/ x) b
t = (float)info[1];
; s8 [( t3 z$ d M6 Htemp = (t/101)*90;0 j8 X) H ~. A" w5 D1 l
pos[1][0] = (10-num+i)*25+x+100;
; }* q l) E$ e/ {0 N$ Upos[1][1] = y+210-(int)temp;
3 M, K- Z8 R A; P9 ~/ s. c `t = (float)info[2];
4 D1 G# j0 E" btemp = (t/101)*90;: @! c( f# |$ F3 @
pos[2][0] = (10-num+i)*25+x+100;- O7 C, }( s$ l/ x
pos[2][1] = y+310-(int)temp;
% O! B$ k4 `& E( h, x* b& q$ h7 _$ @/ [}
; D) c& T: u9 S$ S, S# |if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
+ k: l. N5 I& l4 |5 Z{3 @/ x; j. m- Y( k- t, @3 w
clearrectangle(x,y,x+400,y+315);; m5 ]8 Z6 `( i. @7 b4 E; Q
settextstyle(20, 10, _T("楷体"));
# I7 H3 R8 F- e. [: Urectangle(x,y,x+400,y+325); _1 l0 d6 u% w7 C; l
outtextxy(x+40,y+10,"CPU"); //画柱状图2 P( A; A/ x. z9 s# R
outtextxy(x+45,y+10+100,"IO");& r6 W' d! P0 B. @6 _& H0 s, t
outtextxy(x+40-15,y+10+200,"change");
5 v5 a$ Z( B4 w. \4 Srectangle(x+35,y+30,x+75,y+110);: z3 G+ A9 }3 I7 C
rectangle(x+35,y+130,x+75,y+210);0 A' M7 @* o* B {3 o
rectangle(x+35,y+230,x+75,y+310);" D3 B+ J0 y2 \ J* M7 ?) K
outtextxy(x+180,y+310,"FCFS");
/ r( W% A5 M( w7 s* P8 }t = (float)com;
( J+ R8 K1 ^; H: m8 v3 n2 U4 y$ Gtemp=(t/101)*80;' d- }& j5 Z' w9 P/ K* W# ^
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);- L* J# O! D1 s: D: O) f
t = (float)wai;) T% v# z. R6 S7 x4 f, Y+ Q7 b
temp=(t/101)*80;
+ j# n, g1 t5 Q5 tfillrectangle(x+35,y+210-(int)temp,x+75,y+210);+ X- b% `1 I* g- s6 a
t = (float)cha;; j! k; S1 Z+ e, q/ N- x
temp=(t/101)*80;6 c f J7 W# c* Y) ~
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
2 v# N0 b' A# b4 X+ i& v: H. gfor(i=0; i<3; i++) //画坐标 high=90,length=250( E5 T- ~' g. G3 [/ y! e
{
& I8 O' ^$ Y3 f3 x& _line(x+100,y+110+100*i,x+350,y+110+100*i);8 g( e# k- {" J0 J1 J
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
& M! q3 v8 r+ t( V1 b! [$ jline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
' m& b8 z: ^0 l8 h( a6 i! p% A8 w' Y k1 h/ q
line(x+100,y+110+100*i,x+100,y+20+100*i);
: |7 Z- d7 L/ v- V' s1 yline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
2 W0 r/ P; o, Bline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);( Y! G2 g4 Y& `& X# x& I
for(j=0;j<num-1;j++)
8 e" t$ @* u1 U/ k9 Q+ P$ l{% t9 w' {- R1 G. I f! w" {8 u
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
" z y% O2 W6 Y( ]line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);9 D' M" u+ B8 u
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
& ^1 ?6 M7 c/ b8 F}
* {/ ^3 M* R8 v" C( N) [}
* g$ i9 J$ l" I" O# A}
) Z0 G3 d1 e* a1 {else if(FLAG_FIFO==1)
1 F' E9 D( ]- E. O% I- T5 r+ {; I{* q/ E) j3 M! Z1 U4 c" [' t3 F0 }
x=0,y=0;
8 o# T( z3 Y5 _) c. J* yfor(i=0; i<num; i++)& {9 S) U% }! {7 F1 O
{; k" ~& a) ^9 A6 _" ]
t = (float)info[0];
* R7 m# Z; \6 T1 l" Wtemp = (t/101)*180;8 H5 S+ A' x( s0 M
pos[0][0] = (10-num+i)*50+x+650;: p7 ~8 t8 s8 U4 i4 C' n" ?9 v) y; V
pos[0][1] = y+210-(int)temp;
4 |" s4 }" F- b# Z1 w; h7 ^t = (float)info[1];" c( F8 D& ^* n3 [2 T
temp = (t/101)*180;9 l1 f- c/ C1 T' l; {
pos[1][0] = (10-num+i)*50+x+650;
0 q# M' G$ k) y( X+ _* ^7 W4 Opos[1][1] = y+420-(int)temp;
% H" B) ~' z2 S+ ^t = (float)info[2];( X& u3 J; D! ~ n
temp = (float)(t/101)*180;
* q4 \- {7 b9 w5 hpos[2][0] = (10-num+i)*50+x+650;
6 o s: X J t9 d( Q" npos[2][1] = y+630-(int)temp;6 ]5 [( B% i+ g+ h
}! f; Y& ] q- P3 ^( [9 R
clearrectangle(x,y,x+1200,y+650);
6 p8 |2 ]$ B' q rsettextstyle(40, 20, _T("楷体"));3 g ]' ?- W+ a$ E9 i5 T
outtextxy(x+50,y+50,"FCFS");
3 r4 v7 u1 q/ K" @; m0 v8 Y, `outtextxy(x+280,y+20,"CPU"); //画柱状图
* Z' r8 I& z* k# D& w) |outtextxy(x+285,y+20+200,"IO");
/ d2 F; @0 H0 @7 D* qouttextxy(x+250,y+20+400,"change");7 I: [. n) E/ f1 ^# B. S P+ O5 `1 M# x7 e
rectangle(x+270,y+65,x+330,y+215);
% t. `# e; R) D* Srectangle(x+270,y+265,x+330,y+415);2 H: g/ u! \% e9 D# G
rectangle(x+270,y+465,x+330,y+615);4 z1 s- O$ Q5 v: _% ]
outtextxy(x+290,y+620,"TT"); _9 J1 e# P4 ^
t = (float)com;8 `* ]7 @8 N1 }$ d
temp=(t/101)*150;
% P1 e4 V" V: S4 _: U. Cfillrectangle(x+270,y+215-(int)temp,x+330,y+215);9 P, e- U2 Q$ ?" R P
t = (float)wai;) W7 [% V- A+ j0 B* g2 e8 Z
temp=(t/101)*150;% p& m6 D' [0 M- h6 N; h9 h
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);4 e. E( [' y$ K- n- a3 I
t = (float)cha;$ Y) B1 ]4 U, _% m+ I/ t
temp=(t/101)*150;
e! @2 f5 R& {fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
1 L5 c9 [: Y+ z0 hfor(i=0; i<3; i++) //画坐标 high=90,length=250
8 s# [" }- i$ r) Q3 W a{' q. N8 E# E9 a6 S, j
line(x+650,y+210+210*i,x+1150,y+210+210*i);0 h4 S' y i- p0 P D+ G
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);+ }+ r* Z7 h2 S3 n8 j
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
7 a* d5 q* b s; C [
0 Y+ e o0 b2 F+ n ~8 mline(x+650,y+210+210*i,x+650,y+20+210*i);7 ?+ U v, y& t! I
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
0 L6 Q2 \4 J# f' Wline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
* S3 Y8 G# p, }# `( m Ffor(j=0;j<num-1;j++); r/ A. ~8 [8 g. m [1 x! y3 }
{
7 g, n$ s% x5 W1 j M, R# B3 a0 jline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
1 l5 p+ @0 q" {+ n3 y% T% Yline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
4 I" Y$ i3 \/ Tline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 6 g& H0 a) |1 t, A9 o( F
}! P% U' `9 b4 F& I# c' ~$ L8 b
}
. _6 N# J8 B4 n6 ?& Z* \, A}
* Z3 q/ T8 }$ D# r& V
% N/ l9 j2 K6 P ^
: I. \8 \; U' i7 `; I( dreturn 0;
' M0 w. E" A& e) U! T) C}
# c$ L6 q" w/ w9 Sint drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha), R8 p4 n* c! p5 Y9 u5 _
{
0 { Y% ~' s/ V& `3 M; Xstatic int info[11][3],num=0;9 Y, z! C( X5 ]7 b% G6 E& Q0 w/ D, k
int i=0,j=0,pos[10][3][2];
7 y; d1 @ O, i" ], k1 T9 bfloat temp,t;
d& }( N! i- B* ]8 x. x6 Hinfo[num][0] = com;9 Y7 t2 m* X/ c0 a5 b$ V
info[num][1] = wai;7 o1 v$ T0 P6 v W% |: K' \3 Z2 I
info[num++][2] = cha;9 C; L; x: W/ M. y, R2 g- D$ i
if(num>10) //存储10个点
& L; O ^6 E+ [2 P( l{
0 k& y/ E7 M5 ofor(i=0 ;i<10;i++)
+ P1 D! `4 w" _+ R, g% U{
' A3 R9 I" \) m0 v# p$ q4 g5 tinfo[0] = info[i+1][0];
! Y4 k5 ?% D1 A- pinfo[1] = info[i+1][1];5 ~2 G1 g3 c0 d/ k6 j; H' Q3 s7 R
info[2] = info[i+1][2];
( j- T# v* H6 B}4 C6 M- z6 s+ R2 c$ L
num--;
# m2 n7 @: I4 B: s}$ p' W+ v9 M' M$ L7 q) J8 ^' q
if(FLAG_show==0)* i4 L0 C$ h4 w( x& l; _
return 0;2 r3 `0 c) R, T! `9 [" e
for(i=0; i<num; i++). p' n L- m# }" }" z, p$ m( d7 m
{) v5 L+ j l9 N( d# P8 z
t = (float)info[0];
9 }+ ]: c4 r! [temp = (t/101)*90;( g2 d4 {* J2 @% r
pos[0][0] = (10-num+i)*25+x+100;* U$ r: n- A& ^6 r
pos[0][1] = y+110-(int)temp;
; k# z/ l! n" |* ^t = (float)info[1];
! _6 M8 c& ~ L) E" _' p t3 Stemp = (t/101)*90;# U) F" n/ h/ f& ?+ w
pos[1][0] = (10-num+i)*25+x+100;
" @ }$ z9 ?* ]& U- h" }9 gpos[1][1] = y+210-(int)temp;8 p) Z( ]$ n4 ]) L8 v+ p1 Q7 |
t = (float)info[2];
6 G* h7 M r7 V, O1 B. ]6 ]1 y& Ztemp = (float)(t/101)*90;
! j% p8 S6 b- x0 |pos[2][0] = (10-num+i)*25+x+100;
. g- J N4 |2 [: e& p$ o$ p; [$ ]/ Hpos[2][1] = y+310-(int)temp;
" c* f( R2 G& q. l& ]" k}
! L& T" b, [+ M3 Y5 H- Tif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)( F/ ?' ^. g" z* f! ~; O' p4 c
{
5 R$ T5 R( t5 R7 vclearrectangle(x,y,x+400,y+315);0 V7 f1 \) T6 y* T1 H$ v; G+ l
settextstyle(20, 10, _T("楷体"));
" I: k* }2 {! W9 B0 ?! \rectangle(x,y,x+400,y+325);" _$ N4 B/ h2 N6 a$ Z$ a2 j
outtextxy(x+40,y+10,"CPU"); //画柱状图
! H; `( ]9 Z5 V$ m7 mouttextxy(x+45,y+10+100,"IO");
. Y+ X0 d) W& ~+ mouttextxy(x+40-15,y+10+200,"change");
& F! z6 F) b1 V3 ]6 a2 U" Grectangle(x+35,y+30,x+75,y+110);
l6 R4 [# w" |6 ]) j9 H/ Q; Hrectangle(x+35,y+130,x+75,y+210);
& ~" {. r: ^! ^5 k3 u( @rectangle(x+35,y+230,x+75,y+310);
" V: C( z2 i! v4 Q8 iouttextxy(x+180,y+310,"HR");
7 [6 m9 W6 w" ^: xt = (float)com;6 Y' l6 ?/ O6 q2 }) ~5 O
temp=(t/101)*80;
" H$ W! ~& f* T3 R Ffillrectangle(x+35,y+110-(int)temp,x+75,y+110);
: L8 `8 d' h1 ~: j* it = (float)wai;
. }. j: B# w9 A* @7 e! Rtemp=(t/101)*80;
* s# J, {, ]8 E3 M1 Hfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
6 X0 F% e( c! `/ D/ W+ ot = (float)cha;' f# p9 L# v; [3 Q8 R( _
temp=(t/101)*80;
( a3 l& [; b6 Dfillrectangle(x+35,y+310-(int)temp,x+75,y+310);
# \# o$ | M. {; T: W9 T4 Ufor(i=0; i<3; i++) //画坐标 high=90,length=2504 d3 r+ ]: _6 n! l! ?* V
{6 p. g' ?/ x5 h% Y2 j3 f0 c6 a
line(x+100,y+110+100*i,x+350,y+110+100*i);
0 k! E# A' V0 Y0 e eline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);3 T* D( W; @( p
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
4 c$ A5 W" c2 I# p4 F- A# Z. X
' m6 Y0 u) B X9 X6 Iline(x+100,y+110+100*i,x+100,y+20+100*i);
' @* M% g9 A% `" j( P: k# pline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
1 R- L2 I) h7 [$ }$ G2 \6 ~% U" Gline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
3 ^. n( ~) h8 Z6 c O8 kfor(j=0;j<num-1;j++)) Y7 S, ^0 _$ g" }6 D
{7 J5 T$ j! I- [2 q: d6 J
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
$ M. M4 i" K/ Lline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
* i& d1 U; o# o$ ~9 xline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
" l" {" ^* ? \5 T8 |}
6 |, w! m* T9 v0 B4 i& A+ ^}
, S/ {, ]( o$ C}
) ^! t3 M( M! O2 \/ Lelse if(FLAG_HR==1)
1 ^2 F. S# o: X9 n1 E{! `, M' o. E: @# g
x=0,y=0;/ s$ ~( h2 j& _, H% T7 @) P) q
for(i=0; i<num; i++)! x/ W: j; z3 L/ j* |* p2 P/ a' B
{
$ R' U& ^3 K( n9 ` F* vt = (float)info[0];. J9 p" R- q' s
temp = (t/101)*180; m8 Q! h7 a3 J3 I) l
pos[0][0] = (10-num+i)*50+x+650;
8 |/ _& t0 s5 b- T8 e9 Opos[0][1] = y+210-(int)temp;$ `4 A0 W. `( h- q
t = (float)info[1];
I2 F/ n3 X4 vtemp = (t/101)*180;( }, V- \+ A5 u- r/ E
pos[1][0] = (10-num+i)*50+x+650; H, R# O2 j {' K3 j, k* [
pos[1][1] = y+420-(int)temp;
% o0 {' u1 J- J" ct = (float)info[2];4 Z; g, t( p6 `8 F$ w) Y6 a) W: }
temp = (float)(t/101)*180;
* `: j) T% H2 W! {. I" |; ppos[2][0] = (10-num+i)*50+x+650;% k; }* e- e7 O& E
pos[2][1] = y+630-(int)temp;
* ]9 D+ Q5 [! p0 Y1 P, u}
4 X2 C3 N: ~( d* [* Fclearrectangle(x,y,x+1200,y+650);) \% _/ e/ P: C: S2 R1 |' E
settextstyle(40, 20, _T("楷体"));
+ K+ f2 V9 c; L. {& q fouttextxy(x+50,y+50,"HR");
+ p) H7 z& Q7 S; `) xouttextxy(x+280,y+20,"CPU"); //画柱状图4 V. b* R' i: M& R9 n
outtextxy(x+285,y+20+200,"IO");# l) E" W& `7 M9 r2 G# p
outtextxy(x+250,y+20+400,"change");2 E7 R3 \: S8 D6 L. i
rectangle(x+270,y+65,x+330,y+215);" f( d, G+ I; A0 a
rectangle(x+270,y+265,x+330,y+415);
) z3 l* f9 H$ R3 _rectangle(x+270,y+465,x+330,y+615);8 n5 m8 `1 f3 Q# S% S' Y; C% z& d
outtextxy(x+290,y+620,"TT");3 V, e" Z- O. A3 J
t = (float)com;
( b4 D, V" V1 Ctemp=(t/101)*150;
3 \2 ?* c3 B( x! R) O3 _fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
2 P3 _$ \7 d0 n$ F9 N8 ?t = (float)wai; e1 L! y0 q8 b8 \% z
temp=(t/101)*150;: ~5 o% i4 o8 P F& o
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);' o, r1 i( X- {+ t
t = (float)cha;
. G& ?' i, z8 p, `temp=(t/101)*150;
% S* l6 J) a5 k! D+ Jfillrectangle(x+270,y+615-(int)temp,x+330,y+615);
/ q( Q2 }+ _# p6 M; {; sfor(i=0; i<3; i++) //画坐标 high=90,length=250/ m9 k' R1 U( z2 r
{- Q' i" V$ t) p) _* M& W
line(x+650,y+210+210*i,x+1150,y+210+210*i);9 N& m8 f3 }4 C1 ~ J' t9 {
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
8 j* x$ A+ v4 ^' fline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);9 X l7 [1 S9 h! @, e: M
3 e( w' H* T. bline(x+650,y+210+210*i,x+650,y+20+210*i);
7 K# Z6 F+ B9 L* c }: zline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
* u+ r: `5 K5 v/ ~. v7 j5 G5 I. ?line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);" ]' E1 @" ]6 N. p1 h$ T. [- H
for(j=0;j<num-1;j++)
. ~) F4 g# j6 j6 R: V. n{$ \+ X* [: s; r" X
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);& h+ ~+ T4 K: B
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);" A- s: r; R" Z, b; |
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 5 f) t; g& b) h
}: m* a$ @, s' U4 L( c3 M/ Y* M
}* Y; H0 B" y9 x- w h* M2 I7 Y
}
' [2 p( T8 \. c, a" Y$ q6 \; V& s$ [% `; d4 [3 Y
* D& @. |, m9 ?1 j
return 0;4 z, ]* b$ F) {/ X/ K
}3 t. a" q+ A! U( N3 C% x
int drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)
5 h, D% }4 r3 Z" b{1 D7 H7 c5 [, b% I
static int info[11][3],num=0;& u$ I# B! V7 `
int i=0,j=0,pos[10][3][2];1 D8 ?* ?. P, ?
float temp,t;) n5 {. Q- w1 C+ f+ U
info[num][0] = com; W- B: C& p p: e+ p. i
info[num][1] = wai;) l) \- z$ |6 x; Z5 [, {
info[num++][2] = cha;8 ?3 r* W% X% e& C3 f
if(num>10) //存储10个点
5 Q5 f0 g: U5 q9 o9 y* T{5 k6 a, A7 ^6 M8 V- n7 L$ o
for(i=0 ;i<10;i++): Q$ [4 C& s( o& o/ `
{
0 f5 L( }6 Q" ~# u7 Z! ^5 N6 Y$ I5 Xinfo[0] = info[i+1][0];; V. C, v, g1 S
info[1] = info[i+1][1];
# x0 [+ _+ b6 z8 p! hinfo[2] = info[i+1][2];
! c% \1 r- v( f% p. M1 N; ~# B}. D4 F$ }3 F. t0 D ]
num--;
& h G5 h* D' n}
4 u1 l( Z3 z4 ^$ yif(FLAG_show==0)1 w0 }2 r: M& _0 ]" Y
return 0;
; F; ~9 h$ f% Yfor(i=0; i<num; i++)
. C! x/ H3 J* S; e{3 ^: h" }1 f# Y/ _" Y( F
t = (float)info[0];
4 Y5 T' o# j6 gtemp = (t/101)*90;
0 F% ]+ ~( ` Z% s# r2 U+ lpos[0][0] = (10-num+i)*25+x+100;
/ N* c I# u. v% \7 apos[0][1] = y+110-(int)temp;
/ c! O( K$ u0 [6 l" O8 V+ Qt = (float)info[1];
. O4 v3 R' t' m( |temp = (t/101)*90;
% z5 |; z) D! X. w; }2 Opos[1][0] = (10-num+i)*25+x+100;7 @& Z% G9 X# c7 \4 v2 V- b: X
pos[1][1] = y+210-(int)temp;
+ T) w0 s7 ^4 l. r' ^/ K' qt = (float)info[2];3 r: K6 k% B% X: U& s1 z
temp = (float)(t/101)*90;
# N3 p7 P2 q) I' D q' upos[2][0] = (10-num+i)*25+x+100;
/ \5 l: T I0 W. [pos[2][1] = y+310-(int)temp;
. }# w- @; A; [}
0 p7 m- D( y: A& |# I Kif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)* j0 T3 I0 X, l8 z9 w) ^) d
{6 ^( O4 d6 p6 |- H7 k
clearrectangle(x,y,x+400,y+315);9 G* k2 `# E2 e8 d; K8 e4 Q* D! \
settextstyle(20, 10, _T("楷体"));; k( I6 I+ s& A* {; f
rectangle(x,y,x+400,y+325);
, S" _% F" `; s. N) \% touttextxy(x+40,y+10,"CPU"); //画柱状图
7 G7 A, i! L2 ]( Mouttextxy(x+45,y+10+100,"IO");) {( j& x& D8 | I0 O
outtextxy(x+40-15,y+10+200,"change");& s9 N6 D( N4 [6 B2 w- u! w
rectangle(x+35,y+30,x+75,y+110);: ?. j9 |/ z( f. i# _- J
rectangle(x+35,y+130,x+75,y+210);
( h$ J0 Q a+ v. D; c7 o; O3 frectangle(x+35,y+230,x+75,y+310);4 }3 p/ q- \( @& M
outtextxy(x+180,y+310,"TT");) ?6 D/ T! _2 {: d( M
t = (float)com;
2 U, ]& ~9 G1 X0 p7 Wtemp=(t/101)*80;( D6 h2 v% v" A" G: d9 c
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);2 V5 e+ u0 Z4 n& g
t = (float)wai;
- ?. q6 v- J7 w& J5 Htemp=(t/101)*80;
- n9 T, w4 K" M7 P2 Afillrectangle(x+35,y+210-(int)temp,x+75,y+210);' V) L2 _% L: M" j; T; e! ]; k0 g; s
t = (float)cha;; p& z% b% H+ o5 ~/ U
temp=(t/101)*80;5 x; J/ ]) M8 A% v
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);* W( w1 Q! ^2 `, g/ I. S" B: a7 D; W
for(i=0; i<3; i++) //画坐标 high=90,length=250
0 x# t; H8 T4 f, N{: [8 {7 m# g1 O7 v) W
line(x+100,y+110+100*i,x+350,y+110+100*i);
, x, P, U; _2 z( r& t, Lline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);0 p& F5 }9 C% G
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);- ]9 j$ j1 b- E5 t Q
2 P) C2 @/ c/ ~# t6 A i
line(x+100,y+110+100*i,x+100,y+20+100*i);; O$ M7 p$ `. o& |' Q' ?8 H. Y% Z
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);8 \/ E2 q3 @% {
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
0 P8 e: ?* b- {; X$ kfor(j=0;j<num-1;j++)
- [5 L* _' `) T' j{
" |! N" ^) z0 m; ^2 O$ T; m g1 |line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);4 C) `/ c' @8 {3 e
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);6 D8 C* L9 a2 q
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); . R7 I* {/ }! ~& r/ _) H
}( h' b }5 C! w$ Y
}
- h! s; ~9 f3 j0 W. i/ @5 M5 F4 ^# ?7 }3 N}
: E/ R7 `) F2 J* F* q6 R/ c6 {else if(FLAG_TT==1)
# ?7 y# l6 @0 q# z2 i* u{
4 b1 i1 u& p) \- l/ f+ Jx=0,y=0;
6 l( O7 q2 i& `4 w0 Kfor(i=0; i<num; i++)2 H9 L# i$ t- u2 m2 d3 S# U& B- y
{
! I8 X3 ?% z* b- St = (float)info[0];
$ B% N6 |5 w/ c) a( y6 Gtemp = (t/101)*180;
2 L+ b/ P; G) O. G& I5 {pos[0][0] = (10-num+i)*50+x+650;
, r6 m2 I/ ^6 Y! n1 M/ t; v+ Kpos[0][1] = y+210-(int)temp;
, s5 ?1 E9 {4 D& ]$ @! v3 H. It = (float)info[1];: W* ^' B5 e9 C
temp = (t/101)*180;5 Y8 o+ S7 E& g4 x
pos[1][0] = (10-num+i)*50+x+650;
: [5 Q4 \. |1 g9 K* w+ lpos[1][1] = y+420-(int)temp;
v5 {0 r- E$ K: k' P' @t = (float)info[2];) ?" B, x* H1 Q4 U% ]! ?% j
temp = (float)(t/101)*180;$ W7 }9 C6 t% J8 L0 s' ] S
pos[2][0] = (10-num+i)*50+x+650;
! t# J0 g. [3 H3 p: bpos[2][1] = y+630-(int)temp;6 u7 k+ Z& H0 u# m9 ?% o5 C
}
( j5 O i- n% c& Cclearrectangle(x,y,x+1200,y+650);
5 Z+ K( m$ k% w6 k- p4 L! ssettextstyle(40, 20, _T("楷体"));
. O2 m: z; M i, G2 gouttextxy(x+50,y+50,"TT");
" [% B; Q5 K& J# M' @. ~& jouttextxy(x+280,y+20,"CPU"); //画柱状图) y, n( I2 ]! S: v4 S2 G* z
outtextxy(x+285,y+20+200,"IO");
+ j/ T) k+ @4 K9 r; y4 E' g0 w& Louttextxy(x+250,y+20+400,"change");
( o+ R( e: Q* y. o8 m; {4 X0 Orectangle(x+270,y+65,x+330,y+215);
' J7 F* p$ T- N. @8 G+ m7 |rectangle(x+270,y+265,x+330,y+415);
8 P& h" N. L; srectangle(x+270,y+465,x+330,y+615);
4 a. B5 I, L% t( d4 `3 @outtextxy(x+290,y+620,"TT");8 x5 w- t* M: z8 Z! E
t = (float)com;
* \8 \% ? v( b8 Atemp=(t/101)*150;
9 \$ `+ u; C) y" q! pfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
7 w6 k3 |: O8 Y$ m. \t = (float)wai;
4 E4 K6 h! F# R& y; D! stemp=(t/101)*150;: A8 P+ F7 [5 g2 N& ^
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
; V. B( U, W! k: h$ J. c! {2 R" j4 t' Jt = (float)cha;( q; u0 g. {7 |: F2 m+ }+ m
temp=(t/101)*150;8 J6 z% \3 ]8 h3 y# T P$ n
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);" d- w( k: b8 k/ ~; C+ ] C
for(i=0; i<3; i++) //画坐标 high=90,length=2507 p: O* K3 m* b# S* c3 o" h' J* j2 C- x
{- V8 I! w, e) K& f5 s
line(x+650,y+210+210*i,x+1150,y+210+210*i);
# B+ B* f, n5 K" j, F' fline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
) y* A: [3 {8 g. y- eline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);/ g+ P$ Y& X/ n, r" C. u% G% T
& Z. J- J+ j# {0 s; Z% e$ Lline(x+650,y+210+210*i,x+650,y+20+210*i);
- \4 C9 q( H5 F [8 U$ b+ d1 ?line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
; i0 s+ k' k% H: a# M5 ~ _1 pline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);( v* `! U3 t6 I3 x
for(j=0;j<num-1;j++)
+ n& m- ]% t- J! J. J8 G5 c4 G{% M" L5 C2 E U" c6 G
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
5 I- p6 h+ M; ?: z2 _0 b2 L8 Aline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
" |. [ Y; I: fline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); * u$ p% O% t& E, A/ h
}/ F: q0 \7 s% g8 c' A; b
}
& J+ u( N- I- x: |$ ?% P}% x/ a* T1 O8 {
) h* R+ H, f4 C; I4 \
4 z/ C2 }! Y2 [" c" o, \& t
return 0;9 F+ u# b8 x7 m6 g3 H% U: N E
}
* E/ A* e( A5 k0 @, m% N9 v6 Xint drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha), f/ w, I s/ T) R
{$ Z0 q2 ~+ q5 T* J8 f" ^
static int info[11][3],num=0;* t$ c5 ~$ }' S" _9 g" P
int i=0,j=0,pos[10][3][2];0 Q2 l O$ O" m! @2 `. c
float temp,t;4 O- q! u W$ f4 X% o# B- {, z F
info[num][0] = com;
/ L1 Q a/ B9 l4 f! p8 kinfo[num][1] = wai;0 m. f4 @1 R/ q% @, D! N" K! ~2 x
info[num++][2] = cha;
* ^0 h6 Z7 n( q H. Lif(num>10) //存储10个点; b; ~# t: v/ f- z$ e2 |, O" u
{4 U! f& w0 k5 J$ S" {3 b! @" Y
for(i=0 ;i<10;i++)
+ B$ ~# s& w+ i: t& Y% _{
6 `$ O4 E3 `' t" Q0 T, C% ?# Linfo[0] = info[i+1][0];
4 a7 S0 F/ N' W4 Kinfo[1] = info[i+1][1];
2 P. D4 W0 b, w/ {1 }% Ninfo[2] = info[i+1][2];- z; _: C/ h% k. a
}9 q2 T8 K' i9 S3 v! q8 C x
num--;( D9 z. w1 Y* L, X5 S b3 ?
}# _7 z/ c, f& C& n6 O. B1 o
if(FLAG_show==0)
& S; n) E3 R- J, W, H; _6 j2 Zreturn 0;
( [& q9 ^ t% Wfor(i=0; i<num; i++)2 n" x# C7 C; C
{2 v0 E2 @: \1 w0 w$ b: e
t = (float)info[0];: g1 H! X2 g3 P* G6 ^. h' g
temp = (t/101)*90;
1 e7 r" v6 I7 Y+ C1 tpos[0][0] = (10-num+i)*25+x+100;
W$ E7 Y( s! z" O9 q1 \. opos[0][1] = y+110-(int)temp;
3 L$ g# N( w1 r6 u: q; C* N- @t = (float)info[1];
* t3 W, E6 z& ?* u, {* Wtemp = (t/101)*90;
# I$ F4 i; i9 u% b+ w: |( A3 k' }1 W9 Opos[1][0] = (10-num+i)*25+x+100;
& M$ A+ O! r0 h# [5 W1 q# Kpos[1][1] = y+210-(int)temp;
- l. n+ c4 `% e: \, L) @2 a# Y7 l* @t = (float)info[2];
6 F& e+ d2 [ E$ ptemp = (float)(t/101)*90;
' s k! s9 F" |+ z; \5 Spos[2][0] = (10-num+i)*25+x+100;
# a5 N6 p; ?5 z5 |- Fpos[2][1] = y+310-(int)temp;( `2 W+ I# [5 A' y" [7 S/ C6 G/ J
}) l5 O9 x+ E4 C0 E9 F, f
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)- Z; j/ o: N: T, c
{: P$ A% ~* F2 F
clearrectangle(x,y,x+400,y+315);
0 C3 _' {, n+ ]/ {3 Qsettextstyle(20, 10, _T("楷体"));; r# a5 Q5 K0 _8 ?- R6 H
rectangle(x,y,x+400,y+325);$ T# j1 N4 F0 Q. H2 Y- s0 O' i: E
outtextxy(x+40,y+10,"CPU"); //画柱状图
$ ?2 g- N7 a! ]1 J' W+ Vouttextxy(x+45,y+10+100,"IO");: v6 D6 }* {8 n! r, l
outtextxy(x+40-15,y+10+200,"change");. r( M& a( Z& W) b* l$ d B9 }
rectangle(x+35,y+30,x+75,y+110);" c( ^ l7 W/ C7 R0 H3 T; q' g/ V* E
rectangle(x+35,y+130,x+75,y+210);
8 h# d% L7 X4 E& D+ v& ^9 irectangle(x+35,y+230,x+75,y+310);
& S. m! i6 G7 g" Houttextxy(x+180,y+310,"PF"); |( {4 t% G2 d% Y
t = (float)com;
/ N4 t. c$ Q3 ?* d5 t9 otemp=(t/101)*80;
; }( X# ~. q h# I$ Y- Q" o3 x3 lfillrectangle(x+35,y+110-(int)temp,x+75,y+110);8 h0 h$ e$ _) M( {9 o
t = (float)wai;0 |7 W4 ?4 R( u3 }' X: v
temp=(t/101)*80;9 ^" y( q, a5 d! p1 g& h4 L
fillrectangle(x+35,y+210-(int)temp,x+75,y+210); l! B( I d5 `5 g7 a5 b1 d* B
t = (float)cha;
7 I( j/ k- H: h: rtemp=(t/101)*80;6 E; e, ~+ h: \, j7 W
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
2 j) \/ q( z( h. p9 b# lfor(i=0; i<3; i++) //画坐标 high=90,length=250
; f; {8 J/ h/ e& m8 s9 _7 G1 F5 p* b{+ s1 `/ ]2 M5 c: e
line(x+100,y+110+100*i,x+350,y+110+100*i);" i7 v( u; T c* y) f2 w0 {4 e
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
6 d" A# ^1 H( y b9 ~line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
5 H- G5 Y2 |& H" R% S0 N+ Y8 S+ p x
/ P- B4 [# g$ c' f/ k% B0 x2 S0 R# A* Bline(x+100,y+110+100*i,x+100,y+20+100*i);' p% R: Z" m3 B; o4 y) L
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
7 R6 b" A; M1 s# E, `line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);# M$ d4 P! i+ C) H% a( E7 E
for(j=0;j<num-1;j++)
( ^- K! m; D0 q* v2 |1 J{
0 v8 W2 \; K; k, d, a9 D1 vline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);% M3 F, j9 u, j8 O& X7 k
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);/ D/ B, v, l0 b$ K1 k
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ; [: u5 @" {0 I7 U: m8 x# D
}
: X% d0 B, [9 K8 O- K}
% m9 }, h. a) L/ w1 ^9 j}; ~7 ?# C; j6 ^, T/ W
else if(FLAG_PF==1)6 [# g4 Q2 U7 E, ^- ?
{
, n6 g) K: @6 o9 ?0 ?+ h: I: H5 vx=0,y=0;5 |. P m/ L2 h; `2 G
for(i=0; i<num; i++)
4 Y) n# @# R* C& U{( D) x6 ~) {" c+ X! s9 ?
t = (float)info[0];
7 X0 d) b0 Y! |' U, _% D& utemp = (t/101)*180;
5 k l: ~5 f# upos[0][0] = (10-num+i)*50+x+650;
3 }& j; F+ Z8 h+ [/ C. a* cpos[0][1] = y+210-(int)temp;/ b+ {& R' ]" u7 V
t = (float)info[1]; g" z& C( ]6 M9 K3 \! C' Z3 D
temp = (t/101)*180;0 S9 r$ j: m& F/ m" e' Q" Q: b- \
pos[1][0] = (10-num+i)*50+x+650;9 H0 c+ Z' x7 ^
pos[1][1] = y+420-(int)temp;
! G. A! P7 M |! c, j4 r- c# K: Bt = (float)info[2];9 A- b1 F& l/ N0 e9 Q) u
temp = (float)(t/101)*180;
% G7 I! h, I1 l- E+ E0 e6 Epos[2][0] = (10-num+i)*50+x+650;
) K& C$ E' C) }( L6 \4 `pos[2][1] = y+630-(int)temp;
* b4 n$ a$ J* x5 s}
7 B6 @" b k) i( A$ Hclearrectangle(x,y,x+1200,y+650);0 R2 S+ _; p9 O; b4 ^* M. r, r
settextstyle(40, 20, _T("楷体"));
1 f4 J$ N6 J2 m6 n+ P. H nouttextxy(x+50,y+50,"PF");
8 I6 @: A6 o$ M4 U; I! kouttextxy(x+280,y+20,"CPU"); //画柱状图# ^6 z) M4 e0 l% ~
outtextxy(x+285,y+20+200,"IO");
' u3 J: H0 b" _7 pouttextxy(x+250,y+20+400,"change");
( D7 [7 ?% o/ q( Erectangle(x+270,y+65,x+330,y+215);
( L6 n4 ^. t* {7 S9 G$ w j: f5 Jrectangle(x+270,y+265,x+330,y+415);, p! D% }: H; Z( \
rectangle(x+270,y+465,x+330,y+615);% o' S4 T! G, ]+ Q
outtextxy(x+290,y+620,"TT");
- B2 |, E7 g) r J0 a. e+ Ft = (float)com;
! i% Y# e x) f6 a! @) k& Xtemp=(t/101)*150;
1 \- Q& u8 g5 G- G, \6 D# {fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
2 v3 z( g. ^$ K1 M* Zt = (float)wai;
+ J% \9 X; D/ F0 X* Ktemp=(t/101)*150;7 R6 i+ p' z, O$ {7 M7 C
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
+ h. E4 b' U& B! st = (float)cha;" ^. W1 n$ s6 X$ S6 r; N4 m0 L9 A! ^
temp=(t/101)*150;
9 H3 _; O: W) G* ]: q9 kfillrectangle(x+270,y+615-(int)temp,x+330,y+615);$ o( H3 @ O$ H5 |' S
for(i=0; i<3; i++) //画坐标 high=90,length=250
- Z6 ^1 ]$ g; {0 f! v! z6 b5 @/ h{" `7 e6 _- H" p3 Y
line(x+650,y+210+210*i,x+1150,y+210+210*i);
8 b% @9 Z/ x1 ?) Z3 Yline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
: w3 U8 T" k. T. o1 j8 Aline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);" i3 t7 r2 s8 [
% v @: ?- s7 J" Y
line(x+650,y+210+210*i,x+650,y+20+210*i);0 @- p1 o3 v% R, E1 L5 F4 M- D
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
, Q2 w; ~* }. ~line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
$ O' `: \0 s; G- p yfor(j=0;j<num-1;j++)
8 F3 l9 m( Z; C v3 S& d5 W# n! g. |{0 @4 O( M, f: G/ x, b
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
# G# G6 c2 b9 qline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);5 n! s0 O5 d4 ?: q
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); + z4 i |" W& @8 |
}7 ]" x$ }( a( I" Q+ e% l
}
i( E* {2 i0 p, f6 ]}& l1 ~" V4 u5 O# m3 x
return 0;
5 H D7 T- I) v6 Y' Z}
) Q# ^. |' Z; r! X' r3 cint drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)
1 d! F" g* F: \# n+ Z" u/ k4 G. l* [{9 ^6 \( M0 j4 j. Y1 t* D
static int info[11][3],num=0;( _% W. Z1 i* g+ t$ d& ~* [+ h7 k4 U
int i=0,j=0,pos[10][3][2];
. s* [9 l- G0 I' Gfloat temp,t;
$ @* o7 ~! [, r! ?, einfo[num][0] = com;/ t% }" n4 l! f
info[num][1] = wai;
* f0 g# E+ t, ^. _: Oinfo[num++][2] = cha;# Z- G+ @8 z/ a. V- H
if(num>10) //存储10个点
3 m: _; q' e3 k8 H& ~& Z{
) i$ w6 m# x" a9 O& V- y& Vfor(i=0 ;i<10;i++)9 ?1 _1 [' B0 h5 G, `$ s
{7 }' m: T" L& q. E4 [
info[0] = info[i+1][0];: {7 K8 ]+ w- i+ T. F" k
info[1] = info[i+1][1];
" w* `8 o$ U# Y7 C3 Y' l n3 Binfo[2] = info[i+1][2];- B- x, h+ R L) Q9 E
}
: n% D* f. y/ l9 P4 k/ Fnum--;
4 X6 _% T+ p3 e2 T7 _}8 T7 r) n" | F+ s& H
if(FLAG_show==0)
3 D _9 \: n$ h$ m- Kreturn 0;
' b0 M2 {) T$ {) c: {for(i=0; i<num; i++)
7 y& Q* ~3 J# q{
' H4 d+ _+ y8 n2 q. w/ k. s* s- ct = (float)info[0];
/ l( i4 q7 o$ S# O) Ltemp = (t/101)*90;
* J% U1 f/ m8 I- k% w5 M- Wpos[0][0] = (10-num+i)*25+x+100;% z s( t. v+ Y7 Z8 {, c" _- p% ^- ^
pos[0][1] = y+110-(int)temp;4 q* O6 N6 v! @% @+ S7 \
t = (float)info[1];
, s) N2 {% E' V E) I o# Q6 p8 Ktemp = (t/101)*90;4 x9 b( l7 ?# I2 \
pos[1][0] = (10-num+i)*25+x+100;
1 p1 U- V% n- U: X0 F/ qpos[1][1] = y+210-(int)temp;
+ @% ]% \: s6 ^+ Xt = (float)info[2];
7 l& h0 X, z1 k! |) V/ gtemp = (float)(t/101)*90;
i7 g& a O( J8 a! o: P4 R# Y2 D* Apos[2][0] = (10-num+i)*25+x+100;
2 ^, b7 }3 C, V) R/ p8 {+ Tpos[2][1] = y+310-(int)temp;/ b/ S: ?, V" D8 n) n
}
6 H8 h# F, u3 c: cif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)2 B. D5 |' D& p
{ " r( x# H: _# w, k4 q
clearrectangle(x,y,x+400,y+315);- y% R6 L* ^$ p6 R# R
settextstyle(20, 10, _T("楷体"));
1 l& p! ?, H" b9 M( g- G- vrectangle(x,y,x+400,y+325);, h& l% r% Q q6 R3 r _
outtextxy(x+40,y+10,"CPU"); //画柱状图1 s; ]" }' w4 P, Q
outtextxy(x+45,y+10+100,"IO");5 ]" W* O1 n% X, F& h! N
outtextxy(x+40-15,y+10+200,"change");. W; D3 \: {; p0 R1 c' G+ [
rectangle(x+35,y+30,x+75,y+110);
2 e# P0 R2 A0 R6 P7 v4 d: urectangle(x+35,y+130,x+75,y+210);4 S* y# I4 N0 H9 U9 k I) g( l$ g( [
rectangle(x+35,y+230,x+75,y+310);
1 W8 z/ q' R5 ^7 t3 F) A" touttextxy(x+180,y+310,"SJF");) o6 \1 \8 X3 X) {& t9 Q2 a
t = (float)com;, \1 f* V5 O: O4 y d6 B2 G
temp=(t/101)*80;" s' o' j3 W2 D4 i9 H" M' F+ }
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);; d6 R3 Q& D7 ]6 n7 M( O* _
t = (float)wai;" X$ u5 r' v# X5 Q3 ? x2 [6 C1 C" s
temp=(t/101)*80;# M2 @* D7 O* g+ i
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);2 u9 O& O, R0 ?6 p
t = (float)cha;
+ i( Z6 U3 _5 vtemp=(t/101)*80;2 _! z" g2 Y U6 f9 f
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
! E0 T3 n3 @/ Z* T* s" V# kfor(i=0; i<3; i++) //画坐标 high=90,length=2503 I+ U. Y+ ]4 v
{
$ l" }& F: {4 r7 a$ {, ^" ]- Eline(x+100,y+110+100*i,x+350,y+110+100*i);
' `/ C* x5 ?- @; b4 K9 O7 v* uline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);. C; C% p. ^# z. r5 W! C$ w& r
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
* F/ O9 T# o* f; Y8 i* [* i+ y% ?& o) y% b1 D7 H& ^
line(x+100,y+110+100*i,x+100,y+20+100*i);' e: l9 ^& d: W+ U, ~ h+ m6 D
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);( h8 \* G1 B- `9 {2 f
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);# e8 W( t% D; q; l
for(j=0;j<num-1;j++) v5 ~0 |3 u f3 x5 Q5 }( g0 I
{- D+ m- f- e! l; S, r
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);4 [6 @& W+ _* D# ]
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);4 y# _: ~* C% N% x4 m/ V+ B+ o+ E1 M
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); , Z' d: M) _) W0 u
}. e, {( x; k) E. l/ m$ a
}" _( Q3 Y# s) Z0 P4 v4 X$ e
}# t# _0 A* v& W: T7 Q
else if(FLAG_SJF==1)& L! O! l" M4 F7 n$ R) p
{
$ q$ m. H, c+ s! G$ [, v. M: tx=0,y=0;$ t7 P# _; @, e. l& F) n- d
for(i=0; i<num; i++)
" |' Z, }7 d) i6 o{) r0 p5 Y: M( f4 p! l
t = (float)info[0]; p& @$ G2 t: y/ `! Z; s0 W& v
temp = (t/101)*180;
) A9 f" Z, T" @, ppos[0][0] = (10-num+i)*50+x+650; h# a/ ?' ~" a( I |, c9 ^
pos[0][1] = y+210-(int)temp;# a9 q: G J3 U$ `5 o
t = (float)info[1];
2 m" K/ F- U7 ^, g: y( M) A7 ?temp = (t/101)*180;
+ g3 i( F8 }9 W5 E( e; R) \1 Apos[1][0] = (10-num+i)*50+x+650;
5 n* B6 G7 [1 M. ^5 F% i5 spos[1][1] = y+420-(int)temp;
l0 ^% Y6 a' }7 Ot = (float)info[2];: @6 o$ u( A* [: j/ N5 f% `
temp = (float)(t/101)*180;0 q% T$ c* Y& ?7 t$ O6 s
pos[2][0] = (10-num+i)*50+x+650;6 G6 x: u8 N9 T i& l
pos[2][1] = y+630-(int)temp;) `% j; s# q" k* @! M! Z$ B
}! w: q; a& Y- T. m* B
clearrectangle(x,y,x+1200,y+650);
6 R- D$ g- T$ A4 Z9 D# rsettextstyle(40, 20, _T("楷体"));
& f7 M) s3 m, l- a$ [& Qouttextxy(x+50,y+50,"SJF");
- q2 ~: p. |/ ?' K5 }3 S3 @outtextxy(x+280,y+20,"CPU"); //画柱状图
A( {4 ]! w D) H Jouttextxy(x+285,y+20+200,"IO");6 Z1 s7 c4 q% A
outtextxy(x+250,y+20+400,"change");
) a5 y+ a8 |: X3 c0 e6 U6 vrectangle(x+270,y+65,x+330,y+215);
) M7 W/ T9 C H; h5 x" `rectangle(x+270,y+265,x+330,y+415);
3 m8 w2 K7 N* P% G) u' J3 {, c% Arectangle(x+270,y+465,x+330,y+615);
0 ? k4 Z, T$ x" i. E2 l7 u0 p3 Gouttextxy(x+290,y+620,"TT");. Q4 E: p* s' C2 ^* ~
t = (float)com;- [, J+ m$ L, i# C% J/ h
temp=(t/101)*150;
9 Z; f" m- w% @" [( F& Hfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
1 ~5 D+ o8 g+ F tt = (float)wai;
J# m" p6 h0 g6 m* q2 N% L2 k$ O+ Ytemp=(t/101)*150;% b6 ~0 v Y4 d5 L5 E& R
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);+ [2 K# _/ O4 `) Q
t = (float)cha;
% k9 g1 |+ v( ]* ztemp=(t/101)*150;
( ?7 {5 P: M) z0 @+ o1 rfillrectangle(x+270,y+615-(int)temp,x+330,y+615);
& W* d0 L; h+ E; W( K0 n7 zfor(i=0; i<3; i++) //画坐标 high=90,length=250
; q1 ^' M6 b+ z: j2 y4 |- A# C{
0 X$ {! j" s* _. v; P8 F+ Wline(x+650,y+210+210*i,x+1150,y+210+210*i);' \& p6 e" ~7 w. V! Q
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);5 m+ F) E) C* o$ W% S7 h, ^, i% g
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
( Y K; F$ I" E% _4 h6 K
# ]- r6 W- K7 @- Y; vline(x+650,y+210+210*i,x+650,y+20+210*i);
8 q% U2 D' }% H, `5 b# A$ ~line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);) s! C @2 {: R& L. t
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
! d. y- [1 W# E5 ifor(j=0;j<num-1;j++)5 p+ {' ]& i. q/ j0 B# J) ^
{
" e1 Z/ s/ [# Zline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
- [: W! N6 O% o9 z# S5 @line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
$ p8 p2 e9 T2 c, N+ z% {' Mline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ' {" ~5 B3 i; e \% Y! ~; F H
}5 N) n- b; b! J
}- d' t" r/ e; ]1 m$ q: ~
}" j5 L: V, i$ J2 l' g& `
return 0;
: J, x9 K8 S/ P. o" {4 R}
\2 C' S: Z" h0 l0 v) A! J* Nint High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)/ @0 v' U. _7 V" Q7 v7 V8 G
{
+ o/ m y8 ? [" g5 @6 kstatic int compute=0,waitio=0,change=0;5 Q" Y, m1 v9 ?# Q+ |5 s0 h5 `3 r* `' W
static int computeLast=0,waitioLast=0,changeLast=0;" s7 l9 g' o1 l6 P6 B+ L- v. ]' H
int i=0;
p% G* c9 M! c Zif(draw==1)4 r2 J ?6 [! B+ c8 k( Z2 y
{
0 p/ E0 S$ p7 j! t i//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
# G: f5 p* G' D A9 qdrawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
/ M! e9 X$ J8 h5 F. P" bcomputeLast=compute;
) k, e$ z# a# _: U, VwaitioLast=waitio;; m% F5 W: r! x: w% y7 {
changeLast=change;
( h, g. a$ w' Y4 O}
5 M0 j Q7 @- N; x+ U; E# nif((* memory).p[0].flag==ready)$ B/ P$ z; g i8 e# D$ a: F
(* memory).p[0].flag=computing;
& W$ V% c; j0 p/ q) _, zif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing); ^) n; P, J! V' Q' J( k
{
% E! n1 S0 `, J0 C/ c! a2 W! ]1 di=(*memory).p[0].computeNum;
/ r4 `# v2 r) J1 q# pif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
% N+ e: B; O# v{
( j) z& n- a& m6 _# M0 f6 g(*memory).p[0].flag=IO_waiting;
$ X1 d* s) }% h g) v- K3 u) \(*memory).p[0].computeNum--;" p# C% [: |) v/ o0 B4 ^0 |
change += exchange_IO_Compute;* v, g8 j) Q% @6 W
compute++;+ K1 ^" N) O6 F' D6 U+ [
}
( `2 |, k) Z/ X3 A1 nelse
1 b& _" l8 n) k9 N; T! M{+ F' D( V1 ~; K' T1 n
compute++;9 ^* W p! [3 @, ]
}
1 c1 ?' n6 S' z2 ?# ~; I}
6 ^& |8 I$ o5 ~' b, pelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
7 y' q+ Y' ^" }" _" M7 _& h( `2 P{
9 Z7 l- d6 Y% |4 \2 c
6 q+ m# k) I0 ri=(*memory).p[0].ioNum;# K! E& F( k! l( I! h+ r/ Y7 c
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed2 a9 e# m& v* {3 g" y
{
' {$ e7 F) z( `6 q, m4 {( S(*memory).p[0].flag=computing;% q% ]3 f9 o. A# _7 r v, I
(*memory).p[0].ioNum--;
5 a; r: f/ k! N! mchange += exchange_IO_Compute;
- w2 S+ u/ i. ]! m; w- Y+ lwaitio++;
, M9 K2 M0 D2 l* f, Y7 X% c}
# p& _# D% t8 Q& L3 R- relse
- f+ c& m# e9 a s; Y# z{ f) i' ~: z7 p8 D: J- p& X/ L* Q/ K
waitio++;5 Z' A: Y) T# _& @7 s
}- W4 S- F) J0 ~/ `) ]* _( k( U; M% _
}
* A, L8 C) i2 |) z( E* |else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)* H5 }" r4 ~0 k- t
{. p- m+ h& T6 l4 o) J
(* memory).p[0].flag=IO_waiting;
1 v6 p, I- c) F, C3 ]# `+ L! Dchange += exchange_IO_Compute;) B. O; A, d. ~. @4 b1 y6 e3 ]: |! W
}
/ ]2 E: P# d# Q ~3 Zelse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
8 u1 M9 n% }: J; B2 C; D q9 C$ E{# g. p9 L; _+ C# B: [& G2 F
(* memory).p[0].flag=computing;
% l$ [$ J+ i) U; r, Z* r% rchange += exchange_IO_Compute;0 R' T$ ?5 ^" ~% l
}
+ n/ z6 {' ~5 R/ N, wif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
, ]9 W" o7 l7 ]; v4 T/ e( T( U- e{: ~2 U0 U; n* o7 U" C
(*save) = (PCI*)malloc(sizeof(PCI));& k# X9 B8 C# ~. }6 L. E. v c' I# P
(*save)->next = NULL;
5 |( s7 U( |2 C$ k3 T0 @(*save)->processID = (*memory).p[0].processID;# D8 Z, j( U6 v8 a7 F2 A: ]
(*save)->comeingTime = (*memory).p[0].produceTime;6 i* l$ Q- K8 u0 I6 ^. H
(*save)->askMemory = (*memory).p[0].askMemory;5 E: ~3 [* b3 ?( _! ~
(*save)->compute = compute;5 Q; z( k6 X' y; e$ y' I) J' l* [$ X3 ~
(*save)->waitio = waitio;- i6 R0 y7 {/ E9 \; _1 b/ U
(*save)->exchange = change;
1 a, v1 F/ I' G7 t1 M(*save)->completedTime = systemClock;4 b% P& {2 R# m7 w9 B
(*save)->runningTime = (*memory).p[0].runningTime; ~$ E+ S( r9 d' j4 U1 w% C
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;/ d) @ Z7 g" J2 B6 Z
compute=waitio=change=0;
0 {/ H8 [" L2 pcomputeLast=waitioLast=changeLast=0;" y* E: w1 z6 y/ h8 B+ E2 |1 U
High_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);6 T% U. ?& A G! m
change += exchange_process;
. k1 d3 r5 Q; F0 vreturn task_completed;
, W4 _/ L/ q5 r: C; x4 u3 g}
], p# S% }0 X# h4 velse5 V+ M/ ^& |% p% [
return task_not_completed;
6 y- L4 g% ~3 H9 Y" j}
6 l+ B5 S) ]4 y, oint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)
$ X0 t7 R) `* e" o{- q1 @4 ]# z; e- k0 K7 C
static int waitTime[initProcessNum],i=0,j=0;
9 N) |* Q" L% a' `: Tstatic double HR_ratio[initProcessNum];" d p; g) C! Z& A" w2 d
if(flag==0) //初始化数组
6 B* B2 O4 m1 ~1 y{& v; ]" h7 E+ f1 [( C6 R8 h* |& x
for(i=0; i<initProcessNum; i++)
; H0 f4 b* p. q, K0 b- h' Z{
8 J% {$ h$ y* s' Z% g% b0 @waitTime=0;
# e) G$ l/ s2 Q- n5 U/ DHR_ratio=1;0 g: F2 @/ N5 X- l" P/ I H
}2 p t5 L) H5 \& H& F \
}
7 H3 A' Q8 S2 E2 ]+ i8 `for(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比" X) p0 }9 A) y0 S+ x% x, f
{$ H; ~3 l/ J5 c1 ]; O+ a- M
waitTime++;
, X' m. p" p/ H9 W pHR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);
& q( r1 E8 x+ ~4 w! I4 G5 nif(HR_ratio > HR_ratio[j])8 ?& g% X# b- v8 \* x0 X
j = i;' o+ H: j7 t3 P( V
}9 z x) z9 O* P
if(dispatch==1) //需要调度一个进程到内存中执行
6 j, g8 L& R+ @# {& \{1 y0 `& @' @# [1 L8 I% U6 I
if((*storage).p[j].askMemory < *spareMemory)2 Q* x6 Y; h" f- }; f* [
{* |* L3 j0 Z3 ^# N& N
(*memory).p[0].askMemory = (*storage).p[j].askMemory;
+ P, C- W+ ?6 p(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;+ ?: o( i1 F& t2 F4 j% ^9 v( K
(*memory).p[0].computeNum = (*storage).p[j].computeNum;
, U+ y3 \. l, x7 @(*memory).p[0].ioNum = (*storage).p[j].ioNum;, l& x* _, M# a
(*memory).p[0].processID = (*storage).p[j].processID;. x, n7 D: r2 K9 u
(*memory).p[0].flag = (*storage).p[j].flag;
. W0 W9 N+ ^% _6 q(*memory).p[0].ioTime = (*storage).p[j].ioTime;
* m6 A. @8 ?$ t5 t(*memory).p[0].computeTime = (*storage).p[j].computeTime;
& a- u- l- _" o! T(*memory).p[0].runningTime = systemClock;
7 p& J* R' i6 A(*memory).p[0].produceTime = (*storage).p[j].produceTime;
{0 D2 U4 {# C3 G5 P: |for(i=0; i<(*memory).p[0].ioNum; i++), C5 R \% x2 |5 u8 N, C
(*memory).p[0].ioClock = (*storage).p[j].ioClock;; j) m) y* |: o2 n$ B' I
for(i=0; i<(*memory).p[0].computeNum; i++)
# j9 r9 f) ~3 V(*memory).p[0].computeClock = (*storage).p[j].computeClock;$ c2 ~/ R7 O3 v
(*memory).proNum=1;; H7 E+ W. m# i/ S" {
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
; {& y* T. ~% K4 _) fproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程9 e& z' r* P; Z8 b/ i, \ g
(*storage).p[j].produceTime = systemClock;9 s1 u; N5 ~4 O; p' J' K
MAX_COMING_TIME = (*storage).p[j].comeingTime;
5 ?% K" S0 Y, |* Q, `& ^waitTime[j] = 0;5 x, F0 I% E& b1 m/ n0 x1 W1 N" ?
HR_ratio[j] = 1;
9 y O6 x" v2 Q# h2 ?* E5 H, ~}# m' w7 F) a0 f$ J
else$ X# V' l8 O, `# P7 _. `
{1 p; ^; R& ?2 M' H6 s0 X! o# {
printf("A process ask for a memory overed the system capacity\n ");8 x7 P9 s9 i# }9 h1 Q Z
exit(1);. A0 v; ?& [4 q4 U
}) H; r7 T* }; d9 w8 Y
}' ^( p5 ^5 ` Q5 y* m" ?! i2 A+ s
return 0;
" K H+ i: E5 t- v}
4 e+ R* G- F' b+ z4 o: yint PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
: Z+ g. W, p% S `; `7 m{
$ ~/ M5 S1 \6 s F& \" Bstatic int compute=0,waitio=0,change=0;
, F8 B$ a( [$ \8 Jstatic int computeLast=0,waitioLast=0,changeLast=0;
; v! r* T7 L3 x6 s# T2 v% E" e$ V z. J5 vint i=0;
7 o' `2 c3 L, w+ Mif(draw==1)$ E% C- K& m& W" v8 p- I, g
{ U+ x3 x! `) C. S6 v, k
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);: B+ w3 y, ?" s* k* D
drawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);+ O5 [5 s, i8 I
$ c" p: F' ~% h! E- a
! I. C# u: b( o7 S: fcomputeLast=compute;
s! e, W& A% |* C' a, bwaitioLast=waitio;3 _' B1 W' E' ~ h$ T
changeLast=change;8 H* {2 N* R6 H
}
- U) w9 i0 u b$ w. Oif((* memory).p[0].flag==ready)* z: I; M2 C6 e
(* memory).p[0].flag=computing;! B# x) J, R& }% p! Q$ Q
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)2 S, d$ D1 [5 `8 _. y0 {( h* y
{ l r- v& e" f
i=(*memory).p[0].computeNum;9 j, W K0 ~- K1 O, F* S! D
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed7 f0 n* V+ e% n, U
{+ V7 |' v9 a" N( H M2 ~
(*memory).p[0].flag=IO_waiting;$ h1 X# l8 o+ x9 Y( E5 l
(*memory).p[0].computeNum--;
( w7 D, C- z* wchange += exchange_IO_Compute;
: b- p2 I9 B p, [6 Ecompute++; D# C2 F* X1 h2 N/ l4 f
}5 A. k$ _/ ?! ^+ r4 w5 J5 E1 B
else; u6 |7 ]. U' y' g9 V+ U. k
{
9 B K- Z# F) n* d/ j s0 m' _- Lcompute++;
% o9 j4 B# x- C}1 |, A7 o- J: M6 G
}
, y5 L1 g$ G0 G! P8 r' ielse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
4 S E. r. ^" _9 A. B) V/ t: _{( R/ A; r k) o6 b
$ M( a4 T/ K( H1 M9 y. H
i=(*memory).p[0].ioNum;
; |7 n; }& ~9 _% I# } c2 Fif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed4 h' V6 s. l- p% v1 A; b3 a6 g
{
" e5 F, t" A* S* W6 l- _(*memory).p[0].flag=computing;
6 ^; F- w% b2 {, S8 ?(*memory).p[0].ioNum--;
, c4 W3 _: ~5 u0 k ^; H# Jchange += exchange_IO_Compute;+ O8 x% V( [# Q& \ ^$ d, m S! ?
waitio++;
- q, e2 ~0 Q6 A+ y* \" l) H- ^7 ?}. U: c1 {3 F4 X L
else
0 F3 w/ h. r0 c# r{
. W$ W. V _2 F1 Q9 F5 M. w" pwaitio++;2 o q5 L+ g; ] S6 m6 g# N- B
}) A: e8 ~( P \0 B
}$ O3 o- T5 o8 u4 e$ @, a
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)) O9 }8 y% j6 J: ]
{
$ J- B0 ?! k# A' a2 {(* memory).p[0].flag=IO_waiting;3 X7 J1 o1 _( ~& W: Y- e
change += exchange_IO_Compute;
) R2 o8 |& T5 U8 K% x) Y6 q# l$ ~: }}: G0 X: _7 A/ h1 H; n. T- b) w
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)$ L( \" b) E0 R3 u
{
% t/ ?2 G, q- k( w& ]1 |3 P) d(* memory).p[0].flag=computing;; O0 J: y$ u' C0 P7 P4 A) ?. V& E
change += exchange_IO_Compute;
& i# c! h6 b+ s4 g}
; d ?1 y' e3 C L) {. iif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成2 q! m& b1 e' ]. I
{
0 {8 ]5 ]2 E2 c" r% a( P(*save) = (PCI*)malloc(sizeof(PCI));4 C7 W5 ^9 X& U6 S y8 X/ F/ l; |
(*save)->next = NULL;
+ V! G5 S+ A0 A8 Q(*save)->processID = (*memory).p[0].processID;) B! Z5 Q& { V! |4 k E! K2 K
(*save)->comeingTime = (*memory).p[0].produceTime;
1 @" c% w8 }3 d5 P* ^7 B(*save)->askMemory = (*memory).p[0].askMemory;
' t* x" S6 ]: y$ o" A4 U7 C. Z(*save)->compute = compute;3 A8 t5 T1 e( u
(*save)->waitio = waitio;
; J5 h m0 P8 O8 D(*save)->exchange = change;
; s" {/ O4 \: I0 g(*save)->completedTime = systemClock;- A7 V: n# t/ J, ~, X1 i+ C4 Q
(*save)->runningTime = (*memory).p[0].runningTime;. r/ R- `# @& h |4 Q0 j
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;4 w' o) ]5 Q, }- V9 |. ~1 { b
compute=waitio=change=0;# o6 @1 @8 j2 w
computeLast=waitioLast=changeLast=0;
" s( q6 o$ a$ d; lPriority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
3 Y# X2 [5 M3 m- achange += exchange_process;
" ?6 S9 F, Q; n1 e5 D; Z, P, freturn task_completed;
6 Q( s D* t/ T. Z9 g$ |}. c( q0 {7 Z0 a4 ~
else
3 K) Z' y9 o6 Wreturn task_not_completed;5 v2 T7 c3 X% M+ s9 s4 [" ^
}0 d* {6 D2 o) H! Z4 O0 |
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)1 M2 o* ^* i) a8 s
{
4 j; C2 n; K3 T0 W' O* n, c4 f `int priorityNum[initProcessNum],i=0,j=0;
! G" J7 y$ J( r% M! `9 |$ O" Qdouble temp=0;4 m4 J4 I' q( W" G7 _; ^
for(i=0; i<(*storage).proNum; i++) // setting priority to each process
# L$ W6 Q4 n. O. Z{8 |. i5 p9 q7 ?
temp = (*storage).p.computeTime/(*storage).p.ioTime;* x4 g5 T. J' C6 k' ?! A
if(temp > 0.8)7 E* O1 A _- S% |$ E
priorityNum = 6;
4 p' E# X# n; H1 [7 E6 ^! `* g Welse if(temp > 0.7)5 W" p& {4 `, M1 ^
priorityNum = 5;1 K' I6 a0 q. }
else if(temp > 0.6)
; j% E; u' ?' D9 G9 D5 n1 C0 x" Z% FpriorityNum = 4;; @' r! n! l3 @6 Z
else if(temp > 0.5)
# s" L6 l5 h2 G( r# N7 A, G5 {! I9 }priorityNum = 3;
; a, F* Q" x8 a) L3 M, y9 oelse if(temp > 0.4)
0 g" d5 O# w7 Z) FpriorityNum = 2;
& Z% [9 I z% P7 w1 [& G' Oelse
. N: @6 N8 V! b( @8 W/ k% WpriorityNum = 1;
- B" I" ]4 s2 h) ?if(priorityNum[j] < priorityNum)
* r# K6 \( U$ T% w* ?* qj = i;
5 p6 ]! z' t& T) u$ {! p: H4 a}
$ V, a7 h3 ~# O% y8 Y+ Gif((*storage).p[j].askMemory < *spareMemory)
/ ?6 y+ u1 g& T( z$ y: b9 m& y4 h& V{* }2 S0 R5 @* n: P8 W
(*memory).p[0].askMemory = (*storage).p[j].askMemory;
; l' ^, ?* i) U, s, {* ^(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
9 n6 |# I/ D% f(*memory).p[0].computeNum = (*storage).p[j].computeNum;: F0 S; | @% M, e9 l' ^5 \
(*memory).p[0].ioNum = (*storage).p[j].ioNum;
$ }; {) s+ i/ G& D4 B/ ?; f. s(*memory).p[0].processID = (*storage).p[j].processID;
, r4 R8 h9 A# M) n(*memory).p[0].flag = (*storage).p[j].flag;
8 X. m5 v9 B. `% }6 D5 S(*memory).p[0].ioTime = (*storage).p[j].ioTime;4 P. x! w$ W( y+ b& i V
(*memory).p[0].computeTime = (*storage).p[j].computeTime;0 _0 V* a8 t$ N% R$ `# R" H9 o( _
(*memory).p[0].runningTime = systemClock;
5 X& X c6 ^* W# \) B1 H c1 P/ B4 p(*memory).p[0].produceTime = (*storage).p[j].produceTime;
9 B. r) }- y2 o6 i* Y0 Pfor(i=0; i<(*memory).p[0].ioNum; i++)( `5 H6 C D1 V5 f+ ]3 v2 R
(*memory).p[0].ioClock = (*storage).p[j].ioClock;% w4 Z) h* s% \0 y
for(i=0; i<(*memory).p[0].computeNum; i++)9 e2 f3 Y; z; x
(*memory).p[0].computeClock = (*storage).p[j].computeClock;* w- t: K2 z7 t" `. U6 {
(*memory).proNum=1;
! |+ b- T1 k& I- K2 G9 w; G L*spareMemory = *spareMemory - (*memory).p[j].askMemory;
8 S$ ?2 d7 }; ~" O0 T. F6 H# ~' Eproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程" M, K% k. G" @! u j
MAX_COMING_TIME = (*storage).p[j].comeingTime;3 C' T6 K: n+ K
}
2 J; x x7 ^7 j4 u- s- S& V8 belse
( \* }+ ^! `& r- T. a{
. h: T3 s' k' h \& `printf("A process ask for a memory overed the system capacity\n ");
+ ^ e$ D+ z6 {. uexit(1);# g. \' s$ r- H& O
}( ]1 h5 @, C7 `
return 0;
$ w/ ]# T. @$ |% y7 o3 g# i. Y( n}3 n7 D/ c) j3 f
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)8 d' L$ X( _4 f3 [
{8 [3 d& d+ @4 s* D9 k
static int compute=0,waitio=0,change=0;
3 A! d. j1 t) `1 Q. u* c, H1 tstatic int computeLast=0,waitioLast=0,changeLast=0;8 f' H* U" v* Z2 P* j
int i=0;
2 {; V8 o" p2 h8 w* B- S6 |if(draw==1)
) {. M, J5 d. l{0 M! }7 A* g! d% R; f/ I4 I
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
5 x( D# o( G+ W, b9 ddrawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
* I3 x% J& |3 j, E* m4 ^# H0 g+ Q( ^) I6 p o5 ?8 v2 w( r9 s
0 q# @0 D7 T& E- N& X* |+ jcomputeLast=compute;0 D+ o7 u& Q& |/ j2 g& n( ^
waitioLast=waitio; H1 x6 }1 D7 O& P: ]
changeLast=change;
; E+ `2 C# m7 _4 V: r: L}
[+ o. Q- i* V6 p+ V* q3 Zif((* memory).p[0].flag==ready)
* R Y( D l5 {9 r, o& v$ A* Q; F: Z(* memory).p[0].flag=computing;3 W; T& |% R# R# p _. c1 P% T3 K
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
; U9 f5 I& J. `2 O& D, l{
! M! c: N, q m* U) x! Fi=(*memory).p[0].computeNum;
" Y6 z2 @- m. i5 Rif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed" M# @4 y4 U# e( G' \2 W( @% c: t
{5 ]' Y# P% P" _! S' M
(*memory).p[0].flag=IO_waiting;" ]$ @, ^% J/ l4 P0 Z
(*memory).p[0].computeNum--;
6 |" N+ M h+ e% `# J5 ]+ I0 ?9 Rchange += exchange_IO_Compute;
) H! ~4 y! @3 {) W3 D. @2 Bcompute++;4 A4 _" c$ T3 e/ _3 |: V
}9 o {8 g" ?3 E( i
else
8 t: V, Z( H! ?. p{1 Z* W: [3 `" f8 U% Y; s$ @
compute++; c- h, H$ a& U
}
9 j6 @7 C8 m8 L% L. C* n}
* C4 b( [0 q; t; U: b- D, Helse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
$ q* t+ } r9 f4 B! w, ?7 O2 a5 p{9 v a5 e, l, I0 \. A
5 r) E1 Y! U$ O% F- q, t
i=(*memory).p[0].ioNum;: J- i2 q7 o$ P/ T, k5 d7 h
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
8 [- ~$ V o4 K+ l4 E' k3 a{( R4 ?( ^+ M& W q4 _
(*memory).p[0].flag=computing;+ Z* _* J, W0 D2 N% c* o
(*memory).p[0].ioNum--;& \9 |5 U1 l/ H# D# U& @
change += exchange_IO_Compute;
) h% J( v0 |- Iwaitio++;+ K; ~; y' O0 @4 @$ D
}
/ ~8 C& Y$ a- c, o. f8 @6 t- g2 B. r2 eelse
6 N9 z* k8 I2 I1 ^( R% |( G0 D, A{; O9 Z& j1 s$ b* V
waitio++;& |$ i+ \7 N1 t6 l, n8 D# c
}/ S: s3 D0 }7 |+ {+ J: j3 ]: K% d
}* p- f9 c8 k2 H: ^
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
# |4 H& w* f2 R! n/ X3 ~{
4 ^; F% |. o3 l- p(* memory).p[0].flag=IO_waiting;
# m, H3 `3 l$ F. w/ kchange += exchange_IO_Compute;( a8 e6 W4 |# k$ H$ I, Q
}9 P' W# |6 |$ k% |& F, M' Y
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)- p2 S% j' u$ y* `3 R- @4 o
{
# o5 Q7 V, h0 H% C3 e(* memory).p[0].flag=computing;, r/ R- U- L9 W8 {
change += exchange_IO_Compute;5 J! s! B8 M& y- R. C) C4 Y( N# ]% R
}: m+ \; y5 c% H" v ~
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成" A/ M/ m; | L9 Y) c8 R5 \9 A
{0 o2 u. ?. }9 R8 g) x7 y
(*save) = (PCI*)malloc(sizeof(PCI));
2 ~! x2 h$ N% `5 u9 m( p8 `(*save)->next = NULL;
6 k6 D3 `4 o% t2 L9 G4 F; J* m(*save)->processID = (*memory).p[0].processID;$ Q: H6 y1 a$ M+ q6 [
(*save)->comeingTime = (*memory).p[0].produceTime;
; V) h2 v$ U4 W(*save)->askMemory = (*memory).p[0].askMemory;( k# Q3 s; Z: j& x8 E7 W1 B
(*save)->compute = compute;
( ?. W) N4 u1 X. Y3 O4 w% M(*save)->waitio = waitio;+ F' ?4 t, B6 J. f6 |4 ~; m
(*save)->exchange = change;
j" m" W% J+ P5 A" r) C( }) k* ]0 R(*save)->completedTime = systemClock;
n4 z# X. R( u' W( H(*save)->runningTime = (*memory).p[0].runningTime;5 T4 l/ c5 v! q' Z0 f
*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;
; p8 N$ E/ V \; z6 X# l% x2 k8 @compute=waitio=change=0;
' c, U$ a H' \computeLast=waitioLast=changeLast=0;
. M1 g0 Q' R% i1 d& BSJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
8 U& B5 `% m0 ], q4 M& [change += exchange_process;
4 r1 o, j; G) g6 D4 areturn task_completed;+ J0 T( ^7 l& X# w+ |" D/ L
}4 r+ f" C8 ?, `4 J0 F2 K
else
0 U, z+ ^0 ^; b% ^) Xreturn task_not_completed;6 ^6 J$ z* \" p& K! ?
}
) y. K# A$ o$ e0 o+ {int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
$ i% K& m4 }' a9 [( l; i{, ^* X7 j$ u( @: m5 R) V+ x
int i=0,j=0;
- P/ V. `2 p3 V" ]- Jfor(i=1; i<(*storage).proNum; i++) j0 K0 j; x/ W2 Z n8 G
{
: U* D% ~" C, Qif(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))
* d3 e( ~. @" I2 Sj=i;
, G: \: O/ K+ u$ g3 u& `+ P& M}) T/ w5 C( R- c* z& G. V
if((*storage).p[j].askMemory > *spareMemory)
2 u1 Y, K/ w* G2 U: \{, i' ]. D$ u" v+ e8 c, E: r" ?
printf("The memory asked is overflowed than the system memory.\n");: @; y. i# I8 j. t
exit(0);3 i* ~1 _! i! R& f3 J' P2 |( k
}
5 C/ Q/ G( e! B& ?" g8 f3 j' Kelse8 K& ~- R3 {* A1 A: k) `7 T# l
{, G H# ~, ]: l% c H- | a
(*memory).p[0].askMemory = (*storage).p[j].askMemory;6 }6 j7 q+ U6 K
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;3 K# l1 {" q+ w0 h& D
(*memory).p[0].computeNum = (*storage).p[j].computeNum;
( ~( y a& s6 f9 f1 q& Y( {(*memory).p[0].ioNum = (*storage).p[j].ioNum;
+ M! R" E0 a- V: R0 R(*memory).p[0].processID = (*storage).p[j].processID;! E+ E A4 R5 ]( t
(*memory).p[0].flag = (*storage).p[j].flag;# k; ]# {/ F0 D
(*memory).p[0].ioTime = (*storage).p[j].ioTime;' F6 n: F) C! c# l( j
(*memory).p[0].computeTime = (*storage).p[j].computeTime;
& Y9 R: a2 `9 {. t6 f2 ]. {(*memory).p[0].runningTime = systemClock;
* Q8 B2 G4 Q: i4 Z* c7 [# A7 c2 i(*memory).p[0].produceTime = (*storage).p[j].produceTime;
& v2 H6 \, Q& G7 C4 d! Gfor(i=0; i<(*memory).p[0].ioNum; i++)
" [9 j0 l! m; E(*memory).p[0].ioClock = (*storage).p[j].ioClock;# p- O: ]6 k: ]3 m( a5 _
for(i=0; i<(*memory).p[0].computeNum; i++)- {/ w/ U5 n a' @2 m/ M# `
(*memory).p[0].computeClock = (*storage).p[j].computeClock;$ \ ^' p; [& x% W+ Z! z- |# Q
(*memory).proNum=1;# k0 |( s1 T: [/ Q
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
" ]3 k& h) `. B+ bproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程6 \7 w1 j* o& e8 f1 I
MAX_COMING_TIME = (*storage).p[j].comeingTime;
) s" L; l, z f/ g% i1 `# I}! ^2 {: S( j3 Q2 O3 E- q" O8 w4 z1 u
return 0;) B3 }" I4 }* w" X3 W* o$ m6 j) G
}
9 B( ]( `9 P6 C9 L2 i: Hint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
8 W+ }7 {' T: t m& p{
. \' U$ D1 Z7 F1 ]; H, R0 Wstatic int compute=0,waitio=0,change=0,clockSegment=100,poi=0;# e, x) n2 k1 q& r
static int computeLast=0,waitioLast=0,changeLast=0;
3 |$ }. j0 O8 P1 s7 _6 R7 _. eint i=0,j=0,k=0;
. o+ w& l5 ~" n4 d! P0 Xif((*memory).proNum<=0)
4 u N* V! m2 C3 G. `+ p; TTimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);- x2 t' P* Q$ _* S! V' j. c w
if(draw==1)
, x6 C- C+ l- [, x) F% e x) F$ g{ k H9 ~% _% ~) f1 |
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);; V4 J! M, L w1 J: ~8 ~5 ?: P
drawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);: D/ l' \; ?' E) n
7 r1 `6 l" U5 ^( W( u# Z% A
# n8 B" G5 |, n; ScomputeLast=compute; G6 o: L9 q5 r& t. j! [! F: @/ `
waitioLast=waitio;
7 u9 f' z/ f5 l! a: ychangeLast=change;" P3 G9 }$ d; B
}
# e; S2 ]$ u3 @: Hif(poi>=(* memory).proNum)3 T: x# z: h: A0 a2 {- E
poi = 0;' K5 D5 X% Q2 N0 {2 X4 J7 l, Q
if((* memory).p[poi].flag==ready)
/ d1 m5 Y+ z9 b6 A7 B) _(* memory).p[poi].flag=computing;' u# A) E# X# e+ \% o( l$ ?3 [
if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)# J$ m" i0 D" P9 I0 i1 `- e
{
4 |$ d5 ?- z7 }" H1 oi=(*memory).p[poi].computeNum;
4 q; o$ D7 n& N- t# k9 Hif(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed6 m1 `: c0 m' L# e- h2 X
{
5 o) P$ M' o: q- y4 m0 z" F/ C z: g(*memory).p[poi].flag=IO_waiting;
6 {( V$ ?3 w4 l: M& P% l' @5 C(*memory).p[poi].computeNum--;
# L, M3 L) }7 D( K/ Tchange += exchange_IO_Compute;
Z( I9 T6 j/ S# W, icompute++;- Z6 R! L, B/ f) h
}4 D0 L7 z7 y; R6 x$ T/ ?( W" b
else
# }5 w8 ?! L* k/ L) c$ G1 w/ Q{ j3 J- h$ o3 d( Z& o
compute++;. ]1 H, F* P. }9 l& `
}9 Q6 S( ~/ L, c* b
}- D8 l$ N% T1 K0 O# E8 z& C$ @
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)' [- m% i. w: l( K- C% m7 M7 i
{
# Y B9 T" q! k' [9 j
' C! N8 s: u( ^$ L. `i=(*memory).p[poi].ioNum;
: p0 [; Y; H( n& ?' }+ Sif(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
8 f8 P3 O$ K$ P{' H4 j& O |) E: p
(*memory).p[poi].flag=computing;
0 h2 n% |8 N9 u; k7 p/ |, n(*memory).p[poi].ioNum--;$ Q0 [7 T; T- F' e1 D9 L9 n
change += exchange_IO_Compute;
" X" E7 j! Y9 @, H. }waitio++;
" d9 j$ w: S" B6 I}
$ {* e- V ?: melse
/ O8 q/ U0 n( ~ P5 b{4 b% ~" n( [7 f
waitio++;
. J2 Q4 h6 }6 j& \5 l, o}+ e# F+ X' H/ N# w
}( G+ j8 s0 u- l
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing)+ L0 U# H, U, {7 G8 z, S
{ O! T6 i: J" h1 L
(* memory).p[poi].flag=IO_waiting;) W4 ^; t/ T. n" a+ @/ j9 f7 I
change += exchange_IO_Compute;
# f$ N6 U! [, |- N; c}
3 v; n) ^4 t" velse if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)
P7 k0 h7 V* I1 q{
! x) e& |1 O) o8 E6 P(* memory).p[poi].flag=computing;
+ @# e/ G- ]+ f& s8 M/ \change += exchange_IO_Compute;$ u& u& f0 _4 H% i! e! G
}
7 e; ]1 g% f3 [: @- ]0 ?6 }for(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进+ N R$ I% _4 @& ^: j7 [- E
{: _! l" e- A5 v2 N3 C+ i% a
if(i!=poi && (*memory).p.flag==IO_waiting)
% x+ F$ r8 Y. G/ V9 Z$ r4 K7 X{' {" Z, L3 S# z, X8 P! n
j=(*memory).p.ioNum;
+ o# y- `: @9 x& ]+ nif(j>0)! h, \+ V# H1 u
{
! r( [- k( b( sif(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed# E& B, F- U2 I2 h9 n
{
6 L, C% Q! t- N2 G- u(*memory).p.flag=computing;8 [8 R7 S, E' `& W# } ~
(*memory).p.ioNum--;1 r, H K( o+ o$ H; R' x" Z1 I: H/ T# |
change += exchange_IO_Compute;! N: v- c" R7 s) i9 A
}- d; F4 Q2 {2 h. M/ ], k. C
}. F9 [" O& R! I3 ^
}* e4 _6 |4 z4 [" Q
}% h! O- z9 i. ^
for(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程
) `7 e6 P; y, _' W O m{/ |5 H( ]% q2 f( C% | s V
if((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed
5 b" x* M* ?8 y1 ~{! c: S% L: [( M8 ^7 ~4 E& d
(*save) = (PCI*)malloc(sizeof(PCI));
+ W7 O, i- ^ Q+ g0 u7 E6 O- g(*save)->next = NULL;
2 @3 R3 l! V" Y3 D4 o (*save)->processID = (*memory).p.processID;
' j( B# C. x4 k* H V(*save)->comeingTime = (*memory).p.produceTime;, w* k' d: C" Y, U. O. I5 d1 Y' I% ?
(*save)->askMemory = (*memory).p.askMemory;9 n: Y+ b6 m1 O5 W8 N% N
(*save)->compute = compute;4 o5 }5 a0 I0 r) z% p4 C, I) ?
(*save)->waitio = waitio;/ _8 E, E: i% E. m. a2 j D; r
(*save)->exchange = change;
1 b3 a" u0 e# C- E a/ }# z(*save)->completedTime = systemClock-(*save)->comeingTime;; H9 V) s9 T+ V4 ?$ k6 i# M% i
(*save)->runningTime = (*memory).p.runningTime;
+ s0 p* z$ |- N2 D. y4 Y1 ~9 l(*save)->completedTime = systemClock;
. q5 Z! A+ y3 U" [- |- ^/ k; r8 C*spareMemory = *spareMemory + (*memory).p.askMemory;! M1 b6 \5 G% Y2 l! X7 \3 h1 L
compute=waitio=change=0;6 k& i0 O* n' P; |2 Y& E
computeLast=waitioLast=changeLast=0;
- J- P! }2 }8 r, jif(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入) ^! g1 J- ^9 h& M7 E3 T, a
{
( e6 v7 q4 g* F5 Nif(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程
" t0 o' r& j4 u6 W, a{
1 c% p2 j) ^, f7 X8 V( apoi++;
, n9 V, [+ Z0 S1 x clockSegment=2000;1 g/ e9 ~! o* y. |5 e1 D
}
6 c g/ c5 R5 N! h}
3 G% O- U' s4 k/ y* xelse //没有足够内存调入新进程# x6 |; o) c7 q0 v; u) t! o# P
{
$ r/ |) C4 c; l. ?# {; ]if(i < (*memory).proNum-1)1 J- e6 l# E) e! M6 o$ U( Q# z
{$ ]* \$ v5 ~0 z+ f/ O5 {# ]# x/ t
for(j=i; j+1<(*memory).proNum; j++)
9 U0 S) `7 b1 @9 { r8 n- y{
. n& Q9 Z+ W7 e7 K(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;' }' i& w" }4 O* G0 A8 `$ K' c
(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;
. M0 z O9 j. M3 ~5 q( u) l+ Z3 V(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;0 S* h; ]' n) c( `# H* M' `2 x. R
(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;
9 b/ s: K+ b; S(*memory).p[j].processID = (*memory).p[j+1].processID;$ C$ |; ]1 w M
(*memory).p[j].flag = (*memory).p[j+1].flag;
4 i. [( S- P3 m(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;$ ~- C5 K w4 L J! D
(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;
2 I3 m1 U; C. I* J0 f6 ]! v) |/ C(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;
2 M1 Y7 |9 p5 G9 w5 k- i4 ~; K(*memory).p[j].produceTime = (*memory).p[j+1].produceTime; ~7 |) j( V& J/ F; V2 T$ ~$ c% o
(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;9 y; r+ X1 v' z1 A- j
for(k=0; k<(*memory).p[j].computeNum; k++)
& A* m6 |2 @" A: U5 z* V(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];: T8 f7 v5 S4 j
for(k=0; k<(*memory).p[j].ioNum; k++)
! j) q8 V% m2 P0 B(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];
Z, i2 y3 R( ?! [( r1 x}
6 N0 d9 h( n5 C Mif(i<poi)
( z$ Y U. P( Epoi--;
7 F6 z+ r8 n" R0 B, Xelse if(i==poi)4 z+ y0 \. D1 c( ]
clockSegment=2000;
: D% C: m, M- ^3 h1 q9 r; G}* E! O$ Q0 H; b' D" P% {0 `3 q9 T
i--;5 [# F* Y/ Y8 X6 _8 C _$ S: r" S
(*memory).proNum--;: v2 r I3 i/ L$ m- a
}7 E- f) A2 ]# P; ]+ x; Q
return task_completed;
1 _6 g2 }; \4 ^) ^}
! p- Z) s1 h( R! N}7 X& \) ~; g7 C
--clockSegment;
) \8 s& g3 ]6 R5 k3 iif(clockSegment<=0)
5 l7 e0 k. k% ?* c! J8 v" r c& [{
' e% K: m0 N* {* {3 D, }poi=poi+1;! x9 W3 |. }! y. b$ Z& U
if(poi>=(*memory).proNum)
2 h. ?$ Q5 h e( t4 G0 Gpoi=0;. {+ ^. x4 K& G# }# y5 E. _& m
clockSegment=100;
6 k! A! Z$ Z6 z) N5 T9 E$ k}
8 o& _" C" f V4 n3 @0 d$ i; u, Freturn task_not_completed;% t8 M7 K& s& O
}
! c9 D) p% ?" u6 x# J3 z% s6 k& ?int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)
# z0 e( g( j3 k' p' A{0 b" F& W& C! B; f! c, Y4 D6 E
int i=0,j=0,k=0,flag=0,translation=0;
; j" n4 y0 f7 I4 [' u; Dfor(i=0; i<(*storage).proNum; i++)3 ^, d* j* D( h4 R
{0 H; u. x. f6 |! w$ J) ~. o
if((*storage).p.comeingTime>MAX_COMING_TIME)
( ? \! ^- Y% O _5 JMAX_COMING_TIME = (*storage).p.comeingTime;( N7 V( u0 v$ ~9 Z
}3 j6 o- r0 o+ b! F+ [8 z
if(pos>=0)
v& u' s; p3 X' U0 R{5 @4 n( G4 A! X# P' E& [
for(i=0; i<(*storage).proNum; i++)1 Z2 ~- Y2 v+ p
{. l5 v1 w2 x8 d- v
if((*storage).p.askMemory <= *spareMemory)5 {9 n0 U$ o4 n- a& [
{# E, A# [. |+ f- ]1 E) R& X% L
j=pos;; Z1 c) `' y9 P0 ~
(*memory).p[j].askMemory = (*storage).p.askMemory;) G$ e3 }- S0 U1 \
(*memory).p[j].comeingTime = (*storage).p.comeingTime;9 S+ n3 {% p' Y" a
(*memory).p[j].computeNum = (*storage).p.computeNum;
3 n1 |/ X7 t0 e8 F(*memory).p[j].ioNum = (*storage).p.ioNum;2 Q7 c9 h4 y2 Y, v% Z D
(*memory).p[j].processID = (*storage).p.processID;
, h9 i2 q+ \+ H+ X(*memory).p[j].flag = (*storage).p.flag;
{% Y9 T% `. _" p; B2 z, y(*memory).p[j].ioTime = (*storage).p.ioTime;, z2 W' M I$ X' I2 k4 ^
(*memory).p[j].computeTime = (*storage).p.computeTime;
2 N1 q, n* x: B$ q$ P) f1 x(*memory).p[j].runningTime = systemClock;1 _9 q+ [+ o1 u/ D
(*memory).p[j].produceTime = (*storage).p.produceTime;3 r' ^2 ~: C0 ^
for(k=0; k<(*memory).p[j].ioNum; k++)2 y& w# S* X9 d3 U' y, J
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];6 W6 Z8 w+ X; o7 G2 r
for(k=0; k<(*memory).p[j].computeNum; k++); p; D2 ]9 }0 Y' x. u' z
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];& b- O) T$ r- ?
*spareMemory = *spareMemory - (*memory).p[j].askMemory;' d+ I- Z) t Q1 F8 h% d5 Y, S
produce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
5 L$ {. M6 S0 l LMAX_COMING_TIME = (*storage).p.comeingTime;% @0 Z$ ^3 v* q: g! D4 e
translation=1;
5 a9 w. }# W2 b8 }' F5 o- \break;) W8 A- K: G: O) ]
}1 Y: s/ b1 P. m% Q+ i( ~4 W
}
2 r9 K: c# L' i2 N# c/ j}
( S+ [- c/ j% ^ p0 ?9 X* ~else
: p# [7 D* e1 ]& O! N! q{' S- P5 @7 u* O; h
while(1)
, ~: _8 C9 T! Y{; S; Y+ u# C3 H/ A
flag=0;3 M0 F) J4 q3 w( y1 ~0 a9 g& D
for(i=0; i<(*storage).proNum; i++)
1 y6 c0 z/ I8 _! T2 l7 e{7 P% q; V6 i4 S, I0 k
if((*storage).p.askMemory <= *spareMemory)) G# C5 R7 _' @. {
{
3 ^% r& N* i6 S# x5 jj=(*memory).proNum;
+ S7 f' B2 v4 G0 b/ u, n, b5 o5 P(*memory).p[j].askMemory = (*storage).p.askMemory;1 q2 o# r$ k1 y6 d
(*memory).p[j].comeingTime = (*storage).p.comeingTime;) e2 e/ t3 i, \
(*memory).p[j].computeNum = (*storage).p.computeNum;
. p& N7 G# O* j(*memory).p[j].ioNum = (*storage).p.ioNum;
, P, Q3 L$ |0 t" W5 _5 r6 B(*memory).p[j].processID = (*storage).p.processID;
% D# E1 Z4 T& A, r5 y7 G(*memory).p[j].flag = (*storage).p.flag;
: p( g" O& q: I Q, a& D(*memory).p[j].ioTime = (*storage).p.ioTime;
* y4 N/ X9 H: q' ](*memory).p[j].computeTime = (*storage).p.computeTime;
" s0 u/ k& T G9 U# M2 C; D(*memory).p[j].runningTime = systemClock;
/ ^+ G1 {' z: ^5 U(*memory).p[j].produceTime = (*storage).p.produceTime;. w1 J! I. e% ^% t8 @- E
for(k=0; k<(*memory).p[j].ioNum; k++)
% J* N2 x) r0 r. B4 D) E(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
' {& a/ I* t% r" Sfor(k=0; k<(*memory).p[j].computeNum; k++)
% ^% s0 M9 x- q$ ](*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];1 X8 b* L8 W9 x0 U
(*memory).proNum++;; J3 `9 q9 D7 A
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
( D7 L" g3 ]& L4 {% O; @0 Xproduce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程6 p; P* p) P( x# I0 f T) {
MAX_COMING_TIME = (*storage).p.comeingTime; w2 D. k" R- c) A5 c7 d0 t
flag=1;8 L- j# A0 e* J9 m
translation=1;
N9 [$ v8 ]" Y}
4 G# l2 {8 u. ]% h}
! l9 C% M/ S3 ^7 Z/ F; Lif(flag == 0)
# P6 W" U: H0 Z4 b* ybreak;: R: f! r! M' X+ f- T1 R; }% x
}! g* t t: Y Z( f2 |
}& h1 }9 X% w1 ^
return translation;+ Y3 |" f5 V) x6 _
}- i7 d! S' w9 I
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)
0 x6 v4 {; j- U0 W f{0 R: `# Z+ _6 \5 T2 J, m% x
static int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;
4 d/ m- f. g# P# T. M. astatic int computeLast=0,waitioLast=0,changeLast=0;
0 K7 F8 ]2 i7 }# r" {9 P: Yint i=0;
6 |6 H6 M' y. m' d2 A8 o: g0 W/ K" Fif(draw==1)
) z( y4 B1 S! m% f2 X% @{
) h/ a3 i! a' L; l* d! u//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);5 K- I/ u6 l5 Q( z2 M# ?- N
drawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
! l+ _7 o, H4 ]# W7 R B" Z' e' B- b3 i4 \
: [7 m9 c* P% a) w: e( L
computeLast=compute;- ~8 j5 Y& v$ y* f2 p9 \6 ?4 {
waitioLast=waitio;. x( _8 d! W" G8 e5 ?4 E- c
changeLast=change;: K* N& s( K" @2 [4 Z5 {
}
" L9 r: C$ P0 r4 L. fif(flag==1) - |* U7 \- J$ l6 R) t/ V
{- p% ~/ Z, S+ ]# L0 p3 p( O
if((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed
8 H% `$ k: W+ u d+ U{
: C/ s# D4 o2 Z) n5 {if(flagiocpt==0) // implement compute
5 e& i% e( t4 F1 t) F{6 G% ~& a" L) S) V6 T
i=(*memory).p[0].computeNum;
" T' X8 A6 {1 a4 Kif(i>0 && (*memory).p[0].computeClock[i-1]>0)7 k0 |( n3 K8 y$ V
{
. e* ~; k* V+ L' R i! S5 _if(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed
1 @/ X, o% ?: U/ F{
5 ~, w8 l: }/ w$ W ^flagiocpt = 1;
3 E- \9 B6 K) o' `7 U(*memory).p[0].computeNum--;" W* i5 q1 J6 M
change += exchange_IO_Compute;
) T$ ]7 D u; D/ z6 a: ycompute++;6 ?; x" J& f/ }4 [
}6 V# p- L5 W) [7 G, x3 ~3 h
else
; a+ S$ ~, x( D/ J6 Z' b+ vcompute++;
$ S+ ?+ u% q1 x! h8 F4 w' B+ [' e- l& H/ P. A5 W
}1 @$ P2 N) C; v5 V+ a
else$ V# G; ^) o7 X+ ?# [( r8 f0 w
flagiocpt = 1;9 r$ I. S/ D5 ~# M
}# `. M9 E- K* L& B. \5 l) i
else //wait io
% Z9 v; M0 I @4 K{
) ?0 g5 d) O' l2 N Y1 o7 Hi=(*memory).p[0].ioNum;
! w1 w9 N d# J7 F. j0 W/ a& F' Wif(i>0 && (*memory).p[0].ioClock[i-1]>0)
, j$ p ^5 Y& p0 f{
4 G# |+ v& X8 _ L c& P) kif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed/ N2 E- E* v. V% `0 U4 l
{, N8 C( k- V- o Y4 g- c
flagiocpt = 0;
& M( }/ R: s# g# r(*memory).p[0].ioNum--;
7 x6 q* }; \( q( j; Nchange += exchange_IO_Compute;0 }! Z2 \* x' }# \ t
waitio++;3 G/ Q1 @3 e% a I$ j0 P8 ^3 g9 C
}
2 a5 t3 g) j+ z) r# Zelse# a* l4 H+ c! [% N
waitio++;
h5 V$ o4 C d6 K1 i
/ D. x- N x8 i( D0 z}
e, L4 Z# Z. Felse& X3 e @+ j9 Y* X% T
flagiocpt = 0;, ^: a6 @. Z6 d3 l S! G% j! k
}0 o9 ]5 ~6 f8 V# c6 R8 ]
}0 r& p2 h' o! d4 u2 [0 i
else //task is completed
/ c7 n9 t$ }, h$ S* q* s6 r$ W{
9 [& K! D6 T" m9 T8 h. e(*save) = (PCI*)malloc(sizeof(PCI));
! U% t" E- y9 _) Y' f; o/ B(*save)->next = NULL;! V4 C* T4 C/ }, C
(*save)->processID = (*memory).p[0].processID;
4 {3 c5 ?9 b k, u a(*save)->comeingTime = (*memory).p[0].produceTime;
7 K, U8 `' |! j! K" M4 k, a+ e2 F(*save)->askMemory = (*memory).p[0].askMemory;. O" x* h, V6 @9 z( [& d' m
(*save)->compute = compute;( V0 R- L, ]+ ~" @: j
(*save)->waitio = waitio;$ `- k) F$ [' D
(*save)->exchange = change;4 L1 Q) A7 P! H Z
(*save)->completedTime = systemClock-(*save)->comeingTime;* v. R6 S3 h3 Q+ B) j
(*save)->runningTime = (*memory).p[0].runningTime;
9 F' e8 n$ G }6 i* C/ y1 H(*save)->completedTime = systemClock;4 R+ B2 D" J4 R) s2 G8 q
//*spareMemory = MAX_MEMORY;8 `2 s5 x2 O9 {+ r- [4 ]$ C2 J
free((*memory).p[0].ioClock);8 O9 r* j8 e# R- S3 [, h. ~& p
free((*memory).p[0].computeClock);
, x- H; o) j2 Pfree((*memory).p);* M# g" z2 G" Z. e4 }
flag=0;
6 D; q% a; R. n" B% M% rcompute=waitio=change=0;
1 L+ w2 F% e5 ]/ [9 YcomputeLast=waitioLast=changeLast=0;
) b' A' t. S* V2 [2 a$ Creturn task_completed;
3 ?- @- F# D% {. I6 Y6 I}
: G% j$ t- F) X; L) o o}! ]7 h: u7 l3 e4 F& R, T, H
else 5 `( V5 J; a4 ?
{. T* Q- u: T4 \! ~
FIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));! d$ X. ^$ u. _: g6 p* b/ N$ ^3 ~
change += exchange_process;
, i7 k; R0 v& b' @0 W; m o//*spareMemory -= (*memory).p[0].askMemory;
5 w: _4 P/ ]8 _- B8 Dflag=1;
, v7 Y2 f k! `- R: R//showProcessInf(*memory);$ C8 d% k, A2 Z* p0 L2 ?0 K5 M
return task_not_completed;
, a0 ?% O" D R; W U; i}* b' C# V: ~& j: ^9 a. s( C
return task_not_completed;9 O" d q' b& V! o4 l$ a' a# d
}
2 t$ L. e/ W" m" G2 X* ]: v$ Mint FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)% z3 v1 i" o X: k
{3 Y% N3 j) H n
int i=0,j=0,k=0;
# {4 y, M' M1 \0 Q' H6 ZMAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;
( }7 j' W) e3 L5 `(*memory).p = (process*)malloc(initProcessNum*sizeof(process));
: Z7 g! }) x! N% G6 Mmemory->proNum = 1;0 N. _+ v7 H- B- o" X
for(i=0; i<initProcessNum; i++)
& z# P8 Q* _: Q6 J, \! s{
# ^! E- d5 F" j; n! _8 rif((*storage).p.askMemory <= *spareMemory)
. ]3 O4 L/ B3 t$ i4 ]4 x{
. g- u% R* p. h8 R5 z9 X, ]7 P(*memory).p[0].askMemory = (*storage).p.askMemory;/ o0 D" C* @# Q+ r9 w: t2 {$ I
(*memory).p[0].comeingTime = (*storage).p.comeingTime;
$ F0 o4 f- N) {1 S" }7 D(*memory).p[0].computeNum = (*storage).p.computeNum;
) u% H" C# m4 m- B9 P2 ~; d(*memory).p[0].ioNum = (*storage).p.ioNum;7 C1 Z8 F- c5 {7 K
(*memory).p[0].processID = (*storage).p.processID;# e: t9 b, m' `
(*memory).p[0].flag = (*storage).p.flag;6 T; S R' n1 d5 }$ P
(*memory).p[0].ioTime = (*storage).p.ioTime;
% c, `& L2 K) I& k* E/ F9 F(*memory).p[0].computeTime = (*storage).p.computeTime;
, O! b% r9 H4 C, @" h* W1 |(*memory).p[0].produceTime = (*storage).p.produceTime;
/ G( J+ O' I* z) W3 e(*memory).p[0].runningTime = systemClock;
n& l Y4 E" M( U8 Z5 g(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));4 j% F' V0 X4 h( k" w
(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));
4 l; F5 y- T3 S/ E. w5 [for(k=0; k<(*memory).p[0].ioNum; k++)
1 L! E7 N. |! Y+ N! p8 b/ h(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];
( z( h5 s, }4 Y! [8 Wfor(k=0; k<(*memory).p[0].computeNum; k++)
& W3 p% H- x3 X2 r3 i1 g(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];
* c0 Q& W+ K# C) tbreak;
( j. a4 v, x0 p0 p}" r5 |# A- F3 t4 y
}+ _3 |! d: s% p+ u" q o! H
if(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入1 y& d& t4 I4 [7 ?6 p4 v6 f
{
% F8 ^" b! u3 b& Yproduce_one_task(storage,i,ID_FIFO++);& P1 Q i9 [7 J; L+ L: W
MAX_COMING_TIME = (*storage).p.comeingTime;' m! u+ c* C/ w: l
sort_by_comingtime(storage,i);
& k5 r7 p1 H: B8 F# K/ K3 Z) C# \0 E}
8 T; I X5 S8 ^ A( J5 Z: Xreturn 0;
, R3 I2 F' w( X}
' z0 ]3 o, G, G9 T+ pint sort_by_comingtime(processPool * p,int pos): e+ P+ t: x6 [3 { f9 R
{
l4 j1 a- N' G. V; G% T+ Eint i=0,j=0;
9 c, V# Z! f, K9 L! |, l$ Y' Jprocess temp;
; P1 T% _4 H3 p# I3 u: @, ?if(pos<0)
: {5 D7 V! {- M; b# o( z7 _# Q{/ o0 A: M) b3 ], j D/ x$ F4 B; W
for(i=0; i<initProcessNum; i++)3 g$ k7 i, G9 w3 S" x/ l, C9 S; i" s
for(j=0; j+1<initProcessNum-i; j++). z' H) s. F- {: x( N1 B
{6 A( K% [ M; g/ L
if((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)
0 S* V8 G; U2 _{
- d8 b& L$ |: ]. L3 a2 H: } C, K$ ktemp = (*p).p[j];# g, X' j. W6 U5 T& |2 I5 }: G; m! o7 j
(*p).p[j] = (*p).p[j+1];
. E) i7 M9 y: Q. u) X4 ], ~(*p).p[j+1] = temp;
& V$ X2 i( |4 t! ~6 L( f3 L}" n7 l- [/ ~0 ^' J& c2 S# n, \
}) K7 i8 a# d2 X/ O3 l& B4 B# S% t
}
, X' k* }4 m$ }* s- E1 Y4 ]else if(pos<initProcessNum)
' P2 b* [. L! b7 n6 @0 P# g{* T$ c5 \) b# n* z# o- \) \' a
for(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)4 ^# T9 X2 y; E) `4 E
{, ^9 y3 s; `' D* o
temp = (*p).p;
# h0 e9 v4 K* L/ A0 b8 k(*p).p = (*p).p[i+1]; X* x, C( T( {- E/ d
(*p).p[i+1] = temp;
8 ^/ |0 v, U7 Z0 Y, L! |}
' e3 l" j7 n* V: |* gfor(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)
+ h- ], H4 P$ P{
2 u" F8 q4 C2 M* _4 L- q; W+ ttemp = (*p).p[i-1];
! u F3 @ X7 V% `# H. m O(*p).p[i-1] = (*p).p;
; ?, }- t( [! c9 i7 ]# q& R7 P( [(*p).p = temp;% {# G2 t/ F5 B6 G8 ^
}. L, H; d$ n @2 s) I
}
* ]6 ?6 I+ Y* A9 i5 u, Z: a+ p7 ~0 f9 p/ oelse1 h" R- @$ b* C) J# u) V# l* S
printf("position eror\n");
" l7 |$ b1 F3 C" o$ k- m; Z& Ereturn 0;
: S5 x* ?2 A! I7 ]' x}% g5 O7 P2 Y8 @& n8 B& P* a: q
int InitPool(processPool * p)/ t1 F( |, P: J- W3 k" B
{- s+ e: G* O8 C& w4 o8 u
int i=0; Z7 f, n3 L% @9 t# D7 ?
(*p).proNum = initProcessNum;
7 A$ i0 U+ P X& `(*p).p = (process*)malloc(initProcessNum*sizeof(process));
& p# V& {: w9 ]1 M# hfor(i=0; i<initProcessNum; i++) //init process information: M" [+ ?7 x( D& }9 x
{
6 m- S$ B/ J# T+ G0 R(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));
) U c* M+ u% P(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));
! k( {. {- P* R3 fproduce_one_task(&(*p),i,ID_FIFO++);: z2 `; u3 _1 B+ w8 P
}
2 D" y6 z& D1 x3 [1 ?/ o, Lreturn 0;7 P( M6 U3 e# \1 w" u& X. C
}
. V+ |" b# c, v% D3 ?2 v Rint produce_one_task(processPool * p,int i,int id)
; E$ m* O# h$ j{. R `1 h! |& z- f" ?
int time=MAX_COMING_TIME,j=0,totallTime=0;( |5 @4 `) v1 i$ n1 [. h% f
(*p).p.processID = initProcessID+id; : N. }1 i' R; k8 [
(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);
* H) w* h Y% G5 [8 W2 ? j, _+ _# a(*p).p.produceTime = systemClock;
7 b7 x, B6 r( i( U0 O/ t/ G(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;
) P" l/ {- ?) j(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6;
* d+ w0 ~6 f/ a1 ?: _totallTime = (*p).p.computeNum + (*p).p.ioNum;
3 _6 l: v, I X$ n3 M, [# w( X(*p).p.computeTime=0;2 s$ z4 Y. ^1 U/ g% s) h6 h
for(j=0; j<(*p).p.computeNum; j++)
8 c/ Z- ]3 y/ a! D{
* `- M" B, N% a' B' O(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;
0 c1 b1 u0 Y# Y* s, e(*p).p.computeTime += (*p).p.computeClock[j];
. Z. v3 {5 [9 m2 ] }* b2 i}
/ P5 H6 @) `' G/ Y; f! u7 w(*p).p.ioTime=0;& A9 |. W A2 H& ^
for(j=0; j<(*p).p.ioNum; j++) |
|