Lines Matching refs:sr

41 static bool rand_alloc_choice(struct z_heap_stress_rec *sr)  in rand_alloc_choice()  argument
44 if (sr->blocks_alloced == 0) { in rand_alloc_choice()
46 } else if (sr->blocks_alloced >= sr->nblocks) { in rand_alloc_choice()
65 __ASSERT(sr->total_bytes < 0xffffffffU / 100, "too big for u32!"); in rand_alloc_choice()
66 uint32_t full_pct = (100 * sr->bytes_alloced) / sr->total_bytes; in rand_alloc_choice()
67 uint32_t target = sr->target_percent ? sr->target_percent : 1; in rand_alloc_choice()
70 if (full_pct < sr->target_percent) { in rand_alloc_choice()
81 static size_t rand_alloc_size(struct z_heap_stress_rec *sr) in rand_alloc_size() argument
83 ARG_UNUSED(sr); in rand_alloc_size()
94 static size_t rand_free_choice(struct z_heap_stress_rec *sr) in rand_free_choice() argument
96 return rand32() % sr->blocks_alloced; in rand_free_choice()
115 struct z_heap_stress_rec sr = { in sys_heap_stress() local
128 if (rand_alloc_choice(&sr)) { in sys_heap_stress()
129 size_t sz = rand_alloc_size(&sr); in sys_heap_stress()
130 void *p = sr.alloc_fn(sr.arg, sz); in sys_heap_stress()
135 sr.blocks[sr.blocks_alloced].ptr = p; in sys_heap_stress()
136 sr.blocks[sr.blocks_alloced].sz = sz; in sys_heap_stress()
137 sr.blocks_alloced++; in sys_heap_stress()
138 sr.bytes_alloced += sz; in sys_heap_stress()
141 int b = rand_free_choice(&sr); in sys_heap_stress()
142 void *p = sr.blocks[b].ptr; in sys_heap_stress()
143 size_t sz = sr.blocks[b].sz; in sys_heap_stress()
146 sr.blocks[b] = sr.blocks[sr.blocks_alloced - 1]; in sys_heap_stress()
147 sr.blocks_alloced--; in sys_heap_stress()
148 sr.bytes_alloced -= sz; in sys_heap_stress()
149 sr.free_fn(sr.arg, p); in sys_heap_stress()
151 result->accumulated_in_use_bytes += sr.bytes_alloced; in sys_heap_stress()