memory: transaction API
PATCH 1/1 memory: transaction API
Allow changes to the memory hierarchy to be accumulated and made visible all at once. This reduces computational effort, especially when an accelerator (e.g. kvm) is involved.
Useful when a single register update causes multiple changes to an address space.
--- memory.c | 20 ++++++++++++++++++++ memory.h | 8 ++++++++ 2 files changed, 28 insertions(+), 0 deletions(-)
memory.c +20 -0
@@ -18,6 +18,8 @@#include "kvm.h" #include <assert.h> +unsigned memory_region_transaction_depth =0 ; +typedef struct AddrRange AddrRange ;struct AddrRange {
@@ -648,6 +650,10 @@ static void address_space_update_topology(AddressSpace *as)static void memory_region_update_topology (void ) { +if (memory_region_transaction_depth) { +return ; + } +if (address_space_memory.root) {address_space_update_topology (&address_space_memory); }
@@ -656,6 +662,20 @@ static void memory_region_update_topology(void) } } +void memory_region_transaction_begin (void ) +{ + ++memory_region_transaction_depth; +} + +void memory_region_transaction_commit (void ) +{ +if (!memory_region_transaction_depth) { +abort (); + } + --memory_region_transaction_depth; +memory_region_update_topology (); +} +void memory_region_init (MemoryRegion *mr,const char *name,uint64_t size)
memory.h +8 -0
@@ -246,6 +246,14 @@ void memory_region_add_subregion_overlap(MemoryRegion *mr,void memory_region_del_subregion (MemoryRegion *mr,MemoryRegion *subregion); +/* Start a transaction; changes will be accumulated and made visible only +* when the transaction ends. +*/ +void memory_region_transaction_begin (void ); +/* Commit a transaction and make changes visible to the guest. +*/ +void memory_region_transaction_commit (void ); +#endif #endif
Signature · 1 line
1.7.5.3
Quoted 6 lines · Avi Kivity
Allow changes to the memory hierarchy to be accumulated and made visible all at once. This reduces computational effort, especially when an accelerator (e.g. kvm) is involved.
Useful when a single register update causes multiple changes to an address space.
That's simple to implement in the core, but complicates life for the users, at least for the simple "update this region" use case.
Do we have transactional scenarios during runtime where multiple memory regions are reconfigured?
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 11 lines · Jan Kiszka
Quoted 6 lines · Avi Kivity
Allow changes to the memory hierarchy to be accumulated and made visible all at once. This reduces computational effort, especially when an accelerator (e.g. kvm) is involved.
Useful when a single register update causes multiple changes to an address space.
That's simple to implement in the core, but complicates life for the users, at least for the simple "update this region" use case.
Why? just stick a _begin() and _commit() at the start and end of the update_mapping() function. It's an optional API, for simple cases (like mapping a BAR) you don't have to use it.
Quoted 2 lines
Do we have transactional scenarios during runtime where multiple memory regions are reconfigured?
Both cirrus and 440fx PAM, I believe. They don't check for the "no change" condition (at least, not completely) and instead override the previous mapping.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 6 lines · Avi Kivity
Quoted 5 lines · Jan Kiszka
Quoted 4 lines · Avi Kivity
Allow changes to the memory hierarchy to be accumulated and made visible all at once. This reduces computational effort, especially when an accelerator (e.g. kvm) is involved.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Useful when a single register update causes multiple changes to an address space.
That's simple to implement in the core, but complicates life for the users, at least for the simple "update this region" use case.
Why? just stick a
_begin()and_commit()at the start and end of theupdate_mapping()function. It's an optional API, for simple cases (like mapping a BAR) you don't have to use it.
Do you see an improvement if you change cirrus_update_memory_access() in this fashion?
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Jan Kiszka
Quoted 6 lines · Avi Kivity
Allow changes to the memory hierarchy to be accumulated and made visible all at once. This reduces computational effort, especially when an accelerator (e.g. kvm) is involved.
Useful when a single register update causes multiple changes to an address space.
Quoted 7 lines
Quoted 3 lines
That's simple to implement in the core, but complicates life for the users, at least for the simple "update this region" use case.
Why? just stick a
_begin()and_commit()at the start and end of theupdate_mapping()function. It's an optional API, for simple cases (like mapping a BAR) you don't have to use it.
begin
delete old
free old
create new
add new
end
vs.
update
Quoted 8 lines
Quoted 4 lines
Do we have transactional scenarios during runtime where multiple memory regions are reconfigured?
Both cirrus and 440fx PAM, I believe. They don't check for the "no change" condition (at least, not completely) and instead override the previous mapping.
That's the job of the memory mapping core IIUC. But it can only be done efficiently with an 'update' operation.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 12 lines · Jan Kiszka
Quoted 4 lines
Why? just stick a
_begin()and_commit()at the start and end of theupdate_mapping()function. It's an optional API, for simple cases (like mapping a BAR) you don't have to use it.begin
delete old
free old
create new
add new
end
Quoted 4 lines
vs.
update
The problem is that "update" can change lots of things. offset, size, whether it's mmio or RAM, read-onlyness, even the wierd things like coalesced mmio. So it's either a function with 324.2 parameters (or a large struct), or it's a series of functions with demarcation as to where the update begins and ends.
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines
Do we have transactional scenarios during runtime where multiple memory regions are reconfigured?
Both cirrus and 440fx PAM, I believe. They don't check for the "no change" condition (at least, not completely) and instead override the previous mapping.
That's the job of the memory mapping core IIUC.
In my opinion, too. Devices should be dead simple.
Quoted 2 lines
But it can only be done
efficiently with an 'update' operation.
Why is the transaction API inefficient? AFAICT it accomplishes the same thing. Some cycles are spent on finding out nothing has changed, but that's fine.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 15 lines · Avi Kivity
Quoted 14 lines · Jan Kiszka
Quoted 4 lines
Why? just stick a
_begin()and_commit()at the start and end of theupdate_mapping()function. It's an optional API, for simple cases (like mapping a BAR) you don't have to use it.begin
delete old
free old
create new
add new
endvs.
Quoted 8 lines
Quoted 2 lines
update
The problem is that "update" can change lots of things. offset, size, whether it's mmio or RAM, read-onlyness, even the wierd things like coalesced mmio. So it's either a function with 324.2 parameters (or a large struct), or it's a series of functions with demarcation as to where the update begins and ends.
We do not need to provide update support for each and every bit, but for the common cases. memory_region_update_alias(region, offset, size) would be an excellent first candidate IMO.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 10 lines · Jan Kiszka
Quoted 6 lines
The problem is that "update" can change lots of things. offset, size, whether it's mmio or RAM, read-onlyness, even the wierd things like coalesced mmio. So it's either a function with 324.2 parameters (or a large struct), or it's a series of functions with demarcation as to where the update begins and ends.
We do not need to provide update support for each and every bit, but for the common cases.
memory_region_update_alias(region, offset, size)would be an excellent first candidate IMO.
It's not enough, look at cirrus and PAM.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Jan Kiszka
Quoted 6 lines
The problem is that "update" can change lots of things. offset, size, whether it's mmio or RAM, read-onlyness, even the wierd things like coalesced mmio. So it's either a function with 324.2 parameters (or a large struct), or it's a series of functions with demarcation as to where the update begins and ends.
Quoted 5 lines
Quoted 3 lines
We do not need to provide update support for each and every bit, but for the common cases.
memory_region_update_alias(region, offset, size)would be an excellent first candidate IMO.It's not enough, look at cirrus and PAM.
It's a perfect fit for cirrus, but PAM indeed requires set_readonly in addition.
I also think now that describing a memory region offline via a struct and then passing that to an atomic add/del/update would be a more handy and future-proof API than an increasing number set functions.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Jan Kiszka
Quoted 6 lines
The problem is that "update" can change lots of things. offset, size, whether it's mmio or RAM, read-onlyness, even the wierd things like coalesced mmio. So it's either a function with 324.2 parameters (or a large struct), or it's a series of functions with demarcation as to where the update begins and ends.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
We do not need to provide update support for each and every bit, but for the common cases.
memory_region_update_alias(region, offset, size)would be an excellent first candidate IMO.It's not enough, look at cirrus and PAM.
It's a perfect fit for cirrus, but PAM indeed requires
set_readonlyin addition.
It isn't a pefect fit for cirrus. If the mode changes in a way that makes mapping the map as RAM possible, or vice versa, and if the banks are contiguous, then _update() results in two mappings or unmappings, while _commit() results in just one (since m_r_update_topology() merges the two adjacent regions).
Quoted 3 lines
I also think now that describing a memory region offline via a struct and then passing that to an atomic add/del/update would be a more handy and future-proof API than an increasing number set functions.
Maybe. But it's not sufficient for atomic changes involving multiple regions.
btw, there is another implementation issue involving SMP - if a region that obscures the middle of another region is removed, we'll have two regions removed and replaced with a larger one. That causes some memory to be temporarily inaccessible. I don't think it's a problem in practice, but if it is, we can fix it by stopping all vcpus if we detect this condition, and by adding an atomic change-memory-map-and-get-dirty-log ioctl to kvm.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 20 lines · Avi Kivity
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Jan Kiszka
Quoted 6 lines
The problem is that "update" can change lots of things. offset, size, whether it's mmio or RAM, read-onlyness, even the wierd things like coalesced mmio. So it's either a function with 324.2 parameters (or a large struct), or it's a series of functions with demarcation as to where the update begins and ends.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
We do not need to provide update support for each and every bit, but for the common cases.
memory_region_update_alias(region, offset, size)would be an excellent first candidate IMO.It's not enough, look at cirrus and PAM.
It's a perfect fit for cirrus, but PAM indeed requires
set_readonlyin addition.
Quoted 5 lines
It isn't a pefect fit for cirrus. If the mode changes in a way that makes mapping the map as RAM possible, or vice versa, and if the banks are contiguous, then
_update()results in two mappings or unmappings, while_commit()results in just one (sincem_r_update_topology()merges the two adjacent regions).
Continuous banks or mode changes are uncommon compared to offset changes of the mapped window. Cirrus does not need to bother about continuity of its banks (the memory core will), and mode changes could be implemented by allowing updates of the priority, thus reordering the regions instead of continuously deleting and recreating them.
Quoted 7 lines
Quoted 4 lines
I also think now that describing a memory region offline via a struct and then passing that to an atomic add/del/update would be a more handy and future-proof API than an increasing number set functions.
Maybe. But it's not sufficient for atomic changes involving multiple regions.
Right. The question is still if there are use cases where this matters (ie. update frequencies comparable to graphic scenarios).
Quoted 4 lines
btw, there is another implementation issue involving SMP - if a region that obscures the middle of another region is removed, we'll have two regions removed and replaced with a larger one.
Yes, I've seen many of such temporary changes in the cirrus remapping logs.
Quoted 5 lines
That causes some memory
to be temporarily inaccessible. I don't think it's a problem in practice, but if it is, we can fix it by stopping all vcpus if we detect this condition, and by adding an atomic change-memory-map-and-get-dirty-log ioctl to kvm.
I'm not sure if the cirrus or any similar hardware supports consistent memory accesses during ongoing bank remappings (ie. while the CPU issuing the remapping IO commands is blocked on QEMU executing them). But such an IOCTL would resolve our problem with dropping a logged region as well, right?
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 27 lines · Jan Kiszka
Quoted 20 lines · Avi Kivity
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Jan Kiszka
Quoted 6 lines
The problem is that "update" can change lots of things. offset, size, whether it's mmio or RAM, read-onlyness, even the wierd things like coalesced mmio. So it's either a function with 324.2 parameters (or a large struct), or it's a series of functions with demarcation as to where the update begins and ends.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
We do not need to provide update support for each and every bit, but for the common cases.
memory_region_update_alias(region, offset, size)would be an excellent first candidate IMO.It's not enough, look at cirrus and PAM.
It's a perfect fit for cirrus, but PAM indeed requires
set_readonlyin addition.Quoted 5 lines
It isn't a pefect fit for cirrus. If the mode changes in a way that makes mapping the map as RAM possible, or vice versa, and if the banks are contiguous, then
_update()results in two mappings or unmappings, while_commit()results in just one (sincem_r_update_topology()merges the two adjacent regions).
Quoted 5 lines
Continuous banks or mode changes are uncommon compared to offset changes of the mapped window. Cirrus does not need to bother about continuity of its banks (the memory core will), and mode changes could be implemented by allowing updates of the priority, thus reordering the regions instead of continuously deleting and recreating them.
The point is _update() can only make changes for one region atomic, while _commit() is more general. You can sometimes batch all changes into a single container region, but sometimes it is clumsy, and sometimes impossible.
Deletion and creation are needed because we can't update an alias' offset. I guess I can add that functionality. But it still isn't as general as _commit().
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
I also think now that describing a memory region offline via a struct and then passing that to an atomic add/del/update would be a more handy and future-proof API than an increasing number set functions.
Maybe. But it's not sufficient for atomic changes involving multiple regions.
Right. The question is still if there are use cases where this matters (ie. update frequencies comparable to graphic scenarios).
Does even cirrus update this often? I would guess cirrus usually uses the linear framebuffer, no?
I added support for aliases and the vga banks just to get Windows XP to clear the screen quickly on bootup (used to take ~10 seconds).rary changes in the cirrus remapping logs.
Quoted 9 lines
Quoted 5 lines
That causes some memory
to be temporarily inaccessible. I don't think it's a problem in practice, but if it is, we can fix it by stopping all vcpus if we detect this condition, and by adding an atomic change-memory-map-and-get-dirty-log ioctl to kvm.I'm not sure if the cirrus or any similar hardware supports consistent memory accesses during ongoing bank remappings (ie. while the CPU issuing the remapping IO commands is blocked on QEMU executing them).
Point is, unaffected regions (and so unaffected devices) are also modified. Consider a PAM modified from PCI to RAM. The adjacent RAM regions are removed and re-added. If some code on another cpu is running on this RAM, it would be a little confused.
The CPU that is issuing the command is unaffected.
Quoted 2 lines
But such an IOCTL would resolve our problem with dropping a logged region as well, right?
Yes, if done right. Still we need to support older kernels.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 34 lines · Avi Kivity
Quoted 27 lines · Jan Kiszka
Quoted 20 lines · Avi Kivity
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Jan Kiszka
Quoted 6 lines
The problem is that "update" can change lots of things. offset, size, whether it's mmio or RAM, read-onlyness, even the wierd things like coalesced mmio. So it's either a function with 324.2 parameters (or a large struct), or it's a series of functions with demarcation as to where the update begins and ends.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
We do not need to provide update support for each and every bit, but for the common cases.
memory_region_update_alias(region, offset, size)would be an excellent first candidate IMO.It's not enough, look at cirrus and PAM.
It's a perfect fit for cirrus, but PAM indeed requires
set_readonlyin addition.Quoted 5 lines
It isn't a pefect fit for cirrus. If the mode changes in a way that makes mapping the map as RAM possible, or vice versa, and if the banks are contiguous, then
_update()results in two mappings or unmappings, while_commit()results in just one (sincem_r_update_topology()merges the two adjacent regions).Quoted 5 lines
Continuous banks or mode changes are uncommon compared to offset changes of the mapped window. Cirrus does not need to bother about continuity of its banks (the memory core will), and mode changes could be implemented by allowing updates of the priority, thus reordering the regions instead of continuously deleting and recreating them.
Quoted 8 lines
The point is
_update()can only make changes for one region atomic, while_commit()is more general. You can sometimes batch all changes into a single container region, but sometimes it is clumsy, and sometimes impossible.Deletion and creation are needed because we can't update an alias' offset. I guess I can add that functionality. But it still isn't as general as
_commit().
OK. What about providing _update wrappers? They could be implemented internally by the memory API in terms of begin - remove region - change region object - re-add region - end. That would avoid boilerplate code on the user side and still keep the option to do open-coded transaction also outside the core.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
I also think now that describing a memory region offline via a struct and then passing that to an atomic add/del/update would be a more handy and future-proof API than an increasing number set functions.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Maybe. But it's not sufficient for atomic changes involving multiple regions.
Right. The question is still if there are use cases where this matters (ie. update frequencies comparable to graphic scenarios).
Does even cirrus update this often? I would guess cirrus usually uses the linear framebuffer, no?
Not sure how this mode is called, but when vram is mapped linearly into the 0xa0000 range via two 32K banks, you get quite a few updates on larger screen changes.
Quoted 20 lines
I added support for aliases and the vga banks just to get Windows XP to clear the screen quickly on bootup (used to take ~10 seconds).rary changes in the cirrus remapping logs.
Quoted 9 lines
Quoted 5 lines
That causes some memory
to be temporarily inaccessible. I don't think it's a problem in practice, but if it is, we can fix it by stopping all vcpus if we detect this condition, and by adding an atomic change-memory-map-and-get-dirty-log ioctl to kvm.I'm not sure if the cirrus or any similar hardware supports consistent memory accesses during ongoing bank remappings (ie. while the CPU issuing the remapping IO commands is blocked on QEMU executing them).
Point is, unaffected regions (and so unaffected devices) are also modified. Consider a PAM modified from PCI to RAM. The adjacent RAM regions are removed and re-added. If some code on another cpu is running on this RAM, it would be a little confused.
Quoted 6 lines
The CPU that is issuing the command is unaffected.
Quoted 2 lines
But such an IOCTL would resolve our problem with dropping a logged region as well, right?
Yes, if done right. Still we need to support older kernels.
We will need workarounds like we have today, e.g. confining PAM memory region fragmentation to certain patterns that known OSes require. Full, correct support would remain the privilege of host kernels that allow to combine multi-region updates to an atomic operation (+ returning or preserving dirty logs).
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 10 lines · Jan Kiszka
Quoted 9 lines
The point is
_update()can only make changes for one region atomic, while_commit()is more general. You can sometimes batch all changes into a single container region, but sometimes it is clumsy, and sometimes impossible.Deletion and creation are needed because we can't update an alias' offset. I guess I can add that functionality. But it still isn't as general as
_commit().
Quoted 5 lines
OK. What about providing
_updatewrappers? They could be implemented internally by the memory API in terms of begin - remove region - change region object - re-add region - end. That would avoid boilerplate code on the user side and still keep the option to do open-coded transaction also outside the core.
It's pretty easy to do updates without resorting to transactions. If it's just some property, you simply call m_r_update_topology(). Things like priority need a bit more logic to keep the list in sorted order, but it's not really difficult.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
I also think now that describing a memory region offline via a struct and then passing that to an atomic add/del/update would be a more handy and future-proof API than an increasing number set functions.
Maybe. But it's not sufficient for atomic changes involving multiple regions.
Right. The question is still if there are use cases where this matters (ie. update frequencies comparable to graphic scenarios).
Quoted 7 lines
Quoted 2 lines
Does even cirrus update this often? I would guess cirrus usually uses the linear framebuffer, no?
Not sure how this mode is called, but when vram is mapped linearly into the
0xa0000range via two 32K banks, you get quite a few updates on larger screen changes.
Ok. grub2 again? or another guest?
Quoted 11 lines
Quoted 5 lines
Quoted 3 lines
But such an IOCTL would resolve our problem with dropping a logged region as well, right?
Yes, if done right. Still we need to support older kernels.
We will need workarounds like we have today, e.g. confining PAM memory region fragmentation to certain patterns that known OSes require. Full, correct support would remain the privilege of host kernels that allow to combine multi-region updates to an atomic operation (+ returning or preserving dirty logs).
An atomic update + dirty log fetch can be emulated by temporarily freezing all vcpus.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 38 lines · Avi Kivity
Allow changes to the memory hierarchy to be accumulated and made visible all at once. This reduces computational effort, especially when an accelerator (e.g. kvm) is involved.
Useful when a single register update causes multiple changes to an address space.
Signed-off-by Avi Kivity <[email protected]>--- memory.c | 20 ++++++++++++++++++++ memory.h | 8 ++++++++ 2 files changed, 28 insertions(+), 0 deletions(-)memory.c +6
-0@@ -18,6 +18,8 @@#include "kvm.h" #include <assert.h> +unsigned memory_region_transaction_depth =0 ; +typedef struct AddrRange AddrRange ;struct AddrRange {@@ -648,6 +650,10 @@ static void address_space_update_topology(AddressSpace *as)static void memory_region_update_topology (void ) { +if (memory_region_transaction_depth) { +return ; + } +if (address_space_memory.root) {address_space_update_topology (&address_space_memory); }
memory.c static void memory_region_update_topology(void) · line 669
Quoted 8 lines
memory.c +5
-0@@ -656,6 +662,20 @@ static void memory_region_update_topology(void) } } +void memory_region_transaction_begin (void ) +{ + ++memory_region_transaction_depth; +} +
wouldn't you rather keep it safe by doing either here
if (!memory_region_transaction_depth)
memory_region_transaction_depth++;
memory.c static void memory_region_update_topology(void) · line 678
Quoted 11 lines
memory.c +9
-0+void memory_region_transaction_commit (void ) +{ +if (!memory_region_transaction_depth) { +abort (); + } + --memory_region_transaction_depth; +memory_region_update_topology (); +} +
or by doing here
while (!memory_region_transaction_depth)
memory_region_transaction_depth--;
with your setup nesting transactions will not work correctly I think. You seem to have designed it to not do nesting, so it's safer to make that explicit in your code imho
therefore I'd go for the change in _begin
also, wouldn't you rather rename memory_region_transaction_depth to memory_region_transaction_pending?
Quoted 22 lines
memory.c +0
-0void memory_region_init(MemoryRegion *mr,const char *name,
uint64_tsize)memory.h +8
-0@@ -246,6 +246,14 @@ void memory_region_add_subregion_overlap(MemoryRegion *mr,void memory_region_del_subregion (MemoryRegion *mr,MemoryRegion *subregion); +/* Start a transaction; changes will be accumulated and made visible only +* when the transaction ends. +*/ +void memory_region_transaction_begin (void ); +/* Commit a transaction and make changes visible to the guest. +*/ +void memory_region_transaction_commit (void ); +#endif #endif
Signature · 1 line
Ferry Huberts
Quoted 15 lines · Ferry Huberts
Quoted 8 lines · Avi Kivity
Allow changes to the memory hierarchy to be accumulated and made visible all at once. This reduces computational effort, especially when an accelerator (e.g. kvm) is involved.
Useful when a single register update causes multiple changes to an address space.
Quoted 5 lines
+void
memory_region_transaction_begin(void)
+{
+ ++memory_region_transaction_depth;
+}
+
Quoted 5 lines
wouldn't you rather keep it safe by doing either here
if (!memory_region_transaction_depth)
memory_region_transaction_depth++;
Why? I want to allow nesting transactions (not that I anticipate such a case).
Quoted 14 lines
Quoted 11 lines
+void
memory_region_transaction_commit(void)
+{
+ if (!memory_region_transaction_depth) {
+abort();
+ }+ --memory_region_transaction_depth;
+memory_region_update_topology();
+}
+or by doing here
Quoted 7 lines
while (!memory_region_transaction_depth)
memory_region_transaction_depth--;with your setup nesting transactions will not work correctly I think. You seem to have designed it to not do nesting, so it's safer to make that explicit in your code imho
Nesting should work just fine.
Quoted 4 lines
therefore I'd go for the change in
_beginalso, wouldn't you rather rename
memory_region_transaction_depthtomemory_region_transaction_pending?
The existing name works for me, but if people want it changed, that's fine too.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 16 lines · Avi Kivity
Quoted 15 lines · Ferry Huberts
Quoted 13 lines · Avi Kivity
Allow changes to the memory hierarchy to be accumulated and made visible all at once. This reduces computational effort, especially when an accelerator (e.g. kvm) is involved.
Useful when a single register update causes multiple changes to an address space.
+void
memory_region_transaction_begin(void)
+{
+ ++memory_region_transaction_depth;
+}
+
Quoted 25 lines
Quoted 5 lines
wouldn't you rather keep it safe by doing either here
if (!memory_region_transaction_depth)
memory_region_transaction_depth++;Why? I want to allow nesting transactions (not that I anticipate such a case).
Quoted 16 lines
Quoted 11 lines
+void
memory_region_transaction_commit(void)
+{
+ if (!memory_region_transaction_depth) {
+abort();
+ }+ --memory_region_transaction_depth;
+memory_region_update_topology();
+}
+or by doing here
while (!memory_region_transaction_depth)
memory_region_transaction_depth--;
doesn't memory_region_update_topology commit all accumulated changes? if it does then memory_region_transaction_depth is left non-zero in the nesting case while no more changes are actually present, resulting in superfluous calls to memory_region_update_topology.
maybe I misunderstood memory_region_update_topology?
Quoted 17 lines
Quoted 5 lines
with your setup nesting transactions will not work correctly I think. You seem to have designed it to not do nesting, so it's safer to make that explicit in your code imho
Nesting should work just fine.
Quoted 4 lines
therefore I'd go for the change in
_beginalso, wouldn't you rather rename
memory_region_transaction_depthtomemory_region_transaction_pending?The existing name works for me, but if people want it changed, that's fine too.
Signature · 1 line
Ferry Huberts
Quoted 12 lines · Ferry Huberts
Quoted 12 lines
Quoted 11 lines
Quoted 5 lines
+void
memory_region_transaction_begin(void)
+{
+ ++memory_region_transaction_depth;
+}
+wouldn't you rather keep it safe by doing either here
if (!memory_region_transaction_depth)
memory_region_transaction_depth++;
Quoted 5 lines
Quoted 3 lines
Why? I want to allow nesting transactions (not that I anticipate such a case).
doesn't
memory_region_update_topologycommit all accumulated changes?
It does.
Quoted 7 lines
if
it does thenmemory_region_transaction_depthis left non-zero in the nesting case while no more changes are actually present, resulting in superfluous calls tomemory_region_update_topology.maybe I misunderstood
memory_region_update_topology?
update_mapping()
{m_r_t_begin();
// call memory API functions to change hierarchy some_other_function() entered
m_r_t_begin();
// call more memory API functions to change hierarchy m_r_t_commit(); // nothing happenssome_other_function() exits
// call even more memory API functions to change hierarchy m_r_t_commit(); // all accumulated changes become visible }
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 30 lines · Avi Kivity
Quoted 12 lines · Ferry Huberts
Quoted 12 lines
Quoted 11 lines
Quoted 5 lines
+void
memory_region_transaction_begin(void)
+{
+ ++memory_region_transaction_depth;
+}
+wouldn't you rather keep it safe by doing either here
if (!memory_region_transaction_depth)
memory_region_transaction_depth++;Quoted 6 lines
Quoted 1 line
Why? I want to allow nesting transactions (not that I anticipate
such a
Quoted 2 lines
case).
doesn't
memory_region_update_topologycommit all accumulated changes?It does.
Quoted 7 lines
if
it does thenmemory_region_transaction_depthis left non-zero in the nesting case while no more changes are actually present, resulting in superfluous calls tomemory_region_update_topology.maybe I misunderstood
memory_region_update_topology?
Quoted 13 lines
update_mapping()
{m_r_t_begin();
// call memory API functions to change hierarchysome_other_function()entered
m_r_t_begin();
// call more memory API functions to change hierarchym_r_t_commit(); // nothing happenssome_other_function()exits
// call even more memory API functions to change hierarchym_r_t_commit(); // all accumulated changes become visible }
ahhh. I completely read over the memory_region_update_topology change. shame on me, sorry for the confusion!
Signature · 1 line
Ferry Huberts