From patchwork Tue Jun 16 07:51:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 280407 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=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 E367DC433E0 for ; Tue, 16 Jun 2020 07:54:24 +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 ADBAF2074D for ; Tue, 16 Jun 2020 07:54:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NU6xdCpJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ADBAF2074D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jl6QJ-0000PM-V0 for qemu-devel@archiver.kernel.org; Tue, 16 Jun 2020 03:54:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jl6NV-0003eA-6z; Tue, 16 Jun 2020 03:51:29 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:34407) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jl6NT-00084A-Jj; Tue, 16 Jun 2020 03:51:28 -0400 Received: by mail-wr1-x443.google.com with SMTP id r7so19697962wro.1; Tue, 16 Jun 2020 00:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u02Arpcubj9mPZ8wYNHVoADOr5FJrLRUYb2irB7o4Ig=; b=NU6xdCpJWWMjotGt3hh8qLQaEU6IcuR807+1T9o24PWWNqD9Vogza4t5sE/67Lc+Ul RGfzxZSZE3DbR+GqQrdbaiR5Itv2TJ5BXlyrssUbjIyUavUjrD2sL32ipexO5Un6L8HN jChBwkWzR2d4Cahzr2jOrEAHMxxk3Nvvv00VClpD+StLtJp282jata4OgZXBnCyzhuHJ fiQtd6K4ljhhVoDkTZI+jjJkNZjozK9Q5hQMOo0FuF7f02NHidx60lb9OLa8Hq+rbBND c/5y0//UT6HrihapbCL3sNis3PVVmmf4Y/hXtSZpzXycZPTqZWz43ZOq67pcJlu4blwI cTEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=u02Arpcubj9mPZ8wYNHVoADOr5FJrLRUYb2irB7o4Ig=; b=sB9i9cEqcfUFeFbX9TDjMgB1Y/1w+PyCoubmqdEbvZXndPVIHJof2MtTyIujEucH2O 3tCGslzDLeAJDGv/bLqh5I5KWFvJtq+eVE2gT+bS8SCKK535pXBnjnt4h9D2iqJJ7bfL r+T9qNCNLXR0X99sj3Hm9saUU0UCMat+LJvQXoVclGWYhwgOTsY2Tu2X6HyAUIaV916W zj6hkcCzTUC7X5MlTllv5MgvquBTOb47pIZ6KN12ASOhoCAiCWVWe2TYWKIoY+/yR9v7 dR0HzCujmJnyLntEnvtF0t1SGlcYiYjtS7QRdaxoSKj90GPcNSPdiFhtdz+7YSlzQ9T0 WM/w== X-Gm-Message-State: AOAM530HZnPY6nW8AXq/VGctOoOsdsFWEYsoLFQKkqOONIAOMtpAt6n+ UA6rMSmt/e1N8BZ+8EnIONFRR7NQ X-Google-Smtp-Source: ABdhPJyvI98LxdXs/QaF0wr5dlrQ7y8cygnVOjolGcediY1CUVmrWxnbvLxbeYibXrGIgZMBGQIhoQ== X-Received: by 2002:a5d:4f09:: with SMTP id c9mr1617618wru.3.1592293885188; Tue, 16 Jun 2020 00:51:25 -0700 (PDT) Received: from localhost.localdomain (181.red-88-10-103.dynamicip.rima-tde.net. [88.10.103.181]) by smtp.gmail.com with ESMTPSA id q11sm28093538wrv.67.2020.06.16.00.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 00:51:24 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 1/7] qemu-common: Briefly document qemu_timedate_diff() unit Date: Tue, 16 Jun 2020 09:51:15 +0200 Message-Id: <20200616075121.12837-2-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200616075121.12837-1-f4bug@amsat.org> References: <20200616075121.12837-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::443; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x443.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, Corey Minyard , David Hildenbrand , Andrew Jeffery , "Michael S. Tsirkin" , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?b?ZMOp?= , Max Reitz , qemu-arm@nongnu.org, Joel Stanley , Paolo Bonzini , =?utf-8?b?Q8Op?= =?utf-8?q?dric_Le_Goater?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" It is not obvious that the qemu_timedate_diff() and qemu_ref_timedate() functions return seconds. Briefly document it. Signed-off-by: Philippe Mathieu-Daudé --- include/qemu-common.h | 1 + softmmu/vl.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/qemu-common.h b/include/qemu-common.h index d0142f29ac..e97644710c 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -27,6 +27,7 @@ int qemu_main(int argc, char **argv, char **envp); #endif void qemu_get_timedate(struct tm *tm, int offset); +/* Returns difference with RTC reference time (in seconds) */ int qemu_timedate_diff(struct tm *tm); void *qemu_oom_check(void *ptr); diff --git a/softmmu/vl.c b/softmmu/vl.c index f669c06ede..215459c7b5 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -737,7 +737,7 @@ void qemu_system_vmstop_request(RunState state) } /***********************************************************/ -/* RTC reference time/date access */ +/* RTC reference time/date access (in seconds) */ static time_t qemu_ref_timedate(QEMUClockType clock) { time_t value = qemu_clock_get_ms(clock) / 1000; From patchwork Tue Jun 16 07:51:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 280408 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=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham 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 CD955C433DF for ; Tue, 16 Jun 2020 07:53:10 +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 95AD2206D7 for ; Tue, 16 Jun 2020 07:53:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LgKlPInv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 95AD2206D7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jl6P7-000655-OI for qemu-devel@archiver.kernel.org; Tue, 16 Jun 2020 03:53:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jl6NX-0003gL-Q2; Tue, 16 Jun 2020 03:51:31 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:34409) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jl6NV-00084a-UO; Tue, 16 Jun 2020 03:51:31 -0400 Received: by mail-wr1-x444.google.com with SMTP id r7so19698101wro.1; Tue, 16 Jun 2020 00:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/VMXSScmCR3d2/xkIxPp+LwxksxY5VIsQUSqaq3gT2w=; b=LgKlPInvpyWcJQMbinEVBrhvjBxSLgik0kvjvBXJ5vLSHydazZm1npSvulmJf7g3ZH vcT06mhNwvaHJYzKexKhtPj3X1uBs26KJr/3g/Uo9f4JAi0yOjI+ggFED/eI0EIkz+dj ACegk5qJrKPDUdyxK64vooWuXSaDufmJHKuzwy3GSVwlFGKsCgB82NKF81X9s2w+15Mq 4uJi2mzFI39tn702h5DYgZzIzDyIGI0h9DGV5uY1upX3G5mvZnz3sMexLNHh8qpoVE8J Wg6RLX76p2BP+SM4tkB06dBfc17szJClCmIftRXo4LcH9vhs4Oj86BpiP4C0Uz7dgKN9 oKEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=/VMXSScmCR3d2/xkIxPp+LwxksxY5VIsQUSqaq3gT2w=; b=AsxLDro4zZAdu4jTRPOhclVAfS/ggw/T1El3HPDjqbreIUALnFy4jX4YvSnkVlJZvE 8YNzH4LfkcO8ID5uZ1LcSctnPgucgYshXhqpONdbypwS9CeUwJ3oWa3NmZJenR46sH2D QAWv5OADI76hHcC4F3zd2iD7m7GvuLGb1TuNisUaed6N9ukp91zNDqZFNSop1HcUiVda ypb8iOSusEFcvzdEjnRmq/0qCJvRMYyM+LgaJ2dVPU8XtuS9t7U6Ya9IY1AoHiuW4ZHK 9J3La/aJXqg6Xie8umBw6kiOfG5UhukeamcM1nkduIeTPmzaS4LqotFOypqcTxJgECKf gv2A== X-Gm-Message-State: AOAM533O70R29T0x8VwW+cP1z8Ul5LO5kZLcPQNBsAP5fZ5l6gyKB3JV Ss+QvJe5qqzQlbZ/Yhn2L3mdOR5z X-Google-Smtp-Source: ABdhPJw1CEDYD8VhkYNnlo/tDBeikFnfie1kFgHNOTqW2vK5wDAq1ur41dKnqMxnQXpjcMNkv+hOSw== X-Received: by 2002:adf:f0d2:: with SMTP id x18mr1633039wro.250.1592293887799; Tue, 16 Jun 2020 00:51:27 -0700 (PDT) Received: from localhost.localdomain (181.red-88-10-103.dynamicip.rima-tde.net. [88.10.103.181]) by smtp.gmail.com with ESMTPSA id q11sm28093538wrv.67.2020.06.16.00.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 00:51:27 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 3/7] block/curl: Reduce timer precision to milli-second Date: Tue, 16 Jun 2020 09:51:17 +0200 Message-Id: <20200616075121.12837-4-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200616075121.12837-1-f4bug@amsat.org> References: <20200616075121.12837-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::444; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, Corey Minyard , David Hildenbrand , Andrew Jeffery , "Michael S. Tsirkin" , Mark Cave-Ayland , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , Max Reitz , qemu-arm@nongnu.org, Joel Stanley , Paolo Bonzini , =?utf-8?b?Q8Op?= =?utf-8?q?dric_Le_Goater?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The current implementation uses nano-second precision, while the block driver is only used with a milli-second precision. Simplify by using a milli-second based timer. Rename the timer 'timer_ms' to have the unit explicit. Inspired-by: Mark Cave-Ayland Signed-off-by: Philippe Mathieu-Daudé --- block/curl.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/block/curl.c b/block/curl.c index 6e325901dc..74950373aa 100644 --- a/block/curl.c +++ b/block/curl.c @@ -119,7 +119,7 @@ typedef struct CURLState typedef struct BDRVCURLState { CURLM *multi; - QEMUTimer timer; + QEMUTimer timer_ms; uint64_t len; CURLState states[CURL_NUM_STATES]; char *url; @@ -148,11 +148,10 @@ static int curl_timer_cb(CURLM *multi, long timeout_ms, void *opaque) trace_curl_timer_cb(timeout_ms); if (timeout_ms == -1) { - timer_del(&s->timer); + timer_del(&s->timer_ms); } else { - int64_t timeout_ns = (int64_t)timeout_ms * 1000 * 1000; - timer_mod(&s->timer, - qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + timeout_ns); + timer_mod(&s->timer_ms, + qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + timeout_ms); } return 0; } @@ -582,7 +581,7 @@ static void curl_detach_aio_context(BlockDriverState *bs) } qemu_mutex_unlock(&s->mutex); - timer_del(&s->timer); + timer_del(&s->timer_ms); } static void curl_attach_aio_context(BlockDriverState *bs, @@ -590,8 +589,8 @@ static void curl_attach_aio_context(BlockDriverState *bs, { BDRVCURLState *s = bs->opaque; - aio_timer_init(new_context, &s->timer, - QEMU_CLOCK_REALTIME, SCALE_NS, + aio_timer_init(new_context, &s->timer_ms, + QEMU_CLOCK_REALTIME, SCALE_MS, curl_multi_timeout_do, s); assert(!s->multi); From patchwork Tue Jun 16 07:51:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 280406 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=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham 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 B2D3EC433E2 for ; Tue, 16 Jun 2020 07:56:01 +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 7C8A82078E for ; Tue, 16 Jun 2020 07:56:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hlDQE2Y+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C8A82078E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jl6Rs-0002ca-Iy for qemu-devel@archiver.kernel.org; Tue, 16 Jun 2020 03:56:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jl6Na-0003oP-R0; Tue, 16 Jun 2020 03:51:34 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:42173) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jl6NY-000854-Sy; Tue, 16 Jun 2020 03:51:34 -0400 Received: by mail-wr1-x441.google.com with SMTP id p5so19645032wrw.9; Tue, 16 Jun 2020 00:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jNTvdD7mpsXZtfy12szHXck2/SJaUPu7sRItCYEvWmI=; b=hlDQE2Y+qIt5bfkxo5d9ivmg+RnCdrgZik2djnVqg9fzhIrguwMe2kvyLMnFNkvBF0 fOj9yLWI3qWupCP8+4J6HdrmB6U6CcDV1+n2BP/RiO0JrA8cEh552ypE9Nl/rz/qBoJo XmMkyuNRVWUAXwAxiyexhm2kPcCDhHZRCgO2JIgEgAg1KK1jUXpeyDspzmSsRWgDMniV 8me6Zg+qkEGe1jKLfX86KnAffrKijmKYaClzj9NU4zsNReHvGBxeK+9M6DWvVHkvrhC4 XljtSuY3fqb+52RxtIOd4Piyrfumm5zdTR16RpUQkyKxrDE3P4RWFlvKvfQoRZZZOxRZ hJlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=jNTvdD7mpsXZtfy12szHXck2/SJaUPu7sRItCYEvWmI=; b=lTxB+SjuF4UXWO/+qgx795nv54TIckOQiWi4PlHjbBEaoG9P+lGR86UcNhPhGsmi87 mBlzw1jO0LK9pqD7xiGQr97LlWxOvV8STF+sYQ1tkiJsjUtgu9prfVmE6qvG1GbzuCMU E4WsVqKXy9WmHFnGIDGfV733Shi9/Iho/gvyi3yx47nH1iPVyZTG8oCyikzMy/yqOXS7 mjaDFwpSFhjI8a6ooEcV/kDWXlLuubM0ABL44RUyoCjn5CPGnnpAqkmJ7idNQ/Vr/zcB 5g11RXR27WZr7FFLdAaJgnqubU4jY+LohMvUbbVM91vpT5FhfiIhyrjHCQ+mzFLASyad F7Ow== X-Gm-Message-State: AOAM5311VsAP1M7QtKc7tb8DjGov3OBakQKh3nVqAB4o5q0syBYMWUGa LuRp9VvfySRtLSkWrHr88rFVom4g X-Google-Smtp-Source: ABdhPJw+EFEn77nFC6P8FC/flCFkku6pfG6x4QObNoCxtmxUNdNMglqucXXL/xjsW6biX12wvEnnzA== X-Received: by 2002:a5d:45c2:: with SMTP id b2mr1541194wrs.323.1592293890541; Tue, 16 Jun 2020 00:51:30 -0700 (PDT) Received: from localhost.localdomain (181.red-88-10-103.dynamicip.rima-tde.net. [88.10.103.181]) by smtp.gmail.com with ESMTPSA id q11sm28093538wrv.67.2020.06.16.00.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 00:51:29 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 5/7] hw/rtc/m48t59: Reduce timer precision to milli-second Date: Tue, 16 Jun 2020 09:51:19 +0200 Message-Id: <20200616075121.12837-6-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200616075121.12837-1-f4bug@amsat.org> References: <20200616075121.12837-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, Corey Minyard , David Hildenbrand , Andrew Jeffery , "Michael S. Tsirkin" , Mark Cave-Ayland , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , Max Reitz , qemu-arm@nongnu.org, Joel Stanley , Paolo Bonzini , =?utf-8?b?Q8Op?= =?utf-8?q?dric_Le_Goater?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The current implementation uses nano-second precision, while the RTC can not be more precise than a milli-second. Simplify by using a milli-second based timer. Rename the timer 'alrm_timer_ms' to have the unit explicit. Inspired-by: Mark Cave-Ayland Signed-off-by: Philippe Mathieu-Daudé --- hw/rtc/m48t59-internal.h | 2 +- hw/rtc/m48t59.c | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/hw/rtc/m48t59-internal.h b/hw/rtc/m48t59-internal.h index cd648241e9..f21b603f97 100644 --- a/hw/rtc/m48t59-internal.h +++ b/hw/rtc/m48t59-internal.h @@ -49,7 +49,7 @@ typedef struct M48t59State { time_t stop_time; /* Alarm & watchdog */ struct tm alarm; - QEMUTimer *alrm_timer; + QEMUTimer *alrm_timer_ms; QEMUTimer *wd_timer; /* NVRAM storage */ uint8_t *buffer; diff --git a/hw/rtc/m48t59.c b/hw/rtc/m48t59.c index 47d48054fd..d2717d00a9 100644 --- a/hw/rtc/m48t59.c +++ b/hw/rtc/m48t59.c @@ -89,7 +89,7 @@ static M48txxInfo m48txx_sysbus_info[] = { static void alarm_cb (void *opaque) { struct tm tm; - uint64_t next_time; + uint64_t next_time_s; M48t59State *NVRAM = opaque; qemu_set_irq(NVRAM->IRQ, 1); @@ -104,42 +104,43 @@ static void alarm_cb (void *opaque) tm.tm_mon = 1; tm.tm_year++; } - next_time = qemu_timedate_diff(&tm) - NVRAM->time_offset; + next_time_s = qemu_timedate_diff(&tm) - NVRAM->time_offset; } else if ((NVRAM->buffer[0x1FF5] & 0x80) != 0 && (NVRAM->buffer[0x1FF4] & 0x80) == 0 && (NVRAM->buffer[0x1FF3] & 0x80) == 0 && (NVRAM->buffer[0x1FF2] & 0x80) == 0) { /* Repeat once a day */ - next_time = 24 * 60 * 60; + next_time_s = 24 * 60 * 60; } else if ((NVRAM->buffer[0x1FF5] & 0x80) != 0 && (NVRAM->buffer[0x1FF4] & 0x80) != 0 && (NVRAM->buffer[0x1FF3] & 0x80) == 0 && (NVRAM->buffer[0x1FF2] & 0x80) == 0) { /* Repeat once an hour */ - next_time = 60 * 60; + next_time_s = 60 * 60; } else if ((NVRAM->buffer[0x1FF5] & 0x80) != 0 && (NVRAM->buffer[0x1FF4] & 0x80) != 0 && (NVRAM->buffer[0x1FF3] & 0x80) != 0 && (NVRAM->buffer[0x1FF2] & 0x80) == 0) { /* Repeat once a minute */ - next_time = 60; + next_time_s = 60; } else { /* Repeat once a second */ - next_time = 1; + next_time_s = 1; } - timer_mod(NVRAM->alrm_timer, qemu_clock_get_ns(rtc_clock) + - next_time * 1000); + timer_mod(NVRAM->alrm_timer_ms, + qemu_clock_get_ms(rtc_clock) + next_time_s * + NANOSECONDS_PER_SECOND / SCALE_MS); qemu_set_irq(NVRAM->IRQ, 0); } static void set_alarm(M48t59State *NVRAM) { int diff; - if (NVRAM->alrm_timer != NULL) { - timer_del(NVRAM->alrm_timer); + if (NVRAM->alrm_timer_ms != NULL) { + timer_del(NVRAM->alrm_timer_ms); diff = qemu_timedate_diff(&NVRAM->alarm) - NVRAM->time_offset; if (diff > 0) - timer_mod(NVRAM->alrm_timer, diff * 1000); + timer_mod(NVRAM->alrm_timer_ms, diff * 1000); } } @@ -539,9 +540,9 @@ void m48t59_reset_common(M48t59State *NVRAM) { NVRAM->addr = 0; NVRAM->lock = 0; - if (NVRAM->alrm_timer != NULL) - timer_del(NVRAM->alrm_timer); - + if (NVRAM->alrm_timer_ms != NULL) { + timer_del(NVRAM->alrm_timer_ms); + } if (NVRAM->wd_timer != NULL) timer_del(NVRAM->wd_timer); } @@ -603,7 +604,7 @@ void m48t59_realize_common(M48t59State *s, Error **errp) { s->buffer = g_malloc0(s->size); if (s->model == 59) { - s->alrm_timer = timer_new_ns(rtc_clock, &alarm_cb, s); + s->alrm_timer_ms = timer_new_ms(rtc_clock, &alarm_cb, s); s->wd_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, &watchdog_cb, s); } qemu_get_timedate(&s->alarm, 0);