From nobody Sat Nov 23 23:21:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1728515416; cv=none; d=zohomail.com; s=zohoarc; b=JVDSpGjdPmXGEWNsmY0XqLhUw/D2QGG8i/az/VFhTlTIUveoY8qyP2NOfOgUq0i+o++MXfUl/RePhAS+cgeSyaQBj0JQsePUNS4kxAPxOT1/5LYSi/dFE8PcChk45S6N0fzSL4W7Tov9dVIpqGcOP12HYsYDKWubJwd9aWKZSM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728515416; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=L8GR17FkA/J/rE0TeH3ijOLU5RFbHn5ig8szCuUWCXw=; b=Ttas0xC6sXis+qrPKCNCsElscP99L8Ey0FHed4gB7HJNEdwXuSy1VTOGxnb+e+K08ZPlaYalZ8B2SKmB6F+OIYYZI/uO7/OZJHbOaqAYAMdhs8uX4gGMMKl1JaCXSUVVbvAcLVXHvoFuwbGBbF6ciQVJFRs02TzoMgGSQfZbE7I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728515416130740.3665809366356; Wed, 9 Oct 2024 16:10:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syfo6-000704-1r; Wed, 09 Oct 2024 19:09:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1syfny-0006qj-0v for qemu-devel@nongnu.org; Wed, 09 Oct 2024 19:09:18 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1syfnv-0000la-Qq for qemu-devel@nongnu.org; Wed, 09 Oct 2024 19:09:17 -0400 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-7db637d1e4eso212617a12.2 for ; Wed, 09 Oct 2024 16:09:15 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e2a55f9855sm2271902a91.2.2024.10.09.16.09.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 16:09:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1728515354; x=1729120154; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=L8GR17FkA/J/rE0TeH3ijOLU5RFbHn5ig8szCuUWCXw=; b=0/bWMC6PhJIZAFlBBG3S+/gnIqEAK8JfPRqz8gO1WF1IaZ736Uw1aFcJIsem9QFXo9 T0T9RiqOrD1IojgG94EkaFAYeVuAITvfuIuqXujwEP5QlOBpjV6g1GN38AT8h45e8+rG XQvQoERT08752l3sdRynHg6wbSXKLCLS2bJNSucMnPO3uQKApcABHv9HVZA+gbJwZzT/ v47En+XxSi7pp5sXWpwzQdspv5jw5rik0ncerEkWvHd9C3ErD8TTOD1j+5zzz2fSZwFZ bwoWw7MDxwr1J3u5Bb5txvU1giFOq2vIbJCCg8809sdHMg2uAtzQ4GRyHwYBllw9Zx1Q J7Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728515354; x=1729120154; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=L8GR17FkA/J/rE0TeH3ijOLU5RFbHn5ig8szCuUWCXw=; b=aMLeKrrtLfaGOEqPdN28i55RfTfSFUqJofawBXIDeZO+7GnBO6uAlPIkAKMC2fsAfV ug08mGsthB04ZwQfNvAtMkGW0VVRsaSl52gvBW2VZIOTlyesuj2Q6ZXODj/lWx6vTJd3 EZGwzA62MUxn0J5BKgAFkB4wVL1WJVvRclDpZpQ81lXWZnZ+KHiTAIMpNRRp0/BmiASu usI3x9K2IrpUqT2YR1VdEJOchK822L2/Hd48pQ/Ae7naxsPfIdwdngnQIwyPHQ+pD57X vJu4/El9uznNfNN6OKlienEwkHhyQcwYu70neOT2pm7yuJ9AWpB0X6HLP6cxDwpcrHr1 sY9A== X-Forwarded-Encrypted: i=1; AJvYcCUkaySYqaC1vJhnc3OhOJ1GAhe1tMdQsSwwQUM521elWwsDS7qNaQKgFwwdpZFrb5u/lmO3Nws1CDj3@nongnu.org X-Gm-Message-State: AOJu0YycNiOn4Cuc1UVTfHGrZeICKpg3LE7InI8oC26i2G9wmrwV0wnp VtFLwOPdYk9HcFBPJ+GvPV7O8UPCp0Jd3ROtVXy5oTP8rfKl11G17yZ0Q3VVv3M= X-Google-Smtp-Source: AGHT+IHFAMKMTnnh/U4UHESQK6oc/WZEZOVnpf1VVRMpXWVSlJD3Um1gLpxj94jXPehRT9G6t6bU7w== X-Received: by 2002:a17:90a:c481:b0:2d8:82a2:b093 with SMTP id 98e67ed59e1d1-2e2a23303bdmr5244579a91.13.1728515354513; Wed, 09 Oct 2024 16:09:14 -0700 (PDT) From: Atish Patra Date: Wed, 09 Oct 2024 16:09:08 -0700 Subject: [PATCH RFC 10/10] hw/riscv/virt.c: Generate the PMU node from the machine MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241009-pmu_event_machine-v1-10-dcbd7a60e3ba@rivosinc.com> References: <20241009-pmu_event_machine-v1-0-dcbd7a60e3ba@rivosinc.com> In-Reply-To: <20241009-pmu_event_machine-v1-0-dcbd7a60e3ba@rivosinc.com> To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: alexei.filippov@syntacore.com, Atish Patra , palmer@dabbelt.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, bin.meng@windriver.com, dbarboza@ventanamicro.com, alistair.francis@wdc.com X-Mailer: b4 0.15-dev-13183 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=atishp@rivosinc.com; helo=mail-pg1-x52f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1728515417220116600 The virt machine implementation relies on the SBI PMU extension. The OpenSBI implementation requires a PMU specific DT node that is currently encodes the counter and PMU events mapping. As the PMU DT node encodes the platform specific event encodings, it should be implement in platform specific code instead of generic PMU code. Move the PMU DT node generation code from virt.c from common pmu code. Signed-off-by: Atish Patra --- hw/riscv/virt.c | 21 +++++++++++++++++++-- target/riscv/pmu.c | 36 ------------------------------------ target/riscv/pmu.h | 1 - 3 files changed, 19 insertions(+), 39 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index ffda6d65d673..056afe6a6ceb 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -792,11 +792,28 @@ static void create_fdt_pmu(RISCVVirtState *s) { g_autofree char *pmu_name =3D g_strdup_printf("/pmu"); MachineState *ms =3D MACHINE(s); - RISCVCPU hart =3D s->soc[0].harts[0]; + uint32_t fdt_event_ctr_map[15] =3D {}; + int i; =20 qemu_fdt_add_subnode(ms->fdt, pmu_name); qemu_fdt_setprop_string(ms->fdt, pmu_name, "compatible", "riscv,pmu"); - riscv_pmu_generate_fdt_node(ms->fdt, hart.pmu_avail_ctrs, pmu_name); + + /* + * To keep it simple, any event can be mapped to any programmable coun= ters + * in QEMU. The generic cycle & instruction count events can also be + * monitored using programmable counters. In that case, mcycle & minst= ret + * must continue to provide the correct value as well. Heterogeneous P= MU per + * hart is not supported yet. Thus, number of counters are same across= all + * harts. + */ + for (i =3D 0; i < ARRAY_SIZE(pmu_events_arr); i++) { + fdt_event_ctr_map[0 + i * 3] =3D cpu_to_be32(pmu_events_arr[i].eve= nt_id); + fdt_event_ctr_map[1 + i * 3] =3D cpu_to_be32(pmu_events_arr[i].eve= nt_id); + fdt_event_ctr_map[2 + i * 3] =3D cpu_to_be32(pmu_events_arr[i].cou= nter_mask); + } + /* This a OpenSBI specific DT property documented in OpenSBI docs */ + qemu_fdt_setprop(ms->fdt, pmu_name, "riscv,event-to-mhpmcounters", + fdt_event_ctr_map, sizeof(fdt_event_ctr_map)); } =20 static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memma= p, diff --git a/target/riscv/pmu.c b/target/riscv/pmu.c index e80f0f911fa3..dd0a18ae3dc1 100644 --- a/target/riscv/pmu.c +++ b/target/riscv/pmu.c @@ -27,42 +27,6 @@ =20 #define RISCV_TIMEBASE_FREQ 1000000000 /* 1Ghz */ =20 -/* - * To keep it simple, any event can be mapped to any programmable counters= in - * QEMU. The generic cycle & instruction count events can also be monitored - * using programmable counters. In that case, mcycle & minstret must conti= nue - * to provide the correct value as well. Heterogeneous PMU per hart is not - * supported yet. Thus, number of counters are same across all harts. - */ -void riscv_pmu_generate_fdt_node(void *fdt, uint32_t cmask, char *pmu_name) -{ - uint32_t fdt_event_ctr_map[15] =3D {}; - - fdt_event_ctr_map[0] =3D cpu_to_be32(VIRT_PMU_EVENT_HW_CPU_CYCLES); - fdt_event_ctr_map[1] =3D cpu_to_be32(VIRT_PMU_EVENT_HW_CPU_CYCLES); - fdt_event_ctr_map[2] =3D cpu_to_be32(cmask | 1 << 0); - - fdt_event_ctr_map[3] =3D cpu_to_be32(VIRT_PMU_EVENT_HW_INSTRUCTIONS); - fdt_event_ctr_map[4] =3D cpu_to_be32(VIRT_PMU_EVENT_HW_INSTRUCTIONS); - fdt_event_ctr_map[5] =3D cpu_to_be32(cmask | 1 << 2); - - fdt_event_ctr_map[6] =3D cpu_to_be32(VIRT_PMU_EVENT_CACHE_DTLB_READ_MIS= S); - fdt_event_ctr_map[7] =3D cpu_to_be32(VIRT_PMU_EVENT_CACHE_DTLB_READ_MIS= S); - fdt_event_ctr_map[8] =3D cpu_to_be32(cmask); - - fdt_event_ctr_map[9] =3D cpu_to_be32(VIRT_PMU_EVENT_CACHE_DTLB_WRITE_MI= SS); - fdt_event_ctr_map[10] =3D cpu_to_be32(VIRT_PMU_EVENT_CACHE_DTLB_WRITE_M= ISS); - fdt_event_ctr_map[11] =3D cpu_to_be32(cmask); - - fdt_event_ctr_map[12] =3D cpu_to_be32(VIRT_PMU_EVENT_CACHE_ITLB_PREFETC= H_MISS); - fdt_event_ctr_map[13] =3D cpu_to_be32(VIRT_PMU_EVENT_CACHE_ITLB_PREFETC= H_MISS); - fdt_event_ctr_map[14] =3D cpu_to_be32(cmask); - - /* This a OpenSBI specific DT property documented in OpenSBI docs */ - qemu_fdt_setprop(fdt, pmu_name, "riscv,event-to-mhpmcounters", - fdt_event_ctr_map, sizeof(fdt_event_ctr_map)); -} - static bool riscv_pmu_counter_valid(RISCVCPU *cpu, uint32_t ctr_idx) { if (ctr_idx < 3 || ctr_idx >=3D RV_MAX_MHPMCOUNTERS || diff --git a/target/riscv/pmu.h b/target/riscv/pmu.h index 810ac2fae797..10505040d9e5 100644 --- a/target/riscv/pmu.h +++ b/target/riscv/pmu.h @@ -31,7 +31,6 @@ void riscv_pmu_init(RISCVCPU *cpu, Error **errp); int riscv_pmu_update_event_map(CPURISCVState *env, uint64_t value, uint32_t ctr_idx); int riscv_pmu_incr_ctr(RISCVCPU *cpu, uint64_t event_idx); -void riscv_pmu_generate_fdt_node(void *fdt, uint32_t cmask, char *pmu_name= ); int riscv_pmu_setup_timer(CPURISCVState *env, uint64_t value, uint32_t ctr_idx); void riscv_pmu_update_fixed_ctrs(CPURISCVState *env, target_ulong newpriv, --=20 2.34.1