From owner-svn-src-head@FreeBSD.ORG Mon May 23 13:51:58 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 07AF1106567B; Mon, 23 May 2011 13:51:58 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DF95C8FC25; Mon, 23 May 2011 13:51:57 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p4NDpvj1024438; Mon, 23 May 2011 13:51:57 GMT (envelope-from rwatson@svn.freebsd.org) Received: (from rwatson@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p4NDpvWf024436; Mon, 23 May 2011 13:51:57 GMT (envelope-from rwatson@svn.freebsd.org) Message-Id: <201105231351.p4NDpvWf024436@svn.freebsd.org> From: Robert Watson Date: Mon, 23 May 2011 13:51:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r222213 - head/sys/netinet X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 May 2011 13:51:58 -0000 Author: rwatson Date: Mon May 23 13:51:57 2011 New Revision: 222213 URL: http://svn.freebsd.org/changeset/base/222213 Log: A number of quite incremental refinements to struct inpcbinfo's definition: (1) Add a locking guide for inpcbinfo. (2) Annotate inpcbinfo fields with synchronisation information; not all annotations are 100% satisfactory. (3) Reorder inpcbinfo fields so that the lock is at the head of the structure, and close to fields it protects. (4) Sort fields that will eventually be hashlock/pcbgroup-related together even though they remain locked by ipi_lock for now. Reviewed by: bz Sponsored by: Juniper Networks X-MFC after: KBI analysis required Modified: head/sys/netinet/in_pcb.h Modified: head/sys/netinet/in_pcb.h ============================================================================== --- head/sys/netinet/in_pcb.h Mon May 23 13:02:04 2011 (r222212) +++ head/sys/netinet/in_pcb.h Mon May 23 13:51:57 2011 (r222213) @@ -1,8 +1,12 @@ /*- * Copyright (c) 1982, 1986, 1990, 1993 * The Regents of the University of California. + * Copyright (c) 2010-2011 Juniper Networks, Inc. * All rights reserved. * + * Portions of this software were developed by Robert N. M. Watson under + * contract to Juniper Networks, Inc. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -260,53 +264,70 @@ struct inpcbport { u_short phd_port; }; -/* +/*- * Global data structure for each high-level protocol (UDP, TCP, ...) in both * IPv4 and IPv6. Holds inpcb lists and information for managing them. + * + * Each pcbinfo is protected by ipi_lock, covering mutable global fields (such + * as the global pcb list) and hashed lookup tables. The lock order is: + * + * ipi_lock (before) inpcb locks + * + * Locking key: + * + * (c) Constant or nearly constant after initialisation + * (g) Locked by ipi_lock + * (h) Read using either ipi_lock or inpcb lock; write requires both. + * (x) Synchronisation properties poorly defined */ struct inpcbinfo { /* - * Global list of inpcbs on the protocol. + * Global lock protecting global inpcb list, inpcb count, hash tables, + * etc. */ - struct inpcbhead *ipi_listhead; - u_int ipi_count; + struct rwlock ipi_lock; /* - * Global hash of inpcbs, hashed by local and foreign addresses and - * port numbers. + * Global list of inpcbs on the protocol. */ - struct inpcbhead *ipi_hashbase; - u_long ipi_hashmask; + struct inpcbhead *ipi_listhead; /* (g) */ + u_int ipi_count; /* (g) */ /* - * Global hash of inpcbs, hashed by only local port number. + * Generation count -- incremented each time a connection is allocated + * or freed. */ - struct inpcbporthead *ipi_porthashbase; - u_long ipi_porthashmask; + u_quad_t ipi_gencnt; /* (g) */ /* * Fields associated with port lookup and allocation. */ - u_short ipi_lastport; - u_short ipi_lastlow; - u_short ipi_lasthi; + u_short ipi_lastport; /* (x) */ + u_short ipi_lastlow; /* (x) */ + u_short ipi_lasthi; /* (x) */ /* * UMA zone from which inpcbs are allocated for this protocol. */ - struct uma_zone *ipi_zone; + struct uma_zone *ipi_zone; /* (c) */ /* - * Generation count--incremented each time a connection is allocated - * or freed. + * Global hash of inpcbs, hashed by local and foreign addresses and + * port numbers. */ - u_quad_t ipi_gencnt; - struct rwlock ipi_lock; + struct inpcbhead *ipi_hashbase; /* (g) */ + u_long ipi_hashmask; /* (g) */ + + /* + * Global hash of inpcbs, hashed by only local port number. + */ + struct inpcbporthead *ipi_porthashbase; /* (g) */ + u_long ipi_porthashmask; /* (g) */ /* * Pointer to network stack instance */ - struct vnet *ipi_vnet; + struct vnet *ipi_vnet; /* (c) */ /* * general use 2