habanalabs: expose compute ctx status through info ioctl
authorOfir Bitton <obitton@habana.ai>
Thu, 3 Mar 2022 07:43:10 +0000 (09:43 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 22 May 2022 18:57:34 +0000 (20:57 +0200)
In order for the user to know if he can try and open device, we
expose the compute ctx state. The user can now know if the context
is used by another process or whether the device is still ongoing
through cleanup or reset and will be available soon.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/habanalabs/common/habanalabs_ioctl.c
include/uapi/misc/habanalabs.h

index c6fe35ae1238515b550f0eb7ce500e34a081df95..bfb5cfe68110d909f5dcbfd1208afaf1d1a563ad 100644 (file)
@@ -498,6 +498,8 @@ static int open_stats_info(struct hl_fpriv *hpriv, struct hl_info_args *args)
        open_stats_info.last_open_period_ms = jiffies64_to_msecs(
                hdev->last_open_session_duration_jif);
        open_stats_info.open_counter = hdev->open_counter;
+       open_stats_info.is_compute_ctx_active = hdev->is_compute_ctx_active;
+       open_stats_info.compute_ctx_in_release = hdev->compute_ctx_in_release;
 
        return copy_to_user(out, &open_stats_info,
                min((size_t) max_size, sizeof(open_stats_info))) ? -EFAULT : 0;
index f474e7fb018db708c23eecaf126ee7b83ce3a608..ca2af5f980567bbf5264df7d06b4e7eb6e806de2 100644 (file)
@@ -543,10 +543,15 @@ struct hl_pll_frequency_info {
  * struct hl_open_stats_info - device open statistics information
  * @open_counter: ever growing counter, increased on each successful dev open
  * @last_open_period_ms: duration (ms) device was open last time
+ * @is_compute_ctx_active: Whether there is an active compute context executing
+ * @compute_ctx_in_release: true if the current compute context is being released
  */
 struct hl_open_stats_info {
        __u64 open_counter;
        __u64 last_open_period_ms;
+       __u8 is_compute_ctx_active;
+       __u8 compute_ctx_in_release;
+       __u8 pad[6];
 };
 
 /**