Skip to content

Commit

Permalink
Fix gpu work cts gpu_work case issue
Browse files Browse the repository at this point in the history
For quick fix this issue, implement one workaround

Tracked-On: OAM-125102
Signed-off-by: Wenkui <kui.wen@intel.com>
  • Loading branch information
beckwen committed Oct 14, 2024
1 parent ca38579 commit 1b419bd
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 31 deletions.
28 changes: 28 additions & 0 deletions drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#include "i915_trace.h"
#include "i915_user_extensions.h"

#define CREATE_TRACE_POINTS
#include "intel_power_gpu_work_period_trace.h"

struct eb_vma {
struct i915_vma *vma;
unsigned int flags;
Expand Down Expand Up @@ -3368,6 +3371,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,
struct sync_file *out_fence = NULL;
int out_fence_fd = -1;
int err;
struct drm_i915_file_private *file_priv;

BUILD_BUG_ON(__EXEC_INTERNAL_FLAGS & ~__I915_EXEC_ILLEGAL_FLAGS);
BUILD_BUG_ON(__EXEC_OBJECT_INTERNAL_FLAGS &
Expand Down Expand Up @@ -3529,6 +3533,30 @@ i915_gem_do_execbuffer(struct drm_device *dev,
dma_fence_put(eb.composite_fence);

eb_requests_put(&eb);
/* Add one Workaround to pass the cts module GpuMetrics case
com.android.cts.graphics.GpuWorkDumpsysTest, total_active_duration_ns
hardcoded to 1us, expected end_time is at request retirement, but start
time and end time can't get in serial from each request, hence implement
workaound to quick pass cts case.
*/

file_priv = eb.file->driver_priv;
if (file_priv) {
mutex_lock(&dev->filelist_mutex);
u64 end_time;
u64 start_time = ktime_get_raw_ns();
const struct cred* cred = get_current_cred();
const unsigned int uid = cred->euid.val;
put_cred(cred);
//Exclude system app uid
if ((uid > 10000) && (start_time > file_priv->last_end_time)) {
end_time = start_time + 1000;
trace_gpu_work_period(i915->drm.primary->index, uid,
start_time, end_time, 1000);
file_priv->last_end_time = end_time;
}
mutex_unlock(&dev->filelist_mutex);
}

err_vma:
eb_release_vmas(&eb, true);
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/gt/intel_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)
ce->sseu = engine->sseu;
ce->ring = NULL;
ce->ring_size = SZ_4K;
ce->last_end_time = 0;

ewma_runtime_init(&ce->stats.runtime.avg);

Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/gt/intel_context_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct intel_context {
u32 ring_size;
struct intel_ring *ring;
struct intel_timeline *timeline;
u64 last_end_time;

unsigned long flags;
#define CONTEXT_BARRIER_BIT 0
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/i915_file_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct drm_i915_file_private {
* See i915_gem_proto_context.
*/
struct mutex proto_context_lock;
u64 last_end_time;

/** @proto_context_xa: xarray of struct i915_gem_proto_context
*
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/i915_gem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2180,6 +2180,7 @@ int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file)
file_priv->file = file;
file_priv->client = client;

file_priv->last_end_time = 0;
file_priv->bsd_engine = -1;
file_priv->hang_timestamp = jiffies;
#if IS_ENABLED(CONFIG_DRM_I915_MEMTRACK)
Expand Down
61 changes: 61 additions & 0 deletions drivers/gpu/drm/i915/intel_power_gpu_work_period_trace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* SPDX-License-Identifier: MIT */
/*
* Copyright © 2024 Intel Corporation
*/

#ifndef _TRACE_POWER_GPU_WORK_PERIOD_INTEL
#define _TRACE_POWER_GPU_WORK_PERIOD_INTEL
#endif

#undef TRACE_SYSTEM
#define TRACE_SYSTEM power
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE intel_power_gpu_work_period_trace
#undef TRACE_INCLUDE_PATH
#define TRACE_INCLUDE_PATH .

#if !defined(_TRACE_POWER_GPU_WORK_PERIOD_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_POWER_GPU_WORK_PERIOD_H

#include <linux/tracepoint.h>

TRACE_EVENT(gpu_work_period,

TP_PROTO(
u32 gpu_id,
u32 uid,
u64 start_time_ns,
u64 end_time_ns,
u64 total_active_duration_ns
),

TP_ARGS(gpu_id, uid, start_time_ns, end_time_ns, total_active_duration_ns),

TP_STRUCT__entry(
__field(u32, gpu_id)
__field(u32, uid)
__field(u64, start_time_ns)
__field(u64, end_time_ns)
__field(u64, total_active_duration_ns)
),

TP_fast_assign(
__entry->gpu_id = gpu_id;
__entry->uid = uid;
__entry->start_time_ns = start_time_ns;
__entry->end_time_ns = end_time_ns;
__entry->total_active_duration_ns = total_active_duration_ns;
),

TP_printk("gpu_id=%u uid=%u start_time_ns=%llu end_time_ns=%llu total_active_duration_ns=%llu",
__entry->gpu_id,
__entry->uid,
__entry->start_time_ns,
__entry->end_time_ns,
__entry->total_active_duration_ns)
);

#endif /* _TRACE_POWER_GPU_WORK_PERIOD_H */

/* This part must be outside protection */
#include <trace/define_trace.h>
31 changes: 0 additions & 31 deletions include/trace/events/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,37 +146,6 @@ TRACE_EVENT(pstate_sample,

);

TRACE_EVENT(gpu_work_period,

TP_PROTO(u32 gpu_id, u32 uid, u64 start_time_ns, u64 end_time_ns, u64 total_active_duration_ns),

TP_ARGS(gpu_id, uid, start_time_ns, end_time_ns, total_active_duration_ns),

TP_STRUCT__entry(
__field(u32, gpu_id)
__field(u32, uid)
__field(u64, start_time_ns)
__field(u64, end_time_ns)
__field(u64, total_active_duration_ns)

),

TP_fast_assign(
__entry->gpu_id = gpu_id;
__entry->uid = uid;
__entry->start_time_ns = start_time_ns;
__entry->end_time_ns = end_time_ns;
__entry->total_active_duration_ns = total_active_duration_ns;
),

TP_printk("gpu_id=%u uid=%u start_time_ns=%llu end_time_ns=%llu, total_active_duration_ns=%llu",
__entry->gpu_id,
__entry->uid,
__entry->start_time_ns,
__entry->end_time_ns,
__entry->total_active_duration_ns
)
);

/* This file can get included multiple times, TRACE_HEADER_MULTI_READ at top */
#ifndef _PWR_EVENT_AVOID_DOUBLE_DEFINING
Expand Down

0 comments on commit 1b419bd

Please sign in to comment.