From owner-dev-commits-src-main@freebsd.org Wed Jun 2 15:15:59 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A95FC6457D1; Wed, 2 Jun 2021 15:15:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FwCKC3fQXz3lsT; Wed, 2 Jun 2021 15:15:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 553A219325; Wed, 2 Jun 2021 15:15:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 152FFxYx045972; Wed, 2 Jun 2021 15:15:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 152FFxxi045971; Wed, 2 Jun 2021 15:15:59 GMT (envelope-from git) Date: Wed, 2 Jun 2021 15:15:59 GMT Message-Id: <202106021515.152FFxxi045971@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: c9f8dcda856c - main - kqueue: replace kq_ncallouts loop with atomic_fetchadd MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c9f8dcda856c50325190326a618dc251311bc43a Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jun 2021 15:15:59 -0000 The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=c9f8dcda856c50325190326a618dc251311bc43a commit c9f8dcda856c50325190326a618dc251311bc43a Author: Mateusz Guzik AuthorDate: 2021-06-02 15:14:58 +0000 Commit: Mateusz Guzik CommitDate: 2021-06-02 15:14:58 +0000 kqueue: replace kq_ncallouts loop with atomic_fetchadd --- sys/kern/kern_event.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index b224ce87087e..63b28cd6024f 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -206,7 +206,7 @@ static struct filterops user_filtops = { }; static uma_zone_t knote_zone; -static unsigned int kq_ncallouts = 0; +static unsigned int __exclusive_cache_line kq_ncallouts; static unsigned int kq_calloutmax = 4 * 1024; SYSCTL_UINT(_kern, OID_AUTO, kq_calloutmax, CTLFLAG_RW, &kq_calloutmax, 0, "Maximum number of callouts allocated for kqueue"); @@ -813,18 +813,16 @@ filt_timerattach(struct knote *kn) { struct kq_timer_cb_data *kc; sbintime_t to; - unsigned int ncallouts; int error; error = filt_timervalidate(kn, &to); if (error != 0) return (error); - do { - ncallouts = kq_ncallouts; - if (ncallouts >= kq_calloutmax) - return (ENOMEM); - } while (!atomic_cmpset_int(&kq_ncallouts, ncallouts, ncallouts + 1)); + if (atomic_fetchadd_int(&kq_ncallouts, 1) + 1 > kq_calloutmax) { + atomic_subtract_int(&kq_ncallouts, 1); + return (ENOMEM); + } if ((kn->kn_sfflags & NOTE_ABSTIME) == 0) kn->kn_flags |= EV_CLEAR; /* automatically set */