linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: Prabhakar Lad <prabhakar.csengg@gmail.com>
Cc: "linux-can@vger.kernel.org" <linux-can@vger.kernel.org>
Subject: [RFC] sched policies for candump
Date: Thu, 18 Dec 2014 10:41:58 +0100	[thread overview]
Message-ID: <5492A166.4090806@hartkopp.net> (raw)
In-Reply-To: <CA+V-a8uhnn9cfuxULZQ4oBScy9jYfev+n50SphK+HDTVLPVO_g@mail.gmail.com>

Hello Prabhakar,

I just discovered your pull-request for candump to add scheduling policies for candump:

https://gitorious.org/linux-can/can-utils/commit/0ea8caacfa723271778d000e8cb97b2be4f92165

Is this still needed / valuable?

If so I would suggest to make the commandline option able to handle more than only SCHED_RR ...

Would the following patch be ok for you?

Regards,
Oliver

---

diff --git a/candump.c b/candump.c
index a1146f5..4334be5 100644
--- a/candump.c
+++ b/candump.c
@@ -51,6 +51,7 @@
 #include <libgen.h>
 #include <time.h>
 #include <errno.h>
+#include <sched.h>
 
 #include <sys/time.h>
 #include <sys/types.h>
@@ -124,6 +125,7 @@ void print_usage(char *prg)
 	fprintf(stderr, "         -e          (dump CAN error frames in human-readable format)\n");
 	fprintf(stderr, "         -x          (print extra message infos, rx/tx brs esi)\n");
 	fprintf(stderr, "         -T <msecs>  (terminate after <msecs> without any reception)\n");
+	fprintf(stderr, "         -R <p:prio> (set priority for scheduling policy p={R,F})\n");
 	fprintf(stderr, "\n");
 	fprintf(stderr, "Up to %d CAN interfaces with optional filter sets can be specified\n", MAXSOCK);
 	fprintf(stderr, "on the commandline in the form: <ifname>[,filter]*\n");
@@ -216,6 +218,8 @@ int main(int argc, char **argv)
 	unsigned char logfrmt = 0;
 	int count = 0;
 	int rcvbuf_size = 0;
+	int sched_policy = 0;
+	int sched_priority = 0;
 	int opt, ret;
 	int currmax, numfilter;
 	char *ptr, *nptr;
@@ -240,7 +244,7 @@ int main(int argc, char **argv)
 	last_tv.tv_sec  = 0;
 	last_tv.tv_usec = 0;
 
-	while ((opt = getopt(argc, argv, "t:ciaSs:b:B:u:ldxLn:r:heT:?")) != -1) {
+	while ((opt = getopt(argc, argv, "t:ciaSs:b:B:u:ldxLn:r:heT:R:?")) != -1) {
 		switch (opt) {
 		case 't':
 			timestamp = optarg[0];
@@ -366,6 +370,23 @@ int main(int argc, char **argv)
 			timeout_config.tv_usec = (timeout_config.tv_usec % 1000) * 1000;
 			timeout_current = &timeout;
 			break;
+
+		case 'R':
+		{
+			/* check for supported scheduling policy 'p:<prio>' */
+			if (optarg[0] == 'R' && optarg[1] == ':')
+				sched_policy = SCHED_RR;
+			else if (optarg[0] == 'F' && optarg[1] == ':')
+				sched_policy = SCHED_FIFO;
+			else {
+				print_usage(basename(argv[0]));
+				exit(1);
+			}
+			/* get priority from behind the ':' */
+			sched_priority = atoi(optarg+2);
+			break;
+		}
+
 		default:
 			print_usage(basename(argv[0]));
 			exit(1);
@@ -596,6 +617,17 @@ int main(int argc, char **argv)
 		}
 	}
 
+	/* set scheduler policy and priority */
+	if (sched_policy) {
+		struct sched_param sched;
+
+		memset(&sched, 0, sizeof sched);
+		sched.sched_priority = sched_priority;
+		if (sched_setscheduler(0, sched_policy, &sched) < 0)
+			fprintf(stderr, "\nFailed to select scheduler policy: %s (%d)\n",
+				strerror(errno), errno);
+	}
+
 	/* these settings are static and can be held out of the hot path */
 	iov.iov_base = &frame;
 	msg.msg_name = &addr;



  reply	other threads:[~2014-12-18  9:42 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-23 14:48 C_CAN: can frame drops Ssagarr Patil
2014-07-23 16:04 ` Oliver Hartkopp
2014-07-23 16:33   ` Ssagarr Patil
2014-07-24  7:40     ` Ssagarr Patil
2014-07-24 18:09       ` Oliver Hartkopp
2014-07-25  8:20         ` Ssagarr Patil
2014-07-25  7:17 ` Marc Kleine-Budde
2014-07-25  8:13   ` Ssagarr Patil
2014-07-25  8:16     ` Marc Kleine-Budde
2014-07-25  8:22       ` Ssagarr Patil
2014-07-25  8:27         ` Marc Kleine-Budde
2014-07-25  8:35           ` Ssagarr Patil
2014-07-25  8:48             ` Marc Kleine-Budde
2014-07-25  9:47               ` Ssagarr Patil
2014-07-25 10:10                 ` Marc Kleine-Budde
2014-07-25 11:22                   ` Ssagarr Patil
2014-07-25 10:43                 ` Oliver Hartkopp
2014-07-25 11:24                   ` Ssagarr Patil
2014-07-30 11:28                   ` Prabhakar Lad
2014-07-30 16:17                     ` Oliver Hartkopp
2014-07-31 12:41                       ` Ssagarr Patil
2014-07-31 12:42                         ` Marc Kleine-Budde
2014-07-31 14:11                           ` Oliver Hartkopp
2014-07-31 14:19                             ` Prabhakar Lad
2014-12-18  9:41                               ` Oliver Hartkopp [this message]
2014-12-18 12:33                                 ` [RFC] sched policies for candump Prabhakar Lad
2014-12-18 13:51                                   ` Oliver Hartkopp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5492A166.4090806@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=linux-can@vger.kernel.org \
    --cc=prabhakar.csengg@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).