Commit 526ea064f953fc5ad2fb905b537f490b9374a0f0

Authored by Linus Torvalds

Merge branch 'oprofile-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip

* 'oprofile-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
  oprofile: select RING_BUFFER
  ring_buffer: adding EXPORT_SYMBOLs
  oprofile: fix lost sample counter
  oprofile: remove nr_available_slots()
  oprofile: port to the new ring_buffer
  ring_buffer: add remaining cpu functions to ring_buffer.h
  oprofile: moving cpu_buffer_reset() to cpu_buffer.h
  oprofile: adding cpu_buffer_entries()
  oprofile: adding cpu_buffer_write_commit()
  oprofile: adding cpu buffer r/w access functions
  ftrace: remove unused function arg in trace_iterator_increment()
  ring_buffer: update description for ring_buffer_alloc()
  oprofile: set values to default when creating oprofilefs
  oprofile: implement switch/case in buffer_sync.c
  x86/oprofile: cleanup IBS init/exit functions in op_model_amd.c
  x86/oprofile: reordering IBS code in op_model_amd.c
  oprofile: fix typo
  oprofile: whitspace changes only
  oprofile: update comment for oprofile_add_sample()
  oprofile: comment cleanup

Showing 10 changed files Side-by-side Diff

... ... @@ -6,6 +6,8 @@
6 6 tristate "OProfile system profiling (EXPERIMENTAL)"
7 7 depends on PROFILING
8 8 depends on HAVE_OPROFILE
  9 + select TRACING
  10 + select RING_BUFFER
9 11 help
10 12 OProfile is a profiling system capable of profiling the
11 13 whole system, include the kernel, kernel modules, libraries,
arch/x86/oprofile/op_model_amd.c
... ... @@ -65,11 +65,13 @@
65 65 #define IBS_FETCH_BEGIN 3
66 66 #define IBS_OP_BEGIN 4
67 67  
68   -/* The function interface needs to be fixed, something like add
69   - data. Should then be added to linux/oprofile.h. */
  68 +/*
  69 + * The function interface needs to be fixed, something like add
  70 + * data. Should then be added to linux/oprofile.h.
  71 + */
70 72 extern void
71   -oprofile_add_ibs_sample(struct pt_regs *const regs,
72   - unsigned int *const ibs_sample, int ibs_code);
  73 +oprofile_add_ibs_sample(struct pt_regs * const regs,
  74 + unsigned int * const ibs_sample, int ibs_code);
73 75  
74 76 struct ibs_fetch_sample {
75 77 /* MSRC001_1031 IBS Fetch Linear Address Register */
... ... @@ -104,11 +106,6 @@
104 106 unsigned int ibs_dc_phys_high;
105 107 };
106 108  
107   -/*
108   - * unitialize the APIC for the IBS interrupts if needed on AMD Family10h+
109   -*/
110   -static void clear_ibs_nmi(void);
111   -
112 109 static int ibs_allowed; /* AMD Family10h and later */
113 110  
114 111 struct op_ibs_config {
... ... @@ -223,7 +220,7 @@
223 220 (unsigned int *)&ibs_fetch,
224 221 IBS_FETCH_BEGIN);
225 222  
226   - /*reenable the IRQ */
  223 + /* reenable the IRQ */
227 224 rdmsr(MSR_AMD64_IBSFETCHCTL, low, high);
228 225 high &= ~IBS_FETCH_HIGH_VALID_BIT;
229 226 high |= IBS_FETCH_HIGH_ENABLE;
... ... @@ -331,8 +328,10 @@
331 328 unsigned int low, high;
332 329 int i;
333 330  
334   - /* Subtle: stop on all counters to avoid race with
335   - * setting our pm callback */
  331 + /*
  332 + * Subtle: stop on all counters to avoid race with setting our
  333 + * pm callback
  334 + */
336 335 for (i = 0 ; i < NUM_COUNTERS ; ++i) {
337 336 if (!reset_value[i])
338 337 continue;
339 338  
... ... @@ -343,13 +342,15 @@
343 342  
344 343 #ifdef CONFIG_OPROFILE_IBS
345 344 if (ibs_allowed && ibs_config.fetch_enabled) {
346   - low = 0; /* clear max count and enable */
  345 + /* clear max count and enable */
  346 + low = 0;
347 347 high = 0;
348 348 wrmsr(MSR_AMD64_IBSFETCHCTL, low, high);
349 349 }
350 350  
351 351 if (ibs_allowed && ibs_config.op_enabled) {
352   - low = 0; /* clear max count and enable */
  352 + /* clear max count and enable */
  353 + low = 0;
353 354 high = 0;
354 355 wrmsr(MSR_AMD64_IBSOPCTL, low, high);
355 356 }
356 357  
... ... @@ -370,19 +371,8 @@
370 371 }
371 372 }
372 373  
373   -#ifndef CONFIG_OPROFILE_IBS
  374 +#ifdef CONFIG_OPROFILE_IBS
374 375  
375   -/* no IBS support */
376   -
377   -static int op_amd_init(struct oprofile_operations *ops)
378   -{
379   - return 0;
380   -}
381   -
382   -static void op_amd_exit(void) {}
383   -
384   -#else
385   -
386 376 static u8 ibs_eilvt_off;
387 377  
388 378 static inline void apic_init_ibs_nmi_per_cpu(void *arg)
... ... @@ -395,7 +385,7 @@
395 385 setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_FIX, 1);
396 386 }
397 387  
398   -static int pfm_amd64_setup_eilvt(void)
  388 +static int init_ibs_nmi(void)
399 389 {
400 390 #define IBSCTL_LVTOFFSETVAL (1 << 8)
401 391 #define IBSCTL 0x1cc
402 392  
403 393  
... ... @@ -443,18 +433,22 @@
443 433 return 0;
444 434 }
445 435  
446   -/*
447   - * initialize the APIC for the IBS interrupts
448   - * if available (AMD Family10h rev B0 and later)
449   - */
450   -static void setup_ibs(void)
  436 +/* uninitialize the APIC for the IBS interrupts if needed */
  437 +static void clear_ibs_nmi(void)
451 438 {
  439 + if (ibs_allowed)
  440 + on_each_cpu(apic_clear_ibs_nmi_per_cpu, NULL, 1);
  441 +}
  442 +
  443 +/* initialize the APIC for the IBS interrupts if available */
  444 +static void ibs_init(void)
  445 +{
452 446 ibs_allowed = boot_cpu_has(X86_FEATURE_IBS);
453 447  
454 448 if (!ibs_allowed)
455 449 return;
456 450  
457   - if (pfm_amd64_setup_eilvt()) {
  451 + if (init_ibs_nmi()) {
458 452 ibs_allowed = 0;
459 453 return;
460 454 }
461 455  
... ... @@ -462,14 +456,12 @@
462 456 printk(KERN_INFO "oprofile: AMD IBS detected\n");
463 457 }
464 458  
465   -
466   -/*
467   - * unitialize the APIC for the IBS interrupts if needed on AMD Family10h
468   - * rev B0 and later */
469   -static void clear_ibs_nmi(void)
  459 +static void ibs_exit(void)
470 460 {
471   - if (ibs_allowed)
472   - on_each_cpu(apic_clear_ibs_nmi_per_cpu, NULL, 1);
  461 + if (!ibs_allowed)
  462 + return;
  463 +
  464 + clear_ibs_nmi();
473 465 }
474 466  
475 467 static int (*create_arch_files)(struct super_block *sb, struct dentry *root);
... ... @@ -519,7 +511,7 @@
519 511  
520 512 static int op_amd_init(struct oprofile_operations *ops)
521 513 {
522   - setup_ibs();
  514 + ibs_init();
523 515 create_arch_files = ops->create_files;
524 516 ops->create_files = setup_ibs_files;
525 517 return 0;
526 518  
... ... @@ -527,10 +519,21 @@
527 519  
528 520 static void op_amd_exit(void)
529 521 {
530   - clear_ibs_nmi();
  522 + ibs_exit();
531 523 }
532 524  
533   -#endif
  525 +#else
  526 +
  527 +/* no IBS support */
  528 +
  529 +static int op_amd_init(struct oprofile_operations *ops)
  530 +{
  531 + return 0;
  532 +}
  533 +
  534 +static void op_amd_exit(void) {}
  535 +
  536 +#endif /* CONFIG_OPROFILE_IBS */
534 537  
535 538 struct op_x86_model_spec const op_amd_spec = {
536 539 .init = op_amd_init,
drivers/oprofile/buffer_sync.c
... ... @@ -268,18 +268,6 @@
268 268 return cookie;
269 269 }
270 270  
271   -static void increment_tail(struct oprofile_cpu_buffer *b)
272   -{
273   - unsigned long new_tail = b->tail_pos + 1;
274   -
275   - rmb(); /* be sure fifo pointers are synchromized */
276   -
277   - if (new_tail < b->buffer_size)
278   - b->tail_pos = new_tail;
279   - else
280   - b->tail_pos = 0;
281   -}
282   -
283 271 static unsigned long last_cookie = INVALID_COOKIE;
284 272  
285 273 static void add_cpu_switch(int i)
286 274  
287 275  
288 276  
289 277  
290 278  
... ... @@ -331,28 +319,25 @@
331 319  
332 320 #define IBS_FETCH_CODE_SIZE 2
333 321 #define IBS_OP_CODE_SIZE 5
334   -#define IBS_EIP(offset) \
335   - (((struct op_sample *)&cpu_buf->buffer[(offset)])->eip)
336   -#define IBS_EVENT(offset) \
337   - (((struct op_sample *)&cpu_buf->buffer[(offset)])->event)
338 322  
339 323 /*
340 324 * Add IBS fetch and op entries to event buffer
341 325 */
342   -static void add_ibs_begin(struct oprofile_cpu_buffer *cpu_buf, int code,
343   - struct mm_struct *mm)
  326 +static void add_ibs_begin(int cpu, int code, struct mm_struct *mm)
344 327 {
345 328 unsigned long rip;
346 329 int i, count;
347 330 unsigned long ibs_cookie = 0;
348 331 off_t offset;
  332 + struct op_sample *sample;
349 333  
350   - increment_tail(cpu_buf); /* move to RIP entry */
  334 + sample = cpu_buffer_read_entry(cpu);
  335 + if (!sample)
  336 + goto Error;
  337 + rip = sample->eip;
351 338  
352   - rip = IBS_EIP(cpu_buf->tail_pos);
353   -
354 339 #ifdef __LP64__
355   - rip += IBS_EVENT(cpu_buf->tail_pos) << 32;
  340 + rip += sample->event << 32;
356 341 #endif
357 342  
358 343 if (mm) {
... ... @@ -376,8 +361,8 @@
376 361 add_event_entry(offset); /* Offset from Dcookie */
377 362  
378 363 /* we send the Dcookie offset, but send the raw Linear Add also*/
379   - add_event_entry(IBS_EIP(cpu_buf->tail_pos));
380   - add_event_entry(IBS_EVENT(cpu_buf->tail_pos));
  364 + add_event_entry(sample->eip);
  365 + add_event_entry(sample->event);
381 366  
382 367 if (code == IBS_FETCH_CODE)
383 368 count = IBS_FETCH_CODE_SIZE; /*IBS FETCH is 2 int64s*/
384 369  
... ... @@ -385,10 +370,17 @@
385 370 count = IBS_OP_CODE_SIZE; /*IBS OP is 5 int64s*/
386 371  
387 372 for (i = 0; i < count; i++) {
388   - increment_tail(cpu_buf);
389   - add_event_entry(IBS_EIP(cpu_buf->tail_pos));
390   - add_event_entry(IBS_EVENT(cpu_buf->tail_pos));
  373 + sample = cpu_buffer_read_entry(cpu);
  374 + if (!sample)
  375 + goto Error;
  376 + add_event_entry(sample->eip);
  377 + add_event_entry(sample->event);
391 378 }
  379 +
  380 + return;
  381 +
  382 +Error:
  383 + return;
392 384 }
393 385  
394 386 #endif
... ... @@ -466,33 +458,6 @@
466 458 }
467 459  
468 460  
469   -/* "acquire" as many cpu buffer slots as we can */
470   -static unsigned long get_slots(struct oprofile_cpu_buffer *b)
471   -{
472   - unsigned long head = b->head_pos;
473   - unsigned long tail = b->tail_pos;
474   -
475   - /*
476   - * Subtle. This resets the persistent last_task
477   - * and in_kernel values used for switching notes.
478   - * BUT, there is a small window between reading
479   - * head_pos, and this call, that means samples
480   - * can appear at the new head position, but not
481   - * be prefixed with the notes for switching
482   - * kernel mode or a task switch. This small hole
483   - * can lead to mis-attribution or samples where
484   - * we don't know if it's in the kernel or not,
485   - * at the start of an event buffer.
486   - */
487   - cpu_buffer_reset(b);
488   -
489   - if (head >= tail)
490   - return head - tail;
491   -
492   - return head + (b->buffer_size - tail);
493   -}
494   -
495   -
496 461 /* Move tasks along towards death. Any tasks on dead_tasks
497 462 * will definitely have no remaining references in any
498 463 * CPU buffers at this point, because we use two lists,
499 464  
500 465  
501 466  
502 467  
503 468  
504 469  
505 470  
506 471  
507 472  
508 473  
509 474  
510 475  
511 476  
512 477  
513 478  
514 479  
... ... @@ -559,61 +524,61 @@
559 524 */
560 525 void sync_buffer(int cpu)
561 526 {
562   - struct oprofile_cpu_buffer *cpu_buf = &per_cpu(cpu_buffer, cpu);
563 527 struct mm_struct *mm = NULL;
  528 + struct mm_struct *oldmm;
564 529 struct task_struct *new;
565 530 unsigned long cookie = 0;
566 531 int in_kernel = 1;
567 532 sync_buffer_state state = sb_buffer_start;
568   -#ifndef CONFIG_OPROFILE_IBS
569 533 unsigned int i;
570 534 unsigned long available;
571   -#endif
572 535  
573 536 mutex_lock(&buffer_mutex);
574 537  
575 538 add_cpu_switch(cpu);
576 539  
577   - /* Remember, only we can modify tail_pos */
  540 + cpu_buffer_reset(cpu);
  541 + available = cpu_buffer_entries(cpu);
578 542  
579   -#ifndef CONFIG_OPROFILE_IBS
580   - available = get_slots(cpu_buf);
581   -
582 543 for (i = 0; i < available; ++i) {
583   -#else
584   - while (get_slots(cpu_buf)) {
585   -#endif
586   - struct op_sample *s = &cpu_buf->buffer[cpu_buf->tail_pos];
  544 + struct op_sample *s = cpu_buffer_read_entry(cpu);
  545 + if (!s)
  546 + break;
587 547  
588 548 if (is_code(s->eip)) {
589   - if (s->event <= CPU_IS_KERNEL) {
  549 + switch (s->event) {
  550 + case 0:
  551 + case CPU_IS_KERNEL:
590 552 /* kernel/userspace switch */
591 553 in_kernel = s->event;
592 554 if (state == sb_buffer_start)
593 555 state = sb_sample_start;
594 556 add_kernel_ctx_switch(s->event);
595   - } else if (s->event == CPU_TRACE_BEGIN) {
  557 + break;
  558 + case CPU_TRACE_BEGIN:
596 559 state = sb_bt_start;
597 560 add_trace_begin();
  561 + break;
598 562 #ifdef CONFIG_OPROFILE_IBS
599   - } else if (s->event == IBS_FETCH_BEGIN) {
  563 + case IBS_FETCH_BEGIN:
600 564 state = sb_bt_start;
601   - add_ibs_begin(cpu_buf, IBS_FETCH_CODE, mm);
602   - } else if (s->event == IBS_OP_BEGIN) {
  565 + add_ibs_begin(cpu, IBS_FETCH_CODE, mm);
  566 + break;
  567 + case IBS_OP_BEGIN:
603 568 state = sb_bt_start;
604   - add_ibs_begin(cpu_buf, IBS_OP_CODE, mm);
  569 + add_ibs_begin(cpu, IBS_OP_CODE, mm);
  570 + break;
605 571 #endif
606   - } else {
607   - struct mm_struct *oldmm = mm;
608   -
  572 + default:
609 573 /* userspace context switch */
  574 + oldmm = mm;
610 575 new = (struct task_struct *)s->event;
611   -
612 576 release_mm(oldmm);
613 577 mm = take_tasks_mm(new);
614 578 if (mm != oldmm)
615 579 cookie = get_exec_dcookie(mm);
616 580 add_user_ctx_switch(new, cookie);
  581 + break;
617 582 }
618 583 } else if (state >= sb_bt_start &&
619 584 !add_sample(mm, s, in_kernel)) {
... ... @@ -622,8 +587,6 @@
622 587 atomic_inc(&oprofile_stats.bt_lost_no_mapping);
623 588 }
624 589 }
625   -
626   - increment_tail(cpu_buf);
627 590 }
628 591 release_mm(mm);
629 592  
drivers/oprofile/cpu_buffer.c
... ... @@ -28,6 +28,25 @@
28 28 #include "buffer_sync.h"
29 29 #include "oprof.h"
30 30  
  31 +#define OP_BUFFER_FLAGS 0
  32 +
  33 +/*
  34 + * Read and write access is using spin locking. Thus, writing to the
  35 + * buffer by NMI handler (x86) could occur also during critical
  36 + * sections when reading the buffer. To avoid this, there are 2
  37 + * buffers for independent read and write access. Read access is in
  38 + * process context only, write access only in the NMI handler. If the
  39 + * read buffer runs empty, both buffers are swapped atomically. There
  40 + * is potentially a small window during swapping where the buffers are
  41 + * disabled and samples could be lost.
  42 + *
  43 + * Using 2 buffers is a little bit overhead, but the solution is clear
  44 + * and does not require changes in the ring buffer implementation. It
  45 + * can be changed to a single buffer solution when the ring buffer
  46 + * access is implemented as non-locking atomic code.
  47 + */
  48 +struct ring_buffer *op_ring_buffer_read;
  49 +struct ring_buffer *op_ring_buffer_write;
31 50 DEFINE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer);
32 51  
33 52 static void wq_sync_buffer(struct work_struct *work);
... ... @@ -37,12 +56,12 @@
37 56  
38 57 void free_cpu_buffers(void)
39 58 {
40   - int i;
41   -
42   - for_each_possible_cpu(i) {
43   - vfree(per_cpu(cpu_buffer, i).buffer);
44   - per_cpu(cpu_buffer, i).buffer = NULL;
45   - }
  59 + if (op_ring_buffer_read)
  60 + ring_buffer_free(op_ring_buffer_read);
  61 + op_ring_buffer_read = NULL;
  62 + if (op_ring_buffer_write)
  63 + ring_buffer_free(op_ring_buffer_write);
  64 + op_ring_buffer_write = NULL;
46 65 }
47 66  
48 67 unsigned long oprofile_get_cpu_buffer_size(void)
49 68  
... ... @@ -64,14 +83,16 @@
64 83  
65 84 unsigned long buffer_size = fs_cpu_buffer_size;
66 85  
  86 + op_ring_buffer_read = ring_buffer_alloc(buffer_size, OP_BUFFER_FLAGS);
  87 + if (!op_ring_buffer_read)
  88 + goto fail;
  89 + op_ring_buffer_write = ring_buffer_alloc(buffer_size, OP_BUFFER_FLAGS);
  90 + if (!op_ring_buffer_write)
  91 + goto fail;
  92 +
67 93 for_each_possible_cpu(i) {
68 94 struct oprofile_cpu_buffer *b = &per_cpu(cpu_buffer, i);
69 95  
70   - b->buffer = vmalloc_node(sizeof(struct op_sample) * buffer_size,
71   - cpu_to_node(i));
72   - if (!b->buffer)
73   - goto fail;
74   -
75 96 b->last_task = NULL;
76 97 b->last_is_kernel = -1;
77 98 b->tracing = 0;
78 99  
79 100  
80 101  
81 102  
82 103  
83 104  
84 105  
... ... @@ -124,57 +145,31 @@
124 145 flush_scheduled_work();
125 146 }
126 147  
127   -/* Resets the cpu buffer to a sane state. */
128   -void cpu_buffer_reset(struct oprofile_cpu_buffer *cpu_buf)
  148 +static inline int
  149 +add_sample(struct oprofile_cpu_buffer *cpu_buf,
  150 + unsigned long pc, unsigned long event)
129 151 {
130   - /* reset these to invalid values; the next sample
131   - * collected will populate the buffer with proper
132   - * values to initialize the buffer
133   - */
134   - cpu_buf->last_is_kernel = -1;
135   - cpu_buf->last_task = NULL;
136   -}
  152 + struct op_entry entry;
  153 + int ret;
137 154  
138   -/* compute number of available slots in cpu_buffer queue */
139   -static unsigned long nr_available_slots(struct oprofile_cpu_buffer const *b)
140   -{
141   - unsigned long head = b->head_pos;
142   - unsigned long tail = b->tail_pos;
  155 + ret = cpu_buffer_write_entry(&entry);
  156 + if (ret)
  157 + return ret;
143 158  
144   - if (tail > head)
145   - return (tail - head) - 1;
  159 + entry.sample->eip = pc;
  160 + entry.sample->event = event;
146 161  
147   - return tail + (b->buffer_size - head) - 1;
148   -}
  162 + ret = cpu_buffer_write_commit(&entry);
  163 + if (ret)
  164 + return ret;
149 165  
150   -static void increment_head(struct oprofile_cpu_buffer *b)
151   -{
152   - unsigned long new_head = b->head_pos + 1;
153   -
154   - /* Ensure anything written to the slot before we
155   - * increment is visible */
156   - wmb();
157   -
158   - if (new_head < b->buffer_size)
159   - b->head_pos = new_head;
160   - else
161   - b->head_pos = 0;
  166 + return 0;
162 167 }
163 168  
164   -static inline void
165   -add_sample(struct oprofile_cpu_buffer *cpu_buf,
166   - unsigned long pc, unsigned long event)
167   -{
168   - struct op_sample *entry = &cpu_buf->buffer[cpu_buf->head_pos];
169   - entry->eip = pc;
170   - entry->event = event;
171   - increment_head(cpu_buf);
172   -}
173   -
174   -static inline void
  169 +static inline int
175 170 add_code(struct oprofile_cpu_buffer *buffer, unsigned long value)
176 171 {
177   - add_sample(buffer, ESCAPE_CODE, value);
  172 + return add_sample(buffer, ESCAPE_CODE, value);
178 173 }
179 174  
180 175 /* This must be safe from any context. It's safe writing here
... ... @@ -198,11 +193,6 @@
198 193 return 0;
199 194 }
200 195  
201   - if (nr_available_slots(cpu_buf) < 3) {
202   - cpu_buf->sample_lost_overflow++;
203   - return 0;
204   - }
205   -
206 196 is_kernel = !!is_kernel;
207 197  
208 198 task = current;
209 199  
210 200  
211 201  
212 202  
... ... @@ -210,26 +200,29 @@
210 200 /* notice a switch from user->kernel or vice versa */
211 201 if (cpu_buf->last_is_kernel != is_kernel) {
212 202 cpu_buf->last_is_kernel = is_kernel;
213   - add_code(cpu_buf, is_kernel);
  203 + if (add_code(cpu_buf, is_kernel))
  204 + goto fail;
214 205 }
215 206  
216 207 /* notice a task switch */
217 208 if (cpu_buf->last_task != task) {
218 209 cpu_buf->last_task = task;
219   - add_code(cpu_buf, (unsigned long)task);
  210 + if (add_code(cpu_buf, (unsigned long)task))
  211 + goto fail;
220 212 }
221 213  
222   - add_sample(cpu_buf, pc, event);
  214 + if (add_sample(cpu_buf, pc, event))
  215 + goto fail;
  216 +
223 217 return 1;
  218 +
  219 +fail:
  220 + cpu_buf->sample_lost_overflow++;
  221 + return 0;
224 222 }
225 223  
226 224 static int oprofile_begin_trace(struct oprofile_cpu_buffer *cpu_buf)
227 225 {
228   - if (nr_available_slots(cpu_buf) < 4) {
229   - cpu_buf->sample_lost_overflow++;
230   - return 0;
231   - }
232   -
233 226 add_code(cpu_buf, CPU_TRACE_BEGIN);
234 227 cpu_buf->tracing = 1;
235 228 return 1;
... ... @@ -253,8 +246,10 @@
253 246 if (!oprofile_begin_trace(cpu_buf))
254 247 return;
255 248  
256   - /* if log_sample() fail we can't backtrace since we lost the source
257   - * of this event */
  249 + /*
  250 + * if log_sample() fail we can't backtrace since we lost the
  251 + * source of this event
  252 + */
258 253 if (log_sample(cpu_buf, pc, is_kernel, event))
259 254 oprofile_ops.backtrace(regs, backtrace_depth);
260 255 oprofile_end_trace(cpu_buf);
261 256  
262 257  
263 258  
264 259  
265 260  
266 261  
267 262  
268 263  
269 264  
270 265  
... ... @@ -272,49 +267,55 @@
272 267  
273 268 #define MAX_IBS_SAMPLE_SIZE 14
274 269  
275   -void oprofile_add_ibs_sample(struct pt_regs *const regs,
276   - unsigned int *const ibs_sample, int ibs_code)
  270 +void oprofile_add_ibs_sample(struct pt_regs * const regs,
  271 + unsigned int * const ibs_sample, int ibs_code)
277 272 {
278 273 int is_kernel = !user_mode(regs);
279 274 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer);
280 275 struct task_struct *task;
  276 + int fail = 0;
281 277  
282 278 cpu_buf->sample_received++;
283 279  
284   - if (nr_available_slots(cpu_buf) < MAX_IBS_SAMPLE_SIZE) {
285   - /* we can't backtrace since we lost the source of this event */
286   - cpu_buf->sample_lost_overflow++;
287   - return;
288   - }
289   -
290 280 /* notice a switch from user->kernel or vice versa */
291 281 if (cpu_buf->last_is_kernel != is_kernel) {
  282 + if (add_code(cpu_buf, is_kernel))
  283 + goto fail;
292 284 cpu_buf->last_is_kernel = is_kernel;
293   - add_code(cpu_buf, is_kernel);
294 285 }
295 286  
296 287 /* notice a task switch */
297 288 if (!is_kernel) {
298 289 task = current;
299 290 if (cpu_buf->last_task != task) {
  291 + if (add_code(cpu_buf, (unsigned long)task))
  292 + goto fail;
300 293 cpu_buf->last_task = task;
301   - add_code(cpu_buf, (unsigned long)task);
302 294 }
303 295 }
304 296  
305   - add_code(cpu_buf, ibs_code);
306   - add_sample(cpu_buf, ibs_sample[0], ibs_sample[1]);
307   - add_sample(cpu_buf, ibs_sample[2], ibs_sample[3]);
308   - add_sample(cpu_buf, ibs_sample[4], ibs_sample[5]);
  297 + fail = fail || add_code(cpu_buf, ibs_code);
  298 + fail = fail || add_sample(cpu_buf, ibs_sample[0], ibs_sample[1]);
  299 + fail = fail || add_sample(cpu_buf, ibs_sample[2], ibs_sample[3]);
  300 + fail = fail || add_sample(cpu_buf, ibs_sample[4], ibs_sample[5]);
309 301  
310 302 if (ibs_code == IBS_OP_BEGIN) {
311   - add_sample(cpu_buf, ibs_sample[6], ibs_sample[7]);
312   - add_sample(cpu_buf, ibs_sample[8], ibs_sample[9]);
313   - add_sample(cpu_buf, ibs_sample[10], ibs_sample[11]);
  303 + fail = fail || add_sample(cpu_buf, ibs_sample[6], ibs_sample[7]);
  304 + fail = fail || add_sample(cpu_buf, ibs_sample[8], ibs_sample[9]);
  305 + fail = fail || add_sample(cpu_buf, ibs_sample[10], ibs_sample[11]);
314 306 }
315 307  
  308 + if (fail)
  309 + goto fail;
  310 +
316 311 if (backtrace_depth)
317 312 oprofile_ops.backtrace(regs, backtrace_depth);
  313 +
  314 + return;
  315 +
  316 +fail:
  317 + cpu_buf->sample_lost_overflow++;
  318 + return;
318 319 }
319 320  
320 321 #endif
321 322  
322 323  
... ... @@ -332,21 +333,21 @@
332 333 if (!cpu_buf->tracing)
333 334 return;
334 335  
335   - if (nr_available_slots(cpu_buf) < 1) {
336   - cpu_buf->tracing = 0;
337   - cpu_buf->sample_lost_overflow++;
338   - return;
339   - }
  336 + /*
  337 + * broken frame can give an eip with the same value as an
  338 + * escape code, abort the trace if we get it
  339 + */
  340 + if (pc == ESCAPE_CODE)
  341 + goto fail;
340 342  
341   - /* broken frame can give an eip with the same value as an escape code,
342   - * abort the trace if we get it */
343   - if (pc == ESCAPE_CODE) {
344   - cpu_buf->tracing = 0;
345   - cpu_buf->backtrace_aborted++;
346   - return;
347   - }
  343 + if (add_sample(cpu_buf, pc, 0))
  344 + goto fail;
348 345  
349   - add_sample(cpu_buf, pc, 0);
  346 + return;
  347 +fail:
  348 + cpu_buf->tracing = 0;
  349 + cpu_buf->backtrace_aborted++;
  350 + return;
350 351 }
351 352  
352 353 /*
drivers/oprofile/cpu_buffer.h
... ... @@ -15,6 +15,7 @@
15 15 #include <linux/workqueue.h>
16 16 #include <linux/cache.h>
17 17 #include <linux/sched.h>
  18 +#include <linux/ring_buffer.h>
18 19  
19 20 struct task_struct;
20 21  
... ... @@ -32,6 +33,12 @@
32 33 unsigned long event;
33 34 };
34 35  
  36 +struct op_entry {
  37 + struct ring_buffer_event *event;
  38 + struct op_sample *sample;
  39 + unsigned long irq_flags;
  40 +};
  41 +
35 42 struct oprofile_cpu_buffer {
36 43 volatile unsigned long head_pos;
37 44 volatile unsigned long tail_pos;
... ... @@ -39,7 +46,6 @@
39 46 struct task_struct *last_task;
40 47 int last_is_kernel;
41 48 int tracing;
42   - struct op_sample *buffer;
43 49 unsigned long sample_received;
44 50 unsigned long sample_lost_overflow;
45 51 unsigned long backtrace_aborted;
46 52  
... ... @@ -48,9 +54,68 @@
48 54 struct delayed_work work;
49 55 };
50 56  
  57 +extern struct ring_buffer *op_ring_buffer_read;
  58 +extern struct ring_buffer *op_ring_buffer_write;
51 59 DECLARE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer);
52 60  
53   -void cpu_buffer_reset(struct oprofile_cpu_buffer *cpu_buf);
  61 +/*
  62 + * Resets the cpu buffer to a sane state.
  63 + *
  64 + * reset these to invalid values; the next sample collected will
  65 + * populate the buffer with proper values to initialize the buffer
  66 + */
  67 +static inline void cpu_buffer_reset(int cpu)
  68 +{
  69 + struct oprofile_cpu_buffer *cpu_buf = &per_cpu(cpu_buffer, cpu);
  70 +
  71 + cpu_buf->last_is_kernel = -1;
  72 + cpu_buf->last_task = NULL;
  73 +}
  74 +
  75 +static inline int cpu_buffer_write_entry(struct op_entry *entry)
  76 +{
  77 + entry->event = ring_buffer_lock_reserve(op_ring_buffer_write,
  78 + sizeof(struct op_sample),
  79 + &entry->irq_flags);
  80 + if (entry->event)
  81 + entry->sample = ring_buffer_event_data(entry->event);
  82 + else
  83 + entry->sample = NULL;
  84 +
  85 + if (!entry->sample)
  86 + return -ENOMEM;
  87 +
  88 + return 0;
  89 +}
  90 +
  91 +static inline int cpu_buffer_write_commit(struct op_entry *entry)
  92 +{
  93 + return ring_buffer_unlock_commit(op_ring_buffer_write, entry->event,
  94 + entry->irq_flags);
  95 +}
  96 +
  97 +static inline struct op_sample *cpu_buffer_read_entry(int cpu)
  98 +{
  99 + struct ring_buffer_event *e;
  100 + e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL);
  101 + if (e)
  102 + return ring_buffer_event_data(e);
  103 + if (ring_buffer_swap_cpu(op_ring_buffer_read,
  104 + op_ring_buffer_write,
  105 + cpu))
  106 + return NULL;
  107 + e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL);
  108 + if (e)
  109 + return ring_buffer_event_data(e);
  110 + return NULL;
  111 +}
  112 +
  113 +/* "acquire" as many cpu buffer slots as we can */
  114 +static inline unsigned long cpu_buffer_entries(int cpu)
  115 +{
  116 + return ring_buffer_entries_cpu(op_ring_buffer_read, cpu)
  117 + + ring_buffer_entries_cpu(op_ring_buffer_write, cpu);
  118 +}
54 119  
55 120 /* transient events for the CPU buffer -> event buffer */
56 121 #define CPU_IS_KERNEL 1
drivers/oprofile/oprofile_files.c
... ... @@ -14,10 +14,14 @@
14 14 #include "oprofile_stats.h"
15 15 #include "oprof.h"
16 16  
17   -unsigned long fs_buffer_size = 131072;
18   -unsigned long fs_cpu_buffer_size = 8192;
19   -unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
  17 +#define FS_BUFFER_SIZE_DEFAULT 131072
  18 +#define FS_CPU_BUFFER_SIZE_DEFAULT 8192
  19 +#define FS_BUFFER_WATERSHED_DEFAULT 32768 /* FIXME: tune */
20 20  
  21 +unsigned long fs_buffer_size;
  22 +unsigned long fs_cpu_buffer_size;
  23 +unsigned long fs_buffer_watershed;
  24 +
21 25 static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
22 26 {
23 27 return oprofilefs_ulong_to_user(backtrace_depth, buf, count, offset);
... ... @@ -120,6 +124,11 @@
120 124  
121 125 void oprofile_create_files(struct super_block *sb, struct dentry *root)
122 126 {
  127 + /* reinitialize default values */
  128 + fs_buffer_size = FS_BUFFER_SIZE_DEFAULT;
  129 + fs_cpu_buffer_size = FS_CPU_BUFFER_SIZE_DEFAULT;
  130 + fs_buffer_watershed = FS_BUFFER_WATERSHED_DEFAULT;
  131 +
123 132 oprofilefs_create_file(sb, root, "enable", &enable_fops);
124 133 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
125 134 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
include/linux/oprofile.h
... ... @@ -86,8 +86,7 @@
86 86 void oprofile_arch_exit(void);
87 87  
88 88 /**
89   - * Add a sample. This may be called from any context. Pass
90   - * smp_processor_id() as cpu.
  89 + * Add a sample. This may be called from any context.
91 90 */
92 91 void oprofile_add_sample(struct pt_regs * const regs, unsigned long event);
93 92  
include/linux/ring_buffer.h
... ... @@ -118,6 +118,8 @@
118 118  
119 119 unsigned long ring_buffer_entries(struct ring_buffer *buffer);
120 120 unsigned long ring_buffer_overruns(struct ring_buffer *buffer);
  121 +unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu);
  122 +unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu);
121 123  
122 124 u64 ring_buffer_time_stamp(int cpu);
123 125 void ring_buffer_normalize_time_stamp(int cpu, u64 *ts);
kernel/trace/ring_buffer.c
... ... @@ -69,6 +69,7 @@
69 69 {
70 70 set_bit(RB_BUFFERS_ON_BIT, &ring_buffer_flags);
71 71 }
  72 +EXPORT_SYMBOL_GPL(tracing_on);
72 73  
73 74 /**
74 75 * tracing_off - turn off all tracing buffers
... ... @@ -82,6 +83,7 @@
82 83 {
83 84 clear_bit(RB_BUFFERS_ON_BIT, &ring_buffer_flags);
84 85 }
  86 +EXPORT_SYMBOL_GPL(tracing_off);
85 87  
86 88 /**
87 89 * tracing_off_permanent - permanently disable ring buffers
88 90  
... ... @@ -111,12 +113,14 @@
111 113  
112 114 return time;
113 115 }
  116 +EXPORT_SYMBOL_GPL(ring_buffer_time_stamp);
114 117  
115 118 void ring_buffer_normalize_time_stamp(int cpu, u64 *ts)
116 119 {
117 120 /* Just stupid testing the normalize function and deltas */
118 121 *ts >>= DEBUG_SHIFT;
119 122 }
  123 +EXPORT_SYMBOL_GPL(ring_buffer_normalize_time_stamp);
120 124  
121 125 #define RB_EVNT_HDR_SIZE (sizeof(struct ring_buffer_event))
122 126 #define RB_ALIGNMENT_SHIFT 2
... ... @@ -166,6 +170,7 @@
166 170 {
167 171 return rb_event_length(event);
168 172 }
  173 +EXPORT_SYMBOL_GPL(ring_buffer_event_length);
169 174  
170 175 /* inline for ring buffer fast paths */
171 176 static inline void *
... ... @@ -187,6 +192,7 @@
187 192 {
188 193 return rb_event_data(event);
189 194 }
  195 +EXPORT_SYMBOL_GPL(ring_buffer_event_data);
190 196  
191 197 #define for_each_buffer_cpu(buffer, cpu) \
192 198 for_each_cpu_mask(cpu, buffer->cpumask)
... ... @@ -427,7 +433,7 @@
427 433  
428 434 /**
429 435 * ring_buffer_alloc - allocate a new ring_buffer
430   - * @size: the size in bytes that is needed.
  436 + * @size: the size in bytes per cpu that is needed.
431 437 * @flags: attributes to set for the ring buffer.
432 438 *
433 439 * Currently the only flag that is available is the RB_FL_OVERWRITE
... ... @@ -490,6 +496,7 @@
490 496 kfree(buffer);
491 497 return NULL;
492 498 }
  499 +EXPORT_SYMBOL_GPL(ring_buffer_alloc);
493 500  
494 501 /**
495 502 * ring_buffer_free - free a ring buffer.
... ... @@ -505,6 +512,7 @@
505 512  
506 513 kfree(buffer);
507 514 }
  515 +EXPORT_SYMBOL_GPL(ring_buffer_free);
508 516  
509 517 static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
510 518  
... ... @@ -680,6 +688,7 @@
680 688 mutex_unlock(&buffer->mutex);
681 689 return -ENOMEM;
682 690 }
  691 +EXPORT_SYMBOL_GPL(ring_buffer_resize);
683 692  
684 693 static inline int rb_null_event(struct ring_buffer_event *event)
685 694 {
... ... @@ -1304,6 +1313,7 @@
1304 1313 ftrace_preempt_enable(resched);
1305 1314 return NULL;
1306 1315 }
  1316 +EXPORT_SYMBOL_GPL(ring_buffer_lock_reserve);
1307 1317  
1308 1318 static void rb_commit(struct ring_buffer_per_cpu *cpu_buffer,
1309 1319 struct ring_buffer_event *event)
... ... @@ -1350,6 +1360,7 @@
1350 1360  
1351 1361 return 0;
1352 1362 }
  1363 +EXPORT_SYMBOL_GPL(ring_buffer_unlock_commit);
1353 1364  
1354 1365 /**
1355 1366 * ring_buffer_write - write data to the buffer without reserving
... ... @@ -1411,6 +1422,7 @@
1411 1422  
1412 1423 return ret;
1413 1424 }
  1425 +EXPORT_SYMBOL_GPL(ring_buffer_write);
1414 1426  
1415 1427 static inline int rb_per_cpu_empty(struct ring_buffer_per_cpu *cpu_buffer)
1416 1428 {
... ... @@ -1437,6 +1449,7 @@
1437 1449 {
1438 1450 atomic_inc(&buffer->record_disabled);
1439 1451 }
  1452 +EXPORT_SYMBOL_GPL(ring_buffer_record_disable);
1440 1453  
1441 1454 /**
1442 1455 * ring_buffer_record_enable - enable writes to the buffer
... ... @@ -1449,6 +1462,7 @@
1449 1462 {
1450 1463 atomic_dec(&buffer->record_disabled);
1451 1464 }
  1465 +EXPORT_SYMBOL_GPL(ring_buffer_record_enable);
1452 1466  
1453 1467 /**
1454 1468 * ring_buffer_record_disable_cpu - stop all writes into the cpu_buffer
... ... @@ -1470,6 +1484,7 @@
1470 1484 cpu_buffer = buffer->buffers[cpu];
1471 1485 atomic_inc(&cpu_buffer->record_disabled);
1472 1486 }
  1487 +EXPORT_SYMBOL_GPL(ring_buffer_record_disable_cpu);
1473 1488  
1474 1489 /**
1475 1490 * ring_buffer_record_enable_cpu - enable writes to the buffer
... ... @@ -1489,6 +1504,7 @@
1489 1504 cpu_buffer = buffer->buffers[cpu];
1490 1505 atomic_dec(&cpu_buffer->record_disabled);
1491 1506 }
  1507 +EXPORT_SYMBOL_GPL(ring_buffer_record_enable_cpu);
1492 1508  
1493 1509 /**
1494 1510 * ring_buffer_entries_cpu - get the number of entries in a cpu buffer
... ... @@ -1505,6 +1521,7 @@
1505 1521 cpu_buffer = buffer->buffers[cpu];
1506 1522 return cpu_buffer->entries;
1507 1523 }
  1524 +EXPORT_SYMBOL_GPL(ring_buffer_entries_cpu);
1508 1525  
1509 1526 /**
1510 1527 * ring_buffer_overrun_cpu - get the number of overruns in a cpu_buffer
... ... @@ -1521,6 +1538,7 @@
1521 1538 cpu_buffer = buffer->buffers[cpu];
1522 1539 return cpu_buffer->overrun;
1523 1540 }
  1541 +EXPORT_SYMBOL_GPL(ring_buffer_overrun_cpu);
1524 1542  
1525 1543 /**
1526 1544 * ring_buffer_entries - get the number of entries in a buffer
... ... @@ -1543,6 +1561,7 @@
1543 1561  
1544 1562 return entries;
1545 1563 }
  1564 +EXPORT_SYMBOL_GPL(ring_buffer_entries);
1546 1565  
1547 1566 /**
1548 1567 * ring_buffer_overrun_cpu - get the number of overruns in buffer
... ... @@ -1565,6 +1584,7 @@
1565 1584  
1566 1585 return overruns;
1567 1586 }
  1587 +EXPORT_SYMBOL_GPL(ring_buffer_overruns);
1568 1588  
1569 1589 static void rb_iter_reset(struct ring_buffer_iter *iter)
1570 1590 {
... ... @@ -1600,6 +1620,7 @@
1600 1620 rb_iter_reset(iter);
1601 1621 spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
1602 1622 }
  1623 +EXPORT_SYMBOL_GPL(ring_buffer_iter_reset);
1603 1624  
1604 1625 /**
1605 1626 * ring_buffer_iter_empty - check if an iterator has no more to read
... ... @@ -1614,6 +1635,7 @@
1614 1635 return iter->head_page == cpu_buffer->commit_page &&
1615 1636 iter->head == rb_commit_index(cpu_buffer);
1616 1637 }
  1638 +EXPORT_SYMBOL_GPL(ring_buffer_iter_empty);
1617 1639  
1618 1640 static void
1619 1641 rb_update_read_stamp(struct ring_buffer_per_cpu *cpu_buffer,
... ... @@ -1880,6 +1902,7 @@
1880 1902  
1881 1903 return NULL;
1882 1904 }
  1905 +EXPORT_SYMBOL_GPL(ring_buffer_peek);
1883 1906  
1884 1907 static struct ring_buffer_event *
1885 1908 rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
... ... @@ -1940,6 +1963,7 @@
1940 1963  
1941 1964 return NULL;
1942 1965 }
  1966 +EXPORT_SYMBOL_GPL(ring_buffer_iter_peek);
1943 1967  
1944 1968 /**
1945 1969 * ring_buffer_peek - peek at the next event to be read
... ... @@ -2017,6 +2041,7 @@
2017 2041  
2018 2042 return event;
2019 2043 }
  2044 +EXPORT_SYMBOL_GPL(ring_buffer_consume);
2020 2045  
2021 2046 /**
2022 2047 * ring_buffer_read_start - start a non consuming read of the buffer
... ... @@ -2059,6 +2084,7 @@
2059 2084  
2060 2085 return iter;
2061 2086 }
  2087 +EXPORT_SYMBOL_GPL(ring_buffer_read_start);
2062 2088  
2063 2089 /**
2064 2090 * ring_buffer_finish - finish reading the iterator of the buffer
... ... @@ -2075,6 +2101,7 @@
2075 2101 atomic_dec(&cpu_buffer->record_disabled);
2076 2102 kfree(iter);
2077 2103 }
  2104 +EXPORT_SYMBOL_GPL(ring_buffer_read_finish);
2078 2105  
2079 2106 /**
2080 2107 * ring_buffer_read - read the next item in the ring buffer by the iterator
... ... @@ -2101,6 +2128,7 @@
2101 2128  
2102 2129 return event;
2103 2130 }
  2131 +EXPORT_SYMBOL_GPL(ring_buffer_read);
2104 2132  
2105 2133 /**
2106 2134 * ring_buffer_size - return the size of the ring buffer (in bytes)
... ... @@ -2110,6 +2138,7 @@
2110 2138 {
2111 2139 return BUF_PAGE_SIZE * buffer->pages;
2112 2140 }
  2141 +EXPORT_SYMBOL_GPL(ring_buffer_size);
2113 2142  
2114 2143 static void
2115 2144 rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
... ... @@ -2156,6 +2185,7 @@
2156 2185  
2157 2186 spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
2158 2187 }
  2188 +EXPORT_SYMBOL_GPL(ring_buffer_reset_cpu);
2159 2189  
2160 2190 /**
2161 2191 * ring_buffer_reset - reset a ring buffer
... ... @@ -2168,6 +2198,7 @@
2168 2198 for_each_buffer_cpu(buffer, cpu)
2169 2199 ring_buffer_reset_cpu(buffer, cpu);
2170 2200 }
  2201 +EXPORT_SYMBOL_GPL(ring_buffer_reset);
2171 2202  
2172 2203 /**
2173 2204 * rind_buffer_empty - is the ring buffer empty?
... ... @@ -2186,6 +2217,7 @@
2186 2217 }
2187 2218 return 1;
2188 2219 }
  2220 +EXPORT_SYMBOL_GPL(ring_buffer_empty);
2189 2221  
2190 2222 /**
2191 2223 * ring_buffer_empty_cpu - is a cpu buffer of a ring buffer empty?
... ... @@ -2202,6 +2234,7 @@
2202 2234 cpu_buffer = buffer->buffers[cpu];
2203 2235 return rb_per_cpu_empty(cpu_buffer);
2204 2236 }
  2237 +EXPORT_SYMBOL_GPL(ring_buffer_empty_cpu);
2205 2238  
2206 2239 /**
2207 2240 * ring_buffer_swap_cpu - swap a CPU buffer between two ring buffers
... ... @@ -2250,6 +2283,7 @@
2250 2283  
2251 2284 return 0;
2252 2285 }
  2286 +EXPORT_SYMBOL_GPL(ring_buffer_swap_cpu);
2253 2287  
2254 2288 static void rb_remove_entries(struct ring_buffer_per_cpu *cpu_buffer,
2255 2289 struct buffer_data_page *bpage)
kernel/trace/trace.c
... ... @@ -1310,7 +1310,7 @@
1310 1310 TRACE_FILE_ANNOTATE = 2,
1311 1311 };
1312 1312  
1313   -static void trace_iterator_increment(struct trace_iterator *iter, int cpu)
  1313 +static void trace_iterator_increment(struct trace_iterator *iter)
1314 1314 {
1315 1315 /* Don't allow ftrace to trace into the ring buffers */
1316 1316 ftrace_disable_cpu();
... ... @@ -1389,7 +1389,7 @@
1389 1389 iter->ent = __find_next_entry(iter, &iter->cpu, &iter->ts);
1390 1390  
1391 1391 if (iter->ent)
1392   - trace_iterator_increment(iter, iter->cpu);
  1392 + trace_iterator_increment(iter);
1393 1393  
1394 1394 return iter->ent ? iter : NULL;
1395 1395 }