3 char buf_buf
[BUF_SIZE
+ CLICK_SIZE
];
10 /* SEF functions and variables. */
11 static void sef_local_startup(void);
13 /*===========================================================================*
15 *===========================================================================*/
16 void read_write_buff(char* buff
, int size
, int is_write
)
21 if(size
% CLICK_SIZE
!= 0) {
22 panic("buff_size not page aligned");
25 for(i
=0;i
<size
;i
+=CLICK_SIZE
) buff
[i
] = 1;
28 for(i
=0;i
<size
;i
+=CLICK_SIZE
) c
= buff
[i
];
32 /*===========================================================================*
34 *===========================================================================*/
37 printf("Usage: requestor pages=<nr_pages> map=<0|1> write=<0|1>\n");
41 /*===========================================================================*
43 *===========================================================================*/
44 int main(int argc
, char **argv
)
46 endpoint_t ep_self
, ep_child
;
47 size_t size
= BUF_SIZE
;
50 u64_t start
, end
, diff
;
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
);
59 /* Parse the command line. */
60 r
= env_get_param("pages", nr_pages_str
, sizeof(nr_pages_str
));
62 nr_pages
= atoi(nr_pages_str
);
63 if (r
!= OK
|| errno
|| nr_pages
<=0) {
66 if(nr_pages
> TEST_PAGE_NUM
) {
67 printf("REQUESTOR: too many pages. Max allowed: %d\n",
71 r
= env_get_param("map", is_map_str
, sizeof(is_map_str
));
73 is_map
= atoi(is_map_str
);
74 if (r
!= OK
|| errno
|| (is_map
!=0 && is_map
!=1)) {
77 r
= env_get_param("write", is_write_str
, sizeof(is_write_str
));
79 is_write
= atoi(is_write_str
);
80 if (r
!= OK
|| errno
|| (is_write
!=0 && is_write
!=1)) {
83 printf("REQUESTOR: Running tests with pages=%d map=%d write=%d...\n",
84 nr_pages
, is_map
, is_write
);
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");
95 /* Send the endpoint to the granter, in order to let him to
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",
113 for(i
=0;i
<NR_TEST_ITERATIONS
;i
++) {
115 r
= sys_safemap(ep_granter
, gid
, 0, (long)buf
,
116 nr_pages
*CLICK_SIZE
, D
, 1);
118 printf("REQUESTOR: safemap error: %d\n", r
);
121 read_write_buff(buf
, nr_pages
*CLICK_SIZE
, is_write
);
123 diff
= add64(diff
, (sub64(end
, start
)));
124 r
= sys_safeunmap(D
, (long)buf
);
126 printf("REQUESTOR: safeunmap error: %d\n", r
);
130 micros
= ((double)tsc_64_to_micros(diff
))
131 / (NR_TEST_ITERATIONS
*nr_pages
);
132 REPORT_TEST("REQUESTOR", "SAFEMAP", micros
);
136 for(i
=0;i
<NR_TEST_ITERATIONS
;i
++) {
138 r
= sys_safecopyfrom(ep_granter
, gid
, 0, (long)buf
,
139 nr_pages
*CLICK_SIZE
);
141 printf("REQUESTOR: safecopy error: %d\n", r
);
144 read_write_buff(buf
, nr_pages
*CLICK_SIZE
, is_write
);
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
);
158 /*===========================================================================*
159 * sef_local_startup *
160 *===========================================================================*/
161 static void sef_local_startup()
163 /* Let SEF perform startup. */