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
```

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.