Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

bsched.h File Reference


Detailed Description

Bandwidth scheduling.

Author:
Raphael Manfredi
Date:
2002-2003

#include "sockets.h"
#include "lib/inputevt.h"
#include "lib/tm.h"
#include "if/core/hosts.h"
#include "if/core/nodes.h"
#include "if/core/bsched.h"

Go to the source code of this file.

Data Structures

struct  bsched
 Bandwidth scheduler. More...

struct  bws_set
 Global bandwidth schedulers. More...

struct  sendfile_ctx

Defines

#define BS_T_STREAM   1 /**< Streaming */
 Streaming.

#define BS_T_RANDOM   2 /**< Random (unsupported) */
 Random (unsupported).

#define BS_F_ENABLED   0x00000001 /**< Scheduler enabled */
 Scheduler enabled.

#define BS_F_READ   0x00000002 /**< Reading sources */
 Reading sources.

#define BS_F_WRITE   0x00000004 /**< Writing sources */
 Writing sources.

#define BS_F_NOBW   0x00000008 /**< No more bandwidth */
 No more bandwidth.

#define BS_F_FROZEN_SLOT   0x00000010 /**< Value of `bw_slot' is frozen */
 Value of `bw_slot' is frozen.

#define BS_F_CHANGED_BW   0x00000020 /**< Bandwidth limit changed */
 Bandwidth limit changed.

#define BS_F_CLEARED   0x00000040 /**< Ran clear_active once on sched. */
 Ran clear_active once on sched.

#define BS_F_DATA_READ   0x00000080 /**< Data read from one source */
 Data read from one source.

#define BS_F_RW   (BS_F_READ|BS_F_WRITE)
#define bsched_bps(b)   ((b)->bw_last_period * 1000 / (b)->period)
#define bsched_pct(b)   (bsched_bps(b) * 100 / (1+(b)->bw_per_second))
#define bsched_avg_bps(b)   ((b)->bw_ema * 1000 / (b)->period)
#define bsched_avg_pct(b)   (bsched_avg_bps(b) * 100 / (1+(b)->bw_per_second))
#define bsched_bwps(b)   ((b)->bw_per_second)
#define bsched_saturated(b)   ((b)->bw_actual > (b)->bw_max)
#define bsched_enabled(b)   ((b)->flags & BS_F_ENABLED)

Typedefs

typedef sendfile_ctx sendfile_ctx_t

Functions

bsched_tbsched_make (gchar *name, gint type, guint32 mode, gint bandwidth, gint period)
 Create a new bandwidth scheduler.

void bsched_init (void)
 Initialize global bandwidth schedulers.

void bsched_shutdown (void)
 Shutdowning program.

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.

bio_source_tbsched_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.

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.

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 bsched_timer (void)
 Periodic timer.

void bws_sock_connect (enum socket_type type)
 Record that we're issuing a TCP/IP connection of a particular type.

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_connect_timeout (enum socket_type type)
 A connection attempt of `type' timed out.

void bws_sock_connect_failed (enum socket_type type)
 Record that the connection attempt failed.

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 bws_udp_count_written (gint len)
 Account for written data to UDP.

void bws_udp_count_read (gint len)
 Account for read data from UDP.

gboolean bsched_enough_up_bandwidth (void)
 Needs very short description so that doxygen can parse the following list properly.

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.


Variables

bws_set bws


Define Documentation

#define BS_F_CHANGED_BW   0x00000020 /**< Bandwidth limit changed */
 

Bandwidth limit changed.

#define BS_F_CLEARED   0x00000040 /**< Ran clear_active once on sched. */
 

Ran clear_active once on sched.

#define BS_F_DATA_READ   0x00000080 /**< Data read from one source */
 

Data read from one source.

#define BS_F_ENABLED   0x00000001 /**< Scheduler enabled */
 

Scheduler enabled.

#define BS_F_FROZEN_SLOT   0x00000010 /**< Value of `bw_slot' is frozen */
 

Value of `bw_slot' is frozen.

#define BS_F_NOBW   0x00000008 /**< No more bandwidth */
 

No more bandwidth.

#define BS_F_READ   0x00000002 /**< Reading sources */
 

Reading sources.

#define BS_F_RW   (BS_F_READ|BS_F_WRITE)
 

#define BS_F_WRITE   0x00000004 /**< Writing sources */
 

Writing sources.

#define BS_T_RANDOM   2 /**< Random (unsupported) */
 

Random (unsupported).

#define BS_T_STREAM   1 /**< Streaming */
 

Streaming.

#define bsched_avg_bps  )     ((b)->bw_ema * 1000 / (b)->period)
 

#define bsched_avg_pct  )     (bsched_avg_bps(b) * 100 / (1+(b)->bw_per_second))
 

#define bsched_bps  )     ((b)->bw_last_period * 1000 / (b)->period)
 

#define bsched_bwps  )     ((b)->bw_per_second)
 

#define bsched_enabled  )     ((b)->flags & BS_F_ENABLED)
 

#define bsched_pct  )     (bsched_bps(b) * 100 / (1+(b)->bw_per_second))
 

#define bsched_saturated  )     ((b)->bw_actual > (b)->bw_max)
 


Typedef Documentation

typedef struct sendfile_ctx sendfile_ctx_t
 


Function Documentation

void bio_add_callback bio_source_t bio,
inputevt_handler_t  callback,
gpointer  arg
 

Add I/O callback to a "passive" I/O source.

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.

Returns:
-1 with errno set to EAGAIN, if we cannot read anything due to bandwidth constraints.

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.

If we cannot write anything due to bandwidth constraints, return -1 with errno set to EAGAIN.

void bio_remove_callback bio_source_t bio  ) 
 

Remove I/O callback from I/O source.

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.

Bytes are read from `offset' in the in_fd file descriptor, and the value is updated in place by the kernel.

Returns:
-1 with errno set to EAGAIN, if we cannot write anything due to bandwidth constraints.

ssize_t bio_sendto bio_source_t bio,
gnet_host_t to,
gconstpointer  data,
size_t  len
 

Send UDP datagram to specified destination `to'.

Returns:
-1 with errno set to EAGAIN, if we cannot write anything due to bandwidth constraints.

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.

If we cannot write anything due to bandwidth constraints, return -1 with errno set to EAGAIN.

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.

If we cannot write anything due to bandwidth constraints, return -1 with errno set to EAGAIN.

void bsched_close void   ) 
 

Discard global bandwidth schedulers.

void bsched_config_steal_gnet void   ) 
 

Allow cross-stealing of unused bandwidth between TCP and UDP gnet only.

void bsched_config_steal_http_gnet void   ) 
 

Allow cross-stealing of unused bandwidth between HTTP/gnet.

void bsched_disable bsched_t bs  ) 
 

Disable scheduling.

void bsched_enable bsched_t bs  ) 
 

Enable scheduling, marks the start of the period.

void bsched_enable_all void   ) 
 

Enable all known bandwidth schedulers.

gboolean bsched_enough_up_bandwidth void   ) 
 

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:

  1. There must be more than BW_OUT_UP_MIN outgoing bandwidth available.
  2. If bandwidth schedulers are enabled, leaf nodes must not be configured to steal all the HTTP outgoing bandwidth, unless they disabled uploads.
  3. If Gnet out scheduler is enabled, there must be at least BW_OUT_GNET_MIN bytes per gnet connection.
  4. Overall, there must be BW_OUT_LEAF_MIN bytes per configured leaf plus BW_OUT_GNET_MIN bytes per gnet connection available.

void bsched_init void   ) 
 

Initialize global bandwidth schedulers.

bsched_t* bsched_make gchar *  name,
gint  type,
guint32  mode,
gint  bandwidth,
gint  period
 

Create a new bandwidth scheduler.

Parameters:
`name' no brief description.
`type' refers to the scheduling model. Only BS_T_STREAM for now.
`mode' refers to the nature of the sources: either reading or writing.
`bandwidth' is the expected bandwidth in bytes per second.
`period' is the scheduling period in ms.

void bsched_set_bandwidth bsched_t bs,
gint  bandwidth
 

On-the-fly changing of the allowed bandwidth.

void bsched_set_peermode node_peer_t  mode  ) 
 

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.

void bsched_shutdown void   ) 
 

Shutdowning program.

Disable all known bandwidth schedulers, so that any pending I/O can go through as quickly as possible.

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.

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.

Returns:
new bio_source object.

void bsched_source_remove bio_source_t bio  ) 
 

Remove bio_source object from the scheduler.

The bio_source object is freed and must not be re-used.

void bsched_timer void   ) 
 

Periodic timer.

gboolean bws_can_connect enum socket_type  type  ) 
 

Do we have the bandwidth to issue a new TCP/IP connection of `type'?

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.

Any overused bandwidth will be tracked, so that on average, we stick to the requested bandwidth rate.

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.

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_udp_count_read gint  len  ) 
 

Account for read data from UDP.

void bws_udp_count_written gint  len  ) 
 

Account for written data to UDP.

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.

Any overused bandwidth will be tracked, so that on average, we stick to the requested bandwidth rate.

Returns:
The amount of bytes written or (-1) if an error occurred.


Variable Documentation

struct bws_set bws
 


Generated on Sun Feb 12 10:49:59 2006 for Gtk-Gnutella by doxygen 1.3.6