2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #include "assert_support.h"
16 #include "sh_css_metrics.h"
21 #include "sh_css_internal.h"
23 #define MULTIPLE_PCS 0
26 #define RESUME_MASK 0x8
29 static bool pc_histogram_enabled;
30 static struct sh_css_pc_histogram *isp_histogram;
31 static struct sh_css_pc_histogram *sp_histogram;
33 struct sh_css_metrics sh_css_metrics;
36 sh_css_metrics_start_frame(void)
38 sh_css_metrics.frame_metrics.num_frames++;
42 clear_histogram(struct sh_css_pc_histogram *histogram)
46 assert(histogram != NULL);
48 for (i = 0; i < histogram->length; i++) {
49 histogram->run[i] = 0;
50 histogram->stall[i] = 0;
51 histogram->msink[i] = 0xFFFF;
56 sh_css_metrics_enable_pc_histogram(bool enable)
58 pc_histogram_enabled = enable;
62 make_histogram(struct sh_css_pc_histogram *histogram, unsigned length)
64 assert(histogram != NULL);
66 if (histogram->length)
70 histogram->run = sh_css_malloc(length * sizeof(*histogram->run));
73 histogram->stall = sh_css_malloc(length * sizeof(*histogram->stall));
74 if (!histogram->stall)
76 histogram->msink = sh_css_malloc(length * sizeof(*histogram->msink));
77 if (!histogram->msink)
80 histogram->length = length;
81 clear_histogram(histogram);
85 insert_binary_metrics(struct sh_css_binary_metrics **l,
86 struct sh_css_binary_metrics *metrics)
90 assert(metrics != NULL);
92 for (; *l; l = &(*l)->next)
101 sh_css_metrics_start_binary(struct sh_css_binary_metrics *metrics)
103 assert(metrics != NULL);
105 if (!pc_histogram_enabled)
108 isp_histogram = &metrics->isp_histogram;
109 sp_histogram = &metrics->sp_histogram;
110 make_histogram(isp_histogram, ISP_PMEM_DEPTH);
111 make_histogram(sp_histogram, SP_PMEM_DEPTH);
112 insert_binary_metrics(&sh_css_metrics.binary_metrics, metrics);
116 sh_css_metrics_sample_pcs(void)
124 unsigned int stopped_sc = 0;
125 unsigned int resume_sc = 0;
131 unsigned int pc_tab[NOF_PCS];
133 for (i = 0; i < NOF_PCS; i++)
137 if (!pc_histogram_enabled)
143 isp_ctrl_store(ISP0_ID, ISP_SC_REG, STOP_MASK);
145 msink = isp_ctrl_load(ISP0_ID, ISP_CTRL_SINK_REG);
147 for (i = 0; i < NOF_PCS; i++)
148 pc_tab[i] = isp_ctrl_load(ISP0_ID, ISP_PC_REG);
150 pc = isp_ctrl_load(ISP0_ID, ISP_PC_REG);
155 isp_ctrl_store(ISP0_ID, ISP_SC_REG, RESUME_MASK);
157 isp_histogram->msink[pc] &= msink;
158 stall = (msink != 0x7FF);
161 isp_histogram->stall[pc]++;
163 isp_histogram->run[pc]++;
166 if (sp_histogram && 0) {
167 msink = sp_ctrl_load(SP0_ID, SP_CTRL_SINK_REG);
168 pc = sp_ctrl_load(SP0_ID, SP_PC_REG);
169 sp_histogram->msink[pc] &= msink;
170 stall = (msink != 0x7FF);
172 sp_histogram->stall[pc]++;
174 sp_histogram->run[pc]++;