0001
0002
0003
0004
0005
0006 #ifndef __INTEL_ENGINE_STATS_H__
0007 #define __INTEL_ENGINE_STATS_H__
0008
0009 #include <linux/atomic.h>
0010 #include <linux/ktime.h>
0011 #include <linux/seqlock.h>
0012
0013 #include "i915_gem.h" /* GEM_BUG_ON */
0014 #include "intel_engine.h"
0015
0016 static inline void intel_engine_context_in(struct intel_engine_cs *engine)
0017 {
0018 struct intel_engine_execlists_stats *stats = &engine->stats.execlists;
0019 unsigned long flags;
0020
0021 if (stats->active) {
0022 stats->active++;
0023 return;
0024 }
0025
0026
0027 local_irq_save(flags);
0028 write_seqcount_begin(&stats->lock);
0029
0030 stats->start = ktime_get();
0031 stats->active++;
0032
0033 write_seqcount_end(&stats->lock);
0034 local_irq_restore(flags);
0035
0036 GEM_BUG_ON(!stats->active);
0037 }
0038
0039 static inline void intel_engine_context_out(struct intel_engine_cs *engine)
0040 {
0041 struct intel_engine_execlists_stats *stats = &engine->stats.execlists;
0042 unsigned long flags;
0043
0044 GEM_BUG_ON(!stats->active);
0045 if (stats->active > 1) {
0046 stats->active--;
0047 return;
0048 }
0049
0050 local_irq_save(flags);
0051 write_seqcount_begin(&stats->lock);
0052
0053 stats->active--;
0054 stats->total = ktime_add(stats->total,
0055 ktime_sub(ktime_get(), stats->start));
0056
0057 write_seqcount_end(&stats->lock);
0058 local_irq_restore(flags);
0059 }
0060
0061 #endif