From fa4bce7c439b266ae77db869afe905e0b7d0e0cf Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Thu, 19 Jun 2008 18:30:49 +0000 Subject: [PATCH] - Make res_timing_pthread allow a max rate of 100/sec instead of 50/sec - change the "timing test" CLI command to let you specify a timing rate to test git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@124023 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/timing.c | 22 +++++++++++++++++++--- res/res_timing_pthread.c | 9 ++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/main/timing.c b/main/timing.c index e6b7c25c3f..5f60232035 100644 --- a/main/timing.c +++ b/main/timing.c @@ -202,17 +202,33 @@ static char *timing_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args * { int fd, count = 0; struct timeval start, end; + unsigned int test_rate = 50; switch (cmd) { case CLI_INIT: e->command = "timing test"; - e->usage = "Usage: timing test\n"; + e->usage = "Usage: timing test \n" + " Test a timer with a specified rate, 100/sec by default.\n" + ""; return NULL; case CLI_GENERATE: return NULL; } - ast_cli(a->fd, "Attempting to test a timer with 50 ticks per second ...\n"); + if (a->argc != 2 && a->argc != 3) { + return CLI_SHOWUSAGE; + } + + if (a->argc == 3) { + unsigned int rate; + if (sscanf(a->argv[2], "%u", &rate) == 1) { + test_rate = rate; + } else { + ast_cli(a->fd, "Invalid rate '%s', using default of %u\n", a->argv[2], test_rate); + } + } + + ast_cli(a->fd, "Attempting to test a timer with %u ticks per second ...\n", test_rate); if ((fd = ast_timer_open()) == -1) { ast_cli(a->fd, "Failed to open timing fd\n"); @@ -221,7 +237,7 @@ static char *timing_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args * start = ast_tvnow(); - ast_timer_set_rate(fd, 50); + ast_timer_set_rate(fd, test_rate); while (ast_tvdiff_ms((end = ast_tvnow()), start) < 1000) { int res; diff --git a/res/res_timing_pthread.c b/res/res_timing_pthread.c index ead2c2d90e..cb6bce4395 100644 --- a/res/res_timing_pthread.c +++ b/res/res_timing_pthread.c @@ -57,9 +57,8 @@ static struct ast_timing_functions pthread_timing_functions = { .timer_get_event = pthread_timer_get_event, }; -/* 1 tick / 20 ms */ -#define TIMING_INTERVAL 20 -#define MAX_RATE 50 +/* 1 tick / 10 ms */ +#define MAX_RATE 100 static struct ao2_container *pthread_timers; #define PTHREAD_TIMER_BUCKETS 563 @@ -412,9 +411,9 @@ static void *do_timing(void *arg) while (!timing_thread.stop) { struct timespec ts = { 0, }; - ao2_callback(pthread_timers, 0, run_timer, NULL); + ao2_callback(pthread_timers, OBJ_NODATA, run_timer, NULL); - next_wakeup = ast_tvadd(next_wakeup, ast_tv(0, 10000)); + next_wakeup = ast_tvadd(next_wakeup, ast_tv(0, 5000)); ts.tv_sec = next_wakeup.tv_sec; ts.tv_nsec = next_wakeup.tv_usec * 1000;