From patchwork Sat Feb 17 00:57:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C7291C48BF5 for ; Sat, 17 Feb 2024 00:58:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=c4Dh2YuHbWsv0kZhIEcXIgLuf9uorR4TWFs4BI8ozCw=; b=SODlSHanXoEZ8N /34Ej8EDw+4pC9c4pvlaJAHiRi6CZU2+NFPPhfMlHP8ANrLAeTZhkhInueNPqkPRhbeA8RlBOGMac +J2vinZHmmciyb6tIcyp+zfh7u3MdaptMgOT4NcNfpVPBGwFH35/beWmVBCmAXKk4UpUIxDgINk0F 3mPy6nhOnisg3RArbyKz/sj3HkkcioDgLWGLFDdDwb3KWLOETjxF8G2ZdpQm5y7JfmLJx9a5TS+tv oWfbtS7LrOgCQ6G1qlXH1mkXR70ksdonr7H0yzv9AhMoKYEqAcotQf1tH/Dz67ypE7W+OUTJap4tK /FebSzbHgqowdZJlz4Cw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb926-00000004Hw8-1rTI; Sat, 17 Feb 2024 00:58:22 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb921-00000004Hsc-2J9G for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:58:20 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6e08dd0c7eeso1674125b3a.1 for ; Fri, 16 Feb 2024 16:58:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131496; x=1708736296; darn=lists.infradead.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=GdfDilW9Nk9gfAD8OoYJZ+QpUc7BOx+f1kYB5V55j2o=; b=CaO1RqaI+ixz0MS7kSJ3Gp74S+fdesjOLJJOtEvlkAP1Qgj1BPW83bQokl5L/shX6k 5XoB4LOb/kRqF/LVlUjUv0gXVEUh89jbhRCUB5o5xsED9v2QOjmCRN7QdAO0fZ7FbFtn 1Ih1N/ZW1HG0QZxMDXa2hN8Yd6AMIjkCOx1CKNngqR7vn/DSb6TTdKK7KTydBDilmW3z l6EBqNii7iKolgsQGbmVBLQwEeND+z94wLvEPTaxAS/Xc1qnICTRTtK5LxWhF8hyupNl X8ADuyO64mGjjaux+09djX3xbKbZXpAJXWlg7pThB/srb7TYDFkY6/LDWLCeoazeGr28 hOXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131496; x=1708736296; 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=GdfDilW9Nk9gfAD8OoYJZ+QpUc7BOx+f1kYB5V55j2o=; b=ZlRZIYgcs904VA23BKHyepaWIHwaMmXQ5FZDsKtVatLoCnS6x5fApByk6M4NlFroem iOfCBsr8yMwnELHoxLaXA5a+tdRceq4Yb9+Q2/7sW//42kSaakNjeao92N0DRt9CXdw0 qTPgCsPqgS/ZjPuq+o23IrpUnG+wFEFfHqgM4QKBkY+Mf6oQqm63odTKflJlfR9kzSU8 a+ZJg/cHM4EnGM4VnzVhGWayFWtx2ZLElDRwctjs4UmjmVAjvXp5E6bAjGinPLJ0xtwl sCvs2qo+ChSG9VnH2chyW6ezZXrzOMf/CDPe5Rvr1dn+xhC0LO7lUteKGZpdO8rHr5wt OOOg== X-Forwarded-Encrypted: i=1; AJvYcCWVjNTX6C7umst1M/8kpkRoAA+WLm6vgOfaHPwA0x4d+Xndak75NLz1avVj1EMmW/567kcsio839HUPoKpxz0nIKTKsf5HkbWopIbvT0ldn X-Gm-Message-State: AOJu0Ywzbynk/iyBxOzodoK5wXR4dWFCqAzQtL2AnJjy1HyS9rPBdYqN vG2yzXL4vIUZ+GojFj4AAWjCqAsFOrRtr1cWFhaaJuIw4zUo9g/qeUPOVtkt7mg= X-Google-Smtp-Source: AGHT+IEl08bugsJqJeah6DEdUtuymO07lUypuObDizLTwR5dLnoGamWdEPgOUAV2oyVt0BHvppithQ== X-Received: by 2002:a05:6a00:928c:b0:6e1:4354:ae59 with SMTP id jw12-20020a056a00928c00b006e14354ae59mr3089434pfb.29.1708131496341; Fri, 16 Feb 2024 16:58:16 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:15 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 01/20] perf pmu-events: Add functions in jevent.py to parse counter and event info for hardware aware grouping Date: Fri, 16 Feb 2024 16:57:19 -0800 Message-Id: <20240217005738.3744121-2-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165817_744875_79F3ABC3 X-CRM114-Status: GOOD ( 25.97 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Weilin Wang These functions are added to parse event counter restrictions and counter availability info from json files so that the metric grouping method could do grouping based on the counter restriction of events and the counters that are available on the system. Signed-off-by: Weilin Wang --- tools/perf/pmu-events/jevents.py | 171 ++++++++++++++++++++++++++++- tools/perf/pmu-events/pmu-events.h | 25 ++++- 2 files changed, 188 insertions(+), 8 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 53ab050c8fa4..81e465a43c75 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -23,6 +23,8 @@ _metric_tables = [] _sys_metric_tables = [] # Mapping between sys event table names and sys metric table names. _sys_event_table_to_metric_table_mapping = {} +# List of regular PMU counter layout tables. +_pmu_layouts_tables = [] # Map from an event name to an architecture standard # JsonEvent. Architecture standard events are in json files in the top # f'{_args.starting_dir}/{_args.arch}' directory. @@ -31,6 +33,9 @@ _arch_std_events = {} _pending_events = [] # Name of events table to be written out _pending_events_tblname = None +# PMU counter layout to write out when the table is closed +_pending_pmu_counts = [] # Name of PMU counter layout table to be written out +_pending_pmu_counts_tblname = None # Metrics to write out when the table is closed _pending_metrics = [] # Name of metrics table to be written out @@ -47,10 +52,17 @@ _json_event_attributes = [ 'event', # Short things in alphabetical order. 'compat', 'deprecated', 'perpkg', 'unit', + # Counter this event could use + 'counter', # Longer things (the last won't be iterated over during decompress). 'long_desc' ] +# Attributes that are in pmu_unit_layout. +_json_layout_attributes = [ + 'pmu', 'desc', 'size', 'fixed_size' +] + # Attributes that are in pmu_metric rather than pmu_event. _json_metric_attributes = [ 'metric_name', 'metric_group', 'metric_expr', 'metric_threshold', @@ -58,7 +70,9 @@ _json_metric_attributes = [ 'default_metricgroup_name', 'aggr_mode', 'event_grouping' ] # Attributes that are bools or enum int values, encoded as '0', '1',... -_json_enum_attributes = ['aggr_mode', 'deprecated', 'event_grouping', 'perpkg'] +_json_enum_attributes = ['aggr_mode', 'deprecated', 'event_grouping', 'perpkg', + 'size', 'fixed_size' +] def removesuffix(s: str, suffix: str) -> str: """Remove the suffix from a string @@ -317,6 +331,9 @@ class JsonEvent: if 'Errata' in jd: extra_desc += ' Spec update: ' + jd['Errata'] self.pmu = unit_to_pmu(jd.get('Unit')) + self.counter = jd.get('Counter') + self.size = jd.get('Size') + self.fixed_size = jd.get('FixedSize') filter = jd.get('Filter') self.unit = jd.get('ScaleUnit') self.perpkg = jd.get('PerPkg') @@ -388,8 +405,16 @@ class JsonEvent: s += f'\t{attr} = {value},\n' return s + '}' - def build_c_string(self, metric: bool) -> str: + def build_c_string(self, metric: bool, layout: bool = False) -> str: s = '' + if layout: + for attr in _json_layout_attributes: + x = getattr(self, attr) + if attr in _json_enum_attributes: + s += x if x else '0' + else: + s += f'{x}\\000' if x else '\\000' + return s for attr in _json_metric_attributes if metric else _json_event_attributes: x = getattr(self, attr) if metric and x and attr == 'metric_expr': @@ -404,10 +429,10 @@ class JsonEvent: s += f'{x}\\000' if x else '\\000' return s - def to_c_string(self, metric: bool) -> str: + def to_c_string(self, metric: bool, layout: bool = False) -> str: """Representation of the event as a C struct initializer.""" - s = self.build_c_string(metric) + s = self.build_c_string(metric, layout) return f'{{ { _bcs.offsets[s] } }}, /* {s} */\n' @@ -444,6 +469,8 @@ def preprocess_arch_std_files(archpath: str) -> None: _arch_std_events[event.name.lower()] = event if event.metric_name: _arch_std_events[event.metric_name.lower()] = event + if event.size: + _arch_std_events[event.pmu.lower()] = event def add_events_table_entries(item: os.DirEntry, topic: str) -> None: @@ -453,6 +480,8 @@ def add_events_table_entries(item: os.DirEntry, topic: str) -> None: _pending_events.append(e) if e.metric_name: _pending_metrics.append(e) + if e.size: + _pending_pmu_counts.append(e) def print_pending_events() -> None: @@ -566,6 +595,33 @@ const struct pmu_table_entry {_pending_metrics_tblname}[] = {{ """) _args.output_file.write('};\n\n') +def print_pending_pmu_counts() -> None: + + def pmu_counts_cmp_key(j: JsonEvent) -> Tuple[bool, str, str]: + def fix_none(s: Optional[str]) -> str: + if s is None: + return '' + return s + + return (j.desc is not None, fix_none(j.pmu), fix_none(j.size)) + + global _pending_pmu_counts + if not _pending_pmu_counts: + return + + global _pending_pmu_counts_tblname + global pmu_layouts_tables + _pmu_layouts_tables.append(_pending_pmu_counts_tblname) + + _args.output_file.write( + f'static const struct compact_pmu_event {_pending_pmu_counts_tblname}[] = {{\n') + + for pmu_layout in sorted(_pending_pmu_counts, key=pmu_counts_cmp_key): + _args.output_file.write(pmu_layout.to_c_string(metric=False, layout=True)) + _pending_pmu_counts = [] + + _args.output_file.write('};\n\n') + def get_topic(topic: str) -> str: if topic.endswith('metrics.json'): return 'metrics' @@ -606,6 +662,8 @@ def preprocess_one_file(parents: Sequence[str], item: os.DirEntry) -> None: if event.metric_name: _bcs.add(pmu_name, metric=True) _bcs.add(event.build_c_string(metric=True), metric=True) + if event.size: + _bcs.add(event.build_c_string(metric=False, layout=True), metric=False) def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None: """Process a JSON file during the main walk.""" @@ -619,11 +677,14 @@ def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None: if item.is_dir() and is_leaf_dir(item.path): print_pending_events() print_pending_metrics() + print_pending_pmu_counts() global _pending_events_tblname _pending_events_tblname = file_name_to_table_name('pmu_events_', parents, item.name) global _pending_metrics_tblname _pending_metrics_tblname = file_name_to_table_name('pmu_metrics_', parents, item.name) + global _pending_pmu_counts_tblname + _pending_pmu_counts_tblname = file_name_to_table_name('pmu_layouts_', parents, item.name) if item.name == 'sys': _sys_event_table_to_metric_table_mapping[_pending_events_tblname] = _pending_metrics_tblname @@ -657,6 +718,12 @@ struct pmu_metrics_table { uint32_t num_pmus; }; +/* Struct used to make the PMU counter layout table implementation opaque to callers. */ +struct pmu_layouts_table { + const struct compact_pmu_event *entries; + size_t length; +}; + /* * Map a CPU to its table of PMU events. The CPU is identified by the * cpuid field, which is an arch-specific identifier for the CPU. @@ -670,6 +737,7 @@ struct pmu_events_map { const char *cpuid; struct pmu_events_table event_table; struct pmu_metrics_table metric_table; + struct pmu_layouts_table layout_table; }; /* @@ -714,6 +782,12 @@ const struct pmu_events_map pmu_events_map[] = { metric_size = '0' if event_size == '0' and metric_size == '0': continue + layout_tblname = file_name_to_table_name('pmu_layouts_', [], row[2].replace('/', '_')) + if layout_tblname in _pmu_layouts_tables: + layout_size = f'ARRAY_SIZE({layout_tblname})' + else: + layout_tblname = 'NULL' + layout_size = '0' cpuid = row[0].replace('\\', '\\\\') _args.output_file.write(f"""{{ \t.arch = "{arch}", @@ -725,6 +799,10 @@ const struct pmu_events_map pmu_events_map[] = { \t.metric_table = {{ \t\t.pmus = {metric_tblname}, \t\t.num_pmus = {metric_size} +\t}}, +\t.layout_table = {{ +\t\t.entries = {layout_tblname}, +\t\t.length = {layout_size} \t}} }}, """) @@ -735,6 +813,7 @@ const struct pmu_events_map pmu_events_map[] = { \t.cpuid = 0, \t.event_table = { 0, 0 }, \t.metric_table = { 0, 0 }, +\t.layout_table = { 0, 0 }, } }; """) @@ -823,6 +902,24 @@ static void decompress_metric(int offset, struct pmu_metric *pm) _args.output_file.write('\twhile (*p++);') _args.output_file.write("""} +static void decompress_layout(int offset, struct pmu_layout *pm) +{ +\tconst char *p = &big_c_string[offset]; +""") + for attr in _json_layout_attributes: + _args.output_file.write(f'\n\tpm->{attr} = ') + if attr in _json_enum_attributes: + _args.output_file.write("*p - '0';\n") + else: + _args.output_file.write("(*p == '\\0' ? NULL : p);\n") + if attr == _json_layout_attributes[-1]: + continue + if attr in _json_enum_attributes: + _args.output_file.write('\tp++;') + else: + _args.output_file.write('\twhile (*p++);') + _args.output_file.write("""} + static int pmu_events_table__for_each_event_pmu(const struct pmu_events_table *table, const struct pmu_table_entry *pmu, pmu_event_iter_fn fn, @@ -978,6 +1075,21 @@ int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, return 0; } +int pmu_layouts_table__for_each_layout(const struct pmu_layouts_table *table, + pmu_layout_iter_fn fn, + void *data) { + for (size_t i = 0; i < table->length; i++) { + struct pmu_layout pm; + int ret; + + decompress_layout(table->entries[i].offset, &pm); + ret = fn(&pm, data); + if (ret) + return ret; + } + return 0; +} + static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) { static struct { @@ -1073,6 +1185,33 @@ const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu *pm return NULL; } +const struct pmu_layouts_table *perf_pmu__find_layouts_table(struct perf_pmu *pmu) +{ + const struct pmu_layouts_table *table = NULL; + char *cpuid = perf_pmu__getcpuid(pmu); + int i; + + /* on some platforms which uses cpus map, cpuid can be NULL for + * PMUs other than CORE PMUs. + */ + if (!cpuid) + return NULL; + + i = 0; + for (;;) { + const struct pmu_events_map *map = &pmu_events_map[i++]; + if (!map->arch) + break; + + if (!strcmp_cpuid_str(map->cpuid, cpuid)) { + table = &map->layout_table; + break; + } + } + free(cpuid); + return table; +} + const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid) { for (const struct pmu_events_map *tables = &pmu_events_map[0]; @@ -1094,6 +1233,16 @@ const struct pmu_metrics_table *find_core_metrics_table(const char *arch, const } return NULL; } +const struct pmu_layouts_table *find_core_layouts_table(const char *arch, const char *cpuid) +{ + for (const struct pmu_events_map *tables = &pmu_events_map[0]; + tables->arch; + tables++) { + if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid)) + return &tables->layout_table; + } + return NULL; +} int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data) { @@ -1122,6 +1271,19 @@ int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data) return 0; } +int pmu_for_each_core_layout(pmu_layout_iter_fn fn, void *data) +{ + for (const struct pmu_events_map *tables = &pmu_events_map[0]; + tables->arch; + tables++) { + int ret = pmu_layouts_table__for_each_layout(&tables->layout_table, fn, data); + + if (ret) + return ret; + } + return 0; +} + const struct pmu_events_table *find_sys_events_table(const char *name) { for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; @@ -1278,6 +1440,7 @@ struct pmu_table_entry { ftw(arch_path, [], process_one_file) print_pending_events() print_pending_metrics() + print_pending_pmu_counts() print_mapping_table(archs) print_system_mapping_table() diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index f5aa96f1685c..65e0c5dd8bb4 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -45,6 +45,7 @@ struct pmu_event { const char *desc; const char *topic; const char *long_desc; + const char *counter; const char *pmu; const char *unit; bool perpkg; @@ -67,8 +68,16 @@ struct pmu_metric { enum metric_event_groups event_grouping; }; +struct pmu_layout { + const char *pmu; + const char *desc; + int size; + int fixed_size; +}; + struct pmu_events_table; struct pmu_metrics_table; +struct pmu_layouts_table; typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe, const struct pmu_events_table *table, @@ -78,15 +87,20 @@ typedef int (*pmu_metric_iter_fn)(const struct pmu_metric *pm, const struct pmu_metrics_table *table, void *data); +typedef int (*pmu_layout_iter_fn)(const struct pmu_layout *pm, + void *data); + int pmu_events_table__for_each_event(const struct pmu_events_table *table, struct perf_pmu *pmu, pmu_event_iter_fn fn, void *data); int pmu_events_table__find_event(const struct pmu_events_table *table, - struct perf_pmu *pmu, - const char *name, - pmu_event_iter_fn fn, - void *data); + struct perf_pmu *pmu, + const char *name, + pmu_event_iter_fn fn, + void *data); +int pmu_layouts_table__for_each_layout(const struct pmu_layouts_table *table, pmu_layout_iter_fn fn, + void *data); size_t pmu_events_table__num_events(const struct pmu_events_table *table, struct perf_pmu *pmu); @@ -95,10 +109,13 @@ int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, pm const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu); const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu); +const struct pmu_layouts_table *perf_pmu__find_layouts_table(struct perf_pmu *pmu); const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid); const struct pmu_metrics_table *find_core_metrics_table(const char *arch, const char *cpuid); +const struct pmu_layouts_table *find_core_layouts_table(const char *arch, const char *cpuid); int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data); int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data); +int pmu_for_each_core_layout(pmu_layout_iter_fn fn, void *data); const struct pmu_events_table *find_sys_events_table(const char *name); const struct pmu_metrics_table *find_sys_metrics_table(const char *name); From patchwork Sat Feb 17 00:57:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561198 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EBAF5C48260 for ; Sat, 17 Feb 2024 02:03:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=oIPD3gszHris/W8e4l361NhIE3tjGqLpE93lG8mqb0s=; b=wH4qnCQRGSky6P lc1Si1ZE7GSgnyGmivWK5bUcMGRmri7z63nHcVv3Ax7GXG1I9I/L6jMdiyNWq69V0LGmt+uP0ZEVU cUxfaADdabKgXd49Kh58UtVe/qEco0cnZELmJPZd0ijnoTHshJXkxoI/7N1B2Y2gcDZeStnhIW45i J54g9vQsfF9RH4VD5VwsWrxAV0GO1EO9BxHkCxI+2ROVZv/4eLfxgt6sSZUXbzTxNzYPEr08XA2Or hzl1eHFd3GMKjtxM/BLGYQAfoMIz3lmgsnGUcaXFndXPQ7aQGjNqr1si1DiVPpoAz1S40C3seEDtw CYnSd25L7xLfv6dr3+IQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbA3S-00000004SAP-2Xjz; Sat, 17 Feb 2024 02:03:50 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92Z-00000004INL-3Tkq for linux-riscv@bombadil.infradead.org; Sat, 17 Feb 2024 00:58:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=aQNMm6dQ5GKoaAsA3+Ylkhz7wa/7Q2Lc0P2/ZDz1Yac=; b=I5OGKjLc58wMFQIKJa8Y5jeO79 59tnnMftsIFG66YffiSmGukhWjN+wnjh79fqR3Mf5AmWAzVVqvzov0XwE7ZAjeTglFlRzQQvSU+c5 vEkV/uN6w56iOMiogm8pwF/hblQibELo0nrVwnSdoRxFvJVYSNUvKtxq6u3cqieEw9P7YZg5fZSsq WenAei3icBFMxqU/o6o6QBbfovyFKrgVpqcW6HfOc2tcYVzwiIxZOLR1yaCxdb89yoiHP+EBsMeOq ELmBofKt3tSFqTAxVrQi3sN94UoZlczJEtC5y6Ua6Gllh3uerQPv/ShqTUL2S1G7lVr3nCq1Zxoxw qAo6QHFw==; Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb926-000000007H4-1q0F for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:58:45 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6e08dd0fa0bso2239300b3a.1 for ; Fri, 16 Feb 2024 16:58:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131499; x=1708736299; darn=lists.infradead.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=aQNMm6dQ5GKoaAsA3+Ylkhz7wa/7Q2Lc0P2/ZDz1Yac=; b=05DpMZXYxwex0tvTfd/IInF87FyE3QDfwYni1ypaCnSGSwhSJcyip1mbHWiTT2qFdc ztSY2qJfWP0geENmsDrRgq8DOBDmNzW4CRv9rIMJ70wcILFPZcBAiJU/VsVfrgkavzZZ w1yqAqveNOmtCQHFxpUnvjunFE+6Dm3Y9xaHOGCcy8SFI+79HlMvt6+Xjhp9MCpH5giE HzIuj5d0KwLEZd2Xnr+YAq9wHNWnj9q1SMnZQHLBeXBPwFUtKLknmvA3LzGg0Fn/Lb4H nOXX9sgQs3kG636FesJE/DeM7sH+Tlbywdu8QjstbJE8xLmfcQpdDyJnfJzUzNHK0oTg bPvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131499; x=1708736299; 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=aQNMm6dQ5GKoaAsA3+Ylkhz7wa/7Q2Lc0P2/ZDz1Yac=; b=O7IslJZAnyNIvpInRjeylz565LY+9FNXc7RnE181xkHHN6EQUaqQSO2sPj03ZZPhqO kDRXOYg/H9JRSMj3a8GXG49VV8xrURBY0gBT5l8rJhMYmU93nRonpFYtf9MvsxrFvLH7 kHp7iE9EjcLN8pnRkYigPEIb0AjbJkzHfjC18+tJRGHA0ebXfYjGHODl/bt2+kaEHH5q FMKp0VCB5AkgQ87/SGq2dqW8KKgJY2JQNULW8RkOysy0+S+b7eQbmzUR079x9V/rD0cA pSKT6/Ax3NcPX5knhHPL4otLtQyyDA/4AkShXcnp+6V7WXlVSyjAdGE9Rt9+c4tLDIJr y18w== X-Forwarded-Encrypted: i=1; AJvYcCVQA58qrUJASLYFsAva8UyYGypaDwPYzK7rmYoo/xberwlL0yJBKRKjxq/68ZCsws79pajMtjGIXstAi50wXPSluW1fC8DN1/YcTTUauEcX X-Gm-Message-State: AOJu0Yzw2LL97eSubQP8gDGD4AaFfJiT39BTPydcMmCUCclsN054JHHk vRsReQFqg1aUs8COINXVHHU5OA+Cy/szxDerNeJoNct6Lh94dJMqphTAJVHfJqg= X-Google-Smtp-Source: AGHT+IHBAccR7wewW50qDb/5Fg2zOt9vMTs18qGTYlJw9BsFoZL8lyrT4M/cgU7xwOtlRTzAVrdVuQ== X-Received: by 2002:a05:6a00:2451:b0:6e0:50cb:5f0a with SMTP id d17-20020a056a00245100b006e050cb5f0amr13240534pfj.12.1708131499011; Fri, 16 Feb 2024 16:58:19 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:18 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 02/20] RISC-V: Add Sxcsrind ISA extension CSR definitions Date: Fri, 16 Feb 2024 16:57:20 -0800 Message-Id: <20240217005738.3744121-3-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240217_005823_235501_485E08A0 X-CRM114-Status: GOOD ( 10.33 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Kaiwen Xue This adds definitions of new CSRs and bits defined in Sxcsrind ISA extension. These CSR enables indirect accesses mechanism to access any CSRs in M-, S-, and VS-mode. The range of the select values and ireg will be define by the ISA extension using Sxcsrind extension. Signed-off-by: Kaiwen Xue Signed-off-by: Atish Patra --- arch/riscv/include/asm/csr.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 510014051f5d..0a54856fd807 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -302,6 +302,12 @@ /* Supervisor-Level Window to Indirectly Accessed Registers (AIA) */ #define CSR_SISELECT 0x150 #define CSR_SIREG 0x151 +/* Supervisor-Level Window to Indirectly Accessed Registers (Sxcsrind) */ +#define CSR_SIREG2 0x152 +#define CSR_SIREG3 0x153 +#define CSR_SIREG4 0x155 +#define CSR_SIREG5 0x156 +#define CSR_SIREG6 0x157 /* Supervisor-Level Interrupts (AIA) */ #define CSR_STOPEI 0x15c @@ -349,6 +355,14 @@ /* VS-Level Window to Indirectly Accessed Registers (H-extension with AIA) */ #define CSR_VSISELECT 0x250 #define CSR_VSIREG 0x251 +/* + * VS-Level Window to Indirectly Accessed Registers (H-extension with Sxcsrind) + */ +#define CSR_VSIREG2 0x252 +#define CSR_VSIREG3 0x253 +#define CSR_VSIREG4 0x255 +#define CSR_VSIREG5 0x256 +#define CSR_VISREG6 0x257 /* VS-Level Interrupts (H-extension with AIA) */ #define CSR_VSTOPEI 0x25c @@ -389,6 +403,12 @@ /* Machine-Level Window to Indirectly Accessed Registers (AIA) */ #define CSR_MISELECT 0x350 #define CSR_MIREG 0x351 +/* Machine-Level Window to Indrecitly Accessed Registers (Sxcsrind) */ +#define CSR_MIREG2 0x352 +#define CSR_MIREG3 0x353 +#define CSR_MIREG4 0x355 +#define CSR_MIREG5 0x356 +#define CSR_MIREG6 0x357 /* Machine-Level Interrupts (AIA) */ #define CSR_MTOPEI 0x35c From patchwork Sat Feb 17 00:57:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7E279C48BF6 for ; Sat, 17 Feb 2024 00:58:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5eMUxwaJm0Il8G0jiyQsU51mogawBb4CMuELAir11jw=; b=0uq6ErT31nSn53 9jIOW4o6rZPuunsVLHfA1k32FH5QICadBk+fVnZrnmWQzlMuZP7GtcLM+W8wKtDvQ0DYiT5/nLBHO R+6NVhcaJ0fzoM9jt+DnkutdyTdXKCUJhHdoSpjwi80NQ411wAO1iqHelIabWAJJB536odrGUIWSL Oekm0Bx/RwDl5rSuqp2ue7y9WXFyVBb4mSzYW9ycQlK6ms7CTsjXroXOmHbkMWCabcwIeX6FRYGr2 dRSgmO5AN5cauNswqI3XEHHTeu62ejE+HilYomxzenX5FMl2U1SEgh0COCudVcaZzTC1UQbAqwRhG v2PHBFkinTAg/l389rvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb929-00000004Hyg-2JX0; Sat, 17 Feb 2024 00:58:25 +0000 Received: from mail-oa1-x2d.google.com ([2001:4860:4864:20::2d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb926-00000004Hvy-3aIB for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:58:24 +0000 Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-214ca209184so1745318fac.1 for ; Fri, 16 Feb 2024 16:58:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131501; x=1708736301; darn=lists.infradead.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=fMgr1ik/uEkkoRNgvQCIWXGmAGeZi75wQYv7ioKJulE=; b=Ui/iSDXEAEaqgKV7oWTVVWiMbLyWAKn6VQWj0l4t8Dt6vCGAxViiOSIeCtw2Nt5xSe 2SbiZT7122f6DNvAQZZkaJioC1IQgJ73vEqEWhxVzdgbT76G5ZZPvbLPOheNsVL57UDd IjIuMSXNXQ9svQ035iQeSSUjeqcyuvQssY0Aj3RgT6BNWGDgAqXkgUKemxry7fzcp+rC tSKY17HMRPdWWZdZFxXF8tfbDl6ihHZV66PbkLvTEVN6tvfqb6qtJPuw8FJOMDnb2B7B ZY7LUtpxqfw8+jbAJ9TJTOAKwni2yoSduljjHTrF7IWGYZFMuUZSUAl4yAtCD7ryiYF+ xQlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131501; x=1708736301; 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=fMgr1ik/uEkkoRNgvQCIWXGmAGeZi75wQYv7ioKJulE=; b=Zvkej+AOtg7u1Ky2+Gf1xJtosE9DkMENfJSiNbVHT+lx+khpJBVCb6gXtQEVw7UGZq rPvF6EkMO2b1FVI4/ZQxGv5WPwcBAX1LvaersxzTPGe/Fvdtng99sy+ulbRtKS9VAaD5 sYt3F6FvZKBpy3Y5ca9oDRXdvsDrtgePfajH9XGo5v4ula2luu/NWwfyPkzdtpuy6EN3 VX4WRFIlTcl39GLlKgtrBLqo0shdmRAQCynFDw9at42PgvjGo9ygPGqcipGg3POWRLkb mYyqhBSu3ZYgRHR/kQ0RWwyNLNZ1Q0wGvy0JhjAM/wUN3+8o1e5gFS4Tk/Zlg7T6nzQH 0ktg== X-Forwarded-Encrypted: i=1; AJvYcCUu9zQEnc3Ix77yoNE5wo/xuSt/PDH3EKW1MOADz5m1kgd9QFydmstQMnj0RSgDcoRPAR1ucEWvyi8KWEP65Nc9gftn9rWM1BZ/XTNa1dCj X-Gm-Message-State: AOJu0YwDxYYdOBBCB9ddWa2Y02X6n3oIU3hiMXyCnLy+mZyGZI0JhPSl qGl9cpxHWB06NIDfurbMb2riKZhWLdipWnIUyV+Xzb30aS2/a8Y7PQmFjUR1gEw= X-Google-Smtp-Source: AGHT+IE6LQp69xLCLOFFJy6mutWlZnmsAZsBULNSC4jH5aWno9vuisH9O/sW+xQ1B/XKb7HuL+17UQ== X-Received: by 2002:a05:6870:224d:b0:218:d374:9b7b with SMTP id j13-20020a056870224d00b00218d3749b7bmr7867438oaf.38.1708131501652; Fri, 16 Feb 2024 16:58:21 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:21 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 03/20] RISC-V: Add Sxcsrind ISA extension definition and parsing Date: Fri, 16 Feb 2024 16:57:21 -0800 Message-Id: <20240217005738.3744121-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165823_001057_2AC56345 X-CRM114-Status: GOOD ( 11.31 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The S[m|s]csrind extension extends the indirect CSR access mechanism defined in Smaia/Ssaia extensions. This patch just enables the definition and parsing. Signed-off-by: Atish Patra --- arch/riscv/include/asm/hwcap.h | 2 ++ arch/riscv/kernel/cpufeature.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 5340f818746b..44df259cc815 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -80,6 +80,8 @@ #define RISCV_ISA_EXT_ZFA 71 #define RISCV_ISA_EXT_ZTSO 72 #define RISCV_ISA_EXT_ZACAS 73 +#define RISCV_ISA_EXT_SSCSRIND 74 +#define RISCV_ISA_EXT_SMCSRIND 75 #define RISCV_ISA_EXT_MAX 128 #define RISCV_ISA_EXT_INVALID U32_MAX diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 89920f84d0a3..52ec88dfb004 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -301,7 +301,9 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { __RISCV_ISA_EXT_DATA(zvkt, RISCV_ISA_EXT_ZVKT), __RISCV_ISA_EXT_DATA(smaia, RISCV_ISA_EXT_SMAIA), __RISCV_ISA_EXT_DATA(smstateen, RISCV_ISA_EXT_SMSTATEEN), + __RISCV_ISA_EXT_DATA(smcsrind, RISCV_ISA_EXT_SMCSRIND), __RISCV_ISA_EXT_DATA(ssaia, RISCV_ISA_EXT_SSAIA), + __RISCV_ISA_EXT_DATA(sscsrind, RISCV_ISA_EXT_SSCSRIND), __RISCV_ISA_EXT_DATA(sscofpmf, RISCV_ISA_EXT_SSCOFPMF), __RISCV_ISA_EXT_DATA(sstc, RISCV_ISA_EXT_SSTC), __RISCV_ISA_EXT_DATA(svinval, RISCV_ISA_EXT_SVINVAL), From patchwork Sat Feb 17 00:57:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561200 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45B05C48BC4 for ; Sat, 17 Feb 2024 02:04:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IN7ztriMsJBphY5Y3ik9LQ+WT+++bPjUzvfOW0AO6lQ=; b=KmV/xMVoyT92bG dFHtQZjZDdluAp2m4OI5tIZzDajUBsTZqx9mu/RbM6UZ/GC8GZReEeCVOkvCgyHQJurhWl3JiC+m8 ocjk5/iIY9JTiJE3vhoidKMjj45lk88lENV3SqMRDKGLX6LAhw+lCGhPhgjdMWBdb928cbo9lZ/C0 ucerymn802BwD/ohX0gjAt5hyzBKa1NTFri7jH4y1krfiUxJnT47GeTLneWzUmg/j4k/jDbtXQ+Ka TZvBJ4lkd2FS9cAC8niqAtjrnJJAbwPjJjSm8eXZa5uI7o2/S9q2nM8P/VC1CcG6eUxDB7ypLyuQ0 xZjMbqKfm6kQaLInf5Bw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbA3P-00000004S95-3IOY; Sat, 17 Feb 2024 02:03:47 +0000 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92B-00000004HyA-2Oh8 for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:58:29 +0000 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-204f50f305cso1848265fac.3 for ; Fri, 16 Feb 2024 16:58:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131504; x=1708736304; darn=lists.infradead.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=AGOhtuG2UaHnTQxcaDC8cd9FvgXaDTb+kFLo3H4sRjk=; b=xHsNJpHUr2cyxXFzCn9wYZrPEzfjC+h5zCTT/G4/LD8oaFQuPCmrssQl/U38v2Atdw HyQUByqr7Zzc8hBQkpI3KBYAIG+7a7M7FJbzKkeojfwMqco7IYk6oAAsb6zBb5bFFp6h zo5QR/uQyfRaHG2GVs8XKkuAoL3NZ6aJvVrbTIXpnh4NpJSp3HKLWkEihl3aY4cGSEyl AN4HvWTayrJEVD2c9l0a5EtU31cb01fUVfukCgjFtam9bIKV79XJ+0guwrcWUydvB0/p p/2LpayzSHyAC1Rc0tGTnbDguqqJyVfaD3UF46bEWbnFfbVGSf7xomqvDvhK+coHFLWM 7ZvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131504; x=1708736304; 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=AGOhtuG2UaHnTQxcaDC8cd9FvgXaDTb+kFLo3H4sRjk=; b=CfnkZy3h6Kb8ysCM7Ts1N+XzV8HpSUgW2N277i8GIdIjd8s45tn6wpprpnL++2OzH2 jJwmTmblclqOhvcXkUCoreqRK+GBXBW8Aryj32y7rAcOwoqG7Pm/KVZYCHNgIjaZuKlX nUSYr0xowy7nxzMzLHpB6WP2c0l78jbC0ie5faUnd2jkUWHBLg9iXgOmavT+3ILMiy6p Lo2jxK7c+qyv7nHzv2xdjGjDlBPj8GOwiiQb+s7NUaldvIS49B9d9XZl9GCUvO1kayy/ bU2QeB8oXVBPECPm6fiFRZrVtnQuzswjT/sUTcAqAEdPE4vvpC13rtt56nnaV8kceMTS UvsA== X-Forwarded-Encrypted: i=1; AJvYcCWZkSm92jcojYRfT7yoQN37GZOYnIMA02vMBkBYHcoWKavb/svG51rWRq4MS5BLQW91QBM8doh0fJNdZ4NYgn/yqwLldR1P6DrIOcYPYrDy X-Gm-Message-State: AOJu0Yz/eMSAgqC3H8IuIK/cFNRDKKut5mCKe7uAu5ZBctoJolPk2zrm AQ82U8Q36QoIft4OCqmvpdF2FU2N2s6EjyTUqfsTrxvv/yaBIJ75t3o6rqtFjcY= X-Google-Smtp-Source: AGHT+IHVmqRBo/P6TbzgA+IGRtey54aZ2Ug+NftR1Tt1j04Iczb8JXsSk87BBrBxRg2sWo4RpRMoyA== X-Received: by 2002:a05:6870:40d3:b0:21e:7fba:1960 with SMTP id l19-20020a05687040d300b0021e7fba1960mr1993804oal.18.1708131504258; Fri, 16 Feb 2024 16:58:24 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:23 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 04/20] dt-bindings: riscv: add Sxcsrind ISA extension description Date: Fri, 16 Feb 2024 16:57:22 -0800 Message-Id: <20240217005738.3744121-5-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165827_713951_764074B5 X-CRM114-Status: UNSURE ( 9.68 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add the S[m|s]csrind ISA extension description. Signed-off-by: Atish Patra --- .../devicetree/bindings/riscv/extensions.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Documentation/devicetree/bindings/riscv/extensions.yaml b/Documentation/devicetree/bindings/riscv/extensions.yaml index 63d81dc895e5..77a9f867e36b 100644 --- a/Documentation/devicetree/bindings/riscv/extensions.yaml +++ b/Documentation/devicetree/bindings/riscv/extensions.yaml @@ -134,6 +134,20 @@ properties: added by other RISC-V extensions in H/S/VS/U/VU modes and as ratified at commit a28bfae (Ratified (#7)) of riscv-state-enable. + - const: smcsrind + description: | + The standard Smcsrind supervisor-level extension extends the + indirect CSR access mechanism defined by the Smaia extension. This + extension allows other ISA extension to use indirect CSR access + mechanism in M-mode. + + - const: sscsrind + description: | + The standard Sscsrind supervisor-level extension extends the + indirect CSR access mechanism defined by the Ssaia extension. This + extension allows other ISA extension to use indirect CSR access + mechanism in S-mode. + - const: ssaia description: | The standard Ssaia supervisor-level extension for the advanced From patchwork Sat Feb 17 00:57:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561199 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1D1B9C48BF8 for ; Sat, 17 Feb 2024 02:03:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+1nhtA8+SCejgMJDqIwLxkMt4ET2IwKwl0ebup2ik2M=; b=OrWcuf+uQQRq3K Zj4l5t7UGGQA14ZlMzK+BAOGxKfTL+gnONtR0vtFgS9HbaxAad2KVkxo5armOgRqnI0xK0X42R/Ct 0q+ENjK2oHfZMErGX8A7ScYvf8km27hkh6xzx584ccphMbXO95GYqVU3PS8t/CTnP5foSJelnQ2IM /qjEXDxBRahLoxJTtdpY2HCAxKxtGuBd/VIJWSCDFW7U0SNFq7+T7oBD+mlMpCo/fOI1Tvnjo01fE L8MMUYsE4Ksdf5hwbMHgTLGiW1TojxQhmMn2ohhzIryXyegFJ4QDp09ErynzMQ4iyn1FEwJzmZ8s3 OVgGz7TrVhrz5Ks1gMDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbA3Q-00000004S9B-1jAa; Sat, 17 Feb 2024 02:03:48 +0000 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92C-00000004I0M-0J29 for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:58:31 +0000 Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-3642281e4a6so4021815ab.2 for ; Fri, 16 Feb 2024 16:58:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131507; x=1708736307; darn=lists.infradead.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=tZxqoC10roX3FmWShwLO5FF28+Cew6bJztG9VlJd1gc=; b=u/zSz6bJHk27jnF5mQpkUrvxyM6QTwmz/5hmQASitAd1FAiuIvTYPLoT1Uv2zHxWsE EGcNZX2vWtofuxCViOWvKoGv4Zd6VCjfmm7wHayAw8Y8xLakluFp/tiXyGQNfWLipBf4 vfV/a5SuC86CxcmHoiPJmu0Egej7vxwwDUuW2aYHBHgrYVJXa1lU3I4JuwvLCH6Zi5Hi ZLE8J+YqgwOCXdLk9WagCUHN3yonSa9oFRj3oGQmRpguXN1ZDOeMKWfT8Vwumc4e4v6w x4vBM0SHEHiztxnG6+OwdeE01vNsDj65GFyAP7pZVmju0xE0KIbLgQzNmOgVeNHhfRaY hMcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131507; x=1708736307; 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=tZxqoC10roX3FmWShwLO5FF28+Cew6bJztG9VlJd1gc=; b=ww3IT+Tg3EZNKB8UPhP7gCJVV2907ywNWYer9TwJraLlEy03DgLsRThR4LeX8kprEu te6PSPQkOSlcTrCeXUBmmpq4jYkQfW9rScYocZRttPWmIvSjWsITxnU49m7v4pnEV26m CPthbpxyrrboUAUm0RiACsQPRcvVKrunAwJvlTOPqJ2cQUaZ7jvcXC7BHggW6lFC7saA vQWYWqdvHn4E34hOB/fcS7/QipreWwV/Lmw/UiO+0QY6k4CKR+rteilqXDVqZerFXuiY a9bMc8gsEoINot0fPWSYM/UnKuWikCNIvbGMtor84sCIapaKMZSI/wbwfRHK/HMvQ7C1 m5IA== X-Forwarded-Encrypted: i=1; AJvYcCVTpi7Hq18rcPFGWpjtisLYtLt61eVFM+zJBjci4LRurJsNVjRJQF/3rnsrkm673TmETIGrkL43U47Tw7ItYaudqKROT9Zb7XygdDErx7nL X-Gm-Message-State: AOJu0YxQv0ZA9EOTbzjNK7kJxoLJHHYyNno2mnieXub7VcanGhy6o0KF SAqmlyoTnZHH0hiJUCX7QfX5PwrcTFvdkfZjvvKS6G+o7bfu47P+WGl53oaFHho= X-Google-Smtp-Source: AGHT+IEz0+A9x0GTcr1tO8p0VDE5KRpFc1BbSQ5HWLqCdx+AJgXr1jki3q4ZnbUMgc8MM5i0wwekUQ== X-Received: by 2002:a92:c54d:0:b0:365:1563:c4e5 with SMTP id a13-20020a92c54d000000b003651563c4e5mr2552537ilj.9.1708131506838; Fri, 16 Feb 2024 16:58:26 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:26 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 05/20] RISC-V: Define indirect CSR access helpers Date: Fri, 16 Feb 2024 16:57:23 -0800 Message-Id: <20240217005738.3744121-6-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165828_283593_ADAF24C8 X-CRM114-Status: GOOD ( 13.06 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The indriect CSR requires multiple instructions to read/write CSR. Add a few helper functions for ease of usage. Signed-off-by: Atish Patra --- arch/riscv/include/asm/csr_ind.h | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 arch/riscv/include/asm/csr_ind.h diff --git a/arch/riscv/include/asm/csr_ind.h b/arch/riscv/include/asm/csr_ind.h new file mode 100644 index 000000000000..9611c221eb6f --- /dev/null +++ b/arch/riscv/include/asm/csr_ind.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2024 Rivos Inc. + */ + +#ifndef _ASM_RISCV_CSR_IND_H +#define _ASM_RISCV_CSR_IND_H + +#include + +#define csr_ind_read(iregcsr, iselbase, iseloff) ({ \ + unsigned long value = 0; \ + unsigned long flags; \ + local_irq_save(flags); \ + csr_write(CSR_ISELECT, iselbase + iseloff); \ + value = csr_read(iregcsr); \ + local_irq_restore(flags); \ + value; \ +}) + +#define csr_ind_write(iregcsr, iselbase, iseloff, value) ({ \ + unsigned long flags; \ + local_irq_save(flags); \ + csr_write(CSR_ISELECT, iselbase + iseloff); \ + csr_write(iregcsr, value); \ + local_irq_restore(flags); \ +}) + +#define csr_ind_warl(iregcsr, iselbase, iseloff, warl_val) ({ \ + unsigned long old_val = 0, value = 0; \ + unsigned long flags; \ + local_irq_save(flags); \ + csr_write(CSR_ISELECT, iselbase + iseloff); \ + old_val = csr_read(iregcsr); \ + csr_write(iregcsr, value); \ + value = csr_read(iregcsr); \ + csr_write(iregcsr, old_val); \ + local_irq_restore(flags); \ + value; \ +}) + +#endif From patchwork Sat Feb 17 00:57:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 12306C48260 for ; Sat, 17 Feb 2024 00:58:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2QmU7sIWUgC7wcwdxEOMNMgVFP8qs9Ws/kZwkKe+4VE=; b=hC199+UYMJRVCe UQH/cKZUX4OwbUDVLKd3j1U058yvG4LuMF4tngdGStUFXUPSzFgeoKa7hxNM8dlh5R0ZmuFdigQRw mVmzQ9SDoZJ09OrjO831AHfqw6Qsq0uDErAt7OFDbKtnN8WyOmH0DhQgpBz1iUAJ9DnldbdkAoUq6 MEEwBD6vpQCR49quZhl7ScD2qVgJkeVqmbHDoM2+nNEVpeG+aU5R8QI54LAGcKGGUdgQ8qWExCFJU FZOX/85S1csEjkcuM6KVbsyTLpH64yJxIuNrBgSwxB34VdXywu57xJT2Fnwx0+R5pMhXlwQUIz7W1 ku1HUP+k1mlE5BAhjWqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92R-00000004IGG-0bNy; Sat, 17 Feb 2024 00:58:43 +0000 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92E-00000004I3U-3YoP for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:58:34 +0000 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3c0a36077a5so1519009b6e.0 for ; Fri, 16 Feb 2024 16:58:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131509; x=1708736309; darn=lists.infradead.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=a2xIx7YE6DTpyA9iQ0shuXDu9l/GTuR0ZUSu2bmZ4Gw=; b=Zx7hGco7HJyT9EbOsOL+Of8TzGgVeqNCqNwcjJhceGPPyXPEN5qWVpQ/r1c+ysUMl0 BrhVe2knlyBPwYfOO1+CXKERn0C/uxWiAZcG+SP516PzkZr0qPDk0QqqWQmJ2OYVSgND vFKcc3aUyKOCC3u2oiPKhfj0lXJhZGPu73H3rUDWdX0BLyIaWWeJhBvBPrb2WmaUXfkq e6VzYr9dqJKcW7OjKDGxgb95KqpKb8Tdhnm+4+hRfdg1PNFfmAYkRQbZuUjwFEMWa8ei SjXrpz4CYNUr6j0XWwHJaelm8t5CG447kPDPxSS6ebfu/DRfWpzVFD/X3yrdCkSPLOeA VUmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131509; x=1708736309; 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=a2xIx7YE6DTpyA9iQ0shuXDu9l/GTuR0ZUSu2bmZ4Gw=; b=JLglF3huaUCLWZ+6R0l7qd3OmXrKpvbRS0KPC9Zu6UKadZB0q8WDJnRHkqiQ1urNdV 9g4YeK5X17Ks1adinxuu6dk/WT2B6NOmemfzg0/o9gzj4jLz4xoim4ZCVaHdp0r4jdp6 zgRY6MSefCKceLh7pDCK2NUgR2ux8dN8QiT6btWP7/k9Xn7qs6VFepL2+Ysn/rAal20u wOgSFzAqR9CGwo+BiTOhs5m/51pxaFX9YheKb3ni7rNFGTeLRL7YoUjEPvCDKY99X4b0 T1nRq98yIEpY9ePYud7cRQKyhHGeaOBn9vCzLbbd5mAbTtAm64+kEXD6wmPU1B/uzbyP t1Qw== X-Forwarded-Encrypted: i=1; AJvYcCUDA/LvovM61o2O/e4gCspFd2aYncCajk/72ue/XZy+eWkeNG954dydH6TRvSFsJlXnQZZGgx1XmwTv+cKpYT/x/3wnFccpvnNk6nrVXUyY X-Gm-Message-State: AOJu0YybsFG5CxXpXUk5U+bNBQQHkaIjLRlNQYH6pfl44XOJY9VTCDju u7/S6x5a2yapc1b/EtWocArt/FT9pCtSwNSGPoonkKk5qW/hwmG1N26mLjCCaFU= X-Google-Smtp-Source: AGHT+IFGR2TLppjaVLhGvXb9veJUkvHq4g2Z43QZBpJsKyF4ul3TY6Njmk1X1f97l7rCNISjLsOStA== X-Received: by 2002:a05:6808:2392:b0:3c0:4357:1d20 with SMTP id bp18-20020a056808239200b003c043571d20mr7982453oib.47.1708131509393; Fri, 16 Feb 2024 16:58:29 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:29 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 06/20] RISC-V: Add Sscfg extension CSR definition Date: Fri, 16 Feb 2024 16:57:24 -0800 Message-Id: <20240217005738.3744121-7-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165831_084485_27BF9253 X-CRM114-Status: GOOD ( 10.75 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Kaiwen Xue This adds the scountinhibit CSR definition and S-mode accessible hpmevent bits defined by smcdeleg/ssccfg. scountinhibit allows S-mode to start/stop counters directly from S-mode without invoking SBI calls to M-mode. It is also used to figure out the counters delegated to S-mode by the M-mode as well. Signed-off-by: Kaiwen Xue --- arch/riscv/include/asm/csr.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 0a54856fd807..e1bf1466f32e 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -214,6 +214,31 @@ #define SMSTATEEN0_HSENVCFG (_ULL(1) << SMSTATEEN0_HSENVCFG_SHIFT) #define SMSTATEEN0_SSTATEEN0_SHIFT 63 #define SMSTATEEN0_SSTATEEN0 (_ULL(1) << SMSTATEEN0_SSTATEEN0_SHIFT) +/* HPMEVENT bits. These are accessible in S-mode via Smcdeleg/Ssccfg */ +#ifdef CONFIG_64BIT +#define HPMEVENT_OF (_UL(1) << 63) +#define HPMEVENT_MINH (_UL(1) << 62) +#define HPMEVENT_SINH (_UL(1) << 61) +#define HPMEVENT_UINH (_UL(1) << 60) +#define HPMEVENT_VSINH (_UL(1) << 59) +#define HPMEVENT_VUINH (_UL(1) << 58) +#else +#define HPMEVENTH_OF (_ULL(1) << 31) +#define HPMEVENTH_MINH (_ULL(1) << 30) +#define HPMEVENTH_SINH (_ULL(1) << 29) +#define HPMEVENTH_UINH (_ULL(1) << 28) +#define HPMEVENTH_VSINH (_ULL(1) << 27) +#define HPMEVENTH_VUINH (_ULL(1) << 26) + +#define HPMEVENT_OF (HPMEVENTH_OF << 32) +#define HPMEVENT_MINH (HPMEVENTH_MINH << 32) +#define HPMEVENT_SINH (HPMEVENTH_SINH << 32) +#define HPMEVENT_UINH (HPMEVENTH_UINH << 32) +#define HPMEVENT_VSINH (HPMEVENTH_VSINH << 32) +#define HPMEVENT_VUINH (HPMEVENTH_VUINH << 32) +#endif + +#define SISELECT_SSCCFG_BASE 0x40 /* symbolic CSR names: */ #define CSR_CYCLE 0xc00 @@ -289,6 +314,7 @@ #define CSR_SCOUNTEREN 0x106 #define CSR_SENVCFG 0x10a #define CSR_SSTATEEN0 0x10c +#define CSR_SCOUNTINHIBIT 0x120 #define CSR_SSCRATCH 0x140 #define CSR_SEPC 0x141 #define CSR_SCAUSE 0x142 From patchwork Sat Feb 17 00:57:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561136 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3DF1EC48BF6 for ; Sat, 17 Feb 2024 00:58:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=oClqW0lxLtDGAeuS02oCQAmlLxctWteJXAlfowKL2rc=; b=Bc86pC33Q/jjYp y1sEJVaaTleLWElzOyA3z4fxbWcg5CTZwvMQ+E2Y96+iU28JB+bHq8vkRRe6eqYMrUF3++pbc8geX KtO/ccWidNP39xSN49kamHHRDXqjeS1sRmb+ovD4qZuh/qjIatMctScXvqoki/zMKz0pGfO2YKcZA 6SHM+Wv/2yYjV8SbN27fMB8P0Z39nE6YF7Jcpi/VuYEvq8QVW9x7r4nGDq4qdItds5ck+BTtnMnmP 5d/ih0QBpwDbxPDL9fHa7ElCa5gpAj8/KsAQ+bLTzw7TUjJR2aYol0UZJA+LfzHoo56RfcjD9xksJ SqNBJPQJ2SdsxGnAOQ1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92V-00000004IKT-40mc; Sat, 17 Feb 2024 00:58:47 +0000 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92H-00000004I5s-1pR1 for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:58:36 +0000 Received: by mail-il1-x12b.google.com with SMTP id e9e14a558f8ab-3650dcd38a0so3262605ab.1 for ; Fri, 16 Feb 2024 16:58:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131512; x=1708736312; darn=lists.infradead.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=8yuqScAnZ2lAjzdM+wGDjNHf/qrm86EPmr1bz136zUM=; b=NUx3StnjFV9aK5ks4d+rp6FajNW4PfQ8JiEs9s1DpdmPVX3PKRU0Gc92OlePmJDiXD CMrrXourUbCYzuIx2EelC5IW1C/7pwVTa3YxEWPyeTyekQoMUdhwTP5/kfT6KmubAWow Uy/MkZNHdUBHgPY3PYwKDnsXf7k5wG6Jy70dtbmh07HbDH4d1/oO/Ih1lerEWc0hzqo6 Jng3v/oPbjesOcIcogxUIGSEI9k0Q7arfEw/YwPPYWp8iqq42wZ6aP/zKKY0LU/ugIkL qVEyD2dKpf5VkhI1SFNWO/OfeMxSDROwJ5n8HmbbpBBWAMX/ek1GKHNwqSrcTiq/19Dt gi4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131512; x=1708736312; 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=8yuqScAnZ2lAjzdM+wGDjNHf/qrm86EPmr1bz136zUM=; b=DI8g24lUWqcO0yDT53G7/ps65n3tQPJNkWUdcvr8TIz9z5c3CliFXpmORSEp2BvV0r CxBGdTS1AVCWsYjvvw+KeP+/mjhL0nNNGfl+OgaczfzUKmuNDIvLD06xwawJH17l7LWI kY4EuUM8wvFzmZbqZuCb0eovTEBD6164T1kGgSj1dFlk0wCA4VjzaMFU+8m8e5U01F3G 1fb7m7QYLym7ASBOVKG/QbkizBOVXrzRMD0ZmdiEk+8DH8Y/L3Wu4UN5mgVZh6A5xN35 l7hzlj6ZjuNMA5kXYeaJFboQy9z3gVUUuf/nBH626musDpJf3qCqr0lbDGWpU5VEttV0 0uzA== X-Forwarded-Encrypted: i=1; AJvYcCX462E6B1DytiQns52ldguX6gJgd6ca4JL5JQVBBuGLsABepRuKM925RmoFcOg8YC+pHFyo6qAKs2pFbRIVxzogea2C4gJWWv7NQOl6w6E7 X-Gm-Message-State: AOJu0YzW1msfH5FAd7Ecx9kkXe1ienOZ5c8lNM4UMOobidbIu4DwWKR1 TiYj2ur3LG/mFpgYkaoGCLpf6OovkfZK03ALXAKViigWMCrkFL4t82R/1YhEJmU= X-Google-Smtp-Source: AGHT+IHik4QrimZEc7Y58ACfRBjvwhbVJhwuT0U4/D/6aufYBPUmjg3iZ9kYnwtI0QZLKwXDyQ9OOw== X-Received: by 2002:a05:6e02:1069:b0:363:b362:a2bb with SMTP id q9-20020a056e02106900b00363b362a2bbmr5475068ilj.32.1708131512047; Fri, 16 Feb 2024 16:58:32 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:31 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 07/20] RISC-V: Add Ssccfg ISA extension definition and parsing Date: Fri, 16 Feb 2024 16:57:25 -0800 Message-Id: <20240217005738.3744121-8-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165833_763273_8B4C9BA2 X-CRM114-Status: GOOD ( 10.97 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Ssccfg (‘Ss’ for Privileged architecture and Supervisor-level extension, ‘ccfg’ for Counter Configuration) provides access to delegated counters and new supervisor-level state. This patch just enables the definitions and enable parsing. Signed-off-by: Atish Patra --- arch/riscv/include/asm/hwcap.h | 2 ++ arch/riscv/kernel/cpufeature.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 44df259cc815..5f4401e221ee 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -82,6 +82,8 @@ #define RISCV_ISA_EXT_ZACAS 73 #define RISCV_ISA_EXT_SSCSRIND 74 #define RISCV_ISA_EXT_SMCSRIND 75 +#define RISCV_ISA_EXT_SSCCFG 76 +#define RISCV_ISA_EXT_SMCDELEG 77 #define RISCV_ISA_EXT_MAX 128 #define RISCV_ISA_EXT_INVALID U32_MAX diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 52ec88dfb004..77cc5dbd73bf 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -300,10 +300,12 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { __RISCV_ISA_EXT_BUNDLE(zvksg, riscv_zvksg_bundled_exts), __RISCV_ISA_EXT_DATA(zvkt, RISCV_ISA_EXT_ZVKT), __RISCV_ISA_EXT_DATA(smaia, RISCV_ISA_EXT_SMAIA), + __RISCV_ISA_EXT_DATA(smcdeleg, RISCV_ISA_EXT_SMCDELEG), __RISCV_ISA_EXT_DATA(smstateen, RISCV_ISA_EXT_SMSTATEEN), __RISCV_ISA_EXT_DATA(smcsrind, RISCV_ISA_EXT_SMCSRIND), __RISCV_ISA_EXT_DATA(ssaia, RISCV_ISA_EXT_SSAIA), __RISCV_ISA_EXT_DATA(sscsrind, RISCV_ISA_EXT_SSCSRIND), + __RISCV_ISA_EXT_DATA(ssccfg, RISCV_ISA_EXT_SSCCFG), __RISCV_ISA_EXT_DATA(sscofpmf, RISCV_ISA_EXT_SSCOFPMF), __RISCV_ISA_EXT_DATA(sstc, RISCV_ISA_EXT_SSTC), __RISCV_ISA_EXT_DATA(svinval, RISCV_ISA_EXT_SVINVAL), From patchwork Sat Feb 17 00:57:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561201 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E766BC48260 for ; Sat, 17 Feb 2024 02:04:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=N4ebKkXTlKi7eK4gsxSTxVRwHzdTidoro9j5cgJ9QAA=; b=ot9VuTA/OkdeuN PAt4o9LsdpP+jgqSSoHyEJdKkNRnrsgmVoLDTq/Hao2SfeX1NMWkeUehhQC7eFOS/RYWa+wLcQ4gf iZxRSCc3aME3HzoFMPVAmGXE5gSedgJmzoGHVXODRLtBv8kW6rbCuuE1oHRrZpNuuL1aml8IxNnPX K6lNcG+RyISZQrQqVT2s8t4dzG1Z/rDRn/DaAPvT/++140xEmmOyiviG4PEZuH3gmpCit0p7JjZc+ r5ygSv4AGNV3lO1stJ+eqqABBc99/QrJ8Av/WHSBpFmRekQgPgJ2/Yc+bZllUNF0NTmE+0VRK3nKs yWJWUPB6L4pS8VFftmrA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbA3R-00000004S9b-2Y6H; Sat, 17 Feb 2024 02:03:49 +0000 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92K-00000004I8N-0hVW for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:58:41 +0000 Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-7c47f06863bso96713139f.3 for ; Fri, 16 Feb 2024 16:58:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131515; x=1708736315; darn=lists.infradead.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=zM1FhW7Qr3v0FtC5FiOLqFulLhlj/jL3zhy6p8GYU3U=; b=QnuxqFRnTaO7quft0T86pdal1XMc0Hju7hwM3XS/56Ydpc/wWJbki63TiGClUr8fGO 7/qAOMSDITXzflGKZ9DaPSdyHi76A5pplEMrmOBSp/HbEuo/qABhIGaBwI16pDoYCvxt DzGXilzRQalj/zcWoE1EXIJ5nrm0WxafJT1/6t/PgX6KjjX5HHDgtbORiYGKaUfinwtp n7FSVrWVhXU7jqFI1HyKiCUyf55E22eAoejyIfpdyxshWj47/i2GMekbFvtwDKlLh+EP VCFo300smPZUcOeIFT4NWzXIReNfBy+dwEYejSaQAU80zNkVwKRqxwcILujFOnKRCw96 ATag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131515; x=1708736315; 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=zM1FhW7Qr3v0FtC5FiOLqFulLhlj/jL3zhy6p8GYU3U=; b=XBpR3j1rTUYzjuZ2dJ7fuuhDcVltH5BjsnD7gMpw7jfXFmkxP8xCsr3kVcSJVr68KF BSlZVnMwhlXdbUlcq8ZkFAwPhEe1Djz35bzPpbCbflB+K2kSfutrpomOCTQiNPWUHEcY DgAOzpNuOdTSj1Wz7KljO3KitOwxDjKn0pL2tlmhvg8FOeOtsoG4W/wfmS+MC1+G2Meg djm+VLReqr/bkpkns3xAuqh9sJUl4TphmqXupg7+1yoPc0h297LAZfO1q4p0GDYy5AVR n1C/tesnnPwj7VUCgy8PqVZerKZDpTvcia4sJ4Y9R+86kpPfpMLNB/0QDtCXjVMt/92I 0P5A== X-Forwarded-Encrypted: i=1; AJvYcCXClgWwzmV6W/LYO7L78WAWo26YL/PQiwrvdaMrh9fWjNaG0890yY8x6WiexnfK+RnOOwW42gDpowHh/W1wN5TQwHErNhSUf9h4/RODWT7c X-Gm-Message-State: AOJu0YxETN89uNJaWDjO7/6Il+4V9XkbNf6L2tG96PaW1wJSfLfxCLqA dkj7QrkAjVpnwnlMtAuIAsrtEcGmCP4TzXV4AYL0jfTkH8Mro6iclq9ZpGcJ7QY= X-Google-Smtp-Source: AGHT+IG/18cu0XQrzjjkqrWO02cvxzc2sKclTHZn6KgjzARvIp50etYjTOykyTJQBV988xbbQes5Kw== X-Received: by 2002:a6b:7018:0:b0:7c4:2254:8e59 with SMTP id l24-20020a6b7018000000b007c422548e59mr6880303ioc.5.1708131514686; Fri, 16 Feb 2024 16:58:34 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:34 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 08/20] dt-bindings: riscv: add Ssccfg ISA extension description Date: Fri, 16 Feb 2024 16:57:26 -0800 Message-Id: <20240217005738.3744121-9-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165836_617005_8AFD6811 X-CRM114-Status: GOOD ( 11.40 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add description for the Ssccfg extension. Signed-off-by: Atish Patra --- .../devicetree/bindings/riscv/extensions.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Documentation/devicetree/bindings/riscv/extensions.yaml b/Documentation/devicetree/bindings/riscv/extensions.yaml index 77a9f867e36b..15adeb60441b 100644 --- a/Documentation/devicetree/bindings/riscv/extensions.yaml +++ b/Documentation/devicetree/bindings/riscv/extensions.yaml @@ -128,6 +128,13 @@ properties: changes to interrupts as frozen at commit ccbddab ("Merge pull request #42 from riscv/jhauser-2023-RC4") of riscv-aia. + - const: smcdeleg + description: | + The standard Smcdeleg supervisor-level extension for the machine mode + to delegate the hpmcounters to supvervisor mode so that they are + directlyi accessible in the supervisor mode. This extension depend + on Sscsrind, Zihpm, Zicntr extensions. + - const: smstateen description: | The standard Smstateen extension for controlling access to CSRs @@ -154,6 +161,12 @@ properties: interrupt architecture for supervisor-mode-visible csr and behavioural changes to interrupts as frozen at commit ccbddab ("Merge pull request #42 from riscv/jhauser-2023-RC4") of riscv-aia. + - const: ssccfg + description: | + The standard Ssccfg supervisor-level extension for configuring + the delegated hpmcounters to be accessible directly in supervisor + mode. This extension depend on Sscsrind, Smcdeleg, Zihpm, Zicntr + extensions. - const: sscofpmf description: | From patchwork Sat Feb 17 00:57:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91E0AC48BF5 for ; Sat, 17 Feb 2024 00:59:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+6kLLb+esDUmfpbvEi/JR+oh44XFyIb/ZPgVMg+vZLo=; b=0DJdR5W4AVF2kC 2SxAx/og9kMtOb0xph4v6lmsAqcNSTAMfEWzDdOqGYuYn90v+fl8uyDBBPv7TEpsv2GxKyXz4vMw2 saHTXj0aQWyiPGNFsPmwSN5rH8q1u/GfxS3vRUdH2bdPUxmNWUimVjjig1inMZnrusmaIDj/qjR2A JiL88qoCUg7mP+DQsOqP+7D0C7G5JfFDkEvUwDOk4jxdMFh+/GkF9saqI4loZEvBKYbHXGhu8olma U7MTORrJiFwupyo2xGufJ7V8YJ9Nm/ZsVkQfH+r/Q+8DPpOKT4yQsiNfFYsBsz5dIgZPG6fMQuKMy N2mCu6ZD6D6VcDkANbQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92e-00000004IRI-1p1k; Sat, 17 Feb 2024 00:58:56 +0000 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92M-00000004IBF-2a39 for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:58:43 +0000 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-5dcc4076c13so1127536a12.0 for ; Fri, 16 Feb 2024 16:58:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131517; x=1708736317; darn=lists.infradead.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=UXnbbBG8uU1BPF0JsrRvm9475kp9ExkHduilmVeFprU=; b=yYDOaVa1HHTmHFELz6tyG+Ai0GVp0CQA0yku5JWXhwEcWq57ztw264XD7SFnk8MIky 03adajtLNiJqrqOvyQD7vprVbTnI2qarbNa5tQeOdROTh96gJRemRT5Fthb3BX2A/Zsu TLR7CORwB2V6vM7n/s/IqQwRmXd605c6KynmnYDgQKC3NhxZSzMkYVmysUMd30anWA/m IMKEwDCarUrtgCCECSQKwBIF1Z+GHSEu83l0FF7eB9KUjl760rKZMC9ux5vmsG4jYkkt aW3ZchY6Dgd+1PhwsWhcWsRlA0gnCv5vhSUQFawc1TfG9XuxnHdmpMf1r/2kbqUbfDQ6 5N2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131517; x=1708736317; 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=UXnbbBG8uU1BPF0JsrRvm9475kp9ExkHduilmVeFprU=; b=ZdAonul6u/H9pBuZhtqxgDzQvpVOSoJlk2GUHcg6bepr2EdI65hNm73QsCtVgJNC3S RZUOji2rMS8x98MZdyiutMosvAoMH36NQ4wxOy/ev6GOmoMIbL34MemsEgEYZ3oR3hPV GLN6XYfO/4oO2JmfnJojPz0TcD1k0olRoGPZAdOk/5zqpvqvsgpvU27dt9+Wu7FTIrgt ZP8oY406Ojj3FjO5Q21IG/7+OwWDvvimUujH4wwZ0cO5WLUH2/Wb2MQ+rqRkDH1m9t9W m4kw7Ps58tPw4r2ihicaqSX+RB+Kr/KIQfZvxAcQIj0X2M7DC2qzMQ4sPqqop6xnExXT RKCg== X-Forwarded-Encrypted: i=1; AJvYcCXpslVmgvP6SNgEdgTi/RdJH604zWxzhQgjPKtIw0ClQaMKDgsHHOM+K7wW9urdoHXPjgGlmGndrV+B2KBgrXaRJ4WB5SOyyIIbAfmPxpol X-Gm-Message-State: AOJu0YzJMW+M3ZLbWnRy4VheK3RkTKGq+kZso3cs+W5yW9yRGkxofx+P IRGcQHvClXtz0qQWCJF7FUZuf0F0hfc3+s27gju/n8FDuuOp4FFDxCrsEhwbxnw= X-Google-Smtp-Source: AGHT+IEd55O/kx49zwv2ulB5iw+jovlUvxT19+VDOzMjgyKdkOtaXKU1w9iKYbRt3ClDO/pqc7Grgw== X-Received: by 2002:a05:6a21:918a:b0:19e:9647:dad3 with SMTP id tp10-20020a056a21918a00b0019e9647dad3mr13656557pzb.12.1708131517282; Fri, 16 Feb 2024 16:58:37 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:36 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 09/20] RISC-V: Add Smcntrpmf extension parsing Date: Fri, 16 Feb 2024 16:57:27 -0800 Message-Id: <20240217005738.3744121-10-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165838_968241_71752C6C X-CRM114-Status: GOOD ( 11.84 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Smcntrpmf extension allows M-mode to enable privilege mode filtering for cycle/instret counters. However, the cyclecfg/instretcfg CSRs are only available only in Ssccfg only Smcntrpmf is present. That's why, kernel needs to detect presence of Smcntrpmf extension and enable privilege mode filtering for cycle/instret counters. Signed-off-by: Atish Patra --- arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/kernel/cpufeature.c | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 5f4401e221ee..b82a8d7a9b3b 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -84,6 +84,7 @@ #define RISCV_ISA_EXT_SMCSRIND 75 #define RISCV_ISA_EXT_SSCCFG 76 #define RISCV_ISA_EXT_SMCDELEG 77 +#define RISCV_ISA_EXT_SMCNTRPMF 78 #define RISCV_ISA_EXT_MAX 128 #define RISCV_ISA_EXT_INVALID U32_MAX diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 77cc5dbd73bf..c30be2c924e7 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -302,6 +302,7 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { __RISCV_ISA_EXT_DATA(smaia, RISCV_ISA_EXT_SMAIA), __RISCV_ISA_EXT_DATA(smcdeleg, RISCV_ISA_EXT_SMCDELEG), __RISCV_ISA_EXT_DATA(smstateen, RISCV_ISA_EXT_SMSTATEEN), + __RISCV_ISA_EXT_DATA(smcntrpmf, RISCV_ISA_EXT_SMCNTRPMF), __RISCV_ISA_EXT_DATA(smcsrind, RISCV_ISA_EXT_SMCSRIND), __RISCV_ISA_EXT_DATA(ssaia, RISCV_ISA_EXT_SSAIA), __RISCV_ISA_EXT_DATA(sscsrind, RISCV_ISA_EXT_SSCSRIND), From patchwork Sat Feb 17 00:57:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561159 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA0B6C48260 for ; Sat, 17 Feb 2024 00:59:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ptPFbJ8UxotF45qfgH5sHp75NPU427fz9g9N7kmBTWY=; b=2ZCeXa8sQ/Om2n P8svzXJSeZDU9f4xRSxCR+jbCnON5jr+/RSRRW5ekEUTCFx+X/GRwB6K+yymfSginM2VO+b/4l6a8 TErMJeaFCgyfyFrV0oLjdq6BVcYiABIi4nD9jzAfVehAscbKdEl1FDNLR5H4GDdnKubbNRUP6bYYQ OlCx2qivY+dysLwG1uJB6OWVUjQ51rbYeqmcfozw0MPjIOVjWhZG9mIUUWZkh/Ye9dkndq+O37Spr 38Po16oDdzubVD0GKjpdRfGOKKpAbnvniwGOfNdoPNT8LZKYbriYkF4m42lUkNfMyAErSf5c5rU1p O+jnJ/omQR0Gzvohy0Kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb93J-00000004J1h-2rDA; Sat, 17 Feb 2024 00:59:37 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92v-00000004Ifo-3zFp for linux-riscv@bombadil.infradead.org; Sat, 17 Feb 2024 00:59:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=jA2bwMTLdR68IYWhAHQk0vem/FIvLYvJUSgd6oUDROA=; b=pN0FLsZcbffjKyC07Gc1/9kjR8 +CmYWY8UDMlyKofQYqu1f7vzEH+EcTmPzbGCfSvoI7vS+pU+Xl+gN0a4GYVG8S4stnFBGa7Htzs+d /nr6cpaC1+eURgAM0Fyl5fBgGEAlGoOjRGmcg1cI2Nsfm+KhCMR73IZbsZqIlPBkwjC7cZ+2RnbfU IscsD8cdOcPHLN9dTfJPW4iCCmsrN7SkDhdCtrCBDWzu96sil8PGXi6CW+8eIznxaAsSO/TQuVD+M KCdq6kIOFWMaobGRjRXRDpI35oqXx4J+3wbA3BxX9BJ9ZFfPdSlsarAmoKTKzIcGOhJSxrbme7A8M 3RNqn5Iw==; Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92R-000000007J0-2Cu9 for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:59:04 +0000 Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-7bed9f5d35dso71079239f.3 for ; Fri, 16 Feb 2024 16:58:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131520; x=1708736320; darn=lists.infradead.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=jA2bwMTLdR68IYWhAHQk0vem/FIvLYvJUSgd6oUDROA=; b=LfOLsA9ZndzAKGNXeAK065RAoQa6XREfts/chgglP8cfr+LRLTRuTCTrcPIL8iHIi8 L7LrVbuuaJZrkUkuPC0C1/MBbA6UpPmSSBnc1iuiKUKZ/c1DfQgZaTy4Pnw+8s+R+mAT FubvaT2p1kh3jJD+zVNLvpT3WHc/XAzF/ioHYdREw9TurMB5K6h0kKv6BY4SPjlJ8fRo rNnVgjPmI2p4CbiNOfLXCuhFpwyw7mkG4Hx5s/1AkGihQkxRxqEpuzMN62BTNXY8oNWH duD6Ovp5OppshNY9+ov7+q2eQPft9dt1dGRm7O0k5FKPyILeGJmHYj7JrCJ0Y0ceyFCF NGpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131520; x=1708736320; 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=jA2bwMTLdR68IYWhAHQk0vem/FIvLYvJUSgd6oUDROA=; b=oAHnRtu6b+dNSjpSM2OJfN/x5fW0YpzySxqrxEIOJ9tD0PowxRq5CY/ZzKbD1+vpo4 f/WulBglwgemZg+C7U3/5kkv407URR2Rf5tblC8rMqF88djvhvjDvtnqPZe4O046E6ov joG6kvFROhAn88iprJPdfPtqtQbL3N/EkvwfxTalwM8CC4avwQ7ekuZ85+3aX+DEkYhZ UOK5o6XT9O7yqjFTEZU3mSYvtz0FSWEhBuLlLYR8uehLSmRY+sgsdIhfEiVzpphqLfYZ mF5IkMn43eyzDuzIe5FFCdSLgXAT57irD2v3AUBAZYFNnq6bwpLuh1kT40kkSO99GOuy jkmg== X-Forwarded-Encrypted: i=1; AJvYcCUEphqn3/h+lvFWQg5FxHnHik/MJLOBJM+LfECk6TxcU1WcOeFDrfyoUt3WzdRrQVQ67j9kgBDq8HDE8aYcjZ7sQ90u5KlMa+SN9Yf6oLgE X-Gm-Message-State: AOJu0YxeYeRe8acPFPWGtkmcNF5SnY/tO9M4/Y6miBhUHX1c9Uy4nP/R 82XtCjt8v+jgS+CbxPcT+MB8l+wywfs+Ne+T65dXjQd4qb+EqnGi2tW5N13Snk0= X-Google-Smtp-Source: AGHT+IEdeqVqcC/VKKKrXOEHY/VeTvf9ltSju1U8A00Dr62R9FD2Xfm3+udDPMEcDgQNQ3u+AM/jrg== X-Received: by 2002:a5e:c10c:0:b0:7c7:2e71:bb74 with SMTP id v12-20020a5ec10c000000b007c72e71bb74mr626708iol.4.1708131520123; Fri, 16 Feb 2024 16:58:40 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:39 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 10/20] dt-bindings: riscv: add Smcntrpmf ISA extension description Date: Fri, 16 Feb 2024 16:57:28 -0800 Message-Id: <20240217005738.3744121-11-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240217_005846_247502_57C488F9 X-CRM114-Status: GOOD ( 10.32 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add the description for Smcntrpmf ISA extension Signed-off-by: Atish Patra --- Documentation/devicetree/bindings/riscv/extensions.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/devicetree/bindings/riscv/extensions.yaml b/Documentation/devicetree/bindings/riscv/extensions.yaml index 15adeb60441b..149ecf2a8af3 100644 --- a/Documentation/devicetree/bindings/riscv/extensions.yaml +++ b/Documentation/devicetree/bindings/riscv/extensions.yaml @@ -135,6 +135,13 @@ properties: directlyi accessible in the supervisor mode. This extension depend on Sscsrind, Zihpm, Zicntr extensions. + - const: smcntrpmf + description: | + The standard Smcntrpmf supervisor-level extension for the machine mode + to enable privilege mode filtering for cycle and instret counters. + The Ssccfg extension depends on this as *cfg CSRs are available only + if smcntrpmf is present. + - const: smstateen description: | The standard Smstateen extension for controlling access to CSRs From patchwork Sat Feb 17 00:57:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561138 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A01BEC48260 for ; Sat, 17 Feb 2024 00:59:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yBFmrGv7OrYvM1hP4EGiCyjQJglGV9HjdaHD+gaoNHM=; b=dxy3BKt7ZjC9pk FcrIYvvZJwwL9k3uR5ulZlyXDEWKuoGYjEoLS9qWE1fMLds7yJexTcI+yKzCW473YXDD+mcqltRF+ 3PI7Dva1zO6+YjkFaNPI6FQfcd4xfGj6gxFUnJBNV75RYvoyopJyvXN6LMAevD/5JcJE+yA3Qsmkk QtviDZ34xzZXdIaCh5rxY6VmBWQsMur7qJfW1bqStLG5l+iiVeJaxEoSH4QyujAha4vj0oWCkVlww FwQDNGHmtIlLMQHFje3IcZ0NSi8wIi8pYhhgj33FAEwsv0xduT1epS3uRzEwkmhsuuqKvhA7IYcgw QXn2+RLKTPuOMwwuf78Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92l-00000004IXE-2xzp; Sat, 17 Feb 2024 00:59:03 +0000 Received: from mail-oa1-x2e.google.com ([2001:4860:4864:20::2e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92S-00000004IGm-2Dn9 for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:58:55 +0000 Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-2185739b64cso1538047fac.0 for ; Fri, 16 Feb 2024 16:58:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131523; x=1708736323; darn=lists.infradead.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=Z7baHfz5wM1sAulxZ7aqcH3C+Q/jK4GirAIqj+bIgHg=; b=x0r9bQyfLih8X4PFIcfUdpQ+8mGT0SbW0YsLB79DbkmNaXylg1dbZd0BvBpcIzwBcq V8Cox/ybK983FMn/hkoNHOCJVQ4UcajQx+BmSvfnxHWe0wFVGmou76zkNrW1kB3FYlfv XN8fcaA1MSt0FObdbIgNEooSVkloMGS/Zh7pNEsddLWByLeTuBFiVuG0tO9VVt4xnyxW 1N1qO28AjJ2Flc4HVHMpJD4ScrVhRbZL5s6dCUJIsBIOd7ZBKnAHM2rhJOJxEMFISLdB S22gvs0l6U3SXL4ARQNwNcR3nTLtoO5aRwVFPsfj5pCUYJS/n/r8fHLhkWOX4NSxwZUD klSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131523; x=1708736323; 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=Z7baHfz5wM1sAulxZ7aqcH3C+Q/jK4GirAIqj+bIgHg=; b=TentfCO8/hMsYkAZSIYfrM8F1Nhn5sRuksylwM8fr/To0raNPnSRCf6b1Eoz52z2Ra 8kIBs4NSqShFzD2FoGNqzVYdOazIN1Q/mrsx18wes9hogkSC14lH8xyQixSk8s7MVa+D a1GGuL4yS4VMsuNZS3RGiJv6iiEzVO71x/0Z8I4FJbuiqIlOjYB2Kj4hTp6JPcNFzmBz somU05fu2mEpZaxJ9SZcxJTELwVstF8owCV7yMbitJ03yyUS4vq29/YNuugKsAmeswBE vLoSezB4yaF3trwXUZK5IkBTCMuVixsKn7H20gYRN6C58KKqFVUErQbAKJAZkyurHDyN QLjA== X-Forwarded-Encrypted: i=1; AJvYcCXS4B2UwrVdJFKDJD7hlOoWsFn0/9B0sDRfzB2A5zJvb5jkbqQjJOvVyjP/n5HV1l6xZnEWnY4BWqMoa8i13FW76ofDC33aACpcRAHWoaoC X-Gm-Message-State: AOJu0Yxb9PMjPiyON3bctY2sgg3btB1VlYqekUzIu8uELWydVLhFlzDx WZpMiQ/UNRqsVfXAazEp4S/wKrYI7Cyejz/gipH05N2k7EDDURpb/oq3TAGPubM= X-Google-Smtp-Source: AGHT+IHkxfl5wojcZa7LsnbDVFHdZ6Fhtr81hemCG8W0Rrsj2MuzO5YyD77D//b4vSu9rHffY04CAQ== X-Received: by 2002:a05:6870:331e:b0:219:7f2b:1f2c with SMTP id x30-20020a056870331e00b002197f2b1f2cmr7394263oae.37.1708131522858; Fri, 16 Feb 2024 16:58:42 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:42 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 11/20] RISC-V: perf: Restructure the SBI PMU code Date: Fri, 16 Feb 2024 16:57:29 -0800 Message-Id: <20240217005738.3744121-12-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165844_778068_A8DDBB1D X-CRM114-Status: GOOD ( 23.53 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org With Ssccfg/Smcdeleg, we no longer need SBI PMU extension to program/ access hpmcounter/events. However, we do need it for firmware counters. Rename the driver and its related code to represent generic name that will handle both sbi and ISA mechanism for hpmcounter related operations. Take this opportunity to update the Kconfig names to match the new driver name closely. No functional change intended. Signed-off-by: Atish Patra --- MAINTAINERS | 4 +- drivers/perf/Kconfig | 16 +- drivers/perf/Makefile | 4 +- .../perf/{riscv_pmu.c => riscv_pmu_common.c} | 0 .../perf/{riscv_pmu_sbi.c => riscv_pmu_dev.c} | 170 +++++++++++------- include/linux/perf/riscv_pmu.h | 8 +- 6 files changed, 123 insertions(+), 79 deletions(-) rename drivers/perf/{riscv_pmu.c => riscv_pmu_common.c} (100%) rename drivers/perf/{riscv_pmu_sbi.c => riscv_pmu_dev.c} (87%) diff --git a/MAINTAINERS b/MAINTAINERS index 73d898383e51..6adb24d6cc0a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18856,9 +18856,9 @@ M: Atish Patra R: Anup Patel L: linux-riscv@lists.infradead.org S: Supported -F: drivers/perf/riscv_pmu.c +F: drivers/perf/riscv_pmu_common.c +F: drivers/perf/riscv_pmu_dev.c F: drivers/perf/riscv_pmu_legacy.c -F: drivers/perf/riscv_pmu_sbi.c RISC-V THEAD SoC SUPPORT M: Jisheng Zhang diff --git a/drivers/perf/Kconfig b/drivers/perf/Kconfig index ec6e0d9194a1..86aaa1c1161b 100644 --- a/drivers/perf/Kconfig +++ b/drivers/perf/Kconfig @@ -56,7 +56,7 @@ config ARM_PMU Say y if you want to use CPU performance monitors on ARM-based systems. -config RISCV_PMU +config RISCV_PMU_COMMON depends on RISCV bool "RISC-V PMU framework" default y @@ -67,7 +67,7 @@ config RISCV_PMU can reuse it. config RISCV_PMU_LEGACY - depends on RISCV_PMU + depends on RISCV_PMU_COMMON bool "RISC-V legacy PMU implementation" default y help @@ -76,15 +76,15 @@ config RISCV_PMU_LEGACY of cycle/instruction counter and doesn't support counter overflow, or programmable counters. It will be removed in future. -config RISCV_PMU_SBI - depends on RISCV_PMU && RISCV_SBI - bool "RISC-V PMU based on SBI PMU extension" +config RISCV_PMU + depends on RISCV_PMU_COMMON && RISCV_SBI + bool "RISC-V PMU based on SBI PMU extension and/or Counter delegation extension" default y help Say y if you want to use the CPU performance monitor - using SBI PMU extension on RISC-V based systems. This option provides - full perf feature support i.e. counter overflow, privilege mode - filtering, counter configuration. + using SBI PMU extension or counter delegation ISA extension on RISC-V + based systems. This option provides full perf feature support i.e. + counter overflow, privilege mode filtering, counter configuration. config ARM_PMU_ACPI depends on ARM_PMU && ACPI diff --git a/drivers/perf/Makefile b/drivers/perf/Makefile index a06338e3401c..f2c72915e11d 100644 --- a/drivers/perf/Makefile +++ b/drivers/perf/Makefile @@ -12,9 +12,9 @@ obj-$(CONFIG_FSL_IMX9_DDR_PMU) += fsl_imx9_ddr_perf.o obj-$(CONFIG_HISI_PMU) += hisilicon/ obj-$(CONFIG_QCOM_L2_PMU) += qcom_l2_pmu.o obj-$(CONFIG_QCOM_L3_PMU) += qcom_l3_pmu.o -obj-$(CONFIG_RISCV_PMU) += riscv_pmu.o +obj-$(CONFIG_RISCV_PMU_COMMON) += riscv_pmu_common.o obj-$(CONFIG_RISCV_PMU_LEGACY) += riscv_pmu_legacy.o -obj-$(CONFIG_RISCV_PMU_SBI) += riscv_pmu_sbi.o +obj-$(CONFIG_RISCV_PMU) += riscv_pmu_dev.o obj-$(CONFIG_THUNDERX2_PMU) += thunderx2_pmu.o obj-$(CONFIG_XGENE_PMU) += xgene_pmu.o obj-$(CONFIG_ARM_SPE_PMU) += arm_spe_pmu.o diff --git a/drivers/perf/riscv_pmu.c b/drivers/perf/riscv_pmu_common.c similarity index 100% rename from drivers/perf/riscv_pmu.c rename to drivers/perf/riscv_pmu_common.c diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_dev.c similarity index 87% rename from drivers/perf/riscv_pmu_sbi.c rename to drivers/perf/riscv_pmu_dev.c index 16acd4dcdb96..3d27bd65f140 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_dev.c @@ -8,7 +8,7 @@ * sparc64 and x86 code. */ -#define pr_fmt(fmt) "riscv-pmu-sbi: " fmt +#define pr_fmt(fmt) "riscv-pmu-dev: " fmt #include #include @@ -55,6 +55,8 @@ static const struct attribute_group *riscv_pmu_attr_groups[] = { static int sysctl_perf_user_access __read_mostly = SYSCTL_USER_ACCESS; /* + * This structure is SBI specific but counter delegation also require counter + * width, csr mapping. Reuse it for now. * RISC-V doesn't have heterogeneous harts yet. This need to be part of * per_cpu in case of harts with different pmu counters */ @@ -265,12 +267,12 @@ static const struct sbi_pmu_event_data pmu_cache_event_map[PERF_COUNT_HW_CACHE_M }, }; -static int pmu_sbi_ctr_get_width(int idx) +static int rvpmu_ctr_get_width(int idx) { return pmu_ctr_list[idx].width; } -static bool pmu_sbi_ctr_is_fw(int cidx) +static bool rvpmu_ctr_is_fw(int cidx) { union sbi_pmu_ctr_info *info; @@ -312,12 +314,12 @@ int riscv_pmu_get_hpm_info(u32 *hw_ctr_width, u32 *num_hw_ctr) } EXPORT_SYMBOL_GPL(riscv_pmu_get_hpm_info); -static uint8_t pmu_sbi_csr_index(struct perf_event *event) +static uint8_t rvpmu_csr_index(struct perf_event *event) { return pmu_ctr_list[event->hw.idx].csr - CSR_CYCLE; } -static unsigned long pmu_sbi_get_filter_flags(struct perf_event *event) +static unsigned long rvpmu_sbi_get_filter_flags(struct perf_event *event) { unsigned long cflags = 0; bool guest_events = false; @@ -338,7 +340,7 @@ static unsigned long pmu_sbi_get_filter_flags(struct perf_event *event) return cflags; } -static int pmu_sbi_ctr_get_idx(struct perf_event *event) +static int rvpmu_sbi_ctr_get_idx(struct perf_event *event) { struct hw_perf_event *hwc = &event->hw; struct riscv_pmu *rvpmu = to_riscv_pmu(event->pmu); @@ -348,7 +350,7 @@ static int pmu_sbi_ctr_get_idx(struct perf_event *event) uint64_t cbase = 0, cmask = rvpmu->cmask; unsigned long cflags = 0; - cflags = pmu_sbi_get_filter_flags(event); + cflags = rvpmu_sbi_get_filter_flags(event); /* * In legacy mode, we have to force the fixed counters for those events @@ -385,7 +387,7 @@ static int pmu_sbi_ctr_get_idx(struct perf_event *event) return -ENOENT; /* Additional sanity check for the counter id */ - if (pmu_sbi_ctr_is_fw(idx)) { + if (rvpmu_ctr_is_fw(idx)) { if (!test_and_set_bit(idx, cpuc->used_fw_ctrs)) return idx; } else { @@ -396,7 +398,7 @@ static int pmu_sbi_ctr_get_idx(struct perf_event *event) return -ENOENT; } -static void pmu_sbi_ctr_clear_idx(struct perf_event *event) +static void rvpmu_ctr_clear_idx(struct perf_event *event) { struct hw_perf_event *hwc = &event->hw; @@ -404,7 +406,7 @@ static void pmu_sbi_ctr_clear_idx(struct perf_event *event) struct cpu_hw_events *cpuc = this_cpu_ptr(rvpmu->hw_events); int idx = hwc->idx; - if (pmu_sbi_ctr_is_fw(idx)) + if (rvpmu_ctr_is_fw(idx)) clear_bit(idx, cpuc->used_fw_ctrs); else clear_bit(idx, cpuc->used_hw_ctrs); @@ -442,7 +444,7 @@ static bool pmu_sbi_is_fw_event(struct perf_event *event) return false; } -static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig) +static int rvpmu_sbi_event_map(struct perf_event *event, u64 *econfig) { u32 type = event->attr.type; u64 config = event->attr.config; @@ -483,7 +485,7 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig) return ret; } -static u64 pmu_sbi_ctr_read(struct perf_event *event) +static u64 rvpmu_sbi_ctr_read(struct perf_event *event) { struct hw_perf_event *hwc = &event->hw; int idx = hwc->idx; @@ -506,25 +508,25 @@ static u64 pmu_sbi_ctr_read(struct perf_event *event) return val; } -static void pmu_sbi_set_scounteren(void *arg) +static void rvpmu_set_scounteren(void *arg) { struct perf_event *event = (struct perf_event *)arg; if (event->hw.idx != -1) csr_write(CSR_SCOUNTEREN, - csr_read(CSR_SCOUNTEREN) | (1 << pmu_sbi_csr_index(event))); + csr_read(CSR_SCOUNTEREN) | (1 << rvpmu_csr_index(event))); } -static void pmu_sbi_reset_scounteren(void *arg) +static void rvpmu_reset_scounteren(void *arg) { struct perf_event *event = (struct perf_event *)arg; if (event->hw.idx != -1) csr_write(CSR_SCOUNTEREN, - csr_read(CSR_SCOUNTEREN) & ~(1 << pmu_sbi_csr_index(event))); + csr_read(CSR_SCOUNTEREN) & ~(1 << rvpmu_csr_index(event))); } -static void pmu_sbi_ctr_start(struct perf_event *event, u64 ival) +static void rvpmu_sbi_ctr_start(struct perf_event *event, u64 ival) { struct sbiret ret; struct hw_perf_event *hwc = &event->hw; @@ -543,17 +545,17 @@ static void pmu_sbi_ctr_start(struct perf_event *event, u64 ival) if ((hwc->flags & PERF_EVENT_FLAG_USER_ACCESS) && (hwc->flags & PERF_EVENT_FLAG_USER_READ_CNT)) - pmu_sbi_set_scounteren((void *)event); + rvpmu_set_scounteren((void *)event); } -static void pmu_sbi_ctr_stop(struct perf_event *event, unsigned long flag) +static void rvpmu_sbi_ctr_stop(struct perf_event *event, unsigned long flag) { struct sbiret ret; struct hw_perf_event *hwc = &event->hw; if ((hwc->flags & PERF_EVENT_FLAG_USER_ACCESS) && (hwc->flags & PERF_EVENT_FLAG_USER_READ_CNT)) - pmu_sbi_reset_scounteren((void *)event); + rvpmu_reset_scounteren((void *)event); ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, hwc->idx, 1, flag, 0, 0, 0); if (ret.error && (ret.error != SBI_ERR_ALREADY_STOPPED) && @@ -562,7 +564,7 @@ static void pmu_sbi_ctr_stop(struct perf_event *event, unsigned long flag) hwc->idx, sbi_err_map_linux_errno(ret.error)); } -static int pmu_sbi_find_num_ctrs(void) +static int rvpmu_sbi_find_num_ctrs(void) { struct sbiret ret; @@ -573,7 +575,7 @@ static int pmu_sbi_find_num_ctrs(void) return sbi_err_map_linux_errno(ret.error); } -static int pmu_sbi_get_ctrinfo(int nctr, unsigned long *mask) +static int rvpmu_sbi_get_ctrinfo(int nctr, unsigned long *mask) { struct sbiret ret; int i, num_hw_ctr = 0, num_fw_ctr = 0; @@ -604,7 +606,7 @@ static int pmu_sbi_get_ctrinfo(int nctr, unsigned long *mask) return 0; } -static inline void pmu_sbi_stop_all(struct riscv_pmu *pmu) +static inline void rvpmu_sbi_stop_all(struct riscv_pmu *pmu) { /* * No need to check the error because we are disabling all the counters @@ -614,7 +616,7 @@ static inline void pmu_sbi_stop_all(struct riscv_pmu *pmu) 0, pmu->cmask, 0, 0, 0, 0); } -static inline void pmu_sbi_stop_hw_ctrs(struct riscv_pmu *pmu) +static inline void rvpmu_sbi_stop_hw_ctrs(struct riscv_pmu *pmu) { struct cpu_hw_events *cpu_hw_evt = this_cpu_ptr(pmu->hw_events); @@ -629,7 +631,7 @@ static inline void pmu_sbi_stop_hw_ctrs(struct riscv_pmu *pmu) * while the overflowed counters need to be started with updated initialization * value. */ -static inline void pmu_sbi_start_overflow_mask(struct riscv_pmu *pmu, +static inline void rvpmu_sbi_start_overflow_mask(struct riscv_pmu *pmu, unsigned long ctr_ovf_mask) { int idx = 0; @@ -668,7 +670,7 @@ static inline void pmu_sbi_start_overflow_mask(struct riscv_pmu *pmu, } } -static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev) +static irqreturn_t rvpmu_ovf_handler(int irq, void *dev) { struct perf_sample_data data; struct pt_regs *regs; @@ -699,7 +701,7 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev) } pmu = to_riscv_pmu(event->pmu); - pmu_sbi_stop_hw_ctrs(pmu); + rvpmu_sbi_stop_hw_ctrs(pmu); /* Overflow status register should only be read after counter are stopped */ ALT_SBI_PMU_OVERFLOW(overflow); @@ -755,13 +757,55 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev) } } - pmu_sbi_start_overflow_mask(pmu, overflowed_ctrs); + rvpmu_sbi_start_overflow_mask(pmu, overflowed_ctrs); perf_sample_event_took(sched_clock() - start_clock); return IRQ_HANDLED; } -static int pmu_sbi_starting_cpu(unsigned int cpu, struct hlist_node *node) +static void rvpmu_ctr_start(struct perf_event *event, u64 ival) +{ + rvpmu_sbi_ctr_start(event, ival); + /* TODO: Counter delegation implementation */ +} + +static void rvpmu_ctr_stop(struct perf_event *event, unsigned long flag) +{ + rvpmu_sbi_ctr_stop(event, flag); + /* TODO: Counter delegation implementation */ +} + +static int rvpmu_find_num_ctrs(void) +{ + return rvpmu_sbi_find_num_ctrs(); + /* TODO: Counter delegation implementation */ +} + +static int rvpmu_get_ctrinfo(int nctr, unsigned long *mask) +{ + return rvpmu_sbi_get_ctrinfo(nctr, mask); + /* TODO: Counter delegation implementation */ +} + +static int rvpmu_event_map(struct perf_event *event, u64 *econfig) +{ + return rvpmu_sbi_event_map(event, econfig); + /* TODO: Counter delegation implementation */ +} + +static int rvpmu_ctr_get_idx(struct perf_event *event) +{ + return rvpmu_sbi_ctr_get_idx(event); + /* TODO: Counter delegation implementation */ +} + +static u64 rvpmu_ctr_read(struct perf_event *event) +{ + return rvpmu_sbi_ctr_read(event); + /* TODO: Counter delegation implementation */ +} + +static int rvpmu_starting_cpu(unsigned int cpu, struct hlist_node *node) { struct riscv_pmu *pmu = hlist_entry_safe(node, struct riscv_pmu, node); struct cpu_hw_events *cpu_hw_evt = this_cpu_ptr(pmu->hw_events); @@ -776,7 +820,7 @@ static int pmu_sbi_starting_cpu(unsigned int cpu, struct hlist_node *node) csr_write(CSR_SCOUNTEREN, 0x2); /* Stop all the counters so that they can be enabled from perf */ - pmu_sbi_stop_all(pmu); + rvpmu_sbi_stop_all(pmu); if (riscv_pmu_use_irq) { cpu_hw_evt->irq = riscv_pmu_irq; @@ -788,7 +832,7 @@ static int pmu_sbi_starting_cpu(unsigned int cpu, struct hlist_node *node) return 0; } -static int pmu_sbi_dying_cpu(unsigned int cpu, struct hlist_node *node) +static int rvpmu_dying_cpu(unsigned int cpu, struct hlist_node *node) { if (riscv_pmu_use_irq) { disable_percpu_irq(riscv_pmu_irq); @@ -801,7 +845,7 @@ static int pmu_sbi_dying_cpu(unsigned int cpu, struct hlist_node *node) return 0; } -static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pdev) +static int rvpmu_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pdev) { int ret; struct cpu_hw_events __percpu *hw_events = pmu->hw_events; @@ -834,7 +878,7 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde return -ENODEV; } - ret = request_percpu_irq(riscv_pmu_irq, pmu_sbi_ovf_handler, "riscv-pmu", hw_events); + ret = request_percpu_irq(riscv_pmu_irq, rvpmu_ovf_handler, "riscv-pmu", hw_events); if (ret) { pr_err("registering percpu irq failed [%d]\n", ret); return ret; @@ -904,7 +948,7 @@ static void riscv_pmu_destroy(struct riscv_pmu *pmu) cpuhp_state_remove_instance(CPUHP_AP_PERF_RISCV_STARTING, &pmu->node); } -static void pmu_sbi_event_init(struct perf_event *event) +static void rvpmu_event_init(struct perf_event *event) { /* * The permissions are set at event_init so that we do not depend @@ -918,7 +962,7 @@ static void pmu_sbi_event_init(struct perf_event *event) event->hw.flags |= PERF_EVENT_FLAG_LEGACY; } -static void pmu_sbi_event_mapped(struct perf_event *event, struct mm_struct *mm) +static void rvpmu_event_mapped(struct perf_event *event, struct mm_struct *mm) { if (event->hw.flags & PERF_EVENT_FLAG_NO_USER_ACCESS) return; @@ -946,14 +990,14 @@ static void pmu_sbi_event_mapped(struct perf_event *event, struct mm_struct *mm) * that it is possible to do so to avoid any race. * And we must notify all cpus here because threads that currently run * on other cpus will try to directly access the counter too without - * calling pmu_sbi_ctr_start. + * calling rvpmu_sbi_ctr_start. */ if (event->hw.flags & PERF_EVENT_FLAG_USER_ACCESS) on_each_cpu_mask(mm_cpumask(mm), - pmu_sbi_set_scounteren, (void *)event, 1); + rvpmu_set_scounteren, (void *)event, 1); } -static void pmu_sbi_event_unmapped(struct perf_event *event, struct mm_struct *mm) +static void rvpmu_event_unmapped(struct perf_event *event, struct mm_struct *mm) { if (event->hw.flags & PERF_EVENT_FLAG_NO_USER_ACCESS) return; @@ -975,7 +1019,7 @@ static void pmu_sbi_event_unmapped(struct perf_event *event, struct mm_struct *m if (event->hw.flags & PERF_EVENT_FLAG_USER_ACCESS) on_each_cpu_mask(mm_cpumask(mm), - pmu_sbi_reset_scounteren, (void *)event, 1); + rvpmu_reset_scounteren, (void *)event, 1); } static void riscv_pmu_update_counter_access(void *info) @@ -1019,7 +1063,7 @@ static struct ctl_table sbi_pmu_sysctl_table[] = { { } }; -static int pmu_sbi_device_probe(struct platform_device *pdev) +static int rvpmu_device_probe(struct platform_device *pdev) { struct riscv_pmu *pmu = NULL; int ret = -ENODEV; @@ -1030,7 +1074,7 @@ static int pmu_sbi_device_probe(struct platform_device *pdev) if (!pmu) return -ENOMEM; - num_counters = pmu_sbi_find_num_ctrs(); + num_counters = rvpmu_find_num_ctrs(); if (num_counters < 0) { pr_err("SBI PMU extension doesn't provide any counters\n"); goto out_free; @@ -1043,10 +1087,10 @@ static int pmu_sbi_device_probe(struct platform_device *pdev) } /* cache all the information about counters now */ - if (pmu_sbi_get_ctrinfo(num_counters, &cmask)) + if (rvpmu_get_ctrinfo(num_counters, &cmask)) goto out_free; - ret = pmu_sbi_setup_irqs(pmu, pdev); + ret = rvpmu_setup_irqs(pmu, pdev); if (ret < 0) { pr_info("Perf sampling/filtering is not supported as sscof extension is not available\n"); pmu->pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT; @@ -1055,17 +1099,17 @@ static int pmu_sbi_device_probe(struct platform_device *pdev) pmu->pmu.attr_groups = riscv_pmu_attr_groups; pmu->cmask = cmask; - pmu->ctr_start = pmu_sbi_ctr_start; - pmu->ctr_stop = pmu_sbi_ctr_stop; - pmu->event_map = pmu_sbi_event_map; - pmu->ctr_get_idx = pmu_sbi_ctr_get_idx; - pmu->ctr_get_width = pmu_sbi_ctr_get_width; - pmu->ctr_clear_idx = pmu_sbi_ctr_clear_idx; - pmu->ctr_read = pmu_sbi_ctr_read; - pmu->event_init = pmu_sbi_event_init; - pmu->event_mapped = pmu_sbi_event_mapped; - pmu->event_unmapped = pmu_sbi_event_unmapped; - pmu->csr_index = pmu_sbi_csr_index; + pmu->ctr_start = rvpmu_ctr_start; + pmu->ctr_stop = rvpmu_ctr_stop; + pmu->event_map = rvpmu_event_map; + pmu->ctr_get_idx = rvpmu_ctr_get_idx; + pmu->ctr_get_width = rvpmu_ctr_get_width; + pmu->ctr_clear_idx = rvpmu_ctr_clear_idx; + pmu->ctr_read = rvpmu_ctr_read; + pmu->event_init = rvpmu_event_init; + pmu->event_mapped = rvpmu_event_mapped; + pmu->event_unmapped = rvpmu_event_unmapped; + pmu->csr_index = rvpmu_csr_index; ret = cpuhp_state_add_instance(CPUHP_AP_PERF_RISCV_STARTING, &pmu->node); if (ret) @@ -1091,14 +1135,14 @@ static int pmu_sbi_device_probe(struct platform_device *pdev) return ret; } -static struct platform_driver pmu_sbi_driver = { - .probe = pmu_sbi_device_probe, +static struct platform_driver rvpmu_driver = { + .probe = rvpmu_device_probe, .driver = { - .name = RISCV_PMU_SBI_PDEV_NAME, + .name = RISCV_PMU_PDEV_NAME, }, }; -static int __init pmu_sbi_devinit(void) +static int __init rvpmu_devinit(void) { int ret; struct platform_device *pdev; @@ -1110,20 +1154,20 @@ static int __init pmu_sbi_devinit(void) ret = cpuhp_setup_state_multi(CPUHP_AP_PERF_RISCV_STARTING, "perf/riscv/pmu:starting", - pmu_sbi_starting_cpu, pmu_sbi_dying_cpu); + rvpmu_starting_cpu, rvpmu_dying_cpu); if (ret) { pr_err("CPU hotplug notifier could not be registered: %d\n", ret); return ret; } - ret = platform_driver_register(&pmu_sbi_driver); + ret = platform_driver_register(&rvpmu_driver); if (ret) return ret; - pdev = platform_device_register_simple(RISCV_PMU_SBI_PDEV_NAME, -1, NULL, 0); + pdev = platform_device_register_simple(RISCV_PMU_PDEV_NAME, -1, NULL, 0); if (IS_ERR(pdev)) { - platform_driver_unregister(&pmu_sbi_driver); + platform_driver_unregister(&rvpmu_driver); return PTR_ERR(pdev); } @@ -1132,4 +1176,4 @@ static int __init pmu_sbi_devinit(void) return ret; } -device_initcall(pmu_sbi_devinit) +device_initcall(rvpmu_devinit) diff --git a/include/linux/perf/riscv_pmu.h b/include/linux/perf/riscv_pmu.h index 43282e22ebe1..3d2b1d7913f3 100644 --- a/include/linux/perf/riscv_pmu.h +++ b/include/linux/perf/riscv_pmu.h @@ -13,7 +13,7 @@ #include #include -#ifdef CONFIG_RISCV_PMU +#ifdef CONFIG_RISCV_PMU_COMMON /* * The RISCV_MAX_COUNTERS parameter should be specified. @@ -21,7 +21,7 @@ #define RISCV_MAX_COUNTERS 64 #define RISCV_OP_UNSUPP (-EOPNOTSUPP) -#define RISCV_PMU_SBI_PDEV_NAME "riscv-pmu-sbi" +#define RISCV_PMU_PDEV_NAME "riscv-pmu" #define RISCV_PMU_LEGACY_PDEV_NAME "riscv-pmu-legacy" #define RISCV_PMU_STOP_FLAG_RESET 1 @@ -79,10 +79,10 @@ void riscv_pmu_legacy_skip_init(void); static inline void riscv_pmu_legacy_skip_init(void) {}; #endif struct riscv_pmu *riscv_pmu_alloc(void); -#ifdef CONFIG_RISCV_PMU_SBI +#ifdef CONFIG_RISCV_PMU int riscv_pmu_get_hpm_info(u32 *hw_ctr_width, u32 *num_hw_ctr); #endif -#endif /* CONFIG_RISCV_PMU */ +#endif /* CONFIG_RISCV_PMU_COMMON */ #endif /* _RISCV_PMU_H */ From patchwork Sat Feb 17 00:57:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561162 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 34F46C48BF5 for ; Sat, 17 Feb 2024 00:59:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=y7+FEfaEiBGSF/VTWnHiIlnK9D9pS+7HMlMfU+2M+3Y=; b=kM0bpDwz97uOLR anMBHElVAvqFCsEWSJ8Gq2sDeDvwXs9S6O4n54CVpGEdYj7L7A1w+RYsqYQ4P+iC1IXaX1upE8vKN WUpL3kF5571Lrsspayi9p19HYB1BPR8EIKCZBiK1k48ObrOTi1UUYJ8vOcu6dLi0fL/vEa7Qr3ZuV ksdC8nSpP3TtsrDc3E2bjcNNWaw6FPys4ZNsD0BDODY1JynrD6wClXgsNyXBf/eOSIpxYifUsZSYW Twt7l2Qb9tG+xrCHKJQ+drAXtL9v/v/rgGHgZYdDZdIaiMEr6XiYF/MI2YzG8ZVCtWCbnOmYsuIQj M3xMAmSVOLfsi2MF9Yxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb93Z-00000004JHZ-2NZr; Sat, 17 Feb 2024 00:59:53 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb930-00000004IkU-1TsQ for linux-riscv@bombadil.infradead.org; Sat, 17 Feb 2024 00:59:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=JIGj4g715G6yohgyO/4Q0tCiDPX2tJrcO1/uwFaLqes=; b=QdvL7eHF5burAYAYl60MBGPFVQ jB71oC79oPVU51iSQDhGNZzmP83Ff1EFps50Sn1AirhrI//342Gqvcwznp/z8YkwZs063sjXLtnnj X6FYGFZghBho2qlWNO9lly3A9LVyyAAXLibi4PB+vO3n2ntkB56/XDgBKe5tng9fL3ud7ZxsqX5lu 8IZ5XDnFrXEmWEnm4iXwkIcjGOJ2D26ryc7wCGA4WWJQ9sA4hDDlDnM2XpPOHAiBbBiLpr/gUctPr lfQPazF0jMksozh0Z0xa7xbam6kttTH8M3lrFjnzcMIwEXfRBqV79Udj6L4IpUC/9CpkrdeMtcf8/ S1inCC3g==; Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92X-000000007JI-47Qi for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:59:12 +0000 Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-364f791a428so8149035ab.3 for ; Fri, 16 Feb 2024 16:58:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131525; x=1708736325; darn=lists.infradead.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=JIGj4g715G6yohgyO/4Q0tCiDPX2tJrcO1/uwFaLqes=; b=pyGhu9P/ufBDPNOHnbMBCLQLuPKyv6oKeUAChtSot4T+hR8ur3d9EhgPGMDWNH7TII QORo6y18q5VdomKs/BRAWL6zJrr2wqS4Mos0vIlMW+vEXiLlNENgda5OrhaEhOMkTvEJ gAfd1unqp8GS0I84j0M3u2dYxC8iYALlWaFJkzn2ceH9DuhFLeEdBgSqMYoQGBKgXcZL MuQtFkVYmvZ8W/PilAtSw1PsC67dnBDlqJwQuMXOm85xavfyFyIGTpyM8zkYHXwtsOov gHaaqh3jyUOKqLfdB/BmrvfENhUYTTbdWLSSh6lkSXqhRhXZmkfumNkrwYywYCjf+Sm8 Tjuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131525; x=1708736325; 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=JIGj4g715G6yohgyO/4Q0tCiDPX2tJrcO1/uwFaLqes=; b=uz7O0a1/c1l3xQ/epwZtnALkV9iOIT9pkKVgYpGxzfjnLDRmNtISVIOWjm8texvL+M PpTBGstFraWsokbCmskH0ueWVLd6GPDNWQEr1q2/7k3EyQu58ilaVOCS4YAmgsst3hrt nBL+q4TvQvvoEdIVupcqIX9USOeVSI5VggGVbtw1OuNR3qfDPccB+bZrDBdz8TFdmShg O2NFHfK7N7XnIHnJT1ogeQn7ewkCUEFljfvYEOnBv47IsNGpfcmTscpMMUARwxzF/WLI bcQNx/x2Qm4QHe2gJp6PMuIQ/bnwFbdL3VeNScI5rCf15A4IUwumOEy7BpAdh/u86wip iOXA== X-Forwarded-Encrypted: i=1; AJvYcCV/4RQ3pDX4x0aVjzeebMAs5r2GY04s/yJkLzCjprakA7qi+CcQZt8GyJN2gFt5GGpLQLybvTv+uxls3a0tS/7LOcnH2qBgLjwKfed6RAd7 X-Gm-Message-State: AOJu0YwBS+n9cqlhiF1xVIfzdBu+f3O0HkqSMH1HTihj9alrHCGrD1VR uzbIxiJFiY3CzP1HkiOi8x2UHreObk7+M6B5h3L4bnkXqh3v30R2JAGiidtTn10= X-Google-Smtp-Source: AGHT+IF+X2u5pVrDfJiSLKIz3PkBfnEp1Eo29CwD/FNCbs9zzOknJEUhVT4g49rCOyNlyB3Z65pvKw== X-Received: by 2002:a92:d081:0:b0:365:156:bb86 with SMTP id h1-20020a92d081000000b003650156bb86mr4612456ilh.2.1708131525473; Fri, 16 Feb 2024 16:58:45 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:45 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 12/20] RISC-V: perf: Modify the counter discovery mechanism Date: Fri, 16 Feb 2024 16:57:30 -0800 Message-Id: <20240217005738.3744121-13-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240217_005853_670078_8B05B945 X-CRM114-Status: GOOD ( 27.17 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org If both counter delegation and SBI PMU is present, the counter delegation will be used for hardware pmu counters while the SBI PMU will be used for firmware counters. Thus, the driver has to probe the counters info via SBI PMU to distinguish the firmware counters. The hybrid scheme also requires improvements of the informational logging messages to indicate the user about underlying interface used for each use case. Signed-off-by: Atish Patra --- drivers/perf/riscv_pmu_dev.c | 120 ++++++++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 30 deletions(-) diff --git a/drivers/perf/riscv_pmu_dev.c b/drivers/perf/riscv_pmu_dev.c index 3d27bd65f140..dfc0ddee9da4 100644 --- a/drivers/perf/riscv_pmu_dev.c +++ b/drivers/perf/riscv_pmu_dev.c @@ -35,6 +35,11 @@ PMU_FORMAT_ATTR(event, "config:0-47"); PMU_FORMAT_ATTR(firmware, "config:63"); +static DEFINE_STATIC_KEY_FALSE(riscv_pmu_sbi_available); +static DEFINE_STATIC_KEY_FALSE(riscv_pmu_cdeleg_available); +static bool cdeleg_available; +static bool sbi_available; + static struct attribute *riscv_arch_formats_attr[] = { &format_attr_event.attr, &format_attr_firmware.attr, @@ -56,7 +61,8 @@ static int sysctl_perf_user_access __read_mostly = SYSCTL_USER_ACCESS; /* * This structure is SBI specific but counter delegation also require counter - * width, csr mapping. Reuse it for now. + * width, csr mapping. Reuse it for now we can have firmware counters for + * platfroms with counter delegation support. * RISC-V doesn't have heterogeneous harts yet. This need to be part of * per_cpu in case of harts with different pmu counters */ @@ -67,6 +73,8 @@ static unsigned int riscv_pmu_irq; /* Cache the available counters in a bitmask */ static unsigned long cmask; +/* Cache the available firmware counters in another bitmask */ +static unsigned long firmware_cmask; struct sbi_pmu_event_data { union { @@ -575,35 +583,49 @@ static int rvpmu_sbi_find_num_ctrs(void) return sbi_err_map_linux_errno(ret.error); } -static int rvpmu_sbi_get_ctrinfo(int nctr, unsigned long *mask) +static int rvpmu_deleg_find_ctrs(void) +{ + /* TODO */ + return -1; +} + +static int rvpmu_sbi_get_ctrinfo(int nsbi_ctr, int ndeleg_ctr) { struct sbiret ret; - int i, num_hw_ctr = 0, num_fw_ctr = 0; + int i, num_hw_ctr = 0, num_fw_ctr = 0, num_ctr = 0; union sbi_pmu_ctr_info cinfo; - pmu_ctr_list = kcalloc(nctr, sizeof(*pmu_ctr_list), GFP_KERNEL); - if (!pmu_ctr_list) - return -ENOMEM; - - for (i = 0; i < nctr; i++) { + for (i = 0; i < nsbi_ctr; i++) { ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_GET_INFO, i, 0, 0, 0, 0, 0); if (ret.error) /* The logical counter ids are not expected to be contiguous */ continue; - *mask |= BIT(i); - cinfo.value = ret.value; if (cinfo.type == SBI_PMU_CTR_TYPE_FW) num_fw_ctr++; - else + + if (!cdeleg_available) { num_hw_ctr++; - pmu_ctr_list[i].value = cinfo.value; + cmask |= BIT(i); + pmu_ctr_list[i].value = cinfo.value; + } else if (cinfo.type == SBI_PMU_CTR_TYPE_FW) { + /* Track firmware counters in a different mask */ + firmware_cmask |= BIT(i); + pmu_ctr_list[i].value = cinfo.value; + } + } - pr_info("%d firmware and %d hardware counters\n", num_fw_ctr, num_hw_ctr); + if (cdeleg_available) { + pr_info("%d firmware and %d hardware counters\n", num_fw_ctr, ndeleg_ctr); + num_ctr = num_fw_ctr + ndeleg_ctr; + } else { + pr_info("%d firmware and %d hardware counters\n", num_fw_ctr, num_hw_ctr); + num_ctr = nsbi_ctr; + } - return 0; + return num_ctr; } static inline void rvpmu_sbi_stop_all(struct riscv_pmu *pmu) @@ -775,16 +797,33 @@ static void rvpmu_ctr_stop(struct perf_event *event, unsigned long flag) /* TODO: Counter delegation implementation */ } -static int rvpmu_find_num_ctrs(void) +static int rvpmu_find_ctrs(void) { - return rvpmu_sbi_find_num_ctrs(); - /* TODO: Counter delegation implementation */ -} + int num_sbi_counters = 0, num_deleg_counters = 0, num_counters = 0; -static int rvpmu_get_ctrinfo(int nctr, unsigned long *mask) -{ - return rvpmu_sbi_get_ctrinfo(nctr, mask); - /* TODO: Counter delegation implementation */ + /* + * We don't know how many firmware counters available. Just allocate + * for maximum counters driver can support. The default is 64 anyways. + */ + pmu_ctr_list = kcalloc(RISCV_MAX_COUNTERS, sizeof(*pmu_ctr_list), + GFP_KERNEL); + if (!pmu_ctr_list) + return -ENOMEM; + + if (cdeleg_available) + num_deleg_counters = rvpmu_deleg_find_ctrs(); + + /* This is required for firmware counters even if the above is true */ + if (sbi_available) + num_sbi_counters = rvpmu_sbi_find_num_ctrs(); + + if (num_sbi_counters >= RISCV_MAX_COUNTERS || num_deleg_counters >= RISCV_MAX_COUNTERS) + return -ENOSPC; + + /* cache all the information about counters now */ + num_counters = rvpmu_sbi_get_ctrinfo(num_sbi_counters, num_deleg_counters); + + return num_counters; } static int rvpmu_event_map(struct perf_event *event, u64 *econfig) @@ -1069,12 +1108,21 @@ static int rvpmu_device_probe(struct platform_device *pdev) int ret = -ENODEV; int num_counters; - pr_info("SBI PMU extension is available\n"); + if (cdeleg_available) { + pr_info("hpmcounters will use the counter delegation ISA extension\n"); + if (sbi_available) + pr_info("Firmware counters will be use SBI PMU extension\n"); + else + pr_info("Firmware counters will be not available as SBI PMU extension is not present\n"); + } else if (sbi_available) { + pr_info("Both hpmcounters and firmware counters will use SBI PMU extension\n"); + } + pmu = riscv_pmu_alloc(); if (!pmu) return -ENOMEM; - num_counters = rvpmu_find_num_ctrs(); + num_counters = rvpmu_find_ctrs(); if (num_counters < 0) { pr_err("SBI PMU extension doesn't provide any counters\n"); goto out_free; @@ -1086,9 +1134,6 @@ static int rvpmu_device_probe(struct platform_device *pdev) pr_info("SBI returned more than maximum number of counters. Limiting the number of counters to %d\n", num_counters); } - /* cache all the information about counters now */ - if (rvpmu_get_ctrinfo(num_counters, &cmask)) - goto out_free; ret = rvpmu_setup_irqs(pmu, pdev); if (ret < 0) { @@ -1147,11 +1192,26 @@ static int __init rvpmu_devinit(void) int ret; struct platform_device *pdev; - if (sbi_spec_version < sbi_mk_version(0, 3) || - !sbi_probe_extension(SBI_EXT_PMU)) { - return 0; + if (sbi_spec_version >= sbi_mk_version(0, 3) && + sbi_probe_extension(SBI_EXT_PMU)) { + static_branch_enable(&riscv_pmu_sbi_available); + sbi_available = true; + } + + /* + * We need all three extensions to be present to access the counters + * in S-mode via Supervisor Counter delegation. + */ + if (riscv_isa_extension_available(NULL, SSCCFG) && + riscv_isa_extension_available(NULL, SMCDELEG) && + riscv_isa_extension_available(NULL, SSCSRIND)) { + static_branch_enable(&riscv_pmu_cdeleg_available); + cdeleg_available = true; } + if (!(sbi_available || cdeleg_available)) + return 0; + ret = cpuhp_setup_state_multi(CPUHP_AP_PERF_RISCV_STARTING, "perf/riscv/pmu:starting", rvpmu_starting_cpu, rvpmu_dying_cpu); From patchwork Sat Feb 17 00:57:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2ACBC48BF5 for ; Sat, 17 Feb 2024 00:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=msRelxv0RFxis+kqnmTZRCGF/dC+9C9NFyzoWbXOSEg=; b=nrxAywEN1LvsMR kruBAwK7aqmMHylUiSFQd83sEH6y7aHg/vNwqgLW+GhjPdy8YC25mt33qL9NnKmhkkceh5/j5xGLU 0h3ii8YdzmZx5bjEe4oLodBWolH6LyHRGVuXPfSYAuT4ZvZnuImTBL1a6pP9/QaYbIDmwsAkSIWW6 uzhYvoJzMpNrCflYevYPFWkrmsrkoxVLp+LHstbNe6ztjFg66MPK/GQd050R+lf6POZZhP1Yfwog4 wg3otxPk++IatmsJ+IWa6Z16a3PIdZBw9XaiNxlLGhVBxaxNP4Jfffp67YbHUbYMgcdeY+uN92JKs d2IyTzTVNx5H+edcsjUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92v-00000004Ifa-2CJc; Sat, 17 Feb 2024 00:59:13 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92X-00000004ILT-3G4I for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:59:03 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-204235d0913so985103fac.1 for ; Fri, 16 Feb 2024 16:58:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131528; x=1708736328; darn=lists.infradead.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=HfeB7JYlXDGaZw65RVXErpfWL8gtCGpiY1jb8zlR4wA=; b=sjw4Kxludr5k1zxgGiReiM2sFnOOrSQ5zxRhV2kcHNLK7u57zSL3d7B+aAHjd73Yjr XmBkIAiiPKgeYYJ6OZnpaqoNtM6Il7tAUNaOS+YiqB+h0Q7erjGcmUFvXActEEJjRbFz 8v7TlKxuYPWw/HgIXgJzMgF3BbYVQyaOxawl62b7er15w1JMpwiTPAi1E/xXvY3D0nVA XNNjtA4TrxB4itZwpVoBLBfhMqkwqYXx4nPhONonXp3XcJhGhhoEDPsHk00dIvBgHwko BAvycc3d4QHi6ovDpZ19RqriWuPgusVqjNwNh6/2eZHnDZs4xHhTMuK739DxKU35JOHh MWIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131528; x=1708736328; 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=HfeB7JYlXDGaZw65RVXErpfWL8gtCGpiY1jb8zlR4wA=; b=SaXYZ8MmrtEXs3rUG+AkbJ6DyIRpEfX9ik8drP7oAE4O98tMxcZfZg9bj+tq7g6VT8 ZrTEPCppQcESeEYPML13qCXyXmLB4TALn+zUArJNA2eb5sDfWpHYmd17xNdZ/2w8S3yZ cQdLsDjIjobczBBkgWqySNPsA1WfeVwe2x6ktJQu2l/J3ayCchPfU2YAzXyqfH5taSa2 uCHbdt8D12yy52NUs4mxfY/FhNvmGDqjthSZ+CGayMCRMSYXvP2g+ZrfQ31waga6zgIg fWZLPDutSE4WLGhR/QVxIAhDtZbqwMOfwUq0Qq2337Y74JB9wckjguyARtTY4V9mMXmJ Tkeg== X-Forwarded-Encrypted: i=1; AJvYcCUlS8gV/ZkAzqwV9jtVAkD1mw0hA/VCj7ZrVrIoqChz0K9y8Ol5kJ/lZc7ctyYPymjR+Xq55UHpMCH19TjuMrKwZ4LzV//MDPEetigLpoFp X-Gm-Message-State: AOJu0YyAxeMEy1Ai8kPXzfLy9jDbJCAq5kyFaUnt9L4fHv/u3od8iNLd Q5NVN/01/+1Bn6oNJqcnDDbGuHILiTxvHjYst9YkccwJQX2yK8maF9hQEZmc6oY= X-Google-Smtp-Source: AGHT+IFFZ3X88HR6RYt1MMNPiWVJNj8Aa/iDSy7euok8DzEZ8WyuLJr/udPPXDrFxWGsgBos41HN4g== X-Received: by 2002:a05:6870:d88d:b0:218:df68:87b2 with SMTP id oe13-20020a056870d88d00b00218df6887b2mr6753363oac.44.1708131528256; Fri, 16 Feb 2024 16:58:48 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:47 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 13/20] RISC-V: perf: Implement supervisor counter delegation support Date: Fri, 16 Feb 2024 16:57:31 -0800 Message-Id: <20240217005738.3744121-14-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165850_163046_3DA171B1 X-CRM114-Status: GOOD ( 30.95 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org There are few new RISC-V ISA exensions (ssccfg, sscsrind, smcntrpmf) which allows the hpmcounter/hpmevents to be programmed directly from S-mode. The implementation detects the ISA extension at runtime and uses them if available instead of SBI PMU extension. SBI PMU extension will still be used for firmware counters if the user requests it. The current linux driver relies on event encoding defined by SBI PMU specification for standard perf events. However, there are no standard event encoding available in the ISA. In the future, we may want to decouple the counter delegation and SBI PMU completely. In that case, counter delegation supported platforms must rely on the event encoding defined in the perf json file only. For firmware events, it will continue to use the SBI PMU encoding as one can not support firmware event without SBI PMU. Signed-off-by: Atish Patra --- arch/riscv/include/asm/csr.h | 1 + arch/riscv/include/asm/sbi.h | 2 +- arch/riscv/kvm/vcpu_pmu.c | 2 +- drivers/perf/riscv_pmu_dev.c | 428 ++++++++++++++++++++++++++++----- include/linux/perf/riscv_pmu.h | 3 + 5 files changed, 369 insertions(+), 67 deletions(-) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index e1bf1466f32e..efcd956c517a 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -239,6 +239,7 @@ #endif #define SISELECT_SSCCFG_BASE 0x40 +#define HPMEVENT_MASK GENMASK_ULL(63, 56) /* symbolic CSR names: */ #define CSR_CYCLE 0xc00 diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 6e68f8dff76b..ad0c8a686d6c 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -147,7 +147,7 @@ union sbi_pmu_ctr_info { }; }; -#define RISCV_PMU_RAW_EVENT_MASK GENMASK_ULL(47, 0) +#define RISCV_PMU_SBI_RAW_EVENT_MASK GENMASK_ULL(47, 0) #define RISCV_PMU_RAW_EVENT_IDX 0x20000 /** General pmu event codes specified in SBI PMU extension */ diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c index 86391a5061dd..4c9502a79a54 100644 --- a/arch/riscv/kvm/vcpu_pmu.c +++ b/arch/riscv/kvm/vcpu_pmu.c @@ -125,7 +125,7 @@ static u64 kvm_pmu_get_perf_event_config(unsigned long eidx, uint64_t evt_data) config = kvm_pmu_get_perf_event_cache_config(ecode); break; case SBI_PMU_EVENT_TYPE_RAW: - config = evt_data & RISCV_PMU_RAW_EVENT_MASK; + config = evt_data & RISCV_PMU_SBI_RAW_EVENT_MASK; break; case SBI_PMU_EVENT_TYPE_FW: if (ecode < SBI_PMU_FW_MAX) diff --git a/drivers/perf/riscv_pmu_dev.c b/drivers/perf/riscv_pmu_dev.c index dfc0ddee9da4..0cdad0dafb71 100644 --- a/drivers/perf/riscv_pmu_dev.c +++ b/drivers/perf/riscv_pmu_dev.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #define SYSCTL_NO_USER_ACCESS 0 #define SYSCTL_USER_ACCESS 1 @@ -32,7 +34,20 @@ #define PERF_EVENT_FLAG_USER_ACCESS BIT(SYSCTL_USER_ACCESS) #define PERF_EVENT_FLAG_LEGACY BIT(SYSCTL_LEGACY) -PMU_FORMAT_ATTR(event, "config:0-47"); +#define RVPMU_SBI_PMU_FORMAT_ATTR "config:0-47" +#define RVPMU_CDELEG_PMU_FORMAT_ATTR "config:0-55" + +static ssize_t __maybe_unused rvpmu_format_show(struct device *dev, + struct device_attribute *attr, char *buf); + +#define RVPMU_ATTR_ENTRY(_name, _func, _config) ( \ + &((struct dev_ext_attribute[]) { \ + { __ATTR(_name, 0444, _func, NULL), (void *)_config } \ + })[0].attr.attr) + +#define RVPMU_FORMAT_ATTR_ENTRY(_name, _config) \ + RVPMU_ATTR_ENTRY(_name, rvpmu_format_show, (char *)_config) + PMU_FORMAT_ATTR(firmware, "config:63"); static DEFINE_STATIC_KEY_FALSE(riscv_pmu_sbi_available); @@ -40,19 +55,35 @@ static DEFINE_STATIC_KEY_FALSE(riscv_pmu_cdeleg_available); static bool cdeleg_available; static bool sbi_available; -static struct attribute *riscv_arch_formats_attr[] = { - &format_attr_event.attr, +static struct attribute *riscv_sbi_pmu_formats_attr[] = { + RVPMU_FORMAT_ATTR_ENTRY(event, RVPMU_SBI_PMU_FORMAT_ATTR), + &format_attr_firmware.attr, + NULL, +}; + +static struct attribute_group riscv_sbi_pmu_format_group = { + .name = "format", + .attrs = riscv_sbi_pmu_formats_attr, +}; + +static const struct attribute_group *riscv_sbi_pmu_attr_groups[] = { + &riscv_sbi_pmu_format_group, + NULL, +}; + +static struct attribute *riscv_cdeleg_pmu_formats_attr[] = { + RVPMU_FORMAT_ATTR_ENTRY(event, RVPMU_CDELEG_PMU_FORMAT_ATTR), &format_attr_firmware.attr, NULL, }; -static struct attribute_group riscv_pmu_format_group = { +static struct attribute_group riscv_cdeleg_pmu_format_group = { .name = "format", - .attrs = riscv_arch_formats_attr, + .attrs = riscv_cdeleg_pmu_formats_attr, }; -static const struct attribute_group *riscv_pmu_attr_groups[] = { - &riscv_pmu_format_group, +static const struct attribute_group *riscv_cdeleg_pmu_attr_groups[] = { + &riscv_cdeleg_pmu_format_group, NULL, }; @@ -275,6 +306,14 @@ static const struct sbi_pmu_event_data pmu_cache_event_map[PERF_COUNT_HW_CACHE_M }, }; +static ssize_t rvpmu_format_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct dev_ext_attribute *eattr = container_of(attr, + struct dev_ext_attribute, attr); + return sysfs_emit(buf, "%s\n", (char *)eattr->var); +} + static int rvpmu_ctr_get_width(int idx) { return pmu_ctr_list[idx].width; @@ -327,6 +366,39 @@ static uint8_t rvpmu_csr_index(struct perf_event *event) return pmu_ctr_list[event->hw.idx].csr - CSR_CYCLE; } +static uint64_t get_deleg_priv_filter_bits(struct perf_event *event) +{ + uint64_t priv_filter_bits = 0; + bool guest_events = false; + + if (event->attr.config1 & RISCV_PMU_CONFIG1_GUEST_EVENTS) + guest_events = true; + if (event->attr.exclude_kernel) + priv_filter_bits |= guest_events ? HPMEVENT_VSINH : HPMEVENT_SINH; + if (event->attr.exclude_user) + priv_filter_bits |= guest_events ? HPMEVENT_VUINH : HPMEVENT_UINH; + if (guest_events && event->attr.exclude_hv) + priv_filter_bits |= HPMEVENT_SINH; + if (event->attr.exclude_host) + priv_filter_bits |= HPMEVENT_UINH | HPMEVENT_SINH; + if (event->attr.exclude_guest) + priv_filter_bits |= HPMEVENT_VSINH | HPMEVENT_VUINH; + + + return priv_filter_bits; +} + +static bool pmu_sbi_is_fw_event(struct perf_event *event) +{ + u32 type = event->attr.type; + u64 config = event->attr.config; + + if ((type == PERF_TYPE_RAW) && ((config >> 63) == 1)) + return true; + else + return false; +} + static unsigned long rvpmu_sbi_get_filter_flags(struct perf_event *event) { unsigned long cflags = 0; @@ -355,7 +427,8 @@ static int rvpmu_sbi_ctr_get_idx(struct perf_event *event) struct cpu_hw_events *cpuc = this_cpu_ptr(rvpmu->hw_events); struct sbiret ret; int idx; - uint64_t cbase = 0, cmask = rvpmu->cmask; + uint64_t cbase = 0; + unsigned long ctr_mask = rvpmu->cmask; unsigned long cflags = 0; cflags = rvpmu_sbi_get_filter_flags(event); @@ -368,21 +441,24 @@ static int rvpmu_sbi_ctr_get_idx(struct perf_event *event) if (hwc->flags & PERF_EVENT_FLAG_LEGACY) { if (event->attr.config == PERF_COUNT_HW_CPU_CYCLES) { cflags |= SBI_PMU_CFG_FLAG_SKIP_MATCH; - cmask = 1; + ctr_mask = 1; } else if (event->attr.config == PERF_COUNT_HW_INSTRUCTIONS) { cflags |= SBI_PMU_CFG_FLAG_SKIP_MATCH; - cmask = 1UL << (CSR_INSTRET - CSR_CYCLE); + ctr_mask = 1UL << (CSR_INSTRET - CSR_CYCLE); } } + if (pmu_sbi_is_fw_event(event) && cdeleg_available) + ctr_mask = firmware_cmask; + /* retrieve the available counter index */ #if defined(CONFIG_32BIT) ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH, cbase, - cmask, cflags, hwc->event_base, hwc->config, + ctr_mask, cflags, hwc->event_base, hwc->config, hwc->config >> 32); #else ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH, cbase, - cmask, cflags, hwc->event_base, hwc->config, 0); + ctr_mask, cflags, hwc->event_base, hwc->config, 0); #endif if (ret.error) { pr_debug("Not able to find a counter for event %lx config %llx\n", @@ -391,7 +467,7 @@ static int rvpmu_sbi_ctr_get_idx(struct perf_event *event) } idx = ret.value; - if (!test_bit(idx, &rvpmu->cmask) || !pmu_ctr_list[idx].value) + if (!test_bit(idx, &ctr_mask) || !pmu_ctr_list[idx].value) return -ENOENT; /* Additional sanity check for the counter id */ @@ -441,15 +517,20 @@ static int pmu_event_find_cache(u64 config) return ret; } -static bool pmu_sbi_is_fw_event(struct perf_event *event) +static int rvpmu_deleg_event_map(struct perf_event *event, u64 *econfig) { - u32 type = event->attr.type; u64 config = event->attr.config; - if ((type == PERF_TYPE_RAW) && ((config >> 63) == 1)) - return true; - else - return false; + /* + * The Perf tool for RISC-V is expected to remap the standard perf event to platform + * specific encoding if counter delegation extension is present. + * Thus, the mapped value should be event encoding value specified in the userspace + * There is no additional mapping/validation can be done in the driver. + */ + *econfig = config & RISCV_PMU_DELEG_RAW_EVENT_MASK; + + /* event_base is not used for counter delegation config is sufficient for event encoding */ + return 0; } static int rvpmu_sbi_event_map(struct perf_event *event, u64 *econfig) @@ -476,7 +557,7 @@ static int rvpmu_sbi_event_map(struct perf_event *event, u64 *econfig) * raw event and firmware events. */ bSoftware = config >> 63; - raw_config_val = config & RISCV_PMU_RAW_EVENT_MASK; + raw_config_val = config & RISCV_PMU_SBI_RAW_EVENT_MASK; if (bSoftware) { ret = (raw_config_val & 0xFFFF) | (SBI_PMU_EVENT_TYPE_FW << 16); @@ -493,7 +574,7 @@ static int rvpmu_sbi_event_map(struct perf_event *event, u64 *econfig) return ret; } -static u64 rvpmu_sbi_ctr_read(struct perf_event *event) +static u64 rvpmu_ctr_read(struct perf_event *event) { struct hw_perf_event *hwc = &event->hw; int idx = hwc->idx; @@ -550,10 +631,6 @@ static void rvpmu_sbi_ctr_start(struct perf_event *event, u64 ival) if (ret.error && (ret.error != SBI_ERR_ALREADY_STARTED)) pr_err("Starting counter idx %d failed with error %d\n", hwc->idx, sbi_err_map_linux_errno(ret.error)); - - if ((hwc->flags & PERF_EVENT_FLAG_USER_ACCESS) && - (hwc->flags & PERF_EVENT_FLAG_USER_READ_CNT)) - rvpmu_set_scounteren((void *)event); } static void rvpmu_sbi_ctr_stop(struct perf_event *event, unsigned long flag) @@ -561,10 +638,6 @@ static void rvpmu_sbi_ctr_stop(struct perf_event *event, unsigned long flag) struct sbiret ret; struct hw_perf_event *hwc = &event->hw; - if ((hwc->flags & PERF_EVENT_FLAG_USER_ACCESS) && - (hwc->flags & PERF_EVENT_FLAG_USER_READ_CNT)) - rvpmu_reset_scounteren((void *)event); - ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, hwc->idx, 1, flag, 0, 0, 0); if (ret.error && (ret.error != SBI_ERR_ALREADY_STOPPED) && flag != SBI_PMU_STOP_FLAG_RESET) @@ -583,12 +656,6 @@ static int rvpmu_sbi_find_num_ctrs(void) return sbi_err_map_linux_errno(ret.error); } -static int rvpmu_deleg_find_ctrs(void) -{ - /* TODO */ - return -1; -} - static int rvpmu_sbi_get_ctrinfo(int nsbi_ctr, int ndeleg_ctr) { struct sbiret ret; @@ -647,19 +714,85 @@ static inline void rvpmu_sbi_stop_hw_ctrs(struct riscv_pmu *pmu) cpu_hw_evt->used_hw_ctrs[0], 0, 0, 0, 0); } +static void rvpmu_deleg_ctr_start_mask(unsigned long mask) +{ + unsigned long scountinhibit_val = 0; + + scountinhibit_val = csr_read(CSR_SCOUNTINHIBIT); + scountinhibit_val &= ~mask; + + csr_write(CSR_SCOUNTINHIBIT, scountinhibit_val); +} + +static void rvpmu_deleg_ctr_enable_irq(struct perf_event *event) +{ + unsigned long hpmevent_curr; + unsigned long of_mask; + struct hw_perf_event *hwc = &event->hw; + int counter_idx = hwc->idx; + unsigned long sip_val = csr_read(CSR_SIP); + + if (!is_sampling_event(event) || (sip_val & SIP_LCOFIP)) + return; + +#if defined(CONFIG_32BIT) + hpmevent_curr = csr_ind_read(CSR_SIREG5, SISELECT_SSCCFG_BASE, counter_idx); + of_mask = (u32)~HPMEVENTH_OF; +#else + hpmevent_curr = csr_ind_read(CSR_SIREG2, SISELECT_SSCCFG_BASE, counter_idx); + of_mask = ~HPMEVENT_OF; +#endif + + hpmevent_curr &= of_mask; +#if defined(CONFIG_32BIT) + csr_ind_write(CSR_SIREG4, SISELECT_SSCCFG_BASE, counter_idx, hpmevent_curr); +#else + csr_ind_write(CSR_SIREG2, SISELECT_SSCCFG_BASE, counter_idx, hpmevent_curr); +#endif +} + +static void rvpmu_deleg_ctr_start(struct perf_event *event, u64 ival) +{ + unsigned long scountinhibit_val = 0; + struct hw_perf_event *hwc = &event->hw; + +#if defined(CONFIG_32BIT) + csr_ind_write(CSR_SIREG, SISELECT_SSCCFG_BASE, hwc->idx, ival & 0xFFFFFFFF); + csr_ind_write(CSR_SIREG4, SISELECT_SSCCFG_BASE, hwc->idx, ival >> BITS_PER_LONG); +#else + csr_ind_write(CSR_SIREG, SISELECT_SSCCFG_BASE, hwc->idx, ival); +#endif + + rvpmu_deleg_ctr_enable_irq(event); + + scountinhibit_val = csr_read(CSR_SCOUNTINHIBIT); + scountinhibit_val &= ~(1 << hwc->idx); + + csr_write(CSR_SCOUNTINHIBIT, scountinhibit_val); +} + +static void rvpmu_deleg_ctr_stop_mask(unsigned long mask) +{ + unsigned long scountinhibit_val = 0; + + scountinhibit_val = csr_read(CSR_SCOUNTINHIBIT); + scountinhibit_val |= mask; + + csr_write(CSR_SCOUNTINHIBIT, scountinhibit_val); +} + /* * This function starts all the used counters in two step approach. * Any counter that did not overflow can be start in a single step * while the overflowed counters need to be started with updated initialization * value. */ -static inline void rvpmu_sbi_start_overflow_mask(struct riscv_pmu *pmu, +static inline void rvpmu_start_overflow_mask(struct riscv_pmu *pmu, unsigned long ctr_ovf_mask) { int idx = 0; 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; unsigned long ctr_start_mask = 0; uint64_t max_period; struct hw_perf_event *hwc; @@ -667,9 +800,12 @@ static inline void rvpmu_sbi_start_overflow_mask(struct riscv_pmu *pmu, 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); + if (static_branch_likely(&riscv_pmu_cdeleg_available)) + rvpmu_deleg_ctr_start_mask(ctr_start_mask); + else + /* 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); /* Reinitialize and start all the counter that overflowed */ while (ctr_ovf_mask) { @@ -678,13 +814,10 @@ static inline void rvpmu_sbi_start_overflow_mask(struct riscv_pmu *pmu, hwc = &event->hw; max_period = riscv_pmu_ctr_get_width_mask(event); init_val = local64_read(&hwc->prev_count) & max_period; -#if defined(CONFIG_32BIT) - sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, idx, 1, - flag, init_val, init_val >> 32, 0); -#else - sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, idx, 1, - flag, init_val, 0, 0); -#endif + if (static_branch_likely(&riscv_pmu_cdeleg_available)) + rvpmu_deleg_ctr_start(event, init_val); + else + rvpmu_sbi_ctr_start(event, init_val); perf_event_update_userpage(event); } ctr_ovf_mask = ctr_ovf_mask >> 1; @@ -723,7 +856,10 @@ static irqreturn_t rvpmu_ovf_handler(int irq, void *dev) } pmu = to_riscv_pmu(event->pmu); - rvpmu_sbi_stop_hw_ctrs(pmu); + if (static_branch_likely(&riscv_pmu_cdeleg_available)) + rvpmu_deleg_ctr_stop_mask(cpu_hw_evt->used_hw_ctrs[0]); + else + rvpmu_sbi_stop_hw_ctrs(pmu); /* Overflow status register should only be read after counter are stopped */ ALT_SBI_PMU_OVERFLOW(overflow); @@ -779,22 +915,174 @@ static irqreturn_t rvpmu_ovf_handler(int irq, void *dev) } } - rvpmu_sbi_start_overflow_mask(pmu, overflowed_ctrs); + rvpmu_start_overflow_mask(pmu, overflowed_ctrs); perf_sample_event_took(sched_clock() - start_clock); return IRQ_HANDLED; } +static int get_deleg_hw_ctr_width(int counter_offset) +{ + unsigned long hpm_warl; + int num_bits; + + if (counter_offset < 3 || counter_offset > 31) + return 0; + + hpm_warl = csr_ind_warl(CSR_SIREG, SISELECT_SSCCFG_BASE, counter_offset, -1); + num_bits = __fls(hpm_warl); + +#if defined(CONFIG_32BIT) + hpm_warl = csr_ind_warl(CSR_SIREG4, SISELECT_SSCCFG_BASE, counter_offset, -1); + num_bits += __fls(hpm_warl); +#endif + return num_bits; +} + +static int rvpmu_deleg_find_ctrs(void) +{ + int i, num_hw_ctr = 0; + union sbi_pmu_ctr_info cinfo; + unsigned long scountinhibit_old = 0; + + /* Do a WARL write/read to detect which hpmcounters have been delegated */ + scountinhibit_old = csr_read(CSR_SCOUNTINHIBIT); + csr_write(CSR_SCOUNTINHIBIT, -1); + cmask = csr_read(CSR_SCOUNTINHIBIT); + + csr_write(CSR_SCOUNTINHIBIT, scountinhibit_old); + + for_each_set_bit(i, &cmask, RISCV_MAX_HW_COUNTERS) { + if (unlikely(i == 1)) + continue; /* This should never happen as TM is read only */ + cinfo.value = 0; + cinfo.type = SBI_PMU_CTR_TYPE_HW; + /* + * If counter delegation is enabled, the csr stored to the cinfo will + * be a virtual counter that the delegation attempts to read. + */ + cinfo.csr = CSR_CYCLE + i; + if (i == 0 || i == 2) + cinfo.width = 63; + else + cinfo.width = get_deleg_hw_ctr_width(i) - 1; + + num_hw_ctr++; + pmu_ctr_list[i].value = cinfo.value; + } + + return num_hw_ctr; +} + +static int get_deleg_fixed_hw_idx(struct cpu_hw_events *cpuc, struct perf_event *event) +{ + return -EINVAL; +} + +static int get_deleg_next_hpm_hw_idx(struct cpu_hw_events *cpuc, struct perf_event *event) +{ + unsigned long hw_ctr_mask = 0; + + /* + * TODO: Treat every hpmcounter can monitor every event for now. + * The event to counter mapping should come from the json file. + * The mapping should also tell if sampling is supported or not. + */ + + /* Select only hpmcounters */ + hw_ctr_mask = cmask & (~0x7); + hw_ctr_mask &= ~(cpuc->used_hw_ctrs[0]); + return __ffs(hw_ctr_mask); +} + +static void update_deleg_hpmevent(int counter_idx, uint64_t event_value, uint64_t filter_bits) +{ + uint64_t hpmevent_value = 0; + + /* OF bit should be enable during the start if sampling is requested */ + hpmevent_value = (event_value & ~HPMEVENT_MASK) | filter_bits | HPMEVENT_OF; +#if defined(CONFIG_32BIT) + csr_ind_write(CSR_SIREG2, SISELECT_SSCCFG_BASE, counter_idx, hpmevent_value & 0xFFFFFFFF); + if (riscv_isa_extension_available(NULL, SSCOFPMF)) + csr_ind_write(CSR_SIREG5, SISELECT_SSCCFG_BASE, counter_idx, + hpmevent_value >> BITS_PER_LONG); +#else + csr_ind_write(CSR_SIREG2, SISELECT_SSCCFG_BASE, counter_idx, hpmevent_value); +#endif +} + +static int rvpmu_deleg_ctr_get_idx(struct perf_event *event) +{ + struct hw_perf_event *hwc = &event->hw; + struct riscv_pmu *rvpmu = to_riscv_pmu(event->pmu); + struct cpu_hw_events *cpuc = this_cpu_ptr(rvpmu->hw_events); + unsigned long hw_ctr_max_id; + uint64_t priv_filter; + int idx; + + /* + * TODO: We should not rely on SBI Perf encoding to check if the event + * is a fixed one or not. + */ + if (!is_sampling_event(event)) { + idx = get_deleg_fixed_hw_idx(cpuc, event); + if (idx == 0 || idx == 2) { + /* Priv mode filter bits are only available if smcntrpmf is present */ + if (riscv_isa_extension_available(NULL, SMCNTRPMF)) + goto found_idx; + else + goto skip_update; + } + } + + hw_ctr_max_id = __fls(cmask); + idx = get_deleg_next_hpm_hw_idx(cpuc, event); + if (idx < 3 || idx > hw_ctr_max_id) + goto out_err; +found_idx: + priv_filter = get_deleg_priv_filter_bits(event); + update_deleg_hpmevent(idx, hwc->config, priv_filter); +skip_update: + if (!test_and_set_bit(idx, cpuc->used_hw_ctrs)) + return idx; +out_err: + return -ENOENT; +} + static void rvpmu_ctr_start(struct perf_event *event, u64 ival) { - rvpmu_sbi_ctr_start(event, ival); - /* TODO: Counter delegation implementation */ + struct hw_perf_event *hwc = &event->hw; + + if (static_branch_likely(&riscv_pmu_cdeleg_available) && !pmu_sbi_is_fw_event(event)) + rvpmu_deleg_ctr_start(event, ival); + else + rvpmu_sbi_ctr_start(event, ival); + + + if ((hwc->flags & PERF_EVENT_FLAG_USER_ACCESS) && + (hwc->flags & PERF_EVENT_FLAG_USER_READ_CNT)) + rvpmu_set_scounteren((void *)event); } static void rvpmu_ctr_stop(struct perf_event *event, unsigned long flag) { - rvpmu_sbi_ctr_stop(event, flag); - /* TODO: Counter delegation implementation */ + struct hw_perf_event *hwc = &event->hw; + + if ((hwc->flags & PERF_EVENT_FLAG_USER_ACCESS) && + (hwc->flags & PERF_EVENT_FLAG_USER_READ_CNT)) + rvpmu_reset_scounteren((void *)event); + + if (static_branch_likely(&riscv_pmu_cdeleg_available) && + !pmu_sbi_is_fw_event(event)) { + /* + * The counter is already stopped. No need to stop again. Counter + * mapping will be reset in clear_idx function. + */ + if (flag != RISCV_PMU_STOP_FLAG_RESET) + rvpmu_deleg_ctr_stop_mask((1 << hwc->idx)); + } else { + rvpmu_sbi_ctr_stop(event, flag); + } } static int rvpmu_find_ctrs(void) @@ -828,20 +1116,18 @@ static int rvpmu_find_ctrs(void) static int rvpmu_event_map(struct perf_event *event, u64 *econfig) { - return rvpmu_sbi_event_map(event, econfig); - /* TODO: Counter delegation implementation */ + if (static_branch_likely(&riscv_pmu_cdeleg_available) && !pmu_sbi_is_fw_event(event)) + return rvpmu_deleg_event_map(event, econfig); + else + return rvpmu_sbi_event_map(event, econfig); } static int rvpmu_ctr_get_idx(struct perf_event *event) { - return rvpmu_sbi_ctr_get_idx(event); - /* TODO: Counter delegation implementation */ -} - -static u64 rvpmu_ctr_read(struct perf_event *event) -{ - return rvpmu_sbi_ctr_read(event); - /* TODO: Counter delegation implementation */ + if (static_branch_likely(&riscv_pmu_cdeleg_available) && !pmu_sbi_is_fw_event(event)) + return rvpmu_deleg_ctr_get_idx(event); + else + return rvpmu_sbi_ctr_get_idx(event); } static int rvpmu_starting_cpu(unsigned int cpu, struct hlist_node *node) @@ -859,7 +1145,16 @@ static int rvpmu_starting_cpu(unsigned int cpu, struct hlist_node *node) csr_write(CSR_SCOUNTEREN, 0x2); /* Stop all the counters so that they can be enabled from perf */ - rvpmu_sbi_stop_all(pmu); + if (static_branch_likely(&riscv_pmu_cdeleg_available)) { + rvpmu_deleg_ctr_stop_mask(cmask); + if (static_branch_likely(&riscv_pmu_sbi_available)) { + /* Stop the firmware counters as well */ + sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, 0, firmware_cmask, + 0, 0, 0, 0); + } + } else { + rvpmu_sbi_stop_all(pmu); + } if (riscv_pmu_use_irq) { cpu_hw_evt->irq = riscv_pmu_irq; @@ -1142,7 +1437,10 @@ static int rvpmu_device_probe(struct platform_device *pdev) pmu->pmu.capabilities |= PERF_PMU_CAP_NO_EXCLUDE; } - pmu->pmu.attr_groups = riscv_pmu_attr_groups; + if (cdeleg_available) + pmu->pmu.attr_groups = riscv_cdeleg_pmu_attr_groups; + else + pmu->pmu.attr_groups = riscv_sbi_pmu_attr_groups; pmu->cmask = cmask; pmu->ctr_start = rvpmu_ctr_start; pmu->ctr_stop = rvpmu_ctr_stop; diff --git a/include/linux/perf/riscv_pmu.h b/include/linux/perf/riscv_pmu.h index 3d2b1d7913f3..f878369fecc8 100644 --- a/include/linux/perf/riscv_pmu.h +++ b/include/linux/perf/riscv_pmu.h @@ -20,6 +20,7 @@ */ #define RISCV_MAX_COUNTERS 64 +#define RISCV_MAX_HW_COUNTERS 32 #define RISCV_OP_UNSUPP (-EOPNOTSUPP) #define RISCV_PMU_PDEV_NAME "riscv-pmu" #define RISCV_PMU_LEGACY_PDEV_NAME "riscv-pmu-legacy" @@ -28,6 +29,8 @@ #define RISCV_PMU_CONFIG1_GUEST_EVENTS 0x1 +#define RISCV_PMU_DELEG_RAW_EVENT_MASK GENMASK_ULL(55, 0) + struct cpu_hw_events { /* currently enabled events */ int n_events; From patchwork Sat Feb 17 00:57:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 18B40C48BC4 for ; Sat, 17 Feb 2024 02:03:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0TXqu4Xa5A8LWuTghT9+6cxBzPZJs5sNtas+8rCO/UA=; b=GTyT/CuQGcw1nu d50cIRonVTp1LJOmBUPV+lzmclCaZ+AAGrafEmvAyIv7842EjBzOxBJz4qV4PIApagO76QHSPLlB3 dwXvLQZY5j5OhKkAQbwKV/oPCYac4sKK+hi+0/CBtu4s6MjFgkIZWDgaEuai5oDuE457wDN2anuiC 3LwjQ8kfzLQNszLQjf4g+dmgcgmN5WH/65G/3CkG6bTtsrwcnwv9NCbxkkf+oZ14vvLGriSS+Q+RC pDkW5u+B7hReU5zk+4uTRJsK6hEWebWJ3JeBXXZo5N/u6ruNXvHY+lg3ORbdaDU3e1jJlYQVygDha tPQ2v1LVWpmk6TpV88PQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbA3U-00000004SBL-1dlK; Sat, 17 Feb 2024 02:03:52 +0000 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92Z-00000004INT-3Ard for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:59:02 +0000 Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3c0d59a219dso1574919b6e.0 for ; Fri, 16 Feb 2024 16:58:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131531; x=1708736331; darn=lists.infradead.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=wzekTDmDm0BHWDBhHgdtQywPCZoHi4eTbi4rsPTxLsk=; b=RIj1oilGOUNHBuBFkfmjbwskA5XqvCgqDibjwZB8TIhSnaGrBThXImbmZQk9rCwoi2 B4eVIr0dFKLjKEWk3SyX8HVo3kUc5mm4Dw+vvmDZjC8A0aYAcmw4RB9oXt/dIPf3J8Tp Q/AgHOFVPeJw7WeqJe2cujyDC/YN76+akEHJJxpaaj9VIhx3Ix6an+ZjhpvY8uPo2lgV C0N04E4TpTTqMfBTHgtfT+ot8h0RzwAZa0Ri2B68rCm2E9cFj9PpfQaAe/wtKfhlxOz1 kvbZzDamE2istCm73Ie8zFIaWeLAwHUDNZCFOvoQKgIz0ZIhsQCUNM4vR/ONRAhiClKE 8CGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131531; x=1708736331; 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=wzekTDmDm0BHWDBhHgdtQywPCZoHi4eTbi4rsPTxLsk=; b=gKsClJmUvNEHSTD69P6LQtarJluyMb/DnZ3+qLEeSCgE2MUTAAGu93XkgHG2IID0Eb eUtzn6XPjtpfkwVPitqZ4tV6R8vf0JJP9THALx24z9fSAviKkiDyY+dO+SO6/YWiOnq7 3niiXCl3S24NuoG0Avg1CN9j0dOxF0iMFMt6GaOw4+09O5fORxfkOKo68ip+n2en3vIo JkxGassFIu5lXSikK4vRt/k16n4qF0VIB5d0eqzgfuvz7L/QR7hPAc9z25gmRw+GiUAQ UGARNEtqGIjjoYaDE849Zf8IqfaLrvIbVZxp+OzrbbwHeuYsHiyS7EzXZqc/kA4/UaUv M5qA== X-Forwarded-Encrypted: i=1; AJvYcCVSQUEHcvF40gIhu+NRnbNbvSBgratMbcKaAcKnrCgaf53ogWl0jpU99L2VSyaHWlUI0lojMTYMswArHtzyaH2LMwN1pKfaHHoxlVBOGh4M X-Gm-Message-State: AOJu0Yzc72EGSqLv/jG/YTlDk0IfImpTJNM282FnhJP0ikb50NvNzfdM 5zY8Qj/rwL4WjdTI5tKzlrvZnZPBp9Qvb1+2qfYUZjb3LAA5EjWXq/fd/nMr8Ms= X-Google-Smtp-Source: AGHT+IFh5z2qRfi3D9IkKas86nFROYWU3mPjDzUuW4T2X7wbUeQ8t61ZPYIlkMzVMiWXNbGIgenNww== X-Received: by 2002:a05:6808:4d0:b0:3c1:347f:39d1 with SMTP id a16-20020a05680804d000b003c1347f39d1mr6306573oie.22.1708131530901; Fri, 16 Feb 2024 16:58:50 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:50 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 14/20] RISC-V: perf: Use config2 for event to counter mapping Date: Fri, 16 Feb 2024 16:57:32 -0800 Message-Id: <20240217005738.3744121-15-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165852_095778_047BC0D0 X-CRM114-Status: GOOD ( 24.97 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The counter restriction specified in the json file is passed to the drivers via config2 paarameter in perf attributes. This allows any platform vendor to define their custom mapping between event and hpmcounters without any rules defined in the ISA. However, the cycle and instruction counters are fixed (0 and 2 respectively) by the ISA. The platform vendor must specify this in the json file if intended to be used while profiling. Otherwise, they can just specify the alternate hpmcounters that may monitor and/or sample the cycle/instruction counts. Signed-off-by: Atish Patra --- drivers/perf/riscv_pmu_dev.c | 36 +++++++++++++++++++++++----------- include/linux/perf/riscv_pmu.h | 2 ++ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/drivers/perf/riscv_pmu_dev.c b/drivers/perf/riscv_pmu_dev.c index 0cdad0dafb71..5bad4131e920 100644 --- a/drivers/perf/riscv_pmu_dev.c +++ b/drivers/perf/riscv_pmu_dev.c @@ -49,6 +49,7 @@ static ssize_t __maybe_unused rvpmu_format_show(struct device *dev, RVPMU_ATTR_ENTRY(_name, rvpmu_format_show, (char *)_config) PMU_FORMAT_ATTR(firmware, "config:63"); +PMU_FORMAT_ATTR(counterid_mask, "config2:0-31"); static DEFINE_STATIC_KEY_FALSE(riscv_pmu_sbi_available); static DEFINE_STATIC_KEY_FALSE(riscv_pmu_cdeleg_available); @@ -74,6 +75,7 @@ static const struct attribute_group *riscv_sbi_pmu_attr_groups[] = { static struct attribute *riscv_cdeleg_pmu_formats_attr[] = { RVPMU_FORMAT_ATTR_ENTRY(event, RVPMU_CDELEG_PMU_FORMAT_ATTR), &format_attr_firmware.attr, + &format_attr_counterid_mask.attr, NULL, }; @@ -974,23 +976,39 @@ static int rvpmu_deleg_find_ctrs(void) return num_hw_ctr; } +/* The json file must correctly specify counter 0 or counter 2 is available + * in the counter lists for cycle/instret events. Otherwise, the drivers have + * no way to figure out if a fixed counter must be used and pick a programmable + * counter if available. + */ static int get_deleg_fixed_hw_idx(struct cpu_hw_events *cpuc, struct perf_event *event) { - return -EINVAL; + if (!event->attr.config2) + return -EINVAL; + + if (event->attr.config2 & RISCV_PMU_CYCLE_FIXED_CTR_MASK) + return 0; /* CY counter */ + else if (event->attr.config2 & RISCV_PMU_INSTRUCTION_FIXED_CTR_MASK) + return 2; /* IR counter */ + else + return -EINVAL; } static int get_deleg_next_hpm_hw_idx(struct cpu_hw_events *cpuc, struct perf_event *event) { unsigned long hw_ctr_mask = 0; - /* - * TODO: Treat every hpmcounter can monitor every event for now. - * The event to counter mapping should come from the json file. - * The mapping should also tell if sampling is supported or not. - */ - /* Select only hpmcounters */ hw_ctr_mask = cmask & (~0x7); + + /* + * Mask off the counters that can't monitor this event (specified via json) + * The counter mask for this event is set in config2 via the property 'Counter' + * in the json file or manual configuration of config2. If the config2 is not set, it + * is assumed all the available hpmcounters can monitor this event. + */ + if (event->attr.config2) + hw_ctr_mask = hw_ctr_mask & event->attr.config2; hw_ctr_mask &= ~(cpuc->used_hw_ctrs[0]); return __ffs(hw_ctr_mask); } @@ -1020,10 +1038,6 @@ static int rvpmu_deleg_ctr_get_idx(struct perf_event *event) uint64_t priv_filter; int idx; - /* - * TODO: We should not rely on SBI Perf encoding to check if the event - * is a fixed one or not. - */ if (!is_sampling_event(event)) { idx = get_deleg_fixed_hw_idx(cpuc, event); if (idx == 0 || idx == 2) { diff --git a/include/linux/perf/riscv_pmu.h b/include/linux/perf/riscv_pmu.h index f878369fecc8..425edd6685a9 100644 --- a/include/linux/perf/riscv_pmu.h +++ b/include/linux/perf/riscv_pmu.h @@ -30,6 +30,8 @@ #define RISCV_PMU_CONFIG1_GUEST_EVENTS 0x1 #define RISCV_PMU_DELEG_RAW_EVENT_MASK GENMASK_ULL(55, 0) +#define RISCV_PMU_CYCLE_FIXED_CTR_MASK 0x01 +#define RISCV_PMU_INSTRUCTION_FIXED_CTR_MASK 0x04 struct cpu_hw_events { /* currently enabled events */ From patchwork Sat Feb 17 00:57:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7DE17C48BF5 for ; Sat, 17 Feb 2024 00:59:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0rcfQpY4lU/jO8rK1b+HVAX7lxVyNlFgm6yVtIa5YiI=; b=Y9j92JFeaYLvgK hk5Hirk7ejd4gqcbEg0qYIdXJ0b2P8IOf+MbJaP/Pr62xDxnLRzzEEVnC4+hdFrp5QRwlBu/ifuq9 T3EZ9R9QnLohq88tIkahzzgrjBZSlekl8RfSHqxk9gt/o8mgQYP0FHXbqpYs/ephG8bRksTbUO8f5 0Yf1vUkfHQq7VkfnT/VS7B4JVRf+mwIrSOBWUYm/sklWZne4stnaIoe4b6DH8xw7CNWwLMeazpZQG 3ZyQzL7jxxlrtL27S+YT9X2qH4sAVNfKzCGoK0VXLGA/S+DioK3vBpenIWYa6oKyjan1mz+TM1TAD I5eDPC5vS18a/dMQ8xUw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb939-00000004Isx-46Uf; Sat, 17 Feb 2024 00:59:28 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92q-00000004Ib5-2gmX for linux-riscv@bombadil.infradead.org; Sat, 17 Feb 2024 00:59:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=EtMupTUIOKSWIiS3+KSauzncMWOa0iz/fT9+70O+xec=; b=oU//fNl0V7wdZcimINZyiX5l6s W0hOGiQOUKPKc3Zj8V6fIDr5BulqGtqED5pNCHJR4m7O2y/oCt5AJVZx77ehVQxoiOywzWYEVgdWt SYbHlfzMkIH9r+3uCudBMufbYOIdeAw0VQJKLExr+i0T4usAgqRa3G3u7mCZLN+KQEUGLsK3AqRL7 LVIPUahfTTvIDPKhXnPemyL3uAafphbJwAfP21oAy9EMLJ9oZ7Ln4HN9Lb5foTENxfL4nQYr7679+ AVcuEavXOWAFkOu7k0Hmr3ZQbW9jdbkhqKOPiwHtfon+50LVBJrOz0lfBoq0cjdl0rNdivAChG9tG KI2a9Y+A==; Received: from mail-oo1-xc36.google.com ([2607:f8b0:4864:20::c36]) by casper.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92l-000000066Vq-1Ict for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:59:07 +0000 Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-59fb5b09cc2so17020eaf.0 for ; Fri, 16 Feb 2024 16:58:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131535; x=1708736335; darn=lists.infradead.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=EtMupTUIOKSWIiS3+KSauzncMWOa0iz/fT9+70O+xec=; b=v6G6/ZkxRVLKYPQcRUv7QT+wN5bVNOawpaTJg3MVppLx0FGPAXrm1L6/HHSrzmzL4O APP82krbnyE1uKx9IJS9EGKOeYlV6TrQpx3/36gxsdCpBm162FthSRpBxwasRNgM8aqP bYtTrXy6e0M9SVzD78V8nVe0Sgo38uVPn01NdngKpMDmefu6G+M+riHJqXuELgoeEPiR ckD5pKHn5Esq83kgqvfl47yz5i6pyBEnjlmoV0DXtkYqmKlok0n7R52v8etZLgainPcp ljc989JgP4n6l6ochtd6a99K9yKx2/AlCDfA5yCxvi7ACJGKifRVT8tct8I3d8JDoYGe U0Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131535; x=1708736335; 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=EtMupTUIOKSWIiS3+KSauzncMWOa0iz/fT9+70O+xec=; b=S0CyN8/2qZWKGLMf6pBEUpDQwCEhrNtMVHzloM5fcKkFOYDPpqfQR/O2+gGSLWTrKB WXcdZVQTVBm2Hf3Ft53mg2L6gb1kVbIn065hiw4muwsGE2bIYbiL5W/+iwAVYV+/x0ox UZ/lFKeQlYOdOjCZVjLnHPCEwCDj4wydkq4CBccKSUgIuCVAC5wqkavRnEXnJuAioQmB kNetTiJA5ZSZvQyismKlPda2/47FSJ0gCZM73Cc2ILKwmIrZADZLPTvQXRwkE85ZE3tC VzQY8FqfFh37RWoyZ9mg89UZ4HHRYZNoJ+BgLxCq0GheVPl3ugn49hmsfB08CVEuqugI D5JA== X-Forwarded-Encrypted: i=1; AJvYcCXuaI7m2yn03f+l+UVdZKuNVciHOLU3xVxgEu98ll7wnz47rxie8en1+B7iae3G72GgP/prDoR177D2OagJ1nBpBMgRk3SOW2NYj4yB9MzR X-Gm-Message-State: AOJu0YxjBng5NdSZI7ikQVR6LDl/rKlLEgEysCGRJI+faJ0HeK6VL6Ri qDGdotiLWu1X2JCd48BJHiqE8FDAM0zXtCIVSpAu+UL0yEnoqo1faA3ZPJTOVXU= X-Google-Smtp-Source: AGHT+IGNbIUzWm0Nd5NFQVXMQHrTszP1TZWkXMNIGjnbL/tst4Vl5kEoxiI6rU6dM0tRW8yXxuE6PQ== X-Received: by 2002:a05:6358:2913:b0:177:afce:b12 with SMTP id y19-20020a056358291300b00177afce0b12mr6399019rwb.31.1708131533554; Fri, 16 Feb 2024 16:58:53 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:53 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 15/20] tools/perf: Add arch hooks to override perf standard events Date: Fri, 16 Feb 2024 16:57:33 -0800 Message-Id: <20240217005738.3744121-16-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240217_005904_820235_D1F3D847 X-CRM114-Status: GOOD ( 23.91 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org RISC-V doesn't have any standard event encoding defined in the ISA. Cycle/instruction event is defined in the ISA but lack of event encoding allow vendors to choose their own encoding scheme. These events directly map to perf cycle/instruction events which gets decoded as per perf definitions. An arch hooks allows the RISC-V implementation to override the encodings if a vendor has specified the encodings via Json file at runtime. The alternate solution would be define vendor specific encodings in the driver similar to other architectures. However, these will grow over time to become unmaintainable as the number of vendors in RISC-V can be huge. Signed-off-by: Atish Patra --- tools/perf/arch/riscv/util/Build | 1 + tools/perf/arch/riscv/util/evlist.c | 59 +++++++++++++++++++ tools/perf/builtin-record.c | 3 + tools/perf/builtin-stat.c | 2 + tools/perf/builtin-top.c | 3 + .../pmu-events/arch/riscv/arch-standard.json | 10 ++++ tools/perf/pmu-events/jevents.py | 6 ++ tools/perf/util/evlist.c | 6 ++ tools/perf/util/evlist.h | 6 ++ 9 files changed, 96 insertions(+) create mode 100644 tools/perf/arch/riscv/util/evlist.c create mode 100644 tools/perf/pmu-events/arch/riscv/arch-standard.json diff --git a/tools/perf/arch/riscv/util/Build b/tools/perf/arch/riscv/util/Build index 603dbb5ae4dc..b581fb3d8677 100644 --- a/tools/perf/arch/riscv/util/Build +++ b/tools/perf/arch/riscv/util/Build @@ -1,5 +1,6 @@ perf-y += perf_regs.o perf-y += header.o +perf-y += evlist.o perf-$(CONFIG_DWARF) += dwarf-regs.o perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o diff --git a/tools/perf/arch/riscv/util/evlist.c b/tools/perf/arch/riscv/util/evlist.c new file mode 100644 index 000000000000..9ad287c6f396 --- /dev/null +++ b/tools/perf/arch/riscv/util/evlist.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include "util/pmu.h" +#include "util/pmus.h" +#include "util/evlist.h" +#include "util/parse-events.h" +#include "util/event.h" +#include "evsel.h" + +static int pmu_update_cpu_stdevents_callback(const struct pmu_event *pe, + const struct pmu_events_table *table __maybe_unused, + void *vdata) +{ + struct evsel *evsel = vdata; + struct parse_events_terms terms; + int err; + struct perf_pmu *pmu = perf_pmus__find("cpu"); + + if (pe->event) { + parse_events_terms__init(&terms); + err = parse_events_terms(&terms, pe->event, NULL); + if (err) + goto out_free; + err = perf_pmu__config_terms(pmu, &evsel->core.attr, &terms, + /*zero=*/true, /*err=*/NULL); + if (err) + goto out_free; + } + +out_free: + parse_events_terms__exit(&terms); + return 0; +} + +int arch_evlist__override_default_attrs(struct evlist *evlist, const char *pmu_name) +{ + struct evsel *evsel; + struct perf_pmu *pmu = perf_pmus__find(pmu_name); + static const char *const overriden_event_arr[] = {"cycles", "instructions", + "dTLB-load-misses", "dTLB-store-misses", + "iTLB-load-misses"}; + unsigned int i, len = sizeof(overriden_event_arr) / sizeof(char *); + + if (!pmu) + return 0; + + for (i = 0; i < len; i++) { + if (perf_pmus__have_event(pmu_name, overriden_event_arr[i])) { + evsel = evlist__find_evsel_by_str(evlist, overriden_event_arr[i]); + if (!evsel) + continue; + pmu_events_table__find_event(pmu->events_table, pmu, + overriden_event_arr[i], + pmu_update_cpu_stdevents_callback, evsel); + } + } + + return 0; +} diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 86c910125172..305c2c030208 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -4152,6 +4152,9 @@ int cmd_record(int argc, const char **argv) goto out; } + if (arch_evlist__override_default_attrs(rec->evlist, "cpu")) + goto out; + if (rec->opts.target.tid && !rec->opts.no_inherit_set) rec->opts.no_inherit = true; diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 5fe9abc6a524..a0feafc5be2c 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2713,6 +2713,8 @@ int cmd_stat(int argc, const char **argv) if (add_default_attributes()) goto out; + if (arch_evlist__override_default_attrs(evsel_list, "cpu")) + goto out; if (stat_config.cgroup_list) { if (nr_cgroups > 0) { diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 5301d1badd43..7e268f239df0 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1672,6 +1672,9 @@ int cmd_top(int argc, const char **argv) goto out_delete_evlist; } + if (arch_evlist__override_default_attrs(top.evlist, "cpu")) + goto out_delete_evlist; + status = evswitch__init(&top.evswitch, top.evlist, stderr); if (status) goto out_delete_evlist; diff --git a/tools/perf/pmu-events/arch/riscv/arch-standard.json b/tools/perf/pmu-events/arch/riscv/arch-standard.json new file mode 100644 index 000000000000..96e21f088558 --- /dev/null +++ b/tools/perf/pmu-events/arch/riscv/arch-standard.json @@ -0,0 +1,10 @@ +[ + { + "EventName": "cycles", + "BriefDescription": "cycle executed" + }, + { + "EventName": "instructions", + "BriefDescription": "instruction retired" + } +] diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 81e465a43c75..30934a490109 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -7,6 +7,7 @@ from functools import lru_cache import json import metric import os +import re import sys from typing import (Callable, Dict, Optional, Sequence, Set, Tuple) import collections @@ -388,6 +389,11 @@ class JsonEvent: if arch_std: if arch_std.lower() in _arch_std_events: event = _arch_std_events[arch_std.lower()].event + if eventcode: + event = re.sub(r'event=\d+', f'event={llx(eventcode)}', event) + if configcode: + event = re.sub(r'config=\d+', f'event={llx(configcode)}', event) + # Copy from the architecture standard event to self for undefined fields. for attr, value in _arch_std_events[arch_std.lower()].__dict__.items(): if hasattr(self, attr) and not getattr(self, attr): diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 55a300a0977b..f8a5640cf4fa 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -357,6 +357,12 @@ __weak int arch_evlist__add_default_attrs(struct evlist *evlist, return __evlist__add_default_attrs(evlist, attrs, nr_attrs); } +__weak int arch_evlist__override_default_attrs(struct evlist *evlist __maybe_unused, + const char *pmu_name __maybe_unused) +{ + return 0; +} + struct evsel *evlist__find_tracepoint_by_id(struct evlist *evlist, int id) { struct evsel *evsel; diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index cb91dc9117a2..705b6643b558 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -109,9 +109,15 @@ int arch_evlist__add_default_attrs(struct evlist *evlist, struct perf_event_attr *attrs, size_t nr_attrs); + #define evlist__add_default_attrs(evlist, array) \ arch_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array)) +int arch_evlist__override_default_attrs(struct evlist *evlist, const char *pmu_name); + +#define evlist__override_default_attrs(evlist, pmu_name) \ + arch_evlist__override_default_attrs(evlist, pmu_name) + int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs); int evlist__add_dummy(struct evlist *evlist); From patchwork Sat Feb 17 00:57:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561156 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23E9BC48BF5 for ; Sat, 17 Feb 2024 00:59:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+Kvhfc5e+MnauQ8maNtaPSxb+SVoeeU1pYh5MHvSnyo=; b=RvqYApqnd/oqU4 7iOjCEvt9hSJmQJh8JuFL9l2fGcZ1TakqWK414U3qlvBtCTHlv5et9P0IxpZ9c8AXlznkg/h/U/G5 tzQt794Vm8mwT66IfmScpqbpxNPTezWG9NlARG1lJku41199/YUTsJqaEUR38qUPyJFPalo+nFgJ9 63ILyf5p/H8ufFGG4kFjFZzEKagAITw9/PEELWjokIWQiFW4V2EHdNPx/d0txIOadvYrRJ06kPBFT 1T5TK1w5UEV/vZV/G90yX1XijcmNcNwEcwwPptQb0sNQUY8izxuo8DaD06uwEi8KEhX73VK9Kd+kM yaCf3cFGkGjzFcr7X/mQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb936-00000004Iq2-0zXq; Sat, 17 Feb 2024 00:59:24 +0000 Received: from mail-oa1-x29.google.com ([2001:4860:4864:20::29]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92f-00000004IRm-2fWu for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:59:06 +0000 Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-21433afcc53so631403fac.3 for ; Fri, 16 Feb 2024 16:58:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131536; x=1708736336; darn=lists.infradead.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=UM8zssVewnxKekt4u8gJqVdaJ7ofC8o/V7nPW8x9v/k=; b=oFh8WNP+nVk4dgqXIJ3culYotJRJlclhIhANf6NYu9w+2tmmDRExpYHY7Gg59y6A4P 5+N+kWnR/r7qRLL5CAWXm7MZLGTS33hgK+qAfc6RDhuSYD7MPE7pnPRPqx3DkxLm7ggU uwLFQ1cblMB72m/d1syvtZoVxT35xOfULj43E6JJ0gRtKWPfgH+RJlM67oSOSXXSG4xd IWddN6qcQn+XpB4nTkKCliKuJb1bBUegZm7LCaKDIESYzpAiU7gnIxqHDZranA31Vaet H5FC6UCw97aorzQagZM6g3LyhhhUZIjp1Gg4qM2qTljxetOVS7Fv4eFVME1crJc5JwK2 ng1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131536; x=1708736336; 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=UM8zssVewnxKekt4u8gJqVdaJ7ofC8o/V7nPW8x9v/k=; b=waNciPmyxurdXvcTwwuADKbHF3fgkDGUQt38ywtPFRkrp3m8Gfy/chdZp/KSZ/LVTx dfh+7x33cUu/IgG9raShR9npM2UmQkfVt44bg+3wxdpbGwlIy+E3D6M3FPHMSm3XbHSo mYmLp4AIF9itO5Xv9vcN2m5x7KxGLVgvAGCl/CDVpqZik4evhw213mtOgSjyGKzgEUo3 2vJecL2uzW9n1KKsolmT7qDwhiYAFnEKMAOgQ/3pXAatgjZwNEwnJV53ScYDirE8tvZ1 B36XOpX4de8lFOx14tmUoebOjVP1/E7B494JDCC/cIIbPMQoA2jEGTcaQeO0GSyn36/7 vmzw== X-Forwarded-Encrypted: i=1; AJvYcCXdyqv7bomTH9vJpx4XXB2fX+y1OUGs8Z/3vzsvSz1Eia2u5SlqZpI4DgenyFvk6CK/DEUqLX81rxr+8QQDD5cspnrE/5evi5FqkrNZh7F+ X-Gm-Message-State: AOJu0YyHs1O1JHJNvrnWFhEFuNYo2fQxH8BBAmhqll7/MliPKtQxzof6 XGtP72fJ6wf5cAEo+ymHDWWJ+uYeB8TsLcPZ4L8v1GXhMW2JCnq3HECRiYnJr5s= X-Google-Smtp-Source: AGHT+IHxQ/ohabidKPISMfSUq9m2exq/kzmKZJs/ZvDEyG8lUk4zXZLeanKyyRpfmzqm9XJNLg+WQw== X-Received: by 2002:a05:6870:d88d:b0:218:df68:87b2 with SMTP id oe13-20020a056870d88d00b00218df6887b2mr6753520oac.44.1708131536206; Fri, 16 Feb 2024 16:58:56 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:55 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 16/20] tools/perf: Pass the Counter constraint values in the pmu events Date: Fri, 16 Feb 2024 16:57:34 -0800 Message-Id: <20240217005738.3744121-17-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165857_953735_B9C126A3 X-CRM114-Status: GOOD ( 12.83 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org RISC-V doesn't have any standard event to counter mapping discovery mechanism in the ISA. The ISA defines 29 programmable counters and platforms can choose to implement any number of them and map any events to any counters. Thus, the perf tool need to inform the driver about the counter mapping of each events. The current perf infrastructure only parses the 'Counter' constraints in metrics. This patch extends that to pass in the pmu events so that any driver can retrieve those values via perf attributes if defined accordingly. Signed-off-by: Atish Patra --- tools/perf/pmu-events/jevents.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 30934a490109..f1e320077695 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -278,6 +278,11 @@ class JsonEvent: return fixed[name.lower()] return event + def counter_list_to_bitmask(counterlist): + counter_ids = list(map(int, counterlist.split(','))) + bitmask = sum(1 << pos for pos in counter_ids) + return bitmask + def unit_to_pmu(unit: str) -> Optional[str]: """Convert a JSON Unit to Linux PMU name.""" if not unit: @@ -401,6 +406,10 @@ class JsonEvent: else: raise argparse.ArgumentTypeError('Cannot find arch std event:', arch_std) + if self.counter: + bitmask = counter_list_to_bitmask(self.counter) + event += f',counterid_mask={bitmask:#x}' + self.event = real_event(self.name, event) def __repr__(self) -> str: From patchwork Sat Feb 17 00:57:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561181 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0452AC48260 for ; Sat, 17 Feb 2024 01:05:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uTwyVs0IOu5z/nl7sPb3yZFz86440igox6yBQL4PuAs=; b=vfi++tcJiuZDQT 9FeuiXJZBGQexJ3tbYTBOSUwLRnL/Db1bc3ci1TgHecMQoiBOzWf6dAUYDMRAME3xEkakAJdFQeBn lTerYSSyxoQU2rXsFCYYcVPRB6vS1Bvm2kO6480DItUO0uldT2gMip4pBt+o/8RkP7Ubxf0xG6rU1 DzR4w64KAyaBEE4NsMhKRKTxashdS4SF+zM2oRXblFPW1ysvMPrwVIvHcL4Wy1jcvVDGI3JTgDuEj WbCfxHqVD7U+QB3atdyxRuDDyqKQGMRSatnKXhMB7dKy+NCsP6SpnKTNRED7Ke76krXOffZLk5cU5 latXeh83MnhsiHMZdy2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb98u-00000004LVn-31dN; Sat, 17 Feb 2024 01:05:24 +0000 Received: from mail-qv1-xf2e.google.com ([2607:f8b0:4864:20::f2e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb98q-00000004LTE-3qX4 for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 01:05:23 +0000 Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-6818f3cf00aso14328186d6.0 for ; Fri, 16 Feb 2024 17:05:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131918; x=1708736718; darn=lists.infradead.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=rOdL5Y7wmQdu3cBOk4Oia1bMlPhRJp0p0ru1YQcJjcc=; b=KHCefDP/vZZC8xuHe5mG2ZUcG9TXtUD4qesAL/viqSLOqY+MRnuHwi7jPksL1Dvrw4 jG3dayTkFI/PCrvbLigo7IU/wEvrIj11Te/OG7SEURYGpn0HQ+Y5fOE9GhGfzTs4+foH dsvc8/twAKrnIFhFYIDgCeBO/UqYMNu+S5vAdnHf1bL11dRGaYoCsrGjaB1atQBOQZeZ E8II07Djnjos4m+dk9nXZFMJKZDlhSAG2kjLVwchNEgpG0eR21Oo0SpsC6QeHzjXv33N OmSJiWwA4qRYK7ZmVaaFVxfoVYNyUGyiE+InhPMgMuIehdj0VtY8azGsJayl4ztZC5LO +IJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131918; x=1708736718; 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=rOdL5Y7wmQdu3cBOk4Oia1bMlPhRJp0p0ru1YQcJjcc=; b=Au/pKYg9Hg8yaNvPhkv4VZahXLA9zW/E5Jh44GBBbGC2X8lUWEXIscGN1XC/VUYW/I 09VilR3K+O3rvvradQYioIDp3lNj0fv+AoOduZZy5LEjFRXVClAf1tvJE3kDnJF8fHGn kQrySBo37ZCUlzRjo0Rj+ogmbqjJXkAxfUvdpuR6iT+HMoETr/OHG+IgzQBYFL7eVSId JK/QmFYToOy+Bah/8eA/he40b0LU/s2ZGQYBmST9VjqzvjnnAr9e+Q+s4JVTA9hlWKrN dFFBEO7PAts4z9TkDVsk3Lm5CNfvLx8KCt1fZ0f/bZlT8Ytacm3eq9HHmMl4H2ICPSME Eraw== X-Forwarded-Encrypted: i=1; AJvYcCVEQ31lEedGIXqFRVPAMt5I/etBP4KGIA5SiyctwDEJUaIfJeq+/YoQtb3Oiw0l1Iv06BIpqBDu+DOSk4oSmeyCQh1VNC7c2CdnyG1HbpBx X-Gm-Message-State: AOJu0Yz3qE1gNZstkd4R+6zf9Mj0s7hl1SUDhdU0x62NzryWfENwc1nE M9JP+Jrcq7TU/46noxMhyyIyBbJuiOmOG4PJm7AgfhbRx3UVXRmT/LJC0BphY6656v37HZOOqgO v X-Google-Smtp-Source: AGHT+IHFCfL+kwIHjaTpNxoNxqc+zu9FKDlVsVbSX+8xeWrslZki49h1LDIhhrjmSSo0/9Xc9V8bBQ== X-Received: by 2002:a05:6871:b26:b0:21e:430b:79e2 with SMTP id fq38-20020a0568710b2600b0021e430b79e2mr5862300oab.47.1708131538814; Fri, 16 Feb 2024 16:58:58 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:58:58 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 17/20] perf: Add json file for virt machine supported events Date: Fri, 16 Feb 2024 16:57:35 -0800 Message-Id: <20240217005738.3744121-18-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_170520_979681_65EA1E75 X-CRM114-Status: GOOD ( 15.48 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The linux driver will use the event encodings specified in platform specific json file only for platforms with counter delegation support. Use the perf json infrastructure to encode those events and let the driver uses that if counter delegation is available. Signed-off-by: Atish Patra --- tools/perf/pmu-events/arch/riscv/mapfile.csv | 1 + .../pmu-events/arch/riscv/qemu/virt/cpu.json | 30 ++++++++ .../arch/riscv/qemu/virt/firmware.json | 68 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 tools/perf/pmu-events/arch/riscv/qemu/virt/cpu.json create mode 100644 tools/perf/pmu-events/arch/riscv/qemu/virt/firmware.json diff --git a/tools/perf/pmu-events/arch/riscv/mapfile.csv b/tools/perf/pmu-events/arch/riscv/mapfile.csv index cfc449b19810..b3e7d544e29c 100644 --- a/tools/perf/pmu-events/arch/riscv/mapfile.csv +++ b/tools/perf/pmu-events/arch/riscv/mapfile.csv @@ -17,3 +17,4 @@ 0x489-0x8000000000000007-0x[[:xdigit:]]+,v1,sifive/u74,core 0x5b7-0x0-0x0,v1,thead/c900-legacy,core 0x67e-0x80000000db0000[89]0-0x[[:xdigit:]]+,v1,starfive/dubhe-80,core +0x0-0x0-0x0,v1,qemu/virt,core diff --git a/tools/perf/pmu-events/arch/riscv/qemu/virt/cpu.json b/tools/perf/pmu-events/arch/riscv/qemu/virt/cpu.json new file mode 100644 index 000000000000..9ab631723c88 --- /dev/null +++ b/tools/perf/pmu-events/arch/riscv/qemu/virt/cpu.json @@ -0,0 +1,30 @@ +[ + { + "ArchStdEvent": "instructions", + "EventCode": "0x02", + "Counter":"2,3,4,5,6,7,8,9,10" + }, + { + "ArchStdEvent": "cycles", + "EventCode": "0x01", + "Counter":"0,3,4,5,6,7,8,9,10" + }, + { + "EventName": "dTLB-load-misses", + "EventCode": "0x10019", + "BriefDescription": "Data TLB load miss", + "Counter":"3,4,5,6,7,8,9,10" + }, + { + "EventName": "dTLB-store-misses", + "EventCode": "0x1001B", + "BriefDescription": "Data TLB store miss", + "Counter":"3,4,5,6,7,8,9,10" + }, + { + "EventName": "iTLB-load-misses", + "EventCode": "0x10021", + "BriefDescription": "Instruction fetch TLB load miss", + "Counter":"3,4,5,6,7,8,9,10" + } +] diff --git a/tools/perf/pmu-events/arch/riscv/qemu/virt/firmware.json b/tools/perf/pmu-events/arch/riscv/qemu/virt/firmware.json new file mode 100644 index 000000000000..9b4a032186a7 --- /dev/null +++ b/tools/perf/pmu-events/arch/riscv/qemu/virt/firmware.json @@ -0,0 +1,68 @@ +[ + { + "ArchStdEvent": "FW_MISALIGNED_LOAD" + }, + { + "ArchStdEvent": "FW_MISALIGNED_STORE" + }, + { + "ArchStdEvent": "FW_ACCESS_LOAD" + }, + { + "ArchStdEvent": "FW_ACCESS_STORE" + }, + { + "ArchStdEvent": "FW_ILLEGAL_INSN" + }, + { + "ArchStdEvent": "FW_SET_TIMER" + }, + { + "ArchStdEvent": "FW_IPI_SENT" + }, + { + "ArchStdEvent": "FW_IPI_RECEIVED" + }, + { + "ArchStdEvent": "FW_FENCE_I_SENT" + }, + { + "ArchStdEvent": "FW_FENCE_I_RECEIVED" + }, + { + "ArchStdEvent": "FW_SFENCE_VMA_SENT" + }, + { + "ArchStdEvent": "FW_SFENCE_VMA_RECEIVED" + }, + { + "ArchStdEvent": "FW_SFENCE_VMA_RECEIVED" + }, + { + "ArchStdEvent": "FW_SFENCE_VMA_ASID_RECEIVED" + }, + { + "ArchStdEvent": "FW_HFENCE_GVMA_SENT" + }, + { + "ArchStdEvent": "FW_HFENCE_GVMA_RECEIVED" + }, + { + "ArchStdEvent": "FW_HFENCE_GVMA_VMID_SENT" + }, + { + "ArchStdEvent": "FW_HFENCE_GVMA_VMID_RECEIVED" + }, + { + "ArchStdEvent": "FW_HFENCE_VVMA_SENT" + }, + { + "ArchStdEvent": "FW_HFENCE_VVMA_RECEIVED" + }, + { + "ArchStdEvent": "FW_HFENCE_VVMA_ASID_SENT" + }, + { + "ArchStdEvent": "FW_HFENCE_VVMA_ASID_RECEIVED" + } +] From patchwork Sat Feb 17 00:57:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561158 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E81E7C48BF6 for ; Sat, 17 Feb 2024 00:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ynX6CE9FzY7YHbxa/ktq6QTnlE1pUlRzSP78VJ9lYqs=; b=xbsXcVPrDCwO/b jCsZneA/Y4vx0DWowE7SFp/rdqfDxvYuR7Udx/jqDDsyeiuOJda38QV+ltpL6v3GGsNWg1rmV3bPr k2Bp9WVRXHwiWdlCKKad9yRck/9zCBIwr+upJ2TPzDw8FDXgk/AyRruF3EtLaZqGsYOrIuBI+SoS5 7GXlU0krCBTNcykLz4wjEP5/B0H55WLeozkaIYCefKrwC6FTphC3UxoaNx8cj1T5vFCb9LxCKQRkP GifLf1bSbGtCCx6oJSfDocLCsEVOfO3qM7QE3Jhppb4VDhkcSYPHuqVEYzEQQZyLGwV9guwsiZYd0 V5jIjkEKgoA6GdnddUcg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb93F-00000004IyT-3ioJ; Sat, 17 Feb 2024 00:59:33 +0000 Received: from mail-il1-f178.google.com ([209.85.166.178]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92k-00000004IWG-3uQd for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:59:12 +0000 Received: by mail-il1-f178.google.com with SMTP id e9e14a558f8ab-36503a4980aso4941545ab.3 for ; Fri, 16 Feb 2024 16:59:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131541; x=1708736341; darn=lists.infradead.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=cWbguiNHtTSYUYCLfEbpuKVHcWVD1RqHX9iqh/aIsVE=; b=xoKusNgiHoxE7MnNGYkST+8WkpCymmKBnmEziZbiFCstaBSVhHDbxQqFuvKzbHClrt LUAx05KYhdMDc6Z066z15cJMjPzTzgOImL/q3Y8RRXVcXo0eU55Ch3IDIeeMnl0NlZDH MwRhbVQcibMiaEQmxC2WQBIQluKwE0xCCmzN9azSHcCFdt3O2VDBG54oM8N6tT7ZhfVZ EoH7nzeRX4WILthdzA0w+6TPLv3hfyv3JUPE0rKxlrzMO6OQRzcA1mfQZHwFtMPONUru IpwearEwFkggAS5ZhiG0WBnWrFOmDEmiZDFE9zyIM1ma4UpeMzQNcpv+bMhGDyJohsrF i82A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131541; x=1708736341; 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=cWbguiNHtTSYUYCLfEbpuKVHcWVD1RqHX9iqh/aIsVE=; b=LAibzLDo0Va99+UZMpVZCx1xH/6IcWZ6C1Kj2193U1FWEk6km2TMos+eIdfHVIVRmz jF9AOzZtaA16yQyd7QSDGbz+NM7nt0DeAHgO+XZT9ShLA8mixSLrIqglANI//B6iZKUB q+x38LsV8eudCGEO4P787ZfoAX/iBe/Q9euLQqsQcqVYfO7vzx0SB0fkiXLDc5DsCotv OQJLm/bGfZVBsODGdQAO+c0FMo5xgyza73qePcmSW3n/Gqxs4s9F3jOHKZhvifRJGKKu X3RrkTfznsft6t7d8LiNtNChSwXVA5S8s0SeIPmdJLR7hrdu3koqXjKYVel03edvDERU bqDA== X-Forwarded-Encrypted: i=1; AJvYcCX4dsCs1lDcPJ0gYegwySR4z3NDe1RnHhZ+3sHmkSa/DrtLCkbByL3S3nCdg0+KRAvZP/MKUCE4D2UG5k1/oIEABBIRgEJemIR20Qsd/cBL X-Gm-Message-State: AOJu0YzKos4IKlsyi0AtKOQVoAOJYJmdH0P77IJeE40pHmKyg7GzkWFY a9E4ijqH1jw54V7i3Zl3ekccIS8hmukb7/mJFn7g6bY0WmQMetwQa/ioejuNKUU= X-Google-Smtp-Source: AGHT+IHifVbaiIwPPRkQiapJsv+eTt7V3V9Fl84UxSNLoq2qUyNBCDP8xe0Qfv2O+RYJ3juxVaLu1g== X-Received: by 2002:a92:c5cd:0:b0:365:44:1edb with SMTP id s13-20020a92c5cd000000b0036500441edbmr4716100ilt.3.1708131541456; Fri, 16 Feb 2024 16:59:01 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:59:01 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 18/20] tools arch uapi: Sync the uinstd.h header file for RISC-V Date: Fri, 16 Feb 2024 16:57:36 -0800 Message-Id: <20240217005738.3744121-19-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165903_385485_C90ACA53 X-CRM114-Status: GOOD ( 12.71 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The uninstd.h has been changed since it's last sync. Update it so that perf tool can use the new RISC-V specific syscall in perf tool. Signed-off-by: Atish Patra --- tools/arch/riscv/include/uapi/asm/unistd.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/arch/riscv/include/uapi/asm/unistd.h b/tools/arch/riscv/include/uapi/asm/unistd.h index f506cca520b0..950ab3fd4409 100644 --- a/tools/arch/riscv/include/uapi/asm/unistd.h +++ b/tools/arch/riscv/include/uapi/asm/unistd.h @@ -15,11 +15,14 @@ * along with this program. If not, see . */ -#ifdef __LP64__ +#if defined(__LP64__) && !defined(__SYSCALL_COMPAT) #define __ARCH_WANT_NEW_STAT #define __ARCH_WANT_SET_GET_RLIMIT #endif /* __LP64__ */ +#define __ARCH_WANT_SYS_CLONE3 +#define __ARCH_WANT_MEMFD_SECRET + #include /* @@ -40,3 +43,12 @@ #define __NR_riscv_flush_icache (__NR_arch_specific_syscall + 15) #endif __SYSCALL(__NR_riscv_flush_icache, sys_riscv_flush_icache) + +/* + * Allows userspace to query the kernel for CPU architecture and + * microarchitecture details across a given set of CPUs. + */ +#ifndef __NR_riscv_hwprobe +#define __NR_riscv_hwprobe (__NR_arch_specific_syscall + 14) +#endif +__SYSCALL(__NR_riscv_hwprobe, sys_riscv_hwprobe) From patchwork Sat Feb 17 00:57:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561160 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 122C0C48BF5 for ; Sat, 17 Feb 2024 00:59:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3MhqTlEqHwr7Ig/1xEQC3A8p23AfeF0bSq02P1U3nW4=; b=u3j91tjaLl2MDc o+0is0X9Gp91U/VtMoh9Afh/zxMZ54/OeRH6lZv5gzALrf0bM0EmDweTG3mNF3gc9Pt0orPVXXCYt QIGsc0gB0a1hJhm0wfVm/mEQwiEy6bGVz0mmutwW8f7r5exy91Fzuukn4esPvs/n8+et7KRay6YmZ 3+Y3el/btxn+ggenZu7ptJyJOb1P6nSGJPv1L3C8hS2VA5ogV9svAxLiz5XwY9vuh0pCIRFgXyoGJ bNTVY8RvxMH378FSgWiMYPNnieuR/tY7RM0vmzh2qt3kJu2k1ujPIFhUcjXK3Bllq3HwtdCHD8yWW FyvJBsSIEo7QSiTxOuMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb93P-00000004J89-2EM3; Sat, 17 Feb 2024 00:59:43 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92n-00000004IYG-03Jh for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:59:17 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-21e3c16880fso1312128fac.2 for ; Fri, 16 Feb 2024 16:59:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131544; x=1708736344; darn=lists.infradead.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=5vDBckQYWb4Du0H7yzxJq6wilfl8k4fp2vqlUJD6o0E=; b=ewmB9M0wcrETYjIrCIsn85VMEI1Eoxj8AOoLb4iaGTCdfAJPqmZrqX5z/AUrbCtsWi LyglXhuKKDFepAaDB94l1NtIsvSQTQ6/g8b+6x31O9rS1DMMG3sDQv+1XN3ECUK7+6Ug RXrq/IDvpnd4tWOSWj++PUmV75/vsnUKd+8g2emdijgTrmkyKL3O2M9Gup7+EAGPtLz0 TNg9u9VINFK/E+gU1ncc06DyOSNLjObyQX1O1uratPVO34HNS8e97EpQaLPbREtEOSKy vrOZFGWKMDNfmUO4lWEm6Cqbkn9gAI+c7i2x1v92UeVtdWnq1n8Voc/grCAGmEpcjwlC HyZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131544; x=1708736344; 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=5vDBckQYWb4Du0H7yzxJq6wilfl8k4fp2vqlUJD6o0E=; b=k9QN2AhyGW89aq+lv65JKyGCTfnJYjoupTVJo3eiWSq7KgVfCSm5+kLEmMB77as67H EkL8ZcT0k0sdo+hAP7uhbX30X0x6r2vbvKFCfcjCjWGHD1bmc1g0uu4wmjT9yvpdKWXk ikClVuDAyS9CtZyQLA6dXow8BMYvI5YQBwzOnoY8Zv1r1R0iJxG86I3Jj4/GJee1Vc52 N0kXj6rh1sz7vW37YCmc7nXZQ7HGx+1K/7vvmPaZQgwTqSMxKbAIjdKD4VwRAiMLwCEm ngMq7F8NyT8WtvN/nnDJY9VJ3GizzZqFpv437ow4R1F594nEJr0ijlF+XHpJIc5roFqB 6NPw== X-Forwarded-Encrypted: i=1; AJvYcCVMDqBCdt85SPuhqU7n6yLx1pSaQ6PUQMZI15xNP2Q0IFLKPcxBwk8NB5fVQcf7TyEgmO/y2G1QyybEsT1LWMg4Kke1E4ncN7RogFaIsviX X-Gm-Message-State: AOJu0Yw0uhAk3CWE5YeWkA8DFWzgrbP8pI6CxRIOnMhktvgris7p2tEq u3Zixe6T/H+pAx38aIcaiQCsXiqemb8QMfXfpwtFcljHP0RK6vI4BONDUM4z7qM= X-Google-Smtp-Source: AGHT+IHqkQqjQYTImWOgjE8Z+USH8QzipcCkOvNcsVcXAj1JgydRRCEivR2TUgJmzC2SDHg1vvWlZA== X-Received: by 2002:a05:6870:478a:b0:21e:698f:5c91 with SMTP id c10-20020a056870478a00b0021e698f5c91mr3327913oaq.41.1708131544105; Fri, 16 Feb 2024 16:59:04 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:59:03 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 19/20] RISC-V: Add hwprobe support for Counter delegation extensions Date: Fri, 16 Feb 2024 16:57:37 -0800 Message-Id: <20240217005738.3744121-20-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165905_395696_A07FB58E X-CRM114-Status: GOOD ( 13.68 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Even though the counter delegation extensions are all S-mode extension, perf tool can use it decide whether it wants to map standard events or not. Remapping is not required for if SBI PMU is being used for hardware events. Signed-off-by: Atish Patra --- Documentation/arch/riscv/hwprobe.rst | 10 ++++++++++ arch/riscv/include/uapi/asm/hwprobe.h | 4 ++++ arch/riscv/kernel/sys_hwprobe.c | 3 +++ 3 files changed, 17 insertions(+) diff --git a/Documentation/arch/riscv/hwprobe.rst b/Documentation/arch/riscv/hwprobe.rst index b2bcc9eed9aa..77fa0ed09366 100644 --- a/Documentation/arch/riscv/hwprobe.rst +++ b/Documentation/arch/riscv/hwprobe.rst @@ -188,6 +188,16 @@ The following keys are defined: manual starting from commit 95cf1f9 ("Add changes requested by Ved during signoff") + * :c:macro:`RISCV_HWPROBE_EXT_SMCDELEG`: The Smcdeleg extension is supported as + defined in the RISC-V Counter Delegation extension manual starting from + commit ff61c1f ("switch to v1.0.0 and frozen") + * :c:macro:`RISCV_HWPROBE_EXT_SSCCFG`: The Ssccfg extension is supported as + defined in the RISC-V Counter Delegation extension manual starting from + commit ff61c1f ("switch to v1.0.0 and frozen") + * :c:macro:`RISCV_HWPROBE_EXT_SSCSRIND`: The Sscsrind extension is supported as + defined in the RISC-V Indirect CSR extension manual starting from + commit a28625c ("mark spec as frozen") + * :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: A bitmask that contains performance information about the selected set of processors. diff --git a/arch/riscv/include/uapi/asm/hwprobe.h b/arch/riscv/include/uapi/asm/hwprobe.h index 9f2a8e3ff204..fb7c6bd6822a 100644 --- a/arch/riscv/include/uapi/asm/hwprobe.h +++ b/arch/riscv/include/uapi/asm/hwprobe.h @@ -59,6 +59,10 @@ struct riscv_hwprobe { #define RISCV_HWPROBE_EXT_ZTSO (1ULL << 33) #define RISCV_HWPROBE_EXT_ZACAS (1ULL << 34) #define RISCV_HWPROBE_EXT_ZICOND (1ULL << 35) +#define RISCV_HWPROBE_EXT_SSCSRIND (1ULL << 36) +#define RISCV_HWPROBE_EXT_SMCDELEG (1ULL << 37) +#define RISCV_HWPROBE_EXT_SSCCFG (1ULL << 38) + #define RISCV_HWPROBE_KEY_CPUPERF_0 5 #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) #define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0) diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwprobe.c index a7c56b41efd2..befb6582b1ce 100644 --- a/arch/riscv/kernel/sys_hwprobe.c +++ b/arch/riscv/kernel/sys_hwprobe.c @@ -111,6 +111,9 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair, EXT_KEY(ZTSO); EXT_KEY(ZACAS); EXT_KEY(ZICOND); + EXT_KEY(SSCSRIND); + EXT_KEY(SMCDELEG); + EXT_KEY(SSCCFG); if (has_vector()) { EXT_KEY(ZVBB); From patchwork Sat Feb 17 00:57:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13561161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E3CE6C48BF5 for ; Sat, 17 Feb 2024 00:59:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=s0Mpx0PSqZzSoqslfPkmXW90qgEQC+X832U17xShqGo=; b=oGnRSjb8w0Gjrq cVAvY4S66m07+SjWa5+ipcRrr9meNZpKWtPwOdhznWLOwjRJltho6AvTZSQLzMqgJk8YRb/EwzXqC LgqLmEAL7pcLGO/5J04Aqmjc7jofjL5eAZTudqzPZXVysUBW4PVrOnci6y9rKTn2ggtxkDk5Scd0L /3bjb5O9m93XHpBdnp2w5Gw2MHATX0WfEfFbaE0RuLLVfteGAhozfKq/0RhK83eCjg6oKE9GTTwwK iTgYHp/zxq+G5l/91yG2IzICm0I1gKGhQT3FXXWF8KtnndOJx8UmtaUSYapvTHrLk+Ca/f4Dgbx6m 9G5gKBP0hP9nfFY8Ye8Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb93U-00000004JD5-1ODQ; Sat, 17 Feb 2024 00:59:48 +0000 Received: from mail-io1-f52.google.com ([209.85.166.52]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb92p-00000004Iag-4392 for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 00:59:17 +0000 Received: by mail-io1-f52.google.com with SMTP id ca18e2360f4ac-7bf2c826a5aso115220639f.0 for ; Fri, 16 Feb 2024 16:59:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708131546; x=1708736346; darn=lists.infradead.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=Lkx6F3sDxrDVxzkfg/gwx98H53iZQ+xAtDorLNCTdGY=; b=HuGVz15gExGvwJvMgHvmFAX9S/BRCszgJwRICSADzwOKCxOoGv4MZ2e7tR1rzkN5Xk YGuHSX1harOSIXitTQaEeHteUB0uTNc4qiyASh80Rg/W0uKpc7e2OdLgY1NxMCNth7yy nTYwAsBlyLMRFj+OPsqBc88Hw0SxvmmJxlsaJ4Ig50ZBTmL4En36kBQwu11Xpd62T3JE WHQM+jiDBivXTXnufNJgidD/2kEgYLx+TXxedWfLtLlWAFOb+FqUJ7etSxV4l6ZOYmjg ztRBCk7PAFXlS1cJmrXS8Yx238BH/J9XPCGKnmvYCm2JA9MR7DqmwSZk4S7b1dEj1A1g f/Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708131546; x=1708736346; 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=Lkx6F3sDxrDVxzkfg/gwx98H53iZQ+xAtDorLNCTdGY=; b=um2ifuDUwJWAz2fOOvtJ7FXnWsGXIp9XnxvuPEmHK8pRDJJoAzMcMS7LR5wO+ClLwj i3qjrKD9DtMJEqChOTMbs5dv3Zs4wInovfA1vsrR/CaeIDdhR1JCN0Bwev1yVLbO9IWM uV1biXvT6UGeaVNTgrsVNnTBj0z4WIEYozhErzu2PzP5qVYtkWPS2ukgQTLXmdFZYvuf NrhhXI0u6mVvxyKg69Yd8t1EINNm5OARPQhMmlAcN9eZCipPOcs5y90Xru94D+pECA49 cNkV46YAVMe0WcEouZKC49WnSz3Ky9RG1MAVqPRVABIvde0vG6GKg6VPeOxPc27Z/OQw jMRg== X-Forwarded-Encrypted: i=1; AJvYcCVF8cwKGgQTLFMeCXjK6OP2yIpS3+3Yvm4G3UsBMnpN3MX9wdCLoLWGMJJj30wDNaFGxfkNcYEbb1rvZsdnoQEx5IRzpeGnHOXnUu0tblZf X-Gm-Message-State: AOJu0YzCu3Zh2QgMkrnV2+6jlWr2HUWK/3Y3c2su2PgjEG9ABq73EeUI MZQ6EpO0jEj0LWQGvHt20jQCAm+yIGoj/+pWaZK5JpcsfzCN+H3L03bdBQ1S4Ok= X-Google-Smtp-Source: AGHT+IEe3ejDyxspMJxarQru2mpOZGVU3gTQalogFZ4IV/qmTtJpwp0XG9IR02+mun9kkUrwLV3/Rw== X-Received: by 2002:a05:6602:2766:b0:7c4:9618:5fcb with SMTP id l6-20020a056602276600b007c496185fcbmr7195778ioe.8.1708131546705; Fri, 16 Feb 2024 16:59:06 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d188-20020a6336c5000000b005dc89957e06sm487655pga.71.2024.02.16.16.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:59:06 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Adrian Hunter , Alexander Shishkin , Alexandre Ghiti , Andrew Jones , Anup Patel , Arnaldo Carvalho de Melo , Atish Patra , Christian Brauner , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Conor Dooley , devicetree@vger.kernel.org, Evan Green , Guo Ren , Heiko Stuebner , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , Ji Sheng Teoh , John Garry , Jonathan Corbet , Kan Liang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, Ley Foon Tan , linux-doc@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rob Herring , Samuel Holland , Weilin Wang , Will Deacon , kaiwenxue1@gmail.com, Yang Jihong Subject: [PATCH RFC 20/20] tools/perf: Detect if platform supports counter delegation Date: Fri, 16 Feb 2024 16:57:38 -0800 Message-Id: <20240217005738.3744121-21-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217005738.3744121-1-atishp@rivosinc.com> References: <20240217005738.3744121-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_165908_375949_9398806D X-CRM114-Status: GOOD ( 21.17 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The perf tool currently remap the standard events to the encoding specified by the platform in the json file. We need that only if the counter delegation extension is present. Otherwise, SBI PMU interface is used which defines the encoding for all standard events. The hwprobe mechanism can be used to detect the presence of these extensions and remap the encoding space only in that case. Signed-off-by: Atish Patra --- tools/perf/arch/riscv/util/Build | 1 + tools/perf/arch/riscv/util/evlist.c | 3 ++- tools/perf/arch/riscv/util/pmu.c | 41 +++++++++++++++++++++++++++++ tools/perf/arch/riscv/util/pmu.h | 11 ++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tools/perf/arch/riscv/util/pmu.c create mode 100644 tools/perf/arch/riscv/util/pmu.h diff --git a/tools/perf/arch/riscv/util/Build b/tools/perf/arch/riscv/util/Build index b581fb3d8677..2358f0666e8d 100644 --- a/tools/perf/arch/riscv/util/Build +++ b/tools/perf/arch/riscv/util/Build @@ -1,6 +1,7 @@ perf-y += perf_regs.o perf-y += header.o perf-y += evlist.o +perf-y += pmu.o perf-$(CONFIG_DWARF) += dwarf-regs.o perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o diff --git a/tools/perf/arch/riscv/util/evlist.c b/tools/perf/arch/riscv/util/evlist.c index 9ad287c6f396..aa7eef7280ca 100644 --- a/tools/perf/arch/riscv/util/evlist.c +++ b/tools/perf/arch/riscv/util/evlist.c @@ -6,6 +6,7 @@ #include "util/parse-events.h" #include "util/event.h" #include "evsel.h" +#include "pmu.h" static int pmu_update_cpu_stdevents_callback(const struct pmu_event *pe, const struct pmu_events_table *table __maybe_unused, @@ -41,7 +42,7 @@ int arch_evlist__override_default_attrs(struct evlist *evlist, const char *pmu_n "iTLB-load-misses"}; unsigned int i, len = sizeof(overriden_event_arr) / sizeof(char *); - if (!pmu) + if (!pmu || !perf_pmu_riscv_cdeleg_present()) return 0; for (i = 0; i < len; i++) { diff --git a/tools/perf/arch/riscv/util/pmu.c b/tools/perf/arch/riscv/util/pmu.c new file mode 100644 index 000000000000..79f0974e27f8 --- /dev/null +++ b/tools/perf/arch/riscv/util/pmu.c @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright Rivos Inc 2024 + * Author(s): Atish Patra + */ + +#include +#include +#include +#include +#include + +#include "pmu.h" + +static bool counter_deleg_present; + +bool perf_pmu_riscv_cdeleg_present(void) +{ + return counter_deleg_present; +} + +void perf_pmu__arch_init(struct perf_pmu *pmu __maybe_unused) +{ + struct riscv_hwprobe isa_ext; + int ret; + + isa_ext.key = RISCV_HWPROBE_KEY_IMA_EXT_0; + + ret = syscall(__NR_riscv_hwprobe, &isa_ext, 1, 0, NULL, 0); + if (ret) + return; + + if (isa_ext.key < 0) + return; + + if ((isa_ext.value & RISCV_HWPROBE_EXT_SSCSRIND) && + (isa_ext.value & RISCV_HWPROBE_EXT_SMCDELEG) && + (isa_ext.value & RISCV_HWPROBE_EXT_SSCCFG)) + counter_deleg_present = true; +} diff --git a/tools/perf/arch/riscv/util/pmu.h b/tools/perf/arch/riscv/util/pmu.h new file mode 100644 index 000000000000..21f33f7d323d --- /dev/null +++ b/tools/perf/arch/riscv/util/pmu.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __RISCV_UTIL_PMU_H +#define __RISCV_UTIL_PMU_H + +#include "../../../util/pmu.h" + + +bool perf_pmu_riscv_cdeleg_present(void); + +#endif