Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp4293137rdb; Thu, 28 Dec 2023 17:45:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFxYgi2TAXVeIy4j5F5NOq8yyQs8DAAOdLuy1m14Zc6W8LQZJUIKhr262Iz59XdDuvghrIa X-Received: by 2002:a05:6358:260e:b0:170:4322:4040 with SMTP id l14-20020a056358260e00b0017043224040mr10777673rwc.17.1703814310178; Thu, 28 Dec 2023 17:45:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703814310; cv=none; d=google.com; s=arc-20160816; b=bH75dzxZkOb0lRlMVcwHv3RD7stN51K8BRbIOnw77CayTxZroxQnuAdDkZPzPAbrV+ HHvYMI8tsNP/hzxTc8yxvO/NJnz2SxULVxbI2NObqk2WIeoi6Kii+NTtUd5P5DeD5QXt ZuqmihSivYKP+k3WaJ1AR5PFkz4/NkgtY7XsUeGBxDV08M77Z4uKwoNTA9vmksmSKhea aeR9chmsh7sNKAgN+wSLTQ+D5+eNU4H/qK5K87LSztIiO67emHSRNonELgpWgwyUB08U dcAbnjtaWp3L8A0f2ctMEnRvmb+4nACBEbnueSyD/ulKlCjhvmf0TFLcNbHkMV6YU+zr na+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:to:from:cc:in-reply-to :subject:date:dkim-signature; bh=WNCVR8SMHnCHeEQ/yMeXXkUdP9Bs/RTaT2/RSyEx1Tc=; fh=7jm1ah6RLcZLFBPNyA3LOhc2aXpumIjfCn/TDfmLv9o=; b=f4EQauwjB7gwCIlCoeBwCSUeGwiABi+lQoQw4ggB/mLVSZB2bGkKn16LEmp8apAKoy SfuS8eXiIQYgQuh3j4Vka1pyU+x5VQfB79FOlBi72qnBbUR+hZ0Ea2kwxUKYocZiWY4M K1YNyO1qw33Ek297BtDeLIR4hYMbGqOJ3GD9nzPG+wTPsTh/0Q+6HQ6tQOAJnJoR4Ms8 6ExuArZlkTpef4kHBb+/Mxdh0oeSGPk93JYi1tDdqC3KQCyol6WMh7uxKBRzpQe3YFwO gEinyHObTRG7Nlh98dA9d/hJLlC1tRtKiw9PHS1Bz8eEg3cEJaI3Kk1Wjm1+kZZrFxOz zlgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20230601.gappssmtp.com header.s=20230601 header.b=Gvju+amL; spf=pass (google.com: domain of linux-kernel+bounces-12902-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12902-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 l11-20020a05622a174b00b00427ed402c10si4799020qtk.262.2023.12.28.17.45.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 17:45:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12902-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=@dabbelt-com.20230601.gappssmtp.com header.s=20230601 header.b=Gvju+amL; spf=pass (google.com: domain of linux-kernel+bounces-12902-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12902-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 829581C238EF for ; Fri, 29 Dec 2023 01:45:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C44BC1C26; Fri, 29 Dec 2023 01:44:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dabbelt-com.20230601.gappssmtp.com header.i=@dabbelt-com.20230601.gappssmtp.com header.b="Gvju+amL" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (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 4D0231388 for ; Fri, 29 Dec 2023 01:44:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dabbelt.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dabbelt.com Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-28bcc273833so5421740a91.1 for ; Thu, 28 Dec 2023 17:44:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20230601.gappssmtp.com; s=20230601; t=1703814289; x=1704419089; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:from:to:cc:subject:date:message-id :reply-to; bh=WNCVR8SMHnCHeEQ/yMeXXkUdP9Bs/RTaT2/RSyEx1Tc=; b=Gvju+amLK1SWDCzrmCohjbd3fDyjKYopcQjuln/p70su+MGV689NW/Lpjve1AfMgDZ 3Lpnen4voluq9tu3z7SemfGVZeStKrnbWSeIZVNio72MJ0OSLTV7jkC1FB8O5ws9nxLw iNn/Btn1asPDoGzeDxgfy403w2VNqkd3x6KDAciEHFeJEwp2Tq9f5JDlerxNiyb/sltK l0jr7Jh4DMzQW6Vj25Sq1+neQRbbibTq5Ju77TwnUbYA4S5W2YfF+j4lkDfiQAFhkyhe ufVEqgB+gKjq411/BuEYAl7tPMT/m3eWffCqbHRTZ3Q+qvsrwHh4e/HKC1sP1LlR7BNf wERw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703814289; x=1704419089; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WNCVR8SMHnCHeEQ/yMeXXkUdP9Bs/RTaT2/RSyEx1Tc=; b=atPVJP3+u2dPxblFMeYDmdODUqDTSPjWBYIljcOgA9rdNE06u5KrgiTkoTJRwHBhXY QfcyIPpadUPWxbEnqy5vM6XzCCERVwDbVHVn3OVnmH27pneHONY5AmXi3SE7lhHVmR4R +JuaUhoMjGZaSgKwWaDvkZ8KPyIuVM7MdC30PBqNQmLVeuobaE3COfSp17x9ceF8BGJx M3zmPPk+3/GeODrt2qFMvBQiJ/AxD8uOqPVmOHDEalZafvbHXfUGtq5g5wUDVwX47Ldo CdKnPE8+C8Wch7HAFSrk0sAW29ucJqDTa88WrktEHNujVcuCxckgkrFh6GFc4AP4SfNJ 1SLg== X-Gm-Message-State: AOJu0Yw1V6/HpRQYB8TtrQmymv1Iu9wYCL3o50E5jXpWU0Fcu9xt0DWb FYZrcCs3+Uo0NtDI8vm8dMX/BgYmeGAyvXQ+LPz+esXVqSM= X-Received: by 2002:a17:902:f7ca:b0:1d3:f067:a3f0 with SMTP id h10-20020a170902f7ca00b001d3f067a3f0mr11108857plw.107.1703814289238; Thu, 28 Dec 2023 17:44:49 -0800 (PST) Received: from localhost ([12.44.203.122]) by smtp.gmail.com with ESMTPSA id pl18-20020a17090b269200b0028ae9a419f0sm19000570pjb.44.2023.12.28.17.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 17:44:48 -0800 (PST) Date: Thu, 28 Dec 2023 17:44:48 -0800 (PST) X-Google-Original-Date: Thu, 28 Dec 2023 17:44:25 PST (-0800) Subject: Re: [v1 03/10] drivers/perf: riscv: Read upper bits of a firmware counter In-Reply-To: <20231218104107.2976925-4-atishp@rivosinc.com> CC: linux-kernel@vger.kernel.org, Atish Patra , aou@eecs.berkeley.edu, alexghiti@rivosinc.com, ajones@ventanamicro.com, anup@brainfault.org, atishp@atishpatra.org, Conor Dooley , guoren@kernel.org, uwu@icenowy.me, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Paul Walmsley , Will Deacon From: Palmer Dabbelt To: Atish Patra Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On Mon, 18 Dec 2023 02:41:00 PST (-0800), Atish Patra wrote: > SBI v2.0 introduced a explicit function to read the upper 32 bits > for any firmwar counter width that is longer than 32bits. > This is only applicable for RV32 where firmware counter can be > 64 bit. > > Signed-off-by: Atish Patra > --- > drivers/perf/riscv_pmu_sbi.c | 20 ++++++++++++++++---- > 1 file changed, 16 insertions(+), 4 deletions(-) > > diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c > index 16acd4dcdb96..646604f8c0a5 100644 > --- a/drivers/perf/riscv_pmu_sbi.c > +++ b/drivers/perf/riscv_pmu_sbi.c > @@ -35,6 +35,8 @@ > 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, > @@ -488,16 +490,23 @@ 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 val; > + > + 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 { > - 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; > @@ -1108,6 +1117,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); Acked-by: Palmer Dabbelt