diff options
author | Namhoon Kim <namhoonk@cs.unc.edu> | 2014-11-19 16:01:27 -0500 |
---|---|---|
committer | Namhoon Kim <namhoonk@cs.unc.edu> | 2014-11-19 16:01:27 -0500 |
commit | d77654f3287edf9fa6aeda97825e9a972bdc8821 (patch) | |
tree | 6fef5e799ac51b5410a68d1a928f6a3a6e94fe39 | |
parent | cef9a08794f4ecdd0d1ea80ef4035f2bc9e234ce (diff) |
set_page_color syscall
-rw-r--r-- | arch/arm/include/asm/unistd.h | 2 | ||||
-rw-r--r-- | arch/arm/kernel/calls.S | 3 | ||||
-rw-r--r-- | arch/arm/mm/cache-l2x0.c | 4 | ||||
-rw-r--r-- | arch/x86/syscalls/syscall_32.tbl | 1 | ||||
-rw-r--r-- | arch/x86/syscalls/syscall_64.tbl | 1 | ||||
-rw-r--r-- | include/litmus/unistd_32.h | 3 | ||||
-rw-r--r-- | include/litmus/unistd_64.h | 4 | ||||
-rw-r--r-- | litmus/litmus.c | 110 |
8 files changed, 124 insertions, 4 deletions
diff --git a/arch/arm/include/asm/unistd.h b/arch/arm/include/asm/unistd.h index 0db825dda11f..f31a912e2c9a 100644 --- a/arch/arm/include/asm/unistd.h +++ b/arch/arm/include/asm/unistd.h | |||
@@ -15,7 +15,7 @@ | |||
15 | 15 | ||
16 | #include <uapi/asm/unistd.h> | 16 | #include <uapi/asm/unistd.h> |
17 | /** __NR_syscalls padding */ | 17 | /** __NR_syscalls padding */ |
18 | #define __NR_syscalls (380 + NR_litmus_syscalls + 1) | 18 | #define __NR_syscalls (380 + NR_litmus_syscalls) |
19 | 19 | ||
20 | #define __ARM_NR_cmpxchg (__ARM_NR_BASE+0x00fff0) | 20 | #define __ARM_NR_cmpxchg (__ARM_NR_BASE+0x00fff0) |
21 | 21 | ||
diff --git a/arch/arm/kernel/calls.S b/arch/arm/kernel/calls.S index 34c5ee7964eb..2fbce68d96d3 100644 --- a/arch/arm/kernel/calls.S +++ b/arch/arm/kernel/calls.S | |||
@@ -404,7 +404,8 @@ | |||
404 | CALL(sys_reservation_create) | 404 | CALL(sys_reservation_create) |
405 | CALL(sys_reservation_destroy) | 405 | CALL(sys_reservation_destroy) |
406 | CALL(sys_set_mc2_task_param) | 406 | CALL(sys_set_mc2_task_param) |
407 | 407 | /* 395 */ CALL(sys_set_page_color) | |
408 | |||
408 | #ifndef syscalls_counted | 409 | #ifndef syscalls_counted |
409 | .equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls | 410 | .equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls |
410 | #define syscalls_counted | 411 | #define syscalls_counted |
diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c index 5efe6b6e9d53..cff808e79199 100644 --- a/arch/arm/mm/cache-l2x0.c +++ b/arch/arm/mm/cache-l2x0.c | |||
@@ -326,6 +326,7 @@ void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask) | |||
326 | { | 326 | { |
327 | u32 aux; | 327 | u32 aux; |
328 | u32 cache_id; | 328 | u32 cache_id; |
329 | u32 cache_type; | ||
329 | u32 way_size = 0; | 330 | u32 way_size = 0; |
330 | int ways; | 331 | int ways; |
331 | int way_size_shift = L2X0_WAY_SIZE_SHIFT; | 332 | int way_size_shift = L2X0_WAY_SIZE_SHIFT; |
@@ -337,6 +338,8 @@ void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask) | |||
337 | else | 338 | else |
338 | cache_id = readl_relaxed(l2x0_base + L2X0_CACHE_ID); | 339 | cache_id = readl_relaxed(l2x0_base + L2X0_CACHE_ID); |
339 | aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL); | 340 | aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL); |
341 | |||
342 | cache_type = readl_relaxed(l2x0_base + L2X0_CACHE_TYPE); | ||
340 | 343 | ||
341 | aux &= aux_mask; | 344 | aux &= aux_mask; |
342 | aux |= aux_val; | 345 | aux |= aux_val; |
@@ -424,6 +427,7 @@ void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask) | |||
424 | printk(KERN_INFO "%s cache controller enabled\n", type); | 427 | printk(KERN_INFO "%s cache controller enabled\n", type); |
425 | printk(KERN_INFO "l2x0: %d ways, CACHE_ID 0x%08x, AUX_CTRL 0x%08x, Cache size: %d B\n", | 428 | printk(KERN_INFO "l2x0: %d ways, CACHE_ID 0x%08x, AUX_CTRL 0x%08x, Cache size: %d B\n", |
426 | ways, cache_id, aux, l2x0_size); | 429 | ways, cache_id, aux, l2x0_size); |
430 | printk(KERN_INFO "l2x0: CACHE_TYPE 0x%08x\n", cache_type); | ||
427 | 431 | ||
428 | litmus_setup_lockdown(l2x0_base, cache_id); | 432 | litmus_setup_lockdown(l2x0_base, cache_id); |
429 | } | 433 | } |
diff --git a/arch/x86/syscalls/syscall_32.tbl b/arch/x86/syscalls/syscall_32.tbl index 20f6cdcf56dd..401f313f9cdd 100644 --- a/arch/x86/syscalls/syscall_32.tbl +++ b/arch/x86/syscalls/syscall_32.tbl | |||
@@ -373,3 +373,4 @@ | |||
373 | 363 i386 reservation_create sys_reservation_create | 373 | 363 i386 reservation_create sys_reservation_create |
374 | 364 i386 reservation_destroy sys_reservation_destroy | 374 | 364 i386 reservation_destroy sys_reservation_destroy |
375 | 365 i386 set_mc2_task_param sys_set_mc2_task_param | 375 | 365 i386 set_mc2_task_param sys_set_mc2_task_param |
376 | 366 i386 set_page_color sys_set_page_color | ||
diff --git a/arch/x86/syscalls/syscall_64.tbl b/arch/x86/syscalls/syscall_64.tbl index f3d142c2a900..77710a93c2a3 100644 --- a/arch/x86/syscalls/syscall_64.tbl +++ b/arch/x86/syscalls/syscall_64.tbl | |||
@@ -336,6 +336,7 @@ | |||
336 | 363 common reservation_create sys_reservation_create | 336 | 363 common reservation_create sys_reservation_create |
337 | 364 common reservation_destroy sys_reservation_destroy | 337 | 364 common reservation_destroy sys_reservation_destroy |
338 | 365 common set_mc2_task_param sys_set_mc2_task_param | 338 | 365 common set_mc2_task_param sys_set_mc2_task_param |
339 | 366 common set_page_color sys_set_page_color | ||
339 | 340 | ||
340 | # | 341 | # |
341 | # x32-specific system call numbers start at 512 to avoid cache impact | 342 | # x32-specific system call numbers start at 512 to avoid cache impact |
diff --git a/include/litmus/unistd_32.h b/include/litmus/unistd_32.h index 202f439a62ae..cfffbddd09b7 100644 --- a/include/litmus/unistd_32.h +++ b/include/litmus/unistd_32.h | |||
@@ -20,5 +20,6 @@ | |||
20 | #define __NR_reservation_create __LSC(12) | 20 | #define __NR_reservation_create __LSC(12) |
21 | #define __NR_reservation_destroy __LSC(13) | 21 | #define __NR_reservation_destroy __LSC(13) |
22 | #define __NR_set_mc2_task_param __LSC(14) | 22 | #define __NR_set_mc2_task_param __LSC(14) |
23 | #define __NR_set_page_color __LSC(15) | ||
23 | 24 | ||
24 | #define NR_litmus_syscalls 15 | 25 | #define NR_litmus_syscalls 16 |
diff --git a/include/litmus/unistd_64.h b/include/litmus/unistd_64.h index ba2c91c5bf8c..2fb49dc58eb3 100644 --- a/include/litmus/unistd_64.h +++ b/include/litmus/unistd_64.h | |||
@@ -35,5 +35,7 @@ __SYSCALL(__NR_reservation_create, sys_reservation_create) | |||
35 | __SYSCALL(__NR_reservation_destroy, sys_reservation_destroy) | 35 | __SYSCALL(__NR_reservation_destroy, sys_reservation_destroy) |
36 | #define __NR_set_mc2_task_param __LSC(14) | 36 | #define __NR_set_mc2_task_param __LSC(14) |
37 | __SYSCALL(__NR_set_mc2_task_param, sys_set_mc2_task_param) | 37 | __SYSCALL(__NR_set_mc2_task_param, sys_set_mc2_task_param) |
38 | #define __NR_set_page_color __LSC(15) | ||
39 | __SYSCALL(__NR_set_page_color, sys_set_page_color) | ||
38 | 40 | ||
39 | #define NR_litmus_syscalls 15 | 41 | #define NR_litmus_syscalls 16 |
diff --git a/litmus/litmus.c b/litmus/litmus.c index 8a2446f26f72..cdffbc617d3a 100644 --- a/litmus/litmus.c +++ b/litmus/litmus.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/stop_machine.h> | 13 | #include <linux/stop_machine.h> |
14 | #include <linux/sched/rt.h> | 14 | #include <linux/sched/rt.h> |
15 | #include <linux/rwsem.h> | 15 | #include <linux/rwsem.h> |
16 | #include <linux/list.h> | ||
16 | 17 | ||
17 | #include <litmus/litmus.h> | 18 | #include <litmus/litmus.h> |
18 | #include <litmus/bheap.h> | 19 | #include <litmus/bheap.h> |
@@ -325,6 +326,112 @@ asmlinkage long sys_reservation_destroy(unsigned int reservation_id, int cpu) | |||
325 | return litmus->reservation_destroy(reservation_id, cpu); | 326 | return litmus->reservation_destroy(reservation_id, cpu); |
326 | } | 327 | } |
327 | 328 | ||
329 | struct task_page { | ||
330 | unsigned long vm_start; | ||
331 | unsigned long vm_end; | ||
332 | struct page* page; | ||
333 | struct list_head list; | ||
334 | }; | ||
335 | |||
336 | LIST_HEAD(task_page_list); | ||
337 | |||
338 | static unsigned long color_mask; | ||
339 | |||
340 | static inline unsigned long page_color(struct page *page) | ||
341 | { | ||
342 | return ((page_to_phys(page) & color_mask) >> PAGE_SHIFT); | ||
343 | } | ||
344 | |||
345 | static struct page *walk_page_table(unsigned long addr) | ||
346 | { | ||
347 | pgd_t *pgd; | ||
348 | pte_t *ptep, pte; | ||
349 | pud_t *pud; | ||
350 | pmd_t *pmd; | ||
351 | |||
352 | struct page *page = NULL; | ||
353 | struct mm_struct *mm = current->mm; | ||
354 | |||
355 | pgd = pgd_offset(mm, addr); | ||
356 | if (pgd_none(*pgd) || pgd_bad(*pgd)) | ||
357 | goto out; | ||
358 | |||
359 | pud = pud_offset(pgd, addr); | ||
360 | if (pud_none(*pud) || pud_bad(*pud)) | ||
361 | goto out; | ||
362 | |||
363 | pmd = pmd_offset(pud, addr); | ||
364 | if (pmd_none(*pmd) || pmd_bad(*pmd)) | ||
365 | goto out; | ||
366 | |||
367 | ptep = pte_offset_map(pmd, addr); | ||
368 | if (!ptep) | ||
369 | goto out; | ||
370 | pte = *ptep; | ||
371 | |||
372 | page = pte_page(pte); | ||
373 | if (page) | ||
374 | printk(KERN_INFO "page frame struct is @ %p\n", page); | ||
375 | |||
376 | pte_unmap(ptep); | ||
377 | |||
378 | out: | ||
379 | return page; | ||
380 | } | ||
381 | |||
382 | asmlinkage long sys_set_page_color(int cpu) | ||
383 | { | ||
384 | long ret = 0; | ||
385 | struct task_page *task_page_itr = NULL; | ||
386 | struct task_page *task_page_itr_next = NULL; | ||
387 | struct vm_area_struct *vma_itr = NULL; | ||
388 | struct task_page *entry = NULL; | ||
389 | |||
390 | down_read(¤t->mm->mmap_sem); | ||
391 | printk(KERN_INFO "SYSCALL set_page_color\n"); | ||
392 | vma_itr = current->mm->mmap; | ||
393 | while (vma_itr != NULL) { | ||
394 | unsigned int num_pages = 0, i; | ||
395 | struct page *new_page = NULL; | ||
396 | entry = kmalloc(sizeof(struct task_page), GFP_ATOMIC); | ||
397 | if (entry == NULL) { | ||
398 | return -ENOSPC; | ||
399 | } | ||
400 | entry->vm_start = vma_itr->vm_start; | ||
401 | entry->vm_end = vma_itr->vm_end; | ||
402 | num_pages = (entry->vm_end - entry->vm_start) / PAGE_SIZE; | ||
403 | // print vma flags | ||
404 | printk(KERN_INFO "flags: 0x%lx\n", vma_itr->vm_flags); | ||
405 | printk(KERN_INFO "start - end: 0x%lx - 0x%lx (%lu)\n", vma_itr->vm_start, vma_itr->vm_end, (vma_itr->vm_end - vma_itr->vm_start)/PAGE_SIZE); | ||
406 | |||
407 | for (i = 0; i < num_pages; i++) { | ||
408 | alloc: | ||
409 | new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma_itr, vma_itr->vm_start); | ||
410 | if (!new_page) | ||
411 | return -ENOSPC; | ||
412 | if ( (page_color(new_page)>>2) != cpu) { | ||
413 | |||
414 | |||
415 | } | ||
416 | //entry->page = walk_page_table(entry->vm_start); | ||
417 | |||
418 | INIT_LIST_HEAD(&entry->list); | ||
419 | list_add(&entry->list, &task_page_list); | ||
420 | |||
421 | vma_itr = vma_itr->vm_next; | ||
422 | } | ||
423 | |||
424 | up_read(¤t->mm->mmap_sem); | ||
425 | |||
426 | list_for_each_entry_safe(task_page_itr, task_page_itr_next, &task_page_list, list) { | ||
427 | //printk(KERN_INFO "start - end: 0x%lx - 0x%lx (%lu)\n", task_page_itr->vm_start, task_page_itr->vm_end, (task_page_itr->vm_end - task_page_itr->vm_start)/PAGE_SIZE); | ||
428 | list_del(&task_page_itr->list); | ||
429 | kfree(task_page_itr); | ||
430 | } | ||
431 | |||
432 | return ret; | ||
433 | } | ||
434 | |||
328 | /* p is a real-time task. Re-init its state as a best-effort task. */ | 435 | /* p is a real-time task. Re-init its state as a best-effort task. */ |
329 | static void reinit_litmus_state(struct task_struct* p, int restore) | 436 | static void reinit_litmus_state(struct task_struct* p, int restore) |
330 | { | 437 | { |
@@ -662,6 +769,8 @@ static int __init _init_litmus(void) | |||
662 | * mode change lock is used to enforce single mode change | 769 | * mode change lock is used to enforce single mode change |
663 | * operation. | 770 | * operation. |
664 | */ | 771 | */ |
772 | unsigned int line_size_log = 5; // 2^5 = 32 byte | ||
773 | unsigned int cache_info_sets = 2048; // 64KB (way_size) / 32B (line_size) = 2048 | ||
665 | printk("Starting LITMUS^RT kernel\n"); | 774 | printk("Starting LITMUS^RT kernel\n"); |
666 | 775 | ||
667 | register_sched_plugin(&linux_sched_plugin); | 776 | register_sched_plugin(&linux_sched_plugin); |
@@ -689,6 +798,7 @@ static int __init _init_litmus(void) | |||
689 | litmus_enable_perfcounters(); | 798 | litmus_enable_perfcounters(); |
690 | #endif | 799 | #endif |
691 | 800 | ||
801 | color_mask = ((cache_info_sets << line_size_log) - 1) ^ (PAGE_SIZE - 1); | ||
692 | return 0; | 802 | return 0; |
693 | } | 803 | } |
694 | 804 | ||