Send a notice to user in case the drivers temperature threshold for slowdown is reach...
[hashcat.git] / src / hashcat.c
index 7d0af78..9a60017 100644 (file)
@@ -1549,10 +1549,14 @@ void status_display ()
       {
         char utilization[HM_STR_BUF_SIZE] = { 0 };
         char temperature[HM_STR_BUF_SIZE] = { 0 };
-        char fanspeed[HM_STR_BUF_SIZE] = { 0 };
+        char fanspeed[HM_STR_BUF_SIZE]    = { 0 };
+        char corespeed[HM_STR_BUF_SIZE]   = { 0 };
+        char memoryspeed[HM_STR_BUF_SIZE] = { 0 };
 
-        hm_device_val_to_str ((char *) utilization, HM_STR_BUF_SIZE, "%", hm_get_utilization_with_device_id (device_id));
-        hm_device_val_to_str ((char *) temperature, HM_STR_BUF_SIZE, "c", hm_get_temperature_with_device_id (device_id));
+        hm_device_val_to_str ((char *) utilization, HM_STR_BUF_SIZE,   "%", hm_get_utilization_with_device_id (device_id));
+        hm_device_val_to_str ((char *) temperature, HM_STR_BUF_SIZE,   "c", hm_get_temperature_with_device_id (device_id));
+        hm_device_val_to_str ((char *) corespeed,   HM_STR_BUF_SIZE, "Mhz", hm_get_corespeed_with_device_id   (device_id));
+        hm_device_val_to_str ((char *) memoryspeed, HM_STR_BUF_SIZE, "Mhz", hm_get_memoryspeed_with_device_id (device_id));
 
         if (device_param->device_vendor_id == VENDOR_ID_AMD)
         {
@@ -1563,7 +1567,7 @@ void status_display ()
           hm_device_val_to_str ((char *) fanspeed, HM_STR_BUF_SIZE, "%", hm_get_fanspeed_with_device_id (device_id));
         }
 
-        log_info ("HWMon.GPU.#%d...: %s Util, %s Temp, %s Fan", device_id + 1, utilization, temperature, fanspeed);
+        log_info ("HWMon.GPU.#%d...: %s Util, %s Temp, %s Fan, %s Core, %s Mem", device_id + 1, utilization, temperature, fanspeed, corespeed, memoryspeed);
       }
       else
       {
@@ -2100,6 +2104,7 @@ static void check_hash (hc_device_param_t *device_param, plain_t *plain)
 
       out_fp = stdout;
     }
+
     lock_file (out_fp);
   }
   else
@@ -3777,6 +3782,8 @@ static void *thread_monitor (void *p)
   #ifdef HAVE_HWMON
   uint hwmon_check   = 0;
 
+  int slowdown_warnings = 0;
+
   // these variables are mainly used for fan control (AMD only)
 
   int *fan_speed_chgd = (int *) mycalloc (data.devices_cnt, sizeof (int));
@@ -3842,6 +3849,51 @@ static void *thread_monitor (void *p)
     if (data.devices_status != STATUS_RUNNING) continue;
 
     #ifdef HAVE_HWMON
+
+    if (1)
+    {
+      hc_thread_mutex_lock (mux_adl);
+
+      for (uint device_id = 0; device_id < data.devices_cnt; device_id++)
+      {
+        hc_device_param_t *device_param = &data.devices_param[device_id];
+
+        if (device_param->skipped) continue;
+
+        if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) continue;
+
+        const int temperature = hm_get_temperature_with_device_id (device_id);
+
+        const int threshold = data.hm_device[device_id].gpu_temp_threshold_slowdown;
+
+        if (temperature >= threshold)
+        {
+          if (slowdown_warnings < 3)
+          {
+            if (data.quiet == 0) clear_prompt ();
+
+            log_info ("WARNING: Drivers temperature threshold (%dc) hit on GPU #%d, expect performance to drop...", threshold, device_id + 1);
+
+            if (slowdown_warnings == 2)
+            {
+              log_info ("");
+            }
+
+            if (data.quiet == 0) fprintf (stdout, "%s", PROMPT);
+            if (data.quiet == 0) fflush (stdout);
+
+            slowdown_warnings++;
+          }
+        }
+        else
+        {
+          slowdown_warnings = 0;
+        }
+      }
+
+      hc_thread_mutex_unlock (mux_adl);
+    }
+
     if (hwmon_check == 1)
     {
       hc_thread_mutex_lock (mux_adl);
@@ -5333,7 +5385,7 @@ static uint generate_bitmaps (const uint digests_cnt, const uint dgst_size, cons
  */
 
 #ifdef _WIN
-void SetConsoleWindowSize (const int x, const int y)
+void SetConsoleWindowSize (const int x)
 {
   HANDLE h = GetStdHandle (STD_OUTPUT_HANDLE);
 
@@ -5345,18 +5397,13 @@ void SetConsoleWindowSize (const int x, const int y)
 
   SMALL_RECT *sr = &bufferInfo.srWindow;
 
-  sr->Left   = 0;
-  sr->Top    = 0;
-  sr->Right  = MAX (sr->Right,  x - 1);
-  sr->Bottom = MAX (sr->Bottom, y - 1);
+  sr->Right = MAX (sr->Right, x - 1);
 
   COORD co;
 
   co.X = sr->Right  + 1;
   co.Y = sr->Bottom + 1;
 
-  co.Y = MAX (co.Y, 1337);
-
   if (!SetConsoleScreenBufferSize (h, co)) return;
 
   if (!SetConsoleWindowInfo (h, TRUE, sr)) return;
@@ -5366,7 +5413,7 @@ void SetConsoleWindowSize (const int x, const int y)
 int main (int argc, char **argv)
 {
   #ifdef _WIN
-  SetConsoleWindowSize (132, 44);
+  SetConsoleWindowSize (132);
   #endif
 
   /**
@@ -6884,6 +6931,12 @@ int main (int argc, char **argv)
     weak_hash_threshold   = 0;
     gpu_temp_disable      = 1;
 
+    #ifdef HAVE_HWMON
+    #ifdef HAVE_ADL
+    powertune_enable      = 1;
+    #endif
+    #endif
+
     data.status_timer     = status_timer;
     data.restore_timer    = restore_timer;
     data.restore_disable  = restore_disable;
@@ -13735,12 +13788,11 @@ int main (int argc, char **argv)
           {
             if (device_param->skipped == 0)
             {
-              log_info ("Device #%u: %s, %lu/%lu MB allocatable, %dMhz, %uMCU",
+              log_info ("Device #%u: %s, %lu/%lu MB allocatable, %uMCU",
                         device_id + 1,
                         device_name,
                         (unsigned int) (device_maxmem_alloc / 1024 / 1024),
                         (unsigned int) (device_global_mem   / 1024 / 1024),
-                        (unsigned int) (device_maxclock_frequency),
                         (unsigned int)  device_processors);
             }
             else
@@ -13941,11 +13993,11 @@ int main (int argc, char **argv)
 
     #ifdef HAVE_HWMON
     #if defined(HAVE_NVML) || defined(HAVE_NVAPI)
-    hm_attrs_t hm_adapters_nv[DEVICES_MAX]  = { { { 0 }, 0, 0 } };
+    hm_attrs_t hm_adapters_nv[DEVICES_MAX]  = { { { 0 }, 0, 0, 0, 0 } };
     #endif
 
     #ifdef HAVE_ADL
-    hm_attrs_t hm_adapters_amd[DEVICES_MAX] = { { { 0 }, 0, 0 } };
+    hm_attrs_t hm_adapters_amd[DEVICES_MAX] = { { { 0 }, 0, 0, 0, 0 } };
     #endif
 
     if (gpu_temp_disable == 0)
@@ -14214,13 +14266,13 @@ int main (int argc, char **argv)
       }
     }
 
-   /*
-    * Temporary fix:
-    * with AMD r9 295x cards it seems that we need to set the powertune value just AFTER the ocl init stuff
-    * otherwise after hc_clCreateContext () etc, powertune value was set back to "normal" and cards unfortunately
-    * were not working @ full speed (setting hm_ADL_Overdrive_PowerControl_Set () here seems to fix the problem)
-    * Driver / ADL bug?
-    */
+    /**
+     * Temporary fix:
+     * with AMD r9 295x cards it seems that we need to set the powertune value just AFTER the ocl init stuff
+     * otherwise after hc_clCreateContext () etc, powertune value was set back to "normal" and cards unfortunately
+     * were not working @ full speed (setting hm_ADL_Overdrive_PowerControl_Set () here seems to fix the problem)
+     * Driver / ADL bug?
+     */
 
     #ifdef HAVE_ADL
     if (powertune_enable == 1)
@@ -15560,6 +15612,19 @@ int main (int argc, char **argv)
         run_kernel_bzero (device_param, device_param->d_markov_css_buf, size_markov_css);
       }
 
+      /**
+       * Store thermal target temperature so we can send a notice to user
+       */
+
+      #if defined(HAVE_HWMON)
+      if (gpu_temp_disable == 0)
+      {
+        const int gpu_temp_threshold_slowdown = hm_get_threshold_slowdown_with_device_id (device_id);
+
+        data.hm_device[device_id].gpu_temp_threshold_slowdown = (gpu_temp_threshold_slowdown == -1) ? 100000 : gpu_temp_threshold_slowdown;
+      }
+      #endif
+
       /**
        * Store initial fanspeed if gpu_temp_retain is enabled
        */