* lock_sock or sock_hold ?
@ 2010-07-26 14:00 Neshama Parhoti
2010-07-26 14:43 ` Eric Dumazet
0 siblings, 1 reply; 2+ messages in thread
From: Neshama Parhoti @ 2010-07-26 14:00 UTC (permalink / raw)
To: netdev
hello everyone,
can you please be kind and help me understand the differences between
lock_sock and sock_hold ?
i can see that lock_sock takes a spin lock (bh) to mark owned = 1, and
then takes a mutex, whereas sock_hold only increases the atomic
refcnt.
but how do i know which of them I should use ?
i'm puzzled as to when should those two different APIs be used..
thank you a lot
~pnesh
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: lock_sock or sock_hold ?
2010-07-26 14:00 lock_sock or sock_hold ? Neshama Parhoti
@ 2010-07-26 14:43 ` Eric Dumazet
0 siblings, 0 replies; 2+ messages in thread
From: Eric Dumazet @ 2010-07-26 14:43 UTC (permalink / raw)
To: Neshama Parhoti; +Cc: netdev
Le lundi 26 juillet 2010 à 17:00 +0300, Neshama Parhoti a écrit :
> hello everyone,
>
> can you please be kind and help me understand the differences between
> lock_sock and sock_hold ?
>
> i can see that lock_sock takes a spin lock (bh) to mark owned = 1, and
> then takes a mutex, whereas sock_hold only increases the atomic
> refcnt.
>
> but how do i know which of them I should use ?
>
> i'm puzzled as to when should those two different APIs be used..
sock_hold() only increments a refcount, so that you are sure nobody can
destroy the socket (and its memory) under you. But you cannot modify
socket state only with this refcount taken.
To get exclusive access to the socket you either :
1) Are in process context and use lock_sock().
2) Are in softirq context (input path for example) :
2.1) Lookup the socket in protocol hash tables, and get a refcount on
it (by sock_hold() or other atomic operation on refcnt)
2.2) Then, get semi exclusive access using bh_lock_sock()
2.3) Check if another process already is using the socket (we
interrupted this process on same CPU, or run on another cpu)
if (sock_owned_by_user(sk)) {
// queue work to socket backlog (delayed work)
} else {
// process packet right now
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-07-26 14:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-26 14:00 lock_sock or sock_hold ? Neshama Parhoti
2010-07-26 14:43 ` Eric Dumazet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox