[PATCH 08/27] habanalabs: add info when FD released while device still in use

Stanislaw Gruszka stanislaw.gruszka at linux.intel.com
Thu Feb 16 12:25:45 UTC 2023


On Sun, Feb 12, 2023 at 10:44:35PM +0200, Oded Gabbay wrote:
> From: Tomer Tayar <ttayar at habana.ai>
> 
> When user closes the device file descriptor, it is checked whether the
> device is still in use, and a message is printed if it is.

I guess this is only for debugging your user-space component?
Because kernel driver should not make any assumption about
user-space behavior. Closing whenever user wants should be
no problem.

> +static void print_device_in_use_info(struct hl_device *hdev, const char *message)
> +{
> +	u32 active_cs_num, dmabuf_export_cnt;
> +	char buf[64], *buf_ptr = buf;
> +	size_t buf_size = sizeof(buf);
> +	bool unknown_reason = true;
> +
> +	active_cs_num = hl_get_active_cs_num(hdev);
> +	if (active_cs_num) {
> +		unknown_reason = false;
> +		compose_device_in_use_info(&buf_ptr, &buf_size, " [%u active CS]", active_cs_num);
> +	}
> +
> +	dmabuf_export_cnt = atomic_read(&hdev->dmabuf_export_cnt);
> +	if (dmabuf_export_cnt) {
> +		unknown_reason = false;
> +		compose_device_in_use_info(&buf_ptr, &buf_size, " [%u exported dma-buf]",
> +						dmabuf_export_cnt);
> +	}
> +
> +	if (unknown_reason)
> +		compose_device_in_use_info(&buf_ptr, &buf_size, " [unknown reason]");
> +
> +	dev_notice(hdev->dev, "%s%s\n", message, buf);

why not print counters directly, i.e. "active cs count %u, dmabuf export count %u" ?

>  	if (!hl_hpriv_put(hpriv)) {
> -		dev_notice(hdev->dev, "User process closed FD but device still in use\n");
> +		print_device_in_use_info(hdev, "User process closed FD but device still in use");
>  		hl_device_reset(hdev, HL_DRV_RESET_HARD);

You really need reset here ? 

Regards
Stanislaw


More information about the dri-devel mailing list