[can-utils][PATCH 1/3] cangen: support socket priority

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Zhu Yi <yi.zhu5@xxxxxxxxxxxx>

Add '-P' option for allow user to set the socket priority. This can be
useful in conjuction with queuing discipline.

Signed-off-by: Zhu Yi <yi.zhu5@xxxxxxxxxxxx>
Signed-off-by: Hubert Streidl <hubert.streidl@xxxxxxxxxxxx>
Signed-off-by: Mark Jonas <mark.jonas@xxxxxxxxxxxx>
---
 cangen.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/cangen.c b/cangen.c
index d9a0448..1346eb7 100644
--- a/cangen.c
+++ b/cangen.c
@@ -189,6 +189,7 @@ static void print_usage(char *prg)
 	fprintf(stderr, "         -A <mode>     (CAN XL AF generation mode - see below, no e/o mode)\n");
 	fprintf(stderr, "         -V <mode>     (CAN XL VCID generation mode - see below, no e/o mode)\n");
 	fprintf(stderr, "         -p <timeout>  (poll on -ENOBUFS to write frames with <timeout> ms)\n");
+	fprintf(stderr, "         -P <priority> (set socket priority using SO_PRIORITY)\n");
 	fprintf(stderr, "         -n <count>    (terminate after <count> CAN frames - default infinite)\n");
 	fprintf(stderr, "         -i            (ignore -ENOBUFS return values on write() syscalls)\n");
 	fprintf(stderr, "         -x            (disable local loopback of generated CAN frames)\n");
@@ -479,6 +480,7 @@ int main(int argc, char **argv)
 	uint64_t incdata = 0;
 	__u8 *data; /* base pointer for CC/FD or XL data */
 	int incdlc = 0;
+	int priority = -1;
 	unsigned long rnd;
 	unsigned char fixdata[CANFD_MAX_DLEN];
 	unsigned char rand_position[CANFD_MAX_DLEN] = { 0 };
@@ -512,7 +514,7 @@ int main(int argc, char **argv)
 		{ 0,		0,			0, 0 },
 	};
 
-	while ((opt = getopt_long(argc, argv, "g:atefbEXR8mI:L:D:F:S:A:V:p:n:ixc:vh?", long_options, NULL)) != -1) {
+	while ((opt = getopt_long(argc, argv, "g:atefbEXR8mI:L:D:F:S:A:V:p:P:n:ixc:vh?", long_options, NULL)) != -1) {
 		switch (opt) {
 		case 'g':
 			gap = strtod(optarg, NULL);
@@ -682,6 +684,14 @@ int main(int argc, char **argv)
 			}
 			break;
 
+		case 'P':
+			priority = atoi(optarg);
+			if (priority < 0) {
+				printf("socket priority has to be >= 0\n");
+				return 1;
+			}
+			break;
+
 		case 'i':
 			ignore_enobufs = true;
 			break;
@@ -750,6 +760,14 @@ int main(int argc, char **argv)
 	 */
 	setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
 
+	/*
+	 * user can use tc to configure the queuing discipline (e.g. mqprio),
+	 * together with SO_PRIORITY option to specify the message send from
+	 * this socket should go to which queue.
+	 */
+	if (priority >= 0)
+		setsockopt(s, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority));
+
 	if (loopback_disable) {
 		const int loopback = 0;
 
-- 
2.34.1





[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux