mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-18 20:57:56 +00:00
add context switching speed test to "test memory" command.
This commit is contained in:
parent
6ff2ae4871
commit
31b314d2da
@ -2484,12 +2484,17 @@ int app_reverse_lookup(const struct cli_parsed *parsed, struct cli_context *cont
|
||||
return 1;
|
||||
}
|
||||
|
||||
int context_switch_test(int);
|
||||
int app_mem_test(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
{
|
||||
int mem_size;
|
||||
int addr;
|
||||
uint64_t count;
|
||||
|
||||
|
||||
// First test context switch speed
|
||||
context_switch_test(1);
|
||||
|
||||
for(mem_size=1024;mem_size<=(128*1024*1024);mem_size*=2) {
|
||||
uint8_t *mem=malloc(mem_size);
|
||||
if (!mem) {
|
||||
@ -2525,6 +2530,7 @@ int app_mem_test(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
|
||||
free(mem);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
103
context1.c
Normal file
103
context1.c
Normal file
@ -0,0 +1,103 @@
|
||||
|
||||
/*******************************************************************************
|
||||
* The BYTE UNIX Benchmarks - Release 3
|
||||
* Module: context1.c SID: 3.3 5/15/91 19:30:18
|
||||
*
|
||||
*******************************************************************************
|
||||
* Bug reports, patches, comments, suggestions should be sent to:
|
||||
*
|
||||
* Ben Smith, Rick Grehan or Tom Yager
|
||||
* ben@bytepb.byte.com rick_g@bytepb.byte.com tyager@bytepb.byte.com
|
||||
*
|
||||
*******************************************************************************
|
||||
* Modification Log:
|
||||
* $Header: context1.c,v 3.4 87/06/22 14:22:59 kjmcdonell Beta $
|
||||
* August 28, 1990 - changed timing routines--now returns total number of
|
||||
* iterations in specified time period
|
||||
* October 22, 1997 - code cleanup to remove ANSI C compiler warnings
|
||||
* Andy Kahn <kahn@zk3.dec.com>
|
||||
*
|
||||
******************************************************************************/
|
||||
char SCCSid[] = "@(#) @(#)context1.c:3.3 -- 5/15/91 19:30:18";
|
||||
/*
|
||||
* Context switching via synchronized unbuffered pipe i/o
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include "timeit.c"
|
||||
|
||||
unsigned long iter;
|
||||
int stop_timing=0;
|
||||
|
||||
void report()
|
||||
{
|
||||
fprintf(stderr, "%lu context switches per second.\n", iter);
|
||||
stop_timing=1;
|
||||
}
|
||||
|
||||
int context_switch_test(int duration)
|
||||
{
|
||||
unsigned long check;
|
||||
int p1[2], p2[2];
|
||||
|
||||
|
||||
/* set up alarm call */
|
||||
iter = 0;
|
||||
wake_me(duration, report);
|
||||
|
||||
if (pipe(p1) || pipe(p2)) {
|
||||
perror("pipe create failed");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (fork()) { /* parent process */
|
||||
/* master, write p1 & read p2 */
|
||||
close(p1[0]); close(p2[1]);
|
||||
while (!stop_timing) {
|
||||
if (write(p1[1], (char *)&iter, sizeof(iter)) != sizeof(iter)) {
|
||||
if ((errno != 0) && (errno != EINTR))
|
||||
perror("master write failed");
|
||||
exit(1);
|
||||
}
|
||||
if (read(p2[0], (char *)&check, sizeof(check)) != sizeof(check)) {
|
||||
if ((errno != 0) && (errno != EINTR))
|
||||
perror("master read failed");
|
||||
exit(1);
|
||||
}
|
||||
if (check != iter) {
|
||||
fprintf(stderr, "Master sync error: expect %lu, got %lu\n",
|
||||
iter, check);
|
||||
exit(2);
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
else { /* child process */
|
||||
unsigned long iter1;
|
||||
|
||||
iter1 = 0;
|
||||
/* slave, read p1 & write p2 */
|
||||
close(p1[1]); close(p2[0]);
|
||||
while (!stop_timing) {
|
||||
if (read(p1[0], (char *)&check, sizeof(check)) != sizeof(check)) {
|
||||
if ((errno != 0) && (errno != EINTR))
|
||||
perror("slave read failed");
|
||||
exit(1);
|
||||
}
|
||||
if (check != iter1) {
|
||||
fprintf(stderr, "Slave sync error: expect %lu, got %lu\n",
|
||||
iter, check);
|
||||
exit(2);
|
||||
}
|
||||
if (write(p2[1], (char *)&iter1, sizeof(iter1)) != sizeof(check)) {
|
||||
if ((errno != 0) && (errno != EINTR))
|
||||
perror("slave write failed");
|
||||
exit(1);
|
||||
}
|
||||
iter1++;
|
||||
}
|
||||
}
|
||||
}
|
@ -74,4 +74,5 @@ SERVAL_SOURCES = \
|
||||
$(SERVAL_BASE)fec-3.0.1/ccsds_tables.c \
|
||||
$(SERVAL_BASE)fec-3.0.1/decode_rs_8.c \
|
||||
$(SERVAL_BASE)fec-3.0.1/encode_rs_8.c \
|
||||
$(SERVAL_BASE)fec-3.0.1/init_rs_char.c
|
||||
$(SERVAL_BASE)fec-3.0.1/init_rs_char.c \
|
||||
$(SERVAL_BASE)context1.c
|
||||
|
41
timeit.c
Normal file
41
timeit.c
Normal file
@ -0,0 +1,41 @@
|
||||
/*******************************************************************************
|
||||
*
|
||||
* The BYTE UNIX Benchmarks - Release 3
|
||||
* Module: timeit.c SID: 3.3 5/15/91 19:30:21
|
||||
*******************************************************************************
|
||||
* Bug reports, patches, comments, suggestions should be sent to:
|
||||
*
|
||||
* Ben Smith, Rick Grehan or Tom Yager
|
||||
* ben@bytepb.byte.com rick_g@bytepb.byte.com tyager@bytepb.byte.com
|
||||
*
|
||||
*******************************************************************************
|
||||
* Modification Log:
|
||||
* May 12, 1989 - modified empty loops to avoid nullifying by optimizing
|
||||
* compilers
|
||||
* August 28, 1990 - changed timing relationship--now returns total number
|
||||
* of iterations (ty)
|
||||
* October 22, 1997 - code cleanup to remove ANSI C compiler warnings
|
||||
* Andy Kahn <kahn@zk3.dec.com>
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* this module is #included in other modules--no separate SCCS ID */
|
||||
|
||||
/*
|
||||
* Timing routine
|
||||
*
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void wake_me(seconds, func)
|
||||
int seconds;
|
||||
void (*func)();
|
||||
{
|
||||
/* set up the signal handler */
|
||||
signal(SIGALRM, func);
|
||||
/* get the clock running */
|
||||
alarm(seconds);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user