-
Notifications
You must be signed in to change notification settings - Fork 349
alloc: free_block: perform wb/inv for the blocks #4861
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
Conversation
|
SOFCI TEST |
1 similar comment
|
SOFCI TEST |
When freeing blocks, we need to perform writeback and invalidate to the dirty cache lines, otherwise, they will be evicted from the cache at some point in the future, which will break the usage of the same memory region from another DSP core. Introduce a free_ptr to make sure the original 'ptr' is not changed, so we can use it for this wb/inv operation. Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
kv2019i
left a comment
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 an important fix for sure. One comment on implementation, but not a blocking concern.
| * future, on top of the memory region now being used for | ||
| * different purposes on another core. | ||
| */ | ||
| dcache_writeback_invalidate_region(ptr, block_map->block_size * hdr->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.
@keyonjie I wonder why you use "ptr" here. I guess this is harmless, but it seems this may be called also on noncached pointers.
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.
@keyonjie I wonder why you use "ptr" here. I guess this is harmless, but it seems this may be called also on noncached pointers.
The dcache_writeback_invalidate_region() internal will do nothing for noncached "ptr", and do flush and invalidate for cached "ptr".
The "ptr" is what the user/caller used, while it could be different with the one used for memory blocks management. Imagine that we are using uncached address for BUFFER zone management, while user can use its corresponding cached alias to read/write from the cache lines. That's why we might need to free blocks with uncached_ptr, and do wb/inv with cached one.
On the other hand, if the user/caller uses uncached ptr directly, we don't want/need to do extra/superfluous wb/inv with its alias cached ptr (cached_ptr), so use "ptr" -- the one the user used and pass it into dcache_writeback_invalidate_region() to decide if wb/inv is actually needed.
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.
@keyonjie what about the size of the memory you're invalidatign and writing back here? Shouldnt we be using the original size that was allocated?
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.
@keyonjie what about the size of the memory you're invalidatign and writing back here? Shouldnt we be using the original size that was allocated?
We don't have the original size from the rfree() invoking, and since the whole block is occupied by the caller exclusively, so wb/invalidate the whole block size is safe, although the caller may actually not touching some portion of it at all.
OTOH, if parts of the specified address is not in the cache (as the caller not touching it at all), the wb/inv instruction will actually has no effect on those address, no actual writeback or invalidate happens with those address.
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.
@keyonjie thats good but then shouldnt we be using free_ptr instead of ptr?
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.
@keyonjie thats good but then shouldnt we be using free_ptr instead of ptr?
No, please see my comment above: #4861 (comment)
The free_ptr could be different with the user used ptr.
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.
@keyonjie Isn't it possible that you then wbinv part of the next block? To be fair you're not losing data so this is reasonable but was this accounted for when you wrote the patch?
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.
@paulstelian97 Yes, that was considered: one fact is that all the return allocated pointers are PLATFORM_DCACHE_ALIGN aligned today, so there is no 2 allocated buffers share a same dcache line, wbinv of one allocated cached buffer will not take the cache line from another allocated buffer.
When freeing blocks, we need to perform writeback and invalidate to the
dirty cache lines, otherwise, they will be evicted from the cache at
some point in the future, which will break the usage of the same memory
region from another DSP core.
Introduce a free_ptr to make sure the original 'ptr' is not changed, so
we can use it for this wb/inv operation.
Signed-off-by: Keyon Jie yang.jie@linux.intel.com