Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
tsn-measures
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
tsn-measures
Commits
7dff3f4b
Commit
7dff3f4b
authored
Apr 23, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start latency measuring module
parent
d738089c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
166 additions
and
0 deletions
+166
-0
latency-measure/build/Makefile
latency-measure/build/Makefile
+40
-0
latency-measure/src/main.c
latency-measure/src/main.c
+126
-0
No files found.
latency-measure/build/Makefile
0 → 100644
View file @
7dff3f4b
ARM_CC
=
arm-linux-gnueabihf-gcc
ARM_PROG
=
main_arm
PROG
=
main
SRCDIR
=
../src
SRCS
=
main.c
SRCS
+=
getip.c
SRCS
+=
send_packet.c
OBJS
=
$(SRCS:%.c=%.o)
CFLAGS
=
-Og
-g
-Wall
-Werror
-Wextra
CFLAGS
+=
-MD
-MP
CFLAGS
+=
-I
$(SRCDIR)
CFLAGS
+=
-std
=
gnu99
LDFLAGS
=
-pthread
vpath
%.c
$(SRCDIR)
$(ARM_PROG)
:
FORCE
make clean
make
-e
CC:
=
arm-linux-gnueabihf-gcc
$(PROG)
mv
$(PROG)
$(ARM_PROG)
FORCE
:
$(PROG)
:
$(OBJS)
$(CC)
$(LDFLAGS)
$^
-o
$@
-include
$(subst .c,.d,$(SRCS))
run
:
$(PROG)
./
$^
clean
:
$(RM)
$(OBJS)
$(PROG)
$(
subst
.c,.d,
$(SRCS)
)
.PHONY
:
clean FORCE
latency-measure/src/main.c
0 → 100644
View file @
7dff3f4b
#include <errno.h>
#include <error.h>
#include <pthread.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "getip.h"
#include "send_packet.h"
#define CLOCK_ID CLOCK_MONOTONIC
typedef
struct
thread_stat
{
int
nb_cycles
;
}
thread_stat_t
;
typedef
struct
thread_param
{
int
interval
;
int
priority
;
int
max_cycles
;
const
char
*
ip_address
;
thread_stat_t
stats
;
}
thread_param_t
;
// Real-time thread
// Sends packets at a regular intervall
static
void
*
packet_sending_thread
(
void
*
p
)
{
struct
timespec
next
;
struct
sched_param
priority
;
thread_param_t
*
param
=
(
thread_param_t
*
)
p
;
priority
.
sched_priority
=
param
->
priority
;
int
err
=
sched_setscheduler
(
0
,
SCHED_FIFO
,
&
priority
);
if
(
err
)
error
(
EXIT_FAILURE
,
errno
,
"Couldn't set priority"
);
for
(
param
->
stats
.
nb_cycles
=
0
;;
param
->
stats
.
nb_cycles
++
)
{
if
(
param
->
max_cycles
)
if
(
param
->
stats
.
nb_cycles
>=
param
->
max_cycles
)
break
;
clock_gettime
(
CLOCK_ID
,
&
next
);
next
.
tv_sec
+=
param
->
interval
;
send_udp_packet
(
param
->
ip_address
);
clock_nanosleep
(
CLOCK_ID
,
TIMER_ABSTIME
,
&
next
,
NULL
);
}
return
NULL
;
}
static
void
process_options
(
int
argc
,
char
*
argv
[],
thread_param_t
*
param
)
{
for
(;;)
{
int
c
=
getopt
(
argc
,
argv
,
"l:p:i:"
);
if
(
c
==
-
1
)
break
;
switch
(
c
)
{
case
'p'
:
param
->
priority
=
atoi
(
optarg
);
break
;
case
'l'
:
param
->
max_cycles
=
atoi
(
optarg
);
break
;
case
'i'
:
param
->
interval
=
atoi
(
optarg
);
break
;
default:
exit
(
EXIT_FAILURE
);
break
;
}
}
if
(
argc
!=
optind
+
1
)
{
printf
(
"Usage: %s server_ip
\n
"
,
argv
[
0
]);
exit
(
EXIT_FAILURE
);
}
param
->
ip_address
=
argv
[
optind
];
}
// Main thread, has non-real time priority
// Handles the IO and creates real time threads
int
main
(
int
argc
,
char
*
argv
[])
{
pthread_t
thread
;
thread_param_t
param
;
// Default values
param
.
interval
=
1
;
param
.
max_cycles
=
-
1
;
param
.
priority
=
80
;
process_options
(
argc
,
argv
,
&
param
);
int
err
=
pthread_create
(
&
thread
,
NULL
,
packet_sending_thread
,
(
void
*
)
&
param
);
if
(
err
)
error
(
EXIT_FAILURE
,
errno
,
"Couldn't create thread"
);
for
(;;)
{
usleep
(
100000
);
printf
(
"Nb cycles: %d
\n
"
,
param
.
stats
.
nb_cycles
);
if
(
param
.
max_cycles
==
param
.
stats
.
nb_cycles
)
break
;
}
exit
(
EXIT_SUCCESS
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment