Subject: Re: detaching timecounters (patch)
To: None <>
From: Chris Gilbert <>
List: tech-kern
Date: 12/31/2007 13:54:12
David Young wrote:
> I'm writing a device detachment routine for geodecntr(4), which provides
> a timecounter.  I've come up with the attached routine for detaching
> a timecounter.  Is it ok?
> Dave

Note I'm not an expert on timecounters, I'm just looking over the code 
and your patch :)

I think there's a corner case where the timecounter being set as the 
current timecounter isn't "good enough".  Looking at tc_init there's a 
bunch of requirements for a counter to be "good enough" and if it's not 
timecounter isn't changed and continues to use the default 
dummy_timecounter till one is good enough.  For detach the code should 
proably do the same thing, IE if this is the only tc that was "good 
enough" then it should fallback to dummy_timecounter.

The fix looks easy enough, just default best to dummy_timecounter and 
make sure that negative qualities are ignored, eg:

	for (best = &dummy_timecounter, tc = timecounters; tc != NULL; tc = tc->tc_next) {
		if (tc->tc_quality < 0)
		else if (tc->tc_quality > best->tc_quality)
			best = tc;
		else if (tc->tc_quality < best->tc_quality)
		else if (tc->tc_frequency > best->tc_frequency)
			best = tc;