From 63706a839fe30d9e3fa9315bc5b75b1f1c5f8239 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 21 Mar 2011 14:25:20 -0400 Subject: [PATCH] freetdm: add support for setting the channel tx/rx queue size from config file (wanpipe.conf) and from CLI --- libs/freetdm/conf/wanpipe.conf | 9 ++++ libs/freetdm/mod_freetdm/mod_freetdm.c | 49 ++++++++++++++++++- .../src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 26 ++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/conf/wanpipe.conf b/libs/freetdm/conf/wanpipe.conf index ba609ac42e..3784eaf17a 100644 --- a/libs/freetdm/conf/wanpipe.conf +++ b/libs/freetdm/conf/wanpipe.conf @@ -1,4 +1,13 @@ [defaults] +; User space interval at which data will be delivered codec_ms => 20 + +; wink and flash interval wink_ms => 150 flash_ms => 750 + +; size of the driver queue of elements of MTU size +; typical case is 10 elements of 80 bytes each (10ms of ulaw/alaw) +; don't mess with this if you don't know what you're doing +; txqueue_size => 10 +; rxqueue_size => 10 diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index c230e186ee..442707ebc2 100755 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -3621,8 +3621,9 @@ void dump_chan_xml(ftdm_span_t *span, uint32_t chan_id, switch_stream_handle_t * "ftdm trace []\n" \ "ftdm notrace []\n" \ "ftdm q931_pcap on|off [pcapfilename without suffix]\n" \ -"ftdm gains []\n" \ +"ftdm gains []\n" \ "ftdm dtmf on|off []\n" \ +"ftdm queuesize []\n" \ "--------------------------------------------------------------------------------\n" SWITCH_STANDARD_API(ft_function) { @@ -4059,7 +4060,7 @@ SWITCH_STANDARD_API(ft_function) ftdm_channel_t *chan; ftdm_span_t *span = NULL; if (argc < 4) { - stream->write_function(stream, "-ERR Usage: ft gains []\n"); + stream->write_function(stream, "-ERR Usage: ftdm gains []\n"); goto end; } ftdm_span_find_by_name(argv[3], &span); @@ -4094,6 +4095,50 @@ SWITCH_STANDARD_API(ft_function) } } stream->write_function(stream, "+OK gains set to Rx %f and Tx %f\n", rxgain, txgain); + } else if (!strcasecmp(argv[0], "queuesize")) { + unsigned int i = 0; + uint32_t rxsize = 10; + uint32_t txsize = 10; + uint32_t chan_id = 0; + uint32_t ccount = 0; + ftdm_channel_t *chan; + ftdm_span_t *span = NULL; + if (argc < 4) { + stream->write_function(stream, "-ERR Usage: ftdm queuesize []\n"); + goto end; + } + ftdm_span_find_by_name(argv[3], &span); + if (!span) { + stream->write_function(stream, "-ERR invalid span\n"); + goto end; + } + if (argc > 4) { + chan_id = atoi(argv[4]); + if (chan_id > ftdm_span_get_chan_count(span)) { + stream->write_function(stream, "-ERR invalid chan\n"); + goto end; + } + } + i = sscanf(argv[1], "%u", &rxsize); + i += sscanf(argv[2], "%u", &txsize); + if (i != 2) { + stream->write_function(stream, "-ERR invalid queue sizes provided\n"); + goto end; + } + + if (chan_id) { + chan = ftdm_span_get_channel(span, chan_id); + ftdm_channel_command(chan, FTDM_COMMAND_SET_RX_QUEUE_SIZE, &rxsize); + ftdm_channel_command(chan, FTDM_COMMAND_SET_TX_QUEUE_SIZE, &txsize); + } else { + ccount = ftdm_span_get_chan_count(span); + for (i = 1; i < ccount; i++) { + chan = ftdm_span_get_channel(span, i); + ftdm_channel_command(chan, FTDM_COMMAND_SET_RX_QUEUE_SIZE, &rxsize); + ftdm_channel_command(chan, FTDM_COMMAND_SET_TX_QUEUE_SIZE, &txsize); + } + } + stream->write_function(stream, "+OK queue sizes set to Rx %d and Tx %d\n", rxsize, txsize); } else if (!strcasecmp(argv[0], "restart")) { uint32_t chan_id = 0; ftdm_channel_t *chan; diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index feea128eb7..20a173abb2 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -91,6 +91,8 @@ typedef enum { */ static struct { uint32_t codec_ms; + uint32_t rxqueue_size; + uint32_t txqueue_size; uint32_t wink_ms; uint32_t flash_ms; uint32_t ring_on_ms; @@ -406,6 +408,20 @@ static FIO_CONFIGURE_FUNCTION(wanpipe_configure) } else { wp_globals.codec_ms = num; } + } else if (!strcasecmp(var, "rxqueue_size")) { + num = atoi(val); + if (num < 1 || num > 1000) { + ftdm_log(FTDM_LOG_WARNING, "invalid rx queue size at line %d\n", lineno); + } else { + wp_globals.rxqueue_size = num; + } + } else if (!strcasecmp(var, "txqueue_size")) { + num = atoi(val); + if (num < 1 || num > 1000) { + ftdm_log(FTDM_LOG_WARNING, "invalid tx queue size at line %d\n", lineno); + } else { + wp_globals.txqueue_size = num; + } } else if (!strcasecmp(var, "wink_ms")) { num = atoi(val); if (num < 50 || num > 3000) { @@ -544,6 +560,13 @@ static FIO_OPEN_FUNCTION(wanpipe_open) ftdm_channel_set_feature(ftdmchan, FTDM_CHANNEL_FEATURE_INTERVAL); ftdmchan->effective_interval = ftdmchan->native_interval = wp_globals.codec_ms; ftdmchan->packet_len = ftdmchan->native_interval * 8; + + if (wp_globals.txqueue_size > 0) { + ftdm_channel_command(ftdmchan, FTDM_COMMAND_SET_TX_QUEUE_SIZE, &wp_globals.txqueue_size); + } + if (wp_globals.rxqueue_size > 0) { + ftdm_channel_command(ftdmchan, FTDM_COMMAND_SET_RX_QUEUE_SIZE, &wp_globals.rxqueue_size); + } } return FTDM_SUCCESS; @@ -1573,6 +1596,9 @@ static FIO_IO_LOAD_FUNCTION(wanpipe_init) wp_globals.flash_ms = 750; wp_globals.ring_on_ms = 2000; wp_globals.ring_off_ms = 4000; + /* 0 for queue size will leave driver defaults */ + wp_globals.txqueue_size = 0; + wp_globals.rxqueue_size = 0; wanpipe_interface.name = "wanpipe"; wanpipe_interface.configure_span = wanpipe_configure_span; wanpipe_interface.configure = wanpipe_configure;