You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mynewt.apache.org by Sterling Hughes <st...@apache.org> on 2016/04/04 17:14:04 UTC

os_eventq_get() + timeout

Hey,

I'm looking at: https://issues.apache.org/jira/browse/MYNEWT-8

I'm wondering if I should break BC on this one, and add a new parameter, 
or add a new function call:

- os_eventq_select()

OS_EVENTQ_MASK(my_mask, EVENT_T_TIMER);
OS_EVENTQ_MASK(my_mask, EVENT_T_DATA);

/* timeout after 200 ticks */
ev = os_eventq_select(&my_evq, &my_mask, 200);

Thoughts?

Sterling

PS: For the uninitiated, os_eventq_get() works as follows.

In your task, you create an eventq with os_eventq_init(), and then you 
wait (forever) on os_eventq_get().

If you (currently) want to not wait forever, you can use a callout, 
which will post an event to the eventq after a certain time expires.

   while (1) {
     ev = os_eventq_get(&my_evq);
     switch (ev->ev_type) {
         case EVENT_T_DATA: /* read data from socket */
   	  recv_data();
         case EVENT_T_TIMER: /* timer expired */
	  os_callout_reset(&my_callout, &my_evq, 20);
     }
   }

Re: os_eventq_get() + timeout

Posted by will sanfilippo <wi...@runtime.io>.
Sounds good to me
+1

> On Apr 4, 2016, at 9:16 AM, Sterling Hughes <st...@gmail.com> wrote:
> 
> 
> 
>> On Apr 4, 2016, at 9:13 AM, will sanfilippo <wi...@runtime.io> wrote:
>> 
>> I would not break BC; I would add a different function. Not sure what I would call it but wouldnt it just have a timeout, in ticks, associated with it? For example: os_eventq_wait(&my_evq, timeout_in_os_ticks). What is the purpose of the mask btw? Something to do with returning an error if it times out or some way of selecting particular events?
> 
> Right, it would allow you to quickly poll for a set/type of events.  Select is a common UNIX call which does the same thing (the other being poll()).
> 
> I think it's useful to search the queue for a type of event, so if we're adding a new call with timeout, I think we should add that functionality. 
> 
> Sterling 


Re: os_eventq_get() + timeout

Posted by Sterling Hughes <st...@gmail.com>.

> On Apr 4, 2016, at 9:13 AM, will sanfilippo <wi...@runtime.io> wrote:
> 
> I would not break BC; I would add a different function. Not sure what I would call it but wouldnt it just have a timeout, in ticks, associated with it? For example: os_eventq_wait(&my_evq, timeout_in_os_ticks). What is the purpose of the mask btw? Something to do with returning an error if it times out or some way of selecting particular events?

Right, it would allow you to quickly poll for a set/type of events.  Select is a common UNIX call which does the same thing (the other being poll()).

I think it's useful to search the queue for a type of event, so if we're adding a new call with timeout, I think we should add that functionality. 

Sterling 

Re: os_eventq_get() + timeout

Posted by marko kiiskila <ma...@runtime.io>.
> On Apr 4, 2016, at 12:09 PM, Sterling Hughes <st...@apache.org> wrote:
> 
> hi,
> 
> On 4/4/16 11:59 AM, marko kiiskila wrote:
>> 
>>> On Apr 4, 2016, at 11:33 AM, Sterling Hughes <st...@apache.org> wrote:
>>> 
>>>> I don’t think the select() kind of mask is a good idea. eventq_XXX is more
>>>> like kqueue() rather than select(). I don’t think there are that many places
>>>> where you’d want to mask out some events and not others. Especially
>>>> as this’ll mean that there will presumably will mean that events will get
>>>> delivered out of order.
>>>> 
>>> 
>>> Would you prefer that eventq_poll() poll multiple eventq and return when an event is available on one of them, or there is a timeout?   I can understand wanting to preserve ordering on the queue, and things getting confusing if app code isn't smart about this.
>>> 
>>> However, I think it is a fairly common access mechanism to want to grab only certain events from a queue.  Imagine a case where you send a packet, and you are waiting for a response, and you only want to pull events related to response from the eventq, even if you have multiple events that can run through that queue.  I see two options for handling this neatly:
>>> 
>>> 1- Have a mask, and only pull events off that queue which match the mask
>>> 2- Have eventq_poll() take multiple event queues, so that you can poll multiple queues at once.
>>> 
>>> What do you think?
>>> 
>> 
>> Converting an array of integers to bit mask in the caller, and doing the reverse
>> in the callee is not too great.
>> 
>> Option 2 sounds much, much better.
>> 
> 
> OK, cool.
> 
> So, this is the API I'm thinking of:
> 
> struct os_event *
> os_eventq_poll(struct os_eventq **evq, int n, os_time_t timo);
> 
> Where evq is an array of eventq to poll, and n is the number of elements in that array.  timo represents the timeout in ticks, across all the eventqs.
> 
> This function returns NULL on no events within timo, or the first available event if not.   timo can be OS_WAIT_FOREVER, if caller wishes to sleep until an event becomes available.
> 
> Sterling

+1


Re: os_eventq_get() + timeout

Posted by Vipul Rahane <vi...@runtime.io>.
+1 for option#2 and Sterlings implementation.
Next request by someone might be to have a timeout per eventq. 

  
> On Apr 4, 2016, at 12:09 PM, Sterling Hughes <st...@apache.org> wrote:
> 
> hi,
> 
> On 4/4/16 11:59 AM, marko kiiskila wrote:
>> 
>>> On Apr 4, 2016, at 11:33 AM, Sterling Hughes <st...@apache.org> wrote:
>>> 
>>>> I don’t think the select() kind of mask is a good idea. eventq_XXX is more
>>>> like kqueue() rather than select(). I don’t think there are that many places
>>>> where you’d want to mask out some events and not others. Especially
>>>> as this’ll mean that there will presumably will mean that events will get
>>>> delivered out of order.
>>>> 
>>> 
>>> Would you prefer that eventq_poll() poll multiple eventq and return when an event is available on one of them, or there is a timeout?   I can understand wanting to preserve ordering on the queue, and things getting confusing if app code isn't smart about this.
>>> 
>>> However, I think it is a fairly common access mechanism to want to grab only certain events from a queue.  Imagine a case where you send a packet, and you are waiting for a response, and you only want to pull events related to response from the eventq, even if you have multiple events that can run through that queue.  I see two options for handling this neatly:
>>> 
>>> 1- Have a mask, and only pull events off that queue which match the mask
>>> 2- Have eventq_poll() take multiple event queues, so that you can poll multiple queues at once.
>>> 
>>> What do you think?
>>> 
>> 
>> Converting an array of integers to bit mask in the caller, and doing the reverse
>> in the callee is not too great.
>> 
>> Option 2 sounds much, much better.
>> 
> 
> OK, cool.
> 
> So, this is the API I'm thinking of:
> 
> struct os_event *
> os_eventq_poll(struct os_eventq **evq, int n, os_time_t timo);
> 
> Where evq is an array of eventq to poll, and n is the number of elements in that array.  timo represents the timeout in ticks, across all the eventqs.
> 
> This function returns NULL on no events within timo, or the first available event if not.   timo can be OS_WAIT_FOREVER, if caller wishes to sleep until an event becomes available.
> 
> Sterling


Re: os_eventq_get() + timeout

Posted by Sterling Hughes <st...@apache.org>.
hi,

On 4/4/16 11:59 AM, marko kiiskila wrote:
>
>> On Apr 4, 2016, at 11:33 AM, Sterling Hughes <st...@apache.org> wrote:
>>
>>> I don’t think the select() kind of mask is a good idea. eventq_XXX is more
>>> like kqueue() rather than select(). I don’t think there are that many places
>>> where you’d want to mask out some events and not others. Especially
>>> as this’ll mean that there will presumably will mean that events will get
>>> delivered out of order.
>>>
>>
>> Would you prefer that eventq_poll() poll multiple eventq and return when an event is available on one of them, or there is a timeout?   I can understand wanting to preserve ordering on the queue, and things getting confusing if app code isn't smart about this.
>>
>> However, I think it is a fairly common access mechanism to want to grab only certain events from a queue.  Imagine a case where you send a packet, and you are waiting for a response, and you only want to pull events related to response from the eventq, even if you have multiple events that can run through that queue.  I see two options for handling this neatly:
>>
>> 1- Have a mask, and only pull events off that queue which match the mask
>> 2- Have eventq_poll() take multiple event queues, so that you can poll multiple queues at once.
>>
>> What do you think?
>>
>
> Converting an array of integers to bit mask in the caller, and doing the reverse
> in the callee is not too great.
>
> Option 2 sounds much, much better.
>

OK, cool.

So, this is the API I'm thinking of:

struct os_event *
os_eventq_poll(struct os_eventq **evq, int n, os_time_t timo);

Where evq is an array of eventq to poll, and n is the number of elements 
in that array.  timo represents the timeout in ticks, across all the 
eventqs.

This function returns NULL on no events within timo, or the first 
available event if not.   timo can be OS_WAIT_FOREVER, if caller wishes 
to sleep until an event becomes available.

Sterling

Re: os_eventq_get() + timeout

Posted by marko kiiskila <ma...@runtime.io>.
> On Apr 4, 2016, at 11:33 AM, Sterling Hughes <st...@apache.org> wrote:
> 
>> I don’t think the select() kind of mask is a good idea. eventq_XXX is more
>> like kqueue() rather than select(). I don’t think there are that many places
>> where you’d want to mask out some events and not others. Especially
>> as this’ll mean that there will presumably will mean that events will get
>> delivered out of order.
>> 
> 
> Would you prefer that eventq_poll() poll multiple eventq and return when an event is available on one of them, or there is a timeout?   I can understand wanting to preserve ordering on the queue, and things getting confusing if app code isn't smart about this.
> 
> However, I think it is a fairly common access mechanism to want to grab only certain events from a queue.  Imagine a case where you send a packet, and you are waiting for a response, and you only want to pull events related to response from the eventq, even if you have multiple events that can run through that queue.  I see two options for handling this neatly:
> 
> 1- Have a mask, and only pull events off that queue which match the mask
> 2- Have eventq_poll() take multiple event queues, so that you can poll multiple queues at once.
> 
> What do you think?
> 

Converting an array of integers to bit mask in the caller, and doing the reverse
in the callee is not too great.

Option 2 sounds much, much better.

Re: os_eventq_get() + timeout

Posted by Sterling Hughes <st...@apache.org>.

On 4/4/16 10:50 AM, marko kiiskila wrote:
> Hi,
>
> You get the timeout functionality by adding an timeout event on your own
> to get the same functionality. Would not be a big burden.
>
> However, this kind of convenience function should be ok. You could
> even have that guy implement it this way, as opposed to adding additional
> code to eventq_get() itself.
>

Yeah, I think many people want to use this.

> I don’t think the select() kind of mask is a good idea. eventq_XXX is more
> like kqueue() rather than select(). I don’t think there are that many places
> where you’d want to mask out some events and not others. Especially
> as this’ll mean that there will presumably will mean that events will get
> delivered out of order.
>

Would you prefer that eventq_poll() poll multiple eventq and return when 
an event is available on one of them, or there is a timeout?   I can 
understand wanting to preserve ordering on the queue, and things getting 
confusing if app code isn't smart about this.

However, I think it is a fairly common access mechanism to want to grab 
only certain events from a queue.  Imagine a case where you send a 
packet, and you are waiting for a response, and you only want to pull 
events related to response from the eventq, even if you have multiple 
events that can run through that queue.  I see two options for handling 
this neatly:

1- Have a mask, and only pull events off that queue which match the mask
2- Have eventq_poll() take multiple event queues, so that you can poll 
multiple queues at once.

What do you think?

Sterling

Re: os_eventq_get() + timeout

Posted by marko kiiskila <ma...@runtime.io>.
Hi,

You get the timeout functionality by adding an timeout event on your own
to get the same functionality. Would not be a big burden.

However, this kind of convenience function should be ok. You could
even have that guy implement it this way, as opposed to adding additional
code to eventq_get() itself.

I don’t think the select() kind of mask is a good idea. eventq_XXX is more
like kqueue() rather than select(). I don’t think there are that many places
where you’d want to mask out some events and not others. Especially
as this’ll mean that there will presumably will mean that events will get
delivered out of order.

> On Apr 4, 2016, at 9:13 AM, will sanfilippo <wi...@runtime.io> wrote:
> 
> I would not break BC; I would add a different function. Not sure what I would call it but wouldnt it just have a timeout, in ticks, associated with it? For example: os_eventq_wait(&my_evq, timeout_in_os_ticks). What is the purpose of the mask btw? Something to do with returning an error if it times out or some way of selecting particular events?
> 
> Will
> 
>> On Apr 4, 2016, at 8:14 AM, Sterling Hughes <st...@apache.org> wrote:
>> 
>> Hey,
>> 
>> I'm looking at: https://issues.apache.org/jira/browse/MYNEWT-8
>> 
>> I'm wondering if I should break BC on this one, and add a new parameter, or add a new function call:
>> 
>> - os_eventq_select()
>> 
>> OS_EVENTQ_MASK(my_mask, EVENT_T_TIMER);
>> OS_EVENTQ_MASK(my_mask, EVENT_T_DATA);
>> 
>> /* timeout after 200 ticks */
>> ev = os_eventq_select(&my_evq, &my_mask, 200);
>> 
>> Thoughts?
>> 
>> Sterling
>> 
>> PS: For the uninitiated, os_eventq_get() works as follows.
>> 
>> In your task, you create an eventq with os_eventq_init(), and then you wait (forever) on os_eventq_get().
>> 
>> If you (currently) want to not wait forever, you can use a callout, which will post an event to the eventq after a certain time expires.
>> 
>> while (1) {
>>   ev = os_eventq_get(&my_evq);
>>   switch (ev->ev_type) {
>>       case EVENT_T_DATA: /* read data from socket */
>> 	  recv_data();
>>       case EVENT_T_TIMER: /* timer expired */
>> 	  os_callout_reset(&my_callout, &my_evq, 20);
>>   }
>> }
> 


Re: os_eventq_get() + timeout

Posted by will sanfilippo <wi...@runtime.io>.
I would not break BC; I would add a different function. Not sure what I would call it but wouldnt it just have a timeout, in ticks, associated with it? For example: os_eventq_wait(&my_evq, timeout_in_os_ticks). What is the purpose of the mask btw? Something to do with returning an error if it times out or some way of selecting particular events?

Will

> On Apr 4, 2016, at 8:14 AM, Sterling Hughes <st...@apache.org> wrote:
> 
> Hey,
> 
> I'm looking at: https://issues.apache.org/jira/browse/MYNEWT-8
> 
> I'm wondering if I should break BC on this one, and add a new parameter, or add a new function call:
> 
> - os_eventq_select()
> 
> OS_EVENTQ_MASK(my_mask, EVENT_T_TIMER);
> OS_EVENTQ_MASK(my_mask, EVENT_T_DATA);
> 
> /* timeout after 200 ticks */
> ev = os_eventq_select(&my_evq, &my_mask, 200);
> 
> Thoughts?
> 
> Sterling
> 
> PS: For the uninitiated, os_eventq_get() works as follows.
> 
> In your task, you create an eventq with os_eventq_init(), and then you wait (forever) on os_eventq_get().
> 
> If you (currently) want to not wait forever, you can use a callout, which will post an event to the eventq after a certain time expires.
> 
>  while (1) {
>    ev = os_eventq_get(&my_evq);
>    switch (ev->ev_type) {
>        case EVENT_T_DATA: /* read data from socket */
>  	  recv_data();
>        case EVENT_T_TIMER: /* timer expired */
> 	  os_callout_reset(&my_callout, &my_evq, 20);
>    }
>  }