Hi Mike,

Get Outlook for Android


From: Mathieu Poirier <mathieu.poirier@linaro.org>
Sent: Tuesday, June 11, 2019 10:34:49 PM
To: Student - Ng Yi Zher Jeremy
Cc: Leo Yan; Suzuki K Poulose; Coresight ML
Subject: Re: Request for Guidance in Using sysFS for Coresight in HiKey960 (Cortex A53/A73)
 
On Mon, 10 Jun 2019 at 21:35, Student - Ng Yi Zher Jeremy
<jeremy_ng@mymail.sutd.edu.sg> wrote:
>
> Dear Leo Yan Sir,
>
> Thank you for your message. Please look at inline comments for reply.
> ________________________________
> From: Leo Yan <leo.yan@linaro.org>
> Sent: 10 June 2019 17:32
> To: Student - Ng Yi Zher Jeremy
> Cc: Mathieu Poirier; Suzuki K Poulose; Coresight ML
> Subject: Re: Request for Guidance in Using sysFS for Coresight in HiKey960 (Cortex A53/A73)
>
> Hi Jeremy,
>
> Please see several quick inline comments.
>
> On Mon, Jun 10, 2019 at 08:49:48AM +0000, Student - Ng Yi Zher Jeremy wrote:
>
>
> [...]
>
> > ```bash
> > -rw-r--r-- 1 root root 4096 1970-01-01 00:11 ecc40000.etm/addr_start
> > hikey960:/sys/bus/coresight/devices # echo d10583ff > ecc40000.etm/addr_start
> > 1|hikey960:/sys/bus/coresight/devices # cat ecc40000.etm/addr_start
> > cat: ecc40000.etm/addr_start: Operation not permitted
> > ```
>
> After read the code, I think you need firstly to specify addr_idx:
>
>   echo 3 > ecc40000.etm/addr_idx
>   echo d10583ff > ecc40000.etm/addr_start
>   cat ecc40000.etm/addr_start
>
> I did this as per instructed here and I was able to now read the `addr_start` file. However, there is still no trace found when I run the program.
>
> I will like to clarify that addr_start is referring to the instruction address and not the PC counter.
>
> > I thought it was not important that the Operation was 'not permitted'. Nonetheless, I continued with the tutorial as depicted [here](https://github.com/torvalds/linux/blob/master/Documentation/trace/coresight.txt). One thing I will like to note is that my `rwp` did move when i initially activated the sink and source. However, the 2nd time i checked the `rwp`, it went back `0x0`, the same position as that of my `rrp`.
> >
> > Regardless, I run the program in another kernel, performed CPU affinity to the program to point at the CPU in which the ETM is activated (in this case, CPU0). While the program is running, i looked at the `rwp/rrp` and see that neither of the pointers are moving. I thought perhaps if i perform `dd` operation, I might be able to get something.
> >
> > I performed `dd if=/dev/ec036000.etf of=/data/cs.bin bs=1M` but my device crashed and reboot itself without saving any files.
>
> Could you try below commands before dd command?
>
>   echo 1 > /sys/bus/coresight/devices/ec036000.etf
>   # Enable ETM for CPU0
>   echo 1 > /sys/bus/coresight/devices/ecc40000.etm/enable_source
>   dd if=/dev/ec036000.etf of=/data/cs.bin bs=1M
>
> I did this command as per usual. I even tried enabling different ETFs and alternating enable ETR to see if there are any difference. There is still no movement in my `rwp`. Even if it did (at the start), when i perform `dd` command, it reads:
>
> ```
> hikey960:/sys/bus/coresight/devices # dd if=/dev/ec036000.etf of=/data/cs.bin bs=1M
> 0+1 records in
> 0+1 records out
> 32 bytes (32 B) copied, 0.000517 s, 60 K/s
> ```
>
> I have attached the encoded trace file (cs.bin), decoded trace file (cs.log_e) and the decoded min trace file (just the addresses line: addr_e.log) in this mail. I used ptm2human API for decoding (link here: https://github.com/hwangcc23/ptm2human).
>
> What puzzled me, furthermore, is that it seems i can never perform `dd` on ec80200.etf. Performing that command on that memory address tends to crash the AOSP in Hikey960.
>
>
> Please note, you need firstly configure the address range, and then
> enable the ETM and sink.  If afterwards change the address range
> again, you need disable etf/etm and re-enable etf/etm so can set
> address range configuration into registers properly.
>
> I thought i should detail the entire process for your expertise advise:
>
> ```
> root@intern-nzyj:/data/cstrace# adb shell
> hikey960:/ # cd sys/bus/coresight/devices/
> hikey960:/sys/bus/coresight/devices # echo 3 > ecc40000.etm/addr_idx
> hikey960:/sys/bus/coresight/devices # echo d10583ff > ecc40000.etm/addr_start
> hikey960:/sys/bus/coresight/devices # echo d65f03c0 > ecc40000.etm/addr_stop
> 1|hikey960:/sys/bus/coresight/devices # echo 0 ffffffffffffffffff > ecc40000.etm/addr_range
> 1|hikey960:/sys/bus/coresight/devices # echo 1 > ec036000.etf/enable_sink
> hikey960:/sys/bus/coresight/devices # echo 1 > ecc40000.etm/enable_source
> hikey960:/sys/bus/coresight/devices # cat ec036000.etf/mgmt/rwp
> 0x7b0
> hikey960:/sys/bus/coresight/devices # cat ec036000.etf/mgmt/rrp
> 0x7b0
> hikey960:/sys/bus/coresight/devices # cat ec036000.etf/mgmt/sts
> 0x1
> hikey960:/sys/bus/coresight/devices # cat ec036000.etf/mgmt/ctl
> 0x1
> hikey960:/sys/bus/coresight/devices # cat ec036000.etf/mgmt/rwp
> 0x7b0
> hikey960:/sys/bus/coresight/devices # cat ec036000.etf/mgmt/rwp
> 0x7b0
> hikey960:/sys/bus/coresight/devices # taskset -p 8577
> pid 8577's current affinity mask: 1
> hikey960:/sys/bus/coresight/devices # taskset -p 8577
> taskset: failed to get 8577's affinity: No such process
> 1|hikey960:/sys/bus/coresight/devices # cat ec036000.etf/mgmt/rwp
> 0x7b0
> hikey960:/sys/bus/coresight/devices # cat ec036000.etf/mgmt/rrp
> 0x7b0
> hikey960:/sys/bus/coresight/devices # dd if=/dev/ec036000.etf of=/data/cs.bin bs=1M
> 0+1 records in
> 0+1 records out
> 4096 bytes (4.0 K) copied, 0.001610 s, 2.4 M/s
> hikey960:/sys/bus/coresight/devices # exit
> root@intern-nzyj:/data/cstrace# adb pull /data/cs.bin
> /data/cs.bin: 1 file pulled. 0.1 MB/s (4096 bytes in 0.046s)
> root@intern-nzyj:/data/cstrace# /src/ptm2human/ptm2human -e -i cs.bin > cs.log_e

The ptm2human tools is for PTM tracers while your trancers are ETMv4,
as such you will never get anything sane out of it.  Also note that
CPUidle needs to be disabled if you want CS to work properly on the
HiKey960.  I am working on that problem.
I was actually under the impression that ptm2human can perform etm decoding by specifying the -e option.

I have extracted parts of the README in ptm2human's repo below:
-------
 ETMv4
-------
1. Save the ETMv4 trace stream into a file.
2. Give the trace file to ptm2human:
        $ ptm2human -e -i /path/to/trace/file
   The result is printed to the stdout. Redirect it to a output file:
        $ ptm2human -e -i /path/to/trace/file 1> /path/to/output/file
3. Read traces in a human-readable format:
        $ less output.log
        Reading TraceDataArmv8_dualcore.dat
        Decode trace stream of ID 0
        Syncing the trace stream...
        Decoding the trace stream...
        TraceInfo - Cycle count enabled,
                    Tracing of conditional non-branch instruction disabled,
                    No explicit tracing of load instructions,
                    No explicit tracing of store instructions,
                    p0_key = 0x0,
                    curr_spec_depth = 0,
                    cc_threshold = 0xFF
        TraceOn - A discontinuity in the trace stream
        Context - Context ID = 0x56AC1F3E,
                  VMID = 0x2E,
                  Exception level = EL2,
                  Security = NS,
                  64-bit instruction
        Address - Instruction address 0x0000000000400954, Instruction set Aarch64

Also, thanks for pointing out the options of disabling CPUidle.

> ```
>
> I don't try at my side, if have any question or issue, please report
> back so I can test on Hikey960.
>
> Thanks,
> Leo Yan
>
> Thank you very much for your kind responses and patience!
>
> The above message may contain confidential and/or proprietary information that is exempt from disclosure under applicable law and is intended for receipt and use solely by the addressee(s) named above. If you are not the intended recipient, you are hereby notified that any use, dissemination, distribution, or copying of this message, or any attachment, is strictly prohibited. If you have received this email in error, please inform the sender immediately by reply e-mail or telephone, reversing the charge if necessary. Please delete the message thereafter. Thank you.

Cheers,
Jeremy

The above message may contain confidential and/or proprietary information that is exempt from disclosure under applicable law and is intended for receipt and use solely by the addressee(s) named above. If you are not the intended recipient, you are hereby notified that any use, dissemination, distribution, or copying of this message, or any attachment, is strictly prohibited. If you have received this email in error, please inform the sender immediately by reply e-mail or telephone, reversing the charge if necessary. Please delete the message thereafter. Thank you.