Files
linux/drivers/gpu/drm/xe/xe_gt_stats.h
Matthew Brost 9ff885ef8b drm/xe: Convert GT stats to per-cpu counters
Current GT statistics use atomic64_t counters. Atomic operations incur
a global coherency penalty.

Transition to dynamic per-cpu counters using alloc_percpu(). This allows
stats to be incremented via this_cpu_add(), which compiles to a single
non-locking instruction. This approach keeps the hot-path updates local
to the CPU, avoiding expensive cross-core cache invalidation traffic.

Use for_each_possible_cpu() during aggregation and clear operations to
ensure data consistency across CPU hotplug events.

Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Stuart Summers <stuart.summers@intel.com>
Link: https://patch.msgid.link/20260217200552.596718-1-matthew.brost@intel.com
2026-02-17 18:12:10 -08:00

65 lines
1.4 KiB
C

/* SPDX-License-Identifier: MIT */
/*
* Copyright © 2024 Intel Corporation
*/
#ifndef _XE_GT_STATS_H_
#define _XE_GT_STATS_H_
#include <linux/ktime.h>
#include "xe_gt_stats_types.h"
struct xe_gt;
struct drm_printer;
#ifdef CONFIG_DEBUG_FS
int xe_gt_stats_init(struct xe_gt *gt);
int xe_gt_stats_print_info(struct xe_gt *gt, struct drm_printer *p);
void xe_gt_stats_clear(struct xe_gt *gt);
void xe_gt_stats_incr(struct xe_gt *gt, const enum xe_gt_stats_id id, int incr);
#else
static inline int xe_gt_stats_init(struct xe_gt *gt)
{
return 0;
}
static inline void
xe_gt_stats_incr(struct xe_gt *gt, const enum xe_gt_stats_id id,
int incr)
{
}
#endif
/**
* xe_gt_stats_ktime_us_delta() - Get delta in microseconds between now and a
* start time
* @start: Start time
*
* Helper for GT stats to get delta in microseconds between now and a start
* time, compiles out if GT stats are disabled.
*
* Return: Delta in microseconds between now and a start time
*/
static inline s64 xe_gt_stats_ktime_us_delta(ktime_t start)
{
return IS_ENABLED(CONFIG_DEBUG_FS) ?
ktime_us_delta(ktime_get(), start) : 0;
}
/**
* xe_gt_stats_ktime_get() - Get current ktime
*
* Helper for GT stats to get current ktime, compiles out if GT stats are
* disabled.
*
* Return: Get current ktime
*/
static inline ktime_t xe_gt_stats_ktime_get(void)
{
return IS_ENABLED(CONFIG_DEBUG_FS) ? ktime_get() : 0;
}
#endif