mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Leo Yan <leo.yan@linaro.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Steve MacLean <Steve.MacLean@Microsoft.com>,
	Yonatan Goldschmidt <yonatan.goldschmidt@granulate.io>,
	Kan Liang <kan.liang@linux.intel.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/3] perf session: Add swap operation for event TIME_CONV
Date: Mon, 26 Apr 2021 10:26:12 +0300	[thread overview]
Message-ID: <7f21edac-1bd9-ab98-aeca-2109e5edf5c3@intel.com> (raw)
In-Reply-To: <20210426064421.GA327854@leoy-ThinkPad-X240s>

On 26/04/21 9:44 am, Leo Yan wrote:
> Hi Adrian,
> 
> On Mon, Apr 26, 2021 at 08:40:00AM +0300, Adrian Hunter wrote:
> 
> [...]
> 
>>> +static void perf_event__time_conv_swap(union perf_event *event,
>>> +				       bool sample_id_all __maybe_unused)
>>> +{
>>> +	size_t time_zero_size;
>>> +
>>> +	event->time_conv.time_shift = bswap_64(event->time_conv.time_shift);
>>> +	event->time_conv.time_mult  = bswap_64(event->time_conv.time_mult);
>>> +	event->time_conv.time_zero  = bswap_64(event->time_conv.time_zero);
>>> +
>>> +	time_zero_size = (void *)&event->time_conv.time_cycles - (void *)event;
>>> +	if (event->header.size > time_zero_size) {
>>
>> I wonder if we could have a helper for this e.g. (untested)
>>
>> #define event_contains(obj, mem) (obj.header.size > offsetof(typeof(obj), mem))
>>
>> 	if (event_contains(event->time_conv, time_cycles)) {
> 
> Yeah, this is a better implementation.  Will refine patch for this.
> 
>>> +		event->time_conv.time_cycles = bswap_64(event->time_conv.time_cycles);
>>> +		event->time_conv.time_mask = bswap_64(event->time_conv.time_mask);
>>> +		event->time_conv.cap_user_time_zero =
>>> +			bswap_32(event->time_conv.cap_user_time_zero);
>>> +		event->time_conv.cap_user_time_short =
>>> +			bswap_32(event->time_conv.cap_user_time_short);
>>
>> 'struct perf_record_time_conv' contains bool, the sizeof which, AFAIK, is not defined.
>> Is it really 4 bytes on your implementation?  It is only 1 byte with gcc on x86.
> 
> On Arm64, bool is also 1 byte with GCC.
> 
> When working on this patch, I checked the size for structure
> perf_record_time_conv, it gave out the structure size is 56; I wrongly
> thought the bool size is 4 bytes and there have no padding.  In fact,
> bool size is 1 byte and GCC pads 6 bytes at the end of structure.
> 
>> Either way, you should change 'struct perf_record_time_conv' so it uses a type of known size.
>> Since you are the only one using it, it should match your implementation.
> 
> Will change to "unsigned int" value.

If it is 1 byte, I'd have thought __u8 i.e.

struct perf_record_time_conv {
	struct perf_event_header header;
	__u64			 time_shift;
	__u64			 time_mult;
	__u64			 time_zero;
	__u64			 time_cycles;
	__u64			 time_mask;
	__u8			 cap_user_time_zero;
	__u8			 cap_user_time_short;
	__u8			 unused[6];
};


  reply	other threads:[~2021-04-26  7:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-12  8:34 [PATCH v1 0/3] perf: Allow TIME_CONV to be backwards-compatible and dump it Leo Yan
2021-04-12  8:34 ` [PATCH v1 1/3] perf jit: Let convert_timestamp() to be backwards-compatible Leo Yan
2021-04-26  5:55   ` Adrian Hunter
2021-04-12  8:34 ` [PATCH v1 2/3] perf session: Add swap operation for event TIME_CONV Leo Yan
2021-04-26  5:40   ` Adrian Hunter
2021-04-26  6:44     ` Leo Yan
2021-04-26  7:26       ` Adrian Hunter [this message]
2021-04-26  7:39         ` Leo Yan
2021-04-12  8:34 ` [PATCH v1 3/3] perf session: Dump PERF_RECORD_TIME_CONV event Leo Yan
2021-04-26  6:10   ` Adrian Hunter
2021-04-26  1:41 ` [PATCH v1 0/3] perf: Allow TIME_CONV to be backwards-compatible and dump it Leo Yan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7f21edac-1bd9-ab98-aeca-2109e5edf5c3@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=Steve.MacLean@Microsoft.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=gustavoars@kernel.org \
    --cc=irogers@google.com \
    --cc=jolsa@redhat.com \
    --cc=kan.liang@linux.intel.com \
    --cc=leo.yan@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=yonatan.goldschmidt@granulate.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®