testsh2.sh: change output to new cksum util
[minix.git] / test / safeperf / requestor.c
blobbbb9642c7527724c52bbaa5867b875876744986a
1 #include "inc.h"
3 char buf_buf[BUF_SIZE + CLICK_SIZE];
5 endpoint_t ep_granter;
6 cp_grant_id_t gid;
7 char *buf;
8 int fid_send, fid_get;
10 /* SEF functions and variables. */
11 static void sef_local_startup(void);
13 /*===========================================================================*
14 * read_write_buff *
15 *===========================================================================*/
16 void read_write_buff(char* buff, int size, int is_write)
18 int i;
19 char c;
21 if(size % CLICK_SIZE != 0) {
22 panic("buff_size not page aligned");
24 if(is_write) {
25 for(i=0;i<size;i+=CLICK_SIZE) buff[i] = 1;
27 else {
28 for(i=0;i<size;i+=CLICK_SIZE) c = buff[i];
32 /*===========================================================================*
33 * exit_usage *
34 *===========================================================================*/
35 void exit_usage(void)
37 printf("Usage: requestor pages=<nr_pages> map=<0|1> write=<0|1>\n");
38 exit(1);
41 /*===========================================================================*
42 * main *
43 *===========================================================================*/
44 int main(int argc, char **argv)
46 endpoint_t ep_self, ep_child;
47 size_t size = BUF_SIZE;
48 int i, r, pid;
49 int status;
50 u64_t start, end, diff;
51 double micros;
52 char nr_pages_str[10], is_map_str[2], is_write_str[2];
53 int nr_pages, is_map, is_write;
55 /* SEF local startup. */
56 env_setargs(argc, argv);
57 sef_local_startup();
59 /* Parse the command line. */
60 r = env_get_param("pages", nr_pages_str, sizeof(nr_pages_str));
61 errno = 0;
62 nr_pages = atoi(nr_pages_str);
63 if (r != OK || errno || nr_pages <=0) {
64 exit_usage();
66 if(nr_pages > TEST_PAGE_NUM) {
67 printf("REQUESTOR: too many pages. Max allowed: %d\n",
68 TEST_PAGE_NUM);
69 exit_usage();
71 r = env_get_param("map", is_map_str, sizeof(is_map_str));
72 errno = 0;
73 is_map = atoi(is_map_str);
74 if (r != OK || errno || (is_map!=0 && is_map!=1)) {
75 exit_usage();
77 r = env_get_param("write", is_write_str, sizeof(is_write_str));
78 errno = 0;
79 is_write = atoi(is_write_str);
80 if (r != OK || errno || (is_write!=0 && is_write!=1)) {
81 exit_usage();
83 printf("REQUESTOR: Running tests with pages=%d map=%d write=%d...\n",
84 nr_pages, is_map, is_write);
86 /* Prepare work. */
87 buf = (char*) CLICK_CEIL(buf_buf);
88 fid_get = open(FIFO_GRANTOR, O_RDONLY);
89 fid_send = open(FIFO_REQUESTOR, O_WRONLY);
90 if(fid_get < 0 || fid_send < 0) {
91 printf("REQUESTOR: can't open fifo files.\n");
92 return 1;
95 /* Send the endpoint to the granter, in order to let him to
96 * create the grant.
98 ep_self = getprocnr();
99 write(fid_send, &ep_self, sizeof(ep_self));
100 dprint("REQUESTOR: sending my endpoint: %d\n", ep_self);
102 /* Get the granter's endpoint and gid. */
103 read(fid_get, &ep_granter, sizeof(ep_granter));
104 read(fid_get, &gid, sizeof(gid));
105 dprint("REQUESTOR: getting granter's endpoint %d and gid %d\n",
106 ep_granter, gid);
108 FIFO_WAIT(fid_get);
109 diff = make64(0, 0);
111 if(is_map) {
112 /* Test safemap. */
113 for(i=0;i<NR_TEST_ITERATIONS;i++) {
114 read_tsc_64(&start);
115 r = sys_safemap(ep_granter, gid, 0, (long)buf,
116 nr_pages*CLICK_SIZE, D, 1);
117 if(r != OK) {
118 printf("REQUESTOR: safemap error: %d\n", r);
119 return 1;
121 read_write_buff(buf, nr_pages*CLICK_SIZE, is_write);
122 read_tsc_64(&end);
123 diff = add64(diff, (sub64(end, start)));
124 r = sys_safeunmap(D, (long)buf);
125 if(r != OK) {
126 printf("REQUESTOR: safeunmap error: %d\n", r);
127 return 1;
130 micros = ((double)tsc_64_to_micros(diff))
131 / (NR_TEST_ITERATIONS*nr_pages);
132 REPORT_TEST("REQUESTOR", "SAFEMAP", micros);
134 else {
135 /* Test safecopy. */
136 for(i=0;i<NR_TEST_ITERATIONS;i++) {
137 read_tsc_64(&start);
138 r = sys_safecopyfrom(ep_granter, gid, 0, (long)buf,
139 nr_pages*CLICK_SIZE);
140 if(r != OK) {
141 printf("REQUESTOR: safecopy error: %d\n", r);
142 return 1;
144 read_write_buff(buf, nr_pages*CLICK_SIZE, is_write);
145 read_tsc_64(&end);
146 diff = add64(diff, (sub64(end, start)));
148 micros = ((double)tsc_64_to_micros(diff))
149 / (NR_TEST_ITERATIONS*nr_pages);
150 REPORT_TEST("REQUESTOR", "SAFECOPY", micros);
153 FIFO_NOTIFY(fid_send);
155 return 0;
158 /*===========================================================================*
159 * sef_local_startup *
160 *===========================================================================*/
161 static void sef_local_startup()
163 /* Let SEF perform startup. */
164 sef_startup();