-
Notifications
You must be signed in to change notification settings - Fork 594
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
mm/mm_heap : realtime support for malloc/free functions performing wi… #3398
base: master
Are you sure you want to change the base?
Conversation
Target : [006d616eb3bff6dc9380778460179f076c815d60] - Code Rule Check (C++) OK. |
Target : [006d616eb3bff6dc9380778460179f076c815d60] - Code Rule Check Result: |
006d616
to
eac8f63
Compare
Target : [eac8f6315338d20ea3a0357bcf528661c22c7163] - Code Rule Check (C++) OK. |
Target : [eac8f6315338d20ea3a0357bcf528661c22c7163] - Code Rule Check Result: |
Target : [b21610aa00c5f1d4b7ec8271c304d868f6af2145] - Code Rule Check (C++) OK. |
Target : [b21610aa00c5f1d4b7ec8271c304d868f6af2145] - Code Rule Check Result: |
b21610a
to
2fe0862
Compare
Target : [2fe08620cc5f5a0c653eb63d991f16cb62858b77] - Code Rule Check (C++) OK. |
Target : [2fe08620cc5f5a0c653eb63d991f16cb62858b77] - Code Rule Check Result: |
2fe0862
to
c573119
Compare
Target : [c57311982eb4d58d28cc9123404f7f8b389b2702] - Code Rule Check OK. |
Target : [c57311982eb4d58d28cc9123404f7f8b389b2702] - Code Rule Check (C++) OK. |
#define MM_NNODES (MM_MAX_SHIFT - MM_MIN_SHIFT + 1) | ||
#endif // CONFIG_MM_REALTIME_SUPPORT | ||
|
||
#define MM_GRAN_MASK (MM_MIN_CHUNK-1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide space before and after '-'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is not modified. Let's just keep it as it is.
|
||
else | ||
install: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this extra line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is like a template. Let's just keep it as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
|
||
else | ||
context: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is like a template. Let's just keep it as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
{ | ||
char *addr; | ||
int ndx; | ||
uint32_t miss[MM_REALTIME_SUPPORT_NUMOF_SIZES] = {0, }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide space after open brace.
like: { 0, }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
c573119
to
39bc5e7
Compare
Target : [39bc5e7384e2285ac42d7bd51d0b91e29d8f8c10] - Code Rule Check (C++) OK. |
Target : [39bc5e7384e2285ac42d7bd51d0b91e29d8f8c10] - Code Rule Check OK. |
|
||
addr = (char *)malloc(sizeof(char)); | ||
|
||
if (argc > 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 comments here.
- null check after malloc needed but I think you can use unsigned with out mem alloc.
- You'd better modify it to switch-case if you consider expand it.
- argc > 2 is intended code? actually you already mentioned usage in else state, it means you restrict usage.
So Error case also should be there if argc is greater than 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, my feedback.
- Null check is necessary, but this mem alloc is intended to get heap stat.
- I'll do when I need to extend this function further.
- if argc <= 2, 'heapstat' just goes well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean if user type heapstat reset blah blah blah it also works. is it intended? of course some os accepts it but some other doesn't accept it. I was just curious because you added usaage below..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it was intentionally allowed to keep the code simple. Thanks for your comment, though.
@@ -149,6 +149,9 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem) | |||
/* Check if the following node is free and, if so, merge it */ | |||
|
|||
next = (FAR struct mm_freenode_s *)((char *)node + node->size); | |||
#ifdef CONFIG_MM_REALTIME_SUPPORT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Below is our style.
#ifdef CONFIG_MM_REALTIME_SUPPORT
if (A)
#endif
{
do_something();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks.
struct mm_heap_s *heap; | ||
int ndx; | ||
|
||
heap = mm_get_heap(addr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you'd better change type from void, and return error if mm_get_heap returns null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks.
os/mm/mm_heap/mm_heapstat.c
Outdated
mm_givesemaphore(heap); | ||
} | ||
|
||
void mm_heapstat_reset(char *addr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks.
heap->mm_realtime_miss[ndx] = 0; | ||
} | ||
mm_givesemaphore(heap); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we separate binary, application call these 2 apis? It's not registered syscall.
I Think you'd better expand proc if you want to display info of heap stat in application..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are included in user library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it.
|
||
for (i = 0; i < MM_REALTIME_SUPPORT_NUMOF_SIZES; ++i) { | ||
if (heap->mm_realtime_num[i] < 1) { | ||
heap->mm_realtime_num[i] = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about use unsigned int?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so because it's not a size but a signed number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean it allowed negative value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, but I checked whether the input is negative at line 170.
However, if this var is unsigned, it might be greater than the maximum number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned unsigned type because it is stable for kind of size of buffer, address, length, and so on.
We usually use size_t or ssize_t for it, That's why I commented it, choice is yours.
os/mm/mm_heap/mm_initialize.c
Outdated
|
||
/* First, add one big chunk of free node for non-realtime. */ | ||
node = (FAR struct mm_freenode_s *)(heapbase + SIZEOF_MM_ALLOCNODE); | ||
node->size = heapsize - 2 * SIZEOF_MM_ALLOCNODE - mem_pool_size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You had better add bracket for multiplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's necessary, but fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes minor one, just for readability, thanks.
mm_heapstat_reset(addr); | ||
printf("\nReset the stat of heap for realtime support."); | ||
} else { | ||
printf("Usage: %s [reset]\n", argv[1]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you need free(addr)
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, dear.
Fixed. Thanks.
size_t miss[MM_REALTIME_SUPPORT_NUMOF_SIZES] = { 0, }; | ||
int num[MM_REALTIME_SUPPORT_NUMOF_SIZES] = { 0, }; | ||
|
||
addr = (char *)malloc(sizeof(char)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so that add free(addr)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks.
39bc5e7
to
51e7c0d
Compare
Target : [51e7c0d1d16daa63a5cd18e9e5917c32d9e62c11] - Code Rule Check (C++) OK. |
Target : [51e7c0d1d16daa63a5cd18e9e5917c32d9e62c11] - Code Rule Check OK. |
@@ -671,6 +695,9 @@ void mm_addfreechunk(FAR struct mm_heap_s *heap, FAR struct mm_freenode_s *node) | |||
/* Functions contained in mm_size2ndx.c.c ***********************************/ | |||
|
|||
int mm_size2ndx(size_t size); | |||
#ifdef CONFIG_MM_REALTIME_SUPPORT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the below?
#ifdef CONFIG_MM_REALTIME_SUPPORT
int mm_size2ndx_realtime(FAR struct mm_heap_s *heap, size_t size);
#else
int mm_size2ndx(size_t size);
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment, but it's an additional function in case of realtime support.
#endif | ||
|
||
size_t tsize = (MM_REALTIME_SUPPORT_NUMOF_SIZES + 2) * MM_REALTIME_SUPPORT_STEP_SIZE; | ||
heap->mm_ndx_offset = (tsize >> MM_MIN_SHIFT) - mm_size2ndx(tsize) - 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't mm_size2ndx_realtime()
instead of mm_size2ndx()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment, but in order to compute the offset the original function, mm_size2ndx(), is required.
…thin a constant time Do memory allocation and releasing within a constant time if the requested size is less than or equal to (16 * MM_REALTIME_SUPPORT_NUMOF_SIZES), where MM_REALTIME_SUPPORT_NUMOF_SIZES is the number of sizes for realtime support, starting from 16 bytes with 16 bytes step. For example, if MM_REALTIME_SUPPORT_NUMOF_SIZES is 3, 16, 32, 48 bytes memory can be allocated within a constant time. This number should be positive integer. MM_REALTIME_SUPPORT_NUMS is the list of numbers each of which means the number of a certain-sized free nodes which can be used for memory allocation within a constant time. For example, by default, MM_REALTIME_SUPPORT_NUMS = "100 100 100" means a hundred free nodes for each size, i.e, 16, 32, 48 bytes, are reserved for realtime support. The total amount of memory sizes for realtime support is calculated by (16 * N1 + 32 * N2 + ... + 16 * n * Nn) bytes, where n is the number of sizes (i.e., MM_REALTIME_SUPPORT_NUMOF_SIZES) and Nn is the number of free nodes for the size of 16 * n bytes. These numbers should not be negative integers. If n is larger than the number of these numbers, non-defined numbers of free nodes become, by default, zero.
…stat of heap for realtime support 'heapstat' is an utility app which shows the number of memory requests not allocated within a constant time. When MM_REALTIME_SUPPORT_NUMOF_SIZES = 8 and MM_REALTIME_SUPPORT_NUMS = "200 200 0 150 0 0 0 150", 'heapstat' might print out the current status as shown below: Size 16 bytes : 10 times, given 200 reserved nodes. Size 32 bytes : 20 times, given 200 reserved nodes. Size 48 bytes : 30 times, given 0 reserved nodes. Size 64 bytes : 0 times, given 150 reserved nodes. Size 80 bytes : 5 times, given 0 reserved nodes. Size 96 bytes : 0 times, given 0 reserved nodes. Size 112 bytes : 0 times, given 0 reserved nodes. Size 128 bytes : 8 times, given 150 reserved nodes.
51e7c0d
to
c5107ec
Compare
Target : [c5107ec] - Code Rule Check OK. |
Target : [c5107ec] - Code Rule Check (C++) OK. |
@@ -0,0 +1,3 @@ | |||
config ENTRY_HEAP_STAT_REALTIME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
Please add below Kconfig header as we follow in TizenRT.
#
# For a description of the syntax of this configuration file,
# see kconfig-language at https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt
#
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see the same header in other Kconfig_ENTRY files.
I will add this header in all Kconfig_ENTRY files if necessary.
Target : [c5107ec] - Code Rule Check (C++) OK. |
Target : [c5107ec] - Code Rule Check OK. |
1 similar comment
Target : [c5107ec] - Code Rule Check OK. |
…thin a constant time
Do memory allocation and releasing within a constant time
if the requested size is less than or equal to (16 * MM_REALTIME_SUPPORT_NUMOF_SIZES),
where MM_REALTIME_SUPPORT_NUMOF_SIZES is the number of sizes for realtime support,
starting from 16 bytes with 16 bytes step.
For example, if MM_REALTIME_SUPPORT_NUMOF_SIZES is 3,
16, 32, 48 bytes memory can be allocated within a constant time.
This number should be positive integer.
MM_REALTIME_SUPPORT_NUMS is the list of numbers each of which means the number of
a certain-sized free nodes which can be used for memory allocation within a constant time.
For example, by default, MM_REALTIME_SUPPORT_NUMS = "100 100 100" means
a hundred free nodes for each size, i.e, 16, 32, 48 bytes,
are reserved for realtime support. The total amount of memory sizes
for realtime support is calculated by (16 * N1 + 32 * N2 + ... + 16 * n * Nn) bytes,
where n is the number of sizes (i.e., MM_REALTIME_SUPPORT_NUMOF_SIZES)
and Nn is the number of free nodes for the size of 16 * n bytes.
These numbers should not be negative integers.
If n is larger than the number of these numbers, non-defined numbers of free nodes
become, by default, zero.