- 在线时间
- 1630 小时
- 最后登录
- 2024-1-29
- 注册时间
- 2017-5-16
- 听众数
- 82
- 收听数
- 1
- 能力
- 120 分
- 体力
- 563395 点
- 威望
- 12 点
- 阅读权限
- 255
- 积分
- 174241
- 相册
- 1
- 日志
- 0
- 记录
- 0
- 帖子
- 5313
- 主题
- 5273
- 精华
- 3
- 分享
- 0
- 好友
- 163
TA的每日心情 | 开心 2021-8-11 17:59 |
|---|
签到天数: 17 天 [LV.4]偶尔看看III 网络挑战赛参赛者 网络挑战赛参赛者 - 自我介绍
- 本人女,毕业于内蒙古科技大学,担任文职专业,毕业专业英语。
 群组: 2018美赛大象算法课程 群组: 2018美赛护航培训课程 群组: 2019年 数学中国站长建 群组: 2019年数据分析师课程 群组: 2018年大象老师国赛优 |
) x! d" F) T3 s
经典任务调度算法的模拟程序
: J$ n: F* m7 {7 B0 L2 `1 q j本科毕业设计写了一个经典任务调度算法的模拟仿真程序,测试了五种调度算法的运行性能。在程序中虚拟了任务的进程,按照不同调度算法策略从进程池中选取任务执行,在任务执行过程中,保存相关的统计参数,最后对这些参数进行处理,反映各个调度算法的实际运行性能,程序中可以通过修改任务的相关参数改变任务特点,测试不同任务环境情况下,调度算法的性能适应性。程序是通过C语言编写的,为了对运行结果图像化,采用了EasyX的图形库。由于计算机中实的任务调度过程比较复杂,在实验中为了简化程序的实现,在某些方面进行了特殊处理。* l/ O, }8 f( r5 q; S
- [, k2 r9 P0 ^6 L8 x# g W7 [编程平台:VC6.0+EasyX图形库环境。
Q2 T2 R3 u0 D1 |, [" ]" K3 `
1 l6 f. G6 T1 w, _0 u9 b( ^0 `" R以下截取部分程序运行图::. W4 r! Z( F h
5 S% g3 O. j+ m9 h2 l源代码:
# U* j* m F7 a6 ]2 {" s
& n5 D) K4 _- d: v5 F#include<stdio.h>
4 I9 p, z0 U' X' u, D x% x2 x* `#include<stdlib.h>
3 O1 C: X8 `; I% e& o( R4 q#include<easyx.h>/ X7 m" k- A0 }, M0 u! ~$ [- V
#include<time.h>
& Y: n, g* v9 S#include<conio.h>
! k+ C) }, e* K# O3 D" T" b$ D#include<graphics.h>
4 a; d! e5 X/ `4 x& X% G: O+ O#define initProcessNum 10
- `$ f1 }( g& S$ ?) O8 ]#define initProcessID 1000
2 |% f0 v: X) d, {( V#define MAXProcessRunTime 10000& O' ~9 K9 K0 j7 G
#define MAX_MEMORY 4000% _0 G. v* T4 v6 U( I4 H+ u" U
#define exchange_IO_Compute 10
. _0 ^0 I' z$ ]#define exchange_process 25' d: c3 A! d; W. J
#define task_completed 16 ^% S2 I- I! o) E2 B* N5 i" W
#define task_not_completed 0
5 {+ b3 m% u/ @1 _; M#define initclocknum 100
4 N0 I3 k3 V% _7 venum condition* A* k4 ]! X* a, E7 T5 V
{, p0 v. Z! o- h8 m X3 q
dead,computing,IO_waiting,ready2 ^$ s5 c5 Y9 f3 }5 s3 U
};
6 q9 n8 G3 [1 k/ z9 {; Z2 X lstruct process
9 P$ q" r0 d: W) @8 B/ h) ?2 ^{
6 d/ X: j) |# Nint processID;
$ h: \' d& M2 sint comeingTime;* K3 R3 B6 B7 b' M0 T0 I
int ioNum;& @7 P1 K) X' q8 n, C; X6 @% F1 H; r
int computeNum;9 [5 A* s' h) P$ k, s5 [; Y
int * ioClock;" M$ C5 N" Z6 w/ a1 j& e
int * computeClock;
2 }) a( M8 ~) ^# j! Rint ioTime;
+ b$ J; Y0 J( H3 q9 V7 ?. Eint computeTime;
) j u9 `' S0 e7 Nint askMemory;* O1 f: w% }1 r
condition flag;
: _3 S9 |9 u' Z, u) i' |9 |int produceTime; //生成时间,以下三个数据成员用以计算相关性能
" s m# Z' L4 C9 Wint runningTime; //第一次占用CPU的时间
/ M- r+ J6 _( r/ L5 W( _" n7 Aint completedTime; //进程完成时的时间
- o% z& H' i# m* m};
' J/ ~9 B- m( l1 Jtypedef struct processCmpletedInfo //保存完成一个作业的相关信息. K* H5 K4 R: t( ^$ i0 D. e! `
{
0 {! b" [2 q2 L; o$ ]: S7 rint processID,comeingTime,askMemory;3 O7 u" E/ [0 ^1 |* _
int compute,waitio,exchange,completedTime,runningTime;
3 a) ~9 ] ^& J; T. U$ N' o3 A2 R' ZprocessCmpletedInfo * next;
" r2 f f4 T+ b0 q y}PCI;% _% P# G2 a; N
struct processPool" T8 @9 r* q: Y8 n9 F* l% ^9 q( [/ E6 E
{
9 E, J! j( z- {( e0 ?9 O# kprocess * p;
/ ~% F# W+ x& G- w0 q, _int proNum;
" _! `1 W6 ~; N( r. o z! P: B};1 F6 [ Q$ k% H" z E; H
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;
9 @! p7 w/ b9 i$ u. ?& b3 Cint InitPool(processPool * p);
# n. ]5 i3 V$ v, Z ]% n2 ?int produce_one_task(processPool * p,int i,int id);
/ a: r: n' o: E3 |7 kint FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw);
6 b! x+ U$ e# {9 a6 @& [6 sint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
$ Y! _- W: _ C% H2 l% q# ^% Kint TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos);
" E- z2 V$ {% ?4 @+ j, E+ k* q7 ^int FIFO_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
6 C; Z; ~' ?5 f7 A4 ?- ?int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
9 q: w0 T& B; i: O3 T! b2 b, \# dint SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
) R; h8 E0 d- K6 vint PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);" M' L& {$ T9 V
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory);
" e/ M4 O& Q4 Y: u* D2 {) Jint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int disatch);
) l8 n! r) i8 R: {: F+ j9 Nint High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw);
/ G9 L }2 K4 P' o4 z% j1 n$ [
' G4 [ f" q) w! _! r/ w8 g. A- ^int sort_by_comingtime(processPool * p,int pos);! I3 T, d/ V( \) r5 M6 r- t( ^
int showProcessInf(processPool p);" ]) Z- j# R9 p9 \
int drawPerformance_FIFO(int x,int y,int memorry);
! ~$ I0 i4 l3 t0 ^int drawPerformance_HR(int x,int y,int memorry);
# z* ^& ~' U1 k) w- W4 _6 Gint drawPerformance_PF(int x,int y,int memorry);( g. [. l4 L- ^
int drawPerformance_TT(int x,int y,int memorry);
! q h5 \6 i; r2 T% n& }0 d) V$ _) Cint drawPerformance_SJF(int x,int y,int memorry);* q. {8 r3 ~& o
int MouseListening();8 R1 Y0 f% \+ n+ K4 T& [/ c
int MouseListening2(int *flagShow,int * showTime);
+ N7 B9 j. d X: g$ C0 Cint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR);
3 w3 _$ H: a( k5 ?% u: ?7 X- ]. m
; y' h: M, a7 u O* v9 X: Y' I/ Z8 k9 X6 [- a
void main()3 ?4 O; k$ d8 M
{+ t+ O( X5 C$ t. B K3 p7 q7 q
PCI* FIFO_save_head=NULL,** FIFO_pri=NULL,* Timet_save_head=NULL,** Timet_pri=NULL,* SJF_save_head=NULL,** SJF_pri=NULL,
1 j- _! v8 @) u5 n# |*Priority_save_head=NULL,** Priority_pri=NULL,*HR_save_head=NULL,** HR_pri=NULL,* p;- q9 R; H3 Q8 M* e: G
int i=0,FIFO_memory=MAX_MEMORY,count=0,Timet_memory=MAX_MEMORY,SJF_memory=MAX_MEMORY,Priority_memory=MAX_MEMORY,HR_memory=MAX_MEMORY,, t. M( i* A% K4 u8 Q) \9 p
flagDraw=0,showTime=100000;8 \3 ]5 y6 L/ _1 o3 U
processPool FIFO_p, FIFO_mmy,Timeturn_p,Timeturn_mmy,SJF_p,SJF_mmy,Priority_p,Priority_mmy,HR_p,HR_mmy;
% U- Z3 _$ @, K9 f% g( {FILE *fp=NULL;
5 V, r ]( z9 P" O& b" X! ?//processPool HR_p,HR_mmy;/ [2 [* ^# D+ G* i$ ], k
6 z4 s% [/ ?5 ]% x+ P6 ^2 m' K4 V! Z f+ e6 j
srand((unsigned)time(0));
5 X, g4 U/ q5 a% a! osystemClock=0;* G% ^) x/ Y) m* F. K
initgraph( 1200,650,SHOWCONSOLE );
& J; s) F6 F- Ssettextcolor(GREEN);) X3 w/ }' V$ W
setlinecolor(GREEN);
0 V1 ]: {% l$ J( Y* Qsetfillcolor(GREEN);2 Q2 A ^5 X- k3 a* j9 M
InitPool(&FIFO_p);
' [% w, m0 T( b9 [1 ^sort_by_comingtime(&FIFO_p,-1);) d3 G' f y# M7 B0 J
InitPool(&Timeturn_p);, i) f) [* ]" o/ C' a" d
InitPool(&SJF_p);6 j' W* p' ^! h& G% q4 n* c
InitPool(&Priority_p);( F6 w5 K) N% K% e
InitPool(&HR_p);& U/ C5 I) N" F
//showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);
0 @$ }+ v; Z$ h# r& ^1 O//Sleep(10000);: y- K. k, e7 J, r2 T
0 }7 y& M: G3 }; A2 {: c
7 ^! D/ |, e2 K8 c5 wTimeturn_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
& O' T. P/ Z7 c1 c! f& Z+ xSJF_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
# p' ]$ N) ^) T4 ~: J" W+ g, ~Priority_mmy.p = (process*)malloc(initProcessNum*sizeof(process));
7 S. {; b. r: Q( kHR_mmy.p = (process*)malloc(initProcessNum*sizeof(process));2 I% b: ]1 j" d
for(i=0; i<initProcessNum ;i++)4 Y, t# q J; P0 Y! i
{) v9 n6 ^6 e c
Timeturn_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));' k' X) v+ I; s& ]; C/ j
Timeturn_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));- u2 ]; `( v; w7 U1 m6 Y/ S
SJF_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));1 S7 l+ ]# U2 W; [0 a& a k
SJF_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int)); G$ ], a% T# e7 q
Priority_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));' [# U! S/ u7 K9 q8 m# h; w
Priority_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
# ~; s* n) Z# G0 e- s" n2 tHR_mmy.p.ioClock= (int*)malloc(initclocknum*sizeof(int));
/ v4 j1 b" Z+ v$ r8 |. ~! bHR_mmy.p.computeClock= (int*)malloc(initclocknum*sizeof(int));
3 \% ^6 r: C5 z$ E+ J1 a}
5 }/ a. R5 Q0 h7 j9 wTimeturn_mmy.proNum = 0;5 I, o7 J- G* ^) |
TimeTurining_storage_to_memory(&Timeturn_p,&Timeturn_mmy,&Timet_memory,-1);
+ ?9 Y% X# F5 B/ n$ M' oSJF_storage_to_memory(&SJF_p,&SJF_mmy,&SJF_memory);
8 @8 a2 O( F6 O4 Q0 qPriority_storage_to_memory(&Priority_p,&Priority_mmy,&Priority_memory);* \1 T- T1 x5 Z( B
High_response_ratio_s_to_m(&HR_p,&HR_mmy,&HR_memory,0,1);; B) J+ n2 a$ n: Z# Y2 _
//showProcessInf(Timeturn_mmy);
+ |) [7 n/ U8 v: C+ AFIFO_pri = &FIFO_save_head;* ]( I) G& `1 B- ^; \
Timet_pri = &Timet_save_head;8 p4 N" O; k5 }, O. b- ]; Z/ R
SJF_pri = &SJF_save_head;# |/ X1 N) D0 D! Y2 _
Priority_pri = &Priority_save_head;
1 ~4 n- Z g: A5 [0 Q1 S4 t* \, o4 H HR_pri = &HR_save_head;
' N" Y g: |* b# ksetbkcolor(WHITE);* d( ?# O( ^* x) N! @5 T
while(1)" I2 i' D% S O+ n" x
{! f, h2 U: i! I
if(MouseListening()==1)
* _* c+ G3 Q# ^flagDraw=1;
+ z& Q, I8 i, g4 \: @2 U3 Uif(count==100)
. q" L: Z; U& n6 h. b3 W{' B" k8 F( r8 c! |
if(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,1)==task_completed)1 r) L! t8 | D1 h1 f
{# O% Q; E, r' J
FIFO_pri = &((*FIFO_pri)->next);
( T+ O) `9 S) _2 N) [
8 j3 w# j4 D8 z7 a5 r//printf("hello");
0 L7 I: q" s7 G- l$ d, \9 y}! c3 W0 g3 ^$ d! S |1 B/ n
if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,1)==task_completed)$ a; V! n) x/ H& J5 @, w
{0 x: f2 O* i3 j. H! e
Timet_pri = &((*Timet_pri)->next);
* K& O- x4 w. ^! d0 l! G- c//printf("hello");
& P$ N4 N2 N' Z0 ^0 |& |/ b1 M}3 I. N" X2 T P9 u
if(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,1)==task_completed)' v% o6 x0 }1 L- @. ~6 D
{
* a* J7 Y, Z* I, {SJF_pri = &((*SJF_pri)->next);
! @3 N. V5 O* k7 D//printf("hello\n");6 I% B1 ]: f: w& s- i2 U* C
}4 N) q/ \; G7 l" y
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,1)==task_completed)
8 Q7 H P% D9 v4 u5 N1 }/ H{
8 ~, V4 B5 q, J* {$ ^9 @Priority_pri = &((*Priority_pri)->next);
3 l) n8 K! k& Q$ g9 z: [ j//printf("hello\n");
# Y" H0 C9 K# l5 Q}% s" ^4 n, I% r/ M j6 @% Q
if(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,1)==task_completed)
3 B6 `' q0 f W( e; O2 o{/ D) U7 t5 i e$ P" L1 b2 j$ I
HR_pri = &((*HR_pri)->next);
. Z! x* k& Z3 Z$ @) u% ]//printf("hello");& k1 Q' b* o" x1 n' b$ o4 R8 d
}" ]( c6 z& E# W; a* F* V) _7 S
count=0;
, d; W# H2 f. ?* Z}
1 y/ T' V: d9 w& D: E% qelse
1 C$ [; V' n# E3 g6 N1 W- K{
" u* F/ W4 m K4 ^' C% sif(FIFO(&FIFO_p,&FIFO_mmy,&FIFO_memory,FIFO_pri,0)==task_completed)
# `& i! r2 j& z0 ~{/ L6 s2 R! g4 s5 m2 `
FIFO_pri = &((*FIFO_pri)->next);9 [" g9 ?1 {( g3 K
// printf("hello");
3 E a9 d1 d. r3 s3 n}
0 P$ O& u6 ^8 U) l( Y# q ^* w3 w% `if(TimeTurning(&Timeturn_p,&Timeturn_mmy,&Timet_memory,Timet_pri,0)==task_completed)
- d# B( y8 p M8 G{, ]2 n- Q2 z; m" G
Timet_pri = &((*Timet_pri)->next);
% m3 S2 q& L3 [% l4 z6 a// printf("hello");
- l4 s; `( q, E+ T2 V- p}
j! c( y$ h) b5 K9 @. Wif(ShortJobFirst(&SJF_p,&SJF_mmy,&SJF_memory,SJF_pri,0)==task_completed)
( X' F8 t* l5 k V{
Y$ g7 q J8 C0 f, U% I SJF_pri = &((*SJF_pri)->next);6 V4 Y: c/ l9 p; [
// printf("hello\n");
* g0 l# ^2 i" g+ ]1 C}1 o' _6 R+ y) E J% T
if(PriorityDispatch(&Priority_p,&Priority_mmy,&Priority_memory,Priority_pri,0)==task_completed)
8 I; y! X3 `" v2 i X{
5 i$ M f- n5 z& d. _ s) [Priority_pri = &((*Priority_pri)->next);$ } O5 P: L- ]3 v2 x% e# `
//printf("hello\n");4 F4 R! A+ i! s0 s4 _' u4 C/ z
}
) x/ U- }- e/ {% L" j1 A1 f4 Yif(High_response_ratio_dispatch(&HR_p,&HR_mmy,&HR_memory,HR_pri,0)==task_completed), C# {% | {2 `
{
+ t. E" a+ p( m% G! u& ^) i/ }HR_pri = &((*HR_pri)->next);
0 N) Q+ I1 z, k& A. F/ [//printf("hello");0 ~, t# a: [2 r. F4 ?4 y
//Sleep(1000);5 b2 K0 [% B0 Z& o! n. l q
}
+ I, A: _$ r8 Icount++;) v) W. {( C7 M
}8 u4 m; J: k) e4 ?4 o9 H
if(systemClock==showTime)
% p1 c( B+ K3 i! R) L; Q{' c" H. w/ J: Y. N/ Q
/*PCI * p=FIFO_save_head;- b3 l$ ^- N* q7 a; M
int i=0;
! Z' @' |8 X+ c. P9 C9 ?% jfor( ;p!=NULL;p=p->next); ?' X3 B0 b. [% R) M4 _: c
{
/ _2 j9 u1 @- r. g; o: Y' Y) _printf("Id %d\n",p->processID);( [3 X: | s+ L5 `6 ], q* J4 |
printf("comeingtime %d\n",p->comeingTime);. L9 B+ ]7 P& S" I
printf("runningtime %d\n",p->runningTime);
4 r0 Z* N" Y5 Cprintf("asdmemory %d\n",p->askMemory);
: a; u5 B9 s: n. n2 bprintf("completedtime %d\n",p->completedTime);
. G; B0 ]& n6 w' U) vprintf("compute %d\n",p->compute);
7 Y4 a" @& v& G' q- q2 d, kprintf("exchange %d\n",p->exchange);
5 S1 O' N& h5 K: u2 E! `# c* l7 Z9 `printf("waitio %d\n",p->waitio);
) \) j8 ?! ~: c. X- v8 S$ zi++;
- r5 Y7 e9 o, |9 x7 X, v- h% a$ U, R" }; L" j$ v( u+ p. ]% h$ g9 o
4 w0 ^3 w, i, S
}
' H& T& J5 c/ d' j5 y& _printf("%d\n",i);*/& k# A* i% l8 ^7 @* Q! [8 u# K
if( (fp = fopen( "data.txt", "a" )) == NULL )
1 l! ?2 g8 L& Y{+ o7 B* J9 }( ?$ I" ~% p, V
printf( "The file 'data.txt' was not opened\n" );- \, @8 t p+ M d
//return 1;
: _& t$ J( l+ X# w e}9 j) L6 r% m, {. X* {% `' a! {
else& W6 a9 K0 N' N$ V8 |
{
7 I% ?! y1 @- [' |2 sfprintf(fp,"FCFS \n");
4 x0 j) e% }+ q- j( |# Afor(p=FIFO_save_head;p!=NULL;p=p->next)
# a9 o4 n/ i5 B& V- |fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,; y6 D( ^5 I( b
p->exchange,p->waitio,p->runningTime);
q% C; U& a9 n- J; ~$ Gfprintf(fp,"\nTime turn \n");
4 Y4 d: P4 O' a! C) ~4 ?for(p=Timet_save_head;p!=NULL;p=p->next)
5 a: q- r9 g: Q; D: K l1 ffprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,' p- Z b; v* w6 ?- r+ H5 d
p->exchange,p->waitio,p->runningTime);' v* U2 P7 `2 ^
fprintf(fp,"\nShort Job First \n");
" f- v# S/ F2 \1 Rfor(p=SJF_save_head;p!=NULL;p=p->next)8 S: s" q9 ?9 v0 K; Y' T3 ]
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
5 i& N- `4 Q1 x: i7 }3 B2 S, L& n" Cp->exchange,p->waitio,p->runningTime);
% i/ X( J0 h& [' \- F4 ffprintf(fp,"\nPriority \n");
9 h' S9 V7 J$ d' a& v; efor(p=Priority_save_head;p!=NULL;p=p->next)
3 S5 ^4 j8 H) M, K! ~" _fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,
3 d! [' P" t4 [9 i: o2 d! B Sp->exchange,p->waitio,p->runningTime);$ \( W6 N1 a' Y! \# N- U, m* V
fprintf(fp,"\nHigh response \n");- q& @ k3 L# ~ w D
for(p=HR_save_head;p!=NULL;p=p->next)$ M: k/ U6 C- P0 j: i( _
fprintf(fp,"%d %d %d %d %d %d %d %d\n",p->processID,p->askMemory,p->comeingTime,p->completedTime,p->compute,5 Z5 {, W; [/ y
p->exchange,p->waitio,p->runningTime);' O1 }( b. ^* \# W3 O
fclose(fp);
7 W3 _/ _1 K4 M2 J s, O, O}6 F5 y. K# _. T+ N) M: R* `& D4 m
showRunningResult(FIFO_save_head,Timet_save_head,SJF_save_head,Priority_save_head,HR_save_head);- @: P8 N6 ~/ K# c, q, E! R' S) ?
MouseListening2(&flagDraw,&showTime);
4 \3 }" m. K% W; B}: B1 Q8 w E4 y5 l' K+ ^8 [) ]
systemClock++;- {3 k( e. B. F7 U2 Y* {
if(flagDraw==0)9 Z& j3 E( s/ N d& Y/ \+ T# f
Sleep(10);
# _0 H8 P- F/ V6 F5 U}
( F5 ~6 S5 W- ?9 `0 Y/ b" u
$ |* ^6 f4 Q: f3 q2 _/ M$ N/ f+ [, s a7 H4 f* F7 k$ o0 J% C
}
& f3 j. U" _& c- {( A' l. e" A- Tint showRunningResult(PCI* FIFO,PCI * timet,PCI * SJF,PCI* PR,PCI* HR)
4 t f% V7 T" n d{! p8 w3 i1 k9 l% d- r s
PCI * p=NULL,* name[5];) J7 ^$ Z2 x* \$ A
int count=0,i=0;
) K+ ?0 S2 ?% e5 g! i5 M2 p. Q( Kchar ch[5][10]={"FCFS","timet","SJF","PR","HR"};9 z G" S) U5 p/ D+ @: r
double turnover=0,wait=0,c=0,w=0,change=0,pos[4]={0,0,0,0};4 }9 R& F# G0 I; [+ B
struct info
( x d S. U# {. `3 k{
# q3 W# g; M; R: n4 {9 x% F0 J' |char name[10];" ?9 C" s |5 j* G2 F' G9 `
double throughput,turnover,wait,CPU_rate;
0 R$ X* j, W0 H6 {( }}inf[5];; q- p7 |2 e6 b) n1 w
name[0]=FIFO,name[1]=timet,name[2]=SJF,name[3]=PR,name[4]=HR;9 H$ j8 ?& z* @, T* t# [- V3 H5 k
printf("调度算法..........A\n");
! ~% a" |. S6 n; x/ Tprintf("吞吐量............B\n");4 D/ G/ N% i2 W! f( b
printf("平均周转时间......C\n");
; l9 S% I4 {3 A, b7 n6 q. {1 ?. Uprintf("等待时间..........D\n");! x0 q, U' i4 G' s( \: |6 ^
printf("CPU利用率.........E\n");
+ \" n5 f9 _9 B5 J6 r. Cprintf("A\tB\tC\t\tD\t\tE\n");
, J: X# Q6 J- I, x# ]8 R. @1 efor(i=0;i<5;i++)$ J) E% h" d& y* n
{& q; U. v+ z" k$ O' Z- e4 P( c4 c
count=0,turnover=0,wait=0,c=0,w=0,change=0;$ @# ?3 q1 d" G- C( u
for(p=name; p!=NULL; p=p->next)
% W! O$ v9 u) ]3 H! t1 b7 ~{) \7 G* O3 L9 o
count++;
# {* T3 M3 l5 M6 e' T# qturnover += p->completedTime - p->comeingTime;
# w; N( P1 W: U2 q) C; {wait += p->runningTime - p->comeingTime;
0 T% p4 {& `. A0 s) t* `, jc += p->compute;" A" x0 I8 z: C0 o" _' t/ f2 T8 j1 ?
w += p->waitio;9 \2 X w9 u) Z
change += p->exchange;% O. v5 h+ B) r8 s" Y2 Y
}: p( T& d5 Q. b \- Z
turnover = turnover/count;
: h1 H( Z+ J% Rprintf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\n",ch,count,turnover,wait,c/(c+w+change));9 R0 M6 o2 J8 R2 w1 E1 c
strcpy(inf.name,ch); ~+ w: [) N z) b9 ~5 w# N
inf.throughput=count;
: _2 L7 | z4 g$ b1 K6 I2 ], F% Kinf.turnover=turnover;
; B5 R3 i+ y, E' q9 |- winf.wait=wait;! a3 V4 v& t( P4 `
inf.CPU_rate=c/(c+w+change);7 j) F( S5 y* J
}
7 l! d/ A" v* c1 ]; o; d//画图
+ C: x* K' A! `! C% v& N7 t//cleardevice();/ ^. y2 c* \+ O x# i4 _# t
line(0,600,1200,600);- B/ F1 K4 }( m7 t
line(10,600,10,200);& S) x3 H# q% _+ X) y/ p8 Y. T q
line(10,200,5,205);
6 i9 J9 ]" W5 \& s/ W* Mline(10,200,15,205);4 b# k) w `7 \( t6 \/ w" d8 \( }
line(310,600,310,200);# B' f; r* c5 [5 |: c% C& h% }4 i
line(310,200,305,205);
' v2 m. q* p9 I5 Q4 Tline(310,200,315,205);
4 T; w& B' z0 B9 {line(610,600,610,200);
" G& A; d7 N: a7 {" l* H6 sline(610,200,605,205);+ u+ _/ K0 K" ?- t1 O T7 i- f9 T$ Z" T8 D
line(610,200,615,205);
/ H h4 Z% U9 [* [line(910,600,910,200);3 F! Z. o. N6 w# W; `
line(910,200,905,205);
- I+ T7 h/ X( p/ H( m8 aline(910,200,915,205);//最高的长度400,宽度均为40
! R! C' J7 r/ E" M" g& i% @/ u3 L0 m: _for(i=0;i<5;i++)& Y' k1 L9 D2 K; F
{* X+ x" t8 a( Z e
if(inf.throughput>pos[0])/ L3 q5 m8 W0 c/ R* P3 X5 K6 F P
pos[0]=inf.throughput;2 v! {( J7 o3 c
if(inf.turnover>pos[1])
I0 \/ p! ~5 j& Y; i' o( }9 V2 Jpos[1]=inf.turnover;' a I# `9 k+ t
if(inf.wait>pos[2])
8 D7 n# s8 f2 A% t4 _pos[2]=inf.wait;8 ^+ z( e- |* [- e7 Q' S+ G. ]
if(inf.CPU_rate>pos[3])
. m; {$ V- l# \# d, `pos[3]=inf.CPU_rate;; v7 i6 ^1 M W7 ^
}" X) m3 O! K4 M5 }2 Z) _/ H
settextstyle(30, 15, _T("楷体"));5 ?. Q3 ~! I7 J, X5 s
for(i=0;i<5;i++)
: d3 O" O' ]) L" E7 m{, d# S" K5 d& ]5 A# ~8 `7 F$ g
switch (i)
; c- [0 `' X& {( q) s, {. W{ s R1 z" O0 R5 v9 n) o' r
case 0:
+ X/ R0 K/ e% l, Y+ ]setfillcolor(BLUE);$ W1 _5 f5 G6 v) o S' z/ Z2 x
fillrectangle(100,50,150,100);
?7 o M z7 oouttextxy(160,50,"FCFS");. U$ s" d$ k1 X4 d3 d* y7 B& V, d
break;
9 ~4 D8 h4 v3 E& v' I# W/ lcase 1:6 ~) E1 X" ?* M% [! O
setfillcolor(RED);
/ o3 z: _# t/ `2 ?$ e# Efillrectangle(250,50,300,100);
% U, o6 \" T3 S! F0 s: Y/ Youttextxy(310,50,"timeTurn");
" i _" r0 n$ j/ N" y% Rbreak;, d* E0 o+ m1 l6 O; P" M7 W
case 2:
: j. P! }0 B4 Csetfillcolor(YELLOW);
2 m1 |: u2 W+ a6 U" q+ P) Ifillrectangle(450,50,500,100);# S+ e& M+ _) g1 |, K- A% l& I
outtextxy(510,50,"SJf");/ X! B9 p3 \) R" M2 V' V( v
break;
m0 J& X3 M( G7 m! hcase 3:# }* V# e, Y1 \ z6 z6 s1 X
setfillcolor(BROWN);
! X, X7 \% @2 qfillrectangle(580,50,630,100);
; u" _6 f3 x! M; Couttextxy(640,50,"PR");. p# R9 b6 b. E5 J
break;" M. E, T3 ]5 {4 {* d$ \
case 4:
1 t! V {: P Q; K! nsetfillcolor(GREEN);
( {0 Y- a; T3 |& W0 c# Efillrectangle(690,50,740,100);* q, f" P) i+ L' Y! ~
outtextxy(750,50,"HR");1 ] e: j8 B2 E8 i
break;
3 F+ s7 ]" r& | `! o; r}; i5 b' Q1 v* D8 ]( N- G
fillrectangle(50+i*40,600-(int)(inf.throughput*400/pos[0]),90+i*40,600);
9 E3 C" Z( v6 ^, D, `& w/ J* lfillrectangle(350+i*40,600-(int)(inf.turnover*400/pos[1]),390+i*40,600);
% T$ w4 k% i/ @fillrectangle(650+i*40,600-(int)(inf.wait*400/pos[2]),690+i*40,600);; t* x5 t5 v& I. m; V% H4 u
fillrectangle(950+i*40,600-(int)(inf.CPU_rate*400/pos[3]),990+i*40,600);
4 W3 p8 z" c& \9 J8 m
9 y5 F- f/ {9 ~% I! J5 @8 K( P8 d8 t Z0 K" r) d/ ^
}
2 i: |1 o; g# V% P outtextxy(100,150,"吞吐量");+ K6 Y8 k0 V0 `
outtextxy(350,150,"平均周转时间");, N+ C* o, }" D
outtextxy(650,150,"平均等待时间");
y% l9 `4 W) H% k- x! L5 h% n( Eouttextxy(950,150,"CPU利用率");; y( K/ \0 W" h" u4 F
return 0;- A% |2 a6 t4 M: ]- B
}" R+ c# T! q6 P2 Z# U, C5 l
int MouseListening()
' B! {* {( B( Q' u6 k{
& @4 o# e# C. p5 Y8 U# C/ U+ E# pMOUSEMSG p;
7 p+ E' q/ y# l) aif(MouseHit())
2 ?0 g8 G- @7 c! K' l" X4 z m( g{
# |+ t! u3 x8 ^7 Wp=GetMouseMsg();4 m0 P1 a" m/ K, E
if(p.mkLButton==true)* G% W9 x" \: O6 {: I* I
{
: ]. }2 x- n4 W5 s0 \if(p.x>0 && p.y>0 && p.x<400 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
& i; Q3 S, j# l& |# dFLAG_FIFO = 1;$ U; q: a5 ^- m
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 ?2 y! w" l. s# s8 `1 d6 m- p5 QFLAG_TT = 1;
: F# p) W' c8 d' W* l) ~; p ~9 ~. ~else if(p.x>800 && p.y>0 && p.x<1200 && p.y<325 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)0 V8 D! g ~$ C. P! }8 r+ o
FLAG_PF = 1;
7 m |, `5 a9 Kelse if(p.x>0 && p.y>325 && p.x<400 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)& l6 d0 u5 a. I; E
FLAG_SJF = 1;' ~" C6 s$ R# k# \% N8 v4 I: g3 x3 W. _
else if(p.x>400 && p.y>325 && p.x<800 && p.y<650 && (FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0)
1 h+ O# p% Z( }* M7 n- rFLAG_HR=1;
" y4 s/ T8 D! J. v9 D7 T! s, ?else if(FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO >0)' D4 T# u* O; v
{# P1 O$ J+ s( j9 ]" `+ S) L* D- r
FLAG_HR=FLAG_SJF=FLAG_PF=FLAG_TT=FLAG_FIFO=0;, c* U- _' O% x: a' ?
clearrectangle(800,325,1200,650);
* v- X @6 @0 K}
# @1 R* u! F4 e0 {4 ~, u; Lelse if((FLAG_HR + FLAG_SJF +FLAG_PF + FLAG_TT + FLAG_FIFO) == 0 && p.x>890 && p.y>455 && p.x<1110 && p.y<510 )
/ D2 X+ k h, T M8 M4 C9 \{( X' }# U* I4 O9 k6 F, R1 X3 u: c8 E- P
FLAG_show=0;2 Q$ n5 U( v9 Z+ h
cleardevice();# ^" \ Y' o4 g9 O( O; c/ l
return 1;
* x3 u+ v. r) g% V}% X! G& Y7 Q6 Z" e, |
}
0 z5 G4 m E) E; `}0 j4 t# X; i9 Z X
return 0;
. ^; _5 A8 o% _. l! y}, x( T2 |$ ]) }& Z7 ~! g+ Q: o
int MouseListening2(int *flagShow,int * showTime). U/ w4 }+ E' j: _* {
{
3 c( b+ e! f, a) K( I& S, r6 x& GMOUSEMSG p;
& y/ `0 l1 }- W" Y8 ?rectangle(1150,0,1200,50);
! H* J5 T& Q6 g7 s' Mouttextxy(1160,10,"X");' J6 d' j3 e1 K" H% X! ?; h# M4 ^
while(1)
+ W6 x, F4 w( D* {{
! u! b9 Q' E& Y0 z/ iif(MouseHit())! w, F$ B- k; O' S
{9 J4 g0 g: w( M" s
p=GetMouseMsg();
" `! l3 U% D5 m$ C% G" xif(p.mkLButton==true)
+ g, }4 B3 d) _6 c8 H5 X- Z5 k{8 h L* d/ a# O; y
if(p.x>1150 && p.y>0 && p.x<1200 && p.y<50 )
1 I6 D7 ^( }9 l( i{, D: T# u$ L! s; ] N
(*flagShow) = 0; [* p9 k( |: w- `( J3 R& y
(*showTime) += (*showTime);
9 L) K+ G- r, L0 W) EFLAG_show=1;
* i1 W: k* M: R8 E+ x5 sbreak;
: U- q) I7 N3 Y% i5 h# V v+ s& b}8 d, M4 d! I; F$ ?( T8 M# p! c
9 ?6 s- ~# U* t! f' h7 B& x}5 R* A$ u/ r( H) } G
}6 x1 C8 i8 M) N3 X0 r
Sleep(20);9 U8 U' T( S m* d% _0 ]
}/ m9 p5 @5 e5 z! l, |# U/ r
cleardevice();
: D0 i8 K: S) Vreturn 0;7 n3 N5 |% E1 \2 P$ s, D3 M
}8 B6 Q5 b* j: \5 i
int drawPerformance_FIFO(int x,int y,int memorry,int com,int wai,int cha)8 ^: N% a1 E l3 n/ b' W
{+ F2 \: b" F1 [7 d# a
static int info[11][3],num=0;
; i& j' a$ O3 X" }0 j( w+ fint i=0,j=0,pos[10][3][2];
* X- d. A; [. S" P% b3 ~3 Dfloat temp,t;
7 _3 U2 m4 O, w, H. L& E//画按钮,不属于FIFO图的范围8 M/ {/ ~5 @7 h( y
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0 && FLAG_show==1)
2 R# |1 V4 u$ {2 p{# _3 H4 \8 ?' g3 r
settextstyle(30, 15, _T("楷体"));4 _6 K9 H5 i5 R# X3 ~
rectangle(890,455,1110,510);
7 l- z9 p+ l1 C3 @& Nrectangle(900,465,1100,500);$ }. V0 i! n R1 h
outtextxy(910,468,"查看运行结果");- `& _4 {$ o$ E- n: ^! D
}
5 b J) B j7 R0 o* m//结束画按钮9 i0 J# T# M6 u* X4 ^: A5 R' Z$ b
info[num][0] = com;3 o" N7 P& P% q
info[num][1] = wai;
/ _# [" o3 B- ?# \' R* K% qinfo[num++][2] = cha;7 _5 E3 C; d* t
if(num>10) //存储10个点
: g& F% c) T2 R' k, f# ^! l{
0 o) ` K- c0 _for(i=0 ;i<10;i++)3 ?" @9 L% B) D4 ?& e5 v
{
. r$ K7 v" _0 x) a# b& z$ B1 a* i" _info[0] = info[i+1][0];
Y& r. t- ]( U$ n: R/ f9 ~, zinfo[1] = info[i+1][1];/ L( L; u( j; O! t5 D
info[2] = info[i+1][2]; k2 J* P3 H5 D: Z
}
, [& f# x" K/ f/ n" ?1 B8 ynum--;
1 C R' e$ x3 t8 n}
1 j2 u" ~! ?9 t2 V2 i( jif(FLAG_show==0)
6 f( Z- e' |' l" a. _return 0;8 M5 y6 T( N3 R" S" b7 j) X- V
for(i=0; i<num; i++)
% i1 X* F+ G/ C{+ k+ R% K s: _2 ]/ a# I
t = (float)info[0];' V8 k( d# K/ V: m! B$ z/ w
temp = (t/101)*90;" Y5 T5 k$ R# V+ C9 }6 P3 V
pos[0][0] = (10-num+i)*25+x+100;7 g; y7 K4 y) x
pos[0][1] = y+110-(int)temp;
: M$ \# Y) c2 M a/ g1 t- F, vt = (float)info[1];
, [0 x5 X* |0 R. _6 ^temp = (t/101)*90;# m3 [! ]8 u. R" C8 V, V$ l, X
pos[1][0] = (10-num+i)*25+x+100;1 L* u7 V& M! D0 n
pos[1][1] = y+210-(int)temp;' h+ D; P' J, P$ y& |
t = (float)info[2];2 B' J+ I, O X6 b E
temp = (t/101)*90;& X+ E; l; `5 m# g
pos[2][0] = (10-num+i)*25+x+100;
1 t Y/ c- @0 d" R& R4 Rpos[2][1] = y+310-(int)temp;
6 ?! ^; |0 Y$ m( D1 g}' k6 O, G! r/ L! X5 } ]; u
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
: e8 g8 U* I3 i! r) a{
4 \' U0 K+ q+ H+ b' _* \" cclearrectangle(x,y,x+400,y+315);0 s/ Q, ?* E) p
settextstyle(20, 10, _T("楷体"));
+ T! w3 o Y: Z4 b& wrectangle(x,y,x+400,y+325);
. R6 \3 o0 q" Pouttextxy(x+40,y+10,"CPU"); //画柱状图
/ K ~% z% A( W8 nouttextxy(x+45,y+10+100,"IO");
+ Y2 }0 k9 a! {! Q" U" \, {3 P" eouttextxy(x+40-15,y+10+200,"change");$ O- n' L1 q8 @0 @& c
rectangle(x+35,y+30,x+75,y+110);, _4 k8 P4 p# U/ F0 _* H
rectangle(x+35,y+130,x+75,y+210);$ E/ _. \( i7 S- v
rectangle(x+35,y+230,x+75,y+310);$ K* U( ~. a% F9 J3 q
outtextxy(x+180,y+310,"FCFS");
5 U4 j* I# F8 g8 E; G ~! Q ut = (float)com;
9 o W5 T) A, k1 g1 Y" U6 Etemp=(t/101)*80;+ I8 F1 e$ A) N/ g7 o* m
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
9 e2 O% v/ F3 r/ k9 y( Pt = (float)wai;) O0 g; C4 _ V6 w$ Z% U" v+ Q
temp=(t/101)*80;5 D8 G# A) X2 X2 }! k) C' g5 N
fillrectangle(x+35,y+210-(int)temp,x+75,y+210);% S2 G1 N" j7 D1 \
t = (float)cha;
$ e1 ~* h' l( |7 v! b. c% jtemp=(t/101)*80;
6 h) C1 O; S; z! d Z$ lfillrectangle(x+35,y+310-(int)temp,x+75,y+310);: A' r* {& @, P4 o2 s
for(i=0; i<3; i++) //画坐标 high=90,length=250
, c3 f9 I% d4 l! g: ~{. B! d$ ~* W# x& c4 s5 y, S0 ?
line(x+100,y+110+100*i,x+350,y+110+100*i);
! e$ D3 |0 i) Z/ b. F& z. Iline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
, g; {7 B6 H- k* a3 ?; w9 cline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
' Q) q U* _$ m Q3 @2 E9 s \" p0 J: ]1 u' N, j3 c
line(x+100,y+110+100*i,x+100,y+20+100*i);
8 u! V8 U6 c& [% Vline(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
! e( C3 M( j2 Nline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
, P* v6 l. X; l# yfor(j=0;j<num-1;j++)
! x2 {, S! G# x; C{
. M& G# @+ I" i* n5 A5 R1 \9 |( gline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);9 {8 H, @# L A: {' s p
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);* h9 F, U: r3 B7 T; I0 F
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 0 f9 b- \0 @* }# P2 J* T
}
2 L$ c5 O5 x$ X1 j; m# M}
: I3 M# J9 a+ C1 Y$ p1 s}) L3 R3 M! V- \& x
else if(FLAG_FIFO==1)
7 B% l' U/ Y/ z+ q# e" A6 t S2 c{
5 t8 X2 E% S! U- S gx=0,y=0;/ F- L& K+ |0 f4 m9 {7 D! Q8 l
for(i=0; i<num; i++)7 H4 U& G* L, b1 W
{
: C( s) C$ |, Yt = (float)info[0];5 f$ K: x" d. I, N3 ]0 j( P
temp = (t/101)*180;1 _. H7 ? o1 T4 Y5 C4 q
pos[0][0] = (10-num+i)*50+x+650;5 T) ^: E. W9 J
pos[0][1] = y+210-(int)temp;
- I% j& s, V) x1 b4 {t = (float)info[1];
9 G9 B! j1 p+ `; |7 j5 f$ Atemp = (t/101)*180;; y( j Z8 P7 W+ G5 l+ y6 W) }
pos[1][0] = (10-num+i)*50+x+650;
8 F* A8 R' p+ U, zpos[1][1] = y+420-(int)temp;
! x. I7 N7 K+ F+ dt = (float)info[2];" ^3 \! `+ q% F1 a
temp = (float)(t/101)*180;
5 W2 O" A: |5 [, l; I1 Jpos[2][0] = (10-num+i)*50+x+650;
) |. g( v) O* x$ ~' g0 B4 bpos[2][1] = y+630-(int)temp;
* M7 S$ G. h; \! e2 H$ G+ b}( Q5 P: P2 w Z* E* _3 h) D
clearrectangle(x,y,x+1200,y+650);% o' q' E9 ?2 e- c0 A; j' [5 r
settextstyle(40, 20, _T("楷体"));
( e3 T' u# ?$ l; ?) B$ F! u) ?outtextxy(x+50,y+50,"FCFS");: _+ ?8 T$ z7 g0 J* v
outtextxy(x+280,y+20,"CPU"); //画柱状图: a4 G* f, B6 }4 I0 ]; H$ i
outtextxy(x+285,y+20+200,"IO");
; H1 U0 `+ f# K) T1 r0 Q: Houttextxy(x+250,y+20+400,"change");
0 Q1 I, Z2 I% j/ r( l! wrectangle(x+270,y+65,x+330,y+215);
7 ?9 ^1 S- ?% P9 e* Qrectangle(x+270,y+265,x+330,y+415);
0 }! Q8 ]9 ~: o! D5 crectangle(x+270,y+465,x+330,y+615);
( P2 _: E( {. nouttextxy(x+290,y+620,"TT");( E; q) m3 q0 R/ j1 S- J2 v; \
t = (float)com;6 Y6 B ]' i$ k. _' b; {
temp=(t/101)*150;
& u* E: p5 X" m" |0 Z/ qfillrectangle(x+270,y+215-(int)temp,x+330,y+215);$ |8 _" N& I% `4 p" C" E! Z" c( A
t = (float)wai;
$ a3 G6 c& _1 t( Ntemp=(t/101)*150;1 l1 t# z- j- G1 E; e3 Z+ _3 M8 }
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);' q' x" l, S5 g8 `2 ]) n: E
t = (float)cha;
- o4 O2 a! y# s: a2 f9 k4 Ztemp=(t/101)*150;" \8 b( x, W5 k! z/ y4 v( w
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
0 p3 y( B% i- C9 A) |/ S8 efor(i=0; i<3; i++) //画坐标 high=90,length=2509 X! w% ^4 ~" L2 o3 S* C2 V* b
{
- U8 C; K) E4 _8 Gline(x+650,y+210+210*i,x+1150,y+210+210*i);. d* k3 y3 j0 L9 I
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);- _8 L# J \9 l' b
line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
+ @7 m$ q# ]6 P0 c" G7 s0 k) q# j: x$ i: s8 t- p R; [5 ~
line(x+650,y+210+210*i,x+650,y+20+210*i);
# N8 J1 X! ]# Hline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);( U v! _* X7 c
line(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
! g' Q# G8 R- W, p+ m% R7 jfor(j=0;j<num-1;j++)
; J4 l8 C- E# X6 [2 j/ W{: N7 ?! Z6 Z$ M3 p% W8 d
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
- v/ g! H9 Q/ F5 \+ ~* F8 P5 Eline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
, x6 W Y8 y r7 u$ J/ Bline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 2 S, R% D1 J% X2 N9 H
}& @. K; X, S/ @1 a# `: C( Z
}
4 o1 z i& R7 D" q9 q( C}# _- B8 V' B r# \3 L- v/ K0 U
7 x) f& A+ ~- v* b
, S o, }( n, T+ Q, ^return 0;. R' U5 {4 V( C- v; U! ]
}
% r* R. L7 O2 I( r1 \) Kint drawPerformance_HR(int x,int y,int memorry,int com,int wai,int cha)
0 L6 W* F; t6 @+ E7 |9 S/ g2 C: \{
3 m5 B; X" S5 R; g; n2 cstatic int info[11][3],num=0;' t9 ?9 r- S( r3 A: T1 _" R' o: I4 C
int i=0,j=0,pos[10][3][2];
R1 I6 x$ r# ffloat temp,t;
+ j. z- @- l: p0 Linfo[num][0] = com;: g( f- L! U2 I1 s7 u
info[num][1] = wai;+ Z/ V6 }9 a' v1 M
info[num++][2] = cha;- c! D8 B: Y5 \$ e- Y
if(num>10) //存储10个点
0 E6 i/ n& O! N0 i{
. e; u% p; d6 {6 Z% H Cfor(i=0 ;i<10;i++)# `6 [4 R" Q! t! w/ ]7 ?+ E
{
7 _! l+ P6 e& |. L* @+ b) winfo[0] = info[i+1][0];
+ I# f, d; | r8 d0 `info[1] = info[i+1][1];
/ r# Y% F ?6 j" C: kinfo[2] = info[i+1][2];
/ P& e9 B. B" @6 X/ n}8 y. C$ k5 H1 [3 p
num--;2 T2 ~: A' F7 c& n: Q. q9 d
}, y% V9 f+ A- F
if(FLAG_show==0)5 [3 N! Y! ^$ ~! ^
return 0;
* U3 @4 o) E% H8 Gfor(i=0; i<num; i++)
[( c2 c3 l& H! a{: r7 P0 ^5 \* I) W0 j0 E6 e
t = (float)info[0];+ @7 w8 w# u$ [. }
temp = (t/101)*90;
7 Q7 k) D+ ]3 \6 t* Jpos[0][0] = (10-num+i)*25+x+100;5 m) b* N+ a! O2 M3 \
pos[0][1] = y+110-(int)temp;
' b4 T* [& w4 E. r' e' {+ G0 i! f0 Kt = (float)info[1];
% Z4 i' p9 @. N- Y- u/ ]/ _$ Ftemp = (t/101)*90;8 O/ D L0 R2 K" Z
pos[1][0] = (10-num+i)*25+x+100;
2 v! \/ _* w' g, O, xpos[1][1] = y+210-(int)temp;* N; r: C: V$ b5 C( V6 Q/ ~( r! x
t = (float)info[2];
$ t5 E0 B) Y/ Itemp = (float)(t/101)*90;% |, q5 d+ k) V& v0 s8 q# k2 {! A4 z
pos[2][0] = (10-num+i)*25+x+100;& M/ `+ Z4 H& G2 r( ~: b
pos[2][1] = y+310-(int)temp;, u% a y0 @4 a( `8 t- C+ |
}; e. x2 F/ u( _ v0 G
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
h3 W8 c/ Y h3 P{
* ?* ]+ Z, r5 l1 C) g% lclearrectangle(x,y,x+400,y+315);
5 u( e% p3 u9 A' ~1 V, |settextstyle(20, 10, _T("楷体"));. k# F ?+ G8 ^) O. \# i3 Y) g/ W& g
rectangle(x,y,x+400,y+325);
1 a0 h. {/ n$ E2 }outtextxy(x+40,y+10,"CPU"); //画柱状图
3 n `# l: @* w9 l" Eouttextxy(x+45,y+10+100,"IO");- m! G J1 k- b% a
outtextxy(x+40-15,y+10+200,"change");
4 _4 d' J4 D( O; Zrectangle(x+35,y+30,x+75,y+110);
9 [6 h [; {7 m* ~rectangle(x+35,y+130,x+75,y+210);: j3 P: ^$ E; q/ y) n
rectangle(x+35,y+230,x+75,y+310);
( D1 s7 F' v3 [# }: c4 `, Q( zouttextxy(x+180,y+310,"HR");) V# D) a- L- K) K8 L) k
t = (float)com;* @% r" O5 _+ u3 |5 n
temp=(t/101)*80;
5 ]% p% l0 w6 z1 a; }fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
- d; g. I9 [! q8 K5 At = (float)wai;
: A4 O Q' O1 p: G( ytemp=(t/101)*80;0 b& x* t2 g D" x$ D
fillrectangle(x+35,y+210-(int)temp,x+75,y+210); Z% W; [3 K4 }' w/ `
t = (float)cha;
. D7 [7 M& z4 k* jtemp=(t/101)*80;
8 g3 U, M$ k0 }6 K9 g7 vfillrectangle(x+35,y+310-(int)temp,x+75,y+310);
; b3 L7 \) q, mfor(i=0; i<3; i++) //画坐标 high=90,length=250
$ X1 \3 z" b$ E) J6 _2 J e{
! M7 x$ G! I1 A- U) f4 J& H" {! x* Sline(x+100,y+110+100*i,x+350,y+110+100*i);* s. a z3 w$ P# k
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
' z0 U4 F% k: j8 Wline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);' t+ y' h2 ?+ [, A" o
4 i* N, m! g) n$ n, z# R& T) k
line(x+100,y+110+100*i,x+100,y+20+100*i);$ W: z& s. I. u7 g) |( I) T" L1 k
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
# [2 [! }! C! Fline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
; g) O; d. P5 S/ E( Zfor(j=0;j<num-1;j++)9 h) O* a- |- d3 I
{6 o; s [8 a. ^' `( B; v
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
, {1 l& ?( q# t7 W; `line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
/ M( \- T) l h; ]# g: |- Iline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); ( q ]: {: R/ ?, T
}" i3 x# O; Q( l& K4 u6 e, m! E9 _
}9 R5 G; i! O3 d+ a- T# I
}
' \" T* J- v* o/ E" Celse if(FLAG_HR==1)
( z0 o9 K" J2 c& _8 \/ b9 K{
& K8 ]9 o8 Z% Ex=0,y=0;, Q$ t4 {" D% A" P
for(i=0; i<num; i++)
4 H( z: a8 r; y, W{
$ {; ^$ Y7 H% P- Y4 ~t = (float)info[0]; U; Z' x5 P* j% W" P6 M
temp = (t/101)*180;
% o/ ^) L L( f4 t {pos[0][0] = (10-num+i)*50+x+650;4 I; x8 `/ t3 o& F6 d/ h
pos[0][1] = y+210-(int)temp;" Q( [- c9 q9 o
t = (float)info[1];5 k' B2 p) A+ H7 u V- @
temp = (t/101)*180;4 h" z, ^! ^6 @6 J7 L6 a
pos[1][0] = (10-num+i)*50+x+650;) d# T* G: E* Y
pos[1][1] = y+420-(int)temp;( n% m% X& q& [/ C0 t% R
t = (float)info[2];
; w6 \% A- x0 etemp = (float)(t/101)*180;
- ]' Z) @% y1 Q( hpos[2][0] = (10-num+i)*50+x+650;! p, H" b6 x/ f
pos[2][1] = y+630-(int)temp;6 m) ^& t, I- `- y& p9 R
}
! F) s: Q6 x7 Y/ {% a9 {4 \0 f- Qclearrectangle(x,y,x+1200,y+650);% ~: e! u) Z' A
settextstyle(40, 20, _T("楷体"));
8 Z* N# a0 l. Houttextxy(x+50,y+50,"HR");0 L0 D( Z1 G. J$ N. X
outtextxy(x+280,y+20,"CPU"); //画柱状图! v4 L( t3 K5 {# [, q
outtextxy(x+285,y+20+200,"IO");# v D+ Z1 z) U* C) N) v4 d- @
outtextxy(x+250,y+20+400,"change");
1 H8 u; H/ V# e+ f4 e$ E" _' C( h+ Erectangle(x+270,y+65,x+330,y+215);* I+ ?+ y' r. E4 W5 I
rectangle(x+270,y+265,x+330,y+415);
. [3 X' m# o5 ^' Lrectangle(x+270,y+465,x+330,y+615);9 g7 \! g; T( Q: j1 U
outtextxy(x+290,y+620,"TT");8 I+ F# ~6 O: d( H1 w4 N
t = (float)com;
+ i$ z1 @/ q1 `. O3 L, B9 U2 Dtemp=(t/101)*150;2 p8 G) R0 {$ S: ?3 k5 ?$ [" Y
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
6 A }( t q% W6 x0 g% bt = (float)wai;, ^! K( C# f6 a5 l; z! H7 f# \+ A
temp=(t/101)*150;
G# M1 Y2 w. e" y' V6 e/ H3 zfillrectangle(x+270,y+415-(int)temp,x+330,y+415);- V' M; u& I3 {% N8 s/ t+ G9 d5 P; I
t = (float)cha;
0 @, S, E# D" P! Ptemp=(t/101)*150;
# o9 K6 u7 Y, _7 j1 R/ `) ffillrectangle(x+270,y+615-(int)temp,x+330,y+615);4 ?% ?; D9 S) d; O: V$ E7 a
for(i=0; i<3; i++) //画坐标 high=90,length=250
0 W2 g4 j: q! Q& p/ V* U: u{
2 Y$ E% w; q( @2 O; m( h' I2 h3 zline(x+650,y+210+210*i,x+1150,y+210+210*i);
. \: J$ q9 B) j/ uline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
/ j! \0 k0 ?* E" Oline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
# q0 y( j5 N) P2 s/ V) l1 R2 F( T+ V' V; ]) y. I
line(x+650,y+210+210*i,x+650,y+20+210*i);6 k3 g& |: K; v* _) m, k
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
9 C9 S0 B) ]! `# m+ V/ s' x+ V! Yline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
1 h6 Y+ ?' B7 y* c7 Y5 Afor(j=0;j<num-1;j++)! c% F, r* X7 W K& U3 w
{
?, ?8 S! A6 `+ Z2 F0 Qline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);& U6 I6 O9 u5 R
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
0 g+ I7 T# F d9 k; ^line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); 9 z7 F# P! K$ H
}9 u. q4 |2 V4 x9 o: D3 v5 R
}7 _) s+ h, y2 [, P" d. {+ b# C, v
}
& A: X/ X; E0 L7 k! Q, w! h' G5 f% @( B2 ?( }: v3 B3 [
7 w. L* Z( o5 ?1 J W9 Qreturn 0;/ r& L6 c7 b- V; y
}7 c* v+ m: K# q$ n' V ]
int drawPerformance_TT(int x,int y,int memorry,int com,int wai,int cha)
7 q3 Y2 W/ x! k7 a" C{) y3 ^: h+ D& M3 A" @6 h5 m6 \$ K
static int info[11][3],num=0;
2 e' v, l! j ^( Cint i=0,j=0,pos[10][3][2];' P" ~( ]0 `/ v
float temp,t;
5 u/ N# {" Q% ?' I2 }. m9 ?info[num][0] = com;
- g# Q3 w4 |# oinfo[num][1] = wai;* h4 a g- x) S8 @" [
info[num++][2] = cha;
+ p) o& L1 V ]5 T$ xif(num>10) //存储10个点
& r0 Q: I! H: f0 a0 ?2 z- |- A+ {$ f{
& @: k& {# ~, \' q# {8 U9 c Dfor(i=0 ;i<10;i++)
1 f+ `5 ~( N; X7 T{
2 x# j: H' ~. ]" E% @" Ainfo[0] = info[i+1][0];
. N) |9 {' I9 @9 m* Cinfo[1] = info[i+1][1];
$ A/ V! _* u* U- U3 hinfo[2] = info[i+1][2];
1 }& C$ O5 k% u& O}6 @: Z% E/ q) h) i- H. q# f. W
num--;
0 d% g" `+ O% d3 v, }% j}
7 q1 Q( T J5 ?0 uif(FLAG_show==0)
# M8 G% x% _5 g1 R& zreturn 0;
; N1 p& q. \4 ofor(i=0; i<num; i++)
- v1 b% s( ~5 u{% Y5 C* Y! T( r* s3 U
t = (float)info[0];1 O" x& l" H6 [& }
temp = (t/101)*90;
2 @' P) v* p2 ?0 q7 Wpos[0][0] = (10-num+i)*25+x+100;* \% G4 L) L0 o# V$ H; _5 M7 b6 Z
pos[0][1] = y+110-(int)temp;
" n8 i9 f9 x' X) r: j; Z7 [# _t = (float)info[1];: h- ?$ b: K8 K
temp = (t/101)*90;
& ~8 A: M! v- fpos[1][0] = (10-num+i)*25+x+100;/ }" h! j$ B& H3 s, E# D, ^! p
pos[1][1] = y+210-(int)temp;
/ J/ [: ?7 `+ y J& k/ d/ Vt = (float)info[2];0 Q3 }" ^2 f( b% _0 ~8 o- l
temp = (float)(t/101)*90;
" m6 \1 L8 ]1 P7 T8 spos[2][0] = (10-num+i)*25+x+100; Q6 m, F* @" W4 h2 T9 z# ?
pos[2][1] = y+310-(int)temp;
7 Q' E: y0 |4 u- \2 O}4 K) \! v* m% t- N& e4 ?
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)' x W/ d9 B& Y" j
{
1 W2 Z" t" l. R& E: O1 s7 \clearrectangle(x,y,x+400,y+315);, C; U: Y& `% m
settextstyle(20, 10, _T("楷体"));' C' n5 c" A) f+ q( }1 x
rectangle(x,y,x+400,y+325);
% f$ X- E9 m' g; Mouttextxy(x+40,y+10,"CPU"); //画柱状图: E( a' t* B5 r4 Y1 N
outtextxy(x+45,y+10+100,"IO");
/ h, h8 X( p( k$ m, V7 `& |outtextxy(x+40-15,y+10+200,"change");
" H' P: H f' B3 X* yrectangle(x+35,y+30,x+75,y+110);# E) ~9 \; [. {, T3 p
rectangle(x+35,y+130,x+75,y+210);
5 D9 A4 k9 {. }$ J0 drectangle(x+35,y+230,x+75,y+310);* @% f0 V/ j# v; F8 c# }
outtextxy(x+180,y+310,"TT");' a) n0 u: n4 I$ ^( g2 [7 S
t = (float)com;
- K0 a, U! } w: f" ^temp=(t/101)*80;" m7 c0 D# U% U8 n6 i
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
- m& }# a; V$ k; @5 N! p; v. ?t = (float)wai;1 j0 m/ [" ?( C& ?. X3 V
temp=(t/101)*80;
2 i! B; b+ {$ ^( K' Lfillrectangle(x+35,y+210-(int)temp,x+75,y+210);( x4 ~. s+ \# c% n2 I7 C6 k
t = (float)cha;) Q9 t, f9 U6 o5 T5 }
temp=(t/101)*80;
, S' Z! b. T( {- \. Dfillrectangle(x+35,y+310-(int)temp,x+75,y+310);" H* R( r1 U0 R Q2 q
for(i=0; i<3; i++) //画坐标 high=90,length=250 n2 ]% r3 x) |/ o7 ^ D
{
; c# `& M5 g0 p: p4 T, mline(x+100,y+110+100*i,x+350,y+110+100*i); L& d( O* J# g( ?( a
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);0 U& w; H) C; N0 P3 u, q0 J4 M U
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
1 x4 X, }0 O7 A1 W1 M, G
4 h% I6 u( z! K. oline(x+100,y+110+100*i,x+100,y+20+100*i);0 T g! r0 B8 I5 T- l
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);9 Y. K; M$ w. q0 [+ K9 a
line(x+100,y+20+100*i,x+100+5,y+20+5+100*i);6 k4 Y) W4 H% \6 ?1 l8 o0 l
for(j=0;j<num-1;j++)
|6 Z' u6 N& T{
/ i% [; \# Z/ Kline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
6 k: ]0 |0 q8 Y- ^line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
8 u' }! T2 ^- t; E* Oline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); " }6 w4 T' y, a8 o2 }( Y
}: K5 {1 S4 E6 h/ O J' Y5 f
}5 {4 ~$ F. t6 T/ G0 T$ D
}
+ R! x8 w ~; M/ \# Q" Eelse if(FLAG_TT==1)
- m1 m! }9 w! v{8 p& j( n9 W7 X0 ]. F2 j
x=0,y=0;
+ c* s! v( _& q1 g! s h- b+ ufor(i=0; i<num; i++)
/ B1 ^& O1 p! B' a) v4 \{1 S- Q/ n! E; U% Y" U9 y! Y2 J
t = (float)info[0]; N( U) }& @/ T+ R! b- S
temp = (t/101)*180;% \3 u, Q F% x+ |
pos[0][0] = (10-num+i)*50+x+650;
3 a3 T) ], v( K+ p/ h: U: Lpos[0][1] = y+210-(int)temp;+ Q; H1 ], V" r3 n
t = (float)info[1];( v- V: e6 h( l: h- D9 K
temp = (t/101)*180;$ J$ `) w) i+ ]2 t
pos[1][0] = (10-num+i)*50+x+650;
$ P1 K# Y t4 C6 bpos[1][1] = y+420-(int)temp;
* l6 H8 z6 s8 G! J- n# |t = (float)info[2];
( K+ d" O4 g1 [* l4 Z7 r3 L) r" \$ r' Btemp = (float)(t/101)*180;
# @$ ]/ e* ?( _. K6 P1 W6 Spos[2][0] = (10-num+i)*50+x+650;& G6 x7 J" H7 }/ l8 E
pos[2][1] = y+630-(int)temp;
* Y1 x6 S* j5 {" Q3 c}
( v+ z! W B, ?9 eclearrectangle(x,y,x+1200,y+650);
* h& l1 ~6 ^1 ^: j3 }& \3 @( j) x: i! ysettextstyle(40, 20, _T("楷体"));' r2 u* i( w+ a
outtextxy(x+50,y+50,"TT");
# ^- n" x, q- |; w8 Y9 Fouttextxy(x+280,y+20,"CPU"); //画柱状图& P. M+ v, e; Y+ e( _
outtextxy(x+285,y+20+200,"IO");
! J- n s5 }" }$ z! Fouttextxy(x+250,y+20+400,"change");
6 U! { z$ w! Z+ {& \rectangle(x+270,y+65,x+330,y+215);
# ?! s4 G5 E0 krectangle(x+270,y+265,x+330,y+415);. y o) |: ^0 S+ J% j: T+ E
rectangle(x+270,y+465,x+330,y+615);+ w# E6 U. p. Z2 z$ e
outtextxy(x+290,y+620,"TT");
; ~- R- U9 j8 _: \, j" Ut = (float)com;
' [) W$ h1 n8 L g$ o+ S" y3 Jtemp=(t/101)*150;1 I1 E/ e. ~5 t+ H, K
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
, Y+ f/ D) ?) |( e" nt = (float)wai;
7 M% F t* ^# r; \3 P! etemp=(t/101)*150;+ |) T* V: E$ V4 t
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);$ d' e/ j2 ?3 V% A0 K$ a% C
t = (float)cha;
, Y- D& ^- X& d T( Z( ]temp=(t/101)*150; d) K6 v' _: s! e7 M6 h
fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
2 k9 X0 a7 t @" P# l' V# Afor(i=0; i<3; i++) //画坐标 high=90,length=250, ^' I# s# t% y, v
{7 i" _' X! _5 u9 ]( \2 l0 B5 L
line(x+650,y+210+210*i,x+1150,y+210+210*i);9 c n) a& y! k" U
line(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
F3 h3 s. a! _line(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
9 |6 s/ H/ ~* K5 s, A1 w6 j: I9 P! `7 M) S; n3 R7 G) Y
line(x+650,y+210+210*i,x+650,y+20+210*i);8 g: J; l. V9 J# R. ?
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
/ _+ M) d% K0 u- ~* ?$ Jline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);3 _% c7 ?$ A, {* u: C/ x
for(j=0;j<num-1;j++)
% I' ~( v) @. t{9 V, B, o) j4 ^3 `( r+ P6 S# X+ i+ c
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);- y- m2 G; S1 Z5 s+ k, h/ F! D) Q
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
3 ^: m0 m: D* L) I" J7 v) Bline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
, Q- A. C; }) Z; k- s8 b}5 S# X8 [" g$ S9 q" P5 v0 F% d5 v
}
: n: Y- q$ b3 }- v% o9 `}
; y4 m& N x& a6 v9 X' B" e$ n9 y5 j) _5 H
- l+ [' B8 F' P" nreturn 0;7 @0 n7 }) n7 m7 r# z3 Q: k
}
4 x4 h* J4 w5 I$ i# u! Pint drawPerformance_PF(int x,int y,int memorry,int com,int wai,int cha)" u% P" w- W% s& h1 y" ^
{* o! o& _1 A. u
static int info[11][3],num=0;8 L e/ W2 P3 B; ?$ H) q5 x& n3 Z
int i=0,j=0,pos[10][3][2];! R x0 ^- U, f. ?/ H
float temp,t;5 B8 i- S; \8 s+ v' n: z
info[num][0] = com;
, K1 E2 K4 Y5 F: g2 d! ]info[num][1] = wai;
! p+ V5 z" p5 N0 _+ K$ ]+ Iinfo[num++][2] = cha;8 s# }! c9 T0 Z; w- n2 @
if(num>10) //存储10个点) E/ Q6 y9 S) Q- S& Y
{( F7 [# h5 u6 x+ z7 a, r, a3 L
for(i=0 ;i<10;i++)0 X" S6 G8 A: ?$ f
{7 x9 k! M$ B) q
info[0] = info[i+1][0];
5 ?- I" {9 y8 @7 ]! z! l( d/ E; ainfo[1] = info[i+1][1];
9 {8 H( j3 a b$ x1 ^4 yinfo[2] = info[i+1][2];. c# y3 n2 L9 t
}' r) X. [! R5 D+ B! v
num--;9 e& @- p! x! d2 j% s0 Q
}# t: N9 C( C( H& r4 e8 u% Z
if(FLAG_show==0)* }; ~% w# J% S% V3 F P9 {
return 0;
- v( O. \ J S: V, zfor(i=0; i<num; i++)
, Q( Z' f5 b+ U' N Q{6 ~0 I2 L- l8 C' Z
t = (float)info[0];5 h5 P8 m' P& ^ r+ ^% e
temp = (t/101)*90;
6 h5 g8 \- g* jpos[0][0] = (10-num+i)*25+x+100;! [! l5 u2 z& {# }+ E
pos[0][1] = y+110-(int)temp;' Y) g6 \3 k. h
t = (float)info[1];% S+ I( N9 K* U d8 B" M; V+ F
temp = (t/101)*90;
. Y3 D2 J4 e4 a6 a/ xpos[1][0] = (10-num+i)*25+x+100;
+ E2 l7 \ X& u6 R9 {; ?( o# w2 u9 lpos[1][1] = y+210-(int)temp;
" P! n* F$ b. p# @# }; J: m$ Ot = (float)info[2];
, C; G* I% V0 Otemp = (float)(t/101)*90;+ K5 G$ Q- H5 b* K! ]& K1 t
pos[2][0] = (10-num+i)*25+x+100;- @, X. a+ s( e7 N: R+ }
pos[2][1] = y+310-(int)temp;
! l" `( ?' ]8 |" }}
4 g8 P7 ~. S; O( F5 }if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
4 U* B4 r8 x( h7 O/ {4 D# q, [{
# @) q- w# J2 U. F6 iclearrectangle(x,y,x+400,y+315);
. X& N" w: O1 I) |5 n1 X8 H/ esettextstyle(20, 10, _T("楷体"));
8 m) B* C7 O5 @4 e! o" k/ l4 irectangle(x,y,x+400,y+325);
$ l0 Y. `9 F7 P0 \- t, ]# Touttextxy(x+40,y+10,"CPU"); //画柱状图
; `2 s. |+ q$ oouttextxy(x+45,y+10+100,"IO");: x) I, o! L# u( @8 Q' P& Q! x* g
outtextxy(x+40-15,y+10+200,"change");
! j# x6 L/ x. ~$ H& \rectangle(x+35,y+30,x+75,y+110);
/ x( G1 S' t P9 Z5 G0 H$ frectangle(x+35,y+130,x+75,y+210);
j1 O+ t0 K0 I; U) N+ Y, v1 Irectangle(x+35,y+230,x+75,y+310);
. m8 i9 C# X$ x# i6 Aouttextxy(x+180,y+310,"PF");8 E: d+ ]1 H3 G% z7 P
t = (float)com;
# v* V$ T7 k! u' E: v; ^temp=(t/101)*80;7 N% d5 g4 |& v& W
fillrectangle(x+35,y+110-(int)temp,x+75,y+110);- o3 @/ V% T' e0 v
t = (float)wai;
6 Y( Q' l% X2 @) |5 b1 f) Qtemp=(t/101)*80;
* {5 ~5 A+ k% {7 l; {& P; A. d% Wfillrectangle(x+35,y+210-(int)temp,x+75,y+210);' z8 N: X+ J. F& W* K! z4 K
t = (float)cha;
6 t3 N1 Q! E- |) a& _temp=(t/101)*80;, K3 e5 [! l( C6 m- U7 E- ?$ N
fillrectangle(x+35,y+310-(int)temp,x+75,y+310);
4 i& x+ U6 J5 u. r+ Afor(i=0; i<3; i++) //画坐标 high=90,length=2505 }3 E; R* `! N: b
{8 \# @4 f$ g2 S$ t: B2 C
line(x+100,y+110+100*i,x+350,y+110+100*i);
; ~6 m8 i, d5 ?3 uline(x+350,y+110+100*i,x+350-5,y+110-5+100*i);& E' G# S0 V* y3 \* C2 b
line(x+350,y+110+100*i,x+350-5,y+110+5+100*i);: _8 a T# G+ O4 i2 g
8 C" h5 e+ T7 x& g- B4 {line(x+100,y+110+100*i,x+100,y+20+100*i);' P3 [ X$ A# {" |! f5 d
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
4 a6 p3 ~5 q6 \7 s- R! j0 L( n/ W5 Kline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);7 I. _! u- ?4 z- d! T' L0 V
for(j=0;j<num-1;j++). C/ C: P7 J* K: h: {
{
& b1 G* b+ h! |( Fline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
8 L6 [7 }' U7 u% X- {line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
; J9 g% j' w' V+ I7 {( R6 oline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
) T1 M& ?: y* D, z, C, Z6 J}
) a7 \- ?- c. y4 m}
( x( _' W' r& w. Y; f}( W" ^: S- a& c( {( `% K- x
else if(FLAG_PF==1)
, M. u% a5 W5 R d{
) _. |/ r' ^$ X$ B# p0 r* }; U) bx=0,y=0;
4 z0 H! W. @0 i$ ^ u% Jfor(i=0; i<num; i++)
! O( J5 W& X, S{
) ^2 G2 W3 [/ ^t = (float)info[0];
5 k: W( d3 v' d9 f4 Atemp = (t/101)*180;7 z$ J r/ c. \# M4 s7 o
pos[0][0] = (10-num+i)*50+x+650;
5 E( \( H7 U. Y; Z8 h8 T+ gpos[0][1] = y+210-(int)temp;4 ^' ^4 O: L" N' M5 t* s& _! A5 E, A) D
t = (float)info[1];
4 y w( k" \7 X5 N4 w7 P& @) m! |temp = (t/101)*180;
1 J R; [8 F. U" Fpos[1][0] = (10-num+i)*50+x+650;
' ~! @& `6 H: _9 q$ lpos[1][1] = y+420-(int)temp;
t& u7 r) H ~. f3 X; o/ ?t = (float)info[2];- k7 p% }8 Y- p* ?: W: c
temp = (float)(t/101)*180;
' }0 \$ c: }* C; A& _ _pos[2][0] = (10-num+i)*50+x+650;
3 h" g/ W" g5 V2 P( Y. Upos[2][1] = y+630-(int)temp;
& G# N5 `( z8 |+ M% B: \+ m* g' C1 [5 l}- \9 S6 y0 ?3 b3 f& T6 U
clearrectangle(x,y,x+1200,y+650);/ U* t3 Q: E, k1 d4 z6 x; g' F
settextstyle(40, 20, _T("楷体"));( J7 O9 Y1 k- `. r$ e- O7 W
outtextxy(x+50,y+50,"PF");7 z* T) Z/ A% e/ T1 K/ L7 `
outtextxy(x+280,y+20,"CPU"); //画柱状图
* N% o; q6 u7 h: w5 Eouttextxy(x+285,y+20+200,"IO");
/ A$ z7 k0 T% D) v* v/ Douttextxy(x+250,y+20+400,"change");6 ^4 \8 E) Z, F6 w. G
rectangle(x+270,y+65,x+330,y+215);
6 g) @7 Q; n( h/ X: g4 I5 X7 S- Erectangle(x+270,y+265,x+330,y+415);: ~0 E( ]( c% k' B
rectangle(x+270,y+465,x+330,y+615);3 ^. N1 G: Z( f- X9 w) D5 E k" V
outtextxy(x+290,y+620,"TT");
6 T4 h$ K; L$ o* d0 k# Jt = (float)com;
' Z0 ^; B+ N# {1 F% ?temp=(t/101)*150;
$ N: x6 @% K9 b& u# g Nfillrectangle(x+270,y+215-(int)temp,x+330,y+215);
2 Y# _7 l% n* o# z) xt = (float)wai;
% w% a1 L( N' xtemp=(t/101)*150;4 l6 |( M2 x/ R) R
fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
& k& t: o) v" o# \8 m) }1 f3 dt = (float)cha;% a' F5 ^# g3 O0 s% {3 p
temp=(t/101)*150;
0 g% Q4 S0 }* C; \2 Pfillrectangle(x+270,y+615-(int)temp,x+330,y+615);) J0 {: i8 V, g& ?2 x* y
for(i=0; i<3; i++) //画坐标 high=90,length=250& _: {0 c& A# f& O B. y4 M9 q
{
! E5 k* B+ T# m7 s' Lline(x+650,y+210+210*i,x+1150,y+210+210*i);
+ y+ d0 ?& y, J( gline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
2 v; A. g& j- s# p3 Sline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);* C& I8 R# q0 K' s
4 u* N8 w7 J* w8 V9 a. c1 ^line(x+650,y+210+210*i,x+650,y+20+210*i);
/ b9 n, T9 u$ F7 v( c) y) nline(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
% Z$ R W0 L3 X$ Xline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);: [4 I7 U" y5 x9 B- V
for(j=0;j<num-1;j++)
1 q \! b3 G" T/ u; D* |4 N' j, G) Q{
+ p# o+ ?) r( f* S5 cline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
" f; a( [) X) o& O" N4 v' v& fline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);; v( W: ^6 L( T$ ^$ F# p( T% X$ g$ I
line(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]); % T1 U8 l+ L: C: f Y( Q
}# q3 C' A; s. h3 }8 y
}7 \3 b2 P! f5 D; c# D) v; a
}
D" ], J+ {! }0 v3 T2 r' ]return 0;. O( `5 x5 Y; u8 o0 {* E
}
' R! n( }% W8 F* P# mint drawPerformance_SJF(int x,int y,int memorry,int com,int wai,int cha)
- l, V; }1 C2 `3 t2 z+ p( E{
# Z/ o* h/ E( _5 O, ]static int info[11][3],num=0;
) s% w; v( S4 fint i=0,j=0,pos[10][3][2];! g3 y* f C) u# G ] `
float temp,t;
7 \$ ]/ V2 D, einfo[num][0] = com;& f7 `5 ^# C6 E& Y+ V/ ^7 S$ L+ f: B
info[num][1] = wai;4 v7 R/ {: W' ?# [
info[num++][2] = cha;6 Q$ g" J2 C3 F3 H5 [8 q/ \
if(num>10) //存储10个点; T8 Q2 g5 y1 \6 h; G' h
{
9 V% ^: k2 g* Q& h* e' dfor(i=0 ;i<10;i++)- ^8 E4 h. K( G1 ?& h
{& S3 j I- `6 u5 r
info[0] = info[i+1][0];
. Q/ ?4 n1 Q+ S" f( oinfo[1] = info[i+1][1];# T6 H4 i" W9 Y8 c4 {8 Y6 c
info[2] = info[i+1][2];3 r* n" a1 ?' ?% n; v% e" A3 c
}
) s4 e7 g- g0 h" Lnum--;
8 |2 ^0 F$ H3 @) f$ ?2 ~1 V}
$ @, y) W! d5 E) T0 jif(FLAG_show==0)2 D6 u# h; K0 d( r4 D, W1 a. i4 j2 c
return 0;9 L6 T) J/ W% W
for(i=0; i<num; i++)
2 V' v1 J6 {" p+ i9 d4 w{& f u4 K2 E" V& l T" B+ R' u2 j
t = (float)info[0];" C% K/ A8 K3 T7 D1 v
temp = (t/101)*90;5 w4 _2 i" z9 O/ [* |
pos[0][0] = (10-num+i)*25+x+100;
4 H% ^3 T+ O3 _7 c+ Vpos[0][1] = y+110-(int)temp;
; f& D- K' _) H2 ?$ Q' ?' ft = (float)info[1];
& z8 \/ K- v* S, w1 q1 `temp = (t/101)*90;' N5 @4 z: g" a+ q0 _
pos[1][0] = (10-num+i)*25+x+100;1 L# ^# Q. w5 a+ Y" z
pos[1][1] = y+210-(int)temp;
4 j4 c- ^7 e6 e& N+ ^4 J% f# Pt = (float)info[2];
& G* F" ]3 H4 q6 M ?3 \' ctemp = (float)(t/101)*90;- u; [; F5 `" G8 a) Z5 Z( B
pos[2][0] = (10-num+i)*25+x+100;* x/ @; i% Y' ^1 U8 u. I
pos[2][1] = y+310-(int)temp;- m, ^3 M6 I$ }. a0 m* M
}& Y0 P/ ~# M+ `9 N) K! l& B I; U u
if(FLAG_FIFO+FLAG_HR+FLAG_SJF+FLAG_PF+FLAG_TT==0)
: { X; ?* Y1 ?{ 5 i5 h# N* E+ F& `' S
clearrectangle(x,y,x+400,y+315);1 m1 R3 p( S q" E }- V! O
settextstyle(20, 10, _T("楷体"));2 h) ]( k( I( p1 {1 }9 F* k9 ?$ G
rectangle(x,y,x+400,y+325);2 x- s& b4 e9 Y6 E) Z& ~9 V
outtextxy(x+40,y+10,"CPU"); //画柱状图+ C2 ]+ Y7 x7 }' g
outtextxy(x+45,y+10+100,"IO");( h2 q, Q4 e ?! M: ~4 Z u6 t i
outtextxy(x+40-15,y+10+200,"change");
; S) n/ R! ]( I* Yrectangle(x+35,y+30,x+75,y+110);, ^ X' P$ B9 K4 l, O" ?8 {
rectangle(x+35,y+130,x+75,y+210);
( R3 y( p K. O8 r. v: y! N' Mrectangle(x+35,y+230,x+75,y+310);5 F: X; f& Z0 a5 h; J" b
outtextxy(x+180,y+310,"SJF");! ^& ^8 B4 p0 O' q+ g! m
t = (float)com;
( S1 n, v8 j8 Q' X& F- j5 [temp=(t/101)*80;
( N5 U$ P8 J" `' {fillrectangle(x+35,y+110-(int)temp,x+75,y+110);
u1 s/ P+ F# St = (float)wai;
: D0 ?+ F' ]8 Qtemp=(t/101)*80;
c' [- l/ O+ u# ]5 P9 k5 Zfillrectangle(x+35,y+210-(int)temp,x+75,y+210);
$ N; S' u& }& G% }6 T: n; bt = (float)cha;+ k- ?5 d9 k" l$ T; b! C4 f- @
temp=(t/101)*80;
: _% n H2 x" p7 `+ I4 \( Wfillrectangle(x+35,y+310-(int)temp,x+75,y+310);) G2 K* e7 ?, W% X2 H
for(i=0; i<3; i++) //画坐标 high=90,length=250
, j$ v5 `2 L {{
' _ y8 [! Q3 B* Bline(x+100,y+110+100*i,x+350,y+110+100*i);9 H$ \* Q9 k) G6 a; p
line(x+350,y+110+100*i,x+350-5,y+110-5+100*i);
5 J) p, @4 ?" }* V4 Z; N6 J# F/ yline(x+350,y+110+100*i,x+350-5,y+110+5+100*i);
7 v# H3 h7 p+ ~$ n( ?3 ] G" [6 y4 |
line(x+100,y+110+100*i,x+100,y+20+100*i);. t$ r- F; d$ I' S5 Z
line(x+100,y+20+100*i,x+100-5,y+20+5+100*i);
0 z: K1 H/ ?9 J' L& I' y: Q7 r/ mline(x+100,y+20+100*i,x+100+5,y+20+5+100*i);
" f- I/ k0 v: ifor(j=0;j<num-1;j++)5 O! [0 i7 u5 F
{
8 {2 K, e" o8 u7 dline(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);# D" o% `1 U6 Z; H8 g
line(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
1 \6 D- v9 P0 T9 [& uline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
1 c5 z* N4 J# i, F; J. r- A}& V' ~* Z. C I- z
}; U+ H$ e. e+ w( _7 F
}
! P l8 M$ u8 p6 `else if(FLAG_SJF==1)8 `" F p* z: @. V
{$ r# n$ }' x1 L4 o
x=0,y=0;# n! {, Z# r$ S$ ^$ ]- J
for(i=0; i<num; i++)1 Y- p2 p, v* ]6 @
{, J; u# [" A* L# `! s
t = (float)info[0];
1 l3 f y* b' Q8 Q; xtemp = (t/101)*180;
5 L6 b& X4 n6 n9 Cpos[0][0] = (10-num+i)*50+x+650;# j {. @' ^+ s
pos[0][1] = y+210-(int)temp;2 V1 ?" Q- g9 C+ G; ?+ E
t = (float)info[1];
0 r9 r9 ]% a- r( E. k7 Xtemp = (t/101)*180;2 o# ^$ S1 Q8 t& T
pos[1][0] = (10-num+i)*50+x+650;% B/ I9 }! }: `7 h! D- k* q# P
pos[1][1] = y+420-(int)temp;
, F9 U/ k" c- A3 O% b1 T9 Mt = (float)info[2];( N X" s$ a% x' s1 @8 G% c3 y" j; f! ^
temp = (float)(t/101)*180;7 X3 |; c4 |! ?% k6 o! G6 o" f
pos[2][0] = (10-num+i)*50+x+650;
, B, w% r0 W7 v8 x' P/ spos[2][1] = y+630-(int)temp;0 O3 h( Z8 d) x6 W8 g
}
' v A- M. _& Mclearrectangle(x,y,x+1200,y+650);
' j( {4 F" s/ Y% c1 Q) vsettextstyle(40, 20, _T("楷体"));
8 `- W1 v1 N; i( ^7 b" `/ o+ zouttextxy(x+50,y+50,"SJF");
4 z# [6 @. j+ Uouttextxy(x+280,y+20,"CPU"); //画柱状图5 K9 { t1 ~* l7 R& X
outtextxy(x+285,y+20+200,"IO");
! G5 ]& F1 T/ c, U2 _5 jouttextxy(x+250,y+20+400,"change");
9 U$ W. Z2 [- K( {2 xrectangle(x+270,y+65,x+330,y+215);
4 p+ }4 X5 T+ g( jrectangle(x+270,y+265,x+330,y+415);* u8 D5 k1 s0 h
rectangle(x+270,y+465,x+330,y+615);% A- Y2 \1 X' f
outtextxy(x+290,y+620,"TT");- S% k5 Y' x! o Z: o
t = (float)com;
; d' l, u( ?0 Ktemp=(t/101)*150;9 l2 q5 I& P S
fillrectangle(x+270,y+215-(int)temp,x+330,y+215);
1 {! R: F" u5 \6 T% \t = (float)wai;
# j. P7 e8 r1 o8 w! ]4 [temp=(t/101)*150;
2 S$ m2 B# M$ e# w+ {/ }fillrectangle(x+270,y+415-(int)temp,x+330,y+415);
# s/ S: g* l) T ^! Tt = (float)cha;
% r( q r, R3 b# e+ F7 ctemp=(t/101)*150;
' b$ n% X: }* [fillrectangle(x+270,y+615-(int)temp,x+330,y+615);
3 v! R! s; U. q F$ i5 v, |0 \; Zfor(i=0; i<3; i++) //画坐标 high=90,length=250( v h! e% V5 a$ V o$ s( l
{5 e @& w8 W* H
line(x+650,y+210+210*i,x+1150,y+210+210*i);
+ L% O% M2 q0 u% c# Xline(x+1150,y+210+210*i,x+1150-10,y+210-10+210*i);
( ?7 _0 q+ J2 D0 }2 Q, zline(x+1150,y+210+210*i,x+1150-10,y+210+10+210*i);
( ~( ?4 \* M/ X" }1 p7 r! X3 J: n
0 r W" C4 u* C" q* xline(x+650,y+210+210*i,x+650,y+20+210*i);% t: k, t9 B- ~
line(x+650,y+20+210*i,x+650-10,y+20+10+210*i);
2 E$ O \5 @; Q4 w: m, l8 Eline(x+650,y+20+210*i,x+650+10,y+20+10+210*i);
. d9 N) y, w+ u2 n) J8 D5 q! G! nfor(j=0;j<num-1;j++)
# q8 ]- m4 c, A4 i1 m, r{9 l0 E9 N s* N+ p( r. l& o8 I
line(pos[j][0][0],pos[j][0][1],pos[j+1][0][0],pos[j+1][0][1]);
6 W' ~& {7 H- p* a! uline(pos[j][1][0],pos[j][1][1],pos[j+1][1][0],pos[j+1][1][1]);
# t& j3 O9 @5 ^3 Hline(pos[j][2][0],pos[j][2][1],pos[j+1][2][0],pos[j+1][2][1]);
- r! o' O3 |. A, B}
9 i; j& ^! k' x) ]8 B2 x7 M1 ~) w}
! `1 Y# n$ a6 b$ Y% e}# i- w3 B& V+ ?6 X2 k. t
return 0;9 r d: g8 ]5 a% J
}
$ Y) B& A4 E; m" uint High_response_ratio_dispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)8 K/ r, D. a8 |" {. g% y. B3 [/ L& Z
{
2 R T. l' m; c! J2 Ostatic int compute=0,waitio=0,change=0;8 X. ]0 r0 \" T1 k
static int computeLast=0,waitioLast=0,changeLast=0;
3 E: s6 K; g9 m6 p6 F# dint i=0;
0 w4 c2 Y1 K9 `. G. i8 c. aif(draw==1)
4 v9 }( M) X& x8 a8 [9 K) U$ v$ r" O7 f{
3 B6 D+ i( [0 o. A/ M, E//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
) h9 R8 r! L1 P& @' @; ddrawPerformance_HR(400,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);" N$ ?3 c* \) ?7 g" C" I
computeLast=compute;# Q0 I0 J( ^5 i4 i; {! L, X, z
waitioLast=waitio;' i+ A" K+ s- v# j$ u
changeLast=change;) ?( w9 R) R, E
}, m- J3 Y9 n: C- O. S& _. D0 t
if((* memory).p[0].flag==ready) i1 U |" P" @6 C' _* y
(* memory).p[0].flag=computing;6 S0 Q4 I2 \2 c. U0 I. b4 y
if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
& F; j, z, Q9 {% |; w{5 Z9 @( l0 L; j% a' z9 v5 q
i=(*memory).p[0].computeNum;1 D0 a; N8 [ p: G; }+ @- |0 V' I) `
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed
1 w) h: o6 b, ` f5 `4 ~) U{3 U$ p+ B( ~: S$ d0 g
(*memory).p[0].flag=IO_waiting;
% x6 x7 S, Y0 P3 B4 o(*memory).p[0].computeNum--;# s& V9 n2 I9 s1 x* I( x) u
change += exchange_IO_Compute;
( H$ S( p" \1 J) G3 A6 e8 Xcompute++;7 r0 H8 `/ I7 G. Q( L9 z. u
}, v) }6 \4 `2 u; x# H; y) Q; Y c: I8 n
else
, e. J/ v2 d) E{& o7 _* h& x+ C4 p \3 D* @
compute++;& u5 l; M6 W* g
}( y) T- h3 V# u! Z; e, a
}3 _. Q; M1 j0 u( C
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)9 k# t ~6 _+ ?
{2 @$ {0 J/ H; w0 f& \
* z% [7 P- u0 a- O/ e& t$ a2 Z
i=(*memory).p[0].ioNum;
! S0 o$ X1 S6 I$ j7 f, G% y: qif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed( w3 N; {/ h5 V! R
{/ u8 j3 f4 i- P0 V
(*memory).p[0].flag=computing;
' j% F5 X) C# m4 b& y; o& u0 r8 h. X(*memory).p[0].ioNum--;. L: \: D ~ h; ~* s: _
change += exchange_IO_Compute;# [3 ~0 p) A0 ?. C s1 ?* g
waitio++;
5 ~8 h) k V+ `0 `& n7 A. v& ?}; j/ J2 O o: } }( o+ h$ _: n
else# N* o2 B [4 `* ^/ a* g6 [+ ~
{% G- c1 f& e. Z
waitio++;& c7 }, |: B+ L$ u! q9 s% Z
}! T1 f/ m% ^: y% d$ C- o2 ]
}! y5 q2 R' T! ]/ z; J$ s
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)! F1 [* @9 m, ]$ K
{
8 F2 `# W0 `8 s- a) I& @(* memory).p[0].flag=IO_waiting;
, ]0 N/ {) _4 {2 Fchange += exchange_IO_Compute;
! L( o8 ]- y. y7 @" D$ j' {) i}; I8 X9 b0 V3 L# P
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
! w- G. d( R: N3 M{
6 d( W7 ~8 q( T, s: l(* memory).p[0].flag=computing;9 F7 t: W" u v) G, V* `. q
change += exchange_IO_Compute;
! G$ ?& H) Y' R2 l* F6 N# V+ H! ]}" v+ @+ o! C5 g
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成( u$ R& _5 S) y& e/ M8 I- d2 n8 w
{
' M" Z* a! h- r(*save) = (PCI*)malloc(sizeof(PCI));$ I% G9 `, D/ t1 a% ]3 N( B6 }
(*save)->next = NULL;
) ?2 w8 [/ k& r/ G& `(*save)->processID = (*memory).p[0].processID;/ s, J8 ?/ C5 s5 t
(*save)->comeingTime = (*memory).p[0].produceTime;
$ H9 Z k' L2 j5 H# l9 P) K* R( u(*save)->askMemory = (*memory).p[0].askMemory;
0 e1 B( G9 F' Z0 F$ D" y; a: `(*save)->compute = compute;- L& s* Y0 G1 U" `* t) w5 z6 @
(*save)->waitio = waitio;* @" ?( _! d* k, ^
(*save)->exchange = change;4 y! c* D- R9 [, v9 f
(*save)->completedTime = systemClock;
: }8 n8 e' Q) w7 b& h9 n2 D! B(*save)->runningTime = (*memory).p[0].runningTime;
; G( K: y$ Q, s& m( r*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;+ x8 t+ b- \; h
compute=waitio=change=0;) Q, t1 t. k( l. K5 Y
computeLast=waitioLast=changeLast=0;
% H7 `0 J, M. Z4 `High_response_ratio_s_to_m(&(*storage),&(* memory),&(*spareMemory),1,1);
0 T3 }0 l$ t0 `+ Z3 g, Achange += exchange_process;
2 m* e; P) C' \4 Oreturn task_completed;! F% B! c7 G: L6 a4 B u* ]
}4 s, o# N% w1 T) h
else
- ~' h: [/ q0 [# N, x! |$ A7 lreturn task_not_completed;
0 O8 u( `$ y& r7 g. Q}
8 q! o9 U7 B6 Oint High_response_ratio_s_to_m(processPool *storage,processPool* memory,int *spareMemory,int flag,int dispatch)
" F5 ~( M; w' @& M{7 l% t% b j& b" V
static int waitTime[initProcessNum],i=0,j=0;2 M* ^' u7 S c0 {
static double HR_ratio[initProcessNum];
- L) Z$ ^& p3 |/ d; v4 Eif(flag==0) //初始化数组
/ U$ \0 h8 V) n3 j( q{, o+ m6 {! |( t O7 }, G5 r; j
for(i=0; i<initProcessNum; i++)
3 |% t) j: w! V4 R X{
3 r+ ~+ u9 q# W9 ~2 h7 a: iwaitTime=0;8 f6 R* G2 B2 L! I c0 i7 O& d8 x- W
HR_ratio=1;
) X$ Y7 S* [4 g# l: k7 I2 j$ t$ W# G}
' Z; c6 C" j2 B6 }0 _+ d( S}
$ t3 Q8 r' j! M4 f1 A, _. Tfor(i=0; i<(*storage).proNum; i++) //等待时间增加,重置响应比
: B0 A& ~& s2 e& t{6 {$ W7 ?* m0 p+ t' s8 W4 P
waitTime++;, {0 _1 T# Z' C- m' V- l. ~
HR_ratio = (waitTime+(*storage).p.computeTime+(*storage).p.ioTime)/((*storage).p.computeTime+(*storage).p.ioTime);
0 e. Z3 M) d5 h' Lif(HR_ratio > HR_ratio[j])
. \) l( U9 N+ k! `9 E1 gj = i;: M) M4 I/ y4 b7 \; H' f1 P
}% c* h$ m7 b# n4 ]
if(dispatch==1) //需要调度一个进程到内存中执行
# I! j/ t2 M' W* a% ?6 Z{
4 v9 Y! c2 d& fif((*storage).p[j].askMemory < *spareMemory)
. d4 K$ r2 I' J5 j1 [1 H8 ?/ T{5 c1 S+ e# F6 F9 O
(*memory).p[0].askMemory = (*storage).p[j].askMemory;
3 `2 l! C ~5 h0 V5 ^$ Z(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
9 Z4 ^6 l& ^$ w" N(*memory).p[0].computeNum = (*storage).p[j].computeNum;+ c7 S3 a& p) ~! _" U
(*memory).p[0].ioNum = (*storage).p[j].ioNum;
2 U/ Q8 P- P% l' j$ [0 C9 ^4 h+ `1 H' g(*memory).p[0].processID = (*storage).p[j].processID;
# X0 [& }' l* ~$ S, |(*memory).p[0].flag = (*storage).p[j].flag;: S5 t, v9 ^% E; c
(*memory).p[0].ioTime = (*storage).p[j].ioTime;
% Y( D/ ]' C9 V n(*memory).p[0].computeTime = (*storage).p[j].computeTime;
$ u Y( U! R. N$ r(*memory).p[0].runningTime = systemClock;
& d* z3 x. v' V! B& I m(*memory).p[0].produceTime = (*storage).p[j].produceTime;& C: A4 T' M# o. D& R# {( K6 B
for(i=0; i<(*memory).p[0].ioNum; i++)
( r N! q+ P& i(*memory).p[0].ioClock = (*storage).p[j].ioClock;& p' f, Z7 z7 `$ E3 _- f' d
for(i=0; i<(*memory).p[0].computeNum; i++)
, w3 [3 ^3 e0 ]: a& u6 p$ U(*memory).p[0].computeClock = (*storage).p[j].computeClock;
% s. g, F" y# o7 {) B1 \(*memory).proNum=1;( N( r! D, T" p' A
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
5 f, c. _" @4 p, a, s* p6 _+ r; Rproduce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
% k2 t9 R/ g5 u- V& H- C( f. {(*storage).p[j].produceTime = systemClock;
8 _2 q+ J" m1 C" F" HMAX_COMING_TIME = (*storage).p[j].comeingTime;
- J% ?; e& e( w O0 ?: N4 kwaitTime[j] = 0;3 l8 G3 S9 ] P9 F
HR_ratio[j] = 1;2 H) @" F: G0 e; W" ?9 a9 i: d
}. w0 ]: {5 j& i: ]
else8 H# a0 L' h% e1 y, C
{0 z) C* g& n5 l& ^7 H0 R
printf("A process ask for a memory overed the system capacity\n ");
( F, a6 K9 L% `% G3 |1 sexit(1);
& N0 c* s) X/ ^# D* g1 m}
: S4 W) G. l5 d9 v}
2 R# j' b* W; ]. H4 s' {return 0;5 p* ~) i1 M9 N4 t2 T
} G! n3 R8 k# c/ l6 ~' R9 B
int PriorityDispatch(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)9 Y) d# M) r6 e8 Z8 k4 j
{
$ a/ R$ Y4 G8 \1 j( u$ _static int compute=0,waitio=0,change=0;
5 [' H, Z& I) h' ?" q6 Y* D. Sstatic int computeLast=0,waitioLast=0,changeLast=0;
2 |$ E6 m: c2 M" O* G+ lint i=0;0 w! g% e- {4 f, N
if(draw==1)
; |/ @: e8 @6 d{
- M& k. a! y3 |//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);" |0 V9 U* h3 \' I* L5 ?, F
drawPerformance_PF(800,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
8 F! }% e6 G# ?3 r
1 f/ W) M! R5 V; l% ?0 {0 N+ @7 I* ~8 U1 C
computeLast=compute;
9 z/ N3 M$ k, g/ k. {waitioLast=waitio;
; |2 P$ n( F5 }) EchangeLast=change;
7 K1 m2 z( l* c, z3 C}2 |1 n1 J: `4 j0 t# e" f
if((* memory).p[0].flag==ready)$ \8 E7 K1 ^* ?
(* memory).p[0].flag=computing;
# j! R/ j, f4 O& h: k$ |if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
* ^) ^1 [, S5 @$ Y{; r$ t; X- O( k$ _
i=(*memory).p[0].computeNum;
& \ z! @, ~: K- U, B. |. F1 tif(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed9 T) G' L d( X; \" R% t, Q9 v
{, C# K0 B2 j* J7 e3 s
(*memory).p[0].flag=IO_waiting;6 g+ r+ i; q: w
(*memory).p[0].computeNum--;/ t$ d6 E+ w4 d, R& i% J0 M. M8 j3 K
change += exchange_IO_Compute;* C1 \/ _3 G2 B$ }" R
compute++;1 U1 a7 ~$ Y4 f1 c. G
}
, K; G b' ^" E- Uelse) `4 N: h) c4 ]* S- @" _
{! m; Z z$ R/ J
compute++;: r; S5 x7 x8 S" c! Y7 d
}
5 q; Z" K2 P& B; B3 p T}( v8 M% W# k* q! }) I- |
else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
; V" t6 ^, I1 \/ E{
* g$ H. g3 Y; h/ I0 v3 X3 S
7 j7 \1 W9 B6 o7 v: H. ?8 zi=(*memory).p[0].ioNum;
7 k1 |% G8 A2 a9 O! eif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed' k: q8 D4 X% I: g6 B
{( A5 O C# L8 D/ Z
(*memory).p[0].flag=computing;5 n9 {: g' p3 F$ _+ @3 \
(*memory).p[0].ioNum--;: i1 e, U; Y* P1 }7 Y& w
change += exchange_IO_Compute;+ `+ I# }0 D) \. a# o# o
waitio++;+ \* ~! T' f! Z
}0 q8 r& K" o1 l& }
else
1 w5 {2 ~8 i* y1 W{
9 K( z/ a% E. |2 i! Fwaitio++;3 l. A/ }9 A* W ]7 u/ ?- _, W
}
/ D. A0 g% x. j4 v+ d5 T}
3 `) D2 T' F# f. P1 Y' @else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing)
2 G; l; ]7 B% ]$ f" E{+ u1 U! R+ k& D# M/ g1 g
(* memory).p[0].flag=IO_waiting;. Y+ e( K) @8 \" J$ ^8 Q& y/ Z
change += exchange_IO_Compute;
7 k6 X' ~5 x4 ]6 ]+ R/ \}
8 r& J+ p/ q/ U3 Selse if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)
, T3 _) t$ J% H3 t- P7 S0 G& o{. X C" Q2 r7 @: H v" a3 M6 J
(* memory).p[0].flag=computing;
9 S% n' J. a! lchange += exchange_IO_Compute;9 e/ T$ @/ o6 }; L: ?
}/ H- s: m$ G- N
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成
4 m4 t$ \4 S) e. ~ Z4 x, I{7 ~# ?% Q3 d4 s. T) x- ^) L) t2 h
(*save) = (PCI*)malloc(sizeof(PCI));
8 Y$ b: h: U7 l* s(*save)->next = NULL;' `. A4 b" F! z( {" F( X
(*save)->processID = (*memory).p[0].processID;4 f" d$ n9 |$ ]0 c/ {5 @1 p
(*save)->comeingTime = (*memory).p[0].produceTime;
) s2 j! q) p* P/ R4 s) Q$ n- E& ~(*save)->askMemory = (*memory).p[0].askMemory;
0 j" A3 a. \3 r& B. b' m(*save)->compute = compute;
# C; Q4 }9 K0 k$ h2 j(*save)->waitio = waitio;7 ?$ F# Q: K* J: k7 n
(*save)->exchange = change;* v' W5 d! y0 I6 Y; C
(*save)->completedTime = systemClock;: r: t; B0 u; h% ~' [
(*save)->runningTime = (*memory).p[0].runningTime;
1 e5 @0 r, J/ L6 ^; i+ e3 c- T*spareMemory = MAX_MEMORY; //*spareMemory + (*memory).p[0].askMemory;
/ ]- p$ v1 v1 R. acompute=waitio=change=0;
0 Z: z+ P) d% _& a2 m" E5 Q" RcomputeLast=waitioLast=changeLast=0;
' t: i% v6 N XPriority_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));
4 @9 T) o2 M; mchange += exchange_process;! @6 \& b! r2 a- h
return task_completed;, ~3 `$ f% t% P4 {* G2 t; ~
}( g" y7 V& o5 ?: g- m0 F1 _; q2 ]
else
8 Y0 @& ~6 D9 Y" l* i& vreturn task_not_completed;: o! S6 G; k U! _1 {
}7 w- ]2 m2 ^% y, a$ C
int Priority_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
% D5 E" C( m. ]/ i{0 d2 ~7 S. k1 g4 F+ Y
int priorityNum[initProcessNum],i=0,j=0;
e5 Z+ ^: \4 z/ g9 Wdouble temp=0;( }, J, y- {8 l- l8 }) \
for(i=0; i<(*storage).proNum; i++) // setting priority to each process
2 ^8 E* {8 B6 P# L7 N{3 ]. w* i% E& J( f0 k
temp = (*storage).p.computeTime/(*storage).p.ioTime;
% H; ]- O. m F2 I6 p; q4 L2 }5 Tif(temp > 0.8)
1 \0 f8 h; ?& `: b! VpriorityNum = 6;& c$ [1 }% m+ d% I
else if(temp > 0.7)) I0 C4 i2 p. r
priorityNum = 5;
' C2 r0 C) [; N$ a' yelse if(temp > 0.6)
) p+ ~; K6 [( h2 epriorityNum = 4;
. \7 p/ K B Belse if(temp > 0.5)
) Q# u! |) y1 }priorityNum = 3;0 R8 }0 `) C$ ?( E$ s' d
else if(temp > 0.4)
5 ^+ \3 F% H5 t0 B! KpriorityNum = 2;
) ]1 j$ ]' U$ s% z4 ^$ xelse$ j* T! ?; l! H( A, f
priorityNum = 1;
4 j8 i* \2 B$ _( ]if(priorityNum[j] < priorityNum)
0 }) p1 M _2 D& A5 F, }. u* G3 w( Cj = i;$ }* k$ S4 B3 Q4 _7 n5 q
}0 O' q S8 m. ^: L0 R
if((*storage).p[j].askMemory < *spareMemory)
3 }( P$ n6 p! b Q0 l1 U& B# E{
5 }. G! i3 w# m% F# `(*memory).p[0].askMemory = (*storage).p[j].askMemory;
/ Q( A# u( m6 w. u' R0 p(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;
4 S0 T* t2 [3 `(*memory).p[0].computeNum = (*storage).p[j].computeNum;! f4 o3 p" p- U1 Y1 c
(*memory).p[0].ioNum = (*storage).p[j].ioNum;
' Z- ]- V* D% p% [(*memory).p[0].processID = (*storage).p[j].processID;+ E% Z! n) o: @* V" L
(*memory).p[0].flag = (*storage).p[j].flag;
5 i/ N: x/ e- X& T. W( \& c& w(*memory).p[0].ioTime = (*storage).p[j].ioTime; C# J2 S: Y& g' j: G" U9 S( M8 U
(*memory).p[0].computeTime = (*storage).p[j].computeTime;& g# I" X: C3 N S. Y. Q1 n! t
(*memory).p[0].runningTime = systemClock;
; }% f0 U! j4 D+ l0 S(*memory).p[0].produceTime = (*storage).p[j].produceTime;5 u p7 Y( U3 T7 N: D4 b6 m; P
for(i=0; i<(*memory).p[0].ioNum; i++)
1 E" D& j% @; v5 m: J2 ]8 F* ^(*memory).p[0].ioClock = (*storage).p[j].ioClock;) }" _) {+ G7 I o* L: O2 F
for(i=0; i<(*memory).p[0].computeNum; i++)5 [7 W4 G' Z! H6 \4 \- E J- R
(*memory).p[0].computeClock = (*storage).p[j].computeClock;
7 O* F; l9 I7 L(*memory).proNum=1;% K, ?: @- @0 N( A \
*spareMemory = *spareMemory - (*memory).p[j].askMemory;( e9 j& Q3 b9 y. n* I2 o- s/ k
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
6 q8 C; R, a* r9 cMAX_COMING_TIME = (*storage).p[j].comeingTime;' g% u, w* u/ Q7 D1 Y
}
: x- J7 i( g" {) ^8 @else
9 `5 [) M* ^( q9 {$ P{
3 M0 y7 f0 L2 c Oprintf("A process ask for a memory overed the system capacity\n ");0 ^$ c) C9 a( x! j' Y; m
exit(1);
3 i: P6 P- z* l/ w" ]2 w}
4 N" E) }( n) F0 }/ X# G1 ?return 0;/ ~7 W" }" |: S# E' W" P* H
}! {$ U3 L# S0 B2 c+ h& N% L
int ShortJobFirst(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)5 {4 ~0 k, p1 ^& O: \6 n. z9 |
{2 T x, U& }2 l, ?* \
static int compute=0,waitio=0,change=0;1 x. {" C4 ]+ Z+ _9 c' b3 e2 B
static int computeLast=0,waitioLast=0,changeLast=0; @7 I9 p+ S( a
int i=0;4 y1 n7 @( y' Y. t, ^% t
if(draw==1)
b2 { |5 A! t" X1 E d* w0 ?" p{
z& M" l3 Q6 h$ b//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);
9 u9 `# W" [1 x a" |' [" qdrawPerformance_SJF(0,325,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);
" U2 y3 W, c$ _. x
( H4 [% L) P' v: U" D* B' O' u0 L: u" U3 }# a9 n1 e
computeLast=compute;
& _- N. r. l+ j4 I e3 ~: ]) ewaitioLast=waitio;' ?- O! d0 p! O4 x3 A3 P9 u
changeLast=change;
( [ G! ^5 i4 k0 c+ S}
0 v _* F7 G8 N) t- h p4 {% x* ^if((* memory).p[0].flag==ready)
+ k7 W, a5 t; b- e2 w1 c ](* memory).p[0].flag=computing;
% O1 I; d) l: S( w/ Xif((* memory).p[0].computeNum>0&&(* memory).p[0].flag==computing)
& R$ F/ [4 U8 O{0 U& K$ L2 }9 r
i=(*memory).p[0].computeNum;0 q$ @4 `/ Z- E# Y7 o' {
if(--((*memory).p[0].computeClock[i-1])<=0)// one compute tase is completed0 a7 j2 r8 h# q3 Q
{
% d/ r' X7 R! B- k(*memory).p[0].flag=IO_waiting;
1 U; W0 l j4 \6 N! q0 B(*memory).p[0].computeNum--;
9 ]# @2 F+ T& C. |/ vchange += exchange_IO_Compute;
5 f N1 Z4 ~6 U( x. W5 [* \: G1 wcompute++;
0 x! Y* B+ Y# z( q}
5 I z5 n4 g* D+ s2 ?0 relse
: |( a. Q: E, D' y{* x. P* |" y1 l& e- y! v$ Q
compute++;
; m- G( M/ ?) t1 l1 s}
$ T8 z3 h q( |% k}
' g* O! A, M: F- }4 g% ]else if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==IO_waiting)
$ Y- C y) r, L# _* |0 j }{
2 p5 O8 \/ a3 w! M ^; k/ P: ^& G% `- w
i=(*memory).p[0].ioNum;
9 x Z, { @- pif(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed8 ~$ | D. K% x# O4 s
{
1 w) ?! L2 a6 e: r+ g3 Y; }5 R(*memory).p[0].flag=computing;
5 a2 E- E0 e8 l1 V(*memory).p[0].ioNum--;/ Z4 a4 K) n" T0 {
change += exchange_IO_Compute;
5 G& v5 W9 ]: H4 m+ J) Gwaitio++;3 X/ y1 y6 E W2 x: n, K
}- N8 ]! \5 R U4 k2 [$ s
else9 ]8 y) P$ H7 U% G
{* |8 p3 J$ k) a8 T
waitio++;3 `0 [; M" P) E. o
}
9 }; a& |- _4 Q3 s" k% a0 J, o}
0 Z# I T% D( {3 b2 \* Lelse if((* memory).p[0].ioNum>0&&(* memory).p[0].flag==computing) @4 l# f0 E* ]! g4 S
{
4 s* l: b8 J/ A0 [$ q- R( N( B* G. }(* memory).p[0].flag=IO_waiting;; I* b* y' Z& u6 G
change += exchange_IO_Compute;) e# b: Y; g* U! C7 T0 m# ~; f
} C. k, m1 W$ s8 n" E5 [
else if((* memory).p[0].computeNum>0&&(* memory).p[0].flag==IO_waiting)- ?5 `0 p6 D' A+ O
{
+ _' ^$ \! V' N$ K: d/ h& q0 ](* memory).p[0].flag=computing;
! ~- w0 ~0 m! l0 d+ I- Q4 pchange += exchange_IO_Compute;" m9 [" l5 b8 u6 u2 o4 ?' ~
}+ x' H% m1 `6 }
if((* memory).p[0].computeNum<=0&&(* memory).p[0].ioNum<=0) //一个作业已经完成9 ~- c& O% ?6 Q7 M) d, B
{4 C) n: _2 `% T- g, m0 }- Y
(*save) = (PCI*)malloc(sizeof(PCI));4 `/ T+ E7 `6 u! G+ n
(*save)->next = NULL;
. A R, q1 z: m(*save)->processID = (*memory).p[0].processID;
! ?; d( N9 }4 f* V9 h7 G+ H(*save)->comeingTime = (*memory).p[0].produceTime;
1 c3 ?) c0 W9 z* t L% \# I1 c(*save)->askMemory = (*memory).p[0].askMemory;8 `& X1 s8 C$ ~- b k5 @, Q9 ~
(*save)->compute = compute;
1 ~/ [# J0 k. L(*save)->waitio = waitio;1 T9 g! ]$ }! Q" M2 M- X
(*save)->exchange = change;. ]5 ^$ {) V7 {
(*save)->completedTime = systemClock;
0 [5 V/ B0 {9 p, o(*save)->runningTime = (*memory).p[0].runningTime;+ y/ K: n, E! T8 [
*spareMemory = MAX_MEMORY;//*spareMemory + (*memory).p[0].askMemory;" I1 a9 B) j/ o% c
compute=waitio=change=0;! ~: e8 N1 {$ f( w% b2 }- ^
computeLast=waitioLast=changeLast=0;5 \7 q; p2 b. e( N+ Q1 K& \4 f4 r
SJF_storage_to_memory(&(*storage),&(* memory),&(*spareMemory));2 z5 _2 M) I. G
change += exchange_process;
; }- i: @1 {! Q' g# h" n0 d4 Freturn task_completed;5 A# |! Q: M* S. D5 t6 Q- a
}$ D4 t7 j) w& J' ]' v0 y& [0 W3 b4 o
else- _3 V& X' G1 N# `9 J/ |
return task_not_completed;
1 f( x' s& b( K3 x. v& f# z}! T& e. @- }$ o9 n, C
int SJF_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory)
2 H0 E) `9 [3 f{
1 Q" Q2 T% G& ?% k5 a7 W9 R6 pint i=0,j=0;
8 C8 V5 T& t( z& G& I; W) `7 _for(i=1; i<(*storage).proNum; i++)
" K8 b8 _9 s6 V( u- p$ |! W% p{
) y. F: \5 i% Z# x2 dif(((*storage).p.computeTime+(*storage).p.ioTime)<((*storage).p[j].computeTime+(*storage).p[j].ioTime))
2 m' N" @) w0 ]j=i;
* E) n1 i! j3 W}
. T/ _( C0 B8 h, A1 V: G) A/ nif((*storage).p[j].askMemory > *spareMemory)
8 I! | r8 Z! H, H1 Z1 f{
3 q, m9 Z# ], W: A! Q8 A( sprintf("The memory asked is overflowed than the system memory.\n");
- T) ~- j3 D* Uexit(0);3 m( T9 c( J$ _2 W/ e C+ P
}
1 h4 w9 \' ]# O8 a/ }else
4 U. n. L! P6 ?( Q2 }9 A" @{
; z; j4 T$ O. L8 n9 b(*memory).p[0].askMemory = (*storage).p[j].askMemory;
0 B4 \! N$ Z i+ |) Z' C& t(*memory).p[0].comeingTime = (*storage).p[j].comeingTime;$ f+ ^2 Q6 [! o9 I4 W$ Q# U
(*memory).p[0].computeNum = (*storage).p[j].computeNum;
1 l+ |" v1 N7 M3 h- k! L" X4 `$ r(*memory).p[0].ioNum = (*storage).p[j].ioNum;
3 ]7 h% D1 {% v! ?# b(*memory).p[0].processID = (*storage).p[j].processID;& e) e& P# }( n8 Z: |5 e% u- m
(*memory).p[0].flag = (*storage).p[j].flag;
2 k9 }9 v& j5 v f1 F$ q+ {(*memory).p[0].ioTime = (*storage).p[j].ioTime;# p2 C8 P6 m' T
(*memory).p[0].computeTime = (*storage).p[j].computeTime;
) F/ ~* |- W0 J' I! r(*memory).p[0].runningTime = systemClock;
7 l" b: |5 X, q; r- E(*memory).p[0].produceTime = (*storage).p[j].produceTime;1 _( L6 J! v: \2 ] p) ]- ^
for(i=0; i<(*memory).p[0].ioNum; i++)
( X; _! C1 b- n(*memory).p[0].ioClock = (*storage).p[j].ioClock;5 w1 A% o$ b6 C! Y$ ^" ^7 a
for(i=0; i<(*memory).p[0].computeNum; i++)
2 Q; r, Y7 A5 Y5 M+ p( m(*memory).p[0].computeClock = (*storage).p[j].computeClock;* D0 s' h7 x" V
(*memory).proNum=1;
- I+ @. q1 u& G% V*spareMemory = *spareMemory - (*memory).p[j].askMemory;, b" T4 t: b/ Y" c7 u' E
produce_one_task(&(*storage),j,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程% J( j2 W; U. T
MAX_COMING_TIME = (*storage).p[j].comeingTime;
, U5 `0 l/ n0 N5 @}
$ u& c/ a& a3 Yreturn 0;
( c3 x# w* `, B ^7 n8 ~: F}
' _9 |! t2 [ @" U1 B9 I2 yint TimeTurning(processPool *storage,processPool* memory,int *spareMemory,PCI ** save,int draw)
2 _ q9 z( C' M. f/ R3 A{% c) P6 l0 C9 O8 j% W5 {* O
static int compute=0,waitio=0,change=0,clockSegment=100,poi=0;! U7 H) x( M# E& x) B
static int computeLast=0,waitioLast=0,changeLast=0;
$ a" y v# [+ t& e- x \int i=0,j=0,k=0;
7 t/ F ~7 y! E6 C+ Bif((*memory).proNum<=0)' W& {3 z% U* p
TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),-1);( b" |, `: |5 b, t
if(draw==1)/ M" ~5 n: K2 C) O$ D, \
{
( i$ c: Q [& O: n//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);/ k9 C+ I6 {2 r: ^6 n4 F
drawPerformance_TT(400,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);& v p: v6 z+ [9 v* j6 J3 L( c9 V
3 \( G, I Q$ c* _& ~2 {+ e! k
3 `, O8 b. T5 dcomputeLast=compute;
4 |% t3 p$ m4 z/ k% U3 [waitioLast=waitio;
% S* w5 m1 {3 A1 j3 v" M, wchangeLast=change;
9 G* ~4 z- \. z8 W: u; W, k}
% x! L: _# x; E7 e4 o3 Oif(poi>=(* memory).proNum)7 i4 z( v. r4 R* }! x5 S1 }3 F
poi = 0;% y$ e2 a, E6 N$ C3 C' d% Z
if((* memory).p[poi].flag==ready): n' X1 B; h. @' S, s
(* memory).p[poi].flag=computing;
4 @9 V* J6 V$ _& r9 Fif((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==computing)
0 t4 J0 ~7 g) j$ u9 g. v7 F{
7 ^- y# S) `6 J2 [i=(*memory).p[poi].computeNum;; z9 J6 n& g: f* }' x- {1 R
if(--((*memory).p[poi].computeClock[i-1])<=0)// one compute tase is completed; B9 F/ C5 z5 v1 @
{* J: E6 g3 X$ `
(*memory).p[poi].flag=IO_waiting;; t: v* P- t; e2 d
(*memory).p[poi].computeNum--;) N4 ]5 C& T6 M6 B
change += exchange_IO_Compute; Q5 a1 t: Q3 ^2 h* j5 m
compute++;6 \3 y4 `# K3 R1 J
}
" ~! r4 s5 } y; n$ t4 Z6 i/ Qelse
$ \# E7 N, v$ p' s( t{8 T/ A! n( {; q. w# l
compute++;6 ]6 T' j# f" @ T1 n6 q8 Z
}$ N( C8 K1 ^( F5 l3 T1 o
}/ k+ r* q3 z: u5 z
else if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==IO_waiting)2 l g! M$ W% U: b
{/ u9 x& [1 ]7 l' {* q( y
! E' t* v0 ~( h, V
i=(*memory).p[poi].ioNum;6 U5 O Y; R' v5 A
if(--((*memory).p[poi].ioClock[i-1])<=0)// one io tase is completed
) g7 J+ {6 l) Q, O) H! S. s{- z# t7 M3 w* @! i, {" x; y7 s
(*memory).p[poi].flag=computing;
" c6 `& Y0 [4 l8 ]5 y" {& j(*memory).p[poi].ioNum--;+ E4 {! y; E% Y# a
change += exchange_IO_Compute;% p, c7 O9 h1 F4 J& v, l' T; T
waitio++;
+ u1 r6 M, k1 Q# W}1 E& U3 X7 s4 N; O3 L1 y5 o* ]2 K
else
2 r9 V+ D- X6 z& f6 U{
( v$ L. o. c3 I( y2 _( rwaitio++;9 T7 k& h$ ]+ X& b8 C1 L
}3 ^; S0 i3 J% ^
}
. c' l3 C% a: B' E `) zelse if((* memory).p[poi].ioNum>0&&(* memory).p[poi].flag==computing)
* O) B$ Z' B( o/ s. O1 e{5 |( w- n7 Z2 F9 Q+ \9 l
(* memory).p[poi].flag=IO_waiting;
0 v- F5 @" g0 U( U4 tchange += exchange_IO_Compute;- d; [0 ?. V. [" N
}
8 B, O0 c- c. U+ j9 z0 X; K5 Helse if((* memory).p[poi].computeNum>0&&(* memory).p[poi].flag==IO_waiting)
' e& }, W5 o: @7 |1 D4 O{
- W' m( w# ]9 H+ p/ k(* memory).p[poi].flag=computing;
$ I7 S! e& q7 m- L1 `: i5 Ochange += exchange_IO_Compute; _8 {" Y R6 j% x7 f
}
. V( }" u! z- Lfor(i=0; i<(*memory).proNum; i++) //其他等待io的进程可以并行推进2 I( E& z# q! }. ~7 K- U
{ k0 d* }: V2 y# U
if(i!=poi && (*memory).p.flag==IO_waiting)3 Z' W. H5 Z# W7 U+ e4 f% f6 D, Y
{ z- q8 W* ?0 p" u! H
j=(*memory).p.ioNum;
9 H8 R' j. g/ _% O% L4 m/ uif(j>0)6 n3 l5 _- N) ^3 c% [0 ]
{* \ O9 x6 j9 h! ]
if(--((*memory).p.computeClock[j-1])<=0)// one compute tase is completed
% ]- V$ p( r( I5 G; ~{! N- m' x* n* j3 o( ^
(*memory).p.flag=computing;# I( s, T, {& s( \2 H
(*memory).p.ioNum--;" `# @$ v: H* Z- }
change += exchange_IO_Compute;
4 M7 v( k7 H& ^8 b j6 l; {}
+ V# ]9 v! u; f+ p1 }0 i; L}' D: H w: i, u% n* k7 w
}
8 [8 B/ m$ Y# Q+ Z, N. f}# o. u! d; F% a9 A( C* ]3 n
for(i=0; i<(*memory).proNum; i++) //处理已经运行完毕的进程
9 N; B1 B. A: y; o- Y, {/ \$ k{4 u9 V/ z/ l+ B; ^7 H I
if((*memory).p.ioNum <= 0 && (*memory).p.computeNum <= 0) // a task is completed
3 X" w- D/ V- V/ g8 P- s' B$ u' ]: M{0 q2 V- R* [5 p. n
(*save) = (PCI*)malloc(sizeof(PCI));" Z$ v, I9 E1 H# p
(*save)->next = NULL;5 C* O/ P& H- D3 R8 b/ b9 ^- d
(*save)->processID = (*memory).p.processID;& }- Z ?/ a$ R" O8 C3 t) t
(*save)->comeingTime = (*memory).p.produceTime;
. C. k6 Z/ @8 [- [" u/ \(*save)->askMemory = (*memory).p.askMemory;
6 `$ `4 B# u3 |(*save)->compute = compute;
$ p! p% f! {2 N8 N/ l(*save)->waitio = waitio;% U, F3 @0 e, I6 \3 d, U! C
(*save)->exchange = change;1 o8 L ?1 F# h) [+ p# m1 H
(*save)->completedTime = systemClock-(*save)->comeingTime;0 W- H+ O5 _; ]# A
(*save)->runningTime = (*memory).p.runningTime;2 I% i1 Q7 v8 `% J% ~
(*save)->completedTime = systemClock;
. a6 I$ O; @& h$ E*spareMemory = *spareMemory + (*memory).p.askMemory;/ a& Z5 d8 K- @+ U, p
compute=waitio=change=0;
2 j( d2 m/ J K; z" M$ ncomputeLast=waitioLast=changeLast=0;
# D1 k7 N8 j1 k* I9 S+ vif(TimeTurining_storage_to_memory(&(*storage),&(*memory),&(*spareMemory),i)==1) // 调入一个新进程进入
- q; {, [5 G/ d- ?3 l{
* Z5 a! c1 ?* F: M3 z2 Wif(i==poi) //占用CPU的进程已经运行完,将时间片分给其他进程9 E! P. p: Q* `0 D2 s7 x
{
' {; }/ u v! cpoi++;. x. n$ [& H0 T r' b
clockSegment=2000;" w+ y5 s& [( m* g% |6 u" C! T' [
}
. o; | r# J& V" X}' ~8 M) P! F" ?- o) ? Z
else //没有足够内存调入新进程
% H2 o) z4 y8 P# r{
3 ?+ v" b, p, Z. g* vif(i < (*memory).proNum-1)' x C8 |; @& I2 d+ J1 @6 T8 Q
{' M$ s d, @7 N) j# R! R7 w6 h. I
for(j=i; j+1<(*memory).proNum; j++)
l7 K6 T5 L7 {7 \- V/ a{$ I9 R: S9 F' i$ {# y: D& c
(*memory).p[j].askMemory = (*memory).p[j+1].askMemory;/ b( s; t2 K. }0 A( B
(*memory).p[j].comeingTime = (*memory).p[j+1].comeingTime;
' e L& G( c2 D( @8 i9 n(*memory).p[j].computeNum = (*memory).p[j+1].computeNum;
/ _( f, S9 k# _- I, v8 ^" \8 @5 u(*memory).p[j].ioNum = (*memory).p[j+1].ioNum;
2 x6 e+ ^0 r4 i2 ^* s& F- L(*memory).p[j].processID = (*memory).p[j+1].processID;
0 F0 s0 L/ t; n5 @# y- @+ v% Z. U(*memory).p[j].flag = (*memory).p[j+1].flag;
& a5 i( D8 O8 f7 X(*memory).p[j].ioTime = (*memory).p[j+1].ioTime;
- D) s* i4 x0 M. v E; ~(*memory).p[j].computeTime = (*memory).p[j+1].computeTime; \( ~/ q3 t; E$ O V
(*memory).p[j].runningTime = (*memory).p[j+1].runningTime;
& n. D* U9 u J! R5 R9 u(*memory).p[j].produceTime = (*memory).p[j+1].produceTime;- M! s7 f7 b S
(*memory).p[j].completedTime = (*memory).p[j+1].completedTime;
6 c% \* x1 h; l) \for(k=0; k<(*memory).p[j].computeNum; k++)9 k2 p7 A: ?& M! _
(*memory).p[j].computeClock[k] = (*memory).p[j+1].computeClock[k];% @, E, |/ Q2 ]6 _+ X
for(k=0; k<(*memory).p[j].ioNum; k++)" L5 u3 J9 u8 j/ x
(*memory).p[j].ioClock[k] = (*memory).p[j+1].ioClock[k];$ E D$ r- |$ k" V. @. g
}" E4 J* x8 B, V( V% A" W1 ^) R3 D
if(i<poi)
" C0 Z7 E$ k' F! W7 {poi--;
0 j7 ?% `5 F2 S9 `7 u: nelse if(i==poi)
2 Z" O6 W ~9 @clockSegment=2000;
9 N. D4 e% k2 C8 H* T}9 H! r8 H% A$ o5 ]
i--;& |& U. M( j' n
(*memory).proNum--;3 y. ]) Z @+ ~% C5 v
}
7 Q! e' R, N+ Q- ~. L: a2 nreturn task_completed;+ n0 x9 C9 H+ ]! Q5 X4 `, a
}
5 W+ S6 X. y$ g _* c. f} n; G+ T* T; l2 v2 a
--clockSegment;7 T& [' ?6 V8 m: Z
if(clockSegment<=0)
1 g* `/ I5 e' _1 y7 \- `{/ {! V5 a4 b9 D$ k% V& b3 Z/ W
poi=poi+1;" }, b$ ?6 i" H' B- _5 d
if(poi>=(*memory).proNum)+ g6 e4 U: W- f8 _2 d
poi=0;8 {+ \9 [0 z) h3 i/ o5 q
clockSegment=100;9 L7 s. z4 @& A! o5 X
}
Y9 c: G1 E0 f, U- U! q2 Hreturn task_not_completed;
6 ~9 c; b; f/ r. y$ W/ ^, L, I0 U}, C6 @/ F+ j/ R8 ]7 [1 V- i: p
int TimeTurining_storage_to_memory(processPool *storage,processPool* memory,int *spareMemory,int pos)
2 j2 y( |5 r7 J0 t{; e+ h7 ~- ^1 z* [+ G
int i=0,j=0,k=0,flag=0,translation=0;
9 K0 A) C O. j8 ~for(i=0; i<(*storage).proNum; i++)5 S% a& i2 F" Q" y
{7 G9 Z5 [; v4 |# z
if((*storage).p.comeingTime>MAX_COMING_TIME)5 | N% k4 R7 H6 I3 Q( H8 n* ^
MAX_COMING_TIME = (*storage).p.comeingTime;
) Q7 V! V* i3 T) o# a% q}: H: @; w/ c5 @( |/ _. o7 E1 v* K
if(pos>=0)
3 _' b9 Z2 @% B8 o: @1 q# e0 m8 ~{ M. F$ j5 N2 C
for(i=0; i<(*storage).proNum; i++)7 x/ E/ a3 m2 S# T6 b' G' R+ @7 X
{( ^3 @" d4 K/ \
if((*storage).p.askMemory <= *spareMemory)" ^, s' u' s4 b# D9 p8 s
{2 ~7 e' r7 d/ P( T8 l" n9 j# Y [7 c
j=pos;0 N* r3 H0 _: ], `+ `) [$ r7 b+ q
(*memory).p[j].askMemory = (*storage).p.askMemory;
2 Y6 l6 p: d; G" x$ [(*memory).p[j].comeingTime = (*storage).p.comeingTime;) K. K1 K! w* [
(*memory).p[j].computeNum = (*storage).p.computeNum;) K" P. b+ }. b" V! `
(*memory).p[j].ioNum = (*storage).p.ioNum;4 }$ R; {& u8 ^7 P: c. `$ C, j) b1 K
(*memory).p[j].processID = (*storage).p.processID;: l! f; f1 F* ~5 G; |
(*memory).p[j].flag = (*storage).p.flag;
# l4 {% V t4 a+ Q* f- D/ F(*memory).p[j].ioTime = (*storage).p.ioTime;
- y8 x3 q1 j9 R7 C(*memory).p[j].computeTime = (*storage).p.computeTime;/ X3 F: Q/ `; W) H$ m. c( e! r
(*memory).p[j].runningTime = systemClock;3 M4 F" ^8 y" g1 d+ ? K0 D
(*memory).p[j].produceTime = (*storage).p.produceTime;
) C- w, y* k1 R3 ~4 W1 d' ifor(k=0; k<(*memory).p[j].ioNum; k++)7 L, e( i8 ~6 \# l% D. V
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];- _$ a `7 F( e1 c! l9 M# ~8 j; r
for(k=0; k<(*memory).p[j].computeNum; k++)3 U" v) H! t+ ^! ~) W7 Y2 e
(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
1 _) j8 S8 C+ }' c*spareMemory = *spareMemory - (*memory).p[j].askMemory;
3 ]1 Z" Z$ h9 `/ m! dproduce_one_task(storage,i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
' T8 J1 v4 ?2 |# Z- qMAX_COMING_TIME = (*storage).p.comeingTime;% p, u; @9 Q V3 ]1 b
translation=1;
3 i& |) t3 V; x9 ]break;4 @* `/ `3 [( s2 M- i8 ], [/ q
}3 L+ ~; a$ ^ _2 n
}
. c) ]1 F \1 }" ^) [6 x}* A+ C+ ^1 T' L: _# o7 z) Q
else: V6 @- L+ ?& H4 V' b
{
S7 B- [3 Z$ @! f: j% Z* mwhile(1)
5 O' ~7 E9 u; @, g* |3 d2 a4 Y _{, x0 l' Q: ?3 o6 p4 n0 I; {
flag=0;+ Z+ [- y$ n2 u& w: y9 B; ?- j
for(i=0; i<(*storage).proNum; i++)
6 q# k7 `6 a9 w{
5 v( Z" O4 ?) ]. kif((*storage).p.askMemory <= *spareMemory)8 C8 R5 `' x/ |7 m# ^0 t
{
& n7 n$ F) q1 x* p7 d5 e5 sj=(*memory).proNum;
3 {/ C1 d; R: P+ H! _( c(*memory).p[j].askMemory = (*storage).p.askMemory;2 F! O+ n$ I1 z- t7 N$ N6 T. \
(*memory).p[j].comeingTime = (*storage).p.comeingTime;/ v( a0 B/ P- c2 K7 ]
(*memory).p[j].computeNum = (*storage).p.computeNum;$ C" R8 W5 h6 a2 `
(*memory).p[j].ioNum = (*storage).p.ioNum;6 J* D& m6 Y2 S$ a
(*memory).p[j].processID = (*storage).p.processID;
8 g# L" z; T# \# I8 s(*memory).p[j].flag = (*storage).p.flag;3 e" Z. c/ A9 J+ ~) v) H* h+ P
(*memory).p[j].ioTime = (*storage).p.ioTime;: a3 S( l- c, J$ [
(*memory).p[j].computeTime = (*storage).p.computeTime;
- v& E! i3 z% E* p8 w: D: s(*memory).p[j].runningTime = systemClock;
5 T# w: G! R' a(*memory).p[j].produceTime = (*storage).p.produceTime;
$ V* L0 C9 C( {for(k=0; k<(*memory).p[j].ioNum; k++)* V* i' G6 v* Q- \2 H0 ~
(*memory).p[j].ioClock[k] = (*storage).p.ioClock[k];! ?8 O% n( Z8 [' P1 D" g
for(k=0; k<(*memory).p[j].computeNum; k++)
) k6 ?; W% V/ J5 h0 W(*memory).p[j].computeClock[k] = (*storage).p.computeClock[k];
% y% k2 Y0 v# H% R2 Q(*memory).proNum++;' t/ x* w! x* h6 @8 s/ W. i0 v5 D5 F
*spareMemory = *spareMemory - (*memory).p[j].askMemory;
4 e7 _' F4 g2 U3 n3 rproduce_one_task(&(*storage),i,ID_FIFO++); //调入一个进程后,再在进程池中新生成一个进程
7 n7 A- f7 w4 g8 y( k/ PMAX_COMING_TIME = (*storage).p.comeingTime;
$ l, u8 K9 a3 _% `2 }flag=1;
" \* N% J9 R6 \. Y9 S( n. ktranslation=1;' N" ?* i) P& i3 _( G. s
}
) w8 z& F8 s: ]2 y& y+ \}! M. H; O# P( W
if(flag == 0)4 t' B% |6 Z! D$ h6 j3 `3 w @
break;
2 c5 ?5 P1 _# y: g( H. X5 `2 K4 f8 X6 J}
: s* F8 O7 K( R: m8 s} J! d9 ?8 p, h' _/ n
return translation;9 A, p( V+ Q& M1 W0 i
}. k$ _. c; }% D2 U9 X7 A4 ^
int FIFO(processPool *storage,processPool* memory,int * spareMemory,PCI ** save,int draw), I! \- }$ S% _, l8 {$ n* _0 I* }
{4 V+ l" {# P6 j
static int compute=0,waitio=0,change=0,flag=0,flagiocpt=0;
# I0 i$ q" Q& Z! h8 y9 [' tstatic int computeLast=0,waitioLast=0,changeLast=0;, i' w: m& X+ ^* y1 _
int i=0;' n' c' l8 o6 D+ R$ x- }8 v
if(draw==1)
2 j1 A' S' P, H{
5 X3 V/ S ^3 i( ^: ?% n' R# l//printf("%d %d %d\n",compute-computeLast,waitio-waitioLast,change-changeLast);( p8 j' M4 C& N% l5 s w, H5 P: O
drawPerformance_FIFO(0,0,MAX_MEMORY-(*spareMemory),compute-computeLast,waitio-waitioLast,change-changeLast);7 L) R- s* ]8 s/ k8 k
# w" L' n5 b f* y* E+ A5 }4 c7 e
: h6 p8 D" j/ |! @computeLast=compute;
; [7 k' S5 N. e. HwaitioLast=waitio;- A" N+ f" d- N6 k6 P2 d; o ^
changeLast=change;+ {6 r8 x5 j' C" [
}
0 ?2 q D' [7 ~/ {if(flag==1)
% H% Q8 l; I' P- @& h" ~{( |+ _, p% l0 c( N+ }
if((*memory).p[0].ioNum>0||(*memory).p[0].computeNum>0) //task is not completed
- s3 F' s4 Z( o{% _1 m: E( W% [$ j8 p7 n
if(flagiocpt==0) // implement compute
/ r! B: [& h ?8 ~8 u8 b{. ~' Y1 d; m/ [3 w6 _/ g
i=(*memory).p[0].computeNum;4 `$ [8 J4 j/ `6 b% l# u
if(i>0 && (*memory).p[0].computeClock[i-1]>0)0 P' ~7 Q. W4 `8 C
{
6 B+ z4 D' Q% k6 Uif(--((*memory).p[0].computeClock[i-1])<=0)// ome compute tase is completed
9 j- q$ f9 K# B' ~4 R( D{
* c' q$ U6 I) {7 _& B% i# D& S3 \; z Bflagiocpt = 1;
6 |* D t; N8 {7 c/ y L(*memory).p[0].computeNum--;
* h2 U% D! A: p: W$ J' h, _change += exchange_IO_Compute;
+ \7 O- D( E8 ]: O4 r# Q# U' Icompute++;( W; W1 j- k7 i/ m. Q
}$ P) e( W! J! x) Z( A
else
, q E; i% Z1 \9 Y6 M0 I i" O Hcompute++;
3 A% V- b7 G0 ?8 u; h/ G+ @
$ R3 w( e% r+ q) C}
/ d9 A6 g- v3 k+ `/ Aelse: w4 v* i4 O7 L# y0 x- R. B
flagiocpt = 1;8 B* e7 |) B2 }. ]
}
/ X) s- k; l% K5 belse //wait io* p, D- p& H* g
{
% m+ C! o0 c8 K- i k3 J8 D( U" f, ci=(*memory).p[0].ioNum;
( _& B$ _- I6 P7 n% S" a% xif(i>0 && (*memory).p[0].ioClock[i-1]>0)
7 o) ~% i g; O" B/ ~. N% u{# B1 q7 k2 R* U4 B, s6 b# m
if(--((*memory).p[0].ioClock[i-1])<=0)// one io tase is completed! ]* P2 |0 V9 [, w {3 @8 h* c# e
{
' r5 O& `/ C. m4 N. B& K% p; D5 jflagiocpt = 0;
% _! ]+ Q l7 o/ m9 y(*memory).p[0].ioNum--;
: ?! ^" o0 p+ K6 [% h& jchange += exchange_IO_Compute;0 f3 G8 S: V/ \' U2 c2 B2 t; k% Q! c" u
waitio++;
# }# t3 E6 G6 I* }; i) R" d}
8 g5 O0 b# b8 |& r# P. L9 ]else7 ` k) s. {5 ~0 `
waitio++;
0 S8 h5 G% B! W! E& B; U% j! S' |
}2 G8 b$ ^7 x( l3 Z2 d
else; O E- c3 Q; l
flagiocpt = 0;6 ?# `, s( U+ m% X% C2 n: ?
}
, E' m7 }+ D4 F: g: ?# l& o! g6 z- s}
1 N# O/ }7 w& |8 Y: `else //task is completed
: u! i: Y5 P7 v) {, M2 Y! J{" A/ e' |3 ]" s4 _1 D! ]
(*save) = (PCI*)malloc(sizeof(PCI));5 A* \7 |# E* x" `( }% ?, x
(*save)->next = NULL;
! T2 y/ p8 B |& { (*save)->processID = (*memory).p[0].processID;+ n8 l( C) q6 ^2 C* |3 F/ @9 }; @
(*save)->comeingTime = (*memory).p[0].produceTime;
, o" ~/ H4 m' n$ g(*save)->askMemory = (*memory).p[0].askMemory;
$ U. F- M4 [$ b* z3 ]- G z(*save)->compute = compute;
" x& ~. n- W! O) [& {& O; H(*save)->waitio = waitio;
$ ?1 A: ~. x1 E8 u! p4 V' R(*save)->exchange = change;
3 _) g9 m6 F. Z1 S" \(*save)->completedTime = systemClock-(*save)->comeingTime;9 Q% ~9 i( S6 r) G8 d
(*save)->runningTime = (*memory).p[0].runningTime;8 D/ p& @ N( \" }/ \
(*save)->completedTime = systemClock;6 X$ V. n6 e3 f$ C
//*spareMemory = MAX_MEMORY;
* m* L7 q; W) n5 s2 ]0 Qfree((*memory).p[0].ioClock);. l, w+ m( N1 c' h4 o0 `/ p
free((*memory).p[0].computeClock);
6 x! ~& d/ L# {' t6 cfree((*memory).p);
3 b- H1 D3 q8 N4 d- l, }. x4 Eflag=0;
0 Q0 \' @4 S1 F2 `& o$ wcompute=waitio=change=0;
) T$ T! K" \ K1 L7 vcomputeLast=waitioLast=changeLast=0;1 p- |5 W1 k! c: g
return task_completed;9 L0 r/ E! D$ o4 Z9 J
}
; R6 h! q% s W/ ~5 S& m% I}! m. P) k7 N9 }/ i
else ; \. }8 J, |# B6 |
{
0 N+ w1 h m2 c- @$ X NFIFO_storage_to_memory(&(*storage),&(*memory),&(*spareMemory));
6 A2 H" K% B7 b+ \change += exchange_process;
9 r; k# I- @: O, D& j$ p//*spareMemory -= (*memory).p[0].askMemory;+ o; O$ Y& N$ M7 D* N5 \
flag=1;7 }3 G2 _/ O1 q! J q9 g3 N5 L) j
//showProcessInf(*memory);, Y, X; O7 k: N
return task_not_completed;
1 ?' w( C2 K- \8 k2 @$ ~4 G/ D2 F+ U}
P9 V: T1 C! zreturn task_not_completed;
& | x" r! o9 j* ]' S}( R3 G" ~- y# \ w
int FIFO_storage_to_memory(processPool *storage,processPool* memory,int * spareMemory)
; i4 l9 L# H+ Y# v! S4 L{
0 U4 _4 T8 V4 U/ ^( J3 J1 Eint i=0,j=0,k=0;5 f1 u1 v* E; R+ D
MAX_COMING_TIME = (*storage).p[initProcessNum-1].comeingTime;
& a1 D3 i4 K+ v2 _3 T' H% K2 o5 E(*memory).p = (process*)malloc(initProcessNum*sizeof(process));: O1 p! W, f. i9 [1 L8 ?
memory->proNum = 1;, K1 Z: U \3 I5 l: j- _. P
for(i=0; i<initProcessNum; i++)
. c4 U9 ]- z+ a/ P4 N! l{
9 n, s% x4 n, l3 J3 Pif((*storage).p.askMemory <= *spareMemory); Q/ C0 \. o6 p8 H/ ]! X+ C% o$ c2 k
{9 M# r, _$ }6 a) N: @# R: |+ K p
(*memory).p[0].askMemory = (*storage).p.askMemory;3 j: C& l% H( W/ ?- v
(*memory).p[0].comeingTime = (*storage).p.comeingTime;. E4 z3 P, I/ |. ]! G3 g
(*memory).p[0].computeNum = (*storage).p.computeNum;
: k& }2 f- i% c1 F6 c(*memory).p[0].ioNum = (*storage).p.ioNum;
! r( o6 ?+ ~5 A5 T; n1 q(*memory).p[0].processID = (*storage).p.processID;; s4 p) A$ s( B
(*memory).p[0].flag = (*storage).p.flag;
4 T/ p. R8 {5 S4 H. C: W( y(*memory).p[0].ioTime = (*storage).p.ioTime;
H( E' m- c( U; C9 G( n2 k7 P8 E(*memory).p[0].computeTime = (*storage).p.computeTime;, j% `" ]1 @! R+ B9 _$ }$ Q8 O
(*memory).p[0].produceTime = (*storage).p.produceTime;! U+ D& Q; x0 a0 m4 y
(*memory).p[0].runningTime = systemClock;
8 H$ W3 U2 ?% E N# l3 K(*memory).p[0].computeClock = (int*)malloc((*memory).p[0].computeNum*sizeof(int));( _; o4 m4 f7 _. K
(*memory).p[0].ioClock = (int*)malloc((*memory).p[0].ioNum*sizeof(int));
& b% ^1 w7 L W/ [# R+ lfor(k=0; k<(*memory).p[0].ioNum; k++)
5 q. t0 j7 `0 `% E(*memory).p[0].ioClock[k] = (*storage).p.ioClock[k];
' y+ G; j* `/ O' B+ Q7 w/ @for(k=0; k<(*memory).p[0].computeNum; k++)& H J( @6 |# y8 W
(*memory).p[0].computeClock[k] = (*storage).p.computeClock[k];: M0 o7 q2 E* W0 j& J
break;
- {$ p; W4 _ u u}
3 \+ I3 l7 E1 Z7 i4 J8 A5 x}- d3 |6 t% f: ^7 u1 p& h; w
if(i<initProcessNum) //调用一个作业进入内存后,并再生成一个作业等待调入
9 W% T, e' X, s# Z{2 E& N' ?* Z: f$ F$ u9 k; n5 R9 x7 ~
produce_one_task(storage,i,ID_FIFO++);
9 t% w! D8 Q4 V" M O. ]MAX_COMING_TIME = (*storage).p.comeingTime;1 [% c5 p5 B) f
sort_by_comingtime(storage,i);5 L7 \& Z' x2 @' Y
}
! d, O `1 `* Hreturn 0;1 x& R; \9 x/ a) }; R$ c1 k
}9 \5 }. I8 G! u8 g
int sort_by_comingtime(processPool * p,int pos)% O L/ g9 z0 l
{) {7 g a7 _1 o A6 {
int i=0,j=0;
" J: Z" Z$ S3 d! Y, ?2 oprocess temp;& v7 L- w7 m+ x) g
if(pos<0)& i2 h# Y) k) U& T; W
{
4 u' p- f" g" a, y j2 }4 Zfor(i=0; i<initProcessNum; i++)
3 f" e, P9 [- \5 O; p1 a P. K0 Cfor(j=0; j+1<initProcessNum-i; j++)) F# b4 O- ~% I! B( _5 \; r
{
5 S# ~- a1 c4 C' @/ K3 S: _if((*p).p[j].comeingTime>(*p).p[j+1].comeingTime)) V- ^0 D: ]1 m+ g, Q8 C
{
& B8 f" u* d& Z. S* J2 W7 Ctemp = (*p).p[j];! e2 F, x1 O. D# i. f4 X1 j+ ^
(*p).p[j] = (*p).p[j+1];% a5 P1 h$ W: J8 j% {7 c
(*p).p[j+1] = temp;# P k. t' G: y6 G# N2 f" R
}
h2 n- u2 f) I3 d}( ] C6 Z4 N6 e/ K6 `8 i
}
+ A# f* Z8 i( p% ~else if(pos<initProcessNum)
$ h8 h, `( s7 T! E1 G, Q{
4 ~# @) h8 N* {( ufor(i=pos-1; i>=0 && (*p).p.comeingTime > (*p).p[i+1].comeingTime; i--)
' C' O% {; O7 k{9 F' Q0 u3 j5 m, S) F
temp = (*p).p;/ y' w' v" E Z6 S
(*p).p = (*p).p[i+1];
; V4 D( e+ r7 T* n. s(*p).p[i+1] = temp;/ G$ d4 F0 ^) B+ o; A j) F( X) Q
}
( p+ ^$ m$ J. s# q2 a' ofor(i=pos+1; i<initProcessNum && (*p).p[i-1].comeingTime > (*p).p.comeingTime; i++)
( s- C0 ^* b& i/ F$ f0 P{, a% }% Q( Q0 ?6 \% o" L0 m7 w& U
temp = (*p).p[i-1];7 _/ W1 X4 T. {! q% s; j
(*p).p[i-1] = (*p).p;
. p! u% a; |5 a8 R, L(*p).p = temp;
0 d8 ]% [* d7 [4 e; S% j; x0 C}
/ R' D# B5 K2 y' {" n. l}
' {5 h: r% x2 Q$ R& i. Relse
- E- k% c) e+ _1 }, Aprintf("position eror\n");
( a) `, L( e7 H6 b, Rreturn 0;1 |: k* q8 }& u7 f: ?7 \0 e
}
& w5 f6 {, u( q) ]int InitPool(processPool * p)3 y- H/ L4 t) Z2 S
{
3 p) q2 i/ _2 g7 Wint i=0;
$ w% T0 y- l9 ~" e(*p).proNum = initProcessNum;- l: |8 y* I* n2 ]
(*p).p = (process*)malloc(initProcessNum*sizeof(process));+ d# R3 u B, h7 [
for(i=0; i<initProcessNum; i++) //init process information
m8 U" v( R, ~' c, C; J. P1 P1 O{( F: _- T) N: |% X
(*p).p.computeClock = (int*)malloc(initclocknum*sizeof(int));7 K8 Q4 V1 k U% x. a
(*p).p.ioClock = (int*)malloc(initclocknum*sizeof(int));
& i k6 a' h! a, }) @produce_one_task(&(*p),i,ID_FIFO++);7 e. d; c* _5 g
}
; f+ I" P a/ v; p+ b" Preturn 0;) ~( F. D7 r. y9 @" j& F4 w
}9 S2 p A* _: X( _" J' h. Y
int produce_one_task(processPool * p,int i,int id)
8 w) e; b7 y+ x, [5 e& @{
' u6 a( l/ M) Y8 [, s- i! e3 Q" A' bint time=MAX_COMING_TIME,j=0,totallTime=0;" a0 M9 y/ m: ~% @! u
(*p).p.processID = initProcessID+id;
1 W* ^0 z" v7 n9 B) m(*p).p.comeingTime = time+rand()%(MAXProcessRunTime/5);9 b; Q$ I! @& g+ f6 s* R$ {7 g( c
(*p).p.produceTime = systemClock;8 I# _3 {3 u8 q4 M4 ` g4 g( _
(*p).p.ioNum = rand()%4+20; //IO number setting to 2--5;
! u; o) R6 E7 r, D3 G(*p).p.computeNum = rand()%4+30; //computNum setting to 3--6;
( c( V$ V: i) ~8 h/ Q8 w- vtotallTime = (*p).p.computeNum + (*p).p.ioNum;) k/ s) {" Q' y( U2 b$ P& j: S' V
(*p).p.computeTime=0;# N$ o b) @ g9 \7 y
for(j=0; j<(*p).p.computeNum; j++)
0 a) ^+ W0 o6 i& T0 c& u a9 Q{3 e: _5 ^; Q p! t- f$ N
(*p).p.computeClock[j]=rand()%(MAXProcessRunTime/totallTime)+1;
+ J+ z o& m6 S! u; W/ r8 c$ e(*p).p.computeTime += (*p).p.computeClock[j];# f) O: s& c N) J8 ?
}1 F3 k. {; s) G! y$ L. s0 G) ^
(*p).p.ioTime=0;" s6 s- J6 R% |% ]
for(j=0; j<(*p).p.ioNum; j++) |
|