Cleanup, and integrated some new stuff I had in testing.
[linux-2.6.git] / linux-2.6-590-chopstix-intern.patch
1 diff -Nurb linux-2.6.22-580/arch/i386/Kconfig linux-2.6.22-590/arch/i386/Kconfig
2 --- linux-2.6.22-580/arch/i386/Kconfig  2008-04-29 17:04:54.000000000 -0400
3 +++ linux-2.6.22-590/arch/i386/Kconfig  2008-04-29 17:05:11.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 diff -Nurb linux-2.6.22-580/block/ll_rw_blk.c linux-2.6.22-590/block/ll_rw_blk.c
20 --- linux-2.6.22-580/block/ll_rw_blk.c  2008-04-29 17:04:51.000000000 -0400
21 +++ linux-2.6.22-590/block/ll_rw_blk.c  2008-04-29 17:05:11.000000000 -0400
22 @@ -30,6 +30,7 @@
23  #include <linux/cpu.h>
24  #include <linux/blktrace_api.h>
25  #include <linux/fault-inject.h>
26 +#include <linux/arrays.h>
27  
28  /*
29   * for max sense size
30 @@ -3102,6 +3103,13 @@
31  
32  #endif /* CONFIG_FAIL_MAKE_REQUEST */
33  
34 +extern void (*rec_event)(void *,unsigned int);
35 +struct event_spec {
36 +       unsigned long pc;
37 +       unsigned long dcookie;
38 +       unsigned count;
39 +       unsigned char reason;
40 +};
41  /**
42   * generic_make_request: hand a buffer to its device driver for I/O
43   * @bio:  The bio describing the location in memory and on the device.
44 @@ -3220,7 +3228,23 @@
45                                 goto end_io;
46                         }
47                 }
48 -
49 +#ifdef CONFIG_CHOPSTIX
50 +               if (rec_event) {
51 +                       struct event event;
52 +                       struct event_spec espec;
53 +                       unsigned long eip;
54 +                       
55 +                       espec.reason = 0;/*request */
56 +
57 +                       eip = bio->bi_end_io;
58 +                       event.event_data=&espec;
59 +                       espec.pc=eip;
60 +                       event.event_type=3; 
61 +                       /* index in the event array currently set up */
62 +                       /* make sure the counters are loaded in the order we want them to show up*/ 
63 +                       (*rec_event)(&event, bio->bi_size);
64 +               }
65 +#endif
66                 ret = q->make_request_fn(q, bio);
67         } while (ret);
68  }
69 diff -Nurb linux-2.6.22-580/drivers/oprofile/cpu_buffer.c linux-2.6.22-590/drivers/oprofile/cpu_buffer.c
70 --- linux-2.6.22-580/drivers/oprofile/cpu_buffer.c      2007-07-08 19:32:17.000000000 -0400
71 +++ linux-2.6.22-590/drivers/oprofile/cpu_buffer.c      2008-04-29 17:05:11.000000000 -0400
72 @@ -21,6 +21,7 @@
73  #include <linux/oprofile.h>
74  #include <linux/vmalloc.h>
75  #include <linux/errno.h>
76 +#include <linux/arrays.h>
77   
78  #include "event_buffer.h"
79  #include "cpu_buffer.h"
80 @@ -143,6 +144,17 @@
81                 b->head_pos = 0;
82  }
83  
84 +#ifdef CONFIG_CHOPSTIX
85 +
86 +struct event_spec {
87 +       unsigned int pc;
88 +       unsigned long dcookie;
89 +       unsigned count;
90 +};
91 +
92 +extern void (*rec_event)(void *,unsigned int);
93 +#endif
94 +
95  static inline void
96  add_sample(struct oprofile_cpu_buffer * cpu_buf,
97             unsigned long pc, unsigned long event)
98 @@ -151,6 +163,7 @@
99         entry->eip = pc;
100         entry->event = event;
101         increment_head(cpu_buf);
102 +
103  }
104  
105  static inline void
106 @@ -241,8 +254,28 @@
107  {
108         int is_kernel = !user_mode(regs);
109         unsigned long pc = profile_pc(regs);
110 +       int res=0;
111  
112 +#ifdef CONFIG_CHOPSTIX
113 +       if (rec_event) {
114 +               struct event esig;
115 +               struct event_spec espec;
116 +               esig.task = current;
117 +               espec.pc=pc;
118 +               espec.count=1;
119 +               esig.event_data=&espec;
120 +               esig.event_type=event; /* index in the event array currently set up */
121 +                                       /* make sure the counters are loaded in the order we want them to show up*/ 
122 +               (*rec_event)(&esig, 1);
123 +       }
124 +       else {
125         oprofile_add_ext_sample(pc, regs, event, is_kernel);
126 +       }
127 +#else
128 +       oprofile_add_ext_sample(pc, regs, event, is_kernel);
129 +#endif
130 +
131 +
132  }
133  
134  void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event)
135 diff -Nurb linux-2.6.22-580/fs/bio.c linux-2.6.22-590/fs/bio.c
136 --- linux-2.6.22-580/fs/bio.c   2007-07-08 19:32:17.000000000 -0400
137 +++ linux-2.6.22-590/fs/bio.c   2008-04-29 17:05:11.000000000 -0400
138 @@ -27,6 +27,7 @@
139  #include <linux/workqueue.h>
140  #include <linux/blktrace_api.h>
141  #include <scsi/sg.h>           /* for struct sg_iovec */
142 +#include <linux/arrays.h>
143  
144  #define BIO_POOL_SIZE 2
145  
146 @@ -47,6 +48,7 @@
147         struct kmem_cache *slab;
148  };
149  
150 +
151  /*
152   * if you change this list, also change bvec_alloc or things will
153   * break badly! cannot be bigger than what you can fit into an
154 @@ -999,6 +1001,14 @@
155         }
156  }
157  
158 +struct event_spec {
159 +       unsigned long pc;
160 +       unsigned long dcookie;
161 +       unsigned count;
162 +       unsigned char reason;
163 +};
164 +
165 +extern void (*rec_event)(void *,unsigned int);
166  /**
167   * bio_endio - end I/O on a bio
168   * @bio:       bio
169 @@ -1028,6 +1038,24 @@
170         bio->bi_size -= bytes_done;
171         bio->bi_sector += (bytes_done >> 9);
172  
173 +#ifdef CONFIG_CHOPSTIX
174 +               if (rec_event) {
175 +                       struct event event;
176 +                       struct event_spec espec;
177 +                       unsigned long eip;
178 +                       
179 +                       espec.reason = 1;/*response */
180 +
181 +                       eip = bio->bi_end_io;
182 +                       event.event_data=&espec;
183 +                       espec.pc=eip;
184 +                       event.event_type=3; 
185 +                       /* index in the event array currently set up */
186 +                       /* make sure the counters are loaded in the order we want them to show up*/ 
187 +                       (*rec_event)(&event, bytes_done);
188 +               }
189 +#endif
190 +
191         if (bio->bi_end_io)
192                 bio->bi_end_io(bio, bytes_done, error);
193  }
194 diff -Nurb linux-2.6.22-580/fs/exec.c linux-2.6.22-590/fs/exec.c
195 --- linux-2.6.22-580/fs/exec.c  2008-04-29 17:04:54.000000000 -0400
196 +++ linux-2.6.22-590/fs/exec.c  2008-04-29 17:05:11.000000000 -0400
197 @@ -38,7 +38,7 @@
198  #include <linux/binfmts.h>
199  #include <linux/swap.h>
200  #include <linux/utsname.h>
201 -#include <linux/pid_namespace.h>
202 +/*#include <linux/pid_namespace.h>*/
203  #include <linux/module.h>
204  #include <linux/namei.h>
205  #include <linux/proc_fs.h>
206 @@ -52,6 +52,7 @@
207  #include <linux/audit.h>
208  #include <linux/signalfd.h>
209  #include <linux/vs_memory.h>
210 +#include <linux/dcookies.h>
211  
212  #include <asm/uaccess.h>
213  #include <asm/mmu_context.h>
214 @@ -488,6 +489,12 @@
215  
216         if (!err) {
217                 struct inode *inode = nd.dentry->d_inode;
218 +#ifdef CONFIG_CHOPSTIX
219 +               unsigned long cookie;
220 +               if (!nd.dentry->d_cookie)
221 +                       get_dcookie(nd.dentry, nd.mnt, &cookie);
222 +#endif
223 +
224                 file = ERR_PTR(-EACCES);
225                 if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&
226                     S_ISREG(inode->i_mode)) {
227 @@ -627,8 +634,10 @@
228          * Reparenting needs write_lock on tasklist_lock,
229          * so it is safe to do it under read_lock.
230          */
231 +       /*
232         if (unlikely(tsk->group_leader == child_reaper(tsk)))
233                 tsk->nsproxy->pid_ns->child_reaper = tsk;
234 +               */
235  
236         zap_other_threads(tsk);
237         read_unlock(&tasklist_lock);
238 diff -Nurb linux-2.6.22-580/include/linux/arrays.h linux-2.6.22-590/include/linux/arrays.h
239 --- linux-2.6.22-580/include/linux/arrays.h     1969-12-31 19:00:00.000000000 -0500
240 +++ linux-2.6.22-590/include/linux/arrays.h     2008-04-29 17:05:11.000000000 -0400
241 @@ -0,0 +1,36 @@
242 +#ifndef __ARRAYS_H__
243 +#define __ARRAYS_H__
244 +#include <linux/list.h>
245 +
246 +#define SAMPLING_METHOD_DEFAULT 0
247 +#define SAMPLING_METHOD_LOG 1
248 +
249 +/* Every probe has an array handler */
250 +
251 +/* XXX - Optimize this structure */
252 +
253 +extern void (*rec_event)(void *,unsigned int);
254 +struct array_handler {
255 +       struct list_head link;
256 +       unsigned int (*hash_func)(void *);
257 +       unsigned int (*sampling_func)(void *,int,void *);
258 +       unsigned short size;
259 +       unsigned int threshold;
260 +       unsigned char **expcount;
261 +       unsigned int sampling_method;
262 +       unsigned int **arrays;
263 +       unsigned int arraysize;
264 +       unsigned int num_samples[2];
265 +       void **epoch_samples; /* size-sized lists of samples */
266 +       unsigned int (*serialize)(void *, void *);
267 +       unsigned char code[5];
268 +};
269 +
270 +struct event {
271 +       struct list_head link;
272 +       void *event_data;
273 +       unsigned int count;
274 +       unsigned int event_type;
275 +       struct task_struct *task;
276 +};
277 +#endif
278 diff -Nurb linux-2.6.22-580/include/linux/sched.h linux-2.6.22-590/include/linux/sched.h
279 --- linux-2.6.22-580/include/linux/sched.h      2008-04-29 17:04:54.000000000 -0400
280 +++ linux-2.6.22-590/include/linux/sched.h      2008-04-29 17:05:11.000000000 -0400
281 @@ -850,6 +850,10 @@
282  #endif
283         unsigned long sleep_avg;
284         unsigned long long timestamp, last_ran;
285 +#ifdef CONFIG_CHOPSTIX
286 +       unsigned long last_interrupted, last_ran_j;
287 +#endif
288 +
289         unsigned long long sched_time; /* sched_clock time spent running */
290         enum sleep_type sleep_type;
291  
292 diff -Nurb linux-2.6.22-580/kernel/mutex.c linux-2.6.22-590/kernel/mutex.c
293 --- linux-2.6.22-580/kernel/mutex.c     2007-07-08 19:32:17.000000000 -0400
294 +++ linux-2.6.22-590/kernel/mutex.c     2008-04-29 17:05:11.000000000 -0400
295 @@ -18,6 +18,16 @@
296  #include <linux/spinlock.h>
297  #include <linux/interrupt.h>
298  #include <linux/debug_locks.h>
299 +#include <linux/arrays.h>
300 +
301 +#ifdef CONFIG_CHOPSTIX
302 +struct event_spec {
303 +       unsigned long pc;
304 +       unsigned long dcookie;
305 +       unsigned count;
306 +       unsigned char reason;
307 +};
308 +#endif
309  
310  /*
311   * In the DEBUG case we are using the "NULL fastpath" for mutexes,
312 @@ -43,6 +53,9 @@
313  __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key)
314  {
315         atomic_set(&lock->count, 1);
316 +#ifdef CONFIG_CHOPSTIX
317 +       lock->owner=NULL;
318 +#endif
319         spin_lock_init(&lock->wait_lock);
320         INIT_LIST_HEAD(&lock->wait_list);
321  
322 @@ -88,6 +101,7 @@
323          * The locking fastpath is the 1->0 transition from
324          * 'unlocked' into 'locked' state.
325          */
326 +
327         __mutex_fastpath_lock(&lock->count, __mutex_lock_slowpath);
328  }
329  
330 @@ -168,6 +182,27 @@
331                 }
332                 __set_task_state(task, state);
333  
334 +#ifdef CONFIG_CHOPSTIX
335 +               if (rec_event) {
336 +                       if (lock->owner) {
337 +                               struct event event;
338 +                               struct event_spec espec;
339 +                               struct task_struct *p = lock->owner->task;
340 +                               /*spin_lock(&p->alloc_lock);*/
341 +                               espec.reason = 0; /* lock */
342 +                               event.event_data=&espec;
343 +                               event.task = p;
344 +                               espec.pc=lock;
345 +                               event.event_type=5; 
346 +                               (*rec_event)(&event, 1);
347 +                               /*spin_unlock(&p->alloc_lock);*/
348 +
349 +                       }
350 +                       else 
351 +                               BUG();
352 +               }
353 +#endif
354 +
355                 /* didnt get the lock, go to sleep: */
356                 spin_unlock_mutex(&lock->wait_lock, flags);
357                 schedule();
358 @@ -177,6 +212,9 @@
359         /* got the lock - rejoice! */
360         mutex_remove_waiter(lock, &waiter, task_thread_info(task));
361         debug_mutex_set_owner(lock, task_thread_info(task));
362 +#ifdef CONFIG_CHOPSTIX
363 +       lock->owner = task_thread_info(task);
364 +#endif
365  
366         /* set it to 0 if there are no waiters left: */
367         if (likely(list_empty(&lock->wait_list)))
368 @@ -202,6 +240,7 @@
369  mutex_lock_nested(struct mutex *lock, unsigned int subclass)
370  {
371         might_sleep();
372 +
373         __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, subclass);
374  }
375  
376 @@ -211,6 +250,7 @@
377  mutex_lock_interruptible_nested(struct mutex *lock, unsigned int subclass)
378  {
379         might_sleep();
380 +
381         return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, subclass);
382  }
383  
384 @@ -246,6 +286,23 @@
385  
386                 debug_mutex_wake_waiter(lock, waiter);
387  
388 +#ifdef CONFIG_CHOPSTIX
389 +               if (rec_event) {
390 +                       if (lock->owner) {
391 +                               struct event event;
392 +                               struct event_spec espec;
393 +
394 +                               espec.reason = 1; /* unlock */
395 +                               event.event_data=&espec;
396 +                               event.task = lock->owner->task;
397 +                               espec.pc=lock;
398 +                               event.event_type=5; 
399 +                               (*rec_event)(&event, 1);
400 +                       }
401 +                       else 
402 +                               BUG();
403 +               }
404 +#endif
405                 wake_up_process(waiter->task);
406         }
407  
408 diff -Nurb linux-2.6.22-580/kernel/sched.c linux-2.6.22-590/kernel/sched.c
409 --- linux-2.6.22-580/kernel/sched.c     2008-04-29 17:04:54.000000000 -0400
410 +++ linux-2.6.22-590/kernel/sched.c     2008-04-29 17:05:11.000000000 -0400
411 @@ -10,7 +10,7 @@
412   *  1998-11-19 Implemented schedule_timeout() and related stuff
413   *             by Andrea Arcangeli
414   *  2002-01-04 New ultra-scalable O(1) scheduler by Ingo Molnar:
415 - *             hybrid priority-list and round-robin design with
416 + *             hybrid priority-list and round-robin deventn with
417   *             an array-switch method of distributing timeslices
418   *             and per-CPU runqueues.  Cleanups and useful suggestions
419   *             by Davide Libenzi, preemptible kernel bits by Robert Love.
420 @@ -56,6 +56,7 @@
421  
422  #include <asm/tlb.h>
423  #include <asm/unistd.h>
424 +#include <linux/arrays.h>
425  #include <linux/vs_sched.h>
426  #include <linux/vs_cvirt.h>
427  
428 @@ -431,6 +432,7 @@
429  
430  repeat_lock_task:
431         rq = task_rq(p);
432 +
433         spin_lock(&rq->lock);
434         if (unlikely(rq != task_rq(p))) {
435                 spin_unlock(&rq->lock);
436 @@ -1741,6 +1743,10 @@
437          * event cannot wake it up and insert it on the runqueue either.
438          */
439         p->state = TASK_RUNNING;
440 +#ifdef CONFIG_CHOPSTIX
441 +       p->last_interrupted=0;
442 +       p->last_ran_j=jiffies;
443 +#endif
444  
445         /*
446          * Make sure we do not leak PI boosting priority to the child:
447 @@ -3608,6 +3614,7 @@
448  
449  #endif
450  
451 +
452  static inline int interactive_sleep(enum sleep_type sleep_type)
453  {
454         return (sleep_type == SLEEP_INTERACTIVE ||
455 @@ -3617,16 +3624,28 @@
456  /*
457   * schedule() is the main scheduler function.
458   */
459 +
460 +#ifdef CONFIG_CHOPSTIX
461 +extern void (*rec_event)(void *,unsigned int);
462 +struct event_spec {
463 +       unsigned long pc;
464 +       unsigned long dcookie;
465 +       unsigned count;
466 +       unsigned char reason;
467 +};
468 +#endif
469 +
470  asmlinkage void __sched schedule(void)
471  {
472         struct task_struct *prev, *next;
473         struct prio_array *array;
474         struct list_head *queue;
475         unsigned long long now;
476 -       unsigned long run_time;
477 +       unsigned long run_time, diff;
478         int cpu, idx, new_prio;
479         long *switch_count;
480         struct rq *rq;
481 +       int sampling_reason;
482  
483         /*
484          * Test if we are atomic.  Since do_exit() needs to call into
485 @@ -3680,6 +3699,7 @@
486         switch_count = &prev->nivcsw;
487         if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
488                 switch_count = &prev->nvcsw;
489 +
490                 if (unlikely((prev->state & TASK_INTERRUPTIBLE) &&
491                                 unlikely(signal_pending(prev))))
492                         prev->state = TASK_RUNNING;
493 @@ -3689,6 +3709,14 @@
494                                 vx_uninterruptible_inc(prev);
495                         }
496                         deactivate_task(prev, rq);
497 +#ifdef CONFIG_CHOPSTIX
498 +                       if (prev->state & TASK_UNINTERRUPTIBLE) {
499 +                               prev->last_interrupted=jiffies;
500 +                       }
501 +                       else if (prev->state & TASK_INTERRUPTIBLE) {
502 +                               prev->last_interrupted=-1;
503 +                       }
504 +#endif
505                 }
506         }
507  
508 @@ -3765,6 +3793,38 @@
509                 prev->sleep_avg = 0;
510         prev->timestamp = prev->last_ran = now;
511  
512 +#ifdef CONFIG_CHOPSTIX
513 +       /* Run only if the Chopstix module so decrees it */
514 +       if (rec_event) {
515 +               prev->last_ran_j = jiffies;
516 +               if (next->last_interrupted!=-1) {
517 +                       if (diff > HZ/5) {
518 +                               struct event event;
519 +                               struct event_spec espec;
520 +                               unsigned long eip;
521 +
522 +                               if (next->last_interrupted) {
523 +                                       diff = (jiffies-next->last_interrupted);
524 +                                       sampling_reason = 0;
525 +                               }
526 +                               else {
527 +                                       diff = jiffies-next->last_ran_j;
528 +                                       sampling_reason = 1;
529 +                               }
530 +                               espec.reason = sampling_reason;
531 +                               eip = next->thread.esp & 4095;
532 +                               event.event_data=&espec;
533 +                               event.task=next;
534 +                               espec.pc=eip;
535 +                               event.event_type=2; 
536 +                               /* index in the event array currently set up */
537 +                               /* make sure the counters are loaded in the order we want them to show up*/ 
538 +                               (*rec_event)(&event, diff);
539 +                       }
540 +               }
541 +               next->last_interrupted=0;
542 +       }
543 +#endif
544         sched_info_switch(prev, next);
545         if (likely(prev != next)) {
546                 next->timestamp = next->last_ran = now;
547 @@ -4664,6 +4724,7 @@
548         get_task_struct(p);
549         read_unlock(&tasklist_lock);
550  
551 +
552         retval = -EPERM;
553         if ((current->euid != p->euid) && (current->euid != p->uid) &&
554                         !capable(CAP_SYS_NICE))
555 @@ -5032,6 +5093,7 @@
556         jiffies_to_timespec(p->policy == SCHED_FIFO ?
557                                 0 : task_timeslice(p), &t);
558         read_unlock(&tasklist_lock);
559 +
560         retval = copy_to_user(interval, &t, sizeof(t)) ? -EFAULT : 0;
561  out_nounlock:
562         return retval;
563 @@ -7275,3 +7337,9 @@
564  }
565  
566  #endif
567 +
568 +#ifdef CONFIG_CHOPSTIX
569 +void (*rec_event)(void *,unsigned int);
570 +EXPORT_SYMBOL(rec_event);
571 +EXPORT_SYMBOL(in_sched_functions);
572 +#endif
573 diff -Nurb linux-2.6.22-580/mm/slab.c linux-2.6.22-590/mm/slab.c
574 --- linux-2.6.22-580/mm/slab.c  2008-04-29 17:04:54.000000000 -0400
575 +++ linux-2.6.22-590/mm/slab.c  2008-04-29 17:05:11.000000000 -0400
576 @@ -110,11 +110,13 @@
577  #include       <linux/fault-inject.h>
578  #include       <linux/rtmutex.h>
579  #include       <linux/reciprocal_div.h>
580 +#include <linux/arrays.h>
581  
582  #include       <asm/cacheflush.h>
583  #include       <asm/tlbflush.h>
584  #include       <asm/page.h>
585  
586 +
587  /*
588   * DEBUG       - 1 for kmem_cache_create() to honour; SLAB_RED_ZONE & SLAB_POISON.
589   *               0 for faster, smaller code (especially in the critical paths).
590 @@ -249,6 +251,14 @@
591         void *addr;
592  };
593  
594 +extern void (*rec_event)(void *,unsigned int);
595 +struct event_spec {
596 +       unsigned long pc;
597 +       unsigned long dcookie; 
598 +       unsigned count;
599 +       unsigned char reason;
600 +};
601 +
602  /*
603   * struct array_cache
604   *
605 @@ -3443,6 +3453,19 @@
606         local_irq_restore(save_flags);
607         objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller);
608         prefetchw(objp);
609 +#ifdef CONFIG_CHOPSTIX
610 +       if (rec_event && objp) {
611 +               struct event event;
612 +               struct event_spec espec;
613 +
614 +               espec.reason = 0; /* alloc */
615 +               event.event_data=&espec;
616 +               event.task = current;
617 +               espec.pc=caller;
618 +               event.event_type=4; 
619 +               (*rec_event)(&event, cachep->buffer_size);
620 +       }
621 +#endif
622  
623         return objp;
624  }
625 @@ -3549,13 +3572,26 @@
626   * Release an obj back to its cache. If the obj has a constructed state, it must
627   * be in this state _before_ it is released.  Called with disabled ints.
628   */
629 -static inline void __cache_free(struct kmem_cache *cachep, void *objp)
630 +static inline void __cache_free(struct kmem_cache *cachep, void *objp, void *caller)
631  {
632         struct array_cache *ac = cpu_cache_get(cachep);
633  
634         check_irq_off();
635 -       objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
636 +       objp = cache_free_debugcheck(cachep, objp, caller);
637         vx_slab_free(cachep);
638 +#ifdef CONFIG_CHOPSTIX
639 +       if (rec_event && objp) {
640 +               struct event event;
641 +               struct event_spec espec;
642 +
643 +               espec.reason = 1; /* free */
644 +               event.event_data=&espec;
645 +               event.task = current;
646 +               espec.pc=caller;
647 +               event.event_type=4; 
648 +               (*rec_event)(&event, cachep->buffer_size);
649 +       }
650 +#endif
651  
652         if (cache_free_alien(cachep, objp))
653                 return;
654 @@ -3651,16 +3687,19 @@
655                         __builtin_return_address(0));
656  }
657  EXPORT_SYMBOL(kmem_cache_alloc_node);
658 -
659  static __always_inline void *
660  __do_kmalloc_node(size_t size, gfp_t flags, int node, void *caller)
661  {
662         struct kmem_cache *cachep;
663 +       void *ret;
664 +
665  
666         cachep = kmem_find_general_cachep(size, flags);
667         if (unlikely(cachep == NULL))
668                 return NULL;
669 -       return kmem_cache_alloc_node(cachep, flags, node);
670 +       ret = kmem_cache_alloc_node(cachep, flags, node);
671 +       
672 +       return ret;
673  }
674  
675  #ifdef CONFIG_DEBUG_SLAB
676 @@ -3696,6 +3735,7 @@
677                                           void *caller)
678  {
679         struct kmem_cache *cachep;
680 +       void *ret;
681  
682         /* If you want to save a few bytes .text space: replace
683          * __ with kmem_.
684 @@ -3705,9 +3745,10 @@
685         cachep = __find_general_cachep(size, flags);
686         if (unlikely(cachep == NULL))
687                 return NULL;
688 -       return __cache_alloc(cachep, flags, caller);
689 -}
690 +       ret = __cache_alloc(cachep, flags, caller);
691  
692 +       return ret;
693 +}
694  
695  #ifdef CONFIG_DEBUG_SLAB
696  void *__kmalloc(size_t size, gfp_t flags)
697 @@ -3723,10 +3764,17 @@
698  EXPORT_SYMBOL(__kmalloc_track_caller);
699  
700  #else
701 +#ifdef CONFIG_CHOPSTIX
702 +void *__kmalloc(size_t size, gfp_t flags)
703 +{
704 +       return __do_kmalloc(size, flags, __builtin_return_address(0));
705 +}
706 +#else
707  void *__kmalloc(size_t size, gfp_t flags)
708  {
709         return __do_kmalloc(size, flags, NULL);
710  }
711 +#endif
712  EXPORT_SYMBOL(__kmalloc);
713  #endif
714  
715 @@ -3792,7 +3840,7 @@
716  
717         local_irq_save(flags);
718         debug_check_no_locks_freed(objp, obj_size(cachep));
719 -       __cache_free(cachep, objp);
720 +       __cache_free(cachep, objp,__builtin_return_address(0));
721         local_irq_restore(flags);
722  }
723  EXPORT_SYMBOL(kmem_cache_free);
724 @@ -3817,7 +3865,7 @@
725         kfree_debugcheck(objp);
726         c = virt_to_cache(objp);
727         debug_check_no_locks_freed(objp, obj_size(c));
728 -       __cache_free(c, (void *)objp);
729 +       __cache_free(c, (void *)objp,__builtin_return_address(0));
730         local_irq_restore(flags);
731  }
732  EXPORT_SYMBOL(kfree);