+static int test_cipher_jiffies(struct crypto_tfm *tfm, int enc, char *p,
+ int blen, int sec)
+{
+ struct scatterlist sg[8];
+ unsigned long start, end;
+ int bcount;
+ int ret;
+
+ sg[0].page = virt_to_page(p);
+ sg[0].offset = offset_in_page(p);
+ sg[0].length = blen;
+
+ for (start = jiffies, end = start + sec * HZ, bcount = 0;
+ time_before(jiffies, end); bcount++) {
+ if (enc)
+ ret = crypto_cipher_encrypt(tfm, sg, sg, blen);
+ else
+ ret = crypto_cipher_decrypt(tfm, sg, sg, blen);
+
+ if (ret)
+ return ret;
+ }
+
+ printk("%d operations in %d seconds (%ld bytes)\n",
+ bcount, sec, (long)bcount * blen);
+ return 0;
+}
+
+static int test_cipher_cycles(struct crypto_tfm *tfm, int enc, char *p,
+ int blen)
+{
+ struct scatterlist sg[8];
+ unsigned long cycles = 0;
+ int ret = 0;
+ int i;
+
+ sg[0].page = virt_to_page(p);
+ sg[0].offset = offset_in_page(p);
+ sg[0].length = blen;
+
+ local_bh_disable();
+ local_irq_disable();
+
+ /* Warm-up run. */
+ for (i = 0; i < 4; i++) {
+ if (enc)
+ ret = crypto_cipher_encrypt(tfm, sg, sg, blen);
+ else
+ ret = crypto_cipher_decrypt(tfm, sg, sg, blen);
+
+ if (ret)
+ goto out;
+ }
+
+ /* The real thing. */
+ for (i = 0; i < 8; i++) {
+ cycles_t start, end;
+
+ start = get_cycles();
+ if (enc)
+ ret = crypto_cipher_encrypt(tfm, sg, sg, blen);
+ else
+ ret = crypto_cipher_decrypt(tfm, sg, sg, blen);
+ end = get_cycles();
+
+ if (ret)
+ goto out;
+
+ cycles += end - start;
+ }
+
+out:
+ local_irq_enable();
+ local_bh_enable();
+
+ if (ret == 0)
+ printk("1 operation in %lu cycles (%d bytes)\n",
+ (cycles + 4) / 8, blen);
+
+ return ret;
+}
+