From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47768) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJFTM-0008NF-MX for qemu-devel@nongnu.org; Sat, 02 Jul 2016 03:36:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bJFTI-00030E-B3 for qemu-devel@nongnu.org; Sat, 02 Jul 2016 03:36:15 -0400 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:33744) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJFTI-0002zr-2V for qemu-devel@nongnu.org; Sat, 02 Jul 2016 03:36:12 -0400 Received: by mail-lf0-x241.google.com with SMTP id l188so13156987lfe.0 for ; Sat, 02 Jul 2016 00:36:11 -0700 (PDT) References: <1464986428-6739-1-git-send-email-alex.bennee@linaro.org> <1464986428-6739-13-git-send-email-alex.bennee@linaro.org> <57719893.9070201@gmail.com> From: Sergey Fedorov Message-ID: <57776EE9.1030706@gmail.com> Date: Sat, 2 Jul 2016 10:36:09 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [RFC v3 12/19] tcg: add kick timer for single-threaded vCPU emulation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson , =?UTF-8?Q?Alex_Benn=c3=a9e?= , mttcg@greensocs.com, qemu-devel@nongnu.org, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, cota@braap.org, bobby.prani@gmail.com Cc: mark.burton@greensocs.com, pbonzini@redhat.com, jan.kiszka@siemens.com, peter.maydell@linaro.org, claudio.fontana@huawei.com, Peter Crosthwaite On 02/07/16 03:17, Richard Henderson wrote: > On 06/27/2016 02:20 PM, Sergey Fedorov wrote: >> On 03/06/16 23:40, Alex Bennée wrote: >>> diff --git a/cpus.c b/cpus.c >>> index 1694ce9..12e04c9 100644 >>> --- a/cpus.c >>> +++ b/cpus.c >>> @@ -1208,9 +1208,29 @@ static int tcg_cpu_exec(CPUState *cpu) >>> return ret; >>> } >>> >>> +/* Single-threaded TCG >>> + * >>> + * In the single-threaded case each vCPU is simulated in turn. If >>> + * there is more than a single vCPU we create a simple timer to kick >>> + * the vCPU and ensure we don't get stuck in a tight loop in one vCPU. >>> + * This is done explicitly rather than relying on side-effects >>> + * elsewhere. >>> + */ >>> +static void qemu_cpu_kick_no_halt(void); >>> +#define TCG_KICK_FREQ (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + \ >>> + NANOSECONDS_PER_SECOND / 10) >> >> Hmm, it doesn't look nice to wrap calculation of the next timeout in a >> macro and name it '*_FREQ'. I think we'd better do like this: >> >> #define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10) >> >> static inline int64_t qemu_tcg_next_kick(void) >> { >> return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + TCG_KICK_PERIOD; >> } >> >> and use it like this: >> >> timer_mod(kick_timer, qemu_tcg_next_kick()); > > Agreed. > > As an aside, surely a period of 10ns is too small. > That's on the order of 20-50 host instructions. I think the period is 10 times in a second which is 100 ms. Regards, Sergey