memory: introduce memory_region_test_and_clear_dirty
This function avoids having to do two calls, one to test the dirty bit, and other to reset it. Signed-off-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
		
							parent
							
								
									5f718a15d0
								
							
						
					
					
						commit
						6c279db8ee
					
				@ -453,6 +453,22 @@ bool memory_region_get_dirty(MemoryRegion *mr, hwaddr addr,
 | 
				
			|||||||
void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr,
 | 
					void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr,
 | 
				
			||||||
                             hwaddr size);
 | 
					                             hwaddr size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * memory_region_test_and_clear_dirty: Check whether a range of bytes is dirty
 | 
				
			||||||
 | 
					 *                                     for a specified client. It clears them.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Checks whether a range of bytes has been written to since the last
 | 
				
			||||||
 | 
					 * call to memory_region_reset_dirty() with the same @client.  Dirty logging
 | 
				
			||||||
 | 
					 * must be enabled.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @mr: the memory region being queried.
 | 
				
			||||||
 | 
					 * @addr: the address (relative to the start of the region) being queried.
 | 
				
			||||||
 | 
					 * @size: the size of the range being queried.
 | 
				
			||||||
 | 
					 * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
 | 
				
			||||||
 | 
					 *          %DIRTY_MEMORY_VGA.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					bool memory_region_test_and_clear_dirty(MemoryRegion *mr, hwaddr addr,
 | 
				
			||||||
 | 
					                                        hwaddr size, unsigned client);
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap with
 | 
					 * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap with
 | 
				
			||||||
 *                                  any external TLBs (e.g. kvm)
 | 
					 *                                  any external TLBs (e.g. kvm)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										16
									
								
								memory.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								memory.c
									
									
									
									
									
								
							@ -1081,6 +1081,22 @@ void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr,
 | 
				
			|||||||
    return cpu_physical_memory_set_dirty_range(mr->ram_addr + addr, size, -1);
 | 
					    return cpu_physical_memory_set_dirty_range(mr->ram_addr + addr, size, -1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool memory_region_test_and_clear_dirty(MemoryRegion *mr, hwaddr addr,
 | 
				
			||||||
 | 
					                                        hwaddr size, unsigned client)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    bool ret;
 | 
				
			||||||
 | 
					    assert(mr->terminates);
 | 
				
			||||||
 | 
					    ret = cpu_physical_memory_get_dirty(mr->ram_addr + addr, size,
 | 
				
			||||||
 | 
					                                        1 << client);
 | 
				
			||||||
 | 
					    if (ret) {
 | 
				
			||||||
 | 
					        cpu_physical_memory_reset_dirty(mr->ram_addr + addr,
 | 
				
			||||||
 | 
					                                        mr->ram_addr + addr + size,
 | 
				
			||||||
 | 
					                                        1 << client);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void memory_region_sync_dirty_bitmap(MemoryRegion *mr)
 | 
					void memory_region_sync_dirty_bitmap(MemoryRegion *mr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    AddressSpace *as;
 | 
					    AddressSpace *as;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user