From f1835dc7f574ae012e464393ff906025a918c46b Mon Sep 17 00:00:00 2001 From: jsteube Date: Wed, 14 Sep 2016 20:22:38 +0200 Subject: [PATCH] Move more functions to thread.c --- include/thread.h | 7 ++++ src/hashcat.c | 104 ---------------------------------------------- src/mpsp.c | 2 +- src/restore.c | 2 +- src/rp_cpu.c | 2 +- src/status.c | 2 +- src/thread.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 116 insertions(+), 108 deletions(-) diff --git a/include/thread.h b/include/thread.h index 59e944314..f1fc25dd5 100644 --- a/include/thread.h +++ b/include/thread.h @@ -65,4 +65,11 @@ void hc_signal (void (callback) (int)); void myabort (); void myquit (); +void SuspendThreads (); +void ResumeThreads (); + +void bypass (); + +uint get_work (hc_device_param_t *device_param, const u64 max); + #endif // _THREAD_H diff --git a/src/hashcat.c b/src/hashcat.c index 8188cee25..06938128a 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -746,110 +746,6 @@ static void *thread_outfile_remove (void *p) return (p); } -static void set_kernel_power_final (const u64 kernel_power_final) -{ - if (data.quiet == 0) - { - clear_prompt (); - - //log_info (""); - - log_info ("INFO: approaching final keyspace, workload adjusted"); - log_info (""); - - send_prompt (); - } - - data.kernel_power_final = kernel_power_final; -} - -static u32 get_power (hc_device_param_t *device_param) -{ - const u64 kernel_power_final = data.kernel_power_final; - - if (kernel_power_final) - { - const double device_factor = (double) device_param->hardware_power / data.hardware_power_all; - - const u64 words_left_device = (u64) CEIL (kernel_power_final * device_factor); - - // work should be at least the hardware power available without any accelerator - - const u64 work = MAX (words_left_device, device_param->hardware_power); - - return work; - } - - return device_param->kernel_power; -} - -static uint get_work (hc_device_param_t *device_param, const u64 max) -{ - hc_thread_mutex_lock (mux_dispatcher); - - const u64 words_cur = data.words_cur; - const u64 words_base = (data.limit == 0) ? data.words_base : MIN (data.limit, data.words_base); - - device_param->words_off = words_cur; - - const u64 kernel_power_all = data.kernel_power_all; - - const u64 words_left = words_base - words_cur; - - if (words_left < kernel_power_all) - { - if (data.kernel_power_final == 0) - { - set_kernel_power_final (words_left); - } - } - - const u32 kernel_power = get_power (device_param); - - uint work = MIN (words_left, kernel_power); - - work = MIN (work, max); - - data.words_cur += work; - - hc_thread_mutex_unlock (mux_dispatcher); - - return work; -} - -static void SuspendThreads () -{ - if (data.devices_status != STATUS_RUNNING) return; - - hc_timer_set (&data.timer_paused); - - data.devices_status = STATUS_PAUSED; - - log_info ("Paused"); -} - -static void ResumeThreads () -{ - if (data.devices_status != STATUS_PAUSED) return; - - double ms_paused; - - hc_timer_get (data.timer_paused, ms_paused); - - data.ms_paused += ms_paused; - - data.devices_status = STATUS_RUNNING; - - log_info ("Resumed"); -} - -static void bypass () -{ - data.devices_status = STATUS_BYPASS; - - log_info ("Next dictionary / mask in queue selected, bypassing current one"); -} - static void *thread_autotune (void *p) { hc_device_param_t *device_param = (hc_device_param_t *) p; diff --git a/src/mpsp.c b/src/mpsp.c index 2ae34ab9a..cb36d8bcf 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -21,11 +21,11 @@ #include "ext_nvml.h" #include "ext_xnvctrl.h" #include "filehandling.h" +#include "opencl.h" #include "thread.h" #include "hwmon.h" #include "mpsp.h" #include "rp_cpu.h" -#include "opencl.h" #include "restore.h" #include "outfile.h" #include "potfile.h" diff --git a/src/restore.c b/src/restore.c index 4a8809476..5392d5610 100644 --- a/src/restore.c +++ b/src/restore.c @@ -15,11 +15,11 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" +#include "opencl.h" #include "thread.h" #include "rp_cpu.h" #include "hwmon.h" #include "mpsp.h" -#include "opencl.h" #include "restore.h" #include "outfile.h" #include "potfile.h" diff --git a/src/rp_cpu.c b/src/rp_cpu.c index 84c5929a2..92d952793 100644 --- a/src/rp_cpu.c +++ b/src/rp_cpu.c @@ -20,13 +20,13 @@ #include "ext_nvml.h" #include "ext_xnvctrl.h" #include "convert.h" +#include "opencl.h" #include "thread.h" #include "rp_cpu.h" #include "terminal.h" #include "hwmon.h" #include "mpsp.h" #include "rp_cpu.h" -#include "opencl.h" #include "restore.h" #include "outfile.h" #include "potfile.h" diff --git a/src/status.c b/src/status.c index e5a3c0fd2..6781938da 100644 --- a/src/status.c +++ b/src/status.c @@ -15,12 +15,12 @@ #include "ext_nvapi.h" #include "ext_nvml.h" #include "ext_xnvctrl.h" +#include "opencl.h" #include "thread.h" #include "rp_cpu.h" #include "terminal.h" #include "hwmon.h" #include "mpsp.h" -#include "opencl.h" #include "restore.h" #include "outfile.h" #include "potfile.h" diff --git a/src/thread.c b/src/thread.c index 56052ee43..56f3760e2 100644 --- a/src/thread.c +++ b/src/thread.c @@ -8,6 +8,7 @@ #include "types.h" #include "interface.h" #include "timer.h" +#include "logging.h" #include "ext_OpenCL.h" #include "ext_ADL.h" #include "ext_nvapi.h" @@ -144,3 +145,107 @@ void myquit () { data.devices_status = STATUS_QUIT; } + +void SuspendThreads () +{ + if (data.devices_status != STATUS_RUNNING) return; + + hc_timer_set (&data.timer_paused); + + data.devices_status = STATUS_PAUSED; + + log_info ("Paused"); +} + +void ResumeThreads () +{ + if (data.devices_status != STATUS_PAUSED) return; + + double ms_paused; + + hc_timer_get (data.timer_paused, ms_paused); + + data.ms_paused += ms_paused; + + data.devices_status = STATUS_RUNNING; + + log_info ("Resumed"); +} + +void bypass () +{ + data.devices_status = STATUS_BYPASS; + + log_info ("Next dictionary / mask in queue selected, bypassing current one"); +} + +static void set_kernel_power_final (const u64 kernel_power_final) +{ + if (data.quiet == 0) + { + clear_prompt (); + + //log_info (""); + + log_info ("INFO: approaching final keyspace, workload adjusted"); + log_info (""); + + send_prompt (); + } + + data.kernel_power_final = kernel_power_final; +} + +static u32 get_power (hc_device_param_t *device_param) +{ + const u64 kernel_power_final = data.kernel_power_final; + + if (kernel_power_final) + { + const double device_factor = (double) device_param->hardware_power / data.hardware_power_all; + + const u64 words_left_device = (u64) CEIL (kernel_power_final * device_factor); + + // work should be at least the hardware power available without any accelerator + + const u64 work = MAX (words_left_device, device_param->hardware_power); + + return work; + } + + return device_param->kernel_power; +} + +uint get_work (hc_device_param_t *device_param, const u64 max) +{ + hc_thread_mutex_lock (mux_dispatcher); + + const u64 words_cur = data.words_cur; + const u64 words_base = (data.limit == 0) ? data.words_base : MIN (data.limit, data.words_base); + + device_param->words_off = words_cur; + + const u64 kernel_power_all = data.kernel_power_all; + + const u64 words_left = words_base - words_cur; + + if (words_left < kernel_power_all) + { + if (data.kernel_power_final == 0) + { + set_kernel_power_final (words_left); + } + } + + const u32 kernel_power = get_power (device_param); + + uint work = MIN (words_left, kernel_power); + + work = MIN (work, max); + + data.words_cur += work; + + hc_thread_mutex_unlock (mux_dispatcher); + + return work; +}