Ejemplo n.º 1
0
/**
 * Run the performance test for all hash algorithms.
 *
 * Run the cfs_crypto_performance_test() benchmark for some of the available
 * hash functions at module load time.  This can't be reliably done at runtime
 * since the CPUs may be under load from thousands of connecting clients when
 * the first client connects and the checksum speeds are needed.
 *
 * Since the setup cost and computation speed of various hash algorithms is
 * a function of the buffer size (and possibly internal contention of offload
 * engines), this speed only represents an estimate of the actual speed under
 * actual usage, but is reasonable for comparing available algorithms.
 *
 * The actual speeds are available via cfs_crypto_hash_speed() for later
 * comparison.
 *
 * \retval		0 on success
 * \retval		-ENOMEM if no memory is available for test buffer
 */
static int cfs_crypto_test_hashes(void)
{
	enum cfs_crypto_hash_alg hash_alg;

	for (hash_alg = 1; hash_alg < CFS_HASH_ALG_SPEED_MAX; hash_alg++)
		cfs_crypto_performance_test(hash_alg);

	return 0;
}
Ejemplo n.º 2
0
/**
 * hash speed in Mbytes per second for valid hash algorithm
 *
 * Return the performance of the specified \a hash_alg that was
 * computed using cfs_crypto_performance_test().  If the performance
 * has not yet been computed, do that when it is first requested.
 * That avoids computing the speed when it is not actually needed.
 * To avoid competing threads computing the checksum speed at the
 * same time, only compute a single checksum speed at one time.
 *
 * \param[in] hash_alg	hash algorithm id (CFS_HASH_ALG_*)
 *
 * \retval		positive speed of the hash function in MB/s
 * \retval		-ENOENT if \a hash_alg is unsupported
 * \retval		negative errno if \a hash_alg speed is unavailable
 */
int cfs_crypto_hash_speed(enum cfs_crypto_hash_alg hash_alg)
{
	if (hash_alg < CFS_HASH_ALG_MAX) {
		if (unlikely(cfs_crypto_hash_speeds[hash_alg] == 0)) {
			static DEFINE_MUTEX(crypto_hash_speed_mutex);

			mutex_lock(&crypto_hash_speed_mutex);
			if (cfs_crypto_hash_speeds[hash_alg] == 0)
				cfs_crypto_performance_test(hash_alg);
			mutex_unlock(&crypto_hash_speed_mutex);
		}
		return cfs_crypto_hash_speeds[hash_alg];
	}

	return -ENOENT;
}
Ejemplo n.º 3
0
/**
 * Do performance test for all hash algorithms.
 */
static int cfs_crypto_test_hashes(void)
{
	unsigned char	   i;
	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);
	if (data == NULL) {
		CERROR("Failed to allocate mem\n");
		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;
}