Skip to content

Commit 6bd7c54

Browse files
committed
introduce MT_TRACE to clean up SMP_DEBUG code
1 parent e60fb0f commit 6bd7c54

File tree

1 file changed

+23
-37
lines changed

1 file changed

+23
-37
lines changed

driver/others/blas_server_win32.c

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
#endif
4949
#endif
5050

51+
#ifdef SMP_DEBUG
52+
# define MT_TRACE(...) fprintf(stderr, __VA_ARGS__)
53+
#else
54+
# define MT_TRACE(...)
55+
#endif
56+
5157
/* This is a thread implementation for Win32 lazy implementation */
5258

5359
/* Thread server common information */
@@ -213,29 +219,24 @@ static DWORD WINAPI blas_thread_server(void *arg){
213219
/* Each server needs each buffer */
214220
buffer = blas_memory_alloc(2);
215221

216-
#ifdef SMP_DEBUG
217-
fprintf(STDERR, "Server[%2ld] Thread is started!\n", cpu);
218-
#endif
222+
MT_TRACE("Server[%2ld] Thread is started!\n", cpu);
219223

220224
while (1){
221225

222226
/* Waiting for Queue */
223227

224-
#ifdef SMP_DEBUG
225-
fprintf(STDERR, "Server[%2ld] Waiting for Queue.\n", cpu);
226-
#endif
228+
MT_TRACE("Server[%2ld] Waiting for Queue.\n", cpu);
229+
227230
// event raised when work is added to the queue
228231
WaitForSingleObject(kickoff_event, INFINITE);
229232

230233
if (cpu > thread_target - 2)
231234
{
232-
//printf("thread [%d] exiting.\n", cpu);
235+
//MT_TRACE("thread [%d] exiting.\n", cpu);
233236
break; // excess thread, so worker thread exits
234237
}
235238

236-
#ifdef SMP_DEBUG
237-
fprintf(STDERR, "Server[%2ld] Got it.\n", cpu);
238-
#endif
239+
MT_TRACE("Server[%2ld] Got it.\n", cpu);
239240

240241
#if 1
241242
EnterCriticalSection(&queue_lock);
@@ -270,10 +271,8 @@ static DWORD WINAPI blas_thread_server(void *arg){
270271
__asm__ __volatile__ ("fldcw %0" : : "m" (queue -> x87_mode));
271272
#endif
272273

273-
#ifdef SMP_DEBUG
274-
fprintf(STDERR, "Server[%2ld] Started. Mode = 0x%03x M = %3ld N=%3ld K=%3ld\n",
274+
MT_TRACE("Server[%2ld] Started. Mode = 0x%03x M = %3ld N=%3ld K=%3ld\n",
275275
cpu, queue->mode, queue-> args ->m, queue->args->n, queue->args->k);
276-
#endif
277276

278277
// fprintf(stderr, "queue start[%ld]!!!\n", cpu);
279278

@@ -342,19 +341,14 @@ static DWORD WINAPI blas_thread_server(void *arg){
342341
continue; //if queue == NULL
343342
}
344343

345-
#ifdef SMP_DEBUG
346-
fprintf(STDERR, "Server[%2ld] Finished!\n", cpu);
347-
#endif
344+
MT_TRACE("Server[%2ld] Finished!\n", cpu);
348345

349346
queue->finished = 1;
350-
351347
}
352348

353349
/* Shutdown procedure */
354350

355-
#ifdef SMP_DEBUG
356-
fprintf(STDERR, "Server[%2ld] Shutdown!\n", cpu);
357-
#endif
351+
MT_TRACE("Server[%2ld] Shutdown!\n", cpu);
358352

359353
blas_memory_free(buffer);
360354

@@ -369,10 +363,7 @@ int blas_thread_init(void){
369363

370364
LOCK_COMMAND(&server_lock);
371365

372-
#ifdef SMP_DEBUG
373-
fprintf(STDERR, "Initializing Thread(Num. threads = %d)\n",
374-
blas_cpu_number);
375-
#endif
366+
MT_TRACE("Initializing Thread(Num. threads = %d)\n", blas_cpu_number);
376367

377368
if (!blas_server_avail){
378369
// create the kickoff Event
@@ -383,7 +374,7 @@ int blas_thread_init(void){
383374
InitializeCriticalSection(&queue_lock);
384375

385376
for(i = 0; i < blas_cpu_number - 1; i++){
386-
//printf("thread_init: creating thread [%d]\n", i);
377+
//MT_TRACE("thread_init: creating thread [%d]\n", i);
387378

388379
blas_threads[i] = CreateThread(NULL, 0,
389380
blas_thread_server, (void *)i,
@@ -458,24 +449,19 @@ int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
458449

459450
int exec_blas_async_wait(BLASLONG num, blas_queue_t *queue){
460451

461-
#ifdef SMP_DEBUG
462-
fprintf(STDERR, "Synchronization Waiting.\n");
463-
#endif
452+
MT_TRACE("Synchronization Waiting.\n");
464453

465454
while (num){
466-
#ifdef SMP_DEBUG
467-
fprintf(STDERR, "Waiting Queue ..\n");
468-
#endif
455+
MT_TRACE("Waiting Queue ..\n");
469456
while (!queue->finished)
470457
YIELDING;
471458

472459
queue = queue->next;
473460
num--;
474461
}
475462

476-
#ifdef SMP_DEBUG
477-
fprintf(STDERR, "Completely Done.\n\n");
478-
#endif
463+
MT_TRACE("Completely Done.\n\n");
464+
479465
// if work was added to the queue after this batch we can't sleep the worker threads
480466
// by resetting the event
481467
EnterCriticalSection(&queue_lock);
@@ -577,11 +563,11 @@ void goto_set_num_threads(int num_threads)
577563
SetEvent(kickoff_event);
578564

579565
for (i = num_threads - 1; i < blas_num_threads - 1; i++) {
580-
//printf("set_num_threads: waiting on thread [%d] to quit.\n", i);
566+
//MT_TRACE("set_num_threads: waiting on thread [%d] to quit.\n", i);
581567

582568
WaitForSingleObject(blas_threads[i], INFINITE);
583569

584-
//printf("set_num_threads: thread [%d] has quit.\n", i);
570+
//MT_TRACE("set_num_threads: thread [%d] has quit.\n", i);
585571

586572
CloseHandle(blas_threads[i]);
587573
}
@@ -610,7 +596,7 @@ void goto_set_num_threads(int num_threads)
610596
}
611597

612598
for(i = (blas_num_threads > 0) ? blas_num_threads - 1 : 0; i < num_threads - 1; i++){
613-
//printf("set_num_threads: creating thread [%d]\n", i);
599+
//MT_TRACE("set_num_threads: creating thread [%d]\n", i);
614600

615601
blas_threads[i] = CreateThread(NULL, 0,
616602
blas_thread_server, (void *)i,

0 commit comments

Comments
 (0)