Lines Matching full:region

2  * Memory region management for Tiny Code Generator for QEMU
57 * dynamically allocate from as demand dictates. Given appropriate region
68 size_t size; /* size of one region */
73 size_t current; /* current region index */
77 static struct tcg_region_state region; variable
94 return (size_t)(p - region.start_aligned) <= region.total_size; in in_code_gen_buffer()
125 /* Assert that we end with a pointer in the rw region. */ in tcg_splitwx_to_rw()
185 region_trees = qemu_memalign(qemu_dcache_linesize, region.n * tree_size); in tcg_region_trees_init()
186 for (i = 0; i < region.n; i++) { in tcg_region_trees_init()
209 if (p < region.start_aligned) { in tc_ptr_to_region_tree()
212 ptrdiff_t offset = p - region.start_aligned; in tc_ptr_to_region_tree()
214 if (offset > region.stride * (region.n - 1)) { in tc_ptr_to_region_tree()
215 region_idx = region.n - 1; in tc_ptr_to_region_tree()
217 region_idx = offset / region.stride; in tc_ptr_to_region_tree()
268 for (i = 0; i < region.n; i++) { in tcg_region_tree_lock_all()
279 for (i = 0; i < region.n; i++) { in tcg_region_tree_unlock_all()
291 for (i = 0; i < region.n; i++) { in tcg_tb_foreach()
305 for (i = 0; i < region.n; i++) { in tcg_nb_tbs()
319 for (i = 0; i < region.n; i++) { in tcg_region_tree_reset_all()
333 start = region.start_aligned + curr_region * region.stride; in tcg_region_bounds()
334 end = start + region.size; in tcg_region_bounds()
337 start = region.after_prologue; in tcg_region_bounds()
339 /* The final region may have a few extra pages due to earlier rounding. */ in tcg_region_bounds()
340 if (curr_region == region.n - 1) { in tcg_region_bounds()
341 end = region.start_aligned + region.total_size; in tcg_region_bounds()
362 if (region.current == region.n) { in tcg_region_alloc__locked()
365 tcg_region_assign(s, region.current); in tcg_region_alloc__locked()
366 region.current++; in tcg_region_alloc__locked()
371 * Request a new region once the one in use has filled up.
377 /* read the region size now; alloc__locked will overwrite it on success */ in tcg_region_alloc()
380 qemu_mutex_lock(&region.lock); in tcg_region_alloc()
383 region.agg_size_full += size_full - TCG_HIGHWATER; in tcg_region_alloc()
385 qemu_mutex_unlock(&region.lock); in tcg_region_alloc()
390 * Perform a context's first region allocation.
391 * This function does _not_ increment region.agg_size_full.
401 qemu_mutex_lock(&region.lock); in tcg_region_initial_alloc()
403 qemu_mutex_unlock(&region.lock); in tcg_region_initial_alloc()
412 qemu_mutex_lock(&region.lock); in tcg_region_reset_all()
413 region.current = 0; in tcg_region_reset_all()
414 region.agg_size_full = 0; in tcg_region_reset_all()
420 qemu_mutex_unlock(&region.lock); in tcg_region_reset_all()
438 /* Use a single region if all we have is one vCPU thread */ in tcg_n_regions()
444 * Try to have more regions than max_cpus, with each region being >= 2 MB. in tcg_n_regions()
445 * If we can't, then just allocate one region per vCPU thread. in tcg_n_regions()
525 region.start_aligned = buf; in alloc_code_gen_buffer()
526 region.total_size = size; in alloc_code_gen_buffer()
548 region.start_aligned = buf; in alloc_code_gen_buffer()
549 region.total_size = size; in alloc_code_gen_buffer()
566 region.start_aligned = buf; in alloc_code_gen_buffer_anon()
567 region.total_size = size; in alloc_code_gen_buffer_anon()
593 region.start_aligned = buf_rw; in alloc_code_gen_buffer_splitwx_memfd()
594 region.total_size = size; in alloc_code_gen_buffer_splitwx_memfd()
638 buf_rw = (mach_vm_address_t)region.start_aligned; in alloc_code_gen_buffer_splitwx_vmremap()
725 * Initializes region partitioning.
730 * Region partitioning works by splitting code_gen_buffer into separate regions,
735 * least max_cpus regions in MTTCG. In !MTTCG we use a single region.
740 * In user-mode we use a single region. Having multiple regions in user-mode
746 * that the availability of at least one region per vCPU thread.
779 qemu_madvise(region.start_aligned, region.total_size, QEMU_MADV_HUGEPAGE); in tcg_region_init()
781 qemu_madvise(region.start_aligned + tcg_splitwx_diff, in tcg_region_init()
782 region.total_size, QEMU_MADV_HUGEPAGE); in tcg_region_init()
788 * the buffer; we will assign those to the last region. in tcg_region_init()
790 region.n = tcg_n_regions(tb_size, max_cpus); in tcg_region_init()
791 region_size = tb_size / region.n; in tcg_region_init()
794 /* A region must have at least 2 pages; one code, one guard */ in tcg_region_init()
796 region.stride = region_size; in tcg_region_init()
799 region.size = region_size - page_size; in tcg_region_init()
800 region.total_size -= page_size; in tcg_region_init()
803 * The first region will be smaller than the others, via the prologue, in tcg_region_init()
804 * which has yet to be allocated. For now, the first region begins at in tcg_region_init()
807 region.after_prologue = region.start_aligned; in tcg_region_init()
809 /* init the region struct */ in tcg_region_init()
810 qemu_mutex_init(&region.lock); in tcg_region_init()
824 for (size_t i = 0, n = region.n; i < n; i++) { in tcg_region_init()
856 * Leave the initial context initialized to the first region. in tcg_region_init()
865 /* Deduct the prologue from the first region. */ in tcg_region_prologue_set()
866 g_assert(region.start_aligned == s->code_gen_buffer); in tcg_region_prologue_set()
867 region.after_prologue = s->code_ptr; in tcg_region_prologue_set()
869 /* Recompute boundaries of the first region. */ in tcg_region_prologue_set()
873 tcg_register_jit(tcg_splitwx_to_rx(region.after_prologue), in tcg_region_prologue_set()
874 region.start_aligned + region.total_size - in tcg_region_prologue_set()
875 region.after_prologue); in tcg_region_prologue_set()
891 qemu_mutex_lock(&region.lock); in tcg_code_size()
892 total = region.agg_size_full; in tcg_code_size()
901 qemu_mutex_unlock(&region.lock); in tcg_code_size()
915 guard_size = region.stride - region.size; in tcg_code_capacity()
916 capacity = region.total_size; in tcg_code_capacity()
917 capacity -= (region.n - 1) * guard_size; in tcg_code_capacity()
918 capacity -= region.n * TCG_HIGHWATER; in tcg_code_capacity()