From ee97b6227b8326bff650c1b41264fe425de39e52 Mon Sep 17 00:00:00 2001 From: adash Date: Wed, 25 Nov 2009 02:44:00 +0000 Subject: [PATCH] get time offset of all remote machines while synchronizing clocks --- .../Runtime/DSTM/interface/clocksyncclient.c | 126 ++++++++++++++++++ .../Runtime/DSTM/interface/clocksyncserver.c | 122 +++++++++++++++++ 2 files changed, 248 insertions(+) create mode 100644 Robust/src/Runtime/DSTM/interface/clocksyncclient.c create mode 100644 Robust/src/Runtime/DSTM/interface/clocksyncserver.c diff --git a/Robust/src/Runtime/DSTM/interface/clocksyncclient.c b/Robust/src/Runtime/DSTM/interface/clocksyncclient.c new file mode 100644 index 00000000..749ac47e --- /dev/null +++ b/Robust/src/Runtime/DSTM/interface/clocksyncclient.c @@ -0,0 +1,126 @@ +/** This program runs the client for clock synchronization on all machines + Client on all machines **/ +// One clock tick = (1 / CPU processor speed in Hz) secs +//compile: +// gcc -Wall -o server clocksyncclient.c +// + +#include +#include +#include +#include +#include +#include +#include +#include + +#define PORT 8500 + /* REPLACE with your server machine name*/ +#define DIRSIZE 64 +#define NUMITER 1024 + + +static __inline__ unsigned long long rdtsc(void) +{ + unsigned hi, lo; + __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); + return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 ); +} + +int main(int argc, char **argv) { + unsigned long long dir[1]; + int sd; + struct sockaddr_in pin; + struct hostent *hp; + + unsigned long long array1[NUMITER]; + unsigned long long array2[NUMITER]; + + char *hostname=NULL; + if(argc == 1) { + printf("%s\n", "This program needs arguments....\n\n"); + exit(0); + } + + if((strcmp(argv[1], "2")) == 0) { + hostname="dc-2"; + } else if((strcmp(argv[1], "3")) == 0) { + hostname="dc-3"; + } else if((strcmp(argv[1], "4")) == 0) { + hostname="dc-4"; + } else if((strcmp(argv[1], "5")) == 0) { + hostname="dc-5"; + } else if ((strcmp(argv[1], "6")) == 0) { + hostname="dc-6"; + } else if ((strcmp(argv[1], "7")) == 0) { + hostname="dc-7"; + } else if ((strcmp(argv[1], "8")) == 0) { + hostname="dc-8"; + } else { + printf("hostname is not known \n"); + exit(-1); + } + + FILE *f1; + f1=fopen(hostname, "w"); + + /* go find out about the desired host machine */ + if ((hp = gethostbyname("dc-1.calit2.uci.edu")) == 0) { + perror("gethostbyname"); + exit(1); + } + + /* fill in the socket structure with host information */ + memset(&pin, 0, sizeof(pin)); + pin.sin_family = AF_INET; + pin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr; + pin.sin_port = htons(PORT); + + /* grab an Internet domain socket */ + if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { + perror("socket"); + exit(1); + } + + /* connect to PORT on HOST */ + if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) { + perror("connect"); + exit(1); + } + + int i; + char data[1]; + long long norm = 0; + recv(sd, data, sizeof(data), 0); + for (i=0; i +#include +#include +#include +#include +#include +#include +#include + +#define PORT 8500 +#define NUMITER 1024 +#define DIRSIZE 1 + +static __inline__ unsigned long long rdtsc(void) +{ + unsigned hi, lo; + __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); + return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 ); +} + +int main() { + unsigned long long dir[DIRSIZE]; /* used for incomming dir name, and + outgoing data */ + int sd, sd_current; + socklen_t addrlen; + struct sockaddr_in sin; + struct sockaddr_in pin; + + FILE *f1; + f1=fopen("dc-1", "w"); + + unsigned long long array1[NUMITER]; + unsigned long long array2[NUMITER]; + /* get an internet domain socket */ + if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { + perror("socket"); + exit(1); + } + + /* complete the socket structure */ + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = INADDR_ANY; + sin.sin_port = htons(PORT); + + /* bind the socket to the port number */ + if (bind(sd, (struct sockaddr *) &sin, sizeof(sin)) == -1) { + perror("bind"); + exit(1); + } + + /* show that we are willing to listen */ + if (listen(sd, 5) == -1) { + perror("listen"); + exit(1); + } + /* wait for a client to talk to us */ + addrlen = sizeof(pin); + if ((sd_current = accept(sd, (struct sockaddr *)&pin, &addrlen)) == -1) { + perror("accept"); + exit(1); + } + /* if you want to see the ip address and port of the client, uncomment the + next two lines */ + + /* + printf("Hi there, from %s#\n",inet_ntoa(pin.sin_addr)); + printf("Coming from port %d\n",ntohs(pin.sin_port)); + */ + + int i; + char data[1]; + data[0]='1'; + long long norm = 0; + send(sd_current, data, sizeof(data), MSG_NOSIGNAL); + for(i=0; i