C静态内联函数调用extern函数的动机
C static inline function calling extern function motivation
看看底部补丁
---
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,
--
这个补丁有什么好处,即有什么性能提升?
让 inline
static
函数调用一个 extern
是好的编程习惯吗?
如果extern
表示外部链接,即函数定义在别处,在"this function should be visible only within this translation unit"的static
函数中使用它是否安全?
根据这个答案判断:Inline functions and external linkage
So "external linkage" and "inline" are not exclusive; "external
linkage" means that the function may be referred to in any translation
unit, and "inline" means that it must be defined in any translation
unit that calls it.
inline
和 external
显然不是在打架,但是 static
的存在让我很困扰。
谢谢
What is the benefit of this patch, i.e. are there any performance wins?
好像换了个界面,改了一个函数的名字和参数,然后又多了一个函数。是功能的改变,与性能无关。
Is it good programming practice to have inline static function calling one which is extern?
当然可以,这只是意味着 static
函数在声明它的模块内部,调用者不可用。
is it safe that to use it in static function which says "this function should be visible only within this translation unit"?
使用外部链接调用函数时,从 static
函数或从其他任何地方调用函数没有区别。调用者的链接与被调用函数的链接无关。
看看底部补丁
---
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,
--
这个补丁有什么好处,即有什么性能提升?
让 inline
static
函数调用一个 extern
是好的编程习惯吗?
如果extern
表示外部链接,即函数定义在别处,在"this function should be visible only within this translation unit"的static
函数中使用它是否安全?
根据这个答案判断:Inline functions and external linkage
So "external linkage" and "inline" are not exclusive; "external linkage" means that the function may be referred to in any translation unit, and "inline" means that it must be defined in any translation unit that calls it.
inline
和 external
显然不是在打架,但是 static
的存在让我很困扰。
谢谢
What is the benefit of this patch, i.e. are there any performance wins?
好像换了个界面,改了一个函数的名字和参数,然后又多了一个函数。是功能的改变,与性能无关。
Is it good programming practice to have inline static function calling one which is extern?
当然可以,这只是意味着 static
函数在声明它的模块内部,调用者不可用。
is it safe that to use it in static function which says "this function should be visible only within this translation unit"?
使用外部链接调用函数时,从 static
函数或从其他任何地方调用函数没有区别。调用者的链接与被调用函数的链接无关。