ia64/linux-2.6.18-xen.hg

annotate drivers/oprofile/buffer_sync.c @ 893:f994bfe9b93b

linux/blktap2: reduce TLB flush scope

c/s 885 added very coarse TLB flushing. Since these flushes always
follow single page updates, single page flushes (when available) are
sufficient.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 04 10:32:57 2009 +0100 (2009-06-04)
parents 132f24200f4c
children
rev   line source
ian@0 1 /**
ian@0 2 * @file buffer_sync.c
ian@0 3 *
ian@0 4 * @remark Copyright 2002 OProfile authors
ian@0 5 * @remark Read the file COPYING
ian@0 6 *
ian@0 7 * @author John Levon <levon@movementarian.org>
ian@0 8 *
ian@15 9 * Modified by Aravind Menon for Xen
ian@15 10 * These modifications are:
ian@15 11 * Copyright (C) 2005 Hewlett-Packard Co.
ian@15 12 *
ian@0 13 * This is the core of the buffer management. Each
ian@0 14 * CPU buffer is processed and entered into the
ian@0 15 * global event buffer. Such processing is necessary
ian@0 16 * in several circumstances, mentioned below.
ian@0 17 *
ian@0 18 * The processing does the job of converting the
ian@0 19 * transitory EIP value into a persistent dentry/offset
ian@0 20 * value that the profiler can record at its leisure.
ian@0 21 *
ian@0 22 * See fs/dcookies.c for a description of the dentry/offset
ian@0 23 * objects.
ian@0 24 */
ian@0 25
ian@0 26 #include <linux/mm.h>
ian@0 27 #include <linux/workqueue.h>
ian@0 28 #include <linux/notifier.h>
ian@0 29 #include <linux/dcookies.h>
ian@0 30 #include <linux/profile.h>
ian@0 31 #include <linux/module.h>
ian@0 32 #include <linux/fs.h>
ian@0 33
ian@0 34 #include "oprofile_stats.h"
ian@0 35 #include "event_buffer.h"
ian@0 36 #include "cpu_buffer.h"
ian@0 37 #include "buffer_sync.h"
ian@0 38
ian@0 39 static LIST_HEAD(dying_tasks);
ian@0 40 static LIST_HEAD(dead_tasks);
ian@0 41 static cpumask_t marked_cpus = CPU_MASK_NONE;
ian@0 42 static DEFINE_SPINLOCK(task_mortuary);
ian@0 43 static void process_task_mortuary(void);
ian@0 44
ian@15 45 static int cpu_current_domain[NR_CPUS];
ian@0 46
ian@0 47 /* Take ownership of the task struct and place it on the
ian@0 48 * list for processing. Only after two full buffer syncs
ian@0 49 * does the task eventually get freed, because by then
ian@0 50 * we are sure we will not reference it again.
ian@0 51 * Can be invoked from softirq via RCU callback due to
ian@0 52 * call_rcu() of the task struct, hence the _irqsave.
ian@0 53 */
ian@0 54 static int task_free_notify(struct notifier_block * self, unsigned long val, void * data)
ian@0 55 {
ian@0 56 unsigned long flags;
ian@0 57 struct task_struct * task = data;
ian@0 58 spin_lock_irqsave(&task_mortuary, flags);
ian@0 59 list_add(&task->tasks, &dying_tasks);
ian@0 60 spin_unlock_irqrestore(&task_mortuary, flags);
ian@0 61 return NOTIFY_OK;
ian@0 62 }
ian@0 63
ian@0 64
ian@0 65 /* The task is on its way out. A sync of the buffer means we can catch
ian@0 66 * any remaining samples for this task.
ian@0 67 */
ian@0 68 static int task_exit_notify(struct notifier_block * self, unsigned long val, void * data)
ian@0 69 {
ian@0 70 /* To avoid latency problems, we only process the current CPU,
ian@0 71 * hoping that most samples for the task are on this CPU
ian@0 72 */
ian@0 73 sync_buffer(raw_smp_processor_id());
ian@0 74 return 0;
ian@0 75 }
ian@0 76
ian@0 77
ian@0 78 /* The task is about to try a do_munmap(). We peek at what it's going to
ian@0 79 * do, and if it's an executable region, process the samples first, so
ian@0 80 * we don't lose any. This does not have to be exact, it's a QoI issue
ian@0 81 * only.
ian@0 82 */
ian@0 83 static int munmap_notify(struct notifier_block * self, unsigned long val, void * data)
ian@0 84 {
ian@0 85 unsigned long addr = (unsigned long)data;
ian@0 86 struct mm_struct * mm = current->mm;
ian@0 87 struct vm_area_struct * mpnt;
ian@0 88
ian@0 89 down_read(&mm->mmap_sem);
ian@0 90
ian@0 91 mpnt = find_vma(mm, addr);
ian@0 92 if (mpnt && mpnt->vm_file && (mpnt->vm_flags & VM_EXEC)) {
ian@0 93 up_read(&mm->mmap_sem);
ian@0 94 /* To avoid latency problems, we only process the current CPU,
ian@0 95 * hoping that most samples for the task are on this CPU
ian@0 96 */
ian@0 97 sync_buffer(raw_smp_processor_id());
ian@0 98 return 0;
ian@0 99 }
ian@0 100
ian@0 101 up_read(&mm->mmap_sem);
ian@0 102 return 0;
ian@0 103 }
ian@0 104
ian@0 105
ian@0 106 /* We need to be told about new modules so we don't attribute to a previously
ian@0 107 * loaded module, or drop the samples on the floor.
ian@0 108 */
ian@0 109 static int module_load_notify(struct notifier_block * self, unsigned long val, void * data)
ian@0 110 {
ian@0 111 #ifdef CONFIG_MODULES
ian@0 112 if (val != MODULE_STATE_COMING)
ian@0 113 return 0;
ian@0 114
ian@0 115 /* FIXME: should we process all CPU buffers ? */
ian@0 116 mutex_lock(&buffer_mutex);
ian@0 117 add_event_entry(ESCAPE_CODE);
ian@0 118 add_event_entry(MODULE_LOADED_CODE);
ian@0 119 mutex_unlock(&buffer_mutex);
ian@0 120 #endif
ian@0 121 return 0;
ian@0 122 }
ian@0 123
ian@0 124
ian@0 125 static struct notifier_block task_free_nb = {
ian@0 126 .notifier_call = task_free_notify,
ian@0 127 };
ian@0 128
ian@0 129 static struct notifier_block task_exit_nb = {
ian@0 130 .notifier_call = task_exit_notify,
ian@0 131 };
ian@0 132
ian@0 133 static struct notifier_block munmap_nb = {
ian@0 134 .notifier_call = munmap_notify,
ian@0 135 };
ian@0 136
ian@0 137 static struct notifier_block module_load_nb = {
ian@0 138 .notifier_call = module_load_notify,
ian@0 139 };
ian@0 140
ian@0 141
ian@0 142 static void end_sync(void)
ian@0 143 {
ian@0 144 end_cpu_work();
ian@0 145 /* make sure we don't leak task structs */
ian@0 146 process_task_mortuary();
ian@0 147 process_task_mortuary();
ian@0 148 }
ian@0 149
ian@0 150
ian@0 151 int sync_start(void)
ian@0 152 {
ian@0 153 int err;
ian@15 154 int i;
ian@15 155
ian@15 156 for (i = 0; i < NR_CPUS; i++) {
ian@15 157 cpu_current_domain[i] = COORDINATOR_DOMAIN;
ian@15 158 }
ian@0 159
ian@0 160 start_cpu_work();
ian@0 161
ian@0 162 err = task_handoff_register(&task_free_nb);
ian@0 163 if (err)
ian@0 164 goto out1;
ian@0 165 err = profile_event_register(PROFILE_TASK_EXIT, &task_exit_nb);
ian@0 166 if (err)
ian@0 167 goto out2;
ian@0 168 err = profile_event_register(PROFILE_MUNMAP, &munmap_nb);
ian@0 169 if (err)
ian@0 170 goto out3;
ian@0 171 err = register_module_notifier(&module_load_nb);
ian@0 172 if (err)
ian@0 173 goto out4;
ian@0 174
ian@0 175 out:
ian@0 176 return err;
ian@0 177 out4:
ian@0 178 profile_event_unregister(PROFILE_MUNMAP, &munmap_nb);
ian@0 179 out3:
ian@0 180 profile_event_unregister(PROFILE_TASK_EXIT, &task_exit_nb);
ian@0 181 out2:
ian@0 182 task_handoff_unregister(&task_free_nb);
ian@0 183 out1:
ian@0 184 end_sync();
ian@0 185 goto out;
ian@0 186 }
ian@0 187
ian@0 188
ian@0 189 void sync_stop(void)
ian@0 190 {
ian@0 191 unregister_module_notifier(&module_load_nb);
ian@0 192 profile_event_unregister(PROFILE_MUNMAP, &munmap_nb);
ian@0 193 profile_event_unregister(PROFILE_TASK_EXIT, &task_exit_nb);
ian@0 194 task_handoff_unregister(&task_free_nb);
ian@0 195 end_sync();
ian@0 196 }
ian@0 197
ian@0 198
ian@0 199 /* Optimisation. We can manage without taking the dcookie sem
ian@0 200 * because we cannot reach this code without at least one
ian@0 201 * dcookie user still being registered (namely, the reader
ian@0 202 * of the event buffer). */
ian@0 203 static inline unsigned long fast_get_dcookie(struct dentry * dentry,
ian@0 204 struct vfsmount * vfsmnt)
ian@0 205 {
ian@0 206 unsigned long cookie;
ian@0 207
ian@0 208 if (dentry->d_cookie)
ian@0 209 return (unsigned long)dentry;
ian@0 210 get_dcookie(dentry, vfsmnt, &cookie);
ian@0 211 return cookie;
ian@0 212 }
ian@0 213
ian@0 214
ian@0 215 /* Look up the dcookie for the task's first VM_EXECUTABLE mapping,
ian@0 216 * which corresponds loosely to "application name". This is
ian@0 217 * not strictly necessary but allows oprofile to associate
ian@0 218 * shared-library samples with particular applications
ian@0 219 */
ian@0 220 static unsigned long get_exec_dcookie(struct mm_struct * mm)
ian@0 221 {
ian@0 222 unsigned long cookie = NO_COOKIE;
ian@0 223 struct vm_area_struct * vma;
ian@0 224
ian@0 225 if (!mm)
ian@0 226 goto out;
ian@0 227
ian@0 228 for (vma = mm->mmap; vma; vma = vma->vm_next) {
ian@0 229 if (!vma->vm_file)
ian@0 230 continue;
ian@0 231 if (!(vma->vm_flags & VM_EXECUTABLE))
ian@0 232 continue;
ian@0 233 cookie = fast_get_dcookie(vma->vm_file->f_dentry,
ian@0 234 vma->vm_file->f_vfsmnt);
ian@0 235 break;
ian@0 236 }
ian@0 237
ian@0 238 out:
ian@0 239 return cookie;
ian@0 240 }
ian@0 241
ian@0 242
ian@0 243 /* Convert the EIP value of a sample into a persistent dentry/offset
ian@0 244 * pair that can then be added to the global event buffer. We make
ian@0 245 * sure to do this lookup before a mm->mmap modification happens so
ian@0 246 * we don't lose track.
ian@0 247 */
ian@0 248 static unsigned long lookup_dcookie(struct mm_struct * mm, unsigned long addr, off_t * offset)
ian@0 249 {
ian@0 250 unsigned long cookie = NO_COOKIE;
ian@0 251 struct vm_area_struct * vma;
ian@0 252
ian@0 253 for (vma = find_vma(mm, addr); vma; vma = vma->vm_next) {
ian@0 254
ian@0 255 if (addr < vma->vm_start || addr >= vma->vm_end)
ian@0 256 continue;
ian@0 257
ian@0 258 if (vma->vm_file) {
ian@0 259 cookie = fast_get_dcookie(vma->vm_file->f_dentry,
ian@0 260 vma->vm_file->f_vfsmnt);
ian@0 261 *offset = (vma->vm_pgoff << PAGE_SHIFT) + addr -
ian@0 262 vma->vm_start;
ian@0 263 } else {
ian@0 264 /* must be an anonymous map */
ian@0 265 *offset = addr;
ian@0 266 }
ian@0 267
ian@0 268 break;
ian@0 269 }
ian@0 270
ian@0 271 if (!vma)
ian@0 272 cookie = INVALID_COOKIE;
ian@0 273
ian@0 274 return cookie;
ian@0 275 }
ian@0 276
ian@0 277
ian@0 278 static unsigned long last_cookie = INVALID_COOKIE;
ian@0 279
ian@0 280 static void add_cpu_switch(int i)
ian@0 281 {
ian@0 282 add_event_entry(ESCAPE_CODE);
ian@0 283 add_event_entry(CPU_SWITCH_CODE);
ian@0 284 add_event_entry(i);
ian@0 285 last_cookie = INVALID_COOKIE;
ian@0 286 }
ian@0 287
ian@15 288 static void add_cpu_mode_switch(unsigned int cpu_mode)
ian@0 289 {
ian@0 290 add_event_entry(ESCAPE_CODE);
ian@15 291 switch (cpu_mode) {
ian@15 292 case CPU_MODE_USER:
ian@15 293 add_event_entry(USER_ENTER_SWITCH_CODE);
ian@15 294 break;
ian@15 295 case CPU_MODE_KERNEL:
ian@15 296 add_event_entry(KERNEL_ENTER_SWITCH_CODE);
ian@15 297 break;
ian@15 298 case CPU_MODE_XEN:
ian@15 299 add_event_entry(XEN_ENTER_SWITCH_CODE);
ian@15 300 break;
ian@15 301 default:
ian@15 302 break;
ian@15 303 }
ian@0 304 }
ian@15 305
ian@15 306 static void add_domain_switch(unsigned long domain_id)
ian@15 307 {
ian@15 308 add_event_entry(ESCAPE_CODE);
ian@15 309 add_event_entry(DOMAIN_SWITCH_CODE);
ian@15 310 add_event_entry(domain_id);
ian@15 311 }
ian@15 312
ian@0 313 static void
ian@0 314 add_user_ctx_switch(struct task_struct const * task, unsigned long cookie)
ian@0 315 {
ian@0 316 add_event_entry(ESCAPE_CODE);
ian@0 317 add_event_entry(CTX_SWITCH_CODE);
ian@0 318 add_event_entry(task->pid);
ian@0 319 add_event_entry(cookie);
ian@0 320 /* Another code for daemon back-compat */
ian@0 321 add_event_entry(ESCAPE_CODE);
ian@0 322 add_event_entry(CTX_TGID_CODE);
ian@0 323 add_event_entry(task->tgid);
ian@0 324 }
ian@0 325
ian@0 326
ian@0 327 static void add_cookie_switch(unsigned long cookie)
ian@0 328 {
ian@0 329 add_event_entry(ESCAPE_CODE);
ian@0 330 add_event_entry(COOKIE_SWITCH_CODE);
ian@0 331 add_event_entry(cookie);
ian@0 332 }
ian@0 333
ian@0 334
ian@0 335 static void add_trace_begin(void)
ian@0 336 {
ian@0 337 add_event_entry(ESCAPE_CODE);
ian@0 338 add_event_entry(TRACE_BEGIN_CODE);
ian@0 339 }
ian@0 340
ian@0 341
ian@0 342 static void add_sample_entry(unsigned long offset, unsigned long event)
ian@0 343 {
ian@0 344 add_event_entry(offset);
ian@0 345 add_event_entry(event);
ian@0 346 }
ian@0 347
ian@0 348
ian@0 349 static int add_us_sample(struct mm_struct * mm, struct op_sample * s)
ian@0 350 {
ian@0 351 unsigned long cookie;
ian@0 352 off_t offset;
ian@0 353
ian@0 354 cookie = lookup_dcookie(mm, s->eip, &offset);
ian@0 355
ian@0 356 if (cookie == INVALID_COOKIE) {
ian@0 357 atomic_inc(&oprofile_stats.sample_lost_no_mapping);
ian@0 358 return 0;
ian@0 359 }
ian@0 360
ian@0 361 if (cookie != last_cookie) {
ian@0 362 add_cookie_switch(cookie);
ian@0 363 last_cookie = cookie;
ian@0 364 }
ian@0 365
ian@0 366 add_sample_entry(offset, s->event);
ian@0 367
ian@0 368 return 1;
ian@0 369 }
ian@0 370
ian@0 371
ian@0 372 /* Add a sample to the global event buffer. If possible the
ian@0 373 * sample is converted into a persistent dentry/offset pair
ian@0 374 * for later lookup from userspace.
ian@0 375 */
ian@0 376 static int
ian@15 377 add_sample(struct mm_struct * mm, struct op_sample * s, int cpu_mode)
ian@0 378 {
ian@15 379 if (cpu_mode >= CPU_MODE_KERNEL) {
ian@0 380 add_sample_entry(s->eip, s->event);
ian@0 381 return 1;
ian@0 382 } else if (mm) {
ian@0 383 return add_us_sample(mm, s);
ian@0 384 } else {
ian@0 385 atomic_inc(&oprofile_stats.sample_lost_no_mm);
ian@0 386 }
ian@0 387 return 0;
ian@0 388 }
ian@0 389
ian@0 390
ian@0 391 static void release_mm(struct mm_struct * mm)
ian@0 392 {
ian@0 393 if (!mm)
ian@0 394 return;
ian@0 395 up_read(&mm->mmap_sem);
ian@0 396 mmput(mm);
ian@0 397 }
ian@0 398
ian@0 399
ian@0 400 static struct mm_struct * take_tasks_mm(struct task_struct * task)
ian@0 401 {
ian@0 402 struct mm_struct * mm = get_task_mm(task);
ian@0 403 if (mm)
ian@0 404 down_read(&mm->mmap_sem);
ian@0 405 return mm;
ian@0 406 }
ian@0 407
ian@0 408
ian@0 409 static inline int is_code(unsigned long val)
ian@0 410 {
ian@0 411 return val == ESCAPE_CODE;
ian@0 412 }
ian@0 413
ian@0 414
ian@0 415 /* "acquire" as many cpu buffer slots as we can */
ian@0 416 static unsigned long get_slots(struct oprofile_cpu_buffer * b)
ian@0 417 {
ian@0 418 unsigned long head = b->head_pos;
ian@0 419 unsigned long tail = b->tail_pos;
ian@0 420
ian@0 421 /*
ian@0 422 * Subtle. This resets the persistent last_task
ian@0 423 * and in_kernel values used for switching notes.
ian@0 424 * BUT, there is a small window between reading
ian@0 425 * head_pos, and this call, that means samples
ian@0 426 * can appear at the new head position, but not
ian@0 427 * be prefixed with the notes for switching
ian@0 428 * kernel mode or a task switch. This small hole
ian@0 429 * can lead to mis-attribution or samples where
ian@0 430 * we don't know if it's in the kernel or not,
ian@0 431 * at the start of an event buffer.
ian@0 432 */
ian@0 433 cpu_buffer_reset(b);
ian@0 434
ian@0 435 if (head >= tail)
ian@0 436 return head - tail;
ian@0 437
ian@0 438 return head + (b->buffer_size - tail);
ian@0 439 }
ian@0 440
ian@0 441
ian@0 442 static void increment_tail(struct oprofile_cpu_buffer * b)
ian@0 443 {
ian@0 444 unsigned long new_tail = b->tail_pos + 1;
ian@0 445
ian@0 446 rmb();
ian@0 447
ian@0 448 if (new_tail < b->buffer_size)
ian@0 449 b->tail_pos = new_tail;
ian@0 450 else
ian@0 451 b->tail_pos = 0;
ian@0 452 }
ian@0 453
ian@0 454
ian@0 455 /* Move tasks along towards death. Any tasks on dead_tasks
ian@0 456 * will definitely have no remaining references in any
ian@0 457 * CPU buffers at this point, because we use two lists,
ian@0 458 * and to have reached the list, it must have gone through
ian@0 459 * one full sync already.
ian@0 460 */
ian@0 461 static void process_task_mortuary(void)
ian@0 462 {
ian@0 463 unsigned long flags;
ian@0 464 LIST_HEAD(local_dead_tasks);
ian@0 465 struct task_struct * task;
ian@0 466 struct task_struct * ttask;
ian@0 467
ian@0 468 spin_lock_irqsave(&task_mortuary, flags);
ian@0 469
ian@0 470 list_splice_init(&dead_tasks, &local_dead_tasks);
ian@0 471 list_splice_init(&dying_tasks, &dead_tasks);
ian@0 472
ian@0 473 spin_unlock_irqrestore(&task_mortuary, flags);
ian@0 474
ian@0 475 list_for_each_entry_safe(task, ttask, &local_dead_tasks, tasks) {
ian@0 476 list_del(&task->tasks);
ian@0 477 free_task(task);
ian@0 478 }
ian@0 479 }
ian@0 480
ian@0 481
ian@0 482 static void mark_done(int cpu)
ian@0 483 {
ian@0 484 int i;
ian@0 485
ian@0 486 cpu_set(cpu, marked_cpus);
ian@0 487
ian@0 488 for_each_online_cpu(i) {
ian@0 489 if (!cpu_isset(i, marked_cpus))
ian@0 490 return;
ian@0 491 }
ian@0 492
ian@0 493 /* All CPUs have been processed at least once,
ian@0 494 * we can process the mortuary once
ian@0 495 */
ian@0 496 process_task_mortuary();
ian@0 497
ian@0 498 cpus_clear(marked_cpus);
ian@0 499 }
ian@0 500
ian@0 501
ian@0 502 /* FIXME: this is not sufficient if we implement syscall barrier backtrace
ian@0 503 * traversal, the code switch to sb_sample_start at first kernel enter/exit
ian@0 504 * switch so we need a fifth state and some special handling in sync_buffer()
ian@0 505 */
ian@0 506 typedef enum {
ian@0 507 sb_bt_ignore = -2,
ian@0 508 sb_buffer_start,
ian@0 509 sb_bt_start,
ian@0 510 sb_sample_start,
ian@0 511 } sync_buffer_state;
ian@0 512
ian@0 513 /* Sync one of the CPU's buffers into the global event buffer.
ian@0 514 * Here we need to go through each batch of samples punctuated
ian@0 515 * by context switch notes, taking the task's mmap_sem and doing
ian@0 516 * lookup in task->mm->mmap to convert EIP into dcookie/offset
ian@0 517 * value.
ian@0 518 */
ian@0 519 void sync_buffer(int cpu)
ian@0 520 {
ian@0 521 struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[cpu];
ian@0 522 struct mm_struct *mm = NULL;
ian@0 523 struct task_struct * new;
ian@0 524 unsigned long cookie = 0;
ian@15 525 int cpu_mode = 1;
ian@0 526 unsigned int i;
ian@0 527 sync_buffer_state state = sb_buffer_start;
ian@0 528 unsigned long available;
ian@15 529 int domain_switch = 0;
ian@0 530
ian@0 531 mutex_lock(&buffer_mutex);
ian@0 532
ian@0 533 add_cpu_switch(cpu);
ian@0 534
ian@15 535 /* We need to assign the first samples in this CPU buffer to the
ian@15 536 same domain that we were processing at the last sync_buffer */
ian@15 537 if (cpu_current_domain[cpu] != COORDINATOR_DOMAIN) {
ian@15 538 add_domain_switch(cpu_current_domain[cpu]);
ian@15 539 }
ian@0 540 /* Remember, only we can modify tail_pos */
ian@0 541
ian@0 542 available = get_slots(cpu_buf);
ian@0 543
ian@0 544 for (i = 0; i < available; ++i) {
ian@0 545 struct op_sample * s = &cpu_buf->buffer[cpu_buf->tail_pos];
ian@0 546
ian@15 547 if (is_code(s->eip) && !domain_switch) {
ian@15 548 if (s->event <= CPU_MODE_XEN) {
ian@15 549 /* xen/kernel/userspace switch */
ian@15 550 cpu_mode = s->event;
ian@0 551 if (state == sb_buffer_start)
ian@0 552 state = sb_sample_start;
ian@15 553 add_cpu_mode_switch(s->event);
ian@0 554 } else if (s->event == CPU_TRACE_BEGIN) {
ian@0 555 state = sb_bt_start;
ian@0 556 add_trace_begin();
ian@15 557 } else if (s->event == CPU_DOMAIN_SWITCH) {
ian@15 558 domain_switch = 1;
ian@0 559 } else {
ian@0 560 struct mm_struct * oldmm = mm;
ian@0 561
ian@0 562 /* userspace context switch */
ian@0 563 new = (struct task_struct *)s->event;
ian@0 564
ian@0 565 release_mm(oldmm);
ian@0 566 mm = take_tasks_mm(new);
ian@0 567 if (mm != oldmm)
ian@0 568 cookie = get_exec_dcookie(mm);
ian@0 569 add_user_ctx_switch(new, cookie);
ian@0 570 }
ian@0 571 } else {
ian@15 572 if (domain_switch) {
ian@15 573 cpu_current_domain[cpu] = s->eip;
ian@15 574 add_domain_switch(s->eip);
ian@15 575 domain_switch = 0;
ian@15 576 } else {
ian@15 577 if (cpu_current_domain[cpu] !=
ian@15 578 COORDINATOR_DOMAIN) {
ian@15 579 add_sample_entry(s->eip, s->event);
ian@15 580 }
ian@15 581 else if (state >= sb_bt_start &&
ian@15 582 !add_sample(mm, s, cpu_mode)) {
ian@15 583 if (state == sb_bt_start) {
ian@15 584 state = sb_bt_ignore;
ian@15 585 atomic_inc(&oprofile_stats.bt_lost_no_mapping);
ian@15 586 }
ian@0 587 }
ian@0 588 }
ian@0 589 }
ian@0 590
ian@0 591 increment_tail(cpu_buf);
ian@0 592 }
ian@0 593 release_mm(mm);
ian@0 594
ian@15 595 /* We reset domain to COORDINATOR at each CPU switch */
ian@15 596 if (cpu_current_domain[cpu] != COORDINATOR_DOMAIN) {
ian@15 597 add_domain_switch(COORDINATOR_DOMAIN);
ian@15 598 }
ian@15 599
ian@0 600 mark_done(cpu);
ian@0 601
ian@0 602 mutex_unlock(&buffer_mutex);
ian@0 603 }