I'll never use i and j as counter variables again.
[linux-2.6.git] / linux-2.6-591-chopstix-intern.patch
index 433d558..5f81751 100644 (file)
@@ -323,30 +323,22 @@ Index: linux-2.6.27.y/include/linux/arrays.h
 +      struct task_struct *task;
 +};
 +#endif
-Index: linux-2.6.27.y/include/linux/sched.h.rej
+Index: linux-2.6.27.y/include/linux/sched.h
 ===================================================================
---- /dev/null
-+++ linux-2.6.27.y/include/linux/sched.h.rej
-@@ -0,0 +1,19 @@
-+***************
-+*** 850,855 ****
-+  #endif
-+      unsigned long sleep_avg;
-+      unsigned long long timestamp, last_ran;
-+      unsigned long long sched_time; /* sched_clock time spent running */
-+      enum sleep_type sleep_type;
-+  
-+--- 850,859 ----
-+  #endif
-+      unsigned long sleep_avg;
-+      unsigned long long timestamp, last_ran;
-++ #ifdef CONFIG_CHOPSTIX
-++     unsigned long last_interrupted, last_ran_j;
-++ #endif
-++ 
-+      unsigned long long sched_time; /* sched_clock time spent running */
-+      enum sleep_type sleep_type;
-+  
+--- linux-2.6.27.y.orig/include/linux/sched.h
++++ linux-2.6.27.y/include/linux/sched.h
+@@ -1137,6 +1137,11 @@ struct task_struct {
+       cputime_t utime, stime, utimescaled, stimescaled;
+       cputime_t gtime;
+       cputime_t prev_utime, prev_stime;
++
++    #ifdef CONFIG_CHOPSTIX
++            unsigned long last_interrupted, last_ran_j;
++    #endif
++
+       unsigned long nvcsw, nivcsw; /* context switch counts */
+       struct timespec start_time;             /* monotonic time */
+       struct timespec real_start_time;        /* boot based time */
 Index: linux-2.6.27.y/kernel/sched.c
 ===================================================================
 --- linux-2.6.27.y.orig/kernel/sched.c
@@ -377,7 +369,18 @@ Index: linux-2.6.27.y/kernel/sched.c
  /*
   * Convert user-nice values [ -20 ... 0 ... 19 ]
   * to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
-@@ -4436,6 +4440,29 @@ pick_next_task(struct rq *rq, struct tas
+@@ -2376,6 +2380,10 @@ static void __sched_fork(struct task_str
+       INIT_HLIST_HEAD(&p->preempt_notifiers);
+ #endif
++#ifdef CONFIG_CHOPSTIX
++    p->last_ran_j = jiffies;
++    p->last_interrupted = INTERRUPTIBLE;
++#endif
+       /*
+        * We mark the process as running here, but have not actually
+        * inserted it onto the runqueue yet. This guarantees that
+@@ -4436,6 +4444,29 @@ pick_next_task(struct rq *rq, struct tas
        }
  }
  
@@ -407,7 +410,69 @@ Index: linux-2.6.27.y/kernel/sched.c
  /*
   * schedule() is the main scheduler function.
   */
-@@ -5382,6 +5409,7 @@ long sched_setaffinity(pid_t pid, const 
+@@ -4495,6 +4526,61 @@ need_resched_nonpreemptible:
+       next = pick_next_task(rq, prev);
+       if (likely(prev != next)) {
++
++#ifdef CONFIG_CHOPSTIX
++      /* Run only if the Chopstix module so decrees it */
++      if (rec_event) {
++        unsigned long diff;
++        int sampling_reason;
++              prev->last_ran_j = jiffies;
++              if (next->last_interrupted!=INTERRUPTIBLE) {
++                      if (next->last_interrupted!=RUNNING) {
++                              diff = (jiffies-next->last_interrupted);
++                              sampling_reason = 0;/* BLOCKING */
++                      }
++                      else {
++                              diff = jiffies-next->last_ran_j; 
++                              sampling_reason = 1;/* PREEMPTION */
++                      }
++
++                      if (diff >= HZ/10) {
++                struct event_spec {
++                   unsigned long pc;
++                   unsigned long dcookie;
++                   unsigned int count;
++                   unsigned int reason;
++                };
++
++                              struct event event;
++                              struct event_spec espec;
++                struct pt_regs *regs;
++                regs = task_pt_regs(current);
++
++                              espec.reason = sampling_reason;
++                              event.event_data=&espec;
++                              event.task=next;
++                              espec.pc=regs->ip;
++                              event.event_type=2; 
++                              /* index in the event array currently set up */
++                              /* make sure the counters are loaded in the order we want them to show up*/ 
++                              (*rec_event)(&event, diff);
++                      }
++              }
++        /* next has been elected to run */
++              next->last_interrupted=0;
++
++        /* An uninterruptible process just yielded. Record the current jiffy */
++        if (prev->state & TASK_UNINTERRUPTIBLE) {
++            prev->last_interrupted=jiffies;
++        }
++         /* An interruptible process just yielded, or it got preempted. 
++          * Mark it as interruptible */
++        else if (prev->state & TASK_INTERRUPTIBLE) {
++            prev->last_interrupted=INTERRUPTIBLE;
++        }
++      }
++#endif
++
+               sched_info_switch(prev, next);
+               rq->nr_switches++;
+@@ -5382,6 +5468,7 @@ long sched_setaffinity(pid_t pid, const 
        get_task_struct(p);
        read_unlock(&tasklist_lock);
  
@@ -415,269 +480,6 @@ Index: linux-2.6.27.y/kernel/sched.c
        retval = -EPERM;
        if ((current->euid != p->euid) && (current->euid != p->uid) &&
                        !capable(CAP_SYS_NICE))
-Index: linux-2.6.27.y/kernel/sched.c.rej
-===================================================================
---- /dev/null
-+++ linux-2.6.27.y/kernel/sched.c.rej
-@@ -0,0 +1,258 @@
-+***************
-+*** 23,28 ****
-+  #include <linux/nmi.h>
-+  #include <linux/init.h>
-+  #include <asm/uaccess.h>
-+  #include <linux/highmem.h>
-+  #include <linux/smp_lock.h>
-+  #include <asm/mmu_context.h>
-+--- 23,29 ----
-+  #include <linux/nmi.h>
-+  #include <linux/init.h>
-+  #include <asm/uaccess.h>
-++ #include <linux/arrays.h>
-+  #include <linux/highmem.h>
-+  #include <linux/smp_lock.h>
-+  #include <asm/mmu_context.h>
-+***************
-+*** 451,456 ****
-+  
-+  repeat_lock_task:
-+      rq = task_rq(p);
-+      spin_lock(&rq->lock);
-+      if (unlikely(rq != task_rq(p))) {
-+              spin_unlock(&rq->lock);
-+--- 455,461 ----
-+  
-+  repeat_lock_task:
-+      rq = task_rq(p);
-++ 
-+      spin_lock(&rq->lock);
-+      if (unlikely(rq != task_rq(p))) {
-+              spin_unlock(&rq->lock);
-+***************
-+*** 1761,1766 ****
-+       * event cannot wake it up and insert it on the runqueue either.
-+       */
-+      p->state = TASK_RUNNING;
-+  
-+      /*
-+       * Make sure we do not leak PI boosting priority to the child:
-+--- 1766,1786 ----
-+       * event cannot wake it up and insert it on the runqueue either.
-+       */
-+      p->state = TASK_RUNNING;
-++ #ifdef CONFIG_CHOPSTIX
-++     /* The jiffy of last interruption */
-++     if (p->state & TASK_UNINTERRUPTIBLE) {
-++                             p->last_interrupted=jiffies;
-++     }
-++     else
-++     if (p->state & TASK_INTERRUPTIBLE) {
-++                             p->last_interrupted=INTERRUPTIBLE;
-++     }
-++     else
-++         p->last_interrupted=RUNNING;
-++ 
-++     /* The jiffy of last execution */ 
-++     p->last_ran_j=jiffies;
-++ #endif
-+  
-+      /*
-+       * Make sure we do not leak PI boosting priority to the child:
-+***************
-+*** 3628,3633 ****
-+  
-+  #endif
-+  
-+  static inline int interactive_sleep(enum sleep_type sleep_type)
-+  {
-+      return (sleep_type == SLEEP_INTERACTIVE ||
-+--- 3648,3654 ----
-+  
-+  #endif
-+  
-++ 
-+  static inline int interactive_sleep(enum sleep_type sleep_type)
-+  {
-+      return (sleep_type == SLEEP_INTERACTIVE ||
-+***************
-+*** 3637,3652 ****
-+  /*
-+   * schedule() is the main scheduler function.
-+   */
-+  asmlinkage void __sched schedule(void)
-+  {
-+      struct task_struct *prev, *next;
-+      struct prio_array *array;
-+      struct list_head *queue;
-+      unsigned long long now;
-+-     unsigned long run_time;
-+      int cpu, idx, new_prio;
-+      long *switch_count;
-+      struct rq *rq;
-+  
-+      /*
-+       * Test if we are atomic.  Since do_exit() needs to call into
-+--- 3658,3685 ----
-+  /*
-+   * schedule() is the main scheduler function.
-+   */
-++ 
-++ #ifdef CONFIG_CHOPSTIX
-++ extern void (*rec_event)(void *,unsigned int);
-++ struct event_spec {
-++     unsigned long pc;
-++     unsigned long dcookie;
-++     unsigned int count;
-++     unsigned int reason;
-++ };
-++ #endif
-++ 
-+  asmlinkage void __sched schedule(void)
-+  {
-+      struct task_struct *prev, *next;
-+      struct prio_array *array;
-+      struct list_head *queue;
-+      unsigned long long now;
-++     unsigned long run_time, diff;
-+      int cpu, idx, new_prio;
-+      long *switch_count;
-+      struct rq *rq;
-++     int sampling_reason;
-+  
-+      /*
-+       * Test if we are atomic.  Since do_exit() needs to call into
-+***************
-+*** 3700,3705 ****
-+      switch_count = &prev->nivcsw;
-+      if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
-+              switch_count = &prev->nvcsw;
-+              if (unlikely((prev->state & TASK_INTERRUPTIBLE) &&
-+                              unlikely(signal_pending(prev))))
-+                      prev->state = TASK_RUNNING;
-+--- 3733,3739 ----
-+      switch_count = &prev->nivcsw;
-+      if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
-+              switch_count = &prev->nvcsw;
-++ 
-+              if (unlikely((prev->state & TASK_INTERRUPTIBLE) &&
-+                              unlikely(signal_pending(prev))))
-+                      prev->state = TASK_RUNNING;
-+***************
-+*** 3709,3714 ****
-+                              vx_uninterruptible_inc(prev);
-+                      }
-+                      deactivate_task(prev, rq);
-+              }
-+      }
-+  
-+--- 3743,3759 ----
-+                              vx_uninterruptible_inc(prev);
-+                      }
-+                      deactivate_task(prev, rq);
-++ #ifdef CONFIG_CHOPSTIX
-++             /* An uninterruptible process just yielded. Record the current jiffie */
-++                     if (prev->state & TASK_UNINTERRUPTIBLE) {
-++                             prev->last_interrupted=jiffies;
-++                     }
-++             /* An interruptible process just yielded, or it got preempted. 
-++              * Mark it as interruptible */
-++                     else if (prev->state & TASK_INTERRUPTIBLE) {
-++                             prev->last_interrupted=INTERRUPTIBLE;
-++                     }
-++ #endif
-+              }
-+      }
-+  
-+***************
-+*** 3785,3790 ****
-+              prev->sleep_avg = 0;
-+      prev->timestamp = prev->last_ran = now;
-+  
-+      sched_info_switch(prev, next);
-+      if (likely(prev != next)) {
-+              next->timestamp = next->last_ran = now;
-+--- 3830,3869 ----
-+              prev->sleep_avg = 0;
-+      prev->timestamp = prev->last_ran = now;
-+  
-++ #ifdef CONFIG_CHOPSTIX
-++     /* Run only if the Chopstix module so decrees it */
-++     if (rec_event) {
-++             prev->last_ran_j = jiffies;
-++             if (next->last_interrupted!=INTERRUPTIBLE) {
-++                     if (next->last_interrupted!=RUNNING) {
-++                             diff = (jiffies-next->last_interrupted);
-++                             sampling_reason = 0;/* BLOCKING */
-++                     }
-++                     else {
-++                             diff = jiffies-next->last_ran_j; 
-++                             sampling_reason = 1;/* PREEMPTION */
-++                     }
-++ 
-++                     if (diff >= HZ/10) {
-++                             struct event event;
-++                             struct event_spec espec;
-++                 struct pt_regs *regs;
-++                 regs = task_pt_regs(current);
-++ 
-++                             espec.reason = sampling_reason;
-++                             event.event_data=&espec;
-++                             event.task=next;
-++                             espec.pc=regs->eip;
-++                             event.event_type=2; 
-++                             /* index in the event array currently set up */
-++                             /* make sure the counters are loaded in the order we want them to show up*/ 
-++                             (*rec_event)(&event, diff);
-++                     }
-++             }
-++         /* next has been elected to run */
-++             next->last_interrupted=0;
-++     }
-++ #endif
-+      sched_info_switch(prev, next);
-+      if (likely(prev != next)) {
-+              next->timestamp = next->last_ran = now;
-+***************
-+*** 5737,5742 ****
-+      jiffies_to_timespec(p->policy == SCHED_FIFO ?
-+                              0 : task_timeslice(p), &t);
-+      read_unlock(&tasklist_lock);
-+      retval = copy_to_user(interval, &t, sizeof(t)) ? -EFAULT : 0;
-+  out_nounlock:
-+      return retval;
-+--- 5817,5823 ----
-+      jiffies_to_timespec(p->policy == SCHED_FIFO ?
-+                              0 : task_timeslice(p), &t);
-+      read_unlock(&tasklist_lock);
-++ 
-+      retval = copy_to_user(interval, &t, sizeof(t)) ? -EFAULT : 0;
-+  out_nounlock:
-+      return retval;
-+***************
-+*** 7980,7982 ****
-+  }
-+  
-+  #endif
-+--- 8061,8080 ----
-+  }
-+  
-+  #endif
-++ 
-++ #ifdef CONFIG_CHOPSTIX
-++ void (*rec_event)(void *,unsigned int) = NULL;
-++ 
-++ /* To support safe calling from asm */
-++ asmlinkage void rec_event_asm (struct event *event_signature_in, unsigned int count) {
-++     struct pt_regs *regs;
-++     struct event_spec *es = event_signature_in->event_data;
-++     regs = task_pt_regs(current);
-++     event_signature_in->task=current;
-++     es->pc=regs->eip;
-++     event_signature_in->count=1;
-++     (*rec_event)(event_signature_in, count);
-++ }
-++ EXPORT_SYMBOL(rec_event);
-++ EXPORT_SYMBOL(in_sched_functions);
-++ #endif
 Index: linux-2.6.27.y/mm/memory.c
 ===================================================================
 --- linux-2.6.27.y.orig/mm/memory.c