sk_wait_data
Pranay Srivastava
pranjas at gmail.com
Thu Feb 19 23:41:33 EST 2015
Hi
On Thu, Feb 19, 2015 at 3:45 PM, Grzegorz Dwornicki <gd1100 at gmail.com> wrote:
> Hello
>
> Proces have a established tcp socket. It calls sys_revcmsg on that
> socket. That function goes all the way to tcp_recvmsg function.
>
> Function tcp_recvmsg.c (defined in net/ipv4/tcp.c) blocks it self on
> function sk_wait_data if socket recv queue is empty. I wanted to know
> how socked is checked in time. Soo i Looked up this sk_wait_data
> function (http://lxr.free-electrons.com/source/net/core/sock.c#L1933):
>
> 1933 int sk_wait_data(struct sock *sk, long *timeo)
> 1934 {
> 1935 int rc;
> 1936 DEFINE_WAIT(wait);
> 1937
> 1938 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
> 1939 set_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
> 1940 rc = sk_wait_event(sk, timeo,
> !skb_queue_empty(&sk->sk_receive_queue));
> 1941 clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
> 1942 finish_wait(sk_sleep(sk), &wait);
> 1943 return rc;
> 1944 }
>
> This function blocks it self on the sk_wait_event macro. Here is it
> definition (http://lxr.free-electrons.com/source/include/net/sock.h#L893):
>
> 893 #define sk_wait_event(__sk, __timeo, __condition) \
> 894 ({ int __rc; \
> 895 release_sock(__sk); \
> 896 __rc = __condition; \
> 897 if (!__rc) { \
> 898 *(__timeo) = schedule_timeout(*(__timeo)); \
> 899 } \
> 900 lock_sock(__sk); \
> 901 __rc = __condition; \
> 902 __rc; \
> 903 })
>
> This macro is blocked in the schedule_timeout all the time. I know
> this because I added printk functions with some marks easly to target
> the line blocking the socket. It hangs on this schedule_timeout and it
> magicaly released when some data apear in the revc queue.
>
> How does the kernel know when to "unblock" the process? Function name:
> sk_wait_data and macro name: sk_wait_event tells me that there should
> be some queue checning from time to time...
>
> Can someone explain this to me?
Perhaps you should see sk_data_ready callback's default implementation for this.
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
--
---P.K.S
More information about the Kernelnewbies
mailing list