Tuesday, November 3, 2009

Section 8.15.  Locking










8.15. Locking





We saw in the section "Organization of net_device Structures" that the dev_base list and the two hash tables dev_name_head and dev_name_index are protected by the dev_base_list lock. That lock, however, is used only to serialize accesses to the list and tables, not to serialize changes to the contents of net_device data structures. net_device content changes are taken care of by the Routing Netlink semaphore (rtnl_sem), which is acquired and released with rtnl_lock and rtnl_unlock, respectively.[*] This semaphore is used to serialize changes to net_device instances from:

[*] Other routines can also be used to acquire and release the semaphore. See include/linux/rtnetlink.h for more details.



Runtime events


For example, when the link state changes (e.g., a network cable is plugged or unplugged), the kernel needs to change the device state by modifying dev->flags.


Configuration changes


When the user applies a configuration change with commands such as ifconfig and route from the net-tools package, or ip from the IPROUTE2 package, the kernel is notified via ioctl commands and the Netlink socket, respectively. The routines invoked via these interfaces must use locks.


The net_device data structure includes a few fields used for locking, among them:



ingress_lock



queue_lock


Used by Traffic Control when dealing with ingress and egress traffic scheduling, respectively.


xmit_lock



xmit_lock_owner


Used to synchronize accesses to the device driver hard_start_xmit function.


For more details on these locks, please refer to Chapter 11.












No comments: