Skip to content
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

[posix] adjust posix platform header including #10221

Closed
wants to merge 1 commit into from

Conversation

Irving-cl
Copy link
Contributor

@Irving-cl Irving-cl commented May 11, 2024

This purpose of this PR is to avoid the include chain starting from
posix/platform/xxx_interface.hpp from containing anything from OT
core and lib/platform/exit_code.h. Because xxx_interface.hpp is
included by spinel_manager.hpp which is intended to be used in
ot-br-posix.

The PR does these things:

  • Move those configs that derived from OT configs into a separate
    config file openthread-posix-core-related-config.h and only include
    this file when needed. And remove the including of openthread-core-config.h
    from openthread-posix-config.h.
  • Remove including of platform-posix.h in headers and add necessary
    including. i.e., lib/url/url.hpp. Because platform-posix.h includes
    lib/platform/exit_code.h which contains some widely used name like
    VerifyOrDie and may cause conflicts.
  • In some posix source files, add including of openthread-core-config.h
    if necessary. Originally, these configs were included indirectly by
    the chain openthread-posix-config.h -> openthread-core-config.h

Copy link

size-report bot commented May 11, 2024

Size Report of OpenThread

Merging #10221 into main(be10913).

name branch text data bss total
ot-cli-ftd main 466992 856 66364 534212
#10221 466992 856 66364 534212
+/- 0 0 0 0
ot-ncp-ftd main 435836 760 61576 498172
#10221 435836 760 61576 498172
+/- 0 0 0 0
libopenthread-ftd.a main 236086 95 40310 276491
#10221 236086 95 40310 276491
+/- 0 0 0 0
libopenthread-cli-ftd.a main 57533 0 8075 65608
#10221 57533 0 8075 65608
+/- 0 0 0 0
libopenthread-ncp-ftd.a main 31863 0 5916 37779
#10221 31863 0 5916 37779
+/- 0 0 0 0
ot-cli-mtd main 364456 760 51220 416436
#10221 364456 760 51220 416436
+/- 0 0 0 0
ot-ncp-mtd main 346980 760 46448 394188
#10221 346980 760 46448 394188
+/- 0 0 0 0
libopenthread-mtd.a main 158097 0 25182 183279
#10221 158097 0 25182 183279
+/- 0 0 0 0
libopenthread-cli-mtd.a main 39756 0 8059 47815
#10221 39756 0 8059 47815
+/- 0 0 0 0
libopenthread-ncp-mtd.a main 24743 0 5916 30659
#10221 24743 0 5916 30659
+/- 0 0 0 0
ot-cli-ftd-br main 550720 864 131204 682788
#10221 550720 864 131204 682788
+/- 0 0 0 0
libopenthread-ftd-br.a main 324516 100 105126 429742
#10221 324516 100 105126 429742
+/- 0 0 0 0
libopenthread-cli-ftd-br.a main 71320 0 8099 79419
#10221 71320 0 8099 79419
+/- 0 0 0 0
ot-rcp main 62216 564 20604 83384
#10221 62216 564 20604 83384
+/- 0 0 0 0
libopenthread-rcp.a main 9542 0 5052 14594
#10221 9542 0 5052 14594
+/- 0 0 0 0
libopenthread-radio.a main 18870 0 214 19084
#10221 18870 0 214 19084
+/- 0 0 0 0

@zhanglongxia
Copy link
Contributor

Is it possible to add new config file openthread-posix-platform-config.h, which contains the OPENTHREAD_POSIX_CONFIG_* configurations of the file openthread-posix-config.h. Then the file openthread-posix-config.h contains openthread-core-config.h and openthread-posix-platform-config.h. The xxx_interface.hpp only include the file openthread-posix-platform-config.h. This will be more flexible when including header files.

@Irving-cl
Copy link
Contributor Author

Is it possible to add new config file openthread-posix-platform-config.h, which contains the OPENTHREAD_POSIX_CONFIG_* configurations of the file openthread-posix-config.h. Then the file openthread-posix-config.h contains openthread-core-config.h and openthread-posix-platform-config.h. The xxx_interface.hpp only include the file openthread-posix-platform-config.h. This will be more flexible when including header files.

@zhanglongxia

I think this is an option. However I think it's very confusing that we have both openthread-posix-platform-config.h and openthread-posix-config.h.

I have checked the current openthread-posix-config.h. Actually most of the options don't depend on openthread-core-config.h. The dependencies on openthread-core-config.h are:

/**                                                                                                                                                                                                                                                          
 * @def OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE                                                                                                                                                                                                              
 *                                                                                                                                                                                                                                                           
 * Defines `1` to enable the posix implementation of platform/infra_if.h APIs.                                                                                                                                                                               
 * The default value is set to `OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE` if it's                                                                                                                                                                             
 * not explicit defined.                                                                                                                                                                                                                                     
 */                                                                                                                                                                                                                                                          
#ifndef OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE                                                                                                                                                                                                              
#define OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE \                                                                                                                                                                                                            
    (OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE || OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE)                                                                                                                                                                    
#endif

/**                                                                                                                                                                                                                                                          
 * @def OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE                                                                                                                                                                                         
 *                                                                                                                                                                                                                                                           
 * This setting configures the maximum number of Multicast Forwarding Cache table for POSIX native multicast routing.                                                                                                                                        
 *                                                                                                                                                                                                                                                           
 */                                                                                                                                                                                                                                                          
#ifndef OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE                                                                                                                                                                                         
#define OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE (OPENTHREAD_CONFIG_MAX_MULTICAST_LISTENERS * 10)                                                                                                                                        
#endif

/**                                                                                                                                                                                                                                                          
 * @def OPENTHREAD_POSIX_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE                                                                                                                                                                                     
 *                                                                                                                                                                                                                                                           
 * Define as 1 to enable multicast routing support.                                                                                                                                                                                                          
 *                                                                                                                                                                                                                                                           
 */                                                                                                                                                                                                                                                          
#ifndef OPENTHREAD_POSIX_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE                                                                                                                                                                                     
#define OPENTHREAD_POSIX_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE \                                                                                                                                                                                   
    OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE                                                                                                                                                                                               
#endif

#if OPENTHREAD_POSIX_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE && \                                                                                                                                                                                    
    !OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE                                                                                                                                                                                              
#error \                                                                                                                                                                                                                                                     
    "OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE is required for OPENTHREAD_POSIX_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE"                                                                                                            
#endif  

/**                                                                                                                                                                                                                                                          
 * @def OPENTHREAD_POSIX_CONFIG_MAX_OMR_ROUTES_NUM                                                                                                                                                                                                           
 *                                                                                                                                                                                                                                                           
 * Defines the max number of OMR routes that can be added to kernel.                                                                                                                                                                                         
 *                                                                                                                                                                                                                                                           
 */                                                                                                                                                                                                                                                          
#ifndef OPENTHREAD_POSIX_CONFIG_MAX_OMR_ROUTES_NUM                                                                                                                                                                                                           
#define OPENTHREAD_POSIX_CONFIG_MAX_OMR_ROUTES_NUM OPENTHREAD_CONFIG_IP6_SLAAC_NUM_ADDRESSES                                                                                                                                                                 
#endif  

So maybe let's the devide the options into two categories: related with core and unrelated with core. And let's naming them as openthread-posix-core-related-config.h and openthread-posix-config.h. Thoughts?

@zhanglongxia
Copy link
Contributor

So maybe let's the devide the options into two categories: related with core and unrelated with core. And let's naming them as openthread-posix-core-related-config.h and openthread-posix-config.h. Thoughts?

Sounds good.

@Irving-cl Irving-cl force-pushed the update_spinel_manager branch 4 times, most recently from 67d3c1b to e67330a Compare May 15, 2024 04:10
@Irving-cl Irving-cl changed the title [posix] move definition in spinel_manager from header to source [posix] adjust posix platform header including May 15, 2024
@Irving-cl Irving-cl force-pushed the update_spinel_manager branch 2 times, most recently from 43a4d0b to e8920e0 Compare May 15, 2024 05:31
Copy link
Contributor

@zhanglongxia zhanglongxia left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -35,8 +35,10 @@
#define OT_POSIX_PLATFORM_INFRA_IF_HPP_

#include "openthread-posix-config.h"
#include "openthread-posix-core-related-config.h"
Copy link
Member

@abtink abtink May 17, 2024

Choose a reason for hiding this comment

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

@Irving-cl, I understand the goal of making spinel_interface modules independent of the OT code (as a standalone library), but I'm not clear why we need to change infra_if, netif, udp, etc., so they don't include openthread-core-config.h. These modules are part of the platform layer and should be able to see this header. They shouldn't be part of the spinel library module used by a host-side implementation.

#ifndef OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE
#define OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE \
(OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE || OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE)
#endif
Copy link
Member

Choose a reason for hiding this comment

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

I believe replicating the configurations, defining similar ones under new name of OPENTHREAD_POSIX derived from OPENTHREAD_CONFIG, can get confusing and may lead to incorrect usage. Do we need this? Is there any other way?

@Irving-cl
Copy link
Contributor Author

@abtink Thanks! After thinking more on this, I think we should use another alternative.

FYI, the original intention of this PR is to make posix/platform/spinel_manager.hpp could be directly included from ot-br-posix (for controller_openthread in the NCP case: https://github.com/openthread/ot-br-posix/pull/2283/files#diff-7b951670ff4aaa492d9bb268de313f2f459c921e3415bee6798ace678f4e3a3bR62). I did it like this instead of calling otSysMainloopProcess and otSysMainloopUpdate because in that way we need to develop on two repos frequently which will be difficult and spend more time.

However it looks like including posix platform header directly from ot-br-posix isn't a good idea. Because the posix platform header should be able to see the config and headers in ot core and that caused an including issue if we include the posix platform header from ot-br-posix.

So I think we should still update the otSysMainloopProcess and otSysMainloopUpdate in ot posix and call them from ot-br-posix in the NCP case. Thoughts?

@Irving-cl
Copy link
Contributor Author

Close this PR. Will use another approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants