1 /*
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 * Description: zdiag dfx
15 * This file should be changed only infrequently and with great care.
16 */
17
18 #ifndef __ZDIAG_DFX_H__
19 #define __ZDIAG_DFX_H__
20
21 #include "errcode.h"
22 #include "zdiag_dfx_st.h"
23 #include "diag.h"
24
25 zdiag_dfx_stat_t *uapi_zdiag_get_dfx_stat(void);
26 errcode_t diag_dfx_cmd(uint16_t cmd_id, void *cmd_param, uint16_t cmd_param_size, diag_option_t *option);
27
diag_dfx_channel_receive_data(uint32_t chan_id,uint32_t cnt)28 static inline void diag_dfx_channel_receive_data(uint32_t chan_id, uint32_t cnt)
29 {
30 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
31 if (chan_id < DIAG_DFX_SUPPORT_MAX_CHANNEL) {
32 g_zdiag_dfx_stat->channel_receive_data_cnt[chan_id] += cnt;
33 }
34 }
35
diag_dfx_channel_receive_frame(uint32_t chan_id,uint32_t cnt)36 static inline void diag_dfx_channel_receive_frame(uint32_t chan_id, uint32_t cnt)
37 {
38 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
39 if (chan_id < DIAG_DFX_SUPPORT_MAX_CHANNEL) {
40 g_zdiag_dfx_stat->channel_receive_frame_cnt[chan_id] += cnt;
41 }
42 }
43
diag_dfx_alloc_pkt(uint32_t pkt_type,uint32_t size)44 static inline void diag_dfx_alloc_pkt(uint32_t pkt_type, uint32_t size)
45 {
46 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
47 if (pkt_type < DIAG_DFX_SUPPORT_MAX_PKT_MEM_TYPE) {
48 g_zdiag_dfx_stat->mem_pkt_alloc_size[pkt_type] += size;
49 }
50 }
51
diag_dfx_free_pkt(uint32_t pkt_type,uint32_t size)52 static inline void diag_dfx_free_pkt(uint32_t pkt_type, uint32_t size)
53 {
54 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
55 if (pkt_type < DIAG_DFX_SUPPORT_MAX_PKT_MEM_TYPE) {
56 g_zdiag_dfx_stat->mem_pkt_free_size[pkt_type] += size;
57 }
58 }
59
zdiag_dfx_put_msg_2_cache_fail(void)60 static inline void zdiag_dfx_put_msg_2_cache_fail(void)
61 {
62 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
63 g_zdiag_dfx_stat->put_msg_2_cache_fail_times++;
64 }
65
diag_dfx_msg_process_time(uint32_t time)66 static inline void diag_dfx_msg_process_time(uint32_t time)
67 {
68 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
69 if (g_zdiag_dfx_stat->dfx_msg_process_max_time < time) {
70 g_zdiag_dfx_stat->dfx_msg_process_max_time = time;
71 }
72 }
73
diag_transmit_msg_process_time(uint32_t time)74 static inline void diag_transmit_msg_process_time(uint32_t time)
75 {
76 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
77 if (g_zdiag_dfx_stat->transmit_msg_process_max_time < time) {
78 g_zdiag_dfx_stat->transmit_msg_process_max_time = time;
79 }
80 }
81
zdiag_dfx_send_local_q_success(void)82 static inline void zdiag_dfx_send_local_q_success(void)
83 {
84 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
85 g_zdiag_dfx_stat->send_local_q_success++;
86 }
87
zdiag_dfx_send_local_q_fail(void)88 static inline void zdiag_dfx_send_local_q_fail(void)
89 {
90 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
91 g_zdiag_dfx_stat->send_local_q_fail++;
92 }
93
zdiag_dfx_rev_msg(void)94 static inline void zdiag_dfx_rev_msg(void)
95 {
96 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
97 g_zdiag_dfx_stat->msg_rev_cnt++;
98 }
99
diag_dfx_transmit_rev_msg(void)100 static inline void diag_dfx_transmit_rev_msg(void)
101 {
102 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
103 g_zdiag_dfx_stat->transmit_msg_rev_cnt++;
104 }
105
zdiag_dfx_rev_pkt_msg(void)106 static inline void zdiag_dfx_rev_pkt_msg(void)
107 {
108 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
109 g_zdiag_dfx_stat->diag_pkt_msg_rev_cnt++;
110 }
111
zdiag_dfx_rev_beat_herat_msg(void)112 static inline void zdiag_dfx_rev_beat_herat_msg(void)
113 {
114 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
115 g_zdiag_dfx_stat->beat_heart_msg_rev_cnt++;
116 }
zdiag_dfx_conn_except(void)117 static inline void zdiag_dfx_conn_except(void)
118 {
119 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
120 g_zdiag_dfx_stat->conn_excep_cnt++;
121 }
zdiag_dfx_conn_bu_inc(void)122 static inline void zdiag_dfx_conn_bu_inc(void)
123 {
124 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
125 g_zdiag_dfx_stat->conn_bu_cnt++;
126 }
127
diag_dfx_mem_alloc(uint32_t size)128 static inline void diag_dfx_mem_alloc(uint32_t size)
129 {
130 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
131 g_zdiag_dfx_stat->alloc_mem_size += size;
132 if (g_zdiag_dfx_stat->alloc_mem_size > g_zdiag_dfx_stat->alloc_mem_peak_size) {
133 g_zdiag_dfx_stat->alloc_mem_peak_size = g_zdiag_dfx_stat->alloc_mem_size;
134 }
135 }
136
diag_dfx_mem_free(uint32_t size)137 static inline void diag_dfx_mem_free(uint32_t size)
138 {
139 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
140 g_zdiag_dfx_stat->alloc_mem_size -= size;
141 }
142
diag_dfx_current_msg_num(uint16_t msg_num)143 static inline void diag_dfx_current_msg_num(uint16_t msg_num)
144 {
145 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
146 g_zdiag_dfx_stat->dfx_msg_q_num = msg_num;
147 if (msg_num > g_zdiag_dfx_stat->dfx_msg_q_peak_num) {
148 g_zdiag_dfx_stat->dfx_msg_q_peak_num = msg_num;
149 }
150 }
151
diag_dfx_current_transmit_msg_num(uint16_t msg_num)152 static inline void diag_dfx_current_transmit_msg_num(uint16_t msg_num)
153 {
154 zdiag_dfx_stat_t *g_zdiag_dfx_stat = uapi_zdiag_get_dfx_stat();
155 g_zdiag_dfx_stat->transmit_msg_q_num = msg_num;
156 if (msg_num > g_zdiag_dfx_stat->transmit_msg_q_peak_num) {
157 g_zdiag_dfx_stat->transmit_msg_q_peak_num = msg_num;
158 }
159 }
160
161 #endif
162