From 9f9d3bf0b9164c573595ffa74927142f428a3c6e Mon Sep 17 00:00:00 2001 From: Weilin Wang Date: Thu, 22 Jul 2021 14:50:59 +0800 Subject: [PATCH 1/2] add channel to get memory informations --- .../applications/channel_memory.c | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 bsp/qemu-vexpress-a9/applications/channel_memory.c diff --git a/bsp/qemu-vexpress-a9/applications/channel_memory.c b/bsp/qemu-vexpress-a9/applications/channel_memory.c new file mode 100644 index 0000000000..3e2b07c948 --- /dev/null +++ b/bsp/qemu-vexpress-a9/applications/channel_memory.c @@ -0,0 +1,65 @@ +#include +#include +#include + +#define DBG_TAG "DTAG" +#define DBG_LVL DBG_INFO +#include + +/* put memory informations into buf */ +void rt_memory_get(void* buf) +{ + rt_uint32_t total_mem,used_mem,max_mem; + rt_memory_info(&total_mem,&used_mem,&max_mem); + size_t total_pages = 0, free_pages = 0; + rt_page_get_info(&total_pages, &free_pages); + total_mem = total_mem + total_pages * ARCH_PAGE_SIZE; + used_mem = used_mem + (total_pages - free_pages) * ARCH_PAGE_SIZE; + int size = sizeof(rt_uint32_t); + memcpy(buf, &total_mem, size); + memcpy(buf+size, &used_mem, size); + memcpy(buf+size*2, &max_mem, size); +} + +/* given information(memory) with channel */ +void rt_memory_transinformation_entry(void) +{ + int ch; + struct rt_channel_msg msg_text; + char* channel_msg; + int shmid; + /* create channel called 'channel_memory' to transmitting memory informations */ + ch = rt_channel_open("channel_memory",O_CREAT); + if (ch == -1) + { + LOG_D("Error: rt_channel_open: fail to create the IPC channel for memory!"); + return; + } + while (1) + { + rt_channel_recv(ch,&msg_text); + shmid = (int)msg_text.u.d; + if(shmid < 0 || !(channel_msg = lwp_shminfo(shmid))) + { + msg_text.u.d = (void*)-1; + LOG_D("memory:receive an invalid shared-memory page."); + rt_channel_reply(ch,&msg_text); + continue; + } + /* get memory informations and copy them into the shared memory */ + int len = sizeof(rt_uint32_t)*3; + char memory_buf[len]; + rt_memory_get(memory_buf); + memcpy((void*)channel_msg,memory_buf,len); + rt_channel_reply(ch,&msg_text); + } + rt_channel_close(ch); +} + +void rt_memory_transinformation_thread(void) +{ + rt_thread_t tid = rt_thread_create("channel_trans_memory_thread", rt_memory_transinformation_entry, RT_NULL, LWP_TASK_STACK_SIZE, 25, 300); + rt_thread_startup(tid); +} +INIT_APP_EXPORT(rt_memory_transinformation_thread); + -- Gitee From 9ffabf5947865b80127ce2fdbb2d0559b3f0e335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BC=9F=E6=9E=97?= <9322391+weiger-linux2@user.noreply.gitee.com> Date: Thu, 22 Jul 2021 06:54:51 +0000 Subject: [PATCH 2/2] update bsp/qemu-vexpress-a9/applications/channel_memory.c. --- bsp/qemu-vexpress-a9/applications/channel_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsp/qemu-vexpress-a9/applications/channel_memory.c b/bsp/qemu-vexpress-a9/applications/channel_memory.c index 3e2b07c948..b01cc555e2 100644 --- a/bsp/qemu-vexpress-a9/applications/channel_memory.c +++ b/bsp/qemu-vexpress-a9/applications/channel_memory.c @@ -39,7 +39,7 @@ void rt_memory_transinformation_entry(void) { rt_channel_recv(ch,&msg_text); shmid = (int)msg_text.u.d; - if(shmid < 0 || !(channel_msg = lwp_shminfo(shmid))) + if (shmid < 0 || !(channel_msg = lwp_shminfo(shmid))) { msg_text.u.d = (void*)-1; LOG_D("memory:receive an invalid shared-memory page."); -- Gitee