From owner-trustedbsd-cvs@FreeBSD.ORG Sat Mar 18 16:58:01 2006 Return-Path: X-Original-To: trustedbsd-cvs@freebsd.org Delivered-To: trustedbsd-cvs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 213BA16A482 for ; Sat, 18 Mar 2006 16:58:01 +0000 (UTC) (envelope-from owner-perforce@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [209.31.154.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 404D643D49 for ; Sat, 18 Mar 2006 16:57:59 +0000 (GMT) (envelope-from owner-perforce@freebsd.org) Received: from mx2.freebsd.org (mx2.freebsd.org [216.136.204.119]) by cyrus.watson.org (Postfix) with ESMTP id 7F69746C44 for ; Sat, 18 Mar 2006 11:57:32 -0500 (EST) Received: from hub.freebsd.org (hub.freebsd.org [216.136.204.18]) by mx2.freebsd.org (Postfix) with ESMTP id 85529554A8; Sat, 18 Mar 2006 16:57:49 +0000 (GMT) (envelope-from owner-perforce@freebsd.org) Received: by hub.freebsd.org (Postfix, from userid 32767) id 7E1C116A420; Sat, 18 Mar 2006 16:57:49 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2955A16A400 for ; Sat, 18 Mar 2006 16:57:49 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id DDFF443D45 for ; Sat, 18 Mar 2006 16:57:48 +0000 (GMT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k2IGvmLn004080 for ; Sat, 18 Mar 2006 16:57:48 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k2IGvmPB004077 for perforce@freebsd.org; Sat, 18 Mar 2006 16:57:48 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Sat, 18 Mar 2006 16:57:48 GMT Message-Id: <200603181657.k2IGvmPB004077@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Cc: Subject: PERFORCE change 93510 for review X-BeenThere: trustedbsd-cvs@FreeBSD.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: TrustedBSD CVS and Perforce commit message list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Mar 2006 16:58:01 -0000 http://perforce.freebsd.org/chv.cgi?CH=93510 Change 93510 by rwatson@rwatson_peppercorn on 2006/03/18 16:57:39 Move wait loop up to top of audit_worker work loop, and add replacement as a condition for breaking from the wait loop. Move drain logic into its own function, audit_worker_drain(), and invoke that. Follow advice of comment and don't wake up when going below the watermark if we are draining, since no one is interested. Affected files ... .. //depot/projects/trustedbsd/audit3/sys/security/audit/audit.c#20 edit Differences ... ==== //depot/projects/trustedbsd/audit3/sys/security/audit/audit.c#20 (text+ko) ==== @@ -524,6 +524,22 @@ } /* + * Drain the audit commit queue and free the records. Used if there are + * records present, but no audit log target. + */ +static void +audit_worker_drain(void) +{ + struct kaudit_record *ar; + + while ((ar = TAILQ_FIRST(&audit_q))) { + TAILQ_REMOVE(&audit_q, ar, k_q); + uma_zfree(audit_record_zone, ar); + audit_q_len--; + } +} + +/* * The audit_worker thread is responsible for watching the event queue, * dequeueing records, converting them to BSM format, and committing them to * disk. In order to minimize lock thrashing, records are dequeued in sets @@ -556,10 +572,16 @@ mtx_assert(&audit_mtx, MA_OWNED); /* - * XXXRW: Logic here should really be: while (!events and - * !records) cv_wait(), then process events, and then - * records. + * Wait for record or rotation events. */ + while (!audit_replacement_flag && TAILQ_EMPTY(&audit_q)) { + AUDIT_PRINTF(("audit_worker waiting\n")); + cv_wait(&audit_cv, &audit_mtx); + AUDIT_PRINTF(("audit_worker woken up\n")); + AUDIT_PRINTF(("audit_worker: new vp = %p; value of " + "flag %d\n", audit_replacement_vp, + audit_replacement_flag)); + } /* * First priority: replace the audit log target if requested. @@ -567,19 +589,6 @@ audit_worker_rotate(&audit_cred, &audit_vp, audit_td); /* - * Next, check to see if we have any records to drain into - * the vnode. If not, go back to waiting for an event. - */ - if (TAILQ_EMPTY(&audit_q)) { - AUDIT_PRINTF(("audit_worker waiting\n")); - cv_wait(&audit_cv, &audit_mtx); - AUDIT_PRINTF(("audit_worker woken up\n")); - AUDIT_PRINTF(("audit_worker: new vp = %p; value of flag %d\n", - audit_replacement_vp, audit_replacement_flag)); - continue; - } - - /* * If we have records, but there's no active vnode to write * to, drain the record queue. Generally, we prevent the * unnecessary allocation of records elsewhere, but we need @@ -587,17 +596,7 @@ * queueing. Go back to waiting when we're done. */ if (audit_vp == NULL) { - while ((ar = TAILQ_FIRST(&audit_q))) { - TAILQ_REMOVE(&audit_q, ar, k_q); - uma_zfree(audit_record_zone, ar); - audit_q_len--; - /* - * XXXRW: Why broadcast if we hold the - * mutex and know that audit_vp is NULL? - */ - if (audit_q_len <= audit_qctrl.aq_lowater) - cv_broadcast(&audit_commit_cv); - } + audit_worker_drain(); continue; }