- 在线时间
- 1630 小时
- 最后登录
- 2024-1-29
- 注册时间
- 2017-5-16
- 听众数
- 82
- 收听数
- 1
- 能力
- 120 分
- 体力
- 570793 点
- 威望
- 12 点
- 阅读权限
- 255
- 积分
- 176461
- 相册
- 1
- 日志
- 0
- 记录
- 0
- 帖子
- 5313
- 主题
- 5273
- 精华
- 3
- 分享
- 0
- 好友
- 163
TA的每日心情 | 开心 2021-8-11 17:59 |
|---|
签到天数: 17 天 [LV.4]偶尔看看III 网络挑战赛参赛者 网络挑战赛参赛者 - 自我介绍
- 本人女,毕业于内蒙古科技大学,担任文职专业,毕业专业英语。
 群组: 2018美赛大象算法课程 群组: 2018美赛护航培训课程 群组: 2019年 数学中国站长建 群组: 2019年数据分析师课程 群组: 2018年大象老师国赛优 |
' l) F+ B, E) M: \( q
经典任务调度算法的模拟程序$ `! y, P* `: U: o' |! ^6 b6 l
本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。
o$ h1 e7 X ^4 }/ {; i0 w' z5 a8 j4 ~$ L6 j
编程平台:VC6.0+EasyX图形库环境。5 @; s8 n: r8 A/ e1 z% I% m& P
# C4 t+ H9 }2 r6 n9 t5 }以下截取部分程序运行图::3 |1 S( [4 E; c8 C: _
; u4 V6 M1 w( J) M0 T. I: L2 v源代码:
0 |* @. `& V! K q
' v+ \: B+ l3 s) T3 ~! F" ~% Y: C#include<stdio.h>: J7 B9 m7 V4 x) T4 H- ~; P
#include<stdlib.h>
/ ^. _6 Y/ U; a8 y. A#include<easyx.h>
5 Z) G+ l+ x7 S0 \1 Q3 H) O- z, i( `#include<time.h>
; d4 {. |: V1 @/ f1 C#include<conio.h>
" b( O2 c( L; c% P. {( N/ c#include<graphics.h>" d4 D8 O# S5 D9 O
#define initProcessNum 10 k3 s9 Z2 L( \4 r) t7 r
#define initProcessID 1000, l' q$ ]: B' I* D/ u
#define MAXProcessRunTime 10000- C( K+ S# |( U- ?( ~, K3 y
#define MAX_MEMORY 4000. i! k) D: W( H7 }
#define exchange_IO_Compute 10
7 X. g9 V' a- ]2 y5 L/ Z#define exchange_process 259 W4 x9 Z4 u/ r, M9 g
#define task_completed 18 R; c0 R$ \0 L6 K
#define task_not_completed 0
; q. `, g q* n+ x' z$ p" |. S#define initclocknum 100( f: j/ i& Z7 g7 w( T1 G
enum condition- K/ o7 D% o" O1 X
{& e1 I' q6 s1 f6 e9 q( H* a
dead,computing,IO_waiting,ready
' L! X# H7 S% n8 g& q& Q};4 C, n5 v O0 [) w/ w( X
struct process
+ e5 l" K& j* m6 r$ o7 Y{
1 A( K) |+ a$ aint processID;$ U) {4 ~8 O" Z! Q9 {! P2 h8 c- d
int comeingTime;8 l! }1 k/ n% y0 _9 H/ Q
int ioNum;
. ]1 ^5 { q P6 O. R' A0 Mint computeNum;! B# l5 g9 A/ @1 j: g; x
int * ioClock;3 m2 C/ d3 I6 N, u' O. l- ]
int * computeClock;
+ [# l' ?) e) _" s1 rint ioTime;( T% W$ |' E6 B0 i
int computeTime;
1 o6 Y* q7 m F A; Lint askMemory;8 Y7 z9 n8 _6 [; V
condition flag;
& J7 [8 I2 b' c( Yint produceTime; //生成时间,以下三个数据成员用以计算相关性能
7 W) \* s' M3 O9 K9 ?: [0 jint runningTime; //第一次占用CPU的时间
2 _1 J- S$ T8 i. t6 Yint completedTime; //进程完成时的时间
t) u5 T, p- _1 \7 l' d};
9 Y" F, o/ F0 D* u# G. c3 rtypedef struct processCmpletedInfo //保存完成一个作业的相关信息
! }4 A4 @1 c. s! r' v5 \{: V( }% H, H! N+ A
int processID,comeingTime,askMemory;
: w# `2 ], _5 K& nint compute,waitio,exchange,completedTime,runningTime;9 S4 F' R' |4 I1 f+ A7 Z7 d
processCmpletedInfo * next;
s' D7 r* I% i; D }}PCI;
: m2 b1 B8 E5 ^7 D1 U- D' ^6 Pstruct processPool# L6 }0 m9 ]. W. Y) W
{* F% B) f4 w/ |9 m# Y
process * p;% b: w5 y. l( T$ l
int proNum;# y) k5 u3 L+ e4 }7 i6 i2 N
};
# ]0 o& T# |( h. [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;
) r7 w7 ?$ T4 S. d5 r3 k8 jint InitPool(processPool * p);3 j; V8 w E: s* P! H
int produce_one_task(processPool * p,int i,int id);
" g/ W- a, u- F0 X' oint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);
" Z& L: f" J& {int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);! U, _& F1 a% i- R/ t
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);. a0 d$ ^* D. R/ `
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
, h5 {% w4 ?* g7 `; gint ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
5 [3 P% n/ |2 W% E4 x' xint SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
9 B3 g# \8 k* ]( L: F3 \( v) @int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);$ {1 L0 M3 V% K* J
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
3 {/ x' C! \) j; jint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);9 P) q# H8 U1 t# g9 R
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);; T4 }" ?+ x3 t
5 s# m2 g- E- r# `0 L( {/ l Z& t1 s/ l. N) U
int sort_by_comingtime(processPool * p,int pos);9 G" h5 q; n c( {
int showProcessInf(processPool p);2 |6 y( \% Q _) s: V2 d" |* l2 z; n
int drawPerformance_FIFO(int x,int y,int memorry);
2 D) _9 p. o9 [/ u5 d2 |int drawPerformance_HR(int x,int y,int memorry);
& i; E9 N& A( I) Z1 \int drawPerformance_PF(int x,int y,int memorry);4 N( a" z. i% B: ]
int drawPerformance_TT(int x,int y,int memorry);% K- W3 a- P3 ]9 Y
int drawPerformance_SJF(int x,int y,int memorry);4 I h, p& c/ f4 X! s
int MouseListening();8 X; ], P# G& G" O
int MouseListening2(int *flagShow,int * showTime);$ Q* O1 `3 `6 T: @8 h3 `
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);
# ~$ Q ]/ c- K" p% M2 c/ ]; f) K$ M1 v2 [" J3 z- ]+ X# I* c e V* R
+ O& }# Q! _) Qvoid main()
" K3 p( r3 G2 p9 \) J0 A0 l/ ]{
: ` ?7 r( p4 C5 w8 pPCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,
' S: T5 ]+ j4 W* K+ t8 _' B! r*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;. F" r" s; p4 A& p; M
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,
, a$ E8 i- h7 ]8 hflagDraw=0,showTime=100000;6 Y1 c$ E5 U1 `0 N: |! _
processPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;$ g; Q, ~! c8 }1 K
FILE *fp=NULL;2 M2 P+ t1 c$ B: r& T: J4 Y6 h: ?
//processPool HR_p,HR_mmy;
6 l! a! ]$ J1 @3 K( h' u& ~* W! E& H# p5 d; V8 e* I
! K) n4 Y/ O3 R# |
srand((unsigned)time(0));
& R( ^8 Z0 b, {% v4 H5 q* wsystemClock=0;
' }- B0 o! k4 T& q- d: Qinitgraph( 1200,650,SHOWCONSOLE );; `- T0 J- c! Q7 }& a/ ]4 L
settextcolor(GREEN);
( d5 C2 `5 j0 U2 Dsetlinecolor(GREEN);
: Q/ j- M R% g3 k0 Zsetfillcolor(GREEN);" l$ z5 b0 x$ g% |
InitPool(&FIFO_p);) @/ c- s8 [7 }" \( K1 R
sort_by_comingtime(&FIFO_p,-1);
. S7 e3 p! ?8 {InitPool(&Timeturn_p);
& m ]! v) z7 QInitPool(&SJF_p); l# s4 F+ p! @9 o1 V/ V
InitPool(&Priority_p);
6 B1 d; P: J: w& s [2 LInitPool(&HR_p);
" K0 y! R& L; s! |) \//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
( i3 T! |% _9 R//Sleep(10000);
! E5 D( X9 q; ^7 V. M
`" {! i' H u* R" u
6 f# O& w6 j4 W# J) ITimeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
0 H1 w5 ~& j1 R# P+ l/ x5 _, r( aSJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
v6 V ]. t- v' HPriority_mmy.p = (process*)malloc(initProcessNum*sizeof(process)); q1 v( M: L0 f5 F. Y
HR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));& b. b# Z5 Z* Z) {
for(i=0; i<initProcessNum ;i++)4 z/ D- B; d/ i) \' `
{
) `" Y: ` [4 E, Q0 O" A. ?0 FTimeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
4 x1 ^6 C) `1 Z t. JTimeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
* |! U! [$ @, r y6 \/ [! @7 s" ]SJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));5 y" U! U; o) k/ f
SJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
2 R: x7 y l7 B4 L. D' @Priority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));" p$ R4 a: K/ J/ e( g# a, k
Priority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
O0 _9 {8 [, @HR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
; b' D& g: x" B+ O- Z4 J- kHR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
w0 \9 T S1 {0 K; `* f}
; @# ?+ o+ h& u- r( ~Timeturn_mmy.proNum = 0;. V/ n% g1 ?. q2 a6 Z) w u% a+ E
TimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);( g+ s2 q! e& U( p, a+ y
SJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);: S% A% s( l$ r4 Y* N: r
Priority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);
; J+ D6 P6 F1 w% ~$ O- \High_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);9 Q1 n# a7 L* k* e
//showProcessInf(Timeturn_mmy);/ _" j1 k; q1 R1 Y2 o
FIFO_pri = &FIFO_save_head; N# |8 B- K! }9 O4 `% q) ?
Timet_pri = &Timet_save_head;' b+ V% n" o: Y' c% W9 q
SJF_pri = &SJF_save_head;
% M, ^2 f3 j A$ c6 L( h# j* p) s! P5 VPriority_pri = &Priority_save_head;6 U0 c* k; G5 E, ]8 t; L. @+ g; r
HR_pri = &HR_save_head;, T% I& p. u" P+ `7 v( r* D
setbkcolor(WHITE);
& P$ a/ q0 H" J( ~3 C, ~while(1)7 ?, w0 n2 M( _7 W: i- G# L
{
! [3 D4 V* S7 N- w4 W- s& L0 Tif(MouseListening()==1)2 o! l7 f4 k6 L
flagDraw=1;5 E6 ?7 S m, |- w: r# G
if(count==100)
; s5 X- n" p2 |6 V! ]{
0 r- A$ g) C3 z4 U9 Y; [0 Hif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)- E: J7 I3 y( S0 x* I
{" N/ W0 A4 {+ z& a: E- O
FIFO_pri = &((*FIFO_pri)->next);* v2 q8 i. N+ P% z2 @
3 u2 {: j. @0 f A- O/ z: C//printf("hello");; X) `7 d* g3 A' ?, s7 u5 f
}0 g& w" K1 C1 X$ I# _/ U
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)
" E; M# N/ T7 T. _5 }{6 B* c8 h: ^9 V4 f
Timet_pri = &((*Timet_pri)->next);
A# }) ^( Y: E+ @//printf("hello");1 x; b6 f# H) X6 g" V
}1 d1 z/ X% [; Q: U) t
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)
, e; g/ i9 d0 u$ [9 ]/ ?* N) e{5 M; q+ V7 O$ }
SJF_pri = &((*SJF_pri)->next);
- g- x3 ]' v+ A3 ]+ o//printf("hello\n");
6 v4 F0 ~1 n d2 \, N7 ~6 w}
( d! p; U. B; q Z6 q* R" Xif(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed)
1 v) B" ^2 C! m{
6 m+ B k; @6 g; ?& |Priority_pri = &((*Priority_pri)->next);
2 S4 l+ O0 d, q i6 U" x//printf("hello\n");4 J2 l1 T7 f0 p3 w7 O0 w
}
4 i& y) U$ R) Fif(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)
, a" t6 R' ^$ h{
" F1 W3 d* e2 m7 k EHR_pri = &((*HR_pri)->next);
/ C" C, ~2 a6 s# l' J+ u6 l//printf("hello");8 e n' l# H) |* ?
}
3 O: {* P `5 ?4 T `count=0;
' L+ C9 M8 {" k- q7 L}
8 n% e. l3 m- y$ X' Oelse& L/ m- r; X0 b- \- H: j! V
{$ Y* _; ~5 @8 g
if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)" @' Q' j1 R( V- X2 a
{
" o* l) Y: [- e9 [* O( }FIFO_pri = &((*FIFO_pri)->next);' O1 R8 A& q7 P
// printf("hello");7 G. p6 c$ P% p+ N# r j/ ^9 T5 S
}
) X s! j2 P) ]( G" c7 t9 Kif(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed) W1 p. w% U5 K* p8 g0 X7 ]
{
' v# _" y/ x; V5 R1 hTimet_pri = &((*Timet_pri)->next);2 u3 G0 H0 l4 U4 I4 Q9 X: o" j8 |
// printf("hello");1 {7 a; f+ \+ J. B& S
}
! p; H. ^0 L$ |: F4 |2 e& Oif(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)
s: n: t* O8 V; J{+ y- E' a. }8 X' o6 ], i; @& N
SJF_pri = &((*SJF_pri)->next); A- z8 v& M" Q& t+ A# @
// printf("hello\n");# c) Q! s& C# R6 j& z- Q3 V5 P. g8 `( w
}
7 C; ]1 P8 G9 `5 i, L, [if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)
" B( I9 N* V7 _- }{- z" A/ k9 ?8 y0 h6 n. G
Priority_pri = &((*Priority_pri)->next);
6 H* h' l+ o! ~0 R//printf("hello\n");! P( T$ ?# j/ |* \- G
}' f, ] Z* T" t) L( o
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)
% j* O; N; d9 p: d7 U7 i{
( i2 C4 {& H5 w3 kHR_pri = &((*HR_pri)->next);( B2 }& T$ b! d- u8 R7 H
//printf("hello");, J# E6 d5 I4 w) G1 W; k- G
//Sleep(1000);
+ `" u( V! x% l1 l$ n' s}
0 P. W7 q0 }2 J; b& C e3 s& d2 Ycount++;' v( @8 `* `7 ]8 h1 _, v
}
2 {" ~& f) F; s& e$ Lif(systemClock==showTime)
' F5 X+ {6 _$ @1 u$ @" p& i6 u5 i{% H7 }- v H! a `& b1 M2 v
/*PCI * p=FIFO_save_head;4 \# s+ f1 ~3 B8 Q" W% T
int i=0; s4 H2 [+ {+ H1 o6 D9 j8 c
for( ;p!=NULL;p=p->next)
- X) Q* W) G2 V+ M! E& R* a+ S; v{/ E$ Y) V7 r: y% ]5 Z
printf("Id %d\n",p->processID);
& C1 P# V' e& s0 D8 j* W, Wprintf("comeingtime %d\n",p->comeingTime);
# @- q B7 r' F6 E& n& Uprintf("runningtime %d\n",p->runningTime);, @. T" L3 e8 z1 G5 I. @/ \) o* X+ p
printf("asdmemory %d\n",p->askMemory);; g, s& i+ O- [! ]" W
printf("completedtime %d\n",p->completedTime);
: X8 } X8 I% D( U8 mprintf("compute %d\n",p->compute);
$ |& K s: ^. z2 \# }' ?printf("exchange %d\n",p->exchange);
# Q+ M% v/ e& j1 H8 F7 P( q8 G0 Tprintf("waitio %d\n",p->waitio);
: I+ m0 f1 E ?3 W; Oi++;9 y+ v' G: F+ O/ h
0 i# W7 a# {7 i+ L
2 B. B/ C6 T" p3 @: z$ |, a}
2 E) H( q3 ]. `( h' Hprintf("%d\n",i);*/
& }1 y1 y8 D5 G6 a3 X8 ~! F. i4 |if( (fp = fopen( "data.txt", "a" )) == NULL )
* s$ ? m" |' L" t5 P{0 @# G2 n/ z d5 B1 [1 C4 u
printf( "The file 'data.txt' was not opened\n" );# ]! B! D# d. [3 m
//return 1;% P) ^6 f4 @" |' y/ D' V& }2 Y
}# [- f6 {: t7 r6 Q: A2 ^9 p( g! Q9 q
else% h, k# @0 ^9 t( S B+ \
{
. Z: X; A+ }, d% C7 ?8 Vfprintf(fp,"FCFS \n");
7 y" }, F+ x; x0 K, pfor(p=FIFO_save_head;p!=NULL;p=p->next)( G, v% n3 K# ]) `& Y, q4 M
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
- ~- W2 j1 o$ G; x- J! h) @! xp->exchange,p->waitio,p->runningTime);
0 s* u( i1 {$ ?4 ~+ ~3 z8 f! Dfprintf(fp,"\nTime turn \n");
, \ l# [2 ?4 g, J3 tfor(p=Timet_save_head;p!=NULL;p=p->next)( x, p6 K7 C# N7 n, d6 |6 L
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute, T6 d6 I( D( \2 R
p->exchange,p->waitio,p->runningTime);4 Q% C2 H2 P$ n4 C5 b& v* s0 c
fprintf(fp,"\nShort Job First \n");
$ P; {% r8 d0 v# b+ cfor(p=SJF_save_head;p!=NULL;p=p->next)$ C; i& `$ t. k$ d$ \( d7 M
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
- l; l$ ]5 m$ G6 Q8 X& f9 Qp->exchange,p->waitio,p->runningTime);
' j5 L9 ^3 x) m" h8 mfprintf(fp,"\nPriority \n");
7 j+ Q$ M( n; o" `+ R tfor(p=Priority_save_head;p!=NULL;p=p->next)
4 b" M8 [3 A4 P& b; `9 _0 L4 Bfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
% w( j$ E5 e8 [3 Zp->exchange,p->waitio,p->runningTime);
# H" }2 H7 |2 Q: e1 E5 e( v5 Cfprintf(fp,"\nHigh response \n");
8 h3 ]3 [# @" ^+ m1 J7 t: Y4 lfor(p=HR_save_head;p!=NULL;p=p->next)7 @0 n/ z# w( M0 E
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
0 x u2 Y" y, P) K; {# _2 L' cp->exchange,p->waitio,p->runningTime);5 g% `( Y* h% k) Z8 V1 a& Y9 n
fclose(fp);6 Q; o" X- J8 ~
}& N" W! f1 \5 K" s a; t
showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
+ E' j% D0 {5 n" w3 ]3 O+ [- EMouseListening2(&flagDraw,&showTime);% B O L7 v+ ^) n! R9 w5 p# s
}
' M, u* ^& A- Y6 Q* Z7 {( m) {( F( y. GsystemClock++;( X. E* g& p3 `* q( F
if(flagDraw==0)$ b( S( {& K& T
Sleep(10);
$ ]4 N) |2 V3 W t6 }}: S: d6 `' _8 F/ p/ e' U0 O1 f
* a$ w3 j' P5 f' {$ m8 r7 ^" j/ M8 G$ a& B3 a0 s$ Z
}5 d; X( e3 C! O" t
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)
5 D! U7 Z! w1 {1 Z1 q{. b5 h" f3 E& b1 [ R/ ?( u$ V
PCI * p=NULL,* name[5];. t. j+ D u6 a& V2 Y; W- V
int count=0,i=0;
7 f6 L8 n+ U# D- Ochar ch[5][10]={"FCFS","timet","SJF","PR","HR"};1 c2 t3 S; D& N5 F, D
double turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};, n: e# y, `. T
struct info' u+ |. ` I1 H+ R9 g
{
" k5 P/ `# p' B, ochar name[10];* Q( ?6 r3 g K+ X1 z3 }! [
double throughput,turnover,wait,CPU_rate;& A/ h' g7 Q# E/ J9 _: d7 K
}inf[5];' {. i+ L) s1 q% ~: F9 B5 P
name[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;' x5 R, _2 h; ^; P, ^ u
printf("调度算法..........A\n");4 E1 s1 s' P" F t; Y( }
printf("吞吐量............B\n");
- r: i1 B- G4 _$ e: [: bprintf("平均周转时间......C\n");7 f. m* ?% A! O" ]5 W( ~
printf("等待时间..........D\n");
; s" b& f6 f( {& q/ x% `! i: D4 ]printf("CPU利用率.........E\n");
7 l( X. c& b1 v% J. Q( R# Iprintf("A\tB\tC\t\tD\t\tE\n");8 P/ W+ n& P6 y% r6 }3 f, n
for(i=0;i<5;i++)
4 U, Y/ s1 b5 g* r{5 w4 h! E7 F, L9 ?
count=0,turnover=0,wait=0,c=0,w=0,change=0;
4 G' b* i* I2 H" t7 ]for(p=name; p!=NULL; p=p->next)* _$ R, T" ? _/ V$ |9 }+ K- @( Y) _
{
3 R; _1 v0 Z4 {7 ?" p7 Z) h; r/ zcount++;/ ~3 f U" e5 } [2 o- K
turnover += p->completedTime - p->comeingTime;
# K" Z. P" \; ]wait += p->runningTime - p->comeingTime; ~* }. X, X8 j6 R7 @" l z& L3 X" {* v
c += p->compute;
& M4 z% q/ b& a" ow += p->waitio;: O* Z, y8 N& T1 c& A# k
change += p->exchange;% S+ \5 {- c5 L9 Q" O: X, w
}- s. l- V+ C8 K$ M- }0 p
turnover = turnover/count;9 V7 s, M5 h6 ?& s0 }
printf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));
& _6 ~2 c/ G' kstrcpy(inf.name,ch);
. e- l5 E$ M$ [) einf.throughput=count;4 k* w" c& Y9 Z: {
inf.turnover=turnover;
3 I( j+ i9 z4 K' J$ q' cinf.wait=wait;$ N, |, X& j3 e& |
inf.CPU_rate=c/(c+w+change);. d# Z: \: i2 J2 ?& u
}5 i# k" W4 c- v5 L
//画图
# K) S2 W% j! i# j2 }//cleardevice();6 C9 s% O2 P- V# e6 Q0 B( s6 a3 G4 E
line(0,600,1200,600);
4 M" P! o, {- M/ |/ @line(10,600,10,200);& B. t v+ M1 i, d9 q) Q% Y8 q( h
line(10,200,5,205);
6 g8 R/ `1 ~6 pline(10,200,15,205);
2 d) E8 w- D( [3 v- Tline(310,600,310,200);, W# z( V/ B! M% H) h2 _
line(310,200,305,205);
7 d7 a8 J( ^2 Tline(310,200,315,205);4 D0 t- Y7 ~( _3 ]5 W
line(610,600,610,200);
& i. p/ X4 } R8 Zline(610,200,605,205);
1 |2 @# e( Q1 C7 N3 Oline(610,200,615,205);
$ D' z. a/ y/ b, f& eline(910,600,910,200);! @8 S7 p# o% W6 J+ j K4 Q" p
line(910,200,905,205);. p" X. p/ d; |" R
line(910,200,915,205);//最高的长度400,宽度均为40
- u' E. U( \: h6 Rfor(i=0;i<5;i++)
8 P( J( z0 C+ C1 @" ]% ?0 Y{& ?& X% y5 \1 Z) f# n: l
if(inf.throughput>pos[0])
" o P* n2 H3 s: f i0 U/ gpos[0]=inf.throughput;0 |# r" b& g7 }4 \& h: t8 _
if(inf.turnover>pos[1])/ W: O/ a8 X5 ?; p! n' R2 L0 Z
pos[1]=inf.turnover;2 Q) q0 N1 T/ {) o9 {
if(inf.wait>pos[2])
' p+ A8 v- A& s3 y, Kpos[2]=inf.wait;
4 @- \* H e( f- S! p. S+ |, J1 Sif(inf.CPU_rate>pos[3])! q, [8 I- k- F3 V, S$ G
pos[3]=inf.CPU_rate;( A9 S1 o$ b( e
}1 H0 h$ F4 H# m6 `0 Y! D
settextstyle(30, 15, _T("楷体"));
% ^* e9 [/ b" v# sfor(i=0;i<5;i++)+ |4 n! \8 X7 X! D
{$ ~$ l. T0 Q+ u- k! O
switch (i); a1 n8 w0 _9 H
{
) k6 W5 U8 ?/ X6 Hcase 0:
' T" w( h. [8 F; v2 K0 zsetfillcolor(BLUE);
( G( n. U* A1 b1 O5 h# s# yfillrectangle(100,50,150,100);
s7 J3 |# J0 l' C, {& Iouttextxy(160,50,"FCFS");
4 X" ^9 C3 u- A/ Y% w- ?break;
: Y6 p h1 s: O L3 {# mcase 1:
- k5 ^4 U6 A/ f% n3 Zsetfillcolor(RED);
$ F! W# E0 G! I* D. k: yfillrectangle(250,50,300,100);1 G/ R) @' n% h! d
outtextxy(310,50,"timeTurn");- R% X- O: A" y' t+ s
break;
8 |- y3 Y/ l! D, X5 _ Acase 2:
! X+ a% F7 o! z4 Rsetfillcolor(YELLOW);% R5 [6 a& @8 {
fillrectangle(450,50,500,100);/ q! h; T) K1 A
outtextxy(510,50,"SJf");
- U0 x; K2 r' Mbreak;
, ]% u/ ~( P$ S/ ecase 3: Q' j+ `: v: Z$ Y( o$ z- d
setfillcolor(BROWN);! v- ~2 y3 v8 M5 M4 h
fillrectangle(580,50,630,100);2 ]! W+ M% ^- c: G7 m7 L, \
outtextxy(640,50,"PR");
1 }9 Q6 M; i# f; Z$ Mbreak;3 m9 n) A: C- r% X# s3 d
case 4:: W* j8 Q4 \4 Y8 q' [
setfillcolor(GREEN);2 y- [) n5 j( [% U, O( Q1 {* _
fillrectangle(690,50,740,100);
/ ~& a i$ H7 r# |' Xouttextxy(750,50,"HR");
: U& V* y( A5 e/ @0 Bbreak;# X$ A! T' C* I! M
}9 ^2 N# J7 ?; j- M1 J
fillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);
5 I5 C* N" J- p; e) Qfillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);
6 |1 {- n! ~. n: }fillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);
. j6 I/ i! q- b! v2 j# V1 `' Wfillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);* H* ^. q6 A' ~$ g6 P5 z- Z
4 h9 R/ h2 c% K9 {* q
; B6 r9 z# m+ ~2 c" ]( n2 Q! u; \# C}* P+ F& f% s1 U, ^8 a9 @
outtextxy(100,150,"吞吐量");0 Z, i) ?* u3 }. x8 F1 X1 V4 h+ D D
outtextxy(350,150,"平均周转时间");
. n) D3 j }3 _7 n5 N F% l* [outtextxy(650,150,"平均等待时间");
* H& D1 y p- r6 Pouttextxy(950,150,"CPU利用率");
" e! Q2 Z( E$ P; `return 0;% v" z. W0 M+ @; f
}
8 S+ q* R" I( s3 h% F' P6 I& A/ p; pint MouseListening()
. A0 d7 y8 p% ^+ V1 r4 o8 {4 F{
/ I& `& s" i# uMOUSEMSG p;
7 _. t; h9 y; i3 I/ J( yif(MouseHit())4 ]7 r5 I3 w# {' M; C0 N
{( P; F: G: z, I7 {$ Y
p=GetMouseMsg();& E( F$ c+ Q& p% P5 c
if(p.mkLButton==true)! y; \- U* g c& W
{
+ M6 ~& T! A" d/ k$ Aif(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0) L# P+ n4 g1 c0 o" J
FLAG_FIFO = 1;
# Q, M% F0 n9 T. X% o) lelse if(p.x>400 && p.y>0 && p.x<800 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)& m5 i+ |) L9 N w% \% @5 P
FLAG_TT = 1;8 O3 c/ p7 P2 d# s3 S
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)
/ h' c3 n# ?, p b" X' _; AFLAG_PF = 1;
) `* y& L5 V( a7 N( Jelse if(p.x>0 && p.y>325 && p.x<400 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)6 a& R% w2 }2 g- o$ J( [+ K9 `$ V5 [
FLAG_SJF = 1;' S/ b% o: M. m( N7 i( v
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)" V. @6 R6 J5 U0 ?% n: w2 d. \
FLAG_HR=1;* E# o: ~: `9 e: J+ [
else if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)/ {) L* V- R& S6 F. Q- {
{
6 c4 G1 @ K; M1 R6 w8 lFLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;- y# g' S* K/ P- ?
clearrectangle(800,325,1200,650);
5 [5 W6 c4 f" y5 l0 y}
9 T3 p+ H6 C" w( Selse if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )
7 Z9 P. u/ ^9 F, c8 W0 G{
; Y$ g2 L. ?' ]4 LFLAG_show=0;. p0 E1 ^$ g% ^ [
cleardevice();
) C& P/ W" G9 h$ `6 A( D( nreturn 1; ^1 {/ m/ S6 E6 {" f* z: b
}8 g, u& L2 i) S4 \2 n9 T/ c
}1 p- K7 c+ ~' \0 S0 F
}
8 t; A7 K% n" j3 D' Y% y0 treturn 0;" ^0 c3 P" z+ W' V- U
}$ Z+ B6 T! C% ]- M$ e% ^* t
int MouseListening2(int *flagShow,int * showTime)
5 O0 Z0 G: x5 h7 x7 A. Y4 Q{' _/ t9 d! V4 b1 x# G$ w- |
MOUSEMSG p;
+ T. C/ a, z0 d: t8 x6 e/ Grectangle(1150,0,1200,50);# V1 Y& p1 f3 j# q8 \
outtextxy(1160,10,"X");
3 H$ f W3 W: }$ i/ W& R" y$ P% Y Wwhile(1)! ]: O* S4 i+ M: p y% Y$ F
{
. ?" W3 c7 h cif(MouseHit())
+ U z+ }" @, q. I& ]' A. \) r; [{, `8 r0 |, m7 t# ^1 m
p=GetMouseMsg();, h' O% O) T6 w
if(p.mkLButton==true)' D5 b0 |- l4 u. @. j4 P" |, w
{
8 Z9 `, m" |- Fif(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 )
2 t1 Y% a9 T/ ~, A5 h# t+ x4 i& `{3 m* {% @3 P# u$ I3 e+ L
(*flagShow) = 0;
0 ]! [6 G* g: p8 S8 o; v( d( E(*showTime) += (*showTime);6 ~" P, |- R& O4 o- A
FLAG_show=1;
5 s6 E1 M: R- O& K$ U% }break;
X& Z. I; V. H: a9 |}
3 T. r( y% b' r. t; T( A$ L, e8 \1 e. T/ ^1 l
}: M: T% o) D$ m x- [/ k6 R. y! L/ D
}; Q; o! Y, \) ]' [$ K
Sleep(20);1 ?' b w3 C5 k/ O: y; n/ Y
}
6 [/ r1 s3 { ^cleardevice();5 f8 ~& f# k# ^% n @
return 0;& W, H7 V6 ~' ^( X* j# F1 P; A8 e
} {0 H ~# ~* n1 C. J. a
int drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)
0 l2 t7 B2 |: P% w; D& V{8 G" B8 {7 B2 S$ G$ g
static int info[11][3],num=0;
9 R3 t) G. L1 i$ iint i=0,j=0,pos[10][3][2];
) i; D: c$ h. ~& ^' c1 d$ {float temp,t;
8 _9 A) Q) ]1 v1 G) d s//画按钮,不属于FIFO图的范围/ D9 v. u9 T! Y: E! [3 l8 d
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1)
6 A7 M- a7 m# \5 x8 R s{5 G7 @7 r" v- L4 I4 N
settextstyle(30, 15, _T("楷体"));
) ~' p; A9 ^5 a' Arectangle(890,455,1110,510);
" ]. k0 @& W/ u n0 n+ W6 }rectangle(900,465,1100,500);* x" z; e" Y% t5 P m* k# N
outtextxy(910,468,"查看运行结果");$ B% [! E' _) R9 R
}
& u7 `( R# \" J% B1 A//结束画按钮
0 s- _5 T# }) ^' z, ]info[num][0] = com;. k7 x" ~2 ]: O
info[num][1] = wai;
) n( N. k3 G- O" R3 }0 g; n" _0 Kinfo[num++][2] = cha;! E" X6 Y( d& p
if(num>10) //存储10个点; N2 B k9 m2 Q) V0 N' X
{6 p: ~% Z. }+ y
for(i=0 ;i<10;i++)! H1 a3 ]; m9 { k$ p# l
{3 k; y7 i1 M& s
info[0] = info[i+1][0];$ A1 b# M$ [9 ]) n$ x/ U; v
info[1] = info[i+1][1];
: k" j/ }' e5 }- `: tinfo[2] = info[i+1][2];
& O9 f/ p P! G4 X$ y- b; n! p' O" \+ S}
5 o/ ^, E( |2 f. x3 K3 enum--;
4 {. x' d7 `: v( P}9 _3 i. Q& _& h2 z: t
if(FLAG_show==0)
1 S f8 n6 `$ G( D2 hreturn 0;
$ S: c! @9 Z8 x) I. q7 f$ X, Jfor(i=0; i<num; i++)
7 l( @; L i6 k{
0 w& h0 N4 i9 N# bt = (float)info[0];. z' p; W/ |6 x' ?% {4 L6 E/ U7 w; z
temp = (t/101)*90;3 w: w8 p$ d& k6 j. r: ^
pos[0][0] = (10-num+i)*25+x+100;
) O3 W. n, ^' {6 C0 v# ]% ipos[0][1] = y+110-(int)temp;
* \2 n0 Y# x7 nt = (float)info[1];! ~. b9 b1 X3 ^2 t/ f& c( l
temp = (t/101)*90;
8 H" e2 E( ? L* m4 x e+ @0 q$ p# ]pos[1][0] = (10-num+i)*25+x+100;5 G# c: Z2 C4 a* Y* E/ e. ]
pos[1][1] = y+210-(int)temp;6 u5 t& Q2 q. _ n7 M! Z9 H! H
t = (float)info[2];* t6 t1 K: [+ |4 H/ c! M+ o, ^
temp = (t/101)*90;
/ R& b, \0 v& X q7 A, v) Npos[2][0] = (10-num+i)*25+x+100;6 F9 i& v! E5 k, {6 n, u
pos[2][1] = y+310-(int)temp;8 }/ K# R3 l @" B, f7 Y
}
$ R8 r/ z7 A: I/ [8 Hif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
" i6 c, b+ j& j o$ }8 r @{
. ]7 l' f4 r% H3 e2 I: ^8 w# [1 Pclearrectangle(x,y,x+400,y+315);5 a; D' I7 s1 r, D+ R+ L3 o/ h' @
settextstyle(20, 10, _T("楷体"));. }0 g6 y# K0 G6 g
rectangle(x,y,x+400,y+325);
; L% Z% K. {. ~5 k b4 souttextxy(x+40,y+10,"CPU"); //画柱状图& C! M0 f+ U+ F4 d8 J, t
outtextxy(x+45,y+10+100,"IO");# i) R, _7 z' P" R* T* G/ |' t q& S# a
outtextxy(x+40-15,y+10+200,"change");# R" l' V, G c! |& W
rectangle(x+35,y+30,x+75,y+110);6 b* `/ v: O! R, o$ X
rectangle(x+35,y+130,x+75,y+210);+ X7 N* F% o: l3 ]
rectangle(x+35,y+230,x+75,y+310);
! R1 N: e$ O; r; ]outtextxy(x+180,y+310,"FCFS");, H- c5 V% j% j6 O# e: d
t = (float)com;
5 |8 Y' K9 A3 mtemp=(t/101)*80;* n v6 k% U% h- ]" x8 o O
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
7 N- F9 E% L5 {- e2 X9 A Ft = (float)wai;* {4 L7 A3 }- P0 B
temp=(t/101)*80;
2 P! `# j Y4 N H9 `9 u4 R" x5 ffillrectangle(x+35,y+210-(int)temp,x+75,y+210);
. @& i: {5 m# \8 R4 \t = (float)cha;) A9 X" x: H, J8 [" z2 | o0 t
temp=(t/101)*80;
+ k- W4 Y! B* F: F" Dfillrectangle(x+35,y+310-(int)temp,x+75,y+310);% b g1 Q& t0 J$ M" ~/ y) H
for(i=0; i<3; i++) //画坐标 high=90,length=250
; z8 S7 B$ y% [: g% i9 \0 |{
2 I7 e0 S, H6 e5 Z4 O mline(x+100,y+110+100*i,x+350,y+110+100*i);
0 N% G/ k: I0 Vline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
: h) V8 N# A0 M' E/ `9 Mline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
6 N: a4 d' n9 U
1 y y5 b1 H: ^" ^line(x+100,y+110+100*i,x+100,y+20+100*i);
4 d) a5 J( B9 S+ [0 \/ n0 Oline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);' @0 k, P* Y# e" R# l9 }) ?! Q
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
U$ O7 ?* ^2 nfor(j=0;j<num-1;j++)' L }5 _% d7 {, r
{
0 k' Z/ n t+ X7 `4 A y3 Uline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
5 L9 P' q3 y1 n F/ r6 H; Fline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
2 q, f8 B3 @' _6 K. Cline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
X9 x8 Y" X/ b3 S' a}2 g* ]* [$ _3 a* f3 C) [$ ^
}
9 U z3 o3 f" f0 P/ U}
$ h7 x2 G0 R: u A0 t: i/ Relse if(FLAG_FIFO==1)$ ?4 N" E0 @" q9 R2 u# v. ~% S
{0 \1 P( S' D$ j$ S# C& l; M
x=0,y=0;
$ h. c5 p) i- ]$ y9 N) t3 Ffor(i=0; i<num; i++)
% d$ r! F) V5 ]: W4 U{
. n# c8 u5 t# @' S' ]0 n5 Jt = (float)info[0];
3 A$ Q% c4 x! `! N' ptemp = (t/101)*180;1 x k9 R( M6 y2 _5 e# t
pos[0][0] = (10-num+i)*50+x+650;
& G# O( L& _( T- c" y& qpos[0][1] = y+210-(int)temp;1 o1 ]) G7 ]8 r: C5 t# E* S
t = (float)info[1];
( j7 e2 U0 I/ [. I) J9 E* Ptemp = (t/101)*180;2 z" k9 V: \3 B5 @
pos[1][0] = (10-num+i)*50+x+650;
# o0 F8 _: @5 B6 c3 `7 |pos[1][1] = y+420-(int)temp;* }7 \( C O) t" c. W$ Y
t = (float)info[2];
0 Q3 a8 _6 `& Q7 D! Y/ F3 w! k+ Utemp = (float)(t/101)*180;4 j% K6 C$ b+ Y! z9 f/ z2 m1 d1 p- N7 x
pos[2][0] = (10-num+i)*50+x+650;! l& ~, R3 u# _9 ~' }
pos[2][1] = y+630-(int)temp;/ [: G7 y S3 Y( e7 W
}: r! x+ B( i" m& Z9 q- V
clearrectangle(x,y,x+1200,y+650);1 Y5 E4 T3 R# k8 [
settextstyle(40, 20, _T("楷体"));1 t x5 d* e# W9 j, j
outtextxy(x+50,y+50,"FCFS");9 n- c: C3 b7 x6 |' @$ r5 ]6 L9 I
outtextxy(x+280,y+20,"CPU"); //画柱状图8 V8 b/ O5 A: k( Z# c
outtextxy(x+285,y+20+200,"IO");
" m) l% f% w. v [- z x7 m; {* uouttextxy(x+250,y+20+400,"change");
% }& s N& a( ]2 R# Srectangle(x+270,y+65,x+330,y+215);& v7 N' H! m5 f9 e, c+ g
rectangle(x+270,y+265,x+330,y+415);! |" \6 Y% q' i" n& Y1 s* I
rectangle(x+270,y+465,x+330,y+615);3 I, g4 J. {' u( J5 Z- V+ J7 P
outtextxy(x+290,y+620,"TT");/ v/ L# m+ A! [' p0 S6 y
t = (float)com;/ J4 S; v$ s7 k _# ?- D
temp=(t/101)*150;, D5 m. r7 R x* `5 e# P s
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);7 y: x v9 q7 |" h, \: L# A& U. ~3 D
t = (float)wai;4 l' [9 h+ J, d1 D' E* r D
temp=(t/101)*150;
3 T e4 F0 \8 r' Lfillrectangle(x+270,y+415-(int)temp,x+330,y+415);8 o a1 N/ M/ h& G! @
t = (float)cha;, q! G2 d% y( n$ |( @4 T; x
temp=(t/101)*150;
: Y3 _: x5 W' K$ h4 x0 Efillrectangle(x+270,y+615-(int)temp,x+330,y+615);5 N- P" C* Q. B* C" L
for(i=0; i<3; i++) //画坐标 high=90,length=250: B, ]7 \' k0 Q* V0 C7 C
{
5 f+ y' K- G5 I2 c! Pline(x+650,y+210+210*i,x+1150,y+210+210*i);8 L- I) v; G3 t; p% |/ g0 I
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);* {' g0 x ?* v% P+ R2 i
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
- g4 J$ N6 c5 f* C0 T, u3 R2 D
: } w$ i) a. o3 mline(x+650,y+210+210*i,x+650,y+20+210*i);: v& j+ W# I; ~/ D; Q
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);& o# A7 `1 O n" u' G* V/ M
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
$ z G5 C3 ?( K7 A) J+ r7 C! Y; l* Tfor(j=0;j<num-1;j++)
. z2 t9 |, Z; J1 {* g; h$ l( k- y{1 D( t- E. Q% d$ W
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);6 L& V k2 M9 A- j$ s/ D
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
6 ]6 W; b! \' Cline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ) [. A% h" W8 ~9 P3 x! J
}( b2 a/ a7 N& z- D" R& ]
}
0 D5 {1 Q1 m* R$ ^" v* D- y' W}
9 ^: I) B8 k* \5 c$ ~, a1 |% I6 y) H
N) F: S. [/ }8 o' h& w$ i
return 0;$ ^4 p" h7 O- l6 {
}
2 T/ `$ H9 F# v$ Gint drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)
. S! x2 Y% S6 q0 h) n2 a4 @9 ]3 p{" s& |0 N X0 _; d3 c
static int info[11][3],num=0;( A% q) ], ]9 _& b/ Q% C
int i=0,j=0,pos[10][3][2];1 F8 m6 O- j7 J a o, i
float temp,t;
5 T+ X4 C$ \% B6 \! _+ @info[num][0] = com;
9 r1 J. `* C2 w6 S. Y' ninfo[num][1] = wai;
; m( [( h5 q( l+ |' S+ M: X% |$ Q0 \info[num++][2] = cha;2 q) F( P. W+ [1 M* o8 G, s; V+ o
if(num>10) //存储10个点/ `. H3 j7 i2 c0 \
{4 @: u: g" ~* `: a3 W; }6 F
for(i=0 ;i<10;i++)( ~* [) r) L: t* N) r4 u
{
" J$ J8 A: M* x0 n7 }' Minfo[0] = info[i+1][0];
* e4 a& S, E5 e$ Sinfo[1] = info[i+1][1];
7 A% Q( l: \% W. N6 \! {info[2] = info[i+1][2];2 o+ F- N, K G6 [" m
}
: H8 P" N4 s+ ~3 S/ H! P2 h0 nnum--;
+ b b5 q. E2 Y% S* }# H}: {2 Y" X& w' o/ g
if(FLAG_show==0)1 X; j) s4 v+ T8 h
return 0;4 W3 a& W; T' R2 M$ {/ B
for(i=0; i<num; i++)
7 J) {5 f4 C1 V0 E; r f{
`: [2 ~: C6 w. st = (float)info[0];
, U' P+ |% ], ` Jtemp = (t/101)*90;. f% j5 y$ _1 h8 F. J! y
pos[0][0] = (10-num+i)*25+x+100;, k0 v( e6 O: V0 Z
pos[0][1] = y+110-(int)temp; Q6 E7 n- D$ x9 ^+ P
t = (float)info[1];
( E! m8 t J: t% c% F# \2 j/ Etemp = (t/101)*90;1 c# K, A: T" z
pos[1][0] = (10-num+i)*25+x+100;% G9 S) F% ?: l( E
pos[1][1] = y+210-(int)temp;
! ]' ?; b3 N: i+ s" ]" st = (float)info[2];6 t5 P+ U+ A* t$ ^- ]. N
temp = (float)(t/101)*90;
/ _% n: k! v0 A% d! @1 J8 ?pos[2][0] = (10-num+i)*25+x+100;6 e! Y7 {; s- _) c. l; }
pos[2][1] = y+310-(int)temp;- @4 \+ X8 K6 f: B9 l* l. C9 v2 H+ p
}5 S. T; u; c; l# v
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)5 ?1 V8 k8 _5 R' A$ l' s
{
! T0 Y, O5 |8 k$ r! l" aclearrectangle(x,y,x+400,y+315);
7 V# \$ r# K. ~- \7 |4 [settextstyle(20, 10, _T("楷体"));5 D; h7 R; E& N8 Y
rectangle(x,y,x+400,y+325);
+ F* w$ e; ^" Z2 K' C: }# W1 Qouttextxy(x+40,y+10,"CPU"); //画柱状图
) `0 o( n7 V/ L) }9 aouttextxy(x+45,y+10+100,"IO");* C6 S' N$ _" s! I: `( k" ?& _5 x* e" h
outtextxy(x+40-15,y+10+200,"change");
/ |) u+ F; M8 @. u6 @% [5 V* l% _" j L* Erectangle(x+35,y+30,x+75,y+110);5 w! {2 P: y3 r$ t1 h l
rectangle(x+35,y+130,x+75,y+210);
, |4 o2 Y1 t {' V' brectangle(x+35,y+230,x+75,y+310);4 z9 B K, Z' B# u* ~* f
outtextxy(x+180,y+310,"HR");
4 F( L" V8 }; W6 G% zt = (float)com;
: u5 M" \; v2 \ x" D otemp=(t/101)*80;
3 B% B" v! y3 M6 z, Ufillrectangle(x+35,y+110-(int)temp,x+75,y+110);! M. ]2 ?: D8 p* G- B& m9 a$ I" I. b x
t = (float)wai;# X1 R/ E4 b7 v; O8 \7 Q
temp=(t/101)*80;
& E/ a @9 F3 d7 r( u$ V, Bfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
2 Z$ X" g, t6 s: N/ Z' V! A Lt = (float)cha;
3 l- c+ E! V, G( j+ P' Ctemp=(t/101)*80;
" K& ~% I$ k( S0 hfillrectangle(x+35,y+310-(int)temp,x+75,y+310);+ u$ ^, ~& s. `: z; K: C8 ~
for(i=0; i<3; i++) //画坐标 high=90,length=2507 ^6 ]$ |4 K6 K
{
9 e- X& C& Y( B B& Hline(x+100,y+110+100*i,x+350,y+110+100*i);7 d( q8 p# f# h2 |, O @5 ]9 C$ a6 F
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i); B0 j( y+ G) ^' K' b) @
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);7 ?" x, E! D' c7 R; Y. l# l- X
- F# G: _ K2 O x
line(x+100,y+110+100*i,x+100,y+20+100*i);
1 w, N6 }$ h' \5 Z* w: p1 xline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
7 x: X$ [9 N; x8 Sline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);; j- ?! O& @" ]# a# [
for(j=0;j<num-1;j++)4 q- Y5 h! y5 k h, Z C
{ K' x+ I' e1 @) h! ^/ `
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);( g5 q+ I! n" ^+ T! V: L1 z! i: l
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
# g) i8 ?. k$ L! i8 nline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
1 a* c4 X* M7 Z J% h" U}
* l/ y" i7 w% M1 R}
/ q% x3 J6 ^* ^9 ]! S}
! x" x; R6 i) D) c& uelse if(FLAG_HR==1)1 o5 h5 q* f& n1 R
{
2 i/ a' M) C1 y* I! I. \x=0,y=0;
& o3 A8 L/ d$ W$ O; W5 zfor(i=0; i<num; i++)
. H# y; f g5 ^2 _; E: `{
' I c5 |" S8 a' E; r0 {t = (float)info[0];$ K, ^, c! x7 {8 m* U% L
temp = (t/101)*180;7 |+ m1 V+ y2 r$ S; Q8 K5 c" p5 ?
pos[0][0] = (10-num+i)*50+x+650;* X6 A- a: j# g/ `0 O
pos[0][1] = y+210-(int)temp;+ s, v0 W0 {" U% \9 ~
t = (float)info[1];
4 ]# |( k8 O6 P! ?temp = (t/101)*180;
* k' `7 P* R; f" I" Rpos[1][0] = (10-num+i)*50+x+650;
$ f& g9 ?2 e: k+ y$ opos[1][1] = y+420-(int)temp;6 k* r. r( |, [2 q" A( f
t = (float)info[2];
2 E$ S+ @4 N! G3 L( O d% ytemp = (float)(t/101)*180;7 d" g' r! ]( x, b' `, Q
pos[2][0] = (10-num+i)*50+x+650;7 N2 Z2 U: \" U$ O* v8 X
pos[2][1] = y+630-(int)temp;
* {& K% i$ v. g+ c9 Z" o! x}5 Q6 B" E7 |' @ ]
clearrectangle(x,y,x+1200,y+650);
: r; E1 n( n/ e+ q; ~% A/ xsettextstyle(40, 20, _T("楷体"));
+ D5 S1 Y" L+ Y+ f; x3 B, A7 k5 mouttextxy(x+50,y+50,"HR");: h D+ }3 r! U- k" s
outtextxy(x+280,y+20,"CPU"); //画柱状图
- f+ B8 \: W* ]6 ]5 r/ F( Touttextxy(x+285,y+20+200,"IO");% X; I- ]# Q! [# b+ I
outtextxy(x+250,y+20+400,"change");
3 R O8 a' z) m7 x6 H* e7 H& vrectangle(x+270,y+65,x+330,y+215);
4 M2 U0 e+ J/ f; [: O2 ^rectangle(x+270,y+265,x+330,y+415);
0 g) D$ d7 ], V9 r9 w, C% P% Irectangle(x+270,y+465,x+330,y+615);
6 c) v! y, {, ?5 Z4 v( i; louttextxy(x+290,y+620,"TT");
* D: k7 a9 b9 l4 J4 F, ?t = (float)com;9 Q8 S+ q t: @; h- v5 k' B
temp=(t/101)*150;* d2 w, |# S, i5 T4 ?) [
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
: S7 J& ~- P# _0 j L( m5 q1 Ot = (float)wai;& ?& i0 D4 _3 T; Z( O3 u0 s' P
temp=(t/101)*150;
! R0 q' M* K" P- G- [fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
! n j+ m! ^3 n) p4 dt = (float)cha;. I7 w1 b! J( E9 \* l
temp=(t/101)*150;
* Q% a9 h' W- D& d8 Q hfillrectangle(x+270,y+615-(int)temp,x+330,y+615);
: Y9 F4 ~; H+ ?) _( E4 o) afor(i=0; i<3; i++) //画坐标 high=90,length=250
o/ y3 L. I$ m. W" k{+ h4 R; w( S# J. u
line(x+650,y+210+210*i,x+1150,y+210+210*i);
, t. U& o; x. U6 H. [line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
" |. K; `/ ?# i) Z+ J4 @8 bline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);7 J" Q$ X3 |$ t
7 i0 a6 ?' B3 J! ~( F1 K7 J4 Y/ N2 k
line(x+650,y+210+210*i,x+650,y+20+210*i);2 ]* q9 B% h* ^# v- ~0 O8 b- a) N
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
. P: a" V; k0 B+ Hline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);* Y6 }1 j4 c* Q: u. J
for(j=0;j<num-1;j++)
4 R0 O4 e0 y- r% p& ?{
+ U3 M+ a3 c% N, Sline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
% ^2 I, {# k; T: `line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
- f* G- x! X8 |* G+ e' ~line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ! @# C, ~# K: p2 h9 X0 M# K
}1 D2 A" | @1 k% d5 Z/ `% X$ E
}
( L9 ]+ M7 K6 Z5 E& x}$ D( k- `* H9 x4 K+ H( H& _& L- C0 N% a
2 R; q1 Q/ f) Q$ ~ I* ]8 G( b; ~8 I
( }+ _+ j, Z9 f7 Zreturn 0;! J7 T6 x# E$ l0 V" ?, l
}: z; o7 D* ` `! U8 z
int drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)
% P: y1 I$ n. C4 F5 S{, V" X0 y [/ @- \' D$ @0 i
static int info[11][3],num=0;
) _& [5 x2 L/ |- |) Bint i=0,j=0,pos[10][3][2];- D2 N4 N% h9 c" ]! g3 I
float temp,t;
; Q" R% p8 h7 G d+ @" o; Pinfo[num][0] = com;
/ C* O0 ^( q5 T* o" j& e# Tinfo[num][1] = wai;
, `3 A! F) `/ L) B( {( t' Pinfo[num++][2] = cha;% o1 w! s+ h4 R- a% \# r% D
if(num>10) //存储10个点
, j* L* x& K; ]/ p{
6 T, V9 h' Y& \$ D$ {for(i=0 ;i<10;i++)
; r# {! N; h9 |{) p2 K% d" n; ]# J/ v: Q" V
info[0] = info[i+1][0];
0 n) _3 f) g. l% G0 ninfo[1] = info[i+1][1];
% x. p: c0 C" h1 {info[2] = info[i+1][2];
* P2 ^; L! O7 Y0 r5 p}
/ |: b1 s( K7 p \5 ]7 s9 O4 N6 I2 ?num--;( J% U) E3 t* j$ x
}
4 z# k) B/ K$ ~; | W6 g+ uif(FLAG_show==0)
( {, H" O7 \( _4 X) @. breturn 0;, I( _0 b( R d( Y+ l. m- u
for(i=0; i<num; i++)
^7 o! l/ ?8 m' N5 x{
: n) e! o1 a! r* b6 ~( h5 {& Dt = (float)info[0];! P" _% t) K: O& m
temp = (t/101)*90;
4 H0 j/ Z/ i5 Lpos[0][0] = (10-num+i)*25+x+100;; G) K6 ?) Y# N
pos[0][1] = y+110-(int)temp;. ?, A0 ]2 B Y1 n. A. Q* I6 `
t = (float)info[1];
. A) a$ r5 K& \temp = (t/101)*90;1 _6 l7 l! ]5 I8 |. W6 W$ c; B+ Z1 n
pos[1][0] = (10-num+i)*25+x+100;2 H8 w: }# n- M- k( d5 D
pos[1][1] = y+210-(int)temp;
' m2 U' l% i! o- ~$ W% Xt = (float)info[2];
O: C7 e) q# O, d: Ttemp = (float)(t/101)*90;
7 C1 H8 D6 G' _/ zpos[2][0] = (10-num+i)*25+x+100;, H+ \9 K7 M7 A4 n( }
pos[2][1] = y+310-(int)temp;
% c* L6 y) h- j3 Y}8 i0 W _$ Q9 @ K0 E
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0): K! e3 Z4 `! n& D _
{
! K: m% p# e4 a& j7 y- s% Y. r( jclearrectangle(x,y,x+400,y+315);% x5 B# k$ r& k6 N) s: E
settextstyle(20, 10, _T("楷体"));
2 D. b \# R# Y- ]( nrectangle(x,y,x+400,y+325);
" k2 f/ ^% M k `6 C6 souttextxy(x+40,y+10,"CPU"); //画柱状图
) m6 P. O, I* ?; g9 I+ @7 }9 h- Jouttextxy(x+45,y+10+100,"IO");* n( e: _3 N9 x3 g# U' s
outtextxy(x+40-15,y+10+200,"change");! Z1 ]! M7 V; n
rectangle(x+35,y+30,x+75,y+110);; z+ N* x* Z- c" A7 [. b$ j
rectangle(x+35,y+130,x+75,y+210);
% H. V! K' o" L) erectangle(x+35,y+230,x+75,y+310);3 `; A% X( G6 n8 `! E
outtextxy(x+180,y+310,"TT");% O% }( F) R$ L' |' W; |+ t
t = (float)com;/ x; B' z9 |8 @/ Q% P
temp=(t/101)*80;
+ F6 b: D9 b! z2 l2 {/ wfillrectangle(x+35,y+110-(int)temp,x+75,y+110);( S: F- U) d2 n, b
t = (float)wai;
5 i+ s6 Z6 r$ M# M: l2 A" ktemp=(t/101)*80;7 M( T& u9 L; s# C: X8 W
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
+ i: A3 [$ p5 [6 H: z4 Tt = (float)cha;
0 N- I4 `# n& j: q' q2 rtemp=(t/101)*80;+ V7 j4 U4 D3 Q/ t/ ~
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
( }- O# V8 O9 P- V+ Lfor(i=0; i<3; i++) //画坐标 high=90,length=250
! B8 D# U+ a% Q{
2 k& O# q+ i$ l/ Z3 qline(x+100,y+110+100*i,x+350,y+110+100*i);
+ y6 M# n1 [1 c$ h5 x6 y0 gline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);1 w, V6 ~. ~5 a/ n6 ]
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);8 ~, h3 N7 m4 i+ S9 S1 {
: y9 K, w# @3 u, P! j& iline(x+100,y+110+100*i,x+100,y+20+100*i);
% H9 U2 O/ j$ P& s" Rline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
1 h+ K! [5 N9 g2 v. ^- h' uline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);' A* b* q) M/ v, A6 T& Q
for(j=0;j<num-1;j++)4 b3 _0 P1 ?) d6 v! m7 c7 k
{8 y, K6 y% C4 h' _; f! n
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);$ Y" M+ _2 b* ^! o# K# p
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);- R6 d, c- l; g/ U# \0 z p
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); % \; n' g, g3 A, J4 u( L
}7 K* e1 R J3 m! U) ^
}" ~. V; q7 a ]9 D& x9 {
}9 ]5 Z% g- I5 G4 K1 r
else if(FLAG_TT==1)
$ I) M j( M c: o+ [" k{
! M+ V% x' J2 j5 lx=0,y=0;
) I5 v* r" \5 |2 A I) S$ Dfor(i=0; i<num; i++)) f6 S2 P7 D. k/ {
{
# A0 k' m: u* K' ^6 X9 i- i( Y2 Q; D6 Mt = (float)info[0]; g3 D9 O5 f) i" S4 z! f
temp = (t/101)*180;+ {# Y i" i" L! ^, X& z
pos[0][0] = (10-num+i)*50+x+650;! L- ?0 ?4 }' w, a$ z
pos[0][1] = y+210-(int)temp;$ u" }: f, y4 ? i. U
t = (float)info[1];
, u! E, S: h& Z; D5 ttemp = (t/101)*180;3 d7 |# B& Z" M7 C
pos[1][0] = (10-num+i)*50+x+650;
5 ~& p/ ]! Y5 X1 D4 ^$ n" L& lpos[1][1] = y+420-(int)temp;/ s* h9 h9 m1 ?- U0 @5 o& H. z2 {- m4 O
t = (float)info[2];' q8 r4 v6 G- F2 a0 J% z
temp = (float)(t/101)*180;
/ i* ~- [7 F1 G- @$ E. zpos[2][0] = (10-num+i)*50+x+650;
& n8 G% g0 D. L1 ]/ p7 E8 jpos[2][1] = y+630-(int)temp;) P8 O) X# n# o5 f( L8 y
}* q/ J* a" x# _3 ]( J8 s, U
clearrectangle(x,y,x+1200,y+650);
9 F7 @+ w2 `- p' i$ B. b' n5 G3 |settextstyle(40, 20, _T("楷体"));9 @8 z1 {% `3 F* d |6 k8 t
outtextxy(x+50,y+50,"TT");
' ?7 n; }* E6 K* }: \outtextxy(x+280,y+20,"CPU"); //画柱状图; G6 h9 w' b. x% [: L8 M
outtextxy(x+285,y+20+200,"IO");
$ }1 H6 F! m$ O' ^( ?7 p, q7 |! n, Youttextxy(x+250,y+20+400,"change");7 k6 D+ L6 A: U
rectangle(x+270,y+65,x+330,y+215);7 |* f3 O- l# [
rectangle(x+270,y+265,x+330,y+415);
' p, E4 ?3 n2 ?: t) Y$ Grectangle(x+270,y+465,x+330,y+615);
9 w( j9 Z0 ^6 @, ]! L' xouttextxy(x+290,y+620,"TT");/ `8 g1 H* g Z; H1 X1 [ c$ J
t = (float)com;4 h) f# U- \4 v& P9 T( W( G( ^2 u# {; D
temp=(t/101)*150;5 S5 c' u8 u$ t" E2 Y$ l
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
9 f% s! l! O/ gt = (float)wai;
( x5 {0 b# s- d, ktemp=(t/101)*150;
* R; V5 `# p6 T! [- {2 e/ Q/ C, ]fillrectangle(x+270,y+415-(int)temp,x+330,y+415);% k" W! H+ P! y8 T* z6 l# Z
t = (float)cha;
# C( C7 }( K! s& g: dtemp=(t/101)*150;! h4 b7 j& d& m" X0 f; J4 L1 }
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);/ `6 M6 i% L* Q
for(i=0; i<3; i++) //画坐标 high=90,length=250
4 |& d9 F W2 t/ k3 u7 [7 z{0 B5 r8 r8 T9 q' O8 E( j9 |
line(x+650,y+210+210*i,x+1150,y+210+210*i);5 t1 X& D- }0 a
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);3 S1 Y$ p. E- h0 h- E" v
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
1 z4 }; k0 |( X" b$ x& P' c
2 r9 I" K+ b V( S+ Q9 Vline(x+650,y+210+210*i,x+650,y+20+210*i);
' p8 u. v6 l6 jline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);7 l3 Q9 s# A" G( a0 X/ M
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);4 A; v% {+ h& M3 J0 c
for(j=0;j<num-1;j++)3 k) H& B" j4 \& I7 @
{
/ P, x( r! X! b8 V* t- nline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);' M5 W% p. O9 D' B5 W
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
% L. C3 ^1 C | y+ E2 U5 Pline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); : Y+ V* I0 r* R+ Q% P$ g/ ~
}
$ U5 E$ B6 k5 f! h* X}
7 @* O% b" o# y}
" W2 n: `2 Q6 `9 m7 p6 T/ m- |$ U) ^
) a/ m, @5 o* D) }& F3 B2 w) f; n! L3 g9 V# V' O
return 0;
$ C$ {# R6 }6 p, |% i% O6 m}. }3 a; \3 S3 @5 t N! \# [
int drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)% p1 {0 a5 R6 X: x4 a5 v p
{6 H- a0 q; M4 s) s
static int info[11][3],num=0;0 a8 F" g% p+ ~
int i=0,j=0,pos[10][3][2];
1 ], n0 n- e# l4 |# @float temp,t;
2 Q8 e! Q& q7 {info[num][0] = com;
# c5 I: F" k: Cinfo[num][1] = wai;) [# q0 u J3 U K5 ^
info[num++][2] = cha;" ?, O- y" k7 {: o
if(num>10) //存储10个点! M" R8 v, J: A1 u2 o
{
5 \: _. Y3 l: U6 O1 H) Qfor(i=0 ;i<10;i++); T4 I* ^# q( e4 @
{( }8 W" |! B4 Y) K h+ L& A
info[0] = info[i+1][0];
' S: \0 G8 \6 p) b, F, Iinfo[1] = info[i+1][1];
+ O: b/ Z- {0 j9 U" ginfo[2] = info[i+1][2];; s2 |. M! ?# N0 P9 c4 [
}& r) y+ p u- g0 h, `- G7 d8 ^
num--;" q4 W8 _* _$ Z3 o2 j
}3 [$ m1 ^) j Y- Y) N+ p
if(FLAG_show==0)
y* D8 Q; [$ w0 X- Greturn 0;
0 w6 `5 R2 \& f. G& w! sfor(i=0; i<num; i++)
& d+ w/ {+ h( ?{
; W) s6 Z* a/ p6 b% H$ Y9 ]t = (float)info[0];
; l* |' P; ?4 N3 R" ztemp = (t/101)*90;
+ O2 u1 f0 P" h' O1 P' f( }) apos[0][0] = (10-num+i)*25+x+100;* J3 ~& Z0 w9 q4 M" g
pos[0][1] = y+110-(int)temp;2 f3 O' J& O' j# l
t = (float)info[1];8 I8 _# g _) Z4 `! |7 {% c
temp = (t/101)*90;
$ w5 u! a! b7 F: `3 i& m3 W* hpos[1][0] = (10-num+i)*25+x+100;1 d+ v1 H0 ?, b6 @: [- P
pos[1][1] = y+210-(int)temp;- F7 _+ _" E+ w
t = (float)info[2];- y3 M, \' m, Y1 K0 U: X
temp = (float)(t/101)*90;
) Q9 u2 }8 y2 Q/ U0 F4 J3 opos[2][0] = (10-num+i)*25+x+100;' t6 n% M2 g3 ~
pos[2][1] = y+310-(int)temp;6 T# Q# b7 C2 h; f, O$ S! `
}
4 L0 \; ?4 W# F i4 m1 Gif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)+ J/ M6 B% K! n9 u% ]) a
{: o" ]/ w G' M$ s% }
clearrectangle(x,y,x+400,y+315);
* o: J- z Q) O U: Bsettextstyle(20, 10, _T("楷体"));
1 _, M Q' g c X' s' A* l* z! krectangle(x,y,x+400,y+325);# x) n$ |5 B+ l) A6 z6 p0 Q
outtextxy(x+40,y+10,"CPU"); //画柱状图/ D# y+ T3 B- ?- p. d% m) Q
outtextxy(x+45,y+10+100,"IO");" i, Y- R2 r7 ~4 u+ K
outtextxy(x+40-15,y+10+200,"change");& L( @ J& v: _' B6 R% a
rectangle(x+35,y+30,x+75,y+110);
; _+ z" W* c2 zrectangle(x+35,y+130,x+75,y+210);0 o! @1 n4 l2 z" H5 Z2 Y- s
rectangle(x+35,y+230,x+75,y+310);2 n" \7 x- w8 M- }0 u
outtextxy(x+180,y+310,"PF");
9 X5 t1 M- ]3 q( \: v& Et = (float)com;2 u; B# N! t2 y& {, [ C3 C
temp=(t/101)*80;, F, @# t8 K& W$ M; [1 ~" C
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);9 x5 y$ T3 X) U) Z6 I" c
t = (float)wai;
" C* e0 u( M- X1 {6 etemp=(t/101)*80;0 k; \% Q3 w, Z. X+ ~+ l
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);/ n8 P( w$ Q; h# o/ B/ \( c
t = (float)cha;2 F s: O: n- z: }4 e
temp=(t/101)*80;
) ]' `* @2 n- j' C1 h9 Pfillrectangle(x+35,y+310-(int)temp,x+75,y+310);! z3 h5 C# T" I* e
for(i=0; i<3; i++) //画坐标 high=90,length=250
% A+ A$ z5 s6 Y9 j$ k7 f0 C2 S{
9 J, P, ^1 A1 c3 d2 {1 yline(x+100,y+110+100*i,x+350,y+110+100*i);
6 w# s& I/ d3 F! `9 V/ ]( yline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);! [8 I7 d R& E7 x! y
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);) N8 O" k L: k. \( U, H$ D: ?
+ z3 R- ?0 p& L. h
line(x+100,y+110+100*i,x+100,y+20+100*i);
- q3 n! T; {& S7 Bline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
: [+ C4 O! c1 @line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);- J: j3 o, r2 h4 A, ^# l, J9 I
for(j=0;j<num-1;j++)
: q2 \; ]9 R# [ x k" U{
I0 [* A0 p9 d5 Uline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);* z3 W9 m* P: T6 [
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
* h/ G* W2 m* Z0 \line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
% B/ q1 s) ^* g9 B" Z}! t) a& u! W3 \" D. E9 \9 B
}" r! l. W; y+ s: t9 Y
} ^2 B5 Z/ z; [7 C# A
else if(FLAG_PF==1)
8 k# ^5 d! Y) U{
! E! E$ \- F, Q: w2 @" gx=0,y=0;
' F0 ?' S4 H$ z9 c# }) ^; {) u4 bfor(i=0; i<num; i++)/ D4 K$ |. b! V; l! F
{
, L" E( ?$ p# Yt = (float)info[0];
- G5 }/ z) `9 [0 _, J, _+ wtemp = (t/101)*180;* N" B0 Z! v( y$ E; y3 e
pos[0][0] = (10-num+i)*50+x+650;
( }, p; v: F% Cpos[0][1] = y+210-(int)temp;
7 w) e; I* y# ?4 T ~ c2 Nt = (float)info[1];/ D" }4 N G4 q6 l
temp = (t/101)*180;0 }' F2 O6 N2 s* a
pos[1][0] = (10-num+i)*50+x+650;
" e* s- C$ ]8 S: X2 r+ J* cpos[1][1] = y+420-(int)temp;
# p, E5 L3 k) n7 ut = (float)info[2];
# O& W- g; y* @6 M! g' o* Itemp = (float)(t/101)*180;& K; Y5 E" S- [3 R8 C7 T, ^3 s
pos[2][0] = (10-num+i)*50+x+650;" I V" s) G- l6 [
pos[2][1] = y+630-(int)temp;! A# j3 A9 ^4 Q) Q' ~. m6 z
}/ x' v; ^4 f" P0 k9 ?
clearrectangle(x,y,x+1200,y+650);& R$ l4 I# Y2 [% o8 V/ R q
settextstyle(40, 20, _T("楷体"));
8 W% L* E9 j! ~outtextxy(x+50,y+50,"PF");
8 W6 }: T9 h ?8 Fouttextxy(x+280,y+20,"CPU"); //画柱状图
% O! L7 |; [: e% pouttextxy(x+285,y+20+200,"IO");
3 d- m* x `9 j" O1 d9 s( N! B* v) Louttextxy(x+250,y+20+400,"change");
1 B/ F m* ]& e8 hrectangle(x+270,y+65,x+330,y+215);& S: |& ], [9 P/ w6 V$ Y. E
rectangle(x+270,y+265,x+330,y+415);% l. q* `/ r0 U3 [
rectangle(x+270,y+465,x+330,y+615);
- x2 d5 Y' L! nouttextxy(x+290,y+620,"TT");5 E+ k+ l9 j1 ?1 l
t = (float)com;* V- r O1 _7 H5 p" f% ^& L
temp=(t/101)*150;5 ]& o$ Z: \* P, v( _! O* _. [
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);1 L8 F7 y f2 F2 W' a4 O
t = (float)wai;& d3 L. V, j, R' ?8 N: N+ N% p
temp=(t/101)*150;
/ y! i3 C# J. B' k8 ^# Pfillrectangle(x+270,y+415-(int)temp,x+330,y+415);$ W$ K/ m" r$ P) j% h/ k
t = (float)cha;7 K7 ?. s. E ] A9 O" w7 U
temp=(t/101)*150;
! F+ Y& x6 P& `fillrectangle(x+270,y+615-(int)temp,x+330,y+615);6 P) ` N. s! ~! B
for(i=0; i<3; i++) //画坐标 high=90,length=250! Y5 A6 B! {9 o& C
{2 d1 O2 T: M- f' ]3 a
line(x+650,y+210+210*i,x+1150,y+210+210*i);! f. G: Q, j8 F* | W. |! u
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
! w+ z+ I2 p3 w+ G9 @% J v& M' vline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
; u. O: P3 ^- @ x) E" g$ X9 B4 K+ S& j* V
line(x+650,y+210+210*i,x+650,y+20+210*i);
! u Y' A2 K: \( Z) h. Vline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);0 ^) c% h0 {6 f. B: [
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);! u, \! |2 ?# G6 j9 J: ]
for(j=0;j<num-1;j++)
- r% U2 a( U8 F/ M6 h{8 `* Y6 ~, d; z3 |+ ~
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);# @$ q6 V' h. @& r' J
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);& R; o" v- F" X* Z* a9 }4 [
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
2 Y- m$ d: @9 ]1 X6 n}9 R; x9 H8 R, D i
}
% L( M+ ] I0 N0 }1 O}7 T1 k- ^( g4 k- ]& f
return 0;6 c# X9 ]1 Z y, V: l0 k
}
! i( ]6 p$ L+ d- P* r w" zint drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)
- D& C. f! r6 w# y _6 Q{) u0 b# I* P3 A0 ~+ K! \5 ?& Y: p
static int info[11][3],num=0;
2 j1 N2 i5 f ]3 [int i=0,j=0,pos[10][3][2];
+ _) `8 \) q J' V5 z$ Ufloat temp,t;" W- ]- R& L3 i+ \) K) g' @# U
info[num][0] = com;
6 o" l8 g/ L& k2 H4 p' w. Pinfo[num][1] = wai;
7 L" U! v5 k* c! [. H7 M: q6 Xinfo[num++][2] = cha;
4 o- f; o# L% A/ y$ y/ U* S* nif(num>10) //存储10个点/ e/ M4 X( a- d
{) f& m# b$ r6 L5 L0 L [
for(i=0 ;i<10;i++)# T7 Z( L. `( \3 ~7 X" c6 k0 C
{
; J. [4 @3 w8 M" ?: rinfo[0] = info[i+1][0];% o3 {( D) f$ q- D6 a5 m, S$ k
info[1] = info[i+1][1];
6 E) q( h/ [; }, h7 _1 rinfo[2] = info[i+1][2];3 S7 h4 N6 O+ u, z: m! g* V/ d$ }- j( H
}
, F# P3 p/ C) B: o. knum--;
8 B0 ]1 t- \4 I* n/ S}% q& M& Z0 I- |. O& j# O
if(FLAG_show==0)6 c' u- t7 x, N/ U# u
return 0;3 e( x; x/ s# @, \( x- d
for(i=0; i<num; i++)# A5 _9 C- h- K9 L, Y- Q3 V
{! b2 y& n& o4 U& [3 f2 q' @
t = (float)info[0];, s, ~1 J3 {& E' @+ H# D
temp = (t/101)*90;
2 H' ~, z% G( m0 x( Y& cpos[0][0] = (10-num+i)*25+x+100;! S& c: m; g2 _$ Q4 I
pos[0][1] = y+110-(int)temp; _: t$ L9 A; g$ u+ p$ D
t = (float)info[1];& b$ L7 h: w! G( V
temp = (t/101)*90;
. ]; f `# R7 ^$ f rpos[1][0] = (10-num+i)*25+x+100;; m1 i: a) Y8 X$ K* r
pos[1][1] = y+210-(int)temp;) S3 ]; e2 i5 c, {% [) p
t = (float)info[2];
+ M8 k* k6 S6 j" {4 n8 ]temp = (float)(t/101)*90;
3 ] ]7 J1 z5 m- F `) {% B& `pos[2][0] = (10-num+i)*25+x+100;
0 q& L2 s3 {! q9 W# W4 z5 Npos[2][1] = y+310-(int)temp;
( J! j5 z+ j# _) \; A}
; f2 w5 r/ D, _4 I: l1 d9 xif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
' y1 f9 V! A* ^8 M{
5 x1 ]! f. g& Lclearrectangle(x,y,x+400,y+315);7 Z- J, D- _ e
settextstyle(20, 10, _T("楷体"));
9 H V) D6 a" |7 @! W. ~+ f; ]rectangle(x,y,x+400,y+325);
`3 h9 o7 f, |# M8 j2 F. V% eouttextxy(x+40,y+10,"CPU"); //画柱状图% |: j: j9 p2 Y O7 g2 {
outtextxy(x+45,y+10+100,"IO");0 l) o2 \7 {" Q
outtextxy(x+40-15,y+10+200,"change");
+ c; d3 A) m0 |) j# }& k" }: K9 [rectangle(x+35,y+30,x+75,y+110);8 |" `$ e4 ]. W; y2 N/ v
rectangle(x+35,y+130,x+75,y+210);
* z! `! i) j {$ n( {rectangle(x+35,y+230,x+75,y+310);
& T3 z8 x$ h. u7 G' R3 H9 n8 v" Gouttextxy(x+180,y+310,"SJF");
" n8 p; y& p. O6 F# C2 Jt = (float)com;; G3 _2 g' V6 p
temp=(t/101)*80;+ s/ B: {7 C6 z2 J2 \! N
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);- `$ U, }4 h+ \- k
t = (float)wai;
% G. t& g& r0 u- p8 Ttemp=(t/101)*80;
6 o. \: }5 \/ a! Y9 e( ^fillrectangle(x+35,y+210-(int)temp,x+75,y+210);8 b" G# Q$ F; p k1 q j; u5 G
t = (float)cha;! f& A( b# C% u" _
temp=(t/101)*80;: X0 l" m* ^& d7 Y w+ t) P# d
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
7 s* u% C _/ ~+ W' ?- c( lfor(i=0; i<3; i++) //画坐标 high=90,length=2508 N' b% v+ @" e3 ~& ?3 e
{
3 w8 Z+ S1 k8 u; {line(x+100,y+110+100*i,x+350,y+110+100*i);
9 ]& P9 S9 Z5 [line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
0 `8 ]. D9 A7 r" x0 G7 eline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
5 W( s& [3 X, K- O
% b% O& T, G$ Qline(x+100,y+110+100*i,x+100,y+20+100*i);
/ f( K* k% P h% d8 A8 Wline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
, d6 f& [2 a* l- }6 H- hline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);! X' D: Y- r1 `! X" \& d
for(j=0;j<num-1;j++)% W8 P& ^9 A8 n M$ `8 [
{
. X9 x) ] S5 N5 l' \. T4 |, Sline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);$ Q4 k$ ^' K" c8 i
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
{( O/ r) H1 t$ lline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); - g1 t( I0 o3 B0 O. r8 m4 L
}
( G/ F0 E# l ?" n8 Y) g}
4 N. t: [" m$ v# \4 i& S) E}7 W( m. j3 N" P8 a
else if(FLAG_SJF==1)
$ w6 w1 L3 Y8 U% l1 L{
' T; R# l; i0 i- |, P8 G. V5 N5 @$ _x=0,y=0;6 }; i, `" C) H V' F
for(i=0; i<num; i++)
0 m4 ]+ K% T' _6 P3 `{4 K+ F W# R3 C
t = (float)info[0];3 `4 v) d' \ m' l. T1 }
temp = (t/101)*180;
* R9 L D/ i5 k* w6 N/ Rpos[0][0] = (10-num+i)*50+x+650;
4 T% N8 x2 `: Ypos[0][1] = y+210-(int)temp;
* k. n* ] D" ]8 C* ~$ gt = (float)info[1];8 N0 m- s0 L5 @1 W# Y2 K
temp = (t/101)*180;
' A T3 A, G/ p2 s# f' r1 Rpos[1][0] = (10-num+i)*50+x+650;
4 u- m3 m% L j& p, o) c: Tpos[1][1] = y+420-(int)temp;
8 {8 n3 u. L2 _# ^& Lt = (float)info[2];5 t/ c4 k1 C- M
temp = (float)(t/101)*180;
4 N% n: V5 q2 J$ t4 Q1 d$ z( {pos[2][0] = (10-num+i)*50+x+650;6 ~7 @/ z+ t. B% l, w2 f$ v
pos[2][1] = y+630-(int)temp;, ]6 a* I$ e; e
}
S0 m7 I( c+ x' I4 fclearrectangle(x,y,x+1200,y+650);7 h2 O" d- o( ?. c- Y
settextstyle(40, 20, _T("楷体"));
' T; @: [# E' k0 q, {% C4 @9 G. k$ gouttextxy(x+50,y+50,"SJF");- @& t; B2 e7 s% R2 K( B/ x0 z
outtextxy(x+280,y+20,"CPU"); //画柱状图& [1 m3 S. ~# c: t
outtextxy(x+285,y+20+200,"IO");6 }+ a4 M1 q7 g$ P- A
outtextxy(x+250,y+20+400,"change");6 h9 D3 ?7 p. p& O- p
rectangle(x+270,y+65,x+330,y+215);% A& V& q" C7 ~& j1 Y R
rectangle(x+270,y+265,x+330,y+415);7 W F* b* }8 x7 b; J# A
rectangle(x+270,y+465,x+330,y+615);1 h) E) V& G8 X+ l
outtextxy(x+290,y+620,"TT");
J- @' m+ _3 h3 P' _t = (float)com;
4 c0 {0 @. h: w- E1 Xtemp=(t/101)*150;
6 B1 k+ E. n$ x) X: efillrectangle(x+270,y+215-(int)temp,x+330,y+215);* f1 ^) l; U! p" L) [
t = (float)wai;
2 r9 H# h4 l/ j, |temp=(t/101)*150;+ B a. ^. }. ]. K( y0 c
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
( s$ A$ I8 ]' |: j# y: H% Xt = (float)cha;
) n' E0 w+ W$ M# b; Dtemp=(t/101)*150;
W: R8 y, V4 X* Wfillrectangle(x+270,y+615-(int)temp,x+330,y+615);& |3 |& [2 f; H1 X' k0 o- }, ^2 w
for(i=0; i<3; i++) //画坐标 high=90,length=250' K4 v. L9 ?0 N9 U0 B" F2 X
{8 F; s0 H# U" A
line(x+650,y+210+210*i,x+1150,y+210+210*i);
6 K# S9 r) L6 K' d3 pline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
, Z3 k7 |: E6 x5 d4 f$ L9 _' kline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
( g. q5 z! Y3 u- ]1 U% O: m6 l9 j5 b& T( ^! p0 z
line(x+650,y+210+210*i,x+650,y+20+210*i);
8 F, l& U4 q1 g. Y1 Lline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
2 J, d" T7 I- G/ R5 t$ n: Uline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
* t+ |" M5 e9 e/ o& b; v1 xfor(j=0;j<num-1;j++)' \( N, k4 y; j3 a9 u
{% _- S% a2 d$ \* m7 E* L3 k# _
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
6 j. ?' |8 N+ p" k. [line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);, j# V' l2 A: P4 {4 I* Z/ l2 o
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
+ o: G3 J: V, ~1 d; [}
4 T4 R3 g4 u0 Q: I) u}" W( ~; J4 v1 u6 S
}
7 V: A6 k' S; I' r5 s8 O. Ereturn 0;4 }# K9 l) Z0 N9 I2 I4 u# m
}
0 O5 k4 u8 ^8 y0 B- oint High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
& u4 J4 W0 y( i- |6 R0 Z{
" i& B c, L" H( [0 Z+ \* Rstatic int compute=0,waitio=0,change=0;
! j5 s; ?+ L& ?3 Sstatic int computeLast=0,waitioLast=0,changeLast=0;) e$ W6 S0 ^) b, n5 ]$ Z5 p
int i=0;
. l+ i6 m/ Z0 ?if(draw==1)
$ x( U% K" K* L# r$ Q& Y{
" P7 [: D4 ^( @3 i9 H//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);2 o% k- A' ^" G5 n1 L
drawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);# C2 f- g2 ~2 r7 a3 f, C) \, m
computeLast=compute;1 R; _ k2 y8 W8 L
waitioLast=waitio;. z( S# V7 d) |' s' t) ]
changeLast=change;" j7 ^! O& W# I) `. G0 Q
}0 w# @. d" b6 F O/ Y& i1 \9 W
if((* memory).p[0].flag==ready)
+ P% N8 i! T9 c8 v* [- Y(* memory).p[0].flag=computing;! x# r; i0 g( S
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
/ g! t0 B: \% G2 T! O2 _, B" S{8 F- }# m6 u, W/ |; { g- p
i=(*memory).p[0].computeNum;
/ r/ ]2 b6 D/ j+ Kif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
# \0 o( V1 G- Y3 Z2 \# }/ i{
; T( u4 r) ]: w3 `(*memory).p[0].flag=IO_waiting;. H% Q. u. X$ e4 v% {0 l- L- m
(*memory).p[0].computeNum--;
n- k$ w( m( H2 B9 |- d) zchange += exchange_IO_Compute;
( u* ~: D6 T9 Z0 q bcompute++;/ J8 I& r8 z5 [) x4 _9 `
}
4 h# c* L: `% n' o. x5 telse
; [, s1 H% u' M8 H{
! A( h' p5 X) X0 a* @& _compute++;
6 H: x i* c. L3 e& v w}# s% o( H4 B) O A0 W% k% O! H! [
}
# Y1 P2 M; t8 |# A$ X* B. `9 celse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)$ m" B, V+ s3 a% O) Z0 J
{
0 P( E5 y7 Z# p; Y6 X: f& u: \) h- u, J( p8 ~ ]* |+ r
i=(*memory).p[0].ioNum;
9 o5 y, g: @) F- O m/ W" hif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed/ ^- b4 i+ x5 }; N7 N2 o0 W
{% G# c( p4 R5 m
(*memory).p[0].flag=computing;7 ^& _: t/ s2 S9 n& O2 R
(*memory).p[0].ioNum--;
" T0 h- e4 I# Y; P2 pchange += exchange_IO_Compute;+ R( x+ f) C) V1 a |! s
waitio++;
; q8 O8 ?% b, P! l. W}% C0 G- J: Q$ I5 j; t
else: |+ ]. w) [/ ~4 @) ], C
{! y0 x" u; N: }1 K; s
waitio++;- z1 ?- L/ O5 `
}* V; e' b# I: K. T S, f6 ]
}, }; K: k3 [" P
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)2 }+ v+ `" R: j- k& \( M$ e
{
3 e: ^# s5 U3 Z9 g( y8 Z(* memory).p[0].flag=IO_waiting;) p0 |9 X; o" p
change += exchange_IO_Compute;- Y: A* y/ }4 l9 n5 L
} C* O% E7 E9 q1 d# f( d: u% h; \
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
z. n, A, H( ]{: T5 ~" F. Y! h/ _3 S {& ^
(* memory).p[0].flag=computing;4 K6 g9 T: l8 Y2 N8 w) B* O
change += exchange_IO_Compute;
, `9 ]. N6 R3 y}" v3 z. ~+ {# j& p7 r; q
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成& s3 P8 _9 O# G; \4 h
{" d: k% Z. w: R; d
(*save) = (PCI*)malloc(sizeof(PCI));
, }& v1 E: V6 m- _/ @6 ]! }(*save)->next = NULL;
: [# \, C; M' Q6 T& v(*save)->processID = (*memory).p[0].processID;
( ?0 n0 U% S" c* f* T& F% X4 Q$ n( S(*save)->comeingTime = (*memory).p[0].produceTime;
: d6 ^* Q2 \5 h# x6 m/ C; E X$ F" J(*save)->askMemory = (*memory).p[0].askMemory;
( O3 i& o/ U3 F1 t( U+ ?6 D$ X; u y# [(*save)->compute = compute;
* M5 b# Y$ O5 n4 p# X(*save)->waitio = waitio;+ [$ ]" v9 o. T# {; s' ^1 F
(*save)->exchange = change;
2 i1 r' F7 Y5 Y- \0 O+ e3 ~(*save)->completedTime = systemClock; B' P: x5 M$ I9 g% N) ]
(*save)->runningTime = (*memory).p[0].runningTime;
9 f- X1 n* [0 C' Q- s) V% @*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;
( _$ C' L7 l. o- icompute=waitio=change=0;
! S w6 z3 k4 H' G# X; @* i6 EcomputeLast=waitioLast=changeLast=0;+ S& `" N2 W7 X! K- _
High_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);" p% _) }; e) h( b, R8 |8 x
change += exchange_process;% V1 u8 w- _1 w( K8 C3 F
return task_completed;' ]4 B% }6 Q6 w9 `- m! }
}& g+ b3 R. A- g7 n$ t
else
$ c0 \/ m2 ^: g/ }1 A9 Areturn task_not_completed;) B8 ~$ O5 j% J1 F/ {4 o
}, k6 w! _ u* J/ H( H7 ]+ Z
int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch); M6 j6 X! K# ]9 ~1 V
{9 \3 H, }$ k0 V3 U$ ^- F9 z
static int waitTime[initProcessNum],i=0,j=0;
, U0 k Y p: Jstatic double HR_ratio[initProcessNum];4 q, D* ~+ R* w2 b* @0 N
if(flag==0) //初始化数组
) |$ G1 v, X, x5 S/ i1 _{
' d( q0 q- W z- n9 v" M+ A4 efor(i=0; i<initProcessNum; i++)+ _) w3 z- A* V/ L8 n! V
{) {9 B( S p% [5 u) t
waitTime=0; J/ t# d) V5 |' S, j$ \
HR_ratio=1;& c8 c! w$ {! m# |
}+ l2 R) K# J* x6 A
}
8 ?* T7 b2 F+ I% m0 q: J$ B; nfor(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比
" }. K8 o: W) G- T, I{
" F9 {: K1 m* k8 C" F. fwaitTime++;
2 O, V+ u& }* n- i2 \, I6 f* zHR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);
$ A. X+ A4 j8 k/ b1 B( `if(HR_ratio > HR_ratio[j])
. [) y9 a; F. c. _$ w8 T9 l0 H: |j = i;
: W/ W& J. j; Z% P}
. [8 I X y$ C5 x: W8 o( Pif(dispatch==1) //需要调度一个进程到内存中执行$ }! q6 G8 p8 h$ c9 @* u
{
: Q% z8 Y1 Y! Y6 I* b* Iif((*storage).p[j].askMemory < *spareMemory)
) q- b. J, W% ^% Q4 i0 ]+ v{
0 c" c6 Z x% A, q; q- w+ _(*memory).p[0].askMemory = (*storage).p[j].askMemory;
, T; Q" O8 ^6 p% }/ C7 J5 s(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;4 G# Z* R- s& Y- C6 h* g3 A) j
(*memory).p[0].computeNum = (*storage).p[j].computeNum; O, ?% `' K7 i) u# k6 d3 b$ F
(*memory).p[0].ioNum = (*storage).p[j].ioNum;/ W5 ?. i& N' M) p" R" g4 O1 V
(*memory).p[0].processID = (*storage).p[j].processID; g6 G7 Z& ?( T
(*memory).p[0].flag = (*storage).p[j].flag;+ [% l: i$ u7 B" e, z* @+ r! ]
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
$ a4 m8 r& w; q(*memory).p[0].computeTime = (*storage).p[j].computeTime;1 J1 d8 g/ r9 `3 y
(*memory).p[0].runningTime = systemClock;
1 T5 f( a N; N9 v( I(*memory).p[0].produceTime = (*storage).p[j].produceTime;3 u1 X) g# D; w3 x3 r, Z
for(i=0; i<(*memory).p[0].ioNum; i++)2 @( l2 x( O# F* I. E1 A
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
* v1 h) ]6 L2 b7 F# s6 N0 Xfor(i=0; i<(*memory).p[0].computeNum; i++)
! O$ S1 x) X& F7 n* B: ~' s(*memory).p[0].computeClock = (*storage).p[j].computeClock;# I! y1 n @& |. W) t2 ^& z" L
(*memory).proNum=1;6 b" O7 s: l M: x2 n- L
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
" W3 y9 g- L3 ~produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程 s( C; Q0 x8 l0 b" {0 t4 ]5 U$ u
(*storage).p[j].produceTime = systemClock;$ |# e' J# X' F
MAX_COMING_TIME = (*storage).p[j].comeingTime;
4 u4 ~ {% L0 M8 s; pwaitTime[j] = 0;3 d8 ?5 C8 V4 c4 Z, f8 n) Z
HR_ratio[j] = 1;: u9 r( N- T) Y" u; V
}8 A; w- y& b% y
else; m% T" W5 I: ]- F( T% R
{) |! L, n; S! o3 O$ @
printf("A process ask for a memory overed the system capacity\n ");
% J9 D( |& T: Y, t7 `8 {exit(1);- P9 z" P0 K O
}+ G f% S8 F, g( G
}
0 T1 h9 G: O; C6 Z3 `7 x" Breturn 0;# C0 `' T( \, Q N* c- ?1 s
}2 J# l; I! c u1 c
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw), @& k+ G6 d# A8 L
{7 W5 E$ n, P0 F) P1 {* s
static int compute=0,waitio=0,change=0;
3 Y7 V$ m9 p4 S' `3 Sstatic int computeLast=0,waitioLast=0,changeLast=0;# {' w0 S7 c. \* O! [* {3 S
int i=0;9 E8 @9 {+ P# S. C
if(draw==1)
4 x6 q3 F) }; Z/ S5 ?, K. l# H/ u: o{% \$ x; O/ ?5 v. X% W* ^/ t
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);, A$ a1 \ d, m; Y$ [( h% `# y
drawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
; l6 ?4 Y1 {- @2 U
$ i, M _7 }5 J6 } R6 X% U, r7 n# @7 ]: f6 v
computeLast=compute;
8 r/ A! Y* R' h2 YwaitioLast=waitio;
' e0 H" [& j1 \1 i) N2 E4 r/ kchangeLast=change;3 H. d" Z7 W7 }' n* P% y' I
}' D5 Z: f& V# F6 G: q- T4 ^
if((* memory).p[0].flag==ready)
% }: K. b; @4 M& q) k3 \ U0 M4 r. C(* memory).p[0].flag=computing;
+ w. Q! n; c2 T0 }if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
" H: `" g0 n& f/ x, l{4 U+ n2 m* F* @- ^$ h. J
i=(*memory).p[0].computeNum;3 }, t4 C" g+ y
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed s4 O r- W5 Y. T3 p3 G
{
; S. V& w" y4 Q/ P(*memory).p[0].flag=IO_waiting;
1 v/ \5 j2 y. v5 O2 A1 Z" C B(*memory).p[0].computeNum--;
! t9 _$ t4 z/ N/ H. x7 uchange += exchange_IO_Compute;/ x: P: @ a; P0 Y" ?/ O4 V
compute++;
% `; \8 _. Q7 U9 i2 P8 Q" i$ }}
0 Q' N# W: f1 t5 c7 W6 Pelse2 }2 o2 N5 s) C1 M
{
% z5 n9 {& B$ P+ N! `compute++;& H3 Q; y. \9 t) A- w" O
}5 \/ d9 W$ Q5 L$ K% o( Y) q; c% N: K* F
}
; x: N% P! {; w4 oelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
_2 B3 O* d7 K B# Z{
& t! k- {4 i/ v1 r- v, C0 i
* D% J |: o! K! a( si=(*memory).p[0].ioNum;
1 l* c* W8 f- g" j2 f+ s) { Dif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed0 _9 H/ [# i( i" ?
{0 W# m. ?! I* f$ {; c
(*memory).p[0].flag=computing;1 {$ w% c6 A# [. u3 ^* M1 O2 V
(*memory).p[0].ioNum--;
& N0 b+ v- q' C" s2 M9 [" U, ~) kchange += exchange_IO_Compute;4 u+ P+ n! M6 S) S7 _1 j
waitio++;
* {" F3 L/ ]6 ]* v4 \3 E}) j1 J# d5 M4 ~# ~
else
! j& h/ I0 A$ r7 \. C0 w) I8 x{
' R; z. r+ J' \- Lwaitio++;
" _3 r, m+ [% ^6 B- s, K}. j& q. R. z5 J1 N2 H0 X
}
9 k' Z1 V8 o8 U0 T; Q) K: Delse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)4 ? r* w$ H0 C) V. r. d
{: a. |* W8 B; R; [: q% ~
(* memory).p[0].flag=IO_waiting;2 W; i- M5 r, A
change += exchange_IO_Compute;
9 W. V4 l- u( m) I}- k' D8 k) ^; Z1 i& ?
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
$ g; e0 J" z8 U& d2 ^9 x" H" l{& o& ~& f, z) J. C @
(* memory).p[0].flag=computing;% s5 f1 K6 a u" b6 [; I& E
change += exchange_IO_Compute;# ^+ m* z2 x6 V: _
}
3 \7 g C; P: D K+ l2 C+ tif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
5 W2 z# ^- d% Q( K) J5 [{9 u# S1 L. l2 y! L+ q. c# p
(*save) = (PCI*)malloc(sizeof(PCI));
0 U4 p! w) E% t, N(*save)->next = NULL;
x% N0 D: U p& N% w4 ^(*save)->processID = (*memory).p[0].processID;
/ R; x+ I5 x S9 i8 s6 I(*save)->comeingTime = (*memory).p[0].produceTime;
* R- M7 L0 c& v7 Y(*save)->askMemory = (*memory).p[0].askMemory;6 k: d# p x, I' {9 L$ X
(*save)->compute = compute;, ?- B' q- P" w+ Z0 q7 A) x8 p! Z
(*save)->waitio = waitio;) R9 n3 E; o+ p( E) W$ m
(*save)->exchange = change;
b1 h; G; s- d" s0 {0 O+ D: h(*save)->completedTime = systemClock;
$ y; U& q7 L8 M0 K% H {+ u(*save)->runningTime = (*memory).p[0].runningTime;
' M, a2 k# d# \) f0 j*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;
7 m' f; S' f/ P* y3 s7 e& J: Rcompute=waitio=change=0;3 @: H1 E+ r( P/ w
computeLast=waitioLast=changeLast=0;* M. X6 U1 M6 j* u0 g% r
Priority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
6 b, B5 X' U0 d6 m" ~. o0 y. schange += exchange_process;$ Y, |! c& w6 n2 F) w4 ?9 p
return task_completed;4 K; W* E2 n: q- T
}! X8 f& D" V; f- Y8 k
else
3 S4 t3 s. J3 c S! Y9 e# _9 |. nreturn task_not_completed;( S: M0 C3 o/ Q: H q$ w
}6 Q4 Z% R/ }1 W) |% q
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
' A& U! s8 y* ^{* t1 N# {8 G* t& ^& F
int priorityNum[initProcessNum],i=0,j=0; _( F& ?& G' E7 @7 N4 K# {5 t
double temp=0;
/ M9 j. ]) E; g* v" `2 Vfor(i=0; i<(*storage).proNum; i++) // setting priority to each process8 X# [# c$ O* E9 `% G3 s
{1 l0 e! T. z# [' E
temp = (*storage).p.computeTime/(*storage).p.ioTime;) x p& @, Z. @% t* X
if(temp > 0.8)' x1 J$ p& v- z& \% a: G4 E2 ]7 A
priorityNum = 6;4 h2 E( T# e# h8 U# G
else if(temp > 0.7)
a; \# j2 p* {$ g2 D1 c8 tpriorityNum = 5;( v: F- q z% y9 y- P
else if(temp > 0.6)
6 N0 t5 w# B2 n, q4 F P3 W* ~priorityNum = 4;
2 f- z$ I) L$ oelse if(temp > 0.5)8 D( B& N5 D( u) k, U4 f
priorityNum = 3;
9 e/ [4 W H/ M+ R9 Telse if(temp > 0.4)9 G- l4 T1 b# C5 p
priorityNum = 2;
3 n% |$ U# @5 u/ C7 |3 ?else- G1 ^# _+ b! [0 ?1 [) x
priorityNum = 1;4 M+ u k8 d. l0 K9 B2 v# M
if(priorityNum[j] < priorityNum)
8 C6 v$ A: S- E7 jj = i;3 F% H) }0 ?) X5 {- r! f# `
}
$ g+ l2 T& f/ z) Y2 o6 tif((*storage).p[j].askMemory < *spareMemory)* Z. v0 @# O) ?- D
{- |/ l. s/ H* _: @! c0 B& ~
(*memory).p[0].askMemory = (*storage).p[j].askMemory;4 K. r; q& \/ [, M3 f8 b7 E+ t
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;/ F) x$ y5 w6 @' | J2 w4 C* m
(*memory).p[0].computeNum = (*storage).p[j].computeNum;
. y$ [+ p3 x/ h& g8 f(*memory).p[0].ioNum = (*storage).p[j].ioNum;
5 P. x! h& X' m3 G; z1 |(*memory).p[0].processID = (*storage).p[j].processID;
5 L2 ~- S8 L& \4 w: ~(*memory).p[0].flag = (*storage).p[j].flag;
6 i4 g' \! f* I$ v7 y' Z6 |0 Q* t, v0 @: G(*memory).p[0].ioTime = (*storage).p[j].ioTime;
# i) U4 X+ l' A- V$ z& w9 _(*memory).p[0].computeTime = (*storage).p[j].computeTime;' V# z( d9 C" y" p3 K
(*memory).p[0].runningTime = systemClock;' d" |4 g' U U3 h" A
(*memory).p[0].produceTime = (*storage).p[j].produceTime;
" H% z7 ^$ q6 o7 ofor(i=0; i<(*memory).p[0].ioNum; i++)/ E |% k- l7 n$ H
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
) ~. M0 Q: {7 y) Z. r) vfor(i=0; i<(*memory).p[0].computeNum; i++)1 l& n6 @7 B+ t1 S* |# ~
(*memory).p[0].computeClock = (*storage).p[j].computeClock;+ C' d3 s' ^2 D, s8 J6 s
(*memory).proNum=1;9 X, e. |+ V G5 j0 b
*spareMemory = *spareMemory - (*memory).p[j].askMemory;1 B6 x# p2 F' `( G* e* d- o
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
% I3 I; I" [( e; }/ Q- G0 uMAX_COMING_TIME = (*storage).p[j].comeingTime;
) `4 ~/ s% }( ]1 z* e1 _2 y}
5 F8 I- S0 J5 b5 X9 D8 q& lelse- C8 v/ s$ E" X
{! t3 D" F3 P% u" c5 d
printf("A process ask for a memory overed the system capacity\n ");% n+ `) g7 {" _4 J4 O
exit(1);9 M# y) n9 t1 w; H1 ^: u7 K
}
, t; I* U6 h }) Z& O2 Jreturn 0;% }% v5 b( O' R. b- R) O5 T
}
: ?5 }8 F/ y" A3 j7 _int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
/ C+ y: l' w7 |' i: \4 i{7 e6 H( P3 l- N" y$ C5 g
static int compute=0,waitio=0,change=0;8 H1 M4 Q7 u6 w$ ~4 g
static int computeLast=0,waitioLast=0,changeLast=0;
1 O! U; |) ]9 h2 J ^' r0 `( H* Cint i=0;
0 m6 R# y8 b0 r' i2 g2 Qif(draw==1)+ U# n8 o/ ]- l8 _6 u9 r
{
0 t& J5 J4 E( o" O, |9 k//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
' z) e# S# y! P4 a4 w: r+ HdrawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
7 [ ^# ~+ O% I% b9 \* l0 o) F; d. V
& Z" z* R" ~5 w4 q. [6 z9 scomputeLast=compute;9 @1 Q; Y6 u3 q3 W# X& [
waitioLast=waitio;: {3 l# t9 x$ m" h) } k
changeLast=change;
) D6 d. } c' q `}
, o7 _$ g# m3 h6 `7 `& A, `if((* memory).p[0].flag==ready)7 L, r5 u- t! i+ H7 Z
(* memory).p[0].flag=computing;( H, A) |* K8 ]% f* n
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)' O/ `: t3 a$ B! o
{- O: A K. K w1 N% N) V3 V
i=(*memory).p[0].computeNum;- b1 I6 S# U& p$ [. Z h
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
: c3 T/ ~5 ^# |- n' ~4 W{
9 V" c. n. A( m* N3 x/ f(*memory).p[0].flag=IO_waiting;. b# p$ ~3 b& X3 K; O/ o/ K: h
(*memory).p[0].computeNum--;' W. U; H: U: U; l6 k) B
change += exchange_IO_Compute;+ f7 D9 o8 A* E4 z. f
compute++;
# k5 V4 {! H w1 l3 O& ^}
; n% y+ N- a$ `( o$ ]else
6 v$ L6 x1 M% c. Y: O# @0 i{
5 M, @( O7 f! D L; Ecompute++;
2 G4 s! a: a" G* H9 h}
' L. X6 z& B# Z0 T' \}
" u/ L+ p/ Y8 ~; t, D7 helse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)7 Q( O' j3 P. q+ `( K' h! k0 n8 `
{
8 s; d( C' F5 e' R
/ D# I" X7 a/ g; X: m4 k. B/ di=(*memory).p[0].ioNum;
" C6 l( Y/ o. i5 R0 c5 vif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
/ W- D$ b ^. u$ K{
* ]1 G1 D8 k# t# g6 r; \(*memory).p[0].flag=computing;
6 P& H% p" ?4 o! ?(*memory).p[0].ioNum--;
3 ?* s5 `/ e% Q( F" B2 U7 R6 achange += exchange_IO_Compute; K- g, g: [+ B
waitio++;
$ G6 G% X9 d! K) ?+ z/ T5 b- \}
! S- A8 ]/ u- m- `% Melse0 S$ _( |! C) B" m0 g& Y3 C" b. J
{
}& [: O! E2 U3 h; u! vwaitio++;+ v+ c; d8 @ T, f
}9 V7 R6 [2 ^% c: f# t; j1 X9 A
}
, f9 X! V" [% {5 c4 G9 Gelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)1 d1 j2 s2 P: n
{
+ k2 h8 W- ?4 ?% o, `(* memory).p[0].flag=IO_waiting;; l5 a5 e0 K' ?* g$ X
change += exchange_IO_Compute;
9 o# ^( O; z0 [* x5 M}1 `7 @8 P& Q5 x: M' e. e4 J
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)) d- C+ Q1 d5 H
{6 k8 Z+ _) T& K$ v' K5 h
(* memory).p[0].flag=computing;
z+ N4 J' q8 H' C0 B: d, ~8 Nchange += exchange_IO_Compute;& H; B7 W) ?( X9 Y0 n
}
$ | y9 k. G1 ]4 Tif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成" f4 u- k) E) @
{
7 |5 l! z0 Y8 D6 f(*save) = (PCI*)malloc(sizeof(PCI));
- A6 u. W1 f9 ~* N7 \/ m# G2 {4 D6 B(*save)->next = NULL;! M$ }; k# y' ]& X
(*save)->processID = (*memory).p[0].processID;. ?$ U) n5 a& [# Q5 d
(*save)->comeingTime = (*memory).p[0].produceTime;
/ @/ L/ J6 b+ ?+ J(*save)->askMemory = (*memory).p[0].askMemory;9 P2 f' P8 P9 t3 k# @! {7 o& v
(*save)->compute = compute;) D) F' C4 f5 l& T0 W( b
(*save)->waitio = waitio;
Y# ]/ }5 [2 x7 w(*save)->exchange = change;
, @" I L# ], g(*save)->completedTime = systemClock;
4 F5 K) @, d7 | v7 T6 O- F7 W(*save)->runningTime = (*memory).p[0].runningTime;) P2 J) P5 X# e; T7 s4 [: b: G
*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;
! a4 H4 H4 F. v: R) Icompute=waitio=change=0;8 n7 A6 e- r7 Z9 J
computeLast=waitioLast=changeLast=0;
* i4 X. O1 {2 B1 OSJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));* C F2 E6 Z# W8 y0 u) |
change += exchange_process;
5 b( j9 O r% g- e2 Hreturn task_completed;, o/ d3 O( x' e, I! ^) }; Z
}
: H; c' D. f Yelse- V: U/ C4 \' |1 [. C) n
return task_not_completed;
6 Z! \# i1 `4 H( A5 m}, r! _' T! E. H. H) i
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
& ^( @( Z m& @1 C4 {% o2 d& q{
( Y- {1 R. c% b5 C$ m: `int i=0,j=0;
}# B' F0 }# ]# X0 |# A$ u4 t, d% }for(i=1; i<(*storage).proNum; i++)2 ]! J& \, o; e9 K8 p) f, c
{
4 w6 A% ?" E& E# b! d- f; ? Qif(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))2 K, M+ k9 k8 l5 q
j=i;6 W0 ?4 l) X" i4 b* n
}
6 q S& ^, G9 p# a) ]if((*storage).p[j].askMemory > *spareMemory). q1 f& d( s, X! [# f
{& S9 ^. B t( M' D7 h8 d. P
printf("The memory asked is overflowed than the system memory.\n");
4 A7 [3 L3 R! Oexit(0);
9 m. f" m3 `5 i. q}* s3 Y1 I& ? I& m6 k- Q- t( ^2 b* ~
else9 B9 ^: y" v1 a7 ~! K4 c( b* j6 R7 J
{7 v- P" I% e7 p- l1 i$ h& f/ U' m
(*memory).p[0].askMemory = (*storage).p[j].askMemory;
$ t9 w. d% I0 g/ o7 z% Q5 R(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
& p2 |0 S1 h$ R" ?% r2 R(*memory).p[0].computeNum = (*storage).p[j].computeNum;# h% O$ v! S4 _; S7 Q* V3 O
(*memory).p[0].ioNum = (*storage).p[j].ioNum;
Q6 X1 ^8 |' s. z(*memory).p[0].processID = (*storage).p[j].processID;
. @3 K0 d* p- I5 D" S6 H. j4 z( e(*memory).p[0].flag = (*storage).p[j].flag;
1 O, h: }" G& q2 t' c7 v(*memory).p[0].ioTime = (*storage).p[j].ioTime;* |0 {/ k9 w2 P+ d6 A3 K4 E: ]
(*memory).p[0].computeTime = (*storage).p[j].computeTime;5 D2 ]& P& t* M- p. G$ P8 P- L
(*memory).p[0].runningTime = systemClock;( b6 N; J" x- g/ N
(*memory).p[0].produceTime = (*storage).p[j].produceTime;" v1 p C b! c
for(i=0; i<(*memory).p[0].ioNum; i++)) D! W) U' r" Z4 s
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
7 h# D& X' W. r8 {/ H' Rfor(i=0; i<(*memory).p[0].computeNum; i++), ?6 ]4 U9 l2 h6 b7 v/ H" k1 X- r
(*memory).p[0].computeClock = (*storage).p[j].computeClock;
* |( K$ m3 A9 X2 o: b( p(*memory).proNum=1;/ j5 w& c/ \' I1 J6 r( `
*spareMemory = *spareMemory - (*memory).p[j].askMemory;9 a$ h m2 G, {
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
; G% q4 s% z. N' E, EMAX_COMING_TIME = (*storage).p[j].comeingTime;+ h: O, l: t' C, H3 ~7 I. U; L
}; \3 i, u5 k4 M+ w7 d6 L% B
return 0;3 p& W1 E- i6 }! H
}) [, g! g, f. l1 L9 x1 b6 s
int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw) t. [' b+ O! y; t7 q9 }& ^2 W
{
( x N( L# l8 L6 h* R N) zstatic int compute=0,waitio=0,change=0,clockSegment=100,poi=0;" X* D: F3 O& V5 W' e! J* g
static int computeLast=0,waitioLast=0,changeLast=0;) Z- d( a5 h+ r/ d) U
int i=0,j=0,k=0;3 b% f) Y& g+ C4 Y
if((*memory).proNum<=0)
& w! `/ Y- T+ V4 [$ dTimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);2 A g h# c' x( m' T4 i
if(draw==1)
; N5 P0 P- D: K5 b{
- U6 u! A1 U7 D9 d4 Q {//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);9 b( ]8 M+ f7 a8 V' W+ l6 D
drawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
7 |0 \2 ~( S) I4 \2 T9 L& U# | a, F
F; W+ d4 \' ?- k
4 T8 B! e$ r5 V. zcomputeLast=compute;) S0 {) ^' [) R( E$ d: Q. _7 b6 D: b
waitioLast=waitio;- Y$ V6 i, k' {' C. H
changeLast=change;
( g! b& o4 J1 t' h2 w* M Q}0 _9 Y m& w6 |; J% i8 O
if(poi>=(* memory).proNum)8 x& g8 ~0 Y4 ^8 v/ A1 J# H! _
poi = 0;
% ~- X0 Y7 W) K* ]; oif((* memory).p[poi].flag==ready)! \$ U* ~% D2 m7 D
(* memory).p[poi].flag=computing;
6 d9 z4 y& ^2 ?# W5 |: kif((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)
4 a! f: L. o" N8 c! ?0 p) Q9 Y{2 U& d5 B7 e" `2 R: p* h7 J
i=(*memory).p[poi].computeNum;
' U, m, H3 {' y, {if(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed
+ ?; |0 C5 C# N' @- x! r {{- g6 L# K. S" M% d( X! z% [
(*memory).p[poi].flag=IO_waiting;
1 h% G1 _0 d' N2 s) |(*memory).p[poi].computeNum--;/ O/ ~0 F0 [8 ~. j M
change += exchange_IO_Compute;; c# V7 l% a1 I# h* e9 U, n
compute++;) U: Q1 {8 u4 k) u
}
8 n) [7 z3 A G. J$ n1 Kelse
6 j3 T4 U9 J2 F Z{
! r# h$ ~1 O) P9 h4 `- fcompute++;
$ {0 Y- ^( p, h& O# k0 h Q1 [; {}
) V8 K0 g z( i2 J% S3 I6 G}
" Z: H x+ U* N+ W. H( X& |else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)0 a# _& O6 P$ o( _6 ~3 p
{' h2 I6 B, m( Z* [- V1 d
8 ?9 I3 W" E; s! b: k7 s
i=(*memory).p[poi].ioNum;( w w! v( X% g; |8 n- ~" b4 V% r" i* Z
if(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed( ^1 i; E- e% A( D0 C$ ?- ~0 }
{
! v. R4 j1 _. F9 H$ z% a9 N* D8 Q" b(*memory).p[poi].flag=computing;
- T/ E9 x4 q9 I7 J* G/ ^% s8 G(*memory).p[poi].ioNum--;- r% j3 T. M! L4 W
change += exchange_IO_Compute;
/ {2 V& X, I- h5 C0 y/ mwaitio++;
9 q/ L9 M1 X7 K9 k}
8 \4 _! R# u, Y9 kelse- |/ \4 k N) Z1 o: q
{: O8 j& e8 F1 \# n' O
waitio++;/ C/ n) Y. B+ J f. R5 v, x. }
}/ S# X+ q' b9 n# i9 D
}
& `# e; n% z# y% ^else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing)
$ b' y# j3 W1 m{' z5 A0 g1 t) x( z8 p2 t* d
(* memory).p[poi].flag=IO_waiting;
0 T! } g o+ _$ A. \8 J- echange += exchange_IO_Compute;& t, x# ?4 J3 D1 j+ ~
}
8 T/ r) {( E2 B2 delse if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)+ }, Z% f# I v0 V, B/ T
{& `# Q" i# M) l. G: ^$ ]% z* K
(* memory).p[poi].flag=computing;
. L: S1 H' C) m% B. Z, ~% S! nchange += exchange_IO_Compute;
5 b# a+ I; ]2 M/ j6 F- m1 y, \}
5 F+ L# x: B% R# n G! Cfor(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进* K5 R7 l0 O/ z. p3 }' t& y2 G
{3 E$ z0 R u' ?/ S& G/ ]& X" k
if(i!=poi && (*memory).p.flag==IO_waiting)
- q7 Z) f$ f; W; h2 U{& m. X& B$ [( K: y- |' r
j=(*memory).p.ioNum;/ _1 L/ _2 ~" P2 u
if(j>0)' D+ K4 T1 ^$ Q/ d8 ~4 f; m
{
G6 ~0 [: A5 H7 t$ x) Jif(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed
" O3 g, V$ h+ i{
# t$ u0 W$ M" ` @/ W5 L(*memory).p.flag=computing;( {& _- q' Y5 J+ e
(*memory).p.ioNum--;' U2 P5 F r6 I4 H; o! {4 v
change += exchange_IO_Compute;
) a* F4 @3 {+ F1 z2 u! H. N7 o, K}
0 m: w% H$ G5 O2 m}
% \# }+ N6 B \1 S3 H! C/ V2 e4 d}% R" |+ `. B) N+ n( [
}
# T( x6 B# d$ m5 jfor(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程
8 V( k% I' l/ |* U; C{% H/ W: E7 q7 [. i# y9 h) L
if((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed% \+ t' E; C7 ^' f, ~7 d
{9 j" v* z3 N5 N: d, D* `- U0 M
(*save) = (PCI*)malloc(sizeof(PCI));% z! B! m6 B8 a9 }
(*save)->next = NULL;6 x- y5 Q8 x' m6 U) f) }
(*save)->processID = (*memory).p.processID;! X! A, Q Q0 @# H
(*save)->comeingTime = (*memory).p.produceTime;8 R) F8 b n2 W/ A' ?( x. s# M
(*save)->askMemory = (*memory).p.askMemory;
U" }& i" F+ C C) u& S' n(*save)->compute = compute;
- P' [% H7 E0 D( h, P ]6 b(*save)->waitio = waitio;
9 F$ [1 L3 {1 `8 }) B(*save)->exchange = change;
0 X4 z5 Z+ a# |(*save)->completedTime = systemClock-(*save)->comeingTime;9 A7 G: r+ [0 n/ q+ F
(*save)->runningTime = (*memory).p.runningTime;
) ^, c, }- G X3 w4 ]% n(*save)->completedTime = systemClock;
G2 B) a6 f3 Y- v; q: D6 \( X*spareMemory = *spareMemory + (*memory).p.askMemory;2 Z9 t) r6 g0 A4 |& I0 t; [5 j
compute=waitio=change=0;
: [+ l% y" |2 i+ h5 X2 TcomputeLast=waitioLast=changeLast=0;
* s/ @+ e% y5 q2 Kif(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入! g0 v7 J; I- c0 u6 N
{ O# P @2 c5 R, T0 y
if(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程4 t$ }& j( V! g
{4 Q e+ q% ?% M( H- i- f
poi++;
* k, i/ N' Q. [0 `' J clockSegment=2000;
0 S1 a9 Y3 H4 \: Q# @( |}& ~' V8 D r. N6 g$ D/ e7 Y
}, e) K) _3 O" O! w3 b" Z8 Y
else //没有足够内存调入新进程/ @. O2 z0 g' O. P; h+ q
{) v# Y# D/ f* G( ]
if(i < (*memory).proNum-1)3 G' j" `. }+ ~
{
8 O8 }& `7 T8 L4 Cfor(j=i; j+1<(*memory).proNum; j++)6 c+ E/ S- U: I3 F% J6 x0 h
{1 B) \. G$ F" T" n' `5 W3 f/ ]5 Z% S
(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;
$ r8 o9 O) y, Q+ Y5 F C. [0 D* ]2 P(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;
' ?3 \5 p4 t6 _4 H$ h5 B/ M(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;4 w( | n0 T' e* V/ V9 _
(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;& |6 @6 u4 p# [
(*memory).p[j].processID = (*memory).p[j+1].processID;
8 s, ?2 m3 t+ x( x4 S) L(*memory).p[j].flag = (*memory).p[j+1].flag;/ z' M8 y3 b: A4 j# J9 z4 |5 Q# R
(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;1 p% O# ~3 A% I4 i3 s
(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;6 g. \5 Y, F! _. X& S; o ~/ {' P7 A3 @
(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;# o' }* ~1 Y. k1 V3 y! N5 A
(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;
, s4 w8 e$ D' z6 S0 H7 Z$ S(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;
. I9 X; S. v# r" Wfor(k=0; k<(*memory).p[j].computeNum; k++)) \! g, J/ ?$ m( A/ I4 _$ u: R
(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];
6 I7 }9 N) }5 |. `+ sfor(k=0; k<(*memory).p[j].ioNum; k++)9 s: E9 ~9 A- i4 G7 U" O- \4 C6 B0 b' K
(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];. f, ?) w3 B6 i; |4 L9 ^
}" s9 }4 E4 P8 _/ j' ], N, k
if(i<poi)) P! l6 K1 N) d' ]2 O
poi--;" G5 c) K$ `5 L$ Q9 W
else if(i==poi)
% R u. c! j$ `1 C$ O1 S eclockSegment=2000;
$ j- u0 W% I: w* \: X! c9 p, ^}) u* y# N# A- b+ }; \. G) D
i--;
& g3 J8 c$ c; x7 T |7 r9 V(*memory).proNum--;4 I9 N' H2 H/ k( p
}
, z% f+ l# o4 H$ z" N7 c7 Sreturn task_completed;' R* E9 G' q- b) L/ }
}
7 D9 y7 _6 x4 X0 n$ I}# T3 Y |: t( H
--clockSegment;* s/ h% \' [5 \9 I7 B: D4 l* H
if(clockSegment<=0)
1 y) N$ _, J; @+ R) U1 V{9 l( \4 I) L* C
poi=poi+1;4 W5 |9 |% f; a- k( x+ n7 f
if(poi>=(*memory).proNum)9 w" b/ |& V* d9 I6 u% G. G' Z- {
poi=0;; `& U# f z% E F# Z
clockSegment=100;. c( F7 J; S% X0 O
}) [1 p" I7 L; d8 K( v
return task_not_completed;
. a) k% E: a' W" B- g}- f2 R E3 z6 i8 L3 s9 Z" Y' w
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)& T+ J- V2 P8 S6 J4 z- r
{
. q/ @$ X6 s+ `# x% e( \int i=0,j=0,k=0,flag=0,translation=0;3 I$ x: S. g3 b3 L' `7 p
for(i=0; i<(*storage).proNum; i++)
. B, K+ J' N, Z2 G) w# m! h1 ?2 Q{, b2 Q1 H! }6 E4 {+ \4 P
if((*storage).p.comeingTime>MAX_COMING_TIME)6 U9 Z. O% a: C
MAX_COMING_TIME = (*storage).p.comeingTime;
( C) ]% Q& x: F4 h}
& `' }. ]# e$ F3 q0 H, mif(pos>=0)
% O. e$ j' l. d' C S6 W! {5 n{; C# l& z5 k$ L3 G/ X u
for(i=0; i<(*storage).proNum; i++)
' O7 J5 a% \2 B, O& |- e* `3 a{
" H% Y0 Y0 e# n; H$ aif((*storage).p.askMemory <= *spareMemory)
! h* u* j5 e3 ?{
& C+ [) ~5 R2 [- X1 x' i; P$ S! I5 cj=pos;
: r, Z8 X2 G1 B# ]1 t7 Y(*memory).p[j].askMemory = (*storage).p.askMemory;
6 `4 K6 ]5 E& v) r* u: {(*memory).p[j].comeingTime = (*storage).p.comeingTime;1 {: `2 I7 p V. U
(*memory).p[j].computeNum = (*storage).p.computeNum;0 k8 j e( C( f" ]; u0 T6 T- {$ c
(*memory).p[j].ioNum = (*storage).p.ioNum;( }% ~( \, G6 s
(*memory).p[j].processID = (*storage).p.processID;) H* Q8 | Q# b% u \# }$ g
(*memory).p[j].flag = (*storage).p.flag;
4 L9 d- L, r) v* g! @2 N3 x: R# t(*memory).p[j].ioTime = (*storage).p.ioTime;5 i; G9 D. c% R0 O: b; `8 Y
(*memory).p[j].computeTime = (*storage).p.computeTime;8 y1 q# z! K% X. U+ N
(*memory).p[j].runningTime = systemClock;
- O$ I+ ~0 y! h7 s7 t3 u0 j(*memory).p[j].produceTime = (*storage).p.produceTime;
( V0 H, j4 N4 u) Efor(k=0; k<(*memory).p[j].ioNum; k++): Q; r/ a# y. B4 U% T! {: e4 T
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];0 f. t# }( _9 M8 l: `
for(k=0; k<(*memory).p[j].computeNum; k++)
* d% o8 f L& R* v: q(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
. v; V( i! B: ]. F5 G% [1 L* v/ U*spareMemory = *spareMemory - (*memory).p[j].askMemory;+ R/ j2 Q# N$ D( R* M) e
produce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
' G% b- x' a" X' }MAX_COMING_TIME = (*storage).p.comeingTime;
. P; g7 H, O( ?$ A' Btranslation=1;
- j$ J- r4 F9 |; o5 `5 k: ^break;* K n' ^4 J" }! d) S9 Z% A4 k
}
# _) V4 q, q3 w} L- c5 E; h9 ~% [; q. a" ^! j7 J* y
}
: v; c- D4 J* J- Ielse
. n" Y9 ^7 T4 s" _{7 ~, h$ D. d$ ~) c% E
while(1)' m$ O4 ? E! `0 i; l6 e
{ C K3 ^+ ~6 L7 w5 p2 v" y
flag=0;5 v6 T& Q: f5 V4 k a8 E K3 v
for(i=0; i<(*storage).proNum; i++)
- b {6 e( t1 j8 h{6 A2 i0 p: W9 D3 {7 S8 M+ R2 s) X
if((*storage).p.askMemory <= *spareMemory)
0 ] d3 F4 y' P/ P& ?{
: x( \' V5 T' }* T6 h: Qj=(*memory).proNum;) v! @) H$ Y6 Y1 x! R; A/ d' V1 `
(*memory).p[j].askMemory = (*storage).p.askMemory;; g3 Y8 M6 A. y
(*memory).p[j].comeingTime = (*storage).p.comeingTime;8 l: O; i6 n4 `# ^; E5 r
(*memory).p[j].computeNum = (*storage).p.computeNum;* x! b2 E s0 K2 g* D# j e2 t$ Q
(*memory).p[j].ioNum = (*storage).p.ioNum;: T( ~# k) X/ l$ _& G
(*memory).p[j].processID = (*storage).p.processID;
: l2 t1 J7 k: C6 R. n(*memory).p[j].flag = (*storage).p.flag;' \: k! I- q" u* f+ q$ y
(*memory).p[j].ioTime = (*storage).p.ioTime;1 s) u% U q/ k5 a" C' G
(*memory).p[j].computeTime = (*storage).p.computeTime; A& B$ w$ B1 o7 D
(*memory).p[j].runningTime = systemClock;" b2 W, t, L, x8 z
(*memory).p[j].produceTime = (*storage).p.produceTime;
?0 ~3 ^! s6 j# g: T% l0 [4 K* b8 Ffor(k=0; k<(*memory).p[j].ioNum; k++)7 V, B9 ], @. z4 K* R I- T5 Z2 l
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
6 i8 S6 W9 S |0 ^' [: k1 V) i* \for(k=0; k<(*memory).p[j].computeNum; k++)$ i: k5 u; I+ B3 C0 f. y
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
! P$ f* u% w B) r8 q; c(*memory).proNum++;
+ K6 L7 @9 q) }$ H7 M6 a5 e*spareMemory = *spareMemory - (*memory).p[j].askMemory;
, G. L7 y. S% A% H) l1 `. Nproduce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
4 o! A1 a: S) g& ?MAX_COMING_TIME = (*storage).p.comeingTime;8 B% I9 t2 I# L9 a$ z3 R3 o- b
flag=1;% z, z! Z* k4 P3 l, |1 N
translation=1;! ?6 E" l- c# O3 w
}! X# Z0 R% c# X" T- Z9 o. m
}
+ [5 L& a8 w$ G2 q+ i! B1 mif(flag == 0)
& A, {2 v( E9 B) L" ^0 Ybreak;7 E# D3 N4 z8 c4 }2 c
}
1 q# q# u) k5 j( S}
* W5 N8 Q* l3 A. H: X: preturn translation;; n8 V1 I; E0 K9 j4 W
}
* t, t; u8 \& Nint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)! x. L ~% o0 C7 f1 ]0 h& T
{7 j* I2 q# {& ?- {
static int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;8 U4 B3 P) x$ `2 X
static int computeLast=0,waitioLast=0,changeLast=0;1 r7 W; u) m. f" h5 K1 B3 E
int i=0;& i% u- D% u9 ?4 `* Q1 t
if(draw==1)% G1 v: a* c7 F @5 F5 x
{5 t d v* ^# W1 L9 @& }: ~
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);( V6 c5 v# } H/ C% p+ Y& \
drawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);, f: D; M, H( J: ]* z5 _1 U6 r
" Y6 y E$ O' g& T
6 ]# p+ [' b) p2 l+ I- L0 ?computeLast=compute;
! a% _& x3 o, d/ s! ~1 l* jwaitioLast=waitio;1 A7 R' g' b, s) P& V
changeLast=change;5 ?9 S7 r$ T+ M5 i1 d
}
$ m D+ z3 \2 k+ d& R" p6 uif(flag==1) ' k: D' h6 `$ m
{
# A9 c/ b2 p7 ^0 T6 }if((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed
/ L# J l/ Y+ b+ m3 g{7 y- p2 F8 ]1 r9 j* W( O+ K& U
if(flagiocpt==0) // implement compute
/ E; n! [# o) P: L# n3 z, ^3 C8 ^{
3 U" H) e# n4 }i=(*memory).p[0].computeNum;2 E x6 C( b/ O$ U, y6 c
if(i>0 && (*memory).p[0].computeClock[i-1]>0), w) S+ M& |( j8 G- s/ N
{9 p2 h) Z* V1 X3 u o4 Y
if(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed
9 v$ D/ l2 i! C, f) i: E/ n0 u{- ~* s6 H" m" M& D9 @
flagiocpt = 1;
% Z* i# q/ p+ ~# O(*memory).p[0].computeNum--;4 P' f9 N7 ~" f/ E
change += exchange_IO_Compute;* J( ~ X% _$ [- X
compute++;
/ i1 A' z* P$ M6 z+ \8 ?& d3 A8 L; s}8 V) d8 J+ `( ^ P9 Z
else
& T7 `/ B4 c) I1 Ncompute++;% a7 t9 i1 a! {( z2 P9 G8 g/ Z
n- _7 Q; V$ p( Y* ]. v}
7 M8 h& k. h, q: R, celse
; I/ Q+ Y, K, c6 N* aflagiocpt = 1;/ }! }' @7 i& C- ~
}
1 ]; ^( [& d' E( M. p4 U, telse //wait io3 k$ o6 A; B2 t. ^4 ~/ z" a" U
{
( P# |5 o, L# S( h- Y1 I3 Z$ o. Ti=(*memory).p[0].ioNum;6 P: q2 w! ], B" S: B$ n# ]
if(i>0 && (*memory).p[0].ioClock[i-1]>0)
, F/ q8 p% \% [1 v+ @ L{& @$ u7 g( L) h0 O7 ^+ x
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed0 j% @7 A( \; n6 _3 ~; A3 A) y) k
{- S1 X& a+ g, p4 W
flagiocpt = 0;1 x# O# P# T$ s
(*memory).p[0].ioNum--;
; R2 f3 D* C* A. }! T2 e# cchange += exchange_IO_Compute;
+ T3 w6 Q& R- P& vwaitio++;2 l4 Y } H; F; K/ O- v) z
}7 ~1 @7 \) m" b. m+ R/ I7 b
else
% r6 X+ L% @+ q% B( i$ k) hwaitio++; M7 O3 g% P" _3 \* Y* s! {% }! a
' j$ Y: c7 P( X* e" _. i/ L' w3 T( W}
" n. B1 ^: t* h; B2 i5 f/ {' }4 C1 @% Ielse* I! d7 Y* }, S: n5 y+ n" C$ c+ o a
flagiocpt = 0;
- F4 ?; Z" [5 L}" L3 @2 v5 R( t) L/ F
}
" ?2 G3 h; [* C3 }" p( o' }else //task is completed
. U8 r; Y5 q. O4 ], e0 @{ B* P" ~" q2 h, B$ k
(*save) = (PCI*)malloc(sizeof(PCI));' M8 x- p) { ~+ V( j, m' r! Q% t
(*save)->next = NULL;
* O0 k& x* j( }* y8 I0 l (*save)->processID = (*memory).p[0].processID;* o1 g: e1 L* ~$ o
(*save)->comeingTime = (*memory).p[0].produceTime;8 Z) z3 d. L" q. N. L- w
(*save)->askMemory = (*memory).p[0].askMemory;
; }& Q% }* }4 w) `(*save)->compute = compute;- t( A) v: \( i8 @5 @
(*save)->waitio = waitio;
1 [$ S( ^6 A& [: o; h(*save)->exchange = change;2 H0 P- G$ n+ Z* W7 t% `& X
(*save)->completedTime = systemClock-(*save)->comeingTime;3 t4 V6 _/ L$ U
(*save)->runningTime = (*memory).p[0].runningTime;9 x4 _7 W6 n5 b' p
(*save)->completedTime = systemClock;
8 s$ w6 ?3 i, R; {4 e ` ~' d//*spareMemory = MAX_MEMORY;
0 L7 M6 D; [4 Q2 z7 Ufree((*memory).p[0].ioClock);5 R. L! m7 {! g" P
free((*memory).p[0].computeClock);
8 R% w, M8 ]5 U3 S. R5 Z3 u' e' M/ afree((*memory).p);
/ F" F7 F! f- k: V$ C6 f+ cflag=0;
: x8 S" T R6 j5 pcompute=waitio=change=0;
9 y1 u) s' h/ P9 w* p t' _7 icomputeLast=waitioLast=changeLast=0;
3 p. o+ ^* ^# f4 F/ X$ qreturn task_completed;1 g9 O% P" r* G$ \1 _, ~( Z
}, s$ U7 |" B" P9 h; u
}) E& Q" |5 F# j+ K
else 2 M5 ]/ e/ U& h j
{6 X, K, ^9 X' E% l& ^3 |# b1 Y
FIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));) ?' K7 g: O6 N
change += exchange_process; N6 b% p {$ c4 t0 s" |
//*spareMemory -= (*memory).p[0].askMemory;9 y, P$ A. ?4 j9 D9 a; k
flag=1;
3 y |2 k8 ^% s0 \" x, l//showProcessInf(*memory);
3 V* ~7 @! W$ u, j( m6 J5 nreturn task_not_completed;
- G7 ?, \6 v. B$ }) n6 d}
) S& O$ y9 K% greturn task_not_completed;
5 Y0 H& q0 q2 X6 \}. q1 b0 f) [, y8 L3 D7 M+ W$ Z
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)7 l8 D3 Q4 S* s/ ^2 G) Z
{- \1 U! ]. E; ]/ m
int i=0,j=0,k=0;
: k) F w; v1 P/ UMAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;" `- c+ [, U7 ~" c
(*memory).p = (process*)malloc(initProcessNum*sizeof(process));: W3 p: D+ p; P
memory->proNum = 1;
* ?" Y) n# O" B1 D/ h. Zfor(i=0; i<initProcessNum; i++)
% l8 g& X7 e% H+ O. K1 h! C{
) `) E, P2 c8 h$ C8 P5 i1 R& ]if((*storage).p.askMemory <= *spareMemory)
5 s) e$ C4 g9 R' Q; _1 N{9 i. j5 l/ d/ S& K* e
(*memory).p[0].askMemory = (*storage).p.askMemory;" o' }/ ?0 b5 K, E M' x [, s
(*memory).p[0].comeingTime = (*storage).p.comeingTime;3 M2 F* C, f, v: G7 J
(*memory).p[0].computeNum = (*storage).p.computeNum;( a' J/ Z( M5 Y2 V
(*memory).p[0].ioNum = (*storage).p.ioNum;
) h% m7 U) y" ^0 P& M+ |. D(*memory).p[0].processID = (*storage).p.processID;
. y5 s+ d$ t# w7 J& x$ ~: C T(*memory).p[0].flag = (*storage).p.flag;
+ H. w" e9 P& |6 a: `# W(*memory).p[0].ioTime = (*storage).p.ioTime;
8 J+ u+ j1 H# I* M( {(*memory).p[0].computeTime = (*storage).p.computeTime;+ q. B5 e8 @ y _' F# z% b
(*memory).p[0].produceTime = (*storage).p.produceTime;
+ o9 @) o2 a m2 ]( @8 r$ x(*memory).p[0].runningTime = systemClock;" f$ T( d2 p$ G' I; G. q/ O5 X+ G1 ~6 b
(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));
/ } g+ n0 M0 U9 c(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int)); u1 C' r* o- Z4 v" ~
for(k=0; k<(*memory).p[0].ioNum; k++)) g( j6 {" x5 R& O, }5 `0 V
(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];
) \- O1 ?& c4 w3 \- {3 }" Z! ~7 U; {for(k=0; k<(*memory).p[0].computeNum; k++)
$ P% v0 _8 A! q' p: K6 u(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];
7 `1 G+ g u pbreak;' f$ I( j3 y# |' w! ^
}# m& f5 K7 v9 m9 y
}; |' v) `( l# E/ @2 H& e
if(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入# |- R+ w8 j" q4 G" I
{& ~! M+ q: ^- E' R
produce_one_task(storage,i,ID_FIFO++);0 E) ^% ?, v# ^
MAX_COMING_TIME = (*storage).p.comeingTime;
/ M. r$ P% N8 a& \' |- _1 E( I4 zsort_by_comingtime(storage,i);& E. O3 C) W) `
}$ M ?' y/ p+ o. r
return 0;3 n `" x% _/ b' {1 ], j5 l: I! M
}
7 e5 l2 ~& C; g' }2 R4 b8 fint sort_by_comingtime(processPool * p,int pos)
6 S {& K$ e! O9 w+ ~3 k{+ O1 _% E0 v7 D8 n0 k" I
int i=0,j=0;5 T& p2 G5 |$ G, n% V8 y! |# J
process temp;
7 h& S+ K) P7 ^& Q* [8 }if(pos<0)9 b: c. d5 d! [
{
8 {; L+ c$ x ~( |) Lfor(i=0; i<initProcessNum; i++)( J+ ?/ d; d) k' p5 S; k
for(j=0; j+1<initProcessNum-i; j++)
% x( X& R2 w( }1 Y3 F7 b{
% W4 L% Y- z9 z6 y2 J/ K$ s8 O' Bif((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)6 {) q/ K+ H4 B6 \
{
+ o2 a! g: o( ]5 I+ y' c! {temp = (*p).p[j];) O! f# y& K& B: l0 y
(*p).p[j] = (*p).p[j+1];$ V' y- y# W9 s i
(*p).p[j+1] = temp;
3 I+ E9 v6 q: [% y$ k}2 o) N5 f3 Z" D2 F6 |$ {
}
9 T+ [' G* `! a}" ?0 P. Y3 V$ n/ u
else if(pos<initProcessNum)
- r* ?2 _, r V: X# A( b- P{
% x8 d+ p7 D3 D+ Kfor(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)4 Z. p- s/ L, o. Q
{2 o% c# z/ Y7 A y, S
temp = (*p).p;/ ~# p- Y4 U4 G
(*p).p = (*p).p[i+1];& k$ A. N" l8 i h; N8 _6 z6 F
(*p).p[i+1] = temp;' K/ H7 {; ^8 \& P/ t
}
5 Z, O; n) v: ]4 W5 efor(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)
. _8 Y; y* o e: {$ q; d{
* B+ ~6 V8 u$ [% x0 \3 F& K6 ktemp = (*p).p[i-1];
" P, }# _; y! ]. Z+ H(*p).p[i-1] = (*p).p;
, |+ D) }7 N" G/ ^& I(*p).p = temp;
& I' r- z* V: v1 r/ C! E+ I% \}3 g) T3 S& {5 d0 n2 W
}8 R& B3 E/ N# k/ x" @, s7 q, x2 O
else
+ _5 B: r6 `$ s, N% dprintf("position eror\n");
7 I* m$ O* |0 N2 U# ]$ \1 Ereturn 0;
. t6 K! `; q7 j8 S8 ^! i' b4 P}4 s7 o, w: a" S9 ^
int InitPool(processPool * p)6 E. V5 V$ G9 I; ^7 B7 L# ]# k
{
# C9 @6 Q/ D. M% x& iint i=0;5 w- d" U7 Q1 G/ ]2 ]9 ]
(*p).proNum = initProcessNum;
: u0 x3 h8 [6 T m(*p).p = (process*)malloc(initProcessNum*sizeof(process));
1 {& w K; w6 d& z' V6 yfor(i=0; i<initProcessNum; i++) //init process information
) d, L# R/ h* J0 A& ]8 N{
% E( c8 \6 G0 l8 V(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));: H" D. m3 A8 n9 Q8 E2 S4 z! [/ F6 |
(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));
7 v2 j7 K/ k/ lproduce_one_task(&(*p),i,ID_FIFO++);
4 o$ o" t8 }# c}) r7 ~' T4 W& J' ~' a3 U" q6 k
return 0;
. N$ ]( C h. X8 Y& u6 U}
F$ J. I8 q( U; d4 @' Y7 m0 I/ oint produce_one_task(processPool * p,int i,int id); Y/ j5 \1 S O! b; c- y M2 h
{
* g7 W" g3 }4 P2 [/ p" w# oint time=MAX_COMING_TIME,j=0,totallTime=0;
/ v$ P8 s+ q4 b4 f2 Z: z(*p).p.processID = initProcessID+id;
" H9 ^' P) K" k* b/ ]2 P, p7 r* Z(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);
7 H$ W+ h% a- H' ` H(*p).p.produceTime = systemClock;
+ Z3 v! X: Y9 N f(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;6 B5 q/ u b7 {2 p$ X) P
(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6;
$ P4 |% V9 q& o! k6 l& CtotallTime = (*p).p.computeNum + (*p).p.ioNum;
, V! }7 L+ N4 B(*p).p.computeTime=0;
: k% w$ D5 g9 }2 b+ r0 l. mfor(j=0; j<(*p).p.computeNum; j++)* V9 y1 H- l( j' r! o) s
{* F! h, s, r. h$ h5 D! a. p
(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;4 u' ^+ ~2 H6 w1 A `, @
(*p).p.computeTime += (*p).p.computeClock[j];) e8 t! P5 @* B1 b% { q
}
) [+ W1 Q# S) i6 d. ~(*p).p.ioTime=0;
1 S4 r7 l1 {3 c" C. _& w% O" Hfor(j=0; j<(*p).p.ioNum; j++) |
|