From nobody Wed Jun 14 16:46:44 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 4QhBCT5rK8z4dHpF; Wed, 14 Jun 2023 16:46:45 +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 4QhBCS6Ytjz4Q23; Wed, 14 Jun 2023 16:46:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686761204; 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=Bbumi9FncsGxkrVKaQS/Qnrtdcvotmbz3KCzKuY9a3Y=; b=oKIXZs8SPcVxII5LzPhrmxNMX5VP3MiWxglSzan/JjP1IyHHxf/C7HjIw7uCsZtB8KCRbW 9SPcnaWM/C2blPvvU8bjp+IeHdNtCuGJpPSQ/9jkK9lfX/tYh/DG44fb9p0ozJFO0IpS38 WVSc2FJLvq8Z4gsrJXSPyF2bkZHYqd2RzIulxWfe5/YC14Io8zBvj9LzPsOu8ozZqCNeC/ 21RxWjNZrFBgckt34UtsFqGIJ4bkSVBppl1jGTq+HcZ7AFvoVjqYPYAJs5ssbnhLt0z4h0 mWnE3jAcchPukTHJ5/BZbvhFdiDpb9DSWnk277WrZAOIPjOPkIZqCNF/NHUL3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686761204; 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=Bbumi9FncsGxkrVKaQS/Qnrtdcvotmbz3KCzKuY9a3Y=; b=wuNJMUNPnS4tzL5I05WlEubsJLWwRqGfCiCTzTN/KNw4BfJ6VVxsjmmf7B2sOL/WSO454N ThPzRa6Xj2bky/tZ99nogcc3f8D54y7cvvvlNbbsBZYJj5+a0l5onWx21WcLjtpUVio8Ec MvH/U5ti/mJHh8C93kwD1SMdVnM98rS0WuqWu4c/7Uaqk6XBHfb7ZV4IACE4Bwpass6T0h 8OTZ9Q7PeAcPiwogGidT0K/oECEvkj6XFXaeDBxN4A6qqjvW/SPgr1OKIxgbdMIaBKxn5e 0C2v/Dztor6jLMjUlnxe3Zn+j5UNOw/ULbPiIBJsvWhM+OeHS1z8cOzXXUe+nQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1686761204; a=rsa-sha256; cv=none; b=ez4/YrY1Ou6AsJt8W1RpQu0d3S3islcMgW4yPEWojoCbuQ+vVbnCOmYNrSIXeUcG0/MxhA yB2Z+9fcTjYWvkwBSNQPembzQvGyMqM7j8MQFaknqggI111lW/mQP8g75sDGht+wcRYoOW 4Q8Govg+kapGCVdDZFcG3uHEh/7/rW2EsXJ2r2j1IzhxsNBNLBudsx2pQ3TyOEKTldePxN L02EXVSOof5Ukh6jh29ZyebvQZ8lwdmJ7H6jfNrGcZ/uZLwjn+6j6H3D2fSEIx34T+33vC hYysBw8Vi/8ieZufyZuFMvCqBfcJnnaio3vmGFIUJjVbKLSe5y6XEhLazhOd3g== 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 4QhBCS5gZZz1B2B; Wed, 14 Jun 2023 16:46:44 +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 35EGki7a028477; Wed, 14 Jun 2023 16:46:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35EGkinA028476; Wed, 14 Jun 2023 16:46:44 GMT (envelope-from git) Date: Wed, 14 Jun 2023 16:46:44 GMT Message-Id: <202306141646.35EGkinA028476@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: f4fac946c6a5 - main - hwpmc: split out PMC_OP_PMCRELEASE 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: f4fac946c6a5f682130b16e17bb4d9ffe219ea32 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=f4fac946c6a5f682130b16e17bb4d9ffe219ea32 commit f4fac946c6a5f682130b16e17bb4d9ffe219ea32 Author: Mitchell Horne AuthorDate: 2023-06-14 16:33:35 +0000 Commit: Mitchell Horne CommitDate: 2023-06-14 16:34:21 +0000 hwpmc: split out PMC_OP_PMCRELEASE Split out the functional logic from the syscall handler into a helper function. This keeps it separate from the syscall control-flow logic, resulting in better readability overall. It also wins back a level of indentation. Reviewed by: jkoshy MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D40293 --- sys/dev/hwpmc/hwpmc_mod.c | 66 +++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c index fb6aa3ad4588..f9ea87769cae 100644 --- a/sys/dev/hwpmc/hwpmc_mod.c +++ b/sys/dev/hwpmc/hwpmc_mod.c @@ -3622,6 +3622,40 @@ pmc_do_op_pmcdetach(struct thread *td, struct pmc_op_pmcattach a) return (error); } +/* + * Main body of PMC_OP_PMCRELEASE. + */ +static int +pmc_do_op_pmcrelease(pmc_id_t pmcid) +{ + struct pmc_owner *po; + struct pmc *pm; + int error; + + /* + * Find PMC pointer for the named PMC. + * + * Use pmc_release_pmc_descriptor() to switch off the + * PMC, remove all its target threads, and remove the + * PMC from its owner's list. + * + * Remove the owner record if this is the last PMC + * owned. + * + * Free up space. + */ + error = pmc_find_pmc(pmcid, &pm); + if (error != 0) + return (error); + + po = pm->pm_owner; + pmc_release_pmc_descriptor(pm); + pmc_maybe_remove_owner(po); + pmc_destroy_pmc_descriptor(pm); + + return (error); +} + static int pmc_syscall_handler(struct thread *td, void *syscall_args) { @@ -4205,41 +4239,17 @@ pmc_syscall_handler(struct thread *td, void *syscall_args) break; /* - * Release an allocated PMC + * Release an allocated PMC. */ - case PMC_OP_PMCRELEASE: { - pmc_id_t pmcid; - struct pmc *pm; - struct pmc_owner *po; struct pmc_op_simple sp; - /* - * Find PMC pointer for the named PMC. - * - * Use pmc_release_pmc_descriptor() to switch off the - * PMC, remove all its target threads, and remove the - * PMC from its owner's list. - * - * Remove the owner record if this is the last PMC - * owned. - * - * Free up space. - */ - - if ((error = copyin(arg, &sp, sizeof(sp))) != 0) - break; - - pmcid = sp.pm_pmcid; - - if ((error = pmc_find_pmc(pmcid, &pm)) != 0) + error = copyin(arg, &sp, sizeof(sp)); + if (error != 0) break; - po = pm->pm_owner; - pmc_release_pmc_descriptor(pm); - pmc_maybe_remove_owner(po); - pmc_destroy_pmc_descriptor(pm); + error = pmc_do_op_pmcrelease(sp.pm_pmcid); } break;