From owner-svn-src-head@freebsd.org Tue Jun 30 22:01:22 2020 Return-Path: Delivered-To: svn-src-head@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 99A1B3572A1; Tue, 30 Jun 2020 22:01:22 +0000 (UTC) (envelope-from markj@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49xJGV3bDLz42TG; Tue, 30 Jun 2020 22:01:22 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5E8BD1EDC9; Tue, 30 Jun 2020 22:01:22 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 05UM1MFn040903; Tue, 30 Jun 2020 22:01:22 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 05UM1MiH040901; Tue, 30 Jun 2020 22:01:22 GMT (envelope-from markj@FreeBSD.org) Message-Id: <202006302201.05UM1MiH040901@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Tue, 30 Jun 2020 22:01:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362814 - head/sys/opencrypto X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: head/sys/opencrypto X-SVN-Commit-Revision: 362814 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Jun 2020 22:01:22 -0000 Author: markj Date: Tue Jun 30 22:01:21 2020 New Revision: 362814 URL: https://svnweb.freebsd.org/changeset/base/362814 Log: Convert cryptostats to a counter_u64 array. The global counters were not SMP-friendly. Use per-CPU counters instead. Reviewed by: jhb Sponsored by: Rubicon Communications, LLC (Netgate) Differential Revision: https://reviews.freebsd.org/D25466 Modified: head/sys/opencrypto/crypto.c head/sys/opencrypto/cryptodev.h Modified: head/sys/opencrypto/crypto.c ============================================================================== --- head/sys/opencrypto/crypto.c Tue Jun 30 21:50:05 2020 (r362813) +++ head/sys/opencrypto/crypto.c Tue Jun 30 22:01:21 2020 (r362814) @@ -59,7 +59,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include #include #include #include @@ -232,10 +232,32 @@ static int crypto_kinvoke(struct cryptkop *krp); static void crypto_task_invoke(void *ctx, int pending); static void crypto_batch_enqueue(struct cryptop *crp); -static struct cryptostats cryptostats; -SYSCTL_STRUCT(_kern_crypto, OID_AUTO, stats, CTLFLAG_RW, &cryptostats, - cryptostats, "Crypto system statistics"); +static counter_u64_t cryptostats[sizeof(struct cryptostats) / sizeof(uint64_t)]; +SYSCTL_COUNTER_U64_ARRAY(_kern_crypto, OID_AUTO, stats, CTLFLAG_RW, + cryptostats, nitems(cryptostats), + "Crypto system statistics"); +#define CRYPTOSTAT_INC(stat) do { \ + counter_u64_add( \ + cryptostats[offsetof(struct cryptostats, stat) / sizeof(uint64_t)],\ + 1); \ +} while (0) + +static void +cryptostats_init(void *arg __unused) +{ + COUNTER_ARRAY_ALLOC(cryptostats, nitems(cryptostats), M_WAITOK); +} +SYSINIT(cryptostats_init, SI_SUB_COUNTER, SI_ORDER_ANY, cryptostats_init, NULL); + +static void +cryptostats_fini(void *arg __unused) +{ + COUNTER_ARRAY_FREE(cryptostats, nitems(cryptostats)); +} +SYSUNINIT(cryptostats_fini, SI_SUB_COUNTER, SI_ORDER_ANY, cryptostats_fini, + NULL); + /* Try to avoid directly exposing the key buffer as a symbol */ static struct keybuf *keybuf; @@ -1399,7 +1421,7 @@ crypto_dispatch(struct cryptop *crp) crp_sanity(crp); #endif - cryptostats.cs_ops++; + CRYPTOSTAT_INC(cs_ops); crp->crp_retw_id = ((uintptr_t)crp->crp_session) % crypto_workers_num; @@ -1460,7 +1482,7 @@ crypto_kdispatch(struct cryptkop *krp) { int error; - cryptostats.cs_kops++; + CRYPTOSTAT_INC(cs_kops); krp->krp_cap = NULL; error = crypto_kinvoke(krp); @@ -1767,7 +1789,7 @@ crypto_done(struct cryptop *crp) ("crypto_done: op already done, flags 0x%x", crp->crp_flags)); crp->crp_flags |= CRYPTO_F_DONE; if (crp->crp_etype != 0) - cryptostats.cs_errs++; + CRYPTOSTAT_INC(cs_errs); /* * CBIMM means unconditionally do the callback immediately; @@ -1839,7 +1861,7 @@ crypto_kdone(struct cryptkop *krp) struct cryptocap *cap; if (krp->krp_status != 0) - cryptostats.cs_kerrs++; + CRYPTOSTAT_INC(cs_kerrs); CRYPTO_DRIVER_LOCK(); cap = krp->krp_cap; KASSERT(cap->cc_koperations > 0, ("cc_koperations == 0")); @@ -1979,7 +2001,7 @@ crypto_proc(void) */ cap->cc_qblocked = 1; TAILQ_INSERT_HEAD(&crp_q, submit, crp_next); - cryptostats.cs_blocks++; + CRYPTOSTAT_INC(cs_blocks); } } @@ -2016,7 +2038,7 @@ crypto_proc(void) */ krp->krp_cap->cc_kqblocked = 1; TAILQ_INSERT_HEAD(&crp_kq, krp, krp_next); - cryptostats.cs_kblocks++; + CRYPTOSTAT_INC(cs_kblocks); } } @@ -2038,7 +2060,7 @@ crypto_proc(void) crp_sleep = 0; if (cryptoproc == NULL) break; - cryptostats.cs_intrs++; + CRYPTOSTAT_INC(cs_intrs); } } CRYPTO_Q_UNLOCK(); @@ -2099,7 +2121,7 @@ crypto_ret_proc(struct crypto_ret_worker *ret_worker) "crypto_ret_wait", 0); if (ret_worker->cryptoretproc == NULL) break; - cryptostats.cs_rets++; + CRYPTOSTAT_INC(cs_rets); } } CRYPTO_RETW_UNLOCK(ret_worker); Modified: head/sys/opencrypto/cryptodev.h ============================================================================== --- head/sys/opencrypto/cryptodev.h Tue Jun 30 21:50:05 2020 (r362813) +++ head/sys/opencrypto/cryptodev.h Tue Jun 30 22:01:21 2020 (r362814) @@ -327,14 +327,14 @@ struct crypt_kop { #define CIOCCRYPTAEAD _IOWR('c', 109, struct crypt_aead) struct cryptostats { - u_int32_t cs_ops; /* symmetric crypto ops submitted */ - u_int32_t cs_errs; /* symmetric crypto ops that failed */ - u_int32_t cs_kops; /* asymetric/key ops submitted */ - u_int32_t cs_kerrs; /* asymetric/key ops that failed */ - u_int32_t cs_intrs; /* crypto swi thread activations */ - u_int32_t cs_rets; /* crypto return thread activations */ - u_int32_t cs_blocks; /* symmetric op driver block */ - u_int32_t cs_kblocks; /* symmetric op driver block */ + uint64_t cs_ops; /* symmetric crypto ops submitted */ + uint64_t cs_errs; /* symmetric crypto ops that failed */ + uint64_t cs_kops; /* asymetric/key ops submitted */ + uint64_t cs_kerrs; /* asymetric/key ops that failed */ + uint64_t cs_intrs; /* crypto swi thread activations */ + uint64_t cs_rets; /* crypto return thread activations */ + uint64_t cs_blocks; /* symmetric op driver block */ + uint64_t cs_kblocks; /* symmetric op driver block */ }; #ifdef _KERNEL