[GitHub] kasjer commented on a change in pull request #1324: Flash speed test

2018-08-10 Thread GitBox
kasjer commented on a change in pull request #1324: Flash speed test
URL: https://github.com/apache/mynewt-core/pull/1324#discussion_r209274407
 
 

 ##
 File path: test/flash_test/src/flash_test/flash_test.c
 ##
 @@ -127,31 +145,158 @@ flash_cli_cmd(int argc, char **argv)
 
 while (off < sz) {
 sec_cnt = min(sizeof(tmp_buf), sz - off);
-if (hal_flash_write(0, off, tmp_buf, sec_cnt)) {
+if (hal_flash_write(fid, off, tmp_buf, sec_cnt)) {
 console_printf("flash write failure at %lx\n",
 (long unsigned int) off);
 }
 off += sec_cnt;
 }
 console_printf("Done!\n");
-} else if ( !strcmp(argv[1], "?") || !strcmp(argv[1], "help"))
-{
+} else if ( !strcmp(argv[1], "?") || !strcmp(argv[1], "help")) {
 console_printf("Commands Available\n");
-console_printf("flash -- dumps sector map \n");
-console_printf("flash read   -- reads bytes from flash 
\n");
-console_printf("flash write -- writes incrementing 
data pattern 0-8 to flash \n");
-console_printf("flash erase   -- erases flash \n");
+console_printf("flash -- dumps sector map\n");
+console_printf("flash read   [flash dev idx] -- "
+   "read bytes from flash\n");
+console_printf("flash write[flash dev idx] -- "
+   "write incrementing data pattern 0-8 to flash\n");
+console_printf("flash erase   [flash dev idx] -- "
+   "erase flash\n");
 }
 return 0;
 err:
 return -1;
 }
 
+
+/*
+ * Returns # of ops done within 2 seconds.
+ */
+int
+flash_speed_test(int flash_dev, uint32_t addr, int sz, int move)
+{
+int rc;
+int cnt = 0;
+int off = 0;
+int start_time;
+int end_time;
+void *data_buf;
+
+data_buf = malloc(sz);
 
 Review comment:
   It's not checked for NULL, since it is not clear from help what is used for 
I had crash


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] kasjer commented on a change in pull request #1324: Flash speed test

2018-08-10 Thread GitBox
kasjer commented on a change in pull request #1324: Flash speed test
URL: https://github.com/apache/mynewt-core/pull/1324#discussion_r209276045
 
 

 ##
 File path: test/flash_test/src/flash_test/flash_test.c
 ##
 @@ -127,31 +145,158 @@ flash_cli_cmd(int argc, char **argv)
 
 while (off < sz) {
 sec_cnt = min(sizeof(tmp_buf), sz - off);
-if (hal_flash_write(0, off, tmp_buf, sec_cnt)) {
+if (hal_flash_write(fid, off, tmp_buf, sec_cnt)) {
 console_printf("flash write failure at %lx\n",
 (long unsigned int) off);
 }
 off += sec_cnt;
 }
 console_printf("Done!\n");
-} else if ( !strcmp(argv[1], "?") || !strcmp(argv[1], "help"))
-{
+} else if ( !strcmp(argv[1], "?") || !strcmp(argv[1], "help")) {
 console_printf("Commands Available\n");
-console_printf("flash -- dumps sector map \n");
-console_printf("flash read   -- reads bytes from flash 
\n");
-console_printf("flash write -- writes incrementing 
data pattern 0-8 to flash \n");
-console_printf("flash erase   -- erases flash \n");
+console_printf("flash -- dumps sector map\n");
+console_printf("flash read   [flash dev idx] -- "
+   "read bytes from flash\n");
+console_printf("flash write[flash dev idx] -- "
+   "write incrementing data pattern 0-8 to flash\n");
+console_printf("flash erase   [flash dev idx] -- "
+   "erase flash\n");
 }
 return 0;
 err:
 return -1;
 }
 
+
+/*
+ * Returns # of ops done within 2 seconds.
+ */
+int
+flash_speed_test(int flash_dev, uint32_t addr, int sz, int move)
+{
+int rc;
+int cnt = 0;
+int off = 0;
+int start_time;
+int end_time;
+void *data_buf;
+
+data_buf = malloc(sz);
+
+/*
+ * Catch start of a tick.
+ */
+start_time = os_time_get();
+while (1) {
+end_time = os_time_get();
+if (end_time != start_time) {
+start_time = end_time;
+break;
+}
+}
+
+/*
+ * Measure for 2 secs.
+ */
+do {
+rc = hal_flash_read(flash_dev, addr + off, data_buf, sz);
+if (rc) {
+console_printf("hal_flash_read(%d, 0x%x, %d) = %d\n",
+  flash_dev, (unsigned int)addr + off, (unsigned int)sz, rc);
+return -1;
+}
+assert(rc == 0);
+if (move) {
+off++;
+if (off > 16) {
+off = 0;
+}
+}
+end_time = os_time_get();
+cnt++;
+} while (end_time - start_time < 2 * OS_TICKS_PER_SEC);
+
+free(data_buf);
+return cnt;
+}
+
+static int
+flash_speed_test_cli(int argc, char **argv)
+{
+char *ep;
+int flash_dev;
+uint32_t addr;
+uint32_t sz;
+int move;
+int cnt;
+int i;
+
+if (argc < 4) {
+console_printf("flash_speed[move]\n");
 
 Review comment:
   5th argument is not mentioned


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] kasjer commented on a change in pull request #1324: Flash speed test

2018-08-10 Thread GitBox
kasjer commented on a change in pull request #1324: Flash speed test
URL: https://github.com/apache/mynewt-core/pull/1324#discussion_r209275620
 
 

 ##
 File path: test/flash_test/src/flash_test/flash_test.c
 ##
 @@ -127,31 +145,158 @@ flash_cli_cmd(int argc, char **argv)
 
 while (off < sz) {
 sec_cnt = min(sizeof(tmp_buf), sz - off);
-if (hal_flash_write(0, off, tmp_buf, sec_cnt)) {
+if (hal_flash_write(fid, off, tmp_buf, sec_cnt)) {
 console_printf("flash write failure at %lx\n",
 (long unsigned int) off);
 }
 off += sec_cnt;
 }
 console_printf("Done!\n");
-} else if ( !strcmp(argv[1], "?") || !strcmp(argv[1], "help"))
-{
+} else if ( !strcmp(argv[1], "?") || !strcmp(argv[1], "help")) {
 console_printf("Commands Available\n");
-console_printf("flash -- dumps sector map \n");
-console_printf("flash read   -- reads bytes from flash 
\n");
-console_printf("flash write -- writes incrementing 
data pattern 0-8 to flash \n");
-console_printf("flash erase   -- erases flash \n");
+console_printf("flash -- dumps sector map\n");
+console_printf("flash read   [flash dev idx] -- "
+   "read bytes from flash\n");
+console_printf("flash write[flash dev idx] -- "
+   "write incrementing data pattern 0-8 to flash\n");
+console_printf("flash erase   [flash dev idx] -- "
+   "erase flash\n");
 }
 return 0;
 err:
 return -1;
 }
 
+
+/*
+ * Returns # of ops done within 2 seconds.
+ */
+int
+flash_speed_test(int flash_dev, uint32_t addr, int sz, int move)
+{
+int rc;
+int cnt = 0;
+int off = 0;
+int start_time;
+int end_time;
+void *data_buf;
+
+data_buf = malloc(sz);
+
+/*
+ * Catch start of a tick.
+ */
+start_time = os_time_get();
+while (1) {
+end_time = os_time_get();
+if (end_time != start_time) {
+start_time = end_time;
+break;
+}
+}
+
+/*
+ * Measure for 2 secs.
+ */
+do {
+rc = hal_flash_read(flash_dev, addr + off, data_buf, sz);
+if (rc) {
+console_printf("hal_flash_read(%d, 0x%x, %d) = %d\n",
+  flash_dev, (unsigned int)addr + off, (unsigned int)sz, rc);
+return -1;
+}
+assert(rc == 0);
+if (move) {
+off++;
+if (off > 16) {
+off = 0;
+}
+}
+end_time = os_time_get();
+cnt++;
+} while (end_time - start_time < 2 * OS_TICKS_PER_SEC);
+
+free(data_buf);
+return cnt;
+}
+
+static int
+flash_speed_test_cli(int argc, char **argv)
+{
+char *ep;
+int flash_dev;
+uint32_t addr;
+uint32_t sz;
+int move;
+int cnt;
+int i;
+
+if (argc < 4) {
+console_printf("flash_speed[move]\n");
+return 0;
+}
+
+flash_dev = strtoul(argv[1], , 10);
+if (*ep != '\0') {
+console_printf("Invalid flash_id: %s\n", argv[1]);
+return 0;
+}
+
+addr = strtoul(argv[2], , 0);
+if (*ep != '\0') {
+console_printf("Invalid address: %s\n", argv[2]);
+return 0;
+}
+
+sz = strtoul(argv[3], , 0);
+if (*ep != '\0') {
+console_printf("Invalid read size: %s\n", argv[3]);
+return 0;
+}
+if (argc > 4 && !strcmp(argv[4], "move")) {
+move = 1;
+} else {
+move = 0;
+}
+if (argc > 5) {
+i = 1;
+} else {
+i = 0;
+}
+
+if (i == 0) {
+console_printf("Speed test, hal_flash_read(%d, 0x%x%s, %d)\n",
+  flash_dev, (unsigned int)addr, move?"..":"", (unsigned int)sz);
+cnt = flash_speed_test(flash_dev, addr, sz, move);
+console_printf("%d\n", cnt);
+} else {
+uint32_t sizes[] = {
+1, 2, 4, 8, 16, 24, 32, 48, 64, 96, 128, 192, 256
+};
+
+console_printf("Speed test, hal_flash_read(%d, 0x%x%s, X)\n",
+  flash_dev, (unsigned int)addr, move?"..":"");
+
+for (i = 0; i < sizeof(sizes) / sizeof(sizes[0]); i++) {
+cnt = flash_speed_test(flash_dev, addr, sizes[i], move);
+console_printf("%3d %d\n", (int)sizes[i], cnt >> 1);
 
 Review comment:
   it's not clear what was measured


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services