perf.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (c) 2009 Openmoko Inc.
  3. *
  4. * Authors Marek Lindner
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of version 2 of the GNU General Public
  8. * License as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA
  19. *
  20. */
  21. #include <perf.h>
  22. #include <profile.h>
  23. #include <string.h>
  24. #include <diskio.h>
  25. #include <file-io.h>
  26. #include <regs.h>
  27. #include <samo.h>
  28. #include <stdlib.h>
  29. #include <malloc-simple.h>
  30. #include <msg.h>
  31. #define MB 1024 * 1024
  32. #define KB 1024
  33. void perf_test(void)
  34. {
  35. char *mem_src = NULL, *mem_dst = NULL, *file = NULL;
  36. int fd = -1, read;
  37. unsigned int file_size;
  38. mem_src = malloc_simple(MB, MEM_TAG_PERF_M1);
  39. if (!mem_src) {
  40. msg(MSG_INFO, "no mem_src: out of mem ?\n");
  41. malloc_status_simple();
  42. goto out;
  43. }
  44. mem_dst = malloc_simple(MB, MEM_TAG_PERF_M2);
  45. if (!mem_dst) {
  46. msg(MSG_INFO, "no mem_dst: out of mem ?\n");
  47. malloc_status_simple();
  48. goto out;
  49. }
  50. file = malloc_simple(MB, MEM_TAG_PERF_M3);
  51. if (!file) {
  52. msg(MSG_INFO, "no file: out of mem ?\n");
  53. malloc_status_simple();
  54. goto out;
  55. }
  56. prof_start(PROF_memset);
  57. memset(mem_src, 1, MB);
  58. prof_stop(PROF_memset);
  59. prof_start(PROF_memcpy);
  60. memcpy(mem_dst, mem_src, MB);
  61. prof_stop(PROF_memcpy);
  62. prof_start(PROF_memcmp);
  63. memcmp(mem_src, mem_dst, MB);
  64. prof_stop(PROF_memcmp);
  65. prof_start(PROF_sd_read);
  66. for (fd = 0; fd < 8; fd++) {
  67. read = disk_read(0, file + (fd * 512 * 256), fd * 255, 255);
  68. if (read != RES_OK) {
  69. prof_stop(PROF_sd_read);
  70. msg(MSG_INFO, "Could not read sd card: %i\n", read);
  71. goto out;
  72. }
  73. }
  74. prof_stop(PROF_sd_read);
  75. fd = wl_open("8dcec2", WL_O_RDONLY);
  76. if (fd < 0) {
  77. msg(MSG_INFO, "Could not read file '8dcec2': file not found\n");
  78. goto out;
  79. }
  80. wl_fsize(fd, &file_size);
  81. if (file_size > MB) {
  82. msg(MSG_INFO, "Could not read file '8dcec2': file size bigger than %i bytes\n", MB);
  83. goto out;
  84. }
  85. prof_start(PROF_fread);
  86. read = wl_read(fd, file, file_size);
  87. prof_stop(PROF_fread);
  88. if (read != file_size) {
  89. msg(MSG_INFO, "Could not read file '8dcec2': read process aborted after %i bytes\n", read);
  90. goto out;
  91. }
  92. msg(MSG_INFO, "memcpy speed: 1MB/%dms, SD card: 1MB/%dms, fatfs: 1MB/%dms\n",
  93. (prof_container[PROF_memcpy].calls == 0 ? 0 :
  94. ((prof_container[PROF_memcpy].total_time / MCLK_MHz) / prof_container[PROF_memcpy].calls / 1000)),
  95. (prof_container[PROF_sd_read].calls == 0 ? 0 :
  96. ((prof_container[PROF_sd_read].total_time / MCLK_MHz) / prof_container[PROF_sd_read].calls / 1000)),
  97. (prof_container[PROF_fread].calls == 0 ? 0 :
  98. ((prof_container[PROF_fread].total_time / MCLK_MHz) / prof_container[PROF_fread].calls / (file_size / 100 / KB) / 100)));
  99. out:
  100. if (fd)
  101. wl_close(fd);
  102. if (file)
  103. free_simple(file, MEM_TAG_PERF_F3);
  104. if (mem_dst)
  105. free_simple(mem_dst, MEM_TAG_PERF_F4);
  106. if (mem_src)
  107. free_simple(mem_src, MEM_TAG_PERF_F5);
  108. return;
  109. }