static int default_handler(struct task_struct *task, void *buf, pfm_ovfl_arg_t *arg, struct pt_regs *regs, unsigned long stamp) { pfm_default_smpl_hdr_t *hdr; pfm_default_smpl_entry_t *ent; void *cur, *last; unsigned long *e, entry_size; unsigned int npmds, i; unsigned char ovfl_pmd; unsigned char ovfl_notify; if (unlikely(buf == NULL || arg == NULL|| regs == NULL || task == NULL)) { DPRINT(("[%d] invalid arguments buf=%p arg=%p\n", task->pid, buf, arg)); return -EINVAL; } hdr = (pfm_default_smpl_hdr_t *)buf; cur = buf+hdr->hdr_cur_offs; last = buf+hdr->hdr_buf_size; ovfl_pmd = arg->ovfl_pmd; ovfl_notify = arg->ovfl_notify; /* * precheck for sanity */ if ((last - cur) < PFM_DEFAULT_MAX_ENTRY_SIZE) goto full; npmds = hweight64(arg->smpl_pmds[0]); ent = (pfm_default_smpl_entry_t *)cur; prefetch(arg->smpl_pmds_values); entry_size = sizeof(*ent) + (npmds << 3); /* position for first pmd */ e = (unsigned long *)(ent+1); hdr->hdr_count++; DPRINT_ovfl(("[%d] count=%lu cur=%p last=%p free_bytes=%lu ovfl_pmd=%d ovfl_notify=%d npmds=%u\n", task->pid, hdr->hdr_count, cur, last, last-cur, ovfl_pmd, ovfl_notify, npmds)); /* * current = task running at the time of the overflow. * * per-task mode: * - this is usually the task being monitored. * Under certain conditions, it might be a different task * * system-wide: * - this is not necessarily the task controlling the session */ ent->pid = current->pid; ent->ovfl_pmd = ovfl_pmd; ent->last_reset_val = arg->pmd_last_reset; //pmd[0].reg_last_reset_val; /* * where did the fault happen (includes slot number) */ ent->ip = regs->cr_iip | ((regs->cr_ipsr >> 41) & 0x3); ent->tstamp = stamp; ent->cpu = smp_processor_id(); ent->set = arg->active_set; ent->tgid = current->tgid; /* * selectively store PMDs in increasing index number */ if (npmds) { unsigned long *val = arg->smpl_pmds_values; for(i=0; i < npmds; i++) { *e++ = *val++; } } /* * update position for next entry */ hdr->hdr_cur_offs += entry_size; cur += entry_size; /* * post check to avoid losing the last sample */ if ((last - cur) < PFM_DEFAULT_MAX_ENTRY_SIZE) goto full; /* * keep same ovfl_pmds, ovfl_notify */ arg->ovfl_ctrl.bits.notify_user = 0; arg->ovfl_ctrl.bits.block_task = 0; arg->ovfl_ctrl.bits.mask_monitoring = 0; arg->ovfl_ctrl.bits.reset_ovfl_pmds = 1; /* reset before returning from interrupt handler */ return 0; full: DPRINT_ovfl(("sampling buffer full free=%lu, count=%lu, ovfl_notify=%d\n", last-cur, hdr->hdr_count, ovfl_notify)); /* * increment number of buffer overflow. * important to detect duplicate set of samples. */ hdr->hdr_overflows++; /* * if no notification requested, then we saturate the buffer */ if (ovfl_notify == 0) { arg->ovfl_ctrl.bits.notify_user = 0; arg->ovfl_ctrl.bits.block_task = 0; arg->ovfl_ctrl.bits.mask_monitoring = 1; arg->ovfl_ctrl.bits.reset_ovfl_pmds = 0; } else { arg->ovfl_ctrl.bits.notify_user = 1; arg->ovfl_ctrl.bits.block_task = 1; /* ignored for non-blocking context */ arg->ovfl_ctrl.bits.mask_monitoring = 1; arg->ovfl_ctrl.bits.reset_ovfl_pmds = 0; /* no reset now */ } return -1; /* we are full, sorry */ }
static int default_handler(struct task_struct *task, void *buf, pfm_ovfl_arg_t *arg, struct pt_regs *regs, unsigned long stamp) { pfm_default_smpl_hdr_t *hdr; pfm_default_smpl_entry_t *ent; void *cur, *last; unsigned long *e, entry_size; unsigned int npmds, i; unsigned char ovfl_pmd; unsigned char ovfl_notify; if (unlikely(buf == NULL || arg == NULL|| regs == NULL || task == NULL)) { DPRINT(("[%d] invalid arguments buf=%p arg=%p\n", task->pid, buf, arg)); return -EINVAL; } hdr = (pfm_default_smpl_hdr_t *)buf; cur = buf+hdr->hdr_cur_offs; last = buf+hdr->hdr_buf_size; ovfl_pmd = arg->ovfl_pmd; ovfl_notify = arg->ovfl_notify; /* */ if ((last - cur) < PFM_DEFAULT_MAX_ENTRY_SIZE) goto full; npmds = hweight64(arg->smpl_pmds[0]); ent = (pfm_default_smpl_entry_t *)cur; prefetch(arg->smpl_pmds_values); entry_size = sizeof(*ent) + (npmds << 3); /* */ e = (unsigned long *)(ent+1); hdr->hdr_count++; DPRINT_ovfl(("[%d] count=%lu cur=%p last=%p free_bytes=%lu ovfl_pmd=%d ovfl_notify=%d npmds=%u\n", task->pid, hdr->hdr_count, cur, last, last-cur, ovfl_pmd, ovfl_notify, npmds)); /* */ ent->pid = current->pid; ent->ovfl_pmd = ovfl_pmd; ent->last_reset_val = arg->pmd_last_reset; // /* */ ent->ip = regs->cr_iip | ((regs->cr_ipsr >> 41) & 0x3); ent->tstamp = stamp; ent->cpu = smp_processor_id(); ent->set = arg->active_set; ent->tgid = current->tgid; /* */ if (npmds) { unsigned long *val = arg->smpl_pmds_values; for(i=0; i < npmds; i++) { *e++ = *val++; } } /* */ hdr->hdr_cur_offs += entry_size; cur += entry_size; /* */ if ((last - cur) < PFM_DEFAULT_MAX_ENTRY_SIZE) goto full; /* */ arg->ovfl_ctrl.bits.notify_user = 0; arg->ovfl_ctrl.bits.block_task = 0; arg->ovfl_ctrl.bits.mask_monitoring = 0; arg->ovfl_ctrl.bits.reset_ovfl_pmds = 1; /* */ return 0; full: DPRINT_ovfl(("sampling buffer full free=%lu, count=%lu, ovfl_notify=%d\n", last-cur, hdr->hdr_count, ovfl_notify)); /* */ hdr->hdr_overflows++; /* */ if (ovfl_notify == 0) { arg->ovfl_ctrl.bits.notify_user = 0; arg->ovfl_ctrl.bits.block_task = 0; arg->ovfl_ctrl.bits.mask_monitoring = 1; arg->ovfl_ctrl.bits.reset_ovfl_pmds = 0; } else { arg->ovfl_ctrl.bits.notify_user = 1; arg->ovfl_ctrl.bits.block_task = 1; /* */ arg->ovfl_ctrl.bits.mask_monitoring = 1; arg->ovfl_ctrl.bits.reset_ovfl_pmds = 0; /* */ } return -1; /* */ }