dbexec.c revision 1.1.1.11 1 /*******************************************************************************
2 *
3 * Module Name: dbexec - debugger control method execution
4 *
5 ******************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2017, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acdebug.h"
47 #include "acnamesp.h"
48
49
50 #define _COMPONENT ACPI_CA_DEBUGGER
51 ACPI_MODULE_NAME ("dbexec")
52
53
54 static ACPI_DB_METHOD_INFO AcpiGbl_DbMethodInfo;
55
56 /* Local prototypes */
57
58 static ACPI_STATUS
59 AcpiDbExecuteMethod (
60 ACPI_DB_METHOD_INFO *Info,
61 ACPI_BUFFER *ReturnObj);
62
63 static ACPI_STATUS
64 AcpiDbExecuteSetup (
65 ACPI_DB_METHOD_INFO *Info);
66
67 static UINT32
68 AcpiDbGetOutstandingAllocations (
69 void);
70
71 static void ACPI_SYSTEM_XFACE
72 AcpiDbMethodThread (
73 void *Context);
74
75 static ACPI_STATUS
76 AcpiDbExecutionWalk (
77 ACPI_HANDLE ObjHandle,
78 UINT32 NestingLevel,
79 void *Context,
80 void **ReturnValue);
81
82
83 /*******************************************************************************
84 *
85 * FUNCTION: AcpiDbDeleteObjects
86 *
87 * PARAMETERS: Count - Count of objects in the list
88 * Objects - Array of ACPI_OBJECTs to be deleted
89 *
90 * RETURN: None
91 *
92 * DESCRIPTION: Delete a list of ACPI_OBJECTS. Handles packages and nested
93 * packages via recursion.
94 *
95 ******************************************************************************/
96
97 void
98 AcpiDbDeleteObjects (
99 UINT32 Count,
100 ACPI_OBJECT *Objects)
101 {
102 UINT32 i;
103
104
105 for (i = 0; i < Count; i++)
106 {
107 switch (Objects[i].Type)
108 {
109 case ACPI_TYPE_BUFFER:
110
111 ACPI_FREE (Objects[i].Buffer.Pointer);
112 break;
113
114 case ACPI_TYPE_PACKAGE:
115
116 /* Recursive call to delete package elements */
117
118 AcpiDbDeleteObjects (Objects[i].Package.Count,
119 Objects[i].Package.Elements);
120
121 /* Free the elements array */
122
123 ACPI_FREE (Objects[i].Package.Elements);
124 break;
125
126 default:
127
128 break;
129 }
130 }
131 }
132
133
134 /*******************************************************************************
135 *
136 * FUNCTION: AcpiDbExecuteMethod
137 *
138 * PARAMETERS: Info - Valid info segment
139 * ReturnObj - Where to put return object
140 *
141 * RETURN: Status
142 *
143 * DESCRIPTION: Execute a control method.
144 *
145 ******************************************************************************/
146
147 static ACPI_STATUS
148 AcpiDbExecuteMethod (
149 ACPI_DB_METHOD_INFO *Info,
150 ACPI_BUFFER *ReturnObj)
151 {
152 ACPI_STATUS Status;
153 ACPI_OBJECT_LIST ParamObjects;
154 ACPI_OBJECT Params[ACPI_DEBUGGER_MAX_ARGS + 1];
155 UINT32 i;
156
157
158 ACPI_FUNCTION_TRACE (DbExecuteMethod);
159
160
161 if (AcpiGbl_DbOutputToFile && !AcpiDbgLevel)
162 {
163 AcpiOsPrintf ("Warning: debug output is not enabled!\n");
164 }
165
166 ParamObjects.Count = 0;
167 ParamObjects.Pointer = NULL;
168
169 /* Pass through any command-line arguments */
170
171 if (Info->Args && Info->Args[0])
172 {
173 /* Get arguments passed on the command line */
174
175 for (i = 0; (Info->Args[i] && *(Info->Args[i])); i++)
176 {
177 /* Convert input string (token) to an actual ACPI_OBJECT */
178
179 Status = AcpiDbConvertToObject (Info->Types[i],
180 Info->Args[i], &Params[i]);
181 if (ACPI_FAILURE (Status))
182 {
183 ACPI_EXCEPTION ((AE_INFO, Status,
184 "While parsing method arguments"));
185 goto Cleanup;
186 }
187 }
188
189 ParamObjects.Count = i;
190 ParamObjects.Pointer = Params;
191 }
192
193 /* Prepare for a return object of arbitrary size */
194
195 ReturnObj->Pointer = AcpiGbl_DbBuffer;
196 ReturnObj->Length = ACPI_DEBUG_BUFFER_SIZE;
197
198 /* Do the actual method execution */
199
200 AcpiGbl_MethodExecuting = TRUE;
201 Status = AcpiEvaluateObject (NULL, Info->Pathname,
202 &ParamObjects, ReturnObj);
203
204 AcpiGbl_CmSingleStep = FALSE;
205 AcpiGbl_MethodExecuting = FALSE;
206
207 if (ACPI_FAILURE (Status))
208 {
209 if ((Status == AE_ABORT_METHOD) || AcpiGbl_AbortMethod)
210 {
211 /* Clear the abort and fall back to the debugger prompt */
212
213 ACPI_EXCEPTION ((AE_INFO, Status,
214 "Aborting top-level method"));
215
216 AcpiGbl_AbortMethod = FALSE;
217 Status = AE_OK;
218 goto Cleanup;
219 }
220
221 ACPI_EXCEPTION ((AE_INFO, Status,
222 "while executing %s from debugger", Info->Pathname));
223
224 if (Status == AE_BUFFER_OVERFLOW)
225 {
226 ACPI_ERROR ((AE_INFO,
227 "Possible overflow of internal debugger "
228 "buffer (size 0x%X needed 0x%X)",
229 ACPI_DEBUG_BUFFER_SIZE, (UINT32) ReturnObj->Length));
230 }
231 }
232
233 Cleanup:
234 AcpiDbDeleteObjects (ParamObjects.Count, Params);
235 return_ACPI_STATUS (Status);
236 }
237
238
239 /*******************************************************************************
240 *
241 * FUNCTION: AcpiDbExecuteSetup
242 *
243 * PARAMETERS: Info - Valid method info
244 *
245 * RETURN: None
246 *
247 * DESCRIPTION: Setup info segment prior to method execution
248 *
249 ******************************************************************************/
250
251 static ACPI_STATUS
252 AcpiDbExecuteSetup (
253 ACPI_DB_METHOD_INFO *Info)
254 {
255 ACPI_STATUS Status;
256
257
258 ACPI_FUNCTION_NAME (DbExecuteSetup);
259
260
261 /* Catenate the current scope to the supplied name */
262
263 Info->Pathname[0] = 0;
264 if ((Info->Name[0] != '\\') &&
265 (Info->Name[0] != '/'))
266 {
267 if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname),
268 AcpiGbl_DbScopeBuf))
269 {
270 Status = AE_BUFFER_OVERFLOW;
271 goto ErrorExit;
272 }
273 }
274
275 if (AcpiUtSafeStrcat (Info->Pathname, sizeof (Info->Pathname),
276 Info->Name))
277 {
278 Status = AE_BUFFER_OVERFLOW;
279 goto ErrorExit;
280 }
281
282 AcpiDbPrepNamestring (Info->Pathname);
283
284 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
285 AcpiOsPrintf ("Evaluating %s\n", Info->Pathname);
286
287 if (Info->Flags & EX_SINGLE_STEP)
288 {
289 AcpiGbl_CmSingleStep = TRUE;
290 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
291 }
292
293 else
294 {
295 /* No single step, allow redirection to a file */
296
297 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
298 }
299
300 return (AE_OK);
301
302 ErrorExit:
303
304 ACPI_EXCEPTION ((AE_INFO, Status, "During setup for method execution"));
305 return (Status);
306 }
307
308
309 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
310 UINT32
311 AcpiDbGetCacheInfo (
312 ACPI_MEMORY_LIST *Cache)
313 {
314
315 return (Cache->TotalAllocated - Cache->TotalFreed - Cache->CurrentDepth);
316 }
317 #endif
318
319 /*******************************************************************************
320 *
321 * FUNCTION: AcpiDbGetOutstandingAllocations
322 *
323 * PARAMETERS: None
324 *
325 * RETURN: Current global allocation count minus cache entries
326 *
327 * DESCRIPTION: Determine the current number of "outstanding" allocations --
328 * those allocations that have not been freed and also are not
329 * in one of the various object caches.
330 *
331 ******************************************************************************/
332
333 static UINT32
334 AcpiDbGetOutstandingAllocations (
335 void)
336 {
337 UINT32 Outstanding = 0;
338
339 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
340
341 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_StateCache);
342 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeCache);
343 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeExtCache);
344 Outstanding += AcpiDbGetCacheInfo (AcpiGbl_OperandCache);
345 #endif
346
347 return (Outstanding);
348 }
349
350
351 /*******************************************************************************
352 *
353 * FUNCTION: AcpiDbExecutionWalk
354 *
355 * PARAMETERS: WALK_CALLBACK
356 *
357 * RETURN: Status
358 *
359 * DESCRIPTION: Execute a control method. Name is relative to the current
360 * scope.
361 *
362 ******************************************************************************/
363
364 static ACPI_STATUS
365 AcpiDbExecutionWalk (
366 ACPI_HANDLE ObjHandle,
367 UINT32 NestingLevel,
368 void *Context,
369 void **ReturnValue)
370 {
371 ACPI_OPERAND_OBJECT *ObjDesc;
372 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
373 ACPI_BUFFER ReturnObj;
374 ACPI_STATUS Status;
375
376
377 ObjDesc = AcpiNsGetAttachedObject (Node);
378 if (ObjDesc->Method.ParamCount)
379 {
380 return (AE_OK);
381 }
382
383 ReturnObj.Pointer = NULL;
384 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
385
386 AcpiNsPrintNodePathname (Node, "Evaluating");
387
388 /* Do the actual method execution */
389
390 AcpiOsPrintf ("\n");
391 AcpiGbl_MethodExecuting = TRUE;
392
393 Status = AcpiEvaluateObject (Node, NULL, NULL, &ReturnObj);
394
395 AcpiOsPrintf ("Evaluation of [%4.4s] returned %s\n",
396 AcpiUtGetNodeName (Node),
397 AcpiFormatException (Status));
398
399 AcpiGbl_MethodExecuting = FALSE;
400 return (AE_OK);
401 }
402
403
404 /*******************************************************************************
405 *
406 * FUNCTION: AcpiDbExecute
407 *
408 * PARAMETERS: Name - Name of method to execute
409 * Args - Parameters to the method
410 * Types -
411 * Flags - single step/no single step
412 *
413 * RETURN: None
414 *
415 * DESCRIPTION: Execute a control method. Name is relative to the current
416 * scope.
417 *
418 ******************************************************************************/
419
420 void
421 AcpiDbExecute (
422 char *Name,
423 char **Args,
424 ACPI_OBJECT_TYPE *Types,
425 UINT32 Flags)
426 {
427 ACPI_STATUS Status;
428 ACPI_BUFFER ReturnObj;
429 char *NameString;
430
431 #ifdef ACPI_DEBUG_OUTPUT
432 UINT32 PreviousAllocations;
433 UINT32 Allocations;
434 #endif
435
436
437 /*
438 * Allow one execution to be performed by debugger or single step
439 * execution will be dead locked by the interpreter mutexes.
440 */
441 if (AcpiGbl_MethodExecuting)
442 {
443 AcpiOsPrintf ("Only one debugger execution is allowed.\n");
444 return;
445 }
446
447 #ifdef ACPI_DEBUG_OUTPUT
448 /* Memory allocation tracking */
449
450 PreviousAllocations = AcpiDbGetOutstandingAllocations ();
451 #endif
452
453 if (*Name == '*')
454 {
455 (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
456 ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL, NULL);
457 return;
458 }
459
460 NameString = ACPI_ALLOCATE (strlen (Name) + 1);
461 if (!NameString)
462 {
463 return;
464 }
465
466 memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
467 strcpy (NameString, Name);
468 AcpiUtStrupr (NameString);
469
470 /* Subcommand to Execute all predefined names in the namespace */
471
472 if (!strncmp (NameString, "PREDEF", 6))
473 {
474 AcpiDbEvaluatePredefinedNames ();
475 ACPI_FREE (NameString);
476 return;
477 }
478
479 AcpiGbl_DbMethodInfo.Name = NameString;
480 AcpiGbl_DbMethodInfo.Args = Args;
481 AcpiGbl_DbMethodInfo.Types = Types;
482 AcpiGbl_DbMethodInfo.Flags = Flags;
483
484 ReturnObj.Pointer = NULL;
485 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
486
487 Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
488 if (ACPI_FAILURE (Status))
489 {
490 ACPI_FREE (NameString);
491 return;
492 }
493
494 /* Get the NS node, determines existence also */
495
496 Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
497 &AcpiGbl_DbMethodInfo.Method);
498 if (ACPI_SUCCESS (Status))
499 {
500 Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo,
501 &ReturnObj);
502 }
503 ACPI_FREE (NameString);
504
505 /*
506 * Allow any handlers in separate threads to complete.
507 * (Such as Notify handlers invoked from AML executed above).
508 */
509 AcpiOsSleep ((UINT64) 10);
510
511 #ifdef ACPI_DEBUG_OUTPUT
512
513 /* Memory allocation tracking */
514
515 Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations;
516
517 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
518
519 if (Allocations > 0)
520 {
521 AcpiOsPrintf (
522 "0x%X Outstanding allocations after evaluation of %s\n",
523 Allocations, AcpiGbl_DbMethodInfo.Pathname);
524 }
525 #endif
526
527 if (ACPI_FAILURE (Status))
528 {
529 AcpiOsPrintf ("Evaluation of %s failed with status %s\n",
530 AcpiGbl_DbMethodInfo.Pathname,
531 AcpiFormatException (Status));
532 }
533 else
534 {
535 /* Display a return object, if any */
536
537 if (ReturnObj.Length)
538 {
539 AcpiOsPrintf (
540 "Evaluation of %s returned object %p, "
541 "external buffer length %X\n",
542 AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer,
543 (UINT32) ReturnObj.Length);
544
545 AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
546
547 /* Dump a _PLD buffer if present */
548
549 if (ACPI_COMPARE_NAME ((ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
550 AcpiGbl_DbMethodInfo.Method)->Name.Ascii),
551 METHOD_NAME__PLD))
552 {
553 AcpiDbDumpPldBuffer (ReturnObj.Pointer);
554 }
555 }
556 else
557 {
558 AcpiOsPrintf ("No object was returned from evaluation of %s\n",
559 AcpiGbl_DbMethodInfo.Pathname);
560 }
561 }
562
563 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
564 }
565
566
567 /*******************************************************************************
568 *
569 * FUNCTION: AcpiDbMethodThread
570 *
571 * PARAMETERS: Context - Execution info segment
572 *
573 * RETURN: None
574 *
575 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
576 * simply dispatches it.
577 *
578 ******************************************************************************/
579
580 static void ACPI_SYSTEM_XFACE
581 AcpiDbMethodThread (
582 void *Context)
583 {
584 ACPI_STATUS Status;
585 ACPI_DB_METHOD_INFO *Info = Context;
586 ACPI_DB_METHOD_INFO LocalInfo;
587 UINT32 i;
588 UINT8 Allow;
589 ACPI_BUFFER ReturnObj;
590
591
592 /*
593 * AcpiGbl_DbMethodInfo.Arguments will be passed as method arguments.
594 * Prevent AcpiGbl_DbMethodInfo from being modified by multiple threads
595 * concurrently.
596 *
597 * Note: The arguments we are passing are used by the ASL test suite
598 * (aslts). Do not change them without updating the tests.
599 */
600 (void) AcpiOsWaitSemaphore (Info->InfoGate, 1, ACPI_WAIT_FOREVER);
601
602 if (Info->InitArgs)
603 {
604 AcpiDbUint32ToHexString (Info->NumCreated,
605 Info->IndexOfThreadStr);
606 AcpiDbUint32ToHexString ((UINT32) AcpiOsGetThreadId (),
607 Info->IdOfThreadStr);
608 }
609
610 if (Info->Threads && (Info->NumCreated < Info->NumThreads))
611 {
612 Info->Threads[Info->NumCreated++] = AcpiOsGetThreadId();
613 }
614
615 LocalInfo = *Info;
616 LocalInfo.Args = LocalInfo.Arguments;
617 LocalInfo.Arguments[0] = LocalInfo.NumThreadsStr;
618 LocalInfo.Arguments[1] = LocalInfo.IdOfThreadStr;
619 LocalInfo.Arguments[2] = LocalInfo.IndexOfThreadStr;
620 LocalInfo.Arguments[3] = NULL;
621
622 LocalInfo.Types = LocalInfo.ArgTypes;
623
624 (void) AcpiOsSignalSemaphore (Info->InfoGate, 1);
625
626 for (i = 0; i < Info->NumLoops; i++)
627 {
628 Status = AcpiDbExecuteMethod (&LocalInfo, &ReturnObj);
629 if (ACPI_FAILURE (Status))
630 {
631 AcpiOsPrintf ("%s During evaluation of %s at iteration %X\n",
632 AcpiFormatException (Status), Info->Pathname, i);
633 if (Status == AE_ABORT_METHOD)
634 {
635 break;
636 }
637 }
638
639 #if 0
640 if ((i % 100) == 0)
641 {
642 AcpiOsPrintf ("%u loops, Thread 0x%x\n",
643 i, AcpiOsGetThreadId ());
644 }
645
646 if (ReturnObj.Length)
647 {
648 AcpiOsPrintf ("Evaluation of %s returned object %p Buflen %X\n",
649 Info->Pathname, ReturnObj.Pointer,
650 (UINT32) ReturnObj.Length);
651 AcpiDbDumpExternalObject (ReturnObj.Pointer, 1);
652 }
653 #endif
654 }
655
656 /* Signal our completion */
657
658 Allow = 0;
659 (void) AcpiOsWaitSemaphore (Info->ThreadCompleteGate,
660 1, ACPI_WAIT_FOREVER);
661 Info->NumCompleted++;
662
663 if (Info->NumCompleted == Info->NumThreads)
664 {
665 /* Do signal for main thread once only */
666 Allow = 1;
667 }
668
669 (void) AcpiOsSignalSemaphore (Info->ThreadCompleteGate, 1);
670
671 if (Allow)
672 {
673 Status = AcpiOsSignalSemaphore (Info->MainThreadGate, 1);
674 if (ACPI_FAILURE (Status))
675 {
676 AcpiOsPrintf (
677 "Could not signal debugger thread sync semaphore, %s\n",
678 AcpiFormatException (Status));
679 }
680 }
681 }
682
683
684 /*******************************************************************************
685 *
686 * FUNCTION: AcpiDbCreateExecutionThreads
687 *
688 * PARAMETERS: NumThreadsArg - Number of threads to create
689 * NumLoopsArg - Loop count for the thread(s)
690 * MethodNameArg - Control method to execute
691 *
692 * RETURN: None
693 *
694 * DESCRIPTION: Create threads to execute method(s)
695 *
696 ******************************************************************************/
697
698 void
699 AcpiDbCreateExecutionThreads (
700 char *NumThreadsArg,
701 char *NumLoopsArg,
702 char *MethodNameArg)
703 {
704 ACPI_STATUS Status;
705 UINT32 NumThreads;
706 UINT32 NumLoops;
707 UINT32 i;
708 UINT32 Size;
709 ACPI_MUTEX MainThreadGate;
710 ACPI_MUTEX ThreadCompleteGate;
711 ACPI_MUTEX InfoGate;
712
713
714 /* Get the arguments */
715
716 NumThreads = strtoul (NumThreadsArg, NULL, 0);
717 NumLoops = strtoul (NumLoopsArg, NULL, 0);
718
719 if (!NumThreads || !NumLoops)
720 {
721 AcpiOsPrintf ("Bad argument: Threads %X, Loops %X\n",
722 NumThreads, NumLoops);
723 return;
724 }
725
726 /*
727 * Create the semaphore for synchronization of
728 * the created threads with the main thread.
729 */
730 Status = AcpiOsCreateSemaphore (1, 0, &MainThreadGate);
731 if (ACPI_FAILURE (Status))
732 {
733 AcpiOsPrintf ("Could not create semaphore for "
734 "synchronization with the main thread, %s\n",
735 AcpiFormatException (Status));
736 return;
737 }
738
739 /*
740 * Create the semaphore for synchronization
741 * between the created threads.
742 */
743 Status = AcpiOsCreateSemaphore (1, 1, &ThreadCompleteGate);
744 if (ACPI_FAILURE (Status))
745 {
746 AcpiOsPrintf ("Could not create semaphore for "
747 "synchronization between the created threads, %s\n",
748 AcpiFormatException (Status));
749
750 (void) AcpiOsDeleteSemaphore (MainThreadGate);
751 return;
752 }
753
754 Status = AcpiOsCreateSemaphore (1, 1, &InfoGate);
755 if (ACPI_FAILURE (Status))
756 {
757 AcpiOsPrintf ("Could not create semaphore for "
758 "synchronization of AcpiGbl_DbMethodInfo, %s\n",
759 AcpiFormatException (Status));
760
761 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
762 (void) AcpiOsDeleteSemaphore (MainThreadGate);
763 return;
764 }
765
766 memset (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO));
767
768 /* Array to store IDs of threads */
769
770 AcpiGbl_DbMethodInfo.NumThreads = NumThreads;
771 Size = sizeof (ACPI_THREAD_ID) * AcpiGbl_DbMethodInfo.NumThreads;
772
773 AcpiGbl_DbMethodInfo.Threads = AcpiOsAllocate (Size);
774 if (AcpiGbl_DbMethodInfo.Threads == NULL)
775 {
776 AcpiOsPrintf ("No memory for thread IDs array\n");
777 (void) AcpiOsDeleteSemaphore (MainThreadGate);
778 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
779 (void) AcpiOsDeleteSemaphore (InfoGate);
780 return;
781 }
782 memset (AcpiGbl_DbMethodInfo.Threads, 0, Size);
783
784 /* Setup the context to be passed to each thread */
785
786 AcpiGbl_DbMethodInfo.Name = MethodNameArg;
787 AcpiGbl_DbMethodInfo.Flags = 0;
788 AcpiGbl_DbMethodInfo.NumLoops = NumLoops;
789 AcpiGbl_DbMethodInfo.MainThreadGate = MainThreadGate;
790 AcpiGbl_DbMethodInfo.ThreadCompleteGate = ThreadCompleteGate;
791 AcpiGbl_DbMethodInfo.InfoGate = InfoGate;
792
793 /* Init arguments to be passed to method */
794
795 AcpiGbl_DbMethodInfo.InitArgs = 1;
796 AcpiGbl_DbMethodInfo.Args = AcpiGbl_DbMethodInfo.Arguments;
797 AcpiGbl_DbMethodInfo.Arguments[0] = AcpiGbl_DbMethodInfo.NumThreadsStr;
798 AcpiGbl_DbMethodInfo.Arguments[1] = AcpiGbl_DbMethodInfo.IdOfThreadStr;
799 AcpiGbl_DbMethodInfo.Arguments[2] = AcpiGbl_DbMethodInfo.IndexOfThreadStr;
800 AcpiGbl_DbMethodInfo.Arguments[3] = NULL;
801
802 AcpiGbl_DbMethodInfo.Types = AcpiGbl_DbMethodInfo.ArgTypes;
803 AcpiGbl_DbMethodInfo.ArgTypes[0] = ACPI_TYPE_INTEGER;
804 AcpiGbl_DbMethodInfo.ArgTypes[1] = ACPI_TYPE_INTEGER;
805 AcpiGbl_DbMethodInfo.ArgTypes[2] = ACPI_TYPE_INTEGER;
806
807 AcpiDbUint32ToHexString (NumThreads, AcpiGbl_DbMethodInfo.NumThreadsStr);
808
809 Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo);
810 if (ACPI_FAILURE (Status))
811 {
812 goto CleanupAndExit;
813 }
814
815 /* Get the NS node, determines existence also */
816
817 Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname,
818 &AcpiGbl_DbMethodInfo.Method);
819 if (ACPI_FAILURE (Status))
820 {
821 AcpiOsPrintf ("%s Could not get handle for %s\n",
822 AcpiFormatException (Status), AcpiGbl_DbMethodInfo.Pathname);
823 goto CleanupAndExit;
824 }
825
826 /* Create the threads */
827
828 AcpiOsPrintf ("Creating %X threads to execute %X times each\n",
829 NumThreads, NumLoops);
830
831 for (i = 0; i < (NumThreads); i++)
832 {
833 Status = AcpiOsExecute (OSL_DEBUGGER_EXEC_THREAD, AcpiDbMethodThread,
834 &AcpiGbl_DbMethodInfo);
835 if (ACPI_FAILURE (Status))
836 {
837 break;
838 }
839 }
840
841 /* Wait for all threads to complete */
842
843 (void) AcpiOsWaitSemaphore (MainThreadGate, 1, ACPI_WAIT_FOREVER);
844
845 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
846 AcpiOsPrintf ("All threads (%X) have completed\n", NumThreads);
847 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
848
849 CleanupAndExit:
850
851 /* Cleanup and exit */
852
853 (void) AcpiOsDeleteSemaphore (MainThreadGate);
854 (void) AcpiOsDeleteSemaphore (ThreadCompleteGate);
855 (void) AcpiOsDeleteSemaphore (InfoGate);
856
857 AcpiOsFree (AcpiGbl_DbMethodInfo.Threads);
858 AcpiGbl_DbMethodInfo.Threads = NULL;
859 }
860