summaryrefslogtreecommitdiff
path: root/drivers/video/b2r2/b2r2_profiler_socket.c
blob: cb95af9380e1e69a7498c90d1e850a2ace65b47b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright (C) ST-Ericsson SA 2010
 *
 * ST-Ericsson B2R2 profiler socket communication
 *
 * Author: Johan Mossberg <johan.xx.mossberg@stericsson.com>
 * for ST-Ericsson.
 *
 * License terms: GNU General Public License (GPL), version 2.
 */

#include <linux/module.h>
#include <linux/device.h>
#include <linux/semaphore.h>
#include <asm/errno.h>

#include "b2r2_profiler_api.h"
#include "b2r2_internal.h"
#include "b2r2_core.h"

/*
 * TODO: Call the profiler in a seperate thread and have a circular buffer
 * between the B2R2 driver and that thread. That way the profiler can not slow
 * down or kill the B2R2 driver. Seems a bit overkill right now as there is
 * only one B2R2 profiler and we have full control over it but the situation
 * may be different in the future.
 */


static const struct b2r2_profiler *b2r2_profiler;
static DEFINE_SEMAPHORE(b2r2_profiler_lock);


int b2r2_register_profiler(const struct b2r2_profiler * const profiler)
{
	int return_value;

	return_value = down_interruptible(&b2r2_profiler_lock);
	if (return_value != 0)
		return return_value;

	if (b2r2_profiler != NULL) {
		return_value = -EUSERS;

		goto cleanup;
	}

	b2r2_profiler = profiler;

	return_value = 0;

cleanup:
	up(&b2r2_profiler_lock);

	return return_value;
}
EXPORT_SYMBOL(b2r2_register_profiler);

void b2r2_unregister_profiler(const struct b2r2_profiler * const profiler)
{
	down(&b2r2_profiler_lock);

	if (profiler == b2r2_profiler)
		b2r2_profiler = NULL;

	up(&b2r2_profiler_lock);
}
EXPORT_SYMBOL(b2r2_unregister_profiler);


bool is_profiler_registered_approx(void)
{
	/* No locking by design, to make it fast, hence the approx */
	if (b2r2_profiler != NULL)
		return true;
	else
		return false;
}

void b2r2_call_profiler_blt_done(const struct b2r2_blt_request * const request)
{
	int return_value;
	struct b2r2_blt_profiling_info blt_profiling_info;
	struct b2r2_core *core = (struct b2r2_core *) request->job.data;
	struct b2r2_control *cont = core->control;

	return_value = down_interruptible(&b2r2_profiler_lock);
	if (return_value != 0) {
		dev_err(cont->dev,
			"%s: Failed to acquire semaphore, ret=%i. "
			"Lost profiler call!\n", __func__, return_value);

		return;
	}

	if (NULL == b2r2_profiler)
		goto cleanup;

	blt_profiling_info.nsec_active_in_cpu = request->nsec_active_in_cpu;
	blt_profiling_info.nsec_active_in_b2r2 = request->job.nsec_active_in_hw;
	blt_profiling_info.total_time_nsec = request->total_time_nsec;

	b2r2_profiler->blt_done(&request->user_req, request->request_id, &blt_profiling_info);

cleanup:
	up(&b2r2_profiler_lock);
}