Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Computer Time Management and Embedded Systems

3/21/2011

Microsoft Corporation

May 2010

This technical article provides an overview of some options and challenges for managing computer time on an embedded system.

Windows Embedded Standard 7

How you configure an embedded system for managing time depends on the specific needs of the system. You should consider the following when evaluating the best way to manage time on an embedded system:

  • Does the system time have to be synchronized with a master clock or a time authority?
  • How important is it that multiple systems have their time synchronized with one another?
  • Are the needs of the system better met by using Coordinated Universal Time (UTC) or local standard time?
  • If local time is being used, should this include automatic adjustment for Daylight Saving Time (DST)?
  • Does the system have network access?
  • How important is time accuracy?
  • Is the system going to use write filters, such as the following:
    • Enhanced Write Filter (EWF)
    • File-Based Write Filter (FBWF)
    • Hibernate Once Resume Many (HORM)

Depending on the criteria and other requirements, you can develop a strategy best suited for the specific needs of the system.

Most BIOS/EFI provides a real-time clock. This real-time clock is also known as the CMOS clock. The CMOS clock can maintain the date/time in a system even when it is turned off. This enables the NTOS Kernel to determine the date/time during the boot sequence or upon resume from hibernation. Because this internal clock is maintained by the computer hardware, this enables the kernel to determine the date/time without relying on external services (such as a time service).

By default, Microsoft Windows assumes that the date/time stored in the CMOS clock is in local time. Because the default date/time is in local time, the CMOS clock must be adjusted periodically to account for transitions between DST and standard time when DST is applicable for a given time-zone configuration. This contrasts with other operating systems which might assume that the date/time stored in the CMOS clock is in UTC. The CMOS clock does not store information related to time zone or DST. Therefore, this can create issues when write filters are enabled, or when multiple operating systems are installed and used on a single system.

Because the CMOS clock can exhibit a small drift over time, it should not be the primary source of time on systems where accuracy is important. Similarly, other sources should be used when synchronization with an official time source or master clock is needed, or when you must make sure that multiple computers have a synchronized time. In such instances, a time server should be used.

Time servers implement a network protocol that enables computers to synchronize with a centralized time source on a given network. In turn, the time server itself can be synchronized with other time servers or an official master clock. Synchronizing with a time server offers the best solution when time management on multiple computers is needed, or when time accuracy is important.

You should select a time zone based on your time-tracking needs. UTC is best suited for a system where a global standardized time is desirable, while local standard time might be the best choice when the computer has an interactive user. The time zone and related settings are user-configurable from the Date and Time Control Panel, as shown in the following illustration:

Ff794720.9745fcb5-504c-4e76-b093-7f6eb2f8e0a7(en-US,WinEmbedded.1001).gif

Selecting the Change time zone button enables you to select the time zone to be used and to configure whether the clock should automatically be adjusted for DST. You can also use this button to configure the system to use (UTC) Coordinated Universal Time as the time zone (in which case, DST does not apply). Selecting the Change date and time button enables you to configure the system date/time within the specified time zone. Changes to the time zone are updated in the registry, while changes to the date/time are generally updated directly in the CMOS clock. You must disable any write filters that will prevent changes to the registry from persisting before you change the time zone or the clock based on those changes.

As previously stated, the default behavior for Windows is to store the local time for the configured time zone in the CMOS clock. The CMOS clock does not know what time zone is stored in the clock or whether the clock reflects DST or not. This important information is stored in the system registry under the following:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation

The following is a list of keys that are stored in the registry under this location:

Name Type Data Description

ActiveTimeBias

REG_DWORD

The active time Bias as configured for the time zone accounting for DST. This is the bias that was used to configure the CMOS clock.

The Bias is specified in minutes from UTC.

The ActiveTimeBias will be 0 when the time zone is configured for UTC. It will be 420 (0x1A4) during Pacific Daylight Time (PDT) (which is 7 hours * 60 minutes), and it will be 480 (0x1E0) during Pacific Standard Time (PST) (which is 8 hours * 60 minutes).

Bias

REG_DWORD

This is the time Bias for the configured time zone.

The Bias is specified in minutes from UTC.

DaylightBias

REG_DWORD

Signed value that indicates how much to adjust the Bias to determine the bias to be used for DST.

For example, this value might contain -60 (0xffffffc4), which indicates that one hour must be subtracted from the Bias.

DynamicDaylightTimeDisabled

REG_DWORD

Flag that indicates if the system should automatically adjust the clock for DST.

The user can configure this option under the time zone setting for the Date and Time Control Panel.

0 indicates automatic adjustment.

1 indicates automatic adjustment is disabled.

RealTimeIsUniversal

REG_DWORD

This flag is used to indicate if the CMOS clock is configured by using the local date/time (default) or UTC.

0 indicates that the CMOS clock is configured for local date/time.

1 indicates that the CMOS clock is configured by using UTC.

Ff794720.note(en-US,WinEmbedded.1001).gifNote:
This flag is not installed in the system by default and is not officially supported by Windows.

As indicated, the default behavior of Windows is to store local time for the configured time zone in the CMOS clock. Therefore, the CMOS clock must be adjusted periodically as time transitions between DST and standard time. There are instances where this automatic adjustment does not need to occur, such as the following:

  • The time zone is configured as UTC.
  • DST does not apply for a configured time zone.
  • The user disabled the option to Automatically adjust clock for Daylight Saving Time.
  • The CMOS clock is configured to be stored as UTC instead of local time (for example, the registry key RealTimeIsUniversal is set to 1).

When the system needs to adjust the CMOS clock for a transition between DST and standard time, this will occur either during the boot-up sequence (if the system was powered down during the transition) or during the transition itself if the system is up and running.

When the CMOS clock is adjusted the ActiveTimeBias registry key will also be adjusted to reflect the new value that was used to configure the CMOS clock. The following diagram shows the boot sequence as it applies to the CMOS clock, write filters, and system registry IO:

Ff794720.f92a079a-536b-4cab-b7fe-8535c752b9ce(en-US,WinEmbedded.1001).gif

As can be seen from this diagram, the CMOS clock is updated before driver entry where the write filters are enabled. However, the change to the system registry to ActiveTimeBias is cached until Registry IO is enabled which does not occur until after the write filters are enabled. Therefore, the changes to the registry required to record that the CMOS clock has been updated are not persisted when write filters are enabled (for system volume). Similarly, you cannot use the Registry Filter to work around the problem because the Registry Filter is not enabled early enough in the boot sequence to prevent the clock from being adjusted after it has been previously adjusted.

When HORM is enabled, the boot manager will execute the resume code and then execution will resume from the previously saved state of the hibernation file. This will bypass the standard startup logic. However, the system still has logic to update the system clock based on the last saved ActiveTimeBias value.

The purpose of this section is to describe the techniques and options available for computer time management on an embedded system.

CMOS Clock in UTC

The default behavior for Windows is to store local time applicable for the ActiveTimeBias in the CMOS clock. For systems in time zones where DST applies, this can create an issue if a write filter is enabled. This occurs because while the system can update the CMOS clock it is prevented by the write filters from persisting the new value of ActiveTimeBias back into the system registry. Therefore, the system is unable to record that the update has already occurred for access during the next restart. The system will repeat the update with each successive restart as long it is unable to update ActiveTimeBias in the system registry file.

There are several ways in which the system can be configured to avoid this problem, which include the following:

  • Configure the system to use UTC as the time zone.
  • Disable automatic adjustment of the clock for DST.
  • Configure the system so that the CMOS clock is in UTC (the system can still be configured for local time and DST).

In order to configure the system so that the CMOS clock is in UTC, you must create the following registry key and set the DWORD value to 1:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\RealTimeIsUniversal

Naturally, this key should be created when EWF, FBWF, and HORM are disabled. Changes to this key take effect after the next restart. After you do this, you must configure the CMOS clock to use UTC (this should be done from inside the BIOS). Therefore, the basic steps for configuring a system with this option are as follows:

Change the CMOS clock to use UTC
  1. Make sure that EWF and FBWF are disabled.

  2. Configure the Windows time zone to the desired value (for example, Pacific Time).

  3. Add the RealTimeIsUniversal key to the registry as described earlier.

  4. Restart the system and go into the BIOS.

  5. Set the CMOS clock to the current UTC time and date. For example, if you are in Pacific Standard Time Zone, and it is 11:00 AM, then you would set the CMOS clock to 7:00 PM because there is 8 hours difference.

  6. Restart the system and enable EWF or FBWF.

When this option is set, the system will display the time for the time zone configured (for example, PDT or PST) and will adjust the system clock in response to changes between and Standard Time, but will not try to make any adjustments to the underlying CMOS clock. Because the CMOS clock is in UTC the system can compute and display the correct time for the configured time zone.

To disable this feature, just set the registry key to 0 or delete the registry key, restart the system, and reconfigure the CMOS clock.

Ff794720.note(en-US,WinEmbedded.1001).gifNote:
This is an unsupported feature of Windows, and the Windows UI might not honor this registry entry. Therefore, the CMOS clock should be set to UTC within the BIOS and not within Windows.

A time server enables one or more systems to synchronize time based on a master clock. Each client can synchronize its time from the time server. This enables multiple systems to be synchronized with regard to time.

This is the best option when it is important to maintain an accurate time or to make sure that multiple systems are set to the same time. This option requires network access and is not available for systems that are not on a network.

Time synchronization can be configured by using the Internet Time tab on the Date and Time Control Panel.

This option is to configure the system to use UTC. UTC provides a single point of reference for time regardless of location. In addition, UTC does not adjust for DST. Therefore, UTC should be considered as an option for several scenarios, including the following:

  • The system does not have human interaction with the clock or date.
  • The system is globally distributed but accessed by a central location or headquarters.
  • The system can be accessed by several globally distributed clients.
  • The system has EWF, FBWF, or HORM configured.
Configure system to use UTC
  1. Select (UTC) Coordinated Universal Time from the Time Zone Settings dialog of the Date and Time Control Panel.

Ff794720.note(en-US,WinEmbedded.1001).gifNote:
For the purpose of this document no distinction is made between UTC, Universal Time (UT), or Greenwich Mean Time (GMT).

Local time enables you to configure a system based on the local time (typically this is standard time for a given time zone with or without DST). With this option you select the appropriate time zone for the system and set the system date/time for that time zone. For example, the system might be configured for Pacific Standard Time (PST). Additionally, there is an option, Automatically adjust clock for Daylight Saving time, that can be disabled (it is enabled by default). When this option is enabled, the system adjusts the clock atomically in response to transitions between Pacific Daylight Time and Pacific Standard Time. By default, this will also change the CMOS clock.

Generally, this option is chosen for systems where users will interact with the system and need the date/time to be set approximately to local time. For systems where time accuracy is important, or where synchronization with other systems is important, you should consider using a time server. Also, if you use EWF, FBWF, or HORM in a time zone where DST applies, you should consider setting the CMOS clock to use UTC, as described in CMOS Clock in UTC.

Additionally, in systems where EWF, FBWF, or HORM are used, you can select this option after disabling the option to automatically update the clock for DST. This will require manual intervention if you want to update the clock. This approach lets the user control setting the time and avoids the other issues that result from the inability to update the system registry on protected volumes.

Ff794720.note(en-US,WinEmbedded.1001).gifNote:
If you want to use local meridian time, disable automatic adjustment for DST. Then set the clock to local meridian time.

You can configure a system to use additional clocks. For example, you can configure the clock to use UTC but can also configure an additional clock to use Pacific Time. The advantage of doing this is that the user is then able to view the other clocks (such as local time) while the system is still configured to UTC. The taskbar will still display the primary configured clock, but hovering the mouse pointer over the clock or clicking the clock in the taskbar will display the time for the primary clock and any additional clocks.

You can configure additional clocks by using the Additional Clocks tab on the Date and Time Control Panel.

The following table provides a summary of the techniques and criteria described in this article, and when to apply them:

Criteria/Technique CMOS Clock in UTC Time Server Coordinated Universal Time (UTC) Local Time (Automatic DST) Local Time (Automatic DST disabled)

Clock Accuracy is Critical

Fair

Best

Not applicable

Not applicable

Not applicable

Multiple Systems have Synchronized Clock

Poor

Best

Not applicable

Not applicable

Not applicable

Globally Distributed System

Fair

Good

Best

Poor

Poor

User Interaction

Good

Good

Fair

Best

Fair

Write Filters Enabled

Good

Best

Best

No

Fair

HORM Enabled

Good

Good

Best

No

Fair

Non-Networked Computer

Good

No

Good

Good

Fair

Multi-boot system

Best

Good

Good

Poor

Poor

Ff794720.note(en-US,WinEmbedded.1001).gifNote:
When configuring the system to use UTC as the primary time, you might want to configure an additional clock to display the local time for an interactive user.

By using the techniques outlined in this article, you can create systems that use write filters and meet your time handling requirements.

Show:
© 2015 Microsoft