[profile] add memory info
authorYelin Jeong <yelini.jeong@samsung.com>
Tue, 20 Jun 2023 12:40:34 +0000 (21:40 +0900)
committer추지호/SoC Architecture팀(SR)/삼성전자 <jiho.chu@samsung.com>
Fri, 30 Jun 2023 05:22:29 +0000 (14:22 +0900)
This patch separates memory info to reserved and system info in stat.

Signed-off-by: Yelin Jeong <yelini.jeong@samsung.com>
include/common/typedef.h
include/uapi/misc/trinity.h
src/core/npu/NPUdrvAPI_triv2.cc
utils/trinity_cuse/trinity-cuse-triv2.cc
utils/trinity_smi/trinity-smi.cc

index aa04988904f033e155de069f729e93ff62f610f8..67447bedad1e294d11f8f723577dce98a17874c1 100644 (file)
@@ -298,6 +298,16 @@ typedef enum {
   NPU_APP_TERMINATED = 4,
 } npu_app_status;
 
+/**
+ * struct npu_mem_info - Describes memory info
+ * @alloc: Size of allocated memory in the device
+ * @freed: Size of freed memory in the device
+ */
+typedef struct {
+       uint64_t alloc;
+       uint64_t freed;
+} npu_mem_info;
+
 /**
  * @brief Description of npu request (per inference) status
  */
@@ -318,8 +328,9 @@ typedef struct {
   uint32_t num_total_reqs;
   uint32_t num_active_reqs;
 
-  uint64_t total_alloc_mem;
-  uint64_t total_freed_mem;
+       npu_mem_info reserved;
+       npu_mem_info reserved_cont;
+       npu_mem_info system;
 } npu_stat_app;
 
 typedef struct {
index d5d7cb8230e51be6ba360cae67cb7ffe9ed3e558..79cf036fe19ff6b9f9b75c9d4ebd77505da49cf3 100644 (file)
@@ -123,6 +123,16 @@ enum trinity_hwmem_type {
 #define TRINITY_APP_STAT_MAX 10
 #define TRINITY_REQ_STAT_MAX 10
 
+/**
+ * struct trinity_ioctl_mem_info - Describes memory info
+ * @alloc: Size of allocated memory in the device
+ * @freed: Size of freed memory in the device
+ */
+struct trinity_ioctl_mem_info {
+       __u64 alloc;
+       __u64 freed;
+} __attribute__((packed));
+
 /**
  * struct trinity_ioctl_stat_app - Describes stat of the target app
  * @app_id: Trinity app id (currently, equal to pid)
@@ -130,8 +140,6 @@ enum trinity_hwmem_type {
  * @status: Trinity app status
  * @num_total_reqs: Number of total requests in app (including finished ones)
  * @num_active_reqs: Number of active (running or pending) requests in app
- * @total_alloc_mem: Total size of allocated memory in the device
- * @total_freed_mem: Total size of freed memory in the device
  */
 struct trinity_ioctl_stat_app {
        __s32 app_id;
@@ -142,8 +150,9 @@ struct trinity_ioctl_stat_app {
        __u32 num_total_reqs;
        __u32 num_active_reqs;
 
-       __u64 total_alloc_mem;
-       __u64 total_freed_mem;
+       struct trinity_ioctl_mem_info reserved;
+       struct trinity_ioctl_mem_info reserved_cont;
+       struct trinity_ioctl_mem_info system;
 } __attribute__((packed));
 
 /**
index f6766dcc1c2a45702543f7fdd4156876079fffb8..11aa1cc26a0d11b8083626cf1f1182198f57379f 100644 (file)
@@ -354,8 +354,12 @@ TrinityVision2API::getMemoryStatus (size_t *alloc_total, size_t *free_total) con
   if (ret < 0)
     IOCTL_RETURN_ERRNO (TRINITY_IOCTL_STAT_CURRENT_APP);
 
-  *alloc_total = stat.total_alloc_mem;
-  *free_total = stat.total_freed_mem;
+  *alloc_total = stat.reserved.alloc;
+  *alloc_total += stat.reserved_cont.alloc;
+  *alloc_total += stat.system.alloc;
+  *free_total = stat.reserved.freed;
+  *free_total += stat.reserved_cont.freed;
+  *free_total += stat.system.freed;
 
   return 0;
 }
@@ -810,8 +814,12 @@ TrinityVision2API::getStatApps (npu_stat_apps *stat) const {
     stat->stat[i].num_total_reqs = stat_app->num_total_reqs;
     stat->stat[i].num_active_reqs = stat_app->num_active_reqs;
 
-    stat->stat[i].total_alloc_mem = stat_app->total_alloc_mem;
-    stat->stat[i].total_freed_mem = stat_app->total_freed_mem;
+    stat->stat[i].reserved.alloc = stat_app->reserved.alloc;
+    stat->stat[i].reserved.freed = stat_app->reserved.freed;
+    stat->stat[i].reserved_cont.alloc = stat_app->reserved_cont.alloc;
+    stat->stat[i].reserved_cont.freed = stat_app->reserved_cont.freed;
+    stat->stat[i].system.alloc = stat_app->system.alloc;
+    stat->stat[i].system.freed = stat_app->system.freed;
   }
 
   return 0;
index 58f0c2907fa799cf14635d9009a8584779475edf..190d074df2b525ffa4b8f15a3cdaa5ee95bb737c 100644 (file)
@@ -580,12 +580,12 @@ class EmulStat {
 
   void incTotalAllocMem (uint64_t size) {
     std::unique_lock<std::mutex> lock (mutex_);
-    stat_app_.total_alloc_mem += size;
+    stat_app_.reserved.alloc += size;
   }
 
   void incTotalFreedMem (uint64_t size) {
     std::unique_lock<std::mutex> lock (mutex_);
-    stat_app_.total_freed_mem += size;
+    stat_app_.reserved.freed += size;
   }
 
  private:
index 2928b9b4497a007b52b460bf1e18917b7106619a..e6c785351dd13767937a508c80e73dbf11122f32 100644 (file)
@@ -339,7 +339,7 @@ TrinitySMI::append_apps () {
     ss_ << "| " << right << setw (15) << stat->name << " ";
     ss_ << "| " << right << setw (10) << status_str << " ";
     ss_ << "| " << right << setw (9) << fixed << setprecision (2);
-    ss_ << (((double) stat->total_alloc_mem) / 1024.0) << " ";
+    ss_ << (((double) stat->reserved.alloc + (double) stat->reserved_cont.alloc + (double) stat->system.alloc) / 1024.0) << " ";
     ss_ << "| " << right << setw (6) << stat->num_total_reqs << " |\n";
     count++;
   }