staging: lustre: libcfs: allocate memory in cfs_crypto_performance_test()
Move memory allocation from cfs_crypto_test_hashes() into the function cfs_crypto_performance_test(). Signed-off-by: Andreas Dilger <andreas.dilger@intel.com> Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5053 Reviewed-on: http://review.whamcloud.com/9990 Reviewed-by: Bob Glossman <bob.glossman@intel.com> Reviewed-by: James Simmons <uja.ornl@gmail.com> Reviewed-by: Oleg Drokin <oleg.drokin@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
e43c658c5a
commit
6ba3f37825
@@ -307,16 +307,27 @@ EXPORT_SYMBOL(cfs_crypto_hash_final);
|
|||||||
* \param[in] buf data buffer on which to compute the hash
|
* \param[in] buf data buffer on which to compute the hash
|
||||||
* \param[in] buf_len length of \buf on which to compute hash
|
* \param[in] buf_len length of \buf on which to compute hash
|
||||||
*/
|
*/
|
||||||
static void cfs_crypto_performance_test(enum cfs_crypto_hash_alg hash_alg,
|
static void cfs_crypto_performance_test(enum cfs_crypto_hash_alg hash_alg)
|
||||||
const unsigned char *buf,
|
|
||||||
unsigned int buf_len)
|
|
||||||
{
|
{
|
||||||
|
int buf_len = max(PAGE_SIZE, 1048576UL);
|
||||||
|
void *buf;
|
||||||
unsigned long start, end;
|
unsigned long start, end;
|
||||||
int bcount, err = 0;
|
int bcount, err = 0;
|
||||||
int sec = 1; /* do test only 1 sec */
|
int sec = 1; /* do test only 1 sec */
|
||||||
|
struct page *page;
|
||||||
unsigned char hash[CFS_CRYPTO_HASH_DIGESTSIZE_MAX];
|
unsigned char hash[CFS_CRYPTO_HASH_DIGESTSIZE_MAX];
|
||||||
unsigned int hash_len = sizeof(hash);
|
unsigned int hash_len = sizeof(hash);
|
||||||
|
|
||||||
|
page = alloc_page(GFP_KERNEL);
|
||||||
|
if (!page) {
|
||||||
|
err = -ENOMEM;
|
||||||
|
goto out_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = kmap(page);
|
||||||
|
memset(buf, 0xAD, PAGE_SIZE);
|
||||||
|
kunmap(page);
|
||||||
|
|
||||||
for (start = jiffies, end = start + sec * HZ, bcount = 0;
|
for (start = jiffies, end = start + sec * HZ, bcount = 0;
|
||||||
time_before(jiffies, end); bcount++) {
|
time_before(jiffies, end); bcount++) {
|
||||||
err = cfs_crypto_hash_digest(hash_alg, buf, buf_len, NULL, 0,
|
err = cfs_crypto_hash_digest(hash_alg, buf, buf_len, NULL, 0,
|
||||||
@@ -325,7 +336,8 @@ static void cfs_crypto_performance_test(enum cfs_crypto_hash_alg hash_alg,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
end = jiffies;
|
end = jiffies;
|
||||||
|
__free_page(page);
|
||||||
|
out_err:
|
||||||
if (err) {
|
if (err) {
|
||||||
cfs_crypto_hash_speeds[hash_alg] = -1;
|
cfs_crypto_hash_speeds[hash_alg] = -1;
|
||||||
CDEBUG(D_INFO, "Crypto hash algorithm %s, err = %d\n",
|
CDEBUG(D_INFO, "Crypto hash algorithm %s, err = %d\n",
|
||||||
@@ -381,25 +393,11 @@ EXPORT_SYMBOL(cfs_crypto_hash_speed);
|
|||||||
*/
|
*/
|
||||||
static int cfs_crypto_test_hashes(void)
|
static int cfs_crypto_test_hashes(void)
|
||||||
{
|
{
|
||||||
unsigned char i;
|
enum cfs_crypto_hash_alg hash_alg;
|
||||||
unsigned char *data;
|
|
||||||
unsigned int j;
|
|
||||||
/* Data block size for testing hash. Maximum
|
|
||||||
* kmalloc size for 2.6.18 kernel is 128K
|
|
||||||
*/
|
|
||||||
unsigned int data_len = 1 * 128 * 1024;
|
|
||||||
|
|
||||||
data = kmalloc(data_len, 0);
|
for (hash_alg = 0; hash_alg < CFS_HASH_ALG_MAX; hash_alg++)
|
||||||
if (!data)
|
cfs_crypto_performance_test(hash_alg);
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
for (j = 0; j < data_len; j++)
|
|
||||||
data[j] = j & 0xff;
|
|
||||||
|
|
||||||
for (i = 0; i < CFS_HASH_ALG_MAX; i++)
|
|
||||||
cfs_crypto_performance_test(i, data, data_len);
|
|
||||||
|
|
||||||
kfree(data);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user