Commit fbefe9c2 authored by Kan Liang's avatar Kan Liang Committed by Arnaldo Carvalho de Melo

perf tools: Support arch specific PERF_SAMPLE_WEIGHT_STRUCT processing

For X86, the var2_w field of PERF_SAMPLE_WEIGHT_STRUCT stands for the
instruction latency. Current perf forces the var2_w to the data->ins_lat
in the generic code. It works well for now because X86 is the only
architecture that supports the PERF_SAMPLE_WEIGHT_STRUCT, but it may
bring problems once other architectures support the sample type.  For
example, the var2_w may be used to capture something else on PowerPC.

Create two architecture specific functions to parse and synthesize the
weight related samples. Move the X86 specific codes to the X86 version
functions. Other architectures can implement their own functions later
separately.
Signed-off-by: default avatarKan Liang <kan.liang@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lore.kernel.org/lkml/1612540912-6562-1-git-send-email-kan.liang@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent c840cbfe
...@@ -75,3 +75,28 @@ int perf_event__synthesize_extra_kmaps(struct perf_tool *tool, ...@@ -75,3 +75,28 @@ int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
} }
#endif #endif
void arch_perf_parse_sample_weight(struct perf_sample *data,
const __u64 *array, u64 type)
{
union perf_sample_weight weight;
weight.full = *array;
if (type & PERF_SAMPLE_WEIGHT)
data->weight = weight.full;
else {
data->weight = weight.var1_dw;
data->ins_lat = weight.var2_w;
}
}
void arch_perf_synthesize_sample_weight(const struct perf_sample *data,
__u64 *array, u64 type)
{
*array = data->weight;
if (type & PERF_SAMPLE_WEIGHT_STRUCT) {
*array &= 0xffffffff;
*array |= ((u64)data->ins_lat << 32);
}
}
...@@ -421,4 +421,7 @@ extern unsigned int proc_map_timeout; ...@@ -421,4 +421,7 @@ extern unsigned int proc_map_timeout;
#define PAGE_SIZE_NAME_LEN 32 #define PAGE_SIZE_NAME_LEN 32
char *get_page_size_name(u64 size, char *str); char *get_page_size_name(u64 size, char *str);
void arch_perf_parse_sample_weight(struct perf_sample *data, const __u64 *array, u64 type);
void arch_perf_synthesize_sample_weight(const struct perf_sample *data, __u64 *array, u64 type);
#endif /* __PERF_RECORD_H */ #endif /* __PERF_RECORD_H */
...@@ -2105,6 +2105,13 @@ perf_event__check_size(union perf_event *event, unsigned int sample_size) ...@@ -2105,6 +2105,13 @@ perf_event__check_size(union perf_event *event, unsigned int sample_size)
return 0; return 0;
} }
void __weak arch_perf_parse_sample_weight(struct perf_sample *data,
const __u64 *array,
u64 type __maybe_unused)
{
data->weight = *array;
}
int evsel__parse_sample(struct evsel *evsel, union perf_event *event, int evsel__parse_sample(struct evsel *evsel, union perf_event *event,
struct perf_sample *data) struct perf_sample *data)
{ {
...@@ -2346,16 +2353,8 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, ...@@ -2346,16 +2353,8 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event,
} }
if (type & PERF_SAMPLE_WEIGHT_TYPE) { if (type & PERF_SAMPLE_WEIGHT_TYPE) {
union perf_sample_weight weight;
OVERFLOW_CHECK_u64(array); OVERFLOW_CHECK_u64(array);
weight.full = *array; arch_perf_parse_sample_weight(data, array, type);
if (type & PERF_SAMPLE_WEIGHT)
data->weight = weight.full;
else {
data->weight = weight.var1_dw;
data->ins_lat = weight.var2_w;
}
array++; array++;
} }
......
...@@ -1506,6 +1506,12 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, ...@@ -1506,6 +1506,12 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
return result; return result;
} }
void __weak arch_perf_synthesize_sample_weight(const struct perf_sample *data,
__u64 *array, u64 type __maybe_unused)
{
*array = data->weight;
}
int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_format, int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_format,
const struct perf_sample *sample) const struct perf_sample *sample)
{ {
...@@ -1642,11 +1648,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_fo ...@@ -1642,11 +1648,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_fo
} }
if (type & PERF_SAMPLE_WEIGHT_TYPE) { if (type & PERF_SAMPLE_WEIGHT_TYPE) {
*array = sample->weight; arch_perf_synthesize_sample_weight(sample, array, type);
if (type & PERF_SAMPLE_WEIGHT_STRUCT) {
*array &= 0xffffffff;
*array |= ((u64)sample->ins_lat << 32);
}
array++; array++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment