habanalabs: return correct clock throttling period
PATCH 1/11 habanalabs: return correct clock throttling period
From: Ofir Bitton <[email protected]>
Current clock throttling period returned from driver was wrong due to wrong time comparison.
--- drivers/misc/habanalabs/common/habanalabs_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/habanalabs/common/habanalabs_ioctl.c +2 -2
@@ -335,9 +335,9 @@ static int clk_throttle_info(struct hl_fpriv *hpriv, struct hl_info_args *args)ktime_to_us (hdev->clk_throttling.timestamp[i].start);if (ktime_compare (hdev->clk_throttling.timestamp[i].end, zero_time)) - end_time =ktime_get (); -else end_time = hdev->clk_throttling.timestamp[i].end; +else + end_time =ktime_get (); clk_throttle.clk_throttling_duration_ns[i] = ktime_to_ns(ktime_sub(end_time,
Signature · 1 line
2.25.1
PATCH 2/11 habanalabs: remove in_debug check in device open
The driver supports only a single user anyway, so there is no point in checking whether we are in_debug state when a user tries to open the device, because if we are in_debug, it means a user is already using the device.
--- drivers/misc/habanalabs/common/habanalabs.h | 5 +++-- drivers/misc/habanalabs/common/habanalabs_drv.c | 8 -------- 2 files changed, 3 insertions(+), 10 deletions(-)
drivers/misc/habanalabs/common/habanalabs.h +3 -2
@@ -2561,8 +2561,9 @@ struct last_error_session_info {* @init_done: is the initialization of the device done. * @device_cpu_disabled: is the device CPU disabled (due to timeouts) * @dma_mask: the dma mask that was set for this device -* @in_debug: is device under debug. This, together with fpriv_list, enforces -* that only a single user is configuring the debug infrastructure. +* @in_debug: whether the device is in a state where the profiling/tracing infrastructure +* can be used. This indication is needed because in some ASICs we need to do +* specific operations to enable that infrastructure. * @power9_64bit_dma_enable: true to enable 64-bit DMA mask support. Relevant * only to POWER9 machines. * @cdev_sysfs_created: were char devices and sysfs nodes created.
drivers/misc/habanalabs/common/habanalabs_drv.c +0 -8
@@ -153,14 +153,6 @@ int hl_device_open(struct inode *inode, struct file *filp) goto out_err; } -if (hdev->in_debug) { -dev_err_ratelimited (hdev->dev, -"Can't open %s because it is being debugged by another user\n" , -dev_name (hdev->dev)); - rc = -EPERM ; - goto out_err; - } -if (hdev->is_compute_ctx_active) { dev_dbg_ratelimited(hdev->dev, "Can't open %s because another user is working on it\n",
Signature · 1 line
2.25.1
PATCH 3/11 habanalabs: add current PI value to cpu packets
In reply to Oded GabbayFrom: Ofir Bitton <[email protected]>
In order to increase cpucp messaging reliability we will add the current PI value to the descriptor sent to F/W.
F/W will wait for the PI value as an indication of a valid packet.
--- drivers/misc/habanalabs/common/firmware_if.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/common/firmware_if.c +1 -1
@@ -246,7 +246,7 @@ int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,* Which means that we don't need to lock the access to the entire H/W * queues module when submitting a JOB to the CPU queue. */ -hl_hw_queue_submit_bd (hdev, queue,0 , len, pkt_dma_addr); +hl_hw_queue_submit_bd (hdev, queue,hl_queue_inc_ptr (queue->pi), len, pkt_dma_addr);if (prop->fw_app_cpu_boot_dev_sts0 &CPU_BOOT_DEV_STS0_PKT_PI_ACK_EN ) expected_ack_val = queue->pi;
Signature · 1 line
2.25.1
PATCH 4/11 habanalabs: fix hwmon handling for legacy f/w
In reply to Oded GabbayIn legacy f/w that use old hwmon.h file, the values of the hwmon enums are different than the values that are in newer kernels (5.6 and above).
Therefore, to support working with those f/w, we need to do some fixup before registering with the hwmon subsystem and also when calling the functions that communicate with the f/w to retrieve sensors information.
--- drivers/misc/habanalabs/common/hwmon.c | 201 +++++++++++++++++++++---- 1 file changed, 169 insertions(+), 32 deletions(-)
drivers/misc/habanalabs/common/hwmon.c +169 -32
@@ -10,17 +10,148 @@#include <linux/pci.h> #include <linux/hwmon.h> -#define HWMON_NR_SENSOR_TYPES (hwmon_pwm + 1) +#define HWMON_NR_SENSOR_TYPES (hwmon_max) -int hl_build_hwmon_channel_info (struct hl_device *hdev, -struct cpucp_sensor *sensors_arr) +#ifdef _HAS_HWMON_HWMON_T_ENABLE + +static u32 fixup_flags_legacy_fw (struct hl_device *hdev,enum hwmon_sensor_types type, +u32 cpucp_flags) { -u32 counts[HWMON_NR_SENSOR_TYPES ] = {0 }; -u32 *sensors_by_type[HWMON_NR_SENSOR_TYPES ] = {NULL }; +u32 flags; + +switch (type) { +case hwmon_temp: + flags = (cpucp_flags <<1 ) |HWMON_T_ENABLE ; +break ; + +case hwmon_in: + flags = (cpucp_flags <<1 ) |HWMON_I_ENABLE ; +break ; + +case hwmon_curr: + flags = (cpucp_flags <<1 ) |HWMON_C_ENABLE ; +break ; + +case hwmon_fan: + flags = (cpucp_flags <<1 ) |HWMON_F_ENABLE ; +break ; + +case hwmon_power: + flags = (cpucp_flags <<1 ) |HWMON_P_ENABLE ; +break ; + +case hwmon_pwm: +/* enable bit was here from day 1, so no need to adjust */ + flags = cpucp_flags; +break ; + +default : +dev_err (hdev->dev,"unsupported h/w sensor type %d\n" , type); + flags = cpucp_flags; +break ; + } + +return flags; +} + +static u32 fixup_attr_legacy_fw (u32 attr) +{ +return (attr -1 ); +} + +#else + +static u32 fixup_flags_legacy_fw (struct hl_device *hdev,enum hwmon_sensor_types type, +u32 cpucp_flags) +{ +return cpucp_flags; +} + +static u32 fixup_attr_legacy_fw (u32 attr) +{ +return attr; +} + +#endif /* !_HAS_HWMON_HWMON_T_ENABLE */ + +static u32 adjust_hwmon_flags (struct hl_device *hdev,enum hwmon_sensor_types type,u32 cpucp_flags) +{ +u32 flags, cpucp_input_val; +bool use_cpucp_enum; + + use_cpucp_enum = (hdev->asic_prop.fw_app_cpu_boot_dev_sts0 & +CPU_BOOT_DEV_STS0_MAP_HWMON_EN ) ? true : false; + +/* If f/w is using it's own enum, we need to check if the properties values are aligned. +* If not, it means we need to adjust the values to the new format that is used in the +* kernel since 5.6 (enum values were incremented by 1 by adding a new enable value). +*/ +if (use_cpucp_enum) { +switch (type) { +case hwmon_temp: + cpucp_input_val = cpucp_temp_input; +if (cpucp_input_val == hwmon_temp_input) + flags = cpucp_flags; +else + flags = (cpucp_flags <<1 ) |HWMON_T_ENABLE ; +break ; + +case hwmon_in: + cpucp_input_val = cpucp_in_input; +if (cpucp_input_val == hwmon_in_input) + flags = cpucp_flags; +else + flags = (cpucp_flags <<1 ) |HWMON_I_ENABLE ; +break ; + +case hwmon_curr: + cpucp_input_val = cpucp_curr_input; +if (cpucp_input_val == hwmon_curr_input) + flags = cpucp_flags; +else + flags = (cpucp_flags <<1 ) |HWMON_C_ENABLE ; +break ; + +case hwmon_fan: + cpucp_input_val = cpucp_fan_input; +if (cpucp_input_val == hwmon_fan_input) + flags = cpucp_flags; +else + flags = (cpucp_flags <<1 ) |HWMON_F_ENABLE ; +break ; + +case hwmon_pwm: +/* enable bit was here from day 1, so no need to adjust */ + flags = cpucp_flags; +break ; + +case hwmon_power: + cpucp_input_val =CPUCP_POWER_INPUT ; +if (cpucp_input_val == hwmon_power_input) + flags = cpucp_flags; +else + flags = (cpucp_flags <<1 ) |HWMON_P_ENABLE ; +break ; + +default : +dev_err (hdev->dev,"unsupported h/w sensor type %d\n" , type); + flags = cpucp_flags; +break ; + } + }else { + flags =fixup_flags_legacy_fw (hdev, type, cpucp_flags); + } + +return flags; +} + +int hl_build_hwmon_channel_info (struct hl_device *hdev,struct cpucp_sensor *sensors_arr) +{ +u32 num_sensors_for_type, flags, num_active_sensor_types =0 , arr_size =0 , *curr_arr;u32 sensors_by_type_next_index[HWMON_NR_SENSOR_TYPES ] = {0 }; +u32 *sensors_by_type[HWMON_NR_SENSOR_TYPES ] = {NULL };struct hwmon_channel_info **channels_info; -u32 num_sensors_for_type, num_active_sensor_types =0 , - arr_size =0 , *curr_arr; +u32 counts[HWMON_NR_SENSOR_TYPES ] = {0 };enum hwmon_sensor_types type;int rc, i, j;
@@ -31,8 +162,7 @@ int hl_build_hwmon_channel_info(struct hl_device *hdev,break ;if (type >=HWMON_NR_SENSOR_TYPES ) { -dev_err (hdev->dev, -"Got wrong sensor type %d from device\n" , type); +dev_err (hdev->dev,"Got wrong sensor type %d from device\n" , type);return -EINVAL ; }
@@ -45,8 +175,9 @@ int hl_build_hwmon_channel_info(struct hl_device *hdev,continue ; num_sensors_for_type = counts[i] +1 ; - curr_arr =kcalloc (num_sensors_for_type,sizeof (*curr_arr), -GFP_KERNEL ); +dev_dbg (hdev->dev,"num_sensors_for_type %d = %d\n" , i, num_sensors_for_type); + + curr_arr =kcalloc (num_sensors_for_type,sizeof (*curr_arr),GFP_KERNEL );if (!curr_arr) { rc = -ENOMEM ; goto sensors_type_err;
@@ -59,20 +190,18 @@ int hl_build_hwmon_channel_info(struct hl_device *hdev,for (i =0 ; i < arr_size ; i++) { type =le32_to_cpu (sensors_arr[i].type); curr_arr = sensors_by_type[type]; - curr_arr[sensors_by_type_next_index[type]++] = -le32_to_cpu (sensors_arr[i].flags); + flags =adjust_hwmon_flags (hdev, type,le32_to_cpu (sensors_arr[i].flags)); + curr_arr[sensors_by_type_next_index[type]++] = flags; } - channels_info =kcalloc (num_active_sensor_types +1 , -sizeof (*channels_info),GFP_KERNEL ); + channels_info =kcalloc (num_active_sensor_types +1 ,sizeof (*channels_info),GFP_KERNEL );if (!channels_info) { rc = -ENOMEM ; goto channels_info_array_err; }for (i =0 ; i < num_active_sensor_types ; i++) { - channels_info[i] =kzalloc (sizeof (*channels_info[i]), -GFP_KERNEL ); + channels_info[i] =kzalloc (sizeof (*channels_info[i]),GFP_KERNEL );if (!channels_info[i]) { rc = -ENOMEM ; goto channel_info_err;
@@ -88,18 +217,19 @@ int hl_build_hwmon_channel_info(struct hl_device *hdev, j++; } - hdev->hl_chip_info->info = - (const struct hwmon_channel_info **)channels_info; + hdev->hl_chip_info->info = (const struct hwmon_channel_info **)channels_info;return 0 ; channel_info_err: -for (i =0 ; i < num_active_sensor_types ; i++) +for (i =0 ; i < num_active_sensor_types ; i++) {if (channels_info[i]) {kfree (channels_info[i]->config);kfree (channels_info[i]); } + }kfree (channels_info); + channels_info_array_err: sensors_type_err:for (i =0 ; i <HWMON_NR_SENSOR_TYPES ; i++)
@@ -112,14 +242,16 @@ static int hl_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { struct hl_device *hdev = dev_get_drvdata(dev); -int rc; +bool use_cpucp_enum;u32 cpucp_attr; -bool use_cpucp_enum = (hdev->asic_prop.fw_app_cpu_boot_dev_sts0 & -CPU_BOOT_DEV_STS0_MAP_HWMON_EN ) ? true : false; +int rc;if (!hl_device_operational (hdev,NULL ))return -ENODEV ; + use_cpucp_enum = (hdev->asic_prop.fw_app_cpu_boot_dev_sts0 & +CPU_BOOT_DEV_STS0_MAP_HWMON_EN ) ? true : false; +switch (type) {case hwmon_temp:switch (attr) {
@@ -151,7 +283,7 @@ static int hl_read(struct device *dev, enum hwmon_sensor_types type,if (use_cpucp_enum) rc =hl_get_temperature (hdev, channel, cpucp_attr, val);else - rc =hl_get_temperature (hdev, channel, attr, val); + rc =hl_get_temperature (hdev, channel,fixup_attr_legacy_fw (attr), val);break ;case hwmon_in:switch (attr) {
@@ -174,7 +306,7 @@ static int hl_read(struct device *dev, enum hwmon_sensor_types type,if (use_cpucp_enum) rc =hl_get_voltage (hdev, channel, cpucp_attr, val);else - rc =hl_get_voltage (hdev, channel, attr, val); + rc =hl_get_voltage (hdev, channel,fixup_attr_legacy_fw (attr), val);break ;case hwmon_curr:switch (attr) {
@@ -197,7 +329,7 @@ static int hl_read(struct device *dev, enum hwmon_sensor_types type,if (use_cpucp_enum) rc =hl_get_current (hdev, channel, cpucp_attr, val);else - rc =hl_get_current (hdev, channel, attr, val); + rc =hl_get_current (hdev, channel,fixup_attr_legacy_fw (attr), val);break ;case hwmon_fan:switch (attr) {
@@ -217,7 +349,7 @@ static int hl_read(struct device *dev, enum hwmon_sensor_types type,if (use_cpucp_enum) rc =hl_get_fan_speed (hdev, channel, cpucp_attr, val);else - rc =hl_get_fan_speed (hdev, channel, attr, val); + rc =hl_get_fan_speed (hdev, channel,fixup_attr_legacy_fw (attr), val);break ;case hwmon_pwm:switch (attr) {
@@ -234,6 +366,7 @@ static int hl_read(struct device *dev, enum hwmon_sensor_types type,if (use_cpucp_enum) rc =hl_get_pwm_info (hdev, channel, cpucp_attr, val);else +/* no need for fixup as pwm was aligned from day 1 */ rc =hl_get_pwm_info (hdev, channel, attr, val);break ;case hwmon_power:
@@ -251,7 +384,7 @@ static int hl_read(struct device *dev, enum hwmon_sensor_types type,if (use_cpucp_enum) rc =hl_get_power (hdev, channel, cpucp_attr, val);else - rc =hl_get_power (hdev, channel, attr, val); + rc =hl_get_power (hdev, channel,fixup_attr_legacy_fw (attr), val);break ;default :return -EINVAL ;
@@ -286,7 +419,7 @@ static int hl_write(struct device *dev, enum hwmon_sensor_types type,if (use_cpucp_enum)hl_set_temperature (hdev, channel, cpucp_attr, val);else -hl_set_temperature (hdev, channel, attr, val); +hl_set_temperature (hdev, channel,fixup_attr_legacy_fw (attr), val);break ;case hwmon_pwm:switch (attr) {
@@ -303,6 +436,7 @@ static int hl_write(struct device *dev, enum hwmon_sensor_types type,if (use_cpucp_enum)hl_set_pwm_info (hdev, channel, cpucp_attr, val);else +/* no need for fixup as pwm was aligned from day 1 */ hl_set_pwm_info (hdev, channel, attr, val);break ;case hwmon_in:
@@ -317,7 +451,7 @@ static int hl_write(struct device *dev, enum hwmon_sensor_types type,if (use_cpucp_enum)hl_set_voltage (hdev, channel, cpucp_attr, val);else -hl_set_voltage (hdev, channel, attr, val); +hl_set_voltage (hdev, channel,fixup_attr_legacy_fw (attr), val);break ;case hwmon_curr:switch (attr) {
@@ -331,7 +465,7 @@ static int hl_write(struct device *dev, enum hwmon_sensor_types type,if (use_cpucp_enum)hl_set_current (hdev, channel, cpucp_attr, val);else -hl_set_current (hdev, channel, attr, val); +hl_set_current (hdev, channel,fixup_attr_legacy_fw (attr), val);break ;case hwmon_power:switch (attr) {
@@ -345,7 +479,7 @@ static int hl_write(struct device *dev, enum hwmon_sensor_types type,if (use_cpucp_enum)hl_set_power (hdev, channel, cpucp_attr, val);else -hl_set_power (hdev, channel, attr, val); +hl_set_power (hdev, channel,fixup_attr_legacy_fw (attr), val);break ;default :return -EINVAL ;
@@ -444,6 +578,9 @@ int hl_get_temperature(struct hl_device *hdev, pkt.sensor_index =__cpu_to_le16 (sensor_index); pkt.type =__cpu_to_le16 (attr); +dev_dbg (hdev->dev,"get temp, ctl 0x%x, sensor %d, type %d\n" , + pkt.ctl, pkt.sensor_index, pkt.type); + rc = hdev->asic_funcs->send_cpu_message (hdev, (u32 *) &pkt,sizeof (pkt),0 , &result);
Signature · 1 line
2.25.1
PATCH 5/11 habanalabs: keep control device alive during hard reset
In reply to Oded GabbayFrom: Dani Liberman <[email protected]>
Need to allow user retrieve data during reset and afterwards without the need to reopen the device.
Did it by seperating the user peocesses list into two lists:
1. fpriv_list which contains list of user processes that opened the device (currently only one).
2. fpriv_ctrl_list which contains list of user processes that opened the control device. This processes in this list shall not be killed during reset, only when the device is suddenly removed from PCI chain.
--- drivers/misc/habanalabs/common/context.c | 8 +-- drivers/misc/habanalabs/common/device.c | 56 +++++++++++++------ drivers/misc/habanalabs/common/habanalabs.h | 7 ++- .../misc/habanalabs/common/habanalabs_drv.c | 9 ++- 4 files changed, 50 insertions(+), 30 deletions(-)
drivers/misc/habanalabs/common/context.c +3 -5
@@ -283,11 +283,9 @@ struct hl_ctx *hl_get_compute_ctx(struct hl_device *hdev)/* There can only be a single user which has opened the compute device, so exit * immediately once we find him */ -if (!hpriv->is_control) { - ctx = hpriv->ctx; -hl_ctx_get (hdev, ctx); -break ; - } + ctx = hpriv->ctx; +hl_ctx_get (hdev, ctx); +break ; }mutex_unlock (&hdev->fpriv_list_lock);
drivers/misc/habanalabs/common/device.c +38 -18
152 lines not on this page · raw message
drivers/misc/habanalabs/common/habanalabs.h +5 -2
@@ -1824,7 +1824,6 @@ struct hl_debug_params {* @dev_node: node in the device list of file private data * @refcount: number of related contexts. * @restore_phase_mutex: lock for context switch and restore phase. -* @is_control: true for control device, false otherwise */ struct hl_fpriv {struct hl_device *hdev;
@@ -1837,7 +1836,6 @@ struct hl_fpriv {struct list_head dev_node;struct kref refcount;struct mutex restore_phase_mutex; -u8 is_control; };
@@ -2502,7 +2500,10 @@ struct last_error_session_info {* @internal_cb_va_base: internal cb pool mmu virtual address base * @fpriv_list: list of file private data structures. Each structure is created * when a user opens the device +* @fpriv_ctrl_list: list of file private data structures. Each structure is created +* when a user opens the control device * @fpriv_list_lock: protects the fpriv_list +* @fpriv_ctrl_list_lock: protects the fpriv_ctrl_list * @aggregated_cs_counters: aggregated cs counters among all contexts * @mmu_priv: device-specific MMU data. * @mmu_func: device-related MMU functions.
@@ -2655,7 +2656,9 @@ struct hl_device {u64 internal_cb_va_base;struct list_head fpriv_list; +struct list_head fpriv_ctrl_list;struct mutex fpriv_list_lock; +struct mutex fpriv_ctrl_list_lock;struct hl_cs_counters_atomic aggregated_cs_counters;
drivers/misc/habanalabs/common/habanalabs_drv.c +4 -5
@@ -220,12 +220,11 @@ int hl_device_open_ctrl(struct inode *inode, struct file *filp) hpriv->hdev = hdev; filp->private_data = hpriv; hpriv->filp = filp; - hpriv->is_control = true;nonseekable_open (inode, filp); hpriv->taskpid =find_get_pid (current->pid); -mutex_lock (&hdev->fpriv_list_lock); +mutex_lock (&hdev->fpriv_ctrl_list_lock);if (!hl_device_operational (hdev,NULL )) { dev_err_ratelimited(hdev->dev_ctrl,
@@ -235,13 +234,13 @@ int hl_device_open_ctrl(struct inode *inode, struct file *filp) goto out_err; } -list_add (&hpriv->dev_node, &hdev->fpriv_list); -mutex_unlock (&hdev->fpriv_list_lock); +list_add (&hpriv->dev_node, &hdev->fpriv_ctrl_list); +mutex_unlock (&hdev->fpriv_ctrl_list_lock);return 0 ; out_err: -mutex_unlock (&hdev->fpriv_list_lock); +mutex_unlock (&hdev->fpriv_ctrl_list_lock); filp->private_data =NULL ;put_pid (hpriv->taskpid);
Signature · 1 line
2.25.1
PATCH 8/11 habanalabs: clean MMU headers definitions
In reply to Oded GabbayFrom: Ohad Sharabi <[email protected]>
During the MMU development the MMU header files were left with unclean definitions:
- MMU "version specific" definitions that were left in the mmu_general file
- unused definitions
This patch attempts, where possible, to keep definitions that can serve multiple MMU versions (but that are not tightly bound with specific MMU arch) in the mmu_general header file (e.g. different definitions for number of HOPs).
Otherwise, move MMU version specific definitions (e.g. HOPs masks and shifts) to the specific MMU version file.
--- drivers/misc/habanalabs/common/mmu/mmu_v1.c | 8 +++---- drivers/misc/habanalabs/gaudi/gaudi.c | 24 +++++++++---------- drivers/misc/habanalabs/goya/goya.c | 24 +++++++++---------- .../include/hw_ip/mmu/mmu_general.h | 19 ++++----------- .../habanalabs/include/hw_ip/mmu/mmu_v1_0.h | 18 +++++++++++--- .../habanalabs/include/hw_ip/mmu/mmu_v1_1.h | 20 ++++++++++++---- 6 files changed, 64 insertions(+), 49 deletions(-)
drivers/misc/habanalabs/common/mmu/mmu_v1.c +4 -4
@@ -269,7 +269,7 @@ static int dram_default_mapping_init(struct hl_ctx *ctx) num_of_hop3 = prop->dram_size_for_default_page_mapping;do_div (num_of_hop3, prop->dram_page_size); -do_div (num_of_hop3,PTE_ENTRIES_IN_HOP ); +do_div (num_of_hop3,HOP_PTE_ENTRIES_512 );/* add hop1 and hop2 */ total_hops = num_of_hop3 +2 ;
@@ -330,7 +330,7 @@ static int dram_default_mapping_init(struct hl_ctx *ctx)for (i =0 ; i < num_of_hop3 ; i++) { hop3_pte_addr = ctx->dram_default_hops[i]; -for (j =0 ; j <PTE_ENTRIES_IN_HOP ; j++) { +for (j =0 ; j <HOP_PTE_ENTRIES_512 ; j++) {write_final_pte (ctx, hop3_pte_addr, pte_val);get_pte (ctx, ctx->dram_default_hops[i]); hop3_pte_addr +=HL_PTE_SIZE ;
@@ -369,7 +369,7 @@ static void dram_default_mapping_fini(struct hl_ctx *ctx) num_of_hop3 = prop->dram_size_for_default_page_mapping;do_div (num_of_hop3, prop->dram_page_size); -do_div (num_of_hop3,PTE_ENTRIES_IN_HOP ); +do_div (num_of_hop3,HOP_PTE_ENTRIES_512 ); hop0_addr =get_hop0_addr (ctx);/* add hop1 and hop2 */
@@ -379,7 +379,7 @@ static void dram_default_mapping_fini(struct hl_ctx *ctx)for (i =0 ; i < num_of_hop3 ; i++) { hop3_pte_addr = ctx->dram_default_hops[i]; -for (j =0 ; j <PTE_ENTRIES_IN_HOP ; j++) { +for (j =0 ; j <HOP_PTE_ENTRIES_512 ; j++) {clear_pte (ctx, hop3_pte_addr);put_pte (ctx, ctx->dram_default_hops[i]); hop3_pte_addr +=HL_PTE_SIZE ;
drivers/misc/habanalabs/gaudi/gaudi.c +12 -12
@@ -593,21 +593,21 @@ static int gaudi_set_fixed_properties(struct hl_device *hdev)else prop->mmu_pgt_size =MMU_PAGE_TABLES_SIZE ; prop->mmu_pte_size =HL_PTE_SIZE ; - prop->mmu_hop_table_size =HOP_TABLE_SIZE ; - prop->mmu_hop0_tables_total_size =HOP0_TABLES_TOTAL_SIZE ; + prop->mmu_hop_table_size =HOP_TABLE_SIZE_512_PTE ; + prop->mmu_hop0_tables_total_size =HOP0_512_PTE_TABLES_TOTAL_SIZE ; prop->dram_page_size =PAGE_SIZE_2MB ; prop->dram_supports_virtual_memory = false; - prop->pmmu.hop0_shift =HOP0_SHIFT ; - prop->pmmu.hop1_shift =HOP1_SHIFT ; - prop->pmmu.hop2_shift =HOP2_SHIFT ; - prop->pmmu.hop3_shift =HOP3_SHIFT ; - prop->pmmu.hop4_shift =HOP4_SHIFT ; - prop->pmmu.hop0_mask =HOP0_MASK ; - prop->pmmu.hop1_mask =HOP1_MASK ; - prop->pmmu.hop2_mask =HOP2_MASK ; - prop->pmmu.hop3_mask =HOP3_MASK ; - prop->pmmu.hop4_mask =HOP4_MASK ; + prop->pmmu.hop0_shift =MMU_V1_1_HOP0_SHIFT ; + prop->pmmu.hop1_shift =MMU_V1_1_HOP1_SHIFT ; + prop->pmmu.hop2_shift =MMU_V1_1_HOP2_SHIFT ; + prop->pmmu.hop3_shift =MMU_V1_1_HOP3_SHIFT ; + prop->pmmu.hop4_shift =MMU_V1_1_HOP4_SHIFT ; + prop->pmmu.hop0_mask =MMU_V1_1_HOP0_MASK ; + prop->pmmu.hop1_mask =MMU_V1_1_HOP1_MASK ; + prop->pmmu.hop2_mask =MMU_V1_1_HOP2_MASK ; + prop->pmmu.hop3_mask =MMU_V1_1_HOP3_MASK ; + prop->pmmu.hop4_mask =MMU_V1_1_HOP4_MASK ; prop->pmmu.start_addr =VA_HOST_SPACE_START ; prop->pmmu.end_addr = (VA_HOST_SPACE_START +VA_HOST_SPACE_SIZE /2 ) -1 ;
drivers/misc/habanalabs/goya/goya.c +12 -12
@@ -410,21 +410,21 @@ int goya_set_fixed_properties(struct hl_device *hdev)else prop->mmu_pgt_size =MMU_PAGE_TABLES_SIZE ; prop->mmu_pte_size =HL_PTE_SIZE ; - prop->mmu_hop_table_size =HOP_TABLE_SIZE ; - prop->mmu_hop0_tables_total_size =HOP0_TABLES_TOTAL_SIZE ; + prop->mmu_hop_table_size =HOP_TABLE_SIZE_512_PTE ; + prop->mmu_hop0_tables_total_size =HOP0_512_PTE_TABLES_TOTAL_SIZE ; prop->dram_page_size =PAGE_SIZE_2MB ; prop->dram_supports_virtual_memory = true; - prop->dmmu.hop0_shift =HOP0_SHIFT ; - prop->dmmu.hop1_shift =HOP1_SHIFT ; - prop->dmmu.hop2_shift =HOP2_SHIFT ; - prop->dmmu.hop3_shift =HOP3_SHIFT ; - prop->dmmu.hop4_shift =HOP4_SHIFT ; - prop->dmmu.hop0_mask =HOP0_MASK ; - prop->dmmu.hop1_mask =HOP1_MASK ; - prop->dmmu.hop2_mask =HOP2_MASK ; - prop->dmmu.hop3_mask =HOP3_MASK ; - prop->dmmu.hop4_mask =HOP4_MASK ; + prop->dmmu.hop0_shift =MMU_V1_0_HOP0_SHIFT ; + prop->dmmu.hop1_shift =MMU_V1_0_HOP1_SHIFT ; + prop->dmmu.hop2_shift =MMU_V1_0_HOP2_SHIFT ; + prop->dmmu.hop3_shift =MMU_V1_0_HOP3_SHIFT ; + prop->dmmu.hop4_shift =MMU_V1_0_HOP4_SHIFT ; + prop->dmmu.hop0_mask =MMU_V1_0_HOP0_MASK ; + prop->dmmu.hop1_mask =MMU_V1_0_HOP1_MASK ; + prop->dmmu.hop2_mask =MMU_V1_0_HOP2_MASK ; + prop->dmmu.hop3_mask =MMU_V1_0_HOP3_MASK ; + prop->dmmu.hop4_mask =MMU_V1_0_HOP4_MASK ; prop->dmmu.start_addr =VA_DDR_SPACE_START ; prop->dmmu.end_addr =VA_DDR_SPACE_END ; prop->dmmu.page_size =PAGE_SIZE_2MB ;
drivers/misc/habanalabs/include/hw_ip/mmu/mmu_general.h +5 -14
@@ -16,27 +16,18 @@#define PAGE_PRESENT_MASK 0x0000000000001ull#define SWAP_OUT_MASK 0x0000000000004ull#define LAST_MASK 0x0000000000800ull -#define HOP0_MASK 0x3000000000000ull -#define HOP1_MASK 0x0FF8000000000ull -#define HOP2_MASK 0x0007FC0000000ull -#define HOP3_MASK 0x000003FE00000ull -#define HOP4_MASK 0x00000001FF000ull#define FLAGS_MASK 0x0000000000FFFull -#define HOP0_SHIFT 48 -#define HOP1_SHIFT 39 -#define HOP2_SHIFT 30 -#define HOP3_SHIFT 21 -#define HOP4_SHIFT 12 -#define MMU_ARCH_5_HOPS 5#define HOP_PHYS_ADDR_MASK (~FLAGS_MASK)#define HL_PTE_SIZE sizeof(u64) -#define HOP_TABLE_SIZE PAGE_SIZE_4KB -#define PTE_ENTRIES_IN_HOP (HOP_TABLE_SIZE / HL_PTE_SIZE) -#define HOP0_TABLES_TOTAL_SIZE (HOP_TABLE_SIZE * MAX_ASID) + +/* definitions for HOP with 512 PTE entries */ +#define HOP_PTE_ENTRIES_512 512 +#define HOP_TABLE_SIZE_512_PTE (HOP_PTE_ENTRIES_512 * HL_PTE_SIZE) +#define HOP0_512_PTE_TABLES_TOTAL_SIZE (HOP_TABLE_SIZE_512_PTE * MAX_ASID)#define MMU_HOP0_PA43_12_SHIFT 12#define MMU_HOP0_PA49_44_SHIFT (12 + 32)
drivers/misc/habanalabs/include/hw_ip/mmu/mmu_v1_0.h +15 -3
@@ -8,8 +8,20 @@#ifndef INCLUDE_MMU_V1_0_H_ #define INCLUDE_MMU_V1_0_H_ -#define MMU_HOP0_PA43_12 0x490004 -#define MMU_HOP0_PA49_44 0x490008 -#define MMU_ASID_BUSY 0x490000 +#define MMU_V1_0_HOP0_MASK 0x3000000000000ull +#define MMU_V1_0_HOP1_MASK 0x0FF8000000000ull +#define MMU_V1_0_HOP2_MASK 0x0007FC0000000ull +#define MMU_V1_0_HOP3_MASK 0x000003FE00000ull +#define MMU_V1_0_HOP4_MASK 0x00000001FF000ull + +#define MMU_V1_0_HOP0_SHIFT 48 +#define MMU_V1_0_HOP1_SHIFT 39 +#define MMU_V1_0_HOP2_SHIFT 30 +#define MMU_V1_0_HOP3_SHIFT 21 +#define MMU_V1_0_HOP4_SHIFT 12 + +#define MMU_HOP0_PA43_12 0x490004 +#define MMU_HOP0_PA49_44 0x490008 +#define MMU_ASID_BUSY 0x490000#endif /* INCLUDE_MMU_V1_0_H_ */
drivers/misc/habanalabs/include/hw_ip/mmu/mmu_v1_1.h +16 -4
@@ -8,9 +8,21 @@#ifndef INCLUDE_MMU_V1_1_H_ #define INCLUDE_MMU_V1_1_H_ -#define MMU_ASID 0xC12004 -#define MMU_HOP0_PA43_12 0xC12008 -#define MMU_HOP0_PA49_44 0xC1200C -#define MMU_BUSY 0xC12000 +#define MMU_V1_1_HOP0_MASK 0x3000000000000ull +#define MMU_V1_1_HOP1_MASK 0x0FF8000000000ull +#define MMU_V1_1_HOP2_MASK 0x0007FC0000000ull +#define MMU_V1_1_HOP3_MASK 0x000003FE00000ull +#define MMU_V1_1_HOP4_MASK 0x00000001FF000ull + +#define MMU_V1_1_HOP0_SHIFT 48 +#define MMU_V1_1_HOP1_SHIFT 39 +#define MMU_V1_1_HOP2_SHIFT 30 +#define MMU_V1_1_HOP3_SHIFT 21 +#define MMU_V1_1_HOP4_SHIFT 12 + +#define MMU_ASID 0xC12004 +#define MMU_HOP0_PA43_12 0xC12008 +#define MMU_HOP0_PA49_44 0xC1200C +#define MMU_BUSY 0xC12000#endif /* INCLUDE_MMU_V1_1_H_ */
Signature · 1 line
2.25.1
PATCH 7/11 habanalabs: expose soft reset sysfs nodes for inference ASIC
In reply to Oded GabbayFrom: Ofir Bitton <[email protected]>
As we allow soft-reset to be performed only on inference devices, having the sysfs nodes may cause a confusion. Hence, we remove those nodes on training ASICs.
--- drivers/misc/habanalabs/common/sysfs.c | 32 ++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
drivers/misc/habanalabs/common/sysfs.c +30 -2
@@ -424,8 +424,6 @@ static struct attribute *hl_dev_attrs[] = { &dev_attr_max_power.attr, &dev_attr_pci_addr.attr, &dev_attr_preboot_btl_ver.attr, - &dev_attr_soft_reset.attr, - &dev_attr_soft_reset_cnt.attr, &dev_attr_status.attr, &dev_attr_thermal_ver.attr, &dev_attr_uboot_ver.attr,
@@ -450,6 +448,21 @@ static const struct attribute_group *hl_dev_attr_groups[] = { NULL, }; +static struct attribute *hl_dev_inference_attrs[] = { + &dev_attr_soft_reset.attr, + &dev_attr_soft_reset_cnt.attr, +NULL , +}; + +static struct attribute_group hl_dev_inference_attr_group = { + .attrs = hl_dev_inference_attrs, +}; + +static const struct attribute_group *hl_dev_inference_attr_groups[] = { + &hl_dev_inference_attr_group, +NULL , +}; +int hl_sysfs_init (struct hl_device *hdev) {int rc;
@@ -465,10 +478,25 @@ int hl_sysfs_init(struct hl_device *hdev)return rc; } +if (!hdev->allow_inference_soft_reset) +return 0 ; + + rc =device_add_groups (hdev->dev, hl_dev_inference_attr_groups); +if (rc) { +dev_err (hdev->dev, +"Failed to add groups to device, error %d\n" , rc); +return rc; + } +return 0 ; }void hl_sysfs_fini (struct hl_device *hdev) {device_remove_groups (hdev->dev, hl_dev_attr_groups); + +if (!hdev->allow_inference_soft_reset) +return ; + +device_remove_groups (hdev->dev, hl_dev_inference_attr_groups); }
Signature · 1 line
2.25.1
PATCH 6/11 habanalabs: sysfs support for two infineon versions
In reply to Oded GabbayFrom: Ofir Bitton <[email protected]>
Currently sysfs support dumping a single infineon version, in future asics we will have two infineon versions.
--- drivers/misc/habanalabs/common/sysfs.c | 9 +++++++-- drivers/misc/habanalabs/include/common/cpucp_if.h | 13 ++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-)
drivers/misc/habanalabs/common/sysfs.c +7 -2
@@ -163,8 +163,13 @@ static ssize_t infineon_ver_show(struct device *dev, {struct hl_device *hdev =dev_get_drvdata (dev); -return sprintf (buf,"0x%04x\n" , - hdev->asic_prop.cpucp_info.infineon_version); +if (hdev->asic_prop.cpucp_info.infineon_version2) +return sprintf (buf,"%#04x %#04x\n" , +le32_to_cpu (hdev->asic_prop.cpucp_info.infineon_version), +le32_to_cpu (hdev->asic_prop.cpucp_info.infineon_version2)); +else +return sprintf (buf,"%#04x\n" , +le32_to_cpu (hdev->asic_prop.cpucp_info.infineon_version)); } static ssize_t fuse_ver_show(struct device *dev, struct device_attribute *attr,
drivers/misc/habanalabs/include/common/cpucp_if.h +10 -3
@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 * -* Copyright 2021 HabanaLabs, Ltd. +* Copyright 2020-2021 HabanaLabs, Ltd. * All Rights Reserved. * */
@@ -761,6 +761,7 @@ struct cpucp_security_info {* @fuse_version: silicon production FUSE information. * @thermal_version: thermald S/W version. * @cpucp_version: CpuCP S/W version. +* @infineon_version2: Infineon 2nd stage DC-DC version. * @dram_size: available DRAM size. * @card_name: card name that will be displayed in HWMON subsystem on the host * @sec_info: security information
@@ -770,6 +771,10 @@ struct cpucp_security_info {* @dram_binning_mask: DRAM binning mask, 1 bit per dram instance * (0 = functional 1 = binned) * @memory_repair_flag: eFuse flag indicating memory repair +* @edma_binning_mask: EDMA binning mask, 1 bit per EDMA instance +* (0 = functional 1 = binned) +* @xbar_binning_mask: Xbar binning mask, 1 bit per Xbar instance +* (0 = functional 1 = binned) */ struct cpucp_info {struct cpucp_sensor sensors[CPUCP_MAX_SENSORS ];
@@ -782,7 +787,7 @@ struct cpucp_info {__u8 fuse_version[VERSION_MAX_LEN ];__u8 thermal_version[VERSION_MAX_LEN ];__u8 cpucp_version[VERSION_MAX_LEN ]; -__le32 reserved2; +__le32 infineon_version2;__le64 dram_size;char card_name[CARD_NAME_MAX_LEN ];__le64 reserved3;
@@ -790,7 +795,9 @@ struct cpucp_info {__u8 reserved5;__u8 dram_binning_mask;__u8 memory_repair_flag; -__u8 pad[5 ]; +__u8 edma_binning_mask; +__u8 xbar_binning_mask; +__u8 pad[3 ];struct cpucp_security_info sec_info;__le32 reserved6;__u8 pll_map[PLL_MAP_LEN ];
Signature · 1 line
2.25.1
PATCH 9/11 habanalabs: modify cpu boot status error print
In reply to Oded GabbayFrom: Ofir Bitton <[email protected]>
As BTL can be replaced by ROM we should modify relevant error print.
--- drivers/misc/habanalabs/common/firmware_if.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/common/firmware_if.c +1 -1
@@ -1103,7 +1103,7 @@ static void detect_cpu_boot_status(struct hl_device *hdev, u32 status)switch (status) {case CPU_BOOT_STATUS_NA :dev_err (hdev->dev, -"Device boot progress - BTL did NOT run\n" ); +"Device boot progress - BTL/ROM did NOT run\n" );break ;case CPU_BOOT_STATUS_IN_WFE : dev_err(hdev->dev,
Signature · 1 line
2.25.1
PATCH 10/11 habanalabs: prevent wait if CS in multi-CS list completed
In reply to Oded GabbayFrom: Ohad Sharabi <[email protected]>
By the original design we assumed that if we "miss" multi CS completion it is of no severe consequence as we'll just call wait_for_multi_cs again.
Sequence of events for such scenario:
1. user submit CS with sequence N
2. user calls wait for multi-CS with only CS #N in the list
3. the multi CS call starts with poll of the CSs but find that none completed (while CS #N did not completed yet)
4. now, multi CS #N complete but multi CS CTX was not yet created for the above multi-CS. so, attempt to complete multi-CS fails (as no multi CS CTX exist)
5. wait_for_multi_cs call now does init_wait_multi_cs_completion (and for this create the multi-CS CTX)
6. wait_for_multi_cs wits on completion but will not get one as CS #N already completed
To fix the issue we initialize the multi-CS CTX prior polling the fences.
--- .../habanalabs/common/command_submission.c | 85 ++++++++++++------- drivers/misc/habanalabs/common/habanalabs.h | 3 - 2 files changed, 54 insertions(+), 34 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +54 -31
@@ -533,8 +533,8 @@ static void complete_multi_cs(struct hl_device *hdev, struct hl_cs *cs) mcs_compl->stream_master_qid_map)) {/* extract the timestamp only of first completed CS */ if (!mcs_compl->timestamp) - mcs_compl->timestamp = -ktime_to_ns (fence->timestamp); + mcs_compl->timestamp =ktime_to_ns (fence->timestamp); +complete_all (&mcs_compl->completion);/*
@@ -2369,16 +2369,18 @@ static int hl_wait_for_fence(struct hl_ctx *ctx, u64 seq, struct hl_fence *fence* hl_cs_poll_fences - iterate CS fences to check for CS completion * * @mcs_data: multi-CS internal data +* @mcs_compl: multi-CS completion structure * * @return 0 on success, otherwise non 0 error code * * The function iterates on all CS sequence in the list and set bit in * completion_bitmap for each completed CS. -* while iterating, the function can extracts the stream map to be later -* used by the waiting function. -* this function shall be called after taking context ref +* While iterating, the function sets the stream map of each fence in the fence +* array in the completion QID stream map to be used by CSs to perform +* completion to the multi-CS context. +* This function shall be called after taking context ref */ -static int hl_cs_poll_fences (struct multi_cs_data *mcs_data) +static int hl_cs_poll_fences (struct multi_cs_data *mcs_data,struct multi_cs_completion *mcs_compl) {struct hl_fence **fence_ptr = mcs_data->fence_arr;struct hl_device *hdev = mcs_data->ctx->hdev;
@@ -2394,6 +2396,15 @@ static int hl_cs_poll_fences(struct multi_cs_data *mcs_data)if (rc)return rc; +/* +* re-initialize the completion here to handle 2 possible cases: +* 1. CS will complete the multi-CS prior clearing the completion. in which +* case the fence iteration is guaranteed to catch the CS completion. +* 2. the completion will occur after re-init of the completion. +* in which case we will wake up immediately in wait_for_completion. +*/ +reinit_completion (&mcs_compl->completion); +/* * set to maximum time to verify timestamp is valid: if at the end * this value is maintained- no timestamp was updated
@@ -2404,6 +2415,21 @@ static int hl_cs_poll_fences(struct multi_cs_data *mcs_data)for (i =0 ; i < arr_len; i++, fence_ptr++) {struct hl_fence *fence = *fence_ptr; +/* +* In order to prevent case where we wait until timeout even though a CS associated +* with the multi-CS actually completed we do things in the below order: +* 1. for each fence set it's QID map in the multi-CS completion QID map. This way +* any CS can, potentially, complete the multi CS for the specific QID (note +* that once completion is initialized, calling complete* and then wait on the +* completion will cause it to return at once) +* 2. only after allowing multi-CS completion for the specific QID we check whether +* the specific CS already completed (and thus the wait for completion part will +* be skipped). if the CS not completed it is guaranteed that completing CS will +* wake up the completion. +*/ +if (fence) + mcs_compl->stream_master_qid_map |= fence->stream_master_qid_map; +/* * function won't sleep as it is called with timeout 0 (i.e. * poll the fence)
@@ -2419,9 +2445,7 @@ static int hl_cs_poll_fences(struct multi_cs_data *mcs_data)switch (status) {case CS_WAIT_STATUS_BUSY : -/* CS did not finished, keep waiting on its QID*/ - mcs_data->stream_master_qid_map |= - fence->stream_master_qid_map; +/* CS did not finished, QID to wait on already stored */ break ;case CS_WAIT_STATUS_COMPLETED :/*
@@ -2519,9 +2543,7 @@ static inline unsigned long hl_usecs64_to_jiffies(const u64 usecs)* the function gets the first available completion (by marking it "used") * and initialize its values. */ -static struct multi_cs_completion *hl_wait_multi_cs_completion_init ( -struct hl_device *hdev, -u8 stream_master_bitmap) +static struct multi_cs_completion *hl_wait_multi_cs_completion_init (struct hl_device *hdev) {struct multi_cs_completion *mcs_compl;int i;
@@ -2533,8 +2555,11 @@ static struct multi_cs_completion *hl_wait_multi_cs_completion_init(if (!mcs_compl->used) { mcs_compl->used =1 ; mcs_compl->timestamp =0 ; - mcs_compl->stream_master_qid_map = stream_master_bitmap; -reinit_completion (&mcs_compl->completion); +/* +* init QID map to 0 to avoid completion by CSs. the actual QID map +* to multi-CS CSs will be set incrementally at a later stage +*/ + mcs_compl->stream_master_qid_map =0 ;spin_unlock (&mcs_compl->lock);break ; }
@@ -2672,9 +2697,17 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data)hl_ctx_get (hdev, ctx); +/* wait (with timeout) for the first CS to be completed */ + mcs_data.timeout_jiffies =hl_usecs64_to_jiffies (args->in.timeout_us); + mcs_compl =hl_wait_multi_cs_completion_init (hdev); +if (IS_ERR (mcs_compl)) { + rc =PTR_ERR (mcs_compl); + goto put_ctx; + } +/* poll all CS fences, extract timestamp */ mcs_data.update_ts = true; - rc =hl_cs_poll_fences (&mcs_data); + rc =hl_cs_poll_fences (&mcs_data, mcs_compl);/* * skip wait for CS completion when one of the below is true: * - an error on the poll function
@@ -2682,16 +2715,7 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data)* - the user called ioctl with timeout 0 */ if (rc || mcs_data.completion_bitmap || !args->in.timeout_us) - goto put_ctx; - -/* wait (with timeout) for the first CS to be completed */ - mcs_data.timeout_jiffies =hl_usecs64_to_jiffies (args->in.timeout_us); - - mcs_compl =hl_wait_multi_cs_completion_init (hdev, mcs_data.stream_master_qid_map); -if (IS_ERR (mcs_compl)) { - rc =PTR_ERR (mcs_compl); - goto put_ctx; - } + goto completion_fini;while (true) { rc =hl_wait_multi_cs_completion (&mcs_data, mcs_compl);
@@ -2703,7 +2727,7 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data)* no timestamp should be updated this time. */ mcs_data.update_ts = false; - rc =hl_cs_poll_fences (&mcs_data); + rc =hl_cs_poll_fences (&mcs_data, mcs_compl);if (mcs_data.completion_bitmap)break ;
@@ -2713,16 +2737,15 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data)* it got a completion) it either got completed by CS in the multi CS list * (in which case the indication will be non empty completion_bitmap) or it * got completed by CS submitted to one of the shared stream master but -* not in the multi CS list (in which case we should wait again but reinit -* the completion, modify the timeout and set timestamp as zero to let a CS -* related to the current multi-CS set a new, relevant, timestamp) +* not in the multi CS list (in which case we should wait again but modify +* the timeout and set timestamp as zero to let a CS related to the current +* multi-CS set a new, relevant, timestamp) */ -/* wait again with modified timeout */ mcs_data.timeout_jiffies = mcs_data.wait_status; -reinit_completion (&mcs_compl->completion); mcs_compl->timestamp =0 ; } +completion_fini:hl_wait_multi_cs_completion_fini (mcs_compl); put_ctx:
drivers/misc/habanalabs/common/habanalabs.h +0 -3
@@ -2364,8 +2364,6 @@ struct multi_cs_completion {* @timestamp: timestamp of first completed CS * @wait_status: wait for CS status * @completion_bitmap: bitmap of completed CSs (1- completed, otherwise 0) -* @stream_master_qid_map: bitmap of all stream master QIDs on which the -* multi-CS is waiting * @arr_len: fence_arr and seq_arr array length * @gone_cs: indication of gone CS (1- there was gone CS, otherwise 0) * @update_ts: update timestamp. 1- update the timestamp, otherwise 0.
@@ -2378,7 +2376,6 @@ struct multi_cs_data {s64 timestamp;long wait_status;u32 completion_bitmap; -u32 stream_master_qid_map;u8 arr_len;u8 gone_cs;u8 update_ts;
Signature · 1 line
2.25.1
PATCH 11/11 habanalabs: change wait_for_interrupt implementation
In reply to Oded GabbayFrom: farah kassabri <[email protected]>
Currently the cq counters are allocated in userspace memory, and mapped by the driver to the device address space.
A new requirement that is part of new future API related to this one, requires that cq counters will be allocated in kernel memory.
We leverage the existing cb_create API with KERNEL_MAPPED flag set to allocate this memory.
That way we gain two things:
1. The memory cannot be freed while in use since it's protected by refcount in driver.
2. No need to wake up the user thread upon each interrupt from CQ, because the kernel has direct access to the counter. Therefore, it can make comparison with the target value in the interrupt handler and wake up the user thread only if the counter reaches the target value. This is instead of waking the thread up to copy counter value from user then go sleep again if target value wasn't reached.
--- .../misc/habanalabs/common/command_buffer.c | 31 ++++- .../habanalabs/common/command_submission.c | 111 +++++++++++++++++- drivers/misc/habanalabs/common/habanalabs.h | 5 + drivers/misc/habanalabs/common/irq.c | 8 +- include/uapi/misc/habanalabs.h | 61 +++++++--- 5 files changed, 189 insertions(+), 27 deletions(-)
drivers/misc/habanalabs/common/command_buffer.c +25 -6
@@ -380,8 +380,9 @@ int hl_cb_destroy(struct hl_device *hdev, struct hl_cb_mgr *mgr, u64 cb_handle) }static int hl_cb_info (struct hl_device *hdev,struct hl_cb_mgr *mgr, -u64 cb_handle,u32 *usage_cnt) +u64 cb_handle,u32 flags,u32 *usage_cnt,u64 *device_va) { +struct hl_vm_va_block *va_block;struct hl_cb *cb;u32 handle;int rc =0 ;
@@ -402,7 +403,18 @@ static int hl_cb_info(struct hl_device *hdev, struct hl_cb_mgr *mgr, goto out; } - *usage_cnt =atomic_read (&cb->cs_cnt); +if (flags &HL_CB_FLAGS_GET_DEVICE_VA ) { + va_block = list_first_entry(&cb->va_block_list, struct hl_vm_va_block, node); +if (va_block) { + *device_va = va_block->start; + }else { +dev_err (hdev->dev,"CB is not mapped to the device's MMU\n" ); + rc = -EINVAL ; + goto out; + } + }else { + *usage_cnt =atomic_read (&cb->cs_cnt); + } out:spin_unlock (&mgr->cb_lock);
@@ -414,7 +426,7 @@ int hl_cb_ioctl(struct hl_fpriv *hpriv, void *data)union hl_cb_args *args = data;struct hl_device *hdev = hpriv->hdev;enum hl_device_status status; -u64 handle =0 ; +u64 handle =0 , device_va;u32 usage_cnt =0 ;int rc;
@@ -450,9 +462,16 @@ int hl_cb_ioctl(struct hl_fpriv *hpriv, void *data)case HL_CB_OP_INFO : rc =hl_cb_info (hdev, &hpriv->cb_mgr, args->in.cb_handle, - &usage_cnt); -memset (args,0 ,sizeof (*args)); - args->out.usage_cnt = usage_cnt; + args->in.flags, + &usage_cnt, + &device_va); + +memset (&args->out,0 ,sizeof (args->out)); + +if (args->in.flags &HL_CB_FLAGS_GET_DEVICE_VA ) + args->out.device_va = device_va; +else + args->out.usage_cnt = usage_cnt;break ;default :
drivers/misc/habanalabs/common/command_submission.c +109 -2
129 lines not on this page · raw message
drivers/misc/habanalabs/common/habanalabs.h +5 -0
@@ -876,10 +876,15 @@ struct hl_user_interrupt {* pending on an interrupt * @wait_list_node: node in the list of user threads pending on an interrupt * @fence: hl fence object for interrupt completion +* @cq_target_value: CQ target value +* @cq_kernel_addr: CQ kernel address, to be used in the cq interrupt +* handler for taget value comparison */ struct hl_user_pending_interrupt {struct list_head wait_list_node;struct hl_fence fence; +u64 cq_target_value; +u64 *cq_kernel_addr; };/**
drivers/misc/habanalabs/common/irq.c +6 -2
@@ -145,8 +145,12 @@ static void handle_user_cq(struct hl_device *hdev,spin_lock (&user_cq->wait_list_lock);list_for_each_entry (pend, &user_cq->wait_list_head, wait_list_node) { - pend->fence.timestamp = now; -complete_all (&pend->fence.completion); +if ((pend->cq_kernel_addr && + *(pend->cq_kernel_addr) >= pend->cq_target_value) || + !pend->cq_kernel_addr) { + pend->fence.timestamp = now; +complete_all (&pend->fence.completion); + } }spin_unlock (&user_cq->wait_list_lock); }
include/uapi/misc/habanalabs.h +44 -17
91 lines not on this page · raw message
Signature · 1 line
2.25.1