Skip to content

Instantly share code, notes, and snippets.

@giraldeau
Created August 10, 2015 17:28
Show Gist options
  • Save giraldeau/deb15171dcf415657b90 to your computer and use it in GitHub Desktop.
Save giraldeau/deb15171dcf415657b90 to your computer and use it in GitHub Desktop.
int do_syscall_read_long(void *args)
{
FILE *f = args;
int i;
long val;
for (i = 0; i < (PAGE_SIZE / sizeof(val)); i++) {
val = 0;
int ret = read(f->_fileno, &val, sizeof(val));
assert(ret == sizeof(val));
assert(val != 0);
}
fseek(f, 0, SEEK_SET);
return 0;
}
int main(int argc, char **argv) {
void *mmap_addr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
memset(mmap_addr, 0xCA, PAGE_SIZE);
FILE *f = fopen("iofile.data", "w+");
if (f == NULL) {
printf("open error\n");
return -1;
}
int ret = fwrite(mmap_addr, sizeof(char), PAGE_SIZE, f);
printf("fwrite=%d\n", ret);
fseek(f, 0, SEEK_SET);
fflush(f);
struct profile prof[] = {
{
.name = "do_mmap_read_long",
.func = do_mmap_read_long,
.repeat = 1000000,
.args = mmap_addr,
},
/*
{
.name = "do_mmap_read_int",
.func = do_mmap_read_int,
.repeat = 1000000,
.args = mmap_addr,
},
{
.name = "do_mmap_read_byte",
.func = do_mmap_read_byte,
.repeat = 1000000,
.args = mmap_addr,
},
*/
{
.name = "do_syscall_read_long",
.func = do_syscall_read_long,
.repeat = 10000,
.args = f,
},
{ .name = NULL },
};
struct profile *curr;
for (curr = prof; curr->name != NULL; curr++) {
profile_combo(curr);
profile_stats_print(curr, stdout);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment