int oprofile_setup(void) { int err; mutex_lock(&start_mutex); if ((err = alloc_cpu_buffers())) goto out; if ((err = alloc_event_buffer())) goto out1; if (oprofile_ops.setup && (err = oprofile_ops.setup())) goto out2; /* Note even though this starts part of the * profiling overhead, it's necessary to prevent * us missing task deaths and eventually oopsing * when trying to process the event buffer. */ if (oprofile_ops.sync_start) { int sync_ret = oprofile_ops.sync_start(); switch (sync_ret) { case 0: goto post_sync; case 1: goto do_generic; case -1: goto out3; default: goto out3; } } do_generic: if ((err = sync_start())) goto out3; post_sync: is_setup = 1; mutex_unlock(&start_mutex); return 0; out3: if (oprofile_ops.shutdown) oprofile_ops.shutdown(); out2: free_event_buffer(); out1: free_cpu_buffers(); out: mutex_unlock(&start_mutex); return err; }
static Chan* kprofattach(char *spec) { uint32_t n; /* allocate when first used */ kprof.minpc = KTZERO; kprof.maxpc = PTR2UINT(etext); kprof.nbuf = (kprof.maxpc-kprof.minpc) >> LRES; n = kprof.nbuf*SZ; if(kprof.buf == 0) { kprof.buf = malloc(n); if(kprof.buf == 0) error(Enomem); } kproftab[1].length = n; alloc_cpu_buffers(); print("Kprof attached. Buf is %p, %d bytes, minpc %p maxpc %p\n", kprof.buf, n, (void *)kprof.minpc, (void *)kprof.maxpc); return devattach('K', spec); }
int oprofile_setup(void) { int err; down(&start_sem); if ((err = alloc_cpu_buffers())) goto out; if ((err = alloc_event_buffer())) goto out1; if (oprofile_ops.setup && (err = oprofile_ops.setup())) goto out2; /* Note even though this starts part of the * profiling overhead, it's necessary to prevent * us missing task deaths and eventually oopsing * when trying to process the event buffer. */ if ((err = sync_start())) goto out3; is_setup = 1; up(&start_sem); return 0; out3: if (oprofile_ops.shutdown) oprofile_ops.shutdown(); out2: free_event_buffer(); out1: free_cpu_buffers(); out: up(&start_sem); return err; }