- 在线时间
- 1630 小时
- 最后登录
- 2024-1-29
- 注册时间
- 2017-5-16
- 听众数
- 82
- 收听数
- 1
- 能力
- 120 分
- 体力
- 565664 点
- 威望
- 12 点
- 阅读权限
- 255
- 积分
- 174922
- 相册
- 1
- 日志
- 0
- 记录
- 0
- 帖子
- 5313
- 主题
- 5273
- 精华
- 3
- 分享
- 0
- 好友
- 163
TA的每日心情 | 开心 2021-8-11 17:59 |
|---|
签到天数: 17 天 [LV.4]偶尔看看III 网络挑战赛参赛者 网络挑战赛参赛者 - 自我介绍
- 本人女,毕业于内蒙古科技大学,担任文职专业,毕业专业英语。
 群组: 2018美赛大象算法课程 群组: 2018美赛护航培训课程 群组: 2019年 数学中国站长建 群组: 2019年数据分析师课程 群组: 2018年大象老师国赛优 |
/ r( h& Z' o0 E; G4 {3 q经典任务调度算法的模拟程序9 s: e$ ?- p4 F; Z" z% _& R& M" w
本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。! x: \$ j F5 j
0 Q& D4 q. M0 f0 h) w$ ^
编程平台:VC6.0+EasyX图形库环境。5 G+ }4 R" `/ u4 _! W1 f
3 m4 B% q# t& P1 X( Z+ R' J
以下截取部分程序运行图::6 |* @& \, i: B' l4 u6 @% n* k
: @0 B0 D$ ?1 A( V! S
源代码:
H# Z# W: N7 k! ?' m- t
: P4 z- ~& E1 a% k: U#include<stdio.h>4 G9 K. x+ O# _: W, I n/ |7 _! Q
#include<stdlib.h>4 M4 g: w) y0 M5 T* h4 L$ X
#include<easyx.h>9 A8 T2 Y: i5 o
#include<time.h>5 ]' ^. @7 B: R0 R) @2 S
#include<conio.h>
6 V6 {) J( B/ d" ]) s) x9 ^) L#include<graphics.h>
) W, Y: m5 p7 D+ P) U#define initProcessNum 10, y& W% T' y0 n# x# e, N
#define initProcessID 1000
8 {1 m% w4 h3 T+ b#define MAXProcessRunTime 10000
( _9 {" D2 g1 R! R0 s8 B#define MAX_MEMORY 4000$ ^, ]( b$ E7 L# d6 b. q) \. w: x: Y
#define exchange_IO_Compute 10/ \& C2 s* J* Y. D! ]( G5 K# J$ h& W
#define exchange_process 255 q& ]" M8 [8 P/ F2 Y
#define task_completed 1* `/ p/ [$ H1 h! s
#define task_not_completed 0
' U* N0 V( ]4 j+ r! d4 q#define initclocknum 100
, s9 j; }6 P1 D% V) wenum condition
& Q( R: \# g9 Q/ k' t5 Q) w$ c' k{
! W& e+ A0 `# }5 F) Zdead,computing,IO_waiting,ready
& ?1 B3 T a- H& m};
5 G) g0 {. U2 e* Dstruct process% f+ x# {$ C2 ^& ~4 V+ r1 d) ]
{5 o6 c: i3 ^% A2 Y2 s7 {6 S
int processID;6 [- o' Z( `4 u' `6 \: m7 g$ v
int comeingTime;4 V, N, O; N/ T, d {5 m
int ioNum;+ a- D( ?- w! ]. l; `, h7 T
int computeNum;. x7 T i" k% G- `
int * ioClock;
6 s; B+ y% F* x( f, T6 C6 L9 s; {int * computeClock;
7 S5 c+ ^5 i( a6 S8 n2 u# yint ioTime;8 @! k- L2 v+ v/ @! B% s! j
int computeTime;
# i3 p5 T! P5 E( M3 Zint askMemory; E. }- _$ Y# C1 \4 w5 h
condition flag;
, m4 I/ ~: S( p7 J# P. Z! oint produceTime; //生成时间,以下三个数据成员用以计算相关性能- i6 V1 x' N0 j$ Y a
int runningTime; //第一次占用CPU的时间: W3 C$ P# u8 ?- A
int completedTime; //进程完成时的时间
# D- Y2 S( Z! C+ Q5 E% E};+ A3 |) s% Q2 W
typedef struct processCmpletedInfo //保存完成一个作业的相关信息
* k0 H, b3 B7 i{
* x* A; a* j) J) e0 s- Uint processID,comeingTime,askMemory;
m5 ^- g0 S; r: n2 L3 K7 J3 f, aint compute,waitio,exchange,completedTime,runningTime;9 `! H! H: @" _! u8 P" q
processCmpletedInfo * next;, R9 g' c+ [# a/ ^4 j! n2 i
}PCI;
! p1 m. ^0 |" e4 istruct processPool
0 [( d5 y' |- H* Z9 V/ ~9 x{
+ w) j- e L- I Z) u' r5 Qprocess * p;9 N, o8 _3 T& n4 C* [( T' k
int proNum;# C' Q- @: n, Z/ Z5 |7 n7 _
};! D4 t8 s2 M' ]& g5 g
int MAX_COMING_TIME=0,ID_FIFO=0,systemClock=0,FLAG_FIFO=0,FLAG_TT=0,FLAG_PF=0,FLAG_SJF=0,FLAG_HR=0,FLAG_show=1;
2 T1 t& }1 ^9 x; x, }+ m: xint InitPool(processPool * p);' b c4 v; ^1 K( P/ j5 d1 ~; u
int produce_one_task(processPool * p,int i,int id);" L0 O( E, p/ Y( M1 S
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);
. j* K/ H. z7 D# `+ u4 C2 oint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);+ P( ]+ O1 m1 C: n
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);
9 I) R! ^$ c& h* C* jint FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
, G! `! U" U+ \' j/ F' a9 p5 wint ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);, W: N/ i+ ~$ {7 P
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);, [+ @4 D" C J7 Y
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
& e0 R: B) P5 R2 t7 j4 n# pint Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
* L% }3 G Y7 `& m0 P) Vint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch); n Q5 \! m6 D: T
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);5 m: r* u% h8 S) L! @4 d
, o. r1 F" Z/ {# ?0 i$ v) P n" v* V: w# l; L( a
int sort_by_comingtime(processPool * p,int pos);8 _" c" {) u9 z0 F
int showProcessInf(processPool p);
7 }; j5 [. v% M5 @: Bint drawPerformance_FIFO(int x,int y,int memorry);
$ m- l9 J8 P2 B5 F# Mint drawPerformance_HR(int x,int y,int memorry);$ S7 B7 |# b% G4 ^- j2 U9 q& H
int drawPerformance_PF(int x,int y,int memorry);8 H, ^9 p2 m# f# C, o3 [) C( c& l! \' b) L
int drawPerformance_TT(int x,int y,int memorry);
! ?* h( e1 h1 `9 Rint drawPerformance_SJF(int x,int y,int memorry);4 N6 r0 X. x5 c
int MouseListening();9 g. T. {5 J6 l
int MouseListening2(int *flagShow,int * showTime);
0 N( h9 k4 R2 H' y! @: k, p( Q* Bint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);6 U& {7 ?' x3 o+ @& J& [4 n% f' T
9 B5 G8 Z. p& b
4 F/ R6 ]0 Y7 n; gvoid main(); s W* c/ ]3 T* o, }2 ]9 `8 R% r# j
{
|( f% Q: D2 q% q: S) G7 UPCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,% y) ? G% y9 q6 {4 x
*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;
; |/ s! O" S E0 e) `& {2 d( R. ^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,
7 L9 X; q# A% HflagDraw=0,showTime=100000;7 `. Q0 X7 u$ u4 ~$ ?
processPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;- z9 w O, O/ n0 l5 P1 w2 N
FILE *fp=NULL;
7 |# A3 W! x+ M( G7 p$ N [3 i//processPool HR_p,HR_mmy;
7 Y& H8 ~! ?. [( t( V
* C( ]0 i8 v; |! y4 p6 q% K; t: A9 X; x: O& f) d! R4 B8 G `
srand((unsigned)time(0));& O: v) P0 s) _/ s. Q" u5 G
systemClock=0;# B6 n0 u! f* p9 U I6 L6 C
initgraph( 1200,650,SHOWCONSOLE );" G- x Z Z. n1 q. ]: i
settextcolor(GREEN);0 u B. t" k/ W! h
setlinecolor(GREEN);
4 u' D7 W" _3 {/ S- R% S/ [1 Ksetfillcolor(GREEN);* g' X7 J* t* b, K, z9 i" u: Z1 X
InitPool(&FIFO_p);
" z" ~ v0 A+ W2 l2 b7 ~sort_by_comingtime(&FIFO_p,-1);% a5 d( Q" U- o5 f, ^" g q
InitPool(&Timeturn_p);( {3 ?+ g' R) s$ H, b" n
InitPool(&SJF_p);
8 K- q1 h$ L/ ^ kInitPool(&Priority_p);
. m% E- Y2 \0 S. X4 j3 nInitPool(&HR_p);! p; K3 t$ H+ f' J
//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);1 {& Y! p/ x, ^. j
//Sleep(10000);' ^+ w& z3 h; k3 d7 L, T
T! d$ X8 O5 [/ K% g2 i1 n
7 A, d$ w6 S" f$ W6 t7 mTimeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
$ q( \% e5 c7 ^0 \: z! _, d2 qSJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));) ^" b2 _, N# x0 c q5 @8 X
Priority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));$ F, d9 H, ~& c$ Z; |
HR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
$ Y( S8 b' C. rfor(i=0; i<initProcessNum ;i++); {) \% k6 S9 j( S9 C
{
0 @7 h$ X" s9 D( K$ TTimeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));7 Y0 z/ j( ]4 C3 A( M0 f$ s
Timeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));1 W/ V; K i! q1 [" V4 ^
SJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
9 q; r; I9 q( g4 B9 W Y6 M1 eSJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
% u/ ?7 \3 T) ]Priority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));. x. b, q- M5 ]7 E6 m: @) i
Priority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));( o* ~/ Z" [2 S1 H- p3 h. q- X
HR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
" w) h% t6 L# x: |HR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));- @/ t) F6 m! k' E; J! _3 ~
}
% C3 U: ~* v7 |) p- ETimeturn_mmy.proNum = 0;
( S9 ^3 ?. f) O& P. h6 {/ hTimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);
5 N; C& W$ {5 p& K! W8 MSJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);
, A. l# w2 Z' Q0 F6 c5 v: BPriority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);4 z# y( l Z& W
High_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);
* y& k3 I3 o6 H//showProcessInf(Timeturn_mmy);
2 Q" C; v9 C( z( R$ O& W' t( yFIFO_pri = &FIFO_save_head;: y* J5 L4 K' p6 u, @( T2 O
Timet_pri = &Timet_save_head;% u# H( o; _9 X4 `5 o
SJF_pri = &SJF_save_head;; m8 f- J( i9 }- S# O B
Priority_pri = &Priority_save_head;
9 V" b6 p0 ]' n# }2 e' d" @! H HR_pri = &HR_save_head;( b: M" Q8 y. E2 V0 D$ y0 u
setbkcolor(WHITE); |0 V; E( x9 g4 c8 J: R
while(1)" J2 ], w* H7 F; S3 p
{8 v& }7 Z: Q/ n
if(MouseListening()==1)
* _9 g7 s, [3 c8 o6 W# { W f; |# lflagDraw=1;
4 Q4 {; ?7 \1 ?' X9 }2 |9 [/ Sif(count==100)
4 s R5 A/ `- m. x, S2 s* M& b{
! d7 R6 O; r- iif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)
- e0 E$ w8 X4 ?$ [{
- @# C& z8 r3 u0 u# \FIFO_pri = &((*FIFO_pri)->next);
5 f+ f( }: W E# E8 Y9 Y; q6 \- r: W6 t! F% Q3 k
//printf("hello");4 Q9 o/ E& m0 D$ y% h
}- p3 u' }% c$ \9 P' `' b
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)
; ]9 _' |3 e% \: `% f' F, s{" r5 z( ^& O8 l
Timet_pri = &((*Timet_pri)->next); C H3 L0 {+ l/ i( n
//printf("hello");
+ {$ @7 g" T7 I/ W7 s}9 K6 c' K: h, E7 B' o8 l* E3 a
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)
( x, \/ A/ A9 U3 m# n{3 V8 a) f5 H' ^$ B2 b
SJF_pri = &((*SJF_pri)->next);
% [9 N$ _# V0 E* R$ e* p* v8 r//printf("hello\n");
* K; l1 q) Y1 @6 A2 R. H) M a* j# I}
8 B. M& r$ o4 C5 w* b! @if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed)3 U% g6 S- X$ C* i* b+ i
{( }* d0 s8 w- a$ X5 [! f
Priority_pri = &((*Priority_pri)->next);
4 e- a% W2 _1 d* D4 ]2 a//printf("hello\n");
; X2 Q' a) k6 B# i1 t* T' |} Z% x0 R1 i. a- p& _: _/ `; r% \
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)$ n ^* ]& _* t) {1 B% |
{4 \ w, M+ w$ {" M
HR_pri = &((*HR_pri)->next);
. p% u' r# [* P- E/ X% j7 e- g1 e//printf("hello");9 [$ v, @, K2 I0 L+ X' r6 z
}$ X# {' o$ g% R4 c& ^- E; h3 l9 t
count=0;
( s$ E9 Q3 a# G- G% n7 Y( t}) Y! d' x, Y$ c1 i
else
9 g2 q+ D' U* |( q8 ~* s! }{
0 I( C( M" C" x7 c' d) J a8 x! ?if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)
$ Z6 x) n y- f' C+ B{& d! T6 Q) [- u4 b
FIFO_pri = &((*FIFO_pri)->next);' D( M+ @+ R9 n9 V
// printf("hello");
5 ~7 G; O4 A3 X" S}4 w9 d; c" }+ Q) i" f: h/ ]
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)
# r) G# Y6 R$ V3 t4 i{1 M! c* \. ?5 m, f8 u
Timet_pri = &((*Timet_pri)->next);" z2 }7 Q- D: u
// printf("hello");
! i2 S# ]* j8 b. A3 Z. m1 V; \}
% ]1 Z! n1 I' m$ P! a. Bif(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)5 }3 t5 A: c- o- j. i
{+ L8 ]3 E1 |. I, B v. w
SJF_pri = &((*SJF_pri)->next);; a( Z% J5 G9 l& L& j5 q; C
// printf("hello\n");
: q5 L( g4 y: q. i. l. e}! b' ?4 C o$ i, l' E) W
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)9 o) R o/ }9 A6 v
{
2 X2 `' x8 V! M) A& n$ T2 W0 Y8 MPriority_pri = &((*Priority_pri)->next);' w5 L" \' S% p/ x% P0 X
//printf("hello\n");
: Z# E" V, q# P- l9 Q}; b7 S. z; V- ?" I7 D" e
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)
4 H* u) p; u; g{
( ?7 w; r% O3 I, {HR_pri = &((*HR_pri)->next);7 V: n5 Z! N6 p! j3 D
//printf("hello");8 w$ H4 Z* _% M8 k) I2 c# {- R# ]
//Sleep(1000);
$ c) f _9 {% o6 S1 A}$ g4 ?$ n6 m% J5 `( {5 S- u
count++;+ q* m! P7 u4 q& q e; n
}
2 j, E1 a" I Q7 N" q1 Aif(systemClock==showTime)
4 X' ]4 U( _# S$ _ N{* u8 ^8 {" u% B/ d7 r
/*PCI * p=FIFO_save_head;/ D0 U3 G8 [! D, l, C
int i=0;6 r# [& d6 H' l/ R4 c4 ~/ u3 P
for( ;p!=NULL;p=p->next)9 S9 t' h! N) J( g5 Q" f
{. M: y! A* x3 k
printf("Id %d\n",p->processID);2 P( g; K: v# s' W
printf("comeingtime %d\n",p->comeingTime);
( b/ A- ~9 I0 {2 k# Hprintf("runningtime %d\n",p->runningTime);1 Q+ r$ w# N2 R' u
printf("asdmemory %d\n",p->askMemory);
: o: D) t0 n3 B" p! u0 Kprintf("completedtime %d\n",p->completedTime);9 [8 n7 e: ?3 |4 T
printf("compute %d\n",p->compute);
: q" O2 W3 ?1 j: Pprintf("exchange %d\n",p->exchange);7 A( H8 E$ n! x) X
printf("waitio %d\n",p->waitio);
( l1 X- V! p" J! y* m; Ji++;" N5 _) p* m5 }) ^: a6 N3 {; e
6 ~7 S4 U) ~+ e# X+ I- Y/ a H* I0 S7 u, s( v
}
0 }, d! q5 p/ b* a! \printf("%d\n",i);*/ k: f" H! V6 X: c
if( (fp = fopen( "data.txt", "a" )) == NULL )# v- U1 ?# ]6 X" o
{9 I5 i* g' b. {& x/ v
printf( "The file 'data.txt' was not opened\n" );
+ Z1 `+ R$ x3 b//return 1;+ e$ h r8 F( E$ e: P/ o4 _1 P
}
; }+ l+ r# c, F8 J% i Selse* W/ k0 O5 M4 f6 Q8 H" }
{% F) |0 h) }8 g- } l9 D) l
fprintf(fp,"FCFS \n");0 l$ B% S$ f0 D4 |% u8 x7 L/ n' f% @
for(p=FIFO_save_head;p!=NULL;p=p->next)
& L4 l" m: k. Z- ^* d4 g+ E; q9 lfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,, h" k1 v/ j1 c, H X/ O' ^1 ^
p->exchange,p->waitio,p->runningTime);
$ I+ j# R9 {" i1 `& x! rfprintf(fp,"\nTime turn \n");0 @# A1 ?5 Z9 F! L
for(p=Timet_save_head;p!=NULL;p=p->next)
; R8 w+ ^7 v c$ F! R# Wfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,0 X, _1 Y- l ]2 T. p. e) j
p->exchange,p->waitio,p->runningTime);
% t* r! x# \6 m, i# h8 H0 Ffprintf(fp,"\nShort Job First \n");/ v: `' H7 x" k
for(p=SJF_save_head;p!=NULL;p=p->next)6 G% y* A$ ]% J7 D! T/ P& ^
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,! S+ @4 c" e. `" B
p->exchange,p->waitio,p->runningTime);! ?/ U4 a5 p/ u2 i5 }3 M
fprintf(fp,"\nPriority \n");
1 k f4 }- E- {! |for(p=Priority_save_head;p!=NULL;p=p->next)
& L( c' C2 K, m$ Ffprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,& z$ d8 H: J4 d2 `. l4 W7 c" J, C
p->exchange,p->waitio,p->runningTime);7 n: z# L" Q. w" O( m5 G" z+ t- Y
fprintf(fp,"\nHigh response \n");
+ R! n% C/ r6 A! v0 Yfor(p=HR_save_head;p!=NULL;p=p->next)" g) c0 Z5 A. O# x( g c6 E: ^
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,8 Q% ~4 v, V7 F% Y
p->exchange,p->waitio,p->runningTime);
. v( ]! U! L# [/ ?6 r+ @0 p- lfclose(fp);0 P" }( |0 l( A. j$ Q$ ^
}2 O% x) P2 G6 ?/ {2 y7 i
showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);2 M4 |0 |+ q+ m+ E9 v0 p
MouseListening2(&flagDraw,&showTime);
/ o9 Z* i0 n: o& y7 Q& }9 \}. c: y: ^4 m; `& C' Y0 e
systemClock++;
4 t! R. h7 E3 ^, H$ m1 Eif(flagDraw==0)$ l2 ^2 |, j* o, y9 t' G9 g
Sleep(10);/ Y2 I# ?9 U* \
}% T3 f" h& F6 T) Z) a3 R
; x: M/ K7 a* o$ [
~. j# m; O$ ]& f2 E0 Z}
& R7 C2 s. v# V# b( k- Oint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)
. A$ T; {2 D% @6 G! g{
1 i' ]( v7 Z+ G5 ^6 y% NPCI * p=NULL,* name[5];% t5 Q% \$ m# d+ Y" N+ g
int count=0,i=0;
5 L. N4 ~. f. nchar ch[5][10]={"FCFS","timet","SJF","PR","HR"};. e! n, C2 l' f. {6 s4 f0 c8 R+ H
double turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};
( W2 ?/ g1 Z$ q* a) T0 H1 J$ ustruct info
' P! ^1 f4 A+ ~0 N2 {{; I2 o2 K( ^6 i {3 q" B$ @. O
char name[10];5 u7 G6 S/ H; Q6 K
double throughput,turnover,wait,CPU_rate;
" W9 e0 ?$ x% Y/ ^/ P5 c+ p- G. ]}inf[5];
! N8 N' X$ z. [name[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;
2 E& G1 h& W0 F' X' l+ yprintf("调度算法..........A\n");( i6 W+ t! L. G# ~6 t
printf("吞吐量............B\n");
' A0 i) x8 M: y( @" {5 d' |) W. bprintf("平均周转时间......C\n");; J2 o$ f2 }; |
printf("等待时间..........D\n");6 t9 `$ q, W% n: M
printf("CPU利用率.........E\n");
' h! ]; o) {$ s8 `) J+ ^printf("A\tB\tC\t\tD\t\tE\n");: a8 a0 V8 s# y5 P. {# [7 n8 F3 R
for(i=0;i<5;i++)' I2 s1 e! z- u2 G6 g
{7 S. m6 m- x# A6 g T
count=0,turnover=0,wait=0,c=0,w=0,change=0;: p7 S; z; T% i5 O- F) Q
for(p=name; p!=NULL; p=p->next) l2 O! r. o0 P! k6 r! j) @9 r* m
{ M+ r; y( E& F+ n$ q9 k
count++;
$ `9 j- |1 Q+ ^ fturnover += p->completedTime - p->comeingTime;
$ m% {) G: M; rwait += p->runningTime - p->comeingTime;4 A1 h6 ]+ ?0 H
c += p->compute;
- F+ F1 ~" H# nw += p->waitio;8 Y4 k$ ~# I4 `% `& {7 f r
change += p->exchange;" \7 M \: I3 v- H$ F$ c0 f. [
}
+ Q' M7 z" U4 mturnover = turnover/count;5 A: ?5 I& J3 u1 I$ J. a: ~
printf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));
/ ]8 m1 E U% e4 O) K7 Estrcpy(inf.name,ch);1 b! C- |- }- X9 d ?2 ]
inf.throughput=count;
# Q4 K* | [# M+ einf.turnover=turnover;
- q, b" Z2 d/ B5 m# j* d2 e. ?inf.wait=wait;
% g. {: E) s/ _2 vinf.CPU_rate=c/(c+w+change);. D, W* z/ k( M
}
/ [4 F! \4 [' c8 ~//画图
% y) T" k! d _% d; G2 b; |//cleardevice();+ R# }+ O' y& R4 B# z7 R% E
line(0,600,1200,600);' H- [8 Y6 u1 J+ K
line(10,600,10,200);
% T6 \6 @' L2 J/ ^ ~+ g. u' Yline(10,200,5,205);
# k9 u& z8 N+ j9 D0 K; Q. @- Vline(10,200,15,205);
) p, ~2 Z) @2 K! A7 mline(310,600,310,200);
( @$ @9 x! x6 B: fline(310,200,305,205);' }! N7 r$ |5 v N
line(310,200,315,205);
R* W" J% N! R- ^" nline(610,600,610,200);
i8 X) f( N1 _& _line(610,200,605,205);
) W8 _5 R- X" x0 ~line(610,200,615,205);' d% f. K' M9 j) q
line(910,600,910,200);
7 ]7 F' T4 j& a; y# Rline(910,200,905,205);
) o* y1 h. R# K- H% y% \* ^) J1 L% ^line(910,200,915,205);//最高的长度400,宽度均为40
& a3 o0 W. ^( H3 cfor(i=0;i<5;i++)
5 ~) d, W! H; a) @: \- o{: m5 ?0 R: a4 ^, q" T6 ~! `' g
if(inf.throughput>pos[0])
C# E: r8 u4 l4 xpos[0]=inf.throughput;
: o5 j7 E; N$ r, nif(inf.turnover>pos[1])
5 _, F! Z7 O: L* U; N, o6 h7 C6 Jpos[1]=inf.turnover;9 K, @( F5 Q9 l) ~( Q
if(inf.wait>pos[2])8 c v( y/ w, G* t7 @9 L
pos[2]=inf.wait;% Y, P( P+ S2 ?; d0 H1 m3 x- i
if(inf.CPU_rate>pos[3])
- M) C% a9 q0 W; u7 npos[3]=inf.CPU_rate;' r( k0 s+ J) |8 v
}
7 Q I: v: s* V0 G; Nsettextstyle(30, 15, _T("楷体"));0 j5 g c- S) p6 w
for(i=0;i<5;i++)0 O0 u7 e( Y+ N6 g# m
{' F [2 V+ b' I5 N; i6 I, Z
switch (i)
2 B" Z2 K- B p, U: b{+ ?$ U/ y! m* N' |
case 0:
5 R, x3 _6 x+ @5 i# k( {setfillcolor(BLUE);( J" | |/ Q r, z& }, T+ i& O
fillrectangle(100,50,150,100);
# |9 K. {9 B8 i/ \outtextxy(160,50,"FCFS");
, y( V% r1 ]/ c3 Abreak;
5 i$ ~7 S; x8 B4 [" ^! Y/ Jcase 1:+ D+ M* u! k5 y# s
setfillcolor(RED);( B% d& G# v. D2 ]+ N+ L) C$ b) r
fillrectangle(250,50,300,100);' w: ]( L0 n$ z+ L! A) c1 D
outtextxy(310,50,"timeTurn");& c5 F" X$ G" c1 B6 E4 N
break;
! u* X. F$ r2 M! Q+ L* P0 lcase 2:6 s) a* g6 y4 |+ F
setfillcolor(YELLOW);3 w% J! `% U8 r! H6 R
fillrectangle(450,50,500,100);
+ X/ w1 e# Y+ z; w! ~outtextxy(510,50,"SJf");
; U1 L" O5 g+ f: k/ gbreak;
/ p! \% g9 \) M0 vcase 3:) B% T1 J3 x2 ]0 T
setfillcolor(BROWN);
- }& o- p) `; U9 q" I( Pfillrectangle(580,50,630,100);0 M( Q7 n: R6 y, c/ g v: w4 z: r# O
outtextxy(640,50,"PR"); _) B6 T! W7 C V% C; d( {: }
break;
! C$ `" n: u g" |' Gcase 4:2 Q3 r* B/ T5 N
setfillcolor(GREEN);) R& j2 D! z) t* ~6 \/ A B) k
fillrectangle(690,50,740,100);
6 G& y) G+ x5 p4 C9 p% Zouttextxy(750,50,"HR");
' a% L6 ]% ~3 d! vbreak;
, R6 t$ b" z% |6 }}
4 L0 c$ _% N- }0 d! q3 l& Z0 K/ Pfillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);7 ?% i H: y7 d( V `; c! w
fillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);' {: Z1 `8 q: I2 D
fillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);
. ]7 [( G2 b' T6 l2 vfillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);
s. v+ ^2 X- n' e1 [7 R# R W0 {' m7 i0 C0 U Z2 O) ^
) r A |& q. A1 f' |* j
}, {/ W8 y( q4 V% w. S1 N
outtextxy(100,150,"吞吐量");
- e I" v: Y3 p' douttextxy(350,150,"平均周转时间");" G1 `# b% c; U% o, t3 Q
outtextxy(650,150,"平均等待时间");
7 {7 k4 ?, l& i" J; \" f/ qouttextxy(950,150,"CPU利用率");1 n( u2 Y7 u$ P" ^
return 0;
$ a/ \0 y" X2 R+ i} ~/ c% D1 O# u. z4 g/ i! c- I5 `5 }
int MouseListening()) I' Y2 J w) Z% J% |
{
$ z0 E! y8 _% v" S, |1 ]MOUSEMSG p;
+ {( B" G% n$ o# G& a1 n6 a2 Eif(MouseHit()). G/ L, V! C$ s
{, L3 S }! y: O# Y
p=GetMouseMsg();' ^; t) Y% ]1 w7 r' s
if(p.mkLButton==true)/ ^) B% O E1 B' z3 }
{
e3 V" m: _: c& U7 fif(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
& y4 H% e; F$ ~FLAG_FIFO = 1;
0 f+ {0 z# |4 g. \5 Lelse if(p.x>400 && p.y>0 && p.x<800 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
& o& E0 K1 R) \% NFLAG_TT = 1;
) s3 r# g3 f0 I+ e. welse if(p.x>800 && p.y>0 && p.x<1200 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
/ I! w" R9 C2 Y1 u7 f! yFLAG_PF = 1;
3 D t$ i1 x' _9 d4 Y6 u" W9 {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)
% |5 Y! L3 M2 N3 Q! DFLAG_SJF = 1;
5 |1 p' ?$ d8 uelse if(p.x>400 && p.y>325 && p.x<800 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)2 ?& g6 `! g/ G5 N4 |+ P
FLAG_HR=1;/ B9 Y$ [( W5 k5 F. o
else if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)
0 e h3 a, H$ x1 V" ?7 R{$ m" k7 J* C' K8 q5 m. G
FLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;& P1 Q: M3 l3 n j0 K
clearrectangle(800,325,1200,650);! N3 |( H ~1 V. {7 `$ @
}
7 ]/ ?3 F+ @* w3 ~5 j5 H+ i( W; K' oelse if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )" I' N! |" Q, z8 y: n: Q
{
2 A T; L {1 Z! o, iFLAG_show=0;6 r) A! J* {5 ]( q# V- E% A
cleardevice();
, A5 _* q! {. Yreturn 1;: k6 z% V4 V- Q
}
4 l$ v, y6 x& R1 I# M& o- l}
; d4 x7 o0 |- a( M}
/ y8 h2 `) n( L5 b$ ireturn 0;
, g# ~1 S1 ~7 P- |( G# H- g4 v}
# J/ n8 C( q0 z% L% ]int MouseListening2(int *flagShow,int * showTime)' ?. D0 r, T/ r: {
{2 b4 P% D0 r$ B' ~6 f, k
MOUSEMSG p;: p. N: ?# o2 w7 v v( U: f$ b3 Q
rectangle(1150,0,1200,50);
1 M1 ^3 o/ q2 P- H5 T6 Z; routtextxy(1160,10,"X");
& G9 {/ `4 R! Fwhile(1)
& Y3 ?$ }/ y+ @) b6 M! A{- ]8 c/ G9 f; m# K( m2 d
if(MouseHit())5 I. c- Z6 m, h4 g6 ^9 a
{( }" v$ }" z! k6 L" y% t5 b. J
p=GetMouseMsg();
% _( V w$ U) qif(p.mkLButton==true)
" a Q* f8 s U{
! H2 O( E1 B" m: bif(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 )
/ }. l5 q" I8 s{, o- Q$ A0 {" f2 c
(*flagShow) = 0;' ~4 A( i! E0 m; v# L. q
(*showTime) += (*showTime);+ W8 y* m4 w$ W8 u0 m$ o
FLAG_show=1;: C, v! h, w+ c
break; ]8 B" F) b2 Z( f( {
}
7 Z% i1 T; H4 A! F# ?2 f5 |# G" e5 a* W; C
}0 e, M; e& Z" c( S
}9 O* N! A( X7 r" j+ I0 l' n
Sleep(20);
1 Q) A" c* f8 X: x$ R" g; m/ S}
: V, n! }/ b5 r+ L Lcleardevice();: Y, y. T. E7 o0 p$ \0 B4 R$ R" b7 g
return 0;
2 V) u( y6 ^ z4 a- V3 S8 V}
. R9 o' \* @6 d5 Z# Hint drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)
R5 w9 b6 M3 W' r{' U; d O6 o: I0 s' t) g
static int info[11][3],num=0;3 z3 Z% A: K2 m
int i=0,j=0,pos[10][3][2];
. m' `- h( K/ N- S% L' A7 Mfloat temp,t;$ K' s* S6 T+ X( h
//画按钮,不属于FIFO图的范围3 B: w8 B: H. ?, j% w1 J
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1)
. o# }: k3 a0 Z! T: {{4 B0 L; s2 @0 L) X9 @( Y
settextstyle(30, 15, _T("楷体"));# H/ o5 k: K0 }8 `1 T
rectangle(890,455,1110,510);/ {/ s/ }, s( W: q7 ~7 R$ H' v
rectangle(900,465,1100,500);$ [* w1 c E# D& g/ m# L
outtextxy(910,468,"查看运行结果");7 m+ I1 }' H" \1 _
}% E9 r$ J4 X+ S/ l( W% p3 A& `% K q
//结束画按钮4 S$ j# J% c4 @2 p
info[num][0] = com;
1 f8 ^# z: V/ f, p, tinfo[num][1] = wai;, x6 h) t0 o8 l) z! v6 w
info[num++][2] = cha;" E; L, G; ]# I$ T% i0 U! P, @
if(num>10) //存储10个点6 B8 B* l- ]$ H) |1 X
{
' ?. @. i: l0 s+ Gfor(i=0 ;i<10;i++)# ?1 t0 c2 [" I9 d& {; D* a* O4 ~
{1 L4 ?3 C% a% D) J( q2 G6 u! h
info[0] = info[i+1][0];
$ G( _# _5 p+ O/ H0 o3 j# _info[1] = info[i+1][1];' |. z8 `" g2 c- P( x" H
info[2] = info[i+1][2];: ]7 s3 r, @7 D5 ^
}
4 V" W- f- o, } ~& X9 L- Wnum--;
5 m2 W0 \9 `3 J. A/ M0 e2 o}' X" a' T- F. w3 H: @/ Y
if(FLAG_show==0)& q9 k C: Q9 T5 ~) `: p. x& y/ {
return 0;, `' n3 o. a, g
for(i=0; i<num; i++)) L8 v1 T+ L, U$ J' t
{$ j' [' }+ O: I/ T4 K u
t = (float)info[0];
/ M j7 I) ?5 {* Y7 {3 [' Z5 Htemp = (t/101)*90;: O8 _) n/ A+ H, c$ b9 _
pos[0][0] = (10-num+i)*25+x+100;" V/ e1 W# p2 g% c* L
pos[0][1] = y+110-(int)temp;$ M) n/ E- t+ c& T: g
t = (float)info[1];
/ W G8 s7 e0 I* o3 B6 Atemp = (t/101)*90;
$ N$ c/ Z0 O* M$ D; Epos[1][0] = (10-num+i)*25+x+100;
3 ^9 s9 V+ n. ~! W' I% C7 tpos[1][1] = y+210-(int)temp;6 A+ v- e% A4 A
t = (float)info[2];5 Z+ U3 z3 t8 D' ^6 \
temp = (t/101)*90;
3 j5 s8 A0 H0 }) J4 U# a% @pos[2][0] = (10-num+i)*25+x+100;5 z1 b; o! b- S7 [6 l% J+ L( q
pos[2][1] = y+310-(int)temp;
! Q- D7 B8 t1 ?) B5 u) e- Z' k}
9 C) L5 k3 P; s* d/ J+ Q4 Rif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)6 P, q7 B( ?: P) U1 I" c
{
) n8 @$ M2 t, ^* Dclearrectangle(x,y,x+400,y+315);# R( u" I; i* V) Z* n
settextstyle(20, 10, _T("楷体"));9 I) T! i3 Y2 i+ F. l7 r' C
rectangle(x,y,x+400,y+325);
' W5 l& t; K- S Vouttextxy(x+40,y+10,"CPU"); //画柱状图
6 r3 t- l4 S: ]7 a! h/ Zouttextxy(x+45,y+10+100,"IO");; g. Y8 T0 U/ M# L3 {: [. t8 }6 I
outtextxy(x+40-15,y+10+200,"change");8 \+ k' x$ i- c0 ^" [' g
rectangle(x+35,y+30,x+75,y+110);1 a* }5 n, e/ c# @2 `: u
rectangle(x+35,y+130,x+75,y+210);& q4 ]+ ?, z4 O! }
rectangle(x+35,y+230,x+75,y+310);6 O. Y/ e( w7 s: P
outtextxy(x+180,y+310,"FCFS");) H: t1 L2 v% Q
t = (float)com;! Y& Y7 W; Z! H9 ?6 B2 a0 P7 Q
temp=(t/101)*80;
" B( s" @) f% I7 C7 h0 nfillrectangle(x+35,y+110-(int)temp,x+75,y+110);
/ ]0 D3 R s6 i8 m* F3 f `t = (float)wai;
* A4 f2 h8 M+ ]temp=(t/101)*80;! E n1 l" ]* `
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);) u6 f" E' t- j6 r' _
t = (float)cha;. ^- P9 {: q; B; {
temp=(t/101)*80;
$ d$ [$ L8 g/ L" lfillrectangle(x+35,y+310-(int)temp,x+75,y+310);4 ^$ B7 X+ S2 b, }: O7 t
for(i=0; i<3; i++) //画坐标 high=90,length=250. m7 L* f" s* V& N
{
) G' X1 h0 t: E6 K0 c4 m% dline(x+100,y+110+100*i,x+350,y+110+100*i);
; ?/ S. Q/ W8 m; E$ q/ L3 Hline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);& f) q8 K: p" m8 ?$ P. R
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
0 s; J& Q" v7 J- K6 S( ~2 ^: z1 z( k6 U1 c! z' @4 l
line(x+100,y+110+100*i,x+100,y+20+100*i);
$ i* E- k& f/ ^% S R kline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
- ?& G) G# N% E0 g) i* v' a4 pline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
7 f3 T5 Y1 ? w- c/ Ofor(j=0;j<num-1;j++): V! ~/ |4 z2 J
{
- k! y) m6 `$ m$ i }5 G1 @line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);7 |( ]. l& j/ m6 S/ y. V
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);' [3 F6 V" ?. T/ F
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 6 R- h2 Q$ X4 C- `
}0 T0 ^- O H* T/ G3 Q: V5 a$ S
}- I& h+ w) W0 D' k$ d ]; s
}
, a% t+ P+ l/ v4 o+ t" Q) Lelse if(FLAG_FIFO==1)+ A/ F* k7 X& y
{& I( k& G2 L( z7 H9 {* }0 k
x=0,y=0;
$ {1 n( b! `' o0 }( gfor(i=0; i<num; i++)
- \% i3 x9 x" Q9 [{) W' s/ \$ {) i1 K
t = (float)info[0];" v' d/ R9 @3 p, t# b' @& ?
temp = (t/101)*180;
) E* Y. m6 B1 npos[0][0] = (10-num+i)*50+x+650;
5 a0 d' ^. d( ?' z) Q/ npos[0][1] = y+210-(int)temp;3 F0 \( e: K: C( P% _" ?0 D3 V
t = (float)info[1];
: {( E2 H" o+ e7 ktemp = (t/101)*180;1 H1 p9 X. D7 n' B& S
pos[1][0] = (10-num+i)*50+x+650;% x5 e% W% p1 a6 F' f8 o. U7 N2 _
pos[1][1] = y+420-(int)temp;1 s/ M: f+ ^, w! ^2 }+ I9 b2 g
t = (float)info[2];0 o2 ~$ h8 Q8 u. z" Z. B. n/ I
temp = (float)(t/101)*180;
) h2 |3 I% W* m7 U# i5 Tpos[2][0] = (10-num+i)*50+x+650;
, T7 X) B1 {1 K Ipos[2][1] = y+630-(int)temp;, @4 H+ [4 R+ P6 F. D3 X y, |7 K# u
}
H2 v H1 q, X7 D7 {# Pclearrectangle(x,y,x+1200,y+650);$ Y2 S8 j. a# G4 b, p# d
settextstyle(40, 20, _T("楷体"));) X* A& T8 b+ p. _* H. \' e ]
outtextxy(x+50,y+50,"FCFS");$ w3 {/ q% s, d. N9 f
outtextxy(x+280,y+20,"CPU"); //画柱状图
% O; ^9 E `/ e9 ^outtextxy(x+285,y+20+200,"IO");7 L: }$ } m% w' j# |) A- {" ^
outtextxy(x+250,y+20+400,"change");, H: z) }- W" j
rectangle(x+270,y+65,x+330,y+215);
0 C e. z# P) x& _1 q( Grectangle(x+270,y+265,x+330,y+415);/ b( \! |4 W4 A9 t v. a% F' c0 r
rectangle(x+270,y+465,x+330,y+615);& h3 W, u! O) Y- H* w
outtextxy(x+290,y+620,"TT");
2 i+ \5 i1 d9 yt = (float)com;
+ L" b" _) {0 u( L8 ctemp=(t/101)*150;
& a x; U5 ~) ~! z wfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
. x$ Y* W6 u4 {) _t = (float)wai;) g4 \0 e* x9 Y5 I, x( b
temp=(t/101)*150;
5 x5 l2 z& M- C3 _: i Nfillrectangle(x+270,y+415-(int)temp,x+330,y+415);
: X" M% G0 q0 j2 g& E' ^) gt = (float)cha;/ o1 h- j( ?/ H) d k. a; A
temp=(t/101)*150;# f1 r9 N2 P- s4 Q
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
' `! N7 Y; S; T, N5 wfor(i=0; i<3; i++) //画坐标 high=90,length=250& ~1 i% F6 q5 \% ]
{
2 @/ @' a7 i: q2 }/ j" } aline(x+650,y+210+210*i,x+1150,y+210+210*i);
2 m3 x2 o) D( y) Cline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
% J3 ]% }* n9 m% ~line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);: t/ X9 N9 W( p4 d' H: t$ F) n9 }3 P
* } |/ R% } t* V1 k
line(x+650,y+210+210*i,x+650,y+20+210*i);% k/ F7 }$ v7 {3 G/ h8 S
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
% F/ J4 o9 K( e1 k. dline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);8 s$ V2 B; R( O( N a7 Z0 O
for(j=0;j<num-1;j++)
e) D8 K9 q0 h{6 B% s0 o: X6 n
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);% o- d3 u6 l0 {9 d
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
: t8 A' R6 Z4 [) ^line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
+ T9 T8 f* p/ }6 N, ]6 ]}/ X0 G6 O$ u/ w, r/ X$ J7 |
}+ s6 R; ?4 q# D0 `( ^" F
}4 D5 Q% d2 Z; j5 i& w
6 B6 @1 l5 u) d! W! i5 W) a
8 z) T4 f9 z% {$ Nreturn 0;) ^" r9 q) {# i, ~1 \
}) ?# s- T) `. k+ s3 g a0 n
int drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)
# `2 g0 Z6 i& Y! i{
1 [: g5 Q6 \# `& N" a, Dstatic int info[11][3],num=0;
/ `8 V, P/ K9 _4 n- M' Nint i=0,j=0,pos[10][3][2];
3 C, P# G* C$ s Z8 q8 F& Lfloat temp,t;
& t" T3 P, @. q5 Einfo[num][0] = com;
+ o& o/ Q0 Z2 V; _, g3 ~7 Finfo[num][1] = wai;1 p' G! _0 P9 N! q
info[num++][2] = cha;! u" H- s8 T c$ ]; H
if(num>10) //存储10个点
1 f4 n4 O( C7 k) d0 ~+ g{
/ a7 C ^1 _. _for(i=0 ;i<10;i++)
h" R* g% ~$ t+ f5 i7 I, g, C{* s. j7 O, j" S! p' s) D
info[0] = info[i+1][0];
; ?% m6 H" U8 r B* Z [' U& d4 ]info[1] = info[i+1][1];# x$ U. B$ {7 x1 T
info[2] = info[i+1][2];6 c3 O$ q4 W6 ^- O4 S: p( S' S
}
# x; e0 S" b) I1 v0 e n0 ]' p, [num--;3 D1 k& R7 A/ Q1 D
}
* Q7 ~0 W& { F" h" m% c1 ~3 Mif(FLAG_show==0)
5 c& j g0 L; d0 n9 v+ Kreturn 0;6 b0 H. B" t9 [% S6 w
for(i=0; i<num; i++)
5 [* [0 o4 {9 v0 ~% K! H8 ^0 s{
+ j4 c$ ~9 {$ K/ o4 ?/ B! ct = (float)info[0];
9 t4 v3 e( m% h' F% a2 Mtemp = (t/101)*90;; W( v- e8 I0 g" E6 P8 h7 l
pos[0][0] = (10-num+i)*25+x+100;
5 C; h, `7 ]: a, ypos[0][1] = y+110-(int)temp;
% x. z# b0 V$ ot = (float)info[1];
' h" W$ N% i C- etemp = (t/101)*90;3 a5 T0 H* [9 E6 [+ ?0 ^
pos[1][0] = (10-num+i)*25+x+100;
/ p, C7 X7 H! g4 ?pos[1][1] = y+210-(int)temp;
+ p/ `6 O8 M& Qt = (float)info[2];6 z- |5 E8 c* o5 [
temp = (float)(t/101)*90;
9 W d6 q, o9 j4 l* L2 epos[2][0] = (10-num+i)*25+x+100;
, d9 m1 j' j. Q' _pos[2][1] = y+310-(int)temp;) k, i% H# p& _% Q G$ X" d
}
7 y, h$ D5 b8 [4 V/ N. Wif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
; \+ _" T' k9 n) N{
0 F! P+ s& \+ _2 H: }clearrectangle(x,y,x+400,y+315);
/ B2 S) O5 O8 v! Dsettextstyle(20, 10, _T("楷体"));
7 |# S6 E, u/ n+ }3 l" y* Y' vrectangle(x,y,x+400,y+325);5 e4 n& M8 z$ \, Z
outtextxy(x+40,y+10,"CPU"); //画柱状图
P# g' U6 }8 G! v# Y8 k( ?# t2 G+ houttextxy(x+45,y+10+100,"IO");; U& i0 c6 O7 p1 I7 g
outtextxy(x+40-15,y+10+200,"change");( q+ U7 C8 W6 {" h2 `8 t8 p
rectangle(x+35,y+30,x+75,y+110);
' g5 u& e, f6 w# u7 b3 f$ Y" drectangle(x+35,y+130,x+75,y+210);& c/ C) `/ N$ n0 |" n( @# Q
rectangle(x+35,y+230,x+75,y+310);
. Z( G0 i7 b; r$ M5 Aouttextxy(x+180,y+310,"HR");
; t% I! K, v( `6 F2 ?: Ct = (float)com;& @3 c1 ~7 H' |, u' l
temp=(t/101)*80;/ x2 r- n2 _5 ~' c6 f
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);, f$ b u" O k! B& o- |
t = (float)wai;& n' _8 n# S( j
temp=(t/101)*80;
' U: a% B D t; m" ]- r' `fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
4 {9 }2 B' Q' t/ F# q2 K, |9 ft = (float)cha;
4 w& [0 m* M& p( mtemp=(t/101)*80;* P6 n1 a& l1 D7 }* h* {! F
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);& I" Q5 z% A/ E) x2 ]
for(i=0; i<3; i++) //画坐标 high=90,length=2507 G: X9 S5 n0 N
{& N% }1 s6 A4 G
line(x+100,y+110+100*i,x+350,y+110+100*i);
4 r N$ U8 Z5 t- | d" vline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);6 _5 [% p# h" m V* Y* t
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);8 h4 r: V9 V- Y) ?! y8 {$ [
7 f& }- Y2 }' k6 p% j" eline(x+100,y+110+100*i,x+100,y+20+100*i);
1 \' K6 r {) F& S: t, X' I$ ^* ^- H1 }" Pline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);5 c1 `: `& ^" ^. J5 \, u
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);8 k+ P h, d8 A. o% e4 i. E
for(j=0;j<num-1;j++)3 ?& N3 X# x1 K# R/ m+ {; ? t
{
5 C3 B; m% v$ k; o$ J. rline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
& ?% V' l( r% A8 U8 vline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);7 `3 h0 d8 l$ ~
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
; ?$ x v- ?3 ~5 i& |' o9 k; s+ \* @}
) ^# [8 z9 n U1 r S1 x/ S& j}' f' r" `1 w; j/ O/ ^/ v. T; ?, K
}
j- l0 V1 v8 I9 G6 N. C, Melse if(FLAG_HR==1)" s% T' a! j7 l5 h2 D
{; F% d- g/ A% \
x=0,y=0;' N6 h/ @8 h; }" R* b1 x0 _. z6 f+ x
for(i=0; i<num; i++)
+ x1 u, i! ]: K" A8 M" i{4 q, o+ S! M; O# D! n" M
t = (float)info[0];+ w9 Y7 O7 W% x, ^5 n, `
temp = (t/101)*180;* f& { W' _) B2 o+ O2 ?) F
pos[0][0] = (10-num+i)*50+x+650;; D8 Q+ f+ \, V' o8 n1 H& P8 C
pos[0][1] = y+210-(int)temp;8 s$ U# @* o! b. \& A$ T' m, x
t = (float)info[1];$ T2 |* U5 d' e9 t7 p" ~$ J
temp = (t/101)*180;( ^/ t: ~# l. X+ j% b& F
pos[1][0] = (10-num+i)*50+x+650;, {$ L; y2 {9 e5 [2 ]9 {4 X
pos[1][1] = y+420-(int)temp;
& J8 _7 {7 s% e( u; o3 M3 pt = (float)info[2];) \; t m4 |' C% ~; {
temp = (float)(t/101)*180;
4 }: p2 ^7 k2 Y# H* T" ypos[2][0] = (10-num+i)*50+x+650;% S' K9 Y/ Z+ M9 a+ t) n
pos[2][1] = y+630-(int)temp;, b/ l1 M$ h' w+ c2 g
}
9 E% E7 S3 v4 f# W9 g, sclearrectangle(x,y,x+1200,y+650);; s5 t+ z2 D5 B" L7 V
settextstyle(40, 20, _T("楷体"));
5 u" F. z8 x5 d/ Qouttextxy(x+50,y+50,"HR");
6 N1 H V( a/ G7 B; Uouttextxy(x+280,y+20,"CPU"); //画柱状图& E% u- {% S2 l \ K7 m' y
outtextxy(x+285,y+20+200,"IO");( F- O9 e) z6 M; S
outtextxy(x+250,y+20+400,"change");
! w7 W1 r' y4 ^" c0 s! ]+ crectangle(x+270,y+65,x+330,y+215);6 y' h: [% v$ B$ X' \) E
rectangle(x+270,y+265,x+330,y+415);) x; @6 ^) e; I9 y+ d! M2 }
rectangle(x+270,y+465,x+330,y+615);
0 z, @6 G; q( Qouttextxy(x+290,y+620,"TT");* f8 a7 b8 B0 c+ O
t = (float)com;
, r+ ^; E' }0 w2 Mtemp=(t/101)*150; e" F8 z/ V- |: w
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);2 I5 \& }/ B: Y# L8 i6 y/ |4 b
t = (float)wai;
& ~' z/ r! Z6 ~+ Ntemp=(t/101)*150;
`9 h B D& Y+ Cfillrectangle(x+270,y+415-(int)temp,x+330,y+415);) c3 n2 g1 |* q- @5 C
t = (float)cha;
, E/ P! `4 g% ctemp=(t/101)*150;
8 M; K7 L- s% \ i) n7 D' v5 k* Pfillrectangle(x+270,y+615-(int)temp,x+330,y+615);3 [0 [ X) P( W$ S! p! g0 V
for(i=0; i<3; i++) //画坐标 high=90,length=250& e( V; d& y- ]/ j! V
{
& G$ q( v0 x5 x" jline(x+650,y+210+210*i,x+1150,y+210+210*i);& Y; {5 e5 \$ v K$ e/ ^( v
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
# x) y/ O5 i+ L6 m& ?. V- ], M# j$ a; Aline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);, T5 F. `# Q) r6 P
9 _; P9 v+ w# jline(x+650,y+210+210*i,x+650,y+20+210*i);
+ j6 }1 ^, v/ D; zline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);- U' [7 z4 u2 w5 X( y' w) e! _" l
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);8 m/ o' P* H0 Y
for(j=0;j<num-1;j++)1 V/ b, z" c1 \- g% b, e5 J
{- `3 M5 T8 G- }* B% R4 }
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
8 k0 @, _! O1 F$ a+ }; Cline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);% X3 K- {! l5 D" c* H& l2 C3 l' s
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
1 A( x0 `! d* l; }}9 S. f1 ?5 |5 _/ k8 J
}
+ O/ [( Y8 i2 e: t7 H$ ^. o' ?}: W0 ~2 _# ^& h2 \) |
4 D k. Y- V1 L# S* ?7 ~. L" Z
8 F, A: U* E0 K4 ]! {# c9 k/ c
return 0;8 ~& d/ A3 P6 } o$ w
}
5 o5 V, T3 ~! Vint drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)" a# h% |# \( D" ~
{
2 l- K6 D3 `5 Qstatic int info[11][3],num=0;. m9 Q6 v1 ]+ a7 k( C! m
int i=0,j=0,pos[10][3][2];# I. ^. V0 d' u5 m* X( _) S* n$ C
float temp,t;
. Q# @- ]& E. W& a/ Tinfo[num][0] = com;
0 q2 n% A0 Z" Xinfo[num][1] = wai;2 z2 @6 \3 B. d* b7 n7 _. R
info[num++][2] = cha;3 V' h4 C: D. x, n3 H5 }! ?7 ^8 h
if(num>10) //存储10个点. w% z z* i- r4 V" f6 G
{
* T# j. t, y: E$ j! k# [7 Wfor(i=0 ;i<10;i++)# x9 E$ L0 R& Y& [9 V2 \$ {
{
8 G$ ]' }3 R7 finfo[0] = info[i+1][0];1 y+ n* N' L: `
info[1] = info[i+1][1];
5 b+ _) t5 a d, x# t! b; yinfo[2] = info[i+1][2];
, i) g. K& i6 T/ A, E/ C& U}4 M- }7 G# c9 N7 @: A
num--;' L# c& `# O' v; O
}
# [$ A3 V h% Aif(FLAG_show==0)/ [8 I e. z n6 M1 e/ j
return 0;
! Y/ A+ S* {$ n6 ~. _for(i=0; i<num; i++)
) {' s- d+ U/ D$ F. ?% M* y4 r! o{
5 T& D* s6 W; p* e6 g( ut = (float)info[0];# T a7 ^ r2 h, {; f, @% m) R2 \
temp = (t/101)*90;
7 y( I% t( N( y9 l. Vpos[0][0] = (10-num+i)*25+x+100;
/ V3 t/ W1 d( V2 H4 Y0 xpos[0][1] = y+110-(int)temp;
5 ]6 A. w" F$ ?+ l' a/ at = (float)info[1];
% o }0 H7 I) s5 s& C C7 ttemp = (t/101)*90;
\! b" O" ~9 c P0 c! o/ Z! Fpos[1][0] = (10-num+i)*25+x+100;
( O2 }! {3 r' D5 y" Bpos[1][1] = y+210-(int)temp;4 P& { s" N: e( @# r0 I) Y$ d3 N
t = (float)info[2];
) i9 n# x, a. g$ }' e5 c1 Atemp = (float)(t/101)*90;4 N) ]. [7 r( X( a
pos[2][0] = (10-num+i)*25+x+100;
1 S2 v+ o9 f8 J/ s$ T1 Lpos[2][1] = y+310-(int)temp;
# c0 O0 J1 w$ ~. n R% Z* {! W( \3 @}" {5 l7 p5 z# Y; y$ w% C* k
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)( m4 C' p- |) v u; e z( n, V
{
9 j1 E: a6 }6 e4 D) eclearrectangle(x,y,x+400,y+315);1 i1 W0 I2 I4 n" r2 z4 N
settextstyle(20, 10, _T("楷体"));! c5 Y9 K4 d: h! _3 r _
rectangle(x,y,x+400,y+325);1 e2 m2 e9 B9 Q* ?
outtextxy(x+40,y+10,"CPU"); //画柱状图
4 {4 x" T* d& [" y( Routtextxy(x+45,y+10+100,"IO");9 W( K7 Z8 q: d; r+ g
outtextxy(x+40-15,y+10+200,"change");2 V0 u" Z, e4 e- ~0 K- Q
rectangle(x+35,y+30,x+75,y+110);
2 T4 ]6 r( b, ]+ H% V: ?8 V8 vrectangle(x+35,y+130,x+75,y+210);
8 P* l* i0 p1 }& nrectangle(x+35,y+230,x+75,y+310);
5 K4 B C2 }, Q+ U/ T+ `( Souttextxy(x+180,y+310,"TT");
5 c# n6 o! ]* _9 pt = (float)com;8 z) R7 G5 N6 a- \/ o! R) r
temp=(t/101)*80;
$ m( \6 _8 ?7 b; A1 q; ]fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
9 Y& \7 `8 ^! w4 p/ g# a% mt = (float)wai;
: @+ M) Y. Y/ t8 l0 v) G, Itemp=(t/101)*80;+ Z0 S& m1 q6 Y0 d4 I3 u( \: c
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
& `6 V8 y6 U/ `; A% It = (float)cha;; b/ Q+ y; w) Y2 n) [4 `
temp=(t/101)*80;8 W2 r6 H) @5 U
fillrectangle(x+35,y+310-(int)temp,x+75,y+310); n% G+ k: z/ y& V# s7 J2 z
for(i=0; i<3; i++) //画坐标 high=90,length=2505 H* J8 D4 K, T1 y, \: _% q# i
{
6 n/ s0 U- @ V2 ?( hline(x+100,y+110+100*i,x+350,y+110+100*i);. Q8 S, }! D8 @- C( K7 R
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
3 ?! \+ }9 H6 `8 e: V- ?# H+ Aline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
& z# u# C) F. R: ^0 Z
1 ~- a( f8 V$ t: vline(x+100,y+110+100*i,x+100,y+20+100*i);
' ], u' m0 v$ ~line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);( ~ v) `. y0 }& F/ F* W1 h ?
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);! A/ z8 F" b2 X2 E# o5 w3 } I
for(j=0;j<num-1;j++)6 |) V2 j3 x9 V& j! o6 P2 _
{: v- |( R* {* J/ } a5 q
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]); f. [$ u: q/ b1 S) ^/ u/ S) r S
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);- N. P& e1 c2 X9 n: v5 a
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
. n: j% E4 Z9 W% L5 i}9 B. S8 B; \( C! N& i
}: ]) v& t$ ]$ D: W
}+ P0 `5 D3 i- Y
else if(FLAG_TT==1)
6 e! M! o1 \! k0 o$ g{6 n7 ^3 ?0 d, [8 Z, w+ j
x=0,y=0;' P" x9 X( y8 _6 I6 n" m
for(i=0; i<num; i++)
* ], Y8 k; ]0 D$ l{
, v3 l5 ~3 U0 t! U9 [* j$ ]8 {( Xt = (float)info[0];
1 N% {" |( a2 ~5 ]temp = (t/101)*180;- {& Y1 r3 e9 M9 _) ?- O
pos[0][0] = (10-num+i)*50+x+650;
# H2 h# W( h% D' {& \7 Apos[0][1] = y+210-(int)temp;
7 U4 D$ ^! x9 x' A$ N- y9 l' ]+ F) at = (float)info[1];
4 z. s( B! J$ }1 F+ Mtemp = (t/101)*180;. O. @! E; b, S
pos[1][0] = (10-num+i)*50+x+650;7 y4 r+ X) `7 U* o3 _( Y
pos[1][1] = y+420-(int)temp;$ [6 U H5 e# Z9 @% t8 m/ S" }
t = (float)info[2];
9 T7 d9 p% o( p( Ytemp = (float)(t/101)*180;7 u+ ?$ R6 E I/ P% o; T- u
pos[2][0] = (10-num+i)*50+x+650;
& _1 l: H K; s: }* Npos[2][1] = y+630-(int)temp;9 w% _, b1 i& j# J# H
}
* d5 t6 }2 |/ qclearrectangle(x,y,x+1200,y+650); Q- W3 k% C6 e- H
settextstyle(40, 20, _T("楷体"));
6 s. Z' k. }9 _# B5 i0 G8 v1 K: houttextxy(x+50,y+50,"TT");
0 Q5 O) O/ G3 iouttextxy(x+280,y+20,"CPU"); //画柱状图2 B5 p" _7 H# b9 y2 v- _
outtextxy(x+285,y+20+200,"IO");
C" u; Q7 p# S8 ^outtextxy(x+250,y+20+400,"change");
0 ]/ e# v- o, E( ]# a0 X' j2 ^rectangle(x+270,y+65,x+330,y+215);% a& N. Y( Z+ E$ g* [( J+ c
rectangle(x+270,y+265,x+330,y+415);
6 z# u4 ~8 Y* L9 _9 Prectangle(x+270,y+465,x+330,y+615);
, ~" F! V- R5 S; L- ^! ]: houttextxy(x+290,y+620,"TT");
* }' W# @# e/ f0 k% x9 |1 [4 p9 N3 Wt = (float)com;1 Y# [( e7 R( x a' C7 b
temp=(t/101)*150;
" l$ t# ~! X' V2 ?) Y1 T# E7 Cfillrectangle(x+270,y+215-(int)temp,x+330,y+215);6 {8 Q" S8 I# S: b
t = (float)wai;4 C& N* l8 G1 [) J M
temp=(t/101)*150;: Y( D1 ~" W! x; I+ o
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);6 i- _; n. P+ i3 S! o$ G
t = (float)cha;/ `7 X/ W8 b) |! o: u
temp=(t/101)*150;
; T K4 o' V7 ufillrectangle(x+270,y+615-(int)temp,x+330,y+615);
# M; H7 E$ j. k+ j/ |: [5 |. tfor(i=0; i<3; i++) //画坐标 high=90,length=250! l; N7 g4 O+ X0 l
{
* ]0 x. P" X' r" ?: ~% `: e4 Kline(x+650,y+210+210*i,x+1150,y+210+210*i);
; k1 s. ]: K( i+ G* q( w: Dline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);" G' k: B& g7 T w( b5 \. a
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
b" ], A: ~0 y5 @0 T
( G& o+ M. B5 ]) Sline(x+650,y+210+210*i,x+650,y+20+210*i);) y5 W+ B. E) j* _1 L# Q4 ]7 P+ g
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
* N& C' o) R1 g" ?0 |4 Nline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);/ I8 G/ ]) }# t. n1 R4 W, v
for(j=0;j<num-1;j++)
9 G! O7 Y3 Y8 H1 ^4 h: L" x( c6 G" ~{" K. n! U6 y- {
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
8 q( Z" u/ I! K6 \8 Iline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);4 d" ~, @6 S' \6 c
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
0 j5 G; L2 A# m. Z# A}
% F d8 R% _* j! {}
9 t, c( d" s) w W; D. ?}
. t. L( x$ \) S
( t; V P+ e) ~ J8 j S
% n/ R# c2 ? n' x- v( X3 breturn 0;- c, [+ d2 i; j& [7 c0 U* {( |
} I/ R ]/ [) y- p3 L+ f. i
int drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)
8 P. T& E f9 q H+ b{
! c$ P- X% U+ }1 Vstatic int info[11][3],num=0;
9 C, ~0 i& z$ O' q* Wint i=0,j=0,pos[10][3][2];. f0 E' T# v3 V2 B7 `: R" o
float temp,t;
/ l1 J! g$ f7 k/ b f ?info[num][0] = com;
* z! Y1 Q* V6 cinfo[num][1] = wai;2 Q) W7 e- `& Y* Q* O0 f% t
info[num++][2] = cha;& q& n' j/ Y; D( |' i
if(num>10) //存储10个点, u4 R5 _/ N |7 [
{
- g+ J% @( y$ mfor(i=0 ;i<10;i++)
: U! n& q( G* C, a{* G2 C9 W! @2 M6 G/ P
info[0] = info[i+1][0];
* q- V+ G8 I, y8 e) iinfo[1] = info[i+1][1];
7 P1 E! b! C! y; Y* oinfo[2] = info[i+1][2];
+ _6 n" | u) K5 }: W$ h7 U1 y}' k' O% a2 p. L" D4 f
num--;" O" A% l# u; {; g$ a# Z
}3 k" ?! L. g; D8 h
if(FLAG_show==0)
' e% T, M6 d9 }) w2 S# O }; y/ C) ereturn 0;0 `+ D" r) c+ O
for(i=0; i<num; i++)
2 ?; V6 g# r( M Q$ E/ N2 z/ d{
2 S" m% A: E. _0 E6 At = (float)info[0];
# A0 ?0 J/ _" i7 C" ttemp = (t/101)*90;
M# v8 N9 B$ Y7 v6 @ Qpos[0][0] = (10-num+i)*25+x+100;! K1 Y% i; ?: w I# _. F3 |
pos[0][1] = y+110-(int)temp;
& W. G z- Z0 Q; ^6 R! ct = (float)info[1];7 z2 o l+ C; g1 i$ x( G- m
temp = (t/101)*90;7 j1 `& n, r+ h" y. e# B
pos[1][0] = (10-num+i)*25+x+100;
, m0 [* n$ E- K# P5 g: V4 ^0 Apos[1][1] = y+210-(int)temp;4 G( U3 ~! J: D% ~
t = (float)info[2];6 y# L, f/ e: c# r
temp = (float)(t/101)*90;# E0 S5 n- G/ f. H1 I8 g5 @
pos[2][0] = (10-num+i)*25+x+100;
: ^' E1 W0 i4 t: F6 Qpos[2][1] = y+310-(int)temp;
0 z. Q6 w2 Z8 H# ]% M T6 {" W4 Q}
" \0 |4 p; ~( b: L3 Nif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)3 n$ a* l7 ]. Z
{
- z' b1 ^1 z! X# Z* Jclearrectangle(x,y,x+400,y+315);4 s1 W7 B# u8 a1 F; k* L( D9 p* O
settextstyle(20, 10, _T("楷体"));. i# |1 }6 j9 G `1 }( L
rectangle(x,y,x+400,y+325);1 K- @ @3 u" d4 J' u; V0 a
outtextxy(x+40,y+10,"CPU"); //画柱状图" T! X2 v. R) ?4 z
outtextxy(x+45,y+10+100,"IO");. y& P- {, k) E( {
outtextxy(x+40-15,y+10+200,"change");9 |: T3 k. R1 O+ s, ^9 I) S
rectangle(x+35,y+30,x+75,y+110);
% h2 G, V# Z8 Y+ m |# W: H$ lrectangle(x+35,y+130,x+75,y+210);, I0 R- _1 ?/ Y: k: u( B8 a8 W% A
rectangle(x+35,y+230,x+75,y+310);. q2 }4 z( h3 Q
outtextxy(x+180,y+310,"PF");' }! ^! L' t8 d
t = (float)com;8 r/ @$ C* _( b4 J! P j1 w1 }
temp=(t/101)*80;
0 H6 _& z, n* qfillrectangle(x+35,y+110-(int)temp,x+75,y+110);
) d6 c6 Q5 d. G* nt = (float)wai;
% A3 E6 y- f+ j8 Z: ?! D" f( J* m7 V8 Ntemp=(t/101)*80;
& Z9 ?) F" J7 }5 M' m; Mfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
7 ?) M: o$ f7 p4 l4 \2 {. }: e) l3 Xt = (float)cha;
: T- B( ]& s6 Z) G7 P: Ctemp=(t/101)*80;
# [3 V8 u, S& k* dfillrectangle(x+35,y+310-(int)temp,x+75,y+310);* N: ^" T2 v. e, N& N( Z- [$ x
for(i=0; i<3; i++) //画坐标 high=90,length=250* Q8 ?+ c. `$ H' P6 ^6 [2 A8 p
{
& Y4 f# J, X3 Q" q/ gline(x+100,y+110+100*i,x+350,y+110+100*i);: Q1 O! v: D9 d0 t' G8 h5 w
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);( r8 Y: v, k7 y* V
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
) [% @4 q) F, h5 E& o7 `
3 I% s* @& ?' ^5 Z) O, Kline(x+100,y+110+100*i,x+100,y+20+100*i);" L7 C: J' d6 g9 X
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);: a0 R# h6 @5 G1 n" W4 \# P/ j; g
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);) ]) j: v4 B: h a
for(j=0;j<num-1;j++); L2 G# r% [/ F3 O. S
{
2 Z5 v" S% Z- s Z! Xline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);" O0 i. M; }. w/ g
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
+ ]0 \+ J4 [- I0 q; ~, c; Nline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); . F1 `( M5 B. h# v- @1 g2 @ w
}: k' T& E4 S) A {6 e% ^+ F
}
% ~+ y4 O2 N( x/ V7 g% }: ^}
6 C8 u. N; U n( t0 m8 xelse if(FLAG_PF==1)
6 ?( _0 f9 d! o/ u3 f{% U* F1 Z+ f- i3 L# y
x=0,y=0;( c5 F$ ?) L+ _$ t5 m! T
for(i=0; i<num; i++)( h# B* s2 A2 @* r3 v+ ^. t
{( `2 P# W. [/ V
t = (float)info[0];
) _% }7 l$ X, Z" x9 Y4 Ytemp = (t/101)*180;
$ w* b' A/ a% y* s7 |" v/ R$ Ppos[0][0] = (10-num+i)*50+x+650;2 H6 `" M6 v* e
pos[0][1] = y+210-(int)temp;
1 f: c3 y# S* n+ d$ Ht = (float)info[1];
8 Y" K7 _$ H! M8 e# x0 ytemp = (t/101)*180;" M) u5 P/ O% [8 z2 }, ]
pos[1][0] = (10-num+i)*50+x+650;" i3 b/ w( `: I& s9 i8 D! i6 v
pos[1][1] = y+420-(int)temp;( T+ z0 M* A5 {7 E
t = (float)info[2];
{1 k* E$ H" U, P* D1 ?temp = (float)(t/101)*180; `, j9 l; U8 L* Q3 S6 O
pos[2][0] = (10-num+i)*50+x+650;
2 ]0 l& b9 x4 E- N+ Epos[2][1] = y+630-(int)temp;
Q+ @# D& M" @}
4 ^3 z' ]8 I; K) |/ jclearrectangle(x,y,x+1200,y+650); T! V" k2 a8 w7 `
settextstyle(40, 20, _T("楷体"));
. n: k H; m: t( {4 c+ G3 u+ Couttextxy(x+50,y+50,"PF");' J( `. E7 M5 `7 j
outtextxy(x+280,y+20,"CPU"); //画柱状图" P8 _4 ~; x' o$ M. G, b( y
outtextxy(x+285,y+20+200,"IO");
! Q1 f4 D, g' f% zouttextxy(x+250,y+20+400,"change");
$ `6 k# ~- J3 p# ~. S/ D- S% \rectangle(x+270,y+65,x+330,y+215);
5 P4 @7 [& _2 a$ w) h# U% frectangle(x+270,y+265,x+330,y+415);6 ~" S2 f/ ^8 d. r( l
rectangle(x+270,y+465,x+330,y+615);; \" N* C4 k: n+ n, [2 G$ {) K( _; ~
outtextxy(x+290,y+620,"TT");
7 D s3 H/ ^' h4 \5 ct = (float)com;3 I; q' C6 I1 a2 Q. l5 Z4 I8 E3 g
temp=(t/101)*150;0 b) k! o' l- w, N6 s8 q. [/ u& N
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);% j' y) k- M2 v; k1 g+ T- k- l- }
t = (float)wai;1 a; C: ]$ {' Q+ G; C
temp=(t/101)*150;
. N% K/ \5 _, A/ C; U" \% Pfillrectangle(x+270,y+415-(int)temp,x+330,y+415);
! n2 @. w" A$ X2 n9 a$ `6 [t = (float)cha;
# g5 ~( Z* n& A8 ~temp=(t/101)*150;4 o2 M% ?9 P/ A
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);9 J/ @/ \% E9 b6 W' K
for(i=0; i<3; i++) //画坐标 high=90,length=250
6 u3 d1 {9 ^2 ?{
0 F# A% o; \, J, Vline(x+650,y+210+210*i,x+1150,y+210+210*i);' b2 P7 s) k8 l9 B% y( D
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
& e. l+ v( K* [0 i2 J3 u# W& qline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
0 d8 B. X' v% H% ^& r+ q4 a
+ H; H& f6 C+ D) Vline(x+650,y+210+210*i,x+650,y+20+210*i);
5 I0 n4 r$ }- e o4 }9 Jline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
^5 t5 z# L. R: ~line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);4 [2 }3 a5 m, X' }9 b
for(j=0;j<num-1;j++)& Q3 d( E4 ^0 S4 D) V8 U' E, O/ B" Q
{ \' F$ x* g' u# F& F
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);6 m. A$ E* l- o1 [$ L T1 c# k
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);* x+ [/ P8 F7 Z0 i, k
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
4 @- w! d; l$ f/ ~8 O8 ]) f}! S: N! E7 M' O0 M u
}
) Y' c6 b/ t. n5 o! l& N}
7 D9 s6 y2 {7 J, Oreturn 0;# R9 |/ _1 z. c4 V
}
" g# v$ y+ M5 y) F- k! V8 Xint drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)
0 t, H; p9 P* p6 i{
1 E5 q# y) V1 t) B( O+ L. C Hstatic int info[11][3],num=0;- r% ^. S8 I( X+ l7 e5 }$ C2 Z) R6 ?; A
int i=0,j=0,pos[10][3][2];) t% V. o8 U S. ^" i9 ?$ `+ R
float temp,t;
3 I) D7 l( f9 \, ~5 p6 r& D- |) ]) iinfo[num][0] = com;+ t& {2 s) j4 ?" }+ ~
info[num][1] = wai;5 }) a6 ~. Z t1 r7 R& L. Z5 A) F
info[num++][2] = cha;
7 e& C. m$ D1 U o% `. kif(num>10) //存储10个点/ b7 o# i. W, c7 }
{
6 i1 c" i( w& |3 q6 u( Vfor(i=0 ;i<10;i++)4 O a3 D. j: i A" B! g- M* J
{
% ]1 D2 L& c" Z9 x9 h9 R O/ ~$ ^0 yinfo[0] = info[i+1][0];: v+ C2 f2 Q, [; x; E j
info[1] = info[i+1][1];* K3 g7 w! I+ I3 u w. o9 [; D
info[2] = info[i+1][2];
* T; H8 f* o: |}8 T3 D* z/ A+ a5 f6 b+ U
num--;$ a8 A! c. Z! \. r5 q" @
}- F) r% @/ S/ |) P' _
if(FLAG_show==0). {4 T4 @2 c& X: I4 c3 {
return 0;
+ I# D' l( X: l# W5 S( S4 \for(i=0; i<num; i++)" s8 v7 X; w) U) o1 a1 s; s8 d; @
{$ l; [7 q' q: z# D
t = (float)info[0];) i4 D" [& v9 t5 c: m- T+ W/ c, D
temp = (t/101)*90;3 y. |: h; s) J. `
pos[0][0] = (10-num+i)*25+x+100;
, c: t) l; c8 Z" {" S( U g. apos[0][1] = y+110-(int)temp;. l# r6 y/ M* ~* [1 N4 D
t = (float)info[1];1 q# D/ K S( d2 Y4 S C
temp = (t/101)*90;/ K7 C' I% C' G. R7 I" R' N
pos[1][0] = (10-num+i)*25+x+100;+ P& v# v S3 B. s A2 l
pos[1][1] = y+210-(int)temp;
' L% W8 D" K2 It = (float)info[2];
, g. a! |8 v- xtemp = (float)(t/101)*90;
6 L* B% ]; {! G4 ~2 Ppos[2][0] = (10-num+i)*25+x+100; X8 u4 h1 n4 S; x+ v8 J8 \2 y
pos[2][1] = y+310-(int)temp;
5 j9 V& b8 v" J, E5 u9 j' ?}
- p% d) V0 ], ^ e5 d% c8 qif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)( f& a. ^$ V, O+ O7 ~$ S3 a
{
( l! j( S. {. {& W) L5 R3 dclearrectangle(x,y,x+400,y+315);& s# S& y* O( T
settextstyle(20, 10, _T("楷体"));
5 {: ?" U* z' M3 A; Q4 Qrectangle(x,y,x+400,y+325);
; e2 x: B+ y/ ~- P; M1 Q# Souttextxy(x+40,y+10,"CPU"); //画柱状图
- p; k! |5 d( ]3 s2 Douttextxy(x+45,y+10+100,"IO");, w) Q+ {/ P7 E$ \
outtextxy(x+40-15,y+10+200,"change");/ ^7 W* R" g- ]# Q
rectangle(x+35,y+30,x+75,y+110);
3 T% J+ p, V' H6 D' krectangle(x+35,y+130,x+75,y+210);
/ v0 u+ {( o/ ^4 ?rectangle(x+35,y+230,x+75,y+310);
# Y; \1 ^ n3 Souttextxy(x+180,y+310,"SJF");
+ S+ Z7 V) M9 Ct = (float)com;
9 F" \, K; a' E" i0 P1 i0 |8 O/ Ptemp=(t/101)*80;
7 g) U" @3 n2 w3 K E5 l0 Q/ q" \5 ~. dfillrectangle(x+35,y+110-(int)temp,x+75,y+110);
$ W% l& X- o9 E4 Pt = (float)wai;3 M+ G5 l; t3 @% B3 t- I
temp=(t/101)*80;, `9 `0 F4 p Q8 k6 o. Z- V, ^
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);# S. I& y0 Z' @+ a. r$ H) p
t = (float)cha;$ x/ |* ]5 Z- A. [0 y D
temp=(t/101)*80;- ~& Y, u+ f# d- Z1 O3 E
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);* h0 x6 @+ X4 P$ e! P$ A
for(i=0; i<3; i++) //画坐标 high=90,length=250) a: Q( J6 i) a: \ g* ?: d! F$ k; p
{* F# J- ]% m1 |7 r
line(x+100,y+110+100*i,x+350,y+110+100*i);
! e7 R3 `7 X% Bline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);3 g( Q5 Y% \0 g% }% C0 W' U
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
; X4 I4 c$ D5 I5 V/ g( D$ T, F) i! o% E# P5 G1 p S- C, z
line(x+100,y+110+100*i,x+100,y+20+100*i);
3 m' Q& V4 K9 dline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
. K% c" h3 l5 @' K( ?5 Uline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
# C. [3 v! w' v0 _! Dfor(j=0;j<num-1;j++)
) b c: }; ~2 c. X- y{; e' j3 [% L0 o7 \- {& C
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
# m4 r% \4 c7 d% ]- vline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);* h7 [% l0 b0 z6 |. v
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
7 Y& u$ ]2 A4 q}6 J! |- h8 ?0 f# s" \
}
/ c5 B; ?" q; C+ Q3 d}
/ E& C Q2 j+ U% kelse if(FLAG_SJF==1)0 H/ F0 [6 R0 B& _ k, ?9 X
{
% x! M; B$ Q3 v( tx=0,y=0;
. ?6 Q5 S1 }. }9 lfor(i=0; i<num; i++)
/ y% ~! G" d1 R, e8 w3 q6 A{
8 c* C( ]. W8 z6 Q+ pt = (float)info[0];: z- K% h, q( F \5 l
temp = (t/101)*180;
! ]$ a8 R; |: i( Jpos[0][0] = (10-num+i)*50+x+650;) |! ~. E8 o+ C; s
pos[0][1] = y+210-(int)temp;
0 l7 `9 X: o* c7 Qt = (float)info[1];8 M3 B, X9 Q6 C* Y/ w8 {$ Z f
temp = (t/101)*180;5 G& u' y$ F1 b9 |, }
pos[1][0] = (10-num+i)*50+x+650;
6 ]) ]2 n: B6 M/ d7 R% r) vpos[1][1] = y+420-(int)temp;
* o9 H$ t5 K& Nt = (float)info[2];
8 e$ ]/ c4 e, M, L# Ftemp = (float)(t/101)*180;
( S6 m7 _/ W1 j& P$ f/ w$ ^8 tpos[2][0] = (10-num+i)*50+x+650;, S1 o' q, g$ r [! A* t* C
pos[2][1] = y+630-(int)temp;
$ K6 W( [: Q( x0 p4 D+ }+ v}8 a E1 Z% F& T
clearrectangle(x,y,x+1200,y+650);
1 h1 p/ n$ ^9 E3 q/ Vsettextstyle(40, 20, _T("楷体"));6 p6 H+ G+ H1 o3 \
outtextxy(x+50,y+50,"SJF");
% k1 s# Y0 l! d: K2 p+ @7 W* oouttextxy(x+280,y+20,"CPU"); //画柱状图
) z0 h( g3 j9 F6 z) o kouttextxy(x+285,y+20+200,"IO");
0 ~0 L0 a9 a1 a M v! n) Oouttextxy(x+250,y+20+400,"change");
" k6 {5 i6 x* {! ^ krectangle(x+270,y+65,x+330,y+215);
2 I. `9 i; v% Hrectangle(x+270,y+265,x+330,y+415);
; E0 e6 [$ K. F8 X/ f" V6 O/ brectangle(x+270,y+465,x+330,y+615);- t1 @5 O! D# h. ]' U; A
outtextxy(x+290,y+620,"TT");6 G8 ^- a6 t# n6 y- Q% H2 j
t = (float)com;
7 Z3 C% h: c1 c- t- r# b! u) ntemp=(t/101)*150;5 p' f% x/ @9 n1 c6 t9 f0 m4 Y6 z
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
* |. a3 O* {4 \. ~7 M6 Rt = (float)wai;
N6 c2 A: d+ }5 @temp=(t/101)*150;/ V6 s4 `" y/ u# r4 M
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
# Z' o6 l: B6 Y' @t = (float)cha;
! ~) ]* Z! k5 \2 ?! p3 A- S$ Qtemp=(t/101)*150;
9 Q5 U, p" E3 {" I0 P5 n jfillrectangle(x+270,y+615-(int)temp,x+330,y+615);
- \: u& j% [* h" U0 @for(i=0; i<3; i++) //画坐标 high=90,length=250
2 _% R; z7 ?1 ~% f1 w# G{# r" ]; M' j8 q# [* i
line(x+650,y+210+210*i,x+1150,y+210+210*i);7 {* b4 R4 O6 p/ l
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);3 L0 O% y: z: {% l$ J. M8 p* a
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);+ N: t r, [ j2 O" ^* a
6 G5 l1 J( H2 ?1 h7 i+ C* g
line(x+650,y+210+210*i,x+650,y+20+210*i);8 m- l5 S/ e U! {5 P E) q! a
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
; M/ K: p& n" \# i$ Q# oline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);/ N( Z% V1 q* v! Q5 S3 c9 B5 M) S" \
for(j=0;j<num-1;j++): [ m' y# N6 M" u3 @* J. Q
{
/ ~8 w4 B" S1 cline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
! O5 L; w7 e$ ~ Tline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
- e/ k% ?, u9 u; I9 D: u% V* d9 Kline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); # Q' w1 c" v2 h T6 f. t* k
}* f9 N- i/ @$ y
}& N/ {- {. v9 `$ u l
}
- `7 y6 g d) e/ B1 `/ g- |, _0 Breturn 0;5 Q+ R9 R, _7 U1 a$ W4 S
}# `+ b- g6 z I; m' }
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)( n4 c: @$ g/ e9 {/ j- M. V3 ]
{
+ r; U& D, ]3 o" A$ I1 C( Vstatic int compute=0,waitio=0,change=0;9 O$ ]; q9 R6 T2 A |7 J
static int computeLast=0,waitioLast=0,changeLast=0;' u& O! ` ^/ X/ S2 j
int i=0;" n1 X3 S- L/ [0 H
if(draw==1)1 X9 w3 X+ { q6 u6 g0 t F
{
% K: i$ e% \1 `//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);! A' N! G4 _" A: E5 p6 A
drawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);( U9 U. i! j; q3 B- L, w
computeLast=compute;
% G! q, D8 r A' |1 UwaitioLast=waitio;* k5 D, z0 f) G* \) n
changeLast=change;
3 K/ m& R% g6 Y: l9 k6 ?9 |}
/ e) L, I. B; Q- i, D6 A. Lif((* memory).p[0].flag==ready)0 J2 f. P( K! v' J' Q" y) n
(* memory).p[0].flag=computing;
' m s! D8 ] H: Xif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)$ x( H+ Y0 k$ n! `
{
! o6 N& B0 A6 ~: y- pi=(*memory).p[0].computeNum;; l; a$ X4 W. F& e, q/ ~( i% U
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed% z" {7 N1 p+ a J+ J+ E
{5 g* ]/ G' z" N6 q& e
(*memory).p[0].flag=IO_waiting;
; ~. {9 [' d6 k1 C% J {, D(*memory).p[0].computeNum--;& H- C% l) N( g! W$ N
change += exchange_IO_Compute;
$ x7 W/ {+ S; g6 {+ Vcompute++;
" h9 N4 U% G; z8 ~( {1 o5 Y8 W) g}
* j, J+ a1 m! \2 }& d$ lelse2 k: e1 T5 ]- w6 D, n
{+ [. z7 }2 a( u
compute++;
! u+ `" s6 q! b}
. @, Z) \( J' B6 ^' ?( p) p}
) F9 ?2 ~' {: p r6 Jelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)# S1 d: I0 G" k3 w6 y; C8 f
{
$ ?* `: ]8 \% g8 B8 \- ^5 {/ ^* Z3 @4 G( T* q
i=(*memory).p[0].ioNum;
8 R6 B, `% D4 e+ Eif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
" X- a& @5 b4 D M4 Z& J{
- I) ]1 \% W3 P- e2 q2 w$ a(*memory).p[0].flag=computing;
# y2 w0 S3 r$ U, J+ ?3 C(*memory).p[0].ioNum--;
" n3 j' |# Z4 ?" A$ r9 [5 b% V& A$ Nchange += exchange_IO_Compute;
0 j" g& Y5 ^5 h5 |! Xwaitio++;8 _2 _. ]4 ^- e& @+ P' q6 I% |
}
, n/ u7 Q4 ~! H/ g, c# n9 ^else7 o+ E8 p9 p# @, A9 H, |
{
5 u8 E+ O! N' G* b2 K7 gwaitio++;
7 g" r% F o5 u6 \6 u}/ Q4 ~8 D! Z" z
}
, c/ m- o" e/ `else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)! d. U- `' {+ n4 a5 d; d2 u
{
. O3 ~: p! o( U1 K- y5 S2 ]% j(* memory).p[0].flag=IO_waiting;$ o$ G/ r( i9 K; j/ c
change += exchange_IO_Compute;. s7 O% j, D" b7 v- {% G4 L' z$ j# p6 E
}
9 `2 F) P( u* z6 s% }" zelse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)$ R- c6 z. w2 B; I
{1 C, f% V! e6 K2 _0 k
(* memory).p[0].flag=computing;
. S( f& i! A* X9 E$ a) b) cchange += exchange_IO_Compute;
: Q- Y/ T$ i/ C}+ h8 A( Z1 u9 v6 ^1 Y& u; A4 z5 t( o
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
+ l) o$ r8 r1 o% B) y4 T) k0 O{
. O* P2 a7 @) l( G4 O, B, W(*save) = (PCI*)malloc(sizeof(PCI));; L+ @+ {0 W, L
(*save)->next = NULL;
. }. W2 n/ ^% m# M2 n(*save)->processID = (*memory).p[0].processID;
% i- f Y3 ~" X3 ?' R(*save)->comeingTime = (*memory).p[0].produceTime;9 Q& o8 J9 i) U% G( k% Y
(*save)->askMemory = (*memory).p[0].askMemory;4 o9 E3 ?2 {+ E3 O6 W S
(*save)->compute = compute;
6 I3 L# v1 u1 i(*save)->waitio = waitio;
$ |8 c% ]3 G3 ^; l( T( J(*save)->exchange = change;# B6 h7 B J& b4 u% F5 f
(*save)->completedTime = systemClock;
, S6 u) u! }' z' [(*save)->runningTime = (*memory).p[0].runningTime;+ p, x+ F% q6 F o8 F, Q
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;
2 A5 q; }, y0 {" D# E! i. n# K$ Q/ W) Vcompute=waitio=change=0;5 |/ f9 n g$ _7 y
computeLast=waitioLast=changeLast=0;
, e# c* `! f, L& s9 ZHigh_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);& N0 `0 B; U4 t) p1 h; \& D( `
change += exchange_process; }& n9 P1 s6 q! W7 H$ X! Q9 \
return task_completed;5 ~7 d% ?! W' b7 ~2 j
}, M3 f" F9 j- v6 }# [
else! t1 H6 k+ w8 A* V( o% t; l
return task_not_completed;
0 L! C/ O6 ~4 T, M" t}
% P& J# |" z3 K( hint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)$ l T! l: |& n7 F% b: c" U) Y
{
2 z' T5 C3 q. J/ G) u* }& n. `2 Gstatic int waitTime[initProcessNum],i=0,j=0;, ^) I" W: G" h! E3 K; g3 R
static double HR_ratio[initProcessNum];) L3 ]1 L/ e/ n% k
if(flag==0) //初始化数组
3 c4 {3 M. b3 U4 g& r# k{, O1 U. I7 w0 L! D
for(i=0; i<initProcessNum; i++)) J+ a) M& I" d
{, X B: M8 j0 }$ C! a
waitTime=0;
2 x o' M5 Q: Z" O" _HR_ratio=1;
5 r& \5 y; W V6 x9 M7 | I- a}
1 [' y; a! d7 n8 Z% f M5 P}$ r+ Z7 T1 u4 v* u7 a) k$ f# @& o
for(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比
B$ [: @' m& a+ X% O2 P{7 f$ @. Q. E B. d! t3 _
waitTime++;0 ?- d- u$ G: {. P- U7 R" |
HR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);9 N2 s2 ?! o7 u6 z+ q* {: j- U" y
if(HR_ratio > HR_ratio[j])
" @6 @# [! Z+ p2 l- t$ |3 g' n bj = i;+ y4 d. j% N5 w6 l s5 I+ w3 N
}- Q7 G E/ k5 b7 Z% f, h
if(dispatch==1) //需要调度一个进程到内存中执行; R1 u8 Z+ e2 Q) l+ C
{
" u: m- J8 V9 U) |% q$ ?if((*storage).p[j].askMemory < *spareMemory)
4 P# i! F+ B5 [3 r1 F. o+ Q{
2 L( o9 v/ t; g K% `( t' w(*memory).p[0].askMemory = (*storage).p[j].askMemory;3 y/ t6 P) l, y7 @4 H, m
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
( [5 {, A0 q" X) m/ }% Q(*memory).p[0].computeNum = (*storage).p[j].computeNum;
4 V6 N( }2 v( Q4 B2 z$ V(*memory).p[0].ioNum = (*storage).p[j].ioNum;
9 j$ K/ i+ e/ t) H* s3 @(*memory).p[0].processID = (*storage).p[j].processID;
- ~; D( y- e) j% c) d(*memory).p[0].flag = (*storage).p[j].flag;/ L: o; D' q3 O: q
(*memory).p[0].ioTime = (*storage).p[j].ioTime;7 e! ]( ] _* U, \# y" A
(*memory).p[0].computeTime = (*storage).p[j].computeTime;
. ^! A% x& |! E) J8 A8 V g8 f(*memory).p[0].runningTime = systemClock;( \0 d+ q6 }/ O# {
(*memory).p[0].produceTime = (*storage).p[j].produceTime;$ I+ Z2 ?& m* y w+ a& ~
for(i=0; i<(*memory).p[0].ioNum; i++)1 U4 r* c$ x# u% Q/ ~1 I7 K' U2 B9 D
(*memory).p[0].ioClock = (*storage).p[j].ioClock;
8 H& N6 N. n+ A1 \3 c. h% Cfor(i=0; i<(*memory).p[0].computeNum; i++)& b1 o/ Q4 n3 M2 k) \; K, l
(*memory).p[0].computeClock = (*storage).p[j].computeClock;+ g& K7 W) S# x b8 N9 M% x5 e
(*memory).proNum=1;
& e; P/ }% v" G) W2 }*spareMemory = *spareMemory - (*memory).p[j].askMemory;
! H" J( \! L% `0 {1 jproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程2 W% w, n5 ]3 x$ b9 G' Q3 I7 e ~6 n. y
(*storage).p[j].produceTime = systemClock;1 Z, W/ L4 J! Q% v" A/ j. s
MAX_COMING_TIME = (*storage).p[j].comeingTime;
) [% O$ B$ O; n4 ?4 q9 AwaitTime[j] = 0;7 U4 r+ M$ t% C+ |+ s
HR_ratio[j] = 1;
2 B4 }# f) r" b}, X Z( V. Y9 ?9 N6 S
else
# U F* m" p5 G{
; r. ?' d6 |) o# j- A, Rprintf("A process ask for a memory overed the system capacity\n ");
s. A. V4 x% T- {2 a% I% zexit(1);
9 u5 a( O$ A4 {5 c* J}) g& U2 |# M" E5 K; x. n
}, ^' n2 ^8 h3 y v: E+ `) P: v A( o
return 0;
# X+ u" E; a- Y6 l" s! d}
: Y3 p8 e" F+ m( p4 K4 g) f' B1 aint PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)7 q- `0 u7 M; y) ?* Y( |) X; s+ M
{; B4 K/ {4 h% u4 q
static int compute=0,waitio=0,change=0;
; X* O& I9 U& Mstatic int computeLast=0,waitioLast=0,changeLast=0;$ |6 B5 ~; k8 K) }) Q! N
int i=0;
# g* ~% \% o! v5 E" K4 N+ ^if(draw==1)
6 U* _& W3 X; u4 k; f{
8 S7 q1 n, e6 A# B//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);2 K# F! j8 M, J# E
drawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
$ O$ h( M4 p7 ]4 a) y% \. J2 w; o. {2 z: G. D1 U: A0 ]% \1 D
4 [/ ]3 Z' r, g/ G. y; a
computeLast=compute;
, C8 m# R" N; C6 MwaitioLast=waitio;8 v" s$ v6 p6 i) K$ I
changeLast=change;
3 U* S" u, k% n# F}
0 O+ _7 y9 ^" }8 b. f! ?( bif((* memory).p[0].flag==ready)
* @2 n$ q4 P) K l0 V4 C* [(* memory).p[0].flag=computing;8 c6 l. P) z$ D8 ` m
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
) w0 m; p# B$ i" r. o) v3 r1 r! q{' R# E' I* S1 Y, B. ~ x, E
i=(*memory).p[0].computeNum;7 f% l, f* [+ V; y9 E7 _
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
* \6 {/ V s/ L' c) U{* O8 _4 l/ W+ j5 J9 q
(*memory).p[0].flag=IO_waiting;
3 q7 ?5 B9 O- ^1 j7 W(*memory).p[0].computeNum--;
% f7 h5 W, `+ f/ y2 Q8 G3 f+ L* r. Pchange += exchange_IO_Compute;
$ ~0 l8 L% e2 t( }1 m! ]& C' N, Kcompute++;; e$ `) n# o! Z$ Q, q7 K6 p J
}
& h4 z8 g! {+ f, J1 b, T" R- Kelse
5 Y" H8 [3 v: v* M! c. G{
5 g6 t$ w9 z o2 u* ^3 ycompute++;: O5 E1 o, b K( u8 \3 g+ ^
}% Z( F a* h9 [4 i
}
6 ]1 G; b; E/ c5 T% F8 Ielse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)3 o- U0 V+ K7 m0 @ v: D
{3 T# l) a7 M- R( T |- |1 q' d
2 I# n1 f' T2 \8 c& Yi=(*memory).p[0].ioNum;2 I! Y2 r: }/ R* W0 G
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
* v/ B! X2 I2 P7 l& Q# T5 k{5 {% n! }' P, a$ L. P( _; ]* f
(*memory).p[0].flag=computing;0 g3 F+ O; W. [3 l1 A; Y
(*memory).p[0].ioNum--;) z: {, b2 ]' V' `& C
change += exchange_IO_Compute;1 t0 Z! U# m6 [
waitio++;
9 H7 T* F8 O" g1 A0 k9 y2 a7 {}
6 H! Z8 R: M, |+ T9 v) H1 velse
7 d+ H- |' k; _% |: V{
" {3 Y& z/ E% v0 `4 Y# Z/ |waitio++;
3 s) y8 u# q* E3 a! R3 v" R}" P2 r9 V& t K. E* p$ b% Z
}
7 O' u3 B# c6 M: G' `else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing) F$ `5 D2 M J- x- E
{" {/ O0 \1 ~4 Y$ m) l
(* memory).p[0].flag=IO_waiting;
3 h/ Q# U! E6 b7 @change += exchange_IO_Compute;6 _9 @( i( q9 k4 V; ~& B: E
}6 X+ x% P9 w! S( F1 ^( A
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
4 e. l, r; [6 J7 |{' q) Y4 c+ v5 D- M0 W
(* memory).p[0].flag=computing;
6 q6 f! Q, J1 B$ t* Gchange += exchange_IO_Compute;$ W4 x. T: i8 J+ }8 e& S& O
}
* j9 ~* N/ C, d$ Aif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成3 j8 s1 R8 K$ o' J, \) u# U
{
+ J$ K; C: t E! F% t4 F: S; |2 j% k(*save) = (PCI*)malloc(sizeof(PCI));
0 t3 e! R3 ^' a+ W5 [(*save)->next = NULL;2 T) w, R3 K! W( A ^$ E
(*save)->processID = (*memory).p[0].processID;0 l- D/ e6 K& g* J
(*save)->comeingTime = (*memory).p[0].produceTime;
$ V* @0 ~$ m$ G. I(*save)->askMemory = (*memory).p[0].askMemory;
v. D( \4 }+ y- N: R5 J(*save)->compute = compute;
! }* V+ r6 S! H5 e- ?& r: U(*save)->waitio = waitio;
7 E9 r1 C: z/ I) v(*save)->exchange = change;
5 t( j7 R6 R8 f2 m3 l! ~+ I# x(*save)->completedTime = systemClock;
* ^" `' L7 t" t6 t( |( c. c. e- J/ T(*save)->runningTime = (*memory).p[0].runningTime;! U4 A \4 X& ?# T: a/ O
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory; _8 P6 z$ E {/ l; u
compute=waitio=change=0;
1 x' B2 N. Q7 ?% e. AcomputeLast=waitioLast=changeLast=0;
9 }. f4 r) b; {% O wPriority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
6 \( x6 L% b M1 a, `' Ichange += exchange_process;7 V: T9 h* }6 r. Y( A( g; l4 ?( E
return task_completed;
) l; J% w ]+ u. u" d8 p}" a/ U! h9 C1 E& Z& j. v9 _, l6 Y: `
else6 U0 r# c Z7 W) u: N
return task_not_completed;5 K$ `3 l# ~' W- T3 F' x
}! [+ @9 Q2 V" R H
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
4 K, e) ~( U4 }1 R{
# F- B% q$ l; o8 R1 Aint priorityNum[initProcessNum],i=0,j=0;0 p2 S* I& g5 ?
double temp=0;
& d/ F" u3 s* xfor(i=0; i<(*storage).proNum; i++) // setting priority to each process
/ P5 W+ Q3 n: a. @( N# j{
J$ e i3 L2 F7 t7 R( `5 H3 @temp = (*storage).p.computeTime/(*storage).p.ioTime;
3 F7 C c( I( A) k# d0 U; ]" c" M3 Eif(temp > 0.8)
4 d. D a; o0 ]: M7 {+ u3 M9 \priorityNum = 6;
! X& d3 \ w+ _3 J" v4 V6 V8 v$ Pelse if(temp > 0.7)
, | b, I [3 C5 O7 p ~. j& fpriorityNum = 5;' t1 p9 v3 c0 p% L0 V
else if(temp > 0.6)5 X. B, D: p6 w8 b" A
priorityNum = 4;
6 L" O; x& B) R2 l, b5 a/ f3 L* Jelse if(temp > 0.5)
6 q! a) g( Y9 }8 L% h2 XpriorityNum = 3;
' w( L9 E; |1 }8 |. Gelse if(temp > 0.4)/ d2 J6 B# `4 {$ }( J
priorityNum = 2; R' l4 ]2 ^# e' _5 K# ]9 j
else8 L6 y+ o/ i( [0 }. c6 {& D
priorityNum = 1;. \- ~+ k% t. Z# G" U' k' _
if(priorityNum[j] < priorityNum)
$ T1 s7 t- l+ {' f7 z6 Jj = i;
* }1 T# j, w3 i P/ w2 [}
; C, d$ `3 o7 O0 Z8 Iif((*storage).p[j].askMemory < *spareMemory)5 g: M8 R# b; n' I- w& u8 Y
{
9 k _4 i+ }: T3 S4 q(*memory).p[0].askMemory = (*storage).p[j].askMemory;; C3 y# h! \0 l2 c2 {4 D) ]
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime; t. _( h$ ]( ^
(*memory).p[0].computeNum = (*storage).p[j].computeNum;
, R1 _; \$ x2 e. i(*memory).p[0].ioNum = (*storage).p[j].ioNum;
?( F1 R7 o* Q# F, G(*memory).p[0].processID = (*storage).p[j].processID;
5 `, f. y t8 V(*memory).p[0].flag = (*storage).p[j].flag;
; k8 V$ A$ L' Z/ Q q% m2 E& W(*memory).p[0].ioTime = (*storage).p[j].ioTime;2 ]1 }5 L l' W5 l# M
(*memory).p[0].computeTime = (*storage).p[j].computeTime;- v& F3 t* c2 I2 `9 K. a- u: U
(*memory).p[0].runningTime = systemClock;5 ?' T) Z: b# j1 J+ ~
(*memory).p[0].produceTime = (*storage).p[j].produceTime;7 x# F3 H9 d" P: ^. A& t
for(i=0; i<(*memory).p[0].ioNum; i++)
6 \: o {, l* Q3 l7 R(*memory).p[0].ioClock = (*storage).p[j].ioClock;
: j9 c" x7 S: c" h1 G8 I E6 @2 ffor(i=0; i<(*memory).p[0].computeNum; i++)! ?9 G; j3 u: l/ K9 q
(*memory).p[0].computeClock = (*storage).p[j].computeClock;
! Z$ W# U9 P/ c9 @- g(*memory).proNum=1;
# G) `0 d, r6 q$ ]: {0 G" p*spareMemory = *spareMemory - (*memory).p[j].askMemory;
0 m, X1 Q9 B) }7 |' ]! _% eproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
! D6 w0 m: S* ?" \: vMAX_COMING_TIME = (*storage).p[j].comeingTime;, y% M( E9 y, Z
}* o/ S! d* |- G8 I
else3 N% r: {3 \8 t
{/ e: o! v' D# L# |& x8 C
printf("A process ask for a memory overed the system capacity\n ");4 G5 w; |0 w- k: @5 M/ M L
exit(1);) h0 i6 K) D/ L \$ f$ A/ z9 `
}
$ \4 ]1 b# v% i0 |4 J8 A& `: y; [* |return 0;
8 `; V* v2 r! t! k}
9 h* F7 o8 }) U4 r- Y8 n; bint ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw) f2 L: }! B' b& R6 x, @
{2 @8 w [9 ]! T4 n( u
static int compute=0,waitio=0,change=0;
( X3 R* W- J) S7 p0 `static int computeLast=0,waitioLast=0,changeLast=0;
5 `6 G. a/ O5 x0 q/ H/ vint i=0;
2 t. y0 u" H' y, s/ U w" \if(draw==1)
4 {( y. H. \- X- f{
# v& g' r; C! N6 V0 K- c2 ]//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
; j9 B& ^; H3 rdrawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
5 e. ?0 |/ w5 b/ A6 x0 ?* Z
, y& ~/ }7 R9 O& p7 W+ g
' N& F P n8 C# z% P0 V qcomputeLast=compute;0 W" z. v5 \( P0 k
waitioLast=waitio;: G/ J, j7 X& A( z" E5 t
changeLast=change;
' Q) i5 ^- Z5 ^6 s" y& L}7 @0 i& l# w5 k+ w
if((* memory).p[0].flag==ready)
& t5 i, v* P& }(* memory).p[0].flag=computing;
' T% W- J) l Y4 R7 ?if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)9 d! L* [8 ^$ w' \9 k- l- A+ y6 M
{
; Q) Y6 p6 F( Q5 }% oi=(*memory).p[0].computeNum;% Y1 ~& K2 A) N5 ^ _2 F
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
! Z7 c7 Z* w; l0 Y. [5 P9 R{
# a/ p: o, T( ]& a(*memory).p[0].flag=IO_waiting;
0 n4 T( q( I* n5 A0 J- ~# W(*memory).p[0].computeNum--;
: K" L4 Y1 O, P$ _, D: f! s0 achange += exchange_IO_Compute;1 j* U. t2 a9 K
compute++;# u5 f4 K i* j7 k) l
}" ~! H! T& O2 p9 \
else
7 M" F" F- X. f6 o& E; n, s{
' d. S1 K8 b! B% H! B4 R( Ncompute++;# {$ E# s' w$ D0 j* E
} R7 I8 r) f k( G. k$ a
}
' L* K Y/ H: o$ h/ telse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)* ]$ z. ^+ E i# K5 L+ j- m4 H3 a
{
, s* B, @5 X. G3 r4 Z/ ~. k; j
: x7 u1 X9 u5 \& I: o! e+ Di=(*memory).p[0].ioNum;) N. p* n' C( v0 { n! m
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
5 S* I h8 L5 z7 t{& F6 ~2 ^, \ U6 B0 C
(*memory).p[0].flag=computing;
% ~% u. h! F8 p) B0 c(*memory).p[0].ioNum--;3 a! c8 n4 B2 c9 ^1 O
change += exchange_IO_Compute;
1 n1 d4 D( l& Q5 \waitio++;
( S$ j9 ~' n/ I. S ^7 a}
9 H3 H. M$ Y B: [4 x+ h" a$ Felse
0 ]' f! s8 t+ v" |* k{& k6 x) Y+ X j) O' q) a# ~6 C% V
waitio++;+ P7 t' y1 ?! E6 b k
}
9 r6 Z: I9 H j& p! E ?2 ]}
7 k4 _' t+ l% n" M. \else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
4 e9 ^6 e! R; Q3 l( T{' r3 p; @" a2 [( b) z1 d6 g8 R6 @
(* memory).p[0].flag=IO_waiting;
2 T7 q9 I3 v3 Fchange += exchange_IO_Compute;8 t0 C# ^9 v* `2 o
}
9 s$ h- j3 e# {/ E8 @* H0 E1 Telse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
8 G! _1 |/ q1 q" N& E1 G{
) K2 Z5 Q: d' C2 n. }(* memory).p[0].flag=computing;
+ m! M- z8 K4 Y: pchange += exchange_IO_Compute;
) Z4 V5 @& H0 O8 [* L7 {6 p, Y}+ p# c6 Z9 ^* ]# o( f0 V. z
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成; f2 Y, F, v% u5 ?' U
{, E& Z7 h' s5 }. v4 I: C1 j* y
(*save) = (PCI*)malloc(sizeof(PCI));, P- n7 L/ P: h/ Y
(*save)->next = NULL;
+ v; {8 Y! p- v, W9 |" s. ~0 S(*save)->processID = (*memory).p[0].processID;) u2 V% p7 L- s1 J O
(*save)->comeingTime = (*memory).p[0].produceTime;
/ Q+ Z0 p' b3 L5 m8 V6 |(*save)->askMemory = (*memory).p[0].askMemory;+ W, |6 X& B1 V7 g0 P
(*save)->compute = compute;/ p) r) ?1 j7 B/ u" |' k# k+ @
(*save)->waitio = waitio;& @ E- h7 T6 x9 D& E
(*save)->exchange = change;* r/ g4 e% ]6 Q* n, O
(*save)->completedTime = systemClock;
# Z- r* t: K" H/ x(*save)->runningTime = (*memory).p[0].runningTime;9 m. q" L. |! U/ c+ `
*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;$ ?( x# K+ I. c$ C; T
compute=waitio=change=0;
) B# I! I$ {; p" wcomputeLast=waitioLast=changeLast=0;
4 n6 _. w" o; c! _3 DSJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
' T7 G4 q8 U8 [% l- m3 ?change += exchange_process;1 T$ ^' p2 x+ V# y q3 g. C
return task_completed;
8 ?- ^& T; [; v B6 n}
/ q7 D" ^/ \1 G0 y4 O3 velse
' @* }0 G$ s1 U: y8 yreturn task_not_completed;
1 F5 |+ o9 [: p6 ^}
0 n0 M( w r% M \4 p$ o6 Oint SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)" O/ U+ V5 ^7 f$ G7 @
{
+ r3 c% t/ L# @2 b5 }" P" {$ [int i=0,j=0;& k. c3 `0 {5 _# A' w, ?
for(i=1; i<(*storage).proNum; i++)
9 t$ G1 c7 |! \( G{
) Z. ^2 \( `8 W/ c1 @- Wif(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))/ `. o. S5 a, j8 Y! [' Z6 c: H, F
j=i;& G. ]2 a0 R8 X1 y( L
}
E" j: I5 G- cif((*storage).p[j].askMemory > *spareMemory)
0 I# I% ~* W$ v$ F2 w0 u7 |9 M) G{/ N2 U+ t v1 P, l9 y) Z
printf("The memory asked is overflowed than the system memory.\n");
2 Y8 z! P; h) F# p* ? bexit(0);
7 i# F ?( e- K# \2 e/ W& N}
6 S. a, V) J: e+ jelse5 Z$ A* g* D( G5 y" j
{
) `7 @* {# h% k(*memory).p[0].askMemory = (*storage).p[j].askMemory;
5 d, a( o5 E* O(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
, a, {" G/ }. w6 \(*memory).p[0].computeNum = (*storage).p[j].computeNum;4 k2 N0 G& v( P
(*memory).p[0].ioNum = (*storage).p[j].ioNum;2 }+ L; k. w0 z8 R. N* {
(*memory).p[0].processID = (*storage).p[j].processID;
2 z* S4 M- b7 B; Q(*memory).p[0].flag = (*storage).p[j].flag;2 p6 {" }* d# u6 u- O# K+ r3 {4 q
(*memory).p[0].ioTime = (*storage).p[j].ioTime;' d2 z/ K3 @, f$ n
(*memory).p[0].computeTime = (*storage).p[j].computeTime;% S0 r2 E9 G. W4 i2 ]
(*memory).p[0].runningTime = systemClock;( p; m) [) M3 d! u2 O
(*memory).p[0].produceTime = (*storage).p[j].produceTime;
7 p8 }- o5 Z; ?for(i=0; i<(*memory).p[0].ioNum; i++)
5 [% f# G7 R; w7 O0 B1 o(*memory).p[0].ioClock = (*storage).p[j].ioClock;# J/ v5 R$ S( N4 H q# P
for(i=0; i<(*memory).p[0].computeNum; i++)
+ y7 K4 ]' B( P0 Y% J(*memory).p[0].computeClock = (*storage).p[j].computeClock;, }: t; P/ U9 O O0 |1 r* b
(*memory).proNum=1;% u, H" P# {: j8 f7 e- W0 n
*spareMemory = *spareMemory - (*memory).p[j].askMemory;/ J2 i8 ^* }2 U6 f! q
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程' @: [/ T2 H/ {. A1 I4 v5 A( D
MAX_COMING_TIME = (*storage).p[j].comeingTime;- W: r( z4 F& d: ^2 O _5 L" v
}$ _) K& N# z9 }
return 0;
( o8 O5 X" c; X2 e/ }4 p& h5 F) Y}
7 W7 P/ T: a5 X: i/ U" k$ uint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)3 {! ^ g& H" U
{
4 h. e, }3 W" Mstatic int compute=0,waitio=0,change=0,clockSegment=100,poi=0;5 ^$ ?8 P6 s6 {: m$ Y& c+ B# \# ~
static int computeLast=0,waitioLast=0,changeLast=0;
6 q8 J; G# F) W6 l6 A- Iint i=0,j=0,k=0;
& `1 d: V; r) m( Z8 Dif((*memory).proNum<=0)* b8 ?4 V2 y! u6 r
TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);6 B0 ~1 D# I4 i# q' z O
if(draw==1)% \* T8 X- {5 O
{: U8 E5 b7 h1 H) C* W, a! n
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);& U D' c* X; |3 ]1 }; Y" e- @) F
drawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);2 D {" A6 E! \' s" w
y4 Y: c, z' ^6 B) T
7 w: s9 q) j, e! ~" U
computeLast=compute;
$ {6 [) C8 O# r I3 i! WwaitioLast=waitio;
' N2 n- c& g+ l4 C; Q5 G4 QchangeLast=change;
& N( {8 u" W3 F$ \+ d6 Y1 |& g}
( p) d7 A; h. [$ l6 t0 uif(poi>=(* memory).proNum)
8 P$ K' w! K# T" d/ rpoi = 0;
3 Z( s5 N' T% b a+ rif((* memory).p[poi].flag==ready)8 n8 d/ o* q% M
(* memory).p[poi].flag=computing;
0 [. z$ l' `9 E; H0 R8 A6 \if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)
5 w, a0 |3 ?) J# y{
0 Q. G4 F$ _/ u7 Z. g2 Vi=(*memory).p[poi].computeNum;
; \/ e# O2 h) d$ i* oif(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed5 w0 q3 U+ r$ S0 c) U# m# y
{* ~/ ]: [+ @5 \% u5 N! i
(*memory).p[poi].flag=IO_waiting;3 s8 T, Q4 ?+ a) l& ]% X, a
(*memory).p[poi].computeNum--;: F. R% v+ @1 ^
change += exchange_IO_Compute;
1 c1 }- H( [) K+ G) R" Fcompute++;9 Y# y, E- z/ s% c9 Q: c$ z p
}
6 Z0 @9 R/ P: e' G# ^4 E/ }else
- o6 n) ]+ v1 W, r+ r+ F{
$ N- ~6 r7 }/ C7 Q* ?& Hcompute++;
+ X" D3 T$ A' o' c9 C0 R2 g}
3 p& U; G: y) h# [* }9 ^}, @9 j; c$ e. L/ v; p% [" L$ i0 I
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)
4 @8 G: g6 l+ s% e# d2 @! k{- ~% E" _2 R% w/ p) C1 b
. R" b+ P4 H. ]$ ui=(*memory).p[poi].ioNum;/ c9 L1 l$ U) T# O& [- x
if(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
% P) r$ a% w3 L( P- T( |{/ Q, t T& }) J
(*memory).p[poi].flag=computing;
( q' g9 @4 _1 Y6 [) e(*memory).p[poi].ioNum--;$ \& P! M J* W( R
change += exchange_IO_Compute;
- v4 {8 @; l0 V9 v; qwaitio++;! W+ O0 C& \ \
}
1 b5 P1 e; J4 Z0 ~2 q1 |else
2 G" |) \2 \4 B' }% @: r# ]{
( _4 }$ i+ Q' T" Vwaitio++;) w! G& g) ^. @) b! n2 D/ n4 D
}6 s7 A6 Q; L& l' w+ h
}
3 {" e. A9 _# helse if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing); Y3 h: y, H' h
{
K T) k+ u- n(* memory).p[poi].flag=IO_waiting;$ k5 a$ l1 b1 g; {8 E0 B. V! Z
change += exchange_IO_Compute;7 _1 J5 Z# P% c! q: x
}
3 R& L, r8 C) n2 e" O/ {else if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)! p+ G' c7 s& H; r7 h
{: M H& W: ] O# Z3 p: x, m
(* memory).p[poi].flag=computing;% }* T6 f0 Z1 D# A- `3 F/ t. O
change += exchange_IO_Compute;. {# V( ]' Z2 v0 |3 X: y$ j3 ~
}0 V0 n X( l; l- C
for(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进
0 I0 {3 ~- F I& f& O; I, d, t5 [) E{
8 }3 A) t; O/ k3 V+ H" ^if(i!=poi && (*memory).p.flag==IO_waiting)2 M& H) X4 ]# @" @9 o z: z3 Y/ q" Z
{
' H( C; D. c, G! s, L% ^j=(*memory).p.ioNum;/ s: J5 B4 q$ `$ ]% X' Q9 V8 h! w
if(j>0)
" c. x1 ^# M" P3 q. X5 b{" {9 ?3 Y3 T) w& d
if(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed7 d" p5 W9 `5 w2 u2 y1 O: ?& A
{
& T/ x- d" k4 y% l5 H. h& S5 t9 K% ?(*memory).p.flag=computing;
) y$ x+ s8 S2 i& k# H6 U0 T% D(*memory).p.ioNum--;
8 D5 [1 l& }. T; r- g( |change += exchange_IO_Compute;$ e$ y& j ~5 h, E$ p2 A, P. Q4 Y& g/ y
}' o/ P1 V( l6 B0 }, w& b+ m( n$ L
}. l0 V% m( L5 l5 }
}
& [! h+ x$ B+ C; v1 \- d. H}
$ F+ z/ J! |4 D' J5 [8 [for(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程
( m2 N8 J, Z9 [( q0 m# ]{
( K$ v# e `0 I- {$ R, I2 vif((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed
7 I' C% E3 p/ [$ ]{! P; d% ?1 x: `' g+ P- ]* K
(*save) = (PCI*)malloc(sizeof(PCI));2 b* n d5 f# n. U3 e0 ]' x! W$ h
(*save)->next = NULL;: M+ Q( ~0 {# i6 m6 ^% Y
(*save)->processID = (*memory).p.processID;
; d7 U3 H% Q0 F8 U4 N- }(*save)->comeingTime = (*memory).p.produceTime;
. j% g; C2 W! A* B* P% g1 K" y(*save)->askMemory = (*memory).p.askMemory;5 ` ?8 p; |$ }+ d( \0 F
(*save)->compute = compute;* i/ o9 h( n& ^5 C' \
(*save)->waitio = waitio;4 A9 R/ Y5 j4 s3 v6 N- I
(*save)->exchange = change;- T; c: j3 I( a$ o. {/ n" K* u
(*save)->completedTime = systemClock-(*save)->comeingTime;
& `- V) _6 c; a9 l; I% `(*save)->runningTime = (*memory).p.runningTime;
7 _. V; b- ~& t9 u$ e% I' H+ q(*save)->completedTime = systemClock;
& o" l1 W" h& n( k*spareMemory = *spareMemory + (*memory).p.askMemory;3 L. M3 ]7 Z/ ~3 M7 |+ S z: \1 m
compute=waitio=change=0;- r1 c/ T- L* E5 l! m; E
computeLast=waitioLast=changeLast=0;# l/ l0 P- W* s1 W
if(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入# n. d4 ?, t L
{
0 H% y6 e# I: Z5 [0 nif(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程4 g3 H$ H3 S! s0 T# D! A
{
' z- p+ Y: _+ {poi++;+ f( ?4 Y% ~3 e7 a% {
clockSegment=2000;
, `: u7 `2 L7 N}1 Z/ m# I( |% P) z- K
}2 ]9 D) s4 {4 O" i' h8 Y' V1 a
else //没有足够内存调入新进程$ F0 r2 h; Q- f
{
6 t4 J7 S3 j8 Z' j* X) `$ Nif(i < (*memory).proNum-1)
: r g2 f4 n: h- ^( S" O{8 N+ w) Y# l8 T1 d& u1 `8 e! s! M1 x; h
for(j=i; j+1<(*memory).proNum; j++)" @& P# j, b, A; k
{* V# {- ^5 v, ~: O3 P/ a* ~& Q$ z
(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;6 \/ k& Y* i' Z) a
(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;3 t% D3 ]; [8 P3 M H
(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;
& o$ B+ U5 X- [# w(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;+ q( ?* p# l5 ~
(*memory).p[j].processID = (*memory).p[j+1].processID;- |- J; ^1 G. U6 P, f6 o. s7 a E
(*memory).p[j].flag = (*memory).p[j+1].flag;
- ?7 N! S' {0 d* x& S D(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;; n7 H- \, k8 b! j
(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;
) O+ ^; P- @2 E( P; Y; v(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;6 f# {0 a% w. ~. K4 }
(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;& o" I! v$ X7 ~3 W1 n8 a, L: u4 A
(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;0 y8 u0 l. j% ?7 W1 X
for(k=0; k<(*memory).p[j].computeNum; k++)- _: T' j) e3 h; w
(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];
3 z. ~& H# I: G: N( Tfor(k=0; k<(*memory).p[j].ioNum; k++)
8 R% K4 E5 V$ ~5 }5 ~# R& C, K(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];
0 s& w! I3 O2 I8 ]}. p) G0 s6 {/ k
if(i<poi)
$ ?& o' O' \: T6 r* Vpoi--;, |9 X& | |8 M- c6 v7 O
else if(i==poi)
: w+ Y6 a& v- x8 L/ ?clockSegment=2000;
, A' ^/ Y3 s/ W; M* j" U) C5 k}
( G$ e; s2 f6 u$ ~8 {" w! ui--;9 V/ ~& s8 I( v3 w, ~& ?
(*memory).proNum--;, ~6 u% ^ j v b1 ^) F: c
}
r) q, k+ l0 Q a9 ]return task_completed;
( w$ c/ k- {( b# u6 K/ L2 N}
* Z+ x) l8 Z, k8 M}
- B& j" q+ p- |# q: T) T--clockSegment;' t8 }3 k1 H4 {
if(clockSegment<=0)( I) P( Q9 F0 j9 I6 R/ z8 }
{) N7 s" i+ r3 `$ u% Y3 `3 L
poi=poi+1;* w/ \ z5 c! r0 y
if(poi>=(*memory).proNum)7 C' \# F9 l: ~7 Z! G5 g. z6 X; j# X
poi=0;
# ~) t7 @$ p' |. Q6 |$ P' G: G0 B7 IclockSegment=100;2 \0 |0 ~- Y$ \1 i
}5 \* Z3 \. d$ w! t/ M
return task_not_completed;
) T6 [- G) j6 i+ @# j$ ]! E}: Y5 m; z( H" }1 B! M( b3 Z# I
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)' B0 @6 e( j. o+ C
{
) Q- h1 f5 c( o1 W. Z7 {int i=0,j=0,k=0,flag=0,translation=0;
+ l: T7 P5 f7 `2 Xfor(i=0; i<(*storage).proNum; i++)- B9 T/ |) t$ H2 I6 v
{
% U$ _1 Z9 {9 U2 ^if((*storage).p.comeingTime>MAX_COMING_TIME)
) T! R3 \/ T7 F6 n. @3 E# c+ lMAX_COMING_TIME = (*storage).p.comeingTime;+ T; c! h9 z0 y* K9 v
}3 Q+ g) c3 l, [3 l/ Q7 P& f
if(pos>=0)* w( t* l& U$ s- A
{
" J; t6 t; z/ J/ n7 @' l% \for(i=0; i<(*storage).proNum; i++)/ M$ ?% H, s6 G
{. X% `5 k) f- X# d! }1 y; M$ s
if((*storage).p.askMemory <= *spareMemory)
6 B w2 p: e6 j+ g6 H N{0 P% x3 ^8 ]* o5 E& C" v
j=pos;
; Y; l* j+ @& N \0 \(*memory).p[j].askMemory = (*storage).p.askMemory;
* x( P. L7 A0 u! R: a(*memory).p[j].comeingTime = (*storage).p.comeingTime;
: ] k6 e6 m4 h( r7 ~* h(*memory).p[j].computeNum = (*storage).p.computeNum;
) I2 T* Y# D7 N Q- X8 e(*memory).p[j].ioNum = (*storage).p.ioNum;
1 j0 m: U0 P1 S, I9 h* C(*memory).p[j].processID = (*storage).p.processID;
1 y$ |3 @# M' A! s1 w- ^( P; D(*memory).p[j].flag = (*storage).p.flag;5 l: x# l" L5 y# }) U
(*memory).p[j].ioTime = (*storage).p.ioTime;1 s5 P% s3 v+ e
(*memory).p[j].computeTime = (*storage).p.computeTime;( Q4 @; f1 Q# p# v" b
(*memory).p[j].runningTime = systemClock;) \* h0 B1 s3 D5 H8 i5 I5 p' n
(*memory).p[j].produceTime = (*storage).p.produceTime;
6 N2 ~& g: t% Kfor(k=0; k<(*memory).p[j].ioNum; k++)6 q- }# c6 n; {
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
: u$ {6 \' q4 h) U2 t2 ]) ~for(k=0; k<(*memory).p[j].computeNum; k++); A+ | ]7 Q1 `2 |8 t
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
1 X8 E3 O/ U: u( a( M# y*spareMemory = *spareMemory - (*memory).p[j].askMemory;( J& d# B- t: C/ l
produce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程, e5 B5 i$ e' @6 S% {6 J" a9 S
MAX_COMING_TIME = (*storage).p.comeingTime;
8 s! s* z2 L$ M# \" Q4 gtranslation=1;
, B7 B3 c8 h8 Y c) A5 |break;5 x% {9 C, a3 Y7 R
}2 \# f2 F% h/ N1 c$ H9 B) Y& Y- \+ O
}
- Y& v7 }+ L1 I# P. w2 A}# W2 U2 Q6 ^ H
else) g5 F7 D- k* S/ e
{
7 W7 f) O' X* V Ywhile(1)7 X/ m* F2 i+ F
{7 A9 e; P$ y. c1 B3 P7 l
flag=0;' W7 e: R/ S9 A& k) ~. e
for(i=0; i<(*storage).proNum; i++)
; Y: p9 h; N1 ?" a* T" Z6 V9 x{
2 s2 b0 W: W" m& i4 R' t8 s) }if((*storage).p.askMemory <= *spareMemory)
: T( d1 }7 D+ j# a/ L4 i{* ?+ H7 e: F: U, C2 ^: {
j=(*memory).proNum;
, ]3 l5 L; f& k9 N' H& m(*memory).p[j].askMemory = (*storage).p.askMemory; |& m# M3 f$ I9 r% b2 M0 L
(*memory).p[j].comeingTime = (*storage).p.comeingTime;# J6 v1 G8 L7 M+ l+ L
(*memory).p[j].computeNum = (*storage).p.computeNum;) I. S4 R2 h" x# Z
(*memory).p[j].ioNum = (*storage).p.ioNum;
1 L, ?4 i0 q& L( G(*memory).p[j].processID = (*storage).p.processID;) w7 K- e2 I3 [1 e: c
(*memory).p[j].flag = (*storage).p.flag;3 b1 h: R) ]6 H
(*memory).p[j].ioTime = (*storage).p.ioTime;
! c+ p2 G( p+ ]( E" }; Z(*memory).p[j].computeTime = (*storage).p.computeTime;
1 ^4 P) O) b8 U ?! |(*memory).p[j].runningTime = systemClock;
6 I+ ^6 C$ z/ S% P(*memory).p[j].produceTime = (*storage).p.produceTime;
% e2 [; x4 a5 t$ y6 F5 y- ^for(k=0; k<(*memory).p[j].ioNum; k++)
/ B, {$ U; ^, f, t5 X0 L8 |; R- U(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
. Z- w, t7 u* ?" ~4 o( b8 v* Tfor(k=0; k<(*memory).p[j].computeNum; k++)% M% l. O- E2 {
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
2 P1 g+ K( ]: m(*memory).proNum++;
' e2 V, H3 ?5 a( i5 o& V*spareMemory = *spareMemory - (*memory).p[j].askMemory;
2 B5 h. h1 x6 v5 {+ e; c4 Uproduce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
0 J" }$ [6 F8 k! r1 i" f2 z, ~( N' U: XMAX_COMING_TIME = (*storage).p.comeingTime;; [: v8 H: S x8 q# h
flag=1;
) p) Q" Q v- Y. {- M: Ztranslation=1;
; o" F# s/ v4 ?0 s8 Y7 ^} h9 y5 ^/ g: V' M$ `* @: G0 ]
}
# y; ~* y* W3 }) N* k" eif(flag == 0)7 C6 `0 h* P/ h1 n# ]" S
break;
5 F+ G% \& U# ^}
6 F! o% z- V$ Q+ p}
4 L3 w' q1 z& X% g6 [$ z7 b& E, sreturn translation;
+ j! `) L7 _' J& K7 `: a}
% C, O Q" f q' q9 |% W, kint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)
7 m2 Y* }( q2 A0 P' q{* X8 t- o" s+ u! I( [( m& a
static int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;
$ m8 }9 K3 X6 v; Ustatic int computeLast=0,waitioLast=0,changeLast=0;
* ?: T0 D \; W& {% Z8 O1 Q) j* Uint i=0;2 v: Y0 }# _% G( b" \
if(draw==1)
; f$ s4 R; n: p{
4 y1 L( Z6 g$ R5 M( F, G//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
1 Y" w; Q/ X2 ZdrawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
. X" Y; i8 g, g% K5 h+ O7 t8 V% i# Q
; m N$ S1 X1 W( \ H
computeLast=compute;
X/ z/ G: z& ^9 cwaitioLast=waitio;* b6 q% F1 k$ }* ]: B& m. O1 M
changeLast=change;( u0 ~% f1 v2 b8 ^5 C4 e
}
0 |+ g5 F6 Y$ r T5 Q( ]* Q, d- I9 e iif(flag==1)
" A, {) s# s: c& M{# v( Z+ c |9 @6 ?, F& h6 S
if((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed
" u! N# v; G' i{
5 i$ T% J& J0 u7 j4 hif(flagiocpt==0) // implement compute
" V& C# I9 [4 u/ `$ m{
3 r' U: c" _( `8 G- b* di=(*memory).p[0].computeNum;) i* [3 O+ H Z- o/ W( A9 k1 `8 n
if(i>0 && (*memory).p[0].computeClock[i-1]>0)' D3 p2 T1 X i- f" S; c% o% u; }
{. j9 b' E6 @3 k+ e" X! x) W9 I
if(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed" }: O* n; }6 @& Q' t# w W% I
{
* i# e% a8 Y) G# r8 Cflagiocpt = 1;
5 E( ?, Z, u/ z( T. p& l1 c- Q(*memory).p[0].computeNum--;
% T q7 F5 Z# F. Ichange += exchange_IO_Compute;
& }1 s! S7 Y% Ccompute++;
& U/ I! `9 k/ I1 z" H2 t. s: j v}* @7 h5 P' |6 v8 W$ i; g W
else
) L* |/ N# u, [9 _$ e. w: pcompute++; j+ Q+ }; u6 a2 l
; {8 v U* ^1 ~. e' b}. ?! M" M7 C# S1 T- }! l: ~$ @- h
else y, D3 I, O" q
flagiocpt = 1;5 R, N; w* A/ p
}0 B2 F% R0 I7 c ^' O: r
else //wait io
! T; O% ]$ z$ h/ T) L{
6 \ T( b9 m( n$ `i=(*memory).p[0].ioNum;9 N0 k! L. |& v& M( d
if(i>0 && (*memory).p[0].ioClock[i-1]>0)! o' I% k# l) V' |; L4 q
{
9 N/ z6 Y; q _0 B1 d% q% t. f( v# qif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
: X3 P2 w- S6 k' _{8 i* l# r, n& W) U. P
flagiocpt = 0;4 o2 T/ @1 W4 B) D5 `. r6 j9 P2 m
(*memory).p[0].ioNum--;
5 N* s* m: o# u {( n0 Nchange += exchange_IO_Compute;
$ s! Q' K& }1 B& D( V; c& y1 Hwaitio++;) H. e0 l3 a+ Q$ P' |
}
) G/ o+ s" T: s/ k/ w. `' t& `else8 ]) E& I1 N# ~
waitio++;7 f* P5 p9 S; l
- I& }- ^0 P. E. i$ M8 a5 }3 Q( {}
' Z: u8 |* d9 s+ n8 Telse
; C# u% u# a! c7 ]8 V1 jflagiocpt = 0;- ?9 g' q! p3 K K3 A) l. M# Q
}) }8 }: ^# `% C6 C( `' j
}
8 |- @1 n3 w2 ]& a+ _" nelse //task is completed) Q7 a! @, W s# ?
{
$ z/ d/ }- ]$ U1 M& `(*save) = (PCI*)malloc(sizeof(PCI));
: l4 n8 S* M0 \$ T4 K# ^; A(*save)->next = NULL;7 t- C- M; `$ |! {) }- w
(*save)->processID = (*memory).p[0].processID;6 l( w; V9 @% O3 k/ T/ y
(*save)->comeingTime = (*memory).p[0].produceTime;* m$ z* Y4 y, }
(*save)->askMemory = (*memory).p[0].askMemory;
y c H9 n8 K(*save)->compute = compute;/ E6 ~7 F. b* c( }; }, {
(*save)->waitio = waitio;% |3 A, b. k8 V- I- Z
(*save)->exchange = change;% m" n1 J2 T4 q" |" q1 l+ Y
(*save)->completedTime = systemClock-(*save)->comeingTime;6 o. W3 N2 |% m* j, ^$ l; _% u
(*save)->runningTime = (*memory).p[0].runningTime;- g# v7 b9 L# F- p3 g
(*save)->completedTime = systemClock;& i* z: e/ I% s
//*spareMemory = MAX_MEMORY;3 U. N+ S, P3 _ F, [ p* h
free((*memory).p[0].ioClock);4 F9 d+ g9 g7 Y4 F3 w
free((*memory).p[0].computeClock);
: K' e4 p! W; p1 T( U) @& s8 bfree((*memory).p);
) Q. W0 G6 i! c6 w. f7 ?, Oflag=0;
0 N/ x- |: _4 d/ U$ xcompute=waitio=change=0;0 g& r, `2 o" t4 O; G
computeLast=waitioLast=changeLast=0;! E- \5 n' ?$ ~- G7 o3 t# e. `
return task_completed;
3 S. B$ l6 f- s! z/ P! Z}
- ]* U5 R0 l2 |; a# X3 w- [' @3 e}1 \, r* B( v) S; G! F/ h' R
else
% {- h+ z! i- |5 ?8 S{' R; H( r' W* D" N/ s/ u
FIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));
/ F8 J. S" \( a6 y/ v- P! a' \( rchange += exchange_process;1 Y) j1 `5 q; ^6 B {* S
//*spareMemory -= (*memory).p[0].askMemory;0 M: h( y( t- P
flag=1; `' W) Z; r7 V4 G
//showProcessInf(*memory);9 W4 } F% ^+ j6 e7 m- ~6 i: [
return task_not_completed;" J, O% c2 L" D
}3 w% C; g3 W" K: G) ?
return task_not_completed;
7 K( X/ j! }! E0 g}% B' B% h& r8 }: z" R
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)1 y2 z2 f! s. A3 L1 h3 t! m; [
{! g: {" @' g8 \5 _! n% W8 g" Y
int i=0,j=0,k=0;2 x2 K' Z0 _$ h6 J
MAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;
5 j: X5 x' C2 Q% W- g4 O, G% {(*memory).p = (process*)malloc(initProcessNum*sizeof(process));
) v/ m9 n, v/ a' Y) o$ C+ W' s, R: ymemory->proNum = 1;
+ Y& \& ?% J7 ?8 bfor(i=0; i<initProcessNum; i++)
6 i+ n! ~4 a' h8 B6 y% g6 W4 h0 o{: O. q7 N5 V0 s( W# V
if((*storage).p.askMemory <= *spareMemory)& W* H5 B: u6 u; M q
{0 J0 r2 ^. {0 @1 u/ ~
(*memory).p[0].askMemory = (*storage).p.askMemory;( w( h1 c1 }& l5 N
(*memory).p[0].comeingTime = (*storage).p.comeingTime;
. M" A( F, b6 u% |(*memory).p[0].computeNum = (*storage).p.computeNum;; |; c; Y; m: O
(*memory).p[0].ioNum = (*storage).p.ioNum; Y7 ~. M& ~4 ?2 s
(*memory).p[0].processID = (*storage).p.processID;
9 r" L" K0 N2 _ J" J) s" S. E; t(*memory).p[0].flag = (*storage).p.flag;
2 O! p7 x/ Q `- q(*memory).p[0].ioTime = (*storage).p.ioTime;/ `6 {1 k# [5 i3 ^% _' k
(*memory).p[0].computeTime = (*storage).p.computeTime;5 o. V2 L: u; q/ f7 Y
(*memory).p[0].produceTime = (*storage).p.produceTime;
: k$ X1 L3 V; V7 r1 u(*memory).p[0].runningTime = systemClock;
2 A$ J# x9 J' Q(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));
4 p3 ]- F" E; v6 z4 e(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));7 g; z% D: [ N( e
for(k=0; k<(*memory).p[0].ioNum; k++)! c( F+ D( |7 ?& E: I2 p$ s
(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];
0 F6 p% S4 A L( _for(k=0; k<(*memory).p[0].computeNum; k++)2 S- t% L" L+ s; n( L
(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];
. N9 s+ H W. J: z. d* Wbreak;
) Y/ f9 c# A2 l. v% t, p/ c6 C}
) H E% Y! R3 B" e}2 S! B2 `4 ~5 M& r$ K1 m
if(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入9 I6 Z( _4 T" Z, k# O0 e
{+ H% O4 }5 [% \: m
produce_one_task(storage,i,ID_FIFO++);
. L7 g) _# d) `MAX_COMING_TIME = (*storage).p.comeingTime;3 A: M9 N: y) B/ z- w
sort_by_comingtime(storage,i);
$ o" G* @* h9 u2 k1 T}9 r4 j, K" S/ d3 T
return 0;0 \" Z; m) l# {% U( B% i
} _/ ?% C$ Z3 W+ b: Y
int sort_by_comingtime(processPool * p,int pos)
6 N7 Q+ t$ ~; [7 U3 W5 \{
$ K. L- O. {- ~; H% Eint i=0,j=0;
! H' Z3 N4 h( t9 B% z( zprocess temp;
: H8 ?- @8 v2 r/ bif(pos<0); E; O- `, V1 Z' |8 Q) v7 J' ?
{+ T+ B, S" J* s% Y; I
for(i=0; i<initProcessNum; i++)
; ^( b5 O8 E5 K0 T7 l3 Hfor(j=0; j+1<initProcessNum-i; j++)+ c, P" x* d( q6 j9 J, J
{
( Y1 O9 G" Y, J; v& ]; Hif((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)
& i) T# r, O! F! v3 J{5 B) r' G0 x2 X3 R; e8 f) q
temp = (*p).p[j];
( l# \7 A& r" b+ ^, s(*p).p[j] = (*p).p[j+1];
3 V; u# Y7 R q# d(*p).p[j+1] = temp;. Y& y. A# R. x7 R* G. D @& V: R
}4 G! e% L5 {+ p" z; d! e$ s# b
}
/ I% O J; g( c2 n}
- A" n* z: e7 uelse if(pos<initProcessNum)
6 j# N5 o. z% G- f* x{
) e! g$ L, h5 h& T& a) b$ `6 Lfor(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)
2 a/ ?0 _( N+ `' r! p5 v{, Y9 i( Q. b* |, u) b9 k
temp = (*p).p;
9 e) w9 ?3 [& c7 f(*p).p = (*p).p[i+1];# ~5 E7 `& ^/ t$ A$ ~& A
(*p).p[i+1] = temp;8 G4 h' }$ c( U! }8 x8 W/ Y
}
; O; H9 E \9 O: Pfor(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)! _' w4 Y8 r/ `- r7 E. g# o
{' V: N+ x4 Q& \, ^7 j0 ^6 V
temp = (*p).p[i-1];
8 u9 ?1 M6 O# S. U(*p).p[i-1] = (*p).p;
/ n% Q. _4 C5 c7 A# B2 ?. ^4 c(*p).p = temp;7 W, z0 i1 j r! R
}
2 Q+ G' w' M( A}
1 j0 i- h' H7 ?9 ~4 Q2 C/ ]else* Q0 E$ @9 [7 G6 R4 V& |
printf("position eror\n");
8 E' _+ B* h- [! I; yreturn 0;
b1 ?% @- R. E- n4 J$ R/ g}( s7 A! B9 Y( { |$ |
int InitPool(processPool * p)
( H: ?( l/ N( l& E{
5 \! F/ Q/ D5 j7 O3 oint i=0;
5 t) \% {- J4 P" q% }& S7 c" v(*p).proNum = initProcessNum;
5 _; R% f9 Z* c% {/ M(*p).p = (process*)malloc(initProcessNum*sizeof(process));( u0 a+ h3 v$ Q& B1 x I8 O
for(i=0; i<initProcessNum; i++) //init process information g6 q0 G0 G6 j0 b& E2 p& E
{3 Q0 }0 d0 O) Z7 _! Y
(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));
+ i6 P& ?( k2 R(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));4 P4 ?' |! m2 w8 J1 e' Y
produce_one_task(&(*p),i,ID_FIFO++); _' z% y. O( u" T2 X# B, ~
}" Y, _5 ^" o# T/ Y
return 0;7 W" G& N5 }) b. i; V6 A
}
, ?! t* ~) D l8 G. rint produce_one_task(processPool * p,int i,int id)
t3 h, s" c8 Y, _3 e{& {0 m. F5 `8 a! u7 }( `; @
int time=MAX_COMING_TIME,j=0,totallTime=0;
* r' P; X% s/ }(*p).p.processID = initProcessID+id; 3 T& I @, d. P$ ^# ^, Y9 n! c4 x
(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);& W6 z. |2 ^/ u5 c ~# B( a
(*p).p.produceTime = systemClock;* h) c8 v. I# L$ ?3 _# ?3 m
(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;
) o( t/ k, O% p. e6 O, ?/ l(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6;
+ G1 e, p- d. V) y+ stotallTime = (*p).p.computeNum + (*p).p.ioNum;" X: K; ~; _2 p+ _4 W$ X | @# D
(*p).p.computeTime=0;( S9 v5 p0 { T% b6 s4 A9 [
for(j=0; j<(*p).p.computeNum; j++)
% A" d- l. l" h H/ v, J/ O' ?; s{
1 c' m& q4 `; ^' {3 ^. B& U8 H(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;) {7 a$ c Z- V E- i
(*p).p.computeTime += (*p).p.computeClock[j];& T, a# [( d! y4 h
}. R) u) \+ a0 K. r1 `
(*p).p.ioTime=0;
" i0 R9 R4 e$ @* l- Xfor(j=0; j<(*p).p.ioNum; j++) |
|