test whole program
This commit is contained in:
@@ -64,33 +64,33 @@
|
|||||||
assert ((a) == 0); \
|
assert ((a) == 0); \
|
||||||
}
|
}
|
||||||
|
|
||||||
// static inline void *MALLOC(size_t size)
|
static inline void *MALLOC(size_t size)
|
||||||
// {
|
{
|
||||||
// void * temp = malloc(size);
|
void * temp = malloc(size);
|
||||||
// assert(temp);
|
assert(temp);
|
||||||
// return temp;
|
return temp;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// static inline void *CALLOC(size_t num, size_t size)
|
static inline void *CALLOC(size_t num, size_t size)
|
||||||
// {
|
{
|
||||||
// void * temp = calloc(num, size);
|
void * temp = calloc(num, size);
|
||||||
// assert(temp);
|
assert(temp);
|
||||||
// return temp;
|
return temp;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// static inline void *REALLOC(void *ptr, size_t size)
|
static inline void *REALLOC(void *ptr, size_t size)
|
||||||
// {
|
{
|
||||||
// void * temp = realloc(ptr, size);
|
void * temp = realloc(ptr, size);
|
||||||
// assert(temp);
|
assert(temp);
|
||||||
// return temp;
|
return temp;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// static inline char *GETENV(char *envstr)
|
static inline char *GETENV(char *envstr)
|
||||||
// {
|
{
|
||||||
// char *env = getenv(envstr);
|
char *env = getenv(envstr);
|
||||||
// if (!env) return "0";
|
if (!env) return "0";
|
||||||
// else return env;
|
else return env;
|
||||||
// }
|
}
|
||||||
|
|
||||||
#define GET_TIME(start, end, duration) \
|
#define GET_TIME(start, end, duration) \
|
||||||
duration.tv_sec = (end.tv_sec - start.tv_sec); \
|
duration.tv_sec = (end.tv_sec - start.tv_sec); \
|
||||||
@@ -131,140 +131,58 @@ static inline void get_time (struct timeval *t)
|
|||||||
|
|
||||||
// Expirement work
|
// Expirement work
|
||||||
|
|
||||||
// #define FILENAME "/dev/contigmem"
|
#define FILENAME "/dev/contigmem"
|
||||||
|
|
||||||
static char *heap_start;
|
static char *heap_start;
|
||||||
static char *heap;
|
static char *heap;
|
||||||
static size_t HEAP_SIZE = 1024 * 1024 * 1024;
|
static size_t HEAP_SIZE = 1024 * 1024 * 1024;
|
||||||
|
|
||||||
static void *ptr;
|
void *ptr;
|
||||||
static int MallocCounter = 0;
|
int MallocCounter;
|
||||||
|
|
||||||
static size_t sizeUsed;
|
size_t sizeUsed;
|
||||||
|
|
||||||
// INITAlloc(void) {
|
static void INITAlloc(void) {
|
||||||
|
|
||||||
// size_t sz;
|
size_t sz;
|
||||||
// // Pre Allocate 600 MB
|
// Pre Allocate 600 MB
|
||||||
// sz = 100000000;
|
sz = 100000000;
|
||||||
|
|
||||||
// int fd = open(FILENAME, O_RDWR, 0600);
|
int fd = open(FILENAME, O_RDWR, 0600);
|
||||||
|
|
||||||
// if (fd < 0) {
|
if (fd < 0) {
|
||||||
// perror("open");
|
perror("open");
|
||||||
// exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
// }
|
|
||||||
|
|
||||||
// off_t offset = 0; // offset to seek to.
|
|
||||||
|
|
||||||
// if (ftruncate(fd, sz) < 0) {
|
|
||||||
// perror("ftruncate");
|
|
||||||
// close(fd);
|
|
||||||
// exit(EXIT_FAILURE);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // ptr = mmap(NULL, sz,
|
|
||||||
// // PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON,-1,0);
|
|
||||||
|
|
||||||
// ptr = mmap(NULL, sz,
|
|
||||||
// PROT_READ|PROT_WRITE, MAP_SHARED,fd,0);
|
|
||||||
|
|
||||||
// // Added error handling
|
|
||||||
// if(ptr == MAP_FAILED)
|
|
||||||
// {
|
|
||||||
// perror("mmap");
|
|
||||||
// exit(EXIT_FAILURE);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// MallocCounter = (int)sz;
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
static int notrun = 0;
|
|
||||||
|
|
||||||
static int
|
|
||||||
pagesizes(size_t ps[MAXPAGESIZES])
|
|
||||||
{
|
|
||||||
int pscnt;
|
|
||||||
|
|
||||||
pscnt = getpagesizes(ps, MAXPAGESIZES);
|
|
||||||
// ATF_REQUIRE_MSG(pscnt != -1, "getpagesizes failed; errno=%d", errno);
|
|
||||||
// ATF_REQUIRE_MSG(ps[0] != 0, "psind 0 is %zu", ps[0]);
|
|
||||||
// ATF_REQUIRE_MSG(pscnt <= MAXPAGESIZES, "invalid pscnt %d", pscnt);
|
|
||||||
// if (pscnt == 1){
|
|
||||||
// printf("pscnt is 1");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// atf_tc_skip("no large page support");
|
|
||||||
return (pscnt);
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((constructor))
|
|
||||||
static void INITREGULARALLOC(void) {
|
|
||||||
size_t sz;
|
|
||||||
// Pre Allocate 400 MB
|
|
||||||
sz = 1073741824;
|
|
||||||
|
|
||||||
int error, fd, pscnt, pn;
|
|
||||||
|
|
||||||
size_t ps[MAXPAGESIZES];
|
|
||||||
|
|
||||||
size_t size[3];
|
|
||||||
|
|
||||||
pn = getpagesizes(size, 3);
|
|
||||||
printf("page size is [%d]", size[2]);
|
|
||||||
|
|
||||||
pscnt = pagesizes(ps);
|
|
||||||
|
|
||||||
fd = shm_create_largepage(SHM_ANON, O_CREAT | O_RDWR, 1, SHM_LARGEPAGE_ALLOC_DEFAULT, 0);
|
|
||||||
|
|
||||||
if (fd < 0 && errno == ENOTTY) {
|
|
||||||
perror("sh_create_largepages");
|
|
||||||
close(fd);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
// if (fd < 0)
|
|
||||||
// perror("no large page supported");
|
|
||||||
// exit(EXIT_FAILURE);
|
|
||||||
// if (fd < 0 && errno == ENOTTY)
|
|
||||||
// atf_tc_skip("no large page support");
|
|
||||||
// ATF_REQUIRE_MSG(fd >= 0, "shm_create_largepage failed; errno=%d", errno);
|
|
||||||
|
|
||||||
if (ftruncate(fd, sz) < 0) {
|
|
||||||
perror("ftruncate");
|
|
||||||
close(fd);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
// if (error != 0 && errno == ENOMEM)
|
|
||||||
// /*
|
|
||||||
// * The test system might not have enough memory to accommodate
|
|
||||||
// * the request.
|
|
||||||
// */
|
|
||||||
// atf_tc_skip("failed to allocate %zu-byte superpage", sz);
|
|
||||||
// ATF_REQUIRE_MSG(error == 0, "ftruncate failed; errno=%d", errno);
|
|
||||||
|
|
||||||
ptr = mmap(NULL, sz,
|
|
||||||
PROT_READ|PROT_WRITE, MAP_SHARED,fd,0);
|
|
||||||
|
|
||||||
// Added error handling
|
|
||||||
if(ptr == MAP_FAILED)
|
|
||||||
{
|
|
||||||
perror("mmap");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
MallocCounter = (int)sz;
|
|
||||||
notrun = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
off_t offset = 0; // offset to seek to.
|
||||||
|
|
||||||
|
if (ftruncate(fd, sz) < 0) {
|
||||||
|
perror("ftruncate");
|
||||||
|
close(fd);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ptr = mmap(NULL, sz,
|
||||||
|
// PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON,-1,0);
|
||||||
|
|
||||||
|
ptr = mmap(NULL, sz,
|
||||||
|
PROT_READ|PROT_WRITE, MAP_SHARED,fd,0);
|
||||||
|
|
||||||
|
// Added error handling
|
||||||
|
if(ptr == MAP_FAILED)
|
||||||
|
{
|
||||||
|
perror("mmap");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
MallocCounter = (int)sz;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Quick malloc implementation with mmap
|
// Quick malloc implementation with mmap
|
||||||
void* malloc(size_t sz)
|
void* malloc(size_t sz)
|
||||||
{
|
{
|
||||||
// If malloc is called for the first time then allocate huge page
|
|
||||||
if (notrun == 0) {
|
|
||||||
INITREGULARALLOC();
|
|
||||||
}
|
|
||||||
sz = __builtin_align_up(sz, _Alignof(max_align_t));
|
sz = __builtin_align_up(sz, _Alignof(max_align_t));
|
||||||
|
|
||||||
// printf("%d \n", sz);
|
// printf("%d \n", sz);
|
||||||
@@ -283,16 +201,90 @@ void* malloc(size_t sz)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Quick cheri free implementation
|
// Quick cheri free implementation
|
||||||
void free(void *ptr) {
|
// void free(void *ptr) {
|
||||||
|
|
||||||
// printf("free called \n");
|
// // printf("free called \n");
|
||||||
|
|
||||||
// get bounds from
|
// // get bounds from
|
||||||
int len = cheri_getlen(ptr);
|
// int len = cheri_getlen(ptr);
|
||||||
|
|
||||||
// printf("free len %d \n", len);
|
// // printf("free len %d \n", len);
|
||||||
|
|
||||||
munmap(ptr, len);
|
// munmap(ptr, len);
|
||||||
|
// }
|
||||||
|
|
||||||
|
static int
|
||||||
|
pagesizes(size_t ps[MAXPAGESIZES])
|
||||||
|
{
|
||||||
|
int pscnt;
|
||||||
|
|
||||||
|
pscnt = getpagesizes(ps, MAXPAGESIZES);
|
||||||
|
// ATF_REQUIRE_MSG(pscnt != -1, "getpagesizes failed; errno=%d", errno);
|
||||||
|
// ATF_REQUIRE_MSG(ps[0] != 0, "psind 0 is %zu", ps[0]);
|
||||||
|
// ATF_REQUIRE_MSG(pscnt <= MAXPAGESIZES, "invalid pscnt %d", pscnt);
|
||||||
|
// if (pscnt == 1){
|
||||||
|
// printf("pscnt is 1");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// atf_tc_skip("no large page support");
|
||||||
|
return (pscnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((constuctor))
|
||||||
|
static INITREGULARALLOC(void) {
|
||||||
|
size_t sz;
|
||||||
|
// Hard-coded for 1GB huge page
|
||||||
|
sz = 1073741824;
|
||||||
|
|
||||||
|
int error, fd, pscnt, pn;
|
||||||
|
|
||||||
|
size_t ps[MAXPAGESIZES];
|
||||||
|
|
||||||
|
size_t size[3];
|
||||||
|
|
||||||
|
pn = getpagesizes(size, 3);
|
||||||
|
printf("page size is [%d]", size[2]);
|
||||||
|
|
||||||
|
pscnt = pagesizes(ps);
|
||||||
|
|
||||||
|
fd = shm_create_largepage(SHM_ANON, O_CREAT | O_RDWR, 1, SHM_LARGEPAGE_ALLOC_DEFAULT, 0);
|
||||||
|
|
||||||
|
if (fd < 0 && errno == ENOTTY) {
|
||||||
|
perror("sh_create_largepages");
|
||||||
|
close(fd);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
// if (fd < 0)
|
||||||
|
// perror("no large page supported");
|
||||||
|
// exit(EXIT_FAILURE);
|
||||||
|
// if (fd < 0 && errno == ENOTTY)
|
||||||
|
// atf_tc_skip("no large page support");
|
||||||
|
// ATF_REQUIRE_MSG(fd >= 0, "shm_create_largepage failed; errno=%d", errno);
|
||||||
|
|
||||||
|
if (ftruncate(fd, sz) < 0) {
|
||||||
|
perror("ftruncate");
|
||||||
|
close(fd);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
// if (error != 0 && errno == ENOMEM)
|
||||||
|
// /*
|
||||||
|
// * The test system might not have enough memory to accommodate
|
||||||
|
// * the request.
|
||||||
|
// */
|
||||||
|
// atf_tc_skip("failed to allocate %zu-byte superpage", sz);
|
||||||
|
// ATF_REQUIRE_MSG(error == 0, "ftruncate failed; errno=%d", errno);
|
||||||
|
|
||||||
|
ptr = mmap(NULL, sz,
|
||||||
|
PROT_READ|PROT_WRITE, MAP_SHARED,fd,0);
|
||||||
|
|
||||||
|
// Added error handling
|
||||||
|
if(ptr == MAP_FAILED)
|
||||||
|
{
|
||||||
|
perror("mmap");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
MallocCounter = (int)sz;
|
||||||
}
|
}
|
||||||
// Standard Alloc
|
// Standard Alloc
|
||||||
// void* MALLOCREGULAR(size_t sz) {
|
// void* MALLOCREGULAR(size_t sz) {
|
||||||
|
|||||||
Reference in New Issue
Block a user