From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C857AC433EF for ; Tue, 7 Sep 2021 12:25:30 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 945EB60EE6 for ; Tue, 7 Sep 2021 12:25:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 945EB60EE6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:44386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNaAK-0006qg-Sf for qemu-devel@archiver.kernel.org; Tue, 07 Sep 2021 08:25:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNa5f-0006Jm-5J for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:20:41 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:34370) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNa5c-0006E0-DR for qemu-devel@nongnu.org; Tue, 07 Sep 2021 08:20:38 -0400 Received: by mail-wr1-x42c.google.com with SMTP id m9so14163750wrb.1 for ; Tue, 07 Sep 2021 05:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ianFqsv3asyyHYHf8mIeVNpopGZuWsQ6XYB3o0I70lU=; b=EZt9bp99mC3GEjbw4RinYZBDABKrla+F6SXBNZOtNuPmhpjztASkZmePbIDnzGbfwh D8SNEsM3Ip61oeAmQaF7dG4gYUqTrY85vj8A+ghHDhUPzcVQ+5EhpomyMoYcKzSWREMN f/TdMYTTHH1iNJCRwvfhWSvUvLnxmR/6DTRZfId5yaGvfVt1XJE52aEKo6tcU2LZKNJR u5T8V2Hy8L60K2LRxU4poB4l/SDrL5uJvGIrwNhHzhTkWtgFz7+3DEMQuoMrd0tS0zfW OGRBI8ZdGMek0cmr06rLG/++gF1E5HsGkW0tOD6DH4Pax2058UlCB3q2+CYFei63aqK5 hmCg== 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=ianFqsv3asyyHYHf8mIeVNpopGZuWsQ6XYB3o0I70lU=; b=c2xXJOOR8VmsXZt+SaO3nYijS0RzCMhC0TshTzDcwsQOoWLG++6YPMj+fmef6lamEz CsRz6IUEDiWv8agoDuWb3ftgCwCohUF/jeRHIJU80I7BMIKtl6WHB1dsJj7nZnEXvhzI xg6Bmg+D/FORmd1hHc5WVvu3CSpW8vfmEMpQVhsiJQoAYVXJBHG43KnTcKtefZIwNcTH 5ig9w3/sthzfACG79vuJK3YABB47/lFSXJ2isUiw4ifpM4jH59J6qsuGlB0C1VbskEsI iDQqsoGW4LELb6cfEMnVX1ybTHVgnFKoMc/1ApHJLMFq00nw8+ZE/C+ZKBAlAFaAmL2W BVrg== X-Gm-Message-State: AOAM532wCuNg3uOC1T9OI34K+UAV4EEQYpy3FRzJ0QrBfMDLXzX6ru0Y YJGnD/0kRDDfdHbQZ7b+SXUFeqadAd8poxmiZo6Q7w== X-Google-Smtp-Source: ABdhPJzGpwuSK4TaQwGpVNpP7Mc9R8ndixIMyCeHiTVBPaq0wP8EW8reOAt9vlttiAwGDhN1CMAy7Jto4UYNK7kTx6k= X-Received: by 2002:a5d:4647:: with SMTP id j7mr18676304wrs.149.1631017234578; Tue, 07 Sep 2021 05:20:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Peter Maydell Date: Tue, 7 Sep 2021 13:19:45 +0100 Message-ID: Subject: Re: Application of QEMUTimer in short timing. To: Duo jia Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: QEMU Developers Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Tue, 7 Sept 2021 at 12:28, Duo jia wrote: > > In the controller, QEMUTimer will be used in the implementation of timer simulation. > > I wrote an auto-loading timer with a period of 1ms and the clock source used is QEMU_CLOCK_VIRTUAL. But it doesn't seem to be very accurate, because the actual time after I accumulated it to 500 times took about 700ms. It depends on how you use it. Generally the actual firing will not happen exactly on the specified mark. So if your implementation is "set clock for 1ms in the future; when it fires, set for 1ms in the future again" that is likely to be inaccurate. If you implement it as "set clock for 1ms in the future; when it fires, set for 1ms after the time when it should have fired" it will probably be better. In particular, if the semantics of your timer fit the ptimer API (which can implement oneshot and periodic timers) then I would recommend using that instead of a raw QEMUTimer; it deals with a lot of these fiddly details for you. -- PMM