15ca02815Sjsg /* SPDX-License-Identifier: MIT */ 25ca02815Sjsg /* 35ca02815Sjsg * Copyright © 2020 Intel Corporation 45ca02815Sjsg */ 55ca02815Sjsg 65ca02815Sjsg #ifndef __INTEL_ENGINE_STATS_H__ 75ca02815Sjsg #define __INTEL_ENGINE_STATS_H__ 85ca02815Sjsg 95ca02815Sjsg #include <linux/atomic.h> 105ca02815Sjsg #include <linux/ktime.h> 115ca02815Sjsg #include <linux/seqlock.h> 125ca02815Sjsg 135ca02815Sjsg #include "i915_gem.h" /* GEM_BUG_ON */ 145ca02815Sjsg #include "intel_engine.h" 155ca02815Sjsg intel_engine_context_in(struct intel_engine_cs * engine)165ca02815Sjsgstatic inline void intel_engine_context_in(struct intel_engine_cs *engine) 175ca02815Sjsg { 18*1bb76ff1Sjsg struct intel_engine_execlists_stats *stats = &engine->stats.execlists; 195ca02815Sjsg unsigned long flags; 205ca02815Sjsg 21*1bb76ff1Sjsg if (stats->active) { 22*1bb76ff1Sjsg stats->active++; 235ca02815Sjsg return; 245ca02815Sjsg } 255ca02815Sjsg 265ca02815Sjsg /* The writer is serialised; but the pmu reader may be from hardirq */ 275ca02815Sjsg local_irq_save(flags); 28*1bb76ff1Sjsg write_seqcount_begin(&stats->lock); 295ca02815Sjsg 30*1bb76ff1Sjsg stats->start = ktime_get(); 31*1bb76ff1Sjsg stats->active++; 325ca02815Sjsg 33*1bb76ff1Sjsg write_seqcount_end(&stats->lock); 345ca02815Sjsg local_irq_restore(flags); 355ca02815Sjsg 36*1bb76ff1Sjsg GEM_BUG_ON(!stats->active); 375ca02815Sjsg } 385ca02815Sjsg intel_engine_context_out(struct intel_engine_cs * engine)395ca02815Sjsgstatic inline void intel_engine_context_out(struct intel_engine_cs *engine) 405ca02815Sjsg { 41*1bb76ff1Sjsg struct intel_engine_execlists_stats *stats = &engine->stats.execlists; 425ca02815Sjsg unsigned long flags; 435ca02815Sjsg 44*1bb76ff1Sjsg GEM_BUG_ON(!stats->active); 45*1bb76ff1Sjsg if (stats->active > 1) { 46*1bb76ff1Sjsg stats->active--; 475ca02815Sjsg return; 485ca02815Sjsg } 495ca02815Sjsg 505ca02815Sjsg local_irq_save(flags); 51*1bb76ff1Sjsg write_seqcount_begin(&stats->lock); 525ca02815Sjsg 53*1bb76ff1Sjsg stats->active--; 54*1bb76ff1Sjsg stats->total = ktime_add(stats->total, 55*1bb76ff1Sjsg ktime_sub(ktime_get(), stats->start)); 565ca02815Sjsg 57*1bb76ff1Sjsg write_seqcount_end(&stats->lock); 585ca02815Sjsg local_irq_restore(flags); 595ca02815Sjsg } 605ca02815Sjsg 615ca02815Sjsg #endif /* __INTEL_ENGINE_STATS_H__ */ 62