From nobody Mon Feb 06 19:28:09 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 4P9brp0Mdmz3n5WS; Mon, 6 Feb 2023 19:28:10 +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 4P9brn6hSpz3m0d; Mon, 6 Feb 2023 19:28:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675711689; 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=Iv3FWhrL7d7uPJH9iymyEBuYp2EKgx2bud2yWmQBwXo=; b=GUB3LzgoWqhOljFtGesdQVXQ3j02Hjc7lumgSoxBsphJmY/qG2cPYEtxWs7Gbjqw55RrXz EOGUgQQaCPwuGISz4nhsqj5u9fsCkKJ0dEj3XWUTTE3/FwJoHkgtvWR+tVJozMFY3G537J n8uFBF0yu6WmaOoMzsE5lyYMnpy8fdcUGRpDvt+DAAL6kts3ynBqprsviBBYkYmlAeJeoR 52A5N/CtMCAq5g1f0cx8tISEqMKMmP0iVJg476xTSL/p8YK326fbIAcVH3zNTrAvFh4PJp g5FpPpmLq3Xxve9wfqzRglDsq54bWgGSerBDcZMdt8dhUf2T+2Ed52xEAdAM/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675711689; 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=Iv3FWhrL7d7uPJH9iymyEBuYp2EKgx2bud2yWmQBwXo=; b=Cl2a8OzEG/bo7bf11UKWAlJzDQSue56FjAJozPGLyBW2n/DOO/wiTaFtHulCyeTdAO1/P5 SmhBOBbLT2wZhEJYxPZMvpxDxI8wDwJxtyrisXVDVPfc7kQdbkpZ567MyQ0VhN7vXJceXi Z0uecRGAV3S5HSjnKeaWbPCQ2Cw/2Up+qYlY5Gcskgvfi+a4jGoWcB8q6hJzb5IHvGpxsx +f75WBjKd1UWT/EzmyxjwxmBPu5N+8f9BApxeaHH6Mcfqhtac3XfnJF6JvF07++E623srB R3KaKMwPLVS6VlRCe9cU3tmeJOXAokSeYacOxzvxgheJbayRwNrUJhIZv0jtfQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675711689; a=rsa-sha256; cv=none; b=nrNvc31NkvachH14UdA6uKG3xWbKIidRqWWwrDe4P1BOd8XyJIK4CAmdSiM0zSB8Az7xAD f0lC+Y88QROOhjyFhultiMYy8+bxJ25YuKORLgDx3Nkme6qD3pkgw5N7evJ0vRbLvCjsEe eau0EDlq+KXJPZTBhX9uZsGIrsF5n+JPxDPD8yaLPwXOkC2Tnqve7luzGdUOvU1CtOSoJG VW7B6bjELMsY4hbraglcyb0YP2JywY9Y/apXNJ1cbVO88LLQeTENLdKXtxfzEsXSmtDRhL 0FiRDFHjpP3MT1WnxMnJmCyav9dZtn6UBADw4uhFXexTURPbnjejoiAnvTTPqw== 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 4P9brn5gwpzmt3; Mon, 6 Feb 2023 19:28:09 +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 316JS9rK006493; Mon, 6 Feb 2023 19:28:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 316JS9dT006492; Mon, 6 Feb 2023 19:28:09 GMT (envelope-from git) Date: Mon, 6 Feb 2023 19:28:09 GMT Message-Id: <202302061928.316JS9dT006492@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: c6943b44f7d7 - main - dtrace: implement riscv dtrace_getustackdepth() 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: c6943b44f7d73176acd2e36e0615e1b2ded02c0a Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=c6943b44f7d73176acd2e36e0615e1b2ded02c0a commit c6943b44f7d73176acd2e36e0615e1b2ded02c0a Author: Mitchell Horne AuthorDate: 2023-02-06 18:23:42 +0000 Commit: Mitchell Horne CommitDate: 2023-02-06 19:26:53 +0000 dtrace: implement riscv dtrace_getustackdepth() Pretty trivial following other implementations. The existing dtrace_getustack_common() does most of the work. Reviewed by: markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D38303 --- sys/cddl/dev/dtrace/riscv/dtrace_isa.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/sys/cddl/dev/dtrace/riscv/dtrace_isa.c b/sys/cddl/dev/dtrace/riscv/dtrace_isa.c index 6d44a0cee9ee..6e6459a8ce74 100644 --- a/sys/cddl/dev/dtrace/riscv/dtrace_isa.c +++ b/sys/cddl/dev/dtrace/riscv/dtrace_isa.c @@ -169,7 +169,7 @@ dtrace_getupcstack(uint64_t *pcstack, int pcstack_limit) { volatile uint16_t *flags; struct trapframe *tf; - uintptr_t pc, sp, fp; + uintptr_t pc, fp; proc_t *p; int n; @@ -195,7 +195,6 @@ dtrace_getupcstack(uint64_t *pcstack, int pcstack_limit) return; pc = tf->tf_sepc; - sp = tf->tf_sp; fp = tf->tf_s[0]; if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) { @@ -207,7 +206,6 @@ dtrace_getupcstack(uint64_t *pcstack, int pcstack_limit) * at the current stack pointer address since the call * instruction puts it there right before the branch. */ - *pcstack++ = (uint64_t)pc; pcstack_limit--; if (pcstack_limit <= 0) @@ -231,8 +229,33 @@ zero: int dtrace_getustackdepth(void) { + struct trapframe *tf; + uintptr_t pc, fp; + int n = 0; - printf("IMPLEMENT ME: %s\n", __func__); + if (curproc == NULL || (tf = curthread->td_frame) == NULL) + return (0); + + if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_FAULT)) + return (-1); + + pc = tf->tf_sepc; + fp = tf->tf_s[0]; + + if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) { + /* + * In an entry probe. The frame pointer has not yet been + * pushed (that happens in the function prologue). The + * best approach is to add the current pc as a missing top + * of stack and back the pc up to the caller, which is stored + * at the current stack pointer address since the call + * instruction puts it there right before the branch. + */ + pc = tf->tf_ra; + n++; + } + + n += dtrace_getustack_common(NULL, 0, pc, fp); return (0); }