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
fa4f28e6
Commit
fa4f28e6
authored
May 07, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add refresh rate as an option on the client
parent
50a950fd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
41 deletions
+56
-41
.gitignore
.gitignore
+2
-2
packet-exchange/src/client.c
packet-exchange/src/client.c
+50
-38
packet-exchange/src/send_packet.c
packet-exchange/src/send_packet.c
+4
-1
No files found.
.gitignore
View file @
fa4f28e6
*.o
*.d
simple-server/build/main
simple-client/build/main
latency-measure/build/main
latency-measure/build/main
clockres/build/clockres
clockres/build/clockres_arm
packet-exchange/build/server
packet-exchange/build/client
packet-exchange/src/client.c
View file @
fa4f28e6
...
...
@@ -2,6 +2,7 @@
#include <error.h>
#include <pthread.h>
#include <sched.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
...
...
@@ -11,6 +12,7 @@
#include "send_packet.h"
#define CLOCK_ID CLOCK_MONOTONIC
#define NSEC_PER_SEC UINT64_C(1000000000)
typedef
struct
thread_stat
{
int
nb_cycles
;
...
...
@@ -24,13 +26,16 @@ typedef struct thread_param {
thread_stat_t
stats
;
}
thread_param_t
;
static
void
process_options
(
int
argc
,
char
*
argv
[],
thread_param_t
*
param
);
typedef
struct
main_param
{
int
refresh_rate
;
}
main_param_t
;
static
void
process_options
(
int
argc
,
char
*
argv
[],
thread_param_t
*
param
,
main_param_t
*
main_param
);
// Real-time thread
// Sends packets at a regular intervall
static
void
*
packet_sending_thread
(
void
*
p
)
{
struct
timespec
next
;
struct
sched_param
priority
;
...
...
@@ -40,22 +45,24 @@ static void *packet_sending_thread(void *p) {
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
(
err
)
error
(
EXIT_FAILURE
,
errno
,
"Couldn't set priority"
);
if
(
param
->
max_cycles
)
if
(
param
->
stats
.
nb_cycles
>=
param
->
max_cycles
)
break
;
clock_gettime
(
CLOCK_ID
,
&
next
);
clock_gettime
(
CLOCK_ID
,
&
next
);
next
.
tv_sec
+=
param
->
interval
;
for
(
param
->
stats
.
nb_cycles
=
0
;;
param
->
stats
.
nb_cycles
++
)
{
if
(
param
->
max_cycles
)
if
(
param
->
stats
.
nb_cycles
>=
param
->
max_cycles
)
break
;
send_udp_packet
(
param
->
ip_address
);
clock_nanosleep
(
CLOCK_ID
,
TIMER_ABSTIME
,
&
next
,
NULL
)
;
next
.
tv_nsec
+=
param
->
interval
;
if
(
(
unsigned
int
)
next
.
tv_nsec
>=
NSEC_PER_SEC
)
{
next
.
tv_sec
+=
1
;
next
.
tv_nsec
-=
NSEC_PER_SEC
;
}
clock_nanosleep
(
CLOCK_ID
,
TIMER_ABSTIME
,
&
next
,
NULL
);
}
return
NULL
;
...
...
@@ -64,54 +71,59 @@ static void *packet_sending_thread(void *p) {
// 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
;
main_param_t
main_param
;
// Default values
param
.
interval
=
1
;
param
.
max_cycles
=
-
1
;
param
.
priority
=
99
;
process_options
(
argc
,
argv
,
&
param
);
main_param
.
refresh_rate
=
50000
;
// Process bash options
process_options
(
argc
,
argv
,
&
param
,
&
main_param
);
if
(
pthread_create
(
&
thread
,
NULL
,
packet_sending_thread
,
(
void
*
)
&
param
))
usleep
(
10000
);
if
(
pthread_create
(
&
thread
,
NULL
,
packet_sending_thread
,
(
void
*
)
&
param
))
error
(
EXIT_FAILURE
,
errno
,
"Couldn't create thread"
);
for
(;;)
{
usleep
(
100000
);
usleep
(
main_param
.
refresh_rate
);
printf
(
"Nb cycles: %d
\n
"
,
param
.
stats
.
nb_cycles
);
if
(
param
.
max_cycles
==
param
.
stats
.
nb_cycles
)
break
;
if
(
param
.
max_cycles
==
param
.
stats
.
nb_cycles
)
break
;
}
exit
(
EXIT_SUCCESS
);
}
static
void
process_options
(
int
argc
,
char
*
argv
[],
thread_param_t
*
param
)
{
for
(;;)
{
int
c
=
getopt
(
argc
,
argv
,
"l:p:i:"
);
static
void
process_options
(
int
argc
,
char
*
argv
[],
thread_param_t
*
param
,
main_param_t
*
main_param
)
{
for
(;;)
{
int
c
=
getopt
(
argc
,
argv
,
"i:l:p:r:"
);
if
(
c
==
-
1
)
break
;
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
;
switch
(
c
)
{
case
'i'
:
param
->
interval
=
atoi
(
optarg
)
*
1000
;
break
;
case
'l'
:
param
->
max_cycles
=
atoi
(
optarg
);
break
;
case
'p'
:
param
->
priority
=
atoi
(
optarg
);
break
;
case
'r'
:
main_param
->
refresh_rate
=
atoi
(
optarg
);
break
;
default:
exit
(
EXIT_FAILURE
);
break
;
}
}
...
...
packet-exchange/src/send_packet.c
View file @
fa4f28e6
...
...
@@ -57,7 +57,10 @@ int send_udp_packet(const char * server_ip) {
freeaddrinfo
(
servinfo
);
printf
(
"Sent %d bytes to %s
\n
"
,
bytes_sent
,
server_ip
);
#ifdef DEBUG_ENABLED
printf
(
"Sent %d bytes to %s
\n
"
,
bytes_sent
,
server_ip
);
#endif
close
(
sockfd
);
return
0
;
}
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