Re: Request review for re-alloc patch @k_mem_pool_alloc()

Leandro Pereira

Andrew, Zhou Xin,

`ret` is checked against `-EAGAIN` in the `if` statement below. The calling function has to handle this error case; it's actually part of the documented interface. However, I agree that it should retry allocating until it reaches the timeout (or forever, if `timeout` is `K_FOREVER`), and it's not doing it in this case. In fact, the comment in pool_alloc() mentioning `-EAGAIN` seems to agree with your patch, but the current implementation doesn't.

So, yes, please send a pull request. GitHub is currently the best channel for this kind of discussion, as not only it's easier to track patches, the CI system will test them against a battery of tests to ensure things are not broken.


On 12/20/2017 09:34 AM, Boie, Andrew P wrote:
Can you please send this as a pull request in github?
An explanation of what the race is in the commit message will helpful to reviewers.
*From:*zephyr-devel-bounces@... [mailto:zephyr-devel-bounces@...] *On Behalf Of *zhou.xin8@...
*Sent:* Wednesday, December 20, 2017 12:26 AM
*To:* zephyr-devel@...
*Cc:* liu.yanan1@...; leng.tong@...
*Subject:* [Zephyr-devel] Request review for re-alloc patch @k_mem_pool_alloc()
When race condition failure (-EAGAIN), need to try re-alloc.
We have verified this patch on Zephyr OS v1.9.0.
Index: kernel/mempool.c
--- kernel/mempool.c    (revision 70)
+++ kernel/mempool.c    (working copy)
@@ -300,6 +300,11 @@
        while (1) {
                ret = pool_alloc(p, block, size);
+               /* [Sanechips] When race condition causes failure, re_alloc. */
+               if (ret == -EAGAIN) {
+                       continue;
+               }
                if (ret == 0 || timeout == K_NO_WAIT ||
                    ret == -EAGAIN || (ret && ret != -ENOMEM)) {
                        return ret;
周欣 Zhou Xin

4C/F, ZTE R&D Center(NanJing), No.68 ZiJinghua Road,
YuHuatai District, Nanjing, P.R.China, 210012
T: 025-52870384
M: +86 13770868539
E: zhou.xin8@...
Zephyr-devel mailing list

Join to automatically receive all group messages.