Request review for re-alloc patch @k_mem_pool_alloc()


Xin Zhou
 

Hi


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


安全操作系统与驱动
解决方案一部/解决方案部/深圳市中兴微电子技术有限公司


南京市雨花台区紫荆花路68号中兴通讯南京研发中心4C

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@...


Boie, Andrew P
 

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.

http://docs.zephyrproject.org/contribute/contribute_guidelines.html

 

Andrew

 

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()

 

Hi

 

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

 

安全操作系统与驱动
解决方案一部/解决方案部/深圳市中兴微电子技术有限公司

 

南京市雨花台区紫荆花路68号中兴通讯南京研发中心4C

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@...

 


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.

Thanks,
Leandro

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.
http://docs.zephyrproject.org/contribute/contribute_guidelines.html
Andrew
*From:*zephyr-devel-bounces@lists.zephyrproject.org [mailto:zephyr-devel-bounces@lists.zephyrproject.org] *On Behalf Of *zhou.xin8@sanechips.com.cn
*Sent:* Wednesday, December 20, 2017 12:26 AM
*To:* zephyr-devel@lists.zephyrproject.org
*Cc:* liu.yanan1@sanechips.com.cn; leng.tong@zte.com.cn
*Subject:* [Zephyr-devel] Request review for re-alloc patch @k_mem_pool_alloc()
Hi
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
安全操作系统与驱动
解决方案一部/解决方案部/深圳市中兴微电子技术有限公司

南京市雨花台区紫荆花路68号中兴通讯南京研发中心4C
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@sanechips.com.cn
_______________________________________________
Zephyr-devel mailing list
Zephyr-devel@lists.zephyrproject.org
https://lists.zephyrproject.org/mailman/listinfo/zephyr-devel