From nobody Fri Mar 11 19:29:59 2022 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 9CDA31A16E2B; Fri, 11 Mar 2022 19:29:59 +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 4KFbc73hBZz3G0D; Fri, 11 Mar 2022 19:29:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647026999; 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=35ZXt/b8LChaPBtS6L4jh0N/ONOweSWJOl1x7WPVHuA=; b=FVioosJ9MIsYk6jIHdgU1k4j2S6GzEFBg0wrQZVjKgVIuyTL+yeH7K8B+mXYbPYoGJ4/HP RWLxPuNwGdc20smuXa3+pE/KwyF32HtPL0EfQKMAdnTv8cYMr2aeFxQHd/RVz8l9qL7bX9 gWAYXxqmcC1g8/3wYZ4giFip3Awv5QRSnnYk9FSgK/otwgY5p55CpHh2iNJVYVUmqUznUN nIIbKeiVuiK5v/FHnztccgt+jsIRRu/D+J/csf2/ao5StNg1Cj6DAnYTbY3FfZRKMp7RUx ho5E8kOlntNb0tLKyM4JWCaQnavQXcTq1WXk967Z9a+GKeQgMisSJwhLTAZD9g== 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 5F6AD1EDFB; Fri, 11 Mar 2022 19:29:59 +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 22BJTxpu014890; Fri, 11 Mar 2022 19:29:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22BJTxDe014889; Fri, 11 Mar 2022 19:29:59 GMT (envelope-from git) Date: Fri, 11 Mar 2022 19:29:59 GMT Message-Id: <202203111929.22BJTxDe014889@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 6bb7ba4aa180 - main - arm64 hwpmc: Support restricting counters to user or kernel mode. 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6bb7ba4aa180f667c1b558de1fc364f41bab57ce Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647026999; 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=35ZXt/b8LChaPBtS6L4jh0N/ONOweSWJOl1x7WPVHuA=; b=dEz7Amh2D5HZUxRa82Rk9yeqAbdHhFtEBonGRu2eiTh8rMZaSYzgc7N1HCwv0AdVQhqfXb pXKAbFVoDcA0JAXa1+JHQx8BTtDbHAPZmpHQfEPcYw+9GZBjoIFmG+4nCNzOsGdQXKwu1C BPPqZYKfm/gcyj2i6/XEJ9syfBhweRZuPsJCzeefX47/zqpITtugn4YAbC8EleQzLb4X9y rFa+rcoQcsOZaPHEVLq6d4B/pdjrhJA+mx/yyv8UcDolIXKPhu30DU/oTITBIbzeiRs9W8 gcaLJDnzuaUaAfrVd8QX2hb+8K4xzi0TRhzGLtEWRJJdVchwkCLKJwnjLRcJ/w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1647026999; a=rsa-sha256; cv=none; b=tmz2j28SKSyHXwo3MzuKUuL1sWvWD0FOpUXIgM5hG70ksnJbiVtHqxA5jyvilCMYBR4c0e 5BtOrY1CKz8loXMVlgF2nCZDAHzNFouc7fXUgo1zTVKHG+UNW3kshsK2WdEHcGDa4PmuN3 o7OHrZPG4iYB1RLzvatsyYbY8Aqvug4E5Yke2O2BwcJEiCTpBxt6V2VRfWGfgrckcy8bOk CPxEZHMOwmmI8Ksf8rAaU0Ty1XiZicTqe+H2XcjNt5L8azmIhHZgdF7oLbsP1iiVlJlb9n wfg744YdCJQ+O1iQZeI4+PQ23WOZZFgmNlmUetE2VGGH3v6sqd+3U9vNfxxAVQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=6bb7ba4aa180f667c1b558de1fc364f41bab57ce commit 6bb7ba4aa180f667c1b558de1fc364f41bab57ce Author: John Baldwin AuthorDate: 2022-03-11 19:29:45 +0000 Commit: John Baldwin CommitDate: 2022-03-11 19:29:45 +0000 arm64 hwpmc: Support restricting counters to user or kernel mode. Support the "usr" and "os" qualifiers on arm64 events to restrict event counting to either usermode or the kernel, respectively. If neither qualifier is given, events are counted in both. Reviewed by: emaste Sponsored by: University of Cambridge, Google, Inc. Differential Revision: https://reviews.freebsd.org/D34527 --- lib/libpmc/libpmc.c | 17 ++++++++++++----- sys/dev/hwpmc/hwpmc_arm64.c | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/libpmc/libpmc.c b/lib/libpmc/libpmc.c index ea0539d2225a..d01f88bdaff7 100644 --- a/lib/libpmc/libpmc.c +++ b/lib/libpmc/libpmc.c @@ -763,13 +763,20 @@ static struct pmc_event_alias cortex_a57_aliases[] = { static struct pmc_event_alias cortex_a76_aliases[] = { EV_ALIAS(NULL, NULL) }; + static int -arm64_allocate_pmc(enum pmc_event pe, char *ctrspec __unused, - struct pmc_op_pmcallocate *pmc_config __unused) +arm64_allocate_pmc(enum pmc_event pe, char *ctrspec, + struct pmc_op_pmcallocate *pmc_config) { - switch (pe) { - default: - break; + char *p; + + while ((p = strsep(&ctrspec, ",")) != NULL) { + if (KWMATCH(p, "os")) + pmc_config->pm_caps |= PMC_CAP_SYSTEM; + else if (KWMATCH(p, "usr")) + pmc_config->pm_caps |= PMC_CAP_USER; + else + return (-1); } return (0); diff --git a/sys/dev/hwpmc/hwpmc_arm64.c b/sys/dev/hwpmc/hwpmc_arm64.c index 988cd1744a07..9cdb2bfc06cb 100644 --- a/sys/dev/hwpmc/hwpmc_arm64.c +++ b/sys/dev/hwpmc/hwpmc_arm64.c @@ -187,6 +187,23 @@ arm64_allocate_pmc(int cpu, int ri, struct pmc *pm, if (config > (PMC_EV_ARMV8_LAST - PMC_EV_ARMV8_FIRST)) return (EINVAL); } + + switch (a->pm_caps & (PMC_CAP_SYSTEM | PMC_CAP_USER)) { + case PMC_CAP_SYSTEM: + config |= PMEVTYPER_U; + break; + case PMC_CAP_USER: + config |= PMEVTYPER_P; + break; + default: + /* + * Trace both USER and SYSTEM if none are specified + * (default setting) or if both flags are specified + * (user explicitly requested both qualifiers). + */ + break; + } + pm->pm_md.pm_arm64.pm_arm64_evsel = config; PMCDBG2(MDP, ALL, 2, "arm64-allocate ri=%d -> config=0x%x", ri, config);