#include "common.h"
#include "bsched.h"
#include "inet.h"
#include "uploads.h"
#include "if/core/wrap.h"
#include "if/gnet_property_priv.h"
#include "lib/glib-missing.h"
#include "lib/walloc.h"
#include "lib/misc.h"
#include "lib/override.h"
Defines | |
#define | BW_SLOT_MIN 64 /**< Minimum bandwidth/slot for realloc */ |
Minimum bandwidth/slot for realloc. | |
#define | BW_OUT_UP_MIN 8192 /**< Minimum out bandwidth for becoming ultra */ |
Minimum out bandwidth for becoming ultra. | |
#define | BW_OUT_GNET_MIN 128 /**< Minimum out bandwidth per Gnet connection */ |
Minimum out bandwidth per Gnet connection. | |
#define | BW_OUT_LEAF_MIN 32 /**< Minimum out bandwidth per leaf connection */ |
Minimum out bandwidth per leaf connection. | |
#define | BW_TCP_MSG 40 /**< Smallest size of a TCP message */ |
Smallest size of a TCP message. | |
#define | BW_UDP_MSG 20 /**< Minimal IP overhead for a UDP message */ |
Minimal IP overhead for a UDP message. | |
#define | BW_UDP_OVERSIZE 512 /**< Allow that many bytes over available b/w */ |
Allow that many bytes over available b/w. | |
Functions | |
RCSID ("$Id:bsched.c, v 1.45 2005/12/11 14:32:10 rmanfredi Exp $") | |
bsched_t * | bsched_make (gchar *name, gint type, guint32 mode, gint bandwidth, gint period) |
Create a new bandwidth scheduler. | |
void | bsched_free (bsched_t *bs) |
Free bandwidth scheduler. | |
void | bsched_add_stealer (bsched_t *bs, bsched_t *stealer) |
Add `stealer' as a bandwidth stealer for underused bandwidth in `bs'. | |
void | bsched_reset_stealers (bsched_t *bs) |
Reset `stealer' list for scheduler. | |
void | bsched_config_steal_http_gnet (void) |
Allow cross-stealing of unused bandwidth between HTTP/gnet. | |
void | bsched_config_steal_gnet (void) |
Allow cross-stealing of unused bandwidth between TCP and UDP gnet only. | |
void | bsched_init (void) |
Initialize global bandwidth schedulers. | |
void | bsched_close (void) |
Discard global bandwidth schedulers. | |
void | bsched_set_peermode (node_peer_t mode) |
Adapt the overall Gnet/HTTP bandwidth repartition depending on the current peermode. | |
void | bsched_enable (bsched_t *bs) |
Enable scheduling, marks the start of the period. | |
void | bsched_disable (bsched_t *bs) |
Disable scheduling. | |
void | bsched_enable_all (void) |
Enable all known bandwidth schedulers. | |
void | bsched_shutdown (void) |
Shutdowning program. | |
void | bio_enable (bio_source_t *bio) |
Enable an I/O source. | |
void | bio_disable (bio_source_t *bio) |
Disable I/O source. | |
void | bio_add_callback (bio_source_t *bio, inputevt_handler_t callback, gpointer arg) |
Add I/O callback to a "passive" I/O source. | |
void | bio_remove_callback (bio_source_t *bio) |
Remove I/O callback from I/O source. | |
void | bsched_no_more_bandwidth (bsched_t *bs) |
Disable all sources and flag that we have no more bandwidth. | |
void | bsched_clear_active (bsched_t *bs) |
Remove activation indication on all the sources. | |
void | bsched_begin_timeslice (bsched_t *bs) |
Called whenever a new scheduling timeslice begins. | |
void | bsched_bio_add (bsched_t *bs, bio_source_t *bio) |
Add new source to the source list of scheduler. | |
void | bsched_bio_remove (bsched_t *bs, bio_source_t *bio) |
Remove source from the source list of scheduler. | |
bio_source_t * | bsched_source_add (bsched_t *bs, wrap_io_t *wio, guint32 flags, inputevt_handler_t callback, gpointer arg) |
Declare fd as a new source for the scheduler. | |
void | bsched_source_remove (bio_source_t *bio) |
Remove bio_source object from the scheduler. | |
void | bsched_set_bandwidth (bsched_t *bs, gint bandwidth) |
On-the-fly changing of the allowed bandwidth. | |
gint | bw_available (bio_source_t *bio, gint len) |
void | bsched_bw_update (bsched_t *bs, gint used, gint requested) |
Update bandwidth used, and scheduler statistics. | |
ssize_t | bio_write (bio_source_t *bio, gconstpointer data, size_t len) |
Write at most `len' bytes from `buf' to source's fd, as bandwidth permits. | |
ssize_t | bio_writev (bio_source_t *bio, struct iovec *iov, gint iovcnt) |
Write at most `len' bytes from `iov' to source's fd, as bandwidth permits, `len' being determined by the size of the supplied I/O vector. | |
ssize_t | bio_sendto (bio_source_t *bio, gnet_host_t *to, gconstpointer data, size_t len) |
Send UDP datagram to specified destination `to'. | |
ssize_t | bio_sendfile (sendfile_ctx_t *ctx, bio_source_t *bio, gint in_fd, off_t *offset, size_t len) |
Write at most `len' bytes to source's fd, as bandwidth permits. | |
ssize_t | bio_read (bio_source_t *bio, gpointer data, size_t len) |
Read at most `len' bytes from `buf' from source's fd, as bandwidth permits. | |
ssize_t | bio_readv (bio_source_t *bio, struct iovec *iov, gint iovcnt) |
Read at most `len' bytes from `iov' to source's fd, as bandwidth permits, `len' being determined by the size of the supplied I/O vector. | |
ssize_t | bws_write (bsched_t *bs, wrap_io_t *wio, gconstpointer data, size_t len) |
Write at most `len' bytes from `buf' to specified fd, and account the bandwidth used. | |
ssize_t | bws_read (bsched_t *bs, wrap_io_t *wio, gpointer data, size_t len) |
Read at most `len' bytes from `buf' from specified fd, and account the bandwidth used. | |
void | bws_udp_count_read (gint len) |
Account for read data from UDP. | |
void | bws_udp_count_written (gint len) |
Account for written data to UDP. | |
bsched_t * | bs_socket (enum socket_direction dir, enum socket_type type) |
Returns adequate b/w shaper depending on the socket type. | |
void | bws_sock_connect (enum socket_type type) |
Record that we're issuing a TCP/IP connection of a particular type. | |
void | bws_sock_connect_failed (enum socket_type type) |
Record that the connection attempt failed. | |
void | bws_sock_connect_timeout (enum socket_type type) |
A connection attempt of `type' timed out. | |
void | bws_sock_connected (enum socket_type type) |
Record that the connection attempt succeeded. | |
void | bws_sock_accepted (enum socket_type type) |
We accepted an incoming connection of `type'. | |
void | bws_sock_closed (enum socket_type type, gboolean remote) |
The connection was closed, remotely if `remote' is true. | |
gboolean | bws_can_connect (enum socket_type type) |
Do we have the bandwidth to issue a new TCP/IP connection of `type'? | |
void | bsched_heartbeat (bsched_t *bs, tm_t *tv) |
Periodic heartbeat. | |
void | bsched_stealbeat (bsched_t *bs) |
Periodic stealing beat, occurs after the heartbeat. | |
void | bsched_timer (void) |
Periodic timer. | |
gboolean | bsched_enough_up_bandwidth (void) |
Needs very short description so that doxygen can parse the following list properly. | |
Variables | |
bws_set | bws = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } |
GSList * | bws_list = NULL |
GSList * | bws_gsteal_list = NULL |
GSList * | bws_out_list = NULL |
GSList * | bws_in_list = NULL |
gint | bws_out_ema = 0 |
gint | bws_in_ema = 0 |
|
Minimum out bandwidth per Gnet connection.
|
|
Minimum out bandwidth per leaf connection.
|
|
Minimum out bandwidth for becoming ultra.
|
|
Minimum bandwidth/slot for realloc.
|
|
Smallest size of a TCP message.
|
|
Minimal IP overhead for a UDP message.
|
|
Allow that many bytes over available b/w.
|
|
Add I/O callback to a "passive" I/O source.
|
|
Disable I/O source. The value of `bw_available' is ignored, as this is a fairly low-level call. If it is called, then the caller has already taken care of redispatching any remaining bandwidth. |
|
Enable an I/O source.
|
|
Read at most `len' bytes from `buf' from source's fd, as bandwidth permits.
|
|
Read at most `len' bytes from `iov' to source's fd, as bandwidth permits, `len' being determined by the size of the supplied I/O vector. If we cannot write anything due to bandwidth constraints, return -1 with errno set to EAGAIN. |
|
Remove I/O callback from I/O source.
|
|
Write at most `len' bytes to source's fd, as bandwidth permits. Bytes are read from `offset' in the in_fd file descriptor, and the value is updated in place by the kernel.
|
|
Send UDP datagram to specified destination `to'.
|
|
Write at most `len' bytes from `buf' to source's fd, as bandwidth permits. If we cannot write anything due to bandwidth constraints, return -1 with errno set to EAGAIN. |
|
Write at most `len' bytes from `iov' to source's fd, as bandwidth permits, `len' being determined by the size of the supplied I/O vector. If we cannot write anything due to bandwidth constraints, return -1 with errno set to EAGAIN. |
|
Returns adequate b/w shaper depending on the socket type.
|
|
Add `stealer' as a bandwidth stealer for underused bandwidth in `bs'. Both must be either reading or writing schedulers. |
|
Called whenever a new scheduling timeslice begins. Re-enable all sources and flag that we have bandwidth. Update the per-source bandwidth statistics. Clears all activation indication on all sources. |
|
Add new source to the source list of scheduler.
|
|
Remove source from the source list of scheduler.
|
|
Update bandwidth used, and scheduler statistics. If no more bandwidth is available, disable all sources.
|
|
Remove activation indication on all the sources.
|
|
Discard global bandwidth schedulers.
|
|
Allow cross-stealing of unused bandwidth between TCP and UDP gnet only.
|
|
Allow cross-stealing of unused bandwidth between HTTP/gnet.
|
|
Disable scheduling.
|
|
Enable scheduling, marks the start of the period.
|
|
Enable all known bandwidth schedulers.
|
|
Needs very short description so that doxygen can parse the following list properly. Determine whether we have enough bandwidth to possibly become an ultra node:
|
|
Free bandwidth scheduler. All sources have their bsched pointer reset to NULL but are not disposed of. Naturally, they cannot be used for I/O any more. |
|
Periodic heartbeat.
|
|
Initialize global bandwidth schedulers.
|
|
Create a new bandwidth scheduler.
|
|
Disable all sources and flag that we have no more bandwidth.
|
|
Reset `stealer' list for scheduler.
|
|
On-the-fly changing of the allowed bandwidth.
|
|
Adapt the overall Gnet/HTTP bandwidth repartition depending on the current peermode. This routine is called each time the peermode changes or each time the settings for the traffic shapers changes. |
|
Shutdowning program. Disable all known bandwidth schedulers, so that any pending I/O can go through as quickly as possible. |
|
Declare fd as a new source for the scheduler. When `callback' is NULL, the source will be "passive", i.e. its bandwidth will be limited when calls to bio_write() or bio_read() are made, but whether the source can accept those calls without blocking will have to be determined explicitly.
|
|
Remove bio_source object from the scheduler. The bio_source object is freed and must not be re-used. |
|
Periodic stealing beat, occurs after the heartbeat.
Note that we do not use the theoric bandwidth, but bs->bw_max to estimate the amount of underused bandwidth. The reason is that bs->bw_max can be corrected due to traffic spikes. |
|
Periodic timer.
|
|
|
|
Do we have the bandwidth to issue a new TCP/IP connection of `type'?
|
|
Read at most `len' bytes from `buf' from specified fd, and account the bandwidth used. Any overused bandwidth will be tracked, so that on average, we stick to the requested bandwidth rate. |
|
We accepted an incoming connection of `type'.
|
|
The connection was closed, remotely if `remote' is true.
|
|
Record that we're issuing a TCP/IP connection of a particular type.
|
|
Record that the connection attempt failed.
|
|
A connection attempt of `type' timed out.
|
|
Record that the connection attempt succeeded.
|
|
Account for read data from UDP.
|
|
Account for written data to UDP.
|
|
Write at most `len' bytes from `buf' to specified fd, and account the bandwidth used. Any overused bandwidth will be tracked, so that on average, we stick to the requested bandwidth rate.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|