device.c (323adae99f99e900eedb9d3aba9ded9bf5a20c05) device.c (d43bce6e762f25b25685487630510452feaf7362)
1// SPDX-License-Identifier: GPL-2.0
2
3/*
4 * Copyright 2016-2022 HabanaLabs, Ltd.
5 * All Rights Reserved.
6 */
7
8#define pr_fmt(fmt) "habanalabs: " fmt

--- 478 unchanged lines hidden (view full) ---

487 kref_get(&hpriv->refcount);
488}
489
490int hl_hpriv_put(struct hl_fpriv *hpriv)
491{
492 return kref_put(&hpriv->refcount, hpriv_release);
493}
494
1// SPDX-License-Identifier: GPL-2.0
2
3/*
4 * Copyright 2016-2022 HabanaLabs, Ltd.
5 * All Rights Reserved.
6 */
7
8#define pr_fmt(fmt) "habanalabs: " fmt

--- 478 unchanged lines hidden (view full) ---

487 kref_get(&hpriv->refcount);
488}
489
490int hl_hpriv_put(struct hl_fpriv *hpriv)
491{
492 return kref_put(&hpriv->refcount, hpriv_release);
493}
494
495static void compose_device_in_use_info(char **buf, size_t *buf_size, const char *fmt, ...)
496{
497 struct va_format vaf;
498 va_list args;
499 int size;
500
501 va_start(args, fmt);
502 vaf.fmt = fmt;
503 vaf.va = &args;
504
505 size = snprintf(*buf, *buf_size, "%pV", &vaf);
506 if (size >= *buf_size)
507 size = *buf_size;
508
509 *buf += size;
510 *buf_size -= size;
511
512 va_end(args);
513}
514
515static void print_device_in_use_info(struct hl_device *hdev, const char *message)
516{
517 u32 active_cs_num, dmabuf_export_cnt;
518 char buf[64], *buf_ptr = buf;
519 size_t buf_size = sizeof(buf);
520 bool unknown_reason = true;
521
522 active_cs_num = hl_get_active_cs_num(hdev);
523 if (active_cs_num) {
524 unknown_reason = false;
525 compose_device_in_use_info(&buf_ptr, &buf_size, " [%u active CS]", active_cs_num);
526 }
527
528 dmabuf_export_cnt = atomic_read(&hdev->dmabuf_export_cnt);
529 if (dmabuf_export_cnt) {
530 unknown_reason = false;
531 compose_device_in_use_info(&buf_ptr, &buf_size, " [%u exported dma-buf]",
532 dmabuf_export_cnt);
533 }
534
535 if (unknown_reason)
536 compose_device_in_use_info(&buf_ptr, &buf_size, " [unknown reason]");
537
538 dev_notice(hdev->dev, "%s%s\n", message, buf);
539}
540
495/*
496 * hl_device_release - release function for habanalabs device
497 *
498 * @inode: pointer to inode structure
499 * @filp: pointer to file structure
500 *
501 * Called when process closes an habanalabs device
502 */

--- 11 unchanged lines hidden (view full) ---

514 }
515
516 hl_ctx_mgr_fini(hdev, &hpriv->ctx_mgr);
517 hl_mem_mgr_fini(&hpriv->mem_mgr);
518
519 hdev->compute_ctx_in_release = 1;
520
521 if (!hl_hpriv_put(hpriv)) {
541/*
542 * hl_device_release - release function for habanalabs device
543 *
544 * @inode: pointer to inode structure
545 * @filp: pointer to file structure
546 *
547 * Called when process closes an habanalabs device
548 */

--- 11 unchanged lines hidden (view full) ---

560 }
561
562 hl_ctx_mgr_fini(hdev, &hpriv->ctx_mgr);
563 hl_mem_mgr_fini(&hpriv->mem_mgr);
564
565 hdev->compute_ctx_in_release = 1;
566
567 if (!hl_hpriv_put(hpriv)) {
522 dev_notice(hdev->dev, "User process closed FD but device still in use\n");
568 print_device_in_use_info(hdev, "User process closed FD but device still in use");
523 hl_device_reset(hdev, HL_DRV_RESET_HARD);
524 }
525
569 hl_device_reset(hdev, HL_DRV_RESET_HARD);
570 }
571
526 hdev->last_open_session_duration_jif =
527 jiffies - hdev->last_successful_open_jif;
572 hdev->last_open_session_duration_jif = jiffies - hdev->last_successful_open_jif;
528
529 return 0;
530}
531
532static int hl_device_release_ctrl(struct inode *inode, struct file *filp)
533{
534 struct hl_fpriv *hpriv = filp->private_data;
535 struct hl_device *hdev = hpriv->hdev;

--- 2048 unchanged lines hidden ---
573
574 return 0;
575}
576
577static int hl_device_release_ctrl(struct inode *inode, struct file *filp)
578{
579 struct hl_fpriv *hpriv = filp->private_data;
580 struct hl_device *hdev = hpriv->hdev;

--- 2048 unchanged lines hidden ---