Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757457AbdLTXhq (ORCPT ); Wed, 20 Dec 2017 18:37:46 -0500 Received: from merlin.infradead.org ([205.233.59.134]:52094 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757397AbdLTXhU (ORCPT ); Wed, 20 Dec 2017 18:37:20 -0500 Subject: Re: [PATCH RFC 2/3] crypto: Implement a generic crypto statistics To: Corentin Labbe , davem@davemloft.net, herbert@gondor.apana.org.au, nhorman@tuxdriver.com Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org References: <1513800567-12764-1-git-send-email-clabbe@baylibre.com> <1513800567-12764-3-git-send-email-clabbe@baylibre.com> From: Randy Dunlap Message-ID: Date: Wed, 20 Dec 2017 15:37:13 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <1513800567-12764-3-git-send-email-clabbe@baylibre.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2928 Lines: 93 On 12/20/2017 12:09 PM, Corentin Labbe wrote: > This patch implement a generic way to get statistics about all crypto > usages. > > Signed-off-by: Corentin Labbe > --- > crypto/Kconfig | 11 +++ > crypto/ahash.c | 18 +++++ > crypto/algapi.c | 186 +++++++++++++++++++++++++++++++++++++++++++++ > crypto/rng.c | 3 + > include/crypto/acompress.h | 10 +++ > include/crypto/akcipher.h | 12 +++ > include/crypto/kpp.h | 9 +++ > include/crypto/rng.h | 5 ++ > include/crypto/skcipher.h | 8 ++ > include/linux/crypto.h | 22 ++++++ > 10 files changed, 284 insertions(+) > > diff --git a/crypto/Kconfig b/crypto/Kconfig > index d6e9b60fc063..69f1822a026b 100644 > --- a/crypto/Kconfig > +++ b/crypto/Kconfig > @@ -1781,6 +1781,17 @@ config CRYPTO_USER_API_AEAD > This option enables the user-spaces interface for AEAD > cipher algorithms. > > +config CRYPTO_STATS > + bool "Crypto usage statistics for User-space" > + help > + This option enables the gathering of crypto stats. > + This will collect: > + - encrypt/decrypt size and numbers of symmeric operations symmetric > + - compress/decompress size and numbers of compress operations > + - size and numbers of hash operations > + - encrypt/decrypt/sign/verify numbers for asymmetric operations > + - generate/seed numbers for rng operations > + > config CRYPTO_HASH_INFO > bool > > diff --git a/crypto/algapi.c b/crypto/algapi.c > index b8f6122f37e9..4fca4576af78 100644 > --- a/crypto/algapi.c > +++ b/crypto/algapi.c > @@ -20,11 +20,158 @@ > #include > #include > #include > +#include > > #include "internal.h" > > +static ssize_t fcrypto_stat_type(struct kobject *kobj, > + struct kobj_attribute *attr, char *buf) > +{ > + struct crypto_alg *alg; > + u32 type; > + > + alg = container_of(kobj, struct crypto_alg, cra_stat_obj); > + type = (alg->cra_flags & CRYPTO_ALG_TYPE_MASK); > + if (type == CRYPTO_ALG_TYPE_ABLKCIPHER || > + type == CRYPTO_ALG_TYPE_SKCIPHER || > + type == CRYPTO_ALG_TYPE_CIPHER || > + type == CRYPTO_ALG_TYPE_BLKCIPHER > + ) > + return snprintf(buf, 9, "cipher\n"); > + if (type == CRYPTO_ALG_TYPE_AHASH || > + type == CRYPTO_ALG_TYPE_HASH > + ) > + return snprintf(buf, 9, "hash\n"); > + if (type == CRYPTO_ALG_TYPE_COMPRESS || > + type == CRYPTO_ALG_TYPE_SCOMPRESS) > + return snprintf(buf, 11, "compress\n"); > + if (type == CRYPTO_ALG_TYPE_RNG) > + return snprintf(buf, 9, "rng\n"); > + if (type == CRYPTO_ALG_TYPE_AKCIPHER) > + return snprintf(buf, 11, "asymetric\n"); asymmetric > + if (type == CRYPTO_ALG_TYPE_KPP) > + return snprintf(buf, 4, "kpp\n"); > + return snprintf(buf, 16, "unknown %x\n", type); > +} -- ~Randy