lkml.org 
[lkml]   [2015]   [Jul]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 4/5] bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter
于 2015/7/23 10:22, Alexei Starovoitov 写道:
> On 7/22/15 7:12 PM, xiakaixu wrote:
>> So you mean like this?
>>
>> u64 bpf_perf_event_read(u64 r1, u64 index,...)
>> {
>> struct bpf_perf_event_array *array = (void *) (long) r1;
>> struct perf_event *event;
>> ...
>> event = array->events[index];
>> ...
>> }
>
> yes. the only thing needed is to add:
> if (index >= array->map.max_entries)
> return -E2BIG;
> before accessing array->events[index];
>
>>> >
>>>> >>+const struct bpf_func_proto bpf_perf_event_read_proto = {
>>>> >>+ .func = bpf_perf_event_read,
>>>> >>+ .gpl_only = false,
>>>> >>+ .ret_type = RET_INTEGER,
>>>> >>+ .arg1_type = ARG_CONST_MAP_PTR,
>>>> >>+ .arg2_type = ARG_PTR_TO_MAP_KEY,
>>> >
>>> >make it arg2_type = ARG_ANYTHING then you'll just index
>>> >into array the way prog_array does and similar to bpf_tail_call.
>
>> ARG_ANYTHING means any (initialized) argument is ok, but we here
>
> correct.
>
>> really want is map key. So I'm not sure ARG_ANYTHING is suitable.
>> You know ARG_ANYTHING is not checked enough in verifier.
>
> why? during perf_event_array creation time we check that key_size == u32
> so we can accept any integer.
> ARG_PTR_TO_MAP_KEY forces program author to use stack instead of
> passing index directly. Direct index is obviously faster.

Copy that. We will follow them in V3.
>
>
> .
>




\
 
 \ /
  Last update: 2015-07-23 05:01    [W:0.047 / U:1.956 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site