From owner-svn-src-stable-7@FreeBSD.ORG Fri Feb 6 12:06:39 2009 Return-Path: Delivered-To: svn-src-stable-7@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D804E106573D; Fri, 6 Feb 2009 12:06:39 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B88238FC1F; Fri, 6 Feb 2009 12:06:39 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n16C6dMj060415; Fri, 6 Feb 2009 12:06:39 GMT (envelope-from rwatson@svn.freebsd.org) Received: (from rwatson@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n16C6d7D060414; Fri, 6 Feb 2009 12:06:39 GMT (envelope-from rwatson@svn.freebsd.org) Message-Id: <200902061206.n16C6d7D060414@svn.freebsd.org> From: Robert Watson Date: Fri, 6 Feb 2009 12:06:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r188223 - in stable/7/sys: . contrib/pf dev/ath/ath_hal dev/cxgb security/audit X-BeenThere: svn-src-stable-7@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 7-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Feb 2009 12:06:55 -0000 Author: rwatson Date: Fri Feb 6 12:06:39 2009 New Revision: 188223 URL: http://svn.freebsd.org/changeset/base/188223 Log: Merge r184482 from head to stable/7: Protect the event->class lookup database using an rwlock instead of a mutex, as it's rarely changed but frequently accessed read-only from multiple threads, so a potentially significant source of contention. Sponsored by: Apple, Inc. Modified: stable/7/sys/ (props changed) stable/7/sys/contrib/pf/ (props changed) stable/7/sys/dev/ath/ath_hal/ (props changed) stable/7/sys/dev/cxgb/ (props changed) stable/7/sys/security/audit/audit_bsm_klib.c Modified: stable/7/sys/security/audit/audit_bsm_klib.c ============================================================================== --- stable/7/sys/security/audit/audit_bsm_klib.c Fri Feb 6 11:03:51 2009 (r188222) +++ stable/7/sys/security/audit/audit_bsm_klib.c Fri Feb 6 12:06:39 2009 (r188223) @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2005 Apple Inc. + * Copyright (c) 1999-2008 Apple Inc. * Copyright (c) 2005 Robert N. M. Watson * All rights reserved. * @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -64,9 +65,15 @@ struct evclass_list { }; static MALLOC_DEFINE(M_AUDITEVCLASS, "audit_evclass", "Audit event class"); -static struct mtx evclass_mtx; +static struct rwlock evclass_lock; static struct evclass_list evclass_hash[EVCLASSMAP_HASH_TABLE_SIZE]; +#define EVCLASS_LOCK_INIT() rw_init(&evclass_lock, "evclass_lock") +#define EVCLASS_RLOCK() rw_rlock(&evclass_lock) +#define EVCLASS_RUNLOCK() rw_runlock(&evclass_lock) +#define EVCLASS_WLOCK() rw_wlock(&evclass_lock) +#define EVCLASS_WUNLOCK() rw_wunlock(&evclass_lock) + /* * Look up the class for an audit event in the class mapping table. */ @@ -77,7 +84,7 @@ au_event_class(au_event_t event) struct evclass_elem *evc; au_class_t class; - mtx_lock(&evclass_mtx); + EVCLASS_RLOCK(); evcl = &evclass_hash[event % EVCLASSMAP_HASH_TABLE_SIZE]; class = 0; LIST_FOREACH(evc, &evcl->head, entry) { @@ -87,7 +94,7 @@ au_event_class(au_event_t event) } } out: - mtx_unlock(&evclass_mtx); + EVCLASS_RUNLOCK(); return (class); } @@ -110,12 +117,12 @@ au_evclassmap_insert(au_event_t event, a */ evc_new = malloc(sizeof(*evc), M_AUDITEVCLASS, M_WAITOK); - mtx_lock(&evclass_mtx); + EVCLASS_WLOCK(); evcl = &evclass_hash[event % EVCLASSMAP_HASH_TABLE_SIZE]; LIST_FOREACH(evc, &evcl->head, entry) { if (evc->event == event) { evc->class = class; - mtx_unlock(&evclass_mtx); + EVCLASS_WUNLOCK(); free(evc_new, M_AUDITEVCLASS); return; } @@ -124,7 +131,7 @@ au_evclassmap_insert(au_event_t event, a evc->event = event; evc->class = class; LIST_INSERT_HEAD(&evcl->head, evc, entry); - mtx_unlock(&evclass_mtx); + EVCLASS_WUNLOCK(); } void @@ -132,7 +139,7 @@ au_evclassmap_init(void) { int i; - mtx_init(&evclass_mtx, "evclass_mtx", NULL, MTX_DEF); + EVCLASS_LOCK_INIT(); for (i = 0; i < EVCLASSMAP_HASH_TABLE_SIZE; i++) LIST_INIT(&evclass_hash[i].head);