diff options
Diffstat (limited to 'litmus/sched_cedf.c')
-rw-r--r-- | litmus/sched_cedf.c | 107 |
1 files changed, 98 insertions, 9 deletions
diff --git a/litmus/sched_cedf.c b/litmus/sched_cedf.c index f5b77080cc4f..a729d97535e9 100644 --- a/litmus/sched_cedf.c +++ b/litmus/sched_cedf.c | |||
@@ -30,6 +30,8 @@ | |||
30 | #include <linux/sched.h> | 30 | #include <linux/sched.h> |
31 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
32 | 32 | ||
33 | #include <linux/module.h> | ||
34 | |||
33 | #include <litmus/litmus.h> | 35 | #include <litmus/litmus.h> |
34 | #include <litmus/jobs.h> | 36 | #include <litmus/jobs.h> |
35 | #include <litmus/sched_plugin.h> | 37 | #include <litmus/sched_plugin.h> |
@@ -38,7 +40,16 @@ | |||
38 | 40 | ||
39 | #include <litmus/bheap.h> | 41 | #include <litmus/bheap.h> |
40 | 42 | ||
41 | #include <linux/module.h> | 43 | /* to configure the cluster size */ |
44 | #include <litmus/litmus_proc.h> | ||
45 | #include <linux/uaccess.h> | ||
46 | |||
47 | /* | ||
48 | * It makes sense only to cluster around L2 or L3, so if cluster_index = 2 | ||
49 | * (default) we cluster all the CPUs that shares a L2 cache, while | ||
50 | * cluster_cache_index = 3 we cluster all CPs that shares a L3 cache | ||
51 | */ | ||
52 | int cluster_index = 2; | ||
42 | 53 | ||
43 | /* forward declaration... a funny thing with C ;) */ | 54 | /* forward declaration... a funny thing with C ;) */ |
44 | struct clusterdomain; | 55 | struct clusterdomain; |
@@ -641,25 +652,25 @@ static long cedf_activate_plugin(void) | |||
641 | cleanup_cedf(); | 652 | cleanup_cedf(); |
642 | 653 | ||
643 | printk(KERN_INFO "C-EDF: Activate Plugin, cache index = %d\n", | 654 | printk(KERN_INFO "C-EDF: Activate Plugin, cache index = %d\n", |
644 | cluster_cache_index); | 655 | cluster_index); |
645 | 656 | ||
646 | /* need to get cluster_size first */ | 657 | /* need to get cluster_size first */ |
647 | if(!zalloc_cpumask_var(&mask, GFP_ATOMIC)) | 658 | if(!zalloc_cpumask_var(&mask, GFP_ATOMIC)) |
648 | return -ENOMEM; | 659 | return -ENOMEM; |
649 | 660 | ||
650 | if (unlikely(cluster_cache_index == num_online_cpus())) { | 661 | if (unlikely(cluster_index == num_online_cpus())) { |
651 | 662 | ||
652 | cluster_size = num_online_cpus(); | 663 | cluster_size = num_online_cpus(); |
653 | } else { | 664 | } else { |
654 | 665 | ||
655 | chk = get_shared_cpu_map(mask, 0, cluster_cache_index); | 666 | chk = get_shared_cpu_map(mask, 0, cluster_index); |
656 | if (chk) { | 667 | if (chk) { |
657 | /* if chk != 0 then it is the max allowed index */ | 668 | /* if chk != 0 then it is the max allowed index */ |
658 | printk(KERN_INFO "C-EDF: Cannot support cache index = %d\n", | 669 | printk(KERN_INFO "C-EDF: Cannot support cache index = %d\n", |
659 | cluster_cache_index); | 670 | cluster_index); |
660 | printk(KERN_INFO "C-EDF: Using cache index = %d\n", | 671 | printk(KERN_INFO "C-EDF: Using cache index = %d\n", |
661 | chk); | 672 | chk); |
662 | cluster_cache_index = chk; | 673 | cluster_index = chk; |
663 | } | 674 | } |
664 | 675 | ||
665 | cluster_size = cpumask_weight(mask); | 676 | cluster_size = cpumask_weight(mask); |
@@ -706,10 +717,10 @@ static long cedf_activate_plugin(void) | |||
706 | 717 | ||
707 | /* this cpu isn't in any cluster */ | 718 | /* this cpu isn't in any cluster */ |
708 | /* get the shared cpus */ | 719 | /* get the shared cpus */ |
709 | if (unlikely(cluster_cache_index == num_online_cpus())) | 720 | if (unlikely(cluster_index == num_online_cpus())) |
710 | cpumask_copy(mask, cpu_online_mask); | 721 | cpumask_copy(mask, cpu_online_mask); |
711 | else | 722 | else |
712 | get_shared_cpu_map(mask, cpu, cluster_cache_index); | 723 | get_shared_cpu_map(mask, cpu, cluster_index); |
713 | 724 | ||
714 | cpumask_copy(cedf[i].cpu_map, mask); | 725 | cpumask_copy(cedf[i].cpu_map, mask); |
715 | #ifdef VERBOSE_INIT | 726 | #ifdef VERBOSE_INIT |
@@ -759,14 +770,92 @@ static struct sched_plugin cedf_plugin __cacheline_aligned_in_smp = { | |||
759 | }; | 770 | }; |
760 | 771 | ||
761 | 772 | ||
773 | /* proc file interface to configure the cluster size */ | ||
774 | |||
775 | static int proc_read_cluster_size(char *page, char **start, | ||
776 | off_t off, int count, | ||
777 | int *eof, void *data) | ||
778 | { | ||
779 | int len; | ||
780 | if (cluster_index >= 1 && cluster_index <= 3) | ||
781 | len = snprintf(page, PAGE_SIZE, "L%d\n", cluster_index); | ||
782 | else | ||
783 | len = snprintf(page, PAGE_SIZE, "ALL\n"); | ||
784 | |||
785 | return len; | ||
786 | } | ||
787 | |||
788 | static int proc_write_cluster_size(struct file *file, | ||
789 | const char *buffer, | ||
790 | unsigned long count, | ||
791 | void *data) | ||
792 | { | ||
793 | int len; | ||
794 | /* L2, L3 */ | ||
795 | char cache_name[33]; | ||
796 | |||
797 | if(count > 32) | ||
798 | len = 32; | ||
799 | else | ||
800 | len = count; | ||
801 | |||
802 | if(copy_from_user(cache_name, buffer, len)) | ||
803 | return -EFAULT; | ||
804 | |||
805 | cache_name[len] = '\0'; | ||
806 | /* chomp name */ | ||
807 | if (len > 1 && cache_name[len - 1] == '\n') | ||
808 | cache_name[len - 1] = '\0'; | ||
809 | |||
810 | /* do a quick and dirty comparison to find the cluster size */ | ||
811 | if (!strcmp(cache_name, "L2")) | ||
812 | cluster_index = 2; | ||
813 | else if (!strcmp(cache_name, "L3")) | ||
814 | cluster_index = 3; | ||
815 | else if (!strcmp(cache_name, "L1")) | ||
816 | cluster_index = 1; | ||
817 | else if (!strcmp(cache_name, "ALL")) | ||
818 | cluster_index = num_online_cpus(); | ||
819 | else | ||
820 | printk(KERN_INFO "Cluster '%s' is unknown.\n", cache_name); | ||
821 | |||
822 | return len; | ||
823 | } | ||
824 | |||
825 | |||
826 | static struct proc_dir_entry *cluster_file = NULL, *cedf_dir = NULL; | ||
827 | |||
828 | |||
762 | static int __init init_cedf(void) | 829 | static int __init init_cedf(void) |
763 | { | 830 | { |
764 | return register_sched_plugin(&cedf_plugin); | 831 | int err, fs; |
832 | |||
833 | err = register_sched_plugin(&cedf_plugin); | ||
834 | if (!err) { | ||
835 | fs = make_plugin_proc_dir(&cedf_plugin, &cedf_dir); | ||
836 | if (!fs) { | ||
837 | cluster_file = create_proc_entry("cluster", 0644, cedf_dir); | ||
838 | if (!cluster_file) { | ||
839 | printk(KERN_ERR "Could not allocate C-EDF/cluster " | ||
840 | "procfs entry.\n"); | ||
841 | } else { | ||
842 | cluster_file->read_proc = proc_read_cluster_size; | ||
843 | cluster_file->write_proc = proc_write_cluster_size; | ||
844 | } | ||
845 | } else { | ||
846 | printk(KERN_ERR "Could not allocate C-EDF procfs dir.\n"); | ||
847 | } | ||
848 | } | ||
849 | return err; | ||
765 | } | 850 | } |
766 | 851 | ||
767 | static void clean_cedf(void) | 852 | static void clean_cedf(void) |
768 | { | 853 | { |
769 | cleanup_cedf(); | 854 | cleanup_cedf(); |
855 | if (cluster_file) | ||
856 | remove_proc_entry("cluster", cedf_dir); | ||
857 | if (cedf_dir) | ||
858 | remove_plugin_proc_dir(&cedf_plugin); | ||
770 | } | 859 | } |
771 | 860 | ||
772 | module_init(init_cedf); | 861 | module_init(init_cedf); |