aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2007-10-07 18:34:08 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2007-10-07 18:34:08 -0400
commit3a591b6003054e1d4e15c8dd7deefe3c8090192e (patch)
tree50bacb6e64c63514250a80b21d024c41cd5e8bfe /kernel
parent13977c0c24b29cef8516683f028dd5eea399fc56 (diff)
litmus: add qsort list manipulation function
The adaptive optimizer needs to sort lists.
Diffstat (limited to 'kernel')
-rw-r--r--kernel/litmus.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/kernel/litmus.c b/kernel/litmus.c
index c05a20bde7..131fc5039e 100644
--- a/kernel/litmus.c
+++ b/kernel/litmus.c
@@ -679,6 +679,46 @@ void exit_litmus(struct task_struct *dead_tsk)
679 curr_sched_plugin->tear_down(dead_tsk); 679 curr_sched_plugin->tear_down(dead_tsk);
680} 680}
681 681
682void list_qsort(struct list_head* list, list_cmp_t less_than)
683{
684 struct list_head lt;
685 struct list_head geq;
686 struct list_head *pos, *extra, *pivot;
687 int n_lt = 0, n_geq = 0;
688 BUG_ON(!list);
689
690 if (list->next == list)
691 return;
692
693 INIT_LIST_HEAD(&lt);
694 INIT_LIST_HEAD(&geq);
695
696 pivot = list->next;
697 list_for_each_safe(pos, extra, list) {
698 list_del(pos);
699 if (less_than(pos, pivot)) {
700 list_add(pos, &lt);
701 n_lt++;
702 } else {
703 list_add(pos, &geq);
704 n_geq++;
705 }
706 }
707 if (n_lt < n_geq) {
708 if (n_lt > 1)
709 list_qsort(&lt, less_than);
710 if (n_geq > 1)
711 list_qsort(&geq, less_than);
712 } else {
713 if (n_geq > 1)
714 list_qsort(&geq, less_than);
715 if (n_lt > 1)
716 list_qsort(&lt, less_than);
717 }
718 list_splice(&geq, list);
719 list_splice(&lt, list);
720}
721
682#ifdef CONFIG_MAGIC_SYSRQ 722#ifdef CONFIG_MAGIC_SYSRQ
683/* We offer the possibility to change the real-time mode of the system 723/* We offer the possibility to change the real-time mode of the system
684 * with a magic sys request. This helps in debugging in case the system fails 724 * with a magic sys request. This helps in debugging in case the system fails