gpt4 book ai didi

Linux 设备驱动程序 : is the code shared between multiple devices using the same driver?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:44:26 26 4
gpt4 key购买 nike

假设我们有一些简单的 linux 设备驱动程序,其中:

static const struct of_device_id driver_match[] = {
{ .compatible = "vendor,device1" },
{ .compatible = "vendor,device2" },
{},
};

因此 device1device2 将绑定(bind)到同一个驱动程序。我们在驱动程序内部还有以下功能:

static int some_function(int never_mind)
{
static int count = 0;
// print "count" to the logs
....
}

在设备的 probe() 功能期间被调用几次。让我们假设设备“同时”初始化。我的问题是它是如何工作的? device1device2 会使用相同的 some_function 对象和相同的 count 变量还是它们会得到完全不同的实例?

是否有一些关于 linux 驱动程序/模块实际执行方式的好资源/书籍可用?我只能找到很多关于“如何编写驱动程序”的教程。

我很抱歉我不得不问这个问题而不是准备基本的驱动程序并自己检查这个,但我正在等待我的第一个支持 linux 的 SoC 并且无法抗拒更快地获得这些知识:(

最佳答案

Will device1 and device2 use the same some_function object and the same count variable or will they get completely different instances?

是的,他们将使用相同的功能和数据。 Linux 内核是一个整体内核,其中所有符号(驱动程序和核心功能)都加载到内存中,内核的每个其他部分都可以访问内存。 Init/probe 可能发生在不同的内核上,因此您需要正确保护或自动访问任何共享数据。在您的示例中,一个简单的原子增量/减量就可以解决问题。

关于Linux 设备驱动程序 : is the code shared between multiple devices using the same driver?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38856811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com