test whole program
This commit is contained in:
@@ -131,7 +131,7 @@ static inline void get_time (struct timeval *t)
|
||||
|
||||
// Expirement work
|
||||
|
||||
#define FILENAME "/dev/contigmem"
|
||||
// #define FILENAME "/dev/contigmem"
|
||||
|
||||
static char *heap_start;
|
||||
static char *heap;
|
||||
@@ -180,12 +180,71 @@ size_t sizeUsed;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int notrun = 0;
|
||||
// Quick malloc implementation with mmap
|
||||
void* malloc(size_t sz)
|
||||
{
|
||||
// If malloc is called for the first time then allocate huge page
|
||||
if (MallocCounter == 0) {
|
||||
if (notrun == 0) {
|
||||
INITREGULARALLOC();
|
||||
notrun = 1;
|
||||
}
|
||||
sz = __builtin_align_up(sz, _Alignof(max_align_t));
|
||||
|
||||
@@ -233,62 +292,6 @@ pagesizes(size_t ps[MAXPAGESIZES])
|
||||
// atf_tc_skip("no large page support");
|
||||
return (pscnt);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// Standard Alloc
|
||||
// void* MALLOCREGULAR(size_t sz) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user