Tag Archives: counter

Naughty timer ACPI-safe, hangs on FreeBSD on Koolu

After updating the CVS tree from STABLE, rebuilding and reinstalling world and the kernel, I have found that:

  • boot hangs at DHCP discovery (dhclient), devd start-up, and one more place;
  • key repeating doesn’t work, you have to press a key every time;
  • the date doesn’t update;
  • you can’t restart or shut down.

All these have one thing in common: they happen when the counter doesn’t tick.

After noodling around for quite some time with the kernel config and make.conf, I finally understood this wasn’t the reason. See, the GENERIC kernel that kame with the FreeBSD 7.0 CD (and I backed that up after installing, right away) worked, and the GENERIC kernel re-compiled didn’t.

I thought it was related to the build tools. No, not.

Turned out it was the counter (timer). See, your system has several:

% sysctl kern.timecounter.choice
kern.timecounter.choice: TSC(800) ACPI-fast(1000) i8254(0) dummy(-1000000)
% sysctl kern.timecounter.hardware
kern.timecounter.hardware: ACPI-fast

Now, this stuff happened on a Koolu, and it had an ACPI-safe, quality 850, so that got chosen by default. Turned out it didn’t work.

You can do several things:

  • you can boot the same kernel without ACPI, just select the appropriate option;
  • or you can load it by hand:
    sudo sysctl kern.timecounter.hardware=TSC

  • or automatically – add this to /etc/sysctl.conf:
    (Make sure there are no quotes in the latter!)

Atmel AVR timer/counter examples

Here’s the catch: the timer/counter is capable of operating on a completely hardware level, no software interaction required. A nice explanation is given here (section 2). This page starts with an introduction using a software counter. Which shows how tedious that is, especially counting the clock durations yourself.

Another page at AVRfreaks here deals exclusively with the software implementation, although using the timer/counter registers for counting. This is useless and horribly wrong, that’s not how timers/counters with “output compare” capabilities should be used! The dangerous part is that this article doesn’t even mention the hardware-only implementation.