1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2020 Intel Corporation
6 #ifndef __INTEL_ENGINE_STATS_H__
7 #define __INTEL_ENGINE_STATS_H__
9 #include <linux/atomic.h>
10 #include <linux/ktime.h>
11 #include <linux/seqlock.h>
13 #include "i915_gem.h" /* GEM_BUG_ON */
14 #include "intel_engine.h"
16 static inline void intel_engine_context_in(struct intel_engine_cs *engine)
18 struct intel_engine_execlists_stats *stats = &engine->stats.execlists;
26 /* The writer is serialised; but the pmu reader may be from hardirq */
27 local_irq_save(flags);
28 write_seqcount_begin(&stats->lock);
30 stats->start = ktime_get();
33 write_seqcount_end(&stats->lock);
34 local_irq_restore(flags);
36 GEM_BUG_ON(!stats->active);
39 static inline void intel_engine_context_out(struct intel_engine_cs *engine)
41 struct intel_engine_execlists_stats *stats = &engine->stats.execlists;
44 GEM_BUG_ON(!stats->active);
45 if (stats->active > 1) {
50 local_irq_save(flags);
51 write_seqcount_begin(&stats->lock);
54 stats->total = ktime_add(stats->total,
55 ktime_sub(ktime_get(), stats->start));
57 write_seqcount_end(&stats->lock);
58 local_irq_restore(flags);
61 #endif /* __INTEL_ENGINE_STATS_H__ */