Skip to contentSkip to conversation

Enhance perf to collect KVM guest os statistics from host side

PATCH In review Zhang, Yanmin 36 participants 377 messages Mar 16, 2010 – Apr 8, 2010 Page 2 of 2

Subsystems (5)
x86 KVM perf events KVM x86 +1 more subsystems
lore
Share & tools
lore
#212 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 48 lines · Ingo Molnar
Quoted 5 lines · Avi Kivity
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

- Easy default reference to guest instances, and a way for tools to reference them symbolically as well in the multi-guest case. Preferably something trustable and kernel-provided - not some indirect information like a PID file created by libvirt-manager or so.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Usually 'layering violation' is trotted out at such suggestions. [...]

That's weird, how can a feature request be a 'layering violation'?

The 'something trustable and kernel-provided'. The kernel knows nothing about guest names.

The kernel certainly knows about other resources such as task names or network interface names or tracepoint names. This is kernel design 101.

Quoted 5 lines
Quoted 5 lines

If something that users find straightforward and usable is a layering violation to you (such as easily being able to access their own files on the host as well ...) then i think you need to revisit the definition of that term instead of trying to fix the user.

Quoted 14 lines

Here is the explanation, you left it quoted:

Quoted 11 lines
Quoted 11 lines

[...] I don't like using the term, because sometimes the layers are incorrect and need to be violated. But it should be done explicitly, not as a shortcut for a minor feature (and profiling is a minor feature, most users will never use it, especially guest-from-host).

The fact is we have well defined layers today, kvm virtualizes the cpu and memory, qemu emulates devices for a single guest, libvirt manages guests. We break this sometimes but there has to be a good reason. So perf needs to talk to libvirt if it wants names. Could be done via linking, or can be done using a pluging libvirt drops into perf.

This is really just the much-discredited microkernel approach for keeping global enumeration data that should be kept by the kernel ...

Lets look at the ${HOME}/.qemu/qmp/ enumeration method suggested by Anthony. There's numerous ways that this can break:

- Those special files can get corrupted, mis-setup, get out of sync, or can be hard to discover.

Quoted 8 lines

- The ${HOME}/.qemu/qmp/ solution suggested by Anthony has a very obvious design flaw: it is per user. When i'm root i'd like to query _all_ current guest images, not just the ones started by root. A system might not even have a notion of '${HOME}'.

- Apps might start KVM vcpu instances without adhering to the

    ${HOME}/.qemu/qmp/ access method.

Not all KVM vcpus are running operating systems.

Transitive had a product that was using a KVM context to run their binary translator which allowed them full access to the host processes virtual address space range. In this case, there is no kernel and there are no devices.

That's what I mean by a guest being a userspace context. KVM simply provides a new CPU mode to userspace in the same way that vm8086 mode.

Regards,

Anthony Liguori

Quoted 13 lines

- There is no guarantee for the Qemu process to reply to a request - while the kernel can always guarantee an enumeration result. I dont want 'perf kvm' to hang or misbehave just because Qemu has hung.

Really, for such reasons user-space is pretty poor at doing system-wide enumeration and resource management. Microkernels lost for a reason.

You are committing several grave design mistakes here.

Thanks,

Ingo

#213 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 45 lines · Anthony Liguori
Quoted 44 lines · Ingo Molnar
Quoted 9 lines · Avi Kivity
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

- Easy default reference to guest instances, and a way for tools to reference them symbolically as well in the multi-guest case. Preferably something trustable and kernel-provided - not some indirect information like a PID file created by libvirt-manager or so.

Usually 'layering violation' is trotted out at such suggestions. [...]

That's weird, how can a feature request be a 'layering violation'?

The 'something trustable and kernel-provided'. The kernel knows nothing about guest names.

The kernel certainly knows about other resources such as task names or network interface names or tracepoint names. This is kernel design 101.

Quoted 4 lines
Quoted 4 lines

If something that users find straightforward and usable is a layering violation to you (such as easily being able to access their own files on the host as well ...) then i think you need to revisit the definition of that term instead of trying to fix the user.

Quoted 12 lines

Here is the explanation, you left it quoted:

Quoted 10 lines
Quoted 10 lines

[...] I don't like using the term, because sometimes the layers are incorrect and need to be violated. But it should be done explicitly, not as a shortcut for a minor feature (and profiling is a minor feature, most users will never use it, especially guest-from-host).

The fact is we have well defined layers today, kvm virtualizes the cpu and memory, qemu emulates devices for a single guest, libvirt manages guests. We break this sometimes but there has to be a good reason. So perf needs to talk to libvirt if it wants names. Could be done via linking, or can be done using a pluging libvirt drops into perf.

This is really just the much-discredited microkernel approach for keeping global enumeration data that should be kept by the kernel ...

Lets look at the ${HOME}/.qemu/qmp/ enumeration method suggested by Anthony. There's numerous ways that this can break:

- Those special files can get corrupted, mis-setup, get out of sync, or can be hard to discover.

- The ${HOME}/.qemu/qmp/ solution suggested by Anthony has a very obvious design flaw: it is per user. When i'm root i'd like to query _all_ current guest images, not just the ones started by root. A system might not even have a notion of '${HOME}'.

Quoted 4 lines
Quoted 2 lines

- Apps might start KVM vcpu instances without adhering to the ${HOME}/.qemu/qmp/ access method.

Not all KVM vcpus are running operating systems.

But we want to allow developers to instrument all of them ...

Quoted 4 lines

Transitive had a product that was using a KVM context to run their binary translator which allowed them full access to the host processes virtual address space range. In this case, there is no kernel and there are no devices.

And your point is that such vcpus should be excluded from profiling just because they fall outside the Qemu/libvirt umbrella?

That is a ridiculous position.

Ingo

#214 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 8 lines · Ingo Molnar
Quoted 5 lines

Transitive had a product that was using a KVM context to run their binary translator which allowed them full access to the host processes virtual address space range. In this case, there is no kernel and there are no devices.

And your point is that such vcpus should be excluded from profiling just because they fall outside the Qemu/libvirt umbrella?

You don't instrument it the way you'd instrument an operating system so no, you don't want it to show up in perf kvm top.

Regards,

Anthony Liguori

Quoted 2 lines

Ingo

#215 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 11 lines · Anthony Liguori
Quoted 7 lines · Ingo Molnar
Quoted 4 lines

Transitive had a product that was using a KVM context to run their binary translator which allowed them full access to the host processes virtual address space range. In this case, there is no kernel and there are no devices.

And your point is that such vcpus should be excluded from profiling just because they fall outside the Qemu/libvirt umbrella?

You don't instrument it the way you'd instrument an operating system so no, you don't want it to show up in perf kvm top.

Erm, why not? It's executing a virtualized CPU, so sure it makes sense to allow the profiling of it!

It might even not be the weird case you mentioned by some competing virtualization project to Qemu ...

So your argument is wrong on several technical levels, sorry.

Thanks,

Ingo

#216 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 10 lines · Ingo Molnar
Quoted 7 lines · Anthony Liguori
Quoted 5 lines · Ingo Molnar
Quoted 5 lines

Transitive had a product that was using a KVM context to run their binary translator which allowed them full access to the host processes virtual address space range. In this case, there is no kernel and there are no devices.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

And your point is that such vcpus should be excluded from profiling just because they fall outside the Qemu/libvirt umbrella?

You don't instrument it the way you'd instrument an operating system so no, you don't want it to show up in perf kvm top.

Erm, why not? It's executing a virtualized CPU, so sure it makes sense to allow the profiling of it!

It may not make sense to have symbol tables for it, for example it isn't generated from source code but from binary code for another architecture.

Of course, just showing addresses is fine, but you don't need qemu for that.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#217 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 6 lines · Ingo Molnar
Quoted 6 lines

Transitive had a product that was using a KVM context to run their binary translator which allowed them full access to the host processes virtual address space range. In this case, there is no kernel and there are no devices.

Quoted 6 lines

And your point is that such vcpus should be excluded from profiling just because they fall outside the Qemu/libvirt umbrella?

That is a ridiculous position.

Non-guest vcpus will not be able to provide Linux-style symbols.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#218 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 7 lines · Avi Kivity
Quoted 6 lines · Ingo Molnar
Quoted 5 lines

Transitive had a product that was using a KVM context to run their binary translator which allowed them full access to the host processes virtual address space range. In this case, there is no kernel and there are no devices.

Quoted 7 lines
Quoted 5 lines

And your point is that such vcpus should be excluded from profiling just because they fall outside the Qemu/libvirt umbrella?

That is a ridiculous position.

Non-guest vcpus will not be able to provide Linux-style symbols.

And why do you say that it makes no sense to profile them?

Also, why do you define 'guest vcpus' to be 'Qemu started guest vcpus'? If some other KVM using project (which you encouraged just a few mails ago) starts a vcpu we still want to be able to profile them.

Ingo

#219 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 11 lines · Ingo Molnar
Quoted 9 lines
Quoted 7 lines

And your point is that such vcpus should be excluded from profiling just because they fall outside the Qemu/libvirt umbrella?

That is a ridiculous position.

Non-guest vcpus will not be able to provide Linux-style symbols.

And why do you say that it makes no sense to profile them?

It makes sense to profile them, but you don't need to contact their userspace tool for that.

Quoted 5 lines

Also, why do you define 'guest vcpus' to be 'Qemu started guest vcpus'? If some other KVM using project (which you encouraged just a few mails ago) starts a vcpu we still want to be able to profile them.

Maybe it should provide a mechanism for libvirt to list it.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#220 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 14 lines · Ingo Molnar

This is really just the much-discredited microkernel approach for keeping global enumeration data that should be kept by the kernel ...

Lets look at the ${HOME}/.qemu/qmp/ enumeration method suggested by Anthony. There's numerous ways that this can break:

- Those special files can get corrupted, mis-setup, get out of sync, or can be hard to discover.

- The ${HOME}/.qemu/qmp/ solution suggested by Anthony has a very obvious design flaw: it is per user. When i'm root i'd like to query _all_ current guest images, not just the ones started by root. A system might not even have a notion of '${HOME}'.

Quoted 7 lines

- Apps might start KVM vcpu instances without adhering to the

    ${HOME}/.qemu/qmp/ access method.

- There is no guarantee for the Qemu process to reply to a request - while the kernel can always guarantee an enumeration result. I dont want 'perf kvm' to hang or misbehave just because Qemu has hung.

If your position basically boils down to, we can't trust userspace and we can always trust the kernel, I want to eliminate any userspace path, then I can't really help you out.

I believe we can come up with an infrastructure that satisfies your actual requirements within qemu but if you're also insisting upon the above implementation detail then there's nothing I can do.

Regards,

Anthony Liguori

#221 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 18 lines · Anthony Liguori
Quoted 17 lines · Ingo Molnar

This is really just the much-discredited microkernel approach for keeping global enumeration data that should be kept by the kernel ...

Lets look at the ${HOME}/.qemu/qmp/ enumeration method suggested by Anthony. There's numerous ways that this can break:

- Those special files can get corrupted, mis-setup, get out of sync, or can be hard to discover.

- The ${HOME}/.qemu/qmp/ solution suggested by Anthony has a very obvious design flaw: it is per user. When i'm root i'd like to query _all_ current guest images, not just the ones started by root. A system might not even have a notion of '${HOME}'.

- Apps might start KVM vcpu instances without adhering to the ${HOME}/.qemu/qmp/ access method.

Quoted 7 lines
Quoted 3 lines

- There is no guarantee for the Qemu process to reply to a request - while the kernel can always guarantee an enumeration result. I dont want 'perf kvm' to hang or misbehave just because Qemu has hung.

If your position basically boils down to, we can't trust userspace and we can always trust the kernel, I want to eliminate any userspace path, then I can't really help you out.

Why would you want to 'help me out'? I can tell a good solution from a bad one just fine.

You should instead read the long list of disadvantages above, invert them and list then as advantages for the kernel-based vcpu enumeration solution, apply common sense and go admit to yourself that indeed in this situation a kernel provided enumeration of vcpu contexts is the most robust solution.

It's really as simple as that :-)

Thanks,

Ingo

#222 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 8 lines · Ingo Molnar
Quoted 5 lines

If your position basically boils down to, we can't trust userspace and we can always trust the kernel, I want to eliminate any userspace path, then I can't really help you out.

Why would you want to 'help me out'? I can tell a good solution from a bad one just fine.

You are basically making a kernel implementation a requirement, instead of something that follows from the requirement.

Quoted 5 lines

You should instead read the long list of disadvantages above, invert them and list then as advantages for the kernel-based vcpu enumeration solution, apply common sense and go admit to yourself that indeed in this situation a kernel provided enumeration of vcpu contexts is the most robust solution.

Having qemu enumerate guests one way or another is not a good idea IMO since it is focused on one guest and doesn't have a system-wide entity. A userspace system-wide entity will work just as well as kernel implementation, without its disadvantages.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#223 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 11 lines · Avi Kivity
Quoted 7 lines · Ingo Molnar
Quoted 4 lines

If your position basically boils down to, we can't trust userspace and we can always trust the kernel, I want to eliminate any userspace path, then I can't really help you out.

Why would you want to 'help me out'? I can tell a good solution from a bad one just fine.

You are basically making a kernel implementation a requirement, instead of something that follows from the requirement.

No, i'm not.

Quoted 10 lines
Quoted 5 lines

You should instead read the long list of disadvantages above, invert them and list then as advantages for the kernel-based vcpu enumeration solution, apply common sense and go admit to yourself that indeed in this situation a kernel provided enumeration of vcpu contexts is the most robust solution.

Having qemu enumerate guests one way or another is not a good idea IMO since it is focused on one guest and doesn't have a system-wide entity. A userspace system-wide entity will work just as well as kernel implementation, without its disadvantages.

A system-wide user-space entity only solves one problem out of the 4 i listed, still leaving the other 3:

- Those special files can get corrupted, mis-setup, get out of sync, or can be hard to discover.

- Apps might start KVM vcpu instances without adhering to the system-wide access method.

- There is no guarantee for the system-wide process to reply to a request - while the kernel can always guarantee an enumeration result. I dont want 'perf kvm' to hang or misbehave just because the system-wide entity has hung.

Really, i think i have to give up and not try to convince you guys about this anymore - i dont think you are arguing constructively anymore and i dont want yet another pointless flamewar about this.

Please consider 'perf kvm' scrapped indefinitely, due to lack of robust KVM instrumentation features: due to lack of robust+universal vcpu/guest enumeration and due to lack of robust+universal symbol access on the KVM side. It was a really promising feature IMO and i invested two days of arguments into it trying to find a workable solution, but it was not to be.

Thanks,

Ingo

#224 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 12 lines · Ingo Molnar
Quoted 7 lines
Quoted 7 lines

You should instead read the long list of disadvantages above, invert them and list then as advantages for the kernel-based vcpu enumeration solution, apply common sense and go admit to yourself that indeed in this situation a kernel provided enumeration of vcpu contexts is the most robust solution.

Quoted 5 lines

Having qemu enumerate guests one way or another is not a good idea IMO since it is focused on one guest and doesn't have a system-wide entity. A userspace system-wide entity will work just as well as kernel implementation, without its disadvantages.

Quoted 6 lines

A system-wide user-space entity only solves one problem out of the 4 i listed, still leaving the other 3:

- Those special files can get corrupted, mis-setup, get out of sync, or can be hard to discover.

That's a hard requirement anyway. If it happens, we get massive data loss. Way more troubling than 'perf kvm top' doesn't work. So consider it fulfilled.

Quoted 3 lines

- Apps might start KVM vcpu instances without adhering to the system-wide access method.

Then you don't get their symbol tables. That happens anyway if the symbol server is not installed, not running, handing out fake data. So we have to deal with that anyway.

Quoted 5 lines

- There is no guarantee for the system-wide process to reply to a request - while the kernel can always guarantee an enumeration result. I dont want 'perf kvm' to hang or misbehave just because the system-wide entity has hung.

When you press a key there is no guarantee no component along the way will time out.

Quoted 10 lines

Really, i think i have to give up and not try to convince you guys about this anymore - i dont think you are arguing constructively anymore and i dont want yet another pointless flamewar about this.

Please consider 'perf kvm' scrapped indefinitely, due to lack of robust KVM instrumentation features: due to lack of robust+universal vcpu/guest enumeration and due to lack of robust+universal symbol access on the KVM side. It was a really promising feature IMO and i invested two days of arguments into it trying to find a workable solution, but it was not to be.

I am not going to push libvirt or a subset thereof into the kernel for 'perf kvm'.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#225 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 8 lines · Avi Kivity
Quoted 6 lines · Ingo Molnar
Quoted 4 lines

If your position basically boils down to, we can't trust userspace and we can always trust the kernel, I want to eliminate any userspace path, then I can't really help you out.

Why would you want to 'help me out'? I can tell a good solution from a bad one just fine.

Quoted 8 lines

You are basically making a kernel implementation a requirement, instead of something that follows from the requirement.

Quoted 4 lines

You should instead read the long list of disadvantages above, invert them and list then as advantages for the kernel-based vcpu enumeration solution, apply common sense and go admit to yourself that indeed in this situation a kernel provided enumeration of vcpu contexts is the most robust solution.

Having qemu enumerate guests one way or another is not a good idea IMO since it is focused on one guest and doesn't have a system-wide entity.

There always needs to be a system wide entity. There are two ways to enumerate instances from that system wide entity. You can centralize the creation of instances and there by maintain an list of current instances. You can also allow instances to be created in a decentralized manner and provide a standard mechanism for instances to register themselves with the system wide entity.

IOW, it's the difference between asking libvirtd to exec(qemu) vs allowing a user to exec(qemu) and having qemu connect to a well known unix domain socket for libvirt to tell libvirtd that it exists.

The later approach has a number of advantages. libvirt already supports both models. The former is the '/system' uri and the later is the '/session' uri.

What I'm proposing, is to use the host file system as the system wide entity instead of libvirtd. libvirtd can monitor the host file system to participate in these activities but ultimately, moving this functionality out of libvirtd means that it becomes the standard mechanism for all qemu instances regardless of how they're launched.

Regards,

Anthony Liguori

Quoted 3 lines

A userspace system-wide entity will work just as well as kernel
implementation, without its disadvantages.

#226 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 10 lines · Anthony Liguori
Quoted 1 line

Having qemu enumerate guests one way or another is not a good idea IMO since it is focused on one guest and doesn't have a system-wide entity.

There always needs to be a system wide entity. There are two ways to enumerate instances from that system wide entity. You can centralize the creation of instances and there by maintain an list of current instances. You can also allow instances to be created in a decentralized manner and provide a standard mechanism for instances to register themselves with the system wide entity.

IOW, it's the difference between asking libvirtd to exec(qemu) vs allowing a user to exec(qemu) and having qemu connect to a well known unix domain socket for libvirt to tell libvirtd that it exists.

The later approach has a number of advantages. libvirt already supports both models. The former is the '/system' uri and the later is the '/session' uri.

What I'm proposing, is to use the host file system as the system wide entity instead of libvirtd. libvirtd can monitor the host file system to participate in these activities but ultimately, moving this functionality out of libvirtd means that it becomes the standard mechanism for all qemu instances regardless of how they're launched.

I don't like dropping sockets into the host filesystem, especially as they won't be cleaned up on abnormal exit. I also think this breaks our 'mechanism, not policy' policy. Someone may want to do something weird with qemu that doesn't work well with this.

We could allow starting monitors from the global configuration file, so a distribution can do this if it wants, but I don't think we should do this ourselves by default.

Signature · 1 line
error compiling committee.c: too many arguments to function
#227 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 6 lines · Avi Kivity
Quoted 5 lines · Anthony Liguori
Quoted 1 line

Having qemu enumerate guests one way or another is not a good idea IMO since it is focused on one guest and doesn't have a system-wide entity.

There always needs to be a system wide entity. There are two ways to enumerate instances from that system wide entity. You can centralize the creation of instances and there by maintain an list of current instances. You can also allow instances to be created in a decentralized manner and provide a standard mechanism for instances to register themselves with the system wide entity.

Quoted 7 lines
Quoted 5 lines

IOW, it's the difference between asking libvirtd to exec(qemu) vs allowing a user to exec(qemu) and having qemu connect to a well known unix domain socket for libvirt to tell libvirtd that it exists.

The later approach has a number of advantages. libvirt already supports both models. The former is the '/system' uri and the later is the '/session' uri.

What I'm proposing, is to use the host file system as the system wide entity instead of libvirtd. libvirtd can monitor the host file system to participate in these activities but ultimately, moving this functionality out of libvirtd means that it becomes the standard mechanism for all qemu instances regardless of how they're launched.

I don't like dropping sockets into the host filesystem, especially as they won't be cleaned up on abnormal exit. I also think this breaks our 'mechanism, not policy' policy. Someone may want to do something weird with qemu that doesn't work well with this.

The approach I've taken (which I accidentally committed and reverted) was to set this up as the default qmp device much like we have a default monitor device. A user is capable of overriding this by manually specifying a qmp device or by disabling defaults.

Quoted 1 line

We could allow starting monitors from the global configuration file, so a distribution can do this if it wants, but I don't think we should do this ourselves by default.

I've looked at making default devices globally configurable. We'll get there but I think that's orthogonal to setting up a useful default qmp device.

Regards,

Anthony Liguori

#228 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Anthony Liguori

Am 22.03.2010 23:06, schrieb Anthony Liguori:

Quoted 11 lines · Avi Kivity
Quoted 2 lines

Having qemu enumerate guests one way or another is not a good idea IMO since it is focused on one guest and doesn't have a system-wide entity.

There always needs to be a system wide entity. There are two ways to enumerate instances from that system wide entity. You can centralize the creation of instances and there by maintain an list of current instances. You can also allow instances to be created in a decentralized manner and provide a standard mechanism for instances to register themselves with the system wide entity.

Quoted 3 lines

IOW, it's the difference between asking libvirtd to exec(qemu) vs allowing a user to exec(qemu) and having qemu connect to a well known unix domain socket for libvirt to tell libvirtd that it exists.

I think the latter is exactly what I would want for myself. I do see the advantages of having a central instance, but I really don't want to bother with libvirt configuration files or even GUIs just to get an ad-hoc VM up when I can simply run "qemu -hda hd.img -m 1024". Let alone that I usually want to have full control over qemu, including monitor access and small details available as command line options.

I know that I'm not the average user with these requirements, but still I am one user and do have these requirements. If I could just install libvirt, continue using qemu as I always did and libvirt picked my VMs up for things like global enumeration, that would be more or less the optimal thing for me.

Kevin

#229 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 25 lines · Kevin Wolf

Am 22.03.2010 23:06, schrieb Anthony Liguori:

Quoted 12 lines · Avi Kivity
Quoted 4 lines

Having qemu enumerate guests one way or another is not a good idea IMO since it is focused on one guest and doesn't have a system-wide entity.

There always needs to be a system wide entity. There are two ways to enumerate instances from that system wide entity. You can centralize the creation of instances and there by maintain an list of current instances. You can also allow instances to be created in a decentralized manner and provide a standard mechanism for instances to register themselves with the system wide entity.

Quoted 4 lines

IOW, it's the difference between asking libvirtd to exec(qemu) vs allowing a user to exec(qemu) and having qemu connect to a well known unix domain socket for libvirt to tell libvirtd that it exists.

I think the latter is exactly what I would want for myself. I do see the advantages of having a central instance, but I really don't want to bother with libvirt configuration files or even GUIs just to get an ad-hoc VM up when I can simply run "qemu -hda hd.img -m 1024". Let alone that I usually want to have full control over qemu, including monitor access and small details available as command line options.

Quoted 6 lines

I know that I'm not the average user with these requirements, but still I am one user and do have these requirements. If I could just install libvirt, continue using qemu as I always did and libvirt picked my VMs up for things like global enumeration, that would be more or less the optimal thing for me.

+1
And it would also make it more likely that users like us would convert to libvirt in the long run, by providing an easy and integrated transition path.
I've had another look at libvirt, and one of the things that is holding me back is the cost of moving existing scripts to libvirt. If it could just pick up what I have (at least in part), then I don't have to.

Antoine

Quoted 6 lines

Kevin
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#230 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Anthony Liguori
Quoted 6 lines · Anthony Liguori

There always needs to be a system wide entity. There are two ways to enumerate instances from that system wide entity. You can centralize the creation of instances and there by maintain an list of current instances. You can also allow instances to be created in a decentralized manner and provide a standard mechanism for instances to register themselves with the system wide entity.

And this system wide entity is the kvm module. It creates instances of 'struct kvm' and destroys them. I see no problem if we just attach a name to every instance with a good default value like kvm0, kvm1 ... or guest0, guest1 ... User-space can override the name if it wants. The kvm module takes care about the names being unique.
This is very much the same as network card numbering is implemented in the kernel.
Forcing perf to talk to qemu or even libvirt produces to much overhead imho. Instrumentation only produces useful results with low overhead.

Joerg

#231 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 9 lines · Joerg Roedel
Quoted 7 lines · Anthony Liguori

There always needs to be a system wide entity. There are two ways to enumerate instances from that system wide entity. You can centralize the creation of instances and there by maintain an list of current instances. You can also allow instances to be created in a decentralized manner and provide a standard mechanism for instances to register themselves with the system wide entity.

Quoted 6 lines

And this system wide entity is the kvm module. It creates instances of 'struct kvm' and destroys them. I see no problem if we just attach a name to every instance with a good default value like kvm0, kvm1 ... or guest0, guest1 ... User-space can override the name if it wants. The kvm module takes care about the names being unique.

So, two users can't have a guest named MyGuest each? What about namespace support? There's a lot of work in virtualizing all kernel namespaces, you're adding to that. What about notifications when guests are added or removed?

Quoted 6 lines

This is very much the same as network card numbering is implemented in the kernel.
Forcing perf to talk to qemu or even libvirt produces to much overhead imho. Instrumentation only produces useful results with low overhead.

It's a setup cost only.

Signature · 1 line
error compiling committee.c: too many arguments to function
#232 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 9 lines · Avi Kivity
Quoted 6 lines · Joerg Roedel

And this system wide entity is the kvm module. It creates instances of 'struct kvm' and destroys them. I see no problem if we just attach a name to every instance with a good default value like kvm0, kvm1 ... or guest0, guest1 ... User-space can override the name if it wants. The kvm module takes care about the names being unique.

Quoted 3 lines

So, two users can't have a guest named MyGuest each? What about namespace support? There's a lot of work in virtualizing all kernel namespaces, you're adding to that.

This enumeration is a very small and non-intrusive feature. Making it aware of namespaces is easy too.

Quoted 1 line

What about notifications when guests are added or removed?

Who would be the consumer of such notifications? A 'perf kvm list' can live without I guess. If we need them later we can still add them.

Quoted 7 lines
Quoted 5 lines

This is very much the same as network card numbering is implemented in the kernel.
Forcing perf to talk to qemu or even libvirt produces to much overhead imho. Instrumentation only produces useful results with low overhead.

It's a setup cost only.

My statement was not limited to enumeration, I should have been more clear about that. The guest filesystem access-channel is another affected part. The 'perf kvm top' command will access the guest filesystem regularly and going over qemu would be more overhead here. Providing this in the KVM module directly also has the benefit that it would work out-of-the-box with different userspaces too. Or do we want to limit 'perf kvm' to the libvirt-qemu-kvm software stack?

Sidenote: I really think we should come to a conclusion about the
concept. KVM integration into perf is very useful feature to analyze virtualization workloads.

Thanks,

Joerg

maintainer
#233 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 3 lines · Joerg Roedel

Sidenote: I really think we should come to a conclusion about the
concept. KVM integration into perf is very useful feature to analyze virtualization workloads.

I always start my things with bare kvm, It would be very unwelcome to mandate libvirt, or for that matter running a particular userspace in the guest.

#234 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Joerg Roedel
Quoted 7 lines · Joerg Roedel
Quoted 3 lines · Avi Kivity

So, two users can't have a guest named MyGuest each?  What about namespace support?  There's a lot of work in virtualizing all kernel namespaces, you're adding to that.

This enumeration is a very small and non-intrusive feature. Making it aware of namespaces is easy too.

an outsider's comment: this path leads to a filesystem... which could be a very nice idea. it could have a directory for each VM, with pseudo-files with all the guest's status, and even the memory it's
using. perf could simply watch those files. in fact, such a
filesystem could be the main userleve/kernel interface.

but i'm sure such a layour was considered (and rejected) very early in the KVM design. i don't think there's anything new to make it more desirable than it was back then.

Signature · 1 line
Javier
#235 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Joerg Roedel
Quoted 12 lines · Joerg Roedel
Quoted 10 lines · Avi Kivity
Quoted 7 lines · Joerg Roedel

And this system wide entity is the kvm module. It creates instances of 'struct kvm' and destroys them. I see no problem if we just attach a name to every instance with a good default value like kvm0, kvm1 ... or guest0, guest1 ... User-space can override the name if it wants. The kvm module takes care about the names being unique.

Quoted 7 lines
Quoted 4 lines

So, two users can't have a guest named MyGuest each? What about namespace support? There's a lot of work in virtualizing all kernel namespaces, you're adding to that.

This enumeration is a very small and non-intrusive feature. Making it aware of namespaces is easy too.

It's easier (and safer and all the other boring bits) not to do it at all in the kernel.

Quoted 5 lines
Quoted 2 lines

What about notifications when guests are added or removed?

Who would be the consumer of such notifications? A 'perf kvm list' can live without I guess. If we need them later we can still add them.

System-wide monitoring needs to work equally well for guests started before or after the monitor. Even disregarding that, if you introduce an API, people will start using it and complaining if it's incomplete.

The equivalent functionality for network interfaces is in netlink.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

This is very much the same as network card numbering is implemented in the kernel.
Forcing perf to talk to qemu or even libvirt produces to much overhead imho. Instrumentation only produces useful results with low overhead.

Quoted 7 lines
Quoted 2 lines

It's a setup cost only.

My statement was not limited to enumeration, I should have been more clear about that. The guest filesystem access-channel is another affected part. The 'perf kvm top' command will access the guest filesystem regularly and going over qemu would be more overhead here.

Why? Also, the real cost would be accessing the filesystem, not copying data over qemu.

Quoted 4 lines

Providing this in the KVM module directly also has the benefit that it would work out-of-the-box with different userspaces too. Or do we want to limit 'perf kvm' to the libvirt-qemu-kvm software stack?

Other userspaces can also provide this functionality, like they have to provide disk, network, and display emulation. The kernel is not a huge library.

Quoted 5 lines

Sidenote: I really think we should come to a conclusion about the
concept. KVM integration into perf is very useful feature to
analyze virtualization workloads.

Agreed.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#236 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 7 lines · Avi Kivity
Quoted 3 lines · Joerg Roedel

This enumeration is a very small and non-intrusive feature. Making it aware of namespaces is easy too.

It's easier (and safer and all the other boring bits) not to do it at all in the kernel.

For the KVM stack is doesn't matter where it is implemented. It is as easy in qemu or libvirt as in the kernel. I also don't see big risks. On the perf side and for its users it is a lot easier to have this in the kernel.
I for example always use plain qemu when running kvm guests and never used libvirt. The only central entity I have here is the kvm kernel modules. I don't want to start using it only to be able to use perf kvm.

Quoted 5 lines
Quoted 2 lines

Who would be the consumer of such notifications? A 'perf kvm list' can live without I guess. If we need them later we can still add them.

System-wide monitoring needs to work equally well for guests started before or after the monitor.

Could be easily done using notifier chains already in the kernel. Probably implemented with much less than 100 lines of additional code.

Quoted 2 lines

Even disregarding that, if you introduce an API, people will start using it and complaining if it's incomplete.

There is nothing wrong with that. We only need to define what this API should be used for to prevent rank growth. It could be an instrumentation-only API for example.

Quoted 8 lines
Quoted 5 lines

My statement was not limited to enumeration, I should have been more clear about that. The guest filesystem access-channel is another affected part. The 'perf kvm top' command will access the guest filesystem regularly and going over qemu would be more overhead here.

Why? Also, the real cost would be accessing the filesystem, not copying data over qemu.

When measuring cache-misses any additional (and in this case unnecessary) copy-overhead result in less appropriate results.

Quoted 7 lines
Quoted 3 lines

Providing this in the KVM module directly also has the benefit that it would work out-of-the-box with different userspaces too. Or do we want to limit 'perf kvm' to the libvirt-qemu-kvm software stack?

Other userspaces can also provide this functionality, like they have to provide disk, network, and display emulation. The kernel is not a huge library.

This has nothing to do with a library. It is about entity and resource management which is what os kernels are about. The virtual machine is the entity (similar to a process) and we want to add additional access channels and names to it.

Joerg

#237 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 11 lines · Joerg Roedel
Quoted 9 lines · Avi Kivity
Quoted 4 lines · Joerg Roedel

This enumeration is a very small and non-intrusive feature. Making it aware of namespaces is easy too.

It's easier (and safer and all the other boring bits) not to do it at all in the kernel.

Quoted 8 lines

For the KVM stack is doesn't matter where it is implemented. It is as easy in qemu or libvirt as in the kernel. I also don't see big risks. On the perf side and for its users it is a lot easier to have this in the kernel.
I for example always use plain qemu when running kvm guests and never used libvirt. The only central entity I have here is the kvm kernel modules. I don't want to start using it only to be able to use perf kvm.

You can always provide the kernel and module paths as command line parameters. It just won't be transparently usable, but if you're using qemu from the command line, presumably you can live with that.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

Who would be the consumer of such notifications? A 'perf kvm list' can live without I guess. If we need them later we can still add them.

System-wide monitoring needs to work equally well for guests started before or after the monitor.

Could be easily done using notifier chains already in the kernel. Probably implemented with much less than 100 lines of additional code.

And a userspace interface for that.

Quoted 7 lines
Quoted 3 lines

Even disregarding that, if you introduce an API, people will start using it and complaining if it's incomplete.

There is nothing wrong with that. We only need to define what this API should be used for to prevent rank growth. It could be an instrumentation-only API for example.

If we make an API, I'd like it to be generally useful.

It's a total headache. For example, we'd need security module hooks to determine access permissions. So far we managed to avoid that since kvm doesn't allow you to access any information beyond what you provided it directly.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

My statement was not limited to enumeration, I should have been more clear about that. The guest filesystem access-channel is another affected part. The 'perf kvm top' command will access the guest filesystem regularly and going over qemu would be more overhead here.

Quoted 6 lines
Quoted 3 lines

Why? Also, the real cost would be accessing the filesystem, not copying data over qemu.

When measuring cache-misses any additional (and in this case unnecessary) copy-overhead result in less appropriate results.

Copying the objects is a one time cost. If you run perf for more than a second or two, it would fetch and cache all of the data. It's really the same problem with non-guest profiling, only magnified a bit.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Providing this in the KVM module directly also has the benefit that it would work out-of-the-box with different userspaces too. Or do we want to limit 'perf kvm' to the libvirt-qemu-kvm software stack?

Quoted 9 lines
Quoted 4 lines

Other userspaces can also provide this functionality, like they have to provide disk, network, and display emulation. The kernel is not a huge library.

This has nothing to do with a library. It is about entity and resource management which is what os kernels are about. The virtual machine is the entity (similar to a process) and we want to add additional access channels and names to it.

kvm.ko has only a small subset of the information that is used to define a guest.

Signature · 1 line
error compiling committee.c: too many arguments to function
#238 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 5 lines · Avi Kivity

On 03/24/2010 01:59 PM, Joerg Roedel wrote:

You can always provide the kernel and module paths as command line parameters. It just won't be transparently usable, but if you're using qemu from the command line, presumably you can live with that.

I don't want the tool for myself only. A typical perf user expects that it works transparent.

Quoted 4 lines
Quoted 2 lines

Could be easily done using notifier chains already in the kernel. Probably implemented with much less than 100 lines of additional code.

And a userspace interface for that.

Not necessarily. The perf event is configured to measure systemwide kvm by userspace. The kernel side of perf takes care that it stays system-wide even with added vm instances. So in this case the consumer for the notifier would be the perf kernel part. No userspace interface required.

Quoted 1 line

If we make an API, I'd like it to be generally useful.

Thats hard to do at this point since we don't know what people will use it for. We should keep it simple in the beginning and add new features as they are requested and make sense in this context.

Quoted 4 lines

It's a total headache. For example, we'd need security module hooks to determine access permissions. So far we managed to avoid that since kvm doesn't allow you to access any information beyond what you provided it directly.

Depends on how it is designed. A filesystem approach was already mentioned. We could create /sys/kvm/ for example to expose information about virtual machines to userspace. This would not require any new security hooks.

Quoted 3 lines

Copying the objects is a one time cost. If you run perf for more than a second or two, it would fetch and cache all of the data. It's really the same problem with non-guest profiling, only magnified a bit.

I don't think we can cache filesystem data of a running guest on the host. It is too hard to keep such a cache coherent.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Other userspaces can also provide this functionality, like they have to provide disk, network, and display emulation. The kernel is not a huge library.

If two userspaces run in parallel what is the single instance where perf can get a list of guests from?

Quoted 2 lines

kvm.ko has only a small subset of the information that is used to define a guest.

The subset is not small. It contains all guest vcpus, the complete interrupt routing hardware emulation and manages event the guests memory.

Joerg

#239 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 8 lines · Joerg Roedel
Quoted 5 lines

You can always provide the kernel and module paths as command line parameters. It just won't be transparently usable, but if you're using qemu from the command line, presumably you can live with that.

I don't want the tool for myself only. A typical perf user expects that it works transparent.

A typical kvm user uses libvirt, so we can integrate it with that.

Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

Could be easily done using notifier chains already in the kernel. Probably implemented with much less than 100 lines of additional code.

And a userspace interface for that.

Not necessarily. The perf event is configured to measure systemwide kvm by userspace. The kernel side of perf takes care that it stays system-wide even with added vm instances. So in this case the consumer for the notifier would be the perf kernel part. No userspace interface required.

Someone needs to know about the new guest to fetch its symbols. Or do you want that part in the kernel too?

Quoted 6 lines
Quoted 2 lines

If we make an API, I'd like it to be generally useful.

Thats hard to do at this point since we don't know what people will use it for. We should keep it simple in the beginning and add new features as they are requested and make sense in this context.

IMO this use case is to rare to warrant its own API, especially as there are alternatives.

Quoted 10 lines
Quoted 5 lines

It's a total headache. For example, we'd need security module hooks to determine access permissions. So far we managed to avoid that since kvm doesn't allow you to access any information beyond what you provided it directly.

Depends on how it is designed. A filesystem approach was already mentioned. We could create /sys/kvm/ for example to expose information about virtual machines to userspace. This would not require any new security hooks.

Who would set the security context on those files? Plus, we need cgroup support so you can't see one container's guests from an unrelated container.

Quoted 7 lines
Quoted 4 lines

Copying the objects is a one time cost. If you run perf for more than a second or two, it would fetch and cache all of the data. It's really the same problem with non-guest profiling, only magnified a bit.

I don't think we can cache filesystem data of a running guest on the host. It is too hard to keep such a cache coherent.

I don't see any choice. The guest can change its symbols at any time (say by kexec), without any notification.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Other userspaces can also provide this functionality, like they have to provide disk, network, and display emulation. The kernel is not a huge library.

If two userspaces run in parallel what is the single instance where perf can get a list of guests from?

I don't know. Surely that's solvable though.

Quoted 7 lines
Quoted 3 lines

kvm.ko has only a small subset of the information that is used to define a guest.

The subset is not small. It contains all guest vcpus, the complete interrupt routing hardware emulation and manages event the guests memory.

It doesn't contain most of the mmio and pio address space. Integration with qemu would allow perf to tell us that the guest is hitting the interrupt status register of a virtio-blk device in pci slot 5 (the information is already available through the kvm_mmio trace event, but only qemu can decode it).

Signature · 1 line
error compiling committee.c: too many arguments to function
#240 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 6 lines · Avi Kivity
Quoted 2 lines · Joerg Roedel

I don't want the tool for myself only. A typical perf user expects that it works transparent.

A typical kvm user uses libvirt, so we can integrate it with that.

Someone who uses libvirt and virt-manager by default is probably not interested in this feature at the same level a kvm developer is. And developers tend not to use libvirt for low-level kvm development. A number of developers have stated in this thread already that they would appreciate a solution for guest enumeration that would not involve libvirt.

Quoted 2 lines

Someone needs to know about the new guest to fetch its symbols. Or do you want that part in the kernel too?

The samples will be tagged with the guest-name (and some additional information perf needs). Perf userspace can access the symbols then through /sys/kvm/guest0/fs/...

Quoted 6 lines
Quoted 4 lines

Depends on how it is designed. A filesystem approach was already mentioned. We could create /sys/kvm/ for example to expose information about virtual machines to userspace. This would not require any new security hooks.

Who would set the security context on those files?

An approach like: "The files are owned and only readable by the same user that started the vm." might be a good start. So a user can measure its own guests and root can measure all of them.

Quoted 2 lines

Plus, we need cgroup support so you can't see one container's guests from an unrelated container.

cgroup support is an issue but we can solve that too. Its in general still less complex than going through the whole libvirt-qemu-kvm stack.

Quoted 4 lines

Integration with qemu would allow perf to tell us that the guest is hitting the interrupt status register of a virtio-blk device in pci slot 5 (the information is already available through the kvm_mmio trace event, but only qemu can decode it).

Yeah that would be interesting information. But it is more related to tracing than to pmu measurements.
The information which you mentioned above are probably better captured by an extension of trace-events to userspace.

Joerg

#241 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 8 lines · Joerg Roedel
Quoted 6 lines · Avi Kivity
Quoted 3 lines · Joerg Roedel

I don't want the tool for myself only. A typical perf user expects that it works transparent.

Quoted 9 lines
Quoted 2 lines

A typical kvm user uses libvirt, so we can integrate it with that.

Someone who uses libvirt and virt-manager by default is probably not interested in this feature at the same level a kvm developer is. And developers tend not to use libvirt for low-level kvm development. A number of developers have stated in this thread already that they would appreciate a solution for guest enumeration that would not involve libvirt.

So would I. But when I weigh the benefit of truly transparent system-wide perf integration for users who don't use libvirt but do use perf, versus the cost of transforming kvm from a single-process API to a system-wide API with all the complications that I've listed, it comes out in favour of not adding the API.

Those few users can probably script something to cover their needs.

Quoted 7 lines
Quoted 3 lines

Someone needs to know about the new guest to fetch its symbols. Or do you want that part in the kernel too?

The samples will be tagged with the guest-name (and some additional information perf needs). Perf userspace can access the symbols then through /sys/kvm/guest0/fs/...

I take that as a yes? So we need a virtio-serial client in the kernel (which might be exploitable by a malicious guest if buggy) and a fs-over-virtio-serial client in the kernel (also exploitable).

Quoted 11 lines
Quoted 7 lines
Quoted 5 lines

Depends on how it is designed. A filesystem approach was already mentioned. We could create /sys/kvm/ for example to expose information about virtual machines to userspace. This would not require any new security hooks.

Who would set the security context on those files?

An approach like: "The files are owned and only readable by the same user that started the vm." might be a good start. So a user can measure its own guests and root can measure all of them.

That's not how sVirt works. sVirt isolates a user's VMs from each other, so if a guest breaks into qemu it can't break into other guests owned by the same user.

The users who need this API (!libvirt and perf) probably don't care about sVirt, but a new API must not break it.

Quoted 6 lines
Quoted 3 lines

Plus, we need cgroup support so you can't see one container's guests from an unrelated container.

cgroup support is an issue but we can solve that too. Its in general still less complex than going through the whole libvirt-qemu-kvm stack.

It's a tradeoff. IMO, going through qemu is the better way, and also provides more information.

Quoted 10 lines
Quoted 5 lines

Integration with qemu would allow perf to tell us that the guest is hitting the interrupt status register of a virtio-blk device in pci slot 5 (the information is already available through the kvm_mmio trace event, but only qemu can decode it).

Yeah that would be interesting information. But it is more related to tracing than to pmu measurements.
The information which you mentioned above are probably better captured by an extension of trace-events to userspace.

It's all related. You start with perf, see a problem with mmio, call up a histogram of mmio or interrupts or whatever, then zoom in on the misbehaving device.

Signature · 1 line
error compiling committee.c: too many arguments to function
#242 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 10 lines · Avi Kivity
Quoted 6 lines · Joerg Roedel

Someone who uses libvirt and virt-manager by default is probably not interested in this feature at the same level a kvm developer is. And developers tend not to use libvirt for low-level kvm development. A number of developers have stated in this thread already that they would appreciate a solution for guest enumeration that would not involve libvirt.

So would I.

Great.

Quoted 5 lines

But when I weigh the benefit of truly transparent system-wide perf integration for users who don't use libvirt but do use perf, versus the cost of transforming kvm from a single-process API to a system-wide API with all the complications that I've listed, it comes out in favour of not adding the API.

Its not a transformation, its an extension. The current per-process /dev/kvm stays mostly untouched. Its all about having something like this:

$ cd /sys/kvm/guest0
$ ls -l
-r-------- 1 root root 0 2009-08-17 12:05 name
dr-x------ 1 root root 0 2009-08-17 12:05 fs
$ cat name
guest0
$ # ...

The fs/ directory is used as the mount point for the guest root fs.

Quoted 7 lines
Quoted 3 lines

The samples will be tagged with the guest-name (and some additional information perf needs). Perf userspace can access the symbols then through /sys/kvm/guest0/fs/...

I take that as a yes? So we need a virtio-serial client in the kernel (which might be exploitable by a malicious guest if buggy) and a fs-over-virtio-serial client in the kernel (also exploitable).

What I meant was: perf-kernel puts the guest-name into every sample and perf-userspace accesses /sys/kvm/guest_name/fs/ later to resolve the symbols. I leave the question of how the guest-fs is exposed to the host out of this discussion. We should discuss this seperatly.

Quoted 7 lines
Quoted 3 lines

An approach like: "The files are owned and only readable by the same user that started the vm." might be a good start. So a user can measure its own guests and root can measure all of them.

That's not how sVirt works. sVirt isolates a user's VMs from each other, so if a guest breaks into qemu it can't break into other guests owned by the same user.

If a vm breaks into qemu it can access the host file system which is the bigger problem. In this case there is no isolation anymore. From that context it can even kill other VMs of the same user independent of a hypothetical /sys/kvm/.

Quoted 8 lines
Quoted 4 lines

Yeah that would be interesting information. But it is more related to tracing than to pmu measurements. The information which you mentioned above are probably better captured by an extension of trace-events to userspace.

It's all related. You start with perf, see a problem with mmio, call up a histogram of mmio or interrupts or whatever, then zoom in on the misbehaving device.

Yes, but its different from the implementation point-of-view. For the user it surely all plays together.

Joerg

#243 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 19 lines · Joerg Roedel
Quoted 7 lines

But when I weigh the benefit of truly transparent system-wide perf integration for users who don't use libvirt but do use perf, versus the cost of transforming kvm from a single-process API to a system-wide API with all the complications that I've listed, it comes out in favour of not adding the API.

Its not a transformation, its an extension. The current per-process /dev/kvm stays mostly untouched. Its all about having something like this:

$ cd /sys/kvm/guest0
$ ls -l
-r-------- 1 root root 0 2009-08-17 12:05 name
dr-x------ 1 root root 0 2009-08-17 12:05 fs
$ cat name
guest0
$ # ...
Quoted 2 lines

The fs/ directory is used as the mount point for the guest root fs.

The problem is /sys/kvm, not /sys/kvm/fs.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The samples will be tagged with the guest-name (and some additional information perf needs). Perf userspace can access the symbols then through /sys/kvm/guest0/fs/...

Quoted 9 lines
Quoted 4 lines

I take that as a yes? So we need a virtio-serial client in the kernel (which might be exploitable by a malicious guest if buggy) and a fs-over-virtio-serial client in the kernel (also exploitable).

What I meant was: perf-kernel puts the guest-name into every sample and perf-userspace accesses /sys/kvm/guest_name/fs/ later to resolve the symbols. I leave the question of how the guest-fs is exposed to the host out of this discussion. We should discuss this seperatly.

How I see it: perf-kernel puts the guest pid into every sample, and perf-userspace uses that to resolve to a mountpoint served by fuse, or to a unix domain socket that serves the files.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

An approach like: "The files are owned and only readable by the same user that started the vm." might be a good start. So a user can measure its own guests and root can measure all of them.

Quoted 9 lines
Quoted 4 lines

That's not how sVirt works. sVirt isolates a user's VMs from each other, so if a guest breaks into qemu it can't break into other guests owned by the same user.

If a vm breaks into qemu it can access the host file system which is the bigger problem. In this case there is no isolation anymore. From that context it can even kill other VMs of the same user independent of a hypothetical /sys/kvm/.

It cannot. sVirt labels the disk image and other files qemu needs with the appropriate label, and everything else is off limits. Even if you run the guest as root, it won't have access to other files.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Yeah that would be interesting information. But it is more related to tracing than to pmu measurements. The information which you mentioned above are probably better captured by an extension of trace-events to userspace.

Quoted 7 lines
Quoted 4 lines

It's all related. You start with perf, see a problem with mmio, call up a histogram of mmio or interrupts or whatever, then zoom in on the misbehaving device.

Yes, but its different from the implementation point-of-view. For the user it surely all plays together.

We need qemu to cooperate for mmio tracing, and we can cooperate with qemu for symbol resolution. If it prevents adding another kernel API, that's a win from my POV.

Signature · 1 line
error compiling committee.c: too many arguments to function
#244 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 9 lines · Avi Kivity
Quoted 8 lines · Joerg Roedel
$ cd /sys/kvm/guest0
$ ls -l
-r-------- 1 root root 0 2009-08-17 12:05 name
dr-x------ 1 root root 0 2009-08-17 12:05 fs
$ cat name
guest0
$ # ...
Quoted 3 lines
Quoted 1 line

The fs/ directory is used as the mount point for the guest root fs.

The problem is /sys/kvm, not /sys/kvm/fs.

I am not tied to /sys/kvm. We could also use /proc/<pid>/kvm/ for example. This would keep anything in the process space (except for the global list of VMs which we should have anyway).

Quoted 8 lines
Quoted 4 lines

What I meant was: perf-kernel puts the guest-name into every sample and perf-userspace accesses /sys/kvm/guest_name/fs/ later to resolve the symbols. I leave the question of how the guest-fs is exposed to the host out of this discussion. We should discuss this seperatly.

How I see it: perf-kernel puts the guest pid into every sample, and perf-userspace uses that to resolve to a mountpoint served by fuse, or to a unix domain socket that serves the files.

We need a bit more information than just the qemu-pid, but yes, this would also work out.

Quoted 8 lines
Quoted 4 lines

If a vm breaks into qemu it can access the host file system which is the bigger problem. In this case there is no isolation anymore. From that context it can even kill other VMs of the same user independent of a hypothetical /sys/kvm/.

It cannot. sVirt labels the disk image and other files qemu needs with the appropriate label, and everything else is off limits. Even if you run the guest as root, it won't have access to other files.

See my reply to Daniel's email.

Quoted 6 lines
Quoted 2 lines

Yes, but its different from the implementation point-of-view. For the user it surely all plays together.

We need qemu to cooperate for mmio tracing, and we can cooperate with qemu for symbol resolution. If it prevents adding another kernel API, that's a win from my POV.

Thats true. Probably qemu can inject this information in the kvm-trace-events stream.

Joerg

#245 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 12 lines · Joerg Roedel
Quoted 10 lines · Avi Kivity
Quoted 8 lines · Joerg Roedel
$ cd /sys/kvm/guest0
$ ls -l
-r-------- 1 root root 0 2009-08-17 12:05 name
dr-x------ 1 root root 0 2009-08-17 12:05 fs
$ cat name
guest0
$ # ...
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

The fs/ directory is used as the mount point for the guest root fs.

The problem is /sys/kvm, not /sys/kvm/fs.

I am not tied to /sys/kvm. We could also use /proc/<pid>/kvm/ for example. This would keep anything in the process space (except for the global list of VMs which we should have anyway).

How about ~/.qemu/guests/$pid?

Signature · 1 line
error compiling committee.c: too many arguments to function
#246 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 15 lines · Avi Kivity
Quoted 14 lines · Joerg Roedel
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Joerg Roedel
$ cd /sys/kvm/guest0
$ ls -l
-r-------- 1 root root 0 2009-08-17 12:05 name
dr-x------ 1 root root 0 2009-08-17 12:05 fs
$ cat name
guest0
$ # ...

The fs/ directory is used as the mount point for the guest root fs.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

The problem is /sys/kvm, not /sys/kvm/fs.

I am not tied to /sys/kvm. We could also use /proc/<pid>/kvm/ for example. This would keep anything in the process space (except for the global list of VMs which we should have anyway).

How about ~/.qemu/guests/$pid?

That makes it hard for perf to find it and even harder to get a list of all VMs. With /proc/<pid>/kvm/guest we could symlink all guest directories to /proc/kvm/ and perf reads the list from there. Also perf can easily derive the directory for a guest from its pid. Last but not least its kernel-created and thus independent from the userspace part being used.

Joerg

#247 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 11 lines · Joerg Roedel
Quoted 9 lines
Quoted 7 lines

I am not tied to /sys/kvm. We could also use /proc/<pid>/kvm/ for example. This would keep anything in the process space (except for the global list of VMs which we should have anyway).

How about ~/.qemu/guests/$pid?

That makes it hard for perf to find it and even harder to get a list of all VMs.

Looks trivial to find a guest, less so with enumerating (still doable).

Quoted 6 lines

With /proc/<pid>/kvm/guest we could symlink all guest
directories to /proc/kvm/ and perf reads the list from there. Also perf can easily derive the directory for a guest from its pid. Last but not least its kernel-created and thus independent from the userspace part being used.

Doesn't perf already has a dependency on naming conventions for finding debug information?

Signature · 1 line
error compiling committee.c: too many arguments to function
#248 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 8 lines · Avi Kivity
Quoted 7 lines · Joerg Roedel
Quoted 7 lines
Quoted 7 lines

I am not tied to /sys/kvm. We could also use /proc/<pid>/kvm/ for example. This would keep anything in the process space (except for the global list of VMs which we should have anyway).

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

How about ~/.qemu/guests/$pid?

That makes it hard for perf to find it and even harder to get a list of all VMs.

Looks trivial to find a guest, less so with enumerating (still doable).

Not so trival and even more likely to break. Even it perf has the pid of the process and wants to find the directory it has to do:

1. Get the uid of the process
2. Find the username for the uid
3. Use the username to find the home-directory

Steps 2. and 3. need nsswitch and/or pam access to get this information from whatever source the admin has configured. And depending on what the source is it may be temporarily unavailable causing nasty timeouts. In short, there are many weak parts in that chain making it more likely to break.
A kernel-based approach with /proc/<pid>/kvm does not have those issues (and to repeat myself, it is independent from the userspace being used).

Joerg

#249 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 10 lines · Joerg Roedel
Quoted 3 lines

Looks trivial to find a guest, less so with enumerating (still doable).

Not so trival and even more likely to break. Even it perf has the pid of the process and wants to find the directory it has to do:

1. Get the uid of the process
2. Find the username for the uid
3. Use the username to find the home-directory

Quoted 6 lines

Steps 2. and 3. need nsswitch and/or pam access to get this information from whatever source the admin has configured. And depending on what the source is it may be temporarily unavailable causing nasty timeouts. In short, there are many weak parts in that chain making it more likely to break.

It's true. If the kernel provides something, there are fewer things that can break. But if your system is so broken that you can't resolve uids, fix that before running perf. Must we design perf for that case?

After all, 'ls -l' will break under the same circumstances. It's hard to imagine doing useful work when that doesn't work.

Quoted 3 lines

A kernel-based approach with /proc/<pid>/kvm does not have those issues (and to repeat myself, it is independent from the userspace being used).

It has other issues, which are IMO more problematic.

Signature · 1 line
error compiling committee.c: too many arguments to function
#250 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 4 lines · Avi Kivity

It's true. If the kernel provides something, there are fewer things that can break. But if your system is so broken that you can't resolve uids, fix that before running perf. Must we design perf for that case?

After all, 'ls -l' will break under the same circumstances. It's hard to imagine doing useful work when that doesn't work.

Also, perf itself will hang if it needs to access a file using autofs or nfs, and those are broken.

Signature · 1 line
error compiling committee.c: too many arguments to function
#251 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 18 lines · Avi Kivity
Quoted 10 lines · Joerg Roedel
Quoted 3 lines

Looks trivial to find a guest, less so with enumerating (still doable).

Not so trival and even more likely to break. Even it perf has the pid of the process and wants to find the directory it has to do:

1. Get the uid of the process
2. Find the username for the uid
3. Use the username to find the home-directory

Quoted 6 lines

Steps 2. and 3. need nsswitch and/or pam access to get this information from whatever source the admin has configured. And depending on what the source is it may be temporarily unavailable causing nasty timeouts. In short, there are many weak parts in that chain making it more likely to break.

Quoted 3 lines

It's true. If the kernel provides something, there are fewer things that can break. But if your system is so broken that you can't resolve uids, fix that before running perf. Must we design perf for that case?

uid to username can fail when using chroots, or worse point to an incorrect location (and yes, I do use this)

Sorry if this has been covered / discussion has moved on. Just catching up with the 500+ messages in my inbox..

Antoine

Quoted 10 lines

After all, 'ls -l' will break under the same circumstances. It's hard to imagine doing useful work when that doesn't work.

Quoted 3 lines

A kernel-based approach with /proc/<pid>/kvm does not have those issues (and to repeat myself, it is independent from the userspace being used).

It has other issues, which are IMO more problematic.

#252 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity

Em Wed, Mar 24, 2010 at 06:09:30PM +0200, Avi Kivity escreveu:

Quoted 2 lines

Doesn't perf already has a dependency on naming conventions for finding debug information?

It looks at several places, from most symbol rich (/usr/lib/debug/, aka -debuginfo packages, where we have full symtabs) to poorest (the packaged binary, where we may just have a .dynsym).

In an ideal world, it would just get the build-id (a SHA1 cookie that is in an ELF session inserted in every binary (aka DSOs), kernel module, kallsyms or vmlinux file) and use that to look first in a local cache (implemented in perf for a long time already) or in some symbol server.

For instance, for a random perf.data file I collected here in my machine I have:

[acme@doppio linux-2.6-tip]$ perf buildid-list | grep libpthread 5c68f7afeb33309c78037e374b0deee84dd441f6 /lib64/libpthread-2.10.2.so [acme@doppio linux-2.6-tip]$

So I don't have to access /lib64/libpthread-2.10.2.so directly, nor some convention to get a debuginfo in a local file like:

/usr/lib/debug/lib64/libpthread-2.10.2.so.debug

Instead the tools look at:

[acme@doppio linux-2.6-tip]$ l ~/.debug/.build-id/5c/68f7afeb33309c78037e374b0deee84dd441f6
lrwxrwxrwx 1 acme acme 73 2010-01-06 18:53 /home/acme/.debug/.build-id/5c/68f7afeb33309c78037e374b0deee84dd441f6 -> ../../lib64/libpthread-2.10.2.so/5c68f7afeb33309c78037e374b0deee84dd441f6*

To find the file for that specific build-id, not the one installed in my machine (or on the different machine, of a different architecture) that may be completely unrelated, a new one, or one for a different arch.

- Arnaldo

#253 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 26 lines · Arnaldo Carvalho de Melo

Em Wed, Mar 24, 2010 at 06:09:30PM +0200, Avi Kivity escreveu:

Quoted 3 lines

Doesn't perf already has a dependency on naming conventions for finding debug information?

It looks at several places, from most symbol rich (/usr/lib/debug/, aka -debuginfo packages, where we have full symtabs) to poorest (the packaged binary, where we may just have a .dynsym).

In an ideal world, it would just get the build-id (a SHA1 cookie that is in an ELF session inserted in every binary (aka DSOs), kernel module, kallsyms or vmlinux file) and use that to look first in a local cache (implemented in perf for a long time already) or in some symbol server.

For instance, for a random perf.data file I collected here in my machine I have:

[acme@doppio linux-2.6-tip]$ perf buildid-list | grep libpthread 5c68f7afeb33309c78037e374b0deee84dd441f6 /lib64/libpthread-2.10.2.so [acme@doppio linux-2.6-tip]$

So I don't have to access /lib64/libpthread-2.10.2.so directly, nor some convention to get a debuginfo in a local file like:

/usr/lib/debug/lib64/libpthread-2.10.2.so.debug

Quoted 9 lines

Instead the tools look at:

[acme@doppio linux-2.6-tip]$ l ~/.debug/.build-id/5c/68f7afeb33309c78037e374b0deee84dd441f6
lrwxrwxrwx 1 acme acme 73 2010-01-06 18:53 /home/acme/.debug/.build-id/5c/68f7afeb33309c78037e374b0deee84dd441f6 -> ../../lib64/libpthread-2.10.2.so/5c68f7afeb33309c78037e374b0deee84dd441f6*

To find the file for that specific build-id, not the one installed in my machine (or on the different machine, of a different architecture) that may be completely unrelated, a new one, or one for a different arch.

Thanks. I believe qemu could easily act as a symbol server for this use case.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#254 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Em Wed, Mar 24, 2010 at 08:20:10PM +0200, Avi Kivity escreveu:

Quoted 32 lines · Arnaldo Carvalho de Melo
Quoted 31 lines

Em Wed, Mar 24, 2010 at 06:09:30PM +0200, Avi Kivity escreveu:

Quoted 3 lines

Doesn't perf already has a dependency on naming conventions for finding debug information?

It looks at several places, from most symbol rich (/usr/lib/debug/, aka -debuginfo packages, where we have full symtabs) to poorest (the packaged binary, where we may just have a .dynsym).

In an ideal world, it would just get the build-id (a SHA1 cookie that is in an ELF session inserted in every binary (aka DSOs), kernel module, kallsyms or vmlinux file) and use that to look first in a local cache (implemented in perf for a long time already) or in some symbol server.

For instance, for a random perf.data file I collected here in my machine I have:

[acme@doppio linux-2.6-tip]$ perf buildid-list | grep libpthread 5c68f7afeb33309c78037e374b0deee84dd441f6 /lib64/libpthread-2.10.2.so [acme@doppio linux-2.6-tip]$

So I don't have to access /lib64/libpthread-2.10.2.so directly, nor some convention to get a debuginfo in a local file like:

/usr/lib/debug/lib64/libpthread-2.10.2.so.debug

Instead the tools look at:

[acme@doppio linux-2.6-tip]$ l ~/.debug/.build-id/5c/68f7afeb33309c78037e374b0deee84dd441f6
lrwxrwxrwx 1 acme acme 73 2010-01-06 18:53 /home/acme/.debug/.build-id/5c/68f7afeb33309c78037e374b0deee84dd441f6 -> ../../lib64/libpthread-2.10.2.so/5c68f7afeb33309c78037e374b0deee84dd441f6*

Quoted 6 lines
Quoted 3 lines

To find the file for that specific build-id, not the one installed in my machine (or on the different machine, of a different architecture) that may be completely unrelated, a new one, or one for a different arch.

Thanks. I believe qemu could easily act as a symbol server for this use case.

Agreed, but it doesn't even have to :-)

We just need to get the build-id in the PERF_RECORD_MMAP event somehow and then get this symbol from elsewhere, say the same DVD/RHN channel/Debian Repository/embedded developer toolkit image not stripped/whatever.

Or it may already be in the local cache from last week's perf report session :-)

- Arnaldo

#255 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 32 lines · Avi Kivity
Quoted 31 lines · Arnaldo Carvalho de Melo

Em Wed, Mar 24, 2010 at 06:09:30PM +0200, Avi Kivity escreveu:

Quoted 3 lines

Doesn't perf already has a dependency on naming conventions for finding debug information?

It looks at several places, from most symbol rich (/usr/lib/debug/, aka -debuginfo packages, where we have full symtabs) to poorest (the packaged binary, where we may just have a .dynsym).

In an ideal world, it would just get the build-id (a SHA1 cookie that is in an ELF session inserted in every binary (aka DSOs), kernel module, kallsyms or vmlinux file) and use that to look first in a local cache (implemented in perf for a long time already) or in some symbol server.

For instance, for a random perf.data file I collected here in my machine I have:

[acme@doppio linux-2.6-tip]$ perf buildid-list | grep libpthread 5c68f7afeb33309c78037e374b0deee84dd441f6 /lib64/libpthread-2.10.2.so [acme@doppio linux-2.6-tip]$

So I don't have to access /lib64/libpthread-2.10.2.so directly, nor some convention to get a debuginfo in a local file like:

/usr/lib/debug/lib64/libpthread-2.10.2.so.debug

Instead the tools look at:

[acme@doppio linux-2.6-tip]$ l ~/.debug/.build-id/5c/68f7afeb33309c78037e374b0deee84dd441f6
lrwxrwxrwx 1 acme acme 73 2010-01-06 18:53 /home/acme/.debug/.build-id/5c/68f7afeb33309c78037e374b0deee84dd441f6 -> ../../lib64/libpthread-2.10.2.so/5c68f7afeb33309c78037e374b0deee84dd441f6*

Quoted 7 lines
Quoted 4 lines

To find the file for that specific build-id, not the one installed in my machine (or on the different machine, of a different architecture) that may be completely unrelated, a new one, or one for a different arch.

Thanks. I believe qemu could easily act as a symbol server for this use case.

I spent a couple of days to investigate why sshfs/fuse doesn't work well with procfs and sysfs. Just after my patch against fuse is ready almost, I found fuse already supports such access by direct I/O. With parameter -o direct_io, it could work well.

Here is an example to mount / from a guest os. #sshfs -p 5551 -o direct_io localhost:/ guestmount

We can read files and write files if permission is ok.

I will go ahead to support multiple guest os instance statistics parsing.

Yanmin

#256 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Joerg Roedel
Quoted 4 lines · Joerg Roedel
Quoted 4 lines
Quoted 3 lines

An approach like: "The files are owned and only readable by the same user that started the vm." might be a good start. So a user can measure its own guests and root can measure all of them.

Quoted 8 lines
Quoted 3 lines

That's not how sVirt works. sVirt isolates a user's VMs from each other, so if a guest breaks into qemu it can't break into other guests owned by the same user.

If a vm breaks into qemu it can access the host file system which is the bigger problem. In this case there is no isolation anymore. From that context it can even kill other VMs of the same user independent of a hypothetical /sys/kvm/.

No it can't. With sVirt every single VM has a custom security label and the policy only allows it access to disks / files with a matching label, and prevents it attacking any other VMs or processes on the host. THis confines the scope of any exploit in QEMU to those resources the admin has explicitly assigned to the guest.

Regards,
Daniel

Signature · 4 lines
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#257 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 14 lines · Daniel P. Berrange
Quoted 4 lines · Joerg Roedel
Quoted 4 lines
Quoted 3 lines

An approach like: "The files are owned and only readable by the same user that started the vm." might be a good start. So a user can measure its own guests and root can measure all of them.

Quoted 8 lines
Quoted 3 lines

That's not how sVirt works. sVirt isolates a user's VMs from each other, so if a guest breaks into qemu it can't break into other guests owned by the same user.

If a vm breaks into qemu it can access the host file system which is the bigger problem. In this case there is no isolation anymore. From that context it can even kill other VMs of the same user independent of a hypothetical /sys/kvm/.

Quoted 5 lines

No it can't. With sVirt every single VM has a custom security label and the policy only allows it access to disks / files with a matching label, and prevents it attacking any other VMs or processes on the host. THis confines the scope of any exploit in QEMU to those resources the admin has explicitly assigned to the guest.

Even better. So a guest which breaks out can't even access its own /sys/kvm/ directory. Perfect, it doesn't need that access anyway.

Joerg

#258 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 11 lines · Joerg Roedel
Quoted 7 lines

No it can't. With sVirt every single VM has a custom security label and the policy only allows it access to disks / files with a matching label, and prevents it attacking any other VMs or processes on the host. THis confines the scope of any exploit in QEMU to those resources the admin has explicitly assigned to the guest.

Even better. So a guest which breaks out can't even access its own /sys/kvm/ directory. Perfect, it doesn't need that access anyway.

But what security label does that directory have? How can we make sure that whoever needs access to those files, gets them?

Automatically created objects don't work well with that model. They're simply missing information.

Signature · 1 line
error compiling committee.c: too many arguments to function
#259 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 9 lines · Avi Kivity
Quoted 2 lines · Joerg Roedel

Even better. So a guest which breaks out can't even access its own /sys/kvm/ directory. Perfect, it doesn't need that access anyway.

But what security label does that directory have? How can we make sure that whoever needs access to those files, gets them?

Automatically created objects don't work well with that model. They're simply missing information.

If we go the /proc/<pid>/kvm way then the directory should probably inherit the label from /proc/<pid>/?
Same could be applied to /sys/kvm/guest/ if we decide for it. The VM is still bound to a single process with a /proc/<pid> after all.

Joerg

#260 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 7 lines · Joerg Roedel
Quoted 5 lines · Avi Kivity
Quoted 3 lines · Joerg Roedel

Even better. So a guest which breaks out can't even access its own /sys/kvm/ directory. Perfect, it doesn't need that access anyway.

Quoted 9 lines
Quoted 6 lines

But what security label does that directory have? How can we make sure that whoever needs access to those files, gets them?

Automatically created objects don't work well with that model. They're simply missing information.

If we go the /proc/<pid>/kvm way then the directory should probably inherit the label from /proc/<pid>/?

That's a security policy. The security people like their policies outside the kernel.

For example, they may want a label that allows a trace context to read the data, and also qemu itself for introspection.

Quoted 3 lines

Same could be applied to /sys/kvm/guest/ if we decide for it. The VM is still bound to a single process with a /proc/<pid> after all.

Ditto.

Signature · 1 line
error compiling committee.c: too many arguments to function
#261 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 9 lines · Avi Kivity
Quoted 2 lines · Joerg Roedel

If we go the /proc/<pid>/kvm way then the directory should probably inherit the label from /proc/<pid>/?

That's a security policy. The security people like their policies outside the kernel.

For example, they may want a label that allows a trace context to read the data, and also qemu itself for introspection.

Hm, I am not a security expert. But is this not only one entity more for sVirt to handle? I would leave that decision to the sVirt developers. Does attaching the same label as for the VM resources mean that root could not access it anymore?

Joerg

#262 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 7 lines · Joerg Roedel
Quoted 5 lines · Avi Kivity
Quoted 3 lines · Joerg Roedel

If we go the /proc/<pid>/kvm way then the directory should probably inherit the label from /proc/<pid>/?

Quoted 7 lines
Quoted 6 lines

That's a security policy. The security people like their policies outside the kernel.

For example, they may want a label that allows a trace context to read the data, and also qemu itself for introspection.

Hm, I am not a security expert.

I'm out of my depth here as well.

Quoted 5 lines

But is this not only one entity more for
sVirt to handle? I would leave that decision to the sVirt developers. Does attaching the same label as for the VM resources mean that root could not access it anymore?

IIUC processes run under a context, and there's a policy somewhere that tells you which context can access which label (and with what permissions). There was a server on the Internet once that gave you root access and invited you to attack it. No idea if anyone succeeded or not (I got bored after about a minute).

So it depends on the policy. If you attach the same label, that means all files with the same label have the same access permissions. I think.

Signature · 1 line
error compiling committee.c: too many arguments to function
#263 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 7 lines · Avi Kivity
Quoted 5 lines · Joerg Roedel

But is this not only one entity more for
sVirt to handle? I would leave that decision to the sVirt developers. Does attaching the same label as for the VM resources mean that root could not access it anymore?

Quoted 8 lines

IIUC processes run under a context, and there's a policy somewhere that tells you which context can access which label (and with what permissions). There was a server on the Internet once that gave you root access and invited you to attack it. No idea if anyone succeeded or not (I got bored after about a minute).

So it depends on the policy. If you attach the same label, that means all files with the same label have the same access permissions. I think.

So if this is true we can introduce a 'trace' label and add all contexts that should be allowed to trace to it.
But we probably should leave the details to the security experts ;-)

Joerg

#264 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 16 lines · Joerg Roedel
Quoted 14 lines · Avi Kivity
Quoted 6 lines · Joerg Roedel

But is this not only one entity more for
sVirt to handle? I would leave that decision to the sVirt developers. Does attaching the same label as for the VM resources mean that root could not access it anymore?

IIUC processes run under a context, and there's a policy somewhere that tells you which context can access which label (and with what permissions). There was a server on the Internet once that gave you root access and invited you to attack it. No idea if anyone succeeded or not (I got bored after about a minute).

Quoted 7 lines
Quoted 3 lines

So it depends on the policy. If you attach the same label, that means all files with the same label have the same access permissions. I think.

So if this is true we can introduce a 'trace' label and add all contexts that should be allowed to trace to it.
But we probably should leave the details to the security experts ;-)

That's just what I want to do. Leave it in userspace and then they can deal with it without telling us about it.

Signature · 1 line
error compiling committee.c: too many arguments to function
#265 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 4 lines · Avi Kivity

On 03/24/2010 06:31 PM, Joerg Roedel wrote:

That's just what I want to do. Leave it in userspace and then they can deal with it without telling us about it.

They can't do that with a directory in /proc?

#266 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 7 lines · Joerg Roedel
Quoted 4 lines

That's just what I want to do. Leave it in userspace and then they can deal with it without telling us about it.

They can't do that with a directory in /proc?

I don't know.

Signature · 1 line
error compiling committee.c: too many arguments to function
maintainer
#267 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Joerg Roedel
Quoted 4 lines · Joerg Roedel

What I meant was: perf-kernel puts the guest-name into every sample and perf-userspace accesses /sys/kvm/guest_name/fs/ later to resolve the symbols. I leave the question of how the guest-fs is exposed to the host out of this discussion. We should discuss this seperatly.

I'd much prefer a pid like suggested later, keeps the samples smaller.

But that said, we need guest kernel events like mmap and context switches too, otherwise we simply can't make sense of guest userspace addresses, we need to know the guest address space layout.

So aside from a filesystem content, we first need mmap and context switch events to find the files we need to access.

And while I appreciate all the security talk, its basically pointless anyway, the host can access it anyway, everybody agrees on that, but still you're arguing the case..

#268 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 8 lines · Peter Zijlstra
Quoted 5 lines · Joerg Roedel

What I meant was: perf-kernel puts the guest-name into every sample and perf-userspace accesses /sys/kvm/guest_name/fs/ later to resolve the symbols. I leave the question of how the guest-fs is exposed to the host out of this discussion. We should discuss this seperatly.

Quoted 6 lines

I'd much prefer a pid like suggested later, keeps the samples smaller.

But that said, we need guest kernel events like mmap and context switches too, otherwise we simply can't make sense of guest userspace addresses, we need to know the guest address space layout.

The kernel knows some of the address space layout, qemu knows all of it.

Quoted 3 lines

So aside from a filesystem content, we first need mmap and context switch events to find the files we need to access.

This only works for the guest kernel, we don't know anything about guest processes [1].

Quoted 4 lines

And while I appreciate all the security talk, its basically pointless anyway, the host can access it anyway, everybody agrees on that, but still you're arguing the case..

root can access anything, but we're not talking about root. The idea is to protect against a guest that has exploited its qemu and is now attacking the host and its fellow guests. uid protection is no good since we want to isolate the guest from host processes belonging to the same uid and from other guests running under the same uid.

[1] We can find out guest pids if we teach the kernel what to dereference, i.e. gs:offset1->offset2->offset3. Of course this varies from kernel to kernel, so we need some kind of bytecode that we can run in perf nmi context. Kind of what we need to run an unwinder for -fomit-frame-pointer.

Signature · 1 line
error compiling committee.c: too many arguments to function
#269 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Peter Zijlstra
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines · Joerg Roedel

What I meant was: perf-kernel puts the guest-name into every sample and perf-userspace accesses /sys/kvm/guest_name/fs/ later to resolve the symbols. I leave the question of how the guest-fs is exposed to the host out of this discussion. We should discuss this seperatly.

Quoted 5 lines

I'd much prefer a pid like suggested later, keeps the samples smaller.

But that said, we need guest kernel events like mmap and context switches too, otherwise we simply can't make sense of guest userspace addresses, we need to know the guest address space layout.

With the filesystem approach all we need is the pid of the guest process. Then we can access proc/<pid>/maps of the guest and read out the address space layout, no?

Joerg

maintainer
#270 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 10 lines · Joerg Roedel
Quoted 9 lines · Peter Zijlstra
Quoted 4 lines · Joerg Roedel

What I meant was: perf-kernel puts the guest-name into every sample and perf-userspace accesses /sys/kvm/guest_name/fs/ later to resolve the symbols. I leave the question of how the guest-fs is exposed to the host out of this discussion. We should discuss this seperatly.

I'd much prefer a pid like suggested later, keeps the samples smaller.

Quoted 7 lines
Quoted 3 lines

But that said, we need guest kernel events like mmap and context switches too, otherwise we simply can't make sense of guest userspace addresses, we need to know the guest address space layout.

With the filesystem approach all we need is the pid of the guest process. Then we can access proc/<pid>/maps of the guest and read out the address space layout, no?

No, what if it maps new things after you read it? But still getting the pid of the guest process seems non trivial without guest kernel support.

#271 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 24 lines · Avi Kivity
Quoted 8 lines · Joerg Roedel
Quoted 5 lines

You can always provide the kernel and module paths as command line parameters. It just won't be transparently usable, but if you're using qemu from the command line, presumably you can live with that.

I don't want the tool for myself only. A typical perf user expects that it works transparent.

A typical kvm user uses libvirt, so we can integrate it with that.

Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

Could be easily done using notifier chains already in the kernel. Probably implemented with much less than 100 lines of additional code.

And a userspace interface for that.

Not necessarily. The perf event is configured to measure systemwide kvm by userspace. The kernel side of perf takes care that it stays system-wide even with added vm instances. So in this case the consumer for the notifier would be the perf kernel part. No userspace interface required.

Quoted 2 lines

Someone needs to know about the new guest to fetch its symbols. Or do you want that part in the kernel too?

How about we add a virtio "guest file system access" device? The guest would then expose its own file system using that device.

On the host side this would simply be a -virtioguestfs unix:/tmp/guest.fs and you'd get a unix socket that gives you full access to the guest file system by using commands. I envision something like:

SEND: GET /proc/version
RECV: Linux version 2.6.27.37-0.1-default (geeko@buildhost) (gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux) ) #1 SMP 2009-10-15 14:56:58 +0200

Now all we need is integration in perf to enumerate virtual machines based on libvirt. If you want to run qemu-kvm directly, just go with --guestfs=/tmp/guest.fs and perf could fetch all required information automatically.

This should solve all issues while staying 100% in user space, right?

Alex

#272 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 5 lines · Alexander Graf
Quoted 4 lines

Someone needs to know about the new guest to fetch its symbols. Or do you want that part in the kernel too?

Quoted 8 lines

How about we add a virtio "guest file system access" device? The guest would then expose its own file system using that device.

On the host side this would simply be a -virtioguestfs unix:/tmp/guest.fs and you'd get a unix socket that gives you full access to the guest file system by using commands. I envision something like:

The idea is to use a dedicated channel over virtio-serial. If the channel is present the file server can serve files over it.

Quoted 5 lines

SEND: GET /proc/version
RECV: Linux version 2.6.27.37-0.1-default (geeko@buildhost) (gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux) ) #1 SMP 2009-10-15 14:56:58 +0200

Quoted 7 lines

Now all we need is integration in perf to enumerate virtual machines based on libvirt. If you want to run qemu-kvm directly, just go with --guestfs=/tmp/guest.fs and perf could fetch all required information automatically.

This should solve all issues while staying 100% in user space, right?

Yeah, needs a fuse filesystem to populate the host namespace (kind of sshfs over virtio-serial).

Signature · 1 line
error compiling committee.c: too many arguments to function
#273 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 9 lines · Avi Kivity
Quoted 8 lines · Alexander Graf
Quoted 4 lines

Someone needs to know about the new guest to fetch its symbols. Or do you want that part in the kernel too?

How about we add a virtio "guest file system access" device? The guest would then expose its own file system using that device.

Quoted 8 lines
Quoted 5 lines

On the host side this would simply be a -virtioguestfs unix:/tmp/guest.fs and you'd get a unix socket that gives you full access to the guest file system by using commands. I envision something like:

The idea is to use a dedicated channel over virtio-serial. If the channel is present the file server can serve files over it.

The file server being a kernel module inside the guest? We want to be able to serve things as early and hassle free as possible, so in this case I agree with Ingo that a kernel module is superior.

Quoted 11 lines
Quoted 11 lines

SEND: GET /proc/version
RECV: Linux version 2.6.27.37-0.1-default (geeko@buildhost) (gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux) ) #1 SMP 2009-10-15 14:56:58 +0200

Now all we need is integration in perf to enumerate virtual machines based on libvirt. If you want to run qemu-kvm directly, just go with --guestfs=/tmp/guest.fs and perf could fetch all required information automatically.

Quoted 5 lines
Quoted 2 lines

This should solve all issues while staying 100% in user space, right?

Yeah, needs a fuse filesystem to populate the host namespace (kind of sshfs over virtio-serial).

I don't see why we need a fuse filesystem. We can of course create one later on. But for now all you need is a user connecting to that socket.

Alex

#274 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 18 lines · Alexander Graf
Quoted 16 lines · Avi Kivity
Quoted 14 lines · Alexander Graf
Quoted 5 lines

Someone needs to know about the new guest to fetch its symbols. Or do you want that part in the kernel too?

How about we add a virtio "guest file system access" device? The guest would then expose its own file system using that device.

On the host side this would simply be a -virtioguestfs unix:/tmp/guest.fs and you'd get a unix socket that gives you full access to the guest file system by using commands. I envision something like:

Quoted 7 lines
Quoted 3 lines

The idea is to use a dedicated channel over virtio-serial. If the channel is present the file server can serve files over it.

The file server being a kernel module inside the guest? We want to be able to serve things as early and hassle free as possible, so in this case I agree with Ingo that a kernel module is superior.

No, just a daemon. If it's important enough we can get distributions to package it by default, and then it will be hassle free. If "early enough" is also so important, we can get it to start up on initrd. If it's really critical, we can patch grub to serve the files as well.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

SEND: GET /proc/version
RECV: Linux version 2.6.27.37-0.1-default (geeko@buildhost) (gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux) ) #1 SMP 2009-10-15 14:56:58 +0200

Now all we need is integration in perf to enumerate virtual machines based on libvirt. If you want to run qemu-kvm directly, just go with --guestfs=/tmp/guest.fs and perf could fetch all required information automatically.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

This should solve all issues while staying 100% in user space, right?

Yeah, needs a fuse filesystem to populate the host namespace (kind of sshfs over virtio-serial).

I don't see why we need a fuse filesystem. We can of course create one later on. But for now all you need is a user connecting to that socket.

If the perf app knows the protocol, no problem. But leave perf with pure filesystem access and hide the details in fuse.

Signature · 1 line
error compiling committee.c: too many arguments to function
#275 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Joerg Roedel
Quoted 4 lines · Joerg Roedel

Sidenote: I really think we should come to a conclusion about the
concept. KVM integration into perf is very useful feature to analyze virtualization workloads.

Agreed. I especially would like to see instruction/branch tracing working this way. This would a lot of the benefits of a simulator on a real CPU.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#276 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 10 lines · Andi Kleen
Quoted 4 lines · Joerg Roedel

Sidenote: I really think we should come to a conclusion about the
concept. KVM integration into perf is very useful feature to
analyze virtualization workloads.

Agreed. I especially would like to see instruction/branch tracing working this way. This would a lot of the benefits of a simulator on a real CPU.

If you're profiling a single guest it makes more sense to do this from inside the guest - you can profile userspace as well as the kernel.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#277 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 2 lines

If you're profiling a single guest it makes more sense to do this from inside the guest - you can profile userspace as well as the kernel.

I'm interested in debugging the guest without guest cooperation.

In many cases qemu's new gdb stub works for that, but in some cases I would prefer instruction/branch traces over standard gdb style debugging.

I used to use that very successfully with simulators in the past for some hard bugs.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#278 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 9 lines · Andi Kleen
Quoted 3 lines

If you're profiling a single guest it makes more sense to do this from inside the guest - you can profile userspace as well as the kernel.

I'm interested in debugging the guest without guest cooperation.

In many cases qemu's new gdb stub works for that, but in some cases I would prefer instruction/branch traces over standard gdb style debugging.

Isn't gdb supposed to be able to use branch traces? It makes sense to expose them via the gdb stub then. Not to say an external tool doesn't make sense.

Signature · 1 line
error compiling committee.c: too many arguments to function
#279 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 4 lines · Avi Kivity
Quoted 3 lines · Andi Kleen
Quoted 3 lines

If you're profiling a single guest it makes more sense to do this from inside the guest - you can profile userspace as well as the kernel.

Quoted 8 lines
Quoted 6 lines

I'm interested in debugging the guest without guest cooperation.

In many cases qemu's new gdb stub works for that, but in some cases I would prefer instruction/branch traces over standard gdb style debugging.

Isn't gdb supposed to be able to use branch traces?

AFAIK not. The ptrace interface is only used by idb I believe. I might be wrong on that.

Not sure if there is even a remote protocol command for branch traces either.

There's a concept of "tracepoints" in the protocol, but it doesn't quite match at.

Quoted 3 lines

It makes sense to
expose them via the gdb stub then. Not to say an external tool doesn't make sense.

Ok that would work for me too. As long as I can set start/stop triggers and pipe the log somewhere it's fine for me.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#280 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 12 lines · Ingo Molnar
Quoted 6 lines · Avi Kivity
Quoted 2 lines · Ingo Molnar

This is why i consider that line of argument rather dishonest ...

I am not going to reply to any more email from you on this thread.

Because i pointed out that i consider a line of argument intellectually dishonest?

Quoted 8 lines

I did not say _you_ as a person are dishonest - doing that would be an ad honimen attack against your person. (In fact i dont think you are, to the contrary)

An argument can certainly be labeled dishonest in a fair discussion and it is not a personal attack against you to express my opinion about that.

Sigh, why am I drawn into this.

A person who uses dishonest arguments is a dishonest person. When you say I use a dishonest argument you are implying I am dishonest. Why do you argue with me at all if you think I am trying to cheat?

If you disagree with me, tell me I am wrong, not dishonest (or that my arguments are dishonest). And this is just one example in this thread. Seriously, tools/kvm would cause a loss of developers, not a gain, simply because of the style of argument of some people on this list. Maybe qemu/kernels is a better idea.

Again, if you want to talk to me, use the same language you'd like to hear yourself. Or maybe years of lkml made you so thick skinned you no longer understand how to interact with people.

Signature · 1 line
error compiling committee.c: too many arguments to function
#281 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 13 lines · Avi Kivity
Quoted 12 lines · Ingo Molnar
Quoted 3 lines · Avi Kivity
Quoted 1 line · Ingo Molnar

This is why i consider that line of argument rather dishonest ...

I am not going to reply to any more email from you on this thread.

Because i pointed out that i consider a line of argument intellectually dishonest?

I did not say _you_ as a person are dishonest - doing that would be an ad honimen attack against your person. (In fact i dont think you are, to the contrary)

Quoted 7 lines
Quoted 3 lines

An argument can certainly be labeled dishonest in a fair discussion and it is not a personal attack against you to express my opinion about that.

Sigh, why am I drawn into this.

A person who uses dishonest arguments is a dishonest person. [...]

That's not how i understood that phrase - and i did not mean to suggest that you are dishonest and i do not think that you are dishonest (to the contrary).

Thanks,

Ingo

#282 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 25 lines · Ingo Molnar
Quoted 22 lines · Avi Kivity
Quoted 20 lines · Ingo Molnar
Quoted 6 lines · Avi Kivity
Quoted 2 lines · Ingo Molnar

This is why i consider that line of argument rather dishonest ...

I am not going to reply to any more email from you on this thread.

Because i pointed out that i consider a line of argument intellectually dishonest?

I did not say _you_ as a person are dishonest - doing that would be an ad honimen attack against your person. (In fact i dont think you are, to the contrary)

An argument can certainly be labeled dishonest in a fair discussion and it is not a personal attack against you to express my opinion about that.

Quoted 7 lines
Quoted 4 lines

Sigh, why am I drawn into this.

A person who uses dishonest arguments is a dishonest person. [...]

That's not how i understood that phrase - and i did not mean to suggest that you are dishonest and i do not think that you are dishonest (to the contrary).

Word games.

Signature · 1 line
error compiling committee.c: too many arguments to function
maintainer
#283 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 6 lines · Avi Kivity

(btw, why are you interested in desktop-on-desktop? one use case is developers, which don't really need fancy GUIs; a second is people who test out distributions, but that doesn't seem to be a huge population; and a third is people running Windows for some application that doesn't run on Linux - hopefully a small catergory as well.

This third category is pretty well served by virt-manager. It has its quirks and shortcomings, but at least it exists.

Paolo

#284 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 10 lines · Avi Kivity
Quoted 10 lines

Consider the _other_ examples that are a lot more clear:

' If you expose paravirt spilocks via KVM please also make sure the KVM
tooling can make use of it, has an option for it to configure it, and that it has sufficient efficiency statistics displayed in the tool for admins to monitor.'

' If you create this new paravirt driver then please also make sure it can
be configured in the tooling. '

Quoted 6 lines
Quoted 2 lines

' Please also add a testcase for this bug to tools/kvm/testcases/ so we dont
repeat this same mistake in the future. '

All three happen quite commonly in qemu/kvm development. Of course someone who develops a feature also develops a patch that exposes it in qemu. There are several test cases in qemu-kvm.git/kvm/user/test.

If that is the theory then it has failed to trickle through in practice. As you know i have reported a long list of usability problems with hardly a look. That list could be created by pretty much anyone spending a few minutes of getting a first impression with qemu-kvm.

So something is seriously wrong in KVM land, to pretty much anyone trying it for the first time. I have explained how i see the root cause of that, while you seem to suggest that there's nothing wrong to begin with. I guess we'll have to agree to disagree on that.

Thanks,

Ingo

#285 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 5 lines · Ingo Molnar

If that is the theory then it has failed to trickle through in practice. As you know i have reported a long list of usability problems with hardly a look. That list could be created by pretty much anyone spending a few minutes of getting a first impression with qemu-kvm.

I think the point you're missing is that your list was from the perspective of someone looking at a desktop virtualization solution that had was graphically oriented.

As Avi has repeatedly mentioned, so far, that has not been the target audience of QEMU. The target audience tends to be: 1) people looking to do server virtualization and 2) people looking to do command line based development.

Usually, both (1) and (2) are working on machines that are remotely located. What's important to these users is that VMs be easily launchable from the command line, that there is a lot of flexibility in defining machine types, and that there is a programmatic way to interact with a given instance of QEMU. Those are the things that we've been focusing on recently.

The reason we don't have better desktop virtualization support is simple. No one is volunteering to do it and no company is funding development for it.

When you look at something like VirtualBox, what you're looking at is a long ago forked version of QEMU with a GUI added focusing on desktop virtualization.

There is no magic behind adding a better, more usable GUI to QEMU. It just takes resources.

I understand that you're trying to make the point that without catering to the desktop virtualization use case, we won't get as many developers as we could. Personally, I don't think that argument is accurate. If you look at VirtualBox, it's performance is terrible. Having a nice GUI hasn't gotten them the type of developers that can improve their performance.

No one is arguing that we wouldn't like to have a nicer UI. I'd love to merge any patch like that.

Regards,

Anthony Liguori

#286 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

If that is the theory then it has failed to trickle through in practice. As you know i have reported a long list of usability problems with hardly a look. That list could be created by pretty much anyone spending a few minutes of getting a first impression with qemu-kvm.

Can you transfer your list to the following wiki page:

http://wiki.qemu.org/Features/Usability

This thread is so large that I can't find your note that contained the initial list.

I want to make sure this input doesn't die once this thread settles down.

Regards,

Anthony Liguori

#287 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 16 lines · Ingo Molnar
Quoted 13 lines · Avi Kivity
Quoted 13 lines

Consider the _other_ examples that are a lot more clear:

' If you expose paravirt spilocks via KVM please also make sure the KVM
tooling can make use of it, has an option for it to configure it, and that it has sufficient efficiency statistics displayed in the tool for admins to monitor.'

' If you create this new paravirt driver then please also make sure it can
be configured in the tooling. '

' Please also add a testcase for this bug to tools/kvm/testcases/ so we dont
repeat this same mistake in the future. '

Quoted 9 lines
Quoted 4 lines

All three happen quite commonly in qemu/kvm development. Of course someone who develops a feature also develops a patch that exposes it in qemu. There are several test cases in qemu-kvm.git/kvm/user/test.

If that is the theory then it has failed to trickle through in practice. As you know i have reported a long list of usability problems with hardly a look. That list could be created by pretty much anyone spending a few minutes of getting a first impression with qemu-kvm.

It does happen in practice, just not in the GUI areas, since no one is working on them. I am not going to condition a qcow2 reliability fix to a gtk GUI.

Quoted 5 lines

So something is seriously wrong in KVM land, to pretty much anyone trying it for the first time. I have explained how i see the root cause of that, while you seem to suggest that there's nothing wrong to begin with. I guess we'll have to agree to disagree on that.

Not anyone trying it for the first time. RHEV-M users will see a polished GUI that can be used to manage thousands of guests and hosts. I presume IBM and Siemens (and all other contributors) users will also enjoy a good user experience with their respective products. Qemu is not the only GUI for kvm.

So far only one company was interested in a qemu GUI - the makers of virtualbox. Unfortunately they chose not to contribute that back to qemu, and no one was sufficiently motivated to pick out the bits and try to merge them.

Again, if you are interested in a qemu GUI, you either have to write it yourself or convince someone else to do it. My own plate is full and my priorities are clear.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#288 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Anthony Liguori
Quoted 26 lines · Anthony Liguori
Quoted 18 lines · Ingo Molnar
Quoted 17 lines · Anthony Liguori
Quoted 16 lines · Ingo Molnar
Quoted 3 lines

[...] kvm in fact knows nothing about vga, to take your last example. [...]

Look at the VGA dirty bitmap optimization a'ka the KVM_GET_DIRTY_LOG ioctl.

See qemu/kvm-all.c's kvm_physical_sync_dirty_bitmap().

It started out as a VGA optimization (also used by live migration) and even today it's mostly used by the VGA drivers - albeit a weak one.

I wish there were stronger VGA optimizations implemented, copying the dirty bitmap is not a particularly performant solution. (although it's certainly better than full emulation) Graphics performance is one of the more painful aspects of KVM usability today.

Quoted 6 lines
Quoted 5 lines

We have to maintain a dirty bitmap because we don't have a paravirtual graphics driver. IOW, someone needs to write an Xorg driver.

Ideally, we could just implement a Linux framebuffer device, right?

No, you'd want to interact with DRM.

Quoted 8 lines

Using DRM doesn't help very much. You still need an X driver and most of the operations you care about (video rendering, window movement, etc) are not operations that need to go through DRM.

3D graphics virtualization is extremely difficult in the non-passthrough case. It really requires hardware support that isn't widely available today (outside a few NVIDIA chipsets).

Implementing a virtualized DRM/KMS driver would at least get you the framebuffer interface more or less for free, while allowing you to deal with the userspace side of things incrementally (ie, running a dummy xorg on top of the virtualized fbdev until the DRI side catches up). It would also enable you to focus on the 2D and 3D parts independently.

Quoted 5 lines

It doesn't provide the things we need to a good user experience. You need things like an absolute input device, host driven display resize, RGBA hardware cursors. None of these go through DRI and it's those things that really provide the graphics user experience.

None of these things negate the benefit one would get from a virtualized DRM/KMS driver either. There are multiple problems that need solving in this area, and it's a bit disingenuous to discount a valid suggestion out of hand due to the fact it doesn't solve all of the outstanding issues.

#289 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 5 lines · Paul Mundt

Implementing a virtualized DRM/KMS driver would at least get you the framebuffer interface more or less for free, while allowing you to deal with the userspace side of things incrementally (ie, running a dummy xorg on top of the virtualized fbdev until the DRI side catches up). It would also enable you to focus on the 2D and 3D parts independently.

Guys, have a look at Gallium. In many ways it's a pile of crap, but at least it's a pile of crap designed by vmware for *exactly* your problem space.

OG.

#290 lore raw

Re: [LKML] Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 10 lines · Olivier Galibert
Quoted 5 lines · Paul Mundt

Implementing a virtualized DRM/KMS driver would at least get you the framebuffer interface more or less for free, while allowing you to deal with the userspace side of things incrementally (ie, running a dummy xorg on top of the virtualized fbdev until the DRI side catches up). It would also enable you to focus on the 2D and 3D parts independently.

Guys, have a look at Gallium. In many ways it's a pile of crap, but at least it's a pile of crap designed by vmware for *exactly* your problem space.

Or perhaps Chromium, which was designed years ago and can pass-through OpenGL commands via a pipe. VirtualBox uses it for their PV drivers. Naturally it is not a FB, just a OpenGL command pass-through interface.

#291 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 15 lines · Ingo Molnar
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Ingo Molnar
Quoted 7 lines · Avi Kivity
Quoted 5 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Why is that?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

It's not inevitable, if the projects are badly run, you'll have high latencies, but projects don't have to be badly run.

So the 64K dollar question is, why does Qemu still suck?

Why does Linux AIO still suck? Why do we not have a proper interface in userspace for doing asynchronous file system operations?

Why don't we have an interface in userspace to do zero-copy transmit and receive of raw network packets?

The lack of a decent userspace API for asynchronous file system operations is a huge usability problem for us. Take a look at the complexity of our -drive option. It's all because the kernel gives us sucky interfaces.

Regards,

Anthony Liguori

#292 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 11 lines · Anthony Liguori
Quoted 10 lines · Ingo Molnar
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Ingo Molnar
Quoted 5 lines · Avi Kivity
Quoted 4 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Why is that?

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

It's not inevitable, if the projects are badly run, you'll have high latencies, but projects don't have to be badly run.

So the 64K dollar question is, why does Qemu still suck?

Why does Linux AIO still suck? Why do we not have a proper interface in userspace for doing asynchronous file system operations?

Good that you mention it, i think it's an excellent example.

The suckage of kernel async IO is for similar reasons: there's an ugly package separation problem between the kernel and between glibc - and between the apps that would make use of it.

( With the separated libaio it was made worse: there were 3 libraries to
work with, and even less applications that could make use of it ... )

So IMO klibc is an arguably good idea - eventually hpa will get around posting it for upstream merging again. Then we could offer both new libraries much faster, and could offer things like comprehensive AIO used pervasively within existing APIs.

Quoted 6 lines

Why don't we have an interface in userspace to do zero-copy transmit and receive of raw network packets?

The lack of a decent userspace API for asynchronous file system operations is a huge usability problem for us. Take a look at the complexity of our -drive option. It's all because the kernel gives us sucky interfaces.

If you had your bits in tools/kvm/ you could make a strong case for a good kaio implementation - coupled with an actual, working use-case. ( You could use the raw syscall even without klibc. )

We could see the arguments on lkml turn from:

'do we want this and it will take years to propagate this into apps'

into something like:

' Exactly how much faster does kvm go? and I'd get is straight away with my
next kernel update tomorrow? Wow! '

Ok, i exaggerated a bit - but you get the idea. It's a much different picture when kernel developers and maintainers see an actual use-case, _right in the kernel repo they work with every day_.

Currently there's a wall between kernel developers and user-space developers, and there's somewhat of an element of fear and arrogance on both sides. For efficient technology such walls needs torn down and people need a bit more experience with each other's areas.

Ingo

#293 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 5 lines · Ingo Molnar

Currently there's a wall between kernel developers and user-space developers, and there's somewhat of an element of fear and arrogance on both sides. For efficient technology such walls needs torn down and people need a bit more experience with each other's areas.

I think you're increasing the height of that wall by arguing that a userspace project cannot be successful because it's development process sucks and the only way to fix it is to put it into the kernel where people know so much better. Instead we kernel developers should listen to requirements from users, even if their code isn't in tools/.

Signature · 1 line
error compiling committee.c: too many arguments to function
#294 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 7 lines · Avi Kivity
Quoted 4 lines · Ingo Molnar

Currently there's a wall between kernel developers and user-space developers, and there's somewhat of an element of fear and arrogance on both sides. For efficient technology such walls needs torn down and people need a bit more experience with each other's areas.

Quoted 5 lines

I think you're increasing the height of that wall by arguing that a userspace project cannot be successful because it's development process sucks and the only way to fix it is to put it into the kernel where people know so much better. Instead we kernel developers should listen to requirements from users, even if their code isn't in tools/.

No, it's tearing down that wall because finally, instead of providing rather abstract system calls that are designed perfectly, the kernel can operate by providing useful libraries and apps.

At least on the context i've worked on it has torn down walls and has improved the efficiency of working on ABIs towards user-space. (sysprof is an example of that)

Kernel developers are finally faced with user-space development directly, in the same repository, using the same rules of contribution.

Non-kernel-hosted apps win from that process too, as even if they dont integrate (because they dont want to or cannot for license reasons) they can participate in a more direct (and more practical) exchange with kernel developers. They can contribute a new system call and create a library function for it straight away.

Ingo

#295 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

Good that you mention it, i think it's an excellent example.
The suckage of kernel async IO is for similar reasons: there's an ugly package separation problem between the kernel and between glibc - and between the apps that would make use of it.

Quoted 8 lines

( With the separated libaio it was made worse: there were 3 libraries to
work with, and even less applications that could make use of it ... )

So IMO klibc is an arguably good idea - eventually hpa will get around posting it for upstream merging again. Then we could offer both new libraries much faster, and could offer things like comprehensive AIO used pervasively within existing APIs.

And why wouldn't the kernel developers produce posix-aio within klibc.

posix-aio is also a really terrible interface (although not as bad as linux-aio).

The reason boils down to the fact that these interfaces are designed without interacting with the consumers. Part of the reason for that is the attitude of the community.

You approached this discussion with, "QEMU/KVM sucks, you should move into the kernel because we're awesome and we'd fix everything in a heart beat". That attitude does not result in any useful collaboration.

Had you started trying to understand what the problems that we face are and whether there's anything that can be done in the kernel to improve it, it would have been an entirely different discussion.

The sad thing is, QEMU is probably one of the most demanding free software applications out there today with respect to performance. We consume interfaces IO interfaces and things like large pages in a deeper way than just about any application out there.

We've been trying for a long time to improve Linux interfaces for years but we've not had many people in the kernel community be receptive.

We've failed to improve the userspace networking interfaces. Compare Rusty's posting of vringfd to vhost-net. They are the same interface except we tried to do something more generally useful with vringfd and it was shot down because it was "yet another kernel/userspace data transfer interface". Unfortunately, we're learning that if we claim something is virtualization specific, we avoid a lot of the kernel bureaucracy. My concern is that over time, we'll have more things like vhost and that's bad for everyone.

Regards,

Anthony Liguori

#296 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 2 lines · Ingo Molnar

The suckage of kernel async IO is for similar reasons: there's an ugly package separation problem between the kernel and between glibc

Bollocks. glibc would use (and is using) everything the kernel provides. We even have an implementation using the current AIO code. It only works in some situations but that's what the few users are OK with.

Don't try to blame anyone but kernel people for the complete and utter failure of AIO in Linux. I don't know how often I've discussed design of a kernel interface with various kernel developers. Heck, whenever Zach Brown and I meet there never is a different topic. And following these meetings the ball is not and cannot be in my court. How could it?

#297 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 6 lines · * [email protected] <[email protected]> wrote:
Quoted 2 lines · Ingo Molnar

The suckage of kernel async IO is for similar reasons: there's an ugly package separation problem between the kernel and between glibc

Bollocks. glibc would use (and is using) everything the kernel provides.

I didnt say it's glibc's fault - if then it's more of the kernel's fault as most of the complexity is on that side. I said it's due to the fundamental distance between the app that makes use of it, the library and the kernel, and the resulting difficulties in getting a combined solution out.

None of the parties really feels it to be their own thing.

Ingo

#298 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 4 lines · Ingo Molnar

I didnt say it's glibc's fault - if then it's more of the kernel's fault as most of the complexity is on that side. I said it's due to the fundamental distance between the app that makes use of it, the library and the kernel, and the resulting difficulties in getting a combined solution out.

This is wrong, too. Once there is a kernel patch that has a reasonable syscall interface it's easy enough to hack up the glibc side. Don't try to artificially find an argument to support your thesis. If kernel developers always need an immediate itch which lives inside the kernel walls to make a change this is a failure of the kernel model and mustn't be "solved" by dragging ever more code into the kernel.

Aside, you don't need a full-fledged glibc implementation for testing. Especially for AIO it should be usable in much lighter-weight contexts than POSIX AIO. These wrappers are even more easy to hack up (and have been in the few cases where some code has been produced).

For AIO the situation isn't that the people interested in working on it don't know or care about the use. Zach (through Oracle's products) is very much interested in the code and knows how it should look like.

Face it, AIO is an example of a complete failure of the kernel developers to provide something usable. This was the argument and where you started the misdirection of including other projects in the reasoning.

#299 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 10 lines · * [email protected] <[email protected]> wrote:
Quoted 5 lines · Ingo Molnar

I didnt say it's glibc's fault - if then it's more of the kernel's fault as most of the complexity is on that side. I said it's due to the fundamental distance between the app that makes use of it, the library and the kernel, and the resulting difficulties in getting a combined solution out.

This is wrong, too. Once there is a kernel patch that has a reasonable syscall interface it's easy enough to hack up the glibc side. [...]

Where 'reasonable' is defined by you, right?

As i said, the KAIO situation is mostly the kernel's fault, but you are a pretty passive and unhelpful entity in this matter too, arent you?

For example, just to state the obvious: libaio has been written 8 years ago in 2002 and has been used in apps early on. Why arent those kernel APIs, while not being a full/complete solution, supported by glibc, and wrapped to pthreads based emulation on kernels that dont support it?

I'm not talking about a 100% full POSIX AIO implementation (the kernel side is not complete enough for that) - i'm just talking about the APIs that libaio and the kernel supports today.

Why isnt glibc itself making use of those AIO capabilities internally? (even if it's not possible to support full POSIX AIO)

I checked today's glibc repo, and there's no sign of any of that:

glibc> git grep io_submit
glibc> git grep aio_context_t
glibc>

Zero, nil, nada.

Getting _something_ into glibc would certainly help move the situation. Glibc itself using existing KAIO bits internally would help too and dont tell me it's 100% unusable: it's certainly capable enough to run DB servers. glibc using it would create further demand (and pressure, and incentives) for improvements.

There were even glibc patches created by Ben LaHaise for some of these bits, IIRC.

One can certainly make the argument that glibc not using _any_ of the current KAIO capabilities harms its further development.

Quoted 1 line

[...] Don't try to artificially find an argument to support your thesis.

Charming argumentation style, i really missed it.

Thanks,

Ingo

#300 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 1 line · Ingo Molnar

Where 'reasonable' is defined by you, right?

Not only by me. For some of the AIO approaches which happened there were also glibc patches other people wrote. It's pretty simple.

Quoted 2 lines

As i said, the KAIO situation is mostly the kernel's fault, but you are a pretty passive and unhelpful entity in this matter too, arent you?

How'd you guess? I've always been been willing to discuss interface requirements with whoever showed interest in implementing things. Again, ask Zach. I think Christoph Lameter also was involved as were various SGI people over the years.

Short of actually doing all the work myself I've done what can be expected.

Quoted 4 lines

For example, just to state the obvious: libaio has been written 8 years ago in 2002 and has been used in apps early on. Why arent those kernel APIs, while not being a full/complete solution, supported by glibc, and wrapped to pthreads based emulation on kernels that dont support it?

You never looked at the glibc code in use and didn't read what I wrote before. We do have an implementation of libaio using those interfaces. They exist in the Fedora/RHEL glibc and are probably copied elsewhere, too. The code is not upstream because it is not general enough. It simply doesn't work in all situations.

The problem with using it (among others) is that certain operations cannot be implemented. And that's not a kernel interface problem. I cannot just switch to using the pthread-based code when coming across something that's not implementable because then the requests have already been sent to the kernel. Only code that knows about the limitations ahead of time can use the KAIO code.

Quoted 2 lines

Why isnt glibc itself making use of those AIO capabilities internally? (even if it's not possible to support full POSIX AIO)

For what? glibc doesn't implement anything requiring AIO. The only non-trivial file handling is in nscd and nscd uses memory mapped files.

Quoted 1 line

I checked today's glibc repo, and there's no sign of any of that:

Check the Fedora/RHEL/... source files.

Quoted 1 line

Getting _something_ into glibc would certainly help move the situation.

No it won't as the 7+ since Jakub wrote the code nothing came out of it. And before you again make groundless claims, there was plenty of discussions with kernel people at the time when the code was written.

Quoted 3 lines

it's certainly capable enough to run DB servers. glibc
using it would create further demand (and pressure, and incentives) for improvements.

There simply is no need for AIO in glibc internally. Well, there might be, if it could be used on sockets. But that's not the case.

Quoted 1 line

Charming argumentation style, i really missed it.

Well, then this last mail should show you. Without knowing the subject matter, just based on flawed lookups you try to spread the blame to make sure that no mud ever sticks to development process you are so fond of. Sorry to disappoint you.

#301 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 10 lines · * [email protected] <[email protected]> wrote:
Quoted 4 lines

For example, just to state the obvious: libaio has been written 8 years ago in 2002 and has been used in apps early on. Why arent those kernel APIs, while not being a full/complete solution, supported by glibc, and wrapped to pthreads based emulation on kernels that dont support it?

You never looked at the glibc code in use and didn't read what I wrote before. We do have an implementation of libaio using those interfaces. They exist in the Fedora/RHEL glibc and are probably copied elsewhere, too. The code is not upstream because it is not general enough. It simply doesn't work in all situations.

So it's good enough to be in Fedora/RHEL but not good enough to be in upstream glibc? How is that possible? Isnt that a double standard?

Upstream libc presence is really what is needed for an API to be ubiquitous to apps. That is what 'closes the loop' in the the positive feedback cycle loop and creates real back pressure and demand on the kernel to get its act together.

Again, i state it for the third time, the KAIO situation is mostly the kernel's fault. But glibc is certainly not being helpful in that situation either and your earlier claim that you are only waiting for the patches is rather dishonest.

Thanks,

Ingo

#302 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 2 lines

So it's good enough to be in Fedora/RHEL but not good enough to be in upstream glibc? How is that possible? Isnt that a double standard?

Yes its a double standard

Glibc has a higher standard than Fedora/RHEL.

Just like the Ubuntu kernel ships various ugly unfit for upstream kernel drivers.

Quoted 3 lines

kernel's fault. But glibc is certainly not being helpful in that situation either and your earlier claim that you are only waiting for the patches is rather dishonest.

I am sure Ulrich is being totally honest, but send him the patches and you'll find out. Plus you will learn what the API should look like when you try and create them ...

Alan

#303 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 9 lines · Alan Cox
Quoted 2 lines

So it's good enough to be in Fedora/RHEL but not good enough to be in upstream glibc? How is that possible? Isnt that a double standard?

Yes its a double standard

Glibc has a higher standard than Fedora/RHEL.

Just like the Ubuntu kernel ships various ugly unfit for upstream kernel drivers.

There's a world of a difference between a fugly driver and a glibc patch.

Also, we tend to upstream even fugly kernel drivers if they are important and are deployed by a major distro - see Noveau.

Quoted 7 lines
Quoted 3 lines

kernel's fault. But glibc is certainly not being helpful in that situation either and your earlier claim that you are only waiting for the patches is rather dishonest.

I am sure Ulrich is being totally honest, but send him the patches and you'll find out. Plus you will learn what the API should look like when you try and create them ...

I was there and extended/fixed bits of the kaio/libaio code when they were written so yes i already know something about it. To say that the glibc reaction was less than enthusiastic back then is a strong euphemism ;-)

So after 8 years some of the bits made its way into Fedora/RHEL.

I think this is a pretty good demonstration of the points i made ;-)

Thanks,

Ingo

#304 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 11 lines · Ingo Molnar
Quoted 8 lines

Yes its a double standard

Glibc has a higher standard than Fedora/RHEL.

Just like the Ubuntu kernel ships various ugly unfit for upstream kernel drivers.

There's a world of a difference between a fugly driver and a glibc patch.

Yes, fugly drivers can be cleaned up, but glibc ABIs are forever.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#305 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 8 lines · Ingo Molnar
Quoted 2 lines

Why does Linux AIO still suck? Why do we not have a proper interface in userspace for doing asynchronous file system operations?

Good that you mention it, i think it's an excellent example.

The suckage of kernel async IO is for similar reasons: there's an ugly package separation problem between the kernel and between glibc - and between the apps that would make use of it.

No, kernel async IO sucks because it still does not play well with buffered I/O. Last time I checked (about a year ago or so), AIO syscall latencies were much worse when buffered I/O was used compared to direct I/O. Unfortunately, to achieve good performance with direct I/O, you need a HW RAID card with lots of on-board cache.

Gabor

#306 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 10 lines · Ingo Molnar
Quoted 7 lines · Avi Kivity
Quoted 5 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Why is that?

Quoted 9 lines

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

If you ever tried to implement a combo GCC+glibc+kernel feature you'll know
...

Even with the best-run projects in existence it takes forever and is very painful - and here i talk about first hand experience over many years.

Ingo, what you miss is that this is not a bad thing. Fact of the matter is, it's not just painful, it downright sucks.

This is actually a Good Thing (tm). It means you have to get your feature and its interfaces well defined and able to version forwards and backwards independently from each other. And that introduces some complexity and time and testing, but in the end it's what you want. You don't introduce a requirement to have the feature, but take advantage of it if it is there.

It may take everyone else a couple years to upgrade the compilers, tools, libraries and kernel, and by that time any bugs introduced by interacting with this feature will have been ironed out and their patterns well known.

If you haven't well defined and carefully thought out the feature ahead of time, you end up creating a giant mess, possibly the need for nasty backwards compatibility (case in point: COMPAT_VDSO). But in the end, you would have made those same mistakes on your internal tree anyway, and then you (or likely, some other hapless project maintainer for the project you forked) would have to go add the features, fixes and workarounds back to the original project(s). However, since you developed in an insulated sheltered environment, those fixes and workarounds would not be robust and independently versionable from each other.

The result is you've kept your codebase version-neutral, forked in outside code, enhanced it, and left the hard work of backporting those changes and keeping them version-safe to the original package maintainers you forked from. What you've created is no longer a single project, it is called a distro, and you're being short-sighted and anti-social to think you can garner more support than all of those individual packages you forked. This is why most developers work upstream and let the goodness propagate down from the top like molten sugar of each granular package on a flan where it is collected from the rich custard channel sitting on a distribution plate below before the big hungry mouth of the consumer devours it and incorporates it into their infrastructure.

Or at least, something like that, until the last sentence. In short, if project A has Y active developers, you better have Z >> Y active developers to throw at project A when you fork it into project B.

Zach

#307 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 11 lines · Zachary Amsden
Quoted 10 lines · Ingo Molnar
Quoted 5 lines · Avi Kivity
Quoted 4 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Why is that?

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

Quoted 8 lines
Quoted 5 lines

If you ever tried to implement a combo GCC+glibc+kernel feature you'll know
...

Even with the best-run projects in existence it takes forever and is very painful - and here i talk about first hand experience over many years.

Ingo, what you miss is that this is not a bad thing. Fact of the matter is, it's not just painful, it downright sucks.

Our experience is the opposite, and we tried both variants and report about our experience with both models honestly.

You only have experience about one variant - the one you advocate.

See the assymetry?

Quoted 11 lines

This is actually a Good Thing (tm). It means you have to get your feature and its interfaces well defined and able to version forwards and backwards independently from each other. And that introduces some complexity and time and testing, but in the end it's what you want. You don't introduce a requirement to have the feature, but take advantage of it if it is there.

It may take everyone else a couple years to upgrade the compilers, tools, libraries and kernel, and by that time any bugs introduced by interacting with this feature will have been ironed out and their patterns well known.

Sorry, but this is pain not true. The 2.4->2.6 kernel cycle debacle has taught us that waiting long to 'iron out' the details has the following effects:

- developer pain
- user pain
- distro pain
- disconnect
- loss of developers, testers and users
- grave bugs discovered months (years ...) down the line
- untested features
- developer exhaustion

It didnt work, trust me - and i've been around long enough to have suffered through the whole 2.5.x misery. Some of our worst ABIs come from that cycle as well.

So we first created the 2.6.x process, then as we saw that it worked much better we _sped up_ the kernel development process some more, to what many claimed was an impossible, crazy pace: two weeks merge window, 2.5 months stabilization and a stable release every 3 months.

And you can also see the countless examples of carefully drafted, well thought out, committee written computer standards that were honed for years, which are not worth the paper they are written on.

'extra time' and 'extra buerocratic overhead to think things through' is about the worst thing you can inject into a development process.

You should think about the human brain as a cache - the 'closer' things are both in time and pyshically, the better they end up being. Also, the more gradual, the more concentrated a thing is, the better it works out in general. This is part of the basic human nature.

Sorry, but i really think you are really trying to rationalize a disadvantage here ...

Ingo

#308 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 59 lines · Ingo Molnar
Quoted 15 lines · Zachary Amsden
Quoted 13 lines · Ingo Molnar
Quoted 7 lines · Avi Kivity
Quoted 5 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Why is that?

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

Quoted 9 lines
Quoted 6 lines

If you ever tried to implement a combo GCC+glibc+kernel feature you'll know
...

Even with the best-run projects in existence it takes forever and is very painful - and here i talk about first hand experience over many years.

Ingo, what you miss is that this is not a bad thing. Fact of the matter is, it's not just painful, it downright sucks.

Our experience is the opposite, and we tried both variants and report about our experience with both models honestly.

You only have experience about one variant - the one you advocate.

See the assymetry?

Quoted 7 lines

This is actually a Good Thing (tm). It means you have to get your feature and its interfaces well defined and able to version forwards and backwards independently from each other. And that introduces some complexity and time and testing, but in the end it's what you want. You don't introduce a requirement to have the feature, but take advantage of it if it is there.

Quoted 5 lines

It may take everyone else a couple years to upgrade the compilers, tools, libraries and kernel, and by that time any bugs introduced by interacting with this feature will have been ironed out and their patterns well known.

Sorry, but this is pain not true. The 2.4->2.6 kernel cycle debacle has taught us that waiting long to 'iron out' the details has the following effects:

- developer pain
- user pain
- distro pain
- disconnect
- loss of developers, testers and users
- grave bugs discovered months (years ...) down the line
- untested features
- developer exhaustion

Quoted 4 lines

It didnt work, trust me - and i've been around long enough to have suffered through the whole 2.5.x misery. Some of our worst ABIs come from that cycle as well.

You're talking about a single project and comparing it to my argument about multiple independent projects. In that case, I see no point in the discussion. If you want to win the argument by strawman, you are welcome to do so.

Quoted 3 lines

Sorry, but i really think you are really trying to rationalize a disadvantage here ...

This could very well be true, but until someone comes forward with compelling numbers (as in, developers committed to working on the project, number of patches and total amount of code contribution), there is no point in having an argument, there really isn't anything to discuss other than opinion. My opinion is you need a really strong justification to have a successful fork and I don't see that justification.

Zach

#309 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 51 lines · Zachary Amsden
Quoted 50 lines · Ingo Molnar
Quoted 11 lines · Zachary Amsden
Quoted 10 lines · Ingo Molnar
Quoted 5 lines · Avi Kivity
Quoted 4 lines

The moment any change (be it as trivial as fixing a GUI detail or as complex as a new feature) involves two or more packages, development speed slows down to a crawl - while the complexity of the change might be very low!

Why is that?

It's very simple: because the contribution latencies and overhead compound, almost inevitably.

Quoted 7 lines
Quoted 5 lines

If you ever tried to implement a combo GCC+glibc+kernel feature you'll know
...

Even with the best-run projects in existence it takes forever and is very painful - and here i talk about first hand experience over many years.

Ingo, what you miss is that this is not a bad thing. Fact of the matter is, it's not just painful, it downright sucks.

Our experience is the opposite, and we tried both variants and report about our experience with both models honestly.

You only have experience about one variant - the one you advocate.

See the assymetry?

Quoted 11 lines

This is actually a Good Thing (tm). It means you have to get your feature and its interfaces well defined and able to version forwards and backwards independently from each other. And that introduces some complexity and time and testing, but in the end it's what you want. You don't introduce a requirement to have the feature, but take advantage of it if it is there.

It may take everyone else a couple years to upgrade the compilers, tools, libraries and kernel, and by that time any bugs introduced by interacting with this feature will have been ironed out and their patterns well known.

Sorry, but this is pain not true. The 2.4->2.6 kernel cycle debacle has taught us that waiting long to 'iron out' the details has the following effects:

- developer pain
- user pain
- distro pain
- disconnect
- loss of developers, testers and users
- grave bugs discovered months (years ...) down the line
- untested features
- developer exhaustion

Quoted 8 lines
Quoted 3 lines

It didnt work, trust me - and i've been around long enough to have suffered through the whole 2.5.x misery. Some of our worst ABIs come from that cycle as well.

You're talking about a single project and comparing it to my argument about multiple independent projects. In that case, I see no point in the discussion. If you want to win the argument by strawman, you are welcome to do so.

The kernel is a very complex project with many ABI issues, so all those arguments apply to it as well. The description you gave:

 | This is actually a Good Thing (tm).  It means you have to get your feature 
 | and its interfaces well defined and able to version forwards and backwards 
 | independently from each other.  And that introduces some complexity and 
 | time and testing, but in the end it's what you want.  You don't introduce a 
 | requirement to have the feature, but take advantage of it if it is there.

matches the kernel too. We have many such situations. (Furthermore, the tools/perf/ situation, which relates to ABIs and user-space/kernel-space interactions is similar as well.)

Do you still think i'm making a straw-man argument?

Quoted 9 lines
Quoted 2 lines

Sorry, but i really think you are really trying to rationalize a disadvantage here ...

This could very well be true, but until someone comes forward with compelling numbers (as in, developers committed to working on the project, number of patches and total amount of code contribution), there is no point in having an argument, there really isn't anything to discuss other than opinion. My opinion is you need a really strong justification to have a successful fork and I don't see that justification.

I can give you rough numbers for tools/perf - if that counts for you.

For the first four months of its existence, when it was a separate project, i had a single external contributor IIRC.

The moment it went into the kernel repo the number of contributors and contributions skyrocketed and basically all contributions were top-notch. We are at 60+ separate contributors now (after about 8 months upstream) - which is still small compared to the kernel or to Qemu, but huge for a relatively isolated project like instrumentation.

So in my estimation tools/kvm/ would certainly be popular. Whether it would be more popular than current Qemu is hard to tell - it would be pure speculation.

Any reliable numbers for the other aspect, whether a split project creates a more fragile and less developed ABI would be extremely hard to get. I believe it to be true, but that's my opinion based on my experience with other projects, extrapolated to KVM/Qemu.

Anyway, the issue is moot as there's clear opposition to the unification idea.

Too bad - there was heavy initial opposition to the arch/x86 unification as well [and heavy opposition to tools/perf/ as well], still both worked out extremely well :-)

Ingo

#310 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 5 lines · Ingo Molnar

Too bad - there was heavy initial opposition to the arch/x86 unification as well [and heavy opposition to tools/perf/ as well], still both worked out extremely well :-)

Did you forget that arch/x86 was a merging of a code fork that happened several years previously? Maybe that fork shouldn't have been done to begin with.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#311 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 10 lines · Avi Kivity
Quoted 5 lines · Ingo Molnar

Too bad - there was heavy initial opposition to the arch/x86 unification as well [and heavy opposition to tools/perf/ as well], still both worked out extremely well :-)

Did you forget that arch/x86 was a merging of a code fork that happened several years previously? Maybe that fork shouldn't have been done to begin with.

We discussed and probably timidly tried to share the sharable initially but we realized it was too time wasteful. In addition to having to adapt the code to 64bit we would also had to constantly solve another problem on top of it (see the various split on _32/_64, those takes time to achieve, maybe not huge time but still definitely some time and effort). Even in retrospect I am quite sure the way x86-64 happened was optimal and if we would go back we would do it again the exact same way even if the final object was to have a common arch/x86 (and thankfully Linus is flexible and smart enough to realize that code that isn't risking to destabilize anything shouldn't be forced out just because it's not to a totally theoretical-perfect-nitpicking-clean-state yet). It's still a lot of work do the unification later as a separate task, but it's not like if we did it immediately it would have been a lot less work. It's about the same amount of effort and we were able to defer it for later and decrease the time to market which surely has contributed to the success of x86-64.

Problem of qemu is not some lack of GUI or that it's not included in the linux kernel git tree, the definitive problem is how to merge qemu-kvm/kvm and qlx into it. If you (Avi) were the qemu maintainer I am sure there wouldn't two trees so as a developer I would totally love it, and I am sure that with you as maintainer it would have a chance to move forward with qlx on desktop virtualization without proposing to extend vnc instead to achieve a "similar" result (imagine if btrfs is published on a website and people starts to discuss if it should ever be merged ever because reinventing some part of btrfs inside ext5 might achieve ""similar"" results).

About a GUI for KVM to use on desktop distributions, that is an irrelevant concern compared to the lack of protocol more efficient than rdesktop/rdp/vnc for desktop virtualization. I've people asking me to migrate hundreds of desktops to desktop virtualization on KVM in their organizations and I tell them to use spice because I believe it's the most efficient option available (at least as far as we stick to open source open protocols), there are universities using spice on thousand of student desktops, and I think we need paravirt graphics to happen ASAP in the main qemu tree too.

In short: running KVM on the desktop is irrelevant compared to running the desktop on KVM so I suggest to focus on what is more important first ;).

Thanks,
Andrea

#312 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 22 lines · Andrea Arcangeli
Quoted 11 lines · Avi Kivity
Quoted 5 lines · Ingo Molnar

Too bad - there was heavy initial opposition to the arch/x86 unification as well [and heavy opposition to tools/perf/ as well], still both worked out extremely well :-)

Did you forget that arch/x86 was a merging of a code fork that happened several years previously? Maybe that fork shouldn't have been done to begin with.

We discussed and probably timidly tried to share the sharable initially but we realized it was too time wasteful. In addition to having to adapt the code to 64bit we would also had to constantly solve another problem on top of it (see the various split on _32/_64, those takes time to achieve, maybe not huge time but still definitely some time and effort). Even in retrospect I am quite sure the way x86-64 happened was optimal and if we would go back we would do it again the exact same way even if the final object was to have a common arch/x86 (and thankfully Linus is flexible and smart enough to realize

Quoted 9 lines

that code that isn't risking to destabilize anything shouldn't be forced out just because it's not to a totally theoretical-perfect-nitpicking-clean-state yet). It's still a lot of work do the unification later as a separate task, but it's not like if we did it immediately it would have been a lot less work. It's about the same amount of effort and we were able to defer it for later and decrease the time to market which surely has contributed to the success of x86-64.

In hindsight decisions are much easier. I agree it was less risky to fork than to share. But if another instruction set forks out a 64-bit not-exactly-compatible variant, I'm sure we'll start out shared and not fork it, especially if the platform remains the same.

Quoted 11 lines

Problem of qemu is not some lack of GUI or that it's not included in the linux kernel git tree, the definitive problem is how to merge qemu-kvm/kvm and qlx into it. If you (Avi) were the qemu maintainer I am sure there wouldn't two trees so as a developer I would totally love it, and I am sure that with you as maintainer it would have a chance to move forward with qlx on desktop virtualization without proposing to extend vnc instead to achieve a "similar" result (imagine if btrfs is published on a website and people starts to discuss if it should ever be merged ever because reinventing some part of btrfs inside ext5 might achieve ""similar"" results).

The qemu/qemu-kvm fork is definitely hurting. Some history: when kvm started out I pulled qemu for fast hacking and, much like arch/x86_64, I couldn't destabilize qemu for something that was completely experimental (and closed source at the time). Moreover, it wasn't clear if the qemu community would be interested.

The qemu-kvm fork was designed for minimal intrusion so I could merge upstream qemu regularly. This resulted in kvm integration that was fairly ugly. Later Anthony merged a well-integrated alternative implementation (in retrospect this was a mistake IMO - we were left with a well tested high performing ugly implementation and a clean, slow, untested, and unfeatured implementation, and no one who wants to merge the two). So now it is pretty confusing to read the code which has the two alternate implementation sometimes sharing code and sometimes diverging.

Quoted 10 lines

About a GUI for KVM to use on desktop distributions, that is an irrelevant concern compared to the lack of protocol more efficient than rdesktop/rdp/vnc for desktop virtualization. I've people asking me to migrate hundreds of desktops to desktop virtualization on KVM in their organizations and I tell them to use spice because I believe it's the most efficient option available (at least as far as we stick to open source open protocols), there are universities using spice on thousand of student desktops, and I think we need paravirt graphics to happen ASAP in the main qemu tree too.

That effort will have to wait for the spice project to mature.

Quoted 4 lines

In short: running KVM on the desktop is irrelevant compared to running the desktop on KVM so I suggest to focus on what is more important first ;).

Anyone can focus on what interests them, if someone has an interest in a good desktop-on-desktop experience they should start hacking and sending patches.

Signature · 1 line
error compiling committee.c: too many arguments to function
#313 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 6 lines · Avi Kivity
Quoted 2 lines

- move a clean (and minimal) version of the Qemu code base to tools/kvm/, in the upstream kernel repo, and work on that from that point on.

I'll ignore the repository location which should be immaterial to a serious developer and concentrate on the 'clean and minimal' aspect, since it has some merit. [...]

To the contrary, experience shows that repository location, and in particular a shared repository for closely related bits is very much material!

It matters because when there are two separate projects, even a "serious developer" is finding it double and triple difficult to contribute even trivial changes.

It becomes literally a nightmare if you have to touch 3 packages: kernel, a library and an app codebase. It takes _forever_ to get anything useful done.

Also, 'focus on a single thing' is a very basic aspect of humans, especially those who do computer programming. Working on two code bases in two repositories at once can be very challenging physically and psychically.

So what i've seen is that OSS programmers tend to pick a side, pretty much randomly, and then rationalize it in hindsight why they prefer that side ;-)

Most of them become either a kernel developer or a user-space package developer - and then they specialize on that field and shy away from changes that involve both. It's a basic human thing to avoid the hassle that comes with multi-package changes. (One really has to be outright stupid, fanatic or desperate to even attempt such changes these days - such are the difficulties for a comparatively low return.)

The solution is to tear down such artificial walls of contribution where possible. And tearing down the wall between KVM and qemu-kvm seems very much possible and the advantages would be numerous.

Unless by "serious developer" you meant: "developer willing to [or forced to] waste time and effort on illogically structured technology".

Quoted 4 lines

[...]

Do you really think the echo'n'cat school of usability wants to write a GUI? In linux-2.6.git?

Then you'll be surprised to hear that it's happening as we speak and the commits are there in linux-2.6.git. Both a TUI and GUI is in the works.

Furthermore, the numbers show that half of the usability fixes to tools/perf/ came not from regular perf contributors but from random kernel developers and testers who when they build the latest kernel and try out perf at the same time (it's very easy because you already have it in the kernel repository - no separate download, no installation, etc. necessary).

I had literally zero such contributions when (the precursor to) 'perf' was still a separate user-space project.

You could have the same effect for Qemu: the latest bits in tools/kvm/ would be built by regular kernel testers and developers. The integration benefits dont just extend to developers, a unified project is vastly easier to test as well.

Thanks,

Ingo

#314 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 13 lines · Ingo Molnar
Quoted 7 lines · Avi Kivity
Quoted 3 lines

- move a clean (and minimal) version of the Qemu code base to tools/kvm/, in the upstream kernel repo, and work on that from that point on.

I'll ignore the repository location which should be immaterial to a serious developer and concentrate on the 'clean and minimal' aspect, since it has some merit. [...]

To the contrary, experience shows that repository location, and in particular a shared repository for closely related bits is very much material!

Quoted 7 lines

It matters because when there are two separate projects, even a "serious developer" is finding it double and triple difficult to contribute even trivial changes.

It becomes literally a nightmare if you have to touch 3 packages: kernel, a library and an app codebase. It takes _forever_ to get anything useful done.

You can't be serious. I find that the difficulty in contributing a patch has mostly to do with writing the patch, and less with figuring out which email address to send it to.

Quoted 4 lines

Also, 'focus on a single thing' is a very basic aspect of humans, especially those who do computer programming. Working on two code bases in two repositories at once can be very challenging physically and psychically.

Indeed, working simultaneously on two different projects is difficult. I usually work for a while on one, and then 'cd', physically and psychically, to the other. Then switch back. Sort of like the scheduler on a uniprocessor machine.

Quoted 10 lines

So what i've seen is that OSS programmers tend to pick a side, pretty much randomly, and then rationalize it in hindsight why they prefer that side ;-)

Most of them become either a kernel developer or a user-space package developer - and then they specialize on that field and shy away from changes that involve both. It's a basic human thing to avoid the hassle that comes with multi-package changes. (One really has to be outright stupid, fanatic or desperate to even attempt such changes these days - such are the difficulties for a comparatively low return.)

We have a large number of such stupid, fanatic, desperate developers in the qemu and kvm communities.

Quoted 7 lines

The solution is to tear down such artificial walls of contribution where possible. And tearing down the wall between KVM and qemu-kvm seems very much possible and the advantages would be numerous.

Unless by "serious developer" you meant: "developer willing to [or forced to] waste time and effort on illogically structured technology".

By "serious developer" I mean

- someone who is interested in contributing, not in getting their name
into the kernel commits list
- someone who is willing to read the wiki page and find out where the
repository and mailing list for a project is
- someone who will spend enough time on the project so that the time
to clone two repositories will not be a factor in their contributions
- someone who will work on the uncool stuff like fixing bugs and
providing interfaces to other tools

Quoted 14 lines
Quoted 5 lines

[...]

Do you really think the echo'n'cat school of usability wants to write a GUI? In linux-2.6.git?

Then you'll be surprised to hear that it's happening as we speak and the commits are there in linux-2.6.git. Both a TUI and GUI is in the works.

Furthermore, the numbers show that half of the usability fixes to tools/perf/ came not from regular perf contributors but from random kernel developers and testers who when they build the latest kernel and try out perf at the same time (it's very easy because you already have it in the kernel repository - no separate download, no installation, etc. necessary).

Quoted 9 lines

I had literally zero such contributions when (the precursor to) 'perf' was still a separate user-space project.

You could have the same effect for Qemu: the latest bits in tools/kvm/ would be built by regular kernel testers and developers. The integration benefits dont just extend to developers, a unified project is vastly easier to test as well.

Let's wait and see then. If the tools/perf/ experience has really good results, we can reconsider this at a later date.

Signature · 1 line
error compiling committee.c: too many arguments to function
#315 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 17 lines · Avi Kivity
Quoted 16 lines · Ingo Molnar
Quoted 5 lines · Avi Kivity
Quoted 2 lines

- move a clean (and minimal) version of the Qemu code base to tools/kvm/, in the upstream kernel repo, and work on that from that point on.

I'll ignore the repository location which should be immaterial to a serious developer and concentrate on the 'clean and minimal' aspect, since it has some merit. [...]

To the contrary, experience shows that repository location, and in particular a shared repository for closely related bits is very much material!

It matters because when there are two separate projects, even a "serious developer" is finding it double and triple difficult to contribute even trivial changes.

Quoted 7 lines
Quoted 3 lines

It becomes literally a nightmare if you have to touch 3 packages: kernel, a library and an app codebase. It takes _forever_ to get anything useful done.

You can't be serious. I find that the difficulty in contributing a patch has mostly to do with writing the patch, and less with figuring out which email address to send it to.

My own experience and everyone i've talked about such topics (developers and distro people) about feature contribution tells the exact opposite: it's much harder to contribute features to multiple packages than to a single project.

kernel+library+app features take forever to propagate, and there's constant fear of version friction, productization deadlines are uncertain and ABI messups are frequent as well due to disjoint testing. Also, each component has essential veto power: so if the proposed API or approach is opposed or changed in a later stage then that affects (sometimes already committed) changes. If you've ever done it you'll know how tedious it is.

This very thread and recent threads about KVM usability demonstrate the same complications.

Thanks,

Ingo

#316 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Avi Kivity
Quoted 8 lines · Avi Kivity

By "serious developer" I mean

- someone who is interested in contributing, not in getting their name
into the kernel commits list
- someone who is willing to read the wiki page and find out where the
repository and mailing list for a project is
- someone who will spend enough time on the project so that the time to
clone two repositories will not be a factor in their contributions

I'm not going to argue about the Qemu merging here. But your above assessment is incomplete.

It is not because developers don't want to clone two different trees that tools/perf is a success. Or may be it's a factor but I suspect it to be very minimal. I can script git commands if needed. It is actually because both kernel and user side are sync in this scheme.

Quoted 2 lines

Let's wait and see then. If the tools/perf/ experience has really good results, we can reconsider this at a later date.

I think it has already really good results.

#317 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 2 lines · Frederic Weisbecker

[...] It is actually because both kernel and user side are sync in this scheme. [...]

This argues that co-evolution of an interface is easiest on the developers if they own both sides of that interface. No quarrel.

This does not argue that that the preservation of a stable ABI is best done this way. If anything, it makes it too easy to change both the provider and the preferred user of the interface without noticing unintentional breakage to forlorn out-of-your-tree clients.

- FChE

#318 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 7 lines · Frank Ch. Eigler
Quoted 2 lines · Frederic Weisbecker

[...] It is actually because both kernel and user side are sync in this scheme. [...]

This argues that co-evolution of an interface is easiest on the developers if they own both sides of that interface. No quarrel.

Correct, that's a big advantage.

Quoted 4 lines

This does not argue that that the preservation of a stable ABI is best done this way. If anything, it makes it too easy to change both the provider and the preferred user of the interface without noticing unintentional breakage to forlorn out-of-your-tree clients.

Your concern is valid, and this issue has been raised in the past as one of the main counter-arguments against tools/perf/. (there was a big flamewar about it on lkml when it was introduced)

Our roughly 1 year experience with perf is that, somewhat pradoxially, this scheme not only works as well as classic ABI schemes but actually brings a _better_ ABI than the classic "let the kernel define an ABI" single-sided solution.

I know the difference first hand, i've written various syscalls ABIs in the past 10+ years before perf and know how they interact with their user space counterparts.

Why did it work out better with tools/perf/? It turns out that there's an immediate, direct, actionable test feedback effect on the ABI, and much closer relation to the ABI. Typically the same developer implements the kernel bits and the user-space bits (because it's so easy to do co-development), so the ABI aspects are ingrained in the developer much more deeply. Once you see the kind of havoc ABI breakage can cause during development you avoid it in the future.

So developers find that a good, stable ABI helps development. It turns out that developers dont actually _want_ to break the ABI and are careful about it
- and having the app next to the kernel ABI and co-developing it makes it sure there's never any true mismatch.

Also, we can do ABI improvements at a far higher rate than any other kernel subsystem. I checked the git logs, we've done over three dozen ABI extensions since the first version, and all were forwards _and_ backwards compatible.

A higher rate of change gives developers more experience and lets them do a better ABI, and makes them more ABI-conscious. I think if all kernel ABIs had such a healthy rate of change we'd fill in all the missing kernel features very quickly.

With detached packages ABI features are often done by a kernel developer (who is familar with the kernel subsystem in question) and a separate user-space developer (who is familar with the user-space project in question), and the ABI consciousness is less strong.

So you are right that there's a danger of accidental ABI breakage, but it's not an issue in practice. There are external apps making use of the ABI as well, not just tools/perf/.

In a more abstract sense this is kind of a classic case of game theory: that a assume-trust strategy pays off in the long run.

Thanks,

Ingo

#319 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 3 lines · Ingo Molnar

I wish both you and Avi looked back 3-4 years and realized what made KVM so successful back then and why the hearts and minds of virtualization developers were captured by KVM almost overnight.

Ingo,

What made KVM so successful was that the core kernel of the hypervisor was designed the right way, as a kernel module where it belonged. It was obvious to anyone who had been exposed to the main competition at the time, Xen, that this was the right approach. What has ended up killing Xen in the end is the not-invented-here approach of copying everything over, reformatting it, and rewriting half of it, which made it impossible to maintain and support as a single codebase. At my previous employer we ended up dropping all Xen efforts exactly because it was like maintaining two separate operating system kernels. The key to KVM is that once you have Linux, you practically have KVM as well.

Quoted 10 lines

Fast forward to 2010. The kernel side of KVM is maximum goodness - by far the worst-quality remaining aspects of KVM are precisely in areas that you
mention: 'if we have to support third party tools, then it significantly complicates things'. You kept Qemu as an external 'third party' entity to KVM, and KVM is clearly hurting from that - just see the recent KVM usability thread for examples about suckage.

So a similar 'complication' is the crux of the matter behind KVM quality
problems: you've not followed through with the original KVM vision and you have not applied that concept to Qemu!

Well there are two ways to go about this. Either you base the KVM userland on top of an existing project, like QEMU, _or_ you rewrite it all from scratch. However, there is far more to it than just a couple of ioctls, for example the stack of reverse device-drivers is a pretty significant code base, rewriting that and maintaining it is not a trivial task. It is certainly my belief that the benefit we get from sharing that with QEMU by far outweighs the cost of forking it and keeping our own fork in the kernel tree. In fact it would result in exactly the same problems I mentioned above wrt Xen.

Quoted 7 lines

If you want to jump to the next level of technological quality you need to fix this attitude and you need to go back to the design roots of KVM. Concentrate on Qemu (as that is the weakest link now), make it a first class member of the KVM repo and simplify your development model by having a single repo:

- move a clean (and minimal) version of the Qemu code base to tools/kvm/, in the upstream kernel repo, and work on that from that point on.

With this you have just thrown away all the benefits of having the QEMU repository shared with other developers who will actively fix bugs in components we do care about for KVM.

Quoted 3 lines

- encourage kernel-space and user-space KVM developers to work on both user-space and kernel-space bits as a single unit. It's one project and a single experience to the user.

This is already happening and a total non issue.

Quoted 1 line

- [ and probably libvirt should go there too ]

Now that would be interesting, next we'll have to include things like libxml in the kernel git tree as well, to make sure libvirt doesn't get out of sync with the version supplied by your distribution vendor.

Quoted 4 lines

Yes, i've read a thousand excuses for why this is an absolutely impossible and a bad thing to do, and none of them was really convincing to me - and you also have become rather emotional about all the arguments so it's hard to argue about it on a technical basis.

So far your argument would justify pulling all of gdb into the kernel git tree as well, to support the kgdb efforts, or gcc so we can get rid of the gcc version quirks in the kernel header files, e2fsprogs and equivalent for _all_ file systems included in the kernel so we can make sure our fs tools never get out of sync with whats supported in the kernel......

Quoted 3 lines

We made a similar (admittedly very difficult ...) design jump from oprofile to perf, and i can tell you from that experience that it's day and night, both in terms of development and in terms of the end result!

The user components for perf vs oprofile are _tiny_ projects compared to the portions of QEMU that are actually used by KVM.

Oh and you completely forgot SeaBIOS. KVM+QEMU rely on SeaBIOS too, so from what you're saying we should pull that into the kernel git repository as well. Never mind the fact that we share SeaBIOS with the coreboot project which is very actively adding features to it that benefit us as well.....

Sorry, but there are times when unification make sense, and there are times where having a reasonably well designed split makes sense. KVM had problems with QEMU in the past which resulted in the qemu-kvm branch of it, which proved to be a major pain to deal with, but that is fortunately improving and qemu-kvm should go away completely at some point.

Cheers,
Jes

#320 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 8 lines · Jes Sorensen
Quoted 3 lines · Ingo Molnar

I wish both you and Avi looked back 3-4 years and realized what made KVM so successful back then and why the hearts and minds of virtualization developers were captured by KVM almost overnight.

Ingo,

Quoted 7 lines

What made KVM so successful was that the core kernel of the hypervisor was designed the right way, as a kernel module where it belonged. It was obvious to anyone who had been exposed to the main competition at the time, Xen, that this was the right approach. What has ended up killing Xen in the end is the not-invented-here approach of copying everything over, reformatting it, and rewriting half of it, which made it impossible to maintain and support as a single codebase. [...]

Yes, exactly.

I was part of that nightmare so i know.

Quoted 5 lines

[...]

At my previous employer we ended up dropping all Xen efforts exactly because it was like maintaining two separate operating system kernels. The key to KVM is that once you have Linux, you practically have KVM as well.

Yes. Please realize that what is behind it is a strikingly simple argument:

"Once you have a single project to develop and maintain all is much better."

Quoted 7 lines
Quoted 7 lines

Fast forward to 2010. The kernel side of KVM is maximum goodness - by far the worst-quality remaining aspects of KVM are precisely in areas that you
mention: 'if we have to support third party tools, then it significantly complicates things'. You kept Qemu as an external 'third party' entity to KVM, and KVM is clearly hurting from that - just see the recent KVM usability thread for examples about suckage.

Quoted 7 lines
Quoted 3 lines

So a similar 'complication' is the crux of the matter behind KVM quality
problems: you've not followed through with the original KVM vision and you have not applied that concept to Qemu!

Well there are two ways to go about this. Either you base the KVM userland on top of an existing project, like QEMU, _or_ you rewrite it all from scratch. [...]

Btw., i made similar arguments to Avi about 3 years ago when it was going upstream, that qemu should be unified with KVM. This is more true today than ever.

Quoted 7 lines

[...] However, there is far more to it than just a couple of ioctls, for example the stack of reverse device-drivers is a pretty significant code base, rewriting that and maintaining it is not a trivial task. It is certainly my belief that the benefit we get from sharing that with QEMU by far outweighs the cost of forking it and keeping our own fork in the kernel tree. In fact it would result in exactly the same problems I mentioned above wrt Xen.

I do not suggest forking Qemu at all, i suggest using the most natural development model for the KVM+Qemu shared project: a single repository.

Quoted 6 lines
Quoted 6 lines

If you want to jump to the next level of technological quality you need to fix this attitude and you need to go back to the design roots of KVM. Concentrate on Qemu (as that is the weakest link now), make it a first class member of the KVM repo and simplify your development model by having a single repo:

Quoted 6 lines
Quoted 2 lines

- move a clean (and minimal) version of the Qemu code base to tools/kvm/, in the upstream kernel repo, and work on that from that point on.

With this you have just thrown away all the benefits of having the QEMU repository shared with other developers who will actively fix bugs in components we do care about for KVM.

Not if it's a unified project.

Quoted 5 lines
Quoted 3 lines

- encourage kernel-space and user-space KVM developers to work on both user-space and kernel-space bits as a single unit. It's one project and a single experience to the user.

This is already happening and a total non issue.

My experience as an external observer of the end result contradicts this.

Seemingly trivial usability changes to the KVM+Qemu combo are not being done often because they involve cross-discipline changes.

( _In this very thread_ there has been a somewhat self-defeating argument by
Anthony that multi-package scenario would 'significantly complicate' matters. What more proof do we need to state the obvious? Keeping what has become one piece of technology over the years in two separate halves is obviously bad. )

Quoted 5 lines
Quoted 1 line

- [ and probably libvirt should go there too ]

Now that would be interesting, next we'll have to include things like libxml in the kernel git tree as well, to make sure libvirt doesn't get out of sync with the version supplied by your distribution vendor.

The way we have gone about this in tools/perf/ is similar to the route picked by Git: we only use very lowlevel libraries available everywhere, and we provide optional wrappers to the rest.

We are also using the kernel's libraries so we rarely need to go outside to get some functionality.

I.e. it's a non-issue in practice and despite perf having an (optional) dependency on xmlto and docbook we dont include those packages nor do we force users to install particular versions of them.

Quoted 10 lines
Quoted 4 lines

Yes, i've read a thousand excuses for why this is an absolutely impossible and a bad thing to do, and none of them was really convincing to me - and you also have become rather emotional about all the arguments so it's hard to argue about it on a technical basis.

So far your argument would justify pulling all of gdb into the kernel git tree as well, to support the kgdb efforts, or gcc so we can get rid of the gcc version quirks in the kernel header files, e2fsprogs and equivalent for _all_ file systems included in the kernel so we can make sure our fs tools never get out of sync with whats supported in the kernel......

gdb and gcc is clearly extrinsic to the kernel so why would we move them there?

I was talking about tools that are closely related to the kernel - where much of the development and actual use is in combination with the Linux kernel.

90%+ of the Qemu usecases are combined with Linux. (Yes, i know that you can run Qemu without KVM, and no, i dont think it matters in the grand scheme of things and most investment into Qemu comes from the KVM angle these days. In particular it for sure does not justify handicapping future KVM evolution so drastically.)

Quoted 6 lines
Quoted 3 lines

We made a similar (admittedly very difficult ...) design jump from oprofile to perf, and i can tell you from that experience that it's day and night, both in terms of development and in terms of the end result!

The user components for perf vs oprofile are _tiny_ projects compared to the portions of QEMU that are actually used by KVM.

I know the size and scope of Qemu, i even hacked it - still my points remain. (my arguments are influenced and strengthened by that past hacking experience)

Quoted 4 lines

Oh and you completely forgot SeaBIOS. KVM+QEMU rely on SeaBIOS too, so from what you're saying we should pull that into the kernel git repository as well. Never mind the fact that we share SeaBIOS with the coreboot project which is very actively adding features to it that benefit us as well.....

SeaBIOS is in essence a firmware, so it could either be loaded as such.

Just look at the qemu source code - the BIOSes are .bin images in qemu/pc-bios/ imported externally in essence.

Moving qemu to tools/kvm/ would not change that much. The firmware could become part of /lib/firmware/*.bin.

( That would probably be a more intelligent approach to the BIOS image import
problem as well. )

Quoted 5 lines

Sorry, but there are times when unification make sense, and there are times where having a reasonably well designed split makes sense. KVM had problems with QEMU in the past which resulted in the qemu-kvm branch of it, which proved to be a major pain to deal with, but that is fortunately improving and qemu-kvm should go away completely at some point.

qemu-kvm branch is not similar to my proposal at all: it made KVM _more_ fragmented, not more unified. I.e. it was a move in the exact opposite direction and i'd expect such a move to fail.

In fact the failure of qemu-kvm supports my point rather explicitly: it demonstrates that extra packages and split development are actively harmful.

I speak about this as a person who has done successful unifications of split codebases and in my judgement this move would be significantly beneficial to KVM.

You cannot really validly reject this proposal with "It wont work" as it clearly has worked in other, comparable cases. You could only reject this with "I have tried it and it didnt work".

Think about it: a clean and hackable user-space component in tools/kvm/. It's very tempting :-)

Ingo

#321 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 1 line · Ingo Molnar

* Jes Sorensen<[email protected]> wrote:

[...]

Quoted 8 lines
Quoted 4 lines

At my previous employer we ended up dropping all Xen efforts exactly because it was like maintaining two separate operating system kernels. The key to KVM is that once you have Linux, you practically have KVM as well.

Yes. Please realize that what is behind it is a strikingly simple argument:

"Once you have a single project to develop and maintain all is much better."

Thats a very glorified statement but it's not reality, sorry. You can do that with something like perf because it's so small and development of perf is limited to a very small group of developers.

Quoted 10 lines
Quoted 7 lines

[...] However, there is far more to it than just a couple of ioctls, for example the stack of reverse device-drivers is a pretty significant code base, rewriting that and maintaining it is not a trivial task. It is certainly my belief that the benefit we get from sharing that with QEMU by far outweighs the cost of forking it and keeping our own fork in the kernel tree. In fact it would result in exactly the same problems I mentioned above wrt Xen.

I do not suggest forking Qemu at all, i suggest using the most natural development model for the KVM+Qemu shared project: a single repository.

If you are not suggesting to fork QEMU, what are you suggesting then? You don't seriously expect that the KVM community will be able to mandate that the QEMU community switch to the Linux kernel repository? That would be like telling the openssl developers that they should merge with glibc and start working out of the glibc tree.

What you are suggesting is *only* going to happen if we fork QEMU, there is zero chance to move the main QEMU repository into the Linux kernel tree. And trust me, you don't want to have Linus having to deal with handling patches for tcg or embedded board emulation.

Quoted 5 lines
Quoted 3 lines

With this you have just thrown away all the benefits of having the QEMU repository shared with other developers who will actively fix bugs in components we do care about for KVM.

Not if it's a unified project.

You still haven't explained how you expect create a unified KVM+QEMU project, without forking from the existing QEMU.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

- encourage kernel-space and user-space KVM developers to work on both user-space and kernel-space bits as a single unit. It's one project and a single experience to the user.

This is already happening and a total non issue.

My experience as an external observer of the end result contradicts this.

What I have seen you complain about here is the lack of a good end user GUI for KVM. However that is a different thing. So far no vendor has put significant effort into it, but that is nothing new in Linux. We have a great kernel, but our user applications are still lacking. We have 217 CD players for GNOME, but we have no usable calendering application.

A good GUI for virtualization is a big task, and whoever designs it will base their design upon their preferences for whats important. A lot of spare time developers would clearly care most about a gui installation and fancy icons to click on, whereas server users would be much more interested in automation and remote access to the systems. For a good example of an incomplete solution, try installing Fedora over a serial line, you cannot do half the things without launching VNC :( Getting a comprehensive solution for this that would satisfy the bulk of the users would be a huge chunk of code in the kernel tree. Imagine the screaming that would result in? How often have we not had the moaning from x86 users who wanted to rip out all the non x86 code to reduce the size of the tarball?

Quoted 2 lines

Seemingly trivial usability changes to the KVM+Qemu combo are not being done often because they involve cross-discipline changes.

Which trivial usability changes?

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

- [ and probably libvirt should go there too ]

Now that would be interesting, next we'll have to include things like libxml in the kernel git tree as well, to make sure libvirt doesn't get out of sync with the version supplied by your distribution vendor.

The way we have gone about this in tools/perf/ is similar to the route picked by Git: we only use very lowlevel libraries available everywhere, and we provide optional wrappers to the rest.

Did you ever look at what libvirt actually does and what it offers? Or how about the various libraries used by QEMU to offer things like VNC support or X support?

Again this works fine for something like perf where the primary display is text mode.

Quoted 8 lines
Quoted 5 lines

So far your argument would justify pulling all of gdb into the kernel git tree as well, to support the kgdb efforts, or gcc so we can get rid of the gcc version quirks in the kernel header files, e2fsprogs and equivalent for _all_ file systems included in the kernel so we can make sure our fs tools never get out of sync with whats supported in the kernel......

gdb and gcc is clearly extrinsic to the kernel so why would we move them there?

gdb should go with kgdb which goes with the kernel to keep it in sync. If you want to be consistent in your argument, you have to go all the way.

Quoted 2 lines

I was talking about tools that are closely related to the kernel - where much of the development and actual use is in combination with the Linux kernel.

Well the file system tools would obviously have to go into the kernel then so appropriate binaries can be distributed to match the kernel.

Quoted 5 lines

90%+ of the Qemu usecases are combined with Linux. (Yes, i know that you can run Qemu without KVM, and no, i dont think it matters in the grand scheme of things and most investment into Qemu comes from the KVM angle these days. In particular it for sure does not justify handicapping future KVM evolution so drastically.)

90+%? You got to be kidding? You clearly have no idea just how much it's used for running embedded emulators on non Linux. You should have seen the noise it made when I added C99 initializers to certain structs, because it broke builds using very old GCC versions on BeOS. Linux only, not a chance. Try subscribing to qemu-devel and you'll see a list that is only overtaken by few lists like lkml in terms of daily traffic.

Quoted 9 lines
Quoted 4 lines

Oh and you completely forgot SeaBIOS. KVM+QEMU rely on SeaBIOS too, so from what you're saying we should pull that into the kernel git repository as well. Never mind the fact that we share SeaBIOS with the coreboot project which is very actively adding features to it that benefit us as well.....

SeaBIOS is in essence a firmware, so it could either be loaded as such.

Just look at the qemu source code - the BIOSes are .bin images in qemu/pc-bios/ imported externally in essence.

Ehm no, QEMU now pulls in SeaBIOS to build it. And there are a lot of changes that require modification in SeaBIOS to match changes to QEMU.

Quoted 6 lines

qemu-kvm branch is not similar to my proposal at all: it made KVM _more_ fragmented, not more unified. I.e. it was a move in the exact opposite direction and i'd expect such a move to fail.

In fact the failure of qemu-kvm supports my point rather explicitly: it demonstrates that extra packages and split development are actively harmful.

Ehm it showed what happens when you fork QEMU to modify it primarily for your own project, ie. KVM. You are suggesting we fork QEMU for the benefit of KVM, and it will be exactly the same thing that happens.

I know you state that you are not suggesting we fork it, but as I showed above, pulling QEMU into the kernel tree, can only happen as a fork. There is no point pretending otherwise.

Quoted 10 lines

I speak about this as a person who has done successful unifications of split codebases and in my judgement this move would be significantly beneficial to KVM.

You cannot really validly reject this proposal with "It wont work" as it clearly has worked in other, comparable cases. You could only reject this with "I have tried it and it didnt work".

Think about it: a clean and hackable user-space component in tools/kvm/. It's very tempting :-)

I say this based on my hacking experience, my experience with the kernel, the QEMU base, SeaBIOS and merging projects. Yes it can be done, but the cost is much higher than the gain.

Cheers,
Jes

#322 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 8 lines · Jes Sorensen
Quoted 1 line · Ingo Molnar

* Jes Sorensen<[email protected]> wrote:

[...]

Quoted 5 lines
Quoted 4 lines

At my previous employer we ended up dropping all Xen efforts exactly because it was like maintaining two separate operating system kernels. The key to KVM is that once you have Linux, you practically have KVM as well.

Quoted 7 lines
Quoted 3 lines

Yes. Please realize that what is behind it is a strikingly simple argument:

"Once you have a single project to develop and maintain all is much better."

Thats a very glorified statement but it's not reality, sorry. You can do that with something like perf because it's so small and development of perf is limited to a very small group of developers.

I was not talking about just perf: i am also talking about the arch/x86/ unification which is 200+ KLOC of highly non-trivial kernel code with hundreds of contributors and with 8000+ commits in the past two years.

Also, it applies to perf as well: people said exactly that a year ago: 'perf has it easy to be clean as it is small, once it gets as large as Oprofile tooling it will be in the same messy situation'.

Today perf has more features than Oprofile, has a larger and more complex code base, has more contributors, and no, it's not in the same messy situation at all.

So whatever you think of large, unified projects, you are quite clearly mistaken. I have done and maintained through two different types of unifications and the experience was very similar: both developers and users (and maintainers) are much better off.

Ingo

#323 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 9 lines · Ingo Molnar
Quoted 3 lines · Jes Sorensen

Thats a very glorified statement but it's not reality, sorry. You can do that with something like perf because it's so small and development of perf is limited to a very small group of developers.

I was not talking about just perf: i am also talking about the arch/x86/ unification which is 200+ KLOC of highly non-trivial kernel code with hundreds of contributors and with 8000+ commits in the past two years.

Sorry but you cannot compare merging two chunks of kernel code that originated from the same base, with the efforts of mixing a large userland project with a kernel component. Apples and oranges.

Quoted 7 lines

Also, it applies to perf as well: people said exactly that a year ago: 'perf has it easy to be clean as it is small, once it gets as large as Oprofile tooling it will be in the same messy situation'.

Today perf has more features than Oprofile, has a larger and more complex code base, has more contributors, and no, it's not in the same messy situation at all.

Both perf and oprofile are still relatively small projects in comparison to QEMU.

Quoted 4 lines

So whatever you think of large, unified projects, you are quite clearly mistaken. I have done and maintained through two different types of unifications and the experience was very similar: both developers and users (and maintainers) are much better off.

You believe that I am wrong in my assessment of unified projects, and I obviously think you are mistaken and underestimating the cost and effects of trying to merge the two.

Well I think we are just going to agree to disagree on this one. I am not against merging projects where it makes sense, but in this particular case I am strongly convinced the loss would be much greater than the gain.

Cheers,
Jes

#324 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 7 lines · Jes Sorensen
Quoted 6 lines · Ingo Molnar
Quoted 3 lines · Jes Sorensen

Thats a very glorified statement but it's not reality, sorry. You can do that with something like perf because it's so small and development of perf is limited to a very small group of developers.

Quoted 7 lines
Quoted 3 lines

I was not talking about just perf: i am also talking about the arch/x86/ unification which is 200+ KLOC of highly non-trivial kernel code with hundreds of contributors and with 8000+ commits in the past two years.

Sorry but you cannot compare merging two chunks of kernel code that originated from the same base, with the efforts of mixing a large userland project with a kernel component. Apples and oranges.

That's true to a certain degree, but combined with the perf experience it's all rather clear.

Similar arguments were made against the x86 unification and against perf. Similar arguments were made against KVM and in favor of Xen years ago - back when few of you knew about it ;-)

These are all repeating patterns in my experience.

You could fairly contrast that with a _failed_ unification perhaps - but i'm not aware of any such failed unification. (please educate me if you are)

The thing is, unifications are rare in the OSS space not because they dont make sense technically (to the contrary), they are rare due to blind inertia (why change if we managed to muddle through with the current scheme?) and to a certain degree due to the egos involved ;-)

As such we have a proliferation of packages in Linux, and we'd be much better off in a more focused fashion. And whenever i see that in the kernel's context i'll mention it - as it happened here too.

Quoted 10 lines
Quoted 7 lines

Also, it applies to perf as well: people said exactly that a year ago:
'perf has it easy to be clean as it is small, once it gets as large as Oprofile tooling it will be in the same messy situation'.

Today perf has more features than Oprofile, has a larger and more complex code base, has more contributors, and no, it's not in the same messy situation at all.

Both perf and oprofile are still relatively small projects in comparison to QEMU.

So is your argument that the unification does not make sense due to size? Would a smaller Qemu be more appropriate for this purpose?

Quoted 5 lines
Quoted 4 lines

So whatever you think of large, unified projects, you are quite clearly mistaken. I have done and maintained through two different types of unifications and the experience was very similar: both developers and users (and maintainers) are much better off.

Quoted 7 lines

You believe that I am wrong in my assessment of unified projects, and I obviously think you are mistaken and underestimating the cost and effects of trying to merge the two.

Well I think we are just going to agree to disagree on this one. I am not against merging projects where it makes sense, but in this particular case I am strongly convinced the loss would be much greater than the gain.

I wish you said that based on first hand negative experience with unifications, not based on just pure speculation.

(and yes, i speculate too, but at least with some basis)

Ingo

#325 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 7 lines · Ingo Molnar
Quoted 2 lines · Jes Sorensen

Both perf and oprofile are still relatively small projects in comparison to QEMU.

So is your argument that the unification does not make sense due to size? Would a smaller Qemu be more appropriate for this purpose?

As I have stated repeatedly in this discussion, a unification would hurt the QEMU development process because it would alienate a large number of QEMU developers who are *not* Linux kernel users.

QEMU is a lot more complex than you let on.

Quoted 8 lines
Quoted 3 lines

Well I think we are just going to agree to disagree on this one. I am not against merging projects where it makes sense, but in this particular case I am strongly convinced the loss would be much greater than the gain.

I wish you said that based on first hand negative experience with unifications, not based on just pure speculation.

(and yes, i speculate too, but at least with some basis)

You still haven't given us a *single* example of unification of something that wasn't purely linked to the Linux kernel. perf/ oprofile is 100% linked to the Linux kernel, QEMU is not. I wish you would actually look at what users use QEMU for. As long as you continue to purely speculate on this, to use your own words, your arguments are not holding up.

And you are not being consistent either. You have conveniently continue to ignore my questions about why the file system tools are not to be merged into the Linux kernel source tree?

Jes

#326 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 6 lines · Jes Sorensen
Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Jes Sorensen

Both perf and oprofile are still relatively small projects in comparison to QEMU.

Quoted 6 lines
Quoted 2 lines

So is your argument that the unification does not make sense due to size? Would a smaller Qemu be more appropriate for this purpose?

As I have stated repeatedly in this discussion, a unification would hurt the QEMU development process because it would alienate a large number of QEMU developers who are *not* Linux kernel users.

I took a quick look at the qemu.git log and more than half of all recent contributions came from Linux distributors.

So without KVM Qemu would be a much, much smaller project. It would be similar to how it was 5 years ago.

Quoted 1 line

QEMU is a lot more complex than you let on.

Please educate me then about the specifics.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

Well I think we are just going to agree to disagree on this one. I am not against merging projects where it makes sense, but in this particular case I am strongly convinced the loss would be much greater than the gain.

I wish you said that based on first hand negative experience with unifications, not based on just pure speculation.

Quoted 7 lines
Quoted 1 line

(and yes, i speculate too, but at least with some basis)

You still haven't given us a *single* example of unification of something that wasn't purely linked to the Linux kernel. perf/ oprofile is 100% linked to the Linux kernel, QEMU is not. I wish you would actually look at what users use QEMU for. As long as you continue to purely speculate on this, to use your own words, your arguments are not holding up.

The stats show that the huge increase in Qemu contributions over the past few years was mainly due to KVM. Do you claim it wasnt? What other projects make use of it and pay developers to work on it?

Quoted 3 lines

And you are not being consistent either. You have conveniently continue to ignore my questions about why the file system tools are not to be merged into the Linux kernel source tree?

Sorry, i didnt comment on it because the answer is obvious: the file system tools and pretty much any Linux-exclusive tool (such as udev) should be moved there. The difference is that there's not much active development done in most of those tools so the benefits are probably marginal. Both Qemu and KVM is being developed very actively though, so development model inefficiencies show up.

Anyway, i didnt think i'd step into such a hornet's nest by explaining what i see as KVM's biggest weakness today and how i suggest it to be fixed :-)

If you dont agree with me, then dont do it - no need to get emotional about it.

Thanks,

Ingo

#327 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

Quoted 3 lines · Ingo Molnar

I took a quick look at the qemu.git log and more than half of all recent contributions came from Linux distributors.

I don't know what you're looking at, but in the past month, there's been 56 unique contributors, with 411 changesets. I count 16 people employed by distributions with 188 changesets.

Quoted 3 lines

So without KVM Qemu would be a much, much smaller project. It would be similar to how it was 5 years ago.

I'm not saying that KVM isn't significant. I'm employed to work on QEMU because of KVM.

I'm just saying that KVM users aren't 99% of the community and that we can't neglect the rest of the community.

Regards,

Anthony Liguori

#328 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Jes Sorensen

Hi there,

not really trying to get into the CC list of this discussion ;) but for what is worth I'd like to share my opinion on the matter.

Quoted 7 lines · Jes Sorensen

What made KVM so successful was that the core kernel of the hypervisor was designed the right way, as a kernel module where it belonged. It was obvious to anyone who had been exposed to the main competition at the time, Xen, that this was the right approach. What has ended up killing Xen in the end is the not-invented-here approach of copying everything over, reformatting it, and rewriting half of it, which made it impossible to maintain and support as a single codebase. At my previous

Full agreement with that. CVS/git/patches and development model is next to irrelevant compared to the basic design of the code.

qemu (and especially qemu-kvm) is surely much closer to perf, than a firefox or openoffice, because there is some tight interconnect with the kernel API. And the skills required to produce useful patches in qemu are similar to the skills requires to produce useful patches for the kernel, more often than not a new feature in kvm also requires some merging of a qemu-kvm side patch (it always happened to me so far ;). But clearly we've to draw a barrier somewhere and while I could see things like systemtap and util-linux included into the kernel and perf already is, I've an hard time to see userland code supporting kernels other than linux into the kernel.

I think that's probably where I'd draw the line. Let's say somebody creates a pure paravirt userland for kvm without full driver emulation that only runs on a linux kernel and no other OS, maybe that thing wouldn't be so controversial to include into the kernel as qemu is. qemu is clearly beyond the "only-running-on-a-linux-kernel" barrier...

I'd definitely start with systemtap, which I think is even more suitable than perf to be merged into the kernel. Things useful only for developers like perf/systemtap makes even more sense to fetch silently hidden in a single pull. Those projects are so ideal to fetch together because you run your own compiled userland binary and not an rpm, and you need very latest kernel and userland package and sometime new userland might not work so well with older kernel too and the other way around. they're tool for developers and no developer cares about API as they rebuild latest userland code anyway, they almost don't require backwards compatibility of kernel.

Quoted 6 lines

So far your argument would justify pulling all of gdb into the kernel git tree as well, to support the kgdb efforts, or gcc so we can get rid of the gcc version quirks in the kernel header files, e2fsprogs and equivalent for _all_ file systems included in the kernel so we can make sure our fs tools never get out of sync with whats supported in the kernel......

It also boils down to the maintainer, where the code is, defines the maintainer who pushes/commits it to the central repository that everyone pulls from. And having the code into Linus's tree doesn't make sense unless Linus is interested to follow and review qemu. So it'd only create blind pulls.

But I entirely see what Ingo is going after and I have no doubt that contribution increases if some code is merged into the kernel even if it's userland. The more people clones a project, the more people builds, uses, reads the code and has incentive to contribute... and there's nothing else like the linux git tree to give visibility to a project and get more contributions (well as long as the pulled code requires similar skills to the kernel code of course). Plus it's annoying to go on web, find url to clone, clone.. running make is faster. But this purely is a PR effect. It's like free ads, to get more people using and looking into the code because it's already on the harddisk and you've only to run make. After somebody gets familiar with the pulled userland code because it find it in the tree and it didn't need to search the web and cut-and-paste and stuff, clone a new repo, I think it wouldn't matter anymore to have it into the kernel or not. Like for perf, by now I doubt it'd get less contributions if it's moved out of the kernel tree. The only reason to leave it there is if Linus actively checks the code before pulling it.

So I think what would be nice maybe to get the PR/ads positive effect and get more _users_ (and later developers) involved without actually merging, is a command like:

git clone linux-2.6
cd linux-2.6
tools/clone-project qemu-kvm
tools/clone-project qemu
tools/clone-project systemtap
tools/clone-project seabios
tools/clone-project e2fsprogs
tools/clone-project perf
...

And then maybe a git-send-email or similar command that would do the right thing and send it to the right list or similar. Learning the process of other projects is time consuming and requires some effort.

But as far as qemu-kvm goes, the visibility is already there, and most people that could possibly contribute to the kernel side already has the userland cloned and pulls regularly from it so I doubt it'd generate anything remotely as beneficial like it did for perf. systemtap is really _identical_ to perf. You include it, lots more developers toys with it by just running "make", they find a bug and they fixes it, and they keep on contributing new features later after they got familiar with it. As usual ;).

Quoted 3 lines · In separate mail Ingo

Btw., i made similar arguments to Avi about 3 years ago when it was going upstream, that qemu should be unified with KVM. This is more true today than ever.

Well not sure if with KVM you mean qemu-kvm or KVM kernel code, but I would see an huge value and a win-win situation to see qemu-kvm and qemu unified. It's out of my reach how there can be still be a difference considering that nobody runs qemu with perhaps the exception of the maintainers themself. There's not even a qemu/kvm directory in qemu. These are the real problems that should be solved... Every time I've to send a patch I've to check if it also applies to qemu. I usually start with qemu-kvm to do my development there, and then I cross fingers and I hope the patch applies clean against qemu too, and send it there in that case. qemu and qemu-kvm are the same thing, it's the same people, it's the same community, it's the same skills, it's an absolute waste that a little amount of code isn't merged so we can all work on the same tree. And it's not an huge patch at all if compared to the size of qemu-kvm... so there can't be any technical explanation for qemu to take a tangent here.

So my suggestion is to start with what will give a _real_ tangible benefit to developers (i.e. to all work on the same branch), the PR effect of merging it into the kernel would be minor for qemu-kvm, it really doesn't matter which url we pull the code from as long as there is only 1 url and not 2.

#329 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 30 lines · Ingo Molnar
Quoted 27 lines · Anthony Liguori
Quoted 25 lines · Ingo Molnar
Quoted 4 lines

If we look at the use-case, it's going to be something like, a user is creating virtual machines and wants to get performance information about them.

Quoted 9 lines

Having to run a separate tool like perf is not going to be what they would expect they had to do. Instead, they would either use their existing GUI tool (like virt-manager) or they would use their management interface (either QMP or libvirt).

The complexity of interaction is due to the fact that perf shouldn't be a stand alone tool. It should be a library or something with a programmatic interface that another tool can make use of.

But ... a GUI interface/integration is of course possible too, and it's being worked on.

perf is mainly a kernel developer tool, and kernel developers generally dont use GUIs to do their stuff: which is the (sole) reason why its first ~850 commits of tools/perf/ were done without a GUI. We go where our developers are.

In any case it's not an excuse to have no proper command-line tooling. In fact if you cannot get simpler, more atomic command-line tooling right then you'll probably doubly suck at doing a GUI as well.

Quoted 8 lines
Quoted 6 lines

It's about who owns the user interface.

If qemu owns the user interface, than we can satisfy this in a very simple way by adding a perf monitor command. If we have to support third party tools, then it significantly complicates things.

Of course illogical modularization complicates things 'significantly'.

Ok. Then apply this to the kernel. I'm then happy to take patches.

Regards,

Anthony Liguori

commit 84b84db054e83e7686b80fad9f8d2aa87aade1a1

Author: Anthony Liguori <[email protected]>
Date:   Thu Mar 18 09:35:29 2010 -0500

Bring QEMU into the Linux kernel tree

Ingo is under the impression that this will result in a massive improvement in the usability of QEMU.

.gitmodules new file +3 -0
new file mode 100644
index 0000000..76cdb68
@@ -0,0 +1,3 @@
+[submodule "tools/qemu"]
+	path = tools/qemu
+	url = git://git.qemu.org/qemu.git
MAINTAINERS +6 -0
index 03f38c1..6275796 100644
@@ -4427,6 +4427,12 @@ M:	Robert Jarzmik <[email protected]>
 L:	[email protected]
 S:	Maintained
 
+QEMU
+M:      Anthony Liguori <[email protected]>
+L:      [email protected]
+S:      Maintained
+F:      tools/qemu
+
 QLOGIC QLA2XXX FC-SCSI DRIVER
 M:	Andrew Vasquez <[email protected]>
 M:	[email protected]
tools/qemu new file +1 -0
new file mode 160000
index 0000000..e5322f7
@@ -0,0 +1 @@
+Subproject commit e5322f76a72352eea8eb511390c27726b64e5a87
#330 lore raw

Re: [RFC] Unify KVM kernel-space and user-space code into a single project

In reply to Ingo Molnar
Quoted 3 lines · Ingo Molnar

- move a clean (and minimal) version of the Qemu code base to tools/kvm/, in the upstream kernel repo, and work on that from that point on.

QEMU is about 600k LOC. We have a mechanism to compile out portions of the code but a lot things are tied together in an intimate way. In the long run, we're working on adding stronger interfaces such that we can split components out into libraries that are consumable by other applications.

Simplying forking the device model won't work. Well more than half of our contributors are not coming from KVM developers/users. If you just fork the device models, you start to lose a ton of fixes (look at Xen and VirtualBox).

So feel free to either 1) apply my previous patch and then start working on a "clean (and minimal)" QEMU or 2) wait to commit my previous patch and start sending patches to clean up QEMU.

Absolute none of this is going to give you a VirtualBox like GUI for QEMU.

Regards,

Anthony Liguori

#331 lore raw
In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

Hm, that sounds rather messy if we want to use it to basically expose kernel functionality in a guest/host unified way. Is the qemu process discoverable in some secure way? Can we trust it? Is there some proper tooling available to do it, or do we have to push it through 2-3 packages to get such a useful feature done?

Since we want to implement a pmu usable for the guest anyway why we don't just use a guests perf to get all information we want? If we get a pmu-nmi from the guest we just re-inject it to the guest and perf in the guest gives us all information we wand including kernel and userspace symbols, stack traces, and so on.

In the previous thread we discussed about a direct trace channel between guest and host kernel (which can be used for ftrace events for example). This channel could be used to transport this information to the host kernel.

The only additional feature needed is a way for the host to start a perf instance in the guest.

Opinions?

Joerg

#332 lore raw
Quoted 7 lines · oerg Roedel
Quoted 5 lines · Ingo Molnar

Hm, that sounds rather messy if we want to use it to basically expose kernel functionality in a guest/host unified way. Is the qemu process discoverable in some secure way? Can we trust it? Is there some proper tooling available to do it, or do we have to push it through 2-3 packages to get such a useful feature done?

Quoted 5 lines

Since we want to implement a pmu usable for the guest anyway why we don't just use a guests perf to get all information we want? If we get a pmu-nmi from the guest we just re-inject it to the guest and perf in the guest gives us all information we wand including kernel and userspace symbols, stack traces, and so on.

I guess this aims to get information from old environments running on kvm for life extension :)

Quoted 4 lines

In the previous thread we discussed about a direct trace channel between guest and host kernel (which can be used for ftrace events for example). This channel could be used to transport this information to the host kernel.

Interesting! I know the people who are trying to do that with systemtap. See, http://vesper.sourceforge.net/

Quoted 3 lines

The only additional feature needed is a way for the host to start a perf instance in the guest.

# ssh localguest perf record --host-chanel ... ? B-)

Thank you,

Quoted 11 lines

Opinions?

Joerg

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 2 lines
Masami Hiramatsu
e-mail: [email protected]
#333 lore raw
In reply to oerg Roedel
Quoted 9 lines · oerg Roedel
Quoted 5 lines · Ingo Molnar

Hm, that sounds rather messy if we want to use it to basically expose kernel functionality in a guest/host unified way. Is the qemu process discoverable in some secure way? Can we trust it? Is there some proper tooling available to do it, or do we have to push it through 2-3 packages to get such a useful feature done?

Since we want to implement a pmu usable for the guest anyway why we don't just use a guests perf to get all information we want? [...]

Look at the previous posting of this patch, this is something new and rather unique. The main power in the 'perf kvm' kind of instrumentation is to profile _both_ the host and the guest on the host, using the same tool (often using the same kernel) and using similar workloads, and do profile comparisons using 'perf diff'.

Note that KVM's in-kernel design makes it easy to offer this kind of host/guest shared implementation that Yanmin has created. Other virtulization solutions with a poorer design (for example where the hypervisor code base is split away from the guest implementation) will have it much harder to create something similar.

That kind of integrated approach can result in very interesting finds straight away, see:

http://lkml.indiana.edu/hypermail/linux/kernel/1003.0/00613.html

( the profile there demoes the need for spinlock accelerators for example -
there's clearly assymetrically large overhead in guest spinlock code. Guess how much else we'll be able to find with a full 'perf kvm' implementation. )

One of the main goals of a virtualization implementation is to eliminate as many performance differences to the host kernel as possible. From the first day KVM was released the overriding question from users was always: 'how much slower is it than native, and which workloads are hit worst, and why, and could you pretty please speed up important workload XYZ'.

'perf kvm' helps exactly that kind of development workflow.

Note that with oprofile you can already do separate guest space and host space profiling (with the timer driven fallbackin the guest). One idea with 'perf kvm' is to change that paradigm of forced separation and forced duplication and to supprt the workflow that most developers employ: use the host space for development and unify instrumentation in an intuitive framework. Yanmin's 'perf kvm' patch is a very good step towards that goal.

Anyway ... look at the patches, try them and see it for yourself. Back in the days when i did KVM performance work i wish i had something like Yanmin's 'perf kvm' feature. I'd probably still be hacking KVM today ;-)

So, the code is there, it's useful and it's up to you guys whether you live with this opportunity - the perf developers are certainly eager to help out with the details. There's already tons of per kernel subsystem perf helper
tools: perf sched, perf kmem, perf lock, perf bench, perf timechart.

'perf kvm' is really a natural and good next step IMO that underlines the main design goodness KVM brought to the world of virtualization: proper guest/host code base integration.

Thanks,

Ingo

#334 lore raw
In reply to Avi Kivity
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Quoted 7 lines
Quoted 6 lines

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Thanks for your kind comments.

Quoted 4 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

Quoted 20 lines

Perhaps a
symbol server that perf can connect to (and that would connect to guests in turn)?

Quoted 15 lines

diff -Nraup linux-2.6_tipmaster0315/arch/x86/kvm/vmx.c linux-2.6_tipmaster0315_perfkvm/arch/x86/kvm/vmx.c

arch/x86/kvm/vmx.c +1 -0
@@ -26,6 +26,7 @@
  #include<linux/sched.h>
  #include<linux/moduleparam.h>
  #include<linux/ftrace_event.h>
+#include<linux/perf_event.h>
  #include "kvm_cache_regs.h"
  #include "x86.h"
 
@@ -3632,6 +3633,43 @@ static void update_cr8_intercept(struct
  	vmcs_write32(TPR_THRESHOLD, irr);
  }
 
Quoted 15 lines

arch/x86/kvm/vmx.c static void update_cr8_intercept(struct

Quoted 12 lines
arch/x86/kvm/vmx.c +11 -0
+DEFINE_PER_CPU(int, kvm_in_guest) = {0};
+
+static void kvm_set_in_guest(void)
+{
+	percpu_write(kvm_in_guest, 1);
+}
+
+static int kvm_is_in_guest(void)
+{
+	return percpu_read(kvm_in_guest);
+}
 

There is already PF_VCPU for this.

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

Quoted 10 lines

arch/x86/kvm/vmx.c static void update_cr8_intercept(struct

Quoted 8 lines
arch/x86/kvm/vmx.c +6 -0
+static struct perf_guest_info_callbacks kvm_guest_cbs = {
+	.is_in_guest 		= kvm_is_in_guest,
+	.is_user_mode		= kvm_is_user_mode,
+	.get_guest_ip		= kvm_get_guest_ip,
+	.reset_in_guest		= kvm_reset_in_guest,
+};
 

Should be in common code, not vmx specific.

Right. I discussed with Yangsheng. I will move above data structures and callbacks to file arch/x86/kvm/x86.c, and add get_ip, a new callback to kvm_x86_ops.

Yanmin

#335 lore raw
Quoted 29 lines · Yanmin
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Quoted 7 lines
Quoted 6 lines

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Thanks for your kind comments.

Quoted 7 lines
Quoted 4 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

Sorry. I found currently --pid isn't process but a thread (main thread).

Ingo,

Is it possible to support a new parameter or extend --inherit, so 'perf record' and 'perf top' could collect data on all threads of a process when the process is running?

If not, I need add a new ugly parameter which is similar to --pid to filter out process data in userspace.

Yanmin

#336 lore raw
Quoted 7 lines · Yanmin

Sorry. I found currently --pid isn't process but a thread (main thread).

Ingo,

Is it possible to support a new parameter or extend --inherit, so 'perf record' and 'perf top' could collect data on all threads of a process when the process is running?

That seems like a worthwhile addition regardless of this thread. Profile all current threads and any new ones. It probably makes sense to call this --pid and rename the existing --pid to --thread.

Signature · 1 line
error compiling committee.c: too many arguments to function
#337 lore raw
In reply to Zhang, Yanmin
Quoted 39 lines · Zhang, Yanmin
Quoted 29 lines · Yanmin
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Quoted 7 lines
Quoted 6 lines

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Thanks for your kind comments.

Quoted 7 lines
Quoted 4 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

Sorry. I found currently --pid isn't process but a thread (main thread).

Quoted 8 lines

Ingo,

Is it possible to support a new parameter or extend --inherit, so 'perf record' and 'perf top' could collect data on all threads of a process when the process is running?

If not, I need add a new ugly parameter which is similar to --pid to filter out process data in userspace.

Yeah. For maximum utility i'd suggest to extend --pid to include this, and introduce --tid for the previous, limited-to-a-single-task functionality.

Most users would expect --pid to work like a 'late attach' - i.e. to work like strace -f or like a gdb attach.

Ingo

#338 lore raw
Quoted 47 lines · Ingo Molnar
Quoted 45 lines · Zhang, Yanmin
Quoted 29 lines · Yanmin
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Quoted 7 lines
Quoted 6 lines

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Thanks for your kind comments.

Quoted 7 lines
Quoted 4 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

Sorry. I found currently --pid isn't process but a thread (main thread).

Ingo,

Is it possible to support a new parameter or extend --inherit, so 'perf record' and 'perf top' could collect data on all threads of a process when the process is running?

Quoted 8 lines
Quoted 2 lines

If not, I need add a new ugly parameter which is similar to --pid to filter out process data in userspace.

Yeah. For maximum utility i'd suggest to extend --pid to include this, and introduce --tid for the previous, limited-to-a-single-task functionality.

Most users would expect --pid to work like a 'late attach' - i.e. to work like strace -f or like a gdb attach.

Thanks Ingo, Avi.

I worked out below patch against tip/master of March 15th.

Subject: [PATCH] Change perf's parameter --pid to process-wide collection
From: Zhang, Yanmin <[email protected]>

Change parameter -p (--pid) to real process pid and add -t (--tid) meaning thread id. Now, --pid means perf collects the statistics of all threads of the process, while --tid means perf just collect the statistics of that thread.

BTW, the patch fixes a bug of 'perf stat -p'. 'perf stat' always configures attr->disabled=1 if it isn't a system-wide collection. If there is a '-p' and no forks, 'perf stat -p' doesn't collect any data. In addition, the while(!done) in run_perf_stat consumes 100% single cpu time which has bad impact on running workload. I added a sleep(1) in the loop.

---

tools/perf/builtin-record.c +150 -96
diff -Nraup linux-2.6_tipmaster0315/tools/perf/builtin-record.c linux-2.6_tipmaster0315_perfpid/tools/perf/builtin-record.c
@@ -27,7 +27,7 @@
 #include <unistd.h>
 #include <sched.h>
 
-static int			fd[MAX_NR_CPUS][MAX_COUNTERS];
+static int			*fd[MAX_NR_CPUS][MAX_COUNTERS];
 
 static long			default_interval		=      0;
 
@@ -43,6 +43,9 @@ static int			raw_samples			=      0;
 static int			system_wide			=      0;
 static int			profile_cpu			=     -1;
 static pid_t			target_pid			=     -1;
+static pid_t			target_tid			=     -1;
+static int			*all_tids			=      NULL;
+static int			thread_num			=      0;
 static pid_t			child_pid			=     -1;
 static int			inherit				=      1;
 static int			force				=      0;
@@ -60,7 +63,7 @@ static struct timeval		this_read;
 
 static u64			bytes_written			=      0;
 
-static struct pollfd		event_array[MAX_NR_CPUS * MAX_COUNTERS];
+static struct pollfd		*event_array;
 
 static int			nr_poll				=      0;
 static int			nr_cpu				=      0;
@@ -77,7 +80,7 @@ struct mmap_data {
 	unsigned int		prev;
 };
 
-static struct mmap_data		mmap_array[MAX_NR_CPUS][MAX_COUNTERS];
+static struct mmap_data		*mmap_array[MAX_NR_CPUS][MAX_COUNTERS];
 
 static unsigned long mmap_read_head(struct mmap_data *md)
 {
@@ -225,11 +228,12 @@ static struct perf_header_attr *get_head
 	return h_attr;
 }
 
-static void create_counter(int counter, int cpu, pid_t pid, bool forks)
+static void create_counter(int counter, int cpu, bool forks)
 {
 	char *filter = filters[counter];
 	struct perf_event_attr *attr = attrs + counter;
 	struct perf_header_attr *h_attr;
+	int thread_index;
 	int track = !counter; /* only the first counter needs these */
 	int ret;
 	struct {
@@ -280,117 +284,124 @@ static void create_counter(int counter, 
 	if (forks)
 		attr->enable_on_exec = 1;
 
+	for (thread_index = 0; thread_index < thread_num; thread_index++) {
 try_again:
-	fd[nr_cpu][counter] = sys_perf_event_open(attr, pid, cpu, group_fd, 0);
+		fd[nr_cpu][counter][thread_index] = sys_perf_event_open(attr,
+				all_tids[thread_index], cpu, group_fd, 0);
 
-	if (fd[nr_cpu][counter] < 0) {
-		int err = errno;
+		if (fd[nr_cpu][counter][thread_index] < 0) {
+			int err = errno;
 
-		if (err == EPERM || err == EACCES)
-			die("Permission error - are you root?\n"
-			    "\t Consider tweaking /proc/sys/kernel/perf_event_paranoid.\n");
-		else if (err ==  ENODEV && profile_cpu != -1)
-			die("No such device - did you specify an out-of-range profile CPU?\n");
+			if (err == EPERM || err == EACCES)
+				die("Permission error - are you root?\n"
+						"\t Consider tweaking /proc/sys/kernel/perf_event_paranoid.\n");
+			else if (err ==  ENODEV && profile_cpu != -1)
+				die("No such device - did you specify an out-of-range profile CPU?\n");
 
-		/*
-		 * If it's cycles then fall back to hrtimer
-		 * based cpu-clock-tick sw counter, which
-		 * is always available even if no PMU support:
-		 */
-		if (attr->type == PERF_TYPE_HARDWARE
-			&& attr->config == PERF_COUNT_HW_CPU_CYCLES) {
+			/*
+			 * If it's cycles then fall back to hrtimer
+			 * based cpu-clock-tick sw counter, which
+			 * is always available even if no PMU support:
+			 */
+			if (attr->type == PERF_TYPE_HARDWARE
+					&& attr->config == PERF_COUNT_HW_CPU_CYCLES) {
 
-			if (verbose)
-				warning(" ... trying to fall back to cpu-clock-ticks\n");
-			attr->type = PERF_TYPE_SOFTWARE;
-			attr->config = PERF_COUNT_SW_CPU_CLOCK;
-			goto try_again;
-		}
-		printf("\n");
-		error("perfcounter syscall returned with %d (%s)\n",
-			fd[nr_cpu][counter], strerror(err));
+				if (verbose)
+					warning(" ... trying to fall back to cpu-clock-ticks\n");
+				attr->type = PERF_TYPE_SOFTWARE;
+				attr->config = PERF_COUNT_SW_CPU_CLOCK;
+				goto try_again;
+			}
+			printf("\n");
+			error("perfcounter syscall returned with %d (%s)\n",
+				fd[nr_cpu][counter][thread_index],
+				strerror(err));
 
 #if defined(__i386__) || defined(__x86_64__)
-		if (attr->type == PERF_TYPE_HARDWARE && err == EOPNOTSUPP)
-			die("No hardware sampling interrupt available. No APIC? If so then you can boot the kernel with the \"lapic\" boot parameter to force-enable it.\n");
+			if (attr->type == PERF_TYPE_HARDWARE && err == EOPNOTSUPP)
+				die("No hardware sampling interrupt available. No APIC? If so then you can boot the kernel with the \"lapic\" boot parameter to force-enable it.\n");
 #endif
 
-		die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
-		exit(-1);
-	}
+			die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
+			exit(-1);
+		}
 
-	h_attr = get_header_attr(attr, counter);
-	if (h_attr == NULL)
-		die("nomem\n");
+		h_attr = get_header_attr(attr, counter);
+		if (h_attr == NULL)
+			die("nomem\n");
+
+		if (!file_new) {
+			if (memcmp(&h_attr->attr, attr, sizeof(*attr))) {
+				fprintf(stderr, "incompatible append\n");
+				exit(-1);
+			}
+		}
 
-	if (!file_new) {
-		if (memcmp(&h_attr->attr, attr, sizeof(*attr))) {
-			fprintf(stderr, "incompatible append\n");
+		if (read(fd[nr_cpu][counter][thread_index], &read_data, sizeof(read_data)) == -1) {
+			perror("Unable to read perf file descriptor\n");
 			exit(-1);
 		}
-	}
-
-	if (read(fd[nr_cpu][counter], &read_data, sizeof(read_data)) == -1) {
-		perror("Unable to read perf file descriptor\n");
-		exit(-1);
-	}
 
-	if (perf_header_attr__add_id(h_attr, read_data.id) < 0) {
-		pr_warning("Not enough memory to add id\n");
-		exit(-1);
-	}
+		if (perf_header_attr__add_id(h_attr, read_data.id) < 0) {
+			pr_warning("Not enough memory to add id\n");
+			exit(-1);
+		}
 
-	assert(fd[nr_cpu][counter] >= 0);
-	fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK);
+		assert(fd[nr_cpu][counter][thread_index] >= 0);
+		fcntl(fd[nr_cpu][counter][thread_index], F_SETFL, O_NONBLOCK);
 
-	/*
-	 * First counter acts as the group leader:
-	 */
-	if (group && group_fd == -1)
-		group_fd = fd[nr_cpu][counter];
-	if (multiplex && multiplex_fd == -1)
-		multiplex_fd = fd[nr_cpu][counter];
+		/*
+		 * First counter acts as the group leader:
+		 */
+		if (group && group_fd == -1)
+			group_fd = fd[nr_cpu][counter][thread_index];
+		if (multiplex && multiplex_fd == -1)
+			multiplex_fd = fd[nr_cpu][counter][thread_index];
 
-	if (multiplex && fd[nr_cpu][counter] != multiplex_fd) {
+		if (multiplex && fd[nr_cpu][counter][thread_index] != multiplex_fd) {
 
-		ret = ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd);
-		assert(ret != -1);
-	} else {
-		event_array[nr_poll].fd = fd[nr_cpu][counter];
-		event_array[nr_poll].events = POLLIN;
-		nr_poll++;
-
-		mmap_array[nr_cpu][counter].counter = counter;
-		mmap_array[nr_cpu][counter].prev = 0;
-		mmap_array[nr_cpu][counter].mask = mmap_pages*page_size - 1;
-		mmap_array[nr_cpu][counter].base = mmap(NULL, (mmap_pages+1)*page_size,
-				PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter], 0);
-		if (mmap_array[nr_cpu][counter].base == MAP_FAILED) {
-			error("failed to mmap with %d (%s)\n", errno, strerror(errno));
-			exit(-1);
+			ret = ioctl(fd[nr_cpu][counter][thread_index], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd);
+			assert(ret != -1);
+		} else {
+			event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index];
+			event_array[nr_poll].events = POLLIN;
+			nr_poll++;
+
+			mmap_array[nr_cpu][counter][thread_index].counter = counter;
+			mmap_array[nr_cpu][counter][thread_index].prev = 0;
+			mmap_array[nr_cpu][counter][thread_index].mask = mmap_pages*page_size - 1;
+			mmap_array[nr_cpu][counter][thread_index].base = mmap(NULL,
+							(mmap_pages+1)*page_size,
+							PROT_READ|PROT_WRITE, MAP_SHARED,
+							fd[nr_cpu][counter][thread_index],
+							0);
+			if (mmap_array[nr_cpu][counter][thread_index].base == MAP_FAILED) {
+				error("failed to mmap with %d (%s)\n", errno, strerror(errno));
+				exit(-1);
+			}
 		}
-	}
 
-	if (filter != NULL) {
-		ret = ioctl(fd[nr_cpu][counter],
-			    PERF_EVENT_IOC_SET_FILTER, filter);
-		if (ret) {
-			error("failed to set filter with %d (%s)\n", errno,
-			      strerror(errno));
-			exit(-1);
+		if (filter != NULL) {
+			ret = ioctl(fd[nr_cpu][counter][thread_index],
+					PERF_EVENT_IOC_SET_FILTER, filter);
+			if (ret) {
+				error("failed to set filter with %d (%s)\n", errno,
+						strerror(errno));
+				exit(-1);
+			}
 		}
-	}
 
-	ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_ENABLE);
+		ioctl(fd[nr_cpu][counter][thread_index], PERF_EVENT_IOC_ENABLE);
+	}
 }
 
-static void open_counters(int cpu, pid_t pid, bool forks)
+static void open_counters(int cpu, bool forks)
 {
 	int counter;
 
 	group_fd = -1;
 	for (counter = 0; counter < nr_counters; counter++)
-		create_counter(counter, cpu, pid, forks);
+		create_counter(counter, cpu, forks);
 
 	nr_cpu++;
 }
@@ -425,7 +436,7 @@ static int __cmd_record(int argc, const 
 	int err;
 	unsigned long waking = 0;
 	int child_ready_pipe[2], go_pipe[2];
-	const bool forks = target_pid == -1 && argc > 0;
+	const bool forks = target_tid == -1 && argc > 0;
 	char buf;
 
 	page_size = sysconf(_SC_PAGE_SIZE);
@@ -534,7 +545,7 @@ static int __cmd_record(int argc, const 
 		child_pid = pid;
 
 		if (!system_wide)
-			target_pid = pid;
+			target_tid = pid;
 
 		close(child_ready_pipe[1]);
 		close(go_pipe[0]);
@@ -550,11 +561,11 @@ static int __cmd_record(int argc, const 
 
 
 	if ((!system_wide && !inherit) || profile_cpu != -1) {
-		open_counters(profile_cpu, target_pid, forks);
+		open_counters(profile_cpu, forks);
 	} else {
 		nr_cpus = read_cpu_map();
 		for (i = 0; i < nr_cpus; i++)
-			open_counters(cpumap[i], target_pid, forks);
+			open_counters(cpumap[i], forks);
 	}
 
 	if (file_new) {
@@ -579,7 +590,7 @@ static int __cmd_record(int argc, const 
 	}
 
 	if (!system_wide && profile_cpu == -1)
-		event__synthesize_thread(target_pid, process_synthesized_event,
+		event__synthesize_thread(target_tid, process_synthesized_event,
 					 session);
 	else
 		event__synthesize_threads(process_synthesized_event, session);
@@ -602,11 +613,15 @@ static int __cmd_record(int argc, const 
 
 	for (;;) {
 		int hits = samples;
+		int thread;
 
 		for (i = 0; i < nr_cpu; i++) {
 			for (counter = 0; counter < nr_counters; counter++) {
-				if (mmap_array[i][counter].base)
-					mmap_read(&mmap_array[i][counter]);
+				for (thread = 0;
+					thread < thread_num; thread++) {
+					if (mmap_array[i][counter][thread].base)
+						mmap_read(&mmap_array[i][counter][thread]);
+				}
 			}
 		}
 
@@ -619,8 +634,13 @@ static int __cmd_record(int argc, const 
 
 		if (done) {
 			for (i = 0; i < nr_cpu; i++) {
-				for (counter = 0; counter < nr_counters; counter++)
-					ioctl(fd[i][counter], PERF_EVENT_IOC_DISABLE);
+				for (counter = 0; counter < nr_counters;
+					counter++) {
+					for (thread = 0;
+						thread < thread_num; thread++)
+						ioctl(fd[i][counter][thread],
+							PERF_EVENT_IOC_DISABLE);
+				}
 			}
 		}
 	}
@@ -653,6 +673,8 @@ static const struct option options[] = {
 		     "event filter", parse_filter),
 	OPT_INTEGER('p', "pid", &target_pid,
 		    "record events on existing pid"),
+	OPT_INTEGER('t', "tid", &target_tid,
+		    "record events on existing thread id"),
 	OPT_INTEGER('r', "realtime", &realtime_prio,
 		    "collect data with this RT SCHED_FIFO priority"),
 	OPT_BOOLEAN('R', "raw-samples", &raw_samples,
@@ -693,10 +715,11 @@ static const struct option options[] = {
 int cmd_record(int argc, const char **argv, const char *prefix __used)
 {
 	int counter;
+	int i,j;
 
 	argc = parse_options(argc, argv, options, record_usage,
 			    PARSE_OPT_STOP_AT_NON_OPTION);
-	if (!argc && target_pid == -1 && !system_wide && profile_cpu == -1)
+	if (!argc && target_tid == -1 && !system_wide && profile_cpu == -1)
 		usage_with_options(record_usage, options);
 
 	symbol__init();
@@ -707,6 +730,37 @@ int cmd_record(int argc, const char **ar
 		attrs[0].config = PERF_COUNT_HW_CPU_CYCLES;
 	}
 
+	if (target_pid != -1) {
+		target_tid = target_pid;
+		thread_num = find_all_tid(target_pid, &all_tids);
+		if (thread_num <= 0) {
+			fprintf(stderr, "Can't find all threads of pid %d\n",
+				target_pid);
+			usage_with_options(record_usage, options);
+		}
+	} else {
+		all_tids=malloc(sizeof(int));
+		if (!all_tids)
+			return -ENOMEM;
+
+		all_tids[0] = target_tid;
+		thread_num = 1;
+	}
+
+	for (i = 0; i < MAX_NR_CPUS; i++) {
+		for (j = 0; j < MAX_COUNTERS; j++) {
+			fd[i][j] = malloc(sizeof(int)*thread_num);
+			mmap_array[i][j] = malloc(
+				sizeof(struct mmap_data)*thread_num);
+			if (!fd[i][j] || !mmap_array[i][j])
+				return -ENOMEM;
+		}
+	}
+	event_array = malloc(
+		sizeof(struct pollfd)*MAX_NR_CPUS*MAX_COUNTERS*thread_num);
+	if (!event_array)
+		return -ENOMEM;
+
 	/*
 	 * User specified count overrides default frequency.
 	 */
tools/perf/builtin-stat.c +78 -33

219 lines not on this page · raw message

tools/perf/builtin-top.c +102 -54

251 lines not on this page · raw message

tools/perf/util/thread.c +32 -0
diff -Nraup linux-2.6_tipmaster0315/tools/perf/util/thread.c linux-2.6_tipmaster0315_perfpid/tools/perf/util/thread.c
@@ -7,6 +7,37 @@
 #include "util.h"
 #include "debug.h"
 
+int find_all_tid(int pid, int ** all_tid)
+{
+	char name[256];
+	int items;
+	struct dirent **namelist = NULL;
+	int ret = 0;
+	int i;
+
+	sprintf(name, "/proc/%d/task", pid);
+	items = scandir(name, &namelist, NULL, NULL);
+	if (items <= 0)
+                return -ENOENT;
+	*all_tid = malloc(sizeof(int) * items);
+	if (!*all_tid) {
+		ret = -ENOMEM;
+		goto failure;
+	}
+
+	for (i = 0; i < items; i++)
+		(*all_tid)[i] = atoi(namelist[i]->d_name);
+
+	ret = items;
+
+failure:
+	for (i=0; i<items; i++)
+		free(namelist[i]);
+	free(namelist);
+
+	return ret;
+}
+
 void map_groups__init(struct map_groups *self)
 {
 	int i;
@@ -348,3 +379,4 @@ struct symbol *map_groups__find_symbol(s
 
 	return NULL;
 }
+
tools/perf/util/thread.h +1 -0
diff -Nraup linux-2.6_tipmaster0315/tools/perf/util/thread.h linux-2.6_tipmaster0315_perfpid/tools/perf/util/thread.h
@@ -23,6 +23,7 @@ struct thread {
 	int			comm_len;
 };
 
+int find_all_tid(int pid, int ** all_tid);
 void map_groups__init(struct map_groups *self);
 int thread__set_comm(struct thread *self, const char *comm);
 int thread__comm_len(struct thread *self);
#339 lore raw
Quoted 68 lines · Yanmin
Quoted 47 lines · Ingo Molnar
Quoted 45 lines · Zhang, Yanmin
Quoted 29 lines · Yanmin
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Quoted 7 lines
Quoted 6 lines

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Thanks for your kind comments.

Quoted 7 lines
Quoted 4 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

Sorry. I found currently --pid isn't process but a thread (main thread).

Ingo,

Is it possible to support a new parameter or extend --inherit, so 'perf record' and 'perf top' could collect data on all threads of a process when the process is running?

Quoted 8 lines
Quoted 2 lines

If not, I need add a new ugly parameter which is similar to --pid to filter out process data in userspace.

Yeah. For maximum utility i'd suggest to extend --pid to include this, and introduce --tid for the previous, limited-to-a-single-task functionality.

Most users would expect --pid to work like a 'late attach' - i.e. to work like strace -f or like a gdb attach.

Thanks Ingo, Avi.

I worked out below patch against tip/master of March 15th.

Subject: [PATCH] Change perf's parameter --pid to process-wide collection
From: Zhang, Yanmin <[email protected]>

Change parameter -p (--pid) to real process pid and add -t (--tid) meaning thread id. Now, --pid means perf collects the statistics of all threads of the process, while --tid means perf just collect the statistics of that thread.

Quoted 7 lines

BTW, the patch fixes a bug of 'perf stat -p'. 'perf stat' always configures attr->disabled=1 if it isn't a system-wide collection. If there is a '-p' and no forks, 'perf stat -p' doesn't collect any data. In addition, the while(!done) in run_perf_stat consumes 100% single cpu time which has bad impact on running workload. I added a sleep(1) in the loop.

Ingo,

Sorry, the patch has bugs. I need do a better job and will work out 2 separate patches against the 2 issues.

Yanmin

#340 lore raw
Quoted 75 lines · Yanmin
Quoted 74 lines · Yanmin
Quoted 47 lines · Ingo Molnar
Quoted 45 lines · Zhang, Yanmin
Quoted 29 lines · Yanmin
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Yanmin

From: Zhang, Yanmin<[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Quoted 7 lines
Quoted 6 lines

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Thanks for your kind comments.

Quoted 7 lines
Quoted 4 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

Sorry. I found currently --pid isn't process but a thread (main thread).

Ingo,

Is it possible to support a new parameter or extend --inherit, so 'perf record' and 'perf top' could collect data on all threads of a process when the process is running?

Quoted 8 lines
Quoted 2 lines

If not, I need add a new ugly parameter which is similar to --pid to filter out process data in userspace.

Yeah. For maximum utility i'd suggest to extend --pid to include this, and introduce --tid for the previous, limited-to-a-single-task functionality.

Most users would expect --pid to work like a 'late attach' - i.e. to work like strace -f or like a gdb attach.

Thanks Ingo, Avi.

I worked out below patch against tip/master of March 15th.

Subject: [PATCH] Change perf's parameter --pid to process-wide collection
From: Zhang, Yanmin <[email protected]>

Change parameter -p (--pid) to real process pid and add -t (--tid) meaning thread id. Now, --pid means perf collects the statistics of all threads of the process, while --tid means perf just collect the statistics of that thread.

BTW, the patch fixes a bug of 'perf stat -p'. 'perf stat' always configures attr->disabled=1 if it isn't a system-wide collection. If there is a '-p' and no forks, 'perf stat -p' doesn't collect any data. In addition, the while(!done) in run_perf_stat consumes 100% single cpu time which has bad impact on running workload. I added a sleep(1) in the loop.

Quoted 5 lines
Quoted 1 line

Ingo,

Sorry, the patch has bugs. I need do a better job and will work out 2 separate patches against the 2 issues.

I worked out 3 new patches against tip/master tree of Mar. 17th.

1) Patch perf_stat: Fix the issue that perf doesn't enable counters when target_pid != -1. Change the condition to fork/exec subcommand. If there is a subcommand parameter, perf always fork/exec it. The usage example is:
#perf stat -a sleep 10
So this command could collect statistics for 10 seconds precisely. User still could stop it by CTRL+C.

2) Patch perf_record: Fix the issue that when perf forks/exec a subcommand, it should enable all counters after the new process is execing.Change the condition to fork/exec subcommand. If there is a subcommand parameter, perf always fork/exec it. The usage example is:
#perf record -f -a sleep 10
So this command could collect statistics for 10 seconds precisely. User still could stop it by CTRL+C.

3) perf_pid: Change parameter --pid to process-wide collection. Add --tid which means collecting thread-wide statistics. Usage example is:
#perf top -p 8888
#perf record -p 8888 -f sleep 10
#perf stat -p 8888 -f sleep 10

Arnaldo,

Pls. apply the 3 attached patches.

Yanmin

tools/perf/builtin-stat.c +14 -10
diff -Nraup linux-2.6_tipmaster0317/tools/perf/builtin-stat.c linux-2.6_tipmaster0317_fixstat/tools/perf/builtin-stat.c
@@ -159,8 +159,10 @@ static void create_perf_stat_counter(int
 		}
 	} else {
 		attr->inherit	     = inherit;
-		attr->disabled	     = 1;
-		attr->enable_on_exec = 1;
+		if (target_pid == -1) {
+			attr->disabled = 1;
+			attr->enable_on_exec = 1;
+		}
 
 		fd[0][counter] = sys_perf_event_open(attr, pid, -1, -1, 0);
 		if (fd[0][counter] < 0 && verbose)
@@ -251,9 +253,9 @@ static int run_perf_stat(int argc __used
 	unsigned long long t0, t1;
 	int status = 0;
 	int counter;
-	int pid = target_pid;
+	int pid;
 	int child_ready_pipe[2], go_pipe[2];
-	const bool forks = (target_pid == -1 && argc > 0);
+	const bool forks = (argc > 0);
 	char buf;
 
 	if (!system_wide)
@@ -265,10 +267,10 @@ static int run_perf_stat(int argc __used
 	}
 
 	if (forks) {
-		if ((pid = fork()) < 0)
+		if ((child_pid = fork()) < 0)
 			perror("failed to fork");
 
-		if (!pid) {
+		if (!child_pid) {
 			close(child_ready_pipe[0]);
 			close(go_pipe[1]);
 			fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
@@ -297,8 +299,6 @@ static int run_perf_stat(int argc __used
 			exit(-1);
 		}
 
-		child_pid = pid;
-
 		/*
 		 * Wait for the child to be ready to exec.
 		 */
@@ -309,6 +309,10 @@ static int run_perf_stat(int argc __used
 		close(child_ready_pipe[0]);
 	}
 
+	if (target_pid == -1)
+		pid = child_pid;
+	else
+		pid = target_pid;
 	for (counter = 0; counter < nr_counters; counter++)
 		create_perf_stat_counter(counter, pid);
 
@@ -321,7 +325,7 @@ static int run_perf_stat(int argc __used
 		close(go_pipe[1]);
 		wait(&status);
 	} else {
-		while(!done);
+		while(!done) sleep(1);
 	}
 
 	t1 = rdclock();
@@ -459,7 +463,7 @@ static volatile int signr = -1;
 
 static void skip_signal(int signo)
 {
-	if(target_pid != -1)
+	if(child_pid == -1)
 		done = 1;
 
 	signr = signo;
tools/perf/builtin-record.c +15 -18
diff -Nraup linux-2.6_tip0317/tools/perf/builtin-record.c linux-2.6_tip0317_fixrecord/tools/perf/builtin-record.c
@@ -225,7 +225,7 @@ static struct perf_header_attr *get_head
 	return h_attr;
 }
 
-static void create_counter(int counter, int cpu, pid_t pid, bool forks)
+static void create_counter(int counter, int cpu, pid_t pid)
 {
 	char *filter = filters[counter];
 	struct perf_event_attr *attr = attrs + counter;
@@ -275,10 +275,10 @@ static void create_counter(int counter, 
 	attr->mmap		= track;
 	attr->comm		= track;
 	attr->inherit		= inherit;
-	attr->disabled		= 1;
-
-	if (forks)
+	if (target_pid == -1 && !system_wide) {
+		attr->disabled = 1;
 		attr->enable_on_exec = 1;
+	}
 
 try_again:
 	fd[nr_cpu][counter] = sys_perf_event_open(attr, pid, cpu, group_fd, 0);
@@ -380,17 +380,15 @@ try_again:
 			exit(-1);
 		}
 	}
-
-	ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_ENABLE);
 }
 
-static void open_counters(int cpu, pid_t pid, bool forks)
+static void open_counters(int cpu, pid_t pid)
 {
 	int counter;
 
 	group_fd = -1;
 	for (counter = 0; counter < nr_counters; counter++)
-		create_counter(counter, cpu, pid, forks);
+		create_counter(counter, cpu, pid);
 
 	nr_cpu++;
 }
@@ -425,7 +423,7 @@ static int __cmd_record(int argc, const 
 	int err;
 	unsigned long waking = 0;
 	int child_ready_pipe[2], go_pipe[2];
-	const bool forks = target_pid == -1 && argc > 0;
+	const bool forks = argc > 0;
 	char buf;
 
 	page_size = sysconf(_SC_PAGE_SIZE);
@@ -496,13 +494,13 @@ static int __cmd_record(int argc, const 
 	atexit(atexit_header);
 
 	if (forks) {
-		pid = fork();
+		child_pid = fork();
 		if (pid < 0) {
 			perror("failed to fork");
 			exit(-1);
 		}
 
-		if (!pid) {
+		if (!child_pid) {
 			close(child_ready_pipe[0]);
 			close(go_pipe[1]);
 			fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
@@ -531,11 +529,6 @@ static int __cmd_record(int argc, const 
 			exit(-1);
 		}
 
-		child_pid = pid;
-
-		if (!system_wide)
-			target_pid = pid;
-
 		close(child_ready_pipe[1]);
 		close(go_pipe[0]);
 		/*
@@ -548,13 +541,17 @@ static int __cmd_record(int argc, const 
 		close(child_ready_pipe[0]);
 	}
 
+	if (forks && target_pid == -1 && !system_wide)
+		pid = child_pid;
+	else
+		pid = target_pid;
 
 	if ((!system_wide && !inherit) || profile_cpu != -1) {
-		open_counters(profile_cpu, target_pid, forks);
+		open_counters(profile_cpu, pid);
 	} else {
 		nr_cpus = read_cpu_map();
 		for (i = 0; i < nr_cpus; i++)
-			open_counters(cpumap[i], target_pid, forks);
+			open_counters(cpumap[i], pid);
 	}
 
 	if (file_new) {
tools/perf/builtin-record.c +156 -98

382 lines not on this page · raw message

tools/perf/builtin-stat.c +75 -35

206 lines not on this page · raw message

tools/perf/builtin-top.c +103 -55

252 lines not on this page · raw message

tools/perf/util/thread.c +32 -0
diff -Nraup linux-2.6_tip0317_statrecord/tools/perf/util/thread.c linux-2.6_tip0317_statrecordpid/tools/perf/util/thread.c
@@ -7,6 +7,37 @@
 #include "util.h"
 #include "debug.h"
 
+int find_all_tid(int pid, pid_t ** all_tid)
+{
+	char name[256];
+	int items;
+	struct dirent **namelist = NULL;
+	int ret = 0;
+	int i;
+
+	sprintf(name, "/proc/%d/task", pid);
+	items = scandir(name, &namelist, NULL, NULL);
+	if (items <= 0)
+                return -ENOENT;
+	*all_tid = malloc(sizeof(pid_t) * items);
+	if (!*all_tid) {
+		ret = -ENOMEM;
+		goto failure;
+	}
+
+	for (i = 0; i < items; i++)
+		(*all_tid)[i] = atoi(namelist[i]->d_name);
+
+	ret = items;
+
+failure:
+	for (i=0; i<items; i++)
+		free(namelist[i]);
+	free(namelist);
+
+	return ret;
+}
+
 void map_groups__init(struct map_groups *self)
 {
 	int i;
@@ -348,3 +379,4 @@ struct symbol *map_groups__find_symbol(s
 
 	return NULL;
 }
+
tools/perf/util/thread.h +1 -0
diff -Nraup linux-2.6_tip0317_statrecord/tools/perf/util/thread.h linux-2.6_tip0317_statrecordpid/tools/perf/util/thread.h
@@ -23,6 +23,7 @@ struct thread {
 	int			comm_len;
 };
 
+int find_all_tid(int pid, pid_t ** all_tid);
 void map_groups__init(struct map_groups *self);
 int thread__set_comm(struct thread *self, const char *comm);
 int thread__comm_len(struct thread *self);
#341 lore raw
Quoted 1 line · Zhang, Yanmin

I worked out 3 new patches against tip/master tree of Mar. 17th.

Cool! Mind sending them as a series of patches instead of attachment? That makes it easier to review them. Also, the Signed-off-by lines seem to be missing plus we need a per patch changelog as well.

Thanks,

Ingo

#342 lore raw

Em Thu, Mar 18, 2010 at 09:03:25AM +0100, Ingo Molnar escreveu:

Quoted 8 lines · Zhang, Yanmin
Quoted 2 lines

I worked out 3 new patches against tip/master tree of Mar. 17th.

Cool! Mind sending them as a series of patches instead of attachment? That makes it easier to review them. Also, the Signed-off-by lines seem to be missing plus we need a per patch changelog as well.

Yeah, please, and I hadn't merged them, so the resend was the best thing to do.

- Arnaldo

#343 lore raw
In reply to Zhang, Yanmin
Quoted 10 lines · Yanmin
Quoted 6 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

That certainly works, though automatic association of guest data with guest symbols is friendlier.

Quoted 30 lines
Quoted 29 lines
Quoted 28 lines

diff -Nraup linux-2.6_tipmaster0315/arch/x86/kvm/vmx.c linux-2.6_tipmaster0315_perfkvm/arch/x86/kvm/vmx.c

arch/x86/kvm/vmx.c +12 -0
@@ -26,6 +26,7 @@
   #include<linux/sched.h>
   #include<linux/moduleparam.h>
   #include<linux/ftrace_event.h>
+#include<linux/perf_event.h>
   #include "kvm_cache_regs.h"
   #include "x86.h"
 
@@ -3632,6 +3633,43 @@ static void update_cr8_intercept(struct
   	vmcs_write32(TPR_THRESHOLD, irr);
   }
 
+DEFINE_PER_CPU(int, kvm_in_guest) = {0};
+
+static void kvm_set_in_guest(void)
+{
+	percpu_write(kvm_in_guest, 1);
+}
+
+static int kvm_is_in_guest(void)
+{
+	return percpu_read(kvm_in_guest);
+}
 
 
Quoted 6 lines
Quoted 2 lines

There is already PF_VCPU for this.

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it. I guess NMIs will be disabled until the next IRET so it isn't racy, just tricky.

Quoted 10 lines
Quoted 10 lines

arch/x86/kvm/vmx.c static void update_cr8_intercept(struct

Quoted 8 lines
arch/x86/kvm/vmx.c +6 -0
+static struct perf_guest_info_callbacks kvm_guest_cbs = {
+	.is_in_guest 		= kvm_is_in_guest,
+	.is_user_mode		= kvm_is_user_mode,
+	.get_guest_ip		= kvm_get_guest_ip,
+	.reset_in_guest		= kvm_reset_in_guest,
+};
 

Should be in common code, not vmx specific.

Quoted 4 lines

Right. I discussed with Yangsheng. I will move above data structures and callbacks to file arch/x86/kvm/x86.c, and add get_ip, a new callback to kvm_x86_ops.

You will need access to the vcpu pointer (kvm_rip_read() needs it), you can put it in a percpu variable. I guess if it's not null, you know you're in a guest, so no need for PF_VCPU.

Signature · 1 line
error compiling committee.c: too many arguments to function
#344 lore raw
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Yanmin
Quoted 6 lines

Excellent, support for guest kernel != host kernel is critical (I can't remember the last time I ran same kernels).

How would we support multiple guests with different kernels?

Quoted 7 lines
Quoted 4 lines

With the patch, 'perf kvm report --sort pid" could show
summary statistics for all guest os instances. Then, use
parameter --pid of 'perf kvm record' to collect single problematic instance data.

That certainly works, though automatic association of guest data with guest symbols is friendlier.

Thanks. Originally, I planed to add a -G parameter to perf. Such like
-G 8888:/XXX/XXX/guestkallsyms:/XXX/XXX/modules,8889:/XXX/XXX/guestkallsyms:/XXX/XXX/modules 8888 and 8889 are just qemu guest pid.

So we could define multiple guest os symbol files. But it seems ugly, and 'perf kvm report --sort pid" and 'perf kvm top --pid' could provide similar functionality.

Quoted 41 lines
Quoted 31 lines
Quoted 30 lines
Quoted 29 lines

diff -Nraup linux-2.6_tipmaster0315/arch/x86/kvm/vmx.c linux-2.6_tipmaster0315_perfkvm/arch/x86/kvm/vmx.c

arch/x86/kvm/vmx.c +12 -0
@@ -26,6 +26,7 @@
   #include<linux/sched.h>
   #include<linux/moduleparam.h>
   #include<linux/ftrace_event.h>
+#include<linux/perf_event.h>
   #include "kvm_cache_regs.h"
   #include "x86.h"
 
@@ -3632,6 +3633,43 @@ static void update_cr8_intercept(struct
   	vmcs_write32(TPR_THRESHOLD, irr);
   }
 
+DEFINE_PER_CPU(int, kvm_in_guest) = {0};
+
+static void kvm_set_in_guest(void)
+{
+	percpu_write(kvm_in_guest, 1);
+}
+
+static int kvm_is_in_guest(void)
+{
+	return percpu_read(kvm_in_guest);
+}
 
 
Quoted 6 lines
Quoted 2 lines

There is already PF_VCPU for this.

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Quoted 6 lines

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

arch/x86/kvm/vmx.c static void update_cr8_intercept(struct

Quoted 9 lines
arch/x86/kvm/vmx.c +6 -0
+static struct perf_guest_info_callbacks kvm_guest_cbs = {
+	.is_in_guest 		= kvm_is_in_guest,
+	.is_user_mode		= kvm_is_user_mode,
+	.get_guest_ip		= kvm_get_guest_ip,
+	.reset_in_guest		= kvm_reset_in_guest,
+};
 

Should be in common code, not vmx specific.

Quoted 7 lines
Quoted 4 lines

Right. I discussed with Yangsheng. I will move above data structures and callbacks to file arch/x86/kvm/x86.c, and add get_ip, a new callback to kvm_x86_ops.

You will need access to the vcpu pointer (kvm_rip_read() needs it), you can put it in a percpu variable.

We do so now in a new patch.

Quoted 2 lines

I guess if it's not null, you know
you're in a guest, so no need for PF_VCPU.

Good suggestion.

Thanks.

#345 lore raw
Quoted 13 lines · Yanmin
Quoted 12 lines · Avi Kivity
Quoted 3 lines · Yanmin

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

Quoted 5 lines
Quoted 2 lines

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

Signature · 2 lines
regards
Yang, Sheng
#346 lore raw
Quoted 4 lines · Sheng Yang
Quoted 4 lines

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

Quoted 9 lines

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

That's pretty bad, as NMI runs on a separate stack (via IST). So if another NMI happens while our int $2 is running, the stack will be corrupted.

Quoted 7 lines

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

I think you need DM_NMI for that to work correctly.

An alternative is to call the NMI handler directly.

Signature · 1 line
error compiling committee.c: too many arguments to function
#347 lore raw
Quoted 10 lines · On Wednesday 17 March 2010 17:41:58 Avi Kivity wrote:
Quoted 9 lines · Sheng Yang
Quoted 3 lines

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

Quoted 7 lines
Quoted 3 lines

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

That's pretty bad, as NMI runs on a separate stack (via IST). So if another NMI happens while our int $2 is running, the stack will be corrupted.

Though hardware didn't provide this kind of block, software at least would warn about it... nmi_enter() still would be executed by "int $2", and result in BUG() if we are already in NMI context(OK, it is a little better than mysterious crash due to corrupted stack).

Quoted 11 lines
Quoted 7 lines

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

I think you need DM_NMI for that to work correctly.

An alternative is to call the NMI handler directly.

apic_send_IPI_self() already took care of APIC_DM_NMI.

And NMI handler would block the following NMI?

Signature · 2 lines
regards
Yang, Sheng
#348 lore raw
Quoted 7 lines · Sheng Yang
Quoted 5 lines

I think you need DM_NMI for that to work correctly.

An alternative is to call the NMI handler directly.

apic_send_IPI_self() already took care of APIC_DM_NMI.

So it does (though not for x2apic?). I don't see why it doesn't work.

Quoted 3 lines

And NMI handler would block the following NMI?

It wouldn't - won't work without extensive changes.

Signature · 1 line
error compiling committee.c: too many arguments to function
#349 lore raw
In reply to Sheng Yang
Quoted 32 lines · Sheng Yang
Quoted 15 lines · Yanmin
Quoted 13 lines · Avi Kivity
Quoted 4 lines · Yanmin

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

Quoted 6 lines
Quoted 3 lines

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

Quoted 7 lines

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

You can't use the APIC to send vectors 0x00-0x1f, or at least, aren't supposed to be able to.

Zach

#350 lore raw
Quoted 35 lines · On Thursday 18 March 2010 05:14:52 Zachary Amsden wrote:
Quoted 34 lines · Sheng Yang
Quoted 13 lines · Yanmin
Quoted 12 lines · Avi Kivity
Quoted 3 lines · Yanmin

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

Quoted 6 lines
Quoted 2 lines

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

Quoted 5 lines
Quoted 2 lines

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

You can't use the APIC to send vectors 0x00-0x1f, or at least, aren't supposed to be able to.

Um? Why?

Especially kernel is already using it to deliver NMI.

Signature · 2 lines
regards
Yang, Sheng
#351 lore raw
Quoted 44 lines · Sheng Yang
Quoted 42 lines · On Thursday 18 March 2010 05:14:52 Zachary Amsden wrote:
Quoted 40 lines · Sheng Yang
Quoted 15 lines · Yanmin
Quoted 13 lines · Avi Kivity
Quoted 4 lines · Yanmin

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

Quoted 7 lines
Quoted 3 lines

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

Quoted 8 lines
Quoted 3 lines

You can't use the APIC to send vectors 0x00-0x1f, or at least, aren't supposed to be able to.

Um? Why?

Especially kernel is already using it to deliver NMI.

That's the only defined case, and it is defined because the vector field is ignore for DM_NMI. Vol 3A (exact section numbers may vary depending on your version).

8.5.1 / 8.6.1

'100 (NMI) Delivers an NMI interrupt to the target processor or processors. The vector information is ignored'

8.5.2 Valid Interrupt Vectors

'Local and I/O APICs support 240 of these vectors (in the range of 16 to 255) as valid interrupts.'

8.8.4 Interrupt Acceptance for Fixed Interrupts

'...; vectors 0 through 15 are reserved by the APIC (see also: Section 8.5.2, "Valid Interrupt Vectors")'

So I misremembered, apparently you can deliver interrupts 0x10-0x1f, but vectors 0x00-0x0f are not valid to send via APIC or I/O APIC.

Zach

#352 lore raw
Quoted 62 lines · On Thursday 18 March 2010 12:50:58 Zachary Amsden wrote:
Quoted 40 lines · Sheng Yang
Quoted 39 lines · On Thursday 18 March 2010 05:14:52 Zachary Amsden wrote:
Quoted 37 lines · Sheng Yang
Quoted 13 lines · Yanmin
Quoted 12 lines · Avi Kivity
Quoted 3 lines · Yanmin

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

Quoted 6 lines
Quoted 2 lines

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

Quoted 6 lines
Quoted 2 lines

You can't use the APIC to send vectors 0x00-0x1f, or at least, aren't supposed to be able to.

Um? Why?

Especially kernel is already using it to deliver NMI.

That's the only defined case, and it is defined because the vector field is ignore for DM_NMI. Vol 3A (exact section numbers may vary depending on your version).

8.5.1 / 8.6.1

'100 (NMI) Delivers an NMI interrupt to the target processor or processors. The vector information is ignored'

8.5.2 Valid Interrupt Vectors

'Local and I/O APICs support 240 of these vectors (in the range of 16 to
255) as valid interrupts.'

Quoted 7 lines

8.8.4 Interrupt Acceptance for Fixed Interrupts

'...; vectors 0 through 15 are reserved by the APIC (see also: Section 8.5.2, "Valid Interrupt Vectors")'

So I misremembered, apparently you can deliver interrupts 0x10-0x1f, but vectors 0x00-0x0f are not valid to send via APIC or I/O APIC.

As you pointed out, NMI is not "Fixed interrupt". If we want to send NMI, it would need a specific delivery mode rather than vector number.

And if you look at code, if we specific NMI_VECTOR, the delivery mode would be set to NMI.

So what's wrong here?

Signature · 2 lines
regards
Yang, Sheng
#353 lore raw
Quoted 72 lines · On Thursday 18 March 2010 13:22:28 Sheng Yang wrote:
Quoted 63 lines · On Thursday 18 March 2010 12:50:58 Zachary Amsden wrote:
Quoted 41 lines · Sheng Yang
Quoted 40 lines · On Thursday 18 March 2010 05:14:52 Zachary Amsden wrote:
Quoted 38 lines · Sheng Yang
Quoted 14 lines · Yanmin
Quoted 13 lines · Avi Kivity
Quoted 3 lines · Yanmin

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

Quoted 6 lines
Quoted 2 lines

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

Quoted 6 lines
Quoted 2 lines

You can't use the APIC to send vectors 0x00-0x1f, or at least, aren't supposed to be able to.

Um? Why?

Especially kernel is already using it to deliver NMI.

That's the only defined case, and it is defined because the vector field is ignore for DM_NMI. Vol 3A (exact section numbers may vary depending on your version).

8.5.1 / 8.6.1

'100 (NMI) Delivers an NMI interrupt to the target processor or processors. The vector information is ignored'

8.5.2 Valid Interrupt Vectors

'Local and I/O APICs support 240 of these vectors (in the range of 16 to
255) as valid interrupts.'

Quoted 7 lines

8.8.4 Interrupt Acceptance for Fixed Interrupts

'...; vectors 0 through 15 are reserved by the APIC (see also: Section 8.5.2, "Valid Interrupt Vectors")'

So I misremembered, apparently you can deliver interrupts 0x10-0x1f, but vectors 0x00-0x0f are not valid to send via APIC or I/O APIC.

Quoted 7 lines

As you pointed out, NMI is not "Fixed interrupt". If we want to send NMI,
it would need a specific delivery mode rather than vector number.

And if you look at code, if we specific NMI_VECTOR, the delivery mode would
be set to NMI.

So what's wrong here?

OK, I think I understand your points now. You meant that these vectors can't be filled in vector field directly, right? But NMI is a exception due to DM_NMI. Is that your point? I think we agree on this.

Signature · 2 lines
regards
Yang, Sheng
#354 lore raw
Quoted 84 lines · Sheng Yang
Quoted 82 lines · On Thursday 18 March 2010 13:22:28 Sheng Yang wrote:
Quoted 69 lines · On Thursday 18 March 2010 12:50:58 Zachary Amsden wrote:
Quoted 46 lines · Sheng Yang
Quoted 44 lines · On Thursday 18 March 2010 05:14:52 Zachary Amsden wrote:
Quoted 42 lines · Sheng Yang
Quoted 16 lines · Yanmin
Quoted 14 lines · Avi Kivity
Quoted 4 lines · Yanmin

Right, but there is a scope between kvm_guest_enter and really running in guest os, where a perf event might overflow. Anyway, the scope is very narrow, I will change it to use flag PF_VCPU.

There is also a window between setting the flag and calling 'int $2' where an NMI might happen and be accounted incorrectly.

Perhaps separate the 'int $2' into a direct call into perf and another call for the rest of NMI handling. I don't see how it would work on svm though - AFAICT the NMI is held whereas vmx swallows it.

Quoted 7 lines
Quoted 3 lines

I guess NMIs
will be disabled until the next IRET so it isn't racy, just tricky.

I'm not sure if vmexit does break NMI context or not. Hardware NMI context isn't reentrant till a IRET. YangSheng would like to double check it.

After more check, I think VMX won't remained NMI block state for host. That's means, if NMI happened and processor is in VMX non-root mode, it would only result in VMExit, with a reason indicate that it's due to NMI happened, but no more state change in the host.

So in that meaning, there _is_ a window between VMExit and KVM handle the NMI. Moreover, I think we _can't_ stop the re-entrance of NMI handling code because "int $2" don't have effect to block following NMI.

And if the NMI sequence is not important(I think so), then we need to generate a real NMI in current vmexit-after code. Seems let APIC send a NMI IPI to itself is a good idea.

I am debugging a patch based on apic->send_IPI_self(NMI_VECTOR) to replace "int $2". Something unexpected is happening...

Quoted 7 lines
Quoted 3 lines

You can't use the APIC to send vectors 0x00-0x1f, or at least, aren't supposed to be able to.

Um? Why?

Especially kernel is already using it to deliver NMI.

That's the only defined case, and it is defined because the vector field is ignore for DM_NMI. Vol 3A (exact section numbers may vary depending on your version).

8.5.1 / 8.6.1

'100 (NMI) Delivers an NMI interrupt to the target processor or processors. The vector information is ignored'

8.5.2 Valid Interrupt Vectors

'Local and I/O APICs support 240 of these vectors (in the range of 16 to
255) as valid interrupts.'

Quoted 8 lines

8.8.4 Interrupt Acceptance for Fixed Interrupts

'...; vectors 0 through 15 are reserved by the APIC (see also: Section 8.5.2, "Valid Interrupt Vectors")'

So I misremembered, apparently you can deliver interrupts 0x10-0x1f, but vectors 0x00-0x0f are not valid to send via APIC or I/O APIC.

As you pointed out, NMI is not "Fixed interrupt". If we want to send NMI,
it would need a specific delivery mode rather than vector number.

Quoted 9 lines
Quoted 5 lines

And if you look at code, if we specific NMI_VECTOR, the delivery mode would
be set to NMI.

So what's wrong here?

OK, I think I understand your points now. You meant that these vectors can't be filled in vector field directly, right? But NMI is a exception due to DM_NMI. Is that your point? I think we agree on this.

Yes, I think we agree. NMI is the only vector in 0x0-0xf which can be sent via self-IPI because the vector itself does not matter for NMI.

Zach

#355 lore raw

PATCH 1/1 Enhance perf to collect KVM guest os statistics from host side

In reply to Zhang, Yanmin
Quoted 2 lines · Yanmin

From: Zhang, Yanmin <[email protected]>

Here is the new patch of V2 against tip/master of March 17th if anyone wants to try it.

ChangeLog V2:
1) Based on Avi's suggestion, I moved callback functions to generic code area. So the kernel part of the patch is clearer.
2) Add 'perf kvm stat'.

From: Zhang, Yanmin <[email protected]>

Based on the discussion in KVM community, I worked out the patch to support perf to collect guest os statistics from host side. This patch is implemented with Ingo, Peter and some other guys' kind help. Yang Sheng pointed out a critical bug and provided good suggestions with other guys. I really appreciate their kind help.

The patch adds new subcommand kvm to perf.

perf kvm top
perf kvm record
perf kvm report
perf kvm diff
perf kvm stat

The new perf could profile guest os kernel except guest os user space, but it could summarize guest os user space utilization per guest os.

Below are some examples.
1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

--------------------------------------------------------------------------------------------------------------------------
PerfTop: 16010 irqs/sec kernel:59.1% us: 1.5% guest kernel:31.9% guest us: 7.5% exact: 0.0% [1000Hz cycles], (all, 16 CPUs)
--------------------------------------------------------------------------------------------------------------------------

             samples  pcnt function                  DSO
             _______ _____ _________________________ _______________________

            38770.00 20.4% __ticket_spin_lock        [guest.kernel.kallsyms]
            22560.00 11.9% ftrace_likely_update      [kernel.kallsyms]
             9208.00  4.8% __lock_acquire            [kernel.kallsyms]
             5473.00  2.9% trace_hardirqs_off_caller [kernel.kallsyms]
             5222.00  2.7% copy_user_generic_string  [guest.kernel.kallsyms]
             4450.00  2.3% validate_chain            [kernel.kallsyms]
             4262.00  2.2% trace_hardirqs_on_caller  [kernel.kallsyms]
             4239.00  2.2% do_raw_spin_lock          [kernel.kallsyms]
             3548.00  1.9% do_raw_spin_unlock        [kernel.kallsyms]
             2487.00  1.3% lock_release              [kernel.kallsyms]
             2165.00  1.1% __local_bh_disable        [kernel.kallsyms]
             1905.00  1.0% check_chain_key           [kernel.kallsyms]
             1737.00  0.9% lock_acquire              [kernel.kallsyms]
             1604.00  0.8% tcp_recvmsg               [kernel.kallsyms]
             1524.00  0.8% mark_lock                 [kernel.kallsyms]
             1464.00  0.8% schedule                  [kernel.kallsyms]
             1423.00  0.7% __d_lookup                [guest.kernel.kallsyms]

If you want to just show host data, pls. don't use parameter --guest. The headline includes guest os kernel and userspace percentage.

2) perf kvm record
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules record -f -a sleep 60
[ perf record: Woken up 15 times to write data ]
[ perf record: Captured and wrote 29.385 MB perf.data.kvm (~1283837 samples) ]

3) perf kvm report

        3.1) [root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms

--guestmodules=/home/ymzhang/guest/modules report --sort pid --showcpuutilization>norm.host.guest.report.pid # Samples: 424719292247
#
# Overhead sys us guest sys guest us Command: Pid

# ........  .....................
#
    50.57%     1.02%     0.00%    39.97%     9.58%  qemu-system-x86: 3587
    49.32%     1.35%     0.01%    35.20%    12.76%  qemu-system-x86: 3347
     0.07%     0.07%     0.00%     0.00%     0.00%             perf: 5217

Some performance guys require perf to show sys/us/guest_sys/guest_us per KVM guest instance which is actually just a multi-threaded process. Above sub parameter --showcpuutilization does so.

        3.2) [root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms

--guestmodules=/home/ymzhang/guest/modules report >norm.host.guest.report # Samples: 2466991384118
#
# Overhead Command Shared Object Symbol

# ........  ...............  ........................................................................  ......
#
    29.11%  qemu-system-x86  [guest.kernel.kallsyms]                                                   [g] __ticket_spin_lock
     5.88%       tbench_srv  [kernel.kallsyms]                                                         [k] ftrace_likely_update
     5.76%           tbench  [kernel.kallsyms]                                                         [k] ftrace_likely_update
     3.88%  qemu-system-x86                                                                34c3255482  [u] 0x000034c3255482
     1.83%           tbench  [kernel.kallsyms]                                                         [k] __lock_acquire
     1.81%       tbench_srv  [kernel.kallsyms]                                                         [k] __lock_acquire
     1.38%       tbench_srv  [kernel.kallsyms]                                                         [k] trace_hardirqs_off_caller
     1.37%           tbench  [kernel.kallsyms]                                                         [k] trace_hardirqs_off_caller
     1.13%  qemu-system-x86  [guest.kernel.kallsyms]                                                   [g] copy_user_generic_string
     1.04%       tbench_srv  [kernel.kallsyms]                                                         [k] validate_chain
     1.00%           tbench  [kernel.kallsyms]                                                         [k] trace_hardirqs_on_caller
     1.00%       tbench_srv  [kernel.kallsyms]                                                         [k] trace_hardirqs_on_caller
     0.95%           tbench  [kernel.kallsyms]                                                         [k] do_raw_spin_lock

[u] means it's in guest os user space. [g] means in guest os kernel. Other info is very direct. If it shows a module such like [ext4], it means guest kernel module, because native host kernel's modules are start from something like /lib/modules/XXX.

Below is the patch against tip/master tree of 17th March.

---

arch/x86/include/asm/perf_event.h +4 -11
diff -Nraup linux-2.6_tip0317/arch/x86/include/asm/perf_event.h linux-2.6_tip0317_perfkvm/arch/x86/include/asm/perf_event.h
@@ -143,17 +143,10 @@ extern void perf_events_lapic_init(void)
  */
 #define PERF_EFLAGS_EXACT	(1UL << 3)
 
-#define perf_misc_flags(regs)				\
-({	int misc = 0;					\
-	if (user_mode(regs))				\
-		misc |= PERF_RECORD_MISC_USER;		\
-	else						\
-		misc |= PERF_RECORD_MISC_KERNEL;	\
-	if (regs->flags & PERF_EFLAGS_EXACT)		\
-		misc |= PERF_RECORD_MISC_EXACT;		\
-	misc; })
-
-#define perf_instruction_pointer(regs)	((regs)->ip)
+struct pt_regs;
+extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
+extern unsigned long perf_misc_flags(struct pt_regs *regs);
+#define perf_misc_flags(regs)	perf_misc_flags(regs)
 
 #else
 static inline void init_hw_perf_events(void)		{ }
arch/x86/kernel/cpu/perf_event.c +27 -0
diff -Nraup linux-2.6_tip0317/arch/x86/kernel/cpu/perf_event.c linux-2.6_tip0317_perfkvm/arch/x86/kernel/cpu/perf_event.c
@@ -1708,3 +1708,30 @@ void perf_arch_fetch_caller_regs(struct 
 	local_save_flags(regs->flags);
 }
 #endif
+
+unsigned long perf_instruction_pointer(struct pt_regs *regs)
+{
+	unsigned long ip;
+	if (perf_guest_cbs && perf_guest_cbs->is_in_guest())
+		ip = perf_guest_cbs->get_guest_ip();
+	else
+		ip = instruction_pointer(regs);
+	return ip;
+}
+
+unsigned long perf_misc_flags(struct pt_regs *regs)
+{
+	int misc = 0;
+	if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) {
+		misc |= perf_guest_cbs->is_user_mode() ?
+			PERF_RECORD_MISC_GUEST_USER :
+			PERF_RECORD_MISC_GUEST_KERNEL;
+	} else
+		misc |= user_mode(regs) ? PERF_RECORD_MISC_USER :
+			PERF_RECORD_MISC_KERNEL;
+	if (regs->flags & PERF_EFLAGS_EXACT)
+		misc |= PERF_RECORD_MISC_EXACT;
+
+	return misc;
+}
+
arch/x86/kvm/x86.c +36 -0
diff -Nraup linux-2.6_tip0317/arch/x86/kvm/x86.c linux-2.6_tip0317_perfkvm/arch/x86/kvm/x86.c
@@ -3764,6 +3764,35 @@ static void kvm_timer_init(void)
 	}
 }
 
+static DEFINE_PER_CPU(struct kvm_vcpu *, current_vcpu);
+
+static int kvm_is_in_guest(void)
+{
+	return percpu_read(current_vcpu) != NULL;
+}
+
+static int kvm_is_user_mode(void)
+{
+	int user_mode = 3;
+	if (percpu_read(current_vcpu))
+		user_mode = kvm_x86_ops->get_cpl(percpu_read(current_vcpu));
+	return user_mode != 0;
+}
+
+static unsigned long kvm_get_guest_ip(void)
+{
+	unsigned long ip = 0;
+	if (percpu_read(current_vcpu))
+		ip = kvm_rip_read(percpu_read(current_vcpu));
+	return ip;
+}
+
+static struct perf_guest_info_callbacks kvm_guest_cbs = {
+	.is_in_guest            = kvm_is_in_guest,
+	.is_user_mode           = kvm_is_user_mode,
+	.get_guest_ip           = kvm_get_guest_ip,
+};
+
 int kvm_arch_init(void *opaque)
 {
 	int r;
@@ -3800,6 +3829,8 @@ int kvm_arch_init(void *opaque)
 
 	kvm_timer_init();
 
+	perf_register_guest_info_callbacks(&kvm_guest_cbs);
+
 	return 0;
 
 out:
@@ -3808,6 +3839,8 @@ out:
 
 void kvm_arch_exit(void)
 {
+	perf_unregister_guest_info_callbacks(&kvm_guest_cbs);
+
 	if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
 		cpufreq_unregister_notifier(&kvmclock_cpufreq_notifier_block,
 					    CPUFREQ_TRANSITION_NOTIFIER);
@@ -4338,7 +4371,10 @@ static int vcpu_enter_guest(struct kvm_v
 	}
 
 	trace_kvm_entry(vcpu->vcpu_id);
+
+	percpu_write(current_vcpu, vcpu);
 	kvm_x86_ops->run(vcpu);
+	percpu_write(current_vcpu, NULL);
 
 	/*
 	 * If the guest has used debug registers, at least dr7
include/linux/perf_event.h +20 -1
diff -Nraup linux-2.6_tip0317/include/linux/perf_event.h linux-2.6_tip0317_perfkvm/include/linux/perf_event.h
@@ -288,11 +288,13 @@ struct perf_event_mmap_page {
 	__u64	data_tail;		/* user-space written tail */
 };
 
-#define PERF_RECORD_MISC_CPUMODE_MASK		(3 << 0)
+#define PERF_RECORD_MISC_CPUMODE_MASK		(7 << 0)
 #define PERF_RECORD_MISC_CPUMODE_UNKNOWN	(0 << 0)
 #define PERF_RECORD_MISC_KERNEL			(1 << 0)
 #define PERF_RECORD_MISC_USER			(2 << 0)
 #define PERF_RECORD_MISC_HYPERVISOR		(3 << 0)
+#define PERF_RECORD_MISC_GUEST_KERNEL		(4 << 0)
+#define PERF_RECORD_MISC_GUEST_USER		(5 << 0)
 
 #define PERF_RECORD_MISC_EXACT			(1 << 14)
 /*
@@ -446,6 +448,12 @@ enum perf_callchain_context {
 # include <asm/perf_event.h>
 #endif
 
+struct perf_guest_info_callbacks {
+	int (*is_in_guest) (void);
+	int (*is_user_mode) (void);
+	unsigned long (*get_guest_ip) (void);
+};
+
 #ifdef CONFIG_HAVE_HW_BREAKPOINT
 #include <asm/hw_breakpoint.h>
 #endif
@@ -913,6 +921,12 @@ static inline void perf_event_mmap(struc
 		__perf_event_mmap(vma);
 }
 
+extern struct perf_guest_info_callbacks *perf_guest_cbs;
+extern int perf_register_guest_info_callbacks(
+		struct perf_guest_info_callbacks *);
+extern int perf_unregister_guest_info_callbacks(
+		struct perf_guest_info_callbacks *);
+
 extern void perf_event_comm(struct task_struct *tsk);
 extern void perf_event_fork(struct task_struct *tsk);
 
@@ -982,6 +996,11 @@ perf_sw_event(u32 event_id, u64 nr, int 
 static inline void
 perf_bp_event(struct perf_event *event, void *data)			{ }
 
+static inline int perf_register_guest_info_callbacks
+(struct perf_guest_info_callbacks *)   {return 0; }
+static inline int perf_unregister_guest_info_callbacks
+(struct perf_guest_info_callbacks *)   {return 0; }
+
 static inline void perf_event_mmap(struct vm_area_struct *vma)		{ }
 static inline void perf_event_comm(struct task_struct *tsk)		{ }
 static inline void perf_event_fork(struct task_struct *tsk)		{ }
kernel/perf_event.c +22 -1
diff -Nraup linux-2.6_tip0317/kernel/perf_event.c linux-2.6_tip0317_perfkvm/kernel/perf_event.c
@@ -2798,6 +2798,27 @@ void perf_arch_fetch_caller_regs(struct 
 #endif
 
 /*
+ * We assume there is only KVM supporting the callbacks.
+ * Later on, we might change it to a list if there is
+ * another virtualization implementation supporting the callbacks.
+ */
+struct perf_guest_info_callbacks *perf_guest_cbs;
+
+int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
+{
+	perf_guest_cbs = cbs;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(perf_register_guest_info_callbacks);
+
+int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
+{
+	perf_guest_cbs = NULL;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks);
+
+/*
  * Output
  */
 static bool perf_output_space(struct perf_mmap_data *data, unsigned long tail,
@@ -3740,7 +3761,7 @@ void __perf_event_mmap(struct vm_area_st
 		.event_id  = {
 			.header = {
 				.type = PERF_RECORD_MMAP,
-				.misc = 0,
+				.misc = PERF_RECORD_MISC_USER,
 				/* .size */
 			},
 			/* .pid */
tools/perf/builtin-diff.c +4 -1
diff -Nraup linux-2.6_tip0317/tools/perf/builtin-diff.c linux-2.6_tip0317_perfkvm/tools/perf/builtin-diff.c
@@ -33,7 +33,7 @@ static int perf_session__add_hist_entry(
 		return -ENOMEM;
 
 	if (hit)
-		he->count += count;
+		__perf_session__add_count(he, al, count);
 
 	return 0;
 }
@@ -225,6 +225,9 @@ int cmd_diff(int argc, const char **argv
 			input_new = argv[1];
 		} else
 			input_new = argv[0];
+	} else if (symbol_conf.guest_vmlinux_name || symbol_conf.guest_kallsyms) {
+		input_old = "perf.data.host";
+		input_new = "perf.data.guest";
 	}
 
 	symbol_conf.exclude_other = false;
tools/perf/builtin.h +1 -0
diff -Nraup linux-2.6_tip0317/tools/perf/builtin.h linux-2.6_tip0317_perfkvm/tools/perf/builtin.h
@@ -32,5 +32,6 @@ extern int cmd_version(int argc, const c
 extern int cmd_probe(int argc, const char **argv, const char *prefix);
 extern int cmd_kmem(int argc, const char **argv, const char *prefix);
 extern int cmd_lock(int argc, const char **argv, const char *prefix);
+extern int cmd_kvm(int argc, const char **argv, const char *prefix);
 
 #endif
tools/perf/builtin-kvm.c +125 -0

125 lines not on this page · raw message

tools/perf/builtin-record.c +42 -2

60 lines not on this page · raw message

tools/perf/builtin-report.c +3 -1
diff -Nraup linux-2.6_tip0317/tools/perf/builtin-report.c linux-2.6_tip0317_perfkvm/tools/perf/builtin-report.c
@@ -104,7 +104,7 @@ static int perf_session__add_hist_entry(
 		return -ENOMEM;
 
 	if (hit)
-		he->count += data->period;
+		__perf_session__add_count(he, al,  data->period);
 
 	if (symbol_conf.use_callchain) {
 		if (!hit)
@@ -428,6 +428,8 @@ static const struct option options[] = {
 		   "sort by key(s): pid, comm, dso, symbol, parent"),
 	OPT_BOOLEAN('P', "full-paths", &symbol_conf.full_paths,
 		    "Don't shorten the pathnames taking into account the cwd"),
+	OPT_BOOLEAN(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
+		    "Show sample percentage for different cpu modes"),
 	OPT_STRING('p', "parent", &parent_pattern, "regex",
 		   "regex filter to identify parent, see: '--sort parent'"),
 	OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other,
tools/perf/builtin-top.c +34 -7

75 lines not on this page · raw message

tools/perf/Makefile +1 -0
diff -Nraup linux-2.6_tip0317/tools/perf/Makefile linux-2.6_tip0317_perfkvm/tools/perf/Makefile
@@ -462,6 +462,7 @@ BUILTIN_OBJS += builtin-trace.o
 BUILTIN_OBJS += builtin-probe.o
 BUILTIN_OBJS += builtin-kmem.o
 BUILTIN_OBJS += builtin-lock.o
+BUILTIN_OBJS += builtin-kvm.o
 
 PERFLIBS = $(LIB_FILE)
 
tools/perf/perf.c +1 -0
diff -Nraup linux-2.6_tip0317/tools/perf/perf.c linux-2.6_tip0317_perfkvm/tools/perf/perf.c
@@ -308,6 +308,7 @@ static void handle_internal_command(int 
 		{ "probe",	cmd_probe,	0 },
 		{ "kmem",	cmd_kmem,	0 },
 		{ "lock",	cmd_lock,	0 },
+		{ "kvm",	cmd_kvm,	0 },
 	};
 	unsigned int i;
 	static const char ext[] = STRIP_EXTENSION;
tools/perf/perf.h +2 -0
diff -Nraup linux-2.6_tip0317/tools/perf/perf.h linux-2.6_tip0317_perfkvm/tools/perf/perf.h
@@ -133,4 +133,6 @@ struct ip_callchain {
 	u64 ips[0];
 };
 
+extern int perf_host, perf_guest;
+
 #endif
tools/perf/util/event.c +151 -40

293 lines not on this page · raw message

tools/perf/util/event.h +10 -3
diff -Nraup linux-2.6_tip0317/tools/perf/util/event.h linux-2.6_tip0317_perfkvm/tools/perf/util/event.h
@@ -119,10 +119,17 @@ int event__synthesize_thread(pid_t pid, 
 void event__synthesize_threads(event__handler_t process,
 			       struct perf_session *session);
 int event__synthesize_kernel_mmap(event__handler_t process,
-				  struct perf_session *session,
-				  const char *symbol_name);
+				struct perf_session *session,
+				const char *kallsyms_name,
+				const char *mmap_name,
+				struct map **maps,
+				const char *symbol_name,
+				unsigned int misc);
+
 int event__synthesize_modules(event__handler_t process,
-			      struct perf_session *session);
+			      struct perf_session *session,
+			      struct map_groups *kmaps,
+			      unsigned int misc);
 
 int event__process_comm(event_t *self, struct perf_session *session);
 int event__process_lost(event_t *self, struct perf_session *session);
tools/perf/util/hist.c +63 -4

110 lines not on this page · raw message

tools/perf/util/hist.h +3 -0
diff -Nraup linux-2.6_tip0317/tools/perf/util/hist.h linux-2.6_tip0317_perfkvm/tools/perf/util/hist.h
@@ -12,6 +12,9 @@ struct addr_location;
 struct symbol;
 struct rb_root;
 
+void __perf_session__add_count(struct hist_entry *he,
+			struct addr_location *al,
+			u64 count);
 struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
 						  struct addr_location *al,
 						  struct symbol *parent,
tools/perf/util/session.c +23 -9
diff -Nraup linux-2.6_tip0317/tools/perf/util/session.c linux-2.6_tip0317_perfkvm/tools/perf/util/session.c
@@ -54,7 +54,12 @@ out_close:
 
 static inline int perf_session__create_kernel_maps(struct perf_session *self)
 {
-	return map_groups__create_kernel_maps(&self->kmaps, self->vmlinux_maps);
+	int ret;
+	ret = map_groups__create_kernel_maps(&self->kmaps, self->vmlinux_maps);
+	if (ret >= 0)
+		ret = map_groups__create_guest_kernel_maps(&self->guest_kmaps,
+				self->guest_vmlinux_maps);
+	return ret;
 }
 
 struct perf_session *perf_session__new(const char *filename, int mode, bool force)
@@ -77,6 +82,7 @@ struct perf_session *perf_session__new(c
 	self->cwdlen = 0;
 	self->unknown_events = 0;
 	map_groups__init(&self->kmaps);
+	map_groups__init(&self->guest_kmaps);
 
 	if (mode == O_RDONLY) {
 		if (perf_session__open(self, force) < 0)
@@ -356,7 +362,8 @@ int perf_header__read_build_ids(struct p
 		if (read(input, filename, len) != len)
 			goto out;
 
-		if (bev.header.misc & PERF_RECORD_MISC_KERNEL)
+		if ((bev.header.misc & PERF_RECORD_MISC_CPUMODE_MASK)
+			==  PERF_RECORD_MISC_KERNEL)
 			head = &dsos__kernel;
 
 		dso = __dsos__findnew(head, filename);
@@ -519,26 +526,33 @@ bool perf_session__has_traces(struct per
 	return true;
 }
 
-int perf_session__set_kallsyms_ref_reloc_sym(struct perf_session *self,
+int perf_session__set_kallsyms_ref_reloc_sym(struct map ** maps,
 					     const char *symbol_name,
 					     u64 addr)
 {
 	char *bracket;
 	enum map_type i;
+	struct ref_reloc_sym *ref;
 
-	self->ref_reloc_sym.name = strdup(symbol_name);
-	if (self->ref_reloc_sym.name == NULL)
+	ref = zalloc(sizeof(struct ref_reloc_sym));
+	if (ref == NULL)
 		return -ENOMEM;
 
-	bracket = strchr(self->ref_reloc_sym.name, ']');
+	ref->name = strdup(symbol_name);
+	if (ref->name == NULL) {
+		free(ref);
+		return -ENOMEM;
+	}
+
+	bracket = strchr(ref->name, ']');
 	if (bracket)
 		*bracket = '\0';
 
-	self->ref_reloc_sym.addr = addr;
+	ref->addr = addr;
 
 	for (i = 0; i < MAP__NR_TYPES; ++i) {
-		struct kmap *kmap = map__kmap(self->vmlinux_maps[i]);
-		kmap->ref_reloc_sym = &self->ref_reloc_sym;
+		struct kmap *kmap = map__kmap(maps[i]);
+		kmap->ref_reloc_sym = ref;
 	}
 
 	return 0;
tools/perf/util/session.h +3 -16
diff -Nraup linux-2.6_tip0317/tools/perf/util/session.h linux-2.6_tip0317_perfkvm/tools/perf/util/session.h
@@ -16,16 +16,17 @@ struct perf_session {
 	unsigned long		size;
 	unsigned long		mmap_window;
 	struct map_groups	kmaps;
+	struct map_groups	guest_kmaps;
 	struct rb_root		threads;
 	struct thread		*last_match;
 	struct map		*vmlinux_maps[MAP__NR_TYPES];
+	struct map		*guest_vmlinux_maps[MAP__NR_TYPES];
 	struct events_stats	events_stats;
 	struct rb_root		stats_by_id;
 	unsigned long		event_total[PERF_RECORD_MAX];
 	unsigned long		unknown_events;
 	struct rb_root		hists;
 	u64			sample_type;
-	struct ref_reloc_sym	ref_reloc_sym;
 	int			fd;
 	int			cwdlen;
 	char			*cwd;
@@ -67,26 +68,12 @@ bool perf_session__has_traces(struct per
 int perf_header__read_build_ids(struct perf_header *self, int input,
 				u64 offset, u64 file_size);
 
-int perf_session__set_kallsyms_ref_reloc_sym(struct perf_session *self,
+int perf_session__set_kallsyms_ref_reloc_sym(struct map ** maps,
 					     const char *symbol_name,
 					     u64 addr);
 
 void mem_bswap_64(void *src, int byte_size);
 
-static inline int __perf_session__create_kernel_maps(struct perf_session *self,
-						struct dso *kernel)
-{
-	return __map_groups__create_kernel_maps(&self->kmaps,
-						self->vmlinux_maps, kernel);
-}
-
-static inline struct map *
-	perf_session__new_module_map(struct perf_session *self,
-				     u64 start, const char *filename)
-{
-	return map_groups__new_module(&self->kmaps, start, filename);
-}
-
 #ifdef NO_NEWT_SUPPORT
 static inline void perf_session__browse_hists(struct rb_root *hists __used,
 					      u64 session_total __used,
tools/perf/util/sort.h +4 -0
diff -Nraup linux-2.6_tip0317/tools/perf/util/sort.h linux-2.6_tip0317_perfkvm/tools/perf/util/sort.h
@@ -44,6 +44,10 @@ extern enum sort_type sort__first_dimens
 struct hist_entry {
 	struct rb_node		rb_node;
 	u64			count;
+	u64			count_sys;
+	u64			count_us;
+	u64			count_guest_sys;
+	u64			count_guest_us;
 	struct thread		*thread;
 	struct map		*map;
 	struct symbol		*sym;
tools/perf/util/symbol.c +157 -21

346 lines not on this page · raw message

tools/perf/util/symbol.h +18 -4
diff -Nraup linux-2.6_tip0317/tools/perf/util/symbol.h linux-2.6_tip0317_perfkvm/tools/perf/util/symbol.h
@@ -63,10 +63,14 @@ struct symbol_conf {
 			show_nr_samples,
 			use_callchain,
 			exclude_other,
-			full_paths;
+			full_paths,
+			show_cpu_utilization;
 	const char	*vmlinux_name,
 			*field_sep;
-	char            *dso_list_str,
+	const char	*guest_vmlinux_name,
+			*guest_kallsyms,
+			*guest_modules;
+	char		*dso_list_str,
 			*comm_list_str,
 			*sym_list_str,
 			*col_width_list_str;
@@ -95,6 +99,13 @@ struct addr_location {
 	u64	      addr;
 	char	      level;
 	bool	      filtered;
+	unsigned int  cpumode;
+};
+
+enum dso_kernel_type {
+	DSO_TYPE_USER = 0,
+	DSO_TYPE_KERNEL,
+	DSO_TYPE_GUEST_KERNEL
 };
 
 struct dso {
@@ -104,7 +115,7 @@ struct dso {
 	u8		 adjust_symbols:1;
 	u8		 slen_calculated:1;
 	u8		 has_build_id:1;
-	u8		 kernel:1;
+	enum dso_kernel_type	kernel;
 	u8		 hit:1;
 	u8		 annotate_warned:1;
 	unsigned char	 origin;
@@ -120,6 +131,7 @@ struct dso {
 
 struct dso *dso__new(const char *name);
 struct dso *dso__new_kernel(const char *name);
+struct dso *dso__new_guest_kernel(const char *name);
 void dso__delete(struct dso *self);
 
 bool dso__loaded(const struct dso *self, enum map_type type);
@@ -132,7 +144,7 @@ static inline void dso__set_loaded(struc
 
 void dso__sort_by_name(struct dso *self, enum map_type type);
 
-extern struct list_head dsos__user, dsos__kernel;
+extern struct list_head dsos__user, dsos__kernel, dsos__guest_user, dsos__guest_kernel;
 
 struct dso *__dsos__findnew(struct list_head *head, const char *name);
 
@@ -161,6 +173,8 @@ enum dso_origin {
 	DSO__ORIG_BUILDID,
 	DSO__ORIG_DSO,
 	DSO__ORIG_KMODULE,
+	DSO__ORIG_GUEST_KERNEL,
+	DSO__ORIG_GUEST_KMODULE,
 	DSO__ORIG_NOT_FOUND,
 };
 
tools/perf/util/thread.h +4 -1
diff -Nraup linux-2.6_tip0317/tools/perf/util/thread.h linux-2.6_tip0317_perfkvm/tools/perf/util/thread.h
@@ -82,6 +82,9 @@ int __map_groups__create_kernel_maps(str
 int map_groups__create_kernel_maps(struct map_groups *self,
 				   struct map *vmlinux_maps[MAP__NR_TYPES]);
 
+int map_groups__create_guest_kernel_maps(struct map_groups *self,
+				   struct map *vmlinux_maps[MAP__NR_TYPES]);
+
 struct map *map_groups__new_module(struct map_groups *self, u64 start,
-				   const char *filename);
+				   const char *filename, int guest);
 #endif	/* __PERF_THREAD_H */
#356 lore raw

Nice progress!

This bit:

Quoted 3 lines

1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Will be really be painful to developers - to enter that long line while we have these things called 'computers' that ought to reduce human work. Also, it's incomplete, we need access to the guest system's binaries to do ELF symbol resolution and dwarf decoding.

So we really need some good, automatic way to get to the guest symbol space, so that if a developer types:

perf kvm top

Then the obvious thing happens by default. (which is to show the guest overhead)

There's no technical barrier on the perf tooling side to implement all that:
perf supports build-ids extensively and can deal with multiple symbol spaces - as long as it has access to it. The guest kernel could be ID-ed based on its /sys/kernel/notes and /sys/module/*/notes/.note.gnu.build-id build-ids.

So some sort of --guestmount option would be the natural solution, which points to the guest system's root: and a Qemu enumeration of guest mounts (which would be off by default and configurable) from which perf can pick up the target guest all automatically. (obviously only under allowed permissions so that such access is secure)

This would allow not just kallsyms access via $guest/proc/kallsyms but also gives us the full space of symbol features: access to the guest binaries for annotation and general symbol resolution, command/binary name identification, etc.

Such a mount would obviously not broaden existing privileges - and as an additional control a guest would also have a way to indicate that it does not wish a guest mount at all.

Unfortunately, in a previous thread the Qemu maintainer has indicated that he will essentially NAK any attempt to enhance Qemu to provide an easily discoverable, self-contained, transparent guest mount on the host side.

No technical justification was given for that NAK, despite my repeated requests to particulate the exact security problems that such an approach would cause.

If that NAK does not stand in that form then i'd like to know about it - it makes no sense for us to try to code up a solution against a standing maintainer NAK ...

The other option is some sysadmin level hackery to NFS-mount the guest or so. This is a vastly inferior method that brings us back to the absymal usability levels of OProfile:

1) it wont be guest transparent
2) has to be re-done for every guest image.
3) even if packaged it has to be gotten into every. single. Linux. distro. separately.
4) old Linux guests wont work out of box

In other words: it's very inconvenient on multiple levels and wont ever happen on any reasonable enough scale to make a difference to Linux.

Which is an unfortunate situation - and the ball is on the KVM/Qemu side so i can do little about it.

Thanks,

Ingo

#357 lore raw
Quoted 11 lines · Ingo Molnar

Unfortunately, in a previous thread the Qemu maintainer has indicated that he will essentially NAK any attempt to enhance Qemu to provide an easily discoverable, self-contained, transparent guest mount on the host side.

No technical justification was given for that NAK, despite my repeated requests to particulate the exact security problems that such an approach would cause.

If that NAK does not stand in that form then i'd like to know about it - it makes no sense for us to try to code up a solution against a standing maintainer NAK ...

I still think it is the best and most generic way to let the guest do the symbol resolution. This has several advantages:

1. The guest knows best about its symbol space. So this would be extensible to other guest operating systems. A brave developer may even implement symbol passing for Windows or the BSDs ;-)

2. The guest can decide for its own if it want to pass this inforamtion to the host-perf. No security issues at all.

3. The guest can also pass us the call-chain and we don't need to care about complicated of fetching from the guest ourself.

4. This way extensible to nested virtualization too.

How we speak to the guest was already discussed in this thread. My personal opinion is that going through qemu is an unnecessary step and we can solve that more clever and transparent for perf.

Joerg

#358 lore raw
Quoted 9 lines · oerg Roedel
Quoted 8 lines · Ingo Molnar

Unfortunately, in a previous thread the Qemu maintainer has indicated that he will essentially NAK any attempt to enhance Qemu to provide an easily discoverable, self-contained, transparent guest mount on the host side.

No technical justification was given for that NAK, despite my repeated requests to particulate the exact security problems that such an approach would cause.

Quoted 6 lines
Quoted 3 lines

If that NAK does not stand in that form then i'd like to know about it - it makes no sense for us to try to code up a solution against a standing maintainer NAK ...

I still think it is the best and most generic way to let the guest do the symbol resolution. [...]

Not really.

Quoted 6 lines

[...] This has several advantages:

1. The guest knows best about its symbol space. So this would be extensible to other guest operating systems. A brave developer may even implement symbol passing for Windows or the BSDs ;-)

Having access to the actual executable files that include the symbols achieves precisely that - with the additional robustness that all this functionality is concentrated into the host, while the guest side is kept minimal (and transparent).

Quoted 2 lines

2. The guest can decide for its own if it want to pass this inforamtion to the host-perf. No security issues at all.

It can decide whether it exposes the files. Nor are there any "security issues" to begin with.

Quoted 3 lines

3. The guest can also pass us the call-chain and we don't need to care about complicated of fetching from the guest ourself.

You need to be aware of the fact that symbol resolution is a separate step from call chain generation.

I.e. call-chains are a (entirely) separate issue, and could reasonably be done in the guest or in the host.

It has no bearing on this symbol resolution question.

Quoted 1 line

4. This way extensible to nested virtualization too.

Nested virtualization is actually already taken care of by the filesystem solution via an existing method called 'subdirectories'. If the guest offers sub-guests then those symbols will be exposed in a similar way via its own 'guest files' directory hierarchy.

I.e. if we have 'Guest-2' nested inside 'the 'Guest-Fedora-1' instance, we get:

/guests/
/guests/Guest-Fedora-1/etc/
/guests/Guest-Fedora-1/usr/

we'd also have:

/guests/Guest-Fedora-1/guests/Guest-2/

So this is taken care of automatically.

I.e. none of the four 'advantages' listed here are actually advantages over my proposed solution, so your conclusion is subsequently flawed as well.

Quoted 3 lines

How we speak to the guest was already discussed in this thread. My personal opinion is that going through qemu is an unnecessary step and we can solve that more clever and transparent for perf.

Meaning exactly what?

Thanks,

Ingo

#359 lore raw
Quoted 4 lines · Ingo Molnar

Having access to the actual executable files that include the symbols achieves precisely that - with the additional robustness that all this functionality is concentrated into the host, while the guest side is kept minimal (and transparent).

If you want to access the guests file-system you need a piece of software running in the guest which gives you this access. But when you get an event this piece of software may not be runnable (if the guest is in an interrupt handler or any other non-preemptible code path). When the host finally gets access to the guests filesystem again the source of that event may already be gone (process has exited, module unloaded...). The only way to solve that is to pass the event information to the guest immediatly and let it collect the information we want.

Quoted 2 lines

It can decide whether it exposes the files. Nor are there any "security issues" to begin with.

I am not talking about security. Security was sufficiently flamed about already.

Quoted 2 lines

You need to be aware of the fact that symbol resolution is a separate step from call chain generation.

Same concern as above applies to call-chain generation too.

Quoted 5 lines
Quoted 3 lines

How we speak to the guest was already discussed in this thread. My personal opinion is that going through qemu is an unnecessary step and we can solve that more clever and transparent for perf.

Meaning exactly what?

Avi was against that but I think it would make sense to give names to virtual machines (with a default, similar to network interface names). Then we can create a directory in /dev/ with that name (e.g. /dev/vm/fedora/). Inside the guest a (priviledged) process can create some kind of named virt-pipe which results in a device file created in the guests directory (perf could create /dev/vm/fedora/perf for example). This file is used for guest-host communication.

Thanks,

Joerg

#360 lore raw
Quoted 4 lines · oerg Roedel
Quoted 2 lines

It can decide whether it exposes the files. Nor are there any "security issues" to begin with.

I am not talking about security. [...]

You were talking about security, in the portion of your mail that you snipped out, and which i replied to:

Quoted 2 lines
Quoted 2 lines

2. The guest can decide for its own if it want to pass this inforamtion to the host-perf. No security issues at all.

I understood that portion to mean what it says: that your claim that your proposal 'has no security issues at all', in contrast to my suggestion.

Quoted 1 line

[...] Security was sufficiently flamed about already.

All i saw was my suggestion to allow a guest to securely (and scalably and conveniently) integrate/mount its filesystems to the host if both sides (both the host and the guest) permit it, to make it easier for instrumentation to pick up symbol details.

I.e. if a guest runs then its filesystem may be present on the host side as:

/guests/Fedora-G1/
/guests/Fedora-G1/proc/
/guests/Fedora-G1/usr/
/guests/Fedora-G1/.../

( This feature would be configurable and would be default-off, to maintain the
current status quo. )

i.e. it's a bit like sshfs or NFS or loopback block mounts, just in an integrated and working fashion (sshfs doesnt work well with /proc for example) and more guest transparent (obviously sshfs or NFS exports need per guest configuration), and lower overhead than sshfs/NFS - i.e. without the (unnecessary) networking overhead.

That suggestion was 'countered' by an unsubstantiated claim by Anthony that this kind of usability feature would somehow be a 'security nighmare'.

In reality it is just an incremental, more usable, faster and more guest-transparent form of what is already possible today via:

- loopback mounts on host
- NFS exports
- SMB exports
- sshfs
- (and other mechanisms)

I wish there was at least flaming about it - as flames tend to have at least some specifics in them.

What i saw instead was a claim about a 'security nightmare', which was, when i asked for specifics, was followed by deafening silence. And you appear to have repeated that claim here, unwilling to back it up with specifics.

Thanks,

Ingo

#361 lore raw
In reply to oerg Roedel
Quoted 6 lines · oerg Roedel
Quoted 4 lines · Ingo Molnar

Having access to the actual executable files that include the symbols achieves precisely that - with the additional robustness that all this functionality is concentrated into the host, while the guest side is kept minimal (and transparent).

Quoted 8 lines

If you want to access the guests file-system you need a piece of software running in the guest which gives you this access. But when you get an event this piece of software may not be runnable (if the guest is in an interrupt handler or any other non-preemptible code path). When the host finally gets access to the guests filesystem again the source of that event may already be gone (process has exited, module unloaded...). The only way to solve that is to pass the event information to the guest immediatly and let it collect the information we want.

The very same is true of profiling in the host space as well (KVM is nothing special here, other than its unreasonable insistence on not enumerating readily available information in a more usable way).

So are you suggesting a solution to a perf problem we already solved differently? (and which i argue we solved in a better way)

We have solved that in the host space already (and quite elaborately so), and not via your suggestion of moving symbol resolution to a different stage, but by properly generating the right events to allow the post-processing stage to see processes that have already exited, to robustly handle files that have been rebuilt, etc.

Quoted 1 line

From an instrumentation POV it is fundamentally better to acquire the right

data and delay any complexities to the analysis stage (the perf model) than to complicate sampling (the oprofile dcookies model).

Your proposal of 'doing the symbol resolution in the guest context' is in essence re-arguing that very similar point that oprofile lost. Did you really intend to re-argue that point as well? If yes then please propose an alternative implementation for everything that perf does wrt. symbol lookups.

What we propose for 'perf kvm' right now is simply a straight-forward extension of the existing (and well working) symbol handling code to virtualization.

Quoted 4 lines
Quoted 2 lines

You need to be aware of the fact that symbol resolution is a separate step from call chain generation.

Same concern as above applies to call-chain generation too.

Best would be if you demonstrated any problems of the perf symbol lookup code you are aware of on the host side, as it has that exact design you are criticising here. We are eager to fix any bugs in it.

If you claim that it's buggy then that should very much be demonstratable - no need to go into theoretical arguments about it.

( You should be aware of the fact that perf currently works with 'processes
exiting prematurely' and similar scenarios just fine, so if you want to demonstrate that it's broken you will probably need a different example. )

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

How we speak to the guest was already discussed in this thread. My personal opinion is that going through qemu is an unnecessary step and we can solve that more clever and transparent for perf.

Meaning exactly what?

Quoted 7 lines

Avi was against that but I think it would make sense to give names to virtual machines (with a default, similar to network interface names). Then we can create a directory in /dev/ with that name (e.g. /dev/vm/fedora/). Inside the guest a (priviledged) process can create some kind of named virt-pipe which results in a device file created in the guests directory (perf could create /dev/vm/fedora/perf for example). This file is used for guest-host communication.

That is kind of half of my suggestion - the built-in enumeration guests and a guaranteed channel to them accessible to tools. (KVM already has its own special channel so it's not like channels of communication are useless.)

The other half of my suggestion is that if we bring this thought to its logical conclusion then we might as well walk the whole mile and not use quirky, binary API single-channel pipes. I.e. we could use this convenient, human-readable, structured, hierarchical abstraction to expose information in a finegrained, scalable way, which has a world-class implementation in Linux:
the 'VFS namespace'.

Thanks,

Ingo

#362 lore raw
Quoted 6 lines · Ingo Molnar

Best would be if you demonstrated any problems of the perf symbol lookup code you are aware of on the host side, as it has that exact design you are criticising here. We are eager to fix any bugs in it.

If you claim that it's buggy then that should very much be demonstratable - no need to go into theoretical arguments about it.

I am not claiming anything. I just try to imagine how your proposal will look like in practice and forgot that symbol resolution is done at a later point.
But even with defered symbol resolution we need more information from the guest than just the rip falling out of KVM. The guest needs to tell us about the process where the event happened (information that the host has about itself without any hassle) and which executable-files it was loaded from.

Quoted 12 lines
Quoted 7 lines

Avi was against that but I think it would make sense to give names to virtual machines (with a default, similar to network interface names). Then we can create a directory in /dev/ with that name (e.g. /dev/vm/fedora/). Inside the guest a (priviledged) process can create some kind of named virt-pipe which results in a device file created in the guests directory (perf could create /dev/vm/fedora/perf for example). This file is used for guest-host communication.

That is kind of half of my suggestion - the built-in enumeration guests and a guaranteed channel to them accessible to tools. (KVM already has its own special channel so it's not like channels of communication are useless.)

Quoted 6 lines

The other half of my suggestion is that if we bring this thought to its logical conclusion then we might as well walk the whole mile and not use quirky, binary API single-channel pipes. I.e. we could use this convenient, human-readable, structured, hierarchical abstraction to expose information in a finegrained, scalable way, which has a world-class implementation in Linux:
the 'VFS namespace'.

Probably. At least it is the solution that fits best into the current design of perf. But we should think about how this will be done. Raw disk access is no solution because we need to access virtual file-systems of the guest too. Network filesystems may be a solution but then we come back to the 'deployment-nightmare'.

Joerg

#363 lore raw
Quoted 8 lines · Joerg Roedel
Quoted 6 lines · Ingo Molnar

Best would be if you demonstrated any problems of the perf symbol lookup code you are aware of on the host side, as it has that exact design you are criticising here. We are eager to fix any bugs in it.

If you claim that it's buggy then that should very much be demonstratable - no need to go into theoretical arguments about it.

Quoted 8 lines

I am not claiming anything. I just try to imagine how your proposal will look like in practice and forgot that symbol resolution is done at a later point.

But even with defered symbol resolution we need more information from the guest than just the rip falling out of KVM. The guest needs to tell us about the process where the event happened (information that the host has about itself without any hassle) and which executable-files it was loaded from.

Correct - for full information we need a good paravirt perf integration of the kernel bits to pass that through. (I.e. we want to 'integrate' the PID space as well, at least within the perf notion of PIDs.)

Initially we can do without that as well.

Quoted 4 lines

Probably. At least it is the solution that fits best into the current design of perf. But we should think about how this will be done. Raw disk access is no solution because we need to access virtual file-systems of the guest too. [...]

I never said anything about 'raw disk access'. Have you seen my proposal of (optional) VFS namespace integration? (It can be found repeated the Nth time in my mail you replied to)

Thanks,

Ingo

#364 lore raw
In reply to Joerg Roedel
Quoted 8 lines · Joerg Roedel
Quoted 6 lines · Ingo Molnar

Best would be if you demonstrated any problems of the perf symbol lookup code you are aware of on the host side, as it has that exact design you are criticising here. We are eager to fix any bugs in it.

If you claim that it's buggy then that should very much be demonstratable - no need to go into theoretical arguments about it.

Quoted 8 lines

I am not claiming anything. I just try to imagine how your proposal will look like in practice and forgot that symbol resolution is done at a later point.
But even with defered symbol resolution we need more information from the guest than just the rip falling out of KVM. The guest needs to tell us about the process where the event happened (information that the host has about itself without any hassle) and which executable-files it was loaded from.

Slightly tangential, but there is another case that has some of the same problems: profiling other language runtimes than C and C++, say Python. At the moment profilers will generally tell you what is going on inside the python runtime, but not what the python program itself is doing.

To fix that problem, it seems like we need some way to have python export what is going on. Maybe the same mechanism could be used to both access what is going on in qemu and python.

Soren

#365 lore raw
Quoted 4 lines · Soeren Sandmann

To fix that problem, it seems like we need some way to have python export what is going on. Maybe the same mechanism could be used to both access what is going on in qemu and python.

oprofile already has an interface to let JITs export information about the JITed code. C Python is not a JIT, but presumably one of the python JITs could do it.

http://oprofile.sourceforge.net/doc/devel/index.html

I know it's not envogue anymore and you won't be a approved cool kid if you do, but you could just use oprofile?

Ok presumably one would need to do a python interface for this first. I believe it's currently only implemented for Java and Mono. I presume it might work today with IronPython on Mono.

IMHO it doesn't make sense to invent another interface for this, although I'm sure someone will propose just that.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#366 lore raw
Quoted 11 lines · Andi Kleen
Quoted 4 lines · Soeren Sandmann

To fix that problem, it seems like we need some way to have python export what is going on. Maybe the same mechanism could be used to both access what is going on in qemu and python.

oprofile already has an interface to let JITs export information about the JITed code. C Python is not a JIT, but presumably one of the python JITs could do it.

http://oprofile.sourceforge.net/doc/devel/index.html

It's not that I personally want to profile a particular python program. I'm interested in the more general problem of extracting more information from profiled user space programs than just stack traces.

Examples:

- What is going on inside QEMU?

- Which client is the X server servicing?

- What parts of a python/shell/scheme/javascript program is taking the most CPU time?

I don't think the oprofile JIT interface solves any of these problems. (In fact, I don't see why the JIT problem is even hard. The JIT compiler can just generate a little ELF file with symbols in it, and the profiler can pick it up through the mmap events that you get through the perf interface).

Quoted 2 lines

I know it's not envogue anymore and you won't be a approved cool kid if you do, but you could just use oprofile?

I am bringing this up because I want to extend sysprof to be more useful.

Soren

#367 lore raw
Quoted 4 lines · Soeren Sandmann

Examples:

- What is going on inside QEMU?

That's something the JIT interface could answer.

Quoted 4 lines

- Which client is the X server servicing?

- What parts of a python/shell/scheme/javascript program is taking the most CPU time?

I suspect for those you rather need event based tracers of some sort, similar to kernel trace points. Otherwise you would need own separate stacks and other complications.

systemtap has some effort to use the dtrace instrumentation that crops up in more and more user programs for this. It wouldn't surprise me if that was already in python and other programs you're interested in.

I presume right now it only works if you apply the utrace monstrosity though, but perhaps the new uprobes patches floating around will come to rescue.

There also was some effort to have a pure user space daemon based approach for LTT, but I believe that currently needs own trace points.

Again I fully expect someone to reinvent the wheel here and afterwards complain about "community inefficiences" :-)

Quoted 5 lines

I don't think the oprofile JIT interface solves any of these problems. (In fact, I don't see why the JIT problem is even hard. The JIT compiler can just generate a little ELF file with symbols in it, and the profiler can pick it up through the mmap events that you get through the perf interface).

That would require keeping those temporary ELF files for potentially unlimited time around (profilers today look at the ELF files at the final analysis phase, which might be weeks away)

Also that would be a lot of overhead for the JIT and most likely be a larger scale rewrite for a given JIT code base.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#368 lore raw

Em Tue, Mar 23, 2010 at 03:20:11PM +0100, Andi Kleen escreveu:

Quoted 10 lines
Quoted 5 lines · Soeren Sandmann

I don't think the oprofile JIT interface solves any of these problems. (In fact, I don't see why the JIT problem is even hard. The JIT compiler can just generate a little ELF file with symbols in it, and the profiler can pick it up through the mmap events that you get through the perf interface).

That would require keeping those temporary ELF files for potentially unlimited time around (profilers today look at the ELF files at the final analysis phase, which might be weeks away)

'perf record' will traverse the perf.data file just collected and, if the binaries have build-ids, will stash them in ~/.debug/, keyed by build-id just like the -debuginfo packages do.

So only the binaries with hits. Also one can use 'perf archive' to create a tar.bz2 file with the files with hits for the specified perf.data file, that can then be transfered to another machine, whatever arch, untarred at ~/.debug and then the report can be done there.

As it is done by build-id, multiple 'perf record' sessions share files in the cache.

Right now the whole ELF file (or /proc/kallsyms copy) is stored if collected from the DSO directly, or the bits that are stored in -debuginfo files if we find it installed (so smaller). We could strip that down further by storing just the ELF sections needed to make sense of the symtab.

- Arnaldo

#369 lore raw
In reply to Soeren Sandmann
Quoted 6 lines · Soeren Sandmann

[...]
- What is going on inside QEMU?
- Which client is the X server servicing?
- What parts of a python/shell/scheme/javascript program is taking the most CPU time?
[...]

These kinds of questions usually require navigation through internal data of the user-space process ("Where in this linked list is this pointer?"), and often also correlating them with history ("which socket/fd was most recently serviced?").

Systemtap excels at letting one express such things.

- FChE

#370 lore raw
In reply to Andi Kleen

Em Tue, Mar 23, 2010 at 02:49:01PM +0100, Andi Kleen escreveu:

Quoted 5 lines
Quoted 3 lines · Soeren Sandmann

To fix that problem, it seems like we need some way to have python export what is going on. Maybe the same mechanism could be used to both access what is going on in qemu and python.

Quoted 8 lines

oprofile already has an interface to let JITs export information about the JITed code. C Python is not a JIT, but presumably one of the python JITs could do it.

http://oprofile.sourceforge.net/doc/devel/index.html

I know it's not envogue anymore and you won't be a approved cool kid if you do, but you could just use oprofile?

perf also has supports for this and Pekka Enberg's jato uses it:

http://penberg.blogspot.com/2009/06/jato-has-profiler.html

- Arnaldo

maintainer
#371 lore raw
Quoted 10 lines · Arnaldo Carvalho de Melo

Em Tue, Mar 23, 2010 at 02:49:01PM +0100, Andi Kleen escreveu:

Quoted 9 lines
Quoted 3 lines · Soeren Sandmann

To fix that problem, it seems like we need some way to have python export what is going on. Maybe the same mechanism could be used to both access what is going on in qemu and python.

oprofile already has an interface to let JITs export information about the JITed code. C Python is not a JIT, but presumably one of the python JITs could do it.

Quoted 8 lines
Quoted 4 lines

http://oprofile.sourceforge.net/doc/devel/index.html

I know it's not envogue anymore and you won't be a approved cool kid if you do, but you could just use oprofile?

perf also has supports for this and Pekka Enberg's jato uses it:

http://penberg.blogspot.com/2009/06/jato-has-profiler.html

Right, we need to move that into a library though (always meant to do that, never got around to doing it).

That way the app can link against a dso with weak empty stubs and have perf record LD_PRELOAD a version that has a suitable implementation.

That all has the advantage of not exposing the actual interface like we do now.

#372 lore raw
In reply to Ingo Molnar
Quoted 9 lines · Ingo Molnar

Nice progress!

This bit:

Quoted 3 lines

1) perf kvm top
[root@lkp-ne01 norm]# perf kvm --host --guest --guestkallsyms=/home/ymzhang/guest/kallsyms --guestmodules=/home/ymzhang/guest/modules top

Quoted 4 lines

Will be really be painful to developers - to enter that long line while we have these things called 'computers' that ought to reduce human work. Also, it's incomplete, we need access to the guest system's binaries to do ELF symbol resolution and dwarf decoding.

Yes, I agree with you and Avi that we need the enhancement be user-friendly. One of my start points is to keep the tool having less dependency on other components. Admin/developers could write script wrappers quickly if perf has parameters to support the new capability.

Quoted 6 lines

So we really need some good, automatic way to get to the guest symbol space, so that if a developer types:

perf kvm top

Quoted 7 lines

Then the obvious thing happens by default. (which is to show the guest overhead)

There's no technical barrier on the perf tooling side to implement all that:
perf supports build-ids extensively and can deal with multiple symbol spaces - as long as it has access to it. The guest kernel could be ID-ed based on its /sys/kernel/notes and /sys/module/*/notes/.note.gnu.build-id build-ids.

I tried sshfs quickly. sshfs could mount root filesystem of guest os nicely. I could access the files quickly. However, it doesn't work when I access /proc/ and /sys/ because sshfs/scp depend on file size while the sizes of most files of /proc/ and /sys/ are 0.

Quoted 6 lines

So some sort of --guestmount option would be the natural solution, which points to the guest system's root: and a Qemu enumeration of guest mounts (which would be off by default and configurable) from which perf can pick up the target guest all automatically. (obviously only under allowed permissions so that such access is secure)

If sshfs could access /proc/ and /sys correctly, here is a design:
--guestmount points to a directory which consists of a list of sub-directories. Every sub-directory's name is just the qemu process id of guest os. Admin/developer mounts every guest os instance's root directory to corresponding sub-directory.

Then, perf could access all files. It's possible because guest os instance happens to be multi-threading in a process. One of the defects is the accessing to guest os becomes slow or impossible when guest os is very busy.

Quoted 40 lines

This would allow not just kallsyms access via $guest/proc/kallsyms but also gives us the full space of symbol features: access to the guest binaries for annotation and general symbol resolution, command/binary name identification, etc.

Such a mount would obviously not broaden existing privileges - and as an additional control a guest would also have a way to indicate that it does not wish a guest mount at all.

Unfortunately, in a previous thread the Qemu maintainer has indicated that he will essentially NAK any attempt to enhance Qemu to provide an easily discoverable, self-contained, transparent guest mount on the host side.

No technical justification was given for that NAK, despite my repeated requests to particulate the exact security problems that such an approach would cause.

If that NAK does not stand in that form then i'd like to know about it - it makes no sense for us to try to code up a solution against a standing maintainer NAK ...

The other option is some sysadmin level hackery to NFS-mount the guest or so. This is a vastly inferior method that brings us back to the absymal usability levels of OProfile:

1) it wont be guest transparent
2) has to be re-done for every guest image.
3) even if packaged it has to be gotten into every. single. Linux. distro. separately.
4) old Linux guests wont work out of box

In other words: it's very inconvenient on multiple levels and wont ever happen on any reasonable enough scale to make a difference to Linux.

Which is an unfortunate situation - and the ball is on the KVM/Qemu side so i can do little about it.

Thanks,

Ingo

#373 lore raw

Em Mon, Mar 22, 2010 at 03:24:47PM +0800, Zhang, Yanmin escreveu:

Quoted 6 lines · Ingo Molnar
Quoted 5 lines

So some sort of --guestmount option would be the natural solution, which points to the guest system's root: and a Qemu enumeration of guest mounts (which would be off by default and configurable) from which perf can pick up the target guest all automatically. (obviously only under allowed permissions so that such access is secure)

Quoted 8 lines

If sshfs could access /proc/ and /sys correctly, here is a design:
--guestmount points to a directory which consists of a list of sub-directories. Every sub-directory's name is just the qemu process id of guest os. Admin/developer mounts every guest os instance's root directory to corresponding sub-directory.

Then, perf could access all files. It's possible because guest os instance happens to be multi-threading in a process. One of the defects is the accessing to guest os becomes slow or impossible when guest os is very busy.

If the MMAP events on the guest included a cookie that could later be used to query for the symtab of that DSO, we wouldn't need to access the guest FS at all, right?

With build-ids and debuginfo-install like tools the symbol resolution could be performed by using the cookies (build-ids) as keys to get to the *-debuginfo packages with matching symtabs (and DWARF for source annotation, etc).

We have that for the kernel as:

[acme@doppio linux-2.6-tip]$ l /sys/kernel/notes
-r--r--r-- 1 root root 36 2010-03-22 13:14 /sys/kernel/notes
[acme@doppio linux-2.6-tip]$ l /sys/module/ipv6/sections/.note.gnu.build-id -r--r--r-- 1 root root 4096 2010-03-22 13:38 /sys/module/ipv6/sections/.note.gnu.build-id [acme@doppio linux-2.6-tip]$

That way we would cover DSOs being reinstalled in long running 'perf record' sessions too.

This was discussed some time ago but would require help from the bits that load DSOs.

build-ids then would be first class citizens.

- Arnaldo

#374 lore raw
Quoted 12 lines · Arnaldo Carvalho de Melo

Em Mon, Mar 22, 2010 at 03:24:47PM +0800, Zhang, Yanmin escreveu:

Quoted 11 lines · Ingo Molnar
Quoted 5 lines

So some sort of --guestmount option would be the natural solution, which points to the guest system's root: and a Qemu enumeration of guest mounts (which would be off by default and configurable) from which perf can pick up the target guest all automatically. (obviously only under allowed permissions so that such access is secure)

If sshfs could access /proc/ and /sys correctly, here is a design:
--guestmount points to a directory which consists of a list of sub-directories. Every sub-directory's name is just the qemu process id of guest os. Admin/developer mounts every guest os instance's root directory to corresponding sub-directory.

Quoted 7 lines
Quoted 3 lines

Then, perf could access all files. It's possible because guest os instance happens to be multi-threading in a process. One of the defects is the accessing to guest os becomes slow or impossible when guest os is very busy.

If the MMAP events on the guest included a cookie that could later be used to query for the symtab of that DSO, we wouldn't need to access the guest FS at all, right?

It depends on specific sub commands. As for 'perf kvm top', developers want to see the profiling immediately. Even with 'perf kvm record', developers also want to see results quickly. At least I'm eager for the results when investigating a performance issue.

Quoted 5 lines

With build-ids and debuginfo-install like tools the symbol resolution could be performed by using the cookies (build-ids) as keys to get to the *-debuginfo packages with matching symtabs (and DWARF for source annotation, etc).

We can't make sure guest os uses the same os images, or don't know where we could find the original DVD images being used to install guest os.

Current perf does save build id, including both kernls's and other application lib/executables.

Quoted 11 lines

We have that for the kernel as:

[acme@doppio linux-2.6-tip]$ l /sys/kernel/notes
-r--r--r-- 1 root root 36 2010-03-22 13:14 /sys/kernel/notes
[acme@doppio linux-2.6-tip]$ l /sys/module/ipv6/sections/.note.gnu.build-id -r--r--r-- 1 root root 4096 2010-03-22 13:38 /sys/module/ipv6/sections/.note.gnu.build-id [acme@doppio linux-2.6-tip]$

That way we would cover DSOs being reinstalled in long running 'perf record' sessions too.

That's one of objectives of perf to support long running.

Quoted 7 lines

This was discussed some time ago but would require help from the bits that load DSOs.

build-ids then would be first class citizens.

- Arnaldo

#375 lore raw

Em Tue, Mar 23, 2010 at 11:14:41AM +0800, Zhang, Yanmin escreveu:

Quoted 7 lines · Arnaldo Carvalho de Melo
Quoted 6 lines

Em Mon, Mar 22, 2010 at 03:24:47PM +0800, Zhang, Yanmin escreveu:

Quoted 4 lines · Ingo Molnar

Then, perf could access all files. It's possible because guest os instance happens to be multi-threading in a process. One of the defects is the accessing to guest os becomes slow or impossible when guest os is very busy.

Quoted 7 lines
Quoted 3 lines

If the MMAP events on the guest included a cookie that could later be used to query for the symtab of that DSO, we wouldn't need to access the guest FS at all, right?

It depends on specific sub commands. As for 'perf kvm top', developers want to see the profiling immediately. Even with 'perf kvm record', developers also want to

That is not a problem, if you have the relevant buildids in your cache (Look in your machine at ~/.debug/), it will be as fast as ever.

If you use a distro that has its userspace with build-ids, you probably use it always without noticing :-)

Quoted 2 lines

see results quickly. At least I'm eager for the results when investigating a performance issue.

Sure thing.

Quoted 8 lines
Quoted 4 lines

With build-ids and debuginfo-install like tools the symbol resolution could be performed by using the cookies (build-ids) as keys to get to the *-debuginfo packages with matching symtabs (and DWARF for source annotation, etc).

We can't make sure guest os uses the same os images, or don't know where we could find the original DVD images being used to install guest os.

You don't have to have guest and host sharing the same OS image, you just have to somehow populate your buildid cache with what you need, be it using sshfs or what Ingo is suggesting once, or using what your vendor provides (debuginfo packages). And you just have to do it once, for the relevant apps, to have it in your buildid cache.

Quoted 2 lines

Current perf does save build id, including both kernls's and other application lib/executables.

Yeah, I know, I implemented it. :-)

Quoted 8 lines
Quoted 7 lines

We have that for the kernel as:

[acme@doppio linux-2.6-tip]$ l /sys/kernel/notes
-r--r--r-- 1 root root 36 2010-03-22 13:14 /sys/kernel/notes
[acme@doppio linux-2.6-tip]$ l /sys/module/ipv6/sections/.note.gnu.build-id -r--r--r-- 1 root root 4096 2010-03-22 13:38 /sys/module/ipv6/sections/.note.gnu.build-id [acme@doppio linux-2.6-tip]$

Quoted 4 lines
Quoted 2 lines

That way we would cover DSOs being reinstalled in long running 'perf record' sessions too.

That's one of objectives of perf to support long running.

But it doesn't fully supports right now, as I explained, build-ids are collected at the end of the record session, because we have to open the DSOs that had hits to get the 20 bytes cookie we need, the build-id.

If we had it in the PERF_RECORD_MMAP record, we would close this race, and the added cost at load time should be minimal, to get the ELF section with it and put it somewhere in task struct.

If only we could coalesce it a bit to reclaim this:

[acme@doppio linux-2.6-tip]$ pahole -C task_struct ../build/v2.6.34-rc1-tip+/kernel/sched.o | tail -5

	/* size: 5968, cachelines: 94, members: 150 */
	/* sum members: 5943, holes: 7, sum holes: 25 */
	/* bit holes: 1, sum bit holes: 28 bits */
	/* last cacheline: 16 bytes */
};

[acme@doppio linux-2.6-tip]$

8-)

Or at least get just one of those 4 bytes holes then we could stick it at the end to get our build-id there, accessing it would be done only at PERF_RECORD_MMAP injection time, i.e. close to the time when we actually are loading the executable mmap, i.e. close to the time when the loader is injecting the build-id, I guess the extra memory and processing costs would be in the noise.

Quoted 4 lines
Quoted 4 lines

This was discussed some time ago but would require help from the bits that load DSOs.

build-ids then would be first class citizens.

- Arnaldo

#376 lore raw
Quoted 60 lines · Arnaldo Carvalho de Melo

Em Tue, Mar 23, 2010 at 11:14:41AM +0800, Zhang, Yanmin escreveu:

Quoted 7 lines · Arnaldo Carvalho de Melo
Quoted 6 lines

Em Mon, Mar 22, 2010 at 03:24:47PM +0800, Zhang, Yanmin escreveu:

Quoted 4 lines · Ingo Molnar

Then, perf could access all files. It's possible because guest os instance happens to be multi-threading in a process. One of the defects is the accessing to guest os becomes slow or impossible when guest os is very busy.

Quoted 7 lines
Quoted 3 lines

If the MMAP events on the guest included a cookie that could later be used to query for the symtab of that DSO, we wouldn't need to access the guest FS at all, right?

It depends on specific sub commands. As for 'perf kvm top', developers want to see the profiling immediately. Even with 'perf kvm record', developers also want to

That is not a problem, if you have the relevant buildids in your cache (Look in your machine at ~/.debug/), it will be as fast as ever.

If you use a distro that has its userspace with build-ids, you probably use it always without noticing :-)

Quoted 2 lines

see results quickly. At least I'm eager for the results when investigating a performance issue.

Sure thing.

Quoted 8 lines
Quoted 4 lines

With build-ids and debuginfo-install like tools the symbol resolution could be performed by using the cookies (build-ids) as keys to get to the *-debuginfo packages with matching symtabs (and DWARF for source annotation, etc).

We can't make sure guest os uses the same os images, or don't know where we could find the original DVD images being used to install guest os.

You don't have to have guest and host sharing the same OS image, you just have to somehow populate your buildid cache with what you need, be it using sshfs or what Ingo is suggesting once, or using what your vendor provides (debuginfo packages). And you just have to do it once, for the relevant apps, to have it in your buildid cache.

Quoted 2 lines

Current perf does save build id, including both kernls's and other application lib/executables.

Yeah, I know, I implemented it. :-)

Quoted 8 lines
Quoted 7 lines

We have that for the kernel as:

[acme@doppio linux-2.6-tip]$ l /sys/kernel/notes
-r--r--r-- 1 root root 36 2010-03-22 13:14 /sys/kernel/notes
[acme@doppio linux-2.6-tip]$ l /sys/module/ipv6/sections/.note.gnu.build-id -r--r--r-- 1 root root 4096 2010-03-22 13:38 /sys/module/ipv6/sections/.note.gnu.build-id [acme@doppio linux-2.6-tip]$

Quoted 4 lines
Quoted 2 lines

That way we would cover DSOs being reinstalled in long running 'perf record' sessions too.

That's one of objectives of perf to support long running.

Quoted 7 lines

But it doesn't fully supports right now, as I explained, build-ids are collected at the end of the record session, because we have to open the DSOs that had hits to get the 20 bytes cookie we need, the build-id.

If we had it in the PERF_RECORD_MMAP record, we would close this race, and the added cost at load time should be minimal, to get the ELF section with it and put it somewhere in task struct.

Well, you are improving upon perfection.

Quoted 10 lines

If only we could coalesce it a bit to reclaim this:

[acme@doppio linux-2.6-tip]$ pahole -C task_struct ../build/v2.6.34-rc1-tip+/kernel/sched.o | tail -5

	/* size: 5968, cachelines: 94, members: 150 */
	/* sum members: 5943, holes: 7, sum holes: 25 */
	/* bit holes: 1, sum bit holes: 28 bits */
	/* last cacheline: 16 bytes */
};

[acme@doppio linux-2.6-tip]$

That reminds me I listened to your presentation on 2007 OLS. :)

Quoted 16 lines

8-)

Or at least get just one of those 4 bytes holes then we could stick it at the end to get our build-id there, accessing it would be done only at PERF_RECORD_MMAP injection time, i.e. close to the time when we actually are loading the executable mmap, i.e. close to the time when the loader is injecting the build-id, I guess the extra memory and processing costs would be in the noise.

Quoted 4 lines
Quoted 4 lines

This was discussed some time ago but would require help from the bits that load DSOs.

build-ids then would be first class citizens.

- Arnaldo