perf: Add PERF_SAMPLE_PHYS_ADDR
Subsystems (2)
PATCH v2 1/8 perf: Add PERF_SAMPLE_PHYS_ADDR
From: Kan Liang <[email protected]>
For understanding how the workload maps to memory channels and hardware behavior, it's useful to collect address maps with physical addresses. This is not intended for detecting page sharing (which can be already done using the mmap inode), but for lower level hardware behavior studies.
Perf supports load latency/DLA which can only collect virtual addresses. This patch add a new sample type PERF_SAMPLE_PHYS_ADDR to expose the physical addresses.
For kernel direct mapping addresses, the patch uses virt_to_phys to convert the virtual addresses from DLA to physical address. For user virtual addresses, __get_user_pages_fast is used to walk the pages tables for user physical address.
This does not work for vmalloc addresses. Right now these are not resolved, but code to do that could be added.
For security, the physical address can only be exposed to root or privileged user.
---
Changes since V1:
- Order the put calls according to the order defined in the header file
arch/x86/kernel/cpu/perf_event.h | 2 +- arch/x86/kernel/cpu/perf_event_intel_ds.c | 23 +++++++++++++++++++++++ include/linux/perf_event.h | 3 +++ include/uapi/linux/perf_event.h | 4 +++- kernel/events/core.c | 11 +++++++++++ 5 files changed, 41 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event.h +1 -1
@@ -90,7 +90,7 @@ struct amd_nb { (PERF_SAMPLE_IP |PERF_SAMPLE_TID |PERF_SAMPLE_ADDR | \PERF_SAMPLE_ID |PERF_SAMPLE_CPU |PERF_SAMPLE_STREAM_ID | \PERF_SAMPLE_DATA_SRC |PERF_SAMPLE_IDENTIFIER | \ -PERF_SAMPLE_TRANSACTION ) +PERF_SAMPLE_TRANSACTION |PERF_SAMPLE_PHYS_ADDR )/* * A debug store configuration.
arch/x86/kernel/cpu/perf_event_intel_ds.c +23 -0
@@ -986,6 +986,7 @@ static void setup_pebs_sample_data(struct perf_event *event,u64 sample_type;int fll, fst, dsrc;int fl = event->hw.flags; +struct page *p =NULL ;if (pebs ==NULL )return ;
@@ -1071,6 +1072,28 @@ static void setup_pebs_sample_data(struct perf_event *event, x86_pmu.intel_cap.pebs_format >= 1) data->addr = pebs->dla; +if ((sample_type &PERF_SAMPLE_PHYS_ADDR ) && (data->addr !=0 )) { +if (data->addr >=TASK_SIZE ) { +/* If it's vmalloc()d memory, leave phys_addr as 0 */ +if (virt_addr_valid (data->addr) && + !(data->addr >=VMALLOC_START && data->addr <VMALLOC_END )) + data->phys_addr = (u64 )virt_to_phys ((void *)data->addr); + }else { +/* +* Walking the pages tables for user address. +* Interrupts are disabled, so it prevents any tear down +* of the page tables. +* Try IRQ-safe __get_user_pages_fast first. +* If failed, leave phys_addr as 0. +*/ +if ((current->mm !=NULL ) && + (__get_user_pages_fast (data->addr,1 ,0 , &p) ==1 )) + data->phys_addr =page_to_phys (p) + data->addr %PAGE_SIZE ; + +if (p) +put_page (p); + } + }if (x86_pmu.intel_cap.pebs_format >=2 ) {/* Only set the TSX weight when no memory weight. */ if ((sample_type &PERF_SAMPLE_WEIGHT ) && !fll)
include/linux/perf_event.h +3 -0
@@ -795,6 +795,8 @@ struct perf_sample_data {struct perf_regs regs_intr;u64 stack_user_size; + +u64 phys_addr; }____cacheline_aligned ;/* default value for data source */
@@ -815,6 +817,7 @@ static inline void perf_sample_data_init(struct perf_sample_data *data, data->weight =0 ; data->data_src.val =PERF_MEM_NA ; data->txn =0 ; + data->phys_addr =0 ; } extern void perf_output_sample(struct perf_output_handle *handle,
include/uapi/linux/perf_event.h +3 -1
@@ -139,8 +139,9 @@ enum perf_event_sample_format {PERF_SAMPLE_IDENTIFIER =1U <<16 ,PERF_SAMPLE_TRANSACTION =1U <<17 ,PERF_SAMPLE_REGS_INTR =1U <<18 , +PERF_SAMPLE_PHYS_ADDR =1U <<19 , - PERF_SAMPLE_MAX = 1U << 19, /* non-ABI */ + PERF_SAMPLE_MAX = 1U << 20, /* non-ABI */ };/*
@@ -767,6 +768,7 @@ enum perf_event_type {* { u64 transaction; } && PERF_SAMPLE_TRANSACTION * { u64 abi; # enum perf_sample_regs_abi * u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_INTR +* { u64 phys_addr;} && PERF_SAMPLE_PHYS_ADDR * }; */ PERF_RECORD_SAMPLE = 9,
kernel/events/core.c +11 -0
@@ -1334,6 +1334,9 @@ static void __perf_event_header_size(struct perf_event *event, u64 sample_type)if (sample_type &PERF_SAMPLE_TRANSACTION ) size +=sizeof (data->txn); +if (sample_type &PERF_SAMPLE_PHYS_ADDR ) + size +=sizeof (data->phys_addr); + event->header_size = size; }
@@ -5452,6 +5455,9 @@ void perf_output_sample(struct perf_output_handle *handle, } } +if (sample_type &PERF_SAMPLE_PHYS_ADDR ) +perf_output_put (handle, data->phys_addr); +if (!event->attr.watermark) {int wakeup_events = event->attr.wakeup_events;
@@ -8269,6 +8275,11 @@ SYSCALL_DEFINE5(perf_event_open,return -EINVAL ; } +/* Only privileged users can get kernel addresses */ +if ((attr.sample_type &PERF_SAMPLE_PHYS_ADDR ) && + !capable (CAP_SYS_ADMIN )) +return -EACCES ; +/* * In cgroup mode, the pid argument is used to pass the fd * opened to the cgroup directory in cgroupfs. The cpu argument
Signature · 1 line
1.8.3.1
PATCH v2 7/8 perf script: support physical addresses in script
From: Kan Liang <[email protected]>
perf script print out physical addresses by applying phys_addr.
---
Changes since V1:
- PHYS_ADDR already stored in perf.data. Remove the requirement for ADDR.
tools/perf/builtin-script.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +12 -1
@@ -58,6 +58,7 @@ enum perf_output_field {PERF_OUTPUT_IREGS =1U <<14 ,PERF_OUTPUT_BRSTACK =1U <<15 ,PERF_OUTPUT_BRSTACKSYM =1U <<16 , + PERF_OUTPUT_PHYS_ADDR = 1U << 17, }; struct output_option {
@@ -81,6 +82,7 @@ struct output_option { {.str = "iregs", .field = PERF_OUTPUT_IREGS}, {.str = "brstack", .field = PERF_OUTPUT_BRSTACK}, {.str = "brstacksym", .field = PERF_OUTPUT_BRSTACKSYM}, + {.str = "phys_addr", .field = PERF_OUTPUT_PHYS_ADDR}, };/* default set to maintain compatibility with current format */
@@ -290,6 +292,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel, PERF_OUTPUT_IREGS))return -EINVAL ; +if (PRINT_FIELD (PHYS_ADDR ) && +perf_evsel__do_check_stype (evsel,PERF_SAMPLE_PHYS_ADDR ,"PHYS_ADDR" , +PERF_OUTPUT_PHYS_ADDR , allow_user_set)) +return -EINVAL ; +return 0 ; }
@@ -653,6 +660,9 @@ static void process_event(struct perf_script *script __maybe_unused, union perf_if (PRINT_FIELD (ADDR ))print_sample_addr (event, sample, thread, attr); +if (PRINT_FIELD (PHYS_ADDR )) +printf ("%16" PRIx64, sample->phys_addr); +if (PRINT_FIELD (IP )) {if (!symbol_conf.use_callchain)printf (" " );
@@ -1893,7 +1903,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) "comma separated output fields prepend with 'type:'. " "Valid types: hw,sw,trace,raw. " "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," - "addr,symoff,period,iregs,brstack,brstacksym,flags", parse_output_fields), + "addr,symoff,period,iregs,brstack,brstacksym,flags,phys_addr", + parse_output_fields),OPT_BOOLEAN ('a' ,"all-cpus" , &system_wide,"system-wide collection from all CPUs" ), OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
Signature · 1 line
1.8.3.1
PATCH v2 4/8 perf mem: add option phys-data to record physical address
In reply to [email protected]From: Kan Liang <[email protected]>
Add option phys-data in perf mem to record physical address
--- tools/perf/builtin-mem.c | 5 +++++ 1 file changed, 5 insertions(+)
tools/perf/builtin-mem.c +5 -0
@@ -16,6 +16,7 @@ struct perf_mem {bool hide_unresolved;bool dump_raw;bool force; +bool phys_addr;int operation;const char *cpu_list;DECLARE_BITMAP (cpu_bitmap,MAX_NR_CPUS );
@@ -39,6 +40,9 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem) rec_argv[i++] ="-d" ; +if (mem->phys_addr) + rec_argv[i++] ="--phys-data" ; +if (mem->operation &MEM_OPERATION_LOAD ) { rec_argv[i++] ="-e" ; rec_argv[i++] ="cpu/mem-loads/pp" ;
@@ -290,6 +294,7 @@ int cmd_mem(int argc, const char **argv, const char *prefix __maybe_unused)"separator for columns, no spaces will be added" " between columns '.' is reserved."),OPT_BOOLEAN ('f' ,"force" , &mem.force,"don't complain, do it" ), +OPT_BOOLEAN ('p' ,"phys-data" , &mem.phys_addr,"Record sample physical addresses" ), OPT_END() };const char *const mem_subcommands[] = {"record" ,"report" ,NULL };
Signature · 1 line
1.8.3.1
PATCH v2 3/8 perf tools: add sort option phys_daddr
In reply to [email protected]From: Kan Liang <[email protected]>
Add a new sort option phys_daddr for --mem-mode sort. With this option applied, perf can sort and report by sample's physical address.
--- tools/perf/Documentation/perf-report.txt | 1 + tools/perf/util/hist.c | 3 +++ tools/perf/util/hist.h | 1 + tools/perf/util/machine.c | 7 ++++-- tools/perf/util/sort.c | 42 ++++++++++++++++++++++++++++++++ tools/perf/util/sort.h | 1 + tools/perf/util/symbol.h | 1 + 7 files changed, 54 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-report.txt +1 -0
@@ -163,6 +163,7 @@ OPTIONS - mem: type of memory access for the data at the time of sample - snoop: type of snoop (if any) for the data at the time of sample - dcacheline: the cacheline the data address is on at the time of sample + - phys_daddr: physical address of data being executed on at the time of sample And default sort keys are changed to local_weight, mem, sym, dso, symbol_daddr, dso_daddr, snoop, tlb, locked, see '--mem-mode'.
tools/perf/util/hist.c +3 -0
@@ -152,6 +152,9 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h) symlen = unresolved_col_width +4 +2 ;hists__set_unres_dso_col_len (hists,HISTC_MEM_DADDR_DSO ); } + +hists__new_col_len (hists,HISTC_MEM_PHYS_DADDR , unresolved_col_width +4 +2 ); + }else { symlen = unresolved_col_width +4 +2 ;hists__new_col_len (hists,HISTC_MEM_DADDR_SYMBOL , symlen);
tools/perf/util/hist.h +1 -0
@@ -44,6 +44,7 @@ enum hist_column {HISTC_GLOBAL_WEIGHT ,HISTC_MEM_DADDR_SYMBOL ,HISTC_MEM_DADDR_DSO , +HISTC_MEM_PHYS_DADDR ,HISTC_MEM_LOCKED ,HISTC_MEM_TLB , HISTC_MEM_LVL,
tools/perf/util/machine.c +5 -2
@@ -1560,10 +1560,12 @@ static void ip__resolve_ams(struct thread *thread, ams->al_addr = al.addr; ams->sym = al.sym; ams->map = al.map; + ams->phys_addr =0 ; }static void ip__resolve_data (struct thread *thread, -u8 m,struct addr_map_symbol *ams,u64 addr) +u8 m,struct addr_map_symbol *ams, +u64 addr,u64 phys_addr) {struct addr_location al;
@@ -1583,6 +1585,7 @@ static void ip__resolve_data(struct thread *thread, ams->al_addr = al.addr; ams->sym = al.sym; ams->map = al.map; + ams->phys_addr = phys_addr; } struct mem_info *sample__resolve_mem(struct perf_sample *sample,
@@ -1594,7 +1597,7 @@ struct mem_info *sample__resolve_mem(struct perf_sample *sample,return NULL ;ip__resolve_ams (al->thread, &mi->iaddr, sample->ip); -ip__resolve_data (al->thread, al->cpumode, &mi->daddr, sample->addr); +ip__resolve_data (al->thread, al->cpumode, &mi->daddr, sample->addr, sample->phys_addr); mi->data_src.val = sample->data_src;return mi;
tools/perf/util/sort.c +42 -0
60 lines not on this page · raw message
tools/perf/util/sort.h +1 -0
@@ -207,6 +207,7 @@ enum sort_type {SORT_MEM_SNOOP ,SORT_MEM_DCACHELINE ,SORT_MEM_IADDR_SYMBOL , + SORT_MEM_PHYS_DADDR, };/*
tools/perf/util/symbol.h +1 -0
@@ -170,6 +170,7 @@ struct addr_map_symbol {struct symbol *sym;u64 addr;u64 al_addr; +u64 phys_addr; };struct branch_info {
Signature · 1 line
1.8.3.1
PATCH v2 6/8 perf mem: dump physical addresses
In reply to [email protected]From: Kan Liang <[email protected]>
perf mem report should support dumping physical addresses by applying -p or --phys-data.
--- tools/perf/Documentation/perf-mem.txt | 4 ++ tools/perf/builtin-mem.c | 81 ++++++++++++++++++++++++----------- 2 files changed, 61 insertions(+), 24 deletions(-)
tools/perf/Documentation/perf-mem.txt +4 -0
@@ -48,6 +48,10 @@ OPTIONS option can be passed in record mode. It will be interpreted the same way as perf record. +-p:: +--phys-data:: + Record/Report/Dump sample physical addresses + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-report[1]
tools/perf/builtin-mem.c +57 -24
101 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 5/8 perf mem: report physical addresses
In reply to [email protected]From: Kan Liang <[email protected]>
perf mem report should support physical addresses by applying -p or --phys-data.
---
Changes since V1:
- Remove default_phys_mem_sort_order. Use a consistent format "--sort="
tools/perf/builtin-mem.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
tools/perf/builtin-mem.c +11 -4
@@ -176,9 +176,16 @@ static int report_events(int argc, const char **argv, struct perf_mem *mem)* there is no weight (cost) associated with stores, so don't print * the column */ -if (!(mem->operation &MEM_OPERATION_LOAD )) - rep_argv[i++] ="--sort=mem,sym,dso,symbol_daddr," -"dso_daddr,tlb,locked" ; +if (!(mem->operation &MEM_OPERATION_LOAD )) { +if (mem->phys_addr) + rep_argv[i++] ="--sort=mem,sym,dso,symbol_daddr," +"dso_daddr,tlb,locked,phys_daddr" ; +else + rep_argv[i++] ="--sort=mem,sym,dso,symbol_daddr," +"dso_daddr,tlb,locked" ; + }else if (mem->phys_addr) + rep_argv[i++] ="--sort=local_weight,mem,sym,dso,symbol_daddr," +"dso_daddr,snoop,tlb,locked,phys_daddr" ;for (j =1 ; j < argc; j++, i++) rep_argv[i] = argv[j];
@@ -294,7 +301,7 @@ int cmd_mem(int argc, const char **argv, const char *prefix __maybe_unused)"separator for columns, no spaces will be added" " between columns '.' is reserved."),OPT_BOOLEAN ('f' ,"force" , &mem.force,"don't complain, do it" ), -OPT_BOOLEAN ('p' ,"phys-data" , &mem.phys_addr,"Record sample physical addresses" ), +OPT_BOOLEAN ('p' ,"phys-data" , &mem.phys_addr,"Record/Report sample physical addresses" ), OPT_END() };const char *const mem_subcommands[] = {"record" ,"report" ,NULL };
Signature · 1 line
1.8.3.1
PATCH v2 8/8 perf test: add test case for PERF_SAMPLE_PHYS_ADDR
In reply to [email protected]From: Kan Liang <[email protected]>
Extend sample-parsing test cases to support new sample type PERF_SAMPLE_PHYS_ADDR.
--- tools/perf/tests/sample-parsing.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/tests/sample-parsing.c +4 -1
@@ -45,6 +45,9 @@ static bool samples_same(const struct perf_sample *s1,if (type &PERF_SAMPLE_ADDR )COMP (addr); +if (type &PERF_SAMPLE_PHYS_ADDR ) +COMP (phys_addr); +if (type &PERF_SAMPLE_ID )COMP (id);
@@ -303,7 +306,7 @@ int test__sample_parsing(int subtest __maybe_unused)* were added. Please actually update the test rather than just change * the condition below. */ -if (PERF_SAMPLE_MAX >PERF_SAMPLE_REGS_INTR <<1 ) { +if (PERF_SAMPLE_MAX >PERF_SAMPLE_PHYS_ADDR <<1 ) {pr_debug ("sample format has changed, some new PERF_SAMPLE_ bit was introduced - test needs updating\n" );return -1 ; }
Signature · 1 line
1.8.3.1
PATCH v2 2/8 perf tools: add option to record sample physical address
In reply to [email protected]From: Kan Liang <[email protected]>
Add new option --phys-data for perf record to record sample physical address. Once the option is applied, it implies that --data option is also applied to record sample virtual address.
---
Changes since V1:
- Display PHYS_ADDR in perf evlist if applicable
- Order the PHYS_ADDR according to the order defined in the header file
tools/perf/Documentation/perf-record.txt | 6 +++++- tools/perf/builtin-record.c | 10 +++++++++- tools/perf/perf.h | 1 + tools/perf/util/event.h | 1 + tools/perf/util/evsel.c | 19 ++++++++++++++++++- tools/perf/util/session.c | 3 +++ 6 files changed, 37 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-record.txt +5 -1
@@ -181,7 +181,11 @@ OPTIONS -d:: --data:: - Record the sample addresses. + Record the sample virtual addresses. + +--phys-data:: + Record the sample physical addresses which implies + the virtual address is also recorded. -T:: --timestamp::
tools/perf/builtin-record.c +9 -1
@@ -1082,7 +1082,8 @@ struct option __record_options[] = {OPT_BOOLEAN ('q' ,"quiet" , &quiet,"don't print any message" ),OPT_BOOLEAN ('s' ,"stat" , &record.opts.inherit_stat,"per thread counts" ), -OPT_BOOLEAN ('d' ,"data" , &record.opts.sample_address,"Record the sample addresses" ), +OPT_BOOLEAN ('d' ,"data" , &record.opts.sample_address,"Record the sample virtual addresses" ), +OPT_BOOLEAN (0 ,"phys-data" , &record.opts.sample_phys_addr,"Record the sample physical addresses" ),OPT_BOOLEAN_SET ('T' ,"timestamp" , &record.opts.sample_time, &record.opts.sample_time_set, "Record the sample timestamps"),
@@ -1223,6 +1224,13 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) goto out_symbol_exit; } +/* +* Record the sample physical addr which also implies +* the virtual addr is recorded. +*/ +if (rec->opts.sample_phys_addr) + rec->opts.sample_address = true; +if (rec->opts.target.tid && !rec->opts.no_inherit_set) rec->opts.no_inherit = true;
tools/perf/perf.h +1 -0
@@ -49,6 +49,7 @@ struct record_opts {bool no_samples;bool raw_samples;bool sample_address; +bool sample_phys_addr;bool sample_weight;bool sample_time;bool sample_time_set;
tools/perf/util/event.h +1 -0
@@ -190,6 +190,7 @@ struct perf_sample {u32 cpu;u32 raw_size;u64 data_src; +u64 phys_addr;u32 flags;u16 insn_len;void *raw_data;
tools/perf/util/evsel.c +18 -1
@@ -838,6 +838,9 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts)if (opts->sample_address)perf_evsel__set_sample_bit (evsel,DATA_SRC ); +if (opts->sample_phys_addr) +perf_evsel__set_sample_bit (evsel,PHYS_ADDR ); +if (opts->no_buffering) { attr->watermark =0 ; attr->wakeup_events =1 ;
@@ -1208,7 +1211,7 @@ static void __p_sample_type(char *buf, size_t size, u64 value)bit_name (PERIOD ),bit_name (STREAM_ID ),bit_name (RAW ),bit_name (BRANCH_STACK ),bit_name (REGS_USER ),bit_name (STACK_USER ),bit_name (IDENTIFIER ),bit_name (REGS_INTR ),bit_name (DATA_SRC ), -bit_name (WEIGHT ), +bit_name (WEIGHT ),bit_name (PHYS_ADDR ), { .name = NULL, } };#undef bit_name
@@ -1871,6 +1874,12 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, } } + data->phys_addr =0 ; +if (type &PERF_SAMPLE_PHYS_ADDR ) { + data->phys_addr = *array; + array++; + } +return 0 ; }
@@ -1976,6 +1985,9 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, } } +if (type &PERF_SAMPLE_PHYS_ADDR ) + result +=sizeof (u64); +return result; }
@@ -2165,6 +2177,11 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, } } +if (type &PERF_SAMPLE_PHYS_ADDR ) { + *array = sample->phys_addr; + array++; + } +return 0 ; }
tools/perf/util/session.c +3 -0
@@ -1122,6 +1122,9 @@ static void dump_sample(struct perf_evsel *evsel, union perf_event *event,if (sample_type &PERF_SAMPLE_DATA_SRC )printf (" . data_src: 0x%" PRIx64"\n" , sample->data_src); +if (sample_type &PERF_SAMPLE_PHYS_ADDR ) +printf (" .. phys_addr: 0x%" PRIx64"\n" , sample->phys_addr); +if (sample_type &PERF_SAMPLE_TRANSACTION )printf ("... transaction: %" PRIx64"\n" , sample->transaction);
Signature · 1 line
1.8.3.1
kbuild test robot
build botreproduce:
Hi Kan,
[auto build test WARNING on tip/perf/core]
[also build test WARNING on v4.4-rc8 next-20160107]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/kan-liang-intel-com/perf-Add-PERF_SAMPLE_PHYS_ADDR/20160108-045715 config: i386-tinyconfig (attached as .config) reproduce: # save the attached .config to linux build tree make ARCH=i386
All warnings (new ones prefixed by >>):
arch/x86/kernel/cpu/perf_event_intel_ds.c: In function 'setup_pebs_sample_data':
>> arch/x86/kernel/cpu/perf_event_intel_ds.c:1087:41: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
data->phys_addr = (u64)virt_to_phys((void *)data->addr);
^vim +1087 arch/x86/kernel/cpu/perf_event_intel_ds.c
1071 regs->ip = pebs->real_ip;
1072 regs->flags |= PERF_EFLAGS_EXACT;
1073 } else if (event->attr.precise_ip > 1 && intel_pmu_pebs_fixup_ip(regs))
1074 regs->flags |= PERF_EFLAGS_EXACT;
1075 else
1076 regs->flags &= ~PERF_EFLAGS_EXACT;
1077
1078 if ((sample_type & PERF_SAMPLE_ADDR) &&
1079 x86_pmu.intel_cap.pebs_format >= 1)
1080 data->addr = pebs->dla;
1081
1082 if ((sample_type & PERF_SAMPLE_PHYS_ADDR) && (data->addr != 0)) {
1083 if (data->addr >= TASK_SIZE) {
1084 /* If it's vmalloc()d memory, leave phys_addr as 0 */
1085 if (virt_addr_valid(data->addr) &&
1086 !(data->addr >= VMALLOC_START && data->addr < VMALLOC_END))
> 1087 data->phys_addr = (u64)virt_to_phys((void *)data->addr);
1088 } else {
1089 /*
1090 * Walking the pages tables for user address.
1091 * Interrupts are disabled, so it prevents any tear down
1092 * of the page tables.
1093 * Try IRQ-safe __get_user_pages_fast first.
1094 * If failed, leave phys_addr as 0.
1095 */
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botreproduce:
Hi Kan,
[auto build test ERROR on tip/perf/core]
[also build test ERROR on v4.4-rc8 next-20160107]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/kan-liang-intel-com/perf-Add-PERF_SAMPLE_PHYS_ADDR/20160108-045715 config: x86_64-randconfig-x006-01060743 (attached as .config) reproduce: # save the attached .config to linux build tree make ARCH=x86_64
All errors (new ones prefixed by >>):
arch/x86/kernel/cpu/perf_event_intel_ds.c: In function 'setup_pebs_sample_data':
>> arch/x86/kernel/cpu/perf_event_intel_ds.c:1087:28: error: implicit declaration of function 'virt_to_phys' [-Werror=implicit-function-declaration]
data->phys_addr = (u64)virt_to_phys((void *)data->addr);
^
>> arch/x86/kernel/cpu/perf_event_intel_ds.c:1098:23: error: implicit declaration of function 'page_to_phys' [-Werror=implicit-function-declaration]
data->phys_addr = page_to_phys(p) + data->addr % PAGE_SIZE;
^cc1: some warnings being treated as errors
vim +/virt_to_phys +1087 arch/x86/kernel/cpu/perf_event_intel_ds.c
1081
1082 if ((sample_type & PERF_SAMPLE_PHYS_ADDR) && (data->addr != 0)) {
1083 if (data->addr >= TASK_SIZE) {
1084 /* If it's vmalloc()d memory, leave phys_addr as 0 */
1085 if (virt_addr_valid(data->addr) &&
1086 !(data->addr >= VMALLOC_START && data->addr < VMALLOC_END))
> 1087 data->phys_addr = (u64)virt_to_phys((void *)data->addr);
1088 } else {
1089 /*
1090 * Walking the pages tables for user address.
1091 * Interrupts are disabled, so it prevents any tear down
1092 * of the page tables.
1093 * Try IRQ-safe __get_user_pages_fast first.
1094 * If failed, leave phys_addr as 0.
1095 */
1096 if ((current->mm != NULL) &&
1097 (__get_user_pages_fast(data->addr, 1, 0, &p) == 1))
> 1098 data->phys_addr = page_to_phys(p) + data->addr % PAGE_SIZE; 1099
1100 if (p)
1101 put_page(p);
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Peter Zijlstra
maintainerQuoted 7 lines · On Thu, Jan 07, 2016 at 08:30:33AM -0500, [email protected] wrote:
From: Kan Liang <[email protected]>
For understanding how the workload maps to memory channels and hardware behavior, it's useful to collect address maps with physical addresses. This is not intended for detecting page sharing (which can be already done using the mmap inode), but for lower level hardware behavior studies.
This patch set completely lacks any useful example for why we should entertain this.
kernel/events/core.c SYSCALL_DEFINE5(perf_event_open, · line 8282
Quoted 9 lines
kernel/events/core.c +5
-0@@ -8269,6 +8275,11 @@ SYSCALL_DEFINE5(perf_event_open,return -EINVAL ; } +/* Only privileged users can get kernel addresses */ +if ((attr.sample_type &PERF_SAMPLE_PHYS_ADDR ) && + !capable (CAP_SYS_ADMIN )) +return -EACCES ; +
should that not also include a perf_paranoid_kernel() test?