Commit bcd0dad561e84f0fd939f04faab37b2ebb2a92a8
1 parent
8a0c6a1f72
Exists in
master
Network Benchmarks
Showing 16 changed files with 609 additions and 58 deletions Side-by-side Diff
- cpu/a.out
- network/ocli
- network/oser
- network/overhead_client.c
- network/overhead_server.c
- network/peak_client.c
- network/peak_server.c
- network/rand
- network/random_str.c
- network/rtt_client.c
- network/rtt_server.c
- network/run_script.sh
- network/tcp_rtt_client.bul
- network/tcp_rtt_server.c
- osproject_task.c
- rasperf.h
cpu/a.out
View file @
bcd0dad
network/ocli
View file @
bcd0dad
network/oser
View file @
bcd0dad
network/overhead_client.c
View file @
bcd0dad
1 | +#include "../rasperf.h" | |
2 | +#include<stdio.h> | |
3 | +#include<stdlib.h> | |
4 | +#include<arpa/inet.h> | |
5 | +#include<sys/types.h> | |
6 | +#include<sys/socket.h> | |
7 | +#include<netdb.h> | |
8 | +#include<string.h> | |
9 | +//Macro definitions | |
10 | +#define handle_error(msg) \ | |
11 | + do { perror(msg); exit(1);} while(0); | |
12 | +#define BACKLOG 50 | |
13 | +int main(int argc, char*argv[]) | |
14 | +{ | |
15 | + int socket_fd, rc; | |
16 | + float start_delta = 0, close_delta = 0; | |
17 | + if(argc<2){ | |
18 | + handle_error("<usage>:tcp_client <IP address>"); | |
19 | + } | |
20 | + //Retrieve the protocol number mapping | |
21 | + //from /etc/protocols file | |
22 | + struct protoent *proto_entry; | |
23 | + proto_entry = getprotobyname("tcp"); | |
24 | + | |
25 | + | |
26 | + //My address information to bind to | |
27 | + struct sockaddr_in server; | |
28 | + memset(&server, 0, sizeof(struct sockaddr)); | |
29 | + server.sin_family = AF_INET; | |
30 | + server.sin_port = htons(8000); | |
31 | + | |
32 | + rc= inet_pton(AF_INET, argv[1], &server.sin_addr); | |
33 | + if(rc == -1){ | |
34 | + handle_error("Address Error"); | |
35 | + } | |
36 | + time starttime, endtime; | |
37 | + //accept incoming connections | |
38 | + int addr_size = sizeof(struct sockaddr); | |
39 | + int i; | |
40 | + int protonum = proto_entry->p_proto; | |
41 | + for(i=1;i<=BACKLOG;i++){ | |
42 | + getTime(starttime); | |
43 | + //Open an socket end-point for this TCP Server | |
44 | + if((socket_fd = socket(AF_INET, SOCK_STREAM, protonum))<0){ | |
45 | + handle_error("Socket Error"); | |
46 | + } | |
47 | + if(connect(socket_fd, (struct sockaddr*)&server, sizeof(server))<0){ | |
48 | + handle_error("Connection Error"); | |
49 | + } | |
50 | + /*The end calculated here will miss time taken for ACK K+1 | |
51 | + from the client. And so we have to one way delay | |
52 | + measured using another experiment*/ | |
53 | + getTime(endtime); | |
54 | + | |
55 | + //Calculate connection overhead client | |
56 | + start_delta+=diff(endtime,starttime); | |
57 | + | |
58 | + getTime(starttime); | |
59 | + shutdown(socket_fd, SHUT_RDWR); | |
60 | + getTime(endtime); | |
61 | + | |
62 | + //Calculate connection overhead server side | |
63 | + close_delta+=diff(endtime,starttime); | |
64 | + } | |
65 | + printf("Connection Setup =%f us\n", (start_delta + RTT/2 * BACKLOG)/BACKLOG); | |
66 | + printf("Connection Teardown =%f us\n", (close_delta + RTT/2 * BACKLOG)/BACKLOG); | |
67 | + return 0; | |
68 | +} | |
69 | + | |
70 | + |
network/overhead_server.c
View file @
bcd0dad
1 | +#include "../rasperf.h" | |
2 | +#include<stdio.h> | |
3 | +#include<stdlib.h> | |
4 | +#include<arpa/inet.h> | |
5 | +#include<sys/types.h> | |
6 | +#include<sys/wait.h> | |
7 | +#include<sys/socket.h> | |
8 | +#include<netdb.h> | |
9 | +#include<string.h> | |
10 | + | |
11 | +//Macro definitions | |
12 | +#define handle_error(msg) \ | |
13 | + do { perror(msg); exit(1);} while(0); | |
14 | +#define LISTEN_BACKLOG 100 | |
15 | + | |
16 | +int main(int argc, char*argv[]) | |
17 | +{ | |
18 | + int socket_fd, rc; | |
19 | + float setup_delta, close_delta; | |
20 | + if(argc<1){ | |
21 | + handle_error("<usage>:tcp_server"); | |
22 | + } | |
23 | + //Retrieve the protocol number mapping | |
24 | + //from /etc/protocols file | |
25 | + struct protoent *proto_entry; | |
26 | + proto_entry = getprotobyname("tcp"); | |
27 | + | |
28 | + //Open an socket end-point for this TCP Server | |
29 | + socket_fd = socket(AF_INET, SOCK_STREAM, proto_entry->p_proto); | |
30 | + if(socket_fd == -1){ | |
31 | + handle_error("Socket descriptor creation failed"); | |
32 | + } | |
33 | + | |
34 | + //My address information to bind to | |
35 | + struct sockaddr_in sock_addr; | |
36 | + memset(&sock_addr, 0, sizeof(struct sockaddr)); | |
37 | + sock_addr.sin_family = AF_INET; | |
38 | + sock_addr.sin_addr.s_addr = htonl(INADDR_ANY); | |
39 | + sock_addr.sin_port = htons(8000); | |
40 | + | |
41 | + | |
42 | + rc = bind(socket_fd, (struct sockaddr*)&sock_addr, sizeof(sock_addr)); | |
43 | + if(rc == -1){ | |
44 | + handle_error("Bind failure"); | |
45 | + } | |
46 | + rc = listen(socket_fd, LISTEN_BACKLOG); | |
47 | + if(rc == -1){ | |
48 | + handle_error(" Listen Error"); | |
49 | + } | |
50 | + | |
51 | + time starttime, endtime; | |
52 | + | |
53 | + //accept incoming connections | |
54 | + int connfd, i, pid, addr_size = sizeof(struct sockaddr); | |
55 | + for(i=1;i<=1000;i++) | |
56 | + { | |
57 | + printf("Accept Connection\n"); | |
58 | + waitpid(WAIT_ANY, NULL, WNOHANG); | |
59 | + connfd = accept(socket_fd, (struct sockaddr *)NULL, NULL); | |
60 | + if( connfd == -1){ | |
61 | + handle_error("Accept failed"); | |
62 | + } | |
63 | + if(pid = fork() == 0){ | |
64 | + //close the copy of socket descriptor | |
65 | + //child should not medle with it.. | |
66 | + close(socket_fd); | |
67 | + close(connfd); | |
68 | + printf("Connection %d closed in Child\n",i); | |
69 | + exit(0); | |
70 | + } | |
71 | + close(connfd); | |
72 | + } | |
73 | + close(socket_fd); | |
74 | + | |
75 | + return 0; | |
76 | +} | |
77 | + | |
78 | + |
network/peak_client.c
View file @
bcd0dad
1 | +#include "../rasperf.h" | |
2 | +#include<stdio.h> | |
3 | +#include<stdlib.h> | |
4 | +#include<arpa/inet.h> | |
5 | +#include<sys/types.h> | |
6 | +#include<sys/socket.h> | |
7 | +#include<netdb.h> | |
8 | +#include<string.h> | |
9 | +//Macro definitions | |
10 | +#define handle_error(msg) \ | |
11 | + do { perror(msg); exit(1);} while(0); | |
12 | +#define BACKLOG 50 | |
13 | +int main(int argc, char*argv[]) | |
14 | +{ | |
15 | + int socket_fd, rc; | |
16 | + float start_delta = 0, close_delta = 0; | |
17 | + if(argc<2){ | |
18 | + handle_error("<usage>:tcp_client <IP address>"); | |
19 | + } | |
20 | + //Retrieve the protocol number mapping | |
21 | + //from /etc/protocols file | |
22 | + struct protoent *proto_entry; | |
23 | + proto_entry = getprotobyname("tcp"); | |
24 | + | |
25 | + | |
26 | + //My address information to bind to | |
27 | + struct sockaddr_in server; | |
28 | + memset(&server, 0, sizeof(struct sockaddr)); | |
29 | + server.sin_family = AF_INET; | |
30 | + server.sin_port = htons(8000); | |
31 | + | |
32 | + rc= inet_pton(AF_INET, argv[1], &server.sin_addr); | |
33 | + if(rc == -1){ | |
34 | + handle_error("Address Error"); | |
35 | + } | |
36 | + time starttime, endtime; | |
37 | + //accept incoming connections | |
38 | + int addr_size = sizeof(struct sockaddr); | |
39 | + int i; | |
40 | + int protonum = proto_entry->p_proto; | |
41 | + for(i=1;i<=BACKLOG;i++){ | |
42 | + getTime(starttime); | |
43 | + //Open an socket end-point for this TCP Server | |
44 | + if((socket_fd = socket(AF_INET, SOCK_STREAM, protonum))<0){ | |
45 | + handle_error("Socket Error"); | |
46 | + } | |
47 | + if(connect(socket_fd, (struct sockaddr*)&server, sizeof(server))<0){ | |
48 | + handle_error("Connection Error"); | |
49 | + } | |
50 | + /*The end calculated here will miss time taken for ACK K+1 | |
51 | + from the client. And so we have to one way delay | |
52 | + measured using another experiment*/ | |
53 | + getTime(endtime); | |
54 | + | |
55 | + //Calculate connection overhead client | |
56 | + start_delta+=diff(endtime,starttime); | |
57 | + | |
58 | + getTime(starttime); | |
59 | + close(socket_fd); | |
60 | + getTime(endtime); | |
61 | + | |
62 | + //Calculate connection overhead server side | |
63 | + close_delta+=diff(endtime,starttime); | |
64 | + } | |
65 | + printf("Connection Setup =%f us\n", (start_delta + RTT/2 * BACKLOG)/BACKLOG); | |
66 | + printf("Connection Teardown =%f us\n", (close_delta + RTT/2 * BACKLOG)/BACKLOG); | |
67 | + return 0; | |
68 | +} | |
69 | + | |
70 | + |
network/peak_server.c
View file @
bcd0dad
1 | +#include "../rasperf.h" | |
2 | +#include<stdio.h> | |
3 | +#include<stdlib.h> | |
4 | +#include<arpa/inet.h> | |
5 | +#include<sys/types.h> | |
6 | +#include<sys/wait.h> | |
7 | +#include<sys/socket.h> | |
8 | +#include<netdb.h> | |
9 | +#include<string.h> | |
10 | + | |
11 | +//Macro definitions | |
12 | +#define handle_error(msg) \ | |
13 | + do { perror(msg); exit(1);} while(0); | |
14 | +#define LISTEN_BACKLOG 50 | |
15 | + | |
16 | +int main(int argc, char*argv[]) | |
17 | +{ | |
18 | + int socket_fd, rc; | |
19 | + float setup_delta, close_delta; | |
20 | + if(argc<1){ | |
21 | + handle_error("<usage>:tcp_server"); | |
22 | + } | |
23 | + //Retrieve the protocol number mapping | |
24 | + //from /etc/protocols file | |
25 | + struct protoent *proto_entry; | |
26 | + proto_entry = getprotobyname("tcp"); | |
27 | + | |
28 | + //Open an socket end-point for this TCP Server | |
29 | + socket_fd = socket(AF_INET, SOCK_STREAM, proto_entry->p_proto); | |
30 | + if(socket_fd == -1){ | |
31 | + handle_error("Socket descriptor creation failed"); | |
32 | + } | |
33 | + | |
34 | + //My address information to bind to | |
35 | + struct sockaddr_in sock_addr; | |
36 | + memset(&sock_addr, 0, sizeof(struct sockaddr)); | |
37 | + sock_addr.sin_family = AF_INET; | |
38 | + sock_addr.sin_addr.s_addr = htonl(INADDR_ANY); | |
39 | + sock_addr.sin_port = htons(8000); | |
40 | + | |
41 | + | |
42 | + rc = bind(socket_fd, (struct sockaddr*)&sock_addr, sizeof(sock_addr)); | |
43 | + if(rc == -1){ | |
44 | + handle_error("Bind failure"); | |
45 | + } | |
46 | + rc = listen(socket_fd, LISTEN_BACKLOG); | |
47 | + if(rc == -1){ | |
48 | + handle_error(" Listen Error"); | |
49 | + } | |
50 | + | |
51 | + time starttime, endtime; | |
52 | + | |
53 | + //accept incoming connections | |
54 | + int connfd, i, pid, addr_size = sizeof(struct sockaddr); | |
55 | + for(i=1;i<=1000;i++) | |
56 | + { | |
57 | + //getTime(starttime); | |
58 | + printf("Accept Connection\n"); | |
59 | + //waitpid(WAIT_ANY, NULL, WNOHANG); | |
60 | + connfd = accept(socket_fd, (struct sockaddr *)NULL, NULL); | |
61 | + /*The end calculated here would have missed SYN time | |
62 | + from the client. And so we have to add one | |
63 | + packet worth round trip time in the overhead*/ | |
64 | + //getTime(endtime); | |
65 | + if( connfd == -1){ | |
66 | + handle_error("Accept failed"); | |
67 | + } | |
68 | + //setup_delta+=diff(endtime,starttime); | |
69 | + if(pid = fork() == 0){ | |
70 | + close(socket_fd); | |
71 | + close(connfd); | |
72 | + printf("Connection %d closed in Child\n",i); | |
73 | + //close_delta=diff(endtime, starttime); | |
74 | + //printf("Connection Termination %f", close_delta + RTT); | |
75 | + exit(0); | |
76 | + } | |
77 | + close(connfd); | |
78 | + } | |
79 | + //getTime(starttime); | |
80 | + close(socket_fd); | |
81 | + //getTime(endtime); | |
82 | + | |
83 | + //Calculate connection overhead server side | |
84 | + //setup_delta+=diff(endtime,starttime); | |
85 | + //printf("Connection Overhead:Setup =%f us\n", (setup_delta+ RTT*600)/600); | |
86 | + | |
87 | + return 0; | |
88 | +} | |
89 | + | |
90 | + |
network/rand
View file @
bcd0dad
network/random_str.c
View file @
bcd0dad
1 | +#include<stdio.h> | |
2 | +#include<stdlib.h> | |
3 | +char* generate_string(int length) | |
4 | +{ | |
5 | + //Random number seed | |
6 | + srand((unsigned int) ctime(0)); | |
7 | + char * buff; | |
8 | + buff=(char *)malloc(sizeof(char)*length); | |
9 | + int i; | |
10 | + for(i=0;i< length-1;i++){ | |
11 | + buff[i] = rand() % rand() % (126 - 33 + 1) + 33; | |
12 | + } | |
13 | + buff[i] = '\0'; | |
14 | + return buff; | |
15 | +} | |
16 | +int main() | |
17 | +{ | |
18 | + char *buf; | |
19 | + buf = generate_string(5); | |
20 | + printf("String of 5: %s", buf); | |
21 | + free(buf); | |
22 | + | |
23 | + buf = generate_string(40); | |
24 | + printf("String of 5: %s", buf); | |
25 | + free(buf); | |
26 | + | |
27 | + buf = generate_string(80); | |
28 | + printf("String of 5: %s", buf); | |
29 | + free(buf); | |
30 | + | |
31 | + return 0; | |
32 | +} |
network/rtt_client.c
View file @
bcd0dad
1 | +#include "../rasperf.h" | |
2 | +#include<stdio.h> | |
3 | +#include<stdlib.h> | |
4 | +#include<arpa/inet.h> | |
5 | +#include<sys/types.h> | |
6 | +#include<sys/socket.h> | |
7 | +#include<netdb.h> | |
8 | +#include<string.h> | |
9 | +//Macro definitions | |
10 | +#define handle_error(msg) \ | |
11 | + do { perror(msg); exit(1);} while(0); | |
12 | +#define BUFFER_SIZE 2048 | |
13 | +#define STRIDE_SIZE 64 | |
14 | +#define BACKLOG 32 //buff size/stride size | |
15 | + | |
16 | +//A random string generator of given length | |
17 | +char* generate_string(int length) | |
18 | +{ | |
19 | + //Random number seed | |
20 | + srand((unsigned int) ctime(0)); | |
21 | + char * buff; | |
22 | + buff=(char *)malloc(sizeof(char)*length); | |
23 | + int i; | |
24 | + for(i=0;i< length-1;i++){ | |
25 | + buff[i] = rand() % rand() % (126 - 33 + 1) + 33; | |
26 | + } | |
27 | + buff[i] = '\0'; | |
28 | + return buff; | |
29 | +} | |
30 | + | |
31 | +int main(int argc, char*argv[]) | |
32 | +{ | |
33 | + int socket_fd, rc; | |
34 | + char buf[BUFFER_SIZE]; | |
35 | + char *msg; | |
36 | + float start_delta = 0, close_delta = 0; | |
37 | + if(argc<2){ | |
38 | + handle_error("<usage>:tcp_client <IP address>"); | |
39 | + } | |
40 | + //Retrieve the protocol number mapping | |
41 | + //from /etc/protocols file | |
42 | + struct protoent *proto_entry; | |
43 | + proto_entry = getprotobyname("tcp"); | |
44 | + | |
45 | + | |
46 | + //My address information to bind to | |
47 | + struct sockaddr_in server; | |
48 | + memset(&server, 0, sizeof(struct sockaddr)); | |
49 | + server.sin_family = AF_INET; | |
50 | + server.sin_port = htons(8000); | |
51 | + | |
52 | + rc= inet_pton(AF_INET, argv[1], &server.sin_addr); | |
53 | + if(rc == -1){ | |
54 | + handle_error("Address Error"); | |
55 | + } | |
56 | + time starttime, endtime; | |
57 | + //accept incoming connections | |
58 | + int addr_size = sizeof(struct sockaddr); | |
59 | + int i; | |
60 | + int protonum = proto_entry->p_proto; | |
61 | + | |
62 | + //Open an socket end-point for this TCP Server | |
63 | + if((socket_fd = socket(AF_INET, SOCK_STREAM, protonum))<0){ | |
64 | + handle_error("Socket Error"); | |
65 | + } | |
66 | + if(connect(socket_fd, (struct sockaddr*)&server, sizeof(server))<0){ | |
67 | + handle_error("Connection Error"); | |
68 | + } | |
69 | + | |
70 | + for(i=1;i<=BACKLOG;i++){ | |
71 | + //increase the sent message in strides of 64 | |
72 | + //look for for peak rtt | |
73 | + msg = generate_string(STRIDE_SIZE * i); | |
74 | + printf("String Generated: \"%s\"",msg); | |
75 | + getTime(starttime); | |
76 | + if(send(socket_fd, msg, sizeof(msg), 0) <0){ | |
77 | + handler_error("Send Error"); | |
78 | + } | |
79 | + //The recv buffer size is same as the one we sent | |
80 | + if(recv(socket_fd, buff, sizeof(msg), 0) != sizeof(msg)){ | |
81 | + handle_error("Data over/ Receive Error"); | |
82 | + } | |
83 | + getTime(endtime); | |
84 | + delta+=diff(endtime, starttime); | |
85 | + printf("Single RTT %f", diff(endtime, starttime)); | |
86 | + | |
87 | + } | |
88 | + | |
89 | + close(socket_fd); | |
90 | + printf("Averaged RTT =%f us\n", delta/BACKLOG); | |
91 | + return 0; | |
92 | +} | |
93 | + | |
94 | + |
network/rtt_server.c
View file @
bcd0dad
1 | +#include "../rasperf.h" | |
2 | +#include<stdio.h> | |
3 | +#include<stdlib.h> | |
4 | +#include<arpa/inet.h> | |
5 | +#include<sys/types.h> | |
6 | +#include<sys/wait.h> | |
7 | +#include<sys/socket.h> | |
8 | +#include<netdb.h> | |
9 | +#include<string.h> | |
10 | + | |
11 | +//Macro definitions | |
12 | +#define handle_error(msg) \ | |
13 | + do { perror(msg); exit(1);} while(0); | |
14 | +#define LISTEN_BACKLOG 100 | |
15 | +#define BUFFER_SIZE 2048 | |
16 | + | |
17 | +int main(int argc, char*argv[]) | |
18 | +{ | |
19 | + int socket_fd, rc; | |
20 | + char buff[BUFFER_SIZE], msg[BUFFER_SIZE]; | |
21 | + char | |
22 | + float setup_delta, close_delta; | |
23 | + if(argc<1){ | |
24 | + handle_error("<usage>:tcp_server"); | |
25 | + } | |
26 | + //Retrieve the protocol number mapping | |
27 | + //from /etc/protocols file | |
28 | + struct protoent *proto_entry; | |
29 | + proto_entry = getprotobyname("tcp"); | |
30 | + | |
31 | + //Open an socket end-point for this TCP Server | |
32 | + socket_fd = socket(AF_INET, SOCK_STREAM, proto_entry->p_proto); | |
33 | + if(socket_fd == -1){ | |
34 | + handle_error("Socket descriptor creation failed"); | |
35 | + } | |
36 | + | |
37 | + //My address information to bind to | |
38 | + struct sockaddr_in sock_addr; | |
39 | + memset(&sock_addr, 0, sizeof(struct sockaddr)); | |
40 | + sock_addr.sin_family = AF_INET; | |
41 | + sock_addr.sin_addr.s_addr = htonl(INADDR_ANY); | |
42 | + sock_addr.sin_port = htons(8000); | |
43 | + | |
44 | + | |
45 | + rc = bind(socket_fd, (struct sockaddr*)&sock_addr, sizeof(sock_addr)); | |
46 | + if(rc == -1){ | |
47 | + handle_error("Bind failure"); | |
48 | + } | |
49 | + rc = listen(socket_fd, LISTEN_BACKLOG); | |
50 | + if(rc == -1){ | |
51 | + handle_error(" Listen Error"); | |
52 | + } | |
53 | + | |
54 | + time starttime, endtime; | |
55 | + //accept incoming connections | |
56 | + int connfd, i, pid, addr_size = sizeof(struct sockaddr); | |
57 | + printf("Accept Connection\n"); | |
58 | + connfd = accept(socket_fd, (struct sockaddr *)NULL, NULL); | |
59 | + if( connfd == -1){ | |
60 | + handle_error("Accept failed"); | |
61 | + } | |
62 | + for(i=1;i<=BACKLOG;i++) | |
63 | + { | |
64 | + getTime(starttime); | |
65 | + if(recv(connfd, buff, sizeof(i* STRIDE_SIZE), 0)!= sizeof(i* STRIDE_SIZE)){ | |
66 | + handle_error("Receive Error/ Data Done"); | |
67 | + } | |
68 | + if(send(connfd, buff, sizeof(i * STRIDE_SIZE), 0)<0){ | |
69 | + handle_error("Send Error"); | |
70 | + } | |
71 | + getTime(endtime); | |
72 | + } | |
73 | + | |
74 | + close(socket_fd); | |
75 | + close(connfd); | |
76 | + printf("Connection %d closed in Child\n",i); | |
77 | + return 0; | |
78 | +} | |
79 | + |
network/run_script.sh
View file @
bcd0dad
network/tcp_rtt_client.bul
View file @
bcd0dad
1 | +#include "../rasperf.h" | |
2 | +#include<stdio.h> | |
3 | +#include<stdlib.h> | |
4 | +#include<arpa/inet.h> | |
5 | +#include<sys/types.h> | |
6 | +#include<sys/socket.h> | |
7 | +#include<netdb.h> | |
8 | +#include<string.h> | |
9 | +//Macro definitions | |
10 | +#define handle_error(msg) \ | |
11 | + do { perror(msg); exit(1);} while(0); | |
12 | +#define BACKLOG 1 | |
13 | +int main(int argc, char*argv[]) | |
14 | +{ | |
15 | + int socket_fd, rc; | |
16 | + float start_delta = 0, close_delta = 0; | |
17 | + if(argc<2){ | |
18 | + handle_error("<usage>:tcp_client <IP address>"); | |
19 | + } | |
20 | + //Retrieve the protocol number mapping | |
21 | + //from /etc/protocols file | |
22 | + struct protoent *proto_entry; | |
23 | + proto_entry = getprotobyname("tcp"); | |
24 | + | |
25 | + | |
26 | + //My address information to bind to | |
27 | + struct sockaddr_in server; | |
28 | + memset(&server, 0, sizeof(struct sockaddr)); | |
29 | + server.sin_family = AF_INET; | |
30 | + server.sin_port = htons(8000); | |
31 | + | |
32 | + rc= inet_pton(AF_INET, argv[1], &server.sin_addr); | |
33 | + if(rc == -1){ | |
34 | + handle_error("Address Error"); | |
35 | + } | |
36 | + time starttime, endtime; | |
37 | + //accept incoming connections | |
38 | + int addr_size = sizeof(struct sockaddr); | |
39 | + int i; | |
40 | + int protonum = proto_entry->p_proto; | |
41 | + for(i=1;i<=BACKLOG;i++){ | |
42 | + getTime(starttime); | |
43 | + //Open an socket end-point for this TCP Server | |
44 | + if((socket_fd = socket(AF_INET, SOCK_STREAM, protonum))<0){ | |
45 | + handle_error("Socket descriptor creation failed"); | |
46 | + } | |
47 | + if((connect(socket_fd, (struct sockaddr*)&server, sizeof(server)))<0){ | |
48 | + handle_error("Connect failed"); | |
49 | + } | |
50 | + /*The end calculated here will miss time taken for ACK K+1 | |
51 | + from the client. And so we have to one way delay | |
52 | + measured using another experiment*/ | |
53 | + getTime(endtime); | |
54 | + | |
55 | + //Calculate connection overhead client | |
56 | + start_delta+=diff(endtime,starttime); | |
57 | + printf("EndTime: %f usec\n", endtime.tv_sec + endtime.tv_usec*1e6); | |
58 | + printf("Start time:%f usec\n", starttime.tv_sec +starttime.tv_usec*1e6); | |
59 | + printf("Setup:%f\n",diff(endtime,starttime) + 25); | |
60 | + | |
61 | + getTime(starttime); | |
62 | + sleep(1); | |
63 | + close(socket_fd); | |
64 | + getTime(endtime); | |
65 | + printf("Endtime %f usec\n", endtime.tv_sec + endtime.tv_usec*1e6); | |
66 | + printf("Start time:%f usec\n", starttime.tv_sec +starttime.tv_usec*1e6); | |
67 | + printf("TearDown:%f\n",diff(endtime,starttime) + 25); | |
68 | + //Calculate connection overhead server side | |
69 | + close_delta+=diff(endtime,starttime); | |
70 | + } | |
71 | + printf("Connection Setup =%f us\n", (start_delta + RTT/2 * BACKLOG)/BACKLOG); | |
72 | + printf("Connection Teardown =%f us\n", (close_delta + RTT/2 * BACKLOG)/BACKLOG); | |
73 | + return 0; | |
74 | +} | |
75 | + | |
76 | + |
network/tcp_rtt_server.c
View file @
bcd0dad
1 | -#include "../rasperf.h" | |
2 | -#include<arpa/inet.h> | |
3 | -#include<sys/typesh> | |
4 | -#include<sys/socket.h> | |
5 | -#include<netdb.h> | |
6 | - | |
7 | -//Macro definitions | |
8 | -#define handle_error(msg) \ | |
9 | - do { perror(msg); exit(EXIT_FAILURE);} while(0) | |
10 | -#define LISTEN_BACKLOG 5 | |
11 | -int main(int argc, char*argv[]) | |
12 | -{ | |
13 | - int socket_fd, rc; | |
14 | - if(argc<1){ | |
15 | - handle_error("<usage>:"); | |
16 | - } | |
17 | - //Retrieve the protocol number mapping | |
18 | - //from /etc/protocols file | |
19 | - struct protoent *proto_entry; | |
20 | - proto_entry = getprotobyname("tcp"); | |
21 | - | |
22 | - //Open an socket end-point for this TCP Server | |
23 | - socket_fd = socket(AF_INET, SOCK_STREAM, proto_entry->p_proto); | |
24 | - if(socket_fd == -1){ | |
25 | - handle_error("Errno: %d,Socket descriptor creation failed", errorno); | |
26 | - } | |
27 | - | |
28 | - //My address information to bind to | |
29 | - struct sockaddr sock_addr; | |
30 | - memset(&sock_addr, 0, sizeof(struct sockaddr)); | |
31 | - sock_addr.sa_family = AF_INET; | |
32 | - sock_addr.sin_addr.s_addr = htonl(INADDR_ANY); | |
33 | - sock_addr.sin_port = htons(8000); | |
34 | - | |
35 | - | |
36 | - rc = bind(sock_fd, &sock_addr, sizeof(sock_addr)); | |
37 | - if(rc == -1){ | |
38 | - handle_error("Errno: %d, Bind failure", errorno); | |
39 | - } | |
40 | - rc = listen(socket_fd, LISTEN_BACKLOG); | |
41 | - if(rc == -1){ | |
42 | - handle_error("Errno: %d, Listen Error", errorno); | |
43 | - } | |
44 | - | |
45 | - int addr_size = sizeof(struct sockaddr); | |
46 | - rc= accept(sock_fd, &sock_addr, &addr_size); | |
47 | - if( rc == -1){ | |
48 | - handle_error("Error: %d,Accept failed", errorno); | |
49 | - } | |
50 | - |
osproject_task.c
View file @
bcd0dad
... | ... | @@ -7,13 +7,12 @@ |
7 | 7 | unsigned int a, b; |
8 | 8 | unsigned int avg; |
9 | 9 | int status; |
10 | - asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r" (regr)); | |
10 | + readCCNT(regr); | |
11 | 11 | printf("regr: %x\n", regr); |
12 | - | |
13 | - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (a)); | |
12 | + getTime(a); | |
14 | 13 | int pid = fork(); |
15 | 14 | if (pid) { |
16 | - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (b)); | |
15 | + getTime(b); | |
17 | 16 | printf("Time for fork: %u\n", b - a); |
18 | 17 | } |
19 | 18 |
rasperf.h
View file @
bcd0dad
1 | + | |
1 | 2 | #ifndef __RASPERF_H__ |
3 | +#define NULL '\0' | |
2 | 4 | #define __RASPERF_H__ |
3 | -#define PI 1 | |
4 | -#define x86 0 | |
5 | +#define RTT 35 //in MicroSec | |
6 | +#define PI 0 | |
7 | +#define x86 1 | |
8 | +#define CPU_CYCLES 900 | |
9 | +#define MHz 1e6 | |
5 | 10 | #if defined(PI) && PI |
6 | 11 | #define time unsigned int |
7 | 12 | #define getTime(var) \ |
8 | 13 | |
... | ... | @@ -12,13 +17,14 @@ |
12 | 17 | asm volatile (\ |
13 | 18 | "mrc p15, 0, %0, c9, c14, 0":\ |
14 | 19 | "=r" (var)); |
15 | -#define diff(end, begin) (end - begin) | |
20 | +#define diff(end, begin) \ | |
21 | + (end - begin)/ CPU_CYCLES}; | |
16 | 22 | #endif |
17 | 23 | #if defined(x86) && x86 |
18 | 24 | #define time struct timeval |
19 | 25 | #define getTime(var) gettimeofday(&var, NULL) |
20 | 26 | #define diff(end, begin) \ |
21 | - (end.tv_sec*1e6+end.tv_usec - begin.tv_sec*1e6+ begin.tv_usec) | |
27 | + ((end.tv_sec*1e6+end.tv_usec) - (begin.tv_sec*1e6+ begin.tv_usec)) | |
22 | 28 | #endif |
23 | 29 | #endif |