mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Set process priority only for PBKDF benchmark.
Do not increase priority for the whole run, only increase it when we calculate PBKDF paramaters.
This commit is contained in:
@@ -179,6 +179,7 @@ int crypt_get_debug_level(void);
|
||||
|
||||
int crypt_memlock_inc(struct crypt_device *ctx);
|
||||
int crypt_memlock_dec(struct crypt_device *ctx);
|
||||
void crypt_process_priority(struct crypt_device *cd, int *priority, bool raise);
|
||||
|
||||
int crypt_metadata_locking_enabled(void);
|
||||
|
||||
|
||||
29
lib/utils.c
29
lib/utils.c
@@ -59,6 +59,35 @@ uint64_t crypt_getphysmemory_kb(void)
|
||||
return phys_memory_kb;
|
||||
}
|
||||
|
||||
void crypt_process_priority(struct crypt_device *cd, int *priority, bool raise)
|
||||
{
|
||||
int _priority, new_priority;
|
||||
|
||||
if (raise) {
|
||||
_priority = getpriority(PRIO_PROCESS, 0);
|
||||
if (_priority < 0)
|
||||
_priority = 0;
|
||||
if (priority)
|
||||
*priority = _priority;
|
||||
|
||||
/*
|
||||
* Do not bother checking CAP_SYS_NICE as device activation
|
||||
* requires CAP_SYSADMIN later anyway.
|
||||
*/
|
||||
if (getuid() || geteuid())
|
||||
new_priority = 0;
|
||||
else
|
||||
new_priority = -18;
|
||||
|
||||
if (setpriority(PRIO_PROCESS, 0, new_priority))
|
||||
log_dbg(cd, "Cannot raise process priority.");
|
||||
} else {
|
||||
_priority = priority ? *priority : 0;
|
||||
if (setpriority(PRIO_PROCESS, 0, _priority))
|
||||
log_dbg(cd, "Cannot reset process priority.");
|
||||
}
|
||||
}
|
||||
|
||||
/* MEMLOCK */
|
||||
#define DEFAULT_PROCESS_PRIORITY -18
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ int crypt_benchmark_pbkdf(struct crypt_device *cd,
|
||||
int (*progress)(uint32_t time_ms, void *usrptr),
|
||||
void *usrptr)
|
||||
{
|
||||
int r;
|
||||
int r, priority;
|
||||
const char *kdf_opt;
|
||||
|
||||
if (!pbkdf || (!password && password_size))
|
||||
@@ -112,10 +112,12 @@ int crypt_benchmark_pbkdf(struct crypt_device *cd,
|
||||
|
||||
log_dbg(cd, "Running %s(%s) benchmark.", pbkdf->type, kdf_opt);
|
||||
|
||||
crypt_process_priority(cd, &priority, true);
|
||||
r = crypt_pbkdf_perf(pbkdf->type, pbkdf->hash, password, password_size,
|
||||
salt, salt_size, volume_key_size, pbkdf->time_ms,
|
||||
pbkdf->max_memory_kb, pbkdf->parallel_threads,
|
||||
&pbkdf->iterations, &pbkdf->max_memory_kb, progress, usrptr);
|
||||
crypt_process_priority(cd, &priority, false);
|
||||
|
||||
if (!r)
|
||||
log_dbg(cd, "Benchmark returns %s(%s) %u iterations, %u memory, %u threads (for %zu-bits key).",
|
||||
|
||||
Reference in New Issue
Block a user