From: Keir Fraser Subject: Re: [PATCH] x86/hvm/pmtimer: improving scalability of virtual time update on Xen 4.0.0 Date: Wed, 17 Nov 2010 15:43:18 +0000 Message-ID: References: <20101117144745.GG21112@whitby.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20101117144745.GG21112@whitby.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Tim Deegan , Song Xiang Cc: "xen-devel@lists.xensource.com" , Haibo Chen , Jan Beulich List-Id: xen-devel@lists.xenproject.org On 17/11/2010 14:47, "Tim Deegan" wrote: >> /* Update the timer */ >> curr_gtime = hvm_get_guest_time(s->vcpu); >> - s->pm.tmr_val += ((curr_gtime - s->last_gtime) * s->scale) >> 32; >> + *(volatile uint32_t *)&s->pm.tmr_val = s->pm.tmr_val + (((curr_gtime - >> s->last_gtime) * s->scale) >> 32); >> s->pm.tmr_val &= TMR_VAL_MASK; >> s->last_gtime = curr_gtime; > > That doesn't make it an atomic update! The variable is still written > to twice. :) You need to calculate the new tmr_val in a scratch > variable, and then write it back once at the end of the function. > (And no 'volatile' wll be necessary). Can we be sure the compiler will emit only one write to the shared field unless we use volatile? Seems to safer and more explicit to keep it, to me (like atomic_set()). Otherwise compiler could elide the local variable and continue to do the whole composite operation on the shared field? Of course I agree about calculating the value to store in a local variabne and then write the result in one operation. -- Keir