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:
Milan Broz
2022-08-16 19:48:31 +02:00
parent 21d87a246e
commit b9bf657449
3 changed files with 33 additions and 1 deletions

View File

@@ -179,6 +179,7 @@ int crypt_get_debug_level(void);
int crypt_memlock_inc(struct crypt_device *ctx); int crypt_memlock_inc(struct crypt_device *ctx);
int crypt_memlock_dec(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); int crypt_metadata_locking_enabled(void);

View File

@@ -59,6 +59,35 @@ uint64_t crypt_getphysmemory_kb(void)
return phys_memory_kb; 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 */ /* MEMLOCK */
#define DEFAULT_PROCESS_PRIORITY -18 #define DEFAULT_PROCESS_PRIORITY -18

View File

@@ -98,7 +98,7 @@ int crypt_benchmark_pbkdf(struct crypt_device *cd,
int (*progress)(uint32_t time_ms, void *usrptr), int (*progress)(uint32_t time_ms, void *usrptr),
void *usrptr) void *usrptr)
{ {
int r; int r, priority;
const char *kdf_opt; const char *kdf_opt;
if (!pbkdf || (!password && password_size)) 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); 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, r = crypt_pbkdf_perf(pbkdf->type, pbkdf->hash, password, password_size,
salt, salt_size, volume_key_size, pbkdf->time_ms, salt, salt_size, volume_key_size, pbkdf->time_ms,
pbkdf->max_memory_kb, pbkdf->parallel_threads, pbkdf->max_memory_kb, pbkdf->parallel_threads,
&pbkdf->iterations, &pbkdf->max_memory_kb, progress, usrptr); &pbkdf->iterations, &pbkdf->max_memory_kb, progress, usrptr);
crypt_process_priority(cd, &priority, false);
if (!r) if (!r)
log_dbg(cd, "Benchmark returns %s(%s) %u iterations, %u memory, %u threads (for %zu-bits key).", log_dbg(cd, "Benchmark returns %s(%s) %u iterations, %u memory, %u threads (for %zu-bits key).",