DF-2675 / sweep.c
/* * DF-2675 sweep: pin self to <cpu>, then sequentially read the first 64K * of every file listed in <listfile>. All buffer allocations (fresh file * data) happen on the pinned cpu. Prints one line per file for progress. */ #include <sys/types.h> #include <sys/usched.h> #include <err.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(int argc, char **argv) { int cpu, fd, n = 0; char line[1024], *buf; FILE *list; if (argc != 3) { fprintf(stderr, "usage: sweep cpu listfile\n"); return 1; } cpu = atoi(argv[1]); { int pin_cpu = cpu; if (usched_set(0, USCHED_SET_CPU, &pin_cpu, sizeof(pin_cpu)) < 0) err(1, "usched_set"); } buf = malloc(65536); if (!buf) err(1, "malloc"); list = fopen(argv[2], "r"); if (!list) err(1, "fopen list"); while (fgets(line, sizeof(line), list)) { size_t l = strlen(line); if (l && line[l-1] == '\n') line[l-1] = 0; if (line[0] != '/') continue; fd = open(line, O_RDONLY); if (fd < 0) continue; if (pread(fd, buf, 65536, 0) == 65536) ++n; close(fd); printf("SWEPT %d %s\n", n, line); fflush(stdout); } fclose(list); return 0; } |