From nobody Thu Apr 20 18:57:45 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 4Q2Rk567Xnz46SHg; Thu, 20 Apr 2023 18:57:49 +0000 (UTC) (envelope-from mavbsd@gmail.com) Received: from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com [IPv6:2607:f8b0:4864:20::1134]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Q2Rk52Srsz3FNx; Thu, 20 Apr 2023 18:57:49 +0000 (UTC) (envelope-from mavbsd@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-54f21cdfadbso54592747b3.7; Thu, 20 Apr 2023 11:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682017067; x=1684609067; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id:sender :from:to:cc:subject:date:message-id:reply-to; bh=RsY8KjN3FdDYBX/nb4FT9kVxgIw3BqrgocQqQTsKUg0=; b=r2DJagF2dWrYpRWHKFzbHUQNsvrVKzYv+Nn907lww+jbTbJ/jxGkQ8zdyNd3QUPga2 uDAutANsP/DFm+BirhHLe/bqVvD6ZfJhwef2VxJeughBJt5htsznqCYse0cWXvA77FaL mephN2+kXeEmZF5vEfdq/hwTkLTnWurVyOI/Gn66p7uiNKgANKY7qXLKPjNVELAC0Ey+ pMk6ZH9NyO7dCnAl93YkZLxZsq7uaQcxTQALGTok6LT7cgOWOTQ95fXSPmMqmmRW1NVF Qzi7HBELAA6srYI9nC0EOhutj89EcdigdtThZH+pxzsMqejJy7QeFISF9aYYOnzfrlUK KOeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682017067; x=1684609067; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id:sender :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RsY8KjN3FdDYBX/nb4FT9kVxgIw3BqrgocQqQTsKUg0=; b=j7r0+C/d9X8takR/iAqeUU0DMN5a6IFOI/Qg2BeJ+ovJHSD5LxcoadjdqGF0vaXJAR KAmrUVAd3vq3UcYl6Jia4Y2W+MQs9GKYccQgbH9lmF0vle79oI5nzSLi2fC6LoKjVWgO HqDavo0aVP00rs8DjtPsNek0md81ijR91yuN1rSo5b84wBNd9hlGGFZFbPHcJVlGIpXS sedgjkEF4P/c7419wyVmkPUwJe/8GLQolCk3o2iKkEB743ytqrcXsfAjSGPuw0QTk29m Mx5HPnHS+PkspdD0fInnaDjDC2Jfbm2pQWInaUQ7t770IZqybjmywiZ66jt0TfHj22fK m+hg== X-Gm-Message-State: AAQBX9feCgtTC/rno77Z7r4t8KzivvQ+VY6vQw38r5mY8rjPYR9cku1k fBhFCpc0GoyY1WoHC3EZYgFIuSq8eEA= X-Google-Smtp-Source: AKy350bfISNE/zSsrvl3x5utgpyzLALqcH9QZJ61buiHWXNjQ0HZak9Ld/IKlZmuPm3DF+qEVQn6oQ== X-Received: by 2002:a81:834b:0:b0:54f:a8cf:6b48 with SMTP id t72-20020a81834b000000b0054fa8cf6b48mr2035523ywf.10.1682017067591; Thu, 20 Apr 2023 11:57:47 -0700 (PDT) Received: from [10.230.45.5] ([38.32.73.2]) by smtp.gmail.com with ESMTPSA id w9-20020a0dd409000000b0054f8a3f6281sm498490ywd.3.2023.04.20.11.57.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Apr 2023 11:57:47 -0700 (PDT) Message-ID: <5593fcdc-9adb-89a9-3ad8-151a9e7c5c0d@FreeBSD.org> Date: Thu, 20 Apr 2023 14:57:45 -0400 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 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Content-Language: en-US To: Kyle Evans Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org, "Sideropoulos, Alexander" , Andrew Gallatin , Toomas Soome References: <202205310005.24V05MTi034088@gitrepo.freebsd.org> From: Alexander Motin Subject: Re: git: c1e813d12309 - main - hwpmc: Correct selection of Intel fixed counters. In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4Q2Rk52Srsz3FNx X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N Kyle, Andrew, On 19.04.2023 16:06, Kyle Evans wrote: > On Mon, May 30, 2022 at 7:05 PM Alexander Motin wrote: >> >> The branch main has been updated by mav: >> >> URL: https://cgit.FreeBSD.org/src/commit/?id=c1e813d1230915e19a236ec687cadc1051841e56 >> >> commit c1e813d1230915e19a236ec687cadc1051841e56 >> Author: Alexander Motin >> AuthorDate: 2022-05-30 23:46:48 +0000 >> Commit: Alexander Motin >> CommitDate: 2022-05-31 00:05:15 +0000 >> >> hwpmc: Correct selection of Intel fixed counters. >> >> Intel json's use event=0 to specify fixed counter number via umask. >> Alternatively fixed counters have equivalent programmable event/umask. >> >> MFC after: 1 month >> --- >> sys/dev/hwpmc/hwpmc_core.c | 34 +++++++++++++++++++++++++--------- >> 1 file changed, 25 insertions(+), 9 deletions(-) >> >> diff --git a/sys/dev/hwpmc/hwpmc_core.c b/sys/dev/hwpmc/hwpmc_core.c >> index fce97cbd5b8e..73cfee0b3975 100644 >> --- a/sys/dev/hwpmc/hwpmc_core.c >> +++ b/sys/dev/hwpmc/hwpmc_core.c >> @@ -245,15 +245,31 @@ iaf_allocate_pmc(int cpu, int ri, struct pmc *pm, >> ev = IAP_EVSEL_GET(config); >> umask = IAP_UMASK_GET(config); >> >> - /* INST_RETIRED.ANY */ >> - if (ev == 0xC0 && ri != 0) >> - return (EINVAL); >> - /* CPU_CLK_UNHALTED.THREAD */ >> - if (ev == 0x3C && ri != 1) >> - return (EINVAL); >> - /* CPU_CLK_UNHALTED.REF */ >> - if (ev == 0x0 && umask == 0x3 && ri != 2) >> - return (EINVAL); >> + if (ev == 0x0) { >> + if (umask != ri + 1) >> + return (EINVAL); > > Hey Alexander, > > This seems to break system-mode sampling of fixed-mode counters; e.g., > from the manpage, `pmcstat -S instructions`, and I'm not at all > familiar with these parts of pmc. We come in once with umask=1, ri=0; > then again with umask=1, ri=1. The latter fails and we try umask=1, > ri=2, which again fails, and the PMCALLOCATE op ultimately fails. > > Is `umask != ri + 1` correct, or should this be reverted back to > `umask == 0x3 && ri != 2` or something else? I've no idea what the > `umask` values represent in this context. I still believe this code is correct, at least as much as data in lib/libpmc/pmu-events/arch/x86 is consistent (look for "INST_RETIRED.ANY", that actually fails here after translation from "instructions"). The multiple calls you see is the result of hwpmc trying to find counter "matching" parameters. For fixed counters the match is really just (umask == ri + 1), since umask for fixed counters in the Intel events data is just a counter number starting from 1. I've tried to test fixed-mode counters myself and got it failing also. But looking a bit deeper, I think the problem may be caused by this patch: https://reviews.freebsd.org/D35709 . I think it tries to allocate the same fixed counter twice, where the first attempt succeeds, while the second fails, since the hardware is already busy. I haven't looked close on the pmcstat code, but I suppose the patch was wrong, so if you or Andrew wish to fix it properly -- I'd be happy. -- Alexander Motin