New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event queue #18345
Event queue #18345
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conspicuous by their absence are event queue tests
ssl/event_queue.c
Outdated
|
||
if (e != NULL) { | ||
ossl_event_set(e, type, priority, when, ctx, payload, payload_size); | ||
e->flag_dynamic = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me wonder why we need non-dynamic events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A non-dynamic event can be embedded into another structure. i.e. cuts overhead allocating and freeing.
E.g. a re-transmit timer event will always exist with a connection -- do we need to allocate it separately?
Dropping non-dynamic is possible, but it feels like it will be useful.
I didn't do tests because there is no guarantee that this approach will be used. It definitely isn't quite ready to go at this point. |
doc/internal/man3/OSSL_EVENT.pod
Outdated
=item type | ||
|
||
A mandatory event type, which is a simple numeric identity, the | ||
meaning of which is not known by the event functionality itself. | ||
|
||
=item priority | ||
|
||
A manatory nonnegative integral quantity. The lower the priority the earlier | ||
the event will be processes. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked the Richard's suggestion from our discussion that a type might have an inherent priority and we would not need a separate priority value.
A few more comments: I suppose the events will be sorted by My another concern is with the subscription concept - I wonder whether this isn't overcomplicating things, in a way that requires complicated setup of the subscriptions. Couldn't we have for example a simple static per-type callback table? I mean the callback data and the context should provide enough contextual data. Do we think we will have multiple subscribers for each event type? |
@t8m, good points. For dispatch point, it would be possible to extract a list of events that need to run now and sort them by priority rather than time. The main list would be sorted by time only and immediate events would go into the second queue only. I'm sure about the subscriptions either. There are multiple options (in rough order of complexity):
They should all be fairly easy to convert between, e.g. the SSL_METHOD could install the per type handlers during initialisation or a single global event hander could dispatch by type to SSL_METHOD handlers. |
Embeddable or not? The reasons for making the event structure embeddable is efficiency. I see two primary use cases:
struct {
// my fields
...
// event
OSSL_EVENT event;
} mydata;
ossl_event_queue_add(queue, &mydata->event);
The reasons against are modularity and good coding practices. Is this a premature optimisation? |
Uhm no. My design allowed multiple subscribers per event type. This was meant to allow a fork where needed... |
I like the concept of embeddable events as I strongly suspect that for reasonable performance the library should avoid mallocs whenever possible. Retrofitting them into the design later when we'll find that the performance is sub-par might be quite a complicated effort. IMO the biggest concern with embeddable events is the embedded event lifetime - i.e., how to ensure the enclosing object is not prematurely freed, or that the event is forcibly removed from the queue when freeing the enclosing object. |
I think this should be sufficient for our needs. Unless we want to have some user-supplied callbacks directly used as event handlers for some event types. However I am not sure we need this as the callback(s) can be invoked from the static event handler instead. IMO refactoring the dispatch if we find out that we really need multiple handlers per event type should not be too big effort. |
e5c668b
to
219d97b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good on the whole.
struct ossl_event_st { | ||
uint32_t type; /* What type of event this is */ | ||
uint32_t priority; /* What priority this event has */ | ||
OSSL_TIME when; /* When the event is scheduled to happen */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think we can combine type and priority, and just call it type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm quite hesitant here. Keeping them distinct adds quite an amount of flexibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's tempting to remove type
altogether since it's not something the event queue actually cares about anymore.
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl/openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl#18345)
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from openssl#18345)
Partial implementation of an event queue on top of #18274
This should be enough to get a feel for the design