Skip to content

Conversation

@Guozhanxin
Copy link
Member

@Guozhanxin Guozhanxin commented Feb 16, 2023

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

workqueue 用于中断得延后处理机制时,丢失中断频繁

你的解决方案是什么 (what is your solution)

减少临界区,提交重复work时,不需要检查判忙。

在什么测试环境下测试通过 (what is the test environment)

stm32l475潘多拉,测试代码及结果见下面评论
]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification

@Guozhanxin Guozhanxin requested a review from enkiller February 16, 2023 12:22
@Guozhanxin
Copy link
Member Author

Guozhanxin commented Feb 16, 2023

workqueue 用于中断得延后处理机制,统计丢失中断得数目。

修改前

image

修改后

image

修改后明显丢失中断数目减少

测试代码

#include <rtthread.h>
#include <rtdevice.h>

static rt_timer_t timer;
static int a = 0, b = 0;
struct rt_workqueue * workqueue;
struct rt_work work;
void work_func(struct rt_work *work, void *work_data)
{
    a++;
    rt_kprintf("work item run %d times\n", a);
}
static void timeout_func(void *parameter)
{
    b++;

    rt_workqueue_dowork(workqueue, &work);
    if (b > 100)
    {
        rt_timer_stop(timer);
        rt_kprintf("timeout_func run %d times\n", b);
    }
}

int main(void)
{
    workqueue = rt_workqueue_create("workqueue", 2048, 20);
    if (workqueue == RT_NULL)
    {
        rt_kprintf("create workqueue failed\n");
        return -1;
    }
    rt_work_init(&work, work_func, RT_NULL);
    timer = rt_timer_create("timer", timeout_func, RT_NULL, 1, RT_TIMER_FLAG_PERIODIC);
    if (timer == RT_NULL)
    {
        rt_kprintf("create timer failed\n");
        return -1;
    }
    rt_timer_start(timer);
    
    return 0;
}

@mysterywolf mysterywolf added +1 Agree +1 +2 Agree +2 labels Feb 17, 2023
@mysterywolf mysterywolf merged commit b065486 into RT-Thread:master Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

+1 Agree +1 +2 Agree +2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants