- 在线时间
- 1630 小时
- 最后登录
- 2024-1-29
- 注册时间
- 2017-5-16
- 听众数
- 82
- 收听数
- 1
- 能力
- 120 分
- 体力
- 566697 点
- 威望
- 12 点
- 阅读权限
- 255
- 积分
- 175232
- 相册
- 1
- 日志
- 0
- 记录
- 0
- 帖子
- 5313
- 主题
- 5273
- 精华
- 3
- 分享
- 0
- 好友
- 163
TA的每日心情 | 开心 2021-8-11 17:59 |
|---|
签到天数: 17 天 [LV.4]偶尔看看III 网络挑战赛参赛者 网络挑战赛参赛者 - 自我介绍
- 本人女,毕业于内蒙古科技大学,担任文职专业,毕业专业英语。
 群组: 2018美赛大象算法课程 群组: 2018美赛护航培训课程 群组: 2019年 数学中国站长建 群组: 2019年数据分析师课程 群组: 2018年大象老师国赛优 |
0 f+ ^# D3 n4 L1 D" N
经典任务调度算法的模拟程序
9 |- ]+ Y+ i% ^+ @3 v本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。3 V* F2 S4 y: Q* k. r2 X0 x
* n2 v7 l- [3 B; L) l/ A
编程平台:VC6.0+EasyX图形库环境。# J; C$ K. L0 l" ?, E
& l' |. t! P: T; x+ _9 }
以下截取部分程序运行图::
7 b) |' i) \, `! G7 a' Z% D0 l, ]: h& y: Z% n* C
源代码:3 O8 n3 O0 b! B o- x: I4 ~
8 j7 M7 X' k0 y#include<stdio.h>9 y- J5 t m; k- h) C4 Z
#include<stdlib.h>$ S( Z2 i* G. k/ `9 z6 i6 m
#include<easyx.h>( j, j& K% b4 j8 W* o5 \ S
#include<time.h>8 @4 u- c# n6 r+ t/ _% ]" N* e4 I
#include<conio.h>
! x8 t* V6 y1 |#include<graphics.h>
: j$ a5 Y6 e: E1 j$ c7 H5 ~- w# o0 \#define initProcessNum 10+ l+ y5 \# k+ N- B
#define initProcessID 1000
- j5 r' F3 |( ^9 H# F8 X0 H w#define MAXProcessRunTime 10000
F+ H" I& a8 K" I; I3 `#define MAX_MEMORY 4000/ @' C1 }0 o% d' ?2 q r
#define exchange_IO_Compute 10
8 w( f9 I$ }) E3 d: @+ M#define exchange_process 25
* @( N' D, o% D#define task_completed 1
. y7 w! o) q* [#define task_not_completed 0# w N5 ~# E6 ^3 ]
#define initclocknum 100
( o$ t6 ~# B& j! [- Oenum condition9 W8 S5 u/ r- ^# {
{
0 Y' i$ P4 @! T& c( |dead,computing,IO_waiting,ready
9 W( K( X; z/ \$ s# W2 a5 i};
8 e; O% n! d1 b5 [# N0 Z2 y3 Dstruct process
( R8 Q9 o' o! Q3 V7 _. G# N{
: A. H, T; Q, u& Q# l) mint processID;; F. C- y( t; l% q1 v6 W
int comeingTime;
- }* a. X4 E! q2 @int ioNum;
" p' h" S e( p( b9 h. d' h; o I& _int computeNum;
1 _* @: U: v, n8 o: j9 G' D" l1 fint * ioClock;
: b" E: |6 L; K6 I q, A* Uint * computeClock;4 R4 m& D0 M; _' c! _4 P7 R7 M
int ioTime;
. X, T" G" z2 E5 T+ g: b" m8 xint computeTime;) S! `/ W( \ Y: u
int askMemory;
5 @3 w k8 C( m1 F1 Kcondition flag;3 m/ M& Z' r+ f% g" y
int produceTime; //生成时间,以下三个数据成员用以计算相关性能# S3 Z {1 j+ A
int runningTime; //第一次占用CPU的时间
9 J5 n0 {' W: Q7 R! T% ?int completedTime; //进程完成时的时间( g6 v" _0 H: a" Y$ W
};
, u4 S7 }; o% W8 x" l2 s4 R4 l- z4 {typedef struct processCmpletedInfo //保存完成一个作业的相关信息
: o' @! X- n! q% K9 o& `7 |* L{ v; y$ S% D4 I; D" d! s
int processID,comeingTime,askMemory;* D4 R8 B" {/ M
int compute,waitio,exchange,completedTime,runningTime;# G. Q' Y g: }7 B
processCmpletedInfo * next;; O3 x) s% A, L
}PCI;: t; |: |) o. T: F+ W
struct processPool! V; _' S: z5 p$ H
{
7 K E( e9 s% a- E& T6 G ^2 lprocess * p;
, ]# [ J! u, Y0 S5 Z! Q7 Q" Z9 Gint proNum;
3 k) X5 j- J: f4 g/ O' G, `$ K) Q};9 N6 l6 P7 \ Y
int MAX_COMING_TIME=0,ID_FIFO=0,systemClock=0,FLAG_FIFO=0,FLAG_TT=0,FLAG_PF=0,FLAG_SJF=0,FLAG_HR=0,FLAG_show=1;- s/ h! f9 x" J# N) n
int InitPool(processPool * p);
! M* a5 \) c1 L& R3 Xint produce_one_task(processPool * p,int i,int id);8 J- ?' O' O7 ]
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);
4 Y/ h5 V% R o" ^8 [int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
% k/ w$ d/ R- l. g4 f* e& I$ r2 Mint TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);
. y9 r7 |7 X- n. ^" ?int FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);1 w5 B0 E1 T7 Q# @
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);7 e+ I6 m5 k. Y* x) {
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
8 y* ~6 O4 J* K4 w9 Yint PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
! j9 X/ O: M& z% _6 J5 p0 y1 `5 t8 Dint Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
7 {3 L4 `; \! Y% I% [0 i% [int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);
7 @/ y B" h1 D& i5 nint High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
. t1 l& J- R; S3 W1 \ ?6 z) I2 P0 b: I: }# Y- ^( |
& \: L) o" J) N ]$ I; M
int sort_by_comingtime(processPool * p,int pos);" x0 X# ?* m! T, w9 w
int showProcessInf(processPool p);
. k7 H, {/ F5 C! u" z% ^( [( vint drawPerformance_FIFO(int x,int y,int memorry);: m6 E/ r" q5 ^5 C+ A
int drawPerformance_HR(int x,int y,int memorry); w& D" _, G* a( h' z- X; C' N: E( e8 U
int drawPerformance_PF(int x,int y,int memorry);- b, M( J- b: u5 j" B4 J6 Q0 K9 J1 {
int drawPerformance_TT(int x,int y,int memorry);4 \2 [. e) d9 ?6 l* Z+ X3 Q
int drawPerformance_SJF(int x,int y,int memorry);
# N/ i6 S( E$ \8 d$ @& c! q0 t# Cint MouseListening();
4 I- a# @ _# b( Y+ y- Uint MouseListening2(int *flagShow,int * showTime);8 A7 q+ }# I" u1 Z% x6 h
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);9 N' d$ b3 I! ^0 c
1 B3 ], d! D8 w) f1 Z/ K! Z6 w9 d* A" _5 P
void main()
6 P# M- h4 R( t& r7 |$ C% i{. a# z! g- `$ Z% c
PCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,: ?6 T$ h; y5 \7 o6 S# T. Y- x
*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;
$ M# ~5 u1 w+ U6 W- E! n N% Lint i=0,FIFO_memory=MAX_MEMORY,count=0,Timet_memory=MAX_MEMORY,SJF_memory=MAX_MEMORY,Priority_memory=MAX_MEMORY,HR_memory=MAX_MEMORY,5 g4 y) W# u% W8 h. Y: \ r
flagDraw=0,showTime=100000;7 }# i) |; d( E
processPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;7 ?5 T6 q3 r3 e, v& w
FILE *fp=NULL;3 |6 o# E: I+ u$ `- R9 k% j
//processPool HR_p,HR_mmy;
: \: I- w6 ], j: P, |4 g+ _7 p
) y/ ?% V- y1 t3 g# d4 N$ P7 P' X/ U/ X# Q# M3 b0 I
srand((unsigned)time(0));
- g1 l2 C A! P2 k: hsystemClock=0;; f4 ~" q ^7 l5 t: _. j7 F& r
initgraph( 1200,650,SHOWCONSOLE ); P: g8 x. I6 I8 u6 t7 v& F
settextcolor(GREEN);
5 A3 Z B$ l# n7 rsetlinecolor(GREEN);
$ m( b2 D7 m5 f* @/ m$ D! c/ Rsetfillcolor(GREEN);# I, C0 _# _5 `' z
InitPool(&FIFO_p);
+ S" r; X/ x6 ssort_by_comingtime(&FIFO_p,-1);# b: v+ b' [ X2 z6 F2 f: K+ [" O
InitPool(&Timeturn_p);
2 u' I: h# i8 c) F( P5 gInitPool(&SJF_p);
; O0 B( @* D9 B8 L* HInitPool(&Priority_p);" q+ Q J; F( ?3 ?3 K1 u! [
InitPool(&HR_p);
6 n- ~! H/ A9 H1 T# G7 l! r% ?0 D//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
2 Z$ a- i( U8 i' Y//Sleep(10000);
1 l7 ]/ `% V" Q+ Y# u. c, [& K' T4 x# Y: O+ P
% a5 i5 s4 B" r8 J; zTimeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));# h( q4 i* V7 b
SJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));8 ?) K2 l5 Z3 ]4 { K/ a# W' B
Priority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
1 O9 G2 p$ n# p k% T& cHR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
* D+ ]* V: ]$ a9 J+ cfor(i=0; i<initProcessNum ;i++)$ z+ `( h, L+ L0 ~5 |
{, r0 \' I4 ]4 }
Timeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
$ v7 W; e' _, yTimeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
; }1 B4 E' I, w* Q) ]* ^SJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
$ t6 P' X) ~5 ySJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
9 D9 g6 ^. `/ gPriority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));7 w6 X( ?2 E1 m) D
Priority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));3 t' B. S% Z3 |6 Q( N' N
HR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
$ z5 ]& l3 o8 F0 J1 X- UHR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
& ]+ T& }/ a" R' {}
0 }+ T% ]" T8 s9 PTimeturn_mmy.proNum = 0;! \2 F3 T- h$ e# T
TimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);# [8 f7 ]1 N3 e# ^9 G m: H
SJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);4 R; V V. [, a3 z4 P
Priority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);! I$ N5 }3 }2 [
High_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);
0 B; N) g, p8 _% l/ E//showProcessInf(Timeturn_mmy);
7 Y/ p; D& l8 zFIFO_pri = &FIFO_save_head;
0 ~- ^4 g9 B) N% n2 @Timet_pri = &Timet_save_head;4 D, V& X+ `' l) J2 ~5 D% x
SJF_pri = &SJF_save_head;
( x. `8 q& g9 k% m( i7 M$ mPriority_pri = &Priority_save_head;) P8 O# S6 {/ p3 j! U1 m$ h
HR_pri = &HR_save_head;) L7 j" I% g+ I4 d+ F9 i! N8 ~/ b
setbkcolor(WHITE);
9 x y6 T& {2 Fwhile(1)& d. O! M: R, `" b( o+ W0 [- I
{
- m% N2 O- j4 h& e% ^# L6 Uif(MouseListening()==1). a: S, G5 W7 C
flagDraw=1;. ^ V2 I' A/ Y8 j( x
if(count==100)9 \/ h# r1 w3 Y; o ]' _
{
) o" ^! }0 d4 q7 s: pif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)3 h' ~; l F+ }
{
W; x$ G& u! G) v- W7 ~2 A7 R( tFIFO_pri = &((*FIFO_pri)->next);
9 u/ H% u- @; ~; _/ M3 {; `' h7 e- U3 B* X
//printf("hello");! |; p) T% l( h) M
}
1 A& s% g9 @ x" C+ [if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)
5 @0 q( m6 l9 d, T$ o{
' z/ B3 {) i, d7 i/ z Timet_pri = &((*Timet_pri)->next);; M/ |9 Z; b O& W l5 J7 b
//printf("hello");
6 Y8 w! [/ A8 W0 y( ~+ S8 a}. y" T4 \" j9 O. b5 S9 c
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)
6 D3 Y, ` x. _2 i{0 B& _9 M2 J" \
SJF_pri = &((*SJF_pri)->next);2 b6 U7 s2 }% t& y7 K& B
//printf("hello\n");
~- R5 h. N `7 n7 y, q}, ` Z. W; j! }* N3 `) U
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed)! F' B# p6 P1 r% [
{1 W* O4 W- y5 V3 s/ H. y
Priority_pri = &((*Priority_pri)->next);0 W* T8 h: V- I
//printf("hello\n");
( I z7 G9 e& c4 C) N}5 L/ T7 {; a5 w3 E' r; u5 S" Y
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)! A! p: J9 q2 m/ |& e
{
$ p1 E7 X m/ mHR_pri = &((*HR_pri)->next);! h1 z- M! S6 C/ {) N
//printf("hello");
Y' a3 u [6 \6 H# N}
( [2 Z, \; z1 A. ]3 lcount=0;
8 v& J+ N3 Q3 v4 f' E5 r/ _}
1 u, O& y3 N: D2 r4 b0 @else4 k. ]) u& \7 g- t
{ e) H1 e6 l$ I$ j% o" w3 a
if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)
3 V0 h2 m8 E1 V! K' K) N{$ L7 d/ U K3 z, i& |
FIFO_pri = &((*FIFO_pri)->next);# \% v' K2 J; B9 N$ L y
// printf("hello");
& [3 g( |: t2 e2 z9 I1 k: \3 C}2 d; ^# w9 n* p i
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)4 p* K z) g: D: {- ^, _
{
9 p+ d2 w, d# T: H7 ?Timet_pri = &((*Timet_pri)->next);4 I3 u s% c* y6 x9 C: V8 L- T! m; `
// printf("hello");1 G3 Z c; n: A8 A
}/ ~) o' C6 b0 G- g% d2 ~% K& M
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)
# F, i8 k' B. B; W7 C{9 g: c. S8 S1 M
SJF_pri = &((*SJF_pri)->next);1 x0 f9 M* V2 |+ j$ v* p" I$ D
// printf("hello\n");
+ N l8 f3 J7 D) g# K/ }0 F}5 b8 q5 h+ Q( N4 ^( k9 y
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)! G1 B1 P& o Q3 @% C
{
& E! [3 L1 r& {2 k& APriority_pri = &((*Priority_pri)->next);
. W9 P) Q. n6 S- q4 B2 m5 v//printf("hello\n");, M: c# h2 ^& v& u+ |7 Z
}! \! S( b; t! L0 ~: S& D
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed)% [/ h* D) B. f% Q' \
{
2 u# ^& e8 \. Q H$ X8 f M+ u2 s1 uHR_pri = &((*HR_pri)->next);
& {" ?! ?# l! P- Z7 E0 O//printf("hello");
" x I- p0 B4 _7 f+ |4 ^! C//Sleep(1000);8 \2 [8 C& \* G3 [
}- q G i" k6 {3 ?9 S* f9 x
count++;+ L) t6 j; ?$ w7 q
}
: S& u# `4 s& f0 P5 t- e) w7 c. rif(systemClock==showTime)
+ V. w8 \! _9 U" }{
% A! r/ {' v$ T- q/ n! j( b/*PCI * p=FIFO_save_head;: A6 k3 x1 E3 H$ D2 D
int i=0;
2 j) Q6 y/ Q( t& S2 ^) nfor( ;p!=NULL;p=p->next)
# n# N0 b8 p! o# b7 W{
* l$ }) {8 |2 v1 j. Q0 d& sprintf("Id %d\n",p->processID);
! }) ]& O; n: R. w! \printf("comeingtime %d\n",p->comeingTime);
9 J8 j, `" i# V& Xprintf("runningtime %d\n",p->runningTime);5 p( [9 v( L, p6 ~* ?+ E
printf("asdmemory %d\n",p->askMemory);6 T7 i: P; Z' F8 B7 R! C
printf("completedtime %d\n",p->completedTime);/ o7 Y- {$ e0 l5 e/ o( \
printf("compute %d\n",p->compute);2 q- M& ?2 d% `8 }- k/ y
printf("exchange %d\n",p->exchange);
1 [( c8 |# B, a% E; ~ Sprintf("waitio %d\n",p->waitio);& N# [4 e% z, |1 k6 m
i++;. x2 j3 ], s% P" f
( C+ \* S6 O: {- V* `
& L1 [2 Y- E7 W) J, ~" [
}
" ~# X! ~5 b/ H* K8 e) p! jprintf("%d\n",i);*/5 f. g5 _$ f" i `6 x7 c( I# ?7 s' x. h
if( (fp = fopen( "data.txt", "a" )) == NULL )
" c' Y8 }6 i9 W{
0 [: L# i# m K4 oprintf( "The file 'data.txt' was not opened\n" );
- b* m. [) ~7 C% c//return 1; Y' O/ R" g1 o
}) M) Y, [' {7 f1 y2 X4 `1 f7 T5 f- e
else
1 a, E& Q' F* j, L- H% k{
6 z8 d; Q- U5 x' ifprintf(fp,"FCFS \n");
; H' Y! i9 O& P) hfor(p=FIFO_save_head;p!=NULL;p=p->next)
' s6 C/ u9 r1 p0 e: C: Rfprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
: H. T" w% h# B6 v, E! gp->exchange,p->waitio,p->runningTime);
. ?+ N- x8 F: u: n$ _fprintf(fp,"\nTime turn \n");) d+ B- V' V! V8 M$ I- j7 X. y
for(p=Timet_save_head;p!=NULL;p=p->next)
( x6 A1 Y2 {% }# @/ K& Z: @fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,' Q' \' x4 z" O" L* H
p->exchange,p->waitio,p->runningTime);# {( H; K, d" b
fprintf(fp,"\nShort Job First \n");' {" H4 `5 v* J% H& G, I2 Q$ }
for(p=SJF_save_head;p!=NULL;p=p->next)
8 F: e* Y) e W5 C! I4 [! Q- ofprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute," w0 [! K7 J) P7 }+ E- Q4 r4 t5 ]
p->exchange,p->waitio,p->runningTime);0 {1 J& U- s! M" ^2 J0 S
fprintf(fp,"\nPriority \n");
2 U) I6 V: F# v9 cfor(p=Priority_save_head;p!=NULL;p=p->next)2 P& @7 T/ M; G- H/ n: C! b
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
. ~+ T) ]4 ]$ `' x! r$ ?2 @ U3 Pp->exchange,p->waitio,p->runningTime);
7 p: ^" h' C6 n% U3 k: \$ Yfprintf(fp,"\nHigh response \n");% s3 Z) J+ L3 v4 w
for(p=HR_save_head;p!=NULL;p=p->next)2 t$ f8 C5 M/ F; w
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,& B; ?9 X" x$ h8 X" v$ @% [
p->exchange,p->waitio,p->runningTime);
& ]+ p2 d- ]+ e2 R4 J, ?fclose(fp);
* I1 G/ _' F/ U; e6 X}
7 u# |9 W( S" w8 q. fshowRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
, R" _% h( K3 [& GMouseListening2(&flagDraw,&showTime);' w# q$ {% J1 K7 t$ L$ T3 E, E
}9 g- [# J' ?) Z: `/ ]5 }$ ~
systemClock++;
% L0 e- I2 @" P9 G% m2 m( Mif(flagDraw==0)) {% y# H0 l: a1 U
Sleep(10);+ ]" F0 G) {- D& `1 z* v" ]6 l! ?# r
}
( D5 e* w5 ^6 p) Y$ g- b* _1 i; K) F! _* H: l/ v
( R* Q0 `& z& T: d: [: l I9 @}0 C A% _7 ~- x1 y$ w
int showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)( i+ N/ d; _5 x( v' e! r
{
' E! T4 P* J5 m. y' QPCI * p=NULL,* name[5];/ ~$ O0 j4 D6 Q9 D
int count=0,i=0;
4 j- k* h7 ~- X; j8 i% x6 d8 rchar ch[5][10]={"FCFS","timet","SJF","PR","HR"};
' p" L( F3 o/ o# R. k) Ndouble turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};
) e! L l1 \2 H" _2 I4 rstruct info
9 I) y \, X0 M$ w0 m{
, u& o. ~" O& tchar name[10];
( {' |- Q& n9 l8 j% s d! ~' j' hdouble throughput,turnover,wait,CPU_rate;, \/ p, Q3 J# H
}inf[5];3 b: r. U9 A; G2 Z6 F: a- M
name[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;
6 u* K: C( h: ^# Xprintf("调度算法..........A\n");6 J, p/ k o3 W
printf("吞吐量............B\n");
, `; i* z, h$ h2 j; Dprintf("平均周转时间......C\n");
' ?/ s5 C4 j6 tprintf("等待时间..........D\n");
- D1 l, b1 U. V, O; i2 Z% Nprintf("CPU利用率.........E\n");6 q$ X; N' O" N& ~0 Q4 K
printf("A\tB\tC\t\tD\t\tE\n");$ I; q! ~' M# f& A3 b0 ]
for(i=0;i<5;i++): e% x# \8 M! h j {) S6 \
{
; W0 C; L, T; F& P/ s) @! O" wcount=0,turnover=0,wait=0,c=0,w=0,change=0;' P5 W% A* H: L: q
for(p=name; p!=NULL; p=p->next)* K1 s, q! J+ \/ v9 `2 a% h9 f8 F0 D
{# M) y' ]" F4 L0 ], ?( q3 V( S
count++;
; {1 c5 K) }, L2 L! V# fturnover += p->completedTime - p->comeingTime;% h# p9 i0 `& u" d/ v( e( u
wait += p->runningTime - p->comeingTime;
' P' q5 j) I# c. H0 J7 `c += p->compute;8 @% l6 x, R" e" D2 X
w += p->waitio;
4 ^% z7 G& d; |& vchange += p->exchange;5 a6 J) F, Z4 q/ q; U( Z/ f
}
5 Z9 s- j) A7 m) Hturnover = turnover/count;5 `4 {4 j( T5 D& F3 M
printf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));
1 m% F9 O1 y5 G5 C& ^: n1 Qstrcpy(inf.name,ch);; v" X, A3 ~) B: ?! Z/ F
inf.throughput=count;
* Y. t4 `4 u. Xinf.turnover=turnover;5 Q) |$ A! N4 q( X O7 B1 E
inf.wait=wait;3 O+ d# q4 O# ]& d
inf.CPU_rate=c/(c+w+change);
( r5 G: X ~" y% A* k}8 `# e" K0 J) Y: J s# l; `) ~+ ?
//画图
" X( {' L D5 u2 @, n//cleardevice();0 r4 [% s) j( B+ ~
line(0,600,1200,600);( o0 s- o, S& U1 a5 A" G
line(10,600,10,200);
5 f# F- @6 G3 i1 P! }& u$ t! Kline(10,200,5,205);
( M4 I# H2 d" D! X9 z% A( Qline(10,200,15,205);
# v$ g0 O4 a3 b- F7 U8 b- Uline(310,600,310,200);
6 D9 m9 R8 V+ Tline(310,200,305,205);
2 D: c+ o- c$ c; [line(310,200,315,205);
- l7 w. v- h4 L+ _; Iline(610,600,610,200);
* k6 |8 \, y7 k( `( T+ u3 eline(610,200,605,205);
7 \, ~' K: ^! y( q _2 k- H' S/ qline(610,200,615,205);3 a5 e6 o4 i+ T/ I& M
line(910,600,910,200);
1 V$ X0 @/ o2 \4 c# t: {: qline(910,200,905,205);- E$ J9 V& m2 D7 l
line(910,200,915,205);//最高的长度400,宽度均为40
|6 g2 y1 d7 }1 ^; ?6 tfor(i=0;i<5;i++)
% E/ @, f4 _5 k{% Z4 M0 z/ F9 n% a0 e. H; S
if(inf.throughput>pos[0])1 r6 D1 s3 x5 K9 e; w
pos[0]=inf.throughput;; z4 R2 J( H2 w" T
if(inf.turnover>pos[1])9 X2 ?( L& M' S5 y9 s1 U; ^* k: O
pos[1]=inf.turnover; i) d0 M5 V$ e8 ]2 s" b8 G
if(inf.wait>pos[2])
1 l* f$ W) v% V1 m, Jpos[2]=inf.wait;
" _' P5 \. X0 c; t: s8 ~6 Kif(inf.CPU_rate>pos[3])* D5 \( t I, ^1 w
pos[3]=inf.CPU_rate;6 x! {8 z+ w- @
}, S4 k! o, i5 {- B5 I+ n. U
settextstyle(30, 15, _T("楷体"));( e# N5 r, D! }( T
for(i=0;i<5;i++)
l& N& K% e/ G+ b6 |{
7 r. x2 ^7 N9 lswitch (i)3 p$ @9 s5 e: j
{
6 |- k# \8 l% k& c$ B0 ncase 0:- c: Z. K6 U) W/ Z/ V
setfillcolor(BLUE);& }2 y' j! i8 U4 _6 Z. Q! B7 ^
fillrectangle(100,50,150,100);( X3 X) B, U1 {4 h
outtextxy(160,50,"FCFS"); U. }8 [6 B5 `
break;
. [) n1 Z/ M5 f2 f4 E! G1 F& F# w+ a! lcase 1:6 e% G8 r8 Z8 h% Q4 {
setfillcolor(RED);, h+ t1 V* C9 s" j+ D* I
fillrectangle(250,50,300,100);- _0 p0 v8 [& a' K8 K
outtextxy(310,50,"timeTurn");
( L) U0 A6 v; g/ ]3 bbreak;* G; l. n3 u, {* |: [& m
case 2:
- a: [( {, g5 u6 r- e+ p2 s' j, qsetfillcolor(YELLOW);9 }$ b' Y/ B, t6 o9 s
fillrectangle(450,50,500,100);7 ? S7 t# P- F# O5 E8 s2 g0 b6 w9 ]7 J Q
outtextxy(510,50,"SJf");
# a: B4 p% W3 y0 xbreak;6 u( n4 |5 Q' n6 g
case 3:) O. c ` Q, g# V# ]
setfillcolor(BROWN);
: |+ U. }5 d- E# O4 g Kfillrectangle(580,50,630,100);+ @1 n" G; s* i5 W" U2 L" I
outtextxy(640,50,"PR");
a# F. }% c7 y6 t1 F i( Rbreak;
- R+ C3 u: P& T# m+ t8 N4 zcase 4:
) C2 ?8 f/ N# x2 E- n: W7 l7 tsetfillcolor(GREEN);6 D0 }& g e" @
fillrectangle(690,50,740,100);
1 r- ~2 w. A) ?8 g& P. A' Louttextxy(750,50,"HR");
3 [1 n2 V% g; cbreak;, Z0 P/ ?6 g: j4 @& c. q& v
}. K/ A! I! b F6 |* s6 l! Z
fillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);
6 o! `# W- C! {+ _2 ofillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);# m. d$ a3 [1 l3 W% R: i5 ^' ]1 K- M' \
fillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);: a X/ q2 M/ G3 \. O
fillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);) Y w) l, Y+ v
' C4 g! Y. c' t& G" G
4 k7 w! @5 n( x& l}
+ O$ E! F4 z! m8 o( N outtextxy(100,150,"吞吐量");
]% R3 Z9 n4 ~/ W$ [outtextxy(350,150,"平均周转时间");& M U/ P" l' s* Z6 t
outtextxy(650,150,"平均等待时间");6 ^/ I4 W. e0 ~, c" o1 k- X: l% C' o3 B
outtextxy(950,150,"CPU利用率");; ~! K; }& x/ F0 j+ z4 o J
return 0; [ }6 d0 h, [" b7 |+ a' N
}' x. @9 B R4 p
int MouseListening()
' C% T0 q; z8 V2 i6 K5 B7 \+ x{- g( |% T! B* N. c/ L3 W8 B. F
MOUSEMSG p;: ^8 S" }; P; k- k6 C/ Z, G
if(MouseHit())* I- E4 k* y; D- ~) q4 v4 Y
{1 `1 U7 V; v f+ h
p=GetMouseMsg();
: f( g$ ~ D& o+ b0 U" B) oif(p.mkLButton==true)% q" [9 \/ z7 v8 C
{! p" d( W# [: E3 ]$ X; \7 B
if(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)1 W5 c) E3 p* M/ I& J& k" w
FLAG_FIFO = 1;: o# u/ l, \% P
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)0 }+ L% s. t7 Y( G% n" t
FLAG_TT = 1;
1 C8 Q0 ]! W B; m: v) A9 _" Zelse if(p.x>800 && p.y>0 && p.x<1200 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)8 |) ], K; n. C
FLAG_PF = 1;
4 a. k6 f' R$ [ G3 B2 w/ K' @- e+ helse if(p.x>0 && p.y>325 && p.x<400 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)/ u4 U& V% |1 N2 z
FLAG_SJF = 1;4 K: A6 e0 c7 u$ L/ f4 P
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)8 F) `" g4 D& O k6 F7 z+ r
FLAG_HR=1;. M' C0 W# \. V7 ]0 d
else if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)/ t3 p) C* E7 w! l4 O6 h2 d
{ ^3 n6 |$ r+ I0 j& G1 q6 ]
FLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;& Q4 e! `+ v& x C. L! r
clearrectangle(800,325,1200,650);
9 \8 l$ o+ }5 d: A( O+ r}
' I4 I9 R; S/ X# ]1 J* Welse if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )
# N6 q* B: B& G- G{' r! E+ l5 r# U Q' W. ]
FLAG_show=0;
- D% m( Q; f# P% B8 lcleardevice();
/ [1 L4 m" X5 G# m. Nreturn 1;
1 _- p$ ~% _/ x7 r6 c- \7 }; z}; D- |) Z' L# q' K$ k7 ~* t( v/ D3 D
}
) A |, L5 \" Z}0 Q6 c$ E: Y+ l* k) `& }
return 0;
l: Y* c6 O5 b# W}9 ~9 z0 g I1 s- b, N9 V0 M$ F
int MouseListening2(int *flagShow,int * showTime), x% Z6 i4 j, H `; L: c* t% Z G
{8 K' j) J4 R% _5 ^
MOUSEMSG p;
$ g Z5 n: m& R% K( {$ k/ Xrectangle(1150,0,1200,50);
7 s* a- K1 H- r! o* M- W; @outtextxy(1160,10,"X");
g; L0 R H! m8 H( l% I( ywhile(1)
3 s$ V' ^2 _# `3 U3 _8 ~& M{
, @# Z* I t! Z% Kif(MouseHit()), F5 t. R* `5 y2 F
{$ }) x" s- Z; A! W! a/ B
p=GetMouseMsg();, ?: p! d( u# [
if(p.mkLButton==true)# N6 r- b/ |2 I- |* `* M" g
{4 ?' b0 p/ i( ^/ `- j6 F+ b# W: v
if(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 )
! O; x1 A {2 P2 ?6 s1 O3 Q; U{
$ Y$ B2 f: ~) V d(*flagShow) = 0;
' u% J+ ^ I9 W9 t0 P! N4 B(*showTime) += (*showTime);) a8 K0 ^! E |+ G
FLAG_show=1;
D+ \/ [& _6 B, j3 y$ S/ R* U. @break;
1 X2 y( e' E. Y' o0 F; P* b' I}
0 B4 e2 ?, U% `& H- c1 ?
5 t7 T: A R* W( P}* c# v1 ^9 p! P$ d: k
}0 Z& L+ {6 w% b5 A. b
Sleep(20);
% {' t/ {" ~, `! L}( c" `' s. y5 |% A4 l% c& d
cleardevice();; Q2 Q$ r5 m6 t) Z i
return 0;
& f% I5 K/ ~" j}" s+ q, k6 v+ }* V& ?
int drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)6 W- E; ~6 e- b9 R- o' @3 n _* @
{( N9 P R3 m( o* m9 U. n) Z2 h
static int info[11][3],num=0;
- K2 p# \! L2 j$ Xint i=0,j=0,pos[10][3][2];
2 g4 Q9 m0 S4 m9 m$ {- Yfloat temp,t;
1 A) g# S5 c; ~, Q( h8 v//画按钮,不属于FIFO图的范围( ^) ^* }1 |3 O( M9 X
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1)
( E" |+ W* _! M{
0 Q4 ^6 t' q6 t: esettextstyle(30, 15, _T("楷体"));' Y8 A8 J8 T r' p! Z l" f
rectangle(890,455,1110,510); V7 \: {& F; Y0 K; }: y
rectangle(900,465,1100,500);! j, Y3 L6 T" ^8 |1 B
outtextxy(910,468,"查看运行结果"); n7 Z4 m9 O% ]/ }( [ }! A7 F- j
}2 K5 S5 S- I$ `6 L
//结束画按钮2 i3 p* F; ~7 v: c' O
info[num][0] = com;; i6 u& ]+ A" T. o8 c% ^6 U
info[num][1] = wai;9 m& c, V' J* q
info[num++][2] = cha;5 ] P8 J- V$ @! }9 W; C
if(num>10) //存储10个点
& A( w6 ^% F) |. l9 ?" G3 I{' ~* G9 o4 S5 k P9 [7 B
for(i=0 ;i<10;i++)) R0 e6 u' Q8 \) o
{
# n- ~1 Y, ^- Finfo[0] = info[i+1][0];
: n: X# h8 x, z8 n% o" x2 P: Jinfo[1] = info[i+1][1];5 p- _2 t0 y! O5 F% h6 N# c
info[2] = info[i+1][2];0 p3 ?( s# ]5 B U- f5 Z
}& R8 o+ q% z* c; n
num--;) o! N/ j) U% [0 D
}
; t3 h Q" v% ]0 Q! nif(FLAG_show==0): a; P: i: U3 |, [" X4 `% _
return 0;
5 e. A! I1 P" G& n1 p j$ afor(i=0; i<num; i++)) X4 P2 Y* r5 P0 b
{
. P6 W& n* K6 ?9 d7 |8 ot = (float)info[0];
3 |& i% P) U. _9 o5 I, stemp = (t/101)*90;" Y: F" @$ e! w3 e( c6 g9 x1 P
pos[0][0] = (10-num+i)*25+x+100;
0 Y) h% w$ F- i% y4 H1 ~3 ypos[0][1] = y+110-(int)temp;
' j r- X* } ]& xt = (float)info[1];
( q; `& e& }* s3 {! C6 s. Ktemp = (t/101)*90;
- p( g$ I" w6 o, V" epos[1][0] = (10-num+i)*25+x+100;
& F( w4 a3 W) }, F6 cpos[1][1] = y+210-(int)temp;
6 V' @. e. L6 y nt = (float)info[2];! I0 K4 @7 ~0 }6 J) P
temp = (t/101)*90;
+ g$ G3 j- x6 r/ [0 T) \# ^pos[2][0] = (10-num+i)*25+x+100;4 j& J, p, M9 h z% L/ P; Y) M
pos[2][1] = y+310-(int)temp;7 i1 d& [& c$ w& z7 [$ D0 F- r! j
}/ J1 Y; @3 [% P# j4 }
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)9 M! c- m1 ?+ T- P7 M0 q
{* H0 m/ C+ I3 t1 Q
clearrectangle(x,y,x+400,y+315);
3 [6 A8 ]6 r6 P# S2 i& T, g; Xsettextstyle(20, 10, _T("楷体"));9 G" y9 Y# [" y
rectangle(x,y,x+400,y+325);
! P) Z6 q) E: O% c$ Aouttextxy(x+40,y+10,"CPU"); //画柱状图
1 U& _3 ~! y6 ]4 p7 O* U6 ]/ Gouttextxy(x+45,y+10+100,"IO");+ [4 `% w# Z$ ~: }) R2 G
outtextxy(x+40-15,y+10+200,"change");: s: j) h& Y$ c/ [8 E
rectangle(x+35,y+30,x+75,y+110);
- v4 `3 j& @5 l$ j1 Prectangle(x+35,y+130,x+75,y+210);
$ ?9 }- q( h5 Qrectangle(x+35,y+230,x+75,y+310);0 K3 y8 R4 U7 M6 J
outtextxy(x+180,y+310,"FCFS");; \4 v% t' m- M- e( Y$ `" {3 Y
t = (float)com;
9 h1 f5 u: P5 K) G4 ~temp=(t/101)*80;
# [/ A, M- c! ~' K% J$ wfillrectangle(x+35,y+110-(int)temp,x+75,y+110);
6 p5 }0 [* }2 h: Q! ?1 @t = (float)wai;0 \ ?6 R# O" H5 s/ O( F4 C
temp=(t/101)*80;& G3 U: G+ Q( r$ G4 P
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
7 l( P2 o, ^+ {t = (float)cha;
( i6 A, e% f+ [/ |2 E( Atemp=(t/101)*80;
6 g# g n+ R4 y; ?! m9 jfillrectangle(x+35,y+310-(int)temp,x+75,y+310);0 F' b0 q( H& x6 [7 @# w, E* M: I
for(i=0; i<3; i++) //画坐标 high=90,length=2500 o$ G/ C& f; [) d* U( X
{( F% G& i% f9 \$ k1 L
line(x+100,y+110+100*i,x+350,y+110+100*i);
3 |, y% Q2 t& k2 m8 ?line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);* I4 R4 C, z' }% {; F7 ]
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);6 g: d/ a4 j! K5 b: ?
$ R2 H- @9 k* k$ @# C' a, f' y
line(x+100,y+110+100*i,x+100,y+20+100*i);* A$ t( c& b7 `
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
% f! s6 j g* ^. \line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
% X1 `3 w5 T% A) G, r' F8 n# R4 \# ]for(j=0;j<num-1;j++)
* j- R2 x5 ^9 a, L{
5 U. B" g9 n% i* Qline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
; w1 s; @8 [- P, Z: f& |! jline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]); ~4 k+ _/ ?; N7 V& W
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); , `- M" N i, d. c9 v$ k% E
}
) q0 C: y: P1 ^& y) t}# ]- X" d/ R% e( p
}
) V: ]: B0 M& [1 z1 z/ ~8 I1 A5 w+ G* Xelse if(FLAG_FIFO==1)
( l+ Z7 H. ?1 ], w' }{- ^ k4 p0 X1 S1 o
x=0,y=0;
' G9 X& m- h- Dfor(i=0; i<num; i++)
. q6 ?( I$ ?+ P; M{4 {( G' i x# u" _- q5 @& X; |# M
t = (float)info[0];
0 W, o7 Y, T4 D4 d7 Ctemp = (t/101)*180;
6 t: X7 t4 ?) c$ U# o7 ]' q& S8 G& ipos[0][0] = (10-num+i)*50+x+650;" @3 }: _$ n# m: ^, ~; O
pos[0][1] = y+210-(int)temp;) e% A1 Q$ H7 U% ^: l, ?5 Z
t = (float)info[1];
- X7 q/ y3 K+ p7 v4 X1 Ntemp = (t/101)*180;
6 ^7 `2 O+ X* h9 M: qpos[1][0] = (10-num+i)*50+x+650;
; c2 J0 n: D: u$ V7 Y8 Opos[1][1] = y+420-(int)temp;/ J k/ ~. o8 y! H: A- q
t = (float)info[2];
5 O X% ~. O7 A w) k# @1 Ntemp = (float)(t/101)*180;) B4 Z% d& F4 ^/ x# V- `3 i# k* q
pos[2][0] = (10-num+i)*50+x+650;6 Q w; E+ }$ t* F) M& z
pos[2][1] = y+630-(int)temp;3 P* W$ O! T( E9 y/ k* H$ u
}
3 k+ w2 ?3 t. eclearrectangle(x,y,x+1200,y+650);# P, j; a' o( T3 I- z1 M4 ?: z# b$ Q
settextstyle(40, 20, _T("楷体"));+ b8 W8 n9 _1 \. O
outtextxy(x+50,y+50,"FCFS");
0 M6 K- A6 t9 `( e# d0 routtextxy(x+280,y+20,"CPU"); //画柱状图
, [8 Z( }& o& B3 U2 s7 A9 touttextxy(x+285,y+20+200,"IO");
1 o- S; v1 i2 P% r$ p( Gouttextxy(x+250,y+20+400,"change");! r f' {# X" j. H9 f( c- h
rectangle(x+270,y+65,x+330,y+215);
# l" D" m4 Y7 N5 krectangle(x+270,y+265,x+330,y+415);
/ r- A1 o5 n3 g* h8 W( v2 \$ G% trectangle(x+270,y+465,x+330,y+615);9 q$ a k) G% u; @" ]# k
outtextxy(x+290,y+620,"TT");
9 a* r9 E8 z" x* Y! S; G# X$ `t = (float)com;) Z# L$ Y. S: C* ?
temp=(t/101)*150;1 f! q) F" }, F( D- d6 |
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
! I) w+ h1 p+ Q% B6 ]8 Lt = (float)wai;5 \- A' Z* K' X! ~& s3 u0 b
temp=(t/101)*150;
/ J0 ?2 i% H% |$ rfillrectangle(x+270,y+415-(int)temp,x+330,y+415);4 ^1 x6 e1 d9 P( o- A' e& T/ j
t = (float)cha;
, {$ F; L |& I- htemp=(t/101)*150;+ U; w/ Y1 W C' b: u! E& u4 T' l" M
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
$ a) c9 n, }+ L8 s! q, j1 ?for(i=0; i<3; i++) //画坐标 high=90,length=250# R) o9 X) L" }' D
{
( j# }' H& [; Z$ N6 xline(x+650,y+210+210*i,x+1150,y+210+210*i);% N9 ]3 @2 m9 c2 }. @, w! \8 ~
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);; t6 @8 T& V. }6 B( G
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
5 a1 q0 K8 c! k% V$ A/ ~$ }$ P# h, L A! r+ r; f7 m3 l% p5 G
line(x+650,y+210+210*i,x+650,y+20+210*i);
4 k, C$ G: k7 E5 C/ mline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
( ^, ^: d( L% P3 h- Iline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);5 s' F% ]4 i1 J. ^% w q2 @2 ~. n1 u
for(j=0;j<num-1;j++)
, U" u0 \% Z; |; ]1 i" U{
: [/ o0 o e5 t" Tline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);# x, W% _- U6 y, I( K# A" z! c
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
+ Z" A" _ [* r# C& K0 H, y5 dline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
! p% G, @6 I7 a2 n: m}
, Z: k4 O+ C' t2 j}
2 a( V0 r4 A& e; |' s5 I}9 v! `3 n: u( Z, D6 u. @" |
' G7 y. f0 M% j. R# M, o3 I
, l H0 a7 t f$ Rreturn 0;
2 ~: W; u9 G$ Y, n}4 l1 S# L+ q" u, x- N! l
int drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)
1 e# Y: ]+ {% t7 |) x& M8 @{
# s- ?, k7 p2 c! w( Sstatic int info[11][3],num=0;6 F- v, ` u3 \( i
int i=0,j=0,pos[10][3][2];
2 \: ^3 y# d. @8 t( M7 }float temp,t;; o1 f; O8 b$ f9 L& r9 [' D$ R0 j
info[num][0] = com;
0 n: C9 r( M! F2 m& @; b; G) t- Ninfo[num][1] = wai;
% U; M$ i5 J/ _$ ~# tinfo[num++][2] = cha;% q6 G& m) V5 T0 U4 A0 [4 q
if(num>10) //存储10个点" h U2 A5 J$ y) E) u& G9 U: \3 |
{
* a, A( s( O9 Y) G$ G3 jfor(i=0 ;i<10;i++)+ H* j- m! u1 o9 v# b/ e; i" p3 p
{
! C) i d6 }% F1 w" q9 Vinfo[0] = info[i+1][0];
9 r p4 |% `+ o3 T, X ~, linfo[1] = info[i+1][1];- w7 l) x3 n! a1 W3 t
info[2] = info[i+1][2];( R" r8 d2 h* F$ X) n. i6 u+ N
}
& n! e1 n0 M6 T. X. G% g6 Bnum--;% G' R& i0 @9 C& d
}
* m# H5 q: b: ~7 u$ R! X( {if(FLAG_show==0)9 E: |% _) i' L/ q; M' \4 S
return 0;
* Q3 q q8 y7 L/ _for(i=0; i<num; i++)
. H' f+ |3 o. Z; W/ l) m1 u* f{
, p. z: {9 L+ s ~t = (float)info[0];
/ g; ?" H% i* E( T0 G, gtemp = (t/101)*90;
9 q, M/ u' H: {! M# G6 kpos[0][0] = (10-num+i)*25+x+100;' g6 J/ W# ~& b3 E1 [3 @
pos[0][1] = y+110-(int)temp;
$ u! N5 v4 F* R% z4 Pt = (float)info[1];
: Y2 x0 q7 ^8 H3 `0 Etemp = (t/101)*90;
+ a- e& q. j/ |3 e! ypos[1][0] = (10-num+i)*25+x+100;
; j) l, M( U8 U0 r5 k4 l3 u6 lpos[1][1] = y+210-(int)temp;
' y# S, }, l; v4 ?) k7 x; m" t9 yt = (float)info[2];* l* e& m" B1 P" Z" w& T
temp = (float)(t/101)*90;
9 |& M7 O0 Q7 dpos[2][0] = (10-num+i)*25+x+100;; I" R* F. a; [: M! P: f
pos[2][1] = y+310-(int)temp;! G$ x- ~! Q9 Z+ H4 J# O
}
% O0 n) ^+ ^& N3 y3 E) w* Fif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
, j9 O3 {/ M- u6 y: L$ I{
d: I5 p( M. y. y$ a8 Gclearrectangle(x,y,x+400,y+315);2 q, B+ }5 P8 M& q
settextstyle(20, 10, _T("楷体"));% F9 `# p, n. e9 ?' C
rectangle(x,y,x+400,y+325);
( l/ x( a/ R+ Nouttextxy(x+40,y+10,"CPU"); //画柱状图6 z$ W8 |2 a& Q- h- s1 w
outtextxy(x+45,y+10+100,"IO");! p9 z5 v) |" K2 n8 N
outtextxy(x+40-15,y+10+200,"change");" U. l: Z! N J+ ~
rectangle(x+35,y+30,x+75,y+110);
- C2 Q- r; Q9 r: Brectangle(x+35,y+130,x+75,y+210);1 E* p( M' J! p" X0 [/ A6 E
rectangle(x+35,y+230,x+75,y+310);
2 [+ \- c! F8 r0 @# f! ^outtextxy(x+180,y+310,"HR");
9 s; ]% p3 O- k; f7 X* n% Vt = (float)com;8 J& I; }' R' K; [3 L3 h
temp=(t/101)*80;
4 w/ I4 E% D) o6 t8 ^: L" mfillrectangle(x+35,y+110-(int)temp,x+75,y+110);
0 y# M- \- z* o) @+ i/ ?2 tt = (float)wai;. b" e/ e* s$ M( z1 r5 V) w
temp=(t/101)*80;1 D& M6 V8 X% v9 R Z
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);# [) X2 n3 A) v$ \
t = (float)cha;/ O! `3 O7 i2 O* O: L% w" i
temp=(t/101)*80; F( w2 \' e, n) r
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);& U3 Z0 W3 @: d" z) C% \. L$ u
for(i=0; i<3; i++) //画坐标 high=90,length=2506 I' u' c; h! q6 T
{0 s# L" c% l- ~1 ~& L5 M* s
line(x+100,y+110+100*i,x+350,y+110+100*i);
. l/ w- I$ I9 p/ [9 Jline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);7 D' m& {( F- |+ i# ], z1 l; @
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
; Y) { I9 \$ {3 R, f4 ?/ z: O/ ?* t6 I' u5 a
line(x+100,y+110+100*i,x+100,y+20+100*i);! A2 |# O+ a7 V( e
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
! P6 M* n! }" Z# @line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);- O( B/ C: ]! o8 |8 @2 v
for(j=0;j<num-1;j++)
3 \9 k1 \3 w- ?% }& s; {, d c{. j/ K7 Y6 i# U. c, A3 F
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
; k/ l! ]* f+ M) _0 ?8 |7 H) J4 d1 sline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);7 N, J1 a1 h2 W' X
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 6 l* R* {) x5 G8 K0 n2 L2 p. `# K
}
# a. o+ y7 _4 J}0 P& p& z2 ^. c5 e8 H6 P
}
6 k0 x4 d7 q; `" V7 Q4 o0 `! |& delse if(FLAG_HR==1)- J, t- r' J# h
{6 C& R4 p1 ^' ^) v4 v2 H
x=0,y=0;3 e% d% {# l% n7 c( N
for(i=0; i<num; i++)
3 t5 l3 N1 [& |: G+ w{% f2 p% Y1 L2 \' k2 D
t = (float)info[0];
, M) _8 d& x6 z6 l% Ctemp = (t/101)*180;# \( M U `( z
pos[0][0] = (10-num+i)*50+x+650;3 K# ~# Q9 c7 i- G5 g8 u) _# M
pos[0][1] = y+210-(int)temp;
, c3 `, U5 l2 n9 u% I$ |$ Y8 Zt = (float)info[1];
, Z# o( z2 e* N& ytemp = (t/101)*180;
% |# P1 F, z6 S. \pos[1][0] = (10-num+i)*50+x+650;
+ |$ \2 B/ Z, S7 Ipos[1][1] = y+420-(int)temp;3 s9 d0 M+ e4 l+ w
t = (float)info[2];
# w9 p+ O/ U. q: I+ p4 X$ }; J' Ktemp = (float)(t/101)*180;
% V' `7 j5 D1 }) Y9 qpos[2][0] = (10-num+i)*50+x+650;
7 O8 o$ c- s; z* A ypos[2][1] = y+630-(int)temp;: n- ~* x; X% h$ {2 A8 I, A0 s
}
% Q5 @! M% _1 |clearrectangle(x,y,x+1200,y+650);
0 T' Q* |$ l4 L7 B- f2 [2 psettextstyle(40, 20, _T("楷体"));4 H! ~1 P4 S- }( `4 c
outtextxy(x+50,y+50,"HR");
8 |2 Z, ?2 m" d* A( Pouttextxy(x+280,y+20,"CPU"); //画柱状图
1 d$ V' J# M3 Routtextxy(x+285,y+20+200,"IO");. u& W, H& E, u* x- _+ P
outtextxy(x+250,y+20+400,"change");
& V1 _9 d A# Q6 n# K* H. krectangle(x+270,y+65,x+330,y+215);9 A7 H2 J0 B( g
rectangle(x+270,y+265,x+330,y+415);
9 p3 a, O2 J5 m& v" P/ krectangle(x+270,y+465,x+330,y+615);
- E$ p! O6 `2 L, ~3 }# h% bouttextxy(x+290,y+620,"TT");
* u7 S2 V0 T$ Q3 R- lt = (float)com;! `! Z& g& e6 H7 L u3 L
temp=(t/101)*150;
8 T( [1 W8 I; j2 Qfillrectangle(x+270,y+215-(int)temp,x+330,y+215);- T3 u# a0 [0 g) E* @4 ~
t = (float)wai;+ F* W7 i8 D e( A" }; H P; H
temp=(t/101)*150;
- G- {! l- U" s! d! x/ e, D0 qfillrectangle(x+270,y+415-(int)temp,x+330,y+415);/ B4 p2 z# b+ a* J8 n' I/ g
t = (float)cha;$ f; W) f' Q# Y; p, Z/ T% _/ [2 _
temp=(t/101)*150;) [4 Z6 ?4 ], E! @- j1 g+ U& w
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
& k8 t9 z; l% B, z, w% v+ Pfor(i=0; i<3; i++) //画坐标 high=90,length=250. x$ v/ f% P+ c6 j
{& u) q7 u' g% V) h
line(x+650,y+210+210*i,x+1150,y+210+210*i);
( L6 x) d' E2 Z' }: c+ D& m( Cline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);" ^0 W$ i- b/ J% g% X% |2 E" r
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
: I0 E- x1 {/ G) [7 V) U' `. g, c
! n7 }: Q# t$ E& Z x8 r0 zline(x+650,y+210+210*i,x+650,y+20+210*i);
! F* D. E7 Q0 }: kline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
; O7 x7 b& T4 {$ W- Eline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);( u' U% d9 A6 U
for(j=0;j<num-1;j++)
B9 @1 t* ]: e/ T1 h! b{! _4 Y3 R- D- X& j4 ]
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
7 N4 g) \7 y: K( |! l! v& R; Qline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
) B8 b! s) x; H' f' Dline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
3 [) I- l) u; g. W! `}
, h6 T9 H8 K8 a6 ^4 @}+ C7 ?% D& ~6 l5 S# j* V* K7 T
}
' L& B2 z0 R$ d. v
+ P( h& n0 T' J! B% M
1 g3 }( r* i( A' rreturn 0;7 U- S* }6 k, ^. G: D, L3 Y
}
- w! Z+ F) K* Mint drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)
$ d6 t' f- d0 Z! U$ }{
+ I; E0 n ]$ L2 J* z8 ^8 z7 fstatic int info[11][3],num=0;# x) W1 C8 D6 t
int i=0,j=0,pos[10][3][2];& a* C& B. J7 M( c: \
float temp,t;# ^8 e0 d3 l1 s; B1 K# R
info[num][0] = com;
% e& u6 m1 d4 U1 N! minfo[num][1] = wai;3 w1 U5 j0 L& K& l N: N2 \
info[num++][2] = cha;
+ L/ d7 i' _2 p0 qif(num>10) //存储10个点
O- B& H) z: s& a' j{
6 h% \+ I. [# a* F1 vfor(i=0 ;i<10;i++)
; o. I- L8 S8 L& f, R5 @7 X{
3 ?: t* Y: ~. d4 f8 r9 A$ ninfo[0] = info[i+1][0];# U9 W# `4 M' p- ] L- w
info[1] = info[i+1][1];. S' Q( S- n" J7 Q* i
info[2] = info[i+1][2];, y5 g0 K" G6 U$ S, m7 d3 ~
}% S5 V/ U8 P! X. {" u. I
num--;9 y' s1 [+ R* ]5 I4 `: y
}3 \! k, @3 g7 h$ e8 O7 g) @
if(FLAG_show==0)5 l/ y$ @2 k1 }& n# U. h, ^ a
return 0;
: {1 e; i9 s ^/ { _for(i=0; i<num; i++)* _- i% A5 `3 C8 B' S% W2 {
{& V5 m6 b; C2 c7 h: n: o
t = (float)info[0];3 y; ^3 T k' S; s) ]
temp = (t/101)*90;
& M2 K1 C- w& P2 ^, z: _pos[0][0] = (10-num+i)*25+x+100;
' a; }/ L/ ?; v0 y2 y/ X1 |pos[0][1] = y+110-(int)temp;% o( r8 D3 e( j/ r4 ?+ a" ^
t = (float)info[1];
' _7 V6 T3 [0 C& R* ztemp = (t/101)*90;
; s# q- f: n' X h6 npos[1][0] = (10-num+i)*25+x+100;- e6 v" r4 L% Z6 d, w
pos[1][1] = y+210-(int)temp;" q) a* o' e- C4 I
t = (float)info[2];
- ]8 j* }% f) \; gtemp = (float)(t/101)*90;
$ J: v/ F @# {9 g. Mpos[2][0] = (10-num+i)*25+x+100;
( Z( ~, \+ L& _, `3 Cpos[2][1] = y+310-(int)temp;
: J7 j8 Z! j3 C* f}3 q1 T! j8 i# A9 i8 h4 u
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)& y5 B: b: H0 R. X, ~3 W! x9 b5 U
{/ V7 M) f, V, V8 P; A
clearrectangle(x,y,x+400,y+315);
K0 }$ ~! F* `) _4 m) @0 fsettextstyle(20, 10, _T("楷体"));
' L$ I6 c: @! R7 c. Grectangle(x,y,x+400,y+325);
8 N$ k: }7 U; J) o! Pouttextxy(x+40,y+10,"CPU"); //画柱状图
5 j3 b2 M; J: vouttextxy(x+45,y+10+100,"IO");/ o' ?( q# t! _$ c
outtextxy(x+40-15,y+10+200,"change");" z3 F/ P+ M, L( L9 n
rectangle(x+35,y+30,x+75,y+110);8 ^( u( h6 Y0 I, g) n0 P ]
rectangle(x+35,y+130,x+75,y+210);
% c9 }9 J3 m5 z, [+ y, ]rectangle(x+35,y+230,x+75,y+310);
$ l- d2 K7 \ ]. r; Bouttextxy(x+180,y+310,"TT");
" n5 `" w! ?2 R6 Kt = (float)com;( B4 b @2 g) L; s3 _1 |
temp=(t/101)*80;' s" j" V6 w. f( p1 e
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);; G& P5 P/ s) S8 n# u
t = (float)wai;
8 N% v0 E8 w7 @8 x' U5 Utemp=(t/101)*80;
4 c6 l W3 a4 Q0 {fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
0 `# C7 r$ ^# ft = (float)cha;' S5 m V4 p, ]. Y) H% I, j: l
temp=(t/101)*80;2 Z- l( r: t7 q# a( _! \
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
: J9 W- x N1 pfor(i=0; i<3; i++) //画坐标 high=90,length=250% y7 d! C0 j$ s( h% }8 a6 Z+ N1 t
{
, a* Y. J* U5 C6 p5 G5 k$ Y% _/ Pline(x+100,y+110+100*i,x+350,y+110+100*i);
' B8 K, n. ?% i+ k/ vline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
7 ^% |5 w0 w# \+ E1 Aline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
, d1 Y7 Y) {) p4 q
2 V1 p! t0 y$ t2 T) w1 Tline(x+100,y+110+100*i,x+100,y+20+100*i);
1 Q' Z6 S) S# M: ^4 Sline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
+ }9 |' w4 z2 C1 ]+ mline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);% V6 @; @3 ~* s/ R
for(j=0;j<num-1;j++)) R3 Z- F( I2 p
{
' h: d2 q6 o& o8 @- X* q& Iline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
. N6 l6 o3 D8 @' T$ |line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);: c4 A) G/ t6 q
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ; _7 W% f! B; r8 I$ Z9 F
}
: n" x6 C3 r/ X: [2 Q( ^}
$ ]& p) x! v4 y" e) c- P}
* m* b% ~5 |8 R0 |8 Melse if(FLAG_TT==1)+ Q4 M( P0 \2 o
{
F7 s: ?. N8 u4 Ux=0,y=0;
7 r6 S& @/ e6 [1 q% ?7 f; ^for(i=0; i<num; i++)
; u# T U! [( H6 E. v{
/ u. P/ q- ~) _6 Z0 M G0 c6 J+ s' `t = (float)info[0];" r( ^) i$ _9 V( O+ G- |% F
temp = (t/101)*180;/ A; r8 X4 f6 G/ q2 b
pos[0][0] = (10-num+i)*50+x+650;' K1 g' [# q1 N7 ?
pos[0][1] = y+210-(int)temp;, @5 A6 C# z9 o9 D
t = (float)info[1];" e8 \! e% s5 ~/ X3 b
temp = (t/101)*180;0 V9 ?$ u- M; `: f
pos[1][0] = (10-num+i)*50+x+650;
# Q5 a9 x3 [' w$ d, ^* v$ V4 s: ppos[1][1] = y+420-(int)temp;) `3 e7 s7 c2 Q# M- ^+ B
t = (float)info[2];
) J+ q# V& y3 b+ S4 }$ i1 W2 [temp = (float)(t/101)*180;' D$ T( ~2 Y( Y$ d! S) h+ d
pos[2][0] = (10-num+i)*50+x+650;* Z; O, n; e" \5 Q( s% g
pos[2][1] = y+630-(int)temp;
+ e% p3 G% O8 @' k) g* P# c}
: e* [' i. H* M7 J& e6 ^. pclearrectangle(x,y,x+1200,y+650);8 V2 Y2 h4 c! r
settextstyle(40, 20, _T("楷体"));2 M' i+ h6 z' A1 H1 q
outtextxy(x+50,y+50,"TT");
7 R+ x f+ ^! ]1 d: ~outtextxy(x+280,y+20,"CPU"); //画柱状图3 R" a) ]+ E. e m# |6 A
outtextxy(x+285,y+20+200,"IO");
) P1 @2 Q8 f, D1 a' e! T3 ~- wouttextxy(x+250,y+20+400,"change");
4 w4 s* \: w9 }2 ^rectangle(x+270,y+65,x+330,y+215);
( O7 |$ `- G# G9 q9 V& ]rectangle(x+270,y+265,x+330,y+415);) `2 W; O6 H# U
rectangle(x+270,y+465,x+330,y+615);6 P* s9 g- {% P* T) m5 t* O
outtextxy(x+290,y+620,"TT");! M6 \. m* j/ C$ [
t = (float)com;
" Z9 E. ~ u) Z. w% Y% stemp=(t/101)*150;* W5 Q* r4 q$ U9 [7 ]2 \* i
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
# z4 L2 t w7 Z z& o& Q/ at = (float)wai;: G/ A& S7 C3 Z/ ?3 j
temp=(t/101)*150;; K( u+ S: F8 a+ I
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
# A( Y; B: }- F# Ot = (float)cha;
# Y) y ]* t% l7 X5 Dtemp=(t/101)*150;1 |; y3 v. U' B2 ]- p4 i6 @+ ?
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);8 F9 I: @9 V! U P q$ m9 r
for(i=0; i<3; i++) //画坐标 high=90,length=250
, h- ~2 B& p+ D9 E c{( J* f4 T6 E$ q: _
line(x+650,y+210+210*i,x+1150,y+210+210*i);
% |- ^/ |: [: n; ^4 Cline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);5 P: ?$ L3 ^0 ~' p7 K+ C
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);' Q A0 p* }1 Y0 _7 P$ o
, c$ |( `1 L' ] i1 {- w
line(x+650,y+210+210*i,x+650,y+20+210*i);
; E3 e7 k2 N# X1 i$ K' x) Vline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
" F" [- h( z% R! q# Wline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
4 ?8 d1 T& ]' h, a g7 Hfor(j=0;j<num-1;j++)- Z3 w3 B$ o: f& f+ q" Z4 `
{
- K" }8 S: f) w$ O7 L/ f0 Hline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);8 Z2 M* [ G0 f
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);% r0 C' R0 u4 } B. ^# e+ z2 [
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
$ [$ a" G2 |$ f: G+ n+ q8 J} R) ?& D* _) J) B5 f
}$ g& H. i% P- v
}
- P P$ F1 n4 D( u8 e3 A
; U2 j$ M# G% |+ q- X
' `6 | x& U1 x0 mreturn 0;
( U0 k& k: a8 b" e; ^ d- M}
' y8 s1 J P+ U$ L; fint drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)
8 ~9 p4 q" R* M/ T{3 j D1 O$ [; X) q- _* s
static int info[11][3],num=0;! r( j* A# U" k% L0 G: ~: o
int i=0,j=0,pos[10][3][2];
2 ^6 m5 x( X, M/ }/ y" i! kfloat temp,t;2 A) u" q Q6 f" f5 _
info[num][0] = com;1 s0 p I6 x" g9 D, A5 _
info[num][1] = wai;
2 k- r. d0 u' x3 y! \( qinfo[num++][2] = cha;* T- H) B# B O8 _/ L7 G! t( Y+ P
if(num>10) //存储10个点6 G: Z. G2 ]8 G8 e. a
{' P: ~0 g, _% U5 o( l( s( f1 T
for(i=0 ;i<10;i++). b7 _& Q" L1 ~. Z1 }( L( J E
{ l8 q6 f* {1 O' i
info[0] = info[i+1][0];: F) h3 c% L$ F. t( j0 `
info[1] = info[i+1][1];- C# P1 b% ~5 C+ v/ P c( Z
info[2] = info[i+1][2];3 ^ ^7 o/ f% h5 O$ g+ y
}
" f" r. `2 w& L) j( y- w2 R# Cnum--;6 E; j/ H4 B6 Q7 j% h# j% G# _
}
- e" F2 A# Y0 L3 Lif(FLAG_show==0)/ O, F7 O+ ~8 ]# |% L3 u! s
return 0;
4 V3 H- _3 l7 k3 {9 k! O: Ufor(i=0; i<num; i++)8 }9 p( H1 A a4 K
{' a$ S( c$ ]& x6 v# Z! p
t = (float)info[0];+ p( C: a& e( G) x
temp = (t/101)*90;
' i- u- s, A! ^- X; cpos[0][0] = (10-num+i)*25+x+100;
3 W3 I1 t: k$ Z, \, l; Cpos[0][1] = y+110-(int)temp;
3 p$ D1 H0 O( c, ^7 @; ^$ ut = (float)info[1];
$ E- e9 ~+ `2 Vtemp = (t/101)*90;
4 B# U2 G) l' m0 g' qpos[1][0] = (10-num+i)*25+x+100;- a; T. w4 j* o5 y. }8 v5 b
pos[1][1] = y+210-(int)temp;
- m: _' M; T3 z( F' wt = (float)info[2];
+ C- i7 I; C h3 ^& qtemp = (float)(t/101)*90;9 z# f7 ~9 m5 V' W/ M3 G
pos[2][0] = (10-num+i)*25+x+100;8 y" X7 e! n( s1 Z" s' I
pos[2][1] = y+310-(int)temp;
& A# p. {( e, Z4 ~7 X}
$ l0 H& U I# k: q( Oif(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
2 T8 I3 r; x e{
' T" c1 D s: y# ?clearrectangle(x,y,x+400,y+315);. G, C8 _6 r% W$ j) I3 i( H
settextstyle(20, 10, _T("楷体"));
' h, X% Z% M8 \. Hrectangle(x,y,x+400,y+325);' n7 m# x6 N, w( t# `
outtextxy(x+40,y+10,"CPU"); //画柱状图
- ?; S) h, f* [9 houttextxy(x+45,y+10+100,"IO");* s- b- M+ @8 c
outtextxy(x+40-15,y+10+200,"change");
5 n; ^4 v k' }9 t/ ]% h1 x, \rectangle(x+35,y+30,x+75,y+110);
; G7 c& o) u, c1 z1 P" Irectangle(x+35,y+130,x+75,y+210);% R3 ?2 h1 F- D
rectangle(x+35,y+230,x+75,y+310);
# g7 o: P; P5 t2 _/ X G2 @outtextxy(x+180,y+310,"PF");) k3 n1 k( @$ e$ u& U! i' }
t = (float)com;
+ `5 ~5 R6 f9 M$ X: i- ctemp=(t/101)*80;
+ ?/ p& m T8 \9 d4 Kfillrectangle(x+35,y+110-(int)temp,x+75,y+110);; D- Y- K' |, [& N# q; {, X$ ?* M- L
t = (float)wai;. O) i, W7 T3 B# N3 R
temp=(t/101)*80;4 a! N- n# r; t1 O( l- m! w; g H" T
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);
8 u: H9 d3 L: e/ r& s* O( Ut = (float)cha;$ ?( }& v- K L2 V% M
temp=(t/101)*80;' }3 d" h, e/ Y# g; H+ v
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);3 R8 G# \- h% ^/ l% T& q
for(i=0; i<3; i++) //画坐标 high=90,length=250& X/ R$ }0 H* ^1 H' ]$ P
{
0 C2 g7 d3 ^3 \# C3 O/ Lline(x+100,y+110+100*i,x+350,y+110+100*i);* @+ e! O- ~" y/ V1 f6 ]* R6 ~
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);( k+ ]9 b- `9 J
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
) [9 h+ v, X* m% V
7 |: Z# d* h( o. G2 X) |' S! ]' _0 q. oline(x+100,y+110+100*i,x+100,y+20+100*i);) E& u8 X! x& N, Y
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
) P- v8 J6 C" M/ x |% \; f% Mline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);- J) `+ z1 v* V8 D; F4 H; p5 j
for(j=0;j<num-1;j++)8 C0 s5 n! }/ A; b6 C
{' J0 {% }8 q, X. |" `
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);: f! D; y/ Z8 ]2 N. l9 E
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);+ i' H* ^% Q4 t9 t# C: p; }9 U
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); * h! l* k: s5 x9 V4 ?1 H0 e' V( Z
}
6 i- m4 X, N4 f8 G}
6 k' f# n; y# Z( H% g# F0 |/ ?+ ]}; h O9 R( M, X; f5 U' ?7 S5 \7 S
else if(FLAG_PF==1)
1 u9 w( ~7 _# y! m) A{
! \+ }# q4 F, t6 E Ix=0,y=0;
6 Q; J# _, m0 ~& d& M, J' m7 nfor(i=0; i<num; i++)3 b. d" ?8 K3 G. q% r
{- r/ T( e, [$ c4 P5 P+ u
t = (float)info[0];
; K* ~* T* ]4 j5 e0 n3 A3 etemp = (t/101)*180;
2 n1 f% k) Q0 w( R- v7 }pos[0][0] = (10-num+i)*50+x+650;
% Y4 ~6 c3 N/ N9 n! g6 [pos[0][1] = y+210-(int)temp;
5 _3 s( j' S& o" J* D& m4 r3 j/ Nt = (float)info[1];
/ C6 B2 Z! ~& g( J# [temp = (t/101)*180;( K, q# V+ Z! J0 O" h
pos[1][0] = (10-num+i)*50+x+650;2 J R1 ]( r2 | P
pos[1][1] = y+420-(int)temp;
7 F4 ~( B1 |: i9 ?, dt = (float)info[2];9 h+ p1 D: Q" o+ b$ m
temp = (float)(t/101)*180;6 Z; E7 p. x- r$ a
pos[2][0] = (10-num+i)*50+x+650;
1 F! x" J6 A& }: Ppos[2][1] = y+630-(int)temp;
0 f! q2 J5 I5 P1 V7 t0 U}% F$ D' d1 l5 `, z
clearrectangle(x,y,x+1200,y+650);
8 V! l8 n- M' A# fsettextstyle(40, 20, _T("楷体"));9 @5 _; w i: }8 e) l8 e7 B
outtextxy(x+50,y+50,"PF");, `; A- p4 L/ i, c, n% \( Q
outtextxy(x+280,y+20,"CPU"); //画柱状图
4 O3 v2 [4 M. G8 N/ G2 y' Xouttextxy(x+285,y+20+200,"IO");% h! z- [4 H2 k+ t9 ?
outtextxy(x+250,y+20+400,"change");
7 P8 e0 q, k5 t6 F2 ?, }% H9 p+ _- A: Prectangle(x+270,y+65,x+330,y+215);- G& g5 e6 {+ y2 D- `
rectangle(x+270,y+265,x+330,y+415); z$ Z# d9 b. @& _2 m, c
rectangle(x+270,y+465,x+330,y+615);
: i) P2 @0 s% a W/ k9 h6 u, Z& fouttextxy(x+290,y+620,"TT");2 D( x( W( d P& d8 g: {
t = (float)com;
2 c0 P! ] N9 |; D7 u7 L. p! wtemp=(t/101)*150;3 a% T" {$ Q. v* z9 I4 Y
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
* Y( K( [0 p& M- N. x" lt = (float)wai;
, n* t* f" q7 Ptemp=(t/101)*150;6 ~: ~5 N- s+ \2 n$ a* h
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
: K U/ x: l* O, S4 y; It = (float)cha;, W! z* W, E) j/ T
temp=(t/101)*150;9 Y6 Y9 b; S( j- @" b
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
7 [+ y1 E( i! I9 s- K& dfor(i=0; i<3; i++) //画坐标 high=90,length=250! \6 k& M) c; E5 B. a
{
5 T1 b7 |6 H9 G- H! P$ ?line(x+650,y+210+210*i,x+1150,y+210+210*i);
1 b) D# p2 X0 j9 ^1 Gline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
) v! B* U6 D1 ^6 S0 Pline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
1 s4 u) S7 Q h- `" L& u1 N, x! c6 p5 G, @) b9 m# u0 _) N/ e0 L8 Y
line(x+650,y+210+210*i,x+650,y+20+210*i);, P8 f" y ]5 C, w) _2 q( g6 F
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
: |" a. U- t0 R" x" M% I1 l5 oline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);4 j( P% Z9 b+ ?6 Z
for(j=0;j<num-1;j++)) v& w8 Z6 R0 b4 F
{
% t$ n7 j7 J/ Cline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);4 y1 X, T& r. l' k: z
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);$ Y0 G( H0 i' N2 s- s& e" t
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
% j( R4 R0 f7 P( i) n; }}+ M2 v( i, R9 F3 c3 E1 _
}6 h) i: R: m6 z+ k% O2 C+ i
}9 q8 s4 k' s7 I& w Z
return 0;. i& b- \# K% Y) b
}- r3 ?; s- _, l: u& z4 `
int drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)6 s, B7 O% j3 _- q
{5 b3 U6 f& M# n4 E+ v& S
static int info[11][3],num=0;
( N/ O9 [8 `8 ?% @: iint i=0,j=0,pos[10][3][2];
. w8 k9 Y3 j4 Z+ x Q" S7 lfloat temp,t;% H6 ?# d4 v1 D% m. O" C3 d4 E8 l: Z
info[num][0] = com;9 V. ^7 Z3 o% [
info[num][1] = wai;& d6 E8 t, e! R1 K; x5 e
info[num++][2] = cha;" k0 w3 E9 m8 S+ _$ J$ s2 {
if(num>10) //存储10个点- V1 q# @% k' q" r* ^! K. R
{1 a' i3 j: R* K3 A; t
for(i=0 ;i<10;i++). [5 ]! l: N4 j5 _ D9 v6 R
{5 B: R- r# K: o& J6 L- C
info[0] = info[i+1][0];
, N2 g/ s7 Q6 F9 linfo[1] = info[i+1][1];
( J7 [# I$ x7 d( Winfo[2] = info[i+1][2];
+ ~, H# J4 \* j}% Y/ _: w7 h- x8 t
num--;
2 h' ~! r9 n8 ~, G* ?8 U3 R}
5 c9 X: b% B4 I5 Kif(FLAG_show==0)# s2 @/ r, C/ _+ e$ `( S
return 0;
4 x, y! G- T0 ofor(i=0; i<num; i++)) p- e3 J& V# o2 P. S% @! m* @
{' y! q0 z$ L. F7 I$ w: Y D
t = (float)info[0];- I& F, p4 K0 R: V! @! h5 t* i' V
temp = (t/101)*90;+ u9 t3 U3 \8 H7 R: `' w
pos[0][0] = (10-num+i)*25+x+100;
# ~. Y0 @; N0 ~* upos[0][1] = y+110-(int)temp;
B5 O& J9 S& H: J9 W `) rt = (float)info[1];' S. w( F: F% y" I; o4 H3 i
temp = (t/101)*90;2 N/ c" P# [; f. n
pos[1][0] = (10-num+i)*25+x+100;
8 q5 Q; \1 S2 v) H( \pos[1][1] = y+210-(int)temp;
5 F- w, j F5 d$ n4 `* Zt = (float)info[2];
- o1 `. a( }9 S* H0 k0 ]temp = (float)(t/101)*90;* D. ?7 U* R* v+ W8 _. J
pos[2][0] = (10-num+i)*25+x+100;. e E0 n( ?& R+ N( p I& _ ^
pos[2][1] = y+310-(int)temp;8 Q- k( ? e! e( ~4 V
}6 @. g9 |8 E$ J& W3 H$ R: W: @
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
+ ^5 S* g+ n! u7 Y8 w+ F! k{ ! o0 M, G! ^& L8 [
clearrectangle(x,y,x+400,y+315);6 M% [3 X. F _1 U7 J
settextstyle(20, 10, _T("楷体"));
8 ]9 s; V1 Z+ ^( S1 o* i% Urectangle(x,y,x+400,y+325);
0 d% d$ Y$ Q& zouttextxy(x+40,y+10,"CPU"); //画柱状图$ J$ V: T" Z) I6 C' d
outtextxy(x+45,y+10+100,"IO");
- b5 e. X6 F- X( Nouttextxy(x+40-15,y+10+200,"change");
! ]* w7 Z9 n& [1 Erectangle(x+35,y+30,x+75,y+110);
9 ^7 Z6 t, m9 a% B' ?* Wrectangle(x+35,y+130,x+75,y+210);. H- o5 U# ^& b4 Y$ J0 T
rectangle(x+35,y+230,x+75,y+310);/ s5 ~; J* k1 }# f/ c% E& T
outtextxy(x+180,y+310,"SJF");1 W9 Z4 E* G2 S( ^4 B3 s
t = (float)com;
6 [. X1 i4 P4 m; K htemp=(t/101)*80;2 z2 w4 m$ ]2 w' j; `) }
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);7 H( L: i+ a6 [" @9 T
t = (float)wai;% c! n9 y6 z0 r- N( Q: k* b; `, v
temp=(t/101)*80;1 N s$ c- c* T1 o7 m3 x) m
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);$ l M; _! L7 O' I, H6 T
t = (float)cha;
% z) e& h' J* l. e$ p9 a8 Mtemp=(t/101)*80;# w* \( h: o; X+ D
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);# \# [+ e0 w* I, R
for(i=0; i<3; i++) //画坐标 high=90,length=250
]) b" |3 |+ v3 g1 r{
) ?6 o( f3 g gline(x+100,y+110+100*i,x+350,y+110+100*i);
+ L' e8 N2 o, E8 s2 i% O {line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);2 w' Q, i. ]$ a9 U) g- v
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
7 ?$ |$ X. \; B- Z* L3 _1 y _- F& Y- K3 K& q Q2 a
line(x+100,y+110+100*i,x+100,y+20+100*i);% m* X- R5 [' }7 v' g- j. Q
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);( ?, _1 f% _& R0 F$ ?1 ]
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
$ f1 [+ D( C8 u7 X# O, Ifor(j=0;j<num-1;j++)" p, w: N n$ |) M8 }: u/ N/ e. `
{
# o- O0 n+ a9 {. ^% F" E) Cline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
! F1 N. }/ D6 Zline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
, i# k" A' _( X) _2 W* b# x' jline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); + z; s' x# q( R7 N3 E f, ]2 E
}
# j# r o/ [ z% y}5 G% }9 h: m5 k6 w7 y
}
) t1 f' Y2 @9 V' x x o8 Yelse if(FLAG_SJF==1)/ `; n1 |' N: H2 {* e0 y
{) `" r. u1 k$ W1 D+ r
x=0,y=0;4 }5 i8 ^$ d1 B7 r4 g
for(i=0; i<num; i++)
7 E! \6 G6 T5 K: C* ]" N3 i9 C! x{
' C, u: j* U( ^5 Xt = (float)info[0];
5 b# W4 ~7 j7 J2 ~temp = (t/101)*180;/ H% n+ i3 v7 Z8 e, H
pos[0][0] = (10-num+i)*50+x+650;/ \ {4 Z4 ^ f. F' C
pos[0][1] = y+210-(int)temp;
' c: J+ I2 F7 `$ l9 @# H: S: w& wt = (float)info[1];. |+ [( k* H0 [
temp = (t/101)*180;
0 j9 `9 ]- Q3 s$ l! |, epos[1][0] = (10-num+i)*50+x+650;
/ {( \9 p8 @/ r' Ipos[1][1] = y+420-(int)temp;
# I' }, M4 S+ ?) A7 \5 L3 D$ a& F3 Zt = (float)info[2];6 h6 {% L: A: f1 f) V* \/ N. t
temp = (float)(t/101)*180;" s5 Y, h2 ?5 j, Y( z- B$ I8 p% ^
pos[2][0] = (10-num+i)*50+x+650;; K4 T b$ u% N# W
pos[2][1] = y+630-(int)temp;2 j' C6 B6 M& t. ^, Y
}
5 |8 j' M; Q8 Z6 X, u1 zclearrectangle(x,y,x+1200,y+650);
# o6 p1 i+ Q. @) p" usettextstyle(40, 20, _T("楷体"));
+ W1 F! H% g, k- F: c Fouttextxy(x+50,y+50,"SJF");5 S/ ~9 Z2 B7 l1 {8 V) V9 j$ P# A
outtextxy(x+280,y+20,"CPU"); //画柱状图
6 P& G2 ^4 w6 Q3 }+ Zouttextxy(x+285,y+20+200,"IO");* Z9 D2 K6 a K/ j
outtextxy(x+250,y+20+400,"change");' q2 w! |) i0 [. c4 Q& E7 h+ U9 g
rectangle(x+270,y+65,x+330,y+215);
4 F& {8 Z* w0 m3 urectangle(x+270,y+265,x+330,y+415);$ L+ ?0 w7 V" ]9 \$ ^1 y& g( C9 d
rectangle(x+270,y+465,x+330,y+615);
* e2 \! Y1 x- l1 ^+ x. Pouttextxy(x+290,y+620,"TT");1 a" x J0 w+ ?# S0 w: Y
t = (float)com;, {, X$ o6 R- C* {3 K
temp=(t/101)*150;# Q7 ], K \/ T$ W
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
' l0 c. }% L0 {: E& qt = (float)wai;3 A$ z) j6 O1 O* p
temp=(t/101)*150;$ {4 d& |: @% K7 \% Z5 G
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);5 [1 i# _- M& z+ U& Q
t = (float)cha;( X! p* L" o. e1 B. r8 Y
temp=(t/101)*150;
& g& c: X: x- }: V6 afillrectangle(x+270,y+615-(int)temp,x+330,y+615);0 R, Y, | `) O+ c
for(i=0; i<3; i++) //画坐标 high=90,length=250/ H; M% c% z" ^8 ]( Y" N3 Z
{
$ Q+ g7 b# {4 t9 k3 |line(x+650,y+210+210*i,x+1150,y+210+210*i);& Y: p7 W& C; c* S: p
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);+ n8 z/ i3 f* Q
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);' s. `& N9 S' V4 c
* G7 i3 a( b3 K) }% @. q& k" R% _
line(x+650,y+210+210*i,x+650,y+20+210*i);
9 S1 B' Y( O' Q( D# q5 Wline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);6 `7 E. i" \# J+ V4 m; S% X7 K: e
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);1 b2 D1 _6 [; e! G! h
for(j=0;j<num-1;j++)2 O9 n5 Y% X# }: `+ X
{1 } ]. m0 |/ E2 @ h5 r9 [$ U
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);$ S6 A: `. {5 ^5 h" q
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
- X6 O2 v( q$ Q( d; vline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
% U" v3 g* j3 S% c/ I2 ~* Q}8 f0 G' \' C, s& S' c
}
7 _3 C( c. a5 [7 v3 ?3 \}
. R. `, M7 }! M3 Z% G Vreturn 0;) C) `. W, S) M# G7 L
}( z1 j7 U/ i8 X( T6 D3 T
int High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)- X3 Z, t' `3 T( e' f% y
{0 Q: l- C( j4 x. p2 L
static int compute=0,waitio=0,change=0;
' f& G" Q6 H+ s0 n4 I h; [8 D1 astatic int computeLast=0,waitioLast=0,changeLast=0;
! G; Z$ ?: e" }* K) _- b2 e5 zint i=0;) O3 ~, M+ E+ p! Z
if(draw==1)1 Y5 X% e7 j8 E3 ]( \
{
& b2 Y" |' z* a# H% O//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
# H# r: j3 a3 ~! {' H" }* zdrawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);$ X: F" R; `+ g5 c( V' j
computeLast=compute;9 a- B. w9 ? C# _1 P, \0 m
waitioLast=waitio;
' L' ]" e) f0 ~& `( g; achangeLast=change;
$ I9 T: }6 n P' w. X5 K8 G8 \}0 R1 h4 J9 |! M3 N) k" N2 T) u
if((* memory).p[0].flag==ready)0 A- L' k# N( Z \8 s3 u8 a
(* memory).p[0].flag=computing;
8 @: ~: c0 h* P% |/ B1 Qif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)4 `; e7 D$ J( p+ x+ J
{
! H ?8 R' {8 q* j/ X; R0 ]( W5 ei=(*memory).p[0].computeNum;
' Y ^! Z1 `" F5 j: _7 Oif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed: P) G \ R$ w1 _' ~0 s
{
, y% L7 X- A# v1 P7 j" v(*memory).p[0].flag=IO_waiting;
6 E# K! E" E' Y7 a3 e( ]4 k% w, o(*memory).p[0].computeNum--;$ L# i0 r0 f* X: U6 l/ i
change += exchange_IO_Compute;& W- A$ Z5 _3 X
compute++;" W" J/ w6 @3 u" W; K$ H5 N
}
3 T0 L3 `0 x& X1 selse
9 U$ b+ z1 N9 @$ a3 w. Q2 l{
3 v7 z+ s5 N( J( l: Q9 {' hcompute++;
% A9 A! |4 k; Z9 V}' m6 {- R/ J: d0 j: d
}! k3 x9 G4 }( H, G3 y
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
, e4 y5 G4 M8 j, b2 Y1 J% w, n8 |{
. Z" B& U+ Z% o/ ?3 ?2 V8 s) h9 q. _; m
i=(*memory).p[0].ioNum;
% E7 O1 L7 Y9 {# q$ o) K" b! }& `if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed5 U. b r2 g# m. W
{
1 I+ P: X/ C* M(*memory).p[0].flag=computing;
! O+ h2 G' ^5 U(*memory).p[0].ioNum--;
0 \! Y5 n7 O W1 i8 echange += exchange_IO_Compute;' _7 p3 Z4 {* ]2 {
waitio++;
b. x% h; C8 u. g& b2 ^4 N/ j}' o& ~3 o) C- w! T
else
- t& o5 L6 h+ f8 F, d3 `- ?{
3 N1 [8 r" F: W/ r7 n. dwaitio++;+ ?# |; `) \/ [5 S
}
; w3 H5 ?0 |4 W! x}
! ]: I4 z( j: T2 \ C: pelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
' [6 y3 J+ M/ [& s% o{. E) |9 G3 \: `
(* memory).p[0].flag=IO_waiting;1 k ~) O5 E% O9 u/ i2 C
change += exchange_IO_Compute;
i. t, i, B) _; N3 V. X& n& p5 t}* M3 n# Z% V8 b4 f9 t2 j6 A( R- M1 E
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)8 z* @: j: W" _! t( P) C
{; b2 X+ W8 U- y$ `; V; z) @
(* memory).p[0].flag=computing;$ q( w6 e. c4 q3 i
change += exchange_IO_Compute;, \* n3 F2 ^+ Y7 d
}
6 v* ?0 d# l% T% r/ t: \if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
, X" u8 X$ w+ x9 O4 S- n{
5 m _# {, m4 m4 u/ q6 c0 `1 z(*save) = (PCI*)malloc(sizeof(PCI));
0 Z. ^- q7 w+ X H(*save)->next = NULL;9 D( T N% k; D) r- f" X B
(*save)->processID = (*memory).p[0].processID;+ [) V6 {* b' ] M% Q
(*save)->comeingTime = (*memory).p[0].produceTime;- M5 P" }/ L, A% l
(*save)->askMemory = (*memory).p[0].askMemory;
4 j0 i, r2 T+ n5 Y! k$ a$ V5 N(*save)->compute = compute;
8 ^1 ^" N7 J" {2 t% G(*save)->waitio = waitio;
- k d# Q A" Q! i(*save)->exchange = change;+ Z( O% C4 @+ b m8 V, W8 ?2 N5 f
(*save)->completedTime = systemClock; U; ]& I# o% w) p" t
(*save)->runningTime = (*memory).p[0].runningTime;
/ f3 W/ G; ?% t7 k*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;
# q6 E0 M& I/ z% B% f+ ?compute=waitio=change=0;
3 V) u& D% M6 c3 acomputeLast=waitioLast=changeLast=0;5 d3 v# Z" O# n( s6 P# R. m1 f) h
High_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);, W6 Z+ P( I& J$ [( ~4 C$ K
change += exchange_process;
( d# p8 u) g; Yreturn task_completed;
* G' A! o) ]0 p' O$ h2 l}' r5 X5 N A# o/ g% h8 ~" m, z Y
else" Z& A" K# P% W+ o7 a: }
return task_not_completed;$ n6 o) T& P& x% Q/ P+ ~- d
}" `& K# F- z! D& F5 X6 j3 ~
int High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)
" b7 a$ F) g' a+ S2 E{, E: F+ C1 J( {9 ^5 `
static int waitTime[initProcessNum],i=0,j=0;
+ `* @1 ^, ]9 Sstatic double HR_ratio[initProcessNum];4 U7 }- E% [$ ?6 |$ Z
if(flag==0) //初始化数组7 R, s0 s- B/ W& t6 p% B0 {
{
( x$ }, I! s1 p9 r ^1 e' dfor(i=0; i<initProcessNum; i++)
6 r. M; M* F" K{+ w( i. y6 c& R& R1 t
waitTime=0;) Q: R7 \$ Z3 i! a& j# e
HR_ratio=1;
+ P+ R9 S& M t: `# J: i o}
$ [+ O' i' L' G5 U Y}! F. c* Y! x5 k |1 ?
for(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比3 G; G4 B7 w+ |
{
5 j( U, b- o6 h6 ]waitTime++;
9 W" k( K$ z( T( }HR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);
" N" R t! T- Qif(HR_ratio > HR_ratio[j])- p, \0 L; Z* b1 ^4 ^
j = i;
. V( {5 `+ S5 y+ ~! D. b1 T f( g |}5 f' a! v( F- z; J! J3 I, O
if(dispatch==1) //需要调度一个进程到内存中执行; o' R8 ]% g% O( b- X& q
{
- x9 k# b6 T0 |% g* d3 ~6 F7 t& vif((*storage).p[j].askMemory < *spareMemory)* @9 A7 G$ U/ R. ?4 G% U8 \0 d
{9 e# S5 ?6 | u2 g6 y
(*memory).p[0].askMemory = (*storage).p[j].askMemory;
+ \+ y) c* u) Z(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
- B/ Y/ ^. k, }, M5 u) i0 n: v(*memory).p[0].computeNum = (*storage).p[j].computeNum;2 U/ \8 O- W6 v$ V$ ^& d
(*memory).p[0].ioNum = (*storage).p[j].ioNum;
2 ]; B" E$ }) \$ `, W9 J(*memory).p[0].processID = (*storage).p[j].processID;
0 D/ C: ]& l5 A2 a(*memory).p[0].flag = (*storage).p[j].flag;8 T$ R0 n* K. G2 a
(*memory).p[0].ioTime = (*storage).p[j].ioTime;* z1 W3 X% h, ?- i0 i0 t# L: ?8 V
(*memory).p[0].computeTime = (*storage).p[j].computeTime;6 N- w: W1 t, s8 z7 i) w$ t" C3 _
(*memory).p[0].runningTime = systemClock;& z& ~0 t5 q4 R9 v5 H& m" i
(*memory).p[0].produceTime = (*storage).p[j].produceTime;
3 `5 Q/ I- n- i& b& lfor(i=0; i<(*memory).p[0].ioNum; i++)
8 N8 Z1 C- ~ V+ u/ b. O(*memory).p[0].ioClock = (*storage).p[j].ioClock;
5 ?$ Y2 F+ @* H, @: f' yfor(i=0; i<(*memory).p[0].computeNum; i++)! t: h" x% V+ O) Q
(*memory).p[0].computeClock = (*storage).p[j].computeClock;
# l; X8 r, W) h6 X# p1 q0 Q4 b(*memory).proNum=1;
* J! l( U' G w! Y: b- c8 \1 M*spareMemory = *spareMemory - (*memory).p[j].askMemory;
9 \. U! X! O* V6 g! eproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
9 q o' f, v( _: I* B(*storage).p[j].produceTime = systemClock;, R! z2 Q/ O% ^# b! ~9 b
MAX_COMING_TIME = (*storage).p[j].comeingTime;1 V b( x: ^% t8 c
waitTime[j] = 0;
p! v/ X9 b1 f$ \6 d0 w# KHR_ratio[j] = 1;! A4 G4 B. C( v. i. N$ ]% M, \8 B( @
}; X0 A* ?# f* m v, F0 k- {& e! E
else
& I6 g/ g1 {! B8 F. z) k! n{+ B6 B1 W. k* x1 ~; ~
printf("A process ask for a memory overed the system capacity\n ");: M* E. i, _+ `5 E
exit(1);
! w% W( y0 o% D8 A7 U}% o0 D' X8 {! X5 _+ k/ I
}! R z$ C* d" ^
return 0;
$ T% H( g& J3 |( v8 J}
& A$ Q0 ]0 u, i2 Dint PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
$ Y, y# S7 K" [( u{9 K3 A0 X; Z0 H0 J
static int compute=0,waitio=0,change=0;, H: o3 f4 \* B
static int computeLast=0,waitioLast=0,changeLast=0;
. s3 V' U/ \6 N$ M3 V: Sint i=0;
7 `7 `) S4 o6 l# U3 ~if(draw==1)
2 C/ u7 R! Q( \3 x5 Z{
* Z) l { P0 ~/ t5 [! @! z5 H- g1 \//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
( h5 @5 A9 e) c1 _4 adrawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);) c& p9 e0 L, g9 Z
) Y' r% _ B' c' X$ }% y, |
; I: M: X) m# ]" o
computeLast=compute;
4 B/ B( l/ f: K3 cwaitioLast=waitio;2 @3 ]5 J+ ]; O* {# g( Q d) O2 U
changeLast=change;; z( |) h+ d- s9 d" f
}
8 r/ J9 E& F& z" R( Tif((* memory).p[0].flag==ready). D& S7 D( t1 ?+ ~% M
(* memory).p[0].flag=computing;
; f$ d. R* g. m8 Jif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
}7 y! A; {+ e# H2 P; K2 n4 W{
- ~$ `" H- u: Z' Q/ zi=(*memory).p[0].computeNum;6 t+ _- D5 B& p$ i9 R% X) R" M* D" w
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed- \8 s F! a5 r8 n; J& Y5 R* J
{
. X" \: C; S* o e8 O# A(*memory).p[0].flag=IO_waiting;
! Y6 j: x; C& q: d/ A(*memory).p[0].computeNum--;
; D! H7 i2 @5 w, Schange += exchange_IO_Compute;1 Z2 ?9 a( m* O
compute++;. H# u8 z+ N! {: @
}+ i( K# P" x' v( ~
else' k2 F3 [& b. w
{- o6 d! X7 F: Y. S8 L
compute++;# z0 i6 e& r5 l& I! T
}
0 c% C6 z5 X# F5 x2 Y8 G) Q. Q+ n}
( o0 c; A) ?# oelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
" J2 m) V- c1 X( H{
2 R) s6 _/ q) a. I( y o+ V- x3 j; [4 a3 m& \, M# \
i=(*memory).p[0].ioNum;7 N5 z$ s( e: L/ o' T
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
. J0 d! G, p E3 U; N) \. A8 G* d{* ~. k3 x7 p5 Y! P
(*memory).p[0].flag=computing;
2 Q$ ^$ Z- ? q5 M(*memory).p[0].ioNum--;% n4 P; j: Y1 ]' Y' i
change += exchange_IO_Compute;
3 X, k6 M4 e& Q7 Y8 a7 H+ h. ^waitio++;& f7 k. b. M+ j+ o+ O7 d8 G; H
}, x* W5 F: i0 J
else
( J( s4 K( Q1 [{
8 z7 I" \/ N( N" v9 W5 Z* A) ]8 e0 _- A% owaitio++;" Q4 Y' \1 C1 F9 t, q
}+ U0 z, g& V% W
}5 ^$ u- y- X0 E
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)% l A8 [- L1 U4 U
{; u( J3 N' l/ T \
(* memory).p[0].flag=IO_waiting;, i' E* _: P3 n+ R. U
change += exchange_IO_Compute;; j( [$ a& l+ Z8 s
}
5 g* f+ q" y7 g" ^* ]; D, _else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)( _1 o7 Z! K* F4 u6 W' E
{
1 v* I0 y& c7 S5 `* L- l8 T8 E, G(* memory).p[0].flag=computing;
7 g5 D) S E6 `% M4 M# Rchange += exchange_IO_Compute;9 O7 U3 B* ?0 z3 M* X ?; S
}8 V2 n. d% N+ u+ C/ S6 Y
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成7 z' y. b1 X$ O: B/ P0 v: ~- u
{
6 _2 @0 I- I/ I2 L- z) a6 ^3 D(*save) = (PCI*)malloc(sizeof(PCI));
' X1 M3 Q8 O1 A4 N& G(*save)->next = NULL;
* P. e6 t6 e9 g- _" }- X/ ]8 B2 Q(*save)->processID = (*memory).p[0].processID;
# K4 c- z) `0 ]6 ~$ ~(*save)->comeingTime = (*memory).p[0].produceTime;* |/ [5 P- s3 ^5 O8 v1 \- [
(*save)->askMemory = (*memory).p[0].askMemory;
* h( @7 N) L% t+ _(*save)->compute = compute;( N* \( B0 d4 |8 f
(*save)->waitio = waitio;$ O" u& Q1 y1 o0 s% n" u9 J+ |
(*save)->exchange = change;
* T* z' K0 l4 B7 \6 A2 Z$ a% Z9 i4 b(*save)->completedTime = systemClock;
/ j5 g+ P$ t7 H- L2 K+ T/ E(*save)->runningTime = (*memory).p[0].runningTime;$ R7 o8 ^# K( p- j! d9 @; U v6 y
*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;# z5 _1 B7 I! F. A4 G
compute=waitio=change=0;
& m) _. F- D( @computeLast=waitioLast=changeLast=0;. w) q( s3 g; ]8 E! U
Priority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
! p+ n. i- `$ ?8 k; ~2 Gchange += exchange_process;
/ c+ c x) _9 g: \8 o4 ireturn task_completed;
0 H3 X7 W: d5 J+ i3 G* Z# s3 O}
, v- d3 v l! R' ]& b+ W6 u0 `3 Melse* h+ {3 C% U0 I7 t" f$ Z
return task_not_completed;
, m! ^7 F5 u2 t b0 h& |3 k: L! I}
2 B; ~3 V: K y% ]6 Wint Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory). N# P H! g8 u1 u$ O5 V9 l
{% T( J: {: Y4 ]8 N. \1 \: g3 |$ z/ Z
int priorityNum[initProcessNum],i=0,j=0;7 g- l8 m2 O% B$ M2 N: U
double temp=0;8 i" A; d! a) y! c
for(i=0; i<(*storage).proNum; i++) // setting priority to each process2 e+ A6 a" S; Y! p- D
{
3 D4 b( F k3 M/ e7 @( Utemp = (*storage).p.computeTime/(*storage).p.ioTime;
0 {9 f! p3 x% k5 B3 L6 g( [* ?if(temp > 0.8)
( l6 l: N& Z+ E/ b2 }5 [priorityNum = 6;3 s5 W: i# `# Q5 D
else if(temp > 0.7)0 O+ y) Y' a) [& [( v
priorityNum = 5;
% R) j N. [' ?9 f2 m/ Y8 qelse if(temp > 0.6): v/ W! s2 Y0 o6 ]( {9 e, o
priorityNum = 4;
+ D+ u+ D5 e3 m: L1 ^else if(temp > 0.5)
; ~) x: W5 b" T+ R# B; _) GpriorityNum = 3;6 I6 g. d& w$ `( s
else if(temp > 0.4)7 b$ P" E+ ]/ m6 |% [+ b. |
priorityNum = 2;
" h- e/ u) F5 G0 i+ lelse5 ]9 A# p2 z: {1 d. _
priorityNum = 1;
0 ~+ b( ^4 A8 A9 S2 d& H1 zif(priorityNum[j] < priorityNum)* P3 {# l1 F& ?
j = i;
% @' w7 m7 B; j' W! |1 Z: a}0 L, {- \& {$ M+ ~
if((*storage).p[j].askMemory < *spareMemory)
: C, L+ E9 X$ O# e{
8 |4 }) J$ x# A+ E# c, K(*memory).p[0].askMemory = (*storage).p[j].askMemory;& Q) T5 T% x' i! }3 Y: R) F0 h6 L" Y
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;1 i8 @ c/ A. Q3 o! V
(*memory).p[0].computeNum = (*storage).p[j].computeNum;: B- W3 [/ V3 N5 g' `$ ~0 W
(*memory).p[0].ioNum = (*storage).p[j].ioNum;
$ o, z3 D% F0 M4 y1 H8 H(*memory).p[0].processID = (*storage).p[j].processID;
R- A( k) @# q1 a(*memory).p[0].flag = (*storage).p[j].flag;
! e& A4 H% x- k6 Y& J(*memory).p[0].ioTime = (*storage).p[j].ioTime;$ |2 q+ G% w5 P' o) q
(*memory).p[0].computeTime = (*storage).p[j].computeTime;
8 N: R6 o9 ?6 r' U a0 t(*memory).p[0].runningTime = systemClock;( _& W8 L: W6 W/ s
(*memory).p[0].produceTime = (*storage).p[j].produceTime;
8 @$ M6 k0 |" x+ E' \ R* Gfor(i=0; i<(*memory).p[0].ioNum; i++)
2 J Q- H. z2 t% c) _(*memory).p[0].ioClock = (*storage).p[j].ioClock; N& |0 A4 k' I$ ]2 k
for(i=0; i<(*memory).p[0].computeNum; i++)
9 w4 E- f* e _' ~(*memory).p[0].computeClock = (*storage).p[j].computeClock;
& ~9 T! v Y9 S ?6 Y- k(*memory).proNum=1;
& @3 A) [# a7 I: R3 b1 S- t*spareMemory = *spareMemory - (*memory).p[j].askMemory;
9 O, g/ U7 R' Nproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
; u' A1 Y+ y4 B" XMAX_COMING_TIME = (*storage).p[j].comeingTime;% D. f m+ V2 ~4 P! ~0 o, G
}
* B2 a E: a7 F% \4 Belse
7 K6 J* \+ c! Z/ D' B; e; Z0 z{6 b# t$ J, M! P+ B+ G) ^* U0 `9 z5 Q
printf("A process ask for a memory overed the system capacity\n ");
: f" u- |: @, g) G; U: hexit(1);& ?: C" n% s& J' g1 I8 P$ d
}
& d/ n; l+ \( P8 breturn 0;. N) u1 ?: w- }( h
}
; q5 F, R3 Y: C( u' w* y6 s& cint ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)4 s& h; @1 q0 r" U2 p+ X4 U
{" D- N( l8 E6 A' b% c5 t
static int compute=0,waitio=0,change=0;
* t3 e" H! \9 E2 ?static int computeLast=0,waitioLast=0,changeLast=0;
: T7 X% C# S* f$ _4 c- x$ @int i=0;- U D3 }3 g! J3 A/ Z
if(draw==1)
! H9 p3 Q- E2 w1 e{
. E) L& H6 `4 x8 a- y; X//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
( U5 z1 h6 ?2 X( TdrawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
, x$ Q& A8 T: u+ b) m! v* y9 ], s) N; Y4 X
5 j) ^1 v( K1 O3 b6 a
computeLast=compute;" D4 c! [ F: N0 |- O$ r4 k9 D
waitioLast=waitio;) g ^2 d& x2 Y0 b
changeLast=change;
5 K- C1 i* h3 h}* Z+ S" s t6 \ M) ?8 [
if((* memory).p[0].flag==ready). |, X& R. c" v- \, G( l
(* memory).p[0].flag=computing;
( W! n. W B: |+ vif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
7 i0 e( D M3 x2 K: w6 s$ t. @* M{- A$ B; i- N' t$ f R6 y' |7 n
i=(*memory).p[0].computeNum;8 G$ |, }) T5 v& W) y/ _
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
# ^' @1 \" {( z{3 r* r- i; q# V( v( c) m
(*memory).p[0].flag=IO_waiting; R, G, v1 N. { J0 C# V8 l0 V+ U
(*memory).p[0].computeNum--;" T7 R: P* G8 a
change += exchange_IO_Compute;
7 _1 u; |# F4 @, |/ ~compute++;3 h, z5 ^1 y8 U6 t( K! }6 ^! r
}# P5 v, S3 \: v% ?& y: d" e3 D
else0 c. B! ^$ g$ ^5 V$ z. s3 ~
{
" T. T D: w" V- r/ Ycompute++;
/ w' x* M" S1 P1 M& [}
& A, M- o+ H& u& M6 b! y4 K3 ]}
7 x3 G9 a2 z4 x' q* z. delse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)) D& h' P- p7 k* C4 Q
{# z# a4 l6 {- e) [: G
( j4 C# O6 [! W) c4 E2 t3 Ri=(*memory).p[0].ioNum;
; O0 m9 d: l" R: ?0 O% xif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
5 J, j% J+ l7 {, c) b{) r( v" l% w+ k' D" b8 `' D. q
(*memory).p[0].flag=computing;* m1 a+ F# X4 J& p7 y! e
(*memory).p[0].ioNum--;; `- u0 M/ J+ r* q$ K- ^
change += exchange_IO_Compute;
! r0 v9 N+ s" `/ [( Iwaitio++;* K; w4 z+ ^; `5 M6 T6 Z
}) p" t3 j# [, B2 ~. M8 M: w
else/ N' G% q9 g6 t: [# O N
{
. C, [6 l7 |# C n1 H& J9 n$ Rwaitio++;
4 P. Y$ u$ a) P, Z6 `}
2 |' E1 U6 P8 F9 [. H0 z}
8 a8 l0 w- J, s" O( M- Nelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)' E& p& }$ k+ K( h) E
{
- c- R5 I0 f, g$ Q, s# z' y* @(* memory).p[0].flag=IO_waiting;
o+ t$ k, u$ }change += exchange_IO_Compute;. K% v7 S( B! V4 [) o& z
}
( h0 E3 _5 h& Kelse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
6 K1 a6 I! J% S3 I' I3 M{' Q) d$ e0 K5 \1 s4 ^. B( @* B
(* memory).p[0].flag=computing;
( o4 E! Y7 k4 o5 Pchange += exchange_IO_Compute;& U( n, R8 t6 k. @# k
}
1 p; |& m* o$ ^/ Pif((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成( h5 m6 Z% g1 \, w$ C* p9 `
{ H* E( V/ d6 s# L' d+ c A; a
(*save) = (PCI*)malloc(sizeof(PCI));5 V7 O* a @* }, _1 B
(*save)->next = NULL;+ V' o8 D: ]5 J7 k8 N5 }
(*save)->processID = (*memory).p[0].processID;. B; C2 W" `* m( n# A' Z
(*save)->comeingTime = (*memory).p[0].produceTime;$ d! w( y0 Q" }9 F, y2 @
(*save)->askMemory = (*memory).p[0].askMemory;
1 A3 Q( I! T; ~* }(*save)->compute = compute;
: l8 [' L( k# J0 f9 k(*save)->waitio = waitio;) M0 b/ A. V5 I7 D) X! ?
(*save)->exchange = change;
, m% k% A* @6 a* V: \(*save)->completedTime = systemClock;- f: N L& g, @2 Z
(*save)->runningTime = (*memory).p[0].runningTime;
* R, a* g; h$ `. [! W, L*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;3 `+ X7 I3 @2 l/ ]
compute=waitio=change=0;5 ^ v/ w9 n [- q: R
computeLast=waitioLast=changeLast=0;+ t5 y0 A( {) j* R1 X
SJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
1 b5 G. W$ r; n% N8 i2 ?- Bchange += exchange_process;
9 }2 ]( V0 s d) O5 E2 _return task_completed;
, `5 }" C% X# z6 i2 r}2 @" Q7 g& ^) v- Q4 F/ c' v8 v3 S
else4 }) c2 C7 D$ _% t' Y8 \* R
return task_not_completed;
2 z* M. r2 {! S- _4 z! o0 }( U}
$ e j6 a+ A7 Kint SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
% }8 G/ N, o6 w% a$ d{5 T, |3 B0 H0 P/ e# P- P
int i=0,j=0;4 a0 V, _: B9 S7 V+ j+ A+ r1 Z
for(i=1; i<(*storage).proNum; i++)- u. m3 O8 t, b" U; }8 z- I
{0 R. {# @/ X$ B! X
if(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))" m, ]/ o& I/ v& [/ [: w
j=i;
5 p& T! E! V$ ^- Z; _, P; E! j}+ m' m5 c3 a& P2 x* y
if((*storage).p[j].askMemory > *spareMemory)8 E+ W3 n0 `; m0 u
{
" c7 j. Y: U9 _. A) b0 t/ P" w5 Vprintf("The memory asked is overflowed than the system memory.\n");
; ~' U. b" K- ]7 i; _& dexit(0);
3 q0 U* T G$ q$ ]" T$ U}" S! X* G9 K4 m A. B& l
else
; I I& O, V" e; x, |; M5 T$ B{
& ]8 t- h @ v: f9 C0 i9 w(*memory).p[0].askMemory = (*storage).p[j].askMemory;7 A8 W, p: ]# s: W2 M+ A
(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
# c$ k) H6 O7 [(*memory).p[0].computeNum = (*storage).p[j].computeNum;/ X* y* {+ T. m
(*memory).p[0].ioNum = (*storage).p[j].ioNum;
2 Q; i4 e: s5 y" X: h1 S) O$ I9 w(*memory).p[0].processID = (*storage).p[j].processID;" J5 V# ~, w( F
(*memory).p[0].flag = (*storage).p[j].flag;/ l5 ?( A1 y* z4 K. o4 ]9 _
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
! \2 H7 {. n/ k& f) O3 T(*memory).p[0].computeTime = (*storage).p[j].computeTime;
2 b7 _$ j" S: e( l" ~4 |- K+ ](*memory).p[0].runningTime = systemClock;
7 u) v- x( b* r% }( E5 T' g5 |+ V(*memory).p[0].produceTime = (*storage).p[j].produceTime;; Q) ~, ^5 G ^9 n9 T
for(i=0; i<(*memory).p[0].ioNum; i++)
; p! r* \6 w! T4 _(*memory).p[0].ioClock = (*storage).p[j].ioClock;
$ j+ P6 J2 l, e8 ]for(i=0; i<(*memory).p[0].computeNum; i++)9 @$ T/ [8 y1 q2 {: ]/ e6 d! v& A3 A
(*memory).p[0].computeClock = (*storage).p[j].computeClock;% D" L3 E7 I1 [0 q
(*memory).proNum=1;, a, z6 i% J$ h) S" V( P& e( N
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
; g& _8 `5 V" p9 R5 ]2 dproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
+ `: j/ }2 v: y* d3 n1 AMAX_COMING_TIME = (*storage).p[j].comeingTime;' [1 ^3 h' a$ t* E& X
}
2 M" c- }* Q( [7 D F, ]6 _return 0;, P A& W, k- J% U, J8 }
}7 s! [) J+ d9 }. O# x
int TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
2 [. Q7 e* E3 J{. G+ i$ W C8 [/ O: t0 y z+ f
static int compute=0,waitio=0,change=0,clockSegment=100,poi=0;7 f3 v& Z( ]7 `/ r
static int computeLast=0,waitioLast=0,changeLast=0;
) U; U( [! L) Y. i0 |% eint i=0,j=0,k=0;+ Z% w* J$ ?. ?# I4 }1 ]' `
if((*memory).proNum<=0)
R) e8 V8 f0 W/ h: RTimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);
" J- D3 y) d7 L( N* _9 uif(draw==1)& h6 h* F I4 ?; z
{" n" s, ? C+ Q2 j9 ?
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
3 L; ]: y2 r; {% u$ HdrawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);3 P' \: u4 J; l8 r
- o8 U3 V9 _ ?# m
/ e& W1 K" R# a, C5 b: s0 O
computeLast=compute;2 D E$ h5 w9 Z y2 C# a
waitioLast=waitio;# D \7 _; Y ]7 V! r$ J' A
changeLast=change;
7 O3 a; C- ?. a- W3 M3 o/ e}
+ \ ^9 t# ]! o/ `' a/ uif(poi>=(* memory).proNum)
. s! M1 d( W8 a! F3 Ipoi = 0;
# B! D& G0 ?/ h6 R5 ]' Iif((* memory).p[poi].flag==ready)
& C4 a: K9 @' i: H+ H(* memory).p[poi].flag=computing;5 U5 \& G1 K. O0 v
if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)0 z* m" Y' I: ?" @+ d4 L7 ?) |/ T
{! r9 s- J8 Q. q& f" B- J1 v
i=(*memory).p[poi].computeNum;
3 T1 @" U+ R' u& F! P/ Bif(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed7 X' _: C1 {, K
{
$ Y; ]& y# P5 r2 r& f(*memory).p[poi].flag=IO_waiting;
3 Y- U0 M6 r" n `2 |1 z, M+ _% Y- e) r4 M(*memory).p[poi].computeNum--;4 y1 O# E8 E' j1 B! }
change += exchange_IO_Compute;. D+ l+ X$ n& G4 C! n
compute++;6 a, \9 M5 L/ S/ C D C' o
}
. }& I ], R. Z G6 z1 yelse
' Y# D8 u4 [# ]8 D9 l9 _{- ~* C$ c( f, [% J* X: m; H! y
compute++;
/ a8 D# G1 g* J" m1 P}
s- N# U3 R1 p3 X2 o% x}
: n) W0 z6 G Z5 X6 ~else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)6 ?! \* p9 P6 j) n7 E
{
! E/ k1 p1 z8 c
9 P; m. V% ?; t- C5 _5 ?) Vi=(*memory).p[poi].ioNum;
* \7 a6 U2 n" F# d" Nif(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
! B- s1 P" R* i7 |8 c+ W{
" J4 @5 { b3 }9 C2 L" \(*memory).p[poi].flag=computing;8 W8 W- g, r, G6 `8 e; H9 g# Y" z8 [
(*memory).p[poi].ioNum--;2 m+ Y9 m5 V: a7 S0 T
change += exchange_IO_Compute;
1 p( m% z" w9 M; T' r7 j1 Rwaitio++;' {0 K! q' s1 U
}, d8 m5 q# R: W3 [& f
else6 S" ?0 j& D9 Z% L: S" G
{! z/ z8 S6 U+ {7 X& P# q
waitio++;6 ]2 s5 p q+ I; j# F& F
}$ v$ j6 F/ o9 y+ i5 O9 H
}
5 E* a7 R2 r7 e" C, l5 c, g3 aelse if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing)
) k x5 }9 |# Y{& b4 S/ Y! F+ _% W9 \% \1 Z
(* memory).p[poi].flag=IO_waiting;
, Q/ I- [7 K* [: [9 j& [) Gchange += exchange_IO_Compute;
: O" q7 _0 ~$ V5 k# J6 [* Y, y. [}
4 r8 C F$ y" n2 v" belse if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)
8 e$ ~ Z# d; H9 k{* O& t& i. _0 Z d6 h
(* memory).p[poi].flag=computing;
+ z( h- n8 V* V4 x P, S% \change += exchange_IO_Compute;
) H, Y5 l9 `+ j* L! f( T( H} E1 `2 G- |3 Q. g6 G! m
for(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进3 z3 G5 e2 o0 `7 u, b5 f
{- p0 \- y6 |6 Q+ Q& _1 b
if(i!=poi && (*memory).p.flag==IO_waiting)
0 M8 B3 E( X$ G, }1 r0 |, F. W0 @{4 N% P# L; O, X* _5 Q$ Y' F9 q
j=(*memory).p.ioNum;1 y+ A9 A! B8 Z7 x& ^. l
if(j>0)
+ h& R3 ]. t8 A; V0 Q" H8 ]! w{* o- a D1 D8 z4 o% Z7 c5 r9 s& Z
if(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed
: ?% @1 M! K% |) \{
' H% Z2 ^' r: Q" b(*memory).p.flag=computing;
8 U! h. ^& g* q: t# J. n* a' k(*memory).p.ioNum--;
3 \" D0 H& M1 ~change += exchange_IO_Compute;
4 G Q6 w0 Y0 y3 L* @( J}, s, [0 g- i4 b, [( M
}
" n D1 Y* |9 t, {}/ r! O$ J* Z: c7 d5 g
}: A! L: i! F9 T% Y) \3 d1 _
for(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程
- I' a3 r3 @7 U/ q( [! {2 C1 P+ m{
2 G5 U" ~+ m8 `" Mif((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed, \/ Z3 `9 k/ |5 w
{
0 J, |! [* |4 t- Y9 F(*save) = (PCI*)malloc(sizeof(PCI));, L7 ?4 H1 G9 v" e% |" K
(*save)->next = NULL;0 b8 h: U' V8 m, B3 t0 F8 [; i8 ?
(*save)->processID = (*memory).p.processID;& x, Q N4 d3 T% K! |
(*save)->comeingTime = (*memory).p.produceTime;
& w1 b3 b$ p# Y# F(*save)->askMemory = (*memory).p.askMemory;, N3 ?4 O; k; u/ ?' X, h3 Y
(*save)->compute = compute;
3 V. C5 D1 ^" J(*save)->waitio = waitio;7 d9 r( t( c3 _5 W
(*save)->exchange = change;
2 }, Q. F" r* ]* m(*save)->completedTime = systemClock-(*save)->comeingTime;) U# E( X1 ] H: v+ a" [9 j( U
(*save)->runningTime = (*memory).p.runningTime;
Q$ B# N0 v% z# ?9 S+ E* r$ V H/ K( J(*save)->completedTime = systemClock;
6 _: J( q2 j0 X* A2 _; B/ t1 {/ H+ m*spareMemory = *spareMemory + (*memory).p.askMemory;. `' a7 a ?" a" S; H" P
compute=waitio=change=0;8 Q8 H. k8 \4 G! P
computeLast=waitioLast=changeLast=0;3 S- V% T r9 i: S/ a6 U2 |
if(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入
$ R; _4 |& A- V' \1 S" J* w{
5 N) Y+ E( b @: J* _8 J$ |' vif(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程% ]2 @1 P- ~( e( L
{5 Y$ J `; j8 N# t' W6 O
poi++;
: p1 L7 `( S7 @1 X clockSegment=2000;3 @4 J5 A; j( k6 i8 l* u' k" W, D
}
' w1 w3 K2 l. q2 p: N+ b7 A' N6 Y}/ w, t9 Q. t9 r- l0 v( V$ b
else //没有足够内存调入新进程$ [$ q/ ~/ X( x7 e7 E& ^' ?
{
! A. K; j: A3 V2 L) Aif(i < (*memory).proNum-1)5 w- F* p+ V% F6 X0 Y0 l8 x; h
{; o9 W. `9 s8 S$ A; f% b
for(j=i; j+1<(*memory).proNum; j++)
2 {) `. T0 E F" N& H. t{& | \2 B6 H: C" k( u# {3 Z
(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;
; U5 l H& O1 y4 e; T% p' l* w5 e(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;4 ~! t' N7 x5 H8 k& B
(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;1 R% a2 k3 v% b' J- B$ n# }
(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;8 Y' c& V+ |5 A8 ~1 z6 w
(*memory).p[j].processID = (*memory).p[j+1].processID;
: j/ U, q \6 K8 Q% b4 U! ^2 c5 U(*memory).p[j].flag = (*memory).p[j+1].flag;2 W7 Z' w; J) Z
(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;6 n- T' L8 f( A+ g. e: c
(*memory).p[j].computeTime = (*memory).p[j+1].computeTime;# S0 A" d( n |" C& C
(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;
; O" z9 i9 ^: W# f7 d(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;
1 t, ~& p* U* W/ k' n(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;( [3 f. @4 ^- f& O1 w! O4 |
for(k=0; k<(*memory).p[j].computeNum; k++)
. d4 B1 ]8 X$ ?2 [$ I' A6 e& d(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];; H; W. x, d: a2 ? Q/ O' R5 S& e; K
for(k=0; k<(*memory).p[j].ioNum; k++)
, G3 T# R! W$ } H2 z$ k* O(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];
" J& e0 X! E1 }1 E3 v} ^* |1 y: A. D' w+ g" W) c! q
if(i<poi)- d# ?6 s5 ?. t1 V( x5 |
poi--;
- H0 i3 _' J- W) D- E6 oelse if(i==poi)
! M# j4 B4 Y. q5 S8 Y) [clockSegment=2000;
- ]3 a( F- |+ P) C/ e% @ X}
& v2 W" [0 l# ?/ v0 e5 ~% n. Yi--;
0 |# T5 U' P* @(*memory).proNum--;+ G# O# U8 s6 A8 z6 g$ H! N7 @
}! T8 x. J4 N7 P) n
return task_completed;
2 G+ {5 g6 R0 d9 W- J. @}
6 n3 e+ ? c. ~( P+ {7 m+ B% e9 N}
# H5 g0 c, K' p$ k. `--clockSegment;& K! o, q3 g" \1 M( Z& z
if(clockSegment<=0)
3 v9 |, ~4 D% z% k* K{' B: |9 v$ d$ ?4 T' W/ _# {% r0 Y7 h
poi=poi+1;
' ]& K+ i: `+ h& L6 T/ Iif(poi>=(*memory).proNum)
" \0 F5 h+ y) Z6 ppoi=0;* e; m7 M, c6 H" I4 L4 M
clockSegment=100;2 B( r" C) V2 E+ r5 D2 Y
}
# ?: e$ S Z. Treturn task_not_completed;
" S6 W% \! U M+ z. b5 z}$ d: z2 G B3 }
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)2 B- O. x! H% Q# O. `4 H
{3 }' s% z5 @2 {3 Y8 a
int i=0,j=0,k=0,flag=0,translation=0;: u" Z, T! B( M1 z* h
for(i=0; i<(*storage).proNum; i++)1 @) O D' P/ ^: O8 U! \
{
" P; X% d' p7 r; ?( J- eif((*storage).p.comeingTime>MAX_COMING_TIME)2 _5 n+ W+ {( a. C* W
MAX_COMING_TIME = (*storage).p.comeingTime;, y. ?) u: R4 z g4 a
}1 \6 H- w8 D4 e) G+ p
if(pos>=0)
9 V. [$ k: L! P" C& |8 h: n{- [6 e* b. j; f2 f( ^
for(i=0; i<(*storage).proNum; i++)
, [; _7 P' @% w, U* @" X' L) K H9 a{3 Q+ Y! M' F7 l' ~
if((*storage).p.askMemory <= *spareMemory)
+ m5 m$ o0 M( t% X8 ]; i{
# V' J! n3 Q& q) B& g# Yj=pos;
" E6 {! N" H& L- p% f/ R(*memory).p[j].askMemory = (*storage).p.askMemory;) l' L* v, Q3 F* ~; R7 u
(*memory).p[j].comeingTime = (*storage).p.comeingTime;7 H- C5 f6 G( [- [" N% H9 M
(*memory).p[j].computeNum = (*storage).p.computeNum;
' b2 M- q" D# l+ W(*memory).p[j].ioNum = (*storage).p.ioNum;
o/ Z3 }, N# x7 i( ^5 `! y; Z/ Y(*memory).p[j].processID = (*storage).p.processID;$ k8 h s4 e) ~& d4 P- {$ v
(*memory).p[j].flag = (*storage).p.flag;
7 ~* q1 e. G, ^8 l% d" T(*memory).p[j].ioTime = (*storage).p.ioTime;
P8 i* v% ?. P; k4 p' h4 l) b+ _(*memory).p[j].computeTime = (*storage).p.computeTime;" K6 h) M* B( x' e. q, s
(*memory).p[j].runningTime = systemClock;5 s: N$ z* b4 |
(*memory).p[j].produceTime = (*storage).p.produceTime;
6 b6 L1 n$ y% S" ^. Y4 g% ?0 t" N# ]3 @for(k=0; k<(*memory).p[j].ioNum; k++)
' W" e# E+ X! ]; H' E- R(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];
: I" n7 ]8 }% q# F% A& I5 X* Jfor(k=0; k<(*memory).p[j].computeNum; k++)
* G6 e$ q6 E7 a$ p/ l(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];; i* Y `* a3 k% y$ u
*spareMemory = *spareMemory - (*memory).p[j].askMemory;& Z! T* W$ i8 D$ Z) f( E
produce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程! _& G+ I/ v! h6 k3 Z, E( ]( a+ L
MAX_COMING_TIME = (*storage).p.comeingTime;& n$ @5 i4 l8 F7 }1 @: ]5 z
translation=1;
, n* d! u7 i! f' V* ~- R$ Kbreak;
; I7 `+ Z% D( o1 I0 q& |% V% J" Q}
6 b. F1 _" h* Z* ^) s( z7 Z}9 [2 b4 k% ~. ` F9 y2 V
}, ^6 X( n# Y+ ]7 C
else( H% q* X1 _ |) m
{* m2 {& F o+ z9 A5 n5 A/ n
while(1)0 [* H$ b6 ~/ S3 U/ N7 x. p* C" L# ]
{
* L* c: W* l, Y0 n& j% P5 n; x2 mflag=0;
# L% W: y1 o( v* Q; _3 |for(i=0; i<(*storage).proNum; i++)! t6 } I- Z0 h) F0 ^
{
4 H) i* h3 g6 r9 x8 A( ?4 [3 n Y& eif((*storage).p.askMemory <= *spareMemory)
4 a/ H( d C% R{
6 Q% P1 m0 D3 X$ l3 X' a: e3 cj=(*memory).proNum;7 c8 V9 {4 N; ]# ^1 f! g
(*memory).p[j].askMemory = (*storage).p.askMemory;( D0 ?5 |5 ?# h2 F/ b; C
(*memory).p[j].comeingTime = (*storage).p.comeingTime;4 _. M: H m6 R( q" j( \8 g
(*memory).p[j].computeNum = (*storage).p.computeNum;
. s& e- b! |& P0 w& G: Z(*memory).p[j].ioNum = (*storage).p.ioNum;
$ x, n7 ]2 O2 B- _0 d" k% Q2 Y! a(*memory).p[j].processID = (*storage).p.processID;
5 W3 Y- }. J( s% y(*memory).p[j].flag = (*storage).p.flag;4 y1 {( ~# @# ~ S: C
(*memory).p[j].ioTime = (*storage).p.ioTime;) k# d( x4 X) o: ^" @
(*memory).p[j].computeTime = (*storage).p.computeTime;2 k. S# a+ U8 n( a4 D5 T
(*memory).p[j].runningTime = systemClock;
& X1 n: ?* b5 c2 I(*memory).p[j].produceTime = (*storage).p.produceTime;
! N9 i+ H7 {- c& pfor(k=0; k<(*memory).p[j].ioNum; k++)8 i- {( t5 L/ k8 S
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];3 T: g: e. ?( R: R3 ~5 q O
for(k=0; k<(*memory).p[j].computeNum; k++)
; p; W" x5 h7 R* K7 }0 [- b, n(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];6 t4 g ~, x' x8 A8 F5 T& s
(*memory).proNum++;9 P" t0 J4 m4 M X4 g8 d* y
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
4 k( ?! m! j+ L0 _. Rproduce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程6 B% }& b. o `# ^$ P( }
MAX_COMING_TIME = (*storage).p.comeingTime;
: r0 p5 w" P; Sflag=1;: ?: l9 U- H) ]7 U0 ^4 m ?
translation=1;3 e. S$ }; U9 r7 ?
}
& W6 `, E' e: A) K2 _}5 w D' `/ ?* U$ f
if(flag == 0)- x! X: O1 t4 {0 D
break;1 W8 m: Y7 L% r& `) b
}9 B6 n" Z% V* _2 f- Q1 | ?
}
/ P/ s! W3 e6 J* o, k# kreturn translation;
& |4 C# l+ \6 {}( j. u2 S" m% q+ M
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw)
7 S( v) E. x* o8 ]. N{
4 [, ^' i$ ?# Kstatic int compute=0,waitio=0,change=0,flag=0,flagiocpt=0; _. Z/ f( [ [5 G+ z3 n
static int computeLast=0,waitioLast=0,changeLast=0;
( V" r- L7 Z3 y" W$ y9 [int i=0;; D' a1 o: x/ x' h9 o4 B' M; g
if(draw==1)
' o6 k" s. f: Q- J; H ~{! c$ q; v. G* I" d% N0 r4 V5 T
//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);1 Y2 d8 z, p& ^
drawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
! e( i) A8 r( v& o6 z4 l L, @/ m# c! N5 k' T: h
/ P1 T9 U" |" o- i5 t" M- U
computeLast=compute;
{# k; u0 s. o" l+ zwaitioLast=waitio;9 ]+ @7 p2 E5 ^
changeLast=change;( K5 v( X0 P+ Z1 e- E
}
+ A: y' i) a4 _. O) q$ [/ {if(flag==1)
. T: }! f, x8 u' ]6 Y{+ W1 _$ [2 n" {# w
if((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed
) m, B7 H K& @( I1 Y{- f. B1 ]$ i. c9 ]' |+ z" j
if(flagiocpt==0) // implement compute2 @$ b4 t$ z% }
{
4 p) o+ k3 C$ u1 mi=(*memory).p[0].computeNum;
+ m) S: M1 }! e W# K8 Gif(i>0 && (*memory).p[0].computeClock[i-1]>0)
. v% r7 X: d( Q, b# e{
6 }# R" w6 f5 Jif(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed
+ Y- C1 q5 d ]- X{" ~- y, D6 |2 M1 N
flagiocpt = 1;
- Z8 G7 O3 ]7 M0 }+ L r(*memory).p[0].computeNum--;
2 N! E7 M* F2 echange += exchange_IO_Compute;3 n5 J0 k. Q1 ^! _7 {7 g. I
compute++;, d1 E% W+ T0 S/ x! S, n; L/ H
}9 u- F7 L0 L. i+ ]6 W* U5 l1 u. K
else! c Z2 H2 d- {- n8 b! s
compute++;
9 [" I7 s! t$ k% Y3 H3 `; V' g" v- F" t
}
* O# @6 q. B' Nelse0 ^3 }# j% Z+ J9 h
flagiocpt = 1;! [# J! M1 R9 d5 c; R
}
6 V7 k" H$ V/ J8 X& felse //wait io
1 V4 H. Q) ` W. I% G{0 k+ H& @/ w, O$ {& J: l
i=(*memory).p[0].ioNum;$ |6 s9 z7 N6 K+ @
if(i>0 && (*memory).p[0].ioClock[i-1]>0)
$ W3 h# ^; U% S. Y- d0 S& c& v{* y) R: Y% w* Z5 b, m
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed
2 Y$ U( V- s/ L! K" [+ J{
5 R* U) P8 o* s, cflagiocpt = 0;8 U5 W/ O( G3 c' V4 \% J+ U
(*memory).p[0].ioNum--;& m% _5 X) h6 o
change += exchange_IO_Compute;0 E8 @5 K1 H8 E% \" L$ n# M
waitio++;/ }6 W) s* { Y& l2 O4 I
}# Q! n+ ~& _& B A8 }+ V7 @ e& d
else1 R* i. j, d! o- J2 ]! G7 ~, @
waitio++;3 a1 S5 Y" B0 U: K! O1 J
: _7 N2 w$ U/ g- Y}6 O4 y8 q4 N" R! K7 h* W
else
# ?1 f" X& h& F. x8 o2 {8 wflagiocpt = 0;5 L* [3 m. _8 Z! v% \: B6 ?
}8 o+ m* B4 L6 S4 [, O
}% h4 b4 c5 m8 F5 ~ O2 q% W5 f
else //task is completed6 E: K) c0 z# b
{
; y- y+ w2 z6 s7 G(*save) = (PCI*)malloc(sizeof(PCI));
4 O5 B2 Q, m- E6 E" ]( K(*save)->next = NULL;8 F ]# `) i D% \3 C6 c4 Y# I
(*save)->processID = (*memory).p[0].processID;
) ~+ s; O9 L* |! c4 N(*save)->comeingTime = (*memory).p[0].produceTime;
# x" K% V( L) }(*save)->askMemory = (*memory).p[0].askMemory;
$ V5 B8 J) d# {6 `(*save)->compute = compute;/ n4 r2 k! F; v3 }3 O5 Q3 B
(*save)->waitio = waitio;
! \& ?! Z3 `, i(*save)->exchange = change;
* S9 a( ^% }+ }& P( u(*save)->completedTime = systemClock-(*save)->comeingTime;5 ], P& V+ Z9 n5 ~7 A
(*save)->runningTime = (*memory).p[0].runningTime;! ?" m) P' n3 Y
(*save)->completedTime = systemClock;5 F6 K9 M7 I. d7 s& P7 }9 y' q8 C
//*spareMemory = MAX_MEMORY;$ \) v7 n/ x0 P5 J: ~9 \* h* h% W& b
free((*memory).p[0].ioClock);
! _; p9 @/ A/ Pfree((*memory).p[0].computeClock);! w& n4 C/ Y1 v% p1 |
free((*memory).p);9 A, n: e) H3 Q. U7 Z I6 a) v
flag=0;: P$ @8 ?( s$ A3 T0 L3 J% V0 O
compute=waitio=change=0;+ I/ y+ r) H% J9 x. c8 p
computeLast=waitioLast=changeLast=0;
' C( D# m& n, _# ireturn task_completed;
6 V. U$ ~( K0 G, T. s}6 c" V& _+ o) I0 _
}
! t2 I; c/ b j/ e9 [# w3 Z) y, Eelse
: n* O9 J" M+ d9 Q# u5 l+ ^/ H{- w. Z0 y* h0 G2 ~
FIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));
* m8 u. M! I9 M- z# ]' X, pchange += exchange_process; g3 v/ d7 B3 x5 R5 o/ X
//*spareMemory -= (*memory).p[0].askMemory;
, B3 f" V) B% C" {- ^) y2 B5 Hflag=1;
- @. \2 d, U- d$ d* z( s. i- b//showProcessInf(*memory);/ M f9 m; q, k) m: Z* E0 z; M
return task_not_completed;" @& J" g k* \% N
}
/ `5 D8 w! L2 v" G& I$ Xreturn task_not_completed;
: o! h5 c8 a4 a/ J* ^/ B}
4 t2 q& w: G+ P& {int FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)8 F& ~9 J s; v2 O" [
{% ?" t- u, L. n( x% z
int i=0,j=0,k=0;" I: V8 G% \+ h
MAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;
+ I) X+ M) } ~: m; S5 {(*memory).p = (process*)malloc(initProcessNum*sizeof(process));
- c/ x: S; R; a2 Vmemory->proNum = 1;. ~7 }- ^0 y0 r! T& B e4 E" _
for(i=0; i<initProcessNum; i++)! X6 ~% K& I6 N- j
{1 o+ N# o0 Y4 y$ g, v
if((*storage).p.askMemory <= *spareMemory)
W; |8 U7 L2 W: R4 p+ N{
* L1 S1 ~/ ?7 Q(*memory).p[0].askMemory = (*storage).p.askMemory;
8 g8 R4 W# j& n; F% q% r(*memory).p[0].comeingTime = (*storage).p.comeingTime;. `& ~# ]0 [. N3 x6 b9 m5 [" `
(*memory).p[0].computeNum = (*storage).p.computeNum;: B) {9 i) A. i! Z, \! E$ J6 ^+ m# m
(*memory).p[0].ioNum = (*storage).p.ioNum;
/ M3 y" E Z! N2 `(*memory).p[0].processID = (*storage).p.processID;
5 E, I( d1 K2 ]3 R8 N(*memory).p[0].flag = (*storage).p.flag;
, B0 `& d# P! _$ U- f( u9 D(*memory).p[0].ioTime = (*storage).p.ioTime;- n1 }# O) ~ `$ J1 Y, }: U
(*memory).p[0].computeTime = (*storage).p.computeTime;' G# ^$ o3 k B$ q. Q
(*memory).p[0].produceTime = (*storage).p.produceTime;3 y9 j0 D$ o/ D% \+ h Z( Q
(*memory).p[0].runningTime = systemClock;7 _4 B% {) F* f3 ~6 K# q, b
(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int)); F, r, ]: V; z0 P1 V; S
(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));. F7 s: A% \8 O% ~) l% R( D
for(k=0; k<(*memory).p[0].ioNum; k++)
) q; T! q6 n- T5 m9 _9 T/ ^1 Z(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];
+ N( h+ B4 k! l" Yfor(k=0; k<(*memory).p[0].computeNum; k++)
9 } `1 ?. a( z* p1 Z5 c8 l(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];4 i; p$ p2 C6 s7 j
break;* n" F7 I& c* @: Z- T
}) g/ p% G0 p5 s# w, d
}: J3 E5 k+ I, E
if(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入
- m! K; \0 j$ T$ |& v& x* n: K{& J( W# n. f6 e n
produce_one_task(storage,i,ID_FIFO++);2 {. q u4 t- `2 J1 Q; J6 r
MAX_COMING_TIME = (*storage).p.comeingTime;
& X* I" q, U8 D* ?4 r3 Asort_by_comingtime(storage,i);
* C+ q' z$ a# \/ z; X# y: {) M2 d% c1 E& I& Q}, z' m! R, T$ g5 W: }" d- {: Z
return 0;4 [- b7 { z" M
}$ w; l h9 [* g/ G- h
int sort_by_comingtime(processPool * p,int pos)4 O1 L' {9 P- u: _3 @& q$ E
{7 k1 M! {% G& @8 A! R2 U
int i=0,j=0;" w" C7 [: U! L# |, d0 Q
process temp;
1 G% T: ~. [, a6 a$ A! Kif(pos<0)( L8 @, D4 h; I5 F
{7 v* l5 A7 l3 j& p
for(i=0; i<initProcessNum; i++)+ P: U0 e- ?$ I: S0 F
for(j=0; j+1<initProcessNum-i; j++)
6 Z" R: F6 @" g, q( z- O' k+ S{8 j$ q: z3 W8 y5 {
if((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)
% x7 z. Q1 j3 U/ @3 m6 p{9 a4 p/ r5 M, i! }) v4 P
temp = (*p).p[j];
8 M: ^5 U/ U+ L& p* n8 }$ i Z(*p).p[j] = (*p).p[j+1];
" n* X# h9 o+ T& b/ c, y3 ~$ V+ Z(*p).p[j+1] = temp;0 J2 t/ A$ r. S1 |- Z' H! u8 ~
}
; w2 G; h) M/ A0 ~/ @}
7 l8 h' @2 ^! \' G}4 ]: s/ D4 i2 B% P7 [7 Y
else if(pos<initProcessNum)- ~2 z- ?, e+ k; r( E5 k3 K
{
2 H# u' E# c; s4 N7 ?for(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)
) G8 m. e; Q! ?' j5 e" W{
) q" {8 }7 h( h) ctemp = (*p).p;& K; _6 a- q' B m; V- B
(*p).p = (*p).p[i+1];
: ~8 M' K+ k; s4 k+ t/ @(*p).p[i+1] = temp;1 k& O+ v- y; _7 K3 z, L
}4 J* u6 f# r4 ?( z4 Q7 h
for(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)# n; }9 U4 V+ j( {8 G
{
/ m* i" n6 V7 B5 w9 U) @( ?1 p/ ntemp = (*p).p[i-1];
|. x3 n) X9 H(*p).p[i-1] = (*p).p;# E6 J* D+ ?! b, u/ j" z2 o
(*p).p = temp;
# S8 Y$ w8 V6 p, _1 ~}
6 P% q" M: e/ S5 l% N}: E+ Q7 u0 q( R3 R
else
5 N! z" }& Y6 P) \printf("position eror\n");
. b5 L5 L& l/ Z1 u" z, @5 dreturn 0;: W* D9 G& y8 q6 P9 k- _
}3 N" g# y, a* k
int InitPool(processPool * p)
3 R: s8 h" `4 N# t{
0 h1 w6 R5 C; Cint i=0;
* i1 L7 l' q& I I* M' W(*p).proNum = initProcessNum;
; c4 G) L8 p$ K8 B- B(*p).p = (process*)malloc(initProcessNum*sizeof(process));) R4 n4 N7 v' g# D
for(i=0; i<initProcessNum; i++) //init process information
. ~9 o( c/ M1 ~8 j{
1 g7 x$ L% c, M3 R" n. {. J& s H(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));( u2 X. w$ r9 j; E$ Z. {
(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));
) V: w0 Q! G; R; s/ f% x, uproduce_one_task(&(*p),i,ID_FIFO++);1 C5 J" w/ P$ H: e
}7 l: m! h5 @( ?0 }( a) D
return 0;& ?1 P& q8 z' n8 U' g
}# D% p" d# O) L$ F* [* K3 t
int produce_one_task(processPool * p,int i,int id)6 B/ p* Q7 w4 u: }8 Y: m
{
) z9 o( T7 N$ D% y0 f( X2 Tint time=MAX_COMING_TIME,j=0,totallTime=0;
: Z, b4 L4 [+ d+ s; Z; d(*p).p.processID = initProcessID+id;
7 p. s& L2 z9 H( _ M1 l(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);% j0 [( L5 }" Q# ^
(*p).p.produceTime = systemClock;7 n$ I! s% {$ i3 [/ [6 U& q
(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;% D0 @6 V/ @3 W8 m; m! T
(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6; K* P8 r+ {0 R
totallTime = (*p).p.computeNum + (*p).p.ioNum;9 V& ^" Q+ G0 i+ a( B, L! d! y
(*p).p.computeTime=0;- `% i- }2 O; m4 l6 S$ Q
for(j=0; j<(*p).p.computeNum; j++)
0 O3 }: M1 W2 l5 i" u. @% }{( h5 l: W/ u9 d6 U! O: _
(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;
# ]' X* ^6 q) }1 i* \/ H(*p).p.computeTime += (*p).p.computeClock[j];
% C' E8 W1 M' M0 X( q}/ F0 Y$ A3 j9 d
(*p).p.ioTime=0;* E3 w" u }, V! M
for(j=0; j<(*p).p.ioNum; j++) |
|