From nobody Sat May 20 12:48:29 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QNk661ZSNz4C2ys; Sat, 20 May 2023 12:48:30 +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 4QNk660sWDz4BCC; Sat, 20 May 2023 12:48:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684586910; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=H+BZWKZS67JJZ97WlqWmv1NdeftVnO4ujSeAVzDLnbY=; b=CiEJpYqEaE32DDTLw5SZVW5D0xzhVD4OLgqwRbTtQsV8Rh2ic/vd3U2KZUFovEM9T7IoRM VTgBF8zxG8/4XPVEAVIM9SyLYcy7atQQCiT5jtgHq2UvLxIh8Lvbh9l4lQMKPUqGjHn/7U bXlMXVA5awZr8MpWIsrP3d6anq2ZXbw4reL3eLF5MT3dVuckMToFLcunUTjZhlmA4u8KaW pMWzq30zL28yP5FVuN15lqY82N8oWK2vATq0w+FlYNgCk7RZr1aHdmhP3hobKtxgns4OXj 55dqv1FbPyucaCCZmxGxP/sRX5Y1dcJSnC5/oeG68jVVpP9dtH0V99ldapzthQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684586910; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=H+BZWKZS67JJZ97WlqWmv1NdeftVnO4ujSeAVzDLnbY=; b=JfUUZBoDTXeVvvA5uw7p8ODimiTi5S9GPy2SxbvKN9ORQA/kcxZCKiD6sRHYqlxgggvHK1 mNZAt3z0psBLb1dyL/dACmN5AAOsT9rQu7LkHKAjgZ6YeaILomFDQ1a+tuyO24JsYxQ8ab e4kTUZVfPjrIsDq69Hfg7VLR74JthA1D8ZX8bga9FEC7M5KzW5MjKGCB7VOUjMWnQ+JLlB azmvwgoNO1aWBcHqIeiVKUSAPX/mEZIQKVfAooZHah5EyOxVO70Bly4Y9YMnywzLx/upMA g7HLNd+O48GPVoIDGqp4xghLESWzLXA3LQqkMthrND/iP2MGTo5r5mO+RXqAZQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684586910; a=rsa-sha256; cv=none; b=yXexB1ivsVtCGRWD5O59XbQCyamGj2F37n4dAPpnfCcGVyhrEGj0l4NCDWOtKU/ZKwR+ej Lxx2IKn3AhfZQpyUMf21XjWnwAy/GNPhxnQmkpzG3SkUlyRQIxf2jiLRDKT6G2GKtjLF8L S9LQqu7YNThKzpcEIOvKews38E6PPPo9AwlN9ST8FWTRMoridcpLhLqj80lBfv5BxY22z9 2WU6h7fxdYIyjH1XOB3yNvm68QxhdaO2/tlvYJh5iAge7RC1uQZnywHhSlGMhhq04hs92M AA9gD3KFOMjYw2XRZM7Ju+6/Ji7E2RTHxbFlJEA/Jhix0PvYDXL0dWt+VCDJ4Q== 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 4QNk656Zwhz192x; Sat, 20 May 2023 12:48:29 +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 34KCmTTP034043; Sat, 20 May 2023 12:48:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34KCmTGC034042; Sat, 20 May 2023 12:48:29 GMT (envelope-from git) Date: Sat, 20 May 2023 12:48:29 GMT Message-Id: <202305201248.34KCmTGC034042@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: e0c86f5c2feb - main - td: line up with other clean up in thread_reap_domain List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org 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: e0c86f5c2feb95d687eeedb0eafe14c3f76bff41 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=e0c86f5c2feb95d687eeedb0eafe14c3f76bff41 commit e0c86f5c2feb95d687eeedb0eafe14c3f76bff41 Author: Mateusz Guzik AuthorDate: 2022-08-19 19:51:53 +0000 Commit: Mateusz Guzik CommitDate: 2023-05-20 12:48:15 +0000 td: line up with other clean up in thread_reap_domain NFC --- sys/kern/kern_thread.c | 55 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c index 585531d3ab3a..67712450c128 100644 --- a/sys/kern/kern_thread.c +++ b/sys/kern/kern_thread.c @@ -338,6 +338,46 @@ tidbatch_final(struct tidbatch *tb) } } +/* + * Batching thread count free, for consistency + */ +struct tdcountbatch { + int n; +}; + +static void +tdcountbatch_prep(struct tdcountbatch *tb) +{ + + tb->n = 0; +} + +static void +tdcountbatch_add(struct tdcountbatch *tb, struct thread *td __unused) +{ + + tb->n++; +} + +static void +tdcountbatch_process(struct tdcountbatch *tb) +{ + + if (tb->n == 32) { + thread_count_sub(tb->n); + tb->n = 0; + } +} + +static void +tdcountbatch_final(struct tdcountbatch *tb) +{ + + if (tb->n != 0) { + thread_count_sub(tb->n); + } +} + /* * Prepare a thread for use. */ @@ -589,7 +629,7 @@ thread_reap_domain(struct thread_domain_data *tdd) struct tidbatch tidbatch; struct credbatch credbatch; struct limbatch limbatch; - int tdcount; + struct tdcountbatch tdcountbatch; /* * Reading upfront is pessimal if followed by concurrent atomic_swap, @@ -612,7 +652,7 @@ thread_reap_domain(struct thread_domain_data *tdd) tidbatch_prep(&tidbatch); credbatch_prep(&credbatch); limbatch_prep(&limbatch); - tdcount = 0; + tdcountbatch_prep(&tdcountbatch); while (itd != NULL) { ntd = itd->td_zombie; @@ -621,17 +661,14 @@ thread_reap_domain(struct thread_domain_data *tdd) tidbatch_add(&tidbatch, itd); credbatch_add(&credbatch, itd); limbatch_add(&limbatch, itd); + tdcountbatch_add(&tdcountbatch, itd); thread_free_batched(itd); tidbatch_process(&tidbatch); credbatch_process(&credbatch); limbatch_process(&limbatch); - tdcount++; - if (tdcount == 32) { - thread_count_sub(tdcount); - tdcount = 0; - } + tdcountbatch_process(&tdcountbatch); itd = ntd; } @@ -639,9 +676,7 @@ thread_reap_domain(struct thread_domain_data *tdd) tidbatch_final(&tidbatch); credbatch_final(&credbatch); limbatch_final(&limbatch); - if (tdcount != 0) { - thread_count_sub(tdcount); - } + tdcountbatch_final(&tdcountbatch); } /*