Skip to contentSkip to conversation

ACPICA: Remove use of caches in controlled way

PATCH New Alexey Starikovskiy 1 participant 2 messages May 18, 2010 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ACPICA: Remove use of caches in controlled way

---

 source/components/utilities/utcache.c |   99 +++++----------------------------
 1 files changed, 14 insertions(+), 85 deletions(-)
source/components/utilities/utcache.c +14 -85
index 2cee9a1..bdc3ac9 100644
@@ -287,49 +287,15 @@ AcpiOsReleaseObject (
     ACPI_MEMORY_LIST        *Cache,
     void                    *Object)
 {
-    ACPI_STATUS             Status;
-
-
     ACPI_FUNCTION_ENTRY ();
 
-
     if (!Cache || !Object)
     {
         return (AE_BAD_PARAMETER);
     }
 
-    /* If cache is full, just free this object */
-
-    if (Cache->CurrentDepth >= Cache->MaxDepth)
-    {
-        ACPI_FREE (Object);
-        ACPI_MEM_TRACKING (Cache->TotalFreed++);
-    }
-
-    /* Otherwise put this object back into the cache */
-
-    else
-    {
-        Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
-        if (ACPI_FAILURE (Status))
-        {
-            return (Status);
-        }
-
-        /* Mark the object as cached */
-
-        ACPI_MEMSET (Object, 0xCA, Cache->ObjectSize);
-        ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_CACHED);
-
-        /* Put the object at the head of the cache list */
-
-        * (ACPI_CAST_INDIRECT_PTR (char,
-            &(((char *) Object)[Cache->LinkOffset]))) = Cache->ListHead;
-        Cache->ListHead = Object;
-        Cache->CurrentDepth++;
-
-        (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
-    }
+    ACPI_FREE (Object);
+    ACPI_MEM_TRACKING (Cache->TotalFreed++);
 
     return (AE_OK);
 }
@@ -353,8 +319,6 @@ AcpiOsAcquireObject (
     ACPI_MEMORY_LIST        *Cache)
 {
     ACPI_STATUS             Status;
-    void                    *Object;
-
 
     ACPI_FUNCTION_NAME (OsAcquireObject);
 
@@ -372,61 +336,26 @@ AcpiOsAcquireObject (
 
     ACPI_MEM_TRACKING (Cache->Requests++);
 
-    /* Check the cache first */
+    /* The cache is empty, create a new object */
 
-    if (Cache->ListHead)
-    {
-        /* There is an object available, use it */
-
-        Object = Cache->ListHead;
-        Cache->ListHead = *(ACPI_CAST_INDIRECT_PTR (char,
-                                &(((char *) Object)[Cache->LinkOffset])));
-
-        Cache->CurrentDepth--;
-
-        ACPI_MEM_TRACKING (Cache->Hits++);
-        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-            "Object %p from %s cache\n", Object, Cache->ListName));
-
-        Status = AcpiUtReleaseMutex (ACPI_MTX_CACHES);
-        if (ACPI_FAILURE (Status))
-        {
-            return (NULL);
-        }
-
-        /* Clear (zero) the previously used Object */
-
-        ACPI_MEMSET (Object, 0, Cache->ObjectSize);
-    }
-    else
-    {
-        /* The cache is empty, create a new object */
-
-        ACPI_MEM_TRACKING (Cache->TotalAllocated++);
+    ACPI_MEM_TRACKING (Cache->TotalAllocated++);
 
 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
-        if ((Cache->TotalAllocated - Cache->TotalFreed) > Cache->MaxOccupied)
-        {
-            Cache->MaxOccupied = Cache->TotalAllocated - Cache->TotalFreed;
-        }
+    if ((Cache->TotalAllocated - Cache->TotalFreed) > Cache->MaxOccupied)
+    {
+        Cache->MaxOccupied = Cache->TotalAllocated - Cache->TotalFreed;
+    }
 #endif
 
-        /* Avoid deadlock with ACPI_ALLOCATE_ZEROED */
+    /* Avoid deadlock with ACPI_ALLOCATE_ZEROED */
 
-        Status = AcpiUtReleaseMutex (ACPI_MTX_CACHES);
-        if (ACPI_FAILURE (Status))
-        {
-            return (NULL);
-        }
-
-        Object = ACPI_ALLOCATE_ZEROED (Cache->ObjectSize);
-        if (!Object)
-        {
-            return (NULL);
-        }
+    Status = AcpiUtReleaseMutex (ACPI_MTX_CACHES);
+    if (ACPI_FAILURE (Status))
+    {
+        return (NULL);
     }
 
-    return (Object);
+    return ACPI_ALLOCATE_ZEROED (Cache->ObjectSize);
 }
 #endif /* ACPI_USE_LOCAL_CACHE */
 
#1 lore raw

PATCH 2/2 ACPICA: Remove cache code

---

 source/components/debugger/dbexec.c    |   73 ------
 source/components/debugger/dbstats.c   |   38 ---
 source/components/namespace/nsalloc.c  |    7 -
 source/components/parser/psutils.c     |    8 -
 source/components/utilities/utalloc.c  |   61 -----
 source/components/utilities/utcache.c  |  362 --------------------------------
 source/components/utilities/utobject.c |    4 
 source/components/utilities/utstate.c  |    4 
 source/components/utilities/utxface.c  |   35 ---
 source/include/acconfig.h              |    8 -
 source/include/acglobal.h              |    8 -
 source/include/acobject.h              |   12 -
 source/include/acpiosxf.h              |   29 ---
 source/include/actypes.h               |   10 -
 source/include/platform/acenv.h        |    7 -
 source/include/platform/aclinux.h      |    1 
 source/include/platform/acos2.h        |    1 
 source/tools/acpisrc/astable.c         |    2 
 18 files changed, 13 insertions(+), 657 deletions(-)
 delete mode 100644 source/components/utilities/utcache.c
source/components/debugger/dbexec.c +0 -73
index da21a12..3d4632d 100644
@@ -138,10 +138,6 @@ static void
 AcpiDbExecuteSetup (
     ACPI_DB_METHOD_INFO     *Info);
 
-static UINT32
-AcpiDbGetOutstandingAllocations (
-    void);
-
 static void ACPI_SYSTEM_XFACE
 AcpiDbMethodThread (
     void                    *Context);
@@ -320,48 +316,6 @@ AcpiDbExecuteSetup (
 }
 
 
-#ifdef ACPI_DBG_TRACK_ALLOCATIONS
-UINT32
-AcpiDbGetCacheInfo (
-    ACPI_MEMORY_LIST        *Cache)
-{
-
-    return (Cache->TotalAllocated - Cache->TotalFreed - Cache->CurrentDepth);
-}
-#endif
-
-/*******************************************************************************
- *
- * FUNCTION:    AcpiDbGetOutstandingAllocations
- *
- * PARAMETERS:  None
- *
- * RETURN:      Current global allocation count minus cache entries
- *
- * DESCRIPTION: Determine the current number of "outstanding" allocations --
- *              those allocations that have not been freed and also are not
- *              in one of the various object caches.
- *
- ******************************************************************************/
-
-static UINT32
-AcpiDbGetOutstandingAllocations (
-    void)
-{
-    UINT32                  Outstanding = 0;
-
-#ifdef ACPI_DBG_TRACK_ALLOCATIONS
-
-    Outstanding += AcpiDbGetCacheInfo (AcpiGbl_StateCache);
-    Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeCache);
-    Outstanding += AcpiDbGetCacheInfo (AcpiGbl_PsNodeExtCache);
-    Outstanding += AcpiDbGetCacheInfo (AcpiGbl_OperandCache);
-#endif
-
-    return (Outstanding);
-}
-
-
 /*******************************************************************************
  *
  * FUNCTION:    AcpiDbExecutionWalk
@@ -439,17 +393,6 @@ AcpiDbExecute (
     ACPI_BUFFER             ReturnObj;
     char                    *NameString;
 
-
-#ifdef ACPI_DEBUG_OUTPUT
-    UINT32                  PreviousAllocations;
-    UINT32                  Allocations;
-
-
-    /* Memory allocation tracking */
-
-    PreviousAllocations = AcpiDbGetOutstandingAllocations ();
-#endif
-
     if (*Name == '*')
     {
         (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
@@ -486,22 +429,6 @@ AcpiDbExecute (
      */
     AcpiOsSleep ((UINT64) 10);
 
-
-#ifdef ACPI_DEBUG_OUTPUT
-
-    /* Memory allocation tracking */
-
-    Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations;
-
-    AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
-
-    if (Allocations > 0)
-    {
-        AcpiOsPrintf ("Outstanding: 0x%X allocations after execution\n",
-                        Allocations);
-    }
-#endif
-
     if (ACPI_FAILURE (Status))
     {
         AcpiOsPrintf ("Execution of %s failed with status %s\n",
source/components/debugger/dbstats.c +0 -38
index ace8263..4039a4f 100644
@@ -189,9 +189,6 @@ static void
 AcpiDbListInfo (
     ACPI_MEMORY_LIST        *List)
 {
-#ifdef ACPI_DBG_TRACK_ALLOCATIONS
-    UINT32                  Outstanding;
-#endif
 
     AcpiOsPrintf ("\n%s\n", List->ListName);
 
@@ -207,41 +204,6 @@ AcpiDbListInfo (
             (List->CurrentDepth * List->ObjectSize));
     }
 
-#ifdef ACPI_DBG_TRACK_ALLOCATIONS
-    if (List->MaxDepth > 0)
-    {
-        AcpiOsPrintf (
-            "    Cache: [Requests Hits Misses ObjSize]             %8.2X %8.2X %8.2X %8.2X\n",
-            List->Requests,
-            List->Hits,
-            List->Requests - List->Hits,
-            List->ObjectSize);
-    }
-
-    Outstanding = AcpiDbGetCacheInfo (List);
-
-    if (List->ObjectSize)
-    {
-        AcpiOsPrintf (
-            "    Mem:   [Alloc    Free Max    CurSize Outstanding] %8.2X %8.2X %8.2X %8.2X %8.2X\n",
-            List->TotalAllocated,
-            List->TotalFreed,
-            List->MaxOccupied,
-            Outstanding * List->ObjectSize,
-            Outstanding);
-    }
-    else
-    {
-        AcpiOsPrintf (
-            "    Mem:   [Alloc Free Max CurSize Outstanding Total] %8.2X %8.2X %8.2X %8.2X %8.2X %8.2X\n",
-            List->TotalAllocated,
-            List->TotalFreed,
-            List->MaxOccupied,
-            List->CurrentTotalSize,
-            Outstanding,
-            List->TotalSize);
-    }
-#endif
 }
 #endif
 
source/components/namespace/nsalloc.c +4 -3
index 42a5f71..1088967 100644
@@ -150,7 +150,7 @@ AcpiNsCreateNode (
     ACPI_FUNCTION_TRACE (NsCreateNode);
 
 
-    Node = AcpiOsAcquireObject (AcpiGbl_NamespaceCache);
+    Node = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_NAMESPACE_NODE));
     if (!Node)
     {
         return_PTR (NULL);
@@ -223,7 +223,7 @@ AcpiNsDeleteNode (
 
     /* Now we can delete the node */
 
-    (void) AcpiOsReleaseObject (AcpiGbl_NamespaceCache, Node);
+    ACPI_FREE(Node);
 
     ACPI_MEM_TRACKING (AcpiGbl_NsNodeList->TotalFreed++);
     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Node %p, Remaining %X\n",
@@ -282,7 +282,8 @@ AcpiNsRemoveNode (
 
     /* Delete the node and any attached objects */
 
-    AcpiNsDeleteNode (Node);
+    AcpiNsDetachObject (Node);
+    ACPI_FREE (Node);
     return_VOID;
 }
 
source/components/parser/psutils.c +4 -4
index 17be364..2fa58c1 100644
@@ -232,13 +232,13 @@ AcpiPsAllocOp (
     {
         /* The generic op (default) is by far the most common (16 to 1) */
 
-        Op = AcpiOsAcquireObject (AcpiGbl_PsNodeCache);
+        Op = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PARSE_OBJ_COMMON));
     }
     else
     {
         /* Extended parseop */
 
-        Op = AcpiOsAcquireObject (AcpiGbl_PsNodeExtCache);
+        Op = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PARSE_OBJ_NAMED));
     }
 
     /* Initialize the Op */
@@ -280,11 +280,11 @@ AcpiPsFreeOp (
 
     if (Op->Common.Flags & ACPI_PARSEOP_GENERIC)
     {
-        (void) AcpiOsReleaseObject (AcpiGbl_PsNodeCache, Op);
+        ACPI_FREE (Op);
     }
     else
     {
-        (void) AcpiOsReleaseObject (AcpiGbl_PsNodeExtCache, Op);
+        ACPI_FREE (Op);
     }
 }
 
source/components/utilities/utalloc.c +1 -60

74 lines not on this page · raw message

source/components/utilities/utcache.c deleted +0 -362

362 lines not on this page · raw message

source/components/utilities/utobject.c +2 -2
index 0a9f1e7..fcc0674 100644
@@ -506,7 +506,7 @@ AcpiUtAllocateObjectDescDbg (
     ACPI_FUNCTION_TRACE (UtAllocateObjectDescDbg);
 
 
-    Object = AcpiOsAcquireObject (AcpiGbl_OperandCache);
+    Object = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_OPERAND_OBJECT));
     if (!Object)
     {
         ACPI_ERROR ((ModuleName, LineNumber,
@@ -555,7 +555,7 @@ AcpiUtDeleteObjectDesc (
         return_VOID;
     }
 
-    (void) AcpiOsReleaseObject (AcpiGbl_OperandCache, Object);
+    ACPI_FREE (Object);
     return_VOID;
 }
 
source/components/utilities/utstate.c +2 -2
index 08218d1..f9ab1a6 100644
@@ -250,7 +250,7 @@ AcpiUtCreateGenericState (
     ACPI_FUNCTION_ENTRY ();
 
 
-    State = AcpiOsAcquireObject (AcpiGbl_StateCache);
+    State = ACPI_ALLOCATE_ZEROED (sizeof(ACPI_GENERIC_STATE));
     if (State)
     {
         /* Initialize */
@@ -462,7 +462,7 @@ AcpiUtDeleteGenericState (
 
     if (State)
     {
-        (void) AcpiOsReleaseObject (AcpiGbl_StateCache, State);
+        ACPI_FREE (State);
     }
     return_VOID;
 }
source/components/utilities/utxface.c +0 -35
index f59a08d..29607b6 100644
@@ -423,13 +423,6 @@ AcpiInitializeObjects (
         }
     }
 
-    /*
-     * Empty the caches (delete the cached objects) on the assumption that
-     * the table load filled them up more than they will be at runtime --
-     * thus wasting non-paged memory.
-     */
-    Status = AcpiPurgeCachedObjects ();
-
     AcpiGbl_StartupFlags |= ACPI_INITIALIZED_OK;
     return_ACPI_STATUS (Status);
 }
@@ -702,33 +695,5 @@ AcpiInstallInitializationHandler (
 
 ACPI_EXPORT_SYMBOL (AcpiInstallInitializationHandler)
 
-
-/*****************************************************************************
- *
- * FUNCTION:    AcpiPurgeCachedObjects
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Empty all caches (delete the cached objects)
- *
- ****************************************************************************/
-
-ACPI_STATUS
-AcpiPurgeCachedObjects (
-    void)
-{
-    ACPI_FUNCTION_TRACE (AcpiPurgeCachedObjects);
-
-    (void) AcpiOsPurgeCache (AcpiGbl_StateCache);
-    (void) AcpiOsPurgeCache (AcpiGbl_OperandCache);
-    (void) AcpiOsPurgeCache (AcpiGbl_PsNodeCache);
-    (void) AcpiOsPurgeCache (AcpiGbl_PsNodeExtCache);
-    return_ACPI_STATUS (AE_OK);
-}
-
-ACPI_EXPORT_SYMBOL (AcpiPurgeCachedObjects)
-
 #endif /* ACPI_ASL_COMPILER */
 
source/include/acconfig.h +0 -8
index 9417b44..479a944 100644
@@ -144,14 +144,6 @@
  */
 #define ACPI_OS_NAME                    "Microsoft Windows NT"
 
-/* Maximum objects in the various object caches */
-
-#define ACPI_MAX_STATE_CACHE_DEPTH      96          /* State objects */
-#define ACPI_MAX_PARSE_CACHE_DEPTH      96          /* Parse tree objects */
-#define ACPI_MAX_EXTPARSE_CACHE_DEPTH   96          /* Parse tree objects */
-#define ACPI_MAX_OBJECT_CACHE_DEPTH     96          /* Interpreter operand objects */
-#define ACPI_MAX_NAMESPACE_CACHE_DEPTH  96          /* Namespace objects */
-
 /*
  * Should the subsystem abort the loading of an ACPI table if the
  * table checksum is incorrect?
source/include/acglobal.h +0 -8
index e0f8871..1fd49d2 100644
@@ -286,14 +286,6 @@ ACPI_EXTERN ACPI_RW_LOCK                AcpiGbl_NamespaceRwLock;
  *
  ****************************************************************************/
 
-/* Object caches */
-
-ACPI_EXTERN ACPI_CACHE_T               *AcpiGbl_NamespaceCache;
-ACPI_EXTERN ACPI_CACHE_T               *AcpiGbl_StateCache;
-ACPI_EXTERN ACPI_CACHE_T               *AcpiGbl_PsNodeCache;
-ACPI_EXTERN ACPI_CACHE_T               *AcpiGbl_PsNodeExtCache;
-ACPI_EXTERN ACPI_CACHE_T               *AcpiGbl_OperandCache;
-
 /* Global handlers */
 
 ACPI_EXTERN ACPI_OBJECT_NOTIFY_HANDLER  AcpiGbl_DeviceNotify;
source/include/acobject.h +0 -12
index 21c3706..101885d 100644
@@ -546,17 +546,6 @@ typedef struct acpi_object_data
 
 } ACPI_OBJECT_DATA;
 
-
-/* Structure used when objects are cached for reuse */
-
-typedef struct acpi_object_cache_list
-{
-    ACPI_OBJECT_COMMON_HEADER
-    union acpi_operand_object       *Next;              /* Link for object cache and internal lists*/
-
-} ACPI_OBJECT_CACHE_LIST;
-
-
 /******************************************************************************
  *
  * ACPI_OPERAND_OBJECT Descriptor - a giant union of all of the above
@@ -589,7 +578,6 @@ typedef union acpi_operand_object
     ACPI_OBJECT_REFERENCE               Reference;
     ACPI_OBJECT_EXTRA                   Extra;
     ACPI_OBJECT_DATA                    Data;
-    ACPI_OBJECT_CACHE_LIST              Cache;
 
     /*
      * Add namespace node to union in order to simplify code that accepts both
source/include/acpiosxf.h +0 -29
index 3a9da6c..4d2a554 100644
@@ -283,35 +283,6 @@ AcpiOsGetPhysicalAddress (
     void                    *LogicalAddress,
     ACPI_PHYSICAL_ADDRESS   *PhysicalAddress);
 
-
-/*
- * Memory/Object Cache
- */
-ACPI_STATUS
-AcpiOsCreateCache (
-    char                    *CacheName,
-    UINT16                  ObjectSize,
-    UINT16                  MaxDepth,
-    ACPI_CACHE_T            **ReturnCache);
-
-ACPI_STATUS
-AcpiOsDeleteCache (
-    ACPI_CACHE_T            *Cache);
-
-ACPI_STATUS
-AcpiOsPurgeCache (
-    ACPI_CACHE_T            *Cache);
-
-void *
-AcpiOsAcquireObject (
-    ACPI_CACHE_T            *Cache);
-
-ACPI_STATUS
-AcpiOsReleaseObject (
-    ACPI_CACHE_T            *Cache,
-    void                    *Object);
-
-
 /*
  * Interrupt handlers
  */
source/include/actypes.h +0 -10
index 601e87e..dbab6d2 100644
@@ -298,16 +298,6 @@ typedef UINT32                          ACPI_PHYSICAL_ADDRESS;
 #define ACPI_CPU_FLAGS                  ACPI_SIZE
 #endif
 
-/* Object returned from AcpiOsCreateCache */
-
-#ifndef ACPI_CACHE_T
-#ifdef ACPI_USE_LOCAL_CACHE
-#define ACPI_CACHE_T                    ACPI_MEMORY_LIST
-#else
-#define ACPI_CACHE_T                    void *
-#endif
-#endif
-
 /*
  * Synchronization objects - Mutexes, Semaphores, and SpinLocks
  */
source/include/platform/acenv.h +0 -7
index 0567a00..398d764 100644
@@ -159,17 +159,10 @@
 #define ACPI_DBG_TRACK_ALLOCATIONS
 #endif
 
-/* Linkable ACPICA library */
-
-#ifdef ACPI_LIBRARY
-#define ACPI_USE_LOCAL_CACHE
-#endif
-
 /* Common for all ACPICA applications */
 
 #ifdef ACPI_APPLICATION
 #define ACPI_USE_SYSTEM_CLIBRARY
-#define ACPI_USE_LOCAL_CACHE
 #endif
 
 /* Common debug support */
source/include/platform/aclinux.h +0 -1
index 9009689..1c1336b 100644
@@ -144,7 +144,6 @@
 #define ACPI_EXPORT_SYMBOL(symbol)  EXPORT_SYMBOL(symbol);
 #define strtoul                     simple_strtoul
 
-#define ACPI_CACHE_T                struct kmem_cache
 #define ACPI_SPINLOCK               spinlock_t *
 #define ACPI_CPU_FLAGS              unsigned long
 #define ACPI_THREAD_ID              struct task_struct *
source/include/platform/acos2.h +0 -1
index 90e6b2e..86fcb0c 100644
@@ -165,7 +165,6 @@ unsigned short OSPMReleaseGlobalLock (void *);
 #endif
 
 #ifndef ACPI_ASL_COMPILER
-#define ACPI_USE_LOCAL_CACHE
 #undef ACPI_DEBUGGER
 #endif
 
source/tools/acpisrc/astable.c +0 -2
index 5a96f06..ee37a03 100644
@@ -253,7 +253,6 @@ ACPI_TYPED_IDENTIFIER_TABLE           AcpiIdentifiers[] = {
     {"ACPI_BIT_REGISTER_INFO",              SRC_TYPE_STRUCT},
     {"ACPI_BUFFER",                         SRC_TYPE_STRUCT},
     {"ACPI_BUS_ATTRIBUTE",                  SRC_TYPE_STRUCT},
-    {"ACPI_CACHE_T",                        SRC_TYPE_SIMPLE},
     {"ACPI_COMMON_FACS",                    SRC_TYPE_STRUCT},
     {"ACPI_COMMON_STATE",                   SRC_TYPE_STRUCT},
     {"ACPI_COMMON_DESCRIPTOR",              SRC_TYPE_STRUCT},
@@ -335,7 +334,6 @@ ACPI_TYPED_IDENTIFIER_TABLE           AcpiIdentifiers[] = {
     {"ACPI_OBJECT_BANK_FIELD",              SRC_TYPE_STRUCT},
     {"ACPI_OBJECT_BUFFER",                  SRC_TYPE_STRUCT},
     {"ACPI_OBJECT_BUFFER_FIELD",            SRC_TYPE_STRUCT},
-    {"ACPI_OBJECT_CACHE_LIST",              SRC_TYPE_STRUCT},
     {"ACPI_OBJECT_COMMON",                  SRC_TYPE_STRUCT},
     {"ACPI_OBJECT_DATA",                    SRC_TYPE_STRUCT},
     {"ACPI_OBJECT_DEVICE",                  SRC_TYPE_STRUCT},