-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core/shmem): move shared memory logic to dedicated source file
This patch relocates the initialization and shared memory access steps from the hardcoded settings in the existing IPC file to a generic shared memory file. Previously, the code assumed the existence of only one object working with the shared memory (ipc). With this update, the system is now prepared for future versions where multiple objects can be added and working with the shared memory. Signed-off-by: joaopeixoto13 <[email protected]>
- Loading branch information
1 parent
d2d208f
commit 6c1de4d
Showing
7 changed files
with
68 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) Bao Project and Contributors. All rights reserved. | ||
*/ | ||
|
||
#ifndef SHMEM_H | ||
#define SHMEM_H | ||
|
||
#include <mem.h> | ||
|
||
void shmem_init(); | ||
struct shmem* shmem_get(size_t shmem_id); | ||
|
||
#endif /* SHMEM_H */ |
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 |
---|---|---|
|
@@ -13,3 +13,4 @@ core-objs-y+=console.o | |
core-objs-y+=ipc.o | ||
core-objs-y+=objpool.o | ||
core-objs-y+=hypercall.o | ||
core-objs-y+=shmem.o |
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,47 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) Bao Project and Contributors. All rights reserved. | ||
*/ | ||
|
||
#include <shmem.h> | ||
#include <config.h> | ||
|
||
static size_t shmem_table_size; | ||
static struct shmem* shmem_table; | ||
|
||
static void shmem_alloc() | ||
{ | ||
for (size_t i = 0; i < shmem_table_size; i++) { | ||
struct shmem* shmem = &shmem_table[i]; | ||
if (!shmem->place_phys) { | ||
size_t n_pg = NUM_PAGES(shmem->size); | ||
struct ppages ppages = mem_alloc_ppages(shmem->colors, n_pg, false); | ||
if (ppages.num_pages < n_pg) { | ||
ERROR("failed to allocate shared memory"); | ||
} | ||
shmem->phys = ppages.base; | ||
} | ||
} | ||
} | ||
|
||
struct shmem* shmem_get(size_t shmem_id) | ||
{ | ||
if (shmem_id < shmem_table_size) { | ||
return &shmem_table[shmem_id]; | ||
} else { | ||
return NULL; | ||
} | ||
} | ||
|
||
void shmem_init() | ||
{ | ||
if (cpu_is_master()) { | ||
shmem_table_size = config.shmemlist_size; | ||
shmem_table = config.shmemlist; | ||
shmem_alloc(); | ||
|
||
for (size_t i = 0; i < config.shmemlist_size; i++) { | ||
config.shmemlist[i].cpu_masters = 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
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