Add ACPI_DEBUG_CACHE debug option to module build of acpi driver
authorYONETANI Tomokazu <y0netan1@dragonflybsd.org>
Mon, 26 Mar 2007 02:34:39 +0000 (02:34 +0000)
committerYONETANI Tomokazu <y0netan1@dragonflybsd.org>
Mon, 26 Mar 2007 02:34:39 +0000 (02:34 +0000)
to catch the current and the first caller of AcpiOsReleaseObject().

sys/dev/acpica5/Makefile
sys/dev/acpica5/Osd/OsdCache.c
sys/dev/acpica5/include,acpiosxf.h.patch

index 4f61286..29bf709 100644 (file)
@@ -1,5 +1,5 @@
 # $FreeBSD: src/sys/modules/acpi/acpi/Makefile,v 1.3 2004/01/08 16:38:32 njl Exp $
-# $DragonFly: src/sys/dev/acpica5/Makefile,v 1.19 2007/01/25 15:12:06 y0netan1 Exp $
+# $DragonFly: src/sys/dev/acpica5/Makefile,v 1.20 2007/03/26 02:34:39 y0netan1 Exp $
 
 CONTRIBDIR=    ${SYSDIR}/${ACPICA_DIR}
 # patches to fix problems in ACPI-CA code
@@ -8,7 +8,7 @@ PATCHES=        hardware,hwsleep.c.patch tables,tbxface.c.patch
 PATCHES+=      include,acglobal.h.patch debugger,dbstats.c.patch
 
 SYSDIR?= ${.CURDIR}/../..
-.if ACPI_DEBUG_LOCKS || ACPI_DEBUG_MEMMAP
+.if ACPI_DEBUG_LOCKS || ACPI_DEBUG_MEMMAP || ACPI_DEBUG_CACHE
 CFLAGS+=       -I${.OBJDIR}/include
 .if ACPI_DEBUG_LOCKS
 CFLAGS+=       -DACPI_DEBUG_LOCKS=1
@@ -16,6 +16,9 @@ CFLAGS+=      -DACPI_DEBUG_LOCKS=1
 .if ACPI_DEBUG_MEMMAP
 CFLAGS+=       -DACPI_DEBUG_MEMMAP=1
 .endif
+.if ACPI_DEBUG_CACHE
+CFLAGS+=       -DACPI_DEBUG_CACHE=1
+.endif
 PATCHES+=      include,acpiosxf.h.patch
 .endif
 
index 4e03de4..b11258e 100644 (file)
@@ -29,7 +29,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $DragonFly: src/sys/dev/acpica5/Osd/OsdCache.c,v 1.3 2007/03/20 00:56:30 dillon Exp $
+ * $DragonFly: src/sys/dev/acpica5/Osd/OsdCache.c,v 1.4 2007/03/26 02:34:39 y0netan1 Exp $
  */
 
 #include <sys/objcache.h>
@@ -45,6 +45,9 @@ struct acpicache {
  */
 struct acpiobjhead {
        int state;
+       void *cache;
+       const char *func;
+       int line;
        int unused;
 };
 
@@ -94,28 +97,53 @@ void *
 AcpiOsAcquireObject(ACPI_CACHE_T *Cache)
 {
        struct acpiobjhead *head;
-       void *Object;
 
        head = objcache_get(Cache->cache, M_WAITOK);
        bzero(head, Cache->args.objsize);
        head->state = TRACK_ALLOCATED;
+#if ACPI_DEBUG_CACHE
+       head->cache = Cache;
+       head->func = "nowhere";
+       head->line = 0;
+#endif
        return (head + 1);
 }
 
 ACPI_STATUS
+#if ACPI_DEBUG_CACHE
+_AcpiOsReleaseObject(ACPI_CACHE_T *Cache, void *Object,
+ const char *func, int line)
+#else
 AcpiOsReleaseObject(ACPI_CACHE_T *Cache, void *Object)
+#endif
 {
        struct acpiobjhead *head = (void *)((char *)Object - OBJHEADSIZE);
 
+#if ACPI_DEBUG_CACHE
+       if (head->cache != Cache) {
+               kprintf("%s: object %p belongs to %p, not %p\n",
+                       __func__, Object, head->cache, Cache);
+       }
+#endif
        if (head->state != TRACK_ALLOCATED) {
-               if (head->state == TRACK_FREED)
-                       kprintf("AcpiOsReleaseObject: Double Free %p (%08x)\n", Object, head->state);
-               else
-                       kprintf("AcpiOsReleaseObject: Bad object %p (%08x)\n", Object, head->state);
+               if (head->state == TRACK_FREED) {
+#if ACPI_DEBUG_CACHE
+                       kprintf("%s: Double Free %p, %s:%d, first %s:%d\n",
+                               __func__, Object, func, line, head->func,
+                               head->line);
+#else
+                       kprintf("%s: Double Free %p\n", __func__, Object);
+#endif
+               } else
+                       kprintf("AcpiOsReleaseObject: Bad object %p (%08x)\n",
+                               Object, head->state);
                return AE_OK;
        }
        head->state = TRACK_FREED;
-
+#if ACPI_DEBUG_CACHE
+       head->func = func;
+       head->line = line;
+#endif
        objcache_put(Cache->cache, head);
        return AE_OK;
 }
index c582225..f09d8da 100644 (file)
@@ -1,28 +1,27 @@
-# $DragonFly: src/sys/dev/acpica5/include,acpiosxf.h.patch,v 1.1 2007/01/17 17:31:19 y0netan1 Exp $
+# $DragonFly: src/sys/dev/acpica5/include,acpiosxf.h.patch,v 1.2 2007/03/26 02:34:39 y0netan1 Exp $
 
 --- acpiosxf.h.orig    2006-11-30 05:58:15.000000000 +0900
-+++ acpiosxf.h 2006-11-30 06:02:56.000000000 +0900
-@@ -197,9 +197,18 @@
++++ acpiosxf.h 2007-03-11 14:39:09.000000000 +0900
+@@ -197,9 +197,18 @@ void
  AcpiOsDeleteLock (
      ACPI_SPINLOCK           Handle);
  
 +#if ACPI_DEBUG_LOCKS
 +#define AcpiOsAcquireLock(Handle) \
 +_AcpiOsAcquireLock(Handle, __func__, __LINE__)
- ACPI_CPU_FLAGS
--AcpiOsAcquireLock (
++ACPI_CPU_FLAGS
 +_AcpiOsAcquireLock (
 +    ACPI_SPINLOCK           Handle,
 +    const char *func, int line);
 +#else
-+ACPI_CPU_FLAGS
-+AcpiOsAcquireLock (
+ ACPI_CPU_FLAGS
+ AcpiOsAcquireLock (
      ACPI_SPINLOCK           Handle);
 +#endif
  
  void
  AcpiOsReleaseLock (
-@@ -271,6 +280,24 @@
+@@ -271,6 +280,24 @@ void
  AcpiOsFree (
      void *                  Memory);
  
@@ -47,7 +46,7 @@
  void *
  AcpiOsMapMemory (
      ACPI_PHYSICAL_ADDRESS   Where,
-@@ -280,6 +307,7 @@
+@@ -280,6 +307,7 @@ void
  AcpiOsUnmapMemory (
      void                    *LogicalAddress,
      ACPI_SIZE               Size);
  
  ACPI_STATUS
  AcpiOsGetPhysicalAddress (
+@@ -309,10 +337,21 @@ void *
+ AcpiOsAcquireObject (
+     ACPI_CACHE_T            *Cache);
++#if ACPI_DEBUG_CACHE
++#define AcpiOsReleaseObject(Cache, Object) \
++_AcpiOsReleaseObject(Cache, Object, __func__, __LINE__)
++ACPI_STATUS
++_AcpiOsReleaseObject (
++    ACPI_CACHE_T            *Cache,
++    void                    *Object,
++    const char                    *func,
++    int                           line);
++#else
+ ACPI_STATUS
+ AcpiOsReleaseObject (
+     ACPI_CACHE_T            *Cache,
+     void                    *Object);
++#endif
+ /*