- 在线时间
- 1630 小时
- 最后登录
- 2024-1-29
- 注册时间
- 2017-5-16
- 听众数
- 82
- 收听数
- 1
- 能力
- 120 分
- 体力
- 563437 点
- 威望
- 12 点
- 阅读权限
- 255
- 积分
- 174254
- 相册
- 1
- 日志
- 0
- 记录
- 0
- 帖子
- 5313
- 主题
- 5273
- 精华
- 3
- 分享
- 0
- 好友
- 163
TA的每日心情 | 开心 2021-8-11 17:59 |
|---|
签到天数: 17 天 [LV.4]偶尔看看III 网络挑战赛参赛者 网络挑战赛参赛者 - 自我介绍
- 本人女,毕业于内蒙古科技大学,担任文职专业,毕业专业英语。
 群组: 2018美赛大象算法课程 群组: 2018美赛护航培训课程 群组: 2019年 数学中国站长建 群组: 2019年数据分析师课程 群组: 2018年大象老师国赛优 |
& g+ c% ~6 F8 e( ]* b; V* }. Z
经典任务调度算法的模拟程序9 ?2 J& b9 G) ]/ b! E
本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。4 |( z$ i6 N, h; W1 @2 J
1 {. i0 w- D( M9 e3 z2 o编程平台:VC6.0+EasyX图形库环境。
' l) U' a; q. G" Q$ ^7 J6 Q3 E8 I2 H7 @0 G8 Y2 H) q2 }- z7 [
以下截取部分程序运行图::
3 D; d" b% R' m6 C5 v9 H6 k
. {# m9 ^& B) ]/ x$ M* r源代码:
- K6 R; f$ v& \& i' T4 r2 j( Y% |; X
#include<stdio.h>* s% X. W4 w- O4 b8 F. F! O7 C
#include<stdlib.h>( }& X! C% Y1 H1 _
#include<easyx.h>
5 [4 y3 k: r2 |$ C% W& i#include<time.h>
( S0 A# o: M! T4 H* s' M#include<conio.h>! ]' A: i8 A3 T% z) l3 v% W/ _
#include<graphics.h>
; U& r+ F. ~* K( v#define initProcessNum 10
" c" G h3 Q9 ]: Q: l#define initProcessID 1000
4 S! y6 `$ F# t4 L- C#define MAXProcessRunTime 100005 H7 L+ M' {" y* g0 j6 J
#define MAX_MEMORY 4000
; a/ m8 W4 {& N# k- [) `2 i/ r5 z#define exchange_IO_Compute 10- y% l$ H! u( P Z/ i- N. S
#define exchange_process 25* @% w& Y& G* H4 U: _% H! E2 r1 \
#define task_completed 16 Z+ l& d/ J, K. l/ W9 N6 u
#define task_not_completed 0( K9 Q! F7 M4 o+ y, k. @
#define initclocknum 100
& S: `7 z# O- i$ y6 d) R$ h+ a- Henum condition, V$ ^7 p4 B, \. e& F
{
6 \) b# G6 w$ edead,computing,IO_waiting,ready% \9 L1 y3 C) }4 ?1 |
};
6 J7 I% ~5 f H2 V) tstruct process
1 p% h8 r# S& b3 k5 k4 m- Z{" _% W' \9 b3 a- p
int processID;
8 q" T$ _4 u* Eint comeingTime;
, \7 C+ z8 Q- A0 X: |int ioNum;
4 A( D% l5 O" A9 s8 U) _int computeNum;- j t, x% l5 N0 N2 X$ ~
int * ioClock;
5 U0 g8 w u$ B+ b- R, [% dint * computeClock;( Q0 U8 Y7 m, v& K/ e% T" V6 K
int ioTime;
) w+ ^* T1 ?; H# L% bint computeTime;4 g; D9 _! }3 c( d! Z- L7 {: g2 t
int askMemory;9 I& i& E5 t5 f5 K; Z
condition flag;& r) w5 K% m" d, W5 q$ ]
int produceTime; //生成时间,以下三个数据成员用以计算相关性能
# M8 e6 [1 p3 u& J+ Wint runningTime; //第一次占用CPU的时间7 d N P' w! T( l
int completedTime; //进程完成时的时间
4 _4 F7 i1 i6 ^9 a$ ~}; B2 J1 U- H5 U: b; a
typedef struct processCmpletedInfo //保存完成一个作业的相关信息
' R' R$ _% |" M! p% u2 G2 q{2 I2 G& R* s4 C4 A. g! O0 M
int processID,comeingTime,askMemory;
% M( j+ ?2 a6 N/ Tint compute,waitio,exchange,completedTime,runningTime;% Y7 K5 e) c* A* R% T) f9 i
processCmpletedInfo * next;9 T4 E. L2 @2 `7 `* L) x
}PCI;9 c+ y% a2 ?9 o) [$ B* D5 |
struct processPool( H1 c2 w% h0 V: v: `( @. ?) a: S
{& I, ?. i9 S' e, H0 N$ b
process * p;
7 b' g5 p! Q4 H+ b4 S" Qint proNum;" {8 A: B* k" ^! f
};
/ V3 B8 T @4 E# u; bint MAX_COMING_TIME=0,ID_FIFO=0,systemClock=0,FLAG_FIFO=0,FLAG_TT=0,FLAG_PF=0,FLAG_SJF=0,FLAG_HR=0,FLAG_show=1;
b+ g5 ^2 N) q2 T, [4 `int InitPool(processPool * p);, r3 ~8 r7 }* R- I$ o2 L: k' U$ {
int produce_one_task(processPool * p,int i,int id);
2 h4 _8 H7 N" k& Rint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);
1 P% [9 u& F a8 j" C. q8 Bint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);6 I' m- G* X' J" S/ R
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);, [2 i! t5 ]& Z8 E8 h3 p
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);7 t+ k- W% c$ A: H, X+ h$ L
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);# F0 _0 a/ T: d6 @7 h
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);1 `5 g/ \' U$ O2 y# f6 e- T
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);6 U2 {) n- X0 G& z ^) U& e! x
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
7 A% W1 n. z2 {8 O Mint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);
$ n* b$ g- x s8 Y- m2 {- O2 Yint High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
9 s: y9 w) k$ v5 r$ `$ o0 m( } f- K) }5 Q8 X
j9 W; X6 m/ G' O4 l1 Qint sort_by_comingtime(processPool * p,int pos);: B5 P/ D5 |6 e- g5 J4 @
int showProcessInf(processPool p);) S* [8 u9 w. J/ a
int drawPerformance_FIFO(int x,int y,int memorry);# V6 Z p* f- L8 s+ O
int drawPerformance_HR(int x,int y,int memorry);
& y/ O& J7 I' f6 f( H" I. Lint drawPerformance_PF(int x,int y,int memorry);+ `! K! {" \- q
int drawPerformance_TT(int x,int y,int memorry);# a7 X0 F9 b% F/ i$ X
int drawPerformance_SJF(int x,int y,int memorry);
/ s4 i) |' K4 d6 ]0 z- I- C! b3 U `- Wint MouseListening();0 e3 D) @1 ~$ v6 n
int MouseListening2(int *flagShow,int * showTime);, q) T" `$ U5 x
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);" ?' ~: c& m2 O9 G+ ^3 {
' W# ^) A9 u' V7 K
* M2 P- i2 q) K& F. K9 ^7 _0 P
void main()
5 c: \" B2 F& Y/ u3 V' j9 f9 u{5 v$ J8 Z5 }7 w% O- w
PCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,
9 f1 z* h% l- T' Y0 X( G$ S: O! {*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;+ s, T! T" R3 D
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,4 |1 U$ d9 g1 A# F
flagDraw=0,showTime=100000;
6 D# Z' n) `6 n* g M; d4 {1 c% C4 UprocessPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;* f2 c: V) V- ?; G0 a8 y3 [, a
FILE *fp=NULL;
! j3 h, E1 r4 L/ n9 u, o7 Y//processPool HR_p,HR_mmy;
5 O* c! _2 }! v+ m ~4 ~( A) {/ U3 x! F" S2 p
. Q% ]# P# `. Y$ gsrand((unsigned)time(0));3 g6 L& ?; R4 z* Z, k# }- r
systemClock=0;. K0 K5 E. p/ ]" o$ K
initgraph( 1200,650,SHOWCONSOLE );
" m6 F% m; z" m: Q4 X% X0 z- asettextcolor(GREEN);
' {' _; W& J5 U, Xsetlinecolor(GREEN);: _5 m9 q$ q0 A8 H0 d
setfillcolor(GREEN);
: c" x) s2 U. aInitPool(&FIFO_p);* N" h8 T. J& D* E: h
sort_by_comingtime(&FIFO_p,-1);
7 d$ Z9 [+ m HInitPool(&Timeturn_p);
3 e5 }' z* g1 ]' O+ FInitPool(&SJF_p);. r- I* n6 k: G' E" C* C
InitPool(&Priority_p);
3 v. m1 h0 Q$ g' _InitPool(&HR_p);5 ~0 q# n0 c s& G1 S
//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
* k/ z0 e: t0 c0 L+ ^//Sleep(10000);
! n9 V9 D6 l- L% d
% o8 t+ t' K: O) ]" M6 p, D+ x- V$ r1 G$ i
Timeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));. \0 R+ C7 S* J! S* l/ O' Y
SJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
6 {2 y, r0 c1 x! VPriority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));" U$ l: V$ V" s
HR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));* t9 S: Z- X* R( H) ^
for(i=0; i<initProcessNum ;i++)
) P! F7 t. V7 h{$ D- c; t Q, \0 [( z4 `( d8 [6 Q
Timeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
0 O" Z; }& ?* E. D" e4 W* yTimeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));( M3 E: I( b5 [- B7 Q+ o
SJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
5 Y1 L1 S. E3 dSJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
5 p( C3 y# Z! vPriority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
/ b, |: Z; e0 C& _Priority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));8 @, N* u$ \7 A0 [$ ]
HR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
/ d$ v& l+ V8 U' fHR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
2 L6 O9 ?" S- J' U}' B6 D2 w2 X- P( j: |$ F
Timeturn_mmy.proNum = 0;
! w' n$ o# T1 m2 x$ F) k: Q6 N3 _TimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);
$ }1 a/ e- |' s% LSJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);
7 ]& X0 Y1 g- a9 M0 q( mPriority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);5 }9 U' D' M `! K7 x+ h J
High_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1); p! R( Y3 u2 x) N3 k' N
//showProcessInf(Timeturn_mmy);
# u3 i- O% p4 h/ KFIFO_pri = &FIFO_save_head; m9 i; e4 U3 j% ]: ~
Timet_pri = &Timet_save_head;
7 Z8 P( D2 q" u' a- I7 j* oSJF_pri = &SJF_save_head;/ R, G8 G' k! i" l% O
Priority_pri = &Priority_save_head;1 K3 _0 q0 }/ O% F# }7 M
HR_pri = &HR_save_head;# i4 Y9 E3 f7 m$ W+ v6 @3 A5 b, M
setbkcolor(WHITE);
8 J( q4 w( R* Q6 K' }while(1)/ P2 ?, }9 H, ^! Y
{
# v! Z9 @4 c" z. w9 Kif(MouseListening()==1)
+ k" `3 F/ }' A0 Z+ r1 q- ]flagDraw=1;. M; B0 ]" L5 y! V4 t
if(count==100)
9 Q( }) D& w: ]. A{ i/ F! O0 J) ]; M
if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)
7 A l! v2 W/ o# m{( N/ J& Q( V# ~ A4 I- }4 E
FIFO_pri = &((*FIFO_pri)->next);
" _" i! o; i. f+ ^: D6 w4 B, }- w1 K7 f7 X0 m: N" y. v
//printf("hello");* O1 Z6 } ^/ {4 k* U
}+ X7 T2 o" S* F0 L% i- U) D% Y
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)$ Y" m' m. g! m4 C3 o
{
$ e1 I1 W- ?' k* t' a/ v0 V Timet_pri = &((*Timet_pri)->next);
Z7 e1 d1 N6 r//printf("hello");% z$ w2 n4 [- l8 y" \
}& ]8 y I, g \3 E1 L' H
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)$ V" r0 f y8 { J, v
{' G5 M/ `. Y) ~$ N- {! X, E
SJF_pri = &((*SJF_pri)->next);3 o: J3 x2 o* `, B* H
//printf("hello\n");5 O0 p# D1 [6 @
}
' I2 a4 v, l4 f& ~: Wif(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed)
4 p+ ?7 I8 l$ ]) k{
; I9 o' O9 v& J* C" RPriority_pri = &((*Priority_pri)->next);
7 H# b! p+ B1 L$ L5 R//printf("hello\n");) X! d0 L; t3 p, z
}% Z# h- l: I3 N# |+ y
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)3 O( E* l7 x( p; h7 u' H) `$ f! e8 `
{( A* b7 z9 X) {+ Y
HR_pri = &((*HR_pri)->next); d0 i& D i: K! e+ l
//printf("hello");
+ ^# K. o# d3 v- }# m" \}
/ m; g ~5 c) z; q6 Ccount=0;
& L0 ~$ u+ G+ p$ e2 N+ }' x! Z}
7 y- R' p& e* h* C& Z6 G( y% aelse
9 V0 E+ T2 D8 |" E2 e6 l6 Y4 i{, d7 G. ]9 e1 ^! A
if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)) t# S( s4 I0 f, S. i+ g c
{2 q* n0 k+ q* q% L9 @' |
FIFO_pri = &((*FIFO_pri)->next);
! @2 O o, C! i// printf("hello");
, y9 b* [% g# f5 |}
) q1 X7 [$ V$ A! `7 |if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)
5 Z1 R9 e0 @, [4 O' ?- L: p ~{
& g) D8 _! i3 \8 f/ j* N% T. oTimet_pri = &((*Timet_pri)->next);
3 n6 O5 X h, ]( J( b// printf("hello");
& h- L* N# O: c; U. ?}
: ^& R$ @- ]7 s) E! Q4 sif(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed). {0 }) w# K5 G5 \
{
* H. i! @, F8 a0 N5 w SJF_pri = &((*SJF_pri)->next);
; g& _" F2 w( N: U/ i2 e0 q// printf("hello\n");$ V5 X0 r0 E8 O0 Y5 D1 j2 H
}
' k3 ]4 {9 x# ?1 bif(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)
7 c* f" {8 _0 m. L& q. n; p{
6 N/ a! g) B2 Z( R" l! N5 T( IPriority_pri = &((*Priority_pri)->next);9 V; U# p9 Z6 R! |/ J
//printf("hello\n");% t" k# V% v7 `) b& C
}
$ t H! T4 ^* E" Vif(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)
" u7 b# K5 A8 {) G- c, N- |9 Q{
O/ h2 ]/ L$ a; h! j- T* xHR_pri = &((*HR_pri)->next);9 Y6 Q. g) k/ \
//printf("hello");
: @& N- T8 N8 y% g; L6 f9 b//Sleep(1000);5 o# `' e6 ]) B: i
}
$ @/ a* r" s) G2 ]" R& ccount++;! S. K3 w" m1 d7 V5 G
}! ~% I R! T$ @6 |0 \
if(systemClock==showTime); H$ t- ^0 E! F& n; c# x0 Q9 |
{
+ ` G% O. P! A6 S8 X; Y: W. h/*PCI * p=FIFO_save_head;
2 _5 \9 Q4 h/ ^int i=0;
$ x" S' J( t0 f" X4 u8 C' X! d0 ofor( ;p!=NULL;p=p->next)2 | v2 H, U8 v# F" F
{' P8 [, L; E6 n. ^( I8 t
printf("Id %d\n",p->processID);
0 i! Z+ ~$ p+ h/ Uprintf("comeingtime %d\n",p->comeingTime);
$ d1 V$ x+ S' {printf("runningtime %d\n",p->runningTime);
e: Q: J; h/ o2 S, n5 Aprintf("asdmemory %d\n",p->askMemory);
3 t; a0 L4 N f; Eprintf("completedtime %d\n",p->completedTime);
. e9 R; _3 q0 s/ mprintf("compute %d\n",p->compute);! f/ P7 Z4 t& |
printf("exchange %d\n",p->exchange);- o* |" v- w7 \2 y
printf("waitio %d\n",p->waitio);/ M0 L, {$ c% j, j$ P& P
i++;
. E" B& s9 Z' L! i" Z i4 _7 M9 P; o( j
" p% Z/ }0 w+ ?& y9 t5 N; b}
+ ~0 v3 s* ?$ a4 I5 O# }printf("%d\n",i);*/# H h; m( O7 ?# N0 A
if( (fp = fopen( "data.txt", "a" )) == NULL )
" W# [. w, h, k' N{
' r, ~! N) C& B) N8 dprintf( "The file 'data.txt' was not opened\n" );& c0 r8 E: S! W8 x
//return 1;( x8 ~9 B4 A9 C' D2 ~$ @
}" L0 U% C" [& |/ N
else
# @* H; f+ o* H{
# u. |/ N) F0 p+ o* |- ]fprintf(fp,"FCFS \n");+ Z# w3 Y, ^! r
for(p=FIFO_save_head;p!=NULL;p=p->next)
2 X5 J" ~/ _' n+ k- Wfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
5 C% r) ^1 L. u E! Q+ hp->exchange,p->waitio,p->runningTime);+ i( \' l4 a$ V9 l, R
fprintf(fp,"\nTime turn \n");) F* q' r l& D
for(p=Timet_save_head;p!=NULL;p=p->next)/ b4 r/ l5 U- B D1 L V
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,, o( Z9 g \6 D& ]
p->exchange,p->waitio,p->runningTime);, s5 W# b' e% [2 }; y5 W/ p# U
fprintf(fp,"\nShort Job First \n");
2 y- ^: F# K! B( m) ifor(p=SJF_save_head;p!=NULL;p=p->next)
0 N. i4 }- a8 g. y' b' m4 g/ _fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute, a, l8 K$ d8 w w; x. o
p->exchange,p->waitio,p->runningTime);
/ d/ u* k4 u; u; K3 F0 {/ N' zfprintf(fp,"\nPriority \n");
1 Y3 E/ D+ M8 h* V6 X1 e9 z) t9 ?for(p=Priority_save_head;p!=NULL;p=p->next)
* t; X7 @* r- E) ^fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute, X( q) R7 d, T3 e: f J7 k
p->exchange,p->waitio,p->runningTime);' y! h. G9 x- I
fprintf(fp,"\nHigh response \n");
" U/ h+ g- U$ x, P' pfor(p=HR_save_head;p!=NULL;p=p->next)
# b! ~2 S8 x' u) |8 _fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
2 r/ k3 ?) Y; _ sp->exchange,p->waitio,p->runningTime);8 v* L/ P; T- b$ V7 i! m
fclose(fp);
. j& Y+ |2 W1 b1 K}/ L0 |" ]% D8 |! M# H9 u
showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);# G' e" ~9 w& _9 Y3 K6 s' B
MouseListening2(&flagDraw,&showTime);
" r. C; r' ~# j( x' p$ U' _}
+ m7 u& k& m/ l( { }5 hsystemClock++;2 [: v2 Q8 m. @+ D- P4 p# X0 h. u
if(flagDraw==0)
! t5 b, {/ V6 r; L2 U9 L- \ Sleep(10);- G0 B9 }/ z) Z; Q% L- f( ~+ y
}
( L5 E1 {0 `0 b0 a, t5 H# n6 d+ O( D/ k+ e' J+ Z
; u$ j: r5 }* y' y0 m}9 J" r( s. h# ^- |1 H8 d
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)7 x8 U6 d- {& `0 U/ C
{
2 j; ?& P, o' K) M% l5 R6 Q' ]* UPCI * p=NULL,* name[5];
$ @" ]$ |, X7 V# L& mint count=0,i=0;
3 N' ~- v) N& J* Z2 Bchar ch[5][10]={"FCFS","timet","SJF","PR","HR"};+ `/ N/ x/ }- r7 g/ f# l; s0 T- O6 Z
double turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};$ W" W, P: u" Y
struct info4 a% f* q. v9 D0 |1 H; x/ f
{5 Y7 z0 n2 h Z1 F; r
char name[10];) V; d9 {8 Y) D: I( ? j
double throughput,turnover,wait,CPU_rate;
& G' y8 H( W+ D' r$ e}inf[5];
( c+ `- J6 h; Z) q0 Hname[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;+ a0 x; K1 j* b4 z
printf("调度算法..........A\n");. T9 E8 Y' Q1 [ ]4 X/ a7 B0 D
printf("吞吐量............B\n");+ B$ z7 Z& M* L# K' s1 d
printf("平均周转时间......C\n");
8 i- I) q5 G- ]2 v9 zprintf("等待时间..........D\n");) y. E) n' {3 C3 n
printf("CPU利用率.........E\n"); v8 ~, n" D, g( D$ A: S
printf("A\tB\tC\t\tD\t\tE\n");
. a, k; y8 [. h0 qfor(i=0;i<5;i++)
3 O0 ~& M! O8 A. ?8 B* p& p& G& G{
+ Z$ k. `/ e* C5 }: ucount=0,turnover=0,wait=0,c=0,w=0,change=0;
3 |: Z. y$ v$ Z$ `2 X& q# }for(p=name; p!=NULL; p=p->next)
5 A4 ~3 D: W' B0 {" a{
/ n: L+ [8 }0 ^4 d* ]# Gcount++;
}8 |' I( S: Z% w! c2 U/ mturnover += p->completedTime - p->comeingTime;
% H A$ S* j! n0 Mwait += p->runningTime - p->comeingTime;$ n3 z4 k j( b$ p3 @ B
c += p->compute;5 I* c o: a# |4 v @
w += p->waitio;" v/ [9 m! b( y% A
change += p->exchange;$ V3 l( y2 _; z$ L; L; x
}
" [. q/ _( A- h- \+ v Vturnover = turnover/count;0 U. m8 U5 |9 y) C
printf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));' v- ?% a+ L& V# }
strcpy(inf.name,ch);
2 c' K+ v+ X, g0 F$ ?/ dinf.throughput=count;9 L! E3 B8 C4 K9 Z! o) y
inf.turnover=turnover;
4 ^9 u9 T3 m( G' f& z/ }inf.wait=wait;
/ s! E' X$ E% v- F6 V- K) vinf.CPU_rate=c/(c+w+change);' |: d n, g% M$ a% m. J7 m
}
$ M2 y* j$ N$ Z0 m" X7 W9 ?( ]) t- F//画图/ Y8 h f" t( b8 ~% t" Q* C2 s
//cleardevice();
; ~; E8 a) D+ Sline(0,600,1200,600);
5 [: t: h; M0 \0 M1 }line(10,600,10,200);
3 |/ w5 Q2 H9 a( w2 C! H/ A$ E/ uline(10,200,5,205);
0 |9 x( R; @8 W" jline(10,200,15,205);
j/ V9 m. a, e6 w6 K9 c5 P1 J5 Lline(310,600,310,200);
5 q1 [/ k, G$ M t0 hline(310,200,305,205);+ i0 z- ^: m+ `! K7 ^. X
line(310,200,315,205);0 u e i* _$ u' u
line(610,600,610,200);
1 \9 I- s/ \* X) Pline(610,200,605,205);( z6 n, g7 ^6 D6 F) w1 |5 M
line(610,200,615,205);
$ A$ _; q l$ M2 e7 R+ O; Vline(910,600,910,200);
2 P! s# q, q6 H. L" vline(910,200,905,205);. Q; M# g# q: Y _) F3 U
line(910,200,915,205);//最高的长度400,宽度均为40& @) v& s% `* K; E
for(i=0;i<5;i++)4 s' c9 ^ ], C- ~% l, A2 l" \
{9 u9 \3 B, D g2 H
if(inf.throughput>pos[0])
5 Y( {5 O$ {% E/ b3 C' Cpos[0]=inf.throughput;
' K' m0 {0 n! N- `6 X4 Hif(inf.turnover>pos[1])
& q) _/ m7 ^1 J( Y1 _pos[1]=inf.turnover;: E) O* u" q* Z) a9 T
if(inf.wait>pos[2])! q( \& y& j% T0 G6 B
pos[2]=inf.wait;2 i( w2 \5 r0 B6 d J. ~
if(inf.CPU_rate>pos[3])) N' y8 R+ _8 b3 h, v1 ~1 P
pos[3]=inf.CPU_rate;% r! x( h" _1 Y" h: E! j6 N
}" K. T7 c6 S7 H
settextstyle(30, 15, _T("楷体"));
6 h! F" k( ~1 ?0 J% _( Ifor(i=0;i<5;i++)
4 x" F W3 E) S- q1 c{9 e4 ?- `! T6 q- o
switch (i)" a) A. _1 |- a" E: x
{
# X" Y5 p3 l4 C jcase 0:
5 t7 w) D( i6 fsetfillcolor(BLUE);
' K. V5 ~3 }/ o, k( F5 }, n* sfillrectangle(100,50,150,100);
0 V5 R( ]& ]5 g3 e" ]; T" @" o/ N9 couttextxy(160,50,"FCFS");
9 I' X& Y/ D5 r" Y) M( i8 T6 f2 gbreak;
- d1 l9 M# T# @2 m( R4 ncase 1:
, h7 z$ |) W) M' Ssetfillcolor(RED);
6 M5 U7 b: \9 h1 ]4 f% Qfillrectangle(250,50,300,100);
1 N% W- M) ?/ U" Houttextxy(310,50,"timeTurn");2 e% f: [! F* |) R2 o7 C# E+ K( }
break;
& t2 I) i! K# J5 B: A; Z7 Vcase 2:
' F) M' E3 _1 ~6 f/ Qsetfillcolor(YELLOW);' s% t N/ b' B. g: a2 S; s
fillrectangle(450,50,500,100);- z2 P& v0 d0 }* B3 c" T
outtextxy(510,50,"SJf");% h- r9 P) [4 Q
break;
0 O, c# l: l+ ]5 acase 3:
! n u, j$ U2 T" ?2 l1 N) s) n* \setfillcolor(BROWN);
- b" L2 d0 K H/ i' f: `4 z( [fillrectangle(580,50,630,100);
, F6 m/ U% [4 q0 H- \9 n% Z8 `outtextxy(640,50,"PR");: b1 P6 s" B0 R0 d
break;
( y+ [/ A$ ?9 dcase 4:
, i$ Q' R7 V9 R( `( rsetfillcolor(GREEN);
! V5 }- R% w6 Vfillrectangle(690,50,740,100);
! I, z( {6 {, j: k, Kouttextxy(750,50,"HR");
( c8 ?6 ~5 s% T' ^ lbreak;2 ^( i v y7 a9 G
}
- J; F+ i5 _# u8 y4 R- `0 Jfillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);
3 n, Z8 [, s! |1 _fillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);
. @3 ?2 {/ K# }( w) gfillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);8 X' x& P% ~( n4 H( o4 W* ~
fillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);
3 s8 C( \! h8 c1 o( o% D- |% i* J; _. [
$ l% A, L& n- r# G I) I- i}! n, J+ o8 i$ R- Z- V8 _- V
outtextxy(100,150,"吞吐量");/ R) `' O- A4 C5 z q
outtextxy(350,150,"平均周转时间");7 T# P% ~3 w9 y# r
outtextxy(650,150,"平均等待时间");0 k5 K( z1 v, N) \7 p* o+ G! ]! h
outtextxy(950,150,"CPU利用率");! e6 D P- u9 S5 b1 V* H
return 0;
! @" M+ y9 t: I I) p6 F- k' h}* u) | g& H7 a% q$ ?5 t
int MouseListening()
$ ^* l& Q# O" ~1 `1 l{
! |1 g4 y' b7 H# `+ C$ {4 JMOUSEMSG p;
! Q- B( b$ \8 P6 S7 P. I% a5 R2 J3 xif(MouseHit())
@) \ ~) n) e, O/ r& X{4 X% m0 e. ^7 S+ a$ R9 Z
p=GetMouseMsg();- Z+ r' i# y( E+ E' S
if(p.mkLButton==true)
# n' f! K. s/ m- z{
: `% _0 }+ f8 _ @if(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)9 E7 }7 Q6 g- ]. ~; V
FLAG_FIFO = 1;
. Q+ `; v# V0 d/ J0 j) I; |else if(p.x>400 && p.y>0 && p.x<800 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0): w ~8 ]1 X1 q; @# H3 C
FLAG_TT = 1;
2 F" N# ^; B, p" _0 {8 E- F& p |else if(p.x>800 && p.y>0 && p.x<1200 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
1 ~8 }+ Z8 O' p" m2 F+ kFLAG_PF = 1;5 V* s9 f, I' U0 G
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)
0 w8 x9 W: @# s0 J. }& fFLAG_SJF = 1;( I2 p3 v$ s6 z' ]; @; q
else if(p.x>400 && p.y>325 && p.x<800 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
1 U- T4 c# w* j e9 u3 W/ oFLAG_HR=1;1 ^% S4 t! |2 }0 z& L
else if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)
4 i# l7 t9 V8 k+ H) [! z{
6 N: k% l: x% j0 FFLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;" Z+ f: U# \3 s7 m9 R) l8 Z
clearrectangle(800,325,1200,650);3 a7 ^; D; G3 V3 b0 v" g2 L) y0 }
}/ v! E7 s) h3 a$ m5 m; }0 W
else if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )- e$ i0 {' c6 B% R, t
{
. v8 q# ~# i2 Y6 O. ?FLAG_show=0;
' s4 v) `9 t8 [" i0 Dcleardevice();
. a% A6 x* [: h8 wreturn 1;
, K+ [2 j+ X4 U% x% C; _}* Z# u2 N+ U4 J2 H- f% g+ L7 }4 _: L
}
6 \& C' m, p6 @ ]4 d% g9 D" m5 ?}% W J. F- s# G4 @$ x
return 0;; `( S+ [4 E/ Q0 k- B$ x
}
, H- e3 N1 n1 ^, [" W& T/ hint MouseListening2(int *flagShow,int * showTime)
% u, v& ^7 X3 K- h% {{4 y X T; S K, R1 m3 | J
MOUSEMSG p;" D+ u3 q/ x! L. h/ W
rectangle(1150,0,1200,50);
2 e2 l M1 ]2 t" W0 n3 ~! u7 Gouttextxy(1160,10,"X");
4 Q- G7 \) i: b0 Z W$ m2 kwhile(1)
V8 M6 C3 t8 j8 h+ F{$ @% M, l( f9 {9 A* \
if(MouseHit())
( Y: Z5 I3 o9 j0 K1 V4 B- d{' Z) g3 W7 j1 X3 u0 Z1 B( C- u
p=GetMouseMsg();/ m1 S; K# r; Y6 s
if(p.mkLButton==true)& U$ n& V5 R, p: V. m, G
{
: |1 u) r0 w$ g% m. gif(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 ). {+ H$ l% U, I& [/ m- f
{; ^; I* C1 i [- F3 o
(*flagShow) = 0;
! L7 k9 K' m2 t0 i! d% K+ j$ g. n(*showTime) += (*showTime);: c# l, b. o, C& [" _" a: m
FLAG_show=1;( D& e+ E! K; U) _8 g2 O! ]# l
break;1 g8 o4 V: i* N# Z5 N& C
}( n, ?( J- p/ C7 Z' a* j; f
, x: Y) q0 N! L' {) \* n) a& P- ]: H}
4 i6 g8 S& t$ M" C! ?$ h/ e3 [}
1 N/ ~- B5 ^" C5 S- `( ySleep(20);; }5 ?/ L3 a# d* l. i- W- d0 ]
}8 a* Q% E9 u" l: Q
cleardevice();9 L" Y2 J5 ^1 `- S0 A- j) S
return 0;0 D8 \; y8 G9 M+ t
}& o" i4 `4 j3 t4 I$ ?& y( f. \4 v
int drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)
0 O9 h. m3 ^" U! J2 i! B; ?' C+ W" \{
/ `* k2 a4 D6 i) x2 Z3 Estatic int info[11][3],num=0;1 B$ z+ q1 B' h: X
int i=0,j=0,pos[10][3][2];
/ o; q: H) u' afloat temp,t;
2 s% u* J" E! \+ e/ T6 v/ B//画按钮,不属于FIFO图的范围
) n: z( X7 Q" [1 T0 \if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1); c" G) i: ]7 q) `% z4 q5 x
{
s7 x0 f: c! Y7 Ssettextstyle(30, 15, _T("楷体"));
2 q8 L! _7 M3 z0 M: Srectangle(890,455,1110,510);' E# ?; k1 q$ L
rectangle(900,465,1100,500);1 h/ r+ Q" C3 D' ^% P
outtextxy(910,468,"查看运行结果");) {5 L2 l, s7 a1 X
}2 y2 @) A# s A; s2 T/ P$ z. {
//结束画按钮' z/ f5 J" p7 V& L9 p1 K5 }
info[num][0] = com;
0 p1 r: q I) c$ {; Rinfo[num][1] = wai;
" l# Z' C. L7 R/ `" hinfo[num++][2] = cha;6 M$ j, b& J& K3 f1 w1 x* l
if(num>10) //存储10个点8 G1 B! M: \7 M! c- Y8 j2 f0 ?
{: a, B) D3 E- K3 i$ G% P
for(i=0 ;i<10;i++)& f5 k+ V+ Y1 E
{7 e) ], m. \+ m7 ]- m5 |8 N7 u$ R. `
info[0] = info[i+1][0];- X4 F3 ]: S1 G
info[1] = info[i+1][1];6 Y9 o5 J* ?" r! _9 o+ y
info[2] = info[i+1][2];
& C* N- f; V5 f7 o n6 W+ z9 d. N+ W. |}
$ M- ~' X7 G% j( Bnum--;
- L: t; L: q. S( L& N. s}
3 h4 B: E$ v- W4 E3 pif(FLAG_show==0)- S5 w; L/ d. {2 h+ ]
return 0;
1 ^/ S1 w6 r, m: z6 wfor(i=0; i<num; i++)
b) \9 b/ m3 ~3 r8 C{# ]8 o* A+ J- @3 c/ U0 }! r
t = (float)info[0];2 X: m3 F% G# Q L e% Y9 u& E* i% c
temp = (t/101)*90;2 M; F# g9 }4 h3 z
pos[0][0] = (10-num+i)*25+x+100;- O+ C* y+ X, [# f
pos[0][1] = y+110-(int)temp;7 J7 y* l+ o7 E$ c" f5 w
t = (float)info[1];$ G2 O8 N. C# W0 f' Z3 \, z
temp = (t/101)*90;
$ X7 q' e( M# Q, N! E- r0 Ypos[1][0] = (10-num+i)*25+x+100;, U _0 _" N4 W. O/ U& C& N- ~
pos[1][1] = y+210-(int)temp;
/ e1 v0 U3 R: m8 C% h* M: c1 k( Y0 at = (float)info[2];$ ^" w7 b% Z, w4 ~3 R% N" y" ^
temp = (t/101)*90;
! y, ^; G+ N, B5 `3 epos[2][0] = (10-num+i)*25+x+100;
8 g) L3 x8 o2 T. ]5 d! Q8 Opos[2][1] = y+310-(int)temp;
7 l1 Z, F! I+ w% n$ G8 j# h) m, F+ B}
( [$ L+ ?; B* F( d ?% jif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)7 |: \0 |; ]2 \0 \# U
{8 p; j+ O* V X+ z, ?
clearrectangle(x,y,x+400,y+315);1 _$ ^2 q+ ~. C) w6 Y
settextstyle(20, 10, _T("楷体"));
% ]1 N% g) y3 ?; |: Y$ s- D% ]$ Brectangle(x,y,x+400,y+325);
% d$ w/ r6 F! {8 ~+ fouttextxy(x+40,y+10,"CPU"); //画柱状图
' {% _4 n, A. {$ @. E Qouttextxy(x+45,y+10+100,"IO");
5 o. x8 J( u. x2 b& k! \/ D! Xouttextxy(x+40-15,y+10+200,"change");
' l& G+ Q. x8 Srectangle(x+35,y+30,x+75,y+110);
8 R3 ]: O3 T9 A3 M* f* ^3 drectangle(x+35,y+130,x+75,y+210);3 k8 m: N" W& H, [
rectangle(x+35,y+230,x+75,y+310);
0 Q' g3 Y0 @% J5 B O6 }outtextxy(x+180,y+310,"FCFS");0 g B/ \3 r) w6 h) B
t = (float)com;3 ~ o1 E m- j, N
temp=(t/101)*80;
1 a# d6 g, `% {/ R" z% o" A& Afillrectangle(x+35,y+110-(int)temp,x+75,y+110);
* ^ v0 ]% e/ w* _! O4 dt = (float)wai; ]! M! a/ H6 k* u5 }8 u
temp=(t/101)*80;$ D! B! W1 O, N/ [4 I% b
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
& G1 k; i* [4 _9 M- W. v# {t = (float)cha;' \. A9 w+ Z4 y. c/ E! h; S
temp=(t/101)*80;
9 _- _. t0 b7 J) X9 A/ z0 {# Kfillrectangle(x+35,y+310-(int)temp,x+75,y+310);
2 H% |$ `0 T' D) }( Cfor(i=0; i<3; i++) //画坐标 high=90,length=250
" K1 i' {3 S6 H{$ z$ j$ C9 O0 K& q1 z
line(x+100,y+110+100*i,x+350,y+110+100*i);
1 C" a$ c7 w/ a. N+ @) N ?line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);( e, a7 L0 t0 C3 b- M
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
1 {+ O+ k, {/ n3 \# M6 a: q& `0 g- F& f
line(x+100,y+110+100*i,x+100,y+20+100*i);' B. v5 _6 H* r9 }- A
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);$ k/ D! L, P% X" |# I! m% e# ~/ ?
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);7 N3 x! y# D. w/ S* Q
for(j=0;j<num-1;j++)
0 J5 o* k { K{" y$ ^" M( x% R: w( X
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
, H& n/ j+ p" R, Cline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
! a: M' E J' e6 o7 J/ [- Cline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
2 l( u6 c* e$ G4 e! y! T; k}
- @; q1 u: E. h) S T& b/ ~! w}
/ l" K2 U, {% x, H" Q+ n}
" Y9 B; V3 V2 u$ i% ]else if(FLAG_FIFO==1)
# U) p& c9 q, _: x+ K- B# O{! x! n4 w0 V: [8 X8 [( B! ^& w
x=0,y=0;2 Q) M, s- W' w
for(i=0; i<num; i++)
* Z ]2 P% z& q{
+ b/ k& q' q: c( ~( E! V. ]' Nt = (float)info[0];
2 W2 W. r( q6 ttemp = (t/101)*180; p0 F1 s$ O% Y/ ?. ` B; t
pos[0][0] = (10-num+i)*50+x+650;% C2 R( J1 b% C; v1 ~" B
pos[0][1] = y+210-(int)temp;# R- H5 H1 f* S) |% R' z
t = (float)info[1];" s# f3 m' z! K6 a& P0 T c& t6 y
temp = (t/101)*180;
! W! P) R8 O1 u0 F# {pos[1][0] = (10-num+i)*50+x+650;6 T- }4 u5 x- x. Q
pos[1][1] = y+420-(int)temp;
* o/ A* u/ z: o: J" P: bt = (float)info[2];
/ B: a( ?5 R) b, dtemp = (float)(t/101)*180; a5 v/ r: q. @
pos[2][0] = (10-num+i)*50+x+650;
# n5 c3 X5 u, ]8 q5 rpos[2][1] = y+630-(int)temp;
# K/ {/ u0 @. l* h8 c4 Y}/ \1 R! {, b& v, r- e4 i! E) ?
clearrectangle(x,y,x+1200,y+650);8 _8 y: s+ g# ^7 G/ j. ~
settextstyle(40, 20, _T("楷体"));
% T4 Z: L) I* m a/ _/ fouttextxy(x+50,y+50,"FCFS");
) u: U* b" d' a$ m Uouttextxy(x+280,y+20,"CPU"); //画柱状图9 t' x9 \7 ?9 X# ]1 |$ ?
outtextxy(x+285,y+20+200,"IO");
2 w/ r7 M$ z& s) S: }9 oouttextxy(x+250,y+20+400,"change");* M: D2 h; u6 Z) ]9 t: t( `
rectangle(x+270,y+65,x+330,y+215);
& Z& ^2 _# j. I9 d6 g& {( o. Lrectangle(x+270,y+265,x+330,y+415);# C% P0 E n6 T+ ]
rectangle(x+270,y+465,x+330,y+615);
; J X6 H! M) B& R' m" N# Q, m7 y houttextxy(x+290,y+620,"TT");
" f9 L3 m- C; Z: M" q/ X% nt = (float)com;
% y, w/ m0 Z7 @4 jtemp=(t/101)*150;' [# ]6 k* s- |% ~, x
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);( U z @% E/ M% C" }, B
t = (float)wai;
. ?! p! g( U4 f- \7 y: z: ]+ D; mtemp=(t/101)*150;. g8 l# R7 {& a/ {% ~+ y }
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
/ A9 C P8 g) L( u! {$ at = (float)cha;# i& U* Q+ [1 `4 M
temp=(t/101)*150;
+ y* y7 X( _- Ufillrectangle(x+270,y+615-(int)temp,x+330,y+615);, d7 u6 I ]/ q k% O7 v' _
for(i=0; i<3; i++) //画坐标 high=90,length=250. {4 ^' e7 F; q5 L* I
{9 Q3 L6 q0 E) m* L- a1 v
line(x+650,y+210+210*i,x+1150,y+210+210*i);: s+ B, q2 N. a( l( V7 [- _
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i); v# s! t5 o# B
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
- H; P4 v$ I8 H( _ I& _) L) A7 K- E7 ^9 \2 U, Y& b5 x
line(x+650,y+210+210*i,x+650,y+20+210*i);
+ T) ?# F+ E v8 I+ S/ E3 Z! uline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);4 Z1 V" p4 [, w1 M o1 P$ c+ s; {
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
- x: h* L6 t- L/ O% dfor(j=0;j<num-1;j++). t; [/ u2 F6 j
{
. Z3 |* y" O$ b* m1 [9 bline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
o9 A& ]7 i& t9 v! E! i) [. rline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);! i; @- l/ m* }6 F2 e3 Z1 B
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
; [: B2 k5 B/ ]4 F1 k7 t}$ M3 L2 h- k# n, o* W. r, h
}
) Z# u3 d. h- b* A2 {, ?# j; X}
9 N9 N/ ]9 `4 j' k+ Y J3 z( P5 \: T; Z5 W8 s! g/ |8 X
2 Z* r0 W9 T9 {( f% V- freturn 0;1 U) A. o+ g) \; p8 w% k0 F
}
! W$ k' J1 ^3 @5 n5 p+ P; Oint drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)
9 M3 d4 B2 L( ]{. I; [( `& `: f
static int info[11][3],num=0;
/ b: z: q( }' G8 K7 G vint i=0,j=0,pos[10][3][2];- W% r" P- e3 y7 C
float temp,t;
; [0 m$ b6 f3 W2 z, i+ Y I& rinfo[num][0] = com;
8 {3 j7 o1 H0 i1 Y* v8 q0 ]) S2 Hinfo[num][1] = wai;
4 L0 q! j# v+ I( [. r) }9 {' N" Dinfo[num++][2] = cha;: q2 e& V A! ]1 z0 s
if(num>10) //存储10个点( c0 S6 p5 g& L9 d/ q h
{
& X- j! T& K: G$ n, k. y% j3 v- rfor(i=0 ;i<10;i++)
6 h" Z! `7 P0 ]. z, y; ^3 m4 j{
2 F# s$ `0 X! V2 z+ N0 l+ u# Rinfo[0] = info[i+1][0];
; v4 f* J: y! j& vinfo[1] = info[i+1][1];
+ L T% u6 M& ^0 B: Cinfo[2] = info[i+1][2];
3 s2 i1 J+ H- I, k( a* N}
- i. F! Q6 h7 l, Q2 L. K" J( snum--;
4 z* `# k# w, T( Q/ K}
8 V+ T: A0 b9 ~- D: L% zif(FLAG_show==0)% }3 o9 f1 P: \. _
return 0;2 F7 t4 o/ d# Z1 j! j
for(i=0; i<num; i++)
# a( c: X! S$ ?" x0 i{& L2 @5 [! Y6 V1 i% J$ i
t = (float)info[0];1 h/ i' i# l: U5 U" X' X) E
temp = (t/101)*90;
& ^# D! ^8 S' I7 j3 g$ ?pos[0][0] = (10-num+i)*25+x+100;: _5 h. f5 Y: A i8 p% p
pos[0][1] = y+110-(int)temp;
0 \$ Q8 N+ h( r k( J; q7 h$ ?t = (float)info[1];
; F/ w/ H6 B/ Q/ O; g, utemp = (t/101)*90;
# k; @, v' ?: Q4 G( e! [2 xpos[1][0] = (10-num+i)*25+x+100;
7 Q6 V2 E; z$ g1 S( ?, x7 rpos[1][1] = y+210-(int)temp;6 J" r2 r3 D' l/ M5 t8 X; v
t = (float)info[2];
( u4 h$ D, @) jtemp = (float)(t/101)*90;' ~4 A% _+ U$ f( B/ `6 \/ s
pos[2][0] = (10-num+i)*25+x+100;, k; d4 _" g$ P1 H2 a
pos[2][1] = y+310-(int)temp;! s, L$ L" }' U
}
2 d( G" G) ^; l: Z! ~" @6 |+ jif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)3 k+ s0 ^$ K$ K3 g5 O$ O
{
[( K- E* \* P4 v8 K" `clearrectangle(x,y,x+400,y+315);
$ ]+ j+ y' B+ v& v7 W/ rsettextstyle(20, 10, _T("楷体"));8 I: P% C& Y7 w' q# r
rectangle(x,y,x+400,y+325);0 t* o4 P! b/ g1 H
outtextxy(x+40,y+10,"CPU"); //画柱状图
6 z, T/ R `7 Touttextxy(x+45,y+10+100,"IO");2 A' D9 A& }* a1 W/ d& F
outtextxy(x+40-15,y+10+200,"change");: K7 |0 m& X5 S" B" u! }
rectangle(x+35,y+30,x+75,y+110);" e' J5 p" J9 }2 r2 o3 d! W+ N
rectangle(x+35,y+130,x+75,y+210);
! y! _8 i! T; h4 N! B; ?" crectangle(x+35,y+230,x+75,y+310);
1 m# X* _& a% }& P% h# `3 eouttextxy(x+180,y+310,"HR");
* B, N K9 S W. j( ~t = (float)com;
' j. h8 A s+ I2 ]2 Y6 gtemp=(t/101)*80;1 Z0 | R% J( J$ T7 R
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);/ F2 I2 E4 a$ g
t = (float)wai;
. ?; w* h% p8 Q5 _4 V1 L, }& q6 Vtemp=(t/101)*80;
( N6 K( W! `, F% x/ L# b! G6 hfillrectangle(x+35,y+210-(int)temp,x+75,y+210);) y- l* o* p' n( p7 y9 t4 O
t = (float)cha;
9 W6 F2 v4 g5 f* H. I& P( utemp=(t/101)*80;
* \- z0 T- H' y' I6 i2 Y9 L" sfillrectangle(x+35,y+310-(int)temp,x+75,y+310);
6 V5 v3 c& y" M' y8 V5 nfor(i=0; i<3; i++) //画坐标 high=90,length=250
Y6 W& o. H3 I5 L1 N% L{* }' Q- o' n, K, _! Y' V" ]
line(x+100,y+110+100*i,x+350,y+110+100*i);( ~+ i# k) l: X1 e+ G) O
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);: S1 b5 d+ U7 J) `" }
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);) `! S9 v( W9 k' @* }, Q' s
5 c; G/ r7 Q0 B: R8 D1 d
line(x+100,y+110+100*i,x+100,y+20+100*i);, h B/ G e" C( N7 w" Y
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);/ w" R+ m5 { H+ ]! \: y& i& t
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);6 X9 M, n" t( {5 r) g
for(j=0;j<num-1;j++)
7 K. W6 m) f1 Q{
% l4 N, Q2 Z8 f1 d+ Pline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
9 `0 n+ m u+ l4 nline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
' `0 i# r! R& H3 K4 `& mline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 7 y) B/ k: d( l
}' }! l( r" r) N: S2 X) b
} Y$ h# D0 ~6 ^' c9 Q+ i/ f
}
4 ^* s* X. t* a; g X1 Belse if(FLAG_HR==1)
6 h% P# {/ V& M. d+ R& ?0 ~{0 |( t2 w0 U) D
x=0,y=0;
- U2 @# W. W5 A' J. r, c1 Yfor(i=0; i<num; i++)% X c ^" |5 t$ Z' h
{
; A. O* N8 O- v" ^t = (float)info[0];$ U, G4 V0 f7 B, y0 e# q
temp = (t/101)*180;
c8 d+ G, g1 ]2 C% ~pos[0][0] = (10-num+i)*50+x+650;
! O# H& d$ H0 [ `. Opos[0][1] = y+210-(int)temp;
& _/ r% |% _2 t! T7 a) G0 Nt = (float)info[1];
# q/ o4 l$ E' t8 {$ Z: D( l6 Ptemp = (t/101)*180;- |- `: W4 q4 k* }% K
pos[1][0] = (10-num+i)*50+x+650;4 y/ c( J9 g0 ~6 q; k: r& s
pos[1][1] = y+420-(int)temp;
1 ]% k4 v$ B7 R4 p( u: F0 c& s' st = (float)info[2];
0 D' z+ r% M5 X7 V/ L$ Q. C7 Btemp = (float)(t/101)*180;
, m& w& P9 j3 {- w, ]pos[2][0] = (10-num+i)*50+x+650;
5 T6 E( S7 A) Spos[2][1] = y+630-(int)temp;" c9 R( {; C! w) d5 M' L
}3 @+ M9 h8 o2 Z+ a
clearrectangle(x,y,x+1200,y+650);4 h7 S2 R( _; D& v! a+ ]
settextstyle(40, 20, _T("楷体"));
& p! `- A! R- }9 s1 kouttextxy(x+50,y+50,"HR");
, h* w. d S1 ?outtextxy(x+280,y+20,"CPU"); //画柱状图1 Q$ J' Q& O" M
outtextxy(x+285,y+20+200,"IO");
}7 N" V% h. wouttextxy(x+250,y+20+400,"change");( Q* y, b+ j W+ r( y7 m6 M
rectangle(x+270,y+65,x+330,y+215);! Q1 r- u8 R7 o+ J9 Y+ q
rectangle(x+270,y+265,x+330,y+415);
6 ^) A; _* d! A1 I4 Erectangle(x+270,y+465,x+330,y+615);
; ?! ?7 B1 T, { N3 Z: O: C& n$ S- Gouttextxy(x+290,y+620,"TT");9 I2 T/ L' X- F- U5 x
t = (float)com;
& x/ c1 ?9 K0 y3 A9 F: h! ^5 Ctemp=(t/101)*150;
7 m& a6 U7 P4 Q% mfillrectangle(x+270,y+215-(int)temp,x+330,y+215);% i' K A6 e. Y8 |6 U) C% W8 v
t = (float)wai;
5 {4 u5 a- K% A: }0 mtemp=(t/101)*150;
( B. C/ X2 q- K J' u" k) |fillrectangle(x+270,y+415-(int)temp,x+330,y+415);3 g) p s' q+ L1 ^" X
t = (float)cha;. L- M; P9 b L- E! Q4 E
temp=(t/101)*150;8 L5 T6 a* ~2 p% G
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);( c# J, K5 M. h
for(i=0; i<3; i++) //画坐标 high=90,length=250+ |1 B9 ~8 X+ J" S
{
: ]' ], B! T/ T0 Zline(x+650,y+210+210*i,x+1150,y+210+210*i);
8 b$ y' A6 u7 ^' A0 Xline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);( ~8 n* V0 b3 T+ E, f
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);2 q+ s; E) r4 s6 b/ v
" ?5 @" U2 G" M- j
line(x+650,y+210+210*i,x+650,y+20+210*i);
2 U" `4 F2 Q1 h; hline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
- K- Y5 Y/ m R4 gline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);6 M% Z- V, ^; h# S5 L
for(j=0;j<num-1;j++)% A+ S: u" Z" W, u# ?$ ?
{: S" ]" O) H! S( R) j" f9 _
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
% a: V6 a- z( ~, l) @line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);6 `2 L$ k% l) X& B) J
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
# D1 h1 e$ d% c; q5 }}
% c9 K) e' S7 }# Z' N}7 R- } w& I- U
}/ |( j3 m- ^# w/ c1 }3 H
7 e; o4 V8 ~8 U3 \& D7 h
8 p3 Z! w. b+ y! A" Q
return 0;# c. U4 Z% s4 @. e+ u" S
}
8 |" a M! c: ]' y% H; A7 c- oint drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)
: J E. |& Q T h f{9 ^/ ]& C# s3 Z" {$ C8 H- ^' r
static int info[11][3],num=0;* ]% n4 O ^7 {' {* n) T
int i=0,j=0,pos[10][3][2];
! t5 N! G0 r0 U0 u' ifloat temp,t;( g" x9 ~* ^5 Q9 s. S) l- p0 s8 P
info[num][0] = com;. s h( X. ~, ^$ A: C
info[num][1] = wai;; b3 u, F$ F/ O, K
info[num++][2] = cha;$ t( g( U5 b! r2 b7 t
if(num>10) //存储10个点
2 m @( i# H. a- s h7 f{+ K7 P e; o# `+ k( R8 E
for(i=0 ;i<10;i++) b C9 a' P0 Y9 `
{
' b( ?; b. Y$ s/ a2 r6 M$ @ Ginfo[0] = info[i+1][0];/ ?8 U# Y" c& s' {# u' V1 w
info[1] = info[i+1][1];
0 j8 o! y( }: U6 d$ c5 A) \; Jinfo[2] = info[i+1][2];( W, J% ^% J! L/ f* @
}1 U% w& F% Q' {
num--;
* \! f9 {4 K) d* a! a+ h9 H}4 T& n3 U$ m' E
if(FLAG_show==0)5 I, X' d- m$ p# u1 ~( A
return 0;( d9 R6 B4 [ y% I* l6 N1 l
for(i=0; i<num; i++)
" {; |* y& X# I5 _ H8 l{
' I& H$ z" Y) S& Et = (float)info[0];. [3 f# A; l0 g k" _
temp = (t/101)*90;
+ E9 t: V7 R0 b, ]7 ~! |; h" Gpos[0][0] = (10-num+i)*25+x+100;6 b' Q1 V8 H0 {. r$ H' @9 G, e
pos[0][1] = y+110-(int)temp;
$ [9 ]+ z& l7 \t = (float)info[1];
6 m8 J, g% m, j7 F3 u. |temp = (t/101)*90;
3 o+ w) O) G8 A4 Y% A- Mpos[1][0] = (10-num+i)*25+x+100;8 x* W) M. j* s1 M( ^; A9 C
pos[1][1] = y+210-(int)temp;
d3 q% y2 W9 v. D- e1 ^& Ut = (float)info[2];+ \$ j0 S0 T; j# w' z" p
temp = (float)(t/101)*90;0 z/ {" D6 s6 m. y
pos[2][0] = (10-num+i)*25+x+100;
( ` ]" k8 {$ D; [: w, apos[2][1] = y+310-(int)temp;
3 M3 t# }4 H- x% Q" s* e}$ R# ]1 H: T' c; \6 s' c
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)7 J N2 O" R3 ~0 e; L6 B: Z
{, x: B5 d }2 ?! \# m
clearrectangle(x,y,x+400,y+315);
5 g. P! |8 J4 c5 R1 q* U( isettextstyle(20, 10, _T("楷体"));, Q8 ~' K% M0 O7 {. k: q
rectangle(x,y,x+400,y+325);
2 P, G0 O9 p6 C" x( oouttextxy(x+40,y+10,"CPU"); //画柱状图, `* J1 w4 d$ L! ?% K: B4 ^4 _! @
outtextxy(x+45,y+10+100,"IO");$ _* z% \2 ^7 f& k# ]0 a
outtextxy(x+40-15,y+10+200,"change");, [% O$ w% E/ u
rectangle(x+35,y+30,x+75,y+110);2 \) f" K2 z% x& F
rectangle(x+35,y+130,x+75,y+210);
1 |8 L1 K/ c2 h$ Z$ N1 d, M2 ]rectangle(x+35,y+230,x+75,y+310);6 [6 @* l9 h+ n6 m& {- Z# a
outtextxy(x+180,y+310,"TT");: ~/ x! b6 @7 n
t = (float)com;# s# Z& E N- O; I, |
temp=(t/101)*80;
0 Q4 \/ q9 h+ K* Cfillrectangle(x+35,y+110-(int)temp,x+75,y+110);6 ]3 r. Z7 c! T e d* q( T" Z
t = (float)wai;6 g8 x# m& O. |% b% c
temp=(t/101)*80;
6 E2 a; v( [& n# x$ R" pfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
1 S' ~2 y* b3 zt = (float)cha;
/ P4 e) a$ v7 `( I+ etemp=(t/101)*80;7 `9 `: }6 F* k- B2 o
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);& ~& K4 i# u7 c+ t/ B1 V
for(i=0; i<3; i++) //画坐标 high=90,length=250: T0 r9 \* ^% ^: c# q
{& V [8 L9 C4 }. u
line(x+100,y+110+100*i,x+350,y+110+100*i);
' {5 K/ J1 c* P. j" l2 `2 n+ {* l# Kline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
2 C3 r! c' e# m o; P# qline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
2 p/ Q6 W4 S. I( D r+ |0 R9 i# D$ g* N' s: @3 U! H/ j& c
line(x+100,y+110+100*i,x+100,y+20+100*i);+ r% |# `" q% `! `
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
* ~" s; H, m$ O3 eline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
, S" u8 I3 b' g1 ?! m* b7 C- Y$ Ifor(j=0;j<num-1;j++)" T4 O0 ?4 g8 l+ k
{/ G5 f9 P+ u3 c% P
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
' H7 z/ `' L% `line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);7 |8 }: N! ? g% Y/ t8 P
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
" u2 F4 Q* k, |2 a7 `: [$ K* v0 K}
- n0 t$ R6 R; E; f: z}1 _( u$ f2 p; A& B& F# b7 l
}. V9 a6 e9 P! ^( K
else if(FLAG_TT==1)1 g: o7 N7 h1 J" H* A1 y* J0 K
{ T5 J F5 u0 j0 J
x=0,y=0;* D% N9 S0 I6 M1 o' r
for(i=0; i<num; i++)1 J0 } |1 O2 N* w' E7 e
{- s9 M. J @ }# [+ W
t = (float)info[0];1 x5 Y2 `) L* Z
temp = (t/101)*180;, c& {# K2 p. X" V2 H
pos[0][0] = (10-num+i)*50+x+650;. b5 J8 G0 F! J( C
pos[0][1] = y+210-(int)temp;
0 P7 w: W, h- D5 v) h* ~$ t; e3 jt = (float)info[1];
+ u- ~9 v3 A2 }3 htemp = (t/101)*180;5 F% V( y" b; {# L& W( @* K
pos[1][0] = (10-num+i)*50+x+650;/ J2 ]( ?4 d( E' u7 o
pos[1][1] = y+420-(int)temp;
" F% V' C: H$ K$ H2 r4 dt = (float)info[2];
5 H0 y0 X% i, V/ otemp = (float)(t/101)*180;
0 N) B! l8 K) H7 c8 |: V6 M, Tpos[2][0] = (10-num+i)*50+x+650;
" f; {5 {4 o' w Vpos[2][1] = y+630-(int)temp;
. `. D0 E9 Z! M: m: E# I}- N/ ?" Y% j3 M* V
clearrectangle(x,y,x+1200,y+650);+ M0 V4 c1 `1 o F
settextstyle(40, 20, _T("楷体"));$ U% I% q- @, l! N; |
outtextxy(x+50,y+50,"TT");
( Q5 b, r) w7 z8 D! touttextxy(x+280,y+20,"CPU"); //画柱状图/ l# \& `- u" ^. @0 m! J/ Z
outtextxy(x+285,y+20+200,"IO");3 ~6 \ \6 [" M; P r0 f
outtextxy(x+250,y+20+400,"change");
$ O3 w' Y% ?9 A6 A+ @5 p* _rectangle(x+270,y+65,x+330,y+215);$ Q0 J' o0 h* w7 M; K
rectangle(x+270,y+265,x+330,y+415);
6 Z1 G- r1 f' }: J. a7 \rectangle(x+270,y+465,x+330,y+615);2 }0 b* f+ J T( f8 r
outtextxy(x+290,y+620,"TT");
* S& Z3 m7 _ |t = (float)com;" z. f, m0 V: `$ o% m
temp=(t/101)*150;
" I- R8 x2 @/ K' g5 t8 sfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
R- O$ q3 i' w% r4 M x5 R2 lt = (float)wai;
0 h8 M5 }/ T r1 x3 u+ Itemp=(t/101)*150;
7 @* E; d& E" Z% ofillrectangle(x+270,y+415-(int)temp,x+330,y+415);5 ^5 C) F" |9 u2 {# c. g- a
t = (float)cha;
4 b% W, q4 O9 b% Rtemp=(t/101)*150;
, C: F3 d: I) R$ ~" d& U+ pfillrectangle(x+270,y+615-(int)temp,x+330,y+615); `( `; g/ r9 P# P8 ^& C0 v3 \
for(i=0; i<3; i++) //画坐标 high=90,length=250
2 G: N% J i7 h T{2 o# o. F6 K/ S! ]* @7 ]0 y8 n; U
line(x+650,y+210+210*i,x+1150,y+210+210*i);
# d( @0 U$ {( H+ Tline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
- A- W& g1 O) j& e7 j jline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);5 @0 }3 w+ [/ }) k, ]* L
& _$ f# u. p2 v+ d# Q
line(x+650,y+210+210*i,x+650,y+20+210*i);
7 B# D2 I( D4 i) T! n- Mline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
- Y7 O. g& z' |) Lline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
4 [! ]3 a9 J( a- gfor(j=0;j<num-1;j++)
" `2 C7 }* Q, {% p1 s5 @{
9 L9 \. \! O8 g9 _& h" s# iline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);! \+ A% C* c! j
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
3 c U2 b5 [+ v% Q' y8 jline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ! c* v+ I2 T7 p
}8 S* O* V- @" u
}. O0 z2 @4 l9 ?; @4 j9 w
}1 S" Q% N G9 s5 j
/ |- C2 m3 \9 \7 \+ f
3 w9 U/ |5 [4 R# Z1 ?; y5 {2 \return 0;4 w+ i$ M$ w! o+ _$ e+ X/ [
}
4 k' Q2 o; N. a' s5 n# f! s0 L% @9 Dint drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)
6 a. a' \6 D3 q% L{
P, |0 D, U# Q( `. B" _- \static int info[11][3],num=0;
# X4 q! P1 o7 t5 G u/ Xint i=0,j=0,pos[10][3][2];
3 F/ f2 j4 B* z9 ]float temp,t;2 S7 W$ o# I: C- }8 ^( r% N3 W
info[num][0] = com;& B2 X% p8 }5 m2 X
info[num][1] = wai;
$ V% o( a q0 Y8 q2 w0 D, B; B+ Yinfo[num++][2] = cha;) @( h$ K* V/ Y, m8 s" m
if(num>10) //存储10个点
# \( [( N, T! Z0 s3 ]0 R5 j4 V{
: h3 x; \3 I' C$ Dfor(i=0 ;i<10;i++)
% Y& x8 N8 e: M# [5 R: T{4 B3 v4 x% B8 }+ E3 }
info[0] = info[i+1][0];
6 `; K& b+ h# n6 D. d0 jinfo[1] = info[i+1][1];
" V6 R5 b# D# D yinfo[2] = info[i+1][2];
% X8 O+ R/ C3 Q}8 I4 t" m _4 P& N4 R- H, D" i
num--;
1 p7 B* V/ O) c. `) q4 D8 C% R}0 s ^5 t1 o2 Z; r1 x! m% Y2 W1 h
if(FLAG_show==0)2 \8 [ y, V) U! U9 e; j
return 0;
; ^, V% P2 {7 hfor(i=0; i<num; i++)
2 Z4 P8 I* ~- u4 L4 F; o{
9 X! l$ R7 I+ g! pt = (float)info[0];
9 `, f. u! j$ S- X ]3 h0 f. K1 f) C2 c Ctemp = (t/101)*90;1 T* ^# k7 {8 n
pos[0][0] = (10-num+i)*25+x+100;3 p/ Y/ {9 E- {. Q
pos[0][1] = y+110-(int)temp;
4 ~# Q- l' d, rt = (float)info[1];( U Z5 U2 u4 u" z4 s( U& c3 a
temp = (t/101)*90;
1 [7 v( b! l$ J' ]9 Tpos[1][0] = (10-num+i)*25+x+100;
9 ^# M0 m P/ }+ E1 W0 jpos[1][1] = y+210-(int)temp;- }, e' D+ u2 s
t = (float)info[2];# u2 c2 b3 I2 }" G c" t7 [
temp = (float)(t/101)*90;# L( k( j8 q, i! S* \
pos[2][0] = (10-num+i)*25+x+100;4 j3 j, u7 f' R. Z0 f
pos[2][1] = y+310-(int)temp;
9 X: {' ]4 q, j8 j! l}, \2 b1 v' Z6 P# E
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)& x9 K( T+ V3 |" D
{5 _7 Z# v: w/ s2 l. L9 ^/ M, q
clearrectangle(x,y,x+400,y+315);* o! e4 o2 d3 S( u
settextstyle(20, 10, _T("楷体"));
6 ^3 W6 n/ ]+ L# frectangle(x,y,x+400,y+325);
* h9 @; M( R, a9 pouttextxy(x+40,y+10,"CPU"); //画柱状图
% F$ S1 q9 }: _ g, Q# ^1 |, R/ Xouttextxy(x+45,y+10+100,"IO");3 q* f' @2 R" `" T( F2 m
outtextxy(x+40-15,y+10+200,"change");8 D i0 e3 V. z& ~, M! O7 T q
rectangle(x+35,y+30,x+75,y+110);7 v- y" z$ d k9 u. h' O- ~ Q
rectangle(x+35,y+130,x+75,y+210);
4 L& e& ^) j* Drectangle(x+35,y+230,x+75,y+310);
* s0 K" D6 D& mouttextxy(x+180,y+310,"PF");7 v* R' g4 r) `% y
t = (float)com;3 I- R! J/ m/ T6 G7 b" E; ]. Q
temp=(t/101)*80;
0 _/ W, d0 c, Q# a. C" hfillrectangle(x+35,y+110-(int)temp,x+75,y+110);% p8 A* u" g0 H: ~2 ^, W- q
t = (float)wai;* {- Z2 ` ^" s$ P' k7 R0 w: J6 ?
temp=(t/101)*80;
7 P2 M0 G# f) K" Q2 N& o9 Ffillrectangle(x+35,y+210-(int)temp,x+75,y+210);
4 O9 _: ~# ]) A$ u) y* e, Lt = (float)cha;* \7 f- k# o$ ?& U2 h |" h: B
temp=(t/101)*80;9 p q3 ?3 q: }: m4 T
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
5 G$ _3 y! V ]- ]! `for(i=0; i<3; i++) //画坐标 high=90,length=250
; b# Q: [) A0 ]2 C1 W9 F{/ r7 m; M3 E. e- O
line(x+100,y+110+100*i,x+350,y+110+100*i);
' m3 W0 @" y: d+ W6 gline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
7 v, }1 E- x1 P& p) L( Sline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);$ r! F% q/ Q) ~' c) f
" Y# Z# O3 ^' b9 m0 I: h( S7 h
line(x+100,y+110+100*i,x+100,y+20+100*i);
. L3 P: [/ x: c \line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);& }- @. N8 C2 n0 _
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
- \/ g% U! Z! E' N& J+ ofor(j=0;j<num-1;j++)
# [8 ]0 ]3 M# ], z* J" w{: ]4 q3 S! e. A9 u% s, x
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);7 O- A& J& H, C$ t, S; I
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);8 x. b+ b" T0 a- a
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ! g$ U' U7 @, Z$ D+ q
}2 y7 o) @% f" _) v
}
4 J6 p( H" }, O" Q, m2 J; P}$ T8 m6 O8 K& K, A% A
else if(FLAG_PF==1); f0 y; v: }) ~" o
{
. b( |( o# m) s/ I- x( y/ Z5 sx=0,y=0;) U0 H0 D# r) A* T4 r. w' ]
for(i=0; i<num; i++)5 n2 g1 ~: R7 P! C' S. r I
{
3 N* o2 n( F* A9 Y8 Z: g" yt = (float)info[0];& ]5 m! {. D( l
temp = (t/101)*180;& }4 z N6 h J, {6 K+ W
pos[0][0] = (10-num+i)*50+x+650;0 N6 q0 q/ M1 q3 q, G
pos[0][1] = y+210-(int)temp;$ C! l0 \) d; ^* `
t = (float)info[1];
# ~5 \+ z1 [3 G' y+ a# y! x& htemp = (t/101)*180;
8 @2 M7 ^. |8 ypos[1][0] = (10-num+i)*50+x+650;
% P5 ?1 r8 D" opos[1][1] = y+420-(int)temp;9 Z: ]/ L4 @ w" a
t = (float)info[2];" n; H3 x. _; P0 g
temp = (float)(t/101)*180;4 e, ~( j/ S, ?: U6 P! A+ l% R- n1 {
pos[2][0] = (10-num+i)*50+x+650;' w# a. Q, I0 a
pos[2][1] = y+630-(int)temp;
" I0 ~1 {6 w8 R: ?}" \( o* V7 U* x) ]6 H
clearrectangle(x,y,x+1200,y+650);' I$ l6 I, ^3 A& m, O7 G L
settextstyle(40, 20, _T("楷体"));
" N: f- S, i+ ^- S. mouttextxy(x+50,y+50,"PF");1 h) I2 s' }1 l+ m/ a8 T5 V
outtextxy(x+280,y+20,"CPU"); //画柱状图
2 v+ i- x: n2 M4 Nouttextxy(x+285,y+20+200,"IO");4 I4 B2 @" f8 x) m/ d
outtextxy(x+250,y+20+400,"change");' X; X; f) z: ]1 h* b# p
rectangle(x+270,y+65,x+330,y+215);
2 j9 J7 m6 A4 e! J6 lrectangle(x+270,y+265,x+330,y+415);: x) a" B ]+ [$ A5 j4 b$ M1 g4 O3 V
rectangle(x+270,y+465,x+330,y+615);
6 u9 s; u- q# \+ routtextxy(x+290,y+620,"TT");8 S9 Z9 P0 m6 K4 l5 G. p
t = (float)com;
# k7 D1 p, w$ j( Ttemp=(t/101)*150;
* E. }1 ?% ], a' H! `fillrectangle(x+270,y+215-(int)temp,x+330,y+215);1 e9 P; |$ Y( c) y. i! u
t = (float)wai;; C2 J- G5 U" Q* w, s$ J, b" j/ L
temp=(t/101)*150;
; ]' \. z3 r, |# G q% A, P/ Yfillrectangle(x+270,y+415-(int)temp,x+330,y+415);7 ?1 G- c* f) e* N% o7 F8 Z
t = (float)cha;
0 Q. N0 b* X! L9 `7 E" R( ptemp=(t/101)*150;# M% {, K- T W4 T; G9 t
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);, H9 P: B `$ V* ?8 f
for(i=0; i<3; i++) //画坐标 high=90,length=2506 S) d2 @- G/ B0 A, ~5 d( b: L
{6 o N6 W# r- h$ W
line(x+650,y+210+210*i,x+1150,y+210+210*i);
, V( V3 r# `* o2 Eline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
3 ?2 E5 f8 Q! hline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);0 C3 N8 | i8 Z4 o2 d
5 }% Z! i2 V6 g3 nline(x+650,y+210+210*i,x+650,y+20+210*i);
2 w) w; ?3 b: m4 Zline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
+ E' D3 D: f4 `" fline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);. U* c( O" [$ H" c0 M/ v
for(j=0;j<num-1;j++)
' z5 R1 S; v2 B( P: n{# D6 \/ f5 ]* y$ b) p2 W
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
; N1 v! L5 {; ]6 t3 G m0 t$ M7 T' @line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);. y8 y; o; k# l
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
, c& O" g1 X$ O}
2 h& s- ?# m( L+ l0 D2 e8 J6 \}! q$ D; s$ _; O0 }) Q( x1 Q3 R
}
* J K# r! m* C2 w- `return 0;# F' {$ J7 z& K' S( Y
}8 j# Z& _. ]4 ]8 T
int drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)
3 g$ w/ Z: x9 J. I5 e" Q{
' A' v% M) l7 ?3 Q7 d4 j/ zstatic int info[11][3],num=0; y7 R1 Q# e! [8 k: m
int i=0,j=0,pos[10][3][2];, ~5 S6 v% r3 B5 Z* p1 Q: h2 l5 K
float temp,t;
0 h7 \6 q c; P; J) Qinfo[num][0] = com;( ^- z |9 [9 @! z0 G4 k/ F
info[num][1] = wai;8 R; R1 H- G) s5 Z8 f# S3 |/ k
info[num++][2] = cha;
" }! n' G$ L8 n2 q3 Yif(num>10) //存储10个点
! z+ F/ S6 q) B6 ^! `# |" { o{* s6 R: `- j( R. u# ?1 P% I7 O1 Y
for(i=0 ;i<10;i++)
7 B# h+ C1 l. ~5 F r4 V{
5 g) I$ T3 R7 Qinfo[0] = info[i+1][0];. j% d) U; Q& C6 }' E* o& l6 ~
info[1] = info[i+1][1];
0 A+ E# G0 l9 c8 x2 iinfo[2] = info[i+1][2];
: E& r* L# I5 U, f/ W}
9 V1 F( }+ x; ~ {1 V# |, Rnum--;& F; {% ^3 d0 [6 q3 M/ o w
}$ p: r) g( ~/ X$ `) K; z
if(FLAG_show==0)
. e$ S1 }8 X5 O* N h; Ureturn 0;, I$ e. B* D1 |+ ]/ [
for(i=0; i<num; i++)2 B+ k* K4 ]: q& M' Z0 s4 f" q
{0 v% u1 g$ m e/ I r+ y5 R i+ w
t = (float)info[0];9 i5 n4 O) B( W7 }, p6 m6 O7 P% U
temp = (t/101)*90;# p( x7 J1 W1 z
pos[0][0] = (10-num+i)*25+x+100;
. T! m0 O! y, @$ e' spos[0][1] = y+110-(int)temp;
1 A0 d9 P ]" \1 ^ ht = (float)info[1];
+ x& G: d; A- rtemp = (t/101)*90;
( i1 Q7 T. N7 L U1 N# r1 ypos[1][0] = (10-num+i)*25+x+100;5 F3 k4 j3 H( b. l
pos[1][1] = y+210-(int)temp;$ w |! f& U2 t" T& S% ~7 l k/ J
t = (float)info[2];5 ?% F7 \) u% C8 d( |+ o D
temp = (float)(t/101)*90;
( t6 x! q" a0 y6 G& V( n* apos[2][0] = (10-num+i)*25+x+100;) l$ F9 I& d# E* K
pos[2][1] = y+310-(int)temp;) {5 G5 p0 a% z2 r. |
}1 @4 E% G" Q' J0 ~8 ]7 X- M( n0 P
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)2 V6 d1 D" V0 m/ X* f+ g8 c5 a- K
{ ! W$ |; Q3 J3 ~" _: N3 T0 G: \- ?
clearrectangle(x,y,x+400,y+315);
" a6 t1 {/ a1 p/ T1 @0 ksettextstyle(20, 10, _T("楷体"));
( U9 }( B9 t N7 m* L+ d1 K" u2 q/ Frectangle(x,y,x+400,y+325);" F! x. ^2 L; s" `8 a
outtextxy(x+40,y+10,"CPU"); //画柱状图
# G+ K/ ?9 v; h/ k: Vouttextxy(x+45,y+10+100,"IO");2 u. P. A# x. `7 `# J* U, o
outtextxy(x+40-15,y+10+200,"change");# W" I* c; P# K
rectangle(x+35,y+30,x+75,y+110);
9 a+ e% v. p4 U3 [5 d( Z& w# Trectangle(x+35,y+130,x+75,y+210);0 s' p6 k9 Q0 Y! w* Z
rectangle(x+35,y+230,x+75,y+310);
) l" I7 P# j: A: D% y7 Vouttextxy(x+180,y+310,"SJF");
" y! P8 m0 ]( f) g" Xt = (float)com;, ~: \0 F9 Z- R5 p; x( P- t
temp=(t/101)*80;
4 S# D k6 [3 }$ _6 t2 Sfillrectangle(x+35,y+110-(int)temp,x+75,y+110);: K: x% N# d2 n
t = (float)wai;' ]7 ^0 X4 Z; l+ S# f8 \6 k
temp=(t/101)*80;5 l6 H) ^" l5 h2 V
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
* }2 r+ {( d3 D3 ct = (float)cha;
]& _* z1 D7 [temp=(t/101)*80;) g0 [6 t1 l7 E5 _+ ]
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);! _% \( i( q; K* B% N t& P3 l1 K* N
for(i=0; i<3; i++) //画坐标 high=90,length=250$ b0 X- J+ v4 n5 u; {' T% C# ?
{
* E" O0 J! S/ r3 X# {/ T% \line(x+100,y+110+100*i,x+350,y+110+100*i);7 u/ @! ]3 b/ O7 V8 T1 D
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
W: B8 [( Y# T# |. s% f$ O. T! B% Tline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);* |: H$ v8 C: b9 H) x& {' E- V
- `5 ]3 V& F7 }$ c& t0 @6 i
line(x+100,y+110+100*i,x+100,y+20+100*i);
! O3 X% F6 K d* {) n' D1 O* bline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);; v; n) S5 R3 C0 u- {# M1 H
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
0 f- h2 }) @! o; w( ~: V2 Y8 D* zfor(j=0;j<num-1;j++)
0 J2 x: k$ z, X8 K{
$ r; L5 V8 F' S+ \. o0 gline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);4 K5 F9 D! v" [8 |9 h
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);: Y6 ~' W. x9 I4 Y: @
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
4 f& }2 V. A7 g$ W2 s! H8 D}
9 v( R+ Q+ a9 h' z$ ]}
! d5 N R% M1 n}& N; m2 d L5 J! v, k; X
else if(FLAG_SJF==1): ?& ]/ q7 N3 m" }7 s% q" s" j
{
$ b) E! o: t# d" s6 z8 U, V2 ?x=0,y=0;1 [: }0 e0 k( a3 k4 g" b
for(i=0; i<num; i++)
- h* Q) U& @! n{7 V2 x2 k( Z+ o
t = (float)info[0];) E/ E( D% h* P+ V. l
temp = (t/101)*180;4 v. }4 H# [# J( ^& ?8 n' ?
pos[0][0] = (10-num+i)*50+x+650;
0 w' F/ w9 q' spos[0][1] = y+210-(int)temp;3 z2 G/ A+ P6 O1 @ P0 S
t = (float)info[1];
`8 W- F) c+ K+ U) {temp = (t/101)*180;
* k2 }5 Y% S9 {2 B/ Rpos[1][0] = (10-num+i)*50+x+650;
, G8 o3 V+ m/ h+ h( D, v! ^pos[1][1] = y+420-(int)temp;
6 V6 g5 b" k# q8 z; Ct = (float)info[2];, o! t' |' w% }
temp = (float)(t/101)*180;
. z3 o6 i6 l/ H+ T" b- bpos[2][0] = (10-num+i)*50+x+650;* E# f% y' P* \# R
pos[2][1] = y+630-(int)temp;( C/ W1 g" w& v6 U4 X
}9 ?* S8 o$ u. e
clearrectangle(x,y,x+1200,y+650);
, @. O( d6 _8 e% ksettextstyle(40, 20, _T("楷体"));; R4 c4 |* D8 p K# P+ s
outtextxy(x+50,y+50,"SJF");, {! `# Y7 y, P& @
outtextxy(x+280,y+20,"CPU"); //画柱状图
4 S7 Q( v4 M* | X/ Mouttextxy(x+285,y+20+200,"IO");+ ~( L" O M/ B7 Q" s( t" F; |; }7 l. z* G
outtextxy(x+250,y+20+400,"change");3 q# f% t; l b+ Z! O' k
rectangle(x+270,y+65,x+330,y+215);
7 `: R- l0 s0 I: [2 n% O* Lrectangle(x+270,y+265,x+330,y+415);- q: S S4 \- ?, C# @ Y9 j
rectangle(x+270,y+465,x+330,y+615);
Q# a, T' T" Z1 [& R k* qouttextxy(x+290,y+620,"TT");; Z+ d; Q" C& `$ D# _4 J) n" G0 Z
t = (float)com;0 g- W' R0 D4 U3 Z$ {% c* B+ b+ w& t
temp=(t/101)*150;( D, s7 p. P& v/ Z
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);% S6 Q) v- h) j( F. S" j, M
t = (float)wai;
/ b' q% @! D' B: j. X1 ^& Xtemp=(t/101)*150;- x6 |" j/ {, g
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);% A- v9 N: p" {
t = (float)cha;4 y: n) x- E1 K: X; T$ y
temp=(t/101)*150;
% |% t5 {$ E# X# Y j; g- R4 hfillrectangle(x+270,y+615-(int)temp,x+330,y+615);) V; p) {; z. Y+ w5 U/ V6 f( J; ^
for(i=0; i<3; i++) //画坐标 high=90,length=250 J* E5 ?( I3 [: G( f- |9 O, e3 Y
{
8 g0 j/ b4 {! ~+ L: \, V1 Yline(x+650,y+210+210*i,x+1150,y+210+210*i);
0 ?( E4 |& v' y5 O7 ~: T7 nline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);! O* i2 o2 K6 q8 B
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);7 q% Z! s& C: u6 j
6 g c) G0 n8 E* {6 |! O& ]
line(x+650,y+210+210*i,x+650,y+20+210*i);
& O4 X, |. ^ a$ G9 i+ Aline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);& {, [) ~$ G8 i( C9 x
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);( a5 o+ v) v! m$ I
for(j=0;j<num-1;j++)
+ H+ H# V. \/ m5 s{
, A, F" e' b5 j8 y4 B; P% jline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);, v2 r3 A' X' J
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);. N* J- ?& K$ u# V3 C) i- I4 F
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); . g5 f* s6 f3 c1 C
}6 z2 X6 J' o( x! q
}
& b1 V3 c) _( |- {; Y- ]0 X1 W}
+ m- C- s$ H- f1 d7 W) ?! \return 0;
8 d$ n, B0 D0 R+ T9 g! a+ }}$ e0 y- w% e! ]/ g4 J$ \
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)$ D8 C4 p2 E( [; R" o X
{
# E4 W) i/ e" k5 o( tstatic int compute=0,waitio=0,change=0;3 x1 M. t+ ]% N' r! k9 h! k; J8 U2 ~& H
static int computeLast=0,waitioLast=0,changeLast=0;% @: Z7 s2 |% J8 A
int i=0;9 E+ H+ L& i# r# y4 p
if(draw==1)
5 Z0 \5 Z: ^" j' H0 \; _& z% [# X{& v1 \5 M3 W z7 I! f& ~% X" _
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
2 Q9 n, p+ c7 y9 NdrawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
' k7 a) D/ F" g0 u+ f; W/ icomputeLast=compute;( i1 f$ Q/ n( f g
waitioLast=waitio;& X( S9 b+ \" ^( p
changeLast=change;
* Y, D3 n. N0 s% X- F: ]}
% i8 c7 r. a1 b" Tif((* memory).p[0].flag==ready)! c+ p" n! d2 D2 u# {
(* memory).p[0].flag=computing;
- R4 u: j# n0 Z3 M7 \5 eif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)2 u% s/ M* t& N* C1 C- j. p
{' F) x9 K' R6 S% i/ d, P- k: v
i=(*memory).p[0].computeNum;# Y( C9 x1 _7 Q h6 M
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
+ b1 X, I4 F" z8 u9 G8 k( F, ]{
7 F, J$ Z, |+ n) l9 g) i# b(*memory).p[0].flag=IO_waiting;* l2 _$ \$ {6 O* n- ]/ t
(*memory).p[0].computeNum--;2 [" h8 g& c& I
change += exchange_IO_Compute;
0 Q: U' W; f) a* A5 fcompute++;. V Z( l9 s( T6 W4 [1 `! t! v
}7 u( B8 ~ Q/ l c5 t0 }/ H+ ?% c
else# h' C, e! q" @( d7 S
{/ j1 O' U4 K7 _) a" l
compute++;
B. n$ e! r/ H X9 t7 ]2 d}
1 p* F o+ [0 j/ M% a}
# y) o( T o# w f' D1 d9 `2 Jelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
2 w I7 _0 r2 l! t) s5 `% h{/ S- ~7 B8 J1 S0 i7 S
/ _. W9 n5 }$ M1 x( T& W; {i=(*memory).p[0].ioNum;
( N% i4 U& R& T/ ]& ~# dif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed: k! A# }1 A) v- y2 N& I
{1 z; N- O- `$ e2 P; Y
(*memory).p[0].flag=computing;
9 I7 Q9 n% R$ |# a(*memory).p[0].ioNum--;
- q: z9 X9 |' p+ |6 B8 t' x3 Mchange += exchange_IO_Compute;: M" b( C. y/ D, `5 ?. t* `, \$ g, q
waitio++;8 h, H. P; ~: H* x: J; f" O* \
}$ i2 z* w: b% o
else
$ g j ]! E" c: a5 |: M( R- z3 X" H{8 W- q$ C6 x$ J- A+ T, u8 q4 U' d
waitio++;9 _4 b& b$ [! j2 K- K( F4 n8 P0 {
}
5 U4 M- t$ S$ {+ g* ]* ?}
2 x" \& `# N! yelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
$ i2 d- N) N0 a% L3 l+ G{
; l+ j% f$ \- [( f' |+ ^+ ?7 ](* memory).p[0].flag=IO_waiting;
8 g$ v! }- Y8 j+ t8 f& l# D, Lchange += exchange_IO_Compute;( W$ d$ `7 K( |0 V! ?
}* `& @$ W5 S/ ^: X% a3 m
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
( f Z1 H, S: O7 A{8 p; ]1 @; G4 g! I
(* memory).p[0].flag=computing;$ h, ]% t+ O% \4 ~& [: l3 F
change += exchange_IO_Compute;* Z9 ]+ z$ ^1 X( N( _
}- V0 S d0 b2 P
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
! j6 x7 d9 L( `0 J; {+ o0 r4 m{& r; ?" F5 A* Q% y/ X* N
(*save) = (PCI*)malloc(sizeof(PCI));
& I, _/ O+ S' z(*save)->next = NULL;
0 V( C0 R- W7 X% r(*save)->processID = (*memory).p[0].processID;0 I# j+ ^3 u6 ~5 q% x5 ?. x
(*save)->comeingTime = (*memory).p[0].produceTime;5 g0 W! R% S" j. P
(*save)->askMemory = (*memory).p[0].askMemory;
: \- y% c P4 W(*save)->compute = compute;* J, r9 k; }6 k
(*save)->waitio = waitio;
: N u* {! t( p5 q: c(*save)->exchange = change;
' ], g; B" W) y8 N(*save)->completedTime = systemClock;
f& n+ e, M) r% r( N2 [(*save)->runningTime = (*memory).p[0].runningTime;) X& u/ \6 I( V; u
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;
" H% J5 [1 |- B5 mcompute=waitio=change=0;
k% \: P! _; C: B: \computeLast=waitioLast=changeLast=0;
( K Z U7 S! EHigh_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);
! _+ c4 U. x( i9 }! ichange += exchange_process;4 ^- Q3 J' S8 [' q$ u
return task_completed;
6 }; `$ E6 S0 j9 J1 F6 S3 C. B}
: w5 r0 J2 ^/ P& v; Relse
# C1 y: O' W& b5 i; d' Q( ?return task_not_completed;
# x4 L6 w+ e5 B( z4 j; e}# \9 @+ q! L% X3 _' k% @' j
int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)
3 I' r. `5 O( T& u' p7 y5 _{ F- _8 k' ^ u+ Q. d8 l
static int waitTime[initProcessNum],i=0,j=0;) I# X. @8 a5 u4 q4 m0 E: q
static double HR_ratio[initProcessNum];
9 g/ q" g# }3 {% kif(flag==0) //初始化数组
5 n8 g( V' ?. F% Y, X{" X6 q- {/ e6 X) t9 H
for(i=0; i<initProcessNum; i++)' ^# c9 |9 u4 y$ G& G
{/ N5 B* }7 U3 M
waitTime=0;9 K( Z4 k5 E& E, c% M
HR_ratio=1;0 v) H T. ~$ \2 Q& H6 s- A/ ]
}1 b6 n; L" B4 G$ l1 m5 O7 m
}2 B9 L8 P" M0 F
for(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比0 \* f9 h( S* { c
{
. r) p" ^8 J7 W+ T5 ~3 X6 owaitTime++;
- W; n. Q0 X8 X. ]HR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);% z2 Q5 O/ i# b$ c& a: U
if(HR_ratio > HR_ratio[j]) P: f7 I, d M1 S9 A
j = i;6 u# G5 g# R( k! }
}
$ p5 g# k! s% M, U9 Sif(dispatch==1) //需要调度一个进程到内存中执行4 Y- c+ C' O% v( w1 H
{; E& P0 `3 V4 E1 P& Q8 u0 ^
if((*storage).p[j].askMemory < *spareMemory)# _. u& T! F5 T; E
{* t1 n2 o3 X1 J1 Q1 T( t
(*memory).p[0].askMemory = (*storage).p[j].askMemory;( o5 |# {8 f- w: H
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;) {4 e1 g7 b5 S. k6 U- @
(*memory).p[0].computeNum = (*storage).p[j].computeNum;& \0 u2 q, \2 l, ~5 o' Q1 O/ y9 A
(*memory).p[0].ioNum = (*storage).p[j].ioNum;' E. M5 u0 I6 F$ B; Q# x; }
(*memory).p[0].processID = (*storage).p[j].processID;0 Z' ~7 e. C7 L# A
(*memory).p[0].flag = (*storage).p[j].flag;0 I% ]% Y" B/ m
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
4 s9 p9 g; R0 @3 h) `. [(*memory).p[0].computeTime = (*storage).p[j].computeTime;
: x& {2 m1 g5 u/ b(*memory).p[0].runningTime = systemClock;
; O: c. j- @: }7 T(*memory).p[0].produceTime = (*storage).p[j].produceTime;3 g5 b) N0 e X8 M- g9 v5 N0 E7 U
for(i=0; i<(*memory).p[0].ioNum; i++)- ^" l$ O3 A! s# O2 }
(*memory).p[0].ioClock = (*storage).p[j].ioClock;2 ]- G' ^8 v0 n' ?+ D
for(i=0; i<(*memory).p[0].computeNum; i++)
3 T; }: n8 Y; J( s' _3 E1 S0 N(*memory).p[0].computeClock = (*storage).p[j].computeClock;
0 d- k' S; [$ M( K0 k$ H(*memory).proNum=1;
7 o+ \) ^' X' a$ r*spareMemory = *spareMemory - (*memory).p[j].askMemory;
9 }1 [$ [% S* v kproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程7 ~- S( J( S7 h& R" s4 {
(*storage).p[j].produceTime = systemClock;
5 M) a8 _) z; d* y% Z$ aMAX_COMING_TIME = (*storage).p[j].comeingTime;1 U; Y u* Y2 O3 `7 ^ w
waitTime[j] = 0;
+ H* C) F A! T* F5 B: j( Z5 `HR_ratio[j] = 1;. I0 W: y1 t: G9 Q; e% i" m
}
0 x7 v8 X' _' @' F+ ]2 y Oelse. e, y! V. `- Z3 ~
{
" V% b2 x* R j C4 oprintf("A process ask for a memory overed the system capacity\n ");
. k' y4 }# I* v0 z5 }) vexit(1);
' \4 s* | O( ]}
3 H7 O" G' E l0 ^6 j/ X& p" E}$ L" F( I+ a5 r5 ?( P
return 0;
% `" N1 u* q3 B) r3 u}
7 S+ m4 a; ^5 z+ _int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
1 l1 A4 U1 t6 U! W{" p( V; I7 O }8 U5 p
static int compute=0,waitio=0,change=0;( x% N! `( }4 C% s! t3 d' i
static int computeLast=0,waitioLast=0,changeLast=0;' L, c. Z8 p" r( ?9 [' ^# }) ?
int i=0;. C, m$ X) ~4 w1 q! {8 n
if(draw==1) k5 M/ Z6 M- O1 B+ N
{3 ^3 r' H3 F* U
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
7 a! v1 Q* M# w" k3 F% S4 IdrawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
7 @ X7 B' Y8 t b' q
2 ^! b- u6 z l2 d
, C) w& m9 }7 d& A' W$ T( v" FcomputeLast=compute;
7 t4 v4 J8 v/ T5 ]9 ~6 f9 fwaitioLast=waitio;! g' a Z9 |; x# x# U
changeLast=change;$ P" j- |; a" ^6 S5 | M
}
; r/ {) L# U) j0 e9 m {$ F+ eif((* memory).p[0].flag==ready)
+ h6 m3 i3 J: }) ^: D(* memory).p[0].flag=computing;
; T W, s/ b/ fif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)" {% X) D' c' s/ S
{
& T; {! p) I# q" [5 [$ bi=(*memory).p[0].computeNum;
4 r$ i4 J6 O; B( C) x0 G! Jif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
7 E% y. b ?, Q1 z! j8 z; ^{
9 w* l' ^2 d3 }! F: z(*memory).p[0].flag=IO_waiting;; S/ z5 A/ A0 I: u# t6 O
(*memory).p[0].computeNum--;
6 S1 n s. h9 i7 k- D# }# kchange += exchange_IO_Compute;9 C6 H, l+ ~! m5 i1 f
compute++;& U) a6 |7 N! e
}
9 ?4 h* r8 W2 L: T4 helse
% s* e# X1 e' f8 F8 H# i4 C{+ B0 F$ u; j# v% Y; |
compute++;
, n) h$ i7 D# ?0 h+ `& p8 r}
& x+ R7 B% o: n( I! v- x}
' k' i1 i1 X* w8 [else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)4 O& ~4 x* I" z0 e. }6 a# w+ G
{
( r2 E- L& V5 m' ]) t
1 |! `4 x" e6 o' [* `$ N4 h, ti=(*memory).p[0].ioNum;$ Y. O, W- i% J0 V8 | o1 @1 [' R
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed0 O4 l! e9 W7 V2 ~2 @
{
% L+ x! Y' { a, f. @& h(*memory).p[0].flag=computing;
0 l& \; L% T: j) f8 Q' ]9 |(*memory).p[0].ioNum--;7 C/ [6 x! a4 V3 n" H) F6 s1 H
change += exchange_IO_Compute;2 k/ W* k. {3 H* \7 @* H5 a
waitio++;. F8 S; h( B1 C
}0 Q; H5 j7 i4 B5 B& v* j# c! }
else+ J9 T4 r. T, I! X3 j3 ], _: k
{$ d" ~9 p: A# V6 j: o: K
waitio++;9 p0 G* k! e' @; x
}
! I3 v, m" f6 k) ~4 w}
! \( N+ A- X0 f" z* Felse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
, i+ o3 x( }5 j2 E, \{
5 }9 _) ^7 c: j" R" b6 X7 I(* memory).p[0].flag=IO_waiting;
9 U" }7 f: R% H3 H) Y2 Z% achange += exchange_IO_Compute;
$ f% E6 c+ j; W2 [; t}( D0 D% P$ P7 e4 ~
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
9 u5 U' |# s: h2 W{ Q0 X1 q/ b; H7 f9 i! A( F/ C! y4 ?
(* memory).p[0].flag=computing;- f M M( v5 [5 d. a7 X
change += exchange_IO_Compute;
1 q$ S, F& d: W: E \}$ N) p) Y2 h G3 e8 v
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
3 D' `8 V7 o2 _6 J( M{
: ]: M) \% J5 H' d3 ~2 Z, _(*save) = (PCI*)malloc(sizeof(PCI));
; k( [3 }6 M* m. ~(*save)->next = NULL;
: s: p8 \2 X) W! B(*save)->processID = (*memory).p[0].processID;. i$ N2 P- I- U* P4 M' ^* H! ~: m9 ?
(*save)->comeingTime = (*memory).p[0].produceTime;# v: d: n8 ?8 u8 }% j/ d- Y
(*save)->askMemory = (*memory).p[0].askMemory;: p0 ] E t U! l
(*save)->compute = compute;3 ]# q w* e! y) m& e* k
(*save)->waitio = waitio;; X9 N% d4 \! W0 J
(*save)->exchange = change;
5 [0 S3 u) R! V. r- B6 P! v(*save)->completedTime = systemClock;% F, X( x( A7 j" I8 m
(*save)->runningTime = (*memory).p[0].runningTime;% V# H: G; n" I/ |9 W& `0 }
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;6 z% Q; z& S1 Y# o o
compute=waitio=change=0;) L- B' x) W$ S8 H# d
computeLast=waitioLast=changeLast=0;6 m# d0 I; x/ x6 x. L6 E, i
Priority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));4 w8 x* ^0 H7 N8 b, K( R( a
change += exchange_process;8 h3 z, v5 y% L3 Y
return task_completed;
5 b6 |, z2 w" t% _: c6 ^) x}
$ x, _+ b3 C8 C: n) D+ V- K; Welse$ _( j3 Q- C8 a/ u
return task_not_completed;9 a+ j L/ i6 k2 Y1 g& L3 H, ]
}8 p, S5 S" j5 q+ M. `! c
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
' X! m. b6 S! k0 V! R, a9 I{
0 e2 O, C; e/ }3 j; G4 |* _: ^int priorityNum[initProcessNum],i=0,j=0;5 T, F1 V* n7 l. y
double temp=0;" @4 h9 p2 r& Z' T1 p4 }
for(i=0; i<(*storage).proNum; i++) // setting priority to each process0 p9 F+ ]0 o4 J0 a9 F: h: q% j: ]
{
0 D( U) `' l8 {6 G% x3 v% I6 Gtemp = (*storage).p.computeTime/(*storage).p.ioTime;
" a+ i/ T! M: u+ H9 A& }$ |& J. F. Iif(temp > 0.8)1 s4 x! g8 Y, n
priorityNum = 6;
% N( s' s7 i! r# m4 D9 S8 i) v7 O1 O6 celse if(temp > 0.7)
+ o% ]# I& Z+ j5 u9 j KpriorityNum = 5;1 E0 v" I, P0 G' J9 q" h+ N
else if(temp > 0.6)
4 U$ m5 v+ A1 N7 q& p5 ]" [priorityNum = 4;
, @* l4 z( w* B2 V: _else if(temp > 0.5)
# N$ q/ Y% I6 J: m$ ?' ]6 s4 R3 w% UpriorityNum = 3;' J3 D! D: x3 c' m4 O H4 j
else if(temp > 0.4)
* Q, c U& m/ o6 ipriorityNum = 2;" q: h- q1 B! ] }0 D
else
" x+ L$ S. ^; EpriorityNum = 1;* Y( V8 n' h5 A$ {5 r8 R$ ?) R
if(priorityNum[j] < priorityNum)
8 N% ?% o5 p$ P6 d3 Aj = i;
, `# }% I9 x& b6 D. G" C* c}
# t/ _& ^- X, d4 A( Nif((*storage).p[j].askMemory < *spareMemory)1 ^) {) W0 T1 L, P7 S
{
; R; X* R7 L2 d/ p6 `" l(*memory).p[0].askMemory = (*storage).p[j].askMemory;
$ B0 u p6 l2 Z) A0 Y4 }(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
/ c" g$ u! t6 }! r7 s6 P6 C' m, c(*memory).p[0].computeNum = (*storage).p[j].computeNum;
% _. I8 T7 g$ D(*memory).p[0].ioNum = (*storage).p[j].ioNum;$ x2 }: s3 t: ^3 w
(*memory).p[0].processID = (*storage).p[j].processID; Y/ ^) w% n4 }
(*memory).p[0].flag = (*storage).p[j].flag;0 J) y# Q/ n' ?& j d* m
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
% L' P3 j& J+ b+ X(*memory).p[0].computeTime = (*storage).p[j].computeTime;/ Y2 N# @5 B' L1 q h
(*memory).p[0].runningTime = systemClock;/ H. i' Z- R2 s1 k
(*memory).p[0].produceTime = (*storage).p[j].produceTime;
+ U* L% c! g! ^ v- S: jfor(i=0; i<(*memory).p[0].ioNum; i++)
" a% n& ]! }# D$ V* Q% D(*memory).p[0].ioClock = (*storage).p[j].ioClock;
! L& g* u0 B& J2 e9 E3 |for(i=0; i<(*memory).p[0].computeNum; i++)
1 \/ Q y7 }! O; S7 D(*memory).p[0].computeClock = (*storage).p[j].computeClock;% i8 j0 I/ s8 m G+ Y
(*memory).proNum=1;
( |8 N# K* H3 i( A*spareMemory = *spareMemory - (*memory).p[j].askMemory;
; h' _- [* ~8 O. N, `- p7 Qproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程0 R( U- K+ x3 j$ b; y% h8 M
MAX_COMING_TIME = (*storage).p[j].comeingTime;' f. S$ R( F. g; a) W/ F* T! i, F
}4 }) K+ ~. Y( W, ?9 s
else
- H4 d* D" G* e6 ?9 v{
) s* s% t! t2 }( h Eprintf("A process ask for a memory overed the system capacity\n ");
% q5 v/ S5 F, \* a2 Lexit(1);
# v3 d: P* D7 H/ x9 q, n}7 q5 ?/ {8 z5 _2 C
return 0;' L* v1 N, N1 D
}: S x! ~ N2 Z1 A7 M; w
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
( Z' g. P" q! Y. F: _{
" D0 Z; i# K2 y) Tstatic int compute=0,waitio=0,change=0;0 E' O3 p) Y1 C$ }2 w4 m
static int computeLast=0,waitioLast=0,changeLast=0;; A4 A/ e3 D' n# q) Q' l, k
int i=0;
. c+ {! u8 F+ |% H4 ]if(draw==1)" {0 E7 U6 q) _: r% q
{
o6 G6 V* a; X. S& Q0 a//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
- q' ^5 `- Z& a- M# ~0 YdrawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);. O; g+ W- J' z' O/ c
/ V+ o; Z2 K$ [
* y/ h. S/ z/ s9 E; k3 r- \: ?: fcomputeLast=compute;4 p U& Y$ `. t' W$ P: [* a/ a- q4 u
waitioLast=waitio;
5 }, f% @7 G. r$ jchangeLast=change;% i A' F, t- p; r- |) o# ~% V
}( x5 D5 Y9 U3 K5 s- r2 A5 G
if((* memory).p[0].flag==ready), x4 |* R7 z5 C; B \) y& a
(* memory).p[0].flag=computing;+ L, w# c4 F+ r+ f4 C
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
6 P" Q" ?4 e- M( x9 Z{ n: R4 S4 G/ p! r% s
i=(*memory).p[0].computeNum;; x" B. k: s0 ^
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
2 _* {9 v7 T- R( Z7 [{
9 I% R& Y! c- d! c(*memory).p[0].flag=IO_waiting;5 `: I* U" s! a. F( y
(*memory).p[0].computeNum--;4 G3 U9 o- ]/ \8 x4 ~' a
change += exchange_IO_Compute;7 c3 A, t- d# `/ A. ^( B
compute++;
# T3 b0 j. ?2 D5 m; q9 \}8 C P: M9 y4 ~: ^
else) v. ?/ w& M9 u
{
2 ]" R! S M, y, k9 acompute++;( Y( g% @" @7 R3 h
}5 B2 i! T2 V' j9 u, i
}8 ~" j/ F* K* L; i
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
+ F9 L/ _+ i$ p8 s% U1 @; L{
7 ]; a4 t! b+ m# L2 U! S+ w1 S2 H" ~3 @; [7 U% o. U
i=(*memory).p[0].ioNum;
' z/ t) x: f! t% U- g: H/ r$ D6 _if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
% M/ v8 X3 X1 k( V{9 S- Z: \9 [2 V; A+ @0 k% o7 L0 ~; S9 m
(*memory).p[0].flag=computing;& H. j& a" _+ d H% L
(*memory).p[0].ioNum--;+ J+ @) y ?4 l! O" ~+ `- x2 j+ h- [
change += exchange_IO_Compute;
7 R- K& y6 X- v3 p, n5 twaitio++;
% p# y( J' r+ Z# o& _}9 V2 w6 R" M% c4 U7 [
else" _( {7 b& i1 O" A- }+ d, A
{- O: C* a+ l% H: v0 S' q
waitio++;& P1 g0 o; F. M5 z
}! a6 W+ x& _+ |8 k
}
' s- ]" G" d A3 c Lelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)3 W- t+ [% N8 Y3 r3 ^5 f
{
) i: I' D& z' @$ {! N, z7 P(* memory).p[0].flag=IO_waiting;
: \* i" ?6 W5 e% I# b0 [+ qchange += exchange_IO_Compute;/ U" ?" h+ e1 O E9 W; R" Q
}+ ~3 T' f# N) u3 u6 Q% n& x7 u' i8 q
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)1 `, x5 U$ h" M' X$ H3 y; v
{: Q! p+ b7 B; B! B4 [0 B0 R
(* memory).p[0].flag=computing;
, f2 @- I0 n( d1 o& o" `change += exchange_IO_Compute;
: v; l9 R! x' q5 \}
z2 G) I8 U- {6 Kif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
" v4 @6 v" }. {9 e/ B6 B% \+ \{
) M4 `6 C0 S# {0 S, a: A2 w9 U(*save) = (PCI*)malloc(sizeof(PCI));8 }8 L+ z- x6 ~/ [" i
(*save)->next = NULL;
4 z1 Y0 [, Z p& f& k% _9 D" l# `(*save)->processID = (*memory).p[0].processID;( Y. X" \3 z0 o9 m& X6 W
(*save)->comeingTime = (*memory).p[0].produceTime;# O2 N, d4 ^; S) @6 Z8 J& Z4 @
(*save)->askMemory = (*memory).p[0].askMemory;* g+ ^/ }$ [6 f8 I
(*save)->compute = compute;
4 ?. D: ?, F; R D) d) w(*save)->waitio = waitio;1 x' n0 m G: m5 A9 }/ ]+ Q
(*save)->exchange = change;
* x. N& z( o% n4 k(*save)->completedTime = systemClock;$ |! q' B8 y& v
(*save)->runningTime = (*memory).p[0].runningTime;
2 I, D' C* q$ I J1 ^*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;9 d# c$ U; z) r/ f, m8 e; O9 ?
compute=waitio=change=0;
" J0 L, o) }; Y7 Z# FcomputeLast=waitioLast=changeLast=0;
" H- ^' m+ I- L4 X5 v) ?SJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));+ s4 o L2 @3 a6 O* ]" ]4 W! }
change += exchange_process;0 `; L8 Y# X. d# f8 R
return task_completed;
8 ?- O M0 x. h Q}
1 g5 Z- O. x; ]: gelse! V2 T7 S# \) X. G9 ~8 L
return task_not_completed;
$ u% f. s8 V4 S9 ^}
/ M) u0 z: |, f) E8 Y6 Nint SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
! h! M% y |0 O{
1 q& ]( F0 F' G- h- sint i=0,j=0;
- y& O0 ]2 b: j( O' gfor(i=1; i<(*storage).proNum; i++)' ~% k& N' I/ L& J) P: e" T7 y
{; A# C" d" c2 Z: H" _
if(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))$ I) E% @/ [! L& t& S
j=i;
0 K e- C( X; w! A" T}
2 x" [* W. y) q% Mif((*storage).p[j].askMemory > *spareMemory); k& u/ L! q. D7 z0 {; E
{9 V2 A0 K( [9 y1 ]: M
printf("The memory asked is overflowed than the system memory.\n");8 i; B+ n0 V5 H% I) K
exit(0);
Y/ t0 Z2 M$ D- y}/ |+ f9 u0 t* z. P6 k- ^
else' e$ L5 o2 J! G" u+ |6 g, s
{
! s% G5 ^9 {% R* t7 j3 Q$ |3 G# ^(*memory).p[0].askMemory = (*storage).p[j].askMemory;5 u+ Q0 _; p' x6 ]7 s
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;3 D& c$ o4 j# i% Q4 N- Q
(*memory).p[0].computeNum = (*storage).p[j].computeNum;
0 \( f- s9 j$ f; K(*memory).p[0].ioNum = (*storage).p[j].ioNum;6 f/ q4 ^3 M4 l; c& M! L
(*memory).p[0].processID = (*storage).p[j].processID;9 \ C% k0 S! |7 p8 c! K
(*memory).p[0].flag = (*storage).p[j].flag;
O R+ q1 d8 j% f8 U' ^5 Y(*memory).p[0].ioTime = (*storage).p[j].ioTime;4 Z* i& m* \$ K b1 d+ ]
(*memory).p[0].computeTime = (*storage).p[j].computeTime;; V# x2 `+ M, _5 P
(*memory).p[0].runningTime = systemClock;& Q& ]! a) H( k' c& y$ K
(*memory).p[0].produceTime = (*storage).p[j].produceTime;+ Q4 F9 k- f7 @, A
for(i=0; i<(*memory).p[0].ioNum; i++)
2 v7 r' B, |$ `6 X' t- N5 A3 f(*memory).p[0].ioClock = (*storage).p[j].ioClock;
1 }0 Y5 C9 ?5 r. ?for(i=0; i<(*memory).p[0].computeNum; i++)! X7 a( j" } d# t5 z' k
(*memory).p[0].computeClock = (*storage).p[j].computeClock;* `( |5 Z% P+ q! R5 }- E1 W
(*memory).proNum=1;
! ` E* Z# Z: Z# J) B4 V*spareMemory = *spareMemory - (*memory).p[j].askMemory;
; S7 |: o8 L4 `produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
' ]4 w% v5 e: w! h& KMAX_COMING_TIME = (*storage).p[j].comeingTime;
5 v! B% x8 q/ }5 ^1 o4 }. t}) E n1 E! t, O( G; W
return 0;
o% H5 ^: A3 H4 D" L}$ E* b3 r2 \! O
int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)$ L4 \6 P* R" O4 u
{2 f+ F( F+ |$ y" |8 b, W
static int compute=0,waitio=0,change=0,clockSegment=100,poi=0;! }# W$ w F) h' {
static int computeLast=0,waitioLast=0,changeLast=0;
0 o& T) q* N5 _/ y. T- gint i=0,j=0,k=0;* K. x- N( H4 O7 n
if((*memory).proNum<=0)# B5 W9 ~- w2 S& ^6 R
TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);2 m& F# [3 Q' v
if(draw==1)" t$ b# ?- z( b0 ?: W5 \) Z9 n9 c
{+ K! z. q' g6 k! K: h/ G/ ?
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);* W0 y% ^) M; x0 P' @5 Y! p
drawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
4 A, k( U O6 W( ?* r( o7 v0 c; X4 o* d9 b
# `. f7 j- ?9 c6 M7 x4 `/ h3 rcomputeLast=compute;
" \2 b. w' @' MwaitioLast=waitio;
! @; l; i7 {7 H/ k4 y5 [changeLast=change;3 X: h6 \- m5 o, G: w# O. C1 R- v
}
% `6 v1 V. Y, ~) iif(poi>=(* memory).proNum)* p: n- p+ v4 k! N4 Y# p8 }
poi = 0;: k% d+ T9 X1 o* n) S7 p
if((* memory).p[poi].flag==ready)
. } ]6 E! K1 `% a(* memory).p[poi].flag=computing;
8 {' [# E) s: t" J. i1 k2 }if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)6 M- q! Z% z1 ^
{# s* \2 _9 m1 V& k! D4 `
i=(*memory).p[poi].computeNum;
7 c: i- H, o) F8 f& a9 jif(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed E+ a/ |( C% b; I5 |% E) q2 s
{5 Y: p; y2 [/ [$ y
(*memory).p[poi].flag=IO_waiting;6 k+ K# g: x" R* E1 e& J3 L
(*memory).p[poi].computeNum--;2 Y. W: X# \" r" Y6 B
change += exchange_IO_Compute;
( e. I! U3 S2 i. N8 `compute++;$ C- R* g2 A9 a: B6 p8 J
}: j+ _( V; Y, S+ O3 F. m. ^, k
else# X2 R- e2 d. n+ B. _* f; h
{
- `( m& S5 u g6 Lcompute++;
" t- `! `, @" v& x Z a}# S$ M# y4 v5 A
}7 P0 Q4 s/ n: t8 L6 q8 G! b
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)$ ]( P" U! \# X
{+ P; f' n, f" _4 k9 ?) Q
6 b( T0 h, _ ]4 f4 `i=(*memory).p[poi].ioNum;! r; W+ a. P: j' U
if(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
j8 A) F- r2 F& p+ i! J{* V9 M3 g7 R! ~9 f9 k
(*memory).p[poi].flag=computing;. X n0 Q' s: H" b' s0 j1 D
(*memory).p[poi].ioNum--;
" ?% ]$ { R% L7 Q6 Zchange += exchange_IO_Compute;9 `( X/ L% L- F, z8 f) Q
waitio++; ~5 ?7 Y; Q- D2 T
}
& h5 {9 y, \% h) k8 s$ selse- Z2 T; C% T- z' E9 c6 \! `
{
' q7 B0 z3 c9 M9 R+ ^8 Rwaitio++;
' Q* ?& o2 t- X}
/ m' {/ a! d0 z/ K: j}
) _" D9 c5 y, helse if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing)
L* u5 i; D* [' N{# j2 o* j& _0 C5 }) X/ M
(* memory).p[poi].flag=IO_waiting;; u S! _/ Z) ~' q, u& F
change += exchange_IO_Compute;
$ M( x2 e* ~, M}% c2 W* |* i$ O
else if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting). T+ f. W. J& S; h3 a2 P8 a
{
: P e, C o& L, x2 p6 m7 `1 z- {) i(* memory).p[poi].flag=computing;
. U* Q, P( P* N& h& ?( u* _change += exchange_IO_Compute;
7 e* i. K6 o4 c, Z* H}
- o* Y A* p/ |7 Xfor(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进 I- d* F$ P# C+ T# X# S! I
{
2 \+ ` J n& C6 ]' yif(i!=poi && (*memory).p.flag==IO_waiting)
( c0 a4 }" f+ }* c4 r. B! m{: T. [6 s% U$ C+ U5 i5 G7 g
j=(*memory).p.ioNum;
* G a, n3 @5 i/ T$ M0 mif(j>0)" k7 ^+ A1 c' q$ ` o& D; Z2 I" j
{
7 T) { B; h( J/ e2 e- a8 _' fif(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed
3 s" w% ?9 P/ V' }{
/ X( M, e' n) P& j5 `& q0 Z(*memory).p.flag=computing;
7 |* P; `/ A% m+ E* K2 `2 [(*memory).p.ioNum--;6 }( K2 L# Z! G: a" C
change += exchange_IO_Compute;" C7 @( } Q; p0 _
}; O- G. E% \! g' i
}
( ~, U% U' M" z: U9 }}
0 s) O# e, C' C2 b3 J$ D3 s}# L: c! ~3 i9 \
for(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程
2 B& f8 U* Q2 j. c9 q( e{
# h# ?$ H! k1 Q4 m% Dif((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed
6 l# e: Z5 K" ^) M) [) k( f{
! M% ?1 K/ q/ f(*save) = (PCI*)malloc(sizeof(PCI));
% t5 l( F B9 |(*save)->next = NULL;
$ D; w% i, S' C$ K; H! G+ K (*save)->processID = (*memory).p.processID;
: u9 b# y" q% _: D(*save)->comeingTime = (*memory).p.produceTime;
. v1 U* {2 X1 z) B4 D3 {" i(*save)->askMemory = (*memory).p.askMemory;2 j( g7 l+ `3 G0 g8 W+ K, M1 ]
(*save)->compute = compute;
( t: z% r! C& `0 G* B( \6 B(*save)->waitio = waitio;% N4 N- E' V; w$ ^" } X# E+ S
(*save)->exchange = change;& v: O; j# I$ m1 L
(*save)->completedTime = systemClock-(*save)->comeingTime;
( r" J- V: `- g& G: x F9 o(*save)->runningTime = (*memory).p.runningTime;
( u" V# A g( [(*save)->completedTime = systemClock;
: M$ v# a/ R9 g( V ^*spareMemory = *spareMemory + (*memory).p.askMemory;! [9 g3 C7 K0 z& q: U, z
compute=waitio=change=0;
7 r1 K* y# d- C$ e. hcomputeLast=waitioLast=changeLast=0;
- t1 K! a1 \3 k6 c, e6 \if(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入7 k* H5 D4 f* o8 t
{9 c( H. x+ g x3 t8 |; C$ b
if(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程
) S+ L9 k: m" G. G! ]4 G+ ]{4 g1 e8 R7 {3 E1 I
poi++;
5 O5 B k( M2 X5 d, \" ~ clockSegment=2000;' B) W" y7 r9 o! k* N
}
* ^: w9 I) K* e- h" ~1 P}
* @9 r; l; G1 r7 r& V# M* D0 w) nelse //没有足够内存调入新进程 A$ @# M- s" t; W0 Y) j
{
/ u% i$ V* Z$ R0 s5 [: ]/ hif(i < (*memory).proNum-1)% [$ k/ k; [ C( ^0 |! P, n
{6 U5 Z0 k6 W: P9 |7 @
for(j=i; j+1<(*memory).proNum; j++)
2 N9 |- ^$ ?- _ h# l{$ P/ r6 R0 `0 T& o! w. d7 u
(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;/ ^2 {9 |/ b1 g( K: @! D& }) T9 O4 f
(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;' E z" ~+ r# e. Y; _6 X
(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;7 n4 U; R1 d N
(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;# P, {" u M2 U Z
(*memory).p[j].processID = (*memory).p[j+1].processID;* E% J3 a0 q" B& z) x2 [
(*memory).p[j].flag = (*memory).p[j+1].flag;7 r: F7 g* o6 L2 D
(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;
: Q( {1 O7 t3 b+ D* s(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;( u! U* X) G C1 a3 I Z) I: y
(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;
( `9 o7 i w, v7 j- y- z7 S(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;: M9 N$ h0 F$ P( ]! Z/ i
(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;* B s" e6 c4 Q3 K
for(k=0; k<(*memory).p[j].computeNum; k++)
! {: Z/ v! T+ n8 o K/ G(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];$ Q9 \5 c/ D. ?9 O3 w
for(k=0; k<(*memory).p[j].ioNum; k++)
) j5 v& u" C3 J- r2 Q(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];
" `8 N6 ?$ s* @3 P. f6 y}! M5 X" W. t( A" D, T+ o5 A
if(i<poi)% K C7 m! B) T, T# `3 I5 H/ C
poi--;
9 y6 y: B0 h0 \+ r3 n. Y$ Eelse if(i==poi)
4 s. I7 j) B5 QclockSegment=2000;% w5 n9 Y; C0 ~- ]- e: ^
}6 H$ y/ n! S$ q6 S' I
i--;( l3 x1 k7 n, v- M7 ^
(*memory).proNum--;
; g- ]5 b! S1 w& ?8 s& t4 {/ G}
# e! u! |5 f& p& treturn task_completed;) j4 M# ?2 w2 q9 V) \
}0 @: |- p# o* i7 P# F7 r1 x- b, {3 E
}
. K# g/ N4 ]. t7 a+ i--clockSegment;
: [: `5 w, T, R/ R% H; t' g7 Hif(clockSegment<=0)8 S( J* m4 j$ i2 e8 l6 R
{8 R r0 }9 \3 d
poi=poi+1;3 U8 `0 H# l! {) u
if(poi>=(*memory).proNum)
- `, H" s5 @: a Z3 ~- wpoi=0;
/ T3 O) o+ }1 A% H+ F4 r% p4 FclockSegment=100;- ?0 M/ s2 Q( h+ B
}7 J* [( k- N) }! J- f
return task_not_completed;- Y( d8 n2 k; X5 ^
}
. f/ U0 X) \0 U' C* X' uint TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)
/ S/ I( `: Y8 V! U{
1 `" X7 ?+ H$ @* Q& h" K) R: J' pint i=0,j=0,k=0,flag=0,translation=0;& E/ n$ ^2 Q% F9 Y' w9 W& Y
for(i=0; i<(*storage).proNum; i++)6 v8 e: ?/ r. f
{! V5 G' X: V* X8 D2 u& h2 O! y8 V' v c
if((*storage).p.comeingTime>MAX_COMING_TIME)1 Z8 O- p# `% |6 \! i4 H
MAX_COMING_TIME = (*storage).p.comeingTime;
4 ?# H& y7 U( E# k. A}
' B9 Z! }- `% Q k) [if(pos>=0); }6 h( F5 G4 O5 `# l" S3 j) Y. U% r
{' f, O! [9 T0 }- d
for(i=0; i<(*storage).proNum; i++)* R% i# Y ?" z" Z+ [) _
{. u$ j- h6 b0 u/ ]& }( T( j
if((*storage).p.askMemory <= *spareMemory)* z. z" Z: J/ [, b
{2 P$ p" G: a* F3 V; B$ C- c4 {
j=pos;9 z% E. r; i1 M U$ p' D
(*memory).p[j].askMemory = (*storage).p.askMemory;
1 `9 g$ ?9 A4 L8 U(*memory).p[j].comeingTime = (*storage).p.comeingTime;
; O: B/ b! s+ b! q* j+ ~$ d) a& ](*memory).p[j].computeNum = (*storage).p.computeNum;% m. M3 m9 ?* M5 T6 Q4 u
(*memory).p[j].ioNum = (*storage).p.ioNum;
4 b- Q! Y: Q; L* V( S(*memory).p[j].processID = (*storage).p.processID;
: e+ w, e- H1 i& K+ f(*memory).p[j].flag = (*storage).p.flag;
% H$ t) O+ A9 D5 e! F8 _(*memory).p[j].ioTime = (*storage).p.ioTime; q4 _3 ^& @- F
(*memory).p[j].computeTime = (*storage).p.computeTime;
8 @; E! x Q7 V, h4 J V(*memory).p[j].runningTime = systemClock;
- e4 L, H+ j, E! @+ N(*memory).p[j].produceTime = (*storage).p.produceTime;% r2 @. F/ x1 o
for(k=0; k<(*memory).p[j].ioNum; k++)
5 V# ?. i/ D3 C8 j0 a7 I8 `9 f(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
% x2 [- @0 a2 N4 `5 f$ ?6 K Tfor(k=0; k<(*memory).p[j].computeNum; k++). C6 P2 v9 m; k& G6 G
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
& l4 [0 ~' U; o |. F*spareMemory = *spareMemory - (*memory).p[j].askMemory;. ?0 v: u0 ~3 X. y) |
produce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程* T. l! v( r* G# F
MAX_COMING_TIME = (*storage).p.comeingTime;( d r6 K w1 ~/ z9 N! {
translation=1;
) x+ B. \. b- abreak;# n8 z) R$ h% R- p, a- K
}4 Z p/ }1 J& D# u( m$ O: U5 N
}! @3 x- Q5 a- B
}
. ?: Y- z2 h: g7 g4 Aelse
* B- m7 G8 r j2 w v( S{% e* Z1 J, M( m
while(1)+ k5 M1 i+ W/ r$ o6 u
{
% I8 f: b' x3 K7 S+ I% N; i5 pflag=0;
: X5 Y/ a c# G4 S6 C- sfor(i=0; i<(*storage).proNum; i++)+ d7 Z8 N- C' _5 X" p! I Y* A R
{" `. \- X: O7 D, A- |& V
if((*storage).p.askMemory <= *spareMemory)) s* X; @- L5 [7 U' X# V
{3 Z5 E/ w# T8 B) z
j=(*memory).proNum;- L. Y: \6 s! T- b0 U& t/ P
(*memory).p[j].askMemory = (*storage).p.askMemory;
; a, j! l9 H$ `9 V(*memory).p[j].comeingTime = (*storage).p.comeingTime;
0 ~6 V# Q( v; [(*memory).p[j].computeNum = (*storage).p.computeNum;
- [% ?3 j5 }4 D. j1 H( s; l(*memory).p[j].ioNum = (*storage).p.ioNum;
7 ~. k" ^3 S3 ?9 [& w(*memory).p[j].processID = (*storage).p.processID;
1 w2 T1 X" E+ P! v& f(*memory).p[j].flag = (*storage).p.flag;
, p6 L% c- f7 t: |5 X(*memory).p[j].ioTime = (*storage).p.ioTime;
3 G) ~( ]* N( G# X. d. B0 a(*memory).p[j].computeTime = (*storage).p.computeTime;
7 X" H/ g6 Z/ [(*memory).p[j].runningTime = systemClock;& O+ b7 }( G1 W8 I
(*memory).p[j].produceTime = (*storage).p.produceTime;
2 k" U* C7 A- G2 r" x) b+ Yfor(k=0; k<(*memory).p[j].ioNum; k++)
. |7 W* F! b2 b1 w9 W# l/ _(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];1 s( v# [7 k/ ^2 v
for(k=0; k<(*memory).p[j].computeNum; k++). E1 o. g- h/ A5 y3 ?
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
* M# W4 ^ f: V6 ?6 Z( o(*memory).proNum++;
% |$ X( }! j8 E4 b$ u0 ~( e*spareMemory = *spareMemory - (*memory).p[j].askMemory;
, C/ h3 |% A: b5 P7 N' I) Zproduce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程" `. B2 F9 N. c7 f
MAX_COMING_TIME = (*storage).p.comeingTime;
1 E9 `- t2 N( e3 I) Yflag=1;
8 V4 ]; k0 P/ L+ p# n# Ftranslation=1;0 u& X J' p* Y. K8 w
}2 E. I2 I6 b6 x3 t% m7 Z1 K1 w2 U
}- }: H# `6 K/ b' n4 ^
if(flag == 0)
) Y" J1 v& Z4 ^4 D2 d! Gbreak;
1 @$ t% L/ [) G}, @# l8 v) ]+ T4 l
}- x D) b/ v- ?
return translation;2 d* W/ o- ]# Z0 ~2 i3 |
}
- E' ~( e2 q R | o9 I9 |int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)
$ d7 B( S1 F8 q( q{
8 g! X) t7 z; ~- @0 O& S. R3 u' Cstatic int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;
- d4 p' N# S) h/ e4 y% z o: H/ O9 zstatic int computeLast=0,waitioLast=0,changeLast=0;
- D( m" f" T' a6 Lint i=0;; j" z, K$ {% m! V2 @# J9 }& F
if(draw==1)8 P; V( ? H9 a2 U( M! {
{. d6 O2 C" m S9 ~1 g4 K f
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);$ D& z( [6 B3 g( P3 Q2 X5 h, j- X
drawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
8 D9 l3 O' \9 F2 c! z& B! i+ ^" }/ a3 { R$ L1 q
, ]' P& x* s/ q/ x9 M8 ^computeLast=compute;
0 ~6 t" R1 d y' RwaitioLast=waitio;. Q! r& }0 I; p) M
changeLast=change;- |( {3 l9 F7 G6 R
}
1 B9 B8 D3 F( ~9 [" Nif(flag==1) 9 ?! _) O' e( ]6 \
{
: ~( y& ?) R2 d( Dif((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed
: Y. h. r1 x4 J- p7 X/ h6 Q$ W{; S* j# d7 w; }, h3 ~* p
if(flagiocpt==0) // implement compute: Z) O5 s) c' n" {6 f8 P4 Z+ [
{
! k- l+ \+ m0 w `; q+ G( Q! @% `i=(*memory).p[0].computeNum;) G1 o2 R% J7 x3 f
if(i>0 && (*memory).p[0].computeClock[i-1]>0)
0 \+ E* ?1 Y( w- T6 Q% [4 z% J{# K: c, b5 ]) E( l' N
if(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed
* J: M! {/ f# `3 U, |{
9 k1 Q+ z4 c7 N5 y N! iflagiocpt = 1;
Q$ r4 @+ Q* P% K+ Q(*memory).p[0].computeNum--;
: K/ L/ ]/ p m3 qchange += exchange_IO_Compute;' O9 h; e0 l' }* @/ a6 O7 E
compute++;. Q# ?- E& H5 C4 Q! u4 R
}% s& R5 \% u! P
else0 V% \0 i+ E8 \4 x, s% Y# I
compute++;
& e& g$ N6 w z
3 f0 I# ~+ U% I4 A1 _& Q}7 V5 S) w$ H/ b) O A
else8 T: x5 K$ j# r" D$ z
flagiocpt = 1;3 Z" F8 T; r) f8 ^- F
}5 p0 W) w( N0 K6 C. ~2 f
else //wait io
2 K) E4 w7 K( [$ Q9 S& c3 r5 X{: Q/ A$ k N! C' B
i=(*memory).p[0].ioNum;
1 Y* i! b9 E, ~- S1 g1 @9 U5 Pif(i>0 && (*memory).p[0].ioClock[i-1]>0)& H4 X8 W, ?* U" K9 C
{
1 t _- J( v! C8 p7 Zif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed$ p9 _4 \0 k, e
{0 f5 o8 c+ k, u) w& i, }" e
flagiocpt = 0;
5 T9 P6 Q- [) L% D(*memory).p[0].ioNum--;
; s* F5 E( A; T" ~change += exchange_IO_Compute;6 _7 A6 Q+ @. H4 j2 F
waitio++;' ]9 v* s$ s) X" o
}
: w4 O6 g0 `, b1 F0 V* felse
( s6 g0 [# J6 @$ o% jwaitio++;
; f* {: s/ K0 Z) P# V. W. w/ P
: E- |5 w$ t5 G# Q}4 a+ q8 W+ i2 I' d
else
1 J8 [6 K- z' |7 x5 f2 w5 S# @flagiocpt = 0;6 n4 e B9 O( p8 F* a0 @; k
}
4 m# q `# Y! |1 w0 Z; _$ x2 @}
7 C( {6 i6 X7 i' H- uelse //task is completed
2 @$ p4 B6 ?5 y: b$ O{
7 ^: J8 Q5 t: i, H1 V(*save) = (PCI*)malloc(sizeof(PCI));
" x0 l+ N; Z/ b; C M( J k$ S(*save)->next = NULL;
; F$ z7 p0 y i9 [5 i0 |# n (*save)->processID = (*memory).p[0].processID;
" r& _2 z6 l; \(*save)->comeingTime = (*memory).p[0].produceTime;
& @# A! \9 @) O" n+ A(*save)->askMemory = (*memory).p[0].askMemory;: l6 @/ `* N$ a) h( n
(*save)->compute = compute;. Q2 E, y( p* M' W# h! a0 e3 _2 a
(*save)->waitio = waitio;
/ w+ x1 O3 `7 ]' t(*save)->exchange = change;% Q8 F; ?( D% @5 j$ p1 U
(*save)->completedTime = systemClock-(*save)->comeingTime;8 ~2 z9 _, t% e
(*save)->runningTime = (*memory).p[0].runningTime;! P* {2 v: D" h4 P, o0 A
(*save)->completedTime = systemClock;
# t& r1 K1 E$ x! W8 t; z//*spareMemory = MAX_MEMORY;* R3 M7 G s+ \# _
free((*memory).p[0].ioClock);) j3 |* _9 e8 \
free((*memory).p[0].computeClock);
1 [2 w/ p) ^8 Dfree((*memory).p);
0 h! c! S1 d7 ]6 K! ?# X4 g8 g$ `flag=0;
" F- e( F' G' U0 n' d4 m. Kcompute=waitio=change=0;
2 c$ S6 g, i9 a6 m `6 g L6 \3 Q$ AcomputeLast=waitioLast=changeLast=0;5 H- L) H; F# I6 S( C! `
return task_completed;
# N) z3 P- F& S. p7 v7 N8 L}
" a/ g W# W1 U}
# u: S+ F, J; e G% B$ {else & V4 E8 a, a6 p3 K* U- t1 W
{
) l9 ^, B( g5 z6 GFIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));* P+ q" }: Y8 b& [( [/ I
change += exchange_process;) U8 n0 E8 v! _, G
//*spareMemory -= (*memory).p[0].askMemory;5 \# E" ~2 q O. |% Y6 Y0 }
flag=1;
) Y7 K- C2 i8 a/ U//showProcessInf(*memory);
1 @6 m( d `) D1 Ireturn task_not_completed;
5 J; |- _9 i8 A- M3 Z3 f}) G1 G( B" E) T% t- Z2 b
return task_not_completed;
' J7 m# O' B+ d N* f9 }}$ R* q' C5 `/ Z) C$ U- z1 E
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)5 o! _) ]3 d- R
{% l# G2 g8 c( C0 g6 Y# n3 ]
int i=0,j=0,k=0;
& _7 z! N$ P/ o% e' `" aMAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;
" z! i/ a' ?1 U" S(*memory).p = (process*)malloc(initProcessNum*sizeof(process));
& |; H/ d3 d+ W5 K1 k) w2 zmemory->proNum = 1;* n% V& q# G" N2 R" g
for(i=0; i<initProcessNum; i++) q0 v! \+ q$ B7 f! K
{: g- N& H, W. S- G6 ^
if((*storage).p.askMemory <= *spareMemory)6 D8 g* c2 Y4 V, Z& f, w% ^' T
{4 _( u/ E+ Y ]) g: o0 f% D
(*memory).p[0].askMemory = (*storage).p.askMemory;
$ n, w4 h; E2 X8 ^' T7 C(*memory).p[0].comeingTime = (*storage).p.comeingTime;: Z$ h: t; A$ `- {( l
(*memory).p[0].computeNum = (*storage).p.computeNum;4 E3 v* W. e9 M; P1 o( p& e0 d6 {
(*memory).p[0].ioNum = (*storage).p.ioNum;
/ }0 i* n8 b0 c(*memory).p[0].processID = (*storage).p.processID;+ h# Y7 R5 u% P( {" w& w+ i
(*memory).p[0].flag = (*storage).p.flag;
8 E8 \* @0 y; k6 D& P( ~(*memory).p[0].ioTime = (*storage).p.ioTime;- l/ d0 x7 b, ?* `+ J
(*memory).p[0].computeTime = (*storage).p.computeTime;. N0 f. _- r4 z, M
(*memory).p[0].produceTime = (*storage).p.produceTime;
6 e& C6 G4 o. ^- G5 n$ w3 ]. `(*memory).p[0].runningTime = systemClock;, i3 a2 E$ y. c* v1 ^2 W
(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));
. g& ~# }$ P% j. N+ V5 [) ^; ~(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));' X3 S0 F! S2 |* U. e- R
for(k=0; k<(*memory).p[0].ioNum; k++)1 r# p3 Z2 d! d T4 I9 \
(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];0 }6 Y, z% C% {' [. E. F" f4 z
for(k=0; k<(*memory).p[0].computeNum; k++)5 G5 b" V5 S. c3 V0 Q9 v1 o
(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];
# t2 q- C! N6 v" N" g9 P7 A8 }break;, [9 Y" L" {4 `" k; w6 [7 b8 k, u( Y
}8 B' K* J) L7 S$ g1 [8 d
}
1 G2 L9 ]/ s! ]2 ^5 r5 ~if(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入0 F+ d. {' G* Q& i% V( O6 t" ~
{
: Z N. T3 O, c/ T& |- j6 Vproduce_one_task(storage,i,ID_FIFO++);( R0 H3 Y2 y/ s' \
MAX_COMING_TIME = (*storage).p.comeingTime;' n1 `. W- S; k4 L
sort_by_comingtime(storage,i);/ R9 P% h% L6 K8 ]
}
% d% g' F! x& Y: f) e$ c2 h/ j* ureturn 0;
3 T' @, W& z% L( `4 X" f8 r+ ^+ f+ |}% ]* q) ?) ^ A% j* H
int sort_by_comingtime(processPool * p,int pos)9 l2 o9 Y, p0 G4 k3 w, w
{ O1 n8 Q& e' o' N3 a
int i=0,j=0;0 D( k+ ~/ G7 F" ?
process temp;
4 W9 W% u. q/ Q3 k! @ e5 a7 Tif(pos<0)
% _' M, ?) ^2 l' o7 `: B% s. O{. ~( U J1 s1 L
for(i=0; i<initProcessNum; i++)
6 C$ f+ d2 U# M l7 z/ M, tfor(j=0; j+1<initProcessNum-i; j++)
9 x7 b% _4 o, z* w. B8 n{
( g; s; I# D. @$ Zif((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)
. b; }+ W/ l, A I- K{
l- h* S: u. t% Z: \+ x8 o: Utemp = (*p).p[j];
+ I0 V4 M3 D% f2 [- F7 V(*p).p[j] = (*p).p[j+1];
- ^% L$ {: D3 E% `" K8 |3 A! ?(*p).p[j+1] = temp;& ^# d0 ^9 w- c( J2 L4 P9 v$ i* @
}" R" I0 h2 `8 e7 p# `1 F$ f; f
}
& k# w3 }4 X- `7 |/ W8 D}
' r8 b: E, r% m/ l' K7 O3 R4 \else if(pos<initProcessNum)
6 R, t3 |, w/ _3 c/ [{
% [. E1 M: ?8 J# V/ R1 ~2 rfor(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)2 z' e G5 R+ H( v7 X
{
0 s9 }: [7 m" T q7 stemp = (*p).p;
" G2 ?1 S, h+ y" a, v2 `$ \(*p).p = (*p).p[i+1];
7 K9 k1 L6 \, J' F$ W$ T; l, T(*p).p[i+1] = temp;! o. Y: _* m- m
}" L @3 f, s, L% c
for(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)# Y0 z4 R* J; q0 B
{
9 T( P# l$ F9 G$ etemp = (*p).p[i-1];
X; F+ \2 Y2 |% M! ` ~! e5 Q* B(*p).p[i-1] = (*p).p;) o% j. G: R. l
(*p).p = temp;
1 k, N% e, R4 {+ J* v}
( A( } ]* M* n}: R: r$ d& `. T' A" |% T! k8 N
else
# m I8 z: x+ wprintf("position eror\n");
/ e+ l: H1 C1 K" ?return 0;
2 [4 `! X# M) T+ _, h4 K" G: [7 p: a}' ]- ]/ x" _9 Q4 r4 |+ H9 ~' {
int InitPool(processPool * p)7 G6 F7 d( ?7 Z( d, |
{3 k1 x0 Q! I4 D" F F& G' M3 R
int i=0;
: L' N; z1 G% [" p+ `0 T2 o(*p).proNum = initProcessNum;
$ k2 p' e9 c1 ^0 _# j(*p).p = (process*)malloc(initProcessNum*sizeof(process));2 V, i M8 t& i* k6 A0 l
for(i=0; i<initProcessNum; i++) //init process information, F" `) l# U5 d' w
{
0 |$ m7 O0 d! Y/ v' `2 E(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));
" \( l+ R2 V l( l+ M& {(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));
: S; [" b1 z( k' i) P2 Lproduce_one_task(&(*p),i,ID_FIFO++); b7 t! U$ ^) F1 L
}
0 S7 ^( z2 x' k* h" Greturn 0;) M8 W$ J9 d8 V
}
: F* D/ p7 w5 l* |$ iint produce_one_task(processPool * p,int i,int id)
" W O0 V- J1 |! ~{/ @1 E t& T/ ?+ x% ?
int time=MAX_COMING_TIME,j=0,totallTime=0;! W# n7 {1 m' d$ S5 k5 a
(*p).p.processID = initProcessID+id;
/ X0 J5 c- P" Z4 U(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);
9 g0 o" S2 { R; I(*p).p.produceTime = systemClock;
5 e" n6 ?0 j' T( \(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;
& y& u. }$ N- @( G(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6;
2 a% ]1 l7 Q. |1 K* b8 ztotallTime = (*p).p.computeNum + (*p).p.ioNum;
. M/ F% k6 q) \4 b8 R; L0 O(*p).p.computeTime=0; `2 B/ ~: [, A7 Z8 Y0 |; _ o5 F4 v ]) X
for(j=0; j<(*p).p.computeNum; j++)9 h# b" a8 b% G. M& }, l q
{5 l) t' s1 P/ i1 u' h
(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;4 _7 X) X4 R- ]6 e) E) ?* f
(*p).p.computeTime += (*p).p.computeClock[j];
! [: M7 }+ n- s( l# Z1 o}2 U' q8 e! K* V: o& \- y7 c# V
(*p).p.ioTime=0;1 B' {' r( z9 {9 M" g) n1 K1 v
for(j=0; j<(*p).p.ioNum; j++) |
|