debug: add atrace support [1/1]
authorTao Guo <tao.guo@amlogic.com>
Wed, 16 Jan 2019 09:11:54 +0000 (17:11 +0800)
committerNick Xie <nick@khadas.com>
Mon, 5 Aug 2019 06:13:34 +0000 (14:13 +0800)
PD#SWPL-4956

Problem:
Need atrace to debug multimedia issue

Solution:
Add atrace functions

Verify:
P212

Change-Id: I0f07387dfa35a33c25e538a474a3a12bd88d5092
Signed-off-by: Tao Guo <tao.guo@amlogic.com>
Signed-off-by: Luan Yuan <luan.yuan@amlogic.com>
drivers/amlogic/debug/Kconfig
drivers/amlogic/debug/Makefile
drivers/amlogic/debug/meson_atrace.c [new file with mode: 0644]
drivers/amlogic/media/frame_sync/timestamp.c
drivers/amlogic/media/video_sink/video.c
include/trace/events/meson_atrace.h

index 34af209..1bbc487 100644 (file)
@@ -13,3 +13,9 @@ config AMLOGIC_DEBUG_LOCKUP
                Debug lockup in isr and deaklock whit irq disabled.
                When enable this config, Watchdog should be disabled.
 
+config AMLOGIC_DEBUG_ATRACE
+       bool "Amlogic Kernel ATrace"
+       depends on AMLOGIC_DEBUG
+       default y
+       help
+               Add android atrace compatible function
index 2f07bf9..7576af9 100644 (file)
@@ -1 +1,2 @@
 obj-$(CONFIG_AMLOGIC_DEBUG_LOCKUP)     += debug_lockup.o
+obj-$(CONFIG_AMLOGIC_DEBUG_ATRACE)     += meson_atrace.o
diff --git a/drivers/amlogic/debug/meson_atrace.c b/drivers/amlogic/debug/meson_atrace.c
new file mode 100644 (file)
index 0000000..f271326
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * drivers/amlogic/debug/meson_atrace.c
+ *
+ * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ */
+
+#define CREATE_TRACE_POINTS
+#include <trace/events/meson_atrace.h>
+
+EXPORT_TRACEPOINT_SYMBOL_GPL(tracing_mark_write);
index 472be72..a6076d5 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/amlogic/media/utils/vdec_reg.h>
 #include <linux/amlogic/media/registers/register.h>
 #include <linux/amlogic/media/vout/vout_notify.h>
+#include <trace/events/meson_atrace.h>
 
 
 u32 acc_apts_inc;
@@ -147,6 +148,7 @@ EXPORT_SYMBOL(timestamp_tsdemux_pcr_get);
 void timestamp_pcrscr_set(u32 pts)
 {
        /*pr_info("timestamp_pcrscr_set system time  = %x\n", pts);*/
+       ATRACE_COUNTER("PCRSCR",  pts);
        system_time = pts;
 }
 EXPORT_SYMBOL(timestamp_pcrscr_set);
@@ -210,6 +212,7 @@ void timestamp_pcrscr_inc(s32 inc)
                inc = inc * timestamp_inc_factor / PLL_FACTOR;
 #endif
                system_time += inc + system_time_inc_adj;
+               ATRACE_COUNTER("PCRSCR",  system_time);
        }
 }
 EXPORT_SYMBOL(timestamp_pcrscr_inc);
@@ -234,6 +237,7 @@ void timestamp_pcrscr_inc_scale(s32 inc, u32 base)
                        system_time++;
                        system_time_scale_remainder -= system_time_scale_base;
                }
+               ATRACE_COUNTER("PCRSCR",  system_time);
        }
 }
 EXPORT_SYMBOL(timestamp_pcrscr_inc_scale);
index 01b6025..814aa87 100644 (file)
@@ -49,6 +49,7 @@
 #include <linux/sched.h>
 #include <linux/amlogic/media/video_sink/video_keeper.h>
 #include "video_priv.h"
+#include <trace/events/meson_atrace.h>
 
 #if defined(CONFIG_AMLOGIC_MEDIA_ENHANCEMENT_VECM)
 #include <linux/amlogic/media/amvecm/amvecm.h>
@@ -3536,8 +3537,10 @@ static u64 func_div(u64 number, u32 divid)
        return tmp;
 }
 
-static void vsync_toggle_frame(struct vframe_s *vf)
+static void vsync_toggle_frame(struct vframe_s *vf, int line)
 {
+       static u32 last_pts;
+       u32 diff_pts;
        u32 first_picture = 0;
        unsigned long flags = 0;
        bool vf_with_el = false;
@@ -3545,8 +3548,18 @@ static void vsync_toggle_frame(struct vframe_s *vf)
        long long *clk_array;
        bool is_mvc = false;
 
+       ATRACE_COUNTER(__func__,  line);
        if (vf == NULL)
                return;
+       ATRACE_COUNTER("vsync_toggle_frame_pts", vf->pts);
+
+       diff_pts = vf->pts - last_pts;
+       if (last_pts && diff_pts < 90000)
+               ATRACE_COUNTER("vsync_toggle_frame_inc", diff_pts);
+       else
+               ATRACE_COUNTER("vsync_toggle_frame_inc", 0);  /* discontinue */
+       last_pts = vf->pts;
+
        frame_count++;
        toggle_count++;
 
@@ -3629,6 +3642,7 @@ static void vsync_toggle_frame(struct vframe_s *vf)
        if ((vf->width == 0) && (vf->height == 0)) {
                amlog_level(LOG_LEVEL_ERROR,
                            "Video: invalid frame dimension\n");
+               ATRACE_COUNTER(__func__,  __LINE__);
                return;
        }
 
@@ -3662,6 +3676,7 @@ static void vsync_toggle_frame(struct vframe_s *vf)
                                }
                        }
                        video_vf_put(vf);
+                       ATRACE_COUNTER(__func__,  __LINE__);
                        return;
                }
        }
@@ -4052,6 +4067,7 @@ static void vsync_toggle_frame(struct vframe_s *vf)
 #endif
                }
        }
+       ATRACE_COUNTER(__func__,  0);
 }
 
 static void viu_set_dcu(struct vpp_frame_par_s *frame_par, struct vframe_s *vf)
@@ -6453,7 +6469,7 @@ static irqreturn_t vsync_isr_in(int irq, void *dev_id)
                                                cur_index;
                                        }
                                }
-                               vsync_toggle_frame(cur_dispbuf);
+                               vsync_toggle_frame(cur_dispbuf, __LINE__);
                        } else
                                video_property_changed = 0;
                } else {
@@ -6466,11 +6482,12 @@ static irqreturn_t vsync_isr_in(int irq, void *dev_id)
 
        /* setting video display property in underflow mode */
        if ((!vf) && cur_dispbuf && (video_property_changed))
-               vsync_toggle_frame(cur_dispbuf);
+               vsync_toggle_frame(cur_dispbuf, __LINE__);
 
        /*debug info for skip & repeate vframe case*/
        if (!vf) {
                underflow++;
+               ATRACE_COUNTER("underflow",  1);
                if (video_dbg_vf&(1<<0))
                        dump_vframe_status("vdin0");
                if (video_dbg_vf&(1<<1))
@@ -6481,6 +6498,8 @@ static irqreturn_t vsync_isr_in(int irq, void *dev_id)
                        dump_vframe_status("ppmgr");
                if (video_dbg_vf&(1<<4))
                        dump_vdin_reg();
+       } else {
+               ATRACE_COUNTER("underflow",  0);
        }
        video_get_vf_cnt = 0;
        if (platform_type == 1) {
@@ -6490,6 +6509,7 @@ static irqreturn_t vsync_isr_in(int irq, void *dev_id)
        }
        while (vf) {
                if (vpts_expire(cur_dispbuf, vf, toggle_cnt) || show_nosync) {
+                       ATRACE_COUNTER(MODULE_NAME,  __LINE__);
                        if (debug_flag & DEBUG_FLAG_PTS_TRACE)
                                pr_info("vpts = 0x%x, c.dur=0x%x, n.pts=0x%x, scr = 0x%x, pcr-pts-diff=%d, ptstrace=%d\n",
                                        timestamp_vpts_get(),
@@ -6540,8 +6560,10 @@ static irqreturn_t vsync_isr_in(int irq, void *dev_id)
                                hdmiin_frame_check_cnt = 0;
 
                        vf = video_vf_get();
-                       if (!vf)
+                       if (!vf) {
+                               ATRACE_COUNTER(MODULE_NAME,  __LINE__);
                                break;
+                       }
                        if (debug_flag & DEBUG_FLAG_LATENCY) {
                                vf->ready_clock[2] = sched_clock();
                                pr_info("video get latency %lld ms vdin put latency %lld ms. first %lld ms.\n",
@@ -6549,8 +6571,10 @@ static irqreturn_t vsync_isr_in(int irq, void *dev_id)
                                func_div(vf->ready_clock[1], 1000),
                                func_div(vf->ready_clock[0], 1000));
                        }
-                       if (video_vf_dirty_put(vf))
+                       if (video_vf_dirty_put(vf)) {
+                               ATRACE_COUNTER(MODULE_NAME,  __LINE__);
                                break;
+                       }
                        if (vf && hdmiin_frame_check && (vf->source_type ==
                                VFRAME_SOURCE_TYPE_HDMI) &&
                                video_vf_disp_mode_check(vf))
@@ -6568,7 +6592,7 @@ static irqreturn_t vsync_isr_in(int irq, void *dev_id)
                                        video_3d_format = vf->trans_fmt;
                                }
                        }
-                       vsync_toggle_frame(vf);
+                       vsync_toggle_frame(vf, __LINE__);
                        toggle_frame = vf;
 #ifdef CONFIG_AMLOGIC_MEDIA_ENHANCEMENT_DOLBYVISION
                        if (is_dolby_vision_enable()) {
@@ -6615,6 +6639,7 @@ static irqreturn_t vsync_isr_in(int irq, void *dev_id)
                        if (video_get_vf_cnt >= 2)
                                video_drop_vf_cnt++;
                } else {
+                       ATRACE_COUNTER(MODULE_NAME,  __LINE__);
                        /* check if current frame's duration has expired,
                         *in this example
                         * it compares current frame display duration
@@ -6626,6 +6651,7 @@ static irqreturn_t vsync_isr_in(int irq, void *dev_id)
                         * The playback can be smoother than previous method.
                         */
                        if (slowsync_repeat_enable) {
+                               ATRACE_COUNTER(MODULE_NAME,  __LINE__);
                                if (duration_expire
                                    (cur_dispbuf, vf,
                                     frame_repeat_count * vsync_pts_inc)
@@ -6657,9 +6683,12 @@ static irqreturn_t vsync_isr_in(int irq, void *dev_id)
                                                break;
 #endif
                                        vf = video_vf_get();
-                                       if (!vf)
+                                       if (!vf) {
+                                               ATRACE_COUNTER(MODULE_NAME,
+                                                               __LINE__);
                                                break;
-                                       vsync_toggle_frame(vf);
+                                       }
+                                       vsync_toggle_frame(vf, __LINE__);
                                        toggle_frame = vf;
 #ifdef CONFIG_AMLOGIC_MEDIA_ENHANCEMENT_DOLBYVISION
                                        if (is_dolby_vision_enable())
@@ -6692,9 +6721,11 @@ static irqreturn_t vsync_isr_in(int irq, void *dev_id)
                                if (blackout | force_blackout) {
                                        if (cur_dispbuf != &vf_local)
                                                vsync_toggle_frame(
-                                                               cur_dispbuf);
+                                                               cur_dispbuf,
+                                                               __LINE__);
                                } else
-                                       vsync_toggle_frame(cur_dispbuf);
+                                       vsync_toggle_frame(cur_dispbuf,
+                                                       __LINE__);
                                if (is_dolby_vision_enable()) {
                                        pause_vf = cur_dispbuf;
                                        video_pause_global = 1;
index 935ac94..96d5eea 100644 (file)
@@ -66,13 +66,18 @@ TRACE_EVENT(tracing_mark_write,
                print_flags_delim(__entry->flags),
                __get_str(name), __entry->value)
 );
-
+#ifdef CONFIG_AMLOGIC_DEBUG_ATRACE
 #define ATRACE_COUNTER(name, value) \
        trace_tracing_mark_write(name, (1 << KERNEL_ATRACE_COUNTER), value)
 #define ATRACE_BEGIN(name) \
        trace_tracing_mark_write(name, (1 << KERNEL_ATRACE_BEGIN), 0)
 #define ATRACE_END(name) \
        trace_tracing_mark_write("", (1 << KERNEL_ATRACE_END), 1)
+#else
+#define ATRACE_COUNTER(name, value)
+#define ATRACE_BEGIN(name)
+#define ATRACE_END(name)
+#endif
 
 #endif /* _TRACE_MESON_BASE_H */