Skip to content
Snippets Groups Projects
Commit 463e2b32 authored by Ollrogge's avatar Ollrogge
Browse files

pb_submitter: read plan from file

parent e44f6624
Branches
No related tags found
No related merge requests found
obj-m += pb_module.o
all:
make -C $(PWD)/../../ M=$(PWD) modules
clean:
make -C $(PWD)/../../ M=$(PWD) clean
#!/bin/bash
#make
mkdir -p mnt
gcc -static -o test test.c
sudo mount -o loop ../build/qemu-image.img ./mnt
sudo cp test ./mnt/root
sudo umount ./mnt
echo "All done. Run ./run_qemu.sh now"
#include <stdio.h>
#include <sys/syscall.h>
#include <unistd.h>
#define PB_SET_PLAN 0x1337
typedef struct {
int tmp;
} plan_t;
// check kernel log with dmesg command afterwards
int main(void)
{
plan_t plan = {0};
plan.tmp = 0x414141;
int ret = syscall(PB_SET_PLAN, &plan);
if (ret < 0) {
perror("pb: ");
return -1;
}
puts("Done. Check kernel log with dmesg for message");
return 0;
}
...@@ -7,7 +7,7 @@ gcc -static -o pb_submitter pb_submitter.c ...@@ -7,7 +7,7 @@ gcc -static -o pb_submitter pb_submitter.c
gcc -static -o test_prog test_prog.c gcc -static -o test_prog test_prog.c
sudo mount -o loop ../build/qemu-image.img ./mnt sudo mount -o loop ../build/qemu-image.img ./mnt
sudo cp pb_submitter test_prog example_run.sh ./mnt/root sudo cp pb_submitter test_prog example_run.sh example_plan ./mnt/root
sudo umount ./mnt sudo umount ./mnt
......
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
100000
#!/bin/sh #!/bin/sh
./pb_submitter ./test 16 16 ./pb_submitter test example_plan
...@@ -14,41 +14,75 @@ typedef struct { ...@@ -14,41 +14,75 @@ typedef struct {
static void usage(void) static void usage(void)
{ {
puts("Usage: ./pb_submitter <prog_name> <inst_cnt> <num_tasks>"); puts("Usage: ./pb_submitter <prog_name> <plan_file>");
}
static size_t count_lines(FILE *fp)
{
char c;
size_t lines = 0;
while (!feof(fp)) {
c = fgetc(fp);
if (c == '\n') {
lines++;
}
}
rewind(fp);
return lines;
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
if (argc < 0x4) { if (argc < 0x3) {
usage(); usage();
return -1; return -1;
} }
int ret; int ret;
pb_plan_t plan = { 0 }; pb_plan_t plan = { 0 };
FILE *fp;
ret = sscanf(argv[3], "%zu", &plan.num_tasks); char *line = NULL;
if (ret != 1) { size_t len = 0;
ssize_t read;
fp = fopen(argv[2], "r");
if (fp == NULL) {
usage(); usage();
return -1; return -1;
} }
plan.num_tasks = count_lines(fp);
printf("num_tasks: %zu \n", plan.num_tasks);
uint64_t* inst_cnt = calloc(plan.num_tasks, sizeof(uint64_t)); uint64_t* inst_cnt = calloc(plan.num_tasks, sizeof(uint64_t));
if (inst_cnt == NULL) { if (inst_cnt == NULL) {
perror("calloc"); perror("calloc");
return -1; return -1;
} }
// todo only for testing: for (size_t i = 0; i < plan.num_tasks; i++) {
// need to pass in a file that contains all the inst_cnts at some point read = getline(&line, &len, fp);
for (int i = 0; i < 0x10; i++) {
inst_cnt[i] = 0x10000; if (read < 0) {
perror("getline");
return -1;
}
uint64_t cnt = strtoull(line, NULL, 10);
if (inst_cnt == 0) {
puts("Inst_cnt conversion failure");
return -1;
}
inst_cnt[i] = cnt;
} }
plan.inst_cnt = inst_cnt; plan.inst_cnt = inst_cnt;
printf("inst_cnt address: %p \n", inst_cnt);
plan.pid = getpid(); plan.pid = getpid();
ret = syscall(PB_SET_PLAN, &plan); ret = syscall(PB_SET_PLAN, &plan);
......
...@@ -5,8 +5,11 @@ int main(void) ...@@ -5,8 +5,11 @@ int main(void)
unsigned int c = 0; unsigned int c = 0;
// printk(KERN_WARNING "Hello from Module.\n"); // printk(KERN_WARNING "Hello from Module.\n");
int a = 0; int a = 0;
int b = 0;
// printk(KERN_WARNING "A.\n"); // printk(KERN_WARNING "A.\n");
for (;a < 200000; a++){asm("");} for (;b < 100; b++) {
for (;a < 100000; a++){asm("");}
}
// printk(KERN_WARNING "B.\n"); // printk(KERN_WARNING "B.\n");
c++; c++;
// printk(KERN_WARNING "Bye from module.\n"); // printk(KERN_WARNING "Bye from module.\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment