All of lore.kernel.org
 help / color / mirror / Atom feed
* About using PEBS from the user space
@ 2015-05-03 22:05 Harald Servat
  2015-05-03 22:19 ` Vince Weaver
  0 siblings, 1 reply; 7+ messages in thread
From: Harald Servat @ 2015-05-03 22:05 UTC (permalink / raw)
  To: linux-perf-users

Dear list,

   I'd like to use the perf library to access PEBS so as to collect 
referenced memory addresses from the user space. I think I've 
successfully setup the perf structures (struct perf_event_attr) to 
configure the performance counters, but I don't see what should I do to 
access to the captured memory addresses. I've seen that within 
arch/x86/kernel/cpu/perf_event_intel_ds.c there are the routines 
alloc_pebs_buffer, alloc_ds_buffer which seems to allocate and setup the 
necessary buffers using kmalloc_node calls. Question is, how can 
replicate this from the user space? And how we should connect these 
buffers to the PEBS infrastructure using perf calls?

Thank you very much in advance.

WARNING / LEGAL TEXT: This message is intended only for the use of the
individual or entity to which it is addressed and may contain
information which is privileged, confidential, proprietary, or exempt
from disclosure under applicable law. If you are not the intended
recipient or the person responsible for delivering the message to the
intended recipient, you are strictly prohibited from disclosing,
distributing, copying, or in any way using this message. If you have
received this communication in error, please notify the sender and
destroy and delete any copies you may have received.

http://www.bsc.es/disclaimer

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: About using PEBS from the user space
  2015-05-03 22:05 About using PEBS from the user space Harald Servat
@ 2015-05-03 22:19 ` Vince Weaver
  2015-05-04  8:13   ` Harald Servat
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Vince Weaver @ 2015-05-03 22:19 UTC (permalink / raw)
  To: Harald Servat; +Cc: linux-perf-users

On Mon, 4 May 2015, Harald Servat wrote:

> Dear list,
> 
>   I'd like to use the perf library to access PEBS so as to collect referenced
> memory addresses from the user space. I think I've successfully setup the perf
> structures (struct perf_event_attr) to configure the performance counters, but
> I don't see what should I do to access to the captured memory addresses. I've
> seen that within arch/x86/kernel/cpu/perf_event_intel_ds.c there are the
> routines alloc_pebs_buffer, alloc_ds_buffer which seems to allocate and setup
> the necessary buffers using kmalloc_node calls. Question is, how can replicate
> this from the user space? And how we should connect these buffers to the PEBS
> infrastructure using perf calls?

You can try looking at the example code in my perf_event_tests code.
	https://github.com/deater/perf_event_tests

The stuff you are looking for is probably covered in the
	test/record_sample/samples_data_src
	test/record_sample/sample_weight
and especially the
	test/record_sample/sample_regs_intr
tests, although that last one requires a fairly recent kernel to work.

Vince

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: About using PEBS from the user space
  2015-05-03 22:19 ` Vince Weaver
@ 2015-05-04  8:13   ` Harald Servat
  2015-05-04 10:17   ` Harald Servat
  2015-06-25 16:00   ` Harald Servat
  2 siblings, 0 replies; 7+ messages in thread
From: Harald Servat @ 2015-05-04  8:13 UTC (permalink / raw)
  To: Vince Weaver; +Cc: linux-perf-users




On 04/05/15 00:19, Vince Weaver wrote:
> On Mon, 4 May 2015, Harald Servat wrote:
>
>> Dear list,
>>
>>    I'd like to use the perf library to access PEBS so as to collect referenced
>> memory addresses from the user space. I think I've successfully setup the perf
>> structures (struct perf_event_attr) to configure the performance counters, but
>> I don't see what should I do to access to the captured memory addresses. I've
>> seen that within arch/x86/kernel/cpu/perf_event_intel_ds.c there are the
>> routines alloc_pebs_buffer, alloc_ds_buffer which seems to allocate and setup
>> the necessary buffers using kmalloc_node calls. Question is, how can replicate
>> this from the user space? And how we should connect these buffers to the PEBS
>> infrastructure using perf calls?
>
> You can try looking at the example code in my perf_event_tests code.
> 	https://github.com/deater/perf_event_tests
>
> The stuff you are looking for is probably covered in the
> 	test/record_sample/samples_data_src
> 	test/record_sample/sample_weight
> and especially the
> 	test/record_sample/sample_regs_intr
> tests, although that last one requires a fairly recent kernel to work.
>
> Vince

   Thank you very much for these pointers Vince. I'll take a look at them!

Best regards.



WARNING / LEGAL TEXT: This message is intended only for the use of the
individual or entity to which it is addressed and may contain
information which is privileged, confidential, proprietary, or exempt
from disclosure under applicable law. If you are not the intended
recipient or the person responsible for delivering the message to the
intended recipient, you are strictly prohibited from disclosing,
distributing, copying, or in any way using this message. If you have
received this communication in error, please notify the sender and
destroy and delete any copies you may have received.

http://www.bsc.es/disclaimer

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: About using PEBS from the user space
  2015-05-03 22:19 ` Vince Weaver
  2015-05-04  8:13   ` Harald Servat
@ 2015-05-04 10:17   ` Harald Servat
  2015-06-25 16:00   ` Harald Servat
  2 siblings, 0 replies; 7+ messages in thread
From: Harald Servat @ 2015-05-04 10:17 UTC (permalink / raw)
  To: Vince Weaver; +Cc: linux-perf-users

[-- Attachment #1: Type: text/plain, Size: 3669 bytes --]

On 04/05/15 00:19, Vince Weaver wrote:
> On Mon, 4 May 2015, Harald Servat wrote:
>
>> Dear list,
>>
>>    I'd like to use the perf library to access PEBS so as to collect referenced
>> memory addresses from the user space. I think I've successfully setup the perf
>> structures (struct perf_event_attr) to configure the performance counters, but
>> I don't see what should I do to access to the captured memory addresses. I've
>> seen that within arch/x86/kernel/cpu/perf_event_intel_ds.c there are the
>> routines alloc_pebs_buffer, alloc_ds_buffer which seems to allocate and setup
>> the necessary buffers using kmalloc_node calls. Question is, how can replicate
>> this from the user space? And how we should connect these buffers to the PEBS
>> infrastructure using perf calls?
>
> You can try looking at the example code in my perf_event_tests code.
> 	https://github.com/deater/perf_event_tests
>
> The stuff you are looking for is probably covered in the
> 	test/record_sample/samples_data_src
> 	test/record_sample/sample_weight
> and especially the
> 	test/record_sample/sample_regs_intr
> tests, although that last one requires a fairly recent kernel to work.
>
> Vince

   Vince,

   that is really interesting work, thank you! However, for some reason 
the PEBS collected address is never shown (and maybe not captured) 
according to the following partial output

PERF_RECORD_SAMPLE [c001], MISC=16386 
(PERF_RECORD_MISC_USER,PERF_RECORD_MISC_EXACT_IP ), Size=32
	PERF_SAMPLE_IP, IP: 404510
	PERF_SAMPLE_WEIGHT, Weight: 30
	PERF_SAMPLE_DATA_SRC, Raw: 68100242
		Load Hit Line fill buffer No snoop Hit Level 1 TLB Level 2 TLB
PERF_RECORD_SAMPLE [c001], MISC=16386 
(PERF_RECORD_MISC_USER,PERF_RECORD_MISC_EXACT_IP ), Size=32
	PERF_SAMPLE_IP, IP: 404524
	PERF_SAMPLE_WEIGHT, Weight: 76
	PERF_SAMPLE_DATA_SRC, Raw: 68100442
		Load Hit L2 cache No snoop Hit Level 1 TLB Level 2 TLB
PERF_RECORD_SAMPLE [c001], MISC=16386 
(PERF_RECORD_MISC_USER,PERF_RECORD_MISC_EXACT_IP ), Size=32
	PERF_SAMPLE_IP, IP: 404524
	PERF_SAMPLE_WEIGHT, Weight: 77
	PERF_SAMPLE_DATA_SRC, Raw: 68100842
		Load Hit L3 cache No snoop Hit Level 1 TLB Level 2 TLB

   I've looked into your code in order to compare it with the perf tool 
and it looks like you support it in the code in the following lines of 
lib/parse_record.c, so it looks that sample_type is not tagged with 
PERF_SAMPLE_ADDR bit.

511             if (sample_type & PERF_SAMPLE_ADDR) {
512                 long long addr;
513                 memcpy(&addr,&data[offset],sizeof(long long));
514                 if (!quiet) printf("\tPERF_SAMPLE_ADDR, addr: 
%llx\n",addr);
515                 offset+=8;
516             }

   I tweaked a bit the perf dump application so that it prints the 
sample_type and it always shows c10f whereas your binary prints c001. If 
I simply go to one of the tests (say sample_data_src.c) and force 
pe.sample = 0xc10f then it works (printing additional data). So, would 
the following change make sense into your code to emit the sampled address?

Best regards.



WARNING / LEGAL TEXT: This message is intended only for the use of the
individual or entity to which it is addressed and may contain
information which is privileged, confidential, proprietary, or exempt
from disclosure under applicable law. If you are not the intended
recipient or the person responsible for delivering the message to the
intended recipient, you are strictly prohibited from disclosing,
distributing, copying, or in any way using this message. If you have
received this communication in error, please notify the sender and
destroy and delete any copies you may have received.

http://www.bsc.es/disclaimer

[-- Attachment #2: sample_data_src.c.patch --]
[-- Type: text/x-patch, Size: 531 bytes --]

diff --git a/tests/record_sample/sample_data_src.c b/tests/record_sample/sample_data_src.c
index 1c3d260..35c7e81 100644
--- a/tests/record_sample/sample_data_src.c
+++ b/tests/record_sample/sample_data_src.c
@@ -113,7 +113,7 @@ int main(int argc, char **argv) {
         pe.size=sizeof(struct perf_event_attr);
         pe.sample_period=SAMPLE_FREQUENCY;
         pe.sample_type=PERF_SAMPLE_IP | PERF_SAMPLE_WEIGHT |
-			PERF_SAMPLE_DATA_SRC;
+			PERF_SAMPLE_DATA_SRC | PERF_SAMPLE_ADDR ;
 
 	global_sample_type=pe.sample_type;
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: About using PEBS from the user space
  2015-05-03 22:19 ` Vince Weaver
  2015-05-04  8:13   ` Harald Servat
  2015-05-04 10:17   ` Harald Servat
@ 2015-06-25 16:00   ` Harald Servat
  2015-06-25 19:06     ` Manuel Selva
  2 siblings, 1 reply; 7+ messages in thread
From: Harald Servat @ 2015-06-25 16:00 UTC (permalink / raw)
  To: Vince Weaver; +Cc: linux-perf-users

On 04/05/15 00:19, Vince Weaver wrote:
> On Mon, 4 May 2015, Harald Servat wrote:
>
>> Dear list,
>>
>>    I'd like to use the perf library to access PEBS so as to collect referenced
>> memory addresses from the user space. I think I've successfully setup the perf
>> structures (struct perf_event_attr) to configure the performance counters, but
>> I don't see what should I do to access to the captured memory addresses. I've
>> seen that within arch/x86/kernel/cpu/perf_event_intel_ds.c there are the
>> routines alloc_pebs_buffer, alloc_ds_buffer which seems to allocate and setup
>> the necessary buffers using kmalloc_node calls. Question is, how can replicate
>> this from the user space? And how we should connect these buffers to the PEBS
>> infrastructure using perf calls?
>
> You can try looking at the example code in my perf_event_tests code.
> 	https://github.com/deater/perf_event_tests
>
> The stuff you are looking for is probably covered in the
> 	test/record_sample/samples_data_src
> 	test/record_sample/sample_weight
> and especially the
> 	test/record_sample/sample_regs_intr
> tests, although that last one requires a fairly recent kernel to work.
>
> Vince

Hello,

   is there a way to setup PEBS to collect information from loads that 
take at least X cycles to complete using MSR_PEBS_LD_LAT_THRESHOLD 
through this approach?

Thank you!

WARNING / LEGAL TEXT: This message is intended only for the use of the
individual or entity to which it is addressed and may contain
information which is privileged, confidential, proprietary, or exempt
from disclosure under applicable law. If you are not the intended
recipient or the person responsible for delivering the message to the
intended recipient, you are strictly prohibited from disclosing,
distributing, copying, or in any way using this message. If you have
received this communication in error, please notify the sender and
destroy and delete any copies you may have received.

http://www.bsc.es/disclaimer

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: About using PEBS from the user space
  2015-06-25 16:00   ` Harald Servat
@ 2015-06-25 19:06     ` Manuel Selva
  2015-06-26  8:13       ` Harald Servat
  0 siblings, 1 reply; 7+ messages in thread
From: Manuel Selva @ 2015-06-25 19:06 UTC (permalink / raw)
  To: Harald Servat, Vince Weaver; +Cc: linux-perf-users

Hello Harald,

Setting the  config1 field of the perf_event_attr field (as done by the 
perf mem record tool) to X will instruct the PMU to only sample loads 
with latency higher than X. Is it what you are looking for ?

----
Manu

On 06/25/2015 06:00 PM, Harald Servat wrote:
> On 04/05/15 00:19, Vince Weaver wrote:
>> On Mon, 4 May 2015, Harald Servat wrote:
>>
>>> Dear list,
>>>
>>>    I'd like to use the perf library to access PEBS so as to collect
>>> referenced
>>> memory addresses from the user space. I think I've successfully setup
>>> the perf
>>> structures (struct perf_event_attr) to configure the performance
>>> counters, but
>>> I don't see what should I do to access to the captured memory
>>> addresses. I've
>>> seen that within arch/x86/kernel/cpu/perf_event_intel_ds.c there are the
>>> routines alloc_pebs_buffer, alloc_ds_buffer which seems to allocate
>>> and setup
>>> the necessary buffers using kmalloc_node calls. Question is, how can
>>> replicate
>>> this from the user space? And how we should connect these buffers to
>>> the PEBS
>>> infrastructure using perf calls?
>>
>> You can try looking at the example code in my perf_event_tests code.
>>     https://github.com/deater/perf_event_tests
>>
>> The stuff you are looking for is probably covered in the
>>     test/record_sample/samples_data_src
>>     test/record_sample/sample_weight
>> and especially the
>>     test/record_sample/sample_regs_intr
>> tests, although that last one requires a fairly recent kernel to work.
>>
>> Vince
>
> Hello,
>
>    is there a way to setup PEBS to collect information from loads that
> take at least X cycles to complete using MSR_PEBS_LD_LAT_THRESHOLD
> through this approach?
>
> Thank you!
>
> WARNING / LEGAL TEXT: This message is intended only for the use of the
> individual or entity to which it is addressed and may contain
> information which is privileged, confidential, proprietary, or exempt
> from disclosure under applicable law. If you are not the intended
> recipient or the person responsible for delivering the message to the
> intended recipient, you are strictly prohibited from disclosing,
> distributing, copying, or in any way using this message. If you have
> received this communication in error, please notify the sender and
> destroy and delete any copies you may have received.
>
> http://www.bsc.es/disclaimer
> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-perf-users" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: About using PEBS from the user space
  2015-06-25 19:06     ` Manuel Selva
@ 2015-06-26  8:13       ` Harald Servat
  0 siblings, 0 replies; 7+ messages in thread
From: Harald Servat @ 2015-06-26  8:13 UTC (permalink / raw)
  To: Manuel Selva, Vince Weaver; +Cc: linux-perf-users


Ah! Great, thank you Manuel!!

On 25/06/15 21:06, Manuel Selva wrote:
> Hello Harald,
>
> Setting the  config1 field of the perf_event_attr field (as done by the
> perf mem record tool) to X will instruct the PMU to only sample loads
> with latency higher than X. Is it what you are looking for ?
>
> ----
> Manu
>
> On 06/25/2015 06:00 PM, Harald Servat wrote:
>> On 04/05/15 00:19, Vince Weaver wrote:
>>> On Mon, 4 May 2015, Harald Servat wrote:
>>>
>>>> Dear list,
>>>>
>>>>    I'd like to use the perf library to access PEBS so as to collect
>>>> referenced
>>>> memory addresses from the user space. I think I've successfully setup
>>>> the perf
>>>> structures (struct perf_event_attr) to configure the performance
>>>> counters, but
>>>> I don't see what should I do to access to the captured memory
>>>> addresses. I've
>>>> seen that within arch/x86/kernel/cpu/perf_event_intel_ds.c there are
>>>> the
>>>> routines alloc_pebs_buffer, alloc_ds_buffer which seems to allocate
>>>> and setup
>>>> the necessary buffers using kmalloc_node calls. Question is, how can
>>>> replicate
>>>> this from the user space? And how we should connect these buffers to
>>>> the PEBS
>>>> infrastructure using perf calls?
>>>
>>> You can try looking at the example code in my perf_event_tests code.
>>>     https://github.com/deater/perf_event_tests
>>>
>>> The stuff you are looking for is probably covered in the
>>>     test/record_sample/samples_data_src
>>>     test/record_sample/sample_weight
>>> and especially the
>>>     test/record_sample/sample_regs_intr
>>> tests, although that last one requires a fairly recent kernel to work.
>>>
>>> Vince
>>
>> Hello,
>>
>>    is there a way to setup PEBS to collect information from loads that
>> take at least X cycles to complete using MSR_PEBS_LD_LAT_THRESHOLD
>> through this approach?
>>
>> Thank you!
>>
>> WARNING / LEGAL TEXT: This message is intended only for the use of the
>> individual or entity to which it is addressed and may contain
>> information which is privileged, confidential, proprietary, or exempt
>> from disclosure under applicable law. If you are not the intended
>> recipient or the person responsible for delivering the message to the
>> intended recipient, you are strictly prohibited from disclosing,
>> distributing, copying, or in any way using this message. If you have
>> received this communication in error, please notify the sender and
>> destroy and delete any copies you may have received.
>>
>> http://www.bsc.es/disclaimer
>> --
>> To unsubscribe from this list: send the line "unsubscribe
>> linux-perf-users" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
>>


WARNING / LEGAL TEXT: This message is intended only for the use of the
individual or entity to which it is addressed and may contain
information which is privileged, confidential, proprietary, or exempt
from disclosure under applicable law. If you are not the intended
recipient or the person responsible for delivering the message to the
intended recipient, you are strictly prohibited from disclosing,
distributing, copying, or in any way using this message. If you have
received this communication in error, please notify the sender and
destroy and delete any copies you may have received.

http://www.bsc.es/disclaimer

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-06-26  8:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-03 22:05 About using PEBS from the user space Harald Servat
2015-05-03 22:19 ` Vince Weaver
2015-05-04  8:13   ` Harald Servat
2015-05-04 10:17   ` Harald Servat
2015-06-25 16:00   ` Harald Servat
2015-06-25 19:06     ` Manuel Selva
2015-06-26  8:13       ` Harald Servat

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.