dbstats.c revision 87031
1/******************************************************************************* 2 * 3 * Module Name: dbstats - Generation and display of ACPI table statistics 4 * $Revision: 49 $ 5 * 6 ******************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, 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 <amlcode.h> 121#include <acparser.h> 122#include <acnamesp.h> 123 124#ifdef ENABLE_DEBUGGER 125 126#define _COMPONENT ACPI_DEBUGGER 127 MODULE_NAME ("dbstats") 128 129/* 130 * Statistics subcommands 131 */ 132ARGUMENT_INFO AcpiDbStatTypes [] = 133{ 134 {"ALLOCATIONS"}, 135 {"OBJECTS"}, 136 {"MEMORY"}, 137 {"MISC"}, 138 {"TABLES"}, 139 {"SIZES"}, 140 {"STACK"}, 141 {NULL} /* Must be null terminated */ 142}; 143 144#define CMD_ALLOCATIONS 0 145#define CMD_OBJECTS 1 146#define CMD_MEMORY 2 147#define CMD_MISC 3 148#define CMD_TABLES 4 149#define CMD_SIZES 5 150#define CMD_STACK 6 151 152 153/******************************************************************************* 154 * 155 * FUNCTION: AcpiDbEnumerateObject 156 * 157 * PARAMETERS: ObjDesc - Object to be counted 158 * 159 * RETURN: None 160 * 161 * DESCRIPTION: Add this object to the global counts, by object type. 162 * Recursively handles subobjects and packages. 163 * 164 * [TBD] Restructure - remove recursion. 165 * 166 ******************************************************************************/ 167 168void 169AcpiDbEnumerateObject ( 170 ACPI_OPERAND_OBJECT *ObjDesc) 171{ 172 ACPI_OPERAND_OBJECT *ObjDesc2; 173 UINT32 Type; 174 UINT32 i; 175 176 177 if (!ObjDesc) 178 { 179 return; 180 } 181 182 183 /* Enumerate this object first */ 184 185 AcpiGbl_NumObjects++; 186 187 Type = ObjDesc->Common.Type; 188 if (Type > INTERNAL_TYPE_NODE_MAX) 189 { 190 AcpiGbl_ObjTypeCountMisc++; 191 } 192 else 193 { 194 AcpiGbl_ObjTypeCount [Type]++; 195 } 196 197 /* Count the sub-objects */ 198 199 switch (Type) 200 { 201 case ACPI_TYPE_PACKAGE: 202 for (i = 0; i< ObjDesc->Package.Count; i++) 203 { 204 AcpiDbEnumerateObject (ObjDesc->Package.Elements[i]); 205 } 206 break; 207 208 case ACPI_TYPE_DEVICE: 209 AcpiDbEnumerateObject (ObjDesc->Device.SysHandler); 210 AcpiDbEnumerateObject (ObjDesc->Device.DrvHandler); 211 AcpiDbEnumerateObject (ObjDesc->Device.AddrHandler); 212 break; 213 214 case ACPI_TYPE_BUFFER_FIELD: 215 ObjDesc2 = AcpiNsGetSecondaryObject (ObjDesc); 216 if (ObjDesc2) 217 { 218 AcpiGbl_ObjTypeCount [INTERNAL_TYPE_EXTRA]++; 219 } 220 break; 221 222 case ACPI_TYPE_REGION: 223 AcpiGbl_ObjTypeCount [INTERNAL_TYPE_EXTRA]++; 224 AcpiDbEnumerateObject (ObjDesc->Region.AddrHandler); 225 break; 226 227 case ACPI_TYPE_POWER: 228 AcpiDbEnumerateObject (ObjDesc->PowerResource.SysHandler); 229 AcpiDbEnumerateObject (ObjDesc->PowerResource.DrvHandler); 230 break; 231 232 case ACPI_TYPE_PROCESSOR: 233 AcpiDbEnumerateObject (ObjDesc->Processor.SysHandler); 234 AcpiDbEnumerateObject (ObjDesc->Processor.DrvHandler); 235 AcpiDbEnumerateObject (ObjDesc->Processor.AddrHandler); 236 break; 237 238 case ACPI_TYPE_THERMAL: 239 AcpiDbEnumerateObject (ObjDesc->ThermalZone.SysHandler); 240 AcpiDbEnumerateObject (ObjDesc->ThermalZone.DrvHandler); 241 AcpiDbEnumerateObject (ObjDesc->ThermalZone.AddrHandler); 242 break; 243 } 244} 245 246 247#ifndef PARSER_ONLY 248 249/******************************************************************************* 250 * 251 * FUNCTION: AcpiDbClassifyOneObject 252 * 253 * PARAMETERS: Callback for WalkNamespace 254 * 255 * RETURN: Status 256 * 257 * DESCRIPTION: Enumerate both the object descriptor (including subobjects) and 258 * the parent namespace node. 259 * 260 ******************************************************************************/ 261 262ACPI_STATUS 263AcpiDbClassifyOneObject ( 264 ACPI_HANDLE ObjHandle, 265 UINT32 NestingLevel, 266 void *Context, 267 void **ReturnValue) 268{ 269 ACPI_NAMESPACE_NODE *Node; 270 ACPI_OPERAND_OBJECT *ObjDesc; 271 UINT32 Type; 272 273 274 AcpiGbl_NumNodes++; 275 276 Node = (ACPI_NAMESPACE_NODE *) ObjHandle; 277 ObjDesc = AcpiNsGetAttachedObject (Node); 278 279 AcpiDbEnumerateObject (ObjDesc); 280 281 Type = Node->Type; 282 if (Type > INTERNAL_TYPE_NODE_MAX) 283 { 284 AcpiGbl_NodeTypeCountMisc++; 285 } 286 287 else 288 { 289 AcpiGbl_NodeTypeCount [Type]++; 290 } 291 292 return AE_OK; 293 294 295 /* TBD: These need to be counted during the initial parsing phase */ 296 /* 297 if (AcpiPsIsNamedOp (Op->Opcode)) 298 { 299 NumNodes++; 300 } 301 302 if (IsMethod) 303 { 304 NumMethodElements++; 305 } 306 307 NumGrammarElements++; 308 Op = AcpiPsGetDepthNext (Root, Op); 309 310 SizeOfParseTree = (NumGrammarElements - NumMethodElements) * (UINT32) sizeof (ACPI_PARSE_OBJECT); 311 SizeOfMethodTrees = NumMethodElements * (UINT32) sizeof (ACPI_PARSE_OBJECT); 312 SizeOfNodeEntries = NumNodes * (UINT32) sizeof (ACPI_NAMESPACE_NODE); 313 SizeOfAcpiObjects = NumNodes * (UINT32) sizeof (ACPI_OPERAND_OBJECT); 314 315 */ 316} 317 318 319/******************************************************************************* 320 * 321 * FUNCTION: AcpiDbCountNamespaceObjects 322 * 323 * PARAMETERS: None 324 * 325 * RETURN: Status 326 * 327 * DESCRIPTION: Count and classify the entire namespace, including all 328 * namespace nodes and attached objects. 329 * 330 ******************************************************************************/ 331 332ACPI_STATUS 333AcpiDbCountNamespaceObjects ( 334 void) 335{ 336 UINT32 i; 337 338 339 AcpiGbl_NumNodes = 0; 340 AcpiGbl_NumObjects = 0; 341 342 AcpiGbl_ObjTypeCountMisc = 0; 343 for (i = 0; i < (INTERNAL_TYPE_NODE_MAX -1); i++) 344 { 345 AcpiGbl_ObjTypeCount [i] = 0; 346 AcpiGbl_NodeTypeCount [i] = 0; 347 } 348 349 AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, 350 FALSE, AcpiDbClassifyOneObject, NULL, NULL); 351 352 return (AE_OK); 353} 354 355#endif 356 357 358/******************************************************************************* 359 * 360 * FUNCTION: AcpiDbDisplayStatistics 361 * 362 * PARAMETERS: TypeArg - Subcommand 363 * 364 * RETURN: Status 365 * 366 * DESCRIPTION: Display various statistics 367 * 368 ******************************************************************************/ 369 370ACPI_STATUS 371AcpiDbDisplayStatistics ( 372 NATIVE_CHAR *TypeArg) 373{ 374 UINT32 i; 375 UINT32 Type; 376 UINT32 Outstanding; 377 UINT32 Size; 378 379 380 if (!AcpiGbl_DSDT) 381 { 382 AcpiOsPrintf ("*** Warning: There is no DSDT loaded\n"); 383 } 384 385 if (!TypeArg) 386 { 387 AcpiOsPrintf ("The following subcommands are available:\n ALLOCATIONS, OBJECTS, MEMORY, MISC, SIZES, TABLES\n"); 388 return (AE_OK); 389 } 390 391 STRUPR (TypeArg); 392 Type = AcpiDbMatchArgument (TypeArg, AcpiDbStatTypes); 393 if (Type == (UINT32) -1) 394 { 395 AcpiOsPrintf ("Invalid or unsupported argument\n"); 396 return (AE_OK); 397 } 398 399 400 switch (Type) 401 { 402#ifndef PARSER_ONLY 403 case CMD_ALLOCATIONS: 404#ifdef ACPI_DBG_TRACK_ALLOCATIONS 405 AcpiUtDumpAllocationInfo (); 406#endif 407 break; 408#endif 409 410 case CMD_TABLES: 411 412 AcpiOsPrintf ("ACPI Table Information:\n\n"); 413 if (AcpiGbl_DSDT) 414 { 415 AcpiOsPrintf ("DSDT Length:................% 7ld (%X)\n", AcpiGbl_DSDT->Length, AcpiGbl_DSDT->Length); 416 } 417 break; 418 419 case CMD_OBJECTS: 420 421#ifndef PARSER_ONLY 422 423 AcpiDbCountNamespaceObjects (); 424 425 AcpiOsPrintf ("\nObjects defined in the current namespace:\n\n"); 426 427 AcpiOsPrintf ("%16.16s % 10.10s % 10.10s\n", "ACPI_TYPE", "NODES", "OBJECTS"); 428 429 for (i = 0; i < INTERNAL_TYPE_NODE_MAX; i++) 430 { 431 AcpiOsPrintf ("%16.16s % 10ld% 10ld\n", AcpiUtGetTypeName (i), 432 AcpiGbl_NodeTypeCount [i], AcpiGbl_ObjTypeCount [i]); 433 } 434 AcpiOsPrintf ("%16.16s % 10ld% 10ld\n", "Misc/Unknown", 435 AcpiGbl_NodeTypeCountMisc, AcpiGbl_ObjTypeCountMisc); 436 437 AcpiOsPrintf ("%16.16s % 10ld% 10ld\n", "TOTALS:", 438 AcpiGbl_NumNodes, AcpiGbl_NumObjects); 439 440#endif 441 break; 442 443 case CMD_MEMORY: 444 445#ifdef ACPI_DBG_TRACK_ALLOCATIONS 446 AcpiOsPrintf ("\n----Object and Cache Statistics---------------------------------------------\n"); 447 448 for (i = 0; i < ACPI_NUM_MEM_LISTS; i++) 449 { 450 AcpiOsPrintf ("\n%s\n", AcpiGbl_MemoryLists[i].ListName); 451 452 if (AcpiGbl_MemoryLists[i].MaxCacheDepth > 0) 453 { 454 AcpiOsPrintf (" Cache: [Depth Max Avail Size] % 7d % 7d % 7d % 7d B\n", 455 AcpiGbl_MemoryLists[i].CacheDepth, 456 AcpiGbl_MemoryLists[i].MaxCacheDepth, 457 AcpiGbl_MemoryLists[i].MaxCacheDepth - AcpiGbl_MemoryLists[i].CacheDepth, 458 (AcpiGbl_MemoryLists[i].CacheDepth * AcpiGbl_MemoryLists[i].ObjectSize)); 459 460 AcpiOsPrintf (" Cache: [Requests Hits Misses ObjSize] % 7d % 7d % 7d % 7d B\n", 461 AcpiGbl_MemoryLists[i].CacheRequests, 462 AcpiGbl_MemoryLists[i].CacheHits, 463 AcpiGbl_MemoryLists[i].CacheRequests - AcpiGbl_MemoryLists[i].CacheHits, 464 AcpiGbl_MemoryLists[i].ObjectSize); 465 } 466 467 Outstanding = AcpiGbl_MemoryLists[i].TotalAllocated - 468 AcpiGbl_MemoryLists[i].TotalFreed - 469 AcpiGbl_MemoryLists[i].CacheDepth; 470 471 if (AcpiGbl_MemoryLists[i].ObjectSize) 472 { 473 Size = ROUND_UP_TO_1K (Outstanding * AcpiGbl_MemoryLists[i].ObjectSize); 474 } 475 else 476 { 477 Size = ROUND_UP_TO_1K (AcpiGbl_MemoryLists[i].CurrentTotalSize); 478 } 479 480 AcpiOsPrintf (" Mem: [Alloc Free Outstanding Size] % 7d % 7d % 7d % 7d Kb\n", 481 AcpiGbl_MemoryLists[i].TotalAllocated, 482 AcpiGbl_MemoryLists[i].TotalFreed, 483 Outstanding, Size); 484 } 485#endif 486 487 break; 488 489 case CMD_MISC: 490 491 AcpiOsPrintf ("\nMiscellaneous Statistics:\n\n"); 492 AcpiOsPrintf ("Calls to AcpiPsFind:.. ........% 7ld\n", AcpiGbl_PsFindCount); 493 AcpiOsPrintf ("Calls to AcpiNsLookup:..........% 7ld\n", AcpiGbl_NsLookupCount); 494 495 AcpiOsPrintf ("\n"); 496 497 AcpiOsPrintf ("Mutex usage:\n\n"); 498 for (i = 0; i < NUM_MTX; i++) 499 { 500 AcpiOsPrintf ("%-28s: % 7ld\n", AcpiUtGetMutexName (i), AcpiGbl_AcpiMutexInfo[i].UseCount); 501 } 502 break; 503 504 505 case CMD_SIZES: 506 507 AcpiOsPrintf ("\nInternal object sizes:\n\n"); 508 509 AcpiOsPrintf ("Common %3d\n", sizeof (ACPI_OBJECT_COMMON)); 510 AcpiOsPrintf ("Number %3d\n", sizeof (ACPI_OBJECT_INTEGER)); 511 AcpiOsPrintf ("String %3d\n", sizeof (ACPI_OBJECT_STRING)); 512 AcpiOsPrintf ("Buffer %3d\n", sizeof (ACPI_OBJECT_BUFFER)); 513 AcpiOsPrintf ("Package %3d\n", sizeof (ACPI_OBJECT_PACKAGE)); 514 AcpiOsPrintf ("BufferField %3d\n", sizeof (ACPI_OBJECT_BUFFER_FIELD)); 515 AcpiOsPrintf ("Device %3d\n", sizeof (ACPI_OBJECT_DEVICE)); 516 AcpiOsPrintf ("Event %3d\n", sizeof (ACPI_OBJECT_EVENT)); 517 AcpiOsPrintf ("Method %3d\n", sizeof (ACPI_OBJECT_METHOD)); 518 AcpiOsPrintf ("Mutex %3d\n", sizeof (ACPI_OBJECT_MUTEX)); 519 AcpiOsPrintf ("Region %3d\n", sizeof (ACPI_OBJECT_REGION)); 520 AcpiOsPrintf ("PowerResource %3d\n", sizeof (ACPI_OBJECT_POWER_RESOURCE)); 521 AcpiOsPrintf ("Processor %3d\n", sizeof (ACPI_OBJECT_PROCESSOR)); 522 AcpiOsPrintf ("ThermalZone %3d\n", sizeof (ACPI_OBJECT_THERMAL_ZONE)); 523 AcpiOsPrintf ("RegionField %3d\n", sizeof (ACPI_OBJECT_REGION_FIELD)); 524 AcpiOsPrintf ("BankField %3d\n", sizeof (ACPI_OBJECT_BANK_FIELD)); 525 AcpiOsPrintf ("IndexField %3d\n", sizeof (ACPI_OBJECT_INDEX_FIELD)); 526 AcpiOsPrintf ("Reference %3d\n", sizeof (ACPI_OBJECT_REFERENCE)); 527 AcpiOsPrintf ("NotifyHandler %3d\n", sizeof (ACPI_OBJECT_NOTIFY_HANDLER)); 528 AcpiOsPrintf ("AddrHandler %3d\n", sizeof (ACPI_OBJECT_ADDR_HANDLER)); 529 AcpiOsPrintf ("Extra %3d\n", sizeof (ACPI_OBJECT_EXTRA)); 530 AcpiOsPrintf ("Data %3d\n", sizeof (ACPI_OBJECT_DATA)); 531 532 AcpiOsPrintf ("\n"); 533 534 AcpiOsPrintf ("ParseObject %3d\n", sizeof (ACPI_PARSE_OBJECT)); 535 AcpiOsPrintf ("Parse2Object %3d\n", sizeof (ACPI_PARSE2_OBJECT)); 536 AcpiOsPrintf ("OperandObject %3d\n", sizeof (ACPI_OPERAND_OBJECT)); 537 AcpiOsPrintf ("NamespaceNode %3d\n", sizeof (ACPI_NAMESPACE_NODE)); 538 539 break; 540 541 542 case CMD_STACK: 543 544 Size = AcpiGbl_EntryStackPointer - AcpiGbl_LowestStackPointer; 545 546 AcpiOsPrintf ("\nSubsystem Stack Usage:\n\n"); 547 AcpiOsPrintf ("Entry Stack Pointer %X\n", AcpiGbl_EntryStackPointer); 548 AcpiOsPrintf ("Lowest Stack Pointer %X\n", AcpiGbl_LowestStackPointer); 549 AcpiOsPrintf ("Stack Use %X (%d)\n", Size, Size); 550 AcpiOsPrintf ("Deepest Procedure Nesting %d\n", AcpiGbl_DeepestNesting); 551 break; 552 } 553 554 AcpiOsPrintf ("\n"); 555 return (AE_OK); 556} 557 558 559#endif /* ENABLE_DEBUGGER */ 560