From owner-freebsd-current@freebsd.org Wed Jun 27 17:01:51 2018 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 74BDA102D2EC for ; Wed, 27 Jun 2018 17:01:51 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id DF80186D71; Wed, 27 Jun 2018 17:01:50 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: by mail-lj1-x22e.google.com with SMTP id k20-v6so2205587ljk.9; Wed, 27 Jun 2018 10:01:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oHNwFFksmr+oCYpiEzBRksB0VwxWb3n9mcWn6pUVRs8=; b=MNhwSVpZdHnCwG82WPv0lyRiJmP7qIwUttxYjUuVTquJKFWiPDZMW+yY/jx/4dtpie 9Ab3Uwb15PllsGAUkpP9JjgCIRn0q36fG5S2s2K/kp7S3z3ls0g2zeUd9JijyqRR9GEu WGm5zZuDaMwGQse05YG7+ZLt8pGhAokRWLK7LIjmIYCX5R+EQ71BGG3cSEdhYwHmeVvv a0egpr1xEPH93TGaTMaBxV7XNOk9fwdgQ4sm/v/cGGqW5qHjvtGfk9p7H3twmttR8pZK T8qBr6HgxPg0Asz8TLmD85JtnxlUOSmlS1JYRXWf2CfqJIT35FE31+plDqn/SwDCTpQj qh2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oHNwFFksmr+oCYpiEzBRksB0VwxWb3n9mcWn6pUVRs8=; b=nIF239iQ+oYIUhu39hePsbWkThEKnxIz26kljxa2GizudESV8Usva3u5SVwcYOMlPE kbGcgsqVDNh07kNQ2nLM1qDpR4U/xr8oNfz+D6HbkIR+O2QhJgGQz0yTPfbluJQcQ9C3 E1UJBMTunb7jVeuUNUiwUYoqas3ESoLjY/n4hzsdHusiopzTiBNq6f3pLX+ncHtpM5z2 r4LjZRXcy0folKv9K8XjwBpKYaAcehjJFLybrWHm4DLKd8PV8B078f2V129/JvWPZriq c1ygWOfqmyjFzYSw7J1GkiHQQj1mbXNowthDfd34M71pyCfff/Hh48EcDNmMQxRqyW+x 30OQ== X-Gm-Message-State: APt69E0OQBT1FNX0gIZSKCHidPD4ZGqVdZcDeHjsVm2OIWPPPMIyrgRw Y5oQ7MdgcAVgrfEFwPUzknDBBRqI91yZjCrrJTM= X-Google-Smtp-Source: ADUXVKIEGhAxHpmWDA9iADvyyf7OnNVBzgc8IZlsmr3rEkHnNaJ4McIrCax8PHqYV4F0HmOXc1FYHoJU1IvI7znroxc= X-Received: by 2002:a2e:2d11:: with SMTP id t17-v6mr4574477ljt.145.1530118909322; Wed, 27 Jun 2018 10:01:49 -0700 (PDT) MIME-Version: 1.0 References: <8ac353c5-d188-f432-aab1-86f4ca5fd295@FreeBSD.org> <4d7957f6-9497-19ff-4dbb-436bb6b05a56@FreeBSD.org> In-Reply-To: From: Ryan Stone Date: Wed, 27 Jun 2018 13:01:40 -0400 Message-ID: Subject: Re: TSC calibration in virtual machines To: Alan Somers Cc: jkim@freebsd.org, Andriy Gapon , FreeBSD Current Content-Type: text/plain; charset="UTF-8" X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jun 2018 17:01:51 -0000 I would guess that the calibration can fail because when running under the hypervisor, the FreeBSD guest code can be descheduled at the wrong time. As I recall, the current algorithm looks like: 1. Sample rdtsc 2. Use a fixed-frequency timer to busy-wait for exactly 1 second 3. Sample rdtsc again 4. tsc_freq = sample2 - sample1; If we are descheduled between 2 and 3, the time we spend off-cpu will not be accounted for at step 4. On bare-metal this is not possible as neither the scheduler nor interrupts are not running yet. Although, come to think of it, I seem to recall something about SMI interrupts mucking this up long in the past, for exactly the same reason.