Re: [PATCH v20 13/15] trace-cmd: Basic infrastructure for host - guest timestamp synchronization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Now that I'm playing with patch 14, I took more interest in this code.

On Thu, 27 Feb 2020 16:19:59 +0200
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@xxxxxxxxx> wrote:

> +
> +#define PROTO_MASK_SIZE (sizeof(char))

Hmm, this is the size in bytes of the mask, not bits. You may need both.

#define PROTO_MASK_BITS (PROTO_MASK_SIZE * 8)

Because we can have up to 8 protocols per mask size (8 bits in a byte).

> +/**
> + * tracecmd_tsync_proto_select - Select time sync protocol, to be used for
> + *		timestamp synchronization with a peer
> + *
> + * @proto_mask: bitmask array of time sync protocols, supported by the peer
> + * @length: size of the @protos array
> + *
> + * Retuns Id of a time sync protocol, that can be used with the peer, or 0
> + *	  in case there is no match with supported protocols
> + */
> +unsigned int tracecmd_tsync_proto_select(char *proto_mask, int length)
> +{
> +	struct tsync_proto *selected = NULL;
> +	struct tsync_proto *proto;
> +	int word;
> +	int id;
> +
> +	for (word = 0; word < length; word++) {
> +		for (proto = tsync_proto_list; proto; proto = proto->next) {
> +			if (proto->proto_id < word * PROTO_MASK_SIZE)
> +				continue;

The above should be: proto->proto_id < word * PROTO_MASK_BITS

Because what you have currently is:

   proto->proto_id < word * 1


> +
> +			id = proto->proto_id - word * PROTO_MASK_SIZE;

And here you want PROTO_MASK_BITS, otherwise if we have a proto_id of 2
(which would fit as a bit in a char), this would become:

	id = 2 - 0 * 1 = 1

> +			if (id >= PROTO_MASK_SIZE)

Then this is: 2 >= 1 which would skip it.

Hmm, maybe you don't even need PROTO_MASK_SIZE and only need
PROTO_MASK_BITS.

-- Steve

> +				continue;
> +
> +			if ((1 << id) & proto_mask[word]) {
> +				if (selected) {
> +					if (selected->weight < proto->weight)
> +						selected = proto;
> +				} else
> +					selected = proto;
> +			}
> +		}
> +	}
> +
> +	if (selected)
> +		return selected->proto_id;
> +
> +	return 0;
> +}
> +



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux