hla_target: allow non-intrusive profiling on cortex-m 20/4220/3
authorKarl Palsson <karlp@tweak.net.au>
Fri, 8 Sep 2017 10:49:30 +0000 (10:49 +0000)
committerPaul Fertser <fercerpav@gmail.com>
Sat, 13 Jan 2018 09:31:36 +0000 (09:31 +0000)
Leverages the existing work that added profiling via DWT_PCSR.

hla_target doesn't have direct access to the mem_ap for doing a bulk
repeated read, but simply reading the DWT_PCSR register repeatedly is
still ~2 order of magnitude faster than halt/resume.

Change-Id: Ibe451aa95143694398370fdad6939cfb6191d56f
Signed-off-by: Karl Palsson <karlp@tweak.net.au>
Reviewed-on: http://openocd.zylin.com/4220
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
src/target/cortex_m.c
src/target/cortex_m.h
src/target/hla_target.c

index 988323b042132592169aa7723a775f1cf44e58ce..24063a7e6af06dc49bbf083cb0c72a6f05226dcc 100644 (file)
@@ -1707,7 +1707,7 @@ void cortex_m_deinit_target(struct target *target)
        free(cortex_m);
 }
 
        free(cortex_m);
 }
 
-static int cortex_m_profiling(struct target *target, uint32_t *samples,
+int cortex_m_profiling(struct target *target, uint32_t *samples,
                              uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds)
 {
        struct timeval timeout, now;
                              uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds)
 {
        struct timeval timeout, now;
@@ -1749,13 +1749,18 @@ static int cortex_m_profiling(struct target *target, uint32_t *samples,
 
        for (;;) {
                if (use_pcsr) {
 
        for (;;) {
                if (use_pcsr) {
-                       uint32_t read_count = max_num_samples - sample_count;
-                       if (read_count > 1024)
-                               read_count = 1024;
-                       retval = mem_ap_read_buf_noincr(armv7m->debug_ap,
+                       if (armv7m && armv7m->debug_ap) {
+                               uint32_t read_count = max_num_samples - sample_count;
+                               if (read_count > 1024)
+                                       read_count = 1024;
+
+                               retval = mem_ap_read_buf_noincr(armv7m->debug_ap,
                                                        (void *)&samples[sample_count],
                                                        4, read_count, DWT_PCSR);
                                                        (void *)&samples[sample_count],
                                                        4, read_count, DWT_PCSR);
-                       sample_count += read_count;
+                               sample_count += read_count;
+                       } else {
+                               target_read_u32(target, DWT_PCSR, &samples[sample_count++]);
+                       }
                } else {
                        target_poll(target);
                        if (target->state == TARGET_HALTED) {
                } else {
                        target_poll(target);
                        if (target->state == TARGET_HALTED) {
index dbf9ac8a7f00f707b1a0c46332208cc3d35eb307..9500acc1d7d6363035bba13e078950dc3c02581a 100644 (file)
@@ -213,5 +213,7 @@ void cortex_m_enable_breakpoints(struct target *target);
 void cortex_m_enable_watchpoints(struct target *target);
 void cortex_m_dwt_setup(struct cortex_m_common *cm, struct target *target);
 void cortex_m_deinit_target(struct target *target);
 void cortex_m_enable_watchpoints(struct target *target);
 void cortex_m_dwt_setup(struct cortex_m_common *cm, struct target *target);
 void cortex_m_deinit_target(struct target *target);
+int cortex_m_profiling(struct target *target, uint32_t *samples,
+       uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds);
 
 #endif /* OPENOCD_TARGET_CORTEX_M_H */
 
 #endif /* OPENOCD_TARGET_CORTEX_M_H */
index 78dc8c5128228ef12e22c5636eeb80ae28f3d62a..a3e683597bc0126e886783819931ad751ac84ca2 100644 (file)
@@ -814,4 +814,5 @@ struct target_type hla_target = {
        .remove_breakpoint = cortex_m_remove_breakpoint,
        .add_watchpoint = cortex_m_add_watchpoint,
        .remove_watchpoint = cortex_m_remove_watchpoint,
        .remove_breakpoint = cortex_m_remove_breakpoint,
        .add_watchpoint = cortex_m_add_watchpoint,
        .remove_watchpoint = cortex_m_remove_watchpoint,
+       .profiling = cortex_m_profiling,
 };
 };

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)