Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1705929 > unrolled thread

Re: [PATCH v4] printk: Add monotonic, boottime, and realtime timestamps

Started bySergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
First post2017-08-08 02:20 +0200
Last post2017-08-08 15:50 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v4] printk: Add monotonic, boottime, and realtime  timestamps Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2017-08-08 02:20 +0200
    Re: [PATCH v4] printk: Add monotonic, boottime, and realtime  timestamps Prarit Bhargava <prarit@redhat.com> - 2017-08-08 14:40 +0200
    Re: [PATCH v4] printk: Add monotonic, boottime, and realtime  timestamps Prarit Bhargava <prarit@redhat.com> - 2017-08-08 15:50 +0200

#1705929 — Re: [PATCH v4] printk: Add monotonic, boottime, and realtime timestamps

FromSergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Date2017-08-08 02:20 +0200
SubjectRe: [PATCH v4] printk: Add monotonic, boottime, and realtime timestamps
Message-ID<uc0pB-7WI-11@gated-at.bofh.it>
On (08/07/17 11:52), Prarit Bhargava wrote:
[..]
> +/**
> + * enum printk_time_type - Timestamp types for printk() messages.
> + * @PRINTK_TIME_DISABLE: No time stamp.
> + * @PRINTK_TIME_LOCAL: Local hardware clock timestamp.
> + * @PRINTK_TIME_BOOT: Boottime clock timestamp.
> + * @PRINTK_TIME_MONO: Monotonic clock timestamp.
> + * @PRINTK_TIME_REAL: Realtime clock timestamp.  On 32-bit
> + * systems selecting the real clock printk timestamp may lead to unlikely
> + * situations where a timestamp is wrong because the real time offset is read
> + * without the protection of a sequence lock in the call to ktime_get_log_ts()
> + * in printk_get_ts() below.
> + */
> +enum printk_time_type {
> +	PRINTK_TIME_DISABLE = 0,
> +	PRINTK_TIME_LOCAL = 1,
> +	PRINTK_TIME_BOOT = 2,
> +	PRINTK_TIME_MONO = 3,
> +	PRINTK_TIME_REAL = 4,
> +};

may be call the entire thing 'timestamp surces' or something?

[..]
> +	if (strlen(param) == 1) {
> +		/* Preserve legacy boolean settings */
> +		if (!strcmp("0", param) || !strcmp("n", param) ||
> +		    !strcmp("N", param))
> +			_printk_time = PRINTK_TIME_DISABLE;
> +		if (!strcmp("1", param) || !strcmp("y", param) ||
> +		    !strcmp("Y", param))
> +			_printk_time = PRINTK_TIME_LOCAL;
> +	}
> +	if (_printk_time == -1) {
> +		for (stamp = 0; stamp <= 4; stamp++) {
> +			if (!strncmp(printk_time_str[stamp], param,
> +				     strlen(param))) {
> +				_printk_time = stamp;
> +				break;
> +			}
> +		}
> +	}

	you can use match_string() here.

> +	if (_printk_time == -1) {
> +		pr_warn("printk: invalid timestamp value %s\n", param);
> +		return -EINVAL;
> +	}

`invalid timestamp value' is confusing.


> +	} else if ((printk_time_setting != _printk_time) &&
> +		   (_printk_time != 0)) {
> +		pr_warn("printk: timestamp can only be set to 0(disabled) or %s\n",
> +			printk_time_str[printk_time_setting]);

ditto.


> +		return -EINVAL;
> +	}
> +
> +	printk_time = _printk_time;
> +	pr_info("printk: timestamp set to %s\n", printk_time_str[printk_time]);

ditto.


[..]

> +static u64 printk_get_ts(void)
> +{
> +	u64 mono, offset_real;
> +
> +	if (printk_time <= PRINTK_TIME_LOCAL)
> +		return local_clock();
> +
> +	if (printk_time == PRINTK_TIME_BOOT)
> +		return ktime_get_boot_log_ts();
> +
> +	mono = ktime_get_real_log_ts(&offset_real);
> +
> +	if (printk_time == PRINTK_TIME_MONO)
> +		return mono;
> +
> +	return mono + offset_real;
> +}

this looks hard...

> +static int printk_time;
> +static int printk_time_setting;

how about s/printk_time_setting/printk_time_source/? or something similar?

	-ss

[toc] | [next] | [standalone]


#1706495

FromPrarit Bhargava <prarit@redhat.com>
Date2017-08-08 14:40 +0200
Message-ID<ucbXJ-8or-29@gated-at.bofh.it>
In reply to#1705929

On 08/07/2017 08:19 PM, Sergey Senozhatsky wrote:
> On (08/07/17 11:52), Prarit Bhargava wrote:
> [..]
>> +/**
>> + * enum printk_time_type - Timestamp types for printk() messages.
>> + * @PRINTK_TIME_DISABLE: No time stamp.
>> + * @PRINTK_TIME_LOCAL: Local hardware clock timestamp.
>> + * @PRINTK_TIME_BOOT: Boottime clock timestamp.
>> + * @PRINTK_TIME_MONO: Monotonic clock timestamp.
>> + * @PRINTK_TIME_REAL: Realtime clock timestamp.  On 32-bit
>> + * systems selecting the real clock printk timestamp may lead to unlikely
>> + * situations where a timestamp is wrong because the real time offset is read
>> + * without the protection of a sequence lock in the call to ktime_get_log_ts()
>> + * in printk_get_ts() below.
>> + */
>> +enum printk_time_type {
>> +	PRINTK_TIME_DISABLE = 0,
>> +	PRINTK_TIME_LOCAL = 1,
>> +	PRINTK_TIME_BOOT = 2,
>> +	PRINTK_TIME_MONO = 3,
>> +	PRINTK_TIME_REAL = 4,
>> +};
> 
> may be call the entire thing 'timestamp surces' or something?

Done.

> 
> [..]
>> +	if (strlen(param) == 1) {
>> +		/* Preserve legacy boolean settings */
>> +		if (!strcmp("0", param) || !strcmp("n", param) ||
>> +		    !strcmp("N", param))
>> +			_printk_time = PRINTK_TIME_DISABLE;
>> +		if (!strcmp("1", param) || !strcmp("y", param) ||
>> +		    !strcmp("Y", param))
>> +			_printk_time = PRINTK_TIME_LOCAL;
>> +	}
>> +	if (_printk_time == -1) {
>> +		for (stamp = 0; stamp <= 4; stamp++) {
>> +			if (!strncmp(printk_time_str[stamp], param,
>> +				     strlen(param))) {
>> +				_printk_time = stamp;
>> +				break;
>> +			}
>> +		}
>> +	}
> 
> 	you can use match_string() here.
> 
>> +	if (_printk_time == -1) {
>> +		pr_warn("printk: invalid timestamp value %s\n", param);
>> +		return -EINVAL;
>> +	}
> 
> `invalid timestamp value' is confusing.

I can't think of anything better than 'invalid timestamp option'.  If you find
that confusing, please explain why.

> 
> 
>> +	} else if ((printk_time_setting != _printk_time) &&
>> +		   (_printk_time != 0)) {
>> +		pr_warn("printk: timestamp can only be set to 0(disabled) or %s\n",
>> +			printk_time_str[printk_time_setting]);
> 
> ditto.

Changed to 'timestamp can only e set to 0, disabled, or <string>'.

> 
> 
>> +		return -EINVAL;
>> +	}
>> +
>> +	printk_time = _printk_time;
>> +	pr_info("printk: timestamp set to %s\n", printk_time_str[printk_time]);
> 
> ditto.

I don't find this confusing _at all_.  Please offer an explanation of why you
think that message is confusing.

> 
> 
> [..]
> 
>> +static u64 printk_get_ts(void)
>> +{
>> +	u64 mono, offset_real;
>> +
>> +	if (printk_time <= PRINTK_TIME_LOCAL)
>> +		return local_clock();
>> +
>> +	if (printk_time == PRINTK_TIME_BOOT)
>> +		return ktime_get_boot_log_ts();
>> +
>> +	mono = ktime_get_real_log_ts(&offset_real);
>> +
>> +	if (printk_time == PRINTK_TIME_MONO)
>> +		return mono;
>> +
>> +	return mono + offset_real;
>> +}
> 
> this looks hard...

See previous suggestion from peterz to switch to a fn ptr.

> 
>> +static int printk_time;
>> +static int printk_time_setting;
> 
> how about s/printk_time_setting/printk_time_source/? or something similar?

Sure.

P.

> 
> 	-ss
> 

[toc] | [prev] | [next] | [standalone]


#1706578

FromPrarit Bhargava <prarit@redhat.com>
Date2017-08-08 15:50 +0200
Message-ID<ucd3t-De-23@gated-at.bofh.it>
In reply to#1705929

On 08/07/2017 08:19 PM, Sergey Senozhatsky wrote:
> On (08/07/17 11:52), Prarit Bhargava wrote:

<snip>

> [..]
>> +	if (strlen(param) == 1) {
>> +		/* Preserve legacy boolean settings */
>> +		if (!strcmp("0", param) || !strcmp("n", param) ||
>> +		    !strcmp("N", param))
>> +			_printk_time = PRINTK_TIME_DISABLE;
>> +		if (!strcmp("1", param) || !strcmp("y", param) ||
>> +		    !strcmp("Y", param))
>> +			_printk_time = PRINTK_TIME_LOCAL;
>> +	}
>> +	if (_printk_time == -1) {
>> +		for (stamp = 0; stamp <= 4; stamp++) {
>> +			if (!strncmp(printk_time_str[stamp], param,
>> +				     strlen(param))) {
>> +				_printk_time = stamp;
>> +				break;
>> +			}
>> +		}
>> +	}
> 
> 	you can use match_string() here.

match_string doesn't match correctly.  Others have made requests for, for
example, printk.time=r printk.time=real, etc.  Instead of butchering the code
for a bunch of strings I chose to allow partial matching and simplify the code.

P.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web