<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:11pt;color:#0078D7;margin:5pt;" align="Left">
[AMD Official Use Only - Internal Distribution Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
DOS line endings? That is weird....</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
I corrected the issues that showed in checkpatch.pl (the > 80 lines)</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
I'll re-upload</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> Christian König <ckoenig.leichtzumerken@gmail.com><br>
<b>Sent:</b> Thursday, May 13, 2021 1:11 AM<br>
<b>To:</b> Nieto, David M <David.Nieto@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Subject:</b> Re: [PATCH 2/2] drm/amdgpu: fix fence calculation</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Am 12.05.21 um 21:45 schrieb David M Nieto:<br>
> The proper metric for fence utilization over several<br>
> contexts is an harmonic mean, but such calculation is<br>
> prohibitive in kernel space, so the code approximates it.<br>
><br>
> Because the approximation diverges when one context has a<br>
> very small ratio compared with the other context, this change<br>
> filter out ratios smaller that 0.01%<br>
><br>
> Signed-off-by: David M Nieto <david.nieto@amd.com><br>
> Change-Id: I5b6e0ce5f489a5f55855d35354a6a3653e9d613b<br>
<br>
Looks good to me now, but the automated tools complain about "DOS line <br>
endings" plus a couple of other nit picks and won't let me push it :)<br>
<br>
Please use the checkpatch.pl script found in the Linux kernel to fix <br>
those errors and resend.<br>
<br>
Thanks,<br>
Christian.<br>
<br>
> ---<br>
> drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 17 +++++++++++++++--<br>
> drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 1 +<br>
> 2 files changed, 16 insertions(+), 2 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c<br>
> index 9036c93b4a0c..b919615e6644 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c<br>
> @@ -652,12 +652,14 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr)<br>
> mutex_destroy(&mgr->lock);<br>
> }<br>
> <br>
> -void amdgpu_ctx_fence_time(struct amdgpu_ctx *ctx, struct amdgpu_ctx_entity *centity,<br>
> +static void amdgpu_ctx_fence_time(struct amdgpu_ctx *ctx, struct amdgpu_ctx_entity *centity,<br>
> ktime_t *total, ktime_t *max)<br>
> {<br>
> ktime_t now, t1;<br>
> uint32_t i;<br>
> <br>
> + *total = *max = 0;<br>
> +<br>
> now = ktime_get();<br>
> for (i = 0; i < amdgpu_sched_jobs; i++) {<br>
> struct dma_fence *fence;<br>
> @@ -703,11 +705,22 @@ ktime_t amdgpu_ctx_mgr_fence_usage(struct amdgpu_ctx_mgr *mgr, uint32_t hwip,<br>
> idp = &mgr->ctx_handles;<br>
> mutex_lock(&mgr->lock);<br>
> idr_for_each_entry(idp, ctx, id) {<br>
> + ktime_t ttotal, tmax;<br>
> +<br>
> if (!ctx->entities[hwip][idx])<br>
> continue;<br>
> <br>
> centity = ctx->entities[hwip][idx];<br>
> - amdgpu_ctx_fence_time(ctx, centity, &total, &max);<br>
> + amdgpu_ctx_fence_time(ctx, centity, &ttotal, &tmax);<br>
> +<br>
> + /* Harmonic mean approximation diverges for very small<br>
> + * values. If ratio < 0.01% ignore<br>
> + */<br>
> + if (AMDGPU_CTX_FENCE_USAGE_MIN_RATIO(tmax, ttotal))<br>
> + continue;<br>
> +<br>
> + total = ktime_add(total, ttotal);<br>
> + max = ktime_after(tmax, max) ? tmax : max;<br>
> }<br>
> <br>
> mutex_unlock(&mgr->lock);<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h<br>
> index 10dcf59a5c6b..3541dfb059ec 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h<br>
> @@ -30,6 +30,7 @@ struct drm_file;<br>
> struct amdgpu_fpriv;<br>
> <br>
> #define AMDGPU_MAX_ENTITY_NUM 4<br>
> +#define AMDGPU_CTX_FENCE_USAGE_MIN_RATIO(max, total) (max > 16384ULL*total)<br>
> <br>
> struct amdgpu_ctx_entity {<br>
> uint64_t sequence;<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>