All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom St Denis <tom.stdenis-5C7GfCeVMHo@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: Re: [PATCH 1/2] drm/amdgpu: implement read_sensor() for pre-powerplay chips
Date: Mon, 13 Feb 2017 18:17:24 -0500	[thread overview]
Message-ID: <f07176a7-6bfe-e98e-7f80-d8f2668d3045@amd.com> (raw)
In-Reply-To: <20170213220132.1033-2-samuel.pitoiset-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Hi Samuel,

It would be helpful to modify amdgpu_debugfs_sensor_read() to support 
dpm based sensors as well.  This will let me add it to umr.

If you can swing that in here that would be helpful if not I can submit 
my own patch when this lands.

Cheers,
Tom



On 02/13/2017 05:01 PM, Samuel Pitoiset wrote:
> Currently, only the GPU temperature, the shader clock and
> eventually the memory clock are implemented. The main goal
> is to expose this info to the userspace like Radeon.
>
> Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h |  4 +++-
>  drivers/gpu/drm/amd/amdgpu/ci_dpm.c     | 26 +++++++++++++++++++++
>  drivers/gpu/drm/amd/amdgpu/kv_dpm.c     | 34 +++++++++++++++++++++++++++
>  drivers/gpu/drm/amd/amdgpu/si_dpm.c     | 41 +++++++++++++++++++++++++++++++++
>  4 files changed, 104 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
> index 98698dcf15c7..f1876808ff58 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
> @@ -270,6 +270,8 @@ struct amdgpu_dpm_funcs {
>  				struct amdgpu_ps *cps,
>  				struct amdgpu_ps *rps,
>  				bool *equal);
> +	int (*read_sensor)(struct amdgpu_device *adev, int idx, void *value,
> +			   int *size);
>
>  	struct amd_vce_state* (*get_vce_clock_state)(struct amdgpu_device *adev, unsigned idx);
>  	int (*reset_power_profile_state)(struct amdgpu_device *adev,
> @@ -293,7 +295,7 @@ struct amdgpu_dpm_funcs {
>  #define amdgpu_dpm_read_sensor(adev, idx, value, size) \
>  	((adev)->pp_enabled ? \
>  		(adev)->powerplay.pp_funcs->read_sensor(adev->powerplay.pp_handle, (idx), (value), (size)) : \
> -		-EINVAL)
> +		(adev)->pm.funcs->read_sensor((adev), (idx), (value), (size)))
>
>  #define amdgpu_dpm_get_temperature(adev) \
>  	((adev)->pp_enabled ?						\
> diff --git a/drivers/gpu/drm/amd/amdgpu/ci_dpm.c b/drivers/gpu/drm/amd/amdgpu/ci_dpm.c
> index 578878d1d4c0..e3a06d6d9e99 100644
> --- a/drivers/gpu/drm/amd/amdgpu/ci_dpm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/ci_dpm.c
> @@ -6936,6 +6936,31 @@ static int ci_dpm_switch_power_profile(struct amdgpu_device *adev,
>  	return 0;
>  }
>
> +static int ci_dpm_read_sensor(struct amdgpu_device *adev, int idx,
> +			      void *value, int *size)
> +{
> +	/* size must be at least 4 bytes for all sensors */
> +	if (*size < 4)
> +		return -EINVAL;
> +
> +	switch (idx) {
> +	case AMDGPU_PP_SENSOR_GFX_SCLK:
> +		*((uint32_t *)value) = ci_get_average_sclk_freq(adev);
> +		*size = 4;
> +		return 0;
> +	case AMDGPU_PP_SENSOR_GFX_MCLK:
> +		*((uint32_t *)value) = ci_get_average_mclk_freq(adev);
> +		*size = 4;
> +		return 0;
> +	case AMDGPU_PP_SENSOR_GPU_TEMP:
> +		*((uint32_t *)value) = ci_dpm_get_temp(adev);
> +		*size = 4;
> +		return 0;
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
>  const struct amd_ip_funcs ci_dpm_ip_funcs = {
>  	.name = "ci_dpm",
>  	.early_init = ci_dpm_early_init,
> @@ -6982,6 +7007,7 @@ static const struct amdgpu_dpm_funcs ci_dpm_funcs = {
>  	.set_power_profile_state = ci_dpm_set_power_profile_state,
>  	.reset_power_profile_state = ci_dpm_reset_power_profile_state,
>  	.switch_power_profile = ci_dpm_switch_power_profile,
> +	.read_sensor = ci_dpm_read_sensor,
>  };
>
>  static void ci_dpm_set_dpm_funcs(struct amdgpu_device *adev)
> diff --git a/drivers/gpu/drm/amd/amdgpu/kv_dpm.c b/drivers/gpu/drm/amd/amdgpu/kv_dpm.c
> index f5a343cb0010..13f323745729 100644
> --- a/drivers/gpu/drm/amd/amdgpu/kv_dpm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/kv_dpm.c
> @@ -3260,6 +3260,39 @@ static int kv_check_state_equal(struct amdgpu_device *adev,
>  	return 0;
>  }
>
> +static int kv_dpm_read_sensor(struct amdgpu_device *adev, int idx,
> +			      void *value, int *size)
> +{
> +	struct kv_power_info *pi = kv_get_pi(adev);
> +	uint32_t sclk;
> +	u32 pl_index =
> +		(RREG32_SMC(ixTARGET_AND_CURRENT_PROFILE_INDEX) &
> +		TARGET_AND_CURRENT_PROFILE_INDEX__CURR_SCLK_INDEX_MASK) >>
> +		TARGET_AND_CURRENT_PROFILE_INDEX__CURR_SCLK_INDEX__SHIFT;
> +
> +	/* size must be at least 4 bytes for all sensors */
> +	if (*size < 4)
> +		return -EINVAL;
> +
> +	switch (idx) {
> +	case AMDGPU_PP_SENSOR_GFX_SCLK:
> +		if (pl_index < SMU__NUM_SCLK_DPM_STATE) {
> +			sclk = be32_to_cpu(
> +				pi->graphics_level[pl_index].SclkFrequency);
> +			*((uint32_t *)value) = sclk;
> +			*size = 4;
> +			return 0;
> +		}
> +		return -EINVAL;
> +	case AMDGPU_PP_SENSOR_GPU_TEMP:
> +		*((uint32_t *)value) = kv_dpm_get_temp(adev);
> +		*size = 4;
> +		return 0;
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
>  const struct amd_ip_funcs kv_dpm_ip_funcs = {
>  	.name = "kv_dpm",
>  	.early_init = kv_dpm_early_init,
> @@ -3292,6 +3325,7 @@ static const struct amdgpu_dpm_funcs kv_dpm_funcs = {
>  	.enable_bapm = &kv_dpm_enable_bapm,
>  	.get_vce_clock_state = amdgpu_get_vce_clock_state,
>  	.check_state_equal = kv_check_state_equal,
> +	.read_sensor = &kv_dpm_read_sensor,
>  };
>
>  static void kv_dpm_set_dpm_funcs(struct amdgpu_device *adev)
> diff --git a/drivers/gpu/drm/amd/amdgpu/si_dpm.c b/drivers/gpu/drm/amd/amdgpu/si_dpm.c
> index f55e45b52fbc..ded6b9b7153e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/si_dpm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/si_dpm.c
> @@ -7972,6 +7972,46 @@ static int si_check_state_equal(struct amdgpu_device *adev,
>  	return 0;
>  }
>
> +static int si_dpm_read_sensor(struct amdgpu_device *adev, int idx,
> +			      void *value, int *size)
> +{
> +	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
> +	struct amdgpu_ps *rps = &eg_pi->current_rps;
> +	struct  si_ps *ps = si_get_ps(rps);
> +	uint32_t sclk, mclk;
> +	u32 pl_index =
> +		(RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_STATE_INDEX_MASK) >>
> +		CURRENT_STATE_INDEX_SHIFT;
> +
> +	/* size must be at least 4 bytes for all sensors */
> +	if (*size < 4)
> +		return -EINVAL;
> +
> +	switch (idx) {
> +	case AMDGPU_PP_SENSOR_GFX_SCLK:
> +		if (pl_index < ps->performance_level_count) {
> +			sclk = ps->performance_levels[pl_index].sclk;
> +			*((uint32_t *)value) = sclk;
> +			*size = 4;
> +			return 0;
> +		}
> +		return -EINVAL;
> +	case AMDGPU_PP_SENSOR_GFX_MCLK:
> +		if (pl_index < ps->performance_level_count) {
> +			mclk = ps->performance_levels[pl_index].mclk;
> +			*((uint32_t *)value) = mclk;
> +			*size = 4;
> +			return 0;
> +		}
> +		return -EINVAL;
> +	case AMDGPU_PP_SENSOR_GPU_TEMP:
> +		*((uint32_t *)value) = si_dpm_get_temp(adev);
> +		*size = 4;
> +		return 0;
> +	default:
> +		return -EINVAL;
> +	}
> +}
>
>  const struct amd_ip_funcs si_dpm_ip_funcs = {
>  	.name = "si_dpm",
> @@ -8008,6 +8048,7 @@ static const struct amdgpu_dpm_funcs si_dpm_funcs = {
>  	.get_fan_speed_percent = &si_dpm_get_fan_speed_percent,
>  	.check_state_equal = &si_check_state_equal,
>  	.get_vce_clock_state = amdgpu_get_vce_clock_state,
> +	.read_sensor = &si_dpm_read_sensor,
>  };
>
>  static void si_dpm_set_dpm_funcs(struct amdgpu_device *adev)
>

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2017-02-13 23:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-13 22:01 [PATCH 0/2] drm/amdgpu: expose temp and shader/memory clocks Samuel Pitoiset
     [not found] ` <20170213220132.1033-1-samuel.pitoiset-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-13 22:01   ` [PATCH 1/2] drm/amdgpu: implement read_sensor() for pre-powerplay chips Samuel Pitoiset
     [not found]     ` <20170213220132.1033-2-samuel.pitoiset-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-13 22:13       ` Deucher, Alexander
     [not found]         ` <BN6PR12MB1652044A168BA6F29943A2C3F7590-/b2+HYfkarQqUD6E6FAiowdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-02-13 22:40           ` Tom St Denis
2017-02-13 23:17       ` Tom St Denis [this message]
     [not found]         ` <f07176a7-6bfe-e98e-7f80-d8f2668d3045-5C7GfCeVMHo@public.gmane.org>
2017-02-13 23:40           ` Samuel Pitoiset
     [not found]             ` <924552e4-ed96-af5f-82e9-b1e78b265282-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-13 23:46               ` Tom St Denis
     [not found]                 ` <3ad85db6-0ba2-77c9-6d94-a875efffdabb-5C7GfCeVMHo@public.gmane.org>
2017-02-14  0:13                   ` Samuel Pitoiset
2017-02-13 22:01   ` [PATCH 2/2] drm/amdgpu: expose the current temperature and shader/memory clocks Samuel Pitoiset
     [not found]     ` <20170213220132.1033-3-samuel.pitoiset-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-13 22:20       ` Deucher, Alexander
     [not found]         ` <BN6PR12MB1652B624BD6BA79E9A7F54F1F7590-/b2+HYfkarQqUD6E6FAiowdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-02-13 22:23           ` Samuel Pitoiset
2017-02-14  0:00   ` [PATCH v2 1/2] drm/amdgpu: implement read_sensor() for pre-powerplay chips Samuel Pitoiset
2017-02-14  0:01   ` [PATCH v2 2/2] drm/amdgpu: expose the current temperature and shader/memory clocks Samuel Pitoiset
     [not found]     ` <20170214000126.29947-1-samuel.pitoiset-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-14 15:11       ` Samuel Pitoiset
2017-02-14 16:31       ` Deucher, Alexander
2017-02-15 19:15   ` [PATCH v3 2/2] drm/amdgpu: expose GPU sensor related information Samuel Pitoiset
     [not found]     ` <20170215191546.27637-1-samuel.pitoiset-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-02-15 19:18       ` Samuel Pitoiset
2017-02-15 21:57   ` [PATCH v4 " Samuel Pitoiset

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f07176a7-6bfe-e98e-7f80-d8f2668d3045@amd.com \
    --to=tom.stdenis-5c7gfcevmho@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.