aboutsummaryrefslogtreecommitdiff
path: root/drivers/misc/mediatek/gpu/ged/src/ged_profile_dvfs.c
blob: 05cf7d7c444db305e8b98662d62ea84f34fba5fa (plain) (blame)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <linux/slab.h>
#include <linux/sched.h>
#include "ged_base.h"
#include "ged_log.h"
#include "ged_profile_dvfs.h"

static GED_LOG_BUF_HANDLE ghLogBuf = 0;
static struct mutex gsMutex;
static GED_BOOL gbAllowRecord = GED_FALSE;

GED_ERROR ged_profile_dvfs_init(void)
{
    mutex_init(&gsMutex);

#if 0
    ghLogBuf = ged_log_buf_alloc(320, 64 * 320, GED_LOG_BUF_TYPE_QUEUEBUFFER_AUTO_INCREASE, NULL, "profile_dvfs");
#endif

    return GED_OK;
}

GED_ERROR ged_profile_dvfs_enable(void)
{
    GED_ERROR ret;

    mutex_lock(&gsMutex);

    if (NULL == ghLogBuf)
    {
        ghLogBuf = ged_log_buf_alloc(320, 64 * 320, GED_LOG_BUF_TYPE_QUEUEBUFFER_AUTO_INCREASE, NULL, "profile_dvfs");
    }

    ret = ghLogBuf ? GED_OK : GED_ERROR_FAIL;

    mutex_unlock(&gsMutex);

    return ret;
}

void ged_profile_dvfs_disable(void)
{
    mutex_lock(&gsMutex);

    if (NULL != ghLogBuf)
    {
        ged_log_buf_free(ghLogBuf);
        ghLogBuf = NULL;
    }

    mutex_unlock(&gsMutex);
}

void ged_profile_dvfs_start(void)
{
    gbAllowRecord = GED_TRUE;
}

void ged_profile_dvfs_stop(void)
{
    gbAllowRecord = GED_FALSE;
}

void ged_profile_dvfs_ignore_lines(int i32LineCount)
{
    mutex_lock(&gsMutex);

    if (ghLogBuf)
    {
        ged_log_buf_ignore_lines(ghLogBuf, i32LineCount);
    }

    mutex_unlock(&gsMutex);
}

void ged_profile_dvfs_exit(void)
{
    ged_profile_dvfs_disable();
}

void ged_profile_dvfs_record_freq_volt(unsigned int ui32Frequency, unsigned int ui32Voltage)
{
    mutex_lock(&gsMutex);

    if (ghLogBuf && gbAllowRecord)
    {
    	/* copy & modify from ./kernel/printk.c */
    	unsigned long long t;
    	unsigned long nanosec_rem;

    	t = cpu_clock(smp_processor_id());
    	nanosec_rem = do_div(t, 1000000000) / 1000;

        ged_log_buf_print(ghLogBuf, "%5lu.%06lu,freq_volt,%u,%u", (unsigned long) t, nanosec_rem, ui32Frequency, ui32Voltage);
    }
    mutex_unlock(&gsMutex);
}

void ged_profile_dvfs_record_temp(int i32Temp)
{
    mutex_lock(&gsMutex);

    if (ghLogBuf && gbAllowRecord)
    {
    	/* copy & modify from ./kernel/printk.c */
    	unsigned long long t;
    	unsigned long nanosec_rem;

    	t = cpu_clock(smp_processor_id());
    	nanosec_rem = do_div(t, 1000000000) / 1000;

        ged_log_buf_print(ghLogBuf, "%5lu.%06lu,temp,%d", (unsigned long) t, nanosec_rem, i32Temp);
    }
    mutex_unlock(&gsMutex);

}

void ged_profile_dvfs_record_thermal_limit(unsigned int ui32FreqLimit)
{
    mutex_lock(&gsMutex);

    if (ghLogBuf && gbAllowRecord)
    {
    	/* copy & modify from ./kernel/printk.c */
    	unsigned long long t;
    	unsigned long nanosec_rem;

    	t = cpu_clock(smp_processor_id());
    	nanosec_rem = do_div(t, 1000000000) / 1000;

        ged_log_buf_print(ghLogBuf, "%5lu.%06lu,thermal_limit,%u", (unsigned long) t, nanosec_rem, ui32FreqLimit);
    }
    mutex_unlock(&gsMutex);
}

void ged_profile_dvfs_record_gpu_loading(unsigned int ui32GpuLoading)
{
    mutex_lock(&gsMutex);

    if (ghLogBuf && gbAllowRecord)
    {
    	/* copy & modify from ./kernel/printk.c */
    	unsigned long long t;
    	unsigned long nanosec_rem;

    	t = cpu_clock(smp_processor_id());
    	nanosec_rem = do_div(t, 1000000000) / 1000;

        ged_log_buf_print(ghLogBuf, "%5lu.%06lu,gpu_load,%u", (unsigned long) t, nanosec_rem, ui32GpuLoading);
    }

    mutex_unlock(&gsMutex);
}

void ged_profile_dvfs_record_clock_on(void)
{
    mutex_lock(&gsMutex);

    if (ghLogBuf && gbAllowRecord)
    {
    	/* copy & modify from ./kernel/printk.c */
    	unsigned long long t;
    	unsigned long nanosec_rem;

    	t = cpu_clock(smp_processor_id());
    	nanosec_rem = do_div(t, 1000000000) / 1000;

        ged_log_buf_print(ghLogBuf, "%5lu.%06lu,gpu_clock,1", (unsigned long) t, nanosec_rem);
    }

    mutex_unlock(&gsMutex);
}

void ged_profile_dvfs_record_clock_off(void)
{
    mutex_lock(&gsMutex);

    if (ghLogBuf && gbAllowRecord)
    {
    	/* copy & modify from ./kernel/printk.c */
    	unsigned long long t;
    	unsigned long nanosec_rem;

    	t = cpu_clock(smp_processor_id());
    	nanosec_rem = do_div(t, 1000000000) / 1000;

        ged_log_buf_print(ghLogBuf, "%5lu.%06lu,gpu_clock,0", (unsigned long) t, nanosec_rem);
    }

    mutex_unlock(&gsMutex);
}