Skip to content

Commit

Permalink
crypto: user - Split stats in multiple structures
Browse files Browse the repository at this point in the history
Like for userspace, this patch splits stats into multiple structures,
one for each algorithm class.
Signed-off-by: Corentin Labbe <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
montjoie authored and herbertx committed Dec 7, 2018
1 parent 5fff817 commit 17c18f9
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 160 deletions.
108 changes: 51 additions & 57 deletions crypto/algapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,7 @@ static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg)
list_add(&larval->alg.cra_list, &crypto_alg_list);

#ifdef CONFIG_CRYPTO_STATS
atomic64_set(&alg->encrypt_cnt, 0);
atomic64_set(&alg->decrypt_cnt, 0);
atomic64_set(&alg->encrypt_tlen, 0);
atomic64_set(&alg->decrypt_tlen, 0);
atomic64_set(&alg->verify_cnt, 0);
atomic64_set(&alg->cipher_err_cnt, 0);
atomic64_set(&alg->sign_cnt, 0);
memset(&alg->stats, 0, sizeof(alg->stats));
#endif

out:
Expand Down Expand Up @@ -1089,10 +1083,10 @@ void crypto_stats_ablkcipher_encrypt(unsigned int nbytes, int ret,
struct crypto_alg *alg)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
atomic64_inc(&alg->cipher_err_cnt);
atomic64_inc(&alg->stats.cipher.cipher_err_cnt);
} else {
atomic64_inc(&alg->encrypt_cnt);
atomic64_add(nbytes, &alg->encrypt_tlen);
atomic64_inc(&alg->stats.cipher.encrypt_cnt);
atomic64_add(nbytes, &alg->stats.cipher.encrypt_tlen);
}
crypto_alg_put(alg);
}
Expand All @@ -1102,10 +1096,10 @@ void crypto_stats_ablkcipher_decrypt(unsigned int nbytes, int ret,
struct crypto_alg *alg)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
atomic64_inc(&alg->cipher_err_cnt);
atomic64_inc(&alg->stats.cipher.cipher_err_cnt);
} else {
atomic64_inc(&alg->decrypt_cnt);
atomic64_add(nbytes, &alg->decrypt_tlen);
atomic64_inc(&alg->stats.cipher.decrypt_cnt);
atomic64_add(nbytes, &alg->stats.cipher.decrypt_tlen);
}
crypto_alg_put(alg);
}
Expand All @@ -1115,10 +1109,10 @@ void crypto_stats_aead_encrypt(unsigned int cryptlen, struct crypto_alg *alg,
int ret)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
atomic64_inc(&alg->aead_err_cnt);
atomic64_inc(&alg->stats.aead.aead_err_cnt);
} else {
atomic64_inc(&alg->encrypt_cnt);
atomic64_add(cryptlen, &alg->encrypt_tlen);
atomic64_inc(&alg->stats.aead.encrypt_cnt);
atomic64_add(cryptlen, &alg->stats.aead.encrypt_tlen);
}
crypto_alg_put(alg);
}
Expand All @@ -1128,10 +1122,10 @@ void crypto_stats_aead_decrypt(unsigned int cryptlen, struct crypto_alg *alg,
int ret)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
atomic64_inc(&alg->aead_err_cnt);
atomic64_inc(&alg->stats.aead.aead_err_cnt);
} else {
atomic64_inc(&alg->decrypt_cnt);
atomic64_add(cryptlen, &alg->decrypt_tlen);
atomic64_inc(&alg->stats.aead.decrypt_cnt);
atomic64_add(cryptlen, &alg->stats.aead.decrypt_tlen);
}
crypto_alg_put(alg);
}
Expand All @@ -1141,10 +1135,10 @@ void crypto_stats_akcipher_encrypt(unsigned int src_len, int ret,
struct crypto_alg *alg)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
atomic64_inc(&alg->akcipher_err_cnt);
atomic64_inc(&alg->stats.akcipher.akcipher_err_cnt);
} else {
atomic64_inc(&alg->encrypt_cnt);
atomic64_add(src_len, &alg->encrypt_tlen);
atomic64_inc(&alg->stats.akcipher.encrypt_cnt);
atomic64_add(src_len, &alg->stats.akcipher.encrypt_tlen);
}
crypto_alg_put(alg);
}
Expand All @@ -1154,10 +1148,10 @@ void crypto_stats_akcipher_decrypt(unsigned int src_len, int ret,
struct crypto_alg *alg)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
atomic64_inc(&alg->akcipher_err_cnt);
atomic64_inc(&alg->stats.akcipher.akcipher_err_cnt);
} else {
atomic64_inc(&alg->decrypt_cnt);
atomic64_add(src_len, &alg->decrypt_tlen);
atomic64_inc(&alg->stats.akcipher.decrypt_cnt);
atomic64_add(src_len, &alg->stats.akcipher.decrypt_tlen);
}
crypto_alg_put(alg);
}
Expand All @@ -1166,30 +1160,30 @@ EXPORT_SYMBOL_GPL(crypto_stats_akcipher_decrypt);
void crypto_stats_akcipher_sign(int ret, struct crypto_alg *alg)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY)
atomic64_inc(&alg->akcipher_err_cnt);
atomic64_inc(&alg->stats.akcipher.akcipher_err_cnt);
else
atomic64_inc(&alg->sign_cnt);
atomic64_inc(&alg->stats.akcipher.sign_cnt);
crypto_alg_put(alg);
}
EXPORT_SYMBOL_GPL(crypto_stats_akcipher_sign);

void crypto_stats_akcipher_verify(int ret, struct crypto_alg *alg)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY)
atomic64_inc(&alg->akcipher_err_cnt);
atomic64_inc(&alg->stats.akcipher.akcipher_err_cnt);
else
atomic64_inc(&alg->verify_cnt);
atomic64_inc(&alg->stats.akcipher.verify_cnt);
crypto_alg_put(alg);
}
EXPORT_SYMBOL_GPL(crypto_stats_akcipher_verify);

void crypto_stats_compress(unsigned int slen, int ret, struct crypto_alg *alg)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
atomic64_inc(&alg->compress_err_cnt);
atomic64_inc(&alg->stats.compress.compress_err_cnt);
} else {
atomic64_inc(&alg->compress_cnt);
atomic64_add(slen, &alg->compress_tlen);
atomic64_inc(&alg->stats.compress.compress_cnt);
atomic64_add(slen, &alg->stats.compress.compress_tlen);
}
crypto_alg_put(alg);
}
Expand All @@ -1198,10 +1192,10 @@ EXPORT_SYMBOL_GPL(crypto_stats_compress);
void crypto_stats_decompress(unsigned int slen, int ret, struct crypto_alg *alg)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
atomic64_inc(&alg->compress_err_cnt);
atomic64_inc(&alg->stats.compress.compress_err_cnt);
} else {
atomic64_inc(&alg->decompress_cnt);
atomic64_add(slen, &alg->decompress_tlen);
atomic64_inc(&alg->stats.compress.decompress_cnt);
atomic64_add(slen, &alg->stats.compress.decompress_tlen);
}
crypto_alg_put(alg);
}
Expand All @@ -1211,9 +1205,9 @@ void crypto_stats_ahash_update(unsigned int nbytes, int ret,
struct crypto_alg *alg)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY)
atomic64_inc(&alg->hash_err_cnt);
atomic64_inc(&alg->stats.hash.hash_err_cnt);
else
atomic64_add(nbytes, &alg->hash_tlen);
atomic64_add(nbytes, &alg->stats.hash.hash_tlen);
crypto_alg_put(alg);
}
EXPORT_SYMBOL_GPL(crypto_stats_ahash_update);
Expand All @@ -1222,10 +1216,10 @@ void crypto_stats_ahash_final(unsigned int nbytes, int ret,
struct crypto_alg *alg)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
atomic64_inc(&alg->hash_err_cnt);
atomic64_inc(&alg->stats.hash.hash_err_cnt);
} else {
atomic64_inc(&alg->hash_cnt);
atomic64_add(nbytes, &alg->hash_tlen);
atomic64_inc(&alg->stats.hash.hash_cnt);
atomic64_add(nbytes, &alg->stats.hash.hash_tlen);
}
crypto_alg_put(alg);
}
Expand All @@ -1234,39 +1228,39 @@ EXPORT_SYMBOL_GPL(crypto_stats_ahash_final);
void crypto_stats_kpp_set_secret(struct crypto_alg *alg, int ret)
{
if (ret)
atomic64_inc(&alg->kpp_err_cnt);
atomic64_inc(&alg->stats.kpp.kpp_err_cnt);
else
atomic64_inc(&alg->setsecret_cnt);
atomic64_inc(&alg->stats.kpp.setsecret_cnt);
crypto_alg_put(alg);
}
EXPORT_SYMBOL_GPL(crypto_stats_kpp_set_secret);

void crypto_stats_kpp_generate_public_key(struct crypto_alg *alg, int ret)
{
if (ret)
atomic64_inc(&alg->kpp_err_cnt);
atomic64_inc(&alg->stats.kpp.kpp_err_cnt);
else
atomic64_inc(&alg->generate_public_key_cnt);
atomic64_inc(&alg->stats.kpp.generate_public_key_cnt);
crypto_alg_put(alg);
}
EXPORT_SYMBOL_GPL(crypto_stats_kpp_generate_public_key);

void crypto_stats_kpp_compute_shared_secret(struct crypto_alg *alg, int ret)
{
if (ret)
atomic64_inc(&alg->kpp_err_cnt);
atomic64_inc(&alg->stats.kpp.kpp_err_cnt);
else
atomic64_inc(&alg->compute_shared_secret_cnt);
atomic64_inc(&alg->stats.kpp.compute_shared_secret_cnt);
crypto_alg_put(alg);
}
EXPORT_SYMBOL_GPL(crypto_stats_kpp_compute_shared_secret);

void crypto_stats_rng_seed(struct crypto_alg *alg, int ret)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY)
atomic64_inc(&alg->rng_err_cnt);
atomic64_inc(&alg->stats.rng.rng_err_cnt);
else
atomic64_inc(&alg->seed_cnt);
atomic64_inc(&alg->stats.rng.seed_cnt);
crypto_alg_put(alg);
}
EXPORT_SYMBOL_GPL(crypto_stats_rng_seed);
Expand All @@ -1275,10 +1269,10 @@ void crypto_stats_rng_generate(struct crypto_alg *alg, unsigned int dlen,
int ret)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
atomic64_inc(&alg->rng_err_cnt);
atomic64_inc(&alg->stats.rng.rng_err_cnt);
} else {
atomic64_inc(&alg->generate_cnt);
atomic64_add(dlen, &alg->generate_tlen);
atomic64_inc(&alg->stats.rng.generate_cnt);
atomic64_add(dlen, &alg->stats.rng.generate_tlen);
}
crypto_alg_put(alg);
}
Expand All @@ -1288,10 +1282,10 @@ void crypto_stats_skcipher_encrypt(unsigned int cryptlen, int ret,
struct crypto_alg *alg)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
atomic64_inc(&alg->cipher_err_cnt);
atomic64_inc(&alg->stats.cipher.cipher_err_cnt);
} else {
atomic64_inc(&alg->encrypt_cnt);
atomic64_add(cryptlen, &alg->encrypt_tlen);
atomic64_inc(&alg->stats.cipher.encrypt_cnt);
atomic64_add(cryptlen, &alg->stats.cipher.encrypt_tlen);
}
crypto_alg_put(alg);
}
Expand All @@ -1301,10 +1295,10 @@ void crypto_stats_skcipher_decrypt(unsigned int cryptlen, int ret,
struct crypto_alg *alg)
{
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
atomic64_inc(&alg->cipher_err_cnt);
atomic64_inc(&alg->stats.cipher.cipher_err_cnt);
} else {
atomic64_inc(&alg->decrypt_cnt);
atomic64_add(cryptlen, &alg->decrypt_tlen);
atomic64_inc(&alg->stats.cipher.decrypt_cnt);
atomic64_add(cryptlen, &alg->stats.cipher.decrypt_tlen);
}
crypto_alg_put(alg);
}
Expand Down
Loading

0 comments on commit 17c18f9

Please sign in to comment.