<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 7, 2016 at 10:19 AM, Matthew Auld <span dir="ltr"><<a href="mailto:matthew.william.auld@gmail.com" target="_blank">matthew.william.auld@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">On 14 September 2016 at 15:19, Robert Bragg <<a href="mailto:robert@sixbynine.org">robert@sixbynine.org</a>> wrote:<br><br>
> diff --git a/drivers/gpu/drm/i915/i915_<wbr>perf.c b/drivers/gpu/drm/i915/i915_<wbr>perf.c<br>
> index 87530f5..5305982 100644<br>
> --- a/drivers/gpu/drm/i915/i915_<wbr>perf.c<br>
> +++ b/drivers/gpu/drm/i915/i915_<wbr>perf.c<br>
> @@ -28,14 +28,860 @@<br>
>  #include <linux/sizes.h><br>
><br>
>  #include "i915_drv.h"<br>
> +#include "intel_ringbuffer.h"<br>
> +#include "intel_lrc.h"<br>
</div></div>Superfluous includes.<br></blockquote><div> </div><div>ah, yup, removed. <br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class="gmail-"><br>
> +#include "i915_oa_hsw.h"<br>
> +<br>
> +/* Must be a power of two */<br>
> +#define OA_BUFFER_SIZE         SZ_16M<br>
</span>It's a power of two between 128K and 16M, maybe add a build_bug_on and<br>
build_bug_on_not_power_of_2 to check this?<br></blockquote><div><br></div><div>okey, added assertions to init_oa_buffer()<br><br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class="gmail-"><br>
> +#define OA_TAKEN(tail, head)   ((tail - head) & (OA_BUFFER_SIZE - 1))<br>
> +<br>
> +/* There's a HW race condition between OA unit tail pointer register updates and<br>
> + * writes to memory whereby the tail pointer can sometimes get ahead of what's<br>
> + * been written out to the OA buffer so far.<br>
> + *<br>
> + * Although this can be observed explicitly by checking for a zeroed report-id<br>
> + * field in tail reports, it seems preferable to account for this earlier e.g.<br>
> + * as part of the _oa_buffer_is_empty checks to minimize -EAGAIN polling cycles<br>
> + * in this situation.<br>
> + *<br>
> + * To give time for the most recent reports to land before they may be copied to<br>
> + * userspace, the driver operates as if the tail pointer effectively lags behind<br>
> + * the HW tail pointer by 'tail_margin' bytes. The margin in bytes is calculated<br>
> + * based on this constant in nanoseconds, the current OA sampling exponent<br>
> + * and current report size.<br>
> + *<br>
> + * There is also a fallback check while reading to simply skip over reports with<br>
> + * a zeroed report-id.<br>
> + */<br>
> +#define OA_TAIL_MARGIN_NSEC    100000ULL<br>
</span>Yikes!<br></blockquote><div><br></div><div>Yeah :-)<br><br></div><div>Although I've had some feedback from the hw side that there probably is a race as described here; it's currently an assumption  that a 100 microseconds is always enough time for any internally buffered OA reports to get as far as being coherent with the cpu's view. If a more detailed analysis is ever done to quantify the maximum latency (maybe not best to measure as a unit of time) maybe we can update this, but for now I've found this to work. I'm not really pushing for, or expecting this to be investigated in detail for Haswell.<br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div class="gmail-h5"><br><br>
> +<br>
> +static void gen7_init_oa_buffer(struct drm_i915_private *dev_priv)<br>
> +{<br>
> +       /* Pre-DevBDW: OABUFFER must be set with counters off,<br>
> +        * before OASTATUS1, but after OASTATUS2<br>
> +        */<br>
> +       I915_WRITE(GEN7_OASTATUS2, dev_priv->perf.oa.oa_buffer.<wbr>gtt_offset |<br>
> +                  OA_MEM_SELECT_GGTT); /* head */<br>
> +       I915_WRITE(GEN7_OABUFFER, dev_priv->perf.oa.oa_buffer.<wbr>gtt_offset);<br>
> +       I915_WRITE(GEN7_OASTATUS1, dev_priv->perf.oa.oa_buffer.<wbr>gtt_offset |<br>
> +                  OABUFFER_SIZE_16M); /* tail */<br>
> +<br>
> +       /* On Haswell we have to track which OASTATUS1 flags we've<br>
> +        * already seen since they can't be cleared while periodic<br>
> +        * sampling is enabled.<br>
> +        */<br>
> +       dev_priv->perf.oa.gen7_<wbr>latched_oastatus1 = 0;<br>
> +<br>
> +       /* NB: although the OA buffer will initially be allocated<br>
> +        * zeroed via shmfs (and so this memset is redundant when<br>
> +        * first allocating), we may re-init the OA buffer, either<br>
> +        * when re-enabling a stream or in error/reset paths.<br>
> +        *<br>
> +        * The reason we clear the buffer for each re-init is for the<br>
> +        * sanity check in gen7_append_oa_reports() that looks at the<br>
> +        * report-id field to make sure it's non-zero which relies on<br>
> +        * the assumption that new reports are being written to zeroed<br>
> +        * memory...<br>
> +        */<br>
> +       memset(dev_priv->perf.oa.oa_<wbr>buffer.addr, 0, SZ_16M);<br>
</div></div>OA_BUFFER_SIZE<br></blockquote><div><br></div><div>ah, yep.<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div class="gmail-h5"><br>
> +<br>
> +       /* Maybe make ->pollin per-stream state if we support multiple<br>
> +        * concurrent streams in the future. */<br>
> +       atomic_set(&dev_priv->perf.oa.<wbr>pollin, false);<br>
> +}<br>
> +<br>
> +static int alloc_oa_buffer(struct drm_i915_private *dev_priv)<br>
> +{<br>
> +       struct drm_i915_gem_object *bo;<br>
> +       enum i915_map_type map;<br>
> +       struct i915_vma *vma;<br>
> +       int ret;<br>
> +<br>
> +       BUG_ON(dev_priv->perf.oa.oa_<wbr>buffer.obj);<br>
> +<br>
> +       ret = i915_mutex_lock_interruptible(<wbr>&dev_priv->drm);<br>
> +       if (ret)<br>
> +               return ret;<br>
> +<br>
> +       bo = i915_gem_object_create(&dev_<wbr>priv->drm, OA_BUFFER_SIZE);<br>
> +       if (IS_ERR(bo)) {<br>
> +               DRM_ERROR("Failed to allocate OA buffer\n");<br>
> +               ret = PTR_ERR(bo);<br>
> +               goto unlock;<br>
> +       }<br>
> +       dev_priv->perf.oa.oa_buffer.<wbr>obj = bo;<br>
> +<br>
> +       ret = i915_gem_object_set_cache_<wbr>level(bo, I915_CACHE_LLC);<br>
> +       if (ret)<br>
> +               goto err_unref;<br>
> +<br>
> +       /* PreHSW required 512K alignment, HSW requires 16M */<br>
> +       vma = i915_gem_object_ggtt_pin(bo, NULL, 0, SZ_16M, PIN_MAPPABLE);<br>
> +       if (IS_ERR(vma)) {<br>
> +               ret = PTR_ERR(vma);<br>
> +               goto err_unref;<br>
> +       }<br>
> +       dev_priv->perf.oa.oa_buffer.<wbr>vma = vma;<br>
> +<br>
> +       map = HAS_LLC(dev_priv) ? I915_MAP_WB : I915_MAP_WC;<br>
> +<br>
> +       dev_priv->perf.oa.oa_buffer.<wbr>gtt_offset = i915_ggtt_offset(vma);<br>
> +       dev_priv->perf.oa.oa_buffer.<wbr>addr = i915_gem_object_pin_map(bo, map);<br>
> +       if (dev_priv->perf.oa.oa_buffer.<wbr>addr == NULL)<br>
</div></div>i915_gem_object_pin_map can't return NULL.<br>
<div><div class="gmail-h5"><br></div></div></blockquote><div> </div><div>ah, and this error path would have also returned an uninitialized ret error code. <br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="gmail-h5">
> +               goto err_unpin;<br>
> +<br>
> +       dev_priv->perf.oa.ops.init_oa_<wbr>buffer(dev_priv);<br>
> +<br>
> +       DRM_DEBUG_DRIVER("OA Buffer initialized, gtt offset = 0x%x, vaddr = %p",<br>
> +                        dev_priv->perf.oa.oa_buffer.<wbr>gtt_offset,<br>
> +                        dev_priv->perf.oa.oa_buffer.<wbr>addr);<br>
> +<br>
> +       goto unlock;<br>
> +<br>
> +err_unpin:<br>
> +       __i915_vma_unpin(vma);<br>
> +<br>
> +err_unref:<br>
> +       i915_gem_object_put(bo);<br>
> +<br>
> +       dev_priv->perf.oa.oa_buffer.<wbr>gtt_offset = 0;<br>
> +       dev_priv->perf.oa.oa_buffer.<wbr>addr = NULL;<br>
> +       dev_priv->perf.oa.oa_buffer.<wbr>vma = NULL;<br>
> +       dev_priv->perf.oa.oa_buffer.<wbr>obj = NULL;<br>
> +<br>
> +unlock:<br>
> +       mutex_unlock(&dev_priv->drm.<wbr>struct_mutex);<br>
> +       return ret;<br>
> +}<br>
> +<br>
> +static void config_oa_regs(struct drm_i915_private *dev_priv,<br>
> +                          const struct i915_oa_reg *regs,<br>
> +                          int n_regs)<br>
> +{<br>
> +       int i;<br>
> +<br>
> +       for (i = 0; i < n_regs; i++) {<br>
> +               const struct i915_oa_reg *reg = regs + i;<br>
> +<br>
> +               I915_WRITE(reg->addr, reg->value);<br>
> +       }<br>
> +}<br>
> +<br>
> +static int hsw_enable_metric_set(struct drm_i915_private *dev_priv)<br>
> +{<br>
> +       int ret = i915_oa_select_metric_set_hsw(<wbr>dev_priv);<br>
> +<br>
> +       if (ret)<br>
> +               return ret;<br>
> +<br>
> +       I915_WRITE(GDT_CHICKEN_BITS, (I915_READ(GDT_CHICKEN_BITS) |<br>
> +                                     GT_NOA_ENABLE));<br>
> +<br>
> +       /* PRM:<br>
> +        *<br>
> +        * OA unit is using “crclk” for its functionality. When trunk<br>
> +        * level clock gating takes place, OA clock would be gated,<br>
> +        * unable to count the events from non-render clock domain.<br>
> +        * Render clock gating must be disabled when OA is enabled to<br>
> +        * count the events from non-render domain. Unit level clock<br>
> +        * gating for RCS should also be disabled.<br>
> +        */<br>
> +       I915_WRITE(GEN7_MISCCPCTL, (I915_READ(GEN7_MISCCPCTL) &<br>
> +                                   ~GEN7_DOP_CLOCK_GATE_ENABLE));<br>
> +       I915_WRITE(GEN6_UCGCTL1, (I915_READ(GEN6_UCGCTL1) |<br>
> +                                 GEN6_CSUNIT_CLOCK_GATE_<wbr>DISABLE));<br>
> +<br>
> +       config_oa_regs(dev_priv, dev_priv->perf.oa.mux_regs,<br>
> +                      dev_priv->perf.oa.mux_regs_<wbr>len);<br>
> +<br>
> +       /* It apparently takes a fairly long time for a new MUX<br>
> +        * configuration to be be applied after these register writes.<br>
> +        * This delay duration was derived empirically based on the<br>
> +        * render_basic config but hopefully it covers the maximum<br>
> +        * configuration latency.<br>
> +        *<br>
> +        * As a fallback, the checks in _append_oa_reports() to skip<br>
> +        * invalid OA reports do also seem to work to discard reports<br>
> +        * generated before this config has completed - albeit not<br>
> +        * silently.<br>
> +        *<br>
> +        * Unfortunately this is essentially a magic number, since we<br>
> +        * don't currently know of a reliable mechanism for predicting<br>
> +        * how long the MUX config will take to apply and besides<br>
> +        * seeing invalid reports we don't know of a reliable way to<br>
> +        * explicitly check that the MUX config has landed.<br>
> +        *<br>
> +        * It's even possible we've miss characterized the underlying<br>
> +        * problem - it just seems like the simplest explanation why<br>
> +        * a delay at this location would mitigate any invalid reports.<br>
> +        */<br>
> +       usleep_range(15000, 20000);<br>
> +<br>
> +       config_oa_regs(dev_priv, dev_priv->perf.oa.b_counter_<wbr>regs,<br>
> +                      dev_priv->perf.oa.b_counter_<wbr>regs_len);<br>
> +<br>
> +       return 0;<br>
> +}<br>
> +<br>
> +static void hsw_disable_metric_set(struct drm_i915_private *dev_priv)<br>
> +{<br>
> +       I915_WRITE(GEN6_UCGCTL1, (I915_READ(GEN6_UCGCTL1) &<br>
> +                                 ~GEN6_CSUNIT_CLOCK_GATE_<wbr>DISABLE));<br>
> +       I915_WRITE(GEN7_MISCCPCTL, (I915_READ(GEN7_MISCCPCTL) |<br>
> +                                   GEN7_DOP_CLOCK_GATE_ENABLE));<br>
> +<br>
> +       I915_WRITE(GDT_CHICKEN_BITS, (I915_READ(GDT_CHICKEN_BITS) &<br>
> +                                     ~GT_NOA_ENABLE));<br>
> +}<br>
> +<br>
> +static void gen7_update_oacontrol_locked(<wbr>struct drm_i915_private *dev_priv)<br>
> +{<br>
> +       assert_spin_locked(&dev_priv-><wbr>perf.hook_lock);<br>
> +<br>
> +       if (dev_priv->perf.oa.exclusive_<wbr>stream->enabled) {<br>
> +               unsigned long ctx_id = 0;<br>
> +<br>
> +               if (dev_priv->perf.oa.exclusive_<wbr>stream->ctx)<br>
> +                       ctx_id = dev_priv->perf.oa.specific_<wbr>ctx_id;<br>
> +<br>
> +               if (dev_priv->perf.oa.exclusive_<wbr>stream->ctx == NULL || ctx_id) {<br>
</div></div>gem context state pinned at ggtt offset zero is unlikely but still<br>
possible, as pointed<br>
out by Chris.<br></blockquote><div><br></div><div>I've updated i915-perf to use an INVALID_CTX_ID define of 0xffffffff where appropriate.<br><br>When looking at this I realised that specific_ctx_id isn't explicltly initialized on Haswell when the stream is first opened (only for gen8+ in later patches) so I've also updated i915_oa_stream_init() to try initializing specific_ctx_id if the ctx is already pinned. I'll also update the specific ctx igt test which probably didn't catch this because the single context being tested is unused when opening the stream and so it works to rely on the pinning hook in that case.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div class="gmail-h5"><br><br>
> +<br>
> +static int i915_oa_stream_init(struct i915_perf_stream *stream,<br>
> +                              struct drm_i915_perf_open_param *param,<br>
> +                              struct perf_open_properties *props)<br>
> +{<br>
> +       struct drm_i915_private *dev_priv = stream->dev_priv;<br>
> +       int format_size;<br>
> +       int ret;<br>
> +<br>
> +       if (!(props->sample_flags & SAMPLE_OA_REPORT)) {<br>
> +               DRM_ERROR("Only OA report sampling supported\n");<br>
> +               return -EINVAL;<br>
> +       }<br>
> +<br>
> +       if (!dev_priv->perf.oa.ops.init_<wbr>oa_buffer) {<br>
> +               DRM_ERROR("OA unit not supported\n");<br>
> +               return -ENODEV;<br>
> +       }<br>
> +<br>
> +       /* To avoid the complexity of having to accurately filter<br>
> +        * counter reports and marshal to the appropriate client<br>
> +        * we currently only allow exclusive access<br>
> +        */<br>
> +       if (dev_priv->perf.oa.exclusive_<wbr>stream) {<br>
> +               DRM_ERROR("OA unit already in use\n");<br>
> +               return -EBUSY;<br>
> +       }<br>
> +<br>
> +       if (!props->metrics_set) {<br>
> +               DRM_ERROR("OA metric set not specified\n");<br>
> +               return -EINVAL;<br>
> +       }<br>
> +<br>
> +       if (!props->oa_format) {<br>
> +               DRM_ERROR("OA report format not specified\n");<br>
> +               return -EINVAL;<br>
> +       }<br>
> +<br>
> +       stream->sample_size = sizeof(struct drm_i915_perf_record_header);<br>
> +<br>
> +       format_size = dev_priv->perf.oa.oa_formats[<wbr>props->oa_format].size;<br>
> +<br>
> +       stream->sample_flags |= SAMPLE_OA_REPORT;<br>
> +       stream->sample_size += format_size;<br>
> +<br>
> +       dev_priv->perf.oa.oa_buffer.<wbr>format_size = format_size;<br>
> +       BUG_ON(dev_priv->perf.oa.oa_<wbr>buffer.format_size == 0);<br>
> +<br>
> +       dev_priv->perf.oa.oa_buffer.<wbr>format =<br>
> +               dev_priv->perf.oa.oa_formats[<wbr>props->oa_format].format;<br>
> +<br>
> +       dev_priv->perf.oa.metrics_set = props->metrics_set;<br>
> +<br>
> +       dev_priv->perf.oa.periodic = props->oa_periodic;<br>
> +       if (dev_priv->perf.oa.periodic) {<br>
> +               u64 period_ns = oa_exponent_to_ns(dev_priv,<br>
> +                                                 props->oa_period_exponent);<br>
> +<br>
> +               dev_priv->perf.oa.period_<wbr>exponent = props->oa_period_exponent;<br>
> +<br>
> +               /* See comment for OA_TAIL_MARGIN_NSEC for details<br>
> +                * about this tail_margin...<br>
> +                */<br>
> +               dev_priv->perf.oa.tail_margin =<br>
> +                       ((OA_TAIL_MARGIN_NSEC / period_ns) + 1) * format_size;<br>
> +       }<br>
> +<br>
> +       ret = alloc_oa_buffer(dev_priv);<br>
> +       if (ret)<br>
> +               return ret;<br>
> +<br>
> +       /* PRM - observability performance counters:<br>
> +        *<br>
> +        *   OACONTROL, performance counter enable, note:<br>
> +        *<br>
> +        *   "When this bit is set, in order to have coherent counts,<br>
> +        *   RC6 power state and trunk clock gating must be disabled.<br>
> +        *   This can be achieved by programming MMIO registers as<br>
> +        *   0xA094=0 and 0xA090[31]=1"<br>
> +        *<br>
> +        *   In our case we are expecting that taking pm + FORCEWAKE<br>
> +        *   references will effectively disable RC6.<br>
> +        */<br>
> +       intel_runtime_pm_get(dev_priv)<wbr>;<br>
> +       intel_uncore_forcewake_get(<wbr>dev_priv, FORCEWAKE_ALL);<br>
> +<br>
> +       ret = dev_priv->perf.oa.ops.enable_<wbr>metric_set(dev_priv);<br>
> +       if (ret) {<br>
> +               intel_uncore_forcewake_put(<wbr>dev_priv, FORCEWAKE_ALL);<br>
> +               intel_runtime_pm_put(dev_priv)<wbr>;<br>
> +               free_oa_buffer(dev_priv);<br>
> +               return ret;<br>
> +       }<br>
> +<br>
> +       stream->ops = &i915_oa_stream_ops;<br>
> +<br>
> +       /* On Haswell we have to track which OASTATUS1 flags we've already<br>
> +        * seen since they can't be cleared while periodic sampling is enabled.<br>
> +        */<br>
> +       dev_priv->perf.oa.gen7_<wbr>latched_oastatus1 = 0;<br>
</div></div>We already did this step.<br>
<span class="gmail-"><br></span></blockquote><div><br></div><div>Ah, yep.<br> <br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">
> +<br>
> +       dev_priv->perf.oa.exclusive_<wbr>stream = stream;<br>
> +<br>
> +       return 0;<br>
> +}<br>
> +<br>
> +static void gen7_update_hw_ctx_id_locked(<wbr>struct drm_i915_private *dev_priv,<br>
> +                                        u32 ctx_id)<br>
> +{<br>
> +       assert_spin_locked(&dev_priv-><wbr>perf.hook_lock);<br>
> +<br>
> +       dev_priv->perf.oa.specific_<wbr>ctx_id = ctx_id;<br>
> +       gen7_update_oacontrol_locked(<wbr>dev_priv);<br>
> +}<br>
> +<br>
> +static void<br>
> +i915_oa_legacy_context_pin_<wbr>notify_locked(struct drm_i915_private *dev_priv,<br>
> +                                        struct i915_gem_context *ctx)<br>
> +{<br>
> +       assert_spin_locked(&dev_priv-><wbr>perf.hook_lock);<br>
> +<br>
> +       BUG_ON(i915.enable_execlists);<br>
> +<br>
> +       if (dev_priv->perf.oa.ops.update_<wbr>hw_ctx_id_locked == NULL)<br>
</span>For consistency, if (!dev_priv->perf.oa.ops.<wbr>update_hw_ctx_id_locked)<br>
<div><div class="gmail-h5"><br>
> +               return;<br>
> +<br>
> +       if (dev_priv->perf.oa.exclusive_<wbr>stream &&<br>
> +           dev_priv->perf.oa.exclusive_<wbr>stream->ctx == ctx) {<br>
> +               struct i915_vma *vma = ctx->engine[RCS].state;<br>
> +               u32 ctx_id = i915_ggtt_offset(vma);<br>
> +<br>
> +               dev_priv->perf.oa.ops.update_<wbr>hw_ctx_id_locked(dev_priv, ctx_id);<br>
> +       }<br>
> +}<br>
> +<br><br>
> @@ -431,8 +1367,35 @@ int i915_perf_open_ioctl(struct drm_device *dev, void *data,<br>
><br>
>  void i915_perf_init(struct drm_i915_private *dev_priv)<br>
>  {<br>
> +       if (!IS_HASWELL(dev_priv))<br>
> +               return;<br>
> +<br>
> +       hrtimer_init(&dev_priv->perf.<wbr>oa.poll_check_timer,<br>
> +                    CLOCK_MONOTONIC, HRTIMER_MODE_REL);<br>
> +       dev_priv->perf.oa.poll_check_<wbr>timer.function = oa_poll_check_timer_cb;<br>
> +       init_waitqueue_head(&dev_priv-<wbr>>perf.oa.poll_wq);<br>
> +<br>
>         INIT_LIST_HEAD(&dev_priv-><wbr>perf.streams);<br>
>         mutex_init(&dev_priv->perf.<wbr>lock);<br>
> +       spin_lock_init(&dev_priv-><wbr>perf.hook_lock);<br>
> +<br>
> +       dev_priv->perf.oa.ops.init_oa_<wbr>buffer = gen7_init_oa_buffer;<br>
> +       dev_priv->perf.oa.ops.enable_<wbr>metric_set = hsw_enable_metric_set;<br>
> +       dev_priv->perf.oa.ops.disable_<wbr>metric_set = hsw_disable_metric_set;<br>
> +       dev_priv->perf.oa.ops.oa_<wbr>enable = gen7_oa_enable;<br>
> +       dev_priv->perf.oa.ops.oa_<wbr>disable = gen7_oa_disable;<br>
> +       dev_priv->perf.oa.ops.update_<wbr>hw_ctx_id_locked =<br>
> +               gen7_update_hw_ctx_id_locked;<br>
> +       dev_priv->perf.oa.ops.read = gen7_oa_read;<br>
> +       dev_priv->perf.oa.ops.oa_<wbr>buffer_is_empty =<br>
> +               gen7_oa_buffer_is_empty_fop_<wbr>unlocked;<br>
> +<br>
> +       dev_priv->perf.oa.timestamp_<wbr>frequency = 12500000;<br>
</div></div>Slightly magical.<br></blockquote><div><br></div><div>Not sure how to dymistify this with a comment; it pretty much is just a magic hardware constant detailing the fixed frequency of the HW timestamp counter. I think it's likely not actually  specified in the PRMs for < gen 9 considering that I think for all gens prior to SKL the frequency has remained the same.<br><br>Other software that currently deals with these raw HW timestamps (such as Mesa) actually work in terms of an integer multiplier (80)  when scaling HW timestamps to have nanosecond units, and you can derive the frequency from that. Maybe the scalar of 80 is noted in the PRMs somewhere instead of a frequency.<br><br>Awkwardly once we get to Skylake an integer multiple no longer works, so it's preferable to track the platform differences in terms of a frequency like this.<br></div><div><br></div><div>I'll consider noting some of this in a comment. <br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div class="gmail-h5"><br>
> diff --git a/drivers/gpu/drm/i915/intel_<wbr>ringbuffer.c b/drivers/gpu/drm/i915/intel_<wbr>ringbuffer.c<br>
> index 7a74750..22d5ff1 100644<br>
> --- a/drivers/gpu/drm/i915/intel_<wbr>ringbuffer.c<br>
> +++ b/drivers/gpu/drm/i915/intel_<wbr>ringbuffer.c<br>
> @@ -2043,8 +2043,14 @@ static int intel_ring_context_pin(struct i915_gem_context *ctx,<br>
>                 if (ret)<br>
>                         goto error;<br>
><br>
> -               ret = i915_vma_pin(ce->state, 0, ctx->ggtt_alignment,<br>
> -                                  PIN_GLOBAL | PIN_HIGH);<br>
> +               if (engine->id == RCS) {<br>
> +                       u64 vma_flags = PIN_GLOBAL | PIN_HIGH;<br>
</div></div>Maybe move this up a level and reuse for both paths.<br></blockquote><div><br></div><div>Ah yep,  <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div class="gmail-h5"><br>
> +                       ret = i915_gem_context_pin_legacy_<wbr>rcs_state(engine->i915,<br>
> +                                                                   ctx,<br>
> +                                                                   vma_flags);<br>
> +               } else<br>
> +                       ret = i915_vma_pin(ce->state, 0, ctx->ggtt_alignment,<br>
> +                                          PIN_GLOBAL | PIN_HIGH);<br>
>                 if (ret)<br>
>                         goto error;<br>
>         }<br></div></div></blockquote><div><br><br><br></div><div>I'm travelling this week, but will send out an updated patch when I've had a chance to test the change for initializing the specific_ctx_id on haswell.<br><br>thanks for the feedback.<br><br></div><div>Regards,<br></div><div>- Robert <br></div></div><br></div></div>