Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1671802lqe; Mon, 8 Apr 2024 17:04:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWbBLlaDW+CbJJWbJ+Hosc4/bYtKVpkFaQEQp/N+RKXloKhiDnorg4H78Qn4GFOlWQt5bYP1tiHC4oxvd9jY4QngyFEee8nYWiwmWbQbg== X-Google-Smtp-Source: AGHT+IGTBoDhWwWNhKHc/MJJhbNlJcLfRbedEiGfujn26+BpcZoAbsTzfQpDbSGzb688xo12jx63 X-Received: by 2002:a05:6808:1801:b0:3c5:ea64:a471 with SMTP id bh1-20020a056808180100b003c5ea64a471mr7906392oib.6.1712621097150; Mon, 08 Apr 2024 17:04:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712621097; cv=pass; d=google.com; s=arc-20160816; b=jsb1FaQ5uipi1LQbFHP6Q4mvi2A+ukWh3RMcuYKcVCBkkmIzMfQze3g7KWHZAkfErF 6AcXCtzI6+u5Rg0gKHFLov0lTwDLKLp/0AA7veyBqTL18DR3yVyZ2lSRfW8LFV7JMSex Ju2GjporO6CYLMpw25IIdX+GtMvi2L5jAxmqTK6KtqGq03W80N7p5Nn9y8rXz12kdyhu FsGB5F2KDP5QJ4nWMAG0JltSVaC4dWWIO2UKTFIMYQ/FvmzRpL0IdRoTqn2aYK23m05h /F1mQ9grChOEB+70f/8M+Qs11lXAuZ7u3VpJIn6x3VTX9/MdFT0Hze8Sy2UbgRW3BKZb 5GdQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=Xd+FWiZlX/lpCLCXGGzdHlU3p21YETfnnn9ljhWHF9I=; fh=dDYlPFO6bYCgmIPBg/a2Y8NP3ovn5af+QdnRdeeDAsM=; b=rEdOmbi+TzMomSxn8/ZHJXt2HXC/qXVvZ6hAWI8+3eHxRj+rS5gsB6MWLl0Z9N/mJV stn0kZ52C8bHQr7e87PNd4Ze6BqPdCzKjDllp2x/GBRMWa8vtdUrprHDcYAZbcYJ/Rmg N0JqOoqQylcFpEs3V8T5Qlp4XcXo8BnaIQdxg9IAsh0E4yuFylQmebT0zeJxmT03EIbS byqwABWQoQw6Epr/vQ1zfFmwp8NqHCxHkocT2CrxkXZLnAWAuWY+SmkvtMsyKNnmhUw6 ipbqur4Lfu06o/JtUqKgPYg0EEg8Ry+AmAjB8eqj6cwK0dZwkuZxZ1T1OJazNOuepa9R VTxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=ag5YBuC4; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-136031-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136031-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d12-20020ac85d8c000000b00432c8b9f5basi9301079qtx.753.2024.04.08.17.04.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 17:04:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136031-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=ag5YBuC4; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-136031-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136031-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C99A41C23C4D for ; Tue, 9 Apr 2024 00:04:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7505BEC3; Tue, 9 Apr 2024 00:04:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="ag5YBuC4" Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 069C519B for ; Tue, 9 Apr 2024 00:04:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712621086; cv=none; b=TDcgB7uVJ66a8aUFWkDBbl6tYAawfoxlD8nXIb8wzIXXLaeKzpxz5RS+fghlFQ14+BmOAn4nHEmYYglHg7sbcXUaHSNbONnvutzer3e7cPyAKpMs0Ozh6KgZcH/pJv95fG9C+/2wGt8mAkIXUMQp9dLgG48XzByxzZheYSel7g4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712621086; c=relaxed/simple; bh=tGemAdGs1i/th5kpM2ts3FwXyK6yltFMw9jonLi8+1s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=RCRjTptzkhUOdMST9xb28i2ZJLlUy/Cga83dWwXhHPMxsvfvUqmoQeRIhnOZ9CsYmP2mNAH6cIZy8g06c75h2orh4N3JVtcc7KWqK8sFZe0OLbdx3Q7Jel3cj0e9K7t60UyquEkoE4SHBpxL0xiCT0kExEu7wzkw0py0W2zCxkc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=ag5YBuC4; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1e3e56c9d2cso19261185ad.1 for ; Mon, 08 Apr 2024 17:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712621084; x=1713225884; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Xd+FWiZlX/lpCLCXGGzdHlU3p21YETfnnn9ljhWHF9I=; b=ag5YBuC4jZYDWk+vcemFhfpKim+usl0i89xx/mLRK/sZ5KhQu4noBx6ZHCWYMvbb3z 1HberzLuUvZ17p8Xp5sTpijGt+9K+T787qIibS53AIQnhGEsCskhHiJHhqTaHTdGbdJB 4WOrHva4e8dWwlu0Fp50P+XxdpZJEP7HxVU2wenl4GV9nFd6Us/ONeBn8hzAUTCSy0rP DM9/owVNWzWVhxY04snMMIxglq4qND5KGAp/5eMeEQb8D8lDXqSzvtKnhAPVRi11mC/P xr4qRFRV01w8gYyXp4yy0SLWXIcQUf4OcVnbSIGue3lSE1x4W9UhZEdev9rED215ppxZ BJcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712621084; x=1713225884; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Xd+FWiZlX/lpCLCXGGzdHlU3p21YETfnnn9ljhWHF9I=; b=DuO2sFEqqgPg8jpw8SUv9aX58RHZp65MJZd/ztXUaQjEDAUOvsP2Mhl6/S09O9ilbQ bIQoJ80mMzSJtYusYT6fsCQA6abovuPAxffhTz4EE0/7RVfKaPk8fgvKZ+5JXgMhDJqQ MWpSx8ifTln+p7m2DUomVhqv2IxxC1wsRtyhtI75ct5gz9UBbEhM3LBF4ChCYBd1YWtP X1umRi61Y2m6W2NhTZzwVccCTPUXpBafbTCsf39Ac/C5kaxXR9jr43Qjix6xb9bhF9RG YibPARsas4oef6b+9AkjvCXfr5y08pgPDswLMx1FTCo0ihuOFzkB4gdBkRD2xdA+hN9/ /uPg== X-Gm-Message-State: AOJu0Yz+T/zLIF/1rP3sFlqK5hGEFIu+AXWcNU6gHv7tdofKk8jvjCb1 ry2VmY6UiMLmqJnvAlOIcsPv7pc79cT7Y+DwawN0JJv/DovSHH7hnORNUSCON2c= X-Received: by 2002:a17:902:d2ca:b0:1e4:1932:b0a5 with SMTP id n10-20020a170902d2ca00b001e41932b0a5mr5371923plc.68.1712621084126; Mon, 08 Apr 2024 17:04:44 -0700 (PDT) Received: from ?IPV6:2601:647:4180:9630::e8c1? ([2601:647:4180:9630::e8c1]) by smtp.gmail.com with ESMTPSA id c17-20020a170902d49100b001e1071cf0bbsm4411011plg.302.2024.04.08.17.04.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Apr 2024 17:04:43 -0700 (PDT) Message-ID: Date: Mon, 8 Apr 2024 17:04:41 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 03/22] drivers/perf: riscv: Read upper bits of a firmware counter Content-Language: en-US To: Andrew Jones Cc: linux-kernel@vger.kernel.org, Palmer Dabbelt , Conor Dooley , Anup Patel , Ajay Kaher , Alexandre Ghiti , Alexey Makhalov , Juergen Gross , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Shuah Khan , virtualization@lists.linux.dev, VMware PV-Drivers Reviewers , Will Deacon , x86@kernel.org References: <20240403080452.1007601-1-atishp@rivosinc.com> <20240403080452.1007601-4-atishp@rivosinc.com> <20240404-89ee7d7f90a5fcc91809065e@orel> From: Atish Patra In-Reply-To: <20240404-89ee7d7f90a5fcc91809065e@orel> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 4/4/24 04:02, Andrew Jones wrote: > On Wed, Apr 03, 2024 at 01:04:32AM -0700, Atish Patra wrote: >> SBI v2.0 introduced a explicit function to read the upper 32 bits >> for any firmware counter width that is longer than 32bits. >> This is only applicable for RV32 where firmware counter can be >> 64 bit. >> >> Reviewed-by: Andrew Jones >> Acked-by: Palmer Dabbelt >> Reviewed-by: Conor Dooley >> Reviewed-by: Anup Patel >> Signed-off-by: Atish Patra >> --- >> drivers/perf/riscv_pmu_sbi.c | 25 ++++++++++++++++++++----- >> 1 file changed, 20 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c >> index 3e44d2fb8bf8..babf1b9a4dbe 100644 >> --- a/drivers/perf/riscv_pmu_sbi.c >> +++ b/drivers/perf/riscv_pmu_sbi.c >> @@ -57,6 +57,8 @@ asm volatile(ALTERNATIVE( \ >> PMU_FORMAT_ATTR(event, "config:0-47"); >> PMU_FORMAT_ATTR(firmware, "config:63"); >> >> +static bool sbi_v2_available; >> + >> static struct attribute *riscv_arch_formats_attr[] = { >> &format_attr_event.attr, >> &format_attr_firmware.attr, >> @@ -511,19 +513,29 @@ static u64 pmu_sbi_ctr_read(struct perf_event *event) >> struct hw_perf_event *hwc = &event->hw; >> int idx = hwc->idx; >> struct sbiret ret; >> - union sbi_pmu_ctr_info info; >> u64 val = 0; >> + union sbi_pmu_ctr_info info = pmu_ctr_list[idx]; >> >> if (pmu_sbi_is_fw_event(event)) { >> ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_FW_READ, >> hwc->idx, 0, 0, 0, 0, 0); >> - if (!ret.error) >> - val = ret.value; >> + if (ret.error) >> + return 0; >> + >> + val = ret.value; >> + if (IS_ENABLED(CONFIG_32BIT) && sbi_v2_available && info.width >= 32) { >> + ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_FW_READ_HI, >> + hwc->idx, 0, 0, 0, 0, 0); >> + if (!ret.error) >> + val |= ((u64)ret.value << 32); >> + else >> + WARN_ONCE(1, "Unable to read upper 32 bits of firmware counter error: %d\n", >> + sbi_err_map_linux_errno(ret.error)); > > I don't think we should use sbi_err_map_linux_errno() in this case since > we don't have a 1:1 mapping of SBI errors to Linux errors and we don't > propagate the error as a Linux error. For warnings, it's better to output > the exact SBI error. > Sure. Fixed it. >> + } >> } else { >> - info = pmu_ctr_list[idx]; >> val = riscv_pmu_ctr_read_csr(info.csr); >> if (IS_ENABLED(CONFIG_32BIT)) >> - val = ((u64)riscv_pmu_ctr_read_csr(info.csr + 0x80)) << 31 | val; >> + val |= ((u64)riscv_pmu_ctr_read_csr(info.csr + 0x80)) << 32; >> } >> >> return val; >> @@ -1135,6 +1147,9 @@ static int __init pmu_sbi_devinit(void) >> return 0; >> } >> >> + if (sbi_spec_version >= sbi_mk_version(2, 0)) >> + sbi_v2_available = true; >> + >> ret = cpuhp_setup_state_multi(CPUHP_AP_PERF_RISCV_STARTING, >> "perf/riscv/pmu:starting", >> pmu_sbi_starting_cpu, pmu_sbi_dying_cpu); >> -- >> 2.34.1 >> > > Thanks, > drew