LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] habanalabs: add print upon clock change
@ 2020-03-09 11:25 Omer Shpigelman
  2020-03-09 11:51 ` Oded Gabbay
  0 siblings, 1 reply; 2+ messages in thread
From: Omer Shpigelman @ 2020-03-09 11:25 UTC (permalink / raw)
  To: oded.gabbay; +Cc: linux-kernel

Add print upon clock slow down due to power consumption or overheating.
In addition, add print when back to optimal clock.

Signed-off-by: Omer Shpigelman <oshpigelman@habana.ai>
---
 drivers/misc/habanalabs/goya/goya.c           | 50 ++++++++++++++++++-
 .../include/goya/goya_async_events.h          |  4 ++
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/habanalabs/goya/goya.c b/drivers/misc/habanalabs/goya/goya.c
index 9d4295cc83cf..1ccf2ed9a8dc 100644
--- a/drivers/misc/habanalabs/goya/goya.c
+++ b/drivers/misc/habanalabs/goya/goya.c
@@ -324,7 +324,11 @@ static u32 goya_all_events[] = {
 	GOYA_ASYNC_EVENT_ID_DMA_BM_CH1,
 	GOYA_ASYNC_EVENT_ID_DMA_BM_CH2,
 	GOYA_ASYNC_EVENT_ID_DMA_BM_CH3,
-	GOYA_ASYNC_EVENT_ID_DMA_BM_CH4
+	GOYA_ASYNC_EVENT_ID_DMA_BM_CH4,
+	GOYA_ASYNC_EVENT_ID_POWER_ENV_S,
+	GOYA_ASYNC_EVENT_ID_POWER_ENV_E,
+	GOYA_ASYNC_EVENT_ID_THERMAL_ENV_S,
+	GOYA_ASYNC_EVENT_ID_THERMAL_ENV_E
 };
 
 static int goya_mmu_clear_pgt_range(struct hl_device *hdev);
@@ -4389,6 +4393,14 @@ static const char *_goya_get_event_desc(u16 event_type)
 		return "TPC%d_bmon_spmu";
 	case GOYA_ASYNC_EVENT_ID_DMA_BM_CH0 ... GOYA_ASYNC_EVENT_ID_DMA_BM_CH4:
 		return "DMA_bm_ch%d";
+	case GOYA_ASYNC_EVENT_ID_POWER_ENV_S:
+		return "POWER_ENV_S";
+	case GOYA_ASYNC_EVENT_ID_POWER_ENV_E:
+		return "POWER_ENV_E";
+	case GOYA_ASYNC_EVENT_ID_THERMAL_ENV_S:
+		return "THERMAL_ENV_S";
+	case GOYA_ASYNC_EVENT_ID_THERMAL_ENV_E:
+		return "THERMAL_ENV_E";
 	default:
 		return "N/A";
 	}
@@ -4619,6 +4631,33 @@ static int goya_unmask_irq(struct hl_device *hdev, u16 event_type)
 	return rc;
 }
 
+static void goya_print_clk_change_info(struct hl_device *hdev, u16 event_type)
+{
+	switch (event_type) {
+	case GOYA_ASYNC_EVENT_ID_POWER_ENV_S:
+		dev_info_ratelimited(hdev->dev,
+			"Clock throttling due to power consumption\n");
+		break;
+	case GOYA_ASYNC_EVENT_ID_POWER_ENV_E:
+		dev_info_ratelimited(hdev->dev,
+			"Power envelop is safe, back to optimal clock\n");
+		break;
+	case GOYA_ASYNC_EVENT_ID_THERMAL_ENV_S:
+		dev_info_ratelimited(hdev->dev,
+			"Clock throttling due to overheating\n");
+		break;
+	case GOYA_ASYNC_EVENT_ID_THERMAL_ENV_E:
+		dev_info_ratelimited(hdev->dev,
+			"Thermal envelop is safe, back to optimal clock\n");
+		break;
+
+	default:
+		dev_err(hdev->dev, "Received invalid clock change event %d\n",
+			event_type);
+		break;
+	}
+}
+
 void goya_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_entry)
 {
 	u32 ctl = le32_to_cpu(eq_entry->hdr.ctl);
@@ -4702,6 +4741,15 @@ void goya_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_entry)
 		goya_unmask_irq(hdev, event_type);
 		break;
 
+	case GOYA_ASYNC_EVENT_ID_POWER_ENV_S:
+	case GOYA_ASYNC_EVENT_ID_POWER_ENV_E:
+	case GOYA_ASYNC_EVENT_ID_THERMAL_ENV_S:
+	case GOYA_ASYNC_EVENT_ID_THERMAL_ENV_E:
+		goya_print_irq_info(hdev, event_type, false);
+		goya_print_clk_change_info(hdev, event_type);
+		goya_unmask_irq(hdev, event_type);
+		break;
+
 	default:
 		dev_err(hdev->dev, "Received invalid H/W interrupt %d\n",
 				event_type);
diff --git a/drivers/misc/habanalabs/include/goya/goya_async_events.h b/drivers/misc/habanalabs/include/goya/goya_async_events.h
index bb7a1aa3279e..6be41a846c99 100644
--- a/drivers/misc/habanalabs/include/goya/goya_async_events.h
+++ b/drivers/misc/habanalabs/include/goya/goya_async_events.h
@@ -188,6 +188,10 @@ enum goya_async_event_id {
 	GOYA_ASYNC_EVENT_ID_HALT_MACHINE = 485,
 	GOYA_ASYNC_EVENT_ID_INTS_REGISTER = 486,
 	GOYA_ASYNC_EVENT_ID_SOFT_RESET = 487,
+	GOYA_ASYNC_EVENT_ID_POWER_ENV_S = 507,
+	GOYA_ASYNC_EVENT_ID_POWER_ENV_E = 508,
+	GOYA_ASYNC_EVENT_ID_THERMAL_ENV_S = 509,
+	GOYA_ASYNC_EVENT_ID_THERMAL_ENV_E = 510,
 	GOYA_ASYNC_EVENT_ID_LAST_VALID_ID = 1023,
 	GOYA_ASYNC_EVENT_ID_SIZE
 };
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] habanalabs: add print upon clock change
  2020-03-09 11:25 [PATCH] habanalabs: add print upon clock change Omer Shpigelman
@ 2020-03-09 11:51 ` Oded Gabbay
  0 siblings, 0 replies; 2+ messages in thread
From: Oded Gabbay @ 2020-03-09 11:51 UTC (permalink / raw)
  To: Omer Shpigelman; +Cc: Linux-Kernel@Vger. Kernel. Org

On Mon, Mar 9, 2020 at 1:25 PM Omer Shpigelman <oshpigelman@habana.ai> wrote:
>
> Add print upon clock slow down due to power consumption or overheating.
> In addition, add print when back to optimal clock.
>
> Signed-off-by: Omer Shpigelman <oshpigelman@habana.ai>
> ---
>  drivers/misc/habanalabs/goya/goya.c           | 50 ++++++++++++++++++-
>  .../include/goya/goya_async_events.h          |  4 ++
>  2 files changed, 53 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/misc/habanalabs/goya/goya.c b/drivers/misc/habanalabs/goya/goya.c
> index 9d4295cc83cf..1ccf2ed9a8dc 100644
> --- a/drivers/misc/habanalabs/goya/goya.c
> +++ b/drivers/misc/habanalabs/goya/goya.c
> @@ -324,7 +324,11 @@ static u32 goya_all_events[] = {
>         GOYA_ASYNC_EVENT_ID_DMA_BM_CH1,
>         GOYA_ASYNC_EVENT_ID_DMA_BM_CH2,
>         GOYA_ASYNC_EVENT_ID_DMA_BM_CH3,
> -       GOYA_ASYNC_EVENT_ID_DMA_BM_CH4
> +       GOYA_ASYNC_EVENT_ID_DMA_BM_CH4,
> +       GOYA_ASYNC_EVENT_ID_POWER_ENV_S,
> +       GOYA_ASYNC_EVENT_ID_POWER_ENV_E,
> +       GOYA_ASYNC_EVENT_ID_THERMAL_ENV_S,
> +       GOYA_ASYNC_EVENT_ID_THERMAL_ENV_E
>  };
>
>  static int goya_mmu_clear_pgt_range(struct hl_device *hdev);
> @@ -4389,6 +4393,14 @@ static const char *_goya_get_event_desc(u16 event_type)
>                 return "TPC%d_bmon_spmu";
>         case GOYA_ASYNC_EVENT_ID_DMA_BM_CH0 ... GOYA_ASYNC_EVENT_ID_DMA_BM_CH4:
>                 return "DMA_bm_ch%d";
> +       case GOYA_ASYNC_EVENT_ID_POWER_ENV_S:
> +               return "POWER_ENV_S";
> +       case GOYA_ASYNC_EVENT_ID_POWER_ENV_E:
> +               return "POWER_ENV_E";
> +       case GOYA_ASYNC_EVENT_ID_THERMAL_ENV_S:
> +               return "THERMAL_ENV_S";
> +       case GOYA_ASYNC_EVENT_ID_THERMAL_ENV_E:
> +               return "THERMAL_ENV_E";
>         default:
>                 return "N/A";
>         }
> @@ -4619,6 +4631,33 @@ static int goya_unmask_irq(struct hl_device *hdev, u16 event_type)
>         return rc;
>  }
>
> +static void goya_print_clk_change_info(struct hl_device *hdev, u16 event_type)
> +{
> +       switch (event_type) {
> +       case GOYA_ASYNC_EVENT_ID_POWER_ENV_S:
> +               dev_info_ratelimited(hdev->dev,
> +                       "Clock throttling due to power consumption\n");
> +               break;
> +       case GOYA_ASYNC_EVENT_ID_POWER_ENV_E:
> +               dev_info_ratelimited(hdev->dev,
> +                       "Power envelop is safe, back to optimal clock\n");
> +               break;
> +       case GOYA_ASYNC_EVENT_ID_THERMAL_ENV_S:
> +               dev_info_ratelimited(hdev->dev,
> +                       "Clock throttling due to overheating\n");
> +               break;
> +       case GOYA_ASYNC_EVENT_ID_THERMAL_ENV_E:
> +               dev_info_ratelimited(hdev->dev,
> +                       "Thermal envelop is safe, back to optimal clock\n");
> +               break;
> +
> +       default:
> +               dev_err(hdev->dev, "Received invalid clock change event %d\n",
> +                       event_type);
> +               break;
> +       }
> +}
> +
>  void goya_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_entry)
>  {
>         u32 ctl = le32_to_cpu(eq_entry->hdr.ctl);
> @@ -4702,6 +4741,15 @@ void goya_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_entry)
>                 goya_unmask_irq(hdev, event_type);
>                 break;
>
> +       case GOYA_ASYNC_EVENT_ID_POWER_ENV_S:
> +       case GOYA_ASYNC_EVENT_ID_POWER_ENV_E:
> +       case GOYA_ASYNC_EVENT_ID_THERMAL_ENV_S:
> +       case GOYA_ASYNC_EVENT_ID_THERMAL_ENV_E:
> +               goya_print_irq_info(hdev, event_type, false);
> +               goya_print_clk_change_info(hdev, event_type);
> +               goya_unmask_irq(hdev, event_type);
> +               break;
> +
>         default:
>                 dev_err(hdev->dev, "Received invalid H/W interrupt %d\n",
>                                 event_type);
> diff --git a/drivers/misc/habanalabs/include/goya/goya_async_events.h b/drivers/misc/habanalabs/include/goya/goya_async_events.h
> index bb7a1aa3279e..6be41a846c99 100644
> --- a/drivers/misc/habanalabs/include/goya/goya_async_events.h
> +++ b/drivers/misc/habanalabs/include/goya/goya_async_events.h
> @@ -188,6 +188,10 @@ enum goya_async_event_id {
>         GOYA_ASYNC_EVENT_ID_HALT_MACHINE = 485,
>         GOYA_ASYNC_EVENT_ID_INTS_REGISTER = 486,
>         GOYA_ASYNC_EVENT_ID_SOFT_RESET = 487,
> +       GOYA_ASYNC_EVENT_ID_POWER_ENV_S = 507,
> +       GOYA_ASYNC_EVENT_ID_POWER_ENV_E = 508,
> +       GOYA_ASYNC_EVENT_ID_THERMAL_ENV_S = 509,
> +       GOYA_ASYNC_EVENT_ID_THERMAL_ENV_E = 510,
>         GOYA_ASYNC_EVENT_ID_LAST_VALID_ID = 1023,
>         GOYA_ASYNC_EVENT_ID_SIZE
>  };
> --
> 2.17.1
>

This patch is:
Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-09 11:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-09 11:25 [PATCH] habanalabs: add print upon clock change Omer Shpigelman
2020-03-09 11:51 ` Oded Gabbay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).