aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2024-11-05 10:31:20 -0700
committerJack Sangdahl <[email protected]>2024-11-05 10:31:20 -0700
commitb84375f891085d385c2a19a1e8e1bd21171ef91b (patch)
tree48ad8761587674c97adc790c4ef2970e52f0d60e
parent571f79fee9bbe89f544f5453d36243e59c7dcb8e (diff)
downloadcsci3753-b84375f891085d385c2a19a1e8e1bd21171ef91b.tar.gz
csci3753-b84375f891085d385c2a19a1e8e1bd21171ef91b.zip
pa7: improvements
-rw-r--r--pa7_lru/Makefile44
-rw-r--r--pa7_lru/pager-lru.c8
2 files changed, 14 insertions, 38 deletions
diff --git a/pa7_lru/Makefile b/pa7_lru/Makefile
index bf179e3..1302716 100644
--- a/pa7_lru/Makefile
+++ b/pa7_lru/Makefile
@@ -1,42 +1,20 @@
-# CSCI3753 - FA23 PA7
-
-CC = gcc
-CFLAGS = -c -g -Wall -Wextra
-LFLAGS = -g -Wall -Wextra
+OBJS_COMMON = simulator.o programs.o
+OBJS_BASIC = pager-basic.o
+OBJS_LRU = pager-lru.o
VPATH += ../common
-
-SUBMITFILES = pager-lru.c
-
-.PHONY: all clean
+CFLAGS = -Wall -Wextra -g
all: test-basic test-lru
-test-basic: simulator.o pager-basic.o programs.o
- $(CC) $(LFLAGS) $^ -o $@
-
-test-lru: simulator.o pager-lru.o programs.o
- $(CC) $(LFLAGS) $^ -o $@
+test-basic: $(OBJS_COMMON) $(OBJS_BASIC)
+ cc $(CFLAGS) $^ -o $@
-simulator.o: simulator.c programs.o simulator.h
- $(CC) $(CFLAGS) $<
+test-lru: $(OBJS_COMMON) $(OBJS_LRU)
+ cc $(CFLAGS) $^ -o $@
-programs.o: programs.c simulator.h
- $(CC) $(CFLAGS) $<
-
-pager-basic.o: pager-basic.c simulator.h programs.c
- $(CC) $(CFLAGS) $<
-
-pager-lru.o: pager-lru.c simulator.h programs.c
- $(CC) $(CFLAGS) $<
+%.o: %.c
+ cc $(CFLAGS) -c $< -o $@
clean:
- rm -f test-basic test-lru test-predict test-api
- rm -f *.o
- rm -f *~
- rm -f *.csv
- rm -f *.pdf
-
-submit:
- @read -r -p "please enter your identikey username: " username; \
- tar -cvf PA7-$$username.txt $(SUBMITFILES)
+ rm *.o test-basic test-lru
diff --git a/pa7_lru/pager-lru.c b/pa7_lru/pager-lru.c
index 21e592f..14608d0 100644
--- a/pa7_lru/pager-lru.c
+++ b/pa7_lru/pager-lru.c
@@ -3,17 +3,16 @@
// PA7 LRU
#include "../common/simulator.h"
#include <stdbool.h>
+#include <string.h>
void pageit(Pentry q[MAXPROCESSES]) {
static int timestamps[MAXPROCESSES][MAXPROCPAGES], tick = 1;
static bool initialised = false;
if (!initialised) {
- for (int proc = 0; proc < MAXPROCESSES; proc++)
- for (int page = 0; page < MAXPROCPAGES; page++)
- timestamps[proc][page] = 0;
+ memset(timestamps, 0, sizeof(timestamps));
initialised = true;
}
- for (int proc = 0; proc < MAXPROCESSES; proc++) {
+ for (int proc = 0; proc < MAXPROCESSES; proc++)
if (q[proc].active) {
int curr = q[proc].pc / PAGESIZE;
timestamps[proc][curr] = tick;
@@ -28,6 +27,5 @@ void pageit(Pentry q[MAXPROCESSES]) {
pageout(proc, choice);
}
}
- }
tick++;
}