Commit 953e3065 authored by Caleb C. Sander's avatar Caleb C. Sander
Browse files

Fix #2

parent b3903296
No related merge requests found
Showing with 67 additions and 56 deletions
+67 -56
bin/*
out/*
.debug
#
# Makefile for the malloc lab driver
#
CC = clang
CFLAGS = -Werror -Wall -Wextra -O3 -g
all: bin/mdriver-implicit bin/mdriver-explicit
CLEAN_COMMAND = rm -f out/* bin/*
ifdef DEBUG
CC = clang-with-asan
CFLAGS = -Werror -Wall -Wextra
ifeq ($(wildcard .debug),)
$(shell $(CLEAN_COMMAND))
$(shell touch .debug)
endif
else
CC = clang
CFLAGS = -Werror -Wall -Wextra -O3 -g
ifneq ($(wildcard .debug),)
$(shell $(CLEAN_COMMAND) .debug)
endif
endif
bin/mdriver-implicit: out/mdriver-implicit.o out/mm-implicit.o out/memlib.o out/fsecs.o out/fcyc.o out/clock.o out/ftimer.o
$(CC) $(CFLAGS) $^ -o $@
all: bin/mdriver-implicit bin/mdriver-explicit
bin/mdriver-explicit: out/mdriver-explicit.o out/mm-explicit.o out/memlib.o out/fsecs.o out/fcyc.o out/clock.o out/ftimer.o
bin/mdriver-%: out/mdriver-%.o out/mm-%.o out/memlib.o out/fsecs.o out/fcyc.o out/clock.o
$(CC) $(CFLAGS) $^ -o $@
out/mdriver-implicit.o: driver/mdriver.c
......@@ -25,4 +36,6 @@ out/%.o: driver/%.c
$(CC) $(CFLAGS) -c $^ -o $@
clean:
rm -f out/* bin/*
$(CLEAN_COMMAND)
.PRECIOUS: bin/mdriver-% out/mdriver-implicit.o out/mdriver-explicit.o out/%.o
......@@ -43,11 +43,11 @@ static double *samples = NULL;
static void init_sampler()
{
if (values)
free(values);
free(values);
values = calloc(kbest, sizeof(double));
#if KEEP_SAMPLES
if (samples)
free(samples);
free(samples);
/* Allocate extra for wraparound analysis */
samples = calloc(maxsamples+kbest, sizeof(double));
#endif
......@@ -61,11 +61,11 @@ static void add_sample(double val)
{
int pos = 0;
if (samplecount < kbest) {
pos = samplecount;
values[pos] = val;
pos = samplecount;
values[pos] = val;
} else if (val < values[kbest-1]) {
pos = kbest-1;
values[pos] = val;
pos = kbest-1;
values[pos] = val;
}
#if KEEP_SAMPLES
samples[samplecount] = val;
......@@ -73,10 +73,10 @@ static void add_sample(double val)
samplecount++;
/* Insertion sort */
while (pos > 0 && values[pos-1] > values[pos]) {
double temp = values[pos-1];
values[pos-1] = values[pos];
values[pos] = temp;
pos--;
double temp = values[pos-1];
values[pos-1] = values[pos];
values[pos] = temp;
pos--;
}
}
......@@ -86,34 +86,31 @@ static void add_sample(double val)
static int has_converged()
{
return
(samplecount >= kbest) &&
((1 + epsilon)*values[0] >= values[kbest-1]);
(samplecount >= kbest) &&
((1 + epsilon)*values[0] >= values[kbest-1]);
}
/*
* clear - Code to clear cache
*/
static volatile int sink = 0;
static void clear()
{
int x = sink;
int *cptr, *cend;
int incr = cache_block/sizeof(int);
if (!cache_buf) {
cache_buf = malloc(cache_bytes);
if (!cache_buf) {
fprintf(stderr, "Fatal error. Malloc returned null when trying to clear cache\n");
exit(1);
}
cache_buf = malloc(cache_bytes);
if (!cache_buf) {
fprintf(stderr, "Fatal error. Malloc returned null when trying to clear cache\n");
exit(1);
}
}
cptr = (int *) cache_buf;
cend = cptr + cache_bytes/sizeof(int);
while (cptr < cend) {
x += *cptr;
cptr += incr;
*(volatile int *) cptr;
cptr += incr;
}
sink = x;
}
/*
......@@ -136,32 +133,32 @@ double fcyc(test_funct f, void *argp)
double result;
init_sampler();
if (compensate) {
do {
double cyc;
if (clear_cache)
clear();
start_comp_counter();
f(argp);
cyc = get_comp_counter();
add_sample(cyc);
} while (!has_converged() && samplecount < maxsamples);
do {
double cyc;
if (clear_cache)
clear();
start_comp_counter();
f(argp);
cyc = get_comp_counter();
add_sample(cyc);
} while (!has_converged() && samplecount < maxsamples);
} else {
do {
double cyc;
if (clear_cache)
clear();
start_counter();
f(argp);
cyc = get_counter();
add_sample(cyc);
} while (!has_converged() && samplecount < maxsamples);
do {
double cyc;
if (clear_cache)
clear();
start_counter();
f(argp);
cyc = get_counter();
add_sample(cyc);
} while (!has_converged() && samplecount < maxsamples);
}
#ifdef DEBUG
{
int i;
printf(" %d smallest values: [", kbest);
for (i = 0; i < kbest; i++)
printf("%.0f%s", values[i], i==kbest-1 ? "]\n" : ", ");
int i;
printf(" %d smallest values: [", kbest);
for (i = 0; i < kbest; i++)
printf("%.0f%s", values[i], i==kbest-1 ? "]\n" : ", ");
}
#endif
result = values[0];
......@@ -194,11 +191,11 @@ void set_fcyc_clear_cache(int clear)
void set_fcyc_cache_size(int bytes)
{
if (bytes != cache_bytes) {
cache_bytes = bytes;
if (cache_buf) {
free(cache_buf);
cache_buf = NULL;
}
cache_bytes = bytes;
if (cache_buf) {
free(cache_buf);
cache_buf = NULL;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment