{
u64 delta, overflow_residency, prev_residency;
+ lockdep_assert_held(>idle->lock);
+
overflow_residency = BIT_ULL(32);
/*
return sysfs_emit(buff, "%s\n", gt_idle_state_to_string(state));
}
-static DEVICE_ATTR_RO(idle_status);
+u64 xe_gt_idle_residency_msec(struct xe_gt_idle *gtidle)
+{
+ struct xe_guc_pc *pc = gtidle_to_pc(gtidle);
+ u64 residency;
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(>idle->lock, flags);
+ residency = get_residency_ms(gtidle, gtidle->idle_residency(pc));
+ raw_spin_unlock_irqrestore(>idle->lock, flags);
+
+ return residency;
+}
+
+static DEVICE_ATTR_RO(idle_status);
static ssize_t idle_residency_ms_show(struct device *dev,
struct device_attribute *attr, char *buff)
{
u64 residency;
xe_pm_runtime_get(pc_to_xe(pc));
- residency = gtidle->idle_residency(pc);
+ residency = xe_gt_idle_residency_msec(gtidle);
xe_pm_runtime_put(pc_to_xe(pc));
- return sysfs_emit(buff, "%llu\n", get_residency_ms(gtidle, residency));
+ return sysfs_emit(buff, "%llu\n", residency);
}
static DEVICE_ATTR_RO(idle_residency_ms);
if (!kobj)
return -ENOMEM;
+ raw_spin_lock_init(>idle->lock);
+
if (xe_gt_is_media_type(gt)) {
snprintf(gtidle->name, sizeof(gtidle->name), "gt%d-mc", gt->info.id);
gtidle->idle_residency = xe_guc_pc_mc6_residency;
#ifndef _XE_GT_IDLE_SYSFS_TYPES_H_
#define _XE_GT_IDLE_SYSFS_TYPES_H_
+#include <linux/spinlock.h>
#include <linux/types.h>
struct xe_guc_pc;
u64 cur_residency;
/** @prev_residency: previous residency counter */
u64 prev_residency;
+ /** @lock: Lock protecting idle residency counters */
+ raw_spinlock_t lock;
/** @idle_status: get the current idle state */
enum xe_gt_idle_state (*idle_status)(struct xe_guc_pc *pc);
/** @idle_residency: get idle residency counter */