From owner-svn-src-user@FreeBSD.ORG Thu Jan 7 20:40:39 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1B2101065676; Thu, 7 Jan 2010 20:40:39 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 092448FC17; Thu, 7 Jan 2010 20:40:39 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o07KecFa059748; Thu, 7 Jan 2010 20:40:38 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o07KecHW059746; Thu, 7 Jan 2010 20:40:38 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <201001072040.o07KecHW059746@svn.freebsd.org> From: Luigi Rizzo Date: Thu, 7 Jan 2010 20:40:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r201757 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jan 2010 20:40:39 -0000 Author: luigi Date: Thu Jan 7 20:40:38 2010 New Revision: 201757 URL: http://svn.freebsd.org/changeset/base/201757 Log: add header to implement schedulers Added: user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched.h (contents, props changed) Added: user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/dn_sched.h Thu Jan 7 20:40:38 2010 (r201757) @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2010 Riccardo Panicucci, Universita` di Pisa + * Copyright (c) 1998-2002,2010 Luigi Rizzo, Universita` di Pisa + * All rights reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * The API to write a packet scheduling algorithm for dummynet. + */ + +#ifndef _DN_SCHED_H +#define _DN_SCHED_H + +// MALLOC_DECLARE(M_DUMMYNET); + +/* + * Descriptor for the scheduler. + * Contains all function pointers for a given scheduler + * This is typically created when a module is loaded, and stored + * in a global list of schedulers. + */ +struct dn_sched { + int type; /* the scheduler type */ + const char *name; /* scheduler name */ + int ref_count; /* number of instances in the system */ + + /* + * The following define the size of 4 optional data structures + * that may need to be allocated at runtime: + */ + + /* + parameters attached to the template, e.g. + * default queue sizes, weights, quantum size, and so on; + */ + size_t scheduler_size; // sch_arg + + /* + per-instance parameters, such as timestamps, + * ccontainers for queues, etc; + */ + size_t scheduler_i_size; // sch_runtime + + /* + per-flowset parameters, such as individual weights, + * priorities, queue limits, slot sizes... + */ + size_t flowset_size; // fs_arg + + /* + per-queue parameters (what for ?) + */ + size_t queue_size; // queue_arg + + SLIST_ENTRY(dn_sched) next; /* Next scheduler in the list */ + + /* + * Methods implemented by the scheduler: + * enqueue enqueue packet 'm' on scheduler 's'. 'id' is + * the flow id of the packet, 'f' contains + * flowset-specific data. Must returns 1 if the packet + * is NOT enqueued. + * + * dequeue Called when scheduler instance 's' can + * dequeue a packet. Return NULL if none are available. + * XXX what about non work-conserving ? + * + * config called on 'sched X config ...' + * updates the field sch_arg + * + * destroy called on 'sched delete', frees everything + * in sch_arg (other parts are handled by more specific + * functions) + * + * new_sched called when a new instance is + * created by find_scheduler. + * Updates sch_runtime + * + * free_sched called when deleting an instance + * cleans everything linked to sch_runtime + * + * new_fs called on 'queue XX config', create fs_arg + * if the reconfigure flag is set, it means that + * the fs_arg already exists and need to be update + * + * free_fs called on 'queue XX delete', frees things in + * fs_arg. Also called on a 'queue XX config' if the + * scheduler is different from what was previously. + * + * new_queue called to link a new queue to sch_runtime + * can be used to set queue variables e.g. virtual times, + * update sum of weights, etc. + * + * free_queue called to unlink a queue from sch_runtime + * possibly update sum of weights, etc. + * + * drain_queue called to free all idle queues, or possibly all of + * them (this is a subset of delete_scheduler_instance) + */ + int (*enqueue)(void *s, struct gen *f, struct mbuf *m, + struct ipfw_flow_id *id); + struct mbuf * (*dequeue)(void *s); + + int (*config)(char *command, void *sch, int reconfigure); + int (*destroy)(void* sch); + int (*new_sched)(void *v); + int (*free_sched)(void *s); + + int (*new_fs)(char *command, struct gen *g, int reconfigure); + int (*free_fs)(struct gen *f); + + int (*new_queue)(struct new_queue *q, struct gen *f); + int (*free_queue)(struct new_queue *q); + + int (*drain_queue)(void *s, int flag); +}; +SLIST_HEAD(scheduler_head, dn_sched); + +/* + * Additionally, dummynet exports some variables, functions and macros + * to be used by schedulers. + */ + +/* + * You must call dn_pkt_done() when extracting packets from a queue. + * The function is used to update packet and queue statistics. + * - pkt: packet to return; + * - q: packet belongs to this queue + */ +struct mbuf* dn_pkt_done(struct mbuf *pkt, struct new_queue *q); + +/* Called to delete a queue 'q'. If packet belong to this queue should be + * reenqueued, the 'reenqueue' should be set to 1 + */ +int dn_delete_queue (struct new_queue *q, int reenqueue); + +/* Called by enqueue() when it needs to create a new queue. + * - f: extension of the flowset. + * - s: scheduler specific scheduler instance data + * - i: index of the hash table, or 0 if no hash table is used + * - id: flow id for this queue + * - size: size of the queue, including the private data + */ +struct new_queue * dn_create_queue(struct gen *f, void *s, int i, + struct ipfw_flow_id *id); + +/* Allocate an hash table. + * Returns the pointer to the table + * - rq_size: the returned size of table + * - rq_elements: the number of elements present in the table + * - bucket: the desidered size of the table + */ +struct new_queue ** dn_alloc_hash_queue(int *rq_size, int *rq_elements, + int bucket); + +/* Delete all packets from queue 'q' */ +int dn_purge_queue(struct new_queue *q); + +/* Really enqueue the packet 'm' into queue 'q'. + * If the packet is dropped, the function returns 1 + */ +int dn_queue_packet(struct new_queue *q, struct mbuf* m); + +/* Drop a packet 'm' that belong to queue 'q' + * NOTE: q should be NULL if the queue doesn't exist + */ +int dn_drop_packet(struct new_queue *q, struct mbuf* m); + +/* Returns the index of array of hash table. + * The hash is done using flowset pointer and the flow id of the packet. + * - id: flow id + * - f: pointer to the flowset (private data) + * - rq_size: size of the hash table + */ +int dn_i_hash_id(struct ipfw_flow_id *id, struct gen *f, int rq_size); + +/* Returns the queue that match the flowid at the index i, if exists. + * Returns NULL if the queue doesn't exist. + * - id: flow id of the packet + * - i: index of the hash table + * - rq: pointer to the hash table + * - f: pointer to flowset scheduler specific data. Used to access to + * the flowset generic data + */ +struct new_queue * dn_q_hash_id(struct ipfw_flow_id *id, int i, + struct new_queue **rq, struct gen *f); + +int dn_sched_modevent(module_t mod, int cmd, void *arg); + +#define DECLARE_DNSCHED_MODULE(name, dnsched) \ + static moduledata_t name##_mod = { \ + #name, dn_sched_modevent, dnsched \ + }; \ + DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, \ + SI_ORDER_MIDDLE); \ + MODULE_DEPEND(name, dummynet, 3, 3, 3); + +#endif /* _DN_SCHED_H */