PERFORCE change 132459 for review
John Birrell
jb at FreeBSD.org
Thu Jan 3 21:13:30 PST 2008
http://perforce.freebsd.org/chv.cgi?CH=132459
Change 132459 by jb at jb_freebsd1 on 2008/01/04 05:13:01
Drop the mutex lock before freeing memory and obtain it again
directly after. The window the the CPU is unlocked could be
enough for another thread to get in a do the expansion and possibly
to fill the expanded arrays, so put the expand call in a loop
(while the mutex is locked) and only come out when there is space
for the cyclic being added.
Affected files ...
.. //depot/projects/dtrace/src/sys/cddl/kern/cyclic.c#7 edit
Differences ...
==== //depot/projects/dtrace/src/sys/cddl/kern/cyclic.c#7 (text+ko) ====
@@ -690,10 +690,14 @@
mtx_lock_spin(&cpu->cyp_mtx);
/* Check if another thread beat us while the mutex was unlocked. */
- if (old_size < cpu->cyp_size) {
+ if (old_size != cpu->cyp_size) {
/* Oh well, he won. */
+ mtx_unlock_spin(&cpu->cyp_mtx);
+
free(new_heap, M_CYCLIC);
free(new_cyclics, M_CYCLIC);
+
+ mtx_lock_spin(&cpu->cyp_mtx);
return;
}
@@ -722,8 +726,12 @@
if (old_cyclics != NULL) {
ASSERT(old_heap != NULL);
ASSERT(old_size != 0);
+ mtx_unlock_spin(&cpu->cyp_mtx);
+
free(old_cyclics, M_CYCLIC);
free(old_heap, M_CYCLIC);
+
+ mtx_lock_spin(&cpu->cyp_mtx);
}
}
@@ -741,10 +749,10 @@
ASSERT(!(cpu->cyp_cpu->cpu_flags & CPU_OFFLINE));
ASSERT(when->cyt_when >= 0 && when->cyt_interval > 0);
- if (cpu->cyp_nelems == cpu->cyp_size) {
+ while (cpu->cyp_nelems == cpu->cyp_size)
cyclic_expand(cpu);
- ASSERT(cpu->cyp_nelems < cpu->cyp_size);
- }
+
+ ASSERT(cpu->cyp_nelems < cpu->cyp_size);
nelems = cpu->cyp_nelems++;
More information about the p4-projects
mailing list