* [PATCH]optimize error handling in tick_check_new_device
@ 2016-07-27 12:06 Gaurav Jindal (Gaurav Jindal)
2016-07-27 12:23 ` Nicolai Stange
2016-07-28 14:50 ` Thomas Gleixner
0 siblings, 2 replies; 3+ messages in thread
From: Gaurav Jindal (Gaurav Jindal) @ 2016-07-27 12:06 UTC (permalink / raw)
To: tglx; +Cc: linux-kernel, Sanjeev Yadav (Sanjeev Kumar Yadav)
In the function tick_check_new_device, module error is handled after checking
if the newdev should go as broadcast-installation device in the functions
tick_check_percpu and tick_check_preferred. In case the try_module_get returns
false, the above 2 calls are extra thus wasting CPU cycles.
Shifting the try_module_get as first error handling saves CPU cycles when there
is nothing to do in case of module related error.
Signed-off-by:Gaurav Jindal<gaurav.jindal@spreadtrum.com>
Co-developed-by:Sanjeev Yadav<sanjeev.yadav@spreadtrum.com>
---
diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c
index 4fcd99e..23faf4a 100644
--- a/kernel/time/tick-common.c
+++ b/kernel/time/tick-common.c
@@ -307,6 +307,9 @@ void tick_check_new_device(struct clock_event_device *newdev)
td = &per_cpu(tick_cpu_device, cpu);
curdev = td->evtdev;
+ if (!try_module_get(newdev->owner))
+ return;
+
/* cpu local device ? */
if (!tick_check_percpu(curdev, newdev, cpu))
goto out_bc;
@@ -315,8 +318,6 @@ void tick_check_new_device(struct clock_event_device *newdev)
if (!tick_check_preferred(curdev, newdev))
goto out_bc;
- if (!try_module_get(newdev->owner))
- return;
/*
* Replace the eventually existing device by the new
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH]optimize error handling in tick_check_new_device
2016-07-27 12:06 [PATCH]optimize error handling in tick_check_new_device Gaurav Jindal (Gaurav Jindal)
@ 2016-07-27 12:23 ` Nicolai Stange
2016-07-28 14:50 ` Thomas Gleixner
1 sibling, 0 replies; 3+ messages in thread
From: Nicolai Stange @ 2016-07-27 12:23 UTC (permalink / raw)
To: Gaurav Jindal (Gaurav Jindal)
Cc: tglx, linux-kernel, Sanjeev Yadav (Sanjeev Kumar Yadav)
"Gaurav Jindal (Gaurav Jindal)" <Gaurav.Jindal@spreadtrum.com> writes:
> diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c
> index 4fcd99e..23faf4a 100644
> --- a/kernel/time/tick-common.c
> +++ b/kernel/time/tick-common.c
> @@ -307,6 +307,9 @@ void tick_check_new_device(struct clock_event_device *newdev)
> td = &per_cpu(tick_cpu_device, cpu);
> curdev = td->evtdev;
>
> + if (!try_module_get(newdev->owner))
> + return;
> +
Doesn't this leak a reference to newdev->owner if one of the following
conditions hold?
> /* cpu local device ? */
> if (!tick_check_percpu(curdev, newdev, cpu))
> goto out_bc;
> @@ -315,8 +318,6 @@ void tick_check_new_device(struct clock_event_device *newdev)
> if (!tick_check_preferred(curdev, newdev))
> goto out_bc;
> - if (!try_module_get(newdev->owner))
> - return;
>
Thanks,
Nicolai
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH]optimize error handling in tick_check_new_device
2016-07-27 12:06 [PATCH]optimize error handling in tick_check_new_device Gaurav Jindal (Gaurav Jindal)
2016-07-27 12:23 ` Nicolai Stange
@ 2016-07-28 14:50 ` Thomas Gleixner
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Gleixner @ 2016-07-28 14:50 UTC (permalink / raw)
To: Gaurav Jindal (Gaurav Jindal)
Cc: linux-kernel, Sanjeev Yadav (Sanjeev Kumar Yadav)
On Wed, 27 Jul 2016, Gaurav Jindal (Gaurav Jindal) wrote:
> In the function tick_check_new_device, module error is handled after checking
> if the newdev should go as broadcast-installation device in the functions
> tick_check_percpu and tick_check_preferred. In case the try_module_get returns
> false, the above 2 calls are extra thus wasting CPU cycles.
This is hardly a fast path so the extra cycles do not matter at all. As a
result of your change you leak a module reference when the 'goto out_bc' is
taken. So I prefer the existing correct version over a pretty uninteresting
speedup.
Thanks,
tglx
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-07-28 14:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-27 12:06 [PATCH]optimize error handling in tick_check_new_device Gaurav Jindal (Gaurav Jindal)
2016-07-27 12:23 ` Nicolai Stange
2016-07-28 14:50 ` Thomas Gleixner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).