Skip to content

Commit b2d7bc6

Browse files
committed
[mm/page] multi-list page manager
[mm/page] page debugger [libcpu/aarch64] hugepage support
1 parent ca1b1e5 commit b2d7bc6

File tree

16 files changed

+515
-137
lines changed

16 files changed

+515
-137
lines changed

components/drivers/virtio/virtio_net.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static struct pbuf *virtio_net_rx(rt_device_t dev)
106106
#ifdef RT_USING_SMP
107107
level = rt_spin_lock_irqsave(&virtio_dev->spinlock);
108108
#endif
109-
rt_memcpy(p->payload, (void *)VIRTIO_PA2VA(queue_rx->desc[id].addr), len);
109+
rt_memcpy(p->payload, (void *)queue_rx->desc[id].addr - PV_OFFSET, len);
110110

111111
queue_rx->used_idx++;
112112

components/lwp/arch/aarch64/cortex-a/lwp_arch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int arch_user_space_init(struct rt_lwp *lwp)
2626
{
2727
size_t *mmu_table;
2828

29-
mmu_table = (size_t *)rt_pages_alloc(0);
29+
mmu_table = (size_t *)rt_pages_alloc_ext(0, PAGE_ANY_AVAILABLE);
3030
if (!mmu_table)
3131
{
3232
return -RT_ENOMEM;

components/lwp/arch/risc-v/rv64/lwp_arch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ int arch_user_space_init(struct rt_lwp *lwp)
9191
{
9292
rt_ubase_t *mmu_table;
9393

94-
mmu_table = (rt_ubase_t *)rt_pages_alloc(0);
94+
mmu_table = (rt_ubase_t *)rt_pages_alloc_ext(0, PAGE_ANY_AVAILABLE);
9595
if (!mmu_table)
9696
{
9797
return -RT_ENOMEM;

components/lwp/arch/x86/i386/lwp_arch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ int arch_user_space_init(struct rt_lwp *lwp)
8282
{
8383
rt_size_t *mmu_table;
8484

85-
mmu_table = (rt_size_t *)rt_pages_alloc(0);
85+
mmu_table = (rt_size_t *)rt_pages_alloc_ext(0, PAGE_ANY_AVAILABLE);
8686
if (!mmu_table)
8787
{
8888
return -1;

components/lwp/lwp.c

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* 2018-11-02 heyuanjie fix complie error in iar
1010
* 2021-02-03 lizhirui add 64-bit arch support and riscv64 arch support
1111
* 2021-08-26 linzhenxing add lwp_setcwd\lwp_getcwd
12+
* 2023-02-20 wangxiaoyao inv icache before new app startup
1213
*/
1314

1415
#include <rthw.h>
@@ -1097,6 +1098,18 @@ static void _lwp_thread_entry(void *parameter)
10971098
icache_invalid_all();
10981099
}
10991100

1101+
/**
1102+
* without ASID support, it will be a special case when trying to run application
1103+
* and exit multiple times and a same page frame allocated to it bound to
1104+
* different text segment. Then we are in a situation where icache contains
1105+
* out-of-dated data and must be handle by the running core itself.
1106+
* with ASID support, this should be a rare case that ASID & page frame both
1107+
* identical to previous running application.
1108+
*
1109+
* For a new application loaded into memory, icache are seen as empty. And there
1110+
* should be nothing in the icache entry to match. So this icache invalidation
1111+
* operation should have barely influence.
1112+
*/
11001113
rt_hw_icache_invalidate_all();
11011114

11021115
#ifdef ARCH_MM_MMU

components/lwp/lwp_shm.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2019-10-12 Jesven first version
9+
* 2023-02-20 wangxiaoyao adapt to mm
910
*/
1011
#include <rthw.h>
1112
#include <rtthread.h>
@@ -17,8 +18,6 @@
1718

1819
#include <lwp_user_mm.h>
1920
#include <mmu.h>
20-
#include <mm_aspace.h>
21-
#include <mm_flag.h>
2221

2322
/* the kernel structure to represent a share-memory */
2423
struct lwp_shm_struct
@@ -140,7 +139,7 @@ static int _lwp_shmget(size_t key, size_t size, int create)
140139

141140
/* allocate pages up to 2's exponent to cover the required size */
142141
bit = rt_page_bits(size);
143-
page_addr = rt_pages_alloc(bit); /* virtual address */
142+
page_addr = rt_pages_alloc_ext(bit, PAGE_ANY_AVAILABLE); /* virtual address */
144143
if (!page_addr)
145144
{
146145
goto err;

components/lwp/lwp_syscall.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ static char *_insert_args(int new_argc, char *new_argv[], struct lwp_args_info *
18611861
{
18621862
goto quit;
18631863
}
1864-
page = rt_pages_alloc(0); /* 1 page */
1864+
page = rt_pages_alloc_ext(0, PAGE_ANY_AVAILABLE); /* 1 page */
18651865
if (!page)
18661866
{
18671867
goto quit;
@@ -2065,7 +2065,7 @@ int load_ldso(struct rt_lwp *lwp, char *exec_name, char *const argv[], char *con
20652065
}
20662066
}
20672067

2068-
page = rt_pages_alloc(0); /* 1 page */
2068+
page = rt_pages_alloc_ext(0, PAGE_ANY_AVAILABLE); /* 1 page */
20692069
if (!page)
20702070
{
20712071
SET_ERRNO(ENOMEM);
@@ -2252,7 +2252,7 @@ sysret_t sys_execve(const char *path, char *const argv[], char *const envp[])
22522252
SET_ERRNO(EINVAL);
22532253
goto quit;
22542254
}
2255-
page = rt_pages_alloc(0); /* 1 page */
2255+
page = rt_pages_alloc_ext(0, PAGE_ANY_AVAILABLE); /* 1 page */
22562256
if (!page)
22572257
{
22582258
SET_ERRNO(ENOMEM);

components/lwp/lwp_user_mm.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* 2021-02-12 lizhirui add 64-bit support for lwp_brk
1111
* 2021-02-19 lizhirui add riscv64 support for lwp_user_accessable and lwp_get_from_user
1212
* 2021-06-07 lizhirui modify user space bound check
13+
* 2022-12-25 wangxiaoyao adapt to new mm
1314
*/
1415

1516
#include <rtthread.h>
@@ -130,7 +131,7 @@ static void _user_do_page_fault(struct rt_varea *varea,
130131

131132
if (!(varea->flag & MMF_TEXT))
132133
{
133-
void *cp = rt_pages_alloc(0);
134+
void *cp = rt_pages_alloc_ext(0, PAGE_ANY_AVAILABLE);
134135
if (cp)
135136
{
136137
memcpy(cp, vaddr, ARCH_PAGE_SIZE);

components/mm/mm_aspace.c

+5-13
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,16 @@ static int _do_named_map(rt_aspace_t aspace, void *vaddr, rt_size_t length,
134134
int err = RT_EOK;
135135

136136
/* it's ensured by caller that (void*)end will not overflow */
137-
void *end = vaddr + length;
138137
void *phyaddr = (void *)(offset << MM_PAGE_SHIFT);
139-
while (vaddr != end)
138+
139+
void *ret = rt_hw_mmu_map(aspace, vaddr, phyaddr, length, attr);
140+
if (ret == RT_NULL)
140141
{
141-
/* TODO try to map with huge TLB, when flag & HUGEPAGE */
142-
rt_size_t pgsz = ARCH_PAGE_SIZE;
143-
void *ret = rt_hw_mmu_map(aspace, vaddr, phyaddr, pgsz, attr);
144-
if (ret == RT_NULL)
145-
{
146-
err = -RT_ERROR;
147-
break;
148-
}
149-
vaddr += pgsz;
150-
phyaddr += pgsz;
142+
err = -RT_ERROR;
151143
}
152144

153145
if (err == RT_EOK)
154-
rt_hw_tlb_invalidate_range(aspace, end - length, length, ARCH_PAGE_SIZE);
146+
rt_hw_tlb_invalidate_range(aspace, vaddr, length, ARCH_PAGE_SIZE);
155147

156148
return err;
157149
}

components/mm/mm_object.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void rt_varea_pgmgr_pop(rt_varea_t varea, void *vaddr, rt_size_t size)
7070
static void on_page_fault(struct rt_varea *varea, struct rt_aspace_fault_msg *msg)
7171
{
7272
void *page;
73-
page = rt_pages_alloc(0);
73+
page = rt_pages_alloc_ext(0, PAGE_ANY_AVAILABLE);
7474

7575
if (!page)
7676
{

0 commit comments

Comments
 (0)