Module: xenomai-3
Branch: next
Commit: a39c4833603ef5b0ecda3f1fbcbbfae469ce0dec
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=a39c4833603ef5b0ecda3f1fbcbbfae469ce0dec

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Apr 21 12:48:37 2015 +0200

vxworks: add memPartInfoGet() service

maxBlockSizeFree is not reported.

---

 include/vxworks/memPartLib.h |   13 ++++++++++++
 lib/vxworks/memPartLib.c     |   45 ++++++++++++++++++++++++++++++++++++++++++
 lib/vxworks/memPartLib.h     |    2 ++
 3 files changed, 60 insertions(+)

diff --git a/include/vxworks/memPartLib.h b/include/vxworks/memPartLib.h
index 1a6ea56..139714c 100644
--- a/include/vxworks/memPartLib.h
+++ b/include/vxworks/memPartLib.h
@@ -28,6 +28,16 @@
 
 typedef uintptr_t PART_ID;
 
+struct wind_part_stats {
+       unsigned long numBytesFree;
+       unsigned long numBlocksFree;
+       unsigned long numBytesAlloc;
+       unsigned long numBlocksAlloc;
+       unsigned long maxBytesAlloc;
+};
+
+typedef struct wind_part_stats MEM_PART_STATS;
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -46,6 +56,9 @@ STATUS memPartFree(PART_ID partId, char *pBlock);
 
 void memAddToPool(char *pPool, unsigned int poolSize);
 
+STATUS memPartInfoGet(PART_ID partId,
+                     MEM_PART_STATS *ppartStats);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/vxworks/memPartLib.c b/lib/vxworks/memPartLib.c
index 77bd20c..ee9f5cc 100644
--- a/lib/vxworks/memPartLib.c
+++ b/lib/vxworks/memPartLib.c
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <memory.h>
 #include <boilerplate/lock.h>
 #include <copperplate/heapobj.h>
 #include <copperplate/init.h>
@@ -68,6 +69,9 @@ PART_ID memPartCreate(char *pPool, unsigned int poolSize)
        pthread_mutexattr_setpshared(&mattr, mutex_scope_attribute);
        __RT(pthread_mutex_init(&mp->lock, &mattr));
        pthread_mutexattr_destroy(&mattr);
+       memset(&mp->stats, 0, sizeof(mp->stats));
+       mp->stats.numBytesFree = poolSize;
+       mp->stats.numBlocksFree = 1;
        mp->magic = mempart_magic;
 
        CANCEL_RESTORE(svc);
@@ -100,6 +104,9 @@ STATUS memPartAddToPool(PART_ID partId,
        if (heapobj_extend(&mp->hobj, poolSize, pPool)) {
                errno = S_memLib_INVALID_NBYTES;
                ret = ERROR;
+       } else {
+               mp->stats.numBytesFree += poolSize;
+               mp->stats.numBlocksFree++;
        }
 
        __RT(pthread_mutex_unlock(&mp->lock));
@@ -148,7 +155,16 @@ void *memPartAlloc(PART_ID partId, unsigned int nBytes)
                return NULL;
 
        __RT(pthread_mutex_lock(&mp->lock));
+
        p = heapobj_alloc(&mp->hobj, nBytes);
+
+       mp->stats.numBytesAlloc += nBytes;
+       mp->stats.numBlocksAlloc++;
+       mp->stats.numBytesFree -= nBytes;
+       mp->stats.numBlocksFree--;
+       if (mp->stats.numBytesAlloc > mp->stats.maxBytesAlloc)
+               mp->stats.maxBytesAlloc = mp->stats.numBytesAlloc;
+
        __RT(pthread_mutex_unlock(&mp->lock));
 
        return p;
@@ -158,6 +174,7 @@ STATUS memPartFree(PART_ID partId, char *pBlock)
 {
        struct wind_mempart *mp;
        struct service svc;
+       size_t size;
 
        if (pBlock == NULL)
                return ERROR;
@@ -169,7 +186,15 @@ STATUS memPartFree(PART_ID partId, char *pBlock)
        CANCEL_DEFER(svc);
 
        __RT(pthread_mutex_lock(&mp->lock));
+
        heapobj_free(&mp->hobj, pBlock);
+
+       size = heapobj_validate(&mp->hobj, pBlock);
+       mp->stats.numBytesAlloc -= size;
+       mp->stats.numBlocksAlloc--;
+       mp->stats.numBytesFree += size;
+       mp->stats.numBlocksFree++;
+       
        __RT(pthread_mutex_unlock(&mp->lock));
 
        CANCEL_RESTORE(svc);
@@ -189,3 +214,23 @@ void memAddToPool(char *pPool, unsigned int poolSize)
         */
        warning("%s: extending the main partition is useless", __FUNCTION__);
 }
+
+STATUS memPartInfoGet(PART_ID partId, MEM_PART_STATS *ppartStats)
+{
+       struct wind_mempart *mp;
+       struct service svc;
+
+       mp = find_mempart_from_id(partId);
+       if (mp == NULL)
+               return ERROR;
+
+       CANCEL_DEFER(svc);
+
+       __RT(pthread_mutex_lock(&mp->lock));
+       *ppartStats = mp->stats;
+       __RT(pthread_mutex_unlock(&mp->lock));
+
+       CANCEL_RESTORE(svc);
+
+       return OK;
+}
diff --git a/lib/vxworks/memPartLib.h b/lib/vxworks/memPartLib.h
index 1f7e50a..f2cd00a 100644
--- a/lib/vxworks/memPartLib.h
+++ b/lib/vxworks/memPartLib.h
@@ -20,11 +20,13 @@
 #define _VXWORKS_MEMPARTLIB_H
 
 #include <copperplate/heapobj.h>
+#include <vxworks/memPartLib.h>
 
 struct wind_mempart {
        unsigned int magic;
        struct heapobj hobj;
        pthread_mutex_t lock;
+       struct wind_part_stats stats;
 };
 
 #endif /* _VXWORKS_MEMPARTLIB_H */


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to