From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52965) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2Gb7-00076F-SL for qemu-devel@nongnu.org; Fri, 27 Nov 2015 05:49:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a2Gb3-0000dC-Oi for qemu-devel@nongnu.org; Fri, 27 Nov 2015 05:49:49 -0500 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:38173) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2Gb3-0000d6-In for qemu-devel@nongnu.org; Fri, 27 Nov 2015 05:49:45 -0500 Received: by wmec201 with SMTP id c201so53343997wme.1 for ; Fri, 27 Nov 2015 02:49:45 -0800 (PST) Sender: Paolo Bonzini References: <1448464821-8199-1-git-send-email-asmetanin@virtuozzo.com> <1448464821-8199-8-git-send-email-asmetanin@virtuozzo.com> <20151127081244.GC2808@rkaganb.sw.ru> From: Paolo Bonzini Message-ID: <56583544.3040600@redhat.com> Date: Fri, 27 Nov 2015 11:49:40 +0100 MIME-Version: 1.0 In-Reply-To: <20151127081244.GC2808@rkaganb.sw.ru> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v1 7/7] kvm/x86: Hyper-V SynIC timers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Roman Kagan , Andrey Smetanin , kvm@vger.kernel.org, Gleb Natapov , "K. Y. Srinivasan" , Haiyang Zhang , Vitaly Kuznetsov , "Denis V. Lunev" , qemu-devel@nongnu.org On 27/11/2015 09:12, Roman Kagan wrote: >> > + n = div64_u64(time_now - stimer->exp_time, stimer->count) + 1; >> > + stimer->exp_time += n * stimer->count; > This is actually just a reminder calculation so I'd rather do it > directly with div64_u64_rem(). It took me a while to understand why it was a remained. :) Expanding Andrey's formula you get exp_time = exp_time + count + (time_now - exp_time) / count * count the remainder, (time_now - exp_time) % count would be time_now - exp_time - (time_now - exp_time) / count * count so -((time_now - exp_time) % count) is exp_time - time_now + (time_now - exp_time) / count * count so Andrey's expression is exp_time = time_now + (count - (time_now - exp_time) % count) Yeah, that looks nice. Paolo