-
Couldn't load subscription status.
- Fork 8.1k
io32_memcpy #51482
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
io32_memcpy #51482
Conversation
It's the backend for a few other CAN-FD drivers, but you can't build it directly. Instead you can e.g. build any CAN sample or test for |
f30dec5 to
de10a5e
Compare
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.
Are you doing this specifically to have a memcpy32 for IO purposes?
If so, should rename to memcpy_io32 or something like that.
|
@galak : I will rename as such, do you have any other feedback? I'd prefer to wait until all feedback is given in case there is some feedback that completely blocks the PR. |
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.
Looks good to me
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.
Nitpickery: Can we name this something less generic? Maybe sys_wordcopy32() or something? Calling it "memcpy" and putting it in util.h makes it sound like something regular apps are expected to use. And while, sure, this can be implemented in pure C it exists only to honor MMIO requirements of hardware with behavior way outside the C standard.
Also, note that this is sort of a can of worms. What if the hardware has ordering requirements? Does the copy work identically forward and backwards? Hardware can have prefetch units and write combining that messes this up even if the software is doing everything right.
I guess my worry is this: this meets the requirements of that one piece of MCAN hardware (and on the particular SOC integration!). How many other devices are actually going to productively use it? My guess "not enough to make this a standard-looking memcpy".
|
@andyross m_can is actually a driver backend used on many SoC. |
|
@SebastianBoe What use-case do you have for this outside of the M_CAN driver? I tend to agree with @andyross. |
|
@henrikbrixandersen : My use-case was to copy data from nRF->UICR->OTP MMIO, that had this limitation, to RAM. So in my case I eventuallly found that it's awkward that the function requires the buffer in RAM to be word-aligned. I'm not sure about what to do about that. Maybe it's trivial to enforce word-aligned RAM on the buffer being written to. Maybe the MCAN use-case also actually only needs word-aligned enforcement on the read, and not the write. I intend to investigate and address comments. But I want to wait a bit for feedback so I don't have to revisit this many times. |
|
"Can we name this something less generic? Maybe sys_wordcopy32() or something?" I'd like to keep the term memcpy and 32, but we can add io, or sys, or both. memcpy32 can be familiar to other developers: https://lwn.net/Articles/165519/ and clearly communicates that it's a variant of memcpy. wordcopy is not as clear. |
|
@SebastianBoe the reason why we need to copy in 32bit chunks is that the lower two address lines are not present in the m_can. If you use the byte wise copy, all four bytes of the 32bits end up in the first byte. |
de10a5e to
cb97772
Compare
cb97772 to
dcf61ca
Compare
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 update the commit subjects to indicate the actual changes
util: memcpy32drivers: mcan
Aren't useful
include/zephyr/sys/util.h
Outdated
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.
probably can remove this line
lib/os/Kconfig
Outdated
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.
do we really need a Kconfig option for this?
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.
Agreed, @SebastianBoe is this really 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.
Yes, there is no pre-existing source file that the function belongs in.
And we don't want to unconditionally invoke gcc for something that is rarely used as it slows down the build and creates noise in the build.
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 still have a vague sense that this is too specific an API to be useful, but the name is no longer ambiguous and I don't see why it shouldn't be merged.
|
@alexanderwachter - do you have any input here? |
|
I have two comments still open. Bit no blockers. |
include/zephyr/sys/util.h
Outdated
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 would be a reason not to introduce io32_memset here if we are doing this?
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.
Out-of-scope for this PR.
A PR that adds this would be welcome.
dcf61ca to
83fe059
Compare
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.
There needs to be a test for this.
Implement memcpy32, a version of memcpy that only performs 32 bit word-wise copying. Based on Pete Dietl's and the mcan implementation. Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Use io32_memcpy for word-wise copying Fixes zephyrproject-rtos#41074 Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
83fe059 to
4379bed
Compare
|
"There needs to be a test for this." It is trivial enough to be proof-read to be correct. And it is system-tested as it is used by mcan. |
While the function itself is simple enough, who is to say it will not break on some architectures and toolchains because of some ABI-specific details and/or compiler optimisations? It is very important that we sanity-check/validate basic functions like these to ensure that they behave as intended. Also, this is technically an API. Every API function ought to have a corresponding test. |
I was just bitten by this. Code was "trivial enough to be proof-read to be correct" but it actually introduced a subtle bug that could have been easily avoided by including a test. It was before I became POSIX maintainer, but I still was on the approve list. Pay your future self and the future selves of maintainers please 😁 |
|
@stephanosio : Unfortunately I am unable to prioritize spending time adding a test for this. Please, in future reviews, try to leave all comments in one pass to avoid multiple review iterations. |
Implement memcpy32, a version of memcpy that only performs 32 bit
word-wise copying. (useful for MMIO).
Based on Pete Dietl's implementation and the mcan implementation.
Also make use of it from mcan.
I was not able to find a way to build mcan.
But I have done some simple testing locally.
A second attempt at #41273