Troubles with the idle process fixed
authorJens Krieg <jkrieg@mailbox.tu-berlin.de>
Tue, 16 Jul 2013 07:38:24 +0000 (09:38 +0200)
committerJens Krieg <jkrieg@mailbox.tu-berlin.de>
Tue, 16 Jul 2013 07:38:24 +0000 (09:38 +0200)
* idle will be (de)scheduled at the right time

Ignoring key strokes still remains

arch/x86/kernel/process.c
kernel/kthread.c
kernel/sched.new/core.c
kernel/sched.new/sched.h
kernel/softirq.c

index 2e3112f..cee1e7c 100644 (file)
@@ -321,7 +321,6 @@ void cpu_idle(void)
 
        while (1) {
                tick_nohz_idle_enter();
-//             printk("\n RUNQUEUE is empty!!!\n");
                while (!need_resched()) {
                        rmb();
 
@@ -354,7 +353,7 @@ void cpu_idle(void)
                           has already called exit_idle. But some idle
                           loops can be woken up without interrupt. */
                        __exit_idle();
-                       break;
+//                     break;
 
                }
                tick_nohz_idle_exit();
index 7187b2d..40304fd 100644 (file)
@@ -171,6 +171,7 @@ static int kthread(void *_create)
                ret = threadfn(data);
        }
 
+       printk("\nKilled Thread(%p) PID: %i", (void*)current, (int)current->pid);
        thread_counter--;
        printk("\nThread counter: %i", thread_counter);
        /* we can't just return, we must preserve "self" on stack */
index f86eddf..3f81992 100644 (file)
@@ -9,16 +9,18 @@
  */
 
 /**
- * TODO:       It looks like we are idle at boot up for a short period.
- *                     Therefore idle have to give up the CPU at some point.
- *                     Right now it is solved via a break, which is VERY inefficient. Further
- *                     idle is kept in the run queue.
- *                     How ever we are able to boot with some I/O errors, due to the fact
- *                     some essential function are not implemented yet (ASSUMTION).
+ * TODO:  2)        Input from register are not printed on the screen although corresponding
+ *                  interrupts are called. After the serial interrupt a thread (0xffff880007054cc0)
+ *                  is activated, which is probably responsible for the output. In our case that thread
+ *                  is already running, which should be not a problem. At the end a tty function (n_tty_write)
+ *                  must be called, which is not, in order to print the input.
  *
- * FIXME:      - Resched idle in efficient way (remove from run queue)
- *                     - Implement wait_for_complition_timeout
- *                     - Implement try_to_wake_up_local?
+ *        3)        While boot up we encounter a kernel stack overflow, which seems to come randomly. Linux
+ *                  stack overflow checker gives us a warning but its to late to back trace.
+ *                  Maybe we should fix this one first in order to be sure that there are no side effects produced
+ *                  by this "error".
+ *
+ *        4)        We need to strip down clock.c since we use the default linux implementation.
  */
 
 #include <linux/init.h>
@@ -895,7 +897,7 @@ need_resched:
 //     if (sched_feat(HRTICK))
 //             hrtick_clear(rq);
 
-//     raw_spin_lock_irq(&rq->lock);
+       raw_spin_lock_irq(&rq->lock);
 
 //     switch_count = &prev->nivcsw;
        if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
@@ -916,15 +918,14 @@ need_resched:
 
                                to_wakeup = wq_worker_sleeping(prev, cpu);
                                if (to_wakeup)
-                                       //printk("\ntry_to_wake_up_local() needs to be implemented");
                                        try_to_wake_up_local(to_wakeup);
                        }
                }
 //             switch_count = &prev->nvcsw;
        }
-//
+
 //     pre_schedule(rq, prev);
-//
+
 //     if (unlikely(!rq->nr_running))
 //             idle_balance(cpu, rq);
 
@@ -943,7 +944,7 @@ need_resched:
                next = rq->idle;
 
 
-//     clear_tsk_need_resched(prev);
+       clear_tsk_need_resched(prev);
 //     rq->skip_clock_update = 0;
 
        if (likely(prev != next)) {
@@ -953,7 +954,7 @@ need_resched:
 
                context_switch(rq, prev, next); /* unlocks the rq */
                arch_local_irq_enable();
-               //irqs_enable();
+
                /*
                 * The context switch have flipped the stack from under us
                 * and restored the local variables which were saved when
@@ -982,6 +983,14 @@ asmlinkage void __sched schedule(void)
 }
 EXPORT_SYMBOL(schedule);
 
+/**
+ * kernel/sched/core.c:652
+ */
+void resched_task(struct task_struct *p)
+{
+       assert_raw_spin_locked(&task_rq(p)->lock);
+       set_tsk_need_resched(p);
+}
 
 /**
  * kernel/sched/core.c:1439
@@ -1018,6 +1027,9 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
        p->state = TASK_RUNNING;
        list_add(&p->rq_tasks, &rq->rq_list);
 
+       if (rq->curr == rq->idle)
+               resched_task(rq->curr);
+
        /* if a worker is waking up, notify workqueue */
        if (p->flags & PF_WQ_WORKER)
                wq_worker_waking_up(p, 0);
@@ -1057,16 +1069,18 @@ static void try_to_wake_up_local(struct task_struct *p)
 //     }
 
        if (!(p->state & TASK_NORMAL))
-                       goto out;
+               goto out;
 
        p->on_rq = 1;
        p->state = TASK_RUNNING;
        list_add(&p->rq_tasks, &rq->rq_list);
 
+       if (rq->curr == rq->idle)
+               resched_task(rq->curr);
 
 //     if (!p->on_rq)
 //             ttwu_activate(rq, p, ENQUEUE_WAKEUP);
-//
+
 //     ttwu_do_wakeup(rq, p, 0);
 //     ttwu_stat(p, smp_processor_id(), 0);
 out:
@@ -1575,7 +1589,6 @@ unsigned long __sched
 wait_for_completion_timeout(struct completion *x, unsigned long timeout)
 {
        return wait_for_common(x, timeout, TASK_UNINTERRUPTIBLE);
-
 }
 
 
index 694a581..c8a19b7 100644 (file)
@@ -34,6 +34,7 @@ DECLARE_PER_CPU(struct rq, runqueues);
 
 #define cpu_rq(cpu)            (&per_cpu(runqueues, (cpu)))
 #define this_rq()              (&__get_cpu_var(runqueues))
+#define task_rq(p)             cpu_rq(task_cpu(p))
 
 void account_idle_ticks(unsigned long ticks);
 
index 14d7758..1c2e7d5 100644 (file)
@@ -73,6 +73,10 @@ static void wakeup_softirqd(void)
        /* Interrupts are disabled: no need to stop preemption */
        struct task_struct *tsk = __this_cpu_read(ksoftirqd);
 
+       printk("\nTask struct address: %p", (void*)tsk);
+       if (tsk)
+               printk("\nTask struct state: %ld", (long int)tsk->state);
+
        if (tsk && tsk->state != TASK_RUNNING)
                wake_up_process(tsk);
 }