drm/i915/guc: Enable guc logging on guc log relay write

Creating and opening the GuC log relay file enables and starts
the relay potentially before the caller is ready to consume logs.
Change the behavior so that relay starts only on an explicit call
to the write function (with a value of '1'). Other values flush
the log relay as before.

v2: Style changes and fix typos. Add guc_log_relay_stop()
function. (Daniele)

Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
Signed-off-by: Robert M. Fosha <robert.m.fosha@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191022163754.23870-1-robert.m.fosha@intel.com
This commit is contained in:
Robert M. Fosha 2019-10-22 09:37:52 -07:00 committed by Daniele Ceraolo Spurio
parent 37c92dc303
commit 853ddb6993
3 changed files with 64 additions and 19 deletions

View File

@ -226,7 +226,7 @@ static void guc_read_update_log_buffer(struct intel_guc_log *log)
mutex_lock(&log->relay.lock); mutex_lock(&log->relay.lock);
if (WARN_ON(!intel_guc_log_relay_enabled(log))) if (WARN_ON(!intel_guc_log_relay_created(log)))
goto out_unlock; goto out_unlock;
/* Get the pointer to shared GuC log buffer */ /* Get the pointer to shared GuC log buffer */
@ -361,6 +361,7 @@ void intel_guc_log_init_early(struct intel_guc_log *log)
{ {
mutex_init(&log->relay.lock); mutex_init(&log->relay.lock);
INIT_WORK(&log->relay.flush_work, capture_logs_work); INIT_WORK(&log->relay.flush_work, capture_logs_work);
log->relay.started = false;
} }
static int guc_log_relay_create(struct intel_guc_log *log) static int guc_log_relay_create(struct intel_guc_log *log)
@ -546,7 +547,7 @@ int intel_guc_log_set_level(struct intel_guc_log *log, u32 level)
return ret; return ret;
} }
bool intel_guc_log_relay_enabled(const struct intel_guc_log *log) bool intel_guc_log_relay_created(const struct intel_guc_log *log)
{ {
return log->relay.buf_addr; return log->relay.buf_addr;
} }
@ -560,7 +561,7 @@ int intel_guc_log_relay_open(struct intel_guc_log *log)
mutex_lock(&log->relay.lock); mutex_lock(&log->relay.lock);
if (intel_guc_log_relay_enabled(log)) { if (intel_guc_log_relay_created(log)) {
ret = -EEXIST; ret = -EEXIST;
goto out_unlock; goto out_unlock;
} }
@ -585,15 +586,6 @@ int intel_guc_log_relay_open(struct intel_guc_log *log)
mutex_unlock(&log->relay.lock); mutex_unlock(&log->relay.lock);
guc_log_enable_flush_events(log);
/*
* When GuC is logging without us relaying to userspace, we're ignoring
* the flush notification. This means that we need to unconditionally
* flush on relay enabling, since GuC only notifies us once.
*/
queue_work(system_highpri_wq, &log->relay.flush_work);
return 0; return 0;
out_relay: out_relay:
@ -604,11 +596,33 @@ int intel_guc_log_relay_open(struct intel_guc_log *log)
return ret; return ret;
} }
int intel_guc_log_relay_start(struct intel_guc_log *log)
{
if (log->relay.started)
return -EEXIST;
guc_log_enable_flush_events(log);
/*
* When GuC is logging without us relaying to userspace, we're ignoring
* the flush notification. This means that we need to unconditionally
* flush on relay enabling, since GuC only notifies us once.
*/
queue_work(system_highpri_wq, &log->relay.flush_work);
log->relay.started = true;
return 0;
}
void intel_guc_log_relay_flush(struct intel_guc_log *log) void intel_guc_log_relay_flush(struct intel_guc_log *log)
{ {
struct intel_guc *guc = log_to_guc(log); struct intel_guc *guc = log_to_guc(log);
intel_wakeref_t wakeref; intel_wakeref_t wakeref;
if (!log->relay.started)
return;
/* /*
* Before initiating the forceful flush, wait for any pending/ongoing * Before initiating the forceful flush, wait for any pending/ongoing
* flush to complete otherwise forceful flush may not actually happen. * flush to complete otherwise forceful flush may not actually happen.
@ -622,18 +636,33 @@ void intel_guc_log_relay_flush(struct intel_guc_log *log)
guc_log_capture_logs(log); guc_log_capture_logs(log);
} }
void intel_guc_log_relay_close(struct intel_guc_log *log) /*
* Stops the relay log. Called from intel_guc_log_relay_close(), so no
* possibility of race with start/flush since relay_write cannot race
* relay_close.
*/
static void guc_log_relay_stop(struct intel_guc_log *log)
{ {
struct intel_guc *guc = log_to_guc(log); struct intel_guc *guc = log_to_guc(log);
struct drm_i915_private *i915 = guc_to_gt(guc)->i915; struct drm_i915_private *i915 = guc_to_gt(guc)->i915;
if (!log->relay.started)
return;
guc_log_disable_flush_events(log); guc_log_disable_flush_events(log);
intel_synchronize_irq(i915); intel_synchronize_irq(i915);
flush_work(&log->relay.flush_work); flush_work(&log->relay.flush_work);
log->relay.started = false;
}
void intel_guc_log_relay_close(struct intel_guc_log *log)
{
guc_log_relay_stop(log);
mutex_lock(&log->relay.lock); mutex_lock(&log->relay.lock);
GEM_BUG_ON(!intel_guc_log_relay_enabled(log)); GEM_BUG_ON(!intel_guc_log_relay_created(log));
guc_log_unmap(log); guc_log_unmap(log);
guc_log_relay_destroy(log); guc_log_relay_destroy(log);
mutex_unlock(&log->relay.lock); mutex_unlock(&log->relay.lock);

View File

@ -47,6 +47,7 @@ struct intel_guc_log {
struct i915_vma *vma; struct i915_vma *vma;
struct { struct {
void *buf_addr; void *buf_addr;
bool started;
struct work_struct flush_work; struct work_struct flush_work;
struct rchan *channel; struct rchan *channel;
struct mutex lock; struct mutex lock;
@ -65,8 +66,9 @@ int intel_guc_log_create(struct intel_guc_log *log);
void intel_guc_log_destroy(struct intel_guc_log *log); void intel_guc_log_destroy(struct intel_guc_log *log);
int intel_guc_log_set_level(struct intel_guc_log *log, u32 level); int intel_guc_log_set_level(struct intel_guc_log *log, u32 level);
bool intel_guc_log_relay_enabled(const struct intel_guc_log *log); bool intel_guc_log_relay_created(const struct intel_guc_log *log);
int intel_guc_log_relay_open(struct intel_guc_log *log); int intel_guc_log_relay_open(struct intel_guc_log *log);
int intel_guc_log_relay_start(struct intel_guc_log *log);
void intel_guc_log_relay_flush(struct intel_guc_log *log); void intel_guc_log_relay_flush(struct intel_guc_log *log);
void intel_guc_log_relay_close(struct intel_guc_log *log); void intel_guc_log_relay_close(struct intel_guc_log *log);

View File

@ -1866,8 +1866,8 @@ static void i915_guc_log_info(struct seq_file *m,
struct intel_guc_log *log = &dev_priv->gt.uc.guc.log; struct intel_guc_log *log = &dev_priv->gt.uc.guc.log;
enum guc_log_buffer_type type; enum guc_log_buffer_type type;
if (!intel_guc_log_relay_enabled(log)) { if (!intel_guc_log_relay_created(log)) {
seq_puts(m, "GuC log relay disabled\n"); seq_puts(m, "GuC log relay not created\n");
return; return;
} }
@ -2054,9 +2054,23 @@ i915_guc_log_relay_write(struct file *filp,
loff_t *ppos) loff_t *ppos)
{ {
struct intel_guc_log *log = filp->private_data; struct intel_guc_log *log = filp->private_data;
int val;
int ret;
intel_guc_log_relay_flush(log); ret = kstrtoint_from_user(ubuf, cnt, 0, &val);
return cnt; if (ret < 0)
return ret;
/*
* Enable and start the guc log relay on value of 1.
* Flush log relay for any other value.
*/
if (val == 1)
ret = intel_guc_log_relay_start(log);
else
intel_guc_log_relay_flush(log);
return ret ?: cnt;
} }
static int i915_guc_log_relay_release(struct inode *inode, struct file *file) static int i915_guc_log_relay_release(struct inode *inode, struct file *file)