Linux Audio

Check our new training course

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