<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Windows Time Service : Algorithm</title><link>http://blogs.msdn.com/w32time/archive/tags/Algorithm/default.aspx</link><description>Tags: Algorithm</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Keeping the Domain On Time</title><link>http://blogs.msdn.com/w32time/archive/2007/09/04/keeping-the-domain-on-time.aspx</link><pubDate>Tue, 04 Sep 2007 21:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3890438</guid><dc:creator>Ryan Sizemore</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/w32time/comments/3890438.aspx</comments><wfw:commentRss>http://blogs.msdn.com/w32time/commentrss.aspx?PostID=3890438</wfw:commentRss><description>&lt;P&gt;Windows Time Service on a domain (referred to as 'Domain Synchronization' or 'Domain Sync' for short) is a huge topic. I will do my best to cover all of its aspects in this article, but some concepts won't be covered until a later date, and others still relate directly to the original &lt;A href="ftp://ftp.rfc-editor.org/in-notes/rfc1305.txt" target=_blank mce_href="ftp://ftp.rfc-editor.org/in-notes/rfc1305.txt"&gt;RFC&lt;/A&gt; for NTP. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Background&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;As I stated in my &lt;A href="http://blogs.msdn.com/w32time/archive/2007/07/07/welcome.aspx" target=_blank mce_href="http://blogs.msdn.com/w32time/archive/2007/07/07/welcome.aspx"&gt;previous post&lt;/A&gt;, the original reasons for developing w32time stemmed from the requirements imposed by Kerberos. In order for Kerberos to function securely, the time difference between the participating machines needs to be less than five minutes. In time, other components have come to rely on w32time, including &lt;A href="http://technet2.microsoft.com/WindowsServer/en/Library/1465d773-b763-45ec-b971-c23cdc27400e1033.mspx?mfr=true" target=_blank mce_href="http://technet2.microsoft.com/WindowsServer/en/Library/1465d773-b763-45ec-b971-c23cdc27400e1033.mspx?mfr=true"&gt;Active Directory Replication&lt;/A&gt; and &lt;A href="http://update.microsoft.com/" target=_blank mce_href="http://update.microsoft.com"&gt;Windows Update&lt;/A&gt;. In a Windows domain, w32time needs to keep machines synchronized, and it needs to do so in a quick, efficient, and quiet manner.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Beyond NTP&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The NTP protocol described in the RFC goes a long way toward designing a robust time synchronization solution. But in the end, what we are really interested in is just that: the solution. Keeping time synchronized between two machines is possible, but the solution needs to be more robust to deal with computers belonging to a domain. In particular, w32time works to answer these questions (just to name a few):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;How do we ensure that in a large network of computers, an efficient chain of time sources is picked?&lt;/LI&gt;
&lt;LI&gt;How do we auto-configure so that an administrator has to do a minimal amount of work to set it up?&lt;/LI&gt;
&lt;LI&gt;How do we keep it secure and still auto-configurable?&lt;/LI&gt;
&lt;LI&gt;How do we allow administrators to get a look at what is happening?&lt;/LI&gt;
&lt;LI&gt;How do we alert the administrators when something goes wrong?&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;These questions are important, specifically in the domain scenario (as opposed to the home user scenario), since the needs of the home user and the needs of the domain user are quite different.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Designing Inside the Box&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Because many components within Windows depend on w32time to keep the clock synchronized, w32time cannot take (hardly) any dependencies itself. If w32time relied on component X to do something fancy, and component X relied on Kerberos, then we would have a problem, since Kerberos relies on w32time. This would create a circular dependency and, well, that's a bad thing.&lt;/P&gt;
&lt;P&gt;For this reason, w32time has a simplified mechanism to authenticate time syncs. More information on the authentication mechanism will be covered in a future post.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Intelligent Design&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The first issue to address is finding someone to synchronize with. Each machine needs to sync with another machine to get its time. To do this efficiently and automatically, w32time uses the domain hierarchy created with the domain itself. In the simplest frame of mind, a domain consists of the following distinct entities (aka computers):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Exactly one primary domain controller (or PDC-emulator)&lt;/LI&gt;
&lt;LI&gt;Zero or more replica domain controllers (DCs)&lt;/LI&gt;
&lt;LI&gt;Zero or more member computer (either server or workstations)&lt;/LI&gt;&lt;/UL&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG style="WIDTH: 555px; HEIGHT: 593px" title="Time Synchronization in Active Directory Hierarchy" alt="Time Synchronization in Active Directory Hierarchy" src="http://i.technet.microsoft.com/cc773013.4d3b9294-477c-49eb-a06a-7a330ae0cf58(en-us).gif" width=555 height=593 mce_src="http://i.technet.microsoft.com/cc773013.4d3b9294-477c-49eb-a06a-7a330ae0cf58(en-us).gif"&gt;&lt;/P&gt;
&lt;P&gt;The inner working of what a domain is and how it operates is beyond the scope of this post, but this should be enough to provide&amp;nbsp;the groundwork for our discussion.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Time Source Selection&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Each member of the domain follows a different set of requirements, based on its role. Lets take a look at those roles:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Primary Domain Controller - This machine is the authoritative time source for a &lt;EM&gt;domain&lt;/EM&gt;. It will have the most accurate time available in the domain, and must sync with&amp;nbsp;a DC in the parent domain (except in special cases).&lt;/LI&gt;
&lt;LI&gt;Replica Domain Controller - This machine will act as a time source for clients and member servers in the domain. A DC can sync with the PDC of its own domain, or a DC or&amp;nbsp;PDC in the parent domain.&lt;/LI&gt;
&lt;LI&gt;Clients/Member Servers - This machine can sync with any DC or PDC of its own domain, or a DC or PDC in the parent domain&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;These are the default rules of where a machine can go looking for a time source. Keep in mind that there are corner cases where the rules can be bent a little. A few additional rules:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;A machine can only look for a time source in &lt;U&gt;its own domain&lt;/U&gt; or &lt;U&gt;the parent domain&lt;/U&gt;. A machine will never go to a domain on a parallel level, or a "skip-level" parent domain.&lt;/LI&gt;
&lt;LI&gt;Within a domain, a machine cannot sync with its own kind. A DC cannot sync with another DC. A client cannot sync with another client.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Also, you may have noticed that a PDC can only sync from a DC or PDC in the parent domain. Well, what if you are in the parent domain already? This is a special case, which is detailed below in the section "Special Case: The Root PDC".&lt;/P&gt;
&lt;P&gt;The time source selection mechanism works great to enumerate the possible machines to sync from. The problem is that this usually leaves more than one&amp;nbsp;machine as a&amp;nbsp;possible partner. We need a&amp;nbsp;way to pick the "best" one of the group, and that is what scoring does for us.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Score!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Each possible machine is given a score, based on certain criteria. Once all of the candidates have a score, w32time simply chooses the machine with the highest score. Here is what the scoring looks like:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;8 points if the machine is in-site&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;4 points if the machine is "reliable"&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;2 points if the machine is in the parent domain&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;1 point if the machine is a PDC (or PDC emulator)&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P mce_keep="true"&gt;So why are these points given? Let's look at the rules individually. Machines that are in the same site as&amp;nbsp;the&amp;nbsp;one in question have the best chance of providing us with good time. &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;Machines that are out of site probably are disconnected physically in one way or another, and would likely introduce delay.&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;A machine that is "reliable" is pre-configured to be directly connected to a reliable time source, such as a GPS or atomic clock. These devices provide very accurate, very stable time samples. If a machine is configured to sync directly with one of these devices, a registry value can be changed to indicate that this machine will be a source of reliable time.&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;A machine higher in the forest will be closer to the root, and hence will have more accurate time than a machine in the current domain.&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;A PDC (or PDC-emulator) will be more accurate than a DC in the same domain because it is guaranteed to sync with a machine in the parent domain.&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P mce_keep="true"&gt;From this, we can derive a score for each machine, and then choose the machine with the highest score.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Examples&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;When a machine boots up, it will go looking for a time source. Depending on its role, it will be required to choose from a subset of possible machines to sync with. But how do we prioritize between the available choices? Lets take a look at the following example:&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Example 1:&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;This example utilized the graphic above. The domains will be referred to as the&amp;nbsp;"Left Domain", the "Right Domain", and the "Parent Domain".&lt;/EM&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Computer foo has just been joined to the Left Domain as a regular client (not a DC), and it booting up for the first time on a domain. First, we need to enumerate which machines are &lt;EM&gt;possible&lt;/EM&gt; as partners to sync with. We will look at each machine to see if it is a possible sync partner.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;"Domain Controller" [Left Domain]&amp;nbsp; is a DC in the same domain, so it &lt;U&gt;is&lt;/U&gt; a valid choice&lt;/LI&gt;
&lt;LI&gt;"PDC Emulator" [Left Domain] is a PDC in the same domain, so it &lt;U&gt;is&lt;/U&gt; a valid choice&lt;/LI&gt;
&lt;LI&gt;"Domain Controller" [Parent Domain] is a DC in the parent domain, so it &lt;U&gt;is&lt;/U&gt; a valid choice&lt;/LI&gt;
&lt;LI&gt;"PDC Emulator" [Parent Domain] is a PDC in the parent domain, so it &lt;U&gt;is&lt;/U&gt; a valid choice&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Which machines aren't valid? Let's take a look (and find out why)&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;"Workstation" [Left Domain] is not a DC, so it &lt;U&gt;is not&lt;/U&gt; a valid choice&lt;/LI&gt;
&lt;LI&gt;"Server" [Left Domain] is not a DC, so it &lt;U&gt;is not&lt;/U&gt; a valid choice&lt;/LI&gt;
&lt;LI&gt;"Workstation" [Parent Domain] is not a DC, so it &lt;U&gt;is not&lt;/U&gt; a valid choice&lt;/LI&gt;
&lt;LI&gt;"Server" [Parent Domain] is not a DC, so it &lt;U&gt;is not&lt;/U&gt; a valid choice&lt;/LI&gt;
&lt;LI&gt;Anything in the [Right Domain] is not in the same domain, and not in the parent domain, so it&amp;nbsp;&lt;U&gt;is not&lt;/U&gt; a valid choice&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Ok, so&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;we have our possible choices, but now we need to prioritize them to pick the best one. To do this, we will utilize the scoring system. Assuming that our entire forest is in one site, and we don't have any machines configured as "reliable":&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;"Domain Controller" [Left Domain]&amp;nbsp; Score = &lt;STRONG&gt;8&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;"PDC Emulator" [Left Domain] Score = 8 + 1 = &lt;STRONG&gt;9&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;"Domain Controller" [Parent Domain] Score = 8 + 2 = &lt;STRONG&gt;10&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;"PDC Emulator" [Parent Domain] Score = 8 + 2 + 1 = &lt;STRONG&gt;11&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;So there we have it. The PDC in the parent domain will be our time source. But what if the [Left Domain] was put into a separate site?&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Example 2:&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Assume the same scenario as the above example, except that [Left Domain] exists in a different site from the rest of the forest. We will use the same logic applied above to determine a time source.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;So the [Left Domain] is in a different site. Since the first part of time source selection does not take site location into consideration, we will get the same &lt;U&gt;possible&lt;/U&gt; machines to sync with. However, the scoring system will provide us with a different machine when all is said and done. Lets look at how the scoring would now occur:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;"Domain Controller" [Left Domain]&amp;nbsp; Score = &lt;STRONG&gt;8&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;"PDC Emulator" [Left Domain] Score = 8 + 1 = &lt;STRONG&gt;9&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;"Domain Controller" [Parent Domain] Score =&amp;nbsp;2 = &lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;"PDC Emulator" [Parent Domain] Score = 2 + 1 = &lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P mce_keep="true"&gt;Because the DC and PDC in the [Parent Domain] are in a different site, they don't get the +8 to their score. This leaves us with the PDC of the current domain, with a score of &lt;STRONG&gt;9&lt;/STRONG&gt;. But what about the PDC of the [Left Domain]?&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;U&gt;Example 3:&lt;/U&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;EM&gt;Assume the same scenario as Example 2,&amp;nbsp;Again, we will use the same logic applied above to determine a time source.&lt;/EM&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;With the left domain in a different site from the rest of the forest, and with the PDC of the [Left Domain] being the authoritative time source for the [Left Domain], we will need to go out of site for a time source - we have no other choice. So we will look at the scores for the various eligible time sources:&lt;/P&gt;
&lt;UL&gt;
&lt;DIV mce_keep="true"&gt;
&lt;LI&gt;"Domain Controller" [Parent Domain] Score =&amp;nbsp;2 = &lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;"PDC Emulator" [Parent Domain] Score = 2 + 1 = &lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/LI&gt;&lt;/DIV&gt;&lt;/UL&gt;
&lt;P&gt;We cannot&amp;nbsp;sync with any time sources in our own domain, so we only have the time sources from the [Parent Domain]. The scoring will give us the PDC of the [Parent Domain].&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Plan B: Fail over&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;So what happens when things don't go as planned? Windows Time Service has been built to handle fail over situations from the beginning. For a generic&amp;nbsp;example, assume that a client is currently synchronizing with a time source. If the time source goes away for one reason or another, the client will need to go looking for another time source. &lt;/P&gt;
&lt;P&gt;For this reason, we use the scoring system illustrated above. The client will reassess the available time sources, score each of them, and choose the best one. Since the previous time source (which was probably the best first choice) has gone away, w32time will pick the next highest scoring time source.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Special Case: The Root PDC&lt;BR&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;PDC&amp;nbsp;for the domain at the root of the forest (the&amp;nbsp;root PDC)&amp;nbsp;poses a problem. Since it has no time sources that are more authoritative than it, it cannot choose a time source automatically. Thus, the administrator will need to set one up manually, or the domain will operate in a "standalone" mode. In the case of a standalone domain, the root PDC will still be the authoritative time source, but its time will come from its own clock.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Wrap Up&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;We have taken a look at how w32time operates in a domain at a very high level. Future posts will dive deeper into specific areas of w32time, and this will provide a groundwork for those other articles. If you have specific thoughts or questions about this post, please feel free to leave a comment. For general questions about w32time, especially if you have problems with your w32time setup,&amp;nbsp;I encourage you to ask them on &lt;A href="http://forums.microsoft.com/TechNet/ShowForum.aspx?ForumID=722&amp;amp;SiteID=17" mce_href="http://forums.microsoft.com/TechNet/ShowForum.aspx?ForumID=722&amp;amp;SiteID=17"&gt;Windows Vista Applications&lt;/A&gt; section of the &lt;A href="http://forums.microsoft.com/TechNet/default.aspx?SiteID=17" mce_href="http://forums.microsoft.com/TechNet/default.aspx?SiteID=17"&gt;Microsoft Technet forums&lt;/A&gt;. One way or another, questions posted there should make their way to my inbox, and I will do my very best to answer them.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;References&lt;/STRONG&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;A href="http://technet2.microsoft.com/WindowsServer/en/library/b43a025f-cce2-4c82-b3ea-3b95d482db3a1033.mspx?mfr=true"&gt;http://technet2.microsoft.com/WindowsServer/en/library/b43a025f-cce2-4c82-b3ea-3b95d482db3a1033.mspx?mfr=true&lt;/A&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=3890438" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/w32time/archive/tags/Algorithm/default.aspx">Algorithm</category><category domain="http://blogs.msdn.com/w32time/archive/tags/Domain+Sync/default.aspx">Domain Sync</category></item><item><title>What is Windows Time Service?</title><link>http://blogs.msdn.com/w32time/archive/2007/07/07/welcome.aspx</link><pubDate>Sun, 08 Jul 2007 05:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3756037</guid><dc:creator>Ryan Sizemore</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/w32time/comments/3756037.aspx</comments><wfw:commentRss>http://blogs.msdn.com/w32time/commentrss.aspx?PostID=3756037</wfw:commentRss><description>&lt;P&gt;Welcome to the Windows Time Service blog. This blog is here to answer some of the questions about the service and show off some of the useful features that it has. Every week, I will try to cover a new topic surrounding Windows Time Service (w32time for short). If anyone has any requests/suggestions for topics, please feel free to let me know. This blog is for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;So what is Windows Time Service?&lt;/STRONG&gt; &lt;/P&gt;
&lt;P&gt;In short, it is a Windows service that keeps your computer clock accurate. Of course, the "how" is much more interesting than the "why", but for the sake of being the initial post, I will start with why time service exists; and for that, we require a bit of history. &lt;EM&gt;NOTE:&lt;STRONG&gt; &lt;/STRONG&gt;Most of the information about the history of w32time comes from previous knowledge, which is not very extensive. If you find a mistake, please let me know.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;In the days of Windows NT 4.0 and prior, there actually wasn't &lt;A class="" href="ftp://ftp.rfc-editor.org/in-notes/rfc1305.txt" target=_blank mce_href="ftp://ftp.rfc-editor.org/in-notes/rfc1305.txt"&gt;NTP&lt;/A&gt; support, but rather &lt;A class="" title=SNTP href="ftp://ftp.rfc-editor.org/in-notes/rfc1769.txt" target=_blank mce_href="ftp://ftp.rfc-editor.org/in-notes/rfc1769.txt"&gt;SNTP&lt;/A&gt;. This was an initial version of the time service that focused on basic time synchronization&amp;nbsp;(I believe the service was called TimeServ). SNTP doesn't support most of the features of the full NTP protocol, which would be needed in future versions of Windows.&lt;/P&gt;
&lt;P&gt;Windows 2000 brought about a wealth of new features, including Kerberos authentication. As part of the &lt;A class="" href="ftp://ftp.rfc-editor.org/in-notes/rfc4120.txt" target=_blank mce_href="ftp://ftp.rfc-editor.org/in-notes/rfc4120.txt"&gt;Kerberos protocol&lt;/A&gt;&amp;nbsp;(section 1.6, 4th bullet of the RFC), computers using Kerberos authentication need to have clocks that are "loosely synchronized", which is defined as 5 minutes by default. To meet this need, SNTP was abandoned and w32time was born. From Windows 2003 though Vista/Windows Server 2008, w32time has been upgraded &amp;amp; retrofitted to support more features, differing environments, and basically meet whatever needs customers and other internal components have.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;How does Windows Time Service work?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Well, without getting into some of the messy details, w32time communicates with other computers in your network to keep the time on your local computer accurate. The overreaching goal is to keep your local clock in step with a remote clock. In this way, w32time is &lt;EM&gt;synchronizing&lt;/EM&gt; your computer's clock to that of your time source. (Keep in mind that most of this information can also found in the NTP v3.0 RFC, which w32time is based on). This is done by sampling the time on a remote system (known as the &lt;EM&gt;time source&lt;/EM&gt;). The communication between a time client and a time source looks something like this: &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The time client makes a request for a timestamp at time &lt;EM&gt;t1&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;The time source receives the request a time &lt;EM&gt;t2&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;The time source sends back a response a time &lt;EM&gt;t3&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;The time client receives the response a time &lt;EM&gt;t4&lt;/EM&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;This is the fundamental interaction between a time client and a&amp;nbsp;time source. The astute reader would first ask the following question: &lt;/P&gt;
&lt;P&gt;Well, if the 2 computers are not currently synchronized (which is the point of this communication in the first place), then how can those time values (&lt;EM&gt;t1 - t4&lt;/EM&gt;) be useful at all?&lt;/P&gt;
&lt;P&gt;This is a great question because it demonstrates the ingenious design of NTP to be &lt;EM&gt;computer independent&lt;/EM&gt;. Without making assumptions about the relationship of the time source and time client, we can make these initial observations:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;(&lt;EM&gt;t4&lt;/EM&gt; - &lt;EM&gt;t1&lt;/EM&gt;) is the total time that is took for the time source to send out a request and get back a response (transit time)&lt;/LI&gt;
&lt;LI&gt;(&lt;EM&gt;t3&lt;/EM&gt; - &lt;EM&gt;t2&lt;/EM&gt;) is the total time that the time source spent processing the request (processing time)&lt;/LI&gt;
&lt;LI&gt;((&lt;EM&gt;t4&lt;/EM&gt; - &lt;EM&gt;t1&lt;/EM&gt;) - (&lt;EM&gt;t3&lt;/EM&gt; - &lt;EM&gt;t2&lt;/EM&gt;)) is the total transit time of the request (transit time - processing time)&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Using this,&amp;nbsp;we can make the following additional observation:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;((t2 - t1) + (t3 - t4)) / 2 is the clock offset between the&amp;nbsp;two computers&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;[EDIT: The above formula has been corrected. Thanks occulations]&lt;/P&gt;
&lt;P&gt;Now that&amp;nbsp;we have the clock offset, we can start to correct the clock on the local computer (the time client). Correcting the time on a computer can be done in two ways: &lt;EM&gt;skewing&lt;/EM&gt; and&amp;nbsp;&lt;EM&gt;setting&lt;/EM&gt;. If the time difference is small enough*, we can adjust the clock gradually over time. However, if the time difference is too large* (such as hours or days), it is better to simply set the local clock to the desired time.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;* The concept of "too large" or "too small" is relative. These values are adjustable in the registry so that you can control when w32time skews, sets or does nothing at all.&lt;/EM&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;The relationship between w32time and local clock (yes, they are two distinct entities) is complicated and will be explained in a later post.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Time source selection&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Aside from how the service determines the time difference, the next most common question is: How does w32time choose a time source (known as a &lt;EM&gt;peer&lt;/EM&gt;)? The service can operate in one of two possible modes:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;NTP (as defined in the original RFC)&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;NT5DS (using domain lookup mechanisms)&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P mce_keep="true"&gt;The NTP mode is straight-forward: Try to sync with&amp;nbsp;the peer specified. If you can't, wait until you can. This is the mode that non-domain joined computers use. The DNS name or IP address of the peer can be changed in the registry, but it comes as 'time.windows.com' by default. Microsoft hosts its own NTP server, which is how your computer gets correct time "out of the box".&lt;/P&gt;
&lt;P mce_keep="true"&gt;Domain joined computers utilize the NT5DS mode. This mode uses netlogon API calls to find an eligible peer to sync with. Because domains can become both large and deep, and w32time needs to operate in an optimal fashion either way, there is a complex algorithm that is used to find a peer. I will be covering this later in a seperate post (since it is such a large and involved topic), but you can find a reasonable explaination at &lt;A class="" href="http://technet2.microsoft.com/WindowsServer/en/library/71e76587-28f4-4272-a3d7-7f44ca50c0181033.mspx?mfr=true" target=_blank mce_href="http://technet2.microsoft.com/WindowsServer/en/library/71e76587-28f4-4272-a3d7-7f44ca50c0181033.mspx?mfr=true"&gt;TechNet for Windows Server 2003&lt;/A&gt;. Here is the quick overview:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;Computers sync with DCs, preferably&amp;nbsp;from their own site/domain&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;DC sync with local PDC, but will go out of site/domain if needed&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;PDCs sync with other PDC, but possible DCs higher up in the forest if needed&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P mce_keep="true"&gt;At the top of the forest (at the root domain), there needs to be either a local time source or a link to an external peer that provides reliable time data. Again, this really needs a long discussion to make proper sense, but in essence the domain needs to get its time data from somewhere. The w32time service is responsible for distributing the time throughout the domain, but it needs to go to another source to get the data to distribute in the first place.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;STRONG&gt;Wrap Up&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;This should give you a brief look at the Windows Time Service and how it works. If you have topic ideas, please let me know. I'm only one man, and this isn't the &lt;A class="" href="http://shellrevealed.com/default.aspx" target=_blank mce_href="http://shellrevealed.com/default.aspx"&gt;Shell Blog&lt;/A&gt;. I have a list (and it is growing) for future topics, but if the community feels that one or more issues are more important, I will do my best to cover them first. As I said in the beginning, this blog is for you.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=3756037" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/w32time/archive/tags/Algorithm/default.aspx">Algorithm</category><category domain="http://blogs.msdn.com/w32time/archive/tags/Registry+Settings/default.aspx">Registry Settings</category></item></channel></rss>