* How to measure VM events using perf-event
@ 2015-04-10 3:46 Jueyuan Zhu
2015-04-10 15:39 ` Christopher Covington
0 siblings, 1 reply; 6+ messages in thread
From: Jueyuan Zhu @ 2015-04-10 3:46 UTC (permalink / raw)
To: linux-perf-users
Hello,
I am trying to use the perf-event to measure the events for one specified VM in KVM platform. Since each VM is just a process in the host OS, so I thought we could just set the process id of this VM in the perf-event_open API to count the events. The following is my code (based on the example from perf_event_open linux manual).
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/perf_event.h>
#include <asm/unistd.h>
int main(int argc, char **argv)
{
struct perf_event_attr pe;
long long count;
int fd;
int pid = VM_id; // the process id of the VM.
memset(&pe, 0, sizeof(struct perf_event_attr));
pe.size = sizeof(struct perf_event_attr);
pe.type = PERF_TYPE_HARDWARE;
pe.config = PERF_COUNT_HW_INSTRUCTIONS;
pe.disabled = 1;
pe.exclude_kernel = 0;
pe.exclude_hv = 0;
pe.exclude_host = 0;
pe.exclude_guest = 0;
fd = syscall(__NR_perf_event_open, &pe, pid, -1, -1, 0);
if (fd == -1) {
fprintf(stderr, "Error opening leader %llx\n", pe.config);
exit(EXIT_FAILURE);
}
ioctl(fd, PERF_EVENT_IOC_RESET, 0);
ioctl(fd, PERF_EVENT_IOC_ENABLE, 0);
sleep(1);
ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
read(fd, &count, sizeof(long long));
printf("# of instructions: %lld\n", count);
close(fd);
}
However, this program’s output keeps constant whenever this VM is idle, or running different benchmarks. So it seems the event counting is incorrect. Can anyone tell me how to set the flags or perf_event_attr to correctly count the VM events using perf_event_open?
Thank you very much in advance!!
Best regards,
Jueyuan--
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] 6+ messages in thread
* Re: How to measure VM events using perf-event
2015-04-10 3:46 How to measure VM events using perf-event Jueyuan Zhu
@ 2015-04-10 15:39 ` Christopher Covington
2015-04-10 16:17 ` Jueyuan Zhu
0 siblings, 1 reply; 6+ messages in thread
From: Christopher Covington @ 2015-04-10 15:39 UTC (permalink / raw)
To: Jueyuan Zhu, linux-perf-users
Hi Jueyuan,
On 04/09/2015 11:46 PM, Jueyuan Zhu wrote:
> Hello,
>
> I am trying to use the perf-event to measure the events for one specified
> VM in KVM platform. Since each VM is just a process in the host OS, so I thought
> we could just set the process id of this VM in the perf-event_open API to
> count the events. The following is my code (based on the example from
> perf_event_open linux manual).
> However, this program’s output keeps constant whenever this VM is idle, or
> running different benchmarks. So it seems the event counting is incorrect. Can
> anyone tell me how to set the flags or perf_event_attr to correctly count the
> VM events using perf_event_open?
You may want to check that the QEMU or kvmtool you're using correctly
virtualizes or emulates the PMU for your architecture. Information about this
might be in the documentation or release notes or if not you could try asking
on the QEMU or kvmtool mailing list tool.
Chris
--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to measure VM events using perf-event
2015-04-10 15:39 ` Christopher Covington
@ 2015-04-10 16:17 ` Jueyuan Zhu
2015-04-10 16:57 ` Christopher Covington
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Jueyuan Zhu @ 2015-04-10 16:17 UTC (permalink / raw)
To: Christopher Covington; +Cc: linux-perf-users
Hi Chris,
Thanks for your suggestions. Since I am using the perf_event_open in the host OS, not in the guest OS. So does it need the support of PMU virtualization? I used the perf command below to measure the VM, and it can give correct results. So I am wondering how to use perf_event_open to get the same results as the perf user command?
#perf stat -e instructions -p VM_id sleep 1
Thank you!
-Jueyuan
On Apr 10, 2015, at 11:39 AM, Christopher Covington <cov@codeaurora.org> wrote:
> Hi Jueyuan,
>
> On 04/09/2015 11:46 PM, Jueyuan Zhu wrote:
>> Hello,
>>
>> I am trying to use the perf-event to measure the events for one specified
>> VM in KVM platform. Since each VM is just a process in the host OS, so I thought
>> we could just set the process id of this VM in the perf-event_open API to
>> count the events. The following is my code (based on the example from
>> perf_event_open linux manual).
>
>> However, this program’s output keeps constant whenever this VM is idle, or
>> running different benchmarks. So it seems the event counting is incorrect. Can
>> anyone tell me how to set the flags or perf_event_attr to correctly count the
>> VM events using perf_event_open?
>
> You may want to check that the QEMU or kvmtool you're using correctly
> virtualizes or emulates the PMU for your architecture. Information about this
> might be in the documentation or release notes or if not you could try asking
> on the QEMU or kvmtool mailing list tool.
>
> Chris
>
> --
> Qualcomm Innovation Center, Inc.
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to measure VM events using perf-event
2015-04-10 16:17 ` Jueyuan Zhu
@ 2015-04-10 16:57 ` Christopher Covington
2015-04-11 2:45 ` Tianwei Zhang
2015-04-11 11:59 ` Arnaldo Carvalho de Melo
2 siblings, 0 replies; 6+ messages in thread
From: Christopher Covington @ 2015-04-10 16:57 UTC (permalink / raw)
To: Jueyuan Zhu; +Cc: linux-perf-users
Hi Jueyuan,
On 04/10/2015 12:17 PM, Jueyuan Zhu wrote:
> Hi Chris,
>
> Thanks for your suggestions. Since I am using the perf_event_open in the
> host OS, not in the guest OS. So does it need the support of PMU
> virtualization? I used the perf command below to measure the VM, and it can
> give correct results. So I am wondering how to use perf_event_open to get the
> same results as the perf user command?
>
> #perf stat -e instructions -p VM_id sleep 1
Sorry, I overlooked that. I like to set pinned and inherit, but nothing jumps
out to me as wrong. If you'd like to look at more examples of using
perf_event_open, the test suite has the largest collection I know of.
https://github.com/deater/perf_event_tests
Chris
> On Apr 10, 2015, at 11:39 AM, Christopher Covington <cov@codeaurora.org> wrote:
>
>> Hi Jueyuan,
>>
>> On 04/09/2015 11:46 PM, Jueyuan Zhu wrote:
>>> Hello,
>>>
>>> I am trying to use the perf-event to measure the events for one specified
>>> VM in KVM platform. Since each VM is just a process in the host OS, so I thought
>>> we could just set the process id of this VM in the perf-event_open API to
>>> count the events. The following is my code (based on the example from
>>> perf_event_open linux manual).
>>
>>> However, this program’s output keeps constant whenever this VM is idle, or
>>> running different benchmarks. So it seems the event counting is incorrect. Can
>>> anyone tell me how to set the flags or perf_event_attr to correctly count the
>>> VM events using perf_event_open?
>>
>> You may want to check that the QEMU or kvmtool you're using correctly
>> virtualizes or emulates the PMU for your architecture. Information about this
>> might be in the documentation or release notes or if not you could try asking
>> on the QEMU or kvmtool mailing list tool.
>>
>> Chris
>>
>> --
>> Qualcomm Innovation Center, Inc.
>> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
>> a Linux Foundation Collaborative Project
>
> --
> 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
>
--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to measure VM events using perf-event
2015-04-10 16:17 ` Jueyuan Zhu
2015-04-10 16:57 ` Christopher Covington
@ 2015-04-11 2:45 ` Tianwei Zhang
2015-04-11 11:59 ` Arnaldo Carvalho de Melo
2 siblings, 0 replies; 6+ messages in thread
From: Tianwei Zhang @ 2015-04-11 2:45 UTC (permalink / raw)
To: Jueyuan Zhu; +Cc: linux-perf-users
In the KVM-based machine, each VM is a process, with several threads running concurrently. You can use ps -eLf to display all the VM threads. When measuring the performance of the VM, you should also specify the thread ids in the perf_event_open function.
Tianwei
On Apr 10, 2015, at 12:17 PM, Jueyuan Zhu <jueyuan.zhu@gmail.com> wrote:
> Hi Chris,
>
> Thanks for your suggestions. Since I am using the perf_event_open in the host OS, not in the guest OS. So does it need the support of PMU virtualization? I used the perf command below to measure the VM, and it can give correct results. So I am wondering how to use perf_event_open to get the same results as the perf user command?
>
> #perf stat -e instructions -p VM_id sleep 1
>
> Thank you!
>
> -Jueyuan
>
> On Apr 10, 2015, at 11:39 AM, Christopher Covington <cov@codeaurora.org> wrote:
>
>> Hi Jueyuan,
>>
>> On 04/09/2015 11:46 PM, Jueyuan Zhu wrote:
>>> Hello,
>>>
>>> I am trying to use the perf-event to measure the events for one specified
>>> VM in KVM platform. Since each VM is just a process in the host OS, so I thought
>>> we could just set the process id of this VM in the perf-event_open API to
>>> count the events. The following is my code (based on the example from
>>> perf_event_open linux manual).
>>
>>> However, this program’s output keeps constant whenever this VM is idle, or
>>> running different benchmarks. So it seems the event counting is incorrect. Can
>>> anyone tell me how to set the flags or perf_event_attr to correctly count the
>>> VM events using perf_event_open?
>>
>> You may want to check that the QEMU or kvmtool you're using correctly
>> virtualizes or emulates the PMU for your architecture. Information about this
>> might be in the documentation or release notes or if not you could try asking
>> on the QEMU or kvmtool mailing list tool.
>>
>> Chris
>>
>> --
>> Qualcomm Innovation Center, Inc.
>> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
>> a Linux Foundation Collaborative Project
>
> --
> 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] 6+ messages in thread
* Re: How to measure VM events using perf-event
2015-04-10 16:17 ` Jueyuan Zhu
2015-04-10 16:57 ` Christopher Covington
2015-04-11 2:45 ` Tianwei Zhang
@ 2015-04-11 11:59 ` Arnaldo Carvalho de Melo
2 siblings, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-04-11 11:59 UTC (permalink / raw)
To: Jueyuan Zhu; +Cc: Christopher Covington, linux-perf-users
Em Fri, Apr 10, 2015 at 12:17:08PM -0400, Jueyuan Zhu escreveu:
> Hi Chris,
>
> Thanks for your suggestions. Since I am using the perf_event_open in the host OS, not in the guest OS. So does it need the support of PMU virtualization? I used the perf command below to measure the VM, and it can give correct results. So I am wondering how to use perf_event_open to get the same results as the perf user command?
>
> #perf stat -e instructions -p VM_id sleep 1
Try adding -vv to the above perf stat command, it will show you how it
is setting up perf_event_attr, as well as the other arguments to
sys_perf_event_open, for example:
[acme@zoo linux]$ perf stat -vv -e instructions usleep 1
------------------------------------------------------------
perf_event_attr:
size 112
config 1
read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING
disabled 1
inherit 1
enable_on_exec 1
exclude_guest 1
------------------------------------------------------------
sys_perf_event_open: pid 3530 cpu -1 group_fd -1 flags 0x8
instructions: 632294 767399 767399
Performance counter stats for 'usleep 1':
632.294 instructions
0,001521851 seconds time elapsed
[acme@zoo linux]$
- Arnaldo
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-04-11 11:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-10 3:46 How to measure VM events using perf-event Jueyuan Zhu
2015-04-10 15:39 ` Christopher Covington
2015-04-10 16:17 ` Jueyuan Zhu
2015-04-10 16:57 ` Christopher Covington
2015-04-11 2:45 ` Tianwei Zhang
2015-04-11 11:59 ` Arnaldo Carvalho de Melo
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.