dbstats.c revision 102550
1/*******************************************************************************
2 *
3 * Module Name: dbstats - Generation and display of ACPI table statistics
4 *              $Revision: 61 $
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights.  You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code.  No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision.  In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change.  Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee.  Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution.  In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government.  In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117
118#include <acpi.h>
119#include <acdebug.h>
120#include <acnamesp.h>
121
122#ifdef ACPI_DEBUGGER
123
124#define _COMPONENT          ACPI_CA_DEBUGGER
125        ACPI_MODULE_NAME    ("dbstats")
126
127/*
128 * Statistics subcommands
129 */
130static ARGUMENT_INFO        AcpiDbStatTypes [] =
131{
132    {"ALLOCATIONS"},
133    {"OBJECTS"},
134    {"MEMORY"},
135    {"MISC"},
136    {"TABLES"},
137    {"SIZES"},
138    {"STACK"},
139    {NULL}           /* Must be null terminated */
140};
141
142#define CMD_STAT_ALLOCATIONS     0
143#define CMD_STAT_OBJECTS         1
144#define CMD_STAT_MEMORY          2
145#define CMD_STAT_MISC            3
146#define CMD_STAT_TABLES          4
147#define CMD_STAT_SIZES           5
148#define CMD_STAT_STACK           6
149
150
151/*******************************************************************************
152 *
153 * FUNCTION:    AcpiDbEnumerateObject
154 *
155 * PARAMETERS:  ObjDesc             - Object to be counted
156 *
157 * RETURN:      None
158 *
159 * DESCRIPTION: Add this object to the global counts, by object type.
160 *              Limited recursion handles subobjects and packages, and this
161 *              is probably acceptable within the AML debugger only.
162 *
163 ******************************************************************************/
164
165void
166AcpiDbEnumerateObject (
167    ACPI_OPERAND_OBJECT     *ObjDesc)
168{
169    UINT32                  i;
170
171
172    if (!ObjDesc)
173    {
174        return;
175    }
176
177
178    /* Enumerate this object first */
179
180    AcpiGbl_NumObjects++;
181
182    if (ACPI_GET_OBJECT_TYPE (ObjDesc) > INTERNAL_TYPE_NODE_MAX)
183    {
184        AcpiGbl_ObjTypeCountMisc++;
185    }
186    else
187    {
188        AcpiGbl_ObjTypeCount [ACPI_GET_OBJECT_TYPE (ObjDesc)]++;
189    }
190
191    /* Count the sub-objects */
192
193    switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
194    {
195    case ACPI_TYPE_PACKAGE:
196        for (i = 0; i < ObjDesc->Package.Count; i++)
197        {
198            AcpiDbEnumerateObject (ObjDesc->Package.Elements[i]);
199        }
200        break;
201
202    case ACPI_TYPE_DEVICE:
203        AcpiDbEnumerateObject (ObjDesc->Device.SysHandler);
204        AcpiDbEnumerateObject (ObjDesc->Device.DrvHandler);
205        AcpiDbEnumerateObject (ObjDesc->Device.AddrHandler);
206        break;
207
208    case ACPI_TYPE_BUFFER_FIELD:
209        if (AcpiNsGetSecondaryObject (ObjDesc))
210        {
211            AcpiGbl_ObjTypeCount [ACPI_TYPE_BUFFER_FIELD]++;
212        }
213        break;
214
215    case ACPI_TYPE_REGION:
216        AcpiGbl_ObjTypeCount [INTERNAL_TYPE_REGION_FIELD ]++;
217        AcpiDbEnumerateObject (ObjDesc->Region.AddrHandler);
218        break;
219
220    case ACPI_TYPE_POWER:
221        AcpiDbEnumerateObject (ObjDesc->PowerResource.SysHandler);
222        AcpiDbEnumerateObject (ObjDesc->PowerResource.DrvHandler);
223        break;
224
225    case ACPI_TYPE_PROCESSOR:
226        AcpiDbEnumerateObject (ObjDesc->Processor.SysHandler);
227        AcpiDbEnumerateObject (ObjDesc->Processor.DrvHandler);
228        AcpiDbEnumerateObject (ObjDesc->Processor.AddrHandler);
229        break;
230
231    case ACPI_TYPE_THERMAL:
232        AcpiDbEnumerateObject (ObjDesc->ThermalZone.SysHandler);
233        AcpiDbEnumerateObject (ObjDesc->ThermalZone.DrvHandler);
234        AcpiDbEnumerateObject (ObjDesc->ThermalZone.AddrHandler);
235        break;
236
237    default:
238        break;
239    }
240}
241
242
243/*******************************************************************************
244 *
245 * FUNCTION:    AcpiDbClassifyOneObject
246 *
247 * PARAMETERS:  Callback for WalkNamespace
248 *
249 * RETURN:      Status
250 *
251 * DESCRIPTION: Enumerate both the object descriptor (including subobjects) and
252 *              the parent namespace node.
253 *
254 ******************************************************************************/
255
256ACPI_STATUS
257AcpiDbClassifyOneObject (
258    ACPI_HANDLE             ObjHandle,
259    UINT32                  NestingLevel,
260    void                    *Context,
261    void                    **ReturnValue)
262{
263    ACPI_NAMESPACE_NODE     *Node;
264    ACPI_OPERAND_OBJECT     *ObjDesc;
265    UINT32                  Type;
266
267
268    AcpiGbl_NumNodes++;
269
270    Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
271    ObjDesc = AcpiNsGetAttachedObject (Node);
272
273    AcpiDbEnumerateObject (ObjDesc);
274
275    Type = Node->Type;
276    if (Type > INTERNAL_TYPE_NODE_MAX)
277    {
278        AcpiGbl_NodeTypeCountMisc++;
279    }
280
281    else
282    {
283        AcpiGbl_NodeTypeCount [Type]++;
284    }
285
286    return AE_OK;
287
288
289    /* TBD: These need to be counted during the initial parsing phase */
290    /*
291    if (AcpiPsIsNamedOp (Op->Opcode))
292    {
293        NumNodes++;
294    }
295
296    if (IsMethod)
297    {
298        NumMethodElements++;
299    }
300
301    NumGrammarElements++;
302    Op = AcpiPsGetDepthNext (Root, Op);
303
304    SizeOfParseTree             = (NumGrammarElements - NumMethodElements) * (UINT32) sizeof (ACPI_PARSE_OBJECT);
305    SizeOfMethodTrees           = NumMethodElements * (UINT32) sizeof (ACPI_PARSE_OBJECT);
306    SizeOfNodeEntries           = NumNodes * (UINT32) sizeof (ACPI_NAMESPACE_NODE);
307    SizeOfAcpiObjects           = NumNodes * (UINT32) sizeof (ACPI_OPERAND_OBJECT);
308
309    */
310}
311
312
313/*******************************************************************************
314 *
315 * FUNCTION:    AcpiDbCountNamespaceObjects
316 *
317 * PARAMETERS:  None
318 *
319 * RETURN:      Status
320 *
321 * DESCRIPTION: Count and classify the entire namespace, including all
322 *              namespace nodes and attached objects.
323 *
324 ******************************************************************************/
325
326void
327AcpiDbCountNamespaceObjects (
328    void)
329{
330    UINT32                  i;
331
332
333    AcpiGbl_NumNodes = 0;
334    AcpiGbl_NumObjects = 0;
335
336    AcpiGbl_ObjTypeCountMisc = 0;
337    for (i = 0; i < (INTERNAL_TYPE_NODE_MAX -1); i++)
338    {
339        AcpiGbl_ObjTypeCount [i] = 0;
340        AcpiGbl_NodeTypeCount [i] = 0;
341    }
342
343    (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
344                        FALSE, AcpiDbClassifyOneObject, NULL, NULL);
345}
346
347
348/*******************************************************************************
349 *
350 * FUNCTION:    AcpiDbDisplayStatistics
351 *
352 * PARAMETERS:  TypeArg         - Subcommand
353 *
354 * RETURN:      Status
355 *
356 * DESCRIPTION: Display various statistics
357 *
358 ******************************************************************************/
359
360ACPI_STATUS
361AcpiDbDisplayStatistics (
362    NATIVE_CHAR             *TypeArg)
363{
364    UINT32                  i;
365    UINT32                  Type;
366    UINT32                  Size;
367#ifdef ACPI_DBG_TRACK_ALLOCATIONS
368    UINT32                  Outstanding;
369#endif
370
371
372    if (!AcpiGbl_DSDT)
373    {
374        AcpiOsPrintf ("*** Warning:  There is no DSDT loaded\n");
375    }
376
377    if (!TypeArg)
378    {
379        AcpiOsPrintf ("The following subcommands are available:\n    ALLOCATIONS, OBJECTS, MEMORY, MISC, SIZES, TABLES\n");
380        return (AE_OK);
381    }
382
383    ACPI_STRUPR (TypeArg);
384    Type = AcpiDbMatchArgument (TypeArg, AcpiDbStatTypes);
385    if (Type == (UINT32) -1)
386    {
387        AcpiOsPrintf ("Invalid or unsupported argument\n");
388        return (AE_OK);
389    }
390
391
392    switch (Type)
393    {
394    case CMD_STAT_ALLOCATIONS:
395#ifdef ACPI_DBG_TRACK_ALLOCATIONS
396        AcpiUtDumpAllocationInfo ();
397#endif
398        break;
399
400    case CMD_STAT_TABLES:
401
402        AcpiOsPrintf ("ACPI Table Information:\n\n");
403        if (AcpiGbl_DSDT)
404        {
405            AcpiOsPrintf ("DSDT Length:................% 7ld (%X)\n", AcpiGbl_DSDT->Length, AcpiGbl_DSDT->Length);
406        }
407        break;
408
409    case CMD_STAT_OBJECTS:
410
411        AcpiDbCountNamespaceObjects ();
412
413        AcpiOsPrintf ("\nObjects defined in the current namespace:\n\n");
414
415        AcpiOsPrintf ("%16.16s % 10.10s % 10.10s\n", "ACPI_TYPE", "NODES", "OBJECTS");
416
417        for (i = 0; i < INTERNAL_TYPE_NODE_MAX; i++)
418        {
419            AcpiOsPrintf ("%16.16s % 10ld% 10ld\n", AcpiUtGetTypeName (i),
420                AcpiGbl_NodeTypeCount [i], AcpiGbl_ObjTypeCount [i]);
421        }
422        AcpiOsPrintf ("%16.16s % 10ld% 10ld\n", "Misc/Unknown",
423            AcpiGbl_NodeTypeCountMisc, AcpiGbl_ObjTypeCountMisc);
424
425        AcpiOsPrintf ("%16.16s % 10ld% 10ld\n", "TOTALS:",
426            AcpiGbl_NumNodes, AcpiGbl_NumObjects);
427        break;
428
429    case CMD_STAT_MEMORY:
430
431#ifdef ACPI_DBG_TRACK_ALLOCATIONS
432        AcpiOsPrintf ("\n----Object and Cache Statistics---------------------------------------------\n");
433
434        for (i = 0; i < ACPI_NUM_MEM_LISTS; i++)
435        {
436            AcpiOsPrintf ("\n%s\n", AcpiGbl_MemoryLists[i].ListName);
437
438            if (AcpiGbl_MemoryLists[i].MaxCacheDepth > 0)
439            {
440                AcpiOsPrintf ("    Cache: [Depth Max Avail Size]         % 7d % 7d % 7d % 7d B\n",
441                        AcpiGbl_MemoryLists[i].CacheDepth,
442                        AcpiGbl_MemoryLists[i].MaxCacheDepth,
443                        AcpiGbl_MemoryLists[i].MaxCacheDepth - AcpiGbl_MemoryLists[i].CacheDepth,
444                        (AcpiGbl_MemoryLists[i].CacheDepth * AcpiGbl_MemoryLists[i].ObjectSize));
445
446                AcpiOsPrintf ("    Cache: [Requests Hits Misses ObjSize] % 7d % 7d % 7d % 7d B\n",
447                        AcpiGbl_MemoryLists[i].CacheRequests,
448                        AcpiGbl_MemoryLists[i].CacheHits,
449                        AcpiGbl_MemoryLists[i].CacheRequests - AcpiGbl_MemoryLists[i].CacheHits,
450                        AcpiGbl_MemoryLists[i].ObjectSize);
451            }
452
453            Outstanding = AcpiGbl_MemoryLists[i].TotalAllocated -
454                            AcpiGbl_MemoryLists[i].TotalFreed -
455                            AcpiGbl_MemoryLists[i].CacheDepth;
456
457            if (AcpiGbl_MemoryLists[i].ObjectSize)
458            {
459                Size = ACPI_ROUND_UP_TO_1K (Outstanding * AcpiGbl_MemoryLists[i].ObjectSize);
460            }
461            else
462            {
463                Size = ACPI_ROUND_UP_TO_1K (AcpiGbl_MemoryLists[i].CurrentTotalSize);
464            }
465
466            AcpiOsPrintf ("    Mem:   [Alloc Free Outstanding Size]  % 7d % 7d % 7d % 7d Kb\n",
467                    AcpiGbl_MemoryLists[i].TotalAllocated,
468                    AcpiGbl_MemoryLists[i].TotalFreed,
469                    Outstanding, Size);
470        }
471#endif
472
473        break;
474
475    case CMD_STAT_MISC:
476
477        AcpiOsPrintf ("\nMiscellaneous Statistics:\n\n");
478        AcpiOsPrintf ("Calls to AcpiPsFind:..  ........% 7ld\n", AcpiGbl_PsFindCount);
479        AcpiOsPrintf ("Calls to AcpiNsLookup:..........% 7ld\n", AcpiGbl_NsLookupCount);
480
481        AcpiOsPrintf ("\n");
482
483        AcpiOsPrintf ("Mutex usage:\n\n");
484        for (i = 0; i < NUM_MTX; i++)
485        {
486            AcpiOsPrintf ("%-28s:       % 7ld\n", AcpiUtGetMutexName (i), AcpiGbl_AcpiMutexInfo[i].UseCount);
487        }
488        break;
489
490
491    case CMD_STAT_SIZES:
492
493        AcpiOsPrintf ("\nInternal object sizes:\n\n");
494
495        AcpiOsPrintf ("Common           %3d\n", sizeof (ACPI_OBJECT_COMMON));
496        AcpiOsPrintf ("Number           %3d\n", sizeof (ACPI_OBJECT_INTEGER));
497        AcpiOsPrintf ("String           %3d\n", sizeof (ACPI_OBJECT_STRING));
498        AcpiOsPrintf ("Buffer           %3d\n", sizeof (ACPI_OBJECT_BUFFER));
499        AcpiOsPrintf ("Package          %3d\n", sizeof (ACPI_OBJECT_PACKAGE));
500        AcpiOsPrintf ("BufferField      %3d\n", sizeof (ACPI_OBJECT_BUFFER_FIELD));
501        AcpiOsPrintf ("Device           %3d\n", sizeof (ACPI_OBJECT_DEVICE));
502        AcpiOsPrintf ("Event            %3d\n", sizeof (ACPI_OBJECT_EVENT));
503        AcpiOsPrintf ("Method           %3d\n", sizeof (ACPI_OBJECT_METHOD));
504        AcpiOsPrintf ("Mutex            %3d\n", sizeof (ACPI_OBJECT_MUTEX));
505        AcpiOsPrintf ("Region           %3d\n", sizeof (ACPI_OBJECT_REGION));
506        AcpiOsPrintf ("PowerResource    %3d\n", sizeof (ACPI_OBJECT_POWER_RESOURCE));
507        AcpiOsPrintf ("Processor        %3d\n", sizeof (ACPI_OBJECT_PROCESSOR));
508        AcpiOsPrintf ("ThermalZone      %3d\n", sizeof (ACPI_OBJECT_THERMAL_ZONE));
509        AcpiOsPrintf ("RegionField      %3d\n", sizeof (ACPI_OBJECT_REGION_FIELD));
510        AcpiOsPrintf ("BankField        %3d\n", sizeof (ACPI_OBJECT_BANK_FIELD));
511        AcpiOsPrintf ("IndexField       %3d\n", sizeof (ACPI_OBJECT_INDEX_FIELD));
512        AcpiOsPrintf ("Reference        %3d\n", sizeof (ACPI_OBJECT_REFERENCE));
513        AcpiOsPrintf ("NotifyHandler    %3d\n", sizeof (ACPI_OBJECT_NOTIFY_HANDLER));
514        AcpiOsPrintf ("AddrHandler      %3d\n", sizeof (ACPI_OBJECT_ADDR_HANDLER));
515        AcpiOsPrintf ("Extra            %3d\n", sizeof (ACPI_OBJECT_EXTRA));
516        AcpiOsPrintf ("Data             %3d\n", sizeof (ACPI_OBJECT_DATA));
517
518        AcpiOsPrintf ("\n");
519
520        AcpiOsPrintf ("ParseObject      %3d\n", sizeof (ACPI_PARSE_OBJ_COMMON));
521        AcpiOsPrintf ("ParseObjectNamed %3d\n", sizeof (ACPI_PARSE_OBJ_NAMED));
522        AcpiOsPrintf ("ParseObjectAsl   %3d\n", sizeof (ACPI_PARSE_OBJ_ASL));
523        AcpiOsPrintf ("OperandObject    %3d\n", sizeof (ACPI_OPERAND_OBJECT));
524        AcpiOsPrintf ("NamespaceNode    %3d\n", sizeof (ACPI_NAMESPACE_NODE));
525
526        break;
527
528
529    case CMD_STAT_STACK:
530#if defined(ACPI_DEBUG_OUTPUT)
531
532        Size = (UINT32) (AcpiGbl_EntryStackPointer - AcpiGbl_LowestStackPointer);
533
534        AcpiOsPrintf ("\nSubsystem Stack Usage:\n\n");
535        AcpiOsPrintf ("Entry Stack Pointer          %X\n", AcpiGbl_EntryStackPointer);
536        AcpiOsPrintf ("Lowest Stack Pointer         %X\n", AcpiGbl_LowestStackPointer);
537        AcpiOsPrintf ("Stack Use                    %X (%d)\n", Size, Size);
538        AcpiOsPrintf ("Deepest Procedure Nesting    %d\n", AcpiGbl_DeepestNesting);
539#endif
540        break;
541
542    default:
543        break;
544    }
545
546    AcpiOsPrintf ("\n");
547    return (AE_OK);
548}
549
550
551#endif /* ACPI_DEBUGGER  */
552