[ioctl] apply memory status ioctl() for trinity devices
authorDongju Chae <dongju.chae@samsung.com>
Thu, 11 Jun 2020 05:36:40 +0000 (14:36 +0900)
committer송욱/On-Device Lab(SR)/Staff Engineer/삼성전자 <wook16.song@samsung.com>
Wed, 17 Jun 2020 04:41:24 +0000 (13:41 +0900)
This patch applies memory status ioctl() for trinity devices

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
src/core/npu/NPUdrvAPI.h
src/core/npu/NPUdrvAPI_triv.cc
src/core/npu/NPUdrvAPI_triv2.cc

index 09b9190..371e635 100644 (file)
@@ -114,6 +114,7 @@ class TrinityVisionAPI : public DriverAPI {
 
     int alloc (size_t size) const;
     int dealloc (int dmabuf) const;
+    int getMemoryStatus (size_t *alloc, size_t *free) const;
 
     void *mmap (int dmabuf, size_t size) const;
     int munmap (void *addr, size_t size) const;
@@ -144,6 +145,7 @@ class TrinityVision2API : public DriverAPI {
 
     int alloc (size_t size) const;
     int dealloc (int dmabuf) const;
+    int getMemoryStatus (size_t *alloc, size_t *free) const;
 
     void *mmap (int dmabuf, size_t size) const;
     int munmap (void *addr, size_t size) const;
index 068b302..e478b85 100644 (file)
@@ -170,7 +170,7 @@ TrinityVisionAPI::dealloc (int dmabuf) const
   if (!this->initialized())
     return -EPERM;
 
-  ret= ioctl (this->getDeviceFD (), TRINITY_IOCTL_HWMEM_DEALLOC, &dmabuf);
+  ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_HWMEM_DEALLOC, &dmabuf);
   if (ret < 0)
     return -errno;
 
@@ -178,6 +178,34 @@ TrinityVisionAPI::dealloc (int dmabuf) const
 }
 
 /**
+ * @brief get the current memory status
+ * @param[out] alloc_total The size of allocated memory until now
+ * @param[out] free_total The size of freed memory until now
+ * @return 0 if no error. otherwise a negatice error value
+ */
+int
+TrinityVisionAPI::getMemoryStatus (size_t *alloc_total, size_t *free_total) const
+{
+  struct trinity_memory_stat stat;
+  int ret;
+
+  if (!initialized())
+    return -EPERM;
+
+  if (alloc_total == nullptr || free_total == nullptr)
+    return -EINVAL;
+
+  ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_MEMORY_STATUS, &stat);
+  if (ret < 0)
+    return -errno;
+
+  *alloc_total = stat.total_alloc_mem;
+  *free_total = stat.total_freed_mem;
+
+  return 0;
+}
+
+/**
  * @brief do mmap() for the dmabuf fd
  * @param[in] dmabuf dmabuf fd
  * @param[in] size size to be mmapped
index 3c0974a..a1b94e4 100644 (file)
@@ -169,7 +169,7 @@ TrinityVision2API::dealloc (int dmabuf) const
   if (!this->initialized())
     return -EPERM;
 
-  ret= ioctl (this->getDeviceFD (), TRINITY_IOCTL_HWMEM_DEALLOC, &dmabuf);
+  ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_HWMEM_DEALLOC, &dmabuf);
   if (ret < 0)
     return -errno;
 
@@ -177,6 +177,34 @@ TrinityVision2API::dealloc (int dmabuf) const
 }
 
 /**
+ * @brief get the current memory status
+ * @param[out] alloc_total The size of allocated memory until now
+ * @param[out] free_total The size of freed memory until now
+ * @return 0 if no error. otherwise a negatice error value
+ */
+int
+TrinityVision2API::getMemoryStatus (size_t *alloc_total, size_t *free_total) const
+{
+  struct trinity_memory_stat stat;
+  int ret;
+
+  if (!initialized())
+    return -EPERM;
+
+  if (alloc_total == nullptr || free_total == nullptr)
+    return -EINVAL;
+
+  ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_MEMORY_STATUS, &stat);
+  if (ret < 0)
+    return -errno;
+
+  *alloc_total = stat.total_alloc_mem;
+  *free_total = stat.total_freed_mem;
+
+  return 0;
+}
+
+/**
  * @brief do mmap() for the dmabuf fd
  * @param[in] dmabuf dmabuf fd
  * @param[in] size size to be mmapped