Weeding out temporary files.
[linux-2.6.git] / linux-2.6-591-chopstix-intern.patch
1 diff -Nurb --exclude='*.cmd' --exclude='*.orig' --exclude='*.swp' --exclude=tags --exclude='*.patch' --exclude='*.diff' --exclude='*.svn*' linux-2.6.22-590/arch/i386/Kconfig linux-2.6.22-591/arch/i386/Kconfig
2 --- linux-2.6.22-590/arch/i386/Kconfig  2009-03-16 20:49:42.000000000 -0400
3 +++ linux-2.6.22-591/arch/i386/Kconfig  2009-03-16 20:58:59.000000000 -0400
4 @@ -1217,6 +1217,14 @@
5  
6  source "arch/i386/oprofile/Kconfig"
7  
8 +config CHOPSTIX
9 +       bool "Chopstix (PlanetLab)"
10 +       depends on MODULES && OPROFILE
11 +       help
12 +         Chopstix allows you to monitor various events by summarizing them
13 +         in lossy data structures and transferring these data structures
14 +         into user space. If in doubt, say "N".
15 +
16  config KPROBES
17         bool "Kprobes (EXPERIMENTAL)"
18         depends on KALLSYMS && EXPERIMENTAL && MODULES
19 --- linux-2.6.22-590/arch/i386/kernel/asm-offsets.c     2007-07-08 19:32:17.000000000 -0400
20 +++ linux-2.6.22-591/arch/i386/kernel/asm-offsets.c     2009-03-16 20:58:59.000000000 -0400
21 @@ -9,6 +9,7 @@
22  #include <linux/signal.h>
23  #include <linux/personality.h>
24  #include <linux/suspend.h>
25 +#include <linux/arrays.h>
26  #include <asm/ucontext.h>
27  #include "sigframe.h"
28  #include <asm/pgtable.h>
29 @@ -25,9 +26,19 @@
30  #define OFFSET(sym, str, mem) \
31         DEFINE(sym, offsetof(struct str, mem));
32  
33 +#define STACKOFFSET(sym, str, mem) \
34 +       DEFINE(sym, offsetof(struct str, mem)-sizeof(struct str));
35 +
36  /* workaround for a warning with -Wmissing-prototypes */
37  void foo(void);
38  
39 +struct event_spec {
40 +       unsigned long pc;
41 +       unsigned long dcookie;
42 +       unsigned count;
43 +       unsigned int number;
44 +};
45 +
46  void foo(void)
47  {
48         OFFSET(SIGCONTEXT_eax, sigcontext, eax);
49 @@ -51,7 +62,16 @@
50         OFFSET(CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id);
51         BLANK();
52  
53 -       OFFSET(TI_task, thread_info, task);
54 +    STACKOFFSET(TASK_thread, task_struct, thread);
55 +    STACKOFFSET(THREAD_esp, thread_struct, esp);
56 +    STACKOFFSET(EVENT_event_data, event, event_data);
57 +    STACKOFFSET(EVENT_task, event, task);
58 +    STACKOFFSET(EVENT_event_type, event, event_type);
59 +    STACKOFFSET(SPEC_number, event_spec, number);
60 +    DEFINE(EVENT_SIZE, sizeof(struct event));
61 +    DEFINE(SPEC_SIZE, sizeof(struct event_spec));
62 +    DEFINE(SPEC_EVENT_SIZE, sizeof(struct event_spec)+sizeof(struct event));
63 +
64         OFFSET(TI_exec_domain, thread_info, exec_domain);
65         OFFSET(TI_flags, thread_info, flags);
66         OFFSET(TI_status, thread_info, status);
67 --- linux-2.6.22-590/arch/i386/kernel/entry.S   2009-03-16 20:49:07.000000000 -0400
68 +++ linux-2.6.22-591/arch/i386/kernel/entry.S   2009-03-16 20:58:59.000000000 -0400
69 @@ -374,6 +374,33 @@
70         cmpl $(nr_syscalls), %eax
71         jae syscall_badsys
72  syscall_call:
73 +    /* Move Chopstix syscall probe here */
74 +    /* Save and clobber: eax, ecx, ebp  */
75 +    pushl   %eax
76 +    pushl   %ecx
77 +    pushl   %ebp
78 +    movl    %esp, %ebp
79 +    subl    $SPEC_EVENT_SIZE, %esp 
80 +    movl    rec_event, %ecx
81 +    testl   %ecx, %ecx
82 +    jz  carry_on
83 +    # struct event is first, just below %ebp
84 +    movl    %eax, (SPEC_number-EVENT_SIZE)(%ebp)
85 +    leal    -SPEC_EVENT_SIZE(%ebp), %eax
86 +    movl    %eax, EVENT_event_data(%ebp)
87 +    movl    $6, EVENT_event_type(%ebp)
88 +    movl    rec_event, %edx
89 +    movl    $1, 4(%esp)
90 +    leal    -EVENT_SIZE(%ebp), %eax
91 +    movl    %eax, (%esp)
92 +    call    rec_event_asm 
93 +carry_on: 
94 +    addl $SPEC_EVENT_SIZE, %esp
95 +    popl %ebp
96 +    popl %ecx
97 +    popl %eax
98 +     /* End chopstix */
99 +
100         call *sys_call_table(,%eax,4)
101         movl %eax,PT_EAX(%esp)          # store the return value
102  syscall_exit:
103 --- linux-2.6.22-590/arch/i386/mm/fault.c       2009-03-16 20:49:42.000000000 -0400
104 +++ linux-2.6.22-591/arch/i386/mm/fault.c       2009-03-16 20:58:59.000000000 -0400
105 @@ -60,6 +60,15 @@
106                                           DIE_PAGE_FAULT, &args);
107  }
108  
109 +
110 +extern void (*rec_event)(void *,unsigned int);
111 +struct event_spec {
112 +       unsigned long pc;
113 +       unsigned long dcookie; 
114 +       unsigned count;
115 +       unsigned char reason;
116 +};
117 +
118  /*
119   * Return EIP plus the CS segment base.  The segment limit is also
120   * adjusted, clamped to the kernel/user address space (whichever is
121 @@ -296,6 +305,8 @@
122   *     bit 3 == 1 means use of reserved bit detected
123   *     bit 4 == 1 means fault was an instruction fetch
124   */
125 +
126 +
127  fastcall void __kprobes do_page_fault(struct pt_regs *regs,
128                                       unsigned long error_code)
129  {
130 --- linux-2.6.22-590/block/ll_rw_blk.c  2009-03-16 20:49:07.000000000 -0400
131 +++ linux-2.6.22-591/block/ll_rw_blk.c  2009-03-16 20:58:59.000000000 -0400
132 @@ -30,6 +30,7 @@
133  #include <linux/cpu.h>
134  #include <linux/blktrace_api.h>
135  #include <linux/fault-inject.h>
136 +#include <linux/arrays.h>
137  
138  /*
139   * for max sense size
140 @@ -3102,6 +3103,13 @@
141  
142  #endif /* CONFIG_FAIL_MAKE_REQUEST */
143  
144 +extern void (*rec_event)(void *,unsigned int);
145 +struct event_spec {
146 +       unsigned long pc;
147 +       unsigned long dcookie;
148 +       unsigned count;
149 +       unsigned char reason;
150 +};
151  /**
152   * generic_make_request: hand a buffer to its device driver for I/O
153   * @bio:  The bio describing the location in memory and on the device.
154 @@ -3220,7 +3228,23 @@
155                                 goto end_io;
156                         }
157                 }
158 -
159 +#ifdef CONFIG_CHOPSTIX
160 +               if (rec_event) {
161 +                       struct event event;
162 +                       struct event_spec espec;
163 +                       unsigned long eip;
164 +                       
165 +                       espec.reason = 0;/*request */
166 +
167 +                       eip = bio->bi_end_io;
168 +                       event.event_data=&espec;
169 +                       espec.pc=eip;
170 +                       event.event_type=3; 
171 +                       /* index in the event array currently set up */
172 +                       /* make sure the counters are loaded in the order we want them to show up*/ 
173 +                       (*rec_event)(&event, bio->bi_size);
174 +               }
175 +#endif
176                 ret = q->make_request_fn(q, bio);
177         } while (ret);
178  }
179 --- linux-2.6.22-590/drivers/oprofile/cpu_buffer.c      2007-07-08 19:32:17.000000000 -0400
180 +++ linux-2.6.22-591/drivers/oprofile/cpu_buffer.c      2009-03-16 20:58:59.000000000 -0400
181 @@ -21,6 +21,7 @@
182  #include <linux/oprofile.h>
183  #include <linux/vmalloc.h>
184  #include <linux/errno.h>
185 +#include <linux/arrays.h>
186   
187  #include "event_buffer.h"
188  #include "cpu_buffer.h"
189 @@ -143,6 +144,17 @@
190                 b->head_pos = 0;
191  }
192  
193 +#ifdef CONFIG_CHOPSTIX
194 +
195 +struct event_spec {
196 +       unsigned int pc;
197 +       unsigned long dcookie;
198 +       unsigned count;
199 +};
200 +
201 +extern void (*rec_event)(void *,unsigned int);
202 +#endif
203 +
204  static inline void
205  add_sample(struct oprofile_cpu_buffer * cpu_buf,
206             unsigned long pc, unsigned long event)
207 @@ -151,6 +163,7 @@
208         entry->eip = pc;
209         entry->event = event;
210         increment_head(cpu_buf);
211 +
212  }
213  
214  static inline void
215 @@ -241,8 +254,28 @@
216  {
217         int is_kernel = !user_mode(regs);
218         unsigned long pc = profile_pc(regs);
219 +       int res=0;
220  
221 +#ifdef CONFIG_CHOPSTIX
222 +       if (rec_event) {
223 +               struct event esig;
224 +               struct event_spec espec;
225 +               esig.task = current;
226 +               espec.pc=pc;
227 +               espec.count=1;
228 +               esig.event_data=&espec;
229 +               esig.event_type=event; /* index in the event array currently set up */
230 +                                       /* make sure the counters are loaded in the order we want them to show up*/ 
231 +               (*rec_event)(&esig, 1);
232 +       }
233 +       else {
234         oprofile_add_ext_sample(pc, regs, event, is_kernel);
235 +       }
236 +#else
237 +       oprofile_add_ext_sample(pc, regs, event, is_kernel);
238 +#endif
239 +
240 +
241  }
242  
243  void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event)
244 --- linux-2.6.22-590/fs/bio.c   2007-07-08 19:32:17.000000000 -0400
245 +++ linux-2.6.22-591/fs/bio.c   2009-03-16 20:58:59.000000000 -0400
246 @@ -27,6 +27,7 @@
247  #include <linux/workqueue.h>
248  #include <linux/blktrace_api.h>
249  #include <scsi/sg.h>           /* for struct sg_iovec */
250 +#include <linux/arrays.h>
251  
252  #define BIO_POOL_SIZE 2
253  
254 @@ -47,6 +48,7 @@
255         struct kmem_cache *slab;
256  };
257  
258 +
259  /*
260   * if you change this list, also change bvec_alloc or things will
261   * break badly! cannot be bigger than what you can fit into an
262 @@ -999,6 +1001,14 @@
263         }
264  }
265  
266 +struct event_spec {
267 +       unsigned long pc;
268 +       unsigned long dcookie;
269 +       unsigned count;
270 +       unsigned char reason;
271 +};
272 +
273 +extern void (*rec_event)(void *,unsigned int);
274  /**
275   * bio_endio - end I/O on a bio
276   * @bio:       bio
277 @@ -1028,6 +1038,24 @@
278         bio->bi_size -= bytes_done;
279         bio->bi_sector += (bytes_done >> 9);
280  
281 +#ifdef CONFIG_CHOPSTIX
282 +               if (rec_event) {
283 +                       struct event event;
284 +                       struct event_spec espec;
285 +                       unsigned long eip;
286 +                       
287 +                       espec.reason = 1;/*response */
288 +
289 +                       eip = bio->bi_end_io;
290 +                       event.event_data=&espec;
291 +                       espec.pc=eip;
292 +                       event.event_type=3; 
293 +                       /* index in the event array currently set up */
294 +                       /* make sure the counters are loaded in the order we want them to show up*/ 
295 +                       (*rec_event)(&event, bytes_done);
296 +               }
297 +#endif
298 +
299         if (bio->bi_end_io)
300                 bio->bi_end_io(bio, bytes_done, error);
301  }
302 --- linux-2.6.22-590/fs/exec.c  2009-03-16 20:49:42.000000000 -0400
303 +++ linux-2.6.22-591/fs/exec.c  2009-03-16 20:58:59.000000000 -0400
304 @@ -27,6 +27,7 @@
305  #include <linux/mman.h>
306  #include <linux/a.out.h>
307  #include <linux/stat.h>
308 +#include <linux/dcookies.h>
309  #include <linux/fcntl.h>
310  #include <linux/smp_lock.h>
311  #include <linux/init.h>
312 @@ -38,7 +39,7 @@
313  #include <linux/binfmts.h>
314  #include <linux/swap.h>
315  #include <linux/utsname.h>
316 -#include <linux/pid_namespace.h>
317 +/*#include <linux/pid_namespace.h>*/
318  #include <linux/module.h>
319  #include <linux/namei.h>
320  #include <linux/proc_fs.h>
321 @@ -488,6 +489,12 @@
322  
323         if (!err) {
324                 struct inode *inode = nd.dentry->d_inode;
325 +#ifdef CONFIG_CHOPSTIX
326 +               unsigned long cookie;
327 +               if (!nd.dentry->d_cookie)
328 +                       get_dcookie(nd.dentry, nd.mnt, &cookie);
329 +#endif
330 +
331                 file = ERR_PTR(-EACCES);
332                 if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&
333                     S_ISREG(inode->i_mode)) {
334 @@ -627,8 +634,10 @@
335          * Reparenting needs write_lock on tasklist_lock,
336          * so it is safe to do it under read_lock.
337          */
338 +       /*
339         if (unlikely(tsk->group_leader == child_reaper(tsk)))
340                 tsk->nsproxy->pid_ns->child_reaper = tsk;
341 +               */
342  
343         zap_other_threads(tsk);
344         read_unlock(&tasklist_lock);
345 --- linux-2.6.22-590/include/linux/arrays.h     1969-12-31 19:00:00.000000000 -0500
346 +++ linux-2.6.22-591/include/linux/arrays.h     2009-03-16 20:58:59.000000000 -0400
347 @@ -0,0 +1,36 @@
348 +#ifndef __ARRAYS_H__
349 +#define __ARRAYS_H__
350 +#include <linux/list.h>
351 +
352 +#define SAMPLING_METHOD_DEFAULT 0
353 +#define SAMPLING_METHOD_LOG 1
354 +
355 +/* Every probe has an array handler */
356 +
357 +/* XXX - Optimize this structure */
358 +
359 +extern void (*rec_event)(void *,unsigned int);
360 +struct array_handler {
361 +       struct list_head link;
362 +       unsigned int (*hash_func)(void *);
363 +       unsigned int (*sampling_func)(void *,int,void *);
364 +       unsigned short size;
365 +       unsigned int threshold;
366 +       unsigned char **expcount;
367 +       unsigned int sampling_method;
368 +       unsigned int **arrays;
369 +       unsigned int arraysize;
370 +       unsigned int num_samples[2];
371 +       void **epoch_samples; /* size-sized lists of samples */
372 +       unsigned int (*serialize)(void *, void *);
373 +       unsigned char code[5];
374 +};
375 +
376 +struct event {
377 +       struct list_head link;
378 +       void *event_data;
379 +       unsigned int count;
380 +       unsigned int event_type;
381 +       struct task_struct *task;
382 +};
383 +#endif
384 --- linux-2.6.22-590/include/linux/mutex.h      2007-07-08 19:32:17.000000000 -0400
385 +++ linux-2.6.22-591/include/linux/mutex.h      2009-03-16 20:58:59.000000000 -0400
386 @@ -53,6 +53,10 @@
387         struct thread_info      *owner;
388         const char              *name;
389         void                    *magic;
390 +#else
391 +#ifdef CONFIG_CHOPSTIX
392 +       struct thread_info      *owner;
393 +#endif
394  #endif
395  #ifdef CONFIG_DEBUG_LOCK_ALLOC
396         struct lockdep_map      dep_map;
397 --- linux-2.6.22-590/include/linux/sched.h      2009-03-16 20:49:42.000000000 -0400
398 +++ linux-2.6.22-591/include/linux/sched.h      2009-03-16 20:58:59.000000000 -0400
399 @@ -850,6 +850,10 @@
400  #endif
401         unsigned long sleep_avg;
402         unsigned long long timestamp, last_ran;
403 +#ifdef CONFIG_CHOPSTIX
404 +       unsigned long last_interrupted, last_ran_j;
405 +#endif
406 +
407         unsigned long long sched_time; /* sched_clock time spent running */
408         enum sleep_type sleep_type;
409  
410 --- linux-2.6.22-590/kernel/mutex.c     2007-07-08 19:32:17.000000000 -0400
411 +++ linux-2.6.22-591/kernel/mutex.c     2009-03-16 20:58:59.000000000 -0400
412 @@ -18,6 +18,17 @@
413  #include <linux/spinlock.h>
414  #include <linux/interrupt.h>
415  #include <linux/debug_locks.h>
416 +#include <linux/arrays.h>
417 +
418 +#undef CONFIG_CHOPSTIX
419 +#ifdef CONFIG_CHOPSTIX
420 +struct event_spec {
421 +       unsigned long pc;
422 +       unsigned long dcookie;
423 +       unsigned count;
424 +       unsigned char reason;
425 +};
426 +#endif
427  
428  /*
429   * In the DEBUG case we are using the "NULL fastpath" for mutexes,
430 @@ -43,6 +54,9 @@
431  __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key)
432  {
433         atomic_set(&lock->count, 1);
434 +#ifdef CONFIG_CHOPSTIX
435 +       lock->owner=NULL;
436 +#endif
437         spin_lock_init(&lock->wait_lock);
438         INIT_LIST_HEAD(&lock->wait_list);
439  
440 @@ -88,6 +102,7 @@
441          * The locking fastpath is the 1->0 transition from
442          * 'unlocked' into 'locked' state.
443          */
444 +
445         __mutex_fastpath_lock(&lock->count, __mutex_lock_slowpath);
446  }
447  
448 @@ -168,6 +183,27 @@
449                 }
450                 __set_task_state(task, state);
451  
452 +#ifdef CONFIG_CHOPSTIX
453 +               if (rec_event) {
454 +                       if (lock->owner) {
455 +                               struct event event;
456 +                               struct event_spec espec;
457 +                               struct task_struct *p = lock->owner->task;
458 +                               /*spin_lock(&p->alloc_lock);*/
459 +                               espec.reason = 0; /* lock */
460 +                               event.event_data=&espec;
461 +                               event.task = p;
462 +                               espec.pc=lock;
463 +                               event.event_type=5; 
464 +                               (*rec_event)(&event, 1);
465 +                               /*spin_unlock(&p->alloc_lock);*/
466 +
467 +                       }
468 +                       else 
469 +                               BUG();
470 +               }
471 +#endif
472 +
473                 /* didnt get the lock, go to sleep: */
474                 spin_unlock_mutex(&lock->wait_lock, flags);
475                 schedule();
476 @@ -177,6 +213,9 @@
477         /* got the lock - rejoice! */
478         mutex_remove_waiter(lock, &waiter, task_thread_info(task));
479         debug_mutex_set_owner(lock, task_thread_info(task));
480 +#ifdef CONFIG_CHOPSTIX
481 +       lock->owner = task_thread_info(task);
482 +#endif
483  
484         /* set it to 0 if there are no waiters left: */
485         if (likely(list_empty(&lock->wait_list)))
486 @@ -202,6 +241,7 @@
487  mutex_lock_nested(struct mutex *lock, unsigned int subclass)
488  {
489         might_sleep();
490 +
491         __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, subclass);
492  }
493  
494 @@ -211,6 +251,7 @@
495  mutex_lock_interruptible_nested(struct mutex *lock, unsigned int subclass)
496  {
497         might_sleep();
498 +
499         return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, subclass);
500  }
501  
502 @@ -246,6 +287,23 @@
503  
504                 debug_mutex_wake_waiter(lock, waiter);
505  
506 +#ifdef CONFIG_CHOPSTIX
507 +               if (rec_event) {
508 +                       if (lock->owner) {
509 +                               struct event event;
510 +                               struct event_spec espec;
511 +
512 +                               espec.reason = 1; /* unlock */
513 +                               event.event_data=&espec;
514 +                               event.task = lock->owner->task;
515 +                               espec.pc=lock;
516 +                               event.event_type=5; 
517 +                               (*rec_event)(&event, 1);
518 +                       }
519 +                       else 
520 +                               BUG();
521 +               }
522 +#endif
523                 wake_up_process(waiter->task);
524         }
525  
526 --- linux-2.6.22-590/kernel/sched.c     2009-03-16 20:49:42.000000000 -0400
527 +++ linux-2.6.22-591/kernel/sched.c     2009-03-16 20:58:59.000000000 -0400
528 @@ -10,7 +10,7 @@
529   *  1998-11-19 Implemented schedule_timeout() and related stuff
530   *             by Andrea Arcangeli
531   *  2002-01-04 New ultra-scalable O(1) scheduler by Ingo Molnar:
532 - *             hybrid priority-list and round-robin design with
533 + *             hybrid priority-list and round-robin deventn with
534   *             an array-switch method of distributing timeslices
535   *             and per-CPU runqueues.  Cleanups and useful suggestions
536   *             by Davide Libenzi, preemptible kernel bits by Robert Love.
537 @@ -23,6 +23,7 @@
538  #include <linux/nmi.h>
539  #include <linux/init.h>
540  #include <asm/uaccess.h>
541 +#include <linux/arrays.h>
542  #include <linux/highmem.h>
543  #include <linux/smp_lock.h>
544  #include <asm/mmu_context.h>
545 @@ -59,6 +60,9 @@
546  #include <linux/vs_sched.h>
547  #include <linux/vs_cvirt.h>
548  
549 +#define INTERRUPTIBLE   -1
550 +#define RUNNING         0
551 +
552  /*
553   * Scheduler clock - returns current time in nanosec units.
554   * This is default implementation.
555 @@ -431,6 +435,7 @@
556  
557  repeat_lock_task:
558         rq = task_rq(p);
559 +
560         spin_lock(&rq->lock);
561         if (unlikely(rq != task_rq(p))) {
562                 spin_unlock(&rq->lock);
563 @@ -1741,6 +1746,21 @@
564          * event cannot wake it up and insert it on the runqueue either.
565          */
566         p->state = TASK_RUNNING;
567 +#ifdef CONFIG_CHOPSTIX
568 +    /* The jiffy of last interruption */
569 +    if (p->state & TASK_UNINTERRUPTIBLE) {
570 +                               p->last_interrupted=jiffies;
571 +       }
572 +    else
573 +    if (p->state & TASK_INTERRUPTIBLE) {
574 +                               p->last_interrupted=INTERRUPTIBLE;
575 +       }
576 +    else
577 +           p->last_interrupted=RUNNING;
578 +
579 +    /* The jiffy of last execution */ 
580 +       p->last_ran_j=jiffies;
581 +#endif
582  
583         /*
584          * Make sure we do not leak PI boosting priority to the child:
585 @@ -3608,6 +3628,7 @@
586  
587  #endif
588  
589 +
590  static inline int interactive_sleep(enum sleep_type sleep_type)
591  {
592         return (sleep_type == SLEEP_INTERACTIVE ||
593 @@ -3617,16 +3638,28 @@
594  /*
595   * schedule() is the main scheduler function.
596   */
597 +
598 +#ifdef CONFIG_CHOPSTIX
599 +extern void (*rec_event)(void *,unsigned int);
600 +struct event_spec {
601 +       unsigned long pc;
602 +       unsigned long dcookie;
603 +       unsigned int count;
604 +       unsigned int reason;
605 +};
606 +#endif
607 +
608  asmlinkage void __sched schedule(void)
609  {
610         struct task_struct *prev, *next;
611         struct prio_array *array;
612         struct list_head *queue;
613         unsigned long long now;
614 -       unsigned long run_time;
615 +       unsigned long run_time, diff;
616         int cpu, idx, new_prio;
617         long *switch_count;
618         struct rq *rq;
619 +       int sampling_reason;
620  
621         /*
622          * Test if we are atomic.  Since do_exit() needs to call into
623 @@ -3680,6 +3713,7 @@
624         switch_count = &prev->nivcsw;
625         if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
626                 switch_count = &prev->nvcsw;
627 +
628                 if (unlikely((prev->state & TASK_INTERRUPTIBLE) &&
629                                 unlikely(signal_pending(prev))))
630                         prev->state = TASK_RUNNING;
631 @@ -3689,6 +3723,17 @@
632                                 vx_uninterruptible_inc(prev);
633                         }
634                         deactivate_task(prev, rq);
635 +#ifdef CONFIG_CHOPSTIX
636 +            /* An uninterruptible process just yielded. Record the current jiffie */
637 +                       if (prev->state & TASK_UNINTERRUPTIBLE) {
638 +                               prev->last_interrupted=jiffies;
639 +                       }
640 +            /* An interruptible process just yielded, or it got preempted. 
641 +             * Mark it as interruptible */
642 +                       else if (prev->state & TASK_INTERRUPTIBLE) {
643 +                               prev->last_interrupted=INTERRUPTIBLE;
644 +                       }
645 +#endif
646                 }
647         }
648  
649 @@ -3765,6 +3810,40 @@
650                 prev->sleep_avg = 0;
651         prev->timestamp = prev->last_ran = now;
652  
653 +#ifdef CONFIG_CHOPSTIX
654 +       /* Run only if the Chopstix module so decrees it */
655 +       if (rec_event) {
656 +               prev->last_ran_j = jiffies;
657 +               if (next->last_interrupted!=INTERRUPTIBLE) {
658 +                       if (next->last_interrupted!=RUNNING) {
659 +                               diff = (jiffies-next->last_interrupted);
660 +                               sampling_reason = 0;/* BLOCKING */
661 +                       }
662 +                       else {
663 +                               diff = jiffies-next->last_ran_j; 
664 +                               sampling_reason = 1;/* PREEMPTION */
665 +                       }
666 +
667 +                       if (diff >= HZ/10) {
668 +                               struct event event;
669 +                               struct event_spec espec;
670 +                struct pt_regs *regs;
671 +                regs = task_pt_regs(current);
672 +
673 +                               espec.reason = sampling_reason;
674 +                               event.event_data=&espec;
675 +                               event.task=next;
676 +                               espec.pc=regs->eip;
677 +                               event.event_type=2; 
678 +                               /* index in the event array currently set up */
679 +                               /* make sure the counters are loaded in the order we want them to show up*/ 
680 +                               (*rec_event)(&event, diff);
681 +                       }
682 +               }
683 +        /* next has been elected to run */
684 +               next->last_interrupted=0;
685 +       }
686 +#endif
687         sched_info_switch(prev, next);
688         if (likely(prev != next)) {
689                 next->timestamp = next->last_ran = now;
690 @@ -4664,6 +4743,7 @@
691         get_task_struct(p);
692         read_unlock(&tasklist_lock);
693  
694 +
695         retval = -EPERM;
696         if ((current->euid != p->euid) && (current->euid != p->uid) &&
697                         !capable(CAP_SYS_NICE))
698 @@ -5032,6 +5112,7 @@
699         jiffies_to_timespec(p->policy == SCHED_FIFO ?
700                                 0 : task_timeslice(p), &t);
701         read_unlock(&tasklist_lock);
702 +
703         retval = copy_to_user(interval, &t, sizeof(t)) ? -EFAULT : 0;
704  out_nounlock:
705         return retval;
706 @@ -7275,3 +7356,20 @@
707  }
708  
709  #endif
710 +
711 +#ifdef CONFIG_CHOPSTIX
712 +void (*rec_event)(void *,unsigned int) = NULL;
713 +
714 +/* To support safe calling from asm */
715 +asmlinkage void rec_event_asm (struct event *event_signature_in, unsigned int count) {
716 +    struct pt_regs *regs;
717 +    struct event_spec *es = event_signature_in->event_data;
718 +    regs = task_pt_regs(current);
719 +       event_signature_in->task=current;
720 +       es->pc=regs->eip;
721 +    event_signature_in->count=1;
722 +    (*rec_event)(event_signature_in, count);
723 +}
724 +EXPORT_SYMBOL(rec_event);
725 +EXPORT_SYMBOL(in_sched_functions);
726 +#endif
727 --- linux-2.6.22-590/mm/memory.c        2009-03-16 20:49:42.000000000 -0400
728 +++ linux-2.6.22-591/mm/memory.c        2009-03-16 20:58:59.000000000 -0400
729 @@ -59,6 +59,7 @@
730  
731  #include <linux/swapops.h>
732  #include <linux/elf.h>
733 +#include <linux/arrays.h>
734  
735  #ifndef CONFIG_NEED_MULTIPLE_NODES
736  /* use the per-pgdat data instead for discontigmem - mbligh */
737 @@ -2601,6 +2602,15 @@
738         return ret;
739  }
740  
741 +extern void (*rec_event)(void *,unsigned int);
742 +struct event_spec {
743 +       unsigned long pc;
744 +       unsigned long dcookie; 
745 +       unsigned count;
746 +       unsigned char reason;
747 +};
748 +
749 +
750  /*
751   * By the time we get here, we already hold the mm semaphore
752   */
753 @@ -2630,6 +2640,24 @@
754         if (!pte)
755                 return VM_FAULT_OOM;
756  
757 +#ifdef CONFIG_CHOPSTIX
758 +       if (rec_event) {
759 +               struct event event;
760 +               struct event_spec espec;
761 +        struct pt_regs *regs;
762 +        unsigned int pc;
763 +        regs = task_pt_regs(current);
764 +        pc = regs->eip & (unsigned int) ~4095;
765 +
766 +               espec.reason = 0; /* alloc */
767 +               event.event_data=&espec;
768 +               event.task = current;
769 +               espec.pc=pc;
770 +               event.event_type=5; 
771 +               (*rec_event)(&event, 1);
772 +       }
773 +#endif
774 +
775         return handle_pte_fault(mm, vma, address, pte, pmd, write_access);
776  }
777  
778 --- linux-2.6.22-590/mm/slab.c  2009-03-16 20:49:42.000000000 -0400
779 +++ linux-2.6.22-591/mm/slab.c  2009-03-16 21:00:27.000000000 -0400
780 @@ -110,11 +110,13 @@
781  #include       <linux/fault-inject.h>
782  #include       <linux/rtmutex.h>
783  #include       <linux/reciprocal_div.h>
784 +#include <linux/arrays.h>
785  
786  #include       <asm/cacheflush.h>
787  #include       <asm/tlbflush.h>
788  #include       <asm/page.h>
789  
790 +
791  /*
792   * DEBUG       - 1 for kmem_cache_create() to honour; SLAB_RED_ZONE & SLAB_POISON.
793   *               0 for faster, smaller code (especially in the critical paths).
794 @@ -249,6 +251,14 @@
795         void *addr;
796  };
797  
798 +extern void (*rec_event)(void *,unsigned int);
799 +struct event_spec {
800 +       unsigned long pc;
801 +       unsigned long dcookie; 
802 +       unsigned count;
803 +       unsigned char reason;
804 +};
805 +
806  /*
807   * struct array_cache
808   *
809 @@ -3443,6 +3453,19 @@
810         local_irq_restore(save_flags);
811         objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller);
812         prefetchw(objp);
813 +#ifdef CONFIG_CHOPSTIX
814 +       if (rec_event && objp) {
815 +               struct event event;
816 +               struct event_spec espec;
817 +
818 +               espec.reason = 0; /* alloc */
819 +               event.event_data=&espec;
820 +               event.task = current;
821 +               espec.pc=caller;
822 +               event.event_type=5; 
823 +               (*rec_event)(&event, cachep->buffer_size);
824 +       }
825 +#endif
826  
827         return objp;
828  }
829 @@ -3549,12 +3572,26 @@
830   * Release an obj back to its cache. If the obj has a constructed state, it must
831   * be in this state _before_ it is released.  Called with disabled ints.
832   */
833 -static inline void __cache_free(struct kmem_cache *cachep, void *objp)
834 +static inline void __cache_free(struct kmem_cache *cachep, void *objp, void *caller)
835  {
836         struct array_cache *ac = cpu_cache_get(cachep);
837  
838         check_irq_off();
839 -       objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
840 +       objp = cache_free_debugcheck(cachep, objp, caller);
841 + #ifdef CONFIG_CHOPSTIX
842 +       if (rec_event && objp) {
843 +               struct event event;
844 +               struct event_spec espec;
845 +  
846 +               espec.reason = 1; /* free */
847 +               event.event_data=&espec;
848 +               event.task = current;
849 +               espec.pc=caller;
850 +               event.event_type=4; 
851 +               (*rec_event)(&event, cachep->buffer_size);
852 +       }
853 + #endif
854 +
855         vx_slab_free(cachep);
856  
857         if (cache_free_alien(cachep, objp))
858 @@ -3651,16 +3688,19 @@
859                         __builtin_return_address(0));
860  }
861  EXPORT_SYMBOL(kmem_cache_alloc_node);
862 -
863  static __always_inline void *
864  __do_kmalloc_node(size_t size, gfp_t flags, int node, void *caller)
865  {
866         struct kmem_cache *cachep;
867 +       void *ret;
868 +
869  
870         cachep = kmem_find_general_cachep(size, flags);
871         if (unlikely(cachep == NULL))
872                 return NULL;
873 -       return kmem_cache_alloc_node(cachep, flags, node);
874 +       ret = kmem_cache_alloc_node(cachep, flags, node);
875 +       
876 +       return ret;
877  }
878  
879  #ifdef CONFIG_DEBUG_SLAB
880 @@ -3696,6 +3736,7 @@
881                                           void *caller)
882  {
883         struct kmem_cache *cachep;
884 +       void *ret;
885  
886         /* If you want to save a few bytes .text space: replace
887          * __ with kmem_.
888 @@ -3705,9 +3746,10 @@
889         cachep = __find_general_cachep(size, flags);
890         if (unlikely(cachep == NULL))
891                 return NULL;
892 -       return __cache_alloc(cachep, flags, caller);
893 -}
894 +       ret = __cache_alloc(cachep, flags, caller);
895  
896 +       return ret;
897 +}
898  
899  #ifdef CONFIG_DEBUG_SLAB
900  void *__kmalloc(size_t size, gfp_t flags)
901 @@ -3723,10 +3765,17 @@
902  EXPORT_SYMBOL(__kmalloc_track_caller);
903  
904  #else
905 +#ifdef CONFIG_CHOPSTIX
906 +void *__kmalloc(size_t size, gfp_t flags)
907 +{
908 +       return __do_kmalloc(size, flags, __builtin_return_address(0));
909 +}
910 +#else
911  void *__kmalloc(size_t size, gfp_t flags)
912  {
913         return __do_kmalloc(size, flags, NULL);
914  }
915 +#endif
916  EXPORT_SYMBOL(__kmalloc);
917  #endif
918  
919 @@ -3792,7 +3841,7 @@
920  
921         local_irq_save(flags);
922         debug_check_no_locks_freed(objp, obj_size(cachep));
923 -       __cache_free(cachep, objp);
924 +       __cache_free(cachep, objp,__builtin_return_address(0));
925         local_irq_restore(flags);
926  }
927  EXPORT_SYMBOL(kmem_cache_free);
928 @@ -3817,7 +3866,7 @@
929         kfree_debugcheck(objp);
930         c = virt_to_cache(objp);
931         debug_check_no_locks_freed(objp, obj_size(c));
932 -       __cache_free(c, (void *)objp);
933 +       __cache_free(c, (void *)objp,__builtin_return_address(0));
934         local_irq_restore(flags);
935  }
936  EXPORT_SYMBOL(kfree);
937