[Cuse/Stat] Add request statistics in cuse driver
authorDongju Chae <dongju.chae@samsung.com>
Wed, 21 Jul 2021 03:00:05 +0000 (12:00 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Wed, 21 Jul 2021 09:51:52 +0000 (18:51 +0900)
This patch adds request statistics in cuse driver including
some code refactoring.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
utils/trinity_cuse/trinity-cuse-triv2.cc
utils/trinity_cuse/trinity-cuse.cc
utils/trinity_cuse/trinity-cuse.h

index 0c9b910..8fcbb84 100644 (file)
@@ -23,6 +23,8 @@
 #include <atomic>
 #include <list>
 
+#include <chrono>
+
 #include <triv2profile.h>
 #include "trinity-cuse.h"
 
@@ -45,92 +47,6 @@ ThreadSafeMap<int, EmulProfile> global_profile_map;
 ThreadSafeMap<int, EmulStat> global_stat_map;
 
 /**
- * @brief Emulated Stat Impl.
- */
-class EmulStat {
- public:
-  EmulStat (int app_id) : app_id_ (app_id), refcount_ (0) {
-    memset (&app_stat_, '\x00', sizeof (struct trinity_ioctl_stat_app));
-    app_stat_.app_id = app_id;
-    app_stat_.status = TRINITY_APP_STATUS_PENDING;
-  }
-  ~EmulStat () {}
-
-  static EmulStat *find (int app_id, bool create = true) {
-    EmulStat *stat = global_stat_map.find (app_id);
-    if (stat == nullptr && create) {
-      stat = new EmulStat (app_id);
-      if (global_stat_map.size () > TRINITY_APP_STAT_MAX)
-        removeStale ();
-      if (global_stat_map.insert (app_id, stat) != 0) {
-        delete stat;
-        stat = nullptr;
-      }
-    }
-    return stat;
-  }
-
-  static void removeStale () {
-    std::function<bool(EmulStat *)> functor = [](EmulStat *stat) -> bool {
-      /* remove stale stats with zero refcount */
-      return (stat->getRefCount () == 0);
-    };
-    global_stat_map.for_each (functor);
-  }
-
-  struct trinity_ioctl_stat_app *getAppStat () {
-    return &app_stat_;
-  }
-
-  void setStatus (enum trinity_app_status status) {
-    std::unique_lock<std::mutex> lock (mutex_);
-    app_stat_.status = status;
-  }
-
-  void incRefCount () {
-    std::unique_lock<std::mutex> lock (mutex_);
-    refcount_++;
-    app_stat_.status = TRINITY_APP_STATUS_STARTED;
-  }
-
-  void decRefCount () {
-    std::unique_lock<std::mutex> lock (mutex_);
-    if (refcount_ > 0) {
-      refcount_--;
-      if (refcount_ == 0)
-        app_stat_.status = TRINITY_APP_STATUS_TERMINATED;
-    } else {
-      std::cerr << "Invalid refcount: " << refcount_ << "\n";
-      app_stat_.status = TRINITY_APP_STATUS_ERROR;
-    }
-  }
-
-  int getRefCount () {
-    std::unique_lock<std::mutex> lock (mutex_);
-    return refcount_;
-  }
-
-  void incTotalAllocMem (uint64_t size) {
-    std::unique_lock<std::mutex> lock (mutex_);
-    app_stat_.total_alloc_mem += size;
-  }
-
-  void incTotalFreedMem (uint64_t size) {
-    std::unique_lock<std::mutex> lock (mutex_);
-    app_stat_.total_freed_mem += size;
-  }
-
- private:
-  std::mutex mutex_;
-
-  int app_id_;
-  int refcount_;
-
-  struct trinity_ioctl_stat_app app_stat_;
-  std::list<struct trinity_ioctl_stat_req *> req_stat_;
-};
-
-/**
  * @brief Emulated Dmabuf Impl.
  */
 class EmulDmabuf {
@@ -197,7 +113,7 @@ class EmulDmabuf {
  */
 class EmulModel {
  public:
-  EmulModel (const struct trinity_ioctl_model *m) {
+  EmulModel (const trinity_cuse_model *m) {
     id_ = global_id_.fetch_add (1);
     id_ |= (m->dbuf_fd << TRINITY_SHIFT_MODEL_ID);
 
@@ -429,6 +345,137 @@ class EmulProfile {
   npu_profile profile_;
 };
 
+class EmulStatReq {
+ public:
+  EmulStatReq (const trinity_cuse_stat_req &stat)
+      : stat_ (stat), profile_ (nullptr) {}
+  ~EmulStatReq () {
+    if (profile_)
+      global_profile_map.remove (stat_.req_id);
+  }
+
+  const trinity_cuse_stat_req &getStat () { return stat_; }
+
+  void setProfile (EmulProfile *profile) { profile_ = profile; }
+  EmulProfile *getProfile () { return profile_; }
+
+  void updateInferTime (uint32_t infer_time) {
+    stat_.status = TRINITY_REQ_STATUS_FINISHED;
+    stat_.infer_time = infer_time;
+  }
+
+ private:
+  trinity_cuse_stat_req stat_;
+  EmulProfile *profile_;
+};
+
+/**
+ * @brief Emulated Stat Impl.
+ */
+class EmulStat {
+ public:
+  EmulStat (int app_id) : app_id_ (app_id), refcount_ (0) {
+    memset (&stat_app_, '\x00', sizeof (trinity_cuse_stat_app));
+    stat_app_.app_id = app_id;
+    stat_app_.status = TRINITY_APP_STATUS_PENDING;
+  }
+  ~EmulStat () { stat_req_.clear (); }
+
+  static EmulStat *find (int app_id, bool create = true) {
+    EmulStat *stat = global_stat_map.find (app_id);
+    if (stat == nullptr && create) {
+      stat = new EmulStat (app_id);
+      if (global_stat_map.size () > TRINITY_APP_STAT_MAX)
+        removeStale ();
+      if (global_stat_map.insert (app_id, stat) != 0) {
+        delete stat;
+        stat = nullptr;
+      }
+    }
+    return stat;
+  }
+
+  static void removeStale () {
+    std::function<bool(EmulStat *)> functor = [](EmulStat *stat) -> bool {
+      /* remove stale stats with zero refcount */
+      return (stat->getRefCount () == 0);
+    };
+    global_stat_map.for_each (functor);
+  }
+
+  trinity_cuse_stat_app *getStatApp () { return &stat_app_; }
+
+  EmulStatReq *createReqStat (const trinity_cuse_stat_req &stat_req) {
+    std::unique_lock<std::mutex> lock (mutex_);
+    std::unique_ptr<EmulStatReq> stat (new EmulStatReq (stat_req));
+    EmulStatReq *output = stat.get ();
+
+    if (stat_req_.size () == TRINITY_REQ_STAT_MAX)
+      stat_req_.pop_front ();
+    stat_req_.push_back (std::move (stat));
+
+    return output;
+  }
+
+  void getStatReqs (trinity_cuse_stat_reqs *stat) {
+    std::unique_lock<std::mutex> lock (mutex_);
+
+    stat->num_reqs = 0;
+    for (auto const &it : stat_req_) {
+      if (stat->num_reqs == TRINITY_REQ_STAT_MAX)
+        break;
+      stat->stat[stat->num_reqs++] = it->getStat ();
+    }
+  }
+
+  void setStatus (enum trinity_app_status status) {
+    std::unique_lock<std::mutex> lock (mutex_);
+    stat_app_.status = status;
+  }
+
+  void incRefCount () {
+    std::unique_lock<std::mutex> lock (mutex_);
+    refcount_++;
+    stat_app_.status = TRINITY_APP_STATUS_STARTED;
+  }
+
+  void decRefCount () {
+    std::unique_lock<std::mutex> lock (mutex_);
+    if (refcount_ > 0) {
+      refcount_--;
+      if (refcount_ == 0)
+        stat_app_.status = TRINITY_APP_STATUS_TERMINATED;
+    } else {
+      std::cerr << "Invalid refcount: " << refcount_ << "\n";
+      stat_app_.status = TRINITY_APP_STATUS_ERROR;
+    }
+  }
+
+  int getRefCount () {
+    std::unique_lock<std::mutex> lock (mutex_);
+    return refcount_;
+  }
+
+  void incTotalAllocMem (uint64_t size) {
+    std::unique_lock<std::mutex> lock (mutex_);
+    stat_app_.total_alloc_mem += size;
+  }
+
+  void incTotalFreedMem (uint64_t size) {
+    std::unique_lock<std::mutex> lock (mutex_);
+    stat_app_.total_freed_mem += size;
+  }
+
+ private:
+  std::mutex mutex_;
+
+  int app_id_;
+  int refcount_;
+
+  trinity_cuse_stat_app stat_app_;
+  std::list<std::unique_ptr<EmulStatReq>> stat_req_;
+};
+
 /** @brief Global file descriptor */
 std::atomic<int> EmulDmabuf::global_fd_ (1);
 /** @brief Global model id */
@@ -514,8 +561,7 @@ triv2_get_next_request (trinity_cuse_context *ctx, int32_t *req_id) {
  * @brief TRIV2 impl. of hwmem_alloc ioctl()
  */
 static int
-triv2_hwmem_alloc (trinity_cuse_context *ctx,
-                   const struct trinity_ioctl_hwmem *hwmem) {
+triv2_hwmem_alloc (trinity_cuse_context *ctx, const trinity_cuse_hwmem *hwmem) {
   EmulDmabuf *dmabuf;
   EmulStat *stat;
   size_t size;
@@ -554,7 +600,7 @@ triv2_hwmem_alloc (trinity_cuse_context *ctx,
  */
 static int
 triv2_hwmem_dealloc (trinity_cuse_context *ctx,
-                     const struct trinity_ioctl_hwmem *hwmem) {
+                     const trinity_cuse_hwmem *hwmem) {
   EmulDmabuf *dmabuf = global_dmabuf_map.find (hwmem->dbuf_fd);
   if (dmabuf == nullptr)
     return -ENOENT;
@@ -571,9 +617,8 @@ triv2_hwmem_dealloc (trinity_cuse_context *ctx,
  * @brief TRIV2 impl. of register_model ioctl()
  */
 static int
-triv2_register_model (trinity_cuse_context *ctx,
-                      const struct trinity_ioctl_model *in,
-                      struct trinity_ioctl_model *out) {
+triv2_register_model (trinity_cuse_context *ctx, const trinity_cuse_model *in,
+                      trinity_cuse_model *out) {
   EmulModel *model = new EmulModel (in);
   EmulModel *same_model = nullptr;
 
@@ -616,9 +661,8 @@ triv2_deregister_model (trinity_cuse_context *ctx, const uint64_t model_id) {
  * @brief TRIV2 impl. of run_input ioctl()
  */
 static int
-triv2_run_input (trinity_cuse_context *ctx,
-                 const struct trinity_ioctl_input *in,
-                 struct trinity_ioctl_input *out) {
+triv2_run_input (trinity_cuse_context *ctx, const trinity_cuse_input *in,
+                 trinity_cuse_input *out) {
   EmulDmabuf *dbuf_input = global_dmabuf_map.find (in->dbuf_fd);
   if (dbuf_input == nullptr)
     return -ENOENT;
@@ -627,6 +671,10 @@ triv2_run_input (trinity_cuse_context *ctx,
   if (model == nullptr)
     return -ENOENT;
 
+  EmulStat *stat = EmulStat::find (ctx->app_id);
+  if (stat == nullptr)
+    return -ENOENT;
+
   if (model->getVersion () != 3)
     return -EINVAL;
 
@@ -685,9 +733,29 @@ triv2_run_input (trinity_cuse_context *ctx,
   std::string prof_path (ctx->prefix_profile);
   prof_path += "/ne_profile." + std::to_string (req_id);
 
+  trinity_cuse_stat_req stat_req_data;
+
+  stat_req_data.req_id = in->req_id;
+  stat_req_data.model_id = in->model_id;
+  stat_req_data.priority = (enum trinity_req_priority) in->priority;
+  stat_req_data.status = TRINITY_REQ_STATUS_RUNNING;
+  stat_req_data.sched_time = 0;
+  stat_req_data.infer_time = 0;
+
+  EmulStatReq *stat_req = stat->createReqStat (stat_req_data);
+
+  std::chrono::steady_clock::time_point begin =
+      std::chrono::steady_clock::now ();
   run_triv2_emul (prog, segt, meta, cmd_path.c_str (), prof_path.c_str ());
+  std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now ();
+
+  stat_req->updateInferTime (
+      std::chrono::duration_cast<std::chrono::milliseconds> (end - begin)
+          .count ());
 
   EmulProfile *profile = new EmulProfile (req_id, prof_path + ".rec");
+  stat_req->setProfile (profile);
+
   global_profile_map.insert (req_id, profile);
 
   delete[] segt;
@@ -717,12 +785,12 @@ triv2_stop_request (trinity_cuse_context *ctx, const int id) {
  */
 static int
 triv2_stat_current_app (trinity_cuse_context *ctx,
-                        struct trinity_ioctl_stat_app *stat) {
+                        trinity_cuse_stat_app *stat) {
   EmulStat *s = global_stat_map.find (ctx->app_id);
   if (s == nullptr)
     return -ENOENT;
 
-  memcpy (stat, s->getAppStat (), sizeof (*stat));
+  memcpy (stat, s->getStatApp (), sizeof (*stat));
   return 0;
 }
 
@@ -730,15 +798,14 @@ triv2_stat_current_app (trinity_cuse_context *ctx,
  * @brief TRIV2 impl. of stat_apps ioctl()
  */
 static int
-triv2_stat_apps (trinity_cuse_context *ctx,
-                 struct trinity_ioctl_stat_apps *stat) {
+triv2_stat_apps (trinity_cuse_context *ctx, trinity_cuse_stat_apps *stat) {
   memset (stat, '\x00', sizeof (*stat));
   stat->num_apps = 0;
 
   std::function<bool(EmulStat *)> functor = [&](EmulStat *s) -> bool {
     if (stat->num_apps < TRINITY_APP_STAT_MAX) {
-      memcpy (&stat->stat[stat->num_apps++], s->getAppStat (),
-              sizeof (struct trinity_ioctl_stat_app));
+      memcpy (&stat->stat[stat->num_apps++], s->getStatApp (),
+              sizeof (trinity_cuse_stat_app));
     }
     /* don't remove */
     return false;
@@ -752,12 +819,21 @@ triv2_stat_apps (trinity_cuse_context *ctx,
  * @brief TRIV2 impl. of stat_reqs ioctl()
  */
 static int
-triv2_stat_reqs (trinity_cuse_context *ctx,
-                 struct trinity_ioctl_stat_reqs *stat) {
-  /* NYI */
-  memset (stat, '\x00', sizeof (*stat));
-  stat->app_id = ctx->app_id;
-  stat->num_reqs = 0;
+triv2_stat_reqs (trinity_cuse_context *ctx, const trinity_cuse_stat_reqs *in,
+                 trinity_cuse_stat_reqs *out) {
+  int app_id = in->app_id;
+  EmulStat *stat;
+
+  /* use the pid of 'current' */
+  if (app_id == 0)
+    app_id = ctx->app_id;
+
+  stat = global_stat_map.find (app_id);
+  if (stat == nullptr)
+    return -ENOENT;
+
+  stat->getStatReqs (out);
+
   return 0;
 }
 
@@ -766,8 +842,8 @@ triv2_stat_reqs (trinity_cuse_context *ctx,
  */
 static int
 triv2_get_profile_meta (trinity_cuse_context *ctx,
-                        const struct trinity_ioctl_profile_meta *in,
-                        struct trinity_ioctl_profile_meta *out) {
+                        const trinity_cuse_profile_meta *in,
+                        trinity_cuse_profile_meta *out) {
   EmulProfile *profile = global_profile_map.find (in->req_id);
   if (profile == nullptr)
     return -ENOENT;
@@ -790,8 +866,8 @@ triv2_get_profile_meta (trinity_cuse_context *ctx,
  */
 static int
 triv2_get_profile_buff (trinity_cuse_context *ctx,
-                        const struct trinity_ioctl_profile_buff *in,
-                        struct trinity_ioctl_profile_buff *out, void *data) {
+                        const trinity_cuse_profile_buff *in,
+                        trinity_cuse_profile_buff *out, void *data) {
   EmulProfile *profile = global_profile_map.find (in->req_id);
   if (profile == nullptr)
     return -ENOENT;
@@ -803,9 +879,6 @@ triv2_get_profile_buff (trinity_cuse_context *ctx,
   memcpy (data, (char *) profile->getData () + in->profile_pos,
           in->profile_size);
 
-  if (in->profile_pos + in->profile_size == profile->getDataSize ())
-    global_profile_map.remove (in->req_id);
-
   return 0;
 }
 
index 4377037..a6e6256 100644 (file)
@@ -164,32 +164,32 @@ trinity_cuse_ioctl (fuse_req_t req, int cmd, void *arg,
       break;
     case TRINITY_IOCTL_HWMEM_ALLOC:
       if (!in_size) {
-        struct iovec iov = {arg, sizeof (struct trinity_ioctl_hwmem)};
+        struct iovec iov = {arg, sizeof (trinity_cuse_hwmem)};
         fuse_reply_ioctl_retry (req, &iov, 1, NULL, 0);
       } else {
-        const struct trinity_ioctl_hwmem *val =
-            static_cast<const struct trinity_ioctl_hwmem *> (in_buf);
+        const trinity_cuse_hwmem *val =
+            static_cast<const trinity_cuse_hwmem *> (in_buf);
         fuse_reply_ioctl (req, vtable->hwmem_alloc (ctx, val), NULL, 0);
       }
       break;
     case TRINITY_IOCTL_HWMEM_DEALLOC:
       if (!in_size) {
-        struct iovec iov = {arg, sizeof (struct trinity_ioctl_hwmem)};
+        struct iovec iov = {arg, sizeof (trinity_cuse_hwmem)};
         fuse_reply_ioctl_retry (req, &iov, 1, NULL, 0);
       } else {
-        const struct trinity_ioctl_hwmem *val =
-            static_cast<const struct trinity_ioctl_hwmem *> (in_buf);
+        const trinity_cuse_hwmem *val =
+            static_cast<const trinity_cuse_hwmem *> (in_buf);
         fuse_reply_ioctl (req, vtable->hwmem_dealloc (ctx, val), NULL, 0);
       }
       break;
     case TRINITY_IOCTL_REGISTER_MODEL:
       if (!in_size || !out_size) {
-        struct iovec iov = {arg, sizeof (struct trinity_ioctl_model)};
+        struct iovec iov = {arg, sizeof (trinity_cuse_model)};
         fuse_reply_ioctl_retry (req, &iov, 1, &iov, 1);
       } else {
-        const struct trinity_ioctl_model *in_val =
-            static_cast<const struct trinity_ioctl_model *> (in_buf);
-        struct trinity_ioctl_model out_val;
+        const trinity_cuse_model *in_val =
+            static_cast<const trinity_cuse_model *> (in_buf);
+        trinity_cuse_model out_val;
         fuse_reply_ioctl (req, vtable->register_model (ctx, in_val, &out_val),
                           &out_val, sizeof (out_val));
       }
@@ -205,12 +205,12 @@ trinity_cuse_ioctl (fuse_req_t req, int cmd, void *arg,
       break;
     case TRINITY_IOCTL_RUN_INPUT:
       if (!in_size || !out_size) {
-        struct iovec iov = {arg, sizeof (struct trinity_ioctl_input)};
+        struct iovec iov = {arg, sizeof (trinity_cuse_input)};
         fuse_reply_ioctl_retry (req, &iov, 1, &iov, 1);
       } else {
-        const struct trinity_ioctl_input *in_val =
-            static_cast<const struct trinity_ioctl_input *> (in_buf);
-        struct trinity_ioctl_input out_val;
+        const trinity_cuse_input *in_val =
+            static_cast<const trinity_cuse_input *> (in_buf);
+        trinity_cuse_input out_val;
         fuse_reply_ioctl (req, vtable->run_input (ctx, in_val, &out_val),
                           &out_val, sizeof (out_val));
       }
@@ -229,42 +229,44 @@ trinity_cuse_ioctl (fuse_req_t req, int cmd, void *arg,
       break;
     case TRINITY_IOCTL_STAT_CURRENT_APP:
       if (!out_size) {
-        struct iovec iov = {arg, sizeof (struct trinity_ioctl_stat_app)};
+        struct iovec iov = {arg, sizeof (trinity_cuse_stat_app)};
         fuse_reply_ioctl_retry (req, NULL, 0, &iov, 1);
       } else {
-        struct trinity_ioctl_stat_app val;
+        trinity_cuse_stat_app val;
         fuse_reply_ioctl (req, vtable->stat_current_app (ctx, &val), &val,
                           sizeof (val));
       }
       break;
     case TRINITY_IOCTL_STAT_APPS:
       if (!out_size) {
-        struct iovec iov = {arg, sizeof (struct trinity_ioctl_stat_apps)};
+        struct iovec iov = {arg, sizeof (trinity_cuse_stat_apps)};
         fuse_reply_ioctl_retry (req, NULL, 0, &iov, 1);
       } else {
-        struct trinity_ioctl_stat_apps val;
+        trinity_cuse_stat_apps val;
         fuse_reply_ioctl (req, vtable->stat_apps (ctx, &val), &val,
                           sizeof (val));
       }
       break;
     case TRINITY_IOCTL_STAT_REQS:
-      if (!out_size) {
-        struct iovec iov = {arg, sizeof (struct trinity_ioctl_stat_reqs)};
-        fuse_reply_ioctl_retry (req, NULL, 0, &iov, 1);
+      if (!in_size || !out_size) {
+        struct iovec iov = {arg, sizeof (trinity_cuse_stat_reqs)};
+        fuse_reply_ioctl_retry (req, &iov, 1, &iov, 1);
       } else {
-        struct trinity_ioctl_stat_reqs val;
-        fuse_reply_ioctl (req, vtable->stat_reqs (ctx, &val), &val,
-                          sizeof (val));
+        const trinity_cuse_stat_reqs *in_val =
+            static_cast<const trinity_cuse_stat_reqs *> (in_buf);
+        trinity_cuse_stat_reqs out_val;
+        fuse_reply_ioctl (req, vtable->stat_reqs (ctx, in_val, &out_val),
+                          &out_val, sizeof (out_val));
       }
       break;
     case TRINITY_IOCTL_GET_PROFILE_META:
       if (!in_size || !out_size) {
-        struct iovec iov = {arg, sizeof (struct trinity_ioctl_profile_meta)};
+        struct iovec iov = {arg, sizeof (trinity_cuse_profile_meta)};
         fuse_reply_ioctl_retry (req, &iov, 1, &iov, 1);
       } else {
-        const struct trinity_ioctl_profile_meta *in_val =
-            static_cast<const struct trinity_ioctl_profile_meta *> (in_buf);
-        struct trinity_ioctl_profile_meta out_val;
+        const trinity_cuse_profile_meta *in_val =
+            static_cast<const trinity_cuse_profile_meta *> (in_buf);
+        trinity_cuse_profile_meta out_val;
         fuse_reply_ioctl (req, vtable->get_profile_meta (ctx, in_val, &out_val),
                           &out_val, sizeof (out_val));
       }
@@ -274,7 +276,7 @@ trinity_cuse_ioctl (fuse_req_t req, int cmd, void *arg,
       struct iovec out_iov;
 
       arg_iov.iov_base = arg;
-      arg_iov.iov_len = sizeof (struct trinity_ioctl_profile_buff);
+      arg_iov.iov_len = sizeof (trinity_cuse_profile_buff);
 
       /* read input arg */
       if (!in_size) {
@@ -282,8 +284,8 @@ trinity_cuse_ioctl (fuse_req_t req, int cmd, void *arg,
         break;
       }
 
-      const struct trinity_ioctl_profile_buff *in_arg =
-          static_cast<const struct trinity_ioctl_profile_buff *> (in_buf);
+      const trinity_cuse_profile_buff *in_arg =
+          static_cast<const trinity_cuse_profile_buff *> (in_buf);
 
       /* prepare output arg & buffer */
       if (!out_size) {
@@ -294,7 +296,7 @@ trinity_cuse_ioctl (fuse_req_t req, int cmd, void *arg,
         break;
       }
 
-      struct trinity_ioctl_profile_buff out_arg;
+      trinity_cuse_profile_buff out_arg;
       char *data = new char[in_arg->profile_size];
       int ret = vtable->get_profile_buff (ctx, in_arg, &out_arg, data);
 
@@ -313,15 +315,15 @@ trinity_cuse_ioctl (fuse_req_t req, int cmd, void *arg,
 }
 
 /** @brief Structure to describe parameters */
-struct trinity_cuse_param {
+typedef struct {
   unsigned int major;
   unsigned int minor;
   std::string dev_name;
   bool is_help;
-};
+} trinity_cuse_param;
 
 #define TRINITY_OPT(t, p) \
-  { t, offsetof (struct trinity_cuse_param, p), 1 }
+  { t, offsetof (trinity_cuse_param, p), 1 }
 
 enum { KEY_HELP };
 
@@ -352,7 +354,7 @@ print_help_message () {
 static int
 trinity_cuse_parse_args (void *data, const char *arg, int key,
                          struct fuse_args *outargs) {
-  struct trinity_cuse_param *param = (struct trinity_cuse_param *) data;
+  trinity_cuse_param *param = (trinity_cuse_param *) data;
 
   (void) outargs;
   (void) arg;
@@ -390,8 +392,8 @@ static const struct cuse_lowlevel_ops trinity_cuse_clop = {
 int
 main (int argc, char **argv) {
   struct fuse_args args = FUSE_ARGS_INIT (argc, argv);
-  struct trinity_cuse_param param = {0};
   struct cuse_info ci = {0};
+  trinity_cuse_param param = {0};
 
   if (geteuid () != 0) {
     std::cerr << "[Error] Permission denied: use the sudo command\n";
index bc7ab65..e25e4f2 100644 (file)
 #include <misc/trinity.h>
 #include <mutex>
 
+typedef struct trinity_ioctl_hwmem trinity_cuse_hwmem;
+typedef struct trinity_ioctl_input trinity_cuse_input;
+typedef struct trinity_ioctl_model trinity_cuse_model;
+
+typedef struct trinity_ioctl_profile_meta trinity_cuse_profile_meta;
+typedef struct trinity_ioctl_profile_buff trinity_cuse_profile_buff;
+
+typedef struct trinity_ioctl_stat_app trinity_cuse_stat_app;
+typedef struct trinity_ioctl_stat_apps trinity_cuse_stat_apps;
+typedef struct trinity_ioctl_stat_req trinity_cuse_stat_req;
+typedef struct trinity_ioctl_stat_reqs trinity_cuse_stat_reqs;
+
 /**
  * @brief The trinity context
  */
@@ -42,29 +54,26 @@ typedef struct {
   int (*get_dspm) (trinity_cuse_context *, uint32_t *);
   int (*get_next_request) (trinity_cuse_context *, int32_t *);
   /* Device Control */
-  int (*hwmem_alloc) (trinity_cuse_context *,
-                      const struct trinity_ioctl_hwmem *);
-  int (*hwmem_dealloc) (trinity_cuse_context *,
-                        const struct trinity_ioctl_hwmem *);
-  int (*register_model) (trinity_cuse_context *,
-                         const struct trinity_ioctl_model *,
-                         struct trinity_ioctl_model *);
+  int (*hwmem_alloc) (trinity_cuse_context *, const trinity_cuse_hwmem *);
+  int (*hwmem_dealloc) (trinity_cuse_context *, const trinity_cuse_hwmem *);
+  int (*register_model) (trinity_cuse_context *, const trinity_cuse_model *,
+                         trinity_cuse_model *);
   int (*deregister_model) (trinity_cuse_context *, const uint64_t);
-  int (*run_input) (trinity_cuse_context *, const struct trinity_ioctl_input *,
-                    struct trinity_ioctl_input *);
+  int (*run_input) (trinity_cuse_context *, const trinity_cuse_input *,
+                    trinity_cuse_input *);
   int (*stop_requests) (trinity_cuse_context *);
   int (*stop_request) (trinity_cuse_context *, const int);
   /* Device Statistics/Profile */
-  int (*stat_current_app) (trinity_cuse_context *,
-                           struct trinity_ioctl_stat_app *);
-  int (*stat_apps) (trinity_cuse_context *, struct trinity_ioctl_stat_apps *);
-  int (*stat_reqs) (trinity_cuse_context *, struct trinity_ioctl_stat_reqs *);
+  int (*stat_current_app) (trinity_cuse_context *, trinity_cuse_stat_app *);
+  int (*stat_apps) (trinity_cuse_context *, trinity_cuse_stat_apps *);
+  int (*stat_reqs) (trinity_cuse_context *, const trinity_cuse_stat_reqs *,
+                    trinity_cuse_stat_reqs *);
   int (*get_profile_meta) (trinity_cuse_context *,
-                           const struct trinity_ioctl_profile_meta *,
-                           struct trinity_ioctl_profile_meta *);
+                           const trinity_cuse_profile_meta *,
+                           trinity_cuse_profile_meta *);
   int (*get_profile_buff) (trinity_cuse_context *,
-                           const struct trinity_ioctl_profile_buff *,
-                           struct trinity_ioctl_profile_buff *, void *);
+                           const trinity_cuse_profile_buff *,
+                           trinity_cuse_profile_buff *, void *);
 } trinity_cuse_ioctl_vtable;
 
 #endif