Commit bfc87f90 authored by Krystian Pradzynski's avatar Krystian Pradzynski Committed by Stanislaw Gruszka
Browse files

accel/ivpu/40xx: Allow to change profiling frequency



Profiling freq is a debug firmware feature. It switches default clock
to higher resolution for fine-grained and more accurate firmware task
profiling. We already configure it during boot up of VPU4.

Add debugfs knob and helpers per HW generation that allow to change it.
For vpu37xx the implementation is empty as profiling frequency can only
be changed on VPU4 or newer.

Signed-off-by: default avatarKrystian Pradzynski <krystian.pradzynski@linux.intel.com>
Reviewed-by: default avatarStanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
Reviewed-by: default avatarJeffrey Hugo <quic_jhugo@quicinc.com>
Signed-off-by: default avatarStanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20231028155936.1183342-2-stanislaw.gruszka@linux.intel.com
parent 9d7c8c06
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
#include "ivpu_fw.h"
#include "ivpu_fw_log.h"
#include "ivpu_gem.h"
#include "ivpu_hw.h"
#include "ivpu_jsm_msg.h"
#include "ivpu_pm.h"

@@ -176,6 +177,30 @@ static const struct file_operations fw_log_fops = {
	.release = single_release,
};

static ssize_t
fw_profiling_freq_fops_write(struct file *file, const char __user *user_buf,
			     size_t size, loff_t *pos)
{
	struct ivpu_device *vdev = file->private_data;
	bool enable;
	int ret;

	ret = kstrtobool_from_user(user_buf, size, &enable);
	if (ret < 0)
		return ret;

	ivpu_hw_profiling_freq_drive(vdev, enable);
	ivpu_pm_schedule_recovery(vdev);

	return size;
}

static const struct file_operations fw_profiling_freq_fops = {
	.owner = THIS_MODULE,
	.open = simple_open,
	.write = fw_profiling_freq_fops_write,
};

static ssize_t
fw_trace_destination_mask_fops_write(struct file *file, const char __user *user_buf,
				     size_t size, loff_t *pos)
@@ -319,4 +344,8 @@ void ivpu_debugfs_init(struct ivpu_device *vdev)

	debugfs_create_file("reset_engine", 0200, debugfs_root, vdev,
			    &ivpu_reset_engine_fops);

	if (ivpu_hw_gen(vdev) >= IVPU_HW_40XX)
		debugfs_create_file("fw_profiling_freq_drive", 0200,
				    debugfs_root, vdev, &fw_profiling_freq_fops);
}
+7 −0
Original line number Diff line number Diff line
@@ -498,6 +498,13 @@ void ivpu_fw_boot_params_setup(struct ivpu_device *vdev, struct vpu_boot_params
	boot_params->vpu_id = to_pci_dev(vdev->drm.dev)->bus->number;
	boot_params->frequency = ivpu_hw_reg_pll_freq_get(vdev);

	/*
	 * This param is a debug firmware feature.  It switches default clock
	 * to higher resolution one for fine-grained and more accurate firmware
	 * task profiling.
	 */
	boot_params->perf_clk_frequency = ivpu_hw_profiling_freq_get(vdev);

	/*
	 * Uncached region of VPU address space, covers IPC buffers, job queues
	 * and log buffers, programmable to L2$ Uncached by VPU MTRR
+12 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@ struct ivpu_hw_ops {
	int (*wait_for_idle)(struct ivpu_device *vdev);
	void (*wdt_disable)(struct ivpu_device *vdev);
	void (*diagnose_failure)(struct ivpu_device *vdev);
	u32 (*profiling_freq_get)(struct ivpu_device *vdev);
	void (*profiling_freq_drive)(struct ivpu_device *vdev, bool enable);
	u32 (*reg_pll_freq_get)(struct ivpu_device *vdev);
	u32 (*reg_telemetry_offset_get)(struct ivpu_device *vdev);
	u32 (*reg_telemetry_size_get)(struct ivpu_device *vdev);
@@ -104,6 +106,16 @@ static inline void ivpu_hw_wdt_disable(struct ivpu_device *vdev)
	vdev->hw->ops->wdt_disable(vdev);
};

static inline u32 ivpu_hw_profiling_freq_get(struct ivpu_device *vdev)
{
	return vdev->hw->ops->profiling_freq_get(vdev);
};

static inline void ivpu_hw_profiling_freq_drive(struct ivpu_device *vdev, bool enable)
{
	return vdev->hw->ops->profiling_freq_drive(vdev, enable);
};

/* Register indirect accesses */
static inline u32 ivpu_hw_reg_pll_freq_get(struct ivpu_device *vdev)
{
+13 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@

#define PLL_REF_CLK_FREQ	     (50 * 1000000)
#define PLL_SIMULATION_FREQ	     (10 * 1000000)
#define PLL_PROF_CLK_FREQ	     (38400 * 1000)
#define PLL_DEFAULT_EPP_VALUE	     0x80

#define TIM_SAFE_ENABLE		     0xf1d0dead
@@ -769,6 +770,16 @@ static void ivpu_hw_37xx_wdt_disable(struct ivpu_device *vdev)
	REGV_WR32(VPU_37XX_CPU_SS_TIM_GEN_CONFIG, val);
}

static u32 ivpu_hw_37xx_profiling_freq_get(struct ivpu_device *vdev)
{
	return PLL_PROF_CLK_FREQ;
}

static void ivpu_hw_37xx_profiling_freq_drive(struct ivpu_device *vdev, bool enable)
{
	/* Profiling freq - is a debug feature. Unavailable on VPU 37XX. */
}

static u32 ivpu_hw_37xx_pll_to_freq(u32 ratio, u32 config)
{
	u32 pll_clock = PLL_REF_CLK_FREQ * ratio;
@@ -1012,6 +1023,8 @@ const struct ivpu_hw_ops ivpu_hw_37xx_ops = {
	.boot_fw = ivpu_hw_37xx_boot_fw,
	.wdt_disable = ivpu_hw_37xx_wdt_disable,
	.diagnose_failure = ivpu_hw_37xx_diagnose_failure,
	.profiling_freq_get = ivpu_hw_37xx_profiling_freq_get,
	.profiling_freq_drive = ivpu_hw_37xx_profiling_freq_drive,
	.reg_pll_freq_get = ivpu_hw_37xx_reg_pll_freq_get,
	.reg_telemetry_offset_get = ivpu_hw_37xx_reg_telemetry_offset_get,
	.reg_telemetry_size_get = ivpu_hw_37xx_reg_telemetry_size_get,
+15 −0
Original line number Diff line number Diff line
@@ -931,6 +931,19 @@ static void ivpu_hw_40xx_wdt_disable(struct ivpu_device *vdev)
	REGV_WR32(VPU_40XX_CPU_SS_TIM_GEN_CONFIG, val);
}

static u32 ivpu_hw_40xx_profiling_freq_get(struct ivpu_device *vdev)
{
	return vdev->hw->pll.profiling_freq;
}

static void ivpu_hw_40xx_profiling_freq_drive(struct ivpu_device *vdev, bool enable)
{
	if (enable)
		vdev->hw->pll.profiling_freq = PLL_PROFILING_FREQ_HIGH;
	else
		vdev->hw->pll.profiling_freq = PLL_PROFILING_FREQ_DEFAULT;
}

/* Register indirect accesses */
static u32 ivpu_hw_40xx_reg_pll_freq_get(struct ivpu_device *vdev)
{
@@ -1182,6 +1195,8 @@ const struct ivpu_hw_ops ivpu_hw_40xx_ops = {
	.boot_fw = ivpu_hw_40xx_boot_fw,
	.wdt_disable = ivpu_hw_40xx_wdt_disable,
	.diagnose_failure = ivpu_hw_40xx_diagnose_failure,
	.profiling_freq_get = ivpu_hw_40xx_profiling_freq_get,
	.profiling_freq_drive = ivpu_hw_40xx_profiling_freq_drive,
	.reg_pll_freq_get = ivpu_hw_40xx_reg_pll_freq_get,
	.reg_telemetry_offset_get = ivpu_hw_40xx_reg_telemetry_offset_get,
	.reg_telemetry_size_get = ivpu_hw_40xx_reg_telemetry_size_get,