Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1435518lqp; Mon, 15 Apr 2024 06:39:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWmGMfdYcjLERZ27hWJ/VeNC6Pp/syDC6o4BZx4aaUbQhsz74IoRhjnR2j7K/9TJDLwECDclKl6se9WS4WcBIHDL8htRqYb20mRTt0Udg== X-Google-Smtp-Source: AGHT+IHRc8PC1w4R55rWoz7/FHzbaQ4vfI9Hf08jojm9EuOzJ9wCv2Ii6aTcis1JQuBx4AGynoLn X-Received: by 2002:a17:90b:1d08:b0:2a2:930c:9a8f with SMTP id on8-20020a17090b1d0800b002a2930c9a8fmr9103198pjb.32.1713188346861; Mon, 15 Apr 2024 06:39:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713188346; cv=pass; d=google.com; s=arc-20160816; b=aV6RLW9hbHeBa+s22W3b5Yai6dXdo0qrB6cfrV/6vJDbKIfpH39ylqdXX8ZfTjSaEH rYB+g91s4YTO7PoPfLWPlq6pdib7x3s+gIYp/MwIjAYZRLJ2TKQRsQvmWhtTuG79Xuew rZSeveRK+os7xRfBhDxbexWv6lyp8NDOfflLIRP35PxlYInyNh4Nfai0BvNKwTKpVwbx 5MFQf17Cidxxwl9d3d9GjZroK/m7XCmj4onVLnWfyqwjq+0NNIAt2QCkhe0jAHkDzxYF ZEq3VkpdYilrwkMjzuBMJ14p486WxL8NcUr4Lx2rkTuGHFh2h9PQDslOYldhHgLqoUhm J/Lw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hkfoH6pgevkYBCq40yfYP4WU2j0tmJHdJg6k4nyDGog=; fh=tWvpJc29toMKVf0Vo/Cef2lCHnnN2fDsoZmXn9zwJ1Y=; b=IfxKbgj0ay9V7V9uTZlWFXuYFz5MPuZmRFUcJsIeNuEd3ozLrH+O+KtAG1ZxHuBv7Q uwtxBAB0xR/Zb6oQzkGrLMpMUfCZ3UhsaxUDhz5hq2szjjBoIxn3gQmLrObLuNaUNhNw Nyuj01K46pmAUr+O/GnORZJ1DLZzb59H/IjltUmNr5ZCJBDW8qM/RwyuBSY6LuFZz+fk VLjuU9nHZ3iBzWiwjSyCiI7iEYg+t7OtHK+0c7NZO+6JoXkHmzU1PRpQUC6SiT/mJxP+ 8A25dYXbTZjnmswBr5F04beBwmMz2eQY+irY7G70DDIP4lDjSIHyhbpeSkXbNSseDJ6v MCow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=bugntPOs; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-145234-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145234-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id h4-20020a17090aa88400b002a545ed0b00si8061578pjq.166.2024.04.15.06.39.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 06:39:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145234-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=bugntPOs; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-145234-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145234-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 7AF93B2244A for ; Mon, 15 Apr 2024 13:26:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 488E081AC4; Mon, 15 Apr 2024 13:15:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="bugntPOs" Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 5BF8573514 for ; Mon, 15 Apr 2024 13:15:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713186919; cv=none; b=KCZIGLG9GGiIPF6OKomfH4P5xk0jMWV6ZsZp9E1dgHLBhDE3BU89GKzmkd/+eItS8qe1K5wybt01YiLqKjYhGgKbInmwfCSGzxPu37Oxi/imb80SdHsczYIv2hUf4dxfDL4D2w33Zbq/cftXH+wRLnMGb3Eqy9dCYnpS9+HTP0w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713186919; c=relaxed/simple; bh=wQu4AB/hrYeKhHh8iDIAICEBW2rABai55pnKGz7N32g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gDSyLbZLFbTCmsfLq08OKE7JabkE2LQhiZ/Io7AaNoCXKBY10YyP8SN3udXbuo8P6ZXq7nNVTp/l2Ls+6ZEuzvBbzu8aQZHyHssXp7ZB0I5FCz9tFJOD729fntH6axTMwhRoBgUiEnNUcucgxFdOPr9unXup7shma5C1Nm8arCY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=bugntPOs; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-418671bac0aso3703205e9.1 for ; Mon, 15 Apr 2024 06:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1713186915; x=1713791715; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=hkfoH6pgevkYBCq40yfYP4WU2j0tmJHdJg6k4nyDGog=; b=bugntPOs3rv2UwUzmx/l888+vpjQne88H7KkS8WdzDyU9Xz01g9lbsJjAv3Xz15xn8 t2FHCF3kVWnt09c3fwuWVj4YOy+7Tu97aD1hEXjELph0cWVitK0G/n4vcS4C1QE/6CmC YRzOs5GyZTVASd/30iUwpy7KV22eHuKQ/kLpWwA7O3pQszI+7iM1HvX+Z71LNsqnbbsP 2x3vPrC7eko0j4/n7PK7Mfc95qepsb817Mv0yzD0sN683CxnSco7YWMk9PAv3KdhTIlS 9hV2M87IoBPa8wa/SW2S9M/a9iK0zeiE/7oxm0JGrseTuRxX/qDt7vdfKW+kUSKaNi4T z4lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713186915; x=1713791715; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hkfoH6pgevkYBCq40yfYP4WU2j0tmJHdJg6k4nyDGog=; b=TFIBiF7KZlkhh3SgANDLbvym1asBhtfCh2gBWcdnIVyCkB4aq1o2V+Bo4kAa96Lupj 3K9q1SZtuLD3V0RHNSI0+a8h56xKEwQqiT2+q8qhXUGkDJnNxXpZMjuBznxlwwCGvNGR 9hczwaUWg23jzeRP3yQBPLlxxOwF7XHkQRL7yip2j0uMYmtCbKZ7jdyujaIunavWVV1r 7PDRQW7yFqHxng5FAa/t6wxC00Ka//5Ojblw/Zdj3HKPfBVh5kjNhDejm2OYzxopGYrA EFngx2OwFtFh5poCzGOtAchGaNcekwh9MShq/wZCbWcvaLqMd5gCsgics5vg3U9yrxlm Rkyw== X-Gm-Message-State: AOJu0Yzd6c44Op1X+AwflluxGup3bkxujeC9E1NbjaRMQX1P53P/WVQM 3yAQVfBtUDe3Qswl/zS0EXul1bWpA1fWNWSlTXPEpORur/zXJT/fgntZSn4tdWM= X-Received: by 2002:a05:600c:4f4e:b0:418:2394:c60e with SMTP id m14-20020a05600c4f4e00b004182394c60emr3981791wmq.24.1713186914737; Mon, 15 Apr 2024 06:15:14 -0700 (PDT) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id z15-20020adfe54f000000b00345c2f84d5asm12068662wrm.10.2024.04.15.06.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 06:15:14 -0700 (PDT) Date: Mon, 15 Apr 2024 15:15:13 +0200 From: Andrew Jones To: Atish Patra Cc: linux-kernel@vger.kernel.org, Palmer Dabbelt , Anup Patel , Conor Dooley , Ajay Kaher , Albert Ou , Alexandre Ghiti , Alexey Makhalov , Atish Patra , Broadcom internal kernel review list , 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: Re: [PATCH v6 08/24] drivers/perf: riscv: Implement SBI PMU snapshot function Message-ID: <20240415-1654deb9446d6c0ebb858b30@orel> References: <20240411000752.955910-1-atishp@rivosinc.com> <20240411000752.955910-9-atishp@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240411000752.955910-9-atishp@rivosinc.com> On Wed, Apr 10, 2024 at 05:07:36PM -0700, Atish Patra wrote: > SBI v2.0 SBI introduced PMU snapshot feature which adds the following > features. > > 1. Read counter values directly from the shared memory instead of > csr read. > 2. Start multiple counters with initial values with one SBI call. > > These functionalities optimizes the number of traps to the higher > privilege mode. If the kernel is in VS mode while the hypervisor > deploy trap & emulate method, this would minimize all the hpmcounter > CSR read traps. If the kernel is running in S-mode, the benefits > reduced to CSR latency vs DRAM/cache latency as there is no trap > involved while accessing the hpmcounter CSRs. > > In both modes, it does saves the number of ecalls while starting > multiple counter together with an initial values. This is a likely > scenario if multiple counters overflow at the same time. > > Acked-by: Palmer Dabbelt > Reviewed-by: Anup Patel > Reviewed-by: Conor Dooley > Signed-off-by: Atish Patra > --- > drivers/perf/riscv_pmu.c | 1 + > drivers/perf/riscv_pmu_sbi.c | 224 +++++++++++++++++++++++++++++++-- > include/linux/perf/riscv_pmu.h | 6 + > 3 files changed, 219 insertions(+), 12 deletions(-) > > diff --git a/drivers/perf/riscv_pmu.c b/drivers/perf/riscv_pmu.c > index b4efdddb2ad9..36d348753d05 100644 > --- a/drivers/perf/riscv_pmu.c > +++ b/drivers/perf/riscv_pmu.c > @@ -408,6 +408,7 @@ struct riscv_pmu *riscv_pmu_alloc(void) > cpuc->n_events = 0; > for (i = 0; i < RISCV_MAX_COUNTERS; i++) > cpuc->events[i] = NULL; > + cpuc->snapshot_addr = NULL; > } > pmu->pmu = (struct pmu) { > .event_init = riscv_pmu_event_init, > diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c > index f23501898657..e2881415ca0a 100644 > --- a/drivers/perf/riscv_pmu_sbi.c > +++ b/drivers/perf/riscv_pmu_sbi.c > @@ -58,6 +58,9 @@ PMU_FORMAT_ATTR(event, "config:0-47"); > PMU_FORMAT_ATTR(firmware, "config:63"); > > static bool sbi_v2_available; > +static DEFINE_STATIC_KEY_FALSE(sbi_pmu_snapshot_available); > +#define sbi_pmu_snapshot_available() \ > + static_branch_unlikely(&sbi_pmu_snapshot_available) > > static struct attribute *riscv_arch_formats_attr[] = { > &format_attr_event.attr, > @@ -508,14 +511,109 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig) > return ret; > } > > +static void pmu_sbi_snapshot_free(struct riscv_pmu *pmu) > +{ > + int cpu; > + > + for_each_possible_cpu(cpu) { > + struct cpu_hw_events *cpu_hw_evt = per_cpu_ptr(pmu->hw_events, cpu); > + > + if (!cpu_hw_evt->snapshot_addr) > + continue; > + > + free_page((unsigned long)cpu_hw_evt->snapshot_addr); > + cpu_hw_evt->snapshot_addr = NULL; > + cpu_hw_evt->snapshot_addr_phys = 0; > + } > +} > + > +static int pmu_sbi_snapshot_alloc(struct riscv_pmu *pmu) > +{ > + int cpu; > + struct page *snapshot_page; > + > + for_each_possible_cpu(cpu) { > + struct cpu_hw_events *cpu_hw_evt = per_cpu_ptr(pmu->hw_events, cpu); > + > + if (cpu_hw_evt->snapshot_addr) > + continue; > + > + snapshot_page = alloc_page(GFP_ATOMIC | __GFP_ZERO); > + if (!snapshot_page) { > + pmu_sbi_snapshot_free(pmu); > + return -ENOMEM; > + } > + cpu_hw_evt->snapshot_addr = page_to_virt(snapshot_page); > + cpu_hw_evt->snapshot_addr_phys = page_to_phys(snapshot_page); > + } > + > + return 0; > +} > + > +static int pmu_sbi_snapshot_disable(void) > +{ > + struct sbiret ret; > + > + ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_SNAPSHOT_SET_SHMEM, -1, > + -1, 0, 0, 0, 0); The SBI_SHMEM_DISABLE patch got moved in front of this patch, but looks like it was forgotten to apply it. Otherwise, Reviewed-by: Andrew Jones Thanks, drew