Skip to content

Create a prototype for OPENSSL_rdtsc - #4757

Closed
kroeckx wants to merge 1 commit into
openssl:masterfrom
kroeckx:rdtsc
Closed

kroeckx wants to merge 1 commit into
openssl:masterfrom
kroeckx:rdtsc

Conversation

@kroeckx

@kroeckx kroeckx commented Nov 19, 2017 •

Copy link
Copy Markdown
Member

@dot-asm: Does this make sense?

I think so arches have it as long, other as long long.

@kroeckx kroeckx mentioned this pull request Nov 19, 2017
@paulidale

Copy link
Copy Markdown
Contributor

I raised this a while back: #3125

Comment thread test/modes_internal_test.c Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sizeof(size_t) != sizeof(unsigned long long)

Comment thread crypto/armcap.c Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced that making this always return unsigned long long is a good idea. Each CPU will have a native best size.

@dot-asm

dot-asm commented Nov 20, 2017

Copy link
Copy Markdown
Contributor

Trouble is that there is no common type suitable for all platforms. Well, there is one thing one can tell for sure, that return value is 64 bits in all 64-bit builds. Another thing one can tell is that if one tries to use long long in 32-bit builds, then there are platforms where return value will appear gabled. This leaves us with following question, wouldn't long be least troublesome under the circumstances? Yes, long would be least troublesome. With reservation that on WIN64 long is 32 bits. So one can as well argue in favour of size_t, or one can simply say that 32 bits is enough [for purposes of short benchmarking, short enough for not having two wraparounds(*), around a second.]

One can also flip the question and aim for harmonization of all assembly implementations to return 64-bit value. Trouble is that not all processors can deliver that, in which cases single wraparound occurrences(*) will be broken. But one can as well choose disregard this. In other words no matter what one does there always is a corner case :-(

To summarize, given subroutine's usage pattern and overall context is not really inappropriate to be a bit opportunistic and just settle for long (or size_t), but not long long.

(*) one 32-bit wraparound works, because you ignore borrow anyway;

@paulidale

Copy link
Copy Markdown
Contributor

Or we could define an internal type that represents the return value: ossl_rdtsc_value or some such.

I'd also consider a name change: rdtsc is very x86 specific. openssl_instruction_counter or openssl_fast_counter ? This function is private so the possibility exists.

We not only use this as a timer but also as a low grade entropy source in the RNG infrastructure.

@kroeckx

kroeckx commented Nov 20, 2017 •

Copy link
Copy Markdown
Member Author

I'm currently leaning towards just making it return an uint32_t.

@dot-asm

dot-asm commented Nov 21, 2017

Copy link
Copy Markdown
Contributor

Another alternative is to simply omit all those #ifdef segments. They are really debugging artefacts, and they are meant to produce meaningful output only in specific and controlled conditions. I won't miss them (since I kept original copies which are more suitable for debugging purposes) and users are better off using openssl speed...

Switch to make it return an uint32_t instead of the various different
types it returns now.

Fixes: openssl#3125
@kroeckx

kroeckx commented Nov 21, 2017

Copy link
Copy Markdown
Member Author

So I've pushed a new commit changing it to uint32_t. I just don't have an idea if the assembler versions still work properly.

@dot-asm

dot-asm commented Nov 21, 2017

Copy link
Copy Markdown
Contributor

As already said, assembler is good up to size_t.

@dot-asm

dot-asm commented Nov 21, 2017

Copy link
Copy Markdown
Contributor

As already said, assembler is good up to size_t.

This came out a little bit wrong. All assembly modules will work with return type declared up to size_t. [And some 32-bit ones would work with 64-bit return, some will fail...]

@paulidale

Copy link
Copy Markdown
Contributor

It seems like size_t might be the way to go.

@dot-asm

dot-asm commented Nov 22, 2017

Copy link
Copy Markdown
Contributor

Either way works [including removal of #ifdefs]. I'm giving it few day hours in case Kurt changes his mind, and then approving it.

@dot-asm dot-asm added the approval: done This pull request has the required number of approvals label Nov 22, 2017
@kroeckx kroeckx closed this Nov 25, 2017
levitte pushed a commit that referenced this pull request Nov 25, 2017
Switch to make it return an uint32_t instead of the various different
types it returns now.

Fixes: #3125

Reviewed-by: Andy Polyakov <[email protected]>
GH: #4757
@kroeckx kroeckx mentioned this pull request Feb 1, 2018
1 task done
@mspncp mspncp mentioned this pull request Apr 10, 2018
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: done This pull request has the required number of approvals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants