Fix a bug where the callout might not be initialized before being used.

Rev 1.9 introduced another path where machclk_freq would be initialized
before the rest of setup was done (i.e. initializing the callout).  Make
the one-time initialization a separate function and make init_machclk()
able to be called multiple times, any time.  We depend on tsc_freq first
being updated from the highest priority eventhandler, thus we run last
and call init_machclk() to set machclk_freq.  Also, don't initialize
static variables to 0.

Tested by:	Eygene Ryabinkin
Approved by:	re
This commit is contained in:
Nate Lawson 2007-07-12 17:00:51 +00:00
parent fd7c4230b2
commit f1172c58e5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=171407

View File

@ -887,8 +887,8 @@ write_dsfield(m, pktattr, dsfield)
#define MACHCLK_SHIFT 8
int machclk_usepcc;
u_int32_t machclk_freq = 0;
u_int32_t machclk_per_tick = 0;
u_int32_t machclk_freq;
u_int32_t machclk_per_tick;
#ifdef __alpha__
#ifdef __FreeBSD__
@ -911,14 +911,14 @@ tsc_freq_changed(void *arg, const struct cf_level *level, int status)
return;
/* Total setting for this level gives the new frequency in MHz. */
machclk_freq = level->total_set.freq * 1000000;
init_machclk();
}
EVENTHANDLER_DEFINE(cpufreq_post_change, tsc_freq_changed, NULL,
EVENTHANDLER_PRI_ANY);
EVENTHANDLER_PRI_LAST);
#endif /* __FreeBSD_version >= 700035 */
void
init_machclk(void)
static void
init_machclk_setup(void)
{
#if (__FreeBSD_version >= 600000)
callout_init(&tbr_callout, 0);
@ -941,6 +941,18 @@ init_machclk(void)
tsc_is_broken))
machclk_usepcc = 0;
#endif
}
void
init_machclk(void)
{
static int called;
/* Call one-time initialization function. */
if (!called) {
init_machclk_setup();
called = 1;
}
if (machclk_usepcc == 0) {
/* emulate 256MHz using microtime() */