intel_engine_stats.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Copyright © 2020 Intel Corporation
  4. */
  5. #ifndef __INTEL_ENGINE_STATS_H__
  6. #define __INTEL_ENGINE_STATS_H__
  7. #include <linux/atomic.h>
  8. #include <linux/ktime.h>
  9. #include <linux/seqlock.h>
  10. #include "i915_gem.h" /* GEM_BUG_ON */
  11. #include "intel_engine.h"
  12. static inline void intel_engine_context_in(struct intel_engine_cs *engine)
  13. {
  14. struct intel_engine_execlists_stats *stats = &engine->stats.execlists;
  15. unsigned long flags;
  16. if (stats->active) {
  17. stats->active++;
  18. return;
  19. }
  20. /* The writer is serialised; but the pmu reader may be from hardirq */
  21. local_irq_save(flags);
  22. write_seqcount_begin(&stats->lock);
  23. stats->start = ktime_get();
  24. stats->active++;
  25. write_seqcount_end(&stats->lock);
  26. local_irq_restore(flags);
  27. GEM_BUG_ON(!stats->active);
  28. }
  29. static inline void intel_engine_context_out(struct intel_engine_cs *engine)
  30. {
  31. struct intel_engine_execlists_stats *stats = &engine->stats.execlists;
  32. unsigned long flags;
  33. GEM_BUG_ON(!stats->active);
  34. if (stats->active > 1) {
  35. stats->active--;
  36. return;
  37. }
  38. local_irq_save(flags);
  39. write_seqcount_begin(&stats->lock);
  40. stats->active--;
  41. stats->total = ktime_add(stats->total,
  42. ktime_sub(ktime_get(), stats->start));
  43. write_seqcount_end(&stats->lock);
  44. local_irq_restore(flags);
  45. }
  46. #endif /* __INTEL_ENGINE_STATS_H__ */