added large page support

This commit is contained in:
2024-10-21 17:04:01 +01:00
parent 1dd09f4a0c
commit f4ed91acce
4 changed files with 72 additions and 18 deletions

View File

@@ -42,7 +42,8 @@
"sbuf.h": "c", "sbuf.h": "c",
"opt_vm.h": "c", "opt_vm.h": "c",
"stack": "c", "stack": "c",
"ios": "c" "ios": "c",
"stdint.h": "c"
}, },
"C_Cpp.errorSquiggles": "disabled" "C_Cpp.errorSquiggles": "disabled"
} }

View File

@@ -269,8 +269,8 @@ int main(int argc, char **argv)
// Extra code snippet added // Extra code snippet added
// printf("Initial alloc called\n"); // printf("Initial alloc called\n");
INITAlloc(); //INITAlloc();
//INITREGULARALLOC(); INITREGULARALLOC();
int num_procs, curr_point; int num_procs, curr_point;
int i; int i;

View File

@@ -30,13 +30,17 @@
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/errno.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/types.h>
#include <cheriintrin.h> #include <cheriintrin.h>
#include <cheri/cheric.h> #include <cheri/cheric.h>
@@ -44,9 +48,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
// #include <sys/types.h> #define MAXPAGESIZES 2
#include <sys/mman.h>
// #include <fcntl.h>
//#define TIMING //#define TIMING
@@ -146,16 +148,12 @@ INITAlloc(void) {
// 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);
int fd = memfd_create("kilgore",0x00000004); if (fd < 0) {
if (fd == -1) perror("open");
perror("memfd_create()"); exit(EXIT_FAILURE);
}
// if (fd < 0) {
// perror("open");
// exit(EXIT_FAILURE);
// }
off_t offset = 0; // offset to seek to. off_t offset = 0; // offset to seek to.
@@ -215,13 +213,68 @@ void FREECHERI(void *ptr) {
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);
}
INITREGULARALLOC(void) { INITREGULARALLOC(void) {
size_t sz; size_t sz;
// Pre Allocate 400 MB // Pre Allocate 400 MB
sz = 100000000; 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, ptr = mmap(NULL, sz,
PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON,-1,0); PROT_READ|PROT_WRITE, MAP_SHARED,fd,0);
// Added error handling // Added error handling
if(ptr == MAP_FAILED) if(ptr == MAP_FAILED)

View File

@@ -3,4 +3,4 @@ files=`find . -newermt "-3600 secs" | sed 's|^./||'`
for file in $files for file in $files
do do
sshpass -p "" scp "$file" "akilan@192.0.0.3:/home/akilan/Alloc-Test/CHERI-Allocator/$file" sshpass -p "" scp "$file" "akilan@192.0.0.3:/home/akilan/Alloc-Test/CHERI-Allocator/$file"
done done