habanalabs: add missing counter update
PATCH 1/1 habanalabs: add missing counter update
The global CS drop-on-reset counter wasn't updated together with the context counter.
Signed-off-by Oded Gabbay <[email protected]>
--- drivers/misc/habanalabs/common/hw_queue.c | 1 + 1 file changed, 1 insertion(+)
drivers/misc/habanalabs/common/hw_queue.c +1 -0
@@ -529,6 +529,7 @@ int hl_hw_queue_schedule_cs(struct hl_cs *cs) hdev->asic_funcs->hw_queues_lock (hdev);if (!hl_device_operational (hdev, &status)) { +atomic64_inc (&cntr->device_in_reset_drop_cnt);atomic64_inc (&ctx->cs_counters.device_in_reset_drop_cnt);dev_err (hdev->dev,"device is %s, CS rejected!\n" , hdev->status[status]);
Signature · 1 line
2.17.1
PATCH 1/1 habanalabs: add support for cs with timestamp
From: Ofir Bitton <[email protected]>
add support for user to request a timestamp upon
cs completion.
Signed-off-by Ofir Bitton <[email protected]>
Reviewed-by Oded Gabbay <[email protected]>
Signed-off-by Oded Gabbay <[email protected]>
--- .../habanalabs/common/command_submission.c | 44 ++++++++++++++----- drivers/misc/habanalabs/common/habanalabs.h | 4 ++ include/uapi/misc/habanalabs.h | 6 ++- 3 files changed, 41 insertions(+), 13 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +32 -12
@@ -26,7 +26,7 @@ enum hl_cs_wait_status {static void job_wq_completion (struct work_struct *work);static int _hl_cs_wait_ioctl (struct hl_device *hdev,struct hl_ctx *ctx,u64 timeout_us,u64 seq, -enum hl_cs_wait_status *status); +enum hl_cs_wait_status *status,s64 *timestamp);static void cs_do_release (struct kref *ref);static void hl_sob_reset (struct kref *ref)
@@ -150,6 +150,7 @@ static void hl_fence_init(struct hl_fence *fence) {kref_init (&fence->refcount); fence->error =0 ; + fence->timestamp =ktime_set (0 ,0 );init_completion (&fence->completion); }
@@ -404,6 +405,8 @@ static void cs_do_release(struct kref *ref)else if (!cs->submitted) cs->fence->error = -EBUSY ; +if (cs->timestamp) + cs->fence->timestamp =ktime_get ();complete_all (&cs->fence->completion);hl_fence_put (cs->fence);
@@ -734,7 +737,8 @@ static int hl_cs_sanity_checks(struct hl_fpriv *hpriv, union hl_cs_args *args)return -EBUSY ; } - cs_type_flags = args->in.cs_flags & ~HL_CS_FLAGS_FORCE_RESTORE ; + cs_type_flags = args->in.cs_flags & + ~(HL_CS_FLAGS_FORCE_RESTORE |HL_CS_FLAGS_TIMESTAMP );if (unlikely (cs_type_flags && !is_power_of_2 (cs_type_flags))) { dev_err(hdev->dev,
@@ -798,7 +802,7 @@ static int hl_cs_copy_chunk_array(struct hl_device *hdev, }static int cs_ioctl_default (struct hl_fpriv *hpriv,void __user *chunks, -u32 num_chunks,u64 *cs_seq) +u32 num_chunks,u64 *cs_seq,bool timestamp) {bool int_queues_only = true;struct hl_device *hdev = hpriv->hdev;
@@ -825,6 +829,7 @@ static int cs_ioctl_default(struct hl_fpriv *hpriv, void __user *chunks, goto free_cs_chunk_array; } + cs->timestamp = !!timestamp; *cs_seq = cs->sequence;hl_debugfs_add_cs (cs);
@@ -995,7 +1000,7 @@ static int hl_cs_ctx_switch(struct hl_fpriv *hpriv, union hl_cs_args *args, rc =0 ; }else { rc =cs_ioctl_default (hpriv, chunks, num_chunks, - cs_seq); + cs_seq, false); }mutex_unlock (&hpriv->restore_phase_mutex);
@@ -1013,7 +1018,7 @@ static int hl_cs_ctx_switch(struct hl_fpriv *hpriv, union hl_cs_args *args, wait_again: ret =_hl_cs_wait_ioctl (hdev, ctx,jiffies_to_usecs (hdev->timeout_jiffies), - *cs_seq, &status); + *cs_seq, &status,NULL );if (ret) {if (ret == -ERESTARTSYS ) {usleep_range (100 ,200 );
@@ -1154,7 +1159,7 @@ static int cs_ioctl_signal_wait_create_jobs(struct hl_device *hdev,static int cs_ioctl_signal_wait (struct hl_fpriv *hpriv,enum hl_cs_type cs_type,void __user *chunks,u32 num_chunks, -u64 *cs_seq) +u64 *cs_seq,bool timestamp) {struct hl_cs_chunk *cs_chunk_array, *chunk;struct hw_queue_properties *hw_queue_prop;
@@ -1259,6 +1264,8 @@ static int cs_ioctl_signal_wait(struct hl_fpriv *hpriv, enum hl_cs_type cs_type, goto free_cs_chunk_array; } + cs->timestamp = !!timestamp; +/* * Save the signal CS fence for later initialization right before * hanging the wait CS on the queue.
@@ -1334,10 +1341,11 @@ int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data)case CS_TYPE_WAIT :case CS_TYPE_COLLECTIVE_WAIT : rc =cs_ioctl_signal_wait (hpriv, cs_type, chunks, num_chunks, - &cs_seq); + &cs_seq, args->in.cs_flags &HL_CS_FLAGS_TIMESTAMP );break ;default : - rc =cs_ioctl_default (hpriv, chunks, num_chunks, &cs_seq); + rc =cs_ioctl_default (hpriv, chunks, num_chunks, &cs_seq, + args->in.cs_flags &HL_CS_FLAGS_TIMESTAMP );break ; }
@@ -1353,13 +1361,16 @@ int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data)static int _hl_cs_wait_ioctl (struct hl_device *hdev,struct hl_ctx *ctx,u64 timeout_us,u64 seq, -enum hl_cs_wait_status *status) +enum hl_cs_wait_status *status,s64 *timestamp) {struct hl_fence *fence;unsigned long timeout;int rc =0 ;long completion_rc; +if (timestamp) + *timestamp =0 ; +if (timeout_us ==MAX_SCHEDULE_TIMEOUT ) timeout = timeout_us;else
@@ -1382,10 +1393,13 @@ static int _hl_cs_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx,wait_for_completion_interruptible_timeout ( &fence->completion, timeout); -if (completion_rc >0 ) +if (completion_rc >0 ) { *status =CS_WAIT_STATUS_COMPLETED ; -else +if (timestamp) + *timestamp =ktime_to_ns (fence->timestamp); + }else { *status =CS_WAIT_STATUS_BUSY ; + }if (fence->error == -ETIMEDOUT ) rc = -ETIMEDOUT ;
@@ -1411,10 +1425,11 @@ int hl_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data)union hl_wait_cs_args *args = data;enum hl_cs_wait_status status;u64 seq = args->in.seq; +s64 timestamp;int rc; rc =_hl_cs_wait_ioctl (hdev, hpriv->ctx, args->in.timeout_us, seq, - &status); + &status, ×tamp);memset (args,0 ,sizeof (*args));
@@ -1439,6 +1454,11 @@ int hl_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data)return rc; } +if (timestamp) { + args->out.flags |=HL_WAIT_CS_STATUS_FLAG_TIMESTAMP_VLD ; + args->out.timestamp_nsec = timestamp; + } +switch (status) {case CS_WAIT_STATUS_GONE : args->out.flags |=HL_WAIT_CS_STATUS_FLAG_GONE ;
drivers/misc/habanalabs/common/habanalabs.h +4 -0
@@ -481,12 +481,14 @@ struct asic_fixed_properties {* @completion: fence is implemented using completion * @refcount: refcount for this fence * @error: mark this fence with error +* @timestamp: timestamp upon completion * */ struct hl_fence {struct completion completion;struct kref refcount;int error; +ktime_t timestamp; };/**
@@ -1127,6 +1129,7 @@ struct hl_userptr {* @tdr_active: true if TDR was activated for this CS (to prevent * double TDR activation). * @aborted: true if CS was aborted due to some device error. +* @timestamp: true if a timestmap must be captured upon completion */ struct hl_cs {u16 *jobs_in_queue_cnt;
@@ -1147,6 +1150,7 @@ struct hl_cs {u8 timedout;u8 tdr_active;u8 aborted; +u8 timestamp; };/**
include/uapi/misc/habanalabs.h +5 -1
@@ -592,6 +592,7 @@ struct hl_cs_chunk {#define HL_CS_FLAGS_SIGNAL 0x2#define HL_CS_FLAGS_WAIT 0x4#define HL_CS_FLAGS_COLLECTIVE_WAIT 0x8 +#define HL_CS_FLAGS_TIMESTAMP 0x20#define HL_CS_STATUS_SUCCESS 0
@@ -662,13 +663,16 @@ struct hl_wait_cs_in {#define HL_WAIT_CS_STATUS_ABORTED 3#define HL_WAIT_CS_STATUS_INTERRUPTED 4 -#define HL_WAIT_CS_STATUS_FLAG_GONE 0x1 +#define HL_WAIT_CS_STATUS_FLAG_GONE 0x1 +#define HL_WAIT_CS_STATUS_FLAG_TIMESTAMP_VLD 0x2struct hl_wait_cs_out {/* HL_WAIT_CS_STATUS_* */ __u32 status;/* HL_WAIT_CS_STATUS_FLAG* */ __u32 flags; +/* valid only if HL_WAIT_CS_STATUS_FLAG_TIMESTAMP_VLD is set */ +__s64 timestamp_nsec; };union hl_wait_cs_args {
Signature · 1 line
2.17.1
PATCH 1/1 habanalabs: add ull to PLL masks
In reply to Oded GabbayFrom: Alon Mizrahi <[email protected]>
These defines are 64-bit defines so they need ull suffix.
Signed-off-by Alon Mizrahi <[email protected]>
Reviewed-by Oded Gabbay <[email protected]>
Signed-off-by Oded Gabbay <[email protected]>
--- drivers/misc/habanalabs/include/common/cpucp_if.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/misc/habanalabs/include/common/cpucp_if.h +4 -4
@@ -317,13 +317,13 @@ enum cpucp_packet_id {#define CPUCP_PKT_CTL_OPCODE_MASK 0x1FFF0000#define CPUCP_PKT_RES_PLL_OUT0_SHIFT 0 -#define CPUCP_PKT_RES_PLL_OUT0_MASK 0x000000000000FFFF +#define CPUCP_PKT_RES_PLL_OUT0_MASK 0x000000000000FFFFull#define CPUCP_PKT_RES_PLL_OUT1_SHIFT 16 -#define CPUCP_PKT_RES_PLL_OUT1_MASK 0x00000000FFFF0000 +#define CPUCP_PKT_RES_PLL_OUT1_MASK 0x00000000FFFF0000ull#define CPUCP_PKT_RES_PLL_OUT2_SHIFT 32 -#define CPUCP_PKT_RES_PLL_OUT2_MASK 0x0000FFFF00000000 +#define CPUCP_PKT_RES_PLL_OUT2_MASK 0x0000FFFF00000000ull#define CPUCP_PKT_RES_PLL_OUT3_SHIFT 48 -#define CPUCP_PKT_RES_PLL_OUT3_MASK 0xFFFF000000000000 +#define CPUCP_PKT_RES_PLL_OUT3_MASK 0xFFFF000000000000ull struct cpucp_packet { union {
Signature · 1 line
2.17.1
PATCH 1/1 habanalabs: indicate to user that a cs is gone
In reply to Oded GabbayFrom: Ofir Bitton <[email protected]>
We want to indicate to the user that a certain command submission is finished long time ago and it is no longer in database. This means no further information regarding this cs can be obtained.
Signed-off-by Ofir Bitton <[email protected]>
Reviewed-by Oded Gabbay <[email protected]>
Signed-off-by Oded Gabbay <[email protected]>
--- .../habanalabs/common/command_submission.c | 68 ++++++++++++++----- include/uapi/misc/habanalabs.h | 5 +- 2 files changed, 54 insertions(+), 19 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +50 -18
@@ -11,9 +11,22 @@#include <linux/uaccess.h> #include <linux/slab.h> +/** +* enum hl_cs_wait_status - cs wait status +* @CS_WAIT_STATUS_BUSY: cs was not completed yet +* @CS_WAIT_STATUS_COMPLETED: cs completed +* @CS_WAIT_STATUS_GONE: cs completed but fence is already gone +*/ +enum hl_cs_wait_status { +CS_WAIT_STATUS_BUSY , +CS_WAIT_STATUS_COMPLETED , +CS_WAIT_STATUS_GONE +}; +static void job_wq_completion (struct work_struct *work); -static long _hl_cs_wait_ioctl (struct hl_device *hdev, -struct hl_ctx *ctx,u64 timeout_us,u64 seq); +static int _hl_cs_wait_ioctl (struct hl_device *hdev,struct hl_ctx *ctx, +u64 timeout_us,u64 seq, +enum hl_cs_wait_status *status);static void cs_do_release (struct kref *ref);static void hl_sob_reset (struct kref *ref)
@@ -942,7 +955,7 @@ static int hl_cs_ctx_switch(struct hl_fpriv *hpriv, union hl_cs_args *args,int rc =0 , do_ctx_switch;void __user *chunks;u32 num_chunks, tmp; -long ret; +int ret; do_ctx_switch =atomic_cmpxchg (&ctx->thread_ctx_switch_token,1 ,0 );
@@ -996,18 +1009,19 @@ static int hl_cs_ctx_switch(struct hl_fpriv *hpriv, union hl_cs_args *args,/* Need to wait for restore completion before execution phase */ if (num_chunks) { +enum hl_cs_wait_status status; wait_again: ret =_hl_cs_wait_ioctl (hdev, ctx,jiffies_to_usecs (hdev->timeout_jiffies), - *cs_seq); -if (ret <=0 ) { + *cs_seq, &status); +if (ret) {if (ret == -ERESTARTSYS ) {usleep_range (100 ,200 ); goto wait_again; }dev_err (hdev->dev, -"Restore CS for context %d failed to complete %ld\n" , +"Restore CS for context %d failed to complete %d\n" , ctx->asid, ret); rc = -ENOEXEC ; goto out;
@@ -1337,12 +1351,14 @@ int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data)return rc; } -static long _hl_cs_wait_ioctl (struct hl_device *hdev, -struct hl_ctx *ctx,u64 timeout_us,u64 seq) +static int _hl_cs_wait_ioctl (struct hl_device *hdev,struct hl_ctx *ctx, +u64 timeout_us,u64 seq, +enum hl_cs_wait_status *status) {struct hl_fence *fence;unsigned long timeout; -long rc; +int rc =0 ; +long completion_rc;if (timeout_us ==MAX_SCHEDULE_TIMEOUT ) timeout = timeout_us;
@@ -1360,11 +1376,17 @@ static long _hl_cs_wait_ioctl(struct hl_device *hdev, seq, ctx->cs_sequence); }else if (fence) {if (!timeout_us) - rc =completion_done (&fence->completion); + completion_rc =completion_done (&fence->completion);else - rc =wait_for_completion_interruptible_timeout ( + completion_rc = +wait_for_completion_interruptible_timeout ( &fence->completion, timeout); +if (completion_rc >0 ) + *status =CS_WAIT_STATUS_COMPLETED ; +else + *status =CS_WAIT_STATUS_BUSY ; +if (fence->error == -ETIMEDOUT ) rc = -ETIMEDOUT ;else if (fence->error == -EIO )
@@ -1375,7 +1397,7 @@ static long _hl_cs_wait_ioctl(struct hl_device *hdev,dev_dbg (hdev->dev,"Can't wait on seq %llu because current CS is at seq %llu (Fence is gone)\n" , seq, ctx->cs_sequence); - rc =1 ; + *status =CS_WAIT_STATUS_GONE ; }hl_ctx_put (ctx);
@@ -1387,14 +1409,16 @@ int hl_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data) {struct hl_device *hdev = hpriv->hdev;union hl_wait_cs_args *args = data; +enum hl_cs_wait_status status;u64 seq = args->in.seq; -long rc; +int rc; - rc =_hl_cs_wait_ioctl (hdev, hpriv->ctx, args->in.timeout_us, seq); + rc =_hl_cs_wait_ioctl (hdev, hpriv->ctx, args->in.timeout_us, seq, + &status);memset (args,0 ,sizeof (*args)); -if (rc <0 ) { +if (rc) {if (rc == -ERESTARTSYS ) { dev_err_ratelimited(hdev->dev, "user process got signal while waiting for CS handle %llu\n",
@@ -1415,10 +1439,18 @@ int hl_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data)return rc; } -if (rc ==0 ) - args->out.status =HL_WAIT_CS_STATUS_BUSY ; -else +switch (status) { +case CS_WAIT_STATUS_GONE : + args->out.flags |=HL_WAIT_CS_STATUS_FLAG_GONE ; + fallthrough; +case CS_WAIT_STATUS_COMPLETED : args->out.status =HL_WAIT_CS_STATUS_COMPLETED ; +break ; +case CS_WAIT_STATUS_BUSY : +default : + args->out.status =HL_WAIT_CS_STATUS_BUSY ; +break ; + }return 0 ; }
include/uapi/misc/habanalabs.h +4 -1
@@ -662,10 +662,13 @@ struct hl_wait_cs_in {#define HL_WAIT_CS_STATUS_ABORTED 3#define HL_WAIT_CS_STATUS_INTERRUPTED 4 +#define HL_WAIT_CS_STATUS_FLAG_GONE 0x1 +struct hl_wait_cs_out {/* HL_WAIT_CS_STATUS_* */ __u32 status; -__u32 pad; +/* HL_WAIT_CS_STATUS_FLAG* */ +__u32 flags; };union hl_wait_cs_args {
Signature · 1 line
2.17.1