linux - Linux 内核中的 DECLARE_COMPLETION_ONSTACK 功能

标签 linux linux-kernel linux-device-driver embedded-linux spi

谁能帮助我理解“DECLARE_COMPLETION_ONSTACK”和静态(DECLARE_COMPLETION(comp))或动态初始化之间的区别?

我找到了一些引用资料,如下所示(http://lxr.free-electrons.com/source/drivers/spi/spidev.c#L110):

110 spidev_sync(struct spidev_data *spidev, struct spi_message *message)
111 {
112         DECLARE_COMPLETION_ONSTACK(done);
113         int status;
114 
115         message->complete = spidev_complete;
116         message->context = &done;
117 
118         spin_lock_irq(&spidev->spi_lock);
119         if (spidev->spi == NULL)
120                 status = -ESHUTDOWN;
121         else
122                 status = spi_async(spidev->spi, message);
123         spin_unlock_irq(&spidev->spi_lock);
124 
125         if (status == 0) {
126                 wait_for_completion(&done);
127                 status = message->status;
128                 if (status == 0)
129                         status = message->actual_length;
130         }
131         return status;
132 }

看起来这里是在等待 spi_sync() 函数完成,我在理解上述函数时有几个疑问

2:这是否意味着这个函数不是真正的并发?(因为这个完成变量强加了一种序列化)

BR, & 斯里达尔

最佳答案

不开启LOCK_DEP没有区别。

它仅对锁定调试功能有用。

查看下面的内核代码,

47/*
48 * Lockdep needs to run a non-constant initializer for on-stack
49 * completions - so we use the _ONSTACK() variant for those that
50 * are on the kernel stack:
51 */

59#ifdef CONFIG_LOCKDEP
60# define DECLARE_COMPLETION_ONSTACK(work) \
61  struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
62#else
63# define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
64#endif

关于linux - Linux 内核中的 DECLARE_COMPLETION_ONSTACK 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27205152/

相关文章:

java - 使用 uinput 驱动程序创建虚拟多点触控设备

C: 2 个不同的头文件定义了 struct udphdr。如何告诉 GCC 选择一个?

linux - 迭代 Ansible 设置命令

network-programming - 增加 SKB 的引用计数

linux-kernel - Linux 中的 OE+ 是什么?

具有循环缓冲区的字符驱动程序

linux - 以编程方式读取linux内核参数

linux - linux passwd 命令如何确保它无法从非特权帐户修改其他用户的密码

C++ -fvisibility=hidden -fvisibility-inlines-hidden

linux-kernel - 是否有任何内核工具可用于以合理的精度测量中断延迟?