diff --git a/kernel/events/core.c b/kernel/events/core.c index 03ac9c8b02fb81a89662a16c6871755933cf9721..e886b2593e3ad11414e674b52879c1ef7f79eff8 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -9429,7 +9429,25 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu, event->parent = parent_event; - event->ns = get_pid_ns(task_active_pid_ns(current)); + + /* + * This is a fix for pb_sched. + * + * When this method is called within the scheduling process the + * 'current' task is (at least in our case) already in a exit + * state. Trying to use it will cause a NULL-Pointer Exception. + * Thats why we use the task provided by 'task' to prevent this. + */ + if(task != NULL) + { + event->ns = get_pid_ns(task_active_pid_ns(task)); + } + else + { + event->ns = get_pid_ns(task_active_pid_ns(current)); + } + // fix end + event->id = atomic64_inc_return(&perf_event_id); event->state = PERF_EVENT_STATE_INACTIVE; diff --git a/kernel/sched/perf_error_detection.c b/kernel/sched/perf_error_detection.c index f67957f40eaa39f2e2473bf83c413936b3d35533..8c308497312c911bd3d90f6be97828e1a2f60363 100644 --- a/kernel/sched/perf_error_detection.c +++ b/kernel/sched/perf_error_detection.c @@ -14,6 +14,7 @@ * initialize perf event for new task */ int init_perf_event(struct plan_entry *plan_entry, struct perf_event **pevent){ + unsigned long irq_flags; struct perf_event_attr pe; memset(&pe, 0, sizeof(struct perf_event_attr)); @@ -32,7 +33,10 @@ int init_perf_event(struct plan_entry *plan_entry, struct perf_event **pevent){ /* Not needed on 3.2? */ // pe.wakeup_events = 1; + // disable irqs to make 'perf_event_ctx_activate' in 'kernel/events/core.c' happy + local_irq_save(irq_flags); *pevent = perf_event_create(&pe, 0, plan_entry->task_struct); + local_irq_restore(irq_flags); if (IS_ERR(pevent)) { printk(KERN_WARNING "PB ERROR INITIALISING PERF EVENT\n"); diff --git a/pb_utils/.gitignore b/pb_utils/.gitignore index 4cd39960308d23f2976091aacffa42a8eb828ee4..48ef480a33be31ec42e4c4de0e953a5f1ba80ce0 100644 --- a/pb_utils/.gitignore +++ b/pb_utils/.gitignore @@ -1,3 +1,2 @@ build/ mod_gen/mods -mod_gen_new/test \ No newline at end of file diff --git a/pb_utils/mod_gen/Makefile b/pb_utils/mod_gen/Makefile deleted file mode 100644 index aadd2f5d958b0a5d25b5ee9ddaabb293506f8726..0000000000000000000000000000000000000000 --- a/pb_utils/mod_gen/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -obj-m += measure.o - -all: - make -C /home/kelvin/git/master_thesis_linux/ M=$(PWD) modules - -clean: - make -C /home/kelvin/git/master_thesis_linux/ M=$(PWD) clean diff --git a/pb_utils/mod_gen/build.sh b/pb_utils/mod_gen/build.sh index d977d82482c3bf03453f52c918814eeb836f4021..a4c1c8d36c9eeadb5e24f8b803ff88cf377e2bb5 100755 --- a/pb_utils/mod_gen/build.sh +++ b/pb_utils/mod_gen/build.sh @@ -1,12 +1,15 @@ #!/bin/bash -#make -mkdir -p mnt - -sudo mount -o loop ../build/qemu-image.img ./mnt -sudo cp ./mods/plan_same_v.ko ./mnt/root -sudo cp ./mods/random_v.ko ./mnt/root - -sudo umount ./mnt - -echo "All done. Run ./run_qemu.sh now" +if [ ! -d "/mnt/pb_utils/mod_gen" ]; then + echo "are you running this in chroot or the build system?" + exit 1 +fi + +cd /mnt/pb_utils/mod_gen/ +rm -rf mods +./plan_to_module.pl +cd mods && make + +echo "################################################" +echo "modules created and copied to /root" +echo "use 'insmod <file' to run within the test system" diff --git a/pb_utils/mod_gen/measure.c b/pb_utils/mod_gen/measure.c deleted file mode 100644 index 009f8f0d93d73c901b0fef33b021344c357d7fe3..0000000000000000000000000000000000000000 --- a/pb_utils/mod_gen/measure.c +++ /dev/null @@ -1,29 +0,0 @@ -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/kthread.h> -#include <../kernel/sched/sched.h> - - -MODULE_LICENSE("GPL"); - -static int __init pb_client_init(void) -{ - struct rq *rq; - - rq = this_rq(); - set_pb_measure_on(&rq->pb); - - return 0; -} - -static void __exit pb_client_cleanup(void) -{ - struct rq *rq; - rq = this_rq(); - set_pb_measure_off(&rq->pb); - -} - -module_init(pb_client_init); -module_exit(pb_client_cleanup); diff --git a/pb_utils/mod_gen/parse_dmesg.pl b/pb_utils/mod_gen/parse_dmesg.pl deleted file mode 100755 index 905c2e7469f4d66c0ff2e1fbbcf973b4cfde7392..0000000000000000000000000000000000000000 --- a/pb_utils/mod_gen/parse_dmesg.pl +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/perl - -use Plan; - -my $argc = @ARGV; - -my $dmesg_log = $ARGV[0]; - -my $last_time = 0; -my $last_nr = 0; -my @results; - -open (FILE, $dmesg_log); - -while (<FILE>) -{ - unless (/^.*(EXEC|IDLE),(START|STOP),\d*,\d*.*/) - { - next; - } - chomp; - - ($dirty_mode, $state, $entry, $time) = split(/,/); - - $mode = ""; - if ($dirty_mode =~ /.*(EXEC|IDLE).*/) - { - $mode = $1; - } - - if ( $state eq "START" ) - { - $last_time = $time; - $last_nr = $entry; - } - - if ( $state eq "STOP" ) - { - $result = $time - $last_time; - push(@results, { mode => $mode, nr => $last_nr, time => $result }); - } -} -close (FILE); - -if ( $argc > 1 ) -{ - my $plan_csv = $ARGV[1]; - print_compared_result ($plan_csv, @results); -} -else -{ - print_simple_result (@results); -} - -sub print_simple_result -{ - my (@results) = @_; - - foreach (@results) - { - print ($_->{mode}.'['.$_->{nr}.']'.': '.$_->{time}."\n"); - } -} - -sub print_compared_result -{ - my ($plan_csv_file, @results) = @_; - my @expected_results = parse_plan_csv($plan_csv_file); - - push(@results, {mode => 'IDLE', nr => $results[-1]{nr}, time => 0}); - - for (my $i=0; $i <= $#results; $i++) - { - my $expected = $expected_results[$i]->{time}; - my $actual = $results[$i]->{time}; - my $diff = abs($expected - $actual); - - print ($results[$i]->{mode}.'['.$results[$i]->{nr}.']'.' actual: '.$actual.', expected: '.$expected.', diff: '.$diff."\n"); - } -} diff --git a/pb_utils/mod_gen/tmpl/Makefile.tt b/pb_utils/mod_gen/tmpl/Makefile.tt index 9cdbc1ac98b4749420bdb5123dc26f5c03fc3395..362fe2c616d316b26c591c9fc089f52ca15fb020 100644 --- a/pb_utils/mod_gen/tmpl/Makefile.tt +++ b/pb_utils/mod_gen/tmpl/Makefile.tt @@ -2,6 +2,10 @@ [% END %] all: make -C [% linux_src_dir %] M=$(PWD) modules + [% FOREACH module_name IN module_names %]cp [% module_name %].ko /root + [% END %] clean: make -C [% linux_src_dir %] M=$(PWD) clean + [% FOREACH module_name IN module_names %]rm /root/[% module_name %].ko + [% END %] diff --git a/pb_utils/mod_gen/tmpl/module.tt b/pb_utils/mod_gen/tmpl/module.tt index efa4adb9d6154cefaadec7342862b2155b0206cd..4855ac59bed0357ff1161a0dbb687554d3b40f78 100644 --- a/pb_utils/mod_gen/tmpl/module.tt +++ b/pb_utils/mod_gen/tmpl/module.tt @@ -27,7 +27,7 @@ static void init_rq(struct rq *rq) { struct pb_rq *pb_rq = &rq->pb; struct task_struct *proxy_task; - int i; + proxy_task = kthread_create(loop_thread_func, NULL, "PB proxy thread"); proxy_task->sched_class = &pb_sched_class; set_pb_plan_size(pb_rq, [% plan_size %]); diff --git a/pb_utils/pb_submitter/.gitignore b/pb_utils/pb_submitter/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6d5984422b4055f069478d08dc77eb1d5405b1de --- /dev/null +++ b/pb_utils/pb_submitter/.gitignore @@ -0,0 +1,2 @@ +pb_submitter +test_prog diff --git a/pb_utils/pb_submitter/Makefile b/pb_utils/pb_submitter/Makefile deleted file mode 100644 index 55503d9ce1a2506057a149867545ea2ac4ebb8ca..0000000000000000000000000000000000000000 --- a/pb_utils/pb_submitter/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -obj-m += pb_module.o - -all: - make -C $(PWD)/../../ M=$(PWD) modules - -clean: - make -C $(PWD)/../../ M=$(PWD) clean diff --git a/pb_utils/pb_submitter/build.sh b/pb_utils/pb_submitter/build.sh index 4b92faed1e929a87ba42d7e403e4d719ac51f7dc..518b471e4177f4121a15f9197a58204e01fe7a7c 100755 --- a/pb_utils/pb_submitter/build.sh +++ b/pb_utils/pb_submitter/build.sh @@ -1,14 +1,14 @@ #!/bin/bash -#make -mkdir -p mnt +if [ ! -d "/mnt/pb_utils/pb_submitter" ]; then + echo "are you running this in chroot or the build system?" + exit 1 +fi +cd /mnt/pb_utils/pb_submitter 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 example_plan ./mnt/root +cp pb_submitter test_prog example_run.sh example_plan /root -sudo umount ./mnt - -echo "All done. Run ./run_qemu.sh now" +echo "All done. Run '/root/example_run.sh' within ./run_qemu.sh now" diff --git a/pb_utils/pb_submitter/example_run.sh b/pb_utils/pb_submitter/example_run.sh index 380e11c0c24858de8e0d4291996a4af11255e2d0..43de115acb584936c3078f8302fc265469b4f12d 100755 --- a/pb_utils/pb_submitter/example_run.sh +++ b/pb_utils/pb_submitter/example_run.sh @@ -1,3 +1,3 @@ #!/bin/sh - +cd /root ./pb_submitter test_prog example_plan diff --git a/pb_utils/pb_submitter/pb_submitter.c b/pb_utils/pb_submitter/pb_submitter.c index 5524f6678bf540ed5ed2a4e943ede02280793493..e8cb3474749e655885619f8f4e033cfba0fa13eb 100644 --- a/pb_utils/pb_submitter/pb_submitter.c +++ b/pb_utils/pb_submitter/pb_submitter.c @@ -69,7 +69,8 @@ int main(int argc, char** argv) return -1; } - for (size_t i = 0; i < plan.num_tasks; i++) { + size_t i; + for (i = 0; i < plan.num_tasks; i++) { cnt = getline(&line, &len, fp); if (cnt < 0) { diff --git a/pb_utils/pb_submitter/test_prog.c b/pb_utils/pb_submitter/test_prog.c index a1260e89cfbf559150df0130b4a85121a34db906..74d87392c32815ad0502096c0bafc295b89fa7ac 100644 --- a/pb_utils/pb_submitter/test_prog.c +++ b/pb_utils/pb_submitter/test_prog.c @@ -5,12 +5,13 @@ int main(void) { // Make sure program is not finished before pb scheduler takes control sleep(1); - int a = 0; int b = 0; for (;b < 100; b++) { - for (;a < 100000; a++){asm("");} + int a = 0; + int c = 0; + for (;a < 100000; a++){c = c + a;} // check if program runs && syscall to switch tasks - printf("loop run: %d \n", b); + printf("loop run: %d, c = %d \n", b, c); usleep(1); } return 0; diff --git a/pb_utils/readme.md b/pb_utils/readme.md index eb5f75153bd9abdf1d6b5f371d2d75d900e5052d..6372d259c9a6ba932609616f6f917f7080b0d57a 100644 --- a/pb_utils/readme.md +++ b/pb_utils/readme.md @@ -20,6 +20,18 @@ cd /mnt ./build ``` +## chroot into debian rootfs to build test modules +run `./chroot_image.sh`, this drops you in a shell on the created debian and run +```bash +/mnt/pb_utils/mod_gen/build.sh +``` + +## chroot into debian rootfs to build pb_submitter +run `./chroot_image.sh`, this drops you in a shell on the created debian and run +```bash +/mnt/pb_utils/pb_submitter/build.sh +``` + # run the build kernel with the created rootfs run `./run_qemu.sh`