//#define DEBUG 1
//#define DEBUG 2
+#define WITH_RTPRIO
+
+#ifdef WITH_RTPRIO
+#include <sched.h>
+
+int sched_policy = SCHED_OTHER;
+int sched_rtprio;
+
+#endif
+
#ifndef DEBUG
#define dbg(level, fmt, arg...) do {} while (0)
}
}
+#ifdef WITH_RTPRIO
+int set_sched_policy_and_prio(int policy, int rtprio)
+{
+ struct sched_param scheduling_parameters;
+ int maxprio=sched_get_priority_max(policy);
+ int minprio=sched_get_priority_min(policy);
+
+ if((rtprio < minprio) || (rtprio > maxprio)) {
+ fprintf(stderr, "The priority for requested policy is out of <%d, %d> range\n",
+ minprio, maxprio);
+ return -1;
+ }
+
+ scheduling_parameters.sched_priority = rtprio;
+
+ if (0 != pthread_setschedparam(pthread_self(), policy, &scheduling_parameters)) {
+ perror("pthread_setschedparam error");
+ }
+ return 0;
+}
+#endif
+
void print_help(void)
{
printf("Usage: canping -m <master threads> [other options]\n"
" -w ms wait ms miliseconds between sending pings\n"
" -y synchronize threads before start (doesn't test race conditions\n"
" between open and read/write)\n"
+#ifdef WITH_RTPRIO
+ " -r run at realtime priority\n"
+ " -R P:prio run at realtime priority prio, policy RR or FF\n"
+#endif
"\n"
"Example: canping -m 10 -vv\n"
);
int c;
opterr = 0;
- while ((c = getopt (argc, argv, "c:d:hi:l:m:os:t:vw:y")) != -1)
+ while ((c = getopt (argc, argv, "c:d:hi:l:m:os:t:vw:yrR:")) != -1)
switch (c)
{
case 'c':
case 'y':
option_synch_start = 1;
break;
+#ifdef WITH_RTPRIO
+ case 'r':
+ sched_policy = SCHED_FIFO;
+ sched_rtprio = (sched_get_priority_min(SCHED_FIFO) +
+ sched_get_priority_max(SCHED_FIFO)) / 2;
+ break;
+ case 'R':
+ if(!isalpha(*optarg)) {
+ sched_policy = SCHED_FIFO;
+ } else if(!strncmp(optarg,"FF:",3)) {
+ sched_policy = SCHED_FIFO;
+ optarg += 3;
+ } else if(!strncmp(optarg,"RR:",3)) {
+ sched_policy = SCHED_RR;
+ optarg += 3;
+ } else {
+ fprintf (stderr, "Unknown policy %s\n", optarg);
+ exit(EXIT_BAD_PARAM);
+ }
+ sched_rtprio = atoi(optarg);
+ break;
+#endif
case '?':
if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
{
parse_options(argc, argv);
+#ifdef WITH_RTPRIO
+ if(sched_policy != SCHED_OTHER)
+ if(set_sched_policy_and_prio(sched_policy, sched_rtprio) <0)
+ exit(EXIT_BAD_PARAM);
+#endif
+
+
thread_list_init_head(&master_threads);
thread_list_init_head(&slave_threads);