Skip to content

Commit dfbbe98

Browse files
committed
Logging tweaks
Add a LOG_ONCE macro instead of reimplementing the "static int warned" everywhere. Mask mode: Avoid repeating a few log entries. Replace existing old-style log-once with that macro in a few other files. OpenCL: Prefix log entries with "OpenCL:" for clarity.
1 parent a0938a2 commit dfbbe98

File tree

6 files changed

+53
-45
lines changed

6 files changed

+53
-45
lines changed

src/gpu_common.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,10 @@ void gpu_check_temp(void)
473473

474474
if (temp > 125 || temp < 10) {
475475
if (!warned++) {
476-
log_event("Device %d probably invalid temp reading (%d%sC).",
476+
log_event("GPU device %d probably invalid temp reading (%d%sC).",
477477
dev + 1, temp, gpu_degree_sign);
478478
fprintf(stderr,
479-
"Device %d probably invalid temp reading (%d%sC).\n",
479+
"GPU device %d probably invalid temp reading (%d%sC).\n",
480480
dev + 1, temp, gpu_degree_sign);
481481
}
482482
return;
@@ -492,7 +492,7 @@ void gpu_check_temp(void)
492492
if (cool_gpu_down == 1)
493493
warnedTemperature++;
494494

495-
log_event("Device %d overheat (%d%sC, fan %s), %s%s.",
495+
log_event("GPU device %d overheat (%d%sC, fan %s), %s%s.",
496496
dev + 1, temp, gpu_degree_sign, s_fan,
497497
(cool_gpu_down > 0) ? "sleeping" : "aborting job",
498498
(hot_gpu) ? " again" : "");
@@ -532,10 +532,10 @@ void gpu_check_temp(void)
532532
if (fan >= 0)
533533
sprintf(s_fan, "%u%%", fan);
534534

535-
log_event("Device %d is waking up (%d%sC, fan %s).",
535+
log_event("GPU device %d is waking up (%d%sC, fan %s).",
536536
dev + 1, temp, gpu_degree_sign, s_fan);
537537
fprintf(stderr,
538-
"Device %d is waking up (%d%sC, fan %s).\n",
538+
"GPU device %d is waking up (%d%sC, fan %s).\n",
539539
dev + 1, temp, gpu_degree_sign, s_fan);
540540
}
541541
hot_gpu = 0;
@@ -557,15 +557,15 @@ void gpu_log_temp(void)
557557

558558
fan = temp = util = -1;
559559
dev_get_temp[dev](temp_dev_id[dev], &temp, &fan, &util, &cl, &ml);
560-
n = sprintf(s_gpu, "Device %d:", dev + 1);
560+
n = sprintf(s_gpu, "GPU device %d:", dev + 1);
561561
if (temp >= 0)
562562
n += sprintf(s_gpu + n, " temp: %u%sC", temp, gpu_degree_sign);
563563
if (util > 0)
564564
n += sprintf(s_gpu + n, " util: %u%%", util);
565565
if (fan >= 0)
566566
n += sprintf(s_gpu + n, " fan: %u%%", fan);
567567
if (temp >= 0 || util > 0 || fan > 0)
568-
log_event("- %s", s_gpu);
568+
log_event("%s", s_gpu);
569569
}
570570
#endif
571571
}

src/logger.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ extern int log_lock(int fd, int cmd, int type, const char *name,
5050
#endif /* #if defined(F_SETLK) && defined(F_SETLKW) && defined(F_UNLCK)
5151
&& defined(F_RDLCK) && defined(F_WRLCK) */
5252

53+
/*
54+
* Macro to only log something once per session.
55+
*/
56+
#define LOG_ONCE(...) \
57+
do { \
58+
static int warned; \
59+
if (!warned) { \
60+
log_event(__VA_ARGS__); \
61+
warned++; \
62+
} \
63+
} while (0)
64+
5365
/*
5466
* Initializes the logger (opens john.pot and a log file).
5567
*/

src/mask.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,12 +2436,12 @@ static void finalize_mask(int len)
24362436
format_cannot_reset = 0;
24372437
if (john_main_process) {
24382438
fprintf(stderr, "Note: Disabling internal mask due to stacked rules\n");
2439-
log_event("- Disabling internal mask due to stacked rules");
2439+
LOG_ONCE("- Disabling internal mask due to stacked rules");
24402440
}
24412441
}
24422442
#if defined(HAVE_OPENCL) || defined(HAVE_ZTEX)
24432443
else if ((mask_fmt->params.flags & FMT_MASK) && options.req_int_cand_target > 0) {
2444-
log_event("- Overriding format's target internal mask factor of %d with user requested %d",
2444+
LOG_ONCE("- Overriding format's target internal mask factor of %d with user requested %d",
24452445
mask_int_cand_target, options.req_int_cand_target);
24462446
mask_int_cand_target = options.req_int_cand_target;
24472447
}
@@ -2514,9 +2514,14 @@ static void finalize_mask(int len)
25142514
mask_tot_cand = cand * mask_int_cand.num_int_cand;
25152515

25162516
if ((john_main_process || !cfg_get_bool(SECTION_OPTIONS, SUBSECTION_MPI, "MPIAllGPUsSame", 0)) &&
2517-
mask_int_cand.num_int_cand > 1)
2518-
log_event("- Requested internal mask factor: %d, actual now %d",
2519-
mask_int_cand_target, mask_int_cand.num_int_cand);
2517+
mask_int_cand.num_int_cand > 1) {
2518+
static int old_factor = -1;
2519+
if (mask_int_cand.num_int_cand != old_factor) {
2520+
log_event("- Requested internal mask factor: %d, actual now %d",
2521+
mask_int_cand_target, mask_int_cand.num_int_cand);
2522+
old_factor = mask_int_cand.num_int_cand;
2523+
}
2524+
}
25202525
}
25212526

25222527
void mask_crk_init(struct db_main *db)
@@ -2633,6 +2638,7 @@ int do_mask_crack(const char *extern_key)
26332638
}
26342639

26352640
mask_cur_len = i;
2641+
log_event("- Mask length now %u", mask_cur_len);
26362642

26372643
if (format_cannot_reset)
26382644
save_restore(&cpu_mask_ctx, 0, RESTORE);

src/opencl_autotune.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static void autotune_run_extra(struct fmt_main *self, unsigned int rounds,
234234
uint32_t lws, gws, mpi_lws, mpi_gws;
235235

236236
if (john_main_process)
237-
log_event("- Enforcing same work sizes on all MPI nodes");
237+
log_event("OpenCL: Enforcing same work sizes on all MPI nodes");
238238
lws = local_work_size;
239239
gws = global_work_size;
240240
MPI_Allreduce(&lws, &mpi_lws, 1, MPI_UNSIGNED, MPI_MIN, MPI_COMM_WORLD);
@@ -276,7 +276,7 @@ static void autotune_run_extra(struct fmt_main *self, unsigned int rounds,
276276
create_clobj(global_work_size, self);
277277

278278
if (!self_test_running && (!homogenous || john_main_process))
279-
log_event("- OpenCL LWS: "Zu"%s, GWS: "Zu" %s("Zu" blocks)",
279+
log_event("OpenCL: LWS: "Zu"%s, GWS: "Zu" %s("Zu" blocks)",
280280
local_work_size,
281281
(need_best_lws && !needed_best_gws) ? " (auto-tuned)" : "",
282282
global_work_size,

src/opencl_common.c

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ static void load_opencl_environment()
423423
num_platforms = 0;
424424

425425
if (num_platforms < 1 && options.verbosity > VERB_LEGACY)
426-
fprintf(stderr, "%u: No OpenCL platforms were found: %s\n",
426+
fprintf(stderr, "%u: OpenCL: No platforms were found: %s\n",
427427
NODE, get_error_name(ret));
428428

429429
for (i = 0; i < num_platforms; i++) {
@@ -439,7 +439,7 @@ static void load_opencl_environment()
439439

440440
if (num_devices < 1 && options.verbosity > VERB_LEGACY)
441441
fprintf(stderr,
442-
"%u: No OpenCL devices were found on platform #%d: %s\n",
442+
"%u: OpenCL: No devices were found on platform #%d: %s\n",
443443
NODE, i, get_error_name(ret));
444444

445445
// Save platform and devices information
@@ -562,7 +562,7 @@ static int start_opencl_device(int sequential_id, int *err_type)
562562
&devices[sequential_id], NULL, NULL, &ret_code);
563563

564564
if (ret_code != CL_SUCCESS) {
565-
fprintf(stderr, "%u: Error creating context for device %d "
565+
fprintf(stderr, "%u: Error creating OpenCL context for device %d "
566566
"(%d:%d): %s\n",
567567
NODE, sequential_id + 1,
568568
get_platform_id(sequential_id),
@@ -575,7 +575,7 @@ static int start_opencl_device(int sequential_id, int *err_type)
575575
devices[sequential_id], 0, &ret_code);
576576

577577
if (ret_code != CL_SUCCESS) {
578-
fprintf(stderr, "%u: Error creating command queue for "
578+
fprintf(stderr, "%u: Error creating OpenCL command queue for "
579579
"device %d (%d:%d): %s\n", NODE,
580580
sequential_id + 1, get_platform_id(sequential_id),
581581
get_device_id(sequential_id), get_error_name(ret_code));
@@ -620,7 +620,7 @@ static void add_device_to_list(int sequential_id)
620620
if (options.fork)
621621
fprintf(stderr, "%u: ", options.node_min);
622622
#endif
623-
fprintf(stderr, "Device id %d not working correctly,"
623+
fprintf(stderr, "OpenCL device id %d not working correctly,"
624624
" skipping.\n", sequential_id + 1);
625625
return;
626626
}
@@ -1123,7 +1123,7 @@ static void print_device_info(int sequential_id)
11231123
"", "",
11241124
#endif
11251125
device_name, board_name);
1126-
log_event("Device %d: %s%s", sequential_id + 1, device_name, board_name);
1126+
log_event("OpenCL: Device %d: %s%s", sequential_id + 1, device_name, board_name);
11271127
}
11281128

11291129
static char *get_build_opts(int sequential_id, const char *opts)
@@ -1267,7 +1267,7 @@ void opencl_build(int sequential_id, const char *opts, int save, const char *fil
12671267
"clGetProgramBuildInfo II");
12681268

12691269
uint64_t end = john_get_nano();
1270-
log_event("- build time: %ss", ns2string(end - start));
1270+
log_event("OpenCL: Kernel build time: %ss", ns2string(end - start));
12711271

12721272
char *cleaned_log = build_log;
12731273
if (cfg_get_bool(SECTION_OPTIONS, SUBSECTION_OPENCL, "MuteBogusWarnings", 1) &&
@@ -1380,9 +1380,9 @@ cl_int opencl_build_from_binary(int sequential_id, cl_program *program, const ch
13801380
}
13811381
// Nvidia may return a single '\n' that we ignore
13821382
else if (options.verbosity >= LOG_VERB && strlen(build_log) > 1)
1383-
fprintf(stderr, "Binary Build log: %s\n", build_log);
1383+
fprintf(stderr, "Binary build log: %s\n", build_log);
13841384

1385-
log_event("- build time: %ss", ns2string(end - start));
1385+
log_event("OpenCL: Kernel build time: %ss", ns2string(end - start));
13861386
if (options.verbosity >= VERB_MAX)
13871387
fprintf(stderr, "Build time: %ss\n", ns2string(end - start));
13881388
MEM_FREE(build_log);
@@ -2185,7 +2185,7 @@ size_t opencl_read_source(const char *kernel_filename, char **kernel_source)
21852185
read_size = fread(*kernel_source, sizeof(char), source_size, fp);
21862186
if (read_size != source_size)
21872187
fprintf(stderr,
2188-
"Error reading source: expected "Zu", got "Zu" bytes (%s).\n",
2188+
"OpenCL error reading kernel source: expected "Zu", got "Zu" bytes (%s).\n",
21892189
source_size, read_size,
21902190
feof(fp) ? "EOF" : strerror(errno));
21912191
fclose(fp);
@@ -2285,38 +2285,38 @@ void opencl_build_kernel(const char *kernel_filename, int sequential_id, const c
22852285
*/
22862286
if (gpu_nvidia(device_info[sequential_id]) && !platform_apple(get_platform_id(sequential_id))) {
22872287
if (john_main_process || !cfg_get_bool(SECTION_OPTIONS, SUBSECTION_MPI, "MPIAllGPUsSame", 0))
2288-
log_event("- Kernel binary caching disabled for this platform/device");
2288+
LOG_ONCE("OpenCL: Kernel binary caching disabled for this platform/device");
22892289
use_cache = 0;
22902290
} else
22912291
#endif
22922292
if (getenv("DUMP_BINARY")) {
2293-
log_event("- DUMP_BINARY is set, ignoring cached kernel");
2293+
LOG_ONCE("OpenCL: DUMP_BINARY is set, ignoring cached kernel");
22942294
use_cache = 0;
22952295
} else {
22962296
use_cache = !stat(path_expand(bin_name), &bin_stat);
22972297

22982298
if (use_cache && !stat(path_expand(kernel_filename), &source_stat) &&
22992299
source_stat.st_mtime > bin_stat.st_mtime) {
23002300
use_cache = 0;
2301-
log_event("- cached kernel may be stale, ignoring");
2301+
log_event("OpenCL: Cached kernel may be stale, ignoring");
23022302
}
23032303
}
23042304

23052305
// Select the kernel to run.
23062306
if (use_cache) {
23072307
size_t program_size = opencl_read_source(bin_name, &kernel_source);
23082308

2309-
log_event("- Building kernel from cached binary");
2309+
log_event("OpenCL: Building kernel from cached binary");
23102310
ret_code = opencl_build_from_binary(sequential_id, &program[sequential_id], kernel_source, program_size);
23112311
if (ret_code != CL_SUCCESS)
2312-
log_event("- Build from cached binary failed");
2312+
log_event("OpenCL: Build from cached binary failed");
23132313
}
23142314

23152315
if (!use_cache || ret_code != CL_SUCCESS) {
2316-
log_event("- Building kernel from source and caching binary");
2316+
log_event("OpenCL: Building kernel from source and caching binary");
23172317
if (warn && options.verbosity > VERB_DEFAULT) {
23182318
fflush(stdout);
2319-
fprintf(stderr, "Building the kernel, this could take a while\n");
2319+
fprintf(stderr, "Building the OpenCL kernel, this could take a while\n");
23202320
}
23212321
opencl_read_source(kernel_filename, &kernel_source);
23222322
opencl_build(sequential_id, opts, 1, bin_name, &program[sequential_id], kernel_filename, kernel_source);
@@ -2374,14 +2374,9 @@ int opencl_prepare_dev(int sequential_id)
23742374
if (gpu_nvidia(device_info[sequential_id])) {
23752375
opencl_avoid_busy_wait[sequential_id] = cfg_get_bool(SECTION_OPTIONS, SUBSECTION_GPU,
23762376
"AvoidBusyWait", 1);
2377-
static int warned;
2378-
23792377
/* Remove next line once (nearly) all formats has got the macros */
23802378
if (!opencl_avoid_busy_wait[sequential_id])
2381-
if (!warned) {
2382-
warned = 1;
2383-
log_event("- Busy-wait reduction %sabled", opencl_avoid_busy_wait[sequential_id] ? "en" : "dis");
2384-
}
2379+
LOG_ONCE("OpenCL: Busy-wait reduction %sabled", opencl_avoid_busy_wait[sequential_id] ? "en" : "dis");
23852380
}
23862381
#endif
23872382

@@ -2900,8 +2895,7 @@ void opencl_list_devices(void)
29002895
ret = clGetPlatformIDs(MAX_PLATFORMS, platform_list, &num_platforms);
29012896

29022897
if (!num_platforms)
2903-
fprintf(stderr, "Error: No OpenCL-capable platforms were detected"
2904-
" by the installed OpenCL driver.\n");
2898+
fprintf(stderr, "Error: No platforms were detected by the installed OpenCL driver.\n");
29052899

29062900
if (ret != CL_SUCCESS && options.verbosity > VERB_LEGACY)
29072901
fprintf(stderr, "Throw clError: clGetPlatformIDs() = %s\n",
@@ -2940,8 +2934,7 @@ void opencl_list_devices(void)
29402934
printf(" Platform extensions: %s\n", dname);
29412935
}
29422936
}
2943-
fprintf(stderr, "Error: No OpenCL-capable devices were detected"
2944-
" by the installed OpenCL driver.\n\n");
2937+
fprintf(stderr, "Error: No devices were detected by the installed OpenCL driver.\n\n");
29452938
return;
29462939
}
29472940
/* Initialize OpenCL environment */

src/rpp.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,7 @@ static void rpp_process_rule(struct rpp_context *ctx)
134134
if (strlen(conv) == strlen8(input))
135135
strcpy(ctx->input->data, conv); /* Always shorter than original */
136136
else {
137-
static int warned;
138-
139-
if (!warned++)
140-
log_event("- Rule preprocessor: Rejected rule(s) not fitting current internal codepage");
137+
LOG_ONCE("- Rule preprocessor: Rejected rule(s) not fitting current internal codepage");
141138
input[1] = '-';
142139
}
143140
}

0 commit comments

Comments
 (0)