From 83d9dfcd5c500494a7aa197c2f0bf4d8a940e6e4 Mon Sep 17 00:00:00 2001 From: Zheng Da Date: Sat, 31 Jul 2010 06:52:07 +0200 Subject: add libbpf. --- libbpf/Makefile | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 libbpf/Makefile (limited to 'libbpf/Makefile') diff --git a/libbpf/Makefile b/libbpf/Makefile new file mode 100644 index 00000000..6e35fd47 --- /dev/null +++ b/libbpf/Makefile @@ -0,0 +1,33 @@ +# +# Copyright (C) 1994,95,96,97,98,99,2000,01,02,2005 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +dir := libbpf +makemode := library + +libname = libbpf +SRCS= bpf_impl.c +LCLHDRS = bpf_impl.h +installhdrs = + +MIGSTUBS = +OBJS = $(sort $(SRCS:.c=.o) $(MIGSTUBS)) + +HURDLIBS = threads + +MIGCOMSFLAGS = + +include ../Makeconf -- cgit v1.2.3 From 4be0911c78f17c5e7ba227dd99fdcbc54c676b5b Mon Sep 17 00:00:00 2001 From: Zheng Da Date: Sat, 31 Jul 2010 09:44:51 +0200 Subject: move queue.c from eth-multiplexer to libbpf. --- eth-multiplexer/Makefile | 6 +- eth-multiplexer/queue.c | 131 ------------------- eth-multiplexer/queue.h | 329 ----------------------------------------------- libbpf/Makefile | 4 +- libbpf/queue.c | 131 +++++++++++++++++++ 5 files changed, 136 insertions(+), 465 deletions(-) delete mode 100644 eth-multiplexer/queue.c delete mode 100644 eth-multiplexer/queue.h create mode 100644 libbpf/queue.c (limited to 'libbpf/Makefile') diff --git a/eth-multiplexer/Makefile b/eth-multiplexer/Makefile index 5e44227b..f321a619 100644 --- a/eth-multiplexer/Makefile +++ b/eth-multiplexer/Makefile @@ -20,14 +20,14 @@ makemode := server target = eth-multiplexer #CFLAGS += -DDEBUG -SRCS = ethernet.c vdev.c multiplexer.c queue.c dev_stat.c netfs_impl.c notify_impl.c device_impl.c demuxer.c +SRCS = ethernet.c vdev.c multiplexer.c dev_stat.c netfs_impl.c notify_impl.c device_impl.c demuxer.c MIGSTUBS = ourdeviceServer.o notifyServer.o OBJS = $(SRCS:.c=.o) $(MIGSTUBS) -LCLHDRS = ethernet.h queue.h util.h vdev.h netfs_impl.h +LCLHDRS = ethernet.h util.h vdev.h netfs_impl.h DIST_FILES = ourdevice.defs notify.defs HURDLIBS=ports fshelp shouldbeinlibc netfs bpf -CFLAGS += -I../libbpf +CFLAGS += -I$(top_srcdir)/libbpf include ../Makeconf diff --git a/eth-multiplexer/queue.c b/eth-multiplexer/queue.c deleted file mode 100644 index a43a21b0..00000000 --- a/eth-multiplexer/queue.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ -/* - * Routines to implement queue package. - */ - -#include "queue.h" - - - -/* - * Insert element at head of queue. - */ -void enqueue_head( - register queue_t que, - register queue_entry_t elt) -{ - elt->next = que->next; - elt->prev = que; - elt->next->prev = elt; - que->next = elt; -} - -/* - * Insert element at tail of queue. - */ -void enqueue_tail( - register queue_t que, - register queue_entry_t elt) -{ - elt->next = que; - elt->prev = que->prev; - elt->prev->next = elt; - que->prev = elt; -} - -/* - * Remove and return element at head of queue. - */ -queue_entry_t dequeue_head( - register queue_t que) -{ - register queue_entry_t elt; - - if (que->next == que) - return((queue_entry_t)0); - - elt = que->next; - elt->next->prev = que; - que->next = elt->next; - return(elt); -} - -/* - * Remove and return element at tail of queue. - */ -queue_entry_t dequeue_tail( - register queue_t que) -{ - register queue_entry_t elt; - - if (que->prev == que) - return((queue_entry_t)0); - - elt = que->prev; - elt->prev->next = que; - que->prev = elt->prev; - return(elt); -} - -/* - * Remove arbitrary element from queue. - * Does not check whether element is on queue - the world - * will go haywire if it isn't. - */ - -/*ARGSUSED*/ -void remqueue( - queue_t que, - register queue_entry_t elt) -{ - elt->next->prev = elt->prev; - elt->prev->next = elt->next; -} - -/* - * Routines to directly imitate the VAX hardware queue - * package. - */ -void insque( - register struct queue_entry *entry, - register struct queue_entry *pred) -{ - entry->next = pred->next; - entry->prev = pred; - (pred->next)->prev = entry; - pred->next = entry; -} - -struct queue_entry -*remque( - register struct queue_entry *elt) -{ - (elt->next)->prev = elt->prev; - (elt->prev)->next = elt->next; - return(elt); -} - diff --git a/eth-multiplexer/queue.h b/eth-multiplexer/queue.h deleted file mode 100644 index f067f557..00000000 --- a/eth-multiplexer/queue.h +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon rights - * to redistribute these changes. - */ -/* - * File: queue.h - * Author: Avadis Tevanian, Jr. - * Date: 1985 - * - * Type definitions for generic queues. - * - */ - -#ifndef _KERN_QUEUE_H_ -#define _KERN_QUEUE_H_ - -/* - * Queue of abstract objects. Queue is maintained - * within that object. - * - * Supports fast removal from within the queue. - * - * How to declare a queue of elements of type "foo_t": - * In the "*foo_t" type, you must have a field of - * type "queue_chain_t" to hold together this queue. - * There may be more than one chain through a - * "foo_t", for use by different queues. - * - * Declare the queue as a "queue_t" type. - * - * Elements of the queue (of type "foo_t", that is) - * are referred to by reference, and cast to type - * "queue_entry_t" within this module. - */ - -/* - * A generic doubly-linked list (queue). - */ - -struct queue_entry { - struct queue_entry *next; /* next element */ - struct queue_entry *prev; /* previous element */ -}; - -typedef struct queue_entry *queue_t; -typedef struct queue_entry queue_head_t; -typedef struct queue_entry queue_chain_t; -typedef struct queue_entry *queue_entry_t; - -/* - * enqueue puts "elt" on the "queue". - * dequeue returns the first element in the "queue". - * remqueue removes the specified "elt" from the specified "queue". - */ - -#define enqueue(queue,elt) enqueue_tail(queue, elt) -#define dequeue(queue) dequeue_head(queue) - -void enqueue_head(queue_t, queue_entry_t); -void enqueue_tail(queue_t, queue_entry_t); -queue_entry_t dequeue_head(queue_t); -queue_entry_t dequeue_tail(queue_t); -void remqueue(queue_t, queue_entry_t); - -/* - * Macro: queue_init - * Function: - * Initialize the given queue. - * Header: - * void queue_init(q) - * queue_t q; *MODIFIED* - */ -#define queue_init(q) ((q)->next = (q)->prev = q) - -/* - * Macro: queue_first - * Function: - * Returns the first entry in the queue, - * Header: - * queue_entry_t queue_first(q) - * queue_t q; *IN* - */ -#define queue_first(q) ((q)->next) - -/* - * Macro: queue_next - * Function: - * Returns the entry after an item in the queue. - * Header: - * queue_entry_t queue_next(qc) - * queue_t qc; - */ -#define queue_next(qc) ((qc)->next) - -/* - * Macro: queue_last - * Function: - * Returns the last entry in the queue. - * Header: - * queue_entry_t queue_last(q) - * queue_t q; *IN* - */ -#define queue_last(q) ((q)->prev) - -/* - * Macro: queue_prev - * Function: - * Returns the entry before an item in the queue. - * Header: - * queue_entry_t queue_prev(qc) - * queue_t qc; - */ -#define queue_prev(qc) ((qc)->prev) - -/* - * Macro: queue_end - * Function: - * Tests whether a new entry is really the end of - * the queue. - * Header: - * boolean_t queue_end(q, qe) - * queue_t q; - * queue_entry_t qe; - */ -#define queue_end(q, qe) ((q) == (qe)) - -/* - * Macro: queue_empty - * Function: - * Tests whether a queue is empty. - * Header: - * boolean_t queue_empty(q) - * queue_t q; - */ -#define queue_empty(q) queue_end((q), queue_first(q)) - - -/*----------------------------------------------------------------*/ -/* - * Macros that operate on generic structures. The queue - * chain may be at any location within the structure, and there - * may be more than one chain. - */ - -/* - * Macro: queue_enter - * Function: - * Insert a new element at the tail of the queue. - * Header: - * void queue_enter(q, elt, type, field) - * queue_t q; - * elt; - * is what's in our queue - * is the chain field in (*) - */ -#define queue_enter(head, elt, type, field) \ -{ \ - register queue_entry_t prev; \ - \ - prev = (head)->prev; \ - if ((head) == prev) { \ - (head)->next = (queue_entry_t) (elt); \ - } \ - else { \ - ((type)prev)->field.next = (queue_entry_t)(elt);\ - } \ - (elt)->field.prev = prev; \ - (elt)->field.next = head; \ - (head)->prev = (queue_entry_t) elt; \ -} - -/* - * Macro: queue_enter_first - * Function: - * Insert a new element at the head of the queue. - * Header: - * void queue_enter_first(q, elt, type, field) - * queue_t q; - * elt; - * is what's in our queue - * is the chain field in (*) - */ -#define queue_enter_first(head, elt, type, field) \ -{ \ - register queue_entry_t next; \ - \ - next = (head)->next; \ - if ((head) == next) { \ - (head)->prev = (queue_entry_t) (elt); \ - } \ - else { \ - ((type)next)->field.prev = (queue_entry_t)(elt);\ - } \ - (elt)->field.next = next; \ - (elt)->field.prev = head; \ - (head)->next = (queue_entry_t) elt; \ -} - -/* - * Macro: queue_field [internal use only] - * Function: - * Find the queue_chain_t (or queue_t) for the - * given element (thing) in the given queue (head) - */ -#define queue_field(head, thing, type, field) \ - (((head) == (thing)) ? (head) : &((type)(thing))->field) - -/* - * Macro: queue_remove - * Function: - * Remove an arbitrary item from the queue. - * Header: - * void queue_remove(q, qe, type, field) - * arguments as in queue_enter - */ -#define queue_remove(head, elt, type, field) \ -{ \ - register queue_entry_t next, prev; \ - \ - next = (elt)->field.next; \ - prev = (elt)->field.prev; \ - \ - if ((head) == next) \ - (head)->prev = prev; \ - else \ - ((type)next)->field.prev = prev; \ - \ - if ((head) == prev) \ - (head)->next = next; \ - else \ - ((type)prev)->field.next = next; \ -} - -/* - * Macro: queue_remove_first - * Function: - * Remove and return the entry at the head of - * the queue. - * Header: - * queue_remove_first(head, entry, type, field) - * entry is returned by reference - */ -#define queue_remove_first(head, entry, type, field) \ -{ \ - register queue_entry_t next; \ - \ - (entry) = (type) ((head)->next); \ - next = (entry)->field.next; \ - \ - if ((head) == next) \ - (head)->prev = (head); \ - else \ - ((type)(next))->field.prev = (head); \ - (head)->next = next; \ -} - -/* - * Macro: queue_remove_last - * Function: - * Remove and return the entry at the tail of - * the queue. - * Header: - * queue_remove_last(head, entry, type, field) - * entry is returned by reference - */ -#define queue_remove_last(head, entry, type, field) \ -{ \ - register queue_entry_t prev; \ - \ - (entry) = (type) ((head)->prev); \ - prev = (entry)->field.prev; \ - \ - if ((head) == prev) \ - (head)->next = (head); \ - else \ - ((type)(prev))->field.next = (head); \ - (head)->prev = prev; \ -} - -/* - * Macro: queue_assign - */ -#define queue_assign(to, from, type, field) \ -{ \ - ((type)((from)->prev))->field.next = (to); \ - ((type)((from)->next))->field.prev = (to); \ - *to = *from; \ -} - -/* - * Macro: queue_iterate - * Function: - * iterate over each item in the queue. - * Generates a 'for' loop, setting elt to - * each item in turn (by reference). - * Header: - * queue_iterate(q, elt, type, field) - * queue_t q; - * elt; - * is what's in our queue - * is the chain field in (*) - */ -#define queue_iterate(head, elt, type, field) \ - for ((elt) = (type) queue_first(head); \ - !queue_end((head), (queue_entry_t)(elt)); \ - (elt) = (type) queue_next(&(elt)->field)) - -#endif /* _KERN_QUEUE_H_ */ diff --git a/libbpf/Makefile b/libbpf/Makefile index 6e35fd47..5ce87573 100644 --- a/libbpf/Makefile +++ b/libbpf/Makefile @@ -19,8 +19,8 @@ dir := libbpf makemode := library libname = libbpf -SRCS= bpf_impl.c -LCLHDRS = bpf_impl.h +SRCS= bpf_impl.c queue.c +LCLHDRS = bpf_impl.h queue.h installhdrs = MIGSTUBS = diff --git a/libbpf/queue.c b/libbpf/queue.c new file mode 100644 index 00000000..a43a21b0 --- /dev/null +++ b/libbpf/queue.c @@ -0,0 +1,131 @@ +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ +/* + * Routines to implement queue package. + */ + +#include "queue.h" + + + +/* + * Insert element at head of queue. + */ +void enqueue_head( + register queue_t que, + register queue_entry_t elt) +{ + elt->next = que->next; + elt->prev = que; + elt->next->prev = elt; + que->next = elt; +} + +/* + * Insert element at tail of queue. + */ +void enqueue_tail( + register queue_t que, + register queue_entry_t elt) +{ + elt->next = que; + elt->prev = que->prev; + elt->prev->next = elt; + que->prev = elt; +} + +/* + * Remove and return element at head of queue. + */ +queue_entry_t dequeue_head( + register queue_t que) +{ + register queue_entry_t elt; + + if (que->next == que) + return((queue_entry_t)0); + + elt = que->next; + elt->next->prev = que; + que->next = elt->next; + return(elt); +} + +/* + * Remove and return element at tail of queue. + */ +queue_entry_t dequeue_tail( + register queue_t que) +{ + register queue_entry_t elt; + + if (que->prev == que) + return((queue_entry_t)0); + + elt = que->prev; + elt->prev->next = que; + que->prev = elt->prev; + return(elt); +} + +/* + * Remove arbitrary element from queue. + * Does not check whether element is on queue - the world + * will go haywire if it isn't. + */ + +/*ARGSUSED*/ +void remqueue( + queue_t que, + register queue_entry_t elt) +{ + elt->next->prev = elt->prev; + elt->prev->next = elt->next; +} + +/* + * Routines to directly imitate the VAX hardware queue + * package. + */ +void insque( + register struct queue_entry *entry, + register struct queue_entry *pred) +{ + entry->next = pred->next; + entry->prev = pred; + (pred->next)->prev = entry; + pred->next = entry; +} + +struct queue_entry +*remque( + register struct queue_entry *elt) +{ + (elt->next)->prev = elt->prev; + (elt->prev)->next = elt->next; + return(elt); +} + -- cgit v1.2.3