Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add porting codes of rt-thread. #494

Merged
merged 4 commits into from
Jan 14, 2021
Merged

add porting codes of rt-thread. #494

merged 4 commits into from
Jan 14, 2021

Conversation

alvkeke
Copy link
Contributor

@alvkeke alvkeke commented Jan 11, 2021

add porting codes and scons building scripts that are used by rt-thread, document was modified passingly.

Copy link
Contributor

@wenyongh wenyongh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting the patch!

@@ -0,0 +1,27 @@
# for module compiling
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add license header for all files, for the new file, you might claim the copyright to yourself and set license to "Apache-2.0 WITH LLVM-exception", please ref to other file submitted by community developer, e.g. nuttx_platform.c.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have add license header to files I added, please check it.

#include <stdint.h>
#include <ctype.h>

#ifndef BUILD_TARGET
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether we should define BUILD_TARGET here, normally we define BUILD_TARGET_XXX in build-scripts/config_common.cmake by parsing the WAMR_BUILD_TARGET=XXX passed by cmake variable (cmake -DWAMR_BUILD_TARGET=XXX).

And had better define the BH_PLATFORM_XXX macro in this file, so other files can use the macro, e.g. wasm_native.c:
#ifndef BUILD_PLATFORM_RT_THREAD
#define BUILD_PLATFORM_RT_THREAD
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, this definiation was used in the past version and I forgot to delete it, I just remove it from rt-thread/platform_internal.h.

void *os_malloc(unsigned size)
{
void* buf = rt_malloc(size + 8);
if (((rt_ubase_t)buf)&7)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why here it doesn't check buf != NULL, but check (buf & 7), could buf's lowest 3 bits be zero, and higher bits be not zero? e.g. 0x11110, or 0x11118.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wamr need heap init struct be aligned to 8-bytes, otherwise iwasm will print error information: [GC_ERROR]heap init struct buf not 8-byte aligned. these codes are used to make sure the memories allocated are all align to 8-byte.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks a lot! And should we also check the input pointer ptr like os_free in os_realloc? The ptr might be not the original buffer returned by rt_malloc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a list to save the map from fixed-address to origin-address named mem_list. if the address of memory allocated is not align to 8-byte, this address and fixed-address will be save into this list. while os_free be called, will also check this list to find the original address of the pointer pass in.

as for os_realloc, I have not done anything yet, I will resolve it later.

Copy link
Contributor

@wenyongh wenyongh Jan 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, it seems that the performance might be not so good if saving the map to mem_list, e.g. in os_free, we need to traverse the list. And also for multi-thread, normally we should to add lock for the list. How about allocating memory with extra 16 bytes, saving the original address to the next 8-byte aligned address, and return the next next 8-byte aligned address? e.g.:

void *os_malloc(unsigned size)
{
    uint8 *buf = rt_malloc(size + 16);
    uint8 *buf_aligned;

    if (buf) {
        buf_aligned = (uint8 *)(((uintptr_t)buf + 7) & ~(uintptr_t)7);
        *(uint8 **)buf_aligned = buf;
        buf = buf_aligned + 8;
    }
    return buf;
}

void os_free(void *ptr)
{
    uint8 *buf_aligned;

    if (ptr) {
        buf_aligned = (uint8 *)ptr - 8;
        buf = *(uint8 **)buf_aligned;
        rt_free(buf);
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinks for your reply and advice, It seems be a good idea, I will try this today.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have rewrite these three method, please check.

@wenyongh wenyongh merged commit 8ec03a5 into bytecodealliance:main Jan 14, 2021
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants