* CPU reset vs DeviceState reset
@ 2020-03-02 17:20 Peter Maydell
2020-03-02 17:25 ` Peter Maydell
2020-03-02 17:45 ` Eduardo Habkost
0 siblings, 2 replies; 10+ messages in thread
From: Peter Maydell @ 2020-03-02 17:20 UTC (permalink / raw)
To: QEMU Developers
Hi; I've just noticed that although TYPE_CPU is a subclass of
TYPE_DEVICE, it seems to implement its own reset method
('reset' field in CPUClass struct) rather than just using the
DeviceClass's 'reset'.
Is there a reason for doing this, or is it just historical legacy
from TYPE_CPU originally not being a subclass of TYPE_DEVICE?
I ask because I'd like to be able to use 3-phase reset in the Arm
CPU, and I'm wondering whether it would be better to make TYPE_CPU
just use Device's reset system, or to treat TYPE_CPU as its own
base class and implement Resettable there. The former seems more
straightforward, unless I'm missing something that means we
really do need to have the reset method be different.
thanks
-- PMM
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: CPU reset vs DeviceState reset 2020-03-02 17:20 CPU reset vs DeviceState reset Peter Maydell @ 2020-03-02 17:25 ` Peter Maydell 2020-03-02 17:45 ` Eduardo Habkost 1 sibling, 0 replies; 10+ messages in thread From: Peter Maydell @ 2020-03-02 17:25 UTC (permalink / raw) To: QEMU Developers; +Cc: Eduardo Habkost Doh, I meant to cc Eduardo and Marcel but forgot... On Mon, 2 Mar 2020 at 17:20, Peter Maydell <peter.maydell@linaro.org> wrote: > > Hi; I've just noticed that although TYPE_CPU is a subclass of > TYPE_DEVICE, it seems to implement its own reset method > ('reset' field in CPUClass struct) rather than just using the > DeviceClass's 'reset'. > > Is there a reason for doing this, or is it just historical legacy > from TYPE_CPU originally not being a subclass of TYPE_DEVICE? > > I ask because I'd like to be able to use 3-phase reset in the Arm > CPU, and I'm wondering whether it would be better to make TYPE_CPU > just use Device's reset system, or to treat TYPE_CPU as its own > base class and implement Resettable there. The former seems more > straightforward, unless I'm missing something that means we > really do need to have the reset method be different. > > thanks > -- PMM ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: CPU reset vs DeviceState reset 2020-03-02 17:20 CPU reset vs DeviceState reset Peter Maydell 2020-03-02 17:25 ` Peter Maydell @ 2020-03-02 17:45 ` Eduardo Habkost 2020-03-02 18:19 ` Philippe Mathieu-Daudé 2020-03-02 18:41 ` Peter Maydell 1 sibling, 2 replies; 10+ messages in thread From: Eduardo Habkost @ 2020-03-02 17:45 UTC (permalink / raw) To: Peter Maydell; +Cc: QEMU Developers My impression is that this is just historical legacy, but I'm not sure how much work a conversion to the new system would require. I see lots of cpu_reset() calls scattered around the code. To make it worse, TYPE_CPU do have a DeviceClass::reset method implemented, but cpu_reset() won't call it because it bypasses the Device reset system completely. I will do some git archaeology work to try to find out why the code is this way. On Mon, Mar 02, 2020 at 05:20:33PM +0000, Peter Maydell wrote: > Hi; I've just noticed that although TYPE_CPU is a subclass of > TYPE_DEVICE, it seems to implement its own reset method > ('reset' field in CPUClass struct) rather than just using the > DeviceClass's 'reset'. > > Is there a reason for doing this, or is it just historical legacy > from TYPE_CPU originally not being a subclass of TYPE_DEVICE? > > I ask because I'd like to be able to use 3-phase reset in the Arm > CPU, and I'm wondering whether it would be better to make TYPE_CPU > just use Device's reset system, or to treat TYPE_CPU as its own > base class and implement Resettable there. The former seems more > straightforward, unless I'm missing something that means we > really do need to have the reset method be different. > > thanks > -- PMM > -- Eduardo ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: CPU reset vs DeviceState reset 2020-03-02 17:45 ` Eduardo Habkost @ 2020-03-02 18:19 ` Philippe Mathieu-Daudé 2020-03-02 18:42 ` Peter Maydell 2020-03-02 18:41 ` Peter Maydell 1 sibling, 1 reply; 10+ messages in thread From: Philippe Mathieu-Daudé @ 2020-03-02 18:19 UTC (permalink / raw) To: Eduardo Habkost, Peter Maydell, Markus Armbruster; +Cc: QEMU Developers On 3/2/20 6:45 PM, Eduardo Habkost wrote: > My impression is that this is just historical legacy, but I'm not > sure how much work a conversion to the new system would require. > I see lots of cpu_reset() calls scattered around the code. > > To make it worse, TYPE_CPU do have a DeviceClass::reset method > implemented, but cpu_reset() won't call it because it bypasses > the Device reset system completely. I will do some git > archaeology work to try to find out why the code is this way. Without verifying the code base/commits, my understanding is that was required to use cpu object with linux-user before Markus added support for anonymous object container for QOM objects on linux-user. So now we could make CPUClass inherits of DeviceClass. > > > On Mon, Mar 02, 2020 at 05:20:33PM +0000, Peter Maydell wrote: >> Hi; I've just noticed that although TYPE_CPU is a subclass of >> TYPE_DEVICE, it seems to implement its own reset method >> ('reset' field in CPUClass struct) rather than just using the >> DeviceClass's 'reset'. >> >> Is there a reason for doing this, or is it just historical legacy >> from TYPE_CPU originally not being a subclass of TYPE_DEVICE? >> >> I ask because I'd like to be able to use 3-phase reset in the Arm >> CPU, and I'm wondering whether it would be better to make TYPE_CPU >> just use Device's reset system, or to treat TYPE_CPU as its own >> base class and implement Resettable there. The former seems more >> straightforward, unless I'm missing something that means we >> really do need to have the reset method be different. >> >> thanks >> -- PMM >> > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: CPU reset vs DeviceState reset 2020-03-02 18:19 ` Philippe Mathieu-Daudé @ 2020-03-02 18:42 ` Peter Maydell 2020-03-02 21:42 ` Eduardo Habkost 0 siblings, 1 reply; 10+ messages in thread From: Peter Maydell @ 2020-03-02 18:42 UTC (permalink / raw) To: Philippe Mathieu-Daudé Cc: QEMU Developers, Eduardo Habkost, Markus Armbruster On Mon, 2 Mar 2020 at 18:19, Philippe Mathieu-Daudé <philmd@redhat.com> wrote: > Without verifying the code base/commits, my understanding is that was > required to use cpu object with linux-user before Markus added support > for anonymous object container for QOM objects on linux-user. So now we > could make CPUClass inherits of DeviceClass. CPUClass already does inherit from DeviceClass... thanks -- PMM ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: CPU reset vs DeviceState reset 2020-03-02 18:42 ` Peter Maydell @ 2020-03-02 21:42 ` Eduardo Habkost 0 siblings, 0 replies; 10+ messages in thread From: Eduardo Habkost @ 2020-03-02 21:42 UTC (permalink / raw) To: Peter Maydell Cc: Philippe Mathieu-Daudé, Markus Armbruster, QEMU Developers On Mon, Mar 02, 2020 at 06:42:18PM +0000, Peter Maydell wrote: > On Mon, 2 Mar 2020 at 18:19, Philippe Mathieu-Daudé <philmd@redhat.com> wrote: > > Without verifying the code base/commits, my understanding is that was > > required to use cpu object with linux-user before Markus added support > > for anonymous object container for QOM objects on linux-user. So now we > > could make CPUClass inherits of DeviceClass. > > CPUClass already does inherit from DeviceClass... When CPUClass::reset was created, it didn't. See commit dd83b06ae61c ("qom: Introduce CPU class"). The "historical legacy" hypothesis seems accurate. -- Eduardo ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: CPU reset vs DeviceState reset 2020-03-02 17:45 ` Eduardo Habkost 2020-03-02 18:19 ` Philippe Mathieu-Daudé @ 2020-03-02 18:41 ` Peter Maydell 2020-03-02 21:40 ` Eduardo Habkost 1 sibling, 1 reply; 10+ messages in thread From: Peter Maydell @ 2020-03-02 18:41 UTC (permalink / raw) To: Eduardo Habkost; +Cc: QEMU Developers On Mon, 2 Mar 2020 at 17:45, Eduardo Habkost <ehabkost@redhat.com> wrote: > > My impression is that this is just historical legacy, but I'm not > sure how much work a conversion to the new system would require. > I see lots of cpu_reset() calls scattered around the code. I think we can just make the cpu_reset() function be a wrapper that calls device_cold_reset(DEVICE(cpu)). We would need to update the prototypes for > To make it worse, TYPE_CPU do have a DeviceClass::reset method > implemented, but cpu_reset() won't call it because it bypasses > the Device reset system completely. I will do some git > archaeology work to try to find out why the code is this way. At least for Arm CPUs, I don't think it does (well, it has the default DeviceState base class reset method which does nothing). Is there somewhere I missed? (I'm currently attempting to wrestle Coccinelle into doing the conversion of the target/ code automatically.) thanks -- PMM ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: CPU reset vs DeviceState reset 2020-03-02 18:41 ` Peter Maydell @ 2020-03-02 21:40 ` Eduardo Habkost 2020-03-02 21:55 ` Peter Maydell 0 siblings, 1 reply; 10+ messages in thread From: Eduardo Habkost @ 2020-03-02 21:40 UTC (permalink / raw) To: Peter Maydell; +Cc: QEMU Developers On Mon, Mar 02, 2020 at 06:41:31PM +0000, Peter Maydell wrote: > On Mon, 2 Mar 2020 at 17:45, Eduardo Habkost <ehabkost@redhat.com> wrote: > > > > My impression is that this is just historical legacy, but I'm not > > sure how much work a conversion to the new system would require. > > I see lots of cpu_reset() calls scattered around the code. > > I think we can just make the cpu_reset() function be a > wrapper that calls device_cold_reset(DEVICE(cpu)). > We would need to update the prototypes for [1] This might have unintended side effects, as it will also call cpu_common_reset(). I still think we should try it. > > > To make it worse, TYPE_CPU do have a DeviceClass::reset method > > implemented, but cpu_reset() won't call it because it bypasses > > the Device reset system completely. I will do some git > > archaeology work to try to find out why the code is this way. > > At least for Arm CPUs, I don't think it does (well, it > has the default DeviceState base class reset method > which does nothing). Is there somewhere I missed? TYPE_CPU points DeviceClass::reset to cpu_common_reset(), so I believe this affects all TYPE_CPU descendants. > > (I'm currently attempting to wrestle Coccinelle into > doing the conversion of the target/ code automatically.) I see 3 separate problems we might want to address: 1) Making device_cold_reset() end up calling CPUClass::reset in addition to existing cpu_common_reset() (easier to do without side effects). This would get rid of the custom reset callbacks on machine code. 2) Making cpu_reset() call device_cold_reset() (will have side effects, needs additional care[1]). This would make us have only one method of resetting CPUs. 3) Replacing CPUClass::reset with the new reset mechanisms.. This would let us get rid of legacy CPU reset code. -- Eduardo ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: CPU reset vs DeviceState reset 2020-03-02 21:40 ` Eduardo Habkost @ 2020-03-02 21:55 ` Peter Maydell 2020-03-02 22:12 ` Eduardo Habkost 0 siblings, 1 reply; 10+ messages in thread From: Peter Maydell @ 2020-03-02 21:55 UTC (permalink / raw) To: Eduardo Habkost; +Cc: QEMU Developers On Mon, 2 Mar 2020 at 21:40, Eduardo Habkost <ehabkost@redhat.com> wrote: > > On Mon, Mar 02, 2020 at 06:41:31PM +0000, Peter Maydell wrote: > > On Mon, 2 Mar 2020 at 17:45, Eduardo Habkost <ehabkost@redhat.com> wrote: > > > > > > My impression is that this is just historical legacy, but I'm not > > > sure how much work a conversion to the new system would require. > > > I see lots of cpu_reset() calls scattered around the code. > > > > I think we can just make the cpu_reset() function be a > > wrapper that calls device_cold_reset(DEVICE(cpu)). > > We would need to update the prototypes for > > [1] This might have unintended side effects, as it will also call > cpu_common_reset(). I still think we should try it. Yes, but cpu_reset() ends up calling cpu_common_reset() at the moment (every subclass uses cpu_class_set_parent_reset() to put in its own reset implementation and save a pointer to the base class reset function, which it then invokes from its own reset method). A DeviceClass::reset changeover works exactly the same way. (I have some working code for this, just need to test it a bit more and satisfy myself that there aren't any weird places that call DeviceClass::reset on a CPU object and expect it to be a no-op like it is right now. I don't think there should be any since a CPU object is never on a qbus, and none of the direct calls to functions that do device-object resets are dealing with CPUs.) > > At least for Arm CPUs, I don't think it does (well, it > > has the default DeviceState base class reset method > > which does nothing). Is there somewhere I missed? > > TYPE_CPU points DeviceClass::reset to cpu_common_reset(), > so I believe this affects all TYPE_CPU descendants. Where does it do that? cpu_class_init() sets CPUClass::reset to cpu_common_reset and doesn't touch DeviceClass::reset: https://git.qemu.org/?p=qemu.git;a=blob;f=hw/core/cpu.c;h=fe65ca62aceef581d4d9ef3cb9e1b0d7df4e5bfa;hb=HEAD#l416 (the two reset methods have different type signatures so you wouldn't be able to assign cpu_common_reset() to DeviceClass::reset without an ugly and undefined-behaviour cast...) > > (I'm currently attempting to wrestle Coccinelle into > > doing the conversion of the target/ code automatically.) > > I see 3 separate problems we might want to address: > > 1) Making device_cold_reset() end up calling CPUClass::reset > in addition to existing cpu_common_reset() > (easier to do without side effects). This would get rid of > the custom reset callbacks on machine code. > > 2) Making cpu_reset() call device_cold_reset() > (will have side effects, needs additional care[1]). > This would make us have only one method of resetting CPUs. > > 3) Replacing CPUClass::reset with the new reset mechanisms.. > This would let us get rid of legacy CPU reset code. My work-in-progress patch does: * cpu_reset() calls device_cold_reset() * all the targets, plus the base TYPE_CPU class, implement DeviceClass::reset instead of CPUClass::reset * CPUClass::reset goes away entirely It passes 'make check' and 'make check-acceptance', so it's basically right, I think. Note that this does not do anything about the need for each machine or whatever to use qemu_register_reset() to arrange to call cpu_reset() -- that is necessary because CPU objects are not on any qbus, so they don't get reset when the qbus tree rooted at the sysbus bus is reset, and that doesn't change. That's a different and much trickier problem to try to tackle (I don't currently have any good ideas for how we would want to approach it). thanks -- PMM ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: CPU reset vs DeviceState reset 2020-03-02 21:55 ` Peter Maydell @ 2020-03-02 22:12 ` Eduardo Habkost 0 siblings, 0 replies; 10+ messages in thread From: Eduardo Habkost @ 2020-03-02 22:12 UTC (permalink / raw) To: Peter Maydell; +Cc: QEMU Developers On Mon, Mar 02, 2020 at 09:55:42PM +0000, Peter Maydell wrote: > On Mon, 2 Mar 2020 at 21:40, Eduardo Habkost <ehabkost@redhat.com> wrote: > > > > On Mon, Mar 02, 2020 at 06:41:31PM +0000, Peter Maydell wrote: > > > On Mon, 2 Mar 2020 at 17:45, Eduardo Habkost <ehabkost@redhat.com> wrote: > > > > > > > > My impression is that this is just historical legacy, but I'm not > > > > sure how much work a conversion to the new system would require. > > > > I see lots of cpu_reset() calls scattered around the code. > > > > > > I think we can just make the cpu_reset() function be a > > > wrapper that calls device_cold_reset(DEVICE(cpu)). > > > We would need to update the prototypes for > > > > [1] This might have unintended side effects, as it will also call > > cpu_common_reset(). I still think we should try it. > > Yes, but cpu_reset() ends up calling cpu_common_reset() > at the moment (every subclass uses cpu_class_set_parent_reset() > to put in its own reset implementation and save a pointer to > the base class reset function, which it then invokes from > its own reset method). A DeviceClass::reset changeover works > exactly the same way. > > (I have some working code for this, just need to test it a bit > more and satisfy myself that there aren't any weird places > that call DeviceClass::reset on a CPU object and expect it > to be a no-op like it is right now. I don't think there should be > any since a CPU object is never on a qbus, and none of the > direct calls to functions that do device-object resets are > dealing with CPUs.) > > > > At least for Arm CPUs, I don't think it does (well, it > > > has the default DeviceState base class reset method > > > which does nothing). Is there somewhere I missed? > > > > TYPE_CPU points DeviceClass::reset to cpu_common_reset(), > > so I believe this affects all TYPE_CPU descendants. > > Where does it do that? cpu_class_init() sets CPUClass::reset > to cpu_common_reset and doesn't touch DeviceClass::reset: > https://git.qemu.org/?p=qemu.git;a=blob;f=hw/core/cpu.c;h=fe65ca62aceef581d4d9ef3cb9e1b0d7df4e5bfa;hb=HEAD#l416 > (the two reset methods have different type signatures so > you wouldn't be able to assign cpu_common_reset() to > DeviceClass::reset without an ugly and undefined-behaviour > cast...) Oops, my mistake. I misread k->reset as DeviceClass::reset. Forget everything I said above. > > > > (I'm currently attempting to wrestle Coccinelle into > > > doing the conversion of the target/ code automatically.) > > > > I see 3 separate problems we might want to address: > > > > 1) Making device_cold_reset() end up calling CPUClass::reset > > in addition to existing cpu_common_reset() > > (easier to do without side effects). This would get rid of > > the custom reset callbacks on machine code. > > > > 2) Making cpu_reset() call device_cold_reset() > > (will have side effects, needs additional care[1]). > > This would make us have only one method of resetting CPUs. Correcting myself: this part won't have side effects. > > > > 3) Replacing CPUClass::reset with the new reset mechanisms.. > > This would let us get rid of legacy CPU reset code. > > My work-in-progress patch does: > * cpu_reset() calls device_cold_reset() > * all the targets, plus the base TYPE_CPU class, implement > DeviceClass::reset instead of CPUClass::reset > * CPUClass::reset goes away entirely > It passes 'make check' and 'make check-acceptance', so it's > basically right, I think. Sounds good to me. > > Note that this does not do anything about the need for each > machine or whatever to use qemu_register_reset() to arrange > to call cpu_reset() -- that is necessary because CPU objects > are not on any qbus, so they don't get reset when the qbus > tree rooted at the sysbus bus is reset, and that doesn't change. > That's a different and much trickier problem to try to tackle > (I don't currently have any good ideas for how we would want > to approach it). Understood. -- Eduardo ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2020-03-02 22:13 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-03-02 17:20 CPU reset vs DeviceState reset Peter Maydell 2020-03-02 17:25 ` Peter Maydell 2020-03-02 17:45 ` Eduardo Habkost 2020-03-02 18:19 ` Philippe Mathieu-Daudé 2020-03-02 18:42 ` Peter Maydell 2020-03-02 21:42 ` Eduardo Habkost 2020-03-02 18:41 ` Peter Maydell 2020-03-02 21:40 ` Eduardo Habkost 2020-03-02 21:55 ` Peter Maydell 2020-03-02 22:12 ` Eduardo Habkost
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.