Add non-RT sendmsg and recvmsg in rtpacket.
cover Add non-RT sendmsg and recvmsg in rtpacket.
Edouard Tisserant (1):
Add non-RT sendmsg and recvmsg in rtpacket.
kernel/drivers/net/stack/packet/af_packet.c | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+)
Signature · 1 line
2.17.1
Quoted 1 line
From
89155c30d2ffe1ed0b7c51d2b990866eff77a53fMon Sep 17 00:00:00 2001
From: Edouard Tisserant <[email protected]>
Date: Sat, 15 Sep 2018 14:51:11 +0200
Subject: [PATCH 1/1] Add non-RT sendmsg and recvmsg in rtpacket.
--- kernel/drivers/net/stack/packet/af_packet.c | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+)
(quoted diff) +0 -0
b/kernel/drivers/net/stack/packet/af_packet.c
index 9fa985d37..00337892b 100644
kernel/drivers/net/stack/packet/af_packet.c +14 -0
@@ -26,6 +26,7 @@#include <linux/sched.h> #include <linux/err.h> +#include <rtnet_rtpc.h>#include <rtnet_iovec.h> #include <rtnet_socket.h> #include <stack_mgr.h>
@@ -411,7 +412,31 @@ fail: goto out; } +struct recvmsg_params { +struct rtdm_fd *fd; +struct user_msghdr *msg; +int msg_flags; +}; + +static int recvmsg_handler (struct rt_proc_call *call) +{ +struct recvmsg_params *params; + params = rtpc_get_priv(call, struct recvmsg_params); + +return rt_packet_recvmsg (params->fd, params->msg, params->msg_flags); +} + +static ssize_t +nrt_packet_recvmsg(struct rtdm_fd *fd, struct user_msghdr *msg, int
msg_flags)
+{
+ int ret;
+ struct recvmsg_params params = {fd,msg,msg_flags};
+
+ ret = rtpc_dispatch_call(recvmsg_handler, 0, ¶ms,
+ sizeof(params), NULL, NULL);
+ return ret;
+}
/***
* rt_packet_sendmsg
@@ -544,6 +569,33 @@ rt_packet_sendmsg(struct rtdm_fd *fd, const struct user_msghdr *msg, int msg_fla
goto out;
}
+struct sendmsg_params {
+ struct rtdm_fd *fd;
+ const struct user_msghdr *msg;
+ int msg_flags;+};
+
+static int sendmsg_handler(struct rt_proc_call *call)
+{
+ struct sendmsg_params *params;
+
+ params = rtpc_get_priv(call, struct sendmsg_params);
+
+ return rt_packet_sendmsg(params->fd, params->msg, params->msg_flags);
+}
+
+static ssize_t
+nrt_packet_sendmsg(struct rtdm_fd *fd, const struct user_msghdr *msg, int msg_flags)
+{
+ int ret;
+ struct sendmsg_params params = {fd,msg,msg_flags};
+
+ ret = rtpc_dispatch_call(sendmsg_handler, 0, ¶ms,
+ sizeof(params), NULL, NULL);
+ return ret;
+}
+
+
static struct rtdm_driver packet_proto_drv = {
@@ -566,6 +618,8 @@ static struct rtdm_driver packet_proto_drv = {
.ioctl_nrt = rt_packet_ioctl,
.recvmsg_rt = rt_packet_recvmsg,
.sendmsg_rt = rt_packet_sendmsg,
+ .recvmsg_nrt = nrt_packet_recvmsg,
+ .sendmsg_nrt = nrt_packet_sendmsg,
.select = rt_socket_select_bind,
},
};
@@ -595,6 +649,8 @@ static struct rtdm_driver raw_packet_proto_drv = {
.ioctl_nrt = rt_packet_ioctl,
.recvmsg_rt = rt_packet_recvmsg,
.sendmsg_rt = rt_packet_sendmsg,
+ .recvmsg_nrt = nrt_packet_recvmsg,
+ .sendmsg_nrt = nrt_packet_sendmsg,
.select = rt_socket_select_bind,
},};
Signature · 1 line
2.17.1
Quoted 7 lines · Edouard Tisserant
Edouard Tisserant (1):
Add non-RT sendmsg and recvmsg in rtpacket.kernel/drivers/net/stack/packet/af_packet.c | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+)
Better but not quite yet: Just copy&paste the output of "git format-patch --stdout $COMMIT^..$COMMIT" into the email body AND make sure line wrapping is off - or use git send-email.
Quoted 31 lines
From
89155c30d2ffe1ed0b7c51d2b990866eff77a53fMon Sep 17 00:00:00 2001
From: Edouard Tisserant <[email protected]>
Date: Sat, 15 Sep 2018 14:51:11 +0200
Subject: [PATCH 1/1] Add non-RT sendmsg and recvmsg in rtpacket.--- kernel/drivers/net/stack/packet/af_packet.c | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+)kernel/drivers/net/stack/packet/af_packet.c +6
-0@@ -26,6 +26,7 @@#include <linux/sched.h> #include <linux/err.h> +#include <rtnet_rtpc.h>#include <rtnet_iovec.h> #include <rtnet_socket.h> #include <stack_mgr.h> @@ -411,7 +412,31 @@ fail: goto out; } +struct recvmsg_params { +struct rtdm_fd *fd; +struct user_msghdr *msg; +int msg_flags; +}; + +static int recvmsg_handler (struct rt_proc_call *call)
kernel/drivers/net/stack/packet/af_packet.c fail: · line 430
Quoted 10 lines
kernel/drivers/net/stack/packet/af_packet.c +8
-0+{ +struct recvmsg_params *params; + params = rtpc_get_priv(call, struct recvmsg_params); + +return rt_packet_recvmsg (params->fd, params->msg, params->msg_flags); +} + +static ssize_t +nrt_packet_recvmsg (struct rtdm_fd *fd,struct user_msghdr *msg,int msg_flags)
See, something mangled the patch.
Quoted 64 lines
kernel/drivers/net/stack/packet/af_packet.c +8
-0+{ +int ret; +struct recvmsg_params params = {fd,msg,msg_flags}; + + ret =rtpc_dispatch_call (recvmsg_handler,0 , ¶ms, +sizeof (params),NULL ,NULL ); +return ret; +}/*** * rt_packet_sendmsg @@ -544,6 +569,33 @@ rt_packet_sendmsg(struct rtdm_fd *fd, const struct
user_msghdr*msg, intmsg_flagoto out;}
+structsendmsg_params{kernel/drivers/net/stack/packet/af_packet.c +16
-0+struct rtdm_fd *fd; +const struct user_msghdr *msg; +int msg_flags; +}; + +static int sendmsg_handler (struct rt_proc_call *call) +{ +struct sendmsg_params *params; + + params = rtpc_get_priv(call, struct sendmsg_params); + +return rt_packet_sendmsg (params->fd, params->msg, params->msg_flags); +} + +static ssize_t +nrt_packet_sendmsg(struct rtdm_fd *fd, const struct user_msghdr *msg,int
msg_flags)kernel/drivers/net/stack/packet/af_packet.c +14
-0+{ +int ret; +struct sendmsg_params params = {fd,msg,msg_flags}; + + ret =rtpc_dispatch_call (sendmsg_handler,0 , ¶ms, +sizeof (params),NULL ,NULL ); +return ret; +} + +static struct rtdm_driver packet_proto_drv = {@@ -566,6 +618,8 @@ static struct rtdm_driver packet_proto_drv = { .ioctl_nrt = rt_packet_ioctl, .recvmsg_rt = rt_packet_recvmsg, .sendmsg_rt = rt_packet_sendmsg, + .recvmsg_nrt = nrt_packet_recvmsg, + .sendmsg_nrt = nrt_packet_sendmsg, .select = rt_socket_select_bind, }, };@@ -595,6 +649,8 @@ static struct rtdm_driver raw_packet_proto_drv = { .ioctl_nrt = rt_packet_ioctl, .recvmsg_rt = rt_packet_recvmsg, .sendmsg_rt = rt_packet_sendmsg, + .recvmsg_nrt = nrt_packet_recvmsg, + .sendmsg_nrt = nrt_packet_sendmsg, .select = rt_socket_select_bind, }, };Signature · 1 line
2.17.1
Ok, on the content: Why do you need that mechanism? Normally, all your RT application threads have a Xenomai shadow that can be used to execute RT calls, like send or receive. By not providing the related nrt callbacks, a driver signals to the core "migrate the caller to RT as needed". If you look at other drivers, they do not have such trampolines as well, e.g. the CAN stack or the UARTs.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Hi Jan,
Quoted 3 lines
Better but not quite yet: Just copy&paste the output of "git format-patch --stdout $COMMIT^..$COMMIT" into the email body AND make sure line wrapping is off - or use git send-email.
Thanks for telling, I didn't realize my MUA wrecked the patch. I actually used "git send-email --stdout origin > mail.eml", opened .eml file with thunderbird, and sent it. I thought that it would have been preserved this way, but i guess I'll have to setup sendmail.
Quoted 6 lines
Ok, on the content: Why do you need that mechanism? Normally, all your RT application threads have a Xenomai shadow that can be used to execute RT calls, like send or receive. By not providing the related nrt callbacks, a driver signals to the core "migrate the caller to RT as needed". If you look at other drivers, they do not have such trampolines as well, e.g. the CAN stack or the UARTs.
Indeed. Now that you present it like that, it feels like bit of a hack.
The reason is that EtherLAB master "Idle" thread is a non-real-time kernel thread, sending Ethernet frames periodically. That kernel thread found no trampoline when jumping in rtdm_recvmsg, it just got -ENOSYS. It looks like that from kernel side there is no such an automatic migration implemented, so I looked around to see what was implementing such a delegation pattern, and rtpc.c was a good candidate.
Having the "migrate the caller to RT as needed" trampoline for all rtdm_* non implemented ops.nrt_* calls from kernel space would be definitely better. Why it is reserved only to userspace apps ? ;)
Edouard
Quoted 10 lines · Edouard Tisserant
Hi Jan,
Quoted 3 lines
Better but not quite yet: Just copy&paste the output of "git format-patch --stdout $COMMIT^..$COMMIT" into the email body AND make sure line wrapping is off - or use git send-email.
Thanks for telling, I didn't realize my MUA wrecked the patch. I actually used "git send-email --stdout origin > mail.eml", opened .eml file with thunderbird, and sent it. I thought that it would have been preserved this way, but i guess I'll have to setup sendmail.
If you want to use TB, you need to turn off line wrapping in the config, of via the Toggle Word Wrap extension (that needs tweaks of its own since TB60).
Quoted 8 lines
Quoted 7 lines
Ok, on the content: Why do you need that mechanism? Normally, all your RT application threads have a Xenomai shadow that can be used to execute RT calls, like send or receive. By not providing the related nrt callbacks, a driver signals to the core "migrate the caller to RT as needed". If you look at other drivers, they do not have such trampolines as well, e.g. the CAN stack or the UARTs.
Quoted 8 lines
Indeed. Now that you present it like that, it feels like bit of a hack.
The reason is that EtherLAB master "Idle" thread is a non-real-time kernel thread, sending Ethernet frames periodically. That kernel thread found no trampoline when jumping in
rtdm_recvmsg, it just got-ENOSYS. It looks like that from kernel side there is no such an automatic migration implemented, so I looked around to see what was implementing such a delegation pattern, andrtpc.cwas a good candidate.
The migration happens in the syscall entry path, like with other calls as well, if the handler returned -ENOSYS and there is a shadow thread.
Quoted 4 lines
Having the "migrate the caller to RT as needed" trampoline for all rtdm_* non implemented ops.nrt_* calls from kernel space would be definitely better. Why it is reserved only to userspace apps ? ;)
Because there is no syscall entry point for kernel threads so that we could easily detect the condition and migrate them. And there are also no general use cases, I'm afraid. In your scenario, just spawn your own RT kernel thread, like RTnet does for some purposes as well (RTcfg eg.), and let that thread drive the periodic transmission. Does the current non-rt thread do anything with Linux at all? If not, migration would be even simpler.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 7 lines
Quoted 3 lines
Why it is reserved only to userspace apps ? ;)
Because there is no syscall entry point for kernel threads so that we could easily detect the condition and migrate them. And there are also no general use cases, I'm afraid.
Definitely. I was just kidding :)
Quoted 4 lines
In your scenario, just spawn your own RT kernel thread, like RTnet does for some purposes as well (RTcfg eg.), and let that thread drive the periodic transmission. Does the current non-rt thread do anything with Linux at all? If not, migration would be even simpler.
It does. But no problem I'll just move those calls to rtpc_* in rtdmnet.c, and use rtdm_in_rt_context() to decide.
rtpc_* calls are quite handy in that case. Symbols are exposed, but they aren't documented in API, so I suppose they are not part of the "RTDM Driver programming Interface" that I should use in that case... Is it planned to have them in API ?
Edouard