You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by na...@apache.org on 2020/09/08 16:00:55 UTC

[mynewt-core] branch ProfileEncFlashWrites created (now 858518b)

This is an automated email from the ASF dual-hosted git repository.

naveenkaje pushed a change to branch ProfileEncFlashWrites
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


      at 858518b  Profile Enc Flash Writes

This branch includes the following new commits:

     new 858518b  Profile Enc Flash Writes

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[mynewt-core] 01/01: Profile Enc Flash Writes

Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

naveenkaje pushed a commit to branch ProfileEncFlashWrites
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 858518b6a2ce0a2208475caa11e5f5302bbca1aa
Author: Naveen Kaje <na...@juul.com>
AuthorDate: Wed Sep 2 06:48:48 2020 -0500

    Profile Enc Flash Writes
---
 .../crypto/crypto_da1469x/src/crypto_da1469x.c     |  8 +++++++
 hw/drivers/crypto/include/crypto/crypto.h          | 17 ++++++++++++++
 .../flash/enc_flash/ef_da1469x/src/hw_enc_flash.c  | 26 ++++++++++++++++++++++
 hw/drivers/flash/enc_flash/src/enc_flash.c         |  6 +++++
 hw/mcu/dialog/da1469x/src/hal_flash.c              |  9 +++++++-
 sys/config/src/config_store.c                      |  5 +++++
 sys/log/full/src/log.c                             |  7 ++++++
 7 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/hw/drivers/crypto/crypto_da1469x/src/crypto_da1469x.c b/hw/drivers/crypto/crypto_da1469x/src/crypto_da1469x.c
index f8d55b6..c64dcd5 100644
--- a/hw/drivers/crypto/crypto_da1469x/src/crypto_da1469x.c
+++ b/hw/drivers/crypto/crypto_da1469x/src/crypto_da1469x.c
@@ -26,6 +26,7 @@
 #include <mcu/da1469x_otp.h>
 #include <mcu/da1469x_dma.h>
 
+extern struct time_tracker g_tt;
 static struct os_mutex gmtx;
 
 #define VALID_AES_KEYLEN(x) (((x) == 128) || ((x) == 192) || ((x) == 256))
@@ -113,7 +114,9 @@ da1469x_crypto_op(struct crypto_dev *crypto, uint8_t op, uint16_t algo,
         memcpy(iv_save, &inbuf[len-AES_BLOCK_LEN], AES_BLOCK_LEN);
     }
 
+    g_tt.crypto_op_start = os_cputime_get32();
     os_mutex_pend(&gmtx, OS_TIMEOUT_NEVER);
+    g_tt.crypto_mutex_pend = os_cputime_get32();
     da1469x_clock_amba_enable(CRG_TOP_CLK_AMBA_REG_AES_CLK_ENABLE_Msk);
 
     /* enable AES / disable HASH */
@@ -185,7 +188,9 @@ da1469x_crypto_op(struct crypto_dev *crypto, uint8_t op, uint16_t algo,
     }
 
     if (OTP_ADDRESS_RANGE_USER_DATA_KEYS(key)) {
+        g_tt.crypto_dma_tx_begin = os_cputime_get32();
         do_dma_key_tx(key, keylen);
+        g_tt.crypto_dma_tx_end = os_cputime_get32();
     } else {
         keyreg = (uint32_t *)&AES_HASH->CRYPTO_KEYS_START;
         keyp32 = (uint32_t *)key;
@@ -226,6 +231,7 @@ da1469x_crypto_op(struct crypto_dev *crypto, uint8_t op, uint16_t algo,
     /* start encryption/decryption */
     AES_HASH->CRYPTO_START_REG |= AES_HASH_CRYPTO_START_REG_CRYPTO_START_Msk;
 
+    g_tt.crypto_wtf = os_cputime_get32();
     /*
      * Wait to finish.
      *
@@ -234,8 +240,10 @@ da1469x_crypto_op(struct crypto_dev *crypto, uint8_t op, uint16_t algo,
     while (!(AES_HASH->CRYPTO_STATUS_REG &
              AES_HASH_CRYPTO_STATUS_REG_CRYPTO_INACTIVE_Msk));
 
+    g_tt.crypto_wtf_done = os_cputime_get32();
     da1469x_clock_amba_disable(CRG_TOP_CLK_AMBA_REG_AES_CLK_ENABLE_Msk);
     os_mutex_release(&gmtx);
+    g_tt.crypto_mutex_rel = os_cputime_get32();
 
     /*
      * Update crypto framework internals
diff --git a/hw/drivers/crypto/include/crypto/crypto.h b/hw/drivers/crypto/include/crypto/crypto.h
index ad93a00..4fe1f08 100644
--- a/hw/drivers/crypto/include/crypto/crypto.h
+++ b/hw/drivers/crypto/include/crypto/crypto.h
@@ -99,6 +99,23 @@ struct crypto_iovec {
     size_t iov_len;
 };
 
+struct time_tracker {
+    uint32_t start;
+    uint32_t ef_sem_pend;
+    uint32_t co_done;
+    uint32_t end;
+
+    uint32_t crypto_op_start;
+    uint32_t crypto_mutex_pend;
+    uint32_t crypto_dma_tx_begin;
+    uint32_t crypto_dma_tx_end;
+    uint32_t crypto_wtf;
+    uint32_t crypto_wtf_done;
+    uint32_t crypto_mutex_rel;
+
+    bool hff_write;
+};
+
 /**
  * Encrypt a buffer using custom parameters
  *
diff --git a/hw/drivers/flash/enc_flash/ef_da1469x/src/hw_enc_flash.c b/hw/drivers/flash/enc_flash/ef_da1469x/src/hw_enc_flash.c
index 44a0c15..fc8bf60 100644
--- a/hw/drivers/flash/enc_flash/ef_da1469x/src/hw_enc_flash.c
+++ b/hw/drivers/flash/enc_flash/ef_da1469x/src/hw_enc_flash.c
@@ -29,10 +29,13 @@
 #include <mcu/da1469x_dma.h>
 #include <mcu/da1469x_otp.h>
 #include <crypto/crypto.h>
+#include "console/console.h"
 
 #define EDEV_TO_DA1469X(dev)   (struct eflash_da1469x_dev *)dev
 #define DA1469X_AES_KEYSIZE 256
 
+struct time_tracker g_tt;
+
 void
 enc_flash_crypt_arch(struct enc_flash_dev *edev, uint32_t blk_addr,
                      const uint8_t *src, uint8_t *tgt, int off, int cnt)
@@ -43,15 +46,38 @@ enc_flash_crypt_arch(struct enc_flash_dev *edev, uint32_t blk_addr,
     uint8_t blk[ENC_FLASH_BLK] = {0};
     const void *key = (void *)MCU_OTPM_BASE + OTP_SEGMENT_USER_DATA_KEYS +
                       (AES_MAX_KEY_LEN * (MYNEWT_VAL(USER_AES_SLOT)));
+    uint32_t diff;
+
+    g_tt.start = os_cputime_get32();
 
     ctr[0] = (uint32_t) ((blk_addr - h_dev->hf_base_addr) / ENC_FLASH_BLK);
 
     memcpy(blk + off, src, cnt);
     os_sem_pend(&dev->ef_sem, OS_TIMEOUT_NEVER);
+    g_tt.ef_sem_pend = os_cputime_get32();
     crypto_encrypt_aes_ctr(dev->ecd_crypto, key, DA1469X_AES_KEYSIZE, ctr,
                             blk, blk, AES_BLOCK_LEN);
+    g_tt.co_done = os_cputime_get32();
     os_sem_release(&dev->ef_sem);
+    g_tt.end = os_cputime_get32();
     memcpy(tgt, blk + off, cnt);
+    diff = g_tt.end - g_tt.start;
+    if (diff > 1000) {
+        console_printf("#enc: hff_write %d, cnt %d total %ld, efsp_s %ld, cod_efsp %ld, end_cod %ld\n\
+            cmp_cos %ld, cdtb_cmp %ld, cdte_cdtb %ld, cwtf_cdte %ld, cwtfd_cwtf %ld, cmr_ctd %ld\n",
+            g_tt.hff_write,
+            cnt,
+            diff,
+            g_tt.ef_sem_pend - g_tt.start,
+            g_tt.co_done - g_tt.ef_sem_pend,
+            g_tt.end - g_tt.co_done,
+            g_tt.crypto_mutex_pend - g_tt.crypto_op_start,
+            g_tt.crypto_dma_tx_begin - g_tt.crypto_mutex_pend,
+            g_tt.crypto_dma_tx_end - g_tt.crypto_dma_tx_begin,
+            g_tt.crypto_wtf - g_tt.crypto_dma_tx_end,
+            g_tt.crypto_wtf_done - g_tt.crypto_wtf,
+            g_tt.crypto_mutex_rel - g_tt.crypto_wtf_done);
+    }
 }
 
 /* Key is securely DMA transferred from OTP user data key slot */
diff --git a/hw/drivers/flash/enc_flash/src/enc_flash.c b/hw/drivers/flash/enc_flash/src/enc_flash.c
index d2ac9af..257187d 100644
--- a/hw/drivers/flash/enc_flash/src/enc_flash.c
+++ b/hw/drivers/flash/enc_flash/src/enc_flash.c
@@ -48,6 +48,8 @@ const struct hal_flash_funcs enc_flash_funcs = {
     .hff_init         = enc_flash_init,
 };
 
+extern int g_log_walk_ctr;
+extern int g_save_one_ctr;
 /*
  * Read first all the data in to provided memory area, then apply the
  * cipher -> text conversion.
@@ -64,6 +66,10 @@ enc_flash_read(const struct hal_flash *h_dev, uint32_t addr, void *buf,
 
     h_dev = dev->efd_hwdev;
 
+    if (g_log_walk_ctr > 0)
+        g_log_walk_ctr++;
+    if(g_save_one_ctr > 0)
+        g_save_one_ctr++;
     rc = h_dev->hf_itf->hff_read(h_dev, addr, buf, len);
     if (rc) {
         return rc;
diff --git a/hw/mcu/dialog/da1469x/src/hal_flash.c b/hw/mcu/dialog/da1469x/src/hal_flash.c
index 5d19908..3045687 100644
--- a/hw/mcu/dialog/da1469x/src/hal_flash.c
+++ b/hw/mcu/dialog/da1469x/src/hal_flash.c
@@ -25,7 +25,9 @@
 #include "hal/hal_flash_int.h"
 #include "mcu/mcu.h"
 #include <stdbool.h>
+#include "crypto/crypto.h"
 
+extern struct time_tracker g_tt;
 #define CODE_QSPI_INLINE    __attribute__((always_inline)) inline
 
 union da1469x_qspi_data_reg {
@@ -346,12 +348,16 @@ da1469x_hff_write(const struct hal_flash *dev, uint32_t address,
 {
     uint8_t buf[ MYNEWT_VAL(QSPI_FLASH_READ_BUFFER_SIZE) ];
     uint32_t chunk_len;
+    int ret;
 
+    g_tt.hff_write = true;
     /* We can write directly if 'src' is outside flash memory, otherwise we
      * need to read data to RAM first and then write to flash.
      */
     if (da1469x_hff_in_flash_addr_space(src) == false) {
-        return da1469x_qspi_write(dev, address, src, num_bytes);
+        ret = da1469x_qspi_write(dev, address, src, num_bytes);
+        g_tt.hff_write = false;
+        return ret;
     }
 
     while (num_bytes) {
@@ -373,6 +379,7 @@ da1469x_hff_write(const struct hal_flash *dev, uint32_t address,
         num_bytes -= chunk_len;
     }
 
+    g_tt.hff_write = false;
     return 0;
 }
 
diff --git a/sys/config/src/config_store.c b/sys/config/src/config_store.c
index 07b94d7..d488d90 100644
--- a/sys/config/src/config_store.c
+++ b/sys/config/src/config_store.c
@@ -24,6 +24,7 @@
 #include "config/config.h"
 #include "config/config_store.h"
 #include "config_priv.h"
+#include "console/console.h"
 
 struct conf_dup_check_arg {
     const char *name;
@@ -212,6 +213,7 @@ conf_dup_check_cb(char *name, char *val, void *cb_arg)
 /*
  * Append a single value to persisted config. Don't store duplicate value.
  */
+int g_save_one_ctr;
 int
 conf_save_one(const char *name, char *value)
 {
@@ -239,7 +241,10 @@ conf_save_one(const char *name, char *value)
         goto out;
     }
     cs = conf_save_dst;
+    g_save_one_ctr = 1;
     rc = cs->cs_itf->csi_save(cs, name, value);
+    console_printf("g_save_one_ctr %d\n", g_save_one_ctr);
+    g_save_one_ctr = 0;
 out:
     conf_unlock();
     return rc;
diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c
index 473618e..3b77d2b 100644
--- a/sys/log/full/src/log.c
+++ b/sys/log/full/src/log.c
@@ -37,6 +37,8 @@
 #include "shell/shell.h"
 #endif
 
+#include "console/console.h"
+
 struct log_module_entry {
     int16_t id;
     const char *name;
@@ -893,6 +895,8 @@ log_walk_body_fn(struct log *log, struct log_offset *log_offset, const void *dpt
     return 0;
 }
 
+int g_log_walk_ctr;
+
 int
 log_walk_body(struct log *log, log_walk_body_func_t walk_body_func,
               struct log_offset *log_offset)
@@ -904,7 +908,10 @@ log_walk_body(struct log *log, log_walk_body_func_t walk_body_func,
     int rc;
 
     log_offset->lo_arg = &lwba;
+    g_log_walk_ctr = 1;
     rc = log->l_log->log_walk(log, log_walk_body_fn, log_offset);
+    console_printf("g_log_walk_ctr %d\n", g_log_walk_ctr);
+    g_log_walk_ctr = 0;
     log_offset->lo_arg = lwba.arg;
 
     return rc;