/* file: ClockSyncServer.h */ /* author: MLehr */ /* * Copyright (C) 1994 * by the Rector and Board of Visitors of * the University of Virginia * * for more information: * Sanghyuk Son * Department of Computer Science * School of Engineering and Applied Science * University of Virginia * Charlottesville, VA 22903 */ #include "MachUseful.h" #include /* This program is inspired by "Time, Clocks, and the Ordering of Events in a Distributed System" by Lamport. Currently (MK83g), deadline enforcement across hosts is difficult because their physical clocks aren't explicitly synchronized. The real-time clocks that RT-Mach uses typically measure the time since the host was booted, so hosts which aren't rebooted simultaneously are likely out of sync. Lamport's idea is to attach a timestamp to each message as it is sent from one host to another. Upon receipt, a host compares the time according to its own clock and an estimate of the time according to the other host's clock and updates its own clock to the later of the two times. Although ideally this should by done by the RT-Mach IPC mechanism itself, this program makes a best-effort attempt. Rather than attach a timestamp to each message, a client process periodically sends special synchronization message to a server on another host. Synchronization is done according to the timestamp returned in the response. To synchronize the physical clocks of two hosts, A and B, run Mach's netmsgserver (not snames!) and the time server on each. Then start up one client on host A, supplying the other host's name (B). Start up another client on host B, supplying the name of host A. */ int atoi (char *); void bzero (char *, int); void printf (char *, ...); void puts (char *); void sleep (int); kern_return_t clock_set_time (mach_clock_t, timespec_t *); /* Enforcing deadlines accurately is important for all transactions, so all threads involved in this program should be scheduled at highest priority */ #define CRITICALITY 0 typedef struct { rt_mach_msg_header_t header; mach_msg_type_t descriptor; } ClockSyncRequestMessage; typedef struct { rt_mach_msg_header_t header; mach_msg_type_t descriptor; timespec_t timeStamp; } ClockSyncReplyMessage;