Re: [PATCH 3/6] perf record: add time-of-day option

Peter Zijlstra
2011-03-01T14:27:44Z

On Sun, 2011-02-27 at 20:52 -0700, David Ahern wrote:
> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
> index 51a2f34..404b1ee 100644
> --- a/include/linux/perf_event.h
> +++ b/include/linux/perf_event.h
> @@ -240,6 +240,7 @@ struct perf_event_attr {
> #define PERF_EVENT_IOC_PERIOD _IOW('$', 4, __u64)
> #define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5)
> #define PERF_EVENT_IOC_SET_FILTER _IOW('$', 6, char *)
> +#define PERF_EVENT_IOC_RECORD_SAMPLE _IO('$', 7)
>
> enum perf_event_ioc_flags {
> PERF_IOC_FLAG_GROUP = 1U << 0,
> diff --git a/kernel/perf_event.c b/kernel/perf_event.c
> index a25a63d..7999f55 100644
> --- a/kernel/perf_event.c
> +++ b/kernel/perf_event.c
> @@ -3250,6 +3250,7 @@ static struct perf_event *perf_fget_light(int fd, int *fput_needed)
> static int perf_event_set_output(struct perf_event *event,
> struct perf_event *output_event);
> static int perf_event_set_filter(struct perf_event *event, void __user *arg);
> +static int perf_event_generate_sample(struct perf_event *event);
>
> static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
> {
> @@ -3296,6 +3297,9 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
> case PERF_EVENT_IOC_SET_FILTER:
> return perf_event_set_filter(event, (void __user *)arg);
>
> + case PERF_EVENT_IOC_RECORD_SAMPLE:
> + return perf_event_generate_sample(event);
> +
> default:
> return -ENOTTY;
> }
> @@ -4398,6 +4402,21 @@ exit:
> rcu_read_unlock();
> }
>
> +/* add a sample to the event stream based on user request */
> +static int perf_event_generate_sample(struct perf_event *event)
> +{
> + struct perf_sample_data data;
> + struct pt_regs regs;
> +
> + perf_fetch_caller_regs(&regs);
> + event->pmu->read(event);
> + perf_sample_data_init(&data, 0);
> + data.period = event->hw.last_period;
> + perf_event_output(event, 0, &data, &regs);
> +
> + return 0;
> +}

I'm not quite sure why you need this..