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

pb_submitter

parent 65cb0cf4
Branches
No related tags found
No related merge requests found
...@@ -7,26 +7,45 @@ ...@@ -7,26 +7,45 @@
typedef struct pb_plan pb_plan_t; typedef struct pb_plan pb_plan_t;
SYSCALL_DEFINE1(pb_set_plan, pb_plan_t*, plan_info) { SYSCALL_DEFINE1(pb_set_plan, pb_plan_t __user*, plan) {
pb_plan_t _plan; pb_plan_t _plan;
struct task_struct* task; struct task_struct* task;
struct rq* rq; struct rq* rq;
struct pb_rq* pb_rq; struct pb_rq* pb_rq;
size_t expected;
uint64_t* inst_cnt;
unsigned long copied; unsigned long copied;
unsigned int i; unsigned int i;
int res; int res;
copied = copy_from_user(&_plan, plan_info, sizeof(pb_plan_t)); copied = copy_from_user(&_plan, plan, sizeof(pb_plan_t));
if (copied != sizeof(pb_plan_t)) { if (copied != 0) {
printk("copy_from_user pb_plan failed \n");
return -1;
}
expected = _plan.num_tasks * sizeof(*_plan.inst_cnt);
inst_cnt = (uint64_t *)kzalloc(expected, GFP_KERNEL);
if (inst_cnt == NULL) {
return -1;
}
copied = copy_from_user(inst_cnt, _plan.inst_cnt, expected);
if (copied != 0) {
printk("copy from user inst_cnt failed \n");
return -1; return -1;
} }
task = find_task_by_vpid(_plan.pid); task = find_task_by_vpid(_plan.pid);
if (!task) { if (!task) {
printk("!task\n");
return -1; return -1;
} }
...@@ -42,7 +61,7 @@ SYSCALL_DEFINE1(pb_set_plan, pb_plan_t*, plan_info) { ...@@ -42,7 +61,7 @@ SYSCALL_DEFINE1(pb_set_plan, pb_plan_t*, plan_info) {
set_pb_plan_entry( set_pb_plan_entry(
pb_rq, pb_rq,
i, i,
_plan.inst_cnt[i], inst_cnt[i],
i, i,
task task
); );
...@@ -51,6 +70,7 @@ SYSCALL_DEFINE1(pb_set_plan, pb_plan_t*, plan_info) { ...@@ -51,6 +70,7 @@ SYSCALL_DEFINE1(pb_set_plan, pb_plan_t*, plan_info) {
res = pb_submit_plan(rq); res = pb_submit_plan(rq);
if (res == -1) { if (res == -1) {
printk("pb_submit_plan == -1\n");
return res; return res;
} }
......
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 pb_submitter pb_submitter.c
gcc -static -o test_prog test_prog.c
sudo mount -o loop ../build/qemu-image.img ./mnt
sudo cp pb_submitter test_prog example_run.sh ./mnt/root
sudo umount ./mnt
echo "All done. Run ./run_qemu.sh now"
#!/bin/sh
./pb_submitter ./test 16 16
#include <stdio.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>
#define PB_SET_PLAN 0x1337
typedef struct {
pid_t pid;
uint64_t *inst_cnt;
size_t num_tasks;
} pb_plan_t;
static void usage(void)
{
puts("Usage: ./pb_submitter <prog_name> <inst_cnt> <num_tasks>");
}
int main(int argc, char** argv)
{
if (argc < 0x4) {
usage();
return -1;
}
int ret;
pb_plan_t plan = { 0 };
ret = sscanf(argv[3], "%zu", &plan.num_tasks);
if (ret != 1) {
usage();
return -1;
}
uint64_t* inst_cnt = calloc(plan.num_tasks, sizeof(uint64_t));
if (inst_cnt == NULL) {
perror("calloc");
return -1;
}
// todo only for testing:
// need to pass in a file that contains all the inst_cnts at some point
for (int i = 0; i < 0x10; i++) {
inst_cnt[i] = 0x10000;
}
plan.inst_cnt = inst_cnt;
printf("inst_cnt address: %p \n", inst_cnt);
plan.pid = getpid();
ret = syscall(PB_SET_PLAN, &plan);
if (ret < 0) {
puts("PB_SET_PLAN failed");
return -1;
}
char *const args[] = {argv[1], NULL};
char *const env[] = {NULL};
ret = execve(argv[1], args, env);
if (ret < 0) {
perror("execve");
return -1;
}
return 0;
}
#include <stdio.h>
int main(void)
{
unsigned int c = 0;
// printk(KERN_WARNING "Hello from Module.\n");
int a = 0;
// printk(KERN_WARNING "A.\n");
for (;a < 200000; a++){asm("");}
// printk(KERN_WARNING "B.\n");
c++;
// printk(KERN_WARNING "Bye from module.\n");
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment