数学建模社区-数学中国
标题: 经典任务调度算法的模拟程序 [打印本页]
作者: 杨利霞 时间: 2021-4-9 15:15
标题: 经典任务调度算法的模拟程序
8 o3 s" _4 Y0 Z8 {6 }. M) Y6 ~# f4 d经典任务调度算法的模拟程序$ Y3 F% {$ Y2 S5 G
本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。' x, _; U+ T `: P& n$ I" i
0 _' a9 R( \1 w7 R4 e
编程平台:VC6.0+EasyX图形库环境。& m& `! F# G h2 m% S( u6 y8 V
' Z, U% t2 J/ a; i, E8 Q `$ r
以下截取部分程序运行图::- a# E7 |5 F. m: y% j
3 Y n5 B# d, R& r$ F& b9 y源代码:
( Q9 B- ?; O3 N1 U5 P+ P6 ]1 _
5 Y1 a4 [1 x9 I, L. c! {#include<stdio.h>
1 O+ e8 E* G; m2 W#include<stdlib.h>. X8 A/ y+ i) j7 E+ N. j
#include<easyx.h>
' `" R. V) e5 {; i7 f) L/ I% d#include<time.h>
' y4 p! [3 \/ S( ^3 l$ k7 L! U#include<conio.h>
+ V8 g [- M# M0 ~: a0 c#include<graphics.h>
/ t' ^8 \7 p. J* N# o0 Y#define initProcessNum 105 d# w7 F3 [7 o' ]+ M
#define initProcessID 1000
3 k. u0 U9 f. f* i' H/ P8 ?+ B#define MAXProcessRunTime 10000; R/ q* S. x% E& x# U: t
#define MAX_MEMORY 40007 @9 J" e% A4 \: P) g6 x
#define exchange_IO_Compute 101 z: S/ s- l- V# ]0 l& h$ `
#define exchange_process 25
3 s% E: v+ K0 T3 V6 Q0 h#define task_completed 13 G7 ?0 r1 J4 |/ A
#define task_not_completed 07 `% d) Y8 X0 [. g# d& @
#define initclocknum 100. D w. J4 Q# }/ k, z, R
enum condition
" O1 @7 M- H: l+ c+ \/ [! q9 N{
! j( e% ^2 R7 |, ?. M8 w, cdead,computing,IO_waiting,ready3 l( e& V! }% ]4 A% i& l
};
% b' g& O4 |/ Y9 o" P1 {4 h8 Estruct process
0 T" U$ T# w4 P% i9 A* ?{
! p4 e: O! D2 K' Zint processID;
# H: i( q' }( D1 s# |5 cint comeingTime;
4 b* N0 g; v; xint ioNum;
1 ] O, |0 n5 W5 f. t! {0 uint computeNum;
4 }" I& c; _1 @% D1 O! v. i- F* rint * ioClock;
; ^6 c3 ]- r: |' |int * computeClock;
1 ^! n4 H x+ X* a+ K+ Z2 Tint ioTime;- u; P0 W' E4 [5 q2 M' v
int computeTime;8 _+ M! c* d A( _
int askMemory;8 @" H( d4 J6 |1 S. K: w4 o' Q
condition flag;
4 ]+ M3 I# D, S4 ?- b% L5 r( i/ L/ Y, a6 `int produceTime; //生成时间,以下三个数据成员用以计算相关性能2 z" K; @; a( k" C
int runningTime; //第一次占用CPU的时间
( H. e& \$ { {# Aint completedTime; //进程完成时的时间
9 D+ k3 {7 Y) c};
' k& ]5 x4 I+ m% p) k7 q: Rtypedef struct processCmpletedInfo //保存完成一个作业的相关信息
& K$ B9 Z! T% M' l2 Q{' g+ {+ M3 ~7 x% a- a% B: t9 v
int processID,comeingTime,askMemory;8 u& V0 n4 w. o
int compute,waitio,exchange,completedTime,runningTime;9 \: O2 K6 c2 F8 z; W9 }1 {( l+ y
processCmpletedInfo * next;+ g d4 e L) D" l" q
}PCI;
9 R6 B# N: A4 p. p: [9 ?struct processPool1 f- U& T. R M1 l% o7 t0 R+ R6 S
{
: f& \7 r# @+ p' _# T6 Aprocess * p;
! Q0 |4 d1 n M/ G* W9 bint proNum;
$ W% O' X8 U2 f. z};0 r2 w' Y( x# J+ F8 t. J: r+ t
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;6 K# @+ B7 g' Y' H7 Y& [) i
int InitPool(processPool * p);1 M; B6 D( g0 e9 N
int produce_one_task(processPool * p,int i,int id);
. {" U4 N$ c0 S9 O3 tint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);
- l& ]8 R1 _1 y% k& Bint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);. U0 B) F6 O: w. ^5 H, g3 ~9 P
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);
3 X: {+ G. a$ f* j) b( w) c* A& kint FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
+ K+ V# j' y( {' T2 {+ zint ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);& M' z- M2 N- Y. T9 i; q) u
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
" Y% J+ ~: Y0 v& \, F2 v }( nint PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
7 k% c- t& j5 M J& R! U, I; wint Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
; p$ ?5 q6 C4 K/ hint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);
* \0 Y/ q" a0 F9 N% Aint High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);8 O% {1 A2 E _1 c+ J/ W6 _: |
% r$ `3 D+ |9 P- \" ~ m4 \8 K- S, i \ r( W8 V1 _% f( e
int sort_by_comingtime(processPool * p,int pos);
6 T; \. u: ^' b; F. eint showProcessInf(processPool p);* M/ Z. R! ~, g7 o% e6 ?/ u
int drawPerformance_FIFO(int x,int y,int memorry);
/ g8 e1 ] U6 W( R9 uint drawPerformance_HR(int x,int y,int memorry);+ L F: t2 S4 `
int drawPerformance_PF(int x,int y,int memorry);
! q! _2 v! a2 J$ x( N0 Z/ E7 H0 oint drawPerformance_TT(int x,int y,int memorry);1 |) K% N+ {+ m6 p7 \
int drawPerformance_SJF(int x,int y,int memorry);
& [/ N0 J6 i* i7 z4 B8 p! Zint MouseListening();5 a/ L8 h1 |7 {2 W. K! ]6 v
int MouseListening2(int *flagShow,int * showTime);8 e5 j; z6 o5 Z3 L! x4 C, `' Q
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);
- l) G3 v* S* k, }. A1 v1 {& @, ^8 F7 e d+ j* ^
, ~! B9 ~1 @1 p$ A
void main()
4 \* ?, g3 V, i9 H" D4 S{% Q6 x1 e8 H4 P3 U0 H B! g& v
PCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,9 c+ f' V0 v' h, l; W
*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;
" j7 Q. m, k* a1 H9 \. E9 o2 s% `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,) |- z+ q3 a. j* B
flagDraw=0,showTime=100000;
0 ?( b7 r+ x1 v! i. AprocessPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;
, d2 ^$ E: {2 {' EFILE *fp=NULL;6 }, N3 Q7 A* z. ^& O6 U
//processPool HR_p,HR_mmy;
8 N8 P1 ~3 K2 d* ^; ^" h! Y4 V& H1 A1 U+ M, K1 b& d
( d1 L; L: c4 R$ X# G" m# W: S
srand((unsigned)time(0));
# F, Z8 R& H: dsystemClock=0; R% S8 b9 q# [8 {7 U9 @0 ^( |7 N: U
initgraph( 1200,650,SHOWCONSOLE );; @! G0 L8 Q4 v+ Q Z
settextcolor(GREEN);, B8 m# g }% j( s D
setlinecolor(GREEN);
; @( _4 U; e3 G' O8 nsetfillcolor(GREEN);
0 @* }6 c" y. L, o3 q8 ZInitPool(&FIFO_p);9 ^5 r+ _6 \6 x: o$ W
sort_by_comingtime(&FIFO_p,-1);8 ^. V4 L. G) F# z* G9 j! }
InitPool(&Timeturn_p);3 }/ |+ Q! `! K" ~ y8 ^
InitPool(&SJF_p);. p9 r6 T5 d$ n) H$ t" r( L% _
InitPool(&Priority_p);( B- N. f8 A) x1 ?8 [8 e
InitPool(&HR_p);
/ J& z% w, ]0 A* w( k2 E: R+ g/ E# i//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
6 A8 y- q; `7 b0 M6 [, e' J//Sleep(10000);7 M9 m- e1 g: ] c9 p* P# G3 \
' Q; D- M* n8 F- M" n( I
* S( X2 m! Q+ B' {: v- I) L0 ]8 LTimeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));6 D+ H) x1 m ] r
SJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));& `4 ?* s% E( Q- h# v# s8 i
Priority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));# T/ o6 i: [' k, R
HR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
4 q; a/ X6 R) f# ?$ Hfor(i=0; i<initProcessNum ;i++)9 Q1 ?5 e X/ G% N
{" u& [8 ~1 }/ h. j9 p9 a' e! p8 ?
Timeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
% }" D5 [# P; u' iTimeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));: I2 m% t; d) y2 B, g
SJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));* t% q0 j4 O" }- L0 h) H w
SJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
+ w7 K6 p# I0 A3 {* b! ?+ TPriority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int)); K4 ]6 f. Q2 h; W) U2 p- A; y/ E% l
Priority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int)); a- w+ V$ z, X+ U' j. ^4 v
HR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));5 D( m- R& r/ g9 j6 u/ m/ I7 a6 g# V
HR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
' R/ V+ Y# {9 z# ]8 b$ D}
/ Y+ s4 n, c' B* l7 JTimeturn_mmy.proNum = 0;' Z" U R: h; I+ S
TimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);- w' ?5 a. W' h8 o* U
SJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);
& B, z6 T: Z6 N# kPriority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);
! E Z9 V! q7 H9 t3 i3 V$ J# Q4 sHigh_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);
1 [/ W6 i, J7 i& h- {//showProcessInf(Timeturn_mmy);5 T2 ~/ Q* K: G8 e/ |
FIFO_pri = &FIFO_save_head;1 e' e' w$ d5 N' R1 Q/ q& }, k
Timet_pri = &Timet_save_head;
1 a# ]- o9 Q( x* u) H1 ?) A6 F; |SJF_pri = &SJF_save_head;8 f1 L* P* H0 Y& T( |
Priority_pri = &Priority_save_head;1 D/ @+ L. e5 _% U$ o, e' k% f
HR_pri = &HR_save_head;: V* m0 G& e1 x
setbkcolor(WHITE);
" j2 j1 _( Y9 D! ~while(1)8 ?- b$ w* f$ Z% {& J. T8 t6 L
{
+ T. u5 Z1 B' {. n/ s! V2 n3 ~' fif(MouseListening()==1)7 A' w8 y$ r8 E2 k* A
flagDraw=1;
; X" {4 R+ O) Z3 f/ b9 A0 }! i! w% {if(count==100)( m* ^0 L7 f! s/ E M
{
1 O, i8 t+ m5 ^, D4 v1 |* Cif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)9 D6 c% [ M- J( h* ~
{+ L0 u! Q! i( J: [. i
FIFO_pri = &((*FIFO_pri)->next);& J/ s3 J0 l X3 ~2 Q* G* c* t
6 \) Y: f2 w; O7 d9 ^3 c$ J$ R
//printf("hello");
$ @7 C& m/ D& I0 ^}
) y4 u( r% v$ R% ?if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)" B0 z/ Y/ D8 a$ M9 G+ B
{7 |/ w: L# z0 L) g6 Q
Timet_pri = &((*Timet_pri)->next);& R1 i0 h; k- c# P
//printf("hello");4 O2 w* _ @9 m: l' M
}
+ z# @) Z! {7 m, {! Xif(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)
3 n2 O4 l7 |# r- D, W6 G; P/ l{
/ B1 u N6 c# Q7 V0 P5 HSJF_pri = &((*SJF_pri)->next);
/ i0 C9 s5 q( ~0 a//printf("hello\n");4 }: U8 ]1 c' }: |$ v
}2 o6 I3 M) `8 P1 ^7 A3 Y
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed)) e5 z6 A- {- ]6 i" `$ Q, R9 K
{% }. U& U8 |' s7 y3 |# m$ a3 m) x
Priority_pri = &((*Priority_pri)->next);9 T& l2 l. o+ D3 V1 ]+ h; V! `
//printf("hello\n");
( p+ T3 D" u/ Z}; O) I- g# a" L/ U; A! Q) ~6 Y, `
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed); F* E5 [7 H6 _) D6 t
{, p2 I7 S% G& E/ o, k2 Z
HR_pri = &((*HR_pri)->next);# d. l) u8 m; o6 r: n
//printf("hello");
$ i. M0 w1 p# c}- O) N+ x# ~1 t; @; @6 y' C8 |
count=0;
) j5 [5 v9 W: X9 ~' |8 A' @* i}$ G' G L' u9 u& M$ h# q
else
1 Q- r: Q/ g! g! q# r/ g. T" Z{
# ]8 b# y9 P( G& ^# oif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)
% d |& p! `0 N0 ^3 R{9 \; c5 r. K' a( m
FIFO_pri = &((*FIFO_pri)->next);
5 i, J" d% {5 K# R n2 r( N// printf("hello");
, i( s' n" q9 H4 s! [}( x$ I7 T5 [% B; O1 ]6 H7 V$ W
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)
) u2 g i$ [9 x9 V{2 W/ S) l$ d( G/ Q: z; `( S
Timet_pri = &((*Timet_pri)->next);
- |+ d$ d* r) Z$ l! |" J3 s// printf("hello");
! l# V0 h% f5 T. D! h}* { E! D1 S& q1 T- _
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)
, g1 J* y, c& c- u% R, p1 a- m l{4 o( v& |( p1 d; R! i* P( O
SJF_pri = &((*SJF_pri)->next);
6 \* Z9 d% E- \6 V* Y// printf("hello\n");
" M$ Z- ^% k- [* {, u}
0 X! {% J, { R" V9 T$ p5 ]if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)
2 p9 n0 K7 q% f2 h, H{% R8 n& s2 j6 J# D7 F5 l
Priority_pri = &((*Priority_pri)->next);! K+ Z% j3 N; A
//printf("hello\n");3 ?* _. ?1 f S3 S' H. W, P5 O
}
* o0 y* h5 P6 ]+ Z# Bif(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)
" R5 m3 j6 K* T3 T# K6 Q+ h4 E8 ?{
9 V$ o; b' H( }# x; {: z' RHR_pri = &((*HR_pri)->next);
W4 d! L5 F! X& G% _8 B. s' @& m1 b//printf("hello");0 b d, l" a" F/ F; ]: e
//Sleep(1000);2 K" l) ?% p; @; O0 t0 x) ?6 P" y
}: q; x; b( }& X2 ?5 |& T6 v8 u% B
count++;8 G% t# e5 I6 D
}% {8 e- W+ H& x* f9 u. K
if(systemClock==showTime)
6 o$ l6 s8 h# A4 {7 s5 E. m{, |3 Y" k# t5 Z- ]# S+ f
/*PCI * p=FIFO_save_head;: k- T# y% W3 p* f0 X I* q
int i=0;
% v/ d" [: e& d) z0 {. ffor( ;p!=NULL;p=p->next)( R" t: S0 l. |3 c" l
{0 S# s! G Z2 b; C$ ~; p! i( b
printf("Id %d\n",p->processID);
7 d6 x8 a Y2 J8 J* \) ]: Uprintf("comeingtime %d\n",p->comeingTime);; |2 k: ]6 C. F2 ~9 q% `
printf("runningtime %d\n",p->runningTime);! ?" H( D, E5 `( K7 h
printf("asdmemory %d\n",p->askMemory);
- p" r" t% G" T/ w/ B" @7 _printf("completedtime %d\n",p->completedTime);
9 K8 ^" A. U% {! B# Uprintf("compute %d\n",p->compute);- x& l, e; z% n+ i/ ]
printf("exchange %d\n",p->exchange);2 `- n" I C+ y5 J" K
printf("waitio %d\n",p->waitio);
; S9 A, {6 D6 G+ h# Vi++;
% {* V J+ G7 J5 \/ d
1 W: _# |! z3 f/ C9 J; Y5 u5 x
" C4 \! W! y1 ?( U0 w* j}& ?" K# z6 Q* g6 I3 L
printf("%d\n",i);*/% E# l: j* }& ?$ F; ^- s
if( (fp = fopen( "data.txt", "a" )) == NULL )
! A3 I9 x1 Z9 s+ n+ j$ y0 F" K{
3 w7 S, \ { b# Iprintf( "The file 'data.txt' was not opened\n" );
& p3 a6 H" f+ Q) V$ ]3 K4 ?//return 1; D9 p+ ^, v; O, w! q
}2 d8 A2 X v, K% J. S
else
6 r8 G% F! q( e" ^{
9 O. l9 ^8 |& ifprintf(fp,"FCFS \n");
& `9 T$ A& V* q% y2 _- z2 Lfor(p=FIFO_save_head;p!=NULL;p=p->next)
" N) b* Y+ Y. l; b/ Sfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
; ~. j1 j; u, [8 N4 g+ F/ F5 np->exchange,p->waitio,p->runningTime);
; d7 g8 H7 `! h8 z, b$ s; Zfprintf(fp,"\nTime turn \n");
; i- _4 U- V: l) a1 h% m/ t) Cfor(p=Timet_save_head;p!=NULL;p=p->next)
. K9 W$ D5 g1 S# \% @ Yfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
* X% V; |! q. ]" Kp->exchange,p->waitio,p->runningTime);- f% L8 G( U7 D! n2 q- X( |9 _( a; u# x; l
fprintf(fp,"\nShort Job First \n");
' \ x$ T" z/ p5 Ffor(p=SJF_save_head;p!=NULL;p=p->next)
8 F% {4 H9 G L+ S6 a d/ K& Gfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,3 E1 l$ ~6 E! O# b) X
p->exchange,p->waitio,p->runningTime);. j d) g* }+ @3 N0 `
fprintf(fp,"\nPriority \n");
- N7 M! C( L: u% o" o& Lfor(p=Priority_save_head;p!=NULL;p=p->next)+ E0 l c9 \" e8 e
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
V% s; T9 x* m% gp->exchange,p->waitio,p->runningTime);+ d- E/ S, ?1 a- z
fprintf(fp,"\nHigh response \n");/ p6 {( G7 u7 O% L, E
for(p=HR_save_head;p!=NULL;p=p->next)
T& H) Z( o: V4 K& efprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
6 i) _9 f. s) R b6 O% J, _p->exchange,p->waitio,p->runningTime);
% q; f+ ]) m, K, z9 u: Dfclose(fp); S; o5 t9 s3 g" y. {" a5 ^
}7 e6 z+ U0 Y& \4 X8 F
showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
" i6 M3 A3 ]4 q$ S( \ FMouseListening2(&flagDraw,&showTime);
2 l) n+ Q5 {5 o$ F2 F4 d}
, D2 m% \3 L } v6 c! z% nsystemClock++;
) J# S0 Y, X9 T( `* ]if(flagDraw==0)
* s6 {+ Q) e8 z8 U7 o& I) Z: K. O Sleep(10);
- R" Z2 z3 y4 q, W& a3 Q} B. d+ k9 E0 G( j- L( Z# w
& v* W, s0 `% ?7 K7 [* |1 y9 X; j. b' R7 }4 k
}* T$ n) r, K. p- q) p& x0 d
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)
' U6 e9 C! m$ u: ?{
# V' n6 `" N( C: LPCI * p=NULL,* name[5];
& ?; q& \1 ~5 d3 Y# X. [$ k( |7 Yint count=0,i=0;
- x! b" v* M) L) `char ch[5][10]={"FCFS","timet","SJF","PR","HR"};
+ L4 s' e! A1 W6 z# ydouble turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};- U# B! _$ k( {, l+ P
struct info( F0 C* n4 K2 I5 B7 J& `8 j' Z
{
) T6 ^/ [, S% Y; G' G3 Nchar name[10];
% R" m0 o8 H8 Y/ _5 W, zdouble throughput,turnover,wait,CPU_rate;
) l7 D& \) Q. T, A/ ?}inf[5];& z5 ?+ }' o( y4 O4 R: k
name[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;- X* N! r: W$ t" m2 r/ A- x7 k
printf("调度算法..........A\n");" i( w/ }5 w7 D' D) S
printf("吞吐量............B\n");
2 L. g, W+ S! U4 z; @" A7 e/ }- `0 Cprintf("平均周转时间......C\n");
/ x7 G# u$ k; v* |5 l9 lprintf("等待时间..........D\n");/ o( O& t0 N1 e9 M8 R* A
printf("CPU利用率.........E\n");
: h) g" w( x! X' B8 U$ \/ sprintf("A\tB\tC\t\tD\t\tE\n");6 v! s8 S/ Q7 C5 b& `, F$ y6 r
for(i=0;i<5;i++): l+ z2 k9 v/ Q3 x
{" p8 V- Z- h5 Y: `; O* s7 N
count=0,turnover=0,wait=0,c=0,w=0,change=0; d) y" ?$ A I' m7 R8 L
for(p=name; p!=NULL; p=p->next)
" i+ \6 R: s7 M# G+ k{
( ^' i; f4 Y3 Y# hcount++;( W0 E- ?2 d9 J* Y
turnover += p->completedTime - p->comeingTime;. |& M1 ^' H8 k1 e/ ^- D. p4 X
wait += p->runningTime - p->comeingTime;( Q+ l1 g! t5 f# i( Y$ |7 q! ]7 z
c += p->compute;0 }7 c* C- |5 E! d
w += p->waitio;
. O9 _+ m! M2 n0 m9 ?/ }/ x2 Uchange += p->exchange;
8 s3 _4 f- G' \: Y: `}. m6 {0 R; D/ {, Z
turnover = turnover/count;4 [$ H) b- g% m4 K3 L; Y
printf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));* x+ i# K2 l5 o, v4 X
strcpy(inf.name,ch);
& \* j" i3 w% Qinf.throughput=count;
( }' z2 V" ]' _. S: ?1 V6 F! Minf.turnover=turnover;6 H: l% R1 h7 C7 n4 s+ t
inf.wait=wait;! O( t9 c. ]+ J* c$ h) m
inf.CPU_rate=c/(c+w+change); m8 Y4 n& U) X- O7 I
}. X) a' W6 P3 p5 v: K( U7 e
//画图, I, l9 F$ }3 e/ N6 i: ?0 i) }& B
//cleardevice();
: I# ?* z; g' W7 g- b$ Yline(0,600,1200,600);% @/ X2 r" f; W
line(10,600,10,200);, \: A1 K9 N3 \# J% X" D
line(10,200,5,205);: |! y8 c+ H0 r6 K( N7 M
line(10,200,15,205);
+ Q& L0 g) R+ E" C# [- ]8 a$ @2 [) xline(310,600,310,200);5 B2 {! S. M8 t
line(310,200,305,205);
8 d, ?+ S2 k6 w$ t5 ]9 s+ t' \line(310,200,315,205);
& x/ P" L& X/ A [7 pline(610,600,610,200);, Q* J0 v* {. q6 B& F- y3 H6 z" |
line(610,200,605,205);: g3 N* F6 t/ G# X! i3 w
line(610,200,615,205);
; T' \' E' m" Q1 X8 cline(910,600,910,200);- H; z6 v. ~# S+ i# p- g
line(910,200,905,205);
/ V3 M- x- O+ A9 ~line(910,200,915,205);//最高的长度400,宽度均为40
& r% Y9 i/ o! a p8 e2 b, [: u6 Lfor(i=0;i<5;i++)
# p( P! A# @. {7 W{
. C* R( y: B' z8 ?* Dif(inf.throughput>pos[0])/ T, O& @4 w# W7 q0 h
pos[0]=inf.throughput;
( T, W4 A2 y( K; p! [if(inf.turnover>pos[1])& ~/ d) R" _" I( U0 M3 ~ }
pos[1]=inf.turnover;; n0 q5 g; y, y0 ~$ U8 x
if(inf.wait>pos[2])- i: q/ ^- X# [+ R6 ?! g5 p1 M" G
pos[2]=inf.wait;5 ]$ x, N7 y$ d
if(inf.CPU_rate>pos[3])8 r; ?# b/ N# Y& s) c( b
pos[3]=inf.CPU_rate;% }1 b' T( F" @9 Y# l
}
$ o/ e6 v; }4 T1 esettextstyle(30, 15, _T("楷体"));
/ r! D3 P$ E9 ^$ @- h. Y8 I. Nfor(i=0;i<5;i++): \( Z4 g$ W9 \5 `
{
& t6 z. z1 x" R' r4 o h1 {4 ^+ V! Eswitch (i)
5 N2 h6 T% ~& f7 F/ e{3 I) w! d1 W3 V% l1 K
case 0:5 B! l6 d1 M% W1 M6 C2 E
setfillcolor(BLUE);8 K+ ^0 ~% s1 ?) b: b2 D% f
fillrectangle(100,50,150,100);2 J0 d- `8 y" I+ B
outtextxy(160,50,"FCFS");
4 g. b6 R. \8 qbreak;
$ w) L5 h" O7 S x8 Hcase 1:
6 H% a' W. Y" Y% H5 Msetfillcolor(RED);' |' p( x7 e& g A) i4 j
fillrectangle(250,50,300,100);+ H$ Y c3 V# _- m6 E& @# v$ x: B
outtextxy(310,50,"timeTurn");* k6 g9 A0 r4 ?6 y
break;
: T l; s/ g/ P6 b( |; Lcase 2:' z; }7 Y; }' i8 I f
setfillcolor(YELLOW);
6 S) O6 l) S3 ]7 u# K4 \& qfillrectangle(450,50,500,100);4 ~: c w! h( I' p+ r+ e
outtextxy(510,50,"SJf");
( k; ~4 a, @* b5 U3 wbreak;# L% P; T/ b0 w+ d
case 3:3 N( }5 Z# [: f" d' `
setfillcolor(BROWN);
8 t8 O0 E7 H( a4 _" k9 ]+ ^ Rfillrectangle(580,50,630,100);
/ N+ i1 Q$ L: x( A3 v6 C4 Vouttextxy(640,50,"PR");1 C ?, o' M3 g: g7 y8 F
break;
, ]! {$ f- P" v+ S: Y5 v( g& h" j8 U* h# Fcase 4:
" i! m3 u) }8 m" h$ psetfillcolor(GREEN);
: C; d& R0 H3 _! M$ Z" K5 {fillrectangle(690,50,740,100);; u8 ^7 {1 a" a9 T$ Q w
outtextxy(750,50,"HR");7 o9 \# m( S- L3 p( o# E
break;! r6 e( b% b) x# ]1 g% ^
}
3 [* j2 _0 ~$ J8 @9 L6 c: \fillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);
" k) d) }1 n$ v0 l1 I( L" Pfillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);
: V; e/ B/ N% h! }8 G" p0 \7 wfillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);7 Q" u) y' G+ d
fillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);. {3 W* B2 A# Y$ N+ s: A/ l& z
0 D k4 A% J N
6 g$ P' T/ J A4 `$ s3 e( l}
: e% W- } O* g/ w9 \ R3 d g outtextxy(100,150,"吞吐量");
1 x6 w" \$ n* G, W3 F/ d2 T3 [$ Oouttextxy(350,150,"平均周转时间");
( J# F9 a* b" M0 v1 f, zouttextxy(650,150,"平均等待时间");
' X4 ^; ~6 ]# zouttextxy(950,150,"CPU利用率");
% {- J$ s$ O2 s4 d. ^2 Xreturn 0;
7 P% ~: z: d: X$ N- x1 z) E, X}
! [/ Y; r9 K- U! C: { d5 Wint MouseListening(), ^8 }& I( E9 t: C( ~8 [
{
5 P9 c d# y) T7 u W5 @MOUSEMSG p;3 S$ @4 [2 K6 e8 W
if(MouseHit())
c2 E" ]" ]! C# a. T6 p/ \. T+ g{$ }1 H/ ]2 Y. ]0 p
p=GetMouseMsg();
- Y* ~$ I4 R* z2 ~0 g5 Hif(p.mkLButton==true)7 j) W' V, Z- e5 C) q8 \5 \6 H
{. C6 D' C$ M5 g* R+ h
if(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0). V' V+ ]" s1 s
FLAG_FIFO = 1;9 O$ M6 R- C2 w7 @; c) Q
else if(p.x>400 && p.y>0 && p.x<800 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
1 h( E. G3 |& a S" N+ E( \: a" hFLAG_TT = 1;: U/ ~5 x& t# K3 @
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)
7 T" X2 z* p' Z3 ^( c4 B( AFLAG_PF = 1;$ p' ~. ]& c: H% b% {6 }2 n
else if(p.x>0 && p.y>325 && p.x<400 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
% h" C% B. d- T' v: {* V" @FLAG_SJF = 1;
6 ~0 w. L/ ?' ^; F. J. F" `7 A- [% }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)
3 @8 |9 [9 b* C$ S' o- jFLAG_HR=1;+ Y8 c9 T5 b; T' r( Y% w. k
else if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)
# T0 Z& ]8 K+ o8 d p{
. A! g: o- G, n iFLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;
# s5 |. t9 N3 U$ E+ i! P8 b4 A, o0 Qclearrectangle(800,325,1200,650); ?& |( {( w) ?& x& x
}& {) s- R; C) z, Z
else if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )/ G2 y8 |% v0 T( m6 M& S0 T
{' W% [ w9 x5 Q. X
FLAG_show=0;
# a2 n w2 e' v2 Z3 wcleardevice();6 u. }' d5 Q# ]$ ?/ P, G7 v
return 1;# x, X) l7 e' y' \; ^
}
" I2 \% f4 _ i}
) h. N8 t9 `2 M- P2 I: q}6 T f! |! {# V( ]- T$ K c
return 0;2 Z+ }. i/ b" X) \' q3 V/ x) K2 Z
}
6 {3 N3 k- t& w& P" t( X! qint MouseListening2(int *flagShow,int * showTime)% S7 D# r8 e+ z" g/ `7 ]" W! e4 O
{* f9 g9 K! i3 z4 {! K5 Z
MOUSEMSG p;* ]( k: m7 w' Z d/ a$ x3 r8 l( ^8 p( M, ]
rectangle(1150,0,1200,50);! b5 W1 Q# ?) j2 V* n
outtextxy(1160,10,"X");' B* x0 m, V/ x! F' e4 b5 ?
while(1)- i& r9 l. p4 ^7 G6 e7 Z3 C3 h) h
{
" |$ v4 D# d& f2 m. f+ X' ^if(MouseHit())
7 l- @/ [: U. E) ~1 U{
. K7 r8 I+ T h# W9 i j& Np=GetMouseMsg();. F4 S. ^4 d8 c8 G0 u# l! k* h" b
if(p.mkLButton==true)
4 _9 A. n( v, I. N! T& E* o1 x( ?{4 |9 \2 t5 q$ |$ W2 I* j
if(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 )
. L5 P6 _ M' V9 Z& Z{* V8 j( [9 s4 V/ [/ O8 y7 j
(*flagShow) = 0;
5 T8 W% L8 K6 L* R; o- d. d(*showTime) += (*showTime);
* O. l: v; y$ p) QFLAG_show=1;
7 v: K: I* F+ E7 k2 s) Tbreak;9 A, x# S" f. R: I) r4 L- K& T
}# Y& J t" Q' Y
5 S: S. ?& H) l8 _9 G9 G( R# i}
; G, Z6 Z5 D5 M' J}
! Y# I1 N# K8 a0 p7 WSleep(20);
0 q3 v3 T) K0 I& Y}5 h: @6 s& {) V! Y
cleardevice();
4 X% ~ n7 U& V$ B5 f) i$ D1 m" `return 0;5 r* \: g, c+ r7 ?: p0 y ?
}3 R/ ~5 m- J0 a) @0 H5 e r" s' w
int drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)
/ v% A) l. |$ ?1 V8 U{
2 I% k1 D1 |3 e; _9 k5 P$ f, ^static int info[11][3],num=0;# w& _* T# a9 w' C* x4 }0 ~
int i=0,j=0,pos[10][3][2];' ?+ d5 Q5 S! G* C
float temp,t;
' A. o* s' C- E( a( ~7 G' D1 _0 Z//画按钮,不属于FIFO图的范围
' r; P6 O, J+ E. c" ?% g! hif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1)" r" t: F" q' i) @+ y: ~4 ^
{ t7 o6 S" m l. D8 S- \
settextstyle(30, 15, _T("楷体"));5 J7 {% O- b, D2 G
rectangle(890,455,1110,510);
& j* [7 o2 z+ f* S4 H/ c5 x' {/ n* Srectangle(900,465,1100,500);
/ X, z$ l; S" w0 x5 _outtextxy(910,468,"查看运行结果");
( E1 X: l2 n/ ?( E p' g1 n}
) X! U& |+ l) u5 H' X//结束画按钮
& a! n# L3 S* m8 |) Dinfo[num][0] = com;
, s& j% D! B) U$ p& B2 A2 v3 c' winfo[num][1] = wai;8 P& N. C8 C" F+ S" g, Z
info[num++][2] = cha;
) G: D5 e- E+ o' u4 o. i' Zif(num>10) //存储10个点; X; F6 b8 F4 I T' g8 L9 T
{
* S2 c, p) X: a! g* ]1 Dfor(i=0 ;i<10;i++)
! [: n2 M g4 f. p5 a{2 p2 {; e# _# ?! z# s* t' L" g: t
info[0] = info[i+1][0];
& l+ b/ w* W0 Z8 x7 Cinfo[1] = info[i+1][1];* i6 [0 f- c/ ^3 o5 k7 h+ D
info[2] = info[i+1][2];
; `8 @2 U/ p$ Q$ F! C6 |) N}: |. r# d4 s1 i5 ?6 ]
num--;+ K, z8 J2 G/ f& T# D
} b3 S) U) E0 ?. c. _2 r
if(FLAG_show==0)0 L, e! K, B5 r
return 0;
% P; h1 T. V& E" C* G5 Y, v' `# Ofor(i=0; i<num; i++)
5 X) a9 A5 r7 m. G& c8 a{
# D: N- Y% f: ~3 Xt = (float)info[0];2 Y# P! w. `+ g2 R
temp = (t/101)*90;
1 W5 ~8 z' b8 s! a X) ?4 a. A# W3 g) cpos[0][0] = (10-num+i)*25+x+100;5 v! U* t& E( B; d/ E9 U2 l
pos[0][1] = y+110-(int)temp;+ j; K# d1 X0 ?) L
t = (float)info[1];
% o+ q3 W0 b" Y% ttemp = (t/101)*90;
) N( b3 |4 y" E. v, Ipos[1][0] = (10-num+i)*25+x+100;
! Y) ~1 G/ A" G+ h1 B. F! D* qpos[1][1] = y+210-(int)temp;3 y r* _& @6 p, ?+ c* u( ?9 R% s
t = (float)info[2];
4 O ~4 n; w/ [! c- h o3 e4 Dtemp = (t/101)*90;/ D+ E! H5 O8 C9 n# |* m+ W
pos[2][0] = (10-num+i)*25+x+100;
9 Y, O: E6 y; rpos[2][1] = y+310-(int)temp;
$ O9 M8 `& X, l( N) D}
2 V+ f7 m, z# x; S( _& Yif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)* O9 ~# _) ~5 Y/ H+ [) L( W
{- g2 r& Z: y0 e/ M% T
clearrectangle(x,y,x+400,y+315);
0 _" a; O2 J& V4 }/ |5 H% j0 u5 Jsettextstyle(20, 10, _T("楷体"));% J: p4 ]3 [+ S, \
rectangle(x,y,x+400,y+325);! b& }, H" a7 l1 T5 }
outtextxy(x+40,y+10,"CPU"); //画柱状图2 m# y @# a6 v1 d; [- e2 J
outtextxy(x+45,y+10+100,"IO");
: [6 y# L" A$ \: L4 xouttextxy(x+40-15,y+10+200,"change");
, U/ X- {) |/ ]% |3 l# f7 \- grectangle(x+35,y+30,x+75,y+110);# X3 P' j' ]: n ^( k
rectangle(x+35,y+130,x+75,y+210);3 M& c7 l5 U0 b" b( ]
rectangle(x+35,y+230,x+75,y+310);
; S ^4 ~9 v& L: a0 L! j( touttextxy(x+180,y+310,"FCFS");. V$ {6 C1 y4 O, K9 B* p
t = (float)com;
& t1 x0 l! Q1 [3 G( ]9 `temp=(t/101)*80; P& \& e1 O2 D& v f/ a
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);( D, [4 w! }& M8 x) w1 q
t = (float)wai;
" D7 h" `, n8 @+ I. X0 i$ ]: ltemp=(t/101)*80;; a. p& f' F( N
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);/ g$ Y* \! |6 b
t = (float)cha;
7 ~1 `2 V" x% p5 Utemp=(t/101)*80;
: E4 Y+ l) g* Z- W3 s8 \2 S+ `9 ufillrectangle(x+35,y+310-(int)temp,x+75,y+310);
1 E: N! x6 C4 c4 p! u& l) d# ifor(i=0; i<3; i++) //画坐标 high=90,length=250
0 F: G+ W/ L0 e{1 P( r ^( [! P6 S; w" h- t
line(x+100,y+110+100*i,x+350,y+110+100*i);
U0 j& q* X1 X4 ^! m! Qline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
) p- q e) w& }line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);4 y: B/ [" t" n4 f: F
, R7 e. K8 U* O' Y' T$ d2 c O3 U
line(x+100,y+110+100*i,x+100,y+20+100*i);
; q3 D5 O; I0 {6 Q |line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);( ?, L; o+ d: }
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);( |! E; l o& g8 H: f3 F* ^
for(j=0;j<num-1;j++)
$ m+ w0 e0 b1 ?) h{# [/ E) t d* ~& ^# q7 G
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);7 d! [+ o6 ~$ t$ m
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);4 B5 V* j. H) Y6 B
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
8 U+ u. r8 C2 b. d}
5 ^1 p: _% X8 Z5 p. a r2 @0 _! |}& `& e9 y# k# q+ [. G: B$ J
}
% B. u5 ^& a9 _! Relse if(FLAG_FIFO==1)
5 z% M& R. w, O- v3 o- {3 w: r( m* y{
( T8 I' k, T- G; _" _& ^& L5 ux=0,y=0;9 B b+ U3 t2 G8 l
for(i=0; i<num; i++)8 @9 s B7 P+ J) j
{4 z8 \! ?9 d! m' m8 \& a
t = (float)info[0];, v3 Q4 P) u1 u$ a8 `; H7 X" \- G
temp = (t/101)*180;
. M0 g8 s( d( q Gpos[0][0] = (10-num+i)*50+x+650;, M) ~# w3 `" x/ g! t7 N* u
pos[0][1] = y+210-(int)temp;
- \2 f5 D8 j- q3 u4 W' Ht = (float)info[1];
! ^ p. e, o$ X" k2 b- itemp = (t/101)*180;
3 E8 H% A: v0 Gpos[1][0] = (10-num+i)*50+x+650;* f" \* a5 m& a" p3 b* d
pos[1][1] = y+420-(int)temp;
1 K d! d, C- G7 P4 Xt = (float)info[2];( g" |9 g, K8 S
temp = (float)(t/101)*180;6 u, Y4 C: ~2 _, w
pos[2][0] = (10-num+i)*50+x+650;
$ A0 W) q N. D) L$ Fpos[2][1] = y+630-(int)temp;
4 n4 K% ^' x! @! D# Y" n3 B}
$ `' q7 q6 B$ B: q& ?clearrectangle(x,y,x+1200,y+650);3 W3 t! \: S0 E4 x0 N0 p
settextstyle(40, 20, _T("楷体"));9 N) G- W3 J3 L
outtextxy(x+50,y+50,"FCFS");/ o) c3 ]- I, Q# y/ T8 p' `' _, G
outtextxy(x+280,y+20,"CPU"); //画柱状图' P! o/ U1 u7 K% v E' G" Q6 P" F
outtextxy(x+285,y+20+200,"IO");
- e W! @4 O2 V* ?outtextxy(x+250,y+20+400,"change");: ]+ E' h1 X q/ c
rectangle(x+270,y+65,x+330,y+215);6 H) x" M0 e# f5 W4 z
rectangle(x+270,y+265,x+330,y+415);9 B. B D1 K! b; G6 K9 ]4 R
rectangle(x+270,y+465,x+330,y+615);
) A: s) [4 J' P) f! e) Youttextxy(x+290,y+620,"TT");( {5 N3 B1 w& U! G6 K
t = (float)com;# v! I; s# `" r1 Q( u4 {/ Q
temp=(t/101)*150;
! r. Y4 V& e8 k! q- `. ffillrectangle(x+270,y+215-(int)temp,x+330,y+215);
: A# l' Y1 R8 Q3 D. Gt = (float)wai;: V; Q# e) i; q9 |& c# |; [
temp=(t/101)*150;
7 D8 n4 D* R" @$ [5 rfillrectangle(x+270,y+415-(int)temp,x+330,y+415);
( x* f( M, r/ @1 i6 N: wt = (float)cha;
' m' [9 @" l0 N4 c' Y6 Wtemp=(t/101)*150;( t4 U$ R Z8 w4 g) Z& l: k8 A1 q
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
; u6 C8 l9 \/ wfor(i=0; i<3; i++) //画坐标 high=90,length=250
/ q$ c L X5 I' j( k0 a{. N. N: s& E$ ~' T$ B: i
line(x+650,y+210+210*i,x+1150,y+210+210*i);
& n3 }7 g5 S/ Uline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i); z) q$ e6 k9 A! Q: d+ r# H4 i o
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);! m* s5 k' J2 e, ^; _ z5 n
2 c7 p9 @ a' L! }# R3 X
line(x+650,y+210+210*i,x+650,y+20+210*i);. W i5 [. p* j* O! C" l
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);- z" `& x& k. g. W0 T2 b1 S
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);. R+ D8 \9 y8 Y; M8 U
for(j=0;j<num-1;j++)$ J/ Y# g; P# @0 M6 w4 d8 p
{! |/ o0 z4 I# L3 `9 j' o
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
% C: ~4 N. Z- O8 Wline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
- G7 T% K0 z& f m, x: z! Nline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); # z! ?0 O+ E$ f9 C# X
}' u& Y3 O" t5 m
}
" S, d, G$ {9 I7 g, P- z}% }9 J, C; X$ ~ d0 H
) t/ O4 |9 p: y
# J2 t* X1 x" e' H) s& rreturn 0;5 g! `5 Y3 z! |3 V# ?1 N% v7 n. A% v
}5 V( s- J* h8 { K
int drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)
3 Z* L( T9 O2 R+ [- |0 t$ j' P{
1 Y% [3 L+ @ }1 ~# Vstatic int info[11][3],num=0;( o2 B. ~/ ^7 w5 D }
int i=0,j=0,pos[10][3][2];" e+ |1 |3 G5 y) j: R# M
float temp,t;( }" W$ O, l1 c8 N" A' }
info[num][0] = com;
, {7 t" q( w8 C4 H( ^8 V' d+ Ainfo[num][1] = wai;: [/ z6 \# n0 n
info[num++][2] = cha;
; r0 k% |" `4 S/ B: I; u4 w( Nif(num>10) //存储10个点- z8 A( O0 {) m; P2 N9 f
{5 F8 D0 ~1 Y$ x. L& _: E
for(i=0 ;i<10;i++)
' _2 C4 v5 r( R1 R! X+ L{: }9 N9 D5 ?: R6 b8 ]
info[0] = info[i+1][0];
$ d3 ~5 _: v+ J2 ]6 |info[1] = info[i+1][1];
; D+ r7 Z, k9 S5 w$ z0 Y& Hinfo[2] = info[i+1][2];9 m, q" ~# c& q9 R0 O4 |9 F
}8 y6 g# C- |4 h2 f7 {
num--;
5 C4 [1 S# a# O& s, j* |! d}
% x7 g/ t, ?4 E; d" F7 oif(FLAG_show==0)
2 S$ `* L1 b) B* H6 {& h6 Z3 N1 P* rreturn 0;
) u" l% I6 w2 J4 @0 z; R) ^# Mfor(i=0; i<num; i++)) N! O- Y& n1 l1 e+ L
{$ Q* s% [5 F; M0 t2 t
t = (float)info[0];
( M( m& H9 d+ |3 I% l& ~temp = (t/101)*90;. p( \# o! M- i w4 j
pos[0][0] = (10-num+i)*25+x+100;% Y" Z7 U0 u: H& V% d0 H
pos[0][1] = y+110-(int)temp;) S2 H0 n" Q% N8 \" ^
t = (float)info[1];/ H$ x) d5 a5 i- C
temp = (t/101)*90;
7 P6 h! R4 O- `7 vpos[1][0] = (10-num+i)*25+x+100;
& ^! T1 g( b$ _$ mpos[1][1] = y+210-(int)temp;$ s+ ^# M7 ^+ u8 y* ^% I
t = (float)info[2];/ N! W9 ~) M1 V4 W' u" J
temp = (float)(t/101)*90;; p* O" k# [/ _, y8 S- S' M( h& U* |! q
pos[2][0] = (10-num+i)*25+x+100;
: ^5 h' p* ~0 G; o( c- _pos[2][1] = y+310-(int)temp;
3 f' I+ U1 \$ s @ h( _}: r. @( Z7 \( f& _$ K
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)- [4 } t. ?3 {) x
{9 \( i5 b' g" Y7 j# E8 Q
clearrectangle(x,y,x+400,y+315);0 }# Y! I1 \& Q) Q) V
settextstyle(20, 10, _T("楷体"));
4 ]1 w$ K" \- O9 c. \. Drectangle(x,y,x+400,y+325);) t' Q) w+ `3 H! a; [
outtextxy(x+40,y+10,"CPU"); //画柱状图
3 K7 O+ A9 I2 k: R/ bouttextxy(x+45,y+10+100,"IO");
E5 g8 F' r& Routtextxy(x+40-15,y+10+200,"change");
0 y6 ]6 p# N( k: \9 Y, x7 N5 lrectangle(x+35,y+30,x+75,y+110);
2 D5 R8 d$ e5 r' Srectangle(x+35,y+130,x+75,y+210);& ]6 K% y! Z" N+ _ y+ s
rectangle(x+35,y+230,x+75,y+310);- E% O+ x) a% B' r
outtextxy(x+180,y+310,"HR");8 v- u$ t2 G: ]1 F0 I$ V
t = (float)com;
9 y- ~( |1 g5 v4 M% W$ S8 itemp=(t/101)*80;/ I. u9 ]! `( B" ]" D& s1 U
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);+ V, K0 s2 b% _2 M
t = (float)wai;% l0 E, w- W& J$ O; H
temp=(t/101)*80;$ |. i w, `8 f# x) r. @' ?
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
' t8 l" a6 F: _t = (float)cha;7 f3 U l( J6 [+ p5 G; U' Y3 _
temp=(t/101)*80;
* ^6 r5 g0 x I5 p) p5 V; `3 ]$ ~ d4 {fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
* }7 B, j" a* A& ]' J$ K7 D9 Ifor(i=0; i<3; i++) //画坐标 high=90,length=2500 v) `: U* B6 i2 w
{7 [' w, N$ {' l% W! J* x; s9 X
line(x+100,y+110+100*i,x+350,y+110+100*i);
" m) t5 M+ n% zline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
1 m. d: ^& {+ ~4 w+ A6 T6 ?line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
+ h% \( S: V; l$ w4 C
]- ]5 ~# l: [line(x+100,y+110+100*i,x+100,y+20+100*i);5 Q7 z6 P- S/ V. s/ x: ^2 o9 a
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
" ^; p- y3 U5 Iline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
4 n* u- C4 p8 N- A" [for(j=0;j<num-1;j++). L4 E9 v) U$ A
{
* c6 i- u8 a5 u. E* ^5 Oline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
- |& M# G, `! E& H4 iline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);$ N4 P1 R. J6 j
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
* K5 F. S r3 G U3 f}
5 i9 l9 l/ m- W9 x} R( `2 z/ v M
}; R. R' G& S, ^: e- ?; m, k% h
else if(FLAG_HR==1)( g" T8 t( M% a0 O# {
{
# ?' G g. O, s+ g7 D& p# Mx=0,y=0;
1 p" K U* T+ t6 P5 e, jfor(i=0; i<num; i++)
. G2 B( u: Q$ C, X{8 N$ R/ l. ?: @# C S0 g
t = (float)info[0];5 O6 g; k! X% y
temp = (t/101)*180;: W- a. f% p) ]5 i# g; P3 V5 H
pos[0][0] = (10-num+i)*50+x+650;
# C' \0 Y. O9 S* h2 \pos[0][1] = y+210-(int)temp;
6 l1 Z8 Q/ w, s* n; Rt = (float)info[1];
5 V- S9 P, m9 X$ i6 M$ h9 ?& |temp = (t/101)*180;- v' {, h# n8 n9 A
pos[1][0] = (10-num+i)*50+x+650;
8 W5 r4 ~! d8 Vpos[1][1] = y+420-(int)temp;
# q0 X; L3 \9 r' jt = (float)info[2];
. F1 A; |* G# V2 ^1 H; mtemp = (float)(t/101)*180;9 }; A( L/ Q) C" E* f, Y
pos[2][0] = (10-num+i)*50+x+650;
, c% N3 {: ~ _% q% I lpos[2][1] = y+630-(int)temp;( W/ d9 @6 z ?8 v( _
}
0 k) y( n8 e+ T% Zclearrectangle(x,y,x+1200,y+650);
$ z+ z2 I& v" y Y$ Q& S. ~settextstyle(40, 20, _T("楷体"));
7 ^5 [, C' u7 O1 g& U: I- M: {outtextxy(x+50,y+50,"HR");" M$ P Z/ }9 ?& {# x
outtextxy(x+280,y+20,"CPU"); //画柱状图
8 I0 O2 b2 [3 Gouttextxy(x+285,y+20+200,"IO");
P j ?! b$ i, V2 [5 {# _8 k8 I Pouttextxy(x+250,y+20+400,"change");6 v, i5 o. D5 S* j& Y4 I4 x
rectangle(x+270,y+65,x+330,y+215);
( \3 W4 y# A+ Z5 r' Zrectangle(x+270,y+265,x+330,y+415);- N3 ?' b; X3 w+ @1 N
rectangle(x+270,y+465,x+330,y+615);' @ K( e& G# G. a( G9 p
outtextxy(x+290,y+620,"TT");
# e' q& g* u6 \- f, [( Dt = (float)com;% |/ A) `' q) j
temp=(t/101)*150;
' n, o& ^* k, |" F4 gfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
: N5 H# p$ g# x4 @* }t = (float)wai;
+ x) k* g5 `# J1 k4 Wtemp=(t/101)*150;6 p8 {5 W* N' G N
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);) V* y. ^$ X6 P7 C- J
t = (float)cha;2 H4 | d5 c) L" D) o
temp=(t/101)*150;; J% ?1 e4 S) o9 B7 V5 k
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);6 w/ T7 g4 g& H6 E# j# ]7 V* P
for(i=0; i<3; i++) //画坐标 high=90,length=250: J) i, i. d" ~/ B+ e
{0 s/ h3 R: t3 J. {# V$ L/ a) n
line(x+650,y+210+210*i,x+1150,y+210+210*i);9 C' P/ ? P# w# o% ]
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);- [0 R" h( ]- z/ r/ E" T
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);2 U6 n. m3 d& @$ o0 {' B' k
! Y& ~/ M; e7 f) H
line(x+650,y+210+210*i,x+650,y+20+210*i);/ |+ F) s2 a+ O! D- P F: u" ]
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);( @4 j, l2 v6 T/ {* }; Y& D
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
8 w+ V i9 u$ u- B" B$ p4 jfor(j=0;j<num-1;j++)
. S! g+ N3 M4 }5 ~7 d, v1 w) I{
( s7 C3 d9 _" o' \2 e) Y& S9 fline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);8 W; S7 p3 ?- B) M/ v
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);: \. l+ L! t7 K
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
3 u5 U( i) m/ o) R}
7 ]" n( N4 T4 p4 _}
+ R- D& ^$ X4 [4 F$ c; b' q}6 W8 @9 m' j6 Z# R9 V% _
5 f' X, F. j4 i- C% k
. ]+ f- j! \4 L
return 0;
- S5 O7 s4 [0 U& R0 n}. s, Y/ \! w4 w3 @
int drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)
$ @- k# z! I2 T9 l{& v' r- S) C( S
static int info[11][3],num=0;; r0 ` K$ {- f( H* o
int i=0,j=0,pos[10][3][2];/ X$ h: s9 E9 G( G+ J6 a
float temp,t; D& q0 T6 X! t8 N
info[num][0] = com;1 F, ~0 r4 f [0 _% a
info[num][1] = wai;. ^8 ]! m1 j8 o3 D9 f0 n
info[num++][2] = cha;% ^2 @. r9 G# x3 a* B! `" G6 ^
if(num>10) //存储10个点
, X0 L; u+ R4 g: ^, v0 y5 C{7 } X& ?4 W3 g6 C/ O1 \ ]/ Z" L
for(i=0 ;i<10;i++). |9 P b3 H) h3 |
{2 |1 C: {. J0 L* r0 D9 y( J! o
info[0] = info[i+1][0];
+ Y2 j7 }4 {: ginfo[1] = info[i+1][1];
1 Y% c/ {+ e- V6 v# D8 C& u; [+ v. einfo[2] = info[i+1][2];( ^; S# A6 O7 G) O( L- p! i3 w
}
; w% l4 B8 t$ gnum--;
1 t2 U4 _9 E3 p3 T0 ~7 e}" s/ ]) E) y8 q8 m3 G% B4 N# R/ d7 j
if(FLAG_show==0)
" L* Y7 P0 M! g# u% O% F7 p% creturn 0;7 e' R3 H8 T' E {: G) \6 X
for(i=0; i<num; i++)6 n# ^8 m+ T- e0 ^. O# `
{
7 {6 r) I; Z; g7 a5 C% E% qt = (float)info[0];5 E1 O4 U1 h( g; W/ D) O% c, D
temp = (t/101)*90;
- F4 j$ R4 L: ~ {" S! a8 lpos[0][0] = (10-num+i)*25+x+100;
4 {) h3 |* E# B5 bpos[0][1] = y+110-(int)temp;1 X7 I) C4 t+ Z9 p! y* _' T0 j; V
t = (float)info[1];
! s: L3 D# Q, S6 \5 ]/ a% dtemp = (t/101)*90;
) j* {, ^/ _# N! L; c1 ?& h7 P" ~pos[1][0] = (10-num+i)*25+x+100;% B a1 x {; ?* L3 D, M! m: {" n( ~
pos[1][1] = y+210-(int)temp;4 I$ t2 ~. R4 U
t = (float)info[2];
6 O! I V9 @& s" D0 ?8 M0 T% g2 Ftemp = (float)(t/101)*90;
1 _/ J) k8 V: |# npos[2][0] = (10-num+i)*25+x+100;
) B* T1 p1 O0 S2 r3 v8 a* k$ epos[2][1] = y+310-(int)temp;) T: Q+ ^8 H$ i! G9 r7 [
}+ u# n7 u9 c. E
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0); y1 ^+ z* u* _7 z8 w2 ~2 M1 S( c/ K
{( l" o2 J8 r1 W( D8 w0 F# I& N
clearrectangle(x,y,x+400,y+315);
9 O6 f! U" D4 \& }+ Z( isettextstyle(20, 10, _T("楷体"));
" C- G& P) ]9 Yrectangle(x,y,x+400,y+325);$ ~# R. t% P& E/ x7 K. |
outtextxy(x+40,y+10,"CPU"); //画柱状图1 G. I/ S) U6 r; T' P% O
outtextxy(x+45,y+10+100,"IO");
$ s# A5 m! A$ c( ^- \# j* ] vouttextxy(x+40-15,y+10+200,"change");& s, Q/ G9 m0 z6 z; b3 ]- ~
rectangle(x+35,y+30,x+75,y+110);8 v" |- b/ X6 j! i+ R
rectangle(x+35,y+130,x+75,y+210);
7 z D: I, T, c6 o' H6 _: Mrectangle(x+35,y+230,x+75,y+310);0 z0 U5 z; a) G6 E1 D
outtextxy(x+180,y+310,"TT");
/ ^8 T/ G3 b2 f& ft = (float)com;6 |7 F0 d+ g |& x9 ^
temp=(t/101)*80;
6 D/ `$ R- }- p6 z; E% pfillrectangle(x+35,y+110-(int)temp,x+75,y+110);
" M }: F0 Z( a1 W% G2 [t = (float)wai;
$ G+ t/ g6 u7 O) f8 Ctemp=(t/101)*80;/ e5 `- G* p c) ^
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
6 l# o$ J6 R, ^/ V x5 n: ~t = (float)cha;
% f9 G$ B+ q0 ytemp=(t/101)*80;+ q2 ]: N% e# `8 B
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);: T8 C, t, F( `/ j
for(i=0; i<3; i++) //画坐标 high=90,length=250
; ~, @; X0 K! J5 o( z{; L7 p: U( g! D; l" v" |
line(x+100,y+110+100*i,x+350,y+110+100*i);
6 j+ `$ B4 s7 `( E- E0 N6 Uline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
+ b' ~; V& W9 m" w9 L4 L$ U" A4 qline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);+ {, |2 A% r4 ^" o e9 d: d4 v
* ^8 n7 n$ a# R$ q; D* ?1 xline(x+100,y+110+100*i,x+100,y+20+100*i);
9 L: R+ R/ K* J4 E* Aline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);- r5 j) b' A5 a3 _1 t
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);! |: ]+ t3 [* r7 F
for(j=0;j<num-1;j++)
" X# {, c# K2 C- ^{
( t. v7 r: G& r0 G% e; x6 |& }/ G2 @line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);, s D( u2 u* ^5 z! T. ~
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
0 |, n: N! y( o) f( ^line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); - B; g* f# f. P, |/ u" y% k! {0 G% y
}' {3 H/ O; D" R% E2 R! X4 P
}
( Q8 o3 n6 Y% A}
O- P- r2 E' u7 _) L7 Qelse if(FLAG_TT==1)9 F6 x# t/ ]8 j$ [
{
- p3 S) N' O! m2 j8 a( B- ^0 \x=0,y=0;' N! ^/ g6 k0 b9 c2 z
for(i=0; i<num; i++)
1 B5 u* M+ K9 p# ]4 n{5 `( D ^$ b6 ]( X# |& F: E7 {1 ~9 M
t = (float)info[0];) l( u' _; E' [' b! U, n/ s3 s) a
temp = (t/101)*180;9 h, n* K0 ]& C) M' M- B! |6 q0 Q7 |
pos[0][0] = (10-num+i)*50+x+650;
; Q" G! e& K/ m$ h% dpos[0][1] = y+210-(int)temp;
1 Q2 v5 I# a. ~# It = (float)info[1];
4 f! |6 h0 n4 \ B rtemp = (t/101)*180;, n' y5 r# L a7 m2 G
pos[1][0] = (10-num+i)*50+x+650;
* h* P) D! n+ Z4 r+ i! R, @pos[1][1] = y+420-(int)temp;
. y, ]* y& I# T8 et = (float)info[2];7 T. H! K+ o- v% C e- {; \; X! @/ v
temp = (float)(t/101)*180;/ r5 c \6 c& r3 o, y2 z7 X! _
pos[2][0] = (10-num+i)*50+x+650;
+ T5 l! ?5 O# y; F) U/ E1 Ipos[2][1] = y+630-(int)temp;
7 E' V O" D0 Z8 z}4 q* x% O- J6 Z) z& t' ]& @* T2 c" d8 ]
clearrectangle(x,y,x+1200,y+650);
& Q& [) B4 s% a& Osettextstyle(40, 20, _T("楷体"));+ s, S: r2 g t* N- L# J
outtextxy(x+50,y+50,"TT");6 H0 E) U0 t5 d
outtextxy(x+280,y+20,"CPU"); //画柱状图# o' O2 R2 d/ D8 G" O
outtextxy(x+285,y+20+200,"IO");
) Y _- e8 g9 n6 Q% W n" mouttextxy(x+250,y+20+400,"change");# `$ O8 ^. s% r; t. ?; Q
rectangle(x+270,y+65,x+330,y+215);
+ S/ X3 @. Z0 W1 H; H+ Q% Erectangle(x+270,y+265,x+330,y+415);
. m% {1 g! L7 ]" O" \3 ] orectangle(x+270,y+465,x+330,y+615);% i7 V: F9 ^5 Q6 @
outtextxy(x+290,y+620,"TT");
4 P) ^0 @) V- z4 V% Y5 |t = (float)com;
% F: M P% S; ]& {) \2 \temp=(t/101)*150;
0 K5 s8 ^& v+ L1 {; _6 {fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
2 ?$ h+ s# t u% @t = (float)wai;
' q* p: L: M6 `3 L& P" m7 ztemp=(t/101)*150;2 x. G+ ?$ s; ^8 Z5 s7 L5 g! P" H" o
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
" ]$ \+ [9 j2 Z, _" c, Wt = (float)cha;1 R, l8 ~) ~ }
temp=(t/101)*150;
' [1 _! u; J, R+ L. j5 Ifillrectangle(x+270,y+615-(int)temp,x+330,y+615);) ^: Y9 H7 P6 _5 B* x- V4 S! P) D' g3 ]% Q. P
for(i=0; i<3; i++) //画坐标 high=90,length=2508 w( C& g; _5 I$ ]' ~' K2 r7 O g
{' L& J( D% t" P* N1 \: Q" q
line(x+650,y+210+210*i,x+1150,y+210+210*i);
$ Z/ I2 ]8 h' A# \2 y9 R& r& Lline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);# D) A( g; L. q2 l% o* C) E) `
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);* n- U' T+ E* o4 A. @0 A4 \! s
4 p. t7 l* j% ]* |$ G
line(x+650,y+210+210*i,x+650,y+20+210*i);) F" J8 { {6 r) d
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);! J; v) ~5 b% u8 i$ A- G0 c* t* z
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);, d M! o6 d! Q7 b
for(j=0;j<num-1;j++)6 m. @/ F1 N& Y7 @9 S
{
4 k. N* ] z o- hline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
: F. N8 }1 t/ L+ ^: N, p( Nline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
" l/ n: ^( G2 ^ ]2 Oline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 7 R9 Z* W: `5 I" v/ Q; @- q6 I
}6 K8 a. T6 p3 K+ p% Z% s% x! ^3 M
}, L1 R- Q7 ?9 o5 f6 q! A
}* j/ {: F- u ~, q i6 B
8 D+ m9 v, f8 |! }$ ]! v
( C+ h% Q( l; ?7 y' K1 Kreturn 0;
! ^- N, R5 U( m, E! D! Z& R9 T}
' ?5 y8 D9 n0 ?1 hint drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)
2 X# w' m( w9 i3 L f4 y{
# z6 T9 `6 I4 O; }* e o& kstatic int info[11][3],num=0;' S/ G- d8 h: e% z1 w, n0 |
int i=0,j=0,pos[10][3][2];
1 {7 C% Q* V' w- l+ l+ c+ vfloat temp,t;& Q, e6 Q# D2 \+ F f, o$ `2 x2 w! Z
info[num][0] = com;
, n/ M( T' I5 c' [% Yinfo[num][1] = wai;
8 x8 Z0 G b" _. Xinfo[num++][2] = cha;6 r* y6 K4 G+ y( t7 g/ F6 K9 ^/ A& ]9 M
if(num>10) //存储10个点
, z2 V2 u8 z$ A$ {& P2 I7 l( A3 k{# t$ m" j9 n: I; _, u; v
for(i=0 ;i<10;i++)( R; X: Y, L! A ~+ ^& K
{& u6 \# |: ] a& ~
info[0] = info[i+1][0];
( Q# F, n" m8 V: d) y4 Hinfo[1] = info[i+1][1];
+ M& b5 E F; k9 r Linfo[2] = info[i+1][2];
9 ^! l8 T9 b- I% x ^}
5 v: I4 c- p7 |2 C7 f7 D& Xnum--;- ~) ]$ U1 h4 t
}
z9 ^4 P7 V. b2 J b- `if(FLAG_show==0)
6 W! W! o& A5 e: T& c: O- b/ K: Mreturn 0;
5 G1 ^* r; Z2 Rfor(i=0; i<num; i++)
, g* y9 r( H" y" H3 b9 F{" l; n9 Q) ^1 S; e! J
t = (float)info[0];: H5 x7 y$ D: F5 N7 z* l% z) l* [
temp = (t/101)*90;& b) u; o0 q4 ]9 J
pos[0][0] = (10-num+i)*25+x+100;
7 P3 t- k8 X3 E/ g0 c* I) Lpos[0][1] = y+110-(int)temp;
: I% j) S* T0 l6 Vt = (float)info[1];
P8 \0 Y8 Z5 u9 F( F4 Q, w- `temp = (t/101)*90;: u+ {" E6 F7 w
pos[1][0] = (10-num+i)*25+x+100;
( K5 Z: d! y8 ipos[1][1] = y+210-(int)temp;
$ g- e: B$ j! ^) b! ot = (float)info[2];, \4 {2 A8 f) \6 y4 @! m8 [$ n
temp = (float)(t/101)*90;
/ W% A. ~" \: Z/ q) A0 T/ Upos[2][0] = (10-num+i)*25+x+100;, b2 U ^ y% }$ ^
pos[2][1] = y+310-(int)temp;8 y9 j7 H* l4 i. l. S
}) t+ K# t$ r% T& X% E. N
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
1 J* z8 C0 B3 X8 k* X/ { \{# e# L; P' R4 u8 @4 K4 Q
clearrectangle(x,y,x+400,y+315);& _2 C. j* u' f r
settextstyle(20, 10, _T("楷体"));
0 y6 r2 e1 V/ ]' _rectangle(x,y,x+400,y+325);
; U9 t% |! Y" E+ p y: z' {2 eouttextxy(x+40,y+10,"CPU"); //画柱状图
! V' Z _5 u) c9 P) t4 D" }; ]$ g$ W) }outtextxy(x+45,y+10+100,"IO");3 Y v" O1 _ v" T5 X: Y5 f
outtextxy(x+40-15,y+10+200,"change");4 t! p& K: D. a# K( D
rectangle(x+35,y+30,x+75,y+110);
2 l5 {$ D- [$ V$ y1 grectangle(x+35,y+130,x+75,y+210);6 \' H# z+ I7 j+ S
rectangle(x+35,y+230,x+75,y+310);
, W9 B5 w# b/ p0 S& W; c6 ?2 zouttextxy(x+180,y+310,"PF");
0 l# S: d$ y' |2 e0 }3 Pt = (float)com;
% ^6 S- ~" X+ x* p& B0 x' I9 Wtemp=(t/101)*80;
- W' `3 Y' k9 r5 v& ?5 X/ m# i: bfillrectangle(x+35,y+110-(int)temp,x+75,y+110);* H: [5 a$ T( u, P, D
t = (float)wai;
7 y' T k3 y% `( ]0 @% {: qtemp=(t/101)*80;
3 |0 _8 F" \% n5 H8 u. C$ ofillrectangle(x+35,y+210-(int)temp,x+75,y+210);
: \3 P. ^8 ?# N: r% w: @7 U r+ f Gt = (float)cha;
7 X; M4 c* q7 q! ~temp=(t/101)*80;
C8 F( y0 U8 r3 q$ [; Z+ y) Hfillrectangle(x+35,y+310-(int)temp,x+75,y+310);
7 j, ?: h7 q5 ^# ofor(i=0; i<3; i++) //画坐标 high=90,length=250; R, _5 x3 p/ D- x2 C6 g
{- A/ i& }3 r' H# \, O3 n. t+ ~
line(x+100,y+110+100*i,x+350,y+110+100*i);
! q0 a* p9 d# Iline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
( t1 `% n# ^* G( O/ dline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
8 c" j. N7 t' K' W
5 p! Y) V, y2 V) C9 s+ Jline(x+100,y+110+100*i,x+100,y+20+100*i);8 J* z4 I! s. |7 o! f' N2 e4 z
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
, o5 z2 ^, y( G/ m& v/ u W* x: \line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);( C* [6 ^( C6 _6 m& b
for(j=0;j<num-1;j++)
- a0 T5 L8 R/ }/ S1 `, ^# N. |{
2 H, k( ^( _& r! |1 I! @8 h0 a: `, Gline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
! F5 F, v/ }; bline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);; ~' V. O( K) N# M% Y9 F6 B
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); " N/ J8 `7 z- n: I
}
! _/ q: n$ W) Q! l* P) W}
- s. ]+ S3 s- z4 @5 K( L}4 K8 u8 [" y! N& f8 W( {6 M
else if(FLAG_PF==1)
2 {: l- ^ {$ C{0 Z! ]" z# ^8 a6 U) `( h* Z
x=0,y=0;& i9 ^6 I& |( c Q2 T
for(i=0; i<num; i++)
" k& r" N4 C& t9 k5 D, c* ^; i+ q{: o* D5 V( z9 W7 ?% |$ O4 e7 w; W
t = (float)info[0]; i6 E$ Z/ W: I$ h! D& z
temp = (t/101)*180;! a, W2 f& @; P i
pos[0][0] = (10-num+i)*50+x+650;
6 ^0 g3 c* @( `* U; _, h: R/ Apos[0][1] = y+210-(int)temp;! b* Y8 l+ U. x
t = (float)info[1];
% r: {% G$ O& W N+ r+ X( C5 Ztemp = (t/101)*180;4 d6 E3 x3 k) r2 V8 B$ F
pos[1][0] = (10-num+i)*50+x+650;
. R5 Q. Y4 X8 @: O5 { x( Cpos[1][1] = y+420-(int)temp; T- _5 S6 z2 v& O
t = (float)info[2];& o1 v) {$ L/ u# [& z2 L' ?& x
temp = (float)(t/101)*180;
6 I8 s3 `+ k1 p {; w1 upos[2][0] = (10-num+i)*50+x+650;
0 |% K# t; b7 W' t8 hpos[2][1] = y+630-(int)temp;
: t1 r# b; l3 K+ d- @, [( s7 A5 X$ w% v}
! Y$ }* @2 p. o! Lclearrectangle(x,y,x+1200,y+650);
6 g8 x" J& g6 Q5 \, @settextstyle(40, 20, _T("楷体"));9 G" _) C! s) L( ~3 U$ M0 D& z
outtextxy(x+50,y+50,"PF"); }; C/ }0 |9 v, I
outtextxy(x+280,y+20,"CPU"); //画柱状图5 R$ x/ C* e$ r
outtextxy(x+285,y+20+200,"IO");
/ o( O' p; r7 a c, F# r' Wouttextxy(x+250,y+20+400,"change");3 m$ Q& |$ n3 a8 [+ s0 K+ L
rectangle(x+270,y+65,x+330,y+215);
9 d+ s4 m2 ^; |6 m8 s9 K( _# wrectangle(x+270,y+265,x+330,y+415);; J/ L! z" v$ G' h1 j
rectangle(x+270,y+465,x+330,y+615);
4 r u+ Q1 }* ?- Louttextxy(x+290,y+620,"TT");) a2 t. C9 a- [- ^
t = (float)com;! s0 @6 _$ u$ ]% R, L3 m# F
temp=(t/101)*150;5 T9 ^5 H6 K8 S/ O
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
6 k6 D4 \' }- Y9 t; }' Wt = (float)wai;
7 Z( \* x8 S0 v" @6 _+ Stemp=(t/101)*150;
# {$ M( g3 e* e6 W, _1 X( t0 U: }6 M3 Tfillrectangle(x+270,y+415-(int)temp,x+330,y+415);* G& [* E/ g; V: F, V- I5 \
t = (float)cha;6 x/ u" s3 L( F6 W
temp=(t/101)*150;! G1 O1 s4 v% a5 Z3 J
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);6 l- a5 R. W% w
for(i=0; i<3; i++) //画坐标 high=90,length=250: U) _+ a/ g# I# B
{
+ |0 m0 @! \9 j$ V/ _line(x+650,y+210+210*i,x+1150,y+210+210*i);
! m5 Y' l7 G% Z# s( j( T1 {1 M& U- ?line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);5 q, p' w) O" `$ b+ p1 ^( U
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);! {8 l" G, R1 @4 @+ N
- y3 }1 l+ C" q; U1 l. ]& xline(x+650,y+210+210*i,x+650,y+20+210*i);
! c1 X4 o2 k% ~, aline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);( x8 p0 L! ], g2 {5 K5 [( T
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
5 J& `* W4 B% t3 o, gfor(j=0;j<num-1;j++)
6 j( Y) K. r. Z" X# x{) A( Z. o7 P( M# y) n( L; u
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
/ q; R" C" e+ j. Y" nline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);7 Q' R, ?* p) [! f5 L
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); / c s' h9 ^! ~9 n
}( e" b9 W) m* h1 b# A7 p6 {" V1 e
}) N# x/ Q1 N* h
}( d. M7 b! s' v$ R
return 0;
& q+ z+ |( S6 b, N w}/ r" \& |6 P6 V/ f
int drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)4 ], g( V( ]" l: c1 b9 R
{
5 J0 }5 F# z1 q: j, |+ H" E' C5 `static int info[11][3],num=0;
9 e/ b: o9 o- x* F5 O2 ~# kint i=0,j=0,pos[10][3][2];1 o" E8 |$ a- m3 E
float temp,t;' Q: S3 ^+ [$ i& l9 B4 B
info[num][0] = com;- H- t" n! }; ]8 P: A4 r6 n
info[num][1] = wai;
- H' s$ d+ b2 k) Z* u/ G0 z" Vinfo[num++][2] = cha;" r' _4 @& \* \, T/ F
if(num>10) //存储10个点
( G% N0 g- Q' h- X{1 m/ z7 B- x4 D$ F
for(i=0 ;i<10;i++): i* _/ i7 y4 z2 g" o& Q
{
& X. U/ I! |+ N# Rinfo[0] = info[i+1][0];
6 \* @) f- \2 ]( ^4 \: xinfo[1] = info[i+1][1];
: x+ [( k+ N5 [- r* t0 S Q" u5 winfo[2] = info[i+1][2];& N/ v1 X# c( X% F! d- i- t3 ^
}+ U% F/ |* K& U$ s: x; o
num--;
) {8 h8 H5 q8 S, ^" O& y( ]. |7 J}
/ H: }# b3 C6 L0 _- U8 `if(FLAG_show==0)
& |* J9 X# n8 p1 M L8 V' ?return 0;$ _3 {# V3 k* }
for(i=0; i<num; i++)/ T! g; g8 J3 G7 w( j1 [- |5 b
{
% q' x1 G$ Z: Y+ L3 {t = (float)info[0];/ E. F* G2 I1 |
temp = (t/101)*90;
7 F" e% N2 I5 ^+ q8 u( P) apos[0][0] = (10-num+i)*25+x+100;) Q& ~' ]. B4 D+ F
pos[0][1] = y+110-(int)temp;
3 Q$ V' D& Y4 }! Mt = (float)info[1];
2 ?8 @& y' h2 k2 h+ u- u1 L% ~% Etemp = (t/101)*90;
& |+ s( J% Q$ f9 B) [pos[1][0] = (10-num+i)*25+x+100;$ D3 e* I0 T0 G8 h4 ]
pos[1][1] = y+210-(int)temp;
! ]; t, h9 Z6 ?" [t = (float)info[2];
+ I7 o) {7 I; [$ |% M/ dtemp = (float)(t/101)*90;
4 }: {( |( P) q( V2 a# |pos[2][0] = (10-num+i)*25+x+100;
6 e7 |3 R/ m, B& F" l: k% epos[2][1] = y+310-(int)temp;! H2 H5 e3 e5 w* H2 _: L; E2 @3 `
}3 E- d# k7 N5 z# U! K1 l
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
% \) n z( {; y h2 r{ 7 j# u# I' o5 ?0 _" q! D- T, f
clearrectangle(x,y,x+400,y+315);: X3 m( H. s9 d, f& T9 Q
settextstyle(20, 10, _T("楷体"));
8 M) U' Q- d% E* ~# Orectangle(x,y,x+400,y+325);/ Z4 k# g1 n( ~1 @- _2 a3 e
outtextxy(x+40,y+10,"CPU"); //画柱状图' E+ a) V5 D7 ?$ K4 [/ h
outtextxy(x+45,y+10+100,"IO");& R7 Y! \& }( _( j, i
outtextxy(x+40-15,y+10+200,"change");4 t2 p# Y; ?! w
rectangle(x+35,y+30,x+75,y+110);' y: `7 n8 s; v; A
rectangle(x+35,y+130,x+75,y+210);
+ H8 \# ]; F1 j8 G* \/ s9 Q2 E' mrectangle(x+35,y+230,x+75,y+310);. |$ a2 \+ w( F. u3 x! o- R5 R0 ?
outtextxy(x+180,y+310,"SJF");7 K6 F& V. W: d8 X" y& `: W
t = (float)com;
0 }" m* x5 r. j2 X$ S3 ztemp=(t/101)*80;
6 _) I& t' A1 o# `& l0 Vfillrectangle(x+35,y+110-(int)temp,x+75,y+110); y; z" H3 J7 i6 G
t = (float)wai;5 z; o; c$ M6 t. k0 A- i
temp=(t/101)*80;7 @' e1 `% M$ L! F1 ?; X* D
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);6 S2 ~. W0 Y/ p* ~, K! l+ D
t = (float)cha;
5 W4 o0 K/ N) K+ |: B+ w7 D7 gtemp=(t/101)*80;5 A4 i+ U3 A$ |2 o* M* F( I6 M
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);* x& h3 ?. S" |1 `- L1 D
for(i=0; i<3; i++) //画坐标 high=90,length=250- s; j0 }# n1 s5 K# G5 R
{1 D' X) p X9 X( {& i
line(x+100,y+110+100*i,x+350,y+110+100*i);
3 f1 d7 Z' p; A& N2 Zline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
( s& J d. h! B, R# G! Tline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
9 e* T K# o( x$ K0 [, i* ?4 N! c$ g+ u2 P r: K
line(x+100,y+110+100*i,x+100,y+20+100*i);1 A! Q4 w4 W1 M
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
: ?0 ` i& ~9 h" M( u; m8 pline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
. x) |: Z* e+ J6 k/ j( f5 w* Ffor(j=0;j<num-1;j++)
1 M5 J. {1 \2 n4 }3 L+ S H{
7 |3 u: P3 M8 K- W. Cline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
7 f# j5 A1 [2 p8 \9 d# d8 qline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);) m: U1 K8 [( F7 l
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); % _% |; K3 @6 V; C+ W
}
X( s& l' I5 ?* ^* ~) x} y; f4 I0 q7 [; m4 Q) r, p$ \/ e
} f. w G c) l' h% @/ |7 [
else if(FLAG_SJF==1)
& A2 D* K* U2 e, c{6 z9 g; g/ S& M/ P9 u( O: t' @
x=0,y=0;
% ?- c* n9 N; {/ z3 v7 {for(i=0; i<num; i++)& I8 |0 ]: s& [
{
. h) _# |. c) O# D5 O/ z) Zt = (float)info[0];
^& W; b, y+ `temp = (t/101)*180;
( p6 u0 d: g, H& Rpos[0][0] = (10-num+i)*50+x+650;
( f% i: a/ o0 O4 Gpos[0][1] = y+210-(int)temp;
$ I2 u% N3 L# w- U; R' i7 Jt = (float)info[1];
, H3 H% n' I+ O( n/ vtemp = (t/101)*180;
" C9 c# q" L1 w8 z4 A: Zpos[1][0] = (10-num+i)*50+x+650;
1 ^ p% s9 q% F X Dpos[1][1] = y+420-(int)temp;: X1 x3 s7 ]. n8 G1 l
t = (float)info[2]; E+ u4 `% Z- U4 [, ]( [' Z( n
temp = (float)(t/101)*180;
% V" B, v6 }' f" S7 h5 d! M* M- Vpos[2][0] = (10-num+i)*50+x+650;0 L6 G" A, N/ Z0 Q: ^7 }6 v; _
pos[2][1] = y+630-(int)temp;/ o5 I8 \3 L K2 j, P/ m
}- j; y: A/ L3 M' G5 b
clearrectangle(x,y,x+1200,y+650);
# y. b$ Y! e: y8 ?settextstyle(40, 20, _T("楷体"));
$ v8 O0 X8 J& S- ] routtextxy(x+50,y+50,"SJF");( [9 E6 N* K/ x: h0 i
outtextxy(x+280,y+20,"CPU"); //画柱状图* i6 i. L9 K( u B `
outtextxy(x+285,y+20+200,"IO");/ L/ K0 U; Z! L& z) F9 j5 m
outtextxy(x+250,y+20+400,"change");
' B" s: o6 @9 T7 rrectangle(x+270,y+65,x+330,y+215);
) b4 l& [& W$ ^7 z: S2 Krectangle(x+270,y+265,x+330,y+415);. W2 H M& ?: I: o" q# ^3 [
rectangle(x+270,y+465,x+330,y+615);, N3 i. B- v7 ]" ^
outtextxy(x+290,y+620,"TT");: m' _" c5 O* b' m
t = (float)com;) _( U! b$ H; |# m' t A; q
temp=(t/101)*150;" Y8 E1 s, {9 u* X' g
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);% ~! W3 N. N) x+ }! l
t = (float)wai;; m* ~( f/ N- r( x
temp=(t/101)*150;
" b y/ `7 b( v8 G' D- g. Pfillrectangle(x+270,y+415-(int)temp,x+330,y+415);
( K$ }8 C; }' `% v* P9 ~; ft = (float)cha;6 c: X, D+ ^& m0 d. E4 ?
temp=(t/101)*150;
4 g$ O; }2 b( _7 w/ d$ G" v5 Vfillrectangle(x+270,y+615-(int)temp,x+330,y+615);
4 g3 L2 M4 e+ E: }/ }+ ~for(i=0; i<3; i++) //画坐标 high=90,length=250; D7 t/ b$ M5 B8 H7 T% p5 w* V, [
{
9 k$ o9 H# e4 J& n/ V2 L, @% xline(x+650,y+210+210*i,x+1150,y+210+210*i);
% A$ f8 u. O0 Hline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
$ J/ F8 B# i# [, Tline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);# o( a% a" ?& `% n; K
6 ]$ L+ \6 J+ U2 J7 W& |line(x+650,y+210+210*i,x+650,y+20+210*i);
$ z0 c! \- [% H4 I% Iline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
9 S& G& D# z& t! Z) T8 G5 P$ Kline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
6 \2 Q. o9 h* Z% C/ J, gfor(j=0;j<num-1;j++)
& v1 g9 Y& i' H7 @0 L2 g{
9 l; q* R4 U: l' @line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
. B* Y5 R, e3 G8 }% x2 J' tline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
) s" x9 p# E+ rline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); * \0 L" ~- `& k4 Y' X2 {' s( {
}
8 _; \: N/ H+ r' P* i% m}5 b" ?+ }1 a. C- d1 I t( b
}
, `) @( _% W4 n# A1 hreturn 0;
+ n0 u- \, o; T) {}$ ?4 x* I- x' F* I
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw): ?, [3 R" i. p& {0 j( w' B
{
9 ?. f0 B. ^" e4 Rstatic int compute=0,waitio=0,change=0;3 T# q. `0 B# a0 \9 n
static int computeLast=0,waitioLast=0,changeLast=0;! ]+ S; q+ \5 N7 G( ?; b% W$ w% T2 V
int i=0;( g# i4 L( e# _% o4 f! {
if(draw==1)
$ @# V* f+ D$ G; a* A7 D' y, w- K{- T+ i* ^' I, E; h; g8 Y; p
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);' z. L) S# H1 C6 q) q" c
drawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);0 P4 K5 v! T% `6 `2 M: N q
computeLast=compute;5 s- k5 A% V# N
waitioLast=waitio;1 ]- K! k- P& J" T' D
changeLast=change;0 e" A5 [8 }0 d5 G# l
}" F9 m U2 Q D, \, a+ _
if((* memory).p[0].flag==ready)6 ~& }. s3 i( V: C: J
(* memory).p[0].flag=computing;
- K; @9 U1 a7 f% H+ h* W2 zif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing): h( ?% n' D$ i: R
{
. f) s$ G6 {/ ei=(*memory).p[0].computeNum;- }0 m, D) H0 ?6 o/ f3 i. X
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
- O8 m# K, v8 H( e{
5 e* G, d9 [3 L; C }" X(*memory).p[0].flag=IO_waiting;- o; S1 J+ G: o# z( [
(*memory).p[0].computeNum--;! f0 l4 K- q" u' J& \! d V! s2 s
change += exchange_IO_Compute;* W0 C. }0 m: U! g _4 B. h# a
compute++;* D4 ^2 {6 ~5 K- d) ^: }/ o: n& F* y
}/ ~+ b" v; L, V0 |( ^
else
4 G; c7 F' B- l. G( a, F( u{2 P4 s \4 F/ C5 U5 N/ u# A
compute++;# {5 p A0 d4 q; o4 i0 a8 X
}4 p" F- J4 d- S, Q$ Y# d- M
}( Y8 ]4 P; q" M8 n
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)- T4 f1 [' C0 p+ @
{
( {; o- ]; [: l# h) _
, |* F# K4 [4 Ti=(*memory).p[0].ioNum;! z' @8 o, H: o0 O0 A
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed: h8 s' r$ v; }' A- z
{' r u4 a0 l4 [" k
(*memory).p[0].flag=computing;
' Y0 d- o) _, E* d(*memory).p[0].ioNum--;: Z+ I2 G1 I1 N) ^6 H
change += exchange_IO_Compute;# P$ C/ V# ^0 V* j
waitio++;. `! |! ^* U& ` Q: T+ m
}. A6 F& [! M( A0 g
else
5 I) h8 P4 k# @ d{
i& d9 T% W" v# J' w+ ~: [% Ewaitio++;
+ {2 H# y" w- ~$ G: f) @}
) Q2 w4 P& B% |6 ^4 _5 Q9 ~8 c# `}
% t8 Y+ O8 l$ u- s( s6 p- }( B& xelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
+ c; ^$ |, s4 b7 t0 E$ Q{
0 c6 _+ i1 `) F) T: I(* memory).p[0].flag=IO_waiting;: H8 g' R: V' O" W
change += exchange_IO_Compute;
+ L/ m' u6 z v; e}
- W9 A* S' |+ G# d! c6 lelse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)% B) u5 g( ^* R% P; e
{( A) P2 G. s& o ^) z
(* memory).p[0].flag=computing;3 @( ]; `/ }5 L' x
change += exchange_IO_Compute;# R8 \& K6 O/ b. B3 w/ I
}8 K& G: i2 W3 ^; I
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
" I' j5 n( `" R$ }% V! _5 w{& c$ k, Y, J% Y. _" i% O
(*save) = (PCI*)malloc(sizeof(PCI));* P( P7 O- g( m5 m* p2 b/ |1 Z
(*save)->next = NULL;
8 [) u/ n( ?' _3 l* A(*save)->processID = (*memory).p[0].processID;
% m! R9 ]3 Z) M5 R(*save)->comeingTime = (*memory).p[0].produceTime;# n. o( Y2 j: z: z# L4 `; _0 }& o
(*save)->askMemory = (*memory).p[0].askMemory;
0 s3 j1 P1 T( Q4 M6 ^4 m/ H- |(*save)->compute = compute;
- V3 t C! E( B(*save)->waitio = waitio;
4 _0 o- I3 ^" c5 v) O" ^- K- B(*save)->exchange = change;. B% i$ l, `- [7 R* a
(*save)->completedTime = systemClock;6 m3 q/ f5 i. m5 H
(*save)->runningTime = (*memory).p[0].runningTime;- p1 o5 J+ a2 y+ I$ ]) @4 I, W
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;
3 l2 u2 _2 F4 G1 ]! M7 @; f% a8 K8 Icompute=waitio=change=0;; d1 j+ e* q$ A5 A% s8 t
computeLast=waitioLast=changeLast=0;: _( ~' ~7 L, ~
High_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);
9 G0 [3 r7 S- b" g! N# k! p: K: ^9 schange += exchange_process;: I1 ~8 G0 P" f: k
return task_completed;2 U o; z0 r( y7 `0 D8 k2 B
}! V* f7 O$ D6 r* n
else
6 U& H$ @& M4 b. [6 Breturn task_not_completed;' J' r% S( }4 Y' Y( F
}. X6 \( i- `% t, l2 d, _8 V
int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)7 z* U. X- H0 h; Q, `8 M: ~
{
9 v7 T# h# W+ o* ^static int waitTime[initProcessNum],i=0,j=0;
( A# j- x& _. _* o+ Nstatic double HR_ratio[initProcessNum];5 v) T/ t6 C+ r
if(flag==0) //初始化数组
8 V/ A2 p0 q$ B: X* r7 n1 g{" @, N8 h$ F0 O+ w
for(i=0; i<initProcessNum; i++)" f0 Z# \5 ^9 d3 P! i5 S
{! E- j/ s8 X" B1 D8 B) [ b
waitTime=0;
" @7 n W0 K0 ]4 Y# m' X4 H8 ]HR_ratio=1;! s+ N( g. k' |7 M( n
}
3 W; r+ E1 m" n; G: `% C}* _2 ^) E! R1 k7 _
for(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比6 y7 m' Y% H& |* M
{' ]* j; `0 Z- o T5 v6 O
waitTime++;/ M9 V& ^% ]2 |% T% ]# Z& n1 h
HR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);
n+ _8 V9 H2 |6 U- o* Hif(HR_ratio > HR_ratio[j])9 L) v: t1 F" r9 ]/ Z# h' y8 ~
j = i;
2 a2 L& `; p7 Q3 g; H+ H3 c. W}6 h: z+ {- {1 l3 L
if(dispatch==1) //需要调度一个进程到内存中执行
* ]2 m4 b: ~7 h0 o1 Y{( \# R: p9 Q, X' |$ c2 q1 w$ X
if((*storage).p[j].askMemory < *spareMemory)& a z& d5 F% L @% a5 ?" c
{& g. e3 f& r, y+ y3 u( j% x
(*memory).p[0].askMemory = (*storage).p[j].askMemory;! z$ q, I# c& ]7 Y# P! i
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
7 b' g# a+ @2 g- @5 ?(*memory).p[0].computeNum = (*storage).p[j].computeNum;
6 D; G p( o0 L3 e T' _(*memory).p[0].ioNum = (*storage).p[j].ioNum;$ Z* m: ]; ?- m& ], |* _
(*memory).p[0].processID = (*storage).p[j].processID;
& _1 A" ?4 O" g(*memory).p[0].flag = (*storage).p[j].flag;
* I5 |6 J/ |2 s# T# F$ }2 ^" ^(*memory).p[0].ioTime = (*storage).p[j].ioTime;! i2 J8 R* r2 q/ H% w* s. }4 K2 `! J
(*memory).p[0].computeTime = (*storage).p[j].computeTime;
; z1 J- j M3 C8 o! [2 v. p(*memory).p[0].runningTime = systemClock;+ N9 Y* i* ~% B
(*memory).p[0].produceTime = (*storage).p[j].produceTime;6 P" h2 H$ [& N; m/ b
for(i=0; i<(*memory).p[0].ioNum; i++) z6 ]( p& F3 w" W, P; C
(*memory).p[0].ioClock = (*storage).p[j].ioClock;3 A% m* y9 ^( w- J& x$ [& x& D7 E$ o
for(i=0; i<(*memory).p[0].computeNum; i++)( W/ x, n8 R& ~* L& h
(*memory).p[0].computeClock = (*storage).p[j].computeClock;0 B: O& D$ G0 e3 w# m- a
(*memory).proNum=1;
& ~# N% Y7 V' i- H*spareMemory = *spareMemory - (*memory).p[j].askMemory;, ^8 h0 ^! m' H! t" s% G' X
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
. {0 h' ~. R. Z(*storage).p[j].produceTime = systemClock;
* ^3 o3 V7 X# s" u: bMAX_COMING_TIME = (*storage).p[j].comeingTime;
: S+ p9 C+ ^! K! R" r* s( ?waitTime[j] = 0;
; Q% J& C* P) s& x2 JHR_ratio[j] = 1;' e; g8 a( s( S
}( e( c" `5 |/ B8 C7 F7 I% Y
else
3 R9 w$ p$ I: z( P: _$ L0 M{
0 g9 Q7 F; a. Y% Z* w9 s. Mprintf("A process ask for a memory overed the system capacity\n ");/ e& r: I6 k! e+ B' a
exit(1);
* a- [+ c+ v* G* v5 v, h5 S}3 } |* h1 c/ J5 }
}8 _ P. J6 M5 ]9 X8 H1 {1 Q6 O
return 0;
/ q Z& k+ w6 B8 f+ U- T- o}0 l) q+ u" O) n6 M
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
4 E& Q/ T" U, u/ M1 d{0 {) @. J! b, Z6 \5 d2 p- `
static int compute=0,waitio=0,change=0;
t- @& u/ R; C; @3 m8 Qstatic int computeLast=0,waitioLast=0,changeLast=0;
6 `0 T+ f$ D: P9 l2 lint i=0;6 g: d. ?9 T8 ~% S6 }, N- V8 M% p4 V9 ?
if(draw==1)
1 r3 ~) l, B* W4 C7 b: p2 y& z{: K( G6 _5 P) n/ ~
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
3 `& ^0 U" a5 v, p: {4 f2 t0 wdrawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
7 o$ |* t" A$ H( {
( }: _, t6 H5 M5 r+ @" d5 E& ]; Q1 ]
2 B/ G, w" D' q/ icomputeLast=compute;5 f! l5 C, |. M. s/ x. ?; ]$ b4 P7 [
waitioLast=waitio;
Z; p: ?+ s) a! bchangeLast=change;# n8 \& D. P+ T" E" k/ [; t
}7 A- T; m, x2 p5 E7 [! b9 `5 r
if((* memory).p[0].flag==ready)
8 t$ m/ }" g: ~8 j; e& w( Y1 |(* memory).p[0].flag=computing;9 y' q+ Q& g3 j$ t9 F
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)& P9 ^9 B+ P* }% I8 d0 k
{# h# f0 _ {2 w6 P+ A5 D! q
i=(*memory).p[0].computeNum;
* @* R$ m) h( @; M( X2 [if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
?* u6 ~5 a$ l6 F. e{
+ j9 ^" |0 s6 Q% j4 w! _(*memory).p[0].flag=IO_waiting;
( U( P4 ~4 h" P$ F(*memory).p[0].computeNum--;6 H9 p+ D6 y! O4 P8 ]+ \
change += exchange_IO_Compute;
2 C$ u6 T. B# V9 i5 r1 ?6 V+ B1 ?$ Icompute++;
# p* d- }* o8 m: x- q1 Y}* I- z% S) I/ w5 {! L, U8 d/ e
else
+ s1 {1 O4 \" A( R{$ n- |0 n ]- ^: U8 p% {
compute++;
% u) L2 S" G9 E& L; V}9 U# U5 e7 B V! t# A
}
5 v' P2 M0 T! Y0 Q; Lelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
* m- T: I9 `+ y8 \2 g{
1 X% ^0 M& O O# l \4 E, r: Y( L# ^& x0 i
i=(*memory).p[0].ioNum;! G& ^4 d5 W$ G5 c$ k
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed4 v5 r# t* x) k
{( j, v& L* y( e7 ~! P: F% g9 P
(*memory).p[0].flag=computing;
t; ~/ X6 K# m' O(*memory).p[0].ioNum--;# q& ?5 ?: \# ~" H, n, t
change += exchange_IO_Compute;
. b% \3 @$ m! ]5 h. z( \" i9 jwaitio++;
9 G4 k) a" i" v' B' O% q}
6 i( d4 r1 M7 j7 O1 Y7 {else8 h8 g9 M( A5 |0 E% M" U, L
{! ^: o, y K! k) X. f0 s7 h
waitio++;
# T# Y4 D; N6 g1 n' S9 A}& ^) t. t! ?" c! |/ {
}
9 i0 I* q4 m# g+ W- T9 {) M, selse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)3 z# a7 C0 \- S8 r5 t
{, p" ?& S' {8 i/ E/ l
(* memory).p[0].flag=IO_waiting;5 m& U3 \0 G/ |/ F9 a! ^
change += exchange_IO_Compute;
0 q! z+ x, ?! T9 d}
+ Q3 \( g0 h2 ~7 yelse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
1 k8 i8 z! l9 C1 E C, k6 x{" S5 k( V8 O/ \" A3 g) [* U5 x, l
(* memory).p[0].flag=computing;
% q0 G& D% n' z2 H+ S/ M5 tchange += exchange_IO_Compute;
4 J& V3 u! a$ c4 c. x}
+ }/ M$ O% k% L- Z: Q! sif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
. s# O& |! x! w: s$ I$ }8 r{5 Y7 Y6 H$ |9 f% M) \
(*save) = (PCI*)malloc(sizeof(PCI));
( Q7 L: A; e* L/ X) v: O/ Y(*save)->next = NULL;
6 e$ k# T* w% e# f x _9 F* m4 l: T(*save)->processID = (*memory).p[0].processID;/ W: b& G$ G5 b& f
(*save)->comeingTime = (*memory).p[0].produceTime;/ e7 c& E( @) `/ i2 Q2 S j
(*save)->askMemory = (*memory).p[0].askMemory;0 O) P( E+ n- z8 x. k, x0 R5 |
(*save)->compute = compute;
: p: {+ }! y4 I' R2 {(*save)->waitio = waitio;
! l- R3 f) m6 T. Z(*save)->exchange = change;0 w, }; r2 N5 U D& _$ T6 {- c
(*save)->completedTime = systemClock;
9 x% s5 D5 N1 O! \; \(*save)->runningTime = (*memory).p[0].runningTime;
& R; L$ d8 U$ K4 C*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;! u5 g: Y! R5 T2 n6 h% |7 _9 t2 J9 J0 L
compute=waitio=change=0;+ e0 J9 ]+ ^4 N
computeLast=waitioLast=changeLast=0;
. Y" v6 @, Z9 ]Priority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));; X4 }( W' }$ K+ P/ Z2 c
change += exchange_process;$ {. T/ r5 u" H9 F4 S8 d4 H
return task_completed;% a, ~0 p' y/ E& ~1 C7 ~( e( c' g
}2 x3 f/ h) a/ ^& ^8 H8 {. }( x
else8 w; H6 ]3 E2 W
return task_not_completed;
# [; a: g; U' \. ]8 x4 \} G8 v. w" P, ~4 Q2 u; U
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
/ [. @3 B$ k F# v* \' K{
) X1 K( B, V! `; C' i# n7 ~' Gint priorityNum[initProcessNum],i=0,j=0;4 S: l/ F/ J1 ^% y2 g# F4 ]+ y
double temp=0;3 M2 @5 u1 D) H9 @) ]9 L2 Q
for(i=0; i<(*storage).proNum; i++) // setting priority to each process" D& e c/ N+ G$ R
{1 h; Q# o0 [5 i! m6 m% `
temp = (*storage).p.computeTime/(*storage).p.ioTime;
3 ?, X/ j& B8 h* O7 r- y1 C% \if(temp > 0.8) |% |' ?+ ]! i; Y6 i/ \0 x4 J& H
priorityNum = 6;
1 `0 U7 p2 z$ \, ^1 Kelse if(temp > 0.7)& a! j: N9 ?" \; p4 S/ u
priorityNum = 5;* W4 i+ h o* \* u: ]
else if(temp > 0.6)
9 J" z$ `! U9 HpriorityNum = 4;
: o i1 u2 \) i5 Y6 J( X* [else if(temp > 0.5)6 L5 \5 p" d3 R w: b! v* ] P
priorityNum = 3;- a, R W5 m" J6 f, T% @
else if(temp > 0.4)
( e, ?7 e" a1 PpriorityNum = 2;
0 ], Z6 L2 `4 P2 S# A: l1 j4 Lelse
' T3 I1 S( U9 z3 K# A/ h. qpriorityNum = 1;
6 F( S: @% A9 h& |( B9 D3 Eif(priorityNum[j] < priorityNum)" I- Q! l5 i* | e G7 c/ I* p% ]
j = i;
. I" K/ q' D/ T! M1 C0 U8 |} R. T# I( B! g' j2 \, h6 R/ D
if((*storage).p[j].askMemory < *spareMemory). h) N5 D- ^9 w, F5 J- p% V
{3 |) I0 q8 i& K' B3 ~
(*memory).p[0].askMemory = (*storage).p[j].askMemory;
# z' f" b! a/ @4 n(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
$ [/ r; d: F. |5 r( o(*memory).p[0].computeNum = (*storage).p[j].computeNum;
" [) x. R! F( @/ w) H(*memory).p[0].ioNum = (*storage).p[j].ioNum; x) o, g2 q3 W) n
(*memory).p[0].processID = (*storage).p[j].processID;
) r( F4 v- u. {1 f3 h(*memory).p[0].flag = (*storage).p[j].flag;, V( G2 E# v/ G% z" V
(*memory).p[0].ioTime = (*storage).p[j].ioTime;/ B3 p+ Q0 P# D6 n+ `
(*memory).p[0].computeTime = (*storage).p[j].computeTime;8 l0 x, E" Y! k) |
(*memory).p[0].runningTime = systemClock;2 `0 G% }1 o' I' ~# x0 S5 {& @
(*memory).p[0].produceTime = (*storage).p[j].produceTime;3 J4 @- Q; G! h2 n* ?( n: f
for(i=0; i<(*memory).p[0].ioNum; i++)
j% L8 u0 Q3 b(*memory).p[0].ioClock = (*storage).p[j].ioClock;
+ @: L$ j B1 J0 Vfor(i=0; i<(*memory).p[0].computeNum; i++)
' S3 r# Z; T. M/ w$ x6 D(*memory).p[0].computeClock = (*storage).p[j].computeClock;. {9 H# D1 M' _( g9 L+ n
(*memory).proNum=1;
5 S( ]: [' v; ^3 i i: r* e ^& b*spareMemory = *spareMemory - (*memory).p[j].askMemory;0 T8 J5 l7 V$ y- [7 e3 D
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
/ |# F$ Y* d, M/ F* L' CMAX_COMING_TIME = (*storage).p[j].comeingTime;
5 G& `5 n/ i# n4 g, {+ a/ ^: X}
& x. D! i* S& C6 Velse7 T0 @- p8 \& O4 n- ^- ?
{
- k4 B0 j$ c0 f1 a6 A6 z. vprintf("A process ask for a memory overed the system capacity\n ");
?; B) D( ^0 Q; t8 Texit(1);) u# M% g' I- V3 W: Y$ L
}& Q$ ~0 A* h8 Z
return 0;. E# K. C1 o! B- g1 p
}" X* t4 F, k/ O d8 M& F+ a! u0 V
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)( j" D0 _! Z: Y7 j Q/ Q* D/ o
{
) S9 S4 k% B1 P$ Kstatic int compute=0,waitio=0,change=0;, p/ q! t/ W0 t" O% Q+ |, M0 ?
static int computeLast=0,waitioLast=0,changeLast=0;, M; x) H3 j0 |0 q1 H, s' ?
int i=0;" p* m5 G- a! G7 T; ?
if(draw==1)1 a) Q% o6 ` Z' C# X
{: [4 L1 {) D& }- \3 t( e
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);4 j; q. w# n" A& [; s% i
drawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast); t, k4 n( I. K5 P
4 x( t$ u' U7 f
# }- B! t" a: S5 I6 v
computeLast=compute;. i9 p/ ?+ v$ u! }' T. C4 [
waitioLast=waitio;0 X4 K, p* T5 [2 r4 E" s
changeLast=change;1 e6 s( d0 ]2 g! e: w
}
' c+ `+ i+ O# W1 [+ p5 vif((* memory).p[0].flag==ready) j' F8 T8 \: S$ Y9 [
(* memory).p[0].flag=computing;" n6 ]/ w3 T* f k4 i
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)8 C* m. a" t- j1 e1 C& F8 ~
{; w3 L$ C* D, ~0 g2 h
i=(*memory).p[0].computeNum;
) e. h7 m% u6 V. c( D1 kif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
! E7 f7 p/ _3 F3 {{
7 g; q; m: _1 i& e(*memory).p[0].flag=IO_waiting;, Z& j6 ]7 T5 ?5 N
(*memory).p[0].computeNum--;$ g; O! M& S& s- Y3 t: T z; |
change += exchange_IO_Compute;; B( F# ~$ j9 z& M, q% f
compute++;' n- R: r0 H7 ^4 l' M
}
# h, N. D$ t4 ~% k: Jelse6 M8 g: P! G, h! S9 R1 W
{
$ D2 K$ m' R6 a6 }# A9 F8 Hcompute++;
% O V: z. @$ M2 l}" W {2 S0 D p* V
}7 v: U7 \ U3 h9 K( Q
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
! [8 o# X2 b8 K, x' A) t0 E, M{! P; C! N0 r1 X$ s; A& a" |6 w
( v3 t2 ^- T& vi=(*memory).p[0].ioNum;
; J, ~ \$ Q: f cif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed: e0 u1 L9 p9 e/ B4 D8 ]
{
$ C5 W1 U/ [" g3 ^4 k(*memory).p[0].flag=computing;
; K% k; ]7 I' V6 }(*memory).p[0].ioNum--;
& [3 H; D3 Y- r: o: L: \change += exchange_IO_Compute;
- @" U. x$ l' \1 p5 T: Owaitio++; Y* k0 L% g' s3 |2 t* V
}
+ z3 c+ p( W; T0 A2 G/ R( Aelse [. @$ F) `; l
{
0 |4 K" r! z3 x- I0 W+ S6 v; @waitio++;4 v1 y6 D: I; V7 S4 F
}
$ Q" ~: o2 E& x2 i' q8 K}
7 r, o0 }0 Q% b& `4 g& {else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)9 m3 _3 q8 w& t4 }- \/ r) ]5 p
{4 y! {) g1 \3 h# f x
(* memory).p[0].flag=IO_waiting;
6 F: _' v( F% ?8 h; R* f3 ?change += exchange_IO_Compute;
* O0 W/ J: `4 o/ A7 d}
+ Y- {" v- v7 r! Celse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
+ T7 y$ z( G/ a4 J. @0 x W{
5 ^* |7 d$ O+ g( C2 |- m(* memory).p[0].flag=computing;
) |- g* [. ~; g( [, n6 Schange += exchange_IO_Compute;
" P0 p* V) N. ?' l}
y" v+ c. A$ Z* N4 H0 cif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
* [' M0 Z( ~5 _) h" B$ C |{3 S2 f6 Q/ V4 _ }' W
(*save) = (PCI*)malloc(sizeof(PCI));! x7 P6 e1 z9 P6 `( L
(*save)->next = NULL;6 _5 O2 w/ M# L0 Q( X
(*save)->processID = (*memory).p[0].processID;
/ w C$ l6 e, o4 M! q(*save)->comeingTime = (*memory).p[0].produceTime;# R$ T+ V1 N, n; Y2 @
(*save)->askMemory = (*memory).p[0].askMemory;
; b- W- z4 u. `+ u1 I# R(*save)->compute = compute;
8 T4 d. i- _9 g# H5 F(*save)->waitio = waitio;
) X# R; V7 \- `(*save)->exchange = change; r; I+ q) x( ~, [1 D Z6 ~
(*save)->completedTime = systemClock;
: z" ?2 |; r0 B! I3 _1 {! S, s(*save)->runningTime = (*memory).p[0].runningTime;
8 `5 L+ L' C% r( j( U5 x*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;# A# y7 U& E0 ]2 k
compute=waitio=change=0;( @! b Y* k l& E4 x( a
computeLast=waitioLast=changeLast=0;) f# y, W n y" c/ U: u
SJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));, P; G! |4 |$ O6 }, a, F
change += exchange_process;4 f% U# i3 [' a
return task_completed;( A( M! c! C+ d- g1 Q- L0 w' G4 R: l3 B
}
8 a9 P: L7 {7 Z: S2 n# L7 p: Pelse
3 x7 F" u: H3 Z: h% x C8 Vreturn task_not_completed;5 A' w7 V; J7 k% q, v& z
}
* {+ Z4 A& }, \int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)6 S1 t, O7 G- z1 M6 Y; V) V
{' F% s1 n. v8 z
int i=0,j=0;' {$ m1 s, ^$ I8 t
for(i=1; i<(*storage).proNum; i++)2 t# y B1 i+ m( ^: l
{
) V- S, _: a# o+ F Z. `# c8 cif(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))! M9 m( B R4 h" S
j=i;7 g+ C0 Q+ G1 t! [" z
}; o* C1 d* Z9 Q* w9 H' U$ j6 [0 s
if((*storage).p[j].askMemory > *spareMemory)+ p) A' w. X v# b
{
3 r* H# Z2 h3 rprintf("The memory asked is overflowed than the system memory.\n");
2 j$ p6 U) |4 K- F6 [) Lexit(0);
7 \7 m' M+ P7 l; K) j+ i4 O: E+ F}0 n2 U- [4 `, l6 @/ q; R4 n7 m6 L/ u, Q
else
2 Z3 l& j4 ]4 Z, R- P, Y# a- T{
Z* w, o: y0 M: O! o+ T6 l A5 Z(*memory).p[0].askMemory = (*storage).p[j].askMemory;9 n' V, l% j0 h1 d+ S
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
3 V' C" X% p6 N9 ?! B9 m(*memory).p[0].computeNum = (*storage).p[j].computeNum;
: K% W* O% ?3 \" c6 E8 q. [- M. p(*memory).p[0].ioNum = (*storage).p[j].ioNum;
+ A) }8 {6 [. J(*memory).p[0].processID = (*storage).p[j].processID;
7 K" v% {- |6 k. B! D" H. V$ g(*memory).p[0].flag = (*storage).p[j].flag;
1 M3 U8 d3 Z" G( i9 E(*memory).p[0].ioTime = (*storage).p[j].ioTime;
( m3 a) k: [: z2 a0 I- o) H(*memory).p[0].computeTime = (*storage).p[j].computeTime;* Z' k" f e% |
(*memory).p[0].runningTime = systemClock;
9 l6 ^( D+ G" N$ ?(*memory).p[0].produceTime = (*storage).p[j].produceTime;
. k! @' l- E2 cfor(i=0; i<(*memory).p[0].ioNum; i++)
* l' d/ ?/ ^8 ?7 `) C3 W(*memory).p[0].ioClock = (*storage).p[j].ioClock;2 \8 K# B6 j, |" e, X
for(i=0; i<(*memory).p[0].computeNum; i++)
) h& R* L6 S l9 [(*memory).p[0].computeClock = (*storage).p[j].computeClock;
, I, p1 U8 u+ S- Q6 U(*memory).proNum=1;( P$ Y, Y7 h( R% P+ ^# S$ l6 k0 j1 j
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
+ O- v5 L9 H& `% m! B% {1 s0 Iproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程/ T! [3 r. l. F# N
MAX_COMING_TIME = (*storage).p[j].comeingTime;
# [% ?0 n& I5 \& v" x! R}% r4 E% I7 ^6 }
return 0;
. m8 V: t+ y, j% D8 g; N}
+ @$ X8 B- a4 }int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw), s. b! A: A' [; B/ T. B+ ^0 S
{
* J4 _/ m7 d% N5 p0 g( ystatic int compute=0,waitio=0,change=0,clockSegment=100,poi=0;
& h! ?9 m. Q+ ~0 t6 Nstatic int computeLast=0,waitioLast=0,changeLast=0;
* X2 E5 ]; X d! D! W8 t* J, gint i=0,j=0,k=0;
1 Y/ z. e1 D4 p [5 y8 P# m6 I7 e$ dif((*memory).proNum<=0)( Y4 w& U- y7 L
TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);: m3 J% F* J, D
if(draw==1)
; B0 P! ?5 f: i. L; c+ k: ~3 T; \{. F- b/ i3 j, O2 z# a2 T1 c2 l0 Q% j
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
5 ]0 ?- p% e+ e9 _: g" v8 cdrawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
7 p2 r9 F( q2 ]: ]# R* P) w7 w' w% M+ `( H; {5 B8 S
' U7 \# e/ w/ o( n% F: _/ e6 ? u+ TcomputeLast=compute;
& i. F. Y: S& k1 \waitioLast=waitio;& `: o( p) X: h, E8 t; y
changeLast=change;+ q# ]2 R! F9 }* p- _- k1 _/ B5 D
}
/ s& P6 D: V4 y, y }if(poi>=(* memory).proNum)5 M& o8 U+ O- }- `8 h" V9 V/ x' j
poi = 0;
9 b" h% _5 s8 O3 i$ \if((* memory).p[poi].flag==ready)3 I' y8 T4 j2 R$ Z
(* memory).p[poi].flag=computing;$ w# l" H2 k4 B* \9 Q
if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)
5 L7 c- N# r0 K2 F6 r: W+ O{4 G/ L: `+ g% ~+ o+ G+ n0 C
i=(*memory).p[poi].computeNum;; I3 y8 K4 |4 m0 q! n B" [
if(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed
, q* ~4 O: j. J9 h5 @( r{
; t" f3 B' `/ K& D# r(*memory).p[poi].flag=IO_waiting;
+ C- O* Z& ]& P7 U(*memory).p[poi].computeNum--;' O4 F% y& r k5 t# `; Y9 b# F
change += exchange_IO_Compute;
" W4 {$ F2 k0 s( v& } [compute++;+ j) x9 V2 Q" F% U2 z+ ?8 R: W
}
4 H0 U! v6 q) e* N" x0 A. m/ L2 }else* n3 c R9 R7 K
{: F6 U' d+ f- a) S' I+ m5 x* m( n
compute++;
! S( t9 v `; \" | J}
) A8 q/ d% I0 ?}
; @% H; D3 T) B( p4 melse if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)
3 S. I# h& o8 O8 T; g{! q y$ q. T) q
9 P9 l T* c- c2 o, `8 U3 R
i=(*memory).p[poi].ioNum;$ V, E' }' }5 y% i7 e+ i/ d
if(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
# W5 z1 |8 W' [6 Z1 U{# p+ W* E4 y/ h! c
(*memory).p[poi].flag=computing;8 U( p1 g1 I! b- O) q6 h9 W2 R. v
(*memory).p[poi].ioNum--;7 }1 R8 i9 K/ p/ U1 x
change += exchange_IO_Compute;
. b. V9 P1 W. G" p5 ^waitio++;9 ^" o( ?1 K1 i# v5 R) y' U4 R
}+ N2 s- r% c, H7 w3 s
else
( i$ a2 R* ^7 Z{7 S# ^5 s3 s1 ?+ d5 w, m V9 |1 h
waitio++;
! f7 p3 x1 [# L3 G1 O+ E}. u$ x: Y9 h* M
}
: y8 M T8 i7 Y- G" gelse if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing). R' ] ^( D# q& K. N
{
# v4 x) m. L- F) D(* memory).p[poi].flag=IO_waiting;" [9 j4 _6 P+ w; x8 U4 N
change += exchange_IO_Compute;
% A" @1 N, T4 I% C" }" M5 _# |}5 I- r1 }8 R: }8 l
else if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)
* M2 g; [$ }# g' n3 j{
9 d2 y) S: y6 T0 [(* memory).p[poi].flag=computing;
) z# P# N1 R2 V5 i0 Qchange += exchange_IO_Compute;8 n; J @ j2 V0 _
}
8 t: @4 [5 _) i8 P) Y! W4 @$ E/ y& ffor(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进& |3 J2 K$ n" l
{
+ S7 J$ z: E) I+ D/ @if(i!=poi && (*memory).p.flag==IO_waiting)
# }- O0 q* j" p$ h; i9 W5 g; D7 N{
K) j+ j. ]' s$ d/ g3 b, Dj=(*memory).p.ioNum;9 W& M6 c! o, p4 M1 R
if(j>0)1 c2 _. Z$ o6 M
{0 e% r U9 _+ Z( [
if(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed: W/ W9 U% `! B& m7 G2 e
{5 n r3 a: T/ F( C
(*memory).p.flag=computing;5 C7 Q* X. n6 ?; e
(*memory).p.ioNum--;: j1 {8 t' T5 f# G1 K6 c/ r# x; [
change += exchange_IO_Compute;
J3 s5 a$ w5 m1 f1 t7 ^) ^9 v% l}5 ?' D, w; v, n( I; M8 q! t
}* w; E% b) ~4 V, O3 \. m! v) s
}! U: ?2 [5 }" F9 ^( x) n. f
}8 F5 B: B9 y9 W& p
for(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程$ A0 i/ F1 x$ j1 q
{
+ B0 j/ F8 M& k8 O2 m( \if((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed
. y1 W) X+ h$ }" E+ X ~& d{( {# U0 u: S' `( M4 [
(*save) = (PCI*)malloc(sizeof(PCI));
) o. J3 u" ?9 r1 G, W(*save)->next = NULL;6 N. B. _8 P- @2 z* e2 s
(*save)->processID = (*memory).p.processID;% n8 l9 Q8 w( Z A0 a2 z* m7 W% ~
(*save)->comeingTime = (*memory).p.produceTime;. V3 j' e( F) e5 V" r$ S4 C" R
(*save)->askMemory = (*memory).p.askMemory;
- _+ j4 @' H2 ?& T G7 ?(*save)->compute = compute;
, F( F$ j" M' O2 R' {(*save)->waitio = waitio;
! D" z! H0 n. T+ P; L(*save)->exchange = change;$ T' l2 r8 o8 _. @, \& C5 @* K4 Z
(*save)->completedTime = systemClock-(*save)->comeingTime;' H# I9 c7 ^& p; d9 e
(*save)->runningTime = (*memory).p.runningTime;8 b4 V; x, t% b( u; x5 S/ G
(*save)->completedTime = systemClock;
% K0 w$ m4 l$ }0 \*spareMemory = *spareMemory + (*memory).p.askMemory;) B' z" M1 a' P3 ~8 U* A
compute=waitio=change=0;6 J: s7 O2 \: M% m( D: S& d7 C
computeLast=waitioLast=changeLast=0;5 X1 x( J4 T/ z
if(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入
9 e& y9 j4 j% d6 E: l{5 q# v8 x: ~9 T5 R# L9 j+ V0 g
if(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程- e l% ~( f. k1 ~* J8 @! h
{
9 ?9 T3 T( e% J0 t: g4 }8 Mpoi++;
# o8 T2 k- e6 F2 J, J8 Y9 I( { clockSegment=2000;6 v/ u2 J. u0 u* [
}
5 H6 y1 D" i& ~! O" j- f}
% V2 g% \1 c ^" felse //没有足够内存调入新进程
7 i3 t" H. L5 o! x; }6 E{' ~) r9 b2 g& b: `9 H
if(i < (*memory).proNum-1)" _+ Q& `6 B* K; b2 N6 P+ F: ?4 d3 N
{/ h5 a5 h4 A8 M/ E
for(j=i; j+1<(*memory).proNum; j++)
. C% n$ Y1 z/ H{& Y3 D" ^; k) U9 P M9 ?- v
(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;+ y! }' z# m, P, Q8 Q
(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;
" C& b% H; `) O) X3 \2 |% y(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;/ G- x7 i5 F1 k8 w9 V
(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;1 ?& a1 r& n1 {# T
(*memory).p[j].processID = (*memory).p[j+1].processID;
l9 Z3 n$ h3 E* W; A(*memory).p[j].flag = (*memory).p[j+1].flag;
) i2 {9 M6 |+ t7 c# s(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;9 M* i! A6 A1 [9 [' A4 V
(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;
0 n) |% |0 ?8 @$ I$ a, D9 S' q3 n; {(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;% p! B0 u7 y1 X6 t3 A/ l7 q
(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;! \( n. Q5 o- Q+ U9 ^
(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;
+ [( b- k% B/ h/ V Mfor(k=0; k<(*memory).p[j].computeNum; k++)7 x" J% Q% E8 Z" @7 b
(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];0 }& W3 K! ?% `
for(k=0; k<(*memory).p[j].ioNum; k++)
% m& G8 t) C m( B: v* c1 v) k. M$ N(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];, c, u* B9 x. I, [/ x9 ]
}/ c$ s8 {- K2 @4 S8 \5 S- v
if(i<poi)7 F6 X, d o% o0 V9 u) d. x0 l
poi--;& g/ L. P) k. O5 E% ^ t2 C
else if(i==poi)
( ~! f- k5 h* r+ Z+ k! {1 L5 mclockSegment=2000;4 _) c$ A* L! ?) v3 j. q( M7 V* E
}
# K' v( G+ x7 L- I% s2 j: A- Z. ci--;5 @' @/ B) k" y5 o1 z n) S- s
(*memory).proNum--;
2 w- k* V1 l+ g" q% p}
% H' d' C% q! b, K1 V* ^: ?return task_completed;
1 c% m* D% V# ?3 [}7 ~8 C1 o( l9 N# Y" A0 s. U
}8 @9 f6 m: N9 m, B6 c
--clockSegment;+ Z8 O) c! ~/ \! F* g
if(clockSegment<=0) h" O3 }* y* e1 L- _1 K. T5 I
{
9 e* V! |8 P. ~1 _: ppoi=poi+1;& B; k2 ?9 r9 W% i2 }
if(poi>=(*memory).proNum)
7 `! [5 ]5 ?2 }+ b9 V* q- ]9 dpoi=0;
) E9 [# P) r$ U8 r ^clockSegment=100;) c, U7 o- l; E" d; u/ U
}) q: L( V: o- r+ }, o: i! J
return task_not_completed;
8 V0 O( ~) [, l; o}
0 F6 H! e: s, w [. w5 C/ l: Pint TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)! T2 O0 }' r" E( m* z4 y9 N5 @
{
7 h8 T5 r+ k; [9 k4 wint i=0,j=0,k=0,flag=0,translation=0;
. j* b3 b6 p- Ffor(i=0; i<(*storage).proNum; i++)6 h& J$ ]7 @$ a+ ?
{/ N" S; i, B% g
if((*storage).p.comeingTime>MAX_COMING_TIME): a1 u* O: L! O2 A
MAX_COMING_TIME = (*storage).p.comeingTime;
8 T8 e: x2 S' x1 J}
; A" S- q" j0 c* u+ ?if(pos>=0)
6 p; U+ p5 R) f! K# l" H( Y- ]{
. t3 t& r! b S2 p+ E2 Efor(i=0; i<(*storage).proNum; i++)1 x. e" v% p8 Y
{
" S3 p" [ M$ n9 gif((*storage).p.askMemory <= *spareMemory)
& E4 [$ H* m& k{" B$ d: I: b4 Z$ G% I
j=pos;: _# y/ O4 I; J! |4 o
(*memory).p[j].askMemory = (*storage).p.askMemory;/ \& N% @) d' a8 ~. C
(*memory).p[j].comeingTime = (*storage).p.comeingTime;
: y' ]. ?3 X# h% z( A(*memory).p[j].computeNum = (*storage).p.computeNum;* x% |5 V! m7 U) J- w; \4 j F- v! R
(*memory).p[j].ioNum = (*storage).p.ioNum;# x# _+ w' ` o5 O
(*memory).p[j].processID = (*storage).p.processID;
+ x2 \. E) H. b# E(*memory).p[j].flag = (*storage).p.flag;4 n& }* U& B/ u
(*memory).p[j].ioTime = (*storage).p.ioTime; j5 q& D! g5 o9 h3 _1 o v
(*memory).p[j].computeTime = (*storage).p.computeTime;' Q0 }" d# l a) ^0 y
(*memory).p[j].runningTime = systemClock;
. G- [5 t5 R; E' A0 x5 Z(*memory).p[j].produceTime = (*storage).p.produceTime;, M, T: B( ~# n% |
for(k=0; k<(*memory).p[j].ioNum; k++); ]7 b Z" P- [' w5 X" u: C
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
4 t# n/ V. T( {* ffor(k=0; k<(*memory).p[j].computeNum; k++)# c6 @4 ^, K* R4 k$ }1 B1 B
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];6 K, ?' m+ p) S- s1 c" u/ {" i
*spareMemory = *spareMemory - (*memory).p[j].askMemory;1 ~+ d! z$ t- M1 I! N8 d8 i1 S0 k
produce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
8 W! y' z8 Q% I3 [. O! I/ J( u, eMAX_COMING_TIME = (*storage).p.comeingTime;
: ^- j9 O. J8 \& E( Z! Rtranslation=1;
1 F5 U9 T, r; f% i6 o) s" V: z4 r: Rbreak;
c$ w# f! N" a+ n' d, {! A}
0 |+ p* a8 E+ n t7 L1 N, ~) I( z}
; e8 _4 c" E. g# J" A! e! C}1 \# s- O, k- }- e* Z6 o4 L5 c
else
: H# g, X: N" U6 }8 l: |{
( }( k8 }0 s+ C& B1 _' ?! ]while(1)
/ A; A8 t4 H3 R: J{
i, z/ x, i. v) H4 d4 b; _# Sflag=0;
0 Q/ d+ h8 o4 r3 j/ b% Z. x/ Cfor(i=0; i<(*storage).proNum; i++)
7 p4 p( Q4 p O$ \# w6 \$ ?{
9 h6 R! K, W$ V* J" Y( U8 T( fif((*storage).p.askMemory <= *spareMemory)
! |* e6 I# Z/ y. d0 w{8 w; o4 b3 E- Y( G( m8 M; Y$ F
j=(*memory).proNum;0 n2 Z: _ M6 U9 Y& s
(*memory).p[j].askMemory = (*storage).p.askMemory;
9 c4 n, }. j2 B2 t- e$ f! B(*memory).p[j].comeingTime = (*storage).p.comeingTime;$ O) d0 r9 M, D; V- d
(*memory).p[j].computeNum = (*storage).p.computeNum;
/ S2 {- s V1 G. a7 y; |(*memory).p[j].ioNum = (*storage).p.ioNum;
* O, S% G, }- J: O(*memory).p[j].processID = (*storage).p.processID;
4 Z. @. r3 Z+ f+ L5 {& S [$ o(*memory).p[j].flag = (*storage).p.flag;
# ^0 e) d# F3 L. |(*memory).p[j].ioTime = (*storage).p.ioTime;0 L/ _9 u7 y" [( q
(*memory).p[j].computeTime = (*storage).p.computeTime;
- {2 x! \; o4 o- I) }6 ?; N) J- y(*memory).p[j].runningTime = systemClock;% I: s2 T3 F5 U2 Q/ o/ c
(*memory).p[j].produceTime = (*storage).p.produceTime;
8 o& V$ J7 w- z- j9 Ufor(k=0; k<(*memory).p[j].ioNum; k++)
" s; f8 @8 G3 G& B1 L& v- v, j(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
* H+ w" m8 u$ }! Xfor(k=0; k<(*memory).p[j].computeNum; k++)
' G; r9 n( ?1 k(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];1 Q$ }: p9 r% I. ~% } H- H( V
(*memory).proNum++;5 Y$ L' s5 F+ H: Z2 m5 T7 f
*spareMemory = *spareMemory - (*memory).p[j].askMemory;) ?0 N* r! h) f Q. y. O" j
produce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程/ ^, A! P$ |. [. X2 W5 M
MAX_COMING_TIME = (*storage).p.comeingTime;
! t3 h8 u) M: d: k* u' w! P+ N* c7 Lflag=1;
* O; L' E/ j* m" t- Ktranslation=1;
9 j; V5 x. k j+ s4 b' W1 w4 V' [& d}
8 K9 }/ i+ [) p$ o7 U}
1 D8 d; [9 f1 xif(flag == 0)$ y! J4 ]: R) Y& f) l. _
break;
1 I) _0 s& N' Z7 C}
! T" r; N8 Z; I* Z}4 [2 q. J& B& B$ J
return translation;% N/ r8 G' V$ \
}
) R, }+ ^5 c+ |4 g" j7 Fint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)9 ~+ s, F4 m, [2 r
{
: P% q7 z u7 U0 @5 gstatic int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;7 P" ?0 r! c& ~6 P; t7 X$ W
static int computeLast=0,waitioLast=0,changeLast=0;( J$ P% f& F% o
int i=0;9 g- t$ a( w* L
if(draw==1)0 s% D A# r6 q2 n) I( L, D
{* ^( N1 {0 ~- S
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
5 F1 x I1 b7 j( X7 ] d! f }drawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);- a% _$ v* _0 b* G/ S* Y
+ d( u& r1 X' }& M- S5 P6 Y, F$ {2 L; Q7 v; {: c
computeLast=compute;* f" F# T. s) @% P. G8 V4 Z
waitioLast=waitio;5 v# {$ Q9 K! l5 ?5 z O
changeLast=change;
0 f! n% q j7 f: v/ E5 ?. _}) w* l! y+ |1 f# l. c
if(flag==1)
+ E0 a8 ^) T* q! a/ ] R, z5 m- C{
% n, c8 F" Z( ^2 t& Pif((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed
8 D. b& g$ V: H- Y3 Z( R/ q{' I8 E- r5 E, p7 I" x
if(flagiocpt==0) // implement compute
$ g0 L+ ~3 @$ E! G' x. g+ d/ |{7 O( F( V4 N- s6 S! Q0 T
i=(*memory).p[0].computeNum;
1 F$ P+ y0 U) r* r7 jif(i>0 && (*memory).p[0].computeClock[i-1]>0)
, P" n; _% k. F{3 c5 h8 q6 S, I o4 I& ~, g
if(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed& } y5 l1 @4 ~/ D: O3 r6 n
{0 Q2 d7 ^2 g9 q
flagiocpt = 1;
+ k( v6 L* H! Z, o, V(*memory).p[0].computeNum--;4 t) t' c1 k8 F2 Z
change += exchange_IO_Compute;
1 W: @ m( {3 fcompute++; x# m8 N% f6 E' B- ~- r4 o
}
$ G v/ [$ ?! X4 g% ielse6 h2 |; h: p9 B8 j
compute++;
9 x5 V3 Z/ ^: U1 [8 M/ J# v) s: p2 L. n
}7 `) M, [: C3 J
else
7 C9 ]6 F3 p! D: D1 [0 U7 ^) Y! eflagiocpt = 1; c: w+ i3 N2 s0 @4 p/ d
}
6 y# a C8 I9 j7 {# Q# E" celse //wait io
) l `: N4 r2 \, c" d{
% d1 L2 I& b; Z8 T' v: li=(*memory).p[0].ioNum;- _. f; V7 m. R! @! M2 v
if(i>0 && (*memory).p[0].ioClock[i-1]>0)( j/ _$ q1 r {/ u# ^
{
4 a1 g* ~( O Yif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
5 w( h) D# q; Z# [, d0 y. `{! h+ r/ k7 b) b4 _9 e
flagiocpt = 0;
* H. [, A2 t& I( Z(*memory).p[0].ioNum--;
; _- ]7 L& Z/ wchange += exchange_IO_Compute;' X N5 ~. |) @7 e1 W
waitio++;! e( b- x( \) O0 a$ ^
}. U0 S4 [* z8 V0 ~$ J
else
+ ?0 {5 W* u6 r( v" }waitio++;6 p$ L. V# t5 U/ }2 R
$ U) s( T8 o0 ]! M- ?+ V$ M6 F
}
/ V" ?& q( f" z& V2 P8 relse
% G" e# o& l4 O0 ?* Z( Eflagiocpt = 0;
7 C0 R J x8 Z. n7 j}+ I$ u& m b" w
}
) |/ |0 c4 B: t9 l8 B. ?& `$ F. O# zelse //task is completed
- Q0 q |3 X! e/ m* {7 D{
) F, _) l3 R) f0 f# E, o(*save) = (PCI*)malloc(sizeof(PCI));
) o6 h; H9 O0 K* W; A% U(*save)->next = NULL;
: L* c% u$ w' ` (*save)->processID = (*memory).p[0].processID;
" }- B# h; B2 G) ^8 H(*save)->comeingTime = (*memory).p[0].produceTime;
1 M1 g& V P5 G b! v(*save)->askMemory = (*memory).p[0].askMemory;4 [7 z! y# W/ l, P7 d
(*save)->compute = compute;
: |# M$ A+ f5 Q# t$ U5 E+ r' _(*save)->waitio = waitio;
, ^8 ?0 a- V* |$ r- I4 s(*save)->exchange = change;
g- K4 b+ p$ n( L! t2 d4 ^(*save)->completedTime = systemClock-(*save)->comeingTime;
( I3 |+ Y, Y4 j2 q(*save)->runningTime = (*memory).p[0].runningTime;3 L7 \' f8 `' u# P( ^# K7 |7 v
(*save)->completedTime = systemClock;7 j/ p7 r8 y( P7 k* p; X
//*spareMemory = MAX_MEMORY;- p% z" W' y# _. a
free((*memory).p[0].ioClock); e' C& i3 [" P2 u
free((*memory).p[0].computeClock);
$ T0 o+ B* ~+ jfree((*memory).p);- ~! V& `3 ~) I. Q* X4 F. W @
flag=0;5 M" q7 ?$ @9 x7 r' e# u- h7 a
compute=waitio=change=0;
- f% i) b6 s6 r: S) GcomputeLast=waitioLast=changeLast=0;
4 ^# d0 I" P* R; f! @& E! j3 S# Dreturn task_completed;
$ k' i [$ P' F5 h: m% `# Q( V}
. ? N# w8 w5 X+ X- g}( I6 d# N+ s7 T$ A, i% D) T
else
* l$ M2 x% _. x! i{9 n7 q' m% O5 a0 j
FIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));/ c1 G9 t9 q* r: P7 e6 ?& ?
change += exchange_process;( M: f( ~+ j2 Z. b% B1 n
//*spareMemory -= (*memory).p[0].askMemory;+ J& n+ e5 b) v/ L
flag=1;
( @# v/ o/ F' s//showProcessInf(*memory);
+ v, l/ j9 ]; Mreturn task_not_completed;
7 [7 `' _0 Y9 q9 c+ U/ e}5 w. {' g$ Z J8 k+ a3 r
return task_not_completed;
; ?; i2 n! T% C2 P}7 K2 {" y! O* R9 W3 ~
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)+ r. K( a; }* n& m
{
5 h7 J6 y% B: }int i=0,j=0,k=0;; u- e0 B2 s) O9 j
MAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;6 Y. I% s+ w H8 @4 g1 t
(*memory).p = (process*)malloc(initProcessNum*sizeof(process));$ ~) f k# n2 n
memory->proNum = 1;
' Z& |" ?0 l5 ~& G9 A* T4 F, Gfor(i=0; i<initProcessNum; i++)
3 A6 Y' F. }$ C5 \+ _8 U0 r6 r{
8 c& K7 @ Y0 Yif((*storage).p.askMemory <= *spareMemory)
M$ j; b- Y0 Q6 [) d. o{
4 [2 o4 Z, l& Z4 G6 R0 p" ^- a(*memory).p[0].askMemory = (*storage).p.askMemory;
& ^, g* n$ g' I0 _0 R! @(*memory).p[0].comeingTime = (*storage).p.comeingTime;( ?; p& |5 B2 d% Y# u3 h
(*memory).p[0].computeNum = (*storage).p.computeNum;7 E9 r8 M9 K& l% M
(*memory).p[0].ioNum = (*storage).p.ioNum;4 S1 p$ z) W5 u2 N- C
(*memory).p[0].processID = (*storage).p.processID;- D# S* L; O# W$ p
(*memory).p[0].flag = (*storage).p.flag;. @3 R& L7 Q! N8 ^
(*memory).p[0].ioTime = (*storage).p.ioTime;' Y5 |* J' @$ o" o' n @" p
(*memory).p[0].computeTime = (*storage).p.computeTime;2 }2 `) y) F: l' X
(*memory).p[0].produceTime = (*storage).p.produceTime;
# d9 c# N- @/ G(*memory).p[0].runningTime = systemClock;
' @( r$ Q. a0 t: h7 |9 a3 N(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));3 R8 q# H& f: H6 Q4 P6 e3 i
(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));
; I* R) U4 w/ h5 h Xfor(k=0; k<(*memory).p[0].ioNum; k++)
( s7 F, N t+ Q, @, Y6 A n. G(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];6 R2 x# @. o& p# \$ F
for(k=0; k<(*memory).p[0].computeNum; k++)
r% z( y% ?$ Z# Z, Q(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];6 M! o$ l/ s, Q: s \
break;
5 ~, G3 b6 o2 B}
( @& Q* w+ o8 \! S6 t/ ^$ e' U}
$ j$ j3 W; e5 F, `if(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入
5 G# u5 D$ [' D* H{
& u1 }* ^; K0 j% N+ x2 Uproduce_one_task(storage,i,ID_FIFO++);
. v8 p) ?9 i1 h4 r2 TMAX_COMING_TIME = (*storage).p.comeingTime;
! @& ^' y! u1 Y$ @ }4 y6 Qsort_by_comingtime(storage,i);( k* h+ u& K5 p
}
1 e0 C7 m' ~+ H' q3 N: j: Z5 ereturn 0;
# I8 h, R- S9 Q9 B; m+ {( c6 x}, |9 ]( w# v/ b$ o- L& z. a
int sort_by_comingtime(processPool * p,int pos)& `" {- F: j0 z4 }( t
{; J' H- n9 o; b+ I* [, ?
int i=0,j=0;0 P3 x0 N1 \, ?) C) e9 {$ z# ]
process temp;1 X% K; m y9 @
if(pos<0)
' K8 x2 a" _/ W! O/ {% Z{
, V* b. E# c8 l+ b: q7 E' B& Afor(i=0; i<initProcessNum; i++)3 d c" ]- u" w$ `% Y1 X* i
for(j=0; j+1<initProcessNum-i; j++)
; @- ]0 g) q; w5 E+ a* k{7 w w p$ X5 T2 Y) |/ p
if((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)
! ^; `: ]: c% ]" v3 ^2 H, c{
8 X: {' O: O! s6 \' z7 \4 m$ Wtemp = (*p).p[j];* n/ C" n* v' O5 k- K: ~- r0 m
(*p).p[j] = (*p).p[j+1];5 B ^7 S' n# j2 X6 y& S
(*p).p[j+1] = temp;
% s1 p- E" |+ X: \& H' `2 X}) \! B5 E6 f: S( X. ^! _2 Q2 }' k
}4 X" ^9 s: t' x S% D3 c
}9 N7 ]$ X7 l! j9 I9 M; w4 Z
else if(pos<initProcessNum)5 {$ j Y7 H% S5 N
{1 ]- b9 W0 a- M
for(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)
; h! p2 u, ~7 K/ f- Z0 C* G ?{
4 Q# V2 T; V* _8 v$ U5 stemp = (*p).p;1 l" ?1 A1 L3 t$ Z
(*p).p = (*p).p[i+1];2 v/ Z+ f* F& q* c( H% W0 T
(*p).p[i+1] = temp;$ U; e7 B3 n G$ R5 S ?
}
$ J& `" l B: R6 O- @for(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)
: @+ M2 U: m3 ~2 _* l& N{
+ N/ r! M' }0 r3 S: b8 ytemp = (*p).p[i-1];
3 u0 x) ?: |: J7 r- R2 X% r(*p).p[i-1] = (*p).p;& K: X7 `; K, S- M3 E3 |; e
(*p).p = temp;7 Q( r: Q$ \6 O* u/ V
}. `6 J1 I+ {$ t! C/ w; g
}
* `2 M8 U4 m# s1 O0 E$ ]" ^else
( U; q! e o6 h( tprintf("position eror\n");
. k3 U) ?8 ~% Z- v/ Mreturn 0;
7 S7 u! J$ W9 G2 J L3 x' Z}
* H( M. j1 F' i5 [& q$ {int InitPool(processPool * p)
1 p2 F% R* G8 n{8 `; J6 c8 M, [( [5 j3 I* x1 L. Q
int i=0;
6 C- d) F) b/ F# O(*p).proNum = initProcessNum;
/ T$ l' n0 h# M1 [$ D8 y(*p).p = (process*)malloc(initProcessNum*sizeof(process));, u3 g% I) z. B+ S$ G) V6 d
for(i=0; i<initProcessNum; i++) //init process information) D" k M: Q! B( C, z
{7 p+ b, k( a- m0 x
(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));: u/ f. n. j9 ~( G1 X# j
(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));& w& B) B; P" L. c
produce_one_task(&(*p),i,ID_FIFO++);
R% p9 Y9 X3 H, w, F9 Y}+ q; O; J9 M4 x$ |, @, H e
return 0;
3 o- L8 v+ |7 o; F2 l& e! h# ~7 U}" {! l/ n! A5 {5 ^
int produce_one_task(processPool * p,int i,int id)& u- |/ G7 {8 i( q1 r, h( ?4 `7 H
{
' W2 v) O" L7 {$ s$ H4 hint time=MAX_COMING_TIME,j=0,totallTime=0;8 Z; w8 t! W7 [# D( k9 Q
(*p).p.processID = initProcessID+id; 4 {2 L# f, V d5 s2 m
(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);
$ h5 u$ O" T/ }8 F2 T(*p).p.produceTime = systemClock;
0 m6 n: i) p p, ?0 T(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;3 O4 ^8 O T( h6 `0 i
(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6;
, L, U x0 }# L% j8 StotallTime = (*p).p.computeNum + (*p).p.ioNum;
3 V* c! Q; C% ]5 D) Y( [6 L7 \/ h7 a(*p).p.computeTime=0;
+ O. i4 A3 H) p t! L H6 Kfor(j=0; j<(*p).p.computeNum; j++)
% E4 L4 F6 c, z+ k7 A{
! _5 J: R( i( V(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;- d( s) Y3 k& ?7 P, s; p7 i! R9 m
(*p).p.computeTime += (*p).p.computeClock[j];
9 U8 f$ s5 Q8 R$ a" b; ~' j, D. D}
" O! N3 \! g# o, n# F(*p).p.ioTime=0;% e! s) b) `+ j$ y
for(j=0; j<(*p).p.ioNum; j++)
0 J" G( w7 Z7 J, O3 y) x# ^{
7 t7 p1 u! d0 f* M. N! _6 X(*p).p.ioClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;) x5 N: r8 T( Z6 A# ~7 d' A
(*p).p.ioTime += (*p).p.ioClock[j];
) W; M0 m9 F# f}
. { U s+ o1 ^. k8 m(*p).p.askMemory = rand()%(MAX_MEMORY/4); ^- w. @4 G( R9 ~
(*p).p.flag = ready;9 T2 E2 `! p1 h( j' O
return 0;2 S7 R& a) ]9 |; |5 [+ Y
}
2 C) a* k; s) I( mint showProcessInf(processPool p): Z: z5 u1 v4 x0 ~
{
+ q; ~5 V. s3 ~+ n8 A0 ^int i=0,j=0;$ t. P8 c( v! I; {% R8 H! S
for(i=0;i<p.proNum;i++)
2 S/ ^' I0 f$ g6 `( }0 ^- _9 B{/ r, n7 Q/ u8 S; ]% G6 k
printf("ID:%d,%d,%d,%d,%d,%d,%d\n",p.p.processID,p.p.comeingTime,p.p.ioNum,p.p.computeNum,p.p.ioTime,p.p.computeTime
; A& @6 I# }' k5 }9 M/ a,p.p.askMemory);
5 J. _) L) f# h, H5 T- Cfor(j=0;j<p.p.ioNum;j++)" r9 W! V( p3 w; I( ^0 Z8 c
{
) J; e7 A+ N7 |0 `9 m/ B: {( w5 gprintf("%d ",p.p.ioClock[j]);