- 在线时间
- 1630 小时
- 最后登录
- 2024-1-29
- 注册时间
- 2017-5-16
- 听众数
- 82
- 收听数
- 1
- 能力
- 120 分
- 体力
- 565631 点
- 威望
- 12 点
- 阅读权限
- 255
- 积分
- 174912
- 相册
- 1
- 日志
- 0
- 记录
- 0
- 帖子
- 5313
- 主题
- 5273
- 精华
- 3
- 分享
- 0
- 好友
- 163
TA的每日心情 | 开心 2021-8-11 17:59 |
|---|
签到天数: 17 天 [LV.4]偶尔看看III 网络挑战赛参赛者 网络挑战赛参赛者 - 自我介绍
- 本人女,毕业于内蒙古科技大学,担任文职专业,毕业专业英语。
 群组: 2018美赛大象算法课程 群组: 2018美赛护航培训课程 群组: 2019年 数学中国站长建 群组: 2019年数据分析师课程 群组: 2018年大象老师国赛优 |
; i0 c$ a; p$ `& r经典任务调度算法的模拟程序/ P' t; n8 S7 t
本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。
* e( r" N% q6 J, w" V/ R$ v' s8 K
8 f4 H3 r g d% c编程平台:VC6.0+EasyX图形库环境。
/ ?$ G0 R" a, X! }: Q; A. I2 w' z2 s# V1 l% d
以下截取部分程序运行图::
( `" x9 v; T* ~+ Y: g4 P7 y( k3 v& T0 \8 z/ h: N. k, a, s
源代码:4 j2 w) T2 K/ K0 T; e% g6 ~
& z) P+ u! e& t3 z, w1 g7 a& P#include<stdio.h>/ w0 T3 ]; s# J c5 T7 B
#include<stdlib.h>4 z5 h7 @. N' N# N1 |
#include<easyx.h>
8 O% [: N/ ~3 S; k9 g#include<time.h>5 j+ e( K d) u+ S
#include<conio.h>! Q- |, m9 X- \7 s# j+ I
#include<graphics.h>
$ l! {$ N: L: V! ]! Z" i' e5 R#define initProcessNum 10' V& H8 G) J. L9 s) w; n8 U. Q
#define initProcessID 10000 z& Y- A! v6 I. K! T) j
#define MAXProcessRunTime 10000
, A( s8 q- f }, D v% ~" _#define MAX_MEMORY 4000 P6 H$ H* _- l, z! n" a4 K c
#define exchange_IO_Compute 10- s9 W9 N8 f* ~4 V" ~. ~3 ~- z
#define exchange_process 25
; D* Y& J/ n6 t#define task_completed 1) _, U. Y; [+ l+ U
#define task_not_completed 0
* ]1 v: E% c4 l k/ W#define initclocknum 100 Q/ }5 v( R8 l r8 X
enum condition
6 R( j; c' D6 w1 P' x# i& g{
M5 l: ~* N, d/ }- W" b& ]! qdead,computing,IO_waiting,ready
0 k- p! p1 [0 K* y2 T};
5 E! |% H8 I4 m# r6 v: _* ]" pstruct process' `6 u% c) S1 e8 {4 A2 C7 H; A
{: V( R: |6 R( G6 v. ^/ F4 _' Z
int processID;
+ g1 ~ [/ x1 e1 G |% gint comeingTime;
4 _7 z) p% V4 bint ioNum;
: o7 R' R" \) ]9 aint computeNum;8 C: _* m3 A \5 N' H8 b
int * ioClock;
; \6 |, K7 H; ~# `; y& i7 p: iint * computeClock;0 }( @! Q K5 j9 O5 k: Z
int ioTime;+ c+ E$ Z' D5 y" i, j
int computeTime;( C" \& W) z8 v: N, e- Y# A
int askMemory;
# T8 |+ T, Y$ t2 C9 Y. x& y3 Ocondition flag;
8 G) _8 g% G" S% c) h3 Jint produceTime; //生成时间,以下三个数据成员用以计算相关性能1 u% k8 w, B7 M; i" ]1 Y
int runningTime; //第一次占用CPU的时间
5 b- o/ D4 j1 }& [) }int completedTime; //进程完成时的时间* u: l( b% G! \! e! K9 `
};. B$ B! ~7 Q& v g" [! k% R
typedef struct processCmpletedInfo //保存完成一个作业的相关信息. P- {: ]" C2 @$ N
{
% t* N7 C) E7 I/ Y2 Z; bint processID,comeingTime,askMemory;
8 h; \1 `' ]7 j- |8 l- D! J* Uint compute,waitio,exchange,completedTime,runningTime;( v5 b( P+ M0 `0 @; Q+ `( j
processCmpletedInfo * next;
- {( g) B# F; |( n1 j" ^}PCI;) a; ]: `' L1 j8 _
struct processPool7 v1 B9 w$ E6 n# |" |+ z
{1 O( D0 q) N! |7 |: q2 T
process * p;
8 U {% v% K: b& Rint proNum;
* a, I. T' S1 n9 i! Z};
+ g: ?$ e1 \; ~" b9 F4 [& D# Yint 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;
" Y! ?2 j T' {int InitPool(processPool * p);2 @! W0 B6 p$ s8 y- U1 l5 z
int produce_one_task(processPool * p,int i,int id);1 c# A. Z, {8 l* g, o+ r
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);
* b( C9 C; T" r% y% Aint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);# ?3 m$ v7 ]0 }" M& h. e
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);& l( w0 b' Z- h# g
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
: L# B) G5 M9 Q1 G8 Zint ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);$ C/ m; u$ v: C* S' Z
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
, Z* _% q9 @, K2 A' P9 i7 }; v3 Yint PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
5 Y( D3 `4 y; w' U# ^int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);* u" Y" \6 q* }$ g! @9 H
int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);
" }" x8 s1 C+ G4 iint High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);. {1 J3 i, o9 T" g/ R4 |
. v. A* ]8 }3 d
$ Z8 m: L2 k, O* G- \* Qint sort_by_comingtime(processPool * p,int pos); S/ v p, V& |- t
int showProcessInf(processPool p);
0 w1 h. }! s" k' {5 K k3 k8 Sint drawPerformance_FIFO(int x,int y,int memorry);
8 ?) j7 L! G( K' lint drawPerformance_HR(int x,int y,int memorry);6 y" v/ C4 o1 ], d" l
int drawPerformance_PF(int x,int y,int memorry);
2 U( _7 c' d! H, t$ Eint drawPerformance_TT(int x,int y,int memorry);4 g2 C, N; c5 v8 m2 j
int drawPerformance_SJF(int x,int y,int memorry);/ A3 u: u* u# k
int MouseListening();% L- P1 w; x" |9 M5 `$ p8 q
int MouseListening2(int *flagShow,int * showTime);
U7 b$ ~0 @/ t5 mint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);
" P3 p6 C( a# J2 D% \7 {
0 Y% X7 C& r$ n; N% f% J$ ~% ~& g0 p5 d' ~$ w
void main()3 | D# W0 [ z) N9 x: w8 u
{
5 i n8 H5 t; @' E# j/ b V! HPCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,
% Y! R' I4 A2 i2 W*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;+ Z0 o# M3 l$ m! x7 C
int i=0,FIFO_memory=MAX_MEMORY,count=0,Timet_memory=MAX_MEMORY,SJF_memory=MAX_MEMORY,Priority_memory=MAX_MEMORY,HR_memory=MAX_MEMORY,; O! z6 m& n/ R4 L L; I" n: H4 D+ B
flagDraw=0,showTime=100000;% ~: M2 J/ i- N7 h! J
processPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;
3 o! l5 }( s3 L# hFILE *fp=NULL;
" \$ U. l4 R/ Z" |4 m//processPool HR_p,HR_mmy;1 F& K* y- e, W l: a
1 N* V. a9 @4 F1 i$ ?' E' K3 a( _
+ C0 J' h8 X, L6 r, [srand((unsigned)time(0));# Z0 ^) Q5 ~7 Y
systemClock=0;
# H4 D& M, ]7 `4 w: h( binitgraph( 1200,650,SHOWCONSOLE );" ~6 s' `2 O: b1 @( o9 K {
settextcolor(GREEN);- [$ s0 B+ h/ N
setlinecolor(GREEN);
+ h% F% b" X/ X' P+ usetfillcolor(GREEN);: x6 r0 g: \0 ?8 ^
InitPool(&FIFO_p);
. ^" ~' r) p: u" i3 G9 ~" D! Fsort_by_comingtime(&FIFO_p,-1);
! P8 x) E0 K( P, p, B% W/ s# mInitPool(&Timeturn_p);
8 V: U0 D, i" Y/ ~' EInitPool(&SJF_p);
0 Y# e, @( v) C; A, d0 DInitPool(&Priority_p);
1 R0 Q; C7 N* P- g# ^/ W/ @+ u) _InitPool(&HR_p);# y) e1 g) R% E5 P; W) [
//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);7 Z+ _/ A, I5 h+ y# }* o" y3 Z
//Sleep(10000);
. H0 h! T5 V% o- c) p# F K2 E9 k* P& j7 t8 t
: o# r0 _5 u! r7 G6 P) S$ ?Timeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));- S1 Z# A2 [( n6 m
SJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
. a$ |2 C9 g9 gPriority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
) P9 L$ c9 L* tHR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
" Z7 i4 o" k. f( m/ a* M0 M& m/ Dfor(i=0; i<initProcessNum ;i++)" c* T% z/ C$ |( z) b, x6 Y% |/ v
{
# y2 F1 J' m6 x7 i7 j& W& mTimeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));3 }* W; Q) K7 d* m# ^! P
Timeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
! K# Q% F' s7 l4 V) ~4 ]SJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
' |% N8 D/ i5 z4 ~# k. ?: B4 ~SJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
% x1 s7 M) Q$ a- }: Y7 M6 uPriority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
/ Z, T$ Z2 H& E0 u) {4 zPriority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
7 {7 ~: `2 ^1 @: E8 J" GHR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));% u( \1 ^* N0 g x+ f( _
HR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));3 \) r# P" R+ q7 N( T" M2 ?
}
6 f3 O% i4 f5 s' GTimeturn_mmy.proNum = 0;7 G7 ]$ `2 A, e: U/ Z6 H# Y5 G- U
TimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);
! ~9 Y( y: Y8 L* mSJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);6 h7 p! o# J* H$ ^ R. I, J
Priority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);, J. X5 n- M7 D+ h0 U, B
High_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);
! p n7 H4 r: A//showProcessInf(Timeturn_mmy);
& p$ g3 ]# P6 F; t& y* ZFIFO_pri = &FIFO_save_head;$ w0 |: B& I: C* A' k; [
Timet_pri = &Timet_save_head;: p: i, O0 _" [/ v, b
SJF_pri = &SJF_save_head;
% F; e( {0 g. B& R& T- t* DPriority_pri = &Priority_save_head;9 h6 v2 v1 C) G4 n. s8 {
HR_pri = &HR_save_head;
2 L9 y6 H U" F, r0 _setbkcolor(WHITE);
& i Z$ j- T# f& V5 ?0 b9 }while(1)
. P# ~; R% \5 y( x{
P( x# Q. D$ J4 m& h {1 y: B2 Mif(MouseListening()==1)
" T' Q$ J. f- X4 s! a& R8 QflagDraw=1;
4 D& B* f+ f2 _7 ^) a9 ]if(count==100)8 z1 D4 o; x2 ]( D0 n) ^
{
. Z$ F3 K8 M) U" r7 l) Sif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)- {! z2 o# j9 G b5 y- a8 r: u
{
0 T8 h# a; c6 ^FIFO_pri = &((*FIFO_pri)->next);6 B: X5 g* ]8 G' l" ~1 t
+ o& m' }5 {5 D$ K8 u//printf("hello");
" }& w* f/ t9 O& J0 p}
2 t$ U t+ Q9 \! pif(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)
9 A9 r: B# o7 G# `! f2 K9 o{
) A1 o( S ~7 p7 [ Timet_pri = &((*Timet_pri)->next);: x1 K/ n, I( c$ B# a
//printf("hello");0 M. A: X G* G* i) ]% p! u8 O
}7 z) M+ @" b5 Y5 {* \. F
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed): b: J+ n! g% M9 c* P1 [2 |& |7 D% f/ z
{1 ?4 {* r9 ] @& b! @2 r
SJF_pri = &((*SJF_pri)->next);
/ z+ n9 f+ t+ F% q. C0 _+ E//printf("hello\n");
6 A- Y& H% U9 a}
% g3 j2 ?+ A7 K; K- Q( g% wif(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed)
% @6 J2 j" g; o& {& ?. K{: O# p( c6 G$ I' i5 e
Priority_pri = &((*Priority_pri)->next);
8 f! L# j: ^* V9 E1 C* V1 d//printf("hello\n");
2 Z- n# k+ [, Z}
4 Y0 C7 H$ h n" w; bif(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)
& e6 w/ ~* q; N$ ~{/ p* \, Q! @/ x! @3 a
HR_pri = &((*HR_pri)->next);2 Y# o: Q% g8 i# O& l: P
//printf("hello");$ p) y/ I3 ?: a3 H; k7 ]" R
}
. S' g2 B# _3 ~$ ^7 Kcount=0;
# a# |/ P e- W7 \# q}
4 m3 _! D Z8 b4 p8 ~$ y3 V4 Nelse
* t3 @ w1 q1 b3 s+ L{
7 \9 T* x+ D: t% D5 H) |& Lif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)/ f% k& |" d& j: V j
{% @4 o5 j/ S8 M
FIFO_pri = &((*FIFO_pri)->next);
* W* E/ |1 S$ h2 F4 j2 G, X// printf("hello");
2 Y- p! v O( R( b4 L4 q, e- d}
0 L9 j) k+ p. S Z) }+ R) ^if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)
! H0 S; _# `/ E9 O' D; F" t{
5 u$ B% w( }+ Q3 I. M y# OTimet_pri = &((*Timet_pri)->next);5 ]8 i7 k$ d' X" C3 `& f) c4 { ?8 h
// printf("hello");
: w( P# o( K5 N8 e- N" L: l. ?% p/ v}
) X6 l- s- s) ^; ^# V+ W% N: i6 j3 fif(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)
3 A' C- W2 f6 |3 X* P{1 d, w9 H f& ?5 m8 y! [# X
SJF_pri = &((*SJF_pri)->next);
) J- s8 V! d, h2 d0 C+ i2 a* R// printf("hello\n");
/ d! {3 e2 M% b- s' n c}* R* B; z: f7 }0 r
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)8 R7 I K# v2 R8 s f
{5 p2 O/ j/ _0 E
Priority_pri = &((*Priority_pri)->next);% N$ F5 I& w7 Y( w. X
//printf("hello\n");
" ^1 l9 M0 [* P}1 S% @3 P9 \, E2 K9 Q5 q. L
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed) `( j" `% Z! E- h% e+ ]( d8 A
{
# _" ^) @: T- R# m7 ^ G6 d1 jHR_pri = &((*HR_pri)->next);
0 f- S7 o: C ?7 T9 c( d//printf("hello");
% u5 Z$ _8 l$ A4 p, Q$ r//Sleep(1000);
6 `2 d: M* K0 U& B# A}: l7 r! W! D$ O! T+ l- H. \8 {, J
count++;) D* K) c5 B& i+ e; }
}
) h- {7 ~5 F u4 Wif(systemClock==showTime)
9 C0 L: Z8 }* G9 O9 \* e# H{# ~: q7 B h( I! ^" U: h% `% S
/*PCI * p=FIFO_save_head;
7 l! [& _1 G; ] e' R- Gint i=0;
+ G5 B+ Z+ C! i1 Q8 C2 c' u, dfor( ;p!=NULL;p=p->next)
0 a- L; n; b) o' K5 h{
5 y- r$ K- j/ u- Y- [% d# v1 kprintf("Id %d\n",p->processID);) h5 n9 X( T; ^: L! [; j5 h3 I; |
printf("comeingtime %d\n",p->comeingTime);
( |, s# X4 `$ c5 X) P5 b) fprintf("runningtime %d\n",p->runningTime);
8 g( K0 Q: _0 p) E4 F" `3 \printf("asdmemory %d\n",p->askMemory);
) @; p3 ~& M8 f" {# Eprintf("completedtime %d\n",p->completedTime);' s1 l! v6 Y% v; u% t" W6 d
printf("compute %d\n",p->compute);1 X$ x4 R: Z* m/ ]9 C( Y: C7 G, Z* M
printf("exchange %d\n",p->exchange);
0 q' [9 U7 E2 N4 E* Tprintf("waitio %d\n",p->waitio);. ?7 E- B* |5 D8 j a* S
i++;% b2 [4 j) ^4 o5 H: A) r
% D$ |# n% M; y/ @% e+ A# b
" o# m& b. H+ I0 T$ X! W}
( l1 p$ m' W- S. ]printf("%d\n",i);*/8 k0 q+ \, W O7 S8 d7 P0 a- _
if( (fp = fopen( "data.txt", "a" )) == NULL ), G' }6 _5 s: Y; ?( b- j& _
{
$ [5 M( t1 L4 V8 ?printf( "The file 'data.txt' was not opened\n" );
& L" p* C( l+ e6 {6 p# b//return 1;+ O, M0 w& G9 T6 D; F: d5 U/ S( [
}; R3 { O w1 B
else
: e2 T5 K) c2 r9 ~' E{
8 \, o: Q5 A1 f* [+ p6 t4 b, h& Sfprintf(fp,"FCFS \n");: o8 n/ }3 }: R- w @: m/ ~
for(p=FIFO_save_head;p!=NULL;p=p->next)/ }3 i7 ~+ V7 H
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,& r0 L" Z* `! C% p$ E, Y
p->exchange,p->waitio,p->runningTime);2 y6 o t7 h1 }( S+ W7 `
fprintf(fp,"\nTime turn \n");, O2 {, p+ ~+ j4 F) [
for(p=Timet_save_head;p!=NULL;p=p->next)9 x( [2 C, Q0 K
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,) X7 Y3 N% I- P- J* Y5 P" g: \0 j
p->exchange,p->waitio,p->runningTime);, D7 r2 Z' u4 s! q. {9 F
fprintf(fp,"\nShort Job First \n");
. F) Q. x" b3 m {! B; X3 J9 J7 Hfor(p=SJF_save_head;p!=NULL;p=p->next)2 q- ~5 ?7 u6 m* Z' _ d2 F, k- L) `
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
# ?+ W; `8 p' g5 ~p->exchange,p->waitio,p->runningTime);0 N+ s' D8 p: A
fprintf(fp,"\nPriority \n");9 J9 {5 n6 Z$ n
for(p=Priority_save_head;p!=NULL;p=p->next)
: w- D E# e, Q0 g/ efprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,' F/ @' c. i* ?
p->exchange,p->waitio,p->runningTime);, J; W6 a+ D% S) D# p. S/ G
fprintf(fp,"\nHigh response \n");, b) Y! y# {( u* b% w
for(p=HR_save_head;p!=NULL;p=p->next)6 Q1 o5 t1 m0 W8 a; S* u
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
6 `* g, D( s# S: Y4 L# {- Qp->exchange,p->waitio,p->runningTime);3 P+ ?- F8 ~/ d: D, i
fclose(fp);0 Q' D9 F9 e6 g5 \0 L
}
9 i* k" |& B. J ashowRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
: O+ q' Y" f/ }% V3 ZMouseListening2(&flagDraw,&showTime);
: ~2 K. M1 u0 R$ Y6 v2 ~* `: Z5 x} l n1 b& \8 \$ q% _
systemClock++;
Q% s9 F) U6 U: l& sif(flagDraw==0)$ g: O: J! ^9 K6 F( q6 w
Sleep(10);- P9 D$ Z( U( h; X
}5 m2 D" }0 Y; f B1 [+ b; B& j
+ y; D9 I+ r' W. ~* v, H: K
6 X3 v) m/ L% S" N1 {" y
}
1 L ?$ p" c9 g: ?6 z, E0 Kint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)/ E# t3 o( S6 f) b2 ^
{& L/ r# R# H4 T; z. I8 V
PCI * p=NULL,* name[5];" ?( g/ u& g8 Y. T9 x3 S: U% G. I6 J
int count=0,i=0;
. b" W' ?9 J3 y( @; ~/ v6 uchar ch[5][10]={"FCFS","timet","SJF","PR","HR"};
0 t! Z( Z' c, q8 D) ddouble turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};
7 Y1 N3 B [. nstruct info0 ~7 n; @+ t# U' B' N
{# O: ?% S2 C6 v
char name[10];
9 d; K: Z4 ~$ V+ m. @# r* ndouble throughput,turnover,wait,CPU_rate;
( O& s! s, u: c3 ]}inf[5];
$ x& ]/ G* T: X# ~2 w" Y; s, Wname[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;
* N6 B. f4 `$ tprintf("调度算法..........A\n");; n# U# T* A2 F9 b# e
printf("吞吐量............B\n");" [5 z% S& W6 z1 t. {3 x
printf("平均周转时间......C\n");
& J6 I/ L! F& h5 c6 Q g Bprintf("等待时间..........D\n");1 b& u2 ~( E& X" w' A5 O2 y
printf("CPU利用率.........E\n");
% \% [ N6 D, @9 R& k& eprintf("A\tB\tC\t\tD\t\tE\n");
" l9 f) Z" X- T3 B% G" t; Q' `for(i=0;i<5;i++)
' H/ q) @' @: y4 a+ e: z/ f4 ^' @4 t{
# J8 N2 z/ R5 O( R. jcount=0,turnover=0,wait=0,c=0,w=0,change=0;! G6 S- j0 Z- |1 A1 N! D: q
for(p=name; p!=NULL; p=p->next). D4 g$ E7 l$ }: }& o+ V7 E7 C
{
: ]1 H# e. f! H1 N6 tcount++;
3 H1 O6 _1 n) y) e: Zturnover += p->completedTime - p->comeingTime;; l& G6 L# U0 ` M3 E% I
wait += p->runningTime - p->comeingTime;5 q; @: ~' H" |2 t: K
c += p->compute;3 ~5 b8 y, [" H. ~" w$ j
w += p->waitio;- d1 u# b* |: y a
change += p->exchange;) C, x- S1 T$ O' Z4 y
}
, B4 \! O6 p: v* ~4 ^3 H( Gturnover = turnover/count;
) u/ c. N( E" R/ rprintf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));
5 a% z9 D- Z U0 M5 a8 [0 D+ cstrcpy(inf.name,ch);% A! {1 L- M; {. _! t# ]# u& M
inf.throughput=count;& o% t3 ?0 x+ [& \& {/ B! t! v! v' } d
inf.turnover=turnover;
& a; W6 Y" ^5 J4 Ainf.wait=wait;
( e& W" l% q4 Z& f% |: r: Q Pinf.CPU_rate=c/(c+w+change);
4 p; ^! ]! h" G, E/ A! X}6 Q7 f% E2 {) F; F) x, {' u+ x
//画图
* r7 E9 q7 l5 O l/ N//cleardevice();: I& z1 b9 l5 p$ S* C: A0 M
line(0,600,1200,600);
5 ?) W H# y4 Zline(10,600,10,200);( f! l0 @% d/ I' w
line(10,200,5,205);
, |: I+ z7 u) Bline(10,200,15,205);; R% l7 V8 c+ E- l5 K
line(310,600,310,200);9 o P. v( M% J
line(310,200,305,205);/ t) X7 {; B1 I# T2 v
line(310,200,315,205);
0 B6 o: I. U3 ?5 Q: B4 M( Kline(610,600,610,200);
) _0 ?) b/ _! o7 Yline(610,200,605,205);
3 m4 ^2 a6 C2 N) |0 Sline(610,200,615,205);
( B1 U8 s S& M5 X/ z! cline(910,600,910,200);& _- K# U: L P( g+ s( a
line(910,200,905,205);
9 \, A( P* A& o& ]& h, `line(910,200,915,205);//最高的长度400,宽度均为40
: {: T: u. y1 d* a; e, |for(i=0;i<5;i++)& n& P$ J: ^) w6 \5 b
{
) ^0 e2 f; @3 j4 s/ E" jif(inf.throughput>pos[0]). D. x5 O, x; U3 @7 O7 _8 Q
pos[0]=inf.throughput;
" x8 T4 D V1 i/ ]2 W! X9 s# lif(inf.turnover>pos[1])
/ X6 O6 w- i; r, M8 jpos[1]=inf.turnover;
% G7 d/ L% W3 q' r: c0 Gif(inf.wait>pos[2])
- G4 ]- E, q3 w q% K& ^* Tpos[2]=inf.wait; m1 v4 O+ g9 h, |& N! P. W
if(inf.CPU_rate>pos[3])% ^% x4 s% Z5 k$ Z4 Z0 A& y
pos[3]=inf.CPU_rate;
6 F7 H2 [( N" g! V& K}. Y- k. w9 I* v
settextstyle(30, 15, _T("楷体"));
; a1 G9 M3 d5 k- Bfor(i=0;i<5;i++)
& B" p# `: L. V6 a" v2 H3 Y8 n0 P{
6 z$ e) N6 d5 r/ {3 F( d% h: G) ]% {7 pswitch (i)
9 {: K. c( k2 r+ T* q; n{
# j: }! p! S- icase 0:" y! q- w* d; Z. T5 D8 @' X q
setfillcolor(BLUE);! j+ [* v/ j; ~" M( i, \
fillrectangle(100,50,150,100);
3 j" N! n% f4 n# z9 n$ P4 Qouttextxy(160,50,"FCFS");
" p K! S( X( c" Q7 `8 u4 tbreak;9 m; V! T$ p( _* X
case 1:
8 H/ I, e* m, J0 E: e' Qsetfillcolor(RED);
% l. @& {: ^* g* h8 l6 i8 dfillrectangle(250,50,300,100);+ v$ o+ I8 T# ]4 u( p. |
outtextxy(310,50,"timeTurn");
: p* s& R' d+ s' c8 kbreak;8 B8 E3 M' b: B
case 2:8 c) J7 B" _: }2 s3 u
setfillcolor(YELLOW);
* c, R& t( u% X* n& W* vfillrectangle(450,50,500,100);
& N1 G4 r* B/ d* C( c: Routtextxy(510,50,"SJf");( G: o7 v" Q; h: c
break;1 n+ J9 [, k/ u
case 3:
' ?- k6 A5 Z( R+ {2 v: _% Q9 gsetfillcolor(BROWN);
' \1 F3 Z! r( @' x1 ^fillrectangle(580,50,630,100);
! L' x) k( p* e5 J/ u* ?outtextxy(640,50,"PR");' E! X8 m e- z# w8 L! @) O
break;. G. H8 E$ E' G1 d' u0 F7 c
case 4:
% @- o% ]* N& e3 V. I2 @+ i6 H2 \setfillcolor(GREEN);
3 w: w& \! G- h8 lfillrectangle(690,50,740,100);
$ ]0 p8 b, }; W2 \$ W4 ]; Zouttextxy(750,50,"HR");
3 @. e6 n8 w; h( \% r4 nbreak;
4 X/ ]" h, ~4 M# S- X% T. O3 Y}
9 c1 T) o/ b6 K/ U5 O/ ]fillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);- A) ?. l$ n# W9 `( A, L
fillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);
# q9 R9 y- Q1 kfillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);
$ X' `) j! A! X c3 n% ^fillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);( n# R- R' |7 j( q
6 O- {) S3 k4 A* I7 C
8 ], l& T* Z/ S. ^$ t0 l( B}
% f2 D1 o; \0 y% E; x outtextxy(100,150,"吞吐量");
. e& s: _5 I; i [outtextxy(350,150,"平均周转时间");$ T( i+ W% K6 Z' Z' \
outtextxy(650,150,"平均等待时间");
% L4 a6 K& p+ e3 Z6 Pouttextxy(950,150,"CPU利用率");
; W/ C; K. {: Q ]. O2 o! M1 Freturn 0;; }/ i3 J- |# G. G5 s, \, {
}! n9 D. K, Z. }7 ?& {7 s
int MouseListening()
$ k! H. X8 L9 l, o{
, q- X2 z! J0 J& I/ i- GMOUSEMSG p;
2 j1 a# X9 f. X ^6 ~% aif(MouseHit())
- J9 G3 x7 R' w; }& Y{
+ H W# o3 n, M/ Q; a1 c% |p=GetMouseMsg();
4 q) ~5 {5 {# Z9 Iif(p.mkLButton==true)% B X# R: w5 y" [ V- }3 t
{
! ~9 B7 P# s5 `. W* j& Tif(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)4 s6 o- {5 o1 ~; ?! A
FLAG_FIFO = 1;
# d# e/ A) t' U' ~+ p& a8 E9 Eelse if(p.x>400 && p.y>0 && p.x<800 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
+ s& ~: b' c+ y0 u6 WFLAG_TT = 1;
4 W: ?0 E8 l: Eelse if(p.x>800 && p.y>0 && p.x<1200 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
0 k0 X, i% k1 [' q. S5 SFLAG_PF = 1;
( M- W7 M# }; }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)
) Y5 @/ |" A$ v( AFLAG_SJF = 1;
6 \. z5 E$ K' O! h2 A- _2 kelse if(p.x>400 && p.y>325 && p.x<800 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
/ i1 P* ^3 s C4 VFLAG_HR=1;
7 Y- S6 ^5 L/ Q" Welse if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)
: { q6 Y8 d) _{* q7 B( `/ q. B) L" R
FLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;
6 b& V/ A7 u$ tclearrectangle(800,325,1200,650);& J5 N6 i3 ~0 d7 Z1 D0 r6 v
}
% E6 ~3 M' L7 Q" U) w" \) P$ I, ^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 ], m( d% E* _3 H{- G' `3 }/ B8 @+ e6 T
FLAG_show=0;
, z) C0 | B8 ^. T2 r+ scleardevice();
( U. L% B) J, d& | E) L# Hreturn 1;1 i$ X. B% K4 n J+ ]7 z6 u9 {
}
3 v& c) u1 e2 l+ O5 F2 ^4 ]! M; s}0 u1 @# g) f* ~
}, X2 R4 ^5 M$ e* |
return 0;3 w" I1 W) M6 S4 g
}. _; S0 [ V% T: T# i( D/ r
int MouseListening2(int *flagShow,int * showTime)
& z6 q6 b4 x! a% \0 p{/ {$ B, c; G7 |$ E: H/ I8 `
MOUSEMSG p;& |- V. V5 o/ T2 S: u
rectangle(1150,0,1200,50);5 F7 y% @. `$ o+ D$ b6 P
outtextxy(1160,10,"X");1 n0 u r6 R4 g* ~
while(1)
+ p1 ?: }6 T" N5 Y* e" L t; n{0 o' y% Z! k/ {7 o0 h; R& F' a" q! e
if(MouseHit()); a* n% n# G4 P. I
{
2 x: Q- J2 q3 Cp=GetMouseMsg();7 |! I& v, q; Z4 R, q9 R2 u
if(p.mkLButton==true)
* U& S3 ^+ V7 K# ~, e7 V{
: A; a. w9 {$ i$ l, oif(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 )! T! N& O& V, I2 E" n
{
- b5 J5 o- S! J(*flagShow) = 0;
1 j m- ]8 _: h" \+ [3 v) @ a: i(*showTime) += (*showTime);: L' H/ J+ x1 @! w8 f; G i4 N6 [
FLAG_show=1;
9 G; R' h8 S. }' `+ c% [$ t* h8 }break;
0 H3 j+ ~: z. N" o7 ]8 j0 D6 y; U}1 r! q" Z) o. v0 K
1 Z$ k2 R( w$ K' f
}
' N ^1 _0 R1 U9 p}
" z7 O7 }- o7 CSleep(20);* o1 h" | X- y% Q) U8 a' @
}6 M" O. S9 j6 e. H, _
cleardevice();! ]8 D4 ?/ u* e& ]3 n% d$ X* t
return 0;
: R: y" b. a* k}. r: ~& T' J! y9 |
int drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)
/ l; a( E: [ d* }4 d( \{# a8 E2 u( U7 p' u$ i/ l
static int info[11][3],num=0;
) `* E) S& L8 A: O4 _3 Y2 [, u rint i=0,j=0,pos[10][3][2];
% w7 @/ _. C8 J# q% q$ t3 u0 ^4 zfloat temp,t;+ s* F$ U( m+ C& j
//画按钮,不属于FIFO图的范围, ]# ]/ k8 E! B% k# N) Z0 t
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1)( w' I; ^, G d- H$ ]. j
{6 z: ], F; t/ G% U9 X6 f' }# H3 k
settextstyle(30, 15, _T("楷体"));
1 {# H0 p3 k( d7 m: l1 u4 R9 D" @rectangle(890,455,1110,510);4 j- C$ `. N; z/ r. ~( y, M2 F1 v
rectangle(900,465,1100,500);
7 T, [% J/ l C; N3 S: m% {# [2 W {' |outtextxy(910,468,"查看运行结果");
6 G. |+ L( y' {3 j}! i" b, `! ^. }4 [. i" i- |
//结束画按钮5 V, J4 G" r$ X! T" q" p3 q" U5 F7 e7 B
info[num][0] = com;( a1 ?+ T. W+ U/ s( w8 P
info[num][1] = wai;
2 i: Y" e4 _) h9 J- C3 ]info[num++][2] = cha;
5 U5 }# L3 y7 T+ B& n6 z& qif(num>10) //存储10个点
: |3 A1 x0 I; ^( X4 i4 }$ h$ @{
1 T& S8 \, A% m6 G4 I* [. ^% @" Dfor(i=0 ;i<10;i++)7 o* q& n5 V7 t7 q. n
{% @) l' r2 A& N0 Z* z& X2 t
info[0] = info[i+1][0];( i; L0 _5 z' @" u5 v$ T4 e! ~
info[1] = info[i+1][1];. ~. a% V: V% _7 E- S' `- R
info[2] = info[i+1][2];
$ W+ N2 E9 C s6 x}
/ o I: y8 R' w; H! d3 enum--;. o: P! |/ b/ u0 o; P2 P
}
. Y" v1 d% |* kif(FLAG_show==0)
7 v$ N; f* c' L- breturn 0;# V/ a3 ]5 o4 Q) O! K) }( N
for(i=0; i<num; i++)
2 g5 ~4 d9 i6 h. j( f* K# C6 q I{
' c4 f4 A! U8 st = (float)info[0];: d# p% C# q+ \$ Z& j) |
temp = (t/101)*90;
$ Z/ ?- e a3 G& t! U* @0 i6 rpos[0][0] = (10-num+i)*25+x+100;) b7 U! M! F5 d5 x( G- S2 o( P
pos[0][1] = y+110-(int)temp;
, B) V1 v& i; ~! u# o+ Q; {/ `t = (float)info[1];
8 c5 Q! Z* b) a6 l5 I6 Jtemp = (t/101)*90;
# C/ f- K& U/ r+ F" R2 epos[1][0] = (10-num+i)*25+x+100;
# V; b9 k; j/ S+ X* w( E3 d6 }5 Q, Spos[1][1] = y+210-(int)temp;1 E Y3 x7 T+ y
t = (float)info[2];
+ k6 B& U# I: [ O# xtemp = (t/101)*90;* y3 K' g0 k2 s7 H
pos[2][0] = (10-num+i)*25+x+100;- d3 v: F* ^6 n% g1 w6 ?( \
pos[2][1] = y+310-(int)temp;
6 X, W* C7 u! i& J' T7 i}5 E6 n4 ]7 V' i' [1 d- P% ^
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
4 O ^, ]9 V# S0 C+ I4 y4 l. s{, @4 [5 `- Q' V2 S3 R
clearrectangle(x,y,x+400,y+315);8 a& m5 [- H5 s- | }, y* m' x
settextstyle(20, 10, _T("楷体"));
5 J0 m0 J* V/ ~ irectangle(x,y,x+400,y+325);
5 {* ]3 ]0 d" J) Zouttextxy(x+40,y+10,"CPU"); //画柱状图
2 a, _9 U: C+ H0 {- q7 Y" Bouttextxy(x+45,y+10+100,"IO");# Q9 [7 k5 _ ?( B
outtextxy(x+40-15,y+10+200,"change");$ h0 _% N( A B) n
rectangle(x+35,y+30,x+75,y+110);2 ]; }9 }! ^; ^- m( o ~8 A
rectangle(x+35,y+130,x+75,y+210);
$ y/ m. ~; F- I& u, erectangle(x+35,y+230,x+75,y+310);2 M w# u) N8 u4 S- I4 P/ ~
outtextxy(x+180,y+310,"FCFS");
6 g% E1 I3 t( b8 h8 x3 V0 Gt = (float)com;
R% c% \' E/ E- y! u! P0 Itemp=(t/101)*80;
% h' \" v# A# o2 z& v4 ~: y4 @fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
( u2 Y; r; x6 I: u7 g6 E+ F [" ot = (float)wai;3 M" m+ ~) L8 T! E: c5 F
temp=(t/101)*80;/ M; z6 T/ ~. ]5 k5 D" R
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
9 w' `- h* j% n" }# y. tt = (float)cha;
! k: [( G- J" T4 S9 ~/ |temp=(t/101)*80;0 [& Z: U! j, q* s, [4 n4 V
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);: B0 y' \+ d0 n) V% r# X
for(i=0; i<3; i++) //画坐标 high=90,length=250( e6 S2 y2 Q- Y# K z; k
{; Y) L- [; j- L7 n; Y+ _
line(x+100,y+110+100*i,x+350,y+110+100*i);
' {( C! U$ `' |6 s1 m& Kline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);" C9 a- I. E2 {: C8 } m0 j
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
/ {9 p- h: w$ t: w( G, D* o8 [+ l+ n6 F# w* m
line(x+100,y+110+100*i,x+100,y+20+100*i);
/ c0 g+ O9 Z7 B8 [0 j! Kline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
4 L# O4 w% g& f! F3 b3 W3 \: z* Bline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
/ A0 P2 {: o) a4 T4 s3 w4 e2 k, O7 _) nfor(j=0;j<num-1;j++)
8 _3 r" b) k1 ^6 z{4 [# T* D1 t, Z9 W
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);: q% b3 t0 Q; U
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);2 \; \# A# J) o9 r
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
/ a3 I# k* X6 ]) a" i( E7 C8 a. n- A}4 G9 b$ L# d0 p4 u
}
6 u; t, F$ X' M1 l& f}
( W/ |0 }6 Q1 T ]0 ?) M* r ?else if(FLAG_FIFO==1)- O, i. ?& z2 ]6 l1 G
{ w, A/ ?8 X7 `4 V2 O0 R( q, o
x=0,y=0;" [" _6 e$ `! `9 [
for(i=0; i<num; i++)' \0 X+ `2 y& e* M- B1 ?
{2 O0 k. {' ]+ R' C- M! t" E1 x
t = (float)info[0];3 y* Q! E$ S5 H& Z9 Z) C
temp = (t/101)*180;
5 c1 H$ V. k% Z: S0 h9 Cpos[0][0] = (10-num+i)*50+x+650;+ Z. F. T4 L1 p0 \6 P5 h1 _! w# W+ a8 ?
pos[0][1] = y+210-(int)temp;
" L) t2 p) Y+ N% D# xt = (float)info[1];
3 ?% D0 X+ g: F2 x" L3 itemp = (t/101)*180;* r0 Y& H9 U0 r2 Z0 w$ t) G0 K. k
pos[1][0] = (10-num+i)*50+x+650;2 E7 p1 _8 t0 `" ^4 L
pos[1][1] = y+420-(int)temp;
0 b# B# I" ]' Y2 N% L/ Rt = (float)info[2];6 ^9 a% z3 M: B1 k* g# a3 L
temp = (float)(t/101)*180;/ E* H v; L( s: C1 j
pos[2][0] = (10-num+i)*50+x+650;
9 @7 k% R6 y' G# q* N7 ]: W: F0 qpos[2][1] = y+630-(int)temp;4 Z2 q1 f9 m0 q( T9 `7 k
}, {! _6 ~, }: `% G7 P Q5 Z
clearrectangle(x,y,x+1200,y+650);0 x1 y* P5 o* ]3 j: h/ v2 b! u
settextstyle(40, 20, _T("楷体"));3 g) Q# N6 M) p
outtextxy(x+50,y+50,"FCFS");
# ^1 r/ i! ^. x1 Uouttextxy(x+280,y+20,"CPU"); //画柱状图
2 E' w: l# c7 c: [outtextxy(x+285,y+20+200,"IO");
1 f5 `3 v" f" _outtextxy(x+250,y+20+400,"change");
' J+ w" D, D# Q, ]$ w: l Urectangle(x+270,y+65,x+330,y+215);& X2 V5 D/ `4 b, h, L- v
rectangle(x+270,y+265,x+330,y+415);
. n. f3 P) x( P: `2 ]9 V. Crectangle(x+270,y+465,x+330,y+615);$ C- ^( u3 K' V) \! }! _
outtextxy(x+290,y+620,"TT");& Q( r( Z, _% W- u1 u7 x7 X7 U0 E
t = (float)com;
" ?- O6 D! _; ^+ A5 C/ Ttemp=(t/101)*150;
5 B8 k8 }- L* K; a2 m& R5 |fillrectangle(x+270,y+215-(int)temp,x+330,y+215);4 L8 M t) |' v4 U" _6 T6 J
t = (float)wai;
. H0 I* ]1 w3 s! |; o( x$ {5 rtemp=(t/101)*150;
" l) n8 o( D' R6 Tfillrectangle(x+270,y+415-(int)temp,x+330,y+415);' N, [5 P8 d7 ~$ L+ z
t = (float)cha;2 ^4 M- Z* Q) k4 R6 d
temp=(t/101)*150;
$ ]! M+ f0 y+ h/ Vfillrectangle(x+270,y+615-(int)temp,x+330,y+615);& W* ]/ O$ X; T9 W6 f- s
for(i=0; i<3; i++) //画坐标 high=90,length=250
# p+ G2 H9 U6 B, ]{
. C. P# J8 F$ h+ f: lline(x+650,y+210+210*i,x+1150,y+210+210*i);9 l: c' U7 s* {
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);" t+ J4 A) R5 J5 U, h
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
& O, p3 ]9 N% R5 \
, `: r" F$ o% y( J& C9 oline(x+650,y+210+210*i,x+650,y+20+210*i);% C4 Q- q6 F6 E+ o/ K
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
s6 b8 a: U5 s5 g) V8 Aline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);5 E# i. R+ P) J1 V$ ^8 z( j
for(j=0;j<num-1;j++)- i: _5 V! o0 R3 @* S
{
! L* D; S7 s2 z$ l! Oline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);, d7 {3 z0 B+ K
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
' z' R. t' M6 Q) aline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
0 J( w8 d: u" R1 b+ v) ?}- E9 [+ b9 N2 I+ M8 L1 A5 [5 c0 ?
}# A# T1 T* \5 S: z$ ]
}) C% t2 e7 C6 d) W9 _" F- ~
' P. T' r6 d$ n( Q/ e2 h
7 F* [# p! U; r( j yreturn 0;
/ I5 u5 B/ h% |! f}' D, U I/ S/ e! F+ l% b
int drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)
6 H L& F; ~7 y+ U- O" B) K$ k; m{) W1 @! U4 m0 c3 _
static int info[11][3],num=0;4 \3 o8 S& Q- P& S' D
int i=0,j=0,pos[10][3][2];
# Y4 h9 L2 y V% [& ^. D: J# R$ ifloat temp,t; m5 o- w) T4 n: f% F. j1 d
info[num][0] = com;
9 B& m: L: g3 uinfo[num][1] = wai;7 \/ S6 m* V3 |3 v: l
info[num++][2] = cha;
& i6 T2 d# q8 q7 O. zif(num>10) //存储10个点
) q$ t0 Z+ J8 U( d+ g6 V{
/ \' i. V5 X+ B; jfor(i=0 ;i<10;i++) m! \3 a- w: S6 t
{3 | ~5 h: n3 g9 F: Q: F
info[0] = info[i+1][0];
6 z: F9 ] e! T) h& B1 Iinfo[1] = info[i+1][1];0 L$ E7 O* K; [* l0 V2 J3 [
info[2] = info[i+1][2];
g. C! I3 v9 v, A6 O) O D}
1 o9 o/ e4 ]3 O, o" Q# V( B+ K" znum--;4 K: l/ f7 C" M* e- H: T
}# K5 W# G2 \. A( W+ }; f
if(FLAG_show==0)
7 M1 j7 N( m; Dreturn 0;
- J7 [ \ c4 i! Lfor(i=0; i<num; i++)
$ N9 F0 D- W$ p' ~5 a2 e: h8 g: W{
# |- e1 q- K+ t v: c, `7 Zt = (float)info[0];7 J7 T% }, m5 O+ a3 ^1 k/ Y5 H
temp = (t/101)*90;4 v! U G1 d/ L" a
pos[0][0] = (10-num+i)*25+x+100;
: F+ K# F3 Q& Q1 ]+ `& |0 wpos[0][1] = y+110-(int)temp;3 v5 D$ l/ ? g# d' T5 L/ n
t = (float)info[1];; r, X) T7 k( H: c; w
temp = (t/101)*90;# i ?8 Y) y" }- @ i1 G
pos[1][0] = (10-num+i)*25+x+100;; C. t1 N- l J8 O- z6 V
pos[1][1] = y+210-(int)temp;- q# f" \ B) ` k. i$ c
t = (float)info[2];$ o9 a' c) |& W9 K' Q1 A( f. A
temp = (float)(t/101)*90;& ~0 v$ i3 E0 `, Z
pos[2][0] = (10-num+i)*25+x+100;, e8 K c, ~/ {9 S0 A" g8 X" Z7 r
pos[2][1] = y+310-(int)temp;( U$ x* z9 a9 m. C6 l
}: x: q1 |" {0 ~! ]6 X
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)# H+ {8 P/ a& x$ h8 R* A
{
( w: ` x6 A _+ g* P$ T/ i4 o) Fclearrectangle(x,y,x+400,y+315);' O# E* W: |: X! U, c2 d2 H) Q3 [
settextstyle(20, 10, _T("楷体"));0 a3 R( I1 x8 c
rectangle(x,y,x+400,y+325);
0 G; J7 H- @+ S+ f- Fouttextxy(x+40,y+10,"CPU"); //画柱状图% h+ u1 s' v1 `0 R, Y, X3 i! R; R
outtextxy(x+45,y+10+100,"IO"); ]/ W6 [* U& l1 }9 x
outtextxy(x+40-15,y+10+200,"change");0 y2 {, U0 E; W/ A3 p8 Z. }
rectangle(x+35,y+30,x+75,y+110);1 N. Z( ?6 G7 O5 S5 A. ]' q
rectangle(x+35,y+130,x+75,y+210);
: d7 D. E5 h( j0 m: x% arectangle(x+35,y+230,x+75,y+310);
4 d( s4 X/ w0 E. y- D& C3 I8 ~outtextxy(x+180,y+310,"HR");
# @2 M% N7 Q$ c( O3 i% p; p! ft = (float)com;5 A+ R% y2 t$ I6 C
temp=(t/101)*80;6 O2 i& v' R k
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);9 F4 |+ G* q5 T+ F8 h- _; l
t = (float)wai;
& m, b5 g- v7 q( J4 {; etemp=(t/101)*80;- I" S& R! ?4 j$ I% ?, G
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);1 W5 r) D1 k& g3 X0 G$ w
t = (float)cha;
1 i: i# S% }8 |& }9 y, Jtemp=(t/101)*80;( A/ x- \, t1 L( U
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);4 m' x. H, x; v) I8 V/ j5 C/ N/ _
for(i=0; i<3; i++) //画坐标 high=90,length=250
8 `5 u* w& R" b; S) P0 w{
+ Q& p$ m/ @) ?: `& eline(x+100,y+110+100*i,x+350,y+110+100*i);
4 m* v* G9 l7 \5 A0 qline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
" f2 H- W% S5 Uline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
8 t3 T7 x: x0 o" E8 x
) n- B ?" f" L; z. U. x+ }2 C% ~line(x+100,y+110+100*i,x+100,y+20+100*i);
) X6 D! v! P" R0 B6 Y( l7 _" _: C. b3 Wline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
. n- n% P5 i0 V. F1 }line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);0 J3 n* A4 D) e; ]
for(j=0;j<num-1;j++). H+ L* j3 l' r; d2 [2 _
{# P B) l) w9 _0 g
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);% E7 Y. _, {: \9 U' X! ^+ K
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);* O M! ?. W+ |, c2 k0 x
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
% v5 e$ F% l/ j, I; V9 k# s} X4 L0 D; R) B; t
}
" ~7 _2 _3 q" X1 S$ j, W}
+ Y" W6 a8 R" ?& u% O; H0 ~3 r* ^else if(FLAG_HR==1) }. y9 i$ i8 b* Y; v3 R
{2 P# O9 d$ \4 e
x=0,y=0;; E; v, L6 U: W0 N; W
for(i=0; i<num; i++)
- N/ W+ E( D( _' e3 p; V{* l( D1 F1 s- `/ o% e1 m8 C
t = (float)info[0];" u" N1 W) Z5 b* d" b) F
temp = (t/101)*180;! [8 u5 H. q3 {: O
pos[0][0] = (10-num+i)*50+x+650;1 Z; V* {3 ]) F, S) b
pos[0][1] = y+210-(int)temp;
0 r6 z) O1 Z. G9 Z" s8 j# ~t = (float)info[1];$ A& a8 }2 l/ I/ z3 a( B
temp = (t/101)*180;
# R! [& S! [' v' Tpos[1][0] = (10-num+i)*50+x+650;* B! n3 E3 j( W" k* @$ {
pos[1][1] = y+420-(int)temp;7 E' g2 G$ t a' Q& @* t9 j
t = (float)info[2];: c4 G! }$ }; h/ X I3 K
temp = (float)(t/101)*180;
1 N0 z! k# b3 h% V! W( [/ Jpos[2][0] = (10-num+i)*50+x+650;* m: }& Y1 O7 [6 b/ m8 ?
pos[2][1] = y+630-(int)temp;
1 [. l y0 f$ s% ]' Y5 E% i! d' [}
7 s$ F# T8 n& _" B3 A# A7 pclearrectangle(x,y,x+1200,y+650);3 Z G, I1 L- S4 a/ s4 _
settextstyle(40, 20, _T("楷体"));
. r9 e9 }1 E# o: ^outtextxy(x+50,y+50,"HR");, ]# q+ w. E! a' J" z
outtextxy(x+280,y+20,"CPU"); //画柱状图 M0 F( j/ j8 y, R( c* q
outtextxy(x+285,y+20+200,"IO");+ B/ Z9 h% g0 a" U- {- o
outtextxy(x+250,y+20+400,"change");
/ n3 y& \ ?5 v7 T9 G xrectangle(x+270,y+65,x+330,y+215);
* ~% c( g7 _/ A6 k g0 prectangle(x+270,y+265,x+330,y+415);& Q. [& x$ c7 C/ f3 C, J
rectangle(x+270,y+465,x+330,y+615);' j' S# G b! w' J+ ~' m
outtextxy(x+290,y+620,"TT");
0 C8 h0 K7 u) m( L xt = (float)com;9 F. i4 X5 u/ T1 \8 P4 ^+ O! @5 Y- D
temp=(t/101)*150;
5 k$ D) Y( q7 ~9 f5 Z6 R- N; Tfillrectangle(x+270,y+215-(int)temp,x+330,y+215);- K. j1 k: c E* _( t% [' U; R r
t = (float)wai;% c# o# r2 w7 _, y1 \' E) L6 t. g/ ~
temp=(t/101)*150;
- t: P! o' x2 I2 K g+ L/ Wfillrectangle(x+270,y+415-(int)temp,x+330,y+415);. `8 J3 v( q9 j
t = (float)cha;
) C6 m9 o' m, D' d5 b( j7 I4 a0 Q. Mtemp=(t/101)*150;
7 i8 }# B$ B, X- A; z9 lfillrectangle(x+270,y+615-(int)temp,x+330,y+615);: h# P, P8 J' ^4 e" Y3 J- l2 m/ R
for(i=0; i<3; i++) //画坐标 high=90,length=250( v' [! E7 ~6 n) H- C8 ^) z
{
& F6 }$ I6 |6 Z+ U) T% [& hline(x+650,y+210+210*i,x+1150,y+210+210*i);
0 s6 U5 L) V3 O* vline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
3 Z8 p$ A e! W7 oline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
' q; s5 u4 d( o3 q3 u) h" N+ g
* k5 F, q/ n; ~9 S1 q8 ^line(x+650,y+210+210*i,x+650,y+20+210*i);
" {/ f) n7 q' h l6 W' i eline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
2 U# @, O+ y0 g; L5 K. o5 | |& f. ~line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
7 B4 _# ^* G' ^# jfor(j=0;j<num-1;j++)
8 G$ m6 S+ o2 ?5 [{& x! X# A3 `# ^8 a+ [7 I$ B# P7 x! Q
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
% p) x5 l3 c+ M8 @ X; zline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);: l( u: M' y3 A% H
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
5 I- Q: B& X9 ^. V1 ^4 N}
4 E7 b# J) T" `$ N9 M! s5 t. G}
7 x$ g0 ] q! I5 @2 q} q. M1 z; m: h F
3 Q3 j1 B( _. p3 N
2 G3 h T* n4 E0 i7 t1 ?% [; {
return 0;. K5 P* Q% k4 e7 M8 S
}9 ]+ n$ o" h- Z! Q8 q
int drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)
* i% v' d5 ]) N4 b{/ g/ C: R& @5 ?1 I( K" q& a
static int info[11][3],num=0;
$ Z9 f$ r; l4 ~. s0 N' ]4 c5 ]int i=0,j=0,pos[10][3][2];8 _0 V' j {: Z
float temp,t;% A/ E4 T: R2 c/ c ?* Y; w! p
info[num][0] = com;5 r3 b! J L2 {9 G
info[num][1] = wai;4 \5 l- o+ c2 R
info[num++][2] = cha;3 E+ A9 j: U! T& u
if(num>10) //存储10个点
: v4 [ T/ r" p9 ]{6 L1 W/ ~+ Z) ]1 r" a/ T; ]
for(i=0 ;i<10;i++). K" g7 F7 G. w z. \: o
{
+ v& q( r/ A- Ninfo[0] = info[i+1][0];0 v0 W8 E6 ~) m6 { J2 H$ X
info[1] = info[i+1][1];
5 O0 w7 G- e% l/ I6 |info[2] = info[i+1][2];
2 Q' C$ z+ V+ P4 ]9 ] `% h& V}
) q7 p& s7 h2 \$ [3 onum--;
& M6 N$ v5 Y) h( z* d) o7 o+ u}; ^$ n& |/ u" u; o
if(FLAG_show==0)6 v. B# O; F$ X6 I$ S$ Z, {; ^
return 0;
3 {$ q: @# p& D; L$ ^for(i=0; i<num; i++)
) a' E6 w& g3 Q' b{! q* ?$ ]1 [( w/ j9 r
t = (float)info[0];
! [! d; G9 w. }3 Otemp = (t/101)*90;9 g3 Z6 W! Y2 G; Z
pos[0][0] = (10-num+i)*25+x+100;9 U. q( m. Z, Y8 h% [! k2 ^
pos[0][1] = y+110-(int)temp;
' h* _8 ^; ?9 e" ot = (float)info[1];, S- @, k5 o; ]8 r1 {- [8 \
temp = (t/101)*90;
% g2 [$ d) {( ^( e6 ^pos[1][0] = (10-num+i)*25+x+100;7 F2 j: `/ J' v7 P ~3 c
pos[1][1] = y+210-(int)temp;
5 B* u9 z1 N. x" v& O6 G0 ot = (float)info[2];( a- K9 i- U0 Y; c; c; m M
temp = (float)(t/101)*90;+ h; ~- I4 C) x" B2 p- v
pos[2][0] = (10-num+i)*25+x+100;
3 a6 `& E0 Q1 z; @! q4 H0 Q! x9 Hpos[2][1] = y+310-(int)temp;! }$ }2 ~/ h# f) s4 J
}9 s, u) S0 K" R( q' Y+ n- ]7 |
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
' A t+ G1 ]$ r4 v2 E6 J Z4 N" j{0 p8 s) R9 n6 s/ o5 [) } a3 W9 v
clearrectangle(x,y,x+400,y+315);
$ A) s- [- ]# I- Y9 hsettextstyle(20, 10, _T("楷体"));
/ C% w& o8 K4 ]8 K! \9 f) W5 P# G4 Erectangle(x,y,x+400,y+325);5 q C4 x" s) T; [
outtextxy(x+40,y+10,"CPU"); //画柱状图
; Z' R- g; O! ~& P7 Nouttextxy(x+45,y+10+100,"IO");
* Q( m; X* g6 V3 }9 l0 w5 fouttextxy(x+40-15,y+10+200,"change");
2 @/ Y0 G. z! o7 r+ jrectangle(x+35,y+30,x+75,y+110);4 g8 p$ A; l# G8 H: W4 g8 t" Q
rectangle(x+35,y+130,x+75,y+210);: z9 |8 G6 l4 J7 N q" D
rectangle(x+35,y+230,x+75,y+310);
. n$ n: s0 q* j) K0 uouttextxy(x+180,y+310,"TT");& y# T, {- |( S- s! D
t = (float)com;
$ ~! g# T9 U, \5 k! t- D$ ^temp=(t/101)*80;
6 w5 b+ H; q* bfillrectangle(x+35,y+110-(int)temp,x+75,y+110);; m/ A, s/ f# s5 O, b! L' I3 t
t = (float)wai;1 g- ` `, F, X
temp=(t/101)*80;
/ p; h8 ^$ J, h" N1 T$ }7 e* o+ {2 Pfillrectangle(x+35,y+210-(int)temp,x+75,y+210);/ C/ z( u2 M2 l( t+ ~- F
t = (float)cha;
4 O, z4 k( L; f. Ctemp=(t/101)*80;
# [, J& V: T t% sfillrectangle(x+35,y+310-(int)temp,x+75,y+310); X& k3 F* }; S4 {0 F+ H h
for(i=0; i<3; i++) //画坐标 high=90,length=250' Y% d% M4 ^- [1 T+ {: x& s( W% w
{
4 J0 P2 ?% s3 b. Z Eline(x+100,y+110+100*i,x+350,y+110+100*i);) D. m2 Y- ^7 b
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);& ^# c d k0 o+ j( s
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
, ]; X$ W5 b8 S7 k4 E- S) ~. F7 S- s% s4 @7 i* h
line(x+100,y+110+100*i,x+100,y+20+100*i);$ U! D+ l7 [9 `1 Q# e
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);$ d7 }& X- A1 Z" d6 i9 t
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);& }: ^7 h) G: a* @6 i
for(j=0;j<num-1;j++)1 n; X$ x5 F! F- I1 O' P7 W1 F1 u( R
{
! Z" f) U* y6 N- ?) ]. Qline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
- {) C& V, Q4 J: R: B1 K! t7 }& Tline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
6 q: r% X3 i6 F: Bline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
0 ]9 Y3 q) i( N) H* W; W) z}
% y: j+ t& o Z4 B}
" ]! P4 I0 T1 \7 X- V1 Y, B. C}
' J" c `/ i/ ?8 e2 l7 T& A+ Eelse if(FLAG_TT==1)
% S8 ^; {: q3 r" |{ R9 H; u7 y4 {% E
x=0,y=0;
V+ @' M' ]5 i) Ufor(i=0; i<num; i++)
2 m' g6 a% Y0 _6 E2 }{
+ V0 P5 Q% f$ i3 Ct = (float)info[0];5 Q) \7 Q' O- U. _
temp = (t/101)*180;
' f: g9 i/ u, wpos[0][0] = (10-num+i)*50+x+650;
; A1 f; A2 }0 [5 a! ]! T( q# o) fpos[0][1] = y+210-(int)temp;
% a7 x' H1 Z- g+ Ft = (float)info[1];4 c7 F% Z( v6 S. v4 j. W2 C
temp = (t/101)*180;
7 O3 [# m/ d3 J! q9 Y fpos[1][0] = (10-num+i)*50+x+650;
- x; r5 E+ |7 m0 o; }2 Fpos[1][1] = y+420-(int)temp;- c! L- b. V+ ?7 E7 L2 u9 }& M
t = (float)info[2];# }# T5 J3 \" V7 \, Q
temp = (float)(t/101)*180;) y* I5 E4 I5 N2 `5 W( Y: @* b
pos[2][0] = (10-num+i)*50+x+650;# z" | V% K' Q0 |: o
pos[2][1] = y+630-(int)temp;
$ ^# z- l- z* T/ X4 y} Z6 D2 g. }( x! r9 ?" y
clearrectangle(x,y,x+1200,y+650);
* S+ {( ^- Z M1 [/ csettextstyle(40, 20, _T("楷体"));
8 h/ d) T4 x$ V$ K# ^outtextxy(x+50,y+50,"TT");' Z# h9 [( G% D$ L+ E
outtextxy(x+280,y+20,"CPU"); //画柱状图
' o4 t p. g5 b* Zouttextxy(x+285,y+20+200,"IO");
6 T. R3 z6 t. ~6 k$ s2 m9 }( Routtextxy(x+250,y+20+400,"change");
2 w& _0 r# R" G6 }. [rectangle(x+270,y+65,x+330,y+215);
3 {; A0 W" x% S: ^8 w+ `" Lrectangle(x+270,y+265,x+330,y+415);; q7 @8 t; S4 d) z
rectangle(x+270,y+465,x+330,y+615);1 R$ f& u% h+ ?+ v
outtextxy(x+290,y+620,"TT");$ i) ?5 ]: S# w9 `' ~- H
t = (float)com;
5 K8 H f- g* `* L9 Y7 Y6 M. Q0 _; k8 Etemp=(t/101)*150;
1 ?* H0 f0 J7 `: a" J9 f" jfillrectangle(x+270,y+215-(int)temp,x+330,y+215);; P5 U. F3 m0 S
t = (float)wai;
$ x6 A8 [7 ?2 q g' l2 }temp=(t/101)*150;) m! U# l2 I% p% P8 i: V8 v) O
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);3 f0 j2 p' y$ G6 u5 m! H# P1 ]% A
t = (float)cha;
+ z0 o& f& {8 r# u6 htemp=(t/101)*150;
$ h; h# q4 e$ m/ p; hfillrectangle(x+270,y+615-(int)temp,x+330,y+615);
2 {$ B$ {/ g2 F7 k- F" D( ^for(i=0; i<3; i++) //画坐标 high=90,length=250
6 I) S3 C/ m8 Q% r{
2 `) R1 Q4 D' }& Vline(x+650,y+210+210*i,x+1150,y+210+210*i);' p& _0 | }0 _) ~& S! G8 ]2 A
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);0 ^1 w- l( r# a' @( z0 ^
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);1 F5 P* ?) C' ]- T1 B
5 |5 g" p+ T# L7 u) i# @2 v* C
line(x+650,y+210+210*i,x+650,y+20+210*i);7 Q$ C5 ]# P9 W; Z K2 E
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);4 O% C( Y1 b6 Z+ f; p8 I
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);, X4 j" B. j) W; m8 `
for(j=0;j<num-1;j++)
9 N: ^) C- j/ Z7 F8 a! O( L0 }{$ J& D* L2 Z& o' @
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);" g! T" I1 [) V' T ^; i% |
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);% ~# k% j: c, y9 @" ?, E
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
4 T4 }/ O3 l$ C& ?}- ?, o8 e* c1 ?1 x/ Z; o5 `
}. [3 q; a6 O1 G9 m: ]6 Z( T6 _; y
}. ]6 m; y3 s2 E% S& H8 t5 }
8 [ }, X9 k. R; _
/ s- e% C$ \* L& L$ d3 A/ T2 L, qreturn 0;
/ \- `/ Q" r* b9 T) M& Z}9 K+ h6 C0 \ |2 C, E/ o
int drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)8 G" p% i; k, R# ~' M
{
# [ a! l& a, J, [0 J) mstatic int info[11][3],num=0;5 A! @6 A6 u9 c* v2 X8 w
int i=0,j=0,pos[10][3][2];% V9 O9 Y) V: h0 N
float temp,t;, d" \- j+ a7 d- l& S8 F
info[num][0] = com;/ v5 d3 c. v" X9 n, M( ?9 s
info[num][1] = wai;4 l/ `8 b1 Q Q6 g1 T
info[num++][2] = cha;
; I. N. D. V; y, o5 ~+ e2 pif(num>10) //存储10个点! n: W0 W2 A2 v4 ]
{7 t( \3 I6 o/ b. e; D
for(i=0 ;i<10;i++)
6 l; W9 m4 [+ m+ N{
- d8 h4 b$ l8 ]4 p2 I r! ainfo[0] = info[i+1][0];
2 l% V* ~/ C" ?. R, ^6 Cinfo[1] = info[i+1][1];
, z Q o9 e7 M& _) Tinfo[2] = info[i+1][2];
/ C" V- {1 w0 k5 D" f( a% O, B}
1 r+ {5 y3 z% X5 Z; vnum--;
1 G& R& V7 l1 c3 Y0 I& A: x} P/ w, h& Y. H9 w8 l
if(FLAG_show==0)
. i' O; U! P: G& b) j) _return 0;6 h3 f; ^2 k7 M( o
for(i=0; i<num; i++)& X, \6 O- ?+ ]
{
% J) {4 m |0 c2 K7 M+ vt = (float)info[0];+ B' _3 L4 R! K1 h4 R# r7 C
temp = (t/101)*90;
( D- y6 ~ Q0 L4 Mpos[0][0] = (10-num+i)*25+x+100;
* T! j8 o" t/ v8 m' ~pos[0][1] = y+110-(int)temp;
2 H& @/ ~3 D5 O! T2 Rt = (float)info[1];
7 y c/ o+ ?& S* n4 F( S: mtemp = (t/101)*90;2 J# J- { C" p. d
pos[1][0] = (10-num+i)*25+x+100;3 m* w0 H, |& l4 a) S3 G X" a! S
pos[1][1] = y+210-(int)temp;( P4 @6 k) q; }$ {3 |" D
t = (float)info[2];
7 ~) l! `0 z6 jtemp = (float)(t/101)*90;
2 f! g5 I1 M8 o1 G9 K" }pos[2][0] = (10-num+i)*25+x+100;" k* |& I$ S1 g/ H+ A( w
pos[2][1] = y+310-(int)temp;0 X4 n! a% m/ d1 Z+ n- s
}; f, b' t z7 }% [/ G! M
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)# b; ^+ H: }' r' e6 v3 Z4 p
{" l2 A1 a g: n3 I3 l$ ~+ Y E
clearrectangle(x,y,x+400,y+315);
( r1 ^5 ^ v; {settextstyle(20, 10, _T("楷体"));
8 }2 n* F9 p7 u) Yrectangle(x,y,x+400,y+325);! h/ u6 n/ e* ^% y) w) R
outtextxy(x+40,y+10,"CPU"); //画柱状图) j- a8 d8 f+ {. ?! N3 \/ I @
outtextxy(x+45,y+10+100,"IO");
5 P" l n8 \. [- b" mouttextxy(x+40-15,y+10+200,"change");
% ]8 f: z$ ]) yrectangle(x+35,y+30,x+75,y+110);# r8 z4 F; t. }2 X
rectangle(x+35,y+130,x+75,y+210);4 {/ P5 e C$ o8 ?
rectangle(x+35,y+230,x+75,y+310);
3 Q, s9 w( d, Z. o& Z$ {( `outtextxy(x+180,y+310,"PF");! \$ b: n0 A9 Z" u t
t = (float)com;
9 x, p8 W/ L) v5 S# P7 m, D. I. ltemp=(t/101)*80;
' i7 @5 u. N2 gfillrectangle(x+35,y+110-(int)temp,x+75,y+110);, I- V# Z* |/ \7 J* h8 J
t = (float)wai;
# ]: `. H( i. L wtemp=(t/101)*80;
3 ]2 S- P1 _3 F/ {3 Xfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
d* ^) d! z8 Xt = (float)cha;& L: s& Q8 X- t7 s% H8 K1 x9 {7 q
temp=(t/101)*80;
* K( f* A6 D2 F7 r' X. q* [6 rfillrectangle(x+35,y+310-(int)temp,x+75,y+310);
* A/ h3 t; A! Afor(i=0; i<3; i++) //画坐标 high=90,length=250
& Z4 ]3 x/ L* }, d' _- [{1 L# g3 ^6 ~3 E: {6 t
line(x+100,y+110+100*i,x+350,y+110+100*i);
1 u4 ]0 I: l" U$ V" T+ i* |line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);7 F, z9 B( y& s4 q
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
* j' @ i, X5 | i( _' ]4 x
5 c8 `3 E& J; w$ E- P2 F% nline(x+100,y+110+100*i,x+100,y+20+100*i);1 _! E; e7 @ `' L, V+ v
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);( D9 F8 S3 l5 o
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
( U1 D* t6 P1 ^1 I' ifor(j=0;j<num-1;j++) d0 o7 e& a6 j# \" a. Z6 e }
{
) @$ K' \' l3 v+ d) Jline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
# K2 c% f6 ~, l$ F9 e9 N3 I/ X& ^line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
- Y' J2 C/ S. B" v+ x$ e; {, F( aline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); : u' I2 q( j1 g) N, e( Z8 E
}
$ S8 i/ e4 _9 {}, B" W) E! W% z1 ~# N* m
}4 A5 S7 y o3 d, m- ]
else if(FLAG_PF==1)
5 _: F0 C1 R8 K' I7 i{
+ Q) M7 n6 M5 L* ^x=0,y=0;
. M! K0 Y0 a. v1 h, Y4 \% U1 nfor(i=0; i<num; i++)
4 P& N0 H9 Z1 x7 n' f! a. }{" [, {: l. ~6 }9 o x( h; ^" {
t = (float)info[0];1 y+ ^: ^. f+ e0 l6 j6 e5 l
temp = (t/101)*180;
0 L1 w# X V q; ?6 N$ v. H" Vpos[0][0] = (10-num+i)*50+x+650;
0 n" j4 X1 D- \pos[0][1] = y+210-(int)temp;
+ a" M6 S* Z- P& At = (float)info[1];
9 x4 {# K+ X3 a3 i. H7 mtemp = (t/101)*180;8 S( S: e3 Q. X
pos[1][0] = (10-num+i)*50+x+650;7 d1 t. L# x5 D: v
pos[1][1] = y+420-(int)temp;, n& w0 \7 k' E+ r* [6 Y
t = (float)info[2]; r$ ?! g$ l, O
temp = (float)(t/101)*180;# n* E4 P+ [& X3 N7 `- Y
pos[2][0] = (10-num+i)*50+x+650;
" ~" k4 w9 r( b8 s7 |; R. rpos[2][1] = y+630-(int)temp;
$ y& f3 e* y+ D+ M3 U}: _. p- U$ E5 |' m
clearrectangle(x,y,x+1200,y+650);! @& \2 Z E2 Z6 R
settextstyle(40, 20, _T("楷体"));) L% ]8 q: V, ^5 |5 K a$ ~# }
outtextxy(x+50,y+50,"PF");
a& b3 w1 C- S) _+ Oouttextxy(x+280,y+20,"CPU"); //画柱状图+ j. W( s* }7 y: D/ J$ E
outtextxy(x+285,y+20+200,"IO");+ @% I* `7 Q% d* y/ }
outtextxy(x+250,y+20+400,"change");8 g$ A. w V0 t* D) M! Z& _' [5 }
rectangle(x+270,y+65,x+330,y+215);+ `* F5 ~" [+ w* f; ^
rectangle(x+270,y+265,x+330,y+415);, M0 ^* J% V: D5 {
rectangle(x+270,y+465,x+330,y+615);
7 i# ^2 P% M$ i+ y8 p; Vouttextxy(x+290,y+620,"TT");
! l$ B' `6 p/ l( K0 _3 L/ Yt = (float)com;
0 b3 h% K( W% }6 w8 f, ytemp=(t/101)*150;# J9 g3 v# I2 P/ `: h+ G/ r
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);* B4 z# w: _9 |- t9 | V
t = (float)wai;; M7 {/ E/ d0 G+ q) k9 ~% s. R
temp=(t/101)*150;
( ^+ r$ a& y# U* Q0 U$ ifillrectangle(x+270,y+415-(int)temp,x+330,y+415);* o0 u& E% v' S; f1 d
t = (float)cha;' L6 t6 N( G. y! A1 x! ?8 X+ X- g
temp=(t/101)*150;" Z! B' D" v7 L8 I: Q' W
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);3 D7 c- {+ Y" d. |4 B" B3 Z
for(i=0; i<3; i++) //画坐标 high=90,length=250
8 V& `4 R$ ]0 g* b{
$ b* y r& o8 x$ z0 t9 S- L0 qline(x+650,y+210+210*i,x+1150,y+210+210*i);0 J* r& m! e' G' W- K
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);+ ^- O" [5 a7 E/ Z! h& `
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);' Q U2 s( V T
" y' }' o4 k3 D5 n, V( N1 a. s
line(x+650,y+210+210*i,x+650,y+20+210*i);
+ e: k2 E# e. V* M; `; l% l; lline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
" S! h3 i+ s4 G% a% y, E; S# B8 b2 o# `line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);! ~8 a0 u& e: W& r- c
for(j=0;j<num-1;j++): y; `; l4 |5 V& K' ^5 p" J `
{5 b' }. M& _ M3 Q0 c0 f- K! N( [
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
) J$ i2 ] o; n- l2 Eline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);$ ~$ Q* @0 E( c$ g7 M2 [8 A& p, m! ]
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
. o% n$ h: i$ p. I8 l9 N2 Q- e}
% H4 C- w* g- Y}
, {* Q4 c0 o. @# W6 O" y( s}, T% j2 b' Y+ S& v: y, v
return 0;
% w v1 i; m" {3 `4 u# Y" [; Z; }}
+ M6 y3 h+ M1 G2 Z6 f; P- Kint drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)
8 x# I5 |+ ^. j{/ ?8 n: t3 ?# j3 p7 {2 Y! N
static int info[11][3],num=0;
" I: m, d9 o, xint i=0,j=0,pos[10][3][2];% S* Y, Y \# I$ W1 `
float temp,t;
9 j6 H& A& V5 i' d& j+ oinfo[num][0] = com;
, a d2 j' S N( v% F& n& Z4 L/ l3 Ninfo[num][1] = wai;
+ w9 Y! p& L |4 o* B0 yinfo[num++][2] = cha;1 A2 j- p! [0 h$ J! d
if(num>10) //存储10个点2 \- B& T: U# M F% D* h- G
{/ Z$ ?, h3 ]- K, H) d
for(i=0 ;i<10;i++)) t' m* L+ j/ g: J3 V+ q: G
{
0 G2 ~) C8 K+ z! C& F; f H5 T0 ainfo[0] = info[i+1][0];- J+ t9 D& A" V
info[1] = info[i+1][1];4 c( r7 e& g: S! O8 ~
info[2] = info[i+1][2];
& N; j- n& _; j2 U% c! f}
: n' v- Z. j: b7 P5 q* S! @num--;! d9 Y; l7 `9 e9 z$ i: i% `$ [
}
: ?( K) ^' R# b B" dif(FLAG_show==0)& f/ d1 `, \% j* d' G6 U
return 0;& v4 ~! O; t/ z: [1 \9 z% u
for(i=0; i<num; i++)8 k1 P& C+ t8 ~' n# _& D U
{& p* n0 @# y! u0 W3 T& T
t = (float)info[0];& D# F2 ~- ]& J. d+ B/ k( n
temp = (t/101)*90;4 @, x$ \. S4 L4 V: M
pos[0][0] = (10-num+i)*25+x+100;
( [+ ~3 a8 D+ k; C- {% Ipos[0][1] = y+110-(int)temp;1 Y) g( B# e" S8 g; F
t = (float)info[1];8 h1 @5 `% ?# i4 j! h
temp = (t/101)*90;
( s1 m% L0 [0 K w% y% p5 H% xpos[1][0] = (10-num+i)*25+x+100;: C. H, M* l! Y7 h6 W* m4 Q
pos[1][1] = y+210-(int)temp;
9 _1 I3 k9 D8 P- h4 {% r3 pt = (float)info[2];! p' \4 n5 u0 f
temp = (float)(t/101)*90;
4 b9 h9 G% @1 e4 s' Q; mpos[2][0] = (10-num+i)*25+x+100;# `6 h ^2 a1 @3 [! M) v! S D. [
pos[2][1] = y+310-(int)temp;
2 p" g, a( C+ l+ W( x% C}
5 s: f+ N( D+ G6 o( uif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
* D- F( F( p! w8 |3 Y+ Q( d) R t{ 8 x4 i" P" C. j$ `6 I
clearrectangle(x,y,x+400,y+315);% c4 b: f& k7 u7 W
settextstyle(20, 10, _T("楷体"));* M7 {. ^- Q6 x( m$ R( Q% ]
rectangle(x,y,x+400,y+325);9 y) v; y* a; @1 Y: g, v
outtextxy(x+40,y+10,"CPU"); //画柱状图0 ]7 J7 r& {: y+ b, ?
outtextxy(x+45,y+10+100,"IO");) P5 C/ r* \$ } g
outtextxy(x+40-15,y+10+200,"change");
/ s) P( x- E0 R9 o! x% ]8 n; H krectangle(x+35,y+30,x+75,y+110);
; b8 l0 D0 K8 X, V1 c# brectangle(x+35,y+130,x+75,y+210);- R+ Q9 Q- q; X9 ~0 g; i
rectangle(x+35,y+230,x+75,y+310);
' s2 A; C" f' t, zouttextxy(x+180,y+310,"SJF");
9 b! K3 k( \) s1 f) D% Jt = (float)com;2 F& k$ P2 b; T
temp=(t/101)*80;" ?4 ]; {- {( d$ z1 I
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);4 s5 a" [( _! _' Y( _/ b6 t) G
t = (float)wai;/ d7 {2 U2 Y. n! }1 h$ @9 _
temp=(t/101)*80;! j' Z5 I) W: |3 ?
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
& w& D+ _8 j8 [t = (float)cha;0 n( n: y" G1 x/ ?8 \0 d
temp=(t/101)*80;$ Y( ~2 g! F9 l# r, N1 i
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);/ E$ [$ u$ B! Q6 Q& K0 D0 u
for(i=0; i<3; i++) //画坐标 high=90,length=250) s8 q; c6 {2 F
{
5 X. t- d* \% Q6 ]& I; }8 [line(x+100,y+110+100*i,x+350,y+110+100*i);) W( N3 N4 Z7 F- n6 @! {, y
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);6 `( a% I) e8 a8 d! k) V) b5 C
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
( @% N8 W! U {% B1 E+ X" u* `" k, H& O! X; s
line(x+100,y+110+100*i,x+100,y+20+100*i);
" e! o' x! P, E4 O* R, L0 \! ?7 \line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
* j( `$ n n' l I7 kline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
( [3 N) o# t# [2 I/ V3 L( Y: Ffor(j=0;j<num-1;j++)) q. R: S6 I: F3 _
{! \0 O! l9 m. x
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);, o4 c) Q9 H; a, Y; s2 ^0 I
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);8 z, c& X2 r: V$ f/ C' K1 _+ e
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 4 s4 b8 B' C. x* |/ o0 T
}
0 c* a! m# x* E}
) ^, S! I: E7 C& s! Z}
$ f$ |# f/ t5 ]/ V3 q! delse if(FLAG_SJF==1)
6 F7 t" H' B& k& N; n{5 ?# M% B$ f+ u6 u, _( m
x=0,y=0;
( ^9 C3 x* s# r5 Gfor(i=0; i<num; i++): W; X4 z7 e* w1 D j
{$ [1 [0 ]! Q" J; @+ e: R6 C
t = (float)info[0];
# c# e# Y1 \, ?# V4 }temp = (t/101)*180;
. ^. S4 h2 f: X+ _pos[0][0] = (10-num+i)*50+x+650;2 l( Z, p# s" g( X" |; w. A
pos[0][1] = y+210-(int)temp;2 |2 Q1 s4 J$ U K
t = (float)info[1];
# V* {$ K1 x8 j9 i. Ntemp = (t/101)*180;8 x# k7 [; [5 L l: M/ x; G
pos[1][0] = (10-num+i)*50+x+650;% A9 H$ n4 b: ^* B$ h F
pos[1][1] = y+420-(int)temp;
4 \ {5 m- f6 e) L: kt = (float)info[2];) g% T. \0 B* S" t) }" c4 o
temp = (float)(t/101)*180;
. D: z4 A; a7 z/ Y( m/ H# Epos[2][0] = (10-num+i)*50+x+650;0 r. z( C [# o# g0 ]& p& B4 x6 V
pos[2][1] = y+630-(int)temp;
+ Z/ Q m4 s7 ~6 f; O}. b8 ? X( k0 G4 D! p9 {& T
clearrectangle(x,y,x+1200,y+650);5 [. a2 N% k0 t+ K: W; d
settextstyle(40, 20, _T("楷体"));
, Z9 \0 x" z3 v2 T5 L5 R( Routtextxy(x+50,y+50,"SJF");. R- Z2 a+ D7 ~7 _$ g: x5 T
outtextxy(x+280,y+20,"CPU"); //画柱状图( Y4 A$ @( c" Q$ p$ P' z7 C
outtextxy(x+285,y+20+200,"IO");: x- N9 e2 V \1 O" {* g: ^
outtextxy(x+250,y+20+400,"change");
+ L; Y4 c+ d6 hrectangle(x+270,y+65,x+330,y+215);
+ f1 l+ k2 D% r Mrectangle(x+270,y+265,x+330,y+415);2 }" q4 Y. \5 O2 n! U
rectangle(x+270,y+465,x+330,y+615);
! [" z) n* T4 m& u2 d5 M1 o$ ]$ Gouttextxy(x+290,y+620,"TT");
( D+ G9 Q; v( v: i5 y" y% I7 Ut = (float)com;
7 s" d! r: I( m* `temp=(t/101)*150;
/ h+ G9 K% @% g" Afillrectangle(x+270,y+215-(int)temp,x+330,y+215);% H# ^' \4 [# n% Q& ^4 I6 Y. Z
t = (float)wai;
6 P1 H9 ^6 t. K) s3 Z. T- ]temp=(t/101)*150;& T! ?& h. ~2 C
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
7 ?" z) S7 W4 j- { Y6 Xt = (float)cha;/ ?3 o. z$ d0 v
temp=(t/101)*150;
4 T) T; }7 A% ~, zfillrectangle(x+270,y+615-(int)temp,x+330,y+615);
) c1 I5 b8 x5 R. [* G! Nfor(i=0; i<3; i++) //画坐标 high=90,length=250
Z5 c* e4 S/ c{
5 X" O3 o* Z. H1 a. w( {line(x+650,y+210+210*i,x+1150,y+210+210*i);
; y' O. f! i- m/ B0 Jline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);! |6 h8 P; {) Y! S2 [- h
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
' j) X/ q4 A" v9 s5 n
# b0 I) ?8 ~: u8 Mline(x+650,y+210+210*i,x+650,y+20+210*i);
: E8 ~, c. ^( `- U3 xline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);0 s3 ~' o* ~5 O1 V9 c! @6 H) c
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);) O8 B3 P# C% D( c' F
for(j=0;j<num-1;j++)
9 e$ [/ g, _! Z) y) s{
" F% {# v' B( x4 U6 ~/ qline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);1 \7 f% ~, W" M) W2 I0 O. }
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
& i/ p8 a' ], O* I; v: |- z& ^line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
$ p% Q! v) N! f& f. ^/ b}: x. C& f: S0 Y4 |" Q0 A* G
}
: ~. a; Z; d% Z/ h}
& N' B! \# u2 h' m5 b! @( kreturn 0;) H) b0 f$ P" c' @* T, g
}
; h% \- E9 A$ d. ?; }int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)6 y" i- E7 a; m& _# t! g
{
: ]- a% O( c i& I7 {5 estatic int compute=0,waitio=0,change=0;! Y& {2 c9 c5 r: e: r, @; D
static int computeLast=0,waitioLast=0,changeLast=0;' Q, C8 r( w6 j x) b% R. k
int i=0;
+ N& d6 d# s# ^9 \1 v; u( u hif(draw==1)) f7 U: S8 u6 k5 Y4 P+ F
{
! U: |3 b# n$ Q) A+ b( s }//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);& O' `: M) d$ h. [6 J
drawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);& V ` r6 f- H9 b# B
computeLast=compute;- D/ {7 F( |& i8 z) Z p
waitioLast=waitio;
4 H7 o j2 n- b9 gchangeLast=change;, Q: }; |3 D, |! q- u( C) e" x4 X
}
( v% p) O3 O1 Lif((* memory).p[0].flag==ready)) E& t/ k2 _6 \/ L+ o' ?4 v3 g+ }# X
(* memory).p[0].flag=computing;
- G7 E) O% ~6 z! D0 Wif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)' X6 K2 {4 `) [1 ]1 O5 q/ I6 P
{$ K' M6 R4 c j6 p- J0 ^
i=(*memory).p[0].computeNum;
! n; r8 `# V( W) Zif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed, s% H2 R. d& Z } w% |
{9 o- ~" c p3 N' h, H+ m: f6 S( j
(*memory).p[0].flag=IO_waiting;
) h0 w3 W: Y5 w2 Y/ l, n3 K4 D7 g0 H(*memory).p[0].computeNum--;
+ _9 P" d# O9 z5 N. G* ^change += exchange_IO_Compute;5 g! W3 m' [2 l/ @) m& }
compute++;
`( F. W0 F5 o4 j; `}8 h, o7 a& F' t2 a: w$ d& J0 \
else& O: G; t, i, H" ^
{8 J4 C3 u) {0 ^7 I8 z
compute++;) t4 G1 [" ? y) B8 G% j* B
}
* c" b5 w) g1 Q! U2 O' N}
8 M$ \, I9 A) aelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)0 V% Y& Y: `! q1 L
{4 N# C7 }4 p7 ^, f7 c# y
, D O3 H# c ^( ai=(*memory).p[0].ioNum;
: K) u5 w( o/ H+ {0 s6 S. ~if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed" x9 [: ]9 ^. T: q7 L/ M
{" N) d( F7 d x5 D
(*memory).p[0].flag=computing;, N9 N- l) X; e6 K" y' d
(*memory).p[0].ioNum--;
- j9 p7 w% q0 \1 o0 schange += exchange_IO_Compute;
) e7 p3 x; j( X: L" E: U, ewaitio++;' G2 _' d1 P+ [9 V
}
7 F0 ? o/ L. k7 n+ S/ H( Lelse+ t5 }% K1 ] _3 m
{0 ?: k. d2 ?0 Z$ f/ P w) H. K
waitio++;- p* X1 ?: a2 m9 H' l8 U6 i5 W
}
% u" u# }7 W& S4 B}
5 U% ]2 Y) l- C/ A' Lelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)5 M: R1 e* u& v' x0 L! A& M
{
% O) s- Q, n3 O8 r% F(* memory).p[0].flag=IO_waiting;$ M4 A- z6 |" C+ }2 }7 j# V
change += exchange_IO_Compute;
1 g8 [9 I3 t; I: Z7 Q}# J1 B6 q4 x5 q* |- @
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting), @, A8 A, E. Z
{; i. \" S$ i# \# _ s
(* memory).p[0].flag=computing;
' o! D9 l3 M0 c& A$ T% k, f3 lchange += exchange_IO_Compute;9 y' q& Q9 a6 D8 S
}: ^( @! @+ y: z, Q
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
" [' q1 S- X, b" D& w& I{
6 d+ c5 k7 W/ E. R# e5 G% A(*save) = (PCI*)malloc(sizeof(PCI));
, I8 l l2 L: M(*save)->next = NULL;
) A$ z( L' O! J(*save)->processID = (*memory).p[0].processID;7 n' O9 }0 c1 W8 b
(*save)->comeingTime = (*memory).p[0].produceTime;" A- q" E. N* R$ x& `' ^# G' Z! h
(*save)->askMemory = (*memory).p[0].askMemory;' R6 T. g- t9 \; M! K2 k5 m
(*save)->compute = compute;
" M4 y, J: m. g(*save)->waitio = waitio;# A1 ]$ p7 y+ k5 E1 h
(*save)->exchange = change;
" F( |" R6 i. ~7 a% Y& p* ]- U(*save)->completedTime = systemClock;
; |7 `- E' ^$ X! V8 i' E(*save)->runningTime = (*memory).p[0].runningTime;& }7 m' A8 L3 ?9 {* O
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;
, F* r0 a0 H) U; B/ Ycompute=waitio=change=0;
! t( ~: S, N5 K0 G3 k, }8 j) OcomputeLast=waitioLast=changeLast=0;- X/ U2 P1 D2 ~# g' Y
High_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);
# y3 D! t, u8 O7 gchange += exchange_process;
|$ o7 M8 r# X. }. v wreturn task_completed;) s/ |8 v: z- w8 F2 M
}6 m, m I, a& }
else N* T. h6 |4 i
return task_not_completed;7 u6 Y& ?" P& l! I9 j
}; x! s- N6 n, B. _, s
int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)$ k6 C+ j. c3 s
{
+ W+ p n5 o1 X) ^- P5 B* S$ R# Rstatic int waitTime[initProcessNum],i=0,j=0;
6 v) T* a/ F3 N( ~# y" hstatic double HR_ratio[initProcessNum];
4 ~7 z; }! I- p/ Bif(flag==0) //初始化数组: K+ [/ u# T9 j1 e' I
{
7 L) t) O8 |5 l3 i3 efor(i=0; i<initProcessNum; i++). t5 H) `" V" L$ n
{+ E R" `: E' A9 \
waitTime=0;
1 b8 Y: r/ W2 w( o9 hHR_ratio=1;
; @& n# N1 m _}
7 ~% h* v# ]: e5 C}) u- |9 d2 U: v n# h# u
for(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比
$ H" c' {: r' E3 d{" O9 p9 b8 z* A9 @
waitTime++;
$ o% y. a# b% zHR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);
, V% C% O$ t. l7 i$ O* D2 J5 oif(HR_ratio > HR_ratio[j])
" `4 S; \/ {5 ^" C. K! W7 pj = i;+ y# Q9 @% s9 U" p i7 R
}2 g$ m5 p& x8 |/ w4 n# B& y" _% u
if(dispatch==1) //需要调度一个进程到内存中执行& e& @% x% N( J# A: x
{5 P% G2 y: M6 I. R: u& s
if((*storage).p[j].askMemory < *spareMemory); R5 i/ h8 O+ H) ~2 ?* j" K
{
5 a* k$ ]% c6 S+ |2 h6 Z% {* ?, w(*memory).p[0].askMemory = (*storage).p[j].askMemory;
. u% P1 n5 R% U(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
+ A1 L+ r+ W; k+ F3 ~& c3 ^/ E9 u B(*memory).p[0].computeNum = (*storage).p[j].computeNum;" A- ^* Z8 t2 s I4 u: c' M/ r
(*memory).p[0].ioNum = (*storage).p[j].ioNum;* |8 r) z) h7 ]# a0 Z8 ?7 s \
(*memory).p[0].processID = (*storage).p[j].processID;
* a! k. r7 B2 V0 ^4 n(*memory).p[0].flag = (*storage).p[j].flag;8 o& C0 X [) I6 h+ Z$ o# R, U
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
, B( P: }1 \2 }0 P+ E(*memory).p[0].computeTime = (*storage).p[j].computeTime;
/ c* T" s$ Y: ~1 T% K(*memory).p[0].runningTime = systemClock;
" v& Z2 ~" I/ y8 d8 s) A F+ @# q(*memory).p[0].produceTime = (*storage).p[j].produceTime;$ g& [3 b: b- C0 B5 q* |
for(i=0; i<(*memory).p[0].ioNum; i++)
5 @& P" j) Y$ ?3 @. k4 p& ^(*memory).p[0].ioClock = (*storage).p[j].ioClock;
8 w% ?/ a8 i- _: Q: ~* O1 V: K- \for(i=0; i<(*memory).p[0].computeNum; i++)( c/ [$ d" a1 `1 i
(*memory).p[0].computeClock = (*storage).p[j].computeClock; c' `0 A6 K% q& m0 c3 F, z
(*memory).proNum=1;1 X% s7 Q& h7 [8 }# L
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
. n& L& v/ }& Fproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
8 Y o0 r# L% o# I/ Y(*storage).p[j].produceTime = systemClock;
8 ^, v4 @: V$ | KMAX_COMING_TIME = (*storage).p[j].comeingTime;
/ }1 w9 b: ?) ewaitTime[j] = 0;, W( P/ c& A8 ~/ X0 f
HR_ratio[j] = 1;. q& }3 X/ [5 w' u) |4 j- b
}
" S- C4 B B- c* uelse
& K5 ]+ x; y" y{
% D6 ~6 X# F* Zprintf("A process ask for a memory overed the system capacity\n ");
* U1 _1 F& M3 U b; mexit(1);
8 V2 h7 U/ Z$ ~7 J}% \4 d2 K4 e! R9 l! _
}
1 C7 S# x0 B1 l( p4 E! oreturn 0;
2 \. h7 J# ]& s- Y# n& w( q1 |/ }}+ P; g) e1 C ^* s/ {
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
+ M- i* O5 }8 B2 E( l3 F2 N{
# j; a) O( V4 Y4 J5 N/ {$ cstatic int compute=0,waitio=0,change=0;8 O( P" A6 s* [6 ^
static int computeLast=0,waitioLast=0,changeLast=0;
' a1 H5 A9 Y' h! |int i=0;2 U. i$ |! w# d: P( s. P
if(draw==1); d; n" n7 f2 B
{
8 ~9 S, k; S+ e# Z4 d* q2 X& h//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);8 X* Y8 \' n: L. L" M2 c% R
drawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);5 Z& q: R q; @) |$ r) F% \
7 x. B: l5 n6 q, d ]
0 ]# q: S5 W! S1 u. OcomputeLast=compute;6 h4 W/ n( M1 Q
waitioLast=waitio;
6 H1 @+ z7 b: DchangeLast=change;
. J# I# [4 [% G" p6 h}/ [* ?3 y1 r, t' O8 G" }6 E+ F
if((* memory).p[0].flag==ready)- Y R8 y% O0 D+ H7 f# F+ X
(* memory).p[0].flag=computing;
8 E- r) G" P1 @if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)" v* z9 H V1 |! F; i5 b7 X
{
; l* {, a& j3 `' L B9 i5 Hi=(*memory).p[0].computeNum;2 ]$ i8 ~# q! \9 Q+ f3 r
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
) a: y0 H- g% |8 J{6 [! I% S3 i, ~. z9 c3 r
(*memory).p[0].flag=IO_waiting;
/ a$ }3 f8 j+ f2 l(*memory).p[0].computeNum--; \" B. H2 B5 S8 c$ [; a% I
change += exchange_IO_Compute;; u* F0 {) U' Y: B+ I
compute++;" e( N6 B5 n' q6 e3 H
}
/ L5 B0 B* M2 M' B1 v1 I; ielse
- m1 m' q* ^; E4 X. T7 k5 {' M0 ^{
* ]2 |% `' S5 R1 w" Q: L1 n0 H, Fcompute++;. X( [, \9 V! c& r& E/ e0 L& s
}& A' j E: P9 U+ G9 f2 N9 G7 l; ~7 U
}
' f) J, q( O2 W0 Z! |else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
# G/ K! b6 i. y7 i' t. L{
6 Q0 V# Q u* E8 V+ I
9 U3 R7 j8 H" c: ki=(*memory).p[0].ioNum; |0 y& y5 q# t
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
, B3 j _, b6 c* N6 ^{; r/ j8 e/ ?0 y) a& E* j! R" D
(*memory).p[0].flag=computing;
2 O% w& V: i# [3 S0 I. W0 Q4 J(*memory).p[0].ioNum--;+ G! P% l7 N6 G d
change += exchange_IO_Compute;
/ r' l- E& r4 t& X% Z: twaitio++;8 {3 {5 ^+ Q# A. a
}
8 T) ^0 t: d7 A; Y+ T* Zelse
8 g3 z& L. x" v/ a2 b{ g' V* j3 g; x$ a) L9 F
waitio++;2 w+ V. I$ t4 m! P! D# S! ]6 i
}+ _+ Z1 i2 P( @. D7 O+ {
} M5 c2 s: b* A O* C& O8 p
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)# o B0 t- |/ X& B- k/ a' S
{
& `% m& X' b4 @9 r5 Y1 r(* memory).p[0].flag=IO_waiting;1 L( m6 e+ q/ x; A/ G6 ~6 E
change += exchange_IO_Compute;
1 s7 j2 l9 T/ p. t}0 ?7 I5 d' I: A9 H
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)( D" X% k1 r' A" i; H1 i% ]+ ]
{5 t$ _" V( _4 a/ ]) q
(* memory).p[0].flag=computing;' f2 c; A% z0 U$ u2 n9 C
change += exchange_IO_Compute;
" n5 Z% b3 ~% t3 [3 e) s0 s& A! l}( I! ?# n5 ?% D3 \( M. e' d1 i7 ^8 S+ I
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成' r4 m) E2 w7 p, b' r# V) p2 m& _
{: J1 x' c! r5 @3 D/ u
(*save) = (PCI*)malloc(sizeof(PCI));
9 S. r) Z9 N7 v& |' _% P4 c/ W7 {(*save)->next = NULL;
+ X, M* n5 }1 g. d" r(*save)->processID = (*memory).p[0].processID;
) @+ u5 j# u: @9 ]2 |(*save)->comeingTime = (*memory).p[0].produceTime;
# X- e- R' A. ~(*save)->askMemory = (*memory).p[0].askMemory;
: e% J+ c/ U+ U1 A0 U* Q( L G9 x(*save)->compute = compute;8 Q9 {$ R* S1 V2 s' e
(*save)->waitio = waitio;
0 E3 k! Y3 W6 w4 z: p(*save)->exchange = change;
6 p4 i4 j; Z. W(*save)->completedTime = systemClock;0 C3 L* a5 L. U0 p" b- a
(*save)->runningTime = (*memory).p[0].runningTime;
4 t8 j8 s: I* t9 C) C# T9 p3 Z* M*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;/ `: A5 X2 H2 N$ P
compute=waitio=change=0;: d |7 k3 R, ?* ^! @
computeLast=waitioLast=changeLast=0;
3 K' B/ A. H! T7 c6 I- V1 g: ~Priority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));# J/ X+ b, q. i) m
change += exchange_process;' l" b3 n3 s' M9 A
return task_completed;
' {' }& B8 u: j8 f: k% y}
; E( ]3 O2 z4 z6 a5 A# L! pelse/ h7 M( z; I* c, R' y! i! `" U2 R, e9 ~
return task_not_completed;3 Q- W; I& L8 T
}: \9 b8 Y y' Z' e
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
2 j! b" d7 p" T: r" K0 p{
# w+ F% I# Y- X+ b7 cint priorityNum[initProcessNum],i=0,j=0;: w1 o2 u; [ q( {" C
double temp=0;/ Y/ h7 x* _2 g3 H' q6 K( U
for(i=0; i<(*storage).proNum; i++) // setting priority to each process" `7 I( F/ M2 w2 U$ |: s
{9 _3 z1 Q/ q( q
temp = (*storage).p.computeTime/(*storage).p.ioTime;
7 e5 C* U: \! Aif(temp > 0.8)
Z$ L. @* Q Q+ ]priorityNum = 6;# U7 S) J) z. H2 S( {6 n* j0 e
else if(temp > 0.7)
8 O3 O7 M; Q" K, I" rpriorityNum = 5;
- }* n2 E% _% `# o+ V# `else if(temp > 0.6), k5 z9 h) r# T5 f0 d# J
priorityNum = 4;
6 o- E7 k7 a& Delse if(temp > 0.5)
$ s! d. ~1 R0 b& HpriorityNum = 3;
# {6 x# C! x+ @ Q7 ~7 D6 f4 welse if(temp > 0.4); n$ k2 k' i% j j" @& P
priorityNum = 2;9 w/ J8 }1 h' E0 u+ }$ ?* L! Q* X
else! l' i: T( m/ Z+ I( |" g: H
priorityNum = 1;; B2 |2 W: Z' f3 k/ \
if(priorityNum[j] < priorityNum); o% ~7 S+ ^, v; p. Y* E$ V
j = i;
; X: g5 Y" V/ a* ?9 U. Q6 j}
]4 Y6 F& C. O2 t6 X7 A6 S6 U- cif((*storage).p[j].askMemory < *spareMemory)
4 w& h2 T, i% W V{ r" Z5 L4 ]4 T8 g
(*memory).p[0].askMemory = (*storage).p[j].askMemory;0 p; a) U R3 X8 F, ^ s& S
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
q8 i: n; W2 [/ A+ _8 t(*memory).p[0].computeNum = (*storage).p[j].computeNum;
3 [; U8 F% O3 g' r. A; J) x w(*memory).p[0].ioNum = (*storage).p[j].ioNum;
1 ?6 r( \/ ?1 O* ^* O* T: o(*memory).p[0].processID = (*storage).p[j].processID;
$ A0 W0 o7 r; F) }6 u5 X(*memory).p[0].flag = (*storage).p[j].flag;8 [) }2 `) e& ^2 ?3 {8 J* S
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
, ~: u( }% o2 F9 o' `(*memory).p[0].computeTime = (*storage).p[j].computeTime;4 T5 `3 {% b$ L( C, C4 \! \: \
(*memory).p[0].runningTime = systemClock;
4 }" Y2 w" H2 R& ^8 t) c" l! N(*memory).p[0].produceTime = (*storage).p[j].produceTime;; ? |: a& d; ]/ Z9 ]& D/ Q B! }
for(i=0; i<(*memory).p[0].ioNum; i++)5 x* J/ ]' r. d1 t! h
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
0 D9 |; m7 {. afor(i=0; i<(*memory).p[0].computeNum; i++)
9 g4 A5 R' L o3 ^& t4 b- @(*memory).p[0].computeClock = (*storage).p[j].computeClock;
- g7 j- L* i5 A- z! {+ |9 v(*memory).proNum=1;
" O) {! ^* t3 n( D2 p*spareMemory = *spareMemory - (*memory).p[j].askMemory;& t) M( ^% x" ] a |0 @+ ]. o
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
H& i1 ] V# ], bMAX_COMING_TIME = (*storage).p[j].comeingTime;
6 @1 o8 P |; _0 g! s}0 R& Y, p- k% V& W6 x
else7 w5 [1 q5 `5 ]
{" I" u0 p; N2 p6 B
printf("A process ask for a memory overed the system capacity\n ");
; H. n: p! r) `9 L* b* ^. `# Eexit(1);
$ b. d* g9 s; p" i" u; r7 h}
% D" d' g* h: r& b1 kreturn 0;
/ q. [9 d/ J! ^% |}1 z6 g3 R: {# }: ]+ m9 s& F2 u( [# `
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)9 Q/ _+ \6 }8 V# r4 t$ n
{1 a* L9 X* M2 i6 R$ @0 G, o T
static int compute=0,waitio=0,change=0;" t0 d D1 K: |$ }9 l' a$ n
static int computeLast=0,waitioLast=0,changeLast=0;
8 f! D+ H/ L9 }7 s% [int i=0;
3 `# I; b* a0 u3 p" Bif(draw==1)' E' V/ F" I8 O) ] l
{
. R8 S/ [1 V0 Z3 m9 ^//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
& {' G7 i+ R2 V' {9 T8 BdrawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
! A: D' \, W% `
% A; ^4 w+ k3 l: E, l5 E4 Y. u- w+ H- H) L6 w
computeLast=compute;
7 |, l7 p: k0 S5 X, o8 u4 GwaitioLast=waitio;
# X9 n& ~% Y Y% @- i8 k0 }; x0 TchangeLast=change;; Y% D! c' g" X1 h1 o" X
}- [4 A0 Y7 z& s. S
if((* memory).p[0].flag==ready)6 H/ f6 K& M: R8 b9 g
(* memory).p[0].flag=computing;5 E& Y/ a* H; q' E# B
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)# y& M; _! j" Q5 |
{8 q; m4 H( l! F6 U6 t
i=(*memory).p[0].computeNum;
8 M$ _! K6 S- vif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
$ W5 T, S; A5 ^' y4 ~3 h{# [% v l, B' r5 ]
(*memory).p[0].flag=IO_waiting;
5 J* a4 Q) v ]0 T: o9 H/ C5 s(*memory).p[0].computeNum--;
* b9 c4 s* I, a" \# D$ Hchange += exchange_IO_Compute;" K6 [" G7 x* q$ e
compute++;" ~6 I! O& K3 O; M8 j9 V' Z. Y
}4 B0 Q6 t- T: b: {; K& X
else
. g, P- R$ L$ x2 L5 ]1 m{
% t# L A; s" {7 p" M2 Bcompute++;
4 C% U0 F- d2 N8 e A# k3 h}
6 w9 r7 f& u# K) Q+ ]; b' o} z1 ~9 V; I& H! Q0 h
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
6 ^+ U4 `3 j( }{
! d1 K5 ^7 n" F: x$ O9 ]$ C, o. L% k/ U; |
i=(*memory).p[0].ioNum;
@% M; E0 Z4 j- \; _. `2 Wif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed4 x) I; @& T! }; O& S4 `
{* u. e" n2 @3 n; H+ J" `
(*memory).p[0].flag=computing;* h" |2 O$ ^2 v+ G" ]
(*memory).p[0].ioNum--;, c0 A$ @) A) [0 K2 Q
change += exchange_IO_Compute; t' @8 K5 ~! H% q) p. f
waitio++;
# b' u9 U9 g2 P}
/ o c$ G" A( Lelse
' u- {( s6 z6 z8 K; Z{
( p4 a% i' R0 Gwaitio++;
" v& w5 b8 f! i}
+ O9 v9 a |8 x; G0 ?7 \- k& i4 M9 d P( q}1 d* T: G9 x( r
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
P8 Y8 W+ \7 s( n L7 P{& M9 }3 _& b" B2 `. b3 d
(* memory).p[0].flag=IO_waiting;" x) T$ n/ l6 E2 Q) j' _
change += exchange_IO_Compute;3 D8 W7 M, H2 |0 z1 x0 B; H8 H
}4 ^( O) i8 S( L; |; ]/ B5 m |
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting): i, G) D4 _* C6 M% I7 m
{
) ~7 s0 ^6 Z) n9 I8 ^3 m7 g(* memory).p[0].flag=computing;
6 p9 D& r3 q8 o! f9 Lchange += exchange_IO_Compute;8 m0 J9 e" k* y+ z
}
8 x4 W A% U2 r+ Pif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成* b6 W% E" {/ u) P& ?8 G
{
* t& X7 R* d5 T. V" y1 X5 W(*save) = (PCI*)malloc(sizeof(PCI));
; t: m! n- v# Y9 Y$ O(*save)->next = NULL;
: @* G# U4 Y% } ?3 Y0 O(*save)->processID = (*memory).p[0].processID;8 T* K$ q0 U; J1 n" [
(*save)->comeingTime = (*memory).p[0].produceTime;; p( q9 {1 p- ]0 d) y: ]" r
(*save)->askMemory = (*memory).p[0].askMemory;9 f! |; `$ T; B& n: h8 O
(*save)->compute = compute;/ V R+ F' a+ L% z4 A) f/ }
(*save)->waitio = waitio;
G+ M7 s8 S' t(*save)->exchange = change;
! i& J e" u# y/ X& B6 S I& t(*save)->completedTime = systemClock;
+ A7 I* u0 T$ P0 v) i(*save)->runningTime = (*memory).p[0].runningTime;
0 |! Q( t% E5 e N2 H3 T2 G*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;
7 {, e8 {8 `4 `compute=waitio=change=0;
3 o, h/ e9 P d) d( ~7 ?: ycomputeLast=waitioLast=changeLast=0;0 v" l1 L6 f) C* |, H6 f
SJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
7 `% V( C9 P" i. F$ h& H- E& uchange += exchange_process;# j3 D; E$ i4 i" l: {. Z0 _# O
return task_completed;, X4 p0 Z! G$ }
}
" l. v: x& p# w% u/ S5 V2 Felse
) z, R& ]9 U! R/ i; L. ^) Y9 z6 Greturn task_not_completed;( w: z: \2 q( R! I8 e% l* d
}( @. i( L9 Q4 r- z8 p
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)' A6 m, s* `4 K6 B0 J
{" o1 @4 q$ F' p1 N K
int i=0,j=0;
! F# @2 U3 y- Q0 u* sfor(i=1; i<(*storage).proNum; i++)
! R/ Z$ P: x& t* |{. B. S' d) J! t" O0 [/ Z/ A
if(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))
: f4 J0 e D; `. _0 |j=i;& \6 r4 m8 k$ O0 P: W+ H1 O
}3 E: @, F% B9 |: l& g& a
if((*storage).p[j].askMemory > *spareMemory)/ l/ J, _& J& u' z3 I/ E
{2 u) r$ g" d; m- @7 j
printf("The memory asked is overflowed than the system memory.\n");% @3 c' W1 b- L$ u! D6 o
exit(0);
3 g+ [1 K7 q' M6 F) Y}4 b2 A7 M/ U( [' |5 j* Z
else
: s& g# B% h0 G# R8 r6 ^{
e2 d, w- @1 @+ j- F* {0 j8 E(*memory).p[0].askMemory = (*storage).p[j].askMemory;
$ U6 O) f5 b9 h* J! v(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
& W3 K' B: ?' n J! m- B(*memory).p[0].computeNum = (*storage).p[j].computeNum;
2 ~9 n5 h. `# i% E& ^(*memory).p[0].ioNum = (*storage).p[j].ioNum;. T2 K9 o5 M6 B+ A. @1 @+ E
(*memory).p[0].processID = (*storage).p[j].processID;; }: D( y! s, j
(*memory).p[0].flag = (*storage).p[j].flag;$ w) P% ` a1 \' o" d
(*memory).p[0].ioTime = (*storage).p[j].ioTime;2 V; n* }5 x# v- u4 [/ v
(*memory).p[0].computeTime = (*storage).p[j].computeTime;. K" U) P1 A: I
(*memory).p[0].runningTime = systemClock;
; g, r6 m* P: _ R(*memory).p[0].produceTime = (*storage).p[j].produceTime; @7 O8 ^8 A. E7 o8 |) |: l
for(i=0; i<(*memory).p[0].ioNum; i++)
* t6 m1 q4 J! n; K, E, M(*memory).p[0].ioClock = (*storage).p[j].ioClock;
) u) U. F* ]" k" P* O7 [ K# Pfor(i=0; i<(*memory).p[0].computeNum; i++)
: o9 X" b$ N* i8 V(*memory).p[0].computeClock = (*storage).p[j].computeClock;) x- K. o4 C0 V1 a2 _
(*memory).proNum=1;. t9 M2 b/ S0 B2 @" D Y) M& S
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
7 R v# ]3 N- eproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程5 `$ m: {/ @6 d) o$ q6 s/ O
MAX_COMING_TIME = (*storage).p[j].comeingTime;
4 C, }0 C9 `9 h7 Q6 d: j' Q, J}
) @$ ^7 A0 {+ vreturn 0;7 ?, A) n; r+ v: I/ w" O: U
}
% X6 E( Z: L4 j; Vint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)$ }2 _: r) U: i l+ K! _
{
9 m+ B4 z# A2 zstatic int compute=0,waitio=0,change=0,clockSegment=100,poi=0;
Q# G% J1 T1 A/ u. T, t$ [5 j6 _static int computeLast=0,waitioLast=0,changeLast=0;" O2 [; o! C& a" I) u# E
int i=0,j=0,k=0;5 U5 ?1 M v2 j4 Q9 X
if((*memory).proNum<=0)
; W: a/ Q) p* [- M* g' @! j, RTimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);- c& o/ H4 J" j9 d
if(draw==1)
9 x: L* R5 P$ }) |+ t5 P{$ s- V4 p5 R! T v6 e/ a
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
4 A9 n* ^* m; }! pdrawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
) e# n( z; p& ^. w9 @9 t6 Z+ ~. r* @' P
8 H1 ]) k: |2 W: d2 q
computeLast=compute;
2 o# @8 @! V6 Q+ ]8 y, C& h, {waitioLast=waitio; p' @! ]+ {3 h1 ?! l, a4 W
changeLast=change; i0 ^) \* ^4 \
}
: Z+ ~. a/ V4 ?4 t o% d) d; z( ~& ^if(poi>=(* memory).proNum)' v( Q7 E& ~9 w. n0 W; Z! N' F8 R2 I: i
poi = 0;8 e2 s+ b6 l2 @' c) t1 H# W3 X% G
if((* memory).p[poi].flag==ready)9 n1 k8 y# y% C# b
(* memory).p[poi].flag=computing;+ ~6 \; t" }- m! g. u, ^
if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing): I4 |0 ~( b- W6 ~( E* @% |
{
5 q8 d& N* b' [# r5 ]8 K9 hi=(*memory).p[poi].computeNum;3 q# h" U$ t6 P- v2 _4 ^' _* k# O
if(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed
2 |8 p$ P+ P0 C. }6 H" j- \) `{1 N1 r0 f3 _4 \+ ^& U0 ~' P d3 c6 ?
(*memory).p[poi].flag=IO_waiting;
$ L7 T# O4 y$ s) n& E+ Y5 s# ~+ k, W(*memory).p[poi].computeNum--;. _5 t6 ^4 c1 |1 A* \; T+ n
change += exchange_IO_Compute;+ z- g) b6 }( U( W5 d
compute++;
% h& }/ R$ }* u9 W, G: ]: S. S& a% I}# _5 X7 n6 n9 ^ t/ ~
else
) D ^: h8 T3 M+ n' y{
: b b, _8 l' o" M" C8 ecompute++;
) z# r. i! Y+ h* y}
, A" M5 l5 B, `3 s}. \' n% x5 {+ y
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)
- H6 x3 N) a; A+ H% o4 d0 a) M{. J2 ^ o' ~5 M7 o4 ]
} \1 y! A8 s7 a, y
i=(*memory).p[poi].ioNum;
6 h+ l, t9 o8 m) Kif(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
+ T% ~8 Z3 J# h9 A: q{8 g! e& k7 ]4 B- c8 n
(*memory).p[poi].flag=computing;
6 j, X! D6 H; I(*memory).p[poi].ioNum--;/ O) w \; J% @1 C
change += exchange_IO_Compute;
) b- g* f" t5 b' ~* L' a) ^waitio++;8 X2 J& Q4 X. |# E6 ]" _% u! J; S+ N
}
* M! S; `1 ^+ u# d) lelse
, V: W$ b& h& K' \, p; T& b; J{
2 H4 @# {9 F: Z- O5 x' d# Hwaitio++;
! w+ v( X* m( B8 P; g}
W6 j$ Q" b7 N& \}
! M F. [- G1 ^else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing)
d& @: k0 G) @{
+ y% i7 {. m: z# f+ v7 I7 @(* memory).p[poi].flag=IO_waiting;
I) `, _1 \( j% b% Z! ~* o4 e% Lchange += exchange_IO_Compute;
3 V7 b, w8 J, n1 c% T}
* }4 G$ v+ a- S- V3 f8 `! \0 kelse if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)6 S: O5 d8 k; `7 {" Q* [: e
{$ e0 f% s, z. {2 z5 o+ y% b4 p% W
(* memory).p[poi].flag=computing;
3 J5 R6 h" F& f8 F' achange += exchange_IO_Compute;. a5 l6 @- z- J) {
}
; P) W: Z5 Z. U* [( z' f: S# H, _/ M& Pfor(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进
- K& L0 _% m9 Q{) ]- ~& x6 ^- ~& i7 n$ q E
if(i!=poi && (*memory).p.flag==IO_waiting)8 b w" _ n8 j
{8 w) z5 G# q' u1 N0 n( _* B
j=(*memory).p.ioNum;
( |; e+ |) L4 N/ L+ z# rif(j>0)
' J" @# j" f4 [! I: f; N{+ ^/ w& u0 l ^/ w4 q
if(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed
# X$ {* ]! L5 Z, N: M6 j{# q3 X9 y7 c/ B' l( [2 d1 j9 G
(*memory).p.flag=computing;, x3 N( D; R1 W# ^) ?* \
(*memory).p.ioNum--;
" o4 Y: |- _# Achange += exchange_IO_Compute;' [' U+ T8 ^& m, p# h) e" ~0 ~5 X
}
) j A" o' s1 P) |1 u5 {}
7 k5 Z8 M: Y: B) V! s}) E8 b) e1 N, n k- R9 L
}$ D6 [8 u1 X( F* d
for(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程+ P" P* v3 z9 L$ s& X" M/ a1 D
{* D! u1 w9 @3 a* ]5 u8 I/ [
if((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed# e/ I9 f) s" X9 k
{( w% P: U4 V' J, S* E9 l
(*save) = (PCI*)malloc(sizeof(PCI));
. ?( M7 v* b+ @, N; |(*save)->next = NULL;
& ?! _* J7 g( M, r0 t& a! Q (*save)->processID = (*memory).p.processID;0 f7 S7 _ N$ N* B) t
(*save)->comeingTime = (*memory).p.produceTime;
% M7 |0 m8 r' m(*save)->askMemory = (*memory).p.askMemory;2 f# O' a! C4 ?' s8 v' x" w7 \# s1 J
(*save)->compute = compute;
5 V/ E- j% `: b6 L. r3 p; t(*save)->waitio = waitio;& Q/ I" `8 i+ Y2 m! ~8 u. O7 N. D
(*save)->exchange = change;; l. E1 f, ~5 Z( d1 L! j' G% z' S
(*save)->completedTime = systemClock-(*save)->comeingTime;
8 B4 J* K3 z1 g! b5 p( I(*save)->runningTime = (*memory).p.runningTime;4 L# ^5 n; D/ \' R
(*save)->completedTime = systemClock;
& `1 E& S" |/ w. A*spareMemory = *spareMemory + (*memory).p.askMemory;8 ~) I8 L1 x) V
compute=waitio=change=0;: ~; ^/ }$ J9 u+ j: |2 B7 w. C8 [
computeLast=waitioLast=changeLast=0;
/ \/ u b/ _2 p s5 e7 |2 g+ k% Rif(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入1 w$ V' h, C% l9 R" ?; F/ \
{
& m/ A" a% p( Z! b% y5 dif(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程
, ]' K) @$ Z' G4 E! F$ d{/ P g. e1 {8 o3 s) k
poi++;
$ _; l1 u3 Q) x clockSegment=2000;$ a! j q* ]) x6 ?; w. l
}
3 q' }+ U7 |, C& _}
# c4 M: i1 h ?4 ^+ velse //没有足够内存调入新进程 d9 l# m8 m% Y
{
3 S- P1 _8 {% P e8 c6 qif(i < (*memory).proNum-1)( [+ H3 |( {! R# n+ O1 o9 H
{
, s: r+ I' T" j ~. ]for(j=i; j+1<(*memory).proNum; j++)
2 C) b4 A. v: `8 v7 |" k: F{ D4 q4 n; h: C2 G
(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;. c& z8 f4 w! g2 W. t8 M9 g
(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;
' {0 U6 S$ q; f(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;
, Z; ~% u- }) @(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;- ]/ N+ p- K; Y
(*memory).p[j].processID = (*memory).p[j+1].processID;/ l! V5 Z/ a* D! O9 s! L# I
(*memory).p[j].flag = (*memory).p[j+1].flag;
* G8 O* A5 M. m6 R' u0 D, \* P(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;6 Z# G! J4 u3 ?3 G) g) e
(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;
# _ @0 d% m6 a4 J+ b9 W1 H(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;
9 H8 r! B' C9 r; G0 w(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;
5 Y2 l; B& l, h5 W1 k* w(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;
; Q+ h1 Q: E/ s4 Jfor(k=0; k<(*memory).p[j].computeNum; k++)
' h. W$ G: \( R d% K, f(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];
& x. @2 z/ M. z/ |, qfor(k=0; k<(*memory).p[j].ioNum; k++); O; O: ]1 Q$ x1 }
(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];6 R& |* W! C S0 x; M6 n' |
}$ }' i1 ? r& k1 Q1 I8 ^) p
if(i<poi)3 L% G* c8 f6 k* `5 \
poi--;! ]/ k) }8 C# J w* R
else if(i==poi)
, _( r8 A& S P( a5 L$ cclockSegment=2000;
5 k/ ^% n6 P# I}8 G8 P: H0 Z9 h5 ^, C2 h
i--;
7 A) y# M5 Q. l( b. V3 S+ {(*memory).proNum--;
. j% p6 s N: U1 \( B# s}' ?' ~3 {+ y5 p& _* f1 u& |" ?
return task_completed; t- F: T6 h8 w) T% Y
}
/ w5 j" A4 O3 ?}9 }& K6 v$ \, d0 M
--clockSegment;
. v' a1 _, l1 @ Z3 ~, Qif(clockSegment<=0)+ n1 T' X7 X% H$ V
{
0 m5 ~: h& M2 X2 R% lpoi=poi+1;
! X, H) x% b% d) Dif(poi>=(*memory).proNum)# P+ b5 Q3 J, ?- }
poi=0;. |) J" n& i7 a% I5 |
clockSegment=100;
6 i2 M4 `4 g) o# @/ l: A}
5 G1 q7 e: l. |1 @% Dreturn task_not_completed;
3 ^1 _! H. `( d2 [0 c}
7 t0 v% r# h0 H1 J @0 Lint TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)
U d$ v5 o+ H' Y3 D/ N9 e! M{* p# h+ S# k M- r. D' y
int i=0,j=0,k=0,flag=0,translation=0;
. v. U# m5 k4 I) B6 M# ifor(i=0; i<(*storage).proNum; i++)
+ o( N( |+ |# q% [( `{" O* c7 S8 Z+ A! ~. e: l* o4 l
if((*storage).p.comeingTime>MAX_COMING_TIME)6 v, m" l0 f) p1 @' N6 m
MAX_COMING_TIME = (*storage).p.comeingTime;
: S: e4 \" u8 n}
. b& v7 c" ?1 w+ V4 Hif(pos>=0)8 Y! J, Y$ h. a" y. e) \
{
$ ~# }8 h; u! `for(i=0; i<(*storage).proNum; i++)2 O, n/ G! W+ }6 e6 v5 V |
{& P- s4 N* ?" L7 J6 i
if((*storage).p.askMemory <= *spareMemory)+ {5 h5 w' l, Z
{4 o$ v/ L) ]) U+ H
j=pos;4 {6 T8 N* Z4 |
(*memory).p[j].askMemory = (*storage).p.askMemory;/ G- n9 R1 L+ @+ V
(*memory).p[j].comeingTime = (*storage).p.comeingTime;
$ K. J5 @3 \/ v$ P; Y2 L/ V(*memory).p[j].computeNum = (*storage).p.computeNum;7 o" `9 p# R3 s1 F
(*memory).p[j].ioNum = (*storage).p.ioNum;
7 D/ @9 @; t$ N2 t/ y- i(*memory).p[j].processID = (*storage).p.processID;: Q- p9 }+ U6 Q8 K* y' O3 Q( C
(*memory).p[j].flag = (*storage).p.flag;
8 _2 P( _ b M7 R* p% [+ I0 i(*memory).p[j].ioTime = (*storage).p.ioTime;9 u! D, s, G. ?7 W& P8 k8 ^
(*memory).p[j].computeTime = (*storage).p.computeTime;, u9 ~* L/ k) h1 N9 \6 n
(*memory).p[j].runningTime = systemClock;
' v4 a8 g$ M" [(*memory).p[j].produceTime = (*storage).p.produceTime;* c* N8 }* |2 K3 Z0 I: A
for(k=0; k<(*memory).p[j].ioNum; k++)4 s7 p0 W* F# v0 }! V* j0 L
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
8 [; p" S( N4 g" F2 T/ Jfor(k=0; k<(*memory).p[j].computeNum; k++)
/ W. b7 z0 q) C- B7 l# X% [" f(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
; l1 d% z* c3 A4 M8 p*spareMemory = *spareMemory - (*memory).p[j].askMemory;4 |: f2 O/ x; D( [- ~/ T
produce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程6 p4 I$ y4 Z( w3 m) \
MAX_COMING_TIME = (*storage).p.comeingTime;
6 N( V: [* p9 A; ~translation=1;
7 T+ D. F" K' i- i u# C2 Zbreak;" D: A% B# d+ V8 w( M9 [5 m. t
}
% [( N. {& _+ _; v5 ]' x* {}# y9 t2 I, Y7 n5 R# L, \
}
6 h/ F% K* J" [! y4 \7 D3 x" Jelse' j( O5 g6 X, f4 r9 T! G9 f# i
{& P U* ^0 y+ W ]6 f2 @7 v# @1 B' }
while(1)- ?/ j. Y. v8 M. _5 A
{
$ I" V2 o+ x- A/ p A1 B$ ^6 k: o8 ~flag=0;
! G( V2 Y& e; H1 v2 W) t) G! cfor(i=0; i<(*storage).proNum; i++). K. h! [ c" R9 J% a: g
{. k" i4 D# c, Y2 y/ z2 H
if((*storage).p.askMemory <= *spareMemory)( W3 E7 [% e. \5 b) [1 M0 `& V2 u
{
# g a7 i1 m, W$ C$ Y0 R3 uj=(*memory).proNum;
* z2 _" t$ e3 g! ~( g(*memory).p[j].askMemory = (*storage).p.askMemory;
! c+ p W9 i( i# g0 k% G; h(*memory).p[j].comeingTime = (*storage).p.comeingTime;
2 i: s+ N9 f, {8 q( |(*memory).p[j].computeNum = (*storage).p.computeNum;8 q! C: \& `9 E9 d3 s8 i6 ? m. l
(*memory).p[j].ioNum = (*storage).p.ioNum;. p8 W* u6 P- S* K% e( C
(*memory).p[j].processID = (*storage).p.processID;! I* m$ I+ `* p& K' n6 `& B, \
(*memory).p[j].flag = (*storage).p.flag;- s, R1 c2 k4 v$ g3 a* H# g, e Y
(*memory).p[j].ioTime = (*storage).p.ioTime;
; A3 E3 J7 l' U6 z(*memory).p[j].computeTime = (*storage).p.computeTime;+ C, E' a, r& s& G2 O' h' D$ z
(*memory).p[j].runningTime = systemClock;
# L0 p3 e N: y9 x1 g. H(*memory).p[j].produceTime = (*storage).p.produceTime;! N" q/ Q: q: Q
for(k=0; k<(*memory).p[j].ioNum; k++)
0 O8 w' O: b3 q3 y; Y5 Q3 B% J; L" F(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k]; X4 V$ I5 q" [+ V* b- B
for(k=0; k<(*memory).p[j].computeNum; k++)
, R& n/ i+ w0 `( O8 I(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];4 v$ H9 s5 G W2 A
(*memory).proNum++;* X/ k* k3 m. ^2 y
*spareMemory = *spareMemory - (*memory).p[j].askMemory;3 M6 s% Y$ I5 K% ]8 H: y+ ~
produce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程& ]7 R4 k3 i7 H4 N8 z$ l% r8 J
MAX_COMING_TIME = (*storage).p.comeingTime;: r% a [; ^- B" s- `; F
flag=1;
& K- M _0 c4 k) ctranslation=1;2 s8 r; [& ~" R9 S4 Z
}. Y; j$ _) X! Y7 J6 W
}0 {. l6 p$ e7 M5 b" S% G3 [
if(flag == 0): T6 a9 z0 U+ G, ?" f8 J
break;8 w0 a, Y2 T* L: x
}
6 q6 H, ]6 U; W3 L0 U0 @/ ^. y}
- p9 Z% ?/ R, d) y% F+ qreturn translation;
" H/ |# h5 h/ \0 E+ b}9 r, g6 V% G d8 A
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)
# o# I' {! D3 o5 c7 S& n{& I2 j4 {% }( ?0 I: @
static int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;6 }, W4 a8 X! |, L( A
static int computeLast=0,waitioLast=0,changeLast=0;" ?4 X# u N$ q8 ~4 z0 y; U
int i=0;# Q: j8 F f: ]
if(draw==1)% o4 k, g z; q- g4 Y
{
9 R& M. c1 x# J3 B, g6 z//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);6 H6 {5 @' e$ ^1 P, U8 O
drawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);$ x, `) m+ z8 o3 G* N
9 G' V8 D% ~2 z1 t6 K9 X7 l8 n! f$ Y
: H/ @0 V3 F; [computeLast=compute;
2 x3 c# w4 [2 o: y" SwaitioLast=waitio;
) e, _- m3 l" F8 \* l7 zchangeLast=change;8 V( X, [5 X' J, S2 [. E R
}
8 I2 u8 }8 ]7 q0 s F5 H; bif(flag==1)
& i( X- G6 k" p& F* u* H{$ r0 i7 ?6 U r6 u5 e6 O
if((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed& u9 d0 i$ r9 L) I$ ~% Z
{+ z# r T ]' b2 E( R# O
if(flagiocpt==0) // implement compute9 |( M1 `' q1 k1 b; V: g {
{; g/ A3 v' t$ C( i* M7 o, r
i=(*memory).p[0].computeNum;
; }. @' y: M5 Z$ S8 B) @ ?if(i>0 && (*memory).p[0].computeClock[i-1]>0)
0 u! d4 ?+ x9 q9 k, {6 S7 ?' z' f{2 g$ G; I6 N& Z8 V$ d$ U
if(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed; w! E! Y, ^3 b O( D9 ^: a
{
. B; \' \- U* x: E. t& W1 O, gflagiocpt = 1;0 {- r8 B1 w+ |- u7 x7 i0 ^9 J, m
(*memory).p[0].computeNum--;
/ @9 W, V9 K, N0 g+ g! s% Dchange += exchange_IO_Compute;/ ?. \, w5 C% G5 p
compute++;" ?* l- P$ c5 h8 S5 |$ ]+ R7 `
}
0 _2 A7 |8 Q+ r( m+ Velse
$ _) \* K. n, a4 Vcompute++;: T* j4 x6 f( t" y4 s" p- t
$ z5 b5 _) d8 |! R8 u} n: l) R$ o7 B
else9 m& |! d* G+ I, k0 Z& x; D9 l b3 D
flagiocpt = 1;8 W8 n( j; I$ W+ H
}+ r1 Q- M2 j/ @3 t
else //wait io
1 L: y Z& i( a# v# J1 \{
! X) V; Q9 Q" V2 D9 _1 Yi=(*memory).p[0].ioNum;
5 u- U% I( P% H, u2 |/ J/ I; ^+ ]8 v4 mif(i>0 && (*memory).p[0].ioClock[i-1]>0)
& \8 r" \' }+ Z) N4 S3 J& j/ _{
# p# r1 r% w; wif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
. u6 C: W' a( D1 h& `{
0 a3 S1 W2 ?: E9 N: ~. L9 oflagiocpt = 0;
& r$ o5 Y* T/ m0 L(*memory).p[0].ioNum--;
8 s/ z3 I( z" \change += exchange_IO_Compute;% h% D) H) r" q+ R: C _1 a
waitio++;4 z* g7 U- l8 B( V0 i
}
0 i @7 h. c) H& T- qelse
) t+ V- N; H+ f6 Q' x9 u- J. z2 |0 Fwaitio++;2 d! w& H) q& p x- K: i9 [2 E7 X
7 m( z* ?. Q* J/ O! b}7 y5 \2 J* T5 e+ y0 ]4 C& @
else
0 B9 R! J6 m! p: K: s7 Xflagiocpt = 0;4 Y% w# [# b& H7 Z- d# o. q
}7 R: M* n9 A M. }7 l
}
" N3 v' q6 @: y* w5 felse //task is completed
8 u2 F$ S* ~* P5 J2 n{
* _ S* f! p* {# Z- y: L(*save) = (PCI*)malloc(sizeof(PCI));: J8 W d8 X0 _
(*save)->next = NULL;3 J0 P* t! v. h; S1 `8 s" |. n
(*save)->processID = (*memory).p[0].processID;+ | M. L6 w; J% a% n" t. t! L
(*save)->comeingTime = (*memory).p[0].produceTime;6 y) G9 _' W7 }7 `% v i
(*save)->askMemory = (*memory).p[0].askMemory;! |( Q4 D! d9 f3 J8 e6 b
(*save)->compute = compute;( [: E' y% x+ q( K
(*save)->waitio = waitio;( o5 ^1 X8 f9 i/ y3 m/ J8 F+ o$ a( \
(*save)->exchange = change;5 N' ^( c! G( O
(*save)->completedTime = systemClock-(*save)->comeingTime;+ g" E% X- Q2 d, ?, m
(*save)->runningTime = (*memory).p[0].runningTime;3 O, d" {3 Q; M d! |6 O
(*save)->completedTime = systemClock;
% m) Z( i5 l3 ~//*spareMemory = MAX_MEMORY;
: q" K" ?5 Q) q7 E5 m; Q0 xfree((*memory).p[0].ioClock);
2 h& x% O3 F' B. Efree((*memory).p[0].computeClock);) e2 `9 T) X# M- i
free((*memory).p);$ w: \9 s5 Z" K p! }# d
flag=0;
) \1 w1 p" p$ ~5 e5 J: w" ccompute=waitio=change=0;
6 I' b- e+ s/ ?9 W J0 b1 Q. o3 ecomputeLast=waitioLast=changeLast=0;* g2 Z( o4 k5 s- q2 F
return task_completed;
) v1 ~( x7 ^; P0 I}! `. o1 r5 X$ ~0 C8 Q* B$ r- r% m
}6 W: H* ~0 p2 F9 @6 K5 b
else
, O6 A8 h9 k d* G{
. G7 n) f6 N# W0 J: _FIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));2 M! h! T$ z6 O, g1 q4 o
change += exchange_process;' d2 P% m1 A: J" U
//*spareMemory -= (*memory).p[0].askMemory;; Z) B7 h. J' _/ Y
flag=1;
* r/ O3 d* H9 t: D( J+ f: B8 h//showProcessInf(*memory);
# K0 d" r" C- c& k+ x1 ?% Ereturn task_not_completed;5 V1 I# t% F' T: b
}/ n6 B, {' Q8 w2 W, H
return task_not_completed;
0 {& P" V( I$ B% t N. J1 M}$ b. N l9 @7 _! Q
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)9 f+ V l6 `5 q+ G: h0 K! C
{" [# ^3 k/ J6 x) \2 e! v2 e
int i=0,j=0,k=0;9 c) J! g/ n5 }2 P2 k
MAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;. q& U' v& Y" u& G& u
(*memory).p = (process*)malloc(initProcessNum*sizeof(process));
9 m% Z& k2 T7 S" R0 qmemory->proNum = 1;
v$ T2 ]7 ]" J+ m+ ?for(i=0; i<initProcessNum; i++)% y8 }$ k' @% I* l1 w
{
/ q# q$ A& v0 ]1 Q3 R0 \7 hif((*storage).p.askMemory <= *spareMemory)
6 E4 f1 ]. u# O% ~0 l8 L# ~{' n5 ]6 O# J+ A$ b
(*memory).p[0].askMemory = (*storage).p.askMemory;
{: I$ d8 N# z% _' t(*memory).p[0].comeingTime = (*storage).p.comeingTime;, j3 L0 v4 f: ^5 Q. ^& ]1 e3 Z
(*memory).p[0].computeNum = (*storage).p.computeNum;
h( f+ {' S* F; v(*memory).p[0].ioNum = (*storage).p.ioNum;2 O# V8 G" G1 [) \4 J% ?
(*memory).p[0].processID = (*storage).p.processID;
! T: j& [5 `) [(*memory).p[0].flag = (*storage).p.flag;' a: \$ t( a+ L# _
(*memory).p[0].ioTime = (*storage).p.ioTime;+ {2 i) x" W! E/ p% q a) R
(*memory).p[0].computeTime = (*storage).p.computeTime;
0 a7 ^. t# L- g' z$ _3 S(*memory).p[0].produceTime = (*storage).p.produceTime;
/ p+ I, ~; U8 r(*memory).p[0].runningTime = systemClock;# ?/ ]' k+ d) @3 u
(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));
& S/ R4 `' D% c o" E(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));( E4 H7 m! d! G
for(k=0; k<(*memory).p[0].ioNum; k++)
; f( u! g3 q3 b(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];4 a9 ~* d% Y, S9 K0 Z# [
for(k=0; k<(*memory).p[0].computeNum; k++) Q( {$ o5 v2 P5 e- n1 P+ S- Z
(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];3 }5 R+ R# D6 l1 ~% R7 o3 J
break;+ M+ P) C! o* G
}
, g* q6 C$ d* E# q}6 H1 [* N* ~+ W& N1 K
if(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入
; z: c& l A% r5 `/ [5 q6 r{( R/ T& o4 I3 Q) Z
produce_one_task(storage,i,ID_FIFO++);
; U; Y( p; j4 K' } gMAX_COMING_TIME = (*storage).p.comeingTime;9 ] b% c5 K8 K" z; j
sort_by_comingtime(storage,i);
1 L8 S' n- q5 X I. @}
" [1 z0 K4 r% b6 i& L$ E; nreturn 0;( F' L; G! ^. E) `5 U. d. ^
}
; s4 ^$ \+ K, X! n xint sort_by_comingtime(processPool * p,int pos)
3 p, F5 q! K0 t* h( T( O! `) N{1 K' S* Y X2 \% S t" A* d5 C
int i=0,j=0;
' ?( I1 M+ C: I# Sprocess temp;) {0 u1 ~- M/ g& y# J+ d* q% |
if(pos<0)
. o' C ^: j7 j/ E4 b{1 N/ }, {7 A A
for(i=0; i<initProcessNum; i++)7 R8 K0 J* w" ]; w, C" e$ J
for(j=0; j+1<initProcessNum-i; j++)
& @1 d; Y" ~# @' `2 G{
; K( o o7 m; Qif((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)
1 @" c K1 q/ }- v' s) D) C# ~{
/ h9 O% U6 T4 p" z) Mtemp = (*p).p[j];
" ]( N# `& t# ]7 d$ R3 j. [& T$ g1 J(*p).p[j] = (*p).p[j+1];: z z8 ^4 N, \
(*p).p[j+1] = temp;: m3 m, H [1 \1 C
}
: B% Y2 g( H. |/ _0 ?}
/ S( `5 U4 @, J) Y; B$ R}
y* b' F) ~* c9 |/ N& { B! U. Celse if(pos<initProcessNum)
' o# _# ?5 h" j5 P% x h) X{
7 T9 M0 D, n5 cfor(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)+ g( i3 V3 t* D5 L2 Q
{- E' y# L. q1 v# c7 T8 F ~
temp = (*p).p;2 \; g4 P1 Q6 n
(*p).p = (*p).p[i+1];' q( x6 i# }5 o) K; f* h
(*p).p[i+1] = temp;+ Z9 Y( w* r/ Q6 j7 t7 W
}
5 \! P0 O& R- S& Ufor(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)# Y7 d/ c. f, ?
{% \9 t% k( v2 i& ~
temp = (*p).p[i-1];
1 w' w/ f1 m" h9 ]: N(*p).p[i-1] = (*p).p;
1 G7 S5 k( B, B. l$ B(*p).p = temp;7 X" @( g4 w& G4 d: z* F
}
4 t9 F* {4 { R/ S}
$ ~% I0 r8 w5 p8 X4 Lelse2 F0 n; T* E, l; |# x! C# D0 G
printf("position eror\n");4 ?& _9 ^) P T
return 0;+ E$ E! r9 v# K, X. o; i* S. t
}
5 F$ _0 @* J9 o/ Qint InitPool(processPool * p)5 W7 N7 g7 }$ q& ~5 A, `
{" U+ e5 a" T; R" i) k$ f( j
int i=0;
1 Q9 [! B3 X2 J2 E(*p).proNum = initProcessNum;. ^! R( A& l; Y
(*p).p = (process*)malloc(initProcessNum*sizeof(process));
" _& V) j0 X; Wfor(i=0; i<initProcessNum; i++) //init process information7 M& Z, N) u! X% c" N
{6 ^2 Z1 V" t& R' j4 V c$ o
(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));
+ G) O" f/ e9 S* i$ W, O" i- b(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));# e' R$ I* q! T R) |6 l% u
produce_one_task(&(*p),i,ID_FIFO++);
. }+ G5 A5 @: O+ T( y( ^}9 f, _- G& J5 I E6 R1 e% I
return 0;
3 s# E [6 P$ x) ^! w}5 h: L* n6 U, _7 b/ ^
int produce_one_task(processPool * p,int i,int id)) ~/ s* _3 Q# w+ D
{
4 x4 t- e+ i+ ?int time=MAX_COMING_TIME,j=0,totallTime=0;9 c/ U. T* [. X% E6 }
(*p).p.processID = initProcessID+id; % V6 s7 M9 S8 z. _
(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);
6 a$ u9 A# s0 A+ c2 s(*p).p.produceTime = systemClock;. S) ~2 [# L4 @9 R2 m# o% U) s/ m
(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;
) H" N( \. y% |4 F& F(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6;" }! f; p7 Z7 t
totallTime = (*p).p.computeNum + (*p).p.ioNum;& v4 F" k( y+ j5 p' {3 A" O1 c
(*p).p.computeTime=0;
" c' j% `8 a( \ O# o/ nfor(j=0; j<(*p).p.computeNum; j++)4 A& {2 u% X# p
{
4 Q- s8 |( }! j4 ^' v(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;. u+ M6 x3 P$ J: H
(*p).p.computeTime += (*p).p.computeClock[j];
/ r4 B3 G# a6 ] }}
! v" m$ q; {+ u# N0 Y$ ^(*p).p.ioTime=0;' S Z/ D" e1 a( p
for(j=0; j<(*p).p.ioNum; j++) |
|