Finished porting the scheduler probe to 2.6.27. Should be ready to run and test now.
[linux-2.6.git] / linux-2.6-591-chopstix-intern.patch
index 2dd4cac..2822b4d 100644 (file)
@@ -69,6 +69,27 @@ diff -Nurb linux-2.6.27-590/arch/x86/kernel/asm-offsets_32.c linux-2.6.27-591/ar
        OFFSET(TI_task, thread_info, task);
        OFFSET(TI_exec_domain, thread_info, exec_domain);
        OFFSET(TI_flags, thread_info, flags);
+diff -Nurb linux-2.6.27-590/arch/x86/kernel/asm-offsets_32.c.rej linux-2.6.27-591/arch/x86/kernel/asm-offsets_32.c.rej
+--- linux-2.6.27-590/arch/x86/kernel/asm-offsets_32.c.rej      1969-12-31 19:00:00.000000000 -0500
++++ linux-2.6.27-591/arch/x86/kernel/asm-offsets_32.c.rej      2010-01-31 22:21:08.000000000 -0500
+@@ -0,0 +1,17 @@
++***************
++*** 63,69 ****
++      BLANK();
++  
++      STACKOFFSET(TASK_thread, task_struct, thread);
++-     STACKOFFSET(THREAD_esp, thread_struct, esp);
++      STACKOFFSET(EVENT_event_data, event, event_data);
++      STACKOFFSET(EVENT_task, event, task);
++      STACKOFFSET(EVENT_event_type, event, event_type);
++--- 63,69 ----
++      BLANK();
++  
++      STACKOFFSET(TASK_thread, task_struct, thread);
+++     STACKOFFSET(THREAD_esp, thread_struct, sp);
++      STACKOFFSET(EVENT_event_data, event, event_data);
++      STACKOFFSET(EVENT_task, event, task);
++      STACKOFFSET(EVENT_event_type, event, event_type);
 diff -Nurb linux-2.6.27-590/arch/x86/kernel/entry_32.S linux-2.6.27-591/arch/x86/kernel/entry_32.S
 --- linux-2.6.27-590/arch/x86/kernel/entry_32.S        2008-10-09 18:13:53.000000000 -0400
 +++ linux-2.6.27-591/arch/x86/kernel/entry_32.S        2010-01-29 16:30:22.000000000 -0500
@@ -193,7 +214,7 @@ diff -Nurb linux-2.6.27-590/drivers/oprofile/cpu_buffer.c linux-2.6.27-591/drive
  void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event)
 diff -Nurb linux-2.6.27-590/fs/bio.c linux-2.6.27-591/fs/bio.c
 --- linux-2.6.27-590/fs/bio.c  2008-10-09 18:13:53.000000000 -0400
-+++ linux-2.6.27-591/fs/bio.c  2010-01-29 16:30:22.000000000 -0500
++++ linux-2.6.27-591/fs/bio.c  2010-01-31 22:21:09.000000000 -0500
 @@ -27,6 +27,7 @@
  #include <linux/workqueue.h>
  #include <linux/blktrace_api.h>
@@ -229,7 +250,7 @@ diff -Nurb linux-2.6.27-590/fs/bio.c linux-2.6.27-591/fs/bio.c
        else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
                error = -EIO;
  
-+#ifdef CONFIG_CHOPSTIX
++#if 0
 +              if (rec_event) {
 +                      struct event event;
 +                      struct event_spec espec;
@@ -275,6 +296,46 @@ diff -Nurb linux-2.6.27-590/fs/exec.c linux-2.6.27-591/fs/exec.c
        return file;
  
   out_path_put:
+diff -Nurb linux-2.6.27-590/fs/exec.c.rej linux-2.6.27-591/fs/exec.c.rej
+--- linux-2.6.27-590/fs/exec.c.rej     1969-12-31 19:00:00.000000000 -0500
++++ linux-2.6.27-591/fs/exec.c.rej     2010-01-31 22:21:18.000000000 -0500
+@@ -0,0 +1,36 @@
++***************
++*** 40,46 ****
++  #include <linux/personality.h>
++  #include <linux/binfmts.h>
++  #include <linux/utsname.h>
++- /*#include <linux/pid_namespace.h>*/
++  #include <linux/module.h>
++  #include <linux/namei.h>
++  #include <linux/proc_fs.h>
++--- 40,46 ----
++  #include <linux/personality.h>
++  #include <linux/binfmts.h>
++  #include <linux/utsname.h>
+++ #include <linux/pid_namespace.h>
++  #include <linux/module.h>
++  #include <linux/namei.h>
++  #include <linux/proc_fs.h>
++***************
++*** 702,709 ****
++   #ifdef CONFIG_CHOPSTIX
++      unsigned long cookie;
++      extern void (*rec_event)(void *, unsigned int);
++-     if (rec_event && !nd.dentry->d_cookie)
++-         get_dcookie(nd.dentry, nd.mnt, &cookie);
++   #endif
++  
++      return file;
++--- 702,709 ----
++   #ifdef CONFIG_CHOPSTIX
++      unsigned long cookie;
++      extern void (*rec_event)(void *, unsigned int);
+++     if (rec_event && !nd.path.dentry->d_cookie)
+++         get_dcookie(&nd.path, &cookie);
++   #endif
++  
++      return file;
 diff -Nurb linux-2.6.27-590/include/linux/arrays.h linux-2.6.27-591/include/linux/arrays.h
 --- linux-2.6.27-590/include/linux/arrays.h    1969-12-31 19:00:00.000000000 -0500
 +++ linux-2.6.27-591/include/linux/arrays.h    2010-01-29 16:30:22.000000000 -0500
@@ -315,6 +376,21 @@ diff -Nurb linux-2.6.27-590/include/linux/arrays.h linux-2.6.27-591/include/linu
 +      struct task_struct *task;
 +};
 +#endif
+diff -Nurb linux-2.6.27-590/include/linux/sched.h linux-2.6.27-591/include/linux/sched.h
+--- linux-2.6.27-590/include/linux/sched.h     2010-01-29 16:29:48.000000000 -0500
++++ linux-2.6.27-591/include/linux/sched.h     2010-02-01 16:41:30.000000000 -0500
+@@ -1133,6 +1133,11 @@
+       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 */
 diff -Nurb linux-2.6.27-590/include/linux/sched.h.rej linux-2.6.27-591/include/linux/sched.h.rej
 --- linux-2.6.27-590/include/linux/sched.h.rej 1969-12-31 19:00:00.000000000 -0500
 +++ linux-2.6.27-591/include/linux/sched.h.rej 2010-01-29 16:30:22.000000000 -0500
@@ -340,7 +416,7 @@ diff -Nurb linux-2.6.27-590/include/linux/sched.h.rej linux-2.6.27-591/include/l
 +  
 diff -Nurb linux-2.6.27-590/kernel/sched.c linux-2.6.27-591/kernel/sched.c
 --- linux-2.6.27-590/kernel/sched.c    2010-01-29 16:29:48.000000000 -0500
-+++ linux-2.6.27-591/kernel/sched.c    2010-01-29 17:30:42.000000000 -0500
++++ linux-2.6.27-591/kernel/sched.c    2010-02-01 16:41:30.000000000 -0500
 @@ -10,7 +10,7 @@
   *  1998-11-19        Implemented schedule_timeout() and related stuff
   *            by Andrea Arcangeli
@@ -350,7 +426,14 @@ diff -Nurb linux-2.6.27-590/kernel/sched.c linux-2.6.27-591/kernel/sched.c
   *            an array-switch method of distributing timeslices
   *            and per-CPU runqueues.  Cleanups and useful suggestions
   *            by Davide Libenzi, preemptible kernel bits by Robert Love.
-@@ -79,6 +79,9 @@
+@@ -73,12 +73,16 @@
+ #include <linux/ftrace.h>
+ #include <linux/vs_sched.h>
+ #include <linux/vs_cvirt.h>
++#include <linux/arrays.h>
+ #include <asm/tlb.h>
+ #include <asm/irq_regs.h>
  
  #include "sched_cpupri.h"
  
@@ -360,19 +443,110 @@ diff -Nurb linux-2.6.27-590/kernel/sched.c linux-2.6.27-591/kernel/sched.c
  /*
   * Convert user-nice values [ -20 ... 0 ... 19 ]
   * to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
-@@ -4428,6 +4431,11 @@
+@@ -2368,6 +2372,10 @@
+       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
+@@ -4428,6 +4436,29 @@
        }
  }
  
-+#ifdef CONFIG_CHOPSTIX
 +void (*rec_event)(void *,unsigned int) = NULL;
 +EXPORT_SYMBOL(rec_event);
++#ifdef CONFIG_CHOPSTIX
++
++struct event_spec {
++    unsigned long pc;
++    unsigned long dcookie;
++    unsigned int count;
++    unsigned int reason;
++};
++
++/* 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->ip;
++    event_signature_in->count=1;
++    (*rec_event)(event_signature_in, count);
++}
 +#endif
 +
  /*
   * schedule() is the main scheduler function.
   */
-@@ -5369,6 +5377,7 @@
+@@ -4482,6 +4513,61 @@
+       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++;
+@@ -5369,6 +5455,7 @@
        get_task_struct(p);
        read_unlock(&tasklist_lock);
  
@@ -380,10 +554,37 @@ diff -Nurb linux-2.6.27-590/kernel/sched.c linux-2.6.27-591/kernel/sched.c
        retval = -EPERM;
        if ((current->euid != p->euid) && (current->euid != p->uid) &&
                        !capable(CAP_SYS_NICE))
+@@ -9296,3 +9383,26 @@
+       .subsys_id = cpuacct_subsys_id,
+ };
+ #endif        /* CONFIG_CGROUP_CPUACCT */
++
++#ifdef CONFIG_CHOPSTIX
++void (*rec_event)();
++EXPORT_SYMBOL(rec_event);
++
++struct event_spec {
++    unsigned long pc;
++    unsigned long dcookie;
++    unsigned int count;
++    unsigned int reason;
++};
++
++/* 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->ip;
++    event_signature_in->count=1;
++    (*rec_event)(event_signature_in, count);
++}
++#endif
 diff -Nurb linux-2.6.27-590/kernel/sched.c.orig linux-2.6.27-591/kernel/sched.c.orig
 --- linux-2.6.27-590/kernel/sched.c.orig       1969-12-31 19:00:00.000000000 -0500
-+++ linux-2.6.27-591/kernel/sched.c.orig       2010-01-29 16:30:22.000000000 -0500
-@@ -0,0 +1,9302 @@
++++ linux-2.6.27-591/kernel/sched.c.orig       2010-01-31 22:21:08.000000000 -0500
+@@ -0,0 +1,9349 @@
 +/*
 + *  kernel/sched.c
 + *
@@ -459,6 +660,7 @@ diff -Nurb linux-2.6.27-590/kernel/sched.c.orig linux-2.6.27-591/kernel/sched.c.
 +#include <linux/ftrace.h>
 +#include <linux/vs_sched.h>
 +#include <linux/vs_cvirt.h>
++#include <linux/arrays.h>
 +
 +#include <asm/tlb.h>
 +#include <asm/irq_regs.h>
@@ -4817,6 +5019,29 @@ diff -Nurb linux-2.6.27-590/kernel/sched.c.orig linux-2.6.27-591/kernel/sched.c.
 +      }
 +}
 +
++void (*rec_event)(void *,unsigned int) = NULL;
++EXPORT_SYMBOL(rec_event);
++#ifdef CONFIG_CHOPSTIX
++
++struct event_spec {
++    unsigned long pc;
++    unsigned long dcookie;
++    unsigned int count;
++    unsigned int reason;
++};
++
++/* 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->ip;
++    event_signature_in->count=1;
++    (*rec_event)(event_signature_in, count);
++}
++#endif
++
 +/*
 + * schedule() is the main scheduler function.
 + */
@@ -9686,6 +9911,29 @@ diff -Nurb linux-2.6.27-590/kernel/sched.c.orig linux-2.6.27-591/kernel/sched.c.
 +      .subsys_id = cpuacct_subsys_id,
 +};
 +#endif        /* CONFIG_CGROUP_CPUACCT */
++
++#ifdef CONFIG_CHOPSTIX
++void (*rec_event)();
++EXPORT_SYMBOL(rec_event);
++
++struct event_spec {
++    unsigned long pc;
++    unsigned long dcookie;
++    unsigned int count;
++    unsigned int reason;
++};
++
++/* 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->ip;
++    event_signature_in->count=1;
++    (*rec_event)(event_signature_in, count);
++}
++#endif
 diff -Nurb linux-2.6.27-590/kernel/sched.c.rej linux-2.6.27-591/kernel/sched.c.rej
 --- linux-2.6.27-590/kernel/sched.c.rej        1969-12-31 19:00:00.000000000 -0500
 +++ linux-2.6.27-591/kernel/sched.c.rej        2010-01-29 16:30:22.000000000 -0500
@@ -9950,7 +10198,7 @@ diff -Nurb linux-2.6.27-590/kernel/sched.c.rej linux-2.6.27-591/kernel/sched.c.r
 ++ #endif
 diff -Nurb linux-2.6.27-590/mm/memory.c linux-2.6.27-591/mm/memory.c
 --- linux-2.6.27-590/mm/memory.c       2010-01-29 16:29:48.000000000 -0500
-+++ linux-2.6.27-591/mm/memory.c       2010-01-29 16:30:22.000000000 -0500
++++ linux-2.6.27-591/mm/memory.c       2010-01-31 22:21:18.000000000 -0500
 @@ -61,6 +61,7 @@
  
  #include <linux/swapops.h>
@@ -9986,7 +10234,7 @@ diff -Nurb linux-2.6.27-590/mm/memory.c linux-2.6.27-591/mm/memory.c
 +        struct pt_regs *regs;
 +        unsigned int pc;
 +        regs = task_pt_regs(current);
-+        pc = regs->eip & (unsigned int) ~4095;
++        pc = regs->ip & (unsigned int) ~4095;
 +
 +              espec.reason = 0; /* alloc */
 +              event.event_data=&espec;