[RFC] pps: Increase PPS_MAX_SOURCES value.

Message ID 20230605203147.694716-1-charlie.johnston@ni.com
State New
Headers
Series [RFC] pps: Increase PPS_MAX_SOURCES value. |

Commit Message

Charlie Johnston June 5, 2023, 8:31 p.m. UTC
  For consistency with what ptp uses for minors, this
change sets PPS_MAX_SOURCES to MINORMASK + 1.

The PPS_MAX_SOURCES value is currently set to 16. In
some cases this was not sufficient for a system. For
example, a system with multiple (4+) PCIe cards each
with 4 PTP-capable ethernet interfaces could run out
of the available PPS major:minors if each interface
registers a PPS source.

Signed-off-by: Charlie Johnston <charlie.johnston@ni.com>
---
 include/uapi/linux/pps.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Rodolfo Giometti June 7, 2023, 7:33 a.m. UTC | #1
On 05/06/23 22:31, Charlie Johnston wrote:
> For consistency with what ptp uses for minors, this
> change sets PPS_MAX_SOURCES to MINORMASK + 1.
> 
> The PPS_MAX_SOURCES value is currently set to 16. In
> some cases this was not sufficient for a system. For
> example, a system with multiple (4+) PCIe cards each
> with 4 PTP-capable ethernet interfaces could run out
> of the available PPS major:minors if each interface
> registers a PPS source.
> 
> Signed-off-by: Charlie Johnston <charlie.johnston@ni.com>
> ---
>   include/uapi/linux/pps.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/uapi/linux/pps.h b/include/uapi/linux/pps.h
> index 009ebcd8ced5..85f472330da8 100644
> --- a/include/uapi/linux/pps.h
> +++ b/include/uapi/linux/pps.h
> @@ -26,7 +26,7 @@
>   #include <linux/types.h>
>   
>   #define PPS_VERSION		"5.3.6"
> -#define PPS_MAX_SOURCES		16		/* should be enough... */
> +#define PPS_MAX_SOURCES		(MINORMASK + 1)
>   
>   /* Implementation note: the logical states ``assert'' and ``clear''
>    * are implemented in terms of the chip register, i.e. ``assert''

I have just one question: are you sure that it's safe to call idr_alloc(..., 0, 
(MINORMASK + 1), ...)?

Ciao,

Rodolfo
  
Charlie Johnston June 7, 2023, 10:07 p.m. UTC | #2
On 6/7/23 02:33, Rodolfo Giometti wrote:
> On 05/06/23 22:31, Charlie Johnston wrote:
>> For consistency with what ptp uses for minors, this
>> change sets PPS_MAX_SOURCES to MINORMASK + 1.
>>
>> The PPS_MAX_SOURCES value is currently set to 16. In
>> some cases this was not sufficient for a system. For
>> example, a system with multiple (4+) PCIe cards each
>> with 4 PTP-capable ethernet interfaces could run out
>> of the available PPS major:minors if each interface
>> registers a PPS source.
>>
>> Signed-off-by: Charlie Johnston <charlie.johnston@ni.com>
>> ---
>>   include/uapi/linux/pps.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/uapi/linux/pps.h b/include/uapi/linux/pps.h
>> index 009ebcd8ced5..85f472330da8 100644
>> --- a/include/uapi/linux/pps.h
>> +++ b/include/uapi/linux/pps.h
>> @@ -26,7 +26,7 @@
>>   #include <linux/types.h>
>>     #define PPS_VERSION        "5.3.6"
>> -#define PPS_MAX_SOURCES        16        /* should be enough... */
>> +#define PPS_MAX_SOURCES        (MINORMASK + 1)
>>     /* Implementation note: the logical states ``assert'' and ``clear''
>>    * are implemented in terms of the chip register, i.e. ``assert''
> 
> I have just one question: are you sure that it's safe to call idr_alloc(..., 0, (MINORMASK + 1), ...)?
> 
> Ciao,
> 
> Rodolfo
> 

Thanks for taking a look!

My understanding is that idr_alloc(..., start, end, ...) can take any end value up to INT_MAX. It also handles any values <= 0 by treating them as equal to INT_MAX + 1 since the end value is non-inclusive. I can't think of any reason using MINORMASK + 1 here would be an issue since it's much less than the maximum value idr_alloc() allows.

A number of drivers (e.g. ptp) just explicitly use a start and end value of 0, but I don't think that change would fit here.

Regards,
Charlie
  
Rodolfo Giometti June 9, 2023, 7:30 a.m. UTC | #3
On 08/06/23 00:07, Charlie Johnston wrote:
> On 6/7/23 02:33, Rodolfo Giometti wrote:
>> On 05/06/23 22:31, Charlie Johnston wrote:
>>> For consistency with what ptp uses for minors, this
>>> change sets PPS_MAX_SOURCES to MINORMASK + 1.
>>>
>>> The PPS_MAX_SOURCES value is currently set to 16. In
>>> some cases this was not sufficient for a system. For
>>> example, a system with multiple (4+) PCIe cards each
>>> with 4 PTP-capable ethernet interfaces could run out
>>> of the available PPS major:minors if each interface
>>> registers a PPS source.
>>>
>>> Signed-off-by: Charlie Johnston <charlie.johnston@ni.com>
>>> ---
>>>    include/uapi/linux/pps.h | 2 +-
>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/include/uapi/linux/pps.h b/include/uapi/linux/pps.h
>>> index 009ebcd8ced5..85f472330da8 100644
>>> --- a/include/uapi/linux/pps.h
>>> +++ b/include/uapi/linux/pps.h
>>> @@ -26,7 +26,7 @@
>>>    #include <linux/types.h>
>>>      #define PPS_VERSION        "5.3.6"
>>> -#define PPS_MAX_SOURCES        16        /* should be enough... */
>>> +#define PPS_MAX_SOURCES        (MINORMASK + 1)
>>>      /* Implementation note: the logical states ``assert'' and ``clear''
>>>     * are implemented in terms of the chip register, i.e. ``assert''
>>
>> I have just one question: are you sure that it's safe to call idr_alloc(..., 0, (MINORMASK + 1), ...)?
>>
>> Ciao,
>>
>> Rodolfo
>>
> 
> Thanks for taking a look!
> 
> My understanding is that idr_alloc(..., start, end, ...) can take any end value up to INT_MAX. It also handles any values <= 0 by treating them as equal to INT_MAX + 1 since the end value is non-inclusive. I can't think of any reason using MINORMASK + 1 here would be an issue since it's much less than the maximum value idr_alloc() allows.
> 
> A number of drivers (e.g. ptp) just explicitly use a start and end value of 0, but I don't think that change would fit here.

I see and maybe I should replace the usage of idr_*() with ida_*() as PTP does...

However the right-thing(TM) to do here should be dropping PPS_MAX_SOURCES at all!

Let me go deeper in this issue. I'm going to produce a patch set in next days. 
Have you any chances to test it?

Ciao,

Rodolfo
  
Charlie Johnston June 9, 2023, 9 p.m. UTC | #4
On 6/9/23 02:30, Rodolfo Giometti wrote:
> On 08/06/23 00:07, Charlie Johnston wrote:
>> On 6/7/23 02:33, Rodolfo Giometti wrote:
>>> On 05/06/23 22:31, Charlie Johnston wrote:
>>>> For consistency with what ptp uses for minors, this
>>>> change sets PPS_MAX_SOURCES to MINORMASK + 1.
>>>>
>>>> The PPS_MAX_SOURCES value is currently set to 16. In
>>>> some cases this was not sufficient for a system. For
>>>> example, a system with multiple (4+) PCIe cards each
>>>> with 4 PTP-capable ethernet interfaces could run out
>>>> of the available PPS major:minors if each interface
>>>> registers a PPS source.
>>>>
>>>> Signed-off-by: Charlie Johnston <charlie.johnston@ni.com>
>>>> ---
>>>>    include/uapi/linux/pps.h | 2 +-
>>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/include/uapi/linux/pps.h b/include/uapi/linux/pps.h
>>>> index 009ebcd8ced5..85f472330da8 100644
>>>> --- a/include/uapi/linux/pps.h
>>>> +++ b/include/uapi/linux/pps.h
>>>> @@ -26,7 +26,7 @@
>>>>    #include <linux/types.h>
>>>>      #define PPS_VERSION        "5.3.6"
>>>> -#define PPS_MAX_SOURCES        16        /* should be enough... */
>>>> +#define PPS_MAX_SOURCES        (MINORMASK + 1)
>>>>      /* Implementation note: the logical states ``assert'' and ``clear''
>>>>     * are implemented in terms of the chip register, i.e. ``assert''
>>>
>>> I have just one question: are you sure that it's safe to call idr_alloc(..., 0, (MINORMASK + 1), ...)?
>>>
>>> Ciao,
>>>
>>> Rodolfo
>>>
>>
>> Thanks for taking a look!
>>
>> My understanding is that idr_alloc(..., start, end, ...) can take any end value up to INT_MAX. It also handles any values <= 0 by treating them as equal to INT_MAX + 1 since the end value is non-inclusive. I can't think of any reason using MINORMASK + 1 here would be an issue since it's much less than the maximum value idr_alloc() allows.
>>
>> A number of drivers (e.g. ptp) just explicitly use a start and end value of 0, but I don't think that change would fit here.
> 
> I see and maybe I should replace the usage of idr_*() with ida_*() as PTP does...
> 
> However the right-thing(TM) to do here should be dropping PPS_MAX_SOURCES at all!
> 
> Let me go deeper in this issue. I'm going to produce a patch set in next days. Have you any chances to test it?
> 
> Ciao,
> 
> Rodolfo
> 

I'll have to check when the system we used for testing is available again (not easy to find a system with 20+ Ethernet ports) but I'd be happy to test a patch!

I know an increase to PPS_MAX_SOURCES was tested on that system.

Thanks,
Charlie
  
Rodolfo Giometti June 12, 2023, 4:07 p.m. UTC | #5
On 09/06/23 23:00, Charlie Johnston wrote:
> On 6/9/23 02:30, Rodolfo Giometti wrote:
>> On 08/06/23 00:07, Charlie Johnston wrote:
>>> On 6/7/23 02:33, Rodolfo Giometti wrote:
>>>> On 05/06/23 22:31, Charlie Johnston wrote:
>>>>> For consistency with what ptp uses for minors, this
>>>>> change sets PPS_MAX_SOURCES to MINORMASK + 1.
>>>>>
>>>>> The PPS_MAX_SOURCES value is currently set to 16. In
>>>>> some cases this was not sufficient for a system. For
>>>>> example, a system with multiple (4+) PCIe cards each
>>>>> with 4 PTP-capable ethernet interfaces could run out
>>>>> of the available PPS major:minors if each interface
>>>>> registers a PPS source.
>>>>>
>>>>> Signed-off-by: Charlie Johnston <charlie.johnston@ni.com>
>>>>> ---
>>>>>     include/uapi/linux/pps.h | 2 +-
>>>>>     1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/include/uapi/linux/pps.h b/include/uapi/linux/pps.h
>>>>> index 009ebcd8ced5..85f472330da8 100644
>>>>> --- a/include/uapi/linux/pps.h
>>>>> +++ b/include/uapi/linux/pps.h
>>>>> @@ -26,7 +26,7 @@
>>>>>     #include <linux/types.h>
>>>>>       #define PPS_VERSION        "5.3.6"
>>>>> -#define PPS_MAX_SOURCES        16        /* should be enough... */
>>>>> +#define PPS_MAX_SOURCES        (MINORMASK + 1)
>>>>>       /* Implementation note: the logical states ``assert'' and ``clear''
>>>>>      * are implemented in terms of the chip register, i.e. ``assert''
>>>>
>>>> I have just one question: are you sure that it's safe to call idr_alloc(..., 0, (MINORMASK + 1), ...)?
>>>>
>>>> Ciao,
>>>>
>>>> Rodolfo
>>>>
>>>
>>> Thanks for taking a look!
>>>
>>> My understanding is that idr_alloc(..., start, end, ...) can take any end value up to INT_MAX. It also handles any values <= 0 by treating them as equal to INT_MAX + 1 since the end value is non-inclusive. I can't think of any reason using MINORMASK + 1 here would be an issue since it's much less than the maximum value idr_alloc() allows.
>>>
>>> A number of drivers (e.g. ptp) just explicitly use a start and end value of 0, but I don't think that change would fit here.
>>
>> I see and maybe I should replace the usage of idr_*() with ida_*() as PTP does...
>>
>> However the right-thing(TM) to do here should be dropping PPS_MAX_SOURCES at all!
>>
>> Let me go deeper in this issue. I'm going to produce a patch set in next days. Have you any chances to test it?
>>
>> Ciao,
>>
>> Rodolfo
>>
> MINORMASK
> I'll have to check when the system we used for testing is available again (not easy to find a system with 20+ Ethernet ports) but I'd be happy to test a patch!

Great! Please, let me know.

> I know an increase to PPS_MAX_SOURCES was tested on that system.

I see and it seems that it's safer to set PPS_MAX_SOURCES to MINORMASK... so 
please reproduce your patch with this simple modification, then I'm going to 
produce a patch to drop the PPS_MAX_SOURCES define since it's not needed anymore.

After that you should test all these modifications in order to safely add them 
to Linux.

Ciao,

Rodolfo
  
Charlie Johnston June 20, 2023, 8:42 p.m. UTC | #6
On 6/12/23 11:07, Rodolfo Giometti wrote:
> On 09/06/23 23:00, Charlie Johnston wrote:
>> On 6/9/23 02:30, Rodolfo Giometti wrote:
>>> On 08/06/23 00:07, Charlie Johnston wrote:
>>>> On 6/7/23 02:33, Rodolfo Giometti wrote:
>>>>> On 05/06/23 22:31, Charlie Johnston wrote:
>>>>>> For consistency with what ptp uses for minors, this
>>>>>> change sets PPS_MAX_SOURCES to MINORMASK + 1.
>>>>>>
>>>>>> The PPS_MAX_SOURCES value is currently set to 16. In
>>>>>> some cases this was not sufficient for a system. For
>>>>>> example, a system with multiple (4+) PCIe cards each
>>>>>> with 4 PTP-capable ethernet interfaces could run out
>>>>>> of the available PPS major:minors if each interface
>>>>>> registers a PPS source.
>>>>>>
>>>>>> Signed-off-by: Charlie Johnston <charlie.johnston@ni.com>
>>>>>> ---
>>>>>>     include/uapi/linux/pps.h | 2 +-
>>>>>>     1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>>
>>>>>> diff --git a/include/uapi/linux/pps.h b/include/uapi/linux/pps.h
>>>>>> index 009ebcd8ced5..85f472330da8 100644
>>>>>> --- a/include/uapi/linux/pps.h
>>>>>> +++ b/include/uapi/linux/pps.h
>>>>>> @@ -26,7 +26,7 @@
>>>>>>     #include <linux/types.h>
>>>>>>       #define PPS_VERSION        "5.3.6"
>>>>>> -#define PPS_MAX_SOURCES        16        /* should be enough... */
>>>>>> +#define PPS_MAX_SOURCES        (MINORMASK + 1)
>>>>>>       /* Implementation note: the logical states ``assert'' and ``clear''
>>>>>>      * are implemented in terms of the chip register, i.e. ``assert''
>>>>>
>>>>> I have just one question: are you sure that it's safe to call idr_alloc(..., 0, (MINORMASK + 1), ...)?
>>>>>
>>>>> Ciao,
>>>>>
>>>>> Rodolfo
>>>>>
>>>>
>>>> Thanks for taking a look!
>>>>
>>>> My understanding is that idr_alloc(..., start, end, ...) can take any end value up to INT_MAX. It also handles any values <= 0 by treating them as equal to INT_MAX + 1 since the end value is non-inclusive. I can't think of any reason using MINORMASK + 1 here would be an issue since it's much less than the maximum value idr_alloc() allows.
>>>>
>>>> A number of drivers (e.g. ptp) just explicitly use a start and end value of 0, but I don't think that change would fit here.
>>>
>>> I see and maybe I should replace the usage of idr_*() with ida_*() as PTP does...
>>>
>>> However the right-thing(TM) to do here should be dropping PPS_MAX_SOURCES at all!
>>>
>>> Let me go deeper in this issue. I'm going to produce a patch set in next days. Have you any chances to test it?
>>>
>>> Ciao,
>>>
>>> Rodolfo
>>>
>> MINORMASK
>> I'll have to check when the system we used for testing is available again (not easy to find a system with 20+ Ethernet ports) but I'd be happy to test a patch!
> 
> Great! Please, let me know.
> 
>> I know an increase to PPS_MAX_SOURCES was tested on that system.
> 
> I see and it seems that it's safer to set PPS_MAX_SOURCES to MINORMASK... so please reproduce your patch with this simple modification, then I'm going to produce a patch to drop the PPS_MAX_SOURCES define since it's not needed anymore.
> 
> After that you should test all these modifications in order to safely add them to Linux.
> 
> Ciao,
> 
> Rodolfo
> 

I've resubmitted the patch with just PPS_MAX_SOURCES = MINORMASK. The system which hits the limit and causes the problem is currently available for testing. 

Is there anything you'd like me to try running? Or just confirm the limit change works?

Thanks,
Charlie
  
Rodolfo Giometti June 21, 2023, 3:31 p.m. UTC | #7
On 20/06/23 22:42, Charlie Johnston wrote:
> I've resubmitted the patch with just PPS_MAX_SOURCES = MINORMASK. The system which hits the limit and causes the problem is currently available for testing.
> 
> Is there anything you'd like me to try running? Or just confirm the limit change works?

Sorry for the delay (i was very busy in these days)! Please, test the attached 
two patches.

Ciao,

Rodolfo
  
Charlie Johnston June 23, 2023, 2:03 a.m. UTC | #8
On 6/21/23 10:31, Rodolfo Giometti wrote:
> On 20/06/23 22:42, Charlie Johnston wrote:
>> I've resubmitted the patch with just PPS_MAX_SOURCES = MINORMASK. The system which hits the limit and causes the problem is currently available for testing.
>>
>> Is there anything you'd like me to try running? Or just confirm the limit change works?
> 
> Sorry for the delay (i was very busy in these days)! Please, test the attached 
> two patches.
> 
> Ciao,
> 
> Rodolfo
> 

Had some time to test today. Everything I tried appeared to work and the message log indicated sources were available for each port.

[    1.853052] pps_core: LinuxPPS API ver. 1 registered
[    2.749945] pps pps0: new PPS source ptp0
[    2.790179] pps pps1: new PPS source ptp1
[    2.818900] pps pps2: new PPS source ptp3
...
[    6.326282] pps pps26: new PPS source ptp27
[    6.354941] pps pps27: new PPS source ptp28
[    6.383575] pps pps28: new PPS source ptp29

Thanks for the quick turnaround on the patches!
Charlie
  

Patch

diff --git a/include/uapi/linux/pps.h b/include/uapi/linux/pps.h
index 009ebcd8ced5..85f472330da8 100644
--- a/include/uapi/linux/pps.h
+++ b/include/uapi/linux/pps.h
@@ -26,7 +26,7 @@ 
 #include <linux/types.h>
 
 #define PPS_VERSION		"5.3.6"
-#define PPS_MAX_SOURCES		16		/* should be enough... */
+#define PPS_MAX_SOURCES		(MINORMASK + 1)
 
 /* Implementation note: the logical states ``assert'' and ``clear''
  * are implemented in terms of the chip register, i.e. ``assert''