2015-12-10 141 views
1

看看底部的补丁。C静态内联函数调用外部函数动机

--- 
drivers/iommu/iommu.c    | 4 ++-- 
drivers/iommu/msm_iommu_domains.c | 2 +- 
include/linux/iommu.h    | 6 +++++- 
3 files changed, 8 insertions(+), 4 deletions(-) 

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c 
index 7848f47..c2f694c 100644 
--- a/drivers/iommu/iommu.c 
+++ b/drivers/iommu/iommu.c 
@@ -670,7 +670,7 @@ void iommu_set_fault_handler(struct iommu_domain *domain, 
} 
EXPORT_SYMBOL_GPL(iommu_set_fault_handler); 

-struct iommu_domain *iommu_domain_alloc(struct bus_type *bus, int flags) 
+struct iommu_domain *iommu_domain_alloc_flags(struct bus_type *bus, int flags) 
{ 
    struct iommu_domain *domain; 
    int ret; 
@@ -695,7 +695,7 @@ out_free: 

    return NULL; 
} 
-EXPORT_SYMBOL_GPL(iommu_domain_alloc); 
+EXPORT_SYMBOL_GPL(iommu_domain_alloc_flags); 

void iommu_domain_free(struct iommu_domain *domain) 
{ 
diff --git a/drivers/iommu/msm_iommu_domains.c b/drivers/iommu/msm_iommu_domains.c 
index 26a3f85..7619e66 100644 
--- a/drivers/iommu/msm_iommu_domains.c 
+++ b/drivers/iommu/msm_iommu_domains.c 
@@ -506,7 +506,7 @@ int msm_register_domain(struct msm_iova_layout *layout) 
    if (data->domain_num < 0) 
     goto free_pools; 

- data->domain = iommu_domain_alloc(bus, layout->domain_flags); 
+ data->domain = iommu_domain_alloc_flags(bus, layout->domain_flags); 
    if (!data->domain) 
     goto free_domain_num; 

diff --git a/include/linux/iommu.h b/include/linux/iommu.h 
index fb1efec..8bd9d3f 100644 
--- a/include/linux/iommu.h 
+++ b/include/linux/iommu.h 
@@ -131,7 +131,11 @@ struct iommu_ops { 

extern int bus_set_iommu(struct bus_type *bus, struct iommu_ops *ops); 
extern bool iommu_present(struct bus_type *bus); 
-extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus, int flags); 
+extern struct iommu_domain *iommu_domain_alloc_flags(struct bus_type *bus, int flags); 
+static inline struct iommu_domain *iommu_domain_alloc(struct bus_type *bus) 
+{ 
+ return iommu_domain_alloc_flags(bus, 0); 
+} 
extern struct iommu_group *iommu_group_get_by_id(int id); 
extern void iommu_domain_free(struct iommu_domain *domain); 
extern int iommu_attach_device(struct iommu_domain *domain, 
-- 

这个补丁有什么好处,即是否有任何性能胜利?

inlinestatic函数调用extern是不是很好的编程习惯?

如果extern意味着外部连接,即函数定义在其他地方,那么在static函数中使用它是安全的,该函数说“此函数只能在该翻译单元中可见”?

通过这样的回答来看:Inline functions and external linkage

所以 “外部链接” 和 “内联” 是不是唯一的; “external linkage”意思是该功能可以在任何翻译单位中参考,“inline”意味着它必须在调用它的任何翻译单位 中定义。

inlineexternal显然不是在打架,但static存在是什么困扰着我。

感谢

+0

'static'停止它定义与外部链接功能的副本。 –

回答

1

什么是这个补丁的效果,即是否有任何性能的胜利?

看起来像一个接口的变化,他们改变了函数的名称和参数,然后添加了一个额外的函数。这是功能的变化,与性能无关。

内联静态函数调用外部函数是不错的编程习惯吗?

当然,这只是意味着static函数是声明模块的内部函数,并且对调用方不可用。

在静态函数中使用它是安全的,它说“这个函数只能在这个翻译单元中可见”?

当使用extern链接调用函数时,从static函数或从其他任何位置调用函数时没有区别。调用者的链接与被调用函数的链接无关。