Code view:

A painting is a person's account of this edit as text, recorded independently of the node mapping - a rendering often has several equally defensible answers where the mapping has one. Deletions and insertions carry no position on the opposite side in a painting, so that panel draws no caret for them.

Before

…lines 1–6 unchanged (6 lines)
7 */
8
9#define pr_fmt(fmt) "riscv-kvm-pmu: " fmt
10#include <linux/errno.h>
11#include <linux/err.h>
12#include <linux/kvm_host.h>
13#include <linux/perf/riscv_pmu.h>
14#include <asm/csr.h>
15#include <asm/kvm_vcpu_sbi.h>
16#include <asm/kvm_vcpu_pmu.h>
17#include <asm/sbi.h>
18#include <linux/bitops.h>
19
…lines 20–83 unchanged (64 lines)
84 pmc->perf_event = NULL;
85 }
86}
87
88static u64 kvm_pmu_get_perf_event_hw_config(u32 sbi_event_code)
89{
90 return hw_event_perf_map[sbi_event_code];
91}
92
93static u64 kvm_pmu_get_perf_event_cache_config(u32 sbi_event_code)
94{
95 u64 config = U64_MAX;
96 unsigned int cache_type, cache_op, cache_result;
…lines 97–213 unchanged (117 lines)
214 }
215
216 if (cidx >= kvm_pmu_num_counters(kvpmu) || cidx == 1) {
217 pr_warn("Invalid counter id [%ld]during read\n", cidx);
218 return -EINVAL;
219 }
220
221 pmc = &kvpmu->pmc[cidx];
222
223 if (pmc->cinfo.type != SBI_PMU_CTR_TYPE_FW)
224 return -EINVAL;
225
226 fevent_code = get_event_code(pmc->event_idx);
…lines 227–239 unchanged (13 lines)
240 int fevent_code;
241
242 if (cidx >= kvm_pmu_num_counters(kvpmu) || cidx == 1) {
243 pr_warn("Invalid counter id [%ld] during read\n", cidx);
244 return -EINVAL;
245 }
246
247 pmc = &kvpmu->pmc[cidx];
248
249 if (pmc->cinfo.type == SBI_PMU_CTR_TYPE_FW) {
250 fevent_code = get_event_code(pmc->event_idx);
251 pmc->counter_val = kvpmu->fw_event[fevent_code].value;
252 } else if (pmc->perf_event) {
…lines 253–520 unchanged (268 lines)
521 struct kvm_pmu *kvpmu = vcpu_to_pmu(vcpu);
522
523 if (cidx >= RISCV_KVM_MAX_COUNTERS || cidx == 1) {
524 retdata->err_val = SBI_ERR_INVALID_PARAM;
525 return 0;
526 }
527
528 retdata->out_val = kvpmu->pmc[cidx].cinfo.value;
529
530 return 0;
531}
532
533int kvm_riscv_vcpu_pmu_ctr_start(struct kvm_vcpu *vcpu, unsigned long ctr_base,
…lines 534–555 unchanged (22 lines)
556 sbiret = SBI_ERR_FAILURE;
557 goto out;
558 }
559 }
560 /* Start the counters that have been configured and requested by the guest */
561 for_each_set_bit(i, &ctr_mask, RISCV_MAX_COUNTERS) {
562 pmc_index = i + ctr_base;
563 if (!test_bit(pmc_index, kvpmu->pmc_in_use))
564 continue;
565 /* The guest started the counter again. Reset the overflow status */
566 clear_bit(pmc_index, kvpmu->pmc_overflown);
567 pmc = &kvpmu->pmc[pmc_index];
568 if (flags & SBI_PMU_START_FLAG_SET_INIT_VALUE) {
…lines 569–626 unchanged (58 lines)
627 sbiret = SBI_ERR_NO_SHMEM;
628 goto out;
629 }
630
631 /* Stop the counters that have been configured and requested by the guest */
632 for_each_set_bit(i, &ctr_mask, RISCV_MAX_COUNTERS) {
633 pmc_index = i + ctr_base;
634 if (!test_bit(pmc_index, kvpmu->pmc_in_use))
635 continue;
636 pmc = &kvpmu->pmc[pmc_index];
637 if (pmc->cinfo.type == SBI_PMU_CTR_TYPE_FW) {
638 fevent_code = get_event_code(pmc->event_idx);
639 if (fevent_code >= SBI_PMU_FW_MAX) {
…lines 640–756 unchanged (117 lines)
757 ctr_idx = pmu_get_pmc_index(kvpmu, eidx, ctr_base, ctr_mask);
758 if (ctr_idx < 0) {
759 sbiret = SBI_ERR_NOT_SUPPORTED;
760 goto out;
761 }
762 }
763
764 pmc = &kvpmu->pmc[ctr_idx];
765 pmc->idx = ctr_idx;
766
767 if (is_fevent) {
768 if (flags & SBI_PMU_CFG_FLAG_AUTO_START)
769 kvpmu->fw_event[event_code].started = true;
…lines 770–904 unchanged (135 lines)

After

…lines 1–6 unchanged (6 lines)
7 */
8
9#define pr_fmt(fmt) "riscv-kvm-pmu: " fmt
10#include <linux/errno.h>
11#include <linux/err.h>
12#include <linux/kvm_host.h>
13#include <linux/nospec.h>
14#include <linux/perf/riscv_pmu.h>
15#include <asm/csr.h>
16#include <asm/kvm_vcpu_sbi.h>
17#include <asm/kvm_vcpu_pmu.h>
18#include <asm/sbi.h>
19#include <linux/bitops.h>
…lines 20–84 unchanged (65 lines)
85 pmc->perf_event = NULL;
86 }
87}
88
89static u64 kvm_pmu_get_perf_event_hw_config(u32 sbi_event_code)
90{
91 return hw_event_perf_map[array_index_nospec(sbi_event_code,
92 SBI_PMU_HW_GENERAL_MAX)];
93}
94
95static u64 kvm_pmu_get_perf_event_cache_config(u32 sbi_event_code)
96{
97 u64 config = U64_MAX;
98 unsigned int cache_type, cache_op, cache_result;
…lines 99–216 unchanged (118 lines)
217
218 if (cidx >= kvm_pmu_num_counters(kvpmu) || cidx == 1) {
219 pr_warn("Invalid counter id [%ld]during read\n", cidx);
220 return -EINVAL;
221 }
222
223 cidx = array_index_nospec(cidx, RISCV_KVM_MAX_COUNTERS);
224 pmc = &kvpmu->pmc[cidx];
225
226 if (pmc->cinfo.type != SBI_PMU_CTR_TYPE_FW)
227 return -EINVAL;
228
229 fevent_code = get_event_code(pmc->event_idx);
…lines 230–243 unchanged (14 lines)
244
245 if (cidx >= kvm_pmu_num_counters(kvpmu) || cidx == 1) {
246 pr_warn("Invalid counter id [%ld] during read\n", cidx);
247 return -EINVAL;
248 }
249
250 cidx = array_index_nospec(cidx, RISCV_KVM_MAX_COUNTERS);
251 pmc = &kvpmu->pmc[cidx];
252
253 if (pmc->cinfo.type == SBI_PMU_CTR_TYPE_FW) {
254 fevent_code = get_event_code(pmc->event_idx);
255 pmc->counter_val = kvpmu->fw_event[fevent_code].value;
256 } else if (pmc->perf_event) {
…lines 257–525 unchanged (269 lines)
526
527 if (cidx >= RISCV_KVM_MAX_COUNTERS || cidx == 1) {
528 retdata->err_val = SBI_ERR_INVALID_PARAM;
529 return 0;
530 }
531
532 cidx = array_index_nospec(cidx, RISCV_KVM_MAX_COUNTERS);
533 retdata->out_val = kvpmu->pmc[cidx].cinfo.value;
534
535 return 0;
536}
537
538int kvm_riscv_vcpu_pmu_ctr_start(struct kvm_vcpu *vcpu, unsigned long ctr_base,
…lines 539–560 unchanged (22 lines)
561 sbiret = SBI_ERR_FAILURE;
562 goto out;
563 }
564 }
565 /* Start the counters that have been configured and requested by the guest */
566 for_each_set_bit(i, &ctr_mask, RISCV_MAX_COUNTERS) {
567 pmc_index = array_index_nospec(i + ctr_base,
568 RISCV_KVM_MAX_COUNTERS);
569 if (!test_bit(pmc_index, kvpmu->pmc_in_use))
570 continue;
571 /* The guest started the counter again. Reset the overflow status */
572 clear_bit(pmc_index, kvpmu->pmc_overflown);
573 pmc = &kvpmu->pmc[pmc_index];
574 if (flags & SBI_PMU_START_FLAG_SET_INIT_VALUE) {
…lines 575–632 unchanged (58 lines)
633 sbiret = SBI_ERR_NO_SHMEM;
634 goto out;
635 }
636
637 /* Stop the counters that have been configured and requested by the guest */
638 for_each_set_bit(i, &ctr_mask, RISCV_MAX_COUNTERS) {
639 pmc_index = array_index_nospec(i + ctr_base,
640 RISCV_KVM_MAX_COUNTERS);
641 if (!test_bit(pmc_index, kvpmu->pmc_in_use))
642 continue;
643 pmc = &kvpmu->pmc[pmc_index];
644 if (pmc->cinfo.type == SBI_PMU_CTR_TYPE_FW) {
645 fevent_code = get_event_code(pmc->event_idx);
646 if (fevent_code >= SBI_PMU_FW_MAX) {
…lines 647–764 unchanged (118 lines)
765 if (ctr_idx < 0) {
766 sbiret = SBI_ERR_NOT_SUPPORTED;
767 goto out;
768 }
769 }
770
771 ctr_idx = array_index_nospec(ctr_idx, RISCV_KVM_MAX_COUNTERS);
772 pmc = &kvpmu->pmc[ctr_idx];
773 pmc->idx = ctr_idx;
774
775 if (is_fevent) {
776 if (flags & SBI_PMU_CFG_FLAG_AUTO_START)
777 kvpmu->fw_event[event_code].started = true;
…lines 778–912 unchanged (135 lines)

Before

translation_unit
comment "// SPDX-License-Identifier: GPL-2.0"
comment "/*\n * Copyright (c) 2023 Rivos Inc\n *\n * Authors:\n * Ati"...
preproc_function_def
#define "#define"
identifier "pr_fmt"
preproc_params
( "("
identifier "fmt"
) ")"
preproc_arg "\"riscv-kvm-pmu: \" fmt"
preproc_include
#include "#include"
system_lib_string "<linux/errno.h>"
preproc_include
#include "#include"
system_lib_string "<linux/err.h>"
preproc_include
#include "#include"
system_lib_string "<linux/kvm_host.h>"
preproc_include
#include "#include"
system_lib_string "<linux/perf/riscv_pmu.h>"
preproc_include
#include "#include"
system_lib_string "<asm/csr.h>"
preproc_include
#include "#include"
system_lib_string "<asm/kvm_vcpu_sbi.h>"
preproc_include
#include "#include"
system_lib_string "<asm/kvm_vcpu_pmu.h>"
preproc_include
#include "#include"
system_lib_string "<asm/sbi.h>"
preproc_include
#include "#include"
system_lib_string "<linux/bitops.h>"
preproc_function_def
#define "#define"
identifier "kvm_pmu_num_counters"
preproc_params
( "("
identifier "pmu"
) ")"
preproc_arg "((pmu)->num_hw_ctrs + (pmu)->num_fw_ctrs)"
preproc_function_def
#define "#define"
identifier "get_event_type"
preproc_params
( "("
identifier "x"
) ")"
preproc_arg "(((x) & SBI_PMU_EVENT_IDX_TYPE_MASK) >> 16)"
preproc_function_def
#define "#define"
identifier "get_event_code"
preproc_params
( "("
identifier "x"
) ")"
preproc_arg "((x) & SBI_PMU_EVENT_IDX_CODE_MASK)"
declaration (+97 nodes collapsed)
function_definition (+83 nodes collapsed)
function_definition (+104 nodes collapsed)
function_definition (+29 nodes collapsed)
function_definition (+63 nodes collapsed)
function_definition
storage_class_specifier
static "static"
type_identifier "u64"
function_declarator
identifier "kvm_pmu_get_perf_event_hw_config"
parameter_list
( "("
parameter_declaration
type_identifier "u32"
identifier "sbi_event_code"
) ")"
compound_statement
{ "{"
return_statement
return "return"
subscript_expression
identifier "hw_event_perf_map"
[ "["
identifier "sbi_event_code"
] "]"
; ";"
} "}"
function_definition (+125 nodes collapsed)
function_definition (+181 nodes collapsed)
function_definition (+92 nodes collapsed)
function_definition (+188 nodes collapsed)
function_definition (+81 nodes collapsed)
function_definition
storage_class_specifier
static "static"
primitive_type "int"
function_declarator (+26 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmu"
init_declarator
pointer_declarator
* "*"
identifier "kvpmu"
= "="
call_expression
identifier "vcpu_to_pmu"
argument_list
( "("
identifier "vcpu"
) ")"
; ";"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmc"
pointer_declarator
* "*"
identifier "pmc"
; ";"
declaration
primitive_type "int"
identifier "fevent_code"
; ";"
if_statement (+36 nodes collapsed)
if_statement (+43 nodes collapsed)
expression_statement
assignment_expression
identifier "pmc"
= "="
pointer_expression
& "&"
subscript_expression
field_expression
identifier "kvpmu"
-> "->"
field_identifier "pmc"
[ "["
identifier "cidx"
] "]"
; ";"
if_statement (+21 nodes collapsed)
expression_statement
assignment_expression
identifier "fevent_code"
= "="
call_expression
identifier "get_event_code"
argument_list
( "("
field_expression
identifier "pmc"
-> "->"
field_identifier "event_idx"
) ")"
; ";"
expression_statement
assignment_expression
field_expression
identifier "pmc"
-> "->"
field_identifier "counter_val"
= "="
field_expression
subscript_expression
field_expression
identifier "kvpmu"
-> "->"
field_identifier "fw_event"
[ "["
identifier "fevent_code"
] "]"
. "."
field_identifier "value"
; ";"
expression_statement
assignment_expression
pointer_expression
* "*"
identifier "out_val"
= "="
binary_expression
field_expression
identifier "pmc"
-> "->"
field_identifier "counter_val"
>> ">>"
number_literal "32"
; ";"
return_statement
return "return"
number_literal "0"
; ";"
} "}"
function_definition
storage_class_specifier
static "static"
primitive_type "int"
function_declarator (+26 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmu"
init_declarator
pointer_declarator
* "*"
identifier "kvpmu"
= "="
call_expression
identifier "vcpu_to_pmu"
argument_list
( "("
identifier "vcpu"
) ")"
; ";"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmc"
pointer_declarator
* "*"
identifier "pmc"
; ";"
declaration
type_identifier "u64"
identifier "enabled"
, ","
identifier "running"
; ";"
declaration
primitive_type "int"
identifier "fevent_code"
; ";"
if_statement (+43 nodes collapsed)
expression_statement
assignment_expression
identifier "pmc"
= "="
pointer_expression
& "&"
subscript_expression
field_expression
identifier "kvpmu"
-> "->"
field_identifier "pmc"
[ "["
identifier "cidx"
] "]"
; ";"
if_statement (+101 nodes collapsed)
expression_statement
assignment_expression
pointer_expression
* "*"
identifier "out_val"
= "="
field_expression
identifier "pmc"
-> "->"
field_identifier "counter_val"
; ";"
return_statement
return "return"
number_literal "0"
; ";"
} "}"
function_definition (+72 nodes collapsed)
function_definition (+225 nodes collapsed)
function_definition (+211 nodes collapsed)
function_definition (+103 nodes collapsed)
function_definition (+173 nodes collapsed)
function_definition (+65 nodes collapsed)
function_definition (+299 nodes collapsed)
function_definition (+428 nodes collapsed)
function_definition (+59 nodes collapsed)
function_definition
primitive_type "int"
function_declarator (+26 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmu"
init_declarator
pointer_declarator
* "*"
identifier "kvpmu"
= "="
call_expression
identifier "vcpu_to_pmu"
argument_list
( "("
identifier "vcpu"
) ")"
; ";"
if_statement (+31 nodes collapsed)
expression_statement (+22 nodes collapsed)
return_statement
return "return"
number_literal "0"
; ";"
} "}"
function_definition
primitive_type "int"
function_declarator (+42 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmu"
init_declarator
pointer_declarator
* "*"
identifier "kvpmu"
= "="
call_expression
identifier "vcpu_to_pmu"
argument_list
( "("
identifier "vcpu"
) ")"
; ";"
declaration
primitive_type "int"
identifier "i"
, ","
identifier "pmc_index"
, ","
init_declarator
identifier "sbiret"
= "="
number_literal "0"
; ";"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmc"
pointer_declarator
* "*"
identifier "pmc"
; ";"
declaration
primitive_type "int"
identifier "fevent_code"
; ";"
declaration
primitive_type "bool"
init_declarator
identifier "snap_flag_set"
= "="
binary_expression
identifier "flags"
& "&"
identifier "SBI_PMU_START_FLAG_INIT_SNAPSHOT"
; ";"
if_statement (+31 nodes collapsed)
if_statement (+89 nodes collapsed)
comment "/* Start the counters that have been configured and requeste"...
expression_statement
call_expression
identifier "for_each_set_bit"
argument_list
( "("
identifier "i"
, ","
pointer_expression
& "&"
identifier "ctr_mask"
, ","
identifier "RISCV_MAX_COUNTERS"
) ")"
; ""
compound_statement
{ "{"
expression_statement
assignment_expression
identifier "pmc_index"
= "="
binary_expression
identifier "i"
+ "+"
identifier "ctr_base"
; ";"
if_statement (+21 nodes collapsed)
comment "/* The guest started the counter again. Reset the overflow s"...
expression_statement
call_expression
identifier "clear_bit"
argument_list
( "("
identifier "pmc_index"
, ","
field_expression
identifier "kvpmu"
-> "->"
field_identifier "pmc_overflown"
) ")"
; ";"
expression_statement
assignment_expression
identifier "pmc"
= "="
pointer_expression
& "&"
subscript_expression
field_expression
identifier "kvpmu"
-> "->"
field_identifier "pmc"
[ "["
identifier "pmc_index"
] "]"
; ";"
if_statement (+52 nodes collapsed)
if_statement (+207 nodes collapsed)
} "}"
labeled_statement
statement_identifier "out"
: ":"
expression_statement
assignment_expression
field_expression
identifier "retdata"
-> "->"
field_identifier "err_val"
= "="
identifier "sbiret"
; ";"
return_statement
return "return"
number_literal "0"
; ";"
} "}"
function_definition
primitive_type "int"
function_declarator (+38 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmu"
init_declarator
pointer_declarator
* "*"
identifier "kvpmu"
= "="
call_expression
identifier "vcpu_to_pmu"
argument_list
( "("
identifier "vcpu"
) ")"
; ";"
declaration
primitive_type "int"
identifier "i"
, ","
identifier "pmc_index"
, ","
init_declarator
identifier "sbiret"
= "="
number_literal "0"
; ";"
declaration
type_identifier "u64"
identifier "enabled"
, ","
identifier "running"
; ";"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmc"
pointer_declarator
* "*"
identifier "pmc"
; ";"
declaration
primitive_type "int"
identifier "fevent_code"
; ";"
declaration
primitive_type "bool"
init_declarator
identifier "snap_flag_set"
= "="
binary_expression
identifier "flags"
& "&"
identifier "SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT"
; ";"
declaration
primitive_type "bool"
init_declarator
identifier "shmem_needs_update"
= "="
false "false"
; ";"
if_statement (+31 nodes collapsed)
if_statement (+28 nodes collapsed)
comment "/* Stop the counters that have been configured and requested"...
expression_statement
call_expression
identifier "for_each_set_bit"
argument_list
( "("
identifier "i"
, ","
pointer_expression
& "&"
identifier "ctr_mask"
, ","
identifier "RISCV_MAX_COUNTERS"
) ")"
; ""
compound_statement
{ "{"
expression_statement
assignment_expression
identifier "pmc_index"
= "="
binary_expression
identifier "i"
+ "+"
identifier "ctr_base"
; ";"
if_statement (+21 nodes collapsed)
expression_statement
assignment_expression
identifier "pmc"
= "="
pointer_expression
& "&"
subscript_expression
field_expression
identifier "kvpmu"
-> "->"
field_identifier "pmc"
[ "["
identifier "pmc_index"
] "]"
; ";"
if_statement (+181 nodes collapsed)
if_statement (+143 nodes collapsed)
if_statement (+82 nodes collapsed)
} "}"
if_statement (+33 nodes collapsed)
labeled_statement
statement_identifier "out"
: ":"
expression_statement
assignment_expression
field_expression
identifier "retdata"
-> "->"
field_identifier "err_val"
= "="
identifier "sbiret"
; ";"
return_statement
return "return"
number_literal "0"
; ";"
} "}"
function_definition
primitive_type "int"
function_declarator (+48 nodes collapsed)
compound_statement
{ "{"
declaration
primitive_type "int"
identifier "ctr_idx"
, ","
init_declarator
identifier "sbiret"
= "="
number_literal "0"
; ";"
declaration
sized_type_specifier
long "long"
identifier "ret"
; ";"
declaration
primitive_type "bool"
identifier "is_fevent"
; ";"
declaration
sized_type_specifier
unsigned "unsigned"
long "long"
identifier "event_code"
; ";"
declaration
type_identifier "u32"
init_declarator
identifier "etype"
= "="
call_expression
identifier "kvm_pmu_get_perf_event_type"
argument_list
( "("
identifier "eidx"
) ")"
; ";"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmu"
init_declarator
pointer_declarator
* "*"
identifier "kvpmu"
= "="
call_expression
identifier "vcpu_to_pmu"
argument_list
( "("
identifier "vcpu"
) ")"
; ";"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmc"
init_declarator
pointer_declarator
* "*"
identifier "pmc"
= "="
null
NULL "NULL"
; ";"
declaration (+102 nodes collapsed)
if_statement (+31 nodes collapsed)
expression_statement
assignment_expression
identifier "event_code"
= "="
call_expression
identifier "get_event_code"
argument_list
( "("
identifier "eidx"
) ")"
; ";"
expression_statement
assignment_expression
identifier "is_fevent"
= "="
call_expression
identifier "kvm_pmu_is_fw_event"
argument_list
( "("
identifier "eidx"
) ")"
; ";"
if_statement (+25 nodes collapsed)
comment "/*\n\t * SKIP_MATCH flag indicates the caller is aware of the "...
if_statement (+109 nodes collapsed)
expression_statement
assignment_expression
identifier "pmc"
= "="
pointer_expression
& "&"
subscript_expression
field_expression
identifier "kvpmu"
-> "->"
field_identifier "pmc"
[ "["
identifier "ctr_idx"
] "]"
; ";"
expression_statement
assignment_expression
field_expression
identifier "pmc"
-> "->"
field_identifier "idx"
= "="
identifier "ctr_idx"
; ";"
if_statement (+79 nodes collapsed)
expression_statement
call_expression
identifier "set_bit"
argument_list
( "("
identifier "ctr_idx"
, ","
field_expression
identifier "kvpmu"
-> "->"
field_identifier "pmc_in_use"
) ")"
; ";"
expression_statement
assignment_expression
field_expression
identifier "pmc"
-> "->"
field_identifier "event_idx"
= "="
identifier "eidx"
; ";"
expression_statement
assignment_expression
field_expression
identifier "retdata"
-> "->"
field_identifier "out_val"
= "="
identifier "ctr_idx"
; ";"
labeled_statement
statement_identifier "out"
: ":"
expression_statement
assignment_expression
field_expression
identifier "retdata"
-> "->"
field_identifier "err_val"
= "="
identifier "sbiret"
; ";"
return_statement
return "return"
number_literal "0"
; ";"
} "}"
function_definition (+79 nodes collapsed)
function_definition (+79 nodes collapsed)
function_definition (+410 nodes collapsed)
function_definition (+176 nodes collapsed)
function_definition (+25 nodes collapsed)

After

translation_unit
comment "// SPDX-License-Identifier: GPL-2.0"
comment "/*\n * Copyright (c) 2023 Rivos Inc\n *\n * Authors:\n * Ati"...
preproc_function_def
#define "#define"
identifier "pr_fmt"
preproc_params
( "("
identifier "fmt"
) ")"
preproc_arg "\"riscv-kvm-pmu: \" fmt"
preproc_include
#include "#include"
system_lib_string "<linux/errno.h>"
preproc_include
#include "#include"
system_lib_string "<linux/err.h>"
preproc_include
#include "#include"
system_lib_string "<linux/kvm_host.h>"
preproc_include
#include "#include"
system_lib_string "<linux/nospec.h>"
preproc_include
#include "#include"
system_lib_string "<linux/perf/riscv_pmu.h>"
preproc_include
#include "#include"
system_lib_string "<asm/csr.h>"
preproc_include
#include "#include"
system_lib_string "<asm/kvm_vcpu_sbi.h>"
preproc_include
#include "#include"
system_lib_string "<asm/kvm_vcpu_pmu.h>"
preproc_include
#include "#include"
system_lib_string "<asm/sbi.h>"
preproc_include
#include "#include"
system_lib_string "<linux/bitops.h>"
preproc_function_def
#define "#define"
identifier "kvm_pmu_num_counters"
preproc_params
( "("
identifier "pmu"
) ")"
preproc_arg "((pmu)->num_hw_ctrs + (pmu)->num_fw_ctrs)"
preproc_function_def
#define "#define"
identifier "get_event_type"
preproc_params
( "("
identifier "x"
) ")"
preproc_arg "(((x) & SBI_PMU_EVENT_IDX_TYPE_MASK) >> 16)"
preproc_function_def
#define "#define"
identifier "get_event_code"
preproc_params
( "("
identifier "x"
) ")"
preproc_arg "((x) & SBI_PMU_EVENT_IDX_CODE_MASK)"
declaration (+97 nodes collapsed)
function_definition (+83 nodes collapsed)
function_definition (+104 nodes collapsed)
function_definition (+29 nodes collapsed)
function_definition (+63 nodes collapsed)
function_definition
storage_class_specifier
static "static"
type_identifier "u64"
function_declarator
identifier "kvm_pmu_get_perf_event_hw_config"
parameter_list
( "("
parameter_declaration
type_identifier "u32"
identifier "sbi_event_code"
) ")"
compound_statement
{ "{"
return_statement
return "return"
subscript_expression
identifier "hw_event_perf_map"
[ "["
call_expression
identifier "array_index_nospec"
argument_list
( "("
identifier "sbi_event_code"
, ","
identifier "SBI_PMU_HW_GENERAL_MAX"
) ")"
] "]"
; ";"
} "}"
function_definition (+125 nodes collapsed)
function_definition (+181 nodes collapsed)
function_definition (+92 nodes collapsed)
function_definition (+188 nodes collapsed)
function_definition (+81 nodes collapsed)
function_definition
storage_class_specifier
static "static"
primitive_type "int"
function_declarator (+26 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmu"
init_declarator
pointer_declarator
* "*"
identifier "kvpmu"
= "="
call_expression
identifier "vcpu_to_pmu"
argument_list
( "("
identifier "vcpu"
) ")"
; ";"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmc"
pointer_declarator
* "*"
identifier "pmc"
; ";"
declaration
primitive_type "int"
identifier "fevent_code"
; ";"
if_statement (+36 nodes collapsed)
if_statement (+43 nodes collapsed)
expression_statement
assignment_expression
identifier "cidx"
= "="
call_expression
identifier "array_index_nospec"
argument_list
( "("
identifier "cidx"
, ","
identifier "RISCV_KVM_MAX_COUNTERS"
) ")"
; ";"
expression_statement
assignment_expression
identifier "pmc"
= "="
pointer_expression
& "&"
subscript_expression
field_expression
identifier "kvpmu"
-> "->"
field_identifier "pmc"
[ "["
identifier "cidx"
] "]"
; ";"
if_statement (+21 nodes collapsed)
expression_statement
assignment_expression
identifier "fevent_code"
= "="
call_expression
identifier "get_event_code"
argument_list
( "("
field_expression
identifier "pmc"
-> "->"
field_identifier "event_idx"
) ")"
; ";"
expression_statement
assignment_expression
field_expression
identifier "pmc"
-> "->"
field_identifier "counter_val"
= "="
field_expression
subscript_expression
field_expression
identifier "kvpmu"
-> "->"
field_identifier "fw_event"
[ "["
identifier "fevent_code"
] "]"
. "."
field_identifier "value"
; ";"
expression_statement
assignment_expression
pointer_expression
* "*"
identifier "out_val"
= "="
binary_expression
field_expression
identifier "pmc"
-> "->"
field_identifier "counter_val"
>> ">>"
number_literal "32"
; ";"
return_statement
return "return"
number_literal "0"
; ";"
} "}"
function_definition
storage_class_specifier
static "static"
primitive_type "int"
function_declarator (+26 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmu"
init_declarator
pointer_declarator
* "*"
identifier "kvpmu"
= "="
call_expression
identifier "vcpu_to_pmu"
argument_list
( "("
identifier "vcpu"
) ")"
; ";"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmc"
pointer_declarator
* "*"
identifier "pmc"
; ";"
declaration
type_identifier "u64"
identifier "enabled"
, ","
identifier "running"
; ";"
declaration
primitive_type "int"
identifier "fevent_code"
; ";"
if_statement (+43 nodes collapsed)
expression_statement
assignment_expression
identifier "cidx"
= "="
call_expression
identifier "array_index_nospec"
argument_list
( "("
identifier "cidx"
, ","
identifier "RISCV_KVM_MAX_COUNTERS"
) ")"
; ";"
expression_statement
assignment_expression
identifier "pmc"
= "="
pointer_expression
& "&"
subscript_expression
field_expression
identifier "kvpmu"
-> "->"
field_identifier "pmc"
[ "["
identifier "cidx"
] "]"
; ";"
if_statement (+101 nodes collapsed)
expression_statement
assignment_expression
pointer_expression
* "*"
identifier "out_val"
= "="
field_expression
identifier "pmc"
-> "->"
field_identifier "counter_val"
; ";"
return_statement
return "return"
number_literal "0"
; ";"
} "}"
function_definition (+72 nodes collapsed)
function_definition (+225 nodes collapsed)
function_definition (+211 nodes collapsed)
function_definition (+103 nodes collapsed)
function_definition (+173 nodes collapsed)
function_definition (+65 nodes collapsed)
function_definition (+299 nodes collapsed)
function_definition (+428 nodes collapsed)
function_definition (+59 nodes collapsed)
function_definition
primitive_type "int"
function_declarator (+26 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmu"
init_declarator
pointer_declarator
* "*"
identifier "kvpmu"
= "="
call_expression
identifier "vcpu_to_pmu"
argument_list
( "("
identifier "vcpu"
) ")"
; ";"
if_statement (+31 nodes collapsed)
expression_statement
assignment_expression
identifier "cidx"
= "="
call_expression
identifier "array_index_nospec"
argument_list
( "("
identifier "cidx"
, ","
identifier "RISCV_KVM_MAX_COUNTERS"
) ")"
; ";"
expression_statement (+22 nodes collapsed)
return_statement
return "return"
number_literal "0"
; ";"
} "}"
function_definition
primitive_type "int"
function_declarator (+42 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmu"
init_declarator
pointer_declarator
* "*"
identifier "kvpmu"
= "="
call_expression
identifier "vcpu_to_pmu"
argument_list
( "("
identifier "vcpu"
) ")"
; ";"
declaration
primitive_type "int"
identifier "i"
, ","
identifier "pmc_index"
, ","
init_declarator
identifier "sbiret"
= "="
number_literal "0"
; ";"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmc"
pointer_declarator
* "*"
identifier "pmc"
; ";"
declaration
primitive_type "int"
identifier "fevent_code"
; ";"
declaration
primitive_type "bool"
init_declarator
identifier "snap_flag_set"
= "="
binary_expression
identifier "flags"
& "&"
identifier "SBI_PMU_START_FLAG_INIT_SNAPSHOT"
; ";"
if_statement (+31 nodes collapsed)
if_statement (+89 nodes collapsed)
comment "/* Start the counters that have been configured and requeste"...
expression_statement
call_expression
identifier "for_each_set_bit"
argument_list
( "("
identifier "i"
, ","
pointer_expression
& "&"
identifier "ctr_mask"
, ","
identifier "RISCV_MAX_COUNTERS"
) ")"
; ""
compound_statement
{ "{"
expression_statement
assignment_expression
identifier "pmc_index"
= "="
call_expression
identifier "array_index_nospec"
argument_list
( "("
binary_expression
identifier "i"
+ "+"
identifier "ctr_base"
, ","
identifier "RISCV_KVM_MAX_COUNTERS"
) ")"
; ";"
if_statement (+21 nodes collapsed)
comment "/* The guest started the counter again. Reset the overflow s"...
expression_statement
call_expression
identifier "clear_bit"
argument_list
( "("
identifier "pmc_index"
, ","
field_expression
identifier "kvpmu"
-> "->"
field_identifier "pmc_overflown"
) ")"
; ";"
expression_statement
assignment_expression
identifier "pmc"
= "="
pointer_expression
& "&"
subscript_expression
field_expression
identifier "kvpmu"
-> "->"
field_identifier "pmc"
[ "["
identifier "pmc_index"
] "]"
; ";"
if_statement (+52 nodes collapsed)
if_statement (+207 nodes collapsed)
} "}"
labeled_statement
statement_identifier "out"
: ":"
expression_statement
assignment_expression
field_expression
identifier "retdata"
-> "->"
field_identifier "err_val"
= "="
identifier "sbiret"
; ";"
return_statement
return "return"
number_literal "0"
; ";"
} "}"
function_definition
primitive_type "int"
function_declarator (+38 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmu"
init_declarator
pointer_declarator
* "*"
identifier "kvpmu"
= "="
call_expression
identifier "vcpu_to_pmu"
argument_list
( "("
identifier "vcpu"
) ")"
; ";"
declaration
primitive_type "int"
identifier "i"
, ","
identifier "pmc_index"
, ","
init_declarator
identifier "sbiret"
= "="
number_literal "0"
; ";"
declaration
type_identifier "u64"
identifier "enabled"
, ","
identifier "running"
; ";"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmc"
pointer_declarator
* "*"
identifier "pmc"
; ";"
declaration
primitive_type "int"
identifier "fevent_code"
; ";"
declaration
primitive_type "bool"
init_declarator
identifier "snap_flag_set"
= "="
binary_expression
identifier "flags"
& "&"
identifier "SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT"
; ";"
declaration
primitive_type "bool"
init_declarator
identifier "shmem_needs_update"
= "="
false "false"
; ";"
if_statement (+31 nodes collapsed)
if_statement (+28 nodes collapsed)
comment "/* Stop the counters that have been configured and requested"...
expression_statement
call_expression
identifier "for_each_set_bit"
argument_list
( "("
identifier "i"
, ","
pointer_expression
& "&"
identifier "ctr_mask"
, ","
identifier "RISCV_MAX_COUNTERS"
) ")"
; ""
compound_statement
{ "{"
expression_statement
assignment_expression
identifier "pmc_index"
= "="
call_expression
identifier "array_index_nospec"
argument_list
( "("
binary_expression
identifier "i"
+ "+"
identifier "ctr_base"
, ","
identifier "RISCV_KVM_MAX_COUNTERS"
) ")"
; ";"
if_statement (+21 nodes collapsed)
expression_statement
assignment_expression
identifier "pmc"
= "="
pointer_expression
& "&"
subscript_expression
field_expression
identifier "kvpmu"
-> "->"
field_identifier "pmc"
[ "["
identifier "pmc_index"
] "]"
; ";"
if_statement (+181 nodes collapsed)
if_statement (+143 nodes collapsed)
if_statement (+82 nodes collapsed)
} "}"
if_statement (+33 nodes collapsed)
labeled_statement
statement_identifier "out"
: ":"
expression_statement
assignment_expression
field_expression
identifier "retdata"
-> "->"
field_identifier "err_val"
= "="
identifier "sbiret"
; ";"
return_statement
return "return"
number_literal "0"
; ";"
} "}"
function_definition
primitive_type "int"
function_declarator (+48 nodes collapsed)
compound_statement
{ "{"
declaration
primitive_type "int"
identifier "ctr_idx"
, ","
init_declarator
identifier "sbiret"
= "="
number_literal "0"
; ";"
declaration
sized_type_specifier
long "long"
identifier "ret"
; ";"
declaration
primitive_type "bool"
identifier "is_fevent"
; ";"
declaration
sized_type_specifier
unsigned "unsigned"
long "long"
identifier "event_code"
; ";"
declaration
type_identifier "u32"
init_declarator
identifier "etype"
= "="
call_expression
identifier "kvm_pmu_get_perf_event_type"
argument_list
( "("
identifier "eidx"
) ")"
; ";"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmu"
init_declarator
pointer_declarator
* "*"
identifier "kvpmu"
= "="
call_expression
identifier "vcpu_to_pmu"
argument_list
( "("
identifier "vcpu"
) ")"
; ";"
declaration
struct_specifier
struct "struct"
type_identifier "kvm_pmc"
init_declarator
pointer_declarator
* "*"
identifier "pmc"
= "="
null
NULL "NULL"
; ";"
declaration (+102 nodes collapsed)
if_statement (+31 nodes collapsed)
expression_statement
assignment_expression
identifier "event_code"
= "="
call_expression
identifier "get_event_code"
argument_list
( "("
identifier "eidx"
) ")"
; ";"
expression_statement
assignment_expression
identifier "is_fevent"
= "="
call_expression
identifier "kvm_pmu_is_fw_event"
argument_list
( "("
identifier "eidx"
) ")"
; ";"
if_statement (+25 nodes collapsed)
comment "/*\n\t * SKIP_MATCH flag indicates the caller is aware of the "...
if_statement (+109 nodes collapsed)
expression_statement
assignment_expression
identifier "ctr_idx"
= "="
call_expression
identifier "array_index_nospec"
argument_list
( "("
identifier "ctr_idx"
, ","
identifier "RISCV_KVM_MAX_COUNTERS"
) ")"
; ";"
expression_statement
assignment_expression
identifier "pmc"
= "="
pointer_expression
& "&"
subscript_expression
field_expression
identifier "kvpmu"
-> "->"
field_identifier "pmc"
[ "["
identifier "ctr_idx"
] "]"
; ";"
expression_statement
assignment_expression
field_expression
identifier "pmc"
-> "->"
field_identifier "idx"
= "="
identifier "ctr_idx"
; ";"
if_statement (+79 nodes collapsed)
expression_statement
call_expression
identifier "set_bit"
argument_list
( "("
identifier "ctr_idx"
, ","
field_expression
identifier "kvpmu"
-> "->"
field_identifier "pmc_in_use"
) ")"
; ";"
expression_statement
assignment_expression
field_expression
identifier "pmc"
-> "->"
field_identifier "event_idx"
= "="
identifier "eidx"
; ";"
expression_statement
assignment_expression
field_expression
identifier "retdata"
-> "->"
field_identifier "out_val"
= "="
identifier "ctr_idx"
; ";"
labeled_statement
statement_identifier "out"
: ":"
expression_statement
assignment_expression
field_expression
identifier "retdata"
-> "->"
field_identifier "err_val"
= "="
identifier "sbiret"
; ";"
return_statement
return "return"
number_literal "0"
; ";"
} "}"
function_definition (+79 nodes collapsed)
function_definition (+79 nodes collapsed)
function_definition (+410 nodes collapsed)
function_definition (+176 nodes collapsed)
function_definition (+25 nodes collapsed)