Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4120787pxk; Tue, 29 Sep 2020 15:11:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTQArL/GBdgfLjMvMAj/vEJmZLx/zDXCyjstaJDmBnMIyLiZdsd6GPLmKg9q/9fLPB9SFS X-Received: by 2002:a05:6402:209:: with SMTP id t9mr5860414edv.208.1601417475391; Tue, 29 Sep 2020 15:11:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601417475; cv=none; d=google.com; s=arc-20160816; b=LsJehZ4Q+Gt+cHKHt/gvZyAfsrDfDH0CVS/BlEpTKFabUzmkay9mlPlZL0jl8OeuWZ 5XlBwgNwZcdtg1lt57o4NO8gCGThcVT+sgrAyFXgy7WacQJm7nlnHZTiX8wnhFiky9fQ QZafED/SwzTpwzY0xU3ca0ew+CRsBeBJvpm0w+5h5B2elmqisv9RwQtdw2+HKlC+qe2l duBW9O90zyfu5fGlnX5K66i1z+T9fqdLvG/ORTYp2S7cfftbWvqRVIsUF77gS5Wq5bnS yS/jYeIFs6t54/WF50QbmgguABavEhnmn70iGB/zh2DJ2ulrydGFo6l41Sg6H8x7d8CV gj+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=I98ogDVYNmjIH/ARp0GBQDRwKiEAZpi0sA4DHsC6xTw=; b=zZOYvYlo2HwZPPIvO6GtssU2yicaYUx9Ndc+hjPlNb9wC3yx/cemK7PL7iMqnZIT5Y nvVVnQGic2qUJoJja9s+fo4NTzFEQOsoek5Pquvm5JA6x1Z7dEm3Qxx+4a+19ClB3Flx DPNLOzgFIXUqqspOMAIxbgvHNhGwztW/TwYUYIJGb9n2i4wUVdv5CPnumDjn8qmYkK5K 2FkqVRoZH7zyQFH1sfpAe19QYfaCc1I6XBzTvtGcSwfR9+k8SX4KNPCkHNnnze7P/x5k 1mCmrn1qzsk6pX+4zLgzdbCp7r4ORV+soYP6szrd8fpX5XDB48Ufo75uoZ0Rc4MrEwSd 91sQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gc15si3546922ejb.464.2020.09.29.15.10.52; Tue, 29 Sep 2020 15:11:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728688AbgI2WJb (ORCPT + 99 others); Tue, 29 Sep 2020 18:09:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:40670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727922AbgI2WJb (ORCPT ); Tue, 29 Sep 2020 18:09:31 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 129842083B; Tue, 29 Sep 2020 22:09:28 +0000 (UTC) Date: Tue, 29 Sep 2020 18:09:27 -0400 From: Steven Rostedt To: Axel Rasmussen Cc: Tom Zanussi , Masami Hiramatsu , LKML Subject: Re: [PATCH 3/3] tracing: Add support for dynamic strings to synthetic events Message-ID: <20200929180927.17b6b78f@gandalf.local.home> In-Reply-To: References: X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 29 Sep 2020 15:01:59 -0700 Axel Rasmussen wrote: > > event->fields[i]->offset = n_u64; > > > > - if (event->fields[i]->is_string) { > > + if (event->fields[i]->is_string && !event->fields[i]->is_dynamic) { > > offset += STR_VAR_LEN_MAX; > > n_u64 += STR_VAR_LEN_MAX / sizeof(u64); > > } else { > > @@ -139,6 +139,9 @@ static int synth_field_string_size(char *type) > > if (len > 3) > > return -EINVAL; > > > > + if (len == 0) > > + return 0; /* variable-length string */ > > + > > strncpy(buf, start, len); > > buf[len] = '\0'; > > > > @@ -290,10 +293,25 @@ static enum print_line_t print_synth_event(struct trace_iterator *iter, > > > > /* parameter values */ > > if (se->fields[i]->is_string) { > > - trace_seq_printf(s, print_fmt, se->fields[i]->name, > > - (char *)&entry->fields[n_u64], > > - i == se->n_fields - 1 ? "" : " "); > > - n_u64 += STR_VAR_LEN_MAX / sizeof(u64); > > + if (se->fields[i]->is_dynamic) { > > + u32 offset, data_offset; > > + char *str_field; > > + > > + offset = (u32)entry->fields[n_u64]; > > + data_offset = offset & 0xffff; > > + > > + str_field = (char *)entry + data_offset; > > Is it better to re-use __get_str from include/trace/trace_events.h > instead of writing this out directly? > > > + > > + trace_seq_printf(s, print_fmt, se->fields[i]->name, > > + str_field, > > + i == se->n_fields - 1 ? "" : " "); > > + n_u64++; > > + } else { > > + trace_seq_printf(s, print_fmt, se->fields[i]->name, > > + (char *)&entry->fields[n_u64], > > + i == se->n_fields - 1 ? "" : " "); > > + n_u64 += STR_VAR_LEN_MAX / sizeof(u64); > > + } > > } else { > > struct trace_print_flags __flags[] = { > > __def_gfpflag_names, {-1, NULL} }; > > @@ -325,16 +343,52 @@ static struct trace_event_functions synth_event_funcs = { > > .trace = print_synth_event > > }; > > > > +static unsigned int trace_string(struct synth_trace_event *entry, > > + struct synth_event *event, > > + char *str_val, > > + bool is_dynamic, > > + unsigned int data_size, > > + unsigned int *n_u64) > > +{ > > + unsigned int len = 0; > > + char *str_field; > > + > > + if (is_dynamic) { > > + u32 data_offset; > > + > > + data_offset = offsetof(typeof(*entry), fields); > > + data_offset += event->n_u64 * sizeof(u64); > > + data_offset += data_size; > > + > > + str_field = (char *)entry + data_offset; > > + > > + len = strlen(str_val) + 1; > > + strscpy(str_field, str_val, len); > > + > > + data_offset |= len << 16; > > + *(u32 *)&entry->fields[*n_u64] = data_offset; > > Similar thing here, is it possible to reuse __dynamic_array or __string? Interesting idea. I'd prefer to keep it broken out for this patch set, and then we could look at incorporating this file to use the macros of . But I much rather have that be a separate patch that does that as an enhancement than to include it in this file doing more work. -- Steve > > > + > > + (*n_u64)++; > > + } else { > > + str_field = (char *)&entry->fields[*n_u64]; > > + > > + strscpy(str_field, str_val, STR_VAR_LEN_MAX); > > + (*n_u64) += STR_VAR_LEN_MAX / sizeof(u64); > > + } > > + > > + return len; > > +} > > + > > static n