数学建模社区-数学中国
标题: 经典任务调度算法的模拟程序 [打印本页]
作者: 杨利霞 时间: 2021-4-9 15:15
标题: 经典任务调度算法的模拟程序
) E4 W8 Z" H. j3 c
经典任务调度算法的模拟程序
5 }4 N$ S7 X3 |4 e( P6 I" b本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。
3 \! l! N/ Y5 `
4 y0 t$ S. r+ |& f# a编程平台:VC6.0+EasyX图形库环境。
9 w$ n: _0 t2 t4 n4 X, q
* `8 r/ M0 A r; m P以下截取部分程序运行图::) v% K* `) m0 w; [
/ ?( y% I. O& K) Y! S8 |( A源代码:! D6 C/ j( k$ x1 I5 B) U
$ P# g& f' d2 O0 O4 S3 v# y
#include<stdio.h>1 v( e$ X& l- n) I1 G
#include<stdlib.h>7 l+ a% G: `! F. _9 C
#include<easyx.h>
( u/ I/ m: K) Z; m/ }0 ~#include<time.h>
5 L4 }5 W) ~3 Y& f8 }#include<conio.h>3 } u6 M A7 N8 f" V
#include<graphics.h>* [; b; u f: O ~! L8 i7 `' @, s0 M
#define initProcessNum 10
4 ^2 K6 {; P @" A2 F#define initProcessID 1000% k9 E2 k& _- u: t0 s
#define MAXProcessRunTime 10000# F( G; C5 a+ ^4 C. [2 t
#define MAX_MEMORY 4000$ e. J1 \, M z; j5 c* o: q
#define exchange_IO_Compute 10
+ M" B" k: C. ^% E3 d' q( U8 g' P#define exchange_process 254 d `/ r- Z+ L8 M( s$ s1 R
#define task_completed 12 O& x" i/ ?9 N* `, s
#define task_not_completed 0
5 i# M/ U! A8 Y* s9 H n1 l#define initclocknum 100% |7 y+ e; Y* _9 j! r
enum condition0 c% X* n; Y# C% `# G
{
( K- J+ p# x3 x, z. `dead,computing,IO_waiting,ready
5 `+ F! g! `( G7 P h};/ K! K! a% } z* E+ S
struct process
$ t- q( V& [! I# f& V{
: \" Z. j, a7 n( E( yint processID;' o. D- ` {: \4 n: i7 P, {
int comeingTime;2 h2 ^/ p/ ^& ~9 ~/ u1 L
int ioNum;
, h, W9 A3 H2 \2 H ]' rint computeNum;9 C/ i+ T% [' c* w7 T2 J* b
int * ioClock;4 L H, [" C/ ^7 y
int * computeClock;
7 Q7 i) _+ _% o8 ^' Q; z2 {; Qint ioTime;
& f9 ^* O0 x6 \! E% B5 @int computeTime;. N( x P8 e$ B2 E% _; R
int askMemory;; {/ Y, b) }* x
condition flag;* o0 N# D* ~/ o: e6 c2 G0 B" n
int produceTime; //生成时间,以下三个数据成员用以计算相关性能) l, k' R* H- J7 O) Q4 @
int runningTime; //第一次占用CPU的时间% R- P( N1 {. u9 a8 t S( c
int completedTime; //进程完成时的时间+ C9 b# T/ i7 a( y2 }
};* O0 v2 q2 |7 {. e; N
typedef struct processCmpletedInfo //保存完成一个作业的相关信息. k; U1 O& g% K$ B
{! o( C% O$ u! g7 F! [# O. G
int processID,comeingTime,askMemory;
% i) w: [: a' h6 \int compute,waitio,exchange,completedTime,runningTime;
) Q* N* ~7 H, ^/ @4 Y9 lprocessCmpletedInfo * next;. i# w K, H6 U5 [8 @1 X
}PCI; N7 v7 {& ?) d8 O/ y1 w+ W" G
struct processPool% h5 o7 e5 P5 r3 N
{# ?5 F+ m; S" _7 t7 ]
process * p;; {/ y! q# O' {4 v$ N) R
int proNum;. X( @, k0 E# L6 q
};
8 B5 s: w5 y; t8 \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;
/ b- l Y3 v8 _5 r* jint InitPool(processPool * p);
' g7 \- e# e+ o3 w7 ]: Vint produce_one_task(processPool * p,int i,int id);
. j/ z7 }1 X0 z4 Gint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);" }* G4 D1 F8 v+ ?: ~# @; V
int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);# i3 P# o5 t; V5 |. Y( g
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);
5 B X" ~6 t4 J& ]" n8 ^int FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
7 \+ e4 k9 Q" W" k- C* |int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);, U6 \6 g7 X5 g- x9 L3 A
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
3 w9 s, A# o/ vint PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);3 ~5 k, B1 ^4 W0 [
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
" N& K2 p0 ]' p' [int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);
f2 G" q1 a/ Z7 ?: O, [+ Dint High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);, H& ^2 ^6 W+ P/ R8 S: O
' r b+ O& d0 l* v
2 \% m( ?( N; N) ?int sort_by_comingtime(processPool * p,int pos);' A: Q- G$ Y8 A8 A4 A
int showProcessInf(processPool p);
2 p# [, b, E9 f# w$ M8 wint drawPerformance_FIFO(int x,int y,int memorry);
' f& a, H* Y7 i) h& lint drawPerformance_HR(int x,int y,int memorry);/ h2 V0 b% X. H2 N& L9 {( @
int drawPerformance_PF(int x,int y,int memorry);
3 ^ W1 Z+ S- i. m, ?8 @- x* k8 xint drawPerformance_TT(int x,int y,int memorry);
! @! k* {6 Q8 ?: o8 ?& Hint drawPerformance_SJF(int x,int y,int memorry);, {/ L$ f* s$ x4 a) I3 O4 c
int MouseListening();
4 f8 o/ g) O8 x" N, K( Vint MouseListening2(int *flagShow,int * showTime);
) ~' i& O6 J* sint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);
9 t7 N# X* S! u% T# K( R# z- j5 o) l8 w2 M+ H
( x# n- C6 t* N9 Yvoid main()! ?3 y$ Q& X1 z9 G3 M' l
{8 v9 O. ?# }1 N/ u9 M
PCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,
" T% R8 ^& {3 a7 p$ o( W2 s*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;
5 q( i2 Q" _6 K1 Q; d' @, K/ [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,
) Q7 b1 u' U% I2 Q0 P1 E# W. {7 F1 yflagDraw=0,showTime=100000;
) d7 v$ Q3 z9 Y1 m- [processPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;1 k7 B: s1 `- h9 w- ]7 _) i
FILE *fp=NULL;# C1 ^, m9 } @6 E, H. g
//processPool HR_p,HR_mmy;: {: Z: K' p3 `+ H% Z' R7 U* ]
5 G% Z8 F+ y, [
! V! S6 G! Z- S. l5 w$ k* L5 Nsrand((unsigned)time(0));
1 ]& o! c9 T2 I6 V# W' T) e, B9 ^systemClock=0;& j% B2 a9 d/ u" H: k1 o( o2 M
initgraph( 1200,650,SHOWCONSOLE );8 s/ Z" g2 E, @# T ~" X$ y
settextcolor(GREEN);3 m- j B# _3 U/ G+ k
setlinecolor(GREEN);
8 D6 l! h' `% [0 f) }setfillcolor(GREEN);
9 {. }5 {+ a# A( D/ MInitPool(&FIFO_p);% y6 t. C* q! O$ D8 a3 D, i
sort_by_comingtime(&FIFO_p,-1);
. L5 k4 }3 b) x' b! U; F7 h# aInitPool(&Timeturn_p);
1 a9 z! _9 r2 m/ i" IInitPool(&SJF_p);
. u [. B) p" x! m& qInitPool(&Priority_p);
- R8 g4 P- R$ ~InitPool(&HR_p);
( y4 G: E" u9 U//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
6 [2 l: \5 D- C; h# U; h5 b//Sleep(10000);- e$ \& ~! s* O2 L) S$ ^! i
$ L5 B, o9 p( q
% L8 `4 w- A5 h4 Z: N1 nTimeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));$ W- z. ?) r( }2 N Z
SJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
. w7 D5 }: q6 z' bPriority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
) ?$ u9 j2 S% E# tHR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));, v7 D/ p' D6 L
for(i=0; i<initProcessNum ;i++)
" t1 f9 A# V r& s{
0 ~; u# b( C' {Timeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));6 n# g2 j% L' Z, s9 }9 p
Timeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));" `# u h0 t+ C: ^ N' F' ^
SJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
% Y7 V5 K+ ]0 a, e$ nSJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
) w4 N5 J$ `% cPriority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));0 e) ]% _% X/ `+ X+ u
Priority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
9 f' c) `! d- F6 m1 G' U4 {HR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
0 q9 |& p( d& u6 _HR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
! ~/ M- G1 R+ Z, Z" P! I$ y}
) N( b' X0 Y3 O7 @ I* ~Timeturn_mmy.proNum = 0;6 {" N* O- y; v$ g
TimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);
]7 O+ n E8 K F |SJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);
6 a4 [( V x1 R& y* A' XPriority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);4 S8 B& d, W! Z& p
High_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);$ R% {) A# T. x
//showProcessInf(Timeturn_mmy);
5 c5 ^& l# y7 x7 Q, dFIFO_pri = &FIFO_save_head;+ m: R$ B+ i% e c2 U) u
Timet_pri = &Timet_save_head;* K1 U5 `( B p% t( e- X
SJF_pri = &SJF_save_head;
2 S) _' I; @/ lPriority_pri = &Priority_save_head;
/ R% W4 T% \ q5 b, k8 N HR_pri = &HR_save_head;, T- n. {: W8 ?5 q7 W
setbkcolor(WHITE);, b8 z( n! V2 U5 O, n
while(1)
: m" Y$ Z" ]5 S: V d' W4 Z{% g% L7 \: V0 `2 ~4 L
if(MouseListening()==1)4 A6 W; }* S5 Z6 B! E
flagDraw=1;
1 E# Z; P0 X8 v {6 _if(count==100)
% I9 y7 k0 @+ t: `{
4 \% A0 K" d- a+ b, @if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)
# y4 W( P7 N& v8 H G# B9 |, o5 a{
- y' L& a0 N+ M: G" kFIFO_pri = &((*FIFO_pri)->next);
' U7 t6 c- V3 R0 a2 |4 v
4 A. I8 \7 |0 \: t" P: c, Q//printf("hello");- g; o; n5 g5 U; T# h* {3 Q1 F
}
% f: v) D8 Y8 f2 o% Hif(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)
& T& X! u3 \$ L, Y/ O1 J{9 h O0 p- v2 U4 Z _# l! H7 T3 V
Timet_pri = &((*Timet_pri)->next);+ h& z3 L1 b( Z/ _3 e9 J
//printf("hello");
/ `( L/ Z7 ~4 Z# U}
4 v p) d& }% c/ M( `if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)
6 v2 m( Z4 U h. |7 a{
0 a7 C5 r' u4 G+ [7 Z! u, uSJF_pri = &((*SJF_pri)->next);
% M+ V5 ] }) d' b/ i5 ^0 D//printf("hello\n");) k) `0 Y1 k% E
}
/ [! M0 t8 x. I- O- F& H* bif(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed)
9 M8 ~' L- I& L. I* r) {{8 T" ] T# Z; U, T5 _ X0 J& ^, V7 `
Priority_pri = &((*Priority_pri)->next);5 u' g& {2 C0 l2 Q8 ?
//printf("hello\n");
$ Y3 v2 S; b M" X& u3 N0 b* g5 f}
, s t( \4 Y9 v# B6 Cif(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)
, R+ f/ y# Z7 W1 T" L{
6 r/ f" F& ~! k% ]+ k% ~2 JHR_pri = &((*HR_pri)->next);
2 j. Z% p2 W4 W' M# ]' ^9 O//printf("hello");
: E* h. J9 P6 S6 |$ }. S+ b9 v/ \}
, B/ v3 y3 @4 j! V$ E/ rcount=0;
& _; Q* _: k! R$ ]. \- D: M. m, E}! A- g2 x; {, q, E3 K: {$ }- P) b
else0 j9 l7 m0 ?, r$ S& D
{
! l; j+ F2 Y! `: s" ?# Pif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)" C5 s7 R7 z8 t
{$ N4 Q! C1 a0 e! L" U" _0 |
FIFO_pri = &((*FIFO_pri)->next);& R/ ]- V1 E6 p; ?5 X
// printf("hello");7 G, Q" k! [- {: k% b5 c( }
}
6 Q) @6 j D5 hif(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)% R% U! T& z# W4 ]1 N! ?+ e
{% O; d+ D0 o3 \3 \8 ~: K1 B
Timet_pri = &((*Timet_pri)->next);" W( z7 `' c! v- j7 _) F& r, U
// printf("hello");4 d. c& G2 m% H+ t' A
}
. d0 r6 r q0 v, N( e1 A# e1 a# pif(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)( k0 p$ N+ h9 y) f# a
{9 E; ]- J2 x3 \2 B$ t/ l
SJF_pri = &((*SJF_pri)->next);
+ ^1 h5 Y) q$ [: r* m+ Z( {// printf("hello\n");4 y# K& h4 _. q. {1 g# c u! S
}. [* a3 M& C D) C; {7 ]- D
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)
# @8 z$ r8 `& }" V+ Y; ~/ z1 E7 O{; {$ B5 G. e$ Q- f
Priority_pri = &((*Priority_pri)->next);
, f u! U3 o& T8 b: i( w//printf("hello\n");
' o. O5 E2 Z9 C3 m}$ s6 G1 p) }( z; ?
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)$ g( t u+ G( W1 T+ C. Z3 V; @
{! F; w) ]& h' C9 p! |
HR_pri = &((*HR_pri)->next);
' N; [( ` x2 y+ v//printf("hello");
* J2 h! a- ~ ~" t0 `( p//Sleep(1000);( ?" w0 T$ x( U/ Q; U7 t8 C; @# V
}
7 ?+ o! U$ K+ Fcount++;
; h4 B& H4 y1 P1 ]}
# P! ]1 E/ ]; J' T2 Q' X2 pif(systemClock==showTime)
4 l P$ l0 S6 K8 o1 e5 [{6 [) H$ ]2 A5 r k2 x) C
/*PCI * p=FIFO_save_head;0 k! _' u+ b3 k* ~
int i=0;
& L! Q. B: T4 T9 G* Ufor( ;p!=NULL;p=p->next)
1 @! Z3 [$ x% v; G8 J{9 f+ g4 w/ U' D8 m
printf("Id %d\n",p->processID);3 f/ K: y* w+ X; Y
printf("comeingtime %d\n",p->comeingTime);
3 u9 }) B6 D8 C0 N F3 t0 ~printf("runningtime %d\n",p->runningTime);
3 u; y1 O4 ^4 I& ]) @2 Uprintf("asdmemory %d\n",p->askMemory);
# P9 m4 e F/ y+ V( Dprintf("completedtime %d\n",p->completedTime);0 ^7 b, g9 v0 P& _
printf("compute %d\n",p->compute);) c6 Z2 u+ X7 z' S% O& K
printf("exchange %d\n",p->exchange);
9 W L6 e+ n: \- G! Aprintf("waitio %d\n",p->waitio);; I8 w* X' h9 Q) g
i++;
- L) k7 L; [" \- G) z* s
% `" ~% W, o1 a, `1 k8 W3 z: K
3 G x' }! U$ l; I}
/ n, s' t9 w1 C% yprintf("%d\n",i);*/- q' B6 o) k( e7 k
if( (fp = fopen( "data.txt", "a" )) == NULL )
, x- O& S0 Y+ `* P{
2 X' r3 g% R) f- p @printf( "The file 'data.txt' was not opened\n" );8 U% i6 ^- m. P9 g
//return 1;
# m! r F: E5 x; N}( V7 j5 }8 A: t
else
% I" T0 R$ |1 q5 G1 D" \1 e" H{" u! M4 ]! H% v& y3 p! n8 J
fprintf(fp,"FCFS \n");: R$ N2 R# }3 f
for(p=FIFO_save_head;p!=NULL;p=p->next)" [3 V$ P2 o# p6 p/ q: ^! `
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,3 V% X R2 j$ E- M1 Z+ _/ i
p->exchange,p->waitio,p->runningTime);, q. l5 ~) P0 F- N2 `, j5 p
fprintf(fp,"\nTime turn \n");3 v1 v) ?* j& S0 t m: c
for(p=Timet_save_head;p!=NULL;p=p->next). E4 K7 K* A* V6 X* c. F2 K+ ?1 e
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,; [+ }- j$ m: h. ?1 j" r
p->exchange,p->waitio,p->runningTime);
/ b5 K' S5 m( i0 z ~6 O5 U% Vfprintf(fp,"\nShort Job First \n");. }7 g9 Z0 K# ~4 C. g: f& ?8 Y$ r
for(p=SJF_save_head;p!=NULL;p=p->next). [; }+ K) T/ Y4 a6 h$ Q* H+ k
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,9 h) J$ t* b2 _* a
p->exchange,p->waitio,p->runningTime);4 J1 J3 [% g2 Z8 G: I; c
fprintf(fp,"\nPriority \n");
9 m8 d/ \, c8 g7 E! {for(p=Priority_save_head;p!=NULL;p=p->next)
0 I% r& i. l2 F4 h6 zfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,# o6 A8 [1 m& }9 b7 r H/ R
p->exchange,p->waitio,p->runningTime);
& _& _" b" D% }4 y, z8 efprintf(fp,"\nHigh response \n");2 a( F3 h/ ]7 A" E3 e* g
for(p=HR_save_head;p!=NULL;p=p->next)- L4 P z% a" y! `3 r) c( C9 q
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,2 `0 `5 @+ v r5 r3 w. s. m
p->exchange,p->waitio,p->runningTime);4 i4 O' V$ b& l( F* y; H0 b1 h
fclose(fp);! K3 M0 H3 B; ?4 N! a) }! }# X
}
9 u" f$ B1 c$ I5 b/ I" L5 [( S% KshowRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);: i* j2 T+ f; F4 S8 W0 f+ K- P' U/ J
MouseListening2(&flagDraw,&showTime);) `0 c: b. I. C! v$ h8 w6 d/ T
}, ?5 X+ ?5 n# S1 |! ~
systemClock++;
* M5 p! Q: P9 O" v- l3 zif(flagDraw==0)
0 K q8 `2 a: W! X5 b1 l1 x+ k4 U Sleep(10);; Y! ^# |! F) H. }$ V
}% r6 ]8 {5 v, a; j7 {+ H
' }+ f c2 w6 O, T3 i/ r, `2 h8 n5 Z6 v) y% M+ v: }
}2 |+ e% r# a7 h
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)
% L' T. p5 q$ F{1 M- i1 B2 |6 L' h! h: ]
PCI * p=NULL,* name[5];
2 I c4 L/ N! l" I6 xint count=0,i=0;
% D' u5 c0 ~8 ychar ch[5][10]={"FCFS","timet","SJF","PR","HR"};
4 Q# m: w3 G+ Vdouble turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};
5 k' I9 `4 d7 J8 k Gstruct info5 k2 g8 b# a) T. C
{
2 d, x3 ]7 z5 X+ ~1 { K2 f) zchar name[10];9 q4 L: V# f9 _) u8 F) ]
double throughput,turnover,wait,CPU_rate;
6 X* v( s. [9 r0 h, I; V* e}inf[5];7 i/ S/ U" m3 h6 C Q9 F) h( ^1 C
name[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;* z L$ [" w: V/ J# c R" k6 h
printf("调度算法..........A\n");; e" D: P" V( f0 g
printf("吞吐量............B\n");, m) R" O! ~% X0 `$ H# I; ]
printf("平均周转时间......C\n");
. v* Z$ ]) V6 E3 ]* C, `+ Kprintf("等待时间..........D\n");! w3 T) X( n* i: s, u* c g
printf("CPU利用率.........E\n");/ s4 _3 {2 T' U+ f% {+ _- O
printf("A\tB\tC\t\tD\t\tE\n");
0 J+ U2 @0 J' _2 ^& S+ ffor(i=0;i<5;i++)7 f+ _! J$ W4 S2 a$ m
{5 x$ o8 A: j8 _! Z
count=0,turnover=0,wait=0,c=0,w=0,change=0;
$ ~! ~% N. g9 e. yfor(p=name; p!=NULL; p=p->next)' X/ K3 S: B) t
{' i7 K" L: d- J4 S+ {, Y) o
count++;
- f I; ]6 \& _& W" V9 Tturnover += p->completedTime - p->comeingTime;" r4 J' D: G, f8 Z! w& U' h3 u3 k
wait += p->runningTime - p->comeingTime;7 P2 m7 I0 t: j5 N" Y% f4 _* L
c += p->compute;$ g9 d; Q) e8 ~+ v: ? l
w += p->waitio;
& |5 x. ~- S7 ~% Z j: H& p# L$ fchange += p->exchange;; Q' M& k8 P$ T3 y6 l8 p5 f+ |+ X
}8 I* |2 k* L; n" ]! h
turnover = turnover/count;
3 ^! W3 L; O1 W7 O$ a/ Tprintf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));
+ b3 _2 u, i7 H7 P7 D) C4 Hstrcpy(inf.name,ch);6 U( W8 Z2 \( q
inf.throughput=count;$ I% y0 b3 ^4 s0 m6 V C4 t
inf.turnover=turnover;
! a+ T# \/ k9 Einf.wait=wait;
, C* D0 v6 x& |; Rinf.CPU_rate=c/(c+w+change);, e# F/ q# K# R& \
}
' l3 N1 l- }$ Q- s: r& E$ c* z% ]//画图
* I8 X, F9 S& V5 |# N//cleardevice();$ F0 @5 A$ r, g" v
line(0,600,1200,600);7 V5 f& {! y$ o/ s- E6 w
line(10,600,10,200);% S8 T/ J: Y$ w! S3 q% t9 E. n4 C
line(10,200,5,205);
- P) ?% S1 f4 D2 e# Pline(10,200,15,205);
2 ` I! f+ F, f$ |line(310,600,310,200);
1 \7 z U: ~( G, ^ U5 lline(310,200,305,205);' \& R V; {/ j) g( S
line(310,200,315,205);
9 I$ w9 N2 x9 `line(610,600,610,200);' ^! R8 x6 Y7 O( X3 @9 B6 g# }) I
line(610,200,605,205);$ Q1 ]. s; ~/ X4 r
line(610,200,615,205);
8 d0 h) Z D+ Q3 Gline(910,600,910,200);
* p# I3 G% |" h0 t1 G! U |* jline(910,200,905,205);- D3 i& a7 g. l4 W, |
line(910,200,915,205);//最高的长度400,宽度均为40
9 S4 O6 _! [/ l: T- Vfor(i=0;i<5;i++)! N6 }3 W3 ^" E$ A( \3 ?$ F$ S2 w; ~
{
2 A- a+ @! i0 S4 k5 q4 ]/ ~& {: Kif(inf.throughput>pos[0])' R6 k- E: G8 b# P. ~
pos[0]=inf.throughput;
/ s5 a1 }' i1 H( _0 H* e6 Q5 J ~0 tif(inf.turnover>pos[1])
5 c/ k2 M; B/ Q5 c; upos[1]=inf.turnover;3 s; m, E; o+ z; c: K$ a5 h0 |+ }
if(inf.wait>pos[2])
, b) Z* ^; g$ t( R* a* Jpos[2]=inf.wait;
( e: {3 x! q9 m* vif(inf.CPU_rate>pos[3])0 c$ b9 [6 w) }3 q6 a) W
pos[3]=inf.CPU_rate;: e% o6 H7 g' z
}
6 b$ W! W# `/ C A. Y% }/ Dsettextstyle(30, 15, _T("楷体"));; K1 g3 Q7 B/ [ Z8 g* K! V
for(i=0;i<5;i++)" {7 w- T0 \# n, a
{
, @! I/ z" D: v4 Jswitch (i)
. o- |5 }* l& H5 g{1 X! J$ ?9 B" g, f7 o
case 0:) y) n0 U( g" G6 |1 c i
setfillcolor(BLUE);
) H! S/ z) _; X4 M8 Kfillrectangle(100,50,150,100);
- K- g; o6 s) ^0 Youttextxy(160,50,"FCFS");- g' o+ i3 t8 b: H# K
break;+ J( F# c7 O9 f) d, o4 ~5 T
case 1:
/ w% C8 V- u3 l2 d) @setfillcolor(RED);
8 m1 @: g* s& {, S* cfillrectangle(250,50,300,100);
7 n- m/ a2 j& Xouttextxy(310,50,"timeTurn");
/ W* N/ ]' I6 Y f0 i6 |break;7 s1 x5 ^5 u* }+ Y
case 2:
. g7 z- h; A. P" e9 O9 m. P isetfillcolor(YELLOW);2 B# l% R4 w, R3 t: {
fillrectangle(450,50,500,100);
! B& Z. \; t2 n4 l( T/ Zouttextxy(510,50,"SJf");
. j$ J0 r' x: O& r7 Lbreak;
* Z- q6 B' D- ?. K9 kcase 3:
+ s$ l7 Y+ C2 U1 E% V; Ssetfillcolor(BROWN);' B$ l/ ?# U" I6 T
fillrectangle(580,50,630,100);& ~5 g: l1 C2 {) D+ e! R
outtextxy(640,50,"PR");4 j, h! ]1 @" T# S4 ]/ `
break;/ v( ^- L% I1 u8 R" f! m
case 4:& I+ u! T% _. w! g* M
setfillcolor(GREEN);
) D+ |7 |/ \% e( pfillrectangle(690,50,740,100);
7 ` q+ @/ _+ d" I$ R- X( Pouttextxy(750,50,"HR");
, }& e ]' I/ J4 R0 U1 Ybreak;0 u% ^ z4 V) O( V
}7 S3 u, _: D% M3 }
fillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);) D N1 V" I1 y; x. \
fillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);
; E, T0 m: w+ u/ }9 ffillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);
' t/ I: g$ _" k8 ^; w/ t$ x# @fillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);
$ u( {0 w' n- Z2 p: l
+ O; K) @0 {2 [! a
9 J) N- y* H9 Q}3 r% Y7 Y' P2 N3 f: B) e- A9 H' k
outtextxy(100,150,"吞吐量");
0 j' b4 E$ y/ J( m& k2 h- b2 pouttextxy(350,150,"平均周转时间");6 W7 Y2 F9 g! ^% ^" A) L
outtextxy(650,150,"平均等待时间");
. K; E( u+ A$ w9 c$ [outtextxy(950,150,"CPU利用率");, b2 } s7 T2 w. b* O9 z
return 0;
1 U0 x! F: p7 W! e}# k5 q$ x- c5 A! B
int MouseListening()) m. L9 b! Q/ b1 z4 f( W# z5 Q: l
{
" l V' Q6 k* m' A' ^. W7 WMOUSEMSG p;
3 Z u$ G! |. c! l& O3 Jif(MouseHit())8 @, |" I% ^% k( Z& w9 M9 e
{$ }7 |: T5 n, D! n' W
p=GetMouseMsg();
- h# h9 T, ?* o q3 r6 q. _if(p.mkLButton==true)5 ^5 m- z1 d7 h
{
* H1 C3 U }$ v$ Dif(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
7 d# a6 E# V J, DFLAG_FIFO = 1;/ m: ?' h' W2 ~# S
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)
# k# |/ _! r- m( u+ ]! yFLAG_TT = 1;2 G3 q+ S+ c% Y& }1 r) f4 ]
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)
! S7 { v7 Q4 l7 i$ h2 C( z6 f& ZFLAG_PF = 1;& x- x- r* V% m# Q* g' G! P
else if(p.x>0 && p.y>325 && p.x<400 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
, w# `- l" \) F$ w( B% z+ ?) r1 C9 ]FLAG_SJF = 1;! a" q. O$ f% F
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). ]2 G% o( s J. f* l
FLAG_HR=1;7 k+ e: w2 T! f" r/ v
else if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)4 G+ H# M5 k5 M+ o. g4 U. m
{ r9 X) `$ b- I' m/ y
FLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;
* ]) Q; [9 p1 Xclearrectangle(800,325,1200,650);
( }2 X6 H1 g* k+ L- o}
% P1 N7 m! {2 X- ` \- m. lelse if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )
( q* G: X4 @8 z) ?2 L% D{
4 ~+ N- `3 O+ O8 W% zFLAG_show=0;
, j1 j( o3 {9 c6 B5 ?cleardevice();
2 _% v' U( g; [' V1 c' J) Xreturn 1;
; f: h$ E7 Y7 [! D) U7 h7 W, o; f}
- T5 F/ I8 g+ K' t}3 `8 |0 ~$ |& j" \
}
$ m5 ]+ c9 B$ d/ l5 ^/ ireturn 0;
+ c# Y7 v. f9 g9 b) u0 {} J2 a/ Z, z% ~* H3 N+ l
int MouseListening2(int *flagShow,int * showTime): y2 E4 g8 f+ B
{- o/ [/ x. x2 B2 b; `
MOUSEMSG p;
+ W7 ~. q2 a# S6 q* u, j/ xrectangle(1150,0,1200,50);
9 H5 f; o6 M' w$ }1 N4 `1 E1 b2 routtextxy(1160,10,"X");
9 u J7 C9 [0 h1 e# V) q, @0 Zwhile(1)- q% j l0 u) h2 Y$ N( Z ], F
{4 Z2 I2 Y3 K! `
if(MouseHit())' H% z' T( F3 }4 @
{. K! n- @1 a; R& ^
p=GetMouseMsg();3 Y6 n0 K5 P- l/ X1 I
if(p.mkLButton==true), S- B1 e/ O; R0 ~& N
{
" D3 n3 g2 s( Z+ D3 Q% B7 bif(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 )$ t6 d# Q/ ^ e
{
) {5 _+ @1 Z8 X# y% X" O# \(*flagShow) = 0;
& h: y& [+ F7 V" Q* d8 l2 r(*showTime) += (*showTime);" I, V9 y m+ ?5 h6 D
FLAG_show=1;! Y9 F- g( V7 T k
break;# ]" q- m9 P& u3 G9 Y
}
7 q A. w! E& b2 d/ s$ ~; n9 z
8 X9 a7 ]* @0 A. L' H, l+ H}1 z* N! Q* Z# j* z( Z6 n* @
}, Z$ A( Q1 J5 z" Q
Sleep(20);$ o6 j0 L. r" w' h: n! r
}
[' A3 S: H) e1 ~7 K( ncleardevice();9 t' g: J' z3 Y: Q
return 0;
/ T6 s, M7 ^* \" E}3 N' r" @% S* t# r6 m
int drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)
' J% L8 G7 D+ q5 l a{, f8 q" d {9 I5 I
static int info[11][3],num=0;2 o$ a0 u: w, W% x4 q
int i=0,j=0,pos[10][3][2];/ x5 D* O! Z1 [4 u
float temp,t;
5 v3 h4 p; u$ z: y) @ U//画按钮,不属于FIFO图的范围
4 O% x$ J* Q8 L+ e2 ]if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1)
. m% X: U; A1 ?4 M. a{0 N9 ~1 Q# L0 A7 k5 d- J
settextstyle(30, 15, _T("楷体"));
( ^0 G7 u: q0 o" a9 Mrectangle(890,455,1110,510);
2 k0 G. T: B1 F/ J6 M1 grectangle(900,465,1100,500);
' `8 u- f+ ]8 {' A8 houttextxy(910,468,"查看运行结果");
/ B1 E6 L3 X& Q) }9 z2 [2 C}4 n4 A& G) H: _
//结束画按钮7 ]9 ]6 P7 t' }' x
info[num][0] = com;
% t; `$ S" c/ J) m8 ~7 g# }info[num][1] = wai;
; C$ H3 `1 j9 J! z3 ~/ pinfo[num++][2] = cha;
7 z! I2 }& y7 x) S, mif(num>10) //存储10个点
/ s' ~" H( A, b8 L" c, U& z{
$ ^( L" K4 {( P- X" I+ k, S* r! S8 pfor(i=0 ;i<10;i++)
+ q# X; H/ e a8 s4 h: K2 f3 d{) T: x( N; L- g/ p$ g6 p+ @
info[0] = info[i+1][0];
* T7 T+ Z* G) l, Z$ ~info[1] = info[i+1][1];6 v2 F: I& [0 b' E1 B4 ]
info[2] = info[i+1][2];* F7 L7 z* A; v5 r1 u& Q% d) K
}
$ }8 i# Y( c+ B8 }# M% i m& Gnum--;
- V" n& V! m' @& G}
4 ]2 S: c( E2 Q5 {6 gif(FLAG_show==0)+ P) f. |$ a: P; R; b4 Q
return 0;
3 D& d: o$ R, f7 W- Hfor(i=0; i<num; i++)6 T( k9 x. I# L( X0 H
{0 U# K6 {$ r- G9 z3 E/ w
t = (float)info[0];
# X$ E: U) T# qtemp = (t/101)*90;6 A9 X" Q) }& u! v
pos[0][0] = (10-num+i)*25+x+100;; {9 K/ S8 T* g
pos[0][1] = y+110-(int)temp;
; q1 u* a, I! E+ I: X* lt = (float)info[1];
% P1 M3 H( s9 ?: ^/ [temp = (t/101)*90;5 R$ ~: W0 G5 a e' \6 W. o; w+ r
pos[1][0] = (10-num+i)*25+x+100;1 G O1 e' z/ m
pos[1][1] = y+210-(int)temp;0 \" d3 u* { E5 @9 u! v5 z: q
t = (float)info[2];/ T9 |7 J8 ]9 p. H2 |$ R9 G
temp = (t/101)*90;; _" {4 Q; s' `. g4 C: i
pos[2][0] = (10-num+i)*25+x+100;% M) M2 e1 W* e" l: Y! B( Y8 w. F% A
pos[2][1] = y+310-(int)temp; D1 [+ [7 {1 X
}
. R2 U) G7 V1 B1 x) Xif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)3 a4 @ V( F7 H! D
{# t+ r& \, \0 e+ X2 t( F$ l
clearrectangle(x,y,x+400,y+315);
& Z0 t# k7 z7 B( Xsettextstyle(20, 10, _T("楷体"));
1 c+ x* ^5 `6 a! Rrectangle(x,y,x+400,y+325);
8 t7 Y% D9 z: j6 N+ G" youttextxy(x+40,y+10,"CPU"); //画柱状图
% N5 R* g6 m1 d6 x9 douttextxy(x+45,y+10+100,"IO");# G5 `) b% D. n3 d7 a# w2 q
outtextxy(x+40-15,y+10+200,"change");+ l7 x5 ]$ A% ]6 [9 L& c+ L
rectangle(x+35,y+30,x+75,y+110);$ t) d8 w3 J# f* `1 N1 ^
rectangle(x+35,y+130,x+75,y+210);
+ e" T$ @8 _, n( M6 \rectangle(x+35,y+230,x+75,y+310);
* g, v' c% x/ i% A7 Kouttextxy(x+180,y+310,"FCFS");
+ q! O8 `5 i# f1 g+ Y, G, U/ Kt = (float)com;) f5 e# f; B: [
temp=(t/101)*80;! F5 b: ]# g- G' y. R
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
7 e, p1 @! ~* @2 l1 P, c( P" Jt = (float)wai;
, F# r9 O) U9 J& n" D' C8 ttemp=(t/101)*80;
' H6 d$ @, U1 X1 ~! H- I4 ifillrectangle(x+35,y+210-(int)temp,x+75,y+210);$ h$ p t9 G5 K, k# h6 L
t = (float)cha;
; U( s8 B2 U9 O% A; [! b Mtemp=(t/101)*80;
1 j% a u$ S( C yfillrectangle(x+35,y+310-(int)temp,x+75,y+310);
6 |1 G5 G: z* R' D3 kfor(i=0; i<3; i++) //画坐标 high=90,length=250
. U4 c$ s6 T9 u3 Z4 |) U/ l4 u" i{
0 ^2 p$ H, {& l' q9 F$ Aline(x+100,y+110+100*i,x+350,y+110+100*i);9 w- Y/ D8 X2 u& i9 h4 D
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
: n& O& E! t; Xline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);: g& m' k* c, A$ ^" @, S# `
* ?8 |; j7 A' J7 l8 \6 l
line(x+100,y+110+100*i,x+100,y+20+100*i);+ ]6 r" @" H5 w. a
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);+ N0 B$ N8 y8 ~0 b4 n
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
& s0 v( H" p% ]9 y& r- ^' Ofor(j=0;j<num-1;j++)
( Y. u- P ]" U( | T/ J% W& N8 u{
1 `2 j K2 O% W0 P2 E% K7 Lline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);% [ ^5 U' z$ u2 a+ K
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
# M0 d9 t1 t, S4 K2 iline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
2 }% h, x- K o9 U! U* ^7 H8 y1 `}5 V. l; z0 A- t% m5 w! l" u
}
' I8 }+ V9 [5 i9 O J( W+ w}
! Y: y- ^5 Y2 |5 y$ felse if(FLAG_FIFO==1)
, {/ G/ m. w3 \6 s8 B( ]{
1 x, f8 x6 B5 `! C/ j6 E6 C# dx=0,y=0;! E8 B* u- Y2 w) G7 l1 k
for(i=0; i<num; i++)
8 `1 \1 s0 q3 Y0 x! e9 j5 B7 m5 X{
" H2 V: x6 S% R7 A7 A5 N. }" _t = (float)info[0];
" _ I2 k1 j6 X5 b, g. gtemp = (t/101)*180;5 C: O1 g- C1 `& A
pos[0][0] = (10-num+i)*50+x+650;
& c; L9 B0 F8 R% d4 d4 jpos[0][1] = y+210-(int)temp;
* o# [* t% B, t; }! ct = (float)info[1];
. B' W/ ?) Z! C8 g ]4 x& z, n2 Ltemp = (t/101)*180;5 y2 _' H y# w7 c
pos[1][0] = (10-num+i)*50+x+650;
4 B: o. N; c# S/ i8 P) Z6 ~6 Vpos[1][1] = y+420-(int)temp;
4 T- }0 b9 d0 N9 Vt = (float)info[2];
/ n, p9 I g4 h( T$ S7 Ztemp = (float)(t/101)*180;3 N* p5 l+ _0 g) Q/ ]* A
pos[2][0] = (10-num+i)*50+x+650;4 g9 ]- a: j& M; c J) e) K9 G
pos[2][1] = y+630-(int)temp;
$ ~6 u* w1 \& i$ {9 f* H}
, G" o# J/ S- m7 @* |clearrectangle(x,y,x+1200,y+650);
! g3 a. @: p) {! U. L( q6 {settextstyle(40, 20, _T("楷体"));$ d" n0 L3 p( c3 \( e Q
outtextxy(x+50,y+50,"FCFS");' B. Q) L/ s# d/ [* V# g3 J
outtextxy(x+280,y+20,"CPU"); //画柱状图3 h: Z" q/ Z/ {/ z/ n4 a0 }
outtextxy(x+285,y+20+200,"IO");' q- Q1 ?7 l0 W( Q
outtextxy(x+250,y+20+400,"change");
/ \% }5 S* H) Z2 Q8 R0 ]# ~# trectangle(x+270,y+65,x+330,y+215);
# e4 c/ E; w: U7 p4 Q5 Rrectangle(x+270,y+265,x+330,y+415);9 e& I0 F" E0 v8 z3 @0 l) |
rectangle(x+270,y+465,x+330,y+615);
$ [6 a6 D9 r+ i0 ^outtextxy(x+290,y+620,"TT");6 i5 V; W6 V" c
t = (float)com;7 U0 f6 Y+ |# m
temp=(t/101)*150;
# S( x; O; ^: X6 Q# sfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
$ V) s$ Z2 {( d5 x8 St = (float)wai;
@+ c% \( u) Rtemp=(t/101)*150;
" E5 e3 |" P X; j+ G( Afillrectangle(x+270,y+415-(int)temp,x+330,y+415);, d w0 H. p% |, c; f3 a. H( ]
t = (float)cha;6 ~/ m5 G7 P( V8 k% a2 H
temp=(t/101)*150;3 ^. \' b; d$ u: q) Z
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);+ S7 i! J/ u, }' a- Z; _
for(i=0; i<3; i++) //画坐标 high=90,length=250
3 W+ F- Z# N' v/ \" D; k{
2 b* k$ h6 z! j1 l2 y7 I' jline(x+650,y+210+210*i,x+1150,y+210+210*i);3 s& d/ ^0 B; _$ M4 M
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);- t% U3 c% |% ?. o' ~2 G! f9 b
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
4 i8 X: H7 r& S
! K: v1 V* i( U0 ]5 {" k C' Pline(x+650,y+210+210*i,x+650,y+20+210*i);
( o: g9 y j( u5 r$ a5 ] X* gline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);3 x3 O: I) u+ e$ M$ w* K( R& C
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);/ \9 e& s3 i# G. n
for(j=0;j<num-1;j++)
6 Z! l' M) A' D# X{$ U3 C- ~4 C( T) h
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
# q+ `! T% m1 E2 fline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]); e: ?' d% |) C' u i% @; E; _
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 0 n2 @, i! {* \+ J2 t6 m5 M/ ^
}6 \: W( ^+ g: Y. u5 O
}
7 O$ D, E; y: s4 ?}3 i: [) n; K! ^& j# M
. J' R: n e1 O9 R6 o
9 \6 j' j# i( \, Xreturn 0;
! n) Q G. m' @( W$ \' q}
$ X7 S# L- U6 i: ^% {, U# Fint drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)/ ?0 z8 I! F S7 Q9 w
{
) E" n4 ]2 J' d% ?6 sstatic int info[11][3],num=0;
) s' Y7 ?8 [) z) P. V. r7 Pint i=0,j=0,pos[10][3][2];' Q O9 [& ^8 f5 j# ]/ Z
float temp,t;, ^; S, t: a. T8 c: F
info[num][0] = com;
: ?+ _4 j6 k7 R/ Einfo[num][1] = wai;$ U* V7 |- J6 D3 m" |
info[num++][2] = cha;- b# c6 Q9 J1 R) }0 }& v1 v
if(num>10) //存储10个点9 a. t3 B& A: Z- F: Y$ U+ y9 Q
{2 p& B G* Q: |, ^, i
for(i=0 ;i<10;i++)) y* r. M" q. D: J" i0 @$ q9 ?
{& D, x6 E: H$ m% p% b, ?2 R
info[0] = info[i+1][0];
9 ~4 U) h* J7 b2 F+ A' l" Minfo[1] = info[i+1][1];3 I- W$ o G5 f D
info[2] = info[i+1][2];$ K$ _3 d6 H9 q. W6 N& |
}
4 b8 ]& G# u/ S0 F1 S& I) I* ?) ynum--;
2 g, [+ K; K2 b: F7 S( ^}
4 c T* D6 p7 P6 D$ N$ Y1 m1 aif(FLAG_show==0)4 w' |2 x1 o9 S* D9 L
return 0;
m# A# G ^7 e+ Kfor(i=0; i<num; i++)
" A2 |, s7 C/ Y2 p% F. S) y. d8 g{! D _: n: n. ]0 P5 n; @8 v
t = (float)info[0];
! }; \% d. ]' [3 ^- H7 utemp = (t/101)*90;
{+ @ B' w g6 Cpos[0][0] = (10-num+i)*25+x+100;( p$ a: L8 ^, b( }- Y/ T0 n
pos[0][1] = y+110-(int)temp;
* m6 u' ~: F* @; |. {: j5 I- ]t = (float)info[1];
7 l' V { t6 _ _5 ytemp = (t/101)*90;
; b" p9 D& V) t3 y+ qpos[1][0] = (10-num+i)*25+x+100;( J( ^# j3 f& f7 {: r; y3 ~; v- I6 Y
pos[1][1] = y+210-(int)temp;
( U" U9 z7 n/ x, X L4 b) b: At = (float)info[2];
8 ]0 Y1 R* b, T" t7 R. Ztemp = (float)(t/101)*90;$ z( S* h1 s8 L
pos[2][0] = (10-num+i)*25+x+100;& M( Q P" ~, v" x3 _
pos[2][1] = y+310-(int)temp;; [, T0 _& B( \ T6 U
}& f0 R! Z' `+ j: D' O& V
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
2 T) D, Y5 N8 C{
2 W9 @8 I2 i, {% A; N7 }clearrectangle(x,y,x+400,y+315);+ _3 N2 ^1 [7 ]( C: X" e/ i
settextstyle(20, 10, _T("楷体"));- j/ r) a2 l. }: k
rectangle(x,y,x+400,y+325);
7 c* n, j3 Z# U0 n: Uouttextxy(x+40,y+10,"CPU"); //画柱状图
0 ]$ W7 \3 ~$ }* |& Bouttextxy(x+45,y+10+100,"IO");9 J" C6 a( X0 p) | L
outtextxy(x+40-15,y+10+200,"change");
4 L& b7 I/ A. y# R brectangle(x+35,y+30,x+75,y+110);. N4 H, T, {2 K3 p* k
rectangle(x+35,y+130,x+75,y+210);
( ^% K4 V. N% ]5 Grectangle(x+35,y+230,x+75,y+310);$ F' d9 |0 w2 y1 o
outtextxy(x+180,y+310,"HR");
1 l$ ~9 m! e6 f4 d4 y! g- j7 o& L5 qt = (float)com;
/ H' {, O) J1 Ptemp=(t/101)*80;9 v; e: e `. W( P' `
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);0 |1 c7 I' E- |! V( y
t = (float)wai;
$ O! k5 V5 d4 R+ M m1 b% X8 r9 J' ]temp=(t/101)*80;0 Y; o+ t- \# G/ a; u- _
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);2 t) l9 ]4 @; h& ]8 q
t = (float)cha;$ m+ R& Q* [. j. b- s5 @; |/ z0 d/ \
temp=(t/101)*80;
5 }; R1 s; F% C+ L; _fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
/ o3 O8 X, I: z4 S; O7 u: afor(i=0; i<3; i++) //画坐标 high=90,length=250" g: O( _* c/ H) V7 Z
{( ^8 a9 `' l7 V) R7 K$ m
line(x+100,y+110+100*i,x+350,y+110+100*i);
. u9 V0 x' o( L% Q: L) J- kline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);5 q) I. L( c& A* v9 ?" L" z# q1 P
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);- i e# i* J" q1 u. S* X
+ V8 G; |4 y9 {" F% iline(x+100,y+110+100*i,x+100,y+20+100*i);
1 {) Z6 P+ x% t3 ^4 ~line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
# u( k$ J* `, }line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);1 e& g- t. J+ p3 `0 @1 l
for(j=0;j<num-1;j++)
# w+ y6 c# A" [% ]5 ~& a8 j{
3 P( c B: _0 O; U& fline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);! h5 ?' ?6 n( V
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);. B- O5 h% d5 y3 s l, v
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ) J' v. o: U7 u$ D( ]3 j% B
} F5 h* |, a+ H& H
}
/ _/ v N' Y: W+ C% \! }- c0 B}
; j& @9 I I' _; pelse if(FLAG_HR==1)
0 O2 u" e0 L/ ^$ c1 t{7 k, c+ A; z3 x4 z' H3 Y( K' x* D" O
x=0,y=0;( D" \0 @! q+ M0 _. p. L* `
for(i=0; i<num; i++)& }& ?4 e7 t, \' \9 _0 z- T
{
$ d0 z: n& c" ?: o) Jt = (float)info[0];8 I8 c, |% Z; |* u" p
temp = (t/101)*180;
" @' _" q- u# g6 e2 S' ^pos[0][0] = (10-num+i)*50+x+650;. z1 t: B' a0 q2 S# n5 T& |9 w
pos[0][1] = y+210-(int)temp;
" f$ p- k" G- P7 Jt = (float)info[1];& |: x$ h+ z# L* o6 f3 n* x0 z
temp = (t/101)*180;8 \: P$ h: C- U# W+ E
pos[1][0] = (10-num+i)*50+x+650;% Y5 B; E* A2 j7 X) g
pos[1][1] = y+420-(int)temp;
; S3 |$ q- ^' ~7 _, X3 [- Ht = (float)info[2];6 o$ R1 o. z/ O! c2 A
temp = (float)(t/101)*180;
( R" t4 b: J2 apos[2][0] = (10-num+i)*50+x+650;
( Q, Q, H! L- Y U7 }pos[2][1] = y+630-(int)temp;
9 g B3 g' Z$ n) x}
# @* H6 _1 u: N& N) W5 Wclearrectangle(x,y,x+1200,y+650);2 a! Q) ^; Q( l
settextstyle(40, 20, _T("楷体"));$ J* q D$ {3 |" [: X: Q
outtextxy(x+50,y+50,"HR");
0 g% F, A- p$ i; @: _) P0 Jouttextxy(x+280,y+20,"CPU"); //画柱状图
+ d' h" w; H' ]6 `+ U/ w" xouttextxy(x+285,y+20+200,"IO");, A) A" O. B, h" H' c
outtextxy(x+250,y+20+400,"change");6 O0 P( _# F( E
rectangle(x+270,y+65,x+330,y+215);
$ Y$ d' Y+ W5 w1 C# hrectangle(x+270,y+265,x+330,y+415);
6 H/ M/ c- \# v# yrectangle(x+270,y+465,x+330,y+615);
2 |, Y! B/ F9 ]4 a3 N6 Jouttextxy(x+290,y+620,"TT");
$ g3 p# X7 P) Q4 ot = (float)com;. m2 n7 _) K+ o5 Z
temp=(t/101)*150;6 I7 i9 `5 w Z" Q
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
( n- C' K. w6 l( E+ }! @t = (float)wai;
: u0 L( F: y3 r: \+ y+ gtemp=(t/101)*150;
' S6 o" B& F4 Ofillrectangle(x+270,y+415-(int)temp,x+330,y+415);' b& Z! Q. e3 k7 A! _$ N" p6 D
t = (float)cha;
! f1 @( T5 N9 A3 k+ _" Ftemp=(t/101)*150;
6 z, p! H2 G3 U) l2 lfillrectangle(x+270,y+615-(int)temp,x+330,y+615);* s1 f: E: o/ X. ^
for(i=0; i<3; i++) //画坐标 high=90,length=250
1 O) K3 u3 a L, O. R- i* Z{
8 ^+ E3 }8 V0 h" f2 Eline(x+650,y+210+210*i,x+1150,y+210+210*i);
6 Q J* L3 F+ f5 B" z }# W* oline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);( D7 A$ t1 y1 U( E9 E
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);- J$ E8 H, p5 N; z5 R9 G
( L* l% v0 w) Wline(x+650,y+210+210*i,x+650,y+20+210*i);+ v2 X5 u6 [7 g) Y9 k1 V% a
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
4 a9 [# b% C# Z1 `8 C, h4 o+ {, Gline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
' m' q. q2 O' I2 I& P( D$ [ Tfor(j=0;j<num-1;j++)
# r5 p7 N' k8 R* b: \6 R{
" g4 ^8 @ t& ~! u/ o, ]1 h5 Yline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
0 t+ F. W! X& i8 o! q: Tline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);+ _- f4 f+ W1 g
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); $ m' L! U" \' `) J' h# [
}
, P& g% R2 \; {}
3 ^/ V, p9 `$ T& E0 c}
$ o9 G7 z* Z2 `7 }( A
. a# Q% S, A9 R. H) e h" {4 m" e% t9 J0 ~( y
return 0;
9 X6 C1 ~* R4 O! c}7 U$ Y6 `! b+ Z6 Z) Q
int drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)( I( b& ^8 |7 c
{
. U. `( ^0 c0 |static int info[11][3],num=0;
5 K6 B% b( |2 ^int i=0,j=0,pos[10][3][2];
( Z3 B) f. ~. B- |( z9 i/ lfloat temp,t;
" }) M0 `. L' x( p/ e# @( P9 oinfo[num][0] = com;5 {$ ?/ R1 q4 F2 a
info[num][1] = wai;8 d5 w) {" g/ a) y
info[num++][2] = cha;
1 r; {8 g9 H& O0 A3 Wif(num>10) //存储10个点) {% ?3 U7 z) G2 o `
{" H, l+ T# d+ z! {" Y* ]3 O* N, ]
for(i=0 ;i<10;i++)0 o1 U, E* y5 D
{
: U& S. t9 r& w' dinfo[0] = info[i+1][0];
! ?# V1 y: t% g. [, ]. V. m# Rinfo[1] = info[i+1][1];3 `3 z" f+ `: ]- b
info[2] = info[i+1][2];- c/ ^ z( g3 ?. V. E. M
}3 c w( Q0 R+ s. L! L6 U& h
num--;
, v1 P" z# y2 J4 g}
' T1 j x" @! f- { G4 Iif(FLAG_show==0), U* U' V; K& h' P j
return 0;
" o9 M+ w W/ p8 E0 ?! j% dfor(i=0; i<num; i++)4 X% p2 @9 ?2 _7 p2 A3 I. u' y
{
]$ l2 \" p. }! Wt = (float)info[0];
& E/ }, j0 S( [; W. [temp = (t/101)*90;
7 J# C) t9 h, P* {9 Ipos[0][0] = (10-num+i)*25+x+100;' y e6 L3 @, \! C
pos[0][1] = y+110-(int)temp;
$ z \; t" s8 W7 R+ S |0 {t = (float)info[1];0 h" P* I* c8 r8 A% p
temp = (t/101)*90;3 x) @) A3 T# F- s' T1 c- b X
pos[1][0] = (10-num+i)*25+x+100;
6 c, t5 r: q* v5 _pos[1][1] = y+210-(int)temp;% ~" {1 Q* x8 n( O
t = (float)info[2];! W) v, |, t) q1 u
temp = (float)(t/101)*90;* f( F9 W: H+ u
pos[2][0] = (10-num+i)*25+x+100;
2 J) v2 \0 S' y, B& _- z; `% `2 Upos[2][1] = y+310-(int)temp;
# p: y" h W: J# R, E0 R* \}( ~5 m8 F2 F! D6 n
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)1 v0 i' i2 I% p
{
u. l' U: d; j$ ]. Nclearrectangle(x,y,x+400,y+315);8 f4 h( o7 l. s+ |
settextstyle(20, 10, _T("楷体"));
7 J1 P- Q, l+ W! _) O2 p, |% d! krectangle(x,y,x+400,y+325);4 q+ R. T) R; D" g% V* N
outtextxy(x+40,y+10,"CPU"); //画柱状图
+ p# K% {" @/ o& [4 t; s ~2 Routtextxy(x+45,y+10+100,"IO");" \' |* [- v4 z [
outtextxy(x+40-15,y+10+200,"change");* b! l/ _2 v3 N9 W& G5 b& `
rectangle(x+35,y+30,x+75,y+110);
. X4 T v( l+ R2 w! srectangle(x+35,y+130,x+75,y+210);
7 [# v& V! s a! l, m5 ] G0 irectangle(x+35,y+230,x+75,y+310);% A" R( {$ m' }: O: ~! f
outtextxy(x+180,y+310,"TT");
5 w* {2 w6 _/ M2 Ht = (float)com;
8 w" G& w; c6 ~+ |temp=(t/101)*80;
7 z5 _# ^/ J/ U9 t9 r8 b" Lfillrectangle(x+35,y+110-(int)temp,x+75,y+110);1 R& ~: ~; {/ O* w$ F- T* e+ O
t = (float)wai;
, G# b8 z* V; |, f) X; d. ktemp=(t/101)*80;
8 }9 t4 |3 H2 _; N' t9 h0 \* O# q' ffillrectangle(x+35,y+210-(int)temp,x+75,y+210);
# [1 C3 E" V3 @2 ~" ^3 ^t = (float)cha;% d4 T" C7 Q7 Y: C: M" L- ? s
temp=(t/101)*80;7 C7 q- r2 [" K1 V, C7 F
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);3 g5 v& n8 T& N# V
for(i=0; i<3; i++) //画坐标 high=90,length=250
! m% P- U) c. v{: x, Y" ?" I5 y
line(x+100,y+110+100*i,x+350,y+110+100*i);6 i2 h1 o4 l- F$ W
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
# ~5 Y$ V- W# R Hline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
: z0 C8 u) k2 _2 S* p$ a3 c8 _+ s: `) r5 w' ^7 f1 H
line(x+100,y+110+100*i,x+100,y+20+100*i);* i2 C. X& u- v
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
# j5 g' i/ n; q1 b6 i) vline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
. P# A$ ? _) w4 Kfor(j=0;j<num-1;j++)
) E) f# B! I8 E, j! v{! f' W4 c$ F5 W
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);" C. N8 A8 r2 n
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
1 x. ^8 K4 [4 _6 {- Bline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); " R- t/ J- Y2 t y0 V( b, Y
}, g! Q. D/ W& q {8 |
}0 ^) }( ]. |7 r5 ^( L
}2 L2 z' [' e$ k+ S
else if(FLAG_TT==1)
4 p3 L; q# y9 Q7 O7 o* t/ f) {3 i{/ D: p' d; U6 Y# b6 s
x=0,y=0;
/ d _5 L$ g5 a2 f& [* rfor(i=0; i<num; i++)8 k/ x4 M c( K+ o! G& P
{5 t1 ]' g1 G: X; o8 ~9 c1 O
t = (float)info[0];
. ^# r! L! I+ `' W2 z- f" rtemp = (t/101)*180;+ f5 e! A. T( G: J" |; o
pos[0][0] = (10-num+i)*50+x+650;
) }: P8 T! N8 x5 a1 rpos[0][1] = y+210-(int)temp;* D2 X* O4 R) x/ b) H1 y$ E
t = (float)info[1];3 k9 O, K; m E- \+ ~ P4 O
temp = (t/101)*180;7 x5 T# k% C5 h7 A9 }6 A* O
pos[1][0] = (10-num+i)*50+x+650;
& L1 a1 D4 v2 `pos[1][1] = y+420-(int)temp;
1 n7 C* t; j6 F$ Y/ R: B5 ct = (float)info[2];
; }3 U" A. K& z1 T) W2 ctemp = (float)(t/101)*180;
4 V* W4 Z' I/ d( |- zpos[2][0] = (10-num+i)*50+x+650;
% {. u3 U( N' q8 w8 p6 gpos[2][1] = y+630-(int)temp; [) Q+ X% h; X3 k
}0 S6 O1 Y# k/ w8 v
clearrectangle(x,y,x+1200,y+650);
3 A4 U8 [! h, P" bsettextstyle(40, 20, _T("楷体"));
8 K. E$ m' u* @ H; Fouttextxy(x+50,y+50,"TT");- l; A, J9 k1 _: ?+ R7 M
outtextxy(x+280,y+20,"CPU"); //画柱状图! Y: j$ V" T, h$ u7 I& X
outtextxy(x+285,y+20+200,"IO");; V6 T1 F/ `4 ? g
outtextxy(x+250,y+20+400,"change");
6 s. ?' D( W6 i4 o. g9 |rectangle(x+270,y+65,x+330,y+215);# B' P; _. z% q& t. F$ ]/ m; \. @/ r
rectangle(x+270,y+265,x+330,y+415);( q1 q, C1 }1 Q6 J) D
rectangle(x+270,y+465,x+330,y+615);; Q2 M8 v. T7 k) R* E7 u
outtextxy(x+290,y+620,"TT");9 C5 v }7 z+ c
t = (float)com;5 E, X, h+ ]$ E
temp=(t/101)*150;
! J) u2 l# c0 T5 efillrectangle(x+270,y+215-(int)temp,x+330,y+215);# a- W9 x0 j# Z8 s
t = (float)wai;
1 B, ~, d8 r0 h0 xtemp=(t/101)*150;
4 s8 H& O" p* Q s. Rfillrectangle(x+270,y+415-(int)temp,x+330,y+415);* n' z- N; T: ]' ]
t = (float)cha;. E; F# `, g: X( b+ N0 E
temp=(t/101)*150;! p1 y( x8 R, q: J
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);; I: f4 Y' }$ O, G" h& g c5 m
for(i=0; i<3; i++) //画坐标 high=90,length=2503 s6 T9 [6 ~* c' s' }) @
{
+ r0 s1 B U% R) cline(x+650,y+210+210*i,x+1150,y+210+210*i); }+ u0 ]9 I" M& N
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);7 u# ^5 D& F* v: P3 Y8 o& }
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);4 ^5 ]) l4 p. m9 U; \7 S
7 D: O" S' a& e( J0 }# A/ l( ~9 h- u
line(x+650,y+210+210*i,x+650,y+20+210*i);
: ?5 @1 V' I4 s8 I: I) bline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
) B' I# A9 R7 o- Cline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);4 t2 r' }0 v4 a. I& H' z7 V% t
for(j=0;j<num-1;j++)
. e' e+ E: a: F# o5 _{2 O; ?+ C4 _, V' J8 H3 c7 \! ?6 b
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
4 ~9 y; h2 l7 K/ ]" s% v' nline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
9 u, H' \" ~9 u7 H3 xline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
4 N, O/ N9 T0 S5 y; _* C}
u2 \. A. t# g3 H! ]# ~}
4 X$ H- F a/ \ Y# B/ h% x- t}6 A5 W2 y! M$ l. y
; g: e6 ^2 z: Y" ^$ S' m
- z8 }, h( a5 o, \# r0 Zreturn 0;" U: J) D9 X8 `! F k2 ]( Z
}" _' r4 }# D1 \# B& D) e
int drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)
. \& r1 c3 L( Q/ @# I: J{' z' z: {$ m1 G% E) {- B% H, \$ T
static int info[11][3],num=0;7 o: S- ^% I8 l6 h- |: n
int i=0,j=0,pos[10][3][2];
- \0 m) F" I4 m) D: wfloat temp,t;9 r- t) ^6 W/ C7 {: E( Z. _/ U! I
info[num][0] = com;9 L9 G$ `6 O% [+ [2 |
info[num][1] = wai;
5 p3 P+ ~% j$ m" @info[num++][2] = cha;5 B+ ^0 A9 l! o$ M
if(num>10) //存储10个点
$ d, K- ^! f! x5 v& j{
* h. ?6 m$ G- u9 N, l# qfor(i=0 ;i<10;i++)
0 e+ d b* `0 ^' k5 |( G# n{
$ }3 @, `# P9 ~* h4 I3 {, xinfo[0] = info[i+1][0];3 Z$ k" c+ k) ^0 M# `2 }
info[1] = info[i+1][1];% g- a( F; K6 s) R' k
info[2] = info[i+1][2];
5 L5 R4 ~+ l- H' c& w$ }/ E}
/ k8 m* Z* w, p: P$ enum--;' Z$ E" D- N- t" O' B; k# Y* ]
} Y( P" s% e4 Y
if(FLAG_show==0)
, N- e/ Y1 P! H( Hreturn 0;
; s! X+ b9 t- J$ L+ W: p4 q$ ~* Mfor(i=0; i<num; i++)
( w$ d) m9 {0 H3 Z{9 O9 P" L) f4 Y+ Z
t = (float)info[0];" L" }+ q2 l6 B, B* ^( W% H" G+ W
temp = (t/101)*90;
0 A9 k0 E0 U) V% c$ T0 `pos[0][0] = (10-num+i)*25+x+100;
( Q& v) T0 c. f) S3 l& H/ Xpos[0][1] = y+110-(int)temp;
3 o0 L- Y) J& x9 @# M7 Ct = (float)info[1];
3 P6 K& p& T, j& s0 j% otemp = (t/101)*90;4 p# W1 t* ~% G) B- V6 S7 B
pos[1][0] = (10-num+i)*25+x+100;
7 U2 Z5 l% ~+ v8 y! mpos[1][1] = y+210-(int)temp;
8 J8 _8 c$ ]% s4 c) v/ b: F+ Mt = (float)info[2];2 |" g. ^: b. v' e7 F
temp = (float)(t/101)*90;
4 }/ x6 P q' I1 E3 F+ ^: l2 c# [9 P$ U. Upos[2][0] = (10-num+i)*25+x+100;
) K( o% ^- O3 }+ G$ s2 tpos[2][1] = y+310-(int)temp;
! G# n7 j7 @* G# i}
! i6 a+ N) v* j1 {if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
) r. a* M8 t) @4 l; k! W: @! o1 O{
* }. r& D' Q w* [) Y$ d8 Aclearrectangle(x,y,x+400,y+315);
M) y- U: w' N6 w4 h4 R$ Rsettextstyle(20, 10, _T("楷体"));
7 z+ }, w9 F7 s# f5 z4 r) F' F- x( `rectangle(x,y,x+400,y+325);; Q* R! Q0 G4 v2 G6 U
outtextxy(x+40,y+10,"CPU"); //画柱状图
2 n/ l$ d6 V2 g9 I4 N* p0 eouttextxy(x+45,y+10+100,"IO");* M: D# C* U1 H
outtextxy(x+40-15,y+10+200,"change");
1 P% y' B, \5 srectangle(x+35,y+30,x+75,y+110);
3 K5 T& Q2 Z1 n2 G* z7 lrectangle(x+35,y+130,x+75,y+210);( ^! h4 \! x8 W6 N3 R- e8 g
rectangle(x+35,y+230,x+75,y+310);' e" P8 S I0 b! V- `2 H
outtextxy(x+180,y+310,"PF");3 k# _9 C; b" ]0 I+ w; L" S
t = (float)com;
; `- {( ~- r) R! P* \8 S/ o Ktemp=(t/101)*80; R3 b' Y* D8 ~. W/ r
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);# {; x+ g5 D7 N) |" u( j! N
t = (float)wai;) k: v& c& e# e" E& K5 \ a- Y
temp=(t/101)*80;( k1 S# J. N0 C$ D$ g9 n
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
5 K2 ]; b. b0 y. I2 q3 o5 at = (float)cha;
8 R2 W# y# r7 dtemp=(t/101)*80;
% D0 s% d9 x- Z! Hfillrectangle(x+35,y+310-(int)temp,x+75,y+310);
/ A+ K6 I0 P+ [+ ^* A6 D1 Jfor(i=0; i<3; i++) //画坐标 high=90,length=250
( T; k- X, V4 n- t' s, x) Z{
4 N3 P) ]5 u) Yline(x+100,y+110+100*i,x+350,y+110+100*i);/ x& Z- L7 e+ F: x
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);/ |6 H" ~ \, \3 k* E* K0 j- Q3 H
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
4 k! L _% M2 m9 p6 o0 i W5 o1 b
line(x+100,y+110+100*i,x+100,y+20+100*i);
* N4 Z5 }7 {: s' x. lline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);* k( k, b7 W* N
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
, `" |$ E; S7 ?/ ` C) q5 pfor(j=0;j<num-1;j++)* W8 D& W x8 k0 k9 A( e
{' }& \) q3 c& H/ m1 X
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
6 M( |1 ]$ Y! h* _% Oline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);- t) ~# B5 n' p. o
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
6 R3 F; B C1 A8 b+ W}
& ?4 N6 E7 J2 k9 e* U. C}
# R4 Q" S# ~ @1 l I& I$ J3 j}
& U4 r$ S( ` g; M0 u( L- \- f. Aelse if(FLAG_PF==1)
" ^- ^. d- {' |0 m7 x{
& K& `) m- H n8 Q3 ]: f" ax=0,y=0;
( G% z/ z4 I* n& j5 B7 Wfor(i=0; i<num; i++)- W! T1 }7 i4 O: @6 D) h6 I
{+ [( G; M% U5 G$ O* Z3 h
t = (float)info[0];, K$ r# ?2 H$ M5 J# e, v/ t
temp = (t/101)*180;" P7 E0 Q% `9 b/ k& g* Q
pos[0][0] = (10-num+i)*50+x+650;- C* v1 c4 Z' o. [! f/ X
pos[0][1] = y+210-(int)temp;) _& ~( U" J% Y$ Y2 O
t = (float)info[1];! f+ J. M! p& ~; L7 K5 Y* f1 Z
temp = (t/101)*180;# Y! g7 B; e" x4 L
pos[1][0] = (10-num+i)*50+x+650;
' {* `7 s0 {2 J/ q, l2 g7 x& Epos[1][1] = y+420-(int)temp;0 O- ]0 s5 v) v: D+ D7 K' ?2 v
t = (float)info[2];4 o9 R, c; U3 K. M5 P
temp = (float)(t/101)*180;
) {" A7 c7 {5 O `! xpos[2][0] = (10-num+i)*50+x+650;
3 U- r c# u0 j: Q8 J: l1 T; [8 npos[2][1] = y+630-(int)temp;* Y, w4 J; ?! N. j- X9 X/ D; [. {
}
5 @' w, p" w: N0 M( \8 u+ h3 kclearrectangle(x,y,x+1200,y+650);( D$ W0 T7 _( S+ T
settextstyle(40, 20, _T("楷体"));, Y9 c" Z9 {( @! g# r$ x
outtextxy(x+50,y+50,"PF");- g3 F& o n% `/ {6 H6 s4 P6 [% Q
outtextxy(x+280,y+20,"CPU"); //画柱状图; I* L8 c& ` J' f6 a
outtextxy(x+285,y+20+200,"IO");
" B! n# }# O7 y! I, Q% C/ K6 Iouttextxy(x+250,y+20+400,"change");) k5 e$ L1 K+ t
rectangle(x+270,y+65,x+330,y+215);
; @# |& r( T& z0 Krectangle(x+270,y+265,x+330,y+415);
5 M2 u5 H3 a1 {6 Z2 s' Q6 W+ s% grectangle(x+270,y+465,x+330,y+615);
0 Y X/ l# X! houttextxy(x+290,y+620,"TT");
! w; D! {# I3 p9 |t = (float)com;
; Q* ^2 \% S+ d7 ytemp=(t/101)*150;
/ N; U) [; ^ u# E( D$ D( S( ffillrectangle(x+270,y+215-(int)temp,x+330,y+215);; M9 O, W+ N' u, }" \
t = (float)wai;
7 P6 J( j1 V5 h0 P2 o$ Ztemp=(t/101)*150;6 r7 U. N( m% F7 ~) U
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
( c" [$ L: q, p3 k8 {5 H; k J( Lt = (float)cha;+ V1 D( Z% P, i" H) v* ]
temp=(t/101)*150;, R/ p, y W, t V- ^
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
( R" o" |6 _4 u6 E; x; f% Hfor(i=0; i<3; i++) //画坐标 high=90,length=250
' \/ j3 } V5 v! z{
. \/ |8 I7 Y9 H o6 n! f$ l. `, fline(x+650,y+210+210*i,x+1150,y+210+210*i);: M+ A8 U. H7 U, H7 ^+ ^/ f/ S
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
+ n, b1 W5 z$ f, f6 `# I. i3 Vline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
/ c% E, m2 k; ]# m( X2 N4 f3 g8 C: D0 z; {5 b6 n! Z6 s
line(x+650,y+210+210*i,x+650,y+20+210*i);9 k! \9 S. ~4 M( W- X( g
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
( I4 n% \ \0 H/ L9 C7 Oline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
9 T* O Q7 i, a' F( B% U8 c9 |for(j=0;j<num-1;j++)
9 o! {" n/ U4 a6 S! h' r+ j{3 t8 {# U- ~: F7 @4 L* V5 D
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);: E: o& A$ ]6 I! ^
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);. ^: I' W; F* E2 t5 o$ W# {1 c' G
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 2 c# d$ B% D4 g8 h+ X
}3 [! M; _+ @/ C0 O1 C' M
}' U: a. M. ^3 Q$ a$ q6 k
}
. l! o o" w+ _0 V+ D- I% N+ M5 X" ereturn 0;; q! R2 [' q N. H
}
+ H9 q( l! E. w1 _, Mint drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)8 @: B B' L H: ]* C' E0 f& b
{; F: C' `% W/ c/ s3 h
static int info[11][3],num=0;
: h. S- a$ V$ f: [int i=0,j=0,pos[10][3][2];
1 U ]$ O- u' y9 efloat temp,t;1 H; B' d$ x4 \0 h# R- K
info[num][0] = com;; p9 K6 X0 l" K5 [6 e& N
info[num][1] = wai;
! w) \- v2 H$ @0 u( S5 x, uinfo[num++][2] = cha;, K. I+ G m; ~ M+ H* m& p
if(num>10) //存储10个点. ~# U' |7 u k; Q" R! e& A
{
) V( u' m: Q3 C0 j; ?" Mfor(i=0 ;i<10;i++)3 d) t9 A" n3 R
{; O6 t0 B7 w \7 B% [5 ?' G
info[0] = info[i+1][0];0 o c8 I9 @& B5 C ^/ Y
info[1] = info[i+1][1];/ Z$ E4 E6 z0 v/ O
info[2] = info[i+1][2];
" m5 E9 p5 w2 B6 A9 ]}- U" e/ C$ e, p2 i( H" O' l
num--;# K5 m. q- M+ E- C
}
0 F/ c- j" x4 dif(FLAG_show==0)
) G7 Z- F! I+ C" V. @return 0;) J' `% P+ T# v% x. P. f
for(i=0; i<num; i++)+ f) Z% I- H1 r/ O
{
* q& X& ?+ N! \# B9 T; W! N& rt = (float)info[0];
5 y9 N$ V( y" S, Z: }7 X" u2 Qtemp = (t/101)*90;2 @2 `) D. a4 \& T
pos[0][0] = (10-num+i)*25+x+100;
0 T: e4 B7 I! ^+ w7 [pos[0][1] = y+110-(int)temp;4 B0 ^+ P6 T6 r+ P4 }, ]1 N
t = (float)info[1];
3 W$ z+ G( ~# g# U$ t1 e9 c7 }; J8 Ktemp = (t/101)*90;. F9 `2 j* z6 t7 N
pos[1][0] = (10-num+i)*25+x+100;
5 i7 Y* x2 |2 B# wpos[1][1] = y+210-(int)temp;
: {$ c' m2 I' ]% q, {! y" Tt = (float)info[2];: ~. E! m/ \6 D+ ~) v3 m# z/ N6 g
temp = (float)(t/101)*90;. K! h6 z1 E0 V# x& N' x+ u% M
pos[2][0] = (10-num+i)*25+x+100;
1 v4 L9 {9 B6 i1 K4 W! Z9 h. ]pos[2][1] = y+310-(int)temp;
: b, ^3 i& Z/ Z: g# l}
, L" k; k6 t& L, D* Nif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)) F4 o- h6 q5 z. H# P
{ # \2 [& N6 Q9 A' c& t. D( H
clearrectangle(x,y,x+400,y+315);
2 I9 J+ t. P/ R- |settextstyle(20, 10, _T("楷体"));
, ^ D1 Q( }9 q/ z/ H* frectangle(x,y,x+400,y+325);/ Z6 f1 Z/ @/ n. o+ @
outtextxy(x+40,y+10,"CPU"); //画柱状图* W# W# f& K( ~3 d7 y
outtextxy(x+45,y+10+100,"IO");
7 j* R% P6 [9 {6 k# m3 `outtextxy(x+40-15,y+10+200,"change");
# D( {# ]. f/ w4 ^rectangle(x+35,y+30,x+75,y+110);1 U' m% e+ m" |) w3 a
rectangle(x+35,y+130,x+75,y+210);
4 c8 n* C* G9 h1 U% Jrectangle(x+35,y+230,x+75,y+310);
1 b; H' V; t5 Xouttextxy(x+180,y+310,"SJF");
* {1 |- t+ l# `t = (float)com;2 _7 Y. [/ U/ M4 o9 G
temp=(t/101)*80;
; n. y8 I( @# l t Dfillrectangle(x+35,y+110-(int)temp,x+75,y+110);
0 }& U, }6 z3 st = (float)wai;; x7 E6 U2 I, o2 A9 z
temp=(t/101)*80;% S1 N. e6 E/ Z
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
, x+ C+ P& P# V% u' H2 B3 z* R5 `t = (float)cha;: t1 G- d1 J; x4 O) r* t
temp=(t/101)*80;
7 A( O" o! O) X4 J8 U! _# G- g: `fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
; w+ P U5 T; efor(i=0; i<3; i++) //画坐标 high=90,length=2503 D& d( Q( v1 e* S0 o
{% o5 q" e; i# o' Y6 s( |
line(x+100,y+110+100*i,x+350,y+110+100*i);6 W) c J! g! |2 B
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);' b/ r ]2 s& `' k
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
7 U" @. s+ m* m* `) [ Q( G9 _1 G+ |0 e7 P1 @) m$ b
line(x+100,y+110+100*i,x+100,y+20+100*i);
/ s# d k) H5 mline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);8 P: H' Z8 a2 T6 S T- c- p
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);! c1 r% n! l v
for(j=0;j<num-1;j++)
; A0 N" S3 O! }; J9 Z0 v3 p. J{! H3 j7 \8 f5 l$ f! i& l1 b
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
5 b5 O+ i: T& f0 f8 G$ Jline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);' j& U6 z' u7 o7 {$ Y+ d
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ; ]: o+ K J, m8 S9 @0 e/ J! {/ L
}
|: c" M# h) X, x/ X}
6 N/ ~8 Y1 @0 W8 ]2 d5 b3 s7 p9 O' A8 V}: |* P3 k" x5 N& S7 p1 U
else if(FLAG_SJF==1)
/ x. _2 N$ g6 h( ^. R( |{
* R( b( K" V$ d2 i+ f4 Hx=0,y=0;1 G7 E1 A$ k) ~3 q, R4 y# _+ Y! {
for(i=0; i<num; i++)8 N2 i4 G" k* x6 l( }8 o7 F
{( g& L* }) w: I6 h. k3 G/ T* M
t = (float)info[0];
- s& e+ Q, D, ]1 _# W. L3 ~temp = (t/101)*180;
) Z, d. l. [+ v1 G/ Fpos[0][0] = (10-num+i)*50+x+650;( L; t& c; h) ]4 K
pos[0][1] = y+210-(int)temp;
: F! [' H5 R" J- C4 M3 T' rt = (float)info[1];/ B' y1 u$ Q. s) I0 F3 N$ L
temp = (t/101)*180;
1 ?: z' i" U) W* x) h- Tpos[1][0] = (10-num+i)*50+x+650;
L4 q1 ]/ Z1 B, e5 Dpos[1][1] = y+420-(int)temp;
% c0 {* ~; V2 Mt = (float)info[2];. Q% R( v/ H8 `( F
temp = (float)(t/101)*180;# ]% ^0 |: ~$ s' T a
pos[2][0] = (10-num+i)*50+x+650;
6 l2 r; {9 q# @+ N+ ?4 Spos[2][1] = y+630-(int)temp;3 q- J* {# o( {4 V0 Q6 _
}
0 i8 u! L" ~( L3 D) l7 ]clearrectangle(x,y,x+1200,y+650);0 a3 M4 d P$ K C$ D. R
settextstyle(40, 20, _T("楷体"));
5 T" d5 h l" l$ ^- Q! ^: kouttextxy(x+50,y+50,"SJF");
/ @( L4 G7 H4 d' Jouttextxy(x+280,y+20,"CPU"); //画柱状图" d6 H& c ]; E" g
outtextxy(x+285,y+20+200,"IO");
- t/ ]8 Y( l$ E8 ~" i( l/ L- Jouttextxy(x+250,y+20+400,"change");
+ k0 v3 n; J* H# ^( {rectangle(x+270,y+65,x+330,y+215);; l) L4 G) H, H T" L* B* f
rectangle(x+270,y+265,x+330,y+415);
% E+ S+ ~% M* _6 B3 Y9 drectangle(x+270,y+465,x+330,y+615);6 G% W1 b% J g$ k5 {
outtextxy(x+290,y+620,"TT");
) E3 u3 K1 I: ^- B! h! g0 Bt = (float)com;1 U+ A8 W- |+ g
temp=(t/101)*150;
7 j) A2 Y1 f nfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
0 V: A3 M) L" r% V$ ht = (float)wai;
, P+ G: a d* W+ r9 Y3 z1 ]; ~temp=(t/101)*150;; Q3 B% f `# G B; _5 r
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);$ ~# R4 y& v* a6 u+ v
t = (float)cha;
) _& N) q7 p& I' T, v$ s% vtemp=(t/101)*150;
7 G) W# _' ?* T+ V; E$ T ?fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
, E2 f; d, R; g _for(i=0; i<3; i++) //画坐标 high=90,length=250
+ t# ]/ A3 i* J; _, i* z{! @# v; D' ]1 T% e0 j) Z
line(x+650,y+210+210*i,x+1150,y+210+210*i);
8 s/ A; Y2 U" V8 h5 y0 ]3 Dline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);3 y- Y- F( _( w$ ?9 \
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);4 \ e( m# J# L% P% E
4 w8 }$ l* n' \6 C& E; R6 ]% X( }
line(x+650,y+210+210*i,x+650,y+20+210*i);
Y. @3 [# b6 E2 y) f3 h" a- ^line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);7 A7 y- r) Q% y6 ^5 ~' f
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
& d" H, x) E: g; t% Tfor(j=0;j<num-1;j++)3 D7 e2 s3 ?2 J! ?1 ~" x' C2 v9 }4 N
{, d# j! A, l$ f: Z- B" b0 W
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);9 V, h0 Y6 \ P- e
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
$ h: R, K+ `( r3 aline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); + n- C/ }7 }+ o# _2 K
}
( a$ f" [2 t7 Z' v; |( H$ d}: i* A+ z1 u: v
}* V0 D- ?; |1 D' ?
return 0;
1 T" ?% s& f; G) b. P}$ z/ k T0 Q6 s6 ^4 D
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)* e4 h! S1 e- _6 N0 P i, f( r- b
{
N. c+ l! e; Y5 Y3 wstatic int compute=0,waitio=0,change=0;$ q9 }- {3 I- B: _
static int computeLast=0,waitioLast=0,changeLast=0;
7 L: a* ]6 T& r2 {6 y" wint i=0;
5 U# O( b( `, p# m+ xif(draw==1)! c# Y6 u3 ^7 H5 o' K3 Y& \
{% r6 X9 M7 n5 j
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
& |' j. t7 `8 H7 m! T7 i6 ^* wdrawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
" F9 W6 a9 I2 q/ N1 ?: Q+ ucomputeLast=compute;
! e" Y" _! A4 S: H0 [waitioLast=waitio;
/ F z. B0 V; j; ~" ]changeLast=change;% ` _# o$ i' W7 A
}4 [ k- S7 y, {$ V3 e
if((* memory).p[0].flag==ready)0 h0 ~4 G( X) q: d
(* memory).p[0].flag=computing;# H: O9 a; @7 _0 ^: l, S) I
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
9 }" u& F+ P4 B7 X/ r/ }{+ u+ E' q" P* C8 B, Y* q3 g
i=(*memory).p[0].computeNum;' a9 d @; m, `8 z
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
2 N5 ? x( k" L( T+ I/ l% O{2 h! J" h; w& \* {0 @# U: |
(*memory).p[0].flag=IO_waiting;+ _5 Z2 L& `; x1 ~$ D9 V2 p
(*memory).p[0].computeNum--;* y4 `5 i! u% R$ T
change += exchange_IO_Compute;
) l/ _$ D+ h3 r8 Gcompute++;
9 c" Z& c) }% v( u/ Z}% D- }( a u+ [6 G. L, J9 o
else) k, s! \1 U$ r" O! C' t! O9 t1 P! W# W
{
' o: P; e/ S& j+ }4 M! Y4 ?0 z5 c7 Zcompute++;0 O: S& |3 Z( y; O/ p
}
7 b. F' \6 c" y) H1 j}- k" t% V$ `: h8 e( r; E' _8 t
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
4 D0 s+ e% d0 D2 V{
( t0 [ z% k2 V1 v4 [% a, w/ i5 _# R; v( o5 E8 z- G" |6 Y
i=(*memory).p[0].ioNum;8 x/ O$ B+ B! `
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
% }1 z0 n( C) T6 c# B{* \# Q- a" h$ [$ ~( i; Y
(*memory).p[0].flag=computing;
; f# }: U; ]( o o& f/ E(*memory).p[0].ioNum--;
; n8 L/ C5 M! M) c4 Gchange += exchange_IO_Compute;
' T; O' J% j* F2 ?waitio++;; G c, a3 H! Y* T4 T
}
0 \: y& J: l0 A( E) oelse
0 \# R; M) i; }: `# U8 p% C& ?{: }/ f" Y$ s/ Q& p }0 D$ n9 x
waitio++;( e* Q. ~ X9 J! R) @! Q
}/ k; r, T6 W" H- f
}6 W- v' ^0 g- n% L% j
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
5 N8 d" n( o0 \4 x s* z4 I- x{
# t, b: O7 g) |2 g" l& u0 ](* memory).p[0].flag=IO_waiting;
1 x' g6 ]5 E" E! rchange += exchange_IO_Compute;
- P. i( {/ M0 z2 J% g- L}
( ~- k8 z$ Z6 a+ a+ p# k$ ^: yelse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)( X0 g3 c( Z3 w
{
# b: [) ^( Y$ Y6 Z! V(* memory).p[0].flag=computing;
+ h, s3 _: l$ a! o0 }! {5 w6 achange += exchange_IO_Compute;
7 W+ C8 M' j0 `* h4 I/ u; [. f6 p}
' I9 ]2 t: E% [) T7 H2 Q- |- g0 u* aif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
r& n/ C) }! K* V0 ~/ x% U{" J2 p, X5 T, k! N: B
(*save) = (PCI*)malloc(sizeof(PCI));
% F2 P5 j$ J2 J1 H7 u/ W* q! |$ e3 k(*save)->next = NULL;
5 S* }# ^) X1 U1 L/ o: o, e2 v(*save)->processID = (*memory).p[0].processID;
* d( ]* F) _& i; N* T; F7 H5 i/ [(*save)->comeingTime = (*memory).p[0].produceTime;
# y" L. l% W) Q' j(*save)->askMemory = (*memory).p[0].askMemory;
8 X" P- B# B9 U+ Y0 D, W2 G) D: K/ y(*save)->compute = compute;) j# s; \. {7 m2 A- q2 q" ~
(*save)->waitio = waitio;, v+ O8 {9 b7 t- m* X6 ?
(*save)->exchange = change;
- E7 D4 V1 I$ P4 \0 U(*save)->completedTime = systemClock;/ V2 h5 }5 t' a( ]& Y# n
(*save)->runningTime = (*memory).p[0].runningTime;
" o4 [, y) d& ?& B. K! R5 q*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;; V) S0 X7 C- u7 t4 W
compute=waitio=change=0;, X# L4 |' E! p0 h: j, D* b
computeLast=waitioLast=changeLast=0;
5 x: \5 j" w+ FHigh_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);
/ q3 {- P& l- gchange += exchange_process;
6 V6 [* E" i7 R7 Y# T& Zreturn task_completed;# |$ `3 u: D- L% u+ ]7 M/ F2 T
}8 o" `8 V+ D3 J6 Z- s( U
else8 s4 a' Y& s' S6 I7 a
return task_not_completed;
3 F# C( q! j. C1 x) k5 C/ B}
( A( Q* P+ G w9 aint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)& m2 k2 B8 n) V1 m% M4 p" J
{* |# P' h! `$ O, S/ E. x' }+ ^
static int waitTime[initProcessNum],i=0,j=0;" k3 G0 F% f& a% P. z! z3 y% H. U+ q, P* v
static double HR_ratio[initProcessNum];5 Y- L2 o) P* F$ p* D+ t6 _
if(flag==0) //初始化数组
/ ]4 V x4 g. w7 k( C{
! `) w+ o7 \% q5 _3 ?) Y( l( i, ?6 efor(i=0; i<initProcessNum; i++)& p, d1 N5 L- \9 x) P$ b5 O6 ~ U
{" Q% a; O: ~0 u8 U8 S
waitTime=0;: p3 t! x, |% p& R4 ^
HR_ratio=1;, r" ^* N- {3 T
}3 ]4 t1 E" f' i2 f- U" `( e: a
}
6 ~9 l0 K* ?; ]( s8 N! cfor(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比
4 Y4 I' W# K" q# e$ B% H5 C8 O( K- G! G{+ b3 z$ V7 ?- e- N' ^" d2 t% \
waitTime++;
$ b) M. e" a# P P. f. VHR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);* f) H ], Q, E& d% Y# `+ }' e
if(HR_ratio > HR_ratio[j])
; t% m }+ j4 K5 s, n* wj = i;
: N5 ] m5 p. ?/ G Q7 L4 u}
0 L# C1 f0 H. O) O& mif(dispatch==1) //需要调度一个进程到内存中执行
; M0 j8 ?& F: l! i$ u5 w7 M{
% F, A5 F1 p. M7 h/ v0 ^4 J# Bif((*storage).p[j].askMemory < *spareMemory)
6 K7 G0 L3 Z3 E$ y8 w( P" {1 U5 I{
* K- g r$ w" @6 y(*memory).p[0].askMemory = (*storage).p[j].askMemory;
8 X; Y/ q) c4 v( s" U2 t(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
$ ?; ^8 M' E; W3 s5 d% C+ C0 E* T(*memory).p[0].computeNum = (*storage).p[j].computeNum;
+ ]; {' K1 {1 N/ o5 f8 T" a(*memory).p[0].ioNum = (*storage).p[j].ioNum; n9 t- d5 s9 A, ?: b* L, g: {
(*memory).p[0].processID = (*storage).p[j].processID;3 r- H+ u' G% F' C1 b6 v
(*memory).p[0].flag = (*storage).p[j].flag;3 {; ?0 {( R, t* S- U
(*memory).p[0].ioTime = (*storage).p[j].ioTime; U+ X% v' ?6 t; I3 ]
(*memory).p[0].computeTime = (*storage).p[j].computeTime;
" ]7 G8 ] v( o3 j n; g- ~% J(*memory).p[0].runningTime = systemClock;. `) u5 e% S8 g& L, H
(*memory).p[0].produceTime = (*storage).p[j].produceTime;
) j3 i. Q: ~0 P. k7 c" Bfor(i=0; i<(*memory).p[0].ioNum; i++)
4 c, X3 E( {: {1 v+ y; h! V$ B(*memory).p[0].ioClock = (*storage).p[j].ioClock;0 F# _/ u' c6 } i
for(i=0; i<(*memory).p[0].computeNum; i++)
, J5 R' _* @' x2 r(*memory).p[0].computeClock = (*storage).p[j].computeClock;5 P) v0 M* J" E0 e
(*memory).proNum=1;
* y- L3 _9 ~5 E: [0 v*spareMemory = *spareMemory - (*memory).p[j].askMemory;' u+ h) e/ w. b! R3 e
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程, U8 X3 J' ?2 B; A& K( s; [+ R
(*storage).p[j].produceTime = systemClock;9 I9 o3 g2 {* I; N. \0 \
MAX_COMING_TIME = (*storage).p[j].comeingTime;* r! }+ Z0 F( |
waitTime[j] = 0;
/ n# `1 z& H3 m" CHR_ratio[j] = 1;
4 t* Q5 H3 Z6 f- J}
3 ]$ L- [6 P) }- V' Kelse
' R2 F; r. `. N1 X" o& B6 }2 W{
9 _: Z1 a+ W# n4 E4 g2 b( ?printf("A process ask for a memory overed the system capacity\n ");" z* A. M! ~- C' w6 O
exit(1);0 x! S' i' Y7 r* _- W
}; X8 S( B( E) Q5 D; W
}4 @3 A7 \) x A# W+ f
return 0;. ]* A. f, g: _5 L# n
}
, Y, D2 Y- D7 y: d9 v8 d0 m# f# Hint PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
2 h" |9 y3 D! W) Q: J( K) _{6 H# k3 b0 Q" {6 ^' Q
static int compute=0,waitio=0,change=0;
" {2 A4 U2 k7 @$ k5 n) pstatic int computeLast=0,waitioLast=0,changeLast=0;* H2 o6 e& X8 x, w3 u0 @/ M
int i=0;
3 }2 D+ ~7 L8 e/ Q+ m3 }if(draw==1)
3 T9 b' M }$ T5 g' N( j{
; w4 _2 O+ U: T* b0 m& P//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
G# Y" u1 U& @4 AdrawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
( l1 l( |. d' M/ `- x
9 t% c( l2 z2 }/ p9 c9 C& N" g/ s, t/ \& L0 V- e& w
computeLast=compute;8 d0 ?6 d) Q, O5 M7 k' H/ i
waitioLast=waitio;
1 Y2 H4 o8 e% ~" g8 d- ~# z- ZchangeLast=change;8 z1 j) @2 ~! n5 {$ K
}
- T) C* c5 @1 o+ p3 sif((* memory).p[0].flag==ready)% T/ m4 Y2 F3 g" i
(* memory).p[0].flag=computing;
( g6 A9 d M1 {# ~if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)7 }0 v/ G# E! i4 B! v0 b1 w
{
3 c1 G- V* @+ l! @; si=(*memory).p[0].computeNum;
: U j1 k2 o: _2 Cif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed% N! v4 j/ X; s) u+ w/ d
{
' }! }) \5 c- B* ^(*memory).p[0].flag=IO_waiting;) k. M5 x# B- A# v
(*memory).p[0].computeNum--;
' U% |4 A# H( T% gchange += exchange_IO_Compute;! R. g- g( Z9 ?/ [
compute++;
( Y( Z7 r, S* {$ W8 x7 }4 u* A}2 H# c. k0 B7 K; R# J* `
else
$ J9 J2 g8 r5 B+ g% S3 W7 w{ x2 B" f* H. u( ~! _6 }3 F
compute++;
0 T* l& z( h2 `) g+ J% R2 {) q9 i}3 E. ~/ M" U1 e- b" _
}
3 V% l: n( |: G; J: x5 selse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting): `0 z2 J0 M# p" V7 O/ K
{& z0 _: A+ S, [! j+ g8 o
% X; ~5 X7 v9 n8 r" u5 i
i=(*memory).p[0].ioNum;7 e+ \$ ?3 B, Z1 O7 S* S3 N
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
% F0 [8 h3 G% }9 Q& K9 Z, {{
0 X. }4 b9 ]( f3 g U, C(*memory).p[0].flag=computing;
1 x# J3 _: ?% f5 |(*memory).p[0].ioNum--;+ D4 J5 }, X7 a+ {; B' E
change += exchange_IO_Compute;
/ E* `# b2 B" S6 H$ c) Vwaitio++;& P1 k* p- ]8 t/ h6 r
}
: Y$ [1 H' m% S6 a+ z* c& ^else$ b7 Q1 j1 N% a+ L
{9 F' L2 ?: F; [, q. ~. z
waitio++;( M$ T( m# x8 X: f7 {
}
% K5 s: r8 m/ B; k}
$ A) B Q& Y$ L7 C6 I8 Aelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)! d0 v/ k8 L$ v! |
{* x% ?( Q i: a
(* memory).p[0].flag=IO_waiting;& f& C) Q# F+ Y! |, U6 B
change += exchange_IO_Compute;
$ c1 i+ M e& P- K6 h1 e+ p}
' d' o! G: Q5 _ X0 xelse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)4 P( v/ b# B: P \' ^
{
& G# P R7 ]+ a(* memory).p[0].flag=computing;; e+ i9 U7 B$ I1 q! N6 k
change += exchange_IO_Compute;
7 H: Y2 s1 R) G: ?+ h}
* z6 b5 o8 {1 eif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成/ S8 B+ `4 w& J+ U% [: W, }; l
{
, @6 L' O- u! S- A% Z% }, x! ], p(*save) = (PCI*)malloc(sizeof(PCI));
/ e; z0 ? J. O8 B6 ^* `(*save)->next = NULL;- s3 ~: J' K2 }4 a4 ]
(*save)->processID = (*memory).p[0].processID;; h+ U% D( |- z% F" e1 b Y
(*save)->comeingTime = (*memory).p[0].produceTime;2 \, t) c' e# y, g* |
(*save)->askMemory = (*memory).p[0].askMemory;
! q4 n) ?. f) O% l# w8 |' a& I! T3 W(*save)->compute = compute;
9 z$ l/ {& m9 Y- p5 Y1 d% b(*save)->waitio = waitio;0 c& p) U+ Y, g2 P$ M0 x k
(*save)->exchange = change;/ P9 l+ J% c& K$ _% \
(*save)->completedTime = systemClock;9 }/ b1 K2 C1 c) X# z6 g" H
(*save)->runningTime = (*memory).p[0].runningTime;
5 I, I7 b5 D( G1 w! r*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;; M) x- y {4 M6 L8 F: h
compute=waitio=change=0; Z7 S2 |! o7 b' X' _/ Y
computeLast=waitioLast=changeLast=0;
8 Y. i+ d. Q6 E( ~) i6 sPriority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory)); f: S. X$ `- s6 ^
change += exchange_process;
4 C9 f5 }8 c& Yreturn task_completed;( L. Z+ I' F+ ]8 F: x, j
}4 F( D+ a6 }8 s6 ]% W8 k
else! `6 _- Q$ ]0 ~1 L
return task_not_completed;
; m+ Q( R/ u! `: @/ r8 f5 [}
! b! w2 n s) q; j. b$ g* i% fint Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)$ p' ]$ V; N8 b$ \6 ~* W# n( P
{
0 H; o6 }' g2 uint priorityNum[initProcessNum],i=0,j=0;
+ t: o+ A9 z ldouble temp=0;) w3 Y7 x& ?2 C9 r% E* z
for(i=0; i<(*storage).proNum; i++) // setting priority to each process
# j, z6 n* U$ Q( O7 ~{
5 q+ W9 K* u0 u- p4 Otemp = (*storage).p.computeTime/(*storage).p.ioTime;3 o. e9 Q' O2 o6 x1 O3 E
if(temp > 0.8)
8 i. N2 Q9 z4 J! m; b9 ?" R. `1 n2 w6 LpriorityNum = 6;
" a L. K& }) Aelse if(temp > 0.7)
e2 h: _7 a5 f( T. q6 ?$ O7 m& ?priorityNum = 5;- |6 W% k, N6 y; ]
else if(temp > 0.6)
0 u+ s; Y( f V6 y- UpriorityNum = 4;' n" D3 x8 |' _' I3 y# z% F4 @
else if(temp > 0.5)
) c! q i4 @- @1 b; v6 wpriorityNum = 3;
# `" q# O/ g0 J& [% e f# }9 Xelse if(temp > 0.4)
% A* v; [) [ `* Q: p3 s4 r0 HpriorityNum = 2;
' a8 m1 i& M5 k0 O2 b9 nelse* C% @, ~! H# `. ~7 w( G% V% N
priorityNum = 1;
0 S2 p; y* k* k4 Tif(priorityNum[j] < priorityNum)
0 U2 Q( g4 R& g3 p' u9 rj = i;
! X% h" W; a4 `% p7 D7 A; d}
! k" {+ |% f% b. xif((*storage).p[j].askMemory < *spareMemory)$ T) e2 [2 R8 a: f# ]7 R
{
* u1 o! x0 Z1 x(*memory).p[0].askMemory = (*storage).p[j].askMemory;
4 l9 N# \; \- T; y5 Z5 K8 M(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;6 D, x3 f! G! K( A7 h5 ?
(*memory).p[0].computeNum = (*storage).p[j].computeNum; p3 \6 c1 _( ^# ~
(*memory).p[0].ioNum = (*storage).p[j].ioNum;0 i1 @ S. k" e8 Z. }
(*memory).p[0].processID = (*storage).p[j].processID;% y" ?' m2 \( W" z
(*memory).p[0].flag = (*storage).p[j].flag;
% a* ~9 a& R& t1 f0 ^(*memory).p[0].ioTime = (*storage).p[j].ioTime;- b8 W% D. J6 N; j" h7 ~
(*memory).p[0].computeTime = (*storage).p[j].computeTime;
: x2 @ z4 Y! ]$ T(*memory).p[0].runningTime = systemClock;
6 z' ~7 k3 a4 ~( X(*memory).p[0].produceTime = (*storage).p[j].produceTime;
9 y. M8 c, t+ c9 J* I1 r! M: k, V! Jfor(i=0; i<(*memory).p[0].ioNum; i++)
' d# L. I- t5 D/ [(*memory).p[0].ioClock = (*storage).p[j].ioClock;2 k9 v6 X/ w8 X0 z& j; R* F
for(i=0; i<(*memory).p[0].computeNum; i++): |- w# ^7 v9 a: `
(*memory).p[0].computeClock = (*storage).p[j].computeClock;
5 V, ^$ f5 u. P. b, c1 O" Q( n(*memory).proNum=1;8 x7 Z# X0 t9 M
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
8 J9 a, `% r9 c0 b1 b. Iproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
. y. h: s3 J: N( |0 k& SMAX_COMING_TIME = (*storage).p[j].comeingTime;
% V' c. d3 U7 ~5 U& A$ ~# a4 a}( i8 e: L, J9 ] M
else
8 a2 M- o3 y; ]5 U5 E1 G{
& Z( Y, S" b. _4 I5 R! E/ d8 A1 J) oprintf("A process ask for a memory overed the system capacity\n ");
2 `/ U; c' q* i# p9 bexit(1);( Z" M) _$ }, ^! p- Y. z
}
5 w: l- S+ _/ `% p. H/ Ireturn 0;/ K/ ~' t; z& l b* Y# Z) |
}! u' @2 {3 z0 b
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
( n5 @8 i- |# U{
. b* U. b4 E& S' @" P+ `static int compute=0,waitio=0,change=0;$ e1 D! i* c& ^) ~
static int computeLast=0,waitioLast=0,changeLast=0;
; I) ]; u [4 Q+ V* q4 {* |int i=0;: U0 i& k' Y8 l5 G6 A
if(draw==1)' y4 [, M1 `/ q% I2 N- C
{
6 P8 @ h5 g& D. m- N//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);: Z/ t# c, C( t3 H( b( v/ G
drawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
, v( Y# U& t& }% ~/ g$ ^
# f9 s: ]1 h, k9 H) c" x# N z) f# ?7 ]% ?* |! p7 c1 l; d! \ b
computeLast=compute;
?$ b. W+ u! W6 F' XwaitioLast=waitio;7 g1 l4 d8 Y5 n6 c! v
changeLast=change;
: `/ J6 r- c. r+ z* @}6 g" a0 ?. s; F& j
if((* memory).p[0].flag==ready)) X8 F1 @) N: V' _4 k2 j9 y
(* memory).p[0].flag=computing;
- Z! ~* ^3 M! _1 B, Gif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
0 S$ l* X. I- y# C, G2 M2 h{
0 a" C; e+ P' x4 J) }i=(*memory).p[0].computeNum;
3 p& a: F$ k4 P3 ~4 ?if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed% ^0 N$ ~& O: M# B, F% M6 p5 B
{
+ P9 i7 w8 B; v(*memory).p[0].flag=IO_waiting;) r9 H- X+ N5 o' T+ a; I7 d
(*memory).p[0].computeNum--;
7 O8 j% J/ K1 I1 ~change += exchange_IO_Compute;
% w: k" @7 C" n/ n/ ^compute++;
" G2 n" a: o, \. l0 h1 |0 A}2 L# N. Q5 @4 x8 @. G
else
5 H3 O/ w3 H4 ?- R. X' j) l{
+ A! d: V2 F8 \8 p' G7 j/ |; {compute++;
# h8 a2 x, n0 j7 l}
8 i3 C L* X9 T2 e9 W+ o}
! E N* n1 B4 Q. q: o* eelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting). Q0 Q/ M( D+ i# R5 I& u8 H
{6 A/ @+ n. V: T% p0 h2 z; `
8 b8 J% G! X! f! \i=(*memory).p[0].ioNum;" M9 e$ {( ]! ~5 |, _
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed5 c' b. y, u( Q5 i( ]# e
{
0 R$ L* ?) V8 R. s( L4 U" Y(*memory).p[0].flag=computing;
: P/ u! r7 n( P; u/ _(*memory).p[0].ioNum--;9 R9 C/ a+ [, l+ S2 N# e+ j( n! \
change += exchange_IO_Compute;
9 |" S2 c7 h5 }3 f# y% Dwaitio++;. T# W* J0 J, F/ `# l: P- D6 v
}/ c5 \6 X7 h! L+ p
else+ P) V& N; o' K$ `6 b
{& D( C( v5 V* K
waitio++;
7 W9 Z9 n6 O5 `: I}, I/ \! |+ h1 i" H) L
}
7 O) M/ R8 Y! ~, a$ xelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)( _% [ p, P1 N$ D2 w5 P+ z8 }7 d
{! D1 R) W6 B6 _: S; T V# K; O
(* memory).p[0].flag=IO_waiting;0 ^0 I4 R# L+ X/ I. O2 W/ L
change += exchange_IO_Compute;, X/ P9 V2 c/ h& F+ \7 X( ~5 k
}1 V- a) {" D4 ^* o3 ?0 B) T# ^1 M
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
. T# L" T1 A6 B- }{ l: p7 m2 w+ m8 }) O- j
(* memory).p[0].flag=computing;
* F/ w8 O+ I' ?/ bchange += exchange_IO_Compute;5 c5 a! T- H" R6 E
}
, m6 e ]3 D" Q \8 {if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成9 h& j# K3 r' Z
{% M+ C; x- R v1 A' m) _/ s: M
(*save) = (PCI*)malloc(sizeof(PCI));+ k% N: N4 A5 W7 a
(*save)->next = NULL;
2 E$ u8 `6 k& C/ X5 y3 i$ K(*save)->processID = (*memory).p[0].processID; S5 `5 x; m& f7 s& k1 r
(*save)->comeingTime = (*memory).p[0].produceTime;
5 K; ^4 O( l+ {) X(*save)->askMemory = (*memory).p[0].askMemory;
- f" ~2 Z/ ^6 v(*save)->compute = compute;
& T- Z) q7 o7 t( C# o3 W(*save)->waitio = waitio; A- T \& [* B% F* Z
(*save)->exchange = change;
- C5 c9 G) @. s4 J(*save)->completedTime = systemClock;, c. d, B( X! Y. M8 \' S
(*save)->runningTime = (*memory).p[0].runningTime;' p/ Z! d$ [6 d x2 _: q- P/ r( {
*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;
6 Z, U% L3 y& w5 L t% ^compute=waitio=change=0;
% R" a$ ?. c0 ~ H4 ? V! BcomputeLast=waitioLast=changeLast=0;
8 X ?- E3 F9 ISJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));; A2 Z0 b) }" H3 g7 K6 m
change += exchange_process;4 ]3 [8 H4 F( a8 Q: r
return task_completed;* m' k% M& ~( T
}$ E" A1 T" H# V$ T; ~0 `
else
0 p x8 D% e5 B, {, d+ C* y Lreturn task_not_completed;
9 Y& t+ e8 ]. x9 s7 T/ E}4 ]# w/ y2 {' M7 i0 u* _' I
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
' Y0 ^& n* X# X1 e{
9 y" w6 }* c9 Pint i=0,j=0;& i4 d& |; e# s, y* w
for(i=1; i<(*storage).proNum; i++)
/ J9 a9 M) C9 A6 o7 D$ B; z4 g{' j) B% M- l& N8 c
if(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))# j: ^- G1 }& U" u$ P1 s; ?
j=i;
4 D! Q9 d( N) p$ L: V}
+ C3 l8 i( R' b0 H" Cif((*storage).p[j].askMemory > *spareMemory)" q7 [7 ^6 H: V) D. b
{
2 T) O. U& L' a8 W: c- X$ x ~printf("The memory asked is overflowed than the system memory.\n");* `1 D9 h# b. R2 w2 n9 M8 F
exit(0);
# h9 `- M" \7 a- |" z}
! c! z; Y$ }9 X- qelse2 q E+ F7 I% j( e5 d3 E+ C6 Q, A2 N% A
{
, I8 H( y; E' Y( }4 }! Q( u(*memory).p[0].askMemory = (*storage).p[j].askMemory;
" L' N: z! q! P# V7 R(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;8 U3 U; }& ?8 z7 B' B6 r; p; _0 O6 ?
(*memory).p[0].computeNum = (*storage).p[j].computeNum;7 ^+ o" n9 o2 z# ], v2 D% B; Z
(*memory).p[0].ioNum = (*storage).p[j].ioNum;$ @+ R- r. t% H% B% V
(*memory).p[0].processID = (*storage).p[j].processID;
4 V: R7 t) a! b* W; f$ m! X, t- Q3 |(*memory).p[0].flag = (*storage).p[j].flag;% F" S) e6 j! i
(*memory).p[0].ioTime = (*storage).p[j].ioTime;7 U8 m& n {7 @' u, R% ^
(*memory).p[0].computeTime = (*storage).p[j].computeTime;
$ J2 z, ~2 d) P$ s* U1 s& q$ M(*memory).p[0].runningTime = systemClock;
1 D' n" P( \3 c- F9 L& f" q(*memory).p[0].produceTime = (*storage).p[j].produceTime;
- |2 o6 H, K2 E& pfor(i=0; i<(*memory).p[0].ioNum; i++)( l2 C, l( T/ w0 A; E
(*memory).p[0].ioClock = (*storage).p[j].ioClock;5 O/ F6 E0 M+ d. o% b
for(i=0; i<(*memory).p[0].computeNum; i++)
& T D* [9 B P(*memory).p[0].computeClock = (*storage).p[j].computeClock;
4 m2 }7 z2 h u; `" o$ V9 h(*memory).proNum=1;
0 k6 k- e G4 @$ {. u9 l*spareMemory = *spareMemory - (*memory).p[j].askMemory;, p N" Y; z- z( O9 A$ ^
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
; W* r* c5 F; B4 b. pMAX_COMING_TIME = (*storage).p[j].comeingTime;
" Q+ i7 M% |3 W, O% Z}
& S0 L# b( J& B* Xreturn 0;2 l# b7 l0 `9 G: W. _3 A
}6 l. s5 i9 v. U2 |0 |6 t
int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)5 `/ @ Z0 n8 b( Y: Q: k. g
{6 K: M3 Q Z; d5 `' F& @
static int compute=0,waitio=0,change=0,clockSegment=100,poi=0;& y- a/ v9 { W
static int computeLast=0,waitioLast=0,changeLast=0;
2 v8 g( i8 F" l! Q0 b6 E* F6 g; Dint i=0,j=0,k=0;
]1 @; A: I! x. ?- rif((*memory).proNum<=0)
, s7 }( h, X( Q' ITimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);
* F ?, f7 J4 U; z5 Vif(draw==1)# x% l5 P! X4 j' g v
{5 p4 A& M% M1 s) w. @+ S
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);# v! [6 f% n- v4 b0 l
drawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
6 Z4 f; z) A' o& R! |
* _& Z& F0 ^: r4 q& |2 Y6 l
( e5 {& E) P9 Q& gcomputeLast=compute;4 G( u9 y2 e' i- W- b; ?& K
waitioLast=waitio;
[! J; f! V# A: Q9 B0 A: h/ b8 G: Z0 OchangeLast=change;
& D% [: [) E! ^}0 Q, J4 {# I8 R6 E# X9 O7 l
if(poi>=(* memory).proNum)
' ?3 g9 \2 r, K' A X# dpoi = 0;
1 L2 M! d* E+ qif((* memory).p[poi].flag==ready)
2 V5 U9 p" ~$ u) l! ^2 b(* memory).p[poi].flag=computing;. q4 e/ k; p( o( W' \' [1 T
if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)- [8 [1 O, g: o# p' I3 A
{, q9 S! V) k+ t! C! k
i=(*memory).p[poi].computeNum;
/ e4 z( t2 n9 ^: b Z; M& z& vif(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed4 B& [ }4 D u+ t3 ~% k
{
/ F8 r' f' m; S, N% f(*memory).p[poi].flag=IO_waiting;
$ v" I% F# a6 n6 r2 k1 g$ O! ~(*memory).p[poi].computeNum--;. V1 Z( D& p% `) i# F: G
change += exchange_IO_Compute;$ B# v( j" i1 L6 C3 ~/ N. M
compute++;
' P- t; _- q. m8 w: G}
; e+ A5 i. {( c& `else
7 `$ t+ A/ n ?' w& t{, P$ r4 {6 X& A# A
compute++;" t& N0 I" |3 c: T( s8 W
}
v; f7 M. {$ a3 Z/ n. ~8 N}, V* Q( a( L F( x" h) d) l6 N
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting), m( q5 U ]4 u3 w
{/ [+ b2 [! H& ^5 B
& Z4 ~$ ^2 g. s$ x- L6 f
i=(*memory).p[poi].ioNum;0 k0 y4 `/ p2 a
if(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
. }7 j3 K7 M3 T* w( A7 E: B2 n8 P{7 k* B5 @8 D" |% e" K7 L
(*memory).p[poi].flag=computing;" N0 s* m% o4 |( ?% ~7 z
(*memory).p[poi].ioNum--;
6 a8 b/ d6 `8 Cchange += exchange_IO_Compute;
( H$ x- ]3 s6 p) K7 X4 \waitio++;8 R8 a, W0 l. V
}' }$ J% |7 Y$ R& R5 Q$ |% K/ n! h
else6 F& b3 M" h7 [) f
{
) c+ t9 I9 N5 F0 G% H& b/ Dwaitio++;/ n, h ]5 ]7 [$ W
}9 i4 ~+ C6 _" K$ x( r5 l1 w& B9 j
}) c! ?4 c# w- c' }; F* o
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing)
: ]2 B7 I* h( Q, k0 \) c1 t! K{, y- L y9 Y c4 w* r( w. c
(* memory).p[poi].flag=IO_waiting;
$ e2 h/ b I; }; _3 W7 a+ a! }- Mchange += exchange_IO_Compute;% e, {# X) J8 x9 T/ e( j
}
% a( w/ H7 H: |8 \) s/ lelse if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)
F' H4 \( h5 H3 N# p) r" I1 h{
3 z8 P& e* z0 C9 }% t$ x(* memory).p[poi].flag=computing;# V/ T% [4 R8 ~
change += exchange_IO_Compute;1 Z. @3 n7 @; f# ]* z
}. j+ z0 t: f# u% _1 ~* A6 ~/ L
for(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进
$ N6 `: }! K/ g{
. m8 U6 r$ _. k& rif(i!=poi && (*memory).p.flag==IO_waiting)
) ~% q. I, `# n{
J/ e( l: u& \/ p4 dj=(*memory).p.ioNum;& L3 S! F5 S; f9 R* A
if(j>0)9 r4 ~: D* _* S6 ]; Q# ]+ s
{. ]( P$ V4 W6 J1 j8 c' J( w
if(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed
7 r" I1 Y# t( s$ L8 n{ z" ]) e9 P: ^9 ?5 J
(*memory).p.flag=computing;& ~, F/ }/ F0 i/ I
(*memory).p.ioNum--;
, j6 H/ E+ a: Vchange += exchange_IO_Compute;" O' C. M1 m4 w) `6 C" `
}: S3 s% v# y( n% ^8 H
}
- s0 C& o8 Z3 o- F9 z" Z5 `2 A. y}
: p8 b0 n% G1 A+ H}
9 Z' D+ ^ u; J& n1 _/ afor(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程6 I m" F% h$ c
{" W2 Q, L. q2 {. @- H. s
if((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed
0 c5 p8 r X" j/ T{" C: e% A- H9 m
(*save) = (PCI*)malloc(sizeof(PCI));
( [& G) g. D; J: ^(*save)->next = NULL;
, L/ |. r9 h8 _, Y4 h y. {6 H2 d+ V (*save)->processID = (*memory).p.processID;, u4 k9 T- D$ P. z3 g7 F! y; ]
(*save)->comeingTime = (*memory).p.produceTime;
# e' U ^9 w7 ]* v(*save)->askMemory = (*memory).p.askMemory;
' k8 M, r' [7 I5 I0 ^* G(*save)->compute = compute;; Q# Y7 C" Z* R# S1 ~" a4 }
(*save)->waitio = waitio;
0 x9 T/ n( F9 H, C+ r(*save)->exchange = change;: o8 E2 ]% r) r& ?4 J# s' f3 l+ b" s
(*save)->completedTime = systemClock-(*save)->comeingTime;+ |! B t. ?1 _4 S
(*save)->runningTime = (*memory).p.runningTime;4 |. \# b$ w h- _
(*save)->completedTime = systemClock;
0 d) n" R. B; N; U7 \*spareMemory = *spareMemory + (*memory).p.askMemory;
4 l9 I. l, ~; d T3 ^# q3 Vcompute=waitio=change=0;1 b8 O# s; Y: P# u( Y
computeLast=waitioLast=changeLast=0;/ P c4 R) c( d- F. c- Y/ |
if(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入* k4 p; U( Q/ Z; I4 f7 _
{# d& {% Y1 z Z4 K
if(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程
- @: ^) f, v. p- ^* z. s1 A{) u0 L3 j9 J3 T9 v" Z; X" H
poi++;+ @2 l) J$ l0 }
clockSegment=2000;3 y- |4 h' _# f1 Y/ _7 s
}
0 b( n! \' P$ h" ~0 d}
* V# C5 I) L9 j; x Uelse //没有足够内存调入新进程
: U% b1 [8 B% [7 k7 b- K8 ?9 M2 v{( O: J3 N, q) w9 ?8 E
if(i < (*memory).proNum-1)
3 [; h2 A5 X2 h- {; _{
( @, Q' l$ E* t( b) c" C9 k5 i8 Ofor(j=i; j+1<(*memory).proNum; j++)
& H! K' O. W* I P6 |{# h( J) E; E2 R1 }8 x! e. r. T# G
(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;
; N( |. k5 D& k0 n* y7 {6 h. A2 E(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;( ]8 a S2 r3 k+ K
(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;
9 ~* ~, ?2 N+ q, a(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;
% N2 b2 a4 A8 v" w(*memory).p[j].processID = (*memory).p[j+1].processID;
+ O9 g7 l; b+ _2 \(*memory).p[j].flag = (*memory).p[j+1].flag;
5 n1 q0 t" a7 ^& J/ @& N4 o, t(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;
$ [9 C1 q1 k0 K6 M! w1 ^* ~(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;
! H$ x. |; I" E$ U2 }(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;9 O3 p. D& p. `+ g) x
(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;
# q; Q* N- Y& O( d+ F# \(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;
7 g5 H' N o! I& H0 Vfor(k=0; k<(*memory).p[j].computeNum; k++)
, Y$ ^# `' J. q; S* }(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];
: R1 G; S' w! vfor(k=0; k<(*memory).p[j].ioNum; k++): T, e1 C4 X8 j T( f
(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];& Z1 l5 u$ X3 L: {: \, }
}1 k! S% z3 C6 X' }6 Q4 E `
if(i<poi)
% S" P2 k/ U3 S8 {( w' l: xpoi--;6 A2 s+ H) J7 b. u9 v
else if(i==poi)
* f- b6 p: p4 Y) yclockSegment=2000;: S* p1 A7 _% U
}
# E1 [/ m B9 j; N# N+ k& Ti--;% ?4 t% f; k5 G
(*memory).proNum--;4 M* B" `, [2 R2 \: t
}
( @0 M! a8 v) _: treturn task_completed;
, O' E# ?& `( Z. S; a6 {7 X}
" s: o% }+ j0 P9 O! L}4 G( [7 `$ L! h* R% X' i
--clockSegment;
2 ^: P& s9 X: Gif(clockSegment<=0)
: N" N3 H" N Q/ H{
# y* N# J( a; g. s! ipoi=poi+1;" J3 G9 r: x- r; {, ]) a
if(poi>=(*memory).proNum)
8 Q" ?4 e% K! z1 X3 x# z* Npoi=0;
: X( [; e+ B6 @- h; u' v SclockSegment=100;! _, [# l D. |9 g1 ?/ t
}
1 @) P5 |( g! o6 k7 `* ~return task_not_completed;
9 Y8 S& J9 G6 g1 O- }# @9 c}% B: u. Q g) U( Q8 W' D1 D9 J
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)# |* q- q: r- I6 B, n% g9 H$ Z
{
5 Q6 N2 Z O# w. K! \- h5 ^int i=0,j=0,k=0,flag=0,translation=0;
1 w y% A6 ~: h7 J. R, a' \0 C5 i5 Jfor(i=0; i<(*storage).proNum; i++)
9 F5 {: x N4 _) t0 W, `{+ m' H5 c( \$ W4 S& p1 j7 W m
if((*storage).p.comeingTime>MAX_COMING_TIME)
* D: [4 C( V, V7 Z2 D5 r# h C1 l9 IMAX_COMING_TIME = (*storage).p.comeingTime;# f3 f R; T: |" B- O3 T& _# w
}/ L3 W8 T* [ d# M# c7 v, c
if(pos>=0). t; `1 ~( q% o5 S( G- D! X* k
{
8 `& B" O* ?0 Y, lfor(i=0; i<(*storage).proNum; i++)
; z3 j8 o: s: U3 M{
" X0 V. X- o8 j7 t3 yif((*storage).p.askMemory <= *spareMemory) `% U0 Y' Q( r3 h, b& k) I
{$ S; x8 M" R& g/ T6 ?
j=pos;
^1 d% R: N. o# C(*memory).p[j].askMemory = (*storage).p.askMemory;; z/ w, u7 M/ U
(*memory).p[j].comeingTime = (*storage).p.comeingTime;
- K3 y6 a9 S l( ~: W) p4 B(*memory).p[j].computeNum = (*storage).p.computeNum;' r% c: W# x' o+ {. L
(*memory).p[j].ioNum = (*storage).p.ioNum;+ D$ ?1 Q' J% Q0 C6 {8 s7 f
(*memory).p[j].processID = (*storage).p.processID;, T" Q; q* Y% F! D% `& ~
(*memory).p[j].flag = (*storage).p.flag;
) v J+ j/ G* T) M2 }) _(*memory).p[j].ioTime = (*storage).p.ioTime;$ V9 N: W7 B6 b, D: v4 z
(*memory).p[j].computeTime = (*storage).p.computeTime;6 T, Y2 T# v8 _4 M; }
(*memory).p[j].runningTime = systemClock;, t& O3 o+ G: W7 v% W
(*memory).p[j].produceTime = (*storage).p.produceTime;
) J/ v; A, w# ^0 A* j+ Ufor(k=0; k<(*memory).p[j].ioNum; k++)
4 D( Q! K+ b) K9 b3 z6 s(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];( m" f! n: F) W: Y( i5 O
for(k=0; k<(*memory).p[j].computeNum; k++)
9 |6 N% e0 M& j) F. S4 W: c& z' @6 z(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];: w: w) I* P6 w% H9 |4 f
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
5 H3 Z; v% ?4 M3 oproduce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
5 y& C5 V* Y! t: N7 pMAX_COMING_TIME = (*storage).p.comeingTime;
0 ]0 l: j/ s; y- e7 i8 Z5 dtranslation=1;9 d) B- a4 X( k7 k5 ^5 M
break;- r4 f1 K9 g l
}
& @* i% A1 Z" N, a7 ?- `+ L. ~- P}
. u$ O. W- D2 I5 D}% c& P/ O7 L9 d
else
7 Z) r0 G7 Y' S{, S0 d! Q; W% A9 _' h) l) U
while(1)
/ I! V! I* f8 M* P. }/ b1 S{+ m$ t* v* a3 j4 ?7 l7 O8 C
flag=0;
4 x" t- S' n* J t- Jfor(i=0; i<(*storage).proNum; i++)7 J7 A) M3 ?+ m9 S) |9 u9 o
{" A! Y X. z6 [; X
if((*storage).p.askMemory <= *spareMemory)# p7 D9 E9 e8 b
{
5 a& x3 M- h& o5 |) aj=(*memory).proNum;
; J( X+ t7 D c6 Q1 `1 \( _(*memory).p[j].askMemory = (*storage).p.askMemory;
) P2 L1 Q5 i" j0 O4 @, p0 L7 y(*memory).p[j].comeingTime = (*storage).p.comeingTime;
% I2 V" i' b6 w) o(*memory).p[j].computeNum = (*storage).p.computeNum;0 {% _' q; ]6 m: a3 t0 ~* _- B
(*memory).p[j].ioNum = (*storage).p.ioNum;, I5 q7 P3 g. W& T% Z
(*memory).p[j].processID = (*storage).p.processID;, F( z. j' R' ^9 G0 T
(*memory).p[j].flag = (*storage).p.flag;9 w! Y0 G3 G2 a4 T& h
(*memory).p[j].ioTime = (*storage).p.ioTime;3 F! r1 y* i: o3 |- P. o
(*memory).p[j].computeTime = (*storage).p.computeTime;
/ b9 g; @- o4 S% M5 _(*memory).p[j].runningTime = systemClock;5 d. O- J! V9 ^ N
(*memory).p[j].produceTime = (*storage).p.produceTime;
6 N2 U! q+ C0 _. }9 r5 ofor(k=0; k<(*memory).p[j].ioNum; k++)+ M9 i( a( ]- @' A; V! N0 \# q% v
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];3 l! c0 c( y' K
for(k=0; k<(*memory).p[j].computeNum; k++)6 N( j! j- J8 ?# V7 H7 ^% p
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
& q; B8 E3 M5 j(*memory).proNum++;
) \7 ^$ w1 j) c, _# P: t*spareMemory = *spareMemory - (*memory).p[j].askMemory;, i% Z4 j( _4 J u5 c/ o
produce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
2 V! N% E4 ~$ h; J% ]6 i- Z) Y% iMAX_COMING_TIME = (*storage).p.comeingTime;
" R& w% Q1 F, e5 Dflag=1;5 s7 w5 L. g ?& X, M0 l1 R: p
translation=1;
3 J+ S3 C# J0 u3 E}; J6 X2 p6 `" R3 e V
}$ j9 A# C- I$ Q h0 |8 U
if(flag == 0)% Z9 w: b, [( G+ i' l! d
break;" m% a* T% B- T$ f
}
+ R& R; V1 H6 e U# p% q}
4 m0 T+ ~# l8 [ e6 V# b+ [6 Hreturn translation;; b( t1 v% v5 w* E7 I8 ]# V
}) }* c+ y; ?+ b8 D) [
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)
6 S3 s! c# j3 r{3 \/ n; P0 L+ n5 I* w9 k
static int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;4 x: v! A! }+ ~
static int computeLast=0,waitioLast=0,changeLast=0;
4 r* N) p6 J/ \) Lint i=0;
/ Y {, A) C0 S" y- N9 f, F5 Nif(draw==1), v# v8 j9 f. j G! f* s0 \
{
: b2 d) k) g5 ~# X0 ]/ W3 B0 f* ~//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);, l+ Z; v* Q' @7 ~, U. x3 f8 u
drawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);/ J8 T9 {, k0 e2 b
; _, ?% K3 k$ Y( t
. z; `3 O1 _- e: J5 o2 d4 H
computeLast=compute;
: m9 Y6 d) B* A3 W. v1 ]0 H: SwaitioLast=waitio;+ b1 C; b& z( `1 h; g/ P- j8 g/ W
changeLast=change;
( _. {: ]; z# j; ^. {8 I/ b }}
; h0 _; f0 e) T3 ]2 ~if(flag==1)
, m$ d# q" v% j+ ?) v: _{
, E; x8 `6 q+ V# d4 Z2 rif((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed7 b9 P/ m- u: F! J
{' I0 D0 G2 n$ z- [* M. F' L
if(flagiocpt==0) // implement compute
& D4 X1 |; Q# J1 _7 T{
8 x3 }, l; q2 v; u7 j4 X5 h: |7 pi=(*memory).p[0].computeNum;) W ^/ P; b( C7 X! W3 u
if(i>0 && (*memory).p[0].computeClock[i-1]>0)3 g& B% F$ V1 Z/ d1 H* k
{( P# @6 |) q9 n& _) g4 _% U& j( k
if(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed
1 ~6 V+ \& }$ \+ B{# R% J, R8 o" ]" L5 ]
flagiocpt = 1;
2 F, t, {" K% Q" M a# O(*memory).p[0].computeNum--;8 r+ C$ C2 O. s. O7 X
change += exchange_IO_Compute;1 V$ J* B' D% d; n
compute++;
* M$ n$ X0 i& j, b}
W4 \3 s# \6 [2 Z4 D8 U8 _else" T" o4 {0 E6 U: t Y `: Z
compute++;/ y9 M7 B( f+ K
$ u) b( ]0 ^: ]- B
}* Z% s/ Y/ P; G1 U- M4 a* \9 `
else% O( {% l+ I0 ~- H; }/ d2 r
flagiocpt = 1;% ~% I$ i$ [. }" y/ L, p
}. O7 e- K. h0 |) I" T, d$ _
else //wait io
# V K' z( Y* Q{7 Y- R4 }! v8 s& [* O5 o
i=(*memory).p[0].ioNum;7 Q4 E# L4 V; z! E$ K" E
if(i>0 && (*memory).p[0].ioClock[i-1]>0)1 g8 A& |; q) W
{
8 Y& c! [0 Z$ a R, D: e) N) lif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
% e; ~7 l' k4 G) D2 x' D. I{+ Z7 a4 |% R3 ^, @# S3 r, Y
flagiocpt = 0;3 A5 u9 }, e) ]0 [: b( E6 \' W" J
(*memory).p[0].ioNum--;
4 N H( e0 ^4 z+ Jchange += exchange_IO_Compute;
, t+ p3 W3 b5 ~/ t, z# `waitio++;2 Y* ^' u; W, ~% `9 c
}
0 @$ ~% z' s5 e# K( p7 Oelse
9 ^( i7 |; W- |1 v4 B: Jwaitio++;
, o3 ]' S3 D! b2 L' Q
! n+ L/ D5 L- A9 {" W}& v, l) q* K, {
else8 R9 W( M8 J+ z
flagiocpt = 0;
3 K9 n) i; _ |}
& _! b$ C" t4 ]! r' Y5 J* X [}
; r$ {7 l1 T! T2 ^ z) welse //task is completed% g& {( u5 N( o. c: Q6 F
{6 @ P4 b ^. L( p
(*save) = (PCI*)malloc(sizeof(PCI));7 U$ k u2 N+ u O" t/ w
(*save)->next = NULL;+ B6 e4 G1 [/ [7 Z7 d
(*save)->processID = (*memory).p[0].processID;
8 _9 m4 w) ~8 Y7 i6 k; |(*save)->comeingTime = (*memory).p[0].produceTime;( a( p4 y k, |3 z$ {8 W
(*save)->askMemory = (*memory).p[0].askMemory;
3 r8 x4 a5 i( } _ ?2 q(*save)->compute = compute;* V* H& |4 W' u. J/ o- R
(*save)->waitio = waitio;
$ j! w5 G6 [3 w" q(*save)->exchange = change;
& ~* y' _% B8 L- d(*save)->completedTime = systemClock-(*save)->comeingTime;5 ]# K" A9 U# |$ _
(*save)->runningTime = (*memory).p[0].runningTime;- J d& M6 ~, X) X, V+ d
(*save)->completedTime = systemClock;$ a, [% e4 W6 L- h6 j
//*spareMemory = MAX_MEMORY;8 j% B4 s# U! w! C
free((*memory).p[0].ioClock);4 M% u+ R2 C# M: j0 E
free((*memory).p[0].computeClock);
$ J9 n. m) @4 Q* S, \free((*memory).p);
( a4 S8 P! A w' t. E) K7 F: L; Yflag=0;& s& k0 a7 A2 B3 ?/ G: f" J4 S
compute=waitio=change=0;
6 l5 u: M7 ]0 [8 u1 R5 zcomputeLast=waitioLast=changeLast=0;
/ n, S* ~) Z! kreturn task_completed;. h7 _" w3 Y2 ]/ a
}
6 a1 y, U+ @6 L1 r' ~5 ~3 ^} Z; O0 |4 U9 P" R5 ^( t
else
/ v( q( O# ^" G9 n3 V! G ^+ A1 Y{
7 \% o3 t" O3 Z! ]FIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));' O9 v" m3 m8 ? f
change += exchange_process;
0 k7 d& k8 n1 X$ b' M- p//*spareMemory -= (*memory).p[0].askMemory;
\1 Q& Y" O& T6 v) Yflag=1;% g' w8 S( ~2 I% c
//showProcessInf(*memory);
: x/ s* F5 i/ K4 t* d7 S1 Dreturn task_not_completed;/ J) N6 E# A4 \& N( h- X+ S
}8 O- ~" q' w9 `. R3 x; @
return task_not_completed;
5 O: A; I+ A: f- p3 D# ^. S+ B$ j}0 \: E& m3 B0 v- w! k1 H0 e& \
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)
) R2 E1 _' W. ~{) ~5 `, V2 v. {) E$ d
int i=0,j=0,k=0;
& N: R6 k- J% \: FMAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;
. M* P, x& f' @' w7 C% \7 y) x5 ?(*memory).p = (process*)malloc(initProcessNum*sizeof(process));5 k! a* A# I( X6 i5 Z- J
memory->proNum = 1;$ K( v: T9 o* y; X; K
for(i=0; i<initProcessNum; i++)
3 q1 x) z3 w( |) X, x1 {- k{
7 r% k& F7 w$ J% rif((*storage).p.askMemory <= *spareMemory)
- K$ ]% z' N- m3 `2 a* H7 b; k{2 H8 x9 f2 M' F; D& N5 H
(*memory).p[0].askMemory = (*storage).p.askMemory;
, Q8 I6 h, P$ [( O5 S# e5 M, R. r2 F8 t(*memory).p[0].comeingTime = (*storage).p.comeingTime;& X, `7 ?. t. T1 J0 I$ X3 B7 @
(*memory).p[0].computeNum = (*storage).p.computeNum;6 H1 T. j7 u* \0 a5 O
(*memory).p[0].ioNum = (*storage).p.ioNum; p; `# f8 M( E' Z/ \3 }2 [2 X
(*memory).p[0].processID = (*storage).p.processID;, _) ^1 E0 B. s+ w
(*memory).p[0].flag = (*storage).p.flag;2 e) O4 ^. p1 O
(*memory).p[0].ioTime = (*storage).p.ioTime;. ?0 g8 \% s: U) H
(*memory).p[0].computeTime = (*storage).p.computeTime;4 H7 g# {/ p) s4 {
(*memory).p[0].produceTime = (*storage).p.produceTime;
# J% ?6 E+ G6 w% B+ }9 S" p, u$ U(*memory).p[0].runningTime = systemClock;6 W( c) a' b( l; v
(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));4 U ~. I5 v0 B) T7 D0 q
(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));
; V% f r' I) v ffor(k=0; k<(*memory).p[0].ioNum; k++)4 Z9 X+ k' l% {& p1 a. I
(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];" M5 s; R0 @1 S, K8 _
for(k=0; k<(*memory).p[0].computeNum; k++)2 `, v/ s+ x3 E+ k( P0 e* h; f
(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];3 B0 H3 l- _& i9 m) ]1 ?) C
break;
1 O4 ^- A$ s- l- p6 S}
6 R5 l) j4 o- X) @}
0 g: T. D. T2 _2 Aif(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入4 z5 K' R1 f4 ~
{" W+ v N6 a0 d
produce_one_task(storage,i,ID_FIFO++);- P) j% U2 g) H4 C
MAX_COMING_TIME = (*storage).p.comeingTime;
& O" o' t2 E' U1 ysort_by_comingtime(storage,i);2 w( m! K+ T' U
}4 q8 {: R, p& M, {; F: Z
return 0;* O) c1 U- Q J9 C2 h( C- w6 V
}
4 z l7 K6 ?5 D7 ~: Lint sort_by_comingtime(processPool * p,int pos)
v9 o8 N8 d9 n6 l M o w{
: i% T" o0 M' H8 U- j& X' `8 uint i=0,j=0;- E* x \ s) q n. H9 m
process temp;9 N2 N) Q+ l0 D$ q- I; B: O5 ]* u
if(pos<0). J# @- J: F9 N6 T
{" Y0 k" m2 H( W) C4 m8 A I+ Z6 u
for(i=0; i<initProcessNum; i++)- o. w* p8 g0 I g% {1 H9 c
for(j=0; j+1<initProcessNum-i; j++)
/ i& |' l9 ?9 [{! ?7 n% ?" i2 l* K3 U- E. }
if((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)
# W0 F; ~5 x5 G8 @9 _; D& V7 T{
. m" q- Z+ D8 p4 G9 Wtemp = (*p).p[j];
5 Q" L" P& _: D( l7 F) {- t% U(*p).p[j] = (*p).p[j+1];
5 ~+ V3 Y4 M, r+ Z/ v+ _! \(*p).p[j+1] = temp;
/ v' R2 [) {4 h" Y. {}
0 J7 | I& K5 t3 G0 n9 Z}/ ]4 i+ m" _7 ]6 s; x
}+ V; p6 `( b. l( s( P
else if(pos<initProcessNum)
9 ~! j$ K) w/ r1 j( Y, z{
/ X9 _0 ]& }6 Cfor(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)
# l3 G7 O, j2 g r. g9 p+ L) ^{
' S+ {0 U; f$ l5 y& Qtemp = (*p).p;7 f) V& V1 A& t9 z( R$ m
(*p).p = (*p).p[i+1];
: ]: v' b2 u0 x0 n% k(*p).p[i+1] = temp;
+ c K& B: O; u; b. h5 V7 ^/ d: c8 V% y}7 y4 H, B! d3 W2 n8 I
for(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)7 Z; v" a0 \' D y
{
, u+ h+ i6 W+ e2 gtemp = (*p).p[i-1];6 f" S* e) R) Z
(*p).p[i-1] = (*p).p;
$ G$ ` `# W" M2 b8 E(*p).p = temp;$ F$ W4 U; [/ y7 p: ?
}: z* H: j3 O4 v* d/ c6 f F& Y: `9 r$ h0 \6 M
}, w$ G B% W; Y/ c
else
4 C0 A/ f0 H- q. J% W& mprintf("position eror\n");* N3 X, h e+ Y F# O8 l
return 0;6 T7 B& g2 h8 j% T6 j! w
}$ X L6 X$ F9 J/ q4 @0 b2 w
int InitPool(processPool * p)- [- z1 W& y# w/ Z s1 n# h+ |; x6 q
{$ Z8 e. t0 [8 p) H
int i=0;
6 C' @: D: h- y3 O6 E2 p(*p).proNum = initProcessNum;, \% ]7 r% P- a5 _8 Q
(*p).p = (process*)malloc(initProcessNum*sizeof(process));' }7 @, k7 o2 g' s! ~! E
for(i=0; i<initProcessNum; i++) //init process information
/ @. l! l, _$ y! o{
( w# i# |! X$ e& k. F: a0 ~) w(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));
' j; G) y7 U# w& U' a) F(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));* B+ Q$ c( ^0 W- n
produce_one_task(&(*p),i,ID_FIFO++);8 Q, k* b! ? C. } }) V$ W" j
}, H4 a! A- ?& u9 }
return 0;
~# }6 ^" t; s+ T* E$ w}
7 O" y+ z" K I3 C1 f# u8 gint produce_one_task(processPool * p,int i,int id). m/ m* K$ u9 b5 `1 X4 ]/ o" B5 T
{
$ W9 ?! g; X' h) tint time=MAX_COMING_TIME,j=0,totallTime=0;
6 o8 `1 V* O0 T1 @& I(*p).p.processID = initProcessID+id; # k+ v8 H( R, X2 i6 x* s/ z
(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);
8 e& V9 i+ a/ z6 j" E/ {2 i% E(*p).p.produceTime = systemClock;
* j! O+ h6 E5 K4 @3 N$ f6 P: m(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;3 E' R' V8 `# a# z( O! P, ~ I4 Y' z, C
(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6;9 c# I1 a- B% t+ v, _" G
totallTime = (*p).p.computeNum + (*p).p.ioNum;
3 I3 y; R _5 q/ f( u( O; u( E(*p).p.computeTime=0;8 e- `% z# s O B) C
for(j=0; j<(*p).p.computeNum; j++)9 N0 e4 d- R# d) W. u) q
{
$ E5 l1 _+ ^( r% C4 \(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;0 F! w4 d8 I9 J0 j% J4 y$ K+ F
(*p).p.computeTime += (*p).p.computeClock[j];; W8 d0 ?) _- G5 \, W
}
% ?9 E1 t) `! q" A3 R4 t1 M(*p).p.ioTime=0;
5 H" s0 d; r) D* _5 r; Qfor(j=0; j<(*p).p.ioNum; j++)& b) B! u. B4 N; N& V0 c7 Y
{" v$ C: Q& U, {4 V, e* h
(*p).p.ioClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;- _% F: g2 j6 @) I1 G; \' ~
(*p).p.ioTime += (*p).p.ioClock[j];) P& O5 V& Z/ g4 t4 u6 s
}
; t1 r; [$ D# N; A" t- ^& \(*p).p.askMemory = rand()%(MAX_MEMORY/4);
$ v9 _* r/ g, U$ ~(*p).p.flag = ready;
: U1 D& f" F# i* c) e3 w& Lreturn 0;7 l. \) p+ q1 p# W3 }
}9 @ K- ^! {3 y: D5 G
int showProcessInf(processPool p) S0 n* o1 q" ]
{
! V/ e0 {3 I) p4 ]- l/ _7 Eint i=0,j=0;
5 [2 Z# C& m; E& q; u- f. p) }1 Sfor(i=0;i<p.proNum;i++)
B3 A* |- {8 U3 Z7 j6 c8 j{
% n6 N' B" u6 e3 k9 \) g Wprintf("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+ B- s5 ]5 T0 w! A6 z
,p.p.askMemory);
4 |4 N, n+ a& j7 l( d& xfor(j=0;j<p.p.ioNum;j++)& F% j6 A9 N3 K; V. m( _
{
3 v( ~; V* |0 Z# q, F( Sprintf("%d ",p.p.ioClock[j]);