From cfcf3f10ecfc7dd6004e6b3fa5b67ce1a565cab0 Mon Sep 17 00:00:00 2001 From: codejune Date: Sat, 13 Nov 2021 23:43:29 +0900 Subject: [PATCH 1/6] Project initialization --- .gitignore | 63 ++++++++++++++++++++++++++++++++++++++++ Makefile | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ common.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ common.h | 36 +++++++++++++++++++++++ fifo.c | 29 +++++++++++++++++++ fifo.h | 19 ++++++++++++ lru.c | 17 +++++++++++ lru.h | 18 ++++++++++++ opt.c | 17 +++++++++++ opt.h | 18 ++++++++++++ sc.c | 17 +++++++++++ sc.h | 18 ++++++++++++ 12 files changed, 419 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 common.c create mode 100644 common.h create mode 100644 fifo.c create mode 100644 fifo.h create mode 100644 lru.c create mode 100644 lru.h create mode 100644 opt.c create mode 100644 opt.h create mode 100644 sc.c create mode 100644 sc.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ad220cf --- /dev/null +++ b/.gitignore @@ -0,0 +1,63 @@ +# Execute files +fifo +cs +lru +opt + +# Temporary files +.dependency +*.sh +*.txt + +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6b6f7ac --- /dev/null +++ b/Makefile @@ -0,0 +1,82 @@ +.SUFFIXES: .c .o +.PHONY: dep all new clean + +# Compiler +CC = gcc +# Compile option +# -c: Generate object file +# -W, -Wall: Print warning about all ambigous grammer +# -Wextra: Print warning out of -W, -Wall +# -O2: Optimization +# -g: Debugging, PLEASE DELETE AFTER PROJECT COMPLETE! +CFLAGS = -c -W -Wall -Wextra -g $(INCS) + +# Execute program file +LRU = lru +FIFO = fifo +OPT = opt +SC = sc + +# Source file +COMMON_SRCS = common.c +LRU_SRCS = lru.c +FIFO_SRCS = fifo.c +OPT_SRCS = opt.c +SC_SRCS = sc.c +SRCS = $(COMMON_SRCS) $(LRU_SRCS) $(FIFO_SRCS) $(OPT_SRCS) $(SC_SRCS) + +# Object file +COMMON_OBJS = $(COMMON_SRCS:.c=.o) +LRU_OBJS = $(LRU_SRCS:.c=.o) +FIFO_OBJS = $(FIFO_SRCS:.c=.o) +OPT_OBJS = $(OPT_SRCS:.c=.o) +SC_OBJS = $(SC_SRCS:.c=.o) +OBJS = $(COMMON_OBJS) $(LRU_OBJS) $(FIFO_OBJS) $(OPT_OBJS) $(SC_OBJS) +# Library file +LIBS = +# Include path +INCS = + +# Execute file grneration +# $@ = TARGET +# $^ = DEPENDENCY +all : $(OBJS) + $(CC) -o $(LRU) $(LRU_OBJS) $(LIBS) + $(CC) -o $(FIFO) $(COMMON_OBJS) $(FIFO_OBJS) $(LIBS) + $(CC) -o $(OPT) $(OPT_OBJS) $(LIBS) + $(CC) -o $(SC) $(SC_OBJS) $(LIBS) +$(LRU) : $(LRU_OBJS) + $(CC) -o $@ $^ $(LIBS) +$(FIFO) : $(FIFO_OBJS) $(COMMON_OBJS) + $(CC) -o $@ $^ $(LIBS) +$(OPT) : $(OPT_OBJS) + $(CC) -o $@ $^ $(LIBS) +$(SC) : $(SC_OBJS) + $(CC) -o $@ $^ $(LIBS) + +# Object file generation +# $(OBJS): +# $(CC) $(CFLAGS) $(SRCS) +# $(COMMON_OBJS): +# $(CC) $(CFLAGS) $(COMMON_SRCS) +# $(LRU_OBJS): +# $(CC) $(CFLAGS) $(LRU_SRCS) +# $(FIFO_OBJS): +# $(CC) $(CFLAGS) $(FIFO_SRCS) +# $(OPT_OBJS): +# $(CC) $(CFLAGS) $(OPT_SRCS) +# $(SC_OBJS): +# $(CC) $(CFLAGS) $(SC_SRCS) + +# make dep: Make dependency information file +dep: + $(CC) -M $(INC) $(SRCS) > .dependency + +# make new: Re-generation +new: + $(MAKE) clean + $(MAKE) all + +# make clean: Remove all generated file +clean: + rm *.o $(LRU) $(FIFO) $(OPT) $(SC) diff --git a/common.c b/common.c new file mode 100644 index 0000000..0c9e4cf --- /dev/null +++ b/common.c @@ -0,0 +1,85 @@ +/** + * @file common.c + * @brief 프로젝트에서 공통적으로 사용되는 함수 정의 + * @author 김병준 (kbj9704@gmail.com) + */ +#include "common.h" + +uint8_t g_pg_frms = 0; // Page frames +uint8_t g_pg_ref[BUFFER_SIZE] = {0}; // Page reference list +uint8_t g_pg_ref_cnt = 0; // Page reference count + +/** + * @brief Initialization to global variables + */ +void init(void) +{ + FILE *fp; + char buffer[BUFFER_SIZE]; + + // Get input file path + printf("Input file path > "); + scanf("%s", buffer); + + // Open input file + if ((fp = fopen(buffer, "r")) == NULL) + { + fprintf(stderr, "fopen error for %s\n", buffer); + exit(EXIT_FAILURE); + } + + // Read and set page frms + fscanf(fp, "%hhd\n%[^\n]", &g_pg_frms, buffer); + + // Set page references + set_page_references(buffer); +} + +/** + * @brief Tokenize buffer and set page references + * @param buffer Buffer to tokenize + */ +void set_page_references(char *buffer) +{ + char *token; + + token = strtok(buffer, " "); + while (token != NULL) + { + g_pg_ref[g_pg_ref_cnt++] = atoi(token); + token = strtok(NULL, " "); + } +} + +/** + * @brief Print virtual memory paging method simulator result + * @param method Paging method + */ +void print_header(uint8_t method) +{ + uint8_t i; + printf("Used method : "); + switch (method) + { + case METHOD_OPT: + printf("OPT\n"); + break; + case METHOD_FIFO: + printf("FIFO\n"); + break; + case METHOD_LRU: + printf("LRU\n"); + break; + case METHOD_SC: + printf("SC\n"); + break; + } + printf("Page frames: %hhd\n", g_pg_frms); + printf("Page reference string: "); + for (i = 0; i < g_pg_ref_cnt; i++) + printf("%hhd ", g_pg_ref[i]); + printf("\n\tframe"); + for (uint8_t i = 0; i < g_pg_frms; i++) + printf("\t%d", i + 1); + printf("\tpage fault\ntime\n"); +} \ No newline at end of file diff --git a/common.h b/common.h new file mode 100644 index 0000000..6843d1c --- /dev/null +++ b/common.h @@ -0,0 +1,36 @@ +/** + * @file common.h + * @author 김병준 (kbj9704@gmail.com) + * @brief 시뮬레이터 구현에 필요한 공통 헤더, 함수 및 매크로 정의 + */ +#ifndef COMMON_H +#define COMMON_H + +// header +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Macro +#define BUFFER_SIZE 256 +#define METHOD_OPT 1 +#define METHOD_FIFO 2 +#define METHOD_LRU 3 +#define METHOD_SC 4 +#define MAX_FRAMES 32 + +// Global Variable + +// Function prototype +void init(void); +void set_page_references(char *buffer); +void print_header(uint8_t method); + +#endif \ No newline at end of file diff --git a/fifo.c b/fifo.c new file mode 100644 index 0000000..35ddd74 --- /dev/null +++ b/fifo.c @@ -0,0 +1,29 @@ +/** + * @file cfs.c + * @author 김병준 (kbj9704@gmail.com) + * @brief FIFO 페이징 기법 시뮬레이션을 위한 함수 구현 + */ +#include "fifo.h" + +extern uint8_t g_pg_frms; +extern uint8_t g_pg_ref[BUFFER_SIZE]; +extern uint8_t g_pg_ref_cnt; + +/** + * @brief Main entry function + * @return int OK 0, ERROR 1 + */ +int main(void) +{ + init(); // Initialize header(Page frames, Page references) + print_header(METHOD_FIFO); + simulate(); // Simulate FIFO + exit(EXIT_SUCCESS); +} + +void simulate(void) +{ + uint8_t frms[MAX_FRAMES] = {0}; + + +} \ No newline at end of file diff --git a/fifo.h b/fifo.h new file mode 100644 index 0000000..a37f418 --- /dev/null +++ b/fifo.h @@ -0,0 +1,19 @@ +/** + * @file fifo.h + * @author 김병준 (kbj9704@gmail.com) + * @brief FIFO 페이징 기법 구현에 필요한 헤더, 함수 및 매크로 정의 + */ +#ifndef FIFO_H +#define FIFO_H + +// header +#include "common.h" + +// Macro + +// Global Variable + +// Function prototype +void simulate(void); + +#endif \ No newline at end of file diff --git a/lru.c b/lru.c new file mode 100644 index 0000000..ebba021 --- /dev/null +++ b/lru.c @@ -0,0 +1,17 @@ +/** + * @file cfs.c + * @author 김병준 (kbj9704@gmail.com) + * @brief LRU 페이징 기법 시뮬레이션을 위한 함수 구현 + */ +#include "common.h" +#include "lru.h" + +/** + * @brief Main entry function + * @return int OK 0, ERROR 1 + */ +int main(void) +{ + printf("hello\n"); + exit(EXIT_SUCCESS); +} \ No newline at end of file diff --git a/lru.h b/lru.h new file mode 100644 index 0000000..a1c8549 --- /dev/null +++ b/lru.h @@ -0,0 +1,18 @@ +/** + * @file lru.h + * @author 김병준 (kbj9704@gmail.com) + * @brief LRU 페이징 기법 구현에 필요한 헤더, 함수 및 매크로 정의 + */ +#ifndef LRU_H +#define LRU_H + +// header +#include "common.h" + +// Macro + +// Global Variable + +// Function prototype + +#endif \ No newline at end of file diff --git a/opt.c b/opt.c new file mode 100644 index 0000000..6e115ab --- /dev/null +++ b/opt.c @@ -0,0 +1,17 @@ +/** + * @file cfs.c + * @author 김병준 (kbj9704@gmail.com) + * @brief OPT 페이징 기법 시뮬레이션을 위한 함수 구현 + */ +#include "common.h" +#include "opt.h" + +/** + * @brief Main entry function + * @return int OK 0, ERROR 1 + */ +int main(void) +{ + printf("hello\n"); + exit(EXIT_SUCCESS); +} \ No newline at end of file diff --git a/opt.h b/opt.h new file mode 100644 index 0000000..28ed147 --- /dev/null +++ b/opt.h @@ -0,0 +1,18 @@ +/** + * @file opt.h + * @author 김병준 (kbj9704@gmail.com) + * @brief OPT 페이징 기법 구현에 필요한 헤더, 함수 및 매크로 정의 + */ +#ifndef OPT_H +#define OPT_H + +// header +#include "common.h" + +// Macro + +// Global Variable + +// Function prototype + +#endif \ No newline at end of file diff --git a/sc.c b/sc.c new file mode 100644 index 0000000..14a8375 --- /dev/null +++ b/sc.c @@ -0,0 +1,17 @@ +/** + * @file cfs.c + * @author 김병준 (kbj9704@gmail.com) + * @brief Second Chance 페이징 기법 시뮬레이션을 위한 함수 구현 + */ +#include "common.h" +#include "sc.h" + +/** + * @brief Main entry function + * @return int OK 0, ERROR 1 + */ +int main(void) +{ + printf("hello\n"); + exit(EXIT_SUCCESS); +} \ No newline at end of file diff --git a/sc.h b/sc.h new file mode 100644 index 0000000..2e2f0ab --- /dev/null +++ b/sc.h @@ -0,0 +1,18 @@ +/** + * @file sc.h + * @author 김병준 (kbj9704@gmail.com) + * @brief Second Chance 페이징 기법 구현에 필요한 헤더, 함수 및 매크로 정의 + */ +#ifndef SC_H +#define SC_H + +// header +#include "common.h" + +// Macro + +// Global Variable + +// Function prototype + +#endif \ No newline at end of file From 680bb908845d6073d7054e579c7c9464486d035c Mon Sep 17 00:00:00 2001 From: codejune Date: Sun, 14 Nov 2021 00:13:33 +0900 Subject: [PATCH 2/6] Complete FIFO pageing method --- fifo.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- sc | Bin 0 -> 19384 bytes 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100755 sc diff --git a/fifo.c b/fifo.c index 35ddd74..0df02bd 100644 --- a/fifo.c +++ b/fifo.c @@ -23,7 +23,49 @@ int main(void) void simulate(void) { - uint8_t frms[MAX_FRAMES] = {0}; + int16_t frms[MAX_FRAMES] = {-1}; + uint8_t last_idx = 0; + uint8_t i, j; + bool is_pg_fault = true; + uint8_t pg_fault_cnt = 0; - + // Initialize frame array + memset(frms, -1, sizeof(frms)); + + for (i = 0; i < g_pg_ref_cnt; i++) + { + // Find page reference in page frames + for (j = 0; j < g_pg_frms; j++) + // If page reference is in page frames + if (g_pg_ref[i] == frms[j]) + { + is_pg_fault = false; + break; + } + + // If page reference is not in page frames + if (is_pg_fault) { + frms[last_idx++] = g_pg_ref[i]; + pg_fault_cnt++; + } + + // If page frames is full + if (last_idx == g_pg_frms) + last_idx = 0; + + // Print sequence of page frames + printf("%hhd\t\t", i + 1); + for (j = 0; j < g_pg_frms; j++) + if (frms[j] != -1) + printf("%hhd\t", frms[j]); + else + printf("\t"); + if (is_pg_fault) + printf("F"); + printf("\n"); + + // Reset page fault status + is_pg_fault = true; + } + printf("Number of page faults: %hhd times\n", pg_fault_cnt); } \ No newline at end of file diff --git a/sc b/sc new file mode 100755 index 0000000000000000000000000000000000000000..c746ebbdff3113e288b2890ee36a599251187813 GIT binary patch literal 19384 zcmeHPYj7Lab-n-y0xObBP?T&^YNNHHxRxD&luS{SY=!_|0zK5jGUZn+uRvf4BF2LS z7Lu6hBytodVQr;KGt)R3dq)11Odm7qOgoh)X)V`@l1ZA5HPeSXZc?YIrgEBx>^d1I zu7!T*?mf_A2`1A{{%hSrMNJz zDj;z&BD!$iCf+OB!M917qmMfTTBp3?Z=_)*4}cP`k19>*Z#ZJXlzT{&aBG!8>JSQ3 zp~gYDASo2@r5ja0nXpZj=c7_B&W|?IW6Iy6qKqS!a2FNs zqQWt~ru;GGcv4L07*X-`QUf|FhCB=5#XYESUOK7lnUW7G_g%3w{~LdY6t2^d%?K}L zKTO%*y}+qU>i~bnnJ@EUhcET^^nBq6w?RJ1 zh6>?%N)S)=5Dv0&#{W2Kj*RGK>u(E0*DB*s7)_Ma_w`NW+t!dj3c1n5zGDr0>QpoP zjgW7}v8o{6X$tSKuukS|u~fAy!Zgz-Q|3ahn9AoqY=I>svtp;pwpmE!ielgF%=m=4 zGqy9fOPDir`^}71wz9d3ZI$QtPvlEQYc4gPCuFuzDk`Mum^L+(-SW$*Q{?@KJN>)y zu~FTW(?~w72Eg|<-%rPS9K{87-?H3L@^IYIvz+-?#vD0aWAex4HJ6;{7U{0KfUF zdw!8T{ljqb$>2W?2$6i^qV2D}oIL&2@Jn)BwOzjt@td{xeHNs9iy-?&(!BZl_iDA; zS;`zg;^tH+v?yfEJTyx_*Lo zlV?U>1gUM@3CLS#!9Ija@=WkBkv(tQ8_{*0>gc*wd#!uRDVU3w6ovhEX}@bLk?q%$ zE7y`Q{&+0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w3wT^K3DL)|hkJa3-9C;5uBT3OO|9z!7f|!(=aD z0z+oaSF^B86|=ZA6q_q9l(?RnpD$a-nZpizi|dGBv%BwqETeC7+{*Z@b_(Z_O!;?D zrIxl_C;DC-^jjn2Ip1VzK<6&bZ)7(lw13=*MF&dzoH@jtY&D;>`Fy5~AdAkW2Q@c{9^b zl98)W8}9PkVCc74#&dpMr^=Z7&vr~d0zLh<%RJ}db*k{*{wuLKg9^oz@tm(Sy{HV? zzjyqfQ}}UZSI_GeV9(tL?J|BJBPc$v;18sXzsFqUbpezz2U!aL-!vQ#_@He z{GNu$cwXO~R|(=F0=Wv~nYIJ$#*4Tz9&{-C;U*Zzd?&ypWB;5#Miky_PrlrR@_v#j z^SX-hx7Q_3h4D-`DZIx_>{ShV+hrWv%U_n6anTPc;9(w^(s}W_*6{z8I~~CHTy0X- zi=S8n|Ll+hyxjxvu;QS?d&l|pT@L;q>o=yuGu}--CerZSh-3dH^})IoEDedTCx3s@ j!yiwGBrrK93D#T= Date: Sun, 14 Nov 2021 00:14:38 +0900 Subject: [PATCH 3/6] Remove dummy execute file --- .gitignore | 2 +- sc | Bin 19384 -> 0 bytes 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100755 sc diff --git a/.gitignore b/.gitignore index ad220cf..1061f6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Execute files fifo -cs +sc lru opt diff --git a/sc b/sc deleted file mode 100755 index c746ebbdff3113e288b2890ee36a599251187813..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 19384 zcmeHPYj7Lab-n-y0xObBP?T&^YNNHHxRxD&luS{SY=!_|0zK5jGUZn+uRvf4BF2LS z7Lu6hBytodVQr;KGt)R3dq)11Odm7qOgoh)X)V`@l1ZA5HPeSXZc?YIrgEBx>^d1I zu7!T*?mf_A2`1A{{%hSrMNJz zDj;z&BD!$iCf+OB!M917qmMfTTBp3?Z=_)*4}cP`k19>*Z#ZJXlzT{&aBG!8>J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zi=S8n|Ll+hyxjxvu;QS?d&l|pT@L;q>o=yuGu}--CerZSh-3dH^})IoEDedTCx3s@ j!yiwGBrrK93D#T= Date: Tue, 16 Nov 2021 17:11:03 +0900 Subject: [PATCH 4/6] Finish --- Makefile | 12 +++---- common.c | 10 +++--- fifo.c | 38 ++++++++++----------- fifo.h | 3 ++ lru.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++-- lru.h | 4 +++ opt.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- opt.h | 4 +++ sc.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++--- sc.h | 4 +++ 10 files changed, 333 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index 6b6f7ac..7894133 100644 --- a/Makefile +++ b/Makefile @@ -41,17 +41,17 @@ INCS = # $@ = TARGET # $^ = DEPENDENCY all : $(OBJS) - $(CC) -o $(LRU) $(LRU_OBJS) $(LIBS) + $(CC) -o $(LRU) $(COMMON_OBJS) $(LRU_OBJS) $(LIBS) $(CC) -o $(FIFO) $(COMMON_OBJS) $(FIFO_OBJS) $(LIBS) - $(CC) -o $(OPT) $(OPT_OBJS) $(LIBS) - $(CC) -o $(SC) $(SC_OBJS) $(LIBS) -$(LRU) : $(LRU_OBJS) + $(CC) -o $(OPT) $(COMMON_OBJS) $(OPT_OBJS) $(LIBS) + $(CC) -o $(SC) $(COMMON_OBJS) $(SC_OBJS) $(LIBS) +$(LRU) : $(LRU_OBJS) $(COMMON_OBJS) $(CC) -o $@ $^ $(LIBS) $(FIFO) : $(FIFO_OBJS) $(COMMON_OBJS) $(CC) -o $@ $^ $(LIBS) -$(OPT) : $(OPT_OBJS) +$(OPT) : $(OPT_OBJS) $(COMMON_OBJS) $(CC) -o $@ $^ $(LIBS) -$(SC) : $(SC_OBJS) +$(SC) : $(SC_OBJS) $(COMMON_OBJS) $(CC) -o $@ $^ $(LIBS) # Object file generation diff --git a/common.c b/common.c index 0c9e4cf..84c38e0 100644 --- a/common.c +++ b/common.c @@ -5,7 +5,7 @@ */ #include "common.h" -uint8_t g_pg_frms = 0; // Page frames +uint8_t g_frms_cnt = 0; // Page frames uint8_t g_pg_ref[BUFFER_SIZE] = {0}; // Page reference list uint8_t g_pg_ref_cnt = 0; // Page reference count @@ -29,7 +29,7 @@ void init(void) } // Read and set page frms - fscanf(fp, "%hhd\n%[^\n]", &g_pg_frms, buffer); + fscanf(fp, "%hhd\n%[^\n]", &g_frms_cnt, buffer); // Set page references set_page_references(buffer); @@ -74,12 +74,12 @@ void print_header(uint8_t method) printf("SC\n"); break; } - printf("Page frames: %hhd\n", g_pg_frms); + printf("Page frames: %hhd\n", g_frms_cnt); printf("Page reference string: "); for (i = 0; i < g_pg_ref_cnt; i++) printf("%hhd ", g_pg_ref[i]); - printf("\n\tframe"); - for (uint8_t i = 0; i < g_pg_frms; i++) + printf("\n\n\tframe"); + for (uint8_t i = 0; i < g_frms_cnt; i++) printf("\t%d", i + 1); printf("\tpage fault\ntime\n"); } \ No newline at end of file diff --git a/fifo.c b/fifo.c index 0df02bd..6e9be67 100644 --- a/fifo.c +++ b/fifo.c @@ -1,14 +1,10 @@ /** - * @file cfs.c + * @file fifo.c * @author 김병준 (kbj9704@gmail.com) * @brief FIFO 페이징 기법 시뮬레이션을 위한 함수 구현 */ #include "fifo.h" -extern uint8_t g_pg_frms; -extern uint8_t g_pg_ref[BUFFER_SIZE]; -extern uint8_t g_pg_ref_cnt; - /** * @brief Main entry function * @return int OK 0, ERROR 1 @@ -21,21 +17,26 @@ int main(void) exit(EXIT_SUCCESS); } +/** + * @brief Simulte FIFO paging method + */ void simulate(void) { - int16_t frms[MAX_FRAMES] = {-1}; - uint8_t last_idx = 0; - uint8_t i, j; - bool is_pg_fault = true; + int16_t frms[MAX_FRAMES], last_idx = 0; + bool is_pg_fault; uint8_t pg_fault_cnt = 0; + uint8_t i, j; // Initialize frame array memset(frms, -1, sizeof(frms)); for (i = 0; i < g_pg_ref_cnt; i++) { + // Reset page fault status + is_pg_fault = true; + // Find page reference in page frames - for (j = 0; j < g_pg_frms; j++) + for (j = 0; j < g_frms_cnt; j++) // If page reference is in page frames if (g_pg_ref[i] == frms[j]) { @@ -44,18 +45,18 @@ void simulate(void) } // If page reference is not in page frames - if (is_pg_fault) { - frms[last_idx++] = g_pg_ref[i]; + if (is_pg_fault) + { pg_fault_cnt++; + frms[last_idx++] = g_pg_ref[i]; + // If page frames is full + if (last_idx == g_frms_cnt) + last_idx = 0; } - // If page frames is full - if (last_idx == g_pg_frms) - last_idx = 0; - // Print sequence of page frames printf("%hhd\t\t", i + 1); - for (j = 0; j < g_pg_frms; j++) + for (j = 0; j < g_frms_cnt; j++) if (frms[j] != -1) printf("%hhd\t", frms[j]); else @@ -63,9 +64,6 @@ void simulate(void) if (is_pg_fault) printf("F"); printf("\n"); - - // Reset page fault status - is_pg_fault = true; } printf("Number of page faults: %hhd times\n", pg_fault_cnt); } \ No newline at end of file diff --git a/fifo.h b/fifo.h index a37f418..83b6ac8 100644 --- a/fifo.h +++ b/fifo.h @@ -12,6 +12,9 @@ // Macro // Global Variable +extern uint8_t g_frms_cnt; +extern uint8_t g_pg_ref[BUFFER_SIZE]; +extern uint8_t g_pg_ref_cnt; // Function prototype void simulate(void); diff --git a/lru.c b/lru.c index ebba021..4ec3185 100644 --- a/lru.c +++ b/lru.c @@ -1,9 +1,8 @@ /** - * @file cfs.c + * @file lru.c * @author 김병준 (kbj9704@gmail.com) * @brief LRU 페이징 기법 시뮬레이션을 위한 함수 구현 */ -#include "common.h" #include "lru.h" /** @@ -12,6 +11,99 @@ */ int main(void) { - printf("hello\n"); + init(); // Initialize header(Page frames, Page references) + print_header(METHOD_LRU); + simulate(); // Simulate FIFO exit(EXIT_SUCCESS); +} + +/** + * @brief Simulte LRU paging method + */ +void simulate(void) +{ + int16_t frms[MAX_FRAMES]; + uint8_t ru_queue[MAX_FRAMES] = {0}, ru_queue_end = -1, lrup; + bool is_pg_fault, is_pg_full; + uint8_t pg_fault_cnt = 0; + uint8_t i, j, k; + + // Initialize frame array + memset(frms, -1, sizeof(frms)); + + for (i = 0; i < g_pg_ref_cnt; i++) + { + // Reset page fault status + is_pg_fault = true; + is_pg_full = true; + + // Find page reference in page frames + for (j = 0; j < g_frms_cnt; j++) + + // If page reference is in page frames + if (g_pg_ref[i] == frms[j]) + { + // Update page fault status + is_pg_fault = false; + + // Find last using frame in queue + for (k = 0; k < ru_queue_end; k++) + if (ru_queue[k] == j) + { + lrup = k; + break; + } + + // Update queue + for (k = lrup; k < ru_queue_end; k++) + ru_queue[k] = ru_queue[k + 1]; + ru_queue[ru_queue_end] = j; + break; + } + + // If page reference is not in page frames + if (is_pg_fault) + { + // Find empty frame + for (j = 0; j < g_frms_cnt; j++) + + // If empty frame is found + if (frms[j] < 0) + { + // Set page reference to empty frame + frms[j] = g_pg_ref[i]; + ru_queue[ru_queue_end++] = j; + is_pg_full = false; + break; + } + + // If all frames are full + if (is_pg_full) + { + // Pop page reference from page queue + lrup = ru_queue[0]; + + // Update frame + frms[lrup] = g_pg_ref[i]; + + // Update queue + for (j = 0; j < ru_queue_end; j++) + ru_queue[j] = ru_queue[j + 1]; + ru_queue[ru_queue_end] = lrup; + } + pg_fault_cnt++; + } + + // Print sequence of page frames + printf("%hhd\t\t", i + 1); + for (j = 0; j < g_frms_cnt; j++) + if (frms[j] != -1) + printf("%hhd\t", frms[j]); + else + printf("\t"); + if (is_pg_fault) + printf("F"); + printf("\n"); + } + printf("Number of page faults: %hhd times\n", pg_fault_cnt); } \ No newline at end of file diff --git a/lru.h b/lru.h index a1c8549..1991e92 100644 --- a/lru.h +++ b/lru.h @@ -12,7 +12,11 @@ // Macro // Global Variable +extern uint8_t g_frms_cnt; +extern uint8_t g_pg_ref[BUFFER_SIZE]; +extern uint8_t g_pg_ref_cnt; // Function prototype +void simulate(void); #endif \ No newline at end of file diff --git a/opt.c b/opt.c index 6e115ab..64e18d8 100644 --- a/opt.c +++ b/opt.c @@ -1,9 +1,8 @@ /** - * @file cfs.c + * @file opt.c * @author 김병준 (kbj9704@gmail.com) * @brief OPT 페이징 기법 시뮬레이션을 위한 함수 구현 */ -#include "common.h" #include "opt.h" /** @@ -12,6 +11,103 @@ */ int main(void) { - printf("hello\n"); + init(); // Initialize header(Page frames, Page references) + print_header(METHOD_OPT); + simulate(); // Simulate OPT exit(EXIT_SUCCESS); +} + +/** + * @brief Simulte OPT paging method + */ +void simulate(void) +{ + int16_t frms[MAX_FRAMES], lgst_frm_idx, lgst_pg_idx; + bool is_pg_fault, is_pg_full, is_pg_used; + uint8_t pg_fault_cnt = 0; + uint8_t i, j, k; + + // Initialize frame array + memset(frms, -1, sizeof(frms)); + + for (i = 0; i < g_pg_ref_cnt; i++) + { + // Reset page fault status + is_pg_fault = true; + is_pg_full = true; + + // Find page reference in page frames + for (j = 0; j < g_frms_cnt; j++) + + // If page reference is in page frames + if (g_pg_ref[i] == frms[j]) + { + // Update page fault status + is_pg_fault = false; + break; + } + + // If page reference is not in page frames + if (is_pg_fault) + { + // Find empty frame + for (j = 0; j < g_frms_cnt; j++) + + // If empty frame is found + if (frms[j] < 0) + { + // Set page reference to empty frame + frms[j] = g_pg_ref[i]; + is_pg_full = false; + break; + } + + // If all frames are full + if (is_pg_full) + { + lgst_pg_idx = i; // Reference page index which will not be used for the most longest time + + for (j = 0; j < g_frms_cnt; j++) + { + is_pg_used = false; + + // Find future page reference + for (k = i + 1; k < g_pg_ref_cnt; k++) + if (g_pg_ref[k] == frms[j]) + { + if (k > lgst_pg_idx) + { + lgst_frm_idx = j; + lgst_pg_idx = k; + } + is_pg_used = true; + break; + } + + // If cannot find page which using future + if (!is_pg_used) + { + lgst_frm_idx = j; + break; + } + } + + frms[lgst_frm_idx] = g_pg_ref[i]; + } + pg_fault_cnt++; + } + + // Print sequence of page frames + printf("%hhd\t\t", i + 1); + for (j = 0; j < g_frms_cnt; j++) + if (frms[j] != -1) + printf("%hhd\t", frms[j]); + else + printf("\t"); + if (is_pg_fault) + printf("F"); + printf("\n"); + } + + printf("Number of page faults: %hhd times\n", pg_fault_cnt); } \ No newline at end of file diff --git a/opt.h b/opt.h index 28ed147..fc3d4af 100644 --- a/opt.h +++ b/opt.h @@ -12,7 +12,11 @@ // Macro // Global Variable +extern uint8_t g_frms_cnt; +extern uint8_t g_pg_ref[BUFFER_SIZE]; +extern uint8_t g_pg_ref_cnt; // Function prototype +void simulate(void); #endif \ No newline at end of file diff --git a/sc.c b/sc.c index 14a8375..6f7debd 100644 --- a/sc.c +++ b/sc.c @@ -1,9 +1,8 @@ /** - * @file cfs.c + * @file sc.c * @author 김병준 (kbj9704@gmail.com) - * @brief Second Chance 페이징 기법 시뮬레이션을 위한 함수 구현 + * @brief SC 페이징 기법 시뮬레이션을 위한 함수 구현 */ -#include "common.h" #include "sc.h" /** @@ -12,6 +11,98 @@ */ int main(void) { - printf("hello\n"); + init(); // Initialize header(Page frames, Page references) + print_header(METHOD_SC); + simulate(); // Simulate FIFO exit(EXIT_SUCCESS); +} + +/** + * @brief Simulte Second Chance paging method + */ +void simulate(void) +{ + int16_t frms[MAX_FRAMES], last_idx = 0; + bool rf_frms[MAX_FRAMES]; + bool is_pg_fault, is_pg_full, is_updated; + uint8_t pg_fault_cnt = 0; + uint8_t i, j; + + // Initialize frame array + memset(frms, -1, sizeof(frms)); + memset(rf_frms, false, sizeof(rf_frms)); + + for (i = 0; i < g_pg_ref_cnt; i++) + { + // Reset page fault status + is_pg_fault = true; + is_pg_full = true; + + // Find page reference in page frames + for (j = 0; j < g_frms_cnt; j++) + + // If page reference is in page frames + if (g_pg_ref[i] == frms[j]) + { + // Update status + is_pg_fault = false; + rf_frms[j] = true; + break; + } + + // If page reference is not in page frames + if (is_pg_fault) + { + // Find empty frame + for (j = 0; j < g_frms_cnt; j++) + + // If empty frame is found + if (frms[j] < 0) + { + // Set page reference to empty frame + frms[j] = g_pg_ref[i]; + is_pg_full = false; + break; + } + + // If all frames are full + if (is_pg_full) + { + is_updated = false; + + while (!is_updated) + { + for (j = last_idx; j < g_frms_cnt; j++) + { + if (rf_frms[j]) + rf_frms[j] = false; + else + { + last_idx++; + frms[j] = g_pg_ref[i]; + rf_frms[j] = true; + is_updated = true; + break; + } + } + + if (last_idx == g_frms_cnt) + last_idx = 0; + } + } + pg_fault_cnt++; + } + + // Print sequence of page frames + printf("%hhd\t\t", i + 1); + for (j = 0; j < g_frms_cnt; j++) + if (frms[j] != -1) + printf("%hhd\t", frms[j]); + else + printf("\t"); + if (is_pg_fault) + printf("F"); + printf("\n"); + } + printf("Number of page faults: %hhd times\n", pg_fault_cnt); } \ No newline at end of file diff --git a/sc.h b/sc.h index 2e2f0ab..20b4015 100644 --- a/sc.h +++ b/sc.h @@ -12,7 +12,11 @@ // Macro // Global Variable +extern uint8_t g_frms_cnt; +extern uint8_t g_pg_ref[BUFFER_SIZE]; +extern uint8_t g_pg_ref_cnt; // Function prototype +void simulate(void); #endif \ No newline at end of file From 8e5ddcc21b84b24d80a717de89633a7165f28a6c Mon Sep 17 00:00:00 2001 From: codejune Date: Tue, 16 Nov 2021 21:41:52 +0900 Subject: [PATCH 5/6] Add README.md --- README.md | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c717e19 --- /dev/null +++ b/README.md @@ -0,0 +1,144 @@ +# Virtual Memory Paging Simulator +가상메모리 관리 기법의 하나인 페이지 교체 기법 중 OPT, FIFO, LRU, Second-Chance +를 구현하고 동작 과정을 보여주는 시뮬레이터 구현하기 + +## 0. 빠른 시작 +``` bash +$ git clone https://github.com/codejune/c-virtual-memory-simulator.git +$ cd c-virtual-memory-simulator + +# 일괄 빌드 +$ make + +# 개별 빌드 +$ make opt +$ ./opt +``` + +## 1. 환경 +### a. SW +- Ubuntu 20.04.3 LTS (x86_64) +- Linux Kernel 5.11.22 +### b. HW +- VM Instance +- 4 Core 8 Thread +- 8 GB RAM +- 60 GB Storage + +## 2. 요구사항 +### a. 페이징 기법 단축어 +- OPT: opt +- FIFO: fifo +- LRU: lru +- Second-Chance: sc +### b. 제약 사항 +- Page frame: min 1, max 4 +- Page reference string: min 1, max 30 +- Second-Chance 기법의 경우 참조 기록에 대한 주기적 Refresh는 없다고 가정 +### c. 구현 사항 +- 실행 초기화면에서 입력 데이터의 파일 이름을 입력 받음 +- 입력 데이터에는 Page frame 수, Page reference string 값 포함 +- 각 기법간 Paging 과정 및 page fault 발생 출력 +### d. 예시 +- 입력 데이터 + ``` bash + $ cat input.txt + 3 # Page frame 수 + 2 3 2 1 5 2 4 5 3 2 5 2 # Page reference string + ``` +- 출력 결과 (OPT) + ``` bash + $ ./opt + Input file path > input.txt + Used method : OPT + Page frames: 3 + Page reference string: 2 3 2 1 5 2 4 5 3 2 5 2 + + frame 1 2 3 page fault + time + 1 2 F + 2 2 3 F + 3 2 3 + 4 2 3 1 F + 5 2 3 5 F + 6 2 3 5 + 7 4 3 5 F + 8 4 3 5 + 9 4 3 5 + 10 2 3 5 F + 11 2 3 5 + 12 2 3 5 + Number of page faults: 6 times + ``` +- 출력 결과 (FIFO) + ``` bash + $ ./fifo + Input file path > input.txt + Used method : FIFO + Page frames: 3 + Page reference string: 2 3 2 1 5 2 4 5 3 2 5 2 + + frame 1 2 3 page fault + time + 1 2 F + 2 2 3 F + 3 2 3 + 4 2 3 1 F + 5 5 3 1 F + 6 5 2 1 F + 7 5 2 4 F + 8 5 2 4 + 9 3 2 4 F + 10 3 2 4 + 11 3 5 4 F + 12 3 5 2 F + Number of page faults: 9 times + ``` +- 출력 결과 (LRU) + ``` bash + $ ./lru + Input file path > input.txt + Used method : LRU + Page frames: 3 + Page reference string: 2 3 2 1 5 2 4 5 3 2 5 2 + + frame 1 2 3 page fault + time + 1 2 F + 2 2 3 F + 3 2 3 + 4 2 3 1 F + 5 2 5 1 F + 6 2 5 1 + 7 2 5 4 F + 8 2 5 4 + 9 3 5 4 F + 10 3 5 2 F + 11 3 5 2 + 12 3 5 2 + Number of page faults: 7 times + ``` +- 출력 결과 (Second-Chance) + ``` bash + $ ./sc + Input file path > input.txt + Used method : SC + Page frames: 3 + Page reference string: 2 3 2 1 5 2 4 5 3 2 5 2 + + frame 1 2 3 page fault + time + 1 2 F + 2 2 3 F + 3 2 3 + 4 2 3 1 F + 5 2 5 1 F + 6 2 5 1 + 7 2 5 4 F + 8 2 5 4 + 9 2 5 3 F + 10 2 5 3 + 11 2 5 3 + 12 2 5 3 + Number of page faults: 6 times + ``` From 9bce06bd3cd1fa93576c48612cd785d4b6eabddf Mon Sep 17 00:00:00 2001 From: codejune Date: Thu, 18 Nov 2021 23:38:12 +0900 Subject: [PATCH 6/6] Update README.md --- README.md | 58 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c717e19..b082135 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # Virtual Memory Paging Simulator -가상메모리 관리 기법의 하나인 페이지 교체 기법 중 OPT, FIFO, LRU, Second-Chance -를 구현하고 동작 과정을 보여주는 시뮬레이터 구현하기 -## 0. 빠른 시작 +가상메모리 관리 기법의 하나인 페이지 교체 기법 중 OPT, FIFO, LRU, Second-Chance를 구현하고 동작 과정을 보여주는 시뮬레이터 구현하기 + +## 0. Quick start + ``` bash $ git clone https://github.com/codejune/c-virtual-memory-simulator.git $ cd c-virtual-memory-simulator @@ -15,38 +16,53 @@ $ make opt $ ./opt ``` -## 1. 환경 -### a. SW +## 1. Environment + +### Software + - Ubuntu 20.04.3 LTS (x86_64) - Linux Kernel 5.11.22 -### b. HW + +### Hardware + - VM Instance -- 4 Core 8 Thread +- 4 Core 8 Thread - 8 GB RAM - 60 GB Storage -## 2. 요구사항 -### a. 페이징 기법 단축어 +## 2. Requirement + +### 페이징 기법 단축어 + - OPT: opt - FIFO: fifo - LRU: lru - Second-Chance: sc -### b. 제약 사항 + +### 입력 + - Page frame: min 1, max 4 - Page reference string: min 1, max 30 -- Second-Chance 기법의 경우 참조 기록에 대한 주기적 Refresh는 없다고 가정 -### c. 구현 사항 + +### 조건 + - 실행 초기화면에서 입력 데이터의 파일 이름을 입력 받음 - 입력 데이터에는 Page frame 수, Page reference string 값 포함 - 각 기법간 Paging 과정 및 page fault 발생 출력 -### d. 예시 -- 입력 데이터 +- Second-Chance 기법의 경우 참조 기록에 대한 주기적 Refresh는 없다고 가정 + +### 출력 + +- Input data + ``` bash $ cat input.txt 3 # Page frame 수 2 3 2 1 5 2 4 5 3 2 5 2 # Page reference string ``` -- 출력 결과 (OPT) + +- Output (OPT) + ``` bash $ ./opt Input file path > input.txt @@ -70,7 +86,9 @@ $ ./opt 12 2 3 5 Number of page faults: 6 times ``` -- 출력 결과 (FIFO) + +- Output (FIFO) + ``` bash $ ./fifo Input file path > input.txt @@ -94,7 +112,9 @@ $ ./opt 12 3 5 2 F Number of page faults: 9 times ``` -- 출력 결과 (LRU) + +- Output (LRU) + ``` bash $ ./lru Input file path > input.txt @@ -118,7 +138,9 @@ $ ./opt 12 3 5 2 Number of page faults: 7 times ``` -- 출력 결과 (Second-Chance) + +- Output (Second-Chance) + ``` bash $ ./sc Input file path > input.txt