<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0078D7;margin:15pt;" align="Left">
[AMD Official Use Only - Internal Distribution Only]<br>
</p>
<br>
<div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
I believe bo->tbo.mem.mem_type is of uint32_t type and not an enum, is the index lookup method safe? (i.e., how do you deal with the possibility of having value <span style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt;">TTM_PL_PRIV or above or
 are you suggesting those are not possible for this function.)</span></div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt;"><br>
</span></div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Kenny</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Tuikov, Luben <Luben.Tuikov@amd.com><br>
<b>Sent:</b> Thursday, March 5, 2020 2:19 PM<br>
<b>To:</b> Nirmoy Das <nirmoy.aiemd@gmail.com>; dri-devel@lists.freedesktop.org <dri-devel@lists.freedesktop.org><br>
<b>Cc:</b> Zhou, David(ChunMing) <David1.Zhou@amd.com>; thellstrom@vmware.com <thellstrom@vmware.com>; airlied@linux.ie <airlied@linux.ie>; Ho, Kenny <Kenny.Ho@amd.com>; brian.welty@intel.com <brian.welty@intel.com>; maarten.lankhorst@linux.intel.com <maarten.lankhorst@linux.intel.com>;
 amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; Das, Nirmoy <Nirmoy.Das@amd.com>; linux-graphics-maintainer@vmware.com <linux-graphics-maintainer@vmware.com>; bskeggs@redhat.com <bskeggs@redhat.com>; daniel@ffwll.ch <daniel@ffwll.ch>; Deucher,
 Alexander <Alexander.Deucher@amd.com>; sean@poorly.run <sean@poorly.run>; Koenig, Christian <Christian.Koenig@amd.com>; kraxel@redhat.com <kraxel@redhat.com><br>
<b>Subject:</b> Re: [PATCH 2/8] drm/radeon: don't use ttm bo->offset</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">On 2020-03-05 08:29, Nirmoy Das wrote:<br>
> Calculate GPU offset in radeon_bo_gpu_offset without depending on<br>
> bo->offset.<br>
> <br>
> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com><br>
> Reviewed-and-tested-by: Christian König <christian.koenig@amd.com><br>
> ---<br>
>  drivers/gpu/drm/radeon/radeon.h        |  1 +<br>
>  drivers/gpu/drm/radeon/radeon_object.h | 16 +++++++++++++++-<br>
>  drivers/gpu/drm/radeon/radeon_ttm.c    |  4 +---<br>
>  3 files changed, 17 insertions(+), 4 deletions(-)<br>
> <br>
> diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h<br>
> index 30e32adc1fc6..b7c3fb2bfb54 100644<br>
> --- a/drivers/gpu/drm/radeon/radeon.h<br>
> +++ b/drivers/gpu/drm/radeon/radeon.h<br>
> @@ -2828,6 +2828,7 @@ extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size<br>
>  extern void radeon_program_register_sequence(struct radeon_device *rdev,<br>
>                                             const u32 *registers,<br>
>                                             const u32 array_size);<br>
> +struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev);<br>
> <br>
>  /*<br>
>   * vm<br>
> diff --git a/drivers/gpu/drm/radeon/radeon_object.h b/drivers/gpu/drm/radeon/radeon_object.h<br>
> index d23f2ed4126e..60275b822f79 100644<br>
> --- a/drivers/gpu/drm/radeon/radeon_object.h<br>
> +++ b/drivers/gpu/drm/radeon/radeon_object.h<br>
> @@ -90,7 +90,21 @@ static inline void radeon_bo_unreserve(struct radeon_bo *bo)<br>
>   */<br>
>  static inline u64 radeon_bo_gpu_offset(struct radeon_bo *bo)<br>
>  {<br>
> -     return bo->tbo.offset;<br>
> +     struct radeon_device *rdev;<br>
> +     u64 start = 0;<br>
> +<br>
> +     rdev = radeon_get_rdev(bo->tbo.bdev);<br>
> +<br>
> +     switch (bo->tbo.mem.mem_type) {<br>
> +     case TTM_PL_TT:<br>
> +             start = rdev->mc.gtt_start;<br>
> +             break;<br>
> +     case TTM_PL_VRAM:<br>
> +             start = rdev->mc.vram_start;<br>
> +             break;<br>
> +     }<br>
> +<br>
> +     return (bo->tbo.mem.start << PAGE_SHIFT) + start;<br>
>  }<br>
<br>
You're removing a "return bo->tbo.offset" and adding a<br>
switch-case statement. So, then, now instead of an instant<br>
lookup, you're adding branching. You're adding comparison<br>
and branching. Do you think that's better? Faster? Smaller?<br>
<br>
I've written before about this for this patch: Why not create a map,<br>
whose index is "mem_type" which references the desired<br>
address? No comparison, no branching. Just an index-dereference<br>
and a value:<br>
<br>
return rdev->mc.mem_start_map[bo->tbo.mem.mem_type];<br>
<br>
Obviously, you'll have to create "mem_start_map".<br>
<br>
That's a NAK from me on this patch using comparison<br>
and branching to return static data lookup value.<br>
<br>
Regards,<br>
Luben<br>
<br>
> <br>
>  static inline unsigned long radeon_bo_size(struct radeon_bo *bo)<br>
> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c<br>
> index badf1b6d1549..1c8303468e8f 100644<br>
> --- a/drivers/gpu/drm/radeon/radeon_ttm.c<br>
> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c<br>
> @@ -56,7 +56,7 @@<br>
>  static int radeon_ttm_debugfs_init(struct radeon_device *rdev);<br>
>  static void radeon_ttm_debugfs_fini(struct radeon_device *rdev);<br>
> <br>
> -static struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev)<br>
> +struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev)<br>
>  {<br>
>        struct radeon_mman *mman;<br>
>        struct radeon_device *rdev;<br>
> @@ -82,7 +82,6 @@ static int radeon_init_mem_type(struct ttm_bo_device *bdev, uint32_t type,<br>
>                break;<br>
>        case TTM_PL_TT:<br>
>                man->func = &ttm_bo_manager_func;<br>
> -             man->gpu_offset = rdev->mc.gtt_start;<br>
>                man->available_caching = TTM_PL_MASK_CACHING;<br>
>                man->default_caching = TTM_PL_FLAG_CACHED;<br>
>                man->flags = TTM_MEMTYPE_FLAG_MAPPABLE | TTM_MEMTYPE_FLAG_CMA;<br>
> @@ -104,7 +103,6 @@ static int radeon_init_mem_type(struct ttm_bo_device *bdev, uint32_t type,<br>
>        case TTM_PL_VRAM:<br>
>                /* "On-card" video ram */<br>
>                man->func = &ttm_bo_manager_func;<br>
> -             man->gpu_offset = rdev->mc.vram_start;<br>
>                man->flags = TTM_MEMTYPE_FLAG_FIXED |<br>
>                             TTM_MEMTYPE_FLAG_MAPPABLE;<br>
>                man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;<br>
> --<br>
> 2.25.0<br>
> <br>
> _______________________________________________<br>
> amd-gfx mailing list<br>
> amd-gfx@lists.freedesktop.org<br>
> <a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7Cluben.tuikov%40amd.com%7Cca6004a5ac7a400a030708d7c108bcde%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637190115619487827&amp;sdata=EkSy4vpUIbTE%2B75CSO37JWiULKbRTYbcZUSEtRpcrTk%3D&amp;reserved=0">
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7Cluben.tuikov%40amd.com%7Cca6004a5ac7a400a030708d7c108bcde%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637190115619487827&amp;sdata=EkSy4vpUIbTE%2B75CSO37JWiULKbRTYbcZUSEtRpcrTk%3D&amp;reserved=0</a><br>
> <br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>