Real-Time Java and High Resolution Timers
By Jim Connors-Oracle on Jun 19, 2007
Any modern x86/x64 processor worth its salt comes equipped with an Advanced Programmable Interrupt Controller, or APIC. Among the features that an APIC provides is access to high resolution timers. Without such capability, the default interrupt source for timer and cyclic operations has a precision on the order of 10 milliseconds -- hardly fine-grained enough for any serious real-time work.
The cyclic subsystem, introduced in Solaris 8, gives Solaris the capability to support high resolution timers. The Sun Java Real-Time System version 2.0, available for Solaris on both x86 and Sparc platforms, includes an additional package called SUNWrtjc: Java Real-Time System cyclic driver. This package exposes an interface to the cyclic subsystem, normally only available to the kernel. For those already familiar with Sun's Java RTS, you've no doubt noticed that you either need to run as superuser or assign a set of fine-grained privileges to an ordinary user account. (sys_res_config, proc_priocntl, proc_lock_memory and proc_clock_highres). The proc_clock_highres privilege gives access to those timers.
Originally developed on an AMD Athlon-based PC, I recently moved a Real-Time Java project over to my Toshiba Tecra A1 laptop running the same version of Solaris and Java RTS. With the goal of getting in a little development time during a long flight, that migration suddenly casued timings to be all wrong. Why, might you ask, would moving an application from one seemingly identical Solaris environment to another cause this unusual behavior? Turns out that even though the laptop, a Pentium 4M based system, has an APIC, it was never exposed by the laptop BIOS. In this scenario, regardless what you do from a Solaris perspective, you'll never get access to the high-res timers.
This phenomenon appears to be most prevelant in laptops. As they account for about 50% (or more?) of PCs sold today, developers have a realistic chance of running into this situation. You can issue this magic Solaris incantation to determine if your system has high-res timer support:
# echo "psm_timer_reprogram::print" | mdb -k
If anything but 'apic_timer_reprogram' is then displayed, your machine has no exposed APIC, and is probably unsuitable for Java RTS. In some cases the BIOS may be configurable with regards to APIC support; in many others it is simply not available.
In the absence of an APIC, there is the potential to improve the high-resolution timing by setting the following tunable in /etc/system:
Following a reboot, this would change the clock tick frequency from 100 to 1000 ticks per second. This frequency can then be further tuned by setting the hires_hz tunable to the desired value:
The default value is 1000 ticks per second; higher values are not officially supported.
Note that tuning your machine in this way does not come without cost. It is likely to degrade overall performance, as the system will need to spend a larger proportion of time handling the larger frequency of clock interrupts.1
 Thank you Christophe Lizzi for your explanation of the problem and potential workaround.