Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp963085lqt; Fri, 19 Apr 2024 16:50:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW+RZ9fx8Mk56H2qvx4LEXAn5gZdHRgRpFqruFGvrr8gBTFstX0Bq0wL5LCLG9isgjm9VUmxvg+QXGP5+oZs7+r/tYDdbjsqux9JlHnlg== X-Google-Smtp-Source: AGHT+IE809doqcb1wizTIzEJ8hFsJZlJQeK15vDU7uX2X8eb3tIHDj5PxZdXc25q73i1wCdOVNFJ X-Received: by 2002:a17:906:c312:b0:a52:6e54:1c96 with SMTP id s18-20020a170906c31200b00a526e541c96mr2880892ejz.15.1713570631769; Fri, 19 Apr 2024 16:50:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713570631; cv=pass; d=google.com; s=arc-20160816; b=eiudUJtIdE8OZ5z2dxDuBqH7egsgMHVVq8qv3/KzvVLO5K+CEtJwjEnMzx7mbGBUgB Lzi6ei9GSAiIBOzi+HJBxL6RRMLNsilWMl29n7GveDb0km4CL1ra1KSO4fk0RMT0WxuR SGm3fif+EH0TRYvHnzLzpcNAEFfI8OrRVGM46WmiRPjwlwbWB3XydnBGYztjfIJewASb jyatzjmY8XmGxPpNllAQdEr9oz662fJCun2TpOoJV+sjHC9vQycsBy99Ei6cD0Rf7rh2 QjH2tULi6oSh5lqyT8b8IumVcOL+AZoN8tDfpDHTST+A3EnVXfwnKXoJ+unbhwiHjmVm HaNg== ARC-Message-Signature: i=2; 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=wkOPph+llp8Otwcwt9B3eiemeK+kGnMbysCIlXdxbFk=; fh=z7fJWkZ4T7GjqwnZHLiFaBRNsKIE6v81MvuCrwEofW0=; b=Id1n9nSZI00vz51c/Ug/yMUG2Z6HACUACY7ZsmKzLBWNP9NRKE2KKSG1Si3aF/dW44 TyhqkxfufTOUd49de14+bViMim2cwNZxaA2K/+EYYI/CDYxNZoXYiOUd40rjXxvHb4xD YlZwi3IY4rx1i913ApuXshxbtc5o0UF2y7wRxfBNi7xyI0y9oLvvLE82KmoxWpVRN2fd kjtJlQLfnL8zvUYq1h8tyAorFPR2OXOlZEpXAjFm9ZEsUzOFAV/yXymN+jCpSYODUgyI cAZpX9p5s4vjFIGoXQAi3DUTkEQReI/zsBRb/Z12mtZiTJkJlppTGPr66Vo2/fFo87UG 5rCQ==; 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=CGz90VpD; 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-152031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152031-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ox3-20020a170907100300b00a4e8aaa9f04si2830379ejb.518.2024.04.19.16.50.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 16:50:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=CGz90VpD; 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-152031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152031-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 548541F21CE2 for ; Fri, 19 Apr 2024 23:50:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 058FA144D2F; Fri, 19 Apr 2024 23:48:03 +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="CGz90VpD" Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 BE606144317 for ; Fri, 19 Apr 2024 23:48:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713570482; cv=none; b=rJmiMCJvySjdz0RVxUJEr9N4l+k9VfFu4rWnCHu+trIR2usr1gXY2lXATsJohKSGCy+xwJW5YyaeXsEpRiF3rr4cP/uhGCtLvU1YzWgLYtTqbtxU8q2xbyBxAEkUEQIZCpUHT+Duh0uGbqz8oNAwRj2uUwPG5o8kIe5KvOKlls4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713570482; c=relaxed/simple; bh=MfjfJpm3VBkwjMm72HsMOvO9UI9tfbob2HC7hMKYzy4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=B6PFh22zuiFuykY0jVrZWwH3PU4U31i3/ZRHlkNiTGWtS0vtvcwxmPIIlBGnLdIka3VaptVEgBtPgwXwhKnwCi5S5BfVKOMtpREijx8TNhU+sRZktSQPpcLSYjG9Ot41UbxCtUGIg4idoqqRZ2j712vyv+LSZWmMCmTtb7SxiVc= 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=CGz90VpD; arc=none smtp.client-ip=209.85.214.178 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-f178.google.com with SMTP id d9443c01a7336-1e83a2a4f2cso16913145ad.1 for ; Fri, 19 Apr 2024 16:48:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713570479; x=1714175279; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wkOPph+llp8Otwcwt9B3eiemeK+kGnMbysCIlXdxbFk=; b=CGz90VpDvdqVi8eQyfqgWWuqNbnhGVSLxPjW0WSmFN9Kfpf80dwLnSigUcUN0Y2lFk mFW4C5zV3ZccfO7U/M+Gj1bMZscD3oL3mA1yfsrMcq7jPW3KGrLjGM4SbVFs4f5gmuPI GQn1Ckh2VhaAuLowB3wg+g3WMU1W8JdlQL5Dp/c/tjd9ggV1JwsiltNKXh4RKe3oA8if JYjWrzSdhuahMKkjWsqWHqHI+8/jnqgvJp60eU5aK3eFRsB3kWan9ePnJHDI8aFKFhDq GD/cqBVe8xv/h+2Aogjz3cMhJCrJHrHZyqqSSxZn8JoLNVOLN/LEADmAXHlEYYLtdZV8 CgdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713570479; x=1714175279; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wkOPph+llp8Otwcwt9B3eiemeK+kGnMbysCIlXdxbFk=; b=tS9KfO4Fsilna6wa8lLRjw0aMMSJhZDaE2+N0QoEjhAvNUzqz40Oezr4H5pLMNiOK+ 4If7qPeOo4bVSf5b34OuzV1dnJnXIAlXEdoh3hMnK0arr6TM0HTm+ENLIovXhZQgsZ+U SK8xZ/scBK8s0mzmUKvQbesm/tPkGVum97G4g7Qf9iNAgHLR+XYf5t6x8BxE1Ay8SXnq LvyYLVnqSmL7bRBs06hapwVJDjJdzfdPBJuSIY/3sXv6/aUkVEea9JQFEwptR8VXQweI NbPfTFMKzaKXqrkzZcpI2CQKJDgse5jX/vMK/tfNlgXdhElOcQTg+ARpp9o4lRu08mdv FMYA== X-Gm-Message-State: AOJu0YyOsnpIKxs5kIaeuA6+qXn5dH5E0tfKpv0rQp89QI2yzaymffLB +1Ks6gpaSXmw/2zYQP3pqXxDvY2xxHyFA80AVrFGDB3EFFK/bU+YZbCkEa81z5u0oFufWOWG3lQ S X-Received: by 2002:a17:902:784f:b0:1e4:a120:14f3 with SMTP id e15-20020a170902784f00b001e4a12014f3mr3799131pln.51.1713570479336; Fri, 19 Apr 2024 16:47:59 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id w17-20020a170902d11100b001e42f215f33sm3924017plw.85.2024.04.19.16.47.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 16:47:58 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Andrew Jones , Ajay Kaher , Albert Ou , Alexandre Ghiti , Anup Patel , samuel.holland@sifive.com, Conor Dooley , 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, Will Deacon , x86@kernel.org Subject: [PATCH v8 08/24] drivers/perf: riscv: Fix counter mask iteration for RV32 Date: Sat, 20 Apr 2024 08:17:24 -0700 Message-Id: <20240420151741.962500-9-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240420151741.962500-1-atishp@rivosinc.com> References: <20240420151741.962500-1-atishp@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit For RV32, used_hw_ctrs can have more than 1 word if the firmware chooses to interleave firmware/hardware counters indicies. Even though it's a unlikely scenario, handle that case by iterating over all the words instead of just using the first word. Reviewed-by: Andrew Jones Signed-off-by: Atish Patra --- drivers/perf/riscv_pmu_sbi.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index f23501898657..4eacd89141a9 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -652,10 +652,12 @@ static inline void pmu_sbi_stop_all(struct riscv_pmu *pmu) static inline void pmu_sbi_stop_hw_ctrs(struct riscv_pmu *pmu) { struct cpu_hw_events *cpu_hw_evt = this_cpu_ptr(pmu->hw_events); + int i; - /* No need to check the error here as we can't do anything about the error */ - sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, 0, - cpu_hw_evt->used_hw_ctrs[0], 0, 0, 0, 0); + for (i = 0; i < BITS_TO_LONGS(RISCV_MAX_COUNTERS); i++) + /* No need to check the error here as we can't do anything about the error */ + sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, i * BITS_PER_LONG, + cpu_hw_evt->used_hw_ctrs[i], 0, 0, 0, 0); } /* @@ -667,7 +669,7 @@ static inline void pmu_sbi_stop_hw_ctrs(struct riscv_pmu *pmu) static inline void pmu_sbi_start_overflow_mask(struct riscv_pmu *pmu, unsigned long ctr_ovf_mask) { - int idx = 0; + int idx = 0, i; struct cpu_hw_events *cpu_hw_evt = this_cpu_ptr(pmu->hw_events); struct perf_event *event; unsigned long flag = SBI_PMU_START_FLAG_SET_INIT_VALUE; @@ -676,11 +678,12 @@ static inline void pmu_sbi_start_overflow_mask(struct riscv_pmu *pmu, struct hw_perf_event *hwc; u64 init_val = 0; - ctr_start_mask = cpu_hw_evt->used_hw_ctrs[0] & ~ctr_ovf_mask; - - /* Start all the counters that did not overflow in a single shot */ - sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, 0, ctr_start_mask, - 0, 0, 0, 0); + for (i = 0; i < BITS_TO_LONGS(RISCV_MAX_COUNTERS); i++) { + ctr_start_mask = cpu_hw_evt->used_hw_ctrs[i] & ~ctr_ovf_mask; + /* Start all the counters that did not overflow in a single shot */ + sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, i * BITS_PER_LONG, ctr_start_mask, + 0, 0, 0, 0); + } /* Reinitialize and start all the counter that overflowed */ while (ctr_ovf_mask) { -- 2.34.1