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
6 source "arch/i386/oprofile/Kconfig"
9 + bool "Chopstix (PlanetLab)"
10 + depends on MODULES && OPROFILE
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".
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
23 #include <linux/cpu.h>
24 #include <linux/blktrace_api.h>
25 #include <linux/fault-inject.h>
26 +#include <linux/arrays.h>
30 @@ -3102,6 +3103,13 @@
32 #endif /* CONFIG_FAIL_MAKE_REQUEST */
34 +extern void (*rec_event)(void *,unsigned int);
37 + unsigned long dcookie;
39 + unsigned char reason;
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 @@
49 +#ifdef CONFIG_CHOPSTIX
52 + struct event_spec espec;
55 + espec.reason = 0;/*request */
57 + eip = bio->bi_end_io;
58 + event.event_data=&espec;
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);
66 ret = q->make_request_fn(q, bio);
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
73 #include <linux/oprofile.h>
74 #include <linux/vmalloc.h>
75 #include <linux/errno.h>
76 +#include <linux/arrays.h>
78 #include "event_buffer.h"
79 #include "cpu_buffer.h"
84 +#ifdef CONFIG_CHOPSTIX
88 + unsigned long dcookie;
92 +extern void (*rec_event)(void *,unsigned int);
96 add_sample(struct oprofile_cpu_buffer * cpu_buf,
97 unsigned long pc, unsigned long event)
100 entry->event = event;
101 increment_head(cpu_buf);
108 int is_kernel = !user_mode(regs);
109 unsigned long pc = profile_pc(regs);
112 +#ifdef CONFIG_CHOPSTIX
115 + struct event_spec espec;
116 + esig.task = current;
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);
125 oprofile_add_ext_sample(pc, regs, event, is_kernel);
128 + oprofile_add_ext_sample(pc, regs, event, is_kernel);
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
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>
144 #define BIO_POOL_SIZE 2
147 struct kmem_cache *slab;
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 @@
160 + unsigned long dcookie;
162 + unsigned char reason;
165 +extern void (*rec_event)(void *,unsigned int);
167 * bio_endio - end I/O on a bio
169 @@ -1028,6 +1038,24 @@
170 bio->bi_size -= bytes_done;
171 bio->bi_sector += (bytes_done >> 9);
173 +#ifdef CONFIG_CHOPSTIX
175 + struct event event;
176 + struct event_spec espec;
179 + espec.reason = 1;/*response */
181 + eip = bio->bi_end_io;
182 + event.event_data=&espec;
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);
192 bio->bi_end_io(bio, bytes_done, error);
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
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>
207 #include <linux/audit.h>
208 #include <linux/signalfd.h>
209 #include <linux/vs_memory.h>
210 +#include <linux/dcookies.h>
212 #include <asm/uaccess.h>
213 #include <asm/mmu_context.h>
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);
224 file = ERR_PTR(-EACCES);
225 if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&
226 S_ISREG(inode->i_mode)) {
228 * Reparenting needs write_lock on tasklist_lock,
229 * so it is safe to do it under read_lock.
232 if (unlikely(tsk->group_leader == child_reaper(tsk)))
233 tsk->nsproxy->pid_ns->child_reaper = tsk;
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
242 +#ifndef __ARRAYS_H__
243 +#define __ARRAYS_H__
244 +#include <linux/list.h>
246 +#define SAMPLING_METHOD_DEFAULT 0
247 +#define SAMPLING_METHOD_LOG 1
249 +/* Every probe has an array handler */
251 +/* XXX - Optimize this structure */
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];
271 + struct list_head link;
273 + unsigned int count;
274 + unsigned int event_type;
275 + struct task_struct *task;
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
283 unsigned long sleep_avg;
284 unsigned long long timestamp, last_ran;
285 +#ifdef CONFIG_CHOPSTIX
286 + unsigned long last_interrupted, last_ran_j;
289 unsigned long long sched_time; /* sched_clock time spent running */
290 enum sleep_type sleep_type;
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
296 #include <linux/spinlock.h>
297 #include <linux/interrupt.h>
298 #include <linux/debug_locks.h>
299 +#include <linux/arrays.h>
301 +#ifdef CONFIG_CHOPSTIX
304 + unsigned long dcookie;
306 + unsigned char reason;
311 * In the DEBUG case we are using the "NULL fastpath" for mutexes,
313 __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key)
315 atomic_set(&lock->count, 1);
316 +#ifdef CONFIG_CHOPSTIX
319 spin_lock_init(&lock->wait_lock);
320 INIT_LIST_HEAD(&lock->wait_list);
323 * The locking fastpath is the 1->0 transition from
324 * 'unlocked' into 'locked' state.
327 __mutex_fastpath_lock(&lock->count, __mutex_lock_slowpath);
332 __set_task_state(task, state);
334 +#ifdef CONFIG_CHOPSTIX
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;
345 + event.event_type=5;
346 + (*rec_event)(&event, 1);
347 + /*spin_unlock(&p->alloc_lock);*/
355 /* didnt get the lock, go to sleep: */
356 spin_unlock_mutex(&lock->wait_lock, flags);
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);
366 /* set it to 0 if there are no waiters left: */
367 if (likely(list_empty(&lock->wait_list)))
369 mutex_lock_nested(struct mutex *lock, unsigned int subclass)
373 __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, subclass);
377 mutex_lock_interruptible_nested(struct mutex *lock, unsigned int subclass)
381 return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, subclass);
386 debug_mutex_wake_waiter(lock, waiter);
388 +#ifdef CONFIG_CHOPSTIX
391 + struct event event;
392 + struct event_spec espec;
394 + espec.reason = 1; /* unlock */
395 + event.event_data=&espec;
396 + event.task = lock->owner->task;
398 + event.event_type=5;
399 + (*rec_event)(&event, 1);
405 wake_up_process(waiter->task);
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
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.
423 #include <asm/unistd.h>
424 +#include <linux/arrays.h>
425 #include <linux/vs_sched.h>
426 #include <linux/vs_cvirt.h>
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.
439 p->state = TASK_RUNNING;
440 +#ifdef CONFIG_CHOPSTIX
441 + p->last_interrupted=0;
442 + p->last_ran_j=jiffies;
446 * Make sure we do not leak PI boosting priority to the child:
447 @@ -3608,6 +3614,7 @@
452 static inline int interactive_sleep(enum sleep_type sleep_type)
454 return (sleep_type == SLEEP_INTERACTIVE ||
455 @@ -3617,16 +3624,28 @@
457 * schedule() is the main scheduler function.
460 +#ifdef CONFIG_CHOPSTIX
461 +extern void (*rec_event)(void *,unsigned int);
464 + unsigned long dcookie;
466 + unsigned char reason;
470 asmlinkage void __sched schedule(void)
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;
481 + int sampling_reason;
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;
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);
496 deactivate_task(prev, rq);
497 +#ifdef CONFIG_CHOPSTIX
498 + if (prev->state & TASK_UNINTERRUPTIBLE) {
499 + prev->last_interrupted=jiffies;
501 + else if (prev->state & TASK_INTERRUPTIBLE) {
502 + prev->last_interrupted=-1;
508 @@ -3765,6 +3793,38 @@
510 prev->timestamp = prev->last_ran = now;
512 +#ifdef CONFIG_CHOPSTIX
513 + /* Run only if the Chopstix module so decrees it */
515 + prev->last_ran_j = jiffies;
516 + if (next->last_interrupted!=-1) {
518 + struct event event;
519 + struct event_spec espec;
522 + if (next->last_interrupted) {
523 + diff = (jiffies-next->last_interrupted);
524 + sampling_reason = 0;
527 + diff = jiffies-next->last_ran_j;
528 + sampling_reason = 1;
530 + espec.reason = sampling_reason;
531 + eip = next->thread.esp & 4095;
532 + event.event_data=&espec;
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);
541 + next->last_interrupted=0;
544 sched_info_switch(prev, next);
545 if (likely(prev != next)) {
546 next->timestamp = next->last_ran = now;
547 @@ -4664,6 +4724,7 @@
549 read_unlock(&tasklist_lock);
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);
560 retval = copy_to_user(interval, &t, sizeof(t)) ? -EFAULT : 0;
563 @@ -7275,3 +7337,9 @@
568 +#ifdef CONFIG_CHOPSTIX
569 +void (*rec_event)(void *,unsigned int);
570 +EXPORT_SYMBOL(rec_event);
571 +EXPORT_SYMBOL(in_sched_functions);
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>
582 #include <asm/cacheflush.h>
583 #include <asm/tlbflush.h>
584 #include <asm/page.h>
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).
594 +extern void (*rec_event)(void *,unsigned int);
597 + unsigned long dcookie;
599 + unsigned char reason;
605 @@ -3443,6 +3453,19 @@
606 local_irq_restore(save_flags);
607 objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller);
609 +#ifdef CONFIG_CHOPSTIX
610 + if (rec_event && objp) {
611 + struct event event;
612 + struct event_spec espec;
614 + espec.reason = 0; /* alloc */
615 + event.event_data=&espec;
616 + event.task = current;
618 + event.event_type=4;
619 + (*rec_event)(&event, cachep->buffer_size);
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.
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)
632 struct array_cache *ac = cpu_cache_get(cachep);
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;
643 + espec.reason = 1; /* free */
644 + event.event_data=&espec;
645 + event.task = current;
647 + event.event_type=4;
648 + (*rec_event)(&event, cachep->buffer_size);
652 if (cache_free_alien(cachep, objp))
654 @@ -3651,16 +3687,19 @@
655 __builtin_return_address(0));
657 EXPORT_SYMBOL(kmem_cache_alloc_node);
659 static __always_inline void *
660 __do_kmalloc_node(size_t size, gfp_t flags, int node, void *caller)
662 struct kmem_cache *cachep;
666 cachep = kmem_find_general_cachep(size, flags);
667 if (unlikely(cachep == NULL))
669 - return kmem_cache_alloc_node(cachep, flags, node);
670 + ret = kmem_cache_alloc_node(cachep, flags, node);
675 #ifdef CONFIG_DEBUG_SLAB
676 @@ -3696,6 +3735,7 @@
679 struct kmem_cache *cachep;
682 /* If you want to save a few bytes .text space: replace
684 @@ -3705,9 +3745,10 @@
685 cachep = __find_general_cachep(size, flags);
686 if (unlikely(cachep == NULL))
688 - return __cache_alloc(cachep, flags, caller);
690 + ret = __cache_alloc(cachep, flags, caller);
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);
701 +#ifdef CONFIG_CHOPSTIX
702 +void *__kmalloc(size_t size, gfp_t flags)
704 + return __do_kmalloc(size, flags, __builtin_return_address(0));
707 void *__kmalloc(size_t size, gfp_t flags)
709 return __do_kmalloc(size, flags, NULL);
712 EXPORT_SYMBOL(__kmalloc);
715 @@ -3792,7 +3840,7 @@
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);
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);
732 EXPORT_SYMBOL(kfree);