From owner-dev-commits-src-all@freebsd.org Wed Mar 10 18:52:56 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 86D8A5740A7; Wed, 10 Mar 2021 18:52:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Dwh6J3NYgz4WnK; Wed, 10 Mar 2021 18:52:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6709C16838; Wed, 10 Mar 2021 18:52:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 12AIquVl054768; Wed, 10 Mar 2021 18:52:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 12AIquTp054767; Wed, 10 Mar 2021 18:52:56 GMT (envelope-from git) Date: Wed, 10 Mar 2021 18:52:56 GMT Message-Id: <202103101852.12AIquTp054767@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alexander Motin Subject: git: 2cee045b4d62 - main - Move time math out of disabled interrupts sections. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2cee045b4d62568d065b838a6cf129fed2424709 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Mar 2021 18:52:56 -0000 The branch main has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=2cee045b4d62568d065b838a6cf129fed2424709 commit 2cee045b4d62568d065b838a6cf129fed2424709 Author: Alexander Motin AuthorDate: 2021-03-10 18:39:15 +0000 Commit: Alexander Motin CommitDate: 2021-03-10 18:52:51 +0000 Move time math out of disabled interrupts sections. We don't need the result before next sleep time, so no reason to additionally increase interrupt latency. While there, remove extra PM ticks to microseconds conversion, making C2/C3 sleep times look 4 times smaller than really. The conversion is already done by AcpiGetTimerDuration(). Now I see reported sleep times up to 0.5s, just as expected for planned 2 wakeups per second. MFC after: 1 month --- sys/dev/acpica/acpi_cpu.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/sys/dev/acpica/acpi_cpu.c b/sys/dev/acpica/acpi_cpu.c index 56182ed743de..3c81d55436ca 100644 --- a/sys/dev/acpica/acpi_cpu.c +++ b/sys/dev/acpica/acpi_cpu.c @@ -114,8 +114,6 @@ struct acpi_cpu_device { (bus_space_write_ ## width(rman_get_bustag((reg)), \ rman_get_bushandle((reg)), 0, (val))) -#define PM_USEC(x) ((x) >> 2) /* ~4 clocks per usec (3.57955 Mhz) */ - #define ACPI_NOTIFY_CX_STATES 0x81 /* _CST changed. */ #define CPU_QUIRK_NO_C3 (1<<0) /* C3-type states are not usable. */ @@ -1107,7 +1105,7 @@ acpi_cpu_idle(sbintime_t sbt) { struct acpi_cpu_softc *sc; struct acpi_cx *cx_next; - uint64_t cputicks; + uint64_t start_ticks, end_ticks; uint32_t start_time, end_time; ACPI_STATUS status; int bm_active, cx_next_idx, i, us; @@ -1176,7 +1174,7 @@ acpi_cpu_idle(sbintime_t sbt) * we are called inside critical section, delaying context switch. */ if (cx_next->type == ACPI_STATE_C1) { - cputicks = cpu_ticks(); + start_ticks = cpu_ticks(); if (cx_next->p_lvlx != NULL) { /* C1 I/O then Halt */ CPU_GET_REG(cx_next->p_lvlx, 1); @@ -1185,12 +1183,13 @@ acpi_cpu_idle(sbintime_t sbt) acpi_cpu_idle_mwait(cx_next->mwait_hint); else acpi_cpu_c1(); - end_time = ((cpu_ticks() - cputicks) << 20) / cpu_tickrate(); - if (curthread->td_critnest == 0) - end_time = min(end_time, 500000 / hz); + end_ticks = cpu_ticks(); /* acpi_cpu_c1() returns with interrupts enabled. */ if (cx_next->do_mwait) ACPI_ENABLE_IRQS(); + end_time = ((end_ticks - start_ticks) << 20) / cpu_tickrate(); + if (!cx_next->do_mwait && curthread->td_critnest == 0) + end_time = min(end_time, 500000 / hz); sc->cpu_prev_sleep = (sc->cpu_prev_sleep * 3 + end_time) / 4; return; } @@ -1215,10 +1214,10 @@ acpi_cpu_idle(sbintime_t sbt) */ if (cx_next->type == ACPI_STATE_C3) { AcpiGetTimer(&start_time); - cputicks = 0; + start_ticks = 0; } else { start_time = 0; - cputicks = cpu_ticks(); + start_ticks = cpu_ticks(); } if (cx_next->do_mwait) { acpi_cpu_idle_mwait(cx_next->mwait_hint); @@ -1233,11 +1232,10 @@ acpi_cpu_idle(sbintime_t sbt) AcpiGetTimer(&end_time); } - if (cx_next->type == ACPI_STATE_C3) { + if (cx_next->type == ACPI_STATE_C3) AcpiGetTimer(&end_time); - AcpiGetTimerDuration(start_time, end_time, &end_time); - } else - end_time = ((cpu_ticks() - cputicks) << 20) / cpu_tickrate(); + else + end_ticks = cpu_ticks(); /* Enable bus master arbitration and disable bus master wakeup. */ if (cx_next->type == ACPI_STATE_C3 && @@ -1247,7 +1245,11 @@ acpi_cpu_idle(sbintime_t sbt) } ACPI_ENABLE_IRQS(); - sc->cpu_prev_sleep = (sc->cpu_prev_sleep * 3 + PM_USEC(end_time)) / 4; + if (cx_next->type == ACPI_STATE_C3) + AcpiGetTimerDuration(start_time, end_time, &end_time); + else + end_time = ((end_ticks - start_ticks) << 20) / cpu_tickrate(); + sc->cpu_prev_sleep = (sc->cpu_prev_sleep * 3 + end_time) / 4; } #endif