drm/xe/gt_stats: Use atomic64_t for counters
authorFrancois Dugast <francois.dugast@intel.com>
Tue, 25 Feb 2025 19:57:33 +0000 (20:57 +0100)
committerFrancois Dugast <francois.dugast@intel.com>
Wed, 26 Feb 2025 10:01:00 +0000 (11:01 +0100)
The stats counters are now used for things like counting the VMA
bytes during page faults. During workload execution, the counter
value can grow fast and easily reach the atomic int limit, in
which case it overflows. To make this less likely to happen, push
the limit by switching to 64b atomic to store the counter value.
Overhead is very small as there are only 3 stat entries per GT as
of now, and stats are only enabled with CONFIG_DEBUG_FS.

Suggested-by: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250225195902.1247100-2-francois.dugast@intel.com
Signed-off-by: Francois Dugast <francois.dugast@intel.com>
drivers/gpu/drm/xe/xe_gt_stats.c
drivers/gpu/drm/xe/xe_gt_types.h

index 2e9879ea4674a48233fb6924806d74816b5877f4..af3fd03f665c5770bb7b4c9671aad1a6cb30107d 100644 (file)
@@ -23,7 +23,7 @@ void xe_gt_stats_incr(struct xe_gt *gt, const enum xe_gt_stats_id id, int incr)
        if (id >= __XE_GT_STATS_NUM_IDS)
                return;
 
-       atomic_add(incr, &gt->stats.counters[id]);
+       atomic64_add(incr, &gt->stats.counters[id]);
 }
 
 static const char *const stat_description[__XE_GT_STATS_NUM_IDS] = {
@@ -44,8 +44,8 @@ int xe_gt_stats_print_info(struct xe_gt *gt, struct drm_printer *p)
        enum xe_gt_stats_id id;
 
        for (id = 0; id < __XE_GT_STATS_NUM_IDS; ++id)
-               drm_printf(p, "%s: %d\n", stat_description[id],
-                          atomic_read(&gt->stats.counters[id]));
+               drm_printf(p, "%s: %lld\n", stat_description[id],
+                          atomic64_read(&gt->stats.counters[id]));
 
        return 0;
 }
index 6e66bf0e8b3f705fd2a3929cceefdaf898c7ead0..f72b965cc9e66818d855fb80e306072b5666b96b 100644 (file)
@@ -139,7 +139,7 @@ struct xe_gt {
        /** @stats: GT stats */
        struct {
                /** @stats.counters: counters for various GT stats */
-               atomic_t counters[__XE_GT_STATS_NUM_IDS];
+               atomic64_t counters[__XE_GT_STATS_NUM_IDS];
        } stats;
 #endif