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-30 09:29:26.000000000 -0400
3 +++ linux-2.6.22-590/arch/i386/Kconfig 2008-04-30 09:29:41.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-30 09:29:21.000000000 -0400
21 +++ linux-2.6.22-590/block/ll_rw_blk.c 2008-04-30 09:29:41.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-30 09:29:41.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-30 09:29:41.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-30 09:29:26.000000000 -0400
196 +++ linux-2.6.22-590/fs/exec.c 2008-04-30 09:29:41.000000000 -0400
198 #include <linux/audit.h>
199 #include <linux/signalfd.h>
200 #include <linux/vs_memory.h>
201 +#include <linux/dcookies.h>
203 #include <asm/uaccess.h>
204 #include <asm/mmu_context.h>
208 struct inode *inode = nd.dentry->d_inode;
209 +#ifdef CONFIG_CHOPSTIX
210 + unsigned long cookie;
211 + if (!nd.dentry->d_cookie)
212 + get_dcookie(nd.dentry, nd.mnt, &cookie);
215 file = ERR_PTR(-EACCES);
216 if (!(nd.mnt->mnt_flags & MNT_NOEXEC) &&
217 S_ISREG(inode->i_mode)) {
218 diff -Nurb linux-2.6.22-580/include/linux/arrays.h linux-2.6.22-590/include/linux/arrays.h
219 --- linux-2.6.22-580/include/linux/arrays.h 1969-12-31 19:00:00.000000000 -0500
220 +++ linux-2.6.22-590/include/linux/arrays.h 2008-04-30 09:29:41.000000000 -0400
222 +#ifndef __ARRAYS_H__
223 +#define __ARRAYS_H__
224 +#include <linux/list.h>
226 +#define SAMPLING_METHOD_DEFAULT 0
227 +#define SAMPLING_METHOD_LOG 1
229 +/* Every probe has an array handler */
231 +/* XXX - Optimize this structure */
233 +extern void (*rec_event)(void *,unsigned int);
234 +struct array_handler {
235 + struct list_head link;
236 + unsigned int (*hash_func)(void *);
237 + unsigned int (*sampling_func)(void *,int,void *);
238 + unsigned short size;
239 + unsigned int threshold;
240 + unsigned char **expcount;
241 + unsigned int sampling_method;
242 + unsigned int **arrays;
243 + unsigned int arraysize;
244 + unsigned int num_samples[2];
245 + void **epoch_samples; /* size-sized lists of samples */
246 + unsigned int (*serialize)(void *, void *);
247 + unsigned char code[5];
251 + struct list_head link;
253 + unsigned int count;
254 + unsigned int event_type;
255 + struct task_struct *task;
258 diff -Nurb linux-2.6.22-580/include/linux/mutex.h linux-2.6.22-590/include/linux/mutex.h
259 --- linux-2.6.22-580/include/linux/mutex.h 2007-07-08 19:32:17.000000000 -0400
260 +++ linux-2.6.22-590/include/linux/mutex.h 2008-04-30 09:45:43.000000000 -0400
262 struct thread_info *owner;
266 +#ifdef CONFIG_CHOPSTIX
267 + struct thread_info *owner;
270 #ifdef CONFIG_DEBUG_LOCK_ALLOC
271 struct lockdep_map dep_map;
272 diff -Nurb linux-2.6.22-580/include/linux/sched.h linux-2.6.22-590/include/linux/sched.h
273 --- linux-2.6.22-580/include/linux/sched.h 2008-04-30 09:29:26.000000000 -0400
274 +++ linux-2.6.22-590/include/linux/sched.h 2008-04-30 09:29:41.000000000 -0400
277 unsigned long sleep_avg;
278 unsigned long long timestamp, last_ran;
279 +#ifdef CONFIG_CHOPSTIX
280 + unsigned long last_interrupted, last_ran_j;
283 unsigned long long sched_time; /* sched_clock time spent running */
284 enum sleep_type sleep_type;
286 diff -Nurb linux-2.6.22-580/kernel/mutex.c linux-2.6.22-590/kernel/mutex.c
287 --- linux-2.6.22-580/kernel/mutex.c 2007-07-08 19:32:17.000000000 -0400
288 +++ linux-2.6.22-590/kernel/mutex.c 2008-04-30 09:29:41.000000000 -0400
290 #include <linux/spinlock.h>
291 #include <linux/interrupt.h>
292 #include <linux/debug_locks.h>
293 +#include <linux/arrays.h>
294 +#undef CONFIG_CHOPSTIX
295 +#ifdef CONFIG_CHOPSTIX
298 + unsigned long dcookie;
300 + unsigned char reason;
305 * In the DEBUG case we are using the "NULL fastpath" for mutexes,
307 __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key)
309 atomic_set(&lock->count, 1);
310 +#ifdef CONFIG_CHOPSTIX
313 spin_lock_init(&lock->wait_lock);
314 INIT_LIST_HEAD(&lock->wait_list);
317 * The locking fastpath is the 1->0 transition from
318 * 'unlocked' into 'locked' state.
321 __mutex_fastpath_lock(&lock->count, __mutex_lock_slowpath);
326 __set_task_state(task, state);
328 +#ifdef CONFIG_CHOPSTIX
331 + struct event event;
332 + struct event_spec espec;
333 + struct task_struct *p = lock->owner->task;
334 + /*spin_lock(&p->alloc_lock);*/
335 + espec.reason = 0; /* lock */
336 + event.event_data=&espec;
339 + event.event_type=5;
340 + (*rec_event)(&event, 1);
341 + /*spin_unlock(&p->alloc_lock);*/
349 /* didnt get the lock, go to sleep: */
350 spin_unlock_mutex(&lock->wait_lock, flags);
353 /* got the lock - rejoice! */
354 mutex_remove_waiter(lock, &waiter, task_thread_info(task));
355 debug_mutex_set_owner(lock, task_thread_info(task));
356 +#ifdef CONFIG_CHOPSTIX
357 + lock->owner = task_thread_info(task);
360 /* set it to 0 if there are no waiters left: */
361 if (likely(list_empty(&lock->wait_list)))
363 mutex_lock_nested(struct mutex *lock, unsigned int subclass)
367 __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, subclass);
371 mutex_lock_interruptible_nested(struct mutex *lock, unsigned int subclass)
375 return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, subclass);
380 debug_mutex_wake_waiter(lock, waiter);
382 +#ifdef CONFIG_CHOPSTIX
385 + struct event event;
386 + struct event_spec espec;
388 + espec.reason = 1; /* unlock */
389 + event.event_data=&espec;
390 + event.task = lock->owner->task;
392 + event.event_type=5;
393 + (*rec_event)(&event, 1);
399 wake_up_process(waiter->task);
402 diff -Nurb linux-2.6.22-580/kernel/sched.c linux-2.6.22-590/kernel/sched.c
403 --- linux-2.6.22-580/kernel/sched.c 2008-04-30 09:29:26.000000000 -0400
404 +++ linux-2.6.22-590/kernel/sched.c 2008-04-30 09:29:41.000000000 -0400
406 * 1998-11-19 Implemented schedule_timeout() and related stuff
407 * by Andrea Arcangeli
408 * 2002-01-04 New ultra-scalable O(1) scheduler by Ingo Molnar:
409 - * hybrid priority-list and round-robin design with
410 + * hybrid priority-list and round-robin deventn with
411 * an array-switch method of distributing timeslices
412 * and per-CPU runqueues. Cleanups and useful suggestions
413 * by Davide Libenzi, preemptible kernel bits by Robert Love.
417 #include <asm/unistd.h>
418 +#include <linux/arrays.h>
419 #include <linux/vs_sched.h>
420 #include <linux/vs_cvirt.h>
427 spin_lock(&rq->lock);
428 if (unlikely(rq != task_rq(p))) {
429 spin_unlock(&rq->lock);
430 @@ -1741,6 +1743,10 @@
431 * event cannot wake it up and insert it on the runqueue either.
433 p->state = TASK_RUNNING;
434 +#ifdef CONFIG_CHOPSTIX
435 + p->last_interrupted=0;
436 + p->last_ran_j=jiffies;
440 * Make sure we do not leak PI boosting priority to the child:
441 @@ -3608,6 +3614,7 @@
446 static inline int interactive_sleep(enum sleep_type sleep_type)
448 return (sleep_type == SLEEP_INTERACTIVE ||
449 @@ -3617,16 +3624,28 @@
451 * schedule() is the main scheduler function.
454 +#ifdef CONFIG_CHOPSTIX
455 +extern void (*rec_event)(void *,unsigned int);
458 + unsigned long dcookie;
460 + unsigned char reason;
464 asmlinkage void __sched schedule(void)
466 struct task_struct *prev, *next;
467 struct prio_array *array;
468 struct list_head *queue;
469 unsigned long long now;
470 - unsigned long run_time;
471 + unsigned long run_time, diff;
472 int cpu, idx, new_prio;
475 + int sampling_reason;
478 * Test if we are atomic. Since do_exit() needs to call into
479 @@ -3680,6 +3699,7 @@
480 switch_count = &prev->nivcsw;
481 if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
482 switch_count = &prev->nvcsw;
484 if (unlikely((prev->state & TASK_INTERRUPTIBLE) &&
485 unlikely(signal_pending(prev))))
486 prev->state = TASK_RUNNING;
487 @@ -3689,6 +3709,14 @@
488 vx_uninterruptible_inc(prev);
490 deactivate_task(prev, rq);
491 +#ifdef CONFIG_CHOPSTIX
492 + if (prev->state & TASK_UNINTERRUPTIBLE) {
493 + prev->last_interrupted=jiffies;
495 + else if (prev->state & TASK_INTERRUPTIBLE) {
496 + prev->last_interrupted=-1;
502 @@ -3765,6 +3793,39 @@
504 prev->timestamp = prev->last_ran = now;
506 +#ifdef CONFIG_CHOPSTIX
507 + /* Run only if the Chopstix module so decrees it */
509 + prev->last_ran_j = jiffies;
510 + if (next->last_interrupted!=-1) {
511 + if (next->last_interrupted) {
512 + diff = (jiffies-next->last_interrupted);
513 + sampling_reason = 0;
516 + diff = jiffies-next->last_ran_j;
517 + sampling_reason = 1;
521 + struct event event;
522 + struct event_spec espec;
525 + espec.reason = sampling_reason;
526 + eip = next->thread.esp & 4095;
527 + event.event_data=&espec;
530 + event.event_type=2;
531 + /* index in the event array currently set up */
532 + /* make sure the counters are loaded in the order we want them to show up*/
533 + (*rec_event)(&event, diff);
536 + next->last_interrupted=0;
539 sched_info_switch(prev, next);
540 if (likely(prev != next)) {
541 next->timestamp = next->last_ran = now;
542 @@ -4664,6 +4725,7 @@
544 read_unlock(&tasklist_lock);
548 if ((current->euid != p->euid) && (current->euid != p->uid) &&
549 !capable(CAP_SYS_NICE))
550 @@ -5032,6 +5094,7 @@
551 jiffies_to_timespec(p->policy == SCHED_FIFO ?
552 0 : task_timeslice(p), &t);
553 read_unlock(&tasklist_lock);
555 retval = copy_to_user(interval, &t, sizeof(t)) ? -EFAULT : 0;
558 @@ -7275,3 +7338,9 @@
563 +#ifdef CONFIG_CHOPSTIX
564 +void (*rec_event)(void *,unsigned int);
565 +EXPORT_SYMBOL(rec_event);
566 +EXPORT_SYMBOL(in_sched_functions);
568 diff -Nurb linux-2.6.22-580/mm/slab.c linux-2.6.22-590/mm/slab.c
569 --- linux-2.6.22-580/mm/slab.c 2008-04-30 09:29:26.000000000 -0400
570 +++ linux-2.6.22-590/mm/slab.c 2008-04-30 09:29:41.000000000 -0400
571 @@ -110,11 +110,13 @@
572 #include <linux/fault-inject.h>
573 #include <linux/rtmutex.h>
574 #include <linux/reciprocal_div.h>
575 +#include <linux/arrays.h>
577 #include <asm/cacheflush.h>
578 #include <asm/tlbflush.h>
579 #include <asm/page.h>
583 * DEBUG - 1 for kmem_cache_create() to honour; SLAB_RED_ZONE & SLAB_POISON.
584 * 0 for faster, smaller code (especially in the critical paths).
589 +extern void (*rec_event)(void *,unsigned int);
592 + unsigned long dcookie;
594 + unsigned char reason;
600 @@ -3443,6 +3453,19 @@
601 local_irq_restore(save_flags);
602 objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller);
604 +#ifdef CONFIG_CHOPSTIX
605 + if (rec_event && objp) {
606 + struct event event;
607 + struct event_spec espec;
609 + espec.reason = 0; /* alloc */
610 + event.event_data=&espec;
611 + event.task = current;
613 + event.event_type=4;
614 + (*rec_event)(&event, cachep->buffer_size);
620 @@ -3549,13 +3572,26 @@
621 * Release an obj back to its cache. If the obj has a constructed state, it must
622 * be in this state _before_ it is released. Called with disabled ints.
624 -static inline void __cache_free(struct kmem_cache *cachep, void *objp)
625 +static inline void __cache_free(struct kmem_cache *cachep, void *objp, void *caller)
627 struct array_cache *ac = cpu_cache_get(cachep);
630 - objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
631 + objp = cache_free_debugcheck(cachep, objp, caller);
632 vx_slab_free(cachep);
633 +#ifdef CONFIG_CHOPSTIX
634 + if (rec_event && objp) {
635 + struct event event;
636 + struct event_spec espec;
638 + espec.reason = 1; /* free */
639 + event.event_data=&espec;
640 + event.task = current;
642 + event.event_type=4;
643 + (*rec_event)(&event, cachep->buffer_size);
647 if (cache_free_alien(cachep, objp))
649 @@ -3651,16 +3687,19 @@
650 __builtin_return_address(0));
652 EXPORT_SYMBOL(kmem_cache_alloc_node);
654 static __always_inline void *
655 __do_kmalloc_node(size_t size, gfp_t flags, int node, void *caller)
657 struct kmem_cache *cachep;
661 cachep = kmem_find_general_cachep(size, flags);
662 if (unlikely(cachep == NULL))
664 - return kmem_cache_alloc_node(cachep, flags, node);
665 + ret = kmem_cache_alloc_node(cachep, flags, node);
670 #ifdef CONFIG_DEBUG_SLAB
671 @@ -3696,6 +3735,7 @@
674 struct kmem_cache *cachep;
677 /* If you want to save a few bytes .text space: replace
679 @@ -3705,9 +3745,10 @@
680 cachep = __find_general_cachep(size, flags);
681 if (unlikely(cachep == NULL))
683 - return __cache_alloc(cachep, flags, caller);
685 + ret = __cache_alloc(cachep, flags, caller);
690 #ifdef CONFIG_DEBUG_SLAB
691 void *__kmalloc(size_t size, gfp_t flags)
692 @@ -3723,10 +3764,17 @@
693 EXPORT_SYMBOL(__kmalloc_track_caller);
696 +#ifdef CONFIG_CHOPSTIX
697 +void *__kmalloc(size_t size, gfp_t flags)
699 + return __do_kmalloc(size, flags, __builtin_return_address(0));
702 void *__kmalloc(size_t size, gfp_t flags)
704 return __do_kmalloc(size, flags, NULL);
707 EXPORT_SYMBOL(__kmalloc);
710 @@ -3792,7 +3840,7 @@
712 local_irq_save(flags);
713 debug_check_no_locks_freed(objp, obj_size(cachep));
714 - __cache_free(cachep, objp);
715 + __cache_free(cachep, objp,__builtin_return_address(0));
716 local_irq_restore(flags);
718 EXPORT_SYMBOL(kmem_cache_free);
719 @@ -3817,7 +3865,7 @@
720 kfree_debugcheck(objp);
721 c = virt_to_cache(objp);
722 debug_check_no_locks_freed(objp, obj_size(c));
723 - __cache_free(c, (void *)objp);
724 + __cache_free(c, (void *)objp,__builtin_return_address(0));
725 local_irq_restore(flags);
727 EXPORT_SYMBOL(kfree);