From owner-p4-projects@FreeBSD.ORG Fri Jan 4 05:13:30 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E403616A419; Fri, 4 Jan 2008 05:13:29 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A8A3916A417 for ; Fri, 4 Jan 2008 05:13:29 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 9852D13C45A for ; Fri, 4 Jan 2008 05:13:29 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m045DTNb024798 for ; Fri, 4 Jan 2008 05:13:29 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m045DT9m024795 for perforce@freebsd.org; Fri, 4 Jan 2008 05:13:29 GMT (envelope-from jb@freebsd.org) Date: Fri, 4 Jan 2008 05:13:29 GMT Message-Id: <200801040513.m045DT9m024795@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jb@freebsd.org using -f From: John Birrell To: Perforce Change Reviews Cc: Subject: PERFORCE change 132459 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Jan 2008 05:13:30 -0000 http://perforce.freebsd.org/chv.cgi?CH=132459 Change 132459 by jb@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++;