From nobody Thu May 25 17:11:41 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QRvjV1MFhz4WSct; Thu, 25 May 2023 17:11:42 +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 4QRvjV0dV0z3lyM; Thu, 25 May 2023 17:11:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685034702; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+wazijFpNt5NmNfd9DhLIYgRZRTgTOBxrL7/lJhRNfI=; b=g1tLf6Sc88wJsuXVGMEReJzTppyRNJGn57UXTO14JhlRY4EtbRqsovebukCBgPPCJfK+TM lGp8F2jkJBEKKq25aQlcs4NVaCz/R6EUxLmQGMZ2RQQKEKZMrFQ9ttFwth9nzG2U3U4rt9 6glGIKJ0Jgfh2EligGJqbLGV+yJu4/+aBJ/AUJAS443f8SABzPOh9krrv1gYB00q3+c3cS zkVe4LiO88RrVmdgMdU4AdBfbmyp+6lWgBWpKQHFHx5WiRco0XbDu0+IhHOpYgOGJ76hG7 jl2d5TqdAX7KHW6+t1zGAETbMJdH3qCCPYDkWWrOecseRT330CE24idmj09E0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685034702; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+wazijFpNt5NmNfd9DhLIYgRZRTgTOBxrL7/lJhRNfI=; b=YEXMdf0gNHegQG4UKLHD3FiSTYZAHtbgxzXdmbJZMBqrQMG9kj8EVrnEfKQRLUugXQyUU/ LeJCqLEjGcle4ZTr4dDx8KuueRfxCa24io9bGzHYsU9+thbzgWEPw57uJWkpBeEt6yPY+G z6tuahIlBz5Z1f21e9XzrJTBZzK3ZDfvCcyZysEsIuxEK5LrQ+77air3jAIOPd5+eqIn4j aY1vGLdM6QBXCNLZrSs5kV0TVeiocttiKGxJJTvNwerg5qA/FrI5CGSH2sPuaNzOnavSLL osdzWC4YRO93gv3Sf1KuZRwp3owAxwwqxuiroNbb4LmiVPvhDiTRlc9BZZdMBg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685034702; a=rsa-sha256; cv=none; b=gtQMQRTXIk+fByOnIhhPLiDDR2XQqrWY8+heKjy+EeCUMXahoxHvZYJx+EhqdA7UExaUjz BjE/cacpZ5w+omx7hRmkzL99DpchrNdadyL37K/vejc4BlrgTsCD4ZDeDMDIGcGUjhlkdF thC07RY1ht0ix3tVdoN/m+acd/7Py0Zz0/Jwlkhk41geyt2/AiIIYfyipul1yg7F2qnP6U TI86dso3oKCGvMp6Cpl4oxEyv+NqeuFeAjf2LgmCrZSpznpI+FI6tNpNMFM/3n+ev303p1 lDSgDGa3+lH63XIHxRF0LSZl25Djwf7d4l2g28f+/kRViomRoPghezfa1TkosQ== 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 4QRvjT6qrZzYPF; Thu, 25 May 2023 17:11:41 +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 34PHBfS9041687; Thu, 25 May 2023 17:11:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34PHBfTe041686; Thu, 25 May 2023 17:11:41 GMT (envelope-from git) Date: Thu, 25 May 2023 17:11:41 GMT Message-Id: <202305251711.34PHBfTe041686@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: cadaabcc720b - main - riscv timer: use stimecmp CSR when available List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cadaabcc720bb20d6d604c4792acb29072d2882d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=cadaabcc720bb20d6d604c4792acb29072d2882d commit cadaabcc720bb20d6d604c4792acb29072d2882d Author: Mitchell Horne AuthorDate: 2023-05-25 17:07:49 +0000 Commit: Mitchell Horne CommitDate: 2023-05-25 17:07:49 +0000 riscv timer: use stimecmp CSR when available The Sstc extension defines a new stimecmp CSR, allowing supervisor software to set the timer, rather than just read it. When supported, using this avoids the frequent trips through the SBI every time the CPU's timer expires. Reviewed by: jhb MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D40241 --- sys/riscv/riscv/timer.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sys/riscv/riscv/timer.c b/sys/riscv/riscv/timer.c index 8f01ef2a720f..d23d88d2c0ec 100644 --- a/sys/riscv/riscv/timer.c +++ b/sys/riscv/riscv/timer.c @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -84,6 +85,16 @@ get_timecount(void) return (rdtime()); } +static inline void +set_timecmp(uint64_t timecmp) +{ + + if (has_sstc) + csr_write(stimecmp, timecmp); + else + sbi_set_timer(timecmp); +} + static u_int riscv_timer_tc_get_timecount(struct timecounter *tc __unused) { @@ -107,7 +118,7 @@ riscv_timer_et_start(struct eventtimer *et, sbintime_t first, sbintime_t period) if (first != 0) { counts = ((uint32_t)et->et_frequency * first) >> 32; - sbi_set_timer(get_timecount() + counts); + set_timecmp(get_timecount() + counts); csr_set(sie, SIE_STIE); return (0);