devtools: add .clang-format file
PATCH 1/1 devtools: add .clang-format file
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
--- .clang-format | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .clang-format
.clang-format new file +30 -0
@@ -0,0 +1,30 @@ +--- +# Place opening and closing parentheses on the same line for control statements +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: true + AfterControlStatement: false + +# Set maximum line length to 100 characters +ColumnLimit: 100 + +# Use LF (line feed) as the end-of-line character +EndOfLine: lf + +# Specify style options for the entire file +File: + # Insert a final newline character at the end of the file + EndOfFile: true + +IndentWidth: 8 + +# Set tab width to 8 spaces +TabWidth: 8 + +# Use tabs for indentation +UseTab: Always + +# Specify whitespace-related style options +Whitespace: + # Trim trailing whitespace at the end of each line + TrimTrailingWhitespace: true
Signature · 1 line
2.34.1
Quoted 10 lines · Abdullah Ömer Yamaç
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>
Overall +1 to have a format file, specially to help non-frequent contributors.
1. Some options are failing for me [1], I don't know if it requires a specific version of clang-format
2. Current options are not fully aligned with coding convention, it is easier to see what is not compatible by running the tool on an existing file [2].
we need to fix them.
[1]clang-format -i ./lib/ethdev/rte_ethdev.c
a./home/amd/development/dpdk-next-net/./.clang-format:28:1: error: unknown key 'Whitespace'
Whitespace:
^~~~~~~~~~
Error reading /home/amd/development/dpdk-next-net/./.clang-format:
Invalid argument
b./home/amd/development/dpdk-next-net/./.clang-format:12:1: error: unknown key 'EndOfLine'
EndOfLine: lf
^~~~~~~~~
Error reading /home/amd/development/dpdk-next-net/./.clang-format:
Invalid argument
c./home/amd/development/dpdk-next-net/./.clang-format:15:1: error: unknown key 'File'
File:
^~~~
Error reading /home/amd/development/dpdk-next-net/./.clang-format:
Invalid argument
[2]clang-format -i ./lib/ethdev/rte_ethdev.c (with failing part commented out)git diff
A few diff samples to fix at first glance:
```
static const struct rte_eth_xstats_name_off eth_dev_txq_stats_strings[] = {
- {"packets", offsetof(struct rte_eth_stats, q_opackets)},
- {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
+ {"packets", offsetof(struct rte_eth_stats, q_opackets)},
+ {"bytes", offsetof(struct rte_eth_stats, q_obytes)},
};
``````
-enum {
- STAT_QMAP_TX = 0,
- STAT_QMAP_RX
-};
+enum { STAT_QMAP_TX = 0, STAT_QMAP_RX };
`````` -int -rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str) +int rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str) ```
```
RTE_ETH_FOREACH_DEV(p)
- count++;
+ count++;
``````
rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
- RTE_ETH_FOREACH_VALID_DEV(pid) {
+ RTE_ETH_FOREACH_VALID_DEV(pid)
+ {
```Quoted 2 lines · On Mon, 29 Apr 2024 14:32:43 +0100 Ferruh Yigit <[email protected]> wrote:
```
RTE_ETH_FOREACH_DEV(p)
I think all those foreach macros need to be in clang format.
For example the kernel clang format has:
# Taken from:
# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ tools/ \
# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
# | LC_ALL=C sort -uForEachMacros:
- '__ata_qc_for_each'
- '__bio_for_each_bvec'
- '__bio_for_each_segment'
- '__evlist__for_each_entry'
- '__evlist__for_each_entry_continue'
- '__evlist__for_each_entry_from'
- '__evlist__for_each_entry_reverse'
- '__evlist__for_each_entry_safe'
- '__for_each_mem_range'
- '__for_each_mem_range_rev'
- '__for_each_thread'
- '__hlist_for_each_rcu'
- '__map__for_each_symbol_by_name'
- '__pci_bus_for_each_res0'
- '__pci_bus_for_each_res1'
- '__pci_dev_for_each_res0'
- '__pci_dev_for_each_res1'
- '__perf_evlist__for_each_entry'
- '__perf_evlist__for_each_entry_reverse'
- '__perf_evlist__for_each_entry_safe'
- '__rq_for_each_bio'
- '__shost_for_each_device'
- '__sym_for_each'
- 'apei_estatus_for_each_section'
- 'ata_for_each_dev'
- 'ata_for_each_link'
- 'ata_qc_for_each'
- 'ata_qc_for_each_raw'
- 'ata_qc_for_each_with_internal'
- 'ax25_for_each'
- 'ax25_uid_for_each'
- 'bio_for_each_bvec'
- 'bio_for_each_bvec_all'
- 'bio_for_each_folio_all'
- 'bio_for_each_integrity_vec'
- 'bio_for_each_segment'
- 'bio_for_each_segment_all'
- 'bio_list_for_each'
- 'bip_for_each_vec'
- 'bond_for_each_slave'
- 'bond_for_each_slave_rcu'
- 'bpf_for_each'
- 'bpf_for_each_reg_in_vstate'
- 'bpf_for_each_reg_in_vstate_mask'
- 'bpf_for_each_spilled_reg'
- 'bpf_object__for_each_map'
- 'bpf_object__for_each_program'
- 'btree_for_each_safe128'
- 'btree_for_each_safe32'
- 'btree_for_each_safe64'
- 'btree_for_each_safel'
- 'card_for_each_dev'
- 'cgroup_taskset_for_each'
- 'cgroup_taskset_for_each_leader'
- 'cpu_aggr_map__for_each_idx'
- 'cpufreq_for_each_efficient_entry_idx'
- 'cpufreq_for_each_entry'
- 'cpufreq_for_each_entry_idx'
- 'cpufreq_for_each_valid_entry'
- 'cpufreq_for_each_valid_entry_idx'
- 'css_for_each_child'
- 'css_for_each_descendant_post'
- 'css_for_each_descendant_pre'
- 'damon_for_each_region'
- 'damon_for_each_region_from'
- 'damon_for_each_region_safe'
- 'damon_for_each_scheme'
- 'damon_for_each_scheme_safe'
- 'damon_for_each_target'
- 'damon_for_each_target_safe'
- 'damos_for_each_filter'
- 'damos_for_each_filter_safe'
- 'data__for_each_file'
- 'data__for_each_file_new'
- 'data__for_each_file_start'
- 'device_for_each_child_node'
- 'displayid_iter_for_each'
- 'dma_fence_array_for_each'
- 'dma_fence_chain_for_each'
- 'dma_fence_unwrap_for_each'
- 'dma_resv_for_each_fence'
- 'dma_resv_for_each_fence_unlocked'
- 'do_for_each_ftrace_op'
- 'drm_atomic_crtc_for_each_plane'
- 'drm_atomic_crtc_state_for_each_plane'
- 'drm_atomic_crtc_state_for_each_plane_state'
- 'drm_atomic_for_each_plane_damage'
- 'drm_client_for_each_connector_iter'
- 'drm_client_for_each_modeset'
- 'drm_connector_for_each_possible_encoder'
- 'drm_exec_for_each_locked_object'
- 'drm_exec_for_each_locked_object_reverse'
- 'drm_for_each_bridge_in_chain'
- 'drm_for_each_connector_iter'
- 'drm_for_each_crtc'
- 'drm_for_each_crtc_reverse'
- 'drm_for_each_encoder'
- 'drm_for_each_encoder_mask'
- 'drm_for_each_fb'
- 'drm_for_each_legacy_plane'
- 'drm_for_each_plane'
- 'drm_for_each_plane_mask'
- 'drm_for_each_privobj'
- 'drm_gem_for_each_gpuva'
- 'drm_gem_for_each_gpuva_safe'
- 'drm_gpuva_for_each_op'
- 'drm_gpuva_for_each_op_from_reverse'
- 'drm_gpuva_for_each_op_safe'
- 'drm_gpuvm_for_each_va'
- 'drm_gpuvm_for_each_va_range'
- 'drm_gpuvm_for_each_va_range_safe'
- 'drm_gpuvm_for_each_va_safe'
- 'drm_mm_for_each_hole'
- 'drm_mm_for_each_node'
- 'drm_mm_for_each_node_in_range'
- 'drm_mm_for_each_node_safe'
- 'dsa_switch_for_each_available_port'
- 'dsa_switch_for_each_cpu_port'
- 'dsa_switch_for_each_cpu_port_continue_reverse'
- 'dsa_switch_for_each_port'
- 'dsa_switch_for_each_port_continue_reverse'
- 'dsa_switch_for_each_port_safe'
- 'dsa_switch_for_each_user_port'
- 'dsa_tree_for_each_cpu_port'
- 'dsa_tree_for_each_user_port'
- 'dsa_tree_for_each_user_port_continue_reverse'
- 'dso__for_each_symbol'
- 'dsos__for_each_with_build_id'
- 'elf_hash_for_each_possible'
- 'elf_symtab__for_each_symbol'
- 'evlist__for_each_cpu'
- 'evlist__for_each_entry'
- 'evlist__for_each_entry_continue'
- 'evlist__for_each_entry_from'
- 'evlist__for_each_entry_reverse'
- 'evlist__for_each_entry_safe'
- 'flow_action_for_each'
- 'for_each_acpi_consumer_dev'
- 'for_each_acpi_dev_match'
- 'for_each_active_dev_scope'
- 'for_each_active_drhd_unit'
- 'for_each_active_iommu'
- 'for_each_active_route'
- 'for_each_aggr_pgid'
- 'for_each_and_bit'
- 'for_each_andnot_bit'
- 'for_each_available_child_of_node'
- 'for_each_bench'
- 'for_each_bio'
- 'for_each_board_func_rsrc'
- 'for_each_btf_ext_rec'
- 'for_each_btf_ext_sec'
- 'for_each_bvec'
- 'for_each_card_auxs'
- 'for_each_card_auxs_safe'
- 'for_each_card_components'
- 'for_each_card_dapms'
- 'for_each_card_pre_auxs'
- 'for_each_card_prelinks'
- 'for_each_card_rtds'
- 'for_each_card_rtds_safe'
- 'for_each_card_widgets'
- 'for_each_card_widgets_safe'
- 'for_each_cgroup_storage_type'
- 'for_each_child_of_node'
- 'for_each_clear_bit'
- 'for_each_clear_bit_from'
- 'for_each_clear_bitrange'
- 'for_each_clear_bitrange_from'
- 'for_each_cmd'
- 'for_each_cmsghdr'
- 'for_each_collection'
- 'for_each_comp_order'
- 'for_each_compatible_node'
- 'for_each_component_dais'
- 'for_each_component_dais_safe'
- 'for_each_conduit'
- 'for_each_console'
- 'for_each_console_srcu'
- 'for_each_cpu'
- 'for_each_cpu_and'
- 'for_each_cpu_andnot'
- 'for_each_cpu_or'
- 'for_each_cpu_wrap'
- 'for_each_dapm_widgets'
- 'for_each_dedup_cand'
- 'for_each_dev_addr'
- 'for_each_dev_scope'
- 'for_each_dma_cap_mask'
- 'for_each_dpcm_be'
- 'for_each_dpcm_be_rollback'
- 'for_each_dpcm_be_safe'
- 'for_each_dpcm_fe'
- 'for_each_drhd_unit'
- 'for_each_dss_dev'
- 'for_each_efi_memory_desc'
- 'for_each_efi_memory_desc_in_map'
- 'for_each_element'
- 'for_each_element_extid'
- 'for_each_element_id'
- 'for_each_endpoint_of_node'
- 'for_each_event'
- 'for_each_event_tps'
- 'for_each_evictable_lru'
- 'for_each_fib6_node_rt_rcu'
- 'for_each_fib6_walker_rt'
- 'for_each_free_mem_pfn_range_in_zone'
- 'for_each_free_mem_pfn_range_in_zone_from'
- 'for_each_free_mem_range'
- 'for_each_free_mem_range_reverse'
- 'for_each_func_rsrc'
- 'for_each_gpiochip_node'
- 'for_each_group_evsel'
- 'for_each_group_evsel_head'
- 'for_each_group_member'
- 'for_each_group_member_head'
- 'for_each_hstate'
- 'for_each_if'
- 'for_each_inject_fn'
- 'for_each_insn'
- 'for_each_insn_prefix'
- 'for_each_intid'
- 'for_each_iommu'
- 'for_each_ip_tunnel_rcu'
- 'for_each_irq_nr'
- 'for_each_lang'
- 'for_each_link_codecs'
- 'for_each_link_cpus'
- 'for_each_link_platforms'
- 'for_each_lru'
- 'for_each_matching_node'
- 'for_each_matching_node_and_match'
- 'for_each_media_entity_data_link'
- 'for_each_mem_pfn_range'
- 'for_each_mem_range'
- 'for_each_mem_range_rev'
- 'for_each_mem_region'
- 'for_each_member'
- 'for_each_memory'
- 'for_each_migratetype_order'
- 'for_each_missing_reg'
- 'for_each_mle_subelement'
- 'for_each_mod_mem_type'
- 'for_each_net'
- 'for_each_net_continue_reverse'
- 'for_each_net_rcu'
- 'for_each_netdev'
- 'for_each_netdev_continue'
- 'for_each_netdev_continue_rcu'
- 'for_each_netdev_continue_reverse'
- 'for_each_netdev_dump'
- 'for_each_netdev_feature'
- 'for_each_netdev_in_bond_rcu'
- 'for_each_netdev_rcu'
- 'for_each_netdev_reverse'
- 'for_each_netdev_safe'
- 'for_each_new_connector_in_state'
- 'for_each_new_crtc_in_state'
- 'for_each_new_mst_mgr_in_state'
- 'for_each_new_plane_in_state'
- 'for_each_new_plane_in_state_reverse'
- 'for_each_new_private_obj_in_state'
- 'for_each_new_reg'
- 'for_each_node'
- 'for_each_node_by_name'
- 'for_each_node_by_type'
- 'for_each_node_mask'
- 'for_each_node_state'
- 'for_each_node_with_cpus'
- 'for_each_node_with_property'
- 'for_each_nonreserved_multicast_dest_pgid'
- 'for_each_numa_hop_mask'
- 'for_each_of_allnodes'
- 'for_each_of_allnodes_from'
- 'for_each_of_cpu_node'
- 'for_each_of_pci_range'
- 'for_each_old_connector_in_state'
- 'for_each_old_crtc_in_state'
- 'for_each_old_mst_mgr_in_state'
- 'for_each_old_plane_in_state'
- 'for_each_old_private_obj_in_state'
- 'for_each_oldnew_connector_in_state'
- 'for_each_oldnew_crtc_in_state'
- 'for_each_oldnew_mst_mgr_in_state'
- 'for_each_oldnew_plane_in_state'
- 'for_each_oldnew_plane_in_state_reverse'
- 'for_each_oldnew_private_obj_in_state'
- 'for_each_online_cpu'
- 'for_each_online_node'
- 'for_each_online_pgdat'
- 'for_each_or_bit'
- 'for_each_path'
- 'for_each_pci_bridge'
- 'for_each_pci_dev'
- 'for_each_pcm_streams'
- 'for_each_physmem_range'
- 'for_each_populated_zone'
- 'for_each_possible_cpu'
- 'for_each_present_blessed_reg'
- 'for_each_present_cpu'
- 'for_each_prime_number'
- 'for_each_prime_number_from'
- 'for_each_probe_cache_entry'
- 'for_each_process'
- 'for_each_process_thread'
- 'for_each_prop_codec_conf'
- 'for_each_prop_dai_codec'
- 'for_each_prop_dai_cpu'
- 'for_each_prop_dlc_codecs'
- 'for_each_prop_dlc_cpus'
- 'for_each_prop_dlc_platforms'
- 'for_each_property_of_node'
- 'for_each_reg'
- 'for_each_reg_filtered'
- 'for_each_reloc'
- 'for_each_reloc_from'
- 'for_each_requested_gpio'
- 'for_each_requested_gpio_in_range'
- 'for_each_reserved_mem_range'
- 'for_each_reserved_mem_region'
- 'for_each_rtd_codec_dais'
- 'for_each_rtd_components'
- 'for_each_rtd_cpu_dais'
- 'for_each_rtd_dais'
- 'for_each_sband_iftype_data'
- 'for_each_script'
- 'for_each_sec'
- 'for_each_set_bit'
- 'for_each_set_bit_from'
- 'for_each_set_bit_wrap'
- 'for_each_set_bitrange'
- 'for_each_set_bitrange_from'
- 'for_each_set_clump8'
- 'for_each_sg'
- 'for_each_sg_dma_page'
- 'for_each_sg_page'
- 'for_each_sgtable_dma_page'
- 'for_each_sgtable_dma_sg'
- 'for_each_sgtable_page'
- 'for_each_sgtable_sg'
- 'for_each_sibling_event'
- 'for_each_sta_active_link'
- 'for_each_subelement'
- 'for_each_subelement_extid'
- 'for_each_subelement_id'
- 'for_each_sublist'
- 'for_each_subsystem'
- 'for_each_supported_activate_fn'
- 'for_each_supported_inject_fn'
- 'for_each_sym'
- 'for_each_test'
- 'for_each_thread'
Quoted 84 lines · On Mon, 29 Apr 2024 14:32:43 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 10 lines · Abdullah Ömer Yamaç
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>Overall +1 to have a format file, specially to help non-frequent contributors.
1. Some options are failing for me [1], I don't know if it requires a specific version of clang-format
2. Current options are not fully aligned with coding convention, it is easier to see what is not compatible by running the tool on an existing file [2].
we need to fix them.[1]
clang-format -i ./lib/ethdev/rte_ethdev.c
a./home/amd/development/dpdk-next-net/./.clang-format:28:1: error: unknown key 'Whitespace'
Whitespace:
^~~~~~~~~~
Error reading/home/amd/development/dpdk-next-net/./.clang-format:
Invalid argumentb.
/home/amd/development/dpdk-next-net/./.clang-format:12:1: error: unknown key 'EndOfLine'
EndOfLine: lf
^~~~~~~~~
Error reading/home/amd/development/dpdk-next-net/./.clang-format:
Invalid argumentc.
/home/amd/development/dpdk-next-net/./.clang-format:15:1: error: unknown key 'File'
File:
^~~~
Error reading/home/amd/development/dpdk-next-net/./.clang-format:
Invalid argument[2]
clang-format -i ./lib/ethdev/rte_ethdev.c(with failing part commented out)git diffA few diff samples to fix at first glance:
``` static const struct rte_eth_xstats_name_off eth_dev_txq_stats_strings[] = { - {"packets", offsetof(struct rte_eth_stats, q_opackets)}, - {"bytes", offsetof(struct rte_eth_stats, q_obytes)}, + {"packets", offsetof(struct rte_eth_stats, q_opackets)}, + {"bytes", offsetof(struct rte_eth_stats, q_obytes)}, }; `````` -enum { - STAT_QMAP_TX = 0, - STAT_QMAP_RX -}; +enum { STAT_QMAP_TX = 0, STAT_QMAP_RX }; `````` -int -rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str) +int rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str) ```
Quoted 2 lines
```
RTE_ETH_FOREACH_DEV(p)
Add this
# Take from
#
# git grep -h '^#define [^[:space:]]*FOREACH[^[:space:]]*(' lib/ \
# | sed "s,^#define \([^[:space:]]*FOREACH[^[:space:]]*\)(.*$, - '\1'," \
# | LC_ALL=C sort -u
ForeachMacros:
- 'CIRBUF_FOREACH'
- 'RTE_BBDEV_FOREACH'
- 'RTE_DEV_FOREACH'
- 'RTE_DMA_FOREACH_DEV'
- 'RTE_EAL_DEVARGS_FOREACH'
- 'RTE_ETH_FOREACH_DEV'
- 'RTE_ETH_FOREACH_DEV_OF'
- 'RTE_ETH_FOREACH_DEV_OWNED_BY'
- 'RTE_ETH_FOREACH_DEV_SIBLING'
- 'RTE_ETH_FOREACH_MATCHING_DEV'
- 'RTE_ETH_FOREACH_VALID_DEV'
- 'RTE_GPU_FOREACH'
- 'RTE_GPU_FOREACH_CHILD'
- 'RTE_GPU_FOREACH_PARENT'
- 'RTE_LCORE_FOREACH'
- 'RTE_LCORE_FOREACH_WORKER'
- 'RTE_TAILQ_FOREACH'
- 'RTE_TAILQ_FOREACH_SAFE'Hello,
I am facing a problem while creating the configuration. I am trying to make a clang-format that formats codes without changing any codebases. Here is the question:
clang-format related config:
...
BraceWrapping:
AfterFunction: true
...
If the configuration supports braces after function, then MACRO's formats fail.
An example of the formatted MACRO is given below:
...
#define RTE_RX_OFFLOAD_BIT2STR(_name) \
{ \
...
If the AfterFunction is false, the functions' formats fail; here is a formatted example.
...
if (devargs_str == NULL) {
...
I will send the current configuration as v2. You can test it.
Quoted 120 lines · Stephen Hemminger
Quoted 53 lines · On Mon, 29 Apr 2024 14:32:43 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 10 lines · Abdullah Ömer Yamaç
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>Overall +1 to have a format file, specially to help non-frequent contributors.
1. Some options are failing for me [1], I don't know if it requires a specific version of clang-format
2. Current options are not fully aligned with coding convention, it is easier to see what is not compatible by running the tool on an existing file [2].
we need to fix them.[1]
clang-format -i ./lib/ethdev/rte_ethdev.c
a./home/amd/development/dpdk-next-net/./.clang-format:28:1: error: unknown key 'Whitespace'
Whitespace:
^~~~~~~~~~
Error reading/home/amd/development/dpdk-next-net/./.clang-format:
Invalid argumentb.
/home/amd/development/dpdk-next-net/./.clang-format:12:1: error: unknown key 'EndOfLine'
EndOfLine: lf
^~~~~~~~~
Error reading/home/amd/development/dpdk-next-net/./.clang-format:
Invalid argumentc.
/home/amd/development/dpdk-next-net/./.clang-format:15:1: error: unknown key 'File'
File:
^~~~
Error reading/home/amd/development/dpdk-next-net/./.clang-format:
Invalid argumentQuoted 8 lines
[2]
clang-format -i ./lib/ethdev/rte_ethdev.c(with failing part commented out)git diffA few diff samples to fix at first glance:
```
static const structrte_eth_xstats_name_offeth_dev_txq_stats_strings[]= {
Quoted 21 lines
- {"packets",
offsetof(struct rte_eth_stats, q_opackets)},
- {"bytes",offsetof(struct rte_eth_stats, q_obytes)},
+ {"packets",offsetof(struct rte_eth_stats, q_opackets)},
+ {"bytes",offsetof(struct rte_eth_stats, q_obytes)},
};``` ``` -enum { - STAT_QMAP_TX = 0, - STAT_QMAP_RX -}; +enum { STAT_QMAP_TX = 0, STAT_QMAP_RX }; ``` ```-int
-rte_eth_iterator_init(structrte_dev_iterator*iter, const char*devargs_str)
+int rte_eth_iterator_init(structrte_dev_iterator*iter, const char*devargs_str)Quoted 4 lines
``` ```
RTE_ETH_FOREACH_DEV(p)Add this
# Take from
## git grep -h '^#define [^[:space:]]*FOREACH[^[:space:]]*(' lib/ \ # | sed "s,^#define \([^[:space:]]*FOREACH[^[:space:]]*\)(.*$, - '\1'," \ # | LC_ALL=C sort -u ForeachMacros: - 'CIRBUF_FOREACH' - 'RTE_BBDEV_FOREACH' - 'RTE_DEV_FOREACH' - 'RTE_DMA_FOREACH_DEV' - 'RTE_EAL_DEVARGS_FOREACH' - 'RTE_ETH_FOREACH_DEV' - 'RTE_ETH_FOREACH_DEV_OF' - 'RTE_ETH_FOREACH_DEV_OWNED_BY' - 'RTE_ETH_FOREACH_DEV_SIBLING' - 'RTE_ETH_FOREACH_MATCHING_DEV' - 'RTE_ETH_FOREACH_VALID_DEV' - 'RTE_GPU_FOREACH' - 'RTE_GPU_FOREACH_CHILD' - 'RTE_GPU_FOREACH_PARENT' - 'RTE_LCORE_FOREACH' - 'RTE_LCORE_FOREACH_WORKER' - 'RTE_TAILQ_FOREACH' - 'RTE_TAILQ_FOREACH_SAFE'
PATCH v2 1/1 devtools: add .clang-format file
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
--- .clang-format | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .clang-format
.clang-format new file +42 -0
@@ -0,0 +1,42 @@ +--- +BasedOnStyle: LLVM + +# Place opening and closing parentheses on the same line for control statements +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: false + AfterControlStatement: false + AfterEnum: false + +# Set maximum line length to 100 characters +ColumnLimit: 100 + +# Use LF (line feed) as the end-of-line character +LineEnding: LF + +# Insert a newline at the end of the file +InsertNewlineAtEOF: true + +# Set indentation width to 8 spaces +IndentWidth: 8 + +# Set continuation indentation width to 8 spaces +ContinuationIndentWidth: 8 + +# Set tab width to 8 spaces +TabWidth: 8 + +# Use tabs for indentation +UseTab: Always + +# Preserve include blocks as they are +IncludeBlocks: Preserve + +# Never sort includes +SortIncludes: Never + +# Always break after return type for top-level definitions +AlwaysBreakAfterReturnType: TopLevelDefinitions + +# Always break before multiline string literals +AlignEscapedNewlines: Left
Signature · 1 line
2.34.1
Quoted 9 lines · On Sat, 4 May 2024 13:41:35 +0000 Abdullah Ömer Yamaç <[email protected]>…
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>
You need to add the ForEachMacros: I sent in earlier email
I was confused about the kernel functions. I didn't understand what you meant at first, but now I understand. I will send a new patch with all DPDK-related foreach macros.
Quoted 16 lines · Stephen Hemminger
Quoted 9 lines · On Sat, 4 May 2024 13:41:35 +0000 Abdullah Ömer Yamaç <[email protected]>…
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>You need to add the ForEachMacros: I sent in earlier email
PATCH v3 1/1 devtools: add .clang-format file
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
--- .clang-format | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 .clang-format
.clang-format new file +138 -0
@@ -0,0 +1,138 @@ +--- +BasedOnStyle: LLVM + +# Place opening and closing parentheses on the same line for control statements +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: false + AfterControlStatement: false + AfterEnum: false + +# Set maximum line length to 100 characters +ColumnLimit: 100 + +# Use LF (line feed) as the end-of-line character +LineEnding: LF + +# Insert a newline at the end of the file +InsertNewlineAtEOF: true + +# Set indentation width to 8 spaces +IndentWidth: 8 + +# Set continuation indentation width to 8 spaces +ContinuationIndentWidth: 8 + +# Set tab width to 8 spaces +TabWidth: 8 + +# Use tabs for indentation +UseTab: Always + +# Preserve include blocks as they are +IncludeBlocks: Preserve + +# Never sort includes +SortIncludes: Never + +# Always break after return type for top-level definitions +AlwaysBreakAfterReturnType: TopLevelDefinitions + +# Always break before multiline string literals +AlignEscapedNewlines: Left + +# Foreach macros +ForEachMacros: [ + "CIRBUF_FOREACH", + "DLB2_LIST_FOR_EACH", + "DLB2_LIST_FOR_EACH_SAFE", + "ECORE_LIST_FOR_EACH_ENTRY", + "ECORE_LIST_FOR_EACH_ENTRY_SAFE", + "FOR_EACH", + "FOR_EACH_BUCKET", + "FOR_EACH_CNIC_QUEUE", + "FOR_EACH_COS_IN_TX_QUEUE", + "FOR_EACH_ETH_QUEUE", + "FOR_EACH_MEMBER", + "FOR_EACH_NONDEFAULT_ETH_QUEUE", + "FOR_EACH_NONDEFAULT_QUEUE", + "FOR_EACH_PORT", + "FOR_EACH_PORT_IF", + "FOR_EACH_QUEUE", + "FOR_EACH_SUITE_TESTCASE", + "FOR_EACH_SUITE_TESTSUITE", + "FOREACH_ABS_FUNC_IN_PORT", + "FOREACH_DEVICE_ON_AUXILIARY_BUS", + "FOREACH_DEVICE_ON_CDXBUS", + "FOREACH_DEVICE_ON_PCIBUS", + "FOREACH_DEVICE_ON_PLATFORM_BUS", + "FOREACH_DEVICE_ON_UACCEBUS", + "FOREACH_DEVICE_ON_VMBUS", + "FOREACH_DRIVER_ON_AUXILIARY_BUS", + "FOREACH_DRIVER_ON_CDXBUS", + "FOREACH_DRIVER_ON_PCIBUS", + "FOREACH_DRIVER_ON_PLATFORM_BUS", + "FOREACH_DRIVER_ON_UACCEBUS", + "FOREACH_DRIVER_ON_VMBUS", + "FOREACH_SUBDEV", + "FOREACH_SUBDEV_STATE", + "HLIST_FOR_EACH_ENTRY", + "ILIST_FOREACH", + "LIST_FOR_EACH_ENTRY", + "LIST_FOR_EACH_ENTRY_SAFE", + "LIST_FOREACH", + "LIST_FOREACH_FROM", + "LIST_FOREACH_FROM_SAFE", + "LIST_FOREACH_SAFE", + "ML_AVG_FOREACH_QP", + "ML_AVG_FOREACH_QP_MVTVM", + "ML_AVG_RESET_FOREACH_QP", + "ML_MAX_FOREACH_QP", + "ML_MAX_FOREACH_QP_MVTVM", + "ML_MAX_RESET_FOREACH_QP", + "ML_MIN_FOREACH_QP", + "ML_MIN_FOREACH_QP_MVTVM", + "ML_MIN_RESET_FOREACH_QP", + "MLX5_ETH_FOREACH_DEV", + "MLX5_IPOOL_FOREACH", + "MLX5_L3T_FOREACH", + "OSAL_LIST_FOR_EACH_ENTRY", + "OSAL_LIST_FOR_EACH_ENTRY_SAFE", + "PLT_TAILQ_FOREACH_SAFE", + "RTE_BBDEV_FOREACH", + "RTE_DEV_FOREACH", + "RTE_DMA_FOREACH_DEV", + "RTE_EAL_DEVARGS_FOREACH", + "RTE_ETH_FOREACH_DEV", + "RTE_ETH_FOREACH_DEV_OF", + "RTE_ETH_FOREACH_DEV_OWNED_BY", + "RTE_ETH_FOREACH_DEV_SIBLING", + "RTE_ETH_FOREACH_MATCHING_DEV", + "RTE_ETH_FOREACH_VALID_DEV", + "RTE_GPU_FOREACH", + "RTE_GPU_FOREACH_CHILD", + "RTE_GPU_FOREACH_PARENT", + "RTE_LCORE_FOREACH", + "RTE_LCORE_FOREACH_WORKER", + "RTE_TAILQ_FOREACH", + "RTE_TAILQ_FOREACH_SAFE", + "SILIST_FOREACH", + "SLIST_FOREACH", + "SLIST_FOREACH_FROM", + "SLIST_FOREACH_FROM_SAFE", + "SLIST_FOREACH_PREVPTR", + "SLIST_FOREACH_SAFE", + "STAILQ_FOREACH", + "STAILQ_FOREACH_FROM", + "STAILQ_FOREACH_FROM_SAFE", + "STAILQ_FOREACH_SAFE", + "TAILQ_FOREACH", + "TAILQ_FOREACH_ENTRY", + "TAILQ_FOREACH_ENTRY_SAFE", + "TAILQ_FOREACH_FROM", + "TAILQ_FOREACH_FROM_SAFE", + "TAILQ_FOREACH_REVERSE", + "TAILQ_FOREACH_REVERSE_FROM", + "TAILQ_FOREACH_REVERSE_FROM_SAFE", + "TAILQ_FOREACH_REVERSE_SAFE", + "TAILQ_FOREACH_SAFE", ]
Signature · 1 line
2.34.1
Quoted 5 lines · On Sat, 4 May 2024 19:18:37 +0000 Abdullah Ömer Yamaç <[email protected]>…
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
Quoted 8 lines
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>--- .clang-format | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 .clang-format
Tried this, but it needs some change to how braces at start of function are handled. For example, this is not how DPDK should look:
static int
-rte_pmd_tap_remove(struct rte_vdev_device *dev) -{
+rte_pmd_tap_remove(struct rte_vdev_device *dev) {
struct rte_eth_dev *eth_dev = NULL;
/* find the ethdev entry */
Quoted 11 lines · Stephen Hemminger
Quoted 8 lines · On Sat, 4 May 2024 19:18:37 +0000 Abdullah Ömer Yamaç <[email protected]>…
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Quoted 9 lines
Quoted 5 lines
Signed-off-by Abdullah Ömer Yamaç <[email protected]>--- .clang-format | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 .clang-formatTried this, but it needs some change to how braces at start of function are handled. For example, this is not how DPDK should look:
Are the changes below ok? When I fix these cases, some macros are also formatted in the same manner.
-#define RTE_RX_OFFLOAD_BIT2STR(_name) \
- { RTE_ETH_RX_OFFLOAD_##_name, #_name }
+#define RTE_RX_OFFLOAD_BIT2STR(_name) \
+ { \
+ RTE_ETH_RX_OFFLOAD_##_name, #_name \
+ }
Quoted 9 lines
static int
(quoted diff) +1
-2-rte_pmd_tap_remove(struct rte_vdev_device *dev) -{ +rte_pmd_tap_remove(struct rte_vdev_device *dev) { struct rte_eth_dev *eth_dev = NULL; /* find the ethdev entry */
Quoted 9 lines · On Sat, 4 May 2024 19:18:37 +0000 Abdullah Ömer Yamaç <[email protected]>…
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>
Also, this looks wrong. The initialized arrays looked better before.
-static const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] = {
- "UNKNOWN", "TUN", "TAP"
-};
+static const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] = {"UNKNOWN", "TUN", "TAP"};
-static const char *valid_arguments[] = {
- ETH_TAP_IFACE_ARG,
- ETH_TAP_REMOTE_ARG,
- ETH_TAP_MAC_ARG,
- ETH_TAP_PERSIST_ARG,
- NULL
-};
+static const char *valid_arguments[] = {ETH_TAP_IFACE_ARG, ETH_TAP_REMOTE_ARG, ETH_TAP_MAC_ARG,
+ ETH_TAP_PERSIST_ARG, NULL};
Quoted 30 lines · Stephen Hemminger
Quoted 9 lines · On Sat, 4 May 2024 19:18:37 +0000 Abdullah Ömer Yamaç <[email protected]>…
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>Also, this looks wrong. The initialized arrays looked better before.
(quoted diff) +1
-3-static const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] = { - "UNKNOWN", "TUN", "TAP" -}; +static const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] = {"UNKNOWN", "TUN","TAP"};
(quoted diff) +1
-7-static const char *valid_arguments[] = { - ETH_TAP_IFACE_ARG, - ETH_TAP_REMOTE_ARG, - ETH_TAP_MAC_ARG, - ETH_TAP_PERSIST_ARG, - NULL -}; +static const char *valid_arguments[] = {ETH_TAP_IFACE_ARG,
Quoted 3 lines
ETH_TAP_REMOTE_ARG,ETH_TAP_MAC_ARG,
+ETH_TAP_PERSIST_ARG, NULL};
I am confused about these variables. tuntap_types list values in a single line, but valid_arguments' values are listed separately.
So, it is getting more complex to handle both of them. What should we do, do you have any idea?
Quoted 9 lines · On Sun, 5 May 2024 22:42:57 +0300 Abdullah Ömer Yamaç <[email protected]>…
Quoted 9 lines
Also, this looks wrong. The initialized arrays looked better before.
(quoted diff) +1
-3-static const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] = { - "UNKNOWN", "TUN", "TAP" -}; +static const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] = {"UNKNOWN", "TUN","TAP"};
Quoted 16 lines
Quoted 11 lines
(quoted diff) +1
-7-static const char *valid_arguments[] = { - ETH_TAP_IFACE_ARG, - ETH_TAP_REMOTE_ARG, - ETH_TAP_MAC_ARG, - ETH_TAP_PERSIST_ARG, - NULL -}; +static const char *valid_arguments[] = {ETH_TAP_IFACE_ARG,
ETH_TAP_REMOTE_ARG,ETH_TAP_MAC_ARG,
+ETH_TAP_PERSIST_ARG, NULL};I am confused about these variables.
tuntap_typeslist values in a single line, butvalid_arguments' values are listed separately.
So, it is getting more complex to handle both of them. What should we do, do you have any idea?
Ignore the initialized lists for now. It should be possible to have it generate something like
static const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] = {
"UNKNOWN", "TUN", "TAP"
};With the following changes result looks better. You got the format wrong for the ForEach list.
.clang-format +124 -97
@@ -1,12 +1,20 @@ --- BasedOnStyle: LLVM +AttributeMacros: + - __rte_aligned + - __rte_packed + - __rte_may_alias + - __rte_deprecated + - __rte_weak + - __rte_unused + - __rte_restrict + # Place opening and closing parentheses on the same line for control statements BreakBeforeBraces: Custom BraceWrapping: - AfterFunction: false + AfterFunction: true AfterControlStatement: false - AfterEnum: false # Set maximum line length to 100 characters ColumnLimit: 100
@@ -41,98 +49,117 @@ AlwaysBreakAfterReturnType: TopLevelDefinitions # Always break before multiline string literals AlignEscapedNewlines: Left -# Foreach macros -ForEachMacros: [ - "CIRBUF_FOREACH", - "DLB2_LIST_FOR_EACH", - "DLB2_LIST_FOR_EACH_SAFE", - "ECORE_LIST_FOR_EACH_ENTRY", - "ECORE_LIST_FOR_EACH_ENTRY_SAFE", - "FOR_EACH", - "FOR_EACH_BUCKET", - "FOR_EACH_CNIC_QUEUE", - "FOR_EACH_COS_IN_TX_QUEUE", - "FOR_EACH_ETH_QUEUE", - "FOR_EACH_MEMBER", - "FOR_EACH_NONDEFAULT_ETH_QUEUE", - "FOR_EACH_NONDEFAULT_QUEUE", - "FOR_EACH_PORT", - "FOR_EACH_PORT_IF", - "FOR_EACH_QUEUE", - "FOR_EACH_SUITE_TESTCASE", - "FOR_EACH_SUITE_TESTSUITE", - "FOREACH_ABS_FUNC_IN_PORT", - "FOREACH_DEVICE_ON_AUXILIARY_BUS", - "FOREACH_DEVICE_ON_CDXBUS", - "FOREACH_DEVICE_ON_PCIBUS", - "FOREACH_DEVICE_ON_PLATFORM_BUS", - "FOREACH_DEVICE_ON_UACCEBUS", - "FOREACH_DEVICE_ON_VMBUS", - "FOREACH_DRIVER_ON_AUXILIARY_BUS", - "FOREACH_DRIVER_ON_CDXBUS", - "FOREACH_DRIVER_ON_PCIBUS", - "FOREACH_DRIVER_ON_PLATFORM_BUS", - "FOREACH_DRIVER_ON_UACCEBUS", - "FOREACH_DRIVER_ON_VMBUS", - "FOREACH_SUBDEV", - "FOREACH_SUBDEV_STATE", - "HLIST_FOR_EACH_ENTRY", - "ILIST_FOREACH", - "LIST_FOR_EACH_ENTRY", - "LIST_FOR_EACH_ENTRY_SAFE", - "LIST_FOREACH", - "LIST_FOREACH_FROM", - "LIST_FOREACH_FROM_SAFE", - "LIST_FOREACH_SAFE", - "ML_AVG_FOREACH_QP", - "ML_AVG_FOREACH_QP_MVTVM", - "ML_AVG_RESET_FOREACH_QP", - "ML_MAX_FOREACH_QP", - "ML_MAX_FOREACH_QP_MVTVM", - "ML_MAX_RESET_FOREACH_QP", - "ML_MIN_FOREACH_QP", - "ML_MIN_FOREACH_QP_MVTVM", - "ML_MIN_RESET_FOREACH_QP", - "MLX5_ETH_FOREACH_DEV", - "MLX5_IPOOL_FOREACH", - "MLX5_L3T_FOREACH", - "OSAL_LIST_FOR_EACH_ENTRY", - "OSAL_LIST_FOR_EACH_ENTRY_SAFE", - "PLT_TAILQ_FOREACH_SAFE", - "RTE_BBDEV_FOREACH", - "RTE_DEV_FOREACH", - "RTE_DMA_FOREACH_DEV", - "RTE_EAL_DEVARGS_FOREACH", - "RTE_ETH_FOREACH_DEV", - "RTE_ETH_FOREACH_DEV_OF", - "RTE_ETH_FOREACH_DEV_OWNED_BY", - "RTE_ETH_FOREACH_DEV_SIBLING", - "RTE_ETH_FOREACH_MATCHING_DEV", - "RTE_ETH_FOREACH_VALID_DEV", - "RTE_GPU_FOREACH", - "RTE_GPU_FOREACH_CHILD", - "RTE_GPU_FOREACH_PARENT", - "RTE_LCORE_FOREACH", - "RTE_LCORE_FOREACH_WORKER", - "RTE_TAILQ_FOREACH", - "RTE_TAILQ_FOREACH_SAFE", - "SILIST_FOREACH", - "SLIST_FOREACH", - "SLIST_FOREACH_FROM", - "SLIST_FOREACH_FROM_SAFE", - "SLIST_FOREACH_PREVPTR", - "SLIST_FOREACH_SAFE", - "STAILQ_FOREACH", - "STAILQ_FOREACH_FROM", - "STAILQ_FOREACH_FROM_SAFE", - "STAILQ_FOREACH_SAFE", - "TAILQ_FOREACH", - "TAILQ_FOREACH_ENTRY", - "TAILQ_FOREACH_ENTRY_SAFE", - "TAILQ_FOREACH_FROM", - "TAILQ_FOREACH_FROM_SAFE", - "TAILQ_FOREACH_REVERSE", - "TAILQ_FOREACH_REVERSE_FROM", - "TAILQ_FOREACH_REVERSE_FROM_SAFE", - "TAILQ_FOREACH_REVERSE_SAFE", - "TAILQ_FOREACH_SAFE", ] +ForEachMacros: + - CIRBUF_FOREACH + - DLB2_LIST_FOR_EACH + - DLB2_LIST_FOR_EACH_SAFE + - ECORE_LIST_FOR_EACH_ENTRY + - ECORE_LIST_FOR_EACH_ENTRY_SAFE + - FOREACH_ABS_FUNC_IN_PORT + - FOREACH_DEVICE_ON_AUXILIARY_BUS + - FOREACH_DEVICE_ON_CDXBUS + - FOREACH_DEVICE_ON_PCIBUS + - FOREACH_DEVICE_ON_PLATFORM_BUS + - FOREACH_DEVICE_ON_UACCEBUS + - FOREACH_DEVICE_ON_VMBUS + - FOREACH_DRIVER_ON_AUXILIARY_BUS + - FOREACH_DRIVER_ON_CDXBUS + - FOREACH_DRIVER_ON_PCIBUS + - FOREACH_DRIVER_ON_PLATFORM_BUS + - FOREACH_DRIVER_ON_UACCEBUS + - FOREACH_DRIVER_ON_VMBUS + - FOREACH_SUBDEV + - FOREACH_SUBDEV_STATE + - FOR_EACH + - FOR_EACH_BUCKET + - FOR_EACH_CNIC_QUEUE + - FOR_EACH_COS_IN_TX_QUEUE + - FOR_EACH_ETH_QUEUE + - FOR_EACH_MEMBER + - FOR_EACH_NONDEFAULT_ETH_QUEUE + - FOR_EACH_NONDEFAULT_QUEUE + - FOR_EACH_PORT + - FOR_EACH_PORT_IF + - FOR_EACH_QUEUE + - FOR_EACH_SUITE_TESTCASE + - FOR_EACH_SUITE_TESTSUITE + - HLIST_FOR_EACH_ENTRY + - ILIST_FOREACH + - LIST_FOREACH + - LIST_FOREACH_FROM + - LIST_FOREACH_FROM_SAFE + - LIST_FOREACH_SAFE + - LIST_FOR_EACH_ENTRY + - LIST_FOR_EACH_ENTRY_SAFE + - MLX5_ETH_FOREACH_DEV + - MLX5_IPOOL_FOREACH + - MLX5_L3T_FOREACH + - ML_AVG_FOREACH_QP + - ML_AVG_FOREACH_QP_MVTVM + - ML_AVG_RESET_FOREACH_QP + - ML_MAX_FOREACH_QP + - ML_MAX_FOREACH_QP_MVTVM + - ML_MAX_RESET_FOREACH_QP + - ML_MIN_FOREACH_QP + - ML_MIN_FOREACH_QP_MVTVM + - ML_MIN_RESET_FOREACH_QP + - OSAL_LIST_FOR_EACH_ENTRY + - OSAL_LIST_FOR_EACH_ENTRY_SAFE + - PLT_TAILQ_FOREACH_SAFE + - RTE_BBDEV_FOREACH + - RTE_BBDEV_FOREACH + - RTE_DEV_FOREACH + - RTE_DEV_FOREACH + - RTE_DMA_FOREACH_DEV + - RTE_DMA_FOREACH_DEV + - RTE_EAL_DEVARGS_FOREACH + - RTE_EAL_DEVARGS_FOREACH + - RTE_ETH_FOREACH_DEV + - RTE_ETH_FOREACH_DEV + - RTE_ETH_FOREACH_DEV_OF + - RTE_ETH_FOREACH_DEV_OF + - RTE_ETH_FOREACH_DEV_OWNED_BY + - RTE_ETH_FOREACH_DEV_OWNED_BY + - RTE_ETH_FOREACH_DEV_SIBLING + - RTE_ETH_FOREACH_DEV_SIBLING + - RTE_ETH_FOREACH_MATCHING_DEV + - RTE_ETH_FOREACH_MATCHING_DEV + - RTE_ETH_FOREACH_VALID_DEV + - RTE_ETH_FOREACH_VALID_DEV + - RTE_GPU_FOREACH + - RTE_GPU_FOREACH + - RTE_GPU_FOREACH_CHILD + - RTE_GPU_FOREACH_CHILD + - RTE_GPU_FOREACH_PARENT + - RTE_GPU_FOREACH_PARENT + - RTE_LCORE_FOREACH + - RTE_LCORE_FOREACH + - RTE_LCORE_FOREACH_WORKER + - RTE_LCORE_FOREACH_WORKER + - RTE_TAILQ_FOREACH + - RTE_TAILQ_FOREACH + - RTE_TAILQ_FOREACH_SAFE + - RTE_TAILQ_FOREACH_SAFE + - SILIST_FOREACH + - SLIST_FOREACH + - SLIST_FOREACH_FROM + - SLIST_FOREACH_FROM_SAFE + - SLIST_FOREACH_PREVPTR + - SLIST_FOREACH_SAFE + - STAILQ_FOREACH + - STAILQ_FOREACH_FROM + - STAILQ_FOREACH_FROM_SAFE + - STAILQ_FOREACH_SAFE + - TAILQ_FOREACH + - TAILQ_FOREACH_ENTRY + - TAILQ_FOREACH_ENTRY_SAFE + - TAILQ_FOREACH_FROM + - TAILQ_FOREACH_FROM_SAFE + - TAILQ_FOREACH_REVERSE + - TAILQ_FOREACH_REVERSE_FROM + - TAILQ_FOREACH_REVERSE_FROM_SAFE + - TAILQ_FOREACH_REVERSE_SAFE + - TAILQ_FOREACH_SAFE + +ObjCSpaceAfterProperty: true +IndentGotoLabels: false
Quoted 73 lines · Stephen Hemminger
Quoted 7 lines · On Sun, 5 May 2024 22:42:57 +0300 Abdullah Ömer Yamaç <[email protected]>…
Review
Quoted 7 lines
Also, this looks wrong. The initialized arrays looked better before.
(quoted diff) +1
-3-static const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] = { - "UNKNOWN", "TUN", "TAP" -}; +static const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] = {"UNKNOWN","TUN",
Quoted 15 lines
Quoted 10 lines
"TAP"};
(quoted diff) +1
-7-static const char *valid_arguments[] = { - ETH_TAP_IFACE_ARG, - ETH_TAP_REMOTE_ARG, - ETH_TAP_MAC_ARG, - ETH_TAP_PERSIST_ARG, - NULL -}; +static const char *valid_arguments[] = {ETH_TAP_IFACE_ARG,Quoted 3 lines
ETH_TAP_REMOTE_ARG,ETH_TAP_MAC_ARG,
+ETH_TAP_PERSIST_ARG, NULL};I am confused about these variables.
tuntap_typeslist values in asingle
Quoted 3 lines
line, but
valid_arguments' values are listed separately.
So, it is getting more complex to handle both of them. What should we do, do you have any idea?Ignore the initialized lists for now. It should be possible to have it generate something
likestatic const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] = { "UNKNOWN", "TUN", "TAP" };With the following changes result looks better. You got the format wrong for the ForEach list.
.clang-format +9
-0@@ -1,12 +1,20 @@ --- BasedOnStyle: LLVM +AttributeMacros: + - __rte_aligned + - __rte_packed + - __rte_may_alias + - __rte_deprecated + - __rte_weak + - __rte_unused + - __rte_restrict + # Place opening and closing parentheses on the same line for controlstatements
BreakBeforeBraces: Custom
BraceWrapping:.clang-format +1
-2- AfterFunction: false + AfterFunction: true AfterControlStatement: false - AfterEnum: falseThese are ok for me.
# Set maximum line length to 100 characters
ColumnLimit: 100
.clang-format AlwaysBreakAfterReturnType: TopLevelDefinitions · line 52
Quoted 5 lines
.clang-format +0
-1@@ -41,98 +49,117 @@ AlwaysBreakAfterReturnType: TopLevelDefinitions # Always break before multiline string literals AlignEscapedNewlines: Left -# Foreach macros
In the clang documentation, it says "ForEachMacros (List of Strings)" and gives an example: "ForEachMacros: ['RANGES_FOR', 'FOREACH']"
.clang-format AlwaysBreakAfterReturnType: TopLevelDefinitions · line 165
Quoted 4 lines
...
.clang-format +2
-0+ObjCSpaceAfterProperty: true +IndentGotoLabels: false
These are also ok for me.
If you agree on the for-each part, then I will send the new patch. Thanks
PATCH v4 1/1 devtools: add .clang-format file
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
--- .clang-format | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 .clang-format
.clang-format new file +141 -0
@@ -0,0 +1,141 @@ +--- +BasedOnStyle: LLVM + +# Place opening and closing parentheses on the same line for control statements +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: true + AfterControlStatement: false + +# Set maximum line length to 100 characters +ColumnLimit: 100 + +# Use LF (line feed) as the end-of-line character +LineEnding: LF + +# Insert a newline at the end of the file +InsertNewlineAtEOF: true + +# Set indentation width to 8 spaces +IndentWidth: 8 + +# Set continuation indentation width to 8 spaces +ContinuationIndentWidth: 8 + +# Set tab width to 8 spaces +TabWidth: 8 + +# Use tabs for indentation +UseTab: Always + +# Preserve include blocks as they are +IncludeBlocks: Preserve + +# Never sort includes +SortIncludes: Never + +# Always break after return type for top-level definitions +AlwaysBreakAfterReturnType: TopLevelDefinitions + +# Always break before multiline string literals +AlignEscapedNewlines: Left + +# Foreach macros +ForEachMacros: + [ + "CIRBUF_FOREACH", + "DLB2_LIST_FOR_EACH", + "DLB2_LIST_FOR_EACH_SAFE", + "ECORE_LIST_FOR_EACH_ENTRY", + "ECORE_LIST_FOR_EACH_ENTRY_SAFE", + "FOR_EACH", + "FOR_EACH_BUCKET", + "FOR_EACH_CNIC_QUEUE", + "FOR_EACH_COS_IN_TX_QUEUE", + "FOR_EACH_ETH_QUEUE", + "FOR_EACH_MEMBER", + "FOR_EACH_NONDEFAULT_ETH_QUEUE", + "FOR_EACH_NONDEFAULT_QUEUE", + "FOR_EACH_PORT", + "FOR_EACH_PORT_IF", + "FOR_EACH_QUEUE", + "FOR_EACH_SUITE_TESTCASE", + "FOR_EACH_SUITE_TESTSUITE", + "FOREACH_ABS_FUNC_IN_PORT", + "FOREACH_DEVICE_ON_AUXILIARY_BUS", + "FOREACH_DEVICE_ON_CDXBUS", + "FOREACH_DEVICE_ON_PCIBUS", + "FOREACH_DEVICE_ON_PLATFORM_BUS", + "FOREACH_DEVICE_ON_UACCEBUS", + "FOREACH_DEVICE_ON_VMBUS", + "FOREACH_DRIVER_ON_AUXILIARY_BUS", + "FOREACH_DRIVER_ON_CDXBUS", + "FOREACH_DRIVER_ON_PCIBUS", + "FOREACH_DRIVER_ON_PLATFORM_BUS", + "FOREACH_DRIVER_ON_UACCEBUS", + "FOREACH_DRIVER_ON_VMBUS", + "FOREACH_SUBDEV", + "FOREACH_SUBDEV_STATE", + "HLIST_FOR_EACH_ENTRY", + "ILIST_FOREACH", + "LIST_FOR_EACH_ENTRY", + "LIST_FOR_EACH_ENTRY_SAFE", + "LIST_FOREACH", + "LIST_FOREACH_FROM", + "LIST_FOREACH_FROM_SAFE", + "LIST_FOREACH_SAFE", + "ML_AVG_FOREACH_QP", + "ML_AVG_FOREACH_QP_MVTVM", + "ML_AVG_RESET_FOREACH_QP", + "ML_MAX_FOREACH_QP", + "ML_MAX_FOREACH_QP_MVTVM", + "ML_MAX_RESET_FOREACH_QP", + "ML_MIN_FOREACH_QP", + "ML_MIN_FOREACH_QP_MVTVM", + "ML_MIN_RESET_FOREACH_QP", + "MLX5_ETH_FOREACH_DEV", + "MLX5_IPOOL_FOREACH", + "MLX5_L3T_FOREACH", + "OSAL_LIST_FOR_EACH_ENTRY", + "OSAL_LIST_FOR_EACH_ENTRY_SAFE", + "PLT_TAILQ_FOREACH_SAFE", + "RTE_BBDEV_FOREACH", + "RTE_DEV_FOREACH", + "RTE_DMA_FOREACH_DEV", + "RTE_EAL_DEVARGS_FOREACH", + "RTE_ETH_FOREACH_DEV", + "RTE_ETH_FOREACH_DEV_OF", + "RTE_ETH_FOREACH_DEV_OWNED_BY", + "RTE_ETH_FOREACH_DEV_SIBLING", + "RTE_ETH_FOREACH_MATCHING_DEV", + "RTE_ETH_FOREACH_VALID_DEV", + "RTE_GPU_FOREACH", + "RTE_GPU_FOREACH_CHILD", + "RTE_GPU_FOREACH_PARENT", + "RTE_LCORE_FOREACH", + "RTE_LCORE_FOREACH_WORKER", + "RTE_TAILQ_FOREACH", + "RTE_TAILQ_FOREACH_SAFE", + "SILIST_FOREACH", + "SLIST_FOREACH", + "SLIST_FOREACH_FROM", + "SLIST_FOREACH_FROM_SAFE", + "SLIST_FOREACH_PREVPTR", + "SLIST_FOREACH_SAFE", + "STAILQ_FOREACH", + "STAILQ_FOREACH_FROM", + "STAILQ_FOREACH_FROM_SAFE", + "STAILQ_FOREACH_SAFE", + "TAILQ_FOREACH", + "TAILQ_FOREACH_ENTRY", + "TAILQ_FOREACH_ENTRY_SAFE", + "TAILQ_FOREACH_FROM", + "TAILQ_FOREACH_FROM_SAFE", + "TAILQ_FOREACH_REVERSE", + "TAILQ_FOREACH_REVERSE_FROM", + "TAILQ_FOREACH_REVERSE_FROM_SAFE", + "TAILQ_FOREACH_REVERSE_SAFE", + "TAILQ_FOREACH_SAFE", + ] +ObjCSpaceAfterProperty: true +IndentGotoLabels: false
Signature · 1 line
2.34.1
Quoted 10 lines · Abdullah Ömer Yamaç
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>
Hi Omer,
I tried on ethdev.c (clang-format -i ./lib/ethdev/rte_ethdev.c), I will highlight a few issues below (not all of them), I hope it is OK to continue step by step, fixing these issues.
1. clang format failed for following options, not sure why, am I using a wrong version:
LineEnding: LF
InsertNewlineAtEOF: true
I commented them out to continue the test.
And for 'ColumnLimit', I prefer default 80 with the flexibility to go 100 when makes sense, so I will got with 'ColumnLimit: 80'; but I don't want to start this discussion.
2. Double tab indentation vs parenthesis align
if (iter->bus != NULL &&
- /* not in middle of rte_eth_dev iteration, */
- iter->class_device == NULL) {
+ /* not in middle of rte_eth_dev iteration, */
+ iter->class_device == NULL) {
DPDK coding guide suggests double tab, but also accepts alignment by spaces. But as far as I can see most of code has double tab. Majority of the diff caused because of this rule.
3. enum merged into single line
-enum {
- STAT_QMAP_TX = 0,
- STAT_QMAP_RX
-};
+enum { STAT_QMAP_TX = 0, STAT_QMAP_RX };
4. split message strings
- RTE_ETHDEV_LOG_LINE(ERR,
- "Cannot initialize iterator from NULL device description
string");
+ RTE_ETHDEV_LOG_LINE(ERR, "Cannot initialize iterator from NULL "
+ "device description string");
5. Empty open parenthesis
- RTE_ETHDEV_LOG_LINE(ERR,
- "Cannot get next device from NULL iterator");
+ RTE_ETHDEV_LOG_LINE(
+ ERR, "Cannot get next device from NULL iterator");
6. space before macro arguments
- RTE_ETH_FOREACH_DEV(p)
+ RTE_ETH_FOREACH_DEV (p)
7. some lists get merged (this seems similar to 3.)
- RTE_PTYPE_L2_MASK, - RTE_PTYPE_L3_MASK, - RTE_PTYPE_L4_MASK, - RTE_PTYPE_TUNNEL_MASK, - RTE_PTYPE_INNER_L2_MASK, - RTE_PTYPE_INNER_L3_MASK, + RTE_PTYPE_L2_MASK, RTE_PTYPE_L3_MASK, + RTE_PTYPE_L4_MASK, RTE_PTYPE_TUNNEL_MASK, + RTE_PTYPE_INNER_L2_MASK, RTE_PTYPE_INNER_L3_MASK,
Thanks,
ferruh
Quoted 10 lines · On Mon, 13 May 2024 14:08:07 +0100 Ferruh Yigit <[email protected]> wrote:
2. Double tab indentation vs parenthesis align
if (iter->bus != NULL &&- /* not in middle of
rte_eth_deviteration, */
-iter->class_device== NULL) {
+ /* not in middle ofrte_eth_deviteration, */
+iter->class_device== NULL) {DPDK coding guide suggests double tab, but also accepts alignment by spaces. But as far as I can see most of code has double tab. Majority of the diff caused because of this rule.
I personally am more used the aligned style, and most tools support that. The DPDK one is unique (not done by most other projects). So can we just keep the kernel (what is this clang-format) version.
Quoted 18 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 13 May 2024 17.55Quoted 10 lines · On Mon, 13 May 2024 14:08:07 +0100 Ferruh Yigit <[email protected]> wrote:
2. Double tab indentation vs parenthesis align
if (iter->bus != NULL &&- /* not in middle of
rte_eth_deviteration, */
-iter->class_device== NULL) {
+ /* not in middle ofrte_eth_deviteration, */
+iter->class_device== NULL) {DPDK coding guide suggests double tab, but also accepts alignment by spaces. But as far as I can see most of code has double tab. Majority of the diff caused because of this rule.
Quoted 4 lines
I personally am more used the aligned style, and most tools support that.
The DPDK one is unique (not done by most other projects). So can we just keep the kernel (what is this clang-format) version.
I personally prefer the double tab.
It also works with editors showing tab as 4 space indentation.
Mixing tabs and spaces only works if the editor shows tabs as 8 space indentation.
Double tab works with both editor configurations.
And there is no confusion if the following block happens to be aligned with the following parameters. E.g.:
if fool(x,
y)
myfn();vs.
if fool(x,
y)
myfn();Quoted 33 lines · Morten Brørup
Quoted 18 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 13 May 2024 17.55Quoted 10 lines · On Mon, 13 May 2024 14:08:07 +0100 Ferruh Yigit <[email protected]> wrote:
2. Double tab indentation vs parenthesis align
if (iter->bus != NULL &&- /* not in middle of
rte_eth_deviteration, */
-iter->class_device== NULL) {
+ /* not in middle ofrte_eth_deviteration, */
+iter->class_device== NULL) {DPDK coding guide suggests double tab, but also accepts alignment by spaces. But as far as I can see most of code has double tab. Majority of the diff caused because of this rule.
Quoted 4 lines
I personally am more used the aligned style, and most tools support that.
The DPDK one is unique (not done by most other projects). So can we just keep the kernel (what is this clang-format) version.I personally prefer the double tab.
It also works with editors showing tab as 4 space indentation.Mixing tabs and spaces only works if the editor shows tabs as 8 space indentation.
Double tab works with both editor configurations.
And there is no confusion if the following block happens to be aligned with the following parameters. E.g.:
if fool(x,
Quoted 9 lines
y) myfn();vs.
if fool(x,
y) myfn();
+1, I also prefer the double tab too for this reason. The other consideration is that double tab leads to smaller diffs on refactor - with aligning brackets if something on the first line changes it could cause whitespace changes to be needed on all subsequent lines
Overall, ignoring our individual preferences, since we already have a mix in DPDK, I think it's infeasible to try and enforce a single standard now. :-(
/Bruce
Quoted 44 lines · Bruce Richardson
Quoted 33 lines · Morten Brørup
Quoted 18 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 13 May 2024 17.55Quoted 10 lines · On Mon, 13 May 2024 14:08:07 +0100 Ferruh Yigit <[email protected]> wrote:
2. Double tab indentation vs parenthesis align
if (iter->bus != NULL &&- /* not in middle of
rte_eth_deviteration, */
-iter->class_device== NULL) {
+ /* not in middle ofrte_eth_deviteration, */
+iter->class_device== NULL) {DPDK coding guide suggests double tab, but also accepts alignment by spaces. But as far as I can see most of code has double tab. Majority of the diff caused because of this rule.
Quoted 4 lines
I personally am more used the aligned style, and most tools support that.
The DPDK one is unique (not done by most other projects). So can we just keep the kernel (what is this clang-format) version.I personally prefer the double tab.
It also works with editors showing tab as 4 space indentation.Mixing tabs and spaces only works if the editor shows tabs as 8 space indentation.
Double tab works with both editor configurations.
And there is no confusion if the following block happens to be aligned with the following parameters. E.g.:
if fool(x,
Quoted 9 lines
y) myfn();vs.
if fool(x,
y) myfn();
Quoted 8 lines
+1, I also prefer the double tab too for this reason. The other consideration is that double tab leads to smaller diffs on refactor - with aligning brackets if something on the first line changes it could cause whitespace changes to be needed on all subsequent lines
Overall, ignoring our individual preferences, since we already have a mix in DPDK, I think it's infeasible to try and enforce a single standard now. :-(
-1 to anything that aligns with parameters. it's the most mechanically inconsistent convention ever, hostile to refactoring and causes a requirement to endlessly shift your eyes horizontally when reading code sequentially.
I want to update you.
Quoted 23 lines · Ferruh Yigit
Quoted 10 lines · Abdullah Ömer Yamaç
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>Hi Omer,
I tried on
ethdev.c(clang-format -i./lib/ethdev/rte_ethdev.c), I will highlight a few issues below (not all of them), I hope it is OK to continue step by step, fixing these issues.1. clang format failed for following options, not sure why, am I using a wrong version:
LineEnding: LF
InsertNewlineAtEOF: true
Quoted 7 lines
I commented them out to continue the test.
And for 'ColumnLimit', I prefer default 80 with the flexibility to go 100 when makes sense, so I will got with 'ColumnLimit: 80'; but I don't want to start this discussion.
In the .editorconfig file, 100 is stated as a
max_line_length. That's why
I prefer 100.
Quoted 67 lines
2. Double tab indentation vs parenthesis align
if (iter->bus != NULL &&- /* not in middle of
rte_eth_deviteration, */
-iter->class_device== NULL) {
+ /* not in middle ofrte_eth_deviteration, */
+iter->class_device== NULL) {DPDK coding guide suggests double tab, but also accepts alignment by spaces. But as far as I can see most of code has double tab. Majority of the diff caused because of this rule.
Still, some discussions are going on
3. enum merged into single line
-enum {
-STAT_QMAP_TX= 0,
-STAT_QMAP_RX
-};
+enum {STAT_QMAP_TX= 0,STAT_QMAP_RX};This is ok; I will send a new patch for it.
4. split message strings
- RTE_ETHDEV_LOG_LINE(ERR,
- "Cannot initialize iterator from NULL device description
string");
+ RTE_ETHDEV_LOG_LINE(ERR, "Cannot initialize iterator from NULL "
+ "device description string");5. Empty open parenthesis
- RTE_ETHDEV_LOG_LINE(ERR,
- "Cannot get next device from NULL iterator");
+ RTE_ETHDEV_LOG_LINE(
+ ERR, "Cannot get next device from NULL iterator");I couldn't find a solution, so I am still working on it.
6. space before macro arguments
(quoted diff) +1
-1- RTE_ETH_FOREACH_DEV(p) + RTE_ETH_FOREACH_DEV (p)This is ok. The fix will be in the next patch.
7. some lists get merged (this seems similar to 3.)
- RTE_PTYPE_L2_MASK, - RTE_PTYPE_L3_MASK, - RTE_PTYPE_L4_MASK, - RTE_PTYPE_TUNNEL_MASK, - RTE_PTYPE_INNER_L2_MASK, - RTE_PTYPE_INNER_L3_MASK, + RTE_PTYPE_L2_MASK, RTE_PTYPE_L3_MASK, + RTE_PTYPE_L4_MASK, RTE_PTYPE_TUNNEL_MASK, + RTE_PTYPE_INNER_L2_MASK, RTE_PTYPE_INNER_L3_MASK,I couldn't find a configuration that aligns with array initialization.
Thanks,
ferruh
Quoted 35 lines · Abdullah Ömer Yamaç
I want to update you.
On Mon, May 13, 2024 at 4:08 PM Ferruh Yigit <[1][email protected]> wrote:On 5/8/2024 10:19 PM, Abdullah Ömer Yamaç wrote:
> clang-format is a tool to format C/C++/Objective-C code. It can be used
> to reformat code to match a given coding style, or to ensure that code
> adheres to a specific coding style. It helps to maintain a consistent
> coding style across the DPDK codebase.
>
> .clang-format file overrides the default style options provided by > clang-format and large set of IDEs and text editors support it. >
> Signed-off-by: Abdullah Ömer Yamaç <[2][email protected]> >
Hi Omer,
I tried onethdev.c(clang-format -i./lib/ethdev/rte_ethdev.c), I will
highlight a few issues below (not all of them), I hope it is OK to continue step by step, fixing these issues.
1. clang format failed for following options, not sure why, am I using a
wrong version:
LineEnding: LF
InsertNewlineAtEOF: true
I commented them out to continue the test.
And for 'ColumnLimit', I prefer default 80 with the flexibility to go
100 when makes sense, so I will got with 'ColumnLimit: 80'; but I don't
want to start this discussion.
Quoted 3 lines
In the .editorconfig file, 100 is stated as a
max_line_length. That's why I prefer 100.
+1 for keeping as 100
Quoted 11 lines
2. Double tab indentation vs parenthesis align
if (iter->bus!= NULL &&
- /* not in middle ofrte_eth_deviteration,
*/
-iter->class_device== NULL) {
+ /* not in middle ofrte_eth_deviteration, */
+iter->class_device== NULL) {
DPDK coding guide suggests double tab, but also accepts alignment by spaces. But as far as I can see most of code has double tab. Majority of the diff caused because of this rule.
Quoted 2 lines
Still, some discussions are going on
This is one where I don't think we will were reach a consensus, and even if we did, it would mean massive churn to DPDK. Can we have clang-format NOT adjust line-continuations in a file?
Thanks,
/Bruce
Quoted 54 lines · Bruce Richardson
Quoted 36 lines · Abdullah Ömer Yamaç
I want to update you.
On Mon, May 13, 2024 at 4:08 PM Ferruh Yigit <[1][email protected]wrote:
On 5/8/2024 10:19 PM, Abdullah Ömer Yamaç wrote:
> clang-format is a tool to format C/C++/Objective-C code. It can be used
> to reformat code to match a given coding style, or to ensure that code
> adheres to a specific coding style. It helps to maintain a consistent
> coding style across the DPDK codebase.
>
> .clang-format file overrides the default style options provided by > clang-format and large set of IDEs and text editors support it. >
> Signed-off-by: Abdullah Ömer Yamaç <[2][email protected]> >
Hi Omer,
I tried onethdev.c(clang-format -i./lib/ethdev/rte_ethdev.c), I will
highlight a few issues below (not all of them), I hope it is OK to continue step by step, fixing these issues.
1. clang format failed for following options, not sure why, am I using a
wrong version:
LineEnding: LF
InsertNewlineAtEOF: true
I commented them out to continue the test.
And for 'ColumnLimit', I prefer default 80 with the flexibility to go
100 when makes sense, so I will got with 'ColumnLimit: 80'; but I don't
want to start this discussion.Quoted 3 lines
In the .editorconfig file, 100 is stated as a
max_line_length. That's why I prefer 100.+1 for keeping as 100
Quoted 11 lines
2. Double tab indentation vs parenthesis align
if (iter->bus!= NULL &&
- /* not in middle ofrte_eth_deviteration,
*/
-iter->class_device== NULL) {
+ /* not in middle ofrte_eth_deviteration, */
+iter->class_device== NULL) {
DPDK coding guide suggests double tab, but also accepts alignment by spaces. But as far as I can see most of code has double tab. Majority of the diff caused because of this rule.
Quoted 8 lines
Quoted 2 lines
Still, some discussions are going on
This is one where I don't think we will were reach a consensus, and even if we did, it would mean massive churn to DPDK. Can we have clang-format NOT adjust line-continuations in a file?
I am not an expert on clang, but it seems we don't have such a
configuration.
There is an option called "AlignAfterOpenBracket" which horizontally aligns arguments after an open bracket.
if I set it to "DontAlign" then "ContinuationIndentWidth" will be active. Depending on the value of ContinuationIndentWidth, two tabs, single tabs, or spaces will be acceptable.
Quoted 3 lines
Thanks,
/Bruce
Quoted 76 lines · Abdullah Ömer Yamaç
On Wed, May 15, 2024 at 11:43 AM Bruce Richardson <[1][email protected]> wrote:
On Wed, May 15, 2024 at 11:28:33AM +0300, Abdullah Ömer Yamaç wrote:
> I want to update you.
> On Mon, May 13, 2024 at 4:08 PM Ferruh Yigit
<[1][2][email protected]>
> wrote:
>
> On 5/8/2024 10:19 PM, Abdullah Ömer Yamaç wrote:
> > clang-format is a tool to format C/C++/Objective-C code. It
can be
> used
> > to reformat code to match a given coding style, or to
ensure that
> code
> > adheres to a specific coding style. It helps to maintain a
> consistent
> > coding style across the DPDK codebase.
> >
> > .clang-format file overrides the default style options
provided by
> > clang-format and large set of IDEs and text editors support
it.
> >
> > Signed-off-by: Abdullah Ömer Yamaç
<[2][3][email protected]>
> >
> Hi Omer,
> I tried onethdev.c(clang-format -i
./lib/ethdev/rte_ethdev.c), I
> will
> highlight a few issues below (not all of them), I hope it is
OK to
> continue step by step, fixing these issues.
> 1. clang format failed for following options, not sure why,
am I
> using a
> wrong version:
> LineEnding: LF
> InsertNewlineAtEOF: true
> I commented them out to continue the test.
> And for 'ColumnLimit', I prefer default 80 with the
flexibility to
> go
> 100 when makes sense, so I will got with 'ColumnLimit: 80';
but I
> don't
> want to start this discussion.
>
> In the .editorconfig file, 100 is stated as amax_line_length.
That's
> why I prefer 100.
>
+1 for keeping as 100
> 2. Double tab indentation vs parenthesis align
> if (iter->bus!= NULL &&
> - /* not in middle ofrte_eth_dev
iteration,
> */
> -iter->class_device== NULL) {
> + /* not in middle ofrte_eth_deviteration, */
> +iter->class_device== NULL) {
> DPDK coding guide suggests double tab, but also accepts
alignment by
> spaces. But as far as I can see most of code has double tab.
> Majority of the diff caused because of this rule.
>
> Still, some discussions are going on
>
This is one where I don't think we will were reach a consensus, and even if
we did, it would mean massive churn to DPDK. Can we have clang-format NOT
adjust line-continuations in a file?
Quoted 8 lines
I am not an expert on clang, but it seems we don't have such a configuration.
There is an option called "AlignAfterOpenBracket" which horizontally aligns arguments after an open bracket.
if I set it to "DontAlign" then "ContinuationIndentWidth" will be active. Depending on the value of ContinuationIndentWidth, two tabs, single tabs, or spaces will be acceptable.
Is there any way to specify per-file the style to be used, e.g. via a header in the file or a macro to override? While the whole DPDK project is inconsistent, we should look for consistency within files.
In the absence of that, given the number of strong opinions already expressed, I'd suggest defaulting the align value to DontAlign for now.
/Bruce
Quoted 53 lines · On Wed, 15 May 2024 09:43:22 +0100 Bruce Richardson…
Quoted 35 lines · Abdullah Ömer Yamaç
I want to update you.
On Mon, May 13, 2024 at 4:08 PM Ferruh Yigit <[1][email protected]> wrote:On 5/8/2024 10:19 PM, Abdullah Ömer Yamaç wrote:
> clang-format is a tool to format C/C++/Objective-C code. It can be used
> to reformat code to match a given coding style, or to ensure that code
> adheres to a specific coding style. It helps to maintain a consistent
> coding style across the DPDK codebase.
>
> .clang-format file overrides the default style options provided by > clang-format and large set of IDEs and text editors support it. >
> Signed-off-by: Abdullah Ömer Yamaç <[2][email protected]> >
Hi Omer,
I tried onethdev.c(clang-format -i./lib/ethdev/rte_ethdev.c), I will
highlight a few issues below (not all of them), I hope it is OK to continue step by step, fixing these issues.
1. clang format failed for following options, not sure why, am I using a
wrong version:
LineEnding: LF
InsertNewlineAtEOF: true
I commented them out to continue the test.
And for 'ColumnLimit', I prefer default 80 with the flexibility to go
100 when makes sense, so I will got with 'ColumnLimit: 80'; but I don't
want to start this discussion.Quoted 3 lines
In the .editorconfig file, 100 is stated as a
max_line_length. That's why I prefer 100.+1 for keeping as 100
Quoted 11 lines
2. Double tab indentation vs parenthesis align
if (iter->bus!= NULL &&
- /* not in middle ofrte_eth_deviteration,
*/
-iter->class_device== NULL) {
+ /* not in middle ofrte_eth_deviteration, */
+iter->class_device== NULL) {
DPDK coding guide suggests double tab, but also accepts alignment by spaces. But as far as I can see most of code has double tab. Majority of the diff caused because of this rule.
Quoted 6 lines
Quoted 2 lines
Still, some discussions are going on
This is one where I don't think we will were reach a consensus, and even if we did, it would mean massive churn to DPDK. Can we have clang-format NOT adjust line-continuations in a file?
Clang format is useful on new and seriously broken code.
Do not want to do it automatically or accept patches across all the current code.
For indentation, can we get some setting that matches what DPDK double tab does? If not is there something close. Often useful to look at the other clang format pre-set styles in source.
Quoted 72 lines · Stephen Hemminger
Quoted 3 lines · On Wed, 15 May 2024 09:43:22 +0100 Bruce Richardson…
Quoted 2 lines · Abdullah Ömer Yamaç
I want to update you.
On Mon, May 13, 2024 at 4:08 PM Ferruh Yigit <[1]Quoted 4 lines
Quoted 4 lines
wrote:
On 5/8/2024 10:19 PM, Abdullah Ömer Yamaç wrote:
> clang-format is a tool to format C/C++/Objective-C code. It canbe
Quoted 2 lines
Quoted 2 lines
used
> to reformat code to match a given coding style, or to ensurethat
Quoted 6 lines
Quoted 6 lines
code
> adheres to a specific coding style. It helps to maintain a consistent
> coding style across the DPDK codebase.
>
> .clang-format file overrides the default style options providedby
Quoted 21 lines
Quoted 21 lines
> clang-format and large set of IDEs and text editors support it. >
> Signed-off-by: Abdullah Ömer Yamaç <[2][email protected]> >
Hi Omer,
I tried onethdev.c(clang-format -i./lib/ethdev/rte_ethdev.c), I will
highlight a few issues below (not all of them), I hope it is OK to continue step by step, fixing these issues.
1. clang format failed for following options, not sure why, am I using a
wrong version:
LineEnding: LF
InsertNewlineAtEOF: true
I commented them out to continue the test.
And for 'ColumnLimit', I prefer default 80 with the flexibility to go
100 when makes sense, so I will got with 'ColumnLimit: 80'; but I don't
want to start this discussion.Quoted 1 line
Quoted 1 line
In the .editorconfig file, 100 is stated as a
max_line_length.That's
Quoted 8 lines
Quoted 2 lines
why I prefer 100.
+1 for keeping as 100
Quoted 3 lines
2. Double tab indentation vs parenthesis align if (
iter->bus!= NULL &&
- /* not in middle ofrte_eth_deviteration,
Quoted 5 lines
Quoted 5 lines
*/
-iter->class_device== NULL) {
+ /* not in middle ofrte_eth_deviteration, */
+iter->class_device== NULL) {
DPDK coding guide suggests double tab, but also accepts alignmentby
Quoted 7 lines
Quoted 5 lines
spaces. But as far as I can see most of code has double tab. Majority of the diff caused because of this rule.
Still, some discussions are going on
This is one where I don't think we will were reach a consensus, and even
if
Quoted 2 lines
we did, it would mean massive churn to DPDK. Can we have clang-format NOT adjust line-continuations in a file?
Quoted 7 lines
Clang format is useful on new and seriously broken code. Do not want to do it automatically or accept patches across all the current code.
For indentation, can we get some setting that matches what DPDK double tab does?
It seems possible. If there is no objection, I will send a new patch with the previous notes Ferruh stated.
Quoted 4 lines
If not is there something close. Often useful to look at the other clang format
pre-set styles in source.
PATCH v5 1/1 devtools: add .clang-format file
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
--- .clang-format | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 .clang-format
.clang-format new file +149 -0
@@ -0,0 +1,149 @@ +--- +BasedOnStyle: LLVM + +# Place opening and closing parentheses on the same line for control statements +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: true + AfterControlStatement: false + +AllowShortEnumsOnASingleLine: false + +# Should be declared this way: +SpaceBeforeParens: Custom +SpaceBeforeParensOptions: + AfterForeachMacros: false + +# Set maximum line length to 100 characters +ColumnLimit: 100 + +# Use LF (line feed) as the end-of-line character +LineEnding: LF + +# Insert a newline at the end of the file +InsertNewlineAtEOF: true + +# Set indentation width to 8 spaces +IndentWidth: 8 + +# Set continuation indentation width to 16 spaces (2 tabs) +AlignAfterOpenBracket: DontAlign +ContinuationIndentWidth: 16 + +# Set tab width to 8 spaces +TabWidth: 8 + +# Use tabs for indentation +UseTab: Always + +# Preserve include blocks as they are +IncludeBlocks: Preserve + +# Never sort includes +SortIncludes: Never + +# Always break after return type for top-level definitions +AlwaysBreakAfterReturnType: TopLevelDefinitions + +# Always break before multiline string literals +AlignEscapedNewlines: Left + +# Foreach macros +ForEachMacros: + [ + "CIRBUF_FOREACH", + "DLB2_LIST_FOR_EACH", + "DLB2_LIST_FOR_EACH_SAFE", + "ECORE_LIST_FOR_EACH_ENTRY", + "ECORE_LIST_FOR_EACH_ENTRY_SAFE", + "FOR_EACH", + "FOR_EACH_BUCKET", + "FOR_EACH_CNIC_QUEUE", + "FOR_EACH_COS_IN_TX_QUEUE", + "FOR_EACH_ETH_QUEUE", + "FOR_EACH_MEMBER", + "FOR_EACH_NONDEFAULT_ETH_QUEUE", + "FOR_EACH_NONDEFAULT_QUEUE", + "FOR_EACH_PORT", + "FOR_EACH_PORT_IF", + "FOR_EACH_QUEUE", + "FOR_EACH_SUITE_TESTCASE", + "FOR_EACH_SUITE_TESTSUITE", + "FOREACH_ABS_FUNC_IN_PORT", + "FOREACH_DEVICE_ON_AUXILIARY_BUS", + "FOREACH_DEVICE_ON_CDXBUS", + "FOREACH_DEVICE_ON_PCIBUS", + "FOREACH_DEVICE_ON_PLATFORM_BUS", + "FOREACH_DEVICE_ON_UACCEBUS", + "FOREACH_DEVICE_ON_VMBUS", + "FOREACH_DRIVER_ON_AUXILIARY_BUS", + "FOREACH_DRIVER_ON_CDXBUS", + "FOREACH_DRIVER_ON_PCIBUS", + "FOREACH_DRIVER_ON_PLATFORM_BUS", + "FOREACH_DRIVER_ON_UACCEBUS", + "FOREACH_DRIVER_ON_VMBUS", + "FOREACH_SUBDEV", + "FOREACH_SUBDEV_STATE", + "HLIST_FOR_EACH_ENTRY", + "ILIST_FOREACH", + "LIST_FOR_EACH_ENTRY", + "LIST_FOR_EACH_ENTRY_SAFE", + "LIST_FOREACH", + "LIST_FOREACH_FROM", + "LIST_FOREACH_FROM_SAFE", + "LIST_FOREACH_SAFE", + "ML_AVG_FOREACH_QP", + "ML_AVG_FOREACH_QP_MVTVM", + "ML_AVG_RESET_FOREACH_QP", + "ML_MAX_FOREACH_QP", + "ML_MAX_FOREACH_QP_MVTVM", + "ML_MAX_RESET_FOREACH_QP", + "ML_MIN_FOREACH_QP", + "ML_MIN_FOREACH_QP_MVTVM", + "ML_MIN_RESET_FOREACH_QP", + "MLX5_ETH_FOREACH_DEV", + "MLX5_IPOOL_FOREACH", + "MLX5_L3T_FOREACH", + "OSAL_LIST_FOR_EACH_ENTRY", + "OSAL_LIST_FOR_EACH_ENTRY_SAFE", + "PLT_TAILQ_FOREACH_SAFE", + "RTE_BBDEV_FOREACH", + "RTE_DEV_FOREACH", + "RTE_DMA_FOREACH_DEV", + "RTE_EAL_DEVARGS_FOREACH", + "RTE_ETH_FOREACH_DEV", + "RTE_ETH_FOREACH_DEV_OF", + "RTE_ETH_FOREACH_DEV_OWNED_BY", + "RTE_ETH_FOREACH_DEV_SIBLING", + "RTE_ETH_FOREACH_MATCHING_DEV", + "RTE_ETH_FOREACH_VALID_DEV", + "RTE_GPU_FOREACH", + "RTE_GPU_FOREACH_CHILD", + "RTE_GPU_FOREACH_PARENT", + "RTE_LCORE_FOREACH", + "RTE_LCORE_FOREACH_WORKER", + "RTE_TAILQ_FOREACH", + "RTE_TAILQ_FOREACH_SAFE", + "SILIST_FOREACH", + "SLIST_FOREACH", + "SLIST_FOREACH_FROM", + "SLIST_FOREACH_FROM_SAFE", + "SLIST_FOREACH_PREVPTR", + "SLIST_FOREACH_SAFE", + "STAILQ_FOREACH", + "STAILQ_FOREACH_FROM", + "STAILQ_FOREACH_FROM_SAFE", + "STAILQ_FOREACH_SAFE", + "TAILQ_FOREACH", + "TAILQ_FOREACH_ENTRY", + "TAILQ_FOREACH_ENTRY_SAFE", + "TAILQ_FOREACH_FROM", + "TAILQ_FOREACH_FROM_SAFE", + "TAILQ_FOREACH_REVERSE", + "TAILQ_FOREACH_REVERSE_FROM", + "TAILQ_FOREACH_REVERSE_FROM_SAFE", + "TAILQ_FOREACH_REVERSE_SAFE", + "TAILQ_FOREACH_SAFE", + ] +ObjCSpaceAfterProperty: true +IndentGotoLabels: false
Signature · 1 line
2.34.1
Quoted 5 lines · Abdullah Ömer Yamaç
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
Quoted 9 lines
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>--- .clang-format | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 .clang-format
I think this is useful to have for new code esp. new libs/drivers.
Quoted 20 lines · On Thu, 16 May 2024 08:20:51 +0000 Abdullah Ömer Yamaç <[email protected]>…
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>--- .clang-format | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 .clang-format.clang-format new file +0
-0
.clang-format line 2
Quoted 2 lines
.clang-format new file +2
-0@@ -0,0 +1,149 @@ +--- +BasedOnStyle: LLVM
Looks good but any new file in DPDK needs a SPDX license header.
Not sure why, but it seems to be indenting somethings to much. Example:
Before clang-format:
static struct rte_vdev_driver pmd_pcap_drv = {
.probe = pmd_pcap_probe,
.remove = pmd_pcap_remove,
};
After clang-format:
static struct rte_vdev_driver pmd_pcap_drv = {
.probe = pmd_pcap_probe,
.remove = pmd_pcap_remove,
};
PATCH v6 1/1 devtools: add .clang-format file
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
--- .clang-format | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 .clang-format
.clang-format new file +153 -0
@@ -0,0 +1,153 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2023 Abdullah Ömer Yamaç. +# + +--- +BasedOnStyle: LLVM + +# Place opening and closing parentheses on the same line for control statements +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: true + AfterControlStatement: false + +AllowShortEnumsOnASingleLine: false + +# Should be declared this way: +SpaceBeforeParens: Custom +SpaceBeforeParensOptions: + AfterForeachMacros: false + +# Set maximum line length to 100 characters +ColumnLimit: 100 + +# Use LF (line feed) as the end-of-line character +LineEnding: LF + +# Insert a newline at the end of the file +InsertNewlineAtEOF: true + +# Set indentation width to 8 spaces +IndentWidth: 8 + +# Set continuation indentation width to 16 spaces (2 tabs) +AlignAfterOpenBracket: DontAlign +ContinuationIndentWidth: 16 + +# Set tab width to 8 spaces +TabWidth: 8 + +# Use tabs for indentation +UseTab: Always + +# Preserve include blocks as they are +IncludeBlocks: Preserve + +# Never sort includes +SortIncludes: Never + +# Always break after return type for top-level definitions +AlwaysBreakAfterReturnType: TopLevelDefinitions + +# Always break before multiline string literals +AlignEscapedNewlines: Left + +# Foreach macros +ForEachMacros: + [ + "CIRBUF_FOREACH", + "DLB2_LIST_FOR_EACH", + "DLB2_LIST_FOR_EACH_SAFE", + "ECORE_LIST_FOR_EACH_ENTRY", + "ECORE_LIST_FOR_EACH_ENTRY_SAFE", + "FOR_EACH", + "FOR_EACH_BUCKET", + "FOR_EACH_CNIC_QUEUE", + "FOR_EACH_COS_IN_TX_QUEUE", + "FOR_EACH_ETH_QUEUE", + "FOR_EACH_MEMBER", + "FOR_EACH_NONDEFAULT_ETH_QUEUE", + "FOR_EACH_NONDEFAULT_QUEUE", + "FOR_EACH_PORT", + "FOR_EACH_PORT_IF", + "FOR_EACH_QUEUE", + "FOR_EACH_SUITE_TESTCASE", + "FOR_EACH_SUITE_TESTSUITE", + "FOREACH_ABS_FUNC_IN_PORT", + "FOREACH_DEVICE_ON_AUXILIARY_BUS", + "FOREACH_DEVICE_ON_CDXBUS", + "FOREACH_DEVICE_ON_PCIBUS", + "FOREACH_DEVICE_ON_PLATFORM_BUS", + "FOREACH_DEVICE_ON_UACCEBUS", + "FOREACH_DEVICE_ON_VMBUS", + "FOREACH_DRIVER_ON_AUXILIARY_BUS", + "FOREACH_DRIVER_ON_CDXBUS", + "FOREACH_DRIVER_ON_PCIBUS", + "FOREACH_DRIVER_ON_PLATFORM_BUS", + "FOREACH_DRIVER_ON_UACCEBUS", + "FOREACH_DRIVER_ON_VMBUS", + "FOREACH_SUBDEV", + "FOREACH_SUBDEV_STATE", + "HLIST_FOR_EACH_ENTRY", + "ILIST_FOREACH", + "LIST_FOR_EACH_ENTRY", + "LIST_FOR_EACH_ENTRY_SAFE", + "LIST_FOREACH", + "LIST_FOREACH_FROM", + "LIST_FOREACH_FROM_SAFE", + "LIST_FOREACH_SAFE", + "ML_AVG_FOREACH_QP", + "ML_AVG_FOREACH_QP_MVTVM", + "ML_AVG_RESET_FOREACH_QP", + "ML_MAX_FOREACH_QP", + "ML_MAX_FOREACH_QP_MVTVM", + "ML_MAX_RESET_FOREACH_QP", + "ML_MIN_FOREACH_QP", + "ML_MIN_FOREACH_QP_MVTVM", + "ML_MIN_RESET_FOREACH_QP", + "MLX5_ETH_FOREACH_DEV", + "MLX5_IPOOL_FOREACH", + "MLX5_L3T_FOREACH", + "OSAL_LIST_FOR_EACH_ENTRY", + "OSAL_LIST_FOR_EACH_ENTRY_SAFE", + "PLT_TAILQ_FOREACH_SAFE", + "RTE_BBDEV_FOREACH", + "RTE_DEV_FOREACH", + "RTE_DMA_FOREACH_DEV", + "RTE_EAL_DEVARGS_FOREACH", + "RTE_ETH_FOREACH_DEV", + "RTE_ETH_FOREACH_DEV_OF", + "RTE_ETH_FOREACH_DEV_OWNED_BY", + "RTE_ETH_FOREACH_DEV_SIBLING", + "RTE_ETH_FOREACH_MATCHING_DEV", + "RTE_ETH_FOREACH_VALID_DEV", + "RTE_GPU_FOREACH", + "RTE_GPU_FOREACH_CHILD", + "RTE_GPU_FOREACH_PARENT", + "RTE_LCORE_FOREACH", + "RTE_LCORE_FOREACH_WORKER", + "RTE_TAILQ_FOREACH", + "RTE_TAILQ_FOREACH_SAFE", + "SILIST_FOREACH", + "SLIST_FOREACH", + "SLIST_FOREACH_FROM", + "SLIST_FOREACH_FROM_SAFE", + "SLIST_FOREACH_PREVPTR", + "SLIST_FOREACH_SAFE", + "STAILQ_FOREACH", + "STAILQ_FOREACH_FROM", + "STAILQ_FOREACH_FROM_SAFE", + "STAILQ_FOREACH_SAFE", + "TAILQ_FOREACH", + "TAILQ_FOREACH_ENTRY", + "TAILQ_FOREACH_ENTRY_SAFE", + "TAILQ_FOREACH_FROM", + "TAILQ_FOREACH_FROM_SAFE", + "TAILQ_FOREACH_REVERSE", + "TAILQ_FOREACH_REVERSE_FROM", + "TAILQ_FOREACH_REVERSE_FROM_SAFE", + "TAILQ_FOREACH_REVERSE_SAFE", + "TAILQ_FOREACH_SAFE", + ] +ObjCSpaceAfterProperty: true +IndentGotoLabels: false
Signature · 1 line
2.34.1
Quoted 9 lines · On Mon, 14 Oct 2024 22:15:45 +0000 Abdullah Ömer Yamaç <[email protected]>…
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>
Looks good, as an experiment I ran some files through clang-format and tried to make sure that clang-format and checkpatch do not disagree.
One that showed up was that clang-format liked to leave open ended functions.
CHECK:OPEN_ENDED_LINE: Lines should not end with a '(' #407: FILE: drivers/net/tap/rte_eth_tap.c:593:
+ *l4_cksum = rte_ipv4_udptcp_cksum_mbuf(
Quoted 10 lines · On Mon, 14 Oct 2024 22:15:45 +0000 Abdullah Ömer Yamaç <[email protected]>…
clang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
Signed-off-by Abdullah Ömer Yamaç <[email protected]>---
Adding a clang-format would be good, but the patch never got reviewed. I was a little concerned that the new clang-format would have some style conflicts with current DPDK usage; so I asked AI. Please consider these proposed changes and resubmit.
## Patch Review: devtools: add .clang-format file
### Commit Message Analysis
| Check | Status | Notes | |-------|--------|-------| | Subject ≤60 chars | ✅ | 39 characters | | Lowercase after colon | ✅ | "add .clang-format file" | | Imperative mood | ✅ | "add" | | No trailing period | ✅ | | | Signed-off-by | ✅ | Present with real name and email | | Body ≤75 chars | ✅ | Lines are within limit |
**Warning**: The prefix devtools: is potentially misleading since the .clang-format file is being added to the repository root, not to the devtools/ directory. Consider using a prefix like style: or build:, or simply omit the prefix for root-level config files.
---
### Clang-Format Settings Review
#### ✅ Correct Settings
| Setting | Value | DPDK Requirement | Status | |---------|-------|------------------|--------| | `ColumnLimit` | 100 | 100 chars max | ✅ | | `TabWidth` | 8 | 8 characters | ✅ | | `IndentWidth` | 8 | 8 characters | ✅ | | `LineEnding` | LF | Unix line endings | ✅ | | `InsertNewlineAtEOF` | true | Files end with newline | ✅ | | `AfterFunction` | true | Brace on new line for functions | ✅ | | `AfterControlStatement` | false | Brace on same line for if/for/while | ✅ | | `IncludeBlocks` | Preserve | Don't reorder include groups | ✅ | | `SortIncludes` | Never | Preserve include order | ✅ | | `AlwaysBreakAfterReturnType` | TopLevelDefinitions | Return type on own line | ✅ | | `IndentGotoLabels` | false | Labels not indented | ✅ | | `ForEachMacros` | comprehensive list | Treat as loops | ✅ |
#### ⚠️ Issues to Address
**1. UseTab Setting (Warning)**
```yaml UseTab: Always ```
DPDK style specifies: *"hard tabs for indentation, spaces for alignment"*
UseTab: Always will use tabs everywhere including for alignment, which can cause misalignment when viewed with different tab widths. Consider:
```yaml UseTab: ForIndentation ```
**2. Missing Pointer Alignment (Warning)**
DPDK follows Linux kernel style where the * binds to the variable name:
```c char *ptr; /* Correct */ char* ptr; /* Wrong */ ```
Add:
```yaml PointerAlignment: Right ```
**3. Missing Space After Cast (Info)**
DPDK style typically has no space after casts. Consider adding:
```yaml SpaceAfterCStyleCast: false ```
**4. Missing Short Function Settings (Info)**
To prevent unwanted single-line functions:
```yaml AllowShortFunctionsOnASingleLine: None AllowShortBlocksOnASingleLine: Never ```
**5. Missing Brace Wrapping Settings (Info)**
The BraceWrapping section is incomplete. For full DPDK compliance, consider:
```yaml
BraceWrapping:
AfterFunction: true
AfterControlStatement: false
AfterStruct: false
AfterEnum: false
AfterUnion: false
BeforeElse: false
BeforeWhile: false
SplitEmptyFunction: true
```**6. Switch Statement Indentation (Info)**
DPDK style shows case labels not indented relative to switch. Add:
```yaml IndentCaseLabels: false IndentCaseBlocks: false ```
**7. BasedOnStyle Consideration (Info)**
BasedOnStyle: LLVM is a reasonable starting point, but Linux kernel style (BasedOnStyle: Kernel if available in your clang-format version) might be closer to DPDK's actual style since DPDK is modeled on Linux kernel development.
---
### Summary
| Severity | Count | Items | |----------|-------|-------| | **Error** | 0 | None | | **Warning** | 2 | `UseTab: Always` should be `ForIndentation`; Missing `PointerAlignment: Right` | | **Info** | 5 | Subject prefix; Missing short function settings; Incomplete brace wrapping; Missing switch indent settings; Space after cast |
**Recommendation**: The patch is a solid foundation but needs the pointer alignment and tab usage fixes before merge. The current UseTab: Always setting will cause alignment issues in multi-line function arguments and struct initializers, and the missing PointerAlignment: Right will format pointers contrary to DPDK convention.
PATCH v6 1/1 devtools: add .clang-format file
In reply to Stephen Hemmingerclang-format is a tool to format C/C++/Objective-C code. It can be used to reformat code to match a given coding style, or to ensure that code adheres to a specific coding style. It helps to maintain a consistent coding style across the DPDK codebase.
.clang-format file overrides the default style options provided by clang-format and large set of IDEs and text editors support it.
--- .clang-format | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 .clang-format
.clang-format new file +153 -0
@@ -0,0 +1,153 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 Abdullah Ömer Yamaç. +# + +--- +BasedOnStyle: LLVM + +# Place opening and closing parentheses on the same line for control statements +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: true + AfterControlStatement: false + +AllowShortEnumsOnASingleLine: false + +# Should be declared this way: +SpaceBeforeParens: Custom +SpaceBeforeParensOptions: + AfterForeachMacros: false + +# Set maximum line length to 100 characters +ColumnLimit: 100 + +# Use LF (line feed) as the end-of-line character +LineEnding: LF + +# Insert a newline at the end of the file +InsertNewlineAtEOF: true + +# Set indentation width to 8 spaces +IndentWidth: 8 + +# Set continuation indentation width to 16 spaces (2 tabs) +AlignAfterOpenBracket: DontAlign +ContinuationIndentWidth: 16 + +# Set tab width to 8 spaces +TabWidth: 8 + +# Use tabs for indentation +UseTab: Always + +# Preserve include blocks as they are +IncludeBlocks: Preserve + +# Never sort includes +SortIncludes: Never + +# Always break after return type for top-level definitions +AlwaysBreakAfterReturnType: TopLevelDefinitions + +# Always break before multiline string literals +AlignEscapedNewlines: Left + +# Foreach macros +ForEachMacros: + [ + "CIRBUF_FOREACH", + "DLB2_LIST_FOR_EACH", + "DLB2_LIST_FOR_EACH_SAFE", + "ECORE_LIST_FOR_EACH_ENTRY", + "ECORE_LIST_FOR_EACH_ENTRY_SAFE", + "FOR_EACH", + "FOR_EACH_BUCKET", + "FOR_EACH_CNIC_QUEUE", + "FOR_EACH_COS_IN_TX_QUEUE", + "FOR_EACH_ETH_QUEUE", + "FOR_EACH_MEMBER", + "FOR_EACH_NONDEFAULT_ETH_QUEUE", + "FOR_EACH_NONDEFAULT_QUEUE", + "FOR_EACH_PORT", + "FOR_EACH_PORT_IF", + "FOR_EACH_QUEUE", + "FOR_EACH_SUITE_TESTCASE", + "FOR_EACH_SUITE_TESTSUITE", + "FOREACH_ABS_FUNC_IN_PORT", + "FOREACH_DEVICE_ON_AUXILIARY_BUS", + "FOREACH_DEVICE_ON_CDXBUS", + "FOREACH_DEVICE_ON_PCIBUS", + "FOREACH_DEVICE_ON_PLATFORM_BUS", + "FOREACH_DEVICE_ON_UACCEBUS", + "FOREACH_DEVICE_ON_VMBUS", + "FOREACH_DRIVER_ON_AUXILIARY_BUS", + "FOREACH_DRIVER_ON_CDXBUS", + "FOREACH_DRIVER_ON_PCIBUS", + "FOREACH_DRIVER_ON_PLATFORM_BUS", + "FOREACH_DRIVER_ON_UACCEBUS", + "FOREACH_DRIVER_ON_VMBUS", + "FOREACH_SUBDEV", + "FOREACH_SUBDEV_STATE", + "HLIST_FOR_EACH_ENTRY", + "ILIST_FOREACH", + "LIST_FOR_EACH_ENTRY", + "LIST_FOR_EACH_ENTRY_SAFE", + "LIST_FOREACH", + "LIST_FOREACH_FROM", + "LIST_FOREACH_FROM_SAFE", + "LIST_FOREACH_SAFE", + "ML_AVG_FOREACH_QP", + "ML_AVG_FOREACH_QP_MVTVM", + "ML_AVG_RESET_FOREACH_QP", + "ML_MAX_FOREACH_QP", + "ML_MAX_FOREACH_QP_MVTVM", + "ML_MAX_RESET_FOREACH_QP", + "ML_MIN_FOREACH_QP", + "ML_MIN_FOREACH_QP_MVTVM", + "ML_MIN_RESET_FOREACH_QP", + "MLX5_ETH_FOREACH_DEV", + "MLX5_IPOOL_FOREACH", + "MLX5_L3T_FOREACH", + "OSAL_LIST_FOR_EACH_ENTRY", + "OSAL_LIST_FOR_EACH_ENTRY_SAFE", + "PLT_TAILQ_FOREACH_SAFE", + "RTE_BBDEV_FOREACH", + "RTE_DEV_FOREACH", + "RTE_DMA_FOREACH_DEV", + "RTE_EAL_DEVARGS_FOREACH", + "RTE_ETH_FOREACH_DEV", + "RTE_ETH_FOREACH_DEV_OF", + "RTE_ETH_FOREACH_DEV_OWNED_BY", + "RTE_ETH_FOREACH_DEV_SIBLING", + "RTE_ETH_FOREACH_MATCHING_DEV", + "RTE_ETH_FOREACH_VALID_DEV", + "RTE_GPU_FOREACH", + "RTE_GPU_FOREACH_CHILD", + "RTE_GPU_FOREACH_PARENT", + "RTE_LCORE_FOREACH", + "RTE_LCORE_FOREACH_WORKER", + "RTE_TAILQ_FOREACH", + "RTE_TAILQ_FOREACH_SAFE", + "SILIST_FOREACH", + "SLIST_FOREACH", + "SLIST_FOREACH_FROM", + "SLIST_FOREACH_FROM_SAFE", + "SLIST_FOREACH_PREVPTR", + "SLIST_FOREACH_SAFE", + "STAILQ_FOREACH", + "STAILQ_FOREACH_FROM", + "STAILQ_FOREACH_FROM_SAFE", + "STAILQ_FOREACH_SAFE", + "TAILQ_FOREACH", + "TAILQ_FOREACH_ENTRY", + "TAILQ_FOREACH_ENTRY_SAFE", + "TAILQ_FOREACH_FROM", + "TAILQ_FOREACH_FROM_SAFE", + "TAILQ_FOREACH_REVERSE", + "TAILQ_FOREACH_REVERSE_FROM", + "TAILQ_FOREACH_REVERSE_FROM_SAFE", + "TAILQ_FOREACH_REVERSE_SAFE", + "TAILQ_FOREACH_SAFE", + ] +ObjCSpaceAfterProperty: true +IndentGotoLabels: false
Signature · 1 line
2.34.1
Quoted 5 lines
...
1. Some options are failing for me [1], I don't know if it requires a specific version of clang-format
I fixed these errors, and the clang-format version should be 17. I will send them after some discussions, as I've shared below.
Quoted 7 lines
2. Current options are not fully aligned with coding convention, it is easier to see what is not compatible by running the tool on an existing file [2].
we need to fix them.There are some cases that we need to discuss. First of all, I applied the
latest clang format that I created.
- In default cases for clang-format, include headers are sorted alphabetically. It improves the readability of code, and it breaks the codebase. These changes do not affect code maintenance because they are only headers.
- Second question about the column width. In the definition of .editorconfig, the column width is set as 100, but the previous commits violate this. Here is the sample code:
struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
@@ -61,8 +61,7 @@ static const struct rte_eth_xstats_name_off eth_dev_stats_strings[] = {
{"rx_missed_errors", offsetof(struct rte_eth_stats, imissed)}, {"rx_errors", offsetof(struct rte_eth_stats, ierrors)}, {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
- {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
- rx_nombuf)},
+ {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,rx_nombuf)},
};
We could use this clang-format file only for the new patches and newly inserted lines. I am using VSCode IDE for development, and after some modification, I can select the modified lines and apply formatting. It is very useful for these cases. Otherwise, we need to handle so many things.
By the way, I am still working on macros. If you have any comments on this, I would be very happy to discuss it.
Quoted 1 line
...