Skip to content

Commit

Permalink
[CRYPTO] tcrypt: Move sg_init_table out of timing loops
Browse files Browse the repository at this point in the history
This patch moves the sg_init_table out of the timing loops for hash
algorithms so that it doesn't impact on the speed test results.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Herbert Xu authored and David S. Miller committed Oct 27, 2007
1 parent ceaa79c commit a5a613a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions crypto/tcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,11 @@ static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
int bcount;
int ret;

sg_init_table(sg, 1);

for (start = jiffies, end = start + sec * HZ, bcount = 0;
time_before(jiffies, end); bcount++) {
sg_init_one(sg, p, blen);
sg_set_buf(sg, p, blen);
ret = crypto_hash_digest(desc, sg, blen, out);
if (ret)
return ret;
Expand All @@ -597,13 +599,15 @@ static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
if (plen == blen)
return test_hash_jiffies_digest(desc, p, blen, out, sec);

sg_init_table(sg, 1);

for (start = jiffies, end = start + sec * HZ, bcount = 0;
time_before(jiffies, end); bcount++) {
ret = crypto_hash_init(desc);
if (ret)
return ret;
for (pcount = 0; pcount < blen; pcount += plen) {
sg_init_one(sg, p + pcount, plen);
sg_set_buf(sg, p + pcount, plen);
ret = crypto_hash_update(desc, sg, plen);
if (ret)
return ret;
Expand All @@ -628,12 +632,14 @@ static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
int i;
int ret;

sg_init_table(sg, 1);

local_bh_disable();
local_irq_disable();

/* Warm-up run. */
for (i = 0; i < 4; i++) {
sg_init_one(sg, p, blen);
sg_set_buf(sg, p, blen);
ret = crypto_hash_digest(desc, sg, blen, out);
if (ret)
goto out;
Expand All @@ -645,7 +651,7 @@ static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,

start = get_cycles();

sg_init_one(sg, p, blen);
sg_set_buf(sg, p, blen);
ret = crypto_hash_digest(desc, sg, blen, out);
if (ret)
goto out;
Expand Down Expand Up @@ -679,6 +685,8 @@ static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
if (plen == blen)
return test_hash_cycles_digest(desc, p, blen, out);

sg_init_table(sg, 1);

local_bh_disable();
local_irq_disable();

Expand All @@ -688,7 +696,7 @@ static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
if (ret)
goto out;
for (pcount = 0; pcount < blen; pcount += plen) {
sg_init_one(sg, p + pcount, plen);
sg_set_buf(sg, p + pcount, plen);
ret = crypto_hash_update(desc, sg, plen);
if (ret)
goto out;
Expand All @@ -708,7 +716,7 @@ static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
if (ret)
goto out;
for (pcount = 0; pcount < blen; pcount += plen) {
sg_init_one(sg, p + pcount, plen);
sg_set_buf(sg, p + pcount, plen);
ret = crypto_hash_update(desc, sg, plen);
if (ret)
goto out;
Expand Down

0 comments on commit a5a613a

Please sign in to comment.