Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1420473

Re: Divide-by-zero in post_init_entity_util_avg

From Yuyang Du <yuyang.du@intel.com>
Newsgroups linux.kernel
Subject Re: Divide-by-zero in post_init_entity_util_avg
Date 2016-06-13 08:30 +0200
Message-ID <rJtxM-2sZ-15@gated-at.bofh.it> (permalink)
References <rI48p-4md-3@gated-at.bofh.it> <rI4Br-4w8-7@gated-at.bofh.it> <rI7SG-6NK-23@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, Jun 09, 2016 at 03:07:50PM +0200, Peter Zijlstra wrote:
> Which given the lack of serialization, and the code generated from
> update_cfs_rq_load_avg() is entirely possible.
> 
> 	if (atomic_long_read(&cfs_rq->removed_load_avg)) {
> 		s64 r = atomic_long_xchg(&cfs_rq->removed_load_avg, 0);
> 		sa->load_avg = max_t(long, sa->load_avg - r, 0);
> 		sa->load_sum = max_t(s64, sa->load_sum - r * LOAD_AVG_MAX, 0);
> 		removed_load = 1;
> 	}
> 
> turns into:
> 
> ffffffff81087064:       49 8b 85 98 00 00 00    mov    0x98(%r13),%rax
> ffffffff8108706b:       48 85 c0                test   %rax,%rax
> ffffffff8108706e:       74 40                   je     ffffffff810870b0 <update_blocked_averages+0xc0>
> ffffffff81087070:       4c 89 f8                mov    %r15,%rax
> ffffffff81087073:       49 87 85 98 00 00 00    xchg   %rax,0x98(%r13)
> ffffffff8108707a:       49 29 45 70             sub    %rax,0x70(%r13)
> ffffffff8108707e:       4c 89 f9                mov    %r15,%rcx
> ffffffff81087081:       bb 01 00 00 00          mov    $0x1,%ebx
> ffffffff81087086:       49 83 7d 70 00          cmpq   $0x0,0x70(%r13)
> ffffffff8108708b:       49 0f 49 4d 70          cmovns 0x70(%r13),%rcx
> 
> Which you'll note ends up with sa->load_avg -= r in memory at
> ffffffff8108707a.
 
Surprised. I actually tweaked a little bit on this, but haven't had desirable
generated codes. Any compiler expert can shed some light on it?

> Ludicrous code generation if you ask me; I'd have expected something
> like (note, r15 holds 0):
> 
> 	mov	%r15, %rax
> 	xchg	%rax, cfs_rq->removed_load_avg
> 	mov	sa->load_avg, %rcx
> 	sub	%rax, %rcx
> 	cmovs	%r15, %rcx
> 	mov	%rcx, sa->load_avg
> 
> Adding the serialization (to _both_ call sites) should fix this.
 
Absolutely, both :)

I am going to remove the group entity post util initialization soon in the
flat hierarchical util implementation, it is not used anywhere.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Divide-by-zero in post_init_entity_util_avg Chris Wilson <chris@chris-wilson.co.uk> - 2016-06-09 11:10 +0200
  Re: Divide-by-zero in post_init_entity_util_avg Yuyang Du <yuyang.du@intel.com> - 2016-06-09 11:40 +0200
    Re: Divide-by-zero in post_init_entity_util_avg Peter Zijlstra <peterz@infradead.org> - 2016-06-09 15:10 +0200
      Re: Divide-by-zero in post_init_entity_util_avg Yuyang Du <yuyang.du@intel.com> - 2016-06-13 08:30 +0200
      [tip:sched/core] sched/fair: Fix post_init_entity_util_avg()  serialization tip-bot for Peter Zijlstra <tipbot@zytor.com> - 2016-06-14 13:30 +0200
      Re: Divide-by-zero in post_init_entity_util_avg Peter Zijlstra <peterz@infradead.org> - 2016-06-16 11:00 +0200
        Re: Divide-by-zero in post_init_entity_util_avg Peter Zijlstra <peterz@infradead.org> - 2016-06-16 14:30 +0200
          Re: Divide-by-zero in post_init_entity_util_avg Peter Zijlstra <peterz@infradead.org> - 2016-06-16 18:20 +0200
          Re: Divide-by-zero in post_init_entity_util_avg Peter Zijlstra <peterz@infradead.org> - 2016-06-17 10:30 +0200
          [PATCH] sched/fair: Fix cfs_rq avg tracking underflow Peter Zijlstra <peterz@infradead.org> - 2016-06-17 11:30 +0200
            Re: [PATCH] sched/fair: Fix cfs_rq avg tracking underflow Yuyang Du <yuyang.du@intel.com> - 2016-06-17 12:00 +0200
            [tip:sched/urgent] sched/fair: Fix cfs_rq avg tracking underflow tip-bot for Peter Zijlstra <tipbot@zytor.com> - 2016-06-20 15:30 +0200
  Re: Divide-by-zero in post_init_entity_util_avg Peter Zijlstra <peterz@infradead.org> - 2016-06-09 12:40 +0200

csiph-web