Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1384147 > unrolled thread
| Started by | Minfei Huang <mnghuan@gmail.com> |
|---|---|
| First post | 2016-04-21 14:30 +0200 |
| Last post | 2016-04-21 15:30 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] Remove useless test during exchanging values Minfei Huang <mnghuan@gmail.com> - 2016-04-21 14:30 +0200
Re: [PATCH] Remove useless test during exchanging values Peter Zijlstra <peterz@infradead.org> - 2016-04-21 15:30 +0200
| From | Minfei Huang <mnghuan@gmail.com> |
|---|---|
| Date | 2016-04-21 14:30 +0200 |
| Subject | [PATCH] Remove useless test during exchanging values |
| Message-ID | <rqlU6-EL-15@gated-at.bofh.it> |
The value delta is correct as well, although calc_load_idle[idx] is
equal to 0. Remove this useless test to improve performance, since this
function is called more frequently.
Signed-off-by: Minfei Huang <mnghuan@gmail.com>
---
kernel/sched/loadavg.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/kernel/sched/loadavg.c b/kernel/sched/loadavg.c
index ef71590..5a5d7ae 100644
--- a/kernel/sched/loadavg.c
+++ b/kernel/sched/loadavg.c
@@ -216,10 +216,9 @@ void calc_load_exit_idle(void)
static long calc_load_fold_idle(void)
{
int idx = calc_load_read_idx();
- long delta = 0;
+ long delta;
- if (atomic_long_read(&calc_load_idle[idx]))
- delta = atomic_long_xchg(&calc_load_idle[idx], 0);
+ delta = atomic_long_xchg(&calc_load_idle[idx], 0);
return delta;
}
--
2.6.3
[toc] | [next] | [standalone]
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Date | 2016-04-21 15:30 +0200 |
| Message-ID | <rqmQc-1lx-55@gated-at.bofh.it> |
| In reply to | #1384147 |
On Thu, Apr 21, 2016 at 08:28:28PM +0800, Minfei Huang wrote:
> The value delta is correct as well, although calc_load_idle[idx] is
> equal to 0. Remove this useless test to improve performance, since this
> function is called more frequently.
>
> Signed-off-by: Minfei Huang <mnghuan@gmail.com>
> ---
> kernel/sched/loadavg.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/sched/loadavg.c b/kernel/sched/loadavg.c
> index ef71590..5a5d7ae 100644
> --- a/kernel/sched/loadavg.c
> +++ b/kernel/sched/loadavg.c
> @@ -216,10 +216,9 @@ void calc_load_exit_idle(void)
> static long calc_load_fold_idle(void)
> {
> int idx = calc_load_read_idx();
> - long delta = 0;
> + long delta;
>
> - if (atomic_long_read(&calc_load_idle[idx]))
> - delta = atomic_long_xchg(&calc_load_idle[idx], 0);
> + delta = atomic_long_xchg(&calc_load_idle[idx], 0);
This will actually degrade performance.
The read can have the cacheline in shared mode, while the xchg will
force it into exclusive mode. Also, the xchg atomic operation is a
really expensive instruction.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web