From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 5DB217351A for ; Mon, 15 Apr 2024 13:15:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713186918; cv=none; b=Mf+ET4FesFbgNuBStoIiae/AVPww0IP/2X6O2N6pxuw1hOhv01MTtAdP689p6s/PZFl9N59uy0umJ5SX2tWDQqL3sE+Hr9OGbwftuvlXTUobdYilXjYc/d8PFQZM7wMLQ6zEOWRUC2BYKVgDdOMgfuU+PGBUuzceZCpDVC80Xvw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713186918; 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=fDCxO35tbovxD6PkTS4cacoz76w96ZPINaENlBud3rnmA9lsOQLQY9TbBevxyT6RBrCezpxI3p0iJvv+nGc7FkwyimIRTN6SASAb5G3hBXjwLRitlHoA9fkIdzWR3lAGP8iYP0vcDFD0U/0Mj4DPaNt+srReNNYPt72KGmi7ATk= 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.50 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="bugntPOs" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-41881bce2a8so748985e9.0 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=KK9AJPij16dG1BJ/3VUO+SJm2wWtKku2JtR0kr9/noB78kpoTff82DPFA4hKlF1tNj XrwV6u9uSmMGL+BckRRZiXXe7D+ignnQfzdoqWywxrX93/KIIPGEfkT81+I8afJPiGM+ SHykZdYZeIBxilbL1r7nC5sxJ8YJWnPwH6WYFBhi3c36wskPqalBK0fcXG3DvMP9GBb7 /ekDFw7jJw9wWsEkT7qdY2paoXoP/rY8tXuMtu20fMLiBfHOOVaCx4E6IMqD6+tgyBf7 OdUG0D4Ylxg/Qyer0e48sXssHfUuaCIJNntGUn/516zYaIzfdTQwOHByilHraJxqycdC kYIQ== X-Forwarded-Encrypted: i=1; AJvYcCXOuLCMXYO/vwx6Qa15F9mHVLTuf59oEr2JY8/7WA1E7Okod68KbQQuuNxziyk3zTNs+qhjJX2tiUnRp02lMh67oPR3AUZjOgDiwBWACmSi X-Gm-Message-State: AOJu0YwwC+YDA2WKC7Dck/u6AomHz+Ahk4RefY7rABKGfkuXhBO+0o1L CZnZ1yakzJ54oaaniRlvmePlRHT+NfjkhjTmxjDBIQIv6ijmi9f1oXAnkgF72pY= X-Google-Smtp-Source: AGHT+IHaN+91KLEi7R/RxmtZuQH0jSX9Ui8qFAfF8HKSuojq26EX0a+2rvsHFXS88Kq+hml8I98gaQ== 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-kselftest@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