From 362b77d3ae9a9ec208086fc014e90158bc1bc22a Mon Sep 17 00:00:00 2001 From: tzafrir Date: Sat, 22 Sep 2007 20:51:33 +0000 Subject: Backport support for high-resolution timers from 1.4. Allows 2.6.22 Fedoras to build again. git-svn-id: http://svn.digium.com/svn/zaptel/branches/1.2@3083 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- ztdummy.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'ztdummy.c') diff --git a/ztdummy.c b/ztdummy.c index e4f0952..8a56f60 100644 --- a/ztdummy.c +++ b/ztdummy.c @@ -8,6 +8,8 @@ * Unified by Mark Spencer * Converted to use RTC on i386 by Tony Mountifield * + * Converted to use HighResTimers on i386 by Jeffery Palmer + * * Copyright (C) 2002, Hermes Softlab * Copyright (C) 2004, Digium, Inc. * @@ -28,6 +30,14 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ + +/* + * To use the high resolution timers, in your kernel CONFIG_HIGH_RES_TIMERS + * needs to be enabled (Processor type and features -> High Resolution + * Timer Support), and optionally HPET (Processor type and features -> + * HPET Timer Support) provides a better clock source. + */ + #include #ifndef VERSION_CODE @@ -46,7 +56,12 @@ */ #if defined(__i386__) || defined(__x86_64__) #if LINUX_VERSION_CODE >= VERSION_CODE(2,6,13) +/* The symbol hrtimer_forward is only exported as of 2.6.22: */ +#if defined(CONFIG_HIGH_RES_TIMERS) && LINUX_VERSION_CODE >= VERSION_CODE(2,6,22) +#define USE_HIGHRESTIMER +#else #define USE_RTC +#endif #else #if 0 #define USE_RTC @@ -70,6 +85,9 @@ #include #endif #ifdef LINUX26 +#ifdef USE_HIGHRESTIMER +#include +#endif #ifdef USE_RTC #include #endif @@ -96,8 +114,14 @@ static struct ztdummy *ztd; static int debug = 0; #ifdef LINUX26 -#ifndef USE_RTC -/* New 2.6 kernel timer stuff */ +#ifdef USE_HIGHRESTIMER +#define CLOCK_SRC "HRtimer" +struct hrtimer zaptimer; +#elif defined(USE_RTC) +#define CLOCK_SRC "RTC" +#else /* Linux 2.6, but no RTC or HRTIMER used */ +#define CLOCK_SRC "Linux26" +/* 2.6 kernel timer stuff */ static struct timer_list timer; #if HZ != 1000 #warning This module will not be usable since the kernel HZ setting is not 1000 ticks per second. @@ -107,6 +131,7 @@ static struct timer_list timer; #if LINUX_VERSION_CODE < VERSION_CODE(2,4,5) # error "This kernel is too old: not supported by this file" #endif +#define CLOCK_SRC "UHCI" /* Old UCHI stuff */ static uhci_desc_t *td; static uhci_t *s; @@ -126,6 +151,15 @@ extern uhci_t **uhci_devices; #endif +#define ZAPTEL_RATE 1000 /* zaptel ticks per second */ +#define ZAPTEL_TIME (1000000 / ZAPTEL_RATE) /* zaptel tick time in us */ +#define ZAPTEL_TIME_NS (ZAPTEL_TIME * 1000) /* zaptel tick time in ns */ + +/* Different bits of the debug variable: */ +#define DEBUG_GENERAL (1 << 0) +#define DEBUG_TICKS (1 << 1) + + #ifdef LINUX26 #ifdef USE_RTC /* rtc_interrupt - called at 1024Hz from hook in RTC handler */ @@ -180,7 +214,7 @@ static int ztdummy_initialize(struct ztdummy *ztd) { /* Zapata stuff */ sprintf(ztd->span.name, "ZTDUMMY/1"); - sprintf(ztd->span.desc, "%s %d", ztd->span.name, 1); + sprintf(ztd->span.desc, "%s (source: " CLOCK_SRC ") %d", ztd->span.name, 1); sprintf(ztd->chan.name, "ZTDUMMY/%d/%d", 1, 0); ztd->chan.chanpos = 1; ztd->span.chans = &ztd->chan; @@ -220,12 +254,12 @@ int init_module(void) } #endif -#if defined(LINUX26) && !defined(USE_RTC) +#if defined(LINUX26) && !defined(USE_RTC) && !defined(USE_HIGHRESTIMER) if (HZ != 1000) { printk("ztdummy: This module requires the kernel HZ setting to be 1000 ticks per second\n"); return -ENODEV; } -#endif /* defined(LINUX26) && !defined(USE_RTC) */ +#endif /* defined(LINUX26) && !defined(USE_RTC) && !defined(USE_HIGHRESTIMER)*/ ztd = kmalloc(sizeof(struct ztdummy), GFP_KERNEL); if (ztd == NULL) { -- cgit v1.2.3