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)
20 if (engine->stats.active) {
21 engine->stats.active++;
25 /* The writer is serialised; but the pmu reader may be from hardirq */
26 local_irq_save(flags);
27 write_seqcount_begin(&engine->stats.lock);
29 engine->stats.start = ktime_get();
30 engine->stats.active++;
32 write_seqcount_end(&engine->stats.lock);
33 local_irq_restore(flags);
35 GEM_BUG_ON(!engine->stats.active);
38 static inline void intel_engine_context_out(struct intel_engine_cs *engine)
42 GEM_BUG_ON(!engine->stats.active);
43 if (engine->stats.active > 1) {
44 engine->stats.active--;
48 local_irq_save(flags);
49 write_seqcount_begin(&engine->stats.lock);
51 engine->stats.active--;
53 ktime_add(engine->stats.total,
54 ktime_sub(ktime_get(), engine->stats.start));
56 write_seqcount_end(&engine->stats.lock);
57 local_irq_restore(flags);
60 #endif /* __INTEL_ENGINE_STATS_H__ */