Skip to content

Commit

Permalink
system/ramspeed: Add system interrupt switch.
Browse files Browse the repository at this point in the history
  • Loading branch information
crafcat7 authored and pkarashchenko committed Oct 3, 2022
1 parent 0e0ac06 commit 744ecf2
Showing 1 changed file with 49 additions and 18 deletions.
67 changes: 49 additions & 18 deletions system/ramspeed/ramspeed_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
****************************************************************************/

#include <nuttx/config.h>
#include <nuttx/irq.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
Expand Down Expand Up @@ -74,6 +75,7 @@ struct ramspeed_s
size_t size;
uint8_t value;
uint32_t repeat_num;
bool irq_disable;
};

/****************************************************************************
Expand All @@ -91,7 +93,7 @@ struct ramspeed_s
static void show_usage(FAR const char *progname, int exitcode)
{
printf("\nUsage: %s -r <hex-address> -w <hex-address> -s <decimal-size>"
" -v <hex-value>[0x00] -n <decimal-repeat number>[100]\n",
" -v <hex-value>[0x00] -n <decimal-repeat number>[100] -i\n",
progname);
printf("\nWhere:\n");
printf(" -r <hex-address> read address.\n");
Expand All @@ -101,6 +103,8 @@ static void show_usage(FAR const char *progname, int exitcode)
" [default value: 0x00].\n");
printf(" -n <decimal-repeat num> number of repetitions"
" [default value: 100].\n");
printf(" -i turn off interrupts while testing"
" [default value: false].\n");
exit(exitcode);
}

Expand All @@ -122,7 +126,7 @@ static void parse_commandline(int argc, FAR char **argv,
show_usage(argv[0], EXIT_FAILURE);
}

while ((ch = getopt(argc, argv, "r:w:s:v:n:")) != ERROR)
while ((ch = getopt(argc, argv, "r:w:s:v:n:i")) != ERROR)
{
switch (ch)
{
Expand All @@ -145,6 +149,9 @@ static void parse_commandline(int argc, FAR char **argv,
printf(RAMSPEED_PREFIX "<repeat number> must > 0\n");
exit(EXIT_FAILURE);
}

case 'i':
info->irq_disable = true;
break;
case '?':
printf(RAMSPEED_PREFIX "Unknown option: %c\n", (char)optopt);
Expand Down Expand Up @@ -346,12 +353,20 @@ static void print_rate(FAR const char *name, size_t bytes,
****************************************************************************/

static void memcpy_speed_test(FAR void *dest, FAR const void *src,
size_t size, uint32_t repeat_cnt)
size_t size, uint32_t repeat_cnt,
bool irq_disable)
{
uint32_t start_time;
uint32_t cost_time;
uint32_t cost_time_system;
uint32_t cost_time_internal;
uint32_t cnt;
const size_t total_size = size * repeat_cnt;
irqstate_t flags;

if (irq_disable)
{
flags = enter_critical_section();
}

start_time = get_timestamp();

Expand All @@ -360,9 +375,7 @@ static void memcpy_speed_test(FAR void *dest, FAR const void *src,
memcpy(dest, src, size);
}

cost_time = get_time_elaps(start_time);

print_rate("system memcpy():\t", total_size, cost_time);
cost_time_system = get_time_elaps(start_time);

start_time = get_timestamp();

Expand All @@ -371,22 +384,36 @@ static void memcpy_speed_test(FAR void *dest, FAR const void *src,
internal_memcpy(dest, src, size);
}

cost_time = get_time_elaps(start_time);
cost_time_internal = get_time_elaps(start_time);

if (irq_disable)
{
leave_critical_section(flags);
}

print_rate("internal memcpy():\t", total_size, cost_time);
print_rate("system memcpy():\t", total_size, cost_time_system);
print_rate("internal memcpy():\t", total_size, cost_time_internal);
}

/****************************************************************************
* Name: memset_speed_test
****************************************************************************/

static void memset_speed_test(FAR void *dest, uint8_t value,
size_t size, uint32_t repeat_num)
size_t size, uint32_t repeat_num,
bool irq_disable)
{
uint32_t start_time;
uint32_t cost_time;
uint32_t cost_time_system;
uint32_t cost_time_internal;
uint32_t cnt;
const size_t total_size = size * repeat_num;
irqstate_t flags;

if (irq_disable)
{
flags = enter_critical_section();
}

start_time = get_timestamp();

Expand All @@ -395,9 +422,7 @@ static void memset_speed_test(FAR void *dest, uint8_t value,
memset(dest, value, size);
}

cost_time = get_time_elaps(start_time);

print_rate("system memset():\t", total_size, cost_time);
cost_time_system = get_time_elaps(start_time);

start_time = get_timestamp();

Expand All @@ -406,9 +431,15 @@ static void memset_speed_test(FAR void *dest, uint8_t value,
internal_memset(dest, value, size);
}

cost_time = get_time_elaps(start_time);
cost_time_internal = get_time_elaps(start_time);

if (irq_disable)
{
leave_critical_section(flags);
}

print_rate("internal memset():\t", total_size, cost_time);
print_rate("system memset():\t", total_size, cost_time_system);
print_rate("internal memset():\t", total_size, cost_time_internal);
}

/****************************************************************************
Expand All @@ -426,10 +457,10 @@ int main(int argc, FAR char *argv[])
parse_commandline(argc, argv, &ramspeed);

memcpy_speed_test(ramspeed.dest, ramspeed.src,
ramspeed.size, ramspeed.repeat_num);
ramspeed.size, ramspeed.repeat_num, ramspeed.irq_disable);

memset_speed_test(ramspeed.dest, ramspeed.value,
ramspeed.size, ramspeed.repeat_num);
ramspeed.size, ramspeed.repeat_num, ramspeed.irq_disable);

return EXIT_SUCCESS;
}

0 comments on commit 744ecf2

Please sign in to comment.