-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: veqcc <ryuta.kambe@tier4.jp>
- Loading branch information
Showing
8 changed files
with
190 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
#pragma once | ||
#include <kunit/test.h> | ||
|
||
#define TEST_CASES_NEW_SHM \ | ||
KUNIT_CASE(test_case_new_shm_normal), KUNIT_CASE(test_case_new_shm_many), \ | ||
KUNIT_CASE(test_case_new_shm_not_aligned), KUNIT_CASE(test_case_new_shm_twice) | ||
#define TEST_CASES_NEW_SHM \ | ||
KUNIT_CASE(test_case_new_shm_normal), KUNIT_CASE(test_case_new_shm_too_big), \ | ||
KUNIT_CASE(test_case_new_shm_too_many), KUNIT_CASE(test_case_new_shm_not_aligned), \ | ||
KUNIT_CASE(test_case_new_shm_twice) | ||
|
||
void test_case_new_shm_normal(struct kunit * test); | ||
void test_case_new_shm_many(struct kunit * test); | ||
void test_case_new_shm_too_big(struct kunit * test); | ||
void test_case_new_shm_too_many(struct kunit * test); | ||
void test_case_new_shm_not_aligned(struct kunit * test); | ||
void test_case_new_shm_twice(struct kunit * test); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#include "memory_allocator.h" | ||
|
||
#include <linux/module.h> | ||
|
||
MODULE_LICENSE("Dual BSD/GPL"); | ||
|
||
#define MEMPOOL_128MB_NUM 1000 | ||
#define MEMPOOL_1GB_NUM 100 | ||
#define MEMPOOL_8GB_NUM 10 | ||
|
||
static uint64_t mempool_size_128mb = 134217728; // 128 * 1024 * 1024 | ||
static uint64_t mempool_size_1gb = 1073741824; // 1 * 1024 * 1024 * 1024 | ||
static uint64_t mempool_size_8gb = 8589934592; // 8 * 1024 * 1024 * 1024 | ||
|
||
static pid_t mempool_128mb_pid[MEMPOOL_128MB_NUM]; | ||
static pid_t mempool_1gb_pid[MEMPOOL_1GB_NUM]; | ||
static pid_t mempool_8gb_pid[MEMPOOL_8GB_NUM]; | ||
|
||
static uint64_t mempool_128mb_addr[MEMPOOL_128MB_NUM]; | ||
static uint64_t mempool_1gb_addr[MEMPOOL_1GB_NUM]; | ||
static uint64_t mempool_8gb_addr[MEMPOOL_8GB_NUM]; | ||
|
||
void agnocast_init_memory_allocator(void) | ||
{ | ||
// TODO(Ryuta Kambe): currently, we assume that the address from 0x40000000000 to 0x8B000000000 is | ||
// available | ||
uint64_t addr = 0x40000000000; | ||
|
||
for (int i = 0; i < MEMPOOL_128MB_NUM; i++) { | ||
mempool_128mb_pid[i] = 0; | ||
mempool_128mb_addr[i] = addr; | ||
addr += mempool_size_128mb; | ||
} | ||
|
||
for (int i = 0; i < MEMPOOL_1GB_NUM; i++) { | ||
mempool_1gb_pid[i] = 0; | ||
mempool_1gb_addr[i] = addr; | ||
addr += mempool_size_1gb; | ||
} | ||
|
||
for (int i = 0; i < MEMPOOL_8GB_NUM; i++) { | ||
mempool_8gb_pid[i] = 0; | ||
mempool_8gb_addr[i] = addr; | ||
addr += mempool_size_8gb; | ||
} | ||
} | ||
|
||
uint64_t agnocast_assign_memory(const pid_t pid, const uint64_t size) | ||
{ | ||
if (size <= mempool_size_128mb) { | ||
for (int i = 0; i < MEMPOOL_128MB_NUM; i++) { | ||
if (mempool_128mb_pid[i] == 0) { | ||
mempool_128mb_pid[i] = pid; | ||
return mempool_128mb_addr[i]; | ||
} | ||
} | ||
} | ||
|
||
if (size <= mempool_size_1gb) { | ||
for (int i = 0; i < MEMPOOL_1GB_NUM; i++) { | ||
if (mempool_1gb_pid[i] == 0) { | ||
mempool_1gb_pid[i] = pid; | ||
return mempool_1gb_addr[i]; | ||
} | ||
} | ||
} | ||
|
||
if (size <= mempool_size_8gb) { | ||
for (int i = 0; i < MEMPOOL_8GB_NUM; i++) { | ||
if (mempool_8gb_pid[i] == 0) { | ||
mempool_8gb_pid[i] = pid; | ||
return mempool_8gb_addr[i]; | ||
} | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int agnocast_free_memory(const pid_t pid) | ||
{ | ||
for (int i = 0; i < MEMPOOL_128MB_NUM; i++) { | ||
if (mempool_128mb_pid[i] == pid) { | ||
mempool_128mb_pid[i] = 0; | ||
return 0; | ||
} | ||
} | ||
|
||
for (int i = 0; i < MEMPOOL_1GB_NUM; i++) { | ||
if (mempool_1gb_pid[i] == pid) { | ||
mempool_1gb_pid[i] = 0; | ||
return 0; | ||
} | ||
} | ||
|
||
for (int i = 0; i < MEMPOOL_8GB_NUM; i++) { | ||
if (mempool_8gb_pid[i] == pid) { | ||
mempool_8gb_pid[i] = 0; | ||
return 0; | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
void agnocast_exit_memory_allocator(void) | ||
{ | ||
for (int i = 0; i < MEMPOOL_128MB_NUM; i++) { | ||
mempool_128mb_pid[i] = 0; | ||
} | ||
|
||
for (int i = 0; i < MEMPOOL_1GB_NUM; i++) { | ||
mempool_1gb_pid[i] = 0; | ||
} | ||
|
||
for (int i = 0; i < MEMPOOL_8GB_NUM; i++) { | ||
mempool_8gb_pid[i] = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include <linux/types.h> | ||
|
||
void agnocast_init_memory_allocator(void); | ||
uint64_t agnocast_assign_memory(const pid_t pid, const uint64_t size); | ||
int agnocast_free_memory(const pid_t pid); | ||
void agnocast_exit_memory_allocator(void); |