+#define _GNU_SOURCE
#include <assert.h>
#include <pthread.h>
#include <sched.h>
int excl_first = 0;
int hist_bin = 10;
int nb = 1000;
+int nb_cores = 0;
char *output = NULL;
extern char *message;
extern void (*usage_ext) (FILE *);
extern int (*parse_arg_ext) (char *);
+extern int rc;
/* usage function */
int usage (int ret)
{
FILE *fd = ret ? stderr : stdout;
- fprintf (fd, "usage: %s [-a int] [-b int] [-d int] [-e int] [-h] [-n int] [-o file] [-s]\n", progname);
+ fprintf (fd, "usage: %s [-a int] [-b int] [-d int] [-e int] [-h] [-k int] [-n int] [-o file] [-s]\n", progname);
fprintf (fd, " -a: avoid aberrand valies (%g%%)\n", abe_per);
fprintf (fd, " -d: delay process start for (%ds)\n", delay);
fprintf (fd, " -b: nb bins for histogram (%d)\n", hist_bin);
fprintf (fd, " -e: exclude %d first tests\n", excl_first);
fprintf (fd, " -h: help message\n");
+ fprintf (fd, " -k: nb dedicated cores (%d)\n", nb_cores);
fprintf (fd, " -n: nb measurements (%d)\n", nb);
fprintf (fd, " -o: output raw data (%s)\n", (output) ? output : "none");
fprintf (fd, " -s: display statistics (%s)\n", (do_stat) ? "yes" : "no");
return ret;
}
+/* launch ping and pong */
+typedef struct {
+ int target;
+ void *(*func)(void *arg);
+} launch_param_t;
+
+void *launch (void *arg)
+{
+ launch_param_t *param = (launch_param_t *)arg;
+ int cpu = (nb_cores == 1) ? 0 : (nb_cores == 2) ? param->target : -1;
+ if (cpu != -1) {
+ cpu_set_t cpu_mask;
+ CPU_ZERO (&cpu_mask);
+ CPU_SET (cpu, &cpu_mask);
+ if (pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpu_mask) != 0) {
+ fprintf (stderr, "error: pthread_setaffinity_np (%d)\n", cpu);
+ rc = 1;
+ pthread_exit (NULL);
+ }
+ }
+ return param->func (arg);
+}
+
/* main function */
int main (int argc, char *argv[])
}
excl_first = atoi (arg);
break;
+ case 'k':
+ arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
+ if (arg == NULL) {
+ fprintf (stderr, "%s: no number of dedicated cores specified\n", progname);
+ return usage (1);
+ }
+ nb_cores = atoi (arg);
+ break;
case 'n':
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
if (arg == NULL) {
}
/* real-time process */
+
struct sched_param param = {0};
if (sched_getparam (0, ¶m) != 0) {
fprintf (stderr, "error: sched_getparam\n");
}
printf ("Test: %s\n", (message) ? message : "unknown");
+ printf ("Dedicated core(s): %d\n", nb_cores);
pthread_mutex_t synchro = PTHREAD_MUTEX_INITIALIZER;
+ launch_param_t lparam = { 0 };
if (init (buffer, nb, &synchro)) {
fprintf (stderr, "error on init\n");
pthread_mutex_lock (&synchro);
pthread_t tid1;
- if (pthread_create (&tid1, NULL, ping, NULL) != 0) {
+ lparam.target = 0;
+ lparam.func = ping;
+ if (pthread_create (&tid1, NULL, launch, &lparam) != 0) {
fprintf (stderr, "error on pthread_create\n");
return 1;
}
pthread_mutex_lock (&synchro);
pthread_t tid2;
- if (pthread_create (&tid2, NULL, pong, NULL) != 0) {
+ lparam.target = 1;
+ lparam.func = pong;
+ if (pthread_create (&tid2, NULL, launch, &lparam) != 0) {
fprintf (stderr, "error on pthread_create\n");
return 1;
}