lkml.org 
[lkml]   [2015]   [Nov]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH v11 21/28] tracing: Remove restriction on string position in hist trigger keys
    On Thu, Oct 22, 2015 at 01:14:25PM -0500, Tom Zanussi wrote:
    > If we assume the maximum size for a string field, we don't have to
    > worry about its position. Since we only allow two keys in a compound
    > key and having more than one string key in a given compound key
    > doesn't make much sense anyway, trading a bit of extra space instead
    > of introducing an arbitrary restriction makes more sense.
    >
    > We also need to use the event field size for static strings when
    > copying the contents, otherwise we get random garbage in the key.
    >
    > Also, cast string return values to avoid warnings on 32-bit compiles.
    >
    > Finally, rearrange the code without changing any functionality by
    > moving the compound key updating code into a separate function.
    >
    > Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
    > Tested-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
    > ---

    [SNIP]
    > @@ -508,8 +508,8 @@ static int create_key_field(struct hist_trigger_data *hist_data,
    > goto out;
    > }
    >
    > - if (is_string_field(field)) /* should be last key field */
    > - key_size = HIST_KEY_SIZE_MAX - key_offset;
    > + if (is_string_field(field))
    > + key_size = MAX_FILTER_STR_VAL;
    > else
    > key_size = field->size;
    > }
    > @@ -781,9 +781,36 @@ static void hist_trigger_elt_update(struct hist_trigger_data *hist_data,
    > }
    > }
    >
    > +static inline void add_to_key(char *compound_key, void *key,
    > + struct hist_field *key_field, void *rec)
    > +{
    > + size_t size = key_field->size;
    > +
    > + if (key_field->flags & HIST_FIELD_STRING) {
    > + struct ftrace_event_field *field;
    > +
    > + /* ensure NULL-termination */
    > + size--;

    No need to do it here since the size will be updated below.

    > +
    > + field = key_field->field;
    > + if (field->filter_type == FILTER_DYN_STRING)
    > + size = *(u32 *)(rec + field->offset) >> 16;
    > + else if (field->filter_type == FILTER_PTR_STRING)
    > + size = strlen(key);
    > + else if (field->filter_type == FILTER_STATIC_STRING)
    > + size = field->size;
    > +
    > + if (size > key_field->size - 1)
    > + size = key_field->size - 1;

    The comment above can be moved here though.

    Thanks,
    Namhyung


    > + }
    > +
    > + memcpy(compound_key + key_field->offset, key, size);
    > +}
    > +


    \
     
     \ /
      Last update: 2015-11-02 16:01    [W:4.303 / U:0.404 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site