- 在线时间
- 1630 小时
- 最后登录
- 2024-1-29
- 注册时间
- 2017-5-16
- 听众数
- 82
- 收听数
- 1
- 能力
- 120 分
- 体力
- 562739 点
- 威望
- 12 点
- 阅读权限
- 255
- 积分
- 174195
- 相册
- 1
- 日志
- 0
- 记录
- 0
- 帖子
- 5313
- 主题
- 5273
- 精华
- 18
- 分享
- 0
- 好友
- 163
TA的每日心情 | 开心 2021-8-11 17:59 |
|---|
签到天数: 17 天 [LV.4]偶尔看看III 网络挑战赛参赛者 网络挑战赛参赛者 - 自我介绍
- 本人女,毕业于内蒙古科技大学,担任文职专业,毕业专业英语。
 群组: 2018美赛大象算法课程 群组: 2018美赛护航培训课程 群组: 2019年 数学中国站长建 群组: 2019年数据分析师课程 群组: 2018年大象老师国赛优 |
7 b5 d x* a2 H% C* }; o6 ^经典任务调度算法的模拟程序
3 Y; p$ K2 }3 E0 Y& O本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。
/ Z" W3 V5 t9 Z' o4 B# }* w5 w+ w V, R
编程平台:VC6.0+EasyX图形库环境。
) o6 `( v& c+ f+ u. n! q& _$ e
/ {0 [) R. x% Z& B以下截取部分程序运行图::0 Z; c. M6 o. O0 b; Z2 V
- T7 N2 A! W. ^/ K, W* Z# x
源代码:
0 w0 A( ^2 K0 n# V& T% S% [6 [1 L& x0 D* V
#include<stdio.h>$ T4 b2 G$ H& \8 p2 {% `
#include<stdlib.h>$ R% D4 R. S# h, Q: S
#include<easyx.h>
( s: ]' t& x7 R#include<time.h>
/ Q% t3 ]2 z4 G#include<conio.h>; a+ E7 j" b6 l0 j" M: H" Z
#include<graphics.h>) W R0 n$ v5 S o2 D: I: F8 d9 I
#define initProcessNum 10
$ }5 s3 p& C* B, w: ^#define initProcessID 1000: W: E. \; ~# O4 N5 t
#define MAXProcessRunTime 100006 i3 w6 m$ I9 {5 W$ s: d
#define MAX_MEMORY 40005 h- W, m& ~: M0 \# {
#define exchange_IO_Compute 10) d6 O+ n }7 t# l
#define exchange_process 25
8 Z. K. _- I9 Y& _1 b4 M8 }3 S#define task_completed 1
- ^- J; N* e/ M; G `0 N9 f- q+ a#define task_not_completed 0
# O' v1 l- e0 U2 _/ V9 G$ `% O9 e#define initclocknum 100
2 s) E0 d1 Z* {, Oenum condition
6 r$ E0 p3 S; V1 b{
! G5 T! f8 R9 m% a! kdead,computing,IO_waiting,ready/ D+ a3 m, @- P" r! S' L
};8 x0 s/ P; i0 o, i$ g
struct process8 A5 _( X0 y2 ^5 K9 |/ }
{6 j' P% M3 w' T
int processID;5 m* H( i" l, `( j, `- _* {
int comeingTime;0 J# B. U( z3 K$ B$ J6 g7 w: n7 t
int ioNum;
0 o. ~" F) N0 r0 \2 i) o# Hint computeNum;, r8 I- F% [& j5 h! n/ E4 Q
int * ioClock;
$ c6 A- b0 c5 N: W$ sint * computeClock;
& a8 S1 F A' r% n8 _5 m6 Lint ioTime;
3 Z( N, e( n3 D6 Rint computeTime;. }$ g$ x7 q5 o2 k1 R5 F1 ^- a' J, r: q
int askMemory;- @* Y9 B! |, J8 S3 e' a$ x+ [2 E
condition flag;
6 k+ ^5 s, w0 E+ `: @int produceTime; //生成时间,以下三个数据成员用以计算相关性能' ~" m8 @3 u. h$ U* ]1 C
int runningTime; //第一次占用CPU的时间$ ?" X& ?! M' P) n0 ]6 H
int completedTime; //进程完成时的时间! G3 k. H9 k+ m/ G2 L1 L
};) ~" a, U( ^+ K. M7 J2 m, ^
typedef struct processCmpletedInfo //保存完成一个作业的相关信息
, s) z' Z' ?4 M' u. s/ w; \{" t E* {( c! T# m o7 f# n0 v
int processID,comeingTime,askMemory;
8 e' Y* ^4 }% g& B4 p% s: ]int compute,waitio,exchange,completedTime,runningTime;7 Q8 n1 L$ ~5 ?' P6 C$ Y
processCmpletedInfo * next;
. a9 d' R m3 s' |/ k}PCI;
0 U; d( y2 Q7 g- e, l" E) estruct processPool2 ~' E1 \# d1 M' i! f0 u2 j
{
, l0 U' b9 R$ f$ y6 T+ H( dprocess * p;
# Y! T# N0 ?; y4 P% nint proNum;% O6 b6 m% S; e0 C1 w! ~
};3 k9 k6 A( l L8 F; i7 [
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;& Z% P- r8 @& L+ w
int InitPool(processPool * p);4 ]4 e7 Y$ V3 b) H4 H
int produce_one_task(processPool * p,int i,int id);& \( h" u" W6 x- n4 d# V
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);+ x- m$ y! ^) n5 I
int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);& e. D: l' ?% W
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);7 w9 _, T; |. H
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);! S$ G6 H t. o5 E' D& H2 i
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
3 z5 O4 n% |' u& y3 mint SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);8 S# m& A& W) n/ E; |( O& i
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
) i( h- }8 c4 M$ D+ o( D! u) J+ pint Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);. S& U1 l% `' g' }0 D
int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);
]. M! M; U; Rint High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
C \( ]8 [3 E5 x3 k5 e N0 q6 s* T u8 Q
4 z7 H# |, p# ^; G8 Y Nint sort_by_comingtime(processPool * p,int pos);
+ a- p* {! F. i# {+ bint showProcessInf(processPool p);8 b7 }; U' ]! ~
int drawPerformance_FIFO(int x,int y,int memorry);! u* ^5 B0 P; U2 f$ M
int drawPerformance_HR(int x,int y,int memorry);
7 o+ i+ [' N/ L+ xint drawPerformance_PF(int x,int y,int memorry);/ ^0 L* H* n% |. \ w; {* g
int drawPerformance_TT(int x,int y,int memorry);$ i% K) b" x. Z. v, w1 t* f
int drawPerformance_SJF(int x,int y,int memorry);# N# Z. O9 I) N5 X5 H2 M Z% V$ n
int MouseListening();
7 w( N) U y8 e" s. pint MouseListening2(int *flagShow,int * showTime);
4 x7 t7 `& f$ {" U: S. a' b' Hint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);
+ Y: `0 e3 t) f9 S/ b2 q: k( c; n' t- j# v8 Q8 N) @1 c
+ c6 O' y( {* a8 J3 x" D# kvoid main()
$ @- T1 M9 D3 v- c8 ~$ Y' C: ]{4 K1 |: v$ X. [$ K
PCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,
+ Q* C6 o" Y* f' V8 [& h' t*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;% L9 }9 |1 w: B" D* C
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,% ?1 ]( |: S# X6 d1 B
flagDraw=0,showTime=100000;
7 _: ]2 S( S, @- i, c& P& gprocessPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;" Q, ?: Y7 Y: w' ~3 x! L, p% ~4 X
FILE *fp=NULL;
- Y* i; C$ a3 d0 p' W) a//processPool HR_p,HR_mmy;* \! b; Z$ s2 F7 G/ ]4 c
% @2 Z$ }* B; D+ g* A
2 y" n1 e" |# f5 L% i" n/ Isrand((unsigned)time(0));
+ [7 Y5 ?6 o$ J& g- C2 MsystemClock=0;
/ p" k2 T7 e& e: B/ Q; yinitgraph( 1200,650,SHOWCONSOLE );4 r3 Y; e2 }; x% f0 a
settextcolor(GREEN);
, b& [7 U1 l& g s; Wsetlinecolor(GREEN);1 Z; D" P6 A5 {- i% G
setfillcolor(GREEN);
: ?8 M8 M6 H b. nInitPool(&FIFO_p);
9 Z! S9 U& ^; `+ Dsort_by_comingtime(&FIFO_p,-1);
0 Q- T& X9 W# G8 E) W" Q& F) HInitPool(&Timeturn_p);' |. Y) W. r h2 d) z5 C+ w
InitPool(&SJF_p);
3 T9 m8 j2 @/ g* K. k1 m/ P0 bInitPool(&Priority_p);- r" _+ W) T1 S
InitPool(&HR_p);
% g" y6 A! W+ P, r- t8 i# q* R L//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
) } T& f6 A( J+ a3 S! d7 O//Sleep(10000);* M# h# \! S/ W8 j: o/ B3 G
3 u8 N9 h. O+ H2 b' S1 @
- j. b4 z8 u+ _7 O/ lTimeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));% D. w9 J( }) z3 ?2 c4 B
SJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));- [0 _6 T# L& i4 q: d z: ^+ }
Priority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
: C$ T) |+ c1 k$ A8 R: WHR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));5 { U' _$ a+ w
for(i=0; i<initProcessNum ;i++)
/ O8 [- d; |5 l{
9 `) |# c) H& d6 [% U' GTimeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
( X1 o/ C' z, a) ~7 s3 vTimeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));& ^7 Y' d7 @& D2 t; j
SJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));! J k9 p/ f8 n( e$ k
SJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
" A& O% T, E3 v+ k; wPriority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
4 M6 D0 X+ J) f3 i+ Y6 r UPriority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));0 P9 \, H& |$ x
HR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));) V- f1 _5 t. j X! G( u! M: P+ p
HR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));4 z) Q) l6 D; k' D2 q: L/ G( Z: L1 S
}
' h% m2 G: o8 `- ?Timeturn_mmy.proNum = 0;
) w& a: ?* J4 ]+ yTimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);
5 c7 W: d/ h- ~. s9 j; HSJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);
: d3 R/ d7 r9 o8 g1 g {Priority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);3 R: g7 U P% f- q( P
High_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);- }1 Y4 [/ T. X0 A- p1 F& c
//showProcessInf(Timeturn_mmy);8 U7 s( s1 O4 {4 J2 O
FIFO_pri = &FIFO_save_head;: ?! y7 R; g- l9 t6 k, u8 `
Timet_pri = &Timet_save_head;
& i' ^2 W) w1 J" x! @SJF_pri = &SJF_save_head;1 {; r4 l5 x' W3 W
Priority_pri = &Priority_save_head;* r( C$ Z, r: G
HR_pri = &HR_save_head;
9 u9 A: ?! B. n: T& C6 Bsetbkcolor(WHITE);
' m$ M6 J( k( E+ j+ `while(1)
6 q- [( J2 Y3 J# q1 L! t' u% E{
: J* A+ j2 f) \0 S9 M% Vif(MouseListening()==1), O# } o! j* _) I* F' ]
flagDraw=1;
- G* y x& R: t2 R, iif(count==100)
8 C" ~7 k( F/ O; l3 z' G+ w% W{' b* `6 e2 M+ `* h
if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)
% `1 s+ k0 v' Q: C! k{
7 ~: ^" F) U0 H2 ~) ^FIFO_pri = &((*FIFO_pri)->next);
8 w% ~. w$ x7 Y3 X/ y9 d f
- l2 R! r6 v# m* q: _//printf("hello");* ?1 O) d" s4 C7 D
}/ G( N* H# w3 l1 |+ O% T
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)5 [/ J' H! g0 D0 \4 P5 Z
{
" C. u" g) {" g x/ o5 P Timet_pri = &((*Timet_pri)->next);
/ Q) g) w0 j: [; M* i7 W$ Q! t2 X. S+ E//printf("hello");6 U' s W/ f( a1 H
}- J4 B5 f6 f, F
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)
9 d* M, r8 ^3 {0 p3 |6 `# b+ @{4 w1 |8 H# T9 e5 N
SJF_pri = &((*SJF_pri)->next);
+ G8 x. k( u; p" g//printf("hello\n");6 o h& A, H6 |9 h2 a+ O4 w
}0 n- m- u! s: e1 T; u6 W5 i5 q
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed)
" \0 p( t% I* ^0 v6 ?: o{
4 ^" ~6 s- C# n7 Q5 vPriority_pri = &((*Priority_pri)->next);/ y2 @$ m T, ]7 p8 H
//printf("hello\n");+ A" B5 G1 E* _
}5 P! C* e# q; w" ]0 S
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)2 \: h) }+ h( z& ~ L4 k, k
{8 H$ e" h" I$ e, [
HR_pri = &((*HR_pri)->next);" b0 M) y7 h' }
//printf("hello");
8 A+ n. k9 P$ O; L( T6 G}6 L- t- ?9 W) b- q
count=0;
; i9 b q. k, ^6 j; Z4 ^}
+ |, a2 U8 O6 i# f' h# xelse0 Q! V- m4 e- {
{
: p% B! }9 e$ n8 h6 C2 hif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)$ E' i( j' i6 ?" j( p
{8 H3 ~$ N0 t. a7 N7 A" W. b$ _
FIFO_pri = &((*FIFO_pri)->next);6 i. F0 ?& c( C; B: |( [- Z Z
// printf("hello");9 j' c4 V& w4 u; T8 @" t2 Y
}. k" V, m* r9 q; B
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)7 I1 W9 Z0 s7 E4 ?# U0 l9 u
{
& Z: j0 y& x& ]8 ~ _Timet_pri = &((*Timet_pri)->next);
3 e' V- Z. }& R2 Q+ r// printf("hello");
6 `5 I$ ^. N! R}; P+ _/ Y2 I7 i5 ^/ N$ f- h
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed): o' A5 A6 f" E& {& s9 d
{
" U; w+ l# l' B) U' T! W' X2 ? SJF_pri = &((*SJF_pri)->next);4 c; r$ s; `6 y" Y: Y( ?9 I
// printf("hello\n");6 k6 U2 O) n' T7 M
}& d) g3 W7 I1 i0 q% |7 S% f# q: h" }" B
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)/ r' H4 a z: D* g& s" {
{
, ^6 X" q4 ]" I& s! `. L# VPriority_pri = &((*Priority_pri)->next);0 Y9 r- [9 t* t$ S, y' U- _5 x3 w
//printf("hello\n");3 T K+ T4 s( c2 z( i0 n- o
}: @6 S* s0 s5 I; K: C X" `) b
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)& ^# C& L& q& f9 v
{
C. `$ c. R# W! w; x6 O! w/ U& iHR_pri = &((*HR_pri)->next);3 ^- H u6 r* n0 L4 r9 E7 `
//printf("hello");
$ n9 B% U1 L4 N9 a//Sleep(1000);
% y7 g1 O+ O$ ?8 I7 T5 I0 N+ p}
/ H# j' Z9 m3 O2 bcount++;
4 {2 P- D! }* k: h}
( t$ O" }2 q( K& J( k* \7 }if(systemClock==showTime)
% B: ]9 o! u, l! I8 I7 E{
5 `+ m/ |& D4 U/*PCI * p=FIFO_save_head;" D2 B$ H9 F7 ~
int i=0;
- W" i, a- {+ W: W0 Ufor( ;p!=NULL;p=p->next)
% j, [0 E1 H2 n% }; q* w* O{- U/ d5 u5 B' z$ P
printf("Id %d\n",p->processID);; P- g D" X/ z* ^1 {# ~ g3 P
printf("comeingtime %d\n",p->comeingTime);
2 v8 z" m u v8 k9 s! I5 xprintf("runningtime %d\n",p->runningTime);
3 K, l! Z. u) ^* S# a1 Xprintf("asdmemory %d\n",p->askMemory);: K; [# u: b" e; P. ]( J; G
printf("completedtime %d\n",p->completedTime);' i8 @ e1 X$ e
printf("compute %d\n",p->compute);- L# [: r7 Q& u
printf("exchange %d\n",p->exchange);9 h- ^; F, V8 X' S! |% U
printf("waitio %d\n",p->waitio);
: L* C) I! V: W; di++;8 l. B9 ^. x) L
1 k# |- G, M5 f9 @3 t6 t% f* `8 t, y
}$ q, a% P9 L4 F% o, y5 T# Q
printf("%d\n",i);*/
. \6 j; G5 _# g6 bif( (fp = fopen( "data.txt", "a" )) == NULL )/ A4 v) w4 a; r* k% p* C
{4 d1 c- d" q. n* Y' q2 F
printf( "The file 'data.txt' was not opened\n" );
; U ~$ b7 O' p, D7 y6 u//return 1;
2 q$ t" h& ?# N}$ N9 G' k2 u7 s. }: Y
else
. J' @6 N. C5 \" i. c( S{, T/ g V$ V0 n) A: U
fprintf(fp,"FCFS \n");
?* m' i. t9 o9 P2 j. E! afor(p=FIFO_save_head;p!=NULL;p=p->next): _6 \ f& Q5 w( o
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
: Z6 B. j ?" ?1 J. `p->exchange,p->waitio,p->runningTime);
3 z& _ } S, }1 `fprintf(fp,"\nTime turn \n");
, l2 O# r7 Y; }9 X: }for(p=Timet_save_head;p!=NULL;p=p->next). |4 B7 X: j& u1 T+ b- U" w
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,4 @" i3 l$ p# M% Q" r ~- t
p->exchange,p->waitio,p->runningTime);$ A0 y" i. B( V
fprintf(fp,"\nShort Job First \n");7 T' s, X6 J1 L5 x1 t; Q' v3 o5 y
for(p=SJF_save_head;p!=NULL;p=p->next)
! ?3 k& f! l# h+ @2 E G- Lfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,/ x2 ~, P$ U" C% O# ^
p->exchange,p->waitio,p->runningTime);1 Z2 n: P: O1 B3 B& _' A# V
fprintf(fp,"\nPriority \n");
$ E7 t1 N7 w& wfor(p=Priority_save_head;p!=NULL;p=p->next)
+ a: c" S! U# B2 o/ s; `/ Yfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
) m. X3 g0 D' w) c& R+ O/ [! H2 Op->exchange,p->waitio,p->runningTime);3 H; i) s" @. c4 F
fprintf(fp,"\nHigh response \n");# B7 }: `0 h% b- q
for(p=HR_save_head;p!=NULL;p=p->next)
9 P6 L7 y' p9 Z' {: Y s2 f/ Kfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
V- ?) u1 C- \6 f" Gp->exchange,p->waitio,p->runningTime);7 E; x7 H) b M8 h: c
fclose(fp);8 w Z" `0 k, H* P1 y! T: G, G
}
& l3 ]5 M! o7 ~9 D: hshowRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
* C% L! p! z) r% s E- KMouseListening2(&flagDraw,&showTime);7 v/ ?, _1 c4 s& [1 n
}1 ~: j) O4 P2 F% p: U
systemClock++;% I$ M& y9 j; x& K7 c" v
if(flagDraw==0)# G, A9 h, m: y7 \0 y8 a
Sleep(10);% ^7 R0 z) R& t. P+ d! D
}
6 b1 S* S$ G5 n5 a$ ~& w$ E
6 j" r4 v; V9 a, Q& G% Q. Z9 ~1 X# C! l6 Z4 \( t( t/ b, p5 {( [
}
4 d* T. ]5 }3 P* W& fint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)
- O0 d/ z" i7 s, v4 L8 Y{7 a; n% K# T; P% k G/ f) x
PCI * p=NULL,* name[5];7 |& H T( D) u/ i; T2 ~; T
int count=0,i=0;
, }; m7 `& q; x! r8 p/ dchar ch[5][10]={"FCFS","timet","SJF","PR","HR"};
$ C( q% k1 o2 I2 idouble turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};
* T' k! W ~1 d- Z. B; I, {9 y2 I1 pstruct info& d* S6 U; x: v2 M2 V
{
4 m' H) ]% v' ^2 { a% dchar name[10];
) O) x+ ^/ ~) B( s6 ^double throughput,turnover,wait,CPU_rate;
' l& e( Z! f: h) D}inf[5];
& D$ q8 D1 P% m' Dname[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;
: r0 ?/ h: C5 oprintf("调度算法..........A\n");
, V% m k& V( Eprintf("吞吐量............B\n");8 j! T: i D8 p( k4 C3 n! f
printf("平均周转时间......C\n");6 a3 \$ @8 p9 I3 O2 G: [3 `
printf("等待时间..........D\n");
+ }2 v/ _ s5 q/ @5 a3 G* `printf("CPU利用率.........E\n");* g/ A4 M( y5 Y/ ?3 C. v
printf("A\tB\tC\t\tD\t\tE\n");
( j! R6 h! e; a4 B; Hfor(i=0;i<5;i++)& U* R# A$ L! |
{2 r% H! J* I$ R$ p/ S
count=0,turnover=0,wait=0,c=0,w=0,change=0;
6 s# q& `# M% ?- Wfor(p=name; p!=NULL; p=p->next); ?$ s! Q N* b! \- W+ E
{) |& ]$ p% k( ?' g
count++;( G% Y3 b6 E& G) f/ H
turnover += p->completedTime - p->comeingTime;3 E. M1 Q- \, k3 i
wait += p->runningTime - p->comeingTime;' j) V' x2 X. o. u
c += p->compute;; l; M% ?3 I; f
w += p->waitio;
, X$ ~9 _6 c3 ?& Echange += p->exchange;5 c, ^$ I. }( U: k. W# d3 x
}& N- ]( L1 o" i- F, ?- O# h
turnover = turnover/count;
2 _4 j! O; m. n3 c0 j2 tprintf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));3 P9 | V. x A* o
strcpy(inf.name,ch);6 k e/ q) r# h# A) H
inf.throughput=count;( F6 t% T* o) u) R
inf.turnover=turnover;: k# n: Y* m9 X4 r) X! o+ w+ T5 r) Y
inf.wait=wait;
( f, M+ a2 G c) einf.CPU_rate=c/(c+w+change);* ~5 o. W9 I( U5 a2 E
}) i1 P; X4 R# f4 U7 m& A3 L
//画图- R8 ]9 G& t3 ^- F
//cleardevice();$ N7 H0 \7 g+ F8 ?6 t
line(0,600,1200,600);3 s0 [# @# t l0 Z9 ]1 I' B9 `
line(10,600,10,200);
. @3 P( Y2 X" K& W& j. Tline(10,200,5,205);
0 J# c1 [' M @% Fline(10,200,15,205);& v4 t+ T5 _; C
line(310,600,310,200);
# L1 n, |$ Z/ P6 I0 A7 cline(310,200,305,205);
* q# L% P; d% C+ yline(310,200,315,205);2 C: { l% n: G' c
line(610,600,610,200);2 e! P w/ s2 \3 U( z P3 X9 x
line(610,200,605,205);$ f) L5 X1 M T2 W a1 [5 w4 ?
line(610,200,615,205);( `6 s! J/ `2 g: N$ u
line(910,600,910,200);& {8 }6 |$ {/ N) R/ k
line(910,200,905,205);4 _1 x0 Z \% x1 d' V/ y
line(910,200,915,205);//最高的长度400,宽度均为406 i% P/ L. h3 j9 g g5 r3 x) h
for(i=0;i<5;i++)
l9 ^2 d D6 }7 B{8 q/ R8 ]0 A d2 i* @
if(inf.throughput>pos[0])
# W; } k( A. M2 g) Cpos[0]=inf.throughput;
% L3 q( H$ w! L+ J0 _7 R% aif(inf.turnover>pos[1])7 _, W; k4 K' A w3 U
pos[1]=inf.turnover;3 G3 h y5 m' x7 m7 U' \! h
if(inf.wait>pos[2])
+ N6 r) V& M5 ]9 q5 Mpos[2]=inf.wait;9 n% E+ y3 w, x3 C6 P) {
if(inf.CPU_rate>pos[3])
& N3 o. s' o) W- M9 l- q1 g& r9 Ypos[3]=inf.CPU_rate;
! R' ^( I% b. m5 P: u+ g}- v. ^ g" E, E/ o9 V& _
settextstyle(30, 15, _T("楷体"));9 I/ B" ^. [# N, {/ E
for(i=0;i<5;i++)6 \: \% s3 k: t6 s
{8 \+ Y$ l$ g+ m4 {4 a
switch (i): k4 N( A+ l1 y
{
/ X+ A, m& Z& L' e) ocase 0:
/ l: q/ ?. j4 V* k% }+ c; t9 T3 n- M' isetfillcolor(BLUE);2 D) t2 t* Z8 b, ~
fillrectangle(100,50,150,100);* J7 K- |$ z5 z6 h5 a
outtextxy(160,50,"FCFS");% _4 x* X5 U+ Y6 E
break;
4 J, \5 w. j7 s" C; Fcase 1:
6 F+ F: R! F& u! H( D! zsetfillcolor(RED);
6 U1 B, h0 l* D' w# ffillrectangle(250,50,300,100);1 [5 Y1 B! }6 }4 G3 P3 [2 p
outtextxy(310,50,"timeTurn");6 ]+ B" N' [8 H3 u! Y
break;
. A1 }! h* t3 g4 {+ B. dcase 2:/ ^9 v8 a+ R: y' _3 {5 R; m6 u
setfillcolor(YELLOW);
, {: J: r+ P! hfillrectangle(450,50,500,100);
8 z# p# W/ k) V2 ~- Qouttextxy(510,50,"SJf");
$ N9 n4 [$ x3 N" n4 Rbreak;) g7 r4 |/ f+ w* c1 v
case 3:1 F0 r! c' }/ I( u
setfillcolor(BROWN);
( v/ ], b$ z4 F& ?# p( lfillrectangle(580,50,630,100);
$ | |6 C- l/ M3 A: }outtextxy(640,50,"PR");
8 U# x( G' W3 S% H% @8 z2 l4 pbreak;) j3 {: X! _# Y9 `+ @- e
case 4:2 e3 s/ t0 p3 Q; Z$ ^
setfillcolor(GREEN);! \ _5 b' G; o; m5 F C
fillrectangle(690,50,740,100);# h4 Q7 ~" {7 X9 {9 H
outtextxy(750,50,"HR");$ w2 c* [$ T" x+ E8 [+ H
break;/ q) J5 j$ |& r( P9 U- k
}
7 U+ y" c1 y3 d" [fillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);
3 R/ T3 T& P1 L9 \7 Efillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);
3 q8 f. d0 d( tfillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);
5 a+ i* w3 j1 Nfillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);
+ R0 D! Q) r8 O! W) {/ H7 G
- R( [+ T4 S4 k! V, K0 H; k/ X( V1 ^; ^3 Z5 V7 v
}' o/ C) v3 K. t# J& V, f+ h
outtextxy(100,150,"吞吐量");
7 M" [- ]5 c3 H8 E' routtextxy(350,150,"平均周转时间");( [3 i0 ?0 ^. ~ H( E1 C% y) W
outtextxy(650,150,"平均等待时间"); L* I5 R8 o7 k) d; H0 `& S* D/ F
outtextxy(950,150,"CPU利用率");
$ V) s: m& ?% j9 e6 creturn 0;
4 t7 _) D' C6 h7 N- N) |0 W; D# d# w}
6 {. z7 Y$ ^& B1 b1 `9 v _8 Eint MouseListening(). p4 B3 k& B0 G
{
{& o; {7 Z* j D) ZMOUSEMSG p;
/ n H0 l) B) J' iif(MouseHit())3 n3 a4 J1 j0 t% u* x/ H
{7 {. h! f8 n4 U2 }1 Z& A. R0 @
p=GetMouseMsg();
# E4 D. V# P8 f. ?& @* Q. \if(p.mkLButton==true)2 E! b' F1 G O
{! v: y7 y, M2 X |1 M+ z7 l
if(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)9 T& W4 {% Q4 M3 x1 P
FLAG_FIFO = 1;: B) Q t: K; o0 ?
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)
3 B/ o- v" i7 \6 {/ I) KFLAG_TT = 1;% u8 x1 K. E5 W% Q8 t4 a9 w7 W
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)
" F! S' @5 U6 }. e0 Z# yFLAG_PF = 1;# M) W2 |4 C3 e2 R, p
else if(p.x>0 && p.y>325 && p.x<400 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
: D8 K7 z+ C& oFLAG_SJF = 1;$ a/ m6 \- i1 u' n" d1 m
else if(p.x>400 && p.y>325 && p.x<800 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
5 p+ W) O- P( `' n8 CFLAG_HR=1;+ ~! t" c8 p3 `
else if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)
1 z0 B- W2 l* L2 c* j8 p7 `" ?5 s{
. L: h% W! k- OFLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;+ P+ M5 q+ ~9 ?2 [7 m
clearrectangle(800,325,1200,650);
0 {4 @5 H+ ~' N4 g2 U0 @& \) D- j}! K8 J5 c- H5 |. x6 l& z/ h& p r
else if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )
* |5 K+ a7 H# u# c$ u) A5 o{
# ^& Y8 G2 z0 v+ kFLAG_show=0;. }. g, k7 E. P1 V) |0 m8 a7 w
cleardevice();9 v1 l2 O6 J y' g' E9 x7 c. g3 }
return 1;
+ W3 A0 Y1 P+ c2 g0 A @}
: D5 M, w+ R! C0 Z} h: ^) l! i, E$ |, }6 m, u$ E
}
% W, C) n/ a0 M4 `4 ~return 0;
: ~9 }" `8 S, v4 \! f}/ \! [% [! [$ q/ Q
int MouseListening2(int *flagShow,int * showTime)
) q7 C7 P8 l7 q% k{
8 y: t4 P0 ^& \" h, z' n, ]7 s2 \MOUSEMSG p;
0 A8 Y0 d. \7 k& Grectangle(1150,0,1200,50);
% `2 C& p: |$ z! u+ R2 m/ Mouttextxy(1160,10,"X");& n7 i* M/ d n# H$ W+ m
while(1)1 i" L5 Z) P) _; W) |* f% k
{7 N. X. X( | g& }# n1 I- n% Z& y
if(MouseHit())
8 p5 ^$ e* l( g{& h& y& S! |: z1 L* G8 ?
p=GetMouseMsg();
* H% s" x; _) T0 ~3 O, m* @4 lif(p.mkLButton==true)
$ _9 ]$ t+ H& t' D{6 w) J( V! b( j' V
if(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 )3 q' J( S. f P( \
{7 r' n' u: ]) [7 r ]1 N+ @
(*flagShow) = 0;$ g* Z. U( ^! Q% P$ i: T5 Z8 J
(*showTime) += (*showTime);
y) _& h0 g! E! HFLAG_show=1;2 q% T/ R+ @5 j: m; _
break;
+ K% n0 p" u) a- v' Z. h}
$ d9 S, {: A0 z% Y
4 s1 t- Q- e) ]! f9 h}! ~( ?8 g" g& z( Z: B% W
}" Z1 D9 I- c8 K, R. E
Sleep(20);6 [' \+ J/ G `2 \" F* O4 s* V
}! e( e7 E7 ^ K5 ~ a% [" b
cleardevice();2 s. n6 x- W. \3 p
return 0;0 m' x) W! d; B, j5 X% T7 W( v
}
6 E- L; E! U/ `2 Fint drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)( x& p3 f& C* p' m5 s
{% |0 c2 O2 {5 f3 q( v
static int info[11][3],num=0;
. d+ k4 O" a% o% Z# cint i=0,j=0,pos[10][3][2];
: K0 M$ a3 o- u' X$ vfloat temp,t;
$ N- Q* ~) X% Q$ ~# m7 m//画按钮,不属于FIFO图的范围
2 L4 @! Y! s) C4 v8 A2 _if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1)/ s( y, q8 I6 G; d/ h7 X% z6 c- c
{
, R& C8 L7 F$ @! I4 S9 ?* Hsettextstyle(30, 15, _T("楷体"));4 j N. t8 Y, E; C
rectangle(890,455,1110,510);
4 Y5 o+ [: Y' C, Jrectangle(900,465,1100,500);
- l3 X" R, C; ]( g3 z3 {2 Eouttextxy(910,468,"查看运行结果");
9 R M$ a4 l! B T}' q. b3 H6 g; o! h7 J
//结束画按钮
. k" v! @* G4 I7 U" P N0 winfo[num][0] = com;3 Z0 x9 g4 p) o0 l: r
info[num][1] = wai;
% w$ E9 t8 ~/ k, U! R" L5 |. ~info[num++][2] = cha;
# p3 Q8 ~( G" l! X% l2 a6 w) zif(num>10) //存储10个点
/ P+ a5 q- n6 s) D5 v6 a{
+ Q# G2 S: B. y! f- w( V9 gfor(i=0 ;i<10;i++) N7 x9 ~8 o5 I7 I0 X" }% Z+ H/ p# K9 U
{! f) o1 ? O2 z+ ?/ Q
info[0] = info[i+1][0];
+ G, ?# N A) ginfo[1] = info[i+1][1];
' X5 q. l! L. o( F2 e" U# G' e' Z. {$ qinfo[2] = info[i+1][2];
* H5 q \9 }4 z) t3 o: U}1 w5 [5 B) L L7 A3 R
num--;
. Z2 N) L* }" `7 v}7 L) |& P! K. I- ?, D; D% ]
if(FLAG_show==0)
3 W0 N( M6 s V8 T5 T4 ireturn 0;5 z7 p0 I3 T8 X
for(i=0; i<num; i++)) ]5 S; ?0 d$ M
{
7 u+ N* [* k9 P( N1 Z* \. ht = (float)info[0];
0 L0 f9 b( l9 v- s# _temp = (t/101)*90;- X; z1 C& M7 K& ?) U
pos[0][0] = (10-num+i)*25+x+100;9 g, Y& I+ O/ a" ^* P$ _4 @2 P' Q
pos[0][1] = y+110-(int)temp;- p: @( ~6 ]* U& E N& b/ c
t = (float)info[1];1 I% M" G% J: ~' t) m
temp = (t/101)*90;+ b3 E9 A: {# a( Z7 v1 M; H7 @* B
pos[1][0] = (10-num+i)*25+x+100;
. l1 u1 ~1 H8 y0 ~8 t; Apos[1][1] = y+210-(int)temp;
$ ~1 ^: [0 A" v" t4 et = (float)info[2];
- j! s7 h" a4 utemp = (t/101)*90;* `; B$ s/ B; K' F
pos[2][0] = (10-num+i)*25+x+100;
' V; b0 t0 @+ g! Y* Wpos[2][1] = y+310-(int)temp;
! j/ h1 k! O T: [5 P}; m" c: U% Y- W6 B) G
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)8 e( P- p" Y* T# l# o5 l1 W" i
{
% N& M9 N4 Z6 l5 u: i! Oclearrectangle(x,y,x+400,y+315);: e$ \6 E# a# d: d, t' L2 X
settextstyle(20, 10, _T("楷体"));8 q6 \# f4 Y8 ^' a0 a: b
rectangle(x,y,x+400,y+325);( P8 u/ Q; r6 U% f; r/ r' @9 s
outtextxy(x+40,y+10,"CPU"); //画柱状图& I3 P/ A7 V! Z1 X) ~2 W
outtextxy(x+45,y+10+100,"IO");
2 J& G/ Z8 X: f1 G1 |# mouttextxy(x+40-15,y+10+200,"change");% Y. J% L; H: S. ]6 e. ?
rectangle(x+35,y+30,x+75,y+110);
5 O$ c+ T! ~8 c' }' V; Krectangle(x+35,y+130,x+75,y+210);
$ A+ U. d/ ?3 }$ arectangle(x+35,y+230,x+75,y+310);. n( j$ Z- p7 @& U# \' y
outtextxy(x+180,y+310,"FCFS");1 l# B7 O9 q& Y2 R+ M. ~8 j
t = (float)com;
0 x/ j( c7 l; S; P/ ztemp=(t/101)*80;
/ [2 z' ^; }! r, w$ r) kfillrectangle(x+35,y+110-(int)temp,x+75,y+110);; C# m, @! W( Y) N/ \6 e
t = (float)wai; _% z5 L) [7 J- n; K4 a" g9 r
temp=(t/101)*80;
* y# l% w1 Z9 afillrectangle(x+35,y+210-(int)temp,x+75,y+210);
& a8 B. {$ G5 Y8 D' x) i% st = (float)cha;( S, n% r* B0 J0 j0 a3 T: K7 e
temp=(t/101)*80;9 h3 s$ P8 j: V* l$ b4 W' W& Z
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);! _2 b9 d1 X4 Y
for(i=0; i<3; i++) //画坐标 high=90,length=250
& J" g* z) _4 u% M) b r{
9 f4 O- m# f( j; q' Cline(x+100,y+110+100*i,x+350,y+110+100*i);' A& Z- C3 Y/ {+ T
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
s0 q- h" D- d/ h, O6 Q7 Y6 z gline(x+350,y+110+100*i,x+350-5,y+110+5+100*i); \) w2 t! l% n; u, X0 r+ ^
: G$ L( m! o7 b% ~# K2 @; Jline(x+100,y+110+100*i,x+100,y+20+100*i);5 }3 u; ]" l' @! p0 V
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);" {/ k) H% P* i! Z1 n
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i); n/ S0 k) ]1 F% J, Q
for(j=0;j<num-1;j++)$ L: i6 \$ k2 w \# t
{
& I/ n" H, _) a/ T1 C! l# @; d0 L0 U# ]line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);, N/ a/ d" ^4 i5 ]# V3 K+ @
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);( b7 b9 a0 D# J1 k
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 1 H0 u3 j# T- Z! j& C9 i) }
}) `5 j+ U6 J* ~3 E0 I
}
; c0 Q2 @- l8 s) o5 _/ L) c}
$ y, J: a* n& {2 M9 n& qelse if(FLAG_FIFO==1)
3 W( @7 `9 J6 H }& i; W{4 i3 F9 e1 N! O9 G% B( O
x=0,y=0;
* Y. s6 k* T' l8 T1 cfor(i=0; i<num; i++). a' ~2 Y' y" F! K2 Y# W/ o9 y0 \
{0 g/ X9 q% Y. N# G( @
t = (float)info[0]; G: H$ n" N( |% p
temp = (t/101)*180;
( f* A0 ~3 W' u( k( [9 `pos[0][0] = (10-num+i)*50+x+650;! m5 b8 `+ N, k
pos[0][1] = y+210-(int)temp;. G- m9 @4 o: D& h
t = (float)info[1];
$ k$ e& s5 V' k: s4 }temp = (t/101)*180;, ?5 ~9 C9 B3 [$ X
pos[1][0] = (10-num+i)*50+x+650;: M. }$ J2 n9 V; S* u
pos[1][1] = y+420-(int)temp;/ r: { @8 H6 o9 y
t = (float)info[2];
4 G( x, e) Z: htemp = (float)(t/101)*180;, q. Y! n/ [* ^1 S1 \+ x# A( `
pos[2][0] = (10-num+i)*50+x+650;& o/ l8 k2 ^1 ~
pos[2][1] = y+630-(int)temp;: Y, n1 U. v E; p0 p
}
6 {3 a$ c% c) S' m+ u4 ~& W3 K; J6 B8 Iclearrectangle(x,y,x+1200,y+650);
0 X2 s# Z( \2 X$ j! |5 O6 ysettextstyle(40, 20, _T("楷体"));: @5 Z( L3 B" N2 E
outtextxy(x+50,y+50,"FCFS");
4 H9 Q8 K! J. ^7 Routtextxy(x+280,y+20,"CPU"); //画柱状图, J( C! Y" g. o7 s" n/ F
outtextxy(x+285,y+20+200,"IO");
$ W4 }! Y5 H. Z& T3 j& X routtextxy(x+250,y+20+400,"change");
3 {( X' U- Y" y+ \4 S0 rrectangle(x+270,y+65,x+330,y+215);
: K) j( p. N2 g" j( \; o- vrectangle(x+270,y+265,x+330,y+415);
6 R0 u' M( d/ G, b0 p* [7 G3 `rectangle(x+270,y+465,x+330,y+615);8 J# m- U: T% h9 Y5 l
outtextxy(x+290,y+620,"TT");: z2 m4 m" k" ~) [, G4 m, {7 u
t = (float)com;
# {$ e) a0 g. e% ?/ W) R+ N+ ttemp=(t/101)*150;6 M0 p6 `% G6 z5 l% m0 n
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
* \4 x; h( I# X/ a) H" ` R& ~' At = (float)wai;9 F2 m2 F4 X. R" I
temp=(t/101)*150;
) a8 }& l$ M% ^fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
$ X. u1 N! b, l. R& U1 [t = (float)cha;
5 p/ ^4 ]/ d$ p1 e; I2 A7 ztemp=(t/101)*150;! A- @4 t" v) h1 |
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);1 O, }) U8 [0 r. u
for(i=0; i<3; i++) //画坐标 high=90,length=250+ h5 Y7 Z( e" G/ H$ Z3 M
{
1 W2 t) b/ u! _2 Hline(x+650,y+210+210*i,x+1150,y+210+210*i);: x8 |$ g/ b5 g
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
5 U# p0 l3 X! A' @) Z* |' ~8 Fline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
' U! K; I7 n# f* k( w0 L& p
1 |3 m: H% p! iline(x+650,y+210+210*i,x+650,y+20+210*i);) v4 C/ @0 E: g1 O" I* k. W1 c! r1 E
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);1 H( q' | a) |" k& D
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
R% h+ m. t# yfor(j=0;j<num-1;j++)6 U# ^2 {; b4 r" V+ M$ F
{1 s1 m' J: P. E4 \" D
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);/ A, ^3 M% D$ n
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);- R; O9 S$ y) n, L5 k7 \
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ! s m0 f k: U H
}
, p+ X1 r' ?- c( Z0 p9 ]: |, R}
Z" M: N) U5 I5 ?4 c, s; t6 r+ _}3 H8 I' k& H: a6 K) _6 g
: T# i: w0 X7 X! h1 x
# \" ~% I8 G! B! L. m1 f4 Zreturn 0;
; _, k9 v% w( a, C! I( s}
; B8 [/ F- z0 g% I- \& Rint drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)
1 ~) z2 I. h9 M# W- W) b% P{% m8 [, A; V3 o$ {4 L; A
static int info[11][3],num=0;
6 _* c/ C- k' n5 h2 O# zint i=0,j=0,pos[10][3][2];
+ P$ ?' f# z8 p0 dfloat temp,t;- F( r+ d1 k8 ^9 O5 k9 c, U
info[num][0] = com;( s% m+ M$ T% a/ d0 O8 ?7 {! `
info[num][1] = wai;
9 X) |) W& Z' z- p7 e7 i( W) D! Tinfo[num++][2] = cha;% _- b% {" P# m9 a* a _7 {
if(num>10) //存储10个点( K" |9 H$ [5 y% w8 T* Z9 l( N
{9 b% f: R6 e% q* \, v4 J
for(i=0 ;i<10;i++)7 ~6 ]6 x" D( y! _ Q2 J! e0 x
{
: Y% ]0 \) P/ b- Y$ _; tinfo[0] = info[i+1][0];( S) j" ~% R- k/ K1 Y6 b+ c
info[1] = info[i+1][1];
" {/ ?) U6 `4 Y( {# |6 _2 n4 h: h& N3 T" binfo[2] = info[i+1][2];" j% h6 P1 q7 z( }3 v
}( q6 E* G7 v# T4 ~
num--;
( H, ?1 N& y6 J; R# O}5 ^# h" Z4 c9 n8 X; E+ g8 R
if(FLAG_show==0)+ F1 ?* t+ k- D' Y
return 0;1 u [3 R/ j8 X/ b% P9 _/ Q
for(i=0; i<num; i++)& ?8 D! k4 z4 {. e& O- t2 R
{* ^+ T. [$ J7 H3 Q
t = (float)info[0];
1 i! _" e2 d# D4 R' _7 dtemp = (t/101)*90;
# U& f5 p9 P4 _1 P5 q. t& Fpos[0][0] = (10-num+i)*25+x+100;
: P! _* m1 z% y* y: rpos[0][1] = y+110-(int)temp;8 m# A. B0 Q" A3 `
t = (float)info[1];
5 v* N* s, ^( ]# I% Y. ^/ Atemp = (t/101)*90;
& M( p1 x2 i9 d, S0 ~7 tpos[1][0] = (10-num+i)*25+x+100; e# D* Z0 n, b: ~3 ~: [
pos[1][1] = y+210-(int)temp;5 Q F3 b8 U6 f( V! K" L
t = (float)info[2];
4 }0 g" W7 q% b) M- i8 H3 Htemp = (float)(t/101)*90;
/ H+ `3 p% d! K1 U0 J- [$ ]9 cpos[2][0] = (10-num+i)*25+x+100;# J" V/ B g" F# y- [) t* c; s
pos[2][1] = y+310-(int)temp;
) d- z4 Y) u3 g}* Y8 Q7 s! W4 W, o& n! m
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
8 @8 L4 B8 o8 I& f8 w- M{# C5 g5 {7 f/ o6 T" d' F
clearrectangle(x,y,x+400,y+315);, _' k1 I% b! {3 ^4 y" I& ]2 i8 Z
settextstyle(20, 10, _T("楷体"));0 ~9 B. u: ~+ T$ c I+ O
rectangle(x,y,x+400,y+325);5 [+ x4 w5 A# ?5 @! F; _% ~
outtextxy(x+40,y+10,"CPU"); //画柱状图/ H4 O: Z8 L+ G- d' m7 u
outtextxy(x+45,y+10+100,"IO");
2 ]& p0 N9 _; ]" B; youttextxy(x+40-15,y+10+200,"change");- E$ m, G; Q9 N( v# S" e
rectangle(x+35,y+30,x+75,y+110);
* l8 D5 C) q8 s5 e6 ^; |rectangle(x+35,y+130,x+75,y+210);/ l% l" c5 [/ D! U+ h: e4 @
rectangle(x+35,y+230,x+75,y+310);4 v, J& D' ^& s0 i4 h: M
outtextxy(x+180,y+310,"HR");5 W! f T* D1 m& V; l' g$ K7 | A
t = (float)com;
* W3 G1 E& T+ @, `5 ttemp=(t/101)*80;$ n+ F% H7 J% U1 K
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);9 m- w4 g) x+ n% X$ W* u
t = (float)wai;, s* i5 `: T8 j
temp=(t/101)*80;6 D% R3 v5 m" i- M% v; w. R; a
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);& u2 ^4 [& {1 }1 g3 L
t = (float)cha;9 ~7 D W' z4 m$ C& e1 S7 d
temp=(t/101)*80;) n5 t( M1 |1 M6 ~9 V0 V: {
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
7 b H7 @" a7 F- j! M( L9 @for(i=0; i<3; i++) //画坐标 high=90,length=250
5 e$ e" T2 w4 f{
! v* B; o3 m( i# p- tline(x+100,y+110+100*i,x+350,y+110+100*i);
4 Z* s: v& c# n' `+ lline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);' N; o5 N" v F% ~6 ~" d2 K
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);" b' U% A6 l) X7 C
0 X) B7 @7 k8 C/ `+ uline(x+100,y+110+100*i,x+100,y+20+100*i);& Q( T% j/ i! s. t3 x/ G
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
$ K4 Y2 |9 |# _8 {/ Mline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
7 {; P: n" Y9 H, Hfor(j=0;j<num-1;j++)
7 _0 ~. }7 g- o7 m3 X* C7 Q{: b& s0 B' J R% X
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
3 a7 A1 ]4 v3 x( j: q) w7 f% ?line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
+ F9 p9 q2 s7 ~- W7 uline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
* `' d, }5 m# r6 g/ t6 G0 ^}& Z" _) E- b% _
}
. a: R) E4 h6 V2 n( t0 y8 ], \}, Q' \" P3 Q" Z! C( k/ g
else if(FLAG_HR==1)% D( {6 X7 f: P! J7 \- s
{5 Q+ c) Y2 T) u8 J
x=0,y=0;' d4 e& d+ h% p
for(i=0; i<num; i++)
, o1 g& F2 `3 k0 R U2 @+ g{
0 d: P# l y) a1 m- rt = (float)info[0];/ Z8 u. p4 J/ {8 ?( b- [1 F2 n
temp = (t/101)*180;8 p/ g! S3 X W4 b
pos[0][0] = (10-num+i)*50+x+650;% s6 x. @$ b' M0 q% {$ j l: w( x
pos[0][1] = y+210-(int)temp;
( p2 a3 y7 K& A- u# f7 t% Xt = (float)info[1];! c; `1 Y+ x/ \7 ^; e# h
temp = (t/101)*180;
a- e; n) p- A) c6 y5 R' r' k* c6 s% ~pos[1][0] = (10-num+i)*50+x+650;7 @: z1 ~/ } U$ {& z3 h
pos[1][1] = y+420-(int)temp;
! c$ L& |: Z# d5 l/ X zt = (float)info[2];" c1 n1 A7 d$ n
temp = (float)(t/101)*180;
' ~0 f* J/ }& W# T7 b- }9 G1 opos[2][0] = (10-num+i)*50+x+650;
6 [4 a& I5 e3 opos[2][1] = y+630-(int)temp;
" s: t+ Y, ]& w* l8 z' l+ ^! T}
$ \' x- ?% ]! D1 B2 o7 u. Hclearrectangle(x,y,x+1200,y+650);
+ g+ W9 G! ] ]& y! }3 z1 psettextstyle(40, 20, _T("楷体"));
; ^7 j7 U' @: d; L* f0 K" v& _outtextxy(x+50,y+50,"HR");
% w: M/ C- V. q5 s: V4 Douttextxy(x+280,y+20,"CPU"); //画柱状图
0 j6 e) J1 J) C' v( P) {outtextxy(x+285,y+20+200,"IO");4 Y* K$ V; k+ {* G
outtextxy(x+250,y+20+400,"change");
& X* i( e. N( Wrectangle(x+270,y+65,x+330,y+215); s( s9 v8 \) X8 @9 k
rectangle(x+270,y+265,x+330,y+415);
. e3 d. T2 {% Frectangle(x+270,y+465,x+330,y+615);
7 _! P8 P2 {# _. |% Gouttextxy(x+290,y+620,"TT");
. Q" ]6 R! X7 ?" Kt = (float)com;: z* d( Y! J) t
temp=(t/101)*150;3 N8 x) g& F( n" X$ S9 g
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);+ w' T( Y5 X- D7 D
t = (float)wai;
/ P% ] `7 z2 ftemp=(t/101)*150;
! [! n& E' ?: q/ F3 b8 O% p) efillrectangle(x+270,y+415-(int)temp,x+330,y+415);
' D5 y. p0 \9 ]0 Z7 N7 Z8 Jt = (float)cha;2 O& v5 L8 A9 B: l
temp=(t/101)*150;) C) s+ u( i% o$ c+ a, w' R+ L
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);8 u6 ?2 e; a* y
for(i=0; i<3; i++) //画坐标 high=90,length=250
8 f9 ?7 e$ O5 J; _ n& _8 s7 E{5 r' d$ U$ e- Y: M& v
line(x+650,y+210+210*i,x+1150,y+210+210*i);
3 x6 m. q, G: `4 ?line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);5 a( M2 w7 o! |- N
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);' x$ e8 f5 y( F+ B' e
# z9 d4 W2 _9 l, x9 \! s* C
line(x+650,y+210+210*i,x+650,y+20+210*i);5 f; S4 S6 x- i9 c7 L
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);* m7 [# g @( K6 Q5 h( i
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);) Z7 c1 @* f7 i {6 h: f* B. G
for(j=0;j<num-1;j++)
9 i9 ]4 V8 C" Y" M1 q! r( ~* k$ g{% a8 I* Q8 W5 n) d$ q
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);# p1 E/ s; g0 W/ V2 m- ~3 z
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
, V! J8 k6 E9 G1 y& [line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); / Q9 M. G1 Y+ P( w
}$ v" W0 Y1 x z {
}
9 A+ r' g; y( B4 R% A}
+ g/ d9 h4 k% r0 g) Q; P! }0 ]
; j" Y7 k( q3 D0 c0 q+ T& l2 b
C2 ^, }% H l8 b p$ ireturn 0;
( P( W& A9 G7 M1 o}
. R" ?: s$ Y2 J6 [int drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)
( Y& E: T& X7 C$ ]+ a{& {5 ^8 P' X! r4 X' A! C Q
static int info[11][3],num=0;
# H' a k4 ]; O' u Cint i=0,j=0,pos[10][3][2];
- n5 I( d& \/ ?0 Z9 \float temp,t;' I3 u8 C+ l5 N$ C% i" {
info[num][0] = com;
* V9 g9 s2 m$ M; v Xinfo[num][1] = wai;
# B$ ~8 t% i+ Y* v1 {. Xinfo[num++][2] = cha;
) P& G" S; C5 Cif(num>10) //存储10个点
2 `. z) M& I4 y1 M& X5 c% ^) W: S% Z{
' C1 Q0 ]7 A( F( S, yfor(i=0 ;i<10;i++)
# ~) b7 A+ B- v7 ~2 K/ b{
/ w; } e/ G! r& ~* z5 x5 t: @$ I; winfo[0] = info[i+1][0];( _! a* A' i& N* X6 @. u
info[1] = info[i+1][1];% }4 \2 c- ?7 R+ \ z
info[2] = info[i+1][2];) Y H) N& s- C* t; U9 O. L
} v* ^. t- _( R4 J
num--;, d# D4 _8 F! e
}5 e) E" f O" C
if(FLAG_show==0)8 }0 q/ w! C- Z' @+ i1 D. X
return 0;& E4 `. S1 t8 C( W
for(i=0; i<num; i++)1 Q. q2 q0 l7 c1 T
{
4 w2 J; i) u8 t1 V' W" |/ kt = (float)info[0];
9 ]4 {2 u' c6 |% R! X, ?temp = (t/101)*90;% T Z7 ~% {$ [
pos[0][0] = (10-num+i)*25+x+100;
6 a5 B) R/ ^8 _6 m8 p8 P spos[0][1] = y+110-(int)temp;( E5 g$ M5 {" u6 j
t = (float)info[1];
/ o6 \' X9 G5 c6 h3 }1 y% Gtemp = (t/101)*90;
( ~8 D- x" C& g! M; q: |( E5 v* e6 Jpos[1][0] = (10-num+i)*25+x+100;% ?6 u% {8 e: W @) t# s
pos[1][1] = y+210-(int)temp;
Q0 c: ^. S. e5 `/ Kt = (float)info[2];
+ @( o# L- b8 mtemp = (float)(t/101)*90;
0 K* ?6 @) U& ^+ hpos[2][0] = (10-num+i)*25+x+100;# \0 L3 [" x/ b9 G% P! }; e
pos[2][1] = y+310-(int)temp;
% C- I# g- |" F7 w+ @" g2 R* z}
/ K2 I5 _" u' H2 G" sif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)( H& s6 k. v7 _9 a. \% p
{
4 c; ~% d8 T& wclearrectangle(x,y,x+400,y+315);
4 k. ~" D+ l9 ksettextstyle(20, 10, _T("楷体"));
% U; w; f% w$ T1 [1 prectangle(x,y,x+400,y+325);6 s& Z, i$ k4 y N) W \2 V$ U
outtextxy(x+40,y+10,"CPU"); //画柱状图
# `. u% a7 {/ l! K8 i3 {0 {5 mouttextxy(x+45,y+10+100,"IO");
. [- E+ S. x' v: louttextxy(x+40-15,y+10+200,"change");- ]9 x. s& q; L+ s Q9 r
rectangle(x+35,y+30,x+75,y+110);1 Q8 a( `/ ~* M' u4 K) b" h( n) `
rectangle(x+35,y+130,x+75,y+210);2 {! H" z4 b2 R
rectangle(x+35,y+230,x+75,y+310);
& @5 N6 s) D( j$ Z" Y% P! Fouttextxy(x+180,y+310,"TT");
2 u2 Q" j, j" J" I/ R( F2 p( m5 n- yt = (float)com;2 g: e X7 v$ ~ e+ D, a% A
temp=(t/101)*80;
3 y7 c3 ]! L( ]5 u% ~( t, gfillrectangle(x+35,y+110-(int)temp,x+75,y+110);% E, H# }8 i3 @9 G% D
t = (float)wai;
6 r1 a& l. d' g9 Wtemp=(t/101)*80;
6 d- w% h" T, Pfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
% I2 Z( b# l8 it = (float)cha;0 j ]/ ?4 F% r) V
temp=(t/101)*80;7 y: g! H0 _, ~8 |+ t7 V' q
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
; O7 R7 C, ^" i+ K+ F) `% _for(i=0; i<3; i++) //画坐标 high=90,length=250
) L) w" m# y$ u/ B{
0 m+ V9 s% C- ^line(x+100,y+110+100*i,x+350,y+110+100*i);2 u* u+ P1 X+ }6 L
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
1 M9 X0 T1 L# ]1 Y1 oline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
* [; {- Y6 Q _0 i) J$ z. c/ x1 x& p
line(x+100,y+110+100*i,x+100,y+20+100*i);% W; o3 |! K5 E- B4 j
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
/ ?1 `$ n) G9 v% B& B! D' P5 ^line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);8 {2 Q; p( k% y1 Z0 Z0 c
for(j=0;j<num-1;j++)
- N4 y1 T" h4 \9 m& T; B{# ~" ^0 [5 Z r" w* M9 P
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);, d( B1 C F+ p! q/ h8 A# p' W" X
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);2 a7 \+ E9 U% A$ U
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); X& y8 z- k$ n5 K& b
}
7 h' k, _3 M& a o0 k4 o}+ y0 P2 r2 [# E
}
/ _2 n+ C3 {5 d4 V& pelse if(FLAG_TT==1)
+ Y8 |. d% k& ?" m7 i{) Q( f S9 V7 K% i4 w, G
x=0,y=0;
9 {4 y, e) `! M9 ?! _& ]: Tfor(i=0; i<num; i++)
1 f4 {/ {% i% S/ h3 T{
" {( G A; D0 q4 j- E% t4 e( At = (float)info[0];
, M5 _& a% D9 q! f+ {$ |temp = (t/101)*180;- G, d" C+ u4 b3 z% G
pos[0][0] = (10-num+i)*50+x+650;
* X2 y( a% a5 X4 W# apos[0][1] = y+210-(int)temp;
! j: V. W: R- }2 [$ Y' G6 M, [5 `t = (float)info[1];5 ]' C1 n2 @) _8 X$ x; T( d
temp = (t/101)*180;
, [3 c% d6 l. F6 ipos[1][0] = (10-num+i)*50+x+650;
9 n3 B7 x1 }+ Xpos[1][1] = y+420-(int)temp;
, {5 e: d/ d' F2 T- z) Rt = (float)info[2];) d2 {: [" G! K& V6 p( O N2 _0 D" [
temp = (float)(t/101)*180;+ `; E1 j( c# \7 y
pos[2][0] = (10-num+i)*50+x+650;( |3 j+ V! Q# I# R
pos[2][1] = y+630-(int)temp;
& k5 v3 ^) z; c3 H. x; a! j}4 N7 S1 |6 g. _3 U
clearrectangle(x,y,x+1200,y+650);
t6 }) s4 }! y- @2 vsettextstyle(40, 20, _T("楷体"));
/ ~, ?( {. w3 x1 H/ p# touttextxy(x+50,y+50,"TT");) ~2 F E. e# u4 V( s+ V. X
outtextxy(x+280,y+20,"CPU"); //画柱状图
; q, l3 A# K' S3 N0 k aouttextxy(x+285,y+20+200,"IO");
; u$ x+ z& f& n# ^, O1 k" g- f$ ?" touttextxy(x+250,y+20+400,"change");. S: c3 P: _0 {+ _* t/ {: x( p8 [
rectangle(x+270,y+65,x+330,y+215);
6 R$ a( @/ N6 b" C- }- Irectangle(x+270,y+265,x+330,y+415);
6 n# v9 v' ?; `9 f8 ]rectangle(x+270,y+465,x+330,y+615);5 w1 P+ b6 T. E* \/ S
outtextxy(x+290,y+620,"TT");! T9 l& h8 J" X% e: K
t = (float)com;7 i% Q1 K9 Y+ P( e- y
temp=(t/101)*150;
6 x! P, _0 n% T+ Rfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
* f6 o% v( o4 T0 Xt = (float)wai;2 @+ f; @3 ]" C4 q* W# {* A
temp=(t/101)*150;
- K; v/ j/ D3 \2 N) b9 bfillrectangle(x+270,y+415-(int)temp,x+330,y+415);
+ }8 N: ]4 U6 d& b7 D( l4 et = (float)cha;+ E' _$ }/ G* F q9 n
temp=(t/101)*150;
. j! I/ T4 j3 C* {fillrectangle(x+270,y+615-(int)temp,x+330,y+615);4 p% R. U0 _/ k2 p$ x
for(i=0; i<3; i++) //画坐标 high=90,length=250$ P4 m) D. T: w) t7 I6 s, z
{# r! N( c8 x. C. V2 n
line(x+650,y+210+210*i,x+1150,y+210+210*i);
& ~( a* V: ?" E rline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);8 p& x# j, v( D4 L9 C: N( b7 k
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);/ L$ J- c. f& u* }+ p' E& v
; y, U, V( e2 dline(x+650,y+210+210*i,x+650,y+20+210*i); k6 [$ j) H7 L
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
. r' \( p2 ~, @! q) w: p1 }- |line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);+ S; S% w8 p6 z7 h; c
for(j=0;j<num-1;j++)
; k0 X1 `, Q9 f$ C{ t% S; _' Y& |- K4 @( n
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
" Z( Z0 E, _' V' M# M9 S$ b2 Fline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
7 \: d5 R9 b$ R W y$ ]line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); + y/ T$ [* c- U1 \( b
}
7 e6 K: j' G, {; Z; h}, p" j0 k S4 x3 \1 ?
}
: C% q- m/ A, W( e. R4 ^9 ^) y+ V r9 f
1 C5 C( @$ ]) Q: @
return 0;
, B6 b2 r3 i4 ]! f. f# ~}
3 J3 u& @; t% Hint drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)+ E4 @9 l% F# N! Z. ?9 V1 t, y
{2 @! {' J% u; f& ?; S& `! m' h4 t
static int info[11][3],num=0;4 w/ G2 D- k4 D6 C7 l9 R/ u% a
int i=0,j=0,pos[10][3][2];+ o, K+ S# X; V# v
float temp,t;$ |- N0 a3 o. A) u
info[num][0] = com;' J$ N6 U" W2 \. I! L3 M) E
info[num][1] = wai;5 Y9 g/ ^0 ^) }/ @8 w8 D
info[num++][2] = cha;
7 }- @( m0 {1 w: Zif(num>10) //存储10个点4 ?( g* ?; [: i& O- z
{6 q" O& h2 j0 z+ V- o
for(i=0 ;i<10;i++)# ~( L+ {$ p5 k# q0 E
{
4 Q9 G& N( N) m) Xinfo[0] = info[i+1][0];
! E2 K( g8 `* p6 f% j6 Zinfo[1] = info[i+1][1];# K% Y* T! g @. Z" G
info[2] = info[i+1][2];
B% E. ]3 e! N" E}. H; O# @ l, S# z% b; H
num--;, D' `1 X5 P, g+ X/ B# G$ w
}. s' d' F* B9 f- H
if(FLAG_show==0)
* Y+ D, }2 [4 `+ x& S" _return 0;
0 X# U O+ i0 `/ C6 {" mfor(i=0; i<num; i++)
: C; ^2 r6 {+ m{7 g7 ^* v) v) [5 _9 `8 i6 w
t = (float)info[0];9 V- ]# W9 G) y- z: T* U6 o
temp = (t/101)*90;3 @& @% P- \6 t+ _6 F; {
pos[0][0] = (10-num+i)*25+x+100;
! ~; ~& y/ u0 _( E- P" ?pos[0][1] = y+110-(int)temp;* ]- N6 E5 J' _- _ g3 t# T
t = (float)info[1];
% R* z& j) D$ M: Jtemp = (t/101)*90;
$ g$ d t: P3 T* N; T( vpos[1][0] = (10-num+i)*25+x+100;9 N8 @4 R7 q" F5 R$ L: B
pos[1][1] = y+210-(int)temp;/ S4 z5 o/ {- J& b2 ^- o0 U
t = (float)info[2];
. f9 @/ |5 C: K) c3 ~% m( ptemp = (float)(t/101)*90;. l8 V; N' \& E& t1 q* J
pos[2][0] = (10-num+i)*25+x+100;, q1 V- u" r8 X
pos[2][1] = y+310-(int)temp;
7 H5 Z2 G3 v$ \- o' ^4 h}/ L. s, _, h/ g9 b
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
9 D5 r* C3 \+ I2 J/ Q# ?' m/ i{; h$ z% @, Y, ?' _3 M8 w
clearrectangle(x,y,x+400,y+315);
* r2 q" M& ?+ P5 J) e& M) Msettextstyle(20, 10, _T("楷体"));
4 H s, W: v. L* O* s) S2 Trectangle(x,y,x+400,y+325);
* H8 ^7 m& S! D, l8 X1 eouttextxy(x+40,y+10,"CPU"); //画柱状图; g0 }" Q" k0 j, I- h- H; B
outtextxy(x+45,y+10+100,"IO");/ w' N) h2 x4 k" `' o8 f" n' z7 H/ i6 U
outtextxy(x+40-15,y+10+200,"change");! p0 u2 x; {$ i2 A+ k7 N- W
rectangle(x+35,y+30,x+75,y+110);
4 Q8 Z& ^( L' m. erectangle(x+35,y+130,x+75,y+210);0 t1 G( M" C# j* m0 T5 t' R! H7 K( X2 M
rectangle(x+35,y+230,x+75,y+310);' V+ z0 K8 |2 ^ {
outtextxy(x+180,y+310,"PF");
% i6 V9 ~ l S1 Ut = (float)com; a& s# G' y6 C: i c
temp=(t/101)*80;0 I5 H8 S0 A% M7 B' ^0 m
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);5 R! W: w: J: i5 f# q& a- h
t = (float)wai;! F* o8 w @ l- h
temp=(t/101)*80;
/ [: h1 v, ]) xfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
1 q# d7 u4 N: v1 T3 W7 ^/ ]6 w4 w' st = (float)cha;
% n9 b: L, T' }# S h. l F% k/ etemp=(t/101)*80;
) c& S6 b! C8 t9 Y6 [ Mfillrectangle(x+35,y+310-(int)temp,x+75,y+310);$ a# u y# a2 a8 l1 x2 `
for(i=0; i<3; i++) //画坐标 high=90,length=250& I P& a. \1 M% C
{
+ S. [ P2 ?; \line(x+100,y+110+100*i,x+350,y+110+100*i);( [2 I* S% t) r7 ~, @
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);" N+ h0 `* t. a K" Q I
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);6 g; _1 Q. p0 ^
3 q9 q4 [6 J! U
line(x+100,y+110+100*i,x+100,y+20+100*i);8 G8 P) G) w1 j2 ~2 I8 ]
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
$ g8 j- `5 R8 \% K/ `7 Jline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
0 a6 ?4 e+ r$ _4 J5 x4 W/ @for(j=0;j<num-1;j++)
$ `: p, }. g$ u, m3 ^1 ?* M{$ M5 K9 S% q6 l: H$ z4 w
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
# h& I9 k% \/ B; eline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);; J- s: m" Q: M; u
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
7 b3 A8 q5 |+ p- h}
% Y( ^4 P+ h# r$ k- T}
+ n& r1 B/ o$ u}
4 f* j% s5 R6 J( H% telse if(FLAG_PF==1)
S) l* h, R a6 V9 k7 I{7 D' p9 p8 Z' I$ n! i
x=0,y=0;3 O% e' E6 \( \: F8 j; P% c. J
for(i=0; i<num; i++)9 `7 T6 z4 D) q" Y4 d( C8 S
{/ j0 U# l+ Q# G& S& u6 ^, F
t = (float)info[0];
2 x" ~9 X, a$ ~2 X2 jtemp = (t/101)*180;$ w/ t- @4 g6 K: W
pos[0][0] = (10-num+i)*50+x+650;$ u. V; J+ _" ^
pos[0][1] = y+210-(int)temp;
2 Y& z" S F! Ct = (float)info[1];
( m. H5 ]. N6 _# \) `$ {& M* k$ gtemp = (t/101)*180;
2 v9 o- ?2 z3 ~, Z hpos[1][0] = (10-num+i)*50+x+650;
- q$ {; {1 Q' y6 J# Upos[1][1] = y+420-(int)temp;
3 O" Z% U& L Y+ r# ?6 Ut = (float)info[2];
" e! l! w/ _& w% C2 N( o, y3 j& ftemp = (float)(t/101)*180; ]7 m" ~4 @5 I U+ u6 {! W8 \* e
pos[2][0] = (10-num+i)*50+x+650;6 j0 |; B6 O% }
pos[2][1] = y+630-(int)temp;: E5 N7 V' l8 _7 H) m5 d2 B
}
* Y8 P: ?; h/ N, K$ Y! g( x! {2 ]clearrectangle(x,y,x+1200,y+650);
! f0 H- ~+ i+ R' u; esettextstyle(40, 20, _T("楷体"));! h, H4 [! R; B% j- n# O
outtextxy(x+50,y+50,"PF");: T/ U4 |! m- v/ e" R
outtextxy(x+280,y+20,"CPU"); //画柱状图
; ~7 t1 x9 l8 ~ X3 m+ routtextxy(x+285,y+20+200,"IO");; P8 a2 B& i; i; d+ e# ?& I7 }
outtextxy(x+250,y+20+400,"change");2 H4 |) c, ]% i2 G
rectangle(x+270,y+65,x+330,y+215);
0 y- k. K# I" s2 d8 X/ frectangle(x+270,y+265,x+330,y+415);
8 T8 Z! _: j, Q+ m+ nrectangle(x+270,y+465,x+330,y+615);( { O# h* k7 _. C# h" D
outtextxy(x+290,y+620,"TT");
6 Q, f/ C2 {- y! rt = (float)com;
7 h. ^$ k( u2 n" V! t' \temp=(t/101)*150;
" Q8 p1 g$ F* z0 Z) vfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
) R0 \! _' }! ~2 f rt = (float)wai;8 V9 T" j2 m4 I/ _; `: g
temp=(t/101)*150;
+ D0 n9 f! w$ efillrectangle(x+270,y+415-(int)temp,x+330,y+415);
b! l: A0 ?! h2 e u& Z) G) h/ et = (float)cha; L) ?, }& ]1 Z
temp=(t/101)*150;" h6 m( ~$ U6 ]% {+ ?
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);9 |! d7 x5 N# \' u! ^$ z) |
for(i=0; i<3; i++) //画坐标 high=90,length=250
4 S8 {6 z$ U8 [0 Y: Z) h{
5 l f( U* E, ]! F8 rline(x+650,y+210+210*i,x+1150,y+210+210*i);
$ @+ u _# E& l% m, z v6 Aline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);3 y ~, M) X( ~
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
- S# M8 W9 t- y; f! f& e
, D' G$ U& f/ ~line(x+650,y+210+210*i,x+650,y+20+210*i);$ t* @1 G! h; K1 c
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
9 Z r* Y Y+ O' R- [5 lline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
5 d* d8 j) Y: r' q6 {( U4 `for(j=0;j<num-1;j++)9 v6 H( U) C' z# E$ L
{! x- ]# B/ O4 W: |
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
% p" a' A; Q! M0 fline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);- W' i$ l) M: N1 F* S2 ] Q
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 0 F8 C( O/ w( D7 R
}& C9 P! H s7 p" J
}
/ O! N; A! j% u: Z: }1 C& B7 L/ J}
* ?7 w# E u4 Y2 dreturn 0;
: r% Q0 |7 x/ r. d5 j! @}
: O6 y/ t0 M. Jint drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)
& x* o* G* K8 ], Y9 O{. o( e; [' u1 J+ b7 b
static int info[11][3],num=0;+ Q/ Q: X, u4 c: e: `1 N1 z
int i=0,j=0,pos[10][3][2];
`8 ~+ @& H0 O$ U$ \7 x: q- M' {float temp,t;
9 N; p! c" W3 B7 V3 O) ]" b: l' hinfo[num][0] = com;
0 N; w" g% D( S- Rinfo[num][1] = wai;
1 y% Z1 Z# @) ^2 }$ jinfo[num++][2] = cha;
9 V% j6 s5 g( P% Q7 C' ^if(num>10) //存储10个点8 f0 `9 u7 ], K3 @! F/ G) @) S; s
{3 G9 K$ i9 B7 e& \: P8 `
for(i=0 ;i<10;i++). w4 p5 U- Z% O8 j1 F" \0 B9 r
{
5 E8 u U, L: \. ~- Tinfo[0] = info[i+1][0];
7 F) |( q0 O) \- T/ iinfo[1] = info[i+1][1];% q* K+ \3 d: H" V3 w
info[2] = info[i+1][2];4 ? a+ ], h) k( \9 c" O' Y
}
3 W* D8 ]9 E6 m x. rnum--;
9 Q& B+ Q' n* H- o}
- T. h6 ^/ B8 z8 M' ~; xif(FLAG_show==0) ~1 B5 R s& ?
return 0;
& @( V* E2 P; y" y8 tfor(i=0; i<num; i++)' t% G5 K1 p+ V/ i1 o! |
{
3 G% ` r: O. d) ?8 ~2 rt = (float)info[0];
7 q' I" R+ ^4 p% \temp = (t/101)*90;: e$ }; g9 a% L
pos[0][0] = (10-num+i)*25+x+100;
6 }4 W* G4 a) W1 npos[0][1] = y+110-(int)temp;
4 Z( e! t* a U3 ht = (float)info[1];& E, p5 { `0 |& Z! `
temp = (t/101)*90;
$ s C4 L; Z! Q9 z! R# Epos[1][0] = (10-num+i)*25+x+100;
; @2 z6 J+ C! }; V: Z5 Hpos[1][1] = y+210-(int)temp;
% O1 ^% R% S/ G/ Ut = (float)info[2];
$ S+ N# W! [" t& c% Etemp = (float)(t/101)*90;
( P0 y O& w9 t [+ j' Opos[2][0] = (10-num+i)*25+x+100;' W" \8 F1 \& M3 q
pos[2][1] = y+310-(int)temp;
. {2 u7 _7 E, l7 \+ e}
8 G/ ]9 j$ [% g' B" v" hif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
M$ ]' y( H9 g{ 7 }) i) u7 H. S
clearrectangle(x,y,x+400,y+315);
. m6 R1 J6 G+ o2 q9 h8 `( |' Bsettextstyle(20, 10, _T("楷体"));
- y5 p, X7 J& ?: F! ?& W+ grectangle(x,y,x+400,y+325);/ D6 q) ], i: ? L; B
outtextxy(x+40,y+10,"CPU"); //画柱状图
! r: W; R5 m/ q" {* O/ o; W7 Oouttextxy(x+45,y+10+100,"IO");# B$ _/ E6 e: T. f' u: B
outtextxy(x+40-15,y+10+200,"change");
! R p& O5 B$ J, i; Xrectangle(x+35,y+30,x+75,y+110);& h. u0 _" T4 O- K
rectangle(x+35,y+130,x+75,y+210);% `: V- Y0 f, j$ W( s6 D. }7 C
rectangle(x+35,y+230,x+75,y+310);
! m8 M, L0 {+ w: ?7 G; Aouttextxy(x+180,y+310,"SJF");
( F3 }+ e+ X" P/ _" h. R: ct = (float)com;4 ~( d" ^2 c3 W
temp=(t/101)*80;+ W" X# K( }) `& c G4 ?& P
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);& U) Q3 A. |8 J9 }# d
t = (float)wai;
: m! f, X6 l( ]& A' e! ?temp=(t/101)*80;
v" d4 @+ ?: T% Ffillrectangle(x+35,y+210-(int)temp,x+75,y+210);
# `0 ~9 Q/ l' S7 j5 F [4 [t = (float)cha;+ M' I* |, h6 W( [1 o
temp=(t/101)*80;7 ]% d3 }: ?1 ^+ y' z2 ~6 n/ s
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
( D; S/ l" v1 n1 i8 O8 k: j' H) `for(i=0; i<3; i++) //画坐标 high=90,length=250
. m/ Z) r$ }/ _1 x7 q{
. @; h# z8 M# J3 c+ ]4 {line(x+100,y+110+100*i,x+350,y+110+100*i);0 l- i$ z" P# b" U- k1 w
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);- A9 Q; |! w. ?( n6 U6 a l0 w2 ]
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);% I9 \- D+ B* Y' H' V! T
- y1 E- J v7 I1 Xline(x+100,y+110+100*i,x+100,y+20+100*i);# i6 R5 f3 f; O& l
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);- e. B1 ~1 W: r, Z& N
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
$ m7 g5 ?0 f3 P/ K; ?4 s" G- ], }- zfor(j=0;j<num-1;j++)8 y7 K9 W$ r1 H Y: h" n! m
{8 W6 Y1 Q* A8 Y p* d
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);( t$ s P; m1 y9 J
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);# D, v; h1 f# \8 p
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
s0 z( n) {& d* q E* c5 n2 i% \3 B}+ D/ D! M$ p! J0 X/ X+ Y# m" T
}
7 G" h. t; Y0 f+ T4 X% a+ Z}
7 k% h, e. }, d! \else if(FLAG_SJF==1)7 J! c! d/ k$ H+ O n+ t
{6 r" i6 v' l; h+ [, E+ i0 O1 q
x=0,y=0;
% y9 ~8 W2 v" ~) a1 i4 pfor(i=0; i<num; i++)
. j" Z) |: t+ c9 S) t V{
) r7 I5 I8 a4 P2 Vt = (float)info[0];
" F/ i) _6 V; g0 ctemp = (t/101)*180;
8 Z1 @0 y+ f, h% P" S2 h( w! a9 lpos[0][0] = (10-num+i)*50+x+650;
' h: z: l5 Q8 C- \' Ypos[0][1] = y+210-(int)temp;
) j# q0 N7 t" m% }t = (float)info[1];, n1 k! X. @, c
temp = (t/101)*180;0 Y+ O1 U+ t5 I# L$ F) n e
pos[1][0] = (10-num+i)*50+x+650;
) i1 W2 @3 O! {# R8 ypos[1][1] = y+420-(int)temp;
) y3 A4 J: z( [1 y( ^& K& E1 G2 K% ft = (float)info[2];
- e4 G. i! i+ \temp = (float)(t/101)*180;
: A3 O7 t; }9 R6 ^5 E4 ?pos[2][0] = (10-num+i)*50+x+650;
- R" c" K9 R& V+ ~# Qpos[2][1] = y+630-(int)temp;
7 ?* I" \' I' L$ k3 r" @! o}
, R) V" O/ M( G9 y6 ^clearrectangle(x,y,x+1200,y+650);! J9 Z% \' T! D0 n
settextstyle(40, 20, _T("楷体"));
% \; q1 r4 q* ]! n# b; G: V7 \6 bouttextxy(x+50,y+50,"SJF");" u1 r+ }+ R2 U" J7 ^# v% @( ~& v. `
outtextxy(x+280,y+20,"CPU"); //画柱状图
' Q6 a! F* \9 }8 f% u, k3 ^outtextxy(x+285,y+20+200,"IO");( e3 r2 `" y! B
outtextxy(x+250,y+20+400,"change");
$ p: E( [* V& p0 L5 l+ E) k2 X2 Erectangle(x+270,y+65,x+330,y+215);" ?8 ], n; P, h
rectangle(x+270,y+265,x+330,y+415);
5 I* e' d# }- E: orectangle(x+270,y+465,x+330,y+615);
, U: g! v2 J; Mouttextxy(x+290,y+620,"TT");2 K4 l( N' _( r# C
t = (float)com;( U2 i6 Z, b. m5 W+ A t ^
temp=(t/101)*150;0 g% z2 F2 ]( x- E ]
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);2 i+ f0 r" i+ O5 E( i! P0 t2 @
t = (float)wai;. o; G1 S: a& N9 K
temp=(t/101)*150;) A" |. u9 \2 V) s- M
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
, U& V) j1 w5 k! }8 {t = (float)cha;
( C6 r4 J; O: d7 K6 C' Ftemp=(t/101)*150;0 g0 v! B4 S# g- F- ^% Z/ q
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
# t# B% I4 P vfor(i=0; i<3; i++) //画坐标 high=90,length=250! F1 c& I! W1 T2 L' Y
{
( [2 R0 X- |7 B& t3 r4 U. Gline(x+650,y+210+210*i,x+1150,y+210+210*i);, |" `3 B" F0 D& c3 {
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);' D' [8 p# ]3 `! c) i
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);+ P' K) K7 s; O: z( t0 _! E' O$ l
* m/ |, Z9 l8 G4 X3 w) d
line(x+650,y+210+210*i,x+650,y+20+210*i);5 f J {4 k# t! C( F. h( ?: ]/ V
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
. h/ G8 [8 y1 W" l9 ]. Pline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
$ Z# L3 f2 P) Z2 c8 `1 U5 ]for(j=0;j<num-1;j++)
0 Q( t: c. f8 u" `- o{
1 V2 E0 j% g+ G. m" Y/ Bline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
* P0 m! w/ t4 W7 N. P/ M4 L( Aline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);4 N: Z; _# n* V! c& r
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
% B. D* \0 Q) _5 W' y- w& \}) {" D& C# |+ w6 j. {( l
}- W2 A* _$ u! T5 w+ H
}
8 U1 k j7 N" _' b, n0 }return 0;
2 Y1 S' y, d) _}
1 G6 a5 Z q, `( dint High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
! ]- F8 v) }" ~1 ]{- ` ?8 C O" n" ^/ }# D) ?4 a
static int compute=0,waitio=0,change=0;0 C- p' B0 g. `6 [6 H3 X$ u
static int computeLast=0,waitioLast=0,changeLast=0;
5 p! U( o8 c6 s' a Fint i=0;
9 g2 Z4 w1 D# M Qif(draw==1)3 V" O% ?( ~- D' C; ?3 `
{# x1 y1 ~- F( B8 O! O3 A' }
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);# S* m- r* k; I9 M: R
drawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
1 C3 k& h+ k3 B$ x4 v( TcomputeLast=compute;
7 U( _( b: X" B/ q+ k; I; \waitioLast=waitio;7 @) k8 d& U! g
changeLast=change;1 a9 i1 E0 y3 @" U! X3 ?
}/ K( B' Z+ {: d$ h [9 a: K
if((* memory).p[0].flag==ready)4 K4 ^ ~5 N. O6 y" g5 h6 L
(* memory).p[0].flag=computing;; { ]# f4 ]4 I) U2 A4 L
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
: t- y! K* u& b0 \" t6 i{
8 B; W4 `0 G# \ ^0 e8 y3 Ui=(*memory).p[0].computeNum;
) Z$ t/ U% o. D6 T, B& E u* N3 V! rif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
' d, R! A, n% [{
5 i! Y# _3 b$ D# c4 V- ~" {5 V(*memory).p[0].flag=IO_waiting;* n) J. M. t, y: R% a7 U' W/ `& I
(*memory).p[0].computeNum--;
( I9 g9 d' u. [% }1 s5 u8 Xchange += exchange_IO_Compute;. ^$ Y" G! e' P) a: T- @0 G
compute++;
+ Q j% G# o6 q8 t# z W}
# w1 j; [$ b1 i' Zelse
& \+ ~% o- Q& G! ~; \9 j{, }1 t [& o2 F: @' o4 T, w3 o6 V
compute++;
# `, x1 I2 }5 `1 [! c) u$ d}
" w3 ^8 G5 D% l* u0 p8 Q}! t: H3 y( M4 Q5 p0 e6 h, Z2 G2 S+ \
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
' q5 K0 U% \& m& ?4 g3 h3 ]{. S8 {! H; ^" n5 r1 \3 I- c! `# K
3 z" {" Q3 [# K! ~" {2 Y- X
i=(*memory).p[0].ioNum;( @9 g2 a0 ]4 N, j* y: H6 g; r
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed" c, [; ?. T0 F( I. V
{
3 I- @7 l) Y! ~; F f! b3 g(*memory).p[0].flag=computing;+ Q; [+ v+ @! m
(*memory).p[0].ioNum--;
6 B! r6 n$ o/ n9 D6 P4 [5 P4 xchange += exchange_IO_Compute;( T6 H0 r& I+ W
waitio++;" ?% \( o9 _& C! Y7 N+ x
}3 l6 M( p N" q5 x1 ~
else) ^. v! `( @( _1 v) b/ t2 O+ W
{9 S6 Q7 l5 Z' r4 p) m9 r, ^6 Z
waitio++;
4 w \4 U+ x+ m8 C' Z( {}5 G: i1 x. A- {2 H
}
9 ^- A2 V! y8 }% |$ Celse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)& l7 o# _4 i! ~
{/ U$ X! g8 U* \
(* memory).p[0].flag=IO_waiting;7 T0 Q; y- i& }5 j9 S
change += exchange_IO_Compute;& ~& u/ o; X0 L8 @( e; _* M2 J
}
6 _9 U- v. B" a5 z; Xelse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)4 l( z# i) Q) e1 z. F
{
0 B' S& b7 f' `. F8 B/ Q(* memory).p[0].flag=computing;3 n3 e3 v6 H4 g5 }6 A: k( p$ T
change += exchange_IO_Compute;" v& S7 N; {1 l- V
}7 I+ X# ?* {; Z" c
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成+ N0 ?8 z* s6 o
{# o9 p6 j. O4 v5 {0 L1 ?, M( A+ F
(*save) = (PCI*)malloc(sizeof(PCI));
" ]2 h4 x; Q$ z) c& O" T/ y(*save)->next = NULL;3 u( }0 I, F, \' I1 W H
(*save)->processID = (*memory).p[0].processID;
/ s: K: ~! ` C" t% V1 b(*save)->comeingTime = (*memory).p[0].produceTime;
. h' H8 o$ n" \+ \4 @(*save)->askMemory = (*memory).p[0].askMemory;0 N I- R4 g7 _6 o) i9 Q
(*save)->compute = compute;
6 p0 y' L$ h; A4 O(*save)->waitio = waitio;0 L$ f' f8 Q4 W, E' S) E7 h1 ]
(*save)->exchange = change;
) [1 @& d1 A* y% u( v' o# W(*save)->completedTime = systemClock;
9 [: m4 p# R# g- P* J(*save)->runningTime = (*memory).p[0].runningTime;# t7 s- w! j4 a
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;1 D+ u* _$ {6 Q0 S, w4 T, i" l
compute=waitio=change=0;' N/ w9 Z' p I1 B9 j
computeLast=waitioLast=changeLast=0;
/ m) z! [5 g4 q, l' N1 @High_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);
2 R3 A3 R* p5 s1 r5 I0 b6 o Rchange += exchange_process;) T% _0 B! w0 d+ R& g
return task_completed; t! O- _; e, r! D
}% A0 ?3 m% C, a& T% t
else8 e+ ` Y* }+ \# Q: T' c; R
return task_not_completed;
, r; `2 v- E- C0 j4 h \}/ f' k" w/ y- F2 n) o0 v
int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)
/ u! S# B. l8 ]' j" E/ Y! o4 x{1 d! N7 _ A* [/ L3 V& v* G* S4 C
static int waitTime[initProcessNum],i=0,j=0;
( X1 E+ X# Q7 T) y" `; S# Qstatic double HR_ratio[initProcessNum];# |/ \! g: S; j
if(flag==0) //初始化数组) \" N1 T4 S1 k6 E6 U
{, o( e" q1 u8 a9 G, e
for(i=0; i<initProcessNum; i++)
: h7 a" }5 d: ]) ]7 j9 e{
0 L d4 L0 }8 P& Q5 |& d$ awaitTime=0;8 T; L% {+ U) z6 t9 S! i
HR_ratio=1;
+ E; d$ M4 F2 p! J4 p j}
' Y, I; n' v% b4 b}+ Y& B" e/ q) f- Q; T
for(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比
% h7 X& t/ l4 z( h0 {{
: X3 Y! q( Y8 \: K! r* UwaitTime++;9 J6 _0 p# {7 t) b/ S0 m8 M' E- v! j
HR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);" b5 K# R) q0 ^) K
if(HR_ratio > HR_ratio[j])+ A9 Y; W! w. a- y" `# e
j = i;
- B$ d' [/ Z" J6 u5 D; D}
. E! F3 S; h: t9 u1 }9 kif(dispatch==1) //需要调度一个进程到内存中执行
5 _& W3 i8 j" f{8 _7 o3 x0 o$ q; W9 l
if((*storage).p[j].askMemory < *spareMemory)! K5 v2 S2 F0 f
{
9 h& {8 o/ i! G(*memory).p[0].askMemory = (*storage).p[j].askMemory;, u" [( _" }$ @- p$ W
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
2 a% h8 {8 z7 v( s(*memory).p[0].computeNum = (*storage).p[j].computeNum;6 N- K* C* T9 m! b9 v0 r
(*memory).p[0].ioNum = (*storage).p[j].ioNum;
1 W8 c7 _, ~- N+ T(*memory).p[0].processID = (*storage).p[j].processID;
* R" n. s# Y+ p6 W: o: M8 G(*memory).p[0].flag = (*storage).p[j].flag;
8 N2 M, d/ d1 f1 O3 V1 t(*memory).p[0].ioTime = (*storage).p[j].ioTime;5 z0 Q$ W! s' u$ Y- S
(*memory).p[0].computeTime = (*storage).p[j].computeTime;+ g1 H! v9 n8 T6 c3 C
(*memory).p[0].runningTime = systemClock;
) U. I$ e" g. X% j* r" G(*memory).p[0].produceTime = (*storage).p[j].produceTime;
+ k( o2 s. H: U0 }7 i( P, O+ Efor(i=0; i<(*memory).p[0].ioNum; i++)# P0 `# k/ _4 Z4 p; Z) x7 m
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
8 ^% p9 b4 V9 V8 J6 s/ s! C2 Tfor(i=0; i<(*memory).p[0].computeNum; i++)
% o6 ^% b5 D( [9 N5 v) q! U5 Q1 {' C(*memory).p[0].computeClock = (*storage).p[j].computeClock;- b6 Q3 Y4 U0 s2 [# m3 |, y3 a
(*memory).proNum=1;
1 t h: r- y1 w*spareMemory = *spareMemory - (*memory).p[j].askMemory;, o) F6 |7 h! v4 ?4 ]* @1 i
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程7 z( O) Q2 z" @8 l5 _& F) ^
(*storage).p[j].produceTime = systemClock;
$ l) l7 j/ f5 U! @, dMAX_COMING_TIME = (*storage).p[j].comeingTime;
5 Q) ]0 o" n2 T1 ~: W) \' L% NwaitTime[j] = 0;' A8 g" J0 {+ u/ D* i6 F
HR_ratio[j] = 1;
0 P' [5 h( D- l7 `2 F [}
) l' u0 u7 E q5 g/ o5 G1 _6 ielse+ c2 `% v0 _' S- e
{
* b5 h7 ~& y: d2 A0 iprintf("A process ask for a memory overed the system capacity\n ");- w3 k0 l6 i1 }% ~. H& h# a
exit(1);
9 | |. h. P @: _4 _5 q- _}
- | g& b8 r+ v! b- |( l9 K& P}; I" `. Y/ F3 p5 m! L3 B- ~
return 0;; {% k6 U4 v! ?( O! F
}, B$ ]5 D% o7 h; Z
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
/ I7 m4 ?- k6 q9 W* p{" R4 s& I v8 n3 v0 S% g6 q
static int compute=0,waitio=0,change=0;
& V# J! g8 e8 b. D. ~" w0 kstatic int computeLast=0,waitioLast=0,changeLast=0;" _- j: `" `* Q9 w- f
int i=0;
- F& T: d. [1 V: e5 h) H* O8 Rif(draw==1)
0 r+ p& o, N8 F4 k/ l& W, G{
% R4 c( E. U! F8 C( b" m//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
; ^0 s, M% @$ b/ t$ MdrawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
6 Y+ u5 _4 S1 @
w( t0 F; d( O* u( t4 x+ @
4 H" _# i) w& d3 k: N3 zcomputeLast=compute;1 b8 N# h4 j& R1 p6 o3 M
waitioLast=waitio;
0 g3 g9 b# ~: c% o \2 ZchangeLast=change;% l$ D; t8 N3 n* C1 V' x/ t- S
}
. U) O6 a7 \0 {$ |if((* memory).p[0].flag==ready)$ [- S; w7 _- Y1 {+ C+ U4 v
(* memory).p[0].flag=computing;
2 {; A/ \7 O* ]9 f' M$ [if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)% @/ f3 V# U; J5 ?% V! a0 m
{7 j# m+ G) F3 k# B r) }' F
i=(*memory).p[0].computeNum;, K8 }6 {( }, h/ K
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed2 L* V8 P2 c0 P8 u9 Q
{
. B3 a" {8 c/ r! A(*memory).p[0].flag=IO_waiting;
6 f; S' b. n0 x6 `3 K" E6 Q7 E; x(*memory).p[0].computeNum--;
9 z: S# D* j I2 Kchange += exchange_IO_Compute;
# y+ \& `0 S$ D- r n# w" r u# j) ucompute++;
K" Z8 X" r( w, p}* V; @/ G1 R7 u; ~# U
else
% Y# b! U( V* N) d6 T{0 B& G9 x* _6 v- a4 W9 K9 I. S8 w
compute++;
1 C6 M j) X1 P: p1 Z+ F}9 P5 A E+ W+ W
}/ r" G! {5 O' H7 Q% w
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)% j& f* y8 ^- X- \. t3 V9 x
{0 K7 x7 }% H( c" o/ z4 G( _
4 p. k I! b8 `1 ri=(*memory).p[0].ioNum;4 s) m c6 [) j& _( W3 X# i c
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed' l3 C% {1 E+ d; o W; i
{
, s# k4 x2 z% o! b0 f6 I' c(*memory).p[0].flag=computing;7 [; Q$ k. f+ Z9 n: G7 `3 `
(*memory).p[0].ioNum--;
$ I- z6 A; J. [+ ?) M* F @change += exchange_IO_Compute;) z5 C" n, f( |1 P# k
waitio++;
6 W8 u: Z3 |0 p, I8 c( s ]3 N}
2 f6 i3 P) E$ S/ melse
1 j6 @, Q; @- e! G4 U: `7 n8 {{. T+ T( i( O6 s
waitio++;
( O8 B) B& {) O% t6 W# ?% G}; P8 D0 m+ N6 \# q) E3 H3 h' X% B
}
. _; M4 E# r8 d! D4 [+ Welse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
7 o4 {% u7 H* c. M9 Z# H9 q{* a1 e4 a- ^1 J% \% C4 }' O
(* memory).p[0].flag=IO_waiting; F9 z* s @ I# R
change += exchange_IO_Compute;
Z e# G$ P# X* |/ h}
, A* Z: I# {+ f1 Nelse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
0 p2 p v, `; j5 M{
a$ f/ {2 @/ g+ D. l* H(* memory).p[0].flag=computing;
9 N8 P7 z3 e) q; V% {# B6 U: Cchange += exchange_IO_Compute;
8 N, j+ J1 ^( Z; x8 E2 _9 a, E}
, C7 v7 T0 J$ s1 Uif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成# t- ^* w k+ i* g! x
{
1 k4 a$ f& |( t2 S* o8 F(*save) = (PCI*)malloc(sizeof(PCI));0 ~) k' @! ]7 p" b2 V4 A, D; r
(*save)->next = NULL;- L, \5 I1 p) a0 l- y
(*save)->processID = (*memory).p[0].processID;9 X3 `' M' @4 x1 b6 X* ~
(*save)->comeingTime = (*memory).p[0].produceTime;
) p9 b. ~/ k n5 w9 ](*save)->askMemory = (*memory).p[0].askMemory;# p7 \8 w5 z9 W% a) H
(*save)->compute = compute;
( Q$ p$ A& Q" h(*save)->waitio = waitio;1 q; R; Q$ K8 i: V& w
(*save)->exchange = change;+ ^5 p2 D# z% H
(*save)->completedTime = systemClock;
: {' S9 t) U8 y; k l- S* g6 R(*save)->runningTime = (*memory).p[0].runningTime;
U; k. ~8 t& M$ M6 O- {*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;0 I" V0 i3 D/ F8 h5 K0 c4 N$ ^) V
compute=waitio=change=0;* A8 w# q& m6 _% N
computeLast=waitioLast=changeLast=0;
# _: v5 J- N4 @% _( V8 z; K; BPriority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
8 ]: t2 _1 d1 T! i% w6 K) p Xchange += exchange_process;
% B2 } Q7 f2 V8 dreturn task_completed;
/ u+ c7 ~0 o" h}) g! T! I- v$ [9 x% h( d1 V5 f
else! ]+ q9 {, ~! A3 {5 m8 K: J
return task_not_completed; `) S' G) A) h3 V
}
9 S8 q% P4 r4 J+ j5 N# q8 u* A- cint Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)" z3 l0 x* _! X) Y
{
! ~5 F- X j1 Y* W. y6 uint priorityNum[initProcessNum],i=0,j=0;3 _* R& p! Z `; p1 G- d' x: k1 j
double temp=0;) |( i# B) i, Q3 P
for(i=0; i<(*storage).proNum; i++) // setting priority to each process: H2 d3 D; B8 |3 V$ _5 G
{- Z; \) D' a8 _0 G2 k! G6 F
temp = (*storage).p.computeTime/(*storage).p.ioTime;
* s/ l( d) U# a4 p: }/ oif(temp > 0.8)3 _) j( K$ B: |) P% h5 ]7 K
priorityNum = 6;; ?2 p$ i! Y4 j/ v
else if(temp > 0.7)& H( o: V: i; f. F5 {
priorityNum = 5;
2 [* u( r+ _5 T9 O8 u2 _6 W# `& helse if(temp > 0.6)! x+ G) e2 G) o6 q
priorityNum = 4;
0 \* U8 I. ~0 j- U8 v) V+ Relse if(temp > 0.5)
5 a6 ^) P. m0 A8 Q" ~priorityNum = 3;
2 ^, Q, @) ~. `; g' jelse if(temp > 0.4)& v* A S# B( L9 ?$ Z' S
priorityNum = 2;6 ^$ N* I% i0 A! p" ?& {6 x- }8 g
else
6 b1 @( h2 o/ M6 p+ wpriorityNum = 1;% u# j4 r$ ?+ ^4 ?5 q: u# u" [. n
if(priorityNum[j] < priorityNum)6 z$ k" _* T- M' H5 J2 ~
j = i;
! g! W" m4 _' Z, R2 M X, \}5 O( L2 }$ B7 s& Y& j# l( h! r
if((*storage).p[j].askMemory < *spareMemory)% n( x) H9 k y; F: \* u2 B
{
5 N1 s5 L) e& [1 s) u(*memory).p[0].askMemory = (*storage).p[j].askMemory;
- i8 O$ V4 [- j7 {; |- c(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;6 p7 U1 t( g y; K
(*memory).p[0].computeNum = (*storage).p[j].computeNum;/ e! [' k6 J7 P4 D1 D' C# O
(*memory).p[0].ioNum = (*storage).p[j].ioNum;
6 e8 Z! d f {5 p! }. u1 T4 s' o9 B7 w(*memory).p[0].processID = (*storage).p[j].processID;
" b( b0 S+ p8 J0 W, K/ z2 U, B(*memory).p[0].flag = (*storage).p[j].flag;& Z+ P: E5 W1 r: B
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
$ V/ }1 I7 Z2 ^( L1 |(*memory).p[0].computeTime = (*storage).p[j].computeTime;: @0 ?7 h, `6 ]0 k- o' i
(*memory).p[0].runningTime = systemClock;
" ~, @: s0 u6 T(*memory).p[0].produceTime = (*storage).p[j].produceTime;, f! i6 M; z; @' O# b/ S
for(i=0; i<(*memory).p[0].ioNum; i++)3 C f" |8 i7 a0 X; _% `
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
$ V( `3 f8 ?( ~for(i=0; i<(*memory).p[0].computeNum; i++)
* N( @) m/ d w(*memory).p[0].computeClock = (*storage).p[j].computeClock;1 P3 G. W8 A. a& w
(*memory).proNum=1;7 N h, Z+ q% E/ X
*spareMemory = *spareMemory - (*memory).p[j].askMemory;2 C* ^, C( j9 z" O
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
! e' S$ w3 A6 l1 j- A( ]MAX_COMING_TIME = (*storage).p[j].comeingTime;; C4 B3 N+ I- N& V3 G5 f& B
}
% I% U/ ?& _' q2 a; U/ Oelse
. h* F3 z8 Z1 D2 A. ]# l4 V{ G t6 h% u" {" u
printf("A process ask for a memory overed the system capacity\n ");
5 o3 w O, Q8 n. oexit(1);
5 b. n: ^0 O- x3 o9 H! s; F}" c2 R- B* q8 Q% Q) k+ x" z
return 0;
* ?9 r ~6 |; t4 ^}" \! i1 n' P6 l
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
: U( {" T2 y6 B1 _{4 X; u; v& r2 A, V: E* t$ B' k
static int compute=0,waitio=0,change=0;
6 F4 U2 q' b( Q+ a; w, A, o& Y5 nstatic int computeLast=0,waitioLast=0,changeLast=0;1 a7 i; S( u2 [) G
int i=0;
' R |+ a1 M' Y, Fif(draw==1)+ @7 R& E3 J; p I0 x
{- J; t2 h5 k9 K( M$ E
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
, d8 H" ~0 _* U- wdrawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);$ Q# q+ _9 f$ c) j4 ^
! {' f4 J' ^2 x
6 h- `) z: H' F+ Y( acomputeLast=compute;- D5 \0 ?1 ]7 H0 A1 \+ k
waitioLast=waitio;2 u/ x) d, ?% w
changeLast=change;
+ x p0 n1 P- c' ?& I1 S; D}
+ B7 e/ U* h0 Q# G- L1 [, A7 H6 bif((* memory).p[0].flag==ready)
( K. p& X: l0 o(* memory).p[0].flag=computing;
5 y/ r* s) H* W0 m/ Tif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
) r; W' W; _- _7 n4 c{0 [& G3 {' V: H- m: _
i=(*memory).p[0].computeNum;
$ x4 o3 o. E' c9 l; Wif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
& O- c0 G; q* n: u( @{ d- l/ E: f3 s1 J- T7 Z
(*memory).p[0].flag=IO_waiting;
1 w6 x5 \' `" ^- q5 X(*memory).p[0].computeNum--;
# o. n! d: ]9 S' M7 y7 M& Dchange += exchange_IO_Compute;: M$ ] }/ X* N3 t' R
compute++;
) `; Z" K/ @0 `4 h3 K}2 {; v$ N1 y1 [ L; \
else8 \) f: d3 N# O2 G6 b
{
" k. ]" D8 d0 V7 ccompute++;! {+ a1 w6 [- Z# [* a
}
# A+ n; A* ] L5 G, y% D) i}
$ b2 J& B% E$ ?9 @2 Zelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting) p& ]- ]: K7 R1 l" Q: _
{; _$ O- E* P& t) l$ P( \
! [! Z1 R! Q" V9 N
i=(*memory).p[0].ioNum;
6 o: t- C' `* O, s" p5 \: Xif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
H7 p1 R2 w0 Y }/ ?* K3 a{
0 o6 B/ O5 }/ i. x9 T(*memory).p[0].flag=computing;
- I1 ]' g4 k" s2 V i1 u3 C0 N(*memory).p[0].ioNum--;0 ~5 C3 C8 V+ e2 P* ?7 r
change += exchange_IO_Compute;
1 {# c8 U9 j }1 hwaitio++;
7 ]9 P9 c) A: |4 x! u1 N* ]- f}# O# A* j/ t( |0 B
else
+ l2 O) z/ h* {' M{
& f4 t, p& |& awaitio++;
2 H3 [* @ L3 c" h+ j$ P/ b$ ~. O. A+ S}
* H) m* ~8 a. j( x}
" G. [3 o! v: F% Q) R& I0 e8 u* ^else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
8 ~2 u0 P0 C3 x- a( S" j{
g: L3 m7 N- x(* memory).p[0].flag=IO_waiting;
( T% p. @3 v. x: }change += exchange_IO_Compute;
5 \# \ D( T' Q7 Y! K}
6 _: P- ?5 {1 n0 S& ielse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
( v: E9 ]7 `# v3 d/ M( @* {, h{
( ?) |4 l/ t% t5 q2 |(* memory).p[0].flag=computing;
/ n( y( [5 G4 I) ?# ~; h- [! K$ {change += exchange_IO_Compute;
3 w" U& ]2 n" a# V}- {. ?, r* G( O! H. ^7 N4 F# l
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成, K( o+ s, R: J! e
{+ P0 a9 T! O; l& |' x8 y: R$ F" B
(*save) = (PCI*)malloc(sizeof(PCI));, i. }/ m+ a& @& l- W
(*save)->next = NULL;
: E' W0 q# J) i0 n(*save)->processID = (*memory).p[0].processID;
% `3 q9 j4 z1 k6 W& U7 S* V0 |(*save)->comeingTime = (*memory).p[0].produceTime;8 ]& {4 R$ N* [0 W/ }4 z4 r
(*save)->askMemory = (*memory).p[0].askMemory;
; L. K7 Q5 E$ y& T6 R {% y(*save)->compute = compute;2 N1 p8 c7 n! i' A/ F N
(*save)->waitio = waitio;" e( t6 @& @+ R3 ~+ P( U; u
(*save)->exchange = change;/ l1 p0 G+ z' K- W' u N" c5 o
(*save)->completedTime = systemClock;
" [$ S8 s) N- k2 e(*save)->runningTime = (*memory).p[0].runningTime;
# I4 L) ]; K+ B0 L; ]*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;$ ?: J# o5 n& C7 J) G
compute=waitio=change=0;
5 p9 _2 F, [7 ~8 k: C0 H2 v5 M$ @1 XcomputeLast=waitioLast=changeLast=0;. U* D: ^. E) P* o
SJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
% ~" j" |' B" d5 z% b7 }- echange += exchange_process;
6 Z9 g2 }0 c% g( x) treturn task_completed; S% y; t+ F- J
}
) e* C; m3 ]" @4 f0 aelse# |) `1 |0 v) v! F7 B6 u
return task_not_completed;
% A7 A. d' D, R# X1 X0 R}& F. p: {1 R$ w( v
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)' J2 x& ]* I/ h# D6 m
{
2 {8 u; o# Z Z4 o( y8 F9 zint i=0,j=0;7 T5 X, X4 V% \
for(i=1; i<(*storage).proNum; i++)$ W3 R1 `5 ~" \) H I
{
" i; X0 g/ ]% Y, w! O$ vif(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))% F; ]. v8 l- e- n0 b: n+ E
j=i;) C2 _& \7 a# {2 k
}
+ x1 A' W. A' D3 u9 }0 Q' nif((*storage).p[j].askMemory > *spareMemory)0 O; N2 w0 t+ n1 }/ O) o0 _
{
' u5 q2 z# _6 O4 H2 S# rprintf("The memory asked is overflowed than the system memory.\n");% S: H2 H! ~4 S5 E6 }* P
exit(0);
6 C5 e3 b* q1 |}) }! K) e2 e. m8 ^
else+ {$ O* \" L2 { @
{
: E! |. A/ r2 I: e( r# k4 X(*memory).p[0].askMemory = (*storage).p[j].askMemory;- k( I% F5 N. N a8 w; v
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
' ^) h( z1 @) O9 R6 \(*memory).p[0].computeNum = (*storage).p[j].computeNum;! }+ p1 }6 e$ O& e4 f
(*memory).p[0].ioNum = (*storage).p[j].ioNum;
$ W- A: d+ Z% H) j( K0 {(*memory).p[0].processID = (*storage).p[j].processID;
5 E- e9 Y2 x' j2 ]! H5 A, @(*memory).p[0].flag = (*storage).p[j].flag;
2 t( C4 L; [7 C( X! d9 y7 v(*memory).p[0].ioTime = (*storage).p[j].ioTime;4 A* n9 j/ c) i! ^6 B& T; `
(*memory).p[0].computeTime = (*storage).p[j].computeTime;
8 i. D; y+ Q* D; M9 p1 j(*memory).p[0].runningTime = systemClock;
4 a f7 X1 \' M: R(*memory).p[0].produceTime = (*storage).p[j].produceTime;: f6 f. D2 a) F6 S& x6 _$ i! i
for(i=0; i<(*memory).p[0].ioNum; i++)
5 K; H& T1 `6 X% z$ B: `% i. P(*memory).p[0].ioClock = (*storage).p[j].ioClock;9 e( N2 p: ]2 p; r1 l
for(i=0; i<(*memory).p[0].computeNum; i++)
5 f( o+ [2 w5 [8 |0 X8 J(*memory).p[0].computeClock = (*storage).p[j].computeClock;# k5 g. i2 n& {) T& p% Y
(*memory).proNum=1;* U7 B1 }1 h# f
*spareMemory = *spareMemory - (*memory).p[j].askMemory;$ d* B" g6 V0 t; u( X
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程2 L( ?& F5 B9 j! t% x
MAX_COMING_TIME = (*storage).p[j].comeingTime;
8 I6 m9 a- o% S# \7 ^}9 C' J1 b! l2 V
return 0;
! |. I8 B2 f- s" e}6 w( z! \# U7 S
int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)8 ], _% b ] c3 w; e! j
{9 E' Q* u- l1 \1 q! D. c
static int compute=0,waitio=0,change=0,clockSegment=100,poi=0;
' M) ?: l. q$ A" W. `& i9 S1 _2 istatic int computeLast=0,waitioLast=0,changeLast=0;
4 r- D+ h. S' U4 h; zint i=0,j=0,k=0; p( F$ t0 X+ O& w" q; V# N( `3 w
if((*memory).proNum<=0)
' ~. ]$ ?8 y$ ?# K+ I5 CTimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);
3 H5 Y* [0 Q6 V/ p3 Y8 Q/ oif(draw==1)2 a! a. Y. }, b/ R* r
{ s$ J9 B- q+ ~- ?, n+ L
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);0 S, A. y1 E! D( ]- H% L& g! F8 k, ]
drawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
" \% Z5 b% D' F3 M" K. c) Q: L( o% {5 p' M4 j
6 f. y) F. ~# ]2 v5 e" y2 m
computeLast=compute;3 f! W+ y, H' y6 D) ?; z. x# S
waitioLast=waitio;
- y C' f; ~- H" F# }) ]changeLast=change;
" Q7 c9 _* r# t- ]4 J}
" O7 v8 X1 T4 a4 n, ^8 aif(poi>=(* memory).proNum)5 s8 q" V, s# C2 s& C3 ?
poi = 0;
( A: Y/ ~% c6 d7 Nif((* memory).p[poi].flag==ready)
6 N( a' o( I! v5 l(* memory).p[poi].flag=computing;/ r) \& \3 ]; z9 H3 [1 g& F
if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)
. [- D( }" m' v+ W5 p{
0 a2 p3 L y& g/ m9 fi=(*memory).p[poi].computeNum;
/ a6 S2 k( T$ E/ z- Q4 bif(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed
8 _4 e W( ^, v: \/ i{* _+ Q% o9 o! c0 ~
(*memory).p[poi].flag=IO_waiting;: E" o/ t) w: d' C2 a- g3 s
(*memory).p[poi].computeNum--;* U0 g5 A8 w: e
change += exchange_IO_Compute;3 V# g8 Q* @9 D- H+ U$ N
compute++;- f* l% t8 I% j# r6 C
}3 ]1 `; \( i. K+ z2 q! E# R
else
# M* e" Q& l" }' D! I{
+ s& s1 \& r- M5 ucompute++;
# N4 w. q' g0 B }' a7 }}
: z1 K/ ]0 C9 T% [& e% }% Z- `5 ^}
6 l! U! O2 \" S7 _: s6 eelse if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)
) s, @6 a- L$ C( X/ E$ }{
+ @# p# \ r7 u; s% j# z4 t. x2 b6 ]- l, D9 t
i=(*memory).p[poi].ioNum;
/ S2 ^; t, q0 P( {9 {% fif(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
9 p3 U% j7 \/ U' X2 ^{1 y" F- G9 \1 j7 e( U
(*memory).p[poi].flag=computing;) w# z5 Q# W0 S/ V2 u! G' P5 X
(*memory).p[poi].ioNum--;0 C z5 c9 v% n( P, ?6 G7 v7 ^) e; Q
change += exchange_IO_Compute;
* v" P* x# O' X/ L/ rwaitio++;
7 D8 c. J- ^% A, X( n1 K d}* v% Y9 Z. J8 i- `. K& D O) _
else8 T/ p6 u' w1 }5 \( V; ~- g
{2 Y& \$ z4 V, t8 z% q
waitio++;. f+ ]5 C& V3 d# `! }. r/ [
}! d8 A6 {9 [$ Y) M& ~
}% J# u) `9 d0 o9 n( q" X4 G
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing)1 X! F9 ~ H6 d9 o
{( ^" i, k1 N" B0 f4 R y) n' ^& S) A
(* memory).p[poi].flag=IO_waiting;
; Q# o6 A5 b& |2 i% T1 @change += exchange_IO_Compute;
* I3 N$ O$ M) J1 F1 `}4 C1 V( U4 q# j% {4 H$ G# E
else if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)( F7 d2 y) _8 ]3 d9 g+ N
{9 L9 U t% B$ S: t% i, k3 A
(* memory).p[poi].flag=computing;1 C7 m6 q( [- X8 U7 a. [+ k
change += exchange_IO_Compute;
' [2 e) x) P9 _6 ]}
8 e) f4 z9 ^* D2 B( @for(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进
0 W4 o# E+ N% J+ V8 e* ~{0 y5 [' b* r6 n
if(i!=poi && (*memory).p.flag==IO_waiting)
5 E4 y/ I: [& ` R{
; ]5 ]: p1 x8 l* V4 Qj=(*memory).p.ioNum;# Y; x7 h- {; V: I+ w
if(j>0)9 E, R" w0 \) E) I- P+ q( z5 F
{' W' f, l, {9 N/ P$ O/ a
if(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed
- @" w) k' w/ \1 |{
W) ^0 P8 z" F" y6 q(*memory).p.flag=computing;
6 \2 Y* w! z% z' x(*memory).p.ioNum--;
6 G0 x$ c) v% m8 Lchange += exchange_IO_Compute;
' U3 D# k! {6 k& W6 s$ J}
$ I. D2 }3 ~+ X! H5 C}
) K. S, V; }2 M}# z- y) ?! p* [8 v& k* ?
}
* }0 C! i9 U+ r1 w4 a! }* ufor(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程
2 l6 m4 F; H+ _/ t& `4 P+ n+ q{- j, m- n: p3 z B3 s
if((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed
* M: k1 S' J: y! m9 ^+ O3 _) }{0 Z7 M( p7 ~5 K& c# x/ i
(*save) = (PCI*)malloc(sizeof(PCI));' [( g: j3 [2 J1 M# ~ C0 v( W
(*save)->next = NULL;
G9 q" V" A' W% ?7 R3 e$ y (*save)->processID = (*memory).p.processID;* P# x" Q; {- U( g
(*save)->comeingTime = (*memory).p.produceTime;
0 K( L- {7 \! l5 s# L: T7 m& U(*save)->askMemory = (*memory).p.askMemory;
7 f; E3 O8 E; C3 ~0 X(*save)->compute = compute;1 I& x- }' E: Q% U3 I
(*save)->waitio = waitio;0 {; X; l4 o8 M: f' |! O
(*save)->exchange = change;, h! z! v3 R/ B) d- t5 F' a. ^4 b
(*save)->completedTime = systemClock-(*save)->comeingTime;- L5 Z1 `9 @0 X
(*save)->runningTime = (*memory).p.runningTime;
* B. ?' m. g, L* e, H( z(*save)->completedTime = systemClock;
+ `' U" {. J2 d* ~# ?$ V*spareMemory = *spareMemory + (*memory).p.askMemory;
' r. o z% ?/ k( V- F# Pcompute=waitio=change=0;
- y" ?/ E' S% _. ]0 a9 \) `5 ecomputeLast=waitioLast=changeLast=0;
% w6 ^8 t$ n: U9 P9 P/ H, f5 uif(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入
( N* \' |7 c& j8 E7 K0 ^{+ `5 Q! D- e* g
if(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程5 }8 o8 @4 K" \/ F# [0 ?
{ y, C0 u. k/ [0 R4 x
poi++;
X0 `$ W' c0 o5 Q3 N clockSegment=2000;
9 W# k5 R& I; d$ U1 n) d, h' b, s}# z3 M; I+ U$ B) t3 V
}4 Q8 t1 c) F! L9 Y
else //没有足够内存调入新进程
% Y, g ]4 `" N8 ~2 R0 [0 S4 y{0 A- H( `% X* K8 j$ H
if(i < (*memory).proNum-1)1 `3 L" d0 P0 z/ Q" X8 S
{3 x. |' } Y% s+ m% O7 n
for(j=i; j+1<(*memory).proNum; j++)
4 }, Y- Q$ A" g5 W{# u* r E* X) `4 ]
(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;$ R- V2 |: V0 ~) M7 \% u* R. k6 @
(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;
' H7 k5 N) P* h/ G; @ r(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;
) Q6 A, C% C- ^8 Y(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;
$ R0 C/ |' X- ]. A8 o# s(*memory).p[j].processID = (*memory).p[j+1].processID;
% N8 u2 y% N& h7 E3 j3 x(*memory).p[j].flag = (*memory).p[j+1].flag;
) S* X1 K- Z7 @% \& Z* U) f9 f(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;
. S& M( K; n7 N. z; Q9 |(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;
+ O4 ~ J5 l/ Y. K% l; P F9 S(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;
7 l7 k. s" ^; D6 x+ I- v(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;
6 q; o0 e& m4 N(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;) u# G [/ g$ i- R, Y2 p- `
for(k=0; k<(*memory).p[j].computeNum; k++)
( D- d: Y8 }1 a$ E- z(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];' z0 b4 u, _* r: k+ B& a
for(k=0; k<(*memory).p[j].ioNum; k++)
: g0 s. X, V. ? P' a D1 d(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];
. _8 z9 y( r1 v. d" f}
. p3 e }: z7 c1 rif(i<poi)* W9 I: [* ` [& C
poi--;
2 D. h4 l" [& o5 e( `6 ]else if(i==poi)- U' u) |0 @* T# n6 O
clockSegment=2000;
1 l/ |& K( p4 f) o, b- U/ B1 W}
) o( e7 X* D3 y+ z1 s. Ci--;4 h/ F. G7 y1 e! G( v3 V
(*memory).proNum--;
/ [, d+ M6 i$ f6 M! t! k b0 u}
- d8 F$ `& ` I/ t4 Ereturn task_completed;5 L& F% v* g1 L
}2 F2 S5 @0 i; o8 z" } i
}9 H8 K! j) x4 \& g
--clockSegment;
5 V2 m" P9 e E* Mif(clockSegment<=0): `- s; v5 [3 O0 R+ K3 d. F
{( [/ B* E0 t# e$ h6 y
poi=poi+1;8 \+ V, Q7 C; Z% X6 } {2 b
if(poi>=(*memory).proNum)
% N% t5 f* o, [7 z3 |, e `poi=0;
: U0 p0 A9 X: y) L T1 p: MclockSegment=100;
' p8 B! Q l/ ?+ ^}
' J' V5 H8 v) d& J1 _- Ereturn task_not_completed;7 {% X8 T1 o6 y
}8 U3 Y5 y6 ~' V, K
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)
. E: d* T; _; B5 w7 U8 U0 f{
* B q% x. o) h8 Uint i=0,j=0,k=0,flag=0,translation=0;/ f9 j( `/ i2 G. ^: F6 p" ?
for(i=0; i<(*storage).proNum; i++), {0 Z# [3 X: a1 h7 u6 z
{
# S# a& B/ R/ t0 n" o/ ^if((*storage).p.comeingTime>MAX_COMING_TIME)
6 u7 h! L) c) u+ GMAX_COMING_TIME = (*storage).p.comeingTime;$ g* F# \& M9 ~' j% p% ~; T
}7 ^) t* d9 G& N8 G1 Y/ }
if(pos>=0)8 ~* b3 ?& M3 B3 \: F: D
{
7 L" z+ @+ Q7 L3 e1 l/ a( `for(i=0; i<(*storage).proNum; i++)7 e1 l) ~9 ?+ k- L0 u
{1 @2 a5 @0 [2 O' d) ~
if((*storage).p.askMemory <= *spareMemory)
* Y6 W$ D F+ {2 x* e{2 N7 Q! \8 }, Q# P9 y
j=pos;
, t" _0 W" q, F% Y: E: P8 t(*memory).p[j].askMemory = (*storage).p.askMemory;
0 t" I+ Q, t2 S# l(*memory).p[j].comeingTime = (*storage).p.comeingTime;. }& x5 e& X) _0 e! w9 R5 D
(*memory).p[j].computeNum = (*storage).p.computeNum;8 z8 Z6 e0 e; G. `# Y
(*memory).p[j].ioNum = (*storage).p.ioNum;$ A- M3 f8 r& d+ m6 F2 [
(*memory).p[j].processID = (*storage).p.processID;. J5 t4 c) T* k# y$ y0 \4 ^- K) a
(*memory).p[j].flag = (*storage).p.flag;- ~! _7 Y: }. m* W2 x+ Z) T0 G
(*memory).p[j].ioTime = (*storage).p.ioTime; D8 R- e. ?3 f3 P7 D; h
(*memory).p[j].computeTime = (*storage).p.computeTime;
9 W' n* V% {: U& Q r/ [9 F) @- F5 r(*memory).p[j].runningTime = systemClock;
# Y# j' b* h5 ?9 O5 W; I6 G(*memory).p[j].produceTime = (*storage).p.produceTime;, m+ Q) C8 S) w* U3 c
for(k=0; k<(*memory).p[j].ioNum; k++)* R) ]9 B, a/ K8 W" }# C
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];" e, x/ z0 p" A/ h
for(k=0; k<(*memory).p[j].computeNum; k++). X, N2 ]! N; s# _ c
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];0 e: I8 X$ F: t1 d8 A+ m8 Y
*spareMemory = *spareMemory - (*memory).p[j].askMemory;: _( g5 c, }' m, ] I$ y
produce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
# @* _' D. J* @8 |* k; w. H0 I8 gMAX_COMING_TIME = (*storage).p.comeingTime;* V# {! a9 r( x% A. X
translation=1;; M* x9 O7 l% S& |$ U
break; O* F- C0 n/ @3 ^, ]- I5 a
}
* Y% K: G0 w, j# V5 ^5 t}
! F" B* _. R0 A9 K" [}; h/ r! l1 `1 a7 A* g! D
else
; M& a8 J) y! O{4 C' E7 b+ l. l: Q
while(1)7 x2 V& U+ Z6 Q
{
' ]" ^/ o) |) y% X a0 Zflag=0;- Z8 d+ W, a6 w7 `) v
for(i=0; i<(*storage).proNum; i++)
# H1 ~0 h( [0 m; Z- t" W, i{2 _( H$ v8 t5 \6 }- j: i
if((*storage).p.askMemory <= *spareMemory)& |2 [: Y- ?: F) \1 X' e
{# [5 H' T6 h/ f V6 l: L* ?* e9 G& k
j=(*memory).proNum;
2 ?( n3 d4 a- d& D2 a(*memory).p[j].askMemory = (*storage).p.askMemory;
) ]' i/ {/ d" N" j& c(*memory).p[j].comeingTime = (*storage).p.comeingTime;
" R4 n$ D) j6 j& S( u(*memory).p[j].computeNum = (*storage).p.computeNum;9 H9 g2 x0 D6 s/ I" Z6 M
(*memory).p[j].ioNum = (*storage).p.ioNum;# g. g% b0 b( ^$ m% C2 b+ v
(*memory).p[j].processID = (*storage).p.processID;: g3 M- ~. _8 V3 V$ K
(*memory).p[j].flag = (*storage).p.flag;
y0 u( x2 Q" }, Q8 d4 g7 F(*memory).p[j].ioTime = (*storage).p.ioTime;
4 m% O; W. T. C3 k# v7 T(*memory).p[j].computeTime = (*storage).p.computeTime;) F2 `* Y! {& T+ M# _7 s
(*memory).p[j].runningTime = systemClock; f2 P( i- p# j0 G3 D
(*memory).p[j].produceTime = (*storage).p.produceTime;" z, o& {# _- X- d, {
for(k=0; k<(*memory).p[j].ioNum; k++)
% p* [! N* Y8 d! [5 p# O(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
6 J. n `% @6 o: ]" f, N+ k* i" efor(k=0; k<(*memory).p[j].computeNum; k++). i) @4 \" z6 M: O6 l
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
" o/ S2 D5 H" B$ |(*memory).proNum++;. w% K7 Y0 f" C
*spareMemory = *spareMemory - (*memory).p[j].askMemory;" P9 ^' P/ A7 K7 t) l& r
produce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
8 M/ o3 D5 L9 u# G0 UMAX_COMING_TIME = (*storage).p.comeingTime;( f- r( F G4 c, X
flag=1;! H" a$ Q7 B8 J# v4 ^4 h
translation=1;
$ ~+ c7 l- {' D. O6 g}
U# [! Y" t' t U m}0 _( h( q$ ~* J# F% u
if(flag == 0)
( J/ z8 }" h7 ?3 P) p/ rbreak;
W5 L* w* p5 r ?}
* C& v) P4 {" X/ e; z8 T7 H}4 C: t4 n6 n; ^/ ]1 [
return translation;6 O7 I; O" ^4 K) A, }2 E
}( m) W& [) e2 C+ ]' T7 |
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)8 p! @! I/ C( G2 G* G* P2 M
{
8 b$ ^9 a: \' F7 ~4 P S$ Gstatic int compute=0,waitio=0,change=0,flag=0,flagiocpt=0; g: \( @6 u5 ?, t m8 l3 w6 G2 p
static int computeLast=0,waitioLast=0,changeLast=0;
$ E/ T& Z3 I" K5 z, |$ ]8 mint i=0;! L5 h- A3 Y2 k4 P% F% _
if(draw==1)
1 i3 l8 P( p& H. Y( e! ~{( u5 u8 P! x. h0 c! F
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
) ~, {* t7 ]. e$ O" j" ?/ \: G0 TdrawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);7 |) V* c4 |. M8 ?: {: S0 e
9 _. X) I$ C! H1 b
2 o. z+ p2 J% g ocomputeLast=compute; S* c9 j3 Z! S
waitioLast=waitio;, q$ I; t) R( u) w; ]
changeLast=change;5 a8 I$ J( z f% ^6 T. {
}9 { y- d! a5 w3 J2 I, H# f9 |% H q
if(flag==1)
' ^3 \% u2 M& x3 \% b6 o{2 ]- J3 M; x! S1 h0 W* Q. g
if((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed
) f, p7 o4 k5 C$ @2 M; E{7 ]+ w3 c( ? X2 n. e' B/ ^
if(flagiocpt==0) // implement compute u- E" c, l1 _& m
{9 B8 J! f$ X* v2 N* k
i=(*memory).p[0].computeNum;, E( C# C- t3 ~: i3 \# s
if(i>0 && (*memory).p[0].computeClock[i-1]>0)
7 N6 Q; `6 n. ^, R% o# B7 R{
5 C. Z! \: Z7 t$ `if(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed
R, J4 M3 g' W. W5 w# e, F/ i{* N: ?' D4 o, g5 O `* U1 o: X
flagiocpt = 1;# ?$ @+ X# C* D+ g: r( v
(*memory).p[0].computeNum--;
- U" E4 d2 d% @: wchange += exchange_IO_Compute;
9 B' \* a9 G6 F* _compute++;, b/ F7 C2 {& V
}
7 G! g1 L# e6 m1 A" I! |else
: K+ d9 Z8 X1 G3 K! Z* t' Mcompute++;
0 _) V7 m6 D- Y3 o6 h2 P
8 z9 x+ D% O* |6 S- L) u Y}( C# U. K, b- O8 W: }/ i$ x$ F/ u% M
else% H) n* l z! C4 X
flagiocpt = 1; H* O( W! O8 {2 V0 f- v
}& s/ z' V8 a2 R! q' w
else //wait io
9 y* o: A8 J& h/ M# e{
1 k; H3 Q+ e) mi=(*memory).p[0].ioNum;
' j8 y* E" f& p P1 xif(i>0 && (*memory).p[0].ioClock[i-1]>0)
& y$ M3 w: m u{
|/ Z; X9 A" V9 Fif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed$ A" V% D% _6 f; G" j
{
: J4 C+ Z3 B& X7 P$ p* @. wflagiocpt = 0;
0 Q$ s' |$ [7 X, @; l5 w1 x, ](*memory).p[0].ioNum--;, I. ^0 w2 ?: h# G8 x
change += exchange_IO_Compute;6 S& u+ }9 \1 J) j/ t$ r1 n ?; @" s" o
waitio++;
( l7 _4 S* s- k$ a}" u& Q) N4 ^( }7 I$ D* g
else
6 s2 g3 }5 R# t/ U$ x9 xwaitio++;
3 }" X) S' h$ q: g; I+ W6 p' R) h4 x
}
1 Y, t, C; K }else
- {* o- n5 o/ Z; u& ~2 Oflagiocpt = 0;
# p/ T, ?& ?! J% o}
. l/ s# E7 f% `* v) E f& ^}. {7 i, e' f9 v# D* I: K
else //task is completed
+ f% D4 e$ H! S% T/ D& j: t& p{
% s0 W) H" v$ j N: A" E3 o(*save) = (PCI*)malloc(sizeof(PCI));
3 Z; o' S2 t: _6 H; N3 D9 e0 p(*save)->next = NULL;& {9 N [: d4 `
(*save)->processID = (*memory).p[0].processID;
2 a8 J4 U% w( m1 S0 r0 x' A4 B(*save)->comeingTime = (*memory).p[0].produceTime;
, U. G) A! ^$ x. P( ](*save)->askMemory = (*memory).p[0].askMemory;) d* _- F! j, V) a, Z* P4 D
(*save)->compute = compute;
$ p1 w- d& s) v( Q6 U( g( E(*save)->waitio = waitio;$ D# I% W2 p! @& _/ [
(*save)->exchange = change;1 D8 K% s( L5 r: k1 l: I
(*save)->completedTime = systemClock-(*save)->comeingTime;
7 p1 c* e0 U" P- Q* G% \(*save)->runningTime = (*memory).p[0].runningTime;
, P3 j5 a+ v% E* T) l(*save)->completedTime = systemClock;
. |6 h0 f! i# t2 x; k- U- g//*spareMemory = MAX_MEMORY;
: J" i, ]4 O9 u2 d/ K6 gfree((*memory).p[0].ioClock);9 G' T0 _7 N) ]* ^& z ]$ O
free((*memory).p[0].computeClock);
( h1 Z0 c; x) Rfree((*memory).p);
, B; H3 ^3 ~* u& a1 Jflag=0;( q. O: F4 B7 e3 c
compute=waitio=change=0;; [# S" L% _9 z4 _9 j
computeLast=waitioLast=changeLast=0;- I; H3 X5 J3 |$ x5 @
return task_completed;
% O: Y% S: J- Y1 ]+ u}
3 l% T6 I# u. C) j3 n, o& R" }}( h/ G/ B! s9 y! p- F
else & N% t/ k( i* v( w' w0 C
{( I& D6 N0 |1 _0 ~' h1 O& g1 O! Q) P
FIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));
# L7 y3 v9 |, e# b o7 Ichange += exchange_process;& f g) f& b" }3 p/ [
//*spareMemory -= (*memory).p[0].askMemory;1 {: Z1 n( ?/ y" W3 M
flag=1;+ y$ P4 b9 r- K
//showProcessInf(*memory);
' U# V- ^; _( P0 Ereturn task_not_completed;
. J/ P" @6 y0 A( Y5 S+ e& V}
8 l2 n! e1 ^6 |( V5 ?6 ~return task_not_completed;( z- s. R/ v, S+ u. V
}
) t& M) h$ }( y6 F$ O( F: B( y, V: jint FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)/ f* i; V% b) a6 a2 Y/ _9 U' ?
{
9 p) h0 Y) H6 J3 [int i=0,j=0,k=0;9 n0 w* s9 q+ [& F
MAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;
5 i5 m# h3 @9 L5 _- z, }(*memory).p = (process*)malloc(initProcessNum*sizeof(process)); `. t2 p( M) Y0 N! h
memory->proNum = 1;
; M2 P# i! [& ^. O; P+ tfor(i=0; i<initProcessNum; i++)7 t- m; J' W2 X
{( M/ c2 i( i8 v' G- l6 |! }. q
if((*storage).p.askMemory <= *spareMemory)' {. p1 H( V0 Z# s
{+ D' s# ?$ H( S
(*memory).p[0].askMemory = (*storage).p.askMemory;$ `" ` I, J% c: W) m
(*memory).p[0].comeingTime = (*storage).p.comeingTime;& o! W! A! t0 A0 z6 V! E2 D+ Z
(*memory).p[0].computeNum = (*storage).p.computeNum;1 F# o) q9 d" z2 i* U
(*memory).p[0].ioNum = (*storage).p.ioNum;9 O- P. y& D/ s$ W3 {. J
(*memory).p[0].processID = (*storage).p.processID;
5 H- t: ^" d: N: K* a% N% p! `+ V(*memory).p[0].flag = (*storage).p.flag;
U2 M e% L( j* t+ ^) d9 Y(*memory).p[0].ioTime = (*storage).p.ioTime;
. ]% m' |+ p ?0 S5 d1 ~+ ?(*memory).p[0].computeTime = (*storage).p.computeTime;3 ]4 t, O) m* R. ?. L v1 G
(*memory).p[0].produceTime = (*storage).p.produceTime;! @ \& v/ v7 U; W7 }) p: Y
(*memory).p[0].runningTime = systemClock;- G) ^4 }" f/ A) y# s, e
(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));
- T! ]$ H1 J2 i6 a" u(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));
7 D6 v. ]& c$ k- W8 r5 ?for(k=0; k<(*memory).p[0].ioNum; k++). e, Y; s. M& ]/ U6 v
(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];" v# w; O1 g2 w! [+ x- E9 S* p
for(k=0; k<(*memory).p[0].computeNum; k++)
6 u. n/ S0 l. z* G8 i(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];, _ v; D" D- f- y7 O
break;
; i7 {, t8 y: e9 j' {- i}" u3 J( U# ] Z' C
}
' N! x9 Q/ D% I& T" Y; {. S5 }if(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入
' Q- R7 ?, R, c4 H; f& x# F6 g& r{' G4 O* B0 N" ]- z! W+ u2 e a
produce_one_task(storage,i,ID_FIFO++);
5 o# P( e% j6 Z9 p% eMAX_COMING_TIME = (*storage).p.comeingTime;
! V2 D! a3 n8 s' ~& ~' W7 D. a8 Hsort_by_comingtime(storage,i);
! [0 Q5 Q4 A. t+ A) Z0 w; ~; y}
! a6 Y3 h! q: V9 w3 }% R# breturn 0;! G x7 g* n8 T0 }6 b" }. z/ d
}+ d F8 v/ s, G) G* l5 F
int sort_by_comingtime(processPool * p,int pos)
0 u9 \# ]+ z# H8 n2 n+ G) I, |{& V2 f6 B7 {# b* }4 ?; f2 |/ S+ t
int i=0,j=0;
% @ w7 N! O: b5 E3 f4 oprocess temp;& Q$ [1 I% \. j ^( F
if(pos<0)/ C5 ]# q$ |! L! y, i: a# A- i
{! |& J) J* U5 Y. z6 R
for(i=0; i<initProcessNum; i++)
) \1 o: ~ F2 ?& b9 N5 f& N* |3 F+ tfor(j=0; j+1<initProcessNum-i; j++)4 s+ K, N3 u- |0 p) ?0 b
{
1 C+ n, N/ q2 M* r) h% d9 Q7 Hif((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)) b% T& I) E6 x+ u X8 K& n
{
+ x$ T X) ] Vtemp = (*p).p[j];- F/ _, T8 X4 F+ _- h3 \/ i3 p
(*p).p[j] = (*p).p[j+1];
# K G, c h( c i k/ X* s# f(*p).p[j+1] = temp;
8 s. B: @5 f/ \}
. d p- M! m4 U: o, @}- c+ o3 H% \1 z5 Y
}
8 u% S( P& X; j" c7 ]else if(pos<initProcessNum)
$ c5 r9 x( c! v! ]. n$ Y{
5 \5 V. X' G( ^7 Gfor(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)
0 |* z2 ?# T5 A y* s6 l# B9 s{
/ M, l4 ?0 o4 {( j" F- gtemp = (*p).p;
4 j& o3 B0 J" X3 W x+ O h/ a. R(*p).p = (*p).p[i+1];3 s' }+ G2 j' v% `
(*p).p[i+1] = temp;
/ O9 R' d5 v% B' a3 U# ]}: s5 R- f* v. Y6 ^- |
for(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)
( Q+ E) b4 } ?* b0 j{7 t1 b5 @9 T5 ~7 n1 }) J
temp = (*p).p[i-1];
! x! u0 i% l+ U. P(*p).p[i-1] = (*p).p;
+ b3 P% D f' c' O L. o/ B5 Y0 E(*p).p = temp;
' f& F$ T9 V7 B- h0 Z}
8 g/ J* H3 e8 J6 l/ M6 T}. S8 F) V: F0 u' F5 g/ f4 e
else
5 O7 y/ h* W/ h6 c4 j- S7 Kprintf("position eror\n");' b, ^/ t% j5 W
return 0;
9 Z6 r6 W* N) a. t6 v6 d1 V/ q}7 W2 \6 g6 z3 k# r" G9 L
int InitPool(processPool * p)
9 | ]+ w4 f6 y k{9 ^& @1 M+ f/ M4 C
int i=0;" C! }" _( f% M. [
(*p).proNum = initProcessNum;
, `2 r ?9 U T(*p).p = (process*)malloc(initProcessNum*sizeof(process));7 d6 Y5 j0 H$ p+ n
for(i=0; i<initProcessNum; i++) //init process information1 v/ l6 s' l, d4 |) Z
{+ M) B2 q6 T( ` }
(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));5 U9 f$ o+ P& ]* u7 G2 L6 q3 R
(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));
9 h* [( z- e* u) y5 N9 j9 J* \' Bproduce_one_task(&(*p),i,ID_FIFO++);
4 b% J- q9 Y- L7 {}0 e" Z( u$ [. ^, V
return 0;7 }3 C& N! V: C6 L# @
}
& I8 u1 U: [" Z( rint produce_one_task(processPool * p,int i,int id)
0 Q3 `, j9 O2 g! F6 i) N{- G8 M" `3 H% T* a* X
int time=MAX_COMING_TIME,j=0,totallTime=0;
/ n' P0 A4 r+ }& Z; a(*p).p.processID = initProcessID+id; , n& [7 [7 L6 y( w$ g1 z: C
(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);; g2 a! _$ U5 i: A1 Q
(*p).p.produceTime = systemClock;8 {/ v$ `( s( P5 q% H" ^3 l
(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;
. s; L& ]# C; s, h(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6;
3 K% q* a! \1 Q% s, qtotallTime = (*p).p.computeNum + (*p).p.ioNum;
* j" `5 O0 {. @" H: G5 D(*p).p.computeTime=0;/ ]( l! e- Z" g6 l+ |7 t1 Q* r
for(j=0; j<(*p).p.computeNum; j++)
" p5 Z, w$ _! Q3 J q S{" V8 h U3 Q- [5 O; y
(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;
3 {3 h& z8 L) L$ z& [9 Q! T(*p).p.computeTime += (*p).p.computeClock[j];
1 a. Z$ P, }2 D3 `2 s1 s; v}
2 E& A+ d$ R/ z/ m" G+ p0 @; n$ B, {(*p).p.ioTime=0;
6 _ w6 C" c- c( Gfor(j=0; j<(*p).p.ioNum; j++) |
|