sched/topology: One function call less in build_group_from_child_sched_domain()
Subsystems (2)
PATCH 1/1 sched/topology: One function call less in build_group_from_child_sched_domain()
From: Markus Elfring <[email protected]>
Date: Sat, 6 Jul 2019 16:00:13 +0200
Avoid an extra function call by using a ternary operator instead of a conditional statement.
This issue was detected by using the Coccinelle software.
--- kernel/sched/topology.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
kernel/sched/topology.c +1 -5
@@ -886,11 +886,7 @@ build_group_from_child_sched_domain(struct sched_domain *sd, int cpu)return NULL ; sg_span =sched_group_span (sg); -if (sd->child) -cpumask_copy (sg_span,sched_domain_span (sd->child)); -else -cpumask_copy (sg_span,sched_domain_span (sd)); - +cpumask_copy (sg_span,sched_domain_span (sd->child ? sd->child : sd));atomic_inc (&sg->ref);return sg; }
--
2.22.0
Quoted 18 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 6 Jul 2019 16:00:13 +0200Avoid an extra function call by using a ternary operator instead of a conditional statement.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- kernel/sched/topology.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)kernel/sched/topology.c +0
-0
kernel/sched/topology.c build_group_from_child_sched_domain(struct sched_domain *sd, int cpu) · line 889
Quoted 9 lines
kernel/sched/topology.c +1
-5@@ -886,11 +886,7 @@ build_group_from_child_sched_domain(struct sched_domain *sd, int cpu)return NULL ; sg_span =sched_group_span (sg); -if (sd->child) -cpumask_copy (sg_span,sched_domain_span (sd->child)); -else -cpumask_copy (sg_span,sched_domain_span (sd)); - +cpumask_copy (sg_span,sched_domain_span (sd->child ? sd->child : sd));
At runtime, Are we avoiding a function call?
However I think we are avoiding a branch instead of a conditional, which may be beneficial.
Quoted 6 lines
kernel/sched/topology.c +0
-1atomic_inc (&sg->ref);return sg; } --2.22.0
Signature · 2 lines
Thanks and Regards Srikar Dronamraju
Quoted 22 lines · Srikar Dronamraju
Quoted 20 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 6 Jul 2019 16:00:13 +0200Avoid an extra function call by using a ternary operator instead of a conditional statement.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- kernel/sched/topology.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)kernel/sched/topology.c +0
-0@@ -886,11 +886,7 @@ build_group_from_child_sched_domain(struct sched_domain *sd, int cpu)return NULL ;
Quoted 11 lines
kernel/sched/topology.c build_group_from_child_sched_domain(struct sched_domain *sd, int cpu) · line 889
Quoted 7 lines
kernel/sched/topology.c +1
-5sg_span =sched_group_span (sg); -if (sd->child) -cpumask_copy (sg_span,sched_domain_span (sd->child)); -else -cpumask_copy (sg_span,sched_domain_span (sd)); - +cpumask_copy (sg_span,sched_domain_span (sd->child ? sd->child : sd));At runtime, Are we avoiding a function call?
However I think we are avoiding a branch instead of a conditional, which may be beneficial.
If you're assuming the compiler doesn't already optimize that (no idea whether gcc really does that).
@Markus: could you check what gcc is actually generating out of both the old and your new version ?
--mtx
Signature · 3 lines
Enrico Weigelt, metux IT consult Free software and Linux embedded engineering [email protected] -- +49-151-27565287
Quoted 5 lines · Enrico Weigelt, metux IT consult
Quoted 4 lines
At runtime, Are we avoiding a function call?
However I think we are avoiding a branch instead of a conditional, which may be beneficial.
Quoted 7 lines
If you're assuming the compiler doesn't already optimize that (no idea whether gcc really does that).
@Markus: could you check what gcc is actually generating out of both the old and your new version ?
I had already tried looking at the object files both on X86 and PowerPc and in both cases (with and without patch) the generated code differs.
Quoted 7 lines
--mtx
Signature · 3 lines
Enrico Weigelt, metux IT consult Free software and Linux embedded engineering [email protected] -- +49-151-27565287
Signature · 2 lines
Thanks and Regards Srikar Dronamraju
Peter Zijlstra
maintainerQuoted 22 lines · Srikar Dronamraju
Quoted 20 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 6 Jul 2019 16:00:13 +0200Avoid an extra function call by using a ternary operator instead of a conditional statement.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- kernel/sched/topology.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)kernel/sched/topology.c +0
-0@@ -886,11 +886,7 @@ build_group_from_child_sched_domain(struct sched_domain *sd, int cpu)return NULL ;
Quoted 11 lines
kernel/sched/topology.c build_group_from_child_sched_domain(struct sched_domain *sd, int cpu) · line 889
Quoted 7 lines
kernel/sched/topology.c +1
-5sg_span =sched_group_span (sg); -if (sd->child) -cpumask_copy (sg_span,sched_domain_span (sd->child)); -else -cpumask_copy (sg_span,sched_domain_span (sd)); - +cpumask_copy (sg_span,sched_domain_span (sd->child ? sd->child : sd));At runtime, Are we avoiding a function call?
However I think we are avoiding a branch instead of a conditional, which may be beneficial.
It all depends on what the compiler does; also this is super slow path stuff and the patch makes code less readable (IMO).
Quoted 35 lines · Peter Zijlstra
Quoted 22 lines · Srikar Dronamraju
Quoted 20 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sat, 6 Jul 2019 16:00:13 +0200Avoid an extra function call by using a ternary operator instead of a conditional statement.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>--- kernel/sched/topology.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)kernel/sched/topology.c +0
-0@@ -886,11 +886,7 @@ build_group_from_child_sched_domain(struct sched_domain *sd, int cpu)return NULL ;Quoted 11 lines
kernel/sched/topology.c build_group_from_child_sched_domain(struct sched_domain *sd, int cpu) · line 889
Quoted 7 lines
kernel/sched/topology.c +1
-5sg_span =sched_group_span (sg); -if (sd->child) -cpumask_copy (sg_span,sched_domain_span (sd->child)); -else -cpumask_copy (sg_span,sched_domain_span (sd)); - +cpumask_copy (sg_span,sched_domain_span (sd->child ? sd->child : sd));At runtime, Are we avoiding a function call?
However I think we are avoiding a branch instead of a conditional, which may be beneficial.
Quoted 3 lines
It all depends on what the compiler does; also this is super slow path stuff and the patch makes code less readable (IMO).
Yes, it definitely makes code readable. I was only commenting on the changelog/subject which says avoids a function call which I think it doesn't.
Signature · 2 lines
Thanks and Regards Srikar Dronamraju
Quoted 1 line
Yes, it definitely makes code readable.
Some developers seem to get difficulties with this view.
Quoted 2 lines
I was only commenting on the changelog/subject which says avoids a function call which I think it doesn't.
Do you prefer an other wording for calling functions only once with a selected parameter value instead of calling them (unoptimised) within two branches of an if statement?
Regards,
Markus