- 在线时间
- 1630 小时
- 最后登录
- 2024-1-29
- 注册时间
- 2017-5-16
- 听众数
- 82
- 收听数
- 1
- 能力
- 120 分
- 体力
- 563412 点
- 威望
- 12 点
- 阅读权限
- 255
- 积分
- 174246
- 相册
- 1
- 日志
- 0
- 记录
- 0
- 帖子
- 5313
- 主题
- 5273
- 精华
- 3
- 分享
- 0
- 好友
- 163
TA的每日心情 | 开心 2021-8-11 17:59 |
|---|
签到天数: 17 天 [LV.4]偶尔看看III 网络挑战赛参赛者 网络挑战赛参赛者 - 自我介绍
- 本人女,毕业于内蒙古科技大学,担任文职专业,毕业专业英语。
 群组: 2018美赛大象算法课程 群组: 2018美赛护航培训课程 群组: 2019年 数学中国站长建 群组: 2019年数据分析师课程 群组: 2018年大象老师国赛优 |
' z' ~8 n- X5 S5 `
经典任务调度算法的模拟程序
% T- Q7 S" L9 f( e) B本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。
) d0 n, G! n+ Q& a2 o- |
. u. \/ G+ H( y- q( J' }编程平台:VC6.0+EasyX图形库环境。7 n! o3 ]1 u3 P/ R
) F8 x( x) w( o s( r: ]/ e& k以下截取部分程序运行图::
2 D: B4 Q$ z3 O1 ~3 C5 K" a7 f6 q8 s/ [0 ^5 O* X
源代码:' N3 N0 ?: ?: d( P/ w! |5 D8 J! H& ~
( z& O5 `4 s/ M#include<stdio.h>
' p* G8 G$ q9 t' O5 M#include<stdlib.h>
1 p" G4 J% v; ~6 {3 R/ y#include<easyx.h>; O8 e) v$ u. ~ p0 U2 a
#include<time.h>
8 W9 ?) J% x* D+ }+ o2 P4 A" \#include<conio.h>
1 i4 ?" a. }8 |* f) S C#include<graphics.h>$ I- H4 i! J. i
#define initProcessNum 10
$ ^ ]- n# q! c7 E#define initProcessID 1000
: D$ B' s0 ]9 s#define MAXProcessRunTime 10000
& k; q/ j* V9 t. u' _$ X#define MAX_MEMORY 4000% K8 N: H+ P' x
#define exchange_IO_Compute 107 m' T6 e) a2 ~# t
#define exchange_process 25
! m7 k6 c+ b2 |) J+ N/ h* k#define task_completed 19 K5 l3 w2 R- @
#define task_not_completed 0
$ J1 O$ Q# \, _9 V0 f#define initclocknum 100, h: E7 }- X& e! g
enum condition
% ^/ k$ P7 x9 n1 P ]{' E" Z d3 o) J4 E! ?" `9 R' w* m2 `
dead,computing,IO_waiting,ready3 R( g! X4 C ]8 I0 \. C
};( g7 f! Z2 b# I4 i( W; W7 l
struct process
: R! a7 }( H/ y{
" s0 N* j: ]% E9 Rint processID;
8 b; R; O. D. C- _int comeingTime;
, w. K) N4 \! V$ x7 r. W8 Jint ioNum;3 u, @1 w% b/ e. p
int computeNum;, [% a7 I/ U3 L5 I" H) x4 d
int * ioClock;
& R% ~" }) m% q$ ^int * computeClock;) N% H+ R" I$ M. v" J5 g
int ioTime;+ s- q2 b- s+ ?5 G+ n
int computeTime;% P4 X, ?7 i2 N! F; y7 t8 C$ [
int askMemory;- _( d0 S) }/ _
condition flag;
7 n" g0 ?$ B% l0 D$ n4 Uint produceTime; //生成时间,以下三个数据成员用以计算相关性能
% Y4 n7 _; R) uint runningTime; //第一次占用CPU的时间
& u# R: w3 q' G" b% q1 Aint completedTime; //进程完成时的时间
$ n% C/ v$ l' H* e5 a- c- I* f3 G};
- C X! h! ^/ F8 e3 Z+ `' q1 [typedef struct processCmpletedInfo //保存完成一个作业的相关信息
0 u- u4 w9 V# U- ?- d6 F& v{
7 h$ {5 D2 S2 N. c6 H- Sint processID,comeingTime,askMemory;+ G- n. C2 a- n
int compute,waitio,exchange,completedTime,runningTime;% U& n% C9 g' P5 y# q2 z
processCmpletedInfo * next;
' M0 ~6 o3 ^$ N}PCI;
* E% A$ `8 W2 l, ^! d* E2 x0 Estruct processPool
. l! S n% U1 I: B: T{( o- V! {5 ]5 G) N7 i5 i: O1 ^: T
process * p; S4 U) m! c- Q
int proNum;& y/ K* w0 u7 J S( q
};
# K+ A+ v, q6 U9 {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;7 X- P6 v8 O$ F
int InitPool(processPool * p);' Y3 S" _, j% I. f
int produce_one_task(processPool * p,int i,int id);
! o/ q/ O G5 D, m1 e7 s+ cint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);
. O% |' ^: ^8 P1 B! E/ i/ U$ q6 Gint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);1 g. e/ K3 I8 {) ?" m H
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);+ o) w, T* k, g* O! Z
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);0 }# W% f$ L; e: M9 T* C) s
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);0 h4 _, ?: ?+ Q* @
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);3 X+ N/ w% u- r: `" F
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);0 z! m& H7 G5 {: }% w* X. k7 W
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
3 b# P4 G6 U! {4 \* K/ @8 Rint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);1 d8 [! B) H7 H0 O
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);+ V/ ^( ~8 Z7 e$ S- X( S" ^ W
% T' t2 O9 {+ |2 v
3 f0 B% Q% A. S1 |+ Lint sort_by_comingtime(processPool * p,int pos);; U! p2 ?5 k7 D1 A# I3 q
int showProcessInf(processPool p);6 _9 _. B! V7 j
int drawPerformance_FIFO(int x,int y,int memorry);
- ]" q k; I# R o, m) u% M: iint drawPerformance_HR(int x,int y,int memorry);* w |! P. Q* P% f( J, |+ }
int drawPerformance_PF(int x,int y,int memorry);0 I0 E3 ?; m$ O+ c2 v: w; ^
int drawPerformance_TT(int x,int y,int memorry);
3 `5 O7 w5 ?' T: hint drawPerformance_SJF(int x,int y,int memorry);
! u$ p8 R) y6 B; oint MouseListening();6 w8 _6 Y D0 z* y5 |
int MouseListening2(int *flagShow,int * showTime);2 Y o/ |9 V' s3 k: H
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);
5 n/ [0 U" `; W
: p0 X$ M4 m) R1 t2 ^: F8 ~; U* A, _# t
void main()
% h" o: G0 Q7 |1 P# i{$ P8 F8 x7 c( b6 Q9 g# ~: y
PCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,
) \2 Z, _2 [& E9 t$ h*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;4 q& i2 [: S# d; A
int i=0,FIFO_memory=MAX_MEMORY,count=0,Timet_memory=MAX_MEMORY,SJF_memory=MAX_MEMORY,Priority_memory=MAX_MEMORY,HR_memory=MAX_MEMORY,$ K& t! H& G3 W% K" u; G& M6 G
flagDraw=0,showTime=100000;: h% z z) |; {6 N5 r4 o/ S% U
processPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;
9 [2 w. b$ E2 z( Z; iFILE *fp=NULL;
0 _& N" G) b' v6 k j//processPool HR_p,HR_mmy;
* U* F* D, O6 m
( @. b0 a) ^& ^7 u" \5 U
* V+ C& w' x. c" fsrand((unsigned)time(0));. { O, h6 T3 {+ N0 b3 u! }
systemClock=0;7 c+ T c! z* v
initgraph( 1200,650,SHOWCONSOLE );
/ I8 ?. M: I' R/ @- w$ {( \settextcolor(GREEN);5 Y8 e7 m; G0 J
setlinecolor(GREEN);
# i, u3 D& Y& r3 R. z/ f' psetfillcolor(GREEN);! b- H1 K5 u- @3 o: q3 ?. O
InitPool(&FIFO_p);* P# X* z6 j7 V& O: C5 d) P
sort_by_comingtime(&FIFO_p,-1);
* s3 A# z* T: Y C, l: QInitPool(&Timeturn_p);# J. t2 ^, f& x, G: t# A- Z
InitPool(&SJF_p);
7 `/ J+ {. U8 g: _: P. [& }8 lInitPool(&Priority_p);$ E! V4 [6 F9 ]5 T X7 B% W
InitPool(&HR_p);
- A5 T1 U5 N+ e( R6 p//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head); @1 N3 F; `: H/ m7 Q" Z
//Sleep(10000);2 a; T1 D( W1 J& N5 J
) l/ C, G. u: b* E
4 T1 d2 A: h% P3 YTimeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
) a1 W1 M5 X# H/ i! SSJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));) X; j( j }9 I8 R$ y5 F! [6 p+ _0 L
Priority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
( E% E/ [6 V4 q- k7 j) a' \0 d7 ~HR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));, V9 X* D+ Y1 z6 _7 \
for(i=0; i<initProcessNum ;i++) B- X; m& U) y& H
{; v* ?! }. o% t/ a: M* O
Timeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
# ?8 h3 r& c1 W0 CTimeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
" f- U+ a G6 r- I7 f! zSJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
& `# x6 {& z+ l9 `( s/ j1 R% R: m7 h* ]SJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
! B+ g! e% C9 ?. |! q" p2 hPriority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
( |' l w( G* G: |8 A& j3 mPriority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));6 l+ V6 E( ^, y% s9 V9 b0 n6 f
HR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
& l) I6 ]( I; i; E: rHR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
& x; F& {6 C. c+ n. b" r" k4 z}
: m* O3 o+ M2 D( ^' y+ C7 J: oTimeturn_mmy.proNum = 0;8 N" y2 q( f' H8 C1 m- ~/ ~: h" }0 L
TimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);
3 S2 R$ G0 @4 P6 r: a/ dSJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);
. b) w1 p) @3 S2 K$ h6 vPriority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);
$ d) F/ G, E, QHigh_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);$ R7 ?* k' M% v5 g
//showProcessInf(Timeturn_mmy);
8 A" s! v2 p1 T3 l, J* U4 p9 U" xFIFO_pri = &FIFO_save_head;
9 t6 f5 d; A% X# R) b3 wTimet_pri = &Timet_save_head;
- m$ G9 F* O; O' N% o+ u5 U" eSJF_pri = &SJF_save_head;7 b. V' }1 W7 F5 J% C
Priority_pri = &Priority_save_head;* i- X& [& P6 O7 w# }; E: ]4 X
HR_pri = &HR_save_head;, k- Y% U# {- D" ]% k3 j
setbkcolor(WHITE);
1 u% Z! V4 H& I! hwhile(1)
, P7 }. h4 t, w+ ~( c; O. i' }( `& v{
9 n5 j: H% O/ f2 R" pif(MouseListening()==1)$ p$ ?3 Q* \. J# G
flagDraw=1;6 q- r, q( _2 x0 `7 o) x
if(count==100)
' {( r. P2 N, W+ F0 X7 e; }{ t: D5 l6 T( P6 \ |
if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed): z& m" W& d8 K. I3 f
{2 L, _. C- U% H7 p; U5 e% i" G
FIFO_pri = &((*FIFO_pri)->next);
+ V4 S' J L9 v/ ?$ Z. }! v6 E) K
* f$ q! d, N/ }3 U0 ?//printf("hello");& Q- C1 @4 m4 s3 \6 m" m# N0 Z
}
; F6 Q' ]8 l" pif(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)4 g1 I" i3 s# r7 U0 Z/ }" B
{% W1 n ~4 j I9 _2 R) M. y7 @
Timet_pri = &((*Timet_pri)->next);& G3 x( b7 H8 ~- s+ ~
//printf("hello");2 K0 k+ F/ c4 w6 C. m
}0 h2 B# W( ]1 q( o. [- C7 s8 V
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)/ |( T& D2 x' s8 ~* s
{
- r+ z. C2 w8 l ^4 fSJF_pri = &((*SJF_pri)->next);# ?! x" G* `3 N, L* ~; e4 c# \2 N
//printf("hello\n");
1 i% P9 x* I: _% S0 d}
. M6 t7 Z6 N- e* jif(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed): j! V0 B( p4 w7 Q
{; R! @6 r" V# z" e& J. V( \
Priority_pri = &((*Priority_pri)->next);' t- \/ B; ~4 n
//printf("hello\n");4 Z ^: W* C: @6 `% L c! _: [
}4 e/ M R' \6 X' b
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)
0 d8 M( T8 k- ^5 j: X0 `" c{ }/ p5 S: [/ O; l2 ~* z8 c( M
HR_pri = &((*HR_pri)->next);
- _9 W/ g0 Q% x//printf("hello");
# y; X" q! y" y}
5 M+ h, Z5 }( M. Wcount=0;. f6 g( s9 M7 `5 h3 W
}+ {0 [& z" I6 i( D/ d1 q* u
else
, X; g8 q k6 U{
1 W4 L+ z% O, y# Cif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)4 Y- ?( ?* ^. c4 o
{3 O( T# ?/ i' s- n! \. M
FIFO_pri = &((*FIFO_pri)->next);
# Z" D, h4 [) ?// printf("hello");; j4 M! b1 z# C8 o9 e
}
6 _( l9 X8 C# W- i( Gif(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)0 |9 ^1 i: I/ p6 @( S& i" o
{4 P+ {! y0 U7 Y- _6 ^
Timet_pri = &((*Timet_pri)->next);/ z! D, c2 z) P4 i
// printf("hello");
9 j! ?* V& Z1 u4 [* R}- c, g" m+ o: L+ @' Z
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)" [1 a2 ~& Y y
{
! P" a6 N3 {3 K SJF_pri = &((*SJF_pri)->next);: i8 \5 i! [: D% h# [$ l! D* T
// printf("hello\n");
1 e$ V4 T D/ O' C}5 F3 X3 R" ^; e5 N
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)
1 b0 ^% z8 R- g& F+ K( z{# t, n2 A3 t! _4 { H
Priority_pri = &((*Priority_pri)->next);; J$ ~1 Z0 L1 x
//printf("hello\n");
' i. ?# \' Q7 I4 ]0 |7 }1 W}
U+ a- ?" T6 L, y* ]' Rif(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)
; C! G2 m' R. e: I{7 w( W! I3 K4 R! P
HR_pri = &((*HR_pri)->next);, y# U% b5 o; `
//printf("hello");
5 e1 S( ?0 x& G: | m//Sleep(1000);
, N# s' v6 y) E, [8 W}% L# q. V9 [) ` f# I
count++;
; |0 w- b$ o. ~ A( E}
- [" d- L! Q9 W" `: \if(systemClock==showTime)3 M4 ?# M: \, ~4 T
{
6 J3 @* ^& b5 ~; y# B1 M/ P# A/*PCI * p=FIFO_save_head;
, u7 A0 |8 N' S6 \! iint i=0;* G' l& E- Q' ~" d( f
for( ;p!=NULL;p=p->next)
+ N* j4 e4 `0 P5 O- Z6 n' Z{
. o) g; `" b3 ^printf("Id %d\n",p->processID);
& d6 r. s6 s! T9 H: d' d6 Aprintf("comeingtime %d\n",p->comeingTime);9 K5 V, E g1 @& A3 V* F& s9 H& T
printf("runningtime %d\n",p->runningTime);7 `, x( x7 \, d# R, A! A$ d& ]
printf("asdmemory %d\n",p->askMemory);
5 a* O- }9 I7 s+ Dprintf("completedtime %d\n",p->completedTime);5 k# z# p( n- _
printf("compute %d\n",p->compute);
1 l; X7 p" @3 fprintf("exchange %d\n",p->exchange);6 @; C4 x8 C/ N& G* L/ }; c
printf("waitio %d\n",p->waitio);7 y* E9 s, r- q
i++;
- h3 {7 m8 p* X& L [4 K% L: _: }8 v0 k- {: f, e
0 L4 x2 r8 _: C N9 ^* x- q
}$ Q1 d$ E# x `% n# i
printf("%d\n",i);*/; z! K8 E& [6 h( M
if( (fp = fopen( "data.txt", "a" )) == NULL )
8 \5 u) O1 X3 {$ p& m8 f1 D{8 k' j7 n; k. z- E& F
printf( "The file 'data.txt' was not opened\n" );
) A+ p3 U* _4 \# H9 _1 f//return 1;
) q/ a0 W& s% D}
# J. L' |& }2 r# W/ pelse
" I _1 ^- O, L8 {" a+ J# ^$ r{
+ E# K# `: t/ V- S; v+ {fprintf(fp,"FCFS \n");
/ O( F, X5 @2 u( T" c# xfor(p=FIFO_save_head;p!=NULL;p=p->next)
2 b2 [) H0 r& ~' g# E0 {$ Dfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
; A) d0 L8 e V" w2 U# y# Ep->exchange,p->waitio,p->runningTime);
8 R7 X& z, i% d. Ifprintf(fp,"\nTime turn \n");( H* ^9 J9 _; J4 z5 j
for(p=Timet_save_head;p!=NULL;p=p->next)
* g$ {6 _( m- f# e, Z8 w5 ?2 k/ nfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,$ b3 ^3 |" n0 d1 u$ H
p->exchange,p->waitio,p->runningTime);
7 t* s0 R8 ^' K* y J: M8 }7 tfprintf(fp,"\nShort Job First \n");
' h" M5 G( m. i+ Sfor(p=SJF_save_head;p!=NULL;p=p->next)
8 y4 X+ n! C% {& lfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
. j1 w, f, q% _/ tp->exchange,p->waitio,p->runningTime);
3 ]- G) l% l4 {8 }fprintf(fp,"\nPriority \n");4 o3 k* e" Y' t" K
for(p=Priority_save_head;p!=NULL;p=p->next)$ d7 g: e. y5 z; F
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,& i) p6 O, D& Y( e7 S
p->exchange,p->waitio,p->runningTime);! _' t2 Q' a( R3 N( f+ e# |) D. F
fprintf(fp,"\nHigh response \n");0 G+ H3 |, W% I; P% ]/ s
for(p=HR_save_head;p!=NULL;p=p->next)3 b# c) F" j$ G
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
( N$ W$ Q2 G7 r7 bp->exchange,p->waitio,p->runningTime);
1 e$ u! [, q. ^fclose(fp);! r9 w* U0 t* q9 b: U* a/ g$ }
}; Y0 N! W4 H: y
showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
/ ~8 t+ Q! s2 P: MMouseListening2(&flagDraw,&showTime);: O$ g- d, O$ l2 `; n$ d9 I
}9 k9 }2 K9 K+ w$ B) i9 T; b" I
systemClock++;
' Z4 _/ {/ n& C8 k; h, gif(flagDraw==0)
0 t/ m$ U. t! x Sleep(10);9 A: m! o, M T6 L7 a6 M% O% w$ ~2 @! T
}; p7 B+ x& ]3 ~ _/ [# S. e
2 D; |; U6 O/ D1 s+ j7 {6 J b v7 A
6 I, w$ D: t/ ?. w
}
5 m# v7 r& [1 `/ L, o4 v7 G4 y) vint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)
' J8 v* | i0 J" F- T u{' i/ |9 Q9 x/ f3 O! z2 v
PCI * p=NULL,* name[5];
* S- {# g* K% |/ C6 ?, s1 s+ @int count=0,i=0;
k* X, |2 u: T5 W+ z) C( D" ^char ch[5][10]={"FCFS","timet","SJF","PR","HR"};
6 }/ R O O) Idouble turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};; A2 a; Y6 a0 y% a$ C8 l
struct info, ?8 X- s" `$ t2 Q5 X6 E3 G0 U
{. o+ Z" p) v, x3 I T$ {3 d
char name[10];8 r X6 a/ c: R5 h0 ?! D8 X- r. w) f
double throughput,turnover,wait,CPU_rate;
# G; M" }/ h" w2 n}inf[5];
+ H( \+ w% e3 R" e, lname[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;
0 |) \4 J. f' u; p1 X: H9 \# Nprintf("调度算法..........A\n");
: k( ^- {4 m) W$ L1 h0 c0 k8 Gprintf("吞吐量............B\n");
0 d) D, J* P; X8 D6 p: mprintf("平均周转时间......C\n");
% A5 C9 @: @1 oprintf("等待时间..........D\n");: }( n% n, x3 E; U8 J" W# Q
printf("CPU利用率.........E\n");: R: e& f- g( S3 s8 j
printf("A\tB\tC\t\tD\t\tE\n");+ ?: ^/ n; r# [
for(i=0;i<5;i++)
, ~& p8 U5 M+ t, Q$ ?{3 q1 U- ^, W/ V- |. y' [' }2 u
count=0,turnover=0,wait=0,c=0,w=0,change=0;
C4 a3 y- C- s, H6 Ufor(p=name; p!=NULL; p=p->next)# ^2 u g" R a# @1 S
{
( R, ^6 R3 e0 g; Z& O& {count++;
. Q( O; l" w( J) B; ^turnover += p->completedTime - p->comeingTime;0 J4 [3 d9 b2 Y* ~: L' T. e `: N
wait += p->runningTime - p->comeingTime;. T4 C9 A N" g7 F& @2 e
c += p->compute;
" H% g: W7 |: [3 k1 v+ b4 Vw += p->waitio;
- P" a% t2 f2 \: o8 [5 W N3 ychange += p->exchange;
# C0 X8 c, G _" ^( z}' \2 G4 B: ~+ [8 [4 A- [) A
turnover = turnover/count;
( V7 ?6 v# {* V" W& D6 O# Y; Bprintf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));
3 q9 F) E6 r$ w5 bstrcpy(inf.name,ch);
' B6 U+ c% e/ I, k: }8 x: I6 X2 Binf.throughput=count;
3 {6 y+ q$ @8 x$ Z* b' |0 ~inf.turnover=turnover;3 J) V: G4 n' F6 l; `7 b% H
inf.wait=wait;
* ?- f: q7 Z/ |' r- |6 n: x( ~# }inf.CPU_rate=c/(c+w+change);/ m4 P- l9 e0 `6 T6 S8 q0 k
}9 [& y, K% r7 f# v% Z
//画图
& P8 o! n0 K) K4 E! S c. i* B//cleardevice();1 `$ ^: h* K9 Y9 F
line(0,600,1200,600);
& R+ y" `9 B" G) [) F8 @line(10,600,10,200);, R X O3 U) n1 f
line(10,200,5,205);" t/ v- S( c: J4 Z0 Z. s- u
line(10,200,15,205);( s/ F- c1 G, ?; r
line(310,600,310,200);
( E0 [; ]0 [* R5 O, ~# T9 }line(310,200,305,205);' G# D( H0 A" e% Z: |" h
line(310,200,315,205);
8 K5 M1 M p2 x1 rline(610,600,610,200);1 Q7 \( w8 c% h: Z) t
line(610,200,605,205);
& J2 A1 A" y6 Q) X* g1 S# S Iline(610,200,615,205);
1 k5 \+ F; s7 gline(910,600,910,200);" u/ B6 P4 n5 d! b+ d
line(910,200,905,205);3 R) i, Q6 l7 R4 n: I1 N
line(910,200,915,205);//最高的长度400,宽度均为40
' V, Z* s% C& r# T0 x7 X1 Ffor(i=0;i<5;i++)
8 X6 U z/ x5 U{$ ~: {: r# g9 x! e3 [
if(inf.throughput>pos[0])
8 ]% X/ f0 Q( J+ |pos[0]=inf.throughput;
" w7 N' J+ ^8 n/ w9 {. iif(inf.turnover>pos[1])9 X. w8 T2 A9 ~
pos[1]=inf.turnover;$ j0 h+ o9 \4 C/ e$ ^
if(inf.wait>pos[2]): A2 N* Q+ p5 E
pos[2]=inf.wait;
% d1 b( ~0 w4 l- c3 x5 dif(inf.CPU_rate>pos[3])
- {- e! O6 i8 S8 o) ^; E2 Upos[3]=inf.CPU_rate;
, V% \0 }1 K' S# t% A}' y0 J- L; Z! }$ A( W* y( l
settextstyle(30, 15, _T("楷体"));% a. D" v& P) r. F5 f
for(i=0;i<5;i++)
5 c; G1 u7 P0 s ?% z, i{
$ ?1 A# L6 Z* `# U: R3 }switch (i)
2 g! L8 L! a+ h, n' [3 o; e5 A{* C& M- C$ Z3 a/ d$ w
case 0:
4 N Z( D8 m9 M/ N) N Y0 H* p) n. K" xsetfillcolor(BLUE);
* N1 H$ U; d# f4 }fillrectangle(100,50,150,100);: Q3 V+ C& D, l' \4 C. |4 E" k1 W9 l5 ]
outtextxy(160,50,"FCFS");2 B. [7 T, t6 L [) d4 l1 P
break;% S. j* h+ v8 o7 `# G
case 1:: e1 Q1 T" Y* N5 V7 [+ [
setfillcolor(RED);: g) ^ R. h/ j, | U
fillrectangle(250,50,300,100);& ~4 a& j/ s8 t
outtextxy(310,50,"timeTurn");4 k- m9 a8 b0 Z- N" u6 }- t9 K- q
break;
% p$ @% i; Y5 L" P, F5 U' q7 lcase 2:
* I w* J$ G B- dsetfillcolor(YELLOW);" M8 v. U$ D( S' X) \
fillrectangle(450,50,500,100);5 _3 y/ s4 o. t- B; R
outtextxy(510,50,"SJf");) U- u9 ]$ ]! c8 Y1 G$ v
break;! r/ X0 T/ k& k- B8 p4 h
case 3:" N3 ^3 s Q$ ~
setfillcolor(BROWN);) f5 o4 ~, z' D, [; M( g
fillrectangle(580,50,630,100);
# z4 h7 a/ h+ Q' H1 Kouttextxy(640,50,"PR");
4 r# N& s" S6 f% ]- hbreak;9 k* \: B/ }* E# w9 t+ I/ x9 [
case 4:
* _8 H' P- J1 v8 A5 ~' A- E' ~setfillcolor(GREEN);
% c" w; f i% ^0 q0 s/ {fillrectangle(690,50,740,100);' B, C: o7 g8 N2 r9 d# b$ A' y1 Y3 a+ D
outtextxy(750,50,"HR");. p5 X; U6 R5 j& T1 t5 N1 M3 ]8 n9 S
break;
( }( @; W: h5 _1 `8 y. l}6 ?1 v, |8 @! ?' U4 s! f
fillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);
; `; ^$ X+ L* n7 T9 wfillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);
9 V5 i0 A" e) @2 B$ ~4 T yfillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);
( x! ]. b8 j+ J! c6 y+ I! C' tfillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);
6 k; p0 Q8 U6 L( z! D( g8 a! k$ D, X) e4 o
6 d( A. P+ b6 s* m8 ]' T9 |' c1 D5 Q}. H# N6 K* v% H2 r
outtextxy(100,150,"吞吐量");
+ c3 H& y) U3 p0 e; N q1 Mouttextxy(350,150,"平均周转时间");) k3 a+ V, s" O. [3 n
outtextxy(650,150,"平均等待时间");: `5 A6 c- K0 ~! d9 R" M, `% a/ y
outtextxy(950,150,"CPU利用率");8 G& R! m7 _, O; T% f
return 0;
1 G) W, t/ Z( r2 i0 H3 a# u |}
+ E# F0 w" ?) L6 C4 N: s% n9 Iint MouseListening()( N& n5 z. Y/ P; U
{
% ]" t# h* \( K$ W" d* z6 A( gMOUSEMSG p;! @, t4 o' u" b( q) y
if(MouseHit())
0 n P3 l3 M9 O" O+ j! b{
Y' D6 A. m( z I0 l8 z! Pp=GetMouseMsg();
5 ~' |6 U' G& e3 |3 Cif(p.mkLButton==true)& r& `* x! u- d; z, j: d7 Q8 r
{
! d# `9 d* q1 L4 Yif(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
E; K+ }3 f! W4 c" GFLAG_FIFO = 1;) Y! X% G) u1 g# W# K, X5 n/ `- K- R
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)" g4 C+ t) Q* k1 \& @* S
FLAG_TT = 1;# L9 b# C6 L8 r5 [/ \" g
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)4 T+ g1 I) I7 `1 s; ^3 n4 ]+ v
FLAG_PF = 1;% O$ a: x8 x4 g2 d7 V
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)
, B$ J) }& `# pFLAG_SJF = 1;1 Z6 O# K3 ]- t, |0 _, 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)
' L7 R; N. z+ L @9 V sFLAG_HR=1;+ F& G7 Y9 r( M* `+ S& l
else if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)+ y6 [7 _( R" [: x3 e
{7 u$ I$ N% H5 B3 ~, ~* K
FLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;
0 w/ N# S1 ~# m0 K: Fclearrectangle(800,325,1200,650);' {1 ?8 x1 U: G4 T
}9 E6 U- I% a! {5 O
else if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )6 e/ _3 P3 e+ H |$ W$ r6 C
{- _1 J3 G! D0 w) `
FLAG_show=0;. M- z2 ]4 V) T" A
cleardevice();9 i$ M) q4 n7 R' K+ {+ M0 A
return 1;! {) z& ]: W4 t& t: T
}
% E9 @5 P: g4 [, m9 r% H}4 P# r1 o# i$ V" }# m
}
2 J% b( |; M; M( p) l8 X( b! y: Greturn 0;, x X* l. M: H+ P. M& T
}9 Y7 P' D) Y9 }
int MouseListening2(int *flagShow,int * showTime)4 Z% |2 S- y( E( J1 y( v3 S
{
& |) J, W5 E0 \0 ]* i$ WMOUSEMSG p;
& M( y: \/ P/ H0 @" |rectangle(1150,0,1200,50);" O, u2 f: B' p" P) n+ a4 {% K/ Z
outtextxy(1160,10,"X");
4 J$ m5 s* f; |" Q+ E, Owhile(1)* M, d9 @/ r" X- O
{
, t8 X5 j) V) N" s: }, zif(MouseHit())
5 ?5 Q" C: A4 A6 _{) O4 `3 {( @ f, N( R
p=GetMouseMsg();" l! g; _0 f/ q6 G& Z# ^ o
if(p.mkLButton==true)
9 J* B1 `5 x/ a6 Z{" X0 r. Y+ u% H7 ^
if(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 )) |* n- J( G z
{" y+ p7 K% m/ x+ f
(*flagShow) = 0;0 y) U# m8 V) f# V
(*showTime) += (*showTime);; \8 M" |( ^' Q" Q/ {* r: T
FLAG_show=1;9 a& I4 V" s! v
break;; N" q. \7 U. Z# N* p! V
}) `5 f+ q1 z' M+ t$ T0 W! L8 |3 [
+ f5 V; x) i1 T}: o, ~( b- Q, ?/ Y9 U& N/ {
}
- @5 c1 c( f- R* S5 y7 g2 v; mSleep(20);' }' E' B7 L4 Y1 p, @: W
}
- L' h) B% u4 v- {# p. K* Hcleardevice();
$ V1 {/ e: i% R& \1 z( Wreturn 0;7 W5 i k! Q0 N) X& m+ M) P
}$ b f( l, K _& p# z7 K: n- U. U
int drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)
* _" Q' f& j1 D0 u5 \{
0 J6 y/ s4 [$ ~4 N' l* xstatic int info[11][3],num=0;- H2 l* d5 n3 H+ N
int i=0,j=0,pos[10][3][2];
( H8 i7 J) W& m1 f. m1 X! Mfloat temp,t;
# p7 j% H) B7 E( U: V//画按钮,不属于FIFO图的范围
3 ^6 A) O7 Z: p/ g3 |if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1)
6 v- S+ E7 a; K8 N" a0 z{5 O; ]7 [! `) G/ r( n5 u% D5 Z
settextstyle(30, 15, _T("楷体"));
# j4 L4 c! w4 Mrectangle(890,455,1110,510);
& r+ w" F& r) ? \rectangle(900,465,1100,500);
9 s+ M1 o3 Q/ nouttextxy(910,468,"查看运行结果");
# {( S: C( k$ y5 u. R5 z D" P6 T}
2 e {# P; ?4 Q//结束画按钮9 O+ [, [0 T( ^% B0 M% a+ @1 [
info[num][0] = com;
+ N$ ]1 q: @1 t7 N* ^# e+ D' |0 vinfo[num][1] = wai;
b# ^4 v6 s( v- Z- binfo[num++][2] = cha;- i: J' J) N- F h
if(num>10) //存储10个点, p$ [( G, g- i2 y- C: t
{
7 i) e# V6 }' O" c! P5 ]# z2 Vfor(i=0 ;i<10;i++)
' O. w' B% y, O: @; O, {: [{! Y5 f- v; S9 k# G/ k7 Y+ @) l% p
info[0] = info[i+1][0];
& [) y1 \) j$ r+ tinfo[1] = info[i+1][1];6 d7 A, ~6 _: w
info[2] = info[i+1][2];- @+ Z% A* x3 |# Y3 o
}
0 s! d, D3 B& m) L# Fnum--;% Z% ~, G' N! j! q
}2 \5 l7 E( e6 g) Z o: B0 C
if(FLAG_show==0); C+ ]# g: J7 C: {: U( A
return 0;
7 K1 w/ y2 T0 | E, m& kfor(i=0; i<num; i++)- S5 O5 \' d {) o) A& _
{" [) J& q% ~ f* K
t = (float)info[0];" h }$ M0 a2 U0 N' J8 z3 G6 h
temp = (t/101)*90;
8 o8 t1 J i7 I6 k$ Apos[0][0] = (10-num+i)*25+x+100;& e9 {8 W+ n; H4 x# ?3 l8 ~8 I
pos[0][1] = y+110-(int)temp;2 L) A$ n/ w9 Z1 F d$ l
t = (float)info[1];
1 S, s- ?% B/ h1 w ^temp = (t/101)*90;
1 S4 k- _4 `/ O. k# S7 t+ d; Fpos[1][0] = (10-num+i)*25+x+100;
4 H" m# F B+ c; D( U G' {pos[1][1] = y+210-(int)temp;
$ {7 Y6 I" _3 Z+ D4 D- Pt = (float)info[2];
5 d6 Y6 ~ @/ x3 b' x. m# ~2 J. Ltemp = (t/101)*90;* M$ m: x* e& M- `, D
pos[2][0] = (10-num+i)*25+x+100;1 _, R& F' P9 D2 H
pos[2][1] = y+310-(int)temp;
: X, r3 c/ s/ `% Y4 Y}
+ T6 z- ?: w K# [8 M cif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)1 x x/ f3 \- [1 s3 Y; [8 s$ b
{0 L8 M2 ~7 j& [+ n9 @( f8 `
clearrectangle(x,y,x+400,y+315);. |7 G" X/ C, y& I. P' U! ~
settextstyle(20, 10, _T("楷体"));
, a" c) a& p3 urectangle(x,y,x+400,y+325);
# G& b) r3 f2 Q4 W' C, b# P9 a$ x$ Souttextxy(x+40,y+10,"CPU"); //画柱状图$ _" x2 ^& d/ L9 `
outtextxy(x+45,y+10+100,"IO");
% N4 Q6 m M# y* P }outtextxy(x+40-15,y+10+200,"change");, I. ~9 `2 V" s# D6 p: @
rectangle(x+35,y+30,x+75,y+110);. J. U' r3 T4 a: z3 V
rectangle(x+35,y+130,x+75,y+210);* D: N ~7 F8 V
rectangle(x+35,y+230,x+75,y+310);
: p( M9 x8 |! n, Fouttextxy(x+180,y+310,"FCFS");+ O% u; E& Y. M1 B6 j
t = (float)com;" v: x& s9 J8 i+ o( l k
temp=(t/101)*80;. N" e ~8 D4 Q4 d; X+ q# n
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);0 ^. N0 U% m/ D# H
t = (float)wai;
$ O1 o) r* W6 ]1 _2 G$ H2 f' i4 mtemp=(t/101)*80;
' H9 i5 n1 T3 d& [! C- nfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
$ d8 q0 N0 K% ]t = (float)cha;$ J. ?& J4 p! d; W
temp=(t/101)*80;
0 y* H1 T' S& i/ H) ^fillrectangle(x+35,y+310-(int)temp,x+75,y+310); ]- a, a& B7 b5 p$ x( [; A
for(i=0; i<3; i++) //画坐标 high=90,length=250
0 O( d) F8 {/ c9 F{
/ K/ o2 m% B5 j3 s9 F/ h1 T- Oline(x+100,y+110+100*i,x+350,y+110+100*i);
; C% D6 h7 M& o1 w# tline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
4 x/ }- R+ w a' d/ V( ~3 Aline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);" ]5 Y0 |& |. U1 V
0 w2 Y5 F* `4 {; m4 q1 E; e1 ?line(x+100,y+110+100*i,x+100,y+20+100*i);
! O u2 u0 j! X5 s, j& {line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);/ K8 i9 g$ ?: @' G( p
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
8 {/ _8 ~( U# S0 n. A% Ffor(j=0;j<num-1;j++)! o/ L5 R) \/ q
{
: J# y g: n! W E, H4 Oline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);8 s. ?1 D+ }7 A) q, j6 S
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);9 {# c! I$ Q1 F6 _
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
, B! _) l1 r9 _, t" |7 }} v6 J* l6 o1 Z/ s
}
! c, u& D: Z3 d3 A, b4 u+ y1 |}
7 M) d; G7 W" P8 O+ G+ `else if(FLAG_FIFO==1)" w! b* W$ g t. i
{ \# _+ O3 P( D( V( x3 s
x=0,y=0;
/ p/ z8 o% E8 F) Kfor(i=0; i<num; i++) }/ e& e# ^) @9 n2 O% i. E
{
2 k6 c, j, }+ }t = (float)info[0];% r- x* Y! M' b3 y
temp = (t/101)*180;
3 B5 K: X! D: |7 {, I0 X. Rpos[0][0] = (10-num+i)*50+x+650;- J+ M, R+ P, |! ]( ^
pos[0][1] = y+210-(int)temp;8 \7 {- e- t- r2 d# s' p( c
t = (float)info[1];
! S3 t5 ?/ i+ x9 p. g" O) ?( q btemp = (t/101)*180;3 _2 n) ^* ]# b S& \2 e
pos[1][0] = (10-num+i)*50+x+650;5 Z% I, ]( G$ V4 |$ |( U) U9 s
pos[1][1] = y+420-(int)temp;
5 {6 @4 c; W h$ C! Xt = (float)info[2];% a k& Y1 ]3 l4 A3 V9 P) K
temp = (float)(t/101)*180;
/ X. l% U, x+ B6 y2 `9 P8 O& u" Cpos[2][0] = (10-num+i)*50+x+650;- H. ^. X" t# [9 }5 h6 o: u
pos[2][1] = y+630-(int)temp;" H3 F4 R" X. U& D/ c9 @
}
% f9 U* A9 `" z; u* {. Xclearrectangle(x,y,x+1200,y+650);
2 [& Q4 J; x3 y8 x6 [7 Ssettextstyle(40, 20, _T("楷体"));8 Q8 |5 f- U) O) c1 \
outtextxy(x+50,y+50,"FCFS");3 I- [6 @ Z( Y8 b4 f2 j6 S
outtextxy(x+280,y+20,"CPU"); //画柱状图7 E S1 j; ^8 j W% S
outtextxy(x+285,y+20+200,"IO");5 f: J" Q3 U: V9 @2 Z
outtextxy(x+250,y+20+400,"change");% w7 u' }) T: s/ M _
rectangle(x+270,y+65,x+330,y+215);$ s1 W/ y( m0 ~5 k2 k
rectangle(x+270,y+265,x+330,y+415);! M( O! T& P0 W# |* y
rectangle(x+270,y+465,x+330,y+615);' N5 E' x# a1 H: M4 w
outtextxy(x+290,y+620,"TT");% K2 }" m/ ^2 c7 o2 q; w2 D
t = (float)com;+ _" d- s& t8 w# \7 U9 e( K
temp=(t/101)*150;; W% k/ ~( F4 s; r, I
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);' {7 H: |; Z9 i `% e0 Q$ ~
t = (float)wai;/ F+ L/ J" s, c
temp=(t/101)*150;& ?! A: S' @/ b
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
/ q" m! ]2 N+ f9 n# vt = (float)cha;
) x# K: ~" q( u7 s2 y& o' O9 Mtemp=(t/101)*150;2 r: q2 a4 K. S1 `* Z( v
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);8 u! Y2 E; C, f
for(i=0; i<3; i++) //画坐标 high=90,length=250
- I) `% r6 ]6 k) Q- I- A{
7 }3 l: I: U9 s: Qline(x+650,y+210+210*i,x+1150,y+210+210*i);% _3 L) u" j( w# G t
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);3 \! E; q6 Q" t
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
7 K# l2 i6 X; Y" ?9 [! g- ], D/ s* g
line(x+650,y+210+210*i,x+650,y+20+210*i);
+ O! ]- e( b2 d/ E$ C- w' ^0 U- c, C9 O# gline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
" j# u; I- K$ d$ T$ [: sline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);8 ~" _0 m6 |) F, t' L
for(j=0;j<num-1;j++)/ C) }8 d5 ~: ~9 w- K
{
+ M3 x8 H8 L1 x3 pline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);9 M3 ?+ ` u# s+ A* C& x2 S F5 Z
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);" M* d3 i+ C4 W& |4 Q l' z0 Z- ?
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
1 C5 V2 `+ s" b' E! ?4 {}; r8 z7 k# o3 \1 a
}3 ?- J* z6 p6 Y& g
}. M/ V) Y+ |3 U6 ^" A& t4 p/ |
! d% j: t6 p% W7 p
3 M1 ?/ W8 W% E7 x# a7 d/ y. Jreturn 0;
M" `. p7 d9 @}
8 C2 [+ n1 r6 c' xint drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)) j. P1 S9 b- G: `8 w0 w
{; s, ]% C- b" j7 y/ b5 L
static int info[11][3],num=0;
2 ~4 C3 L& ~8 ^5 sint i=0,j=0,pos[10][3][2];
# R3 P0 o6 z+ n- w9 a% gfloat temp,t;& ^$ b/ O* s0 i6 J; j# K
info[num][0] = com;! r9 ~2 o# h+ v
info[num][1] = wai;
# f9 B% Q! F' Q" J: N1 K- Kinfo[num++][2] = cha;
2 X, K# s8 x! b# a7 S2 |if(num>10) //存储10个点$ b8 L' r" `5 Y+ l! p9 B
{
1 x. \& U) p6 U$ qfor(i=0 ;i<10;i++)
- d+ q- x3 `$ Z r& A+ u{1 \% W0 s3 ~( t5 ]( e
info[0] = info[i+1][0];6 ]* G4 i* w. Z0 h
info[1] = info[i+1][1];; A& M* i- Y1 [. t2 ]2 H
info[2] = info[i+1][2];
' \( K$ R+ d3 c; y( y}
; E( v( G% R, ?2 `. x! cnum--;1 n. k- |2 R i1 w. \* J# u$ K
}4 I6 F' O8 n6 J* K# `5 i0 ?
if(FLAG_show==0)
2 ~8 n9 D2 U3 w7 Z" j0 R3 s$ @return 0;
8 k# |3 X! g% M/ x6 O- O# N: Wfor(i=0; i<num; i++)
P5 R: r4 P. }( w+ `2 t1 z{! s4 V6 e* [/ p+ q# q. N9 k
t = (float)info[0];& e1 Z2 o- l8 R
temp = (t/101)*90;
$ ~7 R- z I2 }5 k5 D& z0 `pos[0][0] = (10-num+i)*25+x+100;! f0 u6 _- D' t9 i) X
pos[0][1] = y+110-(int)temp;
$ @0 ]! X/ q5 @( G o$ Et = (float)info[1];
) h% T1 {+ ^0 htemp = (t/101)*90;
! L5 f6 j+ B7 Y2 m6 A+ K1 A* ipos[1][0] = (10-num+i)*25+x+100;
+ h2 Q/ U& Q& _) u1 l8 g/ C% O3 E2 @pos[1][1] = y+210-(int)temp;
: D: X- L6 N2 ?; y' S: a. V+ E0 r4 Wt = (float)info[2];6 b9 ~ U6 @9 G
temp = (float)(t/101)*90;
- y% D# \) ?8 J, r! tpos[2][0] = (10-num+i)*25+x+100;
' R5 e! j1 l$ S9 Y' A3 R epos[2][1] = y+310-(int)temp;6 x: P2 Y$ Q9 ^, h
}6 l( j6 B8 s% H, {* i0 \9 c1 ^ B5 z
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0); t6 }3 M9 _0 ~
{! ~* u: `( o# c; T) f# Q
clearrectangle(x,y,x+400,y+315);
: C# T& f2 F) I0 hsettextstyle(20, 10, _T("楷体"));! x8 s1 z3 `! [# R6 u0 F! O
rectangle(x,y,x+400,y+325);
5 _# |9 n; s- a2 V" P9 Mouttextxy(x+40,y+10,"CPU"); //画柱状图! `6 c6 e* B: y" L# F; d5 m
outtextxy(x+45,y+10+100,"IO");8 y6 ` V1 V6 L* B9 s! |
outtextxy(x+40-15,y+10+200,"change");
& i( G. @ \6 P, z. P! @0 m7 `rectangle(x+35,y+30,x+75,y+110);
4 P% Q/ R4 R: b8 C- g+ O6 z Brectangle(x+35,y+130,x+75,y+210);" Y6 P7 S4 Y( k% b/ H ]6 F! Z
rectangle(x+35,y+230,x+75,y+310);# O) D, E6 E$ _) }# c
outtextxy(x+180,y+310,"HR");. i6 p: H! ^. z+ }. h/ }
t = (float)com;1 _. j: V7 p x
temp=(t/101)*80;
: M* w! [+ l6 P/ J5 r! Vfillrectangle(x+35,y+110-(int)temp,x+75,y+110);' R5 [- ?; Z5 H7 x
t = (float)wai;
; i6 Q' |+ A+ Htemp=(t/101)*80;, D9 g2 N1 M- B: J" f/ C2 b
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
1 ^9 i' Q7 k' q* H) u5 Pt = (float)cha;
0 u& e8 k3 M9 Q3 ytemp=(t/101)*80;
8 Y' V0 ]8 t! Y& {3 J, wfillrectangle(x+35,y+310-(int)temp,x+75,y+310);# Y) k& ^2 J8 |3 u
for(i=0; i<3; i++) //画坐标 high=90,length=250
. k4 d' G R6 W" p1 {; a; h1 |' {{+ f0 {8 S8 i& C5 s0 S N7 `+ b
line(x+100,y+110+100*i,x+350,y+110+100*i);
7 T S# u4 V/ B/ i& Y- Yline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
W3 V2 ?+ s- q- k( oline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);/ K- ~3 u8 d0 c. S9 D9 \
# D1 j) m6 n4 \" B
line(x+100,y+110+100*i,x+100,y+20+100*i);
9 q9 x2 w" t) C. b1 R1 ~& t4 O( [line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);7 ?6 U5 I- ]+ F$ ]# `
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
& q) a$ T3 L. Tfor(j=0;j<num-1;j++)
8 |0 H+ N) n6 L: _. {2 S{7 f9 Q. e8 l1 p0 x# U
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
& u7 @5 @, Z$ @+ G hline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);% [5 h9 t& d. ~
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
7 F! @$ X; c/ T/ X- g: q) T}1 R- Z9 M! T' }
}
% B" R8 F: i/ Q/ P}- y, M: B2 e2 u! }" x4 C
else if(FLAG_HR==1)
/ c% M; ?- m0 Y, w2 _* l# R: P6 G, ]{
( N% V3 s+ G" a! l/ tx=0,y=0;
6 s, j: Z+ n# Sfor(i=0; i<num; i++)
: h: a7 Z$ W' D, [# Q{, ]0 I3 l# K9 W% n
t = (float)info[0];# ~8 m5 ^6 S2 A
temp = (t/101)*180;& a' A8 `4 ?+ j P7 |* v
pos[0][0] = (10-num+i)*50+x+650;
+ Z& [7 R5 c; Gpos[0][1] = y+210-(int)temp;* @7 g. g! x- x
t = (float)info[1];
w5 c" I5 s" E \2 rtemp = (t/101)*180;
( ]$ y0 \% W9 E- [. E) Ipos[1][0] = (10-num+i)*50+x+650;( W2 m2 v6 M6 l# [' g# D
pos[1][1] = y+420-(int)temp;9 G/ k" K! S2 \3 c( T# j
t = (float)info[2];
/ M% T" W7 T: R) U2 s0 Z% A4 Qtemp = (float)(t/101)*180;
: h8 A y; U* p2 Mpos[2][0] = (10-num+i)*50+x+650;
; q8 y1 o" ]# }: A; Z* v$ gpos[2][1] = y+630-(int)temp;
' k2 Z; Y- g) Y}: N% T* B& N7 ]# K" e* s
clearrectangle(x,y,x+1200,y+650);- q5 @- k" H: p6 f7 ~
settextstyle(40, 20, _T("楷体"));
1 C7 n' I$ d5 Houttextxy(x+50,y+50,"HR");
( P c( y7 O4 o3 z+ ^outtextxy(x+280,y+20,"CPU"); //画柱状图
* h' Q; U) Q a. B1 p2 ?+ Pouttextxy(x+285,y+20+200,"IO");
- v( x, S9 ^# Q1 D0 o ~4 Q, ?outtextxy(x+250,y+20+400,"change");
6 U/ l* V5 f. z& |9 D& B" D* mrectangle(x+270,y+65,x+330,y+215);( c1 u; O. W0 n" O
rectangle(x+270,y+265,x+330,y+415);
. j. J: x; v3 u7 h4 {rectangle(x+270,y+465,x+330,y+615);' A; W9 h0 n* m9 @6 ]4 x/ g0 n$ ^
outtextxy(x+290,y+620,"TT");
; e6 ^5 K' A5 i I ft = (float)com;
4 p9 F) u* c, H; ~% a( p- t! otemp=(t/101)*150;
: i# ~4 \! W. ^2 ^; o% ^5 ?3 Efillrectangle(x+270,y+215-(int)temp,x+330,y+215);
2 y7 l" ~2 T7 yt = (float)wai;2 W+ U; v( B/ y- k f% j- ?
temp=(t/101)*150;
4 S; ]' Z3 M+ e7 w# I; q- O1 bfillrectangle(x+270,y+415-(int)temp,x+330,y+415);4 g( {# O2 N( _4 G7 R0 {
t = (float)cha;
! h/ O/ B5 ?" Z3 y4 r# }2 L8 vtemp=(t/101)*150;$ T% V/ m% G6 n) s0 E: _
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
3 C9 y5 J3 k ~- n0 i& A2 @for(i=0; i<3; i++) //画坐标 high=90,length=250
( D7 P& a. i$ q{
. W: R- v) S ^% v* v' wline(x+650,y+210+210*i,x+1150,y+210+210*i);
9 K; n5 i: w0 i! @, Jline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);6 F( O) N- m9 w- w3 p% h3 Y$ ?" w7 r
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
! }: m: C3 e( O5 j4 ~* e- h9 v6 d/ t! d1 R/ d
line(x+650,y+210+210*i,x+650,y+20+210*i);
1 \1 y4 \ Q5 M! f: Sline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
7 A H8 U' K, o- rline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
5 Q+ x; r+ }* zfor(j=0;j<num-1;j++)
# d9 A! V1 S: f+ W, b! P{
* U6 U" p5 l$ d( Gline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
8 V1 u0 s9 N: @% M, Z1 Zline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
3 k+ Q, r- I. E. ?0 C3 Vline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); / i$ o1 X3 g, y# C' H _+ W, v
}
9 M3 u7 B0 ]# G8 r9 N}, u U! F" y3 I; z& n# K0 M1 [3 ?
}. C7 k, @+ m0 L7 }9 w* p- ^
8 | C1 h4 v9 F+ q" X# _1 h3 C. g( L4 c
return 0;- L0 y5 V: l/ r) b1 S. `
}* p2 [' \: U- N8 F/ s, W# L' Y' F5 o
int drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)' e$ V% Z# ^" p* d; w% o
{ K! ?( T' W4 |
static int info[11][3],num=0;$ A; E% V1 c5 ?
int i=0,j=0,pos[10][3][2];7 \9 h" P5 [ e" o. o
float temp,t;
' \ Y. d5 e! S8 ~7 n/ Y* l3 ~, linfo[num][0] = com;6 r; Y1 p) s9 R" `
info[num][1] = wai;
2 A8 x& j7 G) X2 z% j$ n3 zinfo[num++][2] = cha;3 E& h' E9 j* x3 [/ i7 G% V
if(num>10) //存储10个点% `: u3 g2 T" L1 b! t( e
{5 h. _1 H, L. l4 X" r
for(i=0 ;i<10;i++)
* v" G4 C2 \, v# O e% m0 C{
4 z7 c+ t- ]2 d N% p2 Iinfo[0] = info[i+1][0];- V/ e, J+ z3 ]( u, p
info[1] = info[i+1][1];+ a- G" x/ S5 i# w
info[2] = info[i+1][2];
3 K9 g0 ]) u/ l6 r: ~' Z}
3 F: A, B L- h! y2 S* O3 x$ J! Snum--;
- P$ D( H- {( `( A, M- G}
: ^7 N$ W/ k0 d4 `* Uif(FLAG_show==0)) r- U- D. w+ Q' E7 P9 O. V$ w
return 0;# K/ x; F/ k" D$ q# M# V; v
for(i=0; i<num; i++)
* O9 D( l7 ]2 H2 d{: G- p( B% a4 b% P+ p+ R
t = (float)info[0];( N/ z' L* k' @# U% X2 u8 O
temp = (t/101)*90;
+ t! E) o, I z* Epos[0][0] = (10-num+i)*25+x+100;) L. s; O# W, P
pos[0][1] = y+110-(int)temp;4 @8 s2 M% j) p p1 \
t = (float)info[1];
3 X9 s( Y$ i- g3 e6 B$ ? Ctemp = (t/101)*90;
& c/ q/ T! n1 opos[1][0] = (10-num+i)*25+x+100;# Y. l o8 d8 _0 `
pos[1][1] = y+210-(int)temp;" {; E" |+ A; F/ W2 l g4 T8 H
t = (float)info[2];
8 r' }! G5 y2 B3 h5 G& w! [- utemp = (float)(t/101)*90;4 b& q: c% X0 r+ `& r3 c
pos[2][0] = (10-num+i)*25+x+100;
- {) H# `$ {+ w5 Dpos[2][1] = y+310-(int)temp;
6 v3 {7 p- W4 }( E}
+ i/ n, c( d' k2 r# I+ \, l1 Bif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)- `9 u7 J2 {# b0 G0 c
{3 y, X* w' T# j7 d) C3 @ |
clearrectangle(x,y,x+400,y+315);
3 n, L0 S7 ]; i/ Hsettextstyle(20, 10, _T("楷体"));: C7 F3 V7 X7 Z, c$ e, S
rectangle(x,y,x+400,y+325);
/ R+ [5 j" D9 T h) r, souttextxy(x+40,y+10,"CPU"); //画柱状图9 P' h0 X$ v: U) C! |9 K5 s* P- B
outtextxy(x+45,y+10+100,"IO");
3 d& s/ G! v6 l2 fouttextxy(x+40-15,y+10+200,"change");
8 h. ~( ]# `9 B/ w2 {6 I* g5 [. lrectangle(x+35,y+30,x+75,y+110);1 w: q: ]' P6 w; d$ }+ |$ C1 |8 }
rectangle(x+35,y+130,x+75,y+210);# B& v9 g3 J- D
rectangle(x+35,y+230,x+75,y+310);
8 a0 I- o6 v! R& Mouttextxy(x+180,y+310,"TT");# j4 l# w) M& C0 C& Q M
t = (float)com;0 r5 a: X' E- p
temp=(t/101)*80;
4 |* }% c# | C# `. ^4 g" i- Pfillrectangle(x+35,y+110-(int)temp,x+75,y+110);
8 k% D% S2 A$ D0 Gt = (float)wai;+ G- B0 _5 I+ p1 ~" G7 w
temp=(t/101)*80;
- k3 o$ l$ o& y U7 H5 r7 U2 w& \9 wfillrectangle(x+35,y+210-(int)temp,x+75,y+210);; Z4 \0 V/ Z% y4 J
t = (float)cha;( M7 J7 h* G/ _- n! |) _
temp=(t/101)*80;
/ C0 X z# H- K+ {fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
+ Z E- @7 e& |: K9 \. w; @for(i=0; i<3; i++) //画坐标 high=90,length=250) t+ l& Y7 X/ \; u! I- P
{3 I8 u2 o6 \/ R- ^3 w4 H
line(x+100,y+110+100*i,x+350,y+110+100*i);; a/ _+ t8 F+ W. c: p2 }6 g1 I
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);6 E/ d( G) c' p U' C
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
' N' _5 _7 M& e
# l/ ]/ p: h3 ^* a. Z7 U" Q xline(x+100,y+110+100*i,x+100,y+20+100*i);3 ]. I+ D6 i, W1 f3 \4 B( z: ~
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
3 i! S! U8 N, P1 A8 y( Y- xline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);0 G3 S! X! M- T5 W% w+ |7 z
for(j=0;j<num-1;j++)
2 N6 G3 \7 M4 T) A{
$ i3 n9 [* }) [line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);7 y @, \' m. V* A7 q) Y
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);7 }6 O B, l$ T$ R
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); * f: T: e. o3 L4 S- Z4 L
}! P8 z: O$ m4 I/ V$ i. v
}
" I( B+ D( t( y) B" {}5 b# D+ K" @8 _- k+ z
else if(FLAG_TT==1)
2 N! G- B E0 v# L! y0 q- T{
% }9 l6 ^. }, Z& F* g; sx=0,y=0;" p* Y A, v" Q( Y- ` X* p
for(i=0; i<num; i++)
: e% g. k) h, O! C5 E# \# D0 X2 ^{; L" i4 W, ?1 w- V9 R; e% ^
t = (float)info[0];9 B! Z9 ~; E5 `5 t% [0 }
temp = (t/101)*180;; Q" @! d9 h1 J$ X, O U
pos[0][0] = (10-num+i)*50+x+650;' T) S# p( v* [2 I M1 F+ m3 H
pos[0][1] = y+210-(int)temp;
3 B1 U7 k) ]" \8 lt = (float)info[1];" f& g" z( Z+ S
temp = (t/101)*180;
* s2 _/ P2 k( o7 Z0 Y' epos[1][0] = (10-num+i)*50+x+650;
B, J# [; D" Ppos[1][1] = y+420-(int)temp;; t- r! X# K9 j% _# C- S; X
t = (float)info[2];: O& b0 x* I2 P- ] R1 q
temp = (float)(t/101)*180;8 K: U" I) h- Z
pos[2][0] = (10-num+i)*50+x+650;3 q1 \+ a% [7 h- l _) y! }, R
pos[2][1] = y+630-(int)temp;& `" w9 I" R0 I! Y
}2 I4 `& p% g" ?2 K/ ?
clearrectangle(x,y,x+1200,y+650);+ t* k: |+ | O5 D# Q$ F+ `
settextstyle(40, 20, _T("楷体"));
]3 Z0 u- V! F8 _6 h: souttextxy(x+50,y+50,"TT");
. Z& X& W0 f% ^5 G. F0 z* Pouttextxy(x+280,y+20,"CPU"); //画柱状图
# Y3 q* k% q2 c) Iouttextxy(x+285,y+20+200,"IO");4 G' Z+ F% U' Q1 V7 ^* t T
outtextxy(x+250,y+20+400,"change");9 a, a; A' @3 d5 h) H. Y) n
rectangle(x+270,y+65,x+330,y+215);, E* i. \0 ]' ^: I1 p
rectangle(x+270,y+265,x+330,y+415);7 z( J7 L [! [# o
rectangle(x+270,y+465,x+330,y+615);
& z) W6 S5 R! [. x7 U Y0 Oouttextxy(x+290,y+620,"TT");9 _: J8 t/ c; [# e. E7 [
t = (float)com;+ O( V- O V# K6 q& M
temp=(t/101)*150;
A& Y& |1 ?7 N2 Tfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
1 Q8 H4 b5 n6 M3 |t = (float)wai;
7 L @; a, g# y& A, c4 K8 g0 Wtemp=(t/101)*150;6 _/ t& [% L# B4 e
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
6 X. I9 E+ M1 z0 I; vt = (float)cha;
( _9 m" j8 p3 w9 v0 `8 u+ g4 }temp=(t/101)*150;& ~! ?; f3 s; z! j
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
/ d$ W1 T8 E5 Y/ Z) J2 K* efor(i=0; i<3; i++) //画坐标 high=90,length=250" J; {; s! y2 b' n0 j% Y4 k1 N
{
3 r2 Q+ _" @: X8 F/ q& q" E% X# U. ~- Kline(x+650,y+210+210*i,x+1150,y+210+210*i);
+ F( z, B; _0 r$ F m, Zline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);. k& F$ q9 u% w5 b I$ ?4 h, n
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
6 }3 Z A$ p3 ?8 F
4 B; V0 y+ ~- O# Q9 pline(x+650,y+210+210*i,x+650,y+20+210*i);
M: v" y* e( V7 d Qline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
9 U ~% E: h' R6 \- g# hline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);. G% r3 Q( H4 x* M) N. N
for(j=0;j<num-1;j++)
/ P y8 [9 V7 @$ B1 h{
; G/ M3 k( ^$ L$ x7 Kline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
1 r2 j/ N. P- O0 T" X4 D& a6 [" qline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);2 } ^( L$ Q& C9 ]3 {0 t
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
9 H/ A p9 O3 z! Q) Y9 R}0 ~. ^, o& n( Q* {. O# G& c6 P* G8 Q
}
( }/ s9 ~9 P! M5 C}7 Y5 H" E! s4 g7 e* S
* O* N/ \ P# [" B: v2 n" Q
. q+ o" W+ C- q( e% f3 C6 ?4 {7 b
return 0;# n4 f* H' I% q. K7 d
}
+ S: S8 J. {: a+ y& `% Fint drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)
5 O; W0 b% k/ J1 ]6 y0 T{
t2 S4 K: G8 N) S& z: i1 r2 ostatic int info[11][3],num=0;
' p: ]9 e0 ?) ]int i=0,j=0,pos[10][3][2];7 K! y. O7 k+ ]$ h3 t( x
float temp,t;
1 M* x' O6 u4 F3 Finfo[num][0] = com;
2 ~0 D; e2 L: I2 u3 ^: k" Linfo[num][1] = wai;
$ P S. b1 r5 Y6 s( u+ e; I' ?info[num++][2] = cha;$ m, C1 q5 r9 d/ @) c" m
if(num>10) //存储10个点
. F- m' t* b" V% k{
2 W( A+ D+ N. E$ Ifor(i=0 ;i<10;i++)
4 S* V9 ^: ~7 p' |{5 Q6 ~! u& `4 \2 ~. V8 k
info[0] = info[i+1][0]; W! j; H. O6 E) q5 Z
info[1] = info[i+1][1];0 O) K; C% ]# X3 |. j2 e, _( m% B
info[2] = info[i+1][2];
# ^9 w+ X, M" d, {5 y2 J+ {}
* M4 C1 ~6 d9 c# Z0 |num--;
3 K8 E4 x. F; L, d7 x- Z' R}
( r" C6 q9 M' a% v1 r% `if(FLAG_show==0)4 x% _/ D1 `5 Y6 s& T; d: S
return 0;8 b9 D, r; T+ J. ^' T! D5 l! O+ L6 m
for(i=0; i<num; i++)
! |! a: G; `% ~% b$ V{
Z" t$ d6 k. B% z9 B# k6 H6 Ht = (float)info[0];
* n- C$ a" i, p- ftemp = (t/101)*90;+ [) q8 A* E+ B1 R9 [, F; [& s
pos[0][0] = (10-num+i)*25+x+100;
2 I) K& N7 Q5 \6 [. a. Upos[0][1] = y+110-(int)temp;! ~, |9 b( c& b: p+ S; C- A: A- J
t = (float)info[1];
2 Y+ F; R; t- Itemp = (t/101)*90;6 A$ K9 ]/ a2 h8 L, L/ `' c
pos[1][0] = (10-num+i)*25+x+100;* B8 O. R0 B( ?" u0 t) M
pos[1][1] = y+210-(int)temp;! k* F$ J2 E& U; W) k
t = (float)info[2];
5 u6 V) Y' w5 M) s8 atemp = (float)(t/101)*90;) c! u6 J, {" r
pos[2][0] = (10-num+i)*25+x+100;8 p0 a, `) y! h: c5 ?* x; b1 S
pos[2][1] = y+310-(int)temp;1 W# x0 s- |5 o6 o3 S
}
) K& l7 u3 H) q' D, E: `" fif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
, G. A9 {1 U% G2 E/ w1 m; j9 ]3 X{" l# T7 `% _2 X9 N. N6 U. {# [
clearrectangle(x,y,x+400,y+315);
% H( b8 ^9 R6 Vsettextstyle(20, 10, _T("楷体"));
* z1 {; g/ F: ~rectangle(x,y,x+400,y+325);
$ Z% Z- P8 f/ `1 R7 j3 Couttextxy(x+40,y+10,"CPU"); //画柱状图: f/ }) X o* w3 G8 H, Y+ u5 h
outtextxy(x+45,y+10+100,"IO");- J( J; O. z5 M) G4 r1 n$ ~
outtextxy(x+40-15,y+10+200,"change");/ i+ F+ {) F2 |5 s+ Y# S
rectangle(x+35,y+30,x+75,y+110);
" j' M8 D( a9 J" h5 S# Jrectangle(x+35,y+130,x+75,y+210);3 f- l- b3 d r6 A3 `
rectangle(x+35,y+230,x+75,y+310);
, h; v: o& d) ~- ]; O kouttextxy(x+180,y+310,"PF");* c8 E' Q2 X3 ?6 M
t = (float)com;
" L7 T7 G o0 ?6 ^temp=(t/101)*80;
$ {+ g9 I. `' S! m7 f1 wfillrectangle(x+35,y+110-(int)temp,x+75,y+110);# l3 R( g. O# _! M+ ~; B; L! Z
t = (float)wai;
+ ~2 `5 T) W4 N# m/ h$ U( Dtemp=(t/101)*80;
2 ^4 b) Y) K8 X2 w& w5 p" {& Mfillrectangle(x+35,y+210-(int)temp,x+75,y+210);: @1 r0 }. p9 Y% c' _5 o. B7 A
t = (float)cha;* }$ q3 L0 C9 K% G: L
temp=(t/101)*80;8 I9 Q! k( R0 ]. @# b8 [9 x
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
& u2 b. g3 O `3 P1 Dfor(i=0; i<3; i++) //画坐标 high=90,length=250
2 ^6 ~/ v8 h0 I x{
/ V2 e( b l) B* ^6 `, Rline(x+100,y+110+100*i,x+350,y+110+100*i);
6 b3 ?& @5 `6 H3 x# f5 D1 }; Wline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);1 q% D9 q/ f1 J: N/ |( C6 L E- g
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);6 d/ `, \5 V f" u U2 K6 w, ^
5 ?5 C! e+ Q% k7 a
line(x+100,y+110+100*i,x+100,y+20+100*i);- A; t1 T4 k1 _
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);$ z5 y# z, \# b0 e# g+ k
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);: W, Z& p% E# E9 C' K# J% `
for(j=0;j<num-1;j++)
% z0 R* }8 v2 |: K0 [% ]# Z{
( \+ B( T' H( f$ Tline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
1 V$ k) }+ B9 ~9 T$ h+ ^9 D4 qline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
0 C' `" W6 Z9 q' p* Qline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
: }' T( m, u+ Z4 `. i}
2 k6 C: g/ a: E7 F5 U( T" ^}
2 A- `; R6 Q" S( U}
/ \& q- \; ~0 aelse if(FLAG_PF==1)
' T1 x z/ Y0 g/ d3 Q8 d{
7 r. `% T* X/ }, z4 S% }' r/ V3 Fx=0,y=0;
% ~ U6 p8 l4 v7 `% G$ n) r: z xfor(i=0; i<num; i++)5 V; X/ S" }+ {" F$ Z
{
! n! U X8 \" Y- l8 N% |t = (float)info[0];) O; X) a4 z3 S7 O( C& H
temp = (t/101)*180;
( W! I' H+ z x2 Gpos[0][0] = (10-num+i)*50+x+650;8 n. z! K- s& V U+ r
pos[0][1] = y+210-(int)temp;
. ^$ n# y& D) V: r/ e$ e& ^" Mt = (float)info[1];
) `7 t' u! J! n9 f1 Ktemp = (t/101)*180;
& L$ p5 {' D5 f4 y: r* \1 _5 u# w7 zpos[1][0] = (10-num+i)*50+x+650;! N) x4 |3 _ E
pos[1][1] = y+420-(int)temp;
! N. U- U+ o# b- H0 Z6 Mt = (float)info[2];3 j6 I. I8 \7 w( }4 Z+ p
temp = (float)(t/101)*180;
& L; C3 a# f0 @1 _( `pos[2][0] = (10-num+i)*50+x+650; H+ i _3 X- X" V
pos[2][1] = y+630-(int)temp;
, m! T- g7 ? ^ o: R: g}
" {+ i5 l D' b3 T4 Gclearrectangle(x,y,x+1200,y+650); B+ S- m/ X2 X+ T
settextstyle(40, 20, _T("楷体"));
$ F+ x7 d( U& F& N5 Iouttextxy(x+50,y+50,"PF");. } o9 o6 U) F5 o9 {2 d" t8 p
outtextxy(x+280,y+20,"CPU"); //画柱状图
2 [2 Y9 e4 E/ }: D+ ~+ b6 Youttextxy(x+285,y+20+200,"IO");
$ @& X3 C$ W3 [* K. Fouttextxy(x+250,y+20+400,"change");
2 k0 }1 D8 Z4 [" L! E `- rrectangle(x+270,y+65,x+330,y+215);3 e0 r) r3 v" {0 q# e1 Z6 W; C
rectangle(x+270,y+265,x+330,y+415);! Z2 W$ G$ E5 Y. m
rectangle(x+270,y+465,x+330,y+615);* }3 j; t1 ^+ \; V; u) V
outtextxy(x+290,y+620,"TT");( o, j0 Y) U( U" H. x. z. B
t = (float)com;! L$ P$ R% @9 V, q* d
temp=(t/101)*150;5 y2 A% h) f1 V# r% p
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);* g, ?5 s# L/ n5 C
t = (float)wai;# y) o, ^" Y) m+ K
temp=(t/101)*150;
. K: Y! A: J5 I2 cfillrectangle(x+270,y+415-(int)temp,x+330,y+415);3 O! K# ^* |. [4 {; q; k
t = (float)cha;
& G: W" L9 D) t6 I& Stemp=(t/101)*150;
- Q5 Z7 W- B8 H+ U( @8 bfillrectangle(x+270,y+615-(int)temp,x+330,y+615);# C8 c- M" V/ r: L
for(i=0; i<3; i++) //画坐标 high=90,length=250
3 q, S d j9 Z8 l c) O{5 L- K2 z: }/ Q! ~) x( S' r& B9 |
line(x+650,y+210+210*i,x+1150,y+210+210*i);5 j. I& K- s! {9 b8 T) q
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);* N' f! _& {4 X* w: f: B `5 h7 }8 i
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);* e: _' R2 Y# w7 j) \
6 @2 G, y1 D8 s q
line(x+650,y+210+210*i,x+650,y+20+210*i);7 |. q5 P4 X( Y8 |' P7 o1 E
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);) G4 Q; [. h0 s' |1 j
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);2 l3 X- _7 [" V- ~ U
for(j=0;j<num-1;j++)
% z* q0 T/ H! S{8 J. h$ n0 d* O: r- W% H- @4 j
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
; @7 P9 T* i, [" }% k% nline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]); I$ h+ d7 a E2 a2 T
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
, n$ m' i1 \2 y# t) y) h) u}- ^8 D" q+ w5 I/ j" W; u
}
. R% j$ Y& m B' \% w}; c3 t! r( L, M
return 0;
3 ^% E4 g; z: K5 v0 M6 z}
+ P4 j2 Q$ g, i* F0 E- X8 Eint drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)
2 p) m& v3 t5 h. q1 E/ y" w{# y, R; I- ?! |: B7 b
static int info[11][3],num=0;2 ~2 ?# ]' v9 N- M6 k" R
int i=0,j=0,pos[10][3][2];
2 }" S& ^' J: u6 J2 p; p6 f A# K t% vfloat temp,t;! `" v% @, ~& {! _3 Z
info[num][0] = com;
! N( d/ P+ [ Z! L& H% J" Y9 Xinfo[num][1] = wai;/ o. k J! O& f2 T0 s9 `$ `
info[num++][2] = cha;
* P9 L, c+ @1 Tif(num>10) //存储10个点6 }: [, C g$ ?, o: a% F
{
# Z# @# ~+ w5 l h. G- G) R' Kfor(i=0 ;i<10;i++)
% ?7 S H$ A5 X3 w{. M P3 R& U% l/ N
info[0] = info[i+1][0];4 Y5 ^5 k/ _* N9 T
info[1] = info[i+1][1];
) w7 i. t3 V0 Ainfo[2] = info[i+1][2];( |' g8 }; Y0 b$ B; t3 c
}
6 e) }$ V' G W$ s2 y1 c) \/ V1 @num--;" o* {8 r+ a# U' P. L
}
. {) ` g; D5 G1 R) ]; F1 }if(FLAG_show==0)3 I' g0 d: s6 m- g3 h
return 0;1 M) v! P6 k6 s, L
for(i=0; i<num; i++)
- u* m7 o; m, \5 m M{
3 h! f% Z$ E2 Q* b/ P0 k5 |, gt = (float)info[0];7 [4 `9 n) Z. t" R( U
temp = (t/101)*90;4 x+ Y9 a% |( E; C9 ^
pos[0][0] = (10-num+i)*25+x+100;
( Z. q& e/ m8 Upos[0][1] = y+110-(int)temp;& j( I& G9 [/ b) K
t = (float)info[1];# A0 y. ^" v2 M7 A) E* ]/ t
temp = (t/101)*90;
3 O j) g- ?1 C, \1 H) Rpos[1][0] = (10-num+i)*25+x+100;
9 a" X4 ^$ a7 k: X; ?* @9 ppos[1][1] = y+210-(int)temp;, g3 T1 W/ b* O1 t0 {# w% y5 F
t = (float)info[2];
$ Y, K/ r6 x" M2 {" s$ Utemp = (float)(t/101)*90;
y2 z' K' Y! ?& J: o$ }2 ~" Bpos[2][0] = (10-num+i)*25+x+100;8 j$ U* C1 Q5 I7 i
pos[2][1] = y+310-(int)temp;
1 |1 r0 g C) t8 Y7 S}
) z: }5 d* w! z8 e0 ^if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
1 { U3 k& J$ k/ V: R/ N{ 6 G* |! H) U* M9 @: n5 A- L& [) ]" z
clearrectangle(x,y,x+400,y+315);
# x; K$ P0 F# f: D- w: o3 D9 isettextstyle(20, 10, _T("楷体"));4 w9 [& s6 }, |! {% H; x% Q
rectangle(x,y,x+400,y+325);
7 G- |- L9 E$ V2 J+ ?% E4 L5 ~9 \outtextxy(x+40,y+10,"CPU"); //画柱状图
+ Z% E/ ^. I3 f9 Nouttextxy(x+45,y+10+100,"IO");# r3 V5 J- f, T" b: ?
outtextxy(x+40-15,y+10+200,"change");$ [: A" t9 |' }* Y
rectangle(x+35,y+30,x+75,y+110);5 [& T ]- w, m& _5 ?
rectangle(x+35,y+130,x+75,y+210);
0 E* m" U, P9 I) hrectangle(x+35,y+230,x+75,y+310);7 s0 ~* o, L8 U/ P0 F/ d! d
outtextxy(x+180,y+310,"SJF");- a9 L1 a3 S. I
t = (float)com;
" j4 ^9 E4 r" H. Etemp=(t/101)*80;
( D# j% }, i& _1 p7 _fillrectangle(x+35,y+110-(int)temp,x+75,y+110);9 _4 O* G1 ~' B* {% }7 s" m
t = (float)wai;* Y" {" y+ ]# w+ f: v- F# t6 |
temp=(t/101)*80;/ T( G3 r7 R- Y" s5 U( H0 R2 o. c# B
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);4 x4 |" O8 m d6 q
t = (float)cha;
& U+ g f- e$ h+ Ktemp=(t/101)*80;$ y( D1 F# E2 z. S
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);5 J/ {3 N6 c$ I/ X/ o& _, r. u8 ?" G0 G
for(i=0; i<3; i++) //画坐标 high=90,length=250
) Q* b3 W, ?4 m4 U. \{
1 x0 X$ f: H6 l( l7 B1 m" e2 L9 x j. {6 Eline(x+100,y+110+100*i,x+350,y+110+100*i);
* `7 }: L5 }" O( P* _line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
1 G1 ^5 Y y) M: u% U$ K' M- ^5 v- Pline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
, V! O8 L! H8 w. g* l$ i* Z7 l$ y$ F
line(x+100,y+110+100*i,x+100,y+20+100*i);/ u- S$ V# o7 b
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
8 Q# w5 q" i( {line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);& P, V8 `0 o- T! ~* p
for(j=0;j<num-1;j++)
! ~& ] g# X6 Q. t" C% {# J2 g{$ E+ j) ?" C2 J! j, |/ I9 J& B+ V: d
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
' n% q% M# T: @! A& O1 P; cline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
/ U& E2 X p5 K& Y* Lline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ! _/ g3 d% n4 w# c. Q2 F; \- n
}& M B8 D$ ]- X) r; N4 T" F8 R9 z
}! W7 u% v5 r) s8 ^+ q
}
/ I1 d! @/ V: U1 ]& ]else if(FLAG_SJF==1)7 o2 t: L( z6 S6 E4 @/ h- m
{" n* S _, }9 `3 Y# H; Z7 M) j1 L+ D
x=0,y=0;
* q+ E1 X6 }& H* T! ofor(i=0; i<num; i++). V1 B- @7 W1 U
{& x V: }. Y: k$ v0 |
t = (float)info[0];
9 S9 j5 T; [9 ~" F2 ]2 B/ H, |temp = (t/101)*180;
7 c9 ~' p5 ]; F+ t0 [. s3 apos[0][0] = (10-num+i)*50+x+650;
, o0 @3 t; t( ^) g+ @6 ppos[0][1] = y+210-(int)temp;/ w$ d; T5 c Q& A
t = (float)info[1];
0 y$ O X8 }# y% |! Z% n9 x7 ptemp = (t/101)*180;
; P8 w8 [ ]* O) D! Kpos[1][0] = (10-num+i)*50+x+650;
2 z/ ^9 M w/ C7 R$ u* K* Gpos[1][1] = y+420-(int)temp;8 { M& W; q' l) G- A
t = (float)info[2];
2 X0 A/ J0 e2 n( a) Gtemp = (float)(t/101)*180;
( u$ |& `, A, v5 t) dpos[2][0] = (10-num+i)*50+x+650;9 b [, F- P4 P0 N7 T! v& T! {
pos[2][1] = y+630-(int)temp;+ v/ z) k. B+ ] W
}$ X1 k% x# L& x4 U$ @, k
clearrectangle(x,y,x+1200,y+650);
0 `4 G5 l. O; M6 J1 Y, Rsettextstyle(40, 20, _T("楷体"));! w( `( ]' J* Y3 P# T. ^7 |
outtextxy(x+50,y+50,"SJF");
' n- C3 d2 {+ j: v; q _outtextxy(x+280,y+20,"CPU"); //画柱状图
g2 c' ^7 T6 |" ]3 pouttextxy(x+285,y+20+200,"IO");6 E2 V0 b5 Z1 P) H! |
outtextxy(x+250,y+20+400,"change");& v; B5 R2 W: ^: a
rectangle(x+270,y+65,x+330,y+215);# m' w6 O& U: J' T( S
rectangle(x+270,y+265,x+330,y+415);
9 x3 A5 ?9 \5 |& trectangle(x+270,y+465,x+330,y+615);
5 o" G; }. Z; L2 y% h+ |outtextxy(x+290,y+620,"TT");$ k+ m# ]0 n; q" k: {
t = (float)com;
# E, k9 ]$ |: f' Y( btemp=(t/101)*150;+ _0 b5 k8 T' h$ D
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);) D7 F( ?0 F8 i% k" x e
t = (float)wai;
. t; J* P ^) c: i2 ?1 q3 }temp=(t/101)*150;2 q0 r6 Y; i4 }5 B# a' F+ K9 E
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);1 m- ?8 t+ U# I
t = (float)cha;
- @7 p% I8 Q s$ ?temp=(t/101)*150;+ J% o- @& U' N2 n' b* N* _
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);3 {6 E$ V& g3 Q* i5 `4 y* {
for(i=0; i<3; i++) //画坐标 high=90,length=250( l( z) G. H/ j# q+ j8 ~+ [$ v F
{
' I z9 t6 H* m+ t) D" g$ |line(x+650,y+210+210*i,x+1150,y+210+210*i);
) n/ L u2 X% p( C. B3 u1 rline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
/ u! ~# }- w9 n% J, ]line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
3 A9 @% x5 r" L B
) z6 G C3 M5 b: o3 T3 Y- z' z# p* Lline(x+650,y+210+210*i,x+650,y+20+210*i);
! H( ~$ b1 r) q- ^line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);: L( y/ a% W' d$ x( G v* E
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);" ?* y7 q6 A! I) z$ B3 v0 t
for(j=0;j<num-1;j++)
4 I/ z5 Y% D& g8 u+ V4 t4 n/ W8 J+ k7 Z{4 D- G0 u4 n: A+ C8 T$ n
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
W( C; g( A+ C" y# Q, {line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
4 s% b2 a9 W* a) o+ @0 Sline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
; P; a2 i9 e) q' J! f" q}- k; V6 T0 I1 }8 k5 E: h
}
' |3 v; Q4 G$ m7 o, N. _}1 ]: g% \; x% b& U) d3 X
return 0;: _2 b8 Z/ X8 W( j/ y M( d
}# R8 n3 n e2 f
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw), @; M5 v! ^3 \+ b- a7 l
{
8 Q+ ?. @+ e# ?& Q& nstatic int compute=0,waitio=0,change=0;0 Y9 z1 w) e+ ?1 h( x
static int computeLast=0,waitioLast=0,changeLast=0;
: r! P4 @# w D! |$ Lint i=0; P1 _4 h* A6 s/ H
if(draw==1)
8 v3 n- ?" O2 u4 x3 S" O% M{
R* H7 @$ ?6 b) L0 l# g( t//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
& u* v8 W: X/ {% v+ H) RdrawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
) J* e5 s* B1 J% ocomputeLast=compute;$ p! [5 ^0 j% F3 y" _; x' v
waitioLast=waitio;
: U- |% q4 s, KchangeLast=change;7 K* u- F3 {7 p. W, E
}: X! q( J8 w* u1 l7 g
if((* memory).p[0].flag==ready)
# k5 Z, x3 U& R* O$ i$ }+ r* Q7 X(* memory).p[0].flag=computing;& a* y0 y' Y( A% N S2 V) B, c! K+ i
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
6 R: t3 a/ q$ h% K+ L{* ^5 N; |1 i: ]/ ]: N W9 Y
i=(*memory).p[0].computeNum;2 K5 r/ g: G4 A
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
5 r0 O* j/ S! \1 a5 H; L+ o& N{ c7 D3 J. T' } v6 t, f
(*memory).p[0].flag=IO_waiting;1 [. L$ x+ @# s4 w
(*memory).p[0].computeNum--;
& ? Q9 v3 ^( V4 Q/ V3 O, N1 }6 i- @change += exchange_IO_Compute;6 L- c+ n1 Y' t' J! F2 f- w% t
compute++;
) J5 Z% ~0 T% r1 }: W}5 i* U. w3 I! N
else
6 F$ p( D [: L7 Q' o3 ^+ T7 S5 U& m{4 l2 n; h! `5 Q; T# {5 a
compute++;
& u4 _$ q7 W8 z- h6 q& j" o}
& O0 ?6 g8 Z) a# c, [' k}) _ ]) Y0 N) f0 a5 a$ w
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
6 g0 J2 K8 X6 A' S( ^7 R{
" L/ W3 q8 N2 h! D6 z0 l- A9 L4 I) @9 H. h
i=(*memory).p[0].ioNum;
4 K8 s" u0 O6 U6 ]3 }if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed' z' A7 Z9 g/ B. D! [
{
2 E) u& P% l5 g! c(*memory).p[0].flag=computing;
7 i: T8 J( h/ N) P(*memory).p[0].ioNum--;4 _5 S9 R7 G+ Q- ~1 W5 Y
change += exchange_IO_Compute;
+ ?/ Z) r' T D. m5 d5 X- Swaitio++;; c( N9 @3 U6 ~6 S7 d6 T0 z# E
}9 A2 \! c2 K/ w& Q
else+ L' j" k6 y% W9 a; \
{6 ?7 L/ n D/ Q$ H6 L/ K
waitio++;2 S' j7 O* {! ~$ G, r! c, ^2 u
}7 l ^' c6 q# h( A5 Z
}( V3 e2 _, w/ y% G5 l
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)( b8 b0 C5 F* c5 }$ @( v
{: y: Y$ H8 r4 k; o, Z
(* memory).p[0].flag=IO_waiting;
3 \. q/ |" D4 d, fchange += exchange_IO_Compute;9 @7 X8 D' J+ Z6 Z
}, [/ W" s& U! a6 g# Y1 |1 q; V
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
+ M" J* n9 j+ O* I. A6 u: \" V) R. x3 t$ v{
9 g o# \9 \% ]2 v(* memory).p[0].flag=computing;. }, ~* J$ u. H) x
change += exchange_IO_Compute;9 S7 Z4 c& R6 D5 t8 G' E
}8 ~( }" h3 K9 R& _
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
% a: G6 w- \) y4 ?& N& W3 b{1 A% C9 g& l' R' O# R) o7 T9 n
(*save) = (PCI*)malloc(sizeof(PCI));
) y# H/ t5 c ]! p0 p% }" h(*save)->next = NULL;
# f6 @ o" I5 }1 `7 U; H(*save)->processID = (*memory).p[0].processID;7 n% P' j- c+ {: Y& B% P- F
(*save)->comeingTime = (*memory).p[0].produceTime;7 ]9 R2 S9 S% Q
(*save)->askMemory = (*memory).p[0].askMemory;7 I: O* t6 Q$ `8 C
(*save)->compute = compute;: t: y! W& ^7 f+ \' h/ O2 N+ b
(*save)->waitio = waitio;
4 l0 W2 k2 C; ]5 R/ ^(*save)->exchange = change;* ~$ P$ _& b& t# R: b( ]
(*save)->completedTime = systemClock;
! W G1 D4 [( R* g/ d X(*save)->runningTime = (*memory).p[0].runningTime;2 i/ l8 _! j" ^6 |
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;4 T1 \: D2 w8 G. c, `) R1 b
compute=waitio=change=0;
1 c3 |4 g8 s" q3 F N4 \0 ~6 YcomputeLast=waitioLast=changeLast=0;. O! f, D; j0 a. b7 l5 z
High_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);
% e5 s5 t7 _. ichange += exchange_process;# d& y9 E. f5 ~4 G, S; z4 X4 Z, H
return task_completed;
- n( T) O; s9 y: p: [+ u0 I7 v% V}
0 B. }3 r' Q, C6 zelse& U' V2 `! U1 D' A
return task_not_completed;
& v3 {! g7 H% A6 ]/ F/ V# n0 X) H}
$ o8 _0 }5 T4 ]% X) M: wint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)9 b {. { O) Q# o
{; L+ \) S; S3 F4 A- f- {3 y
static int waitTime[initProcessNum],i=0,j=0;8 z" i- Z E; W
static double HR_ratio[initProcessNum];3 @% W' a; l7 v/ K( y+ y
if(flag==0) //初始化数组1 i, o4 i6 h+ m! C0 H, u
{
7 e9 s+ s) B0 s& s# h. hfor(i=0; i<initProcessNum; i++)
, M6 d* K4 j) _) e{( s3 b7 G' `* N6 Q4 A
waitTime=0;
* M5 p$ T% i9 [& RHR_ratio=1;& K/ `3 G% a$ @( C6 K) \
}
. C; O7 \% j9 v, Z# A& y}
* A% t# }% ^7 y. [# cfor(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比
- s* f. X+ Z) k0 J6 X, B. |% y; c) d{
" x4 P6 _" Z6 u1 T* CwaitTime++;
3 G- C$ g" J& _. A/ e# }HR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);
# O% m& L, ^) J. v$ [4 Cif(HR_ratio > HR_ratio[j])
7 ^5 l1 d. ]- x! m: t9 Xj = i;& M$ X3 j7 u. R* k
}4 h' C# v& \ y
if(dispatch==1) //需要调度一个进程到内存中执行
: b/ w: W" v* H. D( Z q8 |{
. Q: {# c; g4 d) J3 Gif((*storage).p[j].askMemory < *spareMemory)' u* r2 {) w) j( ~( k
{
; t2 T8 p0 T% x9 X: d3 V# ](*memory).p[0].askMemory = (*storage).p[j].askMemory;
7 F6 e" @% l- Y- O0 Q8 s5 K(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
* g2 m3 W( A# R* V7 a(*memory).p[0].computeNum = (*storage).p[j].computeNum;
" l2 O+ ]+ K& Y. P5 z(*memory).p[0].ioNum = (*storage).p[j].ioNum;
" u0 D8 [2 L f(*memory).p[0].processID = (*storage).p[j].processID;
, D0 x) e: |& x9 Y(*memory).p[0].flag = (*storage).p[j].flag;5 L! w7 q9 l" O% k- p8 [
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
( U3 G* Q3 H; _$ K a9 f, j(*memory).p[0].computeTime = (*storage).p[j].computeTime;" v, N, ~+ k( ~7 e- S
(*memory).p[0].runningTime = systemClock;8 _3 M9 L( n& `% X
(*memory).p[0].produceTime = (*storage).p[j].produceTime;
* V7 E% |$ }7 `4 O" k: Qfor(i=0; i<(*memory).p[0].ioNum; i++)
- }. g; Z3 c0 O' a(*memory).p[0].ioClock = (*storage).p[j].ioClock;; N# }; U" ?% T9 k1 s7 i4 D4 K
for(i=0; i<(*memory).p[0].computeNum; i++)
0 j* z: x g8 X' U8 G(*memory).p[0].computeClock = (*storage).p[j].computeClock;' _4 ]& P, {: ]$ m. F0 S. N
(*memory).proNum=1;
! u. {" U; g: k+ K S' V4 F*spareMemory = *spareMemory - (*memory).p[j].askMemory;
% P1 d7 U1 d7 L) w. ?9 \) o$ K- Lproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
7 _ ?# y' j4 q) v/ f(*storage).p[j].produceTime = systemClock;7 x+ Z, W6 G, J# F- Y
MAX_COMING_TIME = (*storage).p[j].comeingTime;% H3 Q& f2 x8 d# A+ t" v& M, G1 [) e4 }
waitTime[j] = 0;
8 f6 d, A0 o2 JHR_ratio[j] = 1;2 K1 i7 r5 T$ V2 a- W# ]# j9 I
}! |! U$ g/ V5 Z8 N6 w- [* \
else
) x, f U5 W% _( ]& c{
& B, N7 N0 Y5 W1 Sprintf("A process ask for a memory overed the system capacity\n ");
" _6 q/ [7 l/ s! i9 vexit(1);
/ c9 `- ?2 @( ]& O/ j- `7 F}' [2 D9 L g; W8 J- D9 |( i/ j
}7 | c+ f! W# l. b4 q7 {7 V
return 0;: x' F8 v. [& U/ v: g ]
}& ?8 Q) @/ U0 G$ y! b! A
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
) W9 k/ \8 e" a& w: N! d{* `9 o4 O" P# h0 z/ q0 ~
static int compute=0,waitio=0,change=0;0 H c8 [$ f0 ]0 U; X- H5 J! T! [
static int computeLast=0,waitioLast=0,changeLast=0;; B( |* I1 N) ?4 x: R
int i=0; z0 B6 O1 o1 ] w# w9 c
if(draw==1)3 w/ T% N. T$ U O* P0 L
{) q# r+ U" s/ ^7 n; N Q/ X
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);6 A4 t7 P/ g6 W8 \* x1 b6 }8 C
drawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);) i+ I3 l( ]" q! l) b
# d- I6 |$ T6 N! ~+ ?5 o: G1 }) c& i
- P6 l& Y0 b' Q3 e# r' IcomputeLast=compute;
# a, |! M+ J) ?- n7 D/ n k* kwaitioLast=waitio;
, E8 \1 V; c8 }( d- A3 @changeLast=change;
. o+ `+ ?* R* @0 t. P- I}
8 \4 P& t$ t, Xif((* memory).p[0].flag==ready)* Q. ~! E$ x% W- } D
(* memory).p[0].flag=computing;& x8 P6 Z$ X n; y' i0 Z( H+ k
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)5 J9 r) I. j4 l0 E
{* I! V0 b9 {9 |, t8 D0 T
i=(*memory).p[0].computeNum;& Q5 k) G5 u( _
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
6 ^1 Y6 r2 C, L6 S7 l" p" B7 E{
* o* t Q# ~: q/ C8 R( o; O* L8 L(*memory).p[0].flag=IO_waiting;1 I" U5 B9 x0 c1 C
(*memory).p[0].computeNum--;( u3 n0 O! E% C1 x N b
change += exchange_IO_Compute;" T2 Q r9 {7 A6 I+ s9 I) C
compute++;
$ X6 v* J8 Q% W; ~}
/ U; P. ]2 x$ a6 h6 pelse
' b1 v9 c. ~2 f8 Z{
. a8 p; N; q/ Z; [. l+ {compute++;
, f, t) L' x4 O* l! E}
. M2 L+ h( l; d, `5 O}
$ O9 g" B9 h# P. n( velse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)7 S9 b4 g) f# D$ Z
{
! {2 [2 u6 b0 [3 w( l
9 r* Z, f( X; G% d8 ?i=(*memory).p[0].ioNum;
/ @% e) J7 h. K8 S9 @) Bif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
* Q: R) u+ T4 ]4 n; t: m{1 E! R! \! ^5 x; H
(*memory).p[0].flag=computing;
2 E; _& J& |3 C) X$ r(*memory).p[0].ioNum--;
2 r: [. A2 M8 Q& \change += exchange_IO_Compute;' h$ O7 Y2 O: X' \4 M$ C9 J( j
waitio++;
( ~& Z* h& d9 {" I C5 M h7 U+ i}9 w. ~" d) N6 T' F* H
else
; z% S: G* w; z{
9 q* F' W4 [! v. | o m0 T( w% O9 ~3 gwaitio++;
: y+ y/ i/ c: ?% F N& ?}
' C1 I; C* ]( n+ F( d$ Z1 {! J}6 m! H/ g7 s4 x+ F" ~
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
1 m- {; s Q# H: |- J7 S/ k' K{" N1 ^5 s2 {9 g
(* memory).p[0].flag=IO_waiting;
* }0 o; l; G" ]# Rchange += exchange_IO_Compute;0 m/ w# M' @7 S5 P9 l$ P
}# I7 r' N3 V* R- k
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting); o3 L" J' m! N: t
{
) q- ?- J3 d% L6 P(* memory).p[0].flag=computing;: m& L$ j) M' _( Z+ n. a$ F
change += exchange_IO_Compute;' J, X; @3 h9 j! \- I
}, t; {# `& n% r: u+ K
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成9 c. ]% @( d ~' u$ t
{7 K, h/ {0 _. U: G' h" k5 r
(*save) = (PCI*)malloc(sizeof(PCI));
1 l6 ]; v" I; T5 c(*save)->next = NULL;
y1 K" R% Z f8 z. P6 V( I) {(*save)->processID = (*memory).p[0].processID;
) r$ q. u" e I8 x& r(*save)->comeingTime = (*memory).p[0].produceTime;
! b4 P( {: g0 x- W; K a(*save)->askMemory = (*memory).p[0].askMemory;0 c& m E" r/ u/ e8 F" i% o
(*save)->compute = compute;: {& @, F& }1 s
(*save)->waitio = waitio;* s% T9 W0 |8 @
(*save)->exchange = change;4 {% Z. z; L5 t9 P6 ~% U9 P
(*save)->completedTime = systemClock;
" ^6 N; ]# q4 ?+ E3 V% o- W(*save)->runningTime = (*memory).p[0].runningTime;
6 a$ l* Q- @! w5 d* K/ D, S# E/ P*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;
4 z1 e3 O% `$ E e2 I; ^5 c. Mcompute=waitio=change=0;! ^0 C. D7 Z/ w" w5 q& k
computeLast=waitioLast=changeLast=0;# c6 m2 B q) v
Priority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
2 D4 r* M' h3 n( y( j0 b( @change += exchange_process;
9 `) M4 b- s% O9 Qreturn task_completed;
0 _ v5 J& V' [+ i}
& Y" n- w9 S7 w- n1 {6 b4 R4 Relse+ }" Y# `: B6 G
return task_not_completed;
# ?4 B, J8 r/ I. a0 D B}
, c: ^. ^' m( \) c9 qint Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
& U: x+ V4 V* T{
- y% J2 E) H/ M+ f( g. mint priorityNum[initProcessNum],i=0,j=0;
( g& l. x3 N9 n9 C* ?4 C3 @double temp=0;
* J; ~* _! U* T* Q2 a$ |for(i=0; i<(*storage).proNum; i++) // setting priority to each process; q0 a' c2 G5 @8 l0 u" J0 b
{
; X) t4 x& m% itemp = (*storage).p.computeTime/(*storage).p.ioTime;
, G1 s g" Y# ^- {if(temp > 0.8)
0 g, q% W/ J, C- H9 G$ |priorityNum = 6;
' ?, Y: |) Y$ d9 s, D1 uelse if(temp > 0.7)
1 ^( j6 |, K9 y0 GpriorityNum = 5;
/ ~7 b3 c' y, H4 felse if(temp > 0.6)
' {' D4 ]& V0 ^# c1 QpriorityNum = 4;
$ o" r0 G- `$ A4 i8 @% `2 _! K5 G5 Belse if(temp > 0.5)
6 r3 \; {& m7 G$ z. BpriorityNum = 3;
. _$ ?" c. D. Q8 S2 ~else if(temp > 0.4)
( I$ [3 _! J9 _" H opriorityNum = 2;( Y6 S, `+ R& z) g; F
else
8 R5 e1 U# Q! n2 F4 apriorityNum = 1;. R' U. R& c# J0 Q% ?
if(priorityNum[j] < priorityNum)
5 @1 x0 X9 G/ [& ~1 J& Yj = i;
o4 `% u4 E* ]6 Y}) z- d8 V) c0 Z, b7 e g
if((*storage).p[j].askMemory < *spareMemory)
2 l* q+ P( P/ {/ ^1 s, W{, d3 v. a% Z5 q, M1 a8 J
(*memory).p[0].askMemory = (*storage).p[j].askMemory;
2 |. ~7 k0 ^$ Z2 [; I- p6 W(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
$ {: t3 a1 y3 A(*memory).p[0].computeNum = (*storage).p[j].computeNum;. {! t' T7 u. d- Q p
(*memory).p[0].ioNum = (*storage).p[j].ioNum;# d/ c9 s) t l6 G8 b
(*memory).p[0].processID = (*storage).p[j].processID;
) c& K( q0 x3 _8 t(*memory).p[0].flag = (*storage).p[j].flag;
: o7 I# ?5 E+ n2 h: R6 `! P. ](*memory).p[0].ioTime = (*storage).p[j].ioTime;
8 K8 x3 B( X5 | s: d(*memory).p[0].computeTime = (*storage).p[j].computeTime;2 Z) z6 p6 m7 D' }
(*memory).p[0].runningTime = systemClock;
, C0 v D* `' {+ V6 o, ~(*memory).p[0].produceTime = (*storage).p[j].produceTime;# B1 e- o( `2 k
for(i=0; i<(*memory).p[0].ioNum; i++)# C( {' {" }( Z) H( W5 m
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
4 D3 x/ ]4 K+ @3 }% i+ gfor(i=0; i<(*memory).p[0].computeNum; i++)
; n) d7 x k5 v5 i* g/ p. n7 @(*memory).p[0].computeClock = (*storage).p[j].computeClock;
# M+ T8 v; W! L8 e+ R1 x6 @( J(*memory).proNum=1;7 q5 j* `3 l' m' I! M9 L
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
( Z6 d( c+ v1 h7 _; M4 w4 Gproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程+ c8 @( ^8 F: u- B) p
MAX_COMING_TIME = (*storage).p[j].comeingTime;% w7 z F$ ~6 ~5 o( K4 P
}% `+ J9 n1 ~0 u5 o- U# {
else
- l% F7 V9 d' x* n; _{
+ U0 S) D) c* x7 ]% b' m* v$ Tprintf("A process ask for a memory overed the system capacity\n "); `! P' L' v6 a, w
exit(1);; q3 n, }- w) Z4 I+ I
}! n& Q( [! I2 E
return 0;- m i N2 X0 z0 V7 z7 Z8 E- h4 j
}- x: J4 l$ q' U5 O; i- d0 i- Y
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)+ N) \4 ? c! w- `; X! W E! y
{! V6 y0 J) G9 Q* F7 ?! I4 w$ w5 Z
static int compute=0,waitio=0,change=0;* p$ k' K. B8 k" _7 n0 o
static int computeLast=0,waitioLast=0,changeLast=0;
4 }# h/ \, B% ]8 E$ ~& fint i=0;
# Q* J8 z5 x/ U7 O7 q) k3 T* rif(draw==1)
9 o. g0 u9 }* P; v7 D' K5 d{3 T4 @; n/ z0 R4 P: s. t$ c
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);, ]" b1 L! V1 s) L7 D5 r
drawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);, ?) V# a' I, I8 y, m' t/ y
& c) o) L3 v% Z) P6 k5 j( O
2 D5 X1 K& _! @4 s2 X
computeLast=compute;7 g9 f7 I" I- B3 K
waitioLast=waitio;
4 O- k# Q4 C) w* M+ u$ z2 t: jchangeLast=change;/ w$ L( @3 H! S7 b/ C p
}
5 G. c: E! O- ~( P. W- U' Oif((* memory).p[0].flag==ready)" @ N5 R' O) M$ q
(* memory).p[0].flag=computing;3 s, B3 S6 R8 s- }5 d0 A
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
1 H7 t" p4 v! V8 u9 d3 h$ \1 b{
4 H7 T" N6 `' vi=(*memory).p[0].computeNum;
r9 d# K; O3 }4 n$ n5 y3 hif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
- H( b. u# {" A{
6 X9 w: F; L+ h) f q3 K4 K(*memory).p[0].flag=IO_waiting;. [/ ?; G8 a3 n N2 j4 f; u
(*memory).p[0].computeNum--;
$ E. f. j; I, r3 s& ~' `change += exchange_IO_Compute;
- E: d3 X' N" G8 |' H( n+ g2 Ucompute++;
, k; s/ T; |9 B2 E8 y}+ c; ?! a, u! F5 V, M/ Z# F
else
( L1 X4 V4 J$ ^2 Y{0 B2 @# u# }( [6 h/ b+ h
compute++;; |2 h# |- {" \ A% w( n
}
}, w" J! K& ~2 e; L9 O}$ |5 j/ a& ?0 g8 b# d3 ^
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)$ h2 K; F6 E, Y2 D1 @
{5 ~* r8 |, e b2 x+ L5 |0 \
! b1 b3 z$ b: ^9 f
i=(*memory).p[0].ioNum;( @% K8 C+ O. f* C- u" t8 `- n) ?
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
6 n. i1 @4 g0 f* T, @{$ ] d7 p) s S6 W8 d& V& e
(*memory).p[0].flag=computing;
- W3 C' C: J6 p: E3 s* u(*memory).p[0].ioNum--;
O9 J7 b6 N* ^3 X7 Gchange += exchange_IO_Compute;! V' q3 _. a$ s- ^
waitio++;
+ A2 |3 A8 ?; v1 e5 m/ u}
8 @1 N$ e, o$ q5 f0 celse
: [8 a# ^# i1 M2 c/ w6 M{
( Q W' A9 X9 k* }, _5 Qwaitio++;; @5 L7 u6 Y$ Q0 R ]' }. g0 n
}4 I i T( N. \8 X' r& f9 e
}5 ? Z5 Y$ U' q4 G- o3 }6 X
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
4 Z/ {8 @9 N/ A( W/ q{
2 W; s8 |. ~9 p(* memory).p[0].flag=IO_waiting;# R7 \, A3 g1 k# R
change += exchange_IO_Compute;
& R5 W U( N1 h}! @' ~3 W7 ?; E7 Q: ~
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
: ?8 N2 J3 H8 g. ~4 V2 R& m; r5 A8 j{
( V: h7 ?% i4 J5 s(* memory).p[0].flag=computing;
6 k( i9 r9 s4 ]2 Z. y3 Echange += exchange_IO_Compute;
4 ~: T* G; ?0 ^% N' d: G}
. f, ^* Z" a w7 z5 i$ K! Hif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
1 D+ s! R. ]; i4 Y- h! [{- t U C" t2 y. Y
(*save) = (PCI*)malloc(sizeof(PCI));) |/ K" O9 S6 x, }% U1 Z, O
(*save)->next = NULL;- F& W( a# _# i7 V7 H4 N, L3 i
(*save)->processID = (*memory).p[0].processID;- i) Z7 H+ C# z8 ?. Y( Y ~
(*save)->comeingTime = (*memory).p[0].produceTime;
% `9 m$ e1 V% T' K(*save)->askMemory = (*memory).p[0].askMemory;
n& t2 e3 ]- u6 `. z(*save)->compute = compute;) }/ {5 y6 i2 E+ U$ T% R
(*save)->waitio = waitio;
+ p; M3 ]7 e1 y! h- X$ D& C3 x(*save)->exchange = change;
" w2 K8 |2 W+ q2 U5 U0 Q/ h" `* b(*save)->completedTime = systemClock;
- R3 g8 a' H7 o% @; t# M(*save)->runningTime = (*memory).p[0].runningTime;
8 \9 L! p4 X1 p*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;+ Z3 D- h0 s/ `- D) A( K& z) p
compute=waitio=change=0;# u" { B k. ~! m6 ?9 o* x3 A1 i
computeLast=waitioLast=changeLast=0;
% ?4 `7 n; @5 P6 _) BSJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));, P) M- N6 d& @6 I% O3 L
change += exchange_process;% p- S9 ~+ W; p* b9 H# `
return task_completed;
. G j3 h# |: P' O: W}* `4 D7 l7 O o1 A* ^
else
2 \0 R$ @0 e. q3 A9 G' X4 yreturn task_not_completed;1 c' I2 [- o; ^0 n: a
}( V- K a8 `* v& g. l' l1 S
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)6 q9 o4 x% G* q+ H. @' p) `' \
{
9 |; d$ c' t; Z2 [int i=0,j=0;; x2 `: x2 K- U
for(i=1; i<(*storage).proNum; i++)! Y x; r/ V- A8 s8 V- a% O+ U
{$ K9 O% q, H' M- X: g- d" ~' [# @4 U v0 j
if(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))+ w& v5 Y' g' n; k3 a+ U/ Q
j=i;
) D) C4 j7 q3 `! }}; q0 v1 y. H; V9 v. h/ y8 p* g6 r) q
if((*storage).p[j].askMemory > *spareMemory)
+ I: `, c& L0 a. q4 K6 _' B{3 W: f6 k/ J, L! H
printf("The memory asked is overflowed than the system memory.\n");
- S' q/ y: v4 ?+ S' Xexit(0);8 G0 e# {. G; z+ i3 E7 |
}- d2 }+ R! ~3 A( u
else9 Z/ K1 f% h8 c/ h# I
{9 Q0 n, V. u6 _) R& J
(*memory).p[0].askMemory = (*storage).p[j].askMemory;& Z2 Z A) Q0 e
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
8 ~' ]2 O# j9 d) L9 l: U1 ?(*memory).p[0].computeNum = (*storage).p[j].computeNum;
& Y5 f" {5 c% [. X(*memory).p[0].ioNum = (*storage).p[j].ioNum;
( O9 N! D8 F: ?(*memory).p[0].processID = (*storage).p[j].processID;
! X4 [7 N4 S: L* d(*memory).p[0].flag = (*storage).p[j].flag;
; U8 L( e) }9 H(*memory).p[0].ioTime = (*storage).p[j].ioTime;
# _" Y2 k# L z @( L( P$ K(*memory).p[0].computeTime = (*storage).p[j].computeTime;) p2 p0 F" d2 m; S3 d
(*memory).p[0].runningTime = systemClock;, e+ k5 |( x. O3 V
(*memory).p[0].produceTime = (*storage).p[j].produceTime;2 J# L% [( w& G+ ^$ r* y
for(i=0; i<(*memory).p[0].ioNum; i++), _/ X7 W0 x! x4 [& H8 N
(*memory).p[0].ioClock = (*storage).p[j].ioClock;2 I/ E- q, e( ~) G; h/ L: ^4 O
for(i=0; i<(*memory).p[0].computeNum; i++)
, E( ]5 k4 T% K o4 ?& }(*memory).p[0].computeClock = (*storage).p[j].computeClock;8 s# l a# o V
(*memory).proNum=1;+ h: m U* O( f3 H
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
7 {6 V0 P( [! R) ^& Mproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
% ]" x8 h0 e- W9 ]/ f4 s UMAX_COMING_TIME = (*storage).p[j].comeingTime;
8 D$ |0 i7 }, b" h" c}
2 b% a/ x" m5 b8 o) p) _: t6 ~return 0;! ]& M, @* `* k( ] I3 B
}
6 N2 o& `% Q3 d/ N/ ~0 G; ]int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)2 O F% P" Y2 J! q) Z5 ?' r. M( u
{8 d. I' M, s3 h% M/ A E
static int compute=0,waitio=0,change=0,clockSegment=100,poi=0;& M4 Y1 a* k$ c' M) C
static int computeLast=0,waitioLast=0,changeLast=0;# @; L( o. J9 t4 _) I' h0 Z2 q5 j
int i=0,j=0,k=0;8 |& K; y k% t# M1 e
if((*memory).proNum<=0). J$ n6 Y8 q: k- k
TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1); H" x: o6 R# L/ v- ~! e5 V$ J
if(draw==1)
1 ]3 Q* y& f! T+ b{
0 i2 C/ t; L3 p//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);( u! A) z" d6 L( `3 s- Z& j
drawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
( T& ^+ l0 a% b
8 B: l C, [+ ^3 Y# ~
& h3 |5 j9 \; t3 W0 c7 A2 ScomputeLast=compute;+ ? ~+ ^/ B! Z1 S* {
waitioLast=waitio;
8 \7 S/ C% t5 K% ZchangeLast=change;
, Y& O0 x: p) r0 L}
3 Y$ y$ O7 P+ }* iif(poi>=(* memory).proNum)
8 C! U5 t1 {# Q: O2 |. Q# ` L: V" dpoi = 0;2 C8 B# F8 W' D, G8 ~5 m# b
if((* memory).p[poi].flag==ready)
5 l) R0 p7 p5 H# z* q7 D2 D(* memory).p[poi].flag=computing;3 [$ g1 s" i6 c3 H) U, d: i
if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)
2 b6 K/ C/ b2 y$ E{
9 s' p2 s* Q2 z* I: z7 Q bi=(*memory).p[poi].computeNum;
2 L5 G0 w) e7 V* B. t0 V) W& T# tif(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed& c/ y4 F4 z2 J" P0 R: I
{- R, A6 U8 t$ _( m8 V2 a7 @
(*memory).p[poi].flag=IO_waiting;
7 n6 d9 I2 ?! {(*memory).p[poi].computeNum--;0 M" b! s& [1 q- O* u- D
change += exchange_IO_Compute;3 S( \& G+ j9 a* r! T, Z
compute++;
1 F4 @! K1 Q# D9 X}
/ _, z# ]2 l8 d4 |, v( h0 _else4 M1 m% L( d P( m
{
4 b8 _+ d4 h& Z N: y( l5 Ycompute++;/ o8 M+ i: o; `) u+ Y& | i
}
: F( r$ K& R# J" r2 P}
5 \: b+ | b( C/ E4 Yelse if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)3 ^# k1 ]$ L: [% F
{
4 M# h9 C5 j0 n% D$ \0 E; _$ q+ D) _% C) ~! @
i=(*memory).p[poi].ioNum;+ g: E; q1 B- N1 k4 X! C! Q
if(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
2 F5 e5 _: O O+ \# f, U; \{$ Q$ l, ^2 t& v
(*memory).p[poi].flag=computing;
! w2 e: ?' o$ _! }* w. o% S(*memory).p[poi].ioNum--;
# w! E8 c/ |" B" a( L/ tchange += exchange_IO_Compute;
( G0 S/ k- C, D& gwaitio++;8 `5 `- ]. \9 j# m, Y6 ]
}9 ^4 {; d+ _2 r+ P" _9 }; M
else* Z _" K. h8 [+ w4 K
{) Z; P6 M( [! A4 C8 T5 G% I( d/ G
waitio++;) Q/ X/ o: H* n7 `
}. Y% ^1 B; X/ [- K4 C9 C
}8 W5 Q$ C) M' x) q
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing)6 }$ L$ r" t; ?, @; p$ I1 D8 l
{
0 b8 v: |. o. g' U1 A* T1 `% _(* memory).p[poi].flag=IO_waiting;9 q4 [+ k6 ]& i
change += exchange_IO_Compute;
6 c& @( }" |4 s7 C7 \& n5 P}
" Z: G0 E4 `3 t/ u5 Belse if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)1 r# N! m0 }5 {9 ~# i @ k3 Q. B
{2 Y+ U: Z- o3 I, C) H1 {( q
(* memory).p[poi].flag=computing;( E- G" f. e5 j" I
change += exchange_IO_Compute;, O, P) H0 Q# ]/ @1 E
}
, _- s/ o7 I3 n `; Bfor(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进
7 J% Z$ _; @' n9 p% N+ q+ c{! u* m7 i1 a8 m
if(i!=poi && (*memory).p.flag==IO_waiting)" z- j4 `+ |- q& A* W
{
) {8 S) B8 }7 O2 V) v4 p2 O% yj=(*memory).p.ioNum;2 p f: E4 @& d3 E: ~) ^, L
if(j>0)! ` ?( F9 P C0 d
{$ f0 u* k6 Z7 h9 `
if(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed) G+ s' C& E0 U- S* W
{1 y5 {" K* H) K. Q( c
(*memory).p.flag=computing;- u* A0 c6 X6 U1 [; s
(*memory).p.ioNum--; r: O& i9 x3 x" V2 P
change += exchange_IO_Compute;
- w2 w* n% ]/ p' h! p}
2 y, l( {! B$ h, A}
: P1 U' }% y9 c( f. Q% l5 Q}
9 x6 G0 U8 V& D}: M; c( L4 y$ f' K
for(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程2 m* m4 u3 I" s8 H7 G! O4 `! C
{" Q8 c' O J* t# v0 H
if((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed
5 M8 i7 u: B ]7 O- Q{8 O4 F% i2 n& R8 k" ^4 K; _
(*save) = (PCI*)malloc(sizeof(PCI));) w, c0 G0 e) F3 f$ U- p: E' h) O
(*save)->next = NULL;
; L" v( P1 ]/ o0 V (*save)->processID = (*memory).p.processID;
. c" h' C' k9 ?5 M$ X. \3 D(*save)->comeingTime = (*memory).p.produceTime;- z7 n8 D9 z9 V% l. E0 C
(*save)->askMemory = (*memory).p.askMemory;. |4 v; \, G- y4 ^* L! K; k6 a
(*save)->compute = compute;* i8 R$ ~5 V2 w" f% O. K
(*save)->waitio = waitio;; r2 a0 h1 U" M( }0 K u4 f4 F
(*save)->exchange = change;( C; |8 v% F8 T: u k
(*save)->completedTime = systemClock-(*save)->comeingTime;
7 i# x5 ^- K4 a(*save)->runningTime = (*memory).p.runningTime;
3 x# S; e# }! P! v( V(*save)->completedTime = systemClock;
' G) A4 p, z% e; V: ^*spareMemory = *spareMemory + (*memory).p.askMemory;
- c0 T9 ?) [; n" B2 zcompute=waitio=change=0;. `) @* `+ M' `% p9 J
computeLast=waitioLast=changeLast=0;$ K6 r# N3 k& t6 E9 K% M/ o
if(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入
& }% r$ ]) p8 q+ ]. u{4 p; T) X) e) ^; d
if(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程8 q7 H9 ?' P$ X& v
{0 H8 C+ O8 }# S8 e
poi++;2 s: N. h2 U% z+ I- b- O
clockSegment=2000;
" F8 U* U2 j0 i3 d6 H- E}) G3 w2 s5 C8 n2 R% A
}
3 j& b) ] c; s: p5 d0 T% celse //没有足够内存调入新进程
8 y" \9 _3 q" k* B! n. j# L{
- g& ^8 J3 b/ o; S6 g; y* m3 Uif(i < (*memory).proNum-1)
0 p& p0 R# b: k1 W# j/ I9 `{ g! P3 w; ~9 u' z B
for(j=i; j+1<(*memory).proNum; j++)
) n; O! c1 m7 ~0 p5 ^( I" L{: T; _( Y" q+ r
(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;
8 p$ N6 m0 a) r, A! s' X# ](*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;- q, g5 u& Y! Q$ ?3 M9 ~; K% N3 z. t
(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;
, V# u0 {5 k9 u9 [7 p, `(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;
0 H/ O1 ~- f1 z% A4 _(*memory).p[j].processID = (*memory).p[j+1].processID;" G, S8 s) W. k: K$ C
(*memory).p[j].flag = (*memory).p[j+1].flag;2 [1 l( a' v( q; P, } l4 P) b
(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;
+ V% I$ d8 ~ [% ]# d7 j: v(*memory).p[j].computeTime = (*memory).p[j+1].computeTime; }* h' f# I$ @$ S! u
(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;
% s; c( F6 s$ ^8 @$ X% e7 A# L(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;
2 t' R( h: @; V7 C( U& e5 _8 ?(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;8 ]+ c! Y9 ]- @' ^# `
for(k=0; k<(*memory).p[j].computeNum; k++)
X- X [) ~9 h4 {& z6 k, Y7 I(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];
' @. c3 x- U% Y( v: |8 q& \for(k=0; k<(*memory).p[j].ioNum; k++)
2 B! q3 l: |3 i! b(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];
6 l7 i. @% X5 B) a1 d, L}
/ S5 ?/ Z8 f* N ~if(i<poi)
& Z$ J y3 \9 r& i( m1 ppoi--;9 \2 l; X! f/ Q1 w4 I
else if(i==poi)
5 o; q1 e `$ b h+ f2 L- V1 ZclockSegment=2000;2 {) z0 t) }/ \7 [+ ~( j# Z
}& P; T5 Y! \# g% `' `( {' Y
i--;/ u, o5 n$ a( V6 {2 }
(*memory).proNum--;! e. H5 r+ y$ j) S
}5 Z" W8 V) b1 {# I( v
return task_completed;3 D6 |3 m* F* Y' t* C1 d
}
7 Q0 L1 _. j$ P# R1 T$ e1 }}) i/ k: {7 ]# u* b* v+ x1 o
--clockSegment;$ y, _1 r+ Q. J8 O- S% I
if(clockSegment<=0)
0 ]: c' y o& H/ D3 Y{' }1 z1 ?( g! Z n' K" Q
poi=poi+1;
# Z1 a& E3 v/ q/ ]# Lif(poi>=(*memory).proNum)
1 t& U5 y1 n- ~: Mpoi=0;( [; Q3 E" G1 [5 K( G- W) w
clockSegment=100;" T8 [# w$ A2 K/ s X6 e1 x
}
# [& l9 f( i5 x5 f4 w9 d0 \return task_not_completed;: k I, E- ~, a) r9 o, c8 m
}
+ C* ~5 S$ b# E" u! Z6 _9 Eint TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)
, v. S- A' v' b1 S0 B8 Y) M1 l{0 F8 D; {# V7 D! y4 W2 { t
int i=0,j=0,k=0,flag=0,translation=0;
2 @# |" M& E5 V4 U' z. L; e4 `4 l: |for(i=0; i<(*storage).proNum; i++)/ E$ Y5 T0 g+ }
{
8 {8 v% H" j2 a. ^9 F3 |' L% zif((*storage).p.comeingTime>MAX_COMING_TIME)
, y$ k" X3 \' `) M5 T5 }7 jMAX_COMING_TIME = (*storage).p.comeingTime;. J5 p4 @- {2 ^3 w
}
' i( {4 ]" x! C# q6 }: Oif(pos>=0)
. A9 V2 P" b4 {$ C; j# Y{
. u6 Z0 {7 T6 n1 X7 x% X6 Ufor(i=0; i<(*storage).proNum; i++)/ @7 A4 J8 a( M% A% h
{
7 z5 U6 G8 v+ p+ Tif((*storage).p.askMemory <= *spareMemory)
; `. l9 |4 L/ Q( }3 K% t" L{. F9 T$ q7 a. q9 Q
j=pos;
% B3 p* [" `# n& h8 c; B(*memory).p[j].askMemory = (*storage).p.askMemory;
1 ^: x. o; V$ s& `, _8 A [* v(*memory).p[j].comeingTime = (*storage).p.comeingTime;; I" q v' X6 s5 l" N* A
(*memory).p[j].computeNum = (*storage).p.computeNum;
3 M+ A& i) P4 p8 p(*memory).p[j].ioNum = (*storage).p.ioNum;
% h7 ^- T- a, ` k(*memory).p[j].processID = (*storage).p.processID;$ _1 U. b& |6 U
(*memory).p[j].flag = (*storage).p.flag;
8 T/ j1 j1 n" r& D3 S(*memory).p[j].ioTime = (*storage).p.ioTime;* \- b9 D# Q' }
(*memory).p[j].computeTime = (*storage).p.computeTime;
0 P* D5 x. r' j3 k(*memory).p[j].runningTime = systemClock;. z7 z; x2 e* d4 c; _
(*memory).p[j].produceTime = (*storage).p.produceTime;
; |+ J8 u1 `$ B5 @, F0 wfor(k=0; k<(*memory).p[j].ioNum; k++)9 C0 i! F3 Z) N# c% t
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
8 r! D1 k9 q* r1 c% G7 Kfor(k=0; k<(*memory).p[j].computeNum; k++)- R2 x q. O7 w: _2 ^
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
( d6 C5 p( X/ z; m*spareMemory = *spareMemory - (*memory).p[j].askMemory;7 O$ u$ n+ i. d5 O; m x7 B2 h
produce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程/ _2 \- u( X. T4 v% N" K2 l8 |
MAX_COMING_TIME = (*storage).p.comeingTime;
% I( _# S, }0 Ztranslation=1;# a4 g/ `1 r7 D) Q/ D$ _
break;$ v! g5 h5 r" T
}8 x3 M/ u' Q8 u# L' Q; R2 N
}
9 M) J+ @. J w" L2 P7 C4 ?9 t$ p& z}
- ?. L" g) d8 Yelse
! H# a; L6 x/ g& F; r: v/ x2 R{% e: C3 O; w+ u. P: l5 W
while(1)
0 }0 r1 ^8 L8 b1 c# W{
7 d0 V/ [) V' `) y% c8 Tflag=0;, {% C8 x" A) f
for(i=0; i<(*storage).proNum; i++). k1 ~4 f( a+ K x7 r/ m
{
/ }) S) ^3 ~( t: _' gif((*storage).p.askMemory <= *spareMemory)* z5 u1 \, L/ [5 P3 H F6 P
{
; f5 Z4 p& c* Jj=(*memory).proNum;1 D" M$ Q7 Y$ Y5 R
(*memory).p[j].askMemory = (*storage).p.askMemory;* a+ B6 J; `& q# j; p G
(*memory).p[j].comeingTime = (*storage).p.comeingTime;
q, n1 B" Z9 i: q& E) u(*memory).p[j].computeNum = (*storage).p.computeNum;
: k' \+ V3 U% o(*memory).p[j].ioNum = (*storage).p.ioNum;
% ?% y: n# r( r# F' G, k, S(*memory).p[j].processID = (*storage).p.processID;( e6 q% J* A, e0 h6 N) Q( m# W
(*memory).p[j].flag = (*storage).p.flag;
9 n8 U( D7 L9 t ? g! X(*memory).p[j].ioTime = (*storage).p.ioTime;* c. o: w# ~$ k. n8 T6 D. r, G/ e
(*memory).p[j].computeTime = (*storage).p.computeTime;% F. @& n O3 B! ~7 @" l8 {
(*memory).p[j].runningTime = systemClock;
) [. J, \ V/ s0 d- Q4 C(*memory).p[j].produceTime = (*storage).p.produceTime;
5 i b8 B, _ `" f; A0 wfor(k=0; k<(*memory).p[j].ioNum; k++)1 M; A5 m* o K9 b
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
3 P6 p, @# i) ]for(k=0; k<(*memory).p[j].computeNum; k++)7 o2 z8 l; Z7 g/ S9 e9 D" F/ R
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];2 L' L0 O5 F2 o9 f
(*memory).proNum++;1 c, M+ E! N ~7 S% i: G
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
8 _ W+ ]; \: P# m6 Eproduce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程/ P: Q r0 {* h0 B! S ~* W6 b
MAX_COMING_TIME = (*storage).p.comeingTime;
3 U" o* Q/ B6 B7 Z P3 e s1 C1 Fflag=1;) ]$ G" _6 L8 T5 X
translation=1;5 ~, l0 S h& m& X/ u b
}# ]3 O$ S9 }& f4 E8 ?2 [7 {
}
1 m; w. g+ O2 r& ]if(flag == 0)! q2 o$ P( m6 F/ j1 _5 e
break;
7 d& g( \8 h6 s7 A* S( d8 A}" W# P6 g. y! K. P& u
}6 p3 T) `1 E/ b: |& u! O
return translation;1 X, |! M: [3 C! l- E' i, L7 H
}
6 h* {# h0 _: F" A* G x& gint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)
' f! r) ^) I! B, q1 Y4 W" X# ?{2 G3 _' Z R- B1 D+ i5 }
static int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;
{5 x* d! p& b5 a$ r7 l6 Hstatic int computeLast=0,waitioLast=0,changeLast=0;2 e' _- F8 S6 s( n
int i=0;! W8 Q+ [' p |: u' G
if(draw==1)
. l! R+ } `$ `1 c( y, y3 ]{" k. I" g$ {, ~- N4 A; X* E
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
# l1 f' l! q2 T/ {drawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);7 t6 T4 K& G/ F8 x1 I
" A; u% z# a" e" I* I
! I) i7 d3 R+ o0 k& C1 N3 K8 xcomputeLast=compute;
6 O' Z+ k D E' i+ w! OwaitioLast=waitio;
% C; c/ R+ G' S8 g0 R% x( vchangeLast=change;; z2 C. k) R' \( j+ p: A E/ Q5 y
}/ f" p- Q+ ]7 n1 I$ y
if(flag==1) 8 e" \9 j2 j8 e G6 [1 S* V
{* C: f$ w- s- j
if((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed
5 J8 h N" |4 l9 [ T{
; r7 L% k. T4 h2 g0 ]% Tif(flagiocpt==0) // implement compute
6 ~6 q$ Y; d" }/ h8 }. A{: y, j0 t" e6 s# B% S# H2 |6 C$ B4 W
i=(*memory).p[0].computeNum;
: I' _3 p$ U7 Z( X3 f i3 c" Q0 p8 Dif(i>0 && (*memory).p[0].computeClock[i-1]>0)
% x& z6 h7 z/ r: C* S{
! {1 S+ V8 x9 S; ^$ J( W0 ^! t9 aif(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed2 O" G3 K0 y6 K) e" M4 V0 l- K
{
6 a2 ?5 I4 F6 E _' Z5 _5 Cflagiocpt = 1;" V0 `! j$ B5 ?! k. j, G
(*memory).p[0].computeNum--;% w; ^9 j8 f! Z/ T" ^; y
change += exchange_IO_Compute;
0 A- U; I( u. z3 m1 Ocompute++;+ K* Z( w9 E% j, P/ J
}+ g3 I2 [0 x! a1 u
else1 z; I6 c- n5 V+ U
compute++;
9 Z! \: L7 ?# n1 A0 f) ~+ ^% D! W& A/ G4 E
}9 A: }% _4 s7 l: C
else
! D5 Z9 g8 f2 O* n8 n( Uflagiocpt = 1;* Q; ]/ ~2 n% p2 y W1 [8 a& E
}
/ I$ n) I D5 ]+ U5 j/ Aelse //wait io1 z9 O9 j" I% L( N, A* z
{
, M+ b: p( _$ \ r9 \; ^% Ti=(*memory).p[0].ioNum;
: A. f# c/ z1 d+ c3 s, W7 R0 c' aif(i>0 && (*memory).p[0].ioClock[i-1]>0)
3 j+ q q4 R. l9 Q{! }7 s6 E1 Q" x L0 }) N$ o" ]# S6 P
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed' {. b6 k3 r/ J* i& Q) p! a
{8 _% ^9 Y/ l7 W
flagiocpt = 0;
% F s6 {, c5 L! u+ |1 F(*memory).p[0].ioNum--;3 g1 B: P+ S L! h4 }# \4 J$ Y. e
change += exchange_IO_Compute; E( t: v% c8 t% X5 ]/ z. B$ S/ a6 D
waitio++;
7 R- V1 [' P6 H}5 x+ ]/ K" ` l! X( a. ?5 h, _2 Y" _
else
6 v0 u7 U$ b0 J4 {* `/ Gwaitio++;/ h1 i6 w/ {2 h# `
# ]2 F+ a8 a, {
}
1 M& G# A ~) q J. Gelse
2 C) f E% r7 t* q" d! a" _8 rflagiocpt = 0;
$ n0 V, H# y7 J" F5 g. N; I}
4 i# J8 r- Q7 \* Z% ]}3 Q* H# P/ x6 J6 A; g: q" r0 f
else //task is completed
0 Q4 |2 x& ^+ O{
/ m8 N8 o4 r+ g: t. x7 H1 b(*save) = (PCI*)malloc(sizeof(PCI));7 n/ L. L) o1 G Y B0 w
(*save)->next = NULL;
. k& P& i# R9 U2 n8 S (*save)->processID = (*memory).p[0].processID;2 r2 |. z8 J' D. ?; i7 ]3 d# O
(*save)->comeingTime = (*memory).p[0].produceTime;
' t2 x7 B* ~& y0 |; d(*save)->askMemory = (*memory).p[0].askMemory;* V. m. a% @2 X2 z
(*save)->compute = compute;
& r) k d2 j$ o(*save)->waitio = waitio;4 F& X l) T8 s$ E# q% ~* u
(*save)->exchange = change;
: U3 Q1 W3 M. [(*save)->completedTime = systemClock-(*save)->comeingTime;
4 v4 q l, a$ y3 f5 y, A8 Q7 k(*save)->runningTime = (*memory).p[0].runningTime;9 [) u$ {3 k# o- y
(*save)->completedTime = systemClock;/ a6 {# I0 M+ N+ `2 n# ]
//*spareMemory = MAX_MEMORY;: u& R' s7 \$ N9 R" [: n
free((*memory).p[0].ioClock);
- K: T7 ]6 }& }$ U) K) \9 v/ afree((*memory).p[0].computeClock);
1 A3 F5 W8 [9 @2 tfree((*memory).p);
6 g. y _/ }. r9 N6 dflag=0;! j/ c0 B6 r; P5 N& r! G
compute=waitio=change=0;
$ w ]4 _6 z$ K6 a' h) {( G9 a: Z6 ocomputeLast=waitioLast=changeLast=0;$ `6 r+ ]4 M, W# M2 c8 P0 V1 z
return task_completed;
1 d" _; Y( u% C: |/ Y& J& w}. \+ w& I# k, ?
}/ w* @% f( s$ M& F
else
! _) G# j' `' I% z+ l! @. u{, U3 e& |& P! ~
FIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));
, G- ]% I( `& _8 {1 a0 cchange += exchange_process;) L7 s' f/ l# D
//*spareMemory -= (*memory).p[0].askMemory;. x% m3 O6 l" U- Y1 S2 a
flag=1;, I2 G! L5 A/ g* b3 Q4 M# q
//showProcessInf(*memory);
% E- [3 q" D2 b6 d, l0 Hreturn task_not_completed;3 [8 V. h. Q# `9 ?& V
}
9 a1 q5 g- S% L& V s9 Breturn task_not_completed;) [; J9 j% ?) }; N, S6 ]& F2 P
}! s5 C# N& m* ]* t, l
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)$ S" i. P. j3 |% K1 E
{8 W# E J4 w5 N% P+ f: }
int i=0,j=0,k=0;
# }; S; G9 e( M+ P; p5 XMAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;6 u* r8 F- u6 d) X3 s" {6 ~
(*memory).p = (process*)malloc(initProcessNum*sizeof(process));/ K! ?8 t6 ?- |8 Y% G& ]& a
memory->proNum = 1;9 u4 R% t1 Q) q9 B- w, @0 q2 s
for(i=0; i<initProcessNum; i++)
/ h4 R3 {2 R; j; y# r( Y{
- g2 P) a+ z$ \! p! j6 ]1 Xif((*storage).p.askMemory <= *spareMemory); ^) L+ W' p5 ]5 U# j
{
2 q/ n( c- |; c' ~- t(*memory).p[0].askMemory = (*storage).p.askMemory;6 Z9 B+ \' @0 |2 [
(*memory).p[0].comeingTime = (*storage).p.comeingTime;
# ]- E9 ]7 Z: l( o(*memory).p[0].computeNum = (*storage).p.computeNum;- p. J/ M, P1 K
(*memory).p[0].ioNum = (*storage).p.ioNum;
( G8 I7 q ^1 \(*memory).p[0].processID = (*storage).p.processID;4 b7 g& I, I+ R/ [
(*memory).p[0].flag = (*storage).p.flag; K/ z, C5 r9 a0 p
(*memory).p[0].ioTime = (*storage).p.ioTime;
' d5 Q, a2 L W7 o! v(*memory).p[0].computeTime = (*storage).p.computeTime;
' T* {) b/ D: o; n(*memory).p[0].produceTime = (*storage).p.produceTime;8 \: c( g0 C6 f0 B5 h9 P
(*memory).p[0].runningTime = systemClock;
9 _( p. n* n9 P(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));
3 e8 X7 I7 }* b5 O. p* O: [& y(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));' s- c: H9 f: F2 i* z+ L6 R
for(k=0; k<(*memory).p[0].ioNum; k++)
7 g5 `' z0 j3 Y4 i, Y, _# @(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];% P! w7 z& v% z& z2 _
for(k=0; k<(*memory).p[0].computeNum; k++)- V6 ]* a2 `1 M' {; k8 B
(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];
4 g, c( ]* ]+ s& e) B) Ubreak;( M+ q" k& m$ o0 Y7 g
}, d! t) W$ ]. }2 a/ G
}, i& a4 Q, a, Z9 v' l
if(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入; _; N/ f, z C' K
{4 U2 A2 u: H. w Y' {
produce_one_task(storage,i,ID_FIFO++);: {" l6 l) B1 W5 b' Q. T9 _, H
MAX_COMING_TIME = (*storage).p.comeingTime;" c3 q8 ]% Q, x6 O
sort_by_comingtime(storage,i);
6 R' d% W" L* v9 d}
" g' l, p1 N7 O) s4 L* e. x9 [1 ereturn 0;1 T. y) @, @7 y' o9 N
}5 h6 c3 q& f5 Z( ]( O3 j
int sort_by_comingtime(processPool * p,int pos)
" p/ n. `, o- N4 G4 f{
; c$ }! A$ u# A& L+ T& _int i=0,j=0;$ D- q4 [" ^. ` H* L- n, s0 U
process temp;7 @, M, S% B- O9 P
if(pos<0)
; _) x( z X" c3 |# O8 a: L{
" C% G a( `+ [8 D3 P& M; vfor(i=0; i<initProcessNum; i++)
/ z& @- Z: f' U+ `" ufor(j=0; j+1<initProcessNum-i; j++)) ?3 q0 D: L2 l" ~( T! B# B
{+ M2 S+ O, H+ [9 E: r
if((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)& Z X6 H4 `# ]% l/ N* z
{! C. l+ _8 K) T7 w1 I6 \, e
temp = (*p).p[j];
$ A& ]( o. X9 T/ x0 s5 P+ n: q: E(*p).p[j] = (*p).p[j+1];
0 o' s: P( O! s) y$ E(*p).p[j+1] = temp;& a- o8 O9 _' h" i
}
7 v8 U2 ?1 m2 i}
& z% X3 N( n, B: C9 \9 s}
) C0 H# r% [9 \ B8 S. Velse if(pos<initProcessNum)% D0 a) Q9 J v# O+ I" c5 R9 B
{
" a' \+ t# c/ n) q/ b5 o# {for(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)# o$ B O( ?* y, u# ?
{9 l# C/ n, L+ F: ]3 c/ z4 D( Y
temp = (*p).p;% F# [3 h7 F" V. @
(*p).p = (*p).p[i+1];
# c. r! a2 n+ G* O9 U5 k(*p).p[i+1] = temp;8 l+ [2 z. P! d `& X! Z3 G+ o
}
) i" N9 ^* g W; b' F7 Qfor(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)
* t! L% c. J) E' i3 F C0 h: n{5 |7 ?0 @) N1 C5 j7 [. q
temp = (*p).p[i-1];
: l5 l: \% _, ^3 j7 `/ J5 g(*p).p[i-1] = (*p).p;
# ^9 ^! E& y7 i: K! \- J$ T& m(*p).p = temp;( i/ M/ `: Z4 ^$ ^ e. T) @
}
* N6 I( U- ?, `}
' l" K D5 w) S! C) z6 Melse1 I; x: r2 P7 d: Q
printf("position eror\n");) b6 R; z4 i' C/ R
return 0;6 Y9 ]# b/ B' m {5 [- k
}0 c% A8 ^. z8 n8 {5 o+ t ?
int InitPool(processPool * p)9 s" T+ O/ v: M& @! c
{
3 Z9 j1 R# `& yint i=0;
; t- E t/ Q J2 w5 G. t _(*p).proNum = initProcessNum;
# M3 o1 J" ?7 F, y* A# z9 R& i(*p).p = (process*)malloc(initProcessNum*sizeof(process));
* |& D" y$ A- e7 f. }5 v- G8 k% T7 J9 mfor(i=0; i<initProcessNum; i++) //init process information
+ {% S) e5 a! C: U2 j' z{/ x( i* q) @. ^
(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));
! h" e7 m- d6 ^8 o- D(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));( Z2 n" |# _9 m w( n
produce_one_task(&(*p),i,ID_FIFO++);2 t( Z% ~3 H) j. e- C) V
}
2 {, ?9 G2 Y1 K' p) U8 Vreturn 0;
2 }0 X- }6 R/ ], q* Z$ b0 {5 U6 X3 }}
0 l* }! J3 x3 k" iint produce_one_task(processPool * p,int i,int id)
/ W3 S: w4 q7 B5 Y' g6 i% c{2 V) Z- T# A: t3 }) x7 U
int time=MAX_COMING_TIME,j=0,totallTime=0;$ H1 c; I5 h4 R6 v4 N9 {
(*p).p.processID = initProcessID+id;
3 J. T& i; V; ](*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);
- l# {/ A8 T2 B(*p).p.produceTime = systemClock;
/ K2 D$ j: C: @7 Y* S; U(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;, x4 s2 T7 a: F; z
(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6;
5 ?0 f ~; p% T+ }0 E6 TtotallTime = (*p).p.computeNum + (*p).p.ioNum;. j! |$ t3 _3 L6 Q0 d
(*p).p.computeTime=0;
, ^# L; \* M' ?for(j=0; j<(*p).p.computeNum; j++)1 U: A" ^; V6 m4 f0 r. n
{
6 r; g- O; ?* p" ^# R(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;
9 q4 v) V6 V# @' d( s: G( D(*p).p.computeTime += (*p).p.computeClock[j];
. q' `+ W) L( I! f1 E: p: n}5 n! [; _" K4 R* ~. x
(*p).p.ioTime=0;8 G' c5 r( ?5 Z, f
for(j=0; j<(*p).p.ioNum; j++) |
|