kernel/x86: Fix and modernize tracing of timer code; no functional change

* Fixes functionality of TRACE statements on 64-bit platforms.

Change-Id: Iaba8f8b2d49ec1acda3fc2d51e24a207c5bcc97a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4992
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>
Reviewed-by: Fredrik Holmqvist <fredrik.holmqvist@gmail.com>
This commit is contained in:
Alexander von Gluck IV 2022-02-24 10:53:44 -06:00 committed by Alex von Gluck IV
parent 0fea9fec6f
commit f1b2d3ba95
5 changed files with 45 additions and 23 deletions

View File

@ -27,11 +27,12 @@
//#define TRACE_TIMER
#ifdef TRACE_TIMER
# define TRACE(x) dprintf x
# define TRACE(x...) dprintf("arch_timer: " x)
#else
# define TRACE(x) ;
# define TRACE(x...) ;
#endif
extern timer_info gPITTimer;
extern timer_info gAPICTimer;
extern timer_info gHPETTimer;
@ -48,7 +49,7 @@ static timer_info *sTimer = NULL;
void
arch_timer_set_hardware_timer(bigtime_t timeout)
{
TRACE(("arch_timer_set_hardware_timer: timeout %lld\n", timeout));
TRACE("arch_timer_set_hardware_timer: timeout %" B_PRIdBIGTIME "\n", timeout);
sTimer->set_hardware_timer(timeout);
}
@ -56,7 +57,7 @@ arch_timer_set_hardware_timer(bigtime_t timeout)
void
arch_timer_clear_hardware_timer(void)
{
TRACE(("arch_timer_clear_hardware_timer\n"));
TRACE("arch_timer_clear_hardware_timer\n");
sTimer->clear_hardware_timer();
}
@ -65,10 +66,10 @@ static void
sort_timers(timer_info *timers[], int numTimers)
{
timer_info *tempPtr;
int max = 0;
int max = 0;
int i = 0;
int j = 0;
for (i = 0; i < numTimers - 1; i++) {
max = i;
for (j = i + 1; j < numTimers; j++) {
@ -78,10 +79,10 @@ sort_timers(timer_info *timers[], int numTimers)
if (max != i) {
tempPtr = timers[max];
timers[max] = timers[i];
timers[i] = tempPtr;
timers[i] = tempPtr;
}
}
#if 0
for (i = 0; i < numTimers; i++)
dprintf(" %s: priority %d\n", timers[i]->name, timers[i]->get_priority());
@ -97,7 +98,7 @@ arch_init_timer(kernel_args *args)
timer_info *timer = NULL;
cpu_status state = disable_interrupts();
for (int i = 0; (timer = sTimers[i]) != NULL; i++) {
if (timer->init(args) == B_OK)
break;

View File

@ -18,6 +18,14 @@
#include "apic_timer.h"
//#define TRACE_APIC
#ifdef TRACE_APIC
# define TRACE(x...) dprintf("apic: " x)
#else
# define TRACE(x...) ;
#endif
/* Method Prototypes */
static int apic_timer_get_priority();
static status_t apic_timer_set_hardware_timer(bigtime_t relativeTimeout);
@ -70,8 +78,9 @@ apic_timer_set_hardware_timer(bigtime_t relativeTimeout)
config = apic_lvt_timer() & ~APIC_LVT_MASKED; // unmask the timer
apic_set_lvt_timer(config);
//TRACE_TIMER(("arch_smp_set_apic_timer: config 0x%lx, timeout %Ld, tics/sec %lu, tics %lu\n",
// config, relativeTimeout, sApicTicsPerSec, ticks));
TRACE("arch_smp_set_apic_timer: config 0x%" B_PRIx32 ", timeout %" B_PRIdBIGTIME
", tics/sec %" B_PRIu32 ", tics %" B_PRId32 "\n", config, relativeTimeout,
sApicTicsPerSec, ticks);
apic_set_lvt_initial_timer_count(ticks); // start it up

View File

@ -20,13 +20,14 @@
//#define TRACE_HPET
#ifdef TRACE_HPET
#define TRACE(x) dprintf x
# define TRACE(x...) dprintf("hpet: " x)
#else
#define TRACE(x) ;
# define TRACE(x...) ;
#endif
#define TEST_HPET
static struct hpet_regs *sHPETRegs;
static volatile struct hpet_timer *sTimer;
static uint64 sHPETPeriod;
@ -234,9 +235,9 @@ hpet_init(struct kernel_args *args)
sHPETPeriod = HPET_GET_PERIOD(sHPETRegs);
TRACE(("hpet_init: HPET is at %p.\n\tVendor ID: %llx, rev: %llx, period: %" B_PRId64 "\n",
TRACE("hpet_init: HPET is at %p.\n\tVendor ID: %llx, rev: %llx, period: %" B_PRId64 "\n",
sHPETRegs, HPET_GET_VENDOR_ID(sHPETRegs), HPET_GET_REVID(sHPETRegs),
sHPETPeriod));
sHPETPeriod);
status_t status = hpet_set_enabled(false);
if (status != B_OK)
@ -248,11 +249,11 @@ hpet_init(struct kernel_args *args)
uint32 numTimers = HPET_GET_NUM_TIMERS(sHPETRegs) + 1;
TRACE(("hpet_init: HPET supports %" B_PRIu32 " timers, and is %s bits wide.\n",
numTimers, HPET_IS_64BIT(sHPETRegs) ? "64" : "32"));
TRACE("hpet_init: HPET supports %" B_PRIu32 " timers, and is %s bits wide.\n",
numTimers, HPET_IS_64BIT(sHPETRegs) ? "64" : "32");
TRACE(("hpet_init: configuration: 0x%" B_PRIx64 ", timer_interrupts: 0x%" B_PRIx64 "\n",
sHPETRegs->config, sHPETRegs->interrupt_status));
TRACE("hpet_init: configuration: 0x%" B_PRIx64 ", timer_interrupts: 0x%" B_PRIx64 "\n",
sHPETRegs->config, sHPETRegs->interrupt_status);
if (numTimers < 3) {
dprintf("hpet_init: HPET does not have at least 3 timers. Skipping.\n");

View File

@ -15,6 +15,15 @@
#include "pit.h"
//#define TRACE_PIT
#ifdef TRACE_PIT
# define TRACE(x...) dprintf("pit: " x)
#else
# define TRACE(x...) ;
#endif
static bool sPITTimerInitialized = false;
struct timer_info gPITTimer = {
@ -73,13 +82,15 @@ static status_t
pit_init(struct kernel_args *args)
{
if (sPITTimerInitialized) {
TRACE("timer is already initialized");
return B_OK;
}
install_io_interrupt_handler(0, &pit_timer_interrupt, NULL, 0);
pit_clear_hardware_timer();
pit_clear_hardware_timer();
sPITTimerInitialized = true;
TRACE("timer initialized");
return B_OK;
}

View File

@ -250,8 +250,8 @@ timer_interrupt()
per_cpu_timer_data& cpuData = sPerCPU[smp_get_current_cpu()];
int32 rc = B_HANDLED_INTERRUPT;
TRACE(("timer_interrupt: time %lld, cpu %ld\n", system_time(),
smp_get_current_cpu()));
TRACE(("timer_interrupt: time %" B_PRIdBIGTIME ", cpu %" B_PRId32 "\n",
system_time(), smp_get_current_cpu()));
spinlock = &cpuData.lock;