if_hatm_intr.c (121729) | if_hatm_intr.c (121744) |
---|---|
1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * Author: Hartmut Brandt <harti@freebsd.org> 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 13 unchanged lines hidden (view full) --- 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * Author: Hartmut Brandt <harti@freebsd.org> 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 13 unchanged lines hidden (view full) --- 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/dev/hatm/if_hatm_intr.c 121729 2003-10-30 10:43:52Z harti $"); | 30__FBSDID("$FreeBSD: head/sys/dev/hatm/if_hatm_intr.c 121744 2003-10-30 16:19:50Z harti $"); |
31 32/* 33 * ForeHE driver. 34 * 35 * Interrupt handler. 36 */ 37 38#include "opt_inet.h" --- 47 unchanged lines hidden (view full) --- 86CTASSERT(MBUF0_PER_PAGE <= 256); 87CTASSERT(MBUF1_PER_PAGE <= 256); 88 89static void hatm_mbuf_page_alloc(struct hatm_softc *sc, u_int group); 90 91/* 92 * Free an external mbuf to a list. We use atomic functions so that 93 * we don't need a mutex for the list. | 31 32/* 33 * ForeHE driver. 34 * 35 * Interrupt handler. 36 */ 37 38#include "opt_inet.h" --- 47 unchanged lines hidden (view full) --- 86CTASSERT(MBUF0_PER_PAGE <= 256); 87CTASSERT(MBUF1_PER_PAGE <= 256); 88 89static void hatm_mbuf_page_alloc(struct hatm_softc *sc, u_int group); 90 91/* 92 * Free an external mbuf to a list. We use atomic functions so that 93 * we don't need a mutex for the list. |
94 * 95 * Note that in general this algorithm is not safe when multiple readers 96 * and writers are present. To cite from a mail from David Schultz 97 * <das@freebsd.org>: 98 * 99 * It looks like this is subject to the ABA problem. For instance, 100 * suppose X, Y, and Z are the top things on the freelist and a 101 * thread attempts to make an allocation. You set buf to X and load 102 * buf->link (Y) into a register. Then the thread get preempted, and 103 * another thread allocates both X and Y, then frees X. When the 104 * original thread gets the CPU again, X is still on top of the 105 * freelist, so the atomic operation succeeds. However, the atomic 106 * op places Y on top of the freelist, even though Y is no longer 107 * free. 108 * 109 * We are, however sure that we have only one thread that ever allocates 110 * buffers because the only place we're call from is the interrupt handler. 111 * Under these circumstances the code looks safe. |
|
94 */ 95__inline void 96hatm_ext_free(struct mbufx_free **list, struct mbufx_free *buf) 97{ 98 for (;;) { 99 buf->link = *list; 100 if (atomic_cmpset_ptr(list, buf->link, buf)) 101 break; --- 608 unchanged lines hidden --- | 112 */ 113__inline void 114hatm_ext_free(struct mbufx_free **list, struct mbufx_free *buf) 115{ 116 for (;;) { 117 buf->link = *list; 118 if (atomic_cmpset_ptr(list, buf->link, buf)) 119 break; --- 608 unchanged lines hidden --- |