/* Add a sample to the global event buffer. If possible the sample is converted into a persistent dentry/offset pair for later lookup from userspace. Return 0 on failure.  */
static int add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
/* Add a sample to the global event buffer. If possible the sample is converted into a persistent dentry/offset pair for later lookup from userspace. Return 0 on failure.  */
static int add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
{
	unsigned long cookie;
	off_t offset;
	if (in_kernel) {
		add_sample_entry(s->eip, s->event);
		return 1;
	}
	if (!mm) {
		atomic_inc(&oprofile_stats.sample_lost_no_mm);
		return 0;
	}
	cookie = lookup_dcookie(mm, s->eip, &offset);
	if (cookie == INVALID_COOKIE) {
		atomic_inc(&oprofile_stats.sample_lost_no_mapping);
		return 0;
	}
	if (cookie != last_cookie) {
		add_cookie_switch(cookie);
		last_cookie = cookie;
	}
	add_sample_entry(offset, s->event);
	return 1;
}