Skip to content

Refactor XXX_do_all_provided() to behave like XXX_fetch() - #15604

Closed
levitte wants to merge 14 commits into
openssl:masterfrom
levitte:refactor_XXX_do_all_provided
Closed

levitte wants to merge 14 commits into
openssl:masterfrom
levitte:refactor_XXX_do_all_provided

Conversation

@levitte

@levitte levitte commented Jun 3, 2021 •

Copy link
Copy Markdown
Member

This is refactored to use inner_xxx_fetch() without any given
name, which is just there to ensure all decoder implementations are
made into methods, and then use ossl_method_store_do_all() to list
them all.

This also adds the internal xxx_do_all_prefetched(), which
can be used if pre-fetching needs to be done separately from listing
all the decoder implementations, or if listing may happen multiple
times.

Fixes #15538
Fixes #14837

@levitte levitte added the branch: master Applies to master branch label Jun 3, 2021
@levitte levitte added this to the 3.0.0 beta1 milestone Jun 3, 2021
@levitte

levitte commented Jun 3, 2021 •

Copy link
Copy Markdown
Member Author

@paulidale, the basic functionality change in crypto/property/property.c turned out to be very easy, that's what's in here for the moment. I haven't looked at locking at all, though...

@github-actions github-actions Bot added the severity: fips change The pull request changes FIPS provider sources label Jun 3, 2021
@paulidale

Copy link
Copy Markdown
Contributor

I figured it would be easy based on our discussion. But after the mention of store, I was looking to see how the OSSL_STORE_CTX's cached_info could be relevant. The answer is that it isn't :)

@levitte

levitte commented Jun 3, 2021

Copy link
Copy Markdown
Member Author

We have too many kinds of stores 😆

@paulidale

Copy link
Copy Markdown
Contributor

Definitely 😢

Comment thread crypto/property/property.c Resolved
@levitte

levitte commented Jun 4, 2021

Copy link
Copy Markdown
Member Author

I made some progress, now having OSSL_DECODER_do_all_provided() use this new functionality... and the result is showing with gprof!

With master, gprof on a run of the test program from #15199 shows quite a few calls of ossl_decoder_from_algorithm, as already shown in #15498 (comment):

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  us/call  us/call  name    
...
  0.00      0.30     0.00    37037     0.00     0.26  ossl_decoder_from_algorithm

With the work I've done in this branch, I get this instead:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  us/call  us/call  name    
...
  0.00      0.63     0.00       37     0.00     0.01  ossl_decoder_from_algorithm

That's 1000 times fewer calls, i.e. 1000 times less allocations of the same methods!

I'll try to merge this with #15498 to see what effect that brings.

@paulidale

Copy link
Copy Markdown
Contributor

A decent improvement ≈ 10ms saved.

@levitte

levitte commented Jun 4, 2021

Copy link
Copy Markdown
Member Author

A decent improvement ≈ 10ms saved.

Not sure about that... I'm hitting churn elsewhere

@levitte
levitte force-pushed the refactor_XXX_do_all_provided branch 2 times, most recently from 6d5d639 to 261e5cb Compare June 9, 2021 09:51
@levitte levitte changed the title Refactor XXX_do_all_provided() to do "real" fetching. [Pending in #15498] Refactor XXX_do_all_provided() to do "real" fetching. Jun 9, 2021
@levitte
levitte force-pushed the refactor_XXX_do_all_provided branch from d441be5 to 3614ee9 Compare June 9, 2021 15:08
@levitte
levitte marked this pull request as ready for review June 9, 2021 15:12
@levitte levitte changed the title [Pending in #15498] Refactor XXX_do_all_provided() to do "real" fetching. Refactor XXX_do_all_provided() to behave like XXX_fetch() Jun 9, 2021
@levitte

levitte commented Jun 9, 2021

Copy link
Copy Markdown
Member Author

This is ready for review

@paulidale paulidale left a comment

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.

Superficially looks pretty good.

Comment thread crypto/encode_decode/decoder_meth.c Resolved
Comment thread crypto/encode_decode/decoder_meth.c Resolved
Comment thread crypto/encode_decode/decoder_meth.c Resolved
Comment thread crypto/encode_decode/decoder_meth.c Resolved
Comment thread crypto/encode_decode/decoder_meth.c Resolved
Comment thread crypto/evp/evp_fetch.c Resolved
@levitte
levitte force-pushed the refactor_XXX_do_all_provided branch from d07cfa1 to 897fe40 Compare June 11, 2021 08:18
@levitte

levitte commented Jun 11, 2021 •

Copy link
Copy Markdown
Member Author

I just did time measurements with the program from #15199 on the following commits:

  • openssl-3.0.0-alpha17:

    $ time ./15199
    
    real	0m3,969s
    user	0m2,976s
    sys	0m0,004s
    $ time ./15199
    
    real	0m2,934s
    user	0m2,930s
    sys	0m0,004s
  • current master (c24b3f2):

    $ time ./15199
    
    real	0m9,471s
    user	0m9,471s
    sys	0m0,000s
    $ time ./15199
    
    real	0m9,515s
    user	0m9,506s
    sys	0m0,008s
  • This PR (which is rebased on top of current master):

    $ time ./15199
    
    real	0m3,923s
    user	0m3,918s
    sys	0m0,004s
    $ time ./15199
    
    real	0m3,958s
    user	0m3,954s
    sys	0m0,004s

Something to remember when evaluating this is that the current master includes a fix for a bug in decoder chain building that unfortunately brought some extra churn.

All three OpenSSL's were configured like this:

$ ./Configure --debug --strict-warnings enable-fips

And the #15199 program was compiled like this for each of them, locally in the OpenSSL build directory:

$ cc -pthread -g -O0 -pg -I ./include/ -L . -o 15199 ~/gitwrk/openssl.net/personal/3.0-cases/15199.c libcrypto.a -ldl

@mattcaswell

Copy link
Copy Markdown
Member

I just did time measurements with the program from #15199 on the following commits:

Just to be clear, there are 2 programs in #15199. Is it the first one you were measuring?

@levitte

levitte commented Jun 11, 2021

Copy link
Copy Markdown
Member Author

Just to be clear, there are 2 programs in #15199. Is it the first one you were measuring?

Oh! I dunno why I missed the second one... so, er, the PEM variant

@levitte

levitte commented Jun 11, 2021

Copy link
Copy Markdown
Member Author

The same sort of measurements on the DER variant:

  • openssl-3.0.0-alpha17:

    $ time ./15199-der
    
    real	0m1,235s
    user	0m1,231s
    sys	0m0,004s
  • current master (c24b3f2):

    $ time ./15199-der
    
    real	0m5,717s
    user	0m5,708s
    sys	0m0,008s
  • This PR (which is rebased on top of current master):

    $ time ./15199-pem der
    
    real	0m3,962s
    user	0m3,953s
    sys	0m0,008s

@t8m

t8m commented Jun 11, 2021

Copy link
Copy Markdown
Member

So we are not even back at the numbers of alpha17. 😞

@levitte
levitte force-pushed the refactor_XXX_do_all_provided branch from bfbbd8d to 317bc0b Compare June 15, 2021 13:08
@levitte levitte changed the title [Pending on #15737] Refactor XXX_do_all_provided() to behave like XXX_fetch() Refactor XXX_do_all_provided() to behave like XXX_fetch() Jun 15, 2021
@levitte

levitte commented Jun 15, 2021

Copy link
Copy Markdown
Member Author

With #15737 now merged, this is rebased on top of master. Unless something goes wrong, I'll assume that the current approvals hold.

@t8m

t8m commented Jun 15, 2021

Copy link
Copy Markdown
Member

With #15737 now merged, this is rebased on top of master. Unless something goes wrong, I'll assume that the current approvals hold.

Yep.

@levitte levitte added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Jun 15, 2021
openssl-machine pushed a commit that referenced this pull request Jun 15, 2021
It will simply call the given callback for every method found in the
given store.

Fixes #15538
Fixes #14837

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #15604)
openssl-machine pushed a commit that referenced this pull request Jun 15, 2021
…etch()

This is refactored to use inner_ossl_decoder_fetch() without any given
name, which is just there to ensure all decoder implementations are
made into methods, and then use ossl_method_store_do_all() to list
them all.

This also adds the internal ossl_decoder_do_all_prefetched(), which
can be used if pre-fetching needs to be done separately from listing
all the decoder implementations, or if listing may happen multiple
times.

Fixes #15538
Fixes #14837

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #15604)
openssl-machine pushed a commit that referenced this pull request Jun 15, 2021
…etch()

This is refactored to use inner_ossl_encoder_fetch() without any given
name, which is just there to ensure all encoder implementations are
made into methods, and then use ossl_method_store_do_all() to list
them all.

This also adds the internal ossl_encoder_do_all_prefetched(), which
can be used if pre-fetching needs to be done separately from listing
all the encoder implementations, or if listing may happen multiple
times.

Fixes #15538
Fixes #14837

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #15604)
openssl-machine pushed a commit that referenced this pull request Jun 15, 2021
This is refactored to use inner_evp_generic_fetch() without any given
name, which is just there to ensure all decoder implementations are
made into methods, and then use ossl_method_store_do_all() to list
them all.

This also adds the internal evp_generic_do_all_prefetched(), which
can be used if pre-fetching needs to be done separately from listing
all the decoder implementations, or if listing may happen multiple
times.

Fixes #15538
Fixes #14837

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #15604)
openssl-machine pushed a commit that referenced this pull request Jun 15, 2021
…c_do_all()

Fixes #15538
Fixes #14837

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #15604)
openssl-machine pushed a commit that referenced this pull request Jun 15, 2021
Now that we have functions to get the name and properties of the
diverse implementations, we can as well display them for clarity.

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #15604)
openssl-machine pushed a commit that referenced this pull request Jun 15, 2021
If there is an error report, we want to get it printed too.

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #15604)
openssl-machine pushed a commit that referenced this pull request Jun 15, 2021
…E_LOADER_fetch()

This is refactored to use inner_loader_fetch() without any given name,
which is just there to ensure all decoder implementations are made
into methods, and then use ossl_method_store_do_all() to list them
all.

This also adds the internal ossl_store_loader_do_all_prefetched(),
which can be used if pre-fetching needs to be done separately from
listing all the decoder implementations, or if listing may happen
multiple times.

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #15604)
@levitte

levitte commented Jun 15, 2021

Copy link
Copy Markdown
Member Author

Merged

f0191d0 Add the internal function ossl_method_store_do_all()
0756282 Refactor OSSL_DECODER_do_all_provided() to behave like OSSL_DECODER_fetch()
b3f5d5d Refactor OSSL_ENCODER_do_all_provided() to behave like OSSL_ENCODER_fetch()
793b058 Refactor evp_generic_do_all() to behave like evp_generic_fetch()
cd77073 Adapt all public EVP_XXX_do_all_provided() for the changed evp_generic_do_all()
27fb7a0 DECODER & ENCODER: Add better tracing
5d8ad7d test/evp_extra_test.c: Peek at the error instead of getting it.
29b3fda Refactor OSSL_STORE_LOADER_do_all_provided() to behave like OSSL_STORE_LOADER_fetch()

@levitte levitte closed this Jun 15, 2021
@levitte
levitte deleted the refactor_XXX_do_all_provided branch June 15, 2021 14:41
devnexen pushed a commit to devnexen/openssl that referenced this pull request Jul 7, 2021
It will simply call the given callback for every method found in the
given store.

Fixes openssl#15538
Fixes openssl#14837

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#15604)
devnexen pushed a commit to devnexen/openssl that referenced this pull request Jul 7, 2021
…etch()

This is refactored to use inner_ossl_decoder_fetch() without any given
name, which is just there to ensure all decoder implementations are
made into methods, and then use ossl_method_store_do_all() to list
them all.

This also adds the internal ossl_decoder_do_all_prefetched(), which
can be used if pre-fetching needs to be done separately from listing
all the decoder implementations, or if listing may happen multiple
times.

Fixes openssl#15538
Fixes openssl#14837

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#15604)
devnexen pushed a commit to devnexen/openssl that referenced this pull request Jul 7, 2021
…etch()

This is refactored to use inner_ossl_encoder_fetch() without any given
name, which is just there to ensure all encoder implementations are
made into methods, and then use ossl_method_store_do_all() to list
them all.

This also adds the internal ossl_encoder_do_all_prefetched(), which
can be used if pre-fetching needs to be done separately from listing
all the encoder implementations, or if listing may happen multiple
times.

Fixes openssl#15538
Fixes openssl#14837

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#15604)
devnexen pushed a commit to devnexen/openssl that referenced this pull request Jul 7, 2021
This is refactored to use inner_evp_generic_fetch() without any given
name, which is just there to ensure all decoder implementations are
made into methods, and then use ossl_method_store_do_all() to list
them all.

This also adds the internal evp_generic_do_all_prefetched(), which
can be used if pre-fetching needs to be done separately from listing
all the decoder implementations, or if listing may happen multiple
times.

Fixes openssl#15538
Fixes openssl#14837

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#15604)
devnexen pushed a commit to devnexen/openssl that referenced this pull request Jul 7, 2021
…c_do_all()

Fixes openssl#15538
Fixes openssl#14837

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#15604)
devnexen pushed a commit to devnexen/openssl that referenced this pull request Jul 7, 2021
Now that we have functions to get the name and properties of the
diverse implementations, we can as well display them for clarity.

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#15604)
devnexen pushed a commit to devnexen/openssl that referenced this pull request Jul 7, 2021
If there is an error report, we want to get it printed too.

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#15604)
devnexen pushed a commit to devnexen/openssl that referenced this pull request Jul 7, 2021
…E_LOADER_fetch()

This is refactored to use inner_loader_fetch() without any given name,
which is just there to ensure all decoder implementations are made
into methods, and then use ossl_method_store_do_all() to list them
all.

This also adds the internal ossl_store_loader_do_all_prefetched(),
which can be used if pre-fetching needs to be done separately from
listing all the decoder implementations, or if listing may happen
multiple times.

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#15604)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch severity: fips change The pull request changes FIPS provider sources

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XXX_do_all_provided() recreates every method, every time it's called. Extreme number of memory allocation calls

7 participants